@excalidraw/excalidraw 0.18.0-195a743 → 0.18.0-298812e

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 (139) hide show
  1. package/dist/dev/{chunk-T3M44BFV.js → chunk-JCUIYZXF.js} +7 -3
  2. package/dist/dev/chunk-JCUIYZXF.js.map +7 -0
  3. package/dist/dev/{chunk-WMGEUIQQ.js → chunk-RQWTCZLD.js} +2 -2
  4. package/dist/dev/{chunk-H3EW23X2.js → chunk-ZPGIVNNG.js} +14840 -9652
  5. package/dist/dev/chunk-ZPGIVNNG.js.map +7 -0
  6. package/dist/dev/data/{image-TTQKTTOH.js → image-CB4ZYE3A.js} +3 -3
  7. package/dist/dev/index.css +38 -2
  8. package/dist/dev/index.css.map +2 -2
  9. package/dist/dev/index.js +857 -5250
  10. package/dist/dev/index.js.map +4 -4
  11. package/dist/dev/locales/{en-I23TB6DJ.js → en-ZDTPSZNL.js} +2 -2
  12. package/dist/dev/subset-shared.chunk.js +1 -1
  13. package/dist/dev/subset-worker.chunk.js +1 -1
  14. package/dist/prod/{chunk-GK4XUKZB.js → chunk-7TMLMBQX.js} +1 -1
  15. package/dist/prod/{chunk-2Z7RPVPO.js → chunk-GCFVWREF.js} +3 -3
  16. package/dist/prod/chunk-WFJFO6F4.js +33 -0
  17. package/dist/prod/data/image-XJI4SWH2.js +1 -0
  18. package/dist/prod/index.css +1 -1
  19. package/dist/prod/index.js +18 -18
  20. package/dist/prod/locales/{en-TC3OFDA6.js → en-MHZ26NAR.js} +1 -1
  21. package/dist/prod/subset-shared.chunk.js +1 -1
  22. package/dist/prod/subset-worker.chunk.js +1 -1
  23. package/dist/types/common/src/constants.d.ts +1 -0
  24. package/dist/types/{excalidraw → common/src}/emitter.d.ts +1 -1
  25. package/dist/types/common/src/font-metadata.d.ts +4 -2
  26. package/dist/types/common/src/index.d.ts +1 -0
  27. package/dist/types/common/src/utility-types.d.ts +5 -0
  28. package/dist/types/common/src/utils.d.ts +16 -4
  29. package/dist/types/element/src/Scene.d.ts +4 -4
  30. package/dist/types/element/src/ShapeCache.d.ts +1 -1
  31. package/dist/types/element/src/align.d.ts +1 -1
  32. package/dist/types/element/src/binding.d.ts +1 -1
  33. package/dist/types/element/src/bounds.d.ts +1 -1
  34. package/dist/types/{excalidraw/change.d.ts → element/src/delta.d.ts} +40 -35
  35. package/dist/types/element/src/dragElements.d.ts +1 -1
  36. package/dist/types/element/src/flowchart.d.ts +1 -1
  37. package/dist/types/element/src/frame.d.ts +3 -2
  38. package/dist/types/element/src/index.d.ts +45 -2
  39. package/dist/types/element/src/linearElementEditor.d.ts +4 -8
  40. package/dist/types/element/src/newElement.d.ts +1 -1
  41. package/dist/types/element/src/resizeElements.d.ts +1 -1
  42. package/dist/types/element/src/selection.d.ts +1 -6
  43. package/dist/types/element/src/store.d.ts +227 -0
  44. package/dist/types/element/src/textElement.d.ts +1 -1
  45. package/dist/types/element/src/transformHandles.d.ts +4 -4
  46. package/dist/types/element/src/typeChecks.d.ts +2 -1
  47. package/dist/types/element/src/types.d.ts +6 -1
  48. package/dist/types/element/src/zindex.d.ts +3 -3
  49. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +24 -42
  50. package/dist/types/excalidraw/actions/actionAlign.d.ts +8 -8
  51. package/dist/types/excalidraw/actions/actionBoundText.d.ts +16 -28
  52. package/dist/types/excalidraw/actions/actionCanvas.d.ts +194 -272
  53. package/dist/types/excalidraw/actions/actionClipboard.d.ts +50 -86
  54. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +8 -14
  55. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +22 -40
  56. package/dist/types/excalidraw/actions/actionDistribute.d.ts +4 -4
  57. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
  58. package/dist/types/excalidraw/actions/actionElementLink.d.ts +8 -14
  59. package/dist/types/excalidraw/actions/actionElementLock.d.ts +18 -30
  60. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +8 -14
  61. package/dist/types/excalidraw/actions/actionExport.d.ts +159 -213
  62. package/dist/types/excalidraw/actions/actionFinalize.d.ts +14 -26
  63. package/dist/types/excalidraw/actions/actionFlip.d.ts +4 -4
  64. package/dist/types/excalidraw/actions/actionFrame.d.ts +76 -100
  65. package/dist/types/excalidraw/actions/actionGroup.d.ts +22 -34
  66. package/dist/types/excalidraw/actions/actionHistory.d.ts +1 -2
  67. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +7 -13
  68. package/dist/types/excalidraw/actions/actionLink.d.ts +9 -15
  69. package/dist/types/excalidraw/actions/actionMenu.d.ts +26 -44
  70. package/dist/types/excalidraw/actions/actionNavigate.d.ts +16 -28
  71. package/dist/types/excalidraw/actions/actionProperties.d.ts +106 -196
  72. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +10 -16
  73. package/dist/types/excalidraw/actions/actionStyles.d.ts +12 -18
  74. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +10 -16
  75. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +10 -16
  76. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +10 -189
  77. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +10 -16
  78. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +10 -16
  79. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +10 -16
  80. package/dist/types/excalidraw/actions/actionZindex.d.ts +10 -10
  81. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  82. package/dist/types/excalidraw/appState.d.ts +23 -23
  83. package/dist/types/excalidraw/components/App.d.ts +9 -9
  84. package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -1
  85. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +5 -1
  86. package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +1 -1
  87. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -3
  88. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -3
  89. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -2
  90. package/dist/types/excalidraw/components/ColorPicker/TopPicks.d.ts +1 -1
  91. package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +1 -1
  92. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +1 -1
  93. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -28
  94. package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
  95. package/dist/types/excalidraw/components/Range.d.ts +3 -3
  96. package/dist/types/excalidraw/components/Stats/Angle.d.ts +1 -1
  97. package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +1 -1
  98. package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +2 -1
  99. package/dist/types/excalidraw/components/Stats/Dimension.d.ts +1 -1
  100. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +1 -1
  101. package/dist/types/excalidraw/components/Stats/FontSize.d.ts +1 -1
  102. package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +1 -1
  103. package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +1 -1
  104. package/dist/types/excalidraw/components/Stats/MultiFontSize.d.ts +1 -1
  105. package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +1 -1
  106. package/dist/types/excalidraw/components/Stats/Position.d.ts +1 -1
  107. package/dist/types/excalidraw/components/Stats/utils.d.ts +2 -1
  108. package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +1 -1
  109. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -1
  110. package/dist/types/excalidraw/components/icons.d.ts +1 -0
  111. package/dist/types/excalidraw/components/shapes.d.ts +1 -1
  112. package/dist/types/excalidraw/data/blob.d.ts +1 -1
  113. package/dist/types/excalidraw/data/transform.d.ts +1 -1
  114. package/dist/types/excalidraw/fonts/Fonts.d.ts +1 -1
  115. package/dist/types/excalidraw/history.d.ts +14 -22
  116. package/dist/types/excalidraw/hooks/useEmitter.d.ts +1 -1
  117. package/dist/types/excalidraw/index.d.ts +9 -9
  118. package/dist/types/excalidraw/lasso/index.d.ts +1 -0
  119. package/dist/types/excalidraw/renderer/helpers.d.ts +6 -1
  120. package/dist/types/excalidraw/scene/Renderer.d.ts +1 -1
  121. package/dist/types/excalidraw/scene/index.d.ts +2 -2
  122. package/dist/types/excalidraw/snapping.d.ts +2 -2
  123. package/dist/types/excalidraw/types.d.ts +13 -6
  124. package/dist/types/excalidraw/visualdebug.d.ts +1 -1
  125. package/dist/types/math/src/curve.d.ts +2 -0
  126. package/dist/types/math/src/vector.d.ts +4 -0
  127. package/dist/types/utils/src/bbox.d.ts +1 -1
  128. package/dist/types/utils/src/index.d.ts +1 -1
  129. package/dist/types/utils/src/withinBounds.d.ts +1 -1
  130. package/history.ts +68 -94
  131. package/package.json +3 -3
  132. package/dist/dev/chunk-H3EW23X2.js.map +0 -7
  133. package/dist/dev/chunk-T3M44BFV.js.map +0 -7
  134. package/dist/prod/chunk-7M43VNIB.js +0 -33
  135. package/dist/prod/data/image-7YYIWLVQ.js +0 -1
  136. package/dist/types/excalidraw/store.d.ts +0 -129
  137. /package/dist/dev/{chunk-WMGEUIQQ.js.map → chunk-RQWTCZLD.js.map} +0 -0
  138. /package/dist/dev/data/{image-TTQKTTOH.js.map → image-CB4ZYE3A.js.map} +0 -0
  139. /package/dist/dev/locales/{en-I23TB6DJ.js.map → en-ZDTPSZNL.js.map} +0 -0
@@ -1,40 +1,32 @@
1
+ import { Emitter } from "@excalidraw/common";
2
+ import { StoreDelta, type Store } from "@excalidraw/element";
1
3
  import type { SceneElementsMap } from "@excalidraw/element/types";
2
- import { Emitter } from "./emitter";
3
- import type { AppStateChange, ElementsChange } from "./change";
4
- import type { Snapshot } from "./store";
5
4
  import type { AppState } from "./types";
5
+ declare class HistoryEntry extends StoreDelta {
6
+ }
6
7
  export declare class HistoryChangedEvent {
7
8
  readonly isUndoStackEmpty: boolean;
8
9
  readonly isRedoStackEmpty: boolean;
9
10
  constructor(isUndoStackEmpty?: boolean, isRedoStackEmpty?: boolean);
10
11
  }
11
12
  export declare class History {
13
+ private readonly store;
12
14
  readonly onHistoryChangedEmitter: Emitter<[HistoryChangedEvent]>;
13
- private readonly undoStack;
14
- private readonly redoStack;
15
+ readonly undoStack: HistoryEntry[];
16
+ readonly redoStack: HistoryEntry[];
15
17
  get isUndoStackEmpty(): boolean;
16
18
  get isRedoStackEmpty(): boolean;
19
+ constructor(store: Store);
17
20
  clear(): void;
18
21
  /**
19
- * Record a local change which will go into the history
22
+ * Record a non-empty local durable increment, which will go into the undo stack..
23
+ * Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
20
24
  */
21
- record(elementsChange: ElementsChange, appStateChange: AppStateChange): void;
22
- undo(elements: SceneElementsMap, appState: AppState, snapshot: Readonly<Snapshot>): void | [SceneElementsMap, AppState];
23
- redo(elements: SceneElementsMap, appState: AppState, snapshot: Readonly<Snapshot>): void | [SceneElementsMap, AppState];
25
+ record(delta: StoreDelta): void;
26
+ undo(elements: SceneElementsMap, appState: AppState): void | [SceneElementsMap, AppState];
27
+ redo(elements: SceneElementsMap, appState: AppState): void | [SceneElementsMap, AppState];
24
28
  private perform;
25
29
  private static pop;
26
30
  private static push;
27
31
  }
