@widgetic/canvas 0.5.39 → 0.5.41

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 (134) hide show
  1. package/README.md +7 -3
  2. package/dist/canvas/DomCanvas.svelte +7 -3
  3. package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
  4. package/dist/canvas/autosaveScheduler.js +89 -37
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +19 -7
  8. package/dist/canvas/chromeLayout.d.ts +2 -0
  9. package/dist/canvas/chromeLayout.js +31 -17
  10. package/dist/canvas/eventScope.js +14 -10
  11. package/dist/canvas/host/CanvasHost.d.ts +6 -0
  12. package/dist/canvas/host/CanvasHost.js +1556 -1255
  13. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  14. package/dist/canvas/host/CanvasHostApi.js +25 -4
  15. package/dist/canvas/host/browserServices.js +116 -65
  16. package/dist/canvas/host/conversion.js +170 -82
  17. package/dist/canvas/host/hostObject.js +7 -7
  18. package/dist/canvas/host/pageEvents.js +4 -4
  19. package/dist/canvas/host/screenRects.js +31 -28
  20. package/dist/canvas/host/strokeSnap.js +143 -88
  21. package/dist/canvas/openMarks.js +2 -2
  22. package/dist/canvas/outsideClickDeselect.js +7 -6
  23. package/dist/canvas/panZoomPosition.js +2 -2
  24. package/dist/canvas/preferredTextFont.js +25 -13
  25. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  26. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  27. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  28. package/dist/canvas/toolbarPosition.js +2 -2
  29. package/dist/canvas/ui/CanvasContextMenu.svelte +69 -39
  30. package/dist/canvas/ui/CanvasHint.svelte +17 -4
  31. package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
  32. package/dist/canvas/ui/CanvasToolbar.svelte +27 -10
  33. package/dist/canvas/ui/ColorField.svelte +1 -1
  34. package/dist/canvas/ui/SelectionPanel.svelte +24 -20
  35. package/dist/canvas/ui/ShapesMenu.svelte +0 -2
  36. package/dist/canvas/ui/ToolButton.svelte +11 -3
  37. package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
  38. package/dist/canvas/ui/WidgetActions.svelte +1 -1
  39. package/dist/canvas/ui/ZoomControl.svelte +39 -4
  40. package/dist/canvas/ui/ZoomControl.svelte.d.ts +2 -2
  41. package/dist/canvas/ui/colorModel.js +32 -21
  42. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  43. package/dist/canvas/ui/floatingCard.d.ts +7 -5
  44. package/dist/canvas/ui/floatingCard.js +23 -21
  45. package/dist/canvas/ui/floatingLayer.js +6 -5
  46. package/dist/canvas/ui/keyHints.d.ts +5 -0
  47. package/dist/canvas/ui/keyHints.js +23 -7
  48. package/dist/canvas/ui/popoverSide.js +3 -2
  49. package/dist/canvas/ui/selectionTraits.js +40 -34
  50. package/dist/canvas/ui/sizeLabelVisibility.d.ts +5 -2
  51. package/dist/canvas/ui/sizeLabelVisibility.js +7 -6
  52. package/dist/canvas/ui/widgetSelectionPanel.d.ts +6 -0
  53. package/dist/canvas/ui/widgetSelectionPanel.js +9 -0
  54. package/dist/canvas/view/ObjectView.svelte +2 -1
  55. package/dist/canvas/view/SelectionOverlay.svelte +34 -14
  56. package/dist/canvas/view/erasingMarks.js +7 -7
  57. package/dist/canvas/view/geometry.d.ts +14 -4
  58. package/dist/canvas/view/geometry.js +103 -77
  59. package/dist/components/preferenceStorage.js +2 -2
  60. package/dist/engine/EngineCore.d.ts +4 -1
  61. package/dist/engine/EngineCore.js +801 -695
  62. package/dist/engine/codec/canvasDocument.js +173 -173
  63. package/dist/engine/codec/hostReadableKeys.js +1 -1
  64. package/dist/engine/core/arrange.js +38 -26
  65. package/dist/engine/core/arrow.d.ts +10 -3
  66. package/dist/engine/core/arrow.js +96 -75
  67. package/dist/engine/core/arrowBinding.d.ts +69 -0
  68. package/dist/engine/core/arrowBinding.js +344 -0
  69. package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
  70. package/dist/engine/core/arrowBindingRecords.js +141 -0
  71. package/dist/engine/core/brush.js +94 -67
  72. package/dist/engine/core/defaults.js +51 -90
  73. package/dist/engine/core/freehand.js +163 -147
  74. package/dist/engine/core/geometry.js +54 -47
  75. package/dist/engine/core/history.js +50 -33
  76. package/dist/engine/core/hitTest.d.ts +3 -0
  77. package/dist/engine/core/hitTest.js +83 -69
  78. package/dist/engine/core/matrix.js +20 -18
  79. package/dist/engine/core/pathData.js +210 -183
  80. package/dist/engine/core/rotationReset.js +6 -5
  81. package/dist/engine/core/scene.d.ts +3 -0
  82. package/dist/engine/core/scene.js +192 -129
  83. package/dist/engine/core/scribble.js +84 -59
  84. package/dist/engine/core/shapePaths.js +15 -12
  85. package/dist/engine/core/shapeTools.js +63 -72
  86. package/dist/engine/core/snapping.js +117 -65
  87. package/dist/engine/core/style.js +64 -31
  88. package/dist/engine/core/transform.js +94 -83
  89. package/dist/engine/core/types.d.ts +29 -0
  90. package/dist/engine/core/types.js +4 -4
  91. package/dist/engine/core/viewport.js +36 -23
  92. package/dist/engine/input/PointerController.js +476 -447
  93. package/dist/engine/input/arrowHandles.js +12 -12
  94. package/dist/engine/input/gestures.d.ts +12 -1
  95. package/dist/engine/input/gestures.js +342 -251
  96. package/dist/engine/input/hoverCursor.js +1 -1
  97. package/dist/engine/input/keyboard.d.ts +9 -1
  98. package/dist/engine/input/keyboard.js +46 -27
  99. package/dist/engine/input/selectionHandles.js +50 -45
  100. package/dist/engine/input/types.js +1 -1
  101. package/dist/engine/render/rasterize.js +158 -86
  102. package/dist/engine/state.d.ts +6 -1
  103. package/dist/engine/state.js +17 -5
  104. package/dist/engine/text/layoutText.js +62 -43
  105. package/dist/engine/text/textMetrics.js +10 -8
  106. package/dist/engine/widgets.js +137 -101
  107. package/dist/fonts/interFont.js +68 -17
  108. package/dist/fonts/workspaceFonts.js +90 -32
  109. package/dist/i18n/labels.js +6 -5
  110. package/dist/i18n/language.js +4 -4
  111. package/dist/i18n/messages.d.ts +6 -6
  112. package/dist/i18n/messages.js +7 -7
  113. package/dist/i18n/shortcuts.d.ts +12 -0
  114. package/dist/i18n/shortcuts.js +32 -18
  115. package/dist/settings/workspaceToolSettings.js +48 -32
  116. package/dist/tools/components/catalog.d.ts +11 -0
  117. package/dist/tools/components/catalog.js +270 -0
  118. package/dist/tools/components/grouping.d.ts +9 -0
  119. package/dist/tools/components/grouping.js +33 -0
  120. package/dist/tools/definitions.d.ts +19 -0
  121. package/dist/tools/definitions.js +147 -0
  122. package/dist/tools/executors.d.ts +7 -0
  123. package/dist/tools/executors.js +324 -0
  124. package/dist/tools/hostAdapter.d.ts +14 -0
  125. package/dist/tools/hostAdapter.js +40 -0
  126. package/dist/tools/index.d.ts +6 -0
  127. package/dist/tools/index.js +6 -0
  128. package/dist/tools/sceneSummary.d.ts +24 -0
  129. package/dist/tools/sceneSummary.js +170 -0
  130. package/dist/tools/sketchIntent.d.ts +17 -0
  131. package/dist/tools/sketchIntent.js +166 -0
  132. package/dist/tools/types.d.ts +54 -0
  133. package/dist/tools/types.js +11 -0
  134. package/package.json +7 -2
package/README.md CHANGED
@@ -133,8 +133,8 @@ console says `[Canvas] ...` once.
133
133
  `onRecognizeStroke` (`rectangle or square`, `oval (ellipse)` …) are written for the recognizer, not for a screen: they
134
134
  stay English. Each screen says the groups and the shapes through a message (`canvas.category.*`, `canvas.shape.*`).
135
135
  - **Keys.** Names of keys that are words (`Ctrl/Cmd`, `Del`, `Click`) are messages, so a language can write "Strg" or
136
- "Entf". Letters and symbols (`V`, `↑`, `]`) are the same on every keyboard, and the `⌘` glyphs in the menus are the
137
- Mac key caps.
136
+ "Entf". Letters, digits and symbols (`V`, `3`, `↑`, `]`) are the same on every keyboard, and the `⌘` glyphs in the
137
+ menus are the Mac key caps.
138
138
  - **Right to left.** The canvas has no prop for it: its toolbar, the selection panel, the menus and the lists are laid
139
139
  out with logical sides (`start` and `end`, never `left` and `right`), so they start at the start of the line wherever
140
140
  the screen around the canvas is read right to left (the widget creator sets that on its root). The drawing board
@@ -178,7 +178,10 @@ each stroke as its line and its pressures (`ink`) and draws the outline again wh
178
178
 
