@excalidraw/math 0.18.0-6135548 → 0.18.0-699826

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.
Files changed (150) hide show
  1. package/dist/dev/index.js +150 -130
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +1 -1
  4. package/dist/types/common/debug.d.ts +21 -0
  5. package/dist/types/common/src/appEventBus.d.ts +27 -0
  6. package/dist/types/common/src/colors.d.ts +2 -2
  7. package/dist/types/common/src/constants.d.ts +5 -2
  8. package/dist/types/common/src/index.d.ts +3 -0
  9. package/dist/types/common/src/utils.d.ts +4 -7
  10. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  11. package/dist/types/element/src/Scene.d.ts +7 -3
  12. package/dist/types/element/src/arrowheads.d.ts +3 -0
  13. package/dist/types/element/src/arrows/focus.d.ts +27 -0
  14. package/dist/types/element/src/arrows/helpers.d.ts +5 -0
  15. package/dist/types/element/src/binding.d.ts +13 -8
  16. package/dist/types/element/src/bounds.d.ts +22 -3
  17. package/dist/types/element/src/collision.d.ts +4 -3
  18. package/dist/types/element/src/distribute.d.ts +2 -1
  19. package/dist/types/element/src/duplicate.d.ts +1 -0
  20. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  21. package/dist/types/element/src/frame.d.ts +7 -6
  22. package/dist/types/element/src/index.d.ts +3 -0
  23. package/dist/types/element/src/linearElementEditor.d.ts +7 -2
  24. package/dist/types/element/src/mutateElement.d.ts +2 -0
  25. package/dist/types/element/src/selection.d.ts +7 -3
  26. package/dist/types/element/src/shape.d.ts +1 -1
  27. package/dist/types/element/src/textElement.d.ts +1 -1
  28. package/dist/types/element/src/textWrapping.d.ts +26 -0
  29. package/dist/types/element/src/typeChecks.d.ts +1 -0
  30. package/dist/types/element/src/types.d.ts +5 -2
  31. package/dist/types/element/src/utils.d.ts +6 -4
  32. package/dist/types/element/src/zindex.d.ts +1 -1
  33. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +41 -38
  34. package/dist/types/excalidraw/actions/actionBoundText.d.ts +29 -27
  35. package/dist/types/excalidraw/actions/actionCanvas.d.ts +169 -157
  36. package/dist/types/excalidraw/actions/actionClipboard.d.ts +28 -26
  37. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +14 -13
  38. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +44 -39
  39. package/dist/types/excalidraw/actions/actionDeselect.d.ts +159 -0
  40. package/dist/types/excalidraw/actions/actionElementLink.d.ts +10 -13
  41. package/dist/types/excalidraw/actions/actionElementLock.d.ts +28 -26
  42. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +14 -13
  43. package/dist/types/excalidraw/actions/actionExport.d.ts +77 -349
  44. package/dist/types/excalidraw/actions/actionFrame.d.ts +56 -52
  45. package/dist/types/excalidraw/actions/actionGroup.d.ts +29 -27
  46. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +16 -13
  47. package/dist/types/excalidraw/actions/actionLink.d.ts +14 -13
  48. package/dist/types/excalidraw/actions/actionMenu.d.ts +10 -13
  49. package/dist/types/excalidraw/actions/actionProperties.d.ts +30 -28
  50. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +14 -13
  51. package/dist/types/excalidraw/actions/actionStyles.d.ts +14 -12
  52. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
  53. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +172 -0
  54. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +14 -13
  55. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +172 -0
  56. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +14 -13
  57. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +10 -13
  58. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +14 -13
  59. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +14 -13
  60. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +14 -13
  61. package/dist/types/excalidraw/actions/index.d.ts +3 -0
  62. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  63. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  64. package/dist/types/excalidraw/{animated-trail.d.ts → animatedTrail.d.ts} +4 -3
  65. package/dist/types/excalidraw/appState.d.ts +10 -7
  66. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  67. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  68. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  69. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  70. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  71. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  72. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  73. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  74. package/dist/types/excalidraw/clipboard.d.ts +6 -7
  75. package/dist/types/excalidraw/components/App.d.ts +63 -16
  76. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  77. package/dist/types/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -2
  78. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -1
  79. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  80. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  81. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -1
  82. package/dist/types/excalidraw/components/Range.d.ts +10 -4
  83. package/dist/types/excalidraw/components/SVGLayer.d.ts +1 -1
  84. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +2 -6
  85. package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +2 -1
  86. package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
  87. package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +11 -7
  88. package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
  89. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +4 -1
  90. package/dist/types/excalidraw/components/TTDDialog/TTDWelcomeMessage.d.ts +1 -0
  91. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
  92. package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
  93. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +4 -0
  94. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
  95. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
  96. package/dist/types/excalidraw/components/Toast.d.ts +8 -4
  97. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -1
  98. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +1 -0
  99. package/dist/types/excalidraw/components/canvases/StaticCanvas.d.ts +1 -1
  100. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -17
  101. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +3 -2
  102. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +11 -13
  103. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
  104. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -1
  105. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
  106. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
  107. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
  108. package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
  109. package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
  110. package/dist/types/excalidraw/components/icons.d.ts +23 -9
  111. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +24 -3
  112. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +23 -13
  113. package/dist/types/excalidraw/components/shapes.d.ts +81 -1
  114. package/dist/types/excalidraw/data/blob.d.ts +47 -46
  115. package/dist/types/excalidraw/data/filesystem.d.ts +3 -5
  116. package/dist/types/excalidraw/data/index.d.ts +2 -3
  117. package/dist/types/excalidraw/data/json.d.ts +37 -28
  118. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  119. package/dist/types/excalidraw/eraser/index.d.ts +2 -3
  120. package/dist/types/excalidraw/{laser-trails.d.ts → laserTrails.d.ts} +5 -7
  121. package/dist/types/excalidraw/lasso/index.d.ts +2 -3
  122. package/dist/types/excalidraw/renderer/animation.d.ts +4 -1
  123. package/dist/types/excalidraw/scene/Renderer.d.ts +425 -19
  124. package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
  125. package/dist/types/excalidraw/types.d.ts +116 -18
  126. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +5 -1
  127. package/dist/types/fractional-indexing/src/index.d.ts +29 -0
  128. package/dist/types/math/src/constants.d.ts +0 -1
  129. package/dist/types/math/src/curve.d.ts +4 -1
  130. package/dist/types/math/src/point.d.ts +8 -2
  131. package/dist/types/math/src/types.d.ts +25 -1
  132. package/dist/types/utils/src/index.d.ts +1 -2
  133. package/package.json +2 -2
  134. package/dist/types/excalidraw/animation-frame-handler.d.ts +0 -16
  135. package/dist/types/excalidraw/charts.d.ts +0 -27
  136. package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
  137. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -15
  138. package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
  139. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -8
  140. package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +0 -24
  141. package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
  142. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -11
  143. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
  144. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
  145. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -84
  146. package/dist/types/excalidraw/data/reconcile.d.ts +0 -7
  147. package/dist/types/excalidraw/index.d.ts +0 -46
  148. package/dist/types/excalidraw/polyfill.d.ts +0 -2
  149. package/dist/types/utils/src/bbox.d.ts +0 -9
  150. package/dist/types/utils/src/withinBounds.d.ts +0 -19
