@widgetic/canvas 0.5.45 → 0.5.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -2
- package/dist/canvas/host/CanvasHost.js +1615 -1847
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +21 -21
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +35 -41
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +9 -2
- package/dist/engine/EngineCore.js +798 -907
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +84 -96
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.js +160 -224
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +32 -65
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +267 -310
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +35 -39
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.js +6 -17
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.js +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/poster/boardPlacement.js +28 -30
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +8 -0
- package/dist/settings/workspaceToolSettings.js +35 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +137 -169
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +2 -2
|
@@ -11,35 +11,24 @@
|
|
|
11
11
|
* hand, and scaling the line must not change how thick it is where the hand dwelled. Everything here is plain functions over
|
|
12
12
|
* plain records, so the same stroke is drawn in the editor, the screenshot rasterizer and the tests.
|
|
13
13
|
*/
|
|
14
|
-
var __assign = (this && this.__assign) || function () {
|
|
15
|
-
__assign = Object.assign || function(t) {
|
|
16
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
17
|
-
s = arguments[i];
|
|
18
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
19
|
-
t[p] = s[p];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
return __assign.apply(this, arguments);
|
|
24
|
-
};
|
|
25
14
|
import { SHAPE_STYLE_DEFAULTS, createObjectId, createPathObject } from './defaults.js';
|
|
26
15
|
import { brushOptions, brushReach, brushSizeFor, circlePathData, outlineOf, outlinePathData, outlineWithPressures, strokePointsOf, strokePointsOfLine } from './freehand.js';
|
|
27
16
|
import { MIN_OBJECT_SIZE } from './types.js';
|
|
28
17
|
/** The most points of a line a stroke keeps; a longer line is thinned further, so a stroke never grows without bound. */
|
|
29
|
-
export
|
|
18
|
+
export const BRUSH_MAX_POINTS = 4000;
|
|
30
19
|
// The points of a stroke closer together than this fraction of the brush (and than a unit of the board) add nothing the outline
|
|
31
20
|
// shows: it leaves out points closer than 0.62 of the brush on both of its sides already.
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
const POINT_GAP_OF_SIZE = 0.3;
|
|
22
|
+
const MINIMUM_POINT_GAP = 0.75;
|
|
34
23
|
// The decimals a stored point keeps: a hundredth of a unit is far finer than a pixel at the zoom that goes up to eight.
|
|
35
|
-
|
|
24
|
+
const COORDINATE_DECIMALS = 2;
|
|
36
25
|
// A line that never leaves this distance (in units of the board) from where it began is a click: a dot at the pointer.
|
|
37
|
-
|
|
26
|
+
const DOT_REACH = 1;
|
|
38
27
|
// The pressure of a dot made with a mouse or a finger: the middle of the range, as a line drawn at an even pressure has.
|
|
39
|
-
|
|
28
|
+
const DOT_PRESSURE = 0.5;
|
|
40
29
|
/** The narrowest width the Width control may give a brush stroke. */
|
|
41
|
-
export
|
|
42
|
-
|
|
30
|
+
export const MIN_BRUSH_WIDTH = 1;
|
|
31
|
+
const roundTo = (value, decimals) => Math.round(value * 10 ** decimals) / 10 ** decimals;
|
|
43
32
|
/** Whether an object is a brush stroke (a path that was drawn with the Draw tool and holds its line). */
|
|
44
33
|
export function isBrushStroke(object) {
|
|
45
34
|
return object.type === 'path' && !!object.ink;
|
|
@@ -53,37 +42,30 @@ export function brushOverflow(shape) {
|
|
|
53
42
|
}
|
|
54
43
|
/** The line a brush stroke follows, in the coordinates of its box (what the shape snap measures). */
|
|
55
44
|
export function brushCentreline(shape) {
|
|
56
|
-
return shape.ink.points.map(
|
|
57
|
-
var x = _a[0], y = _a[1];
|
|
58
|
-
return ({ x: x, y: y });
|
|
59
|
-
});
|
|
45
|
+
return shape.ink.points.map(([x, y]) => ({ x, y }));
|
|
60
46
|
}
|
|
61
47
|
/**
|
|
62
48
|
* The outline of a stored line, as path data: drawn again from the points and the pressures it holds, at the width of the brush.
|
|
63
49
|
* Always something to draw: a line the outline cannot be made of (one point, or none) is a dot.
|
|
64
50
|
*/
|
|
65
51
|
export function brushOutlineData(ink, strokeWidth) {
|
|
66
|
-
|
|
67
|
-
var size = brushSizeFor(strokeWidth);
|
|
52
|
+
const size = brushSizeFor(strokeWidth);
|
|
68
53
|
// The pressure is already in the points, so it is read, whatever it came from.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return ({ x: x, y: y, pressure: pressure });
|
|
73
|
-
}));
|
|
74
|
-
var data = outlinePathData(outlineOf(points, options));
|
|
54
|
+
const options = { ...brushOptions(size, ink.pressure, true), simulatePressure: false };
|
|
55
|
+
const points = strokePointsOfLine(ink.points.map(([x, y, pressure]) => ({ x, y, pressure })));
|
|
56
|
+
const data = outlinePathData(outlineOf(points, options));
|
|
75
57
|
if (data)
|
|
76
58
|
return data;
|
|
77
|
-
|
|
59
|
+
const center = points[0] ?? { x: 0, y: 0 };
|
|
78
60
|
return circlePathData(center, Math.max(0.5, size / 2));
|
|
79
61
|
}
|
|
80
62
|
/** The points of a smoothed line that the outline needs, with the pressure each was drawn with. */
|
|
81
63
|
function keptPoints(points, pressures, size) {
|
|
82
|
-
|
|
64
|
+
let gap = Math.max(MINIMUM_POINT_GAP, size * POINT_GAP_OF_SIZE);
|
|
83
65
|
for (;;) {
|
|
84
|
-
|
|
85
|
-
for (
|
|
86
|
-
|
|
66
|
+
const kept = [{ point: points[0], pressure: pressures[0] }];
|
|
67
|
+
for (let index = 1; index < points.length - 1; index += 1) {
|
|
68
|
+
const previous = kept[kept.length - 1].point;
|
|
87
69
|
if (Math.hypot(points[index].x - previous.x, points[index].y - previous.y) >= gap) {
|
|
88
70
|
kept.push({ point: points[index], pressure: pressures[index] });
|
|
89
71
|
}
|
|
@@ -100,94 +82,100 @@ function keptPoints(points, pressures, size) {
|
|
|
100
82
|
* The stroke for the samples of a pointer, in world units: the box of its line, the line itself with its pressure, and the
|
|
101
83
|
* outline to draw. Null when there is nothing to draw.
|
|
102
84
|
*/
|
|
103
|
-
export function buildBrushStroke(samples, options) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var pressure = (_b = options.pressure) !== null && _b !== void 0 ? _b : 'speed';
|
|
108
|
-
var size = brushSizeFor(strokeWidth);
|
|
85
|
+
export function buildBrushStroke(samples, options = {}) {
|
|
86
|
+
const strokeWidth = options.strokeWidth ?? SHAPE_STYLE_DEFAULTS.inkStrokeWidth;
|
|
87
|
+
const pressure = options.pressure ?? 'speed';
|
|
88
|
+
const size = brushSizeFor(strokeWidth);
|
|
109
89
|
// A line of one pressure reads that pressure at every sample, and is not smoothed (smoothing is what makes a line trail the hand).
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.filter(
|
|
115
|
-
.map(
|
|
90
|
+
const steadyPressure = typeof options.steadyPressure === 'number' && Number.isFinite(options.steadyPressure) ? Math.min(1, Math.max(0, options.steadyPressure)) : null;
|
|
91
|
+
const brushLine = brushOptions(size, pressure, options.finished === true);
|
|
92
|
+
const lineOptions = steadyPressure === null ? brushLine : { ...brushLine, streamline: 0, simulatePressure: false };
|
|
93
|
+
const usable = samples
|
|
94
|
+
.filter((sample) => Number.isFinite(sample.x) && Number.isFinite(sample.y))
|
|
95
|
+
.map((sample) => (steadyPressure === null ? sample : { x: sample.x, y: sample.y, pressure: steadyPressure }));
|
|
116
96
|
if (usable.length === 0)
|
|
117
97
|
return null;
|
|
118
|
-
|
|
119
|
-
if (usable.every(
|
|
98
|
+
let kept;
|
|
99
|
+
if (usable.every((sample) => Math.hypot(sample.x - usable[0].x, sample.y - usable[0].y) < DOT_REACH)) {
|
|
120
100
|
// A click is a dot where the pointer went down: the line has one point, so nothing is drawn a pixel away from it.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
kept = [{ point
|
|
101
|
+
const penPressure = usable.reduce((most, sample) => Math.max(most, sample.pressure ?? 0), 0);
|
|
102
|
+
const dotPressure = pressure === 'pen' && penPressure > 0 ? Math.min(1, penPressure) : DOT_PRESSURE;
|
|
103
|
+
const point = { x: usable[0].x, y: usable[0].y, pressure: dotPressure, vectorX: 0, vectorY: 0, distance: 0, runningLength: 0 };
|
|
104
|
+
kept = [{ point, pressure: dotPressure }];
|
|
125
105
|
}
|
|
126
106
|
else {
|
|
127
|
-
|
|
107
|
+
const smoothed = strokePointsOf(usable, lineOptions);
|
|
128
108
|
// The pass that works the pressure out (from the speed, or read from the pen) so that it can be kept.
|
|
129
|
-
|
|
109
|
+
const { pressures } = outlineWithPressures(smoothed, lineOptions);
|
|
130
110
|
kept = keptPoints(smoothed, pressures, size);
|
|
131
111
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (
|
|
137
|
-
var point = kept_1[_i].point;
|
|
112
|
+
let minX = Infinity;
|
|
113
|
+
let minY = Infinity;
|
|
114
|
+
let maxX = -Infinity;
|
|
115
|
+
let maxY = -Infinity;
|
|
116
|
+
for (const { point } of kept) {
|
|
138
117
|
minX = Math.min(minX, point.x);
|
|
139
118
|
minY = Math.min(minY, point.y);
|
|
140
119
|
maxX = Math.max(maxX, point.x);
|
|
141
120
|
maxY = Math.max(maxY, point.y);
|
|
142
121
|
}
|
|
143
122
|
// A line that is flat on one axis (a horizontal line, a dot) gets a box one unit thick, with the line in its middle.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
points: kept.map(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
];
|
|
158
|
-
}),
|
|
159
|
-
pressure: pressure
|
|
123
|
+
const flatX = maxX - minX < MIN_OBJECT_SIZE;
|
|
124
|
+
const flatY = maxY - minY < MIN_OBJECT_SIZE;
|
|
125
|
+
const boxX = flatX ? (minX + maxX) / 2 - MIN_OBJECT_SIZE / 2 : minX;
|
|
126
|
+
const boxY = flatY ? (minY + maxY) / 2 - MIN_OBJECT_SIZE / 2 : minY;
|
|
127
|
+
const width = flatX ? MIN_OBJECT_SIZE : maxX - minX;
|
|
128
|
+
const height = flatY ? MIN_OBJECT_SIZE : maxY - minY;
|
|
129
|
+
const ink = {
|
|
130
|
+
points: kept.map(({ point, pressure: pointPressure }) => [
|
|
131
|
+
roundTo(point.x - boxX, COORDINATE_DECIMALS),
|
|
132
|
+
roundTo(point.y - boxY, COORDINATE_DECIMALS),
|
|
133
|
+
roundTo(pointPressure, COORDINATE_DECIMALS)
|
|
134
|
+
]),
|
|
135
|
+
pressure
|
|
160
136
|
};
|
|
161
|
-
|
|
137
|
+
const createId = options.createId ?? createObjectId;
|
|
162
138
|
// The whole line shows through as much as it was asked to; a line that was not asked anything is fully opaque, as an object is.
|
|
163
|
-
|
|
164
|
-
return createPathObject(
|
|
139
|
+
const opacity = typeof options.opacity === 'number' && Number.isFinite(options.opacity) ? Math.min(1, Math.max(0, options.opacity)) : null;
|
|
140
|
+
return createPathObject({
|
|
141
|
+
id: createId('obj'),
|
|
142
|
+
x: boxX,
|
|
143
|
+
y: boxY,
|
|
144
|
+
width,
|
|
145
|
+
height,
|
|
146
|
+
d: brushOutlineData(ink, strokeWidth),
|
|
147
|
+
shape: null,
|
|
165
148
|
// The brush is filled: its colour is the fill of the outline, and the outline has no stroke of its own.
|
|
166
|
-
fill:
|
|
149
|
+
fill: options.color ?? SHAPE_STYLE_DEFAULTS.inkStroke,
|
|
150
|
+
fillOpacity: 1,
|
|
151
|
+
stroke: 'transparent',
|
|
152
|
+
strokeWidth,
|
|
153
|
+
lineCap: 'round',
|
|
154
|
+
lineJoin: 'round',
|
|
155
|
+
...(opacity === null ? {} : { opacity }),
|
|
156
|
+
ink
|
|
157
|
+
});
|
|
167
158
|
}
|
|
168
159
|
/**
|
|
169
160
|
* The stroke with its line scaled (and mirrored) into a new box and its outline drawn again at the brush width: the line goes
|
|
170
161
|
* where the box goes, the brush stays as wide as it was. Only `d`, `ink`, the size of the box and `strokeWidth` are written;
|
|
171
162
|
* where the box is, and how it is turned, is the caller's.
|
|
172
163
|
*/
|
|
173
|
-
export function reshapeBrushStroke(shape, change) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
var x = _a[0], y = _a[1], pressure = _a[2];
|
|
183
|
-
var scaledX = x * scaleX;
|
|
184
|
-
var scaledY = y * scaleY;
|
|
164
|
+
export function reshapeBrushStroke(shape, change = {}) {
|
|
165
|
+
const width = Math.max(MIN_OBJECT_SIZE, change.width ?? shape.width);
|
|
166
|
+
const height = Math.max(MIN_OBJECT_SIZE, change.height ?? shape.height);
|
|
167
|
+
const strokeWidth = change.strokeWidth ?? shape.strokeWidth;
|
|
168
|
+
const scaleX = shape.width > 0 ? width / shape.width : 1;
|
|
169
|
+
const scaleY = shape.height > 0 ? height / shape.height : 1;
|
|
170
|
+
const points = shape.ink.points.map(([x, y, pressure]) => {
|
|
171
|
+
const scaledX = x * scaleX;
|
|
172
|
+
const scaledY = y * scaleY;
|
|
185
173
|
return [
|
|
186
174
|
roundTo(change.flipX ? width - scaledX : scaledX, COORDINATE_DECIMALS),
|
|
187
175
|
roundTo(change.flipY ? height - scaledY : scaledY, COORDINATE_DECIMALS),
|
|
188
176
|
pressure
|
|
189
177
|
];
|
|
190
178
|
});
|
|
191
|
-
|
|
192
|
-
return
|
|
179
|
+
const ink = { points, pressure: shape.ink.pressure };
|
|
180
|
+
return { ...shape, width, height, strokeWidth, ink, d: brushOutlineData(ink, strokeWidth) };
|
|
193
181
|
}
|
|
@@ -20,44 +20,33 @@
|
|
|
20
20
|
*
|
|
21
21
|
* Nothing here knows the clock or the page: the engine asks for the view at a progress, and a test asks for the same.
|
|
22
22
|
*/
|
|
23
|
-
var __assign = (this && this.__assign) || function () {
|
|
24
|
-
__assign = Object.assign || function(t) {
|
|
25
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
26
|
-
s = arguments[i];
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
}
|
|
30
|
-
return t;
|
|
31
|
-
};
|
|
32
|
-
return __assign.apply(this, arguments);
|
|
33
|
-
};
|
|
34
23
|
import { clampNumber } from './geometry.js';
|
|
35
24
|
import { clampZoom, screenToWorld } from './viewport.js';
|
|
36
25
|
/** The shape a move has when nobody chose one: the position and the zoom ease together. */
|
|
37
|
-
export
|
|
26
|
+
export const DEFAULT_CAMERA_PATH_SHAPE = 'ease';
|
|
38
27
|
/** The shortest a move lasts when nobody gave its length, in milliseconds: a shorter one is too quick for the eye to follow. */
|
|
39
|
-
export
|
|
28
|
+
export const CAMERA_MOVE_MIN_DURATION_MS = 380;
|
|
40
29
|
/** The longest a move lasts when nobody gave its length, in milliseconds: a long way across the board still takes under a second. */
|
|
41
|
-
export
|
|
30
|
+
export const CAMERA_MOVE_MAX_DURATION_MS = 1000;
|
|
42
31
|
/** The time for each unit of the length of a path, in milliseconds. */
|
|
43
|
-
export
|
|
32
|
+
export const CAMERA_MOVE_MS_PER_UNIT = 800;
|
|
44
33
|
/**
|
|
45
34
|
* The share of the time a move takes that a quick move takes (`durationScale` of the move options). The double click on the empty
|
|
46
35
|
* board and Ctrl/Cmd+0 use it: they answer something the person has just done and should feel brisk, while a move a page asks for
|
|
47
36
|
* keeps the time its length gives.
|
|
48
37
|
*/
|
|
49
|
-
export
|
|
38
|
+
export const QUICK_CAMERA_MOVE_SCALE = 0.65;
|
|
50
39
|
/**
|
|
51
40
|
* How much the path zooms out on its way when the move is long (ρ in the paper). The square root of 2 is the value its authors
|
|
52
41
|
* found the most pleasing: a larger one zooms out more, and 0 would be a straight line.
|
|
53
42
|
*/
|
|
54
|
-
|
|
43
|
+
const PATH_CURVATURE = Math.SQRT2;
|
|
55
44
|
/** A move whose centres are closer than this fraction of the narrower view is a plain zoom: there is nothing to pan. */
|
|
56
|
-
|
|
45
|
+
const PLAIN_ZOOM_DISTANCE_RATIO = 1e-6;
|
|
57
46
|
/** Two viewports less than this many pixels apart look the same to a person. */
|
|
58
|
-
|
|
47
|
+
const SAME_VIEWPORT_PIXELS = 0.5;
|
|
59
48
|
/** Two zooms that differ by less than this fraction look the same to a person. */
|
|
60
|
-
|
|
49
|
+
const SAME_ZOOM_RATIO = 1e-4;
|
|
61
50
|
/** The view that a viewport shows in a board element of `viewSize`. */
|
|
62
51
|
export function cameraOfViewport(viewport, viewSize) {
|
|
63
52
|
return { center: screenToWorld(viewport, { x: viewSize.width / 2, y: viewSize.height / 2 }), zoom: viewport.zoom };
|
|
@@ -78,14 +67,14 @@ export function viewportsMatch(first, second) {
|
|
|
78
67
|
}
|
|
79
68
|
/** Slow start, quick middle, slow end: the way a person expects a camera to move. `progress` and the answer are between 0 and 1. */
|
|
80
69
|
export function easeInOutCubic(progress) {
|
|
81
|
-
|
|
82
|
-
return clampedProgress < 0.5 ? 4 *
|
|
70
|
+
const clampedProgress = clampNumber(progress, 0, 1);
|
|
71
|
+
return clampedProgress < 0.5 ? 4 * clampedProgress ** 3 : 1 - (-2 * clampedProgress + 2) ** 3 / 2;
|
|
83
72
|
}
|
|
84
73
|
function isUsableView(view) {
|
|
85
74
|
return Number.isFinite(view.center.x) && Number.isFinite(view.center.y) && Number.isFinite(view.zoom) && view.zoom > 0;
|
|
86
75
|
}
|
|
87
76
|
/** A zoom ratio this close to 1 (its logarithm is this close to 0) is no zoom: the centre then goes by the plain share of the progress. */
|
|
88
|
-
|
|
77
|
+
const NO_ZOOM_LOGARITHM = 1e-9;
|
|
89
78
|
/**
|
|
90
79
|
* The view between two views with no detour: the zoom changes by the same factor at every step, and the centre goes along the
|
|
91
80
|
* straight line between the two centres, the way it does when a person zooms about one fixed point of the board and pans nothing
|
|
@@ -98,8 +87,8 @@ var NO_ZOOM_LOGARITHM = 1e-9;
|
|
|
98
87
|
* screen, as the zoom goes on; with no change of zoom it is `progress` itself, and zooming out it is the same formula.
|
|
99
88
|
*/
|
|
100
89
|
function straightView(from, to, progress) {
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
const zoomLogarithm = Math.log(to.zoom / from.zoom);
|
|
91
|
+
const lineShare = Math.abs(zoomLogarithm) < NO_ZOOM_LOGARITHM ? progress : Math.expm1(-progress * zoomLogarithm) / Math.expm1(-zoomLogarithm);
|
|
103
92
|
return {
|
|
104
93
|
center: { x: from.center.x + (to.center.x - from.center.x) * lineShare, y: from.center.y + (to.center.y - from.center.y) * lineShare },
|
|
105
94
|
zoom: clampZoom(from.zoom * Math.exp(zoomLogarithm * progress))
|
|
@@ -112,54 +101,53 @@ function straightView(from, to, progress) {
|
|
|
112
101
|
* `shape` is how the view goes (see `CameraPathShape`): by default the position and the zoom ease together, and `'fly'` takes the
|
|
113
102
|
* path of van Wijk and Nuij. How long the move lasts comes from the length of that path whichever shape is asked for.
|
|
114
103
|
*/
|
|
115
|
-
export function createCameraPath(from, to, viewSize, shape) {
|
|
116
|
-
if (shape === void 0) { shape = DEFAULT_CAMERA_PATH_SHAPE; }
|
|
104
|
+
export function createCameraPath(from, to, viewSize, shape = DEFAULT_CAMERA_PATH_SHAPE) {
|
|
117
105
|
// The path measures a view by the width of the world it shows along the longer side of the board.
|
|
118
|
-
|
|
106
|
+
const extent = Math.max(viewSize.width, viewSize.height);
|
|
119
107
|
if (!(extent > 0) || !isUsableView(from) || !isUsableView(to))
|
|
120
108
|
return null;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
const startWidth = extent / from.zoom;
|
|
110
|
+
const endWidth = extent / to.zoom;
|
|
111
|
+
const deltaX = to.center.x - from.center.x;
|
|
112
|
+
const deltaY = to.center.y - from.center.y;
|
|
113
|
+
const distance = Math.hypot(deltaX, deltaY);
|
|
114
|
+
let length;
|
|
115
|
+
let sampleAt;
|
|
128
116
|
if (distance < Math.min(startWidth, endWidth) * PLAIN_ZOOM_DISTANCE_RATIO) {
|
|
129
117
|
// Nothing to pan: a plain zoom, by the same factor at every step.
|
|
130
118
|
length = Math.log(endWidth / startWidth) / PATH_CURVATURE;
|
|
131
|
-
sampleAt =
|
|
119
|
+
sampleAt = (progress) => ({ fraction: progress, width: startWidth * Math.exp(PATH_CURVATURE * length * progress) });
|
|
132
120
|
}
|
|
133
121
|
else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
122
|
+
const curvatureSquared = PATH_CURVATURE ** 2;
|
|
123
|
+
const widthGrowth = endWidth ** 2 - startWidth ** 2;
|
|
124
|
+
const panPart = curvatureSquared ** 2 * distance ** 2;
|
|
137
125
|
// `asinh` rather than the logarithm of the square root: for a view that zooms in a long way with a short pan, the
|
|
138
126
|
// difference of two nearly equal numbers would come out as 0.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
length = (endAngle -
|
|
142
|
-
sampleAt =
|
|
143
|
-
|
|
127
|
+
const startAngle = -Math.asinh((widthGrowth + panPart) / (2 * startWidth * curvatureSquared * distance));
|
|
128
|
+
const endAngle = -Math.asinh((widthGrowth - panPart) / (2 * endWidth * curvatureSquared * distance));
|
|
129
|
+
length = (endAngle - startAngle) / PATH_CURVATURE;
|
|
130
|
+
sampleAt = (progress) => {
|
|
131
|
+
const along = PATH_CURVATURE * length * progress + startAngle;
|
|
144
132
|
return {
|
|
145
|
-
fraction: (startWidth / (
|
|
146
|
-
width: (startWidth * Math.cosh(
|
|
133
|
+
fraction: (startWidth / (curvatureSquared * distance)) * (Math.cosh(startAngle) * Math.tanh(along) - Math.sinh(startAngle)),
|
|
134
|
+
width: (startWidth * Math.cosh(startAngle)) / Math.cosh(along)
|
|
147
135
|
};
|
|
148
136
|
};
|
|
149
137
|
}
|
|
150
|
-
|
|
138
|
+
const pathLength = Number.isFinite(length) ? Math.abs(length) : 1;
|
|
151
139
|
return {
|
|
152
140
|
length: pathLength,
|
|
153
141
|
duration: clampNumber(pathLength * CAMERA_MOVE_MS_PER_UNIT, CAMERA_MOVE_MIN_DURATION_MS, CAMERA_MOVE_MAX_DURATION_MS),
|
|
154
|
-
at
|
|
142
|
+
at(progress) {
|
|
155
143
|
if (!Number.isFinite(progress) || progress <= 0)
|
|
156
|
-
return { center:
|
|
144
|
+
return { center: { ...from.center }, zoom: from.zoom };
|
|
157
145
|
if (progress >= 1)
|
|
158
|
-
return { center:
|
|
146
|
+
return { center: { ...to.center }, zoom: to.zoom };
|
|
159
147
|
// No detour: the centre and the zoom change at the same rate on the one progress, and arrive together.
|
|
160
148
|
if (shape !== 'fly')
|
|
161
149
|
return straightView(from, to, progress);
|
|
162
|
-
|
|
150
|
+
const sample = sampleAt(progress);
|
|
163
151
|
// A path that came out as something that is not a number (a move across a distance no board has) is walked in a straight line.
|
|
164
152
|
if (!Number.isFinite(sample.fraction) || !(sample.width > 0) || !Number.isFinite(sample.width))
|
|
165
153
|
return straightView(from, to, progress);
|
|
@@ -4,19 +4,8 @@
|
|
|
4
4
|
* Every factory takes only what differs from the defaults, so a tool says "a rectangle here, this big" and
|
|
5
5
|
* nothing else. Ids come from `createObjectId`; a test passes its own `id` and gets the same record every time.
|
|
6
6
|
*/
|
|
7
|
-
var __assign = (this && this.__assign) || function () {
|
|
8
|
-
__assign = Object.assign || function(t) {
|
|
9
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
10
|
-
s = arguments[i];
|
|
11
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
12
|
-
t[p] = s[p];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
|
-
return __assign.apply(this, arguments);
|
|
17
|
-
};
|
|
18
7
|
/** The look of a shape in the wireframe mode (the default of the canvas) and outside it. */
|
|
19
|
-
export
|
|
8
|
+
export const SHAPE_STYLE_DEFAULTS = {
|
|
20
9
|
wireframeFill: '#ffffff',
|
|
21
10
|
wireframeStroke: '#374151',
|
|
22
11
|
wireframeStrokeWidth: 2,
|
|
@@ -26,7 +15,7 @@ export var SHAPE_STYLE_DEFAULTS = {
|
|
|
26
15
|
inkStroke: '#1f2937',
|
|
27
16
|
inkStrokeWidth: 3
|
|
28
17
|
};
|
|
29
|
-
export
|
|
18
|
+
export const TEXT_DEFAULTS = {
|
|
30
19
|
fontSize: 20,
|
|
31
20
|
fontFamily: 'Inter',
|
|
32
21
|
color: '#111827',
|
|
@@ -41,23 +30,21 @@ export var TEXT_DEFAULTS = {
|
|
|
41
30
|
emptyTextMeasureStandIn: 'Type here'
|
|
42
31
|
};
|
|
43
32
|
/** The size of a shape that is placed by a click or a button, not dragged out. */
|
|
44
|
-
export
|
|
33
|
+
export const DEFAULT_OBJECT_SIZE = 100;
|
|
45
34
|
/** A random vivid colour, for a new shape on a board that is not in the wireframe mode. */
|
|
46
|
-
export function randomShapeFill(random) {
|
|
47
|
-
|
|
48
|
-
return "hsl(".concat(Math.floor(random() * 360), ", 70%, 50%)");
|
|
35
|
+
export function randomShapeFill(random = Math.random) {
|
|
36
|
+
return `hsl(${Math.floor(random() * 360)}, 70%, 50%)`;
|
|
49
37
|
}
|
|
50
|
-
|
|
38
|
+
let idCounter = 0;
|
|
51
39
|
/** A unique id: time, a counter and a random tail, so two tabs and two calls in one millisecond never collide. */
|
|
52
|
-
export function createObjectId(prefix) {
|
|
53
|
-
if (prefix === void 0) { prefix = 'obj'; }
|
|
40
|
+
export function createObjectId(prefix = 'obj') {
|
|
54
41
|
idCounter += 1;
|
|
55
|
-
|
|
56
|
-
return
|
|
42
|
+
const randomTail = Math.random().toString(36).slice(2, 8);
|
|
43
|
+
return `${prefix}_${Date.now().toString(36)}_${idCounter.toString(36)}${randomTail}`;
|
|
57
44
|
}
|
|
58
45
|
/** The dash pattern of a stroke style. Dotted uses zero-length dashes, which a round cap turns into dots. */
|
|
59
46
|
export function strokeDashArray(strokeStyle, strokeWidth) {
|
|
60
|
-
|
|
47
|
+
const unit = Math.max(2, strokeWidth);
|
|
61
48
|
switch (strokeStyle) {
|
|
62
49
|
case 'dashed':
|
|
63
50
|
return [unit * 4, unit * 2];
|
|
@@ -67,7 +54,7 @@ export function strokeDashArray(strokeStyle, strokeWidth) {
|
|
|
67
54
|
return null;
|
|
68
55
|
}
|
|
69
56
|
}
|
|
70
|
-
|
|
57
|
+
const BOX_DEFAULTS = {
|
|
71
58
|
parentId: null,
|
|
72
59
|
x: 0,
|
|
73
60
|
y: 0,
|
|
@@ -76,44 +63,98 @@ var BOX_DEFAULTS = {
|
|
|
76
63
|
rotation: 0,
|
|
77
64
|
opacity: 1
|
|
78
65
|
};
|
|
79
|
-
|
|
66
|
+
const PAINT_DEFAULTS = {
|
|
80
67
|
fill: SHAPE_STYLE_DEFAULTS.wireframeFill,
|
|
81
68
|
fillOpacity: 1,
|
|
82
69
|
stroke: SHAPE_STYLE_DEFAULTS.wireframeStroke,
|
|
83
70
|
strokeWidth: SHAPE_STYLE_DEFAULTS.wireframeStrokeWidth,
|
|
84
71
|
strokeStyle: 'solid'
|
|
85
72
|
};
|
|
86
|
-
export function createRectObject(fields) {
|
|
87
|
-
|
|
88
|
-
if (fields === void 0) { fields = {}; }
|
|
89
|
-
return __assign(__assign(__assign(__assign(__assign({}, BOX_DEFAULTS), PAINT_DEFAULTS), { roundness: 0 }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'rect' });
|
|
73
|
+
export function createRectObject(fields = {}) {
|
|
74
|
+
return { ...BOX_DEFAULTS, ...PAINT_DEFAULTS, roundness: 0, ...fields, id: fields.id ?? createObjectId(), type: 'rect' };
|
|
90
75
|
}
|
|
91
|
-
export function createEllipseObject(fields) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
export function createEllipseObject(fields = {}) {
|
|
77
|
+
return {
|
|
78
|
+
...BOX_DEFAULTS,
|
|
79
|
+
...PAINT_DEFAULTS,
|
|
80
|
+
aspectLocked: false,
|
|
81
|
+
...fields,
|
|
82
|
+
id: fields.id ?? createObjectId(),
|
|
83
|
+
type: 'ellipse'
|
|
84
|
+
};
|
|
95
85
|
}
|
|
96
|
-
export function createPathObject(fields) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
export function createPathObject(fields = {}) {
|
|
87
|
+
return {
|
|
88
|
+
...BOX_DEFAULTS,
|
|
89
|
+
...PAINT_DEFAULTS,
|
|
90
|
+
d: '',
|
|
91
|
+
shape: null,
|
|
92
|
+
roundness: 0,
|
|
93
|
+
aspectLocked: false,
|
|
94
|
+
flipX: false,
|
|
95
|
+
flipY: false,
|
|
96
|
+
lineCap: 'round',
|
|
97
|
+
lineJoin: 'round',
|
|
98
|
+
ink: null,
|
|
99
|
+
arrow: null,
|
|
100
|
+
...fields,
|
|
101
|
+
id: fields.id ?? createObjectId(),
|
|
102
|
+
type: 'path'
|
|
103
|
+
};
|
|
100
104
|
}
|
|
101
|
-
export function createTextObject(fields) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
export function createTextObject(fields = {}) {
|
|
106
|
+
return {
|
|
107
|
+
...BOX_DEFAULTS,
|
|
108
|
+
width: TEXT_DEFAULTS.minimumWidth,
|
|
109
|
+
height: Math.ceil(TEXT_DEFAULTS.fontSize * 1.2),
|
|
110
|
+
text: '',
|
|
111
|
+
color: TEXT_DEFAULTS.color,
|
|
112
|
+
fontSize: TEXT_DEFAULTS.fontSize,
|
|
113
|
+
fontFamily: TEXT_DEFAULTS.fontFamily,
|
|
114
|
+
fontWeight: 'normal',
|
|
115
|
+
fontStyle: 'normal',
|
|
116
|
+
underline: false,
|
|
117
|
+
align: 'left',
|
|
118
|
+
lineHeight: 1.2,
|
|
119
|
+
padding: 0,
|
|
120
|
+
backgroundColor: 'transparent',
|
|
121
|
+
autoWidth: true,
|
|
122
|
+
...fields,
|
|
123
|
+
id: fields.id ?? createObjectId(),
|
|
124
|
+
type: 'text'
|
|
125
|
+
};
|
|
105
126
|
}
|
|
106
|
-
export function createImageObject(fields) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
export function createImageObject(fields = {}) {
|
|
128
|
+
return {
|
|
129
|
+
...BOX_DEFAULTS,
|
|
130
|
+
width: 300,
|
|
131
|
+
height: 200,
|
|
132
|
+
src: null,
|
|
133
|
+
imageRef: null,
|
|
134
|
+
fileName: null,
|
|
135
|
+
libraryFileId: null,
|
|
136
|
+
libraryFileUrl: null,
|
|
137
|
+
naturalWidth: 0,
|
|
138
|
+
naturalHeight: 0,
|
|
139
|
+
...fields,
|
|
140
|
+
id: fields.id ?? createObjectId(),
|
|
141
|
+
type: 'image'
|
|
142
|
+
};
|
|
110
143
|
}
|
|
111
144
|
export function createWidgetObject(fields) {
|
|
112
|
-
|
|
113
|
-
|
|
145
|
+
return {
|
|
146
|
+
...BOX_DEFAULTS,
|
|
147
|
+
width: 360,
|
|
148
|
+
height: 268,
|
|
149
|
+
widgetName: null,
|
|
150
|
+
isPrimary: false,
|
|
151
|
+
thumbnail: null,
|
|
152
|
+
thumbnailRef: null,
|
|
153
|
+
...fields,
|
|
154
|
+
id: fields.id ?? createObjectId(),
|
|
155
|
+
type: 'widget'
|
|
156
|
+
};
|
|
114
157
|
}
|
|
115
|
-
export function createGroupObject(fields) {
|
|
116
|
-
|
|
117
|
-
if (fields === void 0) { fields = {}; }
|
|
118
|
-
return __assign(__assign({ parentId: null }, fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId('group'), type: 'group' });
|
|
158
|
+
export function createGroupObject(fields = {}) {
|
|
159
|
+
return { parentId: null, ...fields, id: fields.id ?? createObjectId('group'), type: 'group' };
|
|
119
160
|
}
|