@widgetic/canvas 0.5.45 → 0.5.46

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 (113) hide show
  1. package/README.md +1 -1
  2. package/dist/canvas/autosaveScheduler.js +37 -89
  3. package/dist/canvas/boardFrame.js +1 -1
  4. package/dist/canvas/boardSurface.js +1 -1
  5. package/dist/canvas/canvasLogger.js +7 -19
  6. package/dist/canvas/chromeLayout.js +19 -21
  7. package/dist/canvas/eventScope.js +10 -14
  8. package/dist/canvas/host/CanvasHost.d.ts +6 -2
  9. package/dist/canvas/host/CanvasHost.js +1615 -1847
  10. package/dist/canvas/host/CanvasHostApi.js +4 -19
  11. package/dist/canvas/host/boardFiles.js +35 -51
  12. package/dist/canvas/host/browserServices.js +108 -196
  13. package/dist/canvas/host/conversion.js +82 -170
  14. package/dist/canvas/host/hostObject.js +7 -7
  15. package/dist/canvas/host/nearCards.js +18 -21
  16. package/dist/canvas/host/pageEvents.js +5 -5
  17. package/dist/canvas/host/pictureSaves.js +9 -11
  18. package/dist/canvas/host/screenRects.js +28 -31
  19. package/dist/canvas/host/storedPictures.js +149 -243
  20. package/dist/canvas/host/strokeSnap.js +88 -143
  21. package/dist/canvas/index.d.ts +1 -1
  22. package/dist/canvas/openMarks.js +2 -2
  23. package/dist/canvas/outsideClickDeselect.js +6 -7
  24. package/dist/canvas/panZoomPosition.js +2 -2
  25. package/dist/canvas/preferredTextFont.js +13 -25
  26. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  27. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  28. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  29. package/dist/canvas/toolbarPosition.js +2 -2
  30. package/dist/canvas/types.d.ts +7 -1
  31. package/dist/canvas/ui/colorModel.js +21 -32
  32. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  33. package/dist/canvas/ui/floatingCard.js +21 -21
  34. package/dist/canvas/ui/floatingLayer.js +5 -6
  35. package/dist/canvas/ui/keyHints.js +9 -11
  36. package/dist/canvas/ui/popoverSide.js +2 -3
  37. package/dist/canvas/ui/selectionTraits.js +35 -41
  38. package/dist/canvas/view/CanvasStage.svelte +1 -1
  39. package/dist/canvas/view/erasingMarks.js +7 -7
  40. package/dist/canvas/view/geometry.js +71 -90
  41. package/dist/canvas/view/liftedScene.js +24 -36
  42. package/dist/canvas/view/mountedScene.js +76 -79
  43. package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
  44. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
  45. package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
  46. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
  47. package/dist/components/boardLoaderDelay.d.ts +39 -0
  48. package/dist/components/boardLoaderDelay.js +71 -0
  49. package/dist/components/preferenceStorage.js +2 -2
  50. package/dist/engine/EngineCore.d.ts +9 -2
  51. package/dist/engine/EngineCore.js +798 -907
  52. package/dist/engine/codec/canvasDocument.js +192 -155
  53. package/dist/engine/codec/hostReadableKeys.js +1 -1
  54. package/dist/engine/core/arrange.js +26 -38
  55. package/dist/engine/core/arrow.js +79 -92
  56. package/dist/engine/core/arrowBinding.js +98 -116
  57. package/dist/engine/core/arrowBindingRecords.js +23 -38
  58. package/dist/engine/core/brush.js +84 -96
  59. package/dist/engine/core/cameraMove.js +39 -51
  60. package/dist/engine/core/defaults.js +92 -51
  61. package/dist/engine/core/freehand.js +147 -163
  62. package/dist/engine/core/geometry.js +47 -54
  63. package/dist/engine/core/history.js +38 -55
  64. package/dist/engine/core/hitTest.js +68 -81
  65. package/dist/engine/core/matrix.js +18 -20
  66. package/dist/engine/core/pathData.js +183 -210
  67. package/dist/engine/core/rotationReset.js +5 -6
  68. package/dist/engine/core/scene.js +160 -224
  69. package/dist/engine/core/scribble.js +59 -84
  70. package/dist/engine/core/shapePaths.js +12 -15
  71. package/dist/engine/core/shapeTools.js +72 -63
  72. package/dist/engine/core/snapping.js +65 -117
  73. package/dist/engine/core/style.js +32 -65
  74. package/dist/engine/core/transform.js +84 -95
  75. package/dist/engine/core/types.js +4 -4
  76. package/dist/engine/core/viewport.js +23 -36
  77. package/dist/engine/input/PointerController.js +513 -526
  78. package/dist/engine/input/arrowHandles.js +12 -12
  79. package/dist/engine/input/gestures.js +267 -310
  80. package/dist/engine/input/hoverCursor.js +1 -1
  81. package/dist/engine/input/keyboard.js +35 -39
  82. package/dist/engine/input/selectionHandles.js +45 -50
  83. package/dist/engine/input/types.js +1 -1
  84. package/dist/engine/render/rasterize.js +86 -158
  85. package/dist/engine/state.js +6 -17
  86. package/dist/engine/text/layoutText.js +43 -62
  87. package/dist/engine/text/textMetrics.js +8 -10
  88. package/dist/engine/widgets.js +101 -137
  89. package/dist/fonts/interFont.js +30 -83
  90. package/dist/fonts/workspaceFonts.js +33 -92
  91. package/dist/i18n/labels.js +4 -4
  92. package/dist/i18n/language.js +4 -4
  93. package/dist/i18n/messages.js +1 -1
  94. package/dist/i18n/shortcuts.js +14 -14
  95. package/dist/index.d.ts +1 -1
  96. package/dist/poster/boardPlacement.js +28 -30
  97. package/dist/poster/boardPoster.js +58 -83
  98. package/dist/poster/paintBoardPoster.js +16 -39
  99. package/dist/poster/posterPictures.js +27 -43
  100. package/dist/settings/rememberedTool.d.ts +50 -0
  101. package/dist/settings/rememberedTool.js +68 -0
  102. package/dist/settings/workspaceToolSettings.d.ts +8 -0
  103. package/dist/settings/workspaceToolSettings.js +35 -48
  104. package/dist/tools/components/catalog.js +64 -74
  105. package/dist/tools/components/grouping.js +6 -28
  106. package/dist/tools/definitions.js +5 -5
  107. package/dist/tools/executors.js +137 -169
  108. package/dist/tools/hostAdapter.js +11 -13
  109. package/dist/tools/sceneSummary.js +43 -57
  110. package/dist/tools/sketchIntent.js +13 -21
  111. package/dist/tools/styleArguments.js +19 -21
  112. package/dist/tools/types.js +1 -1
  113. package/package.json +2 -2
@@ -43,9 +43,9 @@ import { shapeVisualBounds } from '../../engine/core/scene.js';
43
43
  import { isBoxedObject } from '../../engine/core/types.js';
44
44
  import { visibleWorldRect } from '../../engine/core/viewport.js';
45
45
  /** A board with fewer objects than this keeps an element for every one of them. */
46
- export var CULLING_MINIMUM_OBJECTS = 150;
46
+ export const CULLING_MINIMUM_OBJECTS = 150;
47
47
  /** How far past the view an object is given an element, as a share of the view's width and height, on every side. */
48
- export var NEAR_MARGIN_RATIO = 0.5;
48
+ export const NEAR_MARGIN_RATIO = 0.5;
49
49
  /**
50
50
  * How far past the view an object that has an element keeps it, in the same measure. More than `NEAR_MARGIN_RATIO`: an object
51
51
  * is not made at the edge of the near area and taken away the moment the view has moved a little, which would have a pan that
@@ -53,30 +53,30 @@ export var NEAR_MARGIN_RATIO = 0.5;
53
53
  * an element is what is in this area, which is nine views. It is not used by a view that has just zoomed in, nor by the first
54
54
  * area of a board (see `nearAreaAround`).
55
55
  */
56
- export var KEEP_MARGIN_RATIO = 1;
56
+ export const KEEP_MARGIN_RATIO = 1;
57
57
  /**
58
58
  * How far the view may go past where it was when the near area was made, as a share of the view, before the area is made again.
59
59
  * What is left of the margin at that moment is the room that a quick pan has before it reaches an object without an element.
60
60
  */
61
- export var REFRESH_DISTANCE_RATIO = 0.15;
61
+ export const REFRESH_DISTANCE_RATIO = 0.15;
62
62
  /** The area is made again once the view has zoomed in by this factor: the objects that are not near the view now lose their element at once. */
63
- export var ZOOM_IN_REFRESH_RATIO = 1.5;
63
+ export const ZOOM_IN_REFRESH_RATIO = 1.5;
64
64
  /** How many objects that had no element get one in the first frame, when many are wanted at once (what follows adapts, see below). */
65
- export var MOUNT_BATCH_SIZE = 30;
65
+ export const MOUNT_BATCH_SIZE = 30;
66
66
  /** The batch never gets smaller than this, so that a very slow device (or a frame that is slow for another reason, a zoom with a thousand objects in view) still gets somewhere... */
67
- export var MIN_MOUNT_BATCH_SIZE = 16;
67
+ export const MIN_MOUNT_BATCH_SIZE = 16;
68
68
  /** ...and never larger than this, however quick the frames are: one frame must stay a frame's work. */
69
- export var MAX_MOUNT_BATCH_SIZE = 120;
69
+ export const MAX_MOUNT_BATCH_SIZE = 120;
70
70
  /** What the batch grows by after a frame that came on time. */
71
- export var MOUNT_BATCH_GROWTH = 8;
71
+ export const MOUNT_BATCH_GROWTH = 8;
72
72
  /** A frame that comes later than this after the one before it (a frame at 60 Hz is 16.7 ms) says the last batch was too much. */
73
- export var SLOW_FRAME_MS = 24;
73
+ export const SLOW_FRAME_MS = 24;
74
74
  /** A frame that comes sooner than this after the one before it says the last batch left room. */
75
- export var QUICK_FRAME_MS = 20;
75
+ export const QUICK_FRAME_MS = 20;
76
76
  /** Frames further apart than this were not being drawn (a hidden tab): they say nothing of how much a batch costs. */
77
- export var PAUSED_FRAME_MS = 500;
77
+ export const PAUSED_FRAME_MS = 500;
78
78
  /** The list before anything was handed over (and the list of an empty board): one shared list. */
79
- export var NOTHING_MOUNTED = Object.freeze([]);
79
+ export const NOTHING_MOUNTED = Object.freeze([]);
80
80
  /**
81
81
  * The rectangle an object paints, in the world: its box turned, with the stroke or the brush's overflow, never negative in size.
82
82
  *
@@ -85,7 +85,7 @@ export var NOTHING_MOUNTED = Object.freeze([]);
85
85
  * whole of a board of 1,000 objects spent most of this module's time on the map and not on the measuring.
86
86
  */
87
87
  function paintedBoundsOf(shape) {
88
- var measured = shapeVisualBounds(shape);
88
+ const measured = shapeVisualBounds(shape);
89
89
  if (measured.width >= 0 && measured.height >= 0)
90
90
  return measured;
91
91
  // A box that was written with a negative size is the same box from the other corner.
@@ -98,8 +98,8 @@ function paintedBoundsOf(shape) {
98
98
  }
99
99
  /** A view with `ratio` of its width and height added on every side. */
100
100
  function viewWithMargin(view, ratio) {
101
- var marginX = view.width * ratio;
102
- var marginY = view.height * ratio;
101
+ const marginX = view.width * ratio;
102
+ const marginY = view.height * ratio;
103
103
  return { x: view.x - marginX, y: view.y - marginY, width: view.width + marginX * 2, height: view.height + marginY * 2 };
104
104
  }
105
105
  /**
@@ -111,10 +111,10 @@ function viewWithMargin(view, ratio) {
111
111
  * size yet does), has the keep area of the near area: what is not near it loses its element at once.
112
112
  */
113
113
  function nearAreaAround(view, zoom, previous) {
114
- var keepsWhatItHas = previous !== null && zoom <= previous.zoom * ZOOM_IN_REFRESH_RATIO;
114
+ const keepsWhatItHas = previous !== null && zoom <= previous.zoom * ZOOM_IN_REFRESH_RATIO;
115
115
  return {
116
- view: view,
117
- zoom: zoom,
116
+ view,
117
+ zoom,
118
118
  area: viewWithMargin(view, NEAR_MARGIN_RATIO),
119
119
  keepArea: viewWithMargin(view, keepsWhatItHas ? KEEP_MARGIN_RATIO : NEAR_MARGIN_RATIO)
120
120
  };
@@ -123,8 +123,8 @@ function nearAreaAround(view, zoom, previous) {
123
123
  function isStillNear(near, view, zoom) {
124
124
  if (zoom > near.zoom * ZOOM_IN_REFRESH_RATIO)
125
125
  return false;
126
- var slackX = near.view.width * REFRESH_DISTANCE_RATIO;
127
- var slackY = near.view.height * REFRESH_DISTANCE_RATIO;
126
+ const slackX = near.view.width * REFRESH_DISTANCE_RATIO;
127
+ const slackY = near.view.height * REFRESH_DISTANCE_RATIO;
128
128
  return (view.x >= near.view.x - slackX &&
129
129
  view.y >= near.view.y - slackY &&
130
130
  view.x + view.width <= near.view.x + near.view.width + slackX &&
@@ -140,7 +140,7 @@ function sameRecords(first, second) {
140
140
  return true;
141
141
  if (first.length !== second.length)
142
142
  return false;
143
- for (var position = 0; position < first.length; position += 1) {
143
+ for (let position = 0; position < first.length; position += 1) {
144
144
  if (first[position] !== second[position])
145
145
  return false;
146
146
  }
@@ -150,7 +150,7 @@ function sameRecords(first, second) {
150
150
  function sameObjects(first, second) {
151
151
  if (first.length !== second.length)
152
152
  return false;
153
- for (var position = 0; position < first.length; position += 1) {
153
+ for (let position = 0; position < first.length; position += 1) {
154
154
  if (first[position].id !== second[position].id)
155
155
  return false;
156
156
  }
@@ -161,59 +161,57 @@ function sameObjects(first, second) {
161
161
  * view first in each of the two kinds.
162
162
  */
163
163
  function nearestIdsFirst(candidates, view, count) {
164
- var middleX = view.x + view.width / 2;
165
- var middleY = view.y + view.height / 2;
164
+ const middleX = view.x + view.width / 2;
165
+ const middleY = view.y + view.height / 2;
166
166
  // Squared distances stay far below this, so adding it puts every object that is out of the view after every one that is in it.
167
- var OUT_OF_VIEW = 1e18;
168
- var ranked = candidates.map(function (object) {
169
- var bounds = paintedBoundsOf(object);
170
- var offsetX = bounds.x + bounds.width / 2 - middleX;
171
- var offsetY = bounds.y + bounds.height / 2 - middleY;
167
+ const OUT_OF_VIEW = 1e18;
168
+ const ranked = candidates.map((object) => {
169
+ const bounds = paintedBoundsOf(object);
170
+ const offsetX = bounds.x + bounds.width / 2 - middleX;
171
+ const offsetY = bounds.y + bounds.height / 2 - middleY;
172
172
  return { id: object.id, rank: (rectsIntersect(view, bounds) ? 0 : OUT_OF_VIEW) + offsetX * offsetX + offsetY * offsetY };
173
173
  });
174
- ranked.sort(function (first, second) { return first.rank - second.rank; });
175
- return new Set(ranked.slice(0, count).map(function (entry) { return entry.id; }));
174
+ ranked.sort((first, second) => first.rank - second.rank);
175
+ return new Set(ranked.slice(0, count).map((entry) => entry.id));
176
176
  }
177
177
  /** The frame the page gives, or null where there is none (a server render). */
178
178
  function pageFrameScheduler() {
179
179
  if (typeof requestAnimationFrame !== 'function' || typeof cancelAnimationFrame !== 'function')
180
180
  return null;
181
- return function (callback) {
182
- var handle = requestAnimationFrame(function (frameTime) { return callback(frameTime); });
183
- return function () { return cancelAnimationFrame(handle); };
181
+ return (callback) => {
182
+ const handle = requestAnimationFrame((frameTime) => callback(frameTime));
183
+ return () => cancelAnimationFrame(handle);
184
184
  };
185
185
  }
186
- export function createMountedScene(options) {
187
- var _a, _b, _c;
188
- if (options === void 0) { options = {}; }
189
- var minimumObjects = (_a = options.minimumObjects) !== null && _a !== void 0 ? _a : CULLING_MINIMUM_OBJECTS;
190
- var scheduleFrame = (_b = options.scheduleFrame) !== null && _b !== void 0 ? _b : pageFrameScheduler();
186
+ export function createMountedScene(options = {}) {
187
+ const minimumObjects = options.minimumObjects ?? CULLING_MINIMUM_OBJECTS;
188
+ const scheduleFrame = options.scheduleFrame ?? pageFrameScheduler();
191
189
  // A batch size that was given stays; otherwise it follows the frames (see `adaptBatchSizeTo`).
192
- var batchSizeFollowsFrames = options.batchSize === undefined;
190
+ const batchSizeFollowsFrames = options.batchSize === undefined;
193
191
  // With no frame to wait for, there is no later to leave the rest of the objects to.
194
- var batchSize = scheduleFrame === null ? Infinity : Math.max(1, (_c = options.batchSize) !== null && _c !== void 0 ? _c : MOUNT_BATCH_SIZE);
192
+ let batchSize = scheduleFrame === null ? Infinity : Math.max(1, options.batchSize ?? MOUNT_BATCH_SIZE);
195
193
  // The time of the frame in which the last batch was made: the next frame says how long that batch took to show.
196
- var lastBatchFrameTime = null;
197
- var _d = writable(NOTHING_MOUNTED), subscribe = _d.subscribe, set = _d.set;
194
+ let lastBatchFrameTime = null;
195
+ const { subscribe, set } = writable(NOTHING_MOUNTED);
198
196
  /** The list the subscribers have. */
199
- var published = NOTHING_MOUNTED;
197
+ let published = NOTHING_MOUNTED;
200
198
  // The ids of the published list, made when someone asks and kept for as long as the list is of the same objects (see `publish`).
201
- var idsOfPublishedFor = null;
202
- var idsOfPublished = new Set();
203
- var near = null;
204
- var latestInput = null;
205
- var latestView = null;
199
+ let idsOfPublishedFor = null;
200
+ let idsOfPublished = new Set();
201
+ let near = null;
202
+ let latestInput = null;
203
+ let latestView = null;
206
204
  // What the last work was made from: the same again is no news.
207
- var workedScene = null;
208
- var workedEditingTextId = null;
209
- var workedNear = null;
210
- var cancelFrame = null;
211
- var destroyed = false;
205
+ let workedScene = null;
206
+ let workedEditingTextId = null;
207
+ let workedNear = null;
208
+ let cancelFrame = null;
209
+ let destroyed = false;
212
210
  // Once the work has failed, the board is drawn whole from then on (and the failure is said once).
213
- var failed = false;
211
+ let failed = false;
214
212
  function idsOfPublishedList() {
215
213
  if (idsOfPublishedFor !== published) {
216
- idsOfPublished = new Set(published.map(function (object) { return object.id; }));
214
+ idsOfPublished = new Set(published.map((object) => object.id));
217
215
  idsOfPublishedFor = published;
218
216
  }
219
217
  return idsOfPublished;
@@ -230,7 +228,7 @@ export function createMountedScene(options) {
230
228
  set(next);
231
229
  }
232
230
  function stopWaitingForFrame() {
233
- cancelFrame === null || cancelFrame === void 0 ? void 0 : cancelFrame();
231
+ cancelFrame?.();
234
232
  cancelFrame = null;
235
233
  }
236
234
  /**
@@ -245,11 +243,11 @@ export function createMountedScene(options) {
245
243
  lastBatchFrameTime = null;
246
244
  return;
247
245
  }
248
- var previous = lastBatchFrameTime;
246
+ const previous = lastBatchFrameTime;
249
247
  lastBatchFrameTime = frameTime;
250
248
  if (previous === null)
251
249
  return;
252
- var interval = frameTime - previous;
250
+ const interval = frameTime - previous;
253
251
  if (interval > PAUSED_FRAME_MS || interval < 0)
254
252
  return;
255
253
  if (interval > SLOW_FRAME_MS)
@@ -274,23 +272,22 @@ export function createMountedScene(options) {
274
272
  }
275
273
  /** Works out the list from the records and the near area, and makes what is wanted in the frames that follow when it is a lot. */
276
274
  function mountNearObjects(input, nearArea, view) {
277
- var scene = input.scene, editingTextId = input.editingTextId;
275
+ const { scene, editingTextId } = input;
278
276
  // The objects that have an element now: the ones that keep it while they are inside the keep area.
279
- var alreadyMade = idsOfPublishedList();
280
- var wanted = [];
277
+ const alreadyMade = idsOfPublishedList();
278
+ const wanted = [];
281
279
  // How many of the wanted ones have no element yet: counted on the way, so that a pass in which nothing is missing (the frames of
282
280
  // a drag) makes no list of them.
283
- var missingCount = 0;
284
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
285
- var object = scene_1[_i];
281
+ let missingCount = 0;
282
+ for (const object of scene) {
286
283
  // A group draws nothing: its members are objects of their own.
287
284
  if (!isBoxedObject(object))
288
285
  continue;
289
- var hasElementAlready = alreadyMade.has(object.id);
286
+ const hasElementAlready = alreadyMade.has(object.id);
290
287
  if (object.id !== editingTextId) {
291
- var painted = paintedBoundsOf(object);
288
+ const painted = paintedBoundsOf(object);
292
289
  // An object is given an element inside the near area, and keeps it (it is not made again later) inside the keep area.
293
- var keepsItsElement = hasElementAlready && rectsIntersect(nearArea.keepArea, painted);
290
+ const keepsItsElement = hasElementAlready && rectsIntersect(nearArea.keepArea, painted);
294
291
  if (!keepsItsElement && !rectsIntersect(nearArea.area, painted))
295
292
  continue;
296
293
  }
@@ -298,12 +295,12 @@ export function createMountedScene(options) {
298
295
  if (!hasElementAlready)
299
296
  missingCount += 1;
300
297
  }
301
- var next = wanted;
302
- var moreToMake = false;
298
+ let next = wanted;
299
+ let moreToMake = false;
303
300
  if (batchSize !== Infinity && missingCount > batchSize) {
304
- var missing = wanted.filter(function (object) { return !alreadyMade.has(object.id); });
305
- var makeNow_1 = nearestIdsFirst(missing, view, batchSize);
306
- next = wanted.filter(function (object) { return alreadyMade.has(object.id) || makeNow_1.has(object.id); });
301
+ const missing = wanted.filter((object) => !alreadyMade.has(object.id));
302
+ const makeNow = nearestIdsFirst(missing, view, batchSize);
303
+ next = wanted.filter((object) => alreadyMade.has(object.id) || makeNow.has(object.id));
307
304
  moreToMake = true;
308
305
  }
309
306
  workedScene = scene;
@@ -318,7 +315,7 @@ export function createMountedScene(options) {
318
315
  }
319
316
  if (cancelFrame !== null || scheduleFrame === null)
320
317
  return;
321
- cancelFrame = scheduleFrame(function (frameTime) {
318
+ cancelFrame = scheduleFrame((frameTime) => {
322
319
  cancelFrame = null;
323
320
  if (destroyed || latestInput === null || near === null || latestView === null)
324
321
  return;
@@ -332,8 +329,8 @@ export function createMountedScene(options) {
332
329
  });
333
330
  }
334
331
  return {
335
- subscribe: subscribe,
336
- take: function (input) {
332
+ subscribe,
333
+ take(input) {
337
334
  if (destroyed)
338
335
  return;
339
336
  latestInput = input;
@@ -342,7 +339,7 @@ export function createMountedScene(options) {
342
339
  publishWholeScene(input.scene);
343
340
  return;
344
341
  }
345
- var view = visibleWorldRect(input.viewport, input.viewSize);
342
+ const view = visibleWorldRect(input.viewport, input.viewSize);
346
343
  if (!isUsableView(view) || !Number.isFinite(input.viewport.zoom) || input.viewport.zoom <= 0) {
347
344
  publishWholeScene(input.scene);
348
345
  return;
@@ -358,7 +355,7 @@ export function createMountedScene(options) {
358
355
  giveUpCulling(error, input.scene);
359
356
  }
360
357
  },
361
- destroy: function () {
358
+ destroy() {
362
359
  destroyed = true;
363
360
  stopWaitingForFrame();
364
361
  }
@@ -6,7 +6,10 @@
6
6
  </script>
7
7
 
8
8
  <script lang="ts">
9
+ import { onDestroy } from 'svelte';
9
10
  import { provideCanvasLanguage, useCanvasLanguage } from '../i18n/language.js';
11
+ import { IconLoader2 } from '../canvas/ui/icons.js';
12
+ import { BOARD_LOADER_DELAY_MS, claimBoardLoader } from './boardLoaderDelay.js';
10
13
 
11
14
  /**
12
15
  * The empty board, drawn before the canvas itself is there.
@@ -14,12 +17,20 @@
14
17
  * A host shows it while the canvas code is still downloading, so the page
15
18
  * has its board at first paint. The real canvas replaces it with the same
16
19
  * surface, so the swap is not visible.
20
+ *
21
+ * Its loader is the design system's spinner, in the design system's muted colour, with no words beside it. It is not drawn at
22
+ * once: a board that opens within `BOARD_LOADER_DELAY_MS` (everything already in the browser) never shows one, and a slower
23
+ * board fades it in after that time, counted from the first placeholder of the opening, not from this one (see
24
+ * `boardLoaderDelay.ts`). A screen reader still hears the name of what is loading.
17
25
  */
18
26
  interface Props {
27
+ /** False draws only the board, with no loader. */
28
+ showLoader?: boolean;
29
+ /** @deprecated The placeholder shows no label any more: this is `showLoader` under its old name. */
19
30
  showLoadingLabel?: boolean;
20
- /** False draws only the loading label, over a board that is already painted. */
31
+ /** False draws only the loader, over a board that is already painted. */
21
32
  showSurface?: boolean;
22
- /** Same as Canvas: give these outside a canvas so the label speaks the page's language. */
33
+ /** Same as Canvas: give these outside a canvas so the name of the loader is in the page's language. */
23
34
  locale?: string | null;
24
35
  messages?: Readonly<Record<string, unknown>> | null;
25
36
  class?: string;
@@ -27,7 +38,8 @@
27
38
  }
28
39
 
29
40
  let {
30
- showLoadingLabel = true,
41
+ showLoader = undefined,
42
+ showLoadingLabel = undefined,
31
43
  showSurface = true,
32
44
  locale = undefined,
33
45
  messages = undefined,
@@ -35,6 +47,9 @@
35
47
  style = ''
36
48
  }: Props = $props();
37
49
 
50
+ /** Whether this placeholder has a loader at all. */
51
+ const hasLoader = $derived(showLoader ?? showLoadingLabel ?? true);
52
+
38
53
  // Inside a canvas the root already set the language; on its own, the page passes it.
39
54
  // svelte-ignore state_referenced_locally
40
55
  const ownsLanguage = locale !== undefined || messages !== undefined;
@@ -47,19 +62,62 @@
47
62
  $effect(() => {
48
63
  languageHandle?.update({ locale: locale ?? null, messages: messages ?? null });
49
64
  });
65
+
66
+ // This placeholder takes its place in the opening of the board when it is made, and gives it back when it goes away. On the page
67
+ // only: a server has no opening to count, and it draws the loader with the whole delay.
68
+ const claim = typeof window === 'undefined' ? null : claimBoardLoader();
69
+ onDestroy(() => claim?.release());
70
+
71
+ /** How long the loader waits before it is first seen: what is left of the delay of the opening this placeholder belongs to. */
72
+ const loaderDelayMs = claim?.delayMs ?? BOARD_LOADER_DELAY_MS;
50
73
  </script>
51
74
 
52
75
  <div
53
76
  class="canvas-board-placeholder relative h-full w-full overflow-hidden {className}"
54
77
  style="{showSurface ? `background-color: ${CANVAS_BOARD_BACKGROUND};` : ''} {style}"
55
- aria-busy={showLoadingLabel}
78
+ aria-busy={hasLoader}
56
79
  >
57
- {#if showLoadingLabel}
58
- <div class="canvas-board-placeholder-status absolute inset-0 flex items-center justify-center pointer-events-none">
59
- <div class="canvas-board-placeholder-status-inner flex items-center gap-2 text-sm font-medium text-gray-500">
60
- <span class="canvas-board-placeholder-spinner h-4 w-4 rounded-full border-2 border-gray-300 border-t-gray-600 animate-spin"></span>
61
- <span>{$t('canvas.state.loading')}</span>
62
- </div>
80
+ {#if hasLoader}
81
+ <div class="canvas-board-placeholder-status pointer-events-none absolute inset-0 flex items-center justify-center" role="status">
82
+ <!-- Fades in once the opening is older than the delay; at once (no fade) when the placeholder before this one was already seen -->
83
+ <span
84
+ class={['canvas-board-placeholder-spinner flex', { 'canvas-board-placeholder-spinner-seen': loaderDelayMs === 0 }]}
85
+ style="--canvas-board-loader-delay: {loaderDelayMs}ms;"
86
+ aria-hidden="true"
87
+ >
88
+ <IconLoader2 class="text-muted-foreground size-4 animate-spin stroke-2 motion-reduce:animate-none" />
89
+ </span>
90
+ <span class="sr-only">{$t('canvas.state.loading')}</span>
63
91
  </div>
64
92
  {/if}
65
93
  </div>
94
+
95
+ <style>
96
+ /* Hidden for the delay, then faded in: no timer to keep, and a placeholder that goes away first never shows it. */
97
+ .canvas-board-placeholder-spinner {
98
+ opacity: 0;
99
+ animation: canvas-board-placeholder-spinner-in var(--duration-base, 160ms) var(--ease-out, ease-out)
100
+ var(--canvas-board-loader-delay, 400ms) both;
101
+ }
102
+
103
+ /* The loader of the placeholder before this one was already on screen: carry on with no new fade, so it does not blink at the hand-over. */
104
+ .canvas-board-placeholder-spinner-seen {
105
+ opacity: 1;
106
+ animation: none;
107
+ }
108
+
109
+ @keyframes canvas-board-placeholder-spinner-in {
110
+ from {
111
+ opacity: 0;
112
+ }
113
+ to {
114
+ opacity: 1;
115
+ }
116
+ }
117
+
118
+ @media (prefers-reduced-motion: reduce) {
119
+ .canvas-board-placeholder-spinner {
120
+ animation-duration: 1ms;
121
+ }
122
+ }
123
+ </style>
@@ -6,12 +6,20 @@ export declare const CANVAS_BOARD_BACKGROUND = "var(--canvas-surface, var(--mute
6
6
  * A host shows it while the canvas code is still downloading, so the page
7
7
  * has its board at first paint. The real canvas replaces it with the same
8
8
  * surface, so the swap is not visible.
9
+ *
10
+ * Its loader is the design system's spinner, in the design system's muted colour, with no words beside it. It is not drawn at
11
+ * once: a board that opens within `BOARD_LOADER_DELAY_MS` (everything already in the browser) never shows one, and a slower
12
+ * board fades it in after that time, counted from the first placeholder of the opening, not from this one (see
13
+ * `boardLoaderDelay.ts`). A screen reader still hears the name of what is loading.
9
14
  */
10
15
  interface Props {
16
+ /** False draws only the board, with no loader. */
17
+ showLoader?: boolean;
18
+ /** @deprecated The placeholder shows no label any more: this is `showLoader` under its old name. */
11
19
  showLoadingLabel?: boolean;
12
- /** False draws only the loading label, over a board that is already painted. */
20
+ /** False draws only the loader, over a board that is already painted. */
13
21
  showSurface?: boolean;
14
- /** Same as Canvas: give these outside a canvas so the label speaks the page's language. */
22
+ /** Same as Canvas: give these outside a canvas so the name of the loader is in the page's language. */
15
23
  locale?: string | null;
16
24
  messages?: Readonly<Record<string, unknown>> | null;
17
25
  class?: string;
@@ -1,11 +1,13 @@
1
1
  <!--
2
2
  The drawing toolbar as it stands before the canvas is there.
3
3
 
4
- The toolbar is the same every time: the same tools, in the same order, in the same place, and the pencil is the tool that is on (a
5
- board that shows the drawing tools opens ready for a sketch: `CanvasHost.#start`). Nothing about it needs the saved board, so it
6
- does not have to wait for the canvas code (the biggest chunk of the page) to be downloaded: a host draws this look-alike next to its
7
- empty board, at first paint, and the real toolbar takes its place when the canvas mounts, in the same spot and at the same size, so
8
- the swap is not seen.
4
+ The toolbar is the same every time: the same tools, in the same order, in the same place, and the tool that is on is the one the
5
+ board opens with: the tool the person had last in this workspace, else the pencil (a board that shows the drawing tools opens ready
6
+ for a sketch). `CanvasHost.#start` and this file take it from the same rule (`settings/rememberedTool.ts`), from the same storage, so
7
+ a refresh does not show the pencil for a moment and then Select. Nothing else about it needs the saved board, so it does not have
8
+ to wait for the canvas code (the biggest chunk of the page) to be downloaded: a host draws this look-alike next to its empty board,
9
+ at first paint, and the real toolbar takes its place when the canvas mounts, in the same spot and at the same size, so the swap is
10
+ not seen.
9
11
 
10
12
  It is only a picture: no tooltips, no menu, no handlers, and it is hidden from the accessibility tree and the tab order (the real
11
13
  toolbar, which has them all, follows within a moment). It is drawn at the 60% of the chrome of a board that is still loading (the
@@ -22,6 +24,7 @@
22
24
  import { IconButton, Separator } from '@widgetic/design-system/components';
23
25
  import { chromeSlots, isSideAnchor } from '../canvas/chromeLayout.js';
24
26
  import { normalizeToolbarPosition } from '../canvas/toolbarPosition.js';
27
+ import { SHAPE_TOOL_IDS, firstToolOfBoard } from '../settings/rememberedTool.js';
25
28
  import { FLOATING_CARD_CLASSES, TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES, TOOLBAR_ICON_STROKE_CLASSES } from '../canvas/ui/floatingCard.js';
26
29
  import {
27
30
  IconArrowBackUp,
@@ -40,9 +43,15 @@
40
43
  toolbarPosition?: string | null;
41
44
  /** The same option the canvas has: false draws nothing, as the canvas draws no toolbar then. */
42
45
  showDrawingTools?: boolean;
46
+ /**
47
+ * The workspace and the person the canvas is given (its `workspaceId` and `userId`): where the tool that was last chosen is kept.
48
+ * Without a workspace nothing is kept, and the pencil is the tool that is on, as for a board where none was chosen yet.
49
+ */
50
+ workspaceId?: string | null;
51
+ userId?: string | null;
43
52
  }
44
53
 
45
- let { toolbarPosition = null, showDrawingTools = true }: Props = $props();
54
+ let { toolbarPosition = null, showDrawingTools = true, workspaceId = null, userId = null }: Props = $props();
46
55
 
47
56
  const anchor = $derived(normalizeToolbarPosition(toolbarPosition));
48
57
  const vertical = $derived(isSideAnchor(anchor));
@@ -51,12 +60,17 @@
51
60
 
52
61
  // The tools, in the order of the canvas's toolbar.
53
62
  const tools = [IconPointer, IconPencil, IconEraser, IconArrowUpRight, IconTypography];
54
- // The pencil is the tool in use when a board that shows the drawing tools opens (this card is not drawn at all without them).
63
+ // The tool in use when the board opens: the one the person had last in this workspace, else the pencil (this card is not drawn at all
64
+ // without the drawing tools). The canvas chooses it by the same rule; one of the shapes lights the Shapes button instead of a tool.
65
+ const openingTool = $derived(firstToolOfBoard({ workspaceId, userId, showDrawingTools }));
66
+ const toolIcons: Record<string, typeof IconPencil | undefined> = { select: IconPointer, draw: IconPencil, erase: IconEraser, arrow: IconArrowUpRight, text: IconTypography };
67
+ const activeToolIcon = $derived(toolIcons[openingTool] ?? null);
68
+ const shapeIsActive = $derived((SHAPE_TOOL_IDS as readonly string[]).includes(openingTool));
55
69
 
56
70
  // Written out in full, as `ToolButton.svelte` does, so that the stylesheet of a page that installs the canvas picks every class up.
57
71
  const TOOL_BUTTON_CLASSES = `size-9 data-[active]:bg-brand-subtle data-[active]:text-foreground ${TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} pointer-events-none`;
58
- // The Shapes menu's button, as `ShapesMenu.svelte` draws it.
59
- const SHAPES_BUTTON_CLASSES = 'flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground [&_svg]:size-4';
72
+ // The Shapes menu's button, as `ShapesMenu.svelte` draws it (the brand tint is for a shape being the tool: `data-active`, below).
73
+ const SHAPES_BUTTON_CLASSES = 'flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground data-[active]:bg-brand-subtle [&_svg]:size-4';
60
74
  </script>
61
75
 
62
76
  {#if slotClasses}
@@ -72,14 +86,14 @@
72
86
  class="canvas-toolbar-placeholder-card flex items-center gap-1 {vertical ? 'max-h-full flex-col overflow-y-auto' : 'max-w-full'} {FLOATING_CARD_CLASSES} {TOOLBAR_ICON_STROKE_CLASSES} [&_svg]:size-4"
73
87
  >
74
88
  {#each tools as Tool, position (position)}
75
- <IconButton label="" tabindex={-1} data-active={Tool === IconPencil ? '' : undefined} class={TOOL_BUTTON_CLASSES}>
89
+ <IconButton label="" tabindex={-1} data-active={Tool === activeToolIcon ? '' : undefined} class={TOOL_BUTTON_CLASSES}>
76
90
  <Tool />
77
91
  </IconButton>
78
92
  {/each}
79
93
 
80
94
  <Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
81
95
 
82
- <div class={SHAPES_BUTTON_CLASSES}>
96
+ <div class={SHAPES_BUTTON_CLASSES} data-active={shapeIsActive ? '' : undefined}>
83
97
  <IconCategory />
84
98
  <IconChevronDown />
85
99
  </div>
@@ -3,6 +3,12 @@ interface Props {
3
3
  toolbarPosition?: string | null;
4
4
  /** The same option the canvas has: false draws nothing, as the canvas draws no toolbar then. */
5
5
  showDrawingTools?: boolean;
6
+ /**
7
+ * The workspace and the person the canvas is given (its `workspaceId` and `userId`): where the tool that was last chosen is kept.
8
+ * Without a workspace nothing is kept, and the pencil is the tool that is on, as for a board where none was chosen yet.
9
+ */
10
+ workspaceId?: string | null;
11
+ userId?: string | null;
6
12
  }
7
13
  declare const CanvasToolbarPlaceholder: import("svelte").Component<Props, {}, "">;
8
14
  type CanvasToolbarPlaceholder = ReturnType<typeof CanvasToolbarPlaceholder>;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * When the loader of an empty board may first be seen.
3
+ *
4
+ * A board that opens fast (its code and its saved text are already in the browser) should show no loader at all: a spinner
5
+ * that flashes for a tenth of a second reads as a stutter, not as progress. So the loader of a placeholder waits for
6
+ * `BOARD_LOADER_DELAY_MS`, counted from the moment the opening began, and a board that is there before that never shows one.
7
+ *
8
+ * Opening a board draws up to three placeholders, one after the other: the page's own (while the creator downloads), the
9
+ * creator's (while the canvas code downloads) and the canvas's (while its saved text loads). If each counted from its own start,
10
+ * the loader would go away and come back again at every hand-over, and the wait would be three times as long. They share one
11
+ * count instead: the time since the first of them was drawn. The count is kept for `BOARD_LOADER_HANDOVER_MS` after the last one
12
+ * is gone, so that the next one, drawn in the same moment, continues it; after that the next placeholder starts a new opening.
13
+ *
14
+ * The count lives on `globalThis` under a registered symbol, not in this module: the page's placeholder and the creator's can come
15
+ * from two copies of this file (one for each bundle that has it), and two copies would each start their own count.
16
+ */
17
+ /** How long an opening may take before its loader is first seen, in milliseconds. */
18
+ export declare const BOARD_LOADER_DELAY_MS = 400;
19
+ /** How long after its last placeholder is gone an opening is still the same one, in milliseconds. */
20
+ export declare const BOARD_LOADER_HANDOVER_MS = 300;
21
+ /** One placeholder's place in the opening. */
22
+ export interface BoardLoaderClaim {
23
+ /** How long this placeholder waits before its loader is first seen: what is left of `BOARD_LOADER_DELAY_MS`, never below 0. */
24
+ delayMs: number;
25
+ /** The placeholder is gone. Can be called more than once. */
26
+ release: () => void;
27
+ }
28
+ /**
29
+ * A placeholder asks when its loader may be seen, and tells when it is gone. `now` is the clock; tests pass their own.
30
+ *
31
+ * ```ts
32
+ * const claim = claimBoardLoader();
33
+ * // show the loader after claim.delayMs
34
+ * claim.release(); // when the placeholder goes away
35
+ * ```
36
+ */
37
+ export declare function claimBoardLoader(now?: () => number): BoardLoaderClaim;
38
+ /** Forgets the opening of this page. For tests: a page never needs it. */
39
+ export declare function resetBoardLoaderOpening(): void;