@@ -0,0 +1,15 @@
1
+ import { type GlobalPoint } from "@excalidraw/math";
2
+ import type { EditorInterface } from "@excalidraw/common";
3
+ import type { ExcalidrawTextElement } from "@excalidraw/element/types";
4
+ export declare const getTextBoxPadding: (zoomValue: number) => number;
5
+ export declare const getTextAutoResizeHandle: (textElement: ExcalidrawTextElement, zoomValue: number, formFactor: EditorInterface["formFactor"]) => {
6
+ center: GlobalPoint | import("@excalidraw/math").LocalPoint;
7
+ start: GlobalPoint;
8
+ end: GlobalPoint;
9
+ hitboxWidth: number;
10
+ hitboxHeight: number;
11
+ } | null;
12
+ export declare const isPointHittingTextAutoResizeHandle: (point: Readonly<{
13
+ x: number;
14
+ y: number;
15
+ }>, textElement: ExcalidrawTextElement, zoomValue: number, formFactor: EditorInterface["formFactor"]) => boolean;
@@ -1,15 +1,15 @@
1
1
  import type { IMAGE_MIME_TYPES, UserIdleState, throttleRAF, MIME_TYPES, EditorInterface } from "@excalidraw/common";
2
2
  import type { LinearElementEditor } from "@excalidraw/element";
3
3
  import type { MaybeTransformHandleType } from "@excalidraw/element";
4
- import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, BindMode } from "@excalidraw/element/types";
4
+ import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, BindMode, ExcalidrawTextElement } from "@excalidraw/element/types";
5
5
  import type { Merge, MaybePromise, ValueOf, MakeBrand } from "@excalidraw/common/utility-types";
6
6
  import type { CaptureUpdateActionType, DurableIncrement, EphemeralIncrement } from "@excalidraw/element";
