@excalidraw/math 0.18.0-1118751 → 0.18.0-1440f2d

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 (127) hide show
  1. package/dist/types/common/src/constants.d.ts +4 -0
  2. package/dist/types/common/src/utils.d.ts +12 -1
  3. package/dist/types/element/src/align.d.ts +4 -1
  4. package/dist/types/element/src/binding.d.ts +70 -0
  5. package/dist/types/element/src/bounds.d.ts +10 -2
  6. package/dist/types/element/src/collision.d.ts +13 -0
  7. package/dist/types/element/src/cropElement.d.ts +36 -4
  8. package/dist/types/element/src/delta.d.ts +7 -1
  9. package/dist/types/element/src/distribute.d.ts +4 -1
  10. package/dist/types/element/src/dragElements.d.ts +8 -3
  11. package/dist/types/element/src/elbowArrow.d.ts +5 -0
  12. package/dist/types/element/src/embeddable.d.ts +2 -1
  13. package/dist/types/element/src/flowchart.d.ts +1 -7
  14. package/dist/types/element/src/frame.d.ts +19 -1
  15. package/dist/types/element/src/groups.d.ts +1 -6
  16. package/dist/types/element/src/image.d.ts +5 -2
  17. package/dist/types/element/src/index.d.ts +2 -0
  18. package/dist/types/element/src/linearElementEditor.d.ts +4 -1
  19. package/dist/types/element/src/listMarker.d.ts +39 -0
  20. package/dist/types/element/src/newElement.d.ts +17 -1
  21. package/dist/types/element/src/renderElement.d.ts +10 -0
  22. package/dist/types/element/src/renderEnvironment.d.ts +66 -0
  23. package/dist/types/element/src/resizeElements.d.ts +15 -5
  24. package/dist/types/element/src/selection.d.ts +1 -7
  25. package/dist/types/element/src/shape.d.ts +2 -0
  26. package/dist/types/element/src/stickyNote.d.ts +8 -0
  27. package/dist/types/element/src/textElement.d.ts +10 -2
  28. package/dist/types/element/src/textMeasurements.d.ts +15 -11
  29. package/dist/types/element/src/textWrapping.d.ts +3 -2
  30. package/dist/types/element/src/transform.d.ts +5 -1
  31. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +30 -3
  32. package/dist/types/excalidraw/actions/actionBoundText.d.ts +56 -214
  33. package/dist/types/excalidraw/actions/actionCanvas.d.ts +76 -16
  34. package/dist/types/excalidraw/actions/actionClipboard.d.ts +20 -2
  35. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +10 -1
  36. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +4 -564
  37. package/dist/types/excalidraw/actions/actionDeselect.d.ts +14 -2
  38. package/dist/types/excalidraw/actions/actionElementLink.d.ts +10 -1
  39. package/dist/types/excalidraw/actions/actionElementLock.d.ts +20 -2
  40. package/dist/types/excalidraw/actions/actionExport.d.ts +27 -9
  41. package/dist/types/excalidraw/actions/actionFrame.d.ts +71 -528
  42. package/dist/types/excalidraw/actions/actionGroup.d.ts +22 -4
  43. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +10 -1
  44. package/dist/types/excalidraw/actions/actionLink.d.ts +10 -1
  45. package/dist/types/excalidraw/actions/actionMenu.d.ts +10 -1
  46. package/dist/types/excalidraw/actions/actionProperties.d.ts +20 -2
  47. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +11 -2
  48. package/dist/types/excalidraw/actions/actionStyles.d.ts +10 -1
  49. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +10 -1
  50. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +10 -1
  51. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +10 -1
  52. package/dist/types/excalidraw/actions/actionToggleMinimap.d.ts +201 -0
  53. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +10 -1
  54. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +10 -1
  55. package/dist/types/excalidraw/actions/actionToggleShowHints.d.ts +198 -0
  56. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +10 -1
  57. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +10 -1
  58. package/dist/types/excalidraw/actions/actionToggleWrap.d.ts +12 -0
  59. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +10 -1
  60. package/dist/types/excalidraw/actions/index.d.ts +3 -0
  61. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  62. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  63. package/dist/types/excalidraw/appState.d.ts +9 -7
  64. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -1
  65. package/dist/types/excalidraw/charts/charts.helpers.d.ts +6 -5
  66. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -1
  67. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -1
  68. package/dist/types/excalidraw/charts/index.d.ts +2 -1
  69. package/dist/types/excalidraw/components/Actions.d.ts +9 -2
  70. package/dist/types/excalidraw/components/App.arrowText.d.ts +5 -39
  71. package/dist/types/excalidraw/components/App.clipboard.d.ts +31 -0
  72. package/dist/types/excalidraw/components/App.d.ts +79 -264
  73. package/dist/types/excalidraw/components/App.duplicate.d.ts +52 -2
  74. package/dist/types/excalidraw/components/App.host.d.ts +102 -0
  75. package/dist/types/excalidraw/components/App.modifiers.d.ts +38 -0
  76. package/dist/types/excalidraw/components/App.pan.d.ts +8 -0
  77. package/dist/types/excalidraw/components/App.selection.d.ts +265 -0
  78. package/dist/types/excalidraw/components/App.selectionTool.d.ts +93 -0
  79. package/dist/types/excalidraw/components/App.text.d.ts +146 -0
  80. package/dist/types/excalidraw/components/App.textTool.d.ts +140 -0
  81. package/dist/types/excalidraw/components/App.viewport.d.ts +64 -4
  82. package/dist/types/excalidraw/components/App.wheel.d.ts +6 -2
  83. package/dist/types/excalidraw/components/App.wrap.d.ts +31 -0
  84. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -1
  85. package/dist/types/excalidraw/components/FileDropOverlay.d.ts +2 -0
  86. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +6 -2
  87. package/dist/types/excalidraw/components/LibraryUnit.d.ts +7 -2
  88. package/dist/types/excalidraw/components/Minimap/Minimap.d.ts +15 -0
  89. package/dist/types/excalidraw/components/Minimap/MinimapAnnouncementDot.d.ts +10 -0
  90. package/dist/types/excalidraw/components/Minimap/minimap-controller.chunk.d.ts +90 -0
  91. package/dist/types/excalidraw/components/Minimap/minimap-shared.chunk.d.ts +122 -0
  92. package/dist/types/excalidraw/components/Minimap/minimap-worker.chunk.d.ts +12 -0
  93. package/dist/types/excalidraw/components/Stats/utils.d.ts +4 -2
  94. package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +2 -1
  95. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
  96. package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +5 -2
  97. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
  98. package/dist/types/excalidraw/components/TTDDialog/common.d.ts +4 -1
  99. package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +3 -2
  100. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +14 -1
  101. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +16 -0
  102. package/dist/types/excalidraw/components/Tooltip.d.ts +26 -2
  103. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +1 -1
  104. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +0 -1
  105. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  106. package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +3 -2
  107. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +13 -2
  108. package/dist/types/excalidraw/components/icons.d.ts +1 -0
  109. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -0
  110. package/dist/types/excalidraw/data/blob.d.ts +34 -16
  111. package/dist/types/excalidraw/data/index.d.ts +3 -3
  112. package/dist/types/excalidraw/data/json.d.ts +17 -8
  113. package/dist/types/excalidraw/fonts/Fonts.d.ts +9 -6
  114. package/dist/types/excalidraw/history.d.ts +10 -4
  115. package/dist/types/excalidraw/mermaid.d.ts +7 -0
  116. package/dist/types/excalidraw/reactUtils.d.ts +1 -1
  117. package/dist/types/excalidraw/renderer/animation.d.ts +11 -4
  118. package/dist/types/excalidraw/renderer/staticScene.d.ts +11 -6
  119. package/dist/types/excalidraw/scene/Renderer.d.ts +1 -1
  120. package/dist/types/excalidraw/scene/export.d.ts +343 -20
  121. package/dist/types/excalidraw/scene/types.d.ts +23 -1
  122. package/dist/types/excalidraw/types.d.ts +83 -14
  123. package/dist/types/excalidraw/viewport.d.ts +23 -1
  124. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +12 -1
  125. package/dist/types/utils/src/index.d.ts +3 -1
  126. package/package.json +2 -2
  127. package/dist/types/utils/src/export.d.ts +0 -36
