@dwelle/excalidraw 0.5.0-ddf5c00 → 0.5.0-dfd3a9a

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 (171) hide show
  1. package/dist/dev/chunk-6AV52PJO.js +5805 -0
  2. package/dist/dev/chunk-6AV52PJO.js.map +7 -0
  3. package/dist/dev/{chunk-N4RJWLSZ.js → chunk-G5DT2A72.js} +15 -5
  4. package/dist/dev/chunk-G5DT2A72.js.map +7 -0
  5. package/dist/dev/chunk-WYHOCMLG.js +7 -0
  6. package/dist/dev/chunk-WYHOCMLG.js.map +7 -0
  7. package/dist/dev/data/{image-7TSQCOPJ.js → image-CVNOYW5X.js} +3 -3
  8. package/dist/dev/index.css +104 -22
  9. package/dist/dev/index.css.map +3 -3
  10. package/dist/dev/index.js +25076 -19609
  11. package/dist/dev/index.js.map +4 -4
  12. package/dist/dev/locales/{en-KO5RAUUV.js → en-KEYRB5CP.js} +2 -2
  13. package/dist/dev/subset-shared.chunk.js +1 -1
  14. package/dist/dev/subset-worker.chunk.js +1 -1
  15. package/dist/prod/chunk-76R4CNZA.js +12 -0
  16. package/dist/prod/chunk-DHNAMUY4.js +4 -0
  17. package/dist/prod/chunk-SS5RKRMN.js +7 -0
  18. package/dist/prod/data/image-YVTXQC5H.js +1 -0
  19. package/dist/prod/index.css +1 -1
  20. package/dist/prod/index.js +33 -20
  21. package/dist/prod/locales/{en-6574ZDO2.js → en-CQGKCVPT.js} +1 -1
  22. package/dist/prod/subset-shared.chunk.js +1 -1
  23. package/dist/prod/subset-worker.chunk.js +1 -1
  24. package/dist/types/common/src/constants.d.ts +20 -3
  25. package/dist/types/{excalidraw → common/src}/emitter.d.ts +1 -1
  26. package/dist/types/common/src/font-metadata.d.ts +4 -2
  27. package/dist/types/common/src/index.d.ts +1 -0
  28. package/dist/types/common/src/utility-types.d.ts +5 -0
  29. package/dist/types/common/src/utils.d.ts +17 -4
  30. package/dist/types/{excalidraw/scene → element/src}/Scene.d.ts +11 -14
  31. package/dist/types/element/src/align.d.ts +4 -3
  32. package/dist/types/element/src/binding.d.ts +26 -16
  33. package/dist/types/element/src/bounds.d.ts +13 -5
  34. package/dist/types/element/src/collision.d.ts +18 -12
  35. package/dist/types/element/src/cropElement.d.ts +1 -1
  36. package/dist/types/{excalidraw/change.d.ts → element/src/delta.d.ts} +63 -38
  37. package/dist/types/element/src/distance.d.ts +2 -2
  38. package/dist/types/element/src/distribute.d.ts +2 -1
  39. package/dist/types/element/src/dragElements.d.ts +3 -2
  40. package/dist/types/element/src/duplicate.d.ts +10 -13
  41. package/dist/types/element/src/elbowArrow.d.ts +1 -1
  42. package/dist/types/element/src/flowchart.d.ts +3 -2
  43. package/dist/types/element/src/fractionalIndex.d.ts +9 -3
  44. package/dist/types/element/src/frame.d.ts +5 -4
  45. package/dist/types/element/src/groups.d.ts +1 -0
  46. package/dist/types/element/src/index.d.ts +43 -2
  47. package/dist/types/element/src/linearElementEditor.d.ts +22 -36
  48. package/dist/types/element/src/mutateElement.d.ts +11 -3
  49. package/dist/types/element/src/newElement.d.ts +4 -3
  50. package/dist/types/element/src/resizeElements.d.ts +5 -4
  51. package/dist/types/element/src/selection.d.ts +11 -5
  52. package/dist/types/element/src/shape.d.ts +42 -0
  53. package/dist/types/element/src/sizeHelpers.d.ts +2 -2
  54. package/dist/types/element/src/store.d.ts +232 -0
  55. package/dist/types/element/src/textElement.d.ts +4 -3
  56. package/dist/types/element/src/typeChecks.d.ts +19 -1
  57. package/dist/types/element/src/types.d.ts +15 -2
  58. package/dist/types/element/src/utils.d.ts +16 -6
  59. package/dist/types/element/src/zindex.d.ts +1 -1
  60. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +42 -51
  61. package/dist/types/excalidraw/actions/actionBoundText.d.ts +28 -34
  62. package/dist/types/excalidraw/actions/actionCanvas.d.ts +188 -227
  63. package/dist/types/excalidraw/actions/actionClipboard.d.ts +81 -98
  64. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +14 -17
  65. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +37 -45
  66. package/dist/types/excalidraw/actions/actionElementLink.d.ts +13 -16
  67. package/dist/types/excalidraw/actions/actionElementLock.d.ts +43 -50
  68. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +14 -17
  69. package/dist/types/excalidraw/actions/actionExport.d.ts +141 -168
  70. package/dist/types/excalidraw/actions/actionFinalize.d.ts +71 -37
  71. package/dist/types/excalidraw/actions/actionFrame.d.ts +103 -115
  72. package/dist/types/excalidraw/actions/actionGroup.d.ts +28 -34
  73. package/dist/types/excalidraw/actions/actionHistory.d.ts +1 -2
  74. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +506 -16
  75. package/dist/types/excalidraw/actions/actionLink.d.ts +13 -16
  76. package/dist/types/excalidraw/actions/actionMenu.d.ts +39 -48
  77. package/dist/types/excalidraw/actions/actionNavigate.d.ts +27 -33
  78. package/dist/types/excalidraw/actions/actionProperties.d.ts +203 -240
  79. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +13 -16
  80. package/dist/types/excalidraw/actions/actionStyles.d.ts +14 -17
  81. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +14 -17
  82. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +14 -17
  83. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +13 -189
  84. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +19 -0
  85. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +14 -17
  86. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +14 -17
  87. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +14 -17
  88. package/dist/types/excalidraw/actions/types.d.ts +4 -3
  89. package/dist/types/excalidraw/appState.d.ts +20 -11
  90. package/dist/types/excalidraw/components/App.d.ts +31 -19
  91. package/dist/types/excalidraw/components/ButtonIcon.d.ts +1 -0
  92. package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -1
  93. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +5 -1
  94. package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +1 -1
  95. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -3
  96. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -3
  97. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -2
  98. package/dist/types/excalidraw/components/ColorPicker/TopPicks.d.ts +1 -1
  99. package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +1 -1
  100. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +1 -1
  101. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +23 -0
  102. package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +4 -3
  103. package/dist/types/excalidraw/components/Ellipsify.d.ts +4 -0
  104. package/dist/types/excalidraw/components/{ButtonIconSelect.d.ts → RadioSelection.d.ts} +1 -1
  105. package/dist/types/excalidraw/components/Range.d.ts +3 -3
  106. package/dist/types/excalidraw/components/Stats/Angle.d.ts +1 -1
  107. package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +1 -1
  108. package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +2 -1
  109. package/dist/types/excalidraw/components/Stats/Dimension.d.ts +1 -1
  110. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +12 -2
  111. package/dist/types/excalidraw/components/Stats/FontSize.d.ts +1 -1
  112. package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +1 -1
  113. package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +1 -1
  114. package/dist/types/excalidraw/components/Stats/MultiFontSize.d.ts +1 -1
  115. package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +1 -1
  116. package/dist/types/excalidraw/components/Stats/Position.d.ts +1 -1
  117. package/dist/types/excalidraw/components/Stats/utils.d.ts +4 -11
  118. package/dist/types/excalidraw/components/UnlockPopup.d.ts +8 -0
  119. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +1 -0
  120. package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +3 -2
  121. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +2 -1
  122. package/dist/types/excalidraw/components/icons.d.ts +3 -0
  123. package/dist/types/excalidraw/components/shapes.d.ts +1 -1
  124. package/dist/types/excalidraw/data/transform.d.ts +1 -1
  125. package/dist/types/excalidraw/editor-jotai.d.ts +6 -6
  126. package/dist/types/excalidraw/eraser/index.d.ts +0 -2
  127. package/dist/types/excalidraw/fonts/Fonts.d.ts +1 -1
  128. package/dist/types/excalidraw/history.d.ts +30 -22
  129. package/dist/types/excalidraw/hooks/useEmitter.d.ts +1 -1
  130. package/dist/types/excalidraw/index.d.ts +10 -9
  131. package/dist/types/excalidraw/lasso/index.d.ts +1 -0
  132. package/dist/types/excalidraw/lasso/utils.d.ts +2 -1
  133. package/dist/types/excalidraw/renderer/helpers.d.ts +6 -1
  134. package/dist/types/excalidraw/scene/Renderer.d.ts +1 -2
  135. package/dist/types/excalidraw/scene/export.d.ts +1 -1
  136. package/dist/types/excalidraw/scene/index.d.ts +2 -2
  137. package/dist/types/excalidraw/scene/scrollbars.d.ts +2 -3
  138. package/dist/types/excalidraw/scene/types.d.ts +2 -0
  139. package/dist/types/excalidraw/snapping.d.ts +2 -2
  140. package/dist/types/excalidraw/types.d.ts +30 -10
  141. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +3 -1
  142. package/dist/types/math/src/angle.d.ts +2 -0
  143. package/dist/types/math/src/constants.d.ts +3 -0
  144. package/dist/types/math/src/curve.d.ts +34 -0
  145. package/dist/types/math/src/index.d.ts +1 -0
  146. package/dist/types/math/src/point.d.ts +1 -1
  147. package/dist/types/math/src/rectangle.d.ts +2 -0
  148. package/dist/types/math/src/vector.d.ts +8 -2
  149. package/dist/types/utils/src/bbox.d.ts +1 -1
  150. package/dist/types/utils/src/index.d.ts +1 -1
  151. package/dist/types/utils/src/withinBounds.d.ts +1 -1
  152. package/history.ts +147 -110
  153. package/package.json +11 -8
  154. package/dist/dev/chunk-N4RJWLSZ.js.map +0 -7
  155. package/dist/dev/chunk-U4RZP56O.js +0 -18849
  156. package/dist/dev/chunk-U4RZP56O.js.map +0 -7
  157. package/dist/dev/chunk-XCMEWBOW.js +0 -7
  158. package/dist/dev/chunk-XCMEWBOW.js.map +0 -7
  159. package/dist/prod/chunk-3ZKFSMTS.js +0 -7
  160. package/dist/prod/chunk-OYRPRL6F.js +0 -12
  161. package/dist/prod/chunk-YO4ODNEY.js +0 -33
  162. package/dist/prod/data/image-TCFXBYOI.js +0 -1
  163. package/dist/types/element/src/Shape.d.ts +0 -17
  164. package/dist/types/element/src/ShapeCache.d.ts +0 -25
  165. package/dist/types/element/src/shapes.d.ts +0 -23
  166. package/dist/types/excalidraw/components/ButtonSelect.d.ts +0 -9
  167. package/dist/types/excalidraw/store.d.ts +0 -129
  168. package/dist/types/excalidraw/visualdebug.d.ts +0 -41
  169. package/dist/types/utils/src/collision.d.ts +0 -8
  170. /package/dist/dev/data/{image-7TSQCOPJ.js.map → image-CVNOYW5X.js.map} +0 -0
  171. /package/dist/dev/locales/{en-KO5RAUUV.js.map → en-KEYRB5CP.js.map} +0 -0
