@dwelle/excalidraw 0.4.0-d8d86cf → 0.4.0-e03b600

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 (203) hide show
  1. package/CHANGELOG.md +458 -0
  2. package/README.md +18 -1422
  3. package/dist/excalidraw.development.js +1882 -498
  4. package/dist/excalidraw.production.min.js +1 -1
  5. package/dist/excalidraw.production.min.js.LICENSE.txt +20 -0
  6. package/package.json +3 -3
  7. package/types/actions/actionAddToLibrary.d.ts +68 -34
  8. package/types/actions/actionAlign.d.ts +12 -18
  9. package/types/actions/actionBoundText.d.ts +158 -19
  10. package/types/actions/actionCanvas.d.ts +544 -118
  11. package/types/actions/actionClipboard.d.ts +132 -59
  12. package/types/actions/actionDeleteSelected.d.ts +72 -41
  13. package/types/actions/actionDistribute.d.ts +2 -6
  14. package/types/actions/actionDuplicateSelection.d.ts +2 -4
  15. package/types/actions/actionElementLock.d.ts +254 -0
  16. package/types/actions/actionExport.d.ts +215 -131
  17. package/types/actions/actionFinalize.d.ts +47 -27
  18. package/types/actions/actionFlip.d.ts +2 -4
  19. package/types/actions/actionFrame.d.ts +397 -0
  20. package/types/actions/actionGroup.d.ts +6 -10
  21. package/types/actions/actionHistory.d.ts +1 -1
  22. package/types/actions/actionLinearEditor.d.ts +25 -13
  23. package/types/actions/actionMenu.d.ts +73 -46
  24. package/types/actions/actionNavigate.d.ts +2 -3
  25. package/types/actions/actionProperties.d.ts +315 -198
  26. package/types/actions/actionStyles.d.ts +23 -12
  27. package/types/actions/actionToggleGridMode.d.ts +25 -12
  28. package/types/actions/actionToggleStats.d.ts +24 -12
  29. package/types/actions/actionToggleViewMode.d.ts +25 -12
  30. package/types/actions/actionToggleZenMode.d.ts +25 -12
  31. package/types/actions/actionZindex.d.ts +8 -16
  32. package/types/actions/index.d.ts +1 -1
  33. package/types/actions/manager.d.ts +3 -2
  34. package/types/actions/shortcuts.d.ts +2 -1
  35. package/types/actions/types.d.ts +13 -11
  36. package/types/appState.d.ts +16 -12
  37. package/types/charts.d.ts +2 -2
  38. package/types/clients.d.ts +5 -6
  39. package/types/clipboard.d.ts +2 -2
  40. package/types/colors.d.ts +60 -5
  41. package/types/components/Actions.d.ts +5 -5
  42. package/types/components/ActiveConfirmDialog.d.ts +4 -0
  43. package/types/components/App.d.ts +58 -68
  44. package/types/components/Avatar.d.ts +1 -2
  45. package/types/components/BraveMeasureTextError.d.ts +2 -0
  46. package/types/components/Button.d.ts +17 -0
  47. package/types/components/ButtonIconSelect.d.ts +11 -3
  48. package/types/components/Card.d.ts +7 -0
  49. package/types/components/ColorPicker/ColorInput.d.ts +7 -0
  50. package/types/components/ColorPicker/ColorPicker.d.ts +19 -0
  51. package/types/components/ColorPicker/CustomColorList.d.ts +8 -0
  52. package/types/components/ColorPicker/HotkeyLabel.d.ts +8 -0
  53. package/types/components/ColorPicker/Picker.d.ts +18 -0
  54. package/types/components/ColorPicker/PickerColorList.d.ts +10 -0
  55. package/types/components/ColorPicker/PickerHeading.d.ts +5 -0
  56. package/types/components/ColorPicker/ShadeList.d.ts +8 -0
  57. package/types/components/ColorPicker/TopPicks.d.ts +9 -0
  58. package/types/components/ColorPicker/colorPickerUtils.d.ts +21 -0
  59. package/types/components/ColorPicker/keyboardNavHandlers.d.ts +21 -0
  60. package/types/components/ContextMenu.d.ts +9 -22
  61. package/types/components/DefaultSidebar.d.ts +30 -0
  62. package/types/components/Dialog.d.ts +3 -4
  63. package/types/components/ErrorDialog.d.ts +3 -2
  64. package/types/components/EyeDropper.d.ts +18 -0
  65. package/types/components/FilledButton.d.ts +17 -0
  66. package/types/components/FixedSideContainer.d.ts +1 -1
  67. package/types/components/HandButton.d.ts +10 -0
  68. package/types/components/HelpButton.d.ts +1 -2
  69. package/types/components/HintViewer.d.ts +2 -2
  70. package/types/components/HomeButton.d.ts +1 -1
  71. package/types/components/ImageExportDialog.d.ts +8 -13
  72. package/types/components/Island.d.ts +1 -1
  73. package/types/components/JSONExportDialog.d.ts +6 -4
  74. package/types/components/LayerUI.d.ts +7 -15
  75. package/types/components/LibraryMenu.d.ts +13 -14
  76. package/types/components/LibraryMenuBrowseButton.d.ts +2 -2
  77. package/types/components/LibraryMenuControlButtons.d.ts +9 -0
  78. package/types/components/LibraryMenuHeaderContent.d.ts +11 -5
  79. package/types/components/LibraryMenuItems.d.ts +6 -7
  80. package/types/components/LibraryMenuSection.d.ts +22 -0
  81. package/types/components/LibraryUnit.d.ts +7 -3
  82. package/types/components/LockButton.d.ts +1 -2
  83. package/types/components/MobileMenu.d.ts +8 -11
  84. package/types/components/OverwriteConfirm/OverwriteConfirm.d.ts +17 -0
  85. package/types/components/OverwriteConfirm/OverwriteConfirmActions.d.ts +17 -0
  86. package/types/components/OverwriteConfirm/OverwriteConfirmState.d.ts +22 -0
  87. package/types/components/PasteChartDialog.d.ts +4 -5
  88. package/types/components/PenModeButton.d.ts +1 -1
  89. package/types/components/Popover.d.ts +1 -1
  90. package/types/components/ProjectName.d.ts +2 -1
  91. package/types/components/PublishLibrary.d.ts +2 -2
  92. package/types/components/RadioGroup.d.ts +12 -0
  93. package/types/components/Sidebar/Sidebar.d.ts +66 -63
  94. package/types/components/Sidebar/SidebarHeader.d.ts +6 -19
  95. package/types/components/Sidebar/SidebarTab.d.ts +9 -0
  96. package/types/components/Sidebar/SidebarTabTrigger.d.ts +10 -0
  97. package/types/components/Sidebar/SidebarTabTriggers.d.ts +7 -0
  98. package/types/components/Sidebar/SidebarTabs.d.ts +7 -0
  99. package/types/components/Sidebar/SidebarTrigger.d.ts +6 -0
  100. package/types/components/Sidebar/common.d.ts +24 -7
  101. package/types/components/Spinner.d.ts +2 -1
  102. package/types/components/Stack.d.ts +4 -3
  103. package/types/components/Stats.d.ts +3 -3
  104. package/types/components/Switch.d.ts +9 -0
  105. package/types/components/ToolButton.d.ts +6 -5
  106. package/types/components/Tooltip.d.ts +1 -1
  107. package/types/components/Trans.d.ts +8 -0
  108. package/types/components/UserList.d.ts +0 -2
  109. package/types/components/dropdownMenu/DropdownMenu.d.ts +67 -0
  110. package/types/components/dropdownMenu/DropdownMenuContent.d.ts +15 -0
  111. package/types/components/dropdownMenu/DropdownMenuGroup.d.ts +11 -0
  112. package/types/components/dropdownMenu/DropdownMenuItem.d.ts +12 -0
  113. package/types/components/dropdownMenu/DropdownMenuItemContent.d.ts +6 -0
  114. package/types/components/dropdownMenu/DropdownMenuItemCustom.d.ts +6 -0
  115. package/types/components/dropdownMenu/DropdownMenuItemLink.d.ts +13 -0
  116. package/types/components/dropdownMenu/DropdownMenuSeparator.d.ts +5 -0
  117. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +11 -0
  118. package/types/components/dropdownMenu/common.d.ts +6 -0
  119. package/types/components/dropdownMenu/dropdownMenuUtils.d.ts +3 -0
  120. package/types/components/footer/Footer.d.ts +12 -0
  121. package/types/components/footer/FooterCenter.d.ts +8 -0
  122. package/types/components/hoc/withInternalFallback.d.ts +4 -0
  123. package/types/components/icons.d.ts +14 -2
  124. package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +10 -0
  125. package/types/components/main-menu/DefaultItems.d.ts +47 -0
  126. package/types/components/main-menu/MainMenu.d.ts +61 -0
  127. package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +58 -0
  128. package/types/components/welcome-screen/WelcomeScreen.Hints.d.ts +19 -0
  129. package/types/components/welcome-screen/WelcomeScreen.d.ts +85 -0
  130. package/types/constants.d.ts +73 -16
  131. package/types/context/tunnels.d.ts +19 -0
  132. package/types/context/ui-appState.d.ts +4 -0
  133. package/types/data/blob.d.ts +3 -2
  134. package/types/data/encode.d.ts +1 -1
  135. package/types/data/filesystem.d.ts +2 -1
  136. package/types/data/index.d.ts +1 -1
  137. package/types/data/library.d.ts +3 -45
  138. package/types/data/restore.d.ts +10 -4
  139. package/types/data/types.d.ts +3 -5
  140. package/types/element/Hyperlink.d.ts +27 -18
  141. package/types/element/binding.d.ts +3 -3
  142. package/types/element/bounds.d.ts +32 -7
  143. package/types/element/collision.d.ts +7 -7
  144. package/types/element/dragElements.d.ts +2 -1
  145. package/types/element/image.d.ts +11 -1
  146. package/types/element/index.d.ts +3 -2
  147. package/types/element/linearElementEditor.d.ts +24 -13
  148. package/types/element/mutateElement.d.ts +2 -1
  149. package/types/element/newElement.d.ts +37 -11
  150. package/types/element/resizeElements.d.ts +1 -0
  151. package/types/element/showSelectedShapeActions.d.ts +2 -2
  152. package/types/element/sortElements.d.ts +2 -0
  153. package/types/element/textElement.d.ts +40 -5
  154. package/types/element/textWysiwyg.d.ts +6 -1
  155. package/types/element/transformHandles.d.ts +12 -5
  156. package/types/element/typeChecks.d.ts +12 -2
  157. package/types/element/types.d.ts +53 -36
  158. package/types/emitter.d.ts +1 -1
  159. package/types/errors.d.ts +1 -1
  160. package/types/frame.d.ts +40 -0
  161. package/types/ga.d.ts +5 -5
  162. package/types/groups.d.ts +4 -0
  163. package/types/hooks/useCreatePortalContainer.d.ts +4 -0
  164. package/types/hooks/useLibraryItemSvg.d.ts +11 -0
  165. package/types/hooks/useOutsideClick.d.ts +19 -1
  166. package/types/hooks/useScrollPosition.d.ts +2 -0
  167. package/types/hooks/useTransition.d.ts +2 -0
  168. package/types/i18n.d.ts +7 -1
  169. package/types/jotai.d.ts +20 -108
  170. package/types/keys.d.ts +4 -4
  171. package/types/math.d.ts +4 -1
  172. package/types/packages/excalidraw/example/App.d.ts +7 -1
  173. package/types/packages/excalidraw/example/CustomFooter.d.ts +5 -0
  174. package/types/packages/excalidraw/example/MobileFooter.d.ts +5 -0
  175. package/types/packages/excalidraw/example/initialData.d.ts +6 -0
  176. package/types/packages/excalidraw/index.d.ts +17 -3
  177. package/types/packages/utils.d.ts +26 -25
  178. package/types/renderer/renderElement.d.ts +7 -5
  179. package/types/renderer/renderScene.d.ts +13 -6
  180. package/types/renderer/roundRect.d.ts +1 -1
  181. package/types/scene/Scene.d.ts +12 -5
  182. package/types/scene/comparisons.d.ts +1 -1
  183. package/types/scene/export.d.ts +157 -10
  184. package/types/scene/index.d.ts +1 -1
  185. package/types/scene/selection.d.ts +15 -5
  186. package/types/scene/types.d.ts +13 -5
  187. package/types/types.d.ts +126 -77
  188. package/types/utility-types.d.ts +22 -0
  189. package/types/utils.d.ts +30 -9
  190. package/types/zindex.d.ts +4 -4
  191. package/types/actions/actionToggleLock.d.ts +0 -116
  192. package/types/components/ActiveFile.d.ts +0 -7
  193. package/types/components/ClearCanvas.d.ts +0 -4
  194. package/types/components/CollabButton.d.ts +0 -6
  195. package/types/components/ColorPicker.d.ts +0 -14
  196. package/types/components/Footer.d.ts +0 -10
  197. package/types/components/LibraryButton.d.ts +0 -8
  198. package/types/components/MenuItem.d.ts +0 -11
  199. package/types/components/MenuUtils.d.ts +0 -1
  200. package/types/components/SingleLibraryItem.d.ts +0 -10
  201. package/types/components/WelcomeScreen.d.ts +0 -10
  202. package/types/components/WelcomeScreenDecor.d.ts +0 -6
  203. package/types/components/hoc/withUpstreamOverride.d.ts +0 -10
@@ -2,18 +2,32 @@ import React from "react";
2
2
  import "../../css/app.scss";
3
3
  import "../../css/styles.scss";
4
4
  import { ExcalidrawAPIRefValue, ExcalidrawProps } from "../../types";
5
- declare type PublicExcalidrawProps = Omit<ExcalidrawProps, "forwardedRef">;
5
+ import Footer from "../../components/footer/FooterCenter";
6
+ import MainMenu from "../../components/main-menu/MainMenu";
7
+ import WelcomeScreen from "../../components/welcome-screen/WelcomeScreen";
8
+ import LiveCollaborationTrigger from "../../components/live-collaboration/LiveCollaborationTrigger";
9
+ type PublicExcalidrawProps = Omit<ExcalidrawProps, "forwardedRef">;
6
10
  export declare const Excalidraw: React.MemoExoticComponent<React.ForwardRefExoticComponent<PublicExcalidrawProps & React.RefAttributes<ExcalidrawAPIRefValue>>>;
7
11
  export { getSceneVersion, isInvisiblySmallElement, getNonDeletedElements, } from "../../element";
8
- export { defaultLang, languages } from "../../i18n";
12
+ export { defaultLang, useI18n, languages } from "../../i18n";
9
13
  export { restore, restoreAppState, restoreElements, restoreLibraryItems, } from "../../data/restore";
10
- export { exportToCanvas, exportToBlob, exportToSvg, serializeAsJSON, serializeLibraryAsJSON, loadLibraryFromBlob, loadFromBlob, loadSceneOrLibraryFromBlob, getFreeDrawSvgPath, exportToClipboard, mergeLibraryItems, } from "../../packages/utils";
14
+ export { exportToBlob, exportToSvg, serializeAsJSON, serializeLibraryAsJSON, loadLibraryFromBlob, loadFromBlob, loadSceneOrLibraryFromBlob, getFreeDrawSvgPath, exportToClipboard, mergeLibraryItems, } from "../../packages/utils";
11
15
  export { isLinearElement } from "../../element/typeChecks";
12
16
  export { FONT_FAMILY, THEME, MIME_TYPES } from "../../constants";
13
17
  export { mutateElement, newElementWith, bumpVersion, } from "../../element/mutateElement";
14
18
  export { parseLibraryTokensFromUrl, useHandleLibrary, } from "../../data/library";
15
19
  export { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, } from "../../utils";
16
20
  export { Sidebar } from "../../components/Sidebar/Sidebar";
21
+ export { Button } from "../../components/Button";
22
+ export { Footer };
23
+ export { MainMenu };
24
+ export { useDevice } from "../../components/App";
25
+ export { WelcomeScreen };
26
+ export { LiveCollaborationTrigger };
27
+ export { DefaultSidebar } from "../../components/DefaultSidebar";
17
28
  export { getDefaultAppState, cleanAppStateForExport, clearAppStateForLocalStorage, } from "../../appState";
