Bladeren bron

harmonized logs

Gildas 7 jaren geleden
bovenliggende
commit
4e7c335805

+ 17 - 15
lib/single-file/css-rules-matcher.js

@@ -41,38 +41,32 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 			this.doc = doc;
 			this.mediaAllInfo = createMediaInfo(MEDIA_ALL);
 			const matchedElementsCache = new Map();
-			let startTime;
 			doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
 				if (styleElement.sheet) {
-					if (DEBUG) {
-						startTime = Date.now();
-						log("  // STARTED getMatchedElementsRules style", styleIndex);
-					}
+					let cssRules = styleElement.sheet.cssRules;
 					if (styleElement.media && styleElement.media != MEDIA_ALL) {
 						const mediaInfo = createMediaInfo(styleElement.media);
 						this.mediaAllInfo.medias.set(styleIndex + "-" + styleElement.media, mediaInfo);
-						getMatchedElementsRules(doc, styleElement.sheet.cssRules, mediaInfo, styleIndex, matchedElementsCache);
+						getMatchedElementsRules(doc, cssRules, mediaInfo, styleIndex, matchedElementsCache);
 					} else {
-						getMatchedElementsRules(doc, styleElement.sheet.cssRules, this.mediaAllInfo, styleIndex, matchedElementsCache);
-					}
-					if (DEBUG) {
-						log("  // ENDED   getMatchedElementsRules style", Date.now() - startTime);
+						getMatchedElementsRules(doc, cssRules, this.mediaAllInfo, styleIndex, matchedElementsCache);
 					}
 				}
 			});
+			let startTime;
 			if (DEBUG) {
 				startTime = Date.now();
-				log("  // STARTED sortRules");
+				log("  -- STARTED sortRules");
 			}
 			sortRules(this.mediaAllInfo);
 			if (DEBUG) {
-				log("  // ENDED sortRules", Date.now() - startTime);
+				log("  -- ENDED sortRules", Date.now() - startTime);
 				startTime = Date.now();
-				log("  // STARTED computeCascade");
+				log("  -- STARTED computeCascade");
 			}
 			computeCascade(this.mediaAllInfo, [], this.mediaAllInfo);
 			if (DEBUG) {
-				log("  // ENDED computeCascade", Date.now() - startTime);
+				log("  -- ENDED computeCascade", Date.now() - startTime);
 			}
 		}
 
@@ -92,6 +86,11 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 	};
 
 	function getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, matchedElementsCache) {
+		let startTime;
+		if (DEBUG && cssRules.length > 1) {
+			startTime = Date.now();
+			log("  -- STARTED getMatchedElementsRules", " index =", sheetIndex, "rules.length =", cssRules.length);
+		}
 		Array.from(cssRules).forEach((cssRule, ruleIndex) => {
 			const cssRuleType = cssRule.type;
 			if (cssRuleType == CSSRule.MEDIA_RULE) {
@@ -115,6 +114,9 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 				}
 			}
 		});
+		if (DEBUG && cssRules.length > 1) {
+			log("  -- ENDED   getMatchedElementsRules", "delay =", Date.now() - startTime);
+		}
 	}
 
 	function getMatchedElementsSelector(doc, cssRule, selector, selectorText, selectorsText, mediaInfo, ruleIndex, sheetIndex, matchedElementsCache) {
@@ -294,7 +296,7 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 	}
 
 	function log(...args) {
-		console.log("S-File <css-ma>", ...args); // eslint-disable-line no-console
+		console.log("S-File <css-mat>", ...args); // eslint-disable-line no-console
 	}
 
 })();

+ 13 - 12
lib/single-file/css-rules-minifier.js

@@ -33,32 +33,25 @@ this.cssMinifier = this.cssMinifier || (() => {
 			const rulesMatcher = RulesMatcher.create(doc);
 			const mediaAllInfo = rulesMatcher.getAllMatchedRules();
 			const stats = { processed: 0, discarded: 0 };
-			let startTime;
 			doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
 				if (styleElement.sheet) {
-					if (DEBUG) {
-						startTime = Date.now();
-						log("  // STARTED processRules style", styleIndex);
-					}
+					const cssRules = styleElement.sheet.cssRules;
 					let mediaInfo;
 					if (styleElement.media && styleElement.media != "all") {
 						mediaInfo = mediaAllInfo.medias.get(styleIndex + "-" + styleElement.media);
 					} else {
 						mediaInfo = mediaAllInfo;
 					}
-					const cssRules = styleElement.sheet.cssRules;
 					stats.processed += cssRules.length;
 					stats.discarded += cssRules.length;
 					styleElement.textContent = processRules(doc, cssRules, mediaInfo);
 					stats.discarded -= cssRules.length;
-					if (DEBUG) {
-						log("  // ENDED   processRules style", Date.now() - startTime);
-					}
 				}
 			});
