@widgetic/canvas 0.5.41 → 0.5.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/canvas/DomCanvas.svelte +49 -20
- package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
- 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.d.ts +14 -3
- package/dist/canvas/chromeLayout.js +30 -20
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +47 -5
- package/dist/canvas/host/CanvasHost.js +1481 -1566
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/browserServices.js +65 -116
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.d.ts +33 -0
- package/dist/canvas/host/nearCards.js +78 -0
- package/dist/canvas/host/pageEvents.d.ts +16 -4
- package/dist/canvas/host/pageEvents.js +17 -8
- package/dist/canvas/host/pictureSaves.d.ts +33 -0
- package/dist/canvas/host/pictureSaves.js +42 -0
- package/dist/canvas/host/screenRects.d.ts +5 -0
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.d.ts +88 -0
- package/dist/canvas/host/storedPictures.js +288 -0
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/index.js +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.d.ts +45 -2
- package/dist/canvas/shapes/shapeImageStore.js +10 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.d.ts +2 -2
- package/dist/canvas/toolbarPosition.js +4 -4
- package/dist/canvas/ui/SelectionPanel.svelte +28 -5
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
- package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
- package/dist/canvas/ui/ToolButton.svelte +8 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +2 -2
- package/dist/canvas/ui/floatingCard.js +20 -20
- package/dist/canvas/ui/floatingLayer.d.ts +13 -2
- package/dist/canvas/ui/floatingLayer.js +18 -7
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/CanvasStage.svelte +101 -67
- package/dist/canvas/view/LeftToRightScope.svelte +21 -0
- package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
- package/dist/canvas/view/ObjectView.svelte +15 -10
- package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/canvas/view/liftedScene.d.ts +31 -0
- package/dist/canvas/view/liftedScene.js +146 -0
- package/dist/canvas/view/mountedScene.d.ts +71 -0
- package/dist/canvas/view/mountedScene.js +363 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +15 -1
- package/dist/engine/EngineCore.js +724 -797
- package/dist/engine/codec/canvasDocument.d.ts +5 -0
- package/dist/engine/codec/canvasDocument.js +212 -149
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +76 -89
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +67 -94
- package/dist/engine/core/defaults.js +90 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.d.ts +6 -0
- package/dist/engine/core/history.js +49 -50
- 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.d.ts +10 -0
- package/dist/engine/core/scene.js +153 -187
- 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 +31 -64
- package/dist/engine/core/transform.js +83 -94
- package/dist/engine/core/types.d.ts +8 -2
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +467 -474
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +265 -309
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +27 -30
- 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.d.ts +20 -0
- package/dist/engine/state.js +5 -15
- 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.d.ts +10 -1
- package/dist/fonts/interFont.js +47 -75
- package/dist/fonts/workspaceFonts.js +32 -90
- 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 +8 -1
- package/dist/i18n/messages.js +10 -2
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/settings/workspaceToolSettings.js +32 -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 +105 -141
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/types.js +1 -1
- package/package.json +1 -1
- package/dist/canvas/ui/SelectorBar.svelte +0 -84
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
* which cursor the board shows. Plain functions of the engine's records and the viewport, free of Svelte and the DOM, so
|
|
4
4
|
* a view only writes what they return and Node can test them.
|
|
5
5
|
*/
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
6
|
import { isArrow } from '../../engine/core/arrow.js';
|
|
18
7
|
import { strokeDashArray } from '../../engine/core/defaults.js';
|
|
19
8
|
import { boxToWorldMatrix, degreesToRadians, matrixToCss } from '../../engine/core/matrix.js';
|
|
@@ -28,23 +17,23 @@ import { fontShorthand } from '../../engine/text/layoutText.js';
|
|
|
28
17
|
*/
|
|
29
18
|
export function placementCss(box) {
|
|
30
19
|
if (!box.rotation)
|
|
31
|
-
return
|
|
20
|
+
return `matrix(1, 0, 0, 1, ${Number(box.x.toFixed(5))}, ${Number(box.y.toFixed(5))})`;
|
|
32
21
|
return matrixToCss(boxToWorldMatrix(box));
|
|
33
22
|
}
|
|
34
23
|
/** The size of an object's box and the corner it turns about: what its style says apart from where it stands. */
|
|
35
24
|
export function boxSizeCss(box) {
|
|
36
|
-
return
|
|
25
|
+
return `left:0;top:0;width:${trim(box.width)}px;height:${trim(box.height)}px;transform-origin:0 0;`;
|
|
37
26
|
}
|
|
38
27
|
/** The CSS that puts an object's box where it belongs in the world layer: its size, and its turn about its own middle. */
|
|
39
28
|
export function boxStyle(box) {
|
|
40
|
-
return
|
|
29
|
+
return `${boxSizeCss(box)}transform:${placementCss(box)};`;
|
|
41
30
|
}
|
|
42
31
|
/** What a text's style says apart from its box: the padding, the colours, the font, and how its lines sit in the box. */
|
|
43
32
|
export function textBoxCss(text) {
|
|
44
|
-
return
|
|
33
|
+
return `padding:${text.padding}px;background-color:${text.backgroundColor};color:${text.color};font:${fontShorthand(text)};line-height:${text.lineHeight};text-align:${text.align};${text.underline ? 'text-decoration:underline;' : ''}`;
|
|
45
34
|
}
|
|
46
35
|
/** The fields of a record that say where an object stands; every other field says what it looks like. */
|
|
47
|
-
|
|
36
|
+
const PLACEMENT_FIELDS = new Set(['x', 'y', 'rotation']);
|
|
48
37
|
/**
|
|
49
38
|
* True when two records of an object differ only in where they stand (its position and its turn).
|
|
50
39
|
*
|
|
@@ -57,14 +46,14 @@ export function sameLook(first, second) {
|
|
|
57
46
|
return true;
|
|
58
47
|
if (first.type !== second.type)
|
|
59
48
|
return false;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (
|
|
49
|
+
const before = first;
|
|
50
|
+
const after = second;
|
|
51
|
+
for (const key in after) {
|
|
63
52
|
if (!PLACEMENT_FIELDS.has(key) && before[key] !== after[key])
|
|
64
53
|
return false;
|
|
65
54
|
}
|
|
66
55
|
// A field that was dropped is a change too (a record with the same fields never takes this loop further).
|
|
67
|
-
for (
|
|
56
|
+
for (const key in before) {
|
|
68
57
|
if (!PLACEMENT_FIELDS.has(key) && !(key in after))
|
|
69
58
|
return false;
|
|
70
59
|
}
|
|
@@ -72,8 +61,8 @@ export function sameLook(first, second) {
|
|
|
72
61
|
}
|
|
73
62
|
/** A colour of `transparent` (or a stroke with no width) is "none" in SVG. */
|
|
74
63
|
export function svgPaintOf(shape) {
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
const hasStroke = shape.stroke !== 'transparent' && shape.strokeWidth > 0;
|
|
65
|
+
const dash = hasStroke ? strokeDashArray(shape.strokeStyle, shape.strokeWidth) : null;
|
|
77
66
|
return {
|
|
78
67
|
fill: shape.fill === 'transparent' ? 'none' : shape.fill,
|
|
79
68
|
fillOpacity: shape.fillOpacity,
|
|
@@ -85,10 +74,10 @@ export function svgPaintOf(shape) {
|
|
|
85
74
|
};
|
|
86
75
|
}
|
|
87
76
|
export function screenFrameOf(frame, viewport) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return { left: center.x - width / 2, top: center.y - height / 2, width
|
|
77
|
+
const center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
|
|
78
|
+
const width = frame.width * viewport.zoom;
|
|
79
|
+
const height = frame.height * viewport.zoom;
|
|
80
|
+
return { left: center.x - width / 2, top: center.y - height / 2, width, height, rotation: frame.rotation, centerX: center.x, centerY: center.y };
|
|
92
81
|
}
|
|
93
82
|
/**
|
|
94
83
|
* The CSS that places a box in a layer that covers the board, in pixels from the layer's top left corner.
|
|
@@ -97,15 +86,14 @@ export function screenFrameOf(frame, viewport) {
|
|
|
97
86
|
* a physical distance from the left edge, and is not written with the start of the line.
|
|
98
87
|
*/
|
|
99
88
|
export function layerBoxStyle(box) {
|
|
100
|
-
|
|
89
|
+
const size = (box.width === undefined ? '' : `width:${trim(box.width)}px;`) + (box.height === undefined ? '' : `height:${trim(box.height)}px;`);
|
|
101
90
|
// rtl-ok: a place on the drawing, measured from the left edge of the layer on every screen
|
|
102
|
-
return
|
|
91
|
+
return `left:${trim(box.left)}px;top:${trim(box.top)}px;${size}`;
|
|
103
92
|
}
|
|
104
93
|
/** The CSS that puts a box of `width` by `height` (a square when only `width` is given) with its middle on a point of the layer that covers the board. */
|
|
105
|
-
export function layerCenteredStyle(center, width, height) {
|
|
106
|
-
if (height === void 0) { height = width; }
|
|
94
|
+
export function layerCenteredStyle(center, width, height = width) {
|
|
107
95
|
// rtl-ok: a place on the drawing, measured from the left edge of the layer on every screen
|
|
108
|
-
return layerBoxStyle({ left: center.x - width / 2, top: center.y - height / 2, width
|
|
96
|
+
return layerBoxStyle({ left: center.x - width / 2, top: center.y - height / 2, width, height });
|
|
109
97
|
}
|
|
110
98
|
/** The CSS that places a point of the layer that covers the board (the corner a label starts from). */
|
|
111
99
|
export function layerPointStyle(point) {
|
|
@@ -116,20 +104,20 @@ export function layerPointStyle(point) {
|
|
|
116
104
|
* on the screen, and the scale from the coordinates of its path to pixels.
|
|
117
105
|
*/
|
|
118
106
|
export function arrowOutlinePlacement(box, viewport) {
|
|
119
|
-
|
|
107
|
+
const corner = worldToScreen(viewport, { x: box.x, y: box.y });
|
|
120
108
|
return { style: layerBoxStyle({ left: corner.x, top: corner.y }), scale: viewport.zoom };
|
|
121
109
|
}
|
|
122
110
|
/** The CSS that places a screen frame in a layer that covers the board. */
|
|
123
111
|
export function screenFrameStyle(frame) {
|
|
124
|
-
|
|
125
|
-
return
|
|
112
|
+
const turn = frame.rotation === 0 ? '' : `transform:rotate(${trim(frame.rotation)}deg);`;
|
|
113
|
+
return `${layerBoxStyle(frame)}${turn}`;
|
|
126
114
|
}
|
|
127
115
|
/**
|
|
128
116
|
* What the figure in the middle of a selection says: a size as `450 × 149`, an angle as `35°`. Numbers and signs, no
|
|
129
117
|
* words, so it needs no translation (the page that shows it sets its direction to left to right, so the order holds).
|
|
130
118
|
*/
|
|
131
119
|
export function formatReadout(readout) {
|
|
132
|
-
return readout.kind === 'size' ?
|
|
120
|
+
return readout.kind === 'size' ? `${readout.width} × ${readout.height}` : `${readout.degrees}°`;
|
|
133
121
|
}
|
|
134
122
|
/**
|
|
135
123
|
* Where the size label sits: in the middle of the selection (the middle of the frame, whatever its turn, and of the box around
|
|
@@ -141,8 +129,8 @@ export function restingSizeLabelPoint(frame, _text) {
|
|
|
141
129
|
}
|
|
142
130
|
/** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the turning dot goes. */
|
|
143
131
|
export function pointBelowFrame(frame, distance) {
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
const radians = degreesToRadians(frame.rotation);
|
|
133
|
+
const reach = frame.height / 2 + distance;
|
|
146
134
|
return { x: frame.centerX - Math.sin(radians) * reach, y: frame.centerY + Math.cos(radians) * reach };
|
|
147
135
|
}
|
|
148
136
|
/**
|
|
@@ -150,27 +138,27 @@ export function pointBelowFrame(frame, distance) {
|
|
|
150
138
|
* shape, the upright rectangle around the members for a group.
|
|
151
139
|
*/
|
|
152
140
|
export function outlineOfUnit(scene, id) {
|
|
153
|
-
|
|
141
|
+
const object = scene.find((candidate) => candidate.id === id);
|
|
154
142
|
if (!object)
|
|
155
143
|
return null;
|
|
156
144
|
if (object.type !== 'group') {
|
|
157
|
-
|
|
145
|
+
const shape = object;
|
|
158
146
|
return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
|
|
159
147
|
}
|
|
160
|
-
|
|
161
|
-
return bounds ?
|
|
148
|
+
const bounds = boundsOfObjects(scene, [id]);
|
|
149
|
+
return bounds ? { ...bounds, rotation: 0 } : null;
|
|
162
150
|
}
|
|
163
151
|
/** The mark for the tie the engine says is in the offing, or null when there is none (or its shape is not on the board any more). */
|
|
164
152
|
export function arrowBindMarkOf(scene, hint, viewport) {
|
|
165
153
|
if (!hint)
|
|
166
154
|
return null;
|
|
167
|
-
|
|
155
|
+
const outline = outlineOfUnit(scene, hint.targetId);
|
|
168
156
|
if (!outline)
|
|
169
157
|
return null;
|
|
170
158
|
return { frame: screenFrameOf(outline, viewport), point: worldToScreen(viewport, hint.point), kind: hint.kind };
|
|
171
159
|
}
|
|
172
160
|
/** What a marquee that takes nothing draws: the one shared empty answer, so a derived value that holds it stays the same. */
|
|
173
|
-
export
|
|
161
|
+
export const NO_MARQUEE_OUTLINES = Object.freeze({ frames: Object.freeze([]), arrows: Object.freeze([]) });
|
|
174
162
|
/**
|
|
175
163
|
* The outlines of the units a marquee would take, in the order given (paint order). One pass over the scene finds the units,
|
|
176
164
|
* so a marquee over the whole board costs one more pass for every group in it and no more for a shape.
|
|
@@ -178,34 +166,32 @@ export var NO_MARQUEE_OUTLINES = Object.freeze({ frames: Object.freeze([]), arro
|
|
|
178
166
|
export function marqueeOutlinesOf(scene, ids, viewport) {
|
|
179
167
|
if (ids.length === 0)
|
|
180
168
|
return NO_MARQUEE_OUTLINES;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
for (
|
|
184
|
-
var object = scene_1[_i];
|
|
169
|
+
const wanted = new Set(ids);
|
|
170
|
+
const found = new Map();
|
|
171
|
+
for (const object of scene) {
|
|
185
172
|
if (wanted.has(object.id))
|
|
186
173
|
found.set(object.id, object);
|
|
187
174
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
for (
|
|
191
|
-
|
|
192
|
-
var object = found.get(id);
|
|
175
|
+
const frames = [];
|
|
176
|
+
const arrows = [];
|
|
177
|
+
for (const id of ids) {
|
|
178
|
+
const object = found.get(id);
|
|
193
179
|
if (!object)
|
|
194
180
|
continue;
|
|
195
181
|
if (object.type === 'path' && isArrow(object)) {
|
|
196
182
|
arrows.push(object);
|
|
197
183
|
continue;
|
|
198
184
|
}
|
|
199
|
-
|
|
185
|
+
const outline = object.type === 'group' ? outlineOfUnit(scene, id) : { x: object.x, y: object.y, width: object.width, height: object.height, rotation: object.rotation };
|
|
200
186
|
if (outline)
|
|
201
|
-
frames.push({ id
|
|
187
|
+
frames.push({ id, frame: screenFrameOf(outline, viewport) });
|
|
202
188
|
}
|
|
203
|
-
return frames.length === 0 && arrows.length === 0 ? NO_MARQUEE_OUTLINES : { frames
|
|
189
|
+
return frames.length === 0 && arrows.length === 0 ? NO_MARQUEE_OUTLINES : { frames, arrows };
|
|
204
190
|
}
|
|
205
191
|
/** What a marquee that takes nothing draws: the one shared empty answer. */
|
|
206
|
-
export
|
|
192
|
+
export const NO_OUTLINE_PATHS = Object.freeze({ upright: '', turned: '' });
|
|
207
193
|
/** Half the width of the line, in pixels: the line is centred this far outside the edge, so it covers the pixel just outside it. */
|
|
208
|
-
|
|
194
|
+
const OUTLINE_HALF_WIDTH = 0.5;
|
|
209
195
|
/**
|
|
210
196
|
* The paths of the outlines of some frames, in the order given.
|
|
211
197
|
*
|
|
@@ -217,46 +203,41 @@ var OUTLINE_HALF_WIDTH = 0.5;
|
|
|
217
203
|
export function outlinePathsOf(frames) {
|
|
218
204
|
if (frames.length === 0)
|
|
219
205
|
return NO_OUTLINE_PATHS;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
206
|
+
let upright = '';
|
|
207
|
+
let turned = '';
|
|
208
|
+
for (const { frame } of frames) {
|
|
223
209
|
if (!Number.isFinite(frame.left + frame.top + frame.width + frame.height + frame.rotation))
|
|
224
|
-
|
|
210
|
+
continue;
|
|
225
211
|
if (frame.rotation === 0) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
upright +=
|
|
231
|
-
|
|
212
|
+
const left = Math.round(frame.left);
|
|
213
|
+
const top = Math.round(frame.top);
|
|
214
|
+
const reachRight = Math.round(frame.left + frame.width) - left + 2 * OUTLINE_HALF_WIDTH;
|
|
215
|
+
const reachDown = Math.round(frame.top + frame.height) - top + 2 * OUTLINE_HALF_WIDTH;
|
|
216
|
+
upright += `M${left - OUTLINE_HALF_WIDTH} ${top - OUTLINE_HALF_WIDTH}h${reachRight}v${reachDown}h${-reachRight}z`;
|
|
217
|
+
continue;
|
|
232
218
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
219
|
+
const radians = degreesToRadians(frame.rotation);
|
|
220
|
+
const cosine = Math.cos(radians);
|
|
221
|
+
const sine = Math.sin(radians);
|
|
222
|
+
const halfWidth = frame.width / 2 + OUTLINE_HALF_WIDTH;
|
|
223
|
+
const halfHeight = frame.height / 2 + OUTLINE_HALF_WIDTH;
|
|
238
224
|
// The four corners of the box grown by half the width of the line, turned about the middle of the box (clockwise, as CSS turns).
|
|
239
|
-
|
|
225
|
+
const corners = [
|
|
240
226
|
[-halfWidth, -halfHeight],
|
|
241
227
|
[halfWidth, -halfHeight],
|
|
242
228
|
[halfWidth, halfHeight],
|
|
243
229
|
[-halfWidth, halfHeight]
|
|
244
230
|
];
|
|
245
231
|
turned += corners
|
|
246
|
-
.map(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return "".concat(index === 0 ? 'M' : 'L').concat(Math.round(x * 100) / 100, " ").concat(Math.round(y * 100) / 100);
|
|
232
|
+
.map(([cornerX, cornerY], index) => {
|
|
233
|
+
const x = frame.centerX + cornerX * cosine - cornerY * sine;
|
|
234
|
+
const y = frame.centerY + cornerX * sine + cornerY * cosine;
|
|
235
|
+
return `${index === 0 ? 'M' : 'L'}${Math.round(x * 100) / 100} ${Math.round(y * 100) / 100}`;
|
|
251
236
|
})
|
|
252
237
|
.join('');
|
|
253
238
|
turned += 'z';
|
|
254
|
-
};
|
|
255
|
-
for (var _i = 0, frames_1 = frames; _i < frames_1.length; _i++) {
|
|
256
|
-
var frame = frames_1[_i].frame;
|
|
257
|
-
_loop_1(frame);
|
|
258
239
|
}
|
|
259
|
-
return upright === '' && turned === '' ? NO_OUTLINE_PATHS : { upright
|
|
240
|
+
return upright === '' && turned === '' ? NO_OUTLINE_PATHS : { upright, turned };
|
|
260
241
|
}
|
|
261
242
|
/** The rectangle around a shape as the board shows it: for a shape that is turned, the box that holds its corners. */
|
|
262
243
|
export function upright(shape) {
|
|
@@ -266,23 +247,23 @@ export function upright(shape) {
|
|
|
266
247
|
* The dot grid under the objects (Figma "Dot Grid": a dot every 24 world units, 2 pixels across, the ink colour at 30%).
|
|
267
248
|
* It moves and scales with the world, and doubles its step while the dots would be closer than 12 pixels.
|
|
268
249
|
*/
|
|
269
|
-
export
|
|
270
|
-
|
|
250
|
+
export const DOT_GRID_STEP = 24;
|
|
251
|
+
const DOT_GRID_MIN_SCREEN_STEP = 12;
|
|
271
252
|
/**
|
|
272
253
|
* One dot in the middle of a cell, as a gradient: it takes its colour from the page's `foreground` token (a data URL
|
|
273
254
|
* cannot), stays two pixels across at every zoom, and costs one background layer however large the board is.
|
|
274
255
|
*/
|
|
275
|
-
export
|
|
256
|
+
export const DOT_GRID_IMAGE = 'radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 0, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 1px, transparent 1.5px)';
|
|
276
257
|
export function dotGridStyle(viewport) {
|
|
277
|
-
|
|
258
|
+
let step = DOT_GRID_STEP;
|
|
278
259
|
while (step * viewport.zoom < DOT_GRID_MIN_SCREEN_STEP)
|
|
279
260
|
step *= 2;
|
|
280
|
-
|
|
261
|
+
const size = step * viewport.zoom;
|
|
281
262
|
// The cells follow the world origin, and the dot is in the middle of each, as in the design.
|
|
282
|
-
return
|
|
263
|
+
return `background-image:${DOT_GRID_IMAGE};background-size:${trim(size)}px ${trim(size)}px;background-position:${trim(viewport.x)}px ${trim(viewport.y)}px;`;
|
|
283
264
|
}
|
|
284
265
|
/** The pointer of the board has a name for the turning handle that CSS does not know: it is drawn as a small arc with an arrowhead. */
|
|
285
|
-
|
|
266
|
+
const ROTATE_CURSOR_CSS = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%230f2010' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 11a8 8 0 1 0-2.3 5.7'/%3E%3Cpath d='M20 4v7h-7'/%3E%3C/svg%3E\") 12 12, grab";
|
|
286
267
|
/** The CSS `cursor` for what the engine asked the board to show. */
|
|
287
268
|
export function cssCursor(cursor) {
|
|
288
269
|
return cursor === ROTATE_CURSOR ? ROTATE_CURSOR_CSS : cursor;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ObjectId, SceneObject } from '../../engine/core/types.js';
|
|
2
|
+
import type { CarriedShapes } from '../../engine/state.js';
|
|
3
|
+
/** A carried selection is drawn as one layer only when at least this many of its objects have an element: a few cost nothing to write. */
|
|
4
|
+
export declare const LIFT_MINIMUM_CARRIED = 40;
|
|
5
|
+
/**
|
|
6
|
+
* ...and only when the objects that are not carried (and have an element) are at most this share of the ones that are, when the drag
|
|
7
|
+
* begins: the work of a step is the work for those, so that is how much of the work is left (a third at the most, with one half).
|
|
8
|
+
*/
|
|
9
|
+
export declare const LIFT_UNCARRIED_SHARE = 0.5;
|
|
10
|
+
/** What the stage draws: the objects, and how far the world layer is moved on top of the view's own move, in world units. */
|
|
11
|
+
export interface LiftedScene {
|
|
12
|
+
objects: readonly SceneObject[];
|
|
13
|
+
offsetX: number;
|
|
14
|
+
offsetY: number;
|
|
15
|
+
}
|
|
16
|
+
export interface LiftedView {
|
|
17
|
+
/**
|
|
18
|
+
* What to draw for the objects that have an element (`mounted`, from the engine's records) and what the engine says is carried
|
|
19
|
+
* (`carry`, null when nothing is). Called at every step of a drag, so it does one pass over the list and nothing more.
|
|
20
|
+
*/
|
|
21
|
+
show(mounted: readonly SceneObject[], carry: CarriedShapes | null): LiftedScene;
|
|
22
|
+
}
|
|
23
|
+
/** How many of the objects are carried. */
|
|
24
|
+
export declare function countCarried(objects: readonly SceneObject[], shapeIds: ReadonlySet<ObjectId>): number;
|
|
25
|
+
/**
|
|
26
|
+
* The records to draw while the carried shapes are lifted: each carried object as it was when the drag began (the very same record at
|
|
27
|
+
* every step), each of the others as the engine holds it, moved back by how far the selection has been carried. Null when a carried
|
|
28
|
+
* object has no record from the start, which says that what the engine handed over is not what this drag is made of.
|
|
29
|
+
*/
|
|
30
|
+
export declare function recordsWhileLifted(mounted: readonly SceneObject[], carry: CarriedShapes): SceneObject[] | null;
|
|
31
|
+
export declare function createLiftedView(): LiftedView;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A big selection that is carried, drawn as one layer.
|
|
3
|
+
*
|
|
4
|
+
* A drag writes a new record for every shape it carries, at every step, and every object that gets a new record is told, works out
|
|
5
|
+
* its placement and has its element written: with the whole of a board of 1,000 objects selected that is 1,000 elements at every
|
|
6
|
+
* frame of the drag, which is the one thing a board of this size could not do within a frame (18.7 ms at 1,000 objects, 58 ms at 3,000).
|
|
7
|
+
*
|
|
8
|
+
* What is carried does not change except for where it stands, and the world layer already moves as a whole for a pan: so while the
|
|
9
|
+
* pointer is down the carried objects are drawn from the records they had when the drag began, which are the same records at every
|
|
10
|
+
* step (the stage's list holds the same objects, and an object that is the same record as before is not told anything), and the world
|
|
11
|
+
* layer is moved by how far the selection has been carried, once. The objects that are not carried would move with the layer, so each of
|
|
12
|
+
* them is drawn from its own record moved back by the same distance: it stands where it stood. Both come to the same place on
|
|
13
|
+
* the screen as the records the engine holds, which is the truth and is what is drawn again, with no distance, the moment the drag ends.
|
|
14
|
+
*
|
|
15
|
+
* carried: on the screen = view + zoom * (distance + record from the start) = where the engine's record is
|
|
16
|
+
* not carried: on the screen = view + zoom * (distance + (record - distance)) = where the engine's record is
|
|
17
|
+
*
|
|
18
|
+
* The cost of a step is then the work for the objects that are *not* carried, and none for the ones that are. That is why it pays when
|
|
19
|
+
* most of what has an element is carried (select all, then drag), and not when a few shapes are carried over a crowd: `show` looks at
|
|
20
|
+
* the numbers and keeps the plain way (the stage draws the engine's records) when the other way would not be cheaper.
|
|
21
|
+
*
|
|
22
|
+
* Nothing about the engine changes: it writes its records at every step (the frame, the guides, the ties of the arrows, the host's own
|
|
23
|
+
* layers and the undo step all read them), and its `carry` in the overlay only says what is carried, from which records and how far
|
|
24
|
+
* (`CarriedShapes`). Where there is nothing like it, or anything about it is not as expected, the objects are drawn the plain way.
|
|
25
|
+
*
|
|
26
|
+
* Plain TypeScript with no Svelte file in it, so that Node can test it.
|
|
27
|
+
*/
|
|
28
|
+
import { isBoxedObject } from '../../engine/core/types.js';
|
|
29
|
+
import { canvasLog } from '../canvasLogger.js';
|
|
30
|
+
/** A carried selection is drawn as one layer only when at least this many of its objects have an element: a few cost nothing to write. */
|
|
31
|
+
export const LIFT_MINIMUM_CARRIED = 40;
|
|
32
|
+
/**
|
|
33
|
+
* ...and only when the objects that are not carried (and have an element) are at most this share of the ones that are, when the drag
|
|
34
|
+
* begins: the work of a step is the work for those, so that is how much of the work is left (a third at the most, with one half).
|
|
35
|
+
*/
|
|
36
|
+
export const LIFT_UNCARRIED_SHARE = 0.5;
|
|
37
|
+
const NO_OBJECTS = Object.freeze([]);
|
|
38
|
+
/** An object moved by a distance (the same object when the distance is none): a group draws nothing and has no place to move. */
|
|
39
|
+
function movedBy(object, distanceX, distanceY) {
|
|
40
|
+
if ((distanceX === 0 && distanceY === 0) || !isBoxedObject(object))
|
|
41
|
+
return object;
|
|
42
|
+
return { ...object, x: object.x + distanceX, y: object.y + distanceY };
|
|
43
|
+
}
|
|
44
|
+
/** How many of the objects are carried. */
|
|
45
|
+
export function countCarried(objects, shapeIds) {
|
|
46
|
+
let carriedCount = 0;
|
|
47
|
+
for (const object of objects) {
|
|
48
|
+
if (shapeIds.has(object.id))
|
|
49
|
+
carriedCount += 1;
|
|
50
|
+
}
|
|
51
|
+
return carriedCount;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The records to draw while the carried shapes are lifted: each carried object as it was when the drag began (the very same record at
|
|
55
|
+
* every step), each of the others as the engine holds it, moved back by how far the selection has been carried. Null when a carried
|
|
56
|
+
* object has no record from the start, which says that what the engine handed over is not what this drag is made of.
|
|
57
|
+
*/
|
|
58
|
+
export function recordsWhileLifted(mounted, carry) {
|
|
59
|
+
const records = new Array(mounted.length);
|
|
60
|
+
for (let position = 0; position < mounted.length; position += 1) {
|
|
61
|
+
const object = mounted[position];
|
|
62
|
+
if (carry.shapeIds.has(object.id)) {
|
|
63
|
+
const recordFromTheStart = carry.startRecords.get(object.id);
|
|
64
|
+
if (recordFromTheStart === undefined)
|
|
65
|
+
return null;
|
|
66
|
+
records[position] = recordFromTheStart;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
records[position] = movedBy(object, -carry.deltaX, -carry.deltaY);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return records;
|
|
73
|
+
}
|
|
74
|
+
/** Whether two lists hold the very same records in the same order. */
|
|
75
|
+
function sameRecordsInOrder(first, second) {
|
|
76
|
+
if (first === second)
|
|
77
|
+
return true;
|
|
78
|
+
if (first.length !== second.length)
|
|
79
|
+
return false;
|
|
80
|
+
for (let position = 0; position < first.length; position += 1) {
|
|
81
|
+
if (first[position] !== second[position])
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
export function createLiftedView() {
|
|
87
|
+
// The drag that was seen last, told by the set of its shapes (one set for a drag, the same one at every step), and what was decided for it.
|
|
88
|
+
let seenDrag = null;
|
|
89
|
+
let decision = 'undecided';
|
|
90
|
+
// What was handed out last: the same records again are handed out as the very same list, so that the stage is told nothing.
|
|
91
|
+
let lastList = NO_OBJECTS;
|
|
92
|
+
// Once the work has failed the objects are drawn the plain way from then on (and the failure is said once).
|
|
93
|
+
let failed = false;
|
|
94
|
+
const drawnPlain = (mounted) => ({ objects: mounted, offsetX: 0, offsetY: 0 });
|
|
95
|
+
return {
|
|
96
|
+
show(mounted, carry) {
|
|
97
|
+
if (carry === null) {
|
|
98
|
+
seenDrag = null;
|
|
99
|
+
decision = 'undecided';
|
|
100
|
+
lastList = NO_OBJECTS;
|
|
101
|
+
return drawnPlain(mounted);
|
|
102
|
+
}
|
|
103
|
+
if (failed)
|
|
104
|
+
return drawnPlain(mounted);
|
|
105
|
+
try {
|
|
106
|
+
if (carry.shapeIds !== seenDrag) {
|
|
107
|
+
seenDrag = carry.shapeIds;
|
|
108
|
+
decision = 'undecided';
|
|
109
|
+
lastList = NO_OBJECTS;
|
|
110
|
+
}
|
|
111
|
+
if (decision === 'plain')
|
|
112
|
+
return drawnPlain(mounted);
|
|
113
|
+
const carriedCount = countCarried(mounted, carry.shapeIds);
|
|
114
|
+
const uncarriedCount = mounted.length - carriedCount;
|
|
115
|
+
if (decision === 'undecided') {
|
|
116
|
+
const worthIt = carriedCount >= LIFT_MINIMUM_CARRIED && uncarriedCount <= carriedCount * LIFT_UNCARRIED_SHARE;
|
|
117
|
+
decision = worthIt ? 'lifted' : 'plain';
|
|
118
|
+
// Said once for the drag, and only for the drags that are drawn another way: the plain way is every other drag.
|
|
119
|
+
if (worthIt)
|
|
120
|
+
canvasLog(`Canvas: a drag of ${carriedCount} objects (${uncarriedCount} others with an element) is drawn as one layer`);
|
|
121
|
+
}
|
|
122
|
+
else if (uncarriedCount > carriedCount) {
|
|
123
|
+
// The drag has come to a crowd of objects that are not carried: moving each of them back costs more than writing the carried ones.
|
|
124
|
+
decision = 'plain';
|
|
125
|
+
canvasLog(`Canvas: the drag came to ${uncarriedCount} objects that are not carried, so it is drawn object by object from here`);
|
|
126
|
+
}
|
|
127
|
+
if (decision === 'plain')
|
|
128
|
+
return drawnPlain(mounted);
|
|
129
|
+
const records = recordsWhileLifted(mounted, carry);
|
|
130
|
+
if (records === null) {
|
|
131
|
+
decision = 'plain';
|
|
132
|
+
canvasLog('Canvas: a carried object had no record from the start of the drag, so the drag is drawn object by object');
|
|
133
|
+
return drawnPlain(mounted);
|
|
134
|
+
}
|
|
135
|
+
const list = sameRecordsInOrder(records, lastList) ? lastList : records;
|
|
136
|
+
lastList = list;
|
|
137
|
+
return { objects: list, offsetX: carry.deltaX, offsetY: carry.deltaY };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
failed = true;
|
|
141
|
+
console.warn('Canvas: a carried selection could not be drawn as one layer, so every object is drawn by itself', error);
|
|
142
|
+
return drawnPlain(mounted);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Readable } from 'svelte/store';
|
|
2
|
+
import type { Scene } from '../../engine/core/scene.js';
|
|
3
|
+
import type { ObjectId, SceneObject, Size, Viewport } from '../../engine/core/types.js';
|
|
4
|
+
/** A board with fewer objects than this keeps an element for every one of them. */
|
|
5
|
+
export declare const CULLING_MINIMUM_OBJECTS = 150;
|
|
6
|
+
/** How far past the view an object is given an element, as a share of the view's width and height, on every side. */
|
|
7
|
+
export declare const NEAR_MARGIN_RATIO = 0.5;
|
|
8
|
+
/**
|
|
9
|
+
* How far past the view an object that has an element keeps it, in the same measure. More than `NEAR_MARGIN_RATIO`: an object
|
|
10
|
+
* is not made at the edge of the near area and taken away the moment the view has moved a little, which would have a pan that
|
|
11
|
+
* goes out and back build the same objects twice (a few hundred of them, when the whole board is in view). The most that can have
|
|
12
|
+
* an element is what is in this area, which is nine views. It is not used by a view that has just zoomed in, nor by the first
|
|
13
|
+
* area of a board (see `nearAreaAround`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const KEEP_MARGIN_RATIO = 1;
|
|
16
|
+
/**
|
|
17
|
+
* How far the view may go past where it was when the near area was made, as a share of the view, before the area is made again.
|
|
18
|
+
* What is left of the margin at that moment is the room that a quick pan has before it reaches an object without an element.
|
|
19
|
+
*/
|
|
20
|
+
export declare const REFRESH_DISTANCE_RATIO = 0.15;
|
|
21
|
+
/** The area is made again once the view has zoomed in by this factor: the objects that are not near the view now lose their element at once. */
|
|
22
|
+
export declare const ZOOM_IN_REFRESH_RATIO = 1.5;
|
|
23
|
+
/** How many objects that had no element get one in the first frame, when many are wanted at once (what follows adapts, see below). */
|
|
24
|
+
export declare const MOUNT_BATCH_SIZE = 30;
|
|
25
|
+
/** The batch never gets smaller than this, so that a very slow device (or a frame that is slow for another reason, a zoom with a thousand objects in view) still gets somewhere... */
|
|
26
|
+
export declare const MIN_MOUNT_BATCH_SIZE = 16;
|
|
27
|
+
/** ...and never larger than this, however quick the frames are: one frame must stay a frame's work. */
|
|
28
|
+
export declare const MAX_MOUNT_BATCH_SIZE = 120;
|
|
29
|
+
/** What the batch grows by after a frame that came on time. */
|
|
30
|
+
export declare const MOUNT_BATCH_GROWTH = 8;
|
|
31
|
+
/** A frame that comes later than this after the one before it (a frame at 60 Hz is 16.7 ms) says the last batch was too much. */
|
|
32
|
+
export declare const SLOW_FRAME_MS = 24;
|
|
33
|
+
/** A frame that comes sooner than this after the one before it says the last batch left room. */
|
|
34
|
+
export declare const QUICK_FRAME_MS = 20;
|
|
35
|
+
/** Frames further apart than this were not being drawn (a hidden tab): they say nothing of how much a batch costs. */
|
|
36
|
+
export declare const PAUSED_FRAME_MS = 500;
|
|
37
|
+
/** The list before anything was handed over (and the list of an empty board): one shared list. */
|
|
38
|
+
export declare const NOTHING_MOUNTED: readonly SceneObject[];
|
|
39
|
+
/** What the board knows when it asks: the records, where the view is, and the text that is being typed in. */
|
|
40
|
+
export interface MountedSceneInput {
|
|
41
|
+
scene: Scene;
|
|
42
|
+
viewport: Viewport;
|
|
43
|
+
/** The size of the board element in CSS pixels. A board with no size yet has every object drawn: nothing is known to be far. */
|
|
44
|
+
viewSize: Size;
|
|
45
|
+
/** The text that is being typed in, or null: it keeps its element wherever it is. */
|
|
46
|
+
editingTextId: ObjectId | null;
|
|
47
|
+
}
|
|
48
|
+
export interface MountedSceneOptions {
|
|
49
|
+
/** Boards with fewer objects than this are not culled (default `CULLING_MINIMUM_OBJECTS`). */
|
|
50
|
+
minimumObjects?: number;
|
|
51
|
+
/**
|
|
52
|
+
* How many objects get an element in one frame. Left out, the number starts at `MOUNT_BATCH_SIZE` and follows how the frames
|
|
53
|
+
* are going; given, it stays what it is (what a test asks for).
|
|
54
|
+
*/
|
|
55
|
+
batchSize?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Calls `callback` at the next frame, with the time of that frame when it is known, and returns what cancels it (default:
|
|
58
|
+
* `requestAnimationFrame`). Where there is no frame to wait for (the server) every object that is wanted is made at once.
|
|
59
|
+
*/
|
|
60
|
+
scheduleFrame?: (callback: (frameTime?: number) => void) => () => void;
|
|
61
|
+
}
|
|
62
|
+
export interface MountedScene extends Readable<readonly SceneObject[]> {
|
|
63
|
+
/**
|
|
64
|
+
* Takes what the board knows now. Called at every frame of a pan or a drag, so it is quick when nothing that matters changed:
|
|
65
|
+
* the same records, the view still inside the near area, the same text being typed in.
|
|
66
|
+
*/
|
|
67
|
+
take(input: MountedSceneInput): void;
|
|
68
|
+
/** Stops what is waiting for a frame. The store keeps its last list. */
|
|
69
|
+
destroy(): void;
|
|
70
|
+
}
|
|
71
|
+
export declare function createMountedScene(options?: MountedSceneOptions): MountedScene;
|