feat: placeholder rects for images
This commit is contained in:
parent
f108129222
commit
1bb6be50b1
1 changed files with 12 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue