|
|
@@ -24,6 +24,8 @@ this.imagesMinifier = this.imagesMinifier || (() => {
|
|
|
|
|
|
const DEBUG = false;
|
|
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
|
+ const PREFIX_DATA_URI_IMAGE_SVG = "data:image/svg+xml";
|
|
|
+ const TRANSFORMED_IMAGE_ATTRIBUTE = "data-single-file-image-transform";
|
|
|
|
|
|
return {
|
|
|
process: (doc, mediaAllInfo, options) => {
|
|
|
@@ -40,6 +42,21 @@ this.imagesMinifier = this.imagesMinifier || (() => {
|
|
|
processStyleSheets(doc, duplicates, mediaAllInfo);
|
|
|
processImages(doc, duplicates, duplicateURLs, options);
|
|
|
}
|
|
|
+ },
|
|
|
+ postProcess(doc) {
|
|
|
+ doc.querySelectorAll("svg[" + TRANSFORMED_IMAGE_ATTRIBUTE + "]").forEach(svgElement => {
|
|
|
+ const useElement = svgElement.childNodes[0];
|
|
|
+ if (useElement) {
|
|
|
+ const refImageId = useElement.getAttribute("xlink:href").substring(1);
|
|
|
+ if (refImageId) {
|
|
|
+ const refImageElement = doc.getElementById(refImageId);
|
|
|
+ if (refImageElement && refImageElement.getAttribute("xlink:href").startsWith(PREFIX_DATA_URI_IMAGE_SVG)) {
|
|
|
+ svgElement.removeAttributeNS(SVG_NS, "preserveAspectRatio");
|
|
|
+ svgElement.removeAttributeNS(SVG_NS, TRANSFORMED_IMAGE_ATTRIBUTE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -111,12 +128,11 @@ this.imagesMinifier = this.imagesMinifier || (() => {
|
|
|
const useElement = doc.createElementNS(SVG_NS, "use");
|
|
|
svgElement.appendChild(useElement);
|
|
|
imgElement.getAttributeNames().forEach(attributeName => attributeName != "src" && svgElement.setAttribute(attributeName, imgElement.getAttribute(attributeName)));
|
|
|
+ svgElement.setAttribute(TRANSFORMED_IMAGE_ATTRIBUTE, "");
|
|
|
svgElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + width + " " + height);
|
|
|
svgElement.setAttributeNS(SVG_NS, "width", imageData.clientWidth);
|
|
|
svgElement.setAttributeNS(SVG_NS, "height", imageData.clientHeight);
|
|
|
- if (!imgElement.src.includes(".svg")) { // FIXME
|
|
|
- svgElement.setAttributeNS(SVG_NS, "preserveAspectRatio", "none");
|
|
|
- }
|
|
|
+ svgElement.setAttributeNS(SVG_NS, "preserveAspectRatio", "none");
|
|
|
useElement.setAttributeNS(SVG_NS, "xlink:href", "#single-file-" + urlIndex);
|
|
|
const imageElement = doc.getElementById("single-file-" + urlIndex);
|
|
|
if (!imageElement.getAttributeNS(SVG_NS, "width") && !imageElement.getAttributeNS(SVG_NS, "height")) {
|