@dwelle/excalidraw 0.4.0-e1bdbb6 → 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 (240) hide show
  1. package/CHANGELOG.md +714 -0
  2. package/README.md +18 -1422
  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 +3257 -1444
  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 +124 -64
  11. package/types/actions/actionAlign.d.ts +33 -40
  12. package/types/actions/actionBoundText.d.ts +182 -25
  13. package/types/actions/actionCanvas.d.ts +754 -220
  14. package/types/actions/actionClipboard.d.ts +236 -115
  15. package/types/actions/actionDeleteSelected.d.ts +133 -72
  16. package/types/actions/actionDistribute.d.ts +11 -16
  17. package/types/actions/actionDuplicateSelection.d.ts +4 -7
  18. package/types/actions/actionElementLock.d.ts +271 -0
  19. package/types/actions/actionExport.d.ts +440 -277
  20. package/types/actions/actionFinalize.d.ts +85 -51
  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 +252 -19
  24. package/types/actions/actionHistory.d.ts +1 -1
  25. package/types/actions/actionLinearEditor.d.ts +44 -24
  26. package/types/actions/actionMenu.d.ts +132 -79
  27. package/types/actions/actionNavigate.d.ts +2 -3
  28. package/types/actions/actionProperties.d.ts +569 -334
  29. package/types/actions/actionSelectAll.d.ts +123 -4
  30. package/types/actions/actionStyles.d.ts +46 -27
  31. package/types/actions/actionToggleGridMode.d.ts +46 -25
  32. package/types/actions/{actionToggleLock.d.ts → actionToggleObjectsSnapMode.d.ts} +56 -35
  33. package/types/actions/actionToggleStats.d.ts +45 -25
  34. package/types/actions/actionToggleViewMode.d.ts +46 -25
  35. package/types/actions/actionToggleZenMode.d.ts +46 -25
  36. package/types/actions/actionZindex.d.ts +16 -24
  37. package/types/actions/index.d.ts +2 -1
  38. package/types/actions/manager.d.ts +3 -2
  39. package/types/actions/shortcuts.d.ts +2 -1
  40. package/types/actions/types.d.ts +16 -13
  41. package/types/appState.d.ts +27 -28
  42. package/types/charts.d.ts +2 -2
  43. package/types/clients.d.ts +5 -6
  44. package/types/clipboard.d.ts +9 -3
  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 +102 -86
  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 +16 -0
  52. package/types/components/ButtonIconSelect.d.ts +11 -3
  53. package/types/components/Card.d.ts +6 -0
  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 +9 -22
  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 +7 -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 +11 -19
  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 -5
  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 +9 -15
  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/UserList.d.ts +0 -2
  120. package/types/components/canvases/InteractiveCanvas.d.ts +27 -0
  121. package/types/components/canvases/StaticCanvas.d.ts +18 -0
  122. package/types/components/canvases/index.d.ts +3 -0
  123. package/types/components/dropdownMenu/DropdownMenu.d.ts +70 -0
  124. package/types/components/dropdownMenu/DropdownMenuContent.d.ts +15 -0
  125. package/types/components/dropdownMenu/DropdownMenuGroup.d.ts +11 -0
  126. package/types/components/dropdownMenu/DropdownMenuItem.d.ts +13 -0
  127. package/types/components/dropdownMenu/DropdownMenuItemContent.d.ts +6 -0
  128. package/types/components/dropdownMenu/DropdownMenuItemCustom.d.ts +7 -0
  129. package/types/components/dropdownMenu/DropdownMenuItemLink.d.ts +14 -0
  130. package/types/components/dropdownMenu/DropdownMenuSeparator.d.ts +5 -0
  131. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +10 -0
  132. package/types/components/dropdownMenu/common.d.ts +6 -0
  133. package/types/components/dropdownMenu/dropdownMenuUtils.d.ts +3 -0
  134. package/types/components/footer/Footer.d.ts +12 -0
  135. package/types/components/footer/FooterCenter.d.ts +8 -0
  136. package/types/components/hoc/withInternalFallback.d.ts +4 -0
  137. package/types/components/icons.d.ts +17 -2
  138. package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +9 -0
  139. package/types/components/main-menu/DefaultItems.d.ts +47 -0
  140. package/types/components/main-menu/MainMenu.d.ts +64 -0
  141. package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +57 -0
  142. package/types/components/welcome-screen/WelcomeScreen.Hints.d.ts +19 -0
  143. package/types/components/welcome-screen/WelcomeScreen.d.ts +84 -0
  144. package/types/constants.d.ts +105 -18
  145. package/types/context/tunnels.d.ts +19 -0
  146. package/types/context/ui-appState.d.ts +4 -0
  147. package/types/cursor.d.ts +5 -0
  148. package/types/data/blob.d.ts +5 -3
  149. package/types/data/encode.d.ts +1 -1
  150. package/types/data/filesystem.d.ts +2 -1
  151. package/types/data/index.d.ts +1 -1
  152. package/types/data/library.d.ts +3 -45
  153. package/types/data/restore.d.ts +10 -4
  154. package/types/data/transform.d.ts +73 -0
  155. package/types/data/types.d.ts +3 -5
  156. package/types/data/url.d.ts +7 -0
  157. package/types/element/Hyperlink.d.ts +57 -36
  158. package/types/element/binding.d.ts +4 -3
  159. package/types/element/bounds.d.ts +41 -10
  160. package/types/element/collision.d.ts +7 -7
  161. package/types/element/dragElements.d.ts +12 -2
  162. package/types/element/embeddable.d.ts +153 -0
  163. package/types/element/image.d.ts +11 -1
  164. package/types/element/index.d.ts +3 -2
  165. package/types/element/linearElementEditor.d.ts +77 -30
  166. package/types/element/mutateElement.d.ts +3 -2
  167. package/types/element/newElement.d.ts +48 -15
  168. package/types/element/resizeElements.d.ts +3 -3
  169. package/types/element/resizeTest.d.ts +2 -1
  170. package/types/element/showSelectedShapeActions.d.ts +2 -2
  171. package/types/element/sizeHelpers.d.ts +8 -1
  172. package/types/element/sortElements.d.ts +2 -0
  173. package/types/element/textElement.d.ts +57 -9
  174. package/types/element/textWysiwyg.d.ts +7 -2
  175. package/types/element/transformHandles.d.ts +15 -8
  176. package/types/element/typeChecks.d.ts +14 -2
  177. package/types/element/types.d.ts +66 -35
  178. package/types/emitter.d.ts +1 -2
  179. package/types/errors.d.ts +1 -1
  180. package/types/frame.d.ts +46 -0
  181. package/types/ga.d.ts +5 -5
  182. package/types/groups.d.ts +15 -11
  183. package/types/history.d.ts +3 -3
  184. package/types/hooks/useCreatePortalContainer.d.ts +4 -0
  185. package/types/hooks/useLibraryItemSvg.d.ts +11 -0
  186. package/types/hooks/useOutsideClick.d.ts +19 -2
  187. package/types/hooks/useScrollPosition.d.ts +1 -0
  188. package/types/hooks/useStable.d.ts +1 -0
  189. package/types/hooks/useTransition.d.ts +2 -0
  190. package/types/i18n.d.ts +11 -2
  191. package/types/jotai.d.ts +20 -108
  192. package/types/keys.d.ts +7 -4
  193. package/types/math.d.ts +7 -1
  194. package/types/packages/bbox.d.ts +11 -0
  195. package/types/packages/excalidraw/example/App.d.ts +7 -1
  196. package/types/packages/excalidraw/example/CustomFooter.d.ts +5 -0
  197. package/types/packages/excalidraw/example/MobileFooter.d.ts +5 -0
  198. package/types/packages/excalidraw/example/initialData.d.ts +182 -64
  199. package/types/packages/excalidraw/index.d.ts +22 -4
  200. package/types/packages/excalidraw/main.d.ts +3 -1
  201. package/types/packages/excalidraw/webpack.dev.config.d.ts +5 -2
  202. package/types/packages/excalidraw/webpack.prod.config.d.ts +3 -0
  203. package/types/packages/utils.d.ts +30 -24
  204. package/types/packages/withinBounds.d.ts +19 -0
  205. package/types/renderer/renderElement.d.ts +13 -22
  206. package/types/renderer/renderScene.d.ts +19 -29
  207. package/types/renderer/renderSnaps.d.ts +2 -0
  208. package/types/renderer/roundRect.d.ts +1 -1
  209. package/types/scene/Fonts.d.ts +21 -0
  210. package/types/scene/Renderer.d.ts +25 -0
  211. package/types/scene/Scene.d.ts +42 -5
  212. package/types/scene/Shape.d.ts +12 -0
  213. package/types/scene/ShapeCache.d.ts +20 -0
  214. package/types/scene/comparisons.d.ts +2 -4
  215. package/types/scene/export.d.ts +183 -10
  216. package/types/scene/index.d.ts +1 -1
  217. package/types/scene/scroll.d.ts +1 -1
  218. package/types/scene/scrollbars.d.ts +2 -6
  219. package/types/scene/selection.d.ts +27 -6
  220. package/types/scene/types.d.ts +70 -26
  221. package/types/snapping.d.ts +108 -0
  222. package/types/types.d.ts +227 -91
  223. package/types/utility-types.d.ts +24 -0
  224. package/types/utils.d.ts +75 -14
  225. package/types/zindex.d.ts +4 -4
  226. package/types/components/ActiveFile.d.ts +0 -7
  227. package/types/components/ClearCanvas.d.ts +0 -4
  228. package/types/components/CollabButton.d.ts +0 -6
  229. package/types/components/ColorPicker.d.ts +0 -14
  230. package/types/components/Footer.d.ts +0 -10
  231. package/types/components/LibraryButton.d.ts +0 -8
  232. package/types/components/MenuItem.d.ts +0 -11
  233. package/types/components/MenuUtils.d.ts +0 -1
  234. package/types/components/SingleLibraryItem.d.ts +0 -10
  235. package/types/components/WelcomeScreen.d.ts +0 -10
  236. package/types/components/WelcomeScreenDecor.d.ts +0 -6
  237. package/types/components/hoc/withUpstreamOverride.d.ts +0 -10
  238. /package/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.js.LICENSE.txt → vendor-d415b28e9024dee4bb1b.js.LICENSE.txt} +0 -0
  239. /package/types/packages/excalidraw/dist/excalidraw-assets/{vendor-2002fe1b8862917b36c1.d.ts → vendor-d415b28e9024dee4bb1b.d.ts} +0 -0
  240. /package/types/packages/excalidraw/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.d.ts → vendor-a14cd58fa2db417e42b2.d.ts} +0 -0
