removing enum

This commit is contained in:
Gabriel Gomes 2025-03-29 21:26:51 +00:00
parent 0a6c0b5950
commit c8ccdf3716
2 changed files with 7 additions and 11 deletions

View file

@ -17,7 +17,7 @@ export const getMetadataChunk = async (
): Promise<{ keyword: string; text: string } | null> => { ): Promise<{ keyword: string; text: string } | null> => {
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob))); const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
const iTXtChunk = chunks.find((chunk) => chunk.name === PNGChunkType.iTXt); const iTXtChunk = chunks.find((chunk) => chunk.name === "iTXt");
if (iTXtChunk) { if (iTXtChunk) {
try { try {
const decoded = decodeITXt(iTXtChunk.data); const decoded = decodeITXt(iTXtChunk.data);
@ -27,7 +27,7 @@ export const getMetadataChunk = async (
} }
} }
const tEXtChunk = chunks.find((chunk) => chunk.name === PNGChunkType.tEXt); const tEXtChunk = chunks.find((chunk) => chunk.name === "tEXt");
if (tEXtChunk) { if (tEXtChunk) {
return tEXt.decode(tEXtChunk.data); return tEXt.decode(tEXtChunk.data);
} }
@ -48,9 +48,9 @@ export const encodePngMetadata = async ({
const filteredChunks = chunks.filter( const filteredChunks = chunks.filter(
(chunk) => (chunk) =>
!(chunk.name === PNGChunkType.tEXt && !(chunk.name === "tEXt" &&
tEXt.decode(chunk.data).keyword === MIME_TYPES.excalidraw) && tEXt.decode(chunk.data).keyword === MIME_TYPES.excalidraw) &&
!(chunk.name === PNGChunkType.iTXt && !(chunk.name === "iTXt" &&
decodeITXt(chunk.data).keyword === MIME_TYPES.excalidraw) decodeITXt(chunk.data).keyword === MIME_TYPES.excalidraw)
); );

View file

@ -32,18 +32,14 @@ interface Clipboard extends EventTarget {
// PNG encoding/decoding // PNG encoding/decoding
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
enum PNGChunkType {
tEXt = "tEXt",
iTXt = "iTXt",
}
type TEXtChunk = { name: "tEXt"; data: Uint8Array }; type TEXtChunk = { name: "tEXt"; data: Uint8Array };
type ITXtChunk = { name: "iTXt"; data: Uint8Array }; type ITXtChunk = { name: "iTXt"; data: Uint8Array };
declare module "png-chunk-text" { declare module "png-chunk-text" {
function encode( function encode(
name: string, name: string,
value: string, value: string,
): { name: PNGChunkType.tEXt; data: Uint8Array }; ): { name: "tEXt"; data: Uint8Array };
function decode(data: Uint8Array): { keyword: string; text: string }; function decode(data: Uint8Array): { keyword: string; text: string };
} }
declare module "png-chunk-itxt" { declare module "png-chunk-itxt" {
@ -51,7 +47,7 @@ declare module "png-chunk-itxt" {
keyword: string, keyword: string,
text: string, text: string,
options?: { compressed?: boolean; compressedMethod: number; language?: string; translated?: string }, options?: { compressed?: boolean; compressedMethod: number; language?: string; translated?: string },
): { name: PNGChunkType.iTXt; data: Uint8Array }; ): { name: "iTXt"; data: Uint8Array };
function decode(data: Uint8Array): { function decode(data: Uint8Array): {
keyword: string; keyword: string;
text: string; text: string;