28
- export declare class HistoryEntry {
29
- readonly appStateChange: AppStateChange;
30
- readonly elementsChange: ElementsChange;
31
- private constructor();
32
- static create(appStateChange: AppStateChange, elementsChange: ElementsChange): HistoryEntry;
33
- inverse(): HistoryEntry;
34
- applyTo(elements: SceneElementsMap, appState: AppState, snapshot: Readonly<Snapshot>): [SceneElementsMap, AppState, boolean];
35
- /**
36
- * Apply latest (remote) changes to the history entry, creates new instance of `HistoryEntry`.
37
- */
38
- applyLatestChanges(elements: SceneElementsMap): HistoryEntry;
39
- isEmpty(): boolean;
40
- }
32
+ export {};
@@ -1,2 +1,2 @@
1
- import type { Emitter } from "../emitter";
1
+ import type { Emitter } from "@excalidraw/common";
2
2
  export declare const useEmitter: <TEvent extends unknown>(emitter: Emitter<[TEvent]>, initialState: TEvent) => TEvent;
@@ -9,20 +9,20 @@ import "./fonts/fonts.css";
9
9
  import type { ExcalidrawProps } from "./types";
10
10
  export declare const Excalidraw: React.MemoExoticComponent<(props: ExcalidrawProps) => import("react/jsx-runtime").JSX.Element>;
