@pixerate/editor 0.19.0 → 0.21.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.
Files changed (112) hide show
  1. package/README.md +95 -4
  2. package/dist/agent/index.cjs +625 -2
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +286 -2
  5. package/dist/agent/index.d.ts +286 -2
  6. package/dist/agent/index.js +624 -1
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/canvas/index.cjs +1240 -22
  9. package/dist/canvas/index.cjs.map +1 -1
  10. package/dist/canvas/index.d.cts +515 -3
  11. package/dist/canvas/index.d.ts +515 -3
  12. package/dist/canvas/index.js +1219 -1
  13. package/dist/canvas/index.js.map +1 -1
  14. package/dist/chunk-3TYMNULT.js +1367 -0
  15. package/dist/chunk-3TYMNULT.js.map +1 -0
  16. package/dist/chunk-4QPLEUL2.cjs +4480 -0
  17. package/dist/chunk-4QPLEUL2.cjs.map +1 -0
  18. package/dist/chunk-4SUNJZWB.cjs +553 -0
  19. package/dist/chunk-4SUNJZWB.cjs.map +1 -0
  20. package/dist/chunk-A7DKIA72.js +2657 -0
  21. package/dist/chunk-A7DKIA72.js.map +1 -0
  22. package/dist/chunk-AXV2ZW34.cjs +118 -0
  23. package/dist/chunk-AXV2ZW34.cjs.map +1 -0
  24. package/dist/chunk-B2ZRLN4S.js +118 -0
  25. package/dist/chunk-B2ZRLN4S.js.map +1 -0
  26. package/dist/chunk-CYFJCKC4.js +4480 -0
  27. package/dist/chunk-CYFJCKC4.js.map +1 -0
  28. package/dist/chunk-GVW4P7BG.js +2706 -0
  29. package/dist/chunk-GVW4P7BG.js.map +1 -0
  30. package/dist/chunk-JACER6TE.cjs +1 -0
  31. package/dist/chunk-JACER6TE.cjs.map +1 -0
  32. package/dist/chunk-JYRIOFEN.cjs +2657 -0
  33. package/dist/chunk-JYRIOFEN.cjs.map +1 -0
  34. package/dist/chunk-KYRZDWM4.js +299 -0
  35. package/dist/chunk-KYRZDWM4.js.map +1 -0
  36. package/dist/chunk-LA7PEGU3.cjs +299 -0
  37. package/dist/chunk-LA7PEGU3.cjs.map +1 -0
  38. package/dist/chunk-N7FG6CBO.js +1 -0
  39. package/dist/chunk-N7FG6CBO.js.map +1 -0
  40. package/dist/chunk-OYXSKQFR.js +553 -0
  41. package/dist/chunk-OYXSKQFR.js.map +1 -0
  42. package/dist/chunk-TVRC4KVT.cjs +1367 -0
  43. package/dist/chunk-TVRC4KVT.cjs.map +1 -0
  44. package/dist/chunk-U6NDQFOK.cjs +2706 -0
  45. package/dist/chunk-U6NDQFOK.cjs.map +1 -0
  46. package/dist/controller-OUdxPY-X.d.cts +754 -0
  47. package/dist/controller-OUdxPY-X.d.ts +754 -0
  48. package/dist/extensions/index.cjs +144 -3
  49. package/dist/extensions/index.cjs.map +1 -1
  50. package/dist/extensions/index.d.cts +9 -144
  51. package/dist/extensions/index.d.ts +9 -144
  52. package/dist/extensions/index.js +145 -4
  53. package/dist/grammar/index.cjs +31 -3
  54. package/dist/grammar/index.cjs.map +1 -1
  55. package/dist/grammar/index.d.cts +239 -19
  56. package/dist/grammar/index.d.ts +239 -19
  57. package/dist/grammar/index.js +31 -3
  58. package/dist/history/index.d.cts +2 -41
  59. package/dist/history/index.d.ts +2 -41
  60. package/dist/index-Ng1pG7JE.d.ts +899 -0
  61. package/dist/index-k3mFbPx_.d.cts +899 -0
  62. package/dist/index.cjs +457 -20
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +99 -12
  65. package/dist/index.d.ts +99 -12
  66. package/dist/index.js +457 -20
  67. package/dist/index.js.map +1 -1
  68. package/dist/registry-iAHbqkYt.d.cts +128 -0
  69. package/dist/registry-iAHbqkYt.d.ts +128 -0
  70. package/dist/serializers/index.cjs +26 -3
  71. package/dist/serializers/index.cjs.map +1 -1
  72. package/dist/serializers/index.d.cts +119 -6
  73. package/dist/serializers/index.d.ts +119 -6
  74. package/dist/serializers/index.js +24 -1
  75. package/dist/spreadsheet/index.cjs +122 -2
  76. package/dist/spreadsheet/index.cjs.map +1 -1
  77. package/dist/spreadsheet/index.d.cts +371 -313
  78. package/dist/spreadsheet/index.d.ts +371 -313
  79. package/dist/spreadsheet/index.js +127 -7
  80. package/dist/tokens-CyLZmIei.d.cts +76 -0
  81. package/dist/tokens-CyLZmIei.d.ts +76 -0
  82. package/dist/track-changes-G8JcWB8b.d.cts +306 -0
  83. package/dist/track-changes-G8JcWB8b.d.ts +306 -0
  84. package/dist/types-BZgcDsC5.d.cts +42 -0
  85. package/dist/types-BZgcDsC5.d.ts +42 -0
  86. package/dist/{types-JV3S8VeR.d.cts → types-DMe0vFB1.d.cts} +1 -1
  87. package/dist/{types-JV3S8VeR.d.ts → types-DMe0vFB1.d.ts} +1 -1
  88. package/package.json +11 -4
  89. package/dist/chunk-7FWEWE6T.js +0 -1888
  90. package/dist/chunk-7FWEWE6T.js.map +0 -1
  91. package/dist/chunk-AIZUKWTL.js +0 -1715
  92. package/dist/chunk-AIZUKWTL.js.map +0 -1
  93. package/dist/chunk-GLSIZKOX.js +0 -17
  94. package/dist/chunk-GLSIZKOX.js.map +0 -1
  95. package/dist/chunk-LDES3EOS.cjs +0 -1888
  96. package/dist/chunk-LDES3EOS.cjs.map +0 -1
  97. package/dist/chunk-LLUAKTLW.cjs +0 -532
  98. package/dist/chunk-LLUAKTLW.cjs.map +0 -1
  99. package/dist/chunk-MPPXH7U5.cjs +0 -336
  100. package/dist/chunk-MPPXH7U5.cjs.map +0 -1
  101. package/dist/chunk-O7LOPQMH.js +0 -336
  102. package/dist/chunk-O7LOPQMH.js.map +0 -1
  103. package/dist/chunk-QGVMBCT5.js +0 -532
  104. package/dist/chunk-QGVMBCT5.js.map +0 -1
  105. package/dist/chunk-SEDR75VH.cjs +0 -17
  106. package/dist/chunk-SEDR75VH.cjs.map +0 -1
  107. package/dist/chunk-YQCI4CCN.cjs +0 -1715
  108. package/dist/chunk-YQCI4CCN.cjs.map +0 -1
  109. package/dist/mention-Dcevh3ff.d.cts +0 -32
  110. package/dist/mention-Dcevh3ff.d.ts +0 -32
  111. package/dist/tokens-7kRTEtPb.d.cts +0 -39
  112. package/dist/tokens-7kRTEtPb.d.ts +0 -39
