@pixerate/editor 0.163.0 → 0.165.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 (159) hide show
  1. package/dist/agent/index.cjs +54 -39
  2. package/dist/agent/index.js +24 -9
  3. package/dist/animation/index.cjs +6 -5
  4. package/dist/animation/index.js +5 -4
  5. package/dist/animation-editor/index.cjs +65 -64
  6. package/dist/animation-editor/index.js +8 -7
  7. package/dist/bridge/cli.cjs +3 -3
  8. package/dist/bridge/cli.js +2 -2
  9. package/dist/bridge/index.cjs +3 -3
  10. package/dist/bridge/index.js +2 -2
  11. package/dist/canvas/displacement.d.cts +34 -2
  12. package/dist/canvas/displacement.d.ts +34 -2
  13. package/dist/canvas/explosion-tools.d.cts +43 -0
  14. package/dist/canvas/explosion-tools.d.ts +43 -0
  15. package/dist/canvas/explosionLayout.d.cts +50 -0
  16. package/dist/canvas/explosionLayout.d.ts +50 -0
  17. package/dist/canvas/explosionState.d.cts +52 -0
  18. package/dist/canvas/explosionState.d.ts +52 -0
  19. package/dist/canvas/index.cjs +512 -168
  20. package/dist/canvas/index.d.cts +3 -0
  21. package/dist/canvas/index.d.ts +3 -0
  22. package/dist/canvas/index.js +434 -90
  23. package/dist/canvas/types.d.cts +27 -2
  24. package/dist/canvas/types.d.ts +27 -2
  25. package/dist/chart/controller.d.cts +31 -2
  26. package/dist/chart/controller.d.ts +31 -2
  27. package/dist/chart/index.cjs +504 -132
  28. package/dist/chart/index.d.cts +2 -0
  29. package/dist/chart/index.d.ts +2 -0
  30. package/dist/chart/index.js +386 -14
  31. package/dist/chart/layout-families.d.cts +7 -0
  32. package/dist/chart/layout-families.d.ts +7 -0
  33. package/dist/chart/links.d.cts +34 -0
  34. package/dist/chart/links.d.ts +34 -0
  35. package/dist/chart/mermaid.d.cts +9 -6
  36. package/dist/chart/mermaid.d.ts +9 -6
  37. package/dist/chart/schemas.d.cts +3 -0
  38. package/dist/chart/schemas.d.ts +3 -0
  39. package/dist/chart/spec.d.cts +3 -2
  40. package/dist/chart/spec.d.ts +3 -2
  41. package/dist/chart/style.d.cts +33 -0
  42. package/dist/chart/style.d.ts +33 -0
  43. package/dist/chart/types.d.cts +24 -2
  44. package/dist/chart/types.d.ts +24 -2
  45. package/dist/{chunk-TALQONZ5.js → chunk-2J5VLJHC.js} +3 -3
  46. package/dist/{chunk-3NEZJCBY.js → chunk-2ZRN43IN.js} +340 -201
  47. package/dist/{chunk-ZVNAMTFO.cjs → chunk-3FSUJIXN.cjs} +18 -174
  48. package/dist/{chunk-RQCMSEM5.cjs → chunk-4QUUHTGJ.cjs} +2 -2
  49. package/dist/{chunk-CIPIESX4.cjs → chunk-4ZC5QJE2.cjs} +3 -3
  50. package/dist/{chunk-S6X2QRVU.cjs → chunk-5UEFBM2M.cjs} +1 -138
  51. package/dist/{chunk-YSAGBIRW.cjs → chunk-64VWWR5U.cjs} +16 -16
  52. package/dist/{chunk-QYZGBVNC.js → chunk-7272D3K2.js} +10 -8
  53. package/dist/{chunk-462WGGXX.cjs → chunk-AMX23CSN.cjs} +27 -16
  54. package/dist/{chunk-3VLOOO3G.js → chunk-BDIM6NVW.js} +1 -1
  55. package/dist/{chunk-POR54B55.js → chunk-CRFSQWKQ.js} +4 -1
  56. package/dist/{chunk-GZ2FM3ZB.js → chunk-DKNEQX7T.js} +6 -162
  57. package/dist/{chunk-JCXMJUQO.cjs → chunk-EGZM52EO.cjs} +3 -3
  58. package/dist/{chunk-ES3UEVUT.cjs → chunk-EUIDTZNQ.cjs} +112 -110
  59. package/dist/{chunk-H3OEM3Q2.js → chunk-F6R67I3A.js} +1 -1
  60. package/dist/{chunk-5FNGLV2D.js → chunk-FEU2XVQH.js} +15 -3
  61. package/dist/{chunk-SZA42R4N.js → chunk-FRBRLKNQ.js} +154 -16
  62. package/dist/chunk-HIDFL5LQ.js +484 -0
  63. package/dist/{chunk-MKTDELCD.js → chunk-I5MRJW7B.js} +1 -1
  64. package/dist/{chunk-SDHZG5TF.js → chunk-ILP77UD6.js} +160 -2
  65. package/dist/{chunk-GKNEJ6EN.cjs → chunk-IMRXC7OA.cjs} +241 -103
  66. package/dist/chunk-KGRZMHZB.js +204 -0
  67. package/dist/{chunk-SET6KJOP.js → chunk-LPIKXPBM.js} +1 -1
  68. package/dist/{chunk-BQWGN5WH.js → chunk-M2TPMYJE.js} +1 -1
  69. package/dist/{chunk-GTELFJRE.cjs → chunk-M5GLQQWG.cjs} +2 -2
  70. package/dist/{chunk-4VU4CP7R.js → chunk-MHLU6GRJ.js} +1 -138
  71. package/dist/{chunk-D54JHQK2.cjs → chunk-MKXK6E4O.cjs} +51 -51
  72. package/dist/{chunk-DAPQGA55.js → chunk-N7NBGT2Y.js} +2 -2
  73. package/dist/chunk-O6OGNDND.js +164 -0
  74. package/dist/{chunk-22KLZZGH.cjs → chunk-ODFCS7HF.cjs} +8 -8
  75. package/dist/{chunk-PA3IMPPS.cjs → chunk-OVYQAYGH.cjs} +81 -81
  76. package/dist/{chunk-YXOW456B.js → chunk-PPEDZ5WR.js} +1 -1
  77. package/dist/{chunk-YGG7WDWT.cjs → chunk-Q25WAFTD.cjs} +21 -18
  78. package/dist/{chunk-SBQVEBSU.cjs → chunk-QO2T6KA5.cjs} +165 -67
  79. package/dist/{chunk-24M7VD6M.cjs → chunk-S4EIAIEW.cjs} +7 -7
  80. package/dist/{chunk-M4MIZPQI.cjs → chunk-SJ2CPTQC.cjs} +189 -15
  81. package/dist/chunk-TFF2GTGN.cjs +153 -0
  82. package/dist/chunk-TTCJPX4U.cjs +204 -0
  83. package/dist/{chunk-NZD2MZJC.cjs → chunk-TVQW26AV.cjs} +35 -23
  84. package/dist/{chunk-R3P2M7HU.cjs → chunk-UVXTOZ2B.cjs} +346 -207
  85. package/dist/{chunk-WI7QJA7A.cjs → chunk-UXETV2NC.cjs} +161 -3
  86. package/dist/{chunk-Z4P2RBMJ.js → chunk-V5GSY3NC.js} +101 -3
  87. package/dist/{chunk-QY4KUDMY.js → chunk-VRXXAXUT.js} +2 -2
  88. package/dist/chunk-VU6WQSMB.cjs +164 -0
  89. package/dist/{chunk-OXERWBKE.js → chunk-X5W645RI.js} +3 -3
  90. package/dist/{chunk-NHLYK3AX.js → chunk-XBQX76CT.js} +182 -8
  91. package/dist/{chunk-5AARIS3R.cjs → chunk-XCDGM7TD.cjs} +37 -37
  92. package/dist/{chunk-EVXQNQND.js → chunk-XZB3TJ6K.js} +16 -5
  93. package/dist/chunk-YBAPT7NL.js +153 -0
  94. package/dist/chunk-Z2UQYMPS.cjs +484 -0
  95. package/dist/color/index.cjs +5 -3
  96. package/dist/color/index.js +12 -10
  97. package/dist/diagram/index.cjs +55 -243
  98. package/dist/diagram/index.js +12 -200
  99. package/dist/export/index.cjs +7 -6
  100. package/dist/export/index.js +6 -5
  101. package/dist/extensions/index.cjs +12 -9
  102. package/dist/extensions/index.js +11 -8
  103. package/dist/gradient/index.cjs +29 -27
  104. package/dist/gradient/index.js +6 -4
  105. package/dist/image-editor/index.cjs +644 -643
  106. package/dist/image-editor/index.js +7 -6
  107. package/dist/index.cjs +21 -18
  108. package/dist/index.js +14 -11
  109. package/dist/paint-editor/index.cjs +19 -18
  110. package/dist/paint-editor/index.js +7 -6
  111. package/dist/parameters/index.cjs +2 -2
  112. package/dist/parameters/index.js +1 -1
  113. package/dist/persistence/assetWrites.d.cts +22 -0
  114. package/dist/persistence/assetWrites.d.ts +22 -0
  115. package/dist/persistence/assets.d.cts +71 -0
  116. package/dist/persistence/assets.d.ts +71 -0
  117. package/dist/persistence/documentStore.d.cts +17 -1
  118. package/dist/persistence/documentStore.d.ts +17 -1
  119. package/dist/persistence/documentTools.d.cts +5 -1
  120. package/dist/persistence/documentTools.d.ts +5 -1
  121. package/dist/persistence/editorAutosave.d.cts +7 -0
  122. package/dist/persistence/editorAutosave.d.ts +7 -0
  123. package/dist/persistence/index.cjs +141 -21
  124. package/dist/persistence/index.js +130 -10
  125. package/dist/persistence/storage.d.cts +13 -1
  126. package/dist/persistence/storage.d.ts +13 -1
  127. package/dist/spreadsheet/index.cjs +3 -3
  128. package/dist/spreadsheet/index.js +2 -2
  129. package/dist/tokens/index.cjs +11 -3
  130. package/dist/tokens/index.d.cts +1 -0
  131. package/dist/tokens/index.d.ts +1 -0
  132. package/dist/tokens/index.js +10 -2
  133. package/dist/tokens/style.d.cts +36 -0
  134. package/dist/tokens/style.d.ts +36 -0
  135. package/dist/tools/index.cjs +15 -3
  136. package/dist/tools/index.d.cts +2 -0
  137. package/dist/tools/index.d.ts +2 -0
  138. package/dist/tools/index.js +14 -2
  139. package/dist/tools/style-tools.d.cts +19 -0
  140. package/dist/tools/style-tools.d.ts +19 -0
  141. package/dist/tools/style.d.cts +212 -0
  142. package/dist/tools/style.d.ts +212 -0
  143. package/dist/tools/view.d.cts +6 -0
  144. package/dist/tools/view.d.ts +6 -0
  145. package/dist/typography/index.cjs +8 -6
  146. package/dist/typography/index.js +5 -3
  147. package/dist/vector/index.cjs +953 -952
  148. package/dist/vector/index.js +7 -6
  149. package/dist/video-editor/index.cjs +8 -7
  150. package/dist/video-editor/index.js +6 -5
  151. package/package.json +1 -1
  152. package/skills/README.md +12 -0
  153. package/skills/pixerate-agent-tools/SKILL.md +34 -1
  154. package/skills/pixerate-chart/SKILL.md +41 -9
  155. package/skills/pixerate-image-editor/SKILL.md +2 -0
  156. package/skills/pixerate-paint-editor/SKILL.md +2 -0
  157. package/skills/pixerate-tokens/SKILL.md +5 -0
  158. package/dist/chunk-ERAGQL2N.cjs +0 -68
  159. package/dist/chunk-KMU6QJB7.js +0 -68
