Просмотр исходного кода

pass background color of images through imageData

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

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

@@ -272,6 +272,7 @@ this.docHelper = this.docHelper || (() => {
 					imageData.empty = imageElement.naturalWidth <= 1 && imageElement.naturalHeight <= 1;
 					if ((!computedStyle.getPropertyValue("background-image") || computedStyle.getPropertyValue("background-image") == "none") && imageData.size.pxWidth > 1 && imageData.size.pxHeight > 1) {
 						imageData.replaceable = true;
+						imageData.backgroundColor = computedStyle.getPropertyValue("background-color");
 						imageData.objectFit = computedStyle.getPropertyValue("object-fit");
 						imageData.objectPosition = computedStyle.getPropertyValue("object-position");
 					}

+ 3 - 0
lib/single-file/single-file-core.js

@@ -1335,6 +1335,9 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					if (imgData.objectPosition) {
 						backgroundStyle["background-position"] = imgData.objectPosition;
 					}
+					if (imgData.backgroundColor) {
+						backgroundStyle["background-color"] = imgData.backgroundColor;
+					}
 					DomProcessorHelper.setBackgroundImage(imgElement, "var(" + variableName + ")", backgroundStyle);
 					imgElement.removeAttribute(dataAttributeName);
 					return true;