@excalidraw/element 0.18.0-063e025 → 0.18.0-1118751

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 (154) hide show
  1. package/dist/dev/index.js +13047 -9808
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +19 -19
  4. package/dist/types/common/src/colors.d.ts +22 -0
  5. package/dist/types/common/src/constants.d.ts +54 -0
  6. package/dist/types/common/src/keys.d.ts +4 -0
  7. package/dist/types/common/src/points.d.ts +1 -1
  8. package/dist/types/common/src/random.d.ts +7 -0
  9. package/dist/types/common/src/utils.d.ts +1 -1
  10. package/dist/types/element/src/Scene.d.ts +1 -1
  11. package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
  12. package/dist/types/element/src/arrows/focus.d.ts +5 -2
  13. package/dist/types/element/src/binding.d.ts +15 -8
  14. package/dist/types/element/src/bucketFill.d.ts +110 -0
  15. package/dist/types/element/src/collision.d.ts +8 -5
  16. package/dist/types/element/src/comparisons.d.ts +7 -5
  17. package/dist/types/element/src/convertToShape.d.ts +23 -0
  18. package/dist/types/element/src/delta.d.ts +23 -1
  19. package/dist/types/element/src/dragElements.d.ts +27 -0
  20. package/dist/types/element/src/duplicate.d.ts +60 -0
  21. package/dist/types/element/src/flowchart.d.ts +10 -6
  22. package/dist/types/element/src/frame.d.ts +2 -2
  23. package/dist/types/element/src/groups.d.ts +1 -1
  24. package/dist/types/element/src/index.d.ts +4 -0
  25. package/dist/types/element/src/linearElementEditor.d.ts +17 -0
  26. package/dist/types/element/src/mutateElement.d.ts +1 -1
  27. package/dist/types/element/src/newElement.d.ts +37 -2
  28. package/dist/types/element/src/renderElement.d.ts +21 -4
  29. package/dist/types/element/src/selection.d.ts +1 -1
  30. package/dist/types/element/src/shape.d.ts +27 -1
  31. package/dist/types/element/src/sizeHelpers.d.ts +6 -0
  32. package/dist/types/element/src/sortElements.d.ts +10 -0
  33. package/dist/types/element/src/stickyNote.d.ts +183 -0
  34. package/dist/types/element/src/textElement.d.ts +7 -3
  35. package/dist/types/element/src/transform.d.ts +25 -6
  36. package/dist/types/element/src/typeChecks.d.ts +3 -2
  37. package/dist/types/element/src/types.d.ts +35 -6
  38. package/dist/types/element/src/utils.d.ts +15 -4
  39. package/dist/types/element/src/zindex.d.ts +1 -1
  40. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +48 -9
  41. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  42. package/dist/types/excalidraw/actions/actionBoundText.d.ts +32 -6
  43. package/dist/types/excalidraw/actions/actionCanvas.d.ts +173 -576
  44. package/dist/types/excalidraw/actions/actionClipboard.d.ts +32 -6
  45. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +16 -3
  46. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +50 -10
  47. package/dist/types/excalidraw/actions/actionDeselect.d.ts +13 -3
  48. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -2
  49. package/dist/types/excalidraw/actions/actionElementLink.d.ts +16 -3
  50. package/dist/types/excalidraw/actions/actionElementLock.d.ts +32 -6
  51. package/dist/types/excalidraw/actions/actionExport.d.ts +34 -8
  52. package/dist/types/excalidraw/actions/actionFinalize.d.ts +1 -0
  53. package/dist/types/excalidraw/actions/actionFrame.d.ts +99 -185
  54. package/dist/types/excalidraw/actions/actionGroup.d.ts +33 -7
  55. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +68 -4
  56. package/dist/types/excalidraw/actions/actionLink.d.ts +16 -3
  57. package/dist/types/excalidraw/actions/actionMenu.d.ts +16 -3
  58. package/dist/types/excalidraw/actions/actionProperties.d.ts +45 -12
  59. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +16 -3
  60. package/dist/types/excalidraw/actions/actionStyles.d.ts +17 -4
  61. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
  62. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +16 -3
  63. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +16 -3
  64. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +16 -3
  65. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +16 -3
  66. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +16 -3
  67. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +16 -3
  68. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +17 -4
  69. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +16 -3
  70. package/dist/types/excalidraw/actions/colorTargets.d.ts +39 -0
  71. package/dist/types/excalidraw/actions/index.d.ts +1 -2
  72. package/dist/types/excalidraw/actions/manager.d.ts +1 -0
  73. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  74. package/dist/types/excalidraw/actions/types.d.ts +5 -1
  75. package/dist/types/excalidraw/appState.d.ts +26 -5
  76. package/dist/types/excalidraw/components/Actions.d.ts +16 -10
  77. package/dist/types/excalidraw/components/App.arrowText.d.ts +104 -0
  78. package/dist/types/excalidraw/components/App.bucketFill.d.ts +48 -0
  79. package/dist/types/excalidraw/components/App.cursor.d.ts +38 -0
  80. package/dist/types/excalidraw/components/App.d.ts +468 -99
  81. package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
  82. package/dist/types/excalidraw/components/App.duplicate.d.ts +51 -0
  83. package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
  84. package/dist/types/excalidraw/components/App.pan.d.ts +54 -0
  85. package/dist/types/excalidraw/components/App.toolDrag.d.ts +63 -0
  86. package/dist/types/excalidraw/components/App.viewport.d.ts +73 -0
  87. package/dist/types/excalidraw/components/App.wheel.d.ts +26 -0
  88. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +8 -2
  89. package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +3 -1
  90. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +5 -1
  91. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +9 -2
  92. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +4 -2
  93. package/dist/types/excalidraw/components/ColorPicker/TopPicks.d.ts +8 -1
  94. package/dist/types/excalidraw/components/ColorPicker/colorTopPicksDnD.d.ts +11 -0
  95. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +2 -1
  96. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +4 -1
  97. package/dist/types/excalidraw/components/FontPicker/FontPickerList.d.ts +6 -1
  98. package/dist/types/excalidraw/components/FontPicker/fontTopPicksDnD.d.ts +12 -0
  99. package/dist/types/excalidraw/components/IconButton.d.ts +48 -0
  100. package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
  101. package/dist/types/excalidraw/components/LayerUI.d.ts +5 -2
  102. package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
  103. package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
  104. package/dist/types/excalidraw/components/MobileMenu.d.ts +4 -4
  105. package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
  106. package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
  107. package/dist/types/excalidraw/components/Popover.d.ts +1 -3
  108. package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
  109. package/dist/types/excalidraw/components/ToolPopover.d.ts +3 -6
  110. package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
  111. package/dist/types/excalidraw/components/Tools.d.ts +151 -0
  112. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksContextMenu.d.ts +14 -0
  113. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksTip.d.ts +11 -0
  114. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +58 -0
  115. package/dist/types/excalidraw/components/UserList.d.ts +3 -2
  116. package/dist/types/excalidraw/components/ViewportStatusFrame/ViewportStatusFrame.d.ts +11 -0
  117. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -0
  118. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +2 -0
  119. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  120. package/dist/types/excalidraw/components/icons.d.ts +5 -1
  121. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -1
  122. package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
  123. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
  124. package/dist/types/excalidraw/data/blob.d.ts +36 -10
  125. package/dist/types/excalidraw/data/json.d.ts +18 -5
  126. package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
  127. package/dist/types/excalidraw/fonts/Fonts.d.ts +3 -2
  128. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +5 -5
  129. package/dist/types/excalidraw/lasso/utils.d.ts +2 -0
  130. package/dist/types/excalidraw/renderOverrides.d.ts +9 -0
  131. package/dist/types/excalidraw/renderer/helpers.d.ts +25 -0
  132. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
  133. package/dist/types/excalidraw/scene/Renderer.d.ts +64 -2
  134. package/dist/types/excalidraw/scene/index.d.ts +1 -1
  135. package/dist/types/excalidraw/scene/types.d.ts +6 -1
  136. package/dist/types/excalidraw/types.d.ts +341 -21
  137. package/dist/types/excalidraw/viewport.d.ts +31 -66
  138. package/dist/types/laser-pointer/src/state.d.ts +1 -0
  139. package/dist/types/math/src/curve.d.ts +19 -12
  140. package/dist/types/math/src/index.d.ts +1 -0
  141. package/dist/types/math/src/pca.d.ts +79 -0
  142. package/dist/types/math/src/polygon.d.ts +25 -1
  143. package/dist/types/math/src/segment.d.ts +6 -0
  144. package/dist/types/utils/src/export.d.ts +1 -0
  145. package/dist/types/utils/src/shape.d.ts +2 -2
  146. package/package.json +4 -4
  147. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +0 -173
  148. package/dist/types/excalidraw/components/FollowMode/FollowMode.d.ts +0 -10
  149. package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
  150. package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -10
  151. package/dist/types/excalidraw/components/ToolButton.d.ts +0 -49
  152. package/dist/types/excalidraw/components/shapes.d.ts +0 -270
  153. package/dist/types/excalidraw/cursor.d.ts +0 -5
  154. package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