7
+ import type { GlobalPoint } from "@excalidraw/math";
7
8
  import type { Action } from "./actions/types";
8
9
  import type { Spreadsheet } from "./charts";
9
10
  import type { ClipboardData } from "./clipboard";
10
11
  import type App from "./components/App";
11
12
  import type Library from "./data/library";
12
- import type { FileSystemHandle } from "./data/filesystem";
13
13
  import type { ContextMenuItems } from "./components/ContextMenu";
14
14
  import type { SnapLine } from "./snapping";
15
15
  import type { ImportedDataState } from "./data/types";
@@ -17,6 +17,7 @@ import type { Language } from "./i18n";
17
17
  import type { isOverScrollBars } from "./scene/scrollbars";
18
18
  import type React from "react";
19
19
  import type { JSX } from "react";
20
+ export type { App };
20
21
  export type SocketId = string & {
21
22
  _brand: "SocketId";
22
23
  };
@@ -128,6 +129,7 @@ export type StaticCanvasAppState = Readonly<_CommonCanvasAppState & {
128
129
  croppingElementId: AppState["croppingElementId"];
129
130
  }>;
130
131
  export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
132
+ activeTool: AppState["activeTool"];
131
133
  activeEmbeddable: AppState["activeEmbeddable"];
132
134
  selectionElement: AppState["selectionElement"];
133
135
  selectedGroupIds: AppState["selectedGroupIds"];
@@ -135,6 +137,7 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
135
137
  multiElement: AppState["multiElement"];
136
138
  newElement: AppState["newElement"];
137
139
  isBindingEnabled: AppState["isBindingEnabled"];
140
+ isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
138
141
  suggestedBinding: AppState["suggestedBinding"];
139
142
  isRotating: AppState["isRotating"];
140
143
  elementsToHighlight: AppState["elementsToHighlight"];
@@ -150,6 +153,7 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
150
153
  frameRendering: AppState["frameRendering"];
151
154
  shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
152
155
  exportScale: AppState["exportScale"];
156
+ currentItemArrowType: AppState["currentItemArrowType"];
153
157
  }>;
154
158
  export type ObservedAppState = ObservedStandaloneAppState & ObservedElementsAppState;
