mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
minor changes and import buffer
This commit is contained in:
parent
6ee38ad826
commit
a89f353f5b
3 changed files with 10 additions and 6 deletions
|
@ -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,
|
||||
{
|
||||
|
|
1
packages/excalidraw/global.d.ts
vendored
1
packages/excalidraw/global.d.ts
vendored
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue