@widgetic/canvas 0.5.41 → 0.5.43

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 (131) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +49 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
  4. package/dist/canvas/autosaveScheduler.js +37 -89
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +7 -19
  8. package/dist/canvas/chromeLayout.d.ts +14 -3
  9. package/dist/canvas/chromeLayout.js +30 -20
  10. package/dist/canvas/eventScope.js +10 -14
  11. package/dist/canvas/host/CanvasHost.d.ts +47 -5
  12. package/dist/canvas/host/CanvasHost.js +1481 -1566
  13. package/dist/canvas/host/CanvasHostApi.js +4 -19
  14. package/dist/canvas/host/browserServices.js +65 -116
  15. package/dist/canvas/host/conversion.js +82 -170
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/nearCards.d.ts +33 -0
  18. package/dist/canvas/host/nearCards.js +78 -0
  19. package/dist/canvas/host/pageEvents.d.ts +16 -4
  20. package/dist/canvas/host/pageEvents.js +17 -8
  21. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  22. package/dist/canvas/host/pictureSaves.js +42 -0
  23. package/dist/canvas/host/screenRects.d.ts +5 -0
  24. package/dist/canvas/host/screenRects.js +28 -31
  25. package/dist/canvas/host/storedPictures.d.ts +88 -0
  26. package/dist/canvas/host/storedPictures.js +288 -0
  27. package/dist/canvas/host/strokeSnap.js +88 -143
  28. package/dist/canvas/index.d.ts +1 -1
  29. package/dist/canvas/index.js +1 -1
  30. package/dist/canvas/openMarks.js +2 -2
  31. package/dist/canvas/outsideClickDeselect.js +6 -7
  32. package/dist/canvas/panZoomPosition.js +2 -2
  33. package/dist/canvas/preferredTextFont.js +13 -25
  34. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  35. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  36. package/dist/canvas/shapes/shapeImageStore.js +10 -3
  37. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  38. package/dist/canvas/toolbarPosition.d.ts +2 -2
  39. package/dist/canvas/toolbarPosition.js +4 -4
  40. package/dist/canvas/ui/SelectionPanel.svelte +28 -5
  41. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  42. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  43. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  44. package/dist/canvas/ui/ToolButton.svelte +8 -2
  45. package/dist/canvas/ui/colorModel.js +21 -32
  46. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  47. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  48. package/dist/canvas/ui/floatingCard.js +20 -20
  49. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  50. package/dist/canvas/ui/floatingLayer.js +18 -7
  51. package/dist/canvas/ui/keyHints.js +9 -11
  52. package/dist/canvas/ui/popoverSide.js +2 -3
  53. package/dist/canvas/ui/selectionTraits.js +34 -40
  54. package/dist/canvas/view/CanvasStage.svelte +101 -67
  55. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  56. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  57. package/dist/canvas/view/ObjectView.svelte +15 -10
  58. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  59. package/dist/canvas/view/erasingMarks.js +7 -7
  60. package/dist/canvas/view/geometry.js +71 -90
  61. package/dist/canvas/view/liftedScene.d.ts +31 -0
  62. package/dist/canvas/view/liftedScene.js +146 -0
  63. package/dist/canvas/view/mountedScene.d.ts +71 -0
  64. package/dist/canvas/view/mountedScene.js +363 -0
  65. package/dist/components/preferenceStorage.js +2 -2
  66. package/dist/engine/EngineCore.d.ts +15 -1
  67. package/dist/engine/EngineCore.js +724 -797
  68. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  69. package/dist/engine/codec/canvasDocument.js +212 -149
  70. package/dist/engine/codec/hostReadableKeys.js +1 -1
  71. package/dist/engine/core/arrange.js +26 -38
  72. package/dist/engine/core/arrow.js +76 -89
  73. package/dist/engine/core/arrowBinding.js +98 -116
  74. package/dist/engine/core/arrowBindingRecords.js +23 -38
  75. package/dist/engine/core/brush.js +67 -94
  76. package/dist/engine/core/defaults.js +90 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.d.ts +6 -0
  80. package/dist/engine/core/history.js +49 -50
  81. package/dist/engine/core/hitTest.js +68 -81
  82. package/dist/engine/core/matrix.js +18 -20
  83. package/dist/engine/core/pathData.js +183 -210
  84. package/dist/engine/core/rotationReset.js +5 -6
  85. package/dist/engine/core/scene.d.ts +10 -0
  86. package/dist/engine/core/scene.js +153 -187
  87. package/dist/engine/core/scribble.js +59 -84
  88. package/dist/engine/core/shapePaths.js +12 -15
  89. package/dist/engine/core/shapeTools.js +72 -63
  90. package/dist/engine/core/snapping.js +65 -117
  91. package/dist/engine/core/style.js +31 -64
  92. package/dist/engine/core/transform.js +83 -94
  93. package/dist/engine/core/types.d.ts +8 -2
  94. package/dist/engine/core/types.js +4 -4
  95. package/dist/engine/core/viewport.js +23 -36
  96. package/dist/engine/input/PointerController.js +467 -474
  97. package/dist/engine/input/arrowHandles.js +12 -12
  98. package/dist/engine/input/gestures.js +265 -309
  99. package/dist/engine/input/hoverCursor.js +1 -1
  100. package/dist/engine/input/keyboard.js +27 -30
  101. package/dist/engine/input/selectionHandles.js +45 -50
  102. package/dist/engine/input/types.js +1 -1
  103. package/dist/engine/render/rasterize.js +86 -158
  104. package/dist/engine/state.d.ts +20 -0
  105. package/dist/engine/state.js +5 -15
  106. package/dist/engine/text/layoutText.js +43 -62
  107. package/dist/engine/text/textMetrics.js +8 -10
  108. package/dist/engine/widgets.js +101 -137
  109. package/dist/fonts/interFont.d.ts +10 -1
  110. package/dist/fonts/interFont.js +47 -75
  111. package/dist/fonts/workspaceFonts.js +32 -90
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.d.ts +3 -3
  114. package/dist/i18n/language.js +4 -4
  115. package/dist/i18n/messages.d.ts +8 -1
  116. package/dist/i18n/messages.js +10 -2
  117. package/dist/i18n/shortcuts.js +14 -14
  118. package/dist/index.d.ts +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/settings/workspaceToolSettings.js +32 -48
  121. package/dist/tools/components/catalog.js +64 -74
  122. package/dist/tools/components/grouping.js +6 -28
  123. package/dist/tools/definitions.js +5 -5
  124. package/dist/tools/executors.js +105 -141
  125. package/dist/tools/hostAdapter.js +11 -13
  126. package/dist/tools/sceneSummary.js +43 -57
  127. package/dist/tools/sketchIntent.js +13 -21
  128. package/dist/tools/types.js +1 -1
  129. package/package.json +1 -1
  130. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  131. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -0,0 +1,363 @@