@@ -1,5 +1,6 @@
1
- import { R as Rect, C as CanvasNode, X as XYPosition, a as CanvasEdge, I as IncrementalLayoutOptions, S as Side, b as CanvasLayoutOptions, P as PlaceBesideOptions, T as TrajectoryFunction, F as FanOutTrajectoryOptions, N as NodeTransition, c as CanvasNodeStyle, d as ReflowDisplacementOptions, D as DirectionalDisplacementOptions, e as CanvasClipboardPayload } from '../types-JV3S8VeR.js';
2
- export { f as CanvasDockingCallbacks, g as CollapseNodeOptions, h as DisplacementDirection, i as DockStrategy, E as ExplodeNodeOptions, j as ExplosionSnapshot, G as GraphDifferences, k as Point, l as Position, m as TrajectoryPoint } from '../types-JV3S8VeR.js';
1
+ import { R as Rect, C as CanvasNode, X as XYPosition, a as CanvasEdge, I as IncrementalLayoutOptions, S as Side, b as CanvasLayoutOptions, P as PlaceBesideOptions, T as TrajectoryFunction, F as FanOutTrajectoryOptions, N as NodeTransition, c as CanvasNodeStyle, d as ReflowDisplacementOptions, D as DirectionalDisplacementOptions, e as CanvasClipboardPayload, f as Position } from '../types-DMe0vFB1.js';
2
+ export { g as CanvasDockingCallbacks, h as CollapseNodeOptions, i as DisplacementDirection, j as DockStrategy, E as ExplodeNodeOptions, k as ExplosionSnapshot, G as GraphDifferences, l as Point, m as TrajectoryPoint } from '../types-DMe0vFB1.js';
3
+ import { C as Command } from '../types-BZgcDsC5.js';
3
4
 
4
5
  declare const DEFAULT_NODE_WIDTH = 200;
5
6
  declare const DEFAULT_NODE_HEIGHT = 60;
