@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
|
@@ -7,101 +7,148 @@
|
|
|
7
7
|
* pointer speeds up: sweeping quickly across a board must not catch on every shape on the way, only a slow,
|
|
8
8
|
* deliberate move should (the same idea Memoreco's layout editor uses).
|
|
9
9
|
*/
|
|
10
|
+
var __assign = (this && this.__assign) || function () {
|
|
11
|
+
__assign = Object.assign || function(t) {
|
|
12
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
13
|
+
s = arguments[i];
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
};
|
|
19
|
+
return __assign.apply(this, arguments);
|
|
20
|
+
};
|
|
21
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
22
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
23
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
24
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
25
|
+
};
|
|
26
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
27
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
28
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
29
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
30
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
31
|
+
};
|
|
32
|
+
var _PointerSpeedTracker_last, _PointerSpeedTracker_speed;
|
|
10
33
|
import { clampNumber } from './geometry.js';
|
|
11
34
|
/** How far, in screen pixels, a line reaches to catch the dragged edge when the pointer is slow. */
|
|
12
|
-
export
|
|
35
|
+
export var SNAP_THRESHOLD_PIXELS = 8;
|
|
13
36
|
/** At or below this speed (pixels per millisecond) the snap has its full reach. */
|
|
14
|
-
export
|
|
37
|
+
export var SNAP_SLOW_SPEED = 0.25;
|
|
15
38
|
/** At or above this speed the snap has no reach at all. */
|
|
16
|
-
export
|
|
39
|
+
export var SNAP_FAST_SPEED = 0.9;
|
|
17
40
|
/** Weight of the newest sample in the smoothed pointer speed. */
|
|
18
|
-
export
|
|
19
|
-
export
|
|
41
|
+
export var SNAP_SPEED_SMOOTHING = 0.35;
|
|
42
|
+
export var NO_SNAP = Object.freeze({ deltaX: 0, deltaY: 0, guides: [] });
|
|
20
43
|
/** The reach of a snap in world units for a pointer moving at `speed`, at `zoom`. */
|
|
21
|
-
export function snapReachInWorld(zoom, speed
|
|
22
|
-
|
|
44
|
+
export function snapReachInWorld(zoom, speed, basePixels) {
|
|
45
|
+
if (speed === void 0) { speed = 0; }
|
|
46
|
+
if (basePixels === void 0) { basePixels = SNAP_THRESHOLD_PIXELS; }
|
|
47
|
+
var speedFactor = clampNumber((speed - SNAP_SLOW_SPEED) / (SNAP_FAST_SPEED - SNAP_SLOW_SPEED), 0, 1);
|
|
23
48
|
return (basePixels * (1 - speedFactor)) / Math.max(zoom, 1e-6);
|
|
24
49
|
}
|
|
25
50
|
/** Follows how fast the pointer moves, smoothed, in screen pixels per millisecond. */
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
51
|
+
var PointerSpeedTracker = /** @class */ (function () {
|
|
52
|
+
function PointerSpeedTracker() {
|
|
53
|
+
_PointerSpeedTracker_last.set(this, null);
|
|
54
|
+
_PointerSpeedTracker_speed.set(this, 0);
|
|
55
|
+
}
|
|
29
56
|
/** Records a pointer position (screen space) and returns the smoothed speed. */
|
|
30
|
-
update(x, y, time) {
|
|
31
|
-
if (this
|
|
32
|
-
|
|
33
|
-
this
|
|
57
|
+
PointerSpeedTracker.prototype.update = function (x, y, time) {
|
|
58
|
+
if (__classPrivateFieldGet(this, _PointerSpeedTracker_last, "f") && time > __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").time) {
|
|
59
|
+
var instant = Math.hypot(x - __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").x, y - __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").y) / (time - __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").time);
|
|
60
|
+
__classPrivateFieldSet(this, _PointerSpeedTracker_speed, __classPrivateFieldGet(this, _PointerSpeedTracker_speed, "f") * (1 - SNAP_SPEED_SMOOTHING) + instant * SNAP_SPEED_SMOOTHING, "f");
|
|
34
61
|
}
|
|
35
|
-
this
|
|
36
|
-
return this
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
62
|
+
__classPrivateFieldSet(this, _PointerSpeedTracker_last, { x: x, y: y, time: time }, "f");
|
|
63
|
+
return __classPrivateFieldGet(this, _PointerSpeedTracker_speed, "f");
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(PointerSpeedTracker.prototype, "speed", {
|
|
66
|
+
get: function () {
|
|
67
|
+
return __classPrivateFieldGet(this, _PointerSpeedTracker_speed, "f");
|
|
68
|
+
},
|
|
69
|
+
enumerable: false,
|
|
70
|
+
configurable: true
|
|
71
|
+
});
|
|
72
|
+
PointerSpeedTracker.prototype.reset = function () {
|
|
73
|
+
__classPrivateFieldSet(this, _PointerSpeedTracker_last, null, "f");
|
|
74
|
+
__classPrivateFieldSet(this, _PointerSpeedTracker_speed, 0, "f");
|
|
75
|
+
};
|
|
76
|
+
return PointerSpeedTracker;
|
|
77
|
+
}());
|
|
78
|
+
export { PointerSpeedTracker };
|
|
79
|
+
_PointerSpeedTracker_last = new WeakMap(), _PointerSpeedTracker_speed = new WeakMap();
|
|
46
80
|
function verticalLinesOf(rects) {
|
|
47
|
-
|
|
48
|
-
for (
|
|
49
|
-
|
|
81
|
+
var lines = [];
|
|
82
|
+
for (var _i = 0, rects_1 = rects; _i < rects_1.length; _i++) {
|
|
83
|
+
var rect = rects_1[_i];
|
|
84
|
+
lines.push({ position: rect.x, rect: rect }, { position: rect.x + rect.width / 2, rect: rect }, { position: rect.x + rect.width, rect: rect });
|
|
50
85
|
}
|
|
51
86
|
return lines;
|
|
52
87
|
}
|
|
53
88
|
function horizontalLinesOf(rects) {
|
|
54
|
-
|
|
55
|
-
for (
|
|
56
|
-
|
|
89
|
+
var lines = [];
|
|
90
|
+
for (var _i = 0, rects_2 = rects; _i < rects_2.length; _i++) {
|
|
91
|
+
var rect = rects_2[_i];
|
|
92
|
+
lines.push({ position: rect.y, rect: rect }, { position: rect.y + rect.height / 2, rect: rect }, { position: rect.y + rect.height, rect: rect });
|
|
57
93
|
}
|
|
58
94
|
return lines;
|
|
59
95
|
}
|
|
60
96
|
/** The smallest signed distance from any anchor to any line, if it is within `reach`. */
|
|
61
97
|
function nearestOffset(anchors, lines, reach) {
|
|
62
|
-
|
|
63
|
-
for (
|
|
64
|
-
|
|
65
|
-
|
|
98
|
+
var best = null;
|
|
99
|
+
for (var _i = 0, anchors_1 = anchors; _i < anchors_1.length; _i++) {
|
|
100
|
+
var anchor = anchors_1[_i];
|
|
101
|
+
for (var _a = 0, lines_1 = lines; _a < lines_1.length; _a++) {
|
|
102
|
+
var line = lines_1[_a];
|
|
103
|
+
var offset = line.position - anchor;
|
|
66
104
|
if (Math.abs(offset) <= reach && (best === null || Math.abs(offset) < Math.abs(best.offset) - 1e-9)) {
|
|
67
|
-
best = { offset };
|
|
105
|
+
best = { offset: offset };
|
|
68
106
|
}
|
|
69
107
|
}
|
|
70
108
|
}
|
|
71
109
|
return best;
|
|
72
110
|
}
|
|
73
|
-
|
|
111
|
+
var MATCH_EPSILON = 0.01;
|
|
74
112
|
/**
|
|
75
113
|
* The guides to draw for a box that sits where it will land: every line of the other shapes that one of
|
|
76
114
|
* its anchors is on, spanning both shapes.
|
|
77
115
|
*/
|
|
78
|
-
export function guidesFor(box, others, anchorsOf
|
|
79
|
-
|
|
116
|
+
export function guidesFor(box, others, anchorsOf) {
|
|
117
|
+
if (anchorsOf === void 0) { anchorsOf = 'both'; }
|
|
118
|
+
var guides = [];
|
|
80
119
|
if (anchorsOf !== 'y') {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (anchors.some((anchor)
|
|
84
|
-
|
|
85
|
-
|
|
120
|
+
var anchors = [box.x, box.x + box.width / 2, box.x + box.width];
|
|
121
|
+
var _loop_1 = function (line) {
|
|
122
|
+
if (anchors.some(function (anchor) { return Math.abs(anchor - line.position) <= MATCH_EPSILON; })) {
|
|
123
|
+
var top = Math.min(box.y, line.rect.y);
|
|
124
|
+
var bottom = Math.max(box.y + box.height, line.rect.y + line.rect.height);
|
|
86
125
|
mergeGuide(guides, { orientation: 'vertical', position: line.position, from: top, to: bottom });
|
|
87
126
|
}
|
|
127
|
+
};
|
|
128
|
+
for (var _i = 0, _a = verticalLinesOf(others); _i < _a.length; _i++) {
|
|
129
|
+
var line = _a[_i];
|
|
130
|
+
_loop_1(line);
|
|
88
131
|
}
|
|
89
132
|
}
|
|
90
133
|
if (anchorsOf !== 'x') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (anchors.some((anchor)
|
|
94
|
-
|
|
95
|
-
|
|
134
|
+
var anchors = [box.y, box.y + box.height / 2, box.y + box.height];
|
|
135
|
+
var _loop_2 = function (line) {
|
|
136
|
+
if (anchors.some(function (anchor) { return Math.abs(anchor - line.position) <= MATCH_EPSILON; })) {
|
|
137
|
+
var left = Math.min(box.x, line.rect.x);
|
|
138
|
+
var right = Math.max(box.x + box.width, line.rect.x + line.rect.width);
|
|
96
139
|
mergeGuide(guides, { orientation: 'horizontal', position: line.position, from: left, to: right });
|
|
97
140
|
}
|
|
141
|
+
};
|
|
142
|
+
for (var _b = 0, _c = horizontalLinesOf(others); _b < _c.length; _b++) {
|
|
143
|
+
var line = _c[_b];
|
|
144
|
+
_loop_2(line);
|
|
98
145
|
}
|
|
99
146
|
}
|
|
100
147
|
return guides;
|
|
101
148
|
}
|
|
102
149
|
/** Adds a guide, or stretches the one already on the same line to cover it. */
|
|
103
150
|
function mergeGuide(guides, guide) {
|
|
104
|
-
|
|
151
|
+
var existing = guides.find(function (candidate) { return candidate.orientation === guide.orientation && Math.abs(candidate.position - guide.position) <= MATCH_EPSILON; });
|
|
105
152
|
if (!existing) {
|
|
106
153
|
guides.push(guide);
|
|
107
154
|
return;
|
|
@@ -114,30 +161,34 @@ function mergeGuide(guides, guide) {
|
|
|
114
161
|
* far to nudge it and which guides to show once it is there.
|
|
115
162
|
*/
|
|
116
163
|
export function computeMoveSnap(moving, others, reach) {
|
|
164
|
+
var _a, _b;
|
|
117
165
|
if (others.length === 0 || reach <= 0)
|
|
118
166
|
return NO_SNAP;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
167
|
+
var x = nearestOffset([moving.x, moving.x + moving.width / 2, moving.x + moving.width], verticalLinesOf(others), reach);
|
|
168
|
+
var y = nearestOffset([moving.y, moving.y + moving.height / 2, moving.y + moving.height], horizontalLinesOf(others), reach);
|
|
169
|
+
var deltaX = (_a = x === null || x === void 0 ? void 0 : x.offset) !== null && _a !== void 0 ? _a : 0;
|
|
170
|
+
var deltaY = (_b = y === null || y === void 0 ? void 0 : y.offset) !== null && _b !== void 0 ? _b : 0;
|
|
123
171
|
if (!x && !y)
|
|
124
172
|
return NO_SNAP;
|
|
125
|
-
|
|
126
|
-
return { deltaX, deltaY, guides: guidesFor(landed, others, x && y ? 'both' : x ? 'x' : 'y') };
|
|
173
|
+
var landed = __assign(__assign({}, moving), { x: moving.x + deltaX, y: moving.y + deltaY });
|
|
174
|
+
return { deltaX: deltaX, deltaY: deltaY, guides: guidesFor(landed, others, x && y ? 'both' : x ? 'x' : 'y') };
|
|
127
175
|
}
|
|
128
176
|
/**
|
|
129
177
|
* Snaps one point (the corner or edge a handle drags, or a corner of a shape being drawn) to the lines of
|
|
130
178
|
* the other shapes. `axes` says which coordinates may snap (an edge handle moves one only).
|
|
131
179
|
*/
|
|
132
|
-
export function snapPoint(point, others, reach, axes
|
|
180
|
+
export function snapPoint(point, others, reach, axes) {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
if (axes === void 0) { axes = { x: true, y: true }; }
|
|
133
183
|
if (others.length === 0 || reach <= 0)
|
|
134
|
-
return { point, guides: [] };
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
184
|
+
return { point: point, guides: [] };
|
|
185
|
+
var x = axes.x ? nearestOffset([point.x], verticalLinesOf(others), reach) : null;
|
|
186
|
+
var y = axes.y ? nearestOffset([point.y], horizontalLinesOf(others), reach) : null;
|
|
187
|
+
var snapped = { x: point.x + ((_a = x === null || x === void 0 ? void 0 : x.offset) !== null && _a !== void 0 ? _a : 0), y: point.y + ((_b = y === null || y === void 0 ? void 0 : y.offset) !== null && _b !== void 0 ? _b : 0) };
|
|
188
|
+
var guides = [];
|
|
139
189
|
if (x) {
|
|
140
|
-
for (
|
|
190
|
+
for (var _i = 0, _c = verticalLinesOf(others); _i < _c.length; _i++) {
|
|
191
|
+
var line = _c[_i];
|
|
141
192
|
if (Math.abs(line.position - snapped.x) <= MATCH_EPSILON) {
|
|
142
193
|
mergeGuide(guides, {
|
|
143
194
|
orientation: 'vertical',
|
|
@@ -149,7 +200,8 @@ export function snapPoint(point, others, reach, axes = { x: true, y: true }) {
|
|
|
149
200
|
}
|
|
150
201
|
}
|
|
151
202
|
if (y) {
|
|
152
|
-
for (
|
|
203
|
+
for (var _d = 0, _e = horizontalLinesOf(others); _d < _e.length; _d++) {
|
|
204
|
+
var line = _e[_d];
|
|
153
205
|
if (Math.abs(line.position - snapped.y) <= MATCH_EPSILON) {
|
|
154
206
|
mergeGuide(guides, {
|
|
155
207
|
orientation: 'horizontal',
|
|
@@ -160,5 +212,5 @@ export function snapPoint(point, others, reach, axes = { x: true, y: true }) {
|
|
|
160
212
|
}
|
|
161
213
|
}
|
|
162
214
|
}
|
|
163
|
-
return { point: snapped, guides };
|
|
215
|
+
return { point: snapped, guides: guides };
|
|
164
216
|
}
|
|
@@ -29,6 +29,16 @@ export interface StylePatch {
|
|
|
29
29
|
}
|
|
30
30
|
/** Whether the Roundness control means something for the path (rounded corners or round line ends). */
|
|
31
31
|
export declare function pathSupportsRoundness(shapeKey: string | null): boolean;
|
|
32
|
+
/** The widest a line may be made with the Width control (the pen's too: see `EngineCore.setPenStyle`). */
|
|
33
|
+
export declare const MAX_STROKE_WIDTH = 200;
|
|
34
|
+
/** The thinnest line a shape that is only a line can be given (the brush's own least is the same): with none, nothing of it is left. */
|
|
35
|
+
export declare const MIN_LINE_STROKE_WIDTH = 1;
|
|
36
|
+
/**
|
|
37
|
+
* The least the Width control may give a shape. A shape with an inside can go without an outline (0), but an arrow, a line-only
|
|
38
|
+
* icon (a check, a cross, a plus, a minus) or a brush stroke is its line: with none it would vanish from the board, so it keeps
|
|
39
|
+
* the thinnest line it can be drawn with.
|
|
40
|
+
*/
|
|
41
|
+
export declare function minimumStrokeWidthOf(shape: ShapeObject): number;
|
|
32
42
|
/** Whether the "Fill" colour of this shape is really the colour of its line, because it has no inside. */
|
|
33
43
|
export declare function paintsFillOnStroke(shape: ShapeObject): boolean;
|
|
34
44
|
/**
|
|
@@ -5,14 +5,45 @@
|
|
|
5
5
|
* its kind and ignores the rest (an image has no stroke, a rectangle no font). A shape comes back unchanged
|
|
6
6
|
* (the same object) when the patch changes nothing for it, so the renderer redraws only what is different.
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
20
|
+
var t = {};
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
24
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
25
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
26
|
+
t[p[i]] = s[p[i]];
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
};
|
|
30
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
31
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
32
|
+
if (ar || !(i in from)) {
|
|
33
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
34
|
+
ar[i] = from[i];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
38
|
+
};
|
|
8
39
|
import { getShapeByKey } from '../../canvas/shapes/ShapeLibrary.js';
|
|
9
40
|
import { isArrow, reshapeArrow } from './arrow.js';
|
|
10
41
|
import { MIN_BRUSH_WIDTH, isBrushStroke, reshapeBrushStroke } from './brush.js';
|
|
11
42
|
import { clampNumber } from './geometry.js';
|
|
12
43
|
import { mirrorPathCommands, serializePathData } from './pathData.js';
|
|
13
44
|
import { regeneratedPathCommands } from './shapePaths.js';
|
|
14
|
-
|
|
15
|
-
|
|
45
|
+
var PAINT_KEYS = ['fill', 'fillOpacity', 'stroke', 'strokeWidth', 'strokeStyle'];
|
|
46
|
+
var TEXT_KEYS = [
|
|
16
47
|
'color',
|
|
17
48
|
'fontSize',
|
|
18
49
|
'fontFamily',
|
|
@@ -28,16 +59,16 @@ const TEXT_KEYS = [
|
|
|
28
59
|
function keysFor(shape) {
|
|
29
60
|
switch (shape.type) {
|
|
30
61
|
case 'rect':
|
|
31
|
-
return ['opacity', 'roundness',
|
|
62
|
+
return __spreadArray(['opacity', 'roundness'], PAINT_KEYS, true);
|
|
32
63
|
case 'ellipse':
|
|
33
|
-
return ['opacity',
|
|
64
|
+
return __spreadArray(['opacity'], PAINT_KEYS, true);
|
|
34
65
|
case 'path':
|
|
35
66
|
// An arrow is a line and a head: nothing to fill, no corner to round.
|
|
36
67
|
if (isArrow(shape))
|
|
37
68
|
return ['opacity', 'stroke', 'strokeWidth', 'strokeStyle'];
|
|
38
|
-
return ['opacity', 'roundness',
|
|
69
|
+
return __spreadArray(['opacity', 'roundness'], PAINT_KEYS, true);
|
|
39
70
|
case 'text':
|
|
40
|
-
return ['opacity',
|
|
71
|
+
return __spreadArray(['opacity'], TEXT_KEYS, true);
|
|
41
72
|
default:
|
|
42
73
|
return ['opacity'];
|
|
43
74
|
}
|
|
@@ -46,16 +77,29 @@ function keysFor(shape) {
|
|
|
46
77
|
export function pathSupportsRoundness(shapeKey) {
|
|
47
78
|
if (shapeKey === 'triangle')
|
|
48
79
|
return true;
|
|
49
|
-
|
|
80
|
+
var shape = getShapeByKey(shapeKey);
|
|
50
81
|
return !!shape && (shape.cornerRadiusMode === 'pathRegen' || shape.cornerRadiusMode === 'strokeRound');
|
|
51
82
|
}
|
|
52
83
|
/** Whether the shape's roundness is the shape of its line ends rather than of its corners. */
|
|
53
84
|
function roundnessIsLineEnds(shapeKey) {
|
|
54
|
-
|
|
85
|
+
var _a;
|
|
86
|
+
return ((_a = getShapeByKey(shapeKey)) === null || _a === void 0 ? void 0 : _a.cornerRadiusMode) === 'strokeRound';
|
|
87
|
+
}
|
|
88
|
+
/** The widest a line may be made with the Width control (the pen's too: see `EngineCore.setPenStyle`). */
|
|
89
|
+
export var MAX_STROKE_WIDTH = 200;
|
|
90
|
+
/** The thinnest line a shape that is only a line can be given (the brush's own least is the same): with none, nothing of it is left. */
|
|
91
|
+
export var MIN_LINE_STROKE_WIDTH = 1;
|
|
92
|
+
/**
|
|
93
|
+
* The least the Width control may give a shape. A shape with an inside can go without an outline (0), but an arrow, a line-only
|
|
94
|
+
* icon (a check, a cross, a plus, a minus) or a brush stroke is its line: with none it would vanish from the board, so it keeps
|
|
95
|
+
* the thinnest line it can be drawn with.
|
|
96
|
+
*/
|
|
97
|
+
export function minimumStrokeWidthOf(shape) {
|
|
98
|
+
if (isBrushStroke(shape))
|
|
99
|
+
return MIN_BRUSH_WIDTH;
|
|
100
|
+
return isArrow(shape) || paintsFillOnStroke(shape) ? MIN_LINE_STROKE_WIDTH : 0;
|
|
55
101
|
}
|
|
56
|
-
|
|
57
|
-
const MAX_STROKE_WIDTH = 200;
|
|
58
|
-
const RANGES = {
|
|
102
|
+
var RANGES = {
|
|
59
103
|
opacity: [0, 1],
|
|
60
104
|
fillOpacity: [0, 1],
|
|
61
105
|
strokeWidth: [0, MAX_STROKE_WIDTH],
|
|
@@ -65,7 +109,7 @@ const RANGES = {
|
|
|
65
109
|
padding: [0, 200]
|
|
66
110
|
};
|
|
67
111
|
/** The line-only icons of the library (a check, a cross, a plus, a minus): their colour is the colour of the line. */
|
|
68
|
-
|
|
112
|
+
var LINE_ICON_KEYS = new Set(['cross', 'plus', 'minus', 'check']);
|
|
69
113
|
/** Whether the "Fill" colour of this shape is really the colour of its line, because it has no inside. */
|
|
70
114
|
export function paintsFillOnStroke(shape) {
|
|
71
115
|
if (shape.type !== 'path' || !shape.shape)
|
|
@@ -86,18 +130,18 @@ export function lineColorOf(shape) {
|
|
|
86
130
|
* Everything else the patch carries means nothing to a stroke and is left out. Same object back when nothing changes.
|
|
87
131
|
*/
|
|
88
132
|
function applyBrushStylePatch(shape, patch) {
|
|
89
|
-
|
|
133
|
+
var next = shape;
|
|
90
134
|
if (patch.opacity !== undefined) {
|
|
91
|
-
|
|
135
|
+
var opacity = clampNumber(patch.opacity, 0, 1);
|
|
92
136
|
if (opacity !== next.opacity)
|
|
93
|
-
next = {
|
|
137
|
+
next = __assign(__assign({}, next), { opacity: opacity });
|
|
94
138
|
}
|
|
95
139
|
if (patch.stroke !== undefined && patch.stroke !== next.fill)
|
|
96
|
-
next = {
|
|
140
|
+
next = __assign(__assign({}, next), { fill: patch.stroke });
|
|
97
141
|
if (patch.strokeWidth !== undefined) {
|
|
98
|
-
|
|
142
|
+
var strokeWidth = clampNumber(patch.strokeWidth, MIN_BRUSH_WIDTH, MAX_STROKE_WIDTH);
|
|
99
143
|
if (strokeWidth !== next.strokeWidth)
|
|
100
|
-
next = reshapeBrushStroke(next, { strokeWidth });
|
|
144
|
+
next = reshapeBrushStroke(next, { strokeWidth: strokeWidth });
|
|
101
145
|
}
|
|
102
146
|
return next;
|
|
103
147
|
}
|
|
@@ -105,45 +149,50 @@ function applyBrushStylePatch(shape, patch) {
|
|
|
105
149
|
export function applyStylePatch(shape, requested) {
|
|
106
150
|
if (isBrushStroke(shape))
|
|
107
151
|
return applyBrushStylePatch(shape, requested);
|
|
108
|
-
|
|
152
|
+
var patch = requested;
|
|
109
153
|
if (patch.fill !== undefined && paintsFillOnStroke(shape)) {
|
|
110
154
|
// The panel's Fill colour is the colour of the line for these icons.
|
|
111
|
-
|
|
112
|
-
patch = {
|
|
155
|
+
var fill = patch.fill, rest = __rest(patch, ["fill"]);
|
|
156
|
+
patch = __assign(__assign({}, rest), { stroke: fill });
|
|
113
157
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
for (
|
|
158
|
+
var allowed = keysFor(shape);
|
|
159
|
+
var changes = {};
|
|
160
|
+
for (var _i = 0, allowed_1 = allowed; _i < allowed_1.length; _i++) {
|
|
161
|
+
var key = allowed_1[_i];
|
|
117
162
|
if (!(key in patch))
|
|
118
163
|
continue;
|
|
119
|
-
|
|
164
|
+
var value = patch[key];
|
|
120
165
|
if (value === undefined)
|
|
121
166
|
continue;
|
|
122
|
-
|
|
167
|
+
var range = RANGES[key];
|
|
123
168
|
if (range && typeof value === 'number')
|
|
124
169
|
value = clampNumber(value, range[0], range[1]);
|
|
170
|
+
// A line is never made so thin that it is gone (an arrow with no line would vanish with nothing left to take hold of).
|
|
171
|
+
if (key === 'strokeWidth' && typeof value === 'number')
|
|
172
|
+
value = Math.max(value, minimumStrokeWidthOf(shape));
|
|
125
173
|
if (shape[key] !== value)
|
|
126
174
|
changes[key] = value;
|
|
127
175
|
}
|
|
128
176
|
if (Object.keys(changes).length === 0)
|
|
129
177
|
return shape;
|
|
130
|
-
|
|
131
|
-
// The head of an arrow is sized by the width of its line
|
|
178
|
+
var next = __assign(__assign({}, shape), changes);
|
|
179
|
+
// The head of an arrow is sized by the width of its line (a thicker line has a bigger head, a thinner one keeps the head of the
|
|
180
|
+
// Arrow tool's width), so a new width draws the arrow again.
|
|
132
181
|
if (isArrow(next) && 'strokeWidth' in changes)
|
|
133
182
|
next = reshapeArrow(next);
|
|
134
183
|
if (next.type === 'path' && 'roundness' in changes) {
|
|
135
184
|
if (roundnessIsLineEnds(next.shape)) {
|
|
136
|
-
|
|
137
|
-
next = {
|
|
185
|
+
var rounded = next.roundness > 0;
|
|
186
|
+
next = __assign(__assign({}, next), { lineCap: (rounded ? 'round' : 'butt'), lineJoin: (rounded ? 'round' : 'miter') });
|
|
138
187
|
}
|
|
139
188
|
else {
|
|
140
|
-
|
|
189
|
+
var commands = regeneratedPathCommands(next, next.width, next.height);
|
|
141
190
|
if (commands) {
|
|
142
|
-
next = {
|
|
191
|
+
next = __assign(__assign({}, next), { d: serializePathData(mirrorPathCommands(commands, next.width, next.height, next.flipX, next.flipY)) });
|
|
143
192
|
}
|
|
144
193
|
else {
|
|
145
194
|
// Nothing to rebuild (the path is drawn, not generated): the roundness stays as it was.
|
|
146
|
-
next = {
|
|
195
|
+
next = __assign(__assign({}, next), { roundness: shape.type === 'path' ? shape.roundness : 0 });
|
|
147
196
|
}
|
|
148
197
|
}
|
|
149
198
|
}
|
|
@@ -40,6 +40,12 @@ export declare function handleDirection(handle: ResizeHandle): {
|
|
|
40
40
|
export declare function selectionFrameOf(shapes: readonly ShapeObject[]): SelectionFrame | null;
|
|
41
41
|
/** The centre of a frame in the world. */
|
|
42
42
|
export declare function frameCenter(frame: SelectionFrame): Point;
|
|
43
|
+
/**
|
|
44
|
+
* 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
|
|
45
|
+
* the points inside its turned box and not those of the upright rectangle around it. A box with no width or no height holds
|
|
46
|
+
* only the points on its line.
|
|
47
|
+
*/
|
|
48
|
+
export declare function frameContains(frame: SelectionFrame, point: Point): boolean;
|
|
43
49
|
/**
|
|
44
50
|
* The frame that results from dragging `handle` to a world point.
|
|
45
51
|
* `frame` is the frame when the drag began (not the one the last pointer move produced).
|