18
29
  export { jotaiScope, jotaiStore } from "../../jotai";
19
30
  export { libraryItemsAtom } from "../../data/library";
31
+ export { exportToCanvas } from "../../scene/export";
32
+ export * as icons from "../../components/icons";
33
+ export * as actions from "../../actions/index";
@@ -1,34 +1,35 @@
1
- import { AppState, BinaryFiles } from "../types";
2
- import { ExcalidrawElement, NonDeleted } from "../element/types";
1
+ import { ExportToCanvasConfig, ExportToCanvasData } from "../scene/export";
3
2
  import { MIME_TYPES } from "../constants";
4
3
  export { MIME_TYPES };
5
- declare type ExportOpts = {
6
- elements: readonly NonDeleted<ExcalidrawElement>[];
7
- appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
8
- files: BinaryFiles | null;
9
- maxWidthOrHeight?: number;
10
- getDimensions?: (width: number, height: number) => {
11
- width: number;
12
- height: number;
13
- scale?: number;
14
- };
15
- };
16
- export declare const exportToCanvas: ({ elements, appState, files, maxWidthOrHeight, getDimensions, exportPadding, }: ExportOpts & {
17
- exportPadding?: number | undefined;
18
- }) => Promise<HTMLCanvasElement>;
19
- export declare const exportToBlob: (opts: ExportOpts & {
4
+ type ExportToBlobConfig = ExportToCanvasConfig & {
20
5
  mimeType?: string;
21
6
  quality?: number;
22
- exportPadding?: number;
7
+ };
8
+ type ExportToSvgConfig = Pick<ExportToCanvasConfig, "canvasBackgroundColor" | "padding" | "theme">;
9
+ export declare const exportToBlob: ({ data, config, }: {
10
+ data: ExportToCanvasData;
11
+ config?: ExportToBlobConfig | undefined;
23
12
  }) => Promise<Blob>;
24
- export declare const exportToSvg: ({ elements, appState, files, exportPadding, }: Omit<ExportOpts, "getDimensions"> & {
25
- exportPadding?: number | undefined;
13
+ export declare const exportToSvg: ({ data, config, }: {
14
+ data: ExportToCanvasData;
15
+ config?: ExportToSvgConfig | undefined;
26
16
  }) => Promise<SVGSVGElement>;
27
- export declare const exportToClipboard: (opts: ExportOpts & {
28
- mimeType?: string;
29
- quality?: number;
30
- type: "png" | "svg" | "json";
31
- }) => Promise<void>;
17
+ export declare const exportToCanvas: ({ data, config, }: {
18
+ data: ExportToCanvasData;
19
+ config?: ExportToCanvasConfig | undefined;
20
+ }) => Promise<HTMLCanvasElement>;
21
+ export declare const exportToClipboard: ({ type, data, config, }: {
22
+ data: ExportToCanvasData;
23
+ } & ({
24
+ type: "png";
25
+ config?: ExportToBlobConfig | undefined;
26
+ } | {
27
+ type: "svg";
28
+ config?: ExportToSvgConfig | undefined;
29
+ } | {
30
+ type: "json";
31
+ config?: undefined;
32
+ })) => Promise<void>;
32
33
  export { serializeAsJSON, serializeLibraryAsJSON } from "../data/json";
33
34
  export { loadFromBlob, loadSceneOrLibraryFromBlob, loadLibraryFromBlob, } from "../data/blob";
34
35
  export { getFreeDrawSvgPath } from "../renderer/renderElement";
@@ -3,19 +3,21 @@ import { RoughCanvas } from "roughjs/bin/canvas";
3
3
  import { Drawable, Options } from "roughjs/bin/core";
4
4
  import { RoughSVG } from "roughjs/bin/svg";
5
5
  import { RenderConfig } from "../scene/types";
6
- import { AppState, BinaryFiles, Zoom } from "../types";
6
+ import { AppState, BinaryFiles } from "../types";
7
7
  export interface ExcalidrawElementWithCanvas {
8
8
  element: ExcalidrawElement | ExcalidrawTextElement;
9
9
  canvas: HTMLCanvasElement;
10
10
  theme: RenderConfig["theme"];
11
- canvasZoom: Zoom["value"];
11
+ scale: number;
12
+ zoomValue: RenderConfig["zoom"]["value"];
12
13
  canvasOffsetX: number;
13
14
  canvasOffsetY: number;
14
15
  boundTextElementVersion: number | null;
16
+ containingFrameOpacity: number;
15
17
  }
16
18
  export declare const DEFAULT_LINK_SIZE = 14;
17
- declare type ElementShape = Drawable | Drawable[] | null;
18
- declare type ElementShapes = {
19
+ type ElementShape = Drawable | Drawable[] | null;
20
+ type ElementShapes = {
19
21
  freedraw: Drawable | null;
20
22
  arrow: Drawable[];
21
23
  line: Drawable[];
@@ -28,7 +30,7 @@ export declare const invalidateShapeForElement: (element: ExcalidrawElement) =>
28
30
  export declare const clearRenderCache: () => void;
29
31
  export declare const generateRoughOptions: (element: ExcalidrawElement, continuousPath?: boolean) => Options;
30
32
  export declare const renderElement: (element: NonDeletedExcalidrawElement, rc: RoughCanvas, context: CanvasRenderingContext2D, renderConfig: RenderConfig, appState: AppState) => void;
31
- export declare const renderElementToSvg: (element: NonDeletedExcalidrawElement, rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, offsetX: number, offsetY: number, exportWithDarkMode?: boolean) => void;
33
+ export declare const renderElementToSvg: (element: NonDeletedExcalidrawElement, rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, offsetX: number, offsetY: number, exportWithDarkMode?: boolean, exportingFrameId?: string | null) => void;
32
34
  export declare let pathsCache: WeakMap<ExcalidrawFreeDrawElement, Path2D>;
33
35
  export declare function generateFreeDrawShape(element: ExcalidrawFreeDrawElement): Path2D;
34
36
  export declare function getFreeDrawPath2D(element: ExcalidrawFreeDrawElement): Path2D | undefined;
@@ -1,13 +1,13 @@
1
1
  import { RoughCanvas } from "roughjs/bin/canvas";
2
2
  import { RoughSVG } from "roughjs/bin/svg";
3
- import { AppState, BinaryFiles } from "../types";
4
- import { NonDeletedExcalidrawElement } from "../element/types";
3
+ import { AppState, BinaryFiles, Zoom } from "../types";
4
+ import { ExcalidrawElement, NonDeletedExcalidrawElement } from "../element/types";
5
5
  import { RenderConfig } from "../scene/types";
6
+ import "canvas-roundrect-polyfill";
6
7
  export declare const DEFAULT_SPACING = 2;
7
- export declare const _renderScene: ({ elements, appState, scale, rc, canvas, renderConfig, }: {
8
+ export declare const _renderScene: ({ elements, appState, rc, canvas, renderConfig, }: {
8
9
  elements: readonly NonDeletedExcalidrawElement[];
9
10
  appState: AppState;
10
- scale: number;
11
11
  rc: RoughCanvas;
12
12
  canvas: HTMLCanvasElement;
13
13
  renderConfig: RenderConfig;
@@ -22,7 +22,6 @@ export declare const _renderScene: ({ elements, appState, scale, rc, canvas, ren
22
22
  export declare const renderScene: <T extends boolean = false>(config: {
23
23
  elements: readonly NonDeletedExcalidrawElement[];
24
24
  appState: AppState;
25
- scale: number;
26
25
  rc: RoughCanvas;
27
26
  canvas: HTMLCanvasElement;
28
27
  renderConfig: RenderConfig;
@@ -34,8 +33,16 @@ export declare const renderScene: <T extends boolean = false>(config: {
34
33
  atLeastOneVisibleElement: boolean;
35
34
  scrollBars: import("../scene/types").ScrollBars | undefined;
36
35
  };
37
- export declare const renderSceneToSvg: (elements: readonly NonDeletedExcalidrawElement[], rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, { offsetX, offsetY, exportWithDarkMode, }?: {
36
+ export declare const isVisibleElement: (element: ExcalidrawElement, canvasWidth: number, canvasHeight: number, viewTransformations: {
37
+ zoom: Zoom;
38
+ offsetLeft: number;
39
+ offsetTop: number;
40
+ scrollX: number;
41
+ scrollY: number;
42
+ }) => boolean;
43
+ export declare const renderSceneToSvg: (elements: readonly NonDeletedExcalidrawElement[], rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, { offsetX, offsetY, exportWithDarkMode, exportingFrameId, }?: {
38
44
  offsetX?: number | undefined;
39
45
  offsetY?: number | undefined;
40
46
  exportWithDarkMode?: boolean | undefined;
47
+ exportingFrameId?: string | null | undefined;
41
48
  }) => void;
@@ -8,4 +8,4 @@
8
8
  * @param {Number} height The height of the rectangle
9
9
  * @param {Number} radius The corner radius
10
10
  */
11
- export declare const roundRect: (context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number) => void;
11
+ export declare const roundRect: (context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number, strokeColor?: string) => void;
@@ -1,9 +1,10 @@
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
+ type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
4
+ type ElementKey = ExcalidrawElement | ElementIdKey;
5
+ type SceneStateCallback = () => void;
6
+ type SceneStateCallbackRemover = () => void;
7
+ export type ExcalidrawElementsIncludingDeleted = readonly ExcalidrawElement[];
7
8
  declare class Scene {
8
9
  private static sceneMapByElement;
9
10
  private static sceneMapById;
@@ -12,9 +13,13 @@ declare class Scene {
12
13
  private callbacks;
13
14
  private nonDeletedElements;
14
15
  private elements;
16
+ private nonDeletedFrames;
17
+ private frames;
15
18
  private elementsMap;
16
19
  getElementsIncludingDeleted(): readonly ExcalidrawElement[];
17
20
  getNonDeletedElements(): readonly NonDeletedExcalidrawElement[];
21
+ getFramesIncludingDeleted(): readonly ExcalidrawFrameElement[];
22
+ getNonDeletedFrames(): readonly NonDeleted<ExcalidrawFrameElement>[];
18
23
  getElement<T extends ExcalidrawElement>(id: T["id"]): T | null;
19
24
  getNonDeletedElement(id: ExcalidrawElement["id"]): NonDeleted<ExcalidrawElement> | null;
20
25
  /**
@@ -35,6 +40,8 @@ declare class Scene {
35
40
  addCallback(cb: SceneStateCallback): SceneStateCallbackRemover;
36
41
  destroy(): void;
37
42
  insertElementAtIndex(element: ExcalidrawElement, index: number): void;
43
+ insertElementsAtIndex(elements: ExcalidrawElement[], index: number): void;
44
+ addNewElement: (element: ExcalidrawElement) => void;
38
45
  getElementIndex(elementId: string): number;
39
46
  }
40
47
  export default Scene;
@@ -3,7 +3,7 @@ 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;
6
+ export declare const canChangeRoundness: (type: string) => boolean;
7
7
  export declare const hasText: (type: string) => boolean;
8
8
  export declare const canHaveArrowheads: (type: string) => boolean;
9
9
  export declare const getElementAtPosition: (elements: readonly NonDeletedExcalidrawElement[], isAtPositionFn: (element: NonDeletedExcalidrawElement) => boolean) => NonDeletedExcalidrawElement | null;
@@ -1,13 +1,157 @@
1
- import { NonDeletedExcalidrawElement } from "../element/types";
1
+ import { NonDeletedExcalidrawElement, Theme } from "../element/types";
2
2
  import { AppState, BinaryFiles } from "../types";
3
+ import { serializeAsJSON } from "../data/json";
3
4
  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;
5
+ export type ExportToCanvasData = {
6
+ elements: readonly NonDeletedExcalidrawElement[];
7
+ appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
8
+ files: BinaryFiles | null;
9
+ };
10
+ export type ExportToCanvasConfig = {
11
+ theme?: Theme;
12
+ /**
13
+ * Canvas background. Valid values are:
14
+ *
15
+ * - `undefined` - the background of "appState.viewBackgroundColor" is used.
16
+ * - `false` - no background is used (set to "transparent").
17
+ * - `string` - should be a valid CSS color.
18
+ *
19
+ * @default undefined
20
+ */
21
+ canvasBackgroundColor?: string | false;
22
+ /**
23
+ * Canvas padding in pixels. Affected by scale. Ignored if `fit` is set to
24
+ * `cover`.
25
+ *
26
+ * @default 10
27
+ */
28
+ padding?: number;
29
+ /**
30
+ * Makes sure the canvas content fits into a frame of width/height no larger
31
+ * than this value, while maintaining the aspect ratio.
32
+ *
33
+ * Final dimensions can get smaller/larger if used in conjunction with
34
+ * `scale`.
35
+ */
36
+ maxWidthOrHeight?: number;
37
+ /**
38
+ * Scale the canvas content to be excatly this many pixels wide/tall.
39
+ *
40
+ * Cannot be used in conjunction with `maxWidthOrHeight`.
41
+ *
42
+ * Final dimensions can get smaller/larger if used in conjunction with
43
+ * `scale`.
44
+ */
45
+ widthOrHeight?: number;
46
+ /**
47
+ * Width of the frame. Supply `x` or `y` if you want to ofsset the canvas
48
+ * content.
49
+ *
50
+ * If `width` omitted but `height` supplied, `width` is calculated from the
51
+ * the content's bounding box to preserve the aspect ratio.
52
+ *
53
+ * Defaults to the content bounding box width when both `width` and `height`
54
+ * are omitted.
55
+ */
56
+ width?: number;
57
+ /**
58
+ * Height of the frame.
59
+ *
60
+ * If `height` omitted but `width` supplied, `height` is calculated from the
61
+ * content's bounding box to preserve the aspect ratio.
62
+ *
63
+ * Defaults to the content bounding box height when both `width` and `height`
64
+ * are omitted.
65
+ */
66
+ height?: number;
67
+ /**
68
+ * Left canvas offset. By default the coordinate is relative to the canvas.
69
+ * You can switch to content coordinates by setting `origin` to `content`.
70
+ *
71
+ * Defaults to the `x` postion of the content bounding box.
72
+ */
73
+ x?: number;
74
+ /**
75
+ * Top canvas offset. By default the coordinate is relative to the canvas.
76
+ * You can switch to content coordinates by setting `origin` to `content`.
77
+ *
78
+ * Defaults to the `y` postion of the content bounding box.
79
+ */
80
+ y?: number;
81
+ /**
82
+ * Indicates the coordinate system of the `x` and `y` values.
83
+ *
84
+ * - `canvas` - `x` and `y` are relative to the canvas [0, 0] position.
85
+ * - `content` - `x` and `y` are relative to the content bounding box.
86
+ *
87
+ * @default "canvas"
88
+ */
89
+ origin?: "canvas" | "content";
90
+ /**
91
+ * If dimensions specified and `x` and `y` are not specified, this indicates
92
+ * how the canvas should be scaled.
93
+ *
94
+ * Behavior aligns with the `object-fit` CSS property.
95
+ *
96
+ * - `none` - no scaling.
97
+ * - `contain` - scale to fit the frame.
98
+ * - `cover` - scale to fill the frame while maintaining aspect ratio. If
99
+ * content overflows, it will be cropped.
100
+ *
101
+ * @default "contain" unless `x` or `y` are specified, in which case "none"
102
+ * is used (forced).
103
+ */
104
+ fit?: "none" | "contain" | "cover";
105
+ /**
106
+ * When either `x` or `y` are not specified, indicates how the canvas should
107
+ * be aligned on the respective axis.
108
+ *
109
+ * - `none` - canvas aligned to top left.
110
+ * - `center` - canvas is centered on the axis which is not specified
111
+ * (or both).
112
+ *
113
+ * @default "center"
114
+ */
115
+ position?: "center" | "none";
116
+ /**
117
+ * A multiplier to increase/decrease the frame dimensions
118
+ * (content resolution).
119
+ *
120
+ * For example, if your canvas is 300x150 and you set scale to 2, the
121
+ * resulting size will be 600x300.
122
+ *
123
+ * @default 1
124
+ */
125
+ scale?: number;
126
+ /**
127
+ * If you need to suply your own canvas, e.g. in test environments or in
128
+ * Node.js.
129
+ *
130
+ * Do not set `canvas.width/height` or modify the canvas context as that's
131
+ * handled by Excalidraw.
132
+ *
133
+ * Defaults to `document.createElement("canvas")`.
134
+ */
135
+ createCanvas?: () => HTMLCanvasElement;
136
+ /**
137
+ * If you want to supply `width`/`height` dynamically (or derive from the
138
+ * content bounding box), you can use this function.
139
+ *
140
+ * Ignored if `maxWidthOrHeight`, `width`, or `height` is set.
141
+ */
142
+ getDimensions?: (width: number, height: number) => {
143
+ width: number;
144
+ height: number;
145
+ scale?: number;
146
+ };
147
+ };
148
+ /**
149
+ * This API is usually used as a precursor to searializing to Blob or PNG,
150
+ * but can also be used to create a canvas for other purposes.
151
+ */
152
+ export declare const exportToCanvas: ({ data, config, }: {
153
+ data: ExportToCanvasData;
154
+ config?: ExportToCanvasConfig | undefined;
11
155
  }) => Promise<HTMLCanvasElement>;
12
156
  export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElement[], appState: {
13
157
  exportBackground: boolean;
@@ -16,5 +160,8 @@ export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElemen
16
160
  viewBackgroundColor: string;
17
161
  exportWithDarkMode?: boolean;
18
162
  exportEmbedScene?: boolean;
19
- }, files: BinaryFiles | null) => Promise<SVGSVGElement>;
20
- export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], exportPadding: number, scale: number) => [number, number];
163
+ renderFrame?: boolean;
164
+ }, files: BinaryFiles | null, opts?: {
165
+ serializeAsJSON?: () => string;
166
+ }) => Promise<SVGSVGElement>;
167
+ export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], padding: number, scale: number) => [number, number];
@@ -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, hasText, getElementsAtPosition, } from "./comparisons";
4
+ export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeRoundness, getElementAtPosition, hasText, getElementsAtPosition, } from "./comparisons";
5
5
  export { getNormalizedZoom } from "./zoom";
@@ -1,11 +1,21 @@
1
1
  import { ExcalidrawElement, NonDeletedExcalidrawElement } from "../element/types";
2
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;
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 isSomeElementSelected: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">) => boolean;
5
12
  /**
6
13
  * Returns common attribute (picked by `getAttribute` callback) of selected
7
14
  * elements. If elements don't share the same value, returns `null`.
8
15
  */
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[];
16
+ export declare const getCommonAttributeOfSelectedElements: <T>(elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">, getAttribute: (element: ExcalidrawElement) => T) => T | null;
17
+ export declare const getSelectedElements: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">, opts?: {
18
+ includeBoundTextElement?: boolean;
19
+ includeElementsInFrames?: boolean;
20
+ }) => ExcalidrawElement[];
21
+ export declare const getTargetElements: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds" | "editingElement">) => ExcalidrawElement[];
@@ -1,13 +1,21 @@
1
1
  import { ExcalidrawTextElement } from "../element/types";
2
2
  import { AppClassProperties, AppState } from "../types";
3
- export declare type RenderConfig = {
3
+ export type RenderConfig = {
4
4
  scrollX: AppState["scrollX"];
5
5
  scrollY: AppState["scrollY"];
6
6
  /** null indicates transparent bg */
7
- viewBackgroundColor: AppState["viewBackgroundColor"] | null;
7
+ canvasBackgroundColor: AppState["viewBackgroundColor"] | null;
8
8
  zoom: AppState["zoom"];
9
9
  shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
10
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;
11
19
  remotePointerViewportCoords: {
12
20
  [id: string]: {
13
21
  x: number;
@@ -35,15 +43,15 @@ export declare type RenderConfig = {
35
43
  isExporting: boolean;
36
44
  selectionColor?: string;
37
45
  };
38
- export declare type SceneScroll = {
46
+ export type SceneScroll = {
39
47
  scrollX: number;
40
48
  scrollY: number;
41
49
  };
42
50
  export interface Scene {
43
51
  elements: ExcalidrawTextElement[];
44
52
  }
45
- export declare type ExportType = "png" | "clipboard" | "clipboard-svg" | "backend" | "svg";
46
- export declare type ScrollBars = {
53
+ export type ExportType = "png" | "clipboard" | "clipboard-svg" | "backend" | "svg";
54
+ export type ScrollBars = {
47
55
  horizontal: {
48
56
  x: number;
49
57
  y: number;