@@ -0,0 +1,21 @@
1
+ import { ExcalidrawElement } from "../element/types";
2
+ import type Scene from "./Scene";
3
+ export declare class Fonts {
4
+ private scene;
5
+ private onSceneUpdated;
6
+ constructor({ scene, onSceneUpdated, }: {
7
+ scene: Scene;
8
+ onSceneUpdated: () => void;
9
+ });
10
+ private static loadedFontFaces;
11
+ /**
12
+ * if we load a (new) font, it's likely that text elements using it have
13
+ * already been rendered using a fallback font. Thus, we want invalidate
14
+ * their shapes and rerender. See #637.
15
+ *
16
+ * Invalidates text elements and rerenders scene, provided that at least one
17
+ * of the supplied fontFaces has not already been processed.
18
+ */
19
+ onFontsLoaded: (fontFaces: readonly FontFace[]) => false | undefined;
20
+ loadFontsForElements: (elements: readonly ExcalidrawElement[]) => Promise<void>;
21
+ }
@@ -0,0 +1,25 @@
1
+ import { NonDeletedExcalidrawElement } from "../element/types";
2
+ import { AppState } from "../types";
3
+ import Scene from "./Scene";
4
+ export declare class Renderer {
5
+ private scene;
6
+ constructor(scene: Scene);
7
+ getRenderableElements: ((opts: {
8
+ zoom: AppState["zoom"];
9
+ offsetLeft: AppState["offsetLeft"];
10
+ offsetTop: AppState["offsetTop"];
11
+ scrollX: AppState["scrollX"];
12
+ scrollY: AppState["scrollY"];
13
+ height: AppState["height"];
14
+ width: AppState["width"];
15
+ editingElement: AppState["editingElement"];
16
+ pendingImageElementId: AppState["pendingImageElementId"];
17
+ versionNonce: ReturnType<InstanceType<typeof Scene>["getVersionNonce"]>;
18
+ }) => {
19
+ canvasElements: NonDeletedExcalidrawElement[];
20
+ visibleElements: readonly NonDeletedExcalidrawElement[];
21
+ }) & {
22
+ clear: () => void;
23
+ };
24
+ destroy(): void;
25
+ }
@@ -1,9 +1,11 @@
1
- import { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted } from "../element/types";
1
+ import { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted, ExcalidrawFrameElement } from "../element/types";
2
2
  import { LinearElementEditor } from "../element/linearElementEditor";
