@myoc/excalidraw 0.19.543 → 0.19.544

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.
@@ -2,12 +2,12 @@ import {
2
2
  decodePngMetadata,
3
3
  encodePngMetadata,
4
4
  getTEXtChunk
5
- } from "../chunk-6OYO4QVO.js";
6
- import "../chunk-VQRWPJBP.js";
5
+ } from "../chunk-DPY7NUSG.js";
6
+ import "../chunk-AKYL2SH7.js";
7
7
  import "../chunk-XDFCUUT6.js";
8
8
  export {
9
9
  decodePngMetadata,
10
10
  encodePngMetadata,
11
11
  getTEXtChunk
12
12
  };
13
- //# sourceMappingURL=image-MKDSIQJM.js.map
13
+ //# sourceMappingURL=image-AIHWJUYD.js.map
package/dist/dev/index.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  canvasToBlob,
15
15
  constrainScrollState,
16
16
  createFile,
17
+ dataURLToFile,
17
18
  dataURLToString,
18
19
  encodePngMetadata,
19
20
  exportToCanvas,
@@ -64,10 +65,10 @@ import {
64
65
  serializeAsJSON,
65
66
  strokeRectWithRotation_simple,
66
67
  zoomToFitBounds
67
- } from "./chunk-6OYO4QVO.js";
68
+ } from "./chunk-DPY7NUSG.js";
68
69
  import {
69
70
  define_import_meta_env_default
70
- } from "./chunk-VQRWPJBP.js";
71
+ } from "./chunk-AKYL2SH7.js";
71
72
  import {
72
73
  en_default
73
74
  } from "./chunk-35XUJXYN.js";
@@ -10337,9 +10338,11 @@ import {
10337
10338
  isInitializedImageElement
10338
10339
  } from "@excalidraw/element";
10339
10340
  import { getContainingFrame } from "@excalidraw/element";
10341
+ var WEB_EXCALIDRAW_CLIPBOARD_MIME_TYPE = `web ${MIME_TYPES2.excalidrawClipboard}`;
10340
10342
  var probablySupportsClipboardReadText = "clipboard" in navigator && "readText" in navigator.clipboard;
10341
10343
  var probablySupportsClipboardWriteText = "clipboard" in navigator && "writeText" in navigator.clipboard;
10342
10344
  var probablySupportsClipboardBlob = "clipboard" in navigator && "write" in navigator.clipboard && "ClipboardItem" in window && "toBlob" in HTMLCanvasElement.prototype;
