@widgetic/canvas 0.5.38 → 0.5.40

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 (58) hide show
  1. package/README.md +5 -0
  2. package/dist/canvas/DomCanvas.svelte +29 -8
  3. package/dist/canvas/DomCanvas.svelte.d.ts +5 -0
  4. package/dist/canvas/autosaveScheduler.d.ts +10 -2
  5. package/dist/canvas/autosaveScheduler.js +31 -5
  6. package/dist/canvas/boardSurface.d.ts +5 -1
  7. package/dist/canvas/boardSurface.js +5 -1
  8. package/dist/canvas/chromeLayout.d.ts +2 -0
  9. package/dist/canvas/chromeLayout.js +17 -2
  10. package/dist/canvas/host/CanvasHost.d.ts +32 -1
  11. package/dist/canvas/host/CanvasHost.js +138 -12
  12. package/dist/canvas/outsideClickDeselect.d.ts +5 -0
  13. package/dist/canvas/outsideClickDeselect.js +25 -0
  14. package/dist/canvas/preferredTextFont.d.ts +7 -1
  15. package/dist/canvas/preferredTextFont.js +26 -2
  16. package/dist/canvas/ui/CanvasContextMenu.svelte +69 -39
  17. package/dist/canvas/ui/CanvasHint.svelte +4 -4
  18. package/dist/canvas/ui/CanvasToolbar.svelte +21 -3
  19. package/dist/canvas/ui/ColorField.svelte +2 -1
  20. package/dist/canvas/ui/SelectionPanel.svelte +82 -43
  21. package/dist/canvas/ui/SelectorBar.svelte +5 -3
  22. package/dist/canvas/ui/ShapesMenu.svelte +0 -2
  23. package/dist/canvas/ui/WidgetActions.svelte +1 -1
  24. package/dist/canvas/ui/ZoomControl.svelte +39 -4
  25. package/dist/canvas/ui/ZoomControl.svelte.d.ts +2 -2
  26. package/dist/canvas/ui/floatingCard.d.ts +7 -5
  27. package/dist/canvas/ui/floatingCard.js +7 -5
  28. package/dist/canvas/ui/keyHints.d.ts +5 -0
  29. package/dist/canvas/ui/keyHints.js +14 -0
  30. package/dist/canvas/ui/sizeLabelVisibility.d.ts +16 -0
  31. package/dist/canvas/ui/sizeLabelVisibility.js +16 -0
  32. package/dist/canvas/ui/widgetSelectionPanel.d.ts +6 -0
  33. package/dist/canvas/ui/widgetSelectionPanel.js +9 -0
  34. package/dist/canvas/view/ObjectView.svelte +2 -1
  35. package/dist/canvas/view/SelectionOverlay.svelte +12 -1
  36. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +1 -1
  37. package/dist/engine/EngineCore.d.ts +19 -2
  38. package/dist/engine/EngineCore.js +51 -7
  39. package/dist/engine/core/defaults.d.ts +1 -1
  40. package/dist/engine/core/defaults.js +1 -1
  41. package/dist/engine/core/shapeTools.d.ts +16 -6
  42. package/dist/engine/core/shapeTools.js +8 -6
  43. package/dist/engine/input/gestures.js +3 -2
  44. package/dist/engine/text/layoutText.d.ts +1 -2
  45. package/dist/engine/text/layoutText.js +2 -4
  46. package/dist/engine/text/textMetrics.d.ts +19 -0
  47. package/dist/engine/text/textMetrics.js +24 -0
  48. package/dist/fonts/interFont.d.ts +5 -0
  49. package/dist/fonts/interFont.js +31 -0
  50. package/dist/fonts/workspaceFonts.d.ts +12 -0
  51. package/dist/fonts/workspaceFonts.js +51 -0
  52. package/dist/i18n/labels.js +2 -1
  53. package/dist/i18n/language.d.ts +3 -3
  54. package/dist/i18n/messages.d.ts +9 -6
  55. package/dist/i18n/messages.js +9 -6
  56. package/dist/settings/workspaceToolSettings.d.ts +45 -0
  57. package/dist/settings/workspaceToolSettings.js +90 -0
  58. package/package.json +3 -3
