@haklex/rich-ext-whiteboard 0.65.7 → 0.66.0

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 (99) hide show
  1. package/README.md +45 -5
  2. package/dist/InteractiveScene-CpoWGP_L.js +424 -0
  3. package/dist/WhiteboardEditor-cZ32fLqJ.js +4799 -0
  4. package/dist/WhiteboardExpandShell-BBjXd5qK.js +474 -0
  5. package/dist/editor/ContextMenu.d.ts +9 -0
  6. package/dist/editor/ContextMenu.d.ts.map +1 -0
  7. package/dist/editor/MobileDock.d.ts +2 -0
  8. package/dist/editor/MobileDock.d.ts.map +1 -1
  9. package/dist/editor/TextEditor.d.ts.map +1 -1
  10. package/dist/editor/Toolbar.d.ts +1 -0
  11. package/dist/editor/Toolbar.d.ts.map +1 -1
  12. package/dist/editor/WhiteboardCanvas.d.ts +2 -1
  13. package/dist/editor/WhiteboardCanvas.d.ts.map +1 -1
  14. package/dist/editor/WhiteboardEditor.d.ts +15 -0
  15. package/dist/editor/WhiteboardEditor.d.ts.map +1 -1
  16. package/dist/editor/card-actions.d.ts +8 -0
  17. package/dist/editor/card-actions.d.ts.map +1 -0
  18. package/dist/editor/chrome.css.d.ts +3 -0
  19. package/dist/editor/chrome.css.d.ts.map +1 -1
  20. package/dist/editor/context-menu.d.ts +27 -0
  21. package/dist/editor/context-menu.d.ts.map +1 -0
  22. package/dist/editor/context-menu.test.d.ts +2 -0
  23. package/dist/editor/context-menu.test.d.ts.map +1 -0
  24. package/dist/editor/embed.test.d.ts +2 -0
  25. package/dist/editor/embed.test.d.ts.map +1 -0
  26. package/dist/editor/focus.d.ts +11 -0
  27. package/dist/editor/focus.d.ts.map +1 -0
  28. package/dist/editor/remote-edit.test.d.ts +2 -0
  29. package/dist/editor/remote-edit.test.d.ts.map +1 -0
  30. package/dist/editor/shortcuts.d.ts +1 -1
  31. package/dist/editor/shortcuts.d.ts.map +1 -1
  32. package/dist/editor/store.d.ts +10 -1
  33. package/dist/editor/store.d.ts.map +1 -1
  34. package/dist/editor/tools/card.d.ts +0 -2
  35. package/dist/editor/tools/card.d.ts.map +1 -1
  36. package/dist/editor-entry.d.ts +28 -0
  37. package/dist/editor-entry.d.ts.map +1 -0
  38. package/dist/editor.mjs +186 -0
  39. package/dist/export/export.test.d.ts +2 -0
  40. package/dist/export/export.test.d.ts.map +1 -0
  41. package/dist/export/fonts.d.ts +22 -0
  42. package/dist/export/fonts.d.ts.map +1 -0
  43. package/dist/export/index.d.ts +7 -0
  44. package/dist/export/index.d.ts.map +1 -0
  45. package/dist/export/png.d.ts +10 -0
  46. package/dist/export/png.d.ts.map +1 -0
  47. package/dist/export/svg.d.ts +19 -0
  48. package/dist/export/svg.d.ts.map +1 -0
  49. package/dist/export-B_abF5zK.js +248 -0
  50. package/dist/index.mjs +6 -4408
  51. package/dist/model/reconcile.d.ts +14 -0
  52. package/dist/model/reconcile.d.ts.map +1 -0
  53. package/dist/model/reconcile.test.d.ts +2 -0
  54. package/dist/model/reconcile.test.d.ts.map +1 -0
  55. package/dist/model/restore-fonts.test.d.ts +2 -0
  56. package/dist/model/restore-fonts.test.d.ts.map +1 -0
  57. package/dist/model/restore.d.ts +5 -0
  58. package/dist/model/restore.d.ts.map +1 -1
  59. package/dist/model/richtext-layout.d.ts +2 -0
  60. package/dist/model/richtext-layout.d.ts.map +1 -1
  61. package/dist/model/skeleton.d.ts +21 -0
  62. package/dist/model/skeleton.d.ts.map +1 -0
  63. package/dist/model/skeleton.test.d.ts +2 -0
  64. package/dist/model/skeleton.test.d.ts.map +1 -0
  65. package/dist/model/supersede.d.ts +3 -0
  66. package/dist/model/supersede.d.ts.map +1 -0
  67. package/dist/model/viewport-fit.d.ts +24 -0
  68. package/dist/model/viewport-fit.d.ts.map +1 -0
  69. package/dist/reconcile-Of9Y1rFE.js +57 -0
  70. package/dist/rich-ext-whiteboard.css +1 -1
  71. package/dist/scene/InteractiveScene.d.ts +14 -1
  72. package/dist/scene/InteractiveScene.d.ts.map +1 -1
  73. package/dist/scene/Scene.d.ts +1 -0
  74. package/dist/scene/Scene.d.ts.map +1 -1
  75. package/dist/scene/SceneControls.d.ts +10 -0
  76. package/dist/scene/SceneControls.d.ts.map +1 -0
  77. package/dist/scene/context.d.ts +2 -0
  78. package/dist/scene/context.d.ts.map +1 -1
  79. package/dist/scene/elements.d.ts.map +1 -1
  80. package/dist/scene/fonts.d.ts +2 -0
  81. package/dist/scene/fonts.d.ts.map +1 -1
  82. package/dist/scene/fonts.test.d.ts +2 -0
  83. package/dist/scene/fonts.test.d.ts.map +1 -0
  84. package/dist/scene/interactive.test.d.ts +2 -0
  85. package/dist/scene/interactive.test.d.ts.map +1 -0
  86. package/dist/scene/richtext/RichTextSvgBody.d.ts +6 -0
  87. package/dist/scene/richtext/RichTextSvgBody.d.ts.map +1 -0
  88. package/dist/scene/transform.d.ts +18 -0
  89. package/dist/scene/transform.d.ts.map +1 -0
  90. package/dist/scene/useSceneFocus.d.ts +35 -0
  91. package/dist/scene/useSceneFocus.d.ts.map +1 -0
  92. package/dist/scene/useSceneGestures.d.ts +20 -0
  93. package/dist/scene/useSceneGestures.d.ts.map +1 -0
  94. package/dist/scene-entry.d.ts +16 -0
  95. package/dist/scene-entry.d.ts.map +1 -0
  96. package/dist/scene.mjs +5 -0
  97. package/dist/static.mjs +1 -1
  98. package/dist/{WhiteboardExpandShell-D1s7iDKh.js → viewport-fit-DzCmuJXY.js} +306 -814
  99. package/package.json +13 -5
