@myoc/excalidraw 0.19.544 → 0.19.545

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dev/index.js CHANGED
@@ -65,10 +65,10 @@ import {
65
65
  serializeAsJSON,
66
66
  strokeRectWithRotation_simple,
67
67
  zoomToFitBounds
68
- } from "./chunk-DPY7NUSG.js";
68
+ } from "./chunk-GWV63UBO.js";
69
69
  import {
70
70
  define_import_meta_env_default
71
- } from "./chunk-AKYL2SH7.js";
71
+ } from "./chunk-CK7JCUHP.js";
72
72
  import {
73
73
  en_default
74
74
  } from "./chunk-35XUJXYN.js";
@@ -10437,11 +10437,36 @@ var serializeAsClipboardJSON = ({
10437
10437
  };
10438
10438
  return JSON.stringify(contents);
10439
10439
  };
10440
+ var convertImageFileToPNG = async (file2) => {
10441
+ const bitmap = await createImageBitmap(file2);
10442
+ try {
10443
+ const canvas = document.createElement("canvas");
10444
+ canvas.width = bitmap.width;
10445
+ canvas.height = bitmap.height;
10446
+ const context = canvas.getContext("2d");
10447
+ if (!context) {
10448
+ throw new Error("Could not create a canvas context for clipboard image");
10449
+ }
10450
+ context.drawImage(bitmap, 0, 0);
10451
+ return await new Promise((resolve, reject) => {
10452
+ canvas.toBlob((blob) => {
10453
+ if (blob) {
10454
+ resolve(blob);
10455
+ } else {
10456
+ reject(new Error("Could not encode clipboard image as PNG"));
10457
+ }
10458
+ }, MIME_TYPES2.png);
10459
+ });
10460
+ } finally {
10461
+ bitmap.close();
10462
+ }
10463
+ };
10440
10464
  var copyToClipboard = async (elements, files, clipboardEvent) => {
10441
10465
  const json = serializeAsClipboardJSON({ elements, files });
10442
10466
  const imageFile = elements.length === 1 && isInitializedImageElement(elements[0]) ? files?.[elements[0].fileId] : null;
10443
10467
  const clipboardFile = imageFile && isSupportedImageFileType(imageFile.mimeType) && imageFile.dataURL ? dataURLToFile(imageFile.dataURL, imageFile.fileName) : null;
10444
10468
  if (clipboardFile) {
10469
+ const clipboardImagePNG = clipboardFile.type === MIME_TYPES2.png ? clipboardFile : convertImageFileToPNG(clipboardFile);
10445
10470
  if (supportsClipboardBlob()) {
10446
10471
  try {
10447
10472
  await navigator.clipboard.write([
@@ -10449,7 +10474,7 @@ var copyToClipboard = async (elements, files, clipboardEvent) => {
10449
10474
  [WEB_EXCALIDRAW_CLIPBOARD_MIME_TYPE]: new Blob([json], {
10450
10475
  type: MIME_TYPES2.excalidrawClipboard
10451
10476
  }),
10452
- [clipboardFile.type]: clipboardFile
10477
+ [MIME_TYPES2.png]: clipboardImagePNG
10453
10478
  })
10454
10479
  ]);
10455
10480
  return;
@@ -10459,7 +10484,12 @@ var copyToClipboard = async (elements, files, clipboardEvent) => {
10459
10484
  }
10460
10485
  if (clipboardEvent?.clipboardData?.items) {
10461
10486
  try {
10462
- clipboardEvent.clipboardData.items.add(clipboardFile);
10487
+ const clipboardImageFile = clipboardFile.type === MIME_TYPES2.png ? clipboardFile : new File(
10488
+ [await clipboardImagePNG],
10489
+ `${clipboardFile.name.replace(/\.[^/.]+$/, "") || "image"}.png`,
10490
+ { type: MIME_TYPES2.png }
10491
+ );
10492
+ clipboardEvent.clipboardData.items.add(clipboardImageFile);
10463
10493
  await copyTextToSystemClipboard(
10464
10494
  { [MIME_TYPES2.excalidrawClipboard]: json },
10465
10495
  clipboardEvent
@@ -11014,7 +11044,7 @@ var exportCanvas = async (type, elements, appState, files, {
11014
11044
  let blob = canvasToBlob(tempCanvas);
11015
11045
  if (appState.exportEmbedScene) {
11016
11046
  blob = blob.then(
11017
- (blob2) => import("./data/image-AIHWJUYD.js").then(
11047
+ (blob2) => import("./data/image-LHD6YZAK.js").then(
11018
11048
  ({ encodePngMetadata: encodePngMetadata2 }) => encodePngMetadata2({
11019
11049
  blob: blob2,
11020
11050
  metadata: serializeAsJSON(elements, appState, files, "local")
@@ -15250,7 +15280,12 @@ import { arrayToMap as arrayToMap23, findIndex, findLastIndex as findLastIndex2
15250
15280
  import { isFiniteNumber } from "@excalidraw/math";
15251
15281
 
15252
15282
  // ../element/src/gif.ts
15253
- import { decode, decodeFrames } from "modern-gif";
15283
+ import { decodeAnimated } from "@discourse/gif";
15284
+ var GIF_WORKER_FILENAME = "gif.worker.js";
15285
+ var gifWorkerUrl = new URL(
15286
+ GIF_WORKER_FILENAME,
15287
+ import.meta.url
15288
+ ).toString();
15254
15289
 
15255
15290
  // ../element/src/image.ts
15256
15291
  import {
@@ -31768,21 +31803,34 @@ var GifPlaybackControls = ({
31768
31803
  app.ensureGifPlaybackLoop();
31769
31804
  }
31770
31805
  };
31771
- const deferredGifBadges = app.scene.getNonDeletedElements().filter(
31772
- (element) => isInitializedImageElement4(element) && !liveAppState.selectedElementIds[element.id] && files[element.fileId]?.mimeType === MIME_TYPES10.gif && app.imageCache.get(element.fileId)?.gifDecodeStatus === "deferred"
31773
- ).map((element) => {
31806
+ const deferredGifControls = app.scene.getNonDeletedElements().flatMap((element) => {
31807
+ if (!isInitializedImageElement4(element) || files[element.fileId]?.mimeType !== MIME_TYPES10.gif || app.imageCache.get(element.fileId)?.gifDecodeStatus !== "deferred") {
31808
+ return [];
31809
+ }
31774
31810
  const position = getGifControlPosition(element, liveAppState);
31775
- return /* @__PURE__ */ jsx113(
31776
- "span",
31777
- {
31778
- className: "gif-playback-controls gif-playback-controls__deferred-badge",
31779
- role: "img",
31780
- "aria-label": "GIF paused",
31781
- style: position,
31782
- children: CirclePauseIcon
31783
- },
31784
- element.id
31785
- );
31811
+ return [
31812
+ /* @__PURE__ */ jsx113(
31813
+ "div",
31814
+ {
31815
+ className: "gif-playback-controls gif-playback-controls--deferred",
31816
+ style: position,
31817
+ onPointerDown: (event) => event.stopPropagation(),
31818
+ children: /* @__PURE__ */ jsx113(
31819
+ "button",
31820
+ {
31821
+ type: "button",
31822
+ className: "gif-playback-controls__load-large",
31823
+ title: "Load Large GIF",
31824
+ onClick: () => {
31825
+ app.loadDeferredGif(element.fileId);
31826
+ },
31827
+ children: "Load Large GIF"
31828
+ }
31829
+ )
31830
+ },
31831
+ element.id
31832
+ )
31833
+ ];
31786
31834
  });
31787
31835
  const selectedElements = app.scene.getSelectedElements(liveAppState);
31788
31836
  const selectedElementControls = () => {
@@ -31813,29 +31861,6 @@ var GifPlaybackControls = ({
31813
31861
  leftTop.y - liveAppState.offsetTop + 16
31814
31862
  )
31815
31863
  );
31816
- if (cacheEntry?.gifDecodeStatus === "deferred") {
31817
- const position = getGifControlPosition(selectedElement, liveAppState);
31818
- return /* @__PURE__ */ jsx113(
31819
- "div",
31820
- {
31821
- className: "gif-playback-controls gif-playback-controls--deferred",
31822
- style: position,
31823
- onPointerDown: (event) => event.stopPropagation(),
31824
- children: /* @__PURE__ */ jsx113(
31825
- "button",
31826
- {
31827
- type: "button",
31828
- className: "gif-playback-controls__load-large",
31829
- title: "Load Large GIF",
31830
- onClick: () => {
31831
- app.loadDeferredGif(selectedElement.fileId);
31832
- },
31833
- children: "Load Large GIF"
31834
- }
31835
- )
31836
- }
31837
- );
31838
- }
31839
31864
  if (cacheEntry?.gifDecodeStatus === "pending") {
31840
31865
  return null;
31841
31866
  }
@@ -32182,7 +32207,7 @@ var GifPlaybackControls = ({
32182
32207
  );
32183
32208
  };
32184
32209
  return /* @__PURE__ */ jsxs59(Fragment18, { children: [
32185
- deferredGifBadges,
32210
+ deferredGifControls,
32186
32211
  selectedElementControls()
32187
32212
  ] });
32188
32213
  };