@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
|
@@ -4,13 +4,23 @@
|
|
|
4
4
|
* Both work on the units of a selection (a group is one unit), measured by the rectangle around the shapes
|
|
5
5
|
* they draw, and move whole units: nothing is resized.
|
|
6
6
|
*/
|
|
7
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
8
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
9
|
+
if (ar || !(i in from)) {
|
|
10
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
11
|
+
ar[i] = from[i];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
15
|
+
};
|
|
7
16
|
import { boundsOfObjects, normalizeSelection, translateObjects } from './scene.js';
|
|
8
17
|
function unitsOf(scene, ids) {
|
|
9
|
-
|
|
10
|
-
for (
|
|
11
|
-
|
|
18
|
+
var units = [];
|
|
19
|
+
for (var _i = 0, _a = normalizeSelection(scene, ids); _i < _a.length; _i++) {
|
|
20
|
+
var id = _a[_i];
|
|
21
|
+
var bounds = boundsOfObjects(scene, [id]);
|
|
12
22
|
if (bounds)
|
|
13
|
-
units.push({ id, bounds });
|
|
23
|
+
units.push({ id: id, bounds: bounds });
|
|
14
24
|
}
|
|
15
25
|
return units;
|
|
16
26
|
}
|
|
@@ -19,17 +29,18 @@ function unitsOf(scene, ids) {
|
|
|
19
29
|
* Needs two units or more; returns the same scene otherwise, or when everything is already in line.
|
|
20
30
|
*/
|
|
21
31
|
export function alignObjects(scene, ids, mode) {
|
|
22
|
-
|
|
32
|
+
var units = unitsOf(scene, ids);
|
|
23
33
|
if (units.length < 2)
|
|
24
34
|
return scene;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
var left = Math.min.apply(Math, units.map(function (unit) { return unit.bounds.x; }));
|
|
36
|
+
var right = Math.max.apply(Math, units.map(function (unit) { return unit.bounds.x + unit.bounds.width; }));
|
|
37
|
+
var top = Math.min.apply(Math, units.map(function (unit) { return unit.bounds.y; }));
|
|
38
|
+
var bottom = Math.max.apply(Math, units.map(function (unit) { return unit.bounds.y + unit.bounds.height; }));
|
|
39
|
+
var next = scene;
|
|
40
|
+
for (var _i = 0, units_1 = units; _i < units_1.length; _i++) {
|
|
41
|
+
var unit = units_1[_i];
|
|
42
|
+
var deltaX = 0;
|
|
43
|
+
var deltaY = 0;
|
|
33
44
|
switch (mode) {
|
|
34
45
|
case 'left':
|
|
35
46
|
deltaX = left - unit.bounds.x;
|
|
@@ -59,21 +70,22 @@ export function alignObjects(scene, ids, mode) {
|
|
|
59
70
|
* Needs three units or more.
|
|
60
71
|
*/
|
|
61
72
|
export function distributeObjects(scene, ids, axis) {
|
|
62
|
-
|
|
73
|
+
var units = unitsOf(scene, ids);
|
|
63
74
|
if (units.length < 3)
|
|
64
75
|
return scene;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
for (
|
|
76
|
-
|
|
76
|
+
var start = function (unit) { return (axis === 'horizontal' ? unit.bounds.x : unit.bounds.y); };
|
|
77
|
+
var size = function (unit) { return (axis === 'horizontal' ? unit.bounds.width : unit.bounds.height); };
|
|
78
|
+
var ordered = __spreadArray([], units, true).sort(function (first, second) { return start(first) - start(second); });
|
|
79
|
+
var first = ordered[0];
|
|
80
|
+
var last = ordered[ordered.length - 1];
|
|
81
|
+
var span = start(last) + size(last) - start(first);
|
|
82
|
+
var occupied = ordered.reduce(function (total, unit) { return total + size(unit); }, 0);
|
|
83
|
+
var gap = (span - occupied) / (ordered.length - 1);
|
|
84
|
+
var next = scene;
|
|
85
|
+
var cursor = start(first) + size(first) + gap;
|
|
86
|
+
for (var _i = 0, _a = ordered.slice(1, -1); _i < _a.length; _i++) {
|
|
87
|
+
var unit = _a[_i];
|
|
88
|
+
var delta = cursor - start(unit);
|
|
77
89
|
next = axis === 'horizontal' ? translateObjects(next, [unit.id], delta, 0) : translateObjects(next, [unit.id], 0, delta);
|
|
78
90
|
cursor += size(unit) + gap;
|
|
79
91
|
}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* circle that goes through the start, the end and that middle. A bend smaller than `MIN_ARROW_BEND` is no bend at all, so an
|
|
8
8
|
* arrow is straight until it is clearly curved.
|
|
9
9
|
* - The head, an open chevron on the end: two wings that open `ARROW_HEAD_ANGLE` (30 degrees) either side of the shaft. Its
|
|
10
|
-
* length is a fifth of the arrow, but never less than
|
|
11
|
-
* arrow has a short head and a long one does not get a big one. Because the head is drawn from the arrow and not scaled with
|
|
12
|
-
* it keeps its size when the arrow is stretched
|
|
10
|
+
* length is a fifth of the arrow, but never less than `ARROW_HEAD_MIN_LENGTH` and never more than `ARROW_HEAD_MAX_LENGTH`, so a
|
|
11
|
+
* short arrow has a short head and a long one does not get a big one. Because the head is drawn from the arrow and not scaled with
|
|
12
|
+
* it, it keeps its size when the arrow is stretched. That is the head of the line the Arrow tool draws with (3 wide): a thinner
|
|
13
|
+
* line keeps it, so the head is not left smaller and smaller as the line is made thinner, and a thicker line grows it in step
|
|
14
|
+
* with the line (twice as wide, twice as long), though never past half the arrow.
|
|
13
15
|
*
|
|
14
16
|
* Everything here is a pure function of numbers, in whatever frame the points are given in (the world, usually). The path comes back
|
|
15
17
|
* in the coordinates of the box that holds it, ready to be written into a path object, together with that box and the arrow's
|
|
@@ -22,10 +24,14 @@ import type { ArrowSpec, PathObject, Point, Rect, ShapeObject } from './types.js
|
|
|
22
24
|
export declare const ARROW_HEAD_ANGLE: number;
|
|
23
25
|
/** The head is this fraction of the length of the arrow ... */
|
|
24
26
|
export declare const ARROW_HEAD_LENGTH_FRACTION: number;
|
|
25
|
-
/** ... but at least this
|
|
26
|
-
export declare const
|
|
27
|
-
/** ... and at most this
|
|
28
|
-
export declare const
|
|
27
|
+
/** ... but at least this long (world units) ... */
|
|
28
|
+
export declare const ARROW_HEAD_MIN_LENGTH = 3;
|
|
29
|
+
/** ... and at most this long: the head of the line the Arrow tool draws with. */
|
|
30
|
+
export declare const ARROW_HEAD_MAX_LENGTH = 9;
|
|
31
|
+
/** The width of that line (the Arrow tool's own, `ARROW_PAINT`): a line this thin or thinner has that head, a thicker one has it grown. */
|
|
32
|
+
export declare const ARROW_HEAD_REFERENCE_WIDTH = 3;
|
|
33
|
+
/** A head grown for a thick line is at most this fraction of the arrow, so that a short, thick arrow is not all head. */
|
|
34
|
+
export declare const ARROW_HEAD_GROWTH_LIMIT_FRACTION: number;
|
|
29
35
|
/** A bend smaller than this (world units) is not a bend: the arrow is straight. */
|
|
30
36
|
export declare const MIN_ARROW_BEND = 8;
|
|
31
37
|
/** An arrow bends by at most this many times its own length (a little under a full circle). */
|
|
@@ -48,7 +54,11 @@ export type ArrowObject = PathObject & {
|
|
|
48
54
|
export declare function isArrow(shape: ShapeObject): shape is ArrowObject;
|
|
49
55
|
/** The bend that is drawn for a bend that was asked for: none below the threshold, and never more than the arrow can hold. */
|
|
50
56
|
export declare function drawnBend(bend: number, length: number): number;
|
|
51
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The length of the head for an arrow whose shaft is `bodyLength` long, drawn with a line `strokeWidth` wide. A line as thin as the
|
|
59
|
+
* Arrow tool's, or thinner, has the head the length of the arrow gives, so making the line thinner never makes the head smaller; a
|
|
60
|
+
* thicker line grows that head in step with the line (twice the width, twice the head), up to half the arrow.
|
|
61
|
+
*/
|
|
52
62
|
export declare function arrowHeadLength(bodyLength: number, strokeWidth: number): number;
|
|
53
63
|
/** The middle of the arrow: the middle of the line between its ends, pushed `bend` to the right of the way it points. */
|
|
54
64
|
export declare function arrowMiddle(start: Point, end: Point, bend: number): Point;
|
|
@@ -7,31 +7,55 @@
|
|
|
7
7
|
* circle that goes through the start, the end and that middle. A bend smaller than `MIN_ARROW_BEND` is no bend at all, so an
|
|
8
8
|
* arrow is straight until it is clearly curved.
|
|
9
9
|
* - The head, an open chevron on the end: two wings that open `ARROW_HEAD_ANGLE` (30 degrees) either side of the shaft. Its
|
|
10
|
-
* length is a fifth of the arrow, but never less than
|
|
11
|
-
* arrow has a short head and a long one does not get a big one. Because the head is drawn from the arrow and not scaled with
|
|
12
|
-
* it keeps its size when the arrow is stretched
|
|
10
|
+
* length is a fifth of the arrow, but never less than `ARROW_HEAD_MIN_LENGTH` and never more than `ARROW_HEAD_MAX_LENGTH`, so a
|
|
11
|
+
* short arrow has a short head and a long one does not get a big one. Because the head is drawn from the arrow and not scaled with
|
|
12
|
+
* it, it keeps its size when the arrow is stretched. That is the head of the line the Arrow tool draws with (3 wide): a thinner
|
|
13
|
+
* line keeps it, so the head is not left smaller and smaller as the line is made thinner, and a thicker line grows it in step
|
|
14
|
+
* with the line (twice as wide, twice as long), though never past half the arrow.
|
|
13
15
|
*
|
|
14
16
|
* Everything here is a pure function of numbers, in whatever frame the points are given in (the world, usually). The path comes back
|
|
15
17
|
* in the coordinates of the box that holds it, ready to be written into a path object, together with that box and the arrow's
|
|
16
18
|
* `ArrowSpec` in the same coordinates.
|
|
17
19
|
*/
|
|
20
|
+
var __assign = (this && this.__assign) || function () {
|
|
21
|
+
__assign = Object.assign || function(t) {
|
|
22
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
+
s = arguments[i];
|
|
24
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
25
|
+
t[p] = s[p];
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
};
|
|
29
|
+
return __assign.apply(this, arguments);
|
|
30
|
+
};
|
|
31
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
32
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
33
|
+
if (ar || !(i in from)) {
|
|
34
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
35
|
+
ar[i] = from[i];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
39
|
+
};
|
|
18
40
|
import { withBindings } from './arrowBindingRecords.js';
|
|
19
41
|
import { clampNumber } from './geometry.js';
|
|
20
42
|
import { parsePathData, pathBounds, serializePathData, translatePathCommands } from './pathData.js';
|
|
21
43
|
/** The wings of the head open this far either side of the shaft (30 degrees). */
|
|
22
|
-
export
|
|
44
|
+
export var ARROW_HEAD_ANGLE = Math.PI / 6;
|
|
23
45
|
/** The head is this fraction of the length of the arrow ... */
|
|
24
|
-
export
|
|
25
|
-
/** ... but at least this
|
|
26
|
-
export
|
|
27
|
-
/** ... and at most this
|
|
28
|
-
export
|
|
46
|
+
export var ARROW_HEAD_LENGTH_FRACTION = 1 / 5;
|
|
47
|
+
/** ... but at least this long (world units) ... */
|
|
48
|
+
export var ARROW_HEAD_MIN_LENGTH = 3;
|
|
49
|
+
/** ... and at most this long: the head of the line the Arrow tool draws with. */
|
|
50
|
+
export var ARROW_HEAD_MAX_LENGTH = 9;
|
|
51
|
+
/** The width of that line (the Arrow tool's own, `ARROW_PAINT`): a line this thin or thinner has that head, a thicker one has it grown. */
|
|
52
|
+
export var ARROW_HEAD_REFERENCE_WIDTH = 3;
|
|
53
|
+
/** A head grown for a thick line is at most this fraction of the arrow, so that a short, thick arrow is not all head. */
|
|
54
|
+
export var ARROW_HEAD_GROWTH_LIMIT_FRACTION = 1 / 2;
|
|
29
55
|
/** A bend smaller than this (world units) is not a bend: the arrow is straight. */
|
|
30
|
-
export
|
|
56
|
+
export var MIN_ARROW_BEND = 8;
|
|
31
57
|
/** An arrow bends by at most this many times its own length (a little under a full circle). */
|
|
32
|
-
export
|
|
33
|
-
/** The line is at least this wide for the size of the head, so that an arrow drawn with no line still has one. */
|
|
34
|
-
const MIN_HEAD_LINE_WIDTH = 1;
|
|
58
|
+
export var MAX_ARROW_BEND_PER_LENGTH = 2;
|
|
35
59
|
/** Whether a shape is an arrow made by the Arrow tool, with the points it is drawn from. */
|
|
36
60
|
export function isArrow(shape) {
|
|
37
61
|
return shape.type === 'path' && shape.arrow !== null;
|
|
@@ -42,30 +66,38 @@ export function drawnBend(bend, length) {
|
|
|
42
66
|
return 0;
|
|
43
67
|
return clampNumber(bend, -MAX_ARROW_BEND_PER_LENGTH * length, MAX_ARROW_BEND_PER_LENGTH * length);
|
|
44
68
|
}
|
|
45
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* The length of the head for an arrow whose shaft is `bodyLength` long, drawn with a line `strokeWidth` wide. A line as thin as the
|
|
71
|
+
* Arrow tool's, or thinner, has the head the length of the arrow gives, so making the line thinner never makes the head smaller; a
|
|
72
|
+
* thicker line grows that head in step with the line (twice the width, twice the head), up to half the arrow.
|
|
73
|
+
*/
|
|
46
74
|
export function arrowHeadLength(bodyLength, strokeWidth) {
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
// A width that is not a number is taken for the Arrow tool's own, which asks the head for no growth.
|
|
76
|
+
var lineWidth = Number.isFinite(strokeWidth) ? strokeWidth : ARROW_HEAD_REFERENCE_WIDTH;
|
|
77
|
+
var lengthFromArrow = clampNumber(bodyLength * ARROW_HEAD_LENGTH_FRACTION, ARROW_HEAD_MIN_LENGTH, ARROW_HEAD_MAX_LENGTH);
|
|
78
|
+
var lengthGrownForLine = lengthFromArrow * Math.max(1, lineWidth / ARROW_HEAD_REFERENCE_WIDTH);
|
|
79
|
+
// The growth stops at half the arrow, and never takes the head below the one the length gives (a very short arrow is all head).
|
|
80
|
+
return Math.max(lengthFromArrow, Math.min(lengthGrownForLine, bodyLength * ARROW_HEAD_GROWTH_LIMIT_FRACTION));
|
|
49
81
|
}
|
|
50
82
|
/** A point turned about another by an angle (radians, clockwise on screen). */
|
|
51
83
|
function rotateAbout(point, center, radians) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
84
|
+
var cosine = Math.cos(radians);
|
|
85
|
+
var sine = Math.sin(radians);
|
|
86
|
+
var offsetX = point.x - center.x;
|
|
87
|
+
var offsetY = point.y - center.y;
|
|
56
88
|
return { x: center.x + offsetX * cosine - offsetY * sine, y: center.y + offsetX * sine + offsetY * cosine };
|
|
57
89
|
}
|
|
58
90
|
/** The direction from one point to another, and the normal to the right of it. A point that is the other's own has a direction to the right. */
|
|
59
91
|
function directionBetween(start, end) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return { length, unit, normal: { x: -unit.y, y: unit.x } };
|
|
92
|
+
var deltaX = end.x - start.x;
|
|
93
|
+
var deltaY = end.y - start.y;
|
|
94
|
+
var length = Math.hypot(deltaX, deltaY);
|
|
95
|
+
var unit = length > 1e-9 ? { x: deltaX / length, y: deltaY / length } : { x: 1, y: 0 };
|
|
96
|
+
return { length: length, unit: unit, normal: { x: -unit.y, y: unit.x } };
|
|
65
97
|
}
|
|
66
98
|
/** The middle of the arrow: the middle of the line between its ends, pushed `bend` to the right of the way it points. */
|
|
67
99
|
export function arrowMiddle(start, end, bend) {
|
|
68
|
-
|
|
100
|
+
var normal = directionBetween(start, end).normal;
|
|
69
101
|
return { x: (start.x + end.x) / 2 + normal.x * bend, y: (start.y + end.y) / 2 + normal.y * bend };
|
|
70
102
|
}
|
|
71
103
|
/**
|
|
@@ -73,7 +105,7 @@ export function arrowMiddle(start, end, bend) {
|
|
|
73
105
|
* measured along the normal to it (so the middle follows the pointer without sliding along the arrow).
|
|
74
106
|
*/
|
|
75
107
|
export function bendTowards(start, end, point) {
|
|
76
|
-
|
|
108
|
+
var normal = directionBetween(start, end).normal;
|
|
77
109
|
return (point.x - (start.x + end.x) / 2) * normal.x + (point.y - (start.y + end.y) / 2) * normal.y;
|
|
78
110
|
}
|
|
79
111
|
/**
|
|
@@ -81,52 +113,53 @@ export function bendTowards(start, end, point) {
|
|
|
81
113
|
* come back in the frame the points were given in, the path moved to the corner of the box that holds it.
|
|
82
114
|
*/
|
|
83
115
|
export function buildArrow(start, end, bend, strokeWidth) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
116
|
+
var _a, _b;
|
|
117
|
+
var _c = directionBetween(start, end), length = _c.length, unit = _c.unit, normal = _c.normal;
|
|
118
|
+
var bent = drawnBend(bend, length);
|
|
119
|
+
var middle = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };
|
|
120
|
+
var shaft;
|
|
121
|
+
var bodyLength = length;
|
|
89
122
|
// The point of the shaft one head-length back from the tip: the head is the shaft's own direction turned either way.
|
|
90
|
-
|
|
123
|
+
var pointBack;
|
|
91
124
|
if (bent === 0) {
|
|
92
125
|
shaft = [
|
|
93
126
|
['M', start.x, start.y],
|
|
94
127
|
['L', end.x, end.y]
|
|
95
128
|
];
|
|
96
|
-
pointBack = (headLength)
|
|
129
|
+
pointBack = function (headLength) { return ({ x: end.x - unit.x * headLength, y: end.y - unit.y * headLength }); };
|
|
97
130
|
}
|
|
98
131
|
else {
|
|
99
132
|
// The circle through the start, the end and the middle: the arc between the ends that goes by the middle.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
133
|
+
var half = length / 2;
|
|
134
|
+
var sagitta = Math.abs(bent);
|
|
135
|
+
var radius_1 = (half * half + sagitta * sagitta) / (2 * sagitta);
|
|
136
|
+
var centerAlongNormal = bent - Math.sign(bent) * radius_1;
|
|
137
|
+
var center_1 = { x: middle.x + normal.x * centerAlongNormal, y: middle.y + normal.y * centerAlongNormal };
|
|
138
|
+
var largeArc = sagitta > half ? 1 : 0;
|
|
106
139
|
// To the right of the way it points (a positive bend) the arc runs against the clock on the screen.
|
|
107
|
-
|
|
108
|
-
shaft = parsePathData(
|
|
109
|
-
bodyLength = 2 *
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
pointBack = (headLength)
|
|
140
|
+
var sweep = bent > 0 ? 0 : 1;
|
|
141
|
+
shaft = parsePathData("M ".concat(start.x, " ").concat(start.y, " A ").concat(radius_1, " ").concat(radius_1, " 0 ").concat(largeArc, " ").concat(sweep, " ").concat(end.x, " ").concat(end.y));
|
|
142
|
+
bodyLength = 2 * radius_1 * Math.atan2(half, radius_1 - sagitta);
|
|
143
|
+
var travel_1 = bent > 0 ? -1 : 1;
|
|
144
|
+
var tipAngle_1 = Math.atan2(end.y - center_1.y, end.x - center_1.x);
|
|
145
|
+
pointBack = function (headLength) {
|
|
113
146
|
// The point of the arc that is `headLength` from the tip as the crow flies, a little way back along the arc.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return { x:
|
|
147
|
+
var turn = 2 * Math.asin(Math.min(1, headLength / (2 * radius_1)));
|
|
148
|
+
var angle = tipAngle_1 - travel_1 * turn;
|
|
149
|
+
return { x: center_1.x + radius_1 * Math.cos(angle), y: center_1.y + radius_1 * Math.sin(angle) };
|
|
117
150
|
};
|
|
118
151
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
152
|
+
var headLength = arrowHeadLength(bodyLength, strokeWidth);
|
|
153
|
+
var back = pointBack(headLength);
|
|
154
|
+
var leftWing = rotateAbout(back, end, ARROW_HEAD_ANGLE);
|
|
155
|
+
var rightWing = rotateAbout(back, end, -ARROW_HEAD_ANGLE);
|
|
156
|
+
var world = __spreadArray(__spreadArray([], shaft, true), [['M', leftWing.x, leftWing.y], ['L', end.x, end.y], ['L', rightWing.x, rightWing.y]], false);
|
|
157
|
+
var bounds = pathBounds(world);
|
|
158
|
+
var origin = bounds ? { x: bounds.x, y: bounds.y } : { x: start.x, y: start.y };
|
|
159
|
+
var box = { x: origin.x, y: origin.y, width: Math.max((_a = bounds === null || bounds === void 0 ? void 0 : bounds.width) !== null && _a !== void 0 ? _a : 0, 1), height: Math.max((_b = bounds === null || bounds === void 0 ? void 0 : bounds.height) !== null && _b !== void 0 ? _b : 0, 1) };
|
|
127
160
|
return {
|
|
128
161
|
commands: translatePathCommands(world, -origin.x, -origin.y),
|
|
129
|
-
box,
|
|
162
|
+
box: box,
|
|
130
163
|
spec: {
|
|
131
164
|
start: { x: start.x - origin.x, y: start.y - origin.y },
|
|
132
165
|
end: { x: end.x - origin.x, y: end.y - origin.y },
|
|
@@ -136,45 +169,37 @@ export function buildArrow(start, end, bend, strokeWidth) {
|
|
|
136
169
|
}
|
|
137
170
|
/** Where the points of an arrow are in the world: its two ends, and the handle in the middle (on the line while the arrow is straight). */
|
|
138
171
|
export function arrowPointsInWorld(shape) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return { start, end, middle: arrowMiddle(start, end, shape.arrow.bend) };
|
|
172
|
+
var start = { x: shape.x + shape.arrow.start.x, y: shape.y + shape.arrow.start.y };
|
|
173
|
+
var end = { x: shape.x + shape.arrow.end.x, y: shape.y + shape.arrow.end.y };
|
|
174
|
+
return { start: start, end: end, middle: arrowMiddle(start, end, shape.arrow.bend) };
|
|
142
175
|
}
|
|
143
176
|
/**
|
|
144
177
|
* The arrow drawn again after a change: a new shape with the same id, the new box, path and points. What its ends are tied to stays
|
|
145
178
|
* as it was unless the change says otherwise (the points do not move because a tie says so here: `arrowBinding.ts` places them).
|
|
146
179
|
*/
|
|
147
|
-
export function reshapeArrow(shape, change
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
180
|
+
export function reshapeArrow(shape, change) {
|
|
181
|
+
var _a, _b, _c, _d;
|
|
182
|
+
if (change === void 0) { change = {}; }
|
|
183
|
+
var current = arrowPointsInWorld(shape);
|
|
184
|
+
var strokeWidth = (_a = change.strokeWidth) !== null && _a !== void 0 ? _a : shape.strokeWidth;
|
|
185
|
+
var geometry = buildArrow((_b = change.start) !== null && _b !== void 0 ? _b : current.start, (_c = change.end) !== null && _c !== void 0 ? _c : current.end, (_d = change.bend) !== null && _d !== void 0 ? _d : shape.arrow.bend, strokeWidth);
|
|
186
|
+
var ties = {
|
|
152
187
|
startBinding: 'startBinding' in change ? change.startBinding : shape.arrow.startBinding,
|
|
153
188
|
endBinding: 'endBinding' in change ? change.endBinding : shape.arrow.endBinding
|
|
154
189
|
};
|
|
155
|
-
return {
|
|
156
|
-
...shape,
|
|
157
|
-
x: geometry.box.x,
|
|
158
|
-
y: geometry.box.y,
|
|
159
|
-
width: geometry.box.width,
|
|
160
|
-
height: geometry.box.height,
|
|
161
|
-
rotation: 0,
|
|
162
|
-
strokeWidth,
|
|
163
|
-
d: serializePathData(geometry.commands),
|
|
164
|
-
arrow: withBindings(geometry.spec, ties)
|
|
165
|
-
};
|
|
190
|
+
return __assign(__assign({}, shape), { x: geometry.box.x, y: geometry.box.y, width: geometry.box.width, height: geometry.box.height, rotation: 0, strokeWidth: strokeWidth, d: serializePathData(geometry.commands), arrow: withBindings(geometry.spec, ties) });
|
|
166
191
|
}
|
|
167
192
|
/**
|
|
168
193
|
* The arrow after the board around it was changed by a mapping of the world (stretched, mirrored, turned): its ends and the middle of
|
|
169
194
|
* its arc go where the mapping sends them, and the bend is whatever puts the arc through those three points.
|
|
170
195
|
*/
|
|
171
196
|
export function transformArrow(shape, mapPoint) {
|
|
172
|
-
|
|
197
|
+
var _a = arrowPointsInWorld(shape), start = _a.start, end = _a.end;
|
|
173
198
|
// The middle the arrow was drawn with, even when it was too small to show: a straight arrow stays straight.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
var middle = arrowMiddle(start, end, shape.arrow.bend);
|
|
200
|
+
var mappedStart = mapPoint(start);
|
|
201
|
+
var mappedEnd = mapPoint(end);
|
|
202
|
+
var mappedMiddle = mapPoint(middle);
|
|
178
203
|
return reshapeArrow(shape, { start: mappedStart, end: mappedEnd, bend: bendTowards(mappedStart, mappedEnd, mappedMiddle) });
|
|
179
204
|
}
|
|
180
205
|
/**
|
|
@@ -182,9 +207,9 @@ export function transformArrow(shape, mapPoint) {
|
|
|
182
207
|
* tip (the shaft, then two wings, each its own sub-path). Null for a path that is not that.
|
|
183
208
|
*/
|
|
184
209
|
export function arrowPointsOfLegacyPath(commands) {
|
|
185
|
-
|
|
210
|
+
var moves = commands.filter(function (command) { return command[0] === 'M'; });
|
|
186
211
|
if (moves.length < 2)
|
|
187
212
|
return null;
|
|
188
|
-
|
|
213
|
+
var first = moves[0], second = moves[1];
|
|
189
214
|
return { start: { x: first[1], y: first[2] }, end: { x: second[1], y: second[2] } };
|
|
190
215
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* `pickArrowBinding` is the other half: which shape a pointer would tie an end to (the topmost one under it that an arrow can be tied
|
|
19
19
|
* to; a hollow shape only near its line, as for any click on it) and how (`edge` when the pointer is near the outline, `center` when
|
|
20
|
-
* it is further in).
|
|
20
|
+
* it is further in; a line drawn by hand is always `edge`: it has no middle to aim at).
|
|
21
21
|
*/
|
|
22
22
|
import type { ArrowObject } from './arrow.js';
|
|
23
23
|
import type { Scene } from './scene.js';
|