@@ -0,0 +1,11 @@
1
+ import { Bounds } from '../model/geometry';
2
+ import { FitInsets, FitOptions } from '../model/viewport-fit';
3
+ import { WhiteboardStore } from './store';
4
+ export type FocusInsets = FitInsets;
5
+ export interface FocusOptions extends FitOptions {
6
+ animate?: boolean;
7
+ duration?: number;
8
+ }
9
+ export type FocusTarget = readonly string[] | Bounds | null;
10
+ export declare function focusElements(store: WhiteboardStore, target: FocusTarget, options?: FocusOptions): boolean;
11
+ //# sourceMappingURL=focus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../../src/editor/focus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI/C,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC;AAEpC,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;AA6B5D,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAsBT"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=remote-edit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-edit.test.d.ts","sourceRoot":"","sources":["../../src/editor/remote-edit.test.ts"],"names":[],"mappings":""}
@@ -12,5 +12,5 @@ export interface ShortcutEvent {
12
12
  export declare function zoomBy(store: WhiteboardStore, factor: number): void;
13
13
  export declare function resetZoom(store: WhiteboardStore): void;
14
14
  export declare function zoomToFit(store: WhiteboardStore): void;
15
- export declare function handleShortcut(store: WhiteboardStore, e: ShortcutEvent): boolean;
15
+ export declare function handleShortcut(store: WhiteboardStore, e: ShortcutEvent, allowedTools?: ReadonlySet<ToolType>): boolean;
16
16
  //# sourceMappingURL=shortcuts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shortcuts.d.ts","sourceRoot":"","sources":["../../src/editor/shortcuts.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM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AI,CAInE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAGtD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAKtD;AAuDD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,eAAe,EACtB,CAAC,EAAE,aAAa,EAChB,YAAY,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,GACnC,OAAO,CA+DT"}
@@ -1,6 +1,12 @@
1
+ import { BinaryFiles, ExcalidrawElement } from '../scene/types';
1
2
  import { Doc, DocUpdater, EditorState, SceneDoc } from './types';
3
+ export interface RemoteUpdate {
4
+ elements?: readonly ExcalidrawElement[];
5
+ files?: BinaryFiles;
6
+ }
2
7
  export interface WhiteboardStore {
3
8
  amend: (fn: (doc: Doc) => Doc) => void;
9
+ applyRemote: (update: RemoteUpdate) => void;
4
10
  beginTransient: () => void;
5
11
  canRedo: () => boolean;
6
12
  canUndo: () => boolean;
@@ -16,6 +22,9 @@ export interface WhiteboardStore {
16
22
  undo: () => void;
17
23
  updateTransient: (updater: DocUpdater) => void;
18
24
  }
19
- export declare function createWhiteboardStore(input: Record<string, unknown> | undefined): WhiteboardStore;
25
+ export interface WhiteboardStoreOptions {
26
+ sync?: boolean;
27
+ }
28
+ export declare function createWhiteboardStore(input: Record<string, unknown> | undefined, options?: WhiteboardStoreOptions): WhiteboardStore;
20
29
  export declare function useStore<T>(store: WhiteboardStore, selector: (state: EditorState) => T): T;
21
30
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/editor/store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEtE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,KAAK,IAAI,C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,5 +1,3 @@
1
1
  import { ToolHandler } from './types';
2
- export declare const CARD_WIDTH = 200;
3
- export declare const CARD_HEIGHT = 120;
4
2
  export declare function createCardTool(): ToolHandler;
5
3
  //# sourceMappingURL=card.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../../src/editor/tools/card.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,eAAO,MAAM,UAAU,MAAM,CAAC;AAC9B,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,wBAAgB,cAAc,IAAI,WAAW,CA6D5C"}
1
+ {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../../src/editor/tools/card.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,wBAAgB,cAAc,IAAI,WAAW,CA6D5C"}
@@ -0,0 +1,28 @@
1
+ export { bringForward, bringToFront, deleteElements, deleteSelection, duplicateSelection, groupSelection, selectAll, sendBackward, sendToBack, ungroupSelection, } from './editor/actions';
2
+ export { CARD_HEIGHT, CARD_WIDTH, placeCard, setTool } from './editor/card-actions';
3
+ export { copySelection, cutSelection, pasteFromClipboard } from './editor/clipboard-actions';
4
+ export type { ContextMenuAction, ContextMenuContext, ContextMenuItem, ContextMenuItemsFn, ContextMenuRequest, ContextMenuSeparator, } from './editor/context-menu';
5
+ export type { FocusInsets, FocusOptions, FocusTarget } from './editor/focus';
6
+ export { focusElements } from './editor/focus';
7
+ export { getSelectedElements } from './editor/selection-utils';
8
+ export type { RemoteUpdate, WhiteboardStore, WhiteboardStoreOptions } from './editor/store';
9
+ export { createWhiteboardStore, useStore } from './editor/store';
10
+ export type { StyleProp } from './editor/style-props';
11
+ export { applyStyle, getApplicableProps, getCommonValue } from './editor/style-props';
12
+ export type { Doc, DocUpdater, EditorState, SceneDoc, ToolType, Viewport } from './editor/types';
13
+ export { clampZoom, fitToContent, MAX_ZOOM, MIN_ZOOM, panBy, sceneToScreen, screenToScene, zoomAt, } from './editor/viewport';
14
+ export { CHROME_ATTR } from './editor/WhiteboardCanvas';
15
+ export type { WhiteboardChrome, WhiteboardEditorProps } from './editor/WhiteboardEditor';
16
+ export { WhiteboardEditor } from './editor/WhiteboardEditor';
17
+ export type { ExportBlobOptions, ExportScene, ExportSvgOptions, FontFace, FontUsage, } from './export';
18
+ export { collectFontFaces, exportToBlob, exportToSvg } from './export';
19
+ export { getCommonBounds, getElementBounds, hitTestElement } from './model/bounds';
20
+ export type { Bounds, Point } from './model/geometry';
21
+ export type { Reconciled } from './model/reconcile';
22
+ export { orderByIndex, reconcileElements } from './model/reconcile';
23
+ export { FontLoadError, restoreElements } from './model/restore';
24
+ export type { ConvertedSkeletons, SkeletonElement } from './model/skeleton';
25
+ export { convertSkeletons } from './model/skeleton';
26
+ export { fontFamilyToCss, HAND_FONT_STACK, isHandFontFamily, MONO_FONT_STACK, SANS_FONT_STACK, setFontFamilyStack, WHITEBOARD_FONT_STACK, } from './scene/fonts';
27
+ export type * from './scene/types';
28
+ //# sourceMappingURL=editor-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-entry.d.ts","sourceRoot":"","sources":["../src/editor-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,YAAY,EACZ,UAAU,EACV,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MA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AM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,mBAAmB,eAAe,CAAC"}
@@ -0,0 +1,186 @@
1
+ import { B as isHandFontFamily, F as HAND_FONT_STACK, G as getElementBounds, I as MONO_FONT_STACK, J as hitTestElement, L as SANS_FONT_STACK, M as randomId, R as WHITEBOARD_FONT_STACK, U as getCommonBounds, V as setFontFamilyStack, _ as parseSvgSize, b as syncIndices, d as normalizeElement, f as restoreElements, h as refreshTextDimensions, k as newTextElement, l as resolveRichTextHeights, m as layoutBoundText, t as viewportFor, u as FontLoadError, v as bumpVersion, y as isValidIndex, z as fontFamilyToCss } from "./viewport-fit-DzCmuJXY.js";
2
+ import { A as sendToBack, C as bringToFront, D as groupSelection, E as duplicateSelection, F as createWhiteboardStore, I as useStore, M as getSelectedElements, O as selectAll, S as bringForward, T as deleteSelection, _ as screenToScene, a as CHROME_ATTR, b as cutSelection, c as placeCard, d as MAX_ZOOM, f as MIN_ZOOM, g as sceneToScreen, h as panBy, i as getCommonValue, j as ungroupSelection, k as sendBackward, l as setTool, m as fitToContent, n as applyStyle, o as CARD_HEIGHT, p as clampZoom, r as getApplicableProps, s as CARD_WIDTH, t as WhiteboardEditor, u as bindLinearEnd, v as zoomAt, w as deleteElements, x as pasteFromClipboard, y as copySelection } from "./WhiteboardEditor-cZ32fLqJ.js";
3
+ import { n as reconcileElements, t as orderByIndex } from "./reconcile-Of9Y1rFE.js";
4
+ import { n as exportToSvg, r as collectFontFaces, t as exportToBlob } from "./export-B_abF5zK.js";
5
+ //#region src/editor/focus.ts
6
+ var DEFAULT_DURATION = 280;
7
+ var isBounds = (target) => !!target && target.length === 4 && target.every((value) => typeof value === "number");
8
+ var running = /* @__PURE__ */ new WeakMap();
9
+ function animateTo(store, target, duration) {
10
+ const from = store.getState().viewport;
11
+ const started = performance.now();
12
+ const step = (now) => {
13
+ const t = Math.min(1, (now - started) / duration);
14
+ const eased = 1 - (1 - t) ** 3;
15
+ const mix = (a, b) => a + (b - a) * eased;
16
+ store.setState({ viewport: {
17
+ zoom: mix(from.zoom, target.zoom),
18
+ scrollX: mix(from.scrollX, target.scrollX),
19
+ scrollY: mix(from.scrollY, target.scrollY)
20
+ } });
21
+ if (t < 1) running.set(store, requestAnimationFrame(step));
22
+ else running.delete(store);
23
+ };
24
+ running.set(store, requestAnimationFrame(step));
25
+ }
26
+ function focusElements(store, target, options = {}) {
27
+ const { elements, canvasSize } = store.getState();
28
+ let bounds = null;
29
+ if (isBounds(target)) bounds = target;
30
+ else {
31
+ const wanted = target ? new Set(target) : null;
32
+ const picked = elements.filter((el) => !el.isDeleted && (!wanted || wanted.has(el.id)));
33
+ if (picked.length > 0) bounds = getCommonBounds(picked);
34
+ }
35
+ if (!bounds || canvasSize.width <= 0 || canvasSize.height <= 0) return false;
36
+ const pendingFrame = running.get(store);
37
+ if (pendingFrame !== void 0) cancelAnimationFrame(pendingFrame);
38
+ running.delete(store);
39
+ const viewport = viewportFor(bounds, canvasSize, {
40
+ ...options,
41
+ minZoom: MIN_ZOOM,
42
+ maxZoom: Math.min(options.maxZoom ?? 30, 30)
43
+ });
44
+ if (options.animate && typeof requestAnimationFrame === "function") animateTo(store, viewport, options.duration ?? DEFAULT_DURATION);
45
+ else store.setState({ viewport });
46
+ return true;
47
+ }
48
+ //#endregion
49
+ //#region src/model/skeleton.ts
50
+ var FRAME_PADDING = 10;
51
+ var SVG_FALLBACK_SIZE = 100;
52
+ var LINEAR = /* @__PURE__ */ new Set(["arrow", "line"]);
53
+ var positive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
54
+ function shape(skeleton) {
55
+ const { children: _children, end: _end, label: _label, start: _start, ...rest } = skeleton;
56
+ const raw = {
57
+ ...rest,
58
+ id: skeleton.id ?? randomId()
59
+ };
60
+ const el = normalizeElement(raw);
61
+ if (LINEAR.has(el.type)) {
62
+ const points = el.points;
63
+ const xs = points.map(([x]) => x);
64
+ const ys = points.map(([, y]) => y);
65
+ return {
66
+ ...el,
67
+ width: Math.max(...xs) - Math.min(...xs),
68
+ height: Math.max(...ys) - Math.min(...ys)
69
+ };
70
+ }
71
+ if (el.type === "svg" && !(positive(rest.width) && positive(rest.height))) {
72
+ const size = parseSvgSize(el.svg ?? "");
73
+ return {
74
+ ...el,
75
+ width: size?.width ?? SVG_FALLBACK_SIZE,
76
+ height: size?.height ?? SVG_FALLBACK_SIZE
77
+ };
78
+ }
79
+ if (el.type === "text") return refreshTextDimensions(el);
80
+ return el;
81
+ }
82
+ function labelFor(container, label) {
83
+ const { text = "", ...style } = label ?? {};
84
+ return newTextElement({
85
+ strokeColor: container.strokeColor,
86
+ textAlign: "center",
87
+ verticalAlign: "middle",
88
+ ...style,
89
+ id: typeof style.id === "string" ? style.id : randomId(),
90
+ text,
91
+ containerId: container.id,
92
+ frameId: container.frameId ?? null
93
+ });
94
+ }
95
+ function fitFrame(frame, members) {
96
+ if (members.length === 0) return frame;
97
+ const [minX, minY, maxX, maxY] = getCommonBounds(members);
98
+ return {
99
+ ...frame,
100
+ x: minX - FRAME_PADDING,
101
+ y: minY - FRAME_PADDING,
102
+ width: maxX - minX + 20,
103
+ height: maxY - minY + 20
104
+ };
105
+ }
106
+ function placed(list, el) {
107
+ if (list.some((existing) => existing.id === el.id)) return list.map((existing) => existing.id === el.id ? el : existing);
108
+ const index = el.index;
109
+ if (!isValidIndex(index)) return [...list, el];
110
+ const above = list.findIndex((existing) => isValidIndex(existing.index) && existing.index > index);
111
+ return above < 0 ? [...list, el] : [
112
+ ...list.slice(0, above),
113
+ el,
114
+ ...list.slice(above)
115
+ ];
116
+ }
117
+ function convertSkeletons(skeletons, scene) {
118
+ const createdIds = /* @__PURE__ */ new Set();
119
+ const sources = /* @__PURE__ */ new Map();
120
+ let working = [...scene];
121
+ const replace = (next) => {
122
+ working = working.map((el) => el.id === next.id ? next : el);
123
+ };
124
+ const byId = (id) => working.find((el) => el.id === id);
125
+ for (const skeleton of skeletons) {
126
+ const shaped = shape(skeleton);
127
+ const replaced = scene.find((existing) => existing.id === shaped.id);
128
+ const layered = replaced ? {
129
+ ...shaped,
130
+ index: shaped.index ?? replaced.index
131
+ } : shaped;
132
+ const el = replaced && (layered.version ?? 0) <= (replaced.version ?? 0) ? bumpVersion({
133
+ ...layered,
134
+ version: replaced.version
135
+ }) : layered;
136
+ createdIds.add(el.id);
137
+ sources.set(el.id, skeleton);
138
+ working = placed(working, el);
139
+ }
140
+ for (const [id, skeleton] of sources) {
141
+ if (!LINEAR.has(skeleton.type)) continue;
142
+ for (const end of ["start", "end"]) {
143
+ const targetId = skeleton[end]?.id;
144
+ const target = typeof targetId === "string" ? byId(targetId) : void 0;
145
+ if (!target || target.isDeleted || target.id === id) continue;
146
+ working = bindLinearEnd(working, id, end, target.id);
147
+ }
148
+ }
149
+ for (const [id, skeleton] of sources) {
150
+ if (!skeleton.label || typeof skeleton.label.text !== "string") continue;
151
+ const container = byId(id);
152
+ const laid = layoutBoundText(container, labelFor(container, skeleton.label));
153
+ createdIds.add(laid.text.id);
154
+ replace({
155
+ ...laid.container,
156
+ boundElements: [...container.boundElements ?? [], {
157
+ id: laid.text.id,
158
+ type: "text"
159
+ }]
160
+ });
161
+ working = [...working, laid.text];
162
+ }
163
+ for (const [id, skeleton] of sources) {
164
+ if (skeleton.type !== "frame" || !Array.isArray(skeleton.children)) continue;
165
+ const wanted = new Set(skeleton.children);
166
+ const joins = (el) => !el.isDeleted && (wanted.has(el.id) || el.type === "text" && !!el.containerId && wanted.has(el.containerId));
167
+ working = working.map((el) => {
168
+ if (!joins(el) || el.frameId === id) return el;
169
+ return createdIds.has(el.id) ? {
170
+ ...el,
171
+ frameId: id
172
+ } : bumpVersion(el, { frameId: id });
173
+ });
174
+ if (positive(skeleton.width) && positive(skeleton.height)) continue;
175
+ replace(fitFrame(byId(id), working.filter((el) => el.frameId === id && !el.isDeleted)));
176
+ }
177
+ const indexed = syncIndices(working);
178
+ working = resolveRichTextHeights(working.map((el, i) => createdIds.has(el.id) ? indexed[i] : el));
179
+ const before = new Map(scene.map((el) => [el.id, el]));
180
+ return {
181
+ created: working.filter((el) => createdIds.has(el.id)),
182
+ touched: working.filter((el) => !createdIds.has(el.id) && before.get(el.id) !== el)
183
+ };
184
+ }
185
+ //#endregion
186
+ export { CARD_HEIGHT, CARD_WIDTH, CHROME_ATTR, FontLoadError, HAND_FONT_STACK, MAX_ZOOM, MIN_ZOOM, MONO_FONT_STACK, SANS_FONT_STACK, WHITEBOARD_FONT_STACK, WhiteboardEditor, applyStyle, bringForward, bringToFront, clampZoom, collectFontFaces, convertSkeletons, copySelection, createWhiteboardStore, cutSelection, deleteElements, deleteSelection, duplicateSelection, exportToBlob, exportToSvg, fitToContent, focusElements, fontFamilyToCss, getApplicableProps, getCommonBounds, getCommonValue, getElementBounds, getSelectedElements, groupSelection, hitTestElement, isHandFontFamily, orderByIndex, panBy, pasteFromClipboard, placeCard, reconcileElements, restoreElements, sceneToScreen, screenToScene, selectAll, sendBackward, sendToBack, setFontFamilyStack, setTool, ungroupSelection, useStore, zoomAt };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=export.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.test.d.ts","sourceRoot":"","sources":["../../src/export/export.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ export interface FontFace {
2
+ family: string;
3
+ format?: string;
4
+ style?: string;
5
+ unicodeRange?: string;
6
+ url: string;
7
+ weight?: string;
8
+ }
9
+ export interface FontUsage {
10
+ families: ReadonlySet<string>;
11
+ text: string;
12
+ }
13
+ export declare function familiesOf(stack: string): string[];
14
+ export declare function collectFontFaces(cssText: string, baseHref: string, usage: FontUsage): FontFace[];
15
+ export declare function toDataUrl(url: string): Promise<string>;
16
+ export interface CssSource {
17
+ baseHref: string;
18
+ cssText: string;
19
+ }
20
+ export declare function expandImports(cssText: string, baseHref: string, fetchText: (url: string) => Promise<string>, depth?: number): Promise<CssSource[]>;
21
+ export declare function embeddedFontCss(usage: FontUsage): Promise<string>;
22
+ //# sourceMappingURL=fonts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fonts.d.ts","sourceRoot":"","sources":["../../src/export/fonts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAoBD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAElD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,QAAQ,EAAE,CA2BhG;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW5D;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC3C,KAAK,SAAI,GACR,OAAO,CAAC,SAAS,EAAE,CAAC,CActB;AAgCD,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBvE"}
@@ -0,0 +1,7 @@
1
+ export type { FontFace, FontUsage } from './fonts';
2
+ export { collectFontFaces } from './fonts';
3
+ export type { ExportBlobOptions } from './png';
4
+ export { exportToBlob } from './png';
5
+ export type { ExportScene, ExportSvgOptions } from './svg';
6
+ export { exportToSvg } from './svg';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/export/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ExportScene, ExportSvgOptions } from './svg';
2
+ export interface ExportBlobOptions extends ExportSvgOptions {
3
+ maxSize?: number;
4
+ mimeType?: string;
5
+ quality?: number;
6
+ scale?: number;
7
+ }
8
+ export declare function rasterScale(width: number, height: number, scale: number, maxSize: number): number;
9
+ export declare function exportToBlob(scene: ExportScene, options?: ExportBlobOptions): Promise<Blob>;
10
+ //# sourceMappingURL=png.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"png.d.ts","sourceRoot":"","sources":["../../src/export/png.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG3D,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGjG;AAWD,wBAAsB,YAAY,CAChC,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
@@ -0,0 +1,19 @@
1
+ import { BinaryFiles, ExcalidrawElement } from '../scene/types';
2
+ export interface ExportScene {
3
+ elements: readonly ExcalidrawElement[];
4
+ files?: BinaryFiles;
5
+ }
6
+ export interface ExportSvgOptions {
7
+ background?: string | null;
8
+ embedFonts?: boolean;
9
+ handFontOverride?: string;
10
+ padding?: number;
11
+ }
12
+ export interface RenderedSvg {
13
+ height: number;
14
+ svg: string;
15
+ width: number;
16
+ }
17
+ export declare function renderSvg(scene: ExportScene, options?: ExportSvgOptions): Promise<RenderedSvg>;
18
+ export declare function exportToSvg(scene: ExportScene, options?: ExportSvgOptions): Promise<string>;
19
+ //# sourceMappingURL=svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../src/export/svg.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAmB,MAAM,gBAAgB,CAAC;AAItF,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACvC,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAuCD,wBAAsB,SAAS,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,WAAW,CAAC,CAiDtB;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEjG"}
@@ -0,0 +1,248 @@
1
+ import { B as isHandFontFamily, L as SANS_FONT_STACK, U as getCommonBounds, i as SceneContent, j as richTextPlainText, l as resolveRichTextHeights, s as SceneExportContext, z as fontFamilyToCss } from "./viewport-fit-DzCmuJXY.js";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { flushSync } from "react-dom";
4
+ import { createRoot } from "react-dom/client";
5
+ //#region src/export/fonts.ts
6
+ var unquote = (value) => value.trim().replace(/^(['"])(.*)\1$/, "$2");
7
+ var descriptor = (block, name) => {
8
+ const match = new RegExp(`(?:^|[;{\\s])${name}\\s*:\\s*([^;}]+)`, "i").exec(block);
9
+ return match ? match[1].trim() : void 0;
10
+ };
11
+ function rangeCovers(range, codePoints) {
12
+ for (const part of range.split(",")) {
13
+ const match = /^u\+([\da-f?]+)(?:-([\da-f]+))?$/i.exec(part.trim());
14
+ if (!match) continue;
15
+ const from = Number.parseInt(match[1].replaceAll("?", "0"), 16);
16
+ const to = Number.parseInt(match[2] ?? match[1].replaceAll("?", "f"), 16);
17
+ for (const point of codePoints) if (point >= from && point <= to) return true;
18
+ }
19
+ return false;
20
+ }
21
+ function familiesOf(stack) {
22
+ return stack.split(",").map((name) => unquote(name).toLowerCase());
23
+ }
24
+ function collectFontFaces(cssText, baseHref, usage) {
25
+ const codePoints = /* @__PURE__ */ new Set();
26
+ for (const char of usage.text) codePoints.add(char.codePointAt(0));
27
+ const faces = [];
28
+ for (const [, block] of cssText.matchAll(/@font-face\s*\{([^}]*)\}/gi)) {
29
+ const family = unquote(descriptor(block, "font-family") ?? "");
30
+ if (!usage.families.has(family.toLowerCase())) continue;
31
+ const unicodeRange = descriptor(block, "unicode-range");
32
+ if (unicodeRange && !rangeCovers(unicodeRange, codePoints)) continue;
33
+ const src = /url\(([^)]*)\)(?:\s*format\(([^)]*)\))?/i.exec(block);
34
+ if (!src) continue;
35
+ let url;
36
+ try {
37
+ url = new URL(unquote(src[1]), baseHref).href;
38
+ } catch {
39
+ continue;
40
+ }
41
+ faces.push({
42
+ family,
43
+ format: src[2] === void 0 ? void 0 : unquote(src[2]),
44
+ style: descriptor(block, "font-style"),
45
+ unicodeRange,
46
+ url,
47
+ weight: descriptor(block, "font-weight")
48
+ });
49
+ }
50
+ return faces;
51
+ }
52
+ async function toDataUrl(url) {
53
+ if (url.startsWith("data:")) return url;
54
+ const response = await fetch(url);
55
+ if (!response.ok) throw new Error(`${response.status} ${url}`);
56
+ const blob = await response.blob();
57
+ return new Promise((resolve, reject) => {
58
+ const reader = new FileReader();
59
+ reader.onload = () => resolve(reader.result);
60
+ reader.onerror = () => reject(reader.error);
61
+ reader.readAsDataURL(blob);
62
+ });
63
+ }
64
+ var MAX_IMPORT_DEPTH = 4;
65
+ async function expandImports(cssText, baseHref, fetchText, depth = 0) {
66
+ const own = {
67
+ baseHref,
68
+ cssText
69
+ };
70
+ if (depth >= MAX_IMPORT_DEPTH) return [own];
71
+ return [...(await Promise.all([...cssText.matchAll(/@import\s+(?:url\(([^)]*)\)|(["'][^"']*["']))/gi)].map(async (match) => {
72
+ try {
73
+ const href = new URL(unquote(match[1] ?? match[2]), baseHref).href;
74
+ return await expandImports(await fetchText(href), href, fetchText, depth + 1);
75
+ } catch {
76
+ return [];
77
+ }
78
+ }))).flat(), own];
79
+ }
80
+ async function fetchText(url) {
81
+ const response = await fetch(url);
82
+ if (!response.ok) throw new Error(`${response.status} ${url}`);
83
+ return response.text();
84
+ }
85
+ async function sheetSources() {
86
+ return (await Promise.all([...document.styleSheets].map(async (sheet) => {
87
+ const baseHref = sheet.href ?? document.baseURI;
88
+ let cssText;
89
+ try {
90
+ cssText = [...sheet.cssRules].map((rule) => rule.cssText).filter((text) => text.startsWith("@font-face") || text.startsWith("@import")).join("\n");
91
+ } catch {
92
+ if (!sheet.href) return [];
93
+ try {
94
+ cssText = await fetchText(sheet.href);
95
+ } catch {
96
+ return [];
97
+ }
98
+ }
99
+ return expandImports(cssText, baseHref, fetchText);
100
+ }))).flat();
101
+ }
102
+ async function embeddedFontCss(usage) {
103
+ if (typeof document === "undefined" || usage.families.size === 0) return "";
104
+ const faces = (await sheetSources()).flatMap((source) => collectFontFaces(source.cssText, source.baseHref, usage));
105
+ return (await Promise.all(faces.map(async (face) => {
106
+ try {
107
+ const data = await toDataUrl(face.url);
108
+ return [
109
+ `@font-face{font-family:"${face.family}";src:url("${data}")${face.format ? ` format("${face.format}")` : ""}`,
110
+ face.weight && `font-weight:${face.weight}`,
111
+ face.style && `font-style:${face.style}`,
112
+ face.unicodeRange && `unicode-range:${face.unicodeRange}`
113
+ ].filter(Boolean).join(";").concat("}");
114
+ } catch {
115
+ return "";
116
+ }
117
+ }))).join("");
118
+ }
119
+ //#endregion
120
+ //#region src/export/svg.tsx
121
+ var DEFAULT_PADDING = 16;
122
+ var EMPTY_SIZE = 100;
123
+ function fontUsage(elements, handFontOverride) {
124
+ const families = /* @__PURE__ */ new Set();
125
+ let text = "";
126
+ for (const el of elements) if (el.type === "text") {
127
+ const stack = handFontOverride && isHandFontFamily(el.fontFamily) ? handFontOverride : fontFamilyToCss(el.fontFamily);
128
+ for (const family of familiesOf(stack)) families.add(family);
129
+ text += el.text;
130
+ } else if (el.type === "richtext") {
131
+ for (const family of familiesOf(SANS_FONT_STACK)) families.add(family);
132
+ text += richTextPlainText(el.content?.root);
133
+ }
134
+ return {
135
+ families,
136
+ text
137
+ };
138
+ }
139
+ async function inlineFiles(files) {
140
+ if (!files) return files;
141
+ const entries = await Promise.all(Object.entries(files).map(async ([id, file]) => {
142
+ if (!/^https?:/i.test(file.dataURL)) return [id, file];
143
+ try {
144
+ return [id, {
145
+ ...file,
146
+ dataURL: await toDataUrl(file.dataURL)
147
+ }];
148
+ } catch {
149
+ return [id, file];
150
+ }
151
+ }));
152
+ return Object.fromEntries(entries);
153
+ }
154
+ async function renderSvg(scene, options = {}) {
155
+ const { background = "#ffffff", embedFonts = true, handFontOverride } = options;
156
+ const padding = options.padding ?? DEFAULT_PADDING;
157
+ const elements = resolveRichTextHeights(scene.elements.filter((el) => !el.isDeleted));
158
+ const [minX, minY, maxX, maxY] = elements.length > 0 ? getCommonBounds(elements) : [
159
+ 0,
160
+ 0,
161
+ EMPTY_SIZE,
162
+ EMPTY_SIZE
163
+ ];
164
+ const x = minX - padding;
165
+ const y = minY - padding;
166
+ const width = maxX - minX + padding * 2;
167
+ const height = maxY - minY + padding * 2;
168
+ const [fontCss, files] = await Promise.all([embedFonts ? embeddedFontCss(fontUsage(elements, handFontOverride)) : "", inlineFiles(scene.files)]);
169
+ const host = document.createElement("div");
170
+ const root = createRoot(host);
171
+ flushSync(() => {
172
+ root.render(/* @__PURE__ */ jsxs("svg", {
173
+ height,
174
+ viewBox: `${x} ${y} ${width} ${height}`,
175
+ width,
176
+ xmlns: "http://www.w3.org/2000/svg",
177
+ children: [
178
+ fontCss && /* @__PURE__ */ jsx("style", { children: fontCss }),
179
+ background && /* @__PURE__ */ jsx("rect", {
180
+ "data-export-background": "",
181
+ fill: background,
182
+ height,
183
+ width,
184
+ x,
185
+ y
186
+ }),
187
+ /* @__PURE__ */ jsx(SceneExportContext, {
188
+ value: true,
189
+ children: /* @__PURE__ */ jsx(SceneContent, {
190
+ files,
191
+ handFontOverride,
192
+ scene: {
193
+ elements,
194
+ files
195
+ }
196
+ })
197
+ })
198
+ ]
199
+ }));
200
+ });
201
+ const svg = new XMLSerializer().serializeToString(host.firstElementChild);
202
+ root.unmount();
203
+ return {
204
+ height,
205
+ svg,
206
+ width
207
+ };
208
+ }
209
+ async function exportToSvg(scene, options) {
210
+ return (await renderSvg(scene, options)).svg;
211
+ }
212
+ //#endregion
213
+ //#region src/export/png.ts
214
+ var DEFAULT_MAX_SIZE = 8192;
215
+ function rasterScale(width, height, scale, maxSize) {
216
+ const longest = Math.max(width, height) * scale;
217
+ return longest > maxSize ? scale * maxSize / longest : scale;
218
+ }
219
+ function loadImage(src) {
220
+ return new Promise((resolve, reject) => {
221
+ const image = new Image();
222
+ image.onload = () => resolve(image);
223
+ image.onerror = () => reject(/* @__PURE__ */ new Error("whiteboard export: the svg could not be rasterized"));
224
+ image.src = src;
225
+ });
226
+ }
227
+ async function exportToBlob(scene, options = {}) {
228
+ const { maxSize = DEFAULT_MAX_SIZE, mimeType = "image/png", quality, scale = 1, ...rest } = options;
229
+ const { height, svg, width } = await renderSvg(scene, rest);
230
+ const ratio = rasterScale(width, height, scale, maxSize);
231
+ const url = URL.createObjectURL(new Blob([svg], { type: "image/svg+xml;charset=utf-8" }));
232
+ try {
233
+ const image = await loadImage(url);
234
+ const canvas = document.createElement("canvas");
235
+ canvas.width = Math.max(1, Math.round(width * ratio));
236
+ canvas.height = Math.max(1, Math.round(height * ratio));
237
+ const context = canvas.getContext("2d");
238
+ if (!context) throw new Error("whiteboard export: no 2d canvas context");
239
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
240
+ return await new Promise((resolve, reject) => {
241
+ canvas.toBlob((blob) => blob ? resolve(blob) : reject(/* @__PURE__ */ new Error("whiteboard export: empty image")), mimeType, quality);
242
+ });
243
+ } finally {
244
+ URL.revokeObjectURL(url);
245
+ }
246
+ }
247
+ //#endregion
248
+ export { exportToSvg as n, collectFontFaces as r, exportToBlob as t };