@widgetic/canvas 0.5.44 → 0.5.45

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 (160) hide show
  1. package/dist/canvas/DomCanvas.svelte +52 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +68 -1
  10. package/dist/canvas/host/CanvasHost.js +1901 -1407
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +28 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +1 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  35. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  36. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  37. package/dist/canvas/ui/SelectionPanel.svelte +78 -17
  38. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  39. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  40. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  41. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  42. package/dist/canvas/ui/ToolButton.svelte +34 -55
  43. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  44. package/dist/canvas/ui/colorModel.js +32 -21
  45. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  46. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  47. package/dist/canvas/ui/floatingCard.js +43 -21
  48. package/dist/canvas/ui/floatingLayer.js +6 -5
  49. package/dist/canvas/ui/icons.d.ts +1 -1
  50. package/dist/canvas/ui/icons.js +1 -1
  51. package/dist/canvas/ui/keyHints.js +11 -9
  52. package/dist/canvas/ui/popoverSide.js +3 -2
  53. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  54. package/dist/canvas/ui/selectionTraits.js +66 -35
  55. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  56. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  57. package/dist/canvas/view/CanvasStage.svelte +7 -2
  58. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  59. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  60. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  61. package/dist/canvas/view/erasingMarks.js +7 -7
  62. package/dist/canvas/view/geometry.d.ts +1 -1
  63. package/dist/canvas/view/geometry.js +90 -71
  64. package/dist/canvas/view/liftedScene.js +36 -24
  65. package/dist/canvas/view/mountedScene.js +79 -76
  66. package/dist/components/CanvasBoardPoster.svelte +206 -0
  67. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  68. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  69. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  70. package/dist/components/index.d.ts +7 -0
  71. package/dist/components/index.js +8 -0
  72. package/dist/components/preferenceStorage.js +2 -2
  73. package/dist/engine/EngineCore.d.ts +37 -2
  74. package/dist/engine/EngineCore.js +946 -768
  75. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  76. package/dist/engine/codec/canvasDocument.js +172 -186
  77. package/dist/engine/codec/hostReadableKeys.js +1 -1
  78. package/dist/engine/core/arrange.js +38 -26
  79. package/dist/engine/core/arrow.d.ts +18 -8
  80. package/dist/engine/core/arrow.js +109 -84
  81. package/dist/engine/core/arrowBinding.d.ts +1 -1
  82. package/dist/engine/core/arrowBinding.js +126 -101
  83. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  84. package/dist/engine/core/arrowBindingRecords.js +48 -29
  85. package/dist/engine/core/brush.d.ts +8 -0
  86. package/dist/engine/core/brush.js +98 -78
  87. package/dist/engine/core/cameraMove.d.ts +6 -0
  88. package/dist/engine/core/cameraMove.js +56 -38
  89. package/dist/engine/core/defaults.js +51 -90
  90. package/dist/engine/core/freehand.js +163 -147
  91. package/dist/engine/core/geometry.js +54 -47
  92. package/dist/engine/core/history.js +55 -38
  93. package/dist/engine/core/hitTest.js +81 -68
  94. package/dist/engine/core/matrix.js +20 -18
  95. package/dist/engine/core/pathData.js +210 -183
  96. package/dist/engine/core/rotationReset.js +6 -5
  97. package/dist/engine/core/scene.d.ts +22 -0
  98. package/dist/engine/core/scene.js +288 -139
  99. package/dist/engine/core/scribble.js +84 -59
  100. package/dist/engine/core/shapePaths.js +15 -12
  101. package/dist/engine/core/shapeTools.js +63 -72
  102. package/dist/engine/core/snapping.js +117 -65
  103. package/dist/engine/core/style.d.ts +10 -0
  104. package/dist/engine/core/style.js +82 -33
  105. package/dist/engine/core/transform.d.ts +6 -0
  106. package/dist/engine/core/transform.js +103 -83
  107. package/dist/engine/core/types.d.ts +7 -0
  108. package/dist/engine/core/types.js +4 -4
  109. package/dist/engine/core/viewport.js +36 -23
  110. package/dist/engine/input/PointerController.d.ts +15 -1
  111. package/dist/engine/input/PointerController.js +547 -476
  112. package/dist/engine/input/arrowHandles.js +12 -12
  113. package/dist/engine/input/gestures.d.ts +3 -1
  114. package/dist/engine/input/gestures.js +340 -266
  115. package/dist/engine/input/hoverCursor.js +1 -1
  116. package/dist/engine/input/keyboard.d.ts +22 -3
  117. package/dist/engine/input/keyboard.js +131 -32
  118. package/dist/engine/input/selectionHandles.js +50 -45
  119. package/dist/engine/input/types.d.ts +7 -0
  120. package/dist/engine/input/types.js +1 -1
  121. package/dist/engine/render/rasterize.js +158 -86
  122. package/dist/engine/state.d.ts +18 -0
  123. package/dist/engine/state.js +25 -4
  124. package/dist/engine/text/layoutText.js +62 -43
  125. package/dist/engine/text/textMetrics.js +10 -8
  126. package/dist/engine/widgets.js +137 -101
  127. package/dist/fonts/interFont.js +83 -30
  128. package/dist/fonts/workspaceFonts.d.ts +6 -0
  129. package/dist/fonts/workspaceFonts.js +108 -34
  130. package/dist/i18n/labels.js +4 -4
  131. package/dist/i18n/language.d.ts +3 -3
  132. package/dist/i18n/language.js +4 -4
  133. package/dist/i18n/messages.d.ts +6 -0
  134. package/dist/i18n/messages.js +7 -1
  135. package/dist/i18n/shortcuts.d.ts +6 -4
  136. package/dist/i18n/shortcuts.js +30 -26
  137. package/dist/index.d.ts +1 -0
  138. package/dist/poster/boardPlacement.d.ts +80 -0
  139. package/dist/poster/boardPlacement.js +140 -0
  140. package/dist/poster/boardPoster.d.ts +80 -0
  141. package/dist/poster/boardPoster.js +251 -0
  142. package/dist/poster/paintBoardPoster.d.ts +49 -0
  143. package/dist/poster/paintBoardPoster.js +112 -0
  144. package/dist/poster/posterPictures.d.ts +32 -0
  145. package/dist/poster/posterPictures.js +138 -0
  146. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  147. package/dist/settings/workspaceToolSettings.js +58 -34
  148. package/dist/tools/components/catalog.js +74 -64
  149. package/dist/tools/components/grouping.js +28 -6
  150. package/dist/tools/definitions.js +31 -9
  151. package/dist/tools/executors.js +214 -106
  152. package/dist/tools/hostAdapter.d.ts +5 -1
  153. package/dist/tools/hostAdapter.js +15 -11
  154. package/dist/tools/sceneSummary.js +57 -43
  155. package/dist/tools/sketchIntent.js +21 -13
  156. package/dist/tools/styleArguments.d.ts +35 -0
  157. package/dist/tools/styleArguments.js +93 -0
  158. package/dist/tools/types.d.ts +26 -1
  159. package/dist/tools/types.js +2 -1
  160. package/package.json +1 -1
