@dwelle/excalidraw 0.4.0-e3bee83 → 0.4.0-e587816

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 (220) hide show
  1. package/CHANGELOG.md +525 -0
  2. package/README.md +18 -1820
  3. package/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.js → vendor-d415b28e9024dee4bb1b.js} +2 -2
  4. package/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.js → vendor-a14cd58fa2db417e42b2.js} +6 -6
  5. package/dist/excalidraw.development.js +3071 -1566
  6. package/dist/excalidraw.production.min.js +1 -1
  7. package/dist/excalidraw.production.min.js.LICENSE.txt +20 -0
  8. package/main.js +1 -8
  9. package/package.json +9 -4
  10. package/types/actions/actionAddToLibrary.d.ts +103 -55
  11. package/types/actions/actionAlign.d.ts +33 -28
  12. package/types/actions/actionBoundText.d.ts +175 -22
  13. package/types/actions/actionCanvas.d.ts +680 -170
  14. package/types/actions/actionClipboard.d.ts +174 -100
  15. package/types/actions/actionDeleteSelected.d.ts +102 -60
  16. package/types/actions/actionDistribute.d.ts +11 -12
  17. package/types/actions/actionDuplicateSelection.d.ts +3 -4
  18. package/types/actions/actionElementLock.d.ts +271 -0
  19. package/types/actions/actionExport.d.ts +363 -221
  20. package/types/actions/actionFinalize.d.ts +70 -42
  21. package/types/actions/actionFlip.d.ts +8 -11
  22. package/types/actions/actionFrame.d.ts +423 -0
  23. package/types/actions/actionGroup.d.ts +250 -13
  24. package/types/actions/actionHistory.d.ts +1 -1
  25. package/types/actions/actionLinearEditor.d.ts +37 -21
  26. package/types/actions/actionMenu.d.ts +108 -62
  27. package/types/actions/actionNavigate.d.ts +1 -1
  28. package/types/actions/actionProperties.d.ts +465 -256
  29. package/types/actions/actionSelectAll.d.ts +123 -4
  30. package/types/actions/actionStyles.d.ts +39 -24
  31. package/types/actions/actionToggleGridMode.d.ts +37 -22
  32. package/types/actions/{actionToggleLock.d.ts → actionToggleObjectsSnapMode.d.ts} +49 -32
  33. package/types/actions/actionToggleStats.d.ts +37 -22
  34. package/types/actions/actionToggleViewMode.d.ts +37 -22
  35. package/types/actions/actionToggleZenMode.d.ts +37 -22
  36. package/types/actions/actionZindex.d.ts +12 -12
  37. package/types/actions/index.d.ts +2 -1
  38. package/types/actions/manager.d.ts +1 -1
  39. package/types/actions/shortcuts.d.ts +2 -1
  40. package/types/actions/types.d.ts +11 -9
  41. package/types/appState.d.ts +18 -18
  42. package/types/charts.d.ts +2 -2
  43. package/types/clients.d.ts +5 -6
  44. package/types/clipboard.d.ts +8 -7
  45. package/types/colors.d.ts +60 -5
  46. package/types/components/Actions.d.ts +7 -12
  47. package/types/components/ActiveConfirmDialog.d.ts +4 -0
  48. package/types/components/App.d.ts +93 -35
  49. package/types/components/Avatar.d.ts +1 -2
  50. package/types/components/BraveMeasureTextError.d.ts +2 -0
  51. package/types/components/Button.d.ts +3 -2
  52. package/types/components/ButtonIconSelect.d.ts +11 -3
  53. package/types/components/Card.d.ts +0 -1
  54. package/types/components/ColorPicker/ColorInput.d.ts +9 -0
  55. package/types/components/ColorPicker/ColorPicker.d.ts +19 -0
  56. package/types/components/ColorPicker/CustomColorList.d.ts +8 -0
  57. package/types/components/ColorPicker/HotkeyLabel.d.ts +8 -0
  58. package/types/components/ColorPicker/Picker.d.ts +18 -0
  59. package/types/components/ColorPicker/PickerColorList.d.ts +10 -0
  60. package/types/components/ColorPicker/PickerHeading.d.ts +5 -0
  61. package/types/components/ColorPicker/ShadeList.d.ts +8 -0
  62. package/types/components/ColorPicker/TopPicks.d.ts +9 -0
  63. package/types/components/ColorPicker/colorPickerUtils.d.ts +21 -0
  64. package/types/components/ColorPicker/keyboardNavHandlers.d.ts +20 -0
  65. package/types/components/ContextMenu.d.ts +3 -3
  66. package/types/components/DefaultSidebar.d.ts +29 -0
  67. package/types/components/Dialog.d.ts +3 -4
  68. package/types/components/ErrorDialog.d.ts +3 -2
  69. package/types/components/ExcalidrawLogo.d.ts +15 -0
  70. package/types/components/EyeDropper.d.ts +28 -0
  71. package/types/components/FilledButton.d.ts +17 -0
  72. package/types/components/FixedSideContainer.d.ts +1 -1
  73. package/types/components/HandButton.d.ts +10 -0
  74. package/types/components/HelpButton.d.ts +1 -2
  75. package/types/components/HintViewer.d.ts +4 -5
  76. package/types/components/HomeButton.d.ts +1 -1
  77. package/types/components/ImageExportDialog.d.ts +8 -13
  78. package/types/components/Island.d.ts +1 -1
  79. package/types/components/JSONExportDialog.d.ts +5 -5
  80. package/types/components/LaserTool/LaserPathManager.d.ts +28 -0
  81. package/types/components/LaserTool/LaserPointerButton.d.ts +10 -0
  82. package/types/components/LaserTool/LaserTool.d.ts +7 -0
  83. package/types/components/LayerUI.d.ts +9 -15
  84. package/types/components/LibraryMenu.d.ts +13 -14
  85. package/types/components/LibraryMenuBrowseButton.d.ts +2 -2
  86. package/types/components/LibraryMenuControlButtons.d.ts +9 -0
  87. package/types/components/LibraryMenuHeaderContent.d.ts +10 -28
  88. package/types/components/LibraryMenuItems.d.ts +6 -7
  89. package/types/components/LibraryMenuSection.d.ts +22 -0
  90. package/types/components/LibraryUnit.d.ts +6 -3
  91. package/types/components/LoadingMessage.d.ts +0 -1
  92. package/types/components/LockButton.d.ts +1 -2
  93. package/types/components/MobileMenu.d.ts +8 -11
  94. package/types/components/OverwriteConfirm/OverwriteConfirm.d.ts +17 -0
  95. package/types/components/OverwriteConfirm/OverwriteConfirmActions.d.ts +17 -0
  96. package/types/components/OverwriteConfirm/OverwriteConfirmState.d.ts +22 -0
  97. package/types/components/PasteChartDialog.d.ts +4 -5
  98. package/types/components/PenModeButton.d.ts +1 -1
  99. package/types/components/Popover.d.ts +1 -1
  100. package/types/components/ProjectName.d.ts +2 -1
  101. package/types/components/PublishLibrary.d.ts +2 -2
  102. package/types/components/RadioGroup.d.ts +12 -0
  103. package/types/components/Section.d.ts +1 -1
  104. package/types/components/Sidebar/Sidebar.d.ts +66 -63
  105. package/types/components/Sidebar/SidebarHeader.d.ts +6 -19
  106. package/types/components/Sidebar/SidebarTab.d.ts +8 -0
  107. package/types/components/Sidebar/SidebarTabTrigger.d.ts +9 -0
  108. package/types/components/Sidebar/SidebarTabTriggers.d.ts +6 -0
  109. package/types/components/Sidebar/SidebarTabs.d.ts +6 -0
  110. package/types/components/Sidebar/SidebarTrigger.d.ts +6 -0
  111. package/types/components/Sidebar/common.d.ts +24 -7
  112. package/types/components/Spinner.d.ts +2 -1
  113. package/types/components/Stack.d.ts +4 -3
  114. package/types/components/Stats.d.ts +3 -3
  115. package/types/components/Switch.d.ts +9 -0
  116. package/types/components/ToolButton.d.ts +6 -5
  117. package/types/components/Tooltip.d.ts +1 -1
  118. package/types/components/Trans.d.ts +9 -0
  119. package/types/components/canvases/InteractiveCanvas.d.ts +27 -0
  120. package/types/components/canvases/StaticCanvas.d.ts +18 -0
  121. package/types/components/canvases/index.d.ts +3 -0
  122. package/types/components/dropdownMenu/DropdownMenu.d.ts +15 -9
  123. package/types/components/dropdownMenu/DropdownMenuContent.d.ts +7 -3
  124. package/types/components/dropdownMenu/DropdownMenuItem.d.ts +4 -4
  125. package/types/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -1
  126. package/types/components/dropdownMenu/DropdownMenuItemLink.d.ts +4 -2
  127. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -2
  128. package/types/components/dropdownMenu/common.d.ts +6 -0
  129. package/types/components/footer/Footer.d.ts +4 -5
  130. package/types/components/hoc/withInternalFallback.d.ts +4 -0
  131. package/types/components/icons.d.ts +16 -1
  132. package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -1
  133. package/types/components/main-menu/MainMenu.d.ts +22 -13
  134. package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -1
  135. package/types/components/welcome-screen/WelcomeScreen.d.ts +2 -3
  136. package/types/constants.d.ts +94 -10
  137. package/types/context/tunnels.d.ts +19 -0
  138. package/types/context/ui-appState.d.ts +4 -0
  139. package/types/cursor.d.ts +5 -0
  140. package/types/data/blob.d.ts +5 -3
  141. package/types/data/encode.d.ts +1 -1
  142. package/types/data/filesystem.d.ts +2 -1
  143. package/types/data/library.d.ts +3 -45
  144. package/types/data/restore.d.ts +10 -4
  145. package/types/data/transform.d.ts +73 -0
  146. package/types/data/types.d.ts +3 -5
  147. package/types/data/url.d.ts +7 -0
  148. package/types/element/Hyperlink.d.ts +48 -29
  149. package/types/element/binding.d.ts +4 -3
  150. package/types/element/bounds.d.ts +40 -10
  151. package/types/element/collision.d.ts +7 -7
  152. package/types/element/dragElements.d.ts +12 -2
  153. package/types/element/embeddable.d.ts +153 -0
  154. package/types/element/image.d.ts +11 -1
  155. package/types/element/index.d.ts +3 -2
  156. package/types/element/linearElementEditor.d.ts +43 -27
  157. package/types/element/mutateElement.d.ts +3 -2
  158. package/types/element/newElement.d.ts +48 -15
  159. package/types/element/resizeElements.d.ts +3 -2
  160. package/types/element/resizeTest.d.ts +2 -1
  161. package/types/element/showSelectedShapeActions.d.ts +2 -2
  162. package/types/element/sizeHelpers.d.ts +8 -1
  163. package/types/element/sortElements.d.ts +2 -0
  164. package/types/element/textElement.d.ts +43 -17
  165. package/types/element/textWysiwyg.d.ts +1 -1
  166. package/types/element/transformHandles.d.ts +16 -8
  167. package/types/element/typeChecks.d.ts +5 -2
  168. package/types/element/types.d.ts +59 -35
  169. package/types/emitter.d.ts +1 -2
  170. package/types/errors.d.ts +1 -1
  171. package/types/frame.d.ts +46 -0
  172. package/types/ga.d.ts +5 -5
  173. package/types/groups.d.ts +15 -11
  174. package/types/history.d.ts +3 -3
  175. package/types/hooks/useCreatePortalContainer.d.ts +4 -0
  176. package/types/hooks/useLibraryItemSvg.d.ts +11 -0
  177. package/types/hooks/useOutsideClick.d.ts +19 -2
  178. package/types/hooks/useScrollPosition.d.ts +1 -0
  179. package/types/hooks/useStable.d.ts +1 -0
  180. package/types/hooks/useTransition.d.ts +2 -0
  181. package/types/i18n.d.ts +11 -2
  182. package/types/jotai.d.ts +20 -108
  183. package/types/keys.d.ts +5 -4
  184. package/types/math.d.ts +5 -0
  185. package/types/packages/bbox.d.ts +11 -0
  186. package/types/packages/excalidraw/example/App.d.ts +7 -1
  187. package/types/packages/excalidraw/example/initialData.d.ts +182 -64
  188. package/types/packages/excalidraw/index.d.ts +11 -4
  189. package/types/packages/excalidraw/main.d.ts +3 -1
  190. package/types/packages/excalidraw/webpack.dev.config.d.ts +5 -2
  191. package/types/packages/excalidraw/webpack.prod.config.d.ts +3 -0
  192. package/types/packages/utils.d.ts +11 -2
  193. package/types/packages/withinBounds.d.ts +19 -0
  194. package/types/renderer/renderElement.d.ts +12 -22
  195. package/types/renderer/renderScene.d.ts +19 -27
  196. package/types/renderer/renderSnaps.d.ts +2 -0
  197. package/types/renderer/roundRect.d.ts +1 -1
  198. package/types/scene/Renderer.d.ts +25 -0
  199. package/types/scene/Scene.d.ts +27 -5
  200. package/types/scene/Shape.d.ts +12 -0
  201. package/types/scene/ShapeCache.d.ts +20 -0
  202. package/types/scene/comparisons.d.ts +0 -1
  203. package/types/scene/export.d.ts +50 -11
  204. package/types/scene/index.d.ts +1 -1
  205. package/types/scene/scroll.d.ts +1 -1
  206. package/types/scene/scrollbars.d.ts +2 -6
  207. package/types/scene/selection.d.ts +27 -6
  208. package/types/scene/types.d.ts +70 -34
  209. package/types/snapping.d.ts +108 -0
  210. package/types/types.d.ts +200 -84
  211. package/types/utility-types.d.ts +24 -0
  212. package/types/utils.d.ts +73 -29
  213. package/types/zindex.d.ts +4 -4
  214. package/types/components/ColorPicker.d.ts +0 -14
  215. package/types/components/LibraryButton.d.ts +0 -8
  216. package/types/components/SingleLibraryItem.d.ts +0 -10
  217. package/types/components/hoc/withUpstreamOverride.d.ts +0 -10
  218. /package/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.js.LICENSE.txt → vendor-d415b28e9024dee4bb1b.js.LICENSE.txt} +0 -0
  219. /package/types/packages/excalidraw/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.d.ts → vendor-d415b28e9024dee4bb1b.d.ts} +0 -0
  220. /package/types/packages/excalidraw/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.d.ts → vendor-a14cd58fa2db417e42b2.d.ts} +0 -0
