Gildas 7 лет назад
Родитель
Сommit
6ca69945e9
2 измененных файлов с 4 добавлено и 2 удалено
  1. 1 1
      lib/single-file/doc-helper.js
  2. 3 1
      lib/single-file/html-images-minifier.js

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

@@ -194,7 +194,7 @@ this.docHelper = this.docHelper || (() => {
 	function getSize(imageElement) {
 		const computedStyle = getComputedStyle(imageElement);
 		let width, height, paddingLeft, paddingRight, paddingTop, paddingBottom;
-		if (computedStyle.getPropertyValue("box-sizing") == "border-box") {
+		if (computedStyle.getPropertyValue("box-sizing") == "content-box") {
 			paddingLeft = paddingRight = paddingTop = paddingBottom = 0;
 		} else {
 			paddingLeft = getWidth("padding-left", computedStyle);

+ 3 - 1
lib/single-file/html-images-minifier.js

@@ -26,7 +26,7 @@ this.imagesMinifier = this.imagesMinifier || (() => {
 	const SVG_NS = "http://www.w3.org/2000/svg";
 	const PREFIX_DATA_URI_IMAGE_SVG = "data:image/svg+xml";
 	const SINGLE_FILE_IMAGE_ATTRIBUTE = "single-file-ref";
-	const IGNORED_ATTRIBUTES = ["src", "viewBox", "preserveAspectRatio", "xlink:href", "title", "class"];
+	const IGNORED_ATTRIBUTES = ["src", "viewBox", "preserveAspectRatio", "xlink:href", "title", "class", "style"];
 	const SINGLE_FILE_SELECTOR = {
 		type: "attribute",
 		action: "exists",
@@ -178,6 +178,8 @@ this.imagesMinifier = this.imagesMinifier || (() => {
 							svgElement.appendChild(titleElement);
 						}
 						svgElement.setAttribute(SINGLE_FILE_IMAGE_ATTRIBUTE, "");
+						const style = svgElement.getAttribute("style") || "";
+						svgElement.setAttribute("style", style + (style && ";") + "box-sizing:content-box!important;width:" + imageData.clientWidth + "px!important;" + "height:" + imageData.clientHeight + "px!important");
 						svgElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + width + " " + height);
 						svgElement.setAttributeNS(SVG_NS, "width", imageData.clientWidth);
 						svgElement.setAttributeNS(SVG_NS, "height", imageData.clientHeight);