@widgetic/canvas 0.5.34 → 0.5.36

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 (212) hide show
  1. package/README.md +105 -36
  2. package/dist/canvas/DomCanvas.svelte +454 -0
  3. package/dist/canvas/DomCanvas.svelte.d.ts +222 -0
  4. package/dist/canvas/autosaveScheduler.d.ts +58 -0
  5. package/dist/canvas/autosaveScheduler.js +157 -0
  6. package/dist/canvas/boardFrame.d.ts +13 -0
  7. package/dist/canvas/boardFrame.js +13 -0
  8. package/dist/canvas/boardSurface.d.ts +9 -0
  9. package/dist/canvas/boardSurface.js +9 -0
  10. package/dist/canvas/chromeLayout.d.ts +76 -0
  11. package/dist/canvas/chromeLayout.js +121 -0
  12. package/dist/canvas/emptyBoardHint.d.ts +17 -0
  13. package/dist/canvas/emptyBoardHint.js +12 -0
  14. package/dist/canvas/eventScope.d.ts +1 -1
  15. package/dist/canvas/eventScope.js +1 -1
  16. package/dist/canvas/host/CanvasHost.d.ts +351 -0
  17. package/dist/canvas/host/CanvasHost.js +1740 -0
  18. package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
  19. package/dist/canvas/host/CanvasHostApi.js +95 -0
  20. package/dist/canvas/host/browserServices.d.ts +46 -0
  21. package/dist/canvas/host/browserServices.js +167 -0
  22. package/dist/canvas/host/conversion.d.ts +51 -0
  23. package/dist/canvas/host/conversion.js +123 -0
  24. package/dist/canvas/host/hostObject.d.ts +40 -0
  25. package/dist/canvas/host/hostObject.js +93 -0
  26. package/dist/canvas/host/pageEvents.d.ts +24 -0
  27. package/dist/canvas/host/pageEvents.js +35 -0
  28. package/dist/canvas/host/screenRects.d.ts +66 -0
  29. package/dist/canvas/host/screenRects.js +102 -0
  30. package/dist/canvas/host/strokeSnap.d.ts +67 -0
  31. package/dist/canvas/host/strokeSnap.js +165 -0
  32. package/dist/canvas/index.d.ts +9 -7
  33. package/dist/canvas/index.js +9 -7
  34. package/dist/canvas/openMarks.d.ts +17 -0
  35. package/dist/canvas/openMarks.js +26 -0
  36. package/dist/canvas/panZoomPosition.d.ts +15 -0
  37. package/dist/canvas/panZoomPosition.js +16 -0
  38. package/dist/canvas/preferredTextFont.d.ts +12 -0
  39. package/dist/canvas/preferredTextFont.js +38 -0
  40. package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
  41. package/dist/canvas/shapes/ShapeLibrary.js +13 -1
  42. package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
  43. package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
  44. package/dist/canvas/toolbarPosition.d.ts +24 -0
  45. package/dist/canvas/toolbarPosition.js +24 -0
  46. package/dist/canvas/types.d.ts +14 -0
  47. package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
  48. package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
  49. package/dist/canvas/ui/CanvasHint.svelte +20 -0
  50. package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
  51. package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
  52. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
  53. package/dist/canvas/ui/ColorField.svelte +155 -0
  54. package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
  55. package/dist/canvas/ui/LoadNotice.svelte +39 -0
  56. package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
  57. package/dist/canvas/ui/SelectionPanel.svelte +300 -0
  58. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
  59. package/dist/canvas/ui/SelectorBar.svelte +82 -0
  60. package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
  61. package/dist/canvas/ui/ShapesMenu.svelte +185 -0
  62. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
  63. package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
  64. package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
  65. package/dist/canvas/ui/ToolButton.svelte +78 -0
  66. package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
  67. package/dist/canvas/ui/WidgetActions.svelte +152 -0
  68. package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
  69. package/dist/canvas/ui/ZoomControl.svelte +89 -0
  70. package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
  71. package/dist/canvas/ui/colorModel.d.ts +18 -0
  72. package/dist/canvas/ui/colorModel.js +85 -0
  73. package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
  74. package/dist/canvas/ui/colorPickerMessages.js +15 -0
  75. package/dist/canvas/ui/floatingCard.d.ts +107 -0
  76. package/dist/canvas/ui/floatingCard.js +107 -0
  77. package/dist/canvas/ui/floatingLayer.d.ts +21 -0
  78. package/dist/canvas/ui/floatingLayer.js +52 -0
  79. package/dist/canvas/ui/icons.d.ts +12 -0
  80. package/dist/canvas/ui/icons.js +7 -0
  81. package/dist/canvas/ui/keyHints.d.ts +27 -0
  82. package/dist/canvas/ui/keyHints.js +43 -0
  83. package/dist/canvas/ui/popoverSide.d.ts +5 -0
  84. package/dist/canvas/ui/popoverSide.js +20 -0
  85. package/dist/canvas/ui/selectionTraits.d.ts +61 -0
  86. package/dist/canvas/ui/selectionTraits.js +99 -0
  87. package/dist/canvas/view/CanvasStage.svelte +132 -0
  88. package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
  89. package/dist/canvas/view/EraserTrail.svelte +50 -0
  90. package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
  91. package/dist/canvas/view/ObjectView.svelte +245 -0
  92. package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
  93. package/dist/canvas/view/SelectionOverlay.svelte +487 -0
  94. package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
  95. package/dist/canvas/view/TextEditor.svelte +76 -0
  96. package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
  97. package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
  98. package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
  99. package/dist/canvas/view/erasingMarks.d.ts +13 -0
  100. package/dist/canvas/view/erasingMarks.js +34 -0
  101. package/dist/canvas/view/geometry.d.ts +169 -0
  102. package/dist/canvas/view/geometry.js +272 -0
  103. package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
  104. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
  105. package/dist/components/index.js +1 -1
  106. package/dist/components/input-controls/ColorIC.svelte +2 -2
  107. package/dist/engine/EngineCore.d.ts +273 -0
  108. package/dist/engine/EngineCore.js +1051 -0
  109. package/dist/engine/codec/canvasDocument.d.ts +57 -0
  110. package/dist/engine/codec/canvasDocument.js +471 -0
  111. package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
  112. package/dist/engine/codec/hostReadableKeys.js +25 -0
  113. package/dist/engine/core/arrange.d.ts +20 -0
  114. package/dist/engine/core/arrange.js +81 -0
  115. package/dist/engine/core/arrow.d.ts +91 -0
  116. package/dist/engine/core/arrow.js +182 -0
  117. package/dist/engine/core/brush.d.ts +68 -0
  118. package/dist/engine/core/brush.js +173 -0
  119. package/dist/engine/core/defaults.d.ts +70 -0
  120. package/dist/engine/core/defaults.js +158 -0
  121. package/dist/engine/core/freehand.d.ts +130 -0
  122. package/dist/engine/core/freehand.js +430 -0
  123. package/dist/engine/core/geometry.d.ts +44 -0
  124. package/dist/engine/core/geometry.js +216 -0
  125. package/dist/engine/core/history.d.ts +39 -0
  126. package/dist/engine/core/history.js +69 -0
  127. package/dist/engine/core/hitTest.d.ts +54 -0
  128. package/dist/engine/core/hitTest.js +298 -0
  129. package/dist/engine/core/matrix.d.ts +47 -0
  130. package/dist/engine/core/matrix.js +101 -0
  131. package/dist/engine/core/pathData.d.ts +50 -0
  132. package/dist/engine/core/pathData.js +550 -0
  133. package/dist/engine/core/rotationReset.d.ts +10 -0
  134. package/dist/engine/core/rotationReset.js +17 -0
  135. package/dist/engine/core/scene.d.ts +99 -0
  136. package/dist/engine/core/scene.js +450 -0
  137. package/dist/engine/core/scribble.d.ts +64 -0
  138. package/dist/engine/core/scribble.js +121 -0
  139. package/dist/engine/core/shapePaths.d.ts +34 -0
  140. package/dist/engine/core/shapePaths.js +69 -0
  141. package/dist/engine/core/shapeTools.d.ts +80 -0
  142. package/dist/engine/core/shapeTools.js +161 -0
  143. package/dist/engine/core/snapping.d.ts +64 -0
  144. package/dist/engine/core/snapping.js +164 -0
  145. package/dist/engine/core/style.d.ts +40 -0
  146. package/dist/engine/core/style.js +151 -0
  147. package/dist/engine/core/transform.d.ts +79 -0
  148. package/dist/engine/core/transform.js +258 -0
  149. package/dist/engine/core/types.d.ts +238 -0
  150. package/dist/engine/core/types.js +31 -0
  151. package/dist/engine/core/viewport.d.ts +32 -0
  152. package/dist/engine/core/viewport.js +84 -0
  153. package/dist/engine/input/PointerController.d.ts +38 -0
  154. package/dist/engine/input/PointerController.js +545 -0
  155. package/dist/engine/input/arrowHandles.d.ts +38 -0
  156. package/dist/engine/input/arrowHandles.js +60 -0
  157. package/dist/engine/input/gestures.d.ts +79 -0
  158. package/dist/engine/input/gestures.js +769 -0
  159. package/dist/engine/input/hoverCursor.d.ts +29 -0
  160. package/dist/engine/input/hoverCursor.js +23 -0
  161. package/dist/engine/input/keyboard.d.ts +75 -0
  162. package/dist/engine/input/keyboard.js +264 -0
  163. package/dist/engine/input/selectionHandles.d.ts +89 -0
  164. package/dist/engine/input/selectionHandles.js +169 -0
  165. package/dist/engine/input/types.d.ts +82 -0
  166. package/dist/engine/input/types.js +5 -0
  167. package/dist/engine/render/rasterize.d.ts +74 -0
  168. package/dist/engine/render/rasterize.js +273 -0
  169. package/dist/engine/state.d.ts +124 -0
  170. package/dist/engine/state.js +47 -0
  171. package/dist/engine/text/layoutText.d.ts +53 -0
  172. package/dist/engine/text/layoutText.js +170 -0
  173. package/dist/engine/widgets.d.ts +124 -0
  174. package/dist/engine/widgets.js +345 -0
  175. package/dist/i18n/labels.d.ts +4 -15
  176. package/dist/i18n/labels.js +33 -53
  177. package/dist/i18n/language.d.ts +3 -3
  178. package/dist/i18n/messages.d.ts +51 -122
  179. package/dist/i18n/messages.js +58 -131
  180. package/dist/i18n/shortcuts.d.ts +0 -1
  181. package/dist/i18n/shortcuts.js +2 -11
  182. package/dist/index.d.ts +6 -2
  183. package/dist/index.js +6 -2
  184. package/package.json +30 -5
  185. package/dist/canvas/Canvas.svelte +0 -13299
  186. package/dist/canvas/Canvas.svelte.d.ts +0 -281
  187. package/dist/canvas/CanvasToolbar.svelte +0 -1498
  188. package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
  189. package/dist/canvas/ContextMenu.svelte +0 -305
  190. package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
  191. package/dist/canvas/PanZoomPanel.svelte +0 -478
  192. package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
  193. package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
  194. package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
  195. package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
  196. package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
  197. package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
  198. package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
  199. package/dist/canvas/shadowRootText.d.ts +0 -5
  200. package/dist/canvas/shadowRootText.js +0 -43
  201. package/dist/canvas/shapes/FrameShape.d.ts +0 -97
  202. package/dist/canvas/shapes/FrameShape.js +0 -953
  203. package/dist/canvas/shapes/ImageShape.d.ts +0 -47
  204. package/dist/canvas/shapes/ImageShape.js +0 -339
  205. package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
  206. package/dist/canvas/shapes/WidgetShape.js +0 -200
  207. package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
  208. package/dist/canvas/widgetPreviewGeometry.js +0 -66
  209. package/dist/i18n/shapeWords.d.ts +0 -30
  210. package/dist/i18n/shapeWords.js +0 -36
  211. package/dist/i18n/slots.d.ts +0 -20
  212. package/dist/i18n/slots.js +0 -40