11
11
  export { getSceneVersion, hashElementsVersion, hashString, getNonDeletedElements, } from "@excalidraw/element";
12
- export { getTextFromElements } from "@excalidraw/element/textElement";
13
- export { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers";
12
+ export { getTextFromElements } from "@excalidraw/element";
13
+ export { isInvisiblySmallElement } from "@excalidraw/element";
14
14
  export { defaultLang, useI18n, languages } from "./i18n";
15
15
  export { restore, restoreAppState, restoreElements, restoreLibraryItems, } from "./data/restore";
16
16
  export { reconcileElements } from "./data/reconcile";
17
17
  export { exportToCanvas, exportToBlob, exportToSvg, exportToClipboard, } from "@excalidraw/utils/export";
18
18
  export { serializeAsJSON, serializeLibraryAsJSON } from "./data/json";
19
19
  export { loadFromBlob, loadSceneOrLibraryFromBlob, loadLibraryFromBlob, } from "./data/blob";
20
- export { getFreeDrawSvgPath } from "@excalidraw/element/renderElement";
20
+ export { getFreeDrawSvgPath } from "@excalidraw/element";
21
21
  export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
22
- export { isLinearElement } from "@excalidraw/element/typeChecks";
22
+ export { isLinearElement } from "@excalidraw/element";
23
23
  export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS, DEFAULT_LASER_COLOR, UserIdleState, normalizeLink, } from "@excalidraw/common";
24
- export { mutateElement, newElementWith, bumpVersion, } from "@excalidraw/element/mutateElement";
25
- export { CaptureUpdateAction } from "./store";
24
+ export { mutateElement, newElementWith, bumpVersion, } from "@excalidraw/element";
25
+ export { CaptureUpdateAction } from "@excalidraw/element";
26
26
  export { parseLibraryTokensFromUrl, useHandleLibrary } from "./data/library";
27
27
  export { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, } from "@excalidraw/common";
28
28
  export { Sidebar } from "./components/Sidebar/Sidebar";
@@ -38,9 +38,9 @@ export { TTDDialog } from "./components/TTDDialog/TTDDialog";
38
38
  export { TTDDialogTrigger } from "./components/TTDDialog/TTDDialogTrigger";
39
39
  export { zoomToFitBounds } from "./actions/actionCanvas";
40
40
  export { convertToExcalidrawElements } from "./data/transform";