+			let startTime;
 			if (DEBUG) {
 				startTime = Date.now();
-				log("  // STARTED processStyleAttribute");
+				log("  -- STARTED processStyleAttribute");
 			}
 			doc.querySelectorAll("[style]").forEach(element => {
 				let textContent = processStyleAttribute(element.style, mediaAllInfo);
@@ -69,7 +62,7 @@ this.cssMinifier = this.cssMinifier || (() => {
 				}
 			});
 			if (DEBUG) {
-				log("  // ENDED   processStyleAttribute", Date.now() - startTime);
+				log("  -- ENDED   processStyleAttribute delay =", Date.now() - startTime);
 			}
 			return stats;
 		}
@@ -77,6 +70,11 @@ this.cssMinifier = this.cssMinifier || (() => {
 
 	function processRules(doc, cssRules, mediaInfo) {
 		let sheetContent = "";
+		let startTime;
+		if (DEBUG && cssRules.length > 1) {
+			startTime = Date.now();
+			log("  -- STARTED processRules", "rules.length =", cssRules.length);
+		}
 		Array.from(cssRules).forEach(cssRule => {
 			if (cssRule.type == CSSRule.MEDIA_RULE) {
 				sheetContent += "@media " + Array.from(cssRule.media).join(",") + "{";
@@ -91,6 +89,9 @@ this.cssMinifier = this.cssMinifier || (() => {
 				sheetContent += cssRule.cssText;
 			}
 		});
+		if (DEBUG && cssRules.length > 1) {
+			log("  -- ENDED   processRules delay =", Date.now() - startTime);
+		}
 		return sheetContent;
 	}
 
@@ -155,7 +156,7 @@ this.cssMinifier = this.cssMinifier || (() => {
 	}
 
 	function log(...args) {
-		console.log("S-File <css-mi>", ...args); // eslint-disable-line no-console
+		console.log("S-File <css-min>", ...args); // eslint-disable-line no-console
 	}
 
 })();

+ 3 - 3
lib/single-file/single-file-browser.js

@@ -57,7 +57,7 @@ this.SingleFile = this.SingleFile || (() => {
 			let startTime;
 			if (DEBUG) {
 				startTime = Date.now();
-				log("  // STARTED download", resourceURL, options.asDataURI);
+				log("  // STARTED download url =", resourceURL, "asDataURI =", options.asDataURI);
 			}
 			let resourceContent;
 			if (!fetchResource) {
@@ -86,7 +86,7 @@ this.SingleFile = this.SingleFile || (() => {
 				try {
 					const buffer = await resourceContent.arrayBuffer();
 					if (DEBUG) {
-						log("  // ENDED   download", resourceURL, Date.now() - startTime);
+						log("  // ENDED   download url =", resourceURL, "delay =", Date.now() - startTime);
 					}
 					const dataURI = "data:" + (contentType || "") + ";" + "base64," + base64.fromByteArray(new Uint8Array(buffer));
 					if (options.maxResourceSizeEnabled && buffer.byteLength > options.maxResourceSize * ONE_MB) {
@@ -109,7 +109,7 @@ this.SingleFile = this.SingleFile || (() => {
 				try {
 					const arrayBuffer = await resourceContent.arrayBuffer();
 					if (DEBUG) {
-						log("  // ENDED   download", resourceURL, Date.now() - startTime);
+						log("  // ENDED   download url =", resourceURL, "delay =", Date.now() - startTime);
 					}
 					const textContent = (new TextDecoder(charSet)).decode(arrayBuffer);
 					if (options.maxResourceSizeEnabled && textContent.length > options.maxResourceSize * ONE_MB) {

+ 6 - 6
lib/single-file/single-file-core.js

@@ -181,17 +181,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		async executeStage(step) {
 			if (DEBUG) {
-				log("** STARTED STAGE", step, "**");
+				log("**** STARTED STAGE", step, "****");
 			}
 			STAGES[step].sequential.forEach(task => {
 				let startTime;
 				if (DEBUG) {
 					startTime = Date.now();
-					log("  -- STARTED", task.action, "...");
+					log("  -- STARTED task =", task.action);
 				}
 				this.executeTask(task, !step);
 				if (DEBUG) {
-					log("  -- ENDED  ", task.action, Date.now() - startTime);
+					log("  -- ENDED   task =", task.action, "delay =", Date.now() - startTime);
 				}
 			});
 			if (STAGES[step].parallel) {
@@ -199,17 +199,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					let startTime;
 					if (DEBUG) {
 						startTime = Date.now();
-						log("  // STARTED", task.action, "...");
+						log("  // STARTED task =", task.action);
 					}
 					const promise = this.executeTask(task, !step);
 					if (DEBUG) {
-						promise.then(() => log("  // ENDED", task.action, Date.now() - startTime));
+						promise.then(() => log("  // ENDED task =", task.action, "delay =", Date.now() - startTime));
 					}
 					return promise;
 				}));
 			}
 			if (DEBUG) {
-				log("** ENDED   STAGE", step, "**");
+				log("**** ENDED   STAGE", step, "****");
 			}
 		}