@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.
- package/README.md +1 -1
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -2
- package/dist/canvas/host/CanvasHost.js +1615 -1847
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +21 -21
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +35 -41
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +9 -2
- package/dist/engine/EngineCore.js +798 -907
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +84 -96
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.js +160 -224
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +32 -65
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +267 -310
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +35 -39
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.js +6 -17
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.js +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/poster/boardPlacement.js +28 -30
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +8 -0
- package/dist/settings/workspaceToolSettings.js +35 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +137 -169
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +2 -2
|
@@ -1,62 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
49
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
50
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
51
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
52
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
53
|
-
};
|
|
54
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
55
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
56
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
57
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
58
|
-
};
|
|
59
|
-
var _PictureQueue_instances, _PictureQueue_waiting, _PictureQueue_positions, _PictureQueue_orderedFor, _PictureQueue_needsOrderingFor, _PictureQueue_orderFor;
|
|
60
1
|
/**
|
|
61
2
|
* Reading the pictures that a saved board only points at, when the board is opened.
|
|
62
3
|
*
|
|
@@ -80,19 +21,18 @@ var _PictureQueue_instances, _PictureQueue_waiting, _PictureQueue_positions, _Pi
|
|
|
80
21
|
import { rectsIntersect } from '../../engine/core/geometry.js';
|
|
81
22
|
import { shapeVisualBounds } from '../../engine/core/scene.js';
|
|
82
23
|
/** How many pictures are asked of the store at the same time. */
|
|
83
|
-
export
|
|
24
|
+
export const PICTURE_LOAD_CONCURRENCY = 6;
|
|
84
25
|
/** How long the pictures that came in are kept before they are put on the board together (so that a burst is one change, not forty). */
|
|
85
|
-
export
|
|
26
|
+
export const PICTURE_APPLY_DELAY_MS = 40;
|
|
86
27
|
/**
|
|
87
28
|
* How long the pictures that are not on screen wait for the ones that are, at most. They wait for them to come in, so that the
|
|
88
29
|
* store and the network are the on-screen pictures' alone; one that hangs must not hold back the rest of the board for ever.
|
|
89
30
|
*/
|
|
90
|
-
export
|
|
31
|
+
export const PICTURE_BACKGROUND_GRACE_MS = 3000;
|
|
91
32
|
/** The objects of a scene that point at a picture and do not hold its bytes, in the order of the scene. */
|
|
92
33
|
export function picturesStillMissing(scene) {
|
|
93
|
-
|
|
94
|
-
for (
|
|
95
|
-
var object = scene_1[_i];
|
|
34
|
+
const missing = [];
|
|
35
|
+
for (const object of scene) {
|
|
96
36
|
if (object.type === 'image' && !object.src && object.imageRef) {
|
|
97
37
|
missing.push({ objectId: object.id, reference: object.imageRef, bounds: shapeVisualBounds(object) });
|
|
98
38
|
}
|
|
@@ -110,18 +50,18 @@ export function picturesStillMissing(scene) {
|
|
|
110
50
|
export function fillPictures(scene, loaded) {
|
|
111
51
|
if (loaded.size === 0)
|
|
112
52
|
return scene;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
53
|
+
let changed = false;
|
|
54
|
+
const filled = scene.map((object) => {
|
|
55
|
+
const picture = loaded.get(object.id);
|
|
116
56
|
if (!picture)
|
|
117
57
|
return object;
|
|
118
58
|
if (object.type === 'image' && !object.src && object.imageRef === picture.reference) {
|
|
119
59
|
changed = true;
|
|
120
|
-
return
|
|
60
|
+
return { ...object, src: picture.dataUrl };
|
|
121
61
|
}
|
|
122
62
|
if (object.type === 'widget' && !object.thumbnail && object.thumbnailRef === picture.reference) {
|
|
123
63
|
changed = true;
|
|
124
|
-
return
|
|
64
|
+
return { ...object, thumbnail: picture.dataUrl };
|
|
125
65
|
}
|
|
126
66
|
return object;
|
|
127
67
|
});
|
|
@@ -131,29 +71,18 @@ export function fillPictures(scene, loaded) {
|
|
|
131
71
|
* Waits for a promise for at most `milliseconds`. True when it finished in time, false when the time ran out first (the promise is
|
|
132
72
|
* not stopped: whatever it was doing goes on). A promise that fails counts as finished: the caller only wanted to know that it is over.
|
|
133
73
|
*/
|
|
134
|
-
export function waitUpTo(promise, milliseconds) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
switch (_a.label) {
|
|
139
|
-
case 0:
|
|
140
|
-
timeRanOut = function () { return undefined; };
|
|
141
|
-
timeUp = new Promise(function (resolve) {
|
|
142
|
-
timeRanOut = function () { return resolve(false); };
|
|
143
|
-
});
|
|
144
|
-
timer = setTimeout(function () { return timeRanOut(); }, milliseconds);
|
|
145
|
-
_a.label = 1;
|
|
146
|
-
case 1:
|
|
147
|
-
_a.trys.push([1, , 3, 4]);
|
|
148
|
-
return [4 /*yield*/, Promise.race([promise.then(function () { return true; }, function () { return true; }), timeUp])];
|
|
149
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
150
|
-
case 3:
|
|
151
|
-
clearTimeout(timer);
|
|
152
|
-
return [7 /*endfinally*/];
|
|
153
|
-
case 4: return [2 /*return*/];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
74
|
+
export async function waitUpTo(promise, milliseconds) {
|
|
75
|
+
let timeRanOut = () => undefined;
|
|
76
|
+
const timeUp = new Promise((resolve) => {
|
|
77
|
+
timeRanOut = () => resolve(false);
|
|
156
78
|
});
|
|
79
|
+
const timer = setTimeout(() => timeRanOut(), milliseconds);
|
|
80
|
+
try {
|
|
81
|
+
return await Promise.race([promise.then(() => true, () => true), timeUp]);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
}
|
|
157
86
|
}
|
|
158
87
|
/** A rectangle made of finite numbers with some size: anything else says the board has no size (or no view) yet. */
|
|
159
88
|
export function isUsableView(view) {
|
|
@@ -163,9 +92,8 @@ export function isUsableView(view) {
|
|
|
163
92
|
export function countPicturesInView(missing, view) {
|
|
164
93
|
if (!isUsableView(view))
|
|
165
94
|
return missing.length;
|
|
166
|
-
|
|
167
|
-
for (
|
|
168
|
-
var picture = missing_1[_i];
|
|
95
|
+
let count = 0;
|
|
96
|
+
for (const picture of missing) {
|
|
169
97
|
if (rectsIntersect(view, picture.bounds))
|
|
170
98
|
count += 1;
|
|
171
99
|
}
|
|
@@ -177,100 +105,87 @@ export function countPicturesInView(missing, view) {
|
|
|
177
105
|
* of itself or changed its size by a quarter (not at every pan frame, and not at every picture), and it is the scene's own order
|
|
178
106
|
* when the view is not known.
|
|
179
107
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
108
|
+
export class PictureQueue {
|
|
109
|
+
// Kept with the best one last, so that handing it out is a `pop`.
|
|
110
|
+
#waiting;
|
|
111
|
+
// Where each picture was in the scene: what breaks a tie, and what a picture that is given back keeps.
|
|
112
|
+
#positions = new Map();
|
|
113
|
+
#orderedFor = null;
|
|
114
|
+
constructor(missing) {
|
|
115
|
+
this.#waiting = missing.map((picture, position) => ({ picture, position })).reverse();
|
|
116
|
+
for (const { picture, position } of this.#waiting)
|
|
117
|
+
this.#positions.set(picture, position);
|
|
118
|
+
}
|
|
119
|
+
/** How many are still to be asked for. */
|
|
120
|
+
get length() {
|
|
121
|
+
return this.#waiting.length;
|
|
193
122
|
}
|
|
194
|
-
Object.defineProperty(PictureQueue.prototype, "length", {
|
|
195
|
-
/** How many are still to be asked for. */
|
|
196
|
-
get: function () {
|
|
197
|
-
return __classPrivateFieldGet(this, _PictureQueue_waiting, "f").length;
|
|
198
|
-
},
|
|
199
|
-
enumerable: false,
|
|
200
|
-
configurable: true
|
|
201
|
-
});
|
|
202
123
|
/** The picture to ask for next, or undefined when none is left. */
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
124
|
+
take(view) {
|
|
125
|
+
if (isUsableView(view) && this.#needsOrderingFor(view))
|
|
126
|
+
this.#orderFor(view);
|
|
127
|
+
return this.#waiting.pop()?.picture;
|
|
128
|
+
}
|
|
209
129
|
/** Puts back a picture that was taken and not asked for after all: it is the next one to be handed out (it was the best). */
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
view.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
__classPrivateFieldSet(this, _PictureQueue_waiting, ranked.map(function (item) { return item.entry; }), "f");
|
|
240
|
-
};
|
|
130
|
+
giveBack(picture) {
|
|
131
|
+
this.#waiting.push({ picture, position: this.#positions.get(picture) ?? 0 });
|
|
132
|
+
}
|
|
133
|
+
#needsOrderingFor(view) {
|
|
134
|
+
const last = this.#orderedFor;
|
|
135
|
+
if (last === null)
|
|
136
|
+
return true;
|
|
137
|
+
return (Math.abs(view.x - last.x) > last.width * 0.25 ||
|
|
138
|
+
Math.abs(view.y - last.y) > last.height * 0.25 ||
|
|
139
|
+
view.width > last.width * 1.25 ||
|
|
140
|
+
view.width < last.width * 0.8);
|
|
141
|
+
}
|
|
142
|
+
#orderFor(view) {
|
|
143
|
+
this.#orderedFor = view;
|
|
144
|
+
const middleX = view.x + view.width / 2;
|
|
145
|
+
const middleY = view.y + view.height / 2;
|
|
146
|
+
// Squared distances stay far below this, so adding it puts every picture that is off the view after every one that is on it.
|
|
147
|
+
const OFF_THE_VIEW = 1e18;
|
|
148
|
+
const ranked = this.#waiting.map((entry) => {
|
|
149
|
+
const bounds = entry.picture.bounds;
|
|
150
|
+
const offsetX = bounds.x + bounds.width / 2 - middleX;
|
|
151
|
+
const offsetY = bounds.y + bounds.height / 2 - middleY;
|
|
152
|
+
return { entry, rank: (rectsIntersect(view, bounds) ? 0 : OFF_THE_VIEW) + offsetX * offsetX + offsetY * offsetY };
|
|
153
|
+
});
|
|
154
|
+
// The worst first and, among equals, the one that was later in the scene first: the last one is the best, and the earliest of equals.
|
|
155
|
+
ranked.sort((first, second) => second.rank - first.rank || second.entry.position - first.entry.position);
|
|
156
|
+
this.#waiting = ranked.map((item) => item.entry);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
241
159
|
/**
|
|
242
160
|
* Asks the store for the missing pictures, a few at a time and in the order of `PictureQueue`, and puts what comes in on the board
|
|
243
161
|
* in small batches. Never throws: a picture the store cannot give is a warning, and the others go on.
|
|
244
162
|
*/
|
|
245
163
|
export function startLoadingPictures(plan) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var firstScreenful = new Promise(function (resolve) {
|
|
164
|
+
const concurrency = Math.max(1, plan.concurrency ?? PICTURE_LOAD_CONCURRENCY);
|
|
165
|
+
const applyDelayMs = plan.applyDelayMs ?? PICTURE_APPLY_DELAY_MS;
|
|
166
|
+
const backgroundGraceMs = plan.backgroundGraceMs ?? PICTURE_BACKGROUND_GRACE_MS;
|
|
167
|
+
const queue = new PictureQueue(plan.missing);
|
|
168
|
+
const arrived = new Map();
|
|
169
|
+
const requests = new Map();
|
|
170
|
+
const failedReferences = new Set();
|
|
171
|
+
let applyTimer = null;
|
|
172
|
+
let boardOpened = false;
|
|
173
|
+
let finishFirstScreenful = () => undefined;
|
|
174
|
+
const firstScreenful = new Promise((resolve) => {
|
|
258
175
|
finishFirstScreenful = resolve;
|
|
259
176
|
});
|
|
260
177
|
// The pictures of objects that are on screen and are being asked for right now, and the workers that hold back a picture of an
|
|
261
178
|
// object that is not on screen until those are answered (or until `letBackgroundStart`).
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
179
|
+
let onScreenInFlight = 0;
|
|
180
|
+
let backgroundMayStart = false;
|
|
181
|
+
let workersHeldBack = [];
|
|
182
|
+
let graceTimer = null;
|
|
266
183
|
function letBackgroundStart() {
|
|
267
184
|
backgroundMayStart = true;
|
|
268
|
-
|
|
185
|
+
const held = workersHeldBack;
|
|
269
186
|
workersHeldBack = [];
|
|
270
|
-
for (
|
|
271
|
-
var release = held_1[_i];
|
|
187
|
+
for (const release of held)
|
|
272
188
|
release();
|
|
273
|
-
}
|
|
274
189
|
}
|
|
275
190
|
function putArrivedOnTheBoard() {
|
|
276
191
|
if (applyTimer !== null) {
|
|
@@ -279,7 +194,7 @@ export function startLoadingPictures(plan) {
|
|
|
279
194
|
}
|
|
280
195
|
if (arrived.size === 0)
|
|
281
196
|
return;
|
|
282
|
-
|
|
197
|
+
const batch = new Map(arrived);
|
|
283
198
|
arrived.clear();
|
|
284
199
|
if (plan.isCancelled())
|
|
285
200
|
return;
|
|
@@ -299,78 +214,69 @@ export function startLoadingPictures(plan) {
|
|
|
299
214
|
finishFirstScreenful();
|
|
300
215
|
letBackgroundStart();
|
|
301
216
|
}
|
|
302
|
-
function work() {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
217
|
+
async function work() {
|
|
218
|
+
for (;;) {
|
|
219
|
+
if (plan.isCancelled())
|
|
220
|
+
return;
|
|
221
|
+
const view = plan.currentView();
|
|
222
|
+
const picture = queue.take(view);
|
|
223
|
+
if (!picture)
|
|
224
|
+
return;
|
|
225
|
+
const onScreen = !isUsableView(view) || rectsIntersect(view, picture.bounds);
|
|
226
|
+
if (!onScreen) {
|
|
227
|
+
// The queue hands out the pictures of objects that are on screen first, so this one coming up means none of them is left to
|
|
228
|
+
// be asked for. When none is on its way either, they are all in: the board opens. Otherwise the ones on their way have the
|
|
229
|
+
// store and the network to themselves until they are answered (or the grace is over: one that hangs must not hold the rest
|
|
230
|
+
// of the board back for ever).
|
|
231
|
+
if (onScreenInFlight === 0) {
|
|
232
|
+
openTheBoard();
|
|
233
|
+
}
|
|
234
|
+
else if (!backgroundMayStart) {
|
|
235
|
+
queue.giveBack(picture);
|
|
236
|
+
graceTimer ??= setTimeout(letBackgroundStart, backgroundGraceMs);
|
|
237
|
+
await new Promise((resolve) => workersHeldBack.push(resolve));
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
onScreenInFlight += 1;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
// One question per reference: a picture that several objects point at is read once and given to each of them.
|
|
246
|
+
let request = requests.get(picture.reference);
|
|
247
|
+
if (!request) {
|
|
248
|
+
request = plan.store.load(picture.reference, { priority: onScreen ? 'visible' : 'background' });
|
|
249
|
+
requests.set(picture.reference, request);
|
|
250
|
+
}
|
|
251
|
+
const dataUrl = await request;
|
|
252
|
+
if (dataUrl) {
|
|
253
|
+
arrived.set(picture.objectId, { reference: picture.reference, dataUrl });
|
|
254
|
+
if (applyTimer === null)
|
|
255
|
+
applyTimer = setTimeout(putArrivedOnTheBoard, applyDelayMs);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
// Said once for a reference, not once for each object that points at it.
|
|
260
|
+
if (!failedReferences.has(picture.reference)) {
|
|
261
|
+
failedReferences.add(picture.reference);
|
|
262
|
+
plan.warn('Canvas: a stored picture could not be read', picture.reference, error);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
if (onScreen) {
|
|
267
|
+
onScreenInFlight -= 1;
|
|
268
|
+
// Workers are held back only by a picture that is not on screen, so there is none on screen left to be asked for.
|
|
269
|
+
if (onScreenInFlight === 0 && workersHeldBack.length > 0)
|
|
317
270
|
openTheBoard();
|
|
318
|
-
return [3 /*break*/, 3];
|
|
319
|
-
case 1:
|
|
320
|
-
if (!!backgroundMayStart) return [3 /*break*/, 3];
|
|
321
|
-
queue.giveBack(picture);
|
|
322
|
-
graceTimer !== null && graceTimer !== void 0 ? graceTimer : (graceTimer = setTimeout(letBackgroundStart, backgroundGraceMs));
|
|
323
|
-
return [4 /*yield*/, new Promise(function (resolve) { return workersHeldBack.push(resolve); })];
|
|
324
|
-
case 2:
|
|
325
|
-
_a.sent();
|
|
326
|
-
return [3 /*break*/, 9];
|
|
327
|
-
case 3: return [3 /*break*/, 5];
|
|
328
|
-
case 4:
|
|
329
|
-
onScreenInFlight += 1;
|
|
330
|
-
_a.label = 5;
|
|
331
|
-
case 5:
|
|
332
|
-
_a.trys.push([5, 7, 8, 9]);
|
|
333
|
-
request = requests.get(picture.reference);
|
|
334
|
-
if (!request) {
|
|
335
|
-
request = plan.store.load(picture.reference, { priority: onScreen ? 'visible' : 'background' });
|
|
336
|
-
requests.set(picture.reference, request);
|
|
337
|
-
}
|
|
338
|
-
return [4 /*yield*/, request];
|
|
339
|
-
case 6:
|
|
340
|
-
dataUrl = _a.sent();
|
|
341
|
-
if (dataUrl) {
|
|
342
|
-
arrived.set(picture.objectId, { reference: picture.reference, dataUrl: dataUrl });
|
|
343
|
-
if (applyTimer === null)
|
|
344
|
-
applyTimer = setTimeout(putArrivedOnTheBoard, applyDelayMs);
|
|
345
|
-
}
|
|
346
|
-
return [3 /*break*/, 9];
|
|
347
|
-
case 7:
|
|
348
|
-
error_1 = _a.sent();
|
|
349
|
-
// Said once for a reference, not once for each object that points at it.
|
|
350
|
-
if (!failedReferences.has(picture.reference)) {
|
|
351
|
-
failedReferences.add(picture.reference);
|
|
352
|
-
plan.warn('Canvas: a stored picture could not be read', picture.reference, error_1);
|
|
353
|
-
}
|
|
354
|
-
return [3 /*break*/, 9];
|
|
355
|
-
case 8:
|
|
356
|
-
if (onScreen) {
|
|
357
|
-
onScreenInFlight -= 1;
|
|
358
|
-
// Workers are held back only by a picture that is not on screen, so there is none on screen left to be asked for.
|
|
359
|
-
if (onScreenInFlight === 0 && workersHeldBack.length > 0)
|
|
360
|
-
openTheBoard();
|
|
361
|
-
}
|
|
362
|
-
return [7 /*endfinally*/];
|
|
363
|
-
case 9: return [3 /*break*/, 0];
|
|
364
|
-
case 10: return [2 /*return*/];
|
|
365
271
|
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
368
274
|
}
|
|
369
|
-
|
|
370
|
-
|
|
275
|
+
const workerCount = Math.min(concurrency, plan.missing.length);
|
|
276
|
+
const everything = Promise.all(Array.from({ length: workerCount }, () => work()))
|
|
371
277
|
// Nothing above throws, but a board that is opened must never be left waiting for a promise that fails.
|
|
372
|
-
.catch(
|
|
373
|
-
.then(
|
|
278
|
+
.catch((error) => plan.warn('Canvas: reading the stored pictures stopped early', error))
|
|
279
|
+
.then(() => {
|
|
374
280
|
if (graceTimer !== null)
|
|
375
281
|
clearTimeout(graceTimer);
|
|
376
282
|
// What is still waiting for its batch goes on the board now, and nothing is left to wait for: everything is answered (or the
|
|
@@ -378,5 +284,5 @@ export function startLoadingPictures(plan) {
|
|
|
378
284
|
putArrivedOnTheBoard();
|
|
379
285
|
openTheBoard();
|
|
380
286
|
});
|
|
381
|
-
return { firstScreenful
|
|
287
|
+
return { firstScreenful, everything };
|
|
382
288
|
}
|