3
- declare type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
4
- declare type ElementKey = ExcalidrawElement | ElementIdKey;
5
- declare type SceneStateCallback = () => void;
6
- declare type SceneStateCallbackRemover = () => void;
3
+ import { AppState } from "../types";
4
+ type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
5
+ type ElementKey = ExcalidrawElement | ElementIdKey;
6
+ type SceneStateCallback = () => void;
7
+ type SceneStateCallbackRemover = () => void;
8
+ export type ExcalidrawElementsIncludingDeleted = readonly ExcalidrawElement[];
7
9
  declare class Scene {
8
10
  private static sceneMapByElement;
9
11
  private static sceneMapById;
@@ -12,14 +14,49 @@ declare class Scene {
12
14
  private callbacks;
13
15
  private nonDeletedElements;
14
16
  private elements;
17
+ private nonDeletedFrames;
18
+ private frames;
15
19
  private elementsMap;
20
+ private selectedElementsCache;
21
+ private versionNonce;
16
22
  getElementsIncludingDeleted(): readonly ExcalidrawElement[];
17
23
  getNonDeletedElements(): readonly NonDeletedExcalidrawElement[];
24
+ getFramesIncludingDeleted(): readonly ExcalidrawFrameElement[];
25
+ getSelectedElements(opts: {
26
+ selectedElementIds: AppState["selectedElementIds"];
27
+ /**
28
+ * for specific cases where you need to use elements not from current
29
+ * scene state. This in effect will likely result in cache-miss, and
30
+ * the cache won't be updated in this case.
31
+ */
32
+ elements?: readonly ExcalidrawElement[];
33
+ includeBoundTextElement?: boolean;
34
+ includeElementsInFrames?: boolean;
35
+ }): NonDeleted<ExcalidrawElement>[];
36
+ getNonDeletedFrames(): readonly NonDeleted<ExcalidrawFrameElement>[];
18
37
  getElement<T extends ExcalidrawElement>(id: T["id"]): T | null;
38
+ getVersionNonce(): number | undefined;
19
39
  getNonDeletedElement(id: ExcalidrawElement["id"]): NonDeleted<ExcalidrawElement> | null;
40
+ /**
41
+ * A utility method to help with updating all scene elements, with the added
42
+ * performance optimization of not renewing the array if no change is made.
43
+ *
44
+ * Maps all current excalidraw elements, invoking the callback for each
45
+ * element. The callback should either return a new mapped element, or the
46
+ * original element if no changes are made. If no changes are made to any
47
+ * element, this results in a no-op. Otherwise, the newly mapped elements
48
+ * are set as the next scene's elements.
49
+ *
50
+ * @returns whether a change was made
51
+ */
52
+ mapElements(iteratee: (element: ExcalidrawElement) => ExcalidrawElement): boolean;
20
53
  replaceAllElements(nextElements: readonly ExcalidrawElement[]): void;
21
54
  informMutation(): void;
22
55
  addCallback(cb: SceneStateCallback): SceneStateCallbackRemover;
23
56
  destroy(): void;
57
+ insertElementAtIndex(element: ExcalidrawElement, index: number): void;
58
+ insertElementsAtIndex(elements: ExcalidrawElement[], index: number): void;
59
+ addNewElement: (element: ExcalidrawElement) => void;
60
+ getElementIndex(elementId: string): number;
24
61
  }
25
62
  export default Scene;
@@ -0,0 +1,12 @@
1
+ import type { Drawable, Options } from "roughjs/bin/core";
2
+ import type { RoughGenerator } from "roughjs/bin/generator";
3
+ import type { ExcalidrawElement, NonDeletedExcalidrawElement, ExcalidrawSelectionElement } from "../element/types";
4
+ export declare const generateRoughOptions: (element: ExcalidrawElement, continuousPath?: boolean) => Options;
5
+ /**
6
+ * Generates the roughjs shape for given element.
7
+ *
8
+ * Low-level. Use `ShapeCache.generateElementShape` instead.
9
+ *
10
+ * @private
11
+ */
12
+ export declare const _generateElementShape: (element: Exclude<NonDeletedExcalidrawElement, ExcalidrawSelectionElement>, generator: RoughGenerator, isExporting?: boolean) => Drawable | Drawable[] | null;
@@ -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
+ }
@@ -1,11 +1,9 @@
1
- import { ExcalidrawElement, ExcalidrawTextContainer, NonDeletedExcalidrawElement } from "../element/types";
1
+ import { NonDeletedExcalidrawElement } from "../element/types";
2
2
  export declare const hasBackground: (type: string) => boolean;
