@pixerate/editor 0.32.0 → 0.34.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.
@@ -1,10 +1,12 @@
1
- import { C as CanvasGradientDef, A as AffineMatrix, B as BezierPathInput, a as BezierPath, S as SvgGradientDef } from '../bezier-6KPx3w7Z.cjs';
1
+ import { C as CanvasGradientDef, A as AffineMatrix, B as BezierPathInput, a as BezierPath, S as SvgGradientDef } from '../bezier-D8bsO-L0.cjs';
2
2
  import { P as Point } from '../types-BFkYA4eF.cjs';
3
3
  import { H as HistoryManager } from '../HistoryManager-DeQQMBCj.cjs';
4
4
  import { C as CommandSpec } from '../registry-D0GADKc7.cjs';
5
5
  import '../types-DsiXGmjo.cjs';
6
6
  import '../schema-DYDGdYL9.cjs';
7
7
 
8
+ /** An affine matrix `[a, b, c, d, e, f]`: `x' = a·x + c·y + e`, `y' = b·x + d·y + f` (SVG order). */
9
+ type VectorMatrix = readonly [number, number, number, number, number, number];
8
10
  /** A point in document coordinates. */
9
11
  interface Vec2 {
10
12
  x: number;
@@ -63,6 +65,13 @@ interface VectorNodeBase {
63
65
  locked?: boolean;
64
66
  /** 0–1, default 1. */
65
67
  opacity?: number;
68
+ /**
69
+ * Placement in the parent's space: a rigid matrix (rotation + translation). Anchors and
70
+ * children are in the node's own space. Omitted for unrotated nodes, whose positions are
71
+ * stored directly. Scale and skew are never stored here — `transformVectorNode` bakes
72
+ * them into the geometry, so stroke widths and the rotated selection box stay exact.
73
+ */
74
+ transform?: VectorMatrix;
66
75
  }
67
76
  /** A shape made of one or more subpaths (holes and compound shapes included). */
68
77
  interface VectorPathNode extends VectorNodeBase, VectorStyle {
@@ -178,8 +187,16 @@ declare function locateVectorNode(nodes: VectorNode[], id: string): {
178
187
  } | null;
179
188
  /** Every path node in the subtree (a path node itself, or a group's descendants). */
180
189
  declare function collectPathNodes(node: VectorNode): VectorPathNode[];
181
- /** Geometric bounds of a node (stroke width not included), or null when it has no points. */
182
- declare function vectorNodeBounds(node: VectorNode): VectorBounds | null;
190
+ /** The node's local → parent matrix (identity when it has no `transform`). */
191
+ declare function nodeMatrix(node: VectorNode): AffineMatrix;
192
+ /** A path node's outline in the space `parent` maps to (default: its parent's space). */
193
+ declare function vectorPathWorldBezier(node: VectorPathNode, parent?: AffineMatrix): BezierPath;
194
+ /**
195
+ * Geometric bounds of a node (stroke width not included) in the space `parent` maps to —
196
+ * by default the node's parent space, which for top-level nodes is the document. Null when
197
+ * the node has no points.
198
+ */
199
+ declare function vectorNodeBounds(node: VectorNode, parent?: AffineMatrix): VectorBounds | null;
183
200
  /** The smallest box around all non-null boxes, or null. */
184
201
  declare function unionBounds(list: readonly (VectorBounds | null | undefined)[]): VectorBounds | null;
185
202
  /** True when two boxes overlap (touching counts). */
@@ -190,7 +207,7 @@ declare function boundsFromPoints(a: Vec2, b: Vec2): VectorBounds;
190
207
  * Whether `p` hits a node: inside its fill (when it has one) or within half its stroke
191
208
  * width plus `tolerance` of its outline. A group is hit when any visible child is.
192
209
  */
193
- declare function hitTestVectorNode(node: VectorNode, p: Vec2, tolerance?: number): boolean;
210
+ declare function hitTestVectorNode(node: VectorNode, p: Vec2, tolerance?: number, parent?: AffineMatrix): boolean;
194
211
  /** The topmost node hit by `p` (skipping hidden and locked ones), or null. */
195
212
  declare function hitTestVectorNodes(nodes: readonly VectorNode[], p: Vec2, tolerance?: number): VectorNode | null;
196
213
  interface NearestSegment {
@@ -201,7 +218,7 @@ interface NearestSegment {
201
218
  point: Vec2;
202
219
  distance: number;
203
220
  }
204
- /** The closest point on any segment of a path node. */
221
+ /** The closest point on any segment of a path node (`p` and the result are in the node's own space). */
205
222
  declare function nearestSegment(node: VectorPathNode, p: Vec2): NearestSegment | null;
206
223
  declare const IDENTITY_MATRIX: AffineMatrix;
207
224
  /** `a` then `b` (apply `a` first). */
@@ -211,8 +228,38 @@ declare function scaleMatrix(sx: number, sy: number, origin?: Vec2): AffineMatri
211
228
  /** Rotation by `degrees` clockwise (y points down) around `origin`. */
212
229
  declare function rotateMatrix(degrees: number, origin?: Vec2): AffineMatrix;
213
230
  declare function applyMatrix(m: AffineMatrix, p: Vec2): Vec2;
214
- /** A copy of the node with every anchor and handle transformed. Stroke widths are kept. */
231
+ declare function isIdentityMatrix(m: AffineMatrix, eps?: number): boolean;
232
+ /** The inverse matrix (the identity for a singular one). */
233
+ declare function invertMatrix(m: AffineMatrix): AffineMatrix;
234
+ /** Applies only the linear part (for directions and offsets). */
235
+ declare function applyMatrixLinear(m: AffineMatrix, v: Vec2): Vec2;
236
+ /**
237
+ * The rotation of a matrix in degrees, clockwise (y down), in (−180, 180]. For a mirrored
238
+ * matrix it is the rotation left after undoing a horizontal flip, so a flipped rotated shape
239
+ * keeps its angle.
240
+ */
241
+ declare function matrixRotation(m: AffineMatrix): number;
242
+ /**
243
+ * Splits `m` into `residual` then `rigid` (`m = residual × rigid` in apply order): `rigid` is
244
+ * the nearest rotation plus the translation, `residual` the linear rest (scale, skew,
245
+ * reflection). An unrotated `m` gives an identity `rigid` and everything in `residual`.
246
+ */
247
+ declare function decomposeRigid(m: AffineMatrix): {
248
+ rigid: AffineMatrix;
249
+ residual: AffineMatrix;
250
+ };
251
+ /**
252
+ * A copy of the node moved by `m`, given in its parent's space. The node's rotation and
253
+ * translation go to its rigid `transform`; scale and skew are baked into its anchors (or its
254
+ * children), so the result draws exactly as `m` says. Stroke widths are kept.
255
+ */
215
256
  declare function transformVectorNode<T extends VectorNode>(node: T, m: AffineMatrix): T;
257
+ /** The node's rotation in degrees (from its `transform` and its ancestors' when `parent` is given). */
258
+ declare function vectorNodeRotation(node: VectorNode, parent?: AffineMatrix): number;
259
+ /** The local → document matrix of node `id` (ancestors' transforms included), or null. */
260
+ declare function vectorWorldMatrix(nodes: readonly VectorNode[], id: string): AffineMatrix | null;
261
+ /** The parent space → document matrix of node `id` (identity for top-level nodes), or null. */
262
+ declare function vectorParentMatrix(nodes: readonly VectorNode[], id: string): AffineMatrix | null;
216
263
  /** Moves an anchor and its handles by (dx, dy). */
217
264
  declare function translateAnchor(a: VectorAnchor, dx: number, dy: number): VectorAnchor;
218
265
  /**
@@ -292,10 +339,222 @@ declare function parseSvgTransform(value: string | undefined): AffineMatrix;
292
339
  /** Parses SVG markup into a vector document. Throws when there is no `<svg>` element. */
293
340
  declare function parseVectorSvg(svg: string, options?: VectorSvgImportOptions): VectorDocument;
294
341
 
342
+ /**
343
+ * What a guide line shows: `align` lines run from a target through the snapped point or box,
344
+ * `construction` lines from where a drawn point leaves, `spacing` marks equal gaps and `size`
345
+ * the side whose length matches another object's.
346
+ */
347
+ type VectorGuideKind = 'align' | 'construction' | 'spacing' | 'size';
348
+ /** A guide line in document units. */
349
+ interface VectorGuideLine {
350
+ kind: VectorGuideKind;
351
+ x1: number;
352
+ y1: number;
353
+ x2: number;
354
+ y2: number;
355
+ }
356
+ /** What a point or box snapped to. */
357
+ type VectorSnapKind = 'anchor' | 'centre' | 'intersect' | 'perpendicular' | 'tangent' | 'path' | 'construction' | 'align' | 'spacing' | 'size';
358
+ /** A guide label in document units: the snap kind's name, or a distance for gaps and sizes. */
359
+ interface VectorGuideLabel {
360
+ kind: VectorSnapKind;
361
+ x: number;
362
+ y: number;
363
+ text: string;
364
+ }
365
+ interface VectorSnapGuides {
366
+ lines: VectorGuideLine[];
367
+ labels: VectorGuideLabel[];
368
+ }
369
+ interface VectorPointSnap extends VectorSnapGuides {
370
+ point: Vec2;
371
+ /** The rule that placed the point, or null when nothing was in reach. */
372
+ kind: VectorSnapKind | null;
373
+ /** Whether x / y were set by a target (for falling back to the grid on the other axis). */
374
+ x: boolean;
375
+ y: boolean;
376
+ }
377
+ interface VectorRectSnap extends VectorSnapGuides {
378
+ /** Correction to add to the move. */
379
+ dx: number;
380
+ dy: number;
381
+ x: boolean;
382
+ y: boolean;
383
+ }
384
+ interface VectorScaleSnap extends VectorSnapGuides {
385
+ sx: number;
386
+ sy: number;
387
+ snapped: boolean;
388
+ }
389
+ /**
390
+ * The point a drawn point leaves from (the anchor before it, a shape's start, a handle's
391
+ * anchor) and how it keeps to it.
392
+ */
393
+ interface VectorSnapLeave {
394
+ at: Vec2;
395
+ /**
396
+ * Shift held: keep to 45° steps round `at` (`angle`), to a diagonal (`square`, a box's
397
+ * corner) or to the nearer axis (`axis`, a dragged point).
398
+ */
399
+ constrain?: 'angle' | 'square' | 'axis' | null;
400
+ /** Construction guide angles through `at`, degrees counter-clockwise on screen. */
401
+ angles?: readonly number[];
402
+ /** Snap to the perpendicular foot and tangent points from `at` on paths (default true). */
403
+ curves?: boolean;
404
+ }
405
+ /** The construction guide angles new editors start with. */
406
+ declare const VECTOR_CONSTRUCTION_ANGLES: readonly number[];
407
+ /** Where `constrain` puts `p` (unchanged without one). */
408
+ declare function constrainToLeave(leave: VectorSnapLeave | null | undefined, p: Vec2): Vec2;
409
+ /**
410
+ * Snap targets in document space, gathered once per gesture. Build them with `forMove`,
411
+ * `forResize`, `forDrawing`, `forAnchorDrag` or `forHandle`, then call `snapFrom`,
412
+ * `snapRect` or `snapScale` on every pointer move. Tolerances are in document units (screen
413
+ * pixels divided by the zoom).
414
+ */
415
+ declare class VectorSnapTargets {
416
+ private readonly points;
417
+ private readonly xs;
418
+ private readonly ys;
419
+ private readonly segments;
420
+ /** Bounds of the objects a moved box spaces itself evenly with. */
421
+ private readonly boxes;
422
+ /** Side lengths of the other objects (in their own frames), which a resize may match. */
423
+ private readonly sizes;
424
+ private constructor();
425
+ /** How many targets of each sort were gathered. */
426
+ get counts(): {
427
+ points: number;
428
+ lines: number;
429
+ segments: number;
430
+ boxes: number;
431
+ };
432
+ /** Targets for moving nodes `ids`: the other art's anchors, bounds and centres, the artboard, and boxes to space evenly with. */
433
+ static forMove(doc: VectorDocument, ids: readonly string[]): VectorSnapTargets;
434
+ /** Targets for resizing nodes `ids`: as for a move, plus the other objects' sizes. */
435
+ static forResize(doc: VectorDocument, ids: readonly string[]): VectorSnapTargets;
436
+ /**
437
+ * Targets for a drawn point (pen, shape tools): the art but `exclude`, its anchors (as
438
+ * points and in line), centres, edges and segments. The anchors and segments of `exclude`
439
+ * (the path being drawn, whose bounds grow with it) stay targets.
440
+ */
441
+ static forDrawing(doc: VectorDocument, exclude?: readonly string[]): VectorSnapTargets;
442
+ /**
443
+ * Targets for dragging anchors: the other art with its segments, and the anchors and
444
+ * segments that stay put on the paths being reshaped (their bounds move along, so they are
445
+ * no targets). The moving anchors are left out.
446
+ */
447
+ static forAnchorDrag(doc: VectorDocument, anchors: readonly VectorAnchorRef[]): VectorSnapTargets;
448
+ /**
449
+ * Targets for dragging a handle of path `nodeId`: the other art and that path's anchors
450
+ * (its bounds and the segments through the handle move with it, so they would chase it).
451
+ */
452
+ static forHandle(doc: VectorDocument, nodeId: string): VectorSnapTargets;
453
+ /** The anchors of the paths `ids` as targets (on them and in line), and their segments when `segments`. */
454
+ private pushPaths;
455
+ private pushAnchor;
456
+ /** The segments of `sp` (mapped by `m`) that stay put while the anchors `moving` accepts move. */
457
+ private pushSegments;
458
+ private pushRect;
459
+ /** Sorts the targets for `within` (stable: of targets alike, the first gathered wins). */
460
+ private index;
461
+ /**
462
+ * Gathers targets from the artboard and every visible node but `exclude` (and what is inside
463
+ * those): each leaf's anchors (also as lines for `drawing`), its segments (`segments`,
464
+ * `drawing`), its bounds' corners as lines and its centre; and the top-level objects' boxes and
465
+ * sizes (inside a group holding an excluded node, that group's other members).
466
+ */
467
+ private static collect;
468
+ /** Snaps a single point (see `snapFrom`). */
469
+ snapPoint(p: Vec2, tol: number): VectorPointSnap;
470
+ /**
471
+ * Snaps a point `p`, drawn or dragged from `leave` when given. With `leave.constrain` it keeps
472
+ * to its angle round `leave.at`, sliding along that way into line with the nearest target.
473
+ * Otherwise it lands, in order, on an anchor or centre, an intersection of two paths, the
474
+ * perpendicular foot or a tangent point from `leave.at`, a path, a construction guide
475
+ * through `leave.at` (where a target's line crosses it if one does nearby), or else lines up
476
+ * with targets on x and y.
477
+ */
478
+ snapFrom(p: Vec2, leave: VectorSnapLeave | null | undefined, tol: number): VectorPointSnap;
479
+ private label;
480
+ /** The anchor or centre nearest `p`, within `tol`. */
481
+ private nearestPoint;
482
+ /**
483
+ * Slides `q`, on the line through `at` along `dir` (beyond `at` only for a `ray`), to where
484
+ * the nearest target line crosses it, at most twice `tol` away: where it lands and the
485
+ * target point that line comes from.
486
+ */
487
+ private slide;
488
+ /** The guides of a point `q` slid into line with the target at `from`: the line and "align", or the target's own label when `q` sits on it. */
489
+ private linedUp;
490
+ /** Target segments whose control box reaches `p` and which pass within `tol` of it, nearest first. */
491
+ private segmentsNear;
492
+ private onSegment;
493
+ /** Where two of the target segments near `p` cross, the crossing nearest `p` within `tol`. */
494
+ private crossing;
495
+ /**
496
+ * The foot of a perpendicular, or a tangent point, from `base` on a target segment near `p`
497
+ * (within `tol` of it): roots of `(B(t) − base) · B′(t)` and `(B(t) − base) × B′(t)`
498
+ * bracketed by sign changes of samples and narrowed by bisection.
499
+ */
500
+ private curvePoint;
501
+ /**
502
+ * Snaps a moving box `r` (the moved selection's bounds): its edge or centre nearest a target
503
+ * line on each axis (`axes` limits which may move). With `spacing`, an axis that lines up
504
+ * with nothing spaces the box evenly in its row or column. Returns the correction and guides.
505
+ */
506
+ snapRect(r: VectorBounds, tol: number, options?: {
507
+ spacing?: boolean;
508
+ axes?: {
509
+ x?: boolean;
510
+ y?: boolean;
511
+ };
512
+ }): VectorRectSnap;
513
+ /**
514
+ * Equal spacing along x (`horizontal`) or y for the moved box `r`, among the objects of its
515
+ * row (column): the shift within `tol` that centres it between its neighbours, or leaves it
516
+ * as far from the neighbour before or after it as two other objects of the row are apart;
517
+ * and the gaps that are equal then, as (start, end, where across).
518
+ */
519
+ private evenSpacing;
520
+ /** A gap mark: a line across the gap with a tick at each end, and its length as a label. */
521
+ private gapMarks;
522
+ /** The other objects' side length nearest `length`, within `tol`, or null. */
523
+ matchSize(length: number, tol: number): number | null;
524
+ /**
525
+ * Snaps a selection-box resize. `sx / sy` are the scale `scaleFor` gave for dragging
526
+ * `handle` of `frame` (in the box's own, possibly rotated frame), `mods.shift` keeps the
527
+ * proportions and `mods.alt` scales about the centre. The handle lands on an anchor or
528
+ * centre within `tol`, else the corner or the side it moves lines up with the nearest
529
+ * target, whatever the box's angle; a handle with one way to go (a side, or a proportional
530
+ * corner) slides along it until one of them is on a target. An axis that snaps to nothing
531
+ * may match another object's width or height instead.
532
+ */
533
+ snapScale(frame: VectorBounds & {
534
+ angle: number;
535
+ }, handle: Exclude<VectorTransformHandle, 'rotate'>, sx: number, sy: number, mods: {
536
+ shift?: boolean;
537
+ alt?: boolean;
538
+ }, tol: number): VectorScaleSnap;
539
+ }
540
+
295
541
  interface VectorSnapOptions {
296
- /** Grid size in document units (0 = off, default 0). */
542
+ /** Grid size in document units (0 = off, default 0). Points and boxes that snap to no object snap to it. */
297
543
  grid: number;
544
+ /**
545
+ * Snap to other objects (default true): anchors, paths and their intersections, bounding-box
546
+ * edges and centres, the artboard, construction angles, equal spacing and matching sizes.
547
+ */
548
+ objects: boolean;
549
+ /** Show smart guide lines and labels while snapping (default true). */
550
+ guides: boolean;
551
+ /** How near a target pulls, in screen pixels (default 5). */
552
+ threshold: number;
553
+ /** Construction guide angles through the point a drawn point leaves from, in degrees (default 0, 45, 90, 135). */
554
+ angles: readonly number[];
298
555
  }
556
+ /** Snap options new editors start with. Hold Cmd / Ctrl (`mod`) during a drag to bypass snapping. */
557
+ declare const DEFAULT_VECTOR_SNAP: Readonly<VectorSnapOptions>;
299
558
  interface VectorEditorOptions {
300
559
  document?: VectorDocument;
301
560
  /** History to record into, e.g. one shared with the rest of the app (default: a new one). */
@@ -381,11 +640,15 @@ interface VectorEditorState {
381
640
  selectedAnchors: readonly VectorAnchorRef[];
382
641
  /** The path whose anchors are being edited, if any. */
383
642
  editingId: string | null;
384
- /** Bounds of the selected nodes in document units. */
643
+ /** Axis-aligned bounds of the selected nodes in document units. */
385
644
  selectionBounds: VectorBounds | null;
645
+ /** The selection box, rotated with the selection when its nodes share a rotation. */
646
+ selectionFrame: VectorSelectionFrame | null;
386
647
  viewport: VectorViewport;
387
648
  defaults: Readonly<Required<Pick<VectorDefaults, 'polygonSides' | 'starPoints' | 'starInnerRatio' | 'cornerRadius'>> & VectorStyle>;
388
649
  snap: VectorSnapOptions;
650
+ /** Smart guides of the snap in progress, in document units (null when there are none). */
651
+ guides: VectorSnapGuides | null;
389
652
  hitRadius: number;
390
653
  hover: VectorHover | null;
391
654
  /** A CSS cursor for the canvas. */
@@ -447,14 +710,57 @@ declare function getVisibleAnchors(state: Pick<VectorEditorState, 'document' | '
447
710
  * (direct tool), or of the last anchor of the pen path.
448
711
  */
449
712
  declare function getVisibleHandles(state: Pick<VectorEditorState, 'document' | 'selection' | 'editingId' | 'tool' | 'pen' | 'selectedAnchors'>): VectorHandleRef[];
450
- /** Looks up an anchor. */
713
+ /** Looks up an anchor (positions in its node's own space). */
451
714
  declare function getAnchor(doc: VectorDocument, ref: VectorAnchorRef): VectorAnchor | undefined;
715
+ /** An anchor with its position and handles in document space (its node's transforms applied). */
716
+ declare function getAnchorWorld(doc: VectorDocument, ref: VectorAnchorRef): {
717
+ x: number;
718
+ y: number;
719
+ in?: Vec2;
720
+ out?: Vec2;
721
+ type?: VectorAnchorType;
722
+ } | undefined;
723
+ /**
724
+ * The selection box: `angle` is the shared rotation of the selected nodes (0 when they
725
+ * differ), `x / y / width / height` the bounds in the box's own frame (document space
726
+ * rotated by −angle). A frame point `q` is at `rotateMatrix(angle)` applied to `q`.
727
+ */
728
+ interface VectorSelectionFrame {
729
+ x: number;
730
+ y: number;
731
+ width: number;
732
+ height: number;
733
+ angle: number;
734
+ }
735
+ /** The selection frame of nodes `ids` (see `VectorSelectionFrame`), or null when they have no points. */
736
+ declare function getVectorSelectionFrame(doc: VectorDocument, ids: readonly string[]): VectorSelectionFrame | null;
452
737
  /** Screen positions of the selection box handles for a box given in screen pixels. */
453
738
  declare function getTransformHandlePositions(box: VectorBounds): {
454
739
  handle: VectorTransformHandle;
455
740
  x: number;
456
741
  y: number;
457
742
  }[];
743
+ /**
744
+ * Screen geometry of a selection box. `box` and each handle's `x / y` are the unrotated box
745
+ * in screen pixels; draw them inside a group with `transform` (a `rotate(angle cx cy)`),
746
+ * or use `screen` for the true on-screen positions (hit-testing).
747
+ */
748
+ interface VectorSelectionBoxGeometry {
749
+ box: VectorBounds;
750
+ angle: number;
751
+ transform: string;
752
+ handles: {
753
+ handle: VectorTransformHandle;
754
+ x: number;
755
+ y: number;
756
+ screen: Vec2;
757
+ }[];
758
+ /** The four corners on screen, clockwise from the top left. */
759
+ corners: Vec2[];
760
+ }
761
+ declare function getVectorSelectionBoxGeometry(frame: VectorSelectionFrame, viewport: VectorViewport): VectorSelectionBoxGeometry;
762
+ /** The resize cursor for a handle of a box rotated by `angle` degrees. */
763
+ declare function vectorResizeCursor(handle: VectorTransformHandle, angle?: number): string;
458
764
  declare function vectorToolLabel(tool: VectorTool): string;
459
765
  /** Keyboard shortcut of each tool (single letters, no modifiers). */
460
766
  declare const VECTOR_TOOL_SHORTCUTS: Readonly<Record<VectorTool, string>>;
@@ -483,6 +789,11 @@ declare class VectorEditorController {
483
789
  private pointer;
484
790
  private drag;
485
791
  private interaction;
792
+ private guides;
793
+ /** Whether the last `snapDrawn` landed on an object (guides may be hidden). */
794
+ private snappedToObject;
795
+ /** Drawing targets for hovering the pen and shape tools, kept while the document and the excluded path stay the same. */
796
+ private hoverTargets;
486
797
  private spaceHeld;
487
798
  private clipboard;
488
799
  private readonly createId;
@@ -506,6 +817,11 @@ declare class VectorEditorController {
506
817
  private computeState;
507
818
  private notify;
508
819
  private boundsOf;
820
+ private frameOf;
821
+ /** Local → document matrix of a node in `doc` (default: the current document). */
822
+ private worldOf;
823
+ /** A document point in node `id`'s own space. */
824
+ private toLocal;
509
825
  private cursorFor;
510
826
  private snapshot;
511
827
  private restore;
@@ -539,8 +855,23 @@ declare class VectorEditorController {
539
855
  setTool(tool: VectorTool): void;
540
856
  setDefaults(defaults: Partial<VectorDefaults>): void;
541
857
  setSnap(snap: Partial<VectorSnapOptions>): void;
858
+ /** Turns object snapping on or off (the toolbar's snapping toggle). */
859
+ toggleSnapping(on?: boolean): void;
860
+ private gridValue;
542
861
  private snapPoint;
543
- private snapDelta;
862
+ /** The pull distance in document units. */
863
+ private snapTolerance;
864
+ private setGuides;
865
+ /**
866
+ * Where a drawn or dragged point `p` goes: onto the smart guide `targets` (gathered by
867
+ * `gather` when missing), else onto the grid, kept to `leave`'s constraint. Cmd / Ctrl
868
+ * bypasses snapping.
869
+ */
870
+ private snapDrawn;
871
+ /** Drawing targets for the pen and shape tools, reused while the document stays the same. */
872
+ private drawingTargets;
873
+ /** Where the pointer at `p` would place a point with the pen or a shape tool (and the guides showing why). */
874
+ private hoverSnap;
544
875
  /** Replaces the document. Undoable unless `{ history: false }` (then history is cleared). */
545
876
  setDocument(doc: VectorDocument, options?: {
546
877
  history?: boolean;
@@ -595,16 +926,24 @@ declare class VectorEditorController {
595
926
  }): void;
596
927
  /** Top-level ids of the selection (members of selected groups are covered by the group). */
597
928
  private selectedRoots;
929
+ /** `m`, given in a frame rotated by `angle`, as a document-space matrix. */
930
+ private inFrame;
598
931
  /** Applies a matrix to the selected (or given) nodes as one undo step. */
599
932
  transform(matrix: AffineMatrix, options?: {
600
933
  ids?: readonly string[];
601
934
  label?: string;
602
935
  }): VectorActionResult;
936
+ /** `doc` with nodes `ids` moved by `m`, given in document space. */
603
937
  private transformed;
604
938
  translate(dx: number, dy: number, options?: {
605
939
  ids?: readonly string[];
606
940
  }): VectorActionResult;
607
- /** Scales around `origin` (default: the selection centre). */
941
+ /** The selection frame's centre in document space. */
942
+ private frameCenter;
943
+ /**
944
+ * Scales along the selection box's own axes (rotated with the selection when its nodes
945
+ * share a rotation) around `origin` (default: the box centre, in document space).
946
+ */
608
947
  scale(sx: number, sy?: number, options?: {
609
948
  ids?: readonly string[];
610
949
  origin?: Vec2;
@@ -614,6 +953,11 @@ declare class VectorEditorController {
614
953
  ids?: readonly string[];
615
954
  origin?: Vec2;
616
955
  }): VectorActionResult;
956
+ /** Sets each selected (or given) node's rotation to `degrees`, turning it around its own centre. */
957
+ setRotation(degrees: number, options?: {
958
+ ids?: readonly string[];
959
+ }): VectorActionResult;
960
+ /** Mirrors along the selection box's own axes. */
617
961
  flip(axis: 'horizontal' | 'vertical', options?: {
618
962
  ids?: readonly string[];
619
963
  }): VectorActionResult;
@@ -660,21 +1004,24 @@ declare class VectorEditorController {
660
1004
  combine(options?: {
661
1005
  ids?: readonly string[];
662
1006
  }): string | null;
1007
+ /** A document-space path mapped into the parent space of node `id`. */
1008
+ private intoParentSpace;
663
1009
  /** Splits selected compound paths into one path per subpath. */
664
1010
  breakApart(options?: {
665
1011
  ids?: readonly string[];
666
1012
  }): VectorActionResult;
667
1013
  private updateAnchors;
1014
+ /** Moves anchors by a document-space offset (converted into each node's own space). */
668
1015
  private movedAnchors;
669
- /** Moves one anchor to a position (handles follow). */
1016
+ /** Moves one anchor to a document position (handles follow). */
670
1017
  moveAnchor(ref: VectorAnchorRef, to: Vec2): VectorActionResult;
671
- /** Moves one handle (see `moveAnchorHandle` for how the opposite handle follows). */
1018
+ /** Moves one handle to a document position (see `moveAnchorHandle` for how the opposite handle follows). */
672
1019
  moveHandle(ref: VectorHandleRef, to: Vec2, options?: {
673
1020
  breakHandles?: boolean;
674
1021
  }): VectorActionResult;
675
1022
  /** Converts the selected (or given) anchors between corner, smooth and symmetric. */
676
1023
  convertAnchors(type: VectorAnchorType, refs?: readonly VectorAnchorRef[]): VectorActionResult;
677
- /** Adds an anchor on the nearest segment of `nodeId` to `point` (shape unchanged). */
1024
+ /** Adds an anchor on the nearest segment of `nodeId` to document point `point` (shape unchanged). */
678
1025
  insertAnchorAt(nodeId: string, point: Vec2): VectorAnchorRef | null;
679
1026
  /** Deletes the selected anchors; empty subpaths and paths go too. */
680
1027
  deleteAnchors(refs?: readonly VectorAnchorRef[]): VectorActionResult;
@@ -719,6 +1066,12 @@ declare class VectorEditorController {
719
1066
  private downShape;
720
1067
  /** Pointer moved over the canvas (with or without a button down). */
721
1068
  pointerMove(screen: Vec2, input?: VectorPointerInput): void;
1069
+ /** Snaps a move of the selection by (dx, dy): its bounds line up with targets or space evenly, else go to the grid. */
1070
+ private snapMove;
1071
+ /** The anchor a point drag snaps by, where it started: the grabbed one, else the moving one nearest the press. */
1072
+ private leadAnchor;
1073
+ /** A shape's dragged corner moved so its width or height matches another object's, when one is within reach. */
1074
+ private matchShapeSize;
722
1075
  /** Primary button released. */
723
1076
  pointerUp(screen?: Vec2, input?: VectorPointerInput): void;
724
1077
  /** The pointer left the canvas. */
@@ -744,6 +1097,8 @@ declare function scaleFor(handle: VectorTransformHandle, b: VectorBounds, p: Vec
744
1097
  interface VectorRenderPath {
745
1098
  kind: 'path';
746
1099
  id: string;
1100
+ /** SVG `transform` (`matrix(…)`) for a rotated node. */
1101
+ transform?: string;
747
1102
  d: string;
748
1103
  /** `none`, a colour, or `url(#id)` of a gradient in `defs`. */
749
1104
  fill: string;
@@ -758,6 +1113,8 @@ interface VectorRenderPath {
758
1113
  interface VectorRenderGroup {
759
1114
  kind: 'group';
760
1115
  id: string;
1116
+ /** SVG `transform` (`matrix(…)`) for a rotated group. */
1117
+ transform?: string;
761
1118
  opacity: number;
762
1119
  children: VectorRenderNode[];
763
1120
  }
@@ -793,6 +1150,21 @@ interface VectorRenderHandle {
793
1150
  anchorY: number;
794
1151
  hovered: boolean;
795
1152
  }
1153
+ /** A smart guide line in screen pixels. */
1154
+ interface VectorRenderGuideLine {
1155
+ kind: VectorGuideKind;
1156
+ x1: number;
1157
+ y1: number;
1158
+ x2: number;
1159
+ y2: number;
1160
+ }
1161
+ /** A smart guide label ("anchor", "intersect", "align", "centre", a gap or a size) at a screen position. */
1162
+ interface VectorRenderGuideLabel {
1163
+ kind: VectorSnapKind;
1164
+ x: number;
1165
+ y: number;
1166
+ text: string;
1167
+ }
796
1168
  interface VectorOverlayRenderData {
797
1169
  /** Outlines (screen-space path data) of hovered and selected nodes. */
798
1170
  outlines: {
@@ -800,18 +1172,17 @@ interface VectorOverlayRenderData {
800
1172
  d: string;
801
1173
  selected: boolean;
802
1174
  }[];
803
- /** Selection box with resize and rotate handles (select tool), screen space. */
804
- selectionBox: {
805
- x: number;
806
- y: number;
807
- width: number;
808
- height: number;
809
- handles: {
810
- handle: VectorTransformHandle;
811
- x: number;
812
- y: number;
813
- }[];
814
- } | null;
1175
+ /**
1176
+ * Selection box with resize and rotate handles (select tool). `x / y / width / height` and
1177
+ * each handle's `x / y` are the unrotated box in screen pixels: draw them inside
1178
+ * `<g transform={transform}>`. `corners` and each handle's `screen` are true positions.
1179
+ */
1180
+ selectionBox: (VectorBounds & {
1181
+ angle: number;
1182
+ transform: string;
1183
+ corners: Vec2[];
1184
+ handles: VectorSelectionBoxGeometry['handles'];
1185
+ }) | null;
815
1186
  anchors: VectorRenderAnchor[];
816
1187
  handles: VectorRenderHandle[];
817
1188
  /** Marquee rectangle, screen space. */
@@ -820,6 +1191,11 @@ interface VectorOverlayRenderData {
820
1191
  penPreview: string | null;
821
1192
  /** Artboard rectangle, screen space. */
822
1193
  artboard: VectorBounds;
1194
+ /** Smart guides of the snap in progress, screen space (empty when nothing snapped). */
1195
+ guides: {
1196
+ lines: VectorRenderGuideLine[];
1197
+ labels: VectorRenderGuideLabel[];
1198
+ };
823
1199
  /** A short status, e.g. "W 120 × H 80" or "45°". */
824
1200
  status: string | null;
825
1201
  }
@@ -835,6 +1211,8 @@ declare function getVectorOverlayRenderData(state: VectorEditorState): VectorOve
835
1211
  /** Colours and sizes (screen pixels) the bundled canvases draw the overlay with. */
836
1212
  declare const VECTOR_OVERLAY_THEME: {
837
1213
  readonly accent: "#0ea5e9";
1214
+ /** Smart guide lines and labels. */
1215
+ readonly guide: "#ff3dfc";
838
1216
  readonly handleFill: "#ffffff";
839
1217
  readonly marqueeFill: "rgba(14, 165, 233, 0.08)";
840
1218
  readonly transformHandleSize: 8;
@@ -906,12 +1284,15 @@ interface VectorNodeListing {
906
1284
  type: 'path' | 'group';
907
1285
  name?: string;
908
1286
  depth: number;
1287
+ /** Axis-aligned bounds in document units. */
909
1288
  bounds: {
910
1289
  x: number;
911
1290
  y: number;
912
1291
  width: number;
913
1292
  height: number;
914
1293
  } | null;
1294
+ /** Rotation in degrees, clockwise (ancestors' rotations included). */
1295
+ rotation: number;
915
1296
  visible: boolean;
916
1297
  locked: boolean;
917
1298
  selected: boolean;
@@ -930,4 +1311,4 @@ interface VectorNodeListing {
930
1311
  */
931
1312
  declare function createVectorCommands(controller: VectorEditorController, options?: VectorCommandOptions): CommandSpec[];
932
1313
 
933
- export { type AddVectorNodeOptions, AffineMatrix, IDENTITY_MATRIX, KAPPA, type NearestSegment, SvgGradientDef, VECTOR_CLIPBOARD_TYPE, VECTOR_OVERLAY_THEME, VECTOR_ROTATE_HANDLE_OFFSET, VECTOR_TOOLS, VECTOR_TOOL_GLYPHS, VECTOR_TOOL_SHORTCUTS, VECTOR_TRANSFORM_HANDLES, type Vec2, type VectorActionResult, type VectorAlign, type VectorAnchor, type VectorAnchorRef, type VectorAnchorType, type VectorArrange, type VectorBooleanOperation, type VectorBounds, type VectorCommandOptions, type VectorDefaults, type VectorDistribute, type VectorDocument, VectorEditorController, type VectorEditorOptions, type VectorEditorState, type VectorFillRule, type VectorGroupNode, type VectorHandleRef, type VectorHover, type VectorInteraction, type VectorKeyInput, type VectorLineCap, type VectorLineJoin, type VectorModifiers, type VectorNode, type VectorNodeListing, type VectorOverlayRenderData, type VectorPaint, type VectorPathNode, type VectorPointerInput, type VectorRenderAnchor, type VectorRenderGroup, type VectorRenderHandle, type VectorRenderNode, type VectorRenderPath, type VectorSceneRenderData, type VectorSelectionStyle, type VectorShapeInput, type VectorSnapOptions, type VectorStyle, type VectorSubpath, type VectorSvgExportOptions, type VectorSvgImportOptions, type VectorTool, type VectorTransformHandle, type VectorViewport, applyMatrix, bezierToSubpaths, boundsFromPoints, boundsIntersect, cloneAnchor, cloneSubpath, cloneVectorDocument, cloneVectorNode, collectPathNodes, convertAnchor, createVectorCommands, ellipseSubpath, findVectorNode, getAnchor, getEditablePathIds, getTransformHandlePositions, getVectorOverlayRenderData, getVectorSceneRenderData, getVectorSelectionStyle, getVisibleAnchors, getVisibleHandles, hasPaint, hitTestVectorNode, hitTestVectorNodes, inferAnchorType, insertAnchor, isVectorTextTarget, lineSubpath, locateVectorNode, moveAnchorHandle, multiplyMatrices, nearestSegment, parseSvgTransform, parseVectorSvg, polygonSubpath, rectSubpath, removeAnchors, reverseSubpath, rotateMatrix, roundSubpaths, scaleFor, scaleMatrix, starSubpath, subpathSegment, subpathSegmentCount, subpathsToBezier, toVectorKeyInput, toVectorModifiers, toVectorPointerInput, transformVectorNode, translateAnchor, translateMatrix, unionBounds, vectorDocumentToSvg, vectorNodeBounds, vectorNodeToBezier, vectorPaintToHex, vectorPaintToSvg, vectorPathData, vectorToolLabel, walkVectorNodes };
1314
+ export { type AddVectorNodeOptions, AffineMatrix, DEFAULT_VECTOR_SNAP, IDENTITY_MATRIX, KAPPA, type NearestSegment, SvgGradientDef, VECTOR_CLIPBOARD_TYPE, VECTOR_CONSTRUCTION_ANGLES, VECTOR_OVERLAY_THEME, VECTOR_ROTATE_HANDLE_OFFSET, VECTOR_TOOLS, VECTOR_TOOL_GLYPHS, VECTOR_TOOL_SHORTCUTS, VECTOR_TRANSFORM_HANDLES, type Vec2, type VectorActionResult, type VectorAlign, type VectorAnchor, type VectorAnchorRef, type VectorAnchorType, type VectorArrange, type VectorBooleanOperation, type VectorBounds, type VectorCommandOptions, type VectorDefaults, type VectorDistribute, type VectorDocument, VectorEditorController, type VectorEditorOptions, type VectorEditorState, type VectorFillRule, type VectorGroupNode, type VectorGuideKind, type VectorGuideLabel, type VectorGuideLine, type VectorHandleRef, type VectorHover, type VectorInteraction, type VectorKeyInput, type VectorLineCap, type VectorLineJoin, type VectorMatrix, type VectorModifiers, type VectorNode, type VectorNodeListing, type VectorOverlayRenderData, type VectorPaint, type VectorPathNode, type VectorPointSnap, type VectorPointerInput, type VectorRectSnap, type VectorRenderAnchor, type VectorRenderGroup, type VectorRenderGuideLabel, type VectorRenderGuideLine, type VectorRenderHandle, type VectorRenderNode, type VectorRenderPath, type VectorScaleSnap, type VectorSceneRenderData, type VectorSelectionBoxGeometry, type VectorSelectionFrame, type VectorSelectionStyle, type VectorShapeInput, type VectorSnapGuides, type VectorSnapKind, type VectorSnapLeave, type VectorSnapOptions, VectorSnapTargets, type VectorStyle, type VectorSubpath, type VectorSvgExportOptions, type VectorSvgImportOptions, type VectorTool, type VectorTransformHandle, type VectorViewport, applyMatrix, applyMatrixLinear, bezierToSubpaths, boundsFromPoints, boundsIntersect, cloneAnchor, cloneSubpath, cloneVectorDocument, cloneVectorNode, collectPathNodes, constrainToLeave, convertAnchor, createVectorCommands, decomposeRigid, ellipseSubpath, findVectorNode, getAnchor, getAnchorWorld, getEditablePathIds, getTransformHandlePositions, getVectorOverlayRenderData, getVectorSceneRenderData, getVectorSelectionBoxGeometry, getVectorSelectionFrame, getVectorSelectionStyle, getVisibleAnchors, getVisibleHandles, hasPaint, hitTestVectorNode, hitTestVectorNodes, inferAnchorType, insertAnchor, invertMatrix, isIdentityMatrix, isVectorTextTarget, lineSubpath, locateVectorNode, matrixRotation, moveAnchorHandle, multiplyMatrices, nearestSegment, nodeMatrix, parseSvgTransform, parseVectorSvg, polygonSubpath, rectSubpath, removeAnchors, reverseSubpath, rotateMatrix, roundSubpaths, scaleFor, scaleMatrix, starSubpath, subpathSegment, subpathSegmentCount, subpathsToBezier, toVectorKeyInput, toVectorModifiers, toVectorPointerInput, transformVectorNode, translateAnchor, translateMatrix, unionBounds, vectorDocumentToSvg, vectorNodeBounds, vectorNodeRotation, vectorNodeToBezier, vectorPaintToHex, vectorPaintToSvg, vectorParentMatrix, vectorPathData, vectorPathWorldBezier, vectorResizeCursor, vectorToolLabel, vectorWorldMatrix, walkVectorNodes };