@@ -1,11 +1,30 @@
1
- import type { CanvasEdge, CanvasNode, DirectionalDisplacementOptions, Rect, ReflowDisplacementOptions, XYPosition } from './types.js';
1
+ import type { CanvasEdge, CanvasLayoutOptions, CanvasNode, DirectionalDisplacementOptions, Rect, ReflowDisplacementOptions, XYPosition } from './types.js';
2
2
  /**
3
3
  * Calculates a bounding rectangle for a set of nodes if not provided by getNodesBounds.
4
4
  */
5
5
  export declare function computeNodesBoundingBox<TNode extends CanvasNode = CanvasNode>(nodes: TNode[], defaultWidth?: number, defaultHeight?: number): Rect;
6
+ /** A node's size: measured, then explicit, then the defaults. */
7
+ export declare function nodeSizeOf<TNode extends CanvasNode = CanvasNode>(node: TNode, defaultWidth?: number, defaultHeight?: number): {
8
+ width: number;
9
+ height: number;
10
+ };
6
11
  /**
7
12
  * Pure directional displacement calculation.
8
- * Shifts downstream or surrounding nodes along an axis to clear space for newly inserted child nodes.
13
+ *
14
+ * Shifts surrounding nodes along an axis to clear space for a cluster of child nodes inserted
15
+ * next to `originNode`, and returns the new positions of the nodes that move (nothing is mutated).
16
+ *
17
+ * - `right` / `left` push nodes on that side by the cluster's width plus `gap`; Y is preserved
18
+ * (except for `spreadSiblingLanes` with `right`).
19
+ * - `up` / `down` push nodes on that side by the cluster's height plus `gap`; X is preserved.
20
+ * - `vertical` opens the origin's row: nodes above move up and nodes below move down by the same
21
+ * amount (the larger of the two clearances); X is preserved and the origin's row stays put.
22
+ * - `layoutMode: 'row-lane'` buckets nodes into lanes `rowSpacing` apart and rounds vertical
23
+ * deltas up to whole lanes.
24
+ * - `minY` / `maxY` keep moved rows inside a band, stacking clamped rows `rowSpacing` apart.
25
+ *
26
+ * @throws RangeError when `gap`, `rowSpacing`, `minY` or `maxY` are not finite, `rowSpacing <= 0`,
27
+ * or `minY > maxY`.
9
28
  */
10
29
  export declare function calculateDirectionalDisplacement<TNode extends CanvasNode = CanvasNode>(params: {
11
30
  existingNodes: TNode[];
@@ -14,6 +33,19 @@ export declare function calculateDirectionalDisplacement<TNode extends CanvasNod
14
33
  getNodesBounds?: (nodes: TNode[]) => Rect;
15
34
  options?: DirectionalDisplacementOptions;
16
35
  }): Map<string, XYPosition>;
36
+ /**
37
+ * Hierarchical Dagre reflow displacement for an explosion: lays out the existing graph plus the
38
+ * child cluster, anchoring the origin node at its current position so the layout does not jump,
39
+ * and returns the new positions of existing nodes that move.
40
+ */
41
+ export declare function calculateReflowDisplacement<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(params: {
42
+ existingNodes: TNode[];
43
+ existingEdges: TEdge[];
44
+ originNode: TNode;
45
+ childNodes: TNode[];
46
+ childEdges?: TEdge[];
47
+ options?: CanvasLayoutOptions;
48
+ }): Map<string, XYPosition>;
17
49
  /**
18
50
  * Calculates Dagre reflow displacement preserving the position of an anchor node.
19
51
  */
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Agent tools for canvas node explosion: `list_explodable_nodes`, `explode_node` and
3
+ * `collapse_node`. They drive a {@link CanvasExplosionToolTarget}, which a host adapts from the
4
+ * declarative state (`canvasExplosionToolTarget`) or from an imperative explosion coordinator
5
+ * (`createCanvasExplosion` / `useCanvasExplosion`, whose `explodeNode` needs the host's children).
6
+ */
7
+ import type { AgentToolProvider } from '../tools/registry.cjs';
8
+ import type { CanvasExplosionState } from './explosionState.cjs';
9
+ import type { CanvasNode } from './types.cjs';
10
+ /** What the explosion tools drive. */
11
+ export interface CanvasExplosionToolTarget<TNode extends CanvasNode = CanvasNode> {
12
+ /** The nodes on the canvas (exploded children included or not; they are only listed when explodable). */
13
+ getNodes: () => readonly TNode[];
14
+ /** Ids of the exploded nodes. */
15
+ exploded: () => readonly string[];
16
+ /** Ids of nodes whose collapse is still animating. Default none. */
17
+ collapsing?: () => readonly string[];
18
+ /** `true` when the node can explode, otherwise false or the reason it cannot. Default: every node. */
19
+ canExplode?: (node: TNode) => boolean | string;
20
+ /** Explodes a node. Return false (or throw) to refuse. */
21
+ explode: (nodeId: string) => void | boolean | Promise<void | boolean>;
22
+ /** Collapses an exploded node. Return false (or throw) to refuse. */
23
+ collapse: (nodeId: string) => void | boolean | Promise<void | boolean>;
24
+ /** Several nodes can be exploded at once. Default false: exploding one collapses the other. */
25
+ multiple?: boolean;
26
+ }
27
+ /** Adapts the declarative explosion state (`createCanvasExplosionState`, `useCanvasExplosionState`) for the tools. */
28
+ export declare function canvasExplosionToolTarget<TNode extends CanvasNode = CanvasNode>(state: CanvasExplosionState, options: {
29
+ getNodes: () => readonly TNode[];
30
+ canExplode?: (node: TNode) => boolean | string;
31
+ }): CanvasExplosionToolTarget<TNode>;
32
+ export interface CanvasExplosionToolProviderOptions {
33
+ /** Provider id (unique per registry). Default `canvas-explosion`. */
34
+ id?: string;
35
+ /** Tool-name prefix (`<namespace>__<name>`); defaults to the provider id, `''` for bare names. */
36
+ namespace?: string;
37
+ /** Exploding is not allowed: `explode_node` and `collapse_node` are hidden. A string is the reason. */
38
+ readOnly?: boolean | string | (() => boolean | string);
39
+ /** Lets the tool list follow changes (e.g. the state's `subscribe`). */
40
+ subscribe?: (notify: () => void) => () => void;
41
+ }
42
+ /** The explosion tools for a canvas (see the module comment). */
43
+ export declare function createCanvasExplosionToolProvider<TNode extends CanvasNode = CanvasNode>(target: CanvasExplosionToolTarget<TNode>, options?: CanvasExplosionToolProviderOptions): AgentToolProvider;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Agent tools for canvas node explosion: `list_explodable_nodes`, `explode_node` and
3
+ * `collapse_node`. They drive a {@link CanvasExplosionToolTarget}, which a host adapts from the
4
+ * declarative state (`canvasExplosionToolTarget`) or from an imperative explosion coordinator
5
+ * (`createCanvasExplosion` / `useCanvasExplosion`, whose `explodeNode` needs the host's children).
6
+ */
7
+ import type { AgentToolProvider } from '../tools/registry.js';
8
+ import type { CanvasExplosionState } from './explosionState.js';
9
+ import type { CanvasNode } from './types.js';
10
+ /** What the explosion tools drive. */
11
+ export interface CanvasExplosionToolTarget<TNode extends CanvasNode = CanvasNode> {
12
+ /** The nodes on the canvas (exploded children included or not; they are only listed when explodable). */
13
+ getNodes: () => readonly TNode[];
14
+ /** Ids of the exploded nodes. */
15
+ exploded: () => readonly string[];
16
+ /** Ids of nodes whose collapse is still animating. Default none. */
17
+ collapsing?: () => readonly string[];
18
+ /** `true` when the node can explode, otherwise false or the reason it cannot. Default: every node. */
19
+ canExplode?: (node: TNode) => boolean | string;
20
+ /** Explodes a node. Return false (or throw) to refuse. */
21
+ explode: (nodeId: string) => void | boolean | Promise<void | boolean>;
22
+ /** Collapses an exploded node. Return false (or throw) to refuse. */
23
+ collapse: (nodeId: string) => void | boolean | Promise<void | boolean>;
24
+ /** Several nodes can be exploded at once. Default false: exploding one collapses the other. */
25
+ multiple?: boolean;
26
+ }
27
+ /** Adapts the declarative explosion state (`createCanvasExplosionState`, `useCanvasExplosionState`) for the tools. */
28
+ export declare function canvasExplosionToolTarget<TNode extends CanvasNode = CanvasNode>(state: CanvasExplosionState, options: {
29
+ getNodes: () => readonly TNode[];
30
+ canExplode?: (node: TNode) => boolean | string;
31
+ }): CanvasExplosionToolTarget<TNode>;
32
+ export interface CanvasExplosionToolProviderOptions {
33
+ /** Provider id (unique per registry). Default `canvas-explosion`. */
34
+ id?: string;
35
+ /** Tool-name prefix (`<namespace>__<name>`); defaults to the provider id, `''` for bare names. */
36
+ namespace?: string;
37
+ /** Exploding is not allowed: `explode_node` and `collapse_node` are hidden. A string is the reason. */
38
+ readOnly?: boolean | string | (() => boolean | string);
39
+ /** Lets the tool list follow changes (e.g. the state's `subscribe`). */
40
+ subscribe?: (notify: () => void) => () => void;
41
+ }
42
+ /** The explosion tools for a canvas (see the module comment). */
43
+ export declare function createCanvasExplosionToolProvider<TNode extends CanvasNode = CanvasNode>(target: CanvasExplosionToolTarget<TNode>, options?: CanvasExplosionToolProviderOptions): AgentToolProvider;
@@ -0,0 +1,50 @@
1
+ import type { CanvasEdge, CanvasLayoutOptions, CanvasNode, DirectionalDisplacementOptions, ExplosionDisplacementStrategy, Rect, XYPosition } from './types.cjs';
2
+ export interface ComputeCanvasExplosionLayoutParams<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> {
3
+ /** Every node on the canvas, including the origin. Never mutated. */
4
+ existingNodes: TNode[];
5
+ /** Every edge on the canvas (only read by the `dagre` strategy). */
6
+ existingEdges?: TEdge[];
7
+ /** The node that explodes. */
8
+ originNode: TNode;
9
+ /** The child nodes at their final positions. Never mutated: the result holds copies. */
10
+ childNodes: TNode[];
11
+ /** Edges between children (or from children to existing nodes). */
12
+ childEdges?: TEdge[];
13
+ /** How existing nodes make room. Default `directional`. */
14
+ strategy?: ExplosionDisplacementStrategy;
15
+ /** Options for the `directional` strategy. */
16
+ options?: DirectionalDisplacementOptions;
17
+ /** Options for the `dagre` strategy. */
18
+ reflowOptions?: CanvasLayoutOptions;
19
+ /** Add parent-to-child edges: every child (`true` / `'all'`), the first child only, or none. Default `false`. */
20
+ connectParentToChildren?: boolean | 'first' | 'all';
21
+ /** Builds a parent-to-child edge. Default `{ id: 'explode:<parent>:<child>', source, target, type: 'default' }`. */
22
+ createEdge?: (sourceId: string, targetId: string) => TEdge;
23
+ /** Bounds of a set of nodes (e.g. the flow instance's `getNodesBounds`). Default: measured sizes. */
24
+ getNodesBounds?: (nodes: TNode[]) => Rect;
25
+ }
26
+ export interface CanvasExplosionLayoutResult<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> {
27
+ /** New positions of the existing nodes that move to make room, by id. */
28
+ displacedPositions: Map<string, XYPosition>;
29
+ /** Where each displaced node was before, by id (what a collapse restores). */
30
+ originalPositions: Map<string, XYPosition>;
31
+ /** Copies of the child nodes at their final positions. */
32
+ childNodes: TNode[];
33
+ /** The child edges plus any parent-to-child edges (deduplicated). */
34
+ childEdges: TEdge[];
35
+ /** Bounds of the child cluster. */
36
+ childBounds: Rect;
37
+ /** The largest distance any displaced node moves along either axis (0 when nothing moves). */
38
+ totalDisplacementDelta: number;
39
+ }
40
+ /** The default id of a parent-to-child edge added by an explosion. */
41
+ export declare const explosionEdgeId: (sourceId: string, targetId: string) => string;
42
+ /**
43
+ * Pure explosion layout: works out where existing nodes move to make room for a child cluster
44
+ * and which edges the explosion adds, without touching the inputs. Feed the result to a
45
+ * declarative derivation (`$derived`, `useMemo`) or to an imperative graph coordinator.
46
+ *
47
+ * @throws Error when the origin is not in `existingNodes`, or a child id is already on the canvas
48
+ * or repeated.
49
+ */
50
+ export declare function computeCanvasExplosionLayout<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(params: ComputeCanvasExplosionLayoutParams<TNode, TEdge>): CanvasExplosionLayoutResult<TNode, TEdge>;
@@ -0,0 +1,50 @@
1
+ import type { CanvasEdge, CanvasLayoutOptions, CanvasNode, DirectionalDisplacementOptions, ExplosionDisplacementStrategy, Rect, XYPosition } from './types.js';
2
+ export interface ComputeCanvasExplosionLayoutParams<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> {
3
+ /** Every node on the canvas, including the origin. Never mutated. */
4
+ existingNodes: TNode[];
5
+ /** Every edge on the canvas (only read by the `dagre` strategy). */
6
+ existingEdges?: TEdge[];
7
+ /** The node that explodes. */
8
+ originNode: TNode;
9
+ /** The child nodes at their final positions. Never mutated: the result holds copies. */
10
+ childNodes: TNode[];
11
+ /** Edges between children (or from children to existing nodes). */
12
+ childEdges?: TEdge[];
13
+ /** How existing nodes make room. Default `directional`. */
14
+ strategy?: ExplosionDisplacementStrategy;
15
+ /** Options for the `directional` strategy. */
16
+ options?: DirectionalDisplacementOptions;
17
+ /** Options for the `dagre` strategy. */
18
+ reflowOptions?: CanvasLayoutOptions;
19
+ /** Add parent-to-child edges: every child (`true` / `'all'`), the first child only, or none. Default `false`. */
20
+ connectParentToChildren?: boolean | 'first' | 'all';
21
+ /** Builds a parent-to-child edge. Default `{ id: 'explode:<parent>:<child>', source, target, type: 'default' }`. */
22
+ createEdge?: (sourceId: string, targetId: string) => TEdge;
23
+ /** Bounds of a set of nodes (e.g. the flow instance's `getNodesBounds`). Default: measured sizes. */
24
+ getNodesBounds?: (nodes: TNode[]) => Rect;
25
+ }
26
+ export interface CanvasExplosionLayoutResult<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> {
27
+ /** New positions of the existing nodes that move to make room, by id. */
28
+ displacedPositions: Map<string, XYPosition>;
29
+ /** Where each displaced node was before, by id (what a collapse restores). */
30
+ originalPositions: Map<string, XYPosition>;
31
+ /** Copies of the child nodes at their final positions. */
32
+ childNodes: TNode[];
33
+ /** The child edges plus any parent-to-child edges (deduplicated). */
34
+ childEdges: TEdge[];
35
+ /** Bounds of the child cluster. */
36
+ childBounds: Rect;
37
+ /** The largest distance any displaced node moves along either axis (0 when nothing moves). */
38
+ totalDisplacementDelta: number;
39
+ }
40
+ /** The default id of a parent-to-child edge added by an explosion. */
41
+ export declare const explosionEdgeId: (sourceId: string, targetId: string) => string;
42
+ /**
43
+ * Pure explosion layout: works out where existing nodes move to make room for a child cluster
44
+ * and which edges the explosion adds, without touching the inputs. Feed the result to a
45
+ * declarative derivation (`$derived`, `useMemo`) or to an imperative graph coordinator.
46
+ *
47
+ * @throws Error when the origin is not in `existingNodes`, or a child id is already on the canvas
48
+ * or repeated.
49
+ */
50
+ export declare function computeCanvasExplosionLayout<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(params: ComputeCanvasExplosionLayoutParams<TNode, TEdge>): CanvasExplosionLayoutResult<TNode, TEdge>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Headless, framework-free state machine for canvas node explosion: which node is exploded,
3
+ * which is collapsing (children still mounted while a collapse animation plays), and the timer
4
+ * that ends the collapse. It never touches a graph or the DOM, so a declarative canvas can derive
5
+ * its nodes from it. The Svelte rune `createCanvasExplosionState` and the React hook
6
+ * `useCanvasExplosionState` wrap it.
7
+ */
8
+ export interface CanvasExplosionStateOptions {
9
+ /** How long children stay rendered after a collapse starts, in ms. Default 380. `0` ends the collapse at once. */
10
+ collapseDurationMs?: number;
11
+ /** The node exploded at creation. Default none. */
12
+ initialActiveId?: string | null;
13
+ /** Called after a node explodes. */
14
+ onExplode?: (nodeId: string) => void;
15
+ /** Called when a node starts collapsing (including when exploding another node replaces it). */
16
+ onCollapse?: (nodeId: string) => void;
17
+ }
18
+ /** The state at one moment. A new object each time it changes, so it can be compared by identity. */
19
+ export interface CanvasExplosionStateSnapshot {
20
+ /** The exploded node, or null. */
21
+ readonly activeId: string | null;
22
+ /** The node whose collapse animation is playing, or null. */
23
+ readonly collapsingId: string | null;
24
+ }
25
+ export interface CanvasExplosionState extends CanvasExplosionStateSnapshot {
26
+ /** True while a node is exploded or collapsing (children are on screen). */
27
+ readonly isExplodingOrCollapsing: boolean;
28
+ isExploded: (nodeId: string) => boolean;
29
+ isCollapsing: (nodeId: string) => boolean;
30
+ /** True when the node's children should be rendered: it is exploded or still collapsing. */
31
+ shouldRenderChildren: (nodeId: string) => boolean;
32
+ /** Explodes a node, replacing (collapsing) any other exploded node. Returns false when it already was. */
33
+ explode: (nodeId: string) => boolean;
34
+ /** Collapses the exploded node (only if it is `nodeId`, when given). Returns false when nothing collapsed. */
35
+ collapse: (nodeId?: string) => boolean;
36
+ /** Collapses the node when it is exploded, otherwise explodes it. Returns true when it is now exploded. */
37
+ toggle: (nodeId: string) => boolean;
38
+ /** Ends a running collapse now (e.g. from an `animationend` handler) instead of waiting for the timer. */
39
+ finishCollapse: () => void;
40
+ /** Clears the collapse timer and listeners; later calls do nothing. */
41
+ destroy: () => void;
42
+ }
43
+ export interface CanvasExplosionStateController extends CanvasExplosionState {
44
+ /** The current state; the same object until something changes. */
45
+ getSnapshot: () => CanvasExplosionStateSnapshot;
46
+ /** Calls `listener` after every change; returns an unsubscribe function. */
47
+ subscribe: (listener: () => void) => () => void;
48
+ /** True after `destroy()`. */
49
+ readonly destroyed: boolean;
50
+ }
51
+ /** Creates the headless explosion state machine (see the module comment). */
52
+ export declare function createCanvasExplosionStateController(options?: CanvasExplosionStateOptions): CanvasExplosionStateController;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Headless, framework-free state machine for canvas node explosion: which node is exploded,
3
+ * which is collapsing (children still mounted while a collapse animation plays), and the timer
4
+ * that ends the collapse. It never touches a graph or the DOM, so a declarative canvas can derive
5
+ * its nodes from it. The Svelte rune `createCanvasExplosionState` and the React hook
6
+ * `useCanvasExplosionState` wrap it.
7
+ */
8
+ export interface CanvasExplosionStateOptions {
9
+ /** How long children stay rendered after a collapse starts, in ms. Default 380. `0` ends the collapse at once. */
10
+ collapseDurationMs?: number;
11
+ /** The node exploded at creation. Default none. */
12
+ initialActiveId?: string | null;
13
+ /** Called after a node explodes. */
14
+ onExplode?: (nodeId: string) => void;
15
+ /** Called when a node starts collapsing (including when exploding another node replaces it). */
16
+ onCollapse?: (nodeId: string) => void;
17
+ }
18
+ /** The state at one moment. A new object each time it changes, so it can be compared by identity. */
19
+ export interface CanvasExplosionStateSnapshot {
20
+ /** The exploded node, or null. */
21
+ readonly activeId: string | null;
22
+ /** The node whose collapse animation is playing, or null. */
23
+ readonly collapsingId: string | null;
24
+ }
25
+ export interface CanvasExplosionState extends CanvasExplosionStateSnapshot {
26
+ /** True while a node is exploded or collapsing (children are on screen). */
27
+ readonly isExplodingOrCollapsing: boolean;
28
+ isExploded: (nodeId: string) => boolean;
29
+ isCollapsing: (nodeId: string) => boolean;
30
+ /** True when the node's children should be rendered: it is exploded or still collapsing. */
31
+ shouldRenderChildren: (nodeId: string) => boolean;
32
+ /** Explodes a node, replacing (collapsing) any other exploded node. Returns false when it already was. */
33
+ explode: (nodeId: string) => boolean;
34
+ /** Collapses the exploded node (only if it is `nodeId`, when given). Returns false when nothing collapsed. */
35
+ collapse: (nodeId?: string) => boolean;
36
+ /** Collapses the node when it is exploded, otherwise explodes it. Returns true when it is now exploded. */
37
+ toggle: (nodeId: string) => boolean;
38
+ /** Ends a running collapse now (e.g. from an `animationend` handler) instead of waiting for the timer. */
39
+ finishCollapse: () => void;
40
+ /** Clears the collapse timer and listeners; later calls do nothing. */
41
+ destroy: () => void;
42
+ }
43
+ export interface CanvasExplosionStateController extends CanvasExplosionState {
44
+ /** The current state; the same object until something changes. */
45
+ getSnapshot: () => CanvasExplosionStateSnapshot;
46
+ /** Calls `listener` after every change; returns an unsubscribe function. */
47
+ subscribe: (listener: () => void) => () => void;
48
+ /** True after `destroy()`. */
49
+ readonly destroyed: boolean;
50
+ }
51
+ /** Creates the headless explosion state machine (see the module comment). */
52
+ export declare function createCanvasExplosionStateController(options?: CanvasExplosionStateOptions): CanvasExplosionStateController;