@@ -22,6 +22,9 @@
22
22
  import { onDestroy } from 'svelte';
23
23
  import { writable } from 'svelte/store';
24
24
  import { Tooltip } from '@widgetic/design-system/components';
25
+ import CanvasBoardPoster from '../components/CanvasBoardPoster.svelte';
26
+ import type { BoardPoster } from '../poster/boardPoster.js';
27
+ import type { PosterPictureResolver } from '../poster/posterPictures.js';
25
28
  import { onlyCardIsSelected } from '../engine/widgets.js';
26
29
  import { provideCanvasLanguage } from '../i18n/language.js';
27
30
  import { BOARD_FRAME_CLASSES } from './boardFrame.js';
@@ -36,6 +39,7 @@
36
39
  import type { ToolbarPosition } from './toolbarPosition.js';
37
40
  import CanvasContextMenu from './ui/CanvasContextMenu.svelte';
38
41
  import CanvasToolbar from './ui/CanvasToolbar.svelte';
42
+ import { CANVAS_TOOLTIP_DELAY_MS, CANVAS_TOOLTIP_SKIP_DELAY_MS } from './ui/floatingCard.js';
39
43
  import { FLOATING_LAYER_CLASSES, provideFloatingLayer } from './ui/floatingLayer.js';
40
44
  import SelectionPanel from './ui/SelectionPanel.svelte';
41
45
  import SelectorIndicator from './ui/SelectorIndicator.svelte';
@@ -110,6 +114,18 @@
110
114
  // Use this to keep the loader visible while the host fetches data from API before calling loadCanvas().
111
115
  export let isExternalDataLoading: CanvasHostProps['isExternalDataLoading'] = DEFAULT_HOST_PROPS.isExternalDataLoading;
112
116
 
117
+ // The poster of the board: a small copy of the objects that were in the saved view (`createBoardPoster`), drawn from the first
118
+ // frame and held while the board loads, so a refresh shows the objects at once and not an empty board first. Nothing changes
119
+ // for a page that does not give one. It is a picture of the shell and not a behaviour of the host, so it is not a host prop.
120
+ export let boardPoster: BoardPoster | null = null;
121
+ // The host's image store for the poster: answers the reference of a picture the board keeps there (a photo, the screenshot of a
122
+ // widget card) with its bytes or an address, so the poster draws the card with its picture. Null: those pictures come with the board.
123
+ export let resolveBoardPosterPicture: PosterPictureResolver | null = null;
124
+ // Whether the poster is on the screen now (the poster says it, `bind:visible`). The board draws no spinner over the objects of a
125
+ // poster that is up: the placeholders before the canvas drew none, and one that came back for the moment the board reads its saved
126
+ // text would blink at the hand-over. The layer of the loader stays: input waits and the cursor shows it.
127
+ let boardPosterVisible = false;
128
+
113
129
  // Callback fired at the very start of component teardown.
114
130
  // Use this in the host page to save canvas state when Vite HMR or navigation destroys this component
115
131
  // before the auto-save timer fires.
@@ -161,6 +177,7 @@
161
177
  // Callback: fires when a widget card is duplicated/pasted.
162
178
  // Receives the source widgetId and the cloned card so the host can duplicate the widget in DB and re-link the clone.
163
179
  export let onWidgetShapeDuplicated: CanvasHostProps['onWidgetShapeDuplicated'] = DEFAULT_HOST_PROPS.onWidgetShapeDuplicated;
