@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
|
@@ -8,17 +8,6 @@
|
|
|
8
8
|
* A handle is dragged in the frame's own (unrotated) space, so a turned shape resizes along its own edges.
|
|
9
9
|
* The edge opposite the handle (or the centre, with Alt) stays where it is in the world.
|
|
10
10
|
*/
|
|
11
|
-
var __assign = (this && this.__assign) || function () {
|
|
12
|
-
__assign = Object.assign || function(t) {
|
|
13
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
-
s = arguments[i];
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
}
|
|
18
|
-
return t;
|
|
19
|
-
};
|
|
20
|
-
return __assign.apply(this, arguments);
|
|
21
|
-
};
|
|
22
11
|
import { isArrow, transformArrow } from './arrow.js';
|
|
23
12
|
import { isBrushStroke, reshapeBrushStroke } from './brush.js';
|
|
24
13
|
import { rotatedBoxBounds, unionRects, worldToBoxLocal, clampNumber } from './geometry.js';
|
|
@@ -26,7 +15,7 @@ import { applyMatrixToPoint, boxToWorldMatrix, degreesToRadians, normalizeDegree
|
|
|
26
15
|
import { parsePathData, scalePathCommands, mirrorPathCommands, serializePathData } from './pathData.js';
|
|
27
16
|
import { regeneratedPathCommands } from './shapePaths.js';
|
|
28
17
|
import { MIN_OBJECT_SIZE } from './types.js';
|
|
29
|
-
|
|
18
|
+
const HANDLE_DIRECTIONS = {
|
|
30
19
|
nw: { x: -1, y: -1 },
|
|
31
20
|
n: { x: 0, y: -1 },
|
|
32
21
|
ne: { x: 1, y: -1 },
|
|
@@ -44,11 +33,11 @@ export function selectionFrameOf(shapes) {
|
|
|
44
33
|
if (shapes.length === 0)
|
|
45
34
|
return null;
|
|
46
35
|
if (shapes.length === 1) {
|
|
47
|
-
|
|
36
|
+
const [shape] = shapes;
|
|
48
37
|
return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
|
|
49
38
|
}
|
|
50
|
-
|
|
51
|
-
return union ?
|
|
39
|
+
const union = unionRects(shapes.map((shape) => rotatedBoxBounds(shape)));
|
|
40
|
+
return union ? { ...union, rotation: 0 } : null;
|
|
52
41
|
}
|
|
53
42
|
/** The centre of a frame in the world. */
|
|
54
43
|
export function frameCenter(frame) {
|
|
@@ -58,31 +47,29 @@ export function frameCenter(frame) {
|
|
|
58
47
|
* The frame that results from dragging `handle` to a world point.
|
|
59
48
|
* `frame` is the frame when the drag began (not the one the last pointer move produced).
|
|
60
49
|
*/
|
|
61
|
-
export function computeResizedFrame(frame, handle, pointerWorld, options) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var direction = HANDLE_DIRECTIONS[handle];
|
|
66
|
-
var local = worldToBoxLocal(frame, pointerWorld);
|
|
50
|
+
export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
|
|
51
|
+
const minimumSize = options.minimumSize ?? MIN_OBJECT_SIZE;
|
|
52
|
+
const direction = HANDLE_DIRECTIONS[handle];
|
|
53
|
+
const local = worldToBoxLocal(frame, pointerWorld);
|
|
67
54
|
if (!local)
|
|
68
|
-
return
|
|
69
|
-
|
|
55
|
+
return { ...frame, flipX: false, flipY: false };
|
|
56
|
+
const { width, height } = frame;
|
|
70
57
|
// How far the handle's edge is from the anchor (the opposite edge, or the centre), signed: negative means
|
|
71
58
|
// the pointer has crossed the anchor.
|
|
72
|
-
|
|
59
|
+
const extentX = direction.x === 0
|
|
73
60
|
? width
|
|
74
61
|
: options.fromCenter
|
|
75
62
|
? (local.x - width / 2) * direction.x * 2
|
|
76
63
|
: (local.x - (direction.x > 0 ? 0 : width)) * direction.x;
|
|
77
|
-
|
|
64
|
+
const extentY = direction.y === 0
|
|
78
65
|
? height
|
|
79
66
|
: options.fromCenter
|
|
80
67
|
? (local.y - height / 2) * direction.y * 2
|
|
81
68
|
: (local.y - (direction.y > 0 ? 0 : height)) * direction.y;
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
let signedWidth = extentX;
|
|
70
|
+
let signedHeight = extentY;
|
|
84
71
|
if (options.keepAspect && width > 0 && height > 0) {
|
|
85
|
-
|
|
72
|
+
let scale;
|
|
86
73
|
if (direction.x !== 0 && direction.y !== 0) {
|
|
87
74
|
scale = Math.max(Math.abs(extentX) / width, Math.abs(extentY) / height);
|
|
88
75
|
}
|
|
@@ -92,14 +79,14 @@ export function computeResizedFrame(frame, handle, pointerWorld, options) {
|
|
|
92
79
|
else {
|
|
93
80
|
scale = Math.abs(extentY) / height;
|
|
94
81
|
}
|
|
95
|
-
|
|
82
|
+
const smallestScale = minimumSize / Math.min(width, height);
|
|
96
83
|
if (!options.allowFlip || scale < smallestScale)
|
|
97
84
|
scale = Math.max(scale, smallestScale);
|
|
98
85
|
signedWidth = (direction.x === 0 || extentX >= 0 ? 1 : -1) * width * scale;
|
|
99
86
|
signedHeight = (direction.y === 0 || extentY >= 0 ? 1 : -1) * height * scale;
|
|
100
87
|
}
|
|
101
|
-
|
|
102
|
-
|
|
88
|
+
let flipX = false;
|
|
89
|
+
let flipY = false;
|
|
103
90
|
if (signedWidth < 0) {
|
|
104
91
|
if (options.allowFlip)
|
|
105
92
|
flipX = true;
|
|
@@ -112,22 +99,22 @@ export function computeResizedFrame(frame, handle, pointerWorld, options) {
|
|
|
112
99
|
else
|
|
113
100
|
signedHeight = minimumSize;
|
|
114
101
|
}
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
const newWidth = Math.max(minimumSize, Math.abs(signedWidth));
|
|
103
|
+
const newHeight = Math.max(minimumSize, Math.abs(signedHeight));
|
|
117
104
|
// The centre of the new box in the frame's own space: half an extent from the anchor, towards the handle.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
const anchorX = direction.x > 0 ? 0 : width;
|
|
106
|
+
const anchorY = direction.y > 0 ? 0 : height;
|
|
107
|
+
const centerLocalX = direction.x === 0 || options.fromCenter ? width / 2 : anchorX + (direction.x * (flipX ? -newWidth : newWidth)) / 2;
|
|
108
|
+
const centerLocalY = direction.y === 0 || options.fromCenter ? height / 2 : anchorY + (direction.y * (flipY ? -newHeight : newHeight)) / 2;
|
|
109
|
+
const centerWorld = applyMatrixToPoint(boxToWorldMatrix(frame), { x: centerLocalX, y: centerLocalY });
|
|
123
110
|
return {
|
|
124
111
|
x: centerWorld.x - newWidth / 2,
|
|
125
112
|
y: centerWorld.y - newHeight / 2,
|
|
126
113
|
width: newWidth,
|
|
127
114
|
height: newHeight,
|
|
128
115
|
rotation: frame.rotation,
|
|
129
|
-
flipX
|
|
130
|
-
flipY
|
|
116
|
+
flipX,
|
|
117
|
+
flipY
|
|
131
118
|
};
|
|
132
119
|
}
|
|
133
120
|
/**
|
|
@@ -137,21 +124,18 @@ export function computeResizedFrame(frame, handle, pointerWorld, options) {
|
|
|
137
124
|
* is drawn again (its head keeps its size), text keeps its font size when it is resized from a side
|
|
138
125
|
* (wrapping) and scales it from a corner.
|
|
139
126
|
*/
|
|
140
|
-
export function resizeShapeToBox(shape, box, flip, textScale) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var height = Math.max(MIN_OBJECT_SIZE, box.height);
|
|
146
|
-
var rotation = (_a = box.rotation) !== null && _a !== void 0 ? _a : shape.rotation;
|
|
147
|
-
var base = __assign(__assign({}, shape), { x: box.x, y: box.y, width: width, height: height, rotation: rotation });
|
|
127
|
+
export function resizeShapeToBox(shape, box, flip = { flipX: false, flipY: false }, textScale = null) {
|
|
128
|
+
const width = Math.max(MIN_OBJECT_SIZE, box.width);
|
|
129
|
+
const height = Math.max(MIN_OBJECT_SIZE, box.height);
|
|
130
|
+
const rotation = box.rotation ?? shape.rotation;
|
|
131
|
+
const base = { ...shape, x: box.x, y: box.y, width, height, rotation };
|
|
148
132
|
switch (shape.type) {
|
|
149
133
|
case 'path': {
|
|
150
134
|
if (isArrow(shape)) {
|
|
151
135
|
// The points of the arrow go where the box goes (mirrored by a flip), and the arrow is drawn again from them.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
136
|
+
const mapPoint = (point) => {
|
|
137
|
+
let unitX = shape.width > 0 ? (point.x - shape.x) / shape.width : 0.5;
|
|
138
|
+
let unitY = shape.height > 0 ? (point.y - shape.y) / shape.height : 0.5;
|
|
155
139
|
if (flip.flipX)
|
|
156
140
|
unitX = 1 - unitX;
|
|
157
141
|
if (flip.flipY)
|
|
@@ -161,35 +145,35 @@ export function resizeShapeToBox(shape, box, flip, textScale) {
|
|
|
161
145
|
return transformArrow(shape, mapPoint);
|
|
162
146
|
}
|
|
163
147
|
// A flip toggles the mirror the shape already has.
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
const flipX = shape.flipX !== flip.flipX;
|
|
149
|
+
const flipY = shape.flipY !== flip.flipY;
|
|
166
150
|
if (isBrushStroke(shape)) {
|
|
167
151
|
// The line goes where the box goes (and is mirrored by this flip); the brush stays as wide as it was.
|
|
168
|
-
|
|
169
|
-
return
|
|
152
|
+
const reshaped = reshapeBrushStroke(shape, { width, height, flipX: flip.flipX, flipY: flip.flipY });
|
|
153
|
+
return { ...base, d: reshaped.d, ink: reshaped.ink, flipX, flipY };
|
|
170
154
|
}
|
|
171
|
-
|
|
172
|
-
|
|
155
|
+
const regenerated = regeneratedPathCommands(shape, width, height);
|
|
156
|
+
let commands;
|
|
173
157
|
if (regenerated) {
|
|
174
158
|
// Rebuilt from its key, so the mirror the shape had is applied again.
|
|
175
159
|
commands = mirrorPathCommands(regenerated, width, height, flipX, flipY);
|
|
176
160
|
}
|
|
177
161
|
else {
|
|
178
162
|
// Scaled from the path it has, which already holds the earlier mirrors: only this flip is applied.
|
|
179
|
-
|
|
180
|
-
|
|
163
|
+
const scaleX = shape.width > 0 ? width / shape.width : 1;
|
|
164
|
+
const scaleY = shape.height > 0 ? height / shape.height : 1;
|
|
181
165
|
commands = mirrorPathCommands(scalePathCommands(parsePathData(shape.d), scaleX, scaleY), width, height, flip.flipX, flip.flipY);
|
|
182
166
|
}
|
|
183
|
-
return
|
|
167
|
+
return { ...base, d: serializePathData(commands), flipX, flipY };
|
|
184
168
|
}
|
|
185
169
|
case 'text': {
|
|
186
|
-
|
|
170
|
+
const text = shape;
|
|
187
171
|
if (textScale !== null && textScale > 0) {
|
|
188
172
|
// A corner drag scales the letters with the box.
|
|
189
|
-
return
|
|
173
|
+
return { ...base, fontSize: clampNumber(text.fontSize * textScale, 4, 600) };
|
|
190
174
|
}
|
|
191
175
|
// A side drag only sets the width the text wraps at.
|
|
192
|
-
return
|
|
176
|
+
return { ...base, autoWidth: false };
|
|
193
177
|
}
|
|
194
178
|
default:
|
|
195
179
|
return base;
|
|
@@ -202,38 +186,38 @@ export function resizeShapeToBox(shape, box, flip, textScale) {
|
|
|
202
186
|
*/
|
|
203
187
|
export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
|
|
204
188
|
if (shapes.length === 1) {
|
|
205
|
-
|
|
206
|
-
|
|
189
|
+
const [shape] = shapes;
|
|
190
|
+
const cornerTextScale = shape.type === 'text' && isCornerHandle && startFrame.width > 0 ? resized.width / startFrame.width : null;
|
|
207
191
|
return [
|
|
208
192
|
resizeShapeToBox(shape, resized, { flipX: resized.flipX, flipY: resized.flipY }, cornerTextScale)
|
|
209
193
|
];
|
|
210
194
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
195
|
+
const scaleX = startFrame.width > 0 ? resized.width / startFrame.width : 1;
|
|
196
|
+
const scaleY = startFrame.height > 0 ? resized.height / startFrame.height : 1;
|
|
197
|
+
const mapPoint = (point) => {
|
|
198
|
+
let unitX = startFrame.width > 0 ? (point.x - startFrame.x) / startFrame.width : 0.5;
|
|
199
|
+
let unitY = startFrame.height > 0 ? (point.y - startFrame.y) / startFrame.height : 0.5;
|
|
216
200
|
if (resized.flipX)
|
|
217
201
|
unitX = 1 - unitX;
|
|
218
202
|
if (resized.flipY)
|
|
219
203
|
unitY = 1 - unitY;
|
|
220
204
|
return { x: resized.x + unitX * resized.width, y: resized.y + unitY * resized.height };
|
|
221
205
|
};
|
|
222
|
-
return shapes.map(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
206
|
+
return shapes.map((shape) => {
|
|
207
|
+
const radians = degreesToRadians(shape.rotation);
|
|
208
|
+
const cosine = Math.cos(radians);
|
|
209
|
+
const sine = Math.sin(radians);
|
|
226
210
|
// The shape's own axes are stretched by the frame; the lengths along them give its new size.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
211
|
+
const widthFactor = Math.hypot(scaleX * cosine, scaleY * sine);
|
|
212
|
+
const heightFactor = Math.hypot(scaleX * sine, scaleY * cosine);
|
|
213
|
+
const newWidth = Math.max(MIN_OBJECT_SIZE, shape.width * widthFactor);
|
|
214
|
+
const newHeight = Math.max(MIN_OBJECT_SIZE, shape.height * heightFactor);
|
|
215
|
+
const center = mapPoint({ x: shape.x + shape.width / 2, y: shape.y + shape.height / 2 });
|
|
232
216
|
// A mirrored shape turns the other way.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
217
|
+
const mirrors = (resized.flipX ? 1 : 0) + (resized.flipY ? 1 : 0);
|
|
218
|
+
const rotation = mirrors % 2 === 1 ? normalizeDegrees(-shape.rotation) : shape.rotation;
|
|
219
|
+
const box = { x: center.x - newWidth / 2, y: center.y - newHeight / 2, width: newWidth, height: newHeight, rotation };
|
|
220
|
+
const textScale = shape.type === 'text' ? (widthFactor + heightFactor) / 2 : null;
|
|
237
221
|
return resizeShapeToBox(shape, box, { flipX: resized.flipX, flipY: resized.flipY }, textScale);
|
|
238
222
|
});
|
|
239
223
|
}
|
|
@@ -242,21 +226,26 @@ export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
|
|
|
242
226
|
* turn (it is always upright): its points go round the point and it is drawn again between them.
|
|
243
227
|
*/
|
|
244
228
|
export function rotateShapesAbout(shapes, pivot, deltaDegrees) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return shapes.map(
|
|
229
|
+
const radians = degreesToRadians(deltaDegrees);
|
|
230
|
+
const cosine = Math.cos(radians);
|
|
231
|
+
const sine = Math.sin(radians);
|
|
232
|
+
return shapes.map((shape) => {
|
|
249
233
|
if (isArrow(shape)) {
|
|
250
|
-
return transformArrow(shape,
|
|
234
|
+
return transformArrow(shape, (point) => ({
|
|
251
235
|
x: pivot.x + (point.x - pivot.x) * cosine - (point.y - pivot.y) * sine,
|
|
252
236
|
y: pivot.y + (point.x - pivot.x) * sine + (point.y - pivot.y) * cosine
|
|
253
|
-
})
|
|
237
|
+
}));
|
|
254
238
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return
|
|
239
|
+
const centerX = shape.x + shape.width / 2 - pivot.x;
|
|
240
|
+
const centerY = shape.y + shape.height / 2 - pivot.y;
|
|
241
|
+
const rotatedX = pivot.x + centerX * cosine - centerY * sine;
|
|
242
|
+
const rotatedY = pivot.y + centerX * sine + centerY * cosine;
|
|
243
|
+
return {
|
|
244
|
+
...shape,
|
|
245
|
+
x: rotatedX - shape.width / 2,
|
|
246
|
+
y: rotatedY - shape.height / 2,
|
|
247
|
+
rotation: normalizeDegrees(shape.rotation + deltaDegrees)
|
|
248
|
+
};
|
|
260
249
|
});
|
|
261
250
|
}
|
|
262
251
|
/** The angle, in degrees, of the line from `center` to `point` (0 is to the right, growing clockwise on screen). */
|
|
@@ -196,7 +196,10 @@ export interface TextObject extends ObjectBase, BoxProps {
|
|
|
196
196
|
}
|
|
197
197
|
export interface ImageObject extends ObjectBase, BoxProps {
|
|
198
198
|
type: 'image';
|
|
199
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* A `data:` or `http(s)` address, or an object URL (`blob:`) the host's image store gave for `imageRef`, or null while the
|
|
201
|
+
* image is only a placeholder. An object URL is never written into the saved text: its `imageRef` is.
|
|
202
|
+
*/
|
|
200
203
|
src: string | null;
|
|
201
204
|
/** The reference under which the host's image store keeps the bytes, when they are not inline. */
|
|
202
205
|
imageRef: string | null;
|
|
@@ -215,7 +218,10 @@ export interface WidgetObject extends ObjectBase, BoxProps {
|
|
|
215
218
|
widgetName: string | null;
|
|
216
219
|
/** The widget the board is about (the host draws a mark around it in the advanced mode). */
|
|
217
220
|
isPrimary: boolean;
|
|
218
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* The last screenshot of the widget: inline bytes or an address (an object URL, `blob:`, is one the store gave for
|
|
223
|
+
* `thumbnailRef`: it is never written into the saved text, and `getWidgetShapeDataUrl` answers `null` for it).
|
|
224
|
+
*/
|
|
219
225
|
thumbnail: string | null;
|
|
220
226
|
/** The reference under which the host's image store keeps the screenshot. */
|
|
221
227
|
thumbnailRef: string | null;
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
* Nothing here knows about the DOM, Svelte or the host, so the same records run in Node tests.
|
|
18
18
|
*/
|
|
19
19
|
/** The version of the saved format. A file of any other version (the previous canvas wrote version 1, a string, `1.0`) is not read: there is no converter. */
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
20
|
+
export const CANVAS_DOCUMENT_VERSION = 2;
|
|
21
|
+
export const MIN_OBJECT_SIZE = 1;
|
|
22
|
+
export const MIN_ZOOM = 0.05;
|
|
23
|
+
export const MAX_ZOOM = 8;
|
|
24
24
|
/** True for the objects that carry a box (so not for a group). */
|
|
25
25
|
export function isBoxedObject(object) {
|
|
26
26
|
return object.type !== 'group';
|
|
@@ -5,22 +5,11 @@
|
|
|
5
5
|
* `viewport.x` and `viewport.y` are where the world origin lands on the board element, in CSS pixels, and
|
|
6
6
|
* `viewport.zoom` is the scale (1 is 100%). The world layer is drawn with `translate(x, y) scale(zoom)`.
|
|
7
7
|
*/
|
|
8
|
-
var __assign = (this && this.__assign) || function () {
|
|
9
|
-
__assign = Object.assign || function(t) {
|
|
10
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
-
s = arguments[i];
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
|
-
return __assign.apply(this, arguments);
|
|
18
|
-
};
|
|
19
8
|
import { clampNumber } from './geometry.js';
|
|
20
9
|
import { MAX_ZOOM, MIN_ZOOM } from './types.js';
|
|
21
|
-
export
|
|
10
|
+
export const INITIAL_VIEWPORT = { x: 0, y: 0, zoom: 1 };
|
|
22
11
|
/** The zoom levels the zoom buttons and the menu step through. */
|
|
23
|
-
export
|
|
12
|
+
export const ZOOM_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
|
|
24
13
|
export function clampZoom(zoom) {
|
|
25
14
|
if (!Number.isFinite(zoom))
|
|
26
15
|
return 1;
|
|
@@ -45,21 +34,21 @@ export function visibleWorldRect(viewport, viewSize) {
|
|
|
45
34
|
}
|
|
46
35
|
/** Changes the zoom and keeps the world point under `screenPoint` where it is (what the wheel and pinch do). */
|
|
47
36
|
export function zoomAtPoint(viewport, screenPoint, nextZoom) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return { x: screenPoint.x - worldPoint.x * zoom, y: screenPoint.y - worldPoint.y * zoom, zoom
|
|
37
|
+
const zoom = clampZoom(nextZoom);
|
|
38
|
+
const worldPoint = screenToWorld(viewport, screenPoint);
|
|
39
|
+
return { x: screenPoint.x - worldPoint.x * zoom, y: screenPoint.y - worldPoint.y * zoom, zoom };
|
|
51
40
|
}
|
|
52
41
|
export function panViewport(viewport, deltaX, deltaY) {
|
|
53
|
-
return
|
|
42
|
+
return { ...viewport, x: viewport.x + deltaX, y: viewport.y + deltaY };
|
|
54
43
|
}
|
|
55
44
|
/** The next step above (direction 1) or below (-1) the current zoom, or the same zoom at the end of the ladder. */
|
|
56
45
|
export function nextZoomStep(zoom, direction) {
|
|
57
|
-
|
|
46
|
+
const tolerance = 1e-6;
|
|
58
47
|
if (direction === 1) {
|
|
59
|
-
|
|
60
|
-
return step
|
|
48
|
+
const step = ZOOM_STEPS.find((candidate) => candidate > zoom + tolerance);
|
|
49
|
+
return step ?? ZOOM_STEPS[ZOOM_STEPS.length - 1];
|
|
61
50
|
}
|
|
62
|
-
for (
|
|
51
|
+
for (let index = ZOOM_STEPS.length - 1; index >= 0; index -= 1) {
|
|
63
52
|
if (ZOOM_STEPS[index] < zoom - tolerance)
|
|
64
53
|
return ZOOM_STEPS[index];
|
|
65
54
|
}
|
|
@@ -69,29 +58,27 @@ export function nextZoomStep(zoom, direction) {
|
|
|
69
58
|
* The view that shows a rectangle of the world, centred, with room around it.
|
|
70
59
|
* Never zooms in past `maxZoom` (a single small shape is not blown up to fill the board).
|
|
71
60
|
*/
|
|
72
|
-
export function fitViewportToRect(rect, viewSize, padding, maxZoom) {
|
|
73
|
-
if (padding === void 0) { padding = 48; }
|
|
74
|
-
if (maxZoom === void 0) { maxZoom = 1; }
|
|
61
|
+
export function fitViewportToRect(rect, viewSize, padding = 48, maxZoom = 1) {
|
|
75
62
|
if (viewSize.width <= 0 || viewSize.height <= 0)
|
|
76
63
|
return INITIAL_VIEWPORT;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return { x: viewSize.width / 2 - centerX * zoom, y: viewSize.height / 2 - centerY * zoom, zoom
|
|
64
|
+
const availableWidth = Math.max(1, viewSize.width - padding * 2);
|
|
65
|
+
const availableHeight = Math.max(1, viewSize.height - padding * 2);
|
|
66
|
+
const zoom = clampZoom(Math.min(maxZoom, rect.width > 0 ? availableWidth / rect.width : maxZoom, rect.height > 0 ? availableHeight / rect.height : maxZoom));
|
|
67
|
+
const centerX = rect.x + rect.width / 2;
|
|
68
|
+
const centerY = rect.y + rect.height / 2;
|
|
69
|
+
return { x: viewSize.width / 2 - centerX * zoom, y: viewSize.height / 2 - centerY * zoom, zoom };
|
|
83
70
|
}
|
|
84
71
|
/** The CSS transform of the world layer. */
|
|
85
72
|
export function viewportToCssTransform(viewport) {
|
|
86
|
-
return
|
|
73
|
+
return `translate(${Number(viewport.x.toFixed(3))}px, ${Number(viewport.y.toFixed(3))}px) scale(${Number(viewport.zoom.toFixed(5))})`;
|
|
87
74
|
}
|
|
88
75
|
/** A viewport read from untrusted data: anything that is not a finite number falls back to the default. */
|
|
89
76
|
export function sanitizeViewport(value) {
|
|
90
77
|
if (!value || typeof value !== 'object')
|
|
91
78
|
return INITIAL_VIEWPORT;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return { x
|
|
79
|
+
const candidate = value;
|
|
80
|
+
const x = typeof candidate.x === 'number' && Number.isFinite(candidate.x) ? candidate.x : 0;
|
|
81
|
+
const y = typeof candidate.y === 'number' && Number.isFinite(candidate.y) ? candidate.y : 0;
|
|
82
|
+
const zoom = typeof candidate.zoom === 'number' ? clampZoom(candidate.zoom) : 1;
|
|
83
|
+
return { x, y, zoom };
|
|
97
84
|
}
|