Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
var newCss = csso.translate(newInlineCssAst);
</style>
continue;
}
var cssStr = styleEl.content[0].text || styleEl.content[0].cdata || [];
// collect <style>s and their css ast
var cssAst = csso.parse(cssStr, { context: 'stylesheet' });
styleItems.push({
styleEl: styleEl,
cssAst: cssAst
});
// collect css selectors and their containing ruleset
var curAtruleExpNode = null,
curPseudoClassItem = null,
curPseudoClassList = null;
csso.walk(cssAst, function (node, item, list) {
// media query blocks
// "look-behind the SimpleSelector", AtruleExpression node comes _before_ the affected SimpleSelector
if (node.type === 'AtruleExpression') { // marks the beginning of an Atrule
curAtruleExpNode = node;
}
// "look-ahead the SimpleSelector", Atrule node comes _after_ the affected SimpleSelector
if (node.type === 'Atrule') { // marks the end of an Atrule
curAtruleExpNode = null;
}
// Pseudo classes
// "look-behind the SimpleSelector", PseudoClass node comes _before_ the affected SimpleSelector
if (node.type === 'PseudoClass') {
curPseudoClassItem = item;
curPseudoClassList = list;</style>
}
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);
}
var newCss = csso.translate(newInlineCssAst);
elInlineStyleAttr.value = newCss;</style>
elInlineStyleAttr.value = newCss;
selectedEl.addAttr(elInlineStyleAttr);
}
if (removeMatchedSelectors && selectedEls !== null && selectedEls.length > 0) {
// clean up matching simple selectors if option removeMatchedSelectors is enabled
selectorItem.rulesetNode.selector.selectors.remove(selectorItem.simpleSelectorItem);
}
}
var styleItemIndex: any = 0,
styleItem: any = {};
for (styleItemIndex in styleItems) {
styleItem = styleItems[styleItemIndex];
csso.walk(styleItem.cssAst, function (node, item, list) {
// clean up