@widgetic/canvas 0.5.44 → 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.
- package/dist/canvas/DomCanvas.svelte +52 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
- package/dist/canvas/autosaveScheduler.js +89 -37
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +19 -7
- package/dist/canvas/chromeLayout.js +21 -19
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +68 -1
- package/dist/canvas/host/CanvasHost.js +1901 -1407
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +28 -5
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +155 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +211 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +21 -18
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +11 -9
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/storedPictures.js +243 -149
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +7 -6
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +25 -13
- package/dist/canvas/shapes/ShapeLibrary.js +148 -138
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/SelectionPanel.svelte +78 -17
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +34 -55
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +43 -21
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +66 -35
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +90 -71
- package/dist/canvas/view/liftedScene.js +36 -24
- package/dist/canvas/view/mountedScene.js +79 -76
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +37 -2
- package/dist/engine/EngineCore.js +946 -768
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +172 -186
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +109 -84
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +126 -101
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +48 -29
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +98 -78
- package/dist/engine/core/cameraMove.d.ts +6 -0
- package/dist/engine/core/cameraMove.js +56 -38
- package/dist/engine/core/defaults.js +51 -90
- package/dist/engine/core/freehand.js +163 -147
- package/dist/engine/core/geometry.js +54 -47
- package/dist/engine/core/history.js +55 -38
- package/dist/engine/core/hitTest.js +81 -68
- package/dist/engine/core/matrix.js +20 -18
- package/dist/engine/core/pathData.js +210 -183
- package/dist/engine/core/rotationReset.js +6 -5
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +288 -139
- package/dist/engine/core/scribble.js +84 -59
- package/dist/engine/core/shapePaths.js +15 -12
- package/dist/engine/core/shapeTools.js +63 -72
- package/dist/engine/core/snapping.js +117 -65
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +82 -33
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +103 -83
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +547 -476
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +340 -266
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +131 -32
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +25 -4
- package/dist/engine/text/layoutText.js +62 -43
- package/dist/engine/text/textMetrics.js +10 -8
- package/dist/engine/widgets.js +137 -101
- package/dist/fonts/interFont.js +83 -30
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +108 -34
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +7 -1
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +30 -26
- package/dist/index.d.ts +1 -0
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +140 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +251 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +112 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +138 -0
- package/dist/settings/workspaceToolSettings.d.ts +6 -0
- package/dist/settings/workspaceToolSettings.js +58 -34
- package/dist/tools/components/catalog.js +74 -64
- package/dist/tools/components/grouping.js +28 -6
- package/dist/tools/definitions.js +31 -9
- package/dist/tools/executors.js +214 -106
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +15 -11
- package/dist/tools/sceneSummary.js +57 -43
- package/dist/tools/sketchIntent.js +21 -13
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +93 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +2 -1
- package/package.json +1 -1
|
@@ -1,3 +1,62 @@
|
|
|
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;
|
|
1
60
|
/**
|
|
2
61
|
* Reading the pictures that a saved board only points at, when the board is opened.
|
|
3
62
|
*
|
|
@@ -21,18 +80,19 @@
|
|
|
21
80
|
import { rectsIntersect } from '../../engine/core/geometry.js';
|
|
22
81
|
import { shapeVisualBounds } from '../../engine/core/scene.js';
|
|
23
82
|
/** How many pictures are asked of the store at the same time. */
|
|
24
|
-
export
|
|
83
|
+
export var PICTURE_LOAD_CONCURRENCY = 6;
|
|
25
84
|
/** 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). */
|
|
26
|
-
export
|
|
85
|
+
export var PICTURE_APPLY_DELAY_MS = 40;
|
|
27
86
|
/**
|
|
28
87
|
* 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
|
|
29
88
|
* store and the network are the on-screen pictures' alone; one that hangs must not hold back the rest of the board for ever.
|
|
30
89
|
*/
|
|
31
|
-
export
|
|
90
|
+
export var PICTURE_BACKGROUND_GRACE_MS = 3000;
|
|
32
91
|
/** The objects of a scene that point at a picture and do not hold its bytes, in the order of the scene. */
|
|
33
92
|
export function picturesStillMissing(scene) {
|
|
34
|
-
|
|
35
|
-
for (
|
|
93
|
+
var missing = [];
|
|
94
|
+
for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
|
|
95
|
+
var object = scene_1[_i];
|
|
36
96
|
if (object.type === 'image' && !object.src && object.imageRef) {
|
|
37
97
|
missing.push({ objectId: object.id, reference: object.imageRef, bounds: shapeVisualBounds(object) });
|
|
38
98
|
}
|
|
@@ -50,18 +110,18 @@ export function picturesStillMissing(scene) {
|
|
|
50
110
|
export function fillPictures(scene, loaded) {
|
|
51
111
|
if (loaded.size === 0)
|
|
52
112
|
return scene;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
113
|
+
var changed = false;
|
|
114
|
+
var filled = scene.map(function (object) {
|
|
115
|
+
var picture = loaded.get(object.id);
|
|
56
116
|
if (!picture)
|
|
57
117
|
return object;
|
|
58
118
|
if (object.type === 'image' && !object.src && object.imageRef === picture.reference) {
|
|
59
119
|
changed = true;
|
|
60
|
-
return {
|
|
120
|
+
return __assign(__assign({}, object), { src: picture.dataUrl });
|
|
61
121
|
}
|
|
62
122
|
if (object.type === 'widget' && !object.thumbnail && object.thumbnailRef === picture.reference) {
|
|
63
123
|
changed = true;
|
|
64
|
-
return {
|
|
124
|
+
return __assign(__assign({}, object), { thumbnail: picture.dataUrl });
|
|
65
125
|
}
|
|
66
126
|
return object;
|
|
67
127
|
});
|
|
@@ -71,18 +131,29 @@ export function fillPictures(scene, loaded) {
|
|
|
71
131
|
* Waits for a promise for at most `milliseconds`. True when it finished in time, false when the time ran out first (the promise is
|
|
72
132
|
* 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.
|
|
73
133
|
*/
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
134
|
+
export function waitUpTo(promise, milliseconds) {
|
|
135
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
136
|
+
var timeRanOut, timeUp, timer;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
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
|
+
});
|
|
78
156
|
});
|
|
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
|
-
}
|
|
86
157
|
}
|
|
87
158
|
/** A rectangle made of finite numbers with some size: anything else says the board has no size (or no view) yet. */
|
|
88
159
|
export function isUsableView(view) {
|
|
@@ -92,8 +163,9 @@ export function isUsableView(view) {
|
|
|
92
163
|
export function countPicturesInView(missing, view) {
|
|
93
164
|
if (!isUsableView(view))
|
|
94
165
|
return missing.length;
|
|
95
|
-
|
|
96
|
-
for (
|
|
166
|
+
var count = 0;
|
|
167
|
+
for (var _i = 0, missing_1 = missing; _i < missing_1.length; _i++) {
|
|
168
|
+
var picture = missing_1[_i];
|
|
97
169
|
if (rectsIntersect(view, picture.bounds))
|
|
98
170
|
count += 1;
|
|
99
171
|
}
|
|
@@ -105,87 +177,100 @@ export function countPicturesInView(missing, view) {
|
|
|
105
177
|
* 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
|
|
106
178
|
* when the view is not known.
|
|
107
179
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return this.#waiting.length;
|
|
180
|
+
var PictureQueue = /** @class */ (function () {
|
|
181
|
+
function PictureQueue(missing) {
|
|
182
|
+
_PictureQueue_instances.add(this);
|
|
183
|
+
// Kept with the best one last, so that handing it out is a `pop`.
|
|
184
|
+
_PictureQueue_waiting.set(this, void 0);
|
|
185
|
+
// Where each picture was in the scene: what breaks a tie, and what a picture that is given back keeps.
|
|
186
|
+
_PictureQueue_positions.set(this, new Map());
|
|
187
|
+
_PictureQueue_orderedFor.set(this, null);
|
|
188
|
+
__classPrivateFieldSet(this, _PictureQueue_waiting, missing.map(function (picture, position) { return ({ picture: picture, position: position }); }).reverse(), "f");
|
|
189
|
+
for (var _i = 0, _a = __classPrivateFieldGet(this, _PictureQueue_waiting, "f"); _i < _a.length; _i++) {
|
|
190
|
+
var _b = _a[_i], picture = _b.picture, position = _b.position;
|
|
191
|
+
__classPrivateFieldGet(this, _PictureQueue_positions, "f").set(picture, position);
|
|
192
|
+
}
|
|
122
193
|
}
|
|
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
|
+
});
|
|
123
202
|
/** The picture to ask for next, or undefined when none is left. */
|
|
124
|
-
take(view) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
203
|
+
PictureQueue.prototype.take = function (view) {
|
|
204
|
+
var _a;
|
|
205
|
+
if (isUsableView(view) && __classPrivateFieldGet(this, _PictureQueue_instances, "m", _PictureQueue_needsOrderingFor).call(this, view))
|
|
206
|
+
__classPrivateFieldGet(this, _PictureQueue_instances, "m", _PictureQueue_orderFor).call(this, view);
|
|
207
|
+
return (_a = __classPrivateFieldGet(this, _PictureQueue_waiting, "f").pop()) === null || _a === void 0 ? void 0 : _a.picture;
|
|
208
|
+
};
|
|
129
209
|
/** 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). */
|
|
130
|
-
giveBack(picture) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
210
|
+
PictureQueue.prototype.giveBack = function (picture) {
|
|
211
|
+
var _a;
|
|
212
|
+
__classPrivateFieldGet(this, _PictureQueue_waiting, "f").push({ picture: picture, position: (_a = __classPrivateFieldGet(this, _PictureQueue_positions, "f").get(picture)) !== null && _a !== void 0 ? _a : 0 });
|
|
213
|
+
};
|
|
214
|
+
return PictureQueue;
|
|
215
|
+
}());
|
|
216
|
+
export { PictureQueue };
|
|
217
|
+
_PictureQueue_waiting = new WeakMap(), _PictureQueue_positions = new WeakMap(), _PictureQueue_orderedFor = new WeakMap(), _PictureQueue_instances = new WeakSet(), _PictureQueue_needsOrderingFor = function _PictureQueue_needsOrderingFor(view) {
|
|
218
|
+
var last = __classPrivateFieldGet(this, _PictureQueue_orderedFor, "f");
|
|
219
|
+
if (last === null)
|
|
220
|
+
return true;
|
|
221
|
+
return (Math.abs(view.x - last.x) > last.width * 0.25 ||
|
|
222
|
+
Math.abs(view.y - last.y) > last.height * 0.25 ||
|
|
223
|
+
view.width > last.width * 1.25 ||
|
|
224
|
+
view.width < last.width * 0.8);
|
|
225
|
+
}, _PictureQueue_orderFor = function _PictureQueue_orderFor(view) {
|
|
226
|
+
__classPrivateFieldSet(this, _PictureQueue_orderedFor, view, "f");
|
|
227
|
+
var middleX = view.x + view.width / 2;
|
|
228
|
+
var middleY = view.y + view.height / 2;
|
|
229
|
+
// Squared distances stay far below this, so adding it puts every picture that is off the view after every one that is on it.
|
|
230
|
+
var OFF_THE_VIEW = 1e18;
|
|
231
|
+
var ranked = __classPrivateFieldGet(this, _PictureQueue_waiting, "f").map(function (entry) {
|
|
232
|
+
var bounds = entry.picture.bounds;
|
|
233
|
+
var offsetX = bounds.x + bounds.width / 2 - middleX;
|
|
234
|
+
var offsetY = bounds.y + bounds.height / 2 - middleY;
|
|
235
|
+
return { entry: entry, rank: (rectsIntersect(view, bounds) ? 0 : OFF_THE_VIEW) + offsetX * offsetX + offsetY * offsetY };
|
|
236
|
+
});
|
|
237
|
+
// 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.
|
|
238
|
+
ranked.sort(function (first, second) { return second.rank - first.rank || second.entry.position - first.entry.position; });
|
|
239
|
+
__classPrivateFieldSet(this, _PictureQueue_waiting, ranked.map(function (item) { return item.entry; }), "f");
|
|
240
|
+
};
|
|
159
241
|
/**
|
|
160
242
|
* 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
|
|
161
243
|
* in small batches. Never throws: a picture the store cannot give is a warning, and the others go on.
|
|
162
244
|
*/
|
|
163
245
|
export function startLoadingPictures(plan) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
246
|
+
var _a, _b, _c;
|
|
247
|
+
var concurrency = Math.max(1, (_a = plan.concurrency) !== null && _a !== void 0 ? _a : PICTURE_LOAD_CONCURRENCY);
|
|
248
|
+
var applyDelayMs = (_b = plan.applyDelayMs) !== null && _b !== void 0 ? _b : PICTURE_APPLY_DELAY_MS;
|
|
249
|
+
var backgroundGraceMs = (_c = plan.backgroundGraceMs) !== null && _c !== void 0 ? _c : PICTURE_BACKGROUND_GRACE_MS;
|
|
250
|
+
var queue = new PictureQueue(plan.missing);
|
|
251
|
+
var arrived = new Map();
|
|
252
|
+
var requests = new Map();
|
|
253
|
+
var failedReferences = new Set();
|
|
254
|
+
var applyTimer = null;
|
|
255
|
+
var boardOpened = false;
|
|
256
|
+
var finishFirstScreenful = function () { return undefined; };
|
|
257
|
+
var firstScreenful = new Promise(function (resolve) {
|
|
175
258
|
finishFirstScreenful = resolve;
|
|
176
259
|
});
|
|
177
260
|
// 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
|
|
178
261
|
// object that is not on screen until those are answered (or until `letBackgroundStart`).
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
262
|
+
var onScreenInFlight = 0;
|
|
263
|
+
var backgroundMayStart = false;
|
|
264
|
+
var workersHeldBack = [];
|
|
265
|
+
var graceTimer = null;
|
|
183
266
|
function letBackgroundStart() {
|
|
184
267
|
backgroundMayStart = true;
|
|
185
|
-
|
|
268
|
+
var held = workersHeldBack;
|
|
186
269
|
workersHeldBack = [];
|
|
187
|
-
for (
|
|
270
|
+
for (var _i = 0, held_1 = held; _i < held_1.length; _i++) {
|
|
271
|
+
var release = held_1[_i];
|
|
188
272
|
release();
|
|
273
|
+
}
|
|
189
274
|
}
|
|
190
275
|
function putArrivedOnTheBoard() {
|
|
191
276
|
if (applyTimer !== null) {
|
|
@@ -194,7 +279,7 @@ export function startLoadingPictures(plan) {
|
|
|
194
279
|
}
|
|
195
280
|
if (arrived.size === 0)
|
|
196
281
|
return;
|
|
197
|
-
|
|
282
|
+
var batch = new Map(arrived);
|
|
198
283
|
arrived.clear();
|
|
199
284
|
if (plan.isCancelled())
|
|
200
285
|
return;
|
|
@@ -214,69 +299,78 @@ export function startLoadingPictures(plan) {
|
|
|
214
299
|
finishFirstScreenful();
|
|
215
300
|
letBackgroundStart();
|
|
216
301
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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)
|
|
302
|
+
function work() {
|
|
303
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
304
|
+
var view, picture, onScreen, request, dataUrl, error_1;
|
|
305
|
+
return __generator(this, function (_a) {
|
|
306
|
+
switch (_a.label) {
|
|
307
|
+
case 0:
|
|
308
|
+
if (plan.isCancelled())
|
|
309
|
+
return [2 /*return*/];
|
|
310
|
+
view = plan.currentView();
|
|
311
|
+
picture = queue.take(view);
|
|
312
|
+
if (!picture)
|
|
313
|
+
return [2 /*return*/];
|
|
314
|
+
onScreen = !isUsableView(view) || rectsIntersect(view, picture.bounds);
|
|
315
|
+
if (!!onScreen) return [3 /*break*/, 4];
|
|
316
|
+
if (!(onScreenInFlight === 0)) return [3 /*break*/, 1];
|
|
270
317
|
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*/];
|
|
271
365
|
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
366
|
+
});
|
|
367
|
+
});
|
|
274
368
|
}
|
|
275
|
-
|
|
276
|
-
|
|
369
|
+
var workerCount = Math.min(concurrency, plan.missing.length);
|
|
370
|
+
var everything = Promise.all(Array.from({ length: workerCount }, function () { return work(); }))
|
|
277
371
|
// Nothing above throws, but a board that is opened must never be left waiting for a promise that fails.
|
|
278
|
-
.catch((error)
|
|
279
|
-
.then(()
|
|
372
|
+
.catch(function (error) { return plan.warn('Canvas: reading the stored pictures stopped early', error); })
|
|
373
|
+
.then(function () {
|
|
280
374
|
if (graceTimer !== null)
|
|
281
375
|
clearTimeout(graceTimer);
|
|
282
376
|
// What is still waiting for its batch goes on the board now, and nothing is left to wait for: everything is answered (or the
|
|
@@ -284,5 +378,5 @@ export function startLoadingPictures(plan) {
|
|
|
284
378
|
putArrivedOnTheBoard();
|
|
285
379
|
openTheBoard();
|
|
286
380
|
});
|
|
287
|
-
return { firstScreenful, everything };
|
|
381
|
+
return { firstScreenful: firstScreenful, everything: everything };
|
|
288
382
|
}
|