@excalidraw/common 0.18.0-4ce38fb → 0.18.0-4ce8305

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 (82) hide show
  1. package/dist/dev/index.js +25 -17
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/src/utils.d.ts +7 -1
  5. package/dist/types/element/src/align.d.ts +4 -1
  6. package/dist/types/element/src/binding.d.ts +36 -0
  7. package/dist/types/element/src/bounds.d.ts +10 -2
  8. package/dist/types/element/src/collision.d.ts +7 -0
  9. package/dist/types/element/src/cropElement.d.ts +36 -4
  10. package/dist/types/element/src/delta.d.ts +7 -1
  11. package/dist/types/element/src/distribute.d.ts +4 -1
  12. package/dist/types/element/src/dragElements.d.ts +8 -3
  13. package/dist/types/element/src/elbowArrow.d.ts +5 -0
  14. package/dist/types/element/src/embeddable.d.ts +2 -1
  15. package/dist/types/element/src/groups.d.ts +1 -6
  16. package/dist/types/element/src/image.d.ts +5 -2
  17. package/dist/types/element/src/index.d.ts +1 -0
  18. package/dist/types/element/src/linearElementEditor.d.ts +4 -1
  19. package/dist/types/element/src/listMarker.d.ts +7 -2
  20. package/dist/types/element/src/newElement.d.ts +3 -1
  21. package/dist/types/element/src/renderElement.d.ts +10 -0
  22. package/dist/types/element/src/renderEnvironment.d.ts +66 -0
  23. package/dist/types/element/src/resizeElements.d.ts +15 -5
  24. package/dist/types/element/src/selection.d.ts +1 -7
  25. package/dist/types/element/src/shape.d.ts +2 -0
  26. package/dist/types/element/src/stickyNote.d.ts +8 -0
  27. package/dist/types/element/src/textElement.d.ts +3 -2
  28. package/dist/types/element/src/textMeasurements.d.ts +15 -11
  29. package/dist/types/element/src/textWrapping.d.ts +3 -2
  30. package/dist/types/element/src/transform.d.ts +5 -1
  31. package/dist/types/excalidraw/actions/actionBoundText.d.ts +46 -221
  32. package/dist/types/excalidraw/actions/actionCanvas.d.ts +2 -2
  33. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +4 -588
  34. package/dist/types/excalidraw/actions/actionExport.d.ts +2 -2
  35. package/dist/types/excalidraw/actions/actionFrame.d.ts +41 -525
  36. package/dist/types/excalidraw/actions/actionToggleWrap.d.ts +12 -0
  37. package/dist/types/excalidraw/actions/index.d.ts +1 -0
  38. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  39. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  40. package/dist/types/excalidraw/appState.d.ts +2 -2
  41. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -1
  42. package/dist/types/excalidraw/charts/charts.helpers.d.ts +6 -5
  43. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -1
  44. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -1
  45. package/dist/types/excalidraw/charts/index.d.ts +2 -1
  46. package/dist/types/excalidraw/components/App.d.ts +34 -20
  47. package/dist/types/excalidraw/components/App.host.d.ts +102 -0
  48. package/dist/types/excalidraw/components/App.modifiers.d.ts +38 -0
  49. package/dist/types/excalidraw/components/App.selection.d.ts +265 -0
  50. package/dist/types/excalidraw/components/App.selectionTool.d.ts +93 -0
  51. package/dist/types/excalidraw/components/App.viewport.d.ts +13 -3
  52. package/dist/types/excalidraw/components/App.wrap.d.ts +31 -0
  53. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -1
  54. package/dist/types/excalidraw/components/Stats/utils.d.ts +4 -2
  55. package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +2 -1
  56. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
  57. package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +5 -2
  58. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
  59. package/dist/types/excalidraw/components/TTDDialog/common.d.ts +4 -1
  60. package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +3 -2
  61. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +14 -1
  62. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +27 -1
  63. package/dist/types/excalidraw/components/Tooltip.d.ts +11 -1
  64. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +1 -1
  65. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +0 -1
  66. package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +3 -2
  67. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +13 -2
  68. package/dist/types/excalidraw/data/blob.d.ts +4 -4
  69. package/dist/types/excalidraw/data/index.d.ts +3 -3
  70. package/dist/types/excalidraw/data/json.d.ts +2 -2
  71. package/dist/types/excalidraw/fonts/Fonts.d.ts +9 -6
  72. package/dist/types/excalidraw/history.d.ts +10 -4
  73. package/dist/types/excalidraw/reactUtils.d.ts +1 -1
  74. package/dist/types/excalidraw/renderer/animation.d.ts +11 -4
  75. package/dist/types/excalidraw/renderer/staticScene.d.ts +11 -6
  76. package/dist/types/excalidraw/scene/Renderer.d.ts +1 -1
  77. package/dist/types/excalidraw/scene/export.d.ts +343 -20
  78. package/dist/types/excalidraw/scene/types.d.ts +23 -1
  79. package/dist/types/excalidraw/types.d.ts +49 -1
  80. package/dist/types/utils/src/index.d.ts +3 -1
  81. package/package.json +1 -1
  82. package/dist/types/utils/src/export.d.ts +0 -36
@@ -17,7 +17,7 @@ export type TopPicksDragState<T> = {
17
17
  slotSpan: number;
18
18
  } | null;
19
19
  export type TopPicksGhost = {
20
- /** the ghost's visual. Rendered into `document.body` — outside the
20
+ /** the ghost's visual. Rendered into the source's `document.body` — outside the
21
21
  * editor's CSS scope, so theme-dependent styling must be resolved from the
22
22
  * rendered DOM (computed styles) rather than CSS variables */
23
23
  content: HTMLElement;
@@ -31,6 +31,5 @@ type InteractiveCanvasProps = {
31
31
  onPointerDown: Exclude<DOMAttributes<HTMLCanvasElement>["onPointerDown"], undefined>;
32
32
  onDoubleClick: Exclude<DOMAttributes<HTMLCanvasElement>["onDoubleClick"], undefined>;
33
33
  };
34
- export declare const INTERACTIVE_SCENE_ANIMATION_KEY = "animateInteractiveScene";
35
34
  declare const _default: React.MemoExoticComponent<(props: InteractiveCanvasProps) => import("react/jsx-runtime").JSX.Element>;
36
35
  export default _default;
@@ -2,6 +2,7 @@ import type { Scene } from "@excalidraw/element";
2
2
  import type { ElementsMap, ExcalidrawEmbeddableElement, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
3
3
  import "./Hyperlink.scss";
4
4
  import type { AppState, ExcalidrawProps, UIAppState } from "../../types";
5
+ export type HyperlinkTooltipOwner = Record<string, unknown>;
5
6
  export declare const Hyperlink: ({ element, scene, setAppState, onLinkOpen, setToast, updateEmbedValidationStatus, }: {
6
7
  element: NonDeletedExcalidrawElement;
7
8
  scene: Scene;
@@ -15,5 +16,5 @@ export declare const Hyperlink: ({ element, scene, setAppState, onLinkOpen, setT
15
16
  updateEmbedValidationStatus: (element: ExcalidrawEmbeddableElement, status: boolean) => void;
16
17
  }) => import("react/jsx-runtime").JSX.Element | null;
17
18
  export declare const getContextMenuLabel: (elements: readonly NonDeletedExcalidrawElement[], appState: UIAppState) => "labels.link.editEmbed" | "labels.link.edit" | "labels.link.create";
18
- export declare const showHyperlinkTooltip: (element: NonDeletedExcalidrawElement, appState: AppState, elementsMap: ElementsMap) => void;
19
- export declare const hideHyperlinkToolip: () => void;
19
+ export declare const showHyperlinkTooltip: (element: NonDeletedExcalidrawElement, appState: AppState, elementsMap: ElementsMap, ownerDocument: Document, owner: HyperlinkTooltipOwner) => void;
20
+ export declare const hideHyperlinkToolip: (owner?: HyperlinkTooltipOwner) => void;
@@ -1,10 +1,21 @@
1
+ import type { RenderEnvironment } from "@excalidraw/element/renderEnvironment";
1
2
  import type { GlobalPoint, Radians } from "@excalidraw/math";
2
3
  import type { Bounds } from "@excalidraw/common";
3
4
  import type { ElementsMap, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
4
5
  import type { AppState } from "../../types";
5
6
  export declare const DEFAULT_LINK_SIZE = 12;
6
- export declare const EXTERNAL_LINK_IMG: HTMLImageElement;
7
- export declare const ELEMENT_LINK_IMG: HTMLImageElement;
7
+ type SettledLinkImgStatus = Exclude<LinkImgStatus, "decoding">;
8
+ export type LinkImgStatus = "decoding" | "decoded" | "failed";
9
+ export type LinkImg = {
10
+ /** Only safe as a `drawImage` source while `status` is `decoded`. */
11
+ img: HTMLImageElement;
12
+ status: LinkImgStatus;
13
+ settled: Promise<SettledLinkImgStatus>;
14
+ };
15
+ export declare const getExternalLinkImg: (renderEnvironment: RenderEnvironment) => LinkImg;
16
+ export declare const getElementLinkImg: (renderEnvironment: RenderEnvironment) => LinkImg;
17
+ export declare const startLinkImgDecoding: (renderEnvironment: RenderEnvironment) => Promise<boolean>;
8
18
  export declare const getLinkHandleFromCoords: ([x1, y1, x2, y2]: Bounds, angle: Radians, appState: Pick<AppState, "zoom">) => Bounds;
9
19
  export declare const isPointHittingLinkIcon: (element: NonDeletedExcalidrawElement, elementsMap: ElementsMap, appState: AppState, [x, y]: GlobalPoint) => boolean;
10
20
  export declare const isPointHittingLink: (element: NonDeletedExcalidrawElement, elementsMap: ElementsMap, appState: AppState, [x, y]: GlobalPoint, isMobile: boolean) => boolean;
21
+ export {};
@@ -34,6 +34,8 @@ fileHandle?: FileSystemFileHandle | null) => Promise<{
34
34
  name: string | null;
35
35
  currentItemArrowType: "sharp" | "round" | "elbow";
36
36
  gridSize: number;
37
+ scrollX: number;
38
+ scrollY: number;
37
39
  contextMenu: {
38
40
  items: import("../components/ContextMenu").ContextMenuItems;
39
41
  top: number;
@@ -109,8 +111,6 @@ fileHandle?: FileSystemFileHandle | null) => Promise<{
109
111
  currentHoveredFontFamily: import("@excalidraw/element/types").FontFamilyValues | null;
110
112
  currentItemRoundness: import("@excalidraw/element/types").StrokeRoundness;
111
113
  viewBackgroundColor: string;
112
- scrollX: number;
113
- scrollY: number;
114
114
  scrollConstraints: import("../types").ScrollConstraints | null;
115
115
  cursorButton: "up" | "down";
116
116
  scrolledOutside: boolean;
@@ -222,6 +222,8 @@ fileHandle?: FileSystemFileHandle | null) => Promise<{
222
222
  name: string | null;
223
223
  currentItemArrowType: "sharp" | "round" | "elbow";
224
224
  gridSize: number;
225
+ scrollX: number;
226
+ scrollY: number;
225
227
  contextMenu: {
226
228
  items: import("../components/ContextMenu").ContextMenuItems;
227
229
  top: number;
@@ -297,8 +299,6 @@ fileHandle?: FileSystemFileHandle | null) => Promise<{
297
299
  currentHoveredFontFamily: import("@excalidraw/element/types").FontFamilyValues | null;
298
300
  currentItemRoundness: import("@excalidraw/element/types").StrokeRoundness;
299
301
  viewBackgroundColor: string;
300
- scrollX: number;
301
- scrollY: number;
302
302
  scrollConstraints: import("../types").ScrollConstraints | null;
303
303
  cursorButton: "up" | "down";
304
304
  scrolledOutside: boolean;
@@ -1,4 +1,5 @@
1
1
  import type { ExcalidrawElement, ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
2
+ import type { RenderEnvironment } from "@excalidraw/element";
2
3
  import type { ExportType } from "../scene/types";
3
4
  import type { AppState, BinaryFiles } from "../types";
4
5
  export { loadFromBlob } from "./blob";
@@ -10,12 +11,11 @@ export declare const prepareElementsForExport: (allElements: readonly Excalidraw
10
11
  exportingFrame: NonDeleted<ExcalidrawFrameLikeElement> | null;
11
12
  exportedElements: ExportedElements;
12
13
  };
13
- export declare const exportCanvas: (type: Omit<ExportType, "backend">, elements: ExportedElements, appState: AppState, files: BinaryFiles, { exportBackground, exportPadding, viewBackgroundColor, name, fileHandle, exportingFrame, }: {
14
- exportBackground: boolean;
14
+ export declare const exportCanvas: (type: Omit<ExportType, "backend">, elements: ExportedElements, appState: AppState, files: BinaryFiles, { exportPadding, name, fileHandle, exportingFrame, renderEnvironment, }: {
15
15
  exportPadding?: number;
16
- viewBackgroundColor: string;
17
16
  /** filename, if applicable */
18
17
  name?: string;
19
18
  fileHandle?: FileSystemFileHandle | null;
20
19
  exportingFrame: NonDeleted<ExcalidrawFrameLikeElement> | null;
20
+ renderEnvironment?: RenderEnvironment;
21
21
  }) => Promise<FileSystemFileHandle | null | undefined>;
@@ -32,6 +32,8 @@ export declare const loadFromJSON: (localAppState: AppState, localElements: read
32
32
  name: string | null;
33
33
  currentItemArrowType: "sharp" | "round" | "elbow";
34
34
  gridSize: number;
35
+ scrollX: number;
36
+ scrollY: number;
35
37
  contextMenu: {
36
38
  items: import("../components/ContextMenu").ContextMenuItems;
37
39
  top: number;
@@ -107,8 +109,6 @@ export declare const loadFromJSON: (localAppState: AppState, localElements: read
107
109
  currentHoveredFontFamily: import("@excalidraw/element/types").FontFamilyValues | null;
108
110
  currentItemRoundness: import("@excalidraw/element/types").StrokeRoundness;
109
111
  viewBackgroundColor: string;
110
- scrollX: number;
111
- scrollY: number;
112
112
  scrollConstraints: import("../types").ScrollConstraints | null;
113
113
  cursorButton: "up" | "down";
114
114
  scrolledOutside: boolean;
@@ -1,5 +1,5 @@
1
1
  import { type FontMetadata } from "@excalidraw/common";
2
- import type { ExcalidrawElement } from "@excalidraw/element/types";
2
+ import type { ExcalidrawElement, ExcalidrawTextElement } from "@excalidraw/element/types";
3
3
  import type { Scene } from "@excalidraw/element";
4
4
  import { ExcalidrawFontFace } from "./ExcalidrawFontFace";
5
5
  export declare class Fonts {
@@ -16,6 +16,7 @@ export declare class Fonts {
16
16
  }>;
17
17
  private readonly scene;
18
18
  private readonly ownerDocument;
19
+ private readonly loadedFonts;
19
20
  constructor(scene: Scene, ownerDocument?: Document);
20
21
  /**
21
22
  * Get all the font families for the given scene.
@@ -33,9 +34,15 @@ export declare class Fonts {
33
34
  /**
34
35
  * Load font faces for a given scene and trigger scene update.
35
36
  */
36
- loadSceneFonts: () => Promise<FontFace[]>;
37
+ loadSceneFonts: (defaultFontFamily?: ExcalidrawTextElement["fontFamily"]) => Promise<FontFace[]>;
37
38
  /**
38
39
  * Load font faces for passed elements - use when the scene is unavailable (i.e. export).
40
+ *
41
+ * Loads into the document's font set, or in a worker into the worker's own
42
+ * (`self.fonts`, what an `OffscreenCanvas` there measures with). Where there
43
+ * is neither -- e.g. a DOM shim without `FontFaceSet` (`linkedom`), or Node
44
+ * -- nothing is loaded: the host makes the fonts available itself, and is
45
+ * warned once if the elements use fonts that would need loading.
39
46
  */
40
47
  static loadElementsFonts: (elements: readonly ExcalidrawElement[], ownerDocument?: Document) => Promise<FontFace[]>;
41
48
  /**
@@ -69,10 +76,6 @@ export declare class Fonts {
69
76
  * Get characters for a given family.
70
77
  */
71
78
  private static getCharacters;
72
- /**
73
- * Get all registered font families.
74
- */
75
- private static getAllFamilies;
76
79
  }
77
80
  export interface ExcalidrawFontFaceDescriptor {
78
81
  uri: string;
@@ -1,13 +1,15 @@
1
1
  import { Emitter } from "@excalidraw/common";
2
2
  import { StoreDelta } from "@excalidraw/element";
3
- import type { StoreSnapshot, Store } from "@excalidraw/element";
3
+ import type { RenderEnvironment, StoreSnapshot, Store } from "@excalidraw/element";
4
4
  import type { SceneElementsMap } from "@excalidraw/element/types";
5
5
  import type { AppState } from "./types";
6
6
  export declare class HistoryDelta extends StoreDelta {
7
7
  /**
8
8
  * Apply the delta to the passed elements and appState, does not modify the snapshot.
9
9
  */
10
- applyTo(elements: SceneElementsMap, appState: AppState, snapshot: StoreSnapshot): [SceneElementsMap, AppState, boolean];
10
+ applyTo(elements: SceneElementsMap, appState: AppState, snapshot: StoreSnapshot,
11
+ /** measures the labels re-laid out after applying */
12
+ renderEnvironment?: RenderEnvironment): [SceneElementsMap, AppState, boolean];
11
13
  /**
12
14
  * Overriding once to avoid type casting everywhere.
13
15
  */
@@ -40,8 +42,12 @@ export declare class History {
40
42
  * Do not re-record history entries, which were already pushed to undo / redo stack, as part of history action.
41
43
  */
42
44
  record(delta: StoreDelta): void;
43
- undo(elements: SceneElementsMap, appState: AppState): void | [SceneElementsMap, AppState];
44
- redo(elements: SceneElementsMap, appState: AppState): void | [SceneElementsMap, AppState];
45
+ undo(elements: SceneElementsMap, appState: AppState,
46
+ /** measures the labels re-laid out after undoing (the host's, in the editor) */
47
+ renderEnvironment?: RenderEnvironment): void | [SceneElementsMap, AppState];
48
+ redo(elements: SceneElementsMap, appState: AppState,
49
+ /** measures the labels re-laid out after redoing (the host's, in the editor) */
50
+ renderEnvironment?: RenderEnvironment): void | [SceneElementsMap, AppState];
45
51
  private perform;
46
52
  private static pop;
47
53
  private static push;
@@ -6,7 +6,7 @@ export declare const withBatchedUpdates: <TFunction extends ((event: any) => voi
6
6
  * barches React state updates and throttles the calls to a single call per
7
7
  * animation frame
8
8
  */
9
- export declare const withBatchedUpdatesThrottled: <TFunction extends ((event: any) => void) | (() => void)>(func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never) => {
9
+ export declare const withBatchedUpdatesThrottled: <TFunction extends ((event: any) => void) | (() => void)>(func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never, ownerWindow?: Window) => {
10
10
  (...args: Parameters<TFunction>): void;
11
11
  flush(): void;
12
12
  cancel(): void;
@@ -1,16 +1,23 @@
1
+ /** String keys are shared process-wide; symbols are created per owning
2
+ * instance, which lets concurrent instances run the same named animation
3
+ * independently. */
4
+ export type AnimationKey = string | symbol;
1
5
  export type Animation<R extends object> = (params: {
2
6
  deltaTime: number;
3
7
  state?: R;
4
8
  }) => R | null | undefined;
9
+ export type AnimationScheduler = Pick<Window, "requestAnimationFrame" | "cancelAnimationFrame" | "setTimeout" | "clearTimeout">;
5
10
  export declare class AnimationController {
6
- private static scheduledFrame;
11
+ private static scheduledFrames;
7
12
  private static animations;
8
- static start<R extends object>(key: string, animation: Animation<R>): void;
13
+ private static readonly schedulerCleanups;
14
+ static start<R extends object>(key: AnimationKey, animation: Animation<R>, scheduler?: AnimationScheduler): void;
9
15
  private static scheduleNextFrame;
10
16
  private static cancelScheduledFrame;
11
17
  private static cancelScheduledFrameIfIdle;
18
+ private static registerSchedulerCleanup;
12
19
  private static tick;
13
- static running(key: string): boolean;
14
- static cancel(key: string): void;
20
+ static running(key: AnimationKey): boolean;
21
+ static cancel(key: AnimationKey): void;
15
22
  static reset(): void;
16
23
  }
@@ -2,12 +2,17 @@ import type { ExcalidrawFrameLikeElement } from "@excalidraw/element/types";
2
2
  import type { StaticCanvasRenderConfig, StaticSceneRenderConfig } from "../scene/types";
3
3
  import type { StaticCanvasAppState } from "../types";
4
4
  export declare const frameClip: (frame: ExcalidrawFrameLikeElement, context: CanvasRenderingContext2D, renderConfig: StaticCanvasRenderConfig, appState: StaticCanvasAppState) => void;
5
- /** throttled to animation framerate */
6
- export declare const renderStaticSceneThrottled: {
7
- (config: StaticSceneRenderConfig): void;
8
- flush(): void;
9
- cancel(): void;
10
- };
5
+ /**
6
+ * Throttled to animation framerate, one throttle per canvas. A shared
7
+ * throttle drops all but the last caller's pending frame when multiple
8
+ * editors render in the same frame, and a module-realm scheduler would run
9
+ * popout renders on the main window's rAF, which freezes while that window
10
+ * is hidden.
11
+ */
12
+ export declare const renderStaticSceneThrottled: (config: StaticSceneRenderConfig) => void;
13
+ /** Drops the canvas' pending frame; the throttle itself is dropped with the
14
+ * canvas. */
15
+ export declare const cancelStaticSceneThrottle: (canvas: HTMLCanvasElement) => void;
11
16
  /**
12
17
  * Static scene is the non-ui canvas where we render elements.
13
18
  */
@@ -494,6 +494,6 @@ export declare class Renderer {
494
494
  }) | null;
495
495
  canvasNonce: string;
496
496
  };
497
- destroy(): void;
497
+ destroy(staticCanvas: HTMLCanvasElement): void;
498
498
  }
499
499
  export {};
@@ -1,31 +1,299 @@
1
- import type { ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
1
+ import { MIME_TYPES } from "@excalidraw/common";
2
+ import type { RenderEnvironment } from "@excalidraw/element";
3
+ import type { ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElement, Theme } from "@excalidraw/element/types";
4
+ import { cleanAppStateForExport } from "../appState";
2
5
  import type { AppState, BinaryFiles } from "../types";
3
- export declare const exportToCanvas: (elements: readonly NonDeletedExcalidrawElement[], appState: AppState, files: BinaryFiles, { exportBackground, exportPadding, viewBackgroundColor, exportingFrame, }: {
4
- exportBackground: boolean;
5
- exportPadding?: number;
6
- viewBackgroundColor: string;
6
+ export type ExportSceneData = {
7
+ elements: readonly NonDeletedExcalidrawElement[];
8
+ /**
9
+ * The scene settings a `.excalidraw` file stores (`viewBackgroundColor`,
10
+ * grid settings) — not editor state. Used as the default background
11
+ * (`canvasBackgroundColor`) and embedded with the scene (`embedScene`).
12
+ * Anything else passed in is ignored; rendering options go to `config`.
13
+ */
14
+ appState?: ReturnType<typeof cleanAppStateForExport>;
15
+ files?: BinaryFiles | null;
16
+ };
17
+ /**
18
+ * The host capabilities an export uses, shared by every format: e.g. for test
19
+ * environments, Node.js or another window.
20
+ *
21
+ * Unlike the editor's `renderEnvironment` prop, this needn't be the same
22
+ * object across exports (e.g. on a server): exports draw without the element
23
+ * caches keyed by an environment, and measure little text. Passing a complete
24
+ * one (`createCanvas` and `createImage`) as-is, as the editor does, only keeps
25
+ * its measuring caches warm.
26
+ */
27
+ type ExportEnvironment = {
28
+ /**
29
+ * Creates the canvas a canvas/PNG/JPEG export renders into, and any canvas
30
+ * the export measures text with (e.g. frame labels, embed placeholders).
31
+ *
32
+ * Do not set `canvas.width/height` or modify the canvas context as that's
33
+ * handled by Excalidraw.
34
+ *
35
+ * Defaults to `document.createElement("canvas")`.
36
+ */
37
+ createCanvas?: RenderEnvironment["createCanvas"];
38
+ /**
39
+ * Creates the images that image elements are decoded into.
40
+ *
41
+ * Defaults to `new Image()`.
42
+ */
43
+ createImage?: RenderEnvironment["createImage"];
44
+ /**
45
+ * Creates the paths that freedraw elements are filled through.
46
+ *
47
+ * Defaults to the global `Path2D`.
48
+ */
49
+ createPath?: RenderEnvironment["createPath"];
50
+ /**
51
+ * The document an SVG export is built in, e.g. a popout window's or,
52
+ * outside the browser, a DOM implementation's (such as `linkedom`).
53
+ *
54
+ * Defaults to the global `document`.
55
+ */
56
+ document?: RenderEnvironment["document"];
57
+ /**
58
+ * Measures text (frame labels, embed placeholders), e.g. where there is no
59
+ * canvas to measure on.
60
+ *
61
+ * Defaults to the global provider set with `setCustomTextMetricsProvider`,
62
+ * else to measuring on a canvas from `createCanvas`.
63
+ */
64
+ textMetrics?: RenderEnvironment["textMetrics"];
65
+ /**
66
+ * Loads the fonts the exported elements use, before rendering.
67
+ *
68
+ * Defaults to loading them through the browser's
69
+ * [FontFace API](https://developer.mozilla.org/en-US/docs/Web/API/FontFace).
70
+ */
71
+ loadFonts?: () => Promise<void>;
72
+ };
73
+ type ExportSceneBaseConfig = {
74
+ /**
75
+ * @default "light"
76
+ */
77
+ theme?: Theme;
78
+ /**
79
+ * Canvas background. Valid values are:
80
+ *
81
+ * - `undefined` - the background of "appState.viewBackgroundColor" is used.
82
+ * - `false` - no background is used (transparent). Not supported for JPEG,
83
+ * which falls back to the default.
84
+ * - `string` - should be a valid CSS color.
85
+ *
86
+ * Specified in light-theme terms: `theme: "dark"` transforms it like any
87
+ * other scene color. Only affects the rendered image, not the embedded
88
+ * scene (`embedScene`).
89
+ *
90
+ * @default undefined
91
+ */
92
+ canvasBackgroundColor?: string | false;
93
+ /**
94
+ * Canvas padding in pixels. Affected by `scale`.
95
+ *
96
+ * When `fit` is `none`, padding is added around the content bounding box,
97
+ * or around the `width`/`height` frame if set — in which case the content
98
+ * may overflow the frame, thus right or bottom padding may be ignored.
99
+ *
100
+ * When `fit` is `contain`, or `maxWidthOrHeight`/`widthOrHeight` is set,
101
+ * padding is subtracted from the target size (so the export doesn't exceed
102
+ * it, `scale` aside), and serves as a minimum distance between the content
103
+ * and the canvas edges — it may be exceeded on one axis to maintain the
104
+ * aspect ratio. It is recommended to set `position` to `center` when using
105
+ * `fit: "contain"`.
106
+ *
107
+ * @default 10
108
+ */
109
+ padding?: number;
110
+ /**
111
+ * A multiplier to increase/decrease the frame dimensions
112
+ * (content resolution).
113
+ *
114
+ * For example, if your canvas is 300x150 and you set scale to 2, the
115
+ * resulting size will be 600x300.
116
+ *
117
+ * Can be a function, which receives the export dimensions at scale 1
118
+ * (padding included) and returns the multiplier — e.g. to cap the output
119
+ * by a pixel budget.
120
+ *
121
+ * @default 1
122
+ */
123
+ scale?: number | ((width: number, height: number) => number);
124
+ /**
125
+ * Host environment overrides, e.g. for test environments or Node.js.
126
+ */
127
+ environment?: ExportEnvironment;
7
128
  exportingFrame?: NonDeleted<ExcalidrawFrameLikeElement> | null;
8
- }, createCanvas?: (width: number, height: number) => {
9
- canvas: HTMLCanvasElement;
129
+ /**
130
+ * Which frame decorations to render. Ignored when exporting a single frame
131
+ * (`exportingFrame`), which renders neither its name nor outline, and clips
132
+ * to it.
133
+ *
134
+ * @default { name: true, outline: true, clip: true }
135
+ */
136
+ frames?: {
137
+ name?: boolean;
138
+ outline?: boolean;
139
+ clip?: boolean;
140
+ };
141
+ };
142
+ /**
143
+ * The ways to size the export — only one can be used. The positioning options
144
+ * (`fit`, `position`, `x`, `y`, `origin`) belong to `width`/`height` (or no
145
+ * size option).
146
+ */
147
+ type ExportSizeOptions = {
148
+ /**
149
+ * Makes sure the canvas content fits into a frame of width/height no larger
150
+ * than this value, while maintaining the aspect ratio.
151
+ *
152
+ * Final dimensions can get smaller/larger if used in conjunction with
153
+ * `scale`.
154
+ *
155
+ * Can't be combined with `width`/`height`, `widthOrHeight`, or the
156
+ * positioning options (`fit`, `position`, `x`, `y`, `origin`).
157
+ */
158
+ maxWidthOrHeight?: number;
159
+ /**
160
+ * Scale the canvas content to be exactly this many pixels wide/tall,
161
+ * maintaining the aspect ratio.
162
+ *
163
+ * Final dimensions can get smaller/larger if used in conjunction with
164
+ * `scale`.
165
+ *
166
+ * Can't be combined with `width`/`height`, `maxWidthOrHeight`, or the
167
+ * positioning options (`fit`, `position`, `x`, `y`, `origin`).
168
+ */
169
+ widthOrHeight?: number;
170
+ /**
171
+ * Width of the frame. Supply `x` or `y` if you want to offset the canvas
172
+ * content.
173
+ *
174
+ * If `width` omitted but `height` supplied, `width` is calculated from the
175
+ * content's aspect ratio when `fit` is `contain` (the default), or is the
176
+ * content bounding box width when `fit` is `none`.
177
+ *
178
+ * Defaults to the content bounding box width when both `width` and `height`
179
+ * are omitted.
180
+ *
181
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`.
182
+ */
183
+ width?: number;
184
+ /**
185
+ * Height of the frame.
186
+ *
187
+ * If `height` omitted but `width` supplied, `height` is calculated from the
188
+ * content's aspect ratio when `fit` is `contain` (the default), or is the
189
+ * content bounding box height when `fit` is `none`.
190
+ *
191
+ * Defaults to the content bounding box height when both `width` and `height`
192
+ * are omitted.
193
+ *
194
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`.
195
+ */
196
+ height?: number;
197
+ /**
198
+ * Left edge of the exported region (`padding` is added around it). By
199
+ * default the coordinate is relative to the canvas. You can switch to
200
+ * content coordinates by setting `origin` to `content`.
201
+ *
202
+ * Defaults to the `x` position of the content bounding box.
203
+ *
204
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`, and is
205
+ * ignored with `fit: "contain"`, so setting `x` or `y` makes `fit` default
206
+ * to `none` (cropping the region).
207
+ */
208
+ x?: number;
209
+ /**
210
+ * Top edge of the exported region (`padding` is added around it). By
211
+ * default the coordinate is relative to the canvas. You can switch to
212
+ * content coordinates by setting `origin` to `content`.
213
+ *
214
+ * Defaults to the `y` position of the content bounding box.
215
+ *
216
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`, and is
217
+ * ignored with `fit: "contain"`, so setting `x` or `y` makes `fit` default
218
+ * to `none` (cropping the region).
219
+ */
220
+ y?: number;
221
+ /**
222
+ * Indicates the coordinate system of the `x` and `y` values.
223
+ *
224
+ * - `canvas` - `x` and `y` are relative to the canvas [0, 0] position.
225
+ * - `content` - `x` and `y` are relative to the content bounding box.
226
+ *
227
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`.
228
+ *
229
+ * @default "canvas"
230
+ */
231
+ origin?: "canvas" | "content";
232
+ /**
233
+ * How the content should be scaled into the `width`/`height` frame.
234
+ *
235
+ * Behavior aligns with the `object-fit` CSS property.
236
+ *
237
+ * - `none` - no scaling.
238
+ * - `contain` - scale to fit the frame. Includes `padding`.
239
+ *
240
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`.
241
+ *
242
+ * @default "contain" if `width` or `height` is set (and `x`/`y` aren't),
243
+ * otherwise "none"
244
+ */
245
+ fit?: "none" | "contain";
246
+ /**
247
+ * When either `x` or `y` are not specified, indicates how the canvas should
248
+ * be aligned on the respective axis.
249
+ *
250
+ * - `topLeft` - canvas aligned to top left.
251
+ * - `center` - canvas is centered on the axis which is not specified
252
+ * (or both).
253
+ *
254
+ * Can't be combined with `maxWidthOrHeight` or `widthOrHeight`.
255
+ *
256
+ * @default "center"
257
+ */
258
+ position?: "center" | "topLeft";
259
+ };
260
+ type ExportSizeOption<K extends keyof ExportSizeOptions> = Pick<ExportSizeOptions, K> & {
261
+ [P in keyof ExportSizeOptions as P extends K ? never : P]?: never;
262
+ };
263
+ type ExportSizeConfig = ExportSizeOption<"width" | "height" | "fit" | "position" | "x" | "y" | "origin"> | ExportSizeOption<"maxWidthOrHeight"> | ExportSizeOption<"widthOrHeight">;
264
+ export type ExportSceneConfig = ExportSceneBaseConfig & ExportSizeConfig;
265
+ /**
266
+ * The export config the editor's export settings translate to. Internal: hosts
267
+ * pass their own config.
268
+ */
269
+ export declare const getExportConfigFromAppState: (appState: Pick<AppState, "exportWithDarkMode" | "exportBackground" | "viewBackgroundColor" | "exportScale" | "frameRendering">) => {
270
+ theme: "light" | "dark";
271
+ canvasBackgroundColor: string | false;
10
272
  scale: number;
11
- }, loadFonts?: () => Promise<void>) => Promise<HTMLCanvasElement>;
12
- export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElement[], appState: {
13
- exportBackground: boolean;
14
- exportPadding?: number;
15
- exportScale?: number;
16
- viewBackgroundColor: string;
17
- exportWithDarkMode?: boolean;
18
- exportEmbedScene?: boolean;
19
- frameRendering?: AppState["frameRendering"];
20
- }, files: BinaryFiles | null, opts?: {
273
+ frames: {
274
+ enabled: boolean;
275
+ name: boolean;
276
+ outline: boolean;
277
+ clip: boolean;
278
+ } | {
279
+ name: boolean;
280
+ outline: boolean;
281
+ clip: boolean;
282
+ };
283
+ };
284
+ type ExportToSvgConfig = Pick<ExportSceneBaseConfig, "canvasBackgroundColor" | "padding" | "theme" | "exportingFrame" | "scale" | "frames" | "environment"> & ExportSizeConfig & {
21
285
  /**
22
286
  * if true, all embeddables passed in will be rendered when possible.
23
287
  */
24
288
  renderEmbeddables?: boolean;
25
- exportingFrame?: NonDeleted<ExcalidrawFrameLikeElement> | null;
26
289
  skipInliningFonts?: true;
27
290
  reuseImages?: boolean;
28
- }) => Promise<SVGSVGElement>;
291
+ /**
292
+ * Embeds the scene into the SVG, so that it can be imported back into
293
+ * Excalidraw.
294
+ */
295
+ embedScene?: boolean;
296
+ };
29
297
  export declare const encodeSvgBase64Payload: ({ payload, metadataElement, }: {
30
298
  payload: string;
31
299
  metadataElement: SVGMetadataElement;
@@ -33,4 +301,59 @@ export declare const encodeSvgBase64Payload: ({ payload, metadataElement, }: {
33
301
  export declare const decodeSvgBase64Payload: ({ svg }: {
34
302
  svg: string;
35
303
  }) => string;
36
- export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], exportPadding: number, scale: number) => [number, number];
304
+ export { MIME_TYPES };
305
+ type ExportToPngConfig = ExportSceneConfig & {
306
+ /**
307
+ * Embeds the scene into the PNG metadata, so that it can be imported back
308
+ * into Excalidraw.
309
+ */
310
+ embedScene?: boolean;
311
+ };
312
+ type ExportToJpegConfig = ExportSceneConfig & {
313
+ /**
314
+ * Encoding quality between 0 and 1.
315
+ *
316
+ * @default 0.92
317
+ */
318
+ quality?: number;
319
+ };
320
+ export type ExportSceneOptions = {
321
+ data: ExportSceneData;
322
+ } & ({
323
+ type: "canvas";
324
+ config?: ExportSceneConfig;
325
+ } | {
326
+ type: "png";
327
+ config?: ExportToPngConfig;
328
+ } | {
329
+ type: "jpeg";
330
+ config?: ExportToJpegConfig;
331
+ } | {
332
+ type: "svg";
333
+ config?: ExportToSvgConfig;
334
+ });
335
+ /**
336
+ * Exports the scene to a canvas, a PNG or JPEG blob, or an SVG element.
337
+ */
338
+ export declare function exportScene(opts: Extract<ExportSceneOptions, {
339
+ type: "canvas";
340
+ }>): Promise<HTMLCanvasElement>;
341
+ export declare function exportScene(opts: Extract<ExportSceneOptions, {
342
+ type: "png" | "jpeg";
343
+ }>): Promise<Blob>;
344
+ export declare function exportScene(opts: Extract<ExportSceneOptions, {
345
+ type: "svg";
346
+ }>): Promise<SVGSVGElement>;
347
+ export declare function exportScene(opts: ExportSceneOptions): Promise<HTMLCanvasElement | Blob | SVGSVGElement>;
348
+ export declare const exportToClipboard: (opts: {
349
+ data: ExportSceneData;
350
+ } & ({
351
+ type: "png";
352
+ config?: ExportToPngConfig;
353
+ } | {
354
+ type: "svg";
355
+ config?: ExportToSvgConfig;
356
+ } | {
357
+ type: "json";
358
+ config?: never;
359
+ })) => Promise<void>;