|
|
@@ -101,7 +101,7 @@ this.matchedRules = this.matchedRules || (() => {
|
|
|
} else if (cssRule.type == "Rule" && cssRule.prelude.children) {
|
|
|
const selectors = cssRule.prelude.children.toArray();
|
|
|
const selectorsText = cssRule.prelude.children.toArray().map(selector => cssTree.generate(selector));
|
|
|
- const ruleInfo = { cssRule, mediaInfo, ruleIndex, sheetIndex, matchedSelectors: new Set(), style: new Map(), selectors, selectorsText };
|
|
|
+ const ruleInfo = { cssRule, mediaInfo, ruleIndex, sheetIndex, matchedSelectors: new Set(), declarations: new Map(), selectors, selectorsText };
|
|
|
if (!invalidSelector(selectorsText.join(","), stylesheet)) {
|
|
|
for (let selector = cssRule.prelude.children.head, selectorIndex = 0; selector; selector = selector.next, selectorIndex++) {
|
|
|
const selectorText = selectorsText[selectorIndex];
|
|
|
@@ -211,7 +211,7 @@ this.matchedRules = this.matchedRules || (() => {
|
|
|
if (!elementInfo) {
|
|
|
elementInfo = [];
|
|
|
if (elementStyle) {
|
|
|
- elementInfo.push({ styleInfo: { cssStyle: elementStyle, style: new Map() } });
|
|
|
+ elementInfo.push({ styleInfo: { cssStyle: elementStyle, declarations: new Map() } });
|
|
|
}
|
|
|
mediaInfo.elements.set(element, elementInfo);
|
|
|
}
|
|
|
@@ -232,28 +232,28 @@ this.matchedRules = this.matchedRules || (() => {
|
|
|
}
|
|
|
|
|
|
function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, stylesheet) {
|
|
|
- mediaInfo.elements.forEach((elementInfo, element) => getStylesInfo(elementInfo, stylesheet, element).forEach((declarations, property) => {
|
|
|
- if (declarations.selectorInfo.ruleInfo || mediaInfo == mediaAllInfo) {
|
|
|
+ mediaInfo.elements.forEach((elementInfo, element) => getDeclarationsInfo(elementInfo, stylesheet, element).forEach((declarationsInfo, property) => {
|
|
|
+ if (declarationsInfo.selectorInfo.ruleInfo || mediaInfo == mediaAllInfo) {
|
|
|
let info;
|
|
|
- if (declarations.selectorInfo.ruleInfo) {
|
|
|
- info = declarations.selectorInfo.ruleInfo;
|
|
|
+ if (declarationsInfo.selectorInfo.ruleInfo) {
|
|
|
+ info = declarationsInfo.selectorInfo.ruleInfo;
|
|
|
const cssRule = info.cssRule;
|
|
|
const ascendantMedia = [mediaInfo, ...parentMediaInfo].find(media => media.rules.get(cssRule)) || mediaInfo;
|
|
|
ascendantMedia.rules.set(cssRule, info);
|
|
|
if (cssRule) {
|
|
|
- info.matchedSelectors.add(declarations.selectorInfo.selectorText);
|
|
|
+ info.matchedSelectors.add(declarationsInfo.selectorInfo.selectorText);
|
|
|
}
|
|
|
} else {
|
|
|
- info = declarations.selectorInfo.styleInfo;
|
|
|
+ info = declarationsInfo.selectorInfo.styleInfo;
|
|
|
const cssStyle = info.cssStyle;
|
|
|
const matchedStyleInfo = mediaAllInfo.matchedStyles.get(cssStyle);
|
|
|
if (!matchedStyleInfo) {
|
|
|
mediaAllInfo.matchedStyles.set(cssStyle, info);
|
|
|
}
|
|
|
}
|
|
|
- const styleValue = info.style.get(property);
|
|
|
+ const styleValue = info.declarations.get(property);
|
|
|
if (!styleValue) {
|
|
|
- info.style.set(property, declarations.styleValue);
|
|
|
+ info.declarations.set(property, declarationsInfo.styleValue);
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
@@ -261,8 +261,8 @@ this.matchedRules = this.matchedRules || (() => {
|
|
|
mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, stylesheet));
|
|
|
}
|
|
|
|
|
|
- function getStylesInfo(elementInfo, stylesheet/*, element */) {
|
|
|
- const stylesInfo = new Map();
|
|
|
+ function getDeclarationsInfo(elementInfo, stylesheet/*, element */) {
|
|
|
+ const declarationsInfo = new Map();
|
|
|
elementInfo.forEach(selectorInfo => {
|
|
|
let declarations;
|
|
|
if (selectorInfo.styleInfo) {
|
|
|
@@ -270,20 +270,20 @@ this.matchedRules = this.matchedRules || (() => {
|
|
|
} else {
|
|
|
declarations = selectorInfo.ruleInfo.cssRule.block.children;
|
|
|
}
|
|
|
- processDeclarations(stylesInfo, declarations, selectorInfo, stylesheet);
|
|
|
+ processDeclarations(declarationsInfo, declarations, selectorInfo, stylesheet);
|
|
|
});
|
|
|
- return stylesInfo;
|
|
|
+ return declarationsInfo;
|
|
|
}
|
|
|
|
|
|
- function processDeclarations(stylesInfo, declarations, selectorInfo, stylesheet) {
|
|
|
+ function processDeclarations(declarationsInfo, declarations, selectorInfo, stylesheet) {
|
|
|
const processedProperties = new Set();
|
|
|
for (let declaration = declarations.tail; declaration; declaration = declaration.prev) {
|
|
|
const declarationData = declaration.data;
|
|
|
if (declarationData.type == "Declaration" && !processedProperties.has(declarationData.property) && !invalidDeclaration(cssTree.generate(declarationData), stylesheet)) {
|
|
|
const styleValue = cssTree.generate(declarationData.value);
|
|
|
- const elementStyleInfo = stylesInfo.get(declarationData);
|
|
|
+ const elementStyleInfo = declarationsInfo.get(declarationData);
|
|
|
if (styleValue.trim() && (!elementStyleInfo || (declarationData.important && !elementStyleInfo.important))) {
|
|
|
- stylesInfo.set(declarationData, { selectorInfo, styleValue, important: declarationData.important });
|
|
|
+ declarationsInfo.set(declarationData, { selectorInfo, styleValue, important: declarationData.important });
|
|
|
processedProperties.add(declarationData.property);
|
|
|
}
|
|
|
}
|