|
@@ -104,23 +104,28 @@ this.imagesMinifier = this.imagesMinifier || (() => {
|
|
|
if (urlIndex != -1) {
|
|
if (urlIndex != -1) {
|
|
|
const dataAttributeName = docHelper.imagesAttributeName(options.sessionId);
|
|
const dataAttributeName = docHelper.imagesAttributeName(options.sessionId);
|
|
|
const imageData = options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
const imageData = options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
- const svgElement = doc.createElementNS(SVG_NS, "svg");
|
|
|
|
|
- const useElement = doc.createElementNS(SVG_NS, "use");
|
|
|
|
|
- svgElement.appendChild(useElement);
|
|
|
|
|
- imgElement.getAttributeNames().forEach(attributeName => attributeName != "src" && svgElement.setAttribute(attributeName, imgElement.getAttribute(attributeName)));
|
|
|
|
|
- svgElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + imageData.naturalWidth + " " + imageData.naturalHeight);
|
|
|
|
|
- svgElement.setAttributeNS(SVG_NS, "width", imageData.clientWidth);
|
|
|
|
|
- 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);
|
|
|
|
|
- if (!imageElement.getAttributeNS(SVG_NS, "width") && !imageElement.getAttributeNS(SVG_NS, "height") && imageData.naturalWidth && imageData.naturalHeight) {
|
|
|
|
|
- imageElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + imageData.naturalWidth + " " + imageData.naturalHeight);
|
|
|
|
|
- imageElement.setAttributeNS(SVG_NS, "width", imageData.naturalWidth);
|
|
|
|
|
- imageElement.setAttributeNS(SVG_NS, "height", imageData.naturalHeight);
|
|
|
|
|
|
|
+ const width = (imageData.naturalWidth > 1 && imageData.naturalWidth) || imageData.width;
|
|
|
|
|
+ const height = (imageData.naturalHeight > 1 && imageData.naturalHeight) || imageData.height;
|
|
|
|
|
+ if (width > 1 && height > 1) {
|
|
|
|
|
+ const svgElement = doc.createElementNS(SVG_NS, "svg");
|
|
|
|
|
+ const useElement = doc.createElementNS(SVG_NS, "use");
|
|
|
|
|
+ svgElement.appendChild(useElement);
|
|
|
|
|
+ imgElement.getAttributeNames().forEach(attributeName => attributeName != "src" && svgElement.setAttribute(attributeName, imgElement.getAttribute(attributeName)));
|
|
|
|
|
+ svgElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + width + " " + height);
|
|
|
|
|
+ svgElement.setAttributeNS(SVG_NS, "width", imageData.clientWidth);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ imageElement.setAttributeNS(SVG_NS, "height", height);
|
|
|
|
|
+ }
|
|
|
|
|
+ // svgElement.style.border = "1px solid red";
|
|
|
|
|
+ imgElement.parentElement.replaceChild(svgElement, imgElement);
|
|
|
}
|
|
}
|
|
|
- // svgElement.style.border = "1px solid red";
|
|
|
|
|
- imgElement.parentElement.replaceChild(svgElement, imgElement);
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|