|
@@ -31,7 +31,7 @@ this.imagesMinifier = this.imagesMinifier || (() => {
|
|
|
let duplicates = new Set();
|
|
let duplicates = new Set();
|
|
|
const duplicateURLs = [];
|
|
const duplicateURLs = [];
|
|
|
imageGroups.forEach((elements, src) => {
|
|
imageGroups.forEach((elements, src) => {
|
|
|
- if (elements.length > 1) {
|
|
|
|
|
|
|
+ if (elements.length > 1 && src && src != options.baseURI) {
|
|
|
elements.forEach(element => duplicates.add(element));
|
|
elements.forEach(element => duplicates.add(element));
|
|
|
duplicateURLs.push(src);
|
|
duplicateURLs.push(src);
|
|
|
}
|
|
}
|
|
@@ -100,25 +100,28 @@ this.imagesMinifier = this.imagesMinifier || (() => {
|
|
|
replaceImage = !Object.keys(ignoredAttributeNames).map(key => ignoredAttributeNames[key]).find(attributeName => imgElement.getAttribute(attributeName));
|
|
replaceImage = !Object.keys(ignoredAttributeNames).map(key => ignoredAttributeNames[key]).find(attributeName => imgElement.getAttribute(attributeName));
|
|
|
}
|
|
}
|
|
|
if (replaceImage && duplicates.has(imgElement)) {
|
|
if (replaceImage && duplicates.has(imgElement)) {
|
|
|
- const dataAttributeName = docHelper.imagesAttributeName(options.sessionId);
|
|
|
|
|
- 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");
|
|
|
|
|
const urlIndex = duplicateURLs.indexOf(imgElement.src);
|
|
const urlIndex = duplicateURLs.indexOf(imgElement.src);
|
|
|
- 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);
|
|
|
|
|
|
|
+ if (urlIndex != -1) {
|
|
|
|
|
+ const dataAttributeName = docHelper.imagesAttributeName(options.sessionId);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ svgElement.style.border = "1px solid red";
|
|
|
|
|
+ imgElement.parentElement.replaceChild(svgElement, imgElement);
|
|
|
}
|
|
}
|
|
|
- imgElement.parentElement.replaceChild(svgElement, imgElement);
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|