179
179
  **An arrow is two points and a bend.** Its open head keeps its size when the arrow is stretched, a selected arrow has a handle
180
180
  on each end and one in the middle that bends it (**Shift** holds the direction to steps of 15°), and a board saves it as
181
- `arrow` and draws the outline again when it is read. An arrow does not attach to a shape. **The eraser marks** the shapes the
181
+ `arrow` and draws the outline again when it is read. **An end of an arrow can be tied to a shape**, the way tldraw's can: dragged
182
+ over a shape, it rests on the nearest point of the outline (near the edge) or aims at the middle of the shape (further in), the
183
+ board shows which shape and where, and the arrow follows the shape when it is moved, stretched, turned or typed in (**Alt** while
184
+ drawing or dragging an end ties nothing; moving the arrow by itself lets go). **The eraser marks** the shapes the
182
185
  pointer passes over, dimmed, and removes them all in one step on release (**Esc** leaves them).
183
186
 
184
187
  **The toolbar and the zoom control stand at one of eight places:** `toolbarPosition` and `panZoomPosition` take `TL` `TC` `TR`
@@ -224,6 +227,7 @@ ORIGIN=http://127.0.0.1:5181 node scripts/browser/handles.mjs # handles an
224
227
  ORIGIN=http://127.0.0.1:5181 node scripts/browser/marquee.mjs # what a marquee would take is outlined while it is dragged
225
228
  ORIGIN=http://127.0.0.1:5181 node scripts/browser/outlinePixels.mjs # ... and that outline is the pointer's, pixel for pixel
226
229
  ORIGIN=http://127.0.0.1:5181 node scripts/browser/arrows.mjs # arrows and their handles
230
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/arrowTies.mjs # arrows tied to shapes follow them
227
231
  npm run build && npx vite preview --port 5182 # a production build, in one terminal ...
228
232
  node scripts/browser/stress.mjs # ... and the frame cost, in another
