@widgetic/canvas 0.5.41 → 0.5.42
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/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +17 -18
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.js +1286 -1536
- 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/pageEvents.js +4 -4
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +3 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +18 -18
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.js +696 -795
- package/dist/engine/codec/canvasDocument.js +183 -147
- 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.js +33 -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.js +129 -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.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 +262 -308
- 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.js +4 -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.js +17 -68
- package/dist/fonts/workspaceFonts.js +32 -90
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/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
|
@@ -7,148 +7,101 @@
|
|
|
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;
|
|
33
10
|
import { clampNumber } from './geometry.js';
|
|
34
11
|
/** How far, in screen pixels, a line reaches to catch the dragged edge when the pointer is slow. */
|
|
35
|
-
export
|
|
12
|
+
export const SNAP_THRESHOLD_PIXELS = 8;
|
|
36
13
|
/** At or below this speed (pixels per millisecond) the snap has its full reach. */
|
|
37
|
-
export
|
|
14
|
+
export const SNAP_SLOW_SPEED = 0.25;
|
|
38
15
|
/** At or above this speed the snap has no reach at all. */
|
|
39
|
-
export
|
|
16
|
+
export const SNAP_FAST_SPEED = 0.9;
|
|
40
17
|
/** Weight of the newest sample in the smoothed pointer speed. */
|
|
41
|
-
export
|
|
42
|
-
export
|
|
18
|
+
export const SNAP_SPEED_SMOOTHING = 0.35;
|
|
19
|
+
export const NO_SNAP = Object.freeze({ deltaX: 0, deltaY: 0, guides: [] });
|
|
43
20
|
/** The reach of a snap in world units for a pointer moving at `speed`, at `zoom`. */
|
|
44
|
-
export function snapReachInWorld(zoom, speed, basePixels) {
|
|
45
|
-
|
|
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);
|
|
21
|
+
export function snapReachInWorld(zoom, speed = 0, basePixels = SNAP_THRESHOLD_PIXELS) {
|
|
22
|
+
const speedFactor = clampNumber((speed - SNAP_SLOW_SPEED) / (SNAP_FAST_SPEED - SNAP_SLOW_SPEED), 0, 1);
|
|
48
23
|
return (basePixels * (1 - speedFactor)) / Math.max(zoom, 1e-6);
|
|
49
24
|
}
|
|
50
25
|
/** Follows how fast the pointer moves, smoothed, in screen pixels per millisecond. */
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
_PointerSpeedTracker_speed.set(this, 0);
|
|
55
|
-
}
|
|
26
|
+
export class PointerSpeedTracker {
|
|
27
|
+
#last = null;
|
|
28
|
+
#speed = 0;
|
|
56
29
|
/** Records a pointer position (screen space) and returns the smoothed speed. */
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
30
|
+
update(x, y, time) {
|
|
31
|
+
if (this.#last && time > this.#last.time) {
|
|
32
|
+
const instant = Math.hypot(x - this.#last.x, y - this.#last.y) / (time - this.#last.time);
|
|
33
|
+
this.#speed = this.#speed * (1 - SNAP_SPEED_SMOOTHING) + instant * SNAP_SPEED_SMOOTHING;
|
|
61
34
|
}
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
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();
|
|
35
|
+
this.#last = { x, y, time };
|
|
36
|
+
return this.#speed;
|
|
37
|
+
}
|
|
38
|
+
get speed() {
|
|
39
|
+
return this.#speed;
|
|
40
|
+
}
|
|
41
|
+
reset() {
|
|
42
|
+
this.#last = null;
|
|
43
|
+
this.#speed = 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
80
46
|
function verticalLinesOf(rects) {
|
|
81
|
-
|
|
82
|
-
for (
|
|
83
|
-
|
|
84
|
-
lines.push({ position: rect.x, rect: rect }, { position: rect.x + rect.width / 2, rect: rect }, { position: rect.x + rect.width, rect: rect });
|
|
47
|
+
const lines = [];
|
|
48
|
+
for (const rect of rects) {
|
|
49
|
+
lines.push({ position: rect.x, rect }, { position: rect.x + rect.width / 2, rect }, { position: rect.x + rect.width, rect });
|
|
85
50
|
}
|
|
86
51
|
return lines;
|
|
87
52
|
}
|
|
88
53
|
function horizontalLinesOf(rects) {
|
|
89
|
-
|
|
90
|
-
for (
|
|
91
|
-
|
|
92
|
-
lines.push({ position: rect.y, rect: rect }, { position: rect.y + rect.height / 2, rect: rect }, { position: rect.y + rect.height, rect: rect });
|
|
54
|
+
const lines = [];
|
|
55
|
+
for (const rect of rects) {
|
|
56
|
+
lines.push({ position: rect.y, rect }, { position: rect.y + rect.height / 2, rect }, { position: rect.y + rect.height, rect });
|
|
93
57
|
}
|
|
94
58
|
return lines;
|
|
95
59
|
}
|
|
96
60
|
/** The smallest signed distance from any anchor to any line, if it is within `reach`. */
|
|
97
61
|
function nearestOffset(anchors, lines, reach) {
|
|
98
|
-
|
|
99
|
-
for (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var line = lines_1[_a];
|
|
103
|
-
var offset = line.position - anchor;
|
|
62
|
+
let best = null;
|
|
63
|
+
for (const anchor of anchors) {
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
const offset = line.position - anchor;
|
|
104
66
|
if (Math.abs(offset) <= reach && (best === null || Math.abs(offset) < Math.abs(best.offset) - 1e-9)) {
|
|
105
|
-
best = { offset
|
|
67
|
+
best = { offset };
|
|
106
68
|
}
|
|
107
69
|
}
|
|
108
70
|
}
|
|
109
71
|
return best;
|
|
110
72
|
}
|
|
111
|
-
|
|
73
|
+
const MATCH_EPSILON = 0.01;
|
|
112
74
|
/**
|
|
113
75
|
* The guides to draw for a box that sits where it will land: every line of the other shapes that one of
|
|
114
76
|
* its anchors is on, spanning both shapes.
|
|
115
77
|
*/
|
|
116
|
-
export function guidesFor(box, others, anchorsOf) {
|
|
117
|
-
|
|
118
|
-
var guides = [];
|
|
78
|
+
export function guidesFor(box, others, anchorsOf = 'both') {
|
|
79
|
+
const guides = [];
|
|
119
80
|
if (anchorsOf !== 'y') {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (anchors.some(
|
|
123
|
-
|
|
124
|
-
|
|
81
|
+
const anchors = [box.x, box.x + box.width / 2, box.x + box.width];
|
|
82
|
+
for (const line of verticalLinesOf(others)) {
|
|
83
|
+
if (anchors.some((anchor) => Math.abs(anchor - line.position) <= MATCH_EPSILON)) {
|
|
84
|
+
const top = Math.min(box.y, line.rect.y);
|
|
85
|
+
const bottom = Math.max(box.y + box.height, line.rect.y + line.rect.height);
|
|
125
86
|
mergeGuide(guides, { orientation: 'vertical', position: line.position, from: top, to: bottom });
|
|
126
87
|
}
|
|
127
|
-
};
|
|
128
|
-
for (var _i = 0, _a = verticalLinesOf(others); _i < _a.length; _i++) {
|
|
129
|
-
var line = _a[_i];
|
|
130
|
-
_loop_1(line);
|
|
131
88
|
}
|
|
132
89
|
}
|
|
133
90
|
if (anchorsOf !== 'x') {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (anchors.some(
|
|
137
|
-
|
|
138
|
-
|
|
91
|
+
const anchors = [box.y, box.y + box.height / 2, box.y + box.height];
|
|
92
|
+
for (const line of horizontalLinesOf(others)) {
|
|
93
|
+
if (anchors.some((anchor) => Math.abs(anchor - line.position) <= MATCH_EPSILON)) {
|
|
94
|
+
const left = Math.min(box.x, line.rect.x);
|
|
95
|
+
const right = Math.max(box.x + box.width, line.rect.x + line.rect.width);
|
|
139
96
|
mergeGuide(guides, { orientation: 'horizontal', position: line.position, from: left, to: right });
|
|
140
97
|
}
|
|
141
|
-
};
|
|
142
|
-
for (var _b = 0, _c = horizontalLinesOf(others); _b < _c.length; _b++) {
|
|
143
|
-
var line = _c[_b];
|
|
144
|
-
_loop_2(line);
|
|
145
98
|
}
|
|
146
99
|
}
|
|
147
100
|
return guides;
|
|
148
101
|
}
|
|
149
102
|
/** Adds a guide, or stretches the one already on the same line to cover it. */
|
|
150
103
|
function mergeGuide(guides, guide) {
|
|
151
|
-
|
|
104
|
+
const existing = guides.find((candidate) => candidate.orientation === guide.orientation && Math.abs(candidate.position - guide.position) <= MATCH_EPSILON);
|
|
152
105
|
if (!existing) {
|
|
153
106
|
guides.push(guide);
|
|
154
107
|
return;
|
|
@@ -161,34 +114,30 @@ function mergeGuide(guides, guide) {
|
|
|
161
114
|
* far to nudge it and which guides to show once it is there.
|
|
162
115
|
*/
|
|
163
116
|
export function computeMoveSnap(moving, others, reach) {
|
|
164
|
-
var _a, _b;
|
|
165
117
|
if (others.length === 0 || reach <= 0)
|
|
166
118
|
return NO_SNAP;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
119
|
+
const x = nearestOffset([moving.x, moving.x + moving.width / 2, moving.x + moving.width], verticalLinesOf(others), reach);
|
|
120
|
+
const y = nearestOffset([moving.y, moving.y + moving.height / 2, moving.y + moving.height], horizontalLinesOf(others), reach);
|
|
121
|
+
const deltaX = x?.offset ?? 0;
|
|
122
|
+
const deltaY = y?.offset ?? 0;
|
|
171
123
|
if (!x && !y)
|
|
172
124
|
return NO_SNAP;
|
|
173
|
-
|
|
174
|
-
return { deltaX
|
|
125
|
+
const landed = { ...moving, x: moving.x + deltaX, y: moving.y + deltaY };
|
|
126
|
+
return { deltaX, deltaY, guides: guidesFor(landed, others, x && y ? 'both' : x ? 'x' : 'y') };
|
|
175
127
|
}
|
|
176
128
|
/**
|
|
177
129
|
* Snaps one point (the corner or edge a handle drags, or a corner of a shape being drawn) to the lines of
|
|
178
130
|
* the other shapes. `axes` says which coordinates may snap (an edge handle moves one only).
|
|
179
131
|
*/
|
|
180
|
-
export function snapPoint(point, others, reach, axes) {
|
|
181
|
-
var _a, _b;
|
|
182
|
-
if (axes === void 0) { axes = { x: true, y: true }; }
|
|
132
|
+
export function snapPoint(point, others, reach, axes = { x: true, y: true }) {
|
|
183
133
|
if (others.length === 0 || reach <= 0)
|
|
184
|
-
return { point
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
134
|
+
return { point, guides: [] };
|
|
135
|
+
const x = axes.x ? nearestOffset([point.x], verticalLinesOf(others), reach) : null;
|
|
136
|
+
const y = axes.y ? nearestOffset([point.y], horizontalLinesOf(others), reach) : null;
|
|
137
|
+
const snapped = { x: point.x + (x?.offset ?? 0), y: point.y + (y?.offset ?? 0) };
|
|
138
|
+
const guides = [];
|
|
189
139
|
if (x) {
|
|
190
|
-
for (
|
|
191
|
-
var line = _c[_i];
|
|
140
|
+
for (const line of verticalLinesOf(others)) {
|
|
192
141
|
if (Math.abs(line.position - snapped.x) <= MATCH_EPSILON) {
|
|
193
142
|
mergeGuide(guides, {
|
|
194
143
|
orientation: 'vertical',
|
|
@@ -200,8 +149,7 @@ export function snapPoint(point, others, reach, axes) {
|
|
|
200
149
|
}
|
|
201
150
|
}
|
|
202
151
|
if (y) {
|
|
203
|
-
for (
|
|
204
|
-
var line = _e[_d];
|
|
152
|
+
for (const line of horizontalLinesOf(others)) {
|
|
205
153
|
if (Math.abs(line.position - snapped.y) <= MATCH_EPSILON) {
|
|
206
154
|
mergeGuide(guides, {
|
|
207
155
|
orientation: 'horizontal',
|
|
@@ -212,5 +160,5 @@ export function snapPoint(point, others, reach, axes) {
|
|
|
212
160
|
}
|
|
213
161
|
}
|
|
214
162
|
}
|
|
215
|
-
return { point: snapped, guides
|
|
163
|
+
return { point: snapped, guides };
|
|
216
164
|
}
|
|
@@ -5,45 +5,14 @@
|
|
|
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
|
-
};
|
|
39
8
|
import { getShapeByKey } from '../../canvas/shapes/ShapeLibrary.js';
|
|
40
9
|
import { isArrow, reshapeArrow } from './arrow.js';
|
|
41
10
|
import { MIN_BRUSH_WIDTH, isBrushStroke, reshapeBrushStroke } from './brush.js';
|
|
42
11
|
import { clampNumber } from './geometry.js';
|
|
43
12
|
import { mirrorPathCommands, serializePathData } from './pathData.js';
|
|
44
13
|
import { regeneratedPathCommands } from './shapePaths.js';
|
|
45
|
-
|
|
46
|
-
|
|
14
|
+
const PAINT_KEYS = ['fill', 'fillOpacity', 'stroke', 'strokeWidth', 'strokeStyle'];
|
|
15
|
+
const TEXT_KEYS = [
|
|
47
16
|
'color',
|
|
48
17
|
'fontSize',
|
|
49
18
|
'fontFamily',
|
|
@@ -59,16 +28,16 @@ var TEXT_KEYS = [
|
|
|
59
28
|
function keysFor(shape) {
|
|
60
29
|
switch (shape.type) {
|
|
61
30
|
case 'rect':
|
|
62
|
-
return
|
|
31
|
+
return ['opacity', 'roundness', ...PAINT_KEYS];
|
|
63
32
|
case 'ellipse':
|
|
64
|
-
return
|
|
33
|
+
return ['opacity', ...PAINT_KEYS];
|
|
65
34
|
case 'path':
|
|
66
35
|
// An arrow is a line and a head: nothing to fill, no corner to round.
|
|
67
36
|
if (isArrow(shape))
|
|
68
37
|
return ['opacity', 'stroke', 'strokeWidth', 'strokeStyle'];
|
|
69
|
-
return
|
|
38
|
+
return ['opacity', 'roundness', ...PAINT_KEYS];
|
|
70
39
|
case 'text':
|
|
71
|
-
return
|
|
40
|
+
return ['opacity', ...TEXT_KEYS];
|
|
72
41
|
default:
|
|
73
42
|
return ['opacity'];
|
|
74
43
|
}
|
|
@@ -77,17 +46,16 @@ function keysFor(shape) {
|
|
|
77
46
|
export function pathSupportsRoundness(shapeKey) {
|
|
78
47
|
if (shapeKey === 'triangle')
|
|
79
48
|
return true;
|
|
80
|
-
|
|
49
|
+
const shape = getShapeByKey(shapeKey);
|
|
81
50
|
return !!shape && (shape.cornerRadiusMode === 'pathRegen' || shape.cornerRadiusMode === 'strokeRound');
|
|
82
51
|
}
|
|
83
52
|
/** Whether the shape's roundness is the shape of its line ends rather than of its corners. */
|
|
84
53
|
function roundnessIsLineEnds(shapeKey) {
|
|
85
|
-
|
|
86
|
-
return ((_a = getShapeByKey(shapeKey)) === null || _a === void 0 ? void 0 : _a.cornerRadiusMode) === 'strokeRound';
|
|
54
|
+
return getShapeByKey(shapeKey)?.cornerRadiusMode === 'strokeRound';
|
|
87
55
|
}
|
|
88
56
|
/** The widest a line may be made with the Width control. */
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
const MAX_STROKE_WIDTH = 200;
|
|
58
|
+
const RANGES = {
|
|
91
59
|
opacity: [0, 1],
|
|
92
60
|
fillOpacity: [0, 1],
|
|
93
61
|
strokeWidth: [0, MAX_STROKE_WIDTH],
|
|
@@ -97,7 +65,7 @@ var RANGES = {
|
|
|
97
65
|
padding: [0, 200]
|
|
98
66
|
};
|
|
99
67
|
/** The line-only icons of the library (a check, a cross, a plus, a minus): their colour is the colour of the line. */
|
|
100
|
-
|
|
68
|
+
const LINE_ICON_KEYS = new Set(['cross', 'plus', 'minus', 'check']);
|
|
101
69
|
/** Whether the "Fill" colour of this shape is really the colour of its line, because it has no inside. */
|
|
102
70
|
export function paintsFillOnStroke(shape) {
|
|
103
71
|
if (shape.type !== 'path' || !shape.shape)
|
|
@@ -118,18 +86,18 @@ export function lineColorOf(shape) {
|
|
|
118
86
|
* Everything else the patch carries means nothing to a stroke and is left out. Same object back when nothing changes.
|
|
119
87
|
*/
|
|
120
88
|
function applyBrushStylePatch(shape, patch) {
|
|
121
|
-
|
|
89
|
+
let next = shape;
|
|
122
90
|
if (patch.opacity !== undefined) {
|
|
123
|
-
|
|
91
|
+
const opacity = clampNumber(patch.opacity, 0, 1);
|
|
124
92
|
if (opacity !== next.opacity)
|
|
125
|
-
next =
|
|
93
|
+
next = { ...next, opacity };
|
|
126
94
|
}
|
|
127
95
|
if (patch.stroke !== undefined && patch.stroke !== next.fill)
|
|
128
|
-
next =
|
|
96
|
+
next = { ...next, fill: patch.stroke };
|
|
129
97
|
if (patch.strokeWidth !== undefined) {
|
|
130
|
-
|
|
98
|
+
const strokeWidth = clampNumber(patch.strokeWidth, MIN_BRUSH_WIDTH, MAX_STROKE_WIDTH);
|
|
131
99
|
if (strokeWidth !== next.strokeWidth)
|
|
132
|
-
next = reshapeBrushStroke(next, { strokeWidth
|
|
100
|
+
next = reshapeBrushStroke(next, { strokeWidth });
|
|
133
101
|
}
|
|
134
102
|
return next;
|
|
135
103
|
}
|
|
@@ -137,22 +105,21 @@ function applyBrushStylePatch(shape, patch) {
|
|
|
137
105
|
export function applyStylePatch(shape, requested) {
|
|
138
106
|
if (isBrushStroke(shape))
|
|
139
107
|
return applyBrushStylePatch(shape, requested);
|
|
140
|
-
|
|
108
|
+
let patch = requested;
|
|
141
109
|
if (patch.fill !== undefined && paintsFillOnStroke(shape)) {
|
|
142
110
|
// The panel's Fill colour is the colour of the line for these icons.
|
|
143
|
-
|
|
144
|
-
patch =
|
|
111
|
+
const { fill, ...rest } = patch;
|
|
112
|
+
patch = { ...rest, stroke: fill };
|
|
145
113
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
for (
|
|
149
|
-
var key = allowed_1[_i];
|
|
114
|
+
const allowed = keysFor(shape);
|
|
115
|
+
const changes = {};
|
|
116
|
+
for (const key of allowed) {
|
|
150
117
|
if (!(key in patch))
|
|
151
118
|
continue;
|
|
152
|
-
|
|
119
|
+
let value = patch[key];
|
|
153
120
|
if (value === undefined)
|
|
154
121
|
continue;
|
|
155
|
-
|
|
122
|
+
const range = RANGES[key];
|
|
156
123
|
if (range && typeof value === 'number')
|
|
157
124
|
value = clampNumber(value, range[0], range[1]);
|
|
158
125
|
if (shape[key] !== value)
|
|
@@ -160,23 +127,23 @@ export function applyStylePatch(shape, requested) {
|
|
|
160
127
|
}
|
|
161
128
|
if (Object.keys(changes).length === 0)
|
|
162
129
|
return shape;
|
|
163
|
-
|
|
130
|
+
let next = { ...shape, ...changes };
|
|
164
131
|
// The head of an arrow is sized by the width of its line, so a new width draws the arrow again.
|
|
165
132
|
if (isArrow(next) && 'strokeWidth' in changes)
|
|
166
133
|
next = reshapeArrow(next);
|
|
167
134
|
if (next.type === 'path' && 'roundness' in changes) {
|
|
168
135
|
if (roundnessIsLineEnds(next.shape)) {
|
|
169
|
-
|
|
170
|
-
next =
|
|
136
|
+
const rounded = next.roundness > 0;
|
|
137
|
+
next = { ...next, lineCap: (rounded ? 'round' : 'butt'), lineJoin: (rounded ? 'round' : 'miter') };
|
|
171
138
|
}
|
|
172
139
|
else {
|
|
173
|
-
|
|
140
|
+
const commands = regeneratedPathCommands(next, next.width, next.height);
|
|
174
141
|
if (commands) {
|
|
175
|
-
next =
|
|
142
|
+
next = { ...next, d: serializePathData(mirrorPathCommands(commands, next.width, next.height, next.flipX, next.flipY)) };
|
|
176
143
|
}
|
|
177
144
|
else {
|
|
178
145
|
// Nothing to rebuild (the path is drawn, not generated): the roundness stays as it was.
|
|
179
|
-
next =
|
|
146
|
+
next = { ...next, roundness: shape.type === 'path' ? shape.roundness : 0 };
|
|
180
147
|
}
|
|
181
148
|
}
|
|
182
149
|
}
|