Răsfoiți Sursa

renamed "media" property to "mediaText"

Gildas 7 ani în urmă
părinte
comite
8cc763bff5

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

@@ -33,9 +33,9 @@ this.matchedRules = this.matchedRules || (() => {
 			const matchedElementsCache = new Map();
 			let sheetIndex = 0;
 			docStyle.stylesheets.forEach(stylesheetInfo => {
-				if (stylesheetInfo.media && stylesheetInfo.media != MEDIA_ALL) {
-					const mediaInfo = createMediaInfo(stylesheetInfo.media);
-					this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + stylesheetInfo.media, mediaInfo);
+				if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
+					const mediaInfo = createMediaInfo(stylesheetInfo.mediaText);
+					this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaInfo);
 					getMatchedElementsRules(doc, stylesheetInfo.stylesheet.children, mediaInfo, sheetIndex, docStyle, matchedElementsCache);
 				} else {
 					getMatchedElementsRules(doc, stylesheetInfo.stylesheet.children, this.mediaAllInfo, sheetIndex, docStyle, matchedElementsCache);

+ 1 - 2
lib/single-file/css-medias-minifier.js

@@ -26,8 +26,7 @@ this.mediasMinifier = this.mediasMinifier || (() => {
 		process: stylesheets => {
 			const stats = { processed: 0, discarded: 0 };
 			stylesheets.forEach((stylesheet, element) => {
-				const media = stylesheet.media || "all";
-				if (matchesMediaType(media, "screen")) {
+				if (matchesMediaType(stylesheet.mediaText || "all", "screen")) {
 					const removedRules = processRules(stylesheet.stylesheet.children, stats);
 					removedRules.forEach(({ cssRules, cssRule }) => cssRules.remove(cssRule));
 				} else {

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

@@ -30,8 +30,8 @@ this.cssRulesMinifier = this.cssRulesMinifier || (() => {
 			let sheetIndex = 0;
 			stylesheets.forEach(stylesheetInfo => {
 				let mediaInfo;
-				if (stylesheetInfo.media && stylesheetInfo.media != "all") {
-					mediaInfo = mediaAllInfo.medias.get("style-" + sheetIndex + "-" + stylesheetInfo.media);
+				if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != "all") {
+					mediaInfo = mediaAllInfo.medias.get("style-" + sheetIndex + "-" + stylesheetInfo.mediaText);
 				} else {
 					mediaInfo = mediaAllInfo;
 				}

+ 9 - 5
lib/single-file/single-file-core.js

@@ -745,7 +745,11 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		async resolveStylesheetURLs() {
 			await Promise.all(Array.from(this.doc.querySelectorAll("style, link[rel*=stylesheet]"))
 				.map(async element => {
-					this.stylesheets.set(element, { media: element.media });
+					let mediaText;
+					if (element.media) {
+						mediaText = element.media;
+					}
+					this.stylesheets.set(element, { mediaText });
 					const options = { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled, url: this.options.url, charSet: this.charSet, compressCSS: this.options.compressCSS };
 					const isLinkTag = element.tagName.toLowerCase() == "link";
 					if (isLinkTag && element.rel.includes("alternate") && element.title) {
@@ -790,8 +794,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 						stylesheetContent = DOM.compressCSS(stylesheetContent);
 					}
 					styleElement.textContent = stylesheetContent;
-					if (stylesheetInfo.media) {
-						styleElement.media = stylesheetInfo.media;
+					if (stylesheetInfo.mediaText) {
+						styleElement.media = stylesheetInfo.mediaText;
 					}
 				} else {
 					styleElement.remove();
@@ -801,8 +805,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				const stylesheetInfo = this.stylesheets.get(linkElement);
 				if (stylesheetInfo) {
 					const styleElement = this.doc.createElement("style");
-					if (stylesheetInfo.media) {
-						styleElement.media = stylesheetInfo.media;
+					if (stylesheetInfo.mediaText) {
+						styleElement.media = stylesheetInfo.mediaText;
 					}
 					let stylesheetContent = cssTree.generate(stylesheetInfo.stylesheet);
 					if (this.options.compressCSS) {