@@ -1,9 +1,10 @@
1
1
  import type { IMAGE_MIME_TYPES, UserIdleState, throttleRAF, MIME_TYPES } from "@excalidraw/common";
2
- import type { SuggestedBinding } from "@excalidraw/element/binding";
3
- import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
4
- import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles";
5
- import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement } from "@excalidraw/element/types";
2
+ import type { SuggestedBinding } from "@excalidraw/element";
3
+ import type { LinearElementEditor } from "@excalidraw/element";
4
+ import type { MaybeTransformHandleType } from "@excalidraw/element";
5
+ import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement } from "@excalidraw/element/types";
6
6
  import type { Merge, MaybePromise, ValueOf, MakeBrand } from "@excalidraw/common/utility-types";
7
+ import type { CaptureUpdateActionType, DurableIncrement, EphemeralIncrement } from "@excalidraw/element";
7
8
  import type { Action } from "./actions/types";
8
9
  import type { Spreadsheet } from "./charts";
9
10
  import type { ClipboardData } from "./clipboard";
@@ -12,7 +13,6 @@ import type Library from "./data/library";
12
13
  import type { FileSystemHandle } from "./data/filesystem";
13
14
  import type { ContextMenuItems } from "./components/ContextMenu";
14
15
  import type { SnapLine } from "./snapping";