1
+ /**
2
+ * Which objects of the board have an element: the ones near what the person sees.
3
+ *
4
+ * Every object of the board used to be an element of the world layer, seen or not, and the work of the browser grew with
5
+ * the number of them (with 3000 objects, the page spent its time on elements that were far outside the screen). Now an
6
+ * object has an element only while it is close to the view; the rest is only a record in the engine's scene, which costs
7
+ * nothing to the browser. What the person does with those records does not need an element (the pointer is found by the
8
+ * engine's own hit test, a selection is drawn from the records), so a far object appears the moment it is near, and the
9
+ * person never meets one that is missing: the margin below is the room an object has to be made in.
10
+ *
11
+ * It is a store of its own, and not something `CanvasStage` derives from the engine's state, for the reason that
12
+ * `erasingMarks.ts` gives: the state is a new object at every frame of a pan, a zoom or a drag, and the board must only be
13
+ * told when the list of objects with an element is a different one.
14
+ *
15
+ * What it decides, in short:
16
+ *
17
+ * - A board of fewer objects than `CULLING_MINIMUM_OBJECTS` keeps an element for every one of them, as it always did: on a
18
+ * small board there is nothing to save, and nothing that could go wrong.
19
+ * - Above that, an object has an element when the rectangle it paints (its box turned, with its stroke, see
20
+ * `shapeVisualBounds`) touches the *near area*: the view, with half a view of room on every side.
21
+ * - An object that has its element already keeps it a while longer: until it is out of the *keep area*, which is the view with
22
+ * a whole view of room on every side. A pan that goes out and comes back (the hand of a person on a tablet does that all the
23
+ * time) must not have the browser build the same objects twice. The keep area is for a view that pans or zooms out. A view
24
+ * that zooms in has no use for what it left behind (the person looks at a few objects of a big board now, which is what this
25
+ * is all for), so it lets go at once of everything that is not near it.
26
+ * - The near area is not worked out again at every frame. It is kept while the view stays within `REFRESH_DISTANCE_RATIO`
27
+ * of a view of where it was when the area was made (and has not zoomed in by more than `ZOOM_IN_REFRESH_RATIO`), so
28
+ * most frames of a pan cost nothing but that check, and the objects are made in steps instead of one by one.
29
+ * - A text that is being typed in always has its element, wherever the person scrolls to: its field is the element.
30
+ * - When many objects are wanted at once (the board was just opened, the view jumped to the whole board, an undo brought
31
+ * back a thousand shapes) they are not all made in the same frame: the ones the person can see come first, the nearest
32
+ * to the middle of the view first among them, then the ones of the margin. How many a frame takes follows how the frames
33
+ * are going: it starts at `MOUNT_BATCH_SIZE`, shrinks by half when a frame came late (the last batch was too much for this
34
+ * device) and grows a little when frames come on time, so that a fast desktop is done in a few frames and a slow tablet
35
+ * keeps drawing at its pace. Objects that are out of the keep area lose their element at once, which is cheap.
36
+ * - The order of the list is the paint order of the scene, and a group, which draws nothing, is not in it.
37
+ *
38
+ * Plain TypeScript with no Svelte file in it, so that Node can test it.
39
+ */
40
+ import { writable } from 'svelte/store';
41
+ import { rectsIntersect } from '../../engine/core/geometry.js';
42
+ import { shapeVisualBounds } from '../../engine/core/scene.js';
43
+ import { isBoxedObject } from '../../engine/core/types.js';
44
+ import { visibleWorldRect } from '../../engine/core/viewport.js';
45
+ /** A board with fewer objects than this keeps an element for every one of them. */
46
+ export const CULLING_MINIMUM_OBJECTS = 150;
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;
49
+ /**
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
+ * 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
52
+ * goes out and back build the same objects twice (a few hundred of them, when the whole board is in view). The most that can have
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
+ * area of a board (see `nearAreaAround`).
55
+ */
56
+ export const KEEP_MARGIN_RATIO = 1;
57
+ /**
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
+ * 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
+ */
61
+ export const REFRESH_DISTANCE_RATIO = 0.15;
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;
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;
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;
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;
70
+ /** What the batch grows by after a frame that came on time. */
71
+ export const MOUNT_BATCH_GROWTH = 8;
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;
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;
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;
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([]);
80
+ /**
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
+ *
83
+ * It is not remembered for the record. A record is measured in about a tenth of a microsecond, and a `WeakMap` that is handed every
84
+ * new record of a drag (all of them, when the whole selection moves) costs ten times that at every frame: measured, a drag of the
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
+ */
87
+ function paintedBoundsOf(shape) {
88
+ const measured = shapeVisualBounds(shape);
89
+ if (measured.width >= 0 && measured.height >= 0)
90
+ return measured;
91
+ // A box that was written with a negative size is the same box from the other corner.
92
+ return {
93
+ x: measured.width < 0 ? measured.x + measured.width : measured.x,
94
+ y: measured.height < 0 ? measured.y + measured.height : measured.y,
95
+ width: Math.abs(measured.width),
96
+ height: Math.abs(measured.height)
97
+ };
98
+ }
99
+ /** A view with `ratio` of its width and height added on every side. */
100
+ function viewWithMargin(view, ratio) {
101
+ const marginX = view.width * ratio;
102
+ const marginY = view.height * ratio;
103
+ return { x: view.x - marginX, y: view.y - marginY, width: view.width + marginX * 2, height: view.height + marginY * 2 };
104
+ }
105
+ /**
106
+ * The near area around a view (`NEAR_MARGIN_RATIO` on every side), and the keep area that goes with it.
107
+ *
108
+ * The keep area is wider (`KEEP_MARGIN_RATIO`) only for a view that comes after another one (`previous`) and has not zoomed in by
109
+ * more than `ZOOM_IN_REFRESH_RATIO` since: it panned, or zoomed out, and what it made stays until it is far. A view that has
110
+ * zoomed in, or the first view of a board (nothing was made around a view before it, or everything was, which a board that has no
111
+ * size yet does), has the keep area of the near area: what is not near it loses its element at once.
112
+ */
113
+ function nearAreaAround(view, zoom, previous) {
114
+ const keepsWhatItHas = previous !== null && zoom <= previous.zoom * ZOOM_IN_REFRESH_RATIO;
115
+ return {
116
+ view,
117
+ zoom,
118
+ area: viewWithMargin(view, NEAR_MARGIN_RATIO),
119
+ keepArea: viewWithMargin(view, keepsWhatItHas ? KEEP_MARGIN_RATIO : NEAR_MARGIN_RATIO)
120
+ };
121
+ }
122
+ /** Whether the near area still serves a view: the view is where it was, give or take the slack, and has not zoomed in far. */
123
+ function isStillNear(near, view, zoom) {
124
+ if (zoom > near.zoom * ZOOM_IN_REFRESH_RATIO)
125
+ return false;
126
+ const slackX = near.view.width * REFRESH_DISTANCE_RATIO;
127
+ const slackY = near.view.height * REFRESH_DISTANCE_RATIO;
128
+ return (view.x >= near.view.x - slackX &&
129
+ view.y >= near.view.y - slackY &&
130
+ view.x + view.width <= near.view.x + near.view.width + slackX &&
131
+ view.y + view.height <= near.view.y + near.view.height + slackY);
132
+ }
133
+ /** A rectangle made of finite numbers, with some size: anything else says the board has no size (or no view) yet. */
134
+ function isUsableView(view) {
135
+ return Number.isFinite(view.x) && Number.isFinite(view.y) && Number.isFinite(view.width) && Number.isFinite(view.height) && view.width > 0 && view.height > 0;
136
+ }
137
+ /** Whether two lists hold the very same records in the same order (the very same list is the quick case). */
138
+ function sameRecords(first, second) {
139
+ if (first === second)
140
+ return true;
141
+ if (first.length !== second.length)
142
+ return false;
143
+ for (let position = 0; position < first.length; position += 1) {
144
+ if (first[position] !== second[position])
145
+ return false;
146
+ }
147
+ return true;
148
+ }
149
+ /** Whether two lists are of the very same objects (by id) in the same order, whatever their records are: a drag changes records and not objects. */
150
+ function sameObjects(first, second) {
151
+ if (first.length !== second.length)
152
+ return false;
153
+ for (let position = 0; position < first.length; position += 1) {
154
+ if (first[position].id !== second[position].id)
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+ /**
160
+ * The ids of the `count` objects to make first: the ones that touch the view before the others, and the nearest to the middle of the
161
+ * view first in each of the two kinds.
162
+ */
163
+ function nearestIdsFirst(candidates, view, count) {
164
+ const middleX = view.x + view.width / 2;
165
+ const middleY = view.y + view.height / 2;
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;
172
+ return { id: object.id, rank: (rectsIntersect(view, bounds) ? 0 : OUT_OF_VIEW) + offsetX * offsetX + offsetY * offsetY };
173
+ });
174
+ ranked.sort((first, second) => first.rank - second.rank);
175
+ return new Set(ranked.slice(0, count).map((entry) => entry.id));
176
+ }
177
+ /** The frame the page gives, or null where there is none (a server render). */
178
+ function pageFrameScheduler() {
179
+ if (typeof requestAnimationFrame !== 'function' || typeof cancelAnimationFrame !== 'function')
180
+ return null;
181
+ return (callback) => {
182
+ const handle = requestAnimationFrame((frameTime) => callback(frameTime));
183
+ return () => cancelAnimationFrame(handle);
184
+ };
185
+ }
186
+ export function createMountedScene(options = {}) {
187
+ const minimumObjects = options.minimumObjects ?? CULLING_MINIMUM_OBJECTS;
188
+ const scheduleFrame = options.scheduleFrame ?? pageFrameScheduler();
189
+ // A batch size that was given stays; otherwise it follows the frames (see `adaptBatchSizeTo`).
190
+ const batchSizeFollowsFrames = options.batchSize === undefined;
191
+ // 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);
193
+ // 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
+ /** The list the subscribers have. */
197
+ let published = NOTHING_MOUNTED;
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`).
199
+ let idsOfPublishedFor = null;
200
+ let idsOfPublished = new Set();
201
+ let near = null;
202
+ let latestInput = null;
203
+ let latestView = null;
204
+ // 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;
210
+ // Once the work has failed, the board is drawn whole from then on (and the failure is said once).
211
+ let failed = false;
212
+ function idsOfPublishedList() {
213
+ if (idsOfPublishedFor !== published) {
214
+ idsOfPublished = new Set(published.map((object) => object.id));
215
+ idsOfPublishedFor = published;
216
+ }
217
+ return idsOfPublished;
218
+ }
219
+ function publish(next) {
220
+ // A store tells its subscribers of every `set` of an object, equal or not: the same records again is no news.
221
+ if (sameRecords(next, published))
222
+ return;
223
+ // A drag hands over other records for the same objects, at every frame: the ids that were gathered for the list that was
224
+ // published are the ids of this one too, and gathering them again (a set of every id) would cost a good part of the frame.
225
+ if (idsOfPublishedFor === published && sameObjects(next, published))
226
+ idsOfPublishedFor = next;
227
+ published = next;
228
+ set(next);
229
+ }
230
+ function stopWaitingForFrame() {
231
+ cancelFrame?.();
232
+ cancelFrame = null;
233
+ }
234
+ /**
235
+ * Learns from the frames how many objects a frame can take. The frame that comes after a batch is late when the batch was too
236
+ * much (the page could not draw it in time), so the next batch is half of it; frames on time let the batch grow by a few.
237
+ * A frame time that is not known, or a pause between frames (a hidden tab), teaches nothing.
238
+ */
239
+ function adaptBatchSizeTo(frameTime) {
240
+ if (!batchSizeFollowsFrames || batchSize === Infinity)
241
+ return;
242
+ if (typeof frameTime !== 'number' || !Number.isFinite(frameTime)) {
243
+ lastBatchFrameTime = null;
244
+ return;
245
+ }
246
+ const previous = lastBatchFrameTime;
247
+ lastBatchFrameTime = frameTime;
248
+ if (previous === null)
249
+ return;
250
+ const interval = frameTime - previous;
251
+ if (interval > PAUSED_FRAME_MS || interval < 0)
252
+ return;
253
+ if (interval > SLOW_FRAME_MS)
254
+ batchSize = Math.max(MIN_MOUNT_BATCH_SIZE, Math.floor(batchSize / 2));
255
+ else if (interval < QUICK_FRAME_MS)
256
+ batchSize = Math.min(MAX_MOUNT_BATCH_SIZE, batchSize + MOUNT_BATCH_GROWTH);
257
+ }
258
+ /** Every object has its element: the board is small, or nothing is known of the view, or the work failed. */
259
+ function publishWholeScene(scene) {
260
+ stopWaitingForFrame();
261
+ near = null;
262
+ workedScene = null;
263
+ workedNear = null;
264
+ publish(scene);
265
+ }
266
+ function giveUpCulling(error, scene) {
267
+ if (!failed) {
268
+ failed = true;
269
+ console.warn('Canvas: the board could not tell which objects are near the view, so every object is drawn', error);
270
+ }
271
+ publishWholeScene(scene);
272
+ }
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. */
274
+ function mountNearObjects(input, nearArea, view) {
275
+ const { scene, editingTextId } = input;
276
+ // 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
+ // 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
+ // a drag) makes no list of them.
281
+ let missingCount = 0;
282
+ for (const object of scene) {
283
+ // A group draws nothing: its members are objects of their own.
284
+ if (!isBoxedObject(object))
285
+ continue;
286
+ const hasElementAlready = alreadyMade.has(object.id);
287
+ if (object.id !== editingTextId) {
288
+ const painted = paintedBoundsOf(object);
289
+ // 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);
291
+ if (!keepsItsElement && !rectsIntersect(nearArea.area, painted))
292
+ continue;
293
+ }
294
+ wanted.push(object);
295
+ if (!hasElementAlready)
296
+ missingCount += 1;
297
+ }
298
+ let next = wanted;
299
+ let moreToMake = false;
300
+ 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
+ moreToMake = true;
305
+ }
306
+ workedScene = scene;
307
+ workedEditingTextId = editingTextId;
308
+ workedNear = nearArea;
309
+ publish(next);
310
+ if (!moreToMake) {
311
+ stopWaitingForFrame();
312
+ // The next burst starts from a fresh reading of the frames.
313
+ lastBatchFrameTime = null;
314
+ return;
315
+ }
316
+ if (cancelFrame !== null || scheduleFrame === null)
317
+ return;
318
+ cancelFrame = scheduleFrame((frameTime) => {
319
+ cancelFrame = null;
320
+ if (destroyed || latestInput === null || near === null || latestView === null)
321
+ return;
322
+ adaptBatchSizeTo(frameTime);
323
+ try {
324
+ mountNearObjects(latestInput, near, latestView);
325
+ }
326
+ catch (error) {
327
+ giveUpCulling(error, latestInput.scene);
328
+ }
329
+ });
330
+ }
331
+ return {
332
+ subscribe,
333
+ take(input) {
334
+ if (destroyed)
335
+ return;
336
+ latestInput = input;
337
+ try {
338
+ if (failed || input.scene.length < minimumObjects) {
339
+ publishWholeScene(input.scene);
340
+ return;
341
+ }
342
+ const view = visibleWorldRect(input.viewport, input.viewSize);
343
+ if (!isUsableView(view) || !Number.isFinite(input.viewport.zoom) || input.viewport.zoom <= 0) {
344
+ publishWholeScene(input.scene);
345
+ return;
346
+ }
347
+ latestView = view;
348
+ if (near === null || !isStillNear(near, view, input.viewport.zoom))
349
+ near = nearAreaAround(view, input.viewport.zoom, near);
350
+ if (input.scene === workedScene && input.editingTextId === workedEditingTextId && near === workedNear)
351
+ return;
352
+ mountNearObjects(input, near, view);
353
+ }
354
+ catch (error) {
355
+ giveUpCulling(error, input.scene);
356
+ }
357
+ },
358
+ destroy() {
359
+ destroyed = true;
360
+ stopWaitingForFrame();
361
+ }
362
+ };
363
+ }
@@ -6,7 +6,7 @@
6
6
  * is written into the page's storage and a browser that several visitors share does not pass one visitor's choices on
7
7
  * to the next. The host does this once, before the canvas is shown.
8
8
  */
9
- var installedStorage = null;
9
+ let installedStorage = null;
10
10
  /** Installs the store the canvas keeps the visitor's choices in; `null` goes back to the browser's `localStorage`. */
11
11
  export function setCanvasPreferenceStorage(storage) {
12
12
  installedStorage = storage;
@@ -18,7 +18,7 @@ export function getCanvasPreferenceStorage() {
18
18
  try {
19
19
  return typeof localStorage === 'undefined' ? null : localStorage;
20
20
  }
21
- catch (_a) {
21
+ catch {
22
22
  // Reading `localStorage` itself throws where the browser blocks storage for the page.
23
23
  return null;
24
24
  }
@@ -128,13 +128,27 @@ export declare class EngineCore {
128
128
  * of what was loaded (a name filled in), not an edit.
129
129
  */
130
130
  applySilently(next: Scene): void;
131
+ /**
132
+ * Fills in what was loaded late (a picture that arrived after the board was opened and used) in the board and in every step of
133
+ * its history, with no undo step and without telling the host that the board changed: a repair of what was loaded, not an edit.
134
+ * `repair` must give back the very same scene when it has nothing to change.
135
+ *
136
+ * Not `applySilently`, which is for what is done before the person can do anything: it makes the board the current step, and
137
+ * that is wrong twice over for a repair that comes in the middle of the person's work. A gesture that is under way has a scene
138
+ * of its own (the board is then not any step), and it would be written into the step the gesture started from, so that Escape
139
+ * could not take it back; and the steps before this one would still be without the picture, so an undo would take it away.
140
+ */
141
+ repairLoaded(repair: (scene: Scene) => Scene): void;
131
142
  /** Records the scene as it is now as one undo step (the end of a gesture). False when nothing changed since the last step. */
132
143
  commit(): boolean;
133
144
  /** Throws away what a gesture did and goes back to the last step (Escape in the middle of a drag). */
134
145
  revertToCommitted(): void;
135
146
  undo(): boolean;
136
147
  redo(): boolean;
137
- /** Adds objects on top of the board in one step. Returns their ids. */
148
+ /**
149
+ * Adds objects on top of the board in one step, except that a drawing goes under the widget cards (a card is added on top).
150
+ * Returns their ids.
151
+ */
138
152
  addObjects(objects: readonly SceneObject[], options?: {
139
153
  select?: boolean;
140
154
  }): ObjectId[];