@pixerate/editor 0.279.1 → 0.281.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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Agent tools for animated edges: `list_edge_animations`, `set_edge_animation` and
3
+ * `clear_edge_animation`. They read and write `edge.data.animation` through the host's edges, and
4
+ * each write is one undo step when a history is given.
5
+ */
6
+ import type { Command } from '../history/types.cjs';
7
+ import type { AgentToolProvider } from '../tools/registry.cjs';
8
+ /** The edge fields the tools read: React Flow and Svelte Flow edges fit as they are. */
9
+ export interface CanvasEdgeAnimationToolEdge {
10
+ id: string;
11
+ source: string;
12
+ target: string;
13
+ label?: unknown;
14
+ data?: Record<string, any>;
15
+ }
16
+ export interface CanvasEdgeAnimationToolTarget<TEdge extends CanvasEdgeAnimationToolEdge = CanvasEdgeAnimationToolEdge> {
17
+ /** The edges on the canvas now. */
18
+ getEdges: () => readonly TEdge[];
19
+ /**
20
+ * Replaces the edges with the result of `update(current)`. React's `setEdges` fits as is; in
21
+ * Svelte, `(update) => (edges = update(edges))`.
22
+ */
23
+ setEdges: (update: (current: TEdge[]) => TEdge[]) => void;
24
+ /** The canvas's undo history: each write is one step there. Without it, writes are not undoable. */
25
+ history?: {
26
+ execute(command: Command): void;
27
+ };
28
+ }
29
+ export interface CanvasEdgeAnimationToolProviderOptions {
30
+ /** Provider id (unique per registry). Default `canvas-edge-animation`. */
31
+ id?: string;
32
+ /** Tool-name prefix (`<namespace>__<name>`); defaults to the provider id, `''` for bare names. */
33
+ namespace?: string;
34
+ /** Edges cannot be changed: the write tools are hidden. A string is the reason. */
35
+ readOnly?: boolean | string | (() => boolean | string);
36
+ /** Lets the tool list follow changes. */
37
+ subscribe?: (notify: () => void) => () => void;
38
+ }
39
+ /** JSON Schema of {@link CanvasEdgeAnimation}, for tools and commands. */
40
+ export declare const CANVAS_EDGE_ANIMATION_SCHEMA: {
41
+ readonly type: "object";
42
+ readonly properties: {
43
+ readonly kind: {
44
+ readonly type: "string";
45
+ readonly enum: import("./edgeAnimation.cjs").CanvasEdgeAnimationKind[];
46
+ readonly description: "What moves: dots (travelling dots), dash (marching dashes), beam (a glowing streak that shoots along), pulse (the edge glows and fades).";
47
+ };
48
+ readonly speed: {
49
+ readonly type: "number";
50
+ readonly minimum: 1;
51
+ readonly maximum: 10000;
52
+ readonly description: "Travel speed in canvas units per second (dots, dash, beam). Defaults: dots 80, dash 40, beam 200.";
53
+ };
54
+ readonly duration: {
55
+ readonly type: "number";
56
+ readonly minimum: 100;
57
+ readonly maximum: 600000;
58
+ readonly description: "One cycle in ms; overrides speed. The pulse timing (default 1600).";
59
+ };
60
+ readonly direction: {
61
+ readonly type: "string";
62
+ readonly enum: readonly ["forward", "reverse", "alternate"];
63
+ readonly description: "forward = source to target (default), reverse = target to source, alternate = back and forth.";
64
+ };
65
+ readonly color: {
66
+ readonly type: "string";
67
+ readonly minLength: 1;
68
+ readonly description: "CSS colour, e.g. \"#38bdf8\". Default: the edge stroke colour.";
69
+ };
70
+ readonly size: {
71
+ readonly type: "number";
72
+ readonly minimum: 0.5;
73
+ readonly maximum: 100;
74
+ readonly description: "Dot radius, or stroke width of dashes, beams and the pulse, in canvas units. Defaults: dots 3, dash 2, beam 3, pulse 4.";
75
+ };
76
+ readonly count: {
77
+ readonly type: "integer";
78
+ readonly minimum: 1;
79
+ readonly maximum: 50;
80
+ readonly description: "How many dots or beams are on the edge at once. Defaults: dots 3, beam 1.";
81
+ };
82
+ readonly length: {
83
+ readonly type: "number";
84
+ readonly minimum: 1;
85
+ readonly maximum: 10000;
86
+ readonly description: "Dash or beam length in canvas units. Defaults: dash 8, beam 40.";
87
+ };
88
+ readonly gap: {
89
+ readonly type: "number";
90
+ readonly minimum: 0;
91
+ readonly maximum: 10000;
92
+ readonly description: "Gap between dashes in canvas units (dash). Default 6.";
93
+ };
94
+ readonly glow: {
95
+ readonly type: "number";
96
+ readonly minimum: 0;
97
+ readonly maximum: 50;
98
+ readonly description: "Glow (blur) radius in canvas units; 0 is none. Defaults: beam 4, pulse 3, others 0.";
99
+ };
100
+ readonly trackOpacity: {
101
+ readonly type: "number";
102
+ readonly minimum: 0;
103
+ readonly maximum: 1;
104
+ readonly description: "Opacity of the edge's own line under the animation, 0-1. Defaults: dash 0 (the dashes are the line), beam 0.35, others 1.";
105
+ };
106
+ readonly paused: {
107
+ readonly type: "boolean";
108
+ readonly description: "Hold the animation still at its first frame. Default false.";
109
+ };
110
+ };
111
+ readonly required: readonly ["kind"];
112
+ readonly additionalProperties: false;
113
+ };
114
+ /** The edge animation tools for a canvas (see the module comment). */
115
+ export declare function createCanvasEdgeAnimationToolProvider<TEdge extends CanvasEdgeAnimationToolEdge = CanvasEdgeAnimationToolEdge>(target: CanvasEdgeAnimationToolTarget<TEdge>, options?: CanvasEdgeAnimationToolProviderOptions): AgentToolProvider;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Agent tools for animated edges: `list_edge_animations`, `set_edge_animation` and
3
+ * `clear_edge_animation`. They read and write `edge.data.animation` through the host's edges, and
4
+ * each write is one undo step when a history is given.
5
+ */
6
+ import type { Command } from '../history/types.js';
7
+ import type { AgentToolProvider } from '../tools/registry.js';
8
+ /** The edge fields the tools read: React Flow and Svelte Flow edges fit as they are. */
9
+ export interface CanvasEdgeAnimationToolEdge {
10
+ id: string;
11
+ source: string;
12
+ target: string;
13
+ label?: unknown;
14
+ data?: Record<string, any>;
15
+ }
16
+ export interface CanvasEdgeAnimationToolTarget<TEdge extends CanvasEdgeAnimationToolEdge = CanvasEdgeAnimationToolEdge> {
17
+ /** The edges on the canvas now. */
18
+ getEdges: () => readonly TEdge[];
19
+ /**
20
+ * Replaces the edges with the result of `update(current)`. React's `setEdges` fits as is; in
21
+ * Svelte, `(update) => (edges = update(edges))`.
22
+ */
23
+ setEdges: (update: (current: TEdge[]) => TEdge[]) => void;
24
+ /** The canvas's undo history: each write is one step there. Without it, writes are not undoable. */
25
+ history?: {
26
+ execute(command: Command): void;
27
+ };
28
+ }
29
+ export interface CanvasEdgeAnimationToolProviderOptions {
30
+ /** Provider id (unique per registry). Default `canvas-edge-animation`. */
31
+ id?: string;
32
+ /** Tool-name prefix (`<namespace>__<name>`); defaults to the provider id, `''` for bare names. */
33
+ namespace?: string;
34
+ /** Edges cannot be changed: the write tools are hidden. A string is the reason. */
35
+ readOnly?: boolean | string | (() => boolean | string);
36
+ /** Lets the tool list follow changes. */
37
+ subscribe?: (notify: () => void) => () => void;
38
+ }
39
+ /** JSON Schema of {@link CanvasEdgeAnimation}, for tools and commands. */
40
+ export declare const CANVAS_EDGE_ANIMATION_SCHEMA: {
41
+ readonly type: "object";
42
+ readonly properties: {
43
+ readonly kind: {
44
+ readonly type: "string";
45
+ readonly enum: import("./edgeAnimation.js").CanvasEdgeAnimationKind[];
46
+ readonly description: "What moves: dots (travelling dots), dash (marching dashes), beam (a glowing streak that shoots along), pulse (the edge glows and fades).";
47
+ };
48
+ readonly speed: {
49
+ readonly type: "number";
50
+ readonly minimum: 1;
51
+ readonly maximum: 10000;
52
+ readonly description: "Travel speed in canvas units per second (dots, dash, beam). Defaults: dots 80, dash 40, beam 200.";
53
+ };
54
+ readonly duration: {
55
+ readonly type: "number";
56
+ readonly minimum: 100;
57
+ readonly maximum: 600000;
58
+ readonly description: "One cycle in ms; overrides speed. The pulse timing (default 1600).";
59
+ };
60
+ readonly direction: {
61
+ readonly type: "string";
62
+ readonly enum: readonly ["forward", "reverse", "alternate"];
63
+ readonly description: "forward = source to target (default), reverse = target to source, alternate = back and forth.";
64
+ };
65
+ readonly color: {
66
+ readonly type: "string";
67
+ readonly minLength: 1;
68
+ readonly description: "CSS colour, e.g. \"#38bdf8\". Default: the edge stroke colour.";
69
+ };
70
+ readonly size: {
71
+ readonly type: "number";
72
+ readonly minimum: 0.5;
73
+ readonly maximum: 100;
74
+ readonly description: "Dot radius, or stroke width of dashes, beams and the pulse, in canvas units. Defaults: dots 3, dash 2, beam 3, pulse 4.";
75
+ };
76
+ readonly count: {
77
+ readonly type: "integer";
78
+ readonly minimum: 1;
79
+ readonly maximum: 50;
80
+ readonly description: "How many dots or beams are on the edge at once. Defaults: dots 3, beam 1.";
81
+ };
82
+ readonly length: {
83
+ readonly type: "number";
84
+ readonly minimum: 1;
85
+ readonly maximum: 10000;
86
+ readonly description: "Dash or beam length in canvas units. Defaults: dash 8, beam 40.";
87
+ };
88
+ readonly gap: {
89
+ readonly type: "number";
90
+ readonly minimum: 0;
91
+ readonly maximum: 10000;
92
+ readonly description: "Gap between dashes in canvas units (dash). Default 6.";
93
+ };
94
+ readonly glow: {
95
+ readonly type: "number";
96
+ readonly minimum: 0;
97
+ readonly maximum: 50;
98
+ readonly description: "Glow (blur) radius in canvas units; 0 is none. Defaults: beam 4, pulse 3, others 0.";
99
+ };
100
+ readonly trackOpacity: {
101
+ readonly type: "number";
102
+ readonly minimum: 0;
103
+ readonly maximum: 1;
104
+ readonly description: "Opacity of the edge's own line under the animation, 0-1. Defaults: dash 0 (the dashes are the line), beam 0.35, others 1.";
105
+ };
106
+ readonly paused: {
107
+ readonly type: "boolean";
108
+ readonly description: "Hold the animation still at its first frame. Default false.";
109
+ };
110
+ };
111
+ readonly required: readonly ["kind"];
112
+ readonly additionalProperties: false;
113
+ };
114
+ /** The edge animation tools for a canvas (see the module comment). */
115
+ export declare function createCanvasEdgeAnimationToolProvider<TEdge extends CanvasEdgeAnimationToolEdge = CanvasEdgeAnimationToolEdge>(target: CanvasEdgeAnimationToolTarget<TEdge>, options?: CanvasEdgeAnimationToolProviderOptions): AgentToolProvider;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Animated canvas edges: dots travelling along an edge, marching dashes, beams of light and a
3
+ * pulsing glow. An edge's animation is data (`edge.data.animation`, a {@link CanvasEdgeAnimation}),
4
+ * so it saves, undoes and copies with the edge. {@link getCanvasEdgeAnimationRender} turns it into a
5
+ * framework-neutral list of SVG elements with SMIL timing, which `<AnimatedEdge>` /
6
+ * `<EdgeAnimation>` (React and Svelte) render; {@link sampleCanvasEdgeAnimation} gives the same
7
+ * picture at a moment in time without a browser (thumbnails, exports, tests, reduced motion).
8
+ */
9
+ import type { CanvasConnectionLineType } from './connectors.cjs';
10
+ import { type MeasuredSvgPath, type SvgPathPoint } from './edgePaths.cjs';
11
+ /** What travels along the edge. */
12
+ export type CanvasEdgeAnimationKind = 'dots' | 'dash' | 'beam' | 'pulse';
13
+ /** Which way the animation runs: source → target, target → source, or back and forth. */
14
+ export type CanvasEdgeAnimationDirection = 'forward' | 'reverse' | 'alternate';
15
+ /** An edge's animation, stored at `edge.data.animation`. Every field but `kind` is optional. */
16
+ export interface CanvasEdgeAnimation {
17
+ kind: CanvasEdgeAnimationKind;
18
+ /** Travel speed in canvas units per second (`dots`, `dash`, `beam`). Defaults per kind. */
19
+ speed?: number;
20
+ /** Length of one cycle in ms; overrides `speed` (and is the only timing for `pulse`). */
21
+ duration?: number;
22
+ /** Default `forward` (source → target). */
23
+ direction?: CanvasEdgeAnimationDirection;
24
+ /** CSS colour. Default: the edge's stroke. */
25
+ color?: string;
26
+ /** Dot radius, or the stroke width of dashes, beams and the pulse, in canvas units. Defaults per kind. */
27
+ size?: number;
28
+ /** Number of dots or beams on the edge at once. Defaults per kind. */
29
+ count?: number;
30
+ /** Dash or beam length, in canvas units. Defaults per kind. */
31
+ length?: number;
32
+ /** Gap between dashes, in canvas units (`dash`). Default 6. */
33
+ gap?: number;
34
+ /** Glow radius (a blur behind the moving part), in canvas units. 0 is none. Defaults per kind. */
35
+ glow?: number;
36
+ /** Opacity of the edge's own stroke under the animation, 0–1. Default 1. */
37
+ trackOpacity?: number;
38
+ /** Held still at its first frame. Default false. */
39
+ paused?: boolean;
40
+ }
41
+ export interface CanvasEdgeAnimationKindInfo {
42
+ kind: CanvasEdgeAnimationKind;
43
+ title: string;
44
+ description: string;
45
+ /** The values used for fields an animation leaves out. */
46
+ defaults: Required<Omit<CanvasEdgeAnimation, 'kind' | 'color' | 'duration' | 'paused'>> & {
47
+ duration?: number;
48
+ };
49
+ }
50
+ /** The animation kinds, with what they look like and their defaults. */
51
+ export declare const CANVAS_EDGE_ANIMATION_KINDS: readonly CanvasEdgeAnimationKindInfo[];
52
+ /**
53
+ * Checks an animation and returns a clean copy (unknown fields dropped). Throws an error that says
54
+ * which field is wrong and what it accepts.
55
+ */
56
+ export declare function normalizeCanvasEdgeAnimation(input: unknown): CanvasEdgeAnimation;
57
+ /** The edge's animation, or null when it has none or it is not valid. */
58
+ export declare function getCanvasEdgeAnimation(edge: {
59
+ data?: Record<string, any>;
60
+ } | null | undefined): CanvasEdgeAnimation | null;
61
+ /** A copy of the edge with its animation set (checked first), or removed when `animation` is null. */
62
+ export declare function setCanvasEdgeAnimation<TEdge extends {
63
+ data?: Record<string, any>;
64
+ }>(edge: TEdge, animation: CanvasEdgeAnimation | null): TEdge;
65
+ /** The animation with every default filled in, as it will play. */
66
+ export declare function resolveCanvasEdgeAnimation(animation: CanvasEdgeAnimation): Required<Omit<CanvasEdgeAnimation, 'color' | 'duration'>> & Pick<CanvasEdgeAnimation, 'color' | 'duration'>;
67
+ /** SMIL timing for an element: rendered as `<animate>` / `<animateMotion>` children. */
68
+ export interface CanvasEdgeAnimationTiming {
69
+ /** Seconds per cycle (SMIL `dur`). */
70
+ dur: number;
71
+ /** Start offset in seconds; negative starts part-way through (SMIL `begin`). */
72
+ begin: number;
73
+ }
74
+ /** One SVG element of an animated edge. Coordinates are canvas units. */
75
+ export type CanvasEdgeAnimationElement = {
76
+ type: 'dot';
77
+ key: string;
78
+ r: number;
79
+ fill: string;
80
+ filter?: string;
81
+ /** Where the dot is at the first frame (used when paused or with reduced motion). */
82
+ at: SvgPathPoint;
83
+ /** Travel along the path: `keyPoints` / `keyTimes` for `<animateMotion>`. */
84
+ motion: CanvasEdgeAnimationTiming & {
85
+ keyPoints: string;
86
+ keyTimes: string;
87
+ };
88
+ } | {
89
+ type: 'stroke';
90
+ key: string;
91
+ stroke: string;
92
+ strokeWidth: number;
93
+ strokeLinecap: 'round' | 'butt';
94
+ strokeDasharray?: string;
95
+ strokeDashoffset?: number;
96
+ opacity?: number;
97
+ filter?: string;
98
+ /** `<animate>`s to add: attribute, values (`;`-separated, SMIL), timing. */
99
+ animate: Array<CanvasEdgeAnimationTiming & {
100
+ attributeName: 'stroke-dashoffset' | 'stroke-opacity' | 'stroke-width';
101
+ values: string;
102
+ }>;
103
+ };
104
+ export interface CanvasEdgeAnimationRender {
105
+ kind: CanvasEdgeAnimationKind;
106
+ /** Path length in canvas units. */
107
+ length: number;
108
+ /** Opacity for the edge's own stroke. */
109
+ trackOpacity: number;
110
+ /** Whether the elements should move (false when paused, reduced motion or a zero-length path). */
111
+ moving: boolean;
112
+ /**
113
+ * A blur filter to define in `<defs>` when anything glows. Its region is in user space (canvas
114
+ * units, `filterUnits="userSpaceOnUse"`): a straight edge has a zero-height box, and a filter
115
+ * sized to the box would hide it.
116
+ */
117
+ glowFilter?: {
118
+ id: string;
119
+ stdDeviation: number;
120
+ x: number;
121
+ y: number;
122
+ width: number;
123
+ height: number;
124
+ };
125
+ elements: CanvasEdgeAnimationElement[];
126
+ }
127
+ export interface CanvasEdgeAnimationRenderOptions {
128
+ /** SVG path data of the edge (`getCanvasEdgePath(...).path` or the path your edge draws). */
129
+ path: string;
130
+ /** A unique id for this edge's defs (the edge id). */
131
+ id: string;
132
+ /** Colour used when the animation has none (the edge's stroke). Default `currentColor`. */
133
+ stroke?: string;
134
+ /** Draw the first frame without movement (honour `prefers-reduced-motion`). Default false. */
135
+ reducedMotion?: boolean;
136
+ /** A measured path to reuse, when you already have one for `path`. */
137
+ measured?: MeasuredSvgPath;
138
+ }
139
+ /**
140
+ * How to draw an animated edge: SVG elements and SMIL timing, computed from the path. Dots use
141
+ * `<animateMotion>` along the path, dashes and beams animate `stroke-dashoffset`, the pulse animates
142
+ * opacity and width. Nothing here needs a DOM; the React and Svelte `<EdgeAnimation>` render it.
143
+ */
144
+ export declare function getCanvasEdgeAnimationRender(animation: CanvasEdgeAnimation, options: CanvasEdgeAnimationRenderOptions): CanvasEdgeAnimationRender;
145
+ /** The animated part of an edge at one moment. */
146
+ export interface CanvasEdgeAnimationFrame {
147
+ kind: CanvasEdgeAnimationKind;
148
+ length: number;
149
+ /** Dot positions (`dots`). */
150
+ dots: SvgPathPoint[];
151
+ /** Visible stretches of the path as [from, to] distances (`dash`, `beam`), clipped to the path. */
152
+ segments: Array<[number, number]>;
153
+ /** Stroke opacity and width (`pulse`). */
154
+ opacity: number;
155
+ strokeWidth: number;
156
+ }
157
+ /**
158
+ * Where everything is `timeMs` into the animation: the same picture the SVG shows at that time,
159
+ * computed without a browser (for thumbnails, exports, canvas renderers and tests). A paused
160
+ * animation always returns its first frame.
161
+ */
162
+ export declare function sampleCanvasEdgeAnimation(animation: CanvasEdgeAnimation, path: string | MeasuredSvgPath, timeMs: number): CanvasEdgeAnimationFrame;
163
+ /** Edge path styles `<AnimatedEdge>` can draw (read from `edge.data.pathType`). */
164
+ export type CanvasAnimatedEdgePathType = CanvasConnectionLineType;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Animated canvas edges: dots travelling along an edge, marching dashes, beams of light and a
3
+ * pulsing glow. An edge's animation is data (`edge.data.animation`, a {@link CanvasEdgeAnimation}),
4
+ * so it saves, undoes and copies with the edge. {@link getCanvasEdgeAnimationRender} turns it into a
5
+ * framework-neutral list of SVG elements with SMIL timing, which `<AnimatedEdge>` /
6
+ * `<EdgeAnimation>` (React and Svelte) render; {@link sampleCanvasEdgeAnimation} gives the same
7
+ * picture at a moment in time without a browser (thumbnails, exports, tests, reduced motion).
8
+ */
9
+ import type { CanvasConnectionLineType } from './connectors.js';
10
+ import { type MeasuredSvgPath, type SvgPathPoint } from './edgePaths.js';
11
+ /** What travels along the edge. */
12
+ export type CanvasEdgeAnimationKind = 'dots' | 'dash' | 'beam' | 'pulse';
13
+ /** Which way the animation runs: source → target, target → source, or back and forth. */
14
+ export type CanvasEdgeAnimationDirection = 'forward' | 'reverse' | 'alternate';
15
+ /** An edge's animation, stored at `edge.data.animation`. Every field but `kind` is optional. */
16
+ export interface CanvasEdgeAnimation {
17
+ kind: CanvasEdgeAnimationKind;
18
+ /** Travel speed in canvas units per second (`dots`, `dash`, `beam`). Defaults per kind. */
19
+ speed?: number;
20
+ /** Length of one cycle in ms; overrides `speed` (and is the only timing for `pulse`). */
21
+ duration?: number;
22
+ /** Default `forward` (source → target). */
23
+ direction?: CanvasEdgeAnimationDirection;
24
+ /** CSS colour. Default: the edge's stroke. */
25
+ color?: string;
26
+ /** Dot radius, or the stroke width of dashes, beams and the pulse, in canvas units. Defaults per kind. */
27
+ size?: number;
28
+ /** Number of dots or beams on the edge at once. Defaults per kind. */
29
+ count?: number;
30
+ /** Dash or beam length, in canvas units. Defaults per kind. */
31
+ length?: number;
32
+ /** Gap between dashes, in canvas units (`dash`). Default 6. */
33
+ gap?: number;
34
+ /** Glow radius (a blur behind the moving part), in canvas units. 0 is none. Defaults per kind. */
35
+ glow?: number;
36
+ /** Opacity of the edge's own stroke under the animation, 0–1. Default 1. */
37
+ trackOpacity?: number;
38
+ /** Held still at its first frame. Default false. */
39
+ paused?: boolean;
40
+ }
41
+ export interface CanvasEdgeAnimationKindInfo {
42
+ kind: CanvasEdgeAnimationKind;
43
+ title: string;
44
+ description: string;
45
+ /** The values used for fields an animation leaves out. */
46
+ defaults: Required<Omit<CanvasEdgeAnimation, 'kind' | 'color' | 'duration' | 'paused'>> & {
47
+ duration?: number;
48
+ };
49
+ }
50
+ /** The animation kinds, with what they look like and their defaults. */
51
+ export declare const CANVAS_EDGE_ANIMATION_KINDS: readonly CanvasEdgeAnimationKindInfo[];
52
+ /**
53
+ * Checks an animation and returns a clean copy (unknown fields dropped). Throws an error that says
54
+ * which field is wrong and what it accepts.
55
+ */
56
+ export declare function normalizeCanvasEdgeAnimation(input: unknown): CanvasEdgeAnimation;
57
+ /** The edge's animation, or null when it has none or it is not valid. */
58
+ export declare function getCanvasEdgeAnimation(edge: {
59
+ data?: Record<string, any>;
60
+ } | null | undefined): CanvasEdgeAnimation | null;
61
+ /** A copy of the edge with its animation set (checked first), or removed when `animation` is null. */
62
+ export declare function setCanvasEdgeAnimation<TEdge extends {
63
+ data?: Record<string, any>;
64
+ }>(edge: TEdge, animation: CanvasEdgeAnimation | null): TEdge;
65
+ /** The animation with every default filled in, as it will play. */
66
+ export declare function resolveCanvasEdgeAnimation(animation: CanvasEdgeAnimation): Required<Omit<CanvasEdgeAnimation, 'color' | 'duration'>> & Pick<CanvasEdgeAnimation, 'color' | 'duration'>;
67
+ /** SMIL timing for an element: rendered as `<animate>` / `<animateMotion>` children. */
68
+ export interface CanvasEdgeAnimationTiming {
69
+ /** Seconds per cycle (SMIL `dur`). */
70
+ dur: number;
71
+ /** Start offset in seconds; negative starts part-way through (SMIL `begin`). */
72
+ begin: number;
73
+ }
74
+ /** One SVG element of an animated edge. Coordinates are canvas units. */
75
+ export type CanvasEdgeAnimationElement = {
76
+ type: 'dot';
77
+ key: string;
78
+ r: number;
79
+ fill: string;
80
+ filter?: string;
81
+ /** Where the dot is at the first frame (used when paused or with reduced motion). */
82
+ at: SvgPathPoint;
83
+ /** Travel along the path: `keyPoints` / `keyTimes` for `<animateMotion>`. */
84
+ motion: CanvasEdgeAnimationTiming & {
85
+ keyPoints: string;
86
+ keyTimes: string;
87
+ };
88
+ } | {
89
+ type: 'stroke';
90
+ key: string;
91
+ stroke: string;
92
+ strokeWidth: number;
93
+ strokeLinecap: 'round' | 'butt';
94
+ strokeDasharray?: string;
95
+ strokeDashoffset?: number;
96
+ opacity?: number;
97
+ filter?: string;
98
+ /** `<animate>`s to add: attribute, values (`;`-separated, SMIL), timing. */
99
+ animate: Array<CanvasEdgeAnimationTiming & {
100
+ attributeName: 'stroke-dashoffset' | 'stroke-opacity' | 'stroke-width';
101
+ values: string;
102
+ }>;
103
+ };
104
+ export interface CanvasEdgeAnimationRender {
105
+ kind: CanvasEdgeAnimationKind;
106
+ /** Path length in canvas units. */
107
+ length: number;
108
+ /** Opacity for the edge's own stroke. */
109
+ trackOpacity: number;
110
+ /** Whether the elements should move (false when paused, reduced motion or a zero-length path). */
111
+ moving: boolean;
112
+ /**
113
+ * A blur filter to define in `<defs>` when anything glows. Its region is in user space (canvas
114
+ * units, `filterUnits="userSpaceOnUse"`): a straight edge has a zero-height box, and a filter
115
+ * sized to the box would hide it.
116
+ */
117
+ glowFilter?: {
118
+ id: string;
119
+ stdDeviation: number;
120
+ x: number;
121
+ y: number;
122
+ width: number;
123
+ height: number;
124
+ };
125
+ elements: CanvasEdgeAnimationElement[];
126
+ }
127
+ export interface CanvasEdgeAnimationRenderOptions {
128
+ /** SVG path data of the edge (`getCanvasEdgePath(...).path` or the path your edge draws). */
129
+ path: string;
130
+ /** A unique id for this edge's defs (the edge id). */
131
+ id: string;
132
+ /** Colour used when the animation has none (the edge's stroke). Default `currentColor`. */
133
+ stroke?: string;
134
+ /** Draw the first frame without movement (honour `prefers-reduced-motion`). Default false. */
135
+ reducedMotion?: boolean;
136
+ /** A measured path to reuse, when you already have one for `path`. */
137
+ measured?: MeasuredSvgPath;
138
+ }
139
+ /**
140
+ * How to draw an animated edge: SVG elements and SMIL timing, computed from the path. Dots use
141
+ * `<animateMotion>` along the path, dashes and beams animate `stroke-dashoffset`, the pulse animates
142
+ * opacity and width. Nothing here needs a DOM; the React and Svelte `<EdgeAnimation>` render it.
143
+ */
144
+ export declare function getCanvasEdgeAnimationRender(animation: CanvasEdgeAnimation, options: CanvasEdgeAnimationRenderOptions): CanvasEdgeAnimationRender;
145
+ /** The animated part of an edge at one moment. */
146
+ export interface CanvasEdgeAnimationFrame {
147
+ kind: CanvasEdgeAnimationKind;
148
+ length: number;
149
+ /** Dot positions (`dots`). */
150
+ dots: SvgPathPoint[];
151
+ /** Visible stretches of the path as [from, to] distances (`dash`, `beam`), clipped to the path. */
152
+ segments: Array<[number, number]>;
153
+ /** Stroke opacity and width (`pulse`). */
154
+ opacity: number;
155
+ strokeWidth: number;
156
+ }
157
+ /**
158
+ * Where everything is `timeMs` into the animation: the same picture the SVG shows at that time,
159
+ * computed without a browser (for thumbnails, exports, canvas renderers and tests). A paused
160
+ * animation always returns its first frame.
161
+ */
162
+ export declare function sampleCanvasEdgeAnimation(animation: CanvasEdgeAnimation, path: string | MeasuredSvgPath, timeMs: number): CanvasEdgeAnimationFrame;
163
+ /** Edge path styles `<AnimatedEdge>` can draw (read from `edge.data.pathType`). */
164
+ export type CanvasAnimatedEdgePathType = CanvasConnectionLineType;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Edge path geometry for canvas edges, matching xyflow's (`getBezierPath`, `getStraightPath`,
3
+ * `getSimpleBezierPath`, `getSmoothStepPath`) so the same path is drawn with or without React Flow /
4
+ * Svelte Flow, plus a small SVG path measurer (`measureSvgPath`) for placing things along a path.
5
+ * No DOM and no xyflow import.
6
+ */
7
+ import type { CanvasConnectionLineType } from './connectors.cjs';
8
+ import type { Position } from './types.cjs';
9
+ export interface CanvasEdgePathParams {
10
+ sourceX: number;
11
+ sourceY: number;
12
+ targetX: number;
13
+ targetY: number;
14
+ /** Side of the source node the edge leaves from. Default `bottom`. */
15
+ sourcePosition?: Position;
16
+ /** Side of the target node the edge enters. Default `top`. */
17
+ targetPosition?: Position;
18
+ /** Path style, as xyflow's edge `type`. Default `default` (bézier). */
19
+ type?: CanvasConnectionLineType;
20
+ /** Bézier curvature (`default`). Default 0.25. */
21
+ curvature?: number;
22
+ /** Corner radius for `smoothstep`, in canvas units. Default 5 (`step` is 0). */
23
+ borderRadius?: number;
24
+ /** Distance the step paths run straight out of a handle before turning, in canvas units. Default 20. */
25
+ offset?: number;
26
+ }
27
+ export interface CanvasEdgePath {
28
+ /** SVG path data. */
29
+ path: string;
30
+ /** Where a label sits (xyflow's `labelX` / `labelY`). */
31
+ labelX: number;
32
+ labelY: number;
33
+ }
34
+ /**
35
+ * The SVG path of a canvas edge, the same as xyflow draws for that edge `type` (`default` bézier,
36
+ * `straight`, `step`, `smoothstep`, `simplebezier`), with the label position.
37
+ */
38
+ export declare function getCanvasEdgePath(params: CanvasEdgePathParams): CanvasEdgePath;
39
+ /** A point on a path with the direction of travel there (radians, 0 = +x). */
40
+ export interface SvgPathPoint {
41
+ x: number;
42
+ y: number;
43
+ angle: number;
44
+ }
45
+ export interface MeasuredSvgPath {
46
+ /** Total length in path units. */
47
+ length: number;
48
+ /** Bounding box of the flattened path. */
49
+ bounds: {
50
+ x: number;
51
+ y: number;
52
+ width: number;
53
+ height: number;
54
+ };
55
+ /** The point `distance` along the path (clamped to [0, length]). */
56
+ pointAt(distance: number): SvgPathPoint;
57
+ }
58
+ /**
59
+ * Measures SVG path data (M, L, H, V, C, S, Q, T, Z, absolute or relative; arcs are drawn as
60
+ * straight lines). Curves are flattened to `segments` pieces each (default 24), which is well under
61
+ * a canvas unit of error for edge-sized curves.
62
+ */
63
+ export declare function measureSvgPath(d: string, segments?: number): MeasuredSvgPath;