@widgetic/canvas 0.5.43 → 0.5.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/DomCanvas.svelte +56 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -28
- package/dist/canvas/autosaveScheduler.js +89 -37
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +19 -7
- package/dist/canvas/chromeLayout.js +21 -19
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +87 -2
- package/dist/canvas/host/CanvasHost.js +1948 -1394
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +32 -5
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +155 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +211 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +21 -18
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +11 -9
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/storedPictures.js +243 -149
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/index.d.ts +2 -0
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +7 -6
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +25 -13
- package/dist/canvas/shapes/ShapeLibrary.js +148 -138
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +17 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/ColorField.svelte +7 -2
- package/dist/canvas/ui/SelectionPanel.svelte +105 -42
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +35 -54
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +43 -21
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +66 -35
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +90 -71
- package/dist/canvas/view/liftedScene.js +36 -24
- package/dist/canvas/view/mountedScene.js +79 -76
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +111 -2
- package/dist/engine/EngineCore.js +1013 -707
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +172 -186
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +109 -84
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +126 -101
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +48 -29
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +98 -78
- package/dist/engine/core/cameraMove.d.ts +73 -0
- package/dist/engine/core/cameraMove.js +172 -0
- package/dist/engine/core/defaults.js +51 -90
- package/dist/engine/core/freehand.js +163 -147
- package/dist/engine/core/geometry.js +54 -47
- package/dist/engine/core/history.js +55 -38
- package/dist/engine/core/hitTest.js +81 -68
- package/dist/engine/core/matrix.js +20 -18
- package/dist/engine/core/pathData.js +210 -183
- package/dist/engine/core/rotationReset.js +6 -5
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +288 -139
- package/dist/engine/core/scribble.js +84 -59
- package/dist/engine/core/shapePaths.js +15 -12
- package/dist/engine/core/shapeTools.js +63 -72
- package/dist/engine/core/snapping.js +117 -65
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +82 -33
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +103 -83
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +549 -466
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +340 -266
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +131 -32
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +25 -4
- package/dist/engine/text/layoutText.js +62 -43
- package/dist/engine/text/textMetrics.js +10 -8
- package/dist/engine/widgets.js +137 -101
- package/dist/fonts/interFont.js +83 -30
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +108 -34
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +7 -1
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +30 -26
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +140 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +251 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +112 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +138 -0
- package/dist/settings/workspaceToolSettings.d.ts +6 -0
- package/dist/settings/workspaceToolSettings.js +58 -34
- package/dist/tools/components/catalog.js +74 -64
- package/dist/tools/components/grouping.js +28 -6
- package/dist/tools/definitions.js +31 -9
- package/dist/tools/executors.js +214 -106
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +15 -11
- package/dist/tools/sceneSummary.js +57 -43
- package/dist/tools/sketchIntent.js +21 -13
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +93 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +2 -1
- package/package.json +1 -1
|
@@ -8,6 +8,17 @@
|
|
|
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
|
+
};
|
|
11
22
|
import { isArrow, transformArrow } from './arrow.js';
|
|
12
23
|
import { isBrushStroke, reshapeBrushStroke } from './brush.js';
|
|
13
24
|
import { rotatedBoxBounds, unionRects, worldToBoxLocal, clampNumber } from './geometry.js';
|
|
@@ -15,7 +26,7 @@ import { applyMatrixToPoint, boxToWorldMatrix, degreesToRadians, normalizeDegree
|
|
|
15
26
|
import { parsePathData, scalePathCommands, mirrorPathCommands, serializePathData } from './pathData.js';
|
|
16
27
|
import { regeneratedPathCommands } from './shapePaths.js';
|
|
17
28
|
import { MIN_OBJECT_SIZE } from './types.js';
|
|
18
|
-
|
|
29
|
+
var HANDLE_DIRECTIONS = {
|
|
19
30
|
nw: { x: -1, y: -1 },
|
|
20
31
|
n: { x: 0, y: -1 },
|
|
21
32
|
ne: { x: 1, y: -1 },
|
|
@@ -33,43 +44,54 @@ export function selectionFrameOf(shapes) {
|
|
|
33
44
|
if (shapes.length === 0)
|
|
34
45
|
return null;
|
|
35
46
|
if (shapes.length === 1) {
|
|
36
|
-
|
|
47
|
+
var shape = shapes[0];
|
|
37
48
|
return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
return union ? {
|
|
50
|
+
var union = unionRects(shapes.map(function (shape) { return rotatedBoxBounds(shape); }));
|
|
51
|
+
return union ? __assign(__assign({}, union), { rotation: 0 }) : null;
|
|
41
52
|
}
|
|
42
53
|
/** The centre of a frame in the world. */
|
|
43
54
|
export function frameCenter(frame) {
|
|
44
55
|
return { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 };
|
|
45
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether a point of the world is inside a frame, edges included. The frame is read in its own space, so one that is turned holds
|
|
59
|
+
* the points inside its turned box and not those of the upright rectangle around it. A box with no width or no height holds
|
|
60
|
+
* only the points on its line.
|
|
61
|
+
*/
|
|
62
|
+
export function frameContains(frame, point) {
|
|
63
|
+
var local = worldToBoxLocal(frame, point);
|
|
64
|
+
return !!local && local.x >= 0 && local.y >= 0 && local.x <= frame.width && local.y <= frame.height;
|
|
65
|
+
}
|
|
46
66
|
/**
|
|
47
67
|
* The frame that results from dragging `handle` to a world point.
|
|
48
68
|
* `frame` is the frame when the drag began (not the one the last pointer move produced).
|
|
49
69
|
*/
|
|
50
|
-
export function computeResizedFrame(frame, handle, pointerWorld, options
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
export function computeResizedFrame(frame, handle, pointerWorld, options) {
|
|
71
|
+
var _a;
|
|
72
|
+
if (options === void 0) { options = {}; }
|
|
73
|
+
var minimumSize = (_a = options.minimumSize) !== null && _a !== void 0 ? _a : MIN_OBJECT_SIZE;
|
|
74
|
+
var direction = HANDLE_DIRECTIONS[handle];
|
|
75
|
+
var local = worldToBoxLocal(frame, pointerWorld);
|
|
54
76
|
if (!local)
|
|
55
|
-
return {
|
|
56
|
-
|
|
77
|
+
return __assign(__assign({}, frame), { flipX: false, flipY: false });
|
|
78
|
+
var width = frame.width, height = frame.height;
|
|
57
79
|
// How far the handle's edge is from the anchor (the opposite edge, or the centre), signed: negative means
|
|
58
80
|
// the pointer has crossed the anchor.
|
|
59
|
-
|
|
81
|
+
var extentX = direction.x === 0
|
|
60
82
|
? width
|
|
61
83
|
: options.fromCenter
|
|
62
84
|
? (local.x - width / 2) * direction.x * 2
|
|
63
85
|
: (local.x - (direction.x > 0 ? 0 : width)) * direction.x;
|
|
64
|
-
|
|
86
|
+
var extentY = direction.y === 0
|
|
65
87
|
? height
|
|
66
88
|
: options.fromCenter
|
|
67
89
|
? (local.y - height / 2) * direction.y * 2
|
|
68
90
|
: (local.y - (direction.y > 0 ? 0 : height)) * direction.y;
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
var signedWidth = extentX;
|
|
92
|
+
var signedHeight = extentY;
|
|
71
93
|
if (options.keepAspect && width > 0 && height > 0) {
|
|
72
|
-
|
|
94
|
+
var scale = void 0;
|
|
73
95
|
if (direction.x !== 0 && direction.y !== 0) {
|
|
74
96
|
scale = Math.max(Math.abs(extentX) / width, Math.abs(extentY) / height);
|
|
75
97
|
}
|
|
@@ -79,14 +101,14 @@ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
|
|
|
79
101
|
else {
|
|
80
102
|
scale = Math.abs(extentY) / height;
|
|
81
103
|
}
|
|
82
|
-
|
|
104
|
+
var smallestScale = minimumSize / Math.min(width, height);
|
|
83
105
|
if (!options.allowFlip || scale < smallestScale)
|
|
84
106
|
scale = Math.max(scale, smallestScale);
|
|
85
107
|
signedWidth = (direction.x === 0 || extentX >= 0 ? 1 : -1) * width * scale;
|
|
86
108
|
signedHeight = (direction.y === 0 || extentY >= 0 ? 1 : -1) * height * scale;
|
|
87
109
|
}
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
var flipX = false;
|
|
111
|
+
var flipY = false;
|
|
90
112
|
if (signedWidth < 0) {
|
|
91
113
|
if (options.allowFlip)
|
|
92
114
|
flipX = true;
|
|
@@ -99,22 +121,22 @@ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
|
|
|
99
121
|
else
|
|
100
122
|
signedHeight = minimumSize;
|
|
101
123
|
}
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
var newWidth = Math.max(minimumSize, Math.abs(signedWidth));
|
|
125
|
+
var newHeight = Math.max(minimumSize, Math.abs(signedHeight));
|
|
104
126
|
// The centre of the new box in the frame's own space: half an extent from the anchor, towards the handle.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
var anchorX = direction.x > 0 ? 0 : width;
|
|
128
|
+
var anchorY = direction.y > 0 ? 0 : height;
|
|
129
|
+
var centerLocalX = direction.x === 0 || options.fromCenter ? width / 2 : anchorX + (direction.x * (flipX ? -newWidth : newWidth)) / 2;
|
|
130
|
+
var centerLocalY = direction.y === 0 || options.fromCenter ? height / 2 : anchorY + (direction.y * (flipY ? -newHeight : newHeight)) / 2;
|
|
131
|
+
var centerWorld = applyMatrixToPoint(boxToWorldMatrix(frame), { x: centerLocalX, y: centerLocalY });
|
|
110
132
|
return {
|
|
111
133
|
x: centerWorld.x - newWidth / 2,
|
|
112
134
|
y: centerWorld.y - newHeight / 2,
|
|
113
135
|
width: newWidth,
|
|
114
136
|
height: newHeight,
|
|
115
137
|
rotation: frame.rotation,
|
|
116
|
-
flipX,
|
|
117
|
-
flipY
|
|
138
|
+
flipX: flipX,
|
|
139
|
+
flipY: flipY
|
|
118
140
|
};
|
|
119
141
|
}
|
|
120
142
|
/**
|
|
@@ -124,18 +146,21 @@ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
|
|
|
124
146
|
* is drawn again (its head keeps its size), text keeps its font size when it is resized from a side
|
|
125
147
|
* (wrapping) and scales it from a corner.
|
|
126
148
|
*/
|
|
127
|
-
export function resizeShapeToBox(shape, box, flip
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
149
|
+
export function resizeShapeToBox(shape, box, flip, textScale) {
|
|
150
|
+
var _a;
|
|
151
|
+
if (flip === void 0) { flip = { flipX: false, flipY: false }; }
|
|
152
|
+
if (textScale === void 0) { textScale = null; }
|
|
153
|
+
var width = Math.max(MIN_OBJECT_SIZE, box.width);
|
|
154
|
+
var height = Math.max(MIN_OBJECT_SIZE, box.height);
|
|
155
|
+
var rotation = (_a = box.rotation) !== null && _a !== void 0 ? _a : shape.rotation;
|
|
156
|
+
var base = __assign(__assign({}, shape), { x: box.x, y: box.y, width: width, height: height, rotation: rotation });
|
|
132
157
|
switch (shape.type) {
|
|
133
158
|
case 'path': {
|
|
134
159
|
if (isArrow(shape)) {
|
|
135
160
|
// The points of the arrow go where the box goes (mirrored by a flip), and the arrow is drawn again from them.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
161
|
+
var mapPoint = function (point) {
|
|
162
|
+
var unitX = shape.width > 0 ? (point.x - shape.x) / shape.width : 0.5;
|
|
163
|
+
var unitY = shape.height > 0 ? (point.y - shape.y) / shape.height : 0.5;
|
|
139
164
|
if (flip.flipX)
|
|
140
165
|
unitX = 1 - unitX;
|
|
141
166
|
if (flip.flipY)
|
|
@@ -145,35 +170,35 @@ export function resizeShapeToBox(shape, box, flip = { flipX: false, flipY: false
|
|
|
145
170
|
return transformArrow(shape, mapPoint);
|
|
146
171
|
}
|
|
147
172
|
// A flip toggles the mirror the shape already has.
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
var flipX = shape.flipX !== flip.flipX;
|
|
174
|
+
var flipY = shape.flipY !== flip.flipY;
|
|
150
175
|
if (isBrushStroke(shape)) {
|
|
151
176
|
// The line goes where the box goes (and is mirrored by this flip); the brush stays as wide as it was.
|
|
152
|
-
|
|
153
|
-
return {
|
|
177
|
+
var reshaped = reshapeBrushStroke(shape, { width: width, height: height, flipX: flip.flipX, flipY: flip.flipY });
|
|
178
|
+
return __assign(__assign({}, base), { d: reshaped.d, ink: reshaped.ink, flipX: flipX, flipY: flipY });
|
|
154
179
|
}
|
|
155
|
-
|
|
156
|
-
|
|
180
|
+
var regenerated = regeneratedPathCommands(shape, width, height);
|
|
181
|
+
var commands = void 0;
|
|
157
182
|
if (regenerated) {
|
|
158
183
|
// Rebuilt from its key, so the mirror the shape had is applied again.
|
|
159
184
|
commands = mirrorPathCommands(regenerated, width, height, flipX, flipY);
|
|
160
185
|
}
|
|
161
186
|
else {
|
|
162
187
|
// Scaled from the path it has, which already holds the earlier mirrors: only this flip is applied.
|
|
163
|
-
|
|
164
|
-
|
|
188
|
+
var scaleX = shape.width > 0 ? width / shape.width : 1;
|
|
189
|
+
var scaleY = shape.height > 0 ? height / shape.height : 1;
|
|
165
190
|
commands = mirrorPathCommands(scalePathCommands(parsePathData(shape.d), scaleX, scaleY), width, height, flip.flipX, flip.flipY);
|
|
166
191
|
}
|
|
167
|
-
return {
|
|
192
|
+
return __assign(__assign({}, base), { d: serializePathData(commands), flipX: flipX, flipY: flipY });
|
|
168
193
|
}
|
|
169
194
|
case 'text': {
|
|
170
|
-
|
|
195
|
+
var text = shape;
|
|
171
196
|
if (textScale !== null && textScale > 0) {
|
|
172
197
|
// A corner drag scales the letters with the box.
|
|
173
|
-
return {
|
|
198
|
+
return __assign(__assign({}, base), { fontSize: clampNumber(text.fontSize * textScale, 4, 600) });
|
|
174
199
|
}
|
|
175
200
|
// A side drag only sets the width the text wraps at.
|
|
176
|
-
return {
|
|
201
|
+
return __assign(__assign({}, base), { autoWidth: false });
|
|
177
202
|
}
|
|
178
203
|
default:
|
|
179
204
|
return base;
|
|
@@ -186,38 +211,38 @@ export function resizeShapeToBox(shape, box, flip = { flipX: false, flipY: false
|
|
|
186
211
|
*/
|
|
187
212
|
export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
|
|
188
213
|
if (shapes.length === 1) {
|
|
189
|
-
|
|
190
|
-
|
|
214
|
+
var shape = shapes[0];
|
|
215
|
+
var cornerTextScale = shape.type === 'text' && isCornerHandle && startFrame.width > 0 ? resized.width / startFrame.width : null;
|
|
191
216
|
return [
|
|
192
217
|
resizeShapeToBox(shape, resized, { flipX: resized.flipX, flipY: resized.flipY }, cornerTextScale)
|
|
193
218
|
];
|
|
194
219
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
220
|
+
var scaleX = startFrame.width > 0 ? resized.width / startFrame.width : 1;
|
|
221
|
+
var scaleY = startFrame.height > 0 ? resized.height / startFrame.height : 1;
|
|
222
|
+
var mapPoint = function (point) {
|
|
223
|
+
var unitX = startFrame.width > 0 ? (point.x - startFrame.x) / startFrame.width : 0.5;
|
|
224
|
+
var unitY = startFrame.height > 0 ? (point.y - startFrame.y) / startFrame.height : 0.5;
|
|
200
225
|
if (resized.flipX)
|
|
201
226
|
unitX = 1 - unitX;
|
|
202
227
|
if (resized.flipY)
|
|
203
228
|
unitY = 1 - unitY;
|
|
204
229
|
return { x: resized.x + unitX * resized.width, y: resized.y + unitY * resized.height };
|
|
205
230
|
};
|
|
206
|
-
return shapes.map((shape)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
231
|
+
return shapes.map(function (shape) {
|
|
232
|
+
var radians = degreesToRadians(shape.rotation);
|
|
233
|
+
var cosine = Math.cos(radians);
|
|
234
|
+
var sine = Math.sin(radians);
|
|
210
235
|
// The shape's own axes are stretched by the frame; the lengths along them give its new size.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
236
|
+
var widthFactor = Math.hypot(scaleX * cosine, scaleY * sine);
|
|
237
|
+
var heightFactor = Math.hypot(scaleX * sine, scaleY * cosine);
|
|
238
|
+
var newWidth = Math.max(MIN_OBJECT_SIZE, shape.width * widthFactor);
|
|
239
|
+
var newHeight = Math.max(MIN_OBJECT_SIZE, shape.height * heightFactor);
|
|
240
|
+
var center = mapPoint({ x: shape.x + shape.width / 2, y: shape.y + shape.height / 2 });
|
|
216
241
|
// A mirrored shape turns the other way.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
242
|
+
var mirrors = (resized.flipX ? 1 : 0) + (resized.flipY ? 1 : 0);
|
|
243
|
+
var rotation = mirrors % 2 === 1 ? normalizeDegrees(-shape.rotation) : shape.rotation;
|
|
244
|
+
var box = { x: center.x - newWidth / 2, y: center.y - newHeight / 2, width: newWidth, height: newHeight, rotation: rotation };
|
|
245
|
+
var textScale = shape.type === 'text' ? (widthFactor + heightFactor) / 2 : null;
|
|
221
246
|
return resizeShapeToBox(shape, box, { flipX: resized.flipX, flipY: resized.flipY }, textScale);
|
|
222
247
|
});
|
|
223
248
|
}
|
|
@@ -226,26 +251,21 @@ export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
|
|
|
226
251
|
* turn (it is always upright): its points go round the point and it is drawn again between them.
|
|
227
252
|
*/
|
|
228
253
|
export function rotateShapesAbout(shapes, pivot, deltaDegrees) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return shapes.map((shape)
|
|
254
|
+
var radians = degreesToRadians(deltaDegrees);
|
|
255
|
+
var cosine = Math.cos(radians);
|
|
256
|
+
var sine = Math.sin(radians);
|
|
257
|
+
return shapes.map(function (shape) {
|
|
233
258
|
if (isArrow(shape)) {
|
|
234
|
-
return transformArrow(shape, (point)
|
|
259
|
+
return transformArrow(shape, function (point) { return ({
|
|
235
260
|
x: pivot.x + (point.x - pivot.x) * cosine - (point.y - pivot.y) * sine,
|
|
236
261
|
y: pivot.y + (point.x - pivot.x) * sine + (point.y - pivot.y) * cosine
|
|
237
|
-
}));
|
|
262
|
+
}); });
|
|
238
263
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
...shape,
|
|
245
|
-
x: rotatedX - shape.width / 2,
|
|
246
|
-
y: rotatedY - shape.height / 2,
|
|
247
|
-
rotation: normalizeDegrees(shape.rotation + deltaDegrees)
|
|
248
|
-
};
|
|
264
|
+
var centerX = shape.x + shape.width / 2 - pivot.x;
|
|
265
|
+
var centerY = shape.y + shape.height / 2 - pivot.y;
|
|
266
|
+
var rotatedX = pivot.x + centerX * cosine - centerY * sine;
|
|
267
|
+
var rotatedY = pivot.y + centerX * sine + centerY * cosine;
|
|
268
|
+
return __assign(__assign({}, shape), { x: rotatedX - shape.width / 2, y: rotatedY - shape.height / 2, rotation: normalizeDegrees(shape.rotation + deltaDegrees) });
|
|
249
269
|
});
|
|
250
270
|
}
|
|
251
271
|
/** The angle, in degrees, of the line from `center` to `point` (0 is to the right, growing clockwise on screen). */
|
|
@@ -204,6 +204,13 @@ export interface ImageObject extends ObjectBase, BoxProps {
|
|
|
204
204
|
/** The reference under which the host's image store keeps the bytes, when they are not inline. */
|
|
205
205
|
imageRef: string | null;
|
|
206
206
|
fileName: string | null;
|
|
207
|
+
/**
|
|
208
|
+
* The id the person's file library (the File Browser of the workspace) knows this picture by, once it is in the library.
|
|
209
|
+
* Null for a picture that only lives on this board. Deleting the picture from the board never touches the library file.
|
|
210
|
+
*/
|
|
211
|
+
libraryFileId: string | null;
|
|
212
|
+
/** Where the library keeps the file (its own address, never the board's bytes). Null while the picture is not in the library. */
|
|
213
|
+
libraryFileUrl: string | null;
|
|
207
214
|
/** The size of the picture itself, to keep its aspect ratio when it is resized. */
|
|
208
215
|
naturalWidth: number;
|
|
209
216
|
naturalHeight: number;
|
|
@@ -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 var CANVAS_DOCUMENT_VERSION = 2;
|
|
21
|
+
export var MIN_OBJECT_SIZE = 1;
|
|
22
|
+
export var MIN_ZOOM = 0.05;
|
|
23
|
+
export var 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,11 +5,22 @@
|
|
|
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
|
+
};
|
|
8
19
|
import { clampNumber } from './geometry.js';
|
|
9
20
|
import { MAX_ZOOM, MIN_ZOOM } from './types.js';
|
|
10
|
-
export
|
|
21
|
+
export var INITIAL_VIEWPORT = { x: 0, y: 0, zoom: 1 };
|
|
11
22
|
/** The zoom levels the zoom buttons and the menu step through. */
|
|
12
|
-
export
|
|
23
|
+
export var ZOOM_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
|
|
13
24
|
export function clampZoom(zoom) {
|
|
14
25
|
if (!Number.isFinite(zoom))
|
|
15
26
|
return 1;
|
|
@@ -34,21 +45,21 @@ export function visibleWorldRect(viewport, viewSize) {
|
|
|
34
45
|
}
|
|
35
46
|
/** Changes the zoom and keeps the world point under `screenPoint` where it is (what the wheel and pinch do). */
|
|
36
47
|
export function zoomAtPoint(viewport, screenPoint, nextZoom) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return { x: screenPoint.x - worldPoint.x * zoom, y: screenPoint.y - worldPoint.y * zoom, zoom };
|
|
48
|
+
var zoom = clampZoom(nextZoom);
|
|
49
|
+
var worldPoint = screenToWorld(viewport, screenPoint);
|
|
50
|
+
return { x: screenPoint.x - worldPoint.x * zoom, y: screenPoint.y - worldPoint.y * zoom, zoom: zoom };
|
|
40
51
|
}
|
|
41
52
|
export function panViewport(viewport, deltaX, deltaY) {
|
|
42
|
-
return {
|
|
53
|
+
return __assign(__assign({}, viewport), { x: viewport.x + deltaX, y: viewport.y + deltaY });
|
|
43
54
|
}
|
|
44
55
|
/** The next step above (direction 1) or below (-1) the current zoom, or the same zoom at the end of the ladder. */
|
|
45
56
|
export function nextZoomStep(zoom, direction) {
|
|
46
|
-
|
|
57
|
+
var tolerance = 1e-6;
|
|
47
58
|
if (direction === 1) {
|
|
48
|
-
|
|
49
|
-
return step
|
|
59
|
+
var step = ZOOM_STEPS.find(function (candidate) { return candidate > zoom + tolerance; });
|
|
60
|
+
return step !== null && step !== void 0 ? step : ZOOM_STEPS[ZOOM_STEPS.length - 1];
|
|
50
61
|
}
|
|
51
|
-
for (
|
|
62
|
+
for (var index = ZOOM_STEPS.length - 1; index >= 0; index -= 1) {
|
|
52
63
|
if (ZOOM_STEPS[index] < zoom - tolerance)
|
|
53
64
|
return ZOOM_STEPS[index];
|
|
54
65
|
}
|
|
@@ -58,27 +69,29 @@ export function nextZoomStep(zoom, direction) {
|
|
|
58
69
|
* The view that shows a rectangle of the world, centred, with room around it.
|
|
59
70
|
* Never zooms in past `maxZoom` (a single small shape is not blown up to fill the board).
|
|
60
71
|
*/
|
|
61
|
-
export function fitViewportToRect(rect, viewSize, padding
|
|
72
|
+
export function fitViewportToRect(rect, viewSize, padding, maxZoom) {
|
|
73
|
+
if (padding === void 0) { padding = 48; }
|
|
74
|
+
if (maxZoom === void 0) { maxZoom = 1; }
|
|
62
75
|
if (viewSize.width <= 0 || viewSize.height <= 0)
|
|
63
76
|
return INITIAL_VIEWPORT;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return { x: viewSize.width / 2 - centerX * zoom, y: viewSize.height / 2 - centerY * zoom, zoom };
|
|
77
|
+
var availableWidth = Math.max(1, viewSize.width - padding * 2);
|
|
78
|
+
var availableHeight = Math.max(1, viewSize.height - padding * 2);
|
|
79
|
+
var zoom = clampZoom(Math.min(maxZoom, rect.width > 0 ? availableWidth / rect.width : maxZoom, rect.height > 0 ? availableHeight / rect.height : maxZoom));
|
|
80
|
+
var centerX = rect.x + rect.width / 2;
|
|
81
|
+
var centerY = rect.y + rect.height / 2;
|
|
82
|
+
return { x: viewSize.width / 2 - centerX * zoom, y: viewSize.height / 2 - centerY * zoom, zoom: zoom };
|
|
70
83
|
}
|
|
71
84
|
/** The CSS transform of the world layer. */
|
|
72
85
|
export function viewportToCssTransform(viewport) {
|
|
73
|
-
return
|
|
86
|
+
return "translate(".concat(Number(viewport.x.toFixed(3)), "px, ").concat(Number(viewport.y.toFixed(3)), "px) scale(").concat(Number(viewport.zoom.toFixed(5)), ")");
|
|
74
87
|
}
|
|
75
88
|
/** A viewport read from untrusted data: anything that is not a finite number falls back to the default. */
|
|
76
89
|
export function sanitizeViewport(value) {
|
|
77
90
|
if (!value || typeof value !== 'object')
|
|
78
91
|
return INITIAL_VIEWPORT;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return { x, y, zoom };
|
|
92
|
+
var candidate = value;
|
|
93
|
+
var x = typeof candidate.x === 'number' && Number.isFinite(candidate.x) ? candidate.x : 0;
|
|
94
|
+
var y = typeof candidate.y === 'number' && Number.isFinite(candidate.y) ? candidate.y : 0;
|
|
95
|
+
var zoom = typeof candidate.zoom === 'number' ? clampZoom(candidate.zoom) : 1;
|
|
96
|
+
return { x: x, y: y, zoom: zoom };
|
|
84
97
|
}
|
|
@@ -19,6 +19,14 @@ export declare class PointerController {
|
|
|
19
19
|
get gestureKind(): string | null;
|
|
20
20
|
/** Space held: a press pans, whatever the tool. */
|
|
21
21
|
setSpaceHeld(held: boolean): void;
|
|
22
|
+
/** Whether G is held: the alignment guides are off while it is. */
|
|
23
|
+
get guidesSuppressed(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* G pressed or let go: the alignment guides are off while it is held, whatever is dragged (a held key can come before the press
|
|
26
|
+
* or in the middle of the drag). A drag that is running takes it up at once, without waiting for the pointer to move: the guides
|
|
27
|
+
* go (and the selection stops being caught by them) when the key goes down, and come back when it is let go.
|
|
28
|
+
*/
|
|
29
|
+
setGuidesSuppressed(suppressed: boolean): void;
|
|
22
30
|
/** Abandons the gesture that is running (Escape). True when there was one. */
|
|
23
31
|
cancelGesture(): boolean;
|
|
24
32
|
/** Shift, Alt, Ctrl or Meta changed while the pointer stayed still. */
|
|
@@ -26,7 +34,13 @@ export declare class PointerController {
|
|
|
26
34
|
dispose(): void;
|
|
27
35
|
/** Handles a press. Returns whether the shell should capture the pointer and keep the browser from acting on it. */
|
|
28
36
|
pointerDown(input: PointerInput): boolean;
|
|
29
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* A right click or a long press: picks the top object under the pointer, unless something that is selected is under it already.
|
|
39
|
+
* The selection stays when the pointer is on one of its objects even if another object lies above that one there: a layer that
|
|
40
|
+
* was reached through the stack (an Alt-click on what is covered, the only way to pick a text under a shape) is still the one the
|
|
41
|
+
* menu is for, and "Bring to front" is what puts it above the rest. Returns the object the menu is for (the selected one under
|
|
42
|
+
* the pointer, else the top one), or null where nothing is under it (the selection is then left as it is).
|
|
43
|
+
*/
|
|
30
44
|
prepareContextMenu(screenPoint: Point): string | null;
|
|
31
45
|
pointerMove(input: PointerInput): void;
|
|
32
46
|
/** The pointer left the board: nothing is hovered any more. */
|