@widgetic/canvas 0.5.43 → 0.5.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/canvas/DomCanvas.svelte +56 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -28
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +87 -2
  10. package/dist/canvas/host/CanvasHost.js +1948 -1394
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +32 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +2 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/types.d.ts +17 -0
  35. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  36. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  37. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  38. package/dist/canvas/ui/ColorField.svelte +7 -2
  39. package/dist/canvas/ui/SelectionPanel.svelte +105 -42
  40. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  41. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  42. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  43. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  44. package/dist/canvas/ui/ToolButton.svelte +35 -54
  45. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  46. package/dist/canvas/ui/colorModel.js +32 -21
  47. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  48. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  49. package/dist/canvas/ui/floatingCard.js +43 -21
  50. package/dist/canvas/ui/floatingLayer.js +6 -5
  51. package/dist/canvas/ui/icons.d.ts +1 -1
  52. package/dist/canvas/ui/icons.js +1 -1
  53. package/dist/canvas/ui/keyHints.js +11 -9
  54. package/dist/canvas/ui/popoverSide.js +3 -2
  55. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  56. package/dist/canvas/ui/selectionTraits.js +66 -35
  57. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  58. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  59. package/dist/canvas/view/CanvasStage.svelte +7 -2
  60. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  61. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  62. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  63. package/dist/canvas/view/erasingMarks.js +7 -7
  64. package/dist/canvas/view/geometry.d.ts +1 -1
  65. package/dist/canvas/view/geometry.js +90 -71
  66. package/dist/canvas/view/liftedScene.js +36 -24
  67. package/dist/canvas/view/mountedScene.js +79 -76
  68. package/dist/components/CanvasBoardPoster.svelte +206 -0
  69. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  70. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  71. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  72. package/dist/components/index.d.ts +7 -0
  73. package/dist/components/index.js +8 -0
  74. package/dist/components/preferenceStorage.js +2 -2
  75. package/dist/engine/EngineCore.d.ts +111 -2
  76. package/dist/engine/EngineCore.js +1013 -707
  77. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  78. package/dist/engine/codec/canvasDocument.js +172 -186
  79. package/dist/engine/codec/hostReadableKeys.js +1 -1
  80. package/dist/engine/core/arrange.js +38 -26
  81. package/dist/engine/core/arrow.d.ts +18 -8
  82. package/dist/engine/core/arrow.js +109 -84
  83. package/dist/engine/core/arrowBinding.d.ts +1 -1
  84. package/dist/engine/core/arrowBinding.js +126 -101
  85. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  86. package/dist/engine/core/arrowBindingRecords.js +48 -29
  87. package/dist/engine/core/brush.d.ts +8 -0
  88. package/dist/engine/core/brush.js +98 -78
  89. package/dist/engine/core/cameraMove.d.ts +73 -0
  90. package/dist/engine/core/cameraMove.js +172 -0
  91. package/dist/engine/core/defaults.js +51 -90
  92. package/dist/engine/core/freehand.js +163 -147
  93. package/dist/engine/core/geometry.js +54 -47
  94. package/dist/engine/core/history.js +55 -38
  95. package/dist/engine/core/hitTest.js +81 -68
  96. package/dist/engine/core/matrix.js +20 -18
  97. package/dist/engine/core/pathData.js +210 -183
  98. package/dist/engine/core/rotationReset.js +6 -5
  99. package/dist/engine/core/scene.d.ts +22 -0
  100. package/dist/engine/core/scene.js +288 -139
  101. package/dist/engine/core/scribble.js +84 -59
  102. package/dist/engine/core/shapePaths.js +15 -12
  103. package/dist/engine/core/shapeTools.js +63 -72
  104. package/dist/engine/core/snapping.js +117 -65
  105. package/dist/engine/core/style.d.ts +10 -0
  106. package/dist/engine/core/style.js +82 -33
  107. package/dist/engine/core/transform.d.ts +6 -0
  108. package/dist/engine/core/transform.js +103 -83
  109. package/dist/engine/core/types.d.ts +7 -0
  110. package/dist/engine/core/types.js +4 -4
  111. package/dist/engine/core/viewport.js +36 -23
  112. package/dist/engine/input/PointerController.d.ts +15 -1
  113. package/dist/engine/input/PointerController.js +549 -466
  114. package/dist/engine/input/arrowHandles.js +12 -12
  115. package/dist/engine/input/gestures.d.ts +3 -1
  116. package/dist/engine/input/gestures.js +340 -266
  117. package/dist/engine/input/hoverCursor.js +1 -1
  118. package/dist/engine/input/keyboard.d.ts +22 -3
  119. package/dist/engine/input/keyboard.js +131 -32
  120. package/dist/engine/input/selectionHandles.js +50 -45
  121. package/dist/engine/input/types.d.ts +7 -0
  122. package/dist/engine/input/types.js +1 -1
  123. package/dist/engine/render/rasterize.js +158 -86
  124. package/dist/engine/state.d.ts +18 -0
  125. package/dist/engine/state.js +25 -4
  126. package/dist/engine/text/layoutText.js +62 -43
  127. package/dist/engine/text/textMetrics.js +10 -8
  128. package/dist/engine/widgets.js +137 -101
  129. package/dist/fonts/interFont.js +83 -30
  130. package/dist/fonts/workspaceFonts.d.ts +6 -0
  131. package/dist/fonts/workspaceFonts.js +108 -34
  132. package/dist/i18n/labels.js +4 -4
  133. package/dist/i18n/language.d.ts +3 -3
  134. package/dist/i18n/language.js +4 -4
  135. package/dist/i18n/messages.d.ts +6 -0
  136. package/dist/i18n/messages.js +7 -1
  137. package/dist/i18n/shortcuts.d.ts +6 -4
  138. package/dist/i18n/shortcuts.js +30 -26
  139. package/dist/index.d.ts +2 -1
  140. package/dist/poster/boardPlacement.d.ts +80 -0
  141. package/dist/poster/boardPlacement.js +140 -0
  142. package/dist/poster/boardPoster.d.ts +80 -0
  143. package/dist/poster/boardPoster.js +251 -0
  144. package/dist/poster/paintBoardPoster.d.ts +49 -0
  145. package/dist/poster/paintBoardPoster.js +112 -0
  146. package/dist/poster/posterPictures.d.ts +32 -0
  147. package/dist/poster/posterPictures.js +138 -0
  148. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  149. package/dist/settings/workspaceToolSettings.js +58 -34
  150. package/dist/tools/components/catalog.js +74 -64
  151. package/dist/tools/components/grouping.js +28 -6
  152. package/dist/tools/definitions.js +31 -9
  153. package/dist/tools/executors.js +214 -106
  154. package/dist/tools/hostAdapter.d.ts +5 -1
  155. package/dist/tools/hostAdapter.js +15 -11
  156. package/dist/tools/sceneSummary.js +57 -43
  157. package/dist/tools/sketchIntent.js +21 -13
  158. package/dist/tools/styleArguments.d.ts +35 -0
  159. package/dist/tools/styleArguments.js +93 -0
  160. package/dist/tools/types.d.ts +26 -1
  161. package/dist/tools/types.js +2 -1
  162. package/package.json +1 -1
@@ -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 const CULLING_MINIMUM_OBJECTS = 150;
46
+ export var 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 const NEAR_MARGIN_RATIO = 0.5;
48
+ export var 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 const 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 const KEEP_MARGIN_RATIO = 1;
56
+ export var 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 const REFRESH_DISTANCE_RATIO = 0.15;
61
+ export var 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 const ZOOM_IN_REFRESH_RATIO = 1.5;
63
+ export var 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 const MOUNT_BATCH_SIZE = 30;
65
+ export var 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 const MIN_MOUNT_BATCH_SIZE = 16;
67
+ export var 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 const MAX_MOUNT_BATCH_SIZE = 120;
69
+ export var MAX_MOUNT_BATCH_SIZE = 120;
70
70
  /** What the batch grows by after a frame that came on time. */
71
- export const MOUNT_BATCH_GROWTH = 8;
71
+ export var 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 const SLOW_FRAME_MS = 24;
73
+ export var 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 const QUICK_FRAME_MS = 20;
75
+ export var 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 const PAUSED_FRAME_MS = 500;
77
+ export var 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 const NOTHING_MOUNTED = Object.freeze([]);
79
+ export var 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 const 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
- const measured = shapeVisualBounds(shape);
88
+ var 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
- const marginX = view.width * ratio;
102
- const marginY = view.height * ratio;
101
+ var marginX = view.width * ratio;
102
+ var 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
- const keepsWhatItHas = previous !== null && zoom <= previous.zoom * ZOOM_IN_REFRESH_RATIO;
114
+ var keepsWhatItHas = previous !== null && zoom <= previous.zoom * ZOOM_IN_REFRESH_RATIO;
115
115
  return {
116
- view,
117
- zoom,
116
+ view: view,
117
+ zoom: 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
- const slackX = near.view.width * REFRESH_DISTANCE_RATIO;
127
- const slackY = near.view.height * REFRESH_DISTANCE_RATIO;
126
+ var slackX = near.view.width * REFRESH_DISTANCE_RATIO;
127
+ var 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 (let position = 0; position < first.length; position += 1) {
143
+ for (var 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 (let position = 0; position < first.length; position += 1) {
153
+ for (var position = 0; position < first.length; position += 1) {
154
154
  if (first[position].id !== second[position].id)
155
155
  return false;
156
156
  }
@@ -161,57 +161,59 @@ function sameObjects(first, second) {
161
161
  * view first in each of the two kinds.
162
162
  */
163
163
  function nearestIdsFirst(candidates, view, count) {
164
- const middleX = view.x + view.width / 2;
165
- const middleY = view.y + view.height / 2;
164
+ var middleX = view.x + view.width / 2;
165
+ var 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
- 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;
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;
172
172
  return { id: object.id, rank: (rectsIntersect(view, bounds) ? 0 : OUT_OF_VIEW) + offsetX * offsetX + offsetY * offsetY };
173
173
  });
174
- ranked.sort((first, second) => first.rank - second.rank);
175
- return new Set(ranked.slice(0, count).map((entry) => entry.id));
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; }));
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 (callback) => {
182
- const handle = requestAnimationFrame((frameTime) => callback(frameTime));
183
- return () => cancelAnimationFrame(handle);
181
+ return function (callback) {
182
+ var handle = requestAnimationFrame(function (frameTime) { return callback(frameTime); });
183
+ return function () { return cancelAnimationFrame(handle); };
184
184
  };
185
185
  }
186
- export function createMountedScene(options = {}) {
187
- const minimumObjects = options.minimumObjects ?? CULLING_MINIMUM_OBJECTS;
188
- const scheduleFrame = options.scheduleFrame ?? pageFrameScheduler();
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();
189
191
  // A batch size that was given stays; otherwise it follows the frames (see `adaptBatchSizeTo`).
190
- const batchSizeFollowsFrames = options.batchSize === undefined;
192
+ var batchSizeFollowsFrames = options.batchSize === undefined;
191
193
  // With no frame to wait for, there is no later to leave the rest of the objects to.
192
- let batchSize = scheduleFrame === null ? Infinity : Math.max(1, options.batchSize ?? MOUNT_BATCH_SIZE);
194
+ var batchSize = scheduleFrame === null ? Infinity : Math.max(1, (_c = options.batchSize) !== null && _c !== void 0 ? _c : MOUNT_BATCH_SIZE);
193
195
  // The time of the frame in which the last batch was made: the next frame says how long that batch took to show.
194
- let lastBatchFrameTime = null;
195
- const { subscribe, set } = writable(NOTHING_MOUNTED);
196
+ var lastBatchFrameTime = null;
197
+ var _d = writable(NOTHING_MOUNTED), subscribe = _d.subscribe, set = _d.set;
196
198
  /** The list the subscribers have. */
197
- let published = NOTHING_MOUNTED;
199
+ var published = NOTHING_MOUNTED;
198
200
  // 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`).
199
- let idsOfPublishedFor = null;
200
- let idsOfPublished = new Set();
201
- let near = null;
202
- let latestInput = null;
203
- let latestView = null;
201
+ var idsOfPublishedFor = null;
202
+ var idsOfPublished = new Set();
203
+ var near = null;
204
+ var latestInput = null;
205
+ var latestView = null;
204
206
  // What the last work was made from: the same again is no news.
205
- let workedScene = null;
206
- let workedEditingTextId = null;
207
- let workedNear = null;
208
- let cancelFrame = null;
209
- let destroyed = false;
207
+ var workedScene = null;
208
+ var workedEditingTextId = null;
209
+ var workedNear = null;
210
+ var cancelFrame = null;
211
+ var destroyed = false;
210
212
  // Once the work has failed, the board is drawn whole from then on (and the failure is said once).
211
- let failed = false;
213
+ var failed = false;
212
214
  function idsOfPublishedList() {
213
215
  if (idsOfPublishedFor !== published) {
214
- idsOfPublished = new Set(published.map((object) => object.id));
216
+ idsOfPublished = new Set(published.map(function (object) { return object.id; }));
215
217
  idsOfPublishedFor = published;
216
218
  }
217
219
  return idsOfPublished;
@@ -228,7 +230,7 @@ export function createMountedScene(options = {}) {
228
230
  set(next);
229
231
  }
230
232
  function stopWaitingForFrame() {
231
- cancelFrame?.();
233
+ cancelFrame === null || cancelFrame === void 0 ? void 0 : cancelFrame();
232
234
  cancelFrame = null;
233
235
  }
234
236
  /**
@@ -243,11 +245,11 @@ export function createMountedScene(options = {}) {
243
245
  lastBatchFrameTime = null;
244
246
  return;
245
247
  }
246
- const previous = lastBatchFrameTime;
248
+ var previous = lastBatchFrameTime;
247
249
  lastBatchFrameTime = frameTime;
248
250
  if (previous === null)
249
251
  return;
250
- const interval = frameTime - previous;
252
+ var interval = frameTime - previous;
251
253
  if (interval > PAUSED_FRAME_MS || interval < 0)
252
254
  return;
253
255
  if (interval > SLOW_FRAME_MS)
@@ -272,22 +274,23 @@ export function createMountedScene(options = {}) {
272
274
  }
273
275
  /** 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. */
274
276
  function mountNearObjects(input, nearArea, view) {
275
- const { scene, editingTextId } = input;
277
+ var scene = input.scene, editingTextId = input.editingTextId;
276
278
  // The objects that have an element now: the ones that keep it while they are inside the keep area.
277
- const alreadyMade = idsOfPublishedList();
278
- const wanted = [];
279
+ var alreadyMade = idsOfPublishedList();
280
+ var wanted = [];
279
281
  // 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
280
282
  // a drag) makes no list of them.
281
- let missingCount = 0;
282
- for (const object of scene) {
283
+ var missingCount = 0;
284
+ for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
285
+ var object = scene_1[_i];
283
286
  // A group draws nothing: its members are objects of their own.
284
287
  if (!isBoxedObject(object))
285
288
  continue;
286
- const hasElementAlready = alreadyMade.has(object.id);
289
+ var hasElementAlready = alreadyMade.has(object.id);
287
290
  if (object.id !== editingTextId) {
288
- const painted = paintedBoundsOf(object);
291
+ var painted = paintedBoundsOf(object);
289
292
  // An object is given an element inside the near area, and keeps it (it is not made again later) inside the keep area.
290
- const keepsItsElement = hasElementAlready && rectsIntersect(nearArea.keepArea, painted);
293
+ var keepsItsElement = hasElementAlready && rectsIntersect(nearArea.keepArea, painted);
291
294
  if (!keepsItsElement && !rectsIntersect(nearArea.area, painted))
292
295
  continue;
293
296
  }
@@ -295,12 +298,12 @@ export function createMountedScene(options = {}) {
295
298
  if (!hasElementAlready)
296
299
  missingCount += 1;
297
300
  }
298
- let next = wanted;
299
- let moreToMake = false;
301
+ var next = wanted;
302
+ var moreToMake = false;
300
303
  if (batchSize !== Infinity && missingCount > batchSize) {
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));
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); });
304
307
  moreToMake = true;
305
308
  }