180
+ export let allowWidgetDuplication: CanvasHostProps['allowWidgetDuplication'] = DEFAULT_HOST_PROPS.allowWidgetDuplication;
164
181
 
165
182
  // Callback: fires when a widget card is about to be deleted.
166
183
  // Returns a Promise<boolean>: if true, proceed with deletion; if false, cancel.
@@ -209,6 +226,18 @@
209
226
  * Inter the page declares itself.
210
227
  */
211
228
  export let interFontSources: CanvasHostProps['interFontSources'] = DEFAULT_HOST_PROPS.interFontSources;
229
+ /**
230
+ * Shows the person's file library (the File Browser of their workspace) in the Shapes menu, before the Image entry. Off by
231
+ * default; it needs `pickFiles`, the page's File Browser (see `BoardFilePicker`), which opens in select state for pictures and
232
+ * vector files. The board puts the files that are chosen down, and never deletes a library file.
233
+ */
234
+ export let showFileBrowser: CanvasHostProps['showFileBrowser'] = DEFAULT_HOST_PROPS.showFileBrowser;
235
+ export let pickFiles: CanvasHostProps['pickFiles'] = DEFAULT_HOST_PROPS.pickFiles;
236
+ /**
237
+ * Pictures the sketch assistant may put on the board by their id (`add_asset`): the icons of the brand kit and the files of the
238
+ * library. The page builds the list; the board draws what the assistant names.
239
+ */
240
+ export let sketchAssets: CanvasHostProps['sketchAssets'] = DEFAULT_HOST_PROPS.sketchAssets;
212
241
 
213
242
  /**
214
243
  * The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
@@ -267,6 +296,7 @@
267
296
  onRecognizeStroke,
268
297
  onNonWidgetSelected,
269
298
  onWidgetShapeDuplicated,
299
+ allowWidgetDuplication,
270
300
  onWidgetShapeDeleting,
271
301
  onWidgetRename,
272
302
  onRefreshScreenshot,
@@ -281,9 +311,14 @@
281
311
  workspaceId,
282
312
  userId,
283
313
  workspaceFonts,
284
- interFontSources
314
+ interFontSources,
315
+ showFileBrowser,
316
+ pickFiles,
317
+ sketchAssets
285
318
  };
286
319
  $: host.setProps(hostProps);
320
+ // The Shapes menu offers the library only when the page asked for it and gave the browser that opens it.
321
+ $: fileBrowserAvailable = showFileBrowser && typeof pickFiles === 'function';
287
322
 
288
323
  /**
289
324
  * THE DOM
@@ -426,13 +461,21 @@
426
461
  export const executeSketchTool = forwardToHost(host, 'executeSketchTool');
427
462
  export const beginSketchToolBatch = forwardToHost(host, 'beginSketchToolBatch');
428
463
  export const endSketchToolBatch = forwardToHost(host, 'endSketchToolBatch');
464
+ // The person's file library on the board: the Shapes menu's Files entry, and the calls the page uses to put the pictures that are
465
+ // only on the board into its library (`getBoardPictures`, then `setPictureLibraryFile` for each one it uploaded;
466
+ // `getLoadedBoardPictures` is the same list at once, for the moment the board is about to change).
467
+ export const openFileBrowser = forwardToHost(host, 'openFileBrowser');
468
+ export const insertPickedFiles = forwardToHost(host, 'insertPickedFiles');
469
+ export const getBoardPictures = forwardToHost(host, 'getBoardPictures');
470
+ export const getLoadedBoardPictures = forwardToHost(host, 'getLoadedBoardPictures');
471
+ export const setPictureLibraryFile = forwardToHost(host, 'setPictureLibraryFile');
429
472
  // The camera: the view eases to some objects, to a point, or back to 100% on everything drawn (position and zoom together).
430
473
  export const flyToObjects = forwardToHost(host, 'flyToObjects');
431
474
  export const flyToPoint = forwardToHost(host, 'flyToPoint');
432
475
  export const flyToContent = forwardToHost(host, 'flyToContent');
433
476
  </script>
434
477
 
435
- <Tooltip.Provider delayDuration={400} skipDelayDuration={200}>
478
+ <Tooltip.Provider delayDuration={CANVAS_TOOLTIP_DELAY_MS} skipDelayDuration={CANVAS_TOOLTIP_SKIP_DELAY_MS}>
436
479
  <div
437
480
  bind:this={rootElement}
438
481
  class="{className ? className + ' ' : ''}canvas-container @container relative isolate h-full w-full overflow-visible text-foreground outline-hidden {showContainerFrame ? BOARD_FRAME_CLASSES : ''}"
@@ -449,9 +492,15 @@
449
492
  {loading}
450
493
  {showEmptyBoardHint}
451
494
  {frameElsewhere}
495
+ posterVisible={boardPosterVisible}
452
496
  bind:board={boardElement}
453
497
  />
454
498
 
499
+ <!-- The poster: the objects of the saved view, drawn before the board has them. Over the board, under the chrome; it fades when the board has painted its own. While it is up the loader draws no spinner over it (`posterVisible`), and the layer of the loader still holds the pointer. -->
500
+ {#if boardPoster}
501
+ <CanvasBoardPoster bind:visible={boardPosterVisible} poster={boardPoster} hold={loading} resolvePicture={resolveBoardPosterPicture} class="z-[1]" />
502
+ {/if}
503
+
455
504
  <!-- The chrome: siblings of the board, so a press on a button never reaches it. It waits while the board loads. -->
456
505
  <div class="pointer-events-none absolute inset-0 z-10 transition-opacity duration-200 motion-reduce:transition-none {loading ? 'opacity-60' : ''}" inert={loading}>
457
506
  <!-- One slot for each place that has a card: the toolbar and the zoom control, side by side when they share a place. -->
@@ -459,7 +508,7 @@
459
508
  <div class={slot.classes} data-canvas-slot={slot.anchor}>
460
509
  {#each slot.cards as card (card)}
461
510
  {#if card === 'toolbar'}
462
- <CanvasToolbar {host} state={engineState} ui={uiState} {showDrawingTools} anchor={toolbarAnchor} />
511
+ <CanvasToolbar {host} state={engineState} ui={uiState} {showDrawingTools} showFiles={fileBrowserAvailable} anchor={toolbarAnchor} />
463
512
  {:else}
464
513
  <ZoomControl {host} state={engineState} ui={uiState} anchor={zoomAnchor} visibleMinWidth={zoomVisibleMinWidth} showZoom={showZoomPanel} {showSaveButton} />
465
514
  {/if}
@@ -1,3 +1,5 @@
1
+ import type { BoardPoster } from '../poster/boardPoster.js';
2
+ import type { PosterPictureResolver } from '../poster/posterPictures.js';
1
3
  import type { CanvasHostProps, SelectorGuide } from './host/CanvasHost.js';
2
4
  import type { PanZoomPosition } from './panZoomPosition.js';
3
5
  import type { ToolbarPosition } from './toolbarPosition.js';
@@ -37,6 +39,8 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
37
39
  initialData?: CanvasHostProps["initialData"];
38
40
  onReady?: CanvasHostProps["onReady"];
39
41
  isExternalDataLoading?: CanvasHostProps["isExternalDataLoading"];
42
+ boardPoster?: BoardPoster | null;
43
+ resolveBoardPosterPicture?: PosterPictureResolver | null;
40
44
  onBeforeUnmount?: CanvasHostProps["onBeforeUnmount"];
41
45
  onAutoSave?: CanvasHostProps["onAutoSave"];
42
46
  autosaveDelayMs?: CanvasHostProps["autosaveDelayMs"];
@@ -50,6 +54,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
50
54
  onRecognizeStroke?: CanvasHostProps["onRecognizeStroke"];
51
55
  onNonWidgetSelected?: CanvasHostProps["onNonWidgetSelected"];
52
56
  onWidgetShapeDuplicated?: CanvasHostProps["onWidgetShapeDuplicated"];
57
+ allowWidgetDuplication?: CanvasHostProps["allowWidgetDuplication"];
53
58
  onWidgetShapeDeleting?: CanvasHostProps["onWidgetShapeDeleting"];
54
59
  onWidgetRename?: CanvasHostProps["onWidgetRename"];
55
60
  onRefreshScreenshot?: CanvasHostProps["onRefreshScreenshot"];
@@ -72,6 +77,16 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
72
77
  * URLs for a page with a strict `font-src`). None by default, so the canvas asks no one for a file and waits for the
73
78
  * Inter the page declares itself.
74
79
  */ interFontSources?: CanvasHostProps["interFontSources"];
