feat: placeholder rects for images

This commit is contained in:
Tomáš Mládek 2022-12-08 00:14:18 +01:00
parent f108129222
commit 1bb6be50b1

View file

@ -391,9 +391,9 @@
return result;
}
function processImages(document: SVGElement): SVGImageElement[] {
function processImages(svgDocument: SVGElement): SVGImageElement[] {
const result: SVGImageElement[] = [];
Array.from(document.getElementsByTagName("image")).forEach((image) => {
Array.from(svgDocument.getElementsByTagName("image")).forEach((image) => {
const href = image.getAttribute("xlink:href");
console.debug(`[SVG/IMAGES] Found image #${image.id} (${href}).`);
const origPath = href.split("/");
@ -401,6 +401,16 @@
newHref = newHref.replace(/jpg$/, "webp");
image.setAttribute("xlink:href", newHref);
result.push(image);
const placeholderRect = document.createElementNS(
"http://www.w3.org/2000/svg",
"rect"
);
placeholderRect.setAttribute("fill", "lightgray");
["x", "y", "width", "height"].forEach((attr) => {
placeholderRect.setAttribute(attr, image.getAttribute(attr));
});
image.parentElement.prepend(placeholderRect);
});
return result;
}