306
309
  workedScene = scene;
@@ -315,7 +318,7 @@ export function createMountedScene(options = {}) {
315
318
  }
316
319
  if (cancelFrame !== null || scheduleFrame === null)
317
320
  return;
318
- cancelFrame = scheduleFrame((frameTime) => {
321
+ cancelFrame = scheduleFrame(function (frameTime) {
319
322
  cancelFrame = null;
320
323
  if (destroyed || latestInput === null || near === null || latestView === null)
321
324
  return;
@@ -329,8 +332,8 @@ export function createMountedScene(options = {}) {
329
332
  });
330
333
  }
331
334
  return {
332
- subscribe,
333
- take(input) {
335
+ subscribe: subscribe,
336
+ take: function (input) {
334
337
  if (destroyed)
335
338
  return;
336
339
  latestInput = input;
@@ -339,7 +342,7 @@ export function createMountedScene(options = {}) {
339
342
  publishWholeScene(input.scene);
340
343
  return;
341
344
  }
342
- const view = visibleWorldRect(input.viewport, input.viewSize);
345
+ var view = visibleWorldRect(input.viewport, input.viewSize);
343
346
  if (!isUsableView(view) || !Number.isFinite(input.viewport.zoom) || input.viewport.zoom <= 0) {
344
347
  publishWholeScene(input.scene);
345
348
  return;
@@ -355,7 +358,7 @@ export function createMountedScene(options = {}) {
355
358
  giveUpCulling(error, input.scene);
356
359
  }
357
360
  },
358
- destroy() {
361
+ destroy: function () {
359
362
  destroyed = true;
360
363
  stopWaitingForFrame();
361
364
  }
@@ -0,0 +1,206 @@
1
+ <!--
2
+ The poster of the board: the objects that were in the saved view, drawn from the first frame, before the canvas engine has them.
3
+
4
+ A refresh used to show the empty board first and the objects a moment later: the saved board is kept next to the page, but
5
+ nothing can draw it until the canvas code has been downloaded, mounted and has read it. The page keeps a small copy of the part
6
+ of the board that was on the screen (`createBoardPoster`) and this draws it, with the engine's own painter (`paintShape`), at the
7
+ view the board was saved with. It is a picture, no more: it takes no pointer, it is hidden from the accessibility tree and the
8
+ tab order, and it draws no selection and no live widget (a card is drawn with its screenshot).
9
+
10
+ A picture whose bytes are in the host's image store (a photo dropped on the board, the screenshot of a widget card) has only a
11
+ reference in the saved text. The host gives `resolvePicture`, which answers a reference with the bytes (or an address) from its
12
+ store; the poster asks for each once, draws the card without the picture until it arrives, and draws it again when it does.
13
+
14
+ It is shown while `hold` is true, which is while the board is loading its own objects (the canvas passes its loading flag), and
15
+ it lets go two frames after that ends, with a short fade, so the hand-over is not seen: the board has painted the same objects
16
+ by then, in the same place. A poster that is given after the board has painted is never shown.
17
+
18
+ It fills the positioned element it is in. Inside the canvas it sits between the board and the chrome (the toolbar stays above it);
19
+ in a host's placeholder it fills the board that stands in for the canvas. The host decides where it is and how high; this file
20
+ only draws.
21
+
22
+ It says when it is on the screen (`bind:visible`). The canvas uses that to draw no spinner over the objects: they are there to look
23
+ at, the placeholders before the canvas drew none, and a spinner that came back for the moment the board reads its saved text would
24
+ blink at the hand-over.
25
+ -->
26
+ <script lang="ts">
27
+ import { onMount, untrack } from 'svelte';
28
+ import { createFixedAdvanceMeasure } from '../engine/text/layoutText.js';
29
+ import type { MeasureText } from '../engine/text/layoutText.js';
30
+ import { parseBoardPoster } from '../poster/boardPoster.js';
31
+ import type { BoardPoster } from '../poster/boardPoster.js';
32
+ import {
33
+ paintBoardPoster,
34
+ posterPaintDependencies,
35
+ posterPictureReferences,
36
+ posterPictureSources,
37
+ withReferencedPictures
38
+ } from '../poster/paintBoardPoster.js';
39
+ import {
40
+ posterPictureFor,
41
+ requestPosterPictures,
42
+ requestReferencedPictures,
43
+ subscribeToPosterPictures
44
+ } from '../poster/posterPictures.js';
45
+ import type { PosterPictureResolver } from '../poster/posterPictures.js';
46
+
47
+ interface Props {
48
+ /** What the page kept of the board (`createBoardPoster`). Nothing is drawn without it. */
49
+ poster?: BoardPoster | null;
50
+ /** True while the real board has not painted its objects yet. When it turns false the poster waits two frames and fades away. */
51
+ hold?: boolean;
52
+ /** The host's image store: answers the reference of a picture the board keeps there with its bytes (a data URL) or an address. */
53
+ resolvePicture?: PosterPictureResolver | null;
54
+ /** Said by the poster, for the host to bind: true while the poster is on the screen (drawn, and not yet gone), false before and after. */
55
+ visible?: boolean;
56
+ /** Where the poster is and how high (the host's own classes). */
57
+ class?: string;
58
+ }
59
+
60
+ let { poster = null, hold = true, resolvePicture = null, visible = $bindable(false), class: className = '' }: Props = $props();
61
+
62
+ /** How long the poster takes to fade out, in milliseconds (the class below says the same, in CSS). */
63
+ const FADE_OUT_MS = 150;
64
+ /** The densest screen the poster draws for: a canvas of more pixels costs memory and shows nothing a person can tell. */
65
+ const MAX_PIXEL_RATIO = 2;
66
+
67
+ // The poster as it is drawn: read through the canvas's own reader, so a damaged or foreign one draws nothing.
68
+ const parsedPoster = $derived(poster ? parseBoardPoster(poster) : null);
69
+ // The same poster with each picture kept in the host's store named by its key, which the painter asks the loaded pictures for.
70
+ const drawablePoster = $derived(parsedPoster ? withReferencedPictures(parsedPoster) : null);
71
+
72
+ // showing → fading → gone. A poster given after the board painted starts gone: the board is already there.
73
+ let phase = $state<'showing' | 'fading' | 'gone'>(untrack(() => (hold ? 'showing' : 'gone')));
74
+
75
+ let canvasElement = $state<HTMLCanvasElement | null>(null);
76
+ // The size of the area the poster stands in (bound to the wrapper below: measured at mount, so the first draw is in the first
77
+ // frame, and again at every resize).
78
+ let areaWidth = $state(0);
79
+ let areaHeight = $state(0);
80
+ // Bumped when a picture has arrived or a font has loaded, so the poster is drawn again with it.
81
+ let picturesRevision = $state(0);
82
+ let fontsRevision = $state(0);
83
+ let paintFailureLogged = false;
84
+
85
+ /** A text measurer made of the browser's canvas; a fixed advance where there is none. */
86
+ function createMeasureText(): MeasureText {
87
+ let context: CanvasRenderingContext2D | null | undefined;
88
+ const fallback = createFixedAdvanceMeasure();
89
+ return (text, font) => {
90
+ if (context === undefined) {
91
+ try {
92
+ context = document.createElement('canvas').getContext('2d');
93
+ } catch {
94
+ context = null;
95
+ }
96
+ }
97
+ if (!context) return fallback(text, font);
98
+ if (context.font !== font) context.font = font;
99
+ return context.measureText(text).width;
100
+ };
101
+ }
102
+ const measureText = createMeasureText();
103
+
104
+ // A picture that arrives, or a font that finishes loading, draws the poster again: neither is there in the first frame.
105
+ onMount(() => {
106
+ const stopListeningToPictures = subscribeToPosterPictures(() => {
107
+ picturesRevision += 1;
108
+ });
109
+ const fonts = typeof document === 'undefined' ? undefined : document.fonts;
110
+ const onFontsLoaded = () => {
111
+ fontsRevision += 1;
112
+ };
113
+ fonts?.addEventListener?.('loadingdone', onFontsLoaded);
114
+ return () => {
115
+ stopListeningToPictures();
116
+ fonts?.removeEventListener?.('loadingdone', onFontsLoaded);
117
+ // A poster that is taken away while it is up leaves nothing on the screen: the host is told
118
+ visible = false;
119
+ };
120
+ });
121
+
122
+ // Whether the poster is on the screen, told to the host: while it is showing, and while it fades.
123
+ $effect(() => {
124
+ visible = parsedPoster !== null && phase !== 'gone';
125
+ });
126
+
127
+ // Drawing. Setting a canvas's width clears it, so the size is only set when it changed; the picture is painted every time.
128
+ $effect(() => {
129
+ const element = canvasElement;
130
+ const shapes = drawablePoster;
131
+ const asRead = parsedPoster;
132
+ const resolve = resolvePicture;
133
+ const width = areaWidth;
134
+ const height = areaHeight;
135
+ void picturesRevision;
136
+ void fontsRevision;
137
+ if (!element || !shapes || !asRead || width <= 0 || height <= 0) return;
138
+ if (untrack(() => phase) === 'gone') return;
139
+ try {
140
+ const pixelRatio = Math.min(MAX_PIXEL_RATIO, window.devicePixelRatio || 1);
141
+ const pixelWidth = Math.round(width * pixelRatio);
142
+ const pixelHeight = Math.round(height * pixelRatio);
143
+ if (element.width !== pixelWidth) element.width = pixelWidth;
144
+ if (element.height !== pixelHeight) element.height = pixelHeight;
145
+ const context = element.getContext('2d');
146
+ if (!context) return;
147
+ paintBoardPoster(
148
+ context,
149
+ shapes,
150
+ { width, height, pixelRatio },
151
+ posterPaintDependencies({ pictureFor: posterPictureFor, createPath: (data) => new Path2D(data), measureText })
152
+ );
153
+ // Pictures with an address of their own: asked for after the shapes are drawn, and drawn again when they arrive.
154
+ // (Asked from the poster as it was read: the one the painter has names the stored pictures by keys, which are no addresses.)
155
+ requestPosterPictures(posterPictureSources(asRead));
156
+ // Pictures the board keeps in the host's store: the host is asked for each reference once.
157
+ if (resolve) requestReferencedPictures(posterPictureReferences(asRead), resolve);
158
+ } catch (error) {
159
+ // Once per poster: the board draws its own objects whatever happens here.
160
+ if (!paintFailureLogged) {
161
+ paintFailureLogged = true;
162
+ console.warn('[CanvasBoardPoster] The poster could not be drawn; the board will draw its own objects', error);
163
+ }
164
+ }
165
+ });
166
+
167
+ // The hand-over. While the board is loading the poster stays; two frames after it stops, the browser has shown the board's own
168
+ // objects, and the poster fades and goes. A board that starts loading again takes the poster back while it fades.
169
+ $effect(() => {
170
+ if (hold) {
171
+ untrack(() => {
172
+ if (phase === 'fading') phase = 'showing';
173
+ });
174
+ return;
175
+ }
176
+ if (untrack(() => phase) !== 'showing') return;
177
+ let secondFrame = 0;
178
+ let removal: ReturnType<typeof setTimeout> | undefined;
179
+ const firstFrame = requestAnimationFrame(() => {
180
+ secondFrame = requestAnimationFrame(() => {
181
+ phase = 'fading';
182
+ removal = setTimeout(() => {
183
+ phase = 'gone';
184
+ }, FADE_OUT_MS + 60);
185
+ });
186
+ });
187
+ return () => {
188
+ cancelAnimationFrame(firstFrame);
189
+ cancelAnimationFrame(secondFrame);
190
+ if (removal !== undefined) clearTimeout(removal);
191
+ };
192
+ });
193
+ </script>
194
+
195
+ {#if parsedPoster && phase !== 'gone'}
196
+ <div
197
+ bind:clientWidth={areaWidth}
198
+ bind:clientHeight={areaHeight}
199
+ class="canvas-board-poster pointer-events-none absolute inset-0 overflow-hidden transition-opacity duration-150 motion-reduce:transition-none {phase === 'fading' ? 'opacity-0' : 'opacity-100'} {className}"
200
+ data-canvas-board-poster
201
+ aria-hidden="true"
202
+ inert
203
+ >
204
+ <canvas bind:this={canvasElement} class="block h-full w-full"></canvas>
205
+ </div>
206
+ {/if}
@@ -0,0 +1,17 @@
1
+ import type { BoardPoster } from '../poster/boardPoster.js';
2
+ import type { PosterPictureResolver } from '../poster/posterPictures.js';
3
+ interface Props {
4
+ /** What the page kept of the board (`createBoardPoster`). Nothing is drawn without it. */
5
+ poster?: BoardPoster | null;
6
+ /** True while the real board has not painted its objects yet. When it turns false the poster waits two frames and fades away. */
7
+ hold?: boolean;
8
+ /** The host's image store: answers the reference of a picture the board keeps there with its bytes (a data URL) or an address. */
9
+ resolvePicture?: PosterPictureResolver | null;
10
+ /** Said by the poster, for the host to bind: true while the poster is on the screen (drawn, and not yet gone), false before and after. */
11
+ visible?: boolean;
12
+ /** Where the poster is and how high (the host's own classes). */
13
+ class?: string;
14
+ }
15
+ declare const CanvasBoardPoster: import("svelte").Component<Props, {}, "visible">;
16
+ type CanvasBoardPoster = ReturnType<typeof CanvasBoardPoster>;
17
+ export default CanvasBoardPoster;
@@ -0,0 +1,115 @@
1
+ <!--
2
+ The drawing toolbar as it stands before the canvas is there.
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.
9
+
10
+ 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
+ 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
12
+ canvas dims its toolbar the same way while its data comes in), so it does not brighten at the hand-over and dim again.
13
+
14
+ It is made of the same parts as the real one (`floatingCard.ts`, `chromeLayout.ts`, the same icons and the design system's Icon
15
+ Button) and `tests/ui/toolbarPlaceholder.test.mjs` holds the two together: the tools, their order, the sizes and the
16
+ place. When the toolbar changes, change this file with it (the test says what drifted).
17
+
18
+ The placement classes come from `chromeLayout.ts`, so the toolbar is where `toolbarPosition` says. It fills the board it is in: put it in
19
+ a positioned element that has the size of the board.
20
+ -->
21
+ <script lang="ts">
22
+ import { IconButton, Separator } from '@widgetic/design-system/components';
23
+ import { chromeSlots, isSideAnchor } from '../canvas/chromeLayout.js';
24
+ import { normalizeToolbarPosition } from '../canvas/toolbarPosition.js';
25
+ import { FLOATING_CARD_CLASSES, TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES, TOOLBAR_ICON_STROKE_CLASSES } from '../canvas/ui/floatingCard.js';
26
+ import {
27
+ IconArrowBackUp,
28
+ IconArrowForwardUp,
29
+ IconArrowUpRight,
30
+ IconCategory,
31
+ IconChevronDown,
32
+ IconEraser,
33
+ IconPencil,
34
+ IconPointer,
35
+ IconTypography
36
+ } from '../canvas/ui/icons.js';
37
+
38
+ interface Props {
39
+ /** Where the toolbar stands: one of the eight places of `toolbarPosition` (anything else is the bottom centre, as in the canvas). */
40
+ toolbarPosition?: string | null;
41
+ /** The same option the canvas has: false draws nothing, as the canvas draws no toolbar then. */
42
+ showDrawingTools?: boolean;
43
+ }
44
+
45
+ let { toolbarPosition = null, showDrawingTools = true }: Props = $props();
46
+
47
+ const anchor = $derived(normalizeToolbarPosition(toolbarPosition));
48
+ const vertical = $derived(isSideAnchor(anchor));
49
+ // The slot the canvas would put the toolbar in: its place on the board and the layout of what is inside it.
50
+ const slotClasses = $derived(chromeSlots(anchor, anchor, { toolbar: showDrawingTools, zoom: false })[0]?.classes ?? null);
51
+
52
+ // The tools, in the order of the canvas's toolbar.
53
+ 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).
55
+
56
+ // Written out in full, as `ToolButton.svelte` does, so that the stylesheet of a page that installs the canvas picks every class up.
57
+ 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';
60
+ </script>
61
+
62
+ {#if slotClasses}
63
+ <!-- `@container`: the history group leaves a board narrower than 384 px, as it does in the canvas (see the style below). -->
64
+ <div
65
+ class="canvas-toolbar-placeholder-root pointer-events-none absolute inset-0 z-10 @container opacity-60"
66
+ data-canvas-toolbar-placeholder
67
+ aria-hidden="true"
68
+ inert
69
+ >
70
+ <div class={slotClasses}>
71
+ <div
72
+ 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
+ >
74
+ {#each tools as Tool, position (position)}
75
+ <IconButton label="" tabindex={-1} data-active={Tool === IconPencil ? '' : undefined} class={TOOL_BUTTON_CLASSES}>
76
+ <Tool />
77
+ </IconButton>
78
+ {/each}
79
+
80
+ <Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
81
+
82
+ <div class={SHAPES_BUTTON_CLASSES}>
83
+ <IconCategory />
84
+ <IconChevronDown />
85
+ </div>
86
+
87
+ <div class="canvas-toolbar-placeholder-history items-center gap-1 {vertical ? 'flex flex-col is-upright' : ''}">
88
+ <Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
89
+ <!-- Nothing has been done yet, so there is nothing to undo or redo: both are dimmed, as the canvas dims them. -->
90
+ <IconButton label="" tabindex={-1} disabled class="size-9">
91
+ <IconArrowBackUp class="rtl:-scale-x-100" />
92
+ </IconButton>
93
+ <IconButton label="" tabindex={-1} disabled class="size-9">
94
+ <IconArrowForwardUp class="rtl:-scale-x-100" />
95
+ </IconButton>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </div>
100
+ {/if}
101
+
102
+ <style>
103
+ /* The canvas's own rule: the history group is the first thing a board too narrow for the whole bar gives up (Figma's phone). An upright bar keeps it. */
104
+ .canvas-toolbar-placeholder-history {
105
+ display: none;
106
+ }
107
+ .canvas-toolbar-placeholder-history.is-upright {
108
+ display: flex;
109
+ }
110
+ @container (min-width: 384px) {
111
+ .canvas-toolbar-placeholder-history:not(.is-upright) {
112
+ display: flex;
113
+ }
114
+ }
115
+ </style>