@@ -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
+ }
@@ -33,10 +33,18 @@ export declare class AppPan {
33
33
  constructor(app: App, dependencies: {
34
34
  /** pointers currently down (a two-finger gesture is not a pan) */
35
35
  getPointerCount: () => number;
36
+ /** a scrollbar being dragged (App's own drag, not a pan session) */
37
+ isDraggingScrollBar: () => boolean;
36
38
  });
37
39
  isActive: () => boolean;
38
40
  isSpaceHeld: () => boolean;
39
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;
40
48
  /** applies the pointer move still waiting for its frame, if any */
41
49
  flushMove: () => void;
42
50
  /** ends the active session, if any — pointerup may never arrive (the user
@@ -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,93 @@
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, or (on mobile devices) any line or arrow. The selection has none in
56
+ * the element link selector.
57
+ */
58
+ getTransformHandleAt(selectedElements: readonly NonDeletedExcalidrawElement[], sceneX: number, sceneY: number, pointerType: PointerType): {
59
+ element?: NonDeletedExcalidrawElement;
60
+ transformHandleType: TransformHandleType;
61
+ } | null;
62
+ /**
63
+ * Updates the selection on a click (no drag): the element below the
64
+ * selected one on an alt-click, the clicked element added to or removed
65
+ * from the selection with shift, or selected, and the selection cleared
66
+ * by a click hitting only a bounding box.
67
+ *
68
+ * @returns whether the pointer event has been completely handled
69
+ */
70
+ handleSelectionOnPointerUp: (childEvent: PointerEvent, pointerDownState: PointerDownState, elementsMap: NonDeletedSceneElementsMap) => boolean;
71
+ clearSelection(hitElement: ExcalidrawElement | null): void;
72
+ /** whether an alt-click on the selection (over other elements) cycles it */
73
+ canCycleSelection: () => boolean;
74
+ /**
75
+ * The selectable unit (an element, or the group a click would select) an
76
+ * element belongs to. Inside an edited group, its elements are units of
77
+ * their own.
78
+ */
79
+ private getSelectableUnit;
80
+ /**
81
+ * The selected unit, if an alt-click can cycle away from it: exactly one
82
+ * is selected, and neither the linear nor the crop editor is open.
83
+ */
84
+ private getCyclableSelectedUnit;
85
+ /**
86
+ * The element an alt-click selects: the selectable unit below the selected
87
+ * one among the hit elements, wrapping around to the topmost — or `null`
88
+ * unless it's an alt-click, the selection can cycle, and it's under the
89
+ * pointer. Inside an edited group, it cycles through the group's elements
90
+ * only, never leaving the group.
91
+ */
92
+ private getSelectionCycleTarget;
93
+ }
@@ -0,0 +1,146 @@
1
+ import { type Bounds, type StylesPanelMode } from "@excalidraw/common";
2
+ import type { ArrowEndpoint } from "@excalidraw/element";
3
+ import type { ExcalidrawElement, ExcalidrawTextContainer, ExcalidrawTextElement, NonDeleted, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
4
+ import { textWysiwyg } from "../wysiwyg/textWysiwyg";
5
+ import type App from "./App";
6
+ import type { AppState, Offsets, ViewportUIName } from "../types";
7
+ type AppTextDependencies = {
8
+ getContainer: () => HTMLDivElement | null;
9
+ getStylesPanelMode: () => StylesPanelMode;
10
+ };
11
+ /**
12
+ * Texts, but for the text tool's pointer interaction (`AppTextTool`):
13
+ *
14
+ * - the editing session: what text to edit, or create, and where
15
+ * (`startTextEditing`), and the editor's lifecycle (`handleTextWysiwyg`)
16
+ * - the part of the canvas a typed or pasted text is kept within
17
+ * (`getTextViewportOffsets`, `getMaxTextWidth`)
18
+ * - the queries that find the text or container to edit at a position
19
+ * - the handle that turns a fixed-width text back into a growing one
20
+ *
21
+ * Every way into editing ends up here: Enter, double-click, pointerup on a
22
+ * selected text or container, the text tool, a drag-created text or sticky
23
+ * note, and a sticky note dropped from the toolbar.
24
+ */
25
+ export declare class AppText {
26
+ private app;
27
+ private dependencies;
28
+ constructor(app: App, dependencies: AppTextDependencies);
29
+ textWysiwygSubmitHandler: ReturnType<typeof textWysiwyg> | null;
30
+ private getTextCreationGridPoint;
31
+ /**
32
+ * The side panels, besides the sidebar, that a typed or pasted text is
33
+ * kept clear of: the stats panel, and the full styles panel (desktop),
34
+ * which shows next to a text while it's edited, and once it's pasted and
35
+ * selected.
36
+ */
37
+ getTextSidePanels: () => ViewportUIName[];
38
+ /**
39
+ * The part of the canvas a typed or pasted text is kept within, as offsets
40
+ * from its edges (screen px): all of it but the sidebar and the side
41
+ * panels (see getTextSidePanels), less some room at each side. The stats
42
+ * panel covers the top of a side only, and counts only for a text beside
43
+ * it: one (given by its scene bounds) with rows within that room of it.
44
+ */
45
+ getTextViewportOffsets: (textBounds?: Bounds) => Required<Offsets>;
46
+ /**
47
+ * The widest a text may grow to as it's typed or pasted, in scene units:
48
+ * TEXT_MAX_WRAP_WIDTH, or less, so that a text never outgrows the part of
49
+ * the canvas it's kept within.
50
+ */
51
+ getMaxTextWidth: (offsets: Required<Offsets>) => number;
52
+ handleTextWysiwyg(element: NonDeleted<ExcalidrawTextElement>, { isExistingElement, initialCaretSceneCoords, initialSelection, }: {
53
+ isExistingElement?: boolean;
54
+ /**
55
+ * supply null if no caret positioning is desired, and instead
56
+ * text should be auto-selected
57
+ */
58
+ initialCaretSceneCoords?: {
59
+ x: number;
60
+ y: number;
61
+ } | null;
62
+ /** range of the text to select (takes precedence over the caret) */
63
+ initialSelection?: {
64
+ start: number;
65
+ end: number;
66
+ } | null;
67
+ }): void;
68
+ private getSelectedTextElement;
69
+ getSelectedTextEditingContainerAtPosition(hitElement: NonDeletedExcalidrawElement | null, sceneCoords: {
70
+ x: number;
71
+ y: number;
72
+ }): ExcalidrawTextContainer | null | undefined;
73
+ getTextElementAtPosition(x: number, y: number): NonDeleted<ExcalidrawTextElement> | null;
74
+ isHittingTextAutoResizeHandle: (selectedElements: NonDeleted<ExcalidrawElement>[], point: Readonly<{
75
+ x: number;
76
+ y: number;
77
+ }>) => boolean;
78
+ handleTextAutoResizeHandlePointerDown: (selectedElements: NonDeleted<ExcalidrawElement>[], point: Readonly<{
79
+ x: number;
80
+ y: number;
81
+ }>) => boolean;
82
+ /**
83
+ * The text container at a position — an arrow hit on its path, any other
84
+ * container hit anywhere in its bounds (frames are skipped so a container
85
+ * inside one can be hit, and a frame's children are only hit inside it,
86
+ * where they are drawn). Purely positional: the selection plays no part.
87
+ *
88
+ * Only what hides the rest ends the search — a filled element or an image
89
+ * (as for arrow binding), or an arrow — so containers below a transparent
90
+ * one stay in reach whatever their z-order. Of the containers found, the
91
+ * innermost one centered on the position wins, since that is where its
92
+ * label would go (an arrow counting as innermost: it is pointed at, not just
93
+ * enclosing); failing that, the top-most.
94
+ */
95
+ getTextBindableContainerAtPosition(x: number, y: number): NonDeleted<ExcalidrawTextContainer>;
96
+ /**
97
+ * Whether a text element's content is still being authored.
98
+ *
99
+ * Creating a text reverts the tool to selection during pointerdown, so the
100
+ * pointerup that follows looks like an ordinary canvas click and would
101
+ * capture the still-empty element as a history entry of its own. Undo would
102
+ * then rewind only the typing, restoring an invisible, zero-content element
103
+ * (and, for an endpoint label, leaving the arrow bound to it) rather than
104
+ * removing it. The editor's own submit captures the finished text instead,
105
+ * so the whole create-and-type lands in a single entry.
106
+ */
107
+ isEditingTextContent(): boolean;
108
+ startTextEditing: ({ sceneX, sceneY, insertAtParentCenter, container, autoEdit, initialCaretSceneCoords, initialSelection, arrowEndpoint, textElement, }: {
109
+ /** X position to insert text at */
110
+ sceneX: number;
111
+ /** Y position to insert text at */
112
+ sceneY: number;
113
+ /** whether to attempt to insert at element center if applicable */
114
+ insertAtParentCenter?: boolean;
115
+ container?: ExcalidrawTextContainer | null;
116
+ autoEdit?: boolean;
117
+ initialCaretSceneCoords?: {
118
+ x: number;
119
+ y: number;
120
+ };
121
+ /** range of an existing text to select (takes precedence over the caret) */
122
+ initialSelection?: {
123
+ start: number;
124
+ end: number;
125
+ };
126
+ /**
127
+ * creates the text as a label for this arrow endpoint: the binding then
128
+ * dictates the text's position and alignment, overriding (sceneX, sceneY)
129
+ */
130
+ arrowEndpoint?: ArrowEndpoint | null;
131
+ /**
132
+ * the text to edit: an element to edit exactly that one; `null` to always
133
+ * create, never adopting a selected text or one under the pointer;
134
+ * `undefined` to resolve it here — a single selected text, the label of a
135
+ * selected or passed arrow container, else the text at (sceneX, sceneY)
136
+ */
137
+ textElement?: NonDeleted<ExcalidrawTextElement> | null;
138
+ }) => void;
139
+ getTextWysiwygSnappedToCenterPosition(x: number, y: number, appState: AppState, container?: ExcalidrawTextContainer | null): {
140
+ viewportX: number;
141
+ viewportY: number;
142
+ elementCenterX: number;
143
+ elementCenterY: number;
144
+ } | undefined;
145
+ }
146
+ export {};