Compare commits
3 Commits
master
...
zsviczian-
Author | SHA1 | Date | |
---|---|---|---|
|
9bf3466cca | ||
|
9a10503c5f | ||
|
d87e080e88 |
@ -15,6 +15,18 @@ import Scene from "./Scene";
|
|||||||
|
|
||||||
export const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
|
export const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
|
||||||
|
|
||||||
|
const createScene = (
|
||||||
|
elements: readonly NonDeletedExcalidrawElement[],
|
||||||
|
): Scene | null => {
|
||||||
|
if (!elements || Scene.getScene(elements[0])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const scene = new Scene();
|
||||||
|
scene.replaceAllElements(elements);
|
||||||
|
elements?.forEach((el) => Scene.mapElementToScene(el, scene));
|
||||||
|
return scene;
|
||||||
|
};
|
||||||
|
|
||||||
export const exportToCanvas = async (
|
export const exportToCanvas = async (
|
||||||
elements: readonly NonDeletedExcalidrawElement[],
|
elements: readonly NonDeletedExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
@ -38,6 +50,7 @@ export const exportToCanvas = async (
|
|||||||
return { canvas, scale: appState.exportScale };
|
return { canvas, scale: appState.exportScale };
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
|
const scene = createScene(elements);
|
||||||
const [minX, minY, width, height] = getCanvasSize(elements, exportPadding);
|
const [minX, minY, width, height] = getCanvasSize(elements, exportPadding);
|
||||||
|
|
||||||
const { canvas, scale = 1 } = createCanvas(width, height);
|
const { canvas, scale = 1 } = createCanvas(width, height);
|
||||||
@ -79,6 +92,7 @@ export const exportToCanvas = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scene?.destroy();
|
||||||
return canvas;
|
return canvas;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,6 +119,7 @@ export const exportToSvg = async (
|
|||||||
exportScale = 1,
|
exportScale = 1,
|
||||||
exportEmbedScene,
|
exportEmbedScene,
|
||||||
} = appState;
|
} = appState;
|
||||||
|
const scene = createScene(elements);
|
||||||
let metadata = "";
|
let metadata = "";
|
||||||
if (exportEmbedScene) {
|
if (exportEmbedScene) {
|
||||||
try {
|
try {
|
||||||
@ -217,6 +232,7 @@ export const exportToSvg = async (
|
|||||||
renderEmbeddables: opts?.renderEmbeddables,
|
renderEmbeddables: opts?.renderEmbeddables,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scene?.destroy();
|
||||||
return svgRoot;
|
return svgRoot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user