@excalidraw/math 0.18.0-2b1c2a9 → 0.18.0-2c3dcc0

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 (164) hide show
  1. package/dist/dev/index.js +8 -2
  2. package/dist/dev/index.js.map +2 -2
  3. package/dist/prod/index.js +1 -1
  4. package/dist/types/common/src/colors.d.ts +3 -0
  5. package/dist/types/common/src/constants.d.ts +56 -0
  6. package/dist/types/common/src/keys.d.ts +4 -0
  7. package/dist/types/common/src/random.d.ts +7 -0
  8. package/dist/types/common/src/utils.d.ts +12 -1
  9. package/dist/types/element/src/Scene.d.ts +1 -1
  10. package/dist/types/element/src/align.d.ts +4 -1
  11. package/dist/types/element/src/binding.d.ts +75 -7
  12. package/dist/types/element/src/bounds.d.ts +10 -2
  13. package/dist/types/element/src/collision.d.ts +21 -5
  14. package/dist/types/element/src/comparisons.d.ts +5 -3
  15. package/dist/types/element/src/cropElement.d.ts +36 -4
  16. package/dist/types/element/src/delta.d.ts +30 -2
  17. package/dist/types/element/src/distribute.d.ts +4 -1
  18. package/dist/types/element/src/dragElements.d.ts +8 -3
  19. package/dist/types/element/src/duplicate.d.ts +60 -0
  20. package/dist/types/element/src/elbowArrow.d.ts +5 -0
  21. package/dist/types/element/src/embeddable.d.ts +2 -1
  22. package/dist/types/element/src/flowchart.d.ts +6 -8
  23. package/dist/types/element/src/frame.d.ts +21 -3
  24. package/dist/types/element/src/groups.d.ts +1 -6
  25. package/dist/types/element/src/image.d.ts +5 -2
  26. package/dist/types/element/src/index.d.ts +3 -0
  27. package/dist/types/element/src/linearElementEditor.d.ts +4 -1
  28. package/dist/types/element/src/listMarker.d.ts +39 -0
  29. package/dist/types/element/src/mutateElement.d.ts +1 -1
  30. package/dist/types/element/src/newElement.d.ts +40 -3
  31. package/dist/types/element/src/renderElement.d.ts +31 -4
  32. package/dist/types/element/src/renderEnvironment.d.ts +66 -0
  33. package/dist/types/element/src/resizeElements.d.ts +15 -5
  34. package/dist/types/element/src/selection.d.ts +4 -10
  35. package/dist/types/element/src/shape.d.ts +17 -1
  36. package/dist/types/element/src/sizeHelpers.d.ts +6 -0
  37. package/dist/types/element/src/stickyNote.d.ts +191 -0
  38. package/dist/types/element/src/textElement.d.ts +10 -2
  39. package/dist/types/element/src/textMeasurements.d.ts +15 -11
  40. package/dist/types/element/src/textWrapping.d.ts +3 -2
  41. package/dist/types/element/src/transform.d.ts +30 -7
  42. package/dist/types/element/src/typeChecks.d.ts +3 -2
  43. package/dist/types/element/src/types.d.ts +28 -6
  44. package/dist/types/element/src/utils.d.ts +8 -1
  45. package/dist/types/element/src/zindex.d.ts +1 -1
  46. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +48 -3
  47. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  48. package/dist/types/excalidraw/actions/actionBoundText.d.ts +62 -208
  49. package/dist/types/excalidraw/actions/actionCanvas.d.ts +121 -16
  50. package/dist/types/excalidraw/actions/actionClipboard.d.ts +32 -2
  51. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +16 -1
  52. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +4 -546
  53. package/dist/types/excalidraw/actions/actionDeselect.d.ts +20 -2
  54. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -2
  55. package/dist/types/excalidraw/actions/actionElementLink.d.ts +16 -1
  56. package/dist/types/excalidraw/actions/actionElementLock.d.ts +32 -2
  57. package/dist/types/excalidraw/actions/actionExport.d.ts +39 -9
  58. package/dist/types/excalidraw/actions/actionFrame.d.ts +92 -479
  59. package/dist/types/excalidraw/actions/actionGroup.d.ts +34 -4
  60. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +66 -2
  61. package/dist/types/excalidraw/actions/actionLink.d.ts +16 -1
  62. package/dist/types/excalidraw/actions/actionMenu.d.ts +16 -1
  63. package/dist/types/excalidraw/actions/actionProperties.d.ts +42 -8
  64. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +17 -2
  65. package/dist/types/excalidraw/actions/actionStyles.d.ts +17 -2
  66. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +452 -6
  67. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +16 -1
  68. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +16 -1
  69. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +16 -1
  70. package/dist/types/excalidraw/actions/actionToggleMinimap.d.ts +201 -0
  71. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +16 -1
  72. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +16 -1
  73. package/dist/types/excalidraw/actions/actionToggleShowHints.d.ts +198 -0
  74. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +16 -1
  75. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +16 -1
  76. package/dist/types/excalidraw/actions/actionToggleWrap.d.ts +12 -0
  77. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +16 -1
  78. package/dist/types/excalidraw/actions/colorTargets.d.ts +39 -0
  79. package/dist/types/excalidraw/actions/index.d.ts +3 -0
  80. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  81. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  82. package/dist/types/excalidraw/appState.d.ts +26 -8
  83. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -1
  84. package/dist/types/excalidraw/charts/charts.helpers.d.ts +6 -5
  85. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -1
  86. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -1
  87. package/dist/types/excalidraw/charts/index.d.ts +2 -1
  88. package/dist/types/excalidraw/components/Actions.d.ts +10 -2
  89. package/dist/types/excalidraw/components/App.arrowText.d.ts +5 -39
  90. package/dist/types/excalidraw/components/App.clipboard.d.ts +31 -0
  91. package/dist/types/excalidraw/components/App.d.ts +129 -218
  92. package/dist/types/excalidraw/components/App.duplicate.d.ts +101 -0
  93. package/dist/types/excalidraw/components/App.host.d.ts +102 -0
  94. package/dist/types/excalidraw/components/App.modifiers.d.ts +38 -0
  95. package/dist/types/excalidraw/components/App.pan.d.ts +62 -0
  96. package/dist/types/excalidraw/components/App.selection.d.ts +265 -0
  97. package/dist/types/excalidraw/components/App.selectionTool.d.ts +94 -0
  98. package/dist/types/excalidraw/components/App.text.d.ts +194 -0
  99. package/dist/types/excalidraw/components/App.textTool.d.ts +140 -0
  100. package/dist/types/excalidraw/components/App.toolDrag.d.ts +63 -0
  101. package/dist/types/excalidraw/components/App.viewport.d.ts +64 -4
  102. package/dist/types/excalidraw/components/App.wheel.d.ts +30 -0
  103. package/dist/types/excalidraw/components/App.wrap.d.ts +39 -0
  104. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
  105. package/dist/types/excalidraw/components/ColorPicker/colorTopPicksDnD.d.ts +11 -0
  106. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -1
  107. package/dist/types/excalidraw/components/FileDropOverlay.d.ts +2 -0
  108. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +4 -1
  109. package/dist/types/excalidraw/components/FontPicker/FontPickerList.d.ts +6 -1
  110. package/dist/types/excalidraw/components/FontPicker/fontTopPicksDnD.d.ts +12 -0
  111. package/dist/types/excalidraw/components/IconButton.d.ts +2 -0
  112. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +6 -2
  113. package/dist/types/excalidraw/components/LibraryUnit.d.ts +7 -2
  114. package/dist/types/excalidraw/components/Minimap/Minimap.d.ts +15 -0
  115. package/dist/types/excalidraw/components/Minimap/MinimapAnnouncementDot.d.ts +10 -0
  116. package/dist/types/excalidraw/components/Minimap/minimap-controller.chunk.d.ts +90 -0
  117. package/dist/types/excalidraw/components/Minimap/minimap-shared.chunk.d.ts +122 -0
  118. package/dist/types/excalidraw/components/Minimap/minimap-worker.chunk.d.ts +12 -0
  119. package/dist/types/excalidraw/components/Stats/utils.d.ts +4 -2
  120. package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +2 -1
  121. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
  122. package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +5 -2
  123. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
  124. package/dist/types/excalidraw/components/TTDDialog/common.d.ts +4 -1
  125. package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +3 -2
  126. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +14 -1
  127. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +16 -0
  128. package/dist/types/excalidraw/components/Tools.d.ts +7 -2
  129. package/dist/types/excalidraw/components/Tooltip.d.ts +26 -2
  130. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksContextMenu.d.ts +14 -0
  131. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksTip.d.ts +11 -0
  132. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +58 -0
  133. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +0 -1
  134. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +2 -0
  135. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  136. package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +3 -2
  137. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +13 -2
  138. package/dist/types/excalidraw/components/icons.d.ts +2 -0
  139. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +3 -0
  140. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +2 -2
  141. package/dist/types/excalidraw/data/blob.d.ts +46 -16
  142. package/dist/types/excalidraw/data/index.d.ts +3 -3
  143. package/dist/types/excalidraw/data/json.d.ts +23 -8
  144. package/dist/types/excalidraw/fonts/Fonts.d.ts +9 -6
  145. package/dist/types/excalidraw/history.d.ts +10 -4
  146. package/dist/types/excalidraw/mermaid.d.ts +7 -0
  147. package/dist/types/excalidraw/reactUtils.d.ts +1 -1
  148. package/dist/types/excalidraw/renderOverrides.d.ts +9 -0
  149. package/dist/types/excalidraw/renderer/animation.d.ts +11 -4
  150. package/dist/types/excalidraw/renderer/helpers.d.ts +18 -0
  151. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
  152. package/dist/types/excalidraw/renderer/staticScene.d.ts +11 -6
  153. package/dist/types/excalidraw/scene/Renderer.d.ts +64 -3
  154. package/dist/types/excalidraw/scene/export.d.ts +343 -20
  155. package/dist/types/excalidraw/scene/index.d.ts +1 -1
  156. package/dist/types/excalidraw/scene/types.d.ts +26 -2
  157. package/dist/types/excalidraw/types.d.ts +191 -22
  158. package/dist/types/excalidraw/viewport.d.ts +29 -1
  159. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +12 -1
  160. package/dist/types/utils/src/index.d.ts +3 -1
  161. package/dist/types/utils/src/shape.d.ts +2 -2
  162. package/package.json +2 -2
  163. package/dist/types/excalidraw/components/ColorPicker/topPicksDnD.d.ts +0 -31
  164. package/dist/types/utils/src/export.d.ts +0 -35