@@ -1,10 +1,14 @@
1
1
  import type { SceneBounds } from "@excalidraw/element";
2
2
  import type { Bounds } from "@excalidraw/common";
3
- import type { ExcalidrawElement, NonDeleted, NonDeletedSceneElementsMap } from "@excalidraw/element/types";
3
+ import type { ExcalidrawElement } from "@excalidraw/element/types";
4
4
  import type { AppState, NormalizedZoomValue, Offsets, PointerCoords, ScrollConstraints, ViewportOffsets, Zoom } from "./types";
5
- export declare const SCROLL_TO_CONTENT_ANIMATION_KEY = "animateScrollToContent";
6
5
  /** default rubberband overscroll give for scroll locks, in viewport px */
7
6
  export declare const DEFAULT_OVERSCROLL = 150;
7
+ type ZoomOptions = {
8
+ viewportX: number;
9
+ viewportY: number;
10
+ nextZoom: NormalizedZoomValue;
11
+ };
8
12
  export type AnimationOptions = {
9
13
  duration?: number;
10
14
  };
@@ -14,7 +18,6 @@ export type SetViewportRect = {
14
18
  width?: number;
15
19
  height?: number;
16
20
  };
17
- export declare const isSetViewportRect: (target: unknown) => target is SetViewportRect;
18
21
  export type SetViewportOptions = {
19
22
  /**
20
23
  * what to show in the viewport: an explicit scene-coordinate box/rect,
@@ -63,22 +66,13 @@ type Viewport = Pick<AppState, "scrollX" | "scrollY" | "zoom">;
63
66
  * resting clamp — pass 0 for a hard clamp.
64
67
  */
65
68
  export declare const constrainScrollState: (state: Pick<AppState, "scrollX" | "scrollY" | "zoom" | "width" | "height" | "scrollConstraints">, overscroll?: number) => Viewport;
66
- export declare const isViewportOverscrolled: (state: Pick<AppState, "scrollX" | "scrollY" | "zoom" | "width" | "height" | "scrollConstraints">) => boolean;
67
- /**
68
- * Rubberband snap-back: animates the viewport from its current (possibly
69
- * overscrolled) position back inside the lock box via the shared
70
- * AnimationController. No-op when already within the hard bounds (or when there
71
- * is no lock).
72
- */
73
- export declare const animateToConstraints: (state: Pick<AppState, "scrollX" | "scrollY" | "zoom" | "width" | "height" | "scrollConstraints">, onFrame: (viewport: Pick<AppState, "scrollX" | "scrollY" | "zoom" | "shouldCacheIgnoreZoom">) => void, duration?: number) => void;
74
69
  /**
75
- * Scrolls (and, per `fit`, zooms) the viewport so the given target box is in
76
- * view, optionally animating the transition. `onComplete` runs once the
77
- * viewport has settled on the target.
70
+ * Resolves a focal-point zoom against the active scroll constraints while
71
+ * preserving the current rubberband displacement in screen pixels. This lets
72
+ * zoom and scroll-constraint snap-back compose without either visually
73
+ * cancelling the other.
78
74
  */
79
- export declare const setViewportToBounds: (state: AppState, bounds: Bounds, opts: Pick<SetViewportOptions, "fit" | "animation"> & {
80
- offsets?: Offsets;
81
- }, onFrame: (state: Pick<AppState, "scrollX" | "scrollY" | "zoom" | "shouldCacheIgnoreZoom">) => void, onComplete?: () => void) => void;
75
+ export declare const getViewportForZoomWithScrollConstraints: (opts: ZoomOptions, state: AppState) => Viewport;
82
76
  export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, minZoom, maxZoom, steppedZoom, }: {
83
77
  bounds: SceneBounds;
84
78
  canvasOffsets?: Offsets;
@@ -106,26 +100,31 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
106
100
  element: import("@excalidraw/element/types").NonDeletedExcalidrawElement;
107
101
  state: "hover" | "active";
108
102
  } | null;
