@crux-diagram/react 0.0.0-stage → 0.1.0
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/cjs/DrawingEditor.d.ts +34 -0
- package/dist/cjs/DrawingEditor.js +289 -0
- package/dist/cjs/DrawingViewer.d.ts +14 -0
- package/dist/cjs/DrawingViewer.js +14 -0
- package/dist/cjs/JointDisplayBar.d.ts +8 -0
- package/dist/cjs/JointDisplayBar.js +22 -0
- package/dist/cjs/NameEditor.d.ts +15 -0
- package/dist/cjs/NameEditor.js +36 -0
- package/dist/cjs/Toolbar.d.ts +8 -0
- package/dist/cjs/Toolbar.js +34 -0
- package/dist/cjs/VersionHistory.d.ts +33 -0
- package/dist/cjs/VersionHistory.js +49 -0
- package/dist/cjs/a11y.d.ts +12 -0
- package/dist/cjs/a11y.js +53 -0
- package/dist/cjs/config.d.ts +50 -0
- package/dist/cjs/config.js +39 -0
- package/dist/cjs/controls.d.ts +12 -0
- package/dist/cjs/controls.js +15 -0
- package/dist/cjs/editor-context.d.ts +45 -0
- package/dist/cjs/editor-context.js +101 -0
- package/dist/cjs/export/export-image.d.ts +29 -0
- package/dist/cjs/export/export-image.js +94 -0
- package/dist/cjs/hooks.d.ts +6 -0
- package/dist/cjs/hooks.js +10 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/interaction/gestures.d.ts +133 -0
- package/dist/cjs/interaction/gestures.js +353 -0
- package/dist/cjs/interaction/joints.d.ts +41 -0
- package/dist/cjs/interaction/joints.js +104 -0
- package/dist/cjs/interaction/keyboard.d.ts +51 -0
- package/dist/cjs/interaction/keyboard.js +116 -0
- package/dist/cjs/interaction/palette.d.ts +19 -0
- package/dist/cjs/interaction/palette.js +64 -0
- package/dist/cjs/interaction/viewport.d.ts +14 -0
- package/dist/cjs/interaction/viewport.js +23 -0
- package/dist/cjs/labels.d.ts +39 -0
- package/dist/cjs/labels.js +49 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/render/DrawingStage.d.ts +27 -0
- package/dist/cjs/render/DrawingStage.js +77 -0
- package/dist/cjs/render/fonts.d.ts +7 -0
- package/dist/cjs/render/fonts.js +50 -0
- package/dist/cjs/render/scene.d.ts +75 -0
- package/dist/cjs/render/scene.js +92 -0
- package/dist/cjs/store.d.ts +90 -0
- package/dist/cjs/store.js +159 -0
- package/dist/esm/DrawingEditor.d.ts +34 -0
- package/dist/esm/DrawingEditor.js +285 -0
- package/dist/esm/DrawingViewer.d.ts +14 -0
- package/dist/esm/DrawingViewer.js +11 -0
- package/dist/esm/JointDisplayBar.d.ts +8 -0
- package/dist/esm/JointDisplayBar.js +19 -0
- package/dist/esm/NameEditor.d.ts +15 -0
- package/dist/esm/NameEditor.js +32 -0
- package/dist/esm/Toolbar.d.ts +8 -0
- package/dist/esm/Toolbar.js +31 -0
- package/dist/esm/VersionHistory.d.ts +33 -0
- package/dist/esm/VersionHistory.js +45 -0
- package/dist/esm/a11y.d.ts +12 -0
- package/dist/esm/a11y.js +47 -0
- package/dist/esm/config.d.ts +50 -0
- package/dist/esm/config.js +35 -0
- package/dist/esm/controls.d.ts +12 -0
- package/dist/esm/controls.js +11 -0
- package/dist/esm/editor-context.d.ts +45 -0
- package/dist/esm/editor-context.js +95 -0
- package/dist/esm/export/export-image.d.ts +29 -0
- package/dist/esm/export/export-image.js +86 -0
- package/dist/esm/hooks.d.ts +6 -0
- package/dist/esm/hooks.js +7 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/interaction/gestures.d.ts +133 -0
- package/dist/esm/interaction/gestures.js +338 -0
- package/dist/esm/interaction/joints.d.ts +41 -0
- package/dist/esm/interaction/joints.js +95 -0
- package/dist/esm/interaction/keyboard.d.ts +51 -0
- package/dist/esm/interaction/keyboard.js +109 -0
- package/dist/esm/interaction/palette.d.ts +19 -0
- package/dist/esm/interaction/palette.js +59 -0
- package/dist/esm/interaction/viewport.d.ts +14 -0
- package/dist/esm/interaction/viewport.js +19 -0
- package/dist/esm/labels.d.ts +39 -0
- package/dist/esm/labels.js +45 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/render/DrawingStage.d.ts +27 -0
- package/dist/esm/render/DrawingStage.js +74 -0
- package/dist/esm/render/fonts.d.ts +7 -0
- package/dist/esm/render/fonts.js +45 -0
- package/dist/esm/render/scene.d.ts +75 -0
- package/dist/esm/render/scene.js +86 -0
- package/dist/esm/store.d.ts +90 -0
- package/dist/esm/store.js +156 -0
- package/package.json +80 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Image export (REA-040 to REA-043). The image is drawn on a Konva stage of its own, with
|
|
2
|
+
// the background, shapes and joints layers only, so nothing of the editing UI can leak in.
|
|
3
|
+
import { argbToCss, CanvasTextMeasurer, DEFAULT_JOINT_STYLE } from '@crux-diagram/core';
|
|
4
|
+
import Konva from 'konva';
|
|
5
|
+
import { whenFontsReady } from '../render/fonts.js';
|
|
6
|
+
import { jointGraphics, LABEL_FONT_FAMILY, placeJoints, shapeNodeProps } from '../render/scene.js';
|
|
7
|
+
/** Most pixels an exported image may have unless `config.exportMaxPixels` says otherwise (REA-043). */
|
|
8
|
+
export const DEFAULT_EXPORT_MAX_PIXELS = 16_000_000;
|
|
9
|
+
const MIME = { png: 'image/png', jpeg: 'image/jpeg' };
|
|
10
|
+
const EXTENSION = { png: '.png', jpeg: '.jpg' };
|
|
11
|
+
/** Throws `RangeError` for any option the export cannot honor, before anything is rendered (REA-043). */
|
|
12
|
+
function validate(document, options, maxPixels) {
|
|
13
|
+
const { format, pixelRatio = 1, quality = 0.92, transparentBackground = false } = options;
|
|
14
|
+
if (format !== 'png' && format !== 'jpeg')
|
|
15
|
+
throw new RangeError('format must be "png" or "jpeg"');
|
|
16
|
+
if (!Number.isFinite(pixelRatio) || pixelRatio <= 0)
|
|
17
|
+
throw new RangeError('pixelRatio must be a positive number');
|
|
18
|
+
if (format === 'jpeg' && !(quality >= 0 && quality <= 1))
|
|
19
|
+
throw new RangeError('quality must be between 0 and 1');
|
|
20
|
+
if (transparentBackground && format !== 'png')
|
|
21
|
+
throw new RangeError('transparentBackground needs the png format');
|
|
22
|
+
const pixels = document.canvas.width * document.canvas.height * pixelRatio * pixelRatio;
|
|
23
|
+
if (pixels > maxPixels)
|
|
24
|
+
throw new RangeError(`the image would have ${Math.round(pixels)} pixels, above the limit of ${maxPixels}`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The stage of the image: layers `background` (white unless transparent), `shapes` and
|
|
28
|
+
* `joints`, in canvas units. Hidden joints are not drawn (REA-042).
|
|
29
|
+
*/
|
|
30
|
+
export function createExportStage(document, { transparentBackground }) {
|
|
31
|
+
const { width, height } = document.canvas;
|
|
32
|
+
const stage = new Konva.Stage({ container: globalThis.document.createElement('div'), width, height });
|
|
33
|
+
const background = new Konva.Layer({ name: 'background' });
|
|
34
|
+
if (!transparentBackground)
|
|
35
|
+
background.add(new Konva.Rect({ name: 'background-fill', width, height, fill: '#ffffff' }));
|
|
36
|
+
const shapes = new Konva.Layer({ name: 'shapes' });
|
|
37
|
+
for (const shape of document.shapes) {
|
|
38
|
+
const { kind, ...props } = shapeNodeProps(shape);
|
|
39
|
+
shapes.add(kind === 'ellipse' ? new Konva.Ellipse({ id: shape.id, ...props }) : new Konva.Rect({ id: shape.id, ...props }));
|
|
40
|
+
}
|
|
41
|
+
const joints = new Konva.Layer({ name: 'joints' });
|
|
42
|
+
const style = DEFAULT_JOINT_STYLE;
|
|
43
|
+
const color = argbToCss(style.color);
|
|
44
|
+
const measurer = new CanvasTextMeasurer({ fontFamily: LABEL_FONT_FAMILY });
|
|
45
|
+
for (const placement of placeJoints(document, style, measurer)) {
|
|
46
|
+
const { line, head, text } = jointGraphics(placement, style, document.jointDisplay.labelSize);
|
|
47
|
+
if (line)
|
|
48
|
+
joints.add(new Konva.Line({ name: 'joint-line', points: line, stroke: color, strokeWidth: style.lineWidth, lineCap: 'butt' }));
|
|
49
|
+
if (head)
|
|
50
|
+
joints.add(new Konva.Line({ name: 'joint-head', points: head, closed: true, fill: color }));
|
|
51
|
+
joints.add(new Konva.Text({ id: placement.joint.id, name: 'joint-label', ...text, align: 'center', verticalAlign: 'middle', wrap: 'none' }));
|
|
52
|
+
}
|
|
53
|
+
stage.add(background, shapes, joints);
|
|
54
|
+
return stage;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Renders `document` to an image `Blob` (REA-040). Waits for the fonts first (REA-032).
|
|
58
|
+
* `maxPixels` is `config.exportMaxPixels`.
|
|
59
|
+
*/
|
|
60
|
+
export async function exportImage(document, options, { maxPixels = DEFAULT_EXPORT_MAX_PIXELS } = {}) {
|
|
61
|
+
validate(document, options, maxPixels);
|
|
62
|
+
const { format, pixelRatio = 1, quality = 0.92, transparentBackground = false, download } = options;
|
|
63
|
+
await whenFontsReady();
|
|
64
|
+
const stage = createExportStage(document, { transparentBackground });
|
|
65
|
+
let blob;
|
|
66
|
+
try {
|
|
67
|
+
blob = await stage.toBlob({ pixelRatio, mimeType: MIME[format], ...(format === 'jpeg' ? { quality } : {}) });
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
stage.destroy();
|
|
71
|
+
}
|
|
72
|
+
if (!blob)
|
|
73
|
+
throw new Error('the browser could not encode the image');
|
|
74
|
+
if (download !== undefined)
|
|
75
|
+
save(blob, /\.[a-z0-9]+$/i.test(download) ? download : download + EXTENSION[format]);
|
|
76
|
+
return blob;
|
|
77
|
+
}
|
|
78
|
+
/** Saves `blob` as a file through a temporary link. */
|
|
79
|
+
function save(blob, name) {
|
|
80
|
+
const url = URL.createObjectURL(blob);
|
|
81
|
+
const link = globalThis.document.createElement('a');
|
|
82
|
+
link.href = url;
|
|
83
|
+
link.download = name;
|
|
84
|
+
link.click();
|
|
85
|
+
URL.revokeObjectURL(url);
|
|
86
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EditorStore } from './store.js';
|
|
2
|
+
/** Whether there is something to undo or redo, kept up to date as the history changes. */
|
|
3
|
+
export declare function useHistoryAvailability(editor: EditorStore): {
|
|
4
|
+
readonly canUndo: boolean;
|
|
5
|
+
readonly canRedo: boolean;
|
|
6
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
/** Whether there is something to undo or redo, kept up to date as the history changes. */
|
|
3
|
+
export function useHistoryAvailability(editor) {
|
|
4
|
+
const canUndo = useSyncExternalStore(editor.subscribeHistory, editor.canUndo, editor.canUndo);
|
|
5
|
+
const canRedo = useSyncExternalStore(editor.subscribeHistory, editor.canRedo, editor.canRedo);
|
|
6
|
+
return { canUndo, canRedo };
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DrawingEditor, type DrawingEditorProps } from './DrawingEditor.js';
|
|
2
|
+
export { DrawingViewer, type DrawingViewerProps } from './DrawingViewer.js';
|
|
3
|
+
export { Toolbar } from './Toolbar.js';
|
|
4
|
+
export { JointDisplayBar } from './JointDisplayBar.js';
|
|
5
|
+
export { DEFAULT_EDITOR_LABELS, type EditorLabels, type EditorLabelsInput } from './labels.js';
|
|
6
|
+
export type { DrawingEditorHandle } from './editor-context.js';
|
|
7
|
+
export type { ExportImageOptions } from './export/export-image.js';
|
|
8
|
+
export { DEFAULT_EDITOR_CONFIG, resolveEditorConfig, type DrawingEditorConfig, type DrawingEditorConfigInput, type ShapeStyle, } from './config.js';
|
|
9
|
+
export { VersionHistory, DEFAULT_VERSION_HISTORY_LABELS, type VersionEntry, type VersionHistoryLabels, type VersionHistoryProps, } from './VersionHistory.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Public API of @crux-diagram/react (spec 05). Nothing here may touch `window` at
|
|
2
|
+
// import time (REA-054).
|
|
3
|
+
export { DrawingEditor } from './DrawingEditor.js';
|
|
4
|
+
export { DrawingViewer } from './DrawingViewer.js';
|
|
5
|
+
export { Toolbar } from './Toolbar.js';
|
|
6
|
+
export { JointDisplayBar } from './JointDisplayBar.js';
|
|
7
|
+
export { DEFAULT_EDITOR_LABELS } from './labels.js';
|
|
8
|
+
export { DEFAULT_EDITOR_CONFIG, resolveEditorConfig, } from './config.js';
|
|
9
|
+
export { VersionHistory, DEFAULT_VERSION_HISTORY_LABELS, } from './VersionHistory.js';
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type DrawingDocument, type Point, type Rect, type ResizeHandle, type Shape, type Vector } from '@crux-diagram/core';
|
|
2
|
+
import type { EditorStore } from '../store.js';
|
|
3
|
+
/**
|
|
4
|
+
* Screen pixels a pointer may travel before release and still count as a tap (PN-4).
|
|
5
|
+
* Assumption: Flutter uses the platform touch slop and spec 05 gives no number.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TAP_SLOP = 4;
|
|
8
|
+
/** Grid settings read when a drag starts and kept until it ends (GA-8). */
|
|
9
|
+
export interface DragGrid {
|
|
10
|
+
/** `config.gridSize`: snapping step while the grid is hidden (GA-2); `null` disables snapping. */
|
|
11
|
+
readonly gridSize: number | null;
|
|
12
|
+
/** Finest drawn grid step while the grid is shown, else `null` (GA-1). */
|
|
13
|
+
readonly visibleStep: number | null;
|
|
14
|
+
/**
|
|
15
|
+
* How close, in canvas units, an anchor must come to another shape's anchor to snap onto it
|
|
16
|
+
* (`config.anchorSnapThreshold` over the view scale); `null` or absent disables it (REA-026).
|
|
17
|
+
*/
|
|
18
|
+
readonly anchorSnapDistance?: number | null;
|
|
19
|
+
}
|
|
20
|
+
/** Touch radius of a handle, in screen pixels (spec 01 section 6). */
|
|
21
|
+
export declare const HANDLE_TOUCH_RADIUS = 24;
|
|
22
|
+
/** Visual radius of a handle, in screen pixels. */
|
|
23
|
+
export declare const HANDLE_VISUAL_RADIUS = 6;
|
|
24
|
+
/** Distance from the top edge to the rotation handle, in screen pixels. */
|
|
25
|
+
export declare const ROTATION_STEM_LENGTH = 32;
|
|
26
|
+
/** What `beginDrag` needs to offer the selected shape's handles. */
|
|
27
|
+
export interface HandleContext {
|
|
28
|
+
/** Screen pixels per canvas unit. */
|
|
29
|
+
readonly scale: number;
|
|
30
|
+
/** `config.rotationSnapStep` and `config.rotationSnapTolerance`, in radians (step 0 disables snapping). */
|
|
31
|
+
readonly rotationSnap: {
|
|
32
|
+
readonly step: number;
|
|
33
|
+
readonly tolerance: number;
|
|
34
|
+
};
|
|
35
|
+
/** The joint labels as drawn, back to front; they are hit before shapes (REA-022). */
|
|
36
|
+
readonly labels?: readonly LabelRect[];
|
|
37
|
+
}
|
|
38
|
+
/** The box of a joint's label on the canvas. */
|
|
39
|
+
export interface LabelRect {
|
|
40
|
+
readonly jointId: string;
|
|
41
|
+
readonly rect: Rect;
|
|
42
|
+
}
|
|
43
|
+
/** The id of the topmost joint whose label contains `point`, or `null`. */
|
|
44
|
+
export declare function labelAt(labels: readonly LabelRect[], point: Point): string | null;
|
|
45
|
+
/** Starts dragging the label under `point`, or returns `null` when there is none (AW-4). */
|
|
46
|
+
export declare function beginLabelDrag(editor: EditorStore, point: Point, labels: readonly LabelRect[]): Gesture | null;
|
|
47
|
+
/** A handle under a point: one of the resize handles or the rotation handle. */
|
|
48
|
+
export type HandleHit = {
|
|
49
|
+
readonly kind: 'resize';
|
|
50
|
+
readonly handle: ResizeHandle;
|
|
51
|
+
} | {
|
|
52
|
+
readonly kind: 'rotate';
|
|
53
|
+
};
|
|
54
|
+
export type Gesture = {
|
|
55
|
+
readonly kind: 'none';
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: 'move';
|
|
58
|
+
/** The committed document when the drag started; deltas are measured from it. */
|
|
59
|
+
readonly start: DrawingDocument;
|
|
60
|
+
readonly ids: readonly string[];
|
|
61
|
+
readonly origin: Point;
|
|
62
|
+
readonly grid: DragGrid;
|
|
63
|
+
/** The last previewed document, or `null` before the first update. */
|
|
64
|
+
readonly last: DrawingDocument | null;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: 'marquee';
|
|
67
|
+
readonly origin: Point;
|
|
68
|
+
readonly rect: Rect;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: 'label';
|
|
71
|
+
readonly start: DrawingDocument;
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly origin: Point;
|
|
74
|
+
readonly startOffset: Vector;
|
|
75
|
+
readonly last: DrawingDocument | null;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'resize';
|
|
78
|
+
readonly start: DrawingDocument;
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly handle: ResizeHandle;
|
|
81
|
+
readonly grid: DragGrid;
|
|
82
|
+
readonly last: DrawingDocument | null;
|
|
83
|
+
} | {
|
|
84
|
+
readonly kind: 'rotate';
|
|
85
|
+
readonly start: DrawingDocument;
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly snap: HandleContext['rotationSnap'];
|
|
88
|
+
readonly last: DrawingDocument | null;
|
|
89
|
+
};
|
|
90
|
+
/** Canvas position of `shape`'s rotation handle: above its top edge, turning with it (FR-7). */
|
|
91
|
+
export declare function rotationHandlePosition(shape: Shape, scale: number): Point;
|
|
92
|
+
/**
|
|
93
|
+
* The handle of `shape` under `point`: the rotation handle first, else the nearest resize
|
|
94
|
+
* handle within the touch radius. Squares and circles have corner handles only (FR-12).
|
|
95
|
+
*/
|
|
96
|
+
export declare function handleAt(shape: Shape, point: Point, scale: number): HandleHit | null;
|
|
97
|
+
/**
|
|
98
|
+
* A tap at `point`: outside selection mode it selects the topmost shape (and its group)
|
|
99
|
+
* or clears the selection on empty canvas; in selection mode it toggles the shape and
|
|
100
|
+
* empty canvas keeps the selection (FR-6, MS-1, MS-6, PN-4).
|
|
101
|
+
*/
|
|
102
|
+
export declare function tap(editor: EditorStore, point: Point, handles?: HandleContext): void;
|
|
103
|
+
/**
|
|
104
|
+
* Starts a drag at `point`. On a handle of the single selected shape (when `handles` is
|
|
105
|
+
* given) it resizes or rotates it (FR-11, FR-15). On a shape it moves the selection; an unselected shape is
|
|
106
|
+
* selected first (FR-8), or joins the selection in selection mode (MS-4). On empty
|
|
107
|
+
* canvas it draws a selection rectangle in selection mode (MS-3) and does nothing
|
|
108
|
+
* otherwise (PN-5; panning is a zoom feature).
|
|
109
|
+
*/
|
|
110
|
+
export declare function beginDrag(editor: EditorStore, point: Point, grid: DragGrid, handles?: HandleContext): Gesture;
|
|
111
|
+
/** Follows the pointer to `point`: previews the moved document, or grows the rectangle. */
|
|
112
|
+
export declare function updateDrag(editor: EditorStore, gesture: Gesture, point: Point): Gesture;
|
|
113
|
+
/**
|
|
114
|
+
* Ends the drag: a move commits one history entry when a shape moved and clears the
|
|
115
|
+
* preview otherwise (FR-22); a selection rectangle adds every shape whose bounds lie
|
|
116
|
+
* fully inside it (MS-3).
|
|
117
|
+
*/
|
|
118
|
+
export declare function endDrag(editor: EditorStore, gesture: Gesture): void;
|
|
119
|
+
/** Drops the preview of an unfinished move, as on `pointercancel` (Flutter `cancelGesture`). */
|
|
120
|
+
export declare function cancelDrag(editor: EditorStore, gesture: Gesture): void;
|
|
121
|
+
export declare function movedDocument(start: DrawingDocument, ids: readonly string[], delta: Vector, grid: DragGrid): DrawingDocument;
|
|
122
|
+
/**
|
|
123
|
+
* Like {@link movedDocument}, plus the anchor that was snapped onto, if any, for the
|
|
124
|
+
* highlight (SN-3). Anchor snapping comes first and replaces grid snapping when it applies
|
|
125
|
+
* (SN-1, SN-3, GA-7); only the nearest pair counts, and for several shapes any selected
|
|
126
|
+
* anchor may snap (MS-4).
|
|
127
|
+
*/
|
|
128
|
+
export declare function movedWithSnap(start: DrawingDocument, ids: readonly string[], delta: Vector, grid: DragGrid): {
|
|
129
|
+
readonly document: DrawingDocument;
|
|
130
|
+
readonly highlight: readonly Point[];
|
|
131
|
+
};
|
|
132
|
+
/** The axis-aligned rectangle with corners `a` and `b`. */
|
|
133
|
+
export declare function rectBetween(a: Point, b: Point): Rect;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// Pointer gestures on shapes, free of Konva so they can be tested alone. Ported from
|
|
2
|
+
// Flutter's `DrawingEditor._onTap`, `_onScaleStart`/`_onScaleUpdate`/`_onScaleEnd` and
|
|
3
|
+
// the controller's `moveSelectedBy`. Points are in canvas units.
|
|
4
|
+
import { anchorIdForHandle, anchorPositionOf, anchorsOf, boundsOfShapes, handleLocalPosition, handlesFor, isQuarterTurn, moveJointLabel, moveShape, nearestAnchorSnap, rectContains, resizeByHandle, rotationFromPointer, shapeBounds, snapBoxShiftToGrid, snapMoveToGrid, sizeLimitsForCanvas, snapPointToGrid, softSnap, topmostShapeAt, worldFromLocal, } from '@crux-diagram/core';
|
|
5
|
+
/**
|
|
6
|
+
* Screen pixels a pointer may travel before release and still count as a tap (PN-4).
|
|
7
|
+
* Assumption: Flutter uses the platform touch slop and spec 05 gives no number.
|
|
8
|
+
*/
|
|
9
|
+
export const TAP_SLOP = 4;
|
|
10
|
+
/** Touch radius of a handle, in screen pixels (spec 01 section 6). */
|
|
11
|
+
export const HANDLE_TOUCH_RADIUS = 24;
|
|
12
|
+
/** Visual radius of a handle, in screen pixels. */
|
|
13
|
+
export const HANDLE_VISUAL_RADIUS = 6;
|
|
14
|
+
/** Distance from the top edge to the rotation handle, in screen pixels. */
|
|
15
|
+
export const ROTATION_STEM_LENGTH = 32;
|
|
16
|
+
/** The id of the topmost joint whose label contains `point`, or `null`. */
|
|
17
|
+
export function labelAt(labels, point) {
|
|
18
|
+
for (let i = labels.length - 1; i >= 0; i--) {
|
|
19
|
+
if (rectContains(labels[i].rect, point))
|
|
20
|
+
return labels[i].jointId;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/** Starts dragging the label under `point`, or returns `null` when there is none (AW-4). */
|
|
25
|
+
export function beginLabelDrag(editor, point, labels) {
|
|
26
|
+
const id = labelAt(labels, point);
|
|
27
|
+
const start = editor.getDocument();
|
|
28
|
+
const joint = id && start.joints.find((j) => j.id === id);
|
|
29
|
+
if (!joint)
|
|
30
|
+
return null;
|
|
31
|
+
return { kind: 'label', start, id: joint.id, origin: point, startOffset: joint.labelOffset, last: null };
|
|
32
|
+
}
|
|
33
|
+
/** Canvas position of `shape`'s rotation handle: above its top edge, turning with it (FR-7). */
|
|
34
|
+
export function rotationHandlePosition(shape, scale) {
|
|
35
|
+
return worldFromLocal(shape.center, shape.rotation, {
|
|
36
|
+
x: 0,
|
|
37
|
+
y: -shape.size.height / 2 - ROTATION_STEM_LENGTH / scale,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The handle of `shape` under `point`: the rotation handle first, else the nearest resize
|
|
42
|
+
* handle within the touch radius. Squares and circles have corner handles only (FR-12).
|
|
43
|
+
*/
|
|
44
|
+
export function handleAt(shape, point, scale) {
|
|
45
|
+
const radius = HANDLE_TOUCH_RADIUS / scale;
|
|
46
|
+
const distance = (target) => Math.hypot(target.x - point.x, target.y - point.y);
|
|
47
|
+
if (distance(rotationHandlePosition(shape, scale)) <= radius)
|
|
48
|
+
return { kind: 'rotate' };
|
|
49
|
+
let nearest = null;
|
|
50
|
+
let nearestDistance = Infinity;
|
|
51
|
+
for (const handle of handlesFor(shape.type)) {
|
|
52
|
+
const d = distance(worldFromLocal(shape.center, shape.rotation, handleLocalPosition(handle, shape.size)));
|
|
53
|
+
if (d <= radius && d < nearestDistance) {
|
|
54
|
+
nearest = { kind: 'resize', handle };
|
|
55
|
+
nearestDistance = d;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return nearest;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A tap at `point`: outside selection mode it selects the topmost shape (and its group)
|
|
62
|
+
* or clears the selection on empty canvas; in selection mode it toggles the shape and
|
|
63
|
+
* empty canvas keeps the selection (FR-6, MS-1, MS-6, PN-4).
|
|
64
|
+
*/
|
|
65
|
+
export function tap(editor, point, handles) {
|
|
66
|
+
const { document, selection, selectionMode } = editor.getState();
|
|
67
|
+
// A tap on a handle of the single selected shape is not a tap on the canvas (Flutter `_onTap`).
|
|
68
|
+
if (handles && selection.length === 1) {
|
|
69
|
+
const selected = document.shapes.find((s) => s.id === selection[0]);
|
|
70
|
+
if (selected && handleAt(selected, point, handles.scale))
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// A label is above the shapes: tapping it selects its joint (AW-7).
|
|
74
|
+
const labeled = handles?.labels && labelAt(handles.labels, point);
|
|
75
|
+
if (labeled)
|
|
76
|
+
return editor.selectJoint(labeled);
|
|
77
|
+
const shape = topmostShapeAt(document.shapes, point);
|
|
78
|
+
if (selectionMode) {
|
|
79
|
+
if (shape)
|
|
80
|
+
editor.toggleSelected(shape.id);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
editor.select(shape?.id ?? null);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Starts a drag at `point`. On a handle of the single selected shape (when `handles` is
|
|
87
|
+
* given) it resizes or rotates it (FR-11, FR-15). On a shape it moves the selection; an unselected shape is
|
|
88
|
+
* selected first (FR-8), or joins the selection in selection mode (MS-4). On empty
|
|
89
|
+
* canvas it draws a selection rectangle in selection mode (MS-3) and does nothing
|
|
90
|
+
* otherwise (PN-5; panning is a zoom feature).
|
|
91
|
+
*/
|
|
92
|
+
export function beginDrag(editor, point, grid, handles) {
|
|
93
|
+
const { document, selection, selectionMode } = editor.getState();
|
|
94
|
+
// Handles come before shapes, and only a single selected shape has them (FR-7, MS-5).
|
|
95
|
+
const selected = handles && selection.length === 1 ? document.shapes.find((s) => s.id === selection[0]) : undefined;
|
|
96
|
+
const hit = selected && handles ? handleAt(selected, point, handles.scale) : null;
|
|
97
|
+
if (selected && handles && hit) {
|
|
98
|
+
return hit.kind === 'rotate'
|
|
99
|
+
? {
|
|
100
|
+
kind: 'rotate',
|
|
101
|
+
start: document,
|
|
102
|
+
id: selected.id,
|
|
103
|
+
snap: handles.rotationSnap,
|
|
104
|
+
last: null,
|
|
105
|
+
}
|
|
106
|
+
: {
|
|
107
|
+
kind: 'resize',
|
|
108
|
+
start: document,
|
|
109
|
+
id: selected.id,
|
|
110
|
+
handle: hit.handle,
|
|
111
|
+
grid: { ...grid },
|
|
112
|
+
last: null,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const label = handles?.labels && beginLabelDrag(editor, point, handles.labels);
|
|
116
|
+
if (label)
|
|
117
|
+
return label;
|
|
118
|
+
const shape = topmostShapeAt(document.shapes, point);
|
|
119
|
+
if (!shape) {
|
|
120
|
+
return selectionMode ? { kind: 'marquee', origin: point, rect: rectBetween(point, point) } : { kind: 'none' };
|
|
121
|
+
}
|
|
122
|
+
if (!selection.includes(shape.id)) {
|
|
123
|
+
if (selectionMode)
|
|
124
|
+
editor.toggleSelected(shape.id);
|
|
125
|
+
else
|
|
126
|
+
editor.select(shape.id);
|
|
127
|
+
}
|
|
128
|
+
const ids = editor.getState().selection;
|
|
129
|
+
return {
|
|
130
|
+
kind: 'move',
|
|
131
|
+
start: document,
|
|
132
|
+
ids,
|
|
133
|
+
origin: point,
|
|
134
|
+
grid: { ...grid },
|
|
135
|
+
last: null,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Follows the pointer to `point`: previews the moved document, or grows the rectangle. */
|
|
139
|
+
export function updateDrag(editor, gesture, point) {
|
|
140
|
+
if (gesture.kind === 'marquee')
|
|
141
|
+
return { ...gesture, rect: rectBetween(gesture.origin, point) };
|
|
142
|
+
if (gesture.kind === 'none' || abandoned(editor, gesture))
|
|
143
|
+
return gesture;
|
|
144
|
+
if (gesture.kind === 'label') {
|
|
145
|
+
const offset = { dx: gesture.startOffset.dx + point.x - gesture.origin.x, dy: gesture.startOffset.dy + point.y - gesture.origin.y };
|
|
146
|
+
const next = moveJointLabel(gesture.start, gesture.id, offset);
|
|
147
|
+
editor.preview(next);
|
|
148
|
+
return { ...gesture, last: next };
|
|
149
|
+
}
|
|
150
|
+
if (gesture.kind === 'resize' || gesture.kind === 'rotate') {
|
|
151
|
+
const { document: next, highlight } = transformedWithSnap(gesture, point);
|
|
152
|
+
editor.preview(next, highlight);
|
|
153
|
+
return { ...gesture, last: next };
|
|
154
|
+
}
|
|
155
|
+
const delta = {
|
|
156
|
+
dx: point.x - gesture.origin.x,
|
|
157
|
+
dy: point.y - gesture.origin.y,
|
|
158
|
+
};
|
|
159
|
+
const { document: next, highlight } = movedWithSnap(gesture.start, gesture.ids, delta, gesture.grid);
|
|
160
|
+
editor.preview(next, highlight);
|
|
161
|
+
return { ...gesture, last: next };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Ends the drag: a move commits one history entry when a shape moved and clears the
|
|
165
|
+
* preview otherwise (FR-22); a selection rectangle adds every shape whose bounds lie
|
|
166
|
+
* fully inside it (MS-3).
|
|
167
|
+
*/
|
|
168
|
+
export function endDrag(editor, gesture) {
|
|
169
|
+
if (gesture.kind === 'marquee') {
|
|
170
|
+
const { rect } = gesture;
|
|
171
|
+
const inside = editor
|
|
172
|
+
.getState()
|
|
173
|
+
.document.shapes.filter((s) => containsRect(rect, shapeBounds(s)))
|
|
174
|
+
.map((s) => s.id);
|
|
175
|
+
if (inside.length > 0)
|
|
176
|
+
editor.selectAll(inside);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (gesture.kind === 'none' || abandoned(editor, gesture))
|
|
180
|
+
return;
|
|
181
|
+
const { last, start } = gesture;
|
|
182
|
+
const changed = gesture.kind === 'move'
|
|
183
|
+
? last && movedAny(start, last, gesture.ids)
|
|
184
|
+
: gesture.kind === 'label'
|
|
185
|
+
? last && labelMoved(start, last, gesture.id)
|
|
186
|
+
: last && transformedAny(start, last, gesture.id);
|
|
187
|
+
if (last && changed)
|
|
188
|
+
editor.commit(last);
|
|
189
|
+
else
|
|
190
|
+
editor.preview(null);
|
|
191
|
+
}
|
|
192
|
+
/** Drops the preview of an unfinished move, as on `pointercancel` (Flutter `cancelGesture`). */
|
|
193
|
+
export function cancelDrag(editor, gesture) {
|
|
194
|
+
if (gesture.kind !== 'none' && gesture.kind !== 'marquee' && !abandoned(editor, gesture))
|
|
195
|
+
editor.preview(null);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The start document with the gesture's shape resized by dragging its handle to `point`
|
|
199
|
+
* (FR-11 to FR-14), with the dragged handle's anchor snapping onto another shape's anchor
|
|
200
|
+
* (SN-2), or rotated so its handle points at `point` with soft snapping (FR-15, FR-16).
|
|
201
|
+
*/
|
|
202
|
+
function transformedWithSnap(gesture, point) {
|
|
203
|
+
const { start, id } = gesture;
|
|
204
|
+
const shape = start.shapes.find((s) => s.id === id);
|
|
205
|
+
if (!shape)
|
|
206
|
+
return { document: start, highlight: [] };
|
|
207
|
+
const replaced = (next) => ({ ...start, shapes: start.shapes.map((s) => (s === shape ? next : s)) });
|
|
208
|
+
if (gesture.kind === 'rotate') {
|
|
209
|
+
// No anchor snapping while rotating (SN-2).
|
|
210
|
+
const rotation = softSnap(rotationFromPointer(shape.center, point), gesture.snap.step, gesture.snap.tolerance).angle;
|
|
211
|
+
return { document: replaced({ ...shape, rotation }), highlight: [] };
|
|
212
|
+
}
|
|
213
|
+
const gridSize = gesture.grid.gridSize ?? undefined;
|
|
214
|
+
const gridStep = gesture.grid.visibleStep ?? undefined;
|
|
215
|
+
const limits = sizeLimitsForCanvas(start.canvas, { gridSize, gridStep });
|
|
216
|
+
const snapped = snappedResize(gesture, shape, point, limits);
|
|
217
|
+
if (snapped)
|
|
218
|
+
return { document: replaced(snapped.shape), highlight: [snapped.to] };
|
|
219
|
+
return { document: replaced(resizeByHandle(shape, gesture.handle, point, { limits, gridSize, gridStep })), highlight: [] };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The resize that puts the dragged handle's anchor exactly on a nearby anchor of another
|
|
223
|
+
* shape, or `null` when there is none or it cannot land exactly, for example at a size
|
|
224
|
+
* limit or under an aspect lock (SN-2, SN-3).
|
|
225
|
+
*/
|
|
226
|
+
function snappedResize(gesture, shape, point, limits) {
|
|
227
|
+
const targets = snapTargets(gesture.start, (id) => id === shape.id, gesture.grid);
|
|
228
|
+
if (targets.length === 0)
|
|
229
|
+
return null;
|
|
230
|
+
const anchorId = anchorIdForHandle(gesture.handle);
|
|
231
|
+
const free = resizeByHandle(shape, gesture.handle, point, { limits });
|
|
232
|
+
const position = anchorPositionOf(free, anchorId);
|
|
233
|
+
if (!position)
|
|
234
|
+
return null;
|
|
235
|
+
const snap = nearestAnchorSnap([{ id: anchorId, kind: 'vertex', position }], targets, { threshold: gesture.grid.anchorSnapDistance ?? 0 });
|
|
236
|
+
if (!snap)
|
|
237
|
+
return null;
|
|
238
|
+
const next = resizeByHandle(shape, gesture.handle, snap.to, { limits });
|
|
239
|
+
const landed = anchorPositionOf(next, anchorId);
|
|
240
|
+
if (!landed || Math.hypot(landed.x - snap.to.x, landed.y - snap.to.y) > 1e-6)
|
|
241
|
+
return null;
|
|
242
|
+
return { shape: next, to: snap.to };
|
|
243
|
+
}
|
|
244
|
+
function transformedAny(start, next, id) {
|
|
245
|
+
const before = start.shapes.find((s) => s.id === id);
|
|
246
|
+
const after = next.shapes.find((s) => s.id === id);
|
|
247
|
+
if (!before || !after)
|
|
248
|
+
return false;
|
|
249
|
+
return (before.center.x !== after.center.x ||
|
|
250
|
+
before.center.y !== after.center.y ||
|
|
251
|
+
before.size.width !== after.size.width ||
|
|
252
|
+
before.size.height !== after.size.height ||
|
|
253
|
+
before.rotation !== after.rotation);
|
|
254
|
+
}
|
|
255
|
+
export function movedDocument(start, ids, delta, grid) {
|
|
256
|
+
return movedWithSnap(start, ids, delta, grid).document;
|
|
257
|
+
}
|
|
258
|
+
/** Anchors of every shape of `document` not in `excluded`, when anchor snapping is on. */
|
|
259
|
+
function snapTargets(document, excluded, grid) {
|
|
260
|
+
if (grid.anchorSnapDistance == null)
|
|
261
|
+
return [];
|
|
262
|
+
return document.shapes.filter((s) => !excluded(s.id)).flatMap(anchorsOf);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Like {@link movedDocument}, plus the anchor that was snapped onto, if any, for the
|
|
266
|
+
* highlight (SN-3). Anchor snapping comes first and replaces grid snapping when it applies
|
|
267
|
+
* (SN-1, SN-3, GA-7); only the nearest pair counts, and for several shapes any selected
|
|
268
|
+
* anchor may snap (MS-4).
|
|
269
|
+
*/
|
|
270
|
+
export function movedWithSnap(start, ids, delta, grid) {
|
|
271
|
+
const moving = start.shapes.filter((s) => ids.includes(s.id));
|
|
272
|
+
if (moving.length === 0)
|
|
273
|
+
return { document: start, highlight: [] };
|
|
274
|
+
const targets = snapTargets(start, (id) => ids.includes(id), grid);
|
|
275
|
+
const threshold = grid.anchorSnapDistance ?? 0;
|
|
276
|
+
let shift = delta;
|
|
277
|
+
let highlight = [];
|
|
278
|
+
if (moving.length === 1) {
|
|
279
|
+
const shape = moving[0];
|
|
280
|
+
const raw = { x: shape.center.x + delta.dx, y: shape.center.y + delta.dy };
|
|
281
|
+
const snap = targets.length > 0 ? nearestAnchorSnap(anchorsOf({ ...shape, center: raw }), targets, { threshold }) : null;
|
|
282
|
+
let center = raw;
|
|
283
|
+
if (snap) {
|
|
284
|
+
center = { x: raw.x + snap.delta.dx, y: raw.y + snap.delta.dy };
|
|
285
|
+
highlight = [snap.to];
|
|
286
|
+
}
|
|
287
|
+
else if (grid.visibleStep !== null) {
|
|
288
|
+
center = snapMoveToGrid(raw, { size: shape.size, rotation: shape.rotation, step: grid.visibleStep });
|
|
289
|
+
}
|
|
290
|
+
else if (grid.gridSize !== null) {
|
|
291
|
+
center = snapPointToGrid(raw, grid.gridSize);
|
|
292
|
+
}
|
|
293
|
+
shift = { dx: center.x - shape.center.x, dy: center.y - shape.center.y };
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
const shifted = moving.flatMap((s) => anchorsOf({ ...s, center: { x: s.center.x + delta.dx, y: s.center.y + delta.dy } }));
|
|
297
|
+
const snap = targets.length > 0 ? nearestAnchorSnap(shifted, targets, { threshold }) : null;
|
|
298
|
+
const step = grid.visibleStep ?? grid.gridSize;
|
|
299
|
+
if (snap) {
|
|
300
|
+
shift = { dx: delta.dx + snap.delta.dx, dy: delta.dy + snap.delta.dy };
|
|
301
|
+
highlight = [snap.to];
|
|
302
|
+
}
|
|
303
|
+
else if (step !== null) {
|
|
304
|
+
shift = snapBoxShiftToGrid(boundsOfShapes(moving), delta, {
|
|
305
|
+
step,
|
|
306
|
+
edges: moving.every((s) => isQuarterTurn(s.rotation)),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return { document: moveShape(start, ids, shift), highlight };
|
|
311
|
+
}
|
|
312
|
+
/** A gesture whose start is no longer the committed document (undo, redo, reset or an outside value). */
|
|
313
|
+
const abandoned = (editor, gesture) => editor.getDocument() !== gesture.start;
|
|
314
|
+
function labelMoved(start, next, id) {
|
|
315
|
+
const before = start.joints.find((j) => j.id === id)?.labelOffset;
|
|
316
|
+
const after = next.joints.find((j) => j.id === id)?.labelOffset;
|
|
317
|
+
return !!before && !!after && (before.dx !== after.dx || before.dy !== after.dy);
|
|
318
|
+
}
|
|
319
|
+
function movedAny(start, next, ids) {
|
|
320
|
+
if (start === next)
|
|
321
|
+
return false;
|
|
322
|
+
const before = new Map(start.shapes.map((s) => [s.id, s.center]));
|
|
323
|
+
return next.shapes.some((s) => {
|
|
324
|
+
const from = before.get(s.id);
|
|
325
|
+
return ids.includes(s.id) && from !== undefined && (from.x !== s.center.x || from.y !== s.center.y);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/** The axis-aligned rectangle with corners `a` and `b`. */
|
|
329
|
+
export function rectBetween(a, b) {
|
|
330
|
+
return { left: Math.min(a.x, b.x), top: Math.min(a.y, b.y), width: Math.abs(a.x - b.x), height: Math.abs(a.y - b.y) };
|
|
331
|
+
}
|
|
332
|
+
/** Whether `inner` lies fully inside `outer`, edges included. */
|
|
333
|
+
function containsRect(outer, inner) {
|
|
334
|
+
return (inner.left >= outer.left &&
|
|
335
|
+
inner.top >= outer.top &&
|
|
336
|
+
inner.left + inner.width <= outer.left + outer.width &&
|
|
337
|
+
inner.top + inner.height <= outer.top + outer.height);
|
|
338
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type JointLabelSize, type Point } from '@crux-diagram/core';
|
|
2
|
+
import type { EditorStore } from '../store.js';
|
|
3
|
+
import { type LabelRect } from './gestures.js';
|
|
4
|
+
/** Hit radius of an anchor, in screen pixels (JT-2). */
|
|
5
|
+
export declare const ANCHOR_HIT_RADIUS = 22;
|
|
6
|
+
/** Anchors whose distance differs by less than this, in screen pixels, are tied: the topmost shape wins (JT-4). */
|
|
7
|
+
export declare const ANCHOR_TIE_TOLERANCE = 2;
|
|
8
|
+
/** Radius of an anchor dot, in screen pixels (JT-1). */
|
|
9
|
+
export declare const ANCHOR_VISUAL_RADIUS = 5;
|
|
10
|
+
export interface JointToolOptions {
|
|
11
|
+
/** Screen pixels per canvas unit. */
|
|
12
|
+
readonly scale: number;
|
|
13
|
+
readonly namePrefix: string;
|
|
14
|
+
readonly nameMaxLength: number;
|
|
15
|
+
/** The joint labels as drawn: tapping one selects its joint before any anchor is tried. */
|
|
16
|
+
readonly labels?: readonly LabelRect[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A tap with the joint tool at canvas `point`. A free anchor gets a new joint, shown as a
|
|
20
|
+
* preview until its name is confirmed so that creating and naming is one history entry
|
|
21
|
+
* (DL-3); an anchor with a joint selects it, showing hidden joints again (REA-025); empty
|
|
22
|
+
* canvas clears the joint selection.
|
|
23
|
+
*/
|
|
24
|
+
export declare function jointToolTap(editor: EditorStore, point: Point, { scale, namePrefix, nameMaxLength, labels }: JointToolOptions): void;
|
|
25
|
+
/** Opens the name editor for an existing joint (NM-2). */
|
|
26
|
+
export declare function beginRename(editor: EditorStore, jointId: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Confirms the name editor with `raw`, trimmed and cut to `nameMaxLength` (NM-1). A new joint
|
|
29
|
+
* is committed with its name; an empty name cancels it. An existing joint is renamed, or
|
|
30
|
+
* keeps its name when `raw` is empty.
|
|
31
|
+
*/
|
|
32
|
+
export declare function confirmNaming(editor: EditorStore, raw: string, nameMaxLength: number): void;
|
|
33
|
+
/** Closes the name editor without a change; a joint that was being created is dropped. */
|
|
34
|
+
export declare function cancelNaming(editor: EditorStore): void;
|
|
35
|
+
/** Sets the joint label size as one history entry; the size already active adds none (JS-4). */
|
|
36
|
+
export declare function setJointLabelSize(editor: EditorStore, labelSize: JointLabelSize): void;
|
|
37
|
+
/**
|
|
38
|
+
* Shows or hides every joint as one history entry (JV-6). Hiding clears the joint
|
|
39
|
+
* selection and keeps the shape selection (JV-3); the joints stay in the document (JV-5).
|
|
40
|
+
*/
|
|
41
|
+
export declare function setJointsVisible(editor: EditorStore, visible: boolean): void;
|