@@ -0,0 +1,20 @@
1
+ import { Drawable } from "roughjs/bin/core";
2
+ import { ExcalidrawElement } from "../element/types";
3
+ import { ElementShape, ElementShapes } from "./types";
4
+ export declare class ShapeCache {
5
+ private static rg;
6
+ private static cache;
7
+ /**
8
+ * Retrieves shape from cache if available. Use this only if shape
9
+ * is optional and you have a fallback in case it's not cached.
10
+ */
11
+ static get: <T extends ExcalidrawElement>(element: T) => T["type"] extends keyof ElementShapes ? ElementShapes[T["type"]] | undefined : ElementShape | undefined;
12
+ static set: <T extends ExcalidrawElement>(element: T, shape: T["type"] extends keyof ElementShapes ? ElementShapes[T["type"]] : Drawable) => WeakMap<ExcalidrawElement, ElementShape>;
13
+ static delete: (element: ExcalidrawElement) => boolean;
14
+ static destroy: () => void;
15
+ /**
16
+ * Generates & caches shape for element if not already cached, otherwise
17
+ * returns cached shape.
18
+ */
19
+ static generateElementShape: <T extends import("../element/types").ExcalidrawLinearElement | import("../element/types").ExcalidrawRectangleElement | import("../element/types").ExcalidrawDiamondElement | import("../element/types").ExcalidrawEllipseElement | import("../element/types").ExcalidrawEmbeddableElement | import("../element/types").ExcalidrawImageElement | import("../element/types").ExcalidrawFrameElement | import("../element/types").ExcalidrawTextElement | import("../element/types").ExcalidrawFreeDrawElement>(element: T, isExporting?: boolean) => ((T["type"] extends keyof ElementShapes ? ElementShapes[T["type"]] | undefined : ElementShape | undefined) & ({} | null)) | (T["type"] extends keyof ElementShapes ? ElementShapes[T["type"]] : Drawable | null);
20
+ }
@@ -4,7 +4,6 @@ export declare const hasStrokeColor: (type: string) => boolean;
4
4
  export declare const hasStrokeWidth: (type: string) => boolean;