229
233
  ```
@@ -29,7 +29,7 @@
29
29
  import { CanvasHost, DEFAULT_HOST_PROPS } from './host/CanvasHost.js';
30
30
  import type { CanvasHostProps, SelectorGuide } from './host/CanvasHost.js';
31
31
  import { forwardToHost } from './host/CanvasHostApi.js';
32
- import { chromeSlots, panelClearanceFor, zoomVisibilityClasses } from './chromeLayout.js';
32
+ import { chromeSlots, panelClearanceFor, zoomVisibilityMinWidth } from './chromeLayout.js';
33
33
  import { DEFAULT_PAN_ZOOM_POSITION, normalizePanZoomPosition } from './panZoomPosition.js';
34
34
  import type { PanZoomPosition } from './panZoomPosition.js';
35
35
  import { DEFAULT_TOOLBAR_POSITION, normalizeToolbarPosition } from './toolbarPosition.js';
@@ -320,7 +320,7 @@
320
320
  $: toolbarAnchor = normalizeToolbarPosition(toolbarPosition);
321
321
  $: zoomAnchor = normalizePanZoomPosition(panZoomPosition);
322
322
  $: slots = chromeSlots(toolbarAnchor, zoomAnchor, { toolbar: showDrawingTools || showSelectorBar, zoom: showZoomControl });
323
- $: zoomVisibleFrom = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
323
+ $: zoomVisibleMinWidth = zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor);
324
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.
325
325
  $: panelClearance = panelClearanceFor(slots);
326
326
 
@@ -397,6 +397,10 @@
397
397
  // Added to the contract. The widget creator's in-flight branches call it, and the simple-board branch
398
398
  // (feat/shopify-feedback-canvas) adds the same function (same name, same answer).
399
399
  export const removeSketchObjectsKeepingWidget = forwardToHost(host, 'removeSketchObjectsKeepingWidget');
400
+ export const getSketchSceneSummary = forwardToHost(host, 'getSketchSceneSummary');
401
+ export const executeSketchTool = forwardToHost(host, 'executeSketchTool');
402
+ export const beginSketchToolBatch = forwardToHost(host, 'beginSketchToolBatch');
403
+ export const endSketchToolBatch = forwardToHost(host, 'endSketchToolBatch');
400
404
  </script>
401
405
 
402
406
  <Tooltip.Provider delayDuration={400} skipDelayDuration={200}>
@@ -432,7 +436,7 @@
432
436
  <SelectorBar active={elementSelectorActive} guide={selectorGuide} anchor={toolbarAnchor} onToggle={() => onToggleElementSelector?.()} />
433
437
  {/if}
434
438
  {:else}
435
- <ZoomControl {host} state={engineState} ui={uiState} anchor={zoomAnchor} visibleFrom={zoomVisibleFrom} showZoom={showZoomPanel} {showSaveButton} />
439
+ <ZoomControl {host} state={engineState} ui={uiState} anchor={zoomAnchor} visibleMinWidth={zoomVisibleMinWidth} showZoom={showZoomPanel} {showSaveButton} />
436
440
  {/if}
437
441
  {/each}
438
442
  </div>
@@ -145,6 +145,10 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
145
145
  addFrame?: () => null;
146
146
  addImage?: () => Promise<void>;
147
147
  removeSketchObjectsKeepingWidget?: (widgetId: string) => number;
148
+ getSketchSceneSummary?: () => import("../tools/types.js").SceneSummary;
149
+ executeSketchTool?: (name: string, args: Record<string, unknown>) => import("../tools/types.js").ToolResult;
150
+ beginSketchToolBatch?: () => void;
151
+ endSketchToolBatch?: () => void;
148
152
  }, {
149
153
  [evt: string]: CustomEvent<any>;
150
154
  }, {}, {
@@ -221,6 +225,10 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
221
225
  addFrame: () => null;
222
226
  addImage: () => Promise<void>;
223
227
  removeSketchObjectsKeepingWidget: (widgetId: string) => number;
228
+ getSketchSceneSummary: () => import("../tools/types.js").SceneSummary;
229
+ executeSketchTool: (name: string, args: Record<string, unknown>) => import("../tools/types.js").ToolResult;
230
+ beginSketchToolBatch: () => void;
231
+ endSketchToolBatch: () => void;
224
232
  }, string>;
225
233
  type DomCanvas = InstanceType<typeof DomCanvas>;
226
234
  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
  }
@@ -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,14 +17,14 @@
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
- export const CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
22
+ export var CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
23
23
  /**
24
24
  * The classes that put an anchor in place, 16 px from the edges as the Figma design has it. Written out in full, so that
25
25
  * the stylesheet of a page that installs the canvas picks every one of them up when it reads this file.
26
26
  */
27
- const ANCHOR_CLASSES = {
27
+ var ANCHOR_CLASSES = {
28
28
  // rtl-ok: the page names a corner of the screen, as it is drawn
29
29
  TL: 'absolute top-4 left-4',
30
30
  TC: 'absolute top-4 left-1/2 -translate-x-1/2',
@@ -45,9 +45,9 @@ const ANCHOR_CLASSES = {
45
45
  * are against), a column on a side edge (centred on each other, so the layout does not depend on the direction of the
46
46
  * page). A slot never grows larger than the board minus its 16 px edges.
47
47
  */
48
- const SLOT_TOP_ROW_CLASSES = 'flex flex-row items-start gap-2 max-w-[calc(100%-2rem)]';
49
- const SLOT_BOTTOM_ROW_CLASSES = 'flex flex-row items-end gap-2 max-w-[calc(100%-2rem)]';
50
- const SLOT_COLUMN_CLASSES = 'flex flex-col items-center gap-2 max-h-[calc(100%-2rem)]';
48
+ var SLOT_TOP_ROW_CLASSES = 'flex flex-row items-start gap-2 max-w-[calc(100%-2rem)]';
49
+ var SLOT_BOTTOM_ROW_CLASSES = 'flex flex-row items-end gap-2 max-w-[calc(100%-2rem)]';
50
+ var SLOT_COLUMN_CLASSES = 'flex flex-col items-center gap-2 max-h-[calc(100%-2rem)]';
51
51
  /** 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. */
52
52
  export function normalizeAnchor(value, fallback) {
53
53
  return CHROME_ANCHORS.includes(value) ? value : fallback;
@@ -77,18 +77,19 @@ export function anchorClasses(anchor) {
77
77
  * from one anchor to another does not make the other one start again.
78
78
  */
79
79
  export function chromeSlots(toolbarAnchor, zoomAnchor, shown) {
80
- const slots = [];
81
- for (const anchor of CHROME_ANCHORS) {
82
- const cards = [];
80
+ var slots = [];
81
+ for (var _i = 0, CHROME_ANCHORS_1 = CHROME_ANCHORS; _i < CHROME_ANCHORS_1.length; _i++) {
82
+ var anchor = CHROME_ANCHORS_1[_i];
83
+ var cards = [];
83
84
  if (shown.toolbar && toolbarAnchor === anchor)
84
85
  cards.push('toolbar');
85
86
  if (shown.zoom && zoomAnchor === anchor)
86
87
  cards.push('zoom');
87
88
  if (cards.length === 0)
88
89
  continue;
89
- const vertical = isSideAnchor(anchor);
90
- const layout = vertical ? SLOT_COLUMN_CLASSES : isTopAnchor(anchor) ? SLOT_TOP_ROW_CLASSES : SLOT_BOTTOM_ROW_CLASSES;
91
- slots.push({ anchor, cards, vertical, classes: `${ANCHOR_CLASSES[anchor]} ${layout}` });
90
+ var vertical = isSideAnchor(anchor);
91
+ var layout = vertical ? SLOT_COLUMN_CLASSES : isTopAnchor(anchor) ? SLOT_TOP_ROW_CLASSES : SLOT_BOTTOM_ROW_CLASSES;
92
+ slots.push({ anchor: anchor, cards: cards, vertical: vertical, classes: "".concat(ANCHOR_CLASSES[anchor], " ").concat(layout) });
92
93
  }
93
94
  return slots;
94
95
  }
@@ -101,8 +102,8 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
101
102
  // A card on a side edge shares no line with a card on the top or the bottom edge, and neither do two cards on different edges.
102
103
  if (isSideAnchor(toolbarAnchor) || isSideAnchor(zoomAnchor) || toolbarAnchor[0] !== zoomAnchor[0])
103
104
  return ZOOM_CONTROL_VISIBLE_FROM.alone;
104
- const toolbarColumn = toolbarAnchor[1];
105
- const zoomColumn = zoomAnchor[1];
105
+ var toolbarColumn = toolbarAnchor[1];
106
+ var zoomColumn = zoomAnchor[1];
106
107
  if (toolbarColumn === zoomColumn)
107
108
  return ZOOM_CONTROL_VISIBLE_FROM.sameSlot;
108
109
  if (toolbarColumn === 'C')
@@ -111,13 +112,26 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
111
112
  return ZOOM_CONTROL_VISIBLE_FROM.centredBesideCornerToolbar;
112
113
  return ZOOM_CONTROL_VISIBLE_FROM.oppositeCorners;
113
114
  }
114
- const TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
115
+ /** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
116
+ export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
117
+ var className = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
118
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.alone)
119
+ return ZOOM_CONTROL_MIN_WIDTHS.alone;
120
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.sameSlot)
121
+ return ZOOM_CONTROL_MIN_WIDTHS.sameSlot;
122
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.besideCentredToolbar)
123
+ return ZOOM_CONTROL_MIN_WIDTHS.besideCentredToolbar;
124
+ if (className === ZOOM_CONTROL_VISIBLE_FROM.centredBesideCornerToolbar)
125
+ return ZOOM_CONTROL_MIN_WIDTHS.centredBesideCornerToolbar;
126
+ return ZOOM_CONTROL_MIN_WIDTHS.oppositeCorners;
127
+ }
128
+ var TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
115
129
  /** What the panel keeps clear of, for the slots that are drawn. */
116
130
  export function panelClearanceFor(slots) {
117
- const rightEdgeSlot = slots.find((slot) => slot.anchor === 'CR');
131
+ var rightEdgeSlot = slots.find(function (slot) { return slot.anchor === 'CR'; });
118
132
  return {
119
133
  // Top-left chrome (e.g. zoom on the creator big page) does not overlap the top-right selection panel.
120
- belowTopCards: slots.some((slot) => TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor)),
134
+ belowTopCards: slots.some(function (slot) { return TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor); }),
121
135
  besideSideCard: rightEdgeSlot ? (rightEdgeSlot.cards.includes('toolbar') ? 'toolbar' : 'zoom') : null
122
136
  };
123
137
  }
@@ -16,9 +16,10 @@
16
16
  */
17
17
  /** The shadow root a node lives in, or null when it lives in the page itself (or is not in a tree at all). */
18
18
  export function getShadowRootOf(node) {
19
- const root = node?.getRootNode?.();
19
+ var _a;
20
+ var root = (_a = node === null || node === void 0 ? void 0 : node.getRootNode) === null || _a === void 0 ? void 0 : _a.call(node);
20
21
  // (`instanceof ShadowRoot` would not hold for a root made by another window, an iframe's, say.)
21
- const isShadowRoot = !!root && root.nodeType === 11 && 'host' in root;
22
+ var isShadowRoot = !!root && root.nodeType === 11 && 'host' in root;
22
23
  return isShadowRoot ? root : null;
23
24
  }
24
25
  /**
@@ -31,14 +32,14 @@ export function getShadowRootOf(node) {
31
32
  * Has to be called while the event is being dispatched (`composedPath()` is empty afterwards).
32
33
  */
33
34
  export function eventIsForScope(event, scopeNode) {
34
- const shadowRoot = getShadowRootOf(scopeNode);
35
+ var shadowRoot = getShadowRootOf(scopeNode);
35
36
  if (!shadowRoot)
36
37
  return true;
37
38
  return event.composedPath().includes(shadowRoot);
38
39
  }
39
40
  /** The element that has the focus in the tree `scopeNode` lives in: the page's, or the shadow root's own. */
40
41
  export function getFocusedElementIn(scopeNode) {
41
- const shadowRoot = getShadowRootOf(scopeNode);
42
+ var shadowRoot = getShadowRootOf(scopeNode);
42
43
  return shadowRoot ? shadowRoot.activeElement : document.activeElement;
43
44
  }
44
45
  /**
@@ -46,7 +47,8 @@ export function getFocusedElementIn(scopeNode) {
46
47
  * event from inside a shadow root; the first element of the path is the one that was pressed.
47
48
  */
48
49
  export function getEventOrigin(event) {
49
- const first = event.composedPath()[0] ?? event.target;
50
+ var _a;
51
+ var first = (_a = event.composedPath()[0]) !== null && _a !== void 0 ? _a : event.target;
50
52
  return first && first.nodeType === 1 ? first : null;
51
53
  }
52
54
  /**
@@ -64,7 +66,8 @@ export function eventWentThrough(event, element) {
64
66
  * page never sees it, and otherwise `document.body`.
65
67
  */
66
68
  export function getTransientHostFor(scopeNode) {
67
- return getShadowRootOf(scopeNode) ?? document.body;
69
+ var _a;
70
+ return (_a = getShadowRootOf(scopeNode)) !== null && _a !== void 0 ? _a : document.body;
68
71
  }
69
72
  /**
70
73
  * Whether the canvas whose element is `scopeNode` should take the keyboard back after the element that held it went away
@@ -76,14 +79,15 @@ export function getTransientHostFor(scopeNode) {
76
79
  * the shortcuts do not mind where the focus is, so there is nothing to do.
77
80
  */
78
81
  export function shouldTakeFocusBack(scopeNode) {
79
- const shadowRoot = getShadowRootOf(scopeNode);
82
+ var _a;
83
+ var shadowRoot = getShadowRootOf(scopeNode);
80
84
  if (!shadowRoot)
81
85
  return false;
82
86
  if (shadowRoot.activeElement)
83
87
  return false;
84
88
  // The focus in the tree the shadow root's host is in (the page's, or another shadow root's).
85
- const outerTree = shadowRoot.host.getRootNode();
86
- const focusOutside = outerTree.activeElement;
87
- const outerBody = outerTree.body ?? null;
89
+ var outerTree = shadowRoot.host.getRootNode();
90
+ var focusOutside = outerTree.activeElement;
91
+ var outerBody = (_a = outerTree.body) !== null && _a !== void 0 ? _a : null;
88
92
  return !focusOutside || focusOutside === shadowRoot.host || focusOutside === outerBody;
89
93
  }
@@ -376,4 +376,10 @@ export declare class CanvasHost {
376
376
  createId(prefix?: string): ObjectId;
377
377
  /** A plain rectangle in the middle of the view (used by the stress page). */
378
378
  makeRect(fields?: Partial<Parameters<typeof createRectObject>[0]>): ObjectId;
379
+ /** Scene summary for the sketch assistant (ids, labels, bounding boxes). */
380
+ getSketchSceneSummary(): import("../../tools/types.js").SceneSummary;
381
+ beginSketchToolBatch(): void;
382
+ endSketchToolBatch(): void;
383
+ /** Run one allow-listed sketch tool (batched into one undo step when a batch is open). */
384
+ executeSketchTool(name: string, args: Record<string, unknown>): import("../../tools/types.js").ToolResult;
379
385
  }