diff --git a/packages/excalidraw/data/image.ts b/packages/excalidraw/data/image.ts index 5796f42fc..4d72a26a4 100644 --- a/packages/excalidraw/data/image.ts +++ b/packages/excalidraw/data/image.ts @@ -1,5 +1,5 @@ import tEXt from "png-chunk-text"; -import { encodeSync, decodeSync} from "png-chunk-itxt"; +import * as iTXt from "png-chunk-itxt"; import encodePng from "png-chunks-encode"; import decodePng from "png-chunks-extract"; @@ -28,7 +28,7 @@ export const getMetadataChunk = async ( if (iTXtChunk) { try { - const decoded = decodeSync(iTXtChunk.data); + const decoded = iTXt.decodeSync(iTXtChunk.data); console.log("Decoded iTXt chunk:", decoded); return { keyword: decoded.keyword, @@ -61,13 +61,13 @@ export const encodePngMetadata = async ({ useITXt?: boolean; }) => { const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob))); - debugger; + const filteredChunks = chunks.filter( (chunk) => !(chunk.name === "tEXt" && tEXt.decode(chunk.data).keyword === MIME_TYPES.excalidraw) && !(chunk.name === "iTXt" && - decodeSync(chunk.data).keyword === MIME_TYPES.excalidraw) + iTXt.decodeSync(chunk.data).keyword === MIME_TYPES.excalidraw) ); const encodedData = JSON.stringify( @@ -80,7 +80,7 @@ export const encodePngMetadata = async ({ let metadataChunk; try { if (useITXt) { - metadataChunk = encodeSync( + metadataChunk = iTXt.encodeSync( MIME_TYPES.excalidraw, encodedData, { diff --git a/packages/excalidraw/global.d.ts b/packages/excalidraw/global.d.ts index efbaa9292..6a142748e 100644 --- a/packages/excalidraw/global.d.ts +++ b/packages/excalidraw/global.d.ts @@ -56,7 +56,6 @@ declare module "png-chunk-itxt" { language?: string; translated?: string; }; - export { encodeSync, decodeSync }; } declare module "png-chunks-encode" { function encode(chunks: (TEXtChunk | ITXtChunk)[]): Uint8Array; diff --git a/packages/utils/src/export.ts b/packages/utils/src/export.ts index 347bf971d..6e122eff9 100644 --- a/packages/utils/src/export.ts +++ b/packages/utils/src/export.ts @@ -19,6 +19,11 @@ import type { NonDeleted, } from "@excalidraw/element/types"; import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types"; +import { Buffer } from "buffer"; + +window.onload = () => { + window.Buffer = Buffer; +} export { MIME_TYPES };