mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: embed scene support for png export in npm package (#5047)
* feat: embed scene support for png export in npm package * move logic to the callback function * add exportEmbedScene checkbox in package example * update readme and changelog * add PR link in changelog * reverse sort changelog items
This commit is contained in:
parent
52d10bb41e
commit
3840e2f4e6
4 changed files with 32 additions and 3 deletions
|
@ -8,6 +8,8 @@ import { ExcalidrawElement, NonDeleted } from "../element/types";
|
|||
import { getNonDeletedElements } from "../element";
|
||||
import { restore } from "../data/restore";
|
||||
import { MIME_TYPES } from "../constants";
|
||||
import { encodePngMetadata } from "../data/image";
|
||||
import { serializeAsJSON } from "../data/json";
|
||||
|
||||
type ExportOpts = {
|
||||
elements: readonly NonDeleted<ExcalidrawElement>[];
|
||||
|
@ -107,7 +109,22 @@ export const exportToBlob = async (
|
|||
|
||||
return new Promise((resolve) => {
|
||||
canvas.toBlob(
|
||||
(blob: Blob | null) => {
|
||||
async (blob: Blob | null) => {
|
||||
if (
|
||||
blob &&
|
||||
mimeType === MIME_TYPES.png &&
|
||||
opts.appState?.exportEmbedScene
|
||||
) {
|
||||
blob = await encodePngMetadata({
|
||||
blob,
|
||||
metadata: serializeAsJSON(
|
||||
opts.elements,
|
||||
opts.appState,
|
||||
opts.files || {},
|
||||
"local",
|
||||
),
|
||||
});
|
||||
}
|
||||
resolve(blob);
|
||||
},
|
||||
mimeType,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue