Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,22 @@ const uniqueString = (string) => {
*/
export const replaceVariables = (el, value) => {

// find non-nested css function calls
// eg: rgb(...), drop-shadow(...)
const funcReg = /([a-z\-]+)\s*\(\s*([^\(\)]*?)\s*(?:,\s*([^\(\)]*?)\s*)?\s*\)/i;
const replacements = [];
let match;
const uniq = uniqueString(value);
let funcReg = /([a-z\-]+)\s*\(\s*([^,\(\)]*)\s*(?:,\s*([^,\(\)]*)\s*)?\)/i;
let match;

while ((match = funcReg.exec(value)) !== null) {
const i = `${replacements.length}`;

// attempt to resolve variables
if (match[1].toLowerCase() == 'var') {
const varValue = findVariableValue(el, match[2]);

// found variable value
if (varValue) {
value = value.replace(match[0], varValue);
continue;
}

// use default value
// var(--name , default-value)
if (match[3]) {
value = value.replace(match[0], match[3]);
continue;
Expand Down