@widgetic/canvas 0.5.45 → 0.5.47
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 +3 -2
- package/dist/canvas/DomCanvas.svelte +1 -2
- 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 -5
- package/dist/canvas/host/CanvasHost.js +1664 -1861
- 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/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- 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/CanvasContextMenu.svelte +40 -3
- package/dist/canvas/ui/CanvasHint.svelte +10 -9
- package/dist/canvas/ui/SelectionPanel.svelte +14 -12
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
- package/dist/canvas/ui/ShapesMenu.svelte +6 -4
- package/dist/canvas/ui/ToolButton.svelte +7 -6
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +48 -28
- 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.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +44 -58
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +2 -2
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +72 -91
- 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/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +42 -10
- package/dist/engine/EngineCore.js +843 -916
- 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.d.ts +24 -0
- package/dist/engine/core/brush.js +223 -103
- 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.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +104 -67
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +79 -80
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- 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.d.ts +8 -3
- package/dist/engine/input/gestures.js +378 -346
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +42 -41
- 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.d.ts +4 -1
- package/dist/poster/boardPlacement.js +34 -33
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +25 -0
- package/dist/settings/workspaceToolSettings.js +38 -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 +10 -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 +5 -5
|
@@ -19,26 +19,6 @@
|
|
|
19
19
|
*
|
|
20
20
|
* Nothing here touches the DOM or the page, so it runs in Node tests.
|
|
21
21
|
*/
|
|
22
|
-
var __assign = (this && this.__assign) || function () {
|
|
23
|
-
__assign = Object.assign || function(t) {
|
|
24
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
25
|
-
s = arguments[i];
|
|
26
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
27
|
-
t[p] = s[p];
|
|
28
|
-
}
|
|
29
|
-
return t;
|
|
30
|
-
};
|
|
31
|
-
return __assign.apply(this, arguments);
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
22
|
import { parseCanvasDocument } from '../engine/codec/canvasDocument.js';
|
|
43
23
|
import { HOST_READABLE_KEYS } from '../engine/codec/hostReadableKeys.js';
|
|
44
24
|
import { brushReach, brushSizeFor } from '../engine/core/freehand.js';
|
|
@@ -46,30 +26,30 @@ import { inflateRect, rectCenter, rectsIntersect, rotatedBoxBounds } from '../en
|
|
|
46
26
|
import { CANVAS_DOCUMENT_VERSION, isBoxedObject } from '../engine/core/types.js';
|
|
47
27
|
import { sanitizeViewport, visibleWorldRect } from '../engine/core/viewport.js';
|
|
48
28
|
/** The version of the poster's own format: a poster of another version is not read (the next visit makes a new one). */
|
|
49
|
-
export
|
|
29
|
+
export const BOARD_POSTER_VERSION = 1;
|
|
50
30
|
/**
|
|
51
31
|
* The kind a page keeps the poster under in its cache (the canvas id is the key). The creator, which writes it, and the page that
|
|
52
32
|
* reads it before the creator is there agree on this one name, so it lives with the format.
|
|
53
33
|
*/
|
|
54
|
-
export
|
|
34
|
+
export const BOARD_POSTER_STORAGE_KIND = 'canvasBoardPoster';
|
|
55
35
|
/** The size of the screen the saved view is taken to have when the page does not say (a large window). */
|
|
56
|
-
export
|
|
36
|
+
export const DEFAULT_POSTER_SURFACE = Object.freeze({ width: 1600, height: 1000 });
|
|
57
37
|
/** The most objects a poster holds; a board with more keeps the ones nearest the middle of the view. */
|
|
58
|
-
export
|
|
38
|
+
export const POSTER_MAX_OBJECTS = 400;
|
|
59
39
|
/** The most bytes of saved text a poster holds (what is kept next to the page stays small, and reading it stays fast). */
|
|
60
|
-
export
|
|
40
|
+
export const POSTER_MAX_BYTES = 240_000;
|
|
61
41
|
/** Inline picture bytes longer than this are left out of the poster (the picture appears with the board). */
|
|
62
|
-
export
|
|
42
|
+
export const POSTER_MAX_INLINE_PICTURE = 24_000;
|
|
63
43
|
/** Screen pixels kept around the saved view on every side, so a small pan, or a larger window than last time, still has its objects. */
|
|
64
|
-
export
|
|
44
|
+
export const POSTER_MARGIN = 160;
|
|
65
45
|
/** The most records `parseBoardPoster` reads, whatever a poster says it holds. */
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
46
|
+
const POSTER_READ_LIMIT = 2_000;
|
|
47
|
+
const MIN_SURFACE_SIDE = 200;
|
|
48
|
+
const MAX_SURFACE_SIDE = 8_000;
|
|
69
49
|
/** The kinds of object a poster draws (a group has no look of its own). */
|
|
70
|
-
|
|
50
|
+
const DRAWN_TYPES = new Set(['rect', 'ellipse', 'path', 'text', 'image', 'widget']);
|
|
71
51
|
/** The keys that may hold the bytes of a picture inline. */
|
|
72
|
-
|
|
52
|
+
const INLINE_PICTURE_KEYS = ['src', 'thumbnail'];
|
|
73
53
|
function isRecord(value) {
|
|
74
54
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
75
55
|
}
|
|
@@ -85,16 +65,16 @@ function readJson(source) {
|
|
|
85
65
|
try {
|
|
86
66
|
return JSON.parse(source);
|
|
87
67
|
}
|
|
88
|
-
catch
|
|
68
|
+
catch {
|
|
89
69
|
return null;
|
|
90
70
|
}
|
|
91
71
|
}
|
|
92
72
|
/** A surface the page named, kept to sizes a board can have; the default when it named none or nonsense. */
|
|
93
73
|
export function sanitizeSurface(value) {
|
|
94
74
|
if (!isRecord(value))
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
75
|
+
return { ...DEFAULT_POSTER_SURFACE };
|
|
76
|
+
const width = finiteNumber(value.width, DEFAULT_POSTER_SURFACE.width);
|
|
77
|
+
const height = finiteNumber(value.height, DEFAULT_POSTER_SURFACE.height);
|
|
98
78
|
return {
|
|
99
79
|
width: Math.min(MAX_SURFACE_SIDE, Math.max(MIN_SURFACE_SIDE, Math.round(width))),
|
|
100
80
|
height: Math.min(MAX_SURFACE_SIDE, Math.max(MIN_SURFACE_SIDE, Math.round(height)))
|
|
@@ -102,13 +82,12 @@ export function sanitizeSurface(value) {
|
|
|
102
82
|
}
|
|
103
83
|
/** A saved record without the picture bytes that are too long to keep (the same record when it has none). */
|
|
104
84
|
function withoutLongPictures(record) {
|
|
105
|
-
|
|
106
|
-
for (
|
|
107
|
-
|
|
108
|
-
var value = record[key];
|
|
85
|
+
let result = record;
|
|
86
|
+
for (const key of INLINE_PICTURE_KEYS) {
|
|
87
|
+
const value = record[key];
|
|
109
88
|
if (typeof value === 'string' && value.startsWith('data:') && value.length > POSTER_MAX_INLINE_PICTURE) {
|
|
110
89
|
if (result === record)
|
|
111
|
-
result =
|
|
90
|
+
result = { ...record };
|
|
112
91
|
delete result[key];
|
|
113
92
|
}
|
|
114
93
|
}
|
|
@@ -119,10 +98,10 @@ function withoutLongPictures(record) {
|
|
|
119
98
|
* room for its line and for a turn. Generous on purpose: it only decides what is kept, and the poster is drawn clipped anyway.
|
|
120
99
|
*/
|
|
121
100
|
function roughBoundsOf(record) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
101
|
+
const strokeWidth = Math.min(200, Math.max(0, finiteNumber(record.strokeWidth, 3)));
|
|
102
|
+
const isBrush = isRecord(record.ink);
|
|
103
|
+
const reach = isBrush ? brushReach(brushSizeFor(strokeWidth)) : strokeWidth * Math.SQRT1_2 + 1;
|
|
104
|
+
const box = {
|
|
126
105
|
x: finiteNumber(record.x, 0),
|
|
127
106
|
y: finiteNumber(record.y, 0),
|
|
128
107
|
width: Math.max(1, finiteNumber(record.width, 100)),
|
|
@@ -135,76 +114,73 @@ function roughBoundsOf(record) {
|
|
|
135
114
|
* The poster of a saved board: the records that touch the view it was saved at, or null when there is nothing to show (a text that
|
|
136
115
|
* is not a saved board, an empty board, nothing in view). `source` is the saved text, or the same thing already parsed.
|
|
137
116
|
*/
|
|
138
|
-
export function createBoardPoster(source, options) {
|
|
139
|
-
|
|
140
|
-
var savedDocument = readJson(source);
|
|
117
|
+
export function createBoardPoster(source, options = {}) {
|
|
118
|
+
const savedDocument = readJson(source);
|
|
141
119
|
if (!isRecord(savedDocument) || savedDocument.version !== CANVAS_DOCUMENT_VERSION)
|
|
142
120
|
return null;
|
|
143
|
-
|
|
144
|
-
|
|
121
|
+
const canvas = savedDocument.canvas;
|
|
122
|
+
const list = isRecord(canvas) && Array.isArray(canvas.objects) ? canvas.objects : [];
|
|
145
123
|
if (list.length === 0)
|
|
146
124
|
return null;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
125
|
+
const viewport = sanitizeViewport(savedDocument.viewport);
|
|
126
|
+
const surface = sanitizeSurface(options.surface);
|
|
127
|
+
const maxObjects = Math.max(1, Math.min(POSTER_MAX_OBJECTS, Math.floor(finiteNumber(options.maxObjects, POSTER_MAX_OBJECTS))));
|
|
128
|
+
const maxBytes = Math.max(1_000, Math.min(POSTER_MAX_BYTES, Math.floor(finiteNumber(options.maxBytes, POSTER_MAX_BYTES))));
|
|
151
129
|
// What the saved view showed, with room around it, in world units.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
for (
|
|
156
|
-
|
|
130
|
+
const keptArea = inflateRect(visibleWorldRect(viewport, surface), POSTER_MARGIN / viewport.zoom);
|
|
131
|
+
const middle = rectCenter(keptArea);
|
|
132
|
+
const candidates = [];
|
|
133
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
134
|
+
const raw = list[index];
|
|
157
135
|
if (!isRecord(raw))
|
|
158
136
|
continue;
|
|
159
|
-
|
|
137
|
+
const type = raw[HOST_READABLE_KEYS.objectType];
|
|
160
138
|
if (typeof type !== 'string' || !DRAWN_TYPES.has(type))
|
|
161
139
|
continue;
|
|
162
140
|
// The reader treats these as "not there"; so does the poster.
|
|
163
141
|
if (raw[HOST_READABLE_KEYS.visible] === false || raw[HOST_READABLE_KEYS.excludeFromExport] === true)
|
|
164
142
|
continue;
|
|
165
|
-
|
|
143
|
+
const bounds = roughBoundsOf(raw);
|
|
166
144
|
if (!rectsIntersect(bounds, keptArea))
|
|
167
145
|
continue;
|
|
168
|
-
|
|
169
|
-
|
|
146
|
+
const record = withoutLongPictures(raw);
|
|
147
|
+
let bytes = 0;
|
|
170
148
|
try {
|
|
171
149
|
bytes = JSON.stringify(record).length;
|
|
172
150
|
}
|
|
173
|
-
catch
|
|
151
|
+
catch {
|
|
174
152
|
// A record that cannot be written down cannot be kept.
|
|
175
153
|
continue;
|
|
176
154
|
}
|
|
177
|
-
|
|
178
|
-
candidates.push({ index
|
|
155
|
+
const center = rectCenter(bounds);
|
|
156
|
+
candidates.push({ index, record, bytes, distance: (center.x - middle.x) ** 2 + (center.y - middle.y) ** 2 });
|
|
179
157
|
}
|
|
180
158
|
if (candidates.length === 0)
|
|
181
159
|
return null;
|
|
182
|
-
|
|
183
|
-
|
|
160
|
+
let kept = candidates;
|
|
161
|
+
const totalBytes = candidates.reduce((total, candidate) => total + candidate.bytes, 0);
|
|
184
162
|
if (candidates.length > maxObjects || totalBytes > maxBytes) {
|
|
185
163
|
// Too much for a poster: keep what is nearest the middle of the view, as long as it fits, and put it back in z-order.
|
|
186
|
-
|
|
164
|
+
const byDistance = [...candidates].sort((first, second) => first.distance - second.distance);
|
|
187
165
|
kept = [];
|
|
188
|
-
|
|
189
|
-
for (
|
|
190
|
-
var candidate = byDistance_1[_i];
|
|
166
|
+
let usedBytes = 0;
|
|
167
|
+
for (const candidate of byDistance) {
|
|
191
168
|
if (kept.length >= maxObjects || usedBytes + candidate.bytes > maxBytes)
|
|
192
169
|
continue;
|
|
193
170
|
kept.push(candidate);
|
|
194
171
|
usedBytes += candidate.bytes;
|
|
195
172
|
}
|
|
196
|
-
kept.sort(
|
|
173
|
+
kept.sort((first, second) => first.index - second.index);
|
|
197
174
|
if (kept.length === 0)
|
|
198
175
|
return null;
|
|
199
176
|
}
|
|
200
|
-
return { version: BOARD_POSTER_VERSION, viewport
|
|
177
|
+
return { version: BOARD_POSTER_VERSION, viewport, surface, objects: kept.map((candidate) => candidate.record) };
|
|
201
178
|
}
|
|
202
179
|
/** The address a picture is drawn from: its own, or the library's when the board's own is gone (an object URL does not outlive a page). */
|
|
203
180
|
function pictureAddressOf(shape) {
|
|
204
|
-
var _a;
|
|
205
181
|
if (shape.src && !shape.src.startsWith('blob:'))
|
|
206
182
|
return shape.src;
|
|
207
|
-
return
|
|
183
|
+
return shape.libraryFileUrl ?? null;
|
|
208
184
|
}
|
|
209
185
|
/**
|
|
210
186
|
* A poster read back from whatever a page kept. Null when it is not a poster of this version or holds nothing that can be drawn.
|
|
@@ -215,23 +191,22 @@ export function parseBoardPoster(value) {
|
|
|
215
191
|
return null;
|
|
216
192
|
if (!Array.isArray(value.objects) || value.objects.length === 0 || value.objects.length > POSTER_READ_LIMIT)
|
|
217
193
|
return null;
|
|
218
|
-
|
|
194
|
+
const parsed = parseCanvasDocument({
|
|
219
195
|
version: CANVAS_DOCUMENT_VERSION,
|
|
220
196
|
viewport: value.viewport,
|
|
221
197
|
canvas: { objects: value.objects }
|
|
222
198
|
});
|
|
223
199
|
if (parsed.status !== 'ok')
|
|
224
200
|
return null;
|
|
225
|
-
|
|
226
|
-
for (
|
|
227
|
-
var object = _a[_i];
|
|
201
|
+
const shapes = [];
|
|
202
|
+
for (const object of parsed.scene) {
|
|
228
203
|
if (!isBoxedObject(object))
|
|
229
204
|
continue;
|
|
230
|
-
shapes.push(object.type === 'image' ?
|
|
205
|
+
shapes.push(object.type === 'image' ? { ...object, src: pictureAddressOf(object) } : object);
|
|
231
206
|
}
|
|
232
207
|
if (shapes.length === 0)
|
|
233
208
|
return null;
|
|
234
|
-
return { viewport: parsed.viewport, surface: sanitizeSurface(value.surface), shapes
|
|
209
|
+
return { viewport: parsed.viewport, surface: sanitizeSurface(value.surface), shapes };
|
|
235
210
|
}
|
|
236
211
|
/**
|
|
237
212
|
* Whether two posters are the same, for a page that keeps the latest and writes only what changed. Compares what would be written,
|
|
@@ -245,7 +220,7 @@ export function boardPostersMatch(first, second) {
|
|
|
245
220
|
try {
|
|
246
221
|
return JSON.stringify(first) === JSON.stringify(second);
|
|
247
222
|
}
|
|
248
|
-
catch
|
|
223
|
+
catch {
|
|
249
224
|
return false;
|
|
250
225
|
}
|
|
251
226
|
}
|
|
@@ -7,26 +7,6 @@
|
|
|
7
7
|
* `window`: the context and the services are handed in, so the drawing order and the geometry are tested in Node with a recording
|
|
8
8
|
* context.
|
|
9
9
|
*/
|
|
10
|
-
var __assign = (this && this.__assign) || function () {
|
|
11
|
-
__assign = Object.assign || function(t) {
|
|
12
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
13
|
-
s = arguments[i];
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
}
|
|
17
|
-
return t;
|
|
18
|
-
};
|
|
19
|
-
return __assign.apply(this, arguments);
|
|
20
|
-
};
|
|
21
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
22
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
23
|
-
if (ar || !(i in from)) {
|
|
24
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
25
|
-
ar[i] = from[i];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
29
|
-
};
|
|
30
10
|
import { inflateRect, rectsIntersect } from '../engine/core/geometry.js';
|
|
31
11
|
import { shapeVisualBounds } from '../engine/core/scene.js';
|
|
32
12
|
import { visibleWorldRect } from '../engine/core/viewport.js';
|
|
@@ -34,7 +14,7 @@ import { imageSourcesOf, paintShape } from '../engine/render/rasterize.js';
|
|
|
34
14
|
import { createFixedAdvanceMeasure } from '../engine/text/layoutText.js';
|
|
35
15
|
import { posterReferenceKey } from './posterPictures.js';
|
|
36
16
|
/** Screen pixels around the area that still get painted, so a stroke that starts just outside it has its edge. */
|
|
37
|
-
|
|
17
|
+
const PAINT_MARGIN = 64;
|
|
38
18
|
/** The addresses of the pictures a poster needs (its images, and the screenshots of its widget cards). */
|
|
39
19
|
export function posterPictureSources(poster) {
|
|
40
20
|
return imageSourcesOf(poster.shapes);
|
|
@@ -44,34 +24,33 @@ export function posterPictureSources(poster) {
|
|
|
44
24
|
* screenshot of a widget card): they have no address in the saved text, only the reference the host knows them by. Once each.
|
|
45
25
|
*/
|
|
46
26
|
export function posterPictureReferences(poster) {
|
|
47
|
-
|
|
48
|
-
for (
|
|
49
|
-
var shape = _a[_i];
|
|
27
|
+
const references = new Set();
|
|
28
|
+
for (const shape of poster.shapes) {
|
|
50
29
|
if (shape.type === 'image' && !shape.src && shape.imageRef)
|
|
51
30
|
references.add(shape.imageRef);
|
|
52
31
|
if (shape.type === 'widget' && !shape.thumbnail && shape.thumbnailRef)
|
|
53
32
|
references.add(shape.thumbnailRef);
|
|
54
33
|
}
|
|
55
|
-
return
|
|
34
|
+
return [...references];
|
|
56
35
|
}
|
|
57
36
|
/**
|
|
58
37
|
* The poster with each picture that is kept by reference named by its key (`posterReferenceKey`), which is what the painter asks
|
|
59
38
|
* the loaded pictures for. The same poster when there is none. A picture that has an address keeps it.
|
|
60
39
|
*/
|
|
61
40
|
export function withReferencedPictures(poster) {
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
let changed = false;
|
|
42
|
+
const shapes = poster.shapes.map((shape) => {
|
|
64
43
|
if (shape.type === 'image' && !shape.src && shape.imageRef) {
|
|
65
44
|
changed = true;
|
|
66
|
-
return
|
|
45
|
+
return { ...shape, src: posterReferenceKey(shape.imageRef) };
|
|
67
46
|
}
|
|
68
47
|
if (shape.type === 'widget' && !shape.thumbnail && shape.thumbnailRef) {
|
|
69
48
|
changed = true;
|
|
70
|
-
return
|
|
49
|
+
return { ...shape, thumbnail: posterReferenceKey(shape.thumbnailRef) };
|
|
71
50
|
}
|
|
72
51
|
return shape;
|
|
73
52
|
});
|
|
74
|
-
return changed ?
|
|
53
|
+
return changed ? { ...poster, shapes } : poster;
|
|
75
54
|
}
|
|
76
55
|
/**
|
|
77
56
|
* Paints the poster: clears the area, sets the saved view, and draws the shapes that touch the area, bottom first. A shape that
|
|
@@ -79,34 +58,32 @@ export function withReferencedPictures(poster) {
|
|
|
79
58
|
* handed over, and the painter draws nothing of it).
|
|
80
59
|
*/
|
|
81
60
|
export function paintBoardPoster(context, poster, target, dependencies) {
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
const pixelRatio = target.pixelRatio > 0 ? target.pixelRatio : 1;
|
|
62
|
+
const { viewport } = poster;
|
|
84
63
|
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
85
64
|
context.clearRect(0, 0, Math.ceil(target.width * pixelRatio), Math.ceil(target.height * pixelRatio));
|
|
86
65
|
// World units to device pixels: the view of the saved board, scaled by the screen's density.
|
|
87
66
|
context.setTransform(pixelRatio * viewport.zoom, 0, 0, pixelRatio * viewport.zoom, pixelRatio * viewport.x, pixelRatio * viewport.y);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (
|
|
91
|
-
var shape = _a[_i];
|
|
67
|
+
const painted = inflateRect(visibleWorldRect(viewport, target), PAINT_MARGIN / viewport.zoom);
|
|
68
|
+
let count = 0;
|
|
69
|
+
for (const shape of poster.shapes) {
|
|
92
70
|
try {
|
|
93
71
|
if (!rectsIntersect(shapeVisualBounds(shape), painted))
|
|
94
72
|
continue;
|
|
95
73
|
paintShape(context, shape, dependencies);
|
|
96
74
|
count += 1;
|
|
97
75
|
}
|
|
98
|
-
catch
|
|
76
|
+
catch {
|
|
99
77
|
// One shape that cannot be drawn must not take the poster with it.
|
|
100
78
|
}
|
|
101
79
|
}
|
|
102
80
|
return count;
|
|
103
81
|
}
|
|
104
82
|
export function posterPaintDependencies(services) {
|
|
105
|
-
var _a;
|
|
106
83
|
return {
|
|
107
84
|
createPath: services.createPath,
|
|
108
85
|
imageFor: services.pictureFor,
|
|
109
|
-
measureText:
|
|
86
|
+
measureText: services.measureText ?? createFixedAdvanceMeasure(),
|
|
110
87
|
widgetFallbackName: ''
|
|
111
88
|
};
|
|
112
89
|
}
|
|
@@ -9,36 +9,26 @@
|
|
|
9
9
|
* The painter asks for a picture by a key. For a picture with an address the key is the address; for one kept by reference it is
|
|
10
10
|
* `posterReferenceKey(reference)`, so the bytes the host hands over (a data URL, possibly megabytes) are never a map key.
|
|
11
11
|
*/
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
12
|
/** What the page has loaded, by key. */
|
|
22
|
-
|
|
13
|
+
const loadedPictures = new Map();
|
|
23
14
|
/** What has been asked for already, loaded or not, so one picture is never fetched twice. */
|
|
24
|
-
|
|
15
|
+
const askedFor = new Set();
|
|
25
16
|
/** Who wants to know when a picture arrives: every poster that is on the screen. */
|
|
26
|
-
|
|
17
|
+
const listeners = new Set();
|
|
27
18
|
/** The most pictures kept; the oldest go first. A poster holds few, so this is a ceiling, not a working size. */
|
|
28
|
-
|
|
19
|
+
const MAX_KEPT_PICTURES = 64;
|
|
29
20
|
/** The key the painter asks for a picture by when the board keeps it in the host's store under `reference`. */
|
|
30
21
|
export function posterReferenceKey(reference) {
|
|
31
|
-
return
|
|
22
|
+
return `ref:${reference}`;
|
|
32
23
|
}
|
|
33
24
|
/** The picture for a key, once it has loaded. Null while it has not, or when it never will. */
|
|
34
25
|
export function posterPictureFor(key) {
|
|
35
|
-
|
|
36
|
-
return key ? ((_a = loadedPictures.get(key)) !== null && _a !== void 0 ? _a : null) : null;
|
|
26
|
+
return key ? (loadedPictures.get(key) ?? null) : null;
|
|
37
27
|
}
|
|
38
28
|
/** Calls `listener` whenever a picture has arrived. Returns what stops it. */
|
|
39
29
|
export function subscribeToPosterPictures(listener) {
|
|
40
30
|
listeners.add(listener);
|
|
41
|
-
return
|
|
31
|
+
return () => {
|
|
42
32
|
listeners.delete(listener);
|
|
43
33
|
};
|
|
44
34
|
}
|
|
@@ -46,16 +36,15 @@ export function subscribeToPosterPictures(listener) {
|
|
|
46
36
|
function imageMaker(createImage) {
|
|
47
37
|
if (createImage)
|
|
48
38
|
return createImage;
|
|
49
|
-
return typeof Image === 'undefined' ? null :
|
|
39
|
+
return typeof Image === 'undefined' ? null : () => new Image();
|
|
50
40
|
}
|
|
51
41
|
/** Tells every poster on the screen that a picture has arrived, once each; one that fails does not stop the others from hearing. */
|
|
52
42
|
function notifyListeners() {
|
|
53
|
-
for (
|
|
54
|
-
var listener = _a[_i];
|
|
43
|
+
for (const listener of [...listeners]) {
|
|
55
44
|
try {
|
|
56
45
|
listener();
|
|
57
46
|
}
|
|
58
|
-
catch
|
|
47
|
+
catch {
|
|
59
48
|
// A subscriber that fails does not stop the others from hearing.
|
|
60
49
|
}
|
|
61
50
|
}
|
|
@@ -63,22 +52,22 @@ function notifyListeners() {
|
|
|
63
52
|
/** Starts loading `source` (an address or a data URL) under `key`. A picture that cannot be loaded stays asked for: it costs one try. */
|
|
64
53
|
function startLoading(key, source, make) {
|
|
65
54
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
loadedPictures.set(key,
|
|
55
|
+
const image = make();
|
|
56
|
+
image.decoding = 'async';
|
|
57
|
+
image.onload = () => {
|
|
58
|
+
loadedPictures.set(key, image);
|
|
70
59
|
if (loadedPictures.size > MAX_KEPT_PICTURES) {
|
|
71
|
-
|
|
60
|
+
const oldest = loadedPictures.keys().next().value;
|
|
72
61
|
if (oldest !== undefined)
|
|
73
62
|
loadedPictures.delete(oldest);
|
|
74
63
|
}
|
|
75
64
|
notifyListeners();
|
|
76
65
|
};
|
|
77
66
|
// Left out: the board draws it when it has it.
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
image.onerror = () => { };
|
|
68
|
+
image.src = source;
|
|
80
69
|
}
|
|
81
|
-
catch
|
|
70
|
+
catch {
|
|
82
71
|
// The browser refused the picture; the poster goes on without it.
|
|
83
72
|
}
|
|
84
73
|
}
|
|
@@ -87,11 +76,10 @@ function startLoading(key, source, make) {
|
|
|
87
76
|
* arrives tells every subscriber, once. `createImage` is for tests; the browser's `Image` is used otherwise.
|
|
88
77
|
*/
|
|
89
78
|
export function requestPosterPictures(sources, createImage) {
|
|
90
|
-
|
|
79
|
+
const make = imageMaker(createImage);
|
|
91
80
|
if (!make)
|
|
92
81
|
return;
|
|
93
|
-
for (
|
|
94
|
-
var source = sources_1[_i];
|
|
82
|
+
for (const source of sources) {
|
|
95
83
|
if (loadedPictures.has(source) || askedFor.has(source))
|
|
96
84
|
continue;
|
|
97
85
|
askedFor.add(source);
|
|
@@ -104,17 +92,17 @@ export function requestPosterPictures(sources, createImage) {
|
|
|
104
92
|
* that fails, or answers with nothing, only means the picture is not in the poster.
|
|
105
93
|
*/
|
|
106
94
|
export function requestReferencedPictures(references, resolve, createImage) {
|
|
107
|
-
|
|
95
|
+
const make = imageMaker(createImage);
|
|
108
96
|
if (!make)
|
|
109
97
|
return;
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
for (const reference of references) {
|
|
99
|
+
const key = posterReferenceKey(reference);
|
|
112
100
|
if (loadedPictures.has(key) || askedFor.has(key))
|
|
113
|
-
|
|
101
|
+
continue;
|
|
114
102
|
askedFor.add(key);
|
|
115
103
|
void Promise.resolve()
|
|
116
|
-
.then(
|
|
117
|
-
.then(
|
|
104
|
+
.then(() => resolve(reference))
|
|
105
|
+
.then((source) => {
|
|
118
106
|
if (typeof source === 'string' && source !== '') {
|
|
119
107
|
startLoading(key, source, make);
|
|
120
108
|
return;
|
|
@@ -122,13 +110,9 @@ export function requestReferencedPictures(references, resolve, createImage) {
|
|
|
122
110
|
// The host does not have it (yet): it is asked again the next time the poster is drawn.
|
|
123
111
|
askedFor.delete(key);
|
|
124
112
|
})
|
|
125
|
-
.catch(
|
|
113
|
+
.catch(() => {
|
|
126
114
|
askedFor.delete(key);
|
|
127
115
|
});
|
|
128
|
-
};
|
|
129
|
-
for (var _i = 0, references_1 = references; _i < references_1.length; _i++) {
|
|
130
|
-
var reference = references_1[_i];
|
|
131
|
-
_loop_1(reference);
|
|
132
116
|
}
|
|
133
117
|
}
|
|
134
118
|
/** Forgets every picture (for tests, and for a page that signs someone out). */
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How what the person last chose for each kind of element (`engine/core/styleMemory.ts`) is kept for a workspace, and read back.
|
|
3
|
+
*
|
|
4
|
+
* The storage (`workspaceToolSettings.ts`) has a part for each kind: `paint` for the shapes that have an inside, `icon` for the line-only
|
|
5
|
+
* icons of the library, `arrow` and `text`; the pen of the Draw tool has its own part (`pen`), kept by the host from `EngineState.penStyle`.
|
|
6
|
+
* Nothing here touches the storage or the engine: these are the two translations between what the engine remembers and what is stored.
|
|
7
|
+
*/
|
|
8
|
+
import type { PatchedStyleKind, RememberedStyles } from '../engine/core/styleMemory.js';
|
|
9
|
+
import type { WorkspaceToolSettingsV1 } from './workspaceToolSettings.js';
|
|
10
|
+
/**
|
|
11
|
+
* The parts of the stored settings that say what the engine remembers for the kinds that changed, to be laid over what is stored (a part
|
|
12
|
+
* keeps the keys the patch does not say, so a kind that did not change is not named and stays as it is). A kind that holds nothing yet is
|
|
13
|
+
* not named either: nothing is written for an element the person never styled.
|
|
14
|
+
*/
|
|
15
|
+
export declare function settingsOfRememberedStyles(styles: RememberedStyles, kinds: readonly PatchedStyleKind[]): Partial<WorkspaceToolSettingsV1>;
|
|
16
|
+
/**
|
|
17
|
+
* What the stored settings hold for each kind, to be given to the engine (`EngineCore.setRememberedStyles`, which checks every key).
|
|
18
|
+
* No settings, or settings that never held a part: nothing for that kind.
|
|
19
|
+
*/
|
|
20
|
+
export declare function rememberedStylesOfSettings(settings: WorkspaceToolSettingsV1 | null): {
|
|
21
|
+
readonly [kind in PatchedStyleKind]: unknown;
|
|
22
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How what the person last chose for each kind of element (`engine/core/styleMemory.ts`) is kept for a workspace, and read back.
|
|
3
|
+
*
|
|
4
|
+
* The storage (`workspaceToolSettings.ts`) has a part for each kind: `paint` for the shapes that have an inside, `icon` for the line-only
|
|
5
|
+
* icons of the library, `arrow` and `text`; the pen of the Draw tool has its own part (`pen`), kept by the host from `EngineState.penStyle`.
|
|
6
|
+
* Nothing here touches the storage or the engine: these are the two translations between what the engine remembers and what is stored.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The parts of the stored settings that say what the engine remembers for the kinds that changed, to be laid over what is stored (a part
|
|
10
|
+
* keeps the keys the patch does not say, so a kind that did not change is not named and stays as it is). A kind that holds nothing yet is
|
|
11
|
+
* not named either: nothing is written for an element the person never styled.
|
|
12
|
+
*/
|
|
13
|
+
export function settingsOfRememberedStyles(styles, kinds) {
|
|
14
|
+
const settings = {};
|
|
15
|
+
for (const kind of kinds) {
|
|
16
|
+
const remembered = styles[kind];
|
|
17
|
+
if (Object.keys(remembered).length === 0)
|
|
18
|
+
continue;
|
|
19
|
+
switch (kind) {
|
|
20
|
+
case 'shape':
|
|
21
|
+
settings.paint = { ...remembered };
|
|
22
|
+
break;
|
|
23
|
+
case 'lineIcon':
|
|
24
|
+
settings.icon = { ...remembered };
|
|
25
|
+
break;
|
|
26
|
+
case 'arrow':
|
|
27
|
+
settings.arrow = { ...remembered };
|
|
28
|
+
break;
|
|
29
|
+
case 'text':
|
|
30
|
+
settings.text = { ...remembered };
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return settings;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What the stored settings hold for each kind, to be given to the engine (`EngineCore.setRememberedStyles`, which checks every key).
|
|
38
|
+
* No settings, or settings that never held a part: nothing for that kind.
|
|
39
|
+
*/
|
|
40
|
+
export function rememberedStylesOfSettings(settings) {
|
|
41
|
+
return {
|
|
42
|
+
shape: settings?.paint,
|
|
43
|
+
lineIcon: settings?.icon,
|
|
44
|
+
arrow: settings?.arrow,
|
|
45
|
+
text: settings?.text
|
|
46
|
+
};
|
|
47
|
+
}
|