109
- newElement: NonDeleted<import("@excalidraw/element/types").ExcalidrawNonSelectionElement> | null;
103
+ newElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawNonSelectionElement> | null;
110
104
  resizingElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
111
- multiElement: NonDeleted<import("@excalidraw/element/types").ExcalidrawLinearElement> | null;
105
+ multiElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawLinearElement> | null;
112
106
  selectionElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
113
107
  isBindingEnabled: boolean;
114
108
  boxSelectionMode: import("./types").BoxSelectionMode;
115
109
  bindingPreference: "enabled" | "disabled";
116
110
  isMidpointSnappingEnabled: boolean;
111
+ inputDevice: import("./types").InputDevice;
117
112
  suggestedBinding: {
118
- element: NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement>;
113
+ element: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement>;
119
114
  midPoint?: import("@excalidraw/math").GlobalPoint;
120
115
  } | null;
121
- frameToHighlight: NonDeleted<import("@excalidraw/element/types").ExcalidrawFrameLikeElement> | null;
116
+ hoveredArrowTextAnchor: {
117
+ elementId: import("@excalidraw/element/types").ExcalidrawArrowElement["id"];
118
+ anchor: "start" | "end" | "label";
119
+ } | null;
120
+ frameToHighlight: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawFrameLikeElement> | null;
122
121
  frameRendering: {
123
122
  enabled: boolean;
124
123
  name: boolean;
125
124
  outline: boolean;
126
125
  clip: boolean;
127
126
  };
128
- editingFrame: string | null;
127
+ editingFrame: import("@excalidraw/element/types").ExcalidrawFrameLikeElement["id"] | null;
129
128
  elementsToHighlight: readonly import("@excalidraw/element/types").NonDeletedExcalidrawElement[] | null;
130
129
  editingTextElement: import("@excalidraw/element/types").ExcalidrawTextElement | null;
131
130
  activeTool: {
@@ -144,6 +143,8 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
144
143
  exportWithDarkMode: boolean;
145
144
  exportScale: number;
146
145
  currentItemStrokeColor: string;
146
+ currentItemStickynoteStrokeColor: string;
147
+ currentItemStickynoteBackgroundColor: string;
147
148
  currentItemBackgroundColor: string;
148
149
  currentItemFillStyle: ExcalidrawElement["fillStyle"];
149
150
  currentItemStrokeWidthKey: import("@excalidraw/common").StrokeWidthKey;
@@ -235,8 +236,6 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
235
236
  y: number;
236
237
  } | null;
237
238
  objectsSnapModeEnabled: boolean;
238
- userToFollow: import("./types").UserToFollow | null;
239
- followedBy: Set<import("./types").SocketId>;
240
239
  isCropping: boolean;
241
240
  croppingElementId: ExcalidrawElement["id"] | null;
