mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
cache the custom image element and improve jittering experience
This commit is contained in:
parent
39d0084a5e
commit
61699ff3c2
1 changed files with 17 additions and 3 deletions
|
@ -6,6 +6,7 @@ import {
|
|||
NonDeletedExcalidrawElement,
|
||||
ExcalidrawFreeDrawElement,
|
||||
ExcalidrawImageElement,
|
||||
ExcalidrawCustomElement,
|
||||
} from "../element/types";
|
||||
import {
|
||||
isTextElement,
|
||||
|
@ -189,6 +190,9 @@ const drawImagePlaceholder = (
|
|||
);
|
||||
};
|
||||
|
||||
const customElementImgCache: {
|
||||
[key: ExcalidrawCustomElement["name"]]: HTMLImageElement;
|
||||
} = {};
|
||||
const drawElementOnCanvas = (
|
||||
element: NonDeletedExcalidrawElement,
|
||||
rc: RoughCanvas,
|
||||
|
@ -254,10 +258,20 @@ const drawElementOnCanvas = (
|
|||
case "custom": {
|
||||
const config = renderConfig.customElementsConfig?.find(
|
||||
(config) => config.name === element.name,
|
||||
)!;
|
||||
if (!customElementImgCache[config.name]) {
|
||||
const img = document.createElement("img");
|
||||
img.id = config.name;
|
||||
img.src = config.svg;
|
||||
customElementImgCache[img.id] = img;
|
||||
}
|
||||
context.drawImage(
|
||||
customElementImgCache[config.name],
|
||||
0,
|
||||
0,
|
||||
element.width,
|
||||
element.height,
|
||||
);
|
||||
const img = document.createElement("img");
|
||||
img.src = config!.svg;
|
||||
context.drawImage(img, 0, 0, element.width, element.height);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue