@nous-excalidraw/excalidraw 0.18.0 → 0.18.2

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
  serializeLibraryAsJSON,
67
67
  strokeRectWithRotation_simple
68
- } from "./chunk-BJORJAH3.js";
68
+ } from "./chunk-VTFWC67S.js";
69
69
  import {
70
70
  define_import_meta_env_default
71
- } from "./chunk-JHTRI4CR.js";
71
+ } from "./chunk-UFTMCXXK.js";
72
72
  import {
73
73
  en_default
74
74
  } from "./chunk-4JOINNOK.js";
@@ -239,7 +239,7 @@ import {
239
239
  isUsingAdaptiveRadius as isUsingAdaptiveRadius4,
240
240
  isIframeElement as isIframeElement2,
241
241
  isIframeLikeElement as isIframeLikeElement2,
242
- isMagicFrameElement as isMagicFrameElement2,
242
+ isMagicFrameElement,
243
243
  isTextBindableContainer as isTextBindableContainer3,
244
244
  isElbowArrow as isElbowArrow10,
245
245
  isFlowchartNodeElement as isFlowchartNodeElement2,
@@ -9630,7 +9630,7 @@ var exportCanvas = async (type, elements, appState, files, {
9630
9630
  let blob = canvasToBlob(tempCanvas);
9631
9631
  if (appState.exportEmbedScene) {
9632
9632
  blob = blob.then(
9633
- (blob2) => import("./data/image-IFYIQRIJ.js").then(
9633
+ (blob2) => import("./data/image-R33I73P5.js").then(
9634
9634
  ({ encodePngMetadata: encodePngMetadata2 }) => encodePngMetadata2({
9635
9635
  blob: blob2,
9636
9636
  metadata: serializeAsJSON(elements, appState, files, "local")
@@ -25846,6 +25846,151 @@ var MobileMenu = ({
25846
25846
  // components/PasteChartDialog.tsx
25847
25847
  import React31, { useLayoutEffect as useLayoutEffect5, useRef as useRef26, useState as useState29 } from "react";
25848
25848
  import { newTextElement as newTextElement3 } from "@nous-excalidraw/element";
25849
+
25850
+ // ../utils/src/withinBounds.ts
25851
+ import { arrayToMap as arrayToMap24 } from "@nous-excalidraw/common";
25852
+ import { getElementBounds as getElementBounds4 } from "@nous-excalidraw/element";
25853
+ import {
25854
+ isArrowElement as isArrowElement10,
25855
+ isExcalidrawElement as isExcalidrawElement3,
25856
+ isFreeDrawElement as isFreeDrawElement4,
25857
+ isLinearElement as isLinearElement9,
25858
+ isTextElement as isTextElement11
25859
+ } from "@nous-excalidraw/element";
25860
+ import {
25861
+ rangeIncludesValue,
25862
+ pointFrom as pointFrom27,
25863
+ pointRotateRads as pointRotateRads18,
25864
+ rangeInclusive as rangeInclusive2
25865
+ } from "@nous-excalidraw/math";
25866
+ var getNonLinearElementRelativePoints = (element) => {
25867
+ if (element.type === "diamond") {
25868
+ return [
25869
+ pointFrom27(element.width / 2, 0),
25870
+ pointFrom27(element.width, element.height / 2),
25871
+ pointFrom27(element.width / 2, element.height),
25872
+ pointFrom27(0, element.height / 2)
25873
+ ];
25874
+ }
25875
+ return [
25876
+ pointFrom27(0, 0),
25877
+ pointFrom27(0 + element.width, 0),
25878
+ pointFrom27(0 + element.width, element.height),
25879
+ pointFrom27(0, element.height)
25880
+ ];
25881
+ };
25882
+ var getElementRelativePoints = (element) => {
25883
+ if (isLinearElement9(element) || isFreeDrawElement4(element)) {
25884
+ return element.points;
25885
+ }
25886
+ return getNonLinearElementRelativePoints(element);
25887
+ };
25888
+ var getMinMaxPoints = (points) => {
25889
+ const ret = points.reduce(
25890
+ (limits, [x, y]) => {
25891
+ limits.minY = Math.min(limits.minY, y);
25892
+ limits.minX = Math.min(limits.minX, x);
25893
+ limits.maxX = Math.max(limits.maxX, x);
25894
+ limits.maxY = Math.max(limits.maxY, y);
25895
+ return limits;
25896
+ },
25897
+ {
25898
+ minX: Infinity,
25899
+ minY: Infinity,
25900
+ maxX: -Infinity,
25901
+ maxY: -Infinity,
25902
+ cx: 0,
25903
+ cy: 0
25904
+ }
25905
+ );
25906
+ ret.cx = (ret.maxX + ret.minX) / 2;
25907
+ ret.cy = (ret.maxY + ret.minY) / 2;
25908
+ return ret;
25909
+ };
25910
+ var getRotatedBBox = (element) => {
25911
+ const points = getElementRelativePoints(element);
25912
+ const { cx, cy } = getMinMaxPoints(points);
25913
+ const centerPoint = pointFrom27(cx, cy);
25914
+ const rotatedPoints = points.map(
25915
+ (p) => pointRotateRads18(p, centerPoint, element.angle)
25916
+ );
25917
+ const { minX, minY, maxX, maxY } = getMinMaxPoints(rotatedPoints);
25918
+ return [
25919
+ minX + element.x,
25920
+ minY + element.y,
25921
+ maxX + element.x,
25922
+ maxY + element.y
25923
+ ];
25924
+ };
25925
+ var isElementInsideBBox = (element, bbox, eitherDirection = false) => {
25926
+ const elementBBox = getRotatedBBox(element);
25927
+ const elementInsideBbox = bbox[0] <= elementBBox[0] && bbox[2] >= elementBBox[2] && bbox[1] <= elementBBox[1] && bbox[3] >= elementBBox[3];
25928
+ if (!eitherDirection) {
25929
+ return elementInsideBbox;
25930
+ }
25931
+ if (elementInsideBbox) {
25932
+ return true;
25933
+ }
25934
+ return elementBBox[0] <= bbox[0] && elementBBox[2] >= bbox[2] && elementBBox[1] <= bbox[1] && elementBBox[3] >= bbox[3];
25935
+ };
25936
+ var elementPartiallyOverlapsWithOrContainsBBox = (element, bbox) => {
25937
+ const elementBBox = getRotatedBBox(element);
25938
+ return (rangeIncludesValue(elementBBox[0], rangeInclusive2(bbox[0], bbox[2])) || rangeIncludesValue(
25939
+ bbox[0],
25940
+ rangeInclusive2(elementBBox[0], elementBBox[2])
25941
+ )) && (rangeIncludesValue(elementBBox[1], rangeInclusive2(bbox[1], bbox[3])) || rangeIncludesValue(
25942
+ bbox[1],
25943
+ rangeInclusive2(elementBBox[1], elementBBox[3])
25944
+ ));
25945
+ };
25946
+ var elementsOverlappingBBox = ({
25947
+ elements,
25948
+ bounds,
25949
+ type,
25950
+ errorMargin = 0
25951
+ }) => {
25952
+ if (isExcalidrawElement3(bounds)) {
25953
+ bounds = getElementBounds4(bounds, arrayToMap24(elements));
25954
+ }
25955
+ const adjustedBBox = [
25956
+ bounds[0] - errorMargin,
25957
+ bounds[1] - errorMargin,
25958
+ bounds[2] + errorMargin,
25959
+ bounds[3] + errorMargin
25960
+ ];
25961
+ const includedElementSet = /* @__PURE__ */ new Set();
25962
+ for (const element of elements) {
25963
+ if (includedElementSet.has(element.id)) {
25964
+ continue;
25965
+ }
25966
+ const isOverlaping = type === "overlap" ? elementPartiallyOverlapsWithOrContainsBBox(element, adjustedBBox) : type === "inside" ? isElementInsideBBox(element, adjustedBBox) : isElementInsideBBox(element, adjustedBBox, true);
25967
+ if (isOverlaping) {
25968
+ includedElementSet.add(element.id);
25969
+ if (element.boundElements) {
25970
+ for (const boundElement of element.boundElements) {
25971
+ includedElementSet.add(boundElement.id);
25972
+ }
25973
+ }
25974
+ if (isTextElement11(element) && element.containerId) {
25975
+ includedElementSet.add(element.containerId);
25976
+ }
25977
+ if (isArrowElement10(element)) {
25978
+ if (element.startBinding) {
25979
+ includedElementSet.add(element.startBinding.elementId);
25980
+ }
25981
+ if (element.endBinding) {
25982
+ includedElementSet.add(element.endBinding?.elementId);
25983
+ }
25984
+ }
25985
+ }
25986
+ }
25987
+ return elements.filter((element) => includedElementSet.has(element.id));
25988
+ };
25989
+
25990
+ // ../utils/src/index.ts
25991
+ import { getCommonBounds as getCommonBounds6 } from "@nous-excalidraw/element";
25992
+
25993
+ // components/PasteChartDialog.tsx
25849
25994
  import { jsx as jsx95, jsxs as jsxs54 } from "react/jsx-runtime";
25850
25995
  var getChartTypeLabel = (chartType) => {
25851
25996
  switch (chartType) {
@@ -25886,19 +26031,17 @@ var ChartPreviewBtn = (props) => {
25886
26031
  let svg;
25887
26032
  const previewNode = previewRef.current;
25888
26033
  (async () => {
25889
- svg = await exportToSvg(
26034
+ svg = await exportToSvg2({
25890
26035
  elements,
25891
- {
26036
+ appState: {
25892
26037
  exportBackground: false,
25893
26038
  viewBackgroundColor: "#fff",
25894
26039
  exportWithDarkMode: theme === "dark"
25895
26040
  },
25896
- null,
26041
+ files: null,
25897
26042
  // files
25898
- {
25899
- skipInliningFonts: true
25900
- }
25901
- );
26043
+ exportPadding: 0
26044
+ });
25902
26045
  svg.querySelector(".style-fonts")?.remove();
25903
26046
  previewNode.replaceChildren();
25904
26047
  previewNode.appendChild(svg);
@@ -25940,18 +26083,16 @@ var PlainTextPreviewBtn = (props) => {
25940
26083
  });
25941
26084
  const previewNode = previewRef.current;
25942
26085
  (async () => {
25943
- const svg = await exportToSvg(
25944
- [textElement],
25945
- {
26086
+ const svg = await exportToSvg2({
26087
+ elements: [textElement],
26088
+ appState: {
25946
26089
  exportBackground: false,
25947
26090
  viewBackgroundColor: "#fff",
25948
26091
  exportWithDarkMode: theme === "dark"
25949
26092
  },
25950
- null,
25951
- {
25952
- skipInliningFonts: true
25953
- }
25954
- );
26093
+ files: null,
26094
+ exportPadding: 0
26095
+ });
25955
26096
  svg.querySelector(".style-fonts")?.remove();
25956
26097
  previewNode.replaceChildren();
25957
26098
  previewNode.appendChild(svg);
@@ -27638,7 +27779,7 @@ import {
27638
27779
  getFontString as getFontString10
27639
27780
  } from "@nous-excalidraw/common";
27640
27781
  import { newTextElement as newTextElement4 } from "@nous-excalidraw/element";
27641
- import { isTextElement as isTextElement11, isFrameLikeElement as isFrameLikeElement10 } from "@nous-excalidraw/element";
27782
+ import { isTextElement as isTextElement12, isFrameLikeElement as isFrameLikeElement10 } from "@nous-excalidraw/element";
27642
27783
  import { getDefaultFrameName } from "@nous-excalidraw/element/frame";
27643
27784
  import { Fragment as Fragment18, jsx as jsx115, jsxs as jsxs67 } from "react/jsx-runtime";
27644
27785
  var searchQueryAtom = atom("");
@@ -27967,7 +28108,7 @@ var MatchListBase = (props) => {
27967
28108
  [props.matches]
27968
28109
  );
27969
28110
  const textMatches = useMemo9(
27970
- () => props.matches.items.filter((match) => isTextElement11(match.element)),
28111
+ () => props.matches.items.filter((match) => isTextElement12(match.element)),
27971
28112
  [props.matches]
27972
28113
  );
27973
28114
  return /* @__PURE__ */ jsxs67("div", { children: [
@@ -28170,7 +28311,7 @@ var handleSearch = debounce2(
28170
28311
  }
28171
28312
  const elements = app.scene.getNonDeletedElements();
28172
28313
  const texts = elements.filter(
28173
- (el) => isTextElement11(el)
28314
+ (el) => isTextElement12(el)
28174
28315
  );
28175
28316
  const frames = elements.filter(
28176
28317
  (el) => isFrameLikeElement10(el)
@@ -28340,7 +28481,7 @@ var TTDDialogInput = ({
28340
28481
  setShowSpinner(true);
28341
28482
  }
28342
28483
  }, SPINNER_DELAY_MS);
28343
- import("./components/TTDDialog/CodeMirrorEditor-EJU7XIUQ.js").then((mod) => {
28484
+ import("./components/TTDDialog/CodeMirrorEditor-TCVBULR7.js").then((mod) => {
28344
28485
  if (!cancelled) {
28345
28486
  setEditorState({ type: "ready", component: mod.default });
28346
28487
  }
@@ -28815,151 +28956,6 @@ import {
28815
28956
  THEME as THEME15
28816
28957
  } from "@nous-excalidraw/common";
28817
28958
  import { convertToExcalidrawElements } from "@nous-excalidraw/element";
28818
-
28819
- // ../utils/src/withinBounds.ts
28820
- import { arrayToMap as arrayToMap24 } from "@nous-excalidraw/common";
28821
- import { getElementBounds as getElementBounds4 } from "@nous-excalidraw/element";
28822
- import {
28823
- isArrowElement as isArrowElement10,
28824
- isExcalidrawElement as isExcalidrawElement3,
28825
- isFreeDrawElement as isFreeDrawElement4,
28826
- isLinearElement as isLinearElement9,
28827
- isTextElement as isTextElement12
28828
- } from "@nous-excalidraw/element";
28829
- import {
28830
- rangeIncludesValue,
28831
- pointFrom as pointFrom27,
28832
- pointRotateRads as pointRotateRads18,
28833
- rangeInclusive as rangeInclusive2
28834
- } from "@nous-excalidraw/math";
28835
- var getNonLinearElementRelativePoints = (element) => {
28836
- if (element.type === "diamond") {
28837
- return [
28838
- pointFrom27(element.width / 2, 0),
28839
- pointFrom27(element.width, element.height / 2),
28840
- pointFrom27(element.width / 2, element.height),
28841
- pointFrom27(0, element.height / 2)
28842
- ];
28843
- }
28844
- return [
28845
- pointFrom27(0, 0),
28846
- pointFrom27(0 + element.width, 0),
28847
- pointFrom27(0 + element.width, element.height),
28848
- pointFrom27(0, element.height)
28849
- ];
28850
- };
28851
- var getElementRelativePoints = (element) => {
28852
- if (isLinearElement9(element) || isFreeDrawElement4(element)) {
28853
- return element.points;
28854
- }
28855
- return getNonLinearElementRelativePoints(element);
28856
- };
28857
- var getMinMaxPoints = (points) => {
28858
- const ret = points.reduce(
28859
- (limits, [x, y]) => {
28860
- limits.minY = Math.min(limits.minY, y);
28861
- limits.minX = Math.min(limits.minX, x);
28862
- limits.maxX = Math.max(limits.maxX, x);
28863
- limits.maxY = Math.max(limits.maxY, y);
28864
- return limits;
28865
- },
28866
- {
28867
- minX: Infinity,
28868
- minY: Infinity,
28869
- maxX: -Infinity,
28870
- maxY: -Infinity,
28871
- cx: 0,
28872
- cy: 0
28873
- }
28874
- );
28875
- ret.cx = (ret.maxX + ret.minX) / 2;
28876
- ret.cy = (ret.maxY + ret.minY) / 2;
28877
- return ret;
28878
- };
28879
- var getRotatedBBox = (element) => {
28880
- const points = getElementRelativePoints(element);
28881
- const { cx, cy } = getMinMaxPoints(points);
28882
- const centerPoint = pointFrom27(cx, cy);
28883
- const rotatedPoints = points.map(
28884
- (p) => pointRotateRads18(p, centerPoint, element.angle)
28885
- );
28886
- const { minX, minY, maxX, maxY } = getMinMaxPoints(rotatedPoints);
28887
- return [
28888
- minX + element.x,
28889
- minY + element.y,
28890
- maxX + element.x,
28891
- maxY + element.y
28892
- ];
28893
- };
28894
- var isElementInsideBBox = (element, bbox, eitherDirection = false) => {
28895
- const elementBBox = getRotatedBBox(element);
28896
- const elementInsideBbox = bbox[0] <= elementBBox[0] && bbox[2] >= elementBBox[2] && bbox[1] <= elementBBox[1] && bbox[3] >= elementBBox[3];
28897
- if (!eitherDirection) {
28898
- return elementInsideBbox;
28899
- }
28900
- if (elementInsideBbox) {
28901
- return true;
28902
- }
28903
- return elementBBox[0] <= bbox[0] && elementBBox[2] >= bbox[2] && elementBBox[1] <= bbox[1] && elementBBox[3] >= bbox[3];
28904
- };
28905
- var elementPartiallyOverlapsWithOrContainsBBox = (element, bbox) => {
28906
- const elementBBox = getRotatedBBox(element);
28907
- return (rangeIncludesValue(elementBBox[0], rangeInclusive2(bbox[0], bbox[2])) || rangeIncludesValue(
28908
- bbox[0],
28909
- rangeInclusive2(elementBBox[0], elementBBox[2])
28910
- )) && (rangeIncludesValue(elementBBox[1], rangeInclusive2(bbox[1], bbox[3])) || rangeIncludesValue(
28911
- bbox[1],
28912
- rangeInclusive2(elementBBox[1], elementBBox[3])
28913
- ));
28914
- };
28915
- var elementsOverlappingBBox = ({
28916
- elements,
28917
- bounds,
28918
- type,
28919
- errorMargin = 0
28920
- }) => {
28921
- if (isExcalidrawElement3(bounds)) {
28922
- bounds = getElementBounds4(bounds, arrayToMap24(elements));
28923
- }
28924
- const adjustedBBox = [
28925
- bounds[0] - errorMargin,
28926
- bounds[1] - errorMargin,
28927
- bounds[2] + errorMargin,
28928
- bounds[3] + errorMargin
28929
- ];
28930
- const includedElementSet = /* @__PURE__ */ new Set();
28931
- for (const element of elements) {
28932
- if (includedElementSet.has(element.id)) {
28933
- continue;
28934
- }
28935
- const isOverlaping = type === "overlap" ? elementPartiallyOverlapsWithOrContainsBBox(element, adjustedBBox) : type === "inside" ? isElementInsideBBox(element, adjustedBBox) : isElementInsideBBox(element, adjustedBBox, true);
28936
- if (isOverlaping) {
28937
- includedElementSet.add(element.id);
28938
- if (element.boundElements) {
28939
- for (const boundElement of element.boundElements) {
28940
- includedElementSet.add(boundElement.id);
28941
- }
28942
- }
28943
- if (isTextElement12(element) && element.containerId) {
28944
- includedElementSet.add(element.containerId);
28945
- }
28946
- if (isArrowElement10(element)) {
28947
- if (element.startBinding) {
28948
- includedElementSet.add(element.startBinding.elementId);
28949
- }
28950
- if (element.endBinding) {
28951
- includedElementSet.add(element.endBinding?.elementId);
28952
- }
28953
- }
28954
- }
28955
- }
28956
- return elements.filter((element) => includedElementSet.has(element.id));
28957
- };
28958
-
28959
- // ../utils/src/index.ts
28960
- import { getCommonBounds as getCommonBounds6 } from "@nous-excalidraw/element";
28961
-
28962
- // components/TTDDialog/common.ts
28963
28959
  var resetPreview = ({
28964
28960
  canvasRef,
28965
28961
  setError
@@ -37872,7 +37868,7 @@ var App = class _App extends React46.Component {
37872
37868
  this.setActiveTool({ type: TOOL_TYPE3.magicframe });
37873
37869
  trackEvent("ai", "tool-select (empty-selection)", "d2c");
37874
37870
  } else {
37875
- const selectedMagicFrame = selectedElements.length === 1 && isMagicFrameElement2(selectedElements[0]) && selectedElements[0];
37871
+ const selectedMagicFrame = selectedElements.length === 1 && isMagicFrameElement(selectedElements[0]) && selectedElements[0];
37876
37872
  if (!selectedMagicFrame && selectedElements.some((el) => isFrameLikeElement15(el) || el.frameId)) {
37877
37873
  this.setActiveTool({ type: TOOL_TYPE3.magicframe });
37878
37874
  return;
@@ -41979,6 +41975,16 @@ var App = class _App extends React46.Component {
41979
41975
  );
41980
41976
  const dataTransferList = await parseDataTransferEvent(event);
41981
41977
  const fileItems = dataTransferList.getFiles();
41978
+ if (fileItems.length > 0) {
41979
+ const files = fileItems.map((item) => item.file).filter((file2) => file2 != null);
41980
+ const isSinglePngOrSvgSceneCandidate = files.length === 1 && (files[0].type === MIME_TYPES9.png || files[0].type === MIME_TYPES9.svg);
41981
+ const hasSupportedImage = files.some(
41982
+ (file2) => isSupportedImageFile(file2)
41983
+ );
41984
+ if (!isSinglePngOrSvgSceneCandidate && !hasSupportedImage) {
41985
+ return;
41986
+ }
41987
+ }
41982
41988
  if (fileItems.length === 1) {
41983
41989
  const { file: file2, fileHandle } = fileItems[0];
41984
41990
  if (file2 && (file2.type === MIME_TYPES9.png || file2.type === MIME_TYPES9.svg)) {
@@ -43439,7 +43445,7 @@ var App = class _App extends React46.Component {
43439
43445
  },
43440
43446
  firstSelectedElement.id
43441
43447
  ),
43442
- this.props.aiEnabled !== false && selectedElements.length === 1 && isMagicFrameElement2(firstSelectedElement) && /* @__PURE__ */ jsx162(
43448
+ this.props.aiEnabled !== false && selectedElements.length === 1 && isMagicFrameElement(firstSelectedElement) && /* @__PURE__ */ jsx162(
43443
43449
  ElementCanvasButtons,
43444
43450
  {
43445
43451
  element: firstSelectedElement,
@@ -43644,7 +43650,7 @@ var App = class _App extends React46.Component {
43644
43650
  this.scene.getNonDeletedElements(),
43645
43651
  magicFrame,
43646
43652
  this.scene.getNonDeletedElementsMap()
43647
- ).filter((el) => !isMagicFrameElement2(el));
43653
+ ).filter((el) => !isMagicFrameElement(el));
43648
43654
  if (!magicFrameChildren.length) {
43649
43655
  if (source === "button") {
43650
43656
  this.setState({ errorMessage: "Cannot generate from an empty frame" });