@@ -327,4 +328,515 @@ declare function blendLayout<TNode extends CanvasNode = CanvasNode>(from: TNode[
327
328
  */
328
329
  declare function connectedOnly<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(nodes: TNode[], edges: TEdge[]): TNode[];
329
330
 
330
- export { CanvasClipboardPayload, CanvasEdge, type CanvasHeightOptions, CanvasLayoutOptions, CanvasNode, CanvasNodeStyle, type Clock, DEFAULT_NODE_HEIGHT, DEFAULT_NODE_WIDTH, DEFAULT_PLACEMENT_GAP, DirectionalDisplacementOptions, FanOutTrajectoryOptions, IncrementalLayoutOptions, ManualClock, type MultiNodeTransitionOptions, NodeTransition, PlaceBesideOptions, Rect, ReflowDisplacementOptions, Side, StreamingLayoutManager, type StreamingLayoutManagerOptions, TrajectoryFunction, XYPosition, blendLayout, boundsOf, calculateDagreReflowDisplacement, calculateDirectionalDisplacement, canvasHeight, centerNodes, centre, computeNodesBoundingBox, connectedOnly, createBezierTrajectory, createFanOutTrajectory, defaultEasing, ensureLayout, estimateCanvasHeight, estimateNodeSize, flowSide, getCenteredNodePosition, getLayoutedNodes, isEventFromTextInput, isValidCanvasEdge, isValidCanvasNode, isValidUrl, layoutBounds, linearPositionTrajectory, linearTrajectory, overlaps, pageHidden, parseCanvasClipboardData, placeBeside, realClock, remapPastedNodes, repositionNodesTo, runMultiNodeTransition, serializeCanvasNodes, withStyleOpacity };
331
+ /**
332
+ * Edge (or centre line) used by `alignNodes`.
333
+ * `center` aligns horizontal centres (a vertical line); `middle` aligns vertical centres.
334
+ */
335
+ type AlignEdge = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
336
+ /** Axis used by `distributeNodes`. `both` distributes horizontally and vertically. */
337
+ type DistributeAxis = 'horizontal' | 'vertical' | 'both';
338
+ /**
339
+ * `gaps` leaves equal space between neighbouring nodes, `centres` spaces their centres equally.
340
+ */
341
+ type DistributeMode = 'gaps' | 'centres';
342
+ /** Dimension(s) copied by `matchSize`. */
343
+ type SizeDimension = 'width' | 'height' | 'both';
344
+ /**
345
+ * Partial node change produced by the arrange helpers. `position` is in the node's own
346
+ * coordinate space (relative to its `parentId` parent when it has one).
347
+ */
348
+ interface CanvasNodeUpdate {
349
+ id: string;
350
+ position?: XYPosition;
351
+ width?: number;
352
+ height?: number;
353
+ zIndex?: number;
354
+ }
355
+ interface NodeRectOptions {
356
+ /** Width used when a node has no measured, explicit or style size and estimation is off. */
357
+ defaultWidth?: number;
358
+ /** Height used when a node has no measured, explicit or style size and estimation is off. */
359
+ defaultHeight?: number;
360
+ /** Estimate unmeasured node sizes from their label via `estimateNodeSize` (default `true`). */
361
+ estimate?: boolean;
362
+ }
363
+ /** Data key marking a node as locked. See `lockNodes`. */
364
+ declare const LOCKED_DATA_KEY = "locked";
365
+ /** Data key holding the interaction flags a node had before it was locked. */
366
+ declare const LOCKED_PREVIOUS_FLAGS_KEY = "lockedPrevious";
367
+ /**
368
+ * Reads a pixel `width` / `height` from a node style, which may be a CSS string (SvelteFlow)
369
+ * or a style object (React Flow). Non-pixel values (`%`, `auto`, ...) are ignored.
370
+ */
371
+ declare function readStyleSize(style: CanvasNodeStyle | undefined | null): {
372
+ width?: number;
373
+ height?: number;
374
+ };
375
+ /**
376
+ * Returns `style` with its pixel `width` / `height` replaced, keeping its representation
377
+ * (string or object). Only dimensions already present in the style are rewritten, because
378
+ * xyflow applies the node's own `width` / `height` props otherwise.
379
+ */
380
+ declare function withStyleSize(style: CanvasNodeStyle | undefined | null, size: {
381
+ width?: number;
382
+ height?: number;
383
+ }): CanvasNodeStyle | undefined;
384
+ /**
385
+ * Resolves a node's size: measured DOM size, then explicit `width` / `height`, then a pixel
386
+ * size in `style`, then a label-based estimate (or the defaults when `estimate` is `false`).
387
+ */
388
+ declare function getNodeSize(node: CanvasNode, options?: NodeRectOptions): {
389
+ width: number;
390
+ height: number;
391
+ };
392
+ /**
393
+ * Absolute (flow-space) position of a node, following its `parentId` chain.
394
+ * Cycles and missing parents are tolerated.
395
+ */
396
+ declare function getAbsolutePosition(node: CanvasNode, lookup: ReadonlyMap<string, CanvasNode>): XYPosition;
397
+ /** Builds an id lookup for a node array. */
398
+ declare function createNodeLookup<TNode extends CanvasNode>(nodes: TNode[]): Map<string, TNode>;
399
+ /** Absolute flow-space rectangle of a node. */
400
+ declare function getNodeRect(node: CanvasNode, lookup?: ReadonlyMap<string, CanvasNode>, options?: NodeRectOptions): Rect;
401
+ /**
402
+ * Whether a node has been locked with `lockNodes`.
403
+ */
404
+ declare function isLocked(node: CanvasNode | undefined | null): boolean;
405
+ /**
406
+ * Locks nodes: marks `data.locked = true` and sets `draggable: false` and `deletable: false`
407
+ * so both SvelteFlow and React Flow stop dragging and deleting them. Nodes stay `selectable`
408
+ * so they can be unlocked again. The previous flags are kept in `data.lockedPrevious` and
409
+ * restored by `unlockNodes`. Returns a new array; untouched nodes keep their identity.
410
+ */
411
+ declare function lockNodes<TNode extends CanvasNode>(nodes: TNode[], ids: Iterable<string>): TNode[];
412
+ /**
413
+ * Reverses `lockNodes`, restoring the `draggable` / `deletable` flags the node had before.
414
+ */
415
+ declare function unlockNodes<TNode extends CanvasNode>(nodes: TNode[], ids: Iterable<string>): TNode[];
416
+ /** Locks the given nodes if any of them is unlocked, otherwise unlocks them all. */
417
+ declare function toggleLockNodes<TNode extends CanvasNode>(nodes: TNode[], ids: Iterable<string>): TNode[];
418
+ interface AlignNodesOptions extends NodeRectOptions {
419
+ /**
420
+ * What to align to: the selection bounding box (default) or a fixed rectangle.
421
+ * Locked nodes never move but still count towards the selection bounds, so they act as anchors.
422
+ */
423
+ to?: 'selection' | Rect;
424
+ }
425
+ /**
426
+ * Aligns nodes to a shared edge or centre line of their bounding box (Freeform's
427
+ * Align Left / Center / Right / Top / Middle / Bottom). Needs at least two nodes unless
428
+ * `options.to` is a rectangle. Locked nodes are not moved.
429
+ */
430
+ declare function alignNodes(nodes: CanvasNode[], ids: Iterable<string>, edge: AlignEdge, options?: AlignNodesOptions): CanvasNodeUpdate[];
431
+ interface DistributeNodesOptions extends NodeRectOptions {
432
+ /** Explicit gap between neighbours for `gaps` mode. Default: spread evenly between the outer nodes. */
433
+ gap?: number;
434
+ }
435
+ /**
436
+ * Distributes nodes along an axis (Freeform's Distribute Horizontally / Vertically / Evenly).
437
+ * The outermost nodes stay put and the others are spaced with equal gaps (`gaps`, default)
438
+ * or equally spaced centres (`centres`). Needs at least three nodes (two with an explicit
439
+ * `gap`). Locked nodes keep their place in the order but are not moved.
440
+ */
441
+ declare function distributeNodes(nodes: CanvasNode[], ids: Iterable<string>, axis: DistributeAxis, mode?: DistributeMode, options?: DistributeNodesOptions): CanvasNodeUpdate[];
442
+ interface MatchSizeOptions extends NodeRectOptions {
443
+ /**
444
+ * Size source: the `largest` (default) or `smallest` node, the `first` id given,
445
+ * or a specific node id.
446
+ */
447
+ reference?: 'largest' | 'smallest' | 'first' | {
448
+ id: string;
449
+ };
450
+ /** Keep each node's centre in place instead of its top-left corner (default `false`). */
451
+ keepCentre?: boolean;
452
+ }
453
+ /**
454
+ * Makes nodes the same width, height or both (Freeform's Make Same Size). Returns size
455
+ * updates (plus position updates with `keepCentre`). Locked nodes are not resized but can
456
+ * be the reference.
457
+ */
458
+ declare function matchSize(nodes: CanvasNode[], ids: Iterable<string>, dimension: SizeDimension, options?: MatchSizeOptions): CanvasNodeUpdate[];
459
+ /** Z-order operation. */
460
+ type ZOrderOperation = 'bringForward' | 'sendBackward' | 'bringToFront' | 'sendToBack';
461
+ /**
462
+ * Restacks nodes (Bring Forward / Send Backward / Bring to Front / Send to Back).
463
+ *
464
+ * Both SvelteFlow and React Flow stack nodes by `zIndex` (missing = 0) and, for equal
465
+ * `zIndex`, by array order. This computes that effective order for the siblings that share
466
+ * the targets' parent, applies the operation, and returns `zIndex` updates assigning each
467
+ * sibling its new rank. The array order is left alone, because xyflow requires parents to
468
+ * precede their children. Locked nodes are not restacked. "Forward" moves past the next
469
+ * sibling the node overlaps, falling back to the next sibling when nothing overlaps.
470
+ */
471
+ declare function reorderNodes(nodes: CanvasNode[], ids: Iterable<string>, operation: ZOrderOperation, options?: NodeRectOptions): CanvasNodeUpdate[];
472
+ /**
473
+ * Applies `CanvasNodeUpdate`s to a node array, returning a new array. Unchanged nodes keep
474
+ * their identity. Size updates set `width` / `height` and rewrite pixel sizes already present
475
+ * in `style` (string or object). An existing `measured` size is updated too, so geometry
476
+ * helpers see the new size before xyflow re-measures the node.
477
+ */
478
+ declare function applyNodeUpdates<TNode extends CanvasNode>(nodes: TNode[], updates: CanvasNodeUpdate[]): TNode[];
479
+ /**
480
+ * Inverse of a set of updates against the current nodes, for undo. Restores the previous
481
+ * position / size / zIndex of every node an update touches.
482
+ */
483
+ declare function invertNodeUpdates(nodes: CanvasNode[], updates: CanvasNodeUpdate[]): CanvasNodeUpdate[];
484
+
485
+ /**
486
+ * A guide line to render while dragging, in flow coordinates.
487
+ * `edge` and `centre` guides are alignment lines; `spacing` guides mark equal gaps.
488
+ */
489
+ interface GuideLine {
490
+ orientation: 'vertical' | 'horizontal';
491
+ kind: 'edge' | 'centre' | 'spacing';
492
+ x1: number;
493
+ y1: number;
494
+ x2: number;
495
+ y2: number;
496
+ }
497
+ interface SnapGuidesOptions {
498
+ /** Current viewport zoom; the threshold is in screen pixels and divided by it (default 1). */
499
+ zoom?: number;
500
+ /** Snap distance in screen pixels (default 6). */
501
+ threshold?: number;
502
+ /** Snap edges to other shapes' edges (default `true`). */
503
+ edges?: boolean;
504
+ /** Snap centres to other shapes' centres (default `true`). */
505
+ centres?: boolean;
506
+ /** Snap to equal spacing between neighbouring shapes in the same row / column (default `true`). */
507
+ spacing?: boolean;
508
+ }
509
+ interface SnapResult {
510
+ /** Snapped top-left of the moving rectangle. */
511
+ position: XYPosition;
512
+ /** Offset applied to the input rectangle (`position - rect`). */
513
+ offset: XYPosition;
514
+ /** Guide segments to draw for the snap that was applied. */
515
+ guides: GuideLine[];
516
+ snappedX: boolean;
517
+ snappedY: boolean;
518
+ }
519
+ interface AxisEntries {
520
+ values: Float64Array;
521
+ rects: Rect[];
522
+ }
523
+ /**
524
+ * Pre-sorted snap targets for a set of static rectangles. Build it once when a drag starts
525
+ * and reuse it on every pointer move; each query is a binary search, so snapping stays
526
+ * cheap with hundreds or thousands of shapes.
527
+ */
528
+ interface GuideIndex {
529
+ rects: Rect[];
530
+ edgeX: AxisEntries;
531
+ centreX: AxisEntries;
532
+ edgeY: AxisEntries;
533
+ centreY: AxisEntries;
534
+ }
535
+ /** Builds a `GuideIndex` from the rectangles the moving shape may snap to. */
536
+ declare function createGuideIndex(rects: Rect[]): GuideIndex;
537
+ /**
538
+ * Computes smart-guide snapping for a moving rectangle (a dragged node or a selection's
539
+ * bounding box) against other shapes. Edges snap to edges and centres to centres within
540
+ * `threshold` screen pixels (converted to flow units via `zoom`). Each axis snaps
541
+ * independently to its nearest candidate. Returns the snapped position and the guides to draw.
542
+ */
543
+ declare function computeSnapGuides(moving: Rect, targets: Rect[] | GuideIndex, options?: SnapGuidesOptions): SnapResult;
544
+ /** Ids of the given nodes plus every descendant (children move with their parent). */
545
+ declare function collectDescendantIds(nodes: CanvasNode[], ids: Iterable<string>): Set<string>;
546
+ /**
547
+ * Builds a `GuideIndex` of every node except the dragged ones and their descendants.
548
+ * Call once at drag start and pass it to `snapNodeDrag` on every move.
549
+ */
550
+ declare function createNodeGuideIndex(nodes: CanvasNode[], draggingIds: Iterable<string>, options?: NodeRectOptions & {
551
+ filter?: (node: CanvasNode) => boolean;
552
+ }): GuideIndex;
553
+ interface SnapNodeDragOptions extends SnapGuidesOptions, NodeRectOptions {
554
+ /** Index from `createNodeGuideIndex`, reused across drag frames. Built on demand when omitted. */
555
+ index?: GuideIndex;
556
+ }
557
+ interface SnapNodeDragResult extends SnapResult {
558
+ /** Position updates moving every dragged node by `offset` (node-relative coordinates). */
559
+ updates: CanvasNodeUpdate[];
560
+ }
561
+ /**
562
+ * Snaps a drag of one or more nodes. The dragged nodes' bounding box is snapped against all
563
+ * other nodes; the resulting offset is applied to each dragged node. Dragged nodes whose
564
+ * parent is also dragged are skipped, because they move with the parent.
565
+ */
566
+ declare function snapNodeDrag(nodes: CanvasNode[], draggingIds: Iterable<string>, options?: SnapNodeDragOptions): SnapNodeDragResult;
567
+
568
+ /**
569
+ * Connection line styles supported by both SvelteFlow and React Flow
570
+ * (`connectionLineType` / edge `type`).
571
+ */
572
+ type CanvasConnectionLineType = 'default' | 'straight' | 'step' | 'smoothstep' | 'simplebezier';
573
+ declare const CONNECTION_LINE_TYPES: readonly CanvasConnectionLineType[];
574
+ /** Maps a handle `Position` to the placement `Side` vocabulary used by `placeBeside`. */
575
+ declare function positionToSide(position: Position): Side;
576
+ /** Maps a placement `Side` to the handle `Position` vocabulary used by xyflow. */
577
+ declare function sideToPosition(side: Side): Position;
578
+ /** The handle position facing the other way. */
579
+ declare function oppositePosition(position: Position): Position;
580
+ /** Midpoint of a rectangle's side, where a centred handle sits. */
581
+ declare function handlePoint(rect: Rect, position: Position): XYPosition;
582
+ interface ConnectorSnapTarget {
583
+ id: string;
584
+ rect: Rect;
585
+ /** Sides that can accept a connection (default: all four). */
586
+ positions?: Position[];
587
+ }
588
+ interface ConnectorSnapOptions {
589
+ /** Viewport zoom; `radius` is in screen pixels and divided by it (default 1). */
590
+ zoom?: number;
591
+ /** How far outside a shape the pointer may be and still attach, in screen pixels (default 24). */
592
+ radius?: number;
593
+ /** Node ids that cannot be attached to, e.g. the connection's source node. */
594
+ excludeIds?: Iterable<string>;
595
+ /**
596
+ * `handle` snaps to the side's midpoint (a centred handle, default). `edge` snaps to the
597
+ * closest point along that side, for floating edges.
598
+ */
599
+ mode?: 'handle' | 'edge';
600
+ }
601
+ interface ConnectorSnap {
602
+ nodeId: string;
603
+ position: Position;
604
+ side: Side;
605
+ /** Attachment point in flow coordinates. */
606
+ point: XYPosition;
607
+ /** Distance from the pointer to `point`, in flow units. */
608
+ distance: number;
609
+ }
610
+ /**
611
+ * Finds the shape side a connection line should attach to for a pointer (flow coordinates).
612
+ * Shapes the pointer is inside win over shapes it is merely near; among those, the closest
613
+ * allowed side wins. Returns `null` when nothing is within `radius`.
614
+ */
615
+ declare function findConnectorSnap(pointer: XYPosition, targets: ConnectorSnapTarget[], options?: ConnectorSnapOptions): ConnectorSnap | null;
616
+ /**
617
+ * Picks the facing sides for a connection between two shapes, the way Freeform attaches
618
+ * connection lines: along the axis with the larger centre offset.
619
+ */
620
+ declare function nearestHandlePositions(source: Rect, target: Rect): {
621
+ source: Position;
622
+ target: Position;
623
+ };
624
+
625
+ /**
626
+ * Viewport transform in xyflow's convention: `screen = flow * zoom + (x, y)`.
627
+ */
628
+ interface CanvasViewport {
629
+ x: number;
630
+ y: number;
631
+ zoom: number;
632
+ }
633
+ /**
634
+ * A named, saved view of the canvas (Freeform "Scenes").
635
+ */
636
+ interface CanvasScene {
637
+ id: string;
638
+ name: string;
639
+ viewport: CanvasViewport;
640
+ /** Optional nodes the scene is about, e.g. to re-fit the scene after they move. */
641
+ nodeIds?: string[];
642
+ }
643
+ interface CanvasScenesState {
644
+ scenes: readonly CanvasScene[];
645
+ /** Id of the scene last shown, or `null`. */
646
+ currentId: string | null;
647
+ /** Index of the current scene, or `-1`. */
648
+ currentIndex: number;
649
+ }
650
+ interface CanvasScenesOptions {
651
+ initialScenes?: CanvasScene[];
652
+ /** Id generator for new scenes (default: `crypto.randomUUID` with a counter fallback). */
653
+ createId?: () => string;
654
+ /** Whether `next` / `previous` wrap around at the ends (default `false`). */
655
+ wrap?: boolean;
656
+ onChange?: (state: CanvasScenesState) => void;
657
+ }
658
+ interface SerializedCanvasScenes {
659
+ version: 1;
660
+ scenes: CanvasScene[];
661
+ }
662
+ /** Validates the shape of a scene. */
663
+ declare function isValidCanvasScene(value: unknown): value is CanvasScene;
664
+ /**
665
+ * Parses serialized scenes (a JSON string, a `{ version, scenes }` object or a bare array).
666
+ * Invalid entries and duplicate ids are dropped.
667
+ */
668
+ declare function parseCanvasScenes(input: string | unknown): CanvasScene[];
669
+ /**
670
+ * Headless, framework-agnostic store of named viewports. Snapshots returned by `getState()`
671
+ * are cached and only replaced on change, so it can back React's `useSyncExternalStore`.
672
+ */
673
+ declare class CanvasScenesStore {
674
+ private scenes;
675
+ private currentId;
676
+ private cached;
677
+ private listeners;
678
+ private readonly createId;
679
+ private readonly onChange?;
680
+ wrap: boolean;
681
+ constructor(options?: CanvasScenesOptions);
682
+ private snapshot;
683
+ private commit;
684
+ getState(): CanvasScenesState;
685
+ getScene(id: string): CanvasScene | undefined;
686
+ subscribe(listener: (state: CanvasScenesState) => void): () => void;
687
+ /** First unused "Scene N" name. */
688
+ nextDefaultName(): string;
689
+ /**
690
+ * Adds a scene (appended, or inserted at `index`) and makes it current.
691
+ */
692
+ add(input: {
693
+ viewport: CanvasViewport;
694
+ name?: string;
695
+ nodeIds?: string[];
696
+ id?: string;
697
+ }, index?: number): CanvasScene;
698
+ /** Patches a scene's name, viewport or node ids. Returns the updated scene. */
699
+ update(id: string, patch: Partial<Omit<CanvasScene, 'id'>>): CanvasScene | undefined;
700
+ rename(id: string, name: string): CanvasScene | undefined;
701
+ /** Moves a scene to `toIndex` (clamped). */
702
+ move(id: string, toIndex: number): void;
703
+ /** Reorders scenes to match `ids`; unknown ids are ignored and missing scenes keep their relative order at the end. */
704
+ reorder(ids: string[]): void;
705
+ remove(id: string): void;
706
+ clear(): void;
707
+ /** Marks a scene as current and returns it. */
708
+ goTo(id: string): CanvasScene | undefined;
709
+ private step;
710
+ /** Shows the next scene. Returns `undefined` at the end unless `wrap` is on. */
711
+ next(): CanvasScene | undefined;
712
+ /** Shows the previous scene. Returns `undefined` at the start unless `wrap` is on. */
713
+ previous(): CanvasScene | undefined;
714
+ toJSON(): SerializedCanvasScenes;
715
+ serialize(): string;
716
+ /** Replaces all scenes from serialized data (see `parseCanvasScenes`). */
717
+ load(input: string | unknown): void;
718
+ }
719
+ declare function createCanvasScenesStore(options?: CanvasScenesOptions): CanvasScenesStore;
720
+ interface FitViewportOptions {
721
+ /** Padding around the content as a fraction of the content size per side (default 0.1, like xyflow). */
722
+ padding?: number;
723
+ minZoom?: number;
724
+ maxZoom?: number;
725
+ }
726
+ /**
727
+ * Viewport that fits `rect` into a container of `size`, centred (xyflow `fitView` maths).
728
+ */
729
+ declare function fitViewportToRect(rect: Rect, size: {
730
+ width: number;
731
+ height: number;
732
+ }, options?: FitViewportOptions): CanvasViewport;
733
+ /**
734
+ * Viewport that fits the given nodes (all nodes when `ids` is omitted), or `null` when none match.
735
+ */
736
+ declare function fitViewportToNodes(nodes: CanvasNode[], size: {
737
+ width: number;
738
+ height: number;
739
+ }, ids?: Iterable<string>, options?: FitViewportOptions & NodeRectOptions): CanvasViewport | null;
740
+
741
+ /**
742
+ * Canvas arrangement actions that have keyboard shortcuts.
743
+ */
744
+ type CanvasArrangeAction = 'alignLeft' | 'alignCenter' | 'alignRight' | 'alignTop' | 'alignMiddle' | 'alignBottom' | 'distributeHorizontal' | 'distributeVertical' | 'lock' | 'unlock' | 'bringForward' | 'sendBackward' | 'bringToFront' | 'sendToBack' | 'nextScene' | 'previousScene';
745
+ interface ArrangeShortcutBinding {
746
+ action: CanvasArrangeAction;
747
+ /** `KeyboardEvent.code` (layout- and Option-independent, e.g. `KeyA`, `BracketRight`). */
748
+ code: string;
749
+ mod?: boolean;
750
+ alt?: boolean;
751
+ shift?: boolean;
752
+ /** Human readable label, e.g. for menus. `Mod` is ⌘ on macOS and Ctrl elsewhere. */
753
+ label: string;
754
+ }
755
+ /**
756
+ * Default bindings. Align/distribute follow Figma (Option/Alt + letter), layer order follows
757
+ * the common `Mod+]` / `Mod+[` convention, lock follows Keynote/Freeform (`Mod+L`,
758
+ * `Mod+Alt+L` to unlock) and scenes step with PageDown / PageUp.
759
+ */
760
+ declare const DEFAULT_ARRANGE_SHORTCUTS: readonly ArrangeShortcutBinding[];
761
+ /**
762
+ * Resolves a keydown event to an arrange action, or `null`. Events from text inputs,
763
+ * textareas, selects, contenteditable and ProseMirror are ignored (see `isEventFromTextInput`).
764
+ * `Mod` is ⌘ or Ctrl.
765
+ */
766
+ declare function matchArrangeShortcut(event: KeyboardEvent, bindings?: readonly ArrangeShortcutBinding[]): CanvasArrangeAction | null;
767
+
768
+ /** Minimal history surface (`HistoryManager` satisfies it). */
769
+ interface ArrangeHistoryTarget {
770
+ execute(command: Command): void;
771
+ }
772
+ interface CanvasArrangeControllerOptions<TNode extends CanvasNode = CanvasNode> {
773
+ getNodes: () => TNode[];
774
+ setNodes: (nodes: TNode[]) => void;
775
+ /** Ids acted on when a method is called without ids (default: nodes with `selected: true`). */
776
+ getSelectedIds?: () => string[];
777
+ /** When set, every arrange action is recorded as one undoable command. */
778
+ history?: ArrangeHistoryTarget;
779
+ /** Current zoom, used to convert the guide threshold from screen pixels (default 1). */
780
+ getZoom?: () => number;
781
+ /** Smart-guide options (threshold in screen px, edges / centres / spacing toggles). */
782
+ guides?: Omit<SnapGuidesOptions, 'zoom'>;
783
+ /** Turns drag snapping off while keeping the arrange actions (default `true`). */
784
+ snapping?: boolean;
785
+ /** Size resolution for unmeasured nodes. */
786
+ rectOptions?: NodeRectOptions;
787
+ /** Called whenever the guide segments change (set while dragging, cleared on drop). */
788
+ onGuidesChange?: (guides: GuideLine[]) => void;
789
+ }
790
+ /** A React Flow / SvelteFlow style node change; only `position` changes are inspected. */
791
+ interface PositionChangeLike {
792
+ type: string;
793
+ id: string;
794
+ position?: XYPosition;
795
+ dragging?: boolean;
796
+ [key: string]: any;
797
+ }
798
+ /**
799
+ * Framework-agnostic arrange controller shared by the Svelte rune and the React hook:
800
+ * align / distribute / match size / lock / z-order actions on the selection (optionally
801
+ * undoable through a `HistoryManager`) and smart-guide snapping during drags.
802
+ */
803
+ declare function createCanvasArrangeController<TNode extends CanvasNode = CanvasNode>(options: CanvasArrangeControllerOptions<TNode>): {
804
+ readonly guides: GuideLine[];
805
+ apply: (name: string, updates: CanvasNodeUpdate[]) => CanvasNodeUpdate[];
806
+ align(edge: AlignEdge, ids?: Iterable<string>, alignOptions?: AlignNodesOptions): CanvasNodeUpdate[];
807
+ distribute(axis: DistributeAxis, mode?: DistributeMode, ids?: Iterable<string>, distributeOptions?: DistributeNodesOptions): CanvasNodeUpdate[];
808
+ matchSize(dimension: SizeDimension, ids?: Iterable<string>, sizeOptions?: MatchSizeOptions): CanvasNodeUpdate[];
809
+ reorder(operation: ZOrderOperation, ids?: Iterable<string>): CanvasNodeUpdate[];
810
+ bringForward: (ids?: Iterable<string>) => CanvasNodeUpdate[];
811
+ sendBackward: (ids?: Iterable<string>) => CanvasNodeUpdate[];
812
+ bringToFront: (ids?: Iterable<string>) => CanvasNodeUpdate[];
813
+ sendToBack: (ids?: Iterable<string>) => CanvasNodeUpdate[];
814
+ lock: (ids?: Iterable<string>) => string[];
815
+ unlock: (ids?: Iterable<string>) => string[];
816
+ toggleLock(ids?: Iterable<string>): string[];
817
+ isLocked: (id: string) => boolean;
818
+ /**
819
+ * Runs a shortcut action. Scene actions are not handled here (see the scenes store);
820
+ * returns `false` for them and for unknown actions.
821
+ */
822
+ runAction(action: CanvasArrangeAction): boolean;
823
+ /** Caches the snap targets for a drag. Optional: `drag` builds them lazily. */
824
+ beginDrag(ids?: Iterable<string>): void;
825
+ /**
826
+ * Snaps the dragged nodes (as currently positioned in `getNodes()`) to the other
827
+ * nodes, writes the snapped positions back through `setNodes` (not recorded in
828
+ * history) and updates `guides`.
829
+ */
830
+ drag(ids?: Iterable<string>): SnapNodeDragResult | null;
831
+ /**
832
+ * React Flow style: adjusts dragging `position` changes in an `onNodesChange` batch so
833
+ * the dragged nodes snap, and updates `guides`. Returns the (possibly new) changes array.
834
+ * A batch without a dragging position change ends the drag and clears the guides.
835
+ */
836
+ snapPositionChanges<TChange extends PositionChangeLike>(changes: TChange[]): TChange[];
837
+ /** Clears guides and the cached snap targets. */
838
+ endDrag(): void;
839
+ };
840
+ type CanvasArrangeController<TNode extends CanvasNode = CanvasNode> = ReturnType<typeof createCanvasArrangeController<TNode>>;
841
+
842
+ export { type AlignEdge, type AlignNodesOptions, type ArrangeHistoryTarget, type ArrangeShortcutBinding, CONNECTION_LINE_TYPES, type CanvasArrangeAction, type CanvasArrangeController, type CanvasArrangeControllerOptions, CanvasClipboardPayload, type CanvasConnectionLineType, CanvasEdge, type CanvasHeightOptions, CanvasLayoutOptions, CanvasNode, CanvasNodeStyle, type CanvasNodeUpdate, type CanvasScene, type CanvasScenesOptions, type CanvasScenesState, CanvasScenesStore, type CanvasViewport, type Clock, type ConnectorSnap, type ConnectorSnapOptions, type ConnectorSnapTarget, DEFAULT_ARRANGE_SHORTCUTS, DEFAULT_NODE_HEIGHT, DEFAULT_NODE_WIDTH, DEFAULT_PLACEMENT_GAP, DirectionalDisplacementOptions, type DistributeAxis, type DistributeMode, type DistributeNodesOptions, FanOutTrajectoryOptions, type FitViewportOptions, type GuideIndex, type GuideLine, IncrementalLayoutOptions, LOCKED_DATA_KEY, LOCKED_PREVIOUS_FLAGS_KEY, ManualClock, type MatchSizeOptions, type MultiNodeTransitionOptions, type NodeRectOptions, NodeTransition, PlaceBesideOptions, Position, type PositionChangeLike, Rect, ReflowDisplacementOptions, type SerializedCanvasScenes, Side, type SizeDimension, type SnapGuidesOptions, type SnapNodeDragOptions, type SnapNodeDragResult, type SnapResult, StreamingLayoutManager, type StreamingLayoutManagerOptions, TrajectoryFunction, XYPosition, type ZOrderOperation, alignNodes, applyNodeUpdates, blendLayout, boundsOf, calculateDagreReflowDisplacement, calculateDirectionalDisplacement, canvasHeight, centerNodes, centre, collectDescendantIds, computeNodesBoundingBox, computeSnapGuides, connectedOnly, createBezierTrajectory, createCanvasArrangeController, createCanvasScenesStore, createFanOutTrajectory, createGuideIndex, createNodeGuideIndex, createNodeLookup, defaultEasing, distributeNodes, ensureLayout, estimateCanvasHeight, estimateNodeSize, findConnectorSnap, fitViewportToNodes, fitViewportToRect, flowSide, getAbsolutePosition, getCenteredNodePosition, getLayoutedNodes, getNodeRect, getNodeSize, handlePoint, invertNodeUpdates, isEventFromTextInput, isLocked, isValidCanvasEdge, isValidCanvasNode, isValidCanvasScene, isValidUrl, layoutBounds, linearPositionTrajectory, linearTrajectory, lockNodes, matchArrangeShortcut, matchSize, nearestHandlePositions, oppositePosition, overlaps, pageHidden, parseCanvasClipboardData, parseCanvasScenes, placeBeside, positionToSide, readStyleSize, realClock, remapPastedNodes, reorderNodes, repositionNodesTo, runMultiNodeTransition, serializeCanvasNodes, sideToPosition, snapNodeDrag, toggleLockNodes, unlockNodes, withStyleOpacity, withStyleSize };