155
159
  export type ObservedStandaloneAppState = {
@@ -168,6 +172,7 @@ export type ObservedElementsAppState = {
168
172
  lockedMultiSelections: AppState["lockedMultiSelections"];
169
173
  activeLockedId: AppState["activeLockedId"];
170
174
  };
175
+ export type BoxSelectionMode = "contain" | "overlap";
171
176
  export interface AppState {
172
177
  contextMenu: {
173
178
  items: ContextMenuItems;
@@ -201,9 +206,25 @@ export interface AppState {
201
206
  * - set on pointer down, updated during pointer move
202
207
  */
203
208
  selectionElement: NonDeletedExcalidrawElement | null;
209
+ /**
210
+ * tracking current arrow binding editor state (takes into account
211
+ * `bindingPreference` and keyboard modifiers (ctrl/alt)
212
+ */
204
213
  isBindingEnabled: boolean;
205
- startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
206
- suggestedBinding: NonDeleted<ExcalidrawBindableElement> | null;
214
+ /** user box selection preference; defaults to "contain" when unset */
215
+ boxSelectionMode: BoxSelectionMode;
216
+ /** user arrow binding preference */
217
+ bindingPreference: "enabled" | "disabled";
218
+ /** user preference whether arrow snap to midpoints while binding */
219
+ isMidpointSnappingEnabled: boolean;
220
+ /**
221
+ * The bindable element the UI highlights for the user when an arrow is
222
+ * dragged or otherwise its endpoint being close to said element.
223
+ */
224
+ suggestedBinding: {
225
+ element: NonDeleted<ExcalidrawBindableElement>;
226
+ midPoint?: GlobalPoint;
227
+ } | null;
207
228
  frameToHighlight: NonDeleted<ExcalidrawFrameLikeElement> | null;
208
229
  frameRendering: {
209
230
  enabled: boolean;
@@ -216,7 +237,7 @@ export interface AppState {
216
237
  /**
217
238
  * set when a new text is created or when an existing text is being edited
218
239
  */
219
- editingTextElement: NonDeletedExcalidrawElement | null;
240
+ editingTextElement: ExcalidrawTextElement | null;
220
241
  activeTool: {
221
242
  /**
222
243
  * indicates a previous tool we should revert back to if we deselect the
@@ -278,6 +299,10 @@ export interface AppState {
278
299
  } | {
279
300
  name: "elementLinkSelector";
280
301
  sourceElementId: ExcalidrawElement["id"];
302
+ } | {
303
+ name: "charts";
304
+ data: Spreadsheet;
305
+ rawText: string;
281
306
  };
282
307
  /**
283
308
  * Reflects user preference for whether the default sidebar should be docked.
@@ -300,7 +325,7 @@ export interface AppState {
300
325
  selectedElementsAreBeingDragged: boolean;
301
326
  shouldCacheIgnoreZoom: boolean;
302
327
  toast: {
303
- message: string;
328
+ message: React.ReactNode;
304
329
  closable?: boolean;
305
330
  duration?: number;
306
331
  } | null;
@@ -322,21 +347,13 @@ export interface AppState {
322
347
  height: number;
323
348
  offsetTop: number;
324
349
  offsetLeft: number;
325
- fileHandle: FileSystemHandle | null;
350
+ fileHandle: FileSystemFileHandle | null;
326
351
  collaborators: Map<SocketId, Collaborator>;
327
352
  stats: {
328
353
  open: boolean;
329
354
  /** bitmap. Use `STATS_PANELS` bit values */
330
355
  panels: number;
331
356
  };
332
- currentChartType: ChartType;
333
- pasteDialog: {
334
- shown: false;
335
- data: null;
336
- } | {
337
- shown: true;
338
- data: Spreadsheet;
339
- };
340
357
  showHyperlinkPopup: false | "info" | "editor";
341
358
  selectedLinearElement: LinearElementEditor | null;
342
359
  snapLines: readonly SnapLine[];
@@ -375,7 +392,7 @@ export type SearchMatch = {
375
392
  showOnCanvas: boolean;
376
393
  }[];
377
394
  };
378
- export type UIAppState = Omit<AppState, "startBoundElement" | "cursorButton" | "scrollX" | "scrollY">;
395
+ export type UIAppState = Omit<AppState, "cursorButton" | "scrollX" | "scrollY">;
379
396
  export type NormalizedZoomValue = number & {
380
397
  _brand: "normalizedZoom";
381
398
  };
@@ -423,11 +440,37 @@ export type OnUserFollowedPayload = {
423
440
  userToFollow: UserToFollow;
424
441
  action: "FOLLOW" | "UNFOLLOW";
425
442
  };
443
+ export type OnExportProgress = {
444
+ type: "progress";
445
+ message?: React.ReactNode;
446
+ /** 0-1 range */
447
+ progress?: number;
448
+ };
426
449
  export interface ExcalidrawProps {
427
450
  onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
451
+ onThemeChange?: (theme: Theme | "system") => void;
452
+ /**
453
+ * note: only subscribes if the props.onIncrement is defined on initial render
454
+ */
428
455
  onIncrement?: (event: DurableIncrement | EphemeralIncrement) => void;
429
456
  initialData?: (() => MaybePromise<ExcalidrawInitialDataState | null>) | MaybePromise<ExcalidrawInitialDataState | null>;
430
- excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
457
+ /**
458
+ * Invoked as soon as the Excalidraw API is available
459
+ * NOTE editor is not yet mounted, and state is not yet initialized
460
+ */
461
+ onExcalidrawAPI?: (api: ExcalidrawImperativeAPI | null) => void;
462
+ /**
463
+ * Invoked once the editor root is mounted.
464
+ */
465
+ onMount?: (payload: ExcalidrawMountPayload) => void;
466
+ /**
467
+ * Invoked when the editor root is unmounted.
468
+ */
469
+ onUnmount?: () => void;
470
+ /**
471
+ * Invoked once the initial scene is loaded.
472
+ */
473
+ onInitialize?: (api: ExcalidrawImperativeAPI) => void;
431
474
  isCollaborating?: boolean;
432
475
  onPointerUpdate?: (payload: {
433
476
  pointer: {
@@ -465,6 +508,10 @@ export interface ExcalidrawProps {
465
508
  name?: string;
466
509
  renderCustomStats?: (elements: readonly NonDeletedExcalidrawElement[], appState: UIAppState) => JSX.Element;
467
510
  UIOptions?: Partial<UIOptions>;
511
+ /**
512
+ * dimensions and size constraints for inserted images
513
+ */
514
+ imageOptions?: ImageOptions;
468
515
  detectScroll?: boolean;
469
516
  handleKeyboardGlobally?: boolean;
470
517
  onLibraryChange?: (libraryItems: LibraryItems) => void | Promise<any>;
@@ -484,6 +531,29 @@ export interface ExcalidrawProps {
484
531
  aiEnabled?: boolean;
485
532
  showDeprecatedFonts?: boolean;
486
533
  renderScrollbars?: boolean;
534
+ /**
535
+ * Called before exporting to a file.
536
+ *
537
+ * Allows the host app to intercept and delay saving until async operations
538
+ * (e.g., images are loaded) complete.
539
+ *
540
+ * If Promise/AsyncGenerator is returned, a progress toast will be shown
541
+ * until the operation completes. Generator can yield progress updates.
542
+ */
543
+ onExport?: (
544
+ /** type of export. Currently we only call for JSON exports or
545
+ * JSON-embedded PNG (which is also identified as `json` type here)*/
546
+ type: "json", data: {
547
+ elements: readonly ExcalidrawElement[];
548
+ appState: AppState;
549
+ files: BinaryFiles;
550
+ }, options: {
551
+ /** signal that gets aborted if user cancels the export (e.g. closes
552
+ * the native file picker dialog). In that case, you can either
553
+ * return immediately, or throw AbortError.
554
+ */
555
+ signal: AbortSignal;
556
+ }) => MaybePromise<void> | AsyncGenerator<OnExportProgress, void>;
487
557
  }
488
558
  export type SceneData = {
489
559
  elements?: ImportedDataState["elements"];
@@ -496,12 +566,21 @@ export type ExportOpts = {
496
566
  onExportToBackend?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles) => void;
497
567
  renderCustomUI?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles, canvas: HTMLCanvasElement) => JSX.Element;
498
568
  };
569
+ export type ImageOptions = Partial<{
570
+ maxWidthOrHeight: number;
571
+ maxFileSizeBytes: number;
572
+ }>;
499
573
  export type CanvasActions = Partial<{
500
574
  changeViewBackgroundColor: boolean;
501
575
  clearCanvas: boolean;
502
576
  export: false | ExportOpts;
503
577
  loadScene: boolean;
504
578
  saveToActiveFile: boolean;
579
+ /**
580
+ * defaults to true if `props.theme` is omitted or `props.onThemeChange`
581
+ * is supplied (at which point the theme is considered as host-app controlled),
582
+ * else default to false
583
+ * */
505
584
  toggleTheme: boolean | null;
506
585
  saveAsImage: boolean;
507
586
  }>;
@@ -525,6 +604,7 @@ export type AppProps = Merge<ExcalidrawProps, {
525
604
  export: ExportOpts;
526
605
  };
527
606
  }>;
607
+ imageOptions: Required<ImageOptions>;
528
608
  detectScroll: boolean;
529
609
  handleKeyboardGlobally: boolean;
530
610
  isCollaborating: boolean;
@@ -536,6 +616,8 @@ export type AppProps = Merge<ExcalidrawProps, {
536
616
  export type AppClassProperties = {
537
617
  props: AppProps;
538
618
  state: AppState;
619
+ api: App["api"];
620
+ sessionExportThemeOverride: App["sessionExportThemeOverride"];
539
621
  interactiveCanvas: HTMLCanvasElement | null;
540
622
  /** static canvas */
541
623
  canvas: HTMLCanvasElement;
@@ -576,7 +658,11 @@ export type AppClassProperties = {
576
658
  onPointerUpEmitter: App["onPointerUpEmitter"];
577
659
  updateEditorAtom: App["updateEditorAtom"];
578
660
  onPointerDownEmitter: App["onPointerDownEmitter"];
661
+ onEvent: App["onEvent"];
662
+ onStateChange: App["onStateChange"];
663
+ lastPointerMoveCoords: App["lastPointerMoveCoords"];
579
664
  bindModeHandler: App["bindModeHandler"];
665
+ setAppState: App["setAppState"];
580
666
  };
581
667
  export type PointerDownState = Readonly<{
582
668
  origin: Readonly<{
@@ -637,7 +723,18 @@ export type PointerDownState = Readonly<{
637
723
  };
638
724
  }>;
639
725
  export type UnsubscribeCallback = () => void;
726
+ export type ExcalidrawMountPayload = {
727
+ excalidrawAPI: ExcalidrawImperativeAPI;
728
+ container: HTMLDivElement | null;
729
+ };
730
+ export type ExcalidrawImperativeAPIEventMap = {
731
+ "editor:mount": [payload: ExcalidrawMountPayload];
732
+ "editor:initialize": [api: ExcalidrawImperativeAPI];
733
+ "editor:unmount": [];
734
+ };
640
735
  export interface ExcalidrawImperativeAPI {
736
+ /** Whether the editor has been unmounted and the API is no longer usable. */
737
+ isDestroyed: boolean;
641
738
  updateScene: InstanceType<typeof App>["updateScene"];
642
739
  applyDeltas: InstanceType<typeof App>["applyDeltas"];
643
740
  mutateElement: InstanceType<typeof App>["mutateElement"];
@@ -675,6 +772,8 @@ export interface ExcalidrawImperativeAPI {
675
772
  onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
676
773
  onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
677
774
  onUserFollow: (callback: (payload: OnUserFollowedPayload) => void) => UnsubscribeCallback;
775
+ onStateChange: InstanceType<typeof App>["onStateChange"];
776
+ onEvent: InstanceType<typeof App>["onEvent"];
678
777
  }
679
778
  export type FrameNameBounds = {
680
779
  x: number;
@@ -715,4 +814,3 @@ export type Offsets = Partial<{
715
814
  bottom: number;
716
815
  left: number;
717
816
  }>;
718
- export {};
@@ -1,7 +1,7 @@
1
1
  import type { ExcalidrawElement, ExcalidrawTextElement } from "@excalidraw/element/types";
2
2
  import type App from "../components/App";
3
3
  type SubmitHandler = () => void;
4
- export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords, element, canvas, excalidrawContainer, app, autoSelect, }: {
4
+ export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords, element, canvas, excalidrawContainer, app, autoSelect, initialCaretSceneCoords, }: {
5
5
  id: ExcalidrawElement["id"];
6
6
  /**
7
7
  * textWysiwyg only deals with `originalText`
@@ -20,5 +20,9 @@ export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords,
20
20
  excalidrawContainer: HTMLDivElement | null;
21
21
  app: App;
22
22
  autoSelect?: boolean;
23
+ initialCaretSceneCoords?: {
24
+ x: number;
25
+ y: number;
26
+ } | null;
23
27
  }) => SubmitHandler;
24
28
  export {};
@@ -0,0 +1,29 @@
1
+ export declare const BASE_62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2
+ /**
3
+ * @param {string} key
4
+ * @param {string} digits
5
+ * @return {void}
6
+ */
7
+ export declare function validateOrderKey(key: string, digits?: string): void;
8
+ /**
9
+ * @param {string | null | undefined} a
10
+ * @param {string | null | undefined} b
11
+ * @param {string=} digits
12
+ * @return {string}
13
+ */
14
+ export declare function generateKeyBetween(a: string | null | undefined, b: string | null | undefined, digits?: string): string;
15
+ /**
16
+ * same preconditions as generateKeysBetween.
17
+ * n >= 0.
18
+ * Returns an array of n distinct keys in sorted order.
19
+ * If a and b are both null, returns [a0, a1, ...]
20
+ * If one or the other is null, returns consecutive "integer"
21
+ * keys. Otherwise, returns relatively short keys between
22
+ * a and b.
23
+ * @param {string | null | undefined} a
24
+ * @param {string | null | undefined} b
25
+ * @param {number} n
26
+ * @param {string} digits
27
+ * @return {string[]}
28
+ */
29
+ export declare function generateNKeysBetween(a: string | null | undefined, b: string | null | undefined, n: number, digits?: string): string[];
@@ -1,3 +1,2 @@
1
- export declare const PRECISION = 0.0001;
2
1
  export declare const LegendreGaussN24TValues: number[];
3
2
  export declare const LegendreGaussN24CValues: number[];
@@ -12,7 +12,10 @@ export declare const bezierEquation: <Point extends GlobalPoint | LocalPoint>(c:
12
12
  /**
13
13
  * Computes the intersection between a cubic spline and a line segment.
14
14
  */
15
- export declare function curveIntersectLineSegment<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, l: LineSegment<Point>): Point[];
15
+ export declare function curveIntersectLineSegment<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, l: LineSegment<Point>, opts?: {
16
+ tolerance?: number;
17
+ iterLimit?: number;
18
+ }): Point[];
16
19
  /**
17
20
  * Finds the closest point on the Bezier curve from another point
18
21
  *
@@ -1,4 +1,4 @@
1
- import type { LocalPoint, GlobalPoint, Radians, Degrees, Vector } from "./types";
1
+ import type { LocalPoint, GlobalPoint, Radians, Degrees, Vector, GlobalCoord, LocalCoord } from "./types";
2
2
  /**
3
3
  * Create a properly typed Point instance from the X and Y coordinates.
4
4
  *
@@ -7,6 +7,11 @@ import type { LocalPoint, GlobalPoint, Radians, Degrees, Vector } from "./types"
7
7
  * @returns The branded and created point
8
8
  */
9
9
  export declare function pointFrom<Point extends GlobalPoint | LocalPoint>(x: number, y: number): Point;
10
+ export declare function pointFrom<Coord extends GlobalCoord | LocalCoord>(coords: Coord): Coord extends GlobalCoord ? GlobalPoint : LocalPoint;
11
+ export declare function pointFrom<Point extends GlobalPoint | LocalPoint>(coords: {
12
+ x: number;
13
+ y: number;
14
+ }): Point;
10
15
  /**
11
16
  * Converts and remaps an array containing a pair of numbers to Point.
12
17
  *
@@ -52,7 +57,7 @@ export declare function pointsEqual<Point extends GlobalPoint | LocalPoint>(a: P
52
57
  * @param angle The radians to rotate the point by
53
58
  * @returns The rotated point
54
59
  */
55
- export declare function pointRotateRads<Point extends GlobalPoint | LocalPoint>([x, y]: Point, [cx, cy]: Point, angle: Radians): Point;
60
+ export declare function pointRotateRads<Point extends GlobalPoint | LocalPoint>(point: Point, center: Point, angle: Radians): Point;
56
61
  /**
57
62
  * Rotate a point by [angle] degree.
58
63
  *
@@ -120,3 +125,4 @@ export declare const pointScaleFromOrigin: <P extends GlobalPoint | LocalPoint>(
120
125
  * @returns TRUE if q is indeed between p and r
121
126
  */
122
127
  export declare const isPointWithinBounds: <P extends GlobalPoint | LocalPoint>(p: P, q: P, r: P) => boolean;
128
+ export declare const isValidPoint: (point: unknown) => point is LocalPoint;
@@ -19,12 +19,24 @@ export type InclusiveRange = [number, number] & {
19
19
  _brand: "excalimath_degree";
20
20
  };
21
21
  /**
22
- * Represents a 2D position in world or canvas space. A
22
+ * Represents a 2D position in world/canvas/scene space. A
23
23
  * global coordinate.
24
24
  */
25
25
  export type GlobalPoint = [x: number, y: number] & {
26
26
  _brand: "excalimath__globalpoint";
27
27
  };
28
+ /**
29
+ * Represents a 2D position in world/canvas/scene space. A
30
+ * global coordinate.
31
+ *
32
+ * TODO remove this once we migrate the codebase to use Point tuples everywhere
33
+ */
34
+ export type GlobalCoord = {
35
+ x: number;
36
+ y: number;
37
+ } & {
38
+ _brand: "excalimath__globalcoord";
39
+ };
28
40
  /**
29
41
  * Represents a 2D position in whatever local space it's
30
42
  * needed. A local coordinate.
@@ -32,6 +44,18 @@ export type GlobalPoint = [x: number, y: number] & {
32
44
  export type LocalPoint = [x: number, y: number] & {
33
45
  _brand: "excalimath__localpoint";
34
46
  };
47
+ /**
48
+ * Represents a 2D position in whatever local space it's needed.
49
+ * A local coordinate.
50
+ *
51
+ * TODO remove this once we migrate the codebase to use Point tuples everywhere
52
+ */
53
+ export type LocalCoord = {
54
+ x: number;
55
+ y: number;
56
+ } & {
57
+ _brand: "excalimath__localcoord";
58
+ };
35
59
  /**
36
60
  * A line is an infinitely long object with no width, depth, or curvature.
37
61
  */
@@ -1,4 +1,3 @@
1
1
  export * from "./export";
2
- export * from "./withinBounds";
3
- export * from "./bbox";
2
+ export { elementsOverlappingBBox } from "@excalidraw/element";
4
3
  export { getCommonBounds } from "@excalidraw/element";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/math",
3
- "version": "0.18.0-6135548",
3
+ "version": "0.18.0-0699826",
4
4
  "type": "module",
5
5
  "types": "./dist/types/math/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -61,6 +61,6 @@
61
61
  "build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
62
62
  },
63
63
  "dependencies": {
64
- "@excalidraw/common": "0.18.0-6135548"
64
+ "@excalidraw/common": "0.18.0-0699826"
65
65
  }
66
66
  }
@@ -1,16 +0,0 @@
1
- export type AnimationCallback = (timestamp: number) => void | boolean;
2
- export type AnimationTarget = {
3
- callback: AnimationCallback;
4
- stopped: boolean;
5
- };
6
- export declare class AnimationFrameHandler {
7
- private targets;
8
- private rafIds;
9
- register(key: object, callback: AnimationCallback): void;
10
- start(key: object): void;
11
- stop(key: object): void;
12
- private constructFrame;
13
- private scheduleFrame;
14
- private cancelFrame;
15
- private onFrame;
16
- }
@@ -1,27 +0,0 @@
1
- import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
2
- export type ChartElements = readonly NonDeletedExcalidrawElement[];
3
- export interface Spreadsheet {
4
- title: string | null;
5
- labels: string[] | null;
6
- values: number[];
7
- }
8
- export declare const NOT_SPREADSHEET = "NOT_SPREADSHEET";
9
- export declare const VALID_SPREADSHEET = "VALID_SPREADSHEET";
10
- type ParseSpreadsheetResult = {
11
- type: typeof NOT_SPREADSHEET;
12
- reason: string;
13
- } | {
14
- type: typeof VALID_SPREADSHEET;
15
- spreadsheet: Spreadsheet;
16
- };
17
- /**
18
- * @private exported for testing
19
- */
20
- export declare const tryParseNumber: (s: string) => number | null;
21
- /**
22
- * @private exported for testing
23
- */
24
- export declare const tryParseCells: (cells: string[][]) => ParseSpreadsheetResult;
25
- export declare const tryParseSpreadsheet: (text: string) => ParseSpreadsheetResult;
26
- export declare const renderSpreadsheet: (chartType: string, spreadsheet: Spreadsheet, x: number, y: number) => ChartElements;
27
- export {};
@@ -1,4 +0,0 @@
1
- import type { GenerateDiagramToCode } from "../../types";
2
- export declare const DiagramToCodePlugin: (props: {
3
- generate: GenerateDiagramToCode;
4
- }) => null;
@@ -1,15 +0,0 @@
1
- import "./ExcalidrawLogo.scss";
2
- type LogoSize = "xs" | "small" | "normal" | "large" | "custom" | "mobile";
3
- interface LogoProps {
4
- size?: LogoSize;
5
- withText?: boolean;
6
- style?: React.CSSProperties;
7
- /**
8
- * If true, the logo will not be wrapped in a Link component.
9
- * The link prop will be ignored as well.
10
- * It will merely be a plain div.
11
- */
12
- isNotLink?: boolean;
13
- }
14
- export declare const ExcalidrawLogo: ({ style, size, withText, }: LogoProps) => import("react/jsx-runtime").JSX.Element;
15
- export {};
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import type { Theme } from "@excalidraw/element/types";
3
- import type { Language } from "../i18n";
4
- interface Props {
5
- langCode: Language["code"];
6
- children: React.ReactElement;
7
- theme?: Theme;
8
- }
9
- export declare const InitializeApp: (props: Props) => import("react/jsx-runtime").JSX.Element;
10
- export {};
@@ -1,8 +0,0 @@
1
- import type { JSX, ReactNode } from "react";
2
- export declare const TTDDialogTrigger: {
3
- ({ children, icon, }: {
4
- children?: ReactNode;
5
- icon?: JSX.Element;
6
- }): import("react/jsx-runtime").JSX.Element;
7
- displayName: string;
8
- };
@@ -1,24 +0,0 @@
1
- import type { LLMMessage, TTTDDialog } from "@excalidraw/excalidraw/components/TTDDialog/types";
2
- interface StreamingOptions {
3
- url: string;
4
- messages: readonly LLMMessage[];
5
- onChunk?: (chunk: string) => void;
6
- extractRateLimits?: boolean;
7
- signal?: AbortSignal;
8
- onStreamCreated?: () => void;
9
- }
10
- export type StreamChunk = {
11
- type: "content";
12
- delta: string;
13
- } | {
14
- type: "done";
15
- finishReason: "stop" | "length" | "content_filter" | "tool_calls" | null;
16
- } | {
17
- type: "error";
18
- error: {
19
- message: string;
20
- status?: number;
21
- };
22
- };
23
- export declare function TTDStreamFetch(options: StreamingOptions): Promise<TTTDDialog.OnTextSubmitRetValue>;
24
- export {};
@@ -1,8 +0,0 @@
1
- import "./FooterCenter.scss";
2
- declare const FooterCenter: {
3
- ({ children }: {
4
- children?: React.ReactNode;
5
- }): import("react/jsx-runtime").JSX.Element;
6
- displayName: string;
7
- };
8
- export default FooterCenter;
@@ -1,11 +0,0 @@
1
- import { type EditorInterface } from "@excalidraw/common";
2
- import "./LiveCollaborationTrigger.scss";
3
- declare const LiveCollaborationTrigger: {
4
- ({ isCollaborating, onSelect, editorInterface, ...rest }: {
5
- isCollaborating: boolean;
6
- onSelect: () => void;
7
- editorInterface?: EditorInterface;
8
- } & React.ButtonHTMLAttributes<HTMLButtonElement>): import("react/jsx-runtime").JSX.Element;
9
- displayName: string;
10
- };
11
- export default LiveCollaborationTrigger;