80
+ /**
81
+ * Shows the person's file library (the File Browser of their workspace) in the Shapes menu, before the Image entry. Off by
82
+ * default; it needs `pickFiles`, the page's File Browser (see `BoardFilePicker`), which opens in select state for pictures and
83
+ * vector files. The board puts the files that are chosen down, and never deletes a library file.
84
+ */ showFileBrowser?: CanvasHostProps["showFileBrowser"];
85
+ pickFiles?: CanvasHostProps["pickFiles"];
86
+ /**
87
+ * Pictures the sketch assistant may put on the board by their id (`add_asset`): the icons of the brand kit and the files of the
88
+ * library. The page builds the list; the board draws what the assistant names.
89
+ */ sketchAssets?: CanvasHostProps["sketchAssets"];
75
90
  /**
76
91
  * The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
77
92
  * the page's own words are in; `messages` are the page's own words, keyed like CANVAS_MESSAGES (a key left out
@@ -86,20 +101,20 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
86
101
  captureCanvasSketch?: () => Promise<string>;
87
102
  absorbCanvasSketchIntoWidget?: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
88
103
  deselectAll?: () => void;
89
- duplicateSelectedObjects?: () => import("../engine/core/types.js").ObjectId[];
104
+ duplicateSelectedObjects?: () => import("../engine/core/types").ObjectId[];
90
105
  deleteSelectedObjects?: () => Promise<boolean>;
91
106
  markSelectedAsDuplicating?: () => void;
92
- linkObjectToWidget?: (target: import("../engine/core/types.js").ObjectId | {
93
- id?: import("../engine/core/types.js").ObjectId;
94
- _objectId?: import("../engine/core/types.js").ObjectId;
107
+ linkObjectToWidget?: (target: import("../engine/core/types").ObjectId | {
108
+ id?: import("../engine/core/types").ObjectId;
109
+ _objectId?: import("../engine/core/types").ObjectId;
95
110
  } | null | undefined, widgetId: string, widgetName?: string | null) => void;
96
111
  linkFrameToWidget?: (objectId: string, widgetId: string) => void;
97
112
  replaceObjectWithWidgetImage?: (objectId: string, widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
98
113
  updateWidgetImage?: (widgetId: string, newScreenshotDataUrl: string) => void;
99
114
  selectWidgetShape?: (widgetId: string) => boolean;
100
- listWidgetShapeScreenRects?: (options?: import("./host/screenRects.js").ListWidgetScreenRectsOptions) => import("./host/screenRects.js").WidgetScreenRect[];
101
- getWidgetShapeScreenRect?: (widgetId: string) => import("./host/screenRects.js").ScreenRect | null;
102
- getObjectScreenRect?: (objectId: string) => import("./host/screenRects.js").ScreenRect | null;
115
+ listWidgetShapeScreenRects?: (options?: import("./host/screenRects").ListWidgetScreenRectsOptions) => import("./host/screenRects").WidgetScreenRect[];
116
+ getWidgetShapeScreenRect?: (widgetId: string) => import("./host/screenRects").ScreenRect | null;
117
+ getObjectScreenRect?: (objectId: string) => import("./host/screenRects").ScreenRect | null;
103
118
  getWidgetShapeDataUrl?: (widgetId: string) => string | null;
104
119
  setWidgetShapeLivePreviewHiddenImage?: (widgetId: string, hidden: boolean) => void;
105
120
  addWidgetShape?: (widgetId: string, widgetName?: string, gridIndex?: number, totalCount?: number, previewImageUrl?: string | null) => string | null;
@@ -123,7 +138,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
123
138
  setWidgetShapeOverlayDragActive?: (active: boolean) => void;
124
139
  selectWidgetShapeById?: (widgetId: string) => boolean;
125
140
  getSelectedWidgetShapeId?: () => string | null;
126
- getSelectedObject?: () => import("./host/hostObject.js").HostObject | null;
141
+ getSelectedObject?: () => import("./host/hostObject").HostObject | null;
127
142
  getHoveredWidgetShapeId?: () => string | null;
128
143
  onSelectImageTool?: () => void;
129
144
  onSelectVideoTool?: () => void;
@@ -144,20 +159,25 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
144
159
  saveCanvas?: () => string | null;
145
160
  loadCanvas?: (jsonString: string) => Promise<void>;
146
161
  onClearAllObjects?: () => void;
147
- addText?: () => import("../engine/core/types.js").ObjectId;
148
- addTriangle?: () => import("../engine/core/types.js").ObjectId | null;
149
- addRect?: () => import("../engine/core/types.js").ObjectId | null;
150
- addCircle?: () => import("../engine/core/types.js").ObjectId | null;
162
+ addText?: () => import("../engine/core/types").ObjectId;
163
+ addTriangle?: () => import("../engine/core/types").ObjectId | null;
164
+ addRect?: () => import("../engine/core/types").ObjectId | null;
165
+ addCircle?: () => import("../engine/core/types").ObjectId | null;
151
166
  addFrame?: () => null;
152
167
  addImage?: () => Promise<void>;
153
168
  removeSketchObjectsKeepingWidget?: (widgetId: string) => number;
154
- getSketchSceneSummary?: () => import("../tools/types.js").SceneSummary;
155
- executeSketchTool?: (name: string, args: Record<string, unknown>) => import("../tools/types.js").ToolResult;
169
+ getSketchSceneSummary?: () => import("../tools").SceneSummary;
170
+ executeSketchTool?: (name: string, args: Record<string, unknown>) => import("../tools").ToolResult;
156
171
  beginSketchToolBatch?: () => void;
157
172
  endSketchToolBatch?: () => void;
158
- flyToObjects?: (objectIds: readonly string[], options?: import("./types.js").CanvasFlyOptions) => boolean;
159
- flyToPoint?: (point: import("../engine/core/types.js").Point, options?: import("./types.js").CanvasFlyOptions) => boolean;
160
- flyToContent?: (options?: import("./types.js").CanvasMoveOptions) => boolean;
173
+ openFileBrowser?: () => Promise<void>;
174
+ insertPickedFiles?: (files: readonly import(".").BoardLibraryFile[], at?: import("../engine/core/types").Point) => Promise<import("../engine/core/types").ObjectId[]>;
175
+ getBoardPictures?: () => Promise<import(".").BoardPicture[]>;
176
+ getLoadedBoardPictures?: () => import(".").BoardPicture[];
177
+ setPictureLibraryFile?: (objectId: import("../engine/core/types").ObjectId, file: import(".").BoardPictureLibraryFile) => boolean;
178
+ flyToObjects?: (objectIds: readonly string[], options?: import("./types").CanvasFlyOptions) => boolean;
179
+ flyToPoint?: (point: import("../engine/core/types").Point, options?: import("./types").CanvasFlyOptions) => boolean;
180
+ flyToContent?: (options?: import("./types").CanvasMoveOptions) => boolean;
161
181
  }, {
162
182
  [evt: string]: CustomEvent<any>;
163
183
  }, {}, {
@@ -169,20 +189,20 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
169
189
  captureCanvasSketch: () => Promise<string>;
170
190
  absorbCanvasSketchIntoWidget: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
171
191
  deselectAll: () => void;
172
- duplicateSelectedObjects: () => import("../engine/core/types.js").ObjectId[];
192
+ duplicateSelectedObjects: () => import("../engine/core/types").ObjectId[];
173
193
  deleteSelectedObjects: () => Promise<boolean>;
174
194
  markSelectedAsDuplicating: () => void;
175
- linkObjectToWidget: (target: import("../engine/core/types.js").ObjectId | {
176
- id?: import("../engine/core/types.js").ObjectId;
177
- _objectId?: import("../engine/core/types.js").ObjectId;
195
+ linkObjectToWidget: (target: import("../engine/core/types").ObjectId | {
196
+ id?: import("../engine/core/types").ObjectId;
197
+ _objectId?: import("../engine/core/types").ObjectId;
178
198
  } | null | undefined, widgetId: string, widgetName?: string | null) => void;
179
199
  linkFrameToWidget: (objectId: string, widgetId: string) => void;
180
200
  replaceObjectWithWidgetImage: (objectId: string, widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
181
201
  updateWidgetImage: (widgetId: string, newScreenshotDataUrl: string) => void;
182
202
  selectWidgetShape: (widgetId: string) => boolean;
183
- listWidgetShapeScreenRects: (options?: import("./host/screenRects.js").ListWidgetScreenRectsOptions) => import("./host/screenRects.js").WidgetScreenRect[];
184
- getWidgetShapeScreenRect: (widgetId: string) => import("./host/screenRects.js").ScreenRect | null;
185
- getObjectScreenRect: (objectId: string) => import("./host/screenRects.js").ScreenRect | null;
203
+ listWidgetShapeScreenRects: (options?: import("./host/screenRects").ListWidgetScreenRectsOptions) => import("./host/screenRects").WidgetScreenRect[];
204
+ getWidgetShapeScreenRect: (widgetId: string) => import("./host/screenRects").ScreenRect | null;
205
+ getObjectScreenRect: (objectId: string) => import("./host/screenRects").ScreenRect | null;
186
206
  getWidgetShapeDataUrl: (widgetId: string) => string | null;
187
207
  setWidgetShapeLivePreviewHiddenImage: (widgetId: string, hidden: boolean) => void;
188
208
  addWidgetShape: (widgetId: string, widgetName?: string, gridIndex?: number, totalCount?: number, previewImageUrl?: string | null) => string | null;
@@ -206,7 +226,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
206
226
  setWidgetShapeOverlayDragActive: (active: boolean) => void;
207
227
  selectWidgetShapeById: (widgetId: string) => boolean;
208
228
  getSelectedWidgetShapeId: () => string | null;
209
- getSelectedObject: () => import("./host/hostObject.js").HostObject | null;
229
+ getSelectedObject: () => import("./host/hostObject").HostObject | null;
210
230
  getHoveredWidgetShapeId: () => string | null;
211
231
  onSelectImageTool: () => void;
212
232
  onSelectVideoTool: () => void;
@@ -227,20 +247,25 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
227
247
  saveCanvas: () => string | null;
228
248
  loadCanvas: (jsonString: string) => Promise<void>;
229
249
  onClearAllObjects: () => void;
230
- addText: () => import("../engine/core/types.js").ObjectId;
231
- addTriangle: () => import("../engine/core/types.js").ObjectId | null;
232
- addRect: () => import("../engine/core/types.js").ObjectId | null;
233
- addCircle: () => import("../engine/core/types.js").ObjectId | null;
250
+ addText: () => import("../engine/core/types").ObjectId;
251
+ addTriangle: () => import("../engine/core/types").ObjectId | null;
252
+ addRect: () => import("../engine/core/types").ObjectId | null;
253
+ addCircle: () => import("../engine/core/types").ObjectId | null;
234
254
  addFrame: () => null;
235
255
  addImage: () => Promise<void>;
236
256
  removeSketchObjectsKeepingWidget: (widgetId: string) => number;
237
- getSketchSceneSummary: () => import("../tools/types.js").SceneSummary;
238
- executeSketchTool: (name: string, args: Record<string, unknown>) => import("../tools/types.js").ToolResult;
257
+ getSketchSceneSummary: () => import("../tools").SceneSummary;
258
+ executeSketchTool: (name: string, args: Record<string, unknown>) => import("../tools").ToolResult;
239
259
  beginSketchToolBatch: () => void;
240
260
  endSketchToolBatch: () => void;
241
- flyToObjects: (objectIds: readonly string[], options?: import("./types.js").CanvasFlyOptions) => boolean;
242
- flyToPoint: (point: import("../engine/core/types.js").Point, options?: import("./types.js").CanvasFlyOptions) => boolean;
243
- flyToContent: (options?: import("./types.js").CanvasMoveOptions) => boolean;
261
+ openFileBrowser: () => Promise<void>;
262
+ insertPickedFiles: (files: readonly import(".").BoardLibraryFile[], at?: import("../engine/core/types").Point) => Promise<import("../engine/core/types").ObjectId[]>;
263
+ getBoardPictures: () => Promise<import(".").BoardPicture[]>;
264
+ getLoadedBoardPictures: () => import(".").BoardPicture[];
265
+ setPictureLibraryFile: (objectId: import("../engine/core/types").ObjectId, file: import(".").BoardPictureLibraryFile) => boolean;
266
+ flyToObjects: (objectIds: readonly string[], options?: import("./types").CanvasFlyOptions) => boolean;
267
+ flyToPoint: (point: import("../engine/core/types").Point, options?: import("./types").CanvasFlyOptions) => boolean;
268
+ flyToContent: (options?: import("./types").CanvasMoveOptions) => boolean;
244
269
  }, string>;
245
270
  type DomCanvas = InstanceType<typeof DomCanvas>;
246
271
  export default DomCanvas;
@@ -19,12 +19,48 @@
19
19
  *
20
20
  * Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
21
21
  */
