From 770f44019a12f66159bb6bd536e9efdf26250cc4 Mon Sep 17 00:00:00 2001 From: Gabriel Gomes Date: Sat, 29 Mar 2025 22:02:22 +0000 Subject: [PATCH] changed metadata output --- packages/excalidraw/data/image.ts | 22 +++++++++++++++++++--- packages/excalidraw/global.d.ts | 2 ++ yarn.lock | 12 ++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/excalidraw/data/image.ts b/packages/excalidraw/data/image.ts index 941c5fcdd..070889fdf 100644 --- a/packages/excalidraw/data/image.ts +++ b/packages/excalidraw/data/image.ts @@ -14,14 +14,30 @@ import { encode, decode } from "./encode"; export const getMetadataChunk = async ( blob: Blob, -): Promise<{ keyword: string; text: string } | null> => { +): Promise<{ + keyword: string; + text: string; + compressionFlag?: boolean; + compressionMethod?: number; + languageTag?: string; + translatedKeyword?: string; + } | null> => { const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob))); const iTXtChunk = chunks.find((chunk) => chunk.name === "iTXt"); + if (iTXtChunk) { try { const decoded = decodeITXt(iTXtChunk.data); - return { keyword: decoded.keyword, text: decoded.text }; + console.log("Decoded iTXt chunk:", decoded); + return { + keyword: decoded.keyword, + text: decoded.text, + compressionFlag: decoded.compressed, + compressionMethod: decoded.compressedMethod, + languageTag: decoded.language || "", + translatedKeyword: decoded.translated || "" + }; } catch (error) { console.error("Failed to decode iTXt chunk:", error); } @@ -45,7 +61,7 @@ export const encodePngMetadata = async ({ useITXt?: boolean; }) => { const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob))); - + debugger; const filteredChunks = chunks.filter( (chunk) => !(chunk.name === "tEXt" && diff --git a/packages/excalidraw/global.d.ts b/packages/excalidraw/global.d.ts index e6ed123dc..8688d354b 100644 --- a/packages/excalidraw/global.d.ts +++ b/packages/excalidraw/global.d.ts @@ -51,6 +51,8 @@ declare module "png-chunk-itxt" { function decode(data: Uint8Array): { keyword: string; text: string; + compressed?: boolean; + compressedMethod?: number; language?: string; translated?: string; }; diff --git a/yarn.lock b/yarn.lock index ccd0827fb..30a203b2b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3882,6 +3882,11 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522" integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== +binary-parser@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/binary-parser/-/binary-parser-2.2.1.tgz#4edc6da2dc56db73fa5ba450dfe6382ede8294ce" + integrity sha512-5ATpz/uPDgq5GgEDxTB4ouXCde7q2lqAQlSdBRQVl/AJnxmQmhIfyxJx+0MGu//D5rHQifkfGbWWlaysG0o9NA== + bl@^4.0.3: version "4.1.0" resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" @@ -7919,6 +7924,13 @@ pkg-dir@4.2.0: dependencies: find-up "^4.0.0" +png-chunk-itxt@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/png-chunk-itxt/-/png-chunk-itxt-1.0.0.tgz#4652547b7c88d512337599e422b7431f2c234355" + integrity sha512-/1gTTBlIBUL47FS1wXI5oW5zidHge1Lwn+w4WNsnTc6wu1i82l63hwz0mgw1x2eYFH4iYkHkmKH0FHoHYMmjig== + dependencies: + binary-parser "^2.2.1" + png-chunk-text@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/png-chunk-text/-/png-chunk-text-1.0.0.tgz#1c6006d8e34ba471d38e1c9c54b3f53e1085e18f"