@@ -0,0 +1,102 @@
1
+ import type { RenderEnvironment } from "@excalidraw/element";
2
+ import { type EyeDropperProperties } from "./EyeDropper";
3
+ import { type HyperlinkTooltipOwner } from "./hyperlink/Hyperlink";
4
+ import type { AppProps } from "../types";
5
+ import type App from "./App";
6
+ /**
7
+ * Owns everything that ties this editor to the document/window it renders
8
+ * into (cross-document runtime ownership): the render environment the
9
+ * canvases, images and paths are minted from, and the state that has to be
10
+ * re-primed whenever that environment is swapped.
11
+ */
12
+ export declare class AppHost {
13
+ private app;
14
+ constructor(app: App);
15
+ /**
16
+ * Identity token for the hyperlink tooltip, which is a module-level
17
+ * singleton shared by every editor in the process — the owner tells it
18
+ * which editor the currently shown tooltip belongs to, so one editor never
19
+ * hides (or leaks a timer into) another's tooltip.
20
+ */
21
+ readonly hyperlinkTooltipOwner: HyperlinkTooltipOwner;
22
+ /**
23
+ * The process-wide interaction slots this editor currently owns: the
24
+ * pointerup handler of the interaction in flight, and the eye dropper (one
25
+ * atom in the editor-wide store). Both hold closures over this editor, so a
26
+ * teardown that leaves one set retains the editor -- and with it its owner
27
+ * window and document, e.g. a closed popout.
28
+ *
29
+ * @see releaseOwnedInteractionState
30
+ */
31
+ private ownedPointerUp;
32
+ private ownedEyeDropper;
33
+ /** Takes over the pointerup slot (or clears it, on `null`). */
34
+ setPointerUp(handler: (() => void) | null): void;
35
+ /**
36
+ * Runs the pending pointerup, whoever owns it -- pointerup does not always
37
+ * fire (the user tabs away), so interactions are settled manually.
38
+ */
39
+ runPendingPointerUp(): void;
40
+ /** Opens the eye dropper (or closes it, on `null`), taking ownership. */
41
+ setActiveEyeDropper(eyeDropper: EyeDropperProperties | null): void;
42
+ /**
43
+ * Drops the ownership token without touching the atom -- for callers that
44
+ * have just closed the eye dropper themselves.
45
+ */
46
+ releaseEyeDropperOwnership(): void;
47
+ /**
48
+ * Releases the process-wide slots this editor owns, so nothing outside it
49
+ * keeps it alive once it is torn down. Ownership-checked: a sibling
50
+ * editor's in-flight interaction must survive our teardown.
51
+ */
52
+ private releaseOwnedInteractionState;
53
+ /**
54
+ * Render environment scoped to this editor's owner window, so that the
55
+ * canvases, images and paths created during rendering live in the owner
56
+ * document. Memoized keyed on the resolved document because render caches
57
+ * are keyed by environment identity: the identity must not survive a
58
+ * document switch, or caches would mix canvases and images from two realms
59
+ * under one bucket.
60
+ */
61
+ private _renderEnvironment;
62
+ private _renderEnvironmentDocument;
63
+ get renderEnvironment(): RenderEnvironment;
64
+ /**
65
+ * Re-primes whatever the render environment owns. Called on mount and on
66
+ * every update, so an environment swap is picked up wherever it happens.
67
+ */
68
+ sync(prevProps?: AppProps): void;
69
+ /**
70
+ * Releases what this editor owns outside itself, so we don't retain the
71
+ * (soon detached) document/window, or leave a pending tooltip timer around.
72
+ */
73
+ destroy(): void;
74
+ private _destroyed;
75
+ /**
76
+ * Link icons decode asynchronously and the static scene skips an icon that
77
+ * is not decoded yet, so start the decode on mount rather than on the
78
+ * first render that happens to have a link, so the decode is settled long
79
+ * before there is a link element to draw an icon for.
80
+ *
81
+ * Re-run on an environment swap: the images are keyed by env identity, so
82
+ * a new environment starts with none.
83
+ *
84
+ * The decode landing only flips a status, which invalidates nothing, so the
85
+ * scene is nudged once when an icon becomes drawable -- otherwise a scene
86
+ * that paints before the decode settles and is then left alone (an initial
87
+ * scene with links, never scrolled or edited) keeps its icons missing until
88
+ * something unrelated repaints. Same shape as a font or an image file
89
+ * landing: repaint only when there is something new to draw.
90
+ */
91
+ private _linkImgDecodingEnvironment;
92
+ private ensureLinkImgDecoding;
93
+ /**
94
+ * Every render cache is keyed by environment identity, so a host passing an
95
+ * inline `renderEnvironment` literal re-mints the identity on each render
96
+ * and re-rasterizes everything, with no visible symptom other than being
97
+ * slow. Detected by the factories' source being unchanged across the swap:
98
+ * a genuine environment switch (e.g. a document change) reads differently.
99
+ */
100
+ private _warnedUnstableRenderEnvironment;
101
+ private warnOnUnstableRenderEnvironment;
102
+ }
@@ -0,0 +1,38 @@
1
+ import { Emitter } from "@excalidraw/common";
2
+ export type HeldModifiers = Readonly<{
3
+ alt: boolean;
4
+ shift: boolean;
5
+ /** Ctrl, or Cmd on macOS */
6
+ ctrlOrCmd: boolean;
7
+ }>;
8
+ /**
9
+ * The modifier keys held over the editor, synced from the flags of its
10
+ * keyboard and pointer events. Kept out of appState so that pressing one
11
+ * re-renders only its subscribers (e.g. the hint).
12
+ */
13
+ export declare class AppModifiers {
14
+ private held;
15
+ /** fires with a new snapshot whenever a modifier is pressed or released */
16
+ readonly onChange: Emitter<[held: Readonly<{
17
+ alt: boolean;
18
+ shift: boolean;
19
+ /** Ctrl, or Cmd on macOS */
20
+ ctrlOrCmd: boolean;
21
+ }>]>;
22
+ get: () => HeldModifiers;
23
+ /**
24
+ * A hook re-rendering on the held modifiers: all of them, or with
25
+ * `modifier`, only on that one being pressed or released.
26
+ */
27
+ useHeld(): HeldModifiers;
28
+ useHeld(modifier: keyof HeldModifiers): boolean;
29
+ sync: (event: {
30
+ altKey: boolean;
31
+ shiftKey: boolean;
32
+ ctrlKey: boolean;
33
+ metaKey: boolean;
34
+ }) => void;
35
+ /** releases them all — e.g. on blur, as Alt+Tab never delivers the keyup */
36
+ reset: () => void;
37
+ private set;
38
+ }
@@ -0,0 +1,62 @@
1
+ import type React from "react";
2
+ import type App from "./App";
3
+ /**
4
+ * The drag-pan: a pointer drag that moves the canvas — the wheel or the
5
+ * secondary button, the main button while space is held or the hand tool
6
+ * is active, or any button in view mode. One session at a time, owning its
7
+ * window listeners and teardown; wheel input is gated on it (see
8
+ * `AppWheel`).
9
+ *
10
+ * A secondary-button session is a pan only once the pointer travels past
11
+ * the drag threshold; released before that, it is a right-click. The
12
+ * platform's `contextmenu` event opens the menu for a right-click where it
13
+ * follows the release (Windows), as it always has; where it comes with the
14
+ * press (macOS, Linux) it is swallowed — a drag cannot be told from a
15
+ * click yet — and the session opens the menu on release instead.
16
+ */
17
+ export declare class AppPan {
18
+ private app;
19
+ private dependencies;
20
+ /** space held down turns a main-button drag into a pan */
21
+ private spaceHeld;
22
+ private active;
23
+ /** the secondary-button session, while one is active */
24
+ private secondary;
25
+ /** the platform fires `contextmenu` on mouseup (Windows) or on mousedown
26
+ * (macOS, Linux); the one belonging to a secondary-button session is not a
27
+ * new click, whichever side of the session it lands on */
28
+ private suppressNextContextMenu;
29
+ /** applies the pointer move the session is holding back for its next
30
+ * frame, if any */
31
+ private pendingMoveFlush;
32
+ private teardown;
33
+ constructor(app: App, dependencies: {
34
+ /** pointers currently down (a two-finger gesture is not a pan) */
35
+ getPointerCount: () => number;
36
+ /** a scrollbar being dragged (App's own drag, not a pan session) */
37
+ isDraggingScrollBar: () => boolean;
38
+ });
39
+ isActive: () => boolean;
40
+ isSpaceHeld: () => boolean;
41
+ setSpaceHeld: (held: boolean) => void;
42
+ /**
43
+ * Whether the pointer is navigating the viewport rather than acting on the
44
+ * scene — space held to pan, a pan in progress, a scrollbar drag, or the
45
+ * hand tool. Hover and cursor then belong to the navigation.
46
+ */
47
+ isNavigating: () => boolean;
48
+ /** applies the pointer move still waiting for its frame, if any */
49
+ flushMove: () => void;
50
+ /** ends the active session, if any — pointerup may never arrive (the user
51
+ * tabs away, a new pointerdown lands first) */
52
+ end: () => void;
53
+ /**
54
+ * Whether a `contextmenu` event belongs to a secondary-button session and
55
+ * must not open the menu: it came with the press (the session decides on
56
+ * release), or it follows a release that turned out to be a drag.
57
+ */
58
+ consumesContextMenuEvent: () => boolean;
59
+ /** starts a session for the pointerdown if it qualifies; returns whether
60
+ * it did */
61
+ start: (event: React.PointerEvent<HTMLElement> | MouseEvent) => boolean;
62
+ }
@@ -0,0 +1,265 @@
1
+ import { LinearElementEditor } from "@excalidraw/element";
2
+ import type { ExcalidrawElement, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
3
+ import type { Mutable } from "@excalidraw/common/utility-types";
4
+ import type { CaptureUpdateActionType } from "@excalidraw/element";
5
+ import type { AppClassProperties, AppState, InteractiveCanvasAppState } from "../types";
6
+ import type App from "./App";
7
+ export declare const selectGroupsForSelectedElements: {
8
+ (appState: Pick<AppState, "selectedElementIds" | "editingGroupId">, elements: readonly NonDeletedExcalidrawElement[], prevAppState: InteractiveCanvasAppState, app: AppClassProperties | null): Mutable<Pick<InteractiveCanvasAppState, "selectedGroupIds" | "editingGroupId" | "selectedElementIds">>;
9
+ clearCache(): void;
10
+ };
11
+ /**
12
+ * The selection of the given elements alone, with their groups (within the
13
+ * edited group): a frame wins over its children, bound text is left to its
14
+ * container, and a lone line or arrow gets its line editor.
15
+ *
16
+ * @param allElements the (non-deleted) elements the selection is in
17
+ * @param deep select the elements themselves rather than their groups,
18
+ * editing their innermost group if they share it (and no group otherwise)
19
+ * — as Ctrl+click does
20
+ */
21
+ export declare const getSelectionStateForElements: (targetElements: readonly NonDeletedExcalidrawElement[], allElements: readonly NonDeletedExcalidrawElement[], appState: AppState, deep?: boolean) => Mutable<Pick<Readonly<{
22
+ zoom: AppState["zoom"];
23
+ scrollX: AppState["scrollX"];
24
+ scrollY: AppState["scrollY"];
25
+ width: AppState["width"];
26
+ height: AppState["height"];
27
+ viewModeEnabled: AppState["viewModeEnabled"];
28
+ openDialog: AppState["openDialog"];
29
+ editingGroupId: AppState["editingGroupId"];
30
+ selectedElementIds: AppState["selectedElementIds"];
31
+ frameToHighlight: AppState["frameToHighlight"];
32
+ offsetLeft: AppState["offsetLeft"];
33
+ offsetTop: AppState["offsetTop"];
34
+ theme: AppState["theme"];
35
+ } & {
36
+ activeTool: AppState["activeTool"];
37
+ activeEmbeddable: AppState["activeEmbeddable"];
38
+ selectionElement: AppState["selectionElement"];
39
+ selectedGroupIds: AppState["selectedGroupIds"];
40
+ selectedLinearElement: AppState["selectedLinearElement"];
41
+ multiElement: AppState["multiElement"];
42
+ newElement: AppState["newElement"];
43
+ isBindingEnabled: AppState["isBindingEnabled"];
44
+ isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
45
+ gridModeEnabled: AppState["gridModeEnabled"];
46
+ suggestedBinding: AppState["suggestedBinding"];
47
+ textToolHover: AppState["textToolHover"];
48
+ isRotating: AppState["isRotating"];
49
+ elementsToHighlight: AppState["elementsToHighlight"];
50
+ collaborators: AppState["collaborators"];
51
+ snapLines: AppState["snapLines"];
52
+ zenModeEnabled: AppState["zenModeEnabled"];
53
+ editingTextElement: AppState["editingTextElement"];
54
+ isCropping: AppState["isCropping"];
55
+ croppingElementId: AppState["croppingElementId"];
56
+ searchMatches: AppState["searchMatches"];
57
+ activeLockedId: AppState["activeLockedId"];
58
+ hoveredElementIds: AppState["hoveredElementIds"];
59
+ frameRendering: AppState["frameRendering"];
60
+ shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
61
+ exportScale: AppState["exportScale"];
62
+ currentItemArrowType: AppState["currentItemArrowType"];
63
+ }>, "selectedElementIds" | "editingGroupId" | "selectedGroupIds">> & {
64
+ selectedLinearElement: LinearElementEditor | null;
65
+ };
66
+ /**
67
+ * The selection with the given elements added, with their groups (within the
68
+ * edited group) — and the line editor of a lone selected line or arrow.
69
+ *
70
+ * A frame and its children aren't selected at the same time: an added frame
71
+ * deselects its children, an added child of a selected (or added) frame is
72
+ * left out, and adding elements grouped with frames deselects those frames'
73
+ * children (and leaves the added ones out). In the element link selector, the
74
+ * added elements replace the selection (unless one's group is selected).
75
+ *
76
+ * @param allElements the (non-deleted) elements the selection is in
77
+ */
78
+ export declare const getSelectionStateAddingElements: (targetElements: readonly NonDeletedExcalidrawElement[], allElements: readonly NonDeletedExcalidrawElement[], appState: AppState) => Mutable<Pick<Readonly<{
79
+ zoom: AppState["zoom"];
80
+ scrollX: AppState["scrollX"];
81
+ scrollY: AppState["scrollY"];
82
+ width: AppState["width"];
83
+ height: AppState["height"];
84
+ viewModeEnabled: AppState["viewModeEnabled"];
85
+ openDialog: AppState["openDialog"];
86
+ editingGroupId: AppState["editingGroupId"];
87
+ selectedElementIds: AppState["selectedElementIds"];
88
+ frameToHighlight: AppState["frameToHighlight"];
89
+ offsetLeft: AppState["offsetLeft"];
90
+ offsetTop: AppState["offsetTop"];
91
+ theme: AppState["theme"];
92
+ } & {
93
+ activeTool: AppState["activeTool"];
94
+ activeEmbeddable: AppState["activeEmbeddable"];
95
+ selectionElement: AppState["selectionElement"];
96
+ selectedGroupIds: AppState["selectedGroupIds"];
97
+ selectedLinearElement: AppState["selectedLinearElement"];
98
+ multiElement: AppState["multiElement"];
99
+ newElement: AppState["newElement"];
100
+ isBindingEnabled: AppState["isBindingEnabled"];
101
+ isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
102
+ gridModeEnabled: AppState["gridModeEnabled"];
103
+ suggestedBinding: AppState["suggestedBinding"];
104
+ textToolHover: AppState["textToolHover"];
105
+ isRotating: AppState["isRotating"];
106
+ elementsToHighlight: AppState["elementsToHighlight"];
107
+ collaborators: AppState["collaborators"];
108
+ snapLines: AppState["snapLines"];
109
+ zenModeEnabled: AppState["zenModeEnabled"];
110
+ editingTextElement: AppState["editingTextElement"];
111
+ isCropping: AppState["isCropping"];
112
+ croppingElementId: AppState["croppingElementId"];
113
+ searchMatches: AppState["searchMatches"];
114
+ activeLockedId: AppState["activeLockedId"];
115
+ hoveredElementIds: AppState["hoveredElementIds"];
116
+ frameRendering: AppState["frameRendering"];
117
+ shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
118
+ exportScale: AppState["exportScale"];
119
+ currentItemArrowType: AppState["currentItemArrowType"];
120
+ }>, "selectedElementIds" | "editingGroupId" | "selectedGroupIds">> & {
121
+ selectedLinearElement: LinearElementEditor | null;
122
+ };
123
+ /**
124
+ * The selection with the given elements removed — with the group they're
125
+ * selected via (if any) — and a lone remaining line or arrow getting its
126
+ * line editor.
127
+ *
128
+ * @param allElements the (non-deleted) elements the selection is in
129
+ */
130
+ export declare const getSelectionStateRemovingElements: (targetElements: readonly NonDeletedExcalidrawElement[], allElements: readonly NonDeletedExcalidrawElement[], appState: AppState) => Mutable<Pick<Readonly<{
131
+ zoom: AppState["zoom"];
132
+ scrollX: AppState["scrollX"];
133
+ scrollY: AppState["scrollY"];
134
+ width: AppState["width"];
135
+ height: AppState["height"];
136
+ viewModeEnabled: AppState["viewModeEnabled"];
137
+ openDialog: AppState["openDialog"];
138
+ editingGroupId: AppState["editingGroupId"];
139
+ selectedElementIds: AppState["selectedElementIds"];
140
+ frameToHighlight: AppState["frameToHighlight"];
141
+ offsetLeft: AppState["offsetLeft"];
142
+ offsetTop: AppState["offsetTop"];
143
+ theme: AppState["theme"];
144
+ } & {
145
+ activeTool: AppState["activeTool"];
146
+ activeEmbeddable: AppState["activeEmbeddable"];
147
+ selectionElement: AppState["selectionElement"];
148
+ selectedGroupIds: AppState["selectedGroupIds"];
149
+ selectedLinearElement: AppState["selectedLinearElement"];
150
+ multiElement: AppState["multiElement"];
151
+ newElement: AppState["newElement"];
152
+ isBindingEnabled: AppState["isBindingEnabled"];
153
+ isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
154
+ gridModeEnabled: AppState["gridModeEnabled"];
155
+ suggestedBinding: AppState["suggestedBinding"];
156
+ textToolHover: AppState["textToolHover"];
157
+ isRotating: AppState["isRotating"];
158
+ elementsToHighlight: AppState["elementsToHighlight"];
159
+ collaborators: AppState["collaborators"];
160
+ snapLines: AppState["snapLines"];
161
+ zenModeEnabled: AppState["zenModeEnabled"];
162
+ editingTextElement: AppState["editingTextElement"];
163
+ isCropping: AppState["isCropping"];
164
+ croppingElementId: AppState["croppingElementId"];
165
+ searchMatches: AppState["searchMatches"];
166
+ activeLockedId: AppState["activeLockedId"];
167
+ hoveredElementIds: AppState["hoveredElementIds"];
168
+ frameRendering: AppState["frameRendering"];
169
+ shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
170
+ exportScale: AppState["exportScale"];
171
+ currentItemArrowType: AppState["currentItemArrowType"];
172
+ }>, "selectedElementIds" | "editingGroupId" | "selectedGroupIds">> & {
173
+ selectedLinearElement: LinearElementEditor | null;
174
+ };
175
+ /** elements, or their ids — one or many */
176
+ export type ElementsOrIds = ExcalidrawElement | ExcalidrawElement["id"] | readonly (ExcalidrawElement | ExcalidrawElement["id"])[];
177
+ type SelectionChangeOptions = {
178
+ /**
179
+ * how the change is recorded for undo (see `updateScene()`) — by default,
180
+ * along with the next undoable change
181
+ */
182
+ captureUpdate?: CaptureUpdateActionType;
183
+ };
184
+ type AddOptions = SelectionChangeOptions & {
185
+ /**
186
+ * select locked elements too — e.g. for the context menu to offer unlocking
187
+ * them
188
+ */
189
+ includeLocked?: boolean;
190
+ };
191
+ type SelectOptions = AddOptions & {
192
+ /**
193
+ * select the elements themselves rather than their groups, editing their
194
+ * innermost group (if they share it) — as Ctrl+click does
195
+ */
196
+ deep?: boolean;
197
+ };
198
+ /**
199
+ * The selection: selecting elements, adding them to or removing them from
200
+ * the selection, and clearing it — keeping its rules: an element is selected
201
+ * with its group (but within the edited group), a frame and its children
202
+ * aren't selected at the same time, locked elements aren't selected, and a
203
+ * lone line or arrow gets its line editor (see the `getSelectionState*()`
204
+ * functions above).
205
+ *
206
+ * What hangs on the selection follows it: the link popup shows for a lone
207
+ * selected element with a link (or an embeddable), an embed stays active only
208
+ * while selected, cropping ends (unless the cropped image is selected again),
209
+ * and selecting (or adding) anything but the edited text ends text editing,
210
+ * submitting the text. The line editor ends once its line is deselected (see
211
+ * `componentDidUpdate()`).
212
+ *
213
+ * Elements are taken by id from the scene: missing and deleted ones are
214
+ * skipped.
215
+ */
216
+ export declare class AppSelection {
217
+ private app;
218
+ constructor(app: App);
219
+ /**
220
+ * Selects the elements alone (with their groups, unless `deep`).
221
+ */
222
+ select: (elementsOrIds: ElementsOrIds, opts?: SelectOptions) => void;
223
+ /**
224
+ * Adds the elements (with their groups) to the selection.
225
+ */
226
+ add: (elementsOrIds: ElementsOrIds, opts?: AddOptions) => void;
227
+ /**
228
+ * Removes the elements from the selection — with the group they're
229
+ * selected via.
230
+ */
231
+ remove: (elementsOrIds: ElementsOrIds, opts?: SelectionChangeOptions) => void;
232
+ /**
233
+ * Clears the selection, leaving the edited group and ending cropping.
234
+ *
235
+ * (Doesn't end text editing: starting it clears the selection.)
236
+ */
237
+ clear: (opts?: SelectionChangeOptions) => void;
238
+ /**
239
+ * Ends what changing the selection ends — cropping (unless
240
+ * `keepsCroppedImage`), and text editing (unless selecting the edited text,
241
+ * or its container) — and records the change for undo as asked.
242
+ *
243
+ * @param elements the elements being selected (or added) — none for a
244
+ * change that leaves text editing be
245
+ */
246
+ private beforeChange;
247
+ /**
248
+ * The next selection state with what follows it: the link popup — shown for
249
+ * a lone selected element with a link (or an embeddable), the link editor
250
+ * staying open if it's the same element, and hidden otherwise — and the
251
+ * active embed, which stays active only while selected.
252
+ */
253
+ private withFollowingState;
254
+ isASelectedElement(hitElement: ExcalidrawElement | null): boolean;
255
+ isHittingCommonBoundingBoxOfSelectedElements(point: Readonly<{
256
+ x: number;
257
+ y: number;
258
+ }>, selectedElements: readonly ExcalidrawElement[]): boolean;
259
+ /**
260
+ * The scene's (non-deleted) elements, by id, once each — but locked ones,
261
+ * unless `includeLocked`
262
+ */
263
+ private resolve;
264
+ }
265
+ export {};
@@ -0,0 +1,94 @@
1
+ import type { TransformHandleType } from "@excalidraw/element";
2
+ import type { ExcalidrawElement, ExcalidrawImageElement, NonDeleted, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap, PointerType } from "@excalidraw/element/types";
3
+ import type React from "react";
4
+ import type { PointerDownState } from "../types";
5
+ import type App from "./App";
6
+ /**
7
+ * The selection tool's (and the lasso's) selection: what a pointer down
8
+ * selects, what a click (a pointer up without a drag) does to the selection —
9
+ * including alt-click cycling through the overlapping elements — and the
10
+ * selection's transform handles (resizing, rotating, cropping).
11
+ */
12
+ export declare class AppSelectionTool {
13
+ private app;
14
+ constructor(app: App);
15
+ clearSelectionIfNotUsingSelection: () => void;
16
+ /**
17
+ * @returns whether the pointer event has been completely handled
18
+ */
19
+ handleSelectionOnPointerDown: (event: React.PointerEvent<HTMLElement>, pointerDownState: PointerDownState) => boolean;
20
+ maybeHandleCrop: (pointerDownState: PointerDownState, event: MouseEvent | KeyboardEvent) => boolean;
21
+ /**
22
+ * In the crop editor, a double-click on a handle uncrops its side (a
23
+ * corner's two), and mirrored, the opposite side(s) too.
24
+ *
25
+ * @returns whether the double-click has been handled
26
+ */
27
+ maybeUncropSides: (image: NonDeleted<ExcalidrawImageElement>, sceneX: number, sceneY: number, mirrored: boolean) => boolean;
28
+ maybeHandleResize: (pointerDownState: PointerDownState, event: MouseEvent | KeyboardEvent) => boolean;
29
+ /**
30
+ * Drags the selection (or, in the crop editor, the image within its crop) —
31
+ * duplicating it on an alt-drag past the drag threshold.
32
+ *
33
+ * @returns whether the pointer event has been completely handled
34
+ */
35
+ handleSelectionDragOnPointerMove: (event: PointerEvent, pointerDownState: PointerDownState, pointerCoords: {
36
+ x: number;
37
+ y: number;
38
+ }, elementsMap: NonDeletedSceneElementsMap) => boolean;
39
+ /**
40
+ * Box-selects with the selection tool — the line editor's points, while
41
+ * editing a line.
42
+ */
43
+ handleBoxSelectionOnPointerMove: (event: PointerEvent, pointerDownState: PointerDownState) => void;
44
+ /**
45
+ * After dragging the selection: the dragged elements join the frame they're
46
+ * dropped in, or leave theirs (and the edited group, if they leave it).
47
+ */
48
+ handleSelectionDragOnPointerUp: (childEvent: PointerEvent) => void;
49
+ /**
50
+ * The selection's transform handle at the scene point, if any — with its
51
+ * element, for a lone selected element.
52
+ *
53
+ * A lone selected element has none while the line editor is open or one of
54
+ * its line points is hovered, nor does an elbow arrow, a two-point line or
55
+ * arrow, (on mobile devices) any line or arrow, or the text being edited
56
+ * (none are drawn for it; see `AppText.getEditedTextResizeHandleAt()` for
57
+ * its sides). The selection has none in the element link selector.
58
+ */
59
+ getTransformHandleAt(selectedElements: readonly NonDeletedExcalidrawElement[], sceneX: number, sceneY: number, pointerType: PointerType): {
60
+ element?: NonDeletedExcalidrawElement;
61
+ transformHandleType: TransformHandleType;
62
+ } | null;
63
+ /**
64
+ * Updates the selection on a click (no drag): the element below the
65
+ * selected one on an alt-click, the clicked element added to or removed
66
+ * from the selection with shift, or selected, and the selection cleared
67
+ * by a click hitting only a bounding box.
68
+ *
69
+ * @returns whether the pointer event has been completely handled
70
+ */
71
+ handleSelectionOnPointerUp: (childEvent: PointerEvent, pointerDownState: PointerDownState, elementsMap: NonDeletedSceneElementsMap) => boolean;
72
+ clearSelection(hitElement: ExcalidrawElement | null): void;
73
+ /** whether an alt-click on the selection (over other elements) cycles it */
74
+ canCycleSelection: () => boolean;
75
+ /**
76
+ * The selectable unit (an element, or the group a click would select) an
77
+ * element belongs to. Inside an edited group, its elements are units of
78
+ * their own.
79
+ */
80
+ private getSelectableUnit;
81
+ /**
82
+ * The selected unit, if an alt-click can cycle away from it: exactly one
83
+ * is selected, and neither the linear nor the crop editor is open.
84
+ */
85
+ private getCyclableSelectedUnit;
86
+ /**
87
+ * The element an alt-click selects: the selectable unit below the selected
88
+ * one among the hit elements, wrapping around to the topmost — or `null`
89
+ * unless it's an alt-click, the selection can cycle, and it's under the
90
+ * pointer. Inside an edited group, it cycles through the group's elements
91
+ * only, never leaving the group.
92
+ */
93
+ private getSelectionCycleTarget;
94
+ }