242
241
  searchMatches: Readonly<{
@@ -248,51 +247,17 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
248
247
  [groupId: string]: true;
249
248
  };
250
249
  bindMode: import("@excalidraw/element/types").BindMode;
250
+ colorTopPicks: {
251
+ elementStroke: readonly string[] | null;
252
+ elementBackground: readonly string[] | null;
253
+ bucketFill: readonly string[] | null;
254
+ stickyNoteStroke: readonly string[] | null;
255
+ stickyNoteBackground: readonly string[] | null;
256
+ };
257
+ fontTopPicks: readonly import("@excalidraw/element/types").FontFamilyValues[] | null;
251
258
  };
252
259
  captureUpdate: "EVENTUALLY";
253
260
  };
254
- /** Computes the viewport (scroll + zoom) that brings the target box into view,
255
- * based on the requested fit behavior. */
256
- export declare const getTargetViewport: (state: AppState, bounds: Bounds, fit?: SetViewportOptions["fit"], offsets?: Offsets) => Viewport;
257
- export type ResolvedViewportTarget = {
258
- /** null when the target couldn't be resolved (unknown id/link, or all
259
- * supplied elements deleted) */
260
- bounds: Bounds | null;
261
- /** how the target was specified, so callers can react to unresolved
262
- * targets themselves (e.g. toast on a broken element link) */
263
- type: "element" | "area" | "link";
264
- };
265
- /** Resolves a `setViewport` target to a scene-coordinate box. */
266
- export declare const resolveViewportTarget: (target: SetViewportOptions["target"], elementsMap: NonDeletedSceneElementsMap, appState: Pick<AppState, "width" | "height">) => ResolvedViewportTarget;
267
- /** Computes the viewport patch for landing on `bounds`: the target
268
- * scroll/zoom, plus the scroll lock to install — or `scrollConstraints: null`
269
- * to clear a previous lock when none is requested. */
270
- export declare const getConstrainedTargetViewport: (appState: AppState, bounds: Bounds, { fit, offsets, lock, }: Pick<SetViewportOptions, "fit" | "lock"> & {
271
- offsets?: Offsets;
272
- }) => Viewport & {
273
- scrollConstraints: ScrollConstraints | null;
274
- };
275
- /**
276
- * Interpolates the viewport from `from` to `target` at the (already-eased)
277
- * blend amount `factor` (0 = `from`, 1 = `target`).
278
- *
279
- * Zoom is interpolated geometrically (so it feels uniform), but the pan can't
280
- * simply lerp alongside it: pairing a geometric zoom with a linear scroll (or
281
- * a linearly-tweened focal point) makes scene points swoop along curved,
282
- * non-monotone screen paths once the zoom ratio exceeds ~e (the destination
283
- * visibly drifts away before converging). Instead we interpolate the view
284
- * transform affinely — a scene point maps to screen as
285
- * `(scenePt + scroll) * zoom`, and requiring every point to travel a straight
286
- * screen line forces `zoom` to be a convex blend `(1-m)*z0 + m*z1` with
287
- * `scroll * zoom` lerped by that same weight. Deriving `m` from the geometric
288
- * zoom keeps its pacing while making all screen trajectories straight and
289
- * monotone.
290
- */
291
- export declare const interpolateViewport: ({ from, target, factor, }: {
292
- from: Viewport;
293
- target: Viewport;
294
- factor: number;
295
- }) => Viewport;
296
261
  export declare const getClosestElementBounds: (elements: readonly ExcalidrawElement[], from: {
297
262
  x: number;
298
263
  y: number;
@@ -6,6 +6,7 @@ export type SizeMappingDetails = {
6
6
  totalLength: number;
7
7
  };
8
8
  export type LaserPointerOptions = {
9
+ /** @default 2 */
9
10
  size: number;
10
11
  streamline: number;
11
12
  simplify: number;
@@ -16,20 +16,25 @@ export declare function curveIntersectLineSegment<Point extends GlobalPoint | Lo
16
16
  tolerance?: number;
17
17
  iterLimit?: number;
18
18
  }): Point[];
19
+ /**
20
+ * Finds the parameter on the Bezier curve whose point is closest to another
21
+ * point
22
+ *
23
+ * @param c The curve to test
24
+ * @param p The point to measure from
25
+ * @param tolerance The width of the search window under which the bisection
26
+ * stops refining the parameter
27
+ */
28
+ export declare function curveClosestParameter<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): number;
19
29
  /**
20
30
  * Finds the closest point on the Bezier curve from another point
21
31
  *
22
- * @param x
23
- * @param y
24
- * @param P0
25
- * @param P1
26
- * @param P2
27
- * @param P3
28
- * @param tolerance
29
- * @param maxLevel
30
- * @returns
32
+ * @param c The curve to test
33
+ * @param p The point to measure from
34
+ * @param tolerance The width of the search window under which the bisection
35
+ * stops refining the parameter
31
36
  */
32
- export declare function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): Point | null;
37
+ export declare function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): Point;
33
38
  /**
34
39
  * Determines the distance between a point and the closest point on the
35
40
  * Bezier curve.
@@ -37,7 +42,7 @@ export declare function curveClosestPoint<Point extends GlobalPoint | LocalPoint
37
42
  * @param c The curve to test
38
43
  * @param p The point to measure from
39
44
  */
