Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (selectedEl.hasAttr('style')) {
elInlineStyleAttr = selectedEl.attr('style');
elInlineStyles = elInlineStyleAttr.value;
}
var inlineCssAst = csso.parse(elInlineStyles, { context: 'block' });
// merge element(inline) styles + matching <style> styles
var newInlineCssAst = csso.parse('', { context: 'block' }); // for an empty css ast (in block context)
var mergedDeclarations = [];
var _fetchDeclarations = function (node, item) {
if (node.type === 'Declaration') {
mergedDeclarations.push(item);
}
};
var itemRulesetNodeCloned = csso.clone(selectorItem.rulesetNode);
// clone to prevent leaking declaration references (csso.translate(...))
csso.walk(itemRulesetNodeCloned, _fetchDeclarations);
csso.walk(inlineCssAst, _fetchDeclarations);
// sort by !important(ce)
var mergedDeclarationsSorted = stable(mergedDeclarations, function (declarationA, declarationB) {
var declarationAScore = ~~declarationA.data.value.important, // (cast boolean to number)
declarationBScore = ~~declarationB.data.value.important; // "
return (declarationAScore - declarationBScore);
});
// to css
for (var mergedDeclarationsSortedIndex in mergedDeclarationsSorted) {
var declaration = mergedDeclarationsSorted[mergedDeclarationsSortedIndex];
newInlineCssAst.declarations.insert(declaration);
}</style>