3
3
  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
- export declare const canChangeSharpness: (type: string) => boolean;
7
- export declare const hasText: (type: string) => boolean;
6
+ export declare const canChangeRoundness: (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[];
11
- export declare const getTextBindableContainerAtPosition: (elements: readonly ExcalidrawElement[], x: number, y: number) => ExcalidrawTextContainer | null;
@@ -1,13 +1,182 @@
1
- import { NonDeletedExcalidrawElement } from "../element/types";
1
+ import { Bounds } from "../element/bounds";
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 const exportToCanvas: (elements: readonly NonDeletedExcalidrawElement[], appState: AppState, files: BinaryFiles, { exportBackground, exportPadding, viewBackgroundColor, }: {
5
- exportBackground: boolean;
6
- exportPadding?: number | undefined;
7
- viewBackgroundColor: string;
8
- }, createCanvas?: (width: number, height: number) => {
9
- canvas: HTMLCanvasElement;
10
- scale: number;
6
+ export type ExportToCanvasData = {
7
+ elements: readonly NonDeletedExcalidrawElement[];
8
+ appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
9
+ files: BinaryFiles | null;
10
+ };
11
+ export type ExportToCanvasConfig = {
12
+ theme?: Theme;
13
+ /**
14
+ * Canvas background. Valid values are:
15
+ *
16
+ * - `undefined` - the background of "appState.viewBackgroundColor" is used.
17
+ * - `false` - no background is used (set to "transparent").
18
+ * - `string` - should be a valid CSS color.
19
+ *
20
+ * @default undefined
21
+ */
22
+ canvasBackgroundColor?: string | false;
23
+ /**
24
+ * Canvas padding in pixels. Affected by `scale`.
25
+ *
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
46
+ */
47
+ padding?: number;
48
+ /**
49
+ * Makes sure the canvas content fits into a frame of width/height no larger
50
+ * than this value, while maintaining the aspect ratio.
51
+ *
52
+ * Final dimensions can get smaller/larger if used in conjunction with
53
+ * `scale`.
54
+ */
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;
66
+ /**
67
+ * Width of the frame. Supply `x` or `y` if you want to ofsset the canvas
68
+ * content.
69
+ *
70
+ * If `width` omitted but `height` supplied, `width` is calculated from the
71
+ * the content's bounding box to preserve the aspect ratio.
72
+ *
73
+ * Defaults to the content bounding box width when both `width` and `height`
74
+ * are omitted.
75
+ */
76
+ width?: number;
77
+ /**
78
+ * Height of the frame.
79
+ *
80
+ * If `height` omitted but `width` supplied, `height` is calculated from the
81
+ * content's bounding box to preserve the aspect ratio.
82
+ *
83
+ * Defaults to the content bounding box height when both `width` and `height`
84
+ * are omitted.
85
+ */
86
+ height?: number;
87
+ /**
88
+ * Left canvas offset. By default the coordinate is relative to the canvas.
89
+ * You can switch to content coordinates by setting `origin` to `content`.
90
+ *
91
+ * Defaults to the `x` postion of the content bounding box.
92
+ */
93
+ x?: number;
94
+ /**
95
+ * Top canvas offset. By default the coordinate is relative to the canvas.
96
+ * You can switch to content coordinates by setting `origin` to `content`.
97
+ *
98
+ * Defaults to the `y` postion of the content bounding box.
99
+ */
100
+ y?: number;
101
+ /**
102
+ * Indicates the coordinate system of the `x` and `y` values.
103
+ *
104
+ * - `canvas` - `x` and `y` are relative to the canvas [0, 0] position.
105
+ * - `content` - `x` and `y` are relative to the content bounding box.
106
+ *
107
+ * @default "canvas"
108
+ */
109
+ origin?: "canvas" | "content";
110
+ /**
111
+ * If dimensions specified and `x` and `y` are not specified, this indicates
112
+ * how the canvas should be scaled.
113
+ *
114
+ * Behavior aligns with the `object-fit` CSS property.
115
+ *
116
+ * - `none` - no scaling.
117
+ * - `contain` - scale to fit the frame. Includes `padding`.
118
+ * - `cover` - scale to fill the frame while maintaining aspect ratio. If
119
+ * content overflows, it will be cropped.
120
+ *
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.
126
+ */
127
+ fit?: "none" | "contain" | "cover";
128
+ /**
129
+ * When either `x` or `y` are not specified, indicates how the canvas should
130
+ * be aligned on the respective axis.
131
+ *
132
+ * - `none` - canvas aligned to top left.
133
+ * - `center` - canvas is centered on the axis which is not specified
134
+ * (or both).
135
+ *
136
+ * If `maxWidthOrHeight` or `widthOrHeight` is set, `position` is ignored.
137
+ *
138
+ * @default "center"
139
+ */
140
+ position?: "center" | "topLeft";
141
+ /**
142
+ * A multiplier to increase/decrease the frame dimensions
143
+ * (content resolution).
144
+ *
145
+ * For example, if your canvas is 300x150 and you set scale to 2, the
146
+ * resulting size will be 600x300.
147
+ *
148
+ * @default 1
149
+ */
150
+ scale?: number;
151
+ /**
152
+ * If you need to suply your own canvas, e.g. in test environments or in
153
+ * Node.js.
154
+ *
155
+ * Do not set `canvas.width/height` or modify the canvas context as that's
156
+ * handled by Excalidraw.
157
+ *
158
+ * Defaults to `document.createElement("canvas")`.
159
+ */
160
+ createCanvas?: () => HTMLCanvasElement;
161
+ /**
162
+ * If you want to supply `width`/`height` dynamically (or derive from the
163
+ * content bounding box), you can use this function.
164
+ *
165
+ * Ignored if `maxWidthOrHeight`, `width`, or `height` is set.
166
+ */
167
+ getDimensions?: (width: number, height: number) => {
168
+ width: number;
169
+ height: number;
170
+ scale?: number;
171
+ };
172
+ };
173
+ /**
174
+ * This API is usually used as a precursor to searializing to Blob or PNG,
175
+ * but can also be used to create a canvas for other purposes.
176
+ */
177
+ export declare const exportToCanvas: ({ data, config, }: {
178
+ data: ExportToCanvasData;
179
+ config?: ExportToCanvasConfig | undefined;
11
180
  }) => Promise<HTMLCanvasElement>;
12
181
  export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElement[], appState: {
13
182
  exportBackground: boolean;
@@ -16,5 +185,9 @@ export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElemen
16
185
  viewBackgroundColor: string;
17
186
  exportWithDarkMode?: boolean;
18
187
  exportEmbedScene?: boolean;
19
- }, files: BinaryFiles | null) => Promise<SVGSVGElement>;
20
- export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], exportPadding: 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, canChangeSharpness, getElementAtPosition, getTextBindableContainerAtPosition, 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,49 +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
- viewBackgroundColor: AppState["viewBackgroundColor"] | null;
8
- zoom: AppState["zoom"];
9
- shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
10
- theme: AppState["theme"];
13
+ canvasBackgroundColor: string | null;
14
+ };
15
+ export type InteractiveCanvasRenderConfig = {
16
+ remoteSelectedElementIds: {
17
+ [elementId: string]: string[];
18
+ };
11
19
  remotePointerViewportCoords: {
12
20
  [id: string]: {
13
21
  x: number;
14
22
  y: number;
23
+ id: string;
15
24
  };
16
25
  };
17
- remotePointerButton?: {
18
- [id: string]: string | undefined;
19
- };
20
- remoteSelectedElementIds: {
21
- [elementId: string]: string[];
26
+ remotePointerUserStates: {
27
+ [id: string]: string;
22
28
  };
23
29
  remotePointerUsernames: {
24
30
  [id: string]: string;
25
31
  };
26
- remotePointerUserStates: {
27
- [id: string]: string;
32
+ remotePointerButton?: {
33
+ [id: string]: string | undefined;
28
34
  };
29
- imageCache: AppClassProperties["imageCache"];
30
- renderScrollbars?: boolean;
31
- renderSelection?: boolean;
32
- renderGrid?: boolean;
33
- /** when exporting the behavior is slightly different (e.g. we can't use
34
- CSS filters), and we disable render optimizations for best output */
35
- isExporting: boolean;
36
35
  selectionColor?: string;
36
+ renderScrollbars?: boolean;
37
+ };
38
+ export type RenderInteractiveSceneCallback = {
39
+ atLeastOneVisibleElement: boolean;
40
+ elements: readonly NonDeletedExcalidrawElement[];
41
+ scrollBars?: ScrollBars;
37
42
  };
38
- 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 = {
39
70
  scrollX: number;
40
71
  scrollY: number;
41
72
  };
42
73
  export interface Scene {
43
74
  elements: ExcalidrawTextElement[];
44
75
  }
45
- export declare type ExportType = "png" | "clipboard" | "clipboard-svg" | "backend" | "svg";
46
- export declare type ScrollBars = {
76
+ export type ExportType = "png" | "clipboard" | "clipboard-svg" | "backend" | "svg";
77
+ export type ScrollBars = {
47
78
  horizontal: {
48
79
  x: number;
49
80
  y: number;
@@ -57,3 +88,16 @@ export declare type ScrollBars = {
57
88
  height: number;
58
89
  } | null;
59
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
+ };