Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
declarations.forEach(function(decl) {
decl.value = helpers.try(function transformCS() {
return reduceFunctionCall(decl.value, 'cs', function reduceCS(body) {
if (!body) {
return false;
}
var parts = body.split(',');
var value = parseInt(parts[0], 10);
// Defaults to the --cs-color variable
var name = parts[1] ? parts[1].trim() : 'color';
var colorObj = colors[name];
if (!colorObj) {
return 'cs(' + body + ')';
}
cs = colorObj.func;
return cs(value);
});
}, decl.source);
css.eachDecl(function transformDecl (decl) {
// Check if the decl is of a color-related property and make sure
// it has a value containing a replaceable color
if (PROPS.indexOf(decl.prop) === -1 ||
!decl.value ||
!KEYWORD_REGEX.test(decl.value)) {
return;
}
// Transform!
decl.value = helpers.try(function transformValue () {
return transforms.reduce(function (value, args) {
return value.replace.apply(value, args);
}, decl.value);
}, decl.source);
});
};
style.eachDecl(function transformDecl(decl) {
helpers.try(function() {
var stringArray = decl.value.toLowerCase().split(' ');
var colorsToReplace = intersection(stringArray, colorsKeys);
if (colorsToReplace.length > 0) {
colorsToReplace.map(function(el) {
decl.value = decl.value.replace( new RegExp(el, 'ig'), colors[el] );
});
}
}, decl.source);
});
};
style.walkDecls(function transformDecl(decl) {
if (!decl.value || !functionsRegex.test(decl.value)) {
return;
}
decl.value = helpers.try(function() {
return handleFunction(decl.value, decl.source);
}, decl.source)
})
}
function transformValue(node, property) {
var value = node[property]
if (!value || !CONTAINS_CALC.test(value)) {
return
}
helpers.try(function transformCSSCalc() {
var reducedValue = reduceCSSCalc(value, precision)
if (warnWhenCannotResolve && CONTAINS_CALC.test(reducedValue)) {
result.warn("Could not reduce expression: " + value,
{plugin: "postcss-calc", node: node})
}
if (!preserve) {
node[property] = reducedValue
return
}
if (reducedValue != value) {
var clone = node.clone()
clone[property] = reducedValue
node.parent.insertBefore(node, clone)
function transformValue(node, property) {
var value = node[property]
if (!value || !CONTAINS_CALC.test(value)) {
return
}
helpers.try(function transformCSSCalc() {
var reducedValue = reduceCSSCalc(value, precision)
if (warnWhenCannotResolve && CONTAINS_CALC.test(reducedValue)) {
result.warn("Could not reduce expression: " + value,
{plugin: "postcss-calc", node: node})
}
if (!preserve) {
node[property] = reducedValue
return
}
if (reducedValue != value) {
var clone = node.clone()
clone[property] = reducedValue
node.parent.insertBefore(node, clone)
return
}
result.messages.push({
plugin: "postcss-color-function",
type: "skipped-color-function-with-custom-property",
word: decl.value,
message:
"Skipped color function with custom property `" +
decl.value +
"`",
})
return
}
try {
decl.value = helpers.try(function transformColorValue() {
return transformColor(decl.value)
}, decl.source)
}
catch (error) {
decl.warn(result, error.message, {
word: decl.value,
index: decl.index,
})
}
})
}
function transformValue(decl, method) {
var promises = [];
var cache = '';
helpers.try(function() {
cache = valueParser(decl.value).walk(function(node) {
if (node.type === 'function') {
var toLower = node.value.toLowerCase();
if (~['hsl', 'hsla', 'rgb', 'rgba'].indexOf(toLower)) {
var value = colorTransformer(stringify(node), method);
node.type = 'word';
node.value = value;
return;
}
if (toLower === 'url') {
promises.push(
getBase64Data(node.nodes[0].value, method).then(function(dataUrl) {
node.nodes[0].value = dataUrl;
})
);
}
const transformDecl = (decl) => {
if (!decl.value || decl.value.indexOf('mix(') === -1) {
return;
}
decl.value = postcssTry(() => transformColor(decl.value, decl.source), decl.source )
};
else if (node.type === 'atrule' && node.name === 'media') {
nodeProp = 'params';
}
else if (node.type === 'rule') {
nodeProp = 'selector';
}
else {
return;
}
var match = functionName + '(';
if (!node[nodeProp] || node[nodeProp].indexOf(match) === -1) {
return;
}
node[nodeProp] = helpers.try(function () {
return transformResolve(node[nodeProp], functionName);
}, node.source);
})
};