5
5
  export declare const hasStrokeStyle: (type: string) => boolean;
6
6
  export declare const canChangeRoundness: (type: string) => boolean;
7
- export declare const hasText: (type: string) => boolean;
8
7
  export declare const canHaveArrowheads: (type: string) => boolean;
9
8
  export declare const getElementAtPosition: (elements: readonly NonDeletedExcalidrawElement[], isAtPositionFn: (element: NonDeletedExcalidrawElement) => boolean) => NonDeletedExcalidrawElement | null;
10
9
  export declare const getElementsAtPosition: (elements: readonly NonDeletedExcalidrawElement[], isAtPositionFn: (element: NonDeletedExcalidrawElement) => boolean) => NonDeletedExcalidrawElement[];
@@ -1,12 +1,14 @@
1
+ import { Bounds } from "../element/bounds";
1
2
  import { NonDeletedExcalidrawElement, Theme } from "../element/types";
2
3
  import { AppState, BinaryFiles } from "../types";
4
+ import { serializeAsJSON } from "../data/json";
3
5
  export declare const SVG_EXPORT_TAG = "<!-- svg-source:excalidraw -->";
4
- export declare type ExportToCanvasData = {
6
+ export type ExportToCanvasData = {
5
7
  elements: readonly NonDeletedExcalidrawElement[];
6
8
  appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
7
9
  files: BinaryFiles | null;
8
10
  };
9
- export declare type ExportToCanvasConfig = {
11
+ export type ExportToCanvasConfig = {
10
12
  theme?: Theme;
11
13
  /**
12
14
  * Canvas background. Valid values are:
@@ -19,10 +21,28 @@ export declare type ExportToCanvasConfig = {
19
21
  */
20
22
  canvasBackgroundColor?: string | false;
21
23
  /**
22
- * Canvas padding in pixels. Affected by scale. Ignored if `fit` is set to
23
- * `cover`.
24
+ * Canvas padding in pixels. Affected by `scale`.
24
25
  *
25
- * @default 10
26
+ * When `fit` is set to `none`, padding is added to the content bounding box
27
+ * (including if you set `width` or `height` or `maxWidthOrHeight` or
28
+ * `widthOrHeight`).
29
+ *
30
+ * When `fit` set to `contain`, padding is subtracted from the content
31
+ * bounding box (ensuring the size doesn't exceed the supplied values, with
32
+ * the exeception of using alongside `scale` as noted above), and the padding
33
+ * serves as a minimum distance between the content and the canvas edges, as
34
+ * it may exceed the supplied padding value from one side or the other in
35
+ * order to maintain the aspect ratio. It is recommended to set `position`
36
+ * to `center` when using `fit=contain`.
37
+ *
38
+ * When `fit` is set to `cover`, padding is disabled (set to 0).
39
+ *
40
+ * When `fit` is set to `none` and either `width` or `height` or
41
+ * `maxWidthOrHeight` is set, padding is simply adding to the bounding box
42
+ * and the content may overflow the canvas, thus right or bottom padding
43
+ * may be ignored.
44
+ *
45
+ * @default 0
26
46
  */
27
47
  padding?: number;
28
48
  /**
@@ -33,6 +53,16 @@ export declare type ExportToCanvasConfig = {
33
53
  * `scale`.
34
54
  */
35
55
  maxWidthOrHeight?: number;
56
+ /**
57
+ * Scale the canvas content to be excatly this many pixels wide/tall,
58
+ * maintaining the aspect ratio.
59
+ *
60
+ * Cannot be used in conjunction with `maxWidthOrHeight`.
61
+ *
62
+ * Final dimensions can get smaller/larger if used in conjunction with
63
+ * `scale`.
64
+ */
65
+ widthOrHeight?: number;
36
66
  /**
37
67
  * Width of the frame. Supply `x` or `y` if you want to ofsset the canvas
38
68
  * content.
@@ -84,12 +114,15 @@ export declare type ExportToCanvasConfig = {
84
114
  * Behavior aligns with the `object-fit` CSS property.
85
115
  *
86
116
  * - `none` - no scaling.
87
- * - `contain` - scale to fit the frame.
117
+ * - `contain` - scale to fit the frame. Includes `padding`.
88
118
  * - `cover` - scale to fill the frame while maintaining aspect ratio. If
89
119
  * content overflows, it will be cropped.
90
120
  *
91
- * @default "contain" unless `x` or `y` are specified, in which case "none"
92
- * is used (forced).
121
+ * If `maxWidthOrHeight` or `widthOrHeight` is set, `fit` is ignored.
122
+ *
123
+ * @default "contain" unless `width`, `height`, `maxWidthOrHeight`, or
124
+ * `widthOrHeight` is specified in which case `none` is the default (can be
125
+ * changed). If `x` or `y` are specified, `none` is forced.
93
126
  */
94
127
  fit?: "none" | "contain" | "cover";
95
128
  /**
@@ -100,9 +133,11 @@ export declare type ExportToCanvasConfig = {
100
133
  * - `center` - canvas is centered on the axis which is not specified
101
134
  * (or both).
102
135
  *
136
+ * If `maxWidthOrHeight` or `widthOrHeight` is set, `position` is ignored.
137
+ *
103
138
  * @default "center"
104
139
  */
105
- position?: "center" | "none";
140
+ position?: "center" | "topLeft";
106
141
  /**
107
142
  * A multiplier to increase/decrease the frame dimensions
108
143
  * (content resolution).
@@ -150,5 +185,9 @@ export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElemen
150
185
  viewBackgroundColor: string;
151
186
  exportWithDarkMode?: boolean;
152
187
  exportEmbedScene?: boolean;
153
- }, files: BinaryFiles | null) => Promise<SVGSVGElement>;
154
- export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], padding: number, scale: number) => [number, number];
188
+ renderFrame?: boolean;
189
+ }, files: BinaryFiles | null, opts?: {
190
+ serializeAsJSON?: () => string;
191
+ renderEmbeddables?: boolean;
192
+ }) => Promise<SVGSVGElement>;
193
+ export declare const getCanvasSize: (elements: readonly NonDeletedExcalidrawElement[]) => Bounds;
@@ -1,5 +1,5 @@
1
1
  export { isOverScrollBars } from "./scrollbars";
2
2
  export { isSomeElementSelected, getElementsWithinSelection, getCommonAttributeOfSelectedElements, getSelectedElements, getTargetElements, } from "./selection";
3
3
  export { calculateScrollCenter } from "./scroll";
4
- export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeRoundness, getElementAtPosition, hasText, getElementsAtPosition, } from "./comparisons";
4
+ export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeRoundness, getElementAtPosition, getElementsAtPosition, } from "./comparisons";
5
5
  export { getNormalizedZoom } from "./zoom";
@@ -11,7 +11,7 @@ export declare const centerScrollOn: ({ scenePoint, viewportDimensions, zoom, }:
11
11
  scrollX: number;
12
12
  scrollY: number;
13
13
  };
14
- export declare const calculateScrollCenter: (elements: readonly ExcalidrawElement[], appState: AppState, canvas: HTMLCanvasElement | null) => {
14
+ export declare const calculateScrollCenter: (elements: readonly ExcalidrawElement[], appState: AppState) => {
15
15
  scrollX: number;
16
16
  scrollY: number;
17
17
  };
@@ -1,14 +1,10 @@
1
1
  import { ExcalidrawElement } from "../element/types";
2
- import { Zoom } from "../types";
2
+ import { InteractiveCanvasAppState } from "../types";
3
3
  import { ScrollBars } from "./types";
4
4
  export declare const SCROLLBAR_MARGIN = 4;
5
5
  export declare const SCROLLBAR_WIDTH = 6;
6
6
  export declare const SCROLLBAR_COLOR = "rgba(0,0,0,0.3)";
7
- export declare const getScrollBars: (elements: readonly ExcalidrawElement[], viewportWidth: number, viewportHeight: number, { scrollX, scrollY, zoom, }: {
8
- scrollX: number;
9
- scrollY: number;
10
- zoom: Zoom;
11
- }) => ScrollBars;
7
+ export declare const getScrollBars: (elements: readonly ExcalidrawElement[], viewportWidth: number, viewportHeight: number, appState: InteractiveCanvasAppState) => ScrollBars;
12
8
  export declare const isOverScrollBars: (scrollBars: ScrollBars, x: number, y: number) => {
13
9
  isOverEither: boolean;
14
10
  isOverHorizontal: boolean;
@@ -1,11 +1,32 @@
1
1
  import { ExcalidrawElement, NonDeletedExcalidrawElement } from "../element/types";
2
- import { AppState } from "../types";
3
- export declare const getElementsWithinSelection: (elements: readonly NonDeletedExcalidrawElement[], selection: NonDeletedExcalidrawElement) => NonDeletedExcalidrawElement[];
4
- export declare const isSomeElementSelected: (elements: readonly NonDeletedExcalidrawElement[], appState: AppState) => boolean;
2
+ import { AppState, InteractiveCanvasAppState } from "../types";
3
+ /**
4
+ * Frames and their containing elements are not to be selected at the same time.
5
+ * Given an array of selected elements, if there are frames and their containing elements
6
+ * we only keep the frames.
7
+ * @param selectedElements
8
+ */
9
+ export declare const excludeElementsInFramesFromSelection: <T extends ExcalidrawElement>(selectedElements: readonly T[]) => T[];
10
+ export declare const getElementsWithinSelection: (elements: readonly NonDeletedExcalidrawElement[], selection: NonDeletedExcalidrawElement, excludeElementsInFrames?: boolean) => NonDeletedExcalidrawElement[];
11
+ export declare const getVisibleAndNonSelectedElements: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: readonly NonDeletedExcalidrawElement[], appState: AppState) => NonDeletedExcalidrawElement[];
12
+ export declare const isSomeElementSelected: {
13
+ (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">): boolean;
14
+ clearCache(): void;
15
+ };
5
16
  /**
6
17
  * Returns common attribute (picked by `getAttribute` callback) of selected
7
18
  * elements. If elements don't share the same value, returns `null`.
8
19
  */
9
- export declare const getCommonAttributeOfSelectedElements: <T>(elements: readonly NonDeletedExcalidrawElement[], appState: AppState, getAttribute: (element: ExcalidrawElement) => T) => T | null;
10
- export declare const getSelectedElements: (elements: readonly NonDeletedExcalidrawElement[], appState: AppState, includeBoundTextElement?: boolean) => NonDeletedExcalidrawElement[];
11
- export declare const getTargetElements: (elements: readonly NonDeletedExcalidrawElement[], appState: AppState) => NonDeletedExcalidrawElement[];
20
+ export declare const getCommonAttributeOfSelectedElements: <T>(elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">, getAttribute: (element: ExcalidrawElement) => T) => T | null;
21
+ export declare const getSelectedElements: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<InteractiveCanvasAppState, "selectedElementIds">, opts?: {
22
+ includeBoundTextElement?: boolean;
23
+ includeElementsInFrames?: boolean;
24
+ }) => ExcalidrawElement[];
25
+ export declare const getTargetElements: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds" | "editingElement">) => ExcalidrawElement[];
26
+ /**
27
+ * returns prevState's selectedElementids if no change from previous, so as to
28
+ * retain reference identity for memoization
29
+ */
30
+ export declare const makeNextSelectedElementIds: (nextSelectedElementIds: AppState["selectedElementIds"], prevState: Pick<AppState, "selectedElementIds">) => Readonly<{
31
+ [id: string]: true;
32
+ }>;
@@ -1,57 +1,80 @@
1
- import { ExcalidrawTextElement } from "../element/types";
2
- import { AppClassProperties, AppState } from "../types";
3
- export declare type RenderConfig = {
4
- scrollX: AppState["scrollX"];
5
- scrollY: AppState["scrollY"];
1
+ import type { RoughCanvas } from "roughjs/bin/canvas";
2
+ import { Drawable } from "roughjs/bin/core";
3
+ import { ExcalidrawTextElement, NonDeletedExcalidrawElement } from "../element/types";
4
+ import { AppClassProperties, InteractiveCanvasAppState, StaticCanvasAppState } from "../types";
5
+ export type RenderConfig = {};
6
+ export type StaticCanvasRenderConfig = {
7
+ imageCache: AppClassProperties["imageCache"];
8
+ renderGrid: boolean;
9
+ /** when exporting the behavior is slightly different (e.g. we can't use
10
+ CSS filters), and we disable render optimizations for best output */
11
+ isExporting: boolean;
6
12
  /** null indicates transparent bg */
7
- canvasBackgroundColor: AppState["viewBackgroundColor"] | null;
8
- zoom: AppState["zoom"];
9
- shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
10
- theme: AppState["theme"];
11
- /**
12
- * canvas scale factor. Not related to zoom. In browsers, it's the
13
- * devicePixelRatio. For export, it's the `appState.exportScale`
14
- * (user setting) or whatever scale you want to use when exporting elsewhere.
15
- *
16
- * Bigger the scale, the more pixels (=quality).
17
- */
18
- canvasScale: number;
13
+ canvasBackgroundColor: string | null;
14
+ };
15
+ export type InteractiveCanvasRenderConfig = {
16
+ remoteSelectedElementIds: {
17
+ [elementId: string]: string[];
18
+ };
19
19
  remotePointerViewportCoords: {
20
20
  [id: string]: {
21
21
  x: number;
22
22
  y: number;
23
+ id: string;
23
24
  };
24
25
  };
25
- remotePointerButton?: {
26
- [id: string]: string | undefined;
27
- };
28
- remoteSelectedElementIds: {
29
- [elementId: string]: string[];
26
+ remotePointerUserStates: {
27
+ [id: string]: string;
30
28
  };
31
29
  remotePointerUsernames: {
32
30
  [id: string]: string;
33
31
  };
34
- remotePointerUserStates: {
35
- [id: string]: string;
32
+ remotePointerButton?: {
33
+ [id: string]: string | undefined;
36
34
  };
37
- imageCache: AppClassProperties["imageCache"];
38
- renderScrollbars?: boolean;
39
- renderSelection?: boolean;
40
- renderGrid?: boolean;
41
- /** when exporting the behavior is slightly different (e.g. we can't use
42
- CSS filters), and we disable render optimizations for best output */
43
- isExporting: boolean;
44
35
  selectionColor?: string;
36
+ renderScrollbars?: boolean;
37
+ };
38
+ export type RenderInteractiveSceneCallback = {
39
+ atLeastOneVisibleElement: boolean;
40
+ elements: readonly NonDeletedExcalidrawElement[];
41
+ scrollBars?: ScrollBars;
45
42
  };
46
- export declare type SceneScroll = {
43
+ export type StaticSceneRenderConfig = {
44
+ canvas: HTMLCanvasElement;
45
+ rc: RoughCanvas;
46
+ elements: readonly NonDeletedExcalidrawElement[];
47
+ visibleElements: readonly NonDeletedExcalidrawElement[];
48
+ /**
49
+ * canvas scale factor. Not related to zoom. In browsers, it's the
50
+ * devicePixelRatio. For export, it's the `appState.exportScale`
51
+ * (user setting) or whatever scale you want to use when exporting elsewhere.
52
+ *
53
+ * Bigger the scale, the more pixels (=quality).
54
+ */
55
+ scale: number;
56
+ appState: StaticCanvasAppState;
57
+ renderConfig: StaticCanvasRenderConfig;
58
+ };
59
+ export type InteractiveSceneRenderConfig = {
60
+ canvas: HTMLCanvasElement | null;
61
+ elements: readonly NonDeletedExcalidrawElement[];
62
+ visibleElements: readonly NonDeletedExcalidrawElement[];
63
+ selectedElements: readonly NonDeletedExcalidrawElement[];
64
+ scale: number;
65
+ appState: InteractiveCanvasAppState;
66
+ renderConfig: InteractiveCanvasRenderConfig;
67
+ callback: (data: RenderInteractiveSceneCallback) => void;
68
+ };
69
+ export type SceneScroll = {
47
70
  scrollX: number;
48
71
  scrollY: number;
49
72
  };
50
73
  export interface Scene {
51
74
  elements: ExcalidrawTextElement[];
52
75
  }
53
- export declare type ExportType = "png" | "clipboard" | "clipboard-svg" | "backend" | "svg";
54
- export declare type ScrollBars = {
76
+ export type ExportType = "png" | "clipboard" | "clipboard-svg" | "backend" | "svg";
77
+ export type ScrollBars = {
55
78
  horizontal: {
56
79
  x: number;
57
80
  y: number;
@@ -65,3 +88,16 @@ export declare type ScrollBars = {
65
88
  height: number;
66
89
  } | null;
67
90
  };
91
+ export type ElementShape = Drawable | Drawable[] | null;
92
+ export type ElementShapes = {
93
+ rectangle: Drawable;
94
+ ellipse: Drawable;
95
+ diamond: Drawable;
96
+ embeddable: Drawable;
97
+ freedraw: Drawable | null;
98
+ arrow: Drawable[];
99
+ line: Drawable[];
100
+ text: null;
101
+ image: null;
102
+ frame: null;
103
+ };
@@ -0,0 +1,108 @@
1
+ import { Bounds } from "./element/bounds";
2
+ import { MaybeTransformHandleType } from "./element/transformHandles";
3
+ import { ExcalidrawElement, NonDeletedExcalidrawElement } from "./element/types";
4
+ import { AppState, KeyboardModifiersObject, Point } from "./types";
5
+ export declare const getSnapDistance: (zoomValue: number) => number;
6
+ type Vector2D = {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ type PointPair = [Point, Point];
11
+ export type PointSnap = {
12
+ type: "point";
13
+ points: PointPair;
14
+ offset: number;
15
+ };
16
+ export type Gap = {
17
+ startBounds: Bounds;
18
+ endBounds: Bounds;
19
+ startSide: [Point, Point];
20
+ endSide: [Point, Point];
21
+ overlap: [number, number];
22
+ length: number;
23
+ };
24
+ export type GapSnap = {
25
+ type: "gap";
26
+ direction: "center_horizontal" | "center_vertical" | "side_left" | "side_right" | "side_top" | "side_bottom";
27
+ gap: Gap;
28
+ offset: number;
29
+ };
30
+ export type GapSnaps = GapSnap[];
31
+ export type Snap = GapSnap | PointSnap;
32
+ export type Snaps = Snap[];
33
+ export type PointSnapLine = {
34
+ type: "points";
35
+ points: Point[];
36
+ };
37
+ export type PointerSnapLine = {
38
+ type: "pointer";
39
+ points: PointPair;
40
+ direction: "horizontal" | "vertical";
41
+ };
42
+ export type GapSnapLine = {
43
+ type: "gap";
44
+ direction: "horizontal" | "vertical";
45
+ points: PointPair;
46
+ };
47
+ export type SnapLine = PointSnapLine | GapSnapLine | PointerSnapLine;
48
+ export declare class SnapCache {
49
+ private static referenceSnapPoints;
50
+ private static visibleGaps;
51
+ static setReferenceSnapPoints: (snapPoints: Point[] | null) => void;
52
+ static getReferenceSnapPoints: () => (readonly [number, number])[] | null;
53
+ static setVisibleGaps: (gaps: {
54
+ verticalGaps: Gap[];
55
+ horizontalGaps: Gap[];
56
+ } | null) => void;
57
+ static getVisibleGaps: () => {
58
+ verticalGaps: Gap[];
59
+ horizontalGaps: Gap[];
60
+ } | null;
61
+ static destroy: () => void;
62
+ }
63
+ export declare const isSnappingEnabled: ({ event, appState, selectedElements, }: {
64
+ appState: AppState;
65
+ event: KeyboardModifiersObject;
66
+ selectedElements: NonDeletedExcalidrawElement[];
67
+ }) => boolean;
68
+ export declare const areRoughlyEqual: (a: number, b: number, precision?: number) => boolean;
69
+ export declare const getElementsCorners: (elements: ExcalidrawElement[], { omitCenter, boundingBoxCorners, dragOffset, }?: {
70
+ omitCenter?: boolean | undefined;
71
+ boundingBoxCorners?: boolean | undefined;
72
+ dragOffset?: Vector2D | undefined;
73
+ }) => Point[];
74
+ export declare const getVisibleGaps: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: ExcalidrawElement[], appState: AppState) => {
75
+ horizontalGaps: Gap[];
76
+ verticalGaps: Gap[];
77
+ };
78
+ export declare const getReferenceSnapPoints: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: ExcalidrawElement[], appState: AppState) => (readonly [number, number])[];
79
+ export declare const snapDraggedElements: (selectedElements: ExcalidrawElement[], dragOffset: Vector2D, appState: AppState, event: KeyboardModifiersObject) => {
80
+ snapOffset: {
81
+ x: number;
82
+ y: number;
83
+ };
84
+ snapLines: (PointSnapLine | GapSnapLine)[];
85
+ };
86
+ export declare const snapResizingElements: (selectedElements: ExcalidrawElement[], selectedOriginalElements: ExcalidrawElement[], appState: AppState, event: KeyboardModifiersObject, dragOffset: Vector2D, transformHandle: MaybeTransformHandleType) => {
87
+ snapOffset: {
88
+ x: number;
89
+ y: number;
90
+ };
91
+ snapLines: PointSnapLine[];
92
+ };
93
+ export declare const snapNewElement: (draggingElement: ExcalidrawElement, appState: AppState, event: KeyboardModifiersObject, origin: Vector2D, dragOffset: Vector2D) => {
94
+ snapOffset: {
95
+ x: number;
96
+ y: number;
97
+ };
98
+ snapLines: PointSnapLine[];
99
+ };
100
+ export declare const getSnapLinesAtPointer: (elements: readonly ExcalidrawElement[], appState: AppState, pointer: Vector2D, event: KeyboardModifiersObject) => {
101
+ originOffset: {
102
+ x: number;
103
+ y: number;
104
+ };
105
+ snapLines: PointerSnapLine[];
106
+ };
107
+ export declare const isActiveToolNonLinearSnappable: (activeToolType: AppState["activeTool"]["type"]) => boolean;
108
+ export {};