package/README.md CHANGED
@@ -191,6 +191,11 @@ that shape when the geometry is confident (a stroke it cannot decide is handed t
191
191
  The package constant `CANVAS_SHAPE_SNAP_ENABLED` stays `false`: it is the one line that turns the snap on for every page, or
192
192
  back off.
193
193
 
194
+ **Keep the drawing centred when the board is resized (off by default).** A page that lets its person drag the edges of the
195
+ board passes `keepCenterOnResize={true}` on `<Canvas>`: when the board grows or shrinks, the pan moves by half of the change
196
+ in size, so the drawing that was in the middle stays in the middle (the zoom does not change). Without it the top-left corner
197
+ of the board stays where it was, as before.
198
+
194
199
  [`__docs/dom-canvas.md`](./__docs/dom-canvas.md) explains the parts, the host contract, the document, the tools and the
195
200
  tests. The engine this one replaced is gone from the package, with no fallback to it: no dependency, no reader for its saved
196
201
  files, and no document about it. Its specs and progress log are only in the git history (`git show d824044:__specs/<file>`).
@@ -25,10 +25,11 @@
25
25
  import { onlyCardIsSelected } from '../engine/widgets.js';
26
26
  import { provideCanvasLanguage } from '../i18n/language.js';
27
27
  import { BOARD_FRAME_CLASSES } from './boardFrame.js';
28
+ import { BOARD_SURFACE_COLOR } from './boardSurface.js';
28
29
  import { CanvasHost, DEFAULT_HOST_PROPS } from './host/CanvasHost.js';
29
30
  import type { CanvasHostProps, SelectorGuide } from './host/CanvasHost.js';
30
31
  import { forwardToHost } from './host/CanvasHostApi.js';
31
- import { chromeSlots, panelClearanceFor, zoomVisibilityClasses } from './chromeLayout.js';
32
+ import { chromeSlots, panelClearanceFor, zoomVisibilityMinWidth } from './chromeLayout.js';
32
33
  import { DEFAULT_PAN_ZOOM_POSITION, normalizePanZoomPosition } from './panZoomPosition.js';
33
34
  import type { PanZoomPosition } from './panZoomPosition.js';
34
35
  import { DEFAULT_TOOLBAR_POSITION, normalizeToolbarPosition } from './toolbarPosition.js';
@@ -113,8 +114,8 @@
113
114
  // Callback fired once the changes have been quiet for autosaveDelayMs, and when the host or the page asks to flush.
114
115
  // Receives the serialized canvas JSON so the host doesn't need to call saveCanvas().
115
116
  // May return a promise: while it is pending no second autosave starts, and what changes meanwhile goes out in one
116
- // save after it, so a slow server is never flooded. A promise that rejects counts as a failed save (the changes stay
117
- // unsaved until the next change or flush).
117
+ // save after it, so a slow server is never flooded. A promise that rejects counts as a failed save: the changes stay
118
+ // unsaved, and the canvas asks again after the waits of autosaveRetryDelaysMs (a change or a flush asks too).
118
119
  export let onAutoSave: CanvasHostProps['onAutoSave'] = DEFAULT_HOST_PROPS.onAutoSave;
119
120
 
120
121
  // Delay in ms for the internal auto-save debounce: how long the canvas waits after the last change before onAutoSave.
@@ -124,6 +125,11 @@
124
125
  // The longest a change waits before it is saved, however busy the person stays. 0 means no limit. Default: 10000ms.
125
126
  export let autosaveMaxWaitMs: CanvasHostProps['autosaveMaxWaitMs'] = DEFAULT_HOST_PROPS.autosaveMaxWaitMs;
126
127
 
128
+ // After onAutoSave fails, the waits (ms) before each new try: the first after the first failure, the second after the
129
+ // second in a row, and so on. When they are used up the trying stops until the next change or flush. An empty list
130
+ // means no retry by itself. Default: 5, 10, 20, 40 and 60 seconds.
131
+ export let autosaveRetryDelaysMs: CanvasHostProps['autosaveRetryDelaysMs'] = DEFAULT_HOST_PROPS.autosaveRetryDelaysMs;
132
+
127
133
  // While set, a due autosave waits another delay instead of serializing.
128
134
  // (Flushing, when the page is hidden or the editor closes, saves whatever the hold.)
129
135
  export let suspendAutosave: CanvasHostProps['suspendAutosave'] = DEFAULT_HOST_PROPS.suspendAutosave;
@@ -184,6 +190,15 @@
184
190
  * becomes that shape. Off unless a page passes true: the package's own flag turns it on for every page.
185
191
  */
186
192
  export let shapeSnap: CanvasHostProps['shapeSnap'] = DEFAULT_HOST_PROPS.shapeSnap;
193
+ /** The drawing stays centred when the board is resized (a page that lets its person drag the edges). Off unless a page passes true. */
194
+ export let keepCenterOnResize: CanvasHostProps['keepCenterOnResize'] = DEFAULT_HOST_PROPS.keepCenterOnResize;
195
+
196
+ /** Workspace id for persisted tool settings (B16). */
197
+ export let workspaceId: CanvasHostProps['workspaceId'] = DEFAULT_HOST_PROPS.workspaceId;
198
+ /** Optional user id when the host distinguishes users inside one workspace embed. */
199
+ export let userId: CanvasHostProps['userId'] = DEFAULT_HOST_PROPS.userId;
200
+ /** Brand-kit fonts for this workspace (B15). */
201
+ export let workspaceFonts: CanvasHostProps['workspaceFonts'] = DEFAULT_HOST_PROPS.workspaceFonts;
187
202
 
188
203
  /**
189
204
  * The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
@@ -232,6 +247,7 @@
232
247
  onAutoSave,
233
248
  autosaveDelayMs,
234
249
  autosaveMaxWaitMs,
250
+ autosaveRetryDelaysMs,
235
251
  suspendAutosave,
236
252
  showSaveButton,
237
253
  onCanvasDirty,
@@ -249,7 +265,11 @@
249
265
  widgetNameRevision,
250
266
  isWidgetKnown,
251
267
  showLogs,
252
- shapeSnap
268
+ shapeSnap,
269
+ keepCenterOnResize,
270
+ workspaceId,
271
+ userId,
272
+ workspaceFonts
253
273
  };
254
274
  $: host.setProps(hostProps);
255
275
 
@@ -300,7 +320,7 @@
300
320
  $: toolbarAnchor = normalizeToolbarPosition(toolbarPosition);
301
321
  $: zoomAnchor = normalizePanZoomPosition(panZoomPosition);
302
322
  $: slots = chromeSlots(toolbarAnchor, zoomAnchor, { toolbar: showDrawingTools || showSelectorBar, zoom: showZoomControl });
303
- $: zoomVisibleFrom = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
323
+ $: zoomVisibleMinWidth = zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor);
304
324
  // The selection panel stands in the top corner at the end of the line: it keeps clear of the cards the page put there.
305
325
  $: panelClearance = panelClearanceFor(slots);
306
326
 
@@ -382,8 +402,9 @@
382
402
  <Tooltip.Provider delayDuration={400} skipDelayDuration={200}>
383
403
  <div
384
404
  bind:this={rootElement}
385
- class="{className ? className + ' ' : ''}canvas-container @container relative isolate h-full w-full overflow-visible bg-muted text-foreground outline-hidden {showContainerFrame ? BOARD_FRAME_CLASSES : ''}"
405
+ class="{className ? className + ' ' : ''}canvas-container @container relative isolate h-full w-full overflow-visible text-foreground outline-hidden {showContainerFrame ? BOARD_FRAME_CLASSES : ''}"
386
406
  {style}
407
+ style:background-color={BOARD_SURFACE_COLOR}
387
408
  data-canvas-root
388
409
  >
389
410
  <!-- The board: the pointer surface, with the objects, the selection, the text field and the loader. -->
@@ -411,7 +432,7 @@
411
432
  <SelectorBar active={elementSelectorActive} guide={selectorGuide} anchor={toolbarAnchor} onToggle={() => onToggleElementSelector?.()} />
412
433
  {/if}
413
434
  {:else}
414
- <ZoomControl {host} state={engineState} ui={uiState} anchor={zoomAnchor} visibleFrom={zoomVisibleFrom} showZoom={showZoomPanel} {showSaveButton} />
435
+ <ZoomControl {host} state={engineState} ui={uiState} anchor={zoomAnchor} visibleMinWidth={zoomVisibleMinWidth} showZoom={showZoomPanel} {showSaveButton} />
415
436
  {/if}
416
437
  {/each}
417
438
  </div>
@@ -444,6 +465,6 @@
444
465
  {/if}
445
466
 
446
467
  <!-- Where every menu, popover and tooltip is drawn: a layer without a size that is its own containing block. -->
447
- <div bind:this={floatingLayerElement} class={FLOATING_LAYER_CLASSES} data-canvas-floating-layer></div>
468
+ <div bind:this={floatingLayerElement} class={FLOATING_LAYER_CLASSES} data-canvas-floating-layer data-canvas-ui></div>
448
469
  </div>
449
470
  </Tooltip.Provider>
@@ -40,6 +40,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
40
40
  onAutoSave?: CanvasHostProps["onAutoSave"];
41
41
  autosaveDelayMs?: CanvasHostProps["autosaveDelayMs"];
42
42
  autosaveMaxWaitMs?: CanvasHostProps["autosaveMaxWaitMs"];
43
+ autosaveRetryDelaysMs?: CanvasHostProps["autosaveRetryDelaysMs"];
43
44
  suspendAutosave?: CanvasHostProps["suspendAutosave"];
44
45
  showSaveButton?: CanvasHostProps["showSaveButton"];
45
46
  onCanvasDirty?: CanvasHostProps["onCanvasDirty"];
@@ -61,6 +62,10 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
61
62
  * Whether a freehand stroke that is a clean shape (a circle, an oval, a rectangle, a triangle, a diamond, a hexagon)
62
63
  * becomes that shape. Off unless a page passes true: the package's own flag turns it on for every page.
63
64
  */ shapeSnap?: CanvasHostProps["shapeSnap"];
65
+ /** The drawing stays centred when the board is resized (a page that lets its person drag the edges). Off unless a page passes true. */ keepCenterOnResize?: CanvasHostProps["keepCenterOnResize"];
66
+ /** Workspace id for persisted tool settings (B16). */ workspaceId?: CanvasHostProps["workspaceId"];
67
+ /** Optional user id when the host distinguishes users inside one workspace embed. */ userId?: CanvasHostProps["userId"];
68
+ /** Brand-kit fonts for this workspace (B15). */ workspaceFonts?: CanvasHostProps["workspaceFonts"];
64
69
  /**
65
70
  * The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
66
71
  * the page's own words are in; `messages` are the page's own words, keyed like CANVAS_MESSAGES (a key left out
@@ -12,8 +12,10 @@
12
12
  * and everything that changed meanwhile goes out in a single save after it. A slow server is never flooded;
13
13
  * - **flush** sends whatever is unsaved at once, whatever the delay and the hold, for the moments a page is about to
14
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.
15
+ * - a save that fails leaves the changes unsaved and says so. It tries again only when the host gave it a **retry
16
+ * schedule** (`getRetryDelayMs`): a wait that grows with every failure in a row, and an end to the trying, so a
17
+ * server that is down is asked a handful of times and not hammered. With no schedule, the next change or the next
18
+ * flush is the retry. A change made after a failure starts its own quiet delay, which is the retry too.
17
19
  *
18
20
  * Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
19
21
  */
@@ -40,6 +42,12 @@ export interface AutosaveSchedulerOptions {
40
42
  isSuspended?: () => boolean;
41
43
  /** Told when a save failed. The changes stay unsaved. */
42
44
  onSaveFailed?: (error: unknown) => void;
45
+ /**
46
+ * How long to wait before trying again after a failed save, in milliseconds, given how many saves in a row have failed
47
+ * (1 after the first). A value of 0 (or less, or not a number) ends the trying: the next change or flush is the retry.
48
+ * Left out, a failed save is not tried again by itself. Read at every failure.
49
+ */
50
+ getRetryDelayMs?: (failuresInARow: number) => number;
43
51
  /** Defaults to the real one. */
44
52
  clock?: AutosaveClock;
45
53
  }
@@ -12,8 +12,10 @@
12
12
  * and everything that changed meanwhile goes out in a single save after it. A slow server is never flooded;
13
13
  * - **flush** sends whatever is unsaved at once, whatever the delay and the hold, for the moments a page is about to
14
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.
15
+ * - a save that fails leaves the changes unsaved and says so. It tries again only when the host gave it a **retry
16
+ * schedule** (`getRetryDelayMs`): a wait that grows with every failure in a row, and an end to the trying, so a
17
+ * server that is down is asked a handful of times and not hammered. With no schedule, the next change or the next
18
+ * flush is the retry. A change made after a failure starts its own quiet delay, which is the retry too.
17
19
  *
18
20
  * Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
19
21
  */
@@ -42,6 +44,8 @@ export function createAutosaveScheduler(options) {
42
44
  let saveOnItsWay = null;
43
45
  /** The next save fell due while another was on its way: it starts as soon as that one is done. */
44
46
  let dueWhileSaving = false;
47
+ /** 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;
45
49
  let disposed = false;
46
50
  function stopTimer() {
47
51
  if (timerHandle === null)
@@ -72,15 +76,32 @@ export function createAutosaveScheduler(options) {
72
76
  }
73
77
  void startSave();
74
78
  }
79
+ /** Sets a timer for the next try after a failure, when the host's schedule has one left. A timer that is already running is left alone: a change made since has its own. */
80
+ function scheduleRetry() {
81
+ if (disposed || timerHandle !== null || !options.getRetryDelayMs)
82
+ return;
83
+ let waitMs = 0;
84
+ try {
85
+ waitMs = toDurationMs(options.getRetryDelayMs(failuresInARow));
86
+ }
87
+ catch (scheduleError) {
88
+ console.warn('[autosave] getRetryDelayMs threw', scheduleError);
89
+ }
90
+ if (waitMs > 0)
91
+ startTimer(waitMs);
92
+ }
75
93
  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.
94
+ // What the failed save was meant to keep is not kept: it is unsaved again, and the retry (or the next change or
95
+ // flush) tries again.
77
96
  dirty = true;
97
+ failuresInARow += 1;
78
98
  try {
79
99
  options.onSaveFailed?.(error);
80
100
  }
81
101
  catch (reportError) {
82
102
  console.warn('[autosave] onSaveFailed threw', reportError);
83
103
  }
104
+ scheduleRetry();
84
105
  }
85
106
  /** Takes everything unsaved into a save, now. The promise it returns never rejects and settles when the save is done. */
86
107
  function startSave() {
@@ -97,10 +118,14 @@ export function createAutosaveScheduler(options) {
97
118
  noteFailure(error);
98
119
  return Promise.resolve();
99
120
  }
100
- if (!isPromiseLike(outcome))
121
+ if (!isPromiseLike(outcome)) {
122
+ failuresInARow = 0;
101
123
  return Promise.resolve();
124
+ }
102
125
  const running = Promise.resolve(outcome)
103
- .then(() => undefined, (error) => noteFailure(error))
126
+ .then(() => {
127
+ failuresInARow = 0;
128
+ }, (error) => noteFailure(error))
104
129
  .then(() => {
105
130
  if (saveOnItsWay === running)
106
131
  saveOnItsWay = null;
@@ -140,6 +165,7 @@ export function createAutosaveScheduler(options) {
140
165
  dirty = false;
141
166
  firstChangeAt = null;
142
167
  dueWhileSaving = false;
168
+ failuresInARow = 0;
143
169
  }
144
170
  function dispose() {
145
171
  cancel();
@@ -5,5 +5,9 @@
5
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
6
  * constant, read by the board and by the placeholder a page shows while the canvas is still downloading, so the swap
7
7
  * from one to the other cannot change colour.
8
+ *
9
+ * A page that wants another colour sets `--canvas-surface` on an element around the board (the home page's sketch card is
10
+ * white in the design, while the full canvas stays `muted`). Nothing else changes: the variable is not set anywhere else, so
11
+ * the board, the creator and the embeds keep the token.
8
12
  */
9
- export declare const BOARD_SURFACE_COLOR = "var(--muted, #f5f5f5)";
13
+ export declare const BOARD_SURFACE_COLOR = "var(--canvas-surface, var(--muted, #f5f5f5))";
@@ -5,5 +5,9 @@
5
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
6
  * constant, read by the board and by the placeholder a page shows while the canvas is still downloading, so the swap
7
7
  * from one to the other cannot change colour.
8
+ *
9
+ * A page that wants another colour sets `--canvas-surface` on an element around the board (the home page's sketch card is
10
+ * white in the design, while the full canvas stays `muted`). Nothing else changes: the variable is not set anywhere else, so
11
+ * the board, the creator and the embeds keep the token.
8
12
  */
9
- export const BOARD_SURFACE_COLOR = 'var(--muted, #f5f5f5)';
13
+ export const BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
@@ -61,6 +61,8 @@ export declare function chromeSlots(toolbarAnchor: ChromeAnchor, zoomAnchor: Chr
61
61
  * behind them are in `ZOOM_CONTROL_MIN_WIDTHS`.
62
62
  */
63
63
  export declare function zoomVisibilityClasses(toolbarAnchor: ChromeAnchor, zoomAnchor: ChromeAnchor): string;
64
+ /** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
65
+ export declare function zoomVisibilityMinWidth(toolbarAnchor: ChromeAnchor, zoomAnchor: ChromeAnchor): number;
64
66
  /** What the selection panel (top right, 336 px wide) has to keep clear of. */
65
67
  export interface PanelClearance {
66
68
  /** A card stands on the top edge: the panel starts below it. */
@@ -17,7 +17,7 @@
17
17
  *
18
18
  * Kept free of Svelte and of the DOM so that Node can test it.
19
19
  */
20
- import { ZOOM_CONTROL_VISIBLE_FROM } from './ui/floatingCard.js';
20
+ import { ZOOM_CONTROL_MIN_WIDTHS, ZOOM_CONTROL_VISIBLE_FROM } from './ui/floatingCard.js';
21
21
  /** The eight places a card can stand. */
22
22
  export const CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
23
23
  /**
@@ -111,11 +111,26 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
111
111
  return ZOOM_CONTROL_VISIBLE_FROM.centredBesideCornerToolbar;
112
112
  return ZOOM_CONTROL_VISIBLE_FROM.oppositeCorners;
113
113
  }
114
+ /** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
115
+ export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
116
+ const className = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
117
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.alone)
118
+ return ZOOM_CONTROL_MIN_WIDTHS.alone;
119
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.sameSlot)
120
+ return ZOOM_CONTROL_MIN_WIDTHS.sameSlot;
121
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.besideCentredToolbar)
122
+ return ZOOM_CONTROL_MIN_WIDTHS.besideCentredToolbar;
123
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.centredBesideCornerToolbar)
124
+ return ZOOM_CONTROL_MIN_WIDTHS.centredBesideCornerToolbar;
125
+ return ZOOM_CONTROL_MIN_WIDTHS.oppositeCorners;
126
+ }
127
+ const TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
114
128
  /** What the panel keeps clear of, for the slots that are drawn. */
115
129
  export function panelClearanceFor(slots) {
116
130
  const rightEdgeSlot = slots.find((slot) => slot.anchor === 'CR');
117
131
  return {
118
- belowTopCards: slots.some((slot) => isTopAnchor(slot.anchor)),
132
+ // Top-left chrome (e.g. zoom on the creator big page) does not overlap the top-right selection panel.
133
+ belowTopCards: slots.some((slot) => TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor)),
119
134
  besideSideCard: rightEdgeSlot ? (rightEdgeSlot.cards.includes('toolbar') ? 'toolbar' : 'zoom') : null
120
135
  };
121
136
  }
@@ -19,6 +19,8 @@ import type { TextLayout } from '../../engine/text/layoutText.js';
19
19
  import type { EngineState, ToolId } from '../../engine/state.js';
20
20
  import { ConversionRegistry } from '../../engine/widgets.js';
21
21
  import type { WidgetMetadata } from '../../engine/widgets.js';
22
+ import { type WorkspaceCanvasFont } from '../../fonts/workspaceFonts.js';
23
+ import type { StylePatch } from '../../engine/core/style.js';
22
24
  import type { PanZoomPosition } from '../panZoomPosition.js';
23
25
  import type { ToolbarPosition } from '../toolbarPosition.js';
24
26
  import type { Translate as CatalogTranslate } from '@widgetic/design-system/i18n';
@@ -37,6 +39,18 @@ export interface SelectorGuide {
37
39
  esc: string;
38
40
  done: string;
39
41
  }
42
+ /**
43
+ * What the canvas tells the page about a save, as the second argument of `onAutoSave`.
44
+ */
45
+ export interface AutosaveContext {
46
+ /**
47
+ * The page is going away (the browser sent `pagehide`: the tab closes, a reload, a navigation to another site). Nothing that
48
+ * waits survives that, so a page that sends the save to a server should send it as a request that outlives the page
49
+ * (`fetch` with `keepalive: true`), at once, and not behind a queue. It is false for every other save, and false again if the
50
+ * page comes back from the browser's back-forward cache (`pageshow`).
51
+ */
52
+ leaving: boolean;
53
+ }
40
54
  /**
41
55
  * Every prop of the canvas that the host reads. `class`, `style`, `locale` and `messages` belong to the shell (they
42
56
  * are about the element and the words), the rest are here. Each is read when it is needed, never copied.
@@ -60,9 +74,15 @@ export interface CanvasHostProps {
60
74
  onReady: (() => void) | null;
61
75
  isExternalDataLoading: boolean;
62
76
  onBeforeUnmount: ((json: string | null) => void) | null;
63
- onAutoSave: ((json: string | null) => void | Promise<unknown>) | null;
77
+ onAutoSave: ((json: string | null, context: AutosaveContext) => void | Promise<unknown>) | null;
64
78
  autosaveDelayMs: number;
65
79
  autosaveMaxWaitMs: number;
80
+ /**
81
+ * After `onAutoSave` fails (it throws or its promise rejects), how long to wait before each new try, in milliseconds:
82
+ * the first entry after the first failure, the second after the second one in a row, and so on. When the list is used
83
+ * up, the trying stops until the next change or flush. An empty list means a failed save is not tried again by itself.
84
+ */
85
+ autosaveRetryDelaysMs: readonly number[];
66
86
  suspendAutosave: boolean;
67
87
  showSaveButton: boolean;
68
88
  onCanvasDirty: (() => void) | null;
@@ -82,6 +102,15 @@ export interface CanvasHostProps {
82
102
  showLogs: boolean;
83
103
  /** Whether a freehand stroke that is a clean shape becomes that shape. Off unless the page passes true. */
84
104
  shapeSnap: boolean;
105
+ /**
106
+ * Whether the drawing stays centred when the board is resized (the pan moves by half of the change in size), for a page
107
+ * that lets its person drag the edges of the board. Off unless the page passes true: the top-left corner stays put then.
108
+ */
109
+ keepCenterOnResize: boolean;
110
+ /** Workspace id for per-workspace tool settings (localStorage by default). */
111
+ workspaceId: string | null;
112
+ userId: string | null;
113
+ workspaceFonts: readonly WorkspaceCanvasFont[];
85
114
  }
86
115
  /** What each prop is until the page sets it (the values the canvas this one replaces had, but for `panZoomPosition`). */
87
116
  export declare const DEFAULT_HOST_PROPS: Readonly<CanvasHostProps>;
@@ -156,6 +185,8 @@ export declare class CanvasHost {
156
185
  constructor(initialProps?: Partial<CanvasHostProps>);
157
186
  /** The page changed some props. */
158
187
  setProps(patch: Partial<CanvasHostProps>): void;
188
+ /** Persists tool style changes for this workspace (called from the selection panel). */
189
+ persistWorkspaceStyle(patch: StylePatch): void;
159
190
  /** The shell gives the host the words of the page's language. */
160
191
  setTranslator(translate: Translate): void;
161
192
  get ui(): HostUiState;