Переглянути джерело

improved image grouping reliability

Gildas 7 роки тому
батько
коміт
59aefb7888

+ 2 - 2
lib/single-file/doc-helper.js

@@ -193,10 +193,10 @@ this.docHelper = this.docHelper || (() => {
 
 	function isFullBox(imageElement) {
 		const computedStyle = getComputedStyle(imageElement);
+		const isContentBox = computedStyle.boxSizing == "content-box";
 		const paddingIsSet = computedStyle.paddingLeft != "0px" || computedStyle.paddingRight != "0px" || computedStyle.paddingBottom != "0px" || computedStyle.paddingTop != "0px";
-		const marginIsSet = computedStyle.marginLeft != "0px" || computedStyle.marginRight != "0px" || computedStyle.marginBottom != "0px" || computedStyle.marginTop != "0px";
 		const borderIsSet = computedStyle.borderLeftWidth != "0px" || computedStyle.borderRightWidth != "0px" || computedStyle.borderBottomWidth != "0px" || computedStyle.borderTopWidth != "0px";
-		return !paddingIsSet && !marginIsSet && !borderIsSet;
+		return !paddingIsSet && (isContentBox || !borderIsSet);
 	}
 
 	function getResponsiveImageData(doc, options) {

+ 7 - 7
lib/single-file/html-images-minifier.js

@@ -99,12 +99,6 @@ this.imagesMinifier = this.imagesMinifier || (() => {
 		svgElement.setAttributeNS(SVG_NS, "height", 0);
 		svgElement.setAttributeNS(SVG_NS, "style", "display:none!important");
 		svgElement.appendChild(defsElement);
-		duplicateURLs.forEach((src, srcIndex) => {
-			const imageElement = doc.createElementNS(SVG_NS, "image");
-			imageElement.setAttribute("xlink:href", src);
-			imageElement.id = "single-file-" + srcIndex;
-			defsElement.appendChild(imageElement);
-		});
 		doc.body.appendChild(svgElement);
 		const ignoredAttributeNames = [];
 		if (options.lazyLoadImages) {
@@ -149,7 +143,13 @@ this.imagesMinifier = this.imagesMinifier || (() => {
 						svgElement.setAttributeNS(SVG_NS, "height", imageData.clientHeight);
 						svgElement.setAttributeNS(SVG_NS, "preserveAspectRatio", "none");
 						useElement.setAttributeNS(SVG_NS, "xlink:href", "#single-file-" + urlIndex);
-						const imageElement = doc.getElementById("single-file-" + urlIndex);
+						let imageElement = doc.getElementById("single-file-" + urlIndex);
+						if (!imageElement) {
+							imageElement = doc.createElementNS(SVG_NS, "image");
+							imageElement.setAttribute("xlink:href", imgElement.src);
+							imageElement.id = "single-file-" + urlIndex;
+							defsElement.appendChild(imageElement);
+						}
 						if (!imageElement.getAttributeNS(SVG_NS, "width") && !imageElement.getAttributeNS(SVG_NS, "height")) {
 							imageElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + width + " " + height);
 							imageElement.setAttributeNS(SVG_NS, "width", width);