40
- export declare function curvePointDistance<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point): number;
45
+ export declare function curvePointDistance<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): number;
41
46
  /**
42
47
  * Determines if the parameter is a Curve
43
48
  */
@@ -74,4 +79,6 @@ export declare function curveLengthAtParameter<P extends GlobalPoint | LocalPoin
74
79
  * @param percent A value between 0 and 1 representing the percentage of the curve's length
75
80
  * @returns The point at the specified percentage of curve length
76
81
  */
77
- export declare function curvePointAtLength<P extends GlobalPoint | LocalPoint>(c: Curve<P>, percent: number): P;
82
+ export declare function curvePointAtLength<P extends GlobalPoint | LocalPoint>(c: Curve<P>, percent: number,
83
+ /** pass the curve's total length when already known to skip recomputing it */
84
+ totalLength?: number): P;
@@ -2,6 +2,7 @@ export * from "./angle";
2
2
  export * from "./curve";
3
3
  export * from "./ellipse";
4
4
  export * from "./line";
5
+ export * from "./pca";
5
6
  export * from "./point";
6
7
  export * from "./polygon";
7
8
  export * from "./range";
@@ -0,0 +1,79 @@
1
+ import type { GlobalPoint, LocalPoint, Vector } from "./types";
2
+ /**
3
+ * The principal axes of a point set, i.e. the eigen decomposition of its
4
+ * 2x2 covariance matrix.
5
+ *
6
+ * The axes are orthonormal and ordered by variance, so `major` is the
7
+ * direction along which the points spread the most. Together with `centroid`
8
+ * they define a canonical frame: expressing the points in it removes
9
+ * translation and rotation, and dividing by `sqrt(majorVariance)` removes
10
+ * scale.
11
+ */
12
+ export type PrincipalAxes<Point extends GlobalPoint | LocalPoint> = {
13
+ centroid: Point;
14
+ /** Unit vector along the direction of largest variance. */
15
+ major: Vector;
16
+ /** Unit vector along the direction of smallest variance, normal to major. */
17
+ minor: Vector;
18
+ /** Variance along `major` (the larger eigenvalue, λ₁). */
19
+ majorVariance: number;
20
+ /** Variance along `minor` (the smaller eigenvalue, λ₂). */
21
+ minorVariance: number;
22
+ };
23
+ /**
24
+ * A point expressed in a principal axes frame: `u` along the major axis,
25
+ * `v` along the minor axis, both relative to the centroid.
26
+ */
27
+ export type PrincipalCoords = [u: number, v: number];
28
+ /**
29
+ * Compute the centroid of a point set.
30
+ */
31
+ export declare function centroid<Point extends GlobalPoint | LocalPoint>(points: readonly Point[]): Point;
32
+ /**
33
+ * Principal component analysis of a 2D point set.
34
+ *
35
+ * Computes the centroid and the eigen decomposition of the covariance matrix
36
+ * [[μ20, μ11], [μ11, μ02]].
37
+ *
38
+ * @param points At least two points; fewer leaves the axes degenerate.
39
+ * @returns The centroid, the orthonormal axes and their variances.
40
+ */
41
+ export declare function principalAxes<Point extends GlobalPoint | LocalPoint>(points: readonly Point[]): PrincipalAxes<Point>;
42
+ /**
43
+ * Express points in the frame of the given principal axes, making the point
44
+ * cloud rotation, scale and translation invariant.
45
+ */
46
+ export declare function principalCoords<Point extends GlobalPoint | LocalPoint>(points: readonly Point[], axes: PrincipalAxes<Point>, scale?: number): PrincipalCoords[];
47
+ /**
48
+ * Flip the major axis so that it points toward the denser end of the point
49
+ * cloud, resolving the 180° sign ambiguity of the eigenvector.
50
+ *
51
+ * @returns The axes with `major`/`minor` flipped if needed. Variances are
52
+ * unchanged, as they are invariant to axis sign.
53
+ */
54
+ export declare function orientPrincipalAxes<Point extends GlobalPoint | LocalPoint>(points: readonly Point[], axes: PrincipalAxes<Point>): PrincipalAxes<Point>;
55
+ /**
56
+ * Ratio of the minor to the major variance in [0, 1]
57
+ *
58
+ * @returns 0 is a perfectly straight stroke, 1 is a stroke with no preferred
59
+ * direction.
60
+ */
61
+ export declare function elongation<Point extends GlobalPoint | LocalPoint>(axes: PrincipalAxes<Point>): number;
62
+ /**
63
+ * The `order`-th standardized moment of a sample in a rotation and scale
64
+ * invariant way (sandardizing by sigma).
65
+ *
66
+ * @returns 0 for a degenerate (zero variance) sample.
67
+ */
68
+ export declare function standardizedMoment(values: readonly number[], order: number): number;
69
+ /**
70
+ * Third standardized moment: how lopsided a sample is.
71
+ *
72
+ */
73
+ export declare function skewness(values: readonly number[]): number;
74
+ /**
75
+ * Fourth standardized moment: how the mass is split between the tails and the
76
+ * middle of a sample. Not excess kurtosis, a normal sample gives 3.
77
+ *
78
+ */
79
+ export declare function kurtosis(values: readonly number[]): number;
@@ -3,4 +3,28 @@ export declare function polygon<Point extends GlobalPoint | LocalPoint>(...point
3
3
  export declare function polygonFromPoints<Point extends GlobalPoint | LocalPoint>(points: Point[]): Polygon<Point>;
4
4
  export declare const polygonIncludesPoint: <Point extends LocalPoint | GlobalPoint>(point: Point, polygon: Polygon<Point>) => boolean;
5
5
  export declare const polygonIncludesPointNonZero: <Point extends [number, number]>(point: Point, polygon: Point[]) => boolean;
6
- export declare const pointOnPolygon: <Point extends LocalPoint | GlobalPoint>(p: Point, poly: Polygon<Point>, threshold?: number) => boolean;
6
+ export declare function polygonIsClosed<Point extends LocalPoint | GlobalPoint>(polygon: readonly Point[], tolerance?: number): boolean;
7
+ /**
8
+ * The signed area of a polygon via the shoelace formula. Positive when the
9
+ * vertices wind counter-clockwise in a y-down coordinate system.
10
+ *
11
+ * The polygon may be given open or closed; a closing vertex
12
+ */
13
+ export declare function polygonSignedArea<Point extends LocalPoint | GlobalPoint>(polygon: readonly Point[], tolerance?: number): number;
14
+ export declare function polygonArea<Point extends LocalPoint | GlobalPoint>(polygon: readonly Point[], tolerance?: number): number;
15
+ /**
16
+ * The convex hull of a point set via Andrew's monotone chain.
17
+ *
18
+ * @returns The hull vertices in counter-clockwise order (y-down), without a
19
+ * repeated closing vertex.
20
+ */
21
+ export declare function convexHull<Point extends LocalPoint | GlobalPoint>(points: readonly Point[]): Point[];
22
+ /**
23
+ * Drop the points of a convex polygon that only contribute a shallow turn,
24
+ * merging each run of near-collinear points into one.
25
+ *
26
+ * @param polygon A convex polygon, as returned by `convexHull`.
27
+ * @param angleThreshold Minimum accumulated turn (radians) for a vertex to be
28
+ * kept.
29
+ */
30
+ export declare function simplifyConvexPolygon<Point extends LocalPoint | GlobalPoint>(polygon: readonly Point[], angleThreshold: number): Point[];
@@ -29,6 +29,11 @@ export declare const lineSegmentRotate: <Point extends LocalPoint | GlobalPoint>
29
29
  export declare const segmentsIntersectAt: <Point extends GlobalPoint | LocalPoint>(a: Readonly<LineSegment<Point>>, b: Readonly<LineSegment<Point>>) => Point | null;
30
30
  export declare const pointOnLineSegment: <Point extends LocalPoint | GlobalPoint>(point: Point, line: LineSegment<Point>, threshold?: number) => boolean;
31
31
  export declare const distanceToLineSegment: <Point extends LocalPoint | GlobalPoint>(point: Point, line: LineSegment<Point>) => number;
32
+ /**
33
+ * Returns the point at parameter `t` along the segment, where `t = 0` is the
34
+ * segment's start and `t = 1` its end. Not clamped.
35
+ */
36
+ export declare function lineSegmentPointAt<Point extends GlobalPoint | LocalPoint>(line: LineSegment<Point>, t: number): Point;
32
37
  /**
33
38
  * Returns the intersection point of a segment and a line
34
39
  *
@@ -38,3 +43,4 @@ export declare const distanceToLineSegment: <Point extends LocalPoint | GlobalPo
38
43
  */
39
44
  export declare function lineSegmentIntersectionPoints<Point extends GlobalPoint | LocalPoint>(l: LineSegment<Point>, s: LineSegment<Point>, threshold?: number): Point | null;
40
45
  export declare function lineSegmentsDistance<Point extends GlobalPoint | LocalPoint>(s1: LineSegment<Point>, s2: LineSegment<Point>): number;
46
+ export declare function lineSegmentClosestParameter<Point extends GlobalPoint | LocalPoint>(point: Point, line: LineSegment<Point>): number;
@@ -3,6 +3,7 @@ import type { ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElemen
3
3
  import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
4
4
  export { MIME_TYPES };
5
5
  type ExportOpts = {
6
+ /** restored before exporting */
6
7
  elements: readonly NonDeletedExcalidrawElement[];
7
8
  appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
8
9
  files: BinaryFiles | null;
@@ -1,5 +1,5 @@
1
1
  import { type GlobalPoint, type LocalPoint } from "@excalidraw/math";
2
- import type { ElementsMap, ExcalidrawBindableElement, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawTextElement } from "@excalidraw/element/types";
2
+ import type { ElementsMap, ExcalidrawBindableElement, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawStickyNoteElement, ExcalidrawTextElement } from "@excalidraw/element/types";
3
3
  import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
4
4
  import type { Drawable, Op } from "roughjs/bin/core";
5
5
  export type Polyline<Point extends GlobalPoint | LocalPoint> = LineSegment<Point>[];
@@ -29,7 +29,7 @@ export type GeometricShape<Point extends GlobalPoint | LocalPoint> = {
29
29
  type: "polycurve";
30
30
  data: Polycurve<Point>;
31
31
  };
32
- type RectangularElement = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawFrameLikeElement | ExcalidrawEmbeddableElement | ExcalidrawImageElement | ExcalidrawIframeElement | ExcalidrawTextElement | ExcalidrawSelectionElement;
32
+ type RectangularElement = ExcalidrawRectangleElement | ExcalidrawStickyNoteElement | ExcalidrawDiamondElement | ExcalidrawFrameLikeElement | ExcalidrawEmbeddableElement | ExcalidrawImageElement | ExcalidrawIframeElement | ExcalidrawTextElement | ExcalidrawSelectionElement;
33
33
  export declare const getPolygonShape: <Point extends GlobalPoint | LocalPoint>(element: RectangularElement) => GeometricShape<Point>;
34
34
  export declare const getSelectionBoxShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawElement, elementsMap: ElementsMap, padding?: number) => GeometricShape<Point>;
35
35
  export declare const getEllipseShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawEllipseElement) => GeometricShape<Point>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/element",
3
- "version": "0.18.0-063e025",
3
+ "version": "0.18.0-1118751",
4
4
  "type": "module",
5
5
  "types": "./dist/types/element/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -63,8 +63,8 @@
63
63
  "build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
64
64
  },