10345
+ var supportsClipboardBlob = () => "clipboard" in navigator && "write" in navigator.clipboard && "ClipboardItem" in window && "toBlob" in HTMLCanvasElement.prototype;
10343
10346
  var clipboardContainsElements = (contents) => {
10344
10347
  if ([
10345
10348
  EXPORT_DATA_TYPES.excalidraw,
@@ -10436,6 +10439,37 @@ var serializeAsClipboardJSON = ({
10436
10439
  };
10437
10440
  var copyToClipboard = async (elements, files, clipboardEvent) => {
10438
10441
  const json = serializeAsClipboardJSON({ elements, files });
10442
+ const imageFile = elements.length === 1 && isInitializedImageElement(elements[0]) ? files?.[elements[0].fileId] : null;
10443
+ const clipboardFile = imageFile && isSupportedImageFileType(imageFile.mimeType) && imageFile.dataURL ? dataURLToFile(imageFile.dataURL, imageFile.fileName) : null;
10444
+ if (clipboardFile) {
10445
+ if (supportsClipboardBlob()) {
10446
+ try {
10447
+ await navigator.clipboard.write([
10448
+ new ClipboardItem({
10449
+ [WEB_EXCALIDRAW_CLIPBOARD_MIME_TYPE]: new Blob([json], {
10450
+ type: MIME_TYPES2.excalidrawClipboard
10451
+ }),
10452
+ [clipboardFile.type]: clipboardFile
10453
+ })
10454
+ ]);
10455
+ return;
10456
+ } catch (error) {
10457
+ console.error("Error copying image with ClipboardItem", error);
10458
+ }
10459
+ }
10460
+ if (clipboardEvent?.clipboardData?.items) {
10461
+ try {
10462
+ clipboardEvent.clipboardData.items.add(clipboardFile);
10463
+ await copyTextToSystemClipboard(
10464
+ { [MIME_TYPES2.excalidrawClipboard]: json },
10465
+ clipboardEvent
10466
+ );
10467
+ return;
10468
+ } catch (error) {
10469
+ console.error("Error copying image to clipboard event", error);
10470
+ }
10471
+ }
10472
+ }
10439
10473
  await copyTextToSystemClipboard(
10440
10474
  {
10441
10475
  [MIME_TYPES2.excalidrawClipboard]: json,
@@ -10511,11 +10545,21 @@ var readSystemClipboard = async () => {
10511
10545
  }
10512
10546
  for (const item of clipboardItems) {
10513
10547
  for (const type of item.types) {
10548
+ if (type === WEB_EXCALIDRAW_CLIPBOARD_MIME_TYPE) {
10549
+ try {
10550
+ types[MIME_TYPES2.excalidrawClipboard] = await (await item.getType(type)).text();
10551
+ } catch (error) {
10552
+ console.warn(
10553
+ `Cannot retrieve ${type} from clipboardItem: ${error.message}`
10554
+ );
10555
+ }
10556
+ continue;
10557
+ }
10514
10558
  if (!isMemberOf(ALLOWED_PASTE_MIME_TYPES, type)) {
10515
10559
  continue;
10516
10560
  }
10517
10561
  try {
10518
- if (type === MIME_TYPES2.text || type === MIME_TYPES2.html) {
10562
+ if (type === MIME_TYPES2.text || type === MIME_TYPES2.html || type === MIME_TYPES2.excalidrawClipboard) {
10519
10563
  types[type] = await (await item.getType(type)).text();
10520
10564
  } else if (isSupportedImageFileType(type)) {
10521
10565
  const imageBlob = await item.getType(type);
@@ -10764,10 +10808,10 @@ var parseDataTransferEvent = async (event) => {
10764
10808
  });
10765
10809
  };
10766
10810
  var parseClipboard = async (dataList, isPlainPaste = false) => {
10767
- const parsedEventData = await parseClipboardEventTextData(
10768
- dataList,
10769
- isPlainPaste
10811
+ const excalidrawClipboardData = dataList.getData(
10812
+ MIME_TYPES2.excalidrawClipboard
10770
10813
  );
10814
+ const parsedEventData = excalidrawClipboardData ? { type: "text", value: excalidrawClipboardData } : await parseClipboardEventTextData(dataList, isPlainPaste);
10771
10815
  if (parsedEventData.type === "mixedContent") {
10772
10816
  return {
10773
10817
  mixedContent: parsedEventData.value
@@ -10970,7 +11014,7 @@ var exportCanvas = async (type, elements, appState, files, {
10970
11014
  let blob = canvasToBlob(tempCanvas);
10971
11015
  if (appState.exportEmbedScene) {
10972
11016
  blob = blob.then(
10973
- (blob2) => import("./data/image-MKDSIQJM.js").then(
11017
+ (blob2) => import("./data/image-AIHWJUYD.js").then(
10974
11018
  ({ encodePngMetadata: encodePngMetadata2 }) => encodePngMetadata2({
10975
11019
  blob: blob2,
10976
11020
  metadata: serializeAsJSON(elements, appState, files, "local")
@@ -37559,9 +37603,30 @@ var App = class _App extends React41.Component {
37559
37603
  if (event && (!(elementUnderCursor instanceof HTMLCanvasElement) || isWritableElement4(target))) {
37560
37604
  return;
37561
37605
  }
37562
- const dataTransferList = await parseDataTransferEvent(event);
37563
- const filesList = dataTransferList.getFiles();
37564
- const data = await parseClipboard(dataTransferList, isPlainPaste);
37606
+ let dataTransferList = await parseDataTransferEvent(event);
37607
+ let filesList = dataTransferList.getFiles();
37608
+ let data = await parseClipboard(dataTransferList, isPlainPaste);
37609
+ if (!data.elements && filesList.length > 0 && !isPlainPaste) {
37610
+ try {
37611
+ const systemClipboard = await readSystemClipboard();
37612
+ const excalidrawJSON = systemClipboard[MIME_TYPES11.excalidrawClipboard];
37613
+ if (typeof excalidrawJSON === "string") {
37614
+ dataTransferList = await parseDataTransferEvent(
37615
+ createPasteEvent({
37616
+ types: {
37617
+ [MIME_TYPES11.excalidrawClipboard]: excalidrawJSON
37618
+ }
37619
+ })
37620
+ );
37621
+ filesList = dataTransferList.getFiles();
37622
+ data = await parseClipboard(dataTransferList, isPlainPaste);
37623
+ }
37624
+ } catch (error) {
37625
+ console.warn(
37626
+ `Could not read editable image clipboard data: ${error.message}`
37627
+ );
37628
+ }
37629
+ }
37565
37630
  if (this.state.viewModeEnabled) {
37566
37631
  if (!this.containsImagePaste(data, filesList, isPlainPaste)) {
37567
37632
  return;
@@ -44062,6 +44127,19 @@ var App = class _App extends React41.Component {
44062
44127
  return;
44063
44128
  }
44064
44129
  }
44130
+ if (data.elements) {
44131
+ const elements = data.programmaticAPI ? convertToExcalidrawElements(
44132
+ data.elements
44133
+ ) : data.elements;
44134
+ this.addElementsFromPasteOrLibrary({
44135
+ elements,
44136
+ files: data.files || null,
44137
+ position: this.editorInterface.formFactor === "desktop" ? "cursor" : "center",
44138
+ retainSeed: isPlainPaste,
44139
+ preserveFrameChildrenOrder: true
44140
+ });
44141
+ return;
44142
+ }
44065
44143
  const imageFiles = dataTransferFiles.map((data2) => data2.file);
44066
44144
  if (imageFiles.length === 0 && data.text && !isPlainPaste) {
44067
44145
  const trimmedText = data.text.trim();
@@ -44077,19 +44155,6 @@ var App = class _App extends React41.Component {
44077
44155
  }
44078
44156
  return;
44079
44157
  }
44080
- if (data.elements) {
44081
- const elements = data.programmaticAPI ? convertToExcalidrawElements(
44082
- data.elements
44083
- ) : data.elements;
44084
- this.addElementsFromPasteOrLibrary({
44085
- elements,
44086
- files: data.files || null,
44087
- position: this.editorInterface.formFactor === "desktop" ? "cursor" : "center",
44088
- retainSeed: isPlainPaste,
44089
- preserveFrameChildrenOrder: true
44090
- });
44091
- return;
44092
- }
44093
44158
  if (!data.text) {
44094
44159
  return;
44095
44160
  }