cache svg with element id
This commit is contained in:
parent
d2d3599661
commit
4e75f10b2c
@ -269,39 +269,46 @@ const drawElementOnCanvas = (
|
|||||||
if (!config) {
|
if (!config) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!customElementImgCache[config.customType]) {
|
if (typeof config.svg === "string") {
|
||||||
const img = document.createElement("img");
|
if (!customElementImgCache[element.id]) {
|
||||||
img.id = config.customType;
|
const img = document.createElement("img");
|
||||||
if (typeof config.svg === "string") {
|
|
||||||
img.src = config.svg;
|
img.src = config.svg;
|
||||||
} else {
|
img.id = element.id;
|
||||||
const svg = config.svg(element);
|
customElementImgCache[img.id] = img;
|
||||||
if (svg instanceof Promise) {
|
}
|
||||||
svg.then((res) => {
|
} else if (typeof config.svg === "function") {
|
||||||
|
const svg = config.svg(element);
|
||||||
|
if (svg instanceof Promise) {
|
||||||
|
svg.then((res) => {
|
||||||
|
if (!customElementImgCache[element.id]) {
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.id = element.id;
|
||||||
img.src = res;
|
img.src = res;
|
||||||
customElementImgCache[img.id] = img;
|
customElementImgCache[img.id] = img;
|
||||||
|
|
||||||
context.drawImage(
|
context.drawImage(
|
||||||
customElementImgCache[config.customType],
|
customElementImgCache[element.id],
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
element.width,
|
element.width,
|
||||||
element.height,
|
element.height,
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
img.src = svg;
|
} else if (!customElementImgCache[element.id]) {
|
||||||
}
|
const img = document.createElement("img");
|
||||||
|
img.id = element.id;
|
||||||
|
img.src = svg;
|
||||||
|
customElementImgCache[img.id] = img;
|
||||||
}
|
}
|
||||||
customElementImgCache[img.id] = img;
|
|
||||||
}
|
}
|
||||||
context.drawImage(
|
context.drawImage(
|
||||||
customElementImgCache[config.customType],
|
customElementImgCache[element.id],
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
element.width,
|
element.width,
|
||||||
element.height,
|
element.height,
|
||||||
);
|
);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user