65
65
  "dependencies": {
66
- "@excalidraw/common": "0.18.0-063e025",
67
- "@excalidraw/math": "0.18.0-063e025",
68
- "@excalidraw/fractional-indexing": "0.18.0-063e025"
66
+ "@excalidraw/common": "0.18.0-1118751",
67
+ "@excalidraw/math": "0.18.0-1118751",
68
+ "@excalidraw/fractional-indexing": "0.18.0-1118751"
69
69
  }
70
70
  }
@@ -1,173 +0,0 @@
1
- export declare const actionSetEmbeddableAsActiveTool: {
2
- name: "setEmbeddableAsActiveTool";
3
- trackEvent: {
4
- category: "toolbar";
5
- };
6
- target: string;
7
- label: string;
8
- perform: (elements: readonly import("@excalidraw/element/types").OrderedExcalidrawElement[], appState: Readonly<import("../types").AppState>, _: unknown, app: import("../types").AppClassProperties) => {
9
- elements: readonly import("@excalidraw/element/types").OrderedExcalidrawElement[];
10
- appState: {
11
- activeTool: {
12
- lastActiveTool: import("../types").ActiveTool | null;
13
- locked: boolean;
14
- fromSelection: boolean;
15
- } & import("../types").ActiveTool;
16
- contextMenu: {
17
- items: import("../components/ContextMenu").ContextMenuItems;
18
- top: number;
19
- left: number;
20
- } | null;
21
- showWelcomeScreen: boolean;
22
- isLoading: boolean;
23
- errorMessage: React.ReactNode;
24
- activeEmbeddable: {
25
- element: import("@excalidraw/element/types").NonDeletedExcalidrawElement;
26
- state: "hover" | "active";
27
- } | null;
28
- newElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawNonSelectionElement> | null;
29
- resizingElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
30
- multiElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawLinearElement> | null;
31
- selectionElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
32
- isBindingEnabled: boolean;
33
- boxSelectionMode: import("../types").BoxSelectionMode;
34
- bindingPreference: "enabled" | "disabled";
35
- isMidpointSnappingEnabled: boolean;
36
- suggestedBinding: {
37
- element: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement>;
38
- midPoint?: import("@excalidraw/math").GlobalPoint;
39
- } | null;
40
- frameToHighlight: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawFrameLikeElement> | null;
41
- frameRendering: {
42
- enabled: boolean;
43
- name: boolean;
44
- outline: boolean;
45
- clip: boolean;
46
- };
47
- editingFrame: string | null;
48
- elementsToHighlight: readonly import("@excalidraw/element/types").NonDeletedExcalidrawElement[] | null;
49
- editingTextElement: import("@excalidraw/element/types").ExcalidrawTextElement | null;
50
- preferredSelectionTool: {
51
- type: "selection" | "lasso";
52
- initialized: boolean;
53
- };
54
- penMode: boolean;
55
- penDetected: boolean;
56
- exportBackground: boolean;
57
- exportEmbedScene: boolean;
58
- exportWithDarkMode: boolean;
59
- exportScale: number;
60
- currentItemStrokeColor: string;
61
- currentItemBackgroundColor: string;
62
- currentItemFillStyle: import("@excalidraw/element/types").ExcalidrawElement["fillStyle"];
63
- currentItemStrokeWidthKey: import("@excalidraw/common").StrokeWidthKey;
64
- currentItemStrokeStyle: import("@excalidraw/element/types").ExcalidrawElement["strokeStyle"];
65
- currentItemRoughness: number;
66
- currentItemStrokeVariability: import("@excalidraw/element/types").StrokeVariability;
67
- currentItemOpacity: number;
68
- currentItemFontFamily: import("@excalidraw/element/types").FontFamilyValues;
69
- currentItemFontSize: number;
70
- currentItemTextAlign: import("@excalidraw/element/types").TextAlign;
71
- currentItemStartArrowhead: import("@excalidraw/element/types").Arrowhead | null;
72
- currentItemEndArrowhead: import("@excalidraw/element/types").Arrowhead | null;
73
- currentHoveredFontFamily: import("@excalidraw/element/types").FontFamilyValues | null;
74
- currentItemRoundness: import("@excalidraw/element/types").StrokeRoundness;
75
- currentItemArrowType: "sharp" | "round" | "elbow";
76
- viewBackgroundColor: string;
77
- scrollX: number;
78
- scrollY: number;
79
- scrollConstraints: import("../types").ScrollConstraints | null;
80
- cursorButton: "up" | "down";
81
- scrolledOutside: boolean;
82
- name: string | null;
83
- isResizing: boolean;
84
- isRotating: boolean;
85
- zoom: import("../types").Zoom;
86
- openMenu: "canvas" | null;
87
- openPopup: "canvasBackground" | "elementBackground" | "elementStroke" | "fontFamily" | "compactTextProperties" | "compactStrokeStyles" | "compactOtherProperties" | "compactArrowProperties" | null;
88
- openSidebar: {
89
- name: import("../types").SidebarName;
90
- tab?: import("../types").SidebarTabName;
91
- } | null;
92
- openDialog: null | {
93
- name: "imageExport" | "help" | "jsonExport";
94
- } | {
95
- name: "ttd";
96
- tab: "text-to-diagram" | "mermaid";
97
- } | {
98
- name: "commandPalette";
99
- } | {
100
- name: "settings";
101
- } | {
102
- name: "elementLinkSelector";
103
- sourceElementId: import("@excalidraw/element/types").ExcalidrawElement["id"];
104
- } | {
105
- name: "charts";
106
- data: import("../charts").Spreadsheet;
107
- rawText: string;
108
- };
109
- defaultSidebarDockedPreference: boolean;
110
- lastPointerDownWith: import("@excalidraw/element/types").PointerType;
111
- selectedElementIds: Readonly<{
112
- [id: string]: true;
113
- }>;
114
- hoveredElementIds: Readonly<{
115
- [id: string]: true;
116
- }>;
117
- previousSelectedElementIds: {
118
- [id: string]: true;
119
- };
120
- selectedElementsAreBeingDragged: boolean;
121
- shouldCacheIgnoreZoom: boolean;
122
- toast: {
123
- message: React.ReactNode;
124
- closable?: boolean;
125
- duration?: number;
126
- } | null;
127
- zenModeEnabled: boolean;
128
- theme: import("@excalidraw/element/types").Theme;
129
- gridSize: number;
130
- gridStep: number;
131
- gridModeEnabled: boolean;
132
- viewModeEnabled: boolean;
133
- selectedGroupIds: {
134
- [groupId: string]: boolean;
135
- };
136
- editingGroupId: import("@excalidraw/element/types").GroupId | null;
137
- width: number;
138
- height: number;
139
- offsetTop: number;
140
- offsetLeft: number;
141
- fileHandle: FileSystemFileHandle | null;
142
- collaborators: Map<import("../types").SocketId, import("../types").Collaborator>;
143
- stats: {
144
- open: boolean;
145
- panels: number;
146
- };
147
- showHyperlinkPopup: false | "info" | "editor";
148
- selectedLinearElement: import("@excalidraw/element").LinearElementEditor | null;
149
- snapLines: readonly import("../snapping").SnapLine[];
150
- originSnapOffset: {
151
- x: number;
152
- y: number;
153
- } | null;
154
- objectsSnapModeEnabled: boolean;
155
- userToFollow: import("../types").UserToFollow | null;
156
- followedBy: Set<import("../types").SocketId>;
157
- isCropping: boolean;
158
- croppingElementId: import("@excalidraw/element/types").ExcalidrawElement["id"] | null;
159
- searchMatches: Readonly<{
160
- focusedId: import("@excalidraw/element/types").ExcalidrawElement["id"] | null;
161
- matches: readonly import("../types").SearchMatch[];
162
- }> | null;
163
- activeLockedId: string | null;
164
- lockedMultiSelections: {
165
- [groupId: string]: true;
166
- };
167
- bindMode: import("@excalidraw/element/types").BindMode;
168
- };
169
- captureUpdate: "EVENTUALLY";
170
- };
171
- } & {
172
- keyTest?: undefined;
173
- };
@@ -1,10 +0,0 @@
1
- import "./FollowMode.scss";
2
- import type { UserToFollow } from "../../types";
3
- interface FollowModeProps {
4
- width: number;
5
- height: number;
6
- userToFollow: UserToFollow;
7
- onDisconnect: () => void;
8
- }
9
- declare const FollowMode: ({ height, width, userToFollow, onDisconnect, }: FollowModeProps) => import("react/jsx-runtime").JSX.Element;
10
- export default FollowMode;
@@ -1,10 +0,0 @@
1
- import "./ToolIcon.scss";
2
- type LockIconProps = {
3
- title?: string;
4
- name?: string;
5
- checked: boolean;
6
- onChange?(): void;
7
- isMobile?: boolean;
8
- };
9
- export declare const HandButton: (props: LockIconProps) => import("react/jsx-runtime").JSX.Element;
10
- export {};
@@ -1,10 +0,0 @@
1
- import "./ToolIcon.scss";
2
- import "./MobileToolBar.scss";
3
- import type { AppClassProperties, UIAppState } from "../types";
4
- type MobileToolBarProps = {
5
- app: AppClassProperties;
6
- onHandToolToggle: () => void;
7
- setAppState: React.Component<any, UIAppState>["setState"];
8
- };
9
- export declare const MobileToolBar: ({ app, onHandToolToggle, setAppState, }: MobileToolBarProps) => import("react/jsx-runtime").JSX.Element;
10
- export {};