Explorar o código

renamed "style" property to "declarations"

Gildas %!s(int64=7) %!d(string=hai) anos
pai
achega
a44db50b7f
Modificáronse 2 ficheiros con 19 adicións e 19 borrados
  1. 17 17
      lib/single-file/css-matched-rules.js
  2. 2 2
      lib/single-file/css-rules-minifier.js

+ 17 - 17
lib/single-file/css-matched-rules.js

@@ -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);
 				}
 			}

+ 2 - 2
lib/single-file/css-rules-minifier.js

@@ -96,7 +96,7 @@ this.cssRulesMinifier = this.cssRulesMinifier || (() => {
 		const removedDeclarations = [];
 		const removedSelectors = [];
 		for (let declaration = cssRule.block.children.tail; declaration; declaration = declaration.prev) {
-			if (!ruleInfo.style.get(declaration.data)) {
+			if (!ruleInfo.declarations.has(declaration.data)) {
 				removedDeclarations.push(declaration);
 			}
 		}
@@ -116,7 +116,7 @@ this.cssRulesMinifier = this.cssRulesMinifier || (() => {
 		if (styleInfo) {
 			let propertyFound;
 			for (let declaration = cssStyle.children.head; declaration && !propertyFound; declaration = declaration.next) {
-				if (!styleInfo.style.get(declaration.data)) {
+				if (!styleInfo.declarations.has(declaration.data)) {
 					removedDeclarations.push(declaration);
 				}
 			}