15
- import type { CaptureUpdateActionType } from "./store";
16
16
  import type { ImportedDataState } from "./data/types";
17
17
  import type { Language } from "./i18n";
18
18
  import type { isOverScrollBars } from "./scene/scrollbars";
@@ -113,7 +113,6 @@ type _CommonCanvasAppState = {
113
113
  offsetLeft: AppState["offsetLeft"];
114
114
  offsetTop: AppState["offsetTop"];
115
115
  theme: AppState["theme"];
116
- pendingImageElementId: AppState["pendingImageElementId"];
117
116
  };
118
117
  export type StaticCanvasAppState = Readonly<_CommonCanvasAppState & {
119
118
  shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
@@ -144,6 +143,7 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
144
143
  isCropping: AppState["isCropping"];
145
144
  croppingElementId: AppState["croppingElementId"];
146
145
  searchMatches: AppState["searchMatches"];
146
+ activeLockedId: AppState["activeLockedId"];
147
147
  }>;
148
148
  export type ObservedAppState = ObservedStandaloneAppState & ObservedElementsAppState;
149
149
  export type ObservedStandaloneAppState = {
@@ -157,6 +157,8 @@ export type ObservedElementsAppState = {
157
157
  editingLinearElementId: LinearElementEditor["elementId"] | null;
158
158
  selectedLinearElementId: LinearElementEditor["elementId"] | null;
159
159
  croppingElementId: AppState["croppingElementId"];
160
+ lockedMultiSelections: AppState["lockedMultiSelections"];
161
+ activeLockedId: AppState["activeLockedId"];
160
162
  };
161
163
  export interface AppState {
162
164
  contextMenu: {
@@ -322,8 +324,6 @@ export interface AppState {
322
324
  shown: true;
323
325
  data: Spreadsheet;
324
326
  };
325
- /** imageElement waiting to be placed on canvas */
326
- pendingImageElementId: ExcalidrawImageElement["id"] | null;
327
327
  showHyperlinkPopup: false | "info" | "editor";
328
328
  selectedLinearElement: LinearElementEditor | null;
329
329
  snapLines: readonly SnapLine[];
@@ -339,9 +339,18 @@ export interface AppState {
339
339
  /** image cropping */
340
340
  isCropping: boolean;
341
341
  croppingElementId: ExcalidrawElement["id"] | null;
342
- searchMatches: readonly SearchMatch[];
342
+ /** null if no search matches found / search closed */
343
+ searchMatches: Readonly<{
344
+ focusedId: ExcalidrawElement["id"] | null;
345
+ matches: readonly SearchMatch[];
346
+ }> | null;
347
+ /** the locked element/group that's active and shows unlock popup */
348
+ activeLockedId: string | null;
349
+ lockedMultiSelections: {
350
+ [groupId: string]: true;
351
+ };
343
352
  }
344
- type SearchMatch = {
353
+ export type SearchMatch = {
345
354
  id: string;
346
355
  focus: boolean;
347
356
  matchedLines: {
@@ -349,6 +358,7 @@ type SearchMatch = {
349
358
  offsetY: number;
350
359
  width: number;
351
360
  height: number;
361
+ showOnCanvas: boolean;
352
362
  }[];
353
363
  };
354
364
  export type UIAppState = Omit<AppState, "suggestedBindings" | "startBoundElement" | "cursorButton" | "scrollX" | "scrollY">;
@@ -405,6 +415,7 @@ export interface ExcalidrawProps {
405
415
  id?: string | null;
406
416
  className?: string;
407
417
  onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles, id?: string | null) => void;
418
+ onIncrement?: (event: DurableIncrement | EphemeralIncrement) => void;
408
419
  initialData?: (() => MaybePromise<ExcalidrawInitialDataState | null>) | MaybePromise<ExcalidrawInitialDataState | null>;
409
420
  excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
410
421
  onHomeButtonClick?: () => void;
@@ -465,6 +476,7 @@ export interface ExcalidrawProps {
465
476
  renderEmbeddable?: (element: NonDeleted<ExcalidrawEmbeddableElement>, appState: AppState) => JSX.Element | null;
466
477
  aiEnabled?: boolean;
467
478
  showDeprecatedFonts?: boolean;
479
+ renderScrollbars?: boolean;
468
480
  interactive?: boolean;
469
481
  ui?: boolean;
470
482
  activeTool?: {
@@ -558,6 +570,7 @@ export type AppClassProperties = {
558
570
  visibleElements: App["visibleElements"];
559
571
  excalidrawContainerValue: App["excalidrawContainerValue"];
560
572
  onPointerUpEmitter: App["onPointerUpEmitter"];
573
+ updateEditorAtom: App["updateEditorAtom"];
561
574
  };
562
575
  export type PointerDownState = Readonly<{
563
576
  origin: Readonly<{
@@ -601,6 +614,10 @@ export type PointerDownState = Readonly<{
601
614
  x: number;
602
615
  y: number;
603
616
  } | null;
617
+ origin: {
618
+ x: number;
619
+ y: number;
620
+ };
604
621
  };
605
622
  eventListeners: {
606
623
  onMove: null | ReturnType<typeof throttleRAF>;
@@ -615,9 +632,11 @@ export type PointerDownState = Readonly<{
615
632
  export type UnsubscribeCallback = () => void;
616
633
  export interface ExcalidrawImperativeAPI {
617
634
  updateScene: InstanceType<typeof App>["updateScene"];
635
+ mutateElement: InstanceType<typeof App>["mutateElement"];
618
636
  updateLibrary: InstanceType<typeof Library>["updateLibrary"];
619
637
  resetScene: InstanceType<typeof App>["resetScene"];
620
638
  getSceneElementsIncludingDeleted: InstanceType<typeof App>["getSceneElementsIncludingDeleted"];
639
+ getSceneElementsMapIncludingDeleted: InstanceType<typeof App>["getSceneElementsMapIncludingDeleted"];
621
640
  history: {
622
641
  clear: InstanceType<typeof App>["resetHistory"];
623
642
  };
@@ -643,6 +662,7 @@ export interface ExcalidrawImperativeAPI {
643
662
  updateFrameRendering: InstanceType<typeof App>["updateFrameRendering"];
644
663
  app: InstanceType<typeof App>;
645
664
  onChange: (callback: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles) => void) => UnsubscribeCallback;
665
+ onIncrement: (callback: (event: DurableIncrement | EphemeralIncrement) => void) => UnsubscribeCallback;
646
666
  onPointerDown: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: React.PointerEvent<HTMLElement>) => void) => UnsubscribeCallback;
647
667
  onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
648
668
  onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
@@ -1,5 +1,6 @@
1
1
  import type { ExcalidrawElement, ExcalidrawTextElement } from "@excalidraw/element/types";
2
2
  import type App from "../components/App";
3
+ type SubmitHandler = () => void;
3
4
  export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords, element, canvas, excalidrawContainer, app, autoSelect, }: {
4
5
  id: ExcalidrawElement["id"];
5
6
  /**
@@ -19,4 +20,5 @@ export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords,
19
20
  excalidrawContainer: HTMLDivElement | null;
20
21
  app: App;
21
22
  autoSelect?: boolean | undefined;
22
- }) => void;
23
+ }) => SubmitHandler;
24
+ export {};
@@ -15,3 +15,5 @@ export declare function radiansToDegrees(degrees: Radians): Degrees;
15
15
  * @returns TRUE if the provided angle is a right angle
16
16
  */
17
17
  export declare function isRightAngleRads(rads: Radians): boolean;
18
+ export declare function radiansBetweenAngles(a: Radians, min: Radians, max: Radians): boolean;
19
+ export declare function radiansDifference(a: Radians, b: Radians): Radians;
@@ -0,0 +1,3 @@
1
+ export declare const PRECISION = 0.0001;
2
+ export declare const LegendreGaussN24TValues: number[];
3
+ export declare const LegendreGaussN24CValues: number[];
@@ -8,6 +8,7 @@ import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";
8
8
  * @returns
9
9
  */
10
10
  export declare function curve<Point extends GlobalPoint | LocalPoint>(a: Point, b: Point, c: Point, d: Point): Curve<Point>;
11
+ export declare const bezierEquation: <Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, t: number) => Point;
11
12
  /**
12
13
  * Computes the intersection between a cubic spline and a line segment.
13
14
  */
@@ -38,3 +39,36 @@ export declare function curvePointDistance<Point extends GlobalPoint | LocalPoin
38
39
  * Determines if the parameter is a Curve
39
40
  */
40
41
  export declare function isCurve<P extends GlobalPoint | LocalPoint>(v: unknown): v is Curve<P>;
42
+ export declare function curveTangent<Point extends GlobalPoint | LocalPoint>([p0, p1, p2, p3]: Curve<Point>, t: number): import("./types").Vector;
43
+ export declare function curveCatmullRomQuadraticApproxPoints(points: GlobalPoint[], tension?: number): [GlobalPoint, GlobalPoint][] | undefined;
44
+ export declare function curveCatmullRomCubicApproxPoints<Point extends GlobalPoint | LocalPoint>(points: Point[], tension?: number): Curve<Point>[] | undefined;
45
+ export declare function curveOffsetPoints([p0, p1, p2, p3]: Curve<GlobalPoint>, offset: number, steps?: number): GlobalPoint[];
46
+ export declare function offsetPointsForQuadraticBezier(p0: GlobalPoint, p1: GlobalPoint, p2: GlobalPoint, offsetDist: number, steps?: number): GlobalPoint[];
47
+ /**
48
+ * Implementation based on Legendre-Gauss quadrature for more accurate arc
49
+ * length calculation.
50
+ *
51
+ * Reference: https://pomax.github.io/bezierinfo/#arclength
52
+ *
53
+ * @param c The curve to calculate the length of
54
+ * @returns The approximated length of the curve
55
+ */
56
+ export declare function curveLength<P extends GlobalPoint | LocalPoint>(c: Curve<P>): number;
57
+ /**
58
+ * Calculates the curve length from t=0 to t=parameter using the same
59
+ * Legendre-Gauss quadrature method used in curveLength
60
+ *
61
+ * @param c The curve to calculate the partial length for
62
+ * @param t The parameter value (0 to 1) to calculate length up to
63
+ * @returns The length of the curve from beginning to parameter t
64
+ */
65
+ export declare function curveLengthAtParameter<P extends GlobalPoint | LocalPoint>(c: Curve<P>, t: number): number;
66
+ /**
67
+ * Calculates the point at a specific percentage of a curve's total length
68
+ * using binary search for improved efficiency and accuracy.
69
+ *
70
+ * @param c The curve to calculate point on
71
+ * @param percent A value between 0 and 1 representing the percentage of the curve's length
72
+ * @returns The point at the specified percentage of curve length
73
+ */
74
+ export declare function curvePointAtLength<P extends GlobalPoint | LocalPoint>(c: Curve<P>, percent: number): P;
@@ -1,5 +1,6 @@
1
1
  export * from "./angle";
2
2
  export * from "./curve";
3
+ export * from "./ellipse";
3
4
  export * from "./line";
4
5
  export * from "./point";
5
6
  export * from "./polygon";
@@ -43,7 +43,7 @@ export declare function isPoint(p: unknown): p is LocalPoint | GlobalPoint;
43
43
  * @param b Point The second point to compare
44
44
  * @returns TRUE if the points are sufficiently close to each other
45
45
  */
46
- export declare function pointsEqual<Point extends GlobalPoint | LocalPoint>(a: Point, b: Point): boolean;
46
+ export declare function pointsEqual<Point extends GlobalPoint | LocalPoint>(a: Point, b: Point, tolerance?: number): boolean;
47
47
  /**
48
48
  * Rotate a point by [angle] radians.
49
49
  *
@@ -1,3 +1,5 @@
1
1
  import type { GlobalPoint, LineSegment, LocalPoint, Rectangle } from "./types";
2
2
  export declare function rectangle<P extends GlobalPoint | LocalPoint>(topLeft: P, bottomRight: P): Rectangle<P>;
3
+ export declare function rectangleFromNumberSequence<Point extends LocalPoint | GlobalPoint>(minX: number, minY: number, maxX: number, maxY: number): Rectangle<Point>;
3
4
  export declare function rectangleIntersectLineSegment<Point extends LocalPoint | GlobalPoint>(r: Rectangle<Point>, l: LineSegment<Point>): Point[];
5
+ export declare function rectangleIntersectRectangle<Point extends LocalPoint | GlobalPoint>(rectangle1: Rectangle<Point>, rectangle2: Rectangle<Point>): boolean;
@@ -12,9 +12,11 @@ export declare function vector(x: number, y: number, originX?: number, originY?:
12
12
  *
13
13
  * @param p The point to turn into a vector
14
14
  * @param origin The origin point in a given coordiante system
15
- * @returns The created vector from the point and the origin
15
+ * @param threshold The threshold to consider the vector as 'undefined'
16
+ * @param defaultValue The default value to return if the vector is 'undefined'
17
+ * @returns The created vector from the point and the origin or default
16
18
  */
17
- export declare function vectorFromPoint<Point extends GlobalPoint | LocalPoint>(p: Point, origin?: Point): Vector;
19
+ export declare function vectorFromPoint<Point extends GlobalPoint | LocalPoint>(p: Point, origin?: Point, threshold?: number, defaultValue?: Vector): Vector;
18
20
  /**
19
21
  * Cross product is a binary operation on two vectors in 2D space.
20
22
  * It results in a vector that is perpendicular to both vectors.
@@ -86,3 +88,7 @@ export declare function vectorMagnitude(v: Vector): number;
86
88
  * @returns The new normalized vector
87
89
  */
88
90
  export declare const vectorNormalize: (v: Vector) => Vector;
91
+ /**
92
+ * Calculate the right-hand normal of the vector.
93
+ */
94
+ export declare const vectorNormal: (v: Vector) => Vector;
@@ -1,5 +1,5 @@
1
1
  import { type GlobalPoint, type LocalPoint } from "@excalidraw/math";
2
- import type { Bounds } from "@excalidraw/element/bounds";
2
+ import type { Bounds } from "@excalidraw/element";
3
3
  export type LineSegment<P extends LocalPoint | GlobalPoint> = [P, P];
4
4
  export declare function getBBox<P extends LocalPoint | GlobalPoint>(line: LineSegment<P>): Bounds;
5
5
  export declare function doBBoxesIntersect(a: Bounds, b: Bounds): boolean;
@@ -1,4 +1,4 @@
1
1
  export * from "./export";
2
2
  export * from "./withinBounds";
3
3
  export * from "./bbox";
4
- export { getCommonBounds } from "@excalidraw/element/bounds";
4
+ export { getCommonBounds } from "@excalidraw/element";
@@ -1,4 +1,4 @@
1
- import type { Bounds } from "@excalidraw/element/bounds";
1
+ import type { Bounds } from "@excalidraw/element";
2
2
  import type { ExcalidrawElement, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
3
3
  type Element = NonDeletedExcalidrawElement;
4
4
  type Elements = readonly NonDeletedExcalidrawElement[];
package/history.ts CHANGED
@@ -1,12 +1,84 @@
1
- import type { SceneElementsMap } from "@excalidraw/element/types";
1
+ import { Emitter } from "@excalidraw/common";
2
+
3
+ import {
4
+ CaptureUpdateAction,
5
+ StoreChange,
6
+ StoreDelta,
7
+ } from "@excalidraw/element";
8
+
9
+ import type { StoreSnapshot, Store } from "@excalidraw/element";
2
10
 
3
- import { Emitter } from "./emitter";
11
+ import type { SceneElementsMap } from "@excalidraw/element/types";
4
12
 
5
- import type { AppStateChange, ElementsChange } from "./change";
6
- import type { Snapshot } from "./store";
7
13
  import type { AppState } from "./types";
8
14
 
9
- type HistoryStack = HistoryEntry[];
15
+ export class HistoryDelta extends StoreDelta {
16
+ /**
17
+ * Apply the delta to the passed elements and appState, does not modify the snapshot.
18
+ */
19
+ public applyTo(
20
+ elements: SceneElementsMap,
21
+ appState: AppState,
22
+ snapshot: StoreSnapshot,
23
+ ): [SceneElementsMap, AppState, boolean] {
24
+ const [nextElements, elementsContainVisibleChange] = this.elements.applyTo(
25
+ elements,
26
+ // used to fallback into local snapshot in case we couldn't apply the delta
27
+ // due to a missing (force deleted) elements in the scene
28
+ snapshot.elements,
29
+ // we don't want to apply the `version` and `versionNonce` properties for history
30
+ // as we always need to end up with a new version due to collaboration,
31
+ // approaching each undo / redo as a new user action
32
+ {
33
+ excludedProperties: new Set(["version", "versionNonce"]),
34
+ },
35
+ );
36
+
37
+ const [nextAppState, appStateContainsVisibleChange] = this.appState.applyTo(
38
+ appState,
39
+ nextElements,
40
+ );
41
+
42
+ const appliedVisibleChanges =
43
+ elementsContainVisibleChange || appStateContainsVisibleChange;
44
+
45
+ return [nextElements, nextAppState, appliedVisibleChanges];
46
+ }
47
+
48
+ /**
49
+ * Overriding once to avoid type casting everywhere.
50
+ */
51
+ public static override calculate(
52
+ prevSnapshot: StoreSnapshot,
53
+ nextSnapshot: StoreSnapshot,
54
+ ) {
55
+ return super.calculate(prevSnapshot, nextSnapshot) as HistoryDelta;
56
+ }
57
+
58
+ /**
59
+ * Overriding once to avoid type casting everywhere.
60
+ */
61
+ public static override inverse(delta: StoreDelta): HistoryDelta {
62
+ return super.inverse(delta) as HistoryDelta;
63
+ }
64
+
65
+ /**
66
+ * Overriding once to avoid type casting everywhere.
67
+ */
68
+ public static override applyLatestChanges(
69
+ delta: StoreDelta,
70
+ prevElements: SceneElementsMap,
71
+ nextElements: SceneElementsMap,
72
+ modifierOptions?: "deleted" | "inserted",
73
+ ) {
74
+ return super.applyLatestChanges(
75
+ delta,
76
+ prevElements,
77
+ nextElements,
78
+ modifierOptions,
79
+ ) as HistoryDelta;
80
+ }
81
+ }
10
82
 
11
83
  export class HistoryChangedEvent {
12
84
  constructor(
@@ -20,8 +92,8 @@ export class History {
20
92
  [HistoryChangedEvent]
21
93
  >();
22
94
 
23
- private readonly undoStack: HistoryStack = [];
24
- private readonly redoStack: HistoryStack = [];
95
+ public readonly undoStack: HistoryDelta[] = [];
96
+ public readonly redoStack: HistoryDelta[] = [];
25
97
 
26
98
  public get isUndoStackEmpty() {
27
99
  return this.undoStack.length === 0;
@@ -31,98 +103,119 @@ export class History {
31
103
  return this.redoStack.length === 0;
32
104
  }
33
105
 
106
+ constructor(private readonly store: Store) {}
107
+
34
108
  public clear() {
35
109
  this.undoStack.length = 0;
36
110
  this.redoStack.length = 0;
37
111
  }
38
112
 
39
113
  /**
40
- * Record a local change which will go into the history
114
+ * Record a non-empty local durable increment, which will go into the undo stack..
115
+ * Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
41
116
  */
42
- public record(
43
- elementsChange: ElementsChange,
44
- appStateChange: AppStateChange,
45
- ) {
46
- const entry = HistoryEntry.create(appStateChange, elementsChange);
117
+ public record(delta: StoreDelta) {
118
+ if (delta.isEmpty() || delta instanceof HistoryDelta) {
119
+ return;
120
+ }
47
121
 
48
- if (!entry.isEmpty()) {
49
- // we have the latest changes, no need to `applyLatest`, which is done within `History.push`
50
- this.undoStack.push(entry.inverse());
122
+ // construct history entry, so once it's emitted, it's not recorded again
123
+ const historyDelta = HistoryDelta.inverse(delta);
51
124
 
52
- if (!entry.elementsChange.isEmpty()) {
53
- // don't reset redo stack on local appState changes,
54
- // as a simple click (unselect) could lead to losing all the redo entries
55
- // only reset on non empty elements changes!
56
- this.redoStack.length = 0;
57
- }
125
+ this.undoStack.push(historyDelta);
58
126
 
59
- this.onHistoryChangedEmitter.trigger(
60
- new HistoryChangedEvent(this.isUndoStackEmpty, this.isRedoStackEmpty),
61
- );
127
+ if (!historyDelta.elements.isEmpty()) {
128
+ // don't reset redo stack on local appState changes,
129
+ // as a simple click (unselect) could lead to losing all the redo entries
130
+ // only reset on non empty elements changes!
131
+ this.redoStack.length = 0;
62
132
  }
133
+
134
+ this.onHistoryChangedEmitter.trigger(
135
+ new HistoryChangedEvent(this.isUndoStackEmpty, this.isRedoStackEmpty),
136
+ );
63
137
  }
64
138
 
65
- public undo(
66
- elements: SceneElementsMap,
67
- appState: AppState,
68
- snapshot: Readonly<Snapshot>,
69
- ) {
139
+ public undo(elements: SceneElementsMap, appState: AppState) {
70
140
  return this.perform(
71
141
  elements,
72
142
  appState,
73
- snapshot,
74
143
  () => History.pop(this.undoStack),
75
- (entry: HistoryEntry) => History.push(this.redoStack, entry, elements),
144
+ (entry: HistoryDelta) => History.push(this.redoStack, entry),
76
145
  );
77
146
  }
78
147
 
79
- public redo(
80
- elements: SceneElementsMap,
81
- appState: AppState,
82
- snapshot: Readonly<Snapshot>,
83
- ) {
148
+ public redo(elements: SceneElementsMap, appState: AppState) {
84
149
  return this.perform(
85
150
  elements,
86
151
  appState,
87
- snapshot,
88
152
  () => History.pop(this.redoStack),
89
- (entry: HistoryEntry) => History.push(this.undoStack, entry, elements),
153
+ (entry: HistoryDelta) => History.push(this.undoStack, entry),
90
154
  );
91
155
  }
92
156
 
93
157
  private perform(
94
158
  elements: SceneElementsMap,
95
159
  appState: AppState,
96
- snapshot: Readonly<Snapshot>,
97
- pop: () => HistoryEntry | null,
98
- push: (entry: HistoryEntry) => void,
160
+ pop: () => HistoryDelta | null,
161
+ push: (entry: HistoryDelta) => void,
99
162
  ): [SceneElementsMap, AppState] | void {
100
163
  try {
101
- let historyEntry = pop();
164
+ let historyDelta = pop();
102
165
 
103
- if (historyEntry === null) {
166
+ if (historyDelta === null) {
104
167
  return;
105
168
  }
106
169
 
170
+ const action = CaptureUpdateAction.IMMEDIATELY;
171
+
172
+ let prevSnapshot = this.store.snapshot;
173
+
107
174
  let nextElements = elements;
108
175
  let nextAppState = appState;
109
176
  let containsVisibleChange = false;
110
177
 
111
- // iterate through the history entries in case they result in no visible changes
112
- while (historyEntry) {
178
+ // iterate through the history entries in case ;they result in no visible changes
179
+ while (historyDelta) {
113
180
  try {
114
181
  [nextElements, nextAppState, containsVisibleChange] =
115
- historyEntry.applyTo(nextElements, nextAppState, snapshot);
182
+ historyDelta.applyTo(nextElements, nextAppState, prevSnapshot);
183
+
184
+ const prevElements = prevSnapshot.elements;
185
+ const nextSnapshot = prevSnapshot.maybeClone(
186
+ action,
187
+ nextElements,
188
+ nextAppState,
189
+ );
190
+
191
+ const change = StoreChange.create(prevSnapshot, nextSnapshot);
192
+ const delta = HistoryDelta.applyLatestChanges(
193
+ historyDelta,
194
+ prevElements,
195
+ nextElements,
196
+ );
197
+
198
+ if (!delta.isEmpty()) {
199
+ // schedule immediate capture, so that it's emitted for the sync purposes
200
+ this.store.scheduleMicroAction({
201
+ action,
202
+ change,
203
+ delta,
204
+ });
205
+
206
+ historyDelta = delta;
207
+ }
208
+
209
+ prevSnapshot = nextSnapshot;
116
210
  } finally {
117
- // make sure to always push / pop, even if the increment is corrupted
118
- push(historyEntry);
211
+ push(historyDelta);
119
212
  }
120
213
 
121
214
  if (containsVisibleChange) {
122
215
  break;
123
216
  }
124
217
 
125
- historyEntry = pop();
218
+ historyDelta = pop();
126
219
  }
127
220
 
128
221
  return [nextElements, nextAppState];
@@ -135,7 +228,7 @@ export class History {
135
228
  }
136
229
  }
137
230
 
138
- private static pop(stack: HistoryStack): HistoryEntry | null {
231
+ private static pop(stack: HistoryDelta[]): HistoryDelta | null {
139
232
  if (!stack.length) {
140
233
  return null;
141
234
  }
@@ -149,64 +242,8 @@ export class History {
149
242
  return null;
150
243
  }
151
244
 
152
- private static push(
153
- stack: HistoryStack,
154
- entry: HistoryEntry,
155
- prevElements: SceneElementsMap,
156
- ) {
157
- const updatedEntry = entry.inverse().applyLatestChanges(prevElements);
158
- return stack.push(updatedEntry);
159
- }
160
- }
161
-
162
- export class HistoryEntry {
163
- private constructor(
164
- public readonly appStateChange: AppStateChange,
165
- public readonly elementsChange: ElementsChange,
166
- ) {}
167
-
168
- public static create(
169
- appStateChange: AppStateChange,
170
- elementsChange: ElementsChange,
171
- ) {
172
- return new HistoryEntry(appStateChange, elementsChange);
173
- }
174
-
175
- public inverse(): HistoryEntry {
176
- return new HistoryEntry(
177
- this.appStateChange.inverse(),
178
- this.elementsChange.inverse(),
179
- );
180
- }
181
-
182
- public applyTo(
183
- elements: SceneElementsMap,
184
- appState: AppState,
185
- snapshot: Readonly<Snapshot>,
186
- ): [SceneElementsMap, AppState, boolean] {
187
- const [nextElements, elementsContainVisibleChange] =
188
- this.elementsChange.applyTo(elements, snapshot.elements);
189
-
190
- const [nextAppState, appStateContainsVisibleChange] =
191
- this.appStateChange.applyTo(appState, nextElements);
192
-
193
- const appliedVisibleChanges =
194
- elementsContainVisibleChange || appStateContainsVisibleChange;
195
-
196
- return [nextElements, nextAppState, appliedVisibleChanges];
197
- }
198
-
199
- /**
200
- * Apply latest (remote) changes to the history entry, creates new instance of `HistoryEntry`.
201
- */
202
- public applyLatestChanges(elements: SceneElementsMap): HistoryEntry {
203
- const updatedElementsChange =
204
- this.elementsChange.applyLatestChanges(elements);
205
-
206
- return HistoryEntry.create(this.appStateChange, updatedElementsChange);
207
- }
208
-
209
- public isEmpty(): boolean {
210
- return this.appStateChange.isEmpty() && this.elementsChange.isEmpty();
245
+ private static push(stack: HistoryDelta[], entry: HistoryDelta) {
246
+ const inversedEntry = HistoryDelta.inverse(entry);
247
+ return stack.push(inversedEntry);
211
248
  }
212
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwelle/excalidraw",
3
- "version": "0.5.0-ddf5c00",
3
+ "version": "0.5.0-dfd3a9a",
4
4
  "type": "module",
5
5
  "types": "./dist/types/excalidraw/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -60,12 +60,22 @@
60
60
  "last 1 safari version"
61
61
  ]
62
62
  },
63
+ "repository": "https://github.com/excalidraw/excalidraw",
64
+ "bugs": "https://github.com/excalidraw/excalidraw/issues",
65
+ "homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
66
+ "scripts": {
67
+ "gen:types": "rimraf types && tsc",
68
+ "build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
69
+ },
63
70
  "peerDependencies": {
64
71
  "react": "^17.0.2 || ^18.2.0 || ^19.0.0",
65
72
  "react-dom": "^17.0.2 || ^18.2.0 || ^19.0.0"
66
73
  },
67
74
  "dependencies": {
68
75
  "@braintree/sanitize-url": "6.0.2",
76
+ "@excalidraw/common": "0.18.0",
77
+ "@excalidraw/element": "0.18.0",
78
+ "@excalidraw/math": "0.18.0",
69
79
  "@excalidraw/laser-pointer": "1.3.1",
70
80
  "@excalidraw/mermaid-to-excalidraw": "1.1.2",
71
81
  "@excalidraw/random-username": "1.1.0",
@@ -118,12 +128,5 @@
118
128
  "harfbuzzjs": "0.3.6",
119
129
  "jest-diff": "29.7.0",
120
130
  "typescript": "4.9.4"
121
- },
122
- "bugs": "https://github.com/excalidraw/excalidraw/issues",
123
- "homepage": "https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw",
124
- "repository": "https://github.com/dwelle/excalidraw",
125
- "scripts": {
126
- "gen:types": "rm -rf types && tsc",
127
- "build:esm": "rm -rf dist && node ../../scripts/buildPackage.js && yarn gen:types"
128
131
  }
129
132
  }