@@ -0,0 +1,222 @@
1
+ import type { CanvasHostProps, SelectorGuide } from './host/CanvasHost.js';
2
+ import type { PanZoomPosition } from './panZoomPosition.js';
3
+ import type { ToolbarPosition } from './toolbarPosition.js';
4
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
+ $$bindings?: Bindings;
7
+ } & Exports;
8
+ (internal: unknown, props: Props & {
9
+ $$events?: Events;
10
+ $$slots?: Slots;
11
+ }): Exports & {
12
+ $set?: any;
13
+ $on?: any;
14
+ };
15
+ z_$$bindings?: Bindings;
16
+ }
17
+ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
18
+ /**
19
+ * COMPONENT PROPS
20
+ */ class?: string;
21
+ style?: string;
22
+ /** Site /canvas embed sits flush under AppHeader: skip the frame (double stroke). */ showContainerFrame?: CanvasHostProps["showContainerFrame"];
23
+ /** The id or class of an element of the page that stands above its live widgets: the frame of a selected widget card is drawn there. */ widgetSelectionLayerTarget?: CanvasHostProps["widgetSelectionLayerTarget"];
24
+ onObjectClick?: CanvasHostProps["onObjectClick"];
25
+ panZoomPosition?: PanZoomPosition;
26
+ toolbarPosition?: ToolbarPosition;
27
+ wireframeMode?: CanvasHostProps["wireframeMode"];
28
+ advancedFeatures?: CanvasHostProps["advancedFeatures"];
29
+ /** The element selector on the toolbar. The host owns whether it is on. */ showElementSelector?: CanvasHostProps["showElementSelector"];
30
+ /** Drawing tools stay until the first generation. After that, only the selector remains. */ showDrawingTools?: CanvasHostProps["showDrawingTools"];
31
+ elementSelectorActive?: CanvasHostProps["elementSelectorActive"];
32
+ onToggleElementSelector?: CanvasHostProps["onToggleElementSelector"];
33
+ /** Words for the selector bar that replaces the drawing tools. */ selectorGuide?: SelectorGuide | null;
34
+ /** The zoom card. Off on the site when debug is off. The save control stays. */ showZoomPanel?: CanvasHostProps["showZoomPanel"];
35
+ /** Accepted for the pages that set it. The design puts Image in the Shapes menu, so it no longer changes what is drawn. */ mediaBtsOnBar?: CanvasHostProps["mediaBtsOnBar"];
36
+ initialData?: CanvasHostProps["initialData"];
37
+ onReady?: CanvasHostProps["onReady"];
38
+ isExternalDataLoading?: CanvasHostProps["isExternalDataLoading"];
39
+ onBeforeUnmount?: CanvasHostProps["onBeforeUnmount"];
40
+ onAutoSave?: CanvasHostProps["onAutoSave"];
41
+ autosaveDelayMs?: CanvasHostProps["autosaveDelayMs"];
42
+ autosaveMaxWaitMs?: CanvasHostProps["autosaveMaxWaitMs"];
43
+ suspendAutosave?: CanvasHostProps["suspendAutosave"];
44
+ showSaveButton?: CanvasHostProps["showSaveButton"];
45
+ onCanvasDirty?: CanvasHostProps["onCanvasDirty"];
46
+ onCanvasCleared?: CanvasHostProps["onCanvasCleared"];
47
+ onConvertToWidget?: CanvasHostProps["onConvertToWidget"];
48
+ onWidgetImageClick?: CanvasHostProps["onWidgetImageClick"];
49
+ onRecognizeStroke?: CanvasHostProps["onRecognizeStroke"];
50
+ onNonWidgetSelected?: CanvasHostProps["onNonWidgetSelected"];
51
+ onWidgetShapeDuplicated?: CanvasHostProps["onWidgetShapeDuplicated"];
52
+ onWidgetShapeDeleting?: CanvasHostProps["onWidgetShapeDeleting"];
53
+ onWidgetRename?: CanvasHostProps["onWidgetRename"];
54
+ onRefreshScreenshot?: CanvasHostProps["onRefreshScreenshot"];
55
+ /** Host persists canvases.primary_widget_id after the canvas marks the primary widget. */ onSetPrimaryWidget?: CanvasHostProps["onSetPrimaryWidget"];
56
+ /** Throttled paint hook for HTML overlays (e.g. the live widgets laid over the cards). */ onAfterRender?: CanvasHostProps["onAfterRender"];
57
+ getWidgetName?: CanvasHostProps["getWidgetName"];
58
+ /** Bumped when names change so the names are resolved again. */ widgetNameRevision?: CanvasHostProps["widgetNameRevision"];
59
+ /** Returns true when widgetId still exists in the host widget list. */ isWidgetKnown?: CanvasHostProps["isWidgetKnown"];
60
+ showLogs?: CanvasHostProps["showLogs"];
61
+ /**
62
+ * Whether a freehand stroke that is a clean shape (a circle, an oval, a rectangle, a triangle, a diamond, a hexagon)
63
+ * becomes that shape. Off unless a page passes true: the package's own flag turns it on for every page.
64
+ */ shapeSnap?: CanvasHostProps["shapeSnap"];
65
+ /**
66
+ * The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
67
+ * the page's own words are in; `messages` are the page's own words, keyed like CANVAS_MESSAGES (a key left out
68
+ * keeps its English text). Without them the canvas speaks English. Both can change while the canvas is open.
69
+ */ locale?: string | null;
70
+ messages?: Readonly<Record<string, unknown>> | null;
71
+ /**
72
+ * THE FUNCTIONS THE PAGE CALLS
73
+ *
74
+ * Each one is the host's method of the same name, with its type. The list is `CANVAS_EXPORTED_FUNCTION_NAMES`.
75
+ */ shapeFillColor?: () => string;
76
+ captureCanvasSketch?: () => Promise<string>;
77
+ absorbCanvasSketchIntoWidget?: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
78
+ deselectAll?: () => void;
79
+ duplicateSelectedObjects?: () => import("../engine/core/types.js").ObjectId[];
80
+ deleteSelectedObjects?: () => Promise<boolean>;
81
+ markSelectedAsDuplicating?: () => void;
82
+ linkObjectToWidget?: (target: import("../engine/core/types.js").ObjectId | {
83
+ id?: import("../engine/core/types.js").ObjectId;
84
+ _objectId?: import("../engine/core/types.js").ObjectId;
85
+ } | null | undefined, widgetId: string, widgetName?: string | null) => void;
86
+ linkFrameToWidget?: (objectId: string, widgetId: string) => void;
87
+ replaceObjectWithWidgetImage?: (objectId: string, widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
88
+ updateWidgetImage?: (widgetId: string, newScreenshotDataUrl: string) => void;
89
+ selectWidgetShape?: (widgetId: string) => boolean;
90
+ listWidgetShapeScreenRects?: () => import("./host/screenRects.js").WidgetScreenRect[];
91
+ getWidgetShapeScreenRect?: (widgetId: string) => import("./host/screenRects.js").ScreenRect | null;
92
+ getObjectScreenRect?: (objectId: string) => import("./host/screenRects.js").ScreenRect | null;
93
+ getWidgetShapeDataUrl?: (widgetId: string) => string | null;
94
+ setWidgetShapeLivePreviewHiddenImage?: (widgetId: string, hidden: boolean) => void;
95
+ addWidgetShape?: (widgetId: string, widgetName?: string, gridIndex?: number, totalCount?: number, previewImageUrl?: string | null) => string | null;
96
+ getLinkedWidgetIds?: () => Set<string>;
97
+ keepOnlyWidgetShape?: (widgetId: string) => number;
98
+ hydrateWidgetShapeMetadata?: (widgetsById: Map<string, import("../engine/widgets.js").WidgetMetadata>) => number;
99
+ markOrphanedWidgetShapes?: (validWidgetIds: Set<string>) => number;
100
+ onSelectSelectTool?: () => void;
101
+ onSelectLibraryShapeTool?: (shapeKey: string, _pathData?: string) => void;
102
+ onSelectEraseTool?: () => void;
103
+ onSelectDrawTool?: () => void;
104
+ onSelectTextTool?: () => void;
105
+ onSelectArrowTool?: () => void;
106
+ onSelectShapeTool?: (shapeType: import("./host/CanvasHost.js").ShapeToolName) => void;
107
+ onSelectFrameTool?: () => void;
108
+ setPrimaryWidgetShape?: (widgetId: string) => boolean;
109
+ getPrimaryWidgetId?: () => string | null;
110
+ setWidgetShapeBodyDragAllowed?: (widgetId: string, allowed: boolean) => void;
111
+ translateWidgetShapeByScreen?: (widgetId: string, dxScreen: number, dyScreen: number) => boolean;
112
+ commitWidgetShapeTranslate?: (_widgetId?: string | null) => void;
113
+ setWidgetShapeOverlayDragActive?: (active: boolean) => void;
114
+ selectWidgetShapeById?: (widgetId: string) => boolean;
115
+ getSelectedWidgetShapeId?: () => string | null;
116
+ getSelectedObject?: () => import("./host/hostObject.js").HostObject | null;
117
+ getHoveredWidgetShapeId?: () => string | null;
118
+ onSelectImageTool?: () => void;
119
+ onSelectVideoTool?: () => void;
120
+ onSelectPanTool?: () => void;
121
+ zoomIn?: () => void;
122
+ zoomOut?: () => void;
123
+ zoomTo?: (percent: number) => void;
124
+ zoomReset?: () => void;
125
+ zoomFit?: () => void;
126
+ onGroupSelection?: () => string | null;
127
+ onUngroupSelection?: () => void;
128
+ onSelectAllObjects?: () => void;
129
+ onDeselectAllObjects?: () => void;
130
+ flushAutosave?: () => Promise<void>;
131
+ saveNow?: () => void;
132
+ undo?: () => Promise<void>;
133
+ redo?: () => Promise<void>;
134
+ saveCanvas?: () => string | null;
135
+ loadCanvas?: (jsonString: string) => Promise<void>;
136
+ onClearAllObjects?: () => void;
137
+ addText?: () => import("../engine/core/types.js").ObjectId;
138
+ addTriangle?: () => import("../engine/core/types.js").ObjectId | null;
139
+ addRect?: () => import("../engine/core/types.js").ObjectId | null;
140
+ addCircle?: () => import("../engine/core/types.js").ObjectId | null;
141
+ addFrame?: () => null;
142
+ addImage?: () => Promise<void>;
143
+ removeSketchObjectsKeepingWidget?: (widgetId: string) => number;
144
+ }, {
145
+ [evt: string]: CustomEvent<any>;
146
+ }, {}, {
147
+ /**
148
+ * THE FUNCTIONS THE PAGE CALLS
149
+ *
150
+ * Each one is the host's method of the same name, with its type. The list is `CANVAS_EXPORTED_FUNCTION_NAMES`.
151
+ */ shapeFillColor: () => string;
152
+ captureCanvasSketch: () => Promise<string>;
153
+ absorbCanvasSketchIntoWidget: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
154
+ deselectAll: () => void;
155
+ duplicateSelectedObjects: () => import("../engine/core/types.js").ObjectId[];
156
+ deleteSelectedObjects: () => Promise<boolean>;
157
+ markSelectedAsDuplicating: () => void;
158
+ linkObjectToWidget: (target: import("../engine/core/types.js").ObjectId | {
159
+ id?: import("../engine/core/types.js").ObjectId;
160
+ _objectId?: import("../engine/core/types.js").ObjectId;
161
+ } | null | undefined, widgetId: string, widgetName?: string | null) => void;
162
+ linkFrameToWidget: (objectId: string, widgetId: string) => void;
163
+ replaceObjectWithWidgetImage: (objectId: string, widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
164
+ updateWidgetImage: (widgetId: string, newScreenshotDataUrl: string) => void;
165
+ selectWidgetShape: (widgetId: string) => boolean;
166
+ listWidgetShapeScreenRects: () => import("./host/screenRects.js").WidgetScreenRect[];
167
+ getWidgetShapeScreenRect: (widgetId: string) => import("./host/screenRects.js").ScreenRect | null;
168
+ getObjectScreenRect: (objectId: string) => import("./host/screenRects.js").ScreenRect | null;
169
+ getWidgetShapeDataUrl: (widgetId: string) => string | null;
170
+ setWidgetShapeLivePreviewHiddenImage: (widgetId: string, hidden: boolean) => void;
171
+ addWidgetShape: (widgetId: string, widgetName?: string, gridIndex?: number, totalCount?: number, previewImageUrl?: string | null) => string | null;
172
+ getLinkedWidgetIds: () => Set<string>;
173
+ keepOnlyWidgetShape: (widgetId: string) => number;
174
+ hydrateWidgetShapeMetadata: (widgetsById: Map<string, import("../engine/widgets.js").WidgetMetadata>) => number;
175
+ markOrphanedWidgetShapes: (validWidgetIds: Set<string>) => number;
176
+ onSelectSelectTool: () => void;
177
+ onSelectLibraryShapeTool: (shapeKey: string, _pathData?: string) => void;
178
+ onSelectEraseTool: () => void;
179
+ onSelectDrawTool: () => void;
180
+ onSelectTextTool: () => void;
181
+ onSelectArrowTool: () => void;
182
+ onSelectShapeTool: (shapeType: import("./host/CanvasHost.js").ShapeToolName) => void;
183
+ onSelectFrameTool: () => void;
184
+ setPrimaryWidgetShape: (widgetId: string) => boolean;
185
+ getPrimaryWidgetId: () => string | null;
186
+ setWidgetShapeBodyDragAllowed: (widgetId: string, allowed: boolean) => void;
187
+ translateWidgetShapeByScreen: (widgetId: string, dxScreen: number, dyScreen: number) => boolean;
188
+ commitWidgetShapeTranslate: (_widgetId?: string | null) => void;
189
+ setWidgetShapeOverlayDragActive: (active: boolean) => void;
190
+ selectWidgetShapeById: (widgetId: string) => boolean;
191
+ getSelectedWidgetShapeId: () => string | null;
192
+ getSelectedObject: () => import("./host/hostObject.js").HostObject | null;
193
+ getHoveredWidgetShapeId: () => string | null;
194
+ onSelectImageTool: () => void;
195
+ onSelectVideoTool: () => void;
196
+ onSelectPanTool: () => void;
197
+ zoomIn: () => void;
198
+ zoomOut: () => void;
199
+ zoomTo: (percent: number) => void;
200
+ zoomReset: () => void;
201
+ zoomFit: () => void;
202
+ onGroupSelection: () => string | null;
203
+ onUngroupSelection: () => void;
204
+ onSelectAllObjects: () => void;
205
+ onDeselectAllObjects: () => void;
206
+ flushAutosave: () => Promise<void>;
207
+ saveNow: () => void;
208
+ undo: () => Promise<void>;
209
+ redo: () => Promise<void>;
210
+ saveCanvas: () => string | null;
211
+ loadCanvas: (jsonString: string) => Promise<void>;
212
+ onClearAllObjects: () => void;
213
+ addText: () => import("../engine/core/types.js").ObjectId;
214
+ addTriangle: () => import("../engine/core/types.js").ObjectId | null;
215
+ addRect: () => import("../engine/core/types.js").ObjectId | null;
216
+ addCircle: () => import("../engine/core/types.js").ObjectId | null;
217
+ addFrame: () => null;
218
+ addImage: () => Promise<void>;
219
+ removeSketchObjectsKeepingWidget: (widgetId: string) => number;
220
+ }, string>;
221
+ type DomCanvas = InstanceType<typeof DomCanvas>;
222
+ export default DomCanvas;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The buffer between a person who edits the board and the server that keeps it.
3
+ *
4
+ * A save is not made at every change: a drag, a run of nudges or a long stretch of drawing would send the whole board
5
+ * to the server fifty times. The scheduler keeps the rule in one place:
6
+ *
7
+ * - a save starts after a **quiet delay** since the last change (a trailing debounce), so a burst is one save;
8
+ * - a person who never pauses still gets a save every **longest wait**, so a crash costs seconds, not minutes;
9
+ * - a save is **held back** while the host asks for it (a code generation makes the page thread busy), for as long as
10
+ * the host asks, however long that is;
11
+ * - **one save at a time**: when a save is still on its way at the moment the next one is due, the next waits for it
12
+ * and everything that changed meanwhile goes out in a single save after it. A slow server is never flooded;
13
+ * - **flush** sends whatever is unsaved at once, whatever the delay and the hold, for the moments a page is about to
14
+ * go (the tab goes to the background, the page is hidden, the editor closes);
15
+ * - a save that fails leaves the changes unsaved and says so, and **does not try again by itself**: the next change, or
16
+ * the next flush, is the retry. A server that is down is not hammered.
17
+ *
18
+ * Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
19
+ */
20
+ /** The clock the scheduler reads and sets timers with. Tests pass one they move by hand. */
21
+ export interface AutosaveClock {
22
+ /** Milliseconds, from any fixed point. */
23
+ now(): number;
24
+ /** Calls `callback` once, `delayMs` from now. Returns what {@link clearTimer} needs to take it back. */
25
+ setTimer(callback: () => void, delayMs: number): unknown;
26
+ clearTimer(handle: unknown): void;
27
+ }
28
+ export interface AutosaveSchedulerOptions {
29
+ /** The quiet time after the last change before a save starts, in milliseconds. Read at every change. */
30
+ getDelayMs: () => number;
31
+ /** The longest a change waits before a save starts, however busy the person stays. 0 means no limit. Read at every change. */
32
+ getMaxWaitMs: () => number;
33
+ /**
34
+ * Makes the save. It may return a promise: while that is pending, no second save starts. A save that throws or
35
+ * rejects counts as failed. A save that finds it has nothing to save yet (the board is still loading) calls
36
+ * {@link AutosaveScheduler.markChanged} again to ask for another go a delay later.
37
+ */
38
+ save: () => void | Promise<unknown>;
39
+ /** True while the host wants saves to wait. A save that falls due then looks again a delay later. */
40
+ isSuspended?: () => boolean;
41
+ /** Told when a save failed. The changes stay unsaved. */
42
+ onSaveFailed?: (error: unknown) => void;
43
+ /** Defaults to the real one. */
44
+ clock?: AutosaveClock;
45
+ }
46
+ export interface AutosaveScheduler {
47
+ /** Something changed that is not saved: starts (or restarts) the quiet delay. */
48
+ markChanged(): void;
49
+ /** Saves whatever is unsaved now, after a save that is on its way, whatever the delay and the hold. Resolves once it is done. Never rejects. */
50
+ flush(): Promise<void>;
51
+ /** Forgets what is unsaved, and the time it has waited: the board was just loaded, so what is on it is what is saved. A save on its way is left alone. */
52
+ cancel(): void;
53
+ /** Stops for good: nothing is saved afterwards. */
54
+ dispose(): void;
55
+ /** Whether something changed that no save has taken yet. */
56
+ readonly isDirty: boolean;
57
+ }
58
+ export declare function createAutosaveScheduler(options: AutosaveSchedulerOptions): AutosaveScheduler;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The buffer between a person who edits the board and the server that keeps it.
3
+ *
4
+ * A save is not made at every change: a drag, a run of nudges or a long stretch of drawing would send the whole board
5
+ * to the server fifty times. The scheduler keeps the rule in one place:
6
+ *
7
+ * - a save starts after a **quiet delay** since the last change (a trailing debounce), so a burst is one save;
8
+ * - a person who never pauses still gets a save every **longest wait**, so a crash costs seconds, not minutes;
9
+ * - a save is **held back** while the host asks for it (a code generation makes the page thread busy), for as long as
10
+ * the host asks, however long that is;
11
+ * - **one save at a time**: when a save is still on its way at the moment the next one is due, the next waits for it
12
+ * and everything that changed meanwhile goes out in a single save after it. A slow server is never flooded;
13
+ * - **flush** sends whatever is unsaved at once, whatever the delay and the hold, for the moments a page is about to
14
+ * go (the tab goes to the background, the page is hidden, the editor closes);
15
+ * - a save that fails leaves the changes unsaved and says so, and **does not try again by itself**: the next change, or
16
+ * the next flush, is the retry. A server that is down is not hammered.
17
+ *
18
+ * Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
19
+ */
20
+ /** The shortest time a save that is held back waits before the host is asked again, so that a delay of 0 does not spin. */
21
+ const SHORTEST_RECHECK_DELAY_MS = 250;
22
+ const realClock = {
23
+ now: () => Date.now(),
24
+ setTimer: (callback, delayMs) => setTimeout(callback, delayMs),
25
+ clearTimer: (handle) => clearTimeout(handle)
26
+ };
27
+ /** A number a host passed as a duration: anything that is not a finite number of at least 0 is 0. */
28
+ function toDurationMs(value) {
29
+ return Number.isFinite(value) && value > 0 ? value : 0;
30
+ }
31
+ function isPromiseLike(value) {
32
+ return !!value && typeof value.then === 'function';
33
+ }
34
+ export function createAutosaveScheduler(options) {
35
+ const clock = options.clock ?? realClock;
36
+ /** Something changed that no save has taken yet. */
37
+ let dirty = false;
38
+ /** When the first change that no save has taken yet was made: where the longest wait is counted from. */
39
+ let firstChangeAt = null;
40
+ let timerHandle = null;
41
+ /** The save that is on its way, if there is one. It never rejects. */
42
+ let saveOnItsWay = null;
43
+ /** The next save fell due while another was on its way: it starts as soon as that one is done. */
44
+ let dueWhileSaving = false;
45
+ let disposed = false;
46
+ function stopTimer() {
47
+ if (timerHandle === null)
48
+ return;
49
+ clock.clearTimer(timerHandle);
50
+ timerHandle = null;
51
+ }
52
+ function startTimer(waitMs) {
53
+ stopTimer();
54
+ timerHandle = clock.setTimer(onTimerFired, Math.max(0, waitMs));
55
+ }
56
+ function onTimerFired() {
57
+ timerHandle = null;
58
+ if (disposed)
59
+ return;
60
+ if (saveOnItsWay) {
61
+ // One save at a time: this one starts when the one on its way is done.
62
+ dueWhileSaving = true;
63
+ return;
64
+ }
65
+ saveUnlessHeldBack();
66
+ }
67
+ /** Starts the save, or, when the host holds saves back, looks again a delay later. */
68
+ function saveUnlessHeldBack() {
69
+ if (options.isSuspended?.()) {
70
+ startTimer(Math.max(toDurationMs(options.getDelayMs()), SHORTEST_RECHECK_DELAY_MS));
71
+ return;
72
+ }
73
+ void startSave();
74
+ }
75
+ function noteFailure(error) {
76
+ // What the failed save was meant to keep is not kept: it is unsaved again, and the next change or flush tries again.
77
+ dirty = true;
78
+ try {
79
+ options.onSaveFailed?.(error);
80
+ }
81
+ catch (reportError) {
82
+ console.warn('[autosave] onSaveFailed threw', reportError);
83
+ }
84
+ }
85
+ /** Takes everything unsaved into a save, now. The promise it returns never rejects and settles when the save is done. */
86
+ function startSave() {
87
+ stopTimer();
88
+ // What is unsaved goes into this save. Anything that changes from here on (a save that asks for another go, a change
89
+ // made while the save is on its way) is unsaved again, and is the next save's.
90
+ dirty = false;
91
+ firstChangeAt = null;
92
+ let outcome;
93
+ try {
94
+ outcome = options.save();
95
+ }
96
+ catch (error) {
97
+ noteFailure(error);
98
+ return Promise.resolve();
99
+ }
100
+ if (!isPromiseLike(outcome))
101
+ return Promise.resolve();
102
+ const running = Promise.resolve(outcome)
103
+ .then(() => undefined, (error) => noteFailure(error))
104
+ .then(() => {
105
+ if (saveOnItsWay === running)
106
+ saveOnItsWay = null;
107
+ if (disposed)
108
+ return;
109
+ if (dueWhileSaving && dirty) {
110
+ dueWhileSaving = false;
111
+ saveUnlessHeldBack();
112
+ }
113
+ });
114
+ saveOnItsWay = running;
115
+ return running;
116
+ }
117
+ function markChanged() {
118
+ if (disposed)
119
+ return;
120
+ const now = clock.now();
121
+ dirty = true;
122
+ if (firstChangeAt === null)
123
+ firstChangeAt = now;
124
+ const quietUntil = now + toDurationMs(options.getDelayMs());
125
+ const longestWait = toDurationMs(options.getMaxWaitMs());
126
+ const dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
127
+ startTimer(dueAt - now);
128
+ }
129
+ async function flush() {
130
+ // A save on its way finishes first, so that two never overlap.
131
+ while (saveOnItsWay)
132
+ await saveOnItsWay;
133
+ // Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
134
+ if (disposed || !dirty)
135
+ return;
136
+ await startSave();
137
+ }
138
+ function cancel() {
139
+ stopTimer();
140
+ dirty = false;
141
+ firstChangeAt = null;
142
+ dueWhileSaving = false;
143
+ }
144
+ function dispose() {
145
+ cancel();
146
+ disposed = true;
147
+ }
148
+ return {
149
+ markChanged,
150
+ flush,
151
+ cancel,
152
+ dispose,
153
+ get isDirty() {
154
+ return dirty;
155
+ }
156
+ };
157
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The frame the board draws around itself when the page asks for it (`showContainerFrame`): rounded corners and a 1 px
3
+ * border, as the Figma design has them.
4
+ *
5
+ * The border is drawn by a pseudo-element laid over the edge of the board and not by a CSS border. A real border takes room
6
+ * of its own, and everything that is placed "16 px from the edge" (the toolbar, the zoom control, the selection panel, the
7
+ * notices) is placed from the inside of it, so it would stand 17 px from the outer edge, a pixel off Figma's measures. The
8
+ * ring has no pointer events, so a press on the 1 px under it still reaches the board.
9
+ *
10
+ * Written out in full, so that the stylesheet of a page that installs the canvas picks every class up when it reads this
11
+ * file. Kept free of Svelte and of the DOM so that Node can test it.
12
+ */
13
+ export declare const BOARD_FRAME_CLASSES = "rounded-card after:pointer-events-none after:absolute after:inset-0 after:z-50 after:rounded-[inherit] after:border after:border-border";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The frame the board draws around itself when the page asks for it (`showContainerFrame`): rounded corners and a 1 px
3
+ * border, as the Figma design has them.
4
+ *
5
+ * The border is drawn by a pseudo-element laid over the edge of the board and not by a CSS border. A real border takes room
6
+ * of its own, and everything that is placed "16 px from the edge" (the toolbar, the zoom control, the selection panel, the
7
+ * notices) is placed from the inside of it, so it would stand 17 px from the outer edge, a pixel off Figma's measures. The
8
+ * ring has no pointer events, so a press on the 1 px under it still reaches the board.
9
+ *
10
+ * Written out in full, so that the stylesheet of a page that installs the canvas picks every class up when it reads this
11
+ * file. Kept free of Svelte and of the DOM so that Node can test it.
12
+ */
13
+ export const BOARD_FRAME_CLASSES = 'rounded-card after:pointer-events-none after:absolute after:inset-0 after:z-50 after:rounded-[inherit] after:border after:border-border';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The colour of the board's surface, under the dots of its grid and under an empty board that has not been drawn yet.
3
+ *
4
+ * It is the design system's own `muted` token (Figma: the canvas surface is `bg-muted`), so the board follows the page's theme.
5
+ * The fallback is the token's value in the light theme, for a page that does not load the design system's styles. One
6
+ * constant, read by the board and by the placeholder a page shows while the canvas is still downloading, so the swap
7
+ * from one to the other cannot change colour.
8
+ */
9
+ export declare const BOARD_SURFACE_COLOR = "var(--muted, #f5f5f5)";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The colour of the board's surface, under the dots of its grid and under an empty board that has not been drawn yet.
3
+ *
4
+ * It is the design system's own `muted` token (Figma: the canvas surface is `bg-muted`), so the board follows the page's theme.
5
+ * The fallback is the token's value in the light theme, for a page that does not load the design system's styles. One
6
+ * constant, read by the board and by the placeholder a page shows while the canvas is still downloading, so the swap
7
+ * from one to the other cannot change colour.
8
+ */
9
+ export const BOARD_SURFACE_COLOR = 'var(--muted, #f5f5f5)';
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Where the floating cards of the chrome (the toolbar and the zoom control) stand on the board, and how they share the
3
+ * board when a page puts both in the same place.
4
+ *
5
+ * A page names a place for each card (`toolbarPosition`, `panZoomPosition`): one of eight anchors, written the way the
6
+ * design names its frames, a row letter and a column letter.
7
+ *
8
+ * TL TC TR the top edge: left, centre, right
9
+ * CL CR the middle of the left edge and of the right edge
10
+ * BL BC BR the bottom edge: left, centre, right
11
+ *
12
+ * The middle of the board is not a place: a card there would sit on the drawing. A card on a side edge (CL, CR) stands
13
+ * upright, its buttons one under the other, and its menus and tooltips open sideways, into the board.
14
+ *
15
+ * Two cards named for the same anchor are put in one row (one column on a side edge) with a gap between them instead of
16
+ * lying on top of each other, so a host can ask for "everything at the bottom left" and get it.
17
+ *
18
+ * Kept free of Svelte and of the DOM so that Node can test it.
19
+ */
20
+ /** The eight places a card can stand. */
21
+ export declare const CHROME_ANCHORS: readonly ["TL", "TC", "TR", "CL", "CR", "BL", "BC", "BR"];
22
+ /** One of {@link CHROME_ANCHORS}. */
23
+ export type ChromeAnchor = (typeof CHROME_ANCHORS)[number];
24
+ /** The cards of the chrome that stand on their own anchor: the drawing toolbar (or the selector bar) and the zoom control. */
25
+ export type ChromeCardId = 'toolbar' | 'zoom';
26
+ /** The side of a card its menus and tooltips open to. */
27
+ export type PopoverSide = 'top' | 'bottom' | 'left' | 'right';
28
+ /** The anchor to use for what a page passed: anything that is not one of the eight is the fallback, so a mistyped option never takes a card off the board. */
29
+ export declare function normalizeAnchor(value: unknown, fallback: ChromeAnchor): ChromeAnchor;
30
+ /** Whether a card at this anchor stands upright, against the left or the right edge. */
31
+ export declare function isSideAnchor(anchor: ChromeAnchor): boolean;
32
+ /** Whether a card at this anchor stands against the top edge. */
33
+ export declare function isTopAnchor(anchor: ChromeAnchor): boolean;
34
+ /** The side of a card at this anchor that its menus and tooltips open to: away from the edge the card stands on. */
35
+ export declare function popoverSideFor(anchor: ChromeAnchor): PopoverSide;
36
+ /** The classes of the anchor alone (its place on the board, no layout of what is inside). */
37
+ export declare function anchorClasses(anchor: ChromeAnchor): string;
38
+ /** One place on the board that holds one or two cards. */
39
+ export interface ChromeSlot {
40
+ anchor: ChromeAnchor;
41
+ /** The cards that stand here, in the order they are drawn (the toolbar first). */
42
+ cards: readonly ChromeCardId[];
43
+ /** The slot stands against a side edge: what is inside is laid out in a column. */
44
+ vertical: boolean;
45
+ /** The classes of the slot's element: its place on the board and the layout of what is inside. */
46
+ classes: string;
47
+ }
48
+ /** Which cards the page shows. */
49
+ export interface ShownCards {
50
+ toolbar: boolean;
51
+ zoom: boolean;
52
+ }
53
+ /**
54
+ * The slots to draw for the anchors a page named: one per anchor that has a card, in a fixed order, so a card that moves
55
+ * from one anchor to another does not make the other one start again.
56
+ */
57
+ export declare function chromeSlots(toolbarAnchor: ChromeAnchor, zoomAnchor: ChromeAnchor, shown: ShownCards): ChromeSlot[];
58
+ /**
59
+ * The classes that show the zoom card from the width of board it needs, and hide it below. A zoom card on the same edge as
60
+ * the toolbar shares the line with it, so how much room it needs depends on where each stands: the widths and the sums
61
+ * behind them are in `ZOOM_CONTROL_MIN_WIDTHS`.
62
+ */
63
+ export declare function zoomVisibilityClasses(toolbarAnchor: ChromeAnchor, zoomAnchor: ChromeAnchor): string;
64
+ /** What the selection panel (top right, 336 px wide) has to keep clear of. */
65
+ export interface PanelClearance {
66
+ /** A card stands on the top edge: the panel starts below it. */
67
+ belowTopCards: boolean;
68
+ /**
69
+ * The card that stands upright against the right edge, when one does: the panel stands beside it, not over it. Which card
70
+ * it is says how wide it is (the toolbar's 59 px: the shape button's 51 and 4 px of padding on each side; the zoom control's
71
+ * 40 px), and the toolbar wins where the two share the slot.
72
+ */
73
+ besideSideCard: ChromeCardId | null;
74
+ }
75
+ /** What the panel keeps clear of, for the slots that are drawn. */
76
+ export declare function panelClearanceFor(slots: readonly ChromeSlot[]): PanelClearance;