22
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
29
+ });
30
+ };
31
+ var __generator = (this && this.__generator) || function (thisArg, body) {
32
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
33
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
+ function verb(n) { return function (v) { return step([n, v]); }; }
35
+ function step(op) {
36
+ if (f) throw new TypeError("Generator is already executing.");
37
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
+ if (y = 0, t) op = [op[0] & 2, t.value];
40
+ switch (op[0]) {
41
+ case 0: case 1: t = op; break;
42
+ case 4: _.label++; return { value: op[1], done: false };
43
+ case 5: _.label++; y = op[1]; op = [0]; continue;
44
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
+ default:
46
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
+ if (t[2]) _.ops.pop();
51
+ _.trys.pop(); continue;
52
+ }
53
+ op = body.call(thisArg, _);
54
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
+ }
57
+ };
22
58
  /** 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. */
23
- const SHORTEST_RECHECK_DELAY_MS = 250;
24
- const realClock = {
25
- now: () => Date.now(),
26
- setTimer: (callback, delayMs) => setTimeout(callback, delayMs),
27
- clearTimer: (handle) => clearTimeout(handle)
59
+ var SHORTEST_RECHECK_DELAY_MS = 250;
60
+ var realClock = {
61
+ now: function () { return Date.now(); },
62
+ setTimer: function (callback, delayMs) { return setTimeout(callback, delayMs); },
63
+ clearTimer: function (handle) { return clearTimeout(handle); }
28
64
  };
29
65
  /** A number a host passed as a duration: anything that is not a finite number of at least 0 is 0. */
30
66
  function toDurationMs(value) {
@@ -34,19 +70,20 @@ function isPromiseLike(value) {
34
70
  return !!value && typeof value.then === 'function';
35
71
  }
36
72
  export function createAutosaveScheduler(options) {
37
- const clock = options.clock ?? realClock;
73
+ var _a;
74
+ var clock = (_a = options.clock) !== null && _a !== void 0 ? _a : realClock;
38
75
  /** Something changed that no save has taken yet. */
39
- let dirty = false;
76
+ var dirty = false;
40
77
  /** When the first change that no save has taken yet was made: where the longest wait is counted from. */
41
- let firstChangeAt = null;
42
- let timerHandle = null;
78
+ var firstChangeAt = null;
79
+ var timerHandle = null;
43
80
  /** The save that is on its way, if there is one. It never rejects. */
44
- let saveOnItsWay = null;
81
+ var saveOnItsWay = null;
45
82
  /** The next save fell due while another was on its way: it starts as soon as that one is done. */
46
- let dueWhileSaving = false;
83
+ var dueWhileSaving = false;
47
84
  /** How many saves in a row have failed. A save that goes through, or a board that was just loaded, makes it 0. */
48
- let failuresInARow = 0;
49
- let disposed = false;
85
+ var failuresInARow = 0;
86
+ var disposed = false;
50
87
  function stopTimer() {
51
88
  if (timerHandle === null)
52
89
  return;
@@ -70,7 +107,8 @@ export function createAutosaveScheduler(options) {
70
107
  }
71
108
  /** Starts the save, or, when the host holds saves back, looks again a delay later. */
72
109
  function saveUnlessHeldBack() {
73
- if (options.isSuspended?.()) {
110
+ var _a;
111
+ if ((_a = options.isSuspended) === null || _a === void 0 ? void 0 : _a.call(options)) {
74
112
  startTimer(Math.max(toDurationMs(options.getDelayMs()), SHORTEST_RECHECK_DELAY_MS));
75
113
  return;
76
114
  }
@@ -80,7 +118,7 @@ export function createAutosaveScheduler(options) {
80
118
  function scheduleRetry() {
81
119
  if (disposed || timerHandle !== null || !options.getRetryDelayMs)
82
120
  return;
83
- let waitMs = 0;
121
+ var waitMs = 0;
84
122
  try {
85
123
  waitMs = toDurationMs(options.getRetryDelayMs(failuresInARow));
86
124
  }
@@ -91,12 +129,13 @@ export function createAutosaveScheduler(options) {
91
129
  startTimer(waitMs);
92
130
  }
93
131
  function noteFailure(error) {
132
+ var _a;
94
133
  // What the failed save was meant to keep is not kept: it is unsaved again, and the retry (or the next change or
95
134
  // flush) tries again.
96
135
  dirty = true;
97
136
  failuresInARow += 1;
98
137
  try {
99
- options.onSaveFailed?.(error);
138
+ (_a = options.onSaveFailed) === null || _a === void 0 ? void 0 : _a.call(options, error);
100
139
  }
101
140
  catch (reportError) {
102
141
  console.warn('[autosave] onSaveFailed threw', reportError);
@@ -110,7 +149,7 @@ export function createAutosaveScheduler(options) {
110
149
  // made while the save is on its way) is unsaved again, and is the next save's.
111
150
  dirty = false;
112
151
  firstChangeAt = null;
113
- let outcome;
152
+ var outcome;
114
153
  try {
115
154
  outcome = options.save();
116
155
  }
@@ -122,11 +161,11 @@ export function createAutosaveScheduler(options) {
122
161
  failuresInARow = 0;
123
162
  return Promise.resolve();
124
163
  }
125
- const running = Promise.resolve(outcome)
126
- .then(() => {
164
+ var running = Promise.resolve(outcome)
165
+ .then(function () {
127
166
  failuresInARow = 0;
128
- }, (error) => noteFailure(error))
129
- .then(() => {
167
+ }, function (error) { return noteFailure(error); })
168
+ .then(function () {
130
169
  if (saveOnItsWay === running)
131
170
  saveOnItsWay = null;
132
171
  if (disposed)
@@ -142,23 +181,36 @@ export function createAutosaveScheduler(options) {
142
181
  function markChanged() {
143
182
  if (disposed)
144
183
  return;
145
- const now = clock.now();
184
+ var now = clock.now();
146
185
  dirty = true;
147
186
  if (firstChangeAt === null)
148
187
  firstChangeAt = now;
149
- const quietUntil = now + toDurationMs(options.getDelayMs());
150
- const longestWait = toDurationMs(options.getMaxWaitMs());
151
- const dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
188
+ var quietUntil = now + toDurationMs(options.getDelayMs());
189
+ var longestWait = toDurationMs(options.getMaxWaitMs());
190
+ var dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
152
191
  startTimer(dueAt - now);
153
192
  }
154
- async function flush() {
155
- // A save on its way finishes first, so that two never overlap.
156
- while (saveOnItsWay)
157
- await saveOnItsWay;
158
- // Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
159
- if (disposed || !dirty)
160
- return;
161
- await startSave();
193
+ function flush() {
194
+ return __awaiter(this, void 0, Promise, function () {
195
+ return __generator(this, function (_a) {
196
+ switch (_a.label) {
197
+ case 0:
198
+ if (!saveOnItsWay) return [3 /*break*/, 2];
199
+ return [4 /*yield*/, saveOnItsWay];
200
+ case 1:
201
+ _a.sent();
202
+ return [3 /*break*/, 0];
203
+ case 2:
204
+ // Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
205
+ if (disposed || !dirty)
206
+ return [2 /*return*/];
207
+ return [4 /*yield*/, startSave()];
208
+ case 3:
209
+ _a.sent();
210
+ return [2 /*return*/];
211
+ }
212
+ });
213
+ });
162
214
  }
163
215
  function cancel() {
164
216
  stopTimer();
@@ -172,10 +224,10 @@ export function createAutosaveScheduler(options) {
172
224
  disposed = true;
173
225
  }
174
226
  return {
175
- markChanged,
176
- flush,
177
- cancel,
178
- dispose,
227
+ markChanged: markChanged,
228
+ flush: flush,
229
+ cancel: cancel,
230
+ dispose: dispose,
179
231
  get isDirty() {
180
232
  return dirty;
181
233
  }
@@ -10,4 +10,4 @@
10
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
11
  * file. Kept free of Svelte and of the DOM so that Node can test it.
12
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';
13
+ export var 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';
@@ -10,4 +10,4 @@
10
10
  * white in the design, while the full canvas stays `muted`). Nothing else changes: the variable is not set anywhere else, so
11
11
  * the board, the creator and the embeds keep the token.
12
12
  */
13
- export const BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
13
+ export var BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
@@ -1,19 +1,31 @@
1
- let _enabled = true;
1
+ var _enabled = true;
2
2
  export function setCanvasLogsEnabled(enabled) {
3
3
  _enabled = enabled;
4
4
  }
5
5
  export function isCanvasLogsEnabled() {
6
6
  return _enabled;
7
7
  }
8
- export function canvasLog(...args) {
8
+ export function canvasLog() {
9
+ var args = [];
10
+ for (var _i = 0; _i < arguments.length; _i++) {
11
+ args[_i] = arguments[_i];
12
+ }
9
13
  if (_enabled)
10
- console.log(...args);
14
+ console.log.apply(console, args);
11
15
  }
12
- export function canvasWarn(...args) {
16
+ export function canvasWarn() {
17
+ var args = [];
18
+ for (var _i = 0; _i < arguments.length; _i++) {
19
+ args[_i] = arguments[_i];
20
+ }
13
21
  if (_enabled)
14
- console.warn(...args);
22
+ console.warn.apply(console, args);
15
23
  }
16
- export function canvasDebug(...args) {
24
+ export function canvasDebug() {
25
+ var args = [];
26
+ for (var _i = 0; _i < arguments.length; _i++) {
27
+ args[_i] = arguments[_i];
28
+ }
17
29
  if (_enabled)
18
- console.debug(...args);
30
+ console.debug.apply(console, args);
19
31
  }