41
- export { getCommonBounds, getVisibleSceneBounds, } from "@excalidraw/element/bounds";
41
+ export { getCommonBounds, getVisibleSceneBounds } from "@excalidraw/element";
42
42
  export { elementsOverlappingBBox, isElementInsideBBox, elementPartiallyOverlapsWithOrContainsBBox, } from "@excalidraw/utils/withinBounds";
43
43
  export { DiagramToCodePlugin } from "./components/DiagramToCodePlugin/DiagramToCodePlugin";
44
44
  export { getDataURL } from "./data/blob";
45
- export { isElementLink } from "@excalidraw/element/elementLink";
46
- export { setCustomTextMetricsProvider } from "@excalidraw/element/textMeasurements";
45
+ export { isElementLink } from "@excalidraw/element";
46
+ export { setCustomTextMetricsProvider } from "@excalidraw/element";
@@ -5,6 +5,7 @@ export declare class LassoTrail extends AnimatedTrail {
5
5
  private intersectedElements;
6
6
  private enclosedElements;
7
7
  private elementsSegments;
8
+ private canvasTranslate;
8
9
  private keepPreviousSelection;
9
10
  constructor(animationFrameHandler: AnimationFrameHandler, app: App);
10
11
  startPath(x: number, y: number, keepPreviousSelection?: boolean): void;
@@ -1,5 +1,6 @@
1
+ import type { ExcalidrawDiamondElement, ExcalidrawRectanguloidElement } from "@excalidraw/element/types";
1
2
  import type { StaticCanvasRenderConfig } from "../scene/types";
2
- import type { StaticCanvasAppState, AppState } from "../types";
3
+ import type { AppState, StaticCanvasAppState } from "../types";
3
4
  export declare const fillCircle: (context: CanvasRenderingContext2D, cx: number, cy: number, radius: number, stroke?: boolean) => void;
4
5
  export declare const getNormalizedCanvasDimensions: (canvas: HTMLCanvasElement, scale: number) => [number, number];
5
6
  export declare const bootstrapCanvas: ({ canvas, scale, normalizedWidth, normalizedHeight, theme, isExporting, viewBackgroundColor, }: {
@@ -11,3 +12,7 @@ export declare const bootstrapCanvas: ({ canvas, scale, normalizedWidth, normali
11
12
  isExporting?: boolean | undefined;
12
13
  viewBackgroundColor?: string | null | undefined;
13
14
  }) => CanvasRenderingContext2D;
15
+ export declare const drawHighlightForRectWithRotation: (context: CanvasRenderingContext2D, element: ExcalidrawRectanguloidElement, padding: number) => void;
16
+ export declare const strokeEllipseWithRotation: (context: CanvasRenderingContext2D, width: number, height: number, cx: number, cy: number, angle: number) => void;
17
+ export declare const strokeRectWithRotation: (context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, cx: number, cy: number, angle: number, fill?: boolean, radius?: number) => void;
18
+ export declare const drawHighlightForDiamondWithRotation: (context: CanvasRenderingContext2D, padding: number, element: ExcalidrawDiamondElement) => void;
@@ -1,5 +1,5 @@
1
1
  import type { ExcalidrawElement, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
2
- import type Scene from "@excalidraw/element/Scene";
2
+ import type { Scene } from "@excalidraw/element";
3
3
  import type { AppState } from "../types";
4
4
  export declare class Renderer {
5
5
  private scene;
@@ -1,4 +1,4 @@
1
- export { isSomeElementSelected, getElementsWithinSelection, getCommonAttributeOfSelectedElements, getSelectedElements, getTargetElements, } from "@excalidraw/element/selection";
1
+ export { isSomeElementSelected, getElementsWithinSelection, getSelectedElements, getTargetElements, } from "@excalidraw/element";
2
2
  export { calculateScrollCenter } from "./scroll";
3
- export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeRoundness, } from "@excalidraw/element/comparisons";
3
+ export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeRoundness, } from "@excalidraw/element";
4
4
  export { getNormalizedZoom, getNormalizedGridSize, getNormalizedGridStep, } from "./normalize";
@@ -1,7 +1,7 @@
1
1
  import { type GlobalPoint } from "@excalidraw/math";
2
2
  import type { InclusiveRange } from "@excalidraw/math";
3
- import type { Bounds } from "@excalidraw/element/bounds";
4
- import type { MaybeTransformHandleType } from "@excalidraw/element/transformHandles";
3
+ import type { Bounds } from "@excalidraw/element";
4
+ import type { MaybeTransformHandleType } from "@excalidraw/element";
5
5
  import type { ElementsMap, ExcalidrawElement, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
6
6
  import type { AppClassProperties, AppState, KeyboardModifiersObject } from "./types";
7
7
  export declare const getSnapDistance: (zoomValue: number) => number;
@@ -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";
2
+ import type { SuggestedBinding } from "@excalidraw/element";
3
+ import type { LinearElementEditor } from "@excalidraw/element";
4
+ import type { MaybeTransformHandleType } from "@excalidraw/element";
5
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";
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";
@@ -341,9 +341,13 @@ export interface AppState {
341
341
  /** image cropping */
342
342
  isCropping: boolean;
343
343
  croppingElementId: ExcalidrawElement["id"] | null;
344
- searchMatches: readonly SearchMatch[];
344
+ /** null if no search matches found / search closed */
345
+ searchMatches: Readonly<{
346
+ focusedId: ExcalidrawElement["id"] | null;
347
+ matches: readonly SearchMatch[];
348
+ }> | null;
345
349
  }
346
- type SearchMatch = {
350
+ export type SearchMatch = {
347
351
  id: string;
348
352
  focus: boolean;
349
353
  matchedLines: {
@@ -351,6 +355,7 @@ type SearchMatch = {
351
355
  offsetY: number;
352
356
  width: number;
353
357
  height: number;
358
+ showOnCanvas: boolean;
354
359
  }[];
355
360
  };
356
361
  export type UIAppState = Omit<AppState, "suggestedBindings" | "startBoundElement" | "cursorButton" | "scrollX" | "scrollY">;
@@ -403,6 +408,7 @@ export type OnUserFollowedPayload = {
403
408
  };
404
409
  export interface ExcalidrawProps {
405
410
  onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
411
+ onIncrement?: (event: DurableIncrement | EphemeralIncrement) => void;
406
412
  initialData?: (() => MaybePromise<ExcalidrawInitialDataState | null>) | MaybePromise<ExcalidrawInitialDataState | null>;
407
413
  excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
408
414
  isCollaborating?: boolean;
@@ -635,6 +641,7 @@ export interface ExcalidrawImperativeAPI {
635
641
  */
636
642
  updateFrameRendering: InstanceType<typeof App>["updateFrameRendering"];
637
643
  onChange: (callback: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles) => void) => UnsubscribeCallback;
644
+ onIncrement: (callback: (event: DurableIncrement | EphemeralIncrement) => void) => UnsubscribeCallback;
638
645
  onPointerDown: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: React.PointerEvent<HTMLElement>) => void) => UnsubscribeCallback;
639
646
  onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
640
647
  onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
@@ -1,7 +1,7 @@
1
1
  import { type GlobalPoint, type LocalPoint } from "@excalidraw/math";
2
2
  import type { Curve } from "@excalidraw/math";
3
3
  import type { LineSegment } from "@excalidraw/utils";
4
- import type { Bounds } from "@excalidraw/element/bounds";
4
+ import type { Bounds } from "@excalidraw/element";
5
5
  declare global {
6
6
  interface Window {
7
7
  visualDebug?: {
@@ -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,4 @@ 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;
@@ -86,3 +86,7 @@ export declare function vectorMagnitude(v: Vector): number;
86
86
  * @returns The new normalized vector
87
87
  */
88
88
  export declare const vectorNormalize: (v: Vector) => Vector;
89
+ /**
90
+ * Calculate the right-hand normal of the vector.
91
+ */
92
+ 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,17 @@
1
- import type { SceneElementsMap } from "@excalidraw/element/types";
1
+ import { Emitter } from "@excalidraw/common";
2
+
3
+ import {
4
+ CaptureUpdateAction,
5
+ StoreChange,
6
+ StoreDelta,
7
+ type Store,
8
+ } from "@excalidraw/element";
2
9
 
3
- import { Emitter } from "./emitter";
10
+ import type { SceneElementsMap } from "@excalidraw/element/types";
4
11
 
5
- import type { AppStateChange, ElementsChange } from "./change";
6
- import type { Snapshot } from "./store";
7
12
  import type { AppState } from "./types";
8
13
 
9
- type HistoryStack = HistoryEntry[];
14
+ class HistoryEntry extends StoreDelta {}
10
15
 
11
16
  export class HistoryChangedEvent {
12
17
  constructor(
@@ -20,8 +25,8 @@ export class History {
20
25
  [HistoryChangedEvent]
21
26
  >();
22
27
 
23
- private readonly undoStack: HistoryStack = [];
24
- private readonly redoStack: HistoryStack = [];
28
+ public readonly undoStack: HistoryEntry[] = [];
29
+ public readonly redoStack: HistoryEntry[] = [];
25
30
 
26
31
  public get isUndoStackEmpty() {
27
32
  return this.undoStack.length === 0;
@@ -31,60 +36,52 @@ export class History {
31
36
  return this.redoStack.length === 0;
32
37
  }
33
38
 
39
+ constructor(private readonly store: Store) {}
40
+
34
41
  public clear() {
35
42
  this.undoStack.length = 0;
36
43
  this.redoStack.length = 0;
37
44
  }
38
45
 
39
46
  /**
40
- * Record a local change which will go into the history
47
+ * Record a non-empty local durable increment, which will go into the undo stack..
48
+ * Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
41
49
  */
42
- public record(
43
- elementsChange: ElementsChange,
44
- appStateChange: AppStateChange,
45
- ) {
46
- const entry = HistoryEntry.create(appStateChange, elementsChange);
50
+ public record(delta: StoreDelta) {
51
+ if (delta.isEmpty() || delta instanceof HistoryEntry) {
52
+ return;
53
+ }
47
54
 
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());
55
+ // construct history entry, so once it's emitted, it's not recorded again
56
+ const entry = HistoryEntry.inverse(delta);
51
57
 
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
- }
58
+ this.undoStack.push(entry);
58
59
 
59
- this.onHistoryChangedEmitter.trigger(
60
- new HistoryChangedEvent(this.isUndoStackEmpty, this.isRedoStackEmpty),
61
- );
60
+ if (!entry.elements.isEmpty()) {
61
+ // don't reset redo stack on local appState changes,
62
+ // as a simple click (unselect) could lead to losing all the redo entries
63
+ // only reset on non empty elements changes!
64
+ this.redoStack.length = 0;
62
65
  }
66
+
67
+ this.onHistoryChangedEmitter.trigger(
68
+ new HistoryChangedEvent(this.isUndoStackEmpty, this.isRedoStackEmpty),
69
+ );
63
70
  }
64
71
 
65
- public undo(
66
- elements: SceneElementsMap,
67
- appState: AppState,
68
- snapshot: Readonly<Snapshot>,
69
- ) {
72
+ public undo(elements: SceneElementsMap, appState: AppState) {
70
73
  return this.perform(
71
74
  elements,
72
75
  appState,
73
- snapshot,
74
76
  () => History.pop(this.undoStack),
75
77
  (entry: HistoryEntry) => History.push(this.redoStack, entry, elements),
76
78
  );
77
79
  }
78
80
 
79
- public redo(
80
- elements: SceneElementsMap,
81
- appState: AppState,
82
- snapshot: Readonly<Snapshot>,
83
- ) {
81
+ public redo(elements: SceneElementsMap, appState: AppState) {
84
82
  return this.perform(
85
83
  elements,
86
84
  appState,
87
- snapshot,
88
85
  () => History.pop(this.redoStack),
89
86
  (entry: HistoryEntry) => History.push(this.undoStack, entry, elements),
90
87
  );
@@ -93,7 +90,6 @@ export class History {
93
90
  private perform(
94
91
  elements: SceneElementsMap,
95
92
  appState: AppState,
96
- snapshot: Readonly<Snapshot>,
97
93
  pop: () => HistoryEntry | null,
98
94
  push: (entry: HistoryEntry) => void,
99
95
  ): [SceneElementsMap, AppState] | void {
@@ -104,6 +100,10 @@ export class History {
104
100
  return;
105
101
  }
106
102
 
103
+ const action = CaptureUpdateAction.IMMEDIATELY;
104
+
105
+ let prevSnapshot = this.store.snapshot;
106
+
107
107
  let nextElements = elements;
108
108
  let nextAppState = appState;
109
109
  let containsVisibleChange = false;
@@ -112,9 +112,29 @@ export class History {
112
112
  while (historyEntry) {
113
113
  try {
114
114
  [nextElements, nextAppState, containsVisibleChange] =
115
- historyEntry.applyTo(nextElements, nextAppState, snapshot);
115
+ StoreDelta.applyTo(
116
+ historyEntry,
117
+ nextElements,
118
+ nextAppState,
119
+ prevSnapshot,
120
+ );
121
+
122
+ const nextSnapshot = prevSnapshot.maybeClone(
123
+ action,
124
+ nextElements,
125
+ nextAppState,
126
+ );
127
+
128
+ // schedule immediate capture, so that it's emitted for the sync purposes
129
+ this.store.scheduleMicroAction({
130
+ action,
131
+ change: StoreChange.create(prevSnapshot, nextSnapshot),
132
+ delta: historyEntry,
133
+ });
134
+
135
+ prevSnapshot = nextSnapshot;
116
136
  } finally {
117
- // make sure to always push / pop, even if the increment is corrupted
137
+ // make sure to always push, even if the delta is corrupted
118
138
  push(historyEntry);
119
139
  }
120
140
 
@@ -135,7 +155,7 @@ export class History {
135
155
  }
136
156
  }
137
157
 
138
- private static pop(stack: HistoryStack): HistoryEntry | null {
158
+ private static pop(stack: HistoryEntry[]): HistoryEntry | null {
139
159
  if (!stack.length) {
140
160
  return null;
141
161
  }
@@ -150,63 +170,17 @@ export class History {
150
170
  }
151
171
 
152
172
  private static push(
153
- stack: HistoryStack,
173
+ stack: HistoryEntry[],
154
174
  entry: HistoryEntry,
155
175
  prevElements: SceneElementsMap,
156
176
  ) {
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(),
177
+ const inversedEntry = HistoryEntry.inverse(entry);
178
+ const updatedEntry = HistoryEntry.applyLatestChanges(
179
+ inversedEntry,
180
+ prevElements,
181
+ "inserted",
179
182
  );
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
183
 
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();
184
+ return stack.push(updatedEntry);
211
185
  }
212
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/excalidraw",
3
- "version": "0.18.0-195a743",
3
+ "version": "0.18.0-298812e",
4
4
  "type": "module",
5
5
  "types": "./dist/types/excalidraw/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -129,7 +129,7 @@
129
129
  "bugs": "https://github.com/excalidraw/excalidraw/issues",
130
130
  "homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
131
131
  "scripts": {
132
- "gen:types": "rm -rf types && tsc",
133
- "build:esm": "rm -rf dist && node ../../scripts/buildPackage.js && yarn gen:types"
132
+ "gen:types": "rimraf types && tsc",
133
+ "build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
134
134
  }
135
135
  }