@pixerate/editor 0.32.0 → 0.33.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.
@@ -5,6 +5,8 @@ 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
  /**
@@ -381,8 +428,10 @@ interface VectorEditorState {
381
428
  selectedAnchors: readonly VectorAnchorRef[];
382
429
  /** The path whose anchors are being edited, if any. */
383
430
  editingId: string | null;
384
- /** Bounds of the selected nodes in document units. */
431
+ /** Axis-aligned bounds of the selected nodes in document units. */
385
432
  selectionBounds: VectorBounds | null;
433
+ /** The selection box, rotated with the selection when its nodes share a rotation. */
434
+ selectionFrame: VectorSelectionFrame | null;
386
435
  viewport: VectorViewport;
387
436
  defaults: Readonly<Required<Pick<VectorDefaults, 'polygonSides' | 'starPoints' | 'starInnerRatio' | 'cornerRadius'>> & VectorStyle>;
388
437
  snap: VectorSnapOptions;
@@ -447,14 +496,57 @@ declare function getVisibleAnchors(state: Pick<VectorEditorState, 'document' | '
447
496
  * (direct tool), or of the last anchor of the pen path.
448
497
  */
449
498
  declare function getVisibleHandles(state: Pick<VectorEditorState, 'document' | 'selection' | 'editingId' | 'tool' | 'pen' | 'selectedAnchors'>): VectorHandleRef[];
450
- /** Looks up an anchor. */
499
+ /** Looks up an anchor (positions in its node's own space). */
451
500
  declare function getAnchor(doc: VectorDocument, ref: VectorAnchorRef): VectorAnchor | undefined;
501
+ /** An anchor with its position and handles in document space (its node's transforms applied). */
502
+ declare function getAnchorWorld(doc: VectorDocument, ref: VectorAnchorRef): {
503
+ x: number;
504
+ y: number;
505
+ in?: Vec2;
506
+ out?: Vec2;
507
+ type?: VectorAnchorType;
508
+ } | undefined;
509
+ /**
510
+ * The selection box: `angle` is the shared rotation of the selected nodes (0 when they
511
+ * differ), `x / y / width / height` the bounds in the box's own frame (document space
512
+ * rotated by −angle). A frame point `q` is at `rotateMatrix(angle)` applied to `q`.
513
+ */
514
+ interface VectorSelectionFrame {
515
+ x: number;
516
+ y: number;
517
+ width: number;
518
+ height: number;
519
+ angle: number;
520
+ }
521
+ /** The selection frame of nodes `ids` (see `VectorSelectionFrame`), or null when they have no points. */
522
+ declare function getVectorSelectionFrame(doc: VectorDocument, ids: readonly string[]): VectorSelectionFrame | null;
452
523
  /** Screen positions of the selection box handles for a box given in screen pixels. */
453
524
  declare function getTransformHandlePositions(box: VectorBounds): {
454
525
  handle: VectorTransformHandle;
455
526
  x: number;
456
527
  y: number;
457
528
  }[];
529
+ /**
530
+ * Screen geometry of a selection box. `box` and each handle's `x / y` are the unrotated box
531
+ * in screen pixels; draw them inside a group with `transform` (a `rotate(angle cx cy)`),
532
+ * or use `screen` for the true on-screen positions (hit-testing).
533
+ */
534
+ interface VectorSelectionBoxGeometry {
535
+ box: VectorBounds;
536
+ angle: number;
537
+ transform: string;
538
+ handles: {
539
+ handle: VectorTransformHandle;
540
+ x: number;
541
+ y: number;
542
+ screen: Vec2;
543
+ }[];
544
+ /** The four corners on screen, clockwise from the top left. */
545
+ corners: Vec2[];
546
+ }
547
+ declare function getVectorSelectionBoxGeometry(frame: VectorSelectionFrame, viewport: VectorViewport): VectorSelectionBoxGeometry;
548
+ /** The resize cursor for a handle of a box rotated by `angle` degrees. */
549
+ declare function vectorResizeCursor(handle: VectorTransformHandle, angle?: number): string;
458
550
  declare function vectorToolLabel(tool: VectorTool): string;
459
551
  /** Keyboard shortcut of each tool (single letters, no modifiers). */
460
552
  declare const VECTOR_TOOL_SHORTCUTS: Readonly<Record<VectorTool, string>>;
@@ -506,6 +598,11 @@ declare class VectorEditorController {
506
598
  private computeState;
507
599
  private notify;
508
600
  private boundsOf;
601
+ private frameOf;
602
+ /** Local → document matrix of a node in `doc` (default: the current document). */
603
+ private worldOf;
604
+ /** A document point in node `id`'s own space. */
605
+ private toLocal;
509
606
  private cursorFor;
510
607
  private snapshot;
511
608
  private restore;
@@ -595,16 +692,24 @@ declare class VectorEditorController {
595
692
  }): void;
596
693
  /** Top-level ids of the selection (members of selected groups are covered by the group). */
597
694
  private selectedRoots;
695
+ /** `m`, given in a frame rotated by `angle`, as a document-space matrix. */
696
+ private inFrame;
598
697
  /** Applies a matrix to the selected (or given) nodes as one undo step. */
599
698
  transform(matrix: AffineMatrix, options?: {
600
699
  ids?: readonly string[];
601
700
  label?: string;
602
701
  }): VectorActionResult;
702
+ /** `doc` with nodes `ids` moved by `m`, given in document space. */
603
703
  private transformed;
604
704
  translate(dx: number, dy: number, options?: {
605
705
  ids?: readonly string[];
606
706
  }): VectorActionResult;
607
- /** Scales around `origin` (default: the selection centre). */
707
+ /** The selection frame's centre in document space. */
708
+ private frameCenter;
709
+ /**
710
+ * Scales along the selection box's own axes (rotated with the selection when its nodes
711
+ * share a rotation) around `origin` (default: the box centre, in document space).
712
+ */
608
713
  scale(sx: number, sy?: number, options?: {
609
714
  ids?: readonly string[];
610
715
  origin?: Vec2;
@@ -614,6 +719,11 @@ declare class VectorEditorController {
614
719
  ids?: readonly string[];
615
720
  origin?: Vec2;
616
721
  }): VectorActionResult;
722
+ /** Sets each selected (or given) node's rotation to `degrees`, turning it around its own centre. */
723
+ setRotation(degrees: number, options?: {
724
+ ids?: readonly string[];
725
+ }): VectorActionResult;
726
+ /** Mirrors along the selection box's own axes. */
617
727
  flip(axis: 'horizontal' | 'vertical', options?: {
618
728
  ids?: readonly string[];
619
729
  }): VectorActionResult;
@@ -660,21 +770,24 @@ declare class VectorEditorController {
660
770
  combine(options?: {
661
771
  ids?: readonly string[];
662
772
  }): string | null;
773
+ /** A document-space path mapped into the parent space of node `id`. */
774
+ private intoParentSpace;
663
775
  /** Splits selected compound paths into one path per subpath. */
664
776
  breakApart(options?: {
665
777
  ids?: readonly string[];
666
778
  }): VectorActionResult;
667
779
  private updateAnchors;
780
+ /** Moves anchors by a document-space offset (converted into each node's own space). */
668
781
  private movedAnchors;
669
- /** Moves one anchor to a position (handles follow). */
782
+ /** Moves one anchor to a document position (handles follow). */
670
783
  moveAnchor(ref: VectorAnchorRef, to: Vec2): VectorActionResult;
671
- /** Moves one handle (see `moveAnchorHandle` for how the opposite handle follows). */
784
+ /** Moves one handle to a document position (see `moveAnchorHandle` for how the opposite handle follows). */
672
785
  moveHandle(ref: VectorHandleRef, to: Vec2, options?: {
673
786
  breakHandles?: boolean;
674
787
  }): VectorActionResult;
675
788
  /** Converts the selected (or given) anchors between corner, smooth and symmetric. */
676
789
  convertAnchors(type: VectorAnchorType, refs?: readonly VectorAnchorRef[]): VectorActionResult;
677
- /** Adds an anchor on the nearest segment of `nodeId` to `point` (shape unchanged). */
790
+ /** Adds an anchor on the nearest segment of `nodeId` to document point `point` (shape unchanged). */
678
791
  insertAnchorAt(nodeId: string, point: Vec2): VectorAnchorRef | null;
679
792
  /** Deletes the selected anchors; empty subpaths and paths go too. */
680
793
  deleteAnchors(refs?: readonly VectorAnchorRef[]): VectorActionResult;
@@ -744,6 +857,8 @@ declare function scaleFor(handle: VectorTransformHandle, b: VectorBounds, p: Vec
744
857
  interface VectorRenderPath {
745
858
  kind: 'path';
746
859
  id: string;
860
+ /** SVG `transform` (`matrix(…)`) for a rotated node. */
861
+ transform?: string;
747
862
  d: string;
748
863
  /** `none`, a colour, or `url(#id)` of a gradient in `defs`. */
749
864
  fill: string;
@@ -758,6 +873,8 @@ interface VectorRenderPath {
758
873
  interface VectorRenderGroup {
759
874
  kind: 'group';
760
875
  id: string;
876
+ /** SVG `transform` (`matrix(…)`) for a rotated group. */
877
+ transform?: string;
761
878
  opacity: number;
762
879
  children: VectorRenderNode[];
763
880
  }
@@ -800,18 +917,17 @@ interface VectorOverlayRenderData {
800
917
  d: string;
801
918
  selected: boolean;
802
919
  }[];
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;
920
+ /**
921
+ * Selection box with resize and rotate handles (select tool). `x / y / width / height` and
922
+ * each handle's `x / y` are the unrotated box in screen pixels: draw them inside
923
+ * `<g transform={transform}>`. `corners` and each handle's `screen` are true positions.
924
+ */
925
+ selectionBox: (VectorBounds & {
926
+ angle: number;
927
+ transform: string;
928
+ corners: Vec2[];
929
+ handles: VectorSelectionBoxGeometry['handles'];
930
+ }) | null;
815
931
  anchors: VectorRenderAnchor[];
816
932
  handles: VectorRenderHandle[];
817
933
  /** Marquee rectangle, screen space. */
@@ -906,12 +1022,15 @@ interface VectorNodeListing {
906
1022
  type: 'path' | 'group';
907
1023
  name?: string;
908
1024
  depth: number;
1025
+ /** Axis-aligned bounds in document units. */
909
1026
  bounds: {
910
1027
  x: number;
911
1028
  y: number;
912
1029
  width: number;
913
1030
  height: number;
914
1031
  } | null;
1032
+ /** Rotation in degrees, clockwise (ancestors' rotations included). */
1033
+ rotation: number;
915
1034
  visible: boolean;
916
1035
  locked: boolean;
917
1036
  selected: boolean;
@@ -930,4 +1049,4 @@ interface VectorNodeListing {
930
1049
  */
931
1050
  declare function createVectorCommands(controller: VectorEditorController, options?: VectorCommandOptions): CommandSpec[];
932
1051
 
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 };
1052
+ 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 VectorMatrix, 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 VectorSelectionBoxGeometry, type VectorSelectionFrame, type VectorSelectionStyle, type VectorShapeInput, type VectorSnapOptions, type VectorStyle, type VectorSubpath, type VectorSvgExportOptions, type VectorSvgImportOptions, type VectorTool, type VectorTransformHandle, type VectorViewport, applyMatrix, applyMatrixLinear, bezierToSubpaths, boundsFromPoints, boundsIntersect, cloneAnchor, cloneSubpath, cloneVectorDocument, cloneVectorNode, collectPathNodes, 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 };
@@ -5,6 +5,8 @@ import { C as CommandSpec } from '../registry-DhVUZioj.js';
5
5
  import '../types-DsiXGmjo.js';
6
6
  import '../schema-DYDGdYL9.js';
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
  /**
@@ -381,8 +428,10 @@ interface VectorEditorState {
381
428
  selectedAnchors: readonly VectorAnchorRef[];
382
429
  /** The path whose anchors are being edited, if any. */
383
430
  editingId: string | null;
384
- /** Bounds of the selected nodes in document units. */
431
+ /** Axis-aligned bounds of the selected nodes in document units. */
385
432
  selectionBounds: VectorBounds | null;
433
+ /** The selection box, rotated with the selection when its nodes share a rotation. */
434
+ selectionFrame: VectorSelectionFrame | null;
386
435
  viewport: VectorViewport;
387
436
  defaults: Readonly<Required<Pick<VectorDefaults, 'polygonSides' | 'starPoints' | 'starInnerRatio' | 'cornerRadius'>> & VectorStyle>;
388
437
  snap: VectorSnapOptions;
@@ -447,14 +496,57 @@ declare function getVisibleAnchors(state: Pick<VectorEditorState, 'document' | '
447
496
  * (direct tool), or of the last anchor of the pen path.
448
497
  */
449
498
  declare function getVisibleHandles(state: Pick<VectorEditorState, 'document' | 'selection' | 'editingId' | 'tool' | 'pen' | 'selectedAnchors'>): VectorHandleRef[];
450
- /** Looks up an anchor. */
499
+ /** Looks up an anchor (positions in its node's own space). */
451
500
  declare function getAnchor(doc: VectorDocument, ref: VectorAnchorRef): VectorAnchor | undefined;
501
+ /** An anchor with its position and handles in document space (its node's transforms applied). */
502
+ declare function getAnchorWorld(doc: VectorDocument, ref: VectorAnchorRef): {
503
+ x: number;
504
+ y: number;
505
+ in?: Vec2;
506
+ out?: Vec2;
507
+ type?: VectorAnchorType;
508
+ } | undefined;
509
+ /**
510
+ * The selection box: `angle` is the shared rotation of the selected nodes (0 when they
511
+ * differ), `x / y / width / height` the bounds in the box's own frame (document space
512
+ * rotated by −angle). A frame point `q` is at `rotateMatrix(angle)` applied to `q`.
513
+ */
514
+ interface VectorSelectionFrame {
515
+ x: number;
516
+ y: number;
517
+ width: number;
518
+ height: number;
519
+ angle: number;
520
+ }
521
+ /** The selection frame of nodes `ids` (see `VectorSelectionFrame`), or null when they have no points. */
522
+ declare function getVectorSelectionFrame(doc: VectorDocument, ids: readonly string[]): VectorSelectionFrame | null;
452
523
  /** Screen positions of the selection box handles for a box given in screen pixels. */
453
524
  declare function getTransformHandlePositions(box: VectorBounds): {
454
525
  handle: VectorTransformHandle;
455
526
  x: number;
456
527
  y: number;
457
528
  }[];
529
+ /**
530
+ * Screen geometry of a selection box. `box` and each handle's `x / y` are the unrotated box
531
+ * in screen pixels; draw them inside a group with `transform` (a `rotate(angle cx cy)`),
532
+ * or use `screen` for the true on-screen positions (hit-testing).
533
+ */
534
+ interface VectorSelectionBoxGeometry {
535
+ box: VectorBounds;
536
+ angle: number;
537
+ transform: string;
538
+ handles: {
539
+ handle: VectorTransformHandle;
540
+ x: number;
541
+ y: number;
542
+ screen: Vec2;
543
+ }[];
544
+ /** The four corners on screen, clockwise from the top left. */
545
+ corners: Vec2[];
546
+ }
547
+ declare function getVectorSelectionBoxGeometry(frame: VectorSelectionFrame, viewport: VectorViewport): VectorSelectionBoxGeometry;
548
+ /** The resize cursor for a handle of a box rotated by `angle` degrees. */
549
+ declare function vectorResizeCursor(handle: VectorTransformHandle, angle?: number): string;
458
550
  declare function vectorToolLabel(tool: VectorTool): string;
459
551
  /** Keyboard shortcut of each tool (single letters, no modifiers). */
460
552
  declare const VECTOR_TOOL_SHORTCUTS: Readonly<Record<VectorTool, string>>;
@@ -506,6 +598,11 @@ declare class VectorEditorController {
506
598
  private computeState;
507
599
  private notify;
508
600
  private boundsOf;
601
+ private frameOf;
602
+ /** Local → document matrix of a node in `doc` (default: the current document). */
603
+ private worldOf;
604
+ /** A document point in node `id`'s own space. */
605
+ private toLocal;
509
606
  private cursorFor;
510
607
  private snapshot;
511
608
  private restore;
@@ -595,16 +692,24 @@ declare class VectorEditorController {
595
692
  }): void;
596
693
  /** Top-level ids of the selection (members of selected groups are covered by the group). */
597
694
  private selectedRoots;
695
+ /** `m`, given in a frame rotated by `angle`, as a document-space matrix. */
696
+ private inFrame;
598
697
  /** Applies a matrix to the selected (or given) nodes as one undo step. */
599
698
  transform(matrix: AffineMatrix, options?: {
600
699
  ids?: readonly string[];
601
700
  label?: string;
602
701
  }): VectorActionResult;
702
+ /** `doc` with nodes `ids` moved by `m`, given in document space. */
603
703
  private transformed;
604
704
  translate(dx: number, dy: number, options?: {
605
705
  ids?: readonly string[];
606
706
  }): VectorActionResult;
607
- /** Scales around `origin` (default: the selection centre). */
707
+ /** The selection frame's centre in document space. */
708
+ private frameCenter;
709
+ /**
710
+ * Scales along the selection box's own axes (rotated with the selection when its nodes
711
+ * share a rotation) around `origin` (default: the box centre, in document space).
712
+ */
608
713
  scale(sx: number, sy?: number, options?: {
609
714
  ids?: readonly string[];
610
715
  origin?: Vec2;
@@ -614,6 +719,11 @@ declare class VectorEditorController {
614
719
  ids?: readonly string[];
615
720
  origin?: Vec2;
616
721
  }): VectorActionResult;
722
+ /** Sets each selected (or given) node's rotation to `degrees`, turning it around its own centre. */
723
+ setRotation(degrees: number, options?: {
724
+ ids?: readonly string[];
725
+ }): VectorActionResult;
726
+ /** Mirrors along the selection box's own axes. */
617
727
  flip(axis: 'horizontal' | 'vertical', options?: {
618
728
  ids?: readonly string[];
619
729
  }): VectorActionResult;
@@ -660,21 +770,24 @@ declare class VectorEditorController {
660
770
  combine(options?: {
661
771
  ids?: readonly string[];
662
772
  }): string | null;
773
+ /** A document-space path mapped into the parent space of node `id`. */
774
+ private intoParentSpace;
663
775
  /** Splits selected compound paths into one path per subpath. */
664
776
  breakApart(options?: {
665
777
  ids?: readonly string[];
666
778
  }): VectorActionResult;
667
779
  private updateAnchors;
780
+ /** Moves anchors by a document-space offset (converted into each node's own space). */
668
781
  private movedAnchors;
669
- /** Moves one anchor to a position (handles follow). */
782
+ /** Moves one anchor to a document position (handles follow). */
670
783
  moveAnchor(ref: VectorAnchorRef, to: Vec2): VectorActionResult;
671
- /** Moves one handle (see `moveAnchorHandle` for how the opposite handle follows). */
784
+ /** Moves one handle to a document position (see `moveAnchorHandle` for how the opposite handle follows). */
672
785
  moveHandle(ref: VectorHandleRef, to: Vec2, options?: {
673
786
  breakHandles?: boolean;
674
787
  }): VectorActionResult;
675
788
  /** Converts the selected (or given) anchors between corner, smooth and symmetric. */
676
789
  convertAnchors(type: VectorAnchorType, refs?: readonly VectorAnchorRef[]): VectorActionResult;
677
- /** Adds an anchor on the nearest segment of `nodeId` to `point` (shape unchanged). */
790
+ /** Adds an anchor on the nearest segment of `nodeId` to document point `point` (shape unchanged). */
678
791
  insertAnchorAt(nodeId: string, point: Vec2): VectorAnchorRef | null;
679
792
  /** Deletes the selected anchors; empty subpaths and paths go too. */
680
793
  deleteAnchors(refs?: readonly VectorAnchorRef[]): VectorActionResult;
@@ -744,6 +857,8 @@ declare function scaleFor(handle: VectorTransformHandle, b: VectorBounds, p: Vec
744
857
  interface VectorRenderPath {
745
858
  kind: 'path';
746
859
  id: string;
860
+ /** SVG `transform` (`matrix(…)`) for a rotated node. */
861
+ transform?: string;
747
862
  d: string;
748
863
  /** `none`, a colour, or `url(#id)` of a gradient in `defs`. */
749
864
  fill: string;
@@ -758,6 +873,8 @@ interface VectorRenderPath {
758
873
  interface VectorRenderGroup {
759
874
  kind: 'group';
760
875
  id: string;
876
+ /** SVG `transform` (`matrix(…)`) for a rotated group. */
877
+ transform?: string;
761
878
  opacity: number;
762
879
  children: VectorRenderNode[];
763
880
  }
@@ -800,18 +917,17 @@ interface VectorOverlayRenderData {
800
917
  d: string;
801
918
  selected: boolean;
802
919
  }[];
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;
920
+ /**
921
+ * Selection box with resize and rotate handles (select tool). `x / y / width / height` and
922
+ * each handle's `x / y` are the unrotated box in screen pixels: draw them inside
923
+ * `<g transform={transform}>`. `corners` and each handle's `screen` are true positions.
924
+ */
925
+ selectionBox: (VectorBounds & {
926
+ angle: number;
927
+ transform: string;
928
+ corners: Vec2[];
929
+ handles: VectorSelectionBoxGeometry['handles'];
930
+ }) | null;
815
931
  anchors: VectorRenderAnchor[];
816
932
  handles: VectorRenderHandle[];
817
933
  /** Marquee rectangle, screen space. */
@@ -906,12 +1022,15 @@ interface VectorNodeListing {
906
1022
  type: 'path' | 'group';
907
1023
  name?: string;
908
1024
  depth: number;
1025
+ /** Axis-aligned bounds in document units. */
909
1026
  bounds: {
910
1027
  x: number;
911
1028
  y: number;
912
1029
  width: number;
913
1030
  height: number;
914
1031
  } | null;
1032
+ /** Rotation in degrees, clockwise (ancestors' rotations included). */
1033
+ rotation: number;
915
1034
  visible: boolean;
916
1035
  locked: boolean;
917
1036
  selected: boolean;
@@ -930,4 +1049,4 @@ interface VectorNodeListing {
930
1049
  */
931
1050
  declare function createVectorCommands(controller: VectorEditorController, options?: VectorCommandOptions): CommandSpec[];
932
1051
 
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 };
1052
+ 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 VectorMatrix, 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 VectorSelectionBoxGeometry, type VectorSelectionFrame, type VectorSelectionStyle, type VectorShapeInput, type VectorSnapOptions, type VectorStyle, type VectorSubpath, type VectorSvgExportOptions, type VectorSvgImportOptions, type VectorTool, type VectorTransformHandle, type VectorViewport, applyMatrix, applyMatrixLinear, bezierToSubpaths, boundsFromPoints, boundsIntersect, cloneAnchor, cloneSubpath, cloneVectorDocument, cloneVectorNode, collectPathNodes, 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 };