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 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 encodePng from "png-chunks-encode";
|
||||||
import decodePng from "png-chunks-extract";
|
import decodePng from "png-chunks-extract";
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ export const getMetadataChunk = async (
|
||||||
|
|
||||||
if (iTXtChunk) {
|
if (iTXtChunk) {
|
||||||
try {
|
try {
|
||||||
const decoded = decodeSync(iTXtChunk.data);
|
const decoded = iTXt.decodeSync(iTXtChunk.data);
|
||||||
console.log("Decoded iTXt chunk:", decoded);
|
console.log("Decoded iTXt chunk:", decoded);
|
||||||
return {
|
return {
|
||||||
keyword: decoded.keyword,
|
keyword: decoded.keyword,
|
||||||
|
@ -61,13 +61,13 @@ export const encodePngMetadata = async ({
|
||||||
useITXt?: boolean;
|
useITXt?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
|
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
|
||||||
debugger;
|
|
||||||
const filteredChunks = chunks.filter(
|
const filteredChunks = chunks.filter(
|
||||||
(chunk) =>
|
(chunk) =>
|
||||||
!(chunk.name === "tEXt" &&
|
!(chunk.name === "tEXt" &&
|
||||||
tEXt.decode(chunk.data).keyword === MIME_TYPES.excalidraw) &&
|
tEXt.decode(chunk.data).keyword === MIME_TYPES.excalidraw) &&
|
||||||
!(chunk.name === "iTXt" &&
|
!(chunk.name === "iTXt" &&
|
||||||
decodeSync(chunk.data).keyword === MIME_TYPES.excalidraw)
|
iTXt.decodeSync(chunk.data).keyword === MIME_TYPES.excalidraw)
|
||||||
);
|
);
|
||||||
|
|
||||||
const encodedData = JSON.stringify(
|
const encodedData = JSON.stringify(
|
||||||
|
@ -80,7 +80,7 @@ export const encodePngMetadata = async ({
|
||||||
let metadataChunk;
|
let metadataChunk;
|
||||||
try {
|
try {
|
||||||
if (useITXt) {
|
if (useITXt) {
|
||||||
metadataChunk = encodeSync(
|
metadataChunk = iTXt.encodeSync(
|
||||||
MIME_TYPES.excalidraw,
|
MIME_TYPES.excalidraw,
|
||||||
encodedData,
|
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;
|
language?: string;
|
||||||
translated?: string;
|
translated?: string;
|
||||||
};
|
};
|
||||||
export { encodeSync, decodeSync };
|
|
||||||
}
|
}
|
||||||
declare module "png-chunks-encode" {
|
declare module "png-chunks-encode" {
|
||||||
function encode(chunks: (TEXtChunk | ITXtChunk)[]): Uint8Array;
|
function encode(chunks: (TEXtChunk | ITXtChunk)[]): Uint8Array;
|
||||||
|
|
|
@ -19,6 +19,11 @@ import type {
|
||||||
NonDeleted,
|
NonDeleted,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
|
import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
|
||||||
|
import { Buffer } from "buffer";
|
||||||
|
|
||||||
|
window.onload = () => {
|
||||||
|
window.Buffer = Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
export { MIME_TYPES };
|
export { MIME_TYPES };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue