@widgetic/canvas 0.5.44 → 0.5.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/canvas/DomCanvas.svelte +52 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
- package/dist/canvas/host/CanvasHost.d.ts +74 -3
- package/dist/canvas/host/CanvasHost.js +278 -16
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +9 -1
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +139 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +58 -0
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/types.d.ts +7 -1
- 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/SelectionPanel.svelte +78 -17
- 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 +34 -55
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +26 -4
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +26 -1
- 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/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +1 -1
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +129 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +15 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/engine/EngineCore.d.ts +46 -4
- package/dist/engine/EngineCore.js +85 -16
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +25 -2
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +24 -12
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +10 -3
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +10 -6
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +10 -2
- package/dist/engine/core/cameraMove.d.ts +6 -0
- package/dist/engine/core/cameraMove.js +6 -0
- package/dist/engine/core/defaults.js +2 -0
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +86 -1
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +19 -3
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +9 -0
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +70 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +41 -10
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +100 -5
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +10 -0
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +44 -29
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +6 -0
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +16 -12
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +138 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +226 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +89 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +122 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +14 -0
- package/dist/settings/workspaceToolSettings.js +21 -10
- package/dist/tools/definitions.js +26 -4
- package/dist/tools/executors.js +81 -5
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +2 -0
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +91 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +1 -0
- package/package.json +2 -2
|
@@ -53,8 +53,15 @@ export declare function createCanvasDocument(scene: readonly SceneObject[], view
|
|
|
53
53
|
/** The text a board is saved as. */
|
|
54
54
|
export declare function serializeCanvasDocument(scene: readonly SceneObject[], viewport: Viewport, options?: SerializeOptions): string;
|
|
55
55
|
export declare function readColor(value: unknown, fallback: string): string;
|
|
56
|
+
/** Whether a text is a well-formed font family name (what a saved board accepts: letters, digits, spaces and a few marks). */
|
|
57
|
+
export declare function isFontFamilyName(value: unknown): boolean;
|
|
56
58
|
/** An image address the browser may load into an `<img>`: inline bytes, http(s), a blob or a path of this site. */
|
|
57
59
|
export declare function readImageAddress(value: unknown): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Where the person's file library keeps a picture: an http(s) address or a path of the page. Never inline bytes (the library
|
|
62
|
+
* address only names the file; the board's own bytes live in `src`/`imageRef`), and never anything a link could abuse.
|
|
63
|
+
*/
|
|
64
|
+
export declare function readLibraryFileAddress(value: unknown): string | null;
|
|
58
65
|
/**
|
|
59
66
|
* Reads a saved canvas: the text `serializeCanvasDocument` wrote, or the same thing already parsed.
|
|
60
67
|
* Never throws.
|
|
@@ -20,6 +20,7 @@ import { clampNumber, roundTo } from '../core/geometry.js';
|
|
|
20
20
|
import { degreesToRadians, normalizeDegrees } from '../core/matrix.js';
|
|
21
21
|
import { parsePathData, serializePathData, translatePathCommands } from '../core/pathData.js';
|
|
22
22
|
import { normalizeScene } from '../core/scene.js';
|
|
23
|
+
import { minimumStrokeWidthOf } from '../core/style.js';
|
|
23
24
|
import { CANVAS_DOCUMENT_VERSION, MIN_OBJECT_SIZE } from '../core/types.js';
|
|
24
25
|
import { sanitizeViewport } from '../core/viewport.js';
|
|
25
26
|
import { HOST_READABLE_KEYS } from './hostReadableKeys.js';
|
|
@@ -54,7 +55,7 @@ const KEYS_BY_TYPE = {
|
|
|
54
55
|
ellipse: [...BOX_KEYS, ...PAINT_KEYS, 'aspectLocked'],
|
|
55
56
|
path: [...BOX_KEYS, ...PAINT_KEYS, 'd', 'shape', 'roundness', 'aspectLocked', 'flipX', 'flipY', 'lineCap', 'lineJoin', 'ink', 'arrow'],
|
|
56
57
|
text: TEXT_OBJECT_KEYS,
|
|
57
|
-
image: [...BOX_KEYS, 'src', 'imageRef', 'fileName', 'naturalWidth', 'naturalHeight'],
|
|
58
|
+
image: [...BOX_KEYS, 'src', 'imageRef', 'fileName', 'libraryFileId', 'libraryFileUrl', 'naturalWidth', 'naturalHeight'],
|
|
58
59
|
widget: [...BOX_KEYS, 'widgetId', 'widgetName', 'isPrimary', 'thumbnail', 'thumbnailRef'],
|
|
59
60
|
group: []
|
|
60
61
|
};
|
|
@@ -190,6 +191,10 @@ export function readColor(value, fallback) {
|
|
|
190
191
|
return typeof value === 'string' && COLOR_PATTERN.test(value.trim()) ? value.trim() : fallback;
|
|
191
192
|
}
|
|
192
193
|
const FONT_FAMILY_PATTERN = /^[\p{L}\p{N}\s,'"\-_.]{1,200}$/u;
|
|
194
|
+
/** Whether a text is a well-formed font family name (what a saved board accepts: letters, digits, spaces and a few marks). */
|
|
195
|
+
export function isFontFamilyName(value) {
|
|
196
|
+
return typeof value === 'string' && FONT_FAMILY_PATTERN.test(value);
|
|
197
|
+
}
|
|
193
198
|
function readFontFamily(value) {
|
|
194
199
|
return typeof value === 'string' && FONT_FAMILY_PATTERN.test(value) ? value : TEXT_DEFAULTS.fontFamily;
|
|
195
200
|
}
|
|
@@ -200,6 +205,17 @@ export function readImageAddress(value) {
|
|
|
200
205
|
return null;
|
|
201
206
|
return IMAGE_ADDRESS_PATTERN.test(value) ? value : null;
|
|
202
207
|
}
|
|
208
|
+
const LIBRARY_ADDRESS_PATTERN = /^(?:https?:\/\/|\/(?!\/))/i;
|
|
209
|
+
const LIBRARY_ADDRESS_MAX_LENGTH = 2000;
|
|
210
|
+
/**
|
|
211
|
+
* Where the person's file library keeps a picture: an http(s) address or a path of the page. Never inline bytes (the library
|
|
212
|
+
* address only names the file; the board's own bytes live in `src`/`imageRef`), and never anything a link could abuse.
|
|
213
|
+
*/
|
|
214
|
+
export function readLibraryFileAddress(value) {
|
|
215
|
+
if (typeof value !== 'string' || value === '' || value.length > LIBRARY_ADDRESS_MAX_LENGTH)
|
|
216
|
+
return null;
|
|
217
|
+
return LIBRARY_ADDRESS_PATTERN.test(value) ? value : null;
|
|
218
|
+
}
|
|
203
219
|
const STROKE_STYLES = ['solid', 'dashed', 'dotted'];
|
|
204
220
|
const LINE_CAPS = ['butt', 'round', 'square'];
|
|
205
221
|
const LINE_JOINS = ['miter', 'round', 'bevel'];
|
|
@@ -377,7 +393,7 @@ function readPath(raw, id, index, warnings) {
|
|
|
377
393
|
warnings.push({ code: 'bad-path', index, detail: 'The outline of the shape is missing or cannot be read.' });
|
|
378
394
|
return null;
|
|
379
395
|
}
|
|
380
|
-
|
|
396
|
+
const path = createPathObject({
|
|
381
397
|
id,
|
|
382
398
|
parentId: readParentId(raw),
|
|
383
399
|
...box,
|
|
@@ -393,6 +409,11 @@ function readPath(raw, id, index, warnings) {
|
|
|
393
409
|
ink,
|
|
394
410
|
arrow
|
|
395
411
|
});
|
|
412
|
+
// A line (an arrow, a line-only icon) saved with no width, as the Width control once allowed, would stay invisible on the board:
|
|
413
|
+
// it comes back with the thinnest line it can have. A brush stroke is drawn from its ink and keeps the width it was drawn with.
|
|
414
|
+
// (The head of an arrow drawn above is the same for a width of 0 as for the thinnest line, so it needs no drawing again.)
|
|
415
|
+
const thinnestLine = ink ? 0 : minimumStrokeWidthOf(path);
|
|
416
|
+
return path.strokeWidth < thinnestLine ? { ...path, strokeWidth: thinnestLine } : path;
|
|
396
417
|
}
|
|
397
418
|
function readText(raw, id) {
|
|
398
419
|
return createTextObject({
|
|
@@ -421,6 +442,8 @@ function readImage(raw, id) {
|
|
|
421
442
|
src: readImageAddress(raw.src),
|
|
422
443
|
imageRef: readNullableString(raw.imageRef, 200),
|
|
423
444
|
fileName: readNullableString(raw.fileName, 300),
|
|
445
|
+
libraryFileId: readNullableString(raw.libraryFileId, 200),
|
|
446
|
+
libraryFileUrl: readLibraryFileAddress(raw.libraryFileUrl),
|
|
424
447
|
naturalWidth: readNumber(raw.naturalWidth, 0, 0, MAX_SIZE),
|
|
425
448
|
naturalHeight: readNumber(raw.naturalHeight, 0, 0, MAX_SIZE)
|
|
426
449
|
});
|
|
@@ -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,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,16 +24,18 @@ import { parsePathData, pathBounds, serializePathData, translatePathCommands } f
|
|
|
22
24
|
export const ARROW_HEAD_ANGLE = Math.PI / 6;
|
|
23
25
|
/** The head is this fraction of the length of the arrow ... */
|
|
24
26
|
export const ARROW_HEAD_LENGTH_FRACTION = 1 / 5;
|
|
25
|
-
/** ... but at least this
|
|
26
|
-
export const
|
|
27
|
-
/** ... and at most this
|
|
28
|
-
export const
|
|
27
|
+
/** ... but at least this long (world units) ... */
|
|
28
|
+
export const ARROW_HEAD_MIN_LENGTH = 3;
|
|
29
|
+
/** ... and at most this long: the head of the line the Arrow tool draws with. */
|
|
30
|
+
export 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 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 const ARROW_HEAD_GROWTH_LIMIT_FRACTION = 1 / 2;
|
|
29
35
|
/** A bend smaller than this (world units) is not a bend: the arrow is straight. */
|
|
30
36
|
export 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). */
|
|
32
38
|
export const MAX_ARROW_BEND_PER_LENGTH = 2;
|
|
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;
|
|
35
39
|
/** Whether a shape is an arrow made by the Arrow tool, with the points it is drawn from. */
|
|
36
40
|
export function isArrow(shape) {
|
|
37
41
|
return shape.type === 'path' && shape.arrow !== null;
|
|
@@ -42,10 +46,18 @@ export function drawnBend(bend, length) {
|
|
|
42
46
|
return 0;
|
|
43
47
|
return clampNumber(bend, -MAX_ARROW_BEND_PER_LENGTH * length, MAX_ARROW_BEND_PER_LENGTH * length);
|
|
44
48
|
}
|
|
45
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* 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
|
|
51
|
+
* 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
|
|
52
|
+
* thicker line grows that head in step with the line (twice the width, twice the head), up to half the arrow.
|
|
53
|
+
*/
|
|
46
54
|
export function arrowHeadLength(bodyLength, strokeWidth) {
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
// A width that is not a number is taken for the Arrow tool's own, which asks the head for no growth.
|
|
56
|
+
const lineWidth = Number.isFinite(strokeWidth) ? strokeWidth : ARROW_HEAD_REFERENCE_WIDTH;
|
|
57
|
+
const lengthFromArrow = clampNumber(bodyLength * ARROW_HEAD_LENGTH_FRACTION, ARROW_HEAD_MIN_LENGTH, ARROW_HEAD_MAX_LENGTH);
|
|
58
|
+
const lengthGrownForLine = lengthFromArrow * Math.max(1, lineWidth / ARROW_HEAD_REFERENCE_WIDTH);
|
|
59
|
+
// 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).
|
|
60
|
+
return Math.max(lengthFromArrow, Math.min(lengthGrownForLine, bodyLength * ARROW_HEAD_GROWTH_LIMIT_FRACTION));
|
|
49
61
|
}
|
|
50
62
|
/** A point turned about another by an angle (radians, clockwise on screen). */
|
|
51
63
|
function rotateAbout(point, center, radians) {
|
|
@@ -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';
|
|
@@ -17,10 +17,11 @@
|
|
|
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 { arrowPointsInWorld, isArrow, reshapeArrow } from './arrow.js';
|
|
23
23
|
import { ARROW_ENDS, bindingOfEnd, canBeTiedTo, hasBindings } from './arrowBindingRecords.js';
|
|
24
|
+
import { isBrushStroke } from './brush.js';
|
|
24
25
|
import { clampNumber, distanceBetween, pointInPolygon, worldToBoxLocal } from './geometry.js';
|
|
25
26
|
import { flattenedOutline, shapeContainsPoint } from './hitTest.js';
|
|
26
27
|
import { applyMatrixToPoint, boxToWorldMatrix } from './matrix.js';
|
|
@@ -281,13 +282,19 @@ function interiorContains(shape, point) {
|
|
|
281
282
|
return false;
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* The tie a pointer at a point makes on one shape it is over: on the outline within the band of it, at the middle further in.
|
|
287
|
+
*
|
|
288
|
+
* A line drawn by hand (a brush stroke) is always tied on its outline, wherever the pointer is on it: it has no middle to aim at (the
|
|
289
|
+
* middle of its box is mostly empty board, and the box of a straight line is only a unit thick, which leaves the band no width at
|
|
290
|
+
* all), so the end rests on the point of the stroke that is nearest to the pointer and stays at that place of the line.
|
|
291
|
+
*/
|
|
285
292
|
function tieOnShape(shape, point, zoom) {
|
|
286
293
|
const local = worldToBoxLocal(shape, point);
|
|
287
294
|
if (!local)
|
|
288
295
|
return null;
|
|
289
296
|
const nearest = nearestOnOutline(outlineOf(shape), local);
|
|
290
|
-
if (distanceBetween(local, nearest) <= edgeBandOf(shape, zoom)) {
|
|
297
|
+
if (isBrushStroke(shape) || distanceBetween(local, nearest) <= edgeBandOf(shape, zoom)) {
|
|
291
298
|
const anchor = { x: clampNumber(nearest.x / Math.max(shape.width, 1e-6), 0, 1), y: clampNumber(nearest.y / Math.max(shape.height, 1e-6), 0, 1) };
|
|
292
299
|
return { binding: { targetId: shape.id, kind: 'edge', anchor }, hint: { targetId: shape.id, kind: 'edge', point: toWorld(shape, nearest) } };
|
|
293
300
|
}
|
|
@@ -23,8 +23,14 @@ export interface ArrowBindingChange {
|
|
|
23
23
|
}
|
|
24
24
|
/** The spec with its ties changed. The same spec when the change says what it says already. */
|
|
25
25
|
export declare function withBindings(spec: ArrowSpec, change: ArrowBindingChange): ArrowSpec;
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Whether an arrow can be tied to this object: a shape that has an outline, which is not an arrow or a group. A line drawn by hand
|
|
28
|
+
* (a brush stroke) can be tied to like any other drawing: an arrow may start from it or end on it. An arrow cannot be tied to another
|
|
29
|
+
* arrow, since two arrows that follow each other would have no end to follow.
|
|
30
|
+
*/
|
|
27
31
|
export declare function canBeTiedTo(object: SceneObject): object is ShapeObject;
|
|
32
|
+
/** An arrow, as far as these records are concerned: a path with the points it is drawn from. Its spec, or null for any other object. */
|
|
33
|
+
export declare function arrowSpecOf(object: SceneObject): ArrowSpec | null;
|
|
28
34
|
/**
|
|
29
35
|
* An arrow that is carried, stretched or turned together with some shapes: the ties to shapes that are not among them are cut (an
|
|
30
36
|
* arrow that is moved by itself comes off the shapes it was tied to, the way it does in tldraw). The same object when nothing is cut.
|
|
@@ -37,7 +43,7 @@ export declare function releaseUnmovedEnds<T extends SceneObject>(object: T, mov
|
|
|
37
43
|
export declare function remapEnds<T extends SceneObject>(object: T, idMap: ReadonlyMap<ObjectId, ObjectId>): T;
|
|
38
44
|
/**
|
|
39
45
|
* A scene in which every tie points at something an arrow can be tied to: a tie whose shape is not on the board (a board that was
|
|
40
|
-
* edited by hand, a shape deleted by another tool), is not a shape with an outline, or is the arrow itself
|
|
41
|
-
* array when nothing is cut.
|
|
46
|
+
* edited by hand, a shape deleted by another tool), is not a shape with an outline (a group, another arrow), or is the arrow itself
|
|
47
|
+
* is cut. The very same array when nothing is cut.
|
|
42
48
|
*/
|
|
43
49
|
export declare function dropDanglingBindings<S extends readonly SceneObject[]>(scene: S): S;
|
|
@@ -36,7 +36,11 @@ export function withBindings(spec, change) {
|
|
|
36
36
|
return spec;
|
|
37
37
|
return { start: spec.start, end: spec.end, bend: spec.bend, ...(start ? { startBinding: start } : {}), ...(end ? { endBinding: end } : {}) };
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Whether an arrow can be tied to this object: a shape that has an outline, which is not an arrow or a group. A line drawn by hand
|
|
41
|
+
* (a brush stroke) can be tied to like any other drawing: an arrow may start from it or end on it. An arrow cannot be tied to another
|
|
42
|
+
* arrow, since two arrows that follow each other would have no end to follow.
|
|
43
|
+
*/
|
|
40
44
|
export function canBeTiedTo(object) {
|
|
41
45
|
switch (object.type) {
|
|
42
46
|
case 'rect':
|
|
@@ -46,13 +50,13 @@ export function canBeTiedTo(object) {
|
|
|
46
50
|
case 'widget':
|
|
47
51
|
return true;
|
|
48
52
|
case 'path':
|
|
49
|
-
return object.arrow === null
|
|
53
|
+
return object.arrow === null;
|
|
50
54
|
default:
|
|
51
55
|
return false;
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
|
-
/** An arrow, as far as these records are concerned: a path with the points it is drawn from. */
|
|
55
|
-
function arrowSpecOf(object) {
|
|
58
|
+
/** An arrow, as far as these records are concerned: a path with the points it is drawn from. Its spec, or null for any other object. */
|
|
59
|
+
export function arrowSpecOf(object) {
|
|
56
60
|
return object.type === 'path' && object.arrow ? object.arrow : null;
|
|
57
61
|
}
|
|
58
62
|
/** The same arrow with its spec replaced, or the very same object when the spec did not change. */
|
|
@@ -90,8 +94,8 @@ export function remapEnds(object, idMap) {
|
|
|
90
94
|
}
|
|
91
95
|
/**
|
|
92
96
|
* A scene in which every tie points at something an arrow can be tied to: a tie whose shape is not on the board (a board that was
|
|
93
|
-
* edited by hand, a shape deleted by another tool), is not a shape with an outline, or is the arrow itself
|
|
94
|
-
* array when nothing is cut.
|
|
97
|
+
* edited by hand, a shape deleted by another tool), is not a shape with an outline (a group, another arrow), or is the arrow itself
|
|
98
|
+
* is cut. The very same array when nothing is cut.
|
|
95
99
|
*/
|
|
96
100
|
export function dropDanglingBindings(scene) {
|
|
97
101
|
if (!scene.some((object) => {
|
|
@@ -41,10 +41,18 @@ export interface BrushStrokeOptions {
|
|
|
41
41
|
color?: string;
|
|
42
42
|
/** The width of the line (what the Width control of the panel shows). */
|
|
43
43
|
strokeWidth?: number;
|
|
44
|
+
/** How much of the board shows through the whole line, from 0 to 1 (what the Opacity control of the panel shows). Fully opaque by default. */
|
|
45
|
+
opacity?: number;
|
|
44
46
|
/** `pen` reads the pressure from the samples, `speed` (the default) works it out from how fast the hand moved. */
|
|
45
47
|
pressure?: BrushPressure;
|
|
46
48
|
/** The pointer was released: the line ends exactly on the last sample, instead of trailing a little behind the hand. */
|
|
47
49
|
finished?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The line is held straight and even (Shift): every point gets this pressure (0 to 1) instead of one worked out from the speed
|
|
52
|
+
* of the hand, so it is as wide at one end as at the other, and the line follows its samples exactly, with no trailing behind
|
|
53
|
+
* the hand even while it is still being drawn (the first and the last sample are the two ends it is drawn between).
|
|
54
|
+
*/
|
|
55
|
+
steadyPressure?: number;
|
|
48
56
|
}
|
|
49
57
|
/**
|
|
50
58
|
* The stroke for the samples of a pointer, in world units: the box of its line, the line itself with its pressure, and the
|
|
@@ -86,8 +86,13 @@ export function buildBrushStroke(samples, options = {}) {
|
|
|
86
86
|
const strokeWidth = options.strokeWidth ?? SHAPE_STYLE_DEFAULTS.inkStrokeWidth;
|
|
87
87
|
const pressure = options.pressure ?? 'speed';
|
|
88
88
|
const size = brushSizeFor(strokeWidth);
|
|
89
|
-
|
|
90
|
-
const
|
|
89
|
+
// A line of one pressure reads that pressure at every sample, and is not smoothed (smoothing is what makes a line trail the hand).
|
|
90
|
+
const steadyPressure = typeof options.steadyPressure === 'number' && Number.isFinite(options.steadyPressure) ? Math.min(1, Math.max(0, options.steadyPressure)) : null;
|
|
91
|
+
const brushLine = brushOptions(size, pressure, options.finished === true);
|
|
92
|
+
const lineOptions = steadyPressure === null ? brushLine : { ...brushLine, streamline: 0, simulatePressure: false };
|
|
93
|
+
const usable = samples
|
|
94
|
+
.filter((sample) => Number.isFinite(sample.x) && Number.isFinite(sample.y))
|
|
95
|
+
.map((sample) => (steadyPressure === null ? sample : { x: sample.x, y: sample.y, pressure: steadyPressure }));
|
|
91
96
|
if (usable.length === 0)
|
|
92
97
|
return null;
|
|
93
98
|
let kept;
|
|
@@ -130,6 +135,8 @@ export function buildBrushStroke(samples, options = {}) {
|
|
|
130
135
|
pressure
|
|
131
136
|
};
|
|
132
137
|
const createId = options.createId ?? createObjectId;
|
|
138
|
+
// The whole line shows through as much as it was asked to; a line that was not asked anything is fully opaque, as an object is.
|
|
139
|
+
const opacity = typeof options.opacity === 'number' && Number.isFinite(options.opacity) ? Math.min(1, Math.max(0, options.opacity)) : null;
|
|
133
140
|
return createPathObject({
|
|
134
141
|
id: createId('obj'),
|
|
135
142
|
x: boxX,
|
|
@@ -145,6 +152,7 @@ export function buildBrushStroke(samples, options = {}) {
|
|
|
145
152
|
strokeWidth,
|
|
146
153
|
lineCap: 'round',
|
|
147
154
|
lineJoin: 'round',
|
|
155
|
+
...(opacity === null ? {} : { opacity }),
|
|
148
156
|
ink
|
|
149
157
|
});
|
|
150
158
|
}
|
|
@@ -49,6 +49,12 @@ export declare const CAMERA_MOVE_MIN_DURATION_MS = 380;
|
|
|
49
49
|
export declare const CAMERA_MOVE_MAX_DURATION_MS = 1000;
|
|
50
50
|
/** The time for each unit of the length of a path, in milliseconds. */
|
|
51
51
|
export declare const CAMERA_MOVE_MS_PER_UNIT = 800;
|
|
52
|
+
/**
|
|
53
|
+
* The share of the time a move takes that a quick move takes (`durationScale` of the move options). The double click on the empty
|
|
54
|
+
* board and Ctrl/Cmd+0 use it: they answer something the person has just done and should feel brisk, while a move a page asks for
|
|
55
|
+
* keeps the time its length gives.
|
|
56
|
+
*/
|
|
57
|
+
export declare const QUICK_CAMERA_MOVE_SCALE = 0.65;
|
|
52
58
|
/** The view that a viewport shows in a board element of `viewSize`. */
|
|
53
59
|
export declare function cameraOfViewport(viewport: Viewport, viewSize: Size): CameraView;
|
|
54
60
|
/** The viewport that shows `camera` in a board element of `viewSize`. */
|
|
@@ -30,6 +30,12 @@ export const CAMERA_MOVE_MIN_DURATION_MS = 380;
|
|
|
30
30
|
export const CAMERA_MOVE_MAX_DURATION_MS = 1000;
|
|
31
31
|
/** The time for each unit of the length of a path, in milliseconds. */
|
|
32
32
|
export const CAMERA_MOVE_MS_PER_UNIT = 800;
|
|
33
|
+
/**
|
|
34
|
+
* The share of the time a move takes that a quick move takes (`durationScale` of the move options). The double click on the empty
|
|
35
|
+
* board and Ctrl/Cmd+0 use it: they answer something the person has just done and should feel brisk, while a move a page asks for
|
|
36
|
+
* keeps the time its length gives.
|
|
37
|
+
*/
|
|
38
|
+
export const QUICK_CAMERA_MOVE_SCALE = 0.65;
|
|
33
39
|
/**
|
|
34
40
|
* How much the path zooms out on its way when the move is long (ρ in the paper). The square root of 2 is the value its authors
|
|
35
41
|
* found the most pleasing: a larger one zooms out more, and 0 would be a straight line.
|
|
@@ -79,6 +79,28 @@ export declare function movingShapeIds(scene: Scene, ids: Iterable<ObjectId>): S
|
|
|
79
79
|
export declare function translateShapes(scene: Scene, moving: ReadonlySet<ObjectId>, deltaX: number, deltaY: number): Scene;
|
|
80
80
|
/** Moves the shapes drawn by the given objects by a distance. */
|
|
81
81
|
export declare function translateObjects(scene: Scene, ids: Iterable<ObjectId>, deltaX: number, deltaY: number): Scene;
|
|
82
|
+
/**
|
|
83
|
+
* What is joined to the given objects by arrows, at any distance: an arrow and the shapes its ends are tied to, the other arrows
|
|
84
|
+
* tied to those shapes, and so on to the last one. The given objects come back too (and the members of a group among them: a group
|
|
85
|
+
* stands for the shapes inside it, so an arrow tied to one of its members joins the whole group to what is at the arrow's other end).
|
|
86
|
+
*
|
|
87
|
+
* The ids of the result are the leaf shapes, the arrows and the groups that were given; `withConnectedObjects` turns them into
|
|
88
|
+
* the objects that are put in front of or behind the others.
|
|
89
|
+
*/
|
|
90
|
+
export declare function connectedObjectIds(scene: Scene, ids: Iterable<ObjectId>): Set<ObjectId>;
|
|
91
|
+
/**
|
|
92
|
+
* The object that is `id` itself or the group above it, whichever sits directly in the list of `parentId` (null is the board),
|
|
93
|
+
* or null when `id` is not under that parent at all.
|
|
94
|
+
*/
|
|
95
|
+
export declare function ancestorWithin(index: ReadonlyMap<ObjectId, SceneObject>, id: ObjectId, parentId: ObjectId | null): ObjectId | null;
|
|
96
|
+
/**
|
|
97
|
+
* The given objects and everything that arrows join to them: shapes that are tied together are one diagram, and putting any
|
|
98
|
+
* one of them in front of the others puts the whole diagram there. What is joined is taken at the level of the given objects,
|
|
99
|
+
* each as the object that sits in the same list of siblings as one of them (a shape inside a group stands for its group when
|
|
100
|
+
* the given objects are on the board, and is left alone when they are inside another group: a layer is only ever moved
|
|
101
|
+
* among its own siblings). In paint order, with no repeats. The same ids, normalised, when nothing is joined.
|
|
102
|
+
*/
|
|
103
|
+
export declare function withConnectedObjects(scene: Scene, ids: Iterable<ObjectId>): ObjectId[];
|
|
82
104
|
/**
|
|
83
105
|
* Changes the paint order of the objects, each among its own siblings (a member of a group moves inside the
|
|
84
106
|
* group, never out of it).
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* which keeps one rule true everywhere: a group comes first, directly followed by its members, and the
|
|
10
10
|
* paint order of the board is the order of the list.
|
|
11
11
|
*/
|
|
12
|
-
import { releaseUnmovedEnds, remapEnds } from './arrowBindingRecords.js';
|
|
12
|
+
import { ARROW_ENDS, arrowSpecOf, bindingOfEnd, releaseUnmovedEnds, remapEnds } from './arrowBindingRecords.js';
|
|
13
13
|
import { brushOverflow, isBrushStroke } from './brush.js';
|
|
14
14
|
import { rotatedBoxBounds, unionRects, inflateRect } from './geometry.js';
|
|
15
15
|
import { createGroupObject, createObjectId } from './defaults.js';
|
|
@@ -332,6 +332,91 @@ export function translateObjects(scene, ids, deltaX, deltaY) {
|
|
|
332
332
|
return scene;
|
|
333
333
|
return translateShapes(scene, movingShapeIds(scene, ids), deltaX, deltaY);
|
|
334
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* What is joined to the given objects by arrows, at any distance: an arrow and the shapes its ends are tied to, the other arrows
|
|
337
|
+
* tied to those shapes, and so on to the last one. The given objects come back too (and the members of a group among them: a group
|
|
338
|
+
* stands for the shapes inside it, so an arrow tied to one of its members joins the whole group to what is at the arrow's other end).
|
|
339
|
+
*
|
|
340
|
+
* The ids of the result are the leaf shapes, the arrows and the groups that were given; `withConnectedObjects` turns them into
|
|
341
|
+
* the objects that are put in front of or behind the others.
|
|
342
|
+
*/
|
|
343
|
+
export function connectedObjectIds(scene, ids) {
|
|
344
|
+
const index = indexScene(scene);
|
|
345
|
+
// Who is tied to whom, both ways: a shape knows its arrows and an arrow knows its shapes.
|
|
346
|
+
const joined = new Map();
|
|
347
|
+
const addNeighbour = (id, neighbourId) => {
|
|
348
|
+
const neighbours = joined.get(id);
|
|
349
|
+
if (neighbours)
|
|
350
|
+
neighbours.push(neighbourId);
|
|
351
|
+
else
|
|
352
|
+
joined.set(id, [neighbourId]);
|
|
353
|
+
};
|
|
354
|
+
for (const object of scene) {
|
|
355
|
+
const spec = arrowSpecOf(object);
|
|
356
|
+
if (!spec)
|
|
357
|
+
continue;
|
|
358
|
+
for (const end of ARROW_ENDS) {
|
|
359
|
+
const binding = bindingOfEnd(spec, end);
|
|
360
|
+
// A tie to something that is not on the board (a board edited by hand) joins nothing.
|
|
361
|
+
if (!binding || binding.targetId === object.id || !index.has(binding.targetId))
|
|
362
|
+
continue;
|
|
363
|
+
addNeighbour(object.id, binding.targetId);
|
|
364
|
+
addNeighbour(binding.targetId, object.id);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const connected = new Set();
|
|
368
|
+
const pending = [...withDescendantIds(scene, ids)].filter((id) => index.has(id));
|
|
369
|
+
while (pending.length > 0) {
|
|
370
|
+
const id = pending.pop();
|
|
371
|
+
if (connected.has(id))
|
|
372
|
+
continue;
|
|
373
|
+
connected.add(id);
|
|
374
|
+
for (const next of joined.get(id) ?? []) {
|
|
375
|
+
if (!connected.has(next))
|
|
376
|
+
pending.push(next);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return connected;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* The object that is `id` itself or the group above it, whichever sits directly in the list of `parentId` (null is the board),
|
|
383
|
+
* or null when `id` is not under that parent at all.
|
|
384
|
+
*/
|
|
385
|
+
export function ancestorWithin(index, id, parentId) {
|
|
386
|
+
let current = index.get(id);
|
|
387
|
+
const visited = new Set();
|
|
388
|
+
while (current && !visited.has(current.id)) {
|
|
389
|
+
if (current.parentId === parentId)
|
|
390
|
+
return current.id;
|
|
391
|
+
visited.add(current.id);
|
|
392
|
+
current = current.parentId === null ? undefined : index.get(current.parentId);
|
|
393
|
+
}
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* The given objects and everything that arrows join to them: shapes that are tied together are one diagram, and putting any
|
|
398
|
+
* one of them in front of the others puts the whole diagram there. What is joined is taken at the level of the given objects,
|
|
399
|
+
* each as the object that sits in the same list of siblings as one of them (a shape inside a group stands for its group when
|
|
400
|
+
* the given objects are on the board, and is left alone when they are inside another group: a layer is only ever moved
|
|
401
|
+
* among its own siblings). In paint order, with no repeats. The same ids, normalised, when nothing is joined.
|
|
402
|
+
*/
|
|
403
|
+
export function withConnectedObjects(scene, ids) {
|
|
404
|
+
const selected = normalizeSelection(scene, ids);
|
|
405
|
+
if (selected.length === 0)
|
|
406
|
+
return selected;
|
|
407
|
+
const connected = connectedObjectIds(scene, selected);
|
|
408
|
+
const index = indexScene(scene);
|
|
409
|
+
const parents = new Set(selected.map((id) => index.get(id)?.parentId ?? null));
|
|
410
|
+
const wanted = new Set(selected);
|
|
411
|
+
for (const id of connected) {
|
|
412
|
+
for (const parentId of parents) {
|
|
413
|
+
const sibling = ancestorWithin(index, id, parentId);
|
|
414
|
+
if (sibling)
|
|
415
|
+
wanted.add(sibling);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return normalizeSelection(scene, wanted);
|
|
419
|
+
}
|
|
335
420
|
/**
|
|
336
421
|
* Changes the paint order of the objects, each among its own siblings (a member of a group moves inside the
|
|
337
422
|
* group, never out of it).
|
|
@@ -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
|
/**
|
|
@@ -53,8 +53,20 @@ export function pathSupportsRoundness(shapeKey) {
|
|
|
53
53
|
function roundnessIsLineEnds(shapeKey) {
|
|
54
54
|
return getShapeByKey(shapeKey)?.cornerRadiusMode === 'strokeRound';
|
|
55
55
|
}
|
|
56
|
-
/** The widest a line may be made with the Width control. */
|
|
57
|
-
const MAX_STROKE_WIDTH = 200;
|
|
56
|
+
/** The widest a line may be made with the Width control (the pen's too: see `EngineCore.setPenStyle`). */
|
|
57
|
+
export const MAX_STROKE_WIDTH = 200;
|
|
58
|
+
/** 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. */
|
|
59
|
+
export const MIN_LINE_STROKE_WIDTH = 1;
|
|
60
|
+
/**
|
|
61
|
+
* 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
|
|
62
|
+
* 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
|
|
63
|
+
* the thinnest line it can be drawn with.
|
|
64
|
+
*/
|
|
65
|
+
export function minimumStrokeWidthOf(shape) {
|
|
66
|
+
if (isBrushStroke(shape))
|
|
67
|
+
return MIN_BRUSH_WIDTH;
|
|
68
|
+
return isArrow(shape) || paintsFillOnStroke(shape) ? MIN_LINE_STROKE_WIDTH : 0;
|
|
69
|
+
}
|
|
58
70
|
const RANGES = {
|
|
59
71
|
opacity: [0, 1],
|
|
60
72
|
fillOpacity: [0, 1],
|
|
@@ -122,13 +134,17 @@ export function applyStylePatch(shape, requested) {
|
|
|
122
134
|
const range = RANGES[key];
|
|
123
135
|
if (range && typeof value === 'number')
|
|
124
136
|
value = clampNumber(value, range[0], range[1]);
|
|
137
|
+
// 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).
|
|
138
|
+
if (key === 'strokeWidth' && typeof value === 'number')
|
|
139
|
+
value = Math.max(value, minimumStrokeWidthOf(shape));
|
|
125
140
|
if (shape[key] !== value)
|
|
126
141
|
changes[key] = value;
|
|
127
142
|
}
|
|
128
143
|
if (Object.keys(changes).length === 0)
|
|
129
144
|
return shape;
|
|
130
145
|
let next = { ...shape, ...changes };
|
|
131
|
-
// The head of an arrow is sized by the width of its line
|
|
146
|
+
// 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
|
|
147
|
+
// Arrow tool's width), so a new width draws the arrow again.
|
|
132
148
|
if (isArrow(next) && 'strokeWidth' in changes)
|
|
133
149
|
next = reshapeArrow(next);
|
|
134
150
|
if (next.type === 'path' && 'roundness' in changes) {
|
|
@@ -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).
|
|
@@ -43,6 +43,15 @@ export function selectionFrameOf(shapes) {
|
|
|
43
43
|
export function frameCenter(frame) {
|
|
44
44
|
return { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 };
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* 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
|
|
48
|
+
* the points inside its turned box and not those of the upright rectangle around it. A box with no width or no height holds
|
|
49
|
+
* only the points on its line.
|
|
50
|
+
*/
|
|
51
|
+
export function frameContains(frame, point) {
|
|
52
|
+
const local = worldToBoxLocal(frame, point);
|
|
53
|
+
return !!local && local.x >= 0 && local.y >= 0 && local.x <= frame.width && local.y <= frame.height;
|
|
54
|
+
}
|
|
46
55
|
/**
|
|
47
56
|
* The frame that results from dragging `handle` to a world point.
|
|
48
57
|
* `frame` is the frame when the drag began (not the one the last pointer move produced).
|