@cascivo/flow 1.6.0 → 1.7.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.
- package/README.md +0 -1
- package/dist/index.d.ts +72 -205
- package/dist/index.js +1 -1
- package/dist/node/index.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|

|
|
12
12
|
|
|
13
13
|
[npm](https://www.npmjs.com/package/@cascivo/flow) · [cascivo.com](https://cascivo.com) · [Docs](https://cascivo.com/docs) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/cascivo/cascivo)
|
|
14
|
-
|
|
15
14
|
</div>
|
|
16
15
|
|
|
17
16
|
---
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReadonlySignal, Signal } from "@cascivo/core";
|
|
2
2
|
import { CSSProperties, HTMLAttributes, ReactNode, RefObject } from "react";
|
|
3
|
-
|
|
4
3
|
/** Shared geometry + graph types for the flow engine. */
|
|
5
4
|
interface XYPosition {
|
|
6
5
|
x: number;
|
|
@@ -55,8 +54,8 @@ interface Connection {
|
|
|
55
54
|
targetHandle?: string | undefined;
|
|
56
55
|
}
|
|
57
56
|
/** Default node footprint when a node has no explicit/measured size. */
|
|
58
|
-
declare const DEFAULT_NODE_SIZE: NodeSize;
|
|
59
|
-
interface UseFlowOptions {
|
|
57
|
+
export declare const DEFAULT_NODE_SIZE: NodeSize;
|
|
58
|
+
export interface UseFlowOptions {
|
|
60
59
|
/** Controlled nodes. When provided, the parent owns node state. */
|
|
61
60
|
nodes?: FlowNode$1[] | undefined;
|
|
62
61
|
defaultNodes?: FlowNode$1[] | undefined;
|
|
@@ -70,7 +69,7 @@ interface UseFlowOptions {
|
|
|
70
69
|
defaultViewport?: Viewport | undefined;
|
|
71
70
|
onViewportChange?: ((viewport: Viewport) => void) | undefined;
|
|
72
71
|
}
|
|
73
|
-
interface FlowStore {
|
|
72
|
+
export interface FlowStore {
|
|
74
73
|
nodes: Signal<FlowNode$1[]>;
|
|
75
74
|
edges: Signal<FlowEdge$1[]>;
|
|
76
75
|
viewport: Signal<Viewport>;
|
|
@@ -84,37 +83,37 @@ interface FlowStore {
|
|
|
84
83
|
* The flow state model — plain signals (no Zustand, no MVX). `nodes`, `edges`,
|
|
85
84
|
* and `viewport` are controllable signals with action helpers. No banned hooks.
|
|
86
85
|
*/
|
|
87
|
-
declare function useFlow(options?: UseFlowOptions): FlowStore;
|
|
86
|
+
export declare function useFlow(options?: UseFlowOptions): FlowStore;
|
|
88
87
|
/** Clamp a zoom level into the allowed range. */
|
|
89
|
-
declare function clampZoom(zoom: number, min?: number, max?: number): number;
|
|
88
|
+
export declare function clampZoom(zoom: number, min?: number, max?: number): number;
|
|
90
89
|
/**
|
|
91
90
|
* Convert a screen-space point (relative to the pane origin) into flow
|
|
92
91
|
* coordinates. Inverse of `flowToScreen`. The pane applies
|
|
93
92
|
* `translate(viewport.x, viewport.y) scale(viewport.zoom)` with origin `0 0`,
|
|
94
93
|
* so a flow point maps to `p * zoom + translate`.
|
|
95
94
|
*/
|
|
96
|
-
declare function screenToFlow(point: XYPosition, viewport: Viewport): XYPosition;
|
|
95
|
+
export declare function screenToFlow(point: XYPosition, viewport: Viewport): XYPosition;
|
|
97
96
|
/** Convert a flow-space point into screen coordinates (relative to the pane origin). */
|
|
98
|
-
declare function flowToScreen(point: XYPosition, viewport: Viewport): XYPosition;
|
|
99
|
-
interface Rect {
|
|
97
|
+
export declare function flowToScreen(point: XYPosition, viewport: Viewport): XYPosition;
|
|
98
|
+
export interface Rect {
|
|
100
99
|
x: number;
|
|
101
100
|
y: number;
|
|
102
101
|
width: number;
|
|
103
102
|
height: number;
|
|
104
103
|
}
|
|
105
|
-
interface Size {
|
|
104
|
+
export interface Size {
|
|
106
105
|
width: number;
|
|
107
106
|
height: number;
|
|
108
107
|
}
|
|
109
108
|
/** The effective size of a node (explicit/measured, else the default footprint). */
|
|
110
|
-
declare function nodeSize(node: FlowNode$1): NodeSize;
|
|
109
|
+
export declare function nodeSize(node: FlowNode$1): NodeSize;
|
|
111
110
|
/** The node's bounding rectangle in flow coordinates. */
|
|
112
|
-
declare function nodeBounds(node: FlowNode$1): Rect;
|
|
111
|
+
export declare function nodeBounds(node: FlowNode$1): Rect;
|
|
113
112
|
/** The `{x,y}` (flow coords) where an edge attaches for a given handle position. */
|
|
114
|
-
declare function handleAnchor(node: FlowNode$1, position: HandlePosition): XYPosition;
|
|
113
|
+
export declare function handleAnchor(node: FlowNode$1, position: HandlePosition): XYPosition;
|
|
115
114
|
/** Bounding box (flow coords) enclosing all nodes — the input to fit-view. */
|
|
116
|
-
declare function graphBounds(nodes: readonly FlowNode$1[]): Rect | null;
|
|
117
|
-
interface FitViewportOptions {
|
|
115
|
+
export declare function graphBounds(nodes: readonly FlowNode$1[]): Rect | null;
|
|
116
|
+
export interface FitViewportOptions {
|
|
118
117
|
/** Fractional padding around the graph (0.1 = 10% on each side). */
|
|
119
118
|
padding?: number;
|
|
120
119
|
minZoom?: number;
|
|
@@ -124,41 +123,38 @@ interface FitViewportOptions {
|
|
|
124
123
|
* Compute the `viewport` (x/y/zoom) that frames `bounds` inside a container of
|
|
125
124
|
* `container` size, with padding. Pure math — testable with injected sizes.
|
|
126
125
|
*/
|
|
127
|
-
declare function fitViewport(bounds: Rect, container: Size, options?: FitViewportOptions): Viewport;
|
|
128
|
-
interface EdgePathParams {
|
|
126
|
+
export declare function fitViewport(bounds: Rect, container: Size, options?: FitViewportOptions): Viewport;
|
|
127
|
+
export interface EdgePathParams {
|
|
129
128
|
source: XYPosition;
|
|
130
129
|
target: XYPosition;
|
|
131
130
|
sourcePosition?: HandlePosition;
|
|
132
131
|
targetPosition?: HandlePosition;
|
|
133
132
|
}
|
|
134
|
-
interface EdgePath {
|
|
133
|
+
export interface EdgePath {
|
|
135
134
|
/** The SVG `d` attribute. */
|
|
136
135
|
d: string;
|
|
137
136
|
/** The path midpoint — where an edge label is placed. */
|
|
138
137
|
mid: XYPosition;
|
|
139
138
|
}
|
|
140
139
|
/** A straight line from source to target. */
|
|
141
|
-
declare function straightPath({
|
|
142
|
-
source,
|
|
143
|
-
target
|
|
144
|
-
}: EdgePathParams): EdgePath;
|
|
140
|
+
export declare function straightPath({ source, target }: EdgePathParams): EdgePath;
|
|
145
141
|
/**
|
|
146
142
|
* A cubic-bezier edge with control points offset along each handle's outward
|
|
147
143
|
* normal. `curvature` scales the control distance relative to the endpoint gap.
|
|
148
144
|
*/
|
|
149
|
-
declare function bezierPath(params: EdgePathParams & {
|
|
145
|
+
export declare function bezierPath(params: EdgePathParams & {
|
|
150
146
|
curvature?: number;
|
|
151
147
|
}): EdgePath;
|
|
152
148
|
/**
|
|
153
149
|
* An orthogonal "step" edge with rounded corners. Splits perpendicular to the
|
|
154
150
|
* source handle's orientation (horizontal handle → vertical split, and vice versa).
|
|
155
151
|
*/
|
|
156
|
-
declare function smoothStepPath(params: EdgePathParams & {
|
|
152
|
+
export declare function smoothStepPath(params: EdgePathParams & {
|
|
157
153
|
borderRadius?: number;
|
|
158
154
|
}): EdgePath;
|
|
159
155
|
/** Dispatch to the builder for `type`. */
|
|
160
|
-
declare function edgePath(type: EdgePathType, params: EdgePathParams): EdgePath;
|
|
161
|
-
interface GridLayoutOptions {
|
|
156
|
+
export declare function edgePath(type: EdgePathType, params: EdgePathParams): EdgePath;
|
|
157
|
+
export interface GridLayoutOptions {
|
|
162
158
|
columns?: number;
|
|
163
159
|
gap?: number;
|
|
164
160
|
nodeWidth?: number;
|
|
@@ -168,8 +164,8 @@ interface GridLayoutOptions {
|
|
|
168
164
|
* Arrange nodes in a simple grid. Pure — returns new nodes with computed
|
|
169
165
|
* `position`s. Bring your own layout for complex graphs.
|
|
170
166
|
*/
|
|
171
|
-
declare function gridLayout(nodes: FlowNode$1[], options?: GridLayoutOptions): FlowNode$1[];
|
|
172
|
-
interface LayeredLayoutOptions {
|
|
167
|
+
export declare function gridLayout(nodes: FlowNode$1[], options?: GridLayoutOptions): FlowNode$1[];
|
|
168
|
+
export interface LayeredLayoutOptions {
|
|
173
169
|
/** 'LR' = left→right (default), 'TB' = top→bottom. */
|
|
174
170
|
direction?: 'LR' | 'TB';
|
|
175
171
|
gap?: number;
|
|
@@ -181,28 +177,28 @@ interface LayeredLayoutOptions {
|
|
|
181
177
|
* the longest path from a root; nodes share a layer along the cross axis. Pure,
|
|
182
178
|
* deterministic. Documented as basic — bring your own layout for complex graphs.
|
|
183
179
|
*/
|
|
184
|
-
declare function layeredLayout(nodes: FlowNode$1[], edges: FlowEdge$1[], options?: LayeredLayoutOptions): FlowNode$1[];
|
|
185
|
-
type LayoutStrategy = 'grid' | 'layered' | ((nodes: FlowNode$1[], edges: FlowEdge$1[]) => FlowNode$1[]);
|
|
180
|
+
export declare function layeredLayout(nodes: FlowNode$1[], edges: FlowEdge$1[], options?: LayeredLayoutOptions): FlowNode$1[];
|
|
181
|
+
export type LayoutStrategy = 'grid' | 'layered' | ((nodes: FlowNode$1[], edges: FlowEdge$1[]) => FlowNode$1[]);
|
|
186
182
|
/** Apply a layout strategy to nodes. */
|
|
187
|
-
declare function applyLayout(nodes: FlowNode$1[], edges: FlowEdge$1[], layout: LayoutStrategy): FlowNode$1[];
|
|
188
|
-
interface StoryStepBase {
|
|
183
|
+
export declare function applyLayout(nodes: FlowNode$1[], edges: FlowEdge$1[], layout: LayoutStrategy): FlowNode$1[];
|
|
184
|
+
export interface StoryStepBase {
|
|
189
185
|
label?: string | undefined;
|
|
190
186
|
description?: string | undefined;
|
|
191
187
|
/** Override the default per-step duration (ms). */
|
|
192
188
|
duration?: number | undefined;
|
|
193
189
|
}
|
|
194
190
|
/** A step expressed as a node pair — the engine finds the connecting edge. */
|
|
195
|
-
interface StoryStepFromTo extends StoryStepBase {
|
|
191
|
+
export interface StoryStepFromTo extends StoryStepBase {
|
|
196
192
|
from: string;
|
|
197
193
|
to: string;
|
|
198
194
|
}
|
|
199
195
|
/** A power-user step that names the edge directly. */
|
|
200
|
-
interface StoryStepEdge extends StoryStepBase {
|
|
196
|
+
export interface StoryStepEdge extends StoryStepBase {
|
|
201
197
|
edge: string;
|
|
202
198
|
reverse?: boolean | undefined;
|
|
203
199
|
}
|
|
204
|
-
type StoryStep = StoryStepFromTo | StoryStepEdge;
|
|
205
|
-
interface ResolvedStep {
|
|
200
|
+
export type StoryStep = StoryStepFromTo | StoryStepEdge;
|
|
201
|
+
export interface ResolvedStep {
|
|
206
202
|
edgeId: string;
|
|
207
203
|
direction: 'forward' | 'reverse';
|
|
208
204
|
label?: string | undefined;
|
|
@@ -214,10 +210,10 @@ interface ResolvedStep {
|
|
|
214
210
|
* edge connecting the pair in either orientation (so one `A<->B` edge serves
|
|
215
211
|
* both `A→B` and `B→A`). Throws on a step that matches no edge (fail-fast).
|
|
216
212
|
*/
|
|
217
|
-
declare function resolveStep(step: StoryStep, edges: readonly FlowEdge$1[]): ResolvedStep;
|
|
213
|
+
export declare function resolveStep(step: StoryStep, edges: readonly FlowEdge$1[]): ResolvedStep;
|
|
218
214
|
/** Resolve a whole script. Pure + deterministic. */
|
|
219
|
-
declare function resolveScript(script: readonly StoryStep[], edges: readonly FlowEdge$1[]): ResolvedStep[];
|
|
220
|
-
interface UseViewportOptions {
|
|
215
|
+
export declare function resolveScript(script: readonly StoryStep[], edges: readonly FlowEdge$1[]): ResolvedStep[];
|
|
216
|
+
export interface UseViewportOptions {
|
|
221
217
|
minZoom?: number | undefined;
|
|
222
218
|
maxZoom?: number | undefined;
|
|
223
219
|
/** Drag the empty pane to pan. Default true. */
|
|
@@ -229,7 +225,7 @@ interface UseViewportOptions {
|
|
|
229
225
|
/** Frame the graph once, when the container is first measured. Default false. */
|
|
230
226
|
fitOnInit?: boolean | undefined;
|
|
231
227
|
}
|
|
232
|
-
interface UseViewportReturn {
|
|
228
|
+
export interface UseViewportReturn {
|
|
233
229
|
/** Outer clipping container — attach for wheel + size measurement. */
|
|
234
230
|
containerRef: RefObject<HTMLDivElement | null>;
|
|
235
231
|
/** Background drag-surface (behind nodes) — the pan handle. */
|
|
@@ -250,8 +246,8 @@ interface UseViewportReturn {
|
|
|
250
246
|
* listener in `useSignalEffect`; fit-view composes `graphBounds` + the measured
|
|
251
247
|
* container size. No `useState`/`useEffect`.
|
|
252
248
|
*/
|
|
253
|
-
declare function useViewport(flow: FlowStore, options?: UseViewportOptions): UseViewportReturn;
|
|
254
|
-
interface ConnectionState {
|
|
249
|
+
export declare function useViewport(flow: FlowStore, options?: UseViewportOptions): UseViewportReturn;
|
|
250
|
+
export interface ConnectionState {
|
|
255
251
|
source: string;
|
|
256
252
|
sourceHandle?: string | undefined;
|
|
257
253
|
/** Source anchor (flow coords) — the live path origin. */
|
|
@@ -259,7 +255,7 @@ interface ConnectionState {
|
|
|
259
255
|
/** Current pointer (flow coords) — the live path end. */
|
|
260
256
|
to: XYPosition;
|
|
261
257
|
}
|
|
262
|
-
interface UseConnectionOptions {
|
|
258
|
+
export interface UseConnectionOptions {
|
|
263
259
|
/** The canvas container; pointerdown on a source handle within it starts a connection. */
|
|
264
260
|
containerRef: RefObject<HTMLElement | null>;
|
|
265
261
|
/** Convert client (screen) coordinates to flow coordinates. */
|
|
@@ -269,7 +265,7 @@ interface UseConnectionOptions {
|
|
|
269
265
|
/** When false, interactive connect is disabled (view mode). Default true. */
|
|
270
266
|
enabled?: boolean | undefined;
|
|
271
267
|
}
|
|
272
|
-
interface UseConnectionReturn {
|
|
268
|
+
export interface UseConnectionReturn {
|
|
273
269
|
/** The in-progress connection, or null. The canvas draws a live path from it. */
|
|
274
270
|
connection: ReadonlySignal<ConnectionState | null>;
|
|
275
271
|
}
|
|
@@ -279,12 +275,12 @@ interface UseConnectionReturn {
|
|
|
279
275
|
* side effects live in `useSignalEffect`; SSR-guarded; no pointer capture (so
|
|
280
276
|
* `pointerup.target` resolves to the handle under the pointer).
|
|
281
277
|
*/
|
|
282
|
-
declare function useConnection(options: UseConnectionOptions): UseConnectionReturn;
|
|
283
|
-
interface StoryClock {
|
|
278
|
+
export declare function useConnection(options: UseConnectionOptions): UseConnectionReturn;
|
|
279
|
+
export interface StoryClock {
|
|
284
280
|
setTimeout: (callback: () => void, ms: number) => unknown;
|
|
285
281
|
clearTimeout: (handle: unknown) => void;
|
|
286
282
|
}
|
|
287
|
-
interface UseStoryOptions {
|
|
283
|
+
export interface UseStoryOptions {
|
|
288
284
|
steps: ResolvedStep[];
|
|
289
285
|
loop?: boolean | undefined;
|
|
290
286
|
/** Controlled play state. */
|
|
@@ -302,7 +298,7 @@ interface UseStoryOptions {
|
|
|
302
298
|
/** Injectable clock for deterministic tests (default real timers). */
|
|
303
299
|
clock?: StoryClock | undefined;
|
|
304
300
|
}
|
|
305
|
-
interface UseStoryReturn {
|
|
301
|
+
export interface UseStoryReturn {
|
|
306
302
|
currentStep: Signal<number>;
|
|
307
303
|
playing: Signal<boolean>;
|
|
308
304
|
activeStep: ReadonlySignal<ResolvedStep | null>;
|
|
@@ -318,8 +314,8 @@ interface UseStoryReturn {
|
|
|
318
314
|
* `useSignalEffect` (the carousel/relative-time idiom) with an injectable clock
|
|
319
315
|
* for deterministic tests. Loops when `loop`. No `useEffect`/wall-clock.
|
|
320
316
|
*/
|
|
321
|
-
declare function useStory(options: UseStoryOptions): UseStoryReturn;
|
|
322
|
-
interface FlowCanvasProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
317
|
+
export declare function useStory(options: UseStoryOptions): UseStoryReturn;
|
|
318
|
+
export interface FlowCanvasProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
323
319
|
children?: ReactNode;
|
|
324
320
|
/** Share an external store (e.g. from `<Flow>`). When omitted, an internal one is created. */
|
|
325
321
|
flow?: FlowStore;
|
|
@@ -346,25 +342,9 @@ interface FlowCanvasProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange
|
|
|
346
342
|
* signal, with drag-to-pan, wheel zoom, and fit-view. Renders `children`
|
|
347
343
|
* (background, nodes, edges) inside the transformed pane. `useSignals()` first.
|
|
348
344
|
*/
|
|
349
|
-
declare function FlowCanvas({
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
viewport: viewportProp,
|
|
353
|
-
defaultViewport,
|
|
354
|
-
onViewportChange,
|
|
355
|
-
minZoom,
|
|
356
|
-
maxZoom,
|
|
357
|
-
panOnDrag,
|
|
358
|
-
zoomOnScroll,
|
|
359
|
-
fitView,
|
|
360
|
-
controller: controllerProp,
|
|
361
|
-
chrome,
|
|
362
|
-
className,
|
|
363
|
-
role,
|
|
364
|
-
...rest
|
|
365
|
-
}: FlowCanvasProps): import("react").JSX.Element;
|
|
366
|
-
type FlowBackgroundVariant = 'dots' | 'grid' | 'cross';
|
|
367
|
-
interface FlowBackgroundProps extends HTMLAttributes<HTMLDivElement> {
|
|
345
|
+
export declare function FlowCanvas({ children, flow, viewport: viewportProp, defaultViewport, onViewportChange, minZoom, maxZoom, panOnDrag, zoomOnScroll, fitView, controller: controllerProp, chrome, className, role, ...rest }: FlowCanvasProps): import("react").JSX.Element;
|
|
346
|
+
export type FlowBackgroundVariant = 'dots' | 'grid' | 'cross';
|
|
347
|
+
export interface FlowBackgroundProps extends HTMLAttributes<HTMLDivElement> {
|
|
368
348
|
/** Pattern style. Default `dots`. */
|
|
369
349
|
variant?: FlowBackgroundVariant;
|
|
370
350
|
/** Distance between pattern cells, in flow px. Default 20. */
|
|
@@ -381,16 +361,8 @@ interface FlowBackgroundProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
381
361
|
* scales with the viewport for free. `pointer-events: none` — clicks fall
|
|
382
362
|
* through to the pan surface.
|
|
383
363
|
*/
|
|
384
|
-
declare function FlowBackground({
|
|
385
|
-
|
|
386
|
-
gap,
|
|
387
|
-
size,
|
|
388
|
-
color,
|
|
389
|
-
className,
|
|
390
|
-
style,
|
|
391
|
-
...rest
|
|
392
|
-
}: FlowBackgroundProps): import("react").JSX.Element;
|
|
393
|
-
interface FlowNodeProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect'> {
|
|
364
|
+
export declare function FlowBackground({ variant, gap, size, color, className, style, ...rest }: FlowBackgroundProps): import("react").JSX.Element;
|
|
365
|
+
export interface FlowNodeProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect'> {
|
|
394
366
|
id: string;
|
|
395
367
|
/** Position in flow coordinates (controllable). */
|
|
396
368
|
position?: XYPosition;
|
|
@@ -414,24 +386,8 @@ interface FlowNodeProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect'>
|
|
|
414
386
|
* `data-selected`, and renders arbitrary themed cascivo children.
|
|
415
387
|
* `useSignals()` first; no `useState`/`useEffect`.
|
|
416
388
|
*/
|
|
417
|
-
declare function FlowNode({
|
|
418
|
-
|
|
419
|
-
position,
|
|
420
|
-
defaultPosition,
|
|
421
|
-
onPositionChange,
|
|
422
|
-
onMeasure,
|
|
423
|
-
zoom,
|
|
424
|
-
selected,
|
|
425
|
-
draggable,
|
|
426
|
-
interactive,
|
|
427
|
-
onSelect,
|
|
428
|
-
children,
|
|
429
|
-
className,
|
|
430
|
-
onClick,
|
|
431
|
-
onKeyDown,
|
|
432
|
-
...rest
|
|
433
|
-
}: FlowNodeProps): import("react").JSX.Element;
|
|
434
|
-
interface FlowHandleProps extends HTMLAttributes<HTMLDivElement> {
|
|
389
|
+
export declare function FlowNode({ id, position, defaultPosition, onPositionChange, onMeasure, zoom, selected, draggable, interactive, onSelect, children, className, onClick, onKeyDown, ...rest }: FlowNodeProps): import("react").JSX.Element;
|
|
390
|
+
export interface FlowHandleProps extends HTMLAttributes<HTMLDivElement> {
|
|
435
391
|
type: 'source' | 'target';
|
|
436
392
|
/** Edge of the node the port sits on. Defaults by type (source→right, target→left). */
|
|
437
393
|
position?: HandlePosition;
|
|
@@ -445,15 +401,8 @@ interface FlowHandleProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
445
401
|
* interactive connect (T5) starts/ends. Renders a small dot inside a ≥44px
|
|
446
402
|
* coarse-pointer hit area; keyboard-focusable. No internal state.
|
|
447
403
|
*/
|
|
448
|
-
declare function FlowHandle({
|
|
449
|
-
|
|
450
|
-
position,
|
|
451
|
-
id,
|
|
452
|
-
isConnectable,
|
|
453
|
-
className,
|
|
454
|
-
...rest
|
|
455
|
-
}: FlowHandleProps): import("react").JSX.Element;
|
|
456
|
-
interface FlowEdgeProps {
|
|
404
|
+
export declare function FlowHandle({ type, position, id, isConnectable, className, ...rest }: FlowHandleProps): import("react").JSX.Element;
|
|
405
|
+
export interface FlowEdgeProps {
|
|
457
406
|
id?: string;
|
|
458
407
|
/** Resolved source anchor (flow coords). */
|
|
459
408
|
sourceX: number;
|
|
@@ -483,31 +432,14 @@ interface FlowEdgeProps {
|
|
|
483
432
|
* `label`) an HTML label at the midpoint. Animation is CSS-only.
|
|
484
433
|
* `useSignals()` first; no `useState`/`useEffect`.
|
|
485
434
|
*/
|
|
486
|
-
declare function FlowEdge({
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
sourceY,
|
|
490
|
-
targetX,
|
|
491
|
-
targetY,
|
|
492
|
-
sourcePosition,
|
|
493
|
-
targetPosition,
|
|
494
|
-
type,
|
|
495
|
-
animated,
|
|
496
|
-
label,
|
|
497
|
-
selected,
|
|
498
|
-
markerStart,
|
|
499
|
-
markerEnd,
|
|
500
|
-
direction,
|
|
501
|
-
active,
|
|
502
|
-
className
|
|
503
|
-
}: FlowEdgeProps): import("react").JSX.Element;
|
|
504
|
-
type FlowChromePosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
505
|
-
interface FlowControlsLabels {
|
|
435
|
+
export declare function FlowEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, type, animated, label, selected, markerStart, markerEnd, direction, active, className }: FlowEdgeProps): import("react").JSX.Element;
|
|
436
|
+
export type FlowChromePosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
437
|
+
export interface FlowControlsLabels {
|
|
506
438
|
zoomIn?: string;
|
|
507
439
|
zoomOut?: string;
|
|
508
440
|
fitView?: string;
|
|
509
441
|
}
|
|
510
|
-
interface FlowControlsProps extends HTMLAttributes<HTMLDivElement> {
|
|
442
|
+
export interface FlowControlsProps extends HTMLAttributes<HTMLDivElement> {
|
|
511
443
|
position?: FlowChromePosition;
|
|
512
444
|
showZoom?: boolean;
|
|
513
445
|
showFitView?: boolean;
|
|
@@ -522,18 +454,8 @@ interface FlowControlsProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
522
454
|
* i18n-defaulted aria-labels. Calls the viewport actions passed in.
|
|
523
455
|
* `useSignals()` first (reads the locale signal via `t`).
|
|
524
456
|
*/
|
|
525
|
-
declare function FlowControls({
|
|
526
|
-
|
|
527
|
-
showZoom,
|
|
528
|
-
showFitView,
|
|
529
|
-
onZoomIn,
|
|
530
|
-
onZoomOut,
|
|
531
|
-
onFitView,
|
|
532
|
-
labels,
|
|
533
|
-
className,
|
|
534
|
-
...rest
|
|
535
|
-
}: FlowControlsProps): import("react").JSX.Element;
|
|
536
|
-
interface FlowMiniMapProps {
|
|
457
|
+
export declare function FlowControls({ position, showZoom, showFitView, onZoomIn, onZoomOut, onFitView, labels, className, ...rest }: FlowControlsProps): import("react").JSX.Element;
|
|
458
|
+
export interface FlowMiniMapProps {
|
|
537
459
|
nodes: FlowNode$1[];
|
|
538
460
|
viewport: Viewport;
|
|
539
461
|
/** Canvas size — used to draw the visible-region rectangle. */
|
|
@@ -559,22 +481,9 @@ interface FlowMiniMapProps {
|
|
|
559
481
|
* A scaled SVG overview of the graph with a draggable viewport rectangle.
|
|
560
482
|
* Dragging the rectangle pans the main viewport. `useSignals()` first.
|
|
561
483
|
*/
|
|
562
|
-
declare function FlowMiniMap({
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
containerWidth,
|
|
566
|
-
containerHeight,
|
|
567
|
-
width,
|
|
568
|
-
height,
|
|
569
|
-
position,
|
|
570
|
-
nodeColor,
|
|
571
|
-
onViewportChange,
|
|
572
|
-
label,
|
|
573
|
-
ariaLabel,
|
|
574
|
-
className
|
|
575
|
-
}: FlowMiniMapProps): import("react").JSX.Element;
|
|
576
|
-
type FlowPanelPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
577
|
-
interface FlowPanelProps extends HTMLAttributes<HTMLDivElement> {
|
|
484
|
+
export declare function FlowMiniMap({ nodes, viewport, containerWidth, containerHeight, width, height, position, nodeColor, onViewportChange, label, ariaLabel, className }: FlowMiniMapProps): import("react").JSX.Element;
|
|
485
|
+
export type FlowPanelPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
486
|
+
export interface FlowPanelProps extends HTMLAttributes<HTMLDivElement> {
|
|
578
487
|
position?: FlowPanelPosition;
|
|
579
488
|
children?: ReactNode;
|
|
580
489
|
className?: string;
|
|
@@ -583,16 +492,11 @@ interface FlowPanelProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
583
492
|
* An absolutely-positioned slot for custom UI on a flow canvas (a legend, a
|
|
584
493
|
* toolbar). Pure presentational — no state.
|
|
585
494
|
*/
|
|
586
|
-
declare function FlowPanel({
|
|
587
|
-
|
|
588
|
-
children,
|
|
589
|
-
className,
|
|
590
|
-
...rest
|
|
591
|
-
}: FlowPanelProps): import("react").JSX.Element;
|
|
592
|
-
type NodeRenderer = (args: {
|
|
495
|
+
export declare function FlowPanel({ position, children, className, ...rest }: FlowPanelProps): import("react").JSX.Element;
|
|
496
|
+
export type NodeRenderer = (args: {
|
|
593
497
|
node: FlowNode$1;
|
|
594
498
|
}) => ReactNode;
|
|
595
|
-
interface FlowProps {
|
|
499
|
+
export interface FlowProps {
|
|
596
500
|
/** Initial nodes (serializable — an agent can emit these as JSON). */
|
|
597
501
|
nodes: FlowNode$1[];
|
|
598
502
|
/** Initial edges. */
|
|
@@ -631,34 +535,15 @@ interface FlowProps {
|
|
|
631
535
|
* plain serializable data. Composes the canvas, background, nodes, edges,
|
|
632
536
|
* interactive connect, and optional chrome. `useSignals()` first; no banned hooks.
|
|
633
537
|
*/
|
|
634
|
-
declare function Flow({
|
|
635
|
-
|
|
636
|
-
edges,
|
|
637
|
-
onNodesChange,
|
|
638
|
-
onEdgesChange,
|
|
639
|
-
onConnect,
|
|
640
|
-
nodeTypes,
|
|
641
|
-
fitView,
|
|
642
|
-
background,
|
|
643
|
-
controls,
|
|
644
|
-
minimap,
|
|
645
|
-
layout,
|
|
646
|
-
minZoom,
|
|
647
|
-
maxZoom,
|
|
648
|
-
interactive,
|
|
649
|
-
activeEdgeId,
|
|
650
|
-
activeDirection,
|
|
651
|
-
className,
|
|
652
|
-
style
|
|
653
|
-
}: FlowProps): import("react").JSX.Element;
|
|
654
|
-
interface FlowStoryLabels {
|
|
538
|
+
export declare function Flow({ nodes, edges, onNodesChange, onEdgesChange, onConnect, nodeTypes, fitView, background, controls, minimap, layout, minZoom, maxZoom, interactive, activeEdgeId, activeDirection, className, style }: FlowProps): import("react").JSX.Element;
|
|
539
|
+
export interface FlowStoryLabels {
|
|
655
540
|
play?: string;
|
|
656
541
|
pause?: string;
|
|
657
542
|
next?: string;
|
|
658
543
|
previous?: string;
|
|
659
544
|
restart?: string;
|
|
660
545
|
}
|
|
661
|
-
interface FlowStoryProps {
|
|
546
|
+
export interface FlowStoryProps {
|
|
662
547
|
nodes: FlowNode$1[];
|
|
663
548
|
edges: FlowEdge$1[];
|
|
664
549
|
/** The storyboard: an ordered, serializable list of steps. */
|
|
@@ -693,23 +578,5 @@ interface FlowStoryProps {
|
|
|
693
578
|
* `<Flow>` and drives the active edge via a `currentStep` signal.
|
|
694
579
|
* `useSignals()` first; no banned hooks.
|
|
695
580
|
*/
|
|
696
|
-
declare function FlowStory({
|
|
697
|
-
|
|
698
|
-
edges,
|
|
699
|
-
script,
|
|
700
|
-
loop,
|
|
701
|
-
stepDuration,
|
|
702
|
-
stepGap,
|
|
703
|
-
playing,
|
|
704
|
-
currentStep,
|
|
705
|
-
onStepChange,
|
|
706
|
-
controls,
|
|
707
|
-
autoPlay,
|
|
708
|
-
background,
|
|
709
|
-
interactive,
|
|
710
|
-
labels,
|
|
711
|
-
clock,
|
|
712
|
-
className,
|
|
713
|
-
style
|
|
714
|
-
}: FlowStoryProps): import("react").JSX.Element;
|
|
715
|
-
export { type Connection, ConnectionState, DEFAULT_NODE_SIZE, EdgePath, EdgePathParams, type EdgePathType, FitViewportOptions, Flow, FlowBackground, FlowBackgroundProps, FlowBackgroundVariant, FlowCanvas, FlowCanvasProps, FlowChromePosition, FlowControls, FlowControlsLabels, FlowControlsProps, FlowEdge, type FlowEdge$1 as FlowEdgeData, FlowEdgeProps, FlowHandle, FlowHandleProps, FlowMiniMap, FlowMiniMapProps, FlowNode, type FlowNode$1 as FlowNodeData, FlowNodeProps, FlowPanel, FlowPanelPosition, FlowPanelProps, FlowProps, FlowStore, FlowStory, FlowStoryLabels, FlowStoryProps, GridLayoutOptions, type HandlePosition, LayeredLayoutOptions, LayoutStrategy, NodeRenderer, type NodeSize, Rect, ResolvedStep, Size, StoryClock, StoryStep, StoryStepBase, StoryStepEdge, StoryStepFromTo, UseConnectionOptions, UseConnectionReturn, UseFlowOptions, UseStoryOptions, UseStoryReturn, UseViewportOptions, UseViewportReturn, type Viewport, type XYPosition, applyLayout, bezierPath, clampZoom, edgePath, fitViewport, flowToScreen, graphBounds, gridLayout, handleAnchor, layeredLayout, nodeBounds, nodeSize, resolveScript, resolveStep, screenToFlow, smoothStepPath, straightPath, useConnection, useFlow, useStory, useViewport };
|
|
581
|
+
export declare function FlowStory({ nodes, edges, script, loop, stepDuration, stepGap, playing, currentStep, onStepChange, controls, autoPlay, background, interactive, labels, clock, className, style }: FlowStoryProps): import("react").JSX.Element;
|
|
582
|
+
export type { Connection, EdgePathType, FlowEdge$1 as FlowEdgeData, FlowNode$1 as FlowNodeData, HandlePosition, NodeSize, Viewport, XYPosition };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import './flow.css';
|
|
3
|
-
import{cn as e,useComputed as t,useControllableSignal as r,useDraggable as i,useEffectPropSignal as a,useResizeObserver as o,useSignal as s,useSignalEffect as c,useSignals as l}from"@cascivo/core";import{useId as u,useRef as d}from"react";import{Fragment as f,jsx as p,jsxs as m}from"react/jsx-runtime";import{cn as h}from"@cascivo/core/pure";import{builtin as g,t as _}from"@cascivo/i18n";var v={width:150,height:40},y={x:0,y:0,zoom:1};function useFlow(e={}){let[t,i]=r({value:e.nodes,defaultValue:e.defaultNodes??[],onChange:e.onNodesChange}),[a,o]=r({value:e.edges,defaultValue:e.defaultEdges??[],onChange:e.onEdgesChange}),[s,c]=r({value:e.viewport,defaultValue:e.defaultViewport??y,onChange:e.onViewportChange});return{nodes:t,edges:a,viewport:s,setNodes:i,updateNode:(e,r)=>{i(t.value.map(t=>t.id===e?{...t,...r}:t))},setEdges:o,addEdge:e=>{o([...a.value,e])},setViewport:c}}function clampZoom(e,t=.2,r=2){return Math.min(r,Math.max(t,e))}function screenToFlow(e,t){return{x:(e.x-t.x)/t.zoom,y:(e.y-t.y)/t.zoom}}function flowToScreen(e,t){return{x:e.x*t.zoom+t.x,y:e.y*t.zoom+t.y}}function nodeSize(e){return{width:e.width??v.width,height:e.height??v.height}}function nodeBounds(e){let{width:t,height:r}=nodeSize(e);return{x:e.position.x,y:e.position.y,width:t,height:r}}function handleAnchor(e,t){let{x:r,y:i,width:a,height:o}=nodeBounds(e);switch(t){case`top`:return{x:r+a/2,y:i};case`right`:return{x:r+a,y:i+o/2};case`bottom`:return{x:r+a/2,y:i+o};case`left`:return{x:r,y:i+o/2}}}function graphBounds(e){if(e.length===0)return null;let t=1/0,r=1/0,i=-1/0,a=-1/0;for(let o of e){let e=nodeBounds(o);t=Math.min(t,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.width),a=Math.max(a,e.y+e.height)}return{x:t,y:r,width:i-t,height:a-r}}function fitViewport(e,t,r={}){let{padding:i=.1,minZoom:a=.2,maxZoom:o=2}=r;if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{x:t.width/2-e.x,y:t.height/2-e.y,zoom:1};let s=t.width/(e.width*(1+i*2)),c=t.height/(e.height*(1+i*2)),l=clampZoom(Math.min(s,c),a,o);return{x:t.width/2-(e.x+e.width/2)*l,y:t.height/2-(e.y+e.height/2)*l,zoom:l}}var n=e=>Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,``),midpoint=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});function normal(e){switch(e){case`top`:return{x:0,y:-1};case`bottom`:return{x:0,y:1};case`left`:return{x:-1,y:0};case`right`:return{x:1,y:0}}}function straightPath({source:e,target:t}){return{d:`M${n(e.x)},${n(e.y)} L${n(t.x)},${n(t.y)}`,mid:midpoint(e,t)}}function bezierPath(e){let{source:t,target:r,curvature:i=.25}=e,a=e.sourcePosition??`right`,o=e.targetPosition??`left`,s=Math.hypot(r.x-t.x,r.y-t.y),c=Math.max(i*s,20),l=normal(a),u=normal(o),d={x:t.x+l.x*c,y:t.y+l.y*c},f={x:r.x+u.x*c,y:r.y+u.y*c},p={x:(t.x+3*d.x+3*f.x+r.x)/8,y:(t.y+3*d.y+3*f.y+r.y)/8};return{d:`M${n(t.x)},${n(t.y)} C${n(d.x)},${n(d.y)} ${n(f.x)},${n(f.y)} ${n(r.x)},${n(r.y)}`,mid:p}}function len(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function towards(e,t,r){let i=len(e,t)||1;return{x:e.x+(t.x-e.x)/i*r,y:e.y+(t.y-e.y)/i*r}}function roundedPath(e,t){if(e.length<2)return``;let r=e[0],i=`M${n(r.x)},${n(r.y)}`;for(let r=1;r<e.length-1;r++){let a=e[r-1],o=e[r],s=e[r+1],c=Math.min(t,len(a,o)/2,len(o,s)/2),l=towards(o,a,c),u=towards(o,s,c);i+=` L${n(l.x)},${n(l.y)} Q${n(o.x)},${n(o.y)} ${n(u.x)},${n(u.y)}`}let a=e[e.length-1];return i+=` L${n(a.x)},${n(a.y)}`,i}function smoothStepPath(e){let{source:t,target:r,borderRadius:i=8}=e,a=e.sourcePosition??`right`,o=a===`left`||a===`right`,s=[t];if(o){let e=(t.x+r.x)/2;s.push({x:e,y:t.y},{x:e,y:r.y})}else{let e=(t.y+r.y)/2;s.push({x:t.x,y:e},{x:r.x,y:e})}return s.push(r),{d:roundedPath(s,i),mid:midpoint(t,r)}}function edgePath(e,t){switch(e){case`straight`:return straightPath(t);case`smoothstep`:return smoothStepPath(t);case`bezier`:return bezierPath(t)}}function gridLayout(e,t={}){let r=t.gap??40,i=t.nodeWidth??v.width,a=t.nodeHeight??v.height,o=t.columns??Math.max(1,Math.ceil(Math.sqrt(e.length)));return e.map((e,t)=>{let s=t%o,c=Math.floor(t/o);return{...e,position:{x:s*(i+r),y:c*(a+r)}}})}function layeredLayout(e,t,r={}){let i=r.direction??`LR`,a=r.gap??60,o=r.nodeWidth??v.width,s=r.nodeHeight??v.height,c=new Set(e.map(e=>e.id)),l=new Map,u=new Map;for(let t of e)u.set(t.id,0);for(let e of t)!c.has(e.source)||!c.has(e.target)||(l.set(e.source,[...l.get(e.source)??[],e.target]),u.set(e.target,(u.get(e.target)??0)+1));let d=new Map,f=e.filter(e=>(u.get(e.id)??0)===0).map(e=>e.id);for(let e of f)d.set(e,0);let p=new Map(u);for(;f.length>0;){let e=[];for(let t of f){let r=d.get(t)??0;for(let i of l.get(t)??[])d.set(i,Math.max(d.get(i)??0,r+1)),p.set(i,(p.get(i)??0)-1),(p.get(i)??0)===0&&e.push(i)}f=e}for(let t of e)d.has(t.id)||d.set(t.id,0);let m=new Map,h=new Map;for(let t of e){let e=d.get(t.id)??0,r=h.get(e)??0;m.set(t.id,r),h.set(e,r+1)}return e.map(e=>{let t=d.get(e.id)??0,r=m.get(e.id)??0,c=i===`LR`?{x:t*(o+a),y:r*(s+a)}:{x:r*(o+a),y:t*(s+a)};return{...e,position:c}})}function applyLayout(e,t,r){return r===`grid`?gridLayout(e):r===`layered`?layeredLayout(e,t):r(e,t)}function isEdgeStep(e){return`edge`in e}function resolveStep(e,t){let r={label:e.label,description:e.description,duration:e.duration};if(isEdgeStep(e)){let i=t.find(t=>t.id===e.edge);if(!i)throw Error(`FlowStory: step references unknown edge "${e.edge}"`);return{edgeId:i.id,direction:e.reverse?`reverse`:`forward`,...r}}let i=t.find(t=>t.source===e.from&&t.target===e.to);if(i)return{edgeId:i.id,direction:`forward`,...r};let a=t.find(t=>t.source===e.to&&t.target===e.from);if(a)return{edgeId:a.id,direction:`reverse`,...r};throw Error(`FlowStory: no edge connects "${e.from}" and "${e.to}"`)}function resolveScript(e,t){return e.map(e=>resolveStep(e,t))}var b=1.2;function useViewport(e,t={}){let{minZoom:r=.2,maxZoom:a=2,panOnDrag:s=!0,zoomOnScroll:l=!0,fitPadding:u=.1,fitOnInit:f=!1}=t,{viewport:p,setViewport:m}=e,{ref:h,size:g}=o(),{handleRef:_,offset:v,isDragging:y}=i({isDisabled:!s}),pan=(e,t)=>{let r=p.peek();m({x:r.x+e,y:r.y+t,zoom:r.zoom})},zoomTo=(e,t)=>{let i=p.peek(),o=clampZoom(e,r,a);if(!t){m({x:i.x,y:i.y,zoom:o});return}let s=screenToFlow(t,i);m({x:t.x-s.x*o,y:t.y-s.y*o,zoom:o})},containerCenter=()=>{let e=h.current;if(e)return{x:e.clientWidth/2,y:e.clientHeight/2}},zoomIn=()=>zoomTo(p.peek().zoom*b,containerCenter()),zoomOut=()=>zoomTo(p.peek().zoom/b,containerCenter()),measuredSize=()=>{let e=g.peek();if(e&&e.width>0&&e.height>0)return e;let t=h.current;return t&&t.clientWidth>0?{width:t.clientWidth,height:t.clientHeight}:null},fitView=t=>{let i=graphBounds(e.nodes.peek());if(!i)return;let o=t??measuredSize();o&&m(fitViewport(i,o,{padding:u,minZoom:r,maxZoom:a}))},x=d(null);c(()=>{let e=y.value,t=v.value;if(!s)return;if(!e){x.current=null;return}x.current||={vp:p.peek(),off:t};let r=x.current;m({x:r.vp.x+(t.x-r.off.x),y:r.vp.y+(t.y-r.off.y),zoom:r.vp.zoom})}),c(()=>{if(!l||typeof window>`u`)return;let e=h.current;if(!e)return;let onWheel=t=>{t.preventDefault();let r=e.getBoundingClientRect(),i={x:t.clientX-r.left,y:t.clientY-r.top},a=t.deltaY<0?b:1/b;zoomTo(p.peek().zoom*a,i)};return e.addEventListener(`wheel`,onWheel,{passive:!1}),()=>e.removeEventListener(`wheel`,onWheel)});let S=d(!1);return c(()=>{if(!f||S.current)return;let e=g.value;!e||e.width===0||(S.current=!0,fitView(e))}),{containerRef:h,panHandleRef:_,viewport:p,pan,zoomTo,zoomIn,zoomOut,fitView}}var x=`[data-flow-handle][data-handle-type="source"]`,S=`[data-flow-handle][data-handle-type="target"]`;function useConnection(e){let{containerRef:t}=e,r=s(null),i=d(e.onConnect);i.current=e.onConnect;let o=d(e.isValid);o.current=e.isValid;let l=d(e.clientToFlow);l.current=e.clientToFlow;let u=a(e.enabled??!0);return c(()=>{if(!u.value||typeof window>`u`)return;let e=t.current;if(!e)return;let onMove=e=>{let t=r.peek();t&&(r.value={...t,to:l.current(e.clientX,e.clientY)})},onUp=e=>{let t=r.peek();if(window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp),r.value=null,!t)return;let a=e.target,s=a instanceof Element?a.closest(S):null,c=s?.closest(`[data-node-id]`);if(!c)return;let l={source:t.source,target:c.getAttribute(`data-node-id`)??``,sourceHandle:t.sourceHandle,targetHandle:s?.getAttribute(`data-handle-id`)??void 0};!l.target||l.source===l.target||o.current&&!o.current(l)||i.current?.(l)},onDown=e=>{let t=e.target;if(!(t instanceof Element))return;let i=t.closest(x);if(!i)return;let a=i.closest(`[data-node-id]`);if(!a)return;e.stopPropagation();let o=i.getBoundingClientRect();r.value={source:a.getAttribute(`data-node-id`)??``,sourceHandle:i.getAttribute(`data-handle-id`)??void 0,from:l.current(o.left+o.width/2,o.top+o.height/2),to:l.current(e.clientX,e.clientY)},window.addEventListener(`pointermove`,onMove),window.addEventListener(`pointerup`,onUp)};return e.addEventListener(`pointerdown`,onDown),()=>{e.removeEventListener(`pointerdown`,onDown),window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp)}}),{connection:r}}var C=1500;function useStory(e){let{steps:i,loop:a=!0,stepDuration:o=C,stepGap:s=0}=e,[l,u]=r({value:e.currentStep,defaultValue:e.defaultCurrentStep??0,onChange:e.onStepChange}),[f,p]=r({value:e.playing,defaultValue:e.defaultPlaying??!0,onChange:e.onPlayingChange}),m=t(()=>i[l.value]??null),h=d(e.clock);h.current=e.clock;let g=d(i);g.current=i;let clock=()=>h.current??{setTimeout:(e,t)=>window.setTimeout(e,t),clearTimeout:e=>window.clearTimeout(e)},advance=e=>{let t=g.current.length;if(t===0)return;let r=l.peek()+e;u(a?(r%t+t)%t:Math.max(0,Math.min(t-1,r)))};return c(()=>{if(!f.value)return;let e=l.value,t=i.length;if(t===0||typeof window>`u`&&!h.current)return;let r=(i[e]?.duration??o)+s,c=clock(),d=c.setTimeout(()=>{let r=e+1;r>=t?a?u(0):p(!1):u(r)},r);return()=>c.clearTimeout(d)}),{currentStep:l,playing:f,activeStep:m,play:()=>p(!0),pause:()=>p(!1),toggle:()=>p(!f.peek()),next:()=>advance(1),prev:()=>advance(-1),restart:()=>{u(0),p(!0)}}}var w={canvas:`_canvas_6fiig_2`,pane:`_pane_6fiig_13`,panSurface:`_panSurface_6fiig_24`};function FlowCanvas({children:t,flow:r,viewport:i,defaultViewport:a,onViewportChange:o,minZoom:s,maxZoom:c,panOnDrag:u=!0,zoomOnScroll:d=!0,fitView:f=!1,controller:h,chrome:g,className:_,role:v=`application`,...y}){l();let b=useFlow({viewport:i,defaultViewport:a,onViewportChange:o}),x=r??b,S=useViewport(x,{minZoom:s,maxZoom:c,panOnDrag:u,zoomOnScroll:d,fitOnInit:f}),C=h??S,T=x.viewport.value;return m(`div`,{ref:C.containerRef,className:e(w.canvas,_),role:v,...y,children:[m(`div`,{className:w.pane,style:{"--flow-tx":`${T.x}px`,"--flow-ty":`${T.y}px`,"--flow-scale":String(T.zoom)},children:[p(`div`,{ref:C.panHandleRef,className:w.panSurface,"aria-hidden":`true`}),t]}),g]})}var T={background:`_background_1pu9x_2`};function FlowBackground({variant:e=`dots`,gap:t=20,size:r=1,color:i,className:a,style:o,...s}){return p(`div`,{"data-variant":e,"aria-hidden":`true`,className:h(T.background,a),style:{"--flow-bg-gap":`${t}px`,"--flow-bg-size":`${r}px`,"--flow-bg-thick":`${Math.max(1,r)}px`,...i?{"--flow-bg-color":i}:{},...o},...s})}var E={node:`_node_9zyg4_2`};function FlowNode({id:t,position:a,defaultPosition:o,onPositionChange:s,onMeasure:u,zoom:f=1,selected:m=!1,draggable:h=!0,interactive:g=!0,onSelect:_,children:v,className:y,onClick:b,onKeyDown:x,...S}){l();let C=h&&g,[w,T]=r({value:a,defaultValue:o??a??{x:0,y:0},onChange:s}),{handleRef:D,targetRef:O,offset:k,isDragging:A}=i({isDisabled:!C}),j=d(null),setRefs=e=>{j.current=e,D.current=e,O.current=e},M=d(u);M.current=u,c(()=>{let e=j.current;if(!e||typeof ResizeObserver>`u`)return;let report=()=>{let t=e.offsetWidth,r=e.offsetHeight;t>0&&r>0&&M.current?.({width:t,height:r})};report();let t=new ResizeObserver(report);return t.observe(e),()=>t.disconnect()});let N=d(f);N.current=f;let P=d(null);c(()=>{let e=A.value,t=k.value;if(!C)return;if(!e){P.current=null;return}P.current||={pos:w.peek(),off:t};let r=P.current,i=N.current||1;T({x:r.pos.x+(t.x-r.off.x)/i,y:r.pos.y+(t.y-r.off.y)/i})});let F=w.value;return p(`div`,{ref:setRefs,"data-node-id":t,"data-selected":m||void 0,"data-dragging":A.value||void 0,"data-static":!g||void 0,role:`group`,tabIndex:g?0:void 0,className:e(E.node,y),style:{"--flow-x":`${F.x}px`,"--flow-y":`${F.y}px`},onClick:e=>{g&&_?.(t),b?.(e)},onKeyDown:e=>{g&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_?.(t)),x?.(e)},...S,children:v})}var D={handle:`_handle_8a1xa_2`,dot:`_dot_8a1xa_41`};function defaultPosition(e){return e===`source`?`right`:`left`}function FlowHandle({type:e,position:t,id:r,isConnectable:i=!0,className:a,...o}){return p(`div`,{"data-handle-type":e,"data-handle-pos":t??defaultPosition(e),"data-handle-id":r,"data-connectable":i||void 0,"data-flow-handle":``,tabIndex:i?0:-1,className:h(D.handle,a),...o,children:p(`span`,{className:D.dot,"aria-hidden":`true`})})}var O={edgeSvg:`_edgeSvg_789n0_2`,edgePath:`_edgePath_789n0_11`,hit:`_hit_789n0_18`,arrow:`_arrow_789n0_26`,"cascivo-flow-dash":`_cascivo-flow-dash_789n0_1`,label:`_label_789n0_64`};function FlowEdge({id:t,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s=`right`,targetPosition:c=`left`,type:l=`bezier`,animated:d=!1,label:h,selected:g=!1,markerStart:_=!1,markerEnd:v=!0,direction:y=`forward`,active:b,className:x}){let S=u(),C=`flow-arrow-${t??S}`,w=_||v,{d:T,mid:E}=edgePath(l,{source:{x:r,y:i},target:{x:a,y:o},sourcePosition:s,targetPosition:c});return m(f,{children:[m(`svg`,{className:e(O.edgeSvg,x),"data-edge-id":t,"data-animated":d||void 0,"data-selected":g||void 0,"data-active":b||void 0,"data-direction":y,"aria-hidden":`true`,children:[w&&p(`defs`,{children:p(`marker`,{id:C,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:p(`path`,{className:O.arrow,d:`M0,0 L10,5 L0,10 z`})})}),p(`path`,{className:O.hit,d:T}),p(`path`,{className:O.edgePath,d:T,markerStart:_?`url(#${C})`:void 0,markerEnd:v?`url(#${C})`:void 0})]}),h!=null&&p(`div`,{className:O.label,style:{"--flow-label-x":`${E.x}px`,"--flow-label-y":`${E.y}px`},children:h})]})}var k={controls:`_controls_s32im_2`,button:`_button_s32im_32`},A={width:18,height:18,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":!0};function FlowControls({position:t=`bottom-left`,showZoom:r=!0,showFitView:i=!0,onZoomIn:a,onZoomOut:o,onFitView:s,labels:c,className:u,...d}){return l(),m(`div`,{"data-position":t,className:e(k.controls,u),...d,children:[r&&m(f,{children:[p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomIn??_(g.flow.zoomIn),onClick:a,children:p(`svg`,{...A,children:p(`path`,{d:`M12 5v14M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})}),p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomOut??_(g.flow.zoomOut),onClick:o,children:p(`svg`,{...A,children:p(`path`,{d:`M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})})]}),i&&p(`button`,{type:`button`,className:k.button,"aria-label":c?.fitView??_(g.flow.fitView),onClick:s,children:p(`svg`,{...A,children:p(`path`,{d:`M4 9V5a1 1 0 0 1 1-1h4M15 4h4a1 1 0 0 1 1 1v4M20 15v4a1 1 0 0 1-1 1h-4M9 20H5a1 1 0 0 1-1-1v-4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}var j={minimap:`_minimap_rdahv_2`,node:`_node_rdahv_28`,viewport:`_viewport_rdahv_32`};function FlowMiniMap({nodes:t,viewport:r,containerWidth:a,containerHeight:o,width:s=200,height:u=150,position:f=`bottom-right`,nodeColor:h,onViewportChange:v,label:y,ariaLabel:b,className:x}){l();let S=graphBounds(t)??{x:0,y:0,width:1,height:1},C=S.width||1,w=S.height||1,T=C*.1,E=w*.1,D={x:S.x-T,y:S.y-E,width:C+T*2,height:w+E*2},O=Math.min(s/D.width,u/D.height),k=-D.x*O+(s-D.width*O)/2,A=-D.y*O+(u-D.height*O)/2,toMM=e=>({x:e.x*O+k,y:e.y*O+A}),M=null;if(a&&o){let e=screenToFlow({x:0,y:0},r),t=screenToFlow({x:a,y:o},r),i=toMM(e);M={x:i.x,y:i.y,w:(t.x-e.x)*O,h:(t.y-e.y)*O}}let{handleRef:N,offset:P,isDragging:F}=i({isDisabled:!v}),I=d(null),setRectRef=e=>{I.current=e,N.current=e},L=d(v);L.current=v;let R=d(null);return c(()=>{let e=F.value,t=P.value;if(!L.current)return;if(!e){R.current=null;return}R.current||={vp:r,off:t};let i=R.current,a=i.vp.zoom;L.current({x:i.vp.x-(t.x-i.off.x)/O*a,y:i.vp.y-(t.y-i.off.y)/O*a,zoom:a})}),m(`svg`,{"data-position":f,className:e(j.minimap,x),width:s,height:u,role:`img`,"aria-label":b??y??_(g.flow.minimap),children:[t.map(e=>{let t=nodeBounds(e),r=toMM({x:t.x,y:t.y});return p(`rect`,{"data-node-id":e.id,className:j.node,x:r.x,y:r.y,width:t.width*O,height:t.height*O,fill:h},e.id)}),M&&p(`rect`,{ref:setRectRef,"data-viewport":``,className:j.viewport,x:M.x,y:M.y,width:M.w,height:M.h})]})}var M={panel:`_panel_l0cix_2`};function FlowPanel({position:e=`top-right`,children:t,className:r,...i}){return p(`div`,{"data-position":e,className:h(M.panel,r),...i,children:t})}var N={flow:`_flow_vejge_2`},P=0;function Flow({nodes:t,edges:r,onNodesChange:i,onEdgesChange:a,onConnect:o,nodeTypes:c,fitView:u=!0,background:d=!1,controls:h=!1,minimap:g=!1,layout:_,minZoom:v,maxZoom:y,interactive:b=!0,activeEdgeId:x,activeDirection:S,className:C,style:w}){l();let T=useFlow({defaultNodes:_?applyLayout(t,r,_):t,defaultEdges:r,onNodesChange:i,onEdgesChange:a}),E=useViewport(T,{minZoom:v,maxZoom:y,fitOnInit:u}),{connection:D}=useConnection({containerRef:E.containerRef,clientToFlow:(e,t)=>{let r=E.containerRef.current?.getBoundingClientRect();return screenToFlow({x:e-(r?.left??0),y:t-(r?.top??0)},T.viewport.peek())},enabled:b,onConnect:e=>{T.addEdge({id:`e-${++P}`,source:e.source,target:e.target}),o?.(e)}}),select=e=>{T.setNodes(T.nodes.value.map(t=>({...t,selected:t.id===e})))},O=s({}),measure=(e,t)=>{let r=O.peek()[e];r&&r.width===t.width&&r.height===t.height||(O.value={...O.peek(),[e]:t})},k=T.nodes.value,A=T.edges.value,j=T.viewport.value.zoom,M=O.value,F=new Map(k.map(e=>{let t=M[e.id];return[e.id,t?{...e,width:t.width,height:t.height}:e]})),I=D.value;return m(FlowCanvas,{flow:T,controller:E,minZoom:v,maxZoom:y,chrome:m(f,{children:[h&&p(FlowControls,{onZoomIn:E.zoomIn,onZoomOut:E.zoomOut,onFitView:()=>E.fitView()}),g&&p(FlowMiniMap,{nodes:k,viewport:T.viewport.value,containerWidth:E.containerRef.current?.clientWidth,containerHeight:E.containerRef.current?.clientHeight,onViewportChange:T.setViewport})]}),className:e(N.flow,C),style:w,children:[d&&p(FlowBackground,{...typeof d==`object`?d:{}}),A.map(e=>{let t=F.get(e.source),r=F.get(e.target);if(!t||!r)return null;let i=handleAnchor(t,`right`),a=handleAnchor(r,`left`),o=x===e.id,s=o?S:void 0,c=s===`reverse`?!0:s===`forward`?!1:e.markerStart??!1,l=s===`reverse`?!1:s===`forward`?!0:e.markerEnd??!0;return p(FlowEdge,{id:e.id,sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y,type:e.type??`bezier`,animated:e.animated||o,active:o,direction:s,markerStart:c,markerEnd:l,label:e.label,selected:e.selected},e.id)}),I&&p(FlowEdge,{sourceX:I.from.x,sourceY:I.from.y,targetX:I.to.x,targetY:I.to.y,markerEnd:!1}),k.map(e=>p(FlowNode,{id:e.id,position:e.position,zoom:j,interactive:b,selected:e.selected??!1,onSelect:b?select:void 0,onMeasure:t=>measure(e.id,t),onPositionChange:t=>T.updateNode(e.id,{position:t}),children:c&&e.type&&c[e.type]?c[e.type]({node:e}):m(f,{children:[p(`span`,{children:String(e.data?.label??e.id)}),b&&p(FlowHandle,{type:`target`,position:`left`}),b&&p(FlowHandle,{type:`source`,position:`right`})]})},e.id))]})}var F={story:`_story_btt88_2`,overlay:`_overlay_btt88_7`,caption:`_caption_btt88_20`,captionText:`_captionText_btt88_36`,captionDesc:`_captionDesc_btt88_48`,controls:`_controls_btt88_52`,button:`_button_btt88_64`,indicator:`_indicator_btt88_93`},I={width:18,height:18,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0};function FlowStory({nodes:t,edges:r,script:i,loop:a=!0,stepDuration:o=1500,stepGap:s=0,playing:c,currentStep:u,onStepChange:d,controls:f=!0,autoPlay:h=!0,background:v=!0,interactive:y=!1,labels:b,clock:x,className:S,style:C}){l();let w=resolveScript(i,r),T=useStory({steps:w,loop:a,stepDuration:o,stepGap:s,playing:c,defaultPlaying:h,currentStep:u,defaultCurrentStep:0,onStepChange:d,clock:x}),E=T.activeStep.value,D=T.currentStep.value,O=T.playing.value;return m(`div`,{className:e(F.story,S),style:C,children:[p(Flow,{nodes:t,edges:r,background:v,interactive:y,activeEdgeId:E?.edgeId,activeDirection:E?.direction}),m(`div`,{className:F.overlay,children:[p(`div`,{className:F.caption,"aria-live":`polite`,children:E?.label&&m(`span`,{className:F.captionText,children:[p(`strong`,{children:E.label}),E.description&&m(`span`,{className:F.captionDesc,children:[` — `,E.description]})]},D)}),f&&m(`div`,{className:F.controls,children:[p(`button`,{type:`button`,className:F.button,"aria-label":b?.previous??_(g.flow.previous),onClick:T.prev,children:p(`svg`,{...I,children:p(`path`,{d:`M15 6 9 12l6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),p(`button`,{type:`button`,className:F.button,"aria-label":O?b?.pause??_(g.flow.pause):b?.play??_(g.flow.play),"aria-pressed":O,onClick:T.toggle,children:O?p(`svg`,{...I,children:p(`path`,{d:`M7 5h3v14H7zM14 5h3v14h-3z`})}):p(`svg`,{...I,children:p(`path`,{d:`M7 5l11 7-11 7z`})})}),p(`button`,{type:`button`,className:F.button,"aria-label":b?.next??_(g.flow.next),onClick:T.next,children:p(`svg`,{...I,children:p(`path`,{d:`M9 6l6 6-6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),p(`span`,{className:F.indicator,children:_(g.flow.step,{current:D+1,total:w.length})})]})]})]})}export{v as DEFAULT_NODE_SIZE,Flow,FlowBackground,FlowCanvas,FlowControls,FlowEdge,FlowHandle,FlowMiniMap,FlowNode,FlowPanel,FlowStory,applyLayout,bezierPath,clampZoom,edgePath,fitViewport,flowToScreen,graphBounds,gridLayout,handleAnchor,layeredLayout,nodeBounds,nodeSize,resolveScript,resolveStep,screenToFlow,smoothStepPath,straightPath,useConnection,useFlow,useStory,useViewport};
|
|
3
|
+
import{cn as e,useComputed as t,useControllableSignal as r,useDraggable as i,useEffectPropSignal as a,useResizeObserver as o,useSignal as s,useSignalEffect as c,useSignals as l}from"@cascivo/core";import{useId as u,useRef as d}from"react";import{Fragment as f,jsx as p,jsxs as m}from"react/jsx-runtime";import{cn as h}from"@cascivo/core/pure";import{builtin as g,t as _}from"@cascivo/i18n";var v={width:150,height:40},y={x:0,y:0,zoom:1};function useFlow(e={}){let[t,i]=r({value:e.nodes,defaultValue:e.defaultNodes??[],onChange:e.onNodesChange}),[a,o]=r({value:e.edges,defaultValue:e.defaultEdges??[],onChange:e.onEdgesChange}),[s,c]=r({value:e.viewport,defaultValue:e.defaultViewport??y,onChange:e.onViewportChange});return{nodes:t,edges:a,viewport:s,setNodes:i,updateNode:(e,r)=>{i(t.value.map(t=>t.id===e?{...t,...r}:t))},setEdges:o,addEdge:e=>{o([...a.value,e])},setViewport:c}}function clampZoom(e,t=.2,r=2){return Math.min(r,Math.max(t,e))}function screenToFlow(e,t){return{x:(e.x-t.x)/t.zoom,y:(e.y-t.y)/t.zoom}}function flowToScreen(e,t){return{x:e.x*t.zoom+t.x,y:e.y*t.zoom+t.y}}function nodeSize(e){return{width:e.width??v.width,height:e.height??v.height}}function nodeBounds(e){let{width:t,height:r}=nodeSize(e);return{x:e.position.x,y:e.position.y,width:t,height:r}}function handleAnchor(e,t){let{x:r,y:i,width:a,height:o}=nodeBounds(e);switch(t){case`top`:return{x:r+a/2,y:i};case`right`:return{x:r+a,y:i+o/2};case`bottom`:return{x:r+a/2,y:i+o};case`left`:return{x:r,y:i+o/2}}}function graphBounds(e){if(e.length===0)return null;let t=1/0,r=1/0,i=-1/0,a=-1/0;for(let o of e){let e=nodeBounds(o);t=Math.min(t,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.width),a=Math.max(a,e.y+e.height)}return{x:t,y:r,width:i-t,height:a-r}}function fitViewport(e,t,r={}){let{padding:i=.1,minZoom:a=.2,maxZoom:o=2}=r;if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{x:t.width/2-e.x,y:t.height/2-e.y,zoom:1};let s=t.width/(e.width*(1+i*2)),c=t.height/(e.height*(1+i*2)),l=clampZoom(Math.min(s,c),a,o);return{x:t.width/2-(e.x+e.width/2)*l,y:t.height/2-(e.y+e.height/2)*l,zoom:l}}var n=e=>Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,``),midpoint=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});function normal(e){switch(e){case`top`:return{x:0,y:-1};case`bottom`:return{x:0,y:1};case`left`:return{x:-1,y:0};case`right`:return{x:1,y:0}}}function straightPath({source:e,target:t}){return{d:`M${n(e.x)},${n(e.y)} L${n(t.x)},${n(t.y)}`,mid:midpoint(e,t)}}function bezierPath(e){let{source:t,target:r,curvature:i=.25}=e,a=e.sourcePosition??`right`,o=e.targetPosition??`left`,s=Math.hypot(r.x-t.x,r.y-t.y),c=Math.max(i*s,20),l=normal(a),u=normal(o),d={x:t.x+l.x*c,y:t.y+l.y*c},f={x:r.x+u.x*c,y:r.y+u.y*c},p={x:(t.x+3*d.x+3*f.x+r.x)/8,y:(t.y+3*d.y+3*f.y+r.y)/8};return{d:`M${n(t.x)},${n(t.y)} C${n(d.x)},${n(d.y)} ${n(f.x)},${n(f.y)} ${n(r.x)},${n(r.y)}`,mid:p}}function len(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function towards(e,t,r){let i=len(e,t)||1;return{x:e.x+(t.x-e.x)/i*r,y:e.y+(t.y-e.y)/i*r}}function roundedPath(e,t){if(e.length<2)return``;let r=e[0],i=`M${n(r.x)},${n(r.y)}`;for(let r=1;r<e.length-1;r++){let a=e[r-1],o=e[r],s=e[r+1],c=Math.min(t,len(a,o)/2,len(o,s)/2),l=towards(o,a,c),u=towards(o,s,c);i+=` L${n(l.x)},${n(l.y)} Q${n(o.x)},${n(o.y)} ${n(u.x)},${n(u.y)}`}let a=e[e.length-1];return i+=` L${n(a.x)},${n(a.y)}`,i}function smoothStepPath(e){let{source:t,target:r,borderRadius:i=8}=e,a=e.sourcePosition??`right`,o=a===`left`||a===`right`,s=[t];if(o){let e=(t.x+r.x)/2;s.push({x:e,y:t.y},{x:e,y:r.y})}else{let e=(t.y+r.y)/2;s.push({x:t.x,y:e},{x:r.x,y:e})}return s.push(r),{d:roundedPath(s,i),mid:midpoint(t,r)}}function edgePath(e,t){switch(e){case`straight`:return straightPath(t);case`smoothstep`:return smoothStepPath(t);case`bezier`:return bezierPath(t)}}function gridLayout(e,t={}){let r=t.gap??40,i=t.nodeWidth??v.width,a=t.nodeHeight??v.height,o=t.columns??Math.max(1,Math.ceil(Math.sqrt(e.length)));return e.map((e,t)=>{let s=t%o,c=Math.floor(t/o);return{...e,position:{x:s*(i+r),y:c*(a+r)}}})}function layeredLayout(e,t,r={}){let i=r.direction??`LR`,a=r.gap??60,o=r.nodeWidth??v.width,s=r.nodeHeight??v.height,c=new Set(e.map(e=>e.id)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;for(let t of e)u.set(t.id,0);for(let e of t)c.has(e.source)&&c.has(e.target)&&(l.set(e.source,[...l.get(e.source)??[],e.target]),u.set(e.target,(u.get(e.target)??0)+1));let d=/* @__PURE__ */ new Map,f=e.filter(e=>(u.get(e.id)??0)===0).map(e=>e.id);for(let e of f)d.set(e,0);let p=new Map(u);for(;f.length>0;){let e=[];for(let t of f){let r=d.get(t)??0;for(let i of l.get(t)??[])d.set(i,Math.max(d.get(i)??0,r+1)),p.set(i,(p.get(i)??0)-1),(p.get(i)??0)===0&&e.push(i)}f=e}for(let t of e)d.has(t.id)||d.set(t.id,0);let m=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new Map;for(let t of e){let e=d.get(t.id)??0,r=h.get(e)??0;m.set(t.id,r),h.set(e,r+1)}return e.map(e=>{let t=d.get(e.id)??0,r=m.get(e.id)??0,c=i===`LR`?{x:t*(o+a),y:r*(s+a)}:{x:r*(o+a),y:t*(s+a)};return{...e,position:c}})}function applyLayout(e,t,r){return r===`grid`?gridLayout(e):r===`layered`?layeredLayout(e,t):r(e,t)}function isEdgeStep(e){return`edge`in e}function resolveStep(e,t){let r={label:e.label,description:e.description,duration:e.duration};if(isEdgeStep(e)){let i=t.find(t=>t.id===e.edge);if(!i)throw Error(`FlowStory: step references unknown edge "${e.edge}"`);return{edgeId:i.id,direction:e.reverse?`reverse`:`forward`,...r}}let i=t.find(t=>t.source===e.from&&t.target===e.to);if(i)return{edgeId:i.id,direction:`forward`,...r};let a=t.find(t=>t.source===e.to&&t.target===e.from);if(a)return{edgeId:a.id,direction:`reverse`,...r};throw Error(`FlowStory: no edge connects "${e.from}" and "${e.to}"`)}function resolveScript(e,t){return e.map(e=>resolveStep(e,t))}var b=1.2;function useViewport(e,t={}){let{minZoom:r=.2,maxZoom:a=2,panOnDrag:s=!0,zoomOnScroll:l=!0,fitPadding:u=.1,fitOnInit:f=!1}=t,{viewport:p,setViewport:m}=e,{ref:h,size:g}=o(),{handleRef:_,offset:v,isDragging:y}=i({isDisabled:!s}),pan=(e,t)=>{let r=p.peek();m({x:r.x+e,y:r.y+t,zoom:r.zoom})},zoomTo=(e,t)=>{let i=p.peek(),o=clampZoom(e,r,a);if(!t){m({x:i.x,y:i.y,zoom:o});return}let s=screenToFlow(t,i);m({x:t.x-s.x*o,y:t.y-s.y*o,zoom:o})},containerCenter=()=>{let e=h.current;if(e)return{x:e.clientWidth/2,y:e.clientHeight/2}},zoomIn=()=>zoomTo(p.peek().zoom*b,containerCenter()),zoomOut=()=>zoomTo(p.peek().zoom/b,containerCenter()),measuredSize=()=>{let e=g.peek();if(e&&e.width>0&&e.height>0)return e;let t=h.current;return t&&t.clientWidth>0?{width:t.clientWidth,height:t.clientHeight}:null},fitView=t=>{let i=graphBounds(e.nodes.peek());if(!i)return;let o=t??measuredSize();o&&m(fitViewport(i,o,{padding:u,minZoom:r,maxZoom:a}))},x=d(null);c(()=>{let e=y.value,t=v.value;if(!s)return;if(!e){x.current=null;return}x.current||={vp:p.peek(),off:t};let r=x.current;m({x:r.vp.x+(t.x-r.off.x),y:r.vp.y+(t.y-r.off.y),zoom:r.vp.zoom})}),c(()=>{if(!l||typeof window>`u`)return;let e=h.current;if(!e)return;let onWheel=t=>{t.preventDefault();let r=e.getBoundingClientRect(),i={x:t.clientX-r.left,y:t.clientY-r.top},a=t.deltaY<0?b:1/b;zoomTo(p.peek().zoom*a,i)};return e.addEventListener(`wheel`,onWheel,{passive:!1}),()=>e.removeEventListener(`wheel`,onWheel)});let S=d(!1);return c(()=>{if(!f||S.current)return;let e=g.value;e&&e.width!==0&&(S.current=!0,fitView(e))}),{containerRef:h,panHandleRef:_,viewport:p,pan,zoomTo,zoomIn,zoomOut,fitView}}var x=`[data-flow-handle][data-handle-type="source"]`,S=`[data-flow-handle][data-handle-type="target"]`;function useConnection(e){let{containerRef:t}=e,r=s(null),i=d(e.onConnect);i.current=e.onConnect;let o=d(e.isValid);o.current=e.isValid;let l=d(e.clientToFlow);l.current=e.clientToFlow;let u=a(e.enabled??!0);return c(()=>{if(!u.value||typeof window>`u`)return;let e=t.current;if(!e)return;let onMove=e=>{let t=r.peek();t&&(r.value={...t,to:l.current(e.clientX,e.clientY)})},onUp=e=>{let t=r.peek();if(window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp),r.value=null,!t)return;let a=e.target,s=a instanceof Element?a.closest(S):null,c=s?.closest(`[data-node-id]`);if(!c)return;let l={source:t.source,target:c.getAttribute(`data-node-id`)??``,sourceHandle:t.sourceHandle,targetHandle:s?.getAttribute(`data-handle-id`)??void 0};l.target&&l.source!==l.target&&(!o.current||o.current(l))&&i.current?.(l)},onDown=e=>{let t=e.target;if(!(t instanceof Element))return;let i=t.closest(x);if(!i)return;let a=i.closest(`[data-node-id]`);if(!a)return;e.stopPropagation();let o=i.getBoundingClientRect();r.value={source:a.getAttribute(`data-node-id`)??``,sourceHandle:i.getAttribute(`data-handle-id`)??void 0,from:l.current(o.left+o.width/2,o.top+o.height/2),to:l.current(e.clientX,e.clientY)},window.addEventListener(`pointermove`,onMove),window.addEventListener(`pointerup`,onUp)};return e.addEventListener(`pointerdown`,onDown),()=>{e.removeEventListener(`pointerdown`,onDown),window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp)}}),{connection:r}}var C=1500;function useStory(e){let{steps:i,loop:a=!0,stepDuration:o=C,stepGap:s=0}=e,[l,u]=r({value:e.currentStep,defaultValue:e.defaultCurrentStep??0,onChange:e.onStepChange}),[f,p]=r({value:e.playing,defaultValue:e.defaultPlaying??!0,onChange:e.onPlayingChange}),m=t(()=>i[l.value]??null),h=d(e.clock);h.current=e.clock;let g=d(i);g.current=i;let clock=()=>h.current??{setTimeout:(e,t)=>window.setTimeout(e,t),clearTimeout:e=>window.clearTimeout(e)},advance=e=>{let t=g.current.length;if(t===0)return;let r=l.peek()+e,i=a?(r%t+t)%t:Math.max(0,Math.min(t-1,r));u(i)};return c(()=>{if(!f.value)return;let e=l.value,t=i.length;if(t===0||typeof window>`u`&&!h.current)return;let r=(i[e]?.duration??o)+s,c=clock(),d=c.setTimeout(()=>{let r=e+1;r>=t?a?u(0):p(!1):u(r)},r);return()=>c.clearTimeout(d)}),{currentStep:l,playing:f,activeStep:m,play:()=>p(!0),pause:()=>p(!1),toggle:()=>p(!f.peek()),next:()=>advance(1),prev:()=>advance(-1),restart:()=>{u(0),p(!0)}}}var w={canvas:`_canvas_6fiig_2`,pane:`_pane_6fiig_13`,panSurface:`_panSurface_6fiig_24`};function FlowCanvas({children:t,flow:r,viewport:i,defaultViewport:a,onViewportChange:o,minZoom:s,maxZoom:c,panOnDrag:u=!0,zoomOnScroll:d=!0,fitView:f=!1,controller:h,chrome:g,className:_,role:v=`application`,...y}){l();let b=useFlow({viewport:i,defaultViewport:a,onViewportChange:o}),x=r??b,S=useViewport(x,{minZoom:s,maxZoom:c,panOnDrag:u,zoomOnScroll:d,fitOnInit:f}),C=h??S,T=x.viewport.value;return/* @__PURE__ */ m(`div`,{ref:C.containerRef,className:e(w.canvas,_),role:v,...y,children:[/* @__PURE__ */ m(`div`,{className:w.pane,style:{"--flow-tx":`${T.x}px`,"--flow-ty":`${T.y}px`,"--flow-scale":String(T.zoom)},children:[/* @__PURE__ */ p(`div`,{ref:C.panHandleRef,className:w.panSurface,"aria-hidden":`true`}),t]}),g]})}var T={background:`_background_1pu9x_2`};function FlowBackground({variant:e=`dots`,gap:t=20,size:r=1,color:i,className:a,style:o,...s}){return/* @__PURE__ */ p(`div`,{"data-variant":e,"aria-hidden":`true`,className:h(T.background,a),style:{"--flow-bg-gap":`${t}px`,"--flow-bg-size":`${r}px`,"--flow-bg-thick":`${Math.max(1,r)}px`,...i?{"--flow-bg-color":i}:{},...o},...s})}var E={node:`_node_9zyg4_2`};function FlowNode({id:t,position:a,defaultPosition:o,onPositionChange:s,onMeasure:u,zoom:f=1,selected:m=!1,draggable:h=!0,interactive:g=!0,onSelect:_,children:v,className:y,onClick:b,onKeyDown:x,...S}){l();let C=h&&g,[w,T]=r({value:a,defaultValue:o??a??{x:0,y:0},onChange:s}),{handleRef:D,targetRef:O,offset:k,isDragging:A}=i({isDisabled:!C}),j=d(null),setRefs=e=>{j.current=e,D.current=e,O.current=e},M=d(u);M.current=u,c(()=>{let e=j.current;if(!e||typeof ResizeObserver>`u`)return;let report=()=>{let t=e.offsetWidth,r=e.offsetHeight;t>0&&r>0&&M.current?.({width:t,height:r})};report();let t=new ResizeObserver(report);return t.observe(e),()=>t.disconnect()});let N=d(f);N.current=f;let P=d(null);c(()=>{let e=A.value,t=k.value;if(!C)return;if(!e){P.current=null;return}P.current||={pos:w.peek(),off:t};let r=P.current,i=N.current||1;T({x:r.pos.x+(t.x-r.off.x)/i,y:r.pos.y+(t.y-r.off.y)/i})});let F=w.value;return/* @__PURE__ */ p(`div`,{ref:setRefs,"data-node-id":t,"data-selected":m||void 0,"data-dragging":A.value||void 0,"data-static":!g||void 0,role:`group`,tabIndex:g?0:void 0,className:e(E.node,y),style:{"--flow-x":`${F.x}px`,"--flow-y":`${F.y}px`},onClick:e=>{g&&_?.(t),b?.(e)},onKeyDown:e=>{g&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_?.(t)),x?.(e)},...S,children:v})}var D={handle:`_handle_8a1xa_2`,dot:`_dot_8a1xa_41`};function defaultPosition(e){return e===`source`?`right`:`left`}function FlowHandle({type:e,position:t,id:r,isConnectable:i=!0,className:a,...o}){let s=t??defaultPosition(e);return/* @__PURE__ */ p(`div`,{"data-handle-type":e,"data-handle-pos":s,"data-handle-id":r,"data-connectable":i||void 0,"data-flow-handle":``,tabIndex:i?0:-1,className:h(D.handle,a),...o,children:/* @__PURE__ */ p(`span`,{className:D.dot,"aria-hidden":`true`})})}var O={edgeSvg:`_edgeSvg_789n0_2`,edgePath:`_edgePath_789n0_11`,hit:`_hit_789n0_18`,arrow:`_arrow_789n0_26`,"cascivo-flow-dash":`_cascivo-flow-dash_789n0_1`,label:`_label_789n0_64`};function FlowEdge({id:t,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s=`right`,targetPosition:c=`left`,type:l=`bezier`,animated:d=!1,label:h,selected:g=!1,markerStart:_=!1,markerEnd:v=!0,direction:y=`forward`,active:b,className:x}){let S=u(),C=`flow-arrow-${t??S}`,w=_||v,{d:T,mid:E}=edgePath(l,{source:{x:r,y:i},target:{x:a,y:o},sourcePosition:s,targetPosition:c});return/* @__PURE__ */ m(f,{children:[/* @__PURE__ */ m(`svg`,{className:e(O.edgeSvg,x),"data-edge-id":t,"data-animated":d||void 0,"data-selected":g||void 0,"data-active":b||void 0,"data-direction":y,"aria-hidden":`true`,children:[w&&/* @__PURE__ */ p(`defs`,{children:/* @__PURE__ */ p(`marker`,{id:C,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:/* @__PURE__ */ p(`path`,{className:O.arrow,d:`M0,0 L10,5 L0,10 z`})})}),/* @__PURE__ */ p(`path`,{className:O.hit,d:T}),/* @__PURE__ */ p(`path`,{className:O.edgePath,d:T,markerStart:_?`url(#${C})`:void 0,markerEnd:v?`url(#${C})`:void 0})]}),h!=null&&/* @__PURE__ */ p(`div`,{className:O.label,style:{"--flow-label-x":`${E.x}px`,"--flow-label-y":`${E.y}px`},children:h})]})}var k={controls:`_controls_s32im_2`,button:`_button_s32im_32`},A={width:18,height:18,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":!0};function FlowControls({position:t=`bottom-left`,showZoom:r=!0,showFitView:i=!0,onZoomIn:a,onZoomOut:o,onFitView:s,labels:c,className:u,...d}){return l(),/* @__PURE__ */ m(`div`,{"data-position":t,className:e(k.controls,u),...d,children:[r&&/* @__PURE__ */ m(f,{children:[/* @__PURE__ */ p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomIn??_(g.flow.zoomIn),onClick:a,children:/* @__PURE__ */ p(`svg`,{...A,children:/* @__PURE__ */ p(`path`,{d:`M12 5v14M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})}),/* @__PURE__ */ p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomOut??_(g.flow.zoomOut),onClick:o,children:/* @__PURE__ */ p(`svg`,{...A,children:/* @__PURE__ */ p(`path`,{d:`M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})})]}),i&&/* @__PURE__ */ p(`button`,{type:`button`,className:k.button,"aria-label":c?.fitView??_(g.flow.fitView),onClick:s,children:/* @__PURE__ */ p(`svg`,{...A,children:/* @__PURE__ */ p(`path`,{d:`M4 9V5a1 1 0 0 1 1-1h4M15 4h4a1 1 0 0 1 1 1v4M20 15v4a1 1 0 0 1-1 1h-4M9 20H5a1 1 0 0 1-1-1v-4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}var j={minimap:`_minimap_rdahv_2`,node:`_node_rdahv_28`,viewport:`_viewport_rdahv_32`};function FlowMiniMap({nodes:t,viewport:r,containerWidth:a,containerHeight:o,width:s=200,height:u=150,position:f=`bottom-right`,nodeColor:h,onViewportChange:v,label:y,ariaLabel:b,className:x}){l();let S=graphBounds(t)??{x:0,y:0,width:1,height:1},C=S.width||1,w=S.height||1,T=C*.1,E=w*.1,D={x:S.x-T,y:S.y-E,width:C+T*2,height:w+E*2},O=Math.min(s/D.width,u/D.height),k=-D.x*O+(s-D.width*O)/2,A=-D.y*O+(u-D.height*O)/2,toMM=e=>({x:e.x*O+k,y:e.y*O+A}),M=null;if(a&&o){let e=screenToFlow({x:0,y:0},r),t=screenToFlow({x:a,y:o},r),i=toMM(e);M={x:i.x,y:i.y,w:(t.x-e.x)*O,h:(t.y-e.y)*O}}let{handleRef:N,offset:P,isDragging:F}=i({isDisabled:!v}),I=d(null),setRectRef=e=>{I.current=e,N.current=e},L=d(v);L.current=v;let R=d(null);return c(()=>{let e=F.value,t=P.value;if(!L.current)return;if(!e){R.current=null;return}R.current||={vp:r,off:t};let i=R.current,a=i.vp.zoom;L.current({x:i.vp.x-(t.x-i.off.x)/O*a,y:i.vp.y-(t.y-i.off.y)/O*a,zoom:a})}),/* @__PURE__ */ m(`svg`,{"data-position":f,className:e(j.minimap,x),width:s,height:u,role:`img`,"aria-label":b??y??_(g.flow.minimap),children:[t.map(e=>{let t=nodeBounds(e),r=toMM({x:t.x,y:t.y});return/* @__PURE__ */ p(`rect`,{"data-node-id":e.id,className:j.node,x:r.x,y:r.y,width:t.width*O,height:t.height*O,fill:h},e.id)}),M&&/* @__PURE__ */ p(`rect`,{ref:setRectRef,"data-viewport":``,className:j.viewport,x:M.x,y:M.y,width:M.w,height:M.h})]})}var M={panel:`_panel_l0cix_2`};function FlowPanel({position:e=`top-right`,children:t,className:r,...i}){return/* @__PURE__ */ p(`div`,{"data-position":e,className:h(M.panel,r),...i,children:t})}var N={flow:`_flow_vejge_2`},P=0;function Flow({nodes:t,edges:r,onNodesChange:i,onEdgesChange:a,onConnect:o,nodeTypes:c,fitView:u=!0,background:d=!1,controls:h=!1,minimap:g=!1,layout:_,minZoom:v,maxZoom:y,interactive:b=!0,activeEdgeId:x,activeDirection:S,className:C,style:w}){l();let T=useFlow({defaultNodes:_?applyLayout(t,r,_):t,defaultEdges:r,onNodesChange:i,onEdgesChange:a}),E=useViewport(T,{minZoom:v,maxZoom:y,fitOnInit:u}),{connection:D}=useConnection({containerRef:E.containerRef,clientToFlow:(e,t)=>{let r=E.containerRef.current?.getBoundingClientRect();return screenToFlow({x:e-(r?.left??0),y:t-(r?.top??0)},T.viewport.peek())},enabled:b,onConnect:e=>{T.addEdge({id:`e-${++P}`,source:e.source,target:e.target}),o?.(e)}}),select=e=>{T.setNodes(T.nodes.value.map(t=>({...t,selected:t.id===e})))},O=s({}),measure=(e,t)=>{let r=O.peek()[e];r&&r.width===t.width&&r.height===t.height||(O.value={...O.peek(),[e]:t})},k=T.nodes.value,A=T.edges.value,j=T.viewport.value.zoom,M=O.value,F=new Map(k.map(e=>{let t=M[e.id];return[e.id,t?{...e,width:t.width,height:t.height}:e]})),I=D.value,L=/* @__PURE__ */ m(f,{children:[h&&/* @__PURE__ */ p(FlowControls,{onZoomIn:E.zoomIn,onZoomOut:E.zoomOut,onFitView:()=>E.fitView()}),g&&/* @__PURE__ */ p(FlowMiniMap,{nodes:k,viewport:T.viewport.value,containerWidth:E.containerRef.current?.clientWidth,containerHeight:E.containerRef.current?.clientHeight,onViewportChange:T.setViewport})]});return/* @__PURE__ */ m(FlowCanvas,{flow:T,controller:E,minZoom:v,maxZoom:y,chrome:L,className:e(N.flow,C),style:w,children:[d&&/* @__PURE__ */ p(FlowBackground,{...typeof d==`object`?d:{}}),A.map(e=>{let t=F.get(e.source),r=F.get(e.target);if(!t||!r)return null;let i=handleAnchor(t,`right`),a=handleAnchor(r,`left`),o=x===e.id,s=o?S:void 0,c=s===`reverse`?!0:s===`forward`?!1:e.markerStart??!1,l=s===`reverse`?!1:s===`forward`?!0:e.markerEnd??!0;return/* @__PURE__ */ p(FlowEdge,{id:e.id,sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y,type:e.type??`bezier`,animated:e.animated||o,active:o,direction:s,markerStart:c,markerEnd:l,label:e.label,selected:e.selected},e.id)}),I&&/* @__PURE__ */ p(FlowEdge,{sourceX:I.from.x,sourceY:I.from.y,targetX:I.to.x,targetY:I.to.y,markerEnd:!1}),k.map(e=>/* @__PURE__ */ p(FlowNode,{id:e.id,position:e.position,zoom:j,interactive:b,selected:e.selected??!1,onSelect:b?select:void 0,onMeasure:t=>measure(e.id,t),onPositionChange:t=>T.updateNode(e.id,{position:t}),children:c&&e.type&&c[e.type]?c[e.type]({node:e}):/* @__PURE__ */ m(f,{children:[/* @__PURE__ */ p(`span`,{children:String(e.data?.label??e.id)}),b&&/* @__PURE__ */ p(FlowHandle,{type:`target`,position:`left`}),b&&/* @__PURE__ */ p(FlowHandle,{type:`source`,position:`right`})]})},e.id))]})}var F={story:`_story_btt88_2`,overlay:`_overlay_btt88_7`,caption:`_caption_btt88_20`,captionText:`_captionText_btt88_36`,captionDesc:`_captionDesc_btt88_48`,controls:`_controls_btt88_52`,button:`_button_btt88_64`,indicator:`_indicator_btt88_93`},I={width:18,height:18,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0};function FlowStory({nodes:t,edges:r,script:i,loop:a=!0,stepDuration:o=1500,stepGap:s=0,playing:c,currentStep:u,onStepChange:d,controls:f=!0,autoPlay:h=!0,background:v=!0,interactive:y=!1,labels:b,clock:x,className:S,style:C}){l();let w=resolveScript(i,r),T=useStory({steps:w,loop:a,stepDuration:o,stepGap:s,playing:c,defaultPlaying:h,currentStep:u,defaultCurrentStep:0,onStepChange:d,clock:x}),E=T.activeStep.value,D=T.currentStep.value,O=T.playing.value;return/* @__PURE__ */ m(`div`,{className:e(F.story,S),style:C,children:[/* @__PURE__ */ p(Flow,{nodes:t,edges:r,background:v,interactive:y,activeEdgeId:E?.edgeId,activeDirection:E?.direction}),/* @__PURE__ */ m(`div`,{className:F.overlay,children:[/* @__PURE__ */ p(`div`,{className:F.caption,"aria-live":`polite`,children:E?.label&&/* @__PURE__ */ m(`span`,{className:F.captionText,children:[/* @__PURE__ */ p(`strong`,{children:E.label}),E.description&&/* @__PURE__ */ m(`span`,{className:F.captionDesc,children:[` — `,E.description]})]},D)}),f&&/* @__PURE__ */ m(`div`,{className:F.controls,children:[/* @__PURE__ */ p(`button`,{type:`button`,className:F.button,"aria-label":b?.previous??_(g.flow.previous),onClick:T.prev,children:/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M15 6 9 12l6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),/* @__PURE__ */ p(`button`,{type:`button`,className:F.button,"aria-label":O?b?.pause??_(g.flow.pause):b?.play??_(g.flow.play),"aria-pressed":O,onClick:T.toggle,children:O?/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M7 5h3v14H7zM14 5h3v14h-3z`})}):/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M7 5l11 7-11 7z`})})}),/* @__PURE__ */ p(`button`,{type:`button`,className:F.button,"aria-label":b?.next??_(g.flow.next),onClick:T.next,children:/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M9 6l6 6-6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),/* @__PURE__ */ p(`span`,{className:F.indicator,children:_(g.flow.step,{current:D+1,total:w.length})})]})]})]})}export{v as DEFAULT_NODE_SIZE,Flow,FlowBackground,FlowCanvas,FlowControls,FlowEdge,FlowHandle,FlowMiniMap,FlowNode,FlowPanel,FlowStory,applyLayout,bezierPath,clampZoom,edgePath,fitViewport,flowToScreen,graphBounds,gridLayout,handleAnchor,layeredLayout,nodeBounds,nodeSize,resolveScript,resolveStep,screenToFlow,smoothStepPath,straightPath,useConnection,useFlow,useStory,useViewport};
|
package/dist/node/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{cn as e,useComputed as t,useControllableSignal as r,useDraggable as i,useEffectPropSignal as a,useResizeObserver as o,useSignal as s,useSignalEffect as c,useSignals as l}from"@cascivo/core";import{useId as u,useRef as d}from"react";import{Fragment as f,jsx as p,jsxs as m}from"react/jsx-runtime";import{cn as h}from"@cascivo/core/pure";import{builtin as g,t as _}from"@cascivo/i18n";var v={width:150,height:40},y={x:0,y:0,zoom:1};function useFlow(e={}){let[t,i]=r({value:e.nodes,defaultValue:e.defaultNodes??[],onChange:e.onNodesChange}),[a,o]=r({value:e.edges,defaultValue:e.defaultEdges??[],onChange:e.onEdgesChange}),[s,c]=r({value:e.viewport,defaultValue:e.defaultViewport??y,onChange:e.onViewportChange});return{nodes:t,edges:a,viewport:s,setNodes:i,updateNode:(e,r)=>{i(t.value.map(t=>t.id===e?{...t,...r}:t))},setEdges:o,addEdge:e=>{o([...a.value,e])},setViewport:c}}function clampZoom(e,t=.2,r=2){return Math.min(r,Math.max(t,e))}function screenToFlow(e,t){return{x:(e.x-t.x)/t.zoom,y:(e.y-t.y)/t.zoom}}function flowToScreen(e,t){return{x:e.x*t.zoom+t.x,y:e.y*t.zoom+t.y}}function nodeSize(e){return{width:e.width??v.width,height:e.height??v.height}}function nodeBounds(e){let{width:t,height:r}=nodeSize(e);return{x:e.position.x,y:e.position.y,width:t,height:r}}function handleAnchor(e,t){let{x:r,y:i,width:a,height:o}=nodeBounds(e);switch(t){case`top`:return{x:r+a/2,y:i};case`right`:return{x:r+a,y:i+o/2};case`bottom`:return{x:r+a/2,y:i+o};case`left`:return{x:r,y:i+o/2}}}function graphBounds(e){if(e.length===0)return null;let t=1/0,r=1/0,i=-1/0,a=-1/0;for(let o of e){let e=nodeBounds(o);t=Math.min(t,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.width),a=Math.max(a,e.y+e.height)}return{x:t,y:r,width:i-t,height:a-r}}function fitViewport(e,t,r={}){let{padding:i=.1,minZoom:a=.2,maxZoom:o=2}=r;if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{x:t.width/2-e.x,y:t.height/2-e.y,zoom:1};let s=t.width/(e.width*(1+i*2)),c=t.height/(e.height*(1+i*2)),l=clampZoom(Math.min(s,c),a,o);return{x:t.width/2-(e.x+e.width/2)*l,y:t.height/2-(e.y+e.height/2)*l,zoom:l}}var n=e=>Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,``),midpoint=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});function normal(e){switch(e){case`top`:return{x:0,y:-1};case`bottom`:return{x:0,y:1};case`left`:return{x:-1,y:0};case`right`:return{x:1,y:0}}}function straightPath({source:e,target:t}){return{d:`M${n(e.x)},${n(e.y)} L${n(t.x)},${n(t.y)}`,mid:midpoint(e,t)}}function bezierPath(e){let{source:t,target:r,curvature:i=.25}=e,a=e.sourcePosition??`right`,o=e.targetPosition??`left`,s=Math.hypot(r.x-t.x,r.y-t.y),c=Math.max(i*s,20),l=normal(a),u=normal(o),d={x:t.x+l.x*c,y:t.y+l.y*c},f={x:r.x+u.x*c,y:r.y+u.y*c},p={x:(t.x+3*d.x+3*f.x+r.x)/8,y:(t.y+3*d.y+3*f.y+r.y)/8};return{d:`M${n(t.x)},${n(t.y)} C${n(d.x)},${n(d.y)} ${n(f.x)},${n(f.y)} ${n(r.x)},${n(r.y)}`,mid:p}}function len(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function towards(e,t,r){let i=len(e,t)||1;return{x:e.x+(t.x-e.x)/i*r,y:e.y+(t.y-e.y)/i*r}}function roundedPath(e,t){if(e.length<2)return``;let r=e[0],i=`M${n(r.x)},${n(r.y)}`;for(let r=1;r<e.length-1;r++){let a=e[r-1],o=e[r],s=e[r+1],c=Math.min(t,len(a,o)/2,len(o,s)/2),l=towards(o,a,c),u=towards(o,s,c);i+=` L${n(l.x)},${n(l.y)} Q${n(o.x)},${n(o.y)} ${n(u.x)},${n(u.y)}`}let a=e[e.length-1];return i+=` L${n(a.x)},${n(a.y)}`,i}function smoothStepPath(e){let{source:t,target:r,borderRadius:i=8}=e,a=e.sourcePosition??`right`,o=a===`left`||a===`right`,s=[t];if(o){let e=(t.x+r.x)/2;s.push({x:e,y:t.y},{x:e,y:r.y})}else{let e=(t.y+r.y)/2;s.push({x:t.x,y:e},{x:r.x,y:e})}return s.push(r),{d:roundedPath(s,i),mid:midpoint(t,r)}}function edgePath(e,t){switch(e){case`straight`:return straightPath(t);case`smoothstep`:return smoothStepPath(t);case`bezier`:return bezierPath(t)}}function gridLayout(e,t={}){let r=t.gap??40,i=t.nodeWidth??v.width,a=t.nodeHeight??v.height,o=t.columns??Math.max(1,Math.ceil(Math.sqrt(e.length)));return e.map((e,t)=>{let s=t%o,c=Math.floor(t/o);return{...e,position:{x:s*(i+r),y:c*(a+r)}}})}function layeredLayout(e,t,r={}){let i=r.direction??`LR`,a=r.gap??60,o=r.nodeWidth??v.width,s=r.nodeHeight??v.height,c=new Set(e.map(e=>e.id)),l=new Map,u=new Map;for(let t of e)u.set(t.id,0);for(let e of t)!c.has(e.source)||!c.has(e.target)||(l.set(e.source,[...l.get(e.source)??[],e.target]),u.set(e.target,(u.get(e.target)??0)+1));let d=new Map,f=e.filter(e=>(u.get(e.id)??0)===0).map(e=>e.id);for(let e of f)d.set(e,0);let p=new Map(u);for(;f.length>0;){let e=[];for(let t of f){let r=d.get(t)??0;for(let i of l.get(t)??[])d.set(i,Math.max(d.get(i)??0,r+1)),p.set(i,(p.get(i)??0)-1),(p.get(i)??0)===0&&e.push(i)}f=e}for(let t of e)d.has(t.id)||d.set(t.id,0);let m=new Map,h=new Map;for(let t of e){let e=d.get(t.id)??0,r=h.get(e)??0;m.set(t.id,r),h.set(e,r+1)}return e.map(e=>{let t=d.get(e.id)??0,r=m.get(e.id)??0,c=i===`LR`?{x:t*(o+a),y:r*(s+a)}:{x:r*(o+a),y:t*(s+a)};return{...e,position:c}})}function applyLayout(e,t,r){return r===`grid`?gridLayout(e):r===`layered`?layeredLayout(e,t):r(e,t)}function isEdgeStep(e){return`edge`in e}function resolveStep(e,t){let r={label:e.label,description:e.description,duration:e.duration};if(isEdgeStep(e)){let i=t.find(t=>t.id===e.edge);if(!i)throw Error(`FlowStory: step references unknown edge "${e.edge}"`);return{edgeId:i.id,direction:e.reverse?`reverse`:`forward`,...r}}let i=t.find(t=>t.source===e.from&&t.target===e.to);if(i)return{edgeId:i.id,direction:`forward`,...r};let a=t.find(t=>t.source===e.to&&t.target===e.from);if(a)return{edgeId:a.id,direction:`reverse`,...r};throw Error(`FlowStory: no edge connects "${e.from}" and "${e.to}"`)}function resolveScript(e,t){return e.map(e=>resolveStep(e,t))}var b=1.2;function useViewport(e,t={}){let{minZoom:r=.2,maxZoom:a=2,panOnDrag:s=!0,zoomOnScroll:l=!0,fitPadding:u=.1,fitOnInit:f=!1}=t,{viewport:p,setViewport:m}=e,{ref:h,size:g}=o(),{handleRef:_,offset:v,isDragging:y}=i({isDisabled:!s}),pan=(e,t)=>{let r=p.peek();m({x:r.x+e,y:r.y+t,zoom:r.zoom})},zoomTo=(e,t)=>{let i=p.peek(),o=clampZoom(e,r,a);if(!t){m({x:i.x,y:i.y,zoom:o});return}let s=screenToFlow(t,i);m({x:t.x-s.x*o,y:t.y-s.y*o,zoom:o})},containerCenter=()=>{let e=h.current;if(e)return{x:e.clientWidth/2,y:e.clientHeight/2}},zoomIn=()=>zoomTo(p.peek().zoom*b,containerCenter()),zoomOut=()=>zoomTo(p.peek().zoom/b,containerCenter()),measuredSize=()=>{let e=g.peek();if(e&&e.width>0&&e.height>0)return e;let t=h.current;return t&&t.clientWidth>0?{width:t.clientWidth,height:t.clientHeight}:null},fitView=t=>{let i=graphBounds(e.nodes.peek());if(!i)return;let o=t??measuredSize();o&&m(fitViewport(i,o,{padding:u,minZoom:r,maxZoom:a}))},x=d(null);c(()=>{let e=y.value,t=v.value;if(!s)return;if(!e){x.current=null;return}x.current||={vp:p.peek(),off:t};let r=x.current;m({x:r.vp.x+(t.x-r.off.x),y:r.vp.y+(t.y-r.off.y),zoom:r.vp.zoom})}),c(()=>{if(!l||typeof window>`u`)return;let e=h.current;if(!e)return;let onWheel=t=>{t.preventDefault();let r=e.getBoundingClientRect(),i={x:t.clientX-r.left,y:t.clientY-r.top},a=t.deltaY<0?b:1/b;zoomTo(p.peek().zoom*a,i)};return e.addEventListener(`wheel`,onWheel,{passive:!1}),()=>e.removeEventListener(`wheel`,onWheel)});let S=d(!1);return c(()=>{if(!f||S.current)return;let e=g.value;!e||e.width===0||(S.current=!0,fitView(e))}),{containerRef:h,panHandleRef:_,viewport:p,pan,zoomTo,zoomIn,zoomOut,fitView}}var x=`[data-flow-handle][data-handle-type="source"]`,S=`[data-flow-handle][data-handle-type="target"]`;function useConnection(e){let{containerRef:t}=e,r=s(null),i=d(e.onConnect);i.current=e.onConnect;let o=d(e.isValid);o.current=e.isValid;let l=d(e.clientToFlow);l.current=e.clientToFlow;let u=a(e.enabled??!0);return c(()=>{if(!u.value||typeof window>`u`)return;let e=t.current;if(!e)return;let onMove=e=>{let t=r.peek();t&&(r.value={...t,to:l.current(e.clientX,e.clientY)})},onUp=e=>{let t=r.peek();if(window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp),r.value=null,!t)return;let a=e.target,s=a instanceof Element?a.closest(S):null,c=s?.closest(`[data-node-id]`);if(!c)return;let l={source:t.source,target:c.getAttribute(`data-node-id`)??``,sourceHandle:t.sourceHandle,targetHandle:s?.getAttribute(`data-handle-id`)??void 0};!l.target||l.source===l.target||o.current&&!o.current(l)||i.current?.(l)},onDown=e=>{let t=e.target;if(!(t instanceof Element))return;let i=t.closest(x);if(!i)return;let a=i.closest(`[data-node-id]`);if(!a)return;e.stopPropagation();let o=i.getBoundingClientRect();r.value={source:a.getAttribute(`data-node-id`)??``,sourceHandle:i.getAttribute(`data-handle-id`)??void 0,from:l.current(o.left+o.width/2,o.top+o.height/2),to:l.current(e.clientX,e.clientY)},window.addEventListener(`pointermove`,onMove),window.addEventListener(`pointerup`,onUp)};return e.addEventListener(`pointerdown`,onDown),()=>{e.removeEventListener(`pointerdown`,onDown),window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp)}}),{connection:r}}var C=1500;function useStory(e){let{steps:i,loop:a=!0,stepDuration:o=C,stepGap:s=0}=e,[l,u]=r({value:e.currentStep,defaultValue:e.defaultCurrentStep??0,onChange:e.onStepChange}),[f,p]=r({value:e.playing,defaultValue:e.defaultPlaying??!0,onChange:e.onPlayingChange}),m=t(()=>i[l.value]??null),h=d(e.clock);h.current=e.clock;let g=d(i);g.current=i;let clock=()=>h.current??{setTimeout:(e,t)=>window.setTimeout(e,t),clearTimeout:e=>window.clearTimeout(e)},advance=e=>{let t=g.current.length;if(t===0)return;let r=l.peek()+e;u(a?(r%t+t)%t:Math.max(0,Math.min(t-1,r)))};return c(()=>{if(!f.value)return;let e=l.value,t=i.length;if(t===0||typeof window>`u`&&!h.current)return;let r=(i[e]?.duration??o)+s,c=clock(),d=c.setTimeout(()=>{let r=e+1;r>=t?a?u(0):p(!1):u(r)},r);return()=>c.clearTimeout(d)}),{currentStep:l,playing:f,activeStep:m,play:()=>p(!0),pause:()=>p(!1),toggle:()=>p(!f.peek()),next:()=>advance(1),prev:()=>advance(-1),restart:()=>{u(0),p(!0)}}}var w={canvas:`_canvas_6fiig_2`,pane:`_pane_6fiig_13`,panSurface:`_panSurface_6fiig_24`};function FlowCanvas({children:t,flow:r,viewport:i,defaultViewport:a,onViewportChange:o,minZoom:s,maxZoom:c,panOnDrag:u=!0,zoomOnScroll:d=!0,fitView:f=!1,controller:h,chrome:g,className:_,role:v=`application`,...y}){l();let b=useFlow({viewport:i,defaultViewport:a,onViewportChange:o}),x=r??b,S=useViewport(x,{minZoom:s,maxZoom:c,panOnDrag:u,zoomOnScroll:d,fitOnInit:f}),C=h??S,T=x.viewport.value;return m(`div`,{ref:C.containerRef,className:e(w.canvas,_),role:v,...y,children:[m(`div`,{className:w.pane,style:{"--flow-tx":`${T.x}px`,"--flow-ty":`${T.y}px`,"--flow-scale":String(T.zoom)},children:[p(`div`,{ref:C.panHandleRef,className:w.panSurface,"aria-hidden":`true`}),t]}),g]})}var T={background:`_background_1pu9x_2`};function FlowBackground({variant:e=`dots`,gap:t=20,size:r=1,color:i,className:a,style:o,...s}){return p(`div`,{"data-variant":e,"aria-hidden":`true`,className:h(T.background,a),style:{"--flow-bg-gap":`${t}px`,"--flow-bg-size":`${r}px`,"--flow-bg-thick":`${Math.max(1,r)}px`,...i?{"--flow-bg-color":i}:{},...o},...s})}var E={node:`_node_9zyg4_2`};function FlowNode({id:t,position:a,defaultPosition:o,onPositionChange:s,onMeasure:u,zoom:f=1,selected:m=!1,draggable:h=!0,interactive:g=!0,onSelect:_,children:v,className:y,onClick:b,onKeyDown:x,...S}){l();let C=h&&g,[w,T]=r({value:a,defaultValue:o??a??{x:0,y:0},onChange:s}),{handleRef:D,targetRef:O,offset:k,isDragging:A}=i({isDisabled:!C}),j=d(null),setRefs=e=>{j.current=e,D.current=e,O.current=e},M=d(u);M.current=u,c(()=>{let e=j.current;if(!e||typeof ResizeObserver>`u`)return;let report=()=>{let t=e.offsetWidth,r=e.offsetHeight;t>0&&r>0&&M.current?.({width:t,height:r})};report();let t=new ResizeObserver(report);return t.observe(e),()=>t.disconnect()});let N=d(f);N.current=f;let P=d(null);c(()=>{let e=A.value,t=k.value;if(!C)return;if(!e){P.current=null;return}P.current||={pos:w.peek(),off:t};let r=P.current,i=N.current||1;T({x:r.pos.x+(t.x-r.off.x)/i,y:r.pos.y+(t.y-r.off.y)/i})});let F=w.value;return p(`div`,{ref:setRefs,"data-node-id":t,"data-selected":m||void 0,"data-dragging":A.value||void 0,"data-static":!g||void 0,role:`group`,tabIndex:g?0:void 0,className:e(E.node,y),style:{"--flow-x":`${F.x}px`,"--flow-y":`${F.y}px`},onClick:e=>{g&&_?.(t),b?.(e)},onKeyDown:e=>{g&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_?.(t)),x?.(e)},...S,children:v})}var D={handle:`_handle_8a1xa_2`,dot:`_dot_8a1xa_41`};function defaultPosition(e){return e===`source`?`right`:`left`}function FlowHandle({type:e,position:t,id:r,isConnectable:i=!0,className:a,...o}){return p(`div`,{"data-handle-type":e,"data-handle-pos":t??defaultPosition(e),"data-handle-id":r,"data-connectable":i||void 0,"data-flow-handle":``,tabIndex:i?0:-1,className:h(D.handle,a),...o,children:p(`span`,{className:D.dot,"aria-hidden":`true`})})}var O={edgeSvg:`_edgeSvg_789n0_2`,edgePath:`_edgePath_789n0_11`,hit:`_hit_789n0_18`,arrow:`_arrow_789n0_26`,"cascivo-flow-dash":`_cascivo-flow-dash_789n0_1`,label:`_label_789n0_64`};function FlowEdge({id:t,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s=`right`,targetPosition:c=`left`,type:l=`bezier`,animated:d=!1,label:h,selected:g=!1,markerStart:_=!1,markerEnd:v=!0,direction:y=`forward`,active:b,className:x}){let S=u(),C=`flow-arrow-${t??S}`,w=_||v,{d:T,mid:E}=edgePath(l,{source:{x:r,y:i},target:{x:a,y:o},sourcePosition:s,targetPosition:c});return m(f,{children:[m(`svg`,{className:e(O.edgeSvg,x),"data-edge-id":t,"data-animated":d||void 0,"data-selected":g||void 0,"data-active":b||void 0,"data-direction":y,"aria-hidden":`true`,children:[w&&p(`defs`,{children:p(`marker`,{id:C,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:p(`path`,{className:O.arrow,d:`M0,0 L10,5 L0,10 z`})})}),p(`path`,{className:O.hit,d:T}),p(`path`,{className:O.edgePath,d:T,markerStart:_?`url(#${C})`:void 0,markerEnd:v?`url(#${C})`:void 0})]}),h!=null&&p(`div`,{className:O.label,style:{"--flow-label-x":`${E.x}px`,"--flow-label-y":`${E.y}px`},children:h})]})}var k={controls:`_controls_s32im_2`,button:`_button_s32im_32`},A={width:18,height:18,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":!0};function FlowControls({position:t=`bottom-left`,showZoom:r=!0,showFitView:i=!0,onZoomIn:a,onZoomOut:o,onFitView:s,labels:c,className:u,...d}){return l(),m(`div`,{"data-position":t,className:e(k.controls,u),...d,children:[r&&m(f,{children:[p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomIn??_(g.flow.zoomIn),onClick:a,children:p(`svg`,{...A,children:p(`path`,{d:`M12 5v14M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})}),p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomOut??_(g.flow.zoomOut),onClick:o,children:p(`svg`,{...A,children:p(`path`,{d:`M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})})]}),i&&p(`button`,{type:`button`,className:k.button,"aria-label":c?.fitView??_(g.flow.fitView),onClick:s,children:p(`svg`,{...A,children:p(`path`,{d:`M4 9V5a1 1 0 0 1 1-1h4M15 4h4a1 1 0 0 1 1 1v4M20 15v4a1 1 0 0 1-1 1h-4M9 20H5a1 1 0 0 1-1-1v-4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}var j={minimap:`_minimap_rdahv_2`,node:`_node_rdahv_28`,viewport:`_viewport_rdahv_32`};function FlowMiniMap({nodes:t,viewport:r,containerWidth:a,containerHeight:o,width:s=200,height:u=150,position:f=`bottom-right`,nodeColor:h,onViewportChange:v,label:y,ariaLabel:b,className:x}){l();let S=graphBounds(t)??{x:0,y:0,width:1,height:1},C=S.width||1,w=S.height||1,T=C*.1,E=w*.1,D={x:S.x-T,y:S.y-E,width:C+T*2,height:w+E*2},O=Math.min(s/D.width,u/D.height),k=-D.x*O+(s-D.width*O)/2,A=-D.y*O+(u-D.height*O)/2,toMM=e=>({x:e.x*O+k,y:e.y*O+A}),M=null;if(a&&o){let e=screenToFlow({x:0,y:0},r),t=screenToFlow({x:a,y:o},r),i=toMM(e);M={x:i.x,y:i.y,w:(t.x-e.x)*O,h:(t.y-e.y)*O}}let{handleRef:N,offset:P,isDragging:F}=i({isDisabled:!v}),I=d(null),setRectRef=e=>{I.current=e,N.current=e},L=d(v);L.current=v;let R=d(null);return c(()=>{let e=F.value,t=P.value;if(!L.current)return;if(!e){R.current=null;return}R.current||={vp:r,off:t};let i=R.current,a=i.vp.zoom;L.current({x:i.vp.x-(t.x-i.off.x)/O*a,y:i.vp.y-(t.y-i.off.y)/O*a,zoom:a})}),m(`svg`,{"data-position":f,className:e(j.minimap,x),width:s,height:u,role:`img`,"aria-label":b??y??_(g.flow.minimap),children:[t.map(e=>{let t=nodeBounds(e),r=toMM({x:t.x,y:t.y});return p(`rect`,{"data-node-id":e.id,className:j.node,x:r.x,y:r.y,width:t.width*O,height:t.height*O,fill:h},e.id)}),M&&p(`rect`,{ref:setRectRef,"data-viewport":``,className:j.viewport,x:M.x,y:M.y,width:M.w,height:M.h})]})}var M={panel:`_panel_l0cix_2`};function FlowPanel({position:e=`top-right`,children:t,className:r,...i}){return p(`div`,{"data-position":e,className:h(M.panel,r),...i,children:t})}var N={flow:`_flow_vejge_2`},P=0;function Flow({nodes:t,edges:r,onNodesChange:i,onEdgesChange:a,onConnect:o,nodeTypes:c,fitView:u=!0,background:d=!1,controls:h=!1,minimap:g=!1,layout:_,minZoom:v,maxZoom:y,interactive:b=!0,activeEdgeId:x,activeDirection:S,className:C,style:w}){l();let T=useFlow({defaultNodes:_?applyLayout(t,r,_):t,defaultEdges:r,onNodesChange:i,onEdgesChange:a}),E=useViewport(T,{minZoom:v,maxZoom:y,fitOnInit:u}),{connection:D}=useConnection({containerRef:E.containerRef,clientToFlow:(e,t)=>{let r=E.containerRef.current?.getBoundingClientRect();return screenToFlow({x:e-(r?.left??0),y:t-(r?.top??0)},T.viewport.peek())},enabled:b,onConnect:e=>{T.addEdge({id:`e-${++P}`,source:e.source,target:e.target}),o?.(e)}}),select=e=>{T.setNodes(T.nodes.value.map(t=>({...t,selected:t.id===e})))},O=s({}),measure=(e,t)=>{let r=O.peek()[e];r&&r.width===t.width&&r.height===t.height||(O.value={...O.peek(),[e]:t})},k=T.nodes.value,A=T.edges.value,j=T.viewport.value.zoom,M=O.value,F=new Map(k.map(e=>{let t=M[e.id];return[e.id,t?{...e,width:t.width,height:t.height}:e]})),I=D.value;return m(FlowCanvas,{flow:T,controller:E,minZoom:v,maxZoom:y,chrome:m(f,{children:[h&&p(FlowControls,{onZoomIn:E.zoomIn,onZoomOut:E.zoomOut,onFitView:()=>E.fitView()}),g&&p(FlowMiniMap,{nodes:k,viewport:T.viewport.value,containerWidth:E.containerRef.current?.clientWidth,containerHeight:E.containerRef.current?.clientHeight,onViewportChange:T.setViewport})]}),className:e(N.flow,C),style:w,children:[d&&p(FlowBackground,{...typeof d==`object`?d:{}}),A.map(e=>{let t=F.get(e.source),r=F.get(e.target);if(!t||!r)return null;let i=handleAnchor(t,`right`),a=handleAnchor(r,`left`),o=x===e.id,s=o?S:void 0,c=s===`reverse`?!0:s===`forward`?!1:e.markerStart??!1,l=s===`reverse`?!1:s===`forward`?!0:e.markerEnd??!0;return p(FlowEdge,{id:e.id,sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y,type:e.type??`bezier`,animated:e.animated||o,active:o,direction:s,markerStart:c,markerEnd:l,label:e.label,selected:e.selected},e.id)}),I&&p(FlowEdge,{sourceX:I.from.x,sourceY:I.from.y,targetX:I.to.x,targetY:I.to.y,markerEnd:!1}),k.map(e=>p(FlowNode,{id:e.id,position:e.position,zoom:j,interactive:b,selected:e.selected??!1,onSelect:b?select:void 0,onMeasure:t=>measure(e.id,t),onPositionChange:t=>T.updateNode(e.id,{position:t}),children:c&&e.type&&c[e.type]?c[e.type]({node:e}):m(f,{children:[p(`span`,{children:String(e.data?.label??e.id)}),b&&p(FlowHandle,{type:`target`,position:`left`}),b&&p(FlowHandle,{type:`source`,position:`right`})]})},e.id))]})}var F={story:`_story_btt88_2`,overlay:`_overlay_btt88_7`,caption:`_caption_btt88_20`,captionText:`_captionText_btt88_36`,captionDesc:`_captionDesc_btt88_48`,controls:`_controls_btt88_52`,button:`_button_btt88_64`,indicator:`_indicator_btt88_93`},I={width:18,height:18,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0};function FlowStory({nodes:t,edges:r,script:i,loop:a=!0,stepDuration:o=1500,stepGap:s=0,playing:c,currentStep:u,onStepChange:d,controls:f=!0,autoPlay:h=!0,background:v=!0,interactive:y=!1,labels:b,clock:x,className:S,style:C}){l();let w=resolveScript(i,r),T=useStory({steps:w,loop:a,stepDuration:o,stepGap:s,playing:c,defaultPlaying:h,currentStep:u,defaultCurrentStep:0,onStepChange:d,clock:x}),E=T.activeStep.value,D=T.currentStep.value,O=T.playing.value;return m(`div`,{className:e(F.story,S),style:C,children:[p(Flow,{nodes:t,edges:r,background:v,interactive:y,activeEdgeId:E?.edgeId,activeDirection:E?.direction}),m(`div`,{className:F.overlay,children:[p(`div`,{className:F.caption,"aria-live":`polite`,children:E?.label&&m(`span`,{className:F.captionText,children:[p(`strong`,{children:E.label}),E.description&&m(`span`,{className:F.captionDesc,children:[` — `,E.description]})]},D)}),f&&m(`div`,{className:F.controls,children:[p(`button`,{type:`button`,className:F.button,"aria-label":b?.previous??_(g.flow.previous),onClick:T.prev,children:p(`svg`,{...I,children:p(`path`,{d:`M15 6 9 12l6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),p(`button`,{type:`button`,className:F.button,"aria-label":O?b?.pause??_(g.flow.pause):b?.play??_(g.flow.play),"aria-pressed":O,onClick:T.toggle,children:O?p(`svg`,{...I,children:p(`path`,{d:`M7 5h3v14H7zM14 5h3v14h-3z`})}):p(`svg`,{...I,children:p(`path`,{d:`M7 5l11 7-11 7z`})})}),p(`button`,{type:`button`,className:F.button,"aria-label":b?.next??_(g.flow.next),onClick:T.next,children:p(`svg`,{...I,children:p(`path`,{d:`M9 6l6 6-6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),p(`span`,{className:F.indicator,children:_(g.flow.step,{current:D+1,total:w.length})})]})]})]})}export{v as DEFAULT_NODE_SIZE,Flow,FlowBackground,FlowCanvas,FlowControls,FlowEdge,FlowHandle,FlowMiniMap,FlowNode,FlowPanel,FlowStory,applyLayout,bezierPath,clampZoom,edgePath,fitViewport,flowToScreen,graphBounds,gridLayout,handleAnchor,layeredLayout,nodeBounds,nodeSize,resolveScript,resolveStep,screenToFlow,smoothStepPath,straightPath,useConnection,useFlow,useStory,useViewport};
|
|
1
|
+
"use client";import{cn as e,useComputed as t,useControllableSignal as r,useDraggable as i,useEffectPropSignal as a,useResizeObserver as o,useSignal as s,useSignalEffect as c,useSignals as l}from"@cascivo/core";import{useId as u,useRef as d}from"react";import{Fragment as f,jsx as p,jsxs as m}from"react/jsx-runtime";import{cn as h}from"@cascivo/core/pure";import{builtin as g,t as _}from"@cascivo/i18n";var v={width:150,height:40},y={x:0,y:0,zoom:1};function useFlow(e={}){let[t,i]=r({value:e.nodes,defaultValue:e.defaultNodes??[],onChange:e.onNodesChange}),[a,o]=r({value:e.edges,defaultValue:e.defaultEdges??[],onChange:e.onEdgesChange}),[s,c]=r({value:e.viewport,defaultValue:e.defaultViewport??y,onChange:e.onViewportChange});return{nodes:t,edges:a,viewport:s,setNodes:i,updateNode:(e,r)=>{i(t.value.map(t=>t.id===e?{...t,...r}:t))},setEdges:o,addEdge:e=>{o([...a.value,e])},setViewport:c}}function clampZoom(e,t=.2,r=2){return Math.min(r,Math.max(t,e))}function screenToFlow(e,t){return{x:(e.x-t.x)/t.zoom,y:(e.y-t.y)/t.zoom}}function flowToScreen(e,t){return{x:e.x*t.zoom+t.x,y:e.y*t.zoom+t.y}}function nodeSize(e){return{width:e.width??v.width,height:e.height??v.height}}function nodeBounds(e){let{width:t,height:r}=nodeSize(e);return{x:e.position.x,y:e.position.y,width:t,height:r}}function handleAnchor(e,t){let{x:r,y:i,width:a,height:o}=nodeBounds(e);switch(t){case`top`:return{x:r+a/2,y:i};case`right`:return{x:r+a,y:i+o/2};case`bottom`:return{x:r+a/2,y:i+o};case`left`:return{x:r,y:i+o/2}}}function graphBounds(e){if(e.length===0)return null;let t=1/0,r=1/0,i=-1/0,a=-1/0;for(let o of e){let e=nodeBounds(o);t=Math.min(t,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.width),a=Math.max(a,e.y+e.height)}return{x:t,y:r,width:i-t,height:a-r}}function fitViewport(e,t,r={}){let{padding:i=.1,minZoom:a=.2,maxZoom:o=2}=r;if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{x:t.width/2-e.x,y:t.height/2-e.y,zoom:1};let s=t.width/(e.width*(1+i*2)),c=t.height/(e.height*(1+i*2)),l=clampZoom(Math.min(s,c),a,o);return{x:t.width/2-(e.x+e.width/2)*l,y:t.height/2-(e.y+e.height/2)*l,zoom:l}}var n=e=>Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,``),midpoint=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});function normal(e){switch(e){case`top`:return{x:0,y:-1};case`bottom`:return{x:0,y:1};case`left`:return{x:-1,y:0};case`right`:return{x:1,y:0}}}function straightPath({source:e,target:t}){return{d:`M${n(e.x)},${n(e.y)} L${n(t.x)},${n(t.y)}`,mid:midpoint(e,t)}}function bezierPath(e){let{source:t,target:r,curvature:i=.25}=e,a=e.sourcePosition??`right`,o=e.targetPosition??`left`,s=Math.hypot(r.x-t.x,r.y-t.y),c=Math.max(i*s,20),l=normal(a),u=normal(o),d={x:t.x+l.x*c,y:t.y+l.y*c},f={x:r.x+u.x*c,y:r.y+u.y*c},p={x:(t.x+3*d.x+3*f.x+r.x)/8,y:(t.y+3*d.y+3*f.y+r.y)/8};return{d:`M${n(t.x)},${n(t.y)} C${n(d.x)},${n(d.y)} ${n(f.x)},${n(f.y)} ${n(r.x)},${n(r.y)}`,mid:p}}function len(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function towards(e,t,r){let i=len(e,t)||1;return{x:e.x+(t.x-e.x)/i*r,y:e.y+(t.y-e.y)/i*r}}function roundedPath(e,t){if(e.length<2)return``;let r=e[0],i=`M${n(r.x)},${n(r.y)}`;for(let r=1;r<e.length-1;r++){let a=e[r-1],o=e[r],s=e[r+1],c=Math.min(t,len(a,o)/2,len(o,s)/2),l=towards(o,a,c),u=towards(o,s,c);i+=` L${n(l.x)},${n(l.y)} Q${n(o.x)},${n(o.y)} ${n(u.x)},${n(u.y)}`}let a=e[e.length-1];return i+=` L${n(a.x)},${n(a.y)}`,i}function smoothStepPath(e){let{source:t,target:r,borderRadius:i=8}=e,a=e.sourcePosition??`right`,o=a===`left`||a===`right`,s=[t];if(o){let e=(t.x+r.x)/2;s.push({x:e,y:t.y},{x:e,y:r.y})}else{let e=(t.y+r.y)/2;s.push({x:t.x,y:e},{x:r.x,y:e})}return s.push(r),{d:roundedPath(s,i),mid:midpoint(t,r)}}function edgePath(e,t){switch(e){case`straight`:return straightPath(t);case`smoothstep`:return smoothStepPath(t);case`bezier`:return bezierPath(t)}}function gridLayout(e,t={}){let r=t.gap??40,i=t.nodeWidth??v.width,a=t.nodeHeight??v.height,o=t.columns??Math.max(1,Math.ceil(Math.sqrt(e.length)));return e.map((e,t)=>{let s=t%o,c=Math.floor(t/o);return{...e,position:{x:s*(i+r),y:c*(a+r)}}})}function layeredLayout(e,t,r={}){let i=r.direction??`LR`,a=r.gap??60,o=r.nodeWidth??v.width,s=r.nodeHeight??v.height,c=new Set(e.map(e=>e.id)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;for(let t of e)u.set(t.id,0);for(let e of t)c.has(e.source)&&c.has(e.target)&&(l.set(e.source,[...l.get(e.source)??[],e.target]),u.set(e.target,(u.get(e.target)??0)+1));let d=/* @__PURE__ */ new Map,f=e.filter(e=>(u.get(e.id)??0)===0).map(e=>e.id);for(let e of f)d.set(e,0);let p=new Map(u);for(;f.length>0;){let e=[];for(let t of f){let r=d.get(t)??0;for(let i of l.get(t)??[])d.set(i,Math.max(d.get(i)??0,r+1)),p.set(i,(p.get(i)??0)-1),(p.get(i)??0)===0&&e.push(i)}f=e}for(let t of e)d.has(t.id)||d.set(t.id,0);let m=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new Map;for(let t of e){let e=d.get(t.id)??0,r=h.get(e)??0;m.set(t.id,r),h.set(e,r+1)}return e.map(e=>{let t=d.get(e.id)??0,r=m.get(e.id)??0,c=i===`LR`?{x:t*(o+a),y:r*(s+a)}:{x:r*(o+a),y:t*(s+a)};return{...e,position:c}})}function applyLayout(e,t,r){return r===`grid`?gridLayout(e):r===`layered`?layeredLayout(e,t):r(e,t)}function isEdgeStep(e){return`edge`in e}function resolveStep(e,t){let r={label:e.label,description:e.description,duration:e.duration};if(isEdgeStep(e)){let i=t.find(t=>t.id===e.edge);if(!i)throw Error(`FlowStory: step references unknown edge "${e.edge}"`);return{edgeId:i.id,direction:e.reverse?`reverse`:`forward`,...r}}let i=t.find(t=>t.source===e.from&&t.target===e.to);if(i)return{edgeId:i.id,direction:`forward`,...r};let a=t.find(t=>t.source===e.to&&t.target===e.from);if(a)return{edgeId:a.id,direction:`reverse`,...r};throw Error(`FlowStory: no edge connects "${e.from}" and "${e.to}"`)}function resolveScript(e,t){return e.map(e=>resolveStep(e,t))}var b=1.2;function useViewport(e,t={}){let{minZoom:r=.2,maxZoom:a=2,panOnDrag:s=!0,zoomOnScroll:l=!0,fitPadding:u=.1,fitOnInit:f=!1}=t,{viewport:p,setViewport:m}=e,{ref:h,size:g}=o(),{handleRef:_,offset:v,isDragging:y}=i({isDisabled:!s}),pan=(e,t)=>{let r=p.peek();m({x:r.x+e,y:r.y+t,zoom:r.zoom})},zoomTo=(e,t)=>{let i=p.peek(),o=clampZoom(e,r,a);if(!t){m({x:i.x,y:i.y,zoom:o});return}let s=screenToFlow(t,i);m({x:t.x-s.x*o,y:t.y-s.y*o,zoom:o})},containerCenter=()=>{let e=h.current;if(e)return{x:e.clientWidth/2,y:e.clientHeight/2}},zoomIn=()=>zoomTo(p.peek().zoom*b,containerCenter()),zoomOut=()=>zoomTo(p.peek().zoom/b,containerCenter()),measuredSize=()=>{let e=g.peek();if(e&&e.width>0&&e.height>0)return e;let t=h.current;return t&&t.clientWidth>0?{width:t.clientWidth,height:t.clientHeight}:null},fitView=t=>{let i=graphBounds(e.nodes.peek());if(!i)return;let o=t??measuredSize();o&&m(fitViewport(i,o,{padding:u,minZoom:r,maxZoom:a}))},x=d(null);c(()=>{let e=y.value,t=v.value;if(!s)return;if(!e){x.current=null;return}x.current||={vp:p.peek(),off:t};let r=x.current;m({x:r.vp.x+(t.x-r.off.x),y:r.vp.y+(t.y-r.off.y),zoom:r.vp.zoom})}),c(()=>{if(!l||typeof window>`u`)return;let e=h.current;if(!e)return;let onWheel=t=>{t.preventDefault();let r=e.getBoundingClientRect(),i={x:t.clientX-r.left,y:t.clientY-r.top},a=t.deltaY<0?b:1/b;zoomTo(p.peek().zoom*a,i)};return e.addEventListener(`wheel`,onWheel,{passive:!1}),()=>e.removeEventListener(`wheel`,onWheel)});let S=d(!1);return c(()=>{if(!f||S.current)return;let e=g.value;e&&e.width!==0&&(S.current=!0,fitView(e))}),{containerRef:h,panHandleRef:_,viewport:p,pan,zoomTo,zoomIn,zoomOut,fitView}}var x=`[data-flow-handle][data-handle-type="source"]`,S=`[data-flow-handle][data-handle-type="target"]`;function useConnection(e){let{containerRef:t}=e,r=s(null),i=d(e.onConnect);i.current=e.onConnect;let o=d(e.isValid);o.current=e.isValid;let l=d(e.clientToFlow);l.current=e.clientToFlow;let u=a(e.enabled??!0);return c(()=>{if(!u.value||typeof window>`u`)return;let e=t.current;if(!e)return;let onMove=e=>{let t=r.peek();t&&(r.value={...t,to:l.current(e.clientX,e.clientY)})},onUp=e=>{let t=r.peek();if(window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp),r.value=null,!t)return;let a=e.target,s=a instanceof Element?a.closest(S):null,c=s?.closest(`[data-node-id]`);if(!c)return;let l={source:t.source,target:c.getAttribute(`data-node-id`)??``,sourceHandle:t.sourceHandle,targetHandle:s?.getAttribute(`data-handle-id`)??void 0};l.target&&l.source!==l.target&&(!o.current||o.current(l))&&i.current?.(l)},onDown=e=>{let t=e.target;if(!(t instanceof Element))return;let i=t.closest(x);if(!i)return;let a=i.closest(`[data-node-id]`);if(!a)return;e.stopPropagation();let o=i.getBoundingClientRect();r.value={source:a.getAttribute(`data-node-id`)??``,sourceHandle:i.getAttribute(`data-handle-id`)??void 0,from:l.current(o.left+o.width/2,o.top+o.height/2),to:l.current(e.clientX,e.clientY)},window.addEventListener(`pointermove`,onMove),window.addEventListener(`pointerup`,onUp)};return e.addEventListener(`pointerdown`,onDown),()=>{e.removeEventListener(`pointerdown`,onDown),window.removeEventListener(`pointermove`,onMove),window.removeEventListener(`pointerup`,onUp)}}),{connection:r}}var C=1500;function useStory(e){let{steps:i,loop:a=!0,stepDuration:o=C,stepGap:s=0}=e,[l,u]=r({value:e.currentStep,defaultValue:e.defaultCurrentStep??0,onChange:e.onStepChange}),[f,p]=r({value:e.playing,defaultValue:e.defaultPlaying??!0,onChange:e.onPlayingChange}),m=t(()=>i[l.value]??null),h=d(e.clock);h.current=e.clock;let g=d(i);g.current=i;let clock=()=>h.current??{setTimeout:(e,t)=>window.setTimeout(e,t),clearTimeout:e=>window.clearTimeout(e)},advance=e=>{let t=g.current.length;if(t===0)return;let r=l.peek()+e,i=a?(r%t+t)%t:Math.max(0,Math.min(t-1,r));u(i)};return c(()=>{if(!f.value)return;let e=l.value,t=i.length;if(t===0||typeof window>`u`&&!h.current)return;let r=(i[e]?.duration??o)+s,c=clock(),d=c.setTimeout(()=>{let r=e+1;r>=t?a?u(0):p(!1):u(r)},r);return()=>c.clearTimeout(d)}),{currentStep:l,playing:f,activeStep:m,play:()=>p(!0),pause:()=>p(!1),toggle:()=>p(!f.peek()),next:()=>advance(1),prev:()=>advance(-1),restart:()=>{u(0),p(!0)}}}var w={canvas:`_canvas_6fiig_2`,pane:`_pane_6fiig_13`,panSurface:`_panSurface_6fiig_24`};function FlowCanvas({children:t,flow:r,viewport:i,defaultViewport:a,onViewportChange:o,minZoom:s,maxZoom:c,panOnDrag:u=!0,zoomOnScroll:d=!0,fitView:f=!1,controller:h,chrome:g,className:_,role:v=`application`,...y}){l();let b=useFlow({viewport:i,defaultViewport:a,onViewportChange:o}),x=r??b,S=useViewport(x,{minZoom:s,maxZoom:c,panOnDrag:u,zoomOnScroll:d,fitOnInit:f}),C=h??S,T=x.viewport.value;return/* @__PURE__ */ m(`div`,{ref:C.containerRef,className:e(w.canvas,_),role:v,...y,children:[/* @__PURE__ */ m(`div`,{className:w.pane,style:{"--flow-tx":`${T.x}px`,"--flow-ty":`${T.y}px`,"--flow-scale":String(T.zoom)},children:[/* @__PURE__ */ p(`div`,{ref:C.panHandleRef,className:w.panSurface,"aria-hidden":`true`}),t]}),g]})}var T={background:`_background_1pu9x_2`};function FlowBackground({variant:e=`dots`,gap:t=20,size:r=1,color:i,className:a,style:o,...s}){return/* @__PURE__ */ p(`div`,{"data-variant":e,"aria-hidden":`true`,className:h(T.background,a),style:{"--flow-bg-gap":`${t}px`,"--flow-bg-size":`${r}px`,"--flow-bg-thick":`${Math.max(1,r)}px`,...i?{"--flow-bg-color":i}:{},...o},...s})}var E={node:`_node_9zyg4_2`};function FlowNode({id:t,position:a,defaultPosition:o,onPositionChange:s,onMeasure:u,zoom:f=1,selected:m=!1,draggable:h=!0,interactive:g=!0,onSelect:_,children:v,className:y,onClick:b,onKeyDown:x,...S}){l();let C=h&&g,[w,T]=r({value:a,defaultValue:o??a??{x:0,y:0},onChange:s}),{handleRef:D,targetRef:O,offset:k,isDragging:A}=i({isDisabled:!C}),j=d(null),setRefs=e=>{j.current=e,D.current=e,O.current=e},M=d(u);M.current=u,c(()=>{let e=j.current;if(!e||typeof ResizeObserver>`u`)return;let report=()=>{let t=e.offsetWidth,r=e.offsetHeight;t>0&&r>0&&M.current?.({width:t,height:r})};report();let t=new ResizeObserver(report);return t.observe(e),()=>t.disconnect()});let N=d(f);N.current=f;let P=d(null);c(()=>{let e=A.value,t=k.value;if(!C)return;if(!e){P.current=null;return}P.current||={pos:w.peek(),off:t};let r=P.current,i=N.current||1;T({x:r.pos.x+(t.x-r.off.x)/i,y:r.pos.y+(t.y-r.off.y)/i})});let F=w.value;return/* @__PURE__ */ p(`div`,{ref:setRefs,"data-node-id":t,"data-selected":m||void 0,"data-dragging":A.value||void 0,"data-static":!g||void 0,role:`group`,tabIndex:g?0:void 0,className:e(E.node,y),style:{"--flow-x":`${F.x}px`,"--flow-y":`${F.y}px`},onClick:e=>{g&&_?.(t),b?.(e)},onKeyDown:e=>{g&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_?.(t)),x?.(e)},...S,children:v})}var D={handle:`_handle_8a1xa_2`,dot:`_dot_8a1xa_41`};function defaultPosition(e){return e===`source`?`right`:`left`}function FlowHandle({type:e,position:t,id:r,isConnectable:i=!0,className:a,...o}){let s=t??defaultPosition(e);return/* @__PURE__ */ p(`div`,{"data-handle-type":e,"data-handle-pos":s,"data-handle-id":r,"data-connectable":i||void 0,"data-flow-handle":``,tabIndex:i?0:-1,className:h(D.handle,a),...o,children:/* @__PURE__ */ p(`span`,{className:D.dot,"aria-hidden":`true`})})}var O={edgeSvg:`_edgeSvg_789n0_2`,edgePath:`_edgePath_789n0_11`,hit:`_hit_789n0_18`,arrow:`_arrow_789n0_26`,"cascivo-flow-dash":`_cascivo-flow-dash_789n0_1`,label:`_label_789n0_64`};function FlowEdge({id:t,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s=`right`,targetPosition:c=`left`,type:l=`bezier`,animated:d=!1,label:h,selected:g=!1,markerStart:_=!1,markerEnd:v=!0,direction:y=`forward`,active:b,className:x}){let S=u(),C=`flow-arrow-${t??S}`,w=_||v,{d:T,mid:E}=edgePath(l,{source:{x:r,y:i},target:{x:a,y:o},sourcePosition:s,targetPosition:c});return/* @__PURE__ */ m(f,{children:[/* @__PURE__ */ m(`svg`,{className:e(O.edgeSvg,x),"data-edge-id":t,"data-animated":d||void 0,"data-selected":g||void 0,"data-active":b||void 0,"data-direction":y,"aria-hidden":`true`,children:[w&&/* @__PURE__ */ p(`defs`,{children:/* @__PURE__ */ p(`marker`,{id:C,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:/* @__PURE__ */ p(`path`,{className:O.arrow,d:`M0,0 L10,5 L0,10 z`})})}),/* @__PURE__ */ p(`path`,{className:O.hit,d:T}),/* @__PURE__ */ p(`path`,{className:O.edgePath,d:T,markerStart:_?`url(#${C})`:void 0,markerEnd:v?`url(#${C})`:void 0})]}),h!=null&&/* @__PURE__ */ p(`div`,{className:O.label,style:{"--flow-label-x":`${E.x}px`,"--flow-label-y":`${E.y}px`},children:h})]})}var k={controls:`_controls_s32im_2`,button:`_button_s32im_32`},A={width:18,height:18,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":!0};function FlowControls({position:t=`bottom-left`,showZoom:r=!0,showFitView:i=!0,onZoomIn:a,onZoomOut:o,onFitView:s,labels:c,className:u,...d}){return l(),/* @__PURE__ */ m(`div`,{"data-position":t,className:e(k.controls,u),...d,children:[r&&/* @__PURE__ */ m(f,{children:[/* @__PURE__ */ p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomIn??_(g.flow.zoomIn),onClick:a,children:/* @__PURE__ */ p(`svg`,{...A,children:/* @__PURE__ */ p(`path`,{d:`M12 5v14M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})}),/* @__PURE__ */ p(`button`,{type:`button`,className:k.button,"aria-label":c?.zoomOut??_(g.flow.zoomOut),onClick:o,children:/* @__PURE__ */ p(`svg`,{...A,children:/* @__PURE__ */ p(`path`,{d:`M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})})]}),i&&/* @__PURE__ */ p(`button`,{type:`button`,className:k.button,"aria-label":c?.fitView??_(g.flow.fitView),onClick:s,children:/* @__PURE__ */ p(`svg`,{...A,children:/* @__PURE__ */ p(`path`,{d:`M4 9V5a1 1 0 0 1 1-1h4M15 4h4a1 1 0 0 1 1 1v4M20 15v4a1 1 0 0 1-1 1h-4M9 20H5a1 1 0 0 1-1-1v-4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}var j={minimap:`_minimap_rdahv_2`,node:`_node_rdahv_28`,viewport:`_viewport_rdahv_32`};function FlowMiniMap({nodes:t,viewport:r,containerWidth:a,containerHeight:o,width:s=200,height:u=150,position:f=`bottom-right`,nodeColor:h,onViewportChange:v,label:y,ariaLabel:b,className:x}){l();let S=graphBounds(t)??{x:0,y:0,width:1,height:1},C=S.width||1,w=S.height||1,T=C*.1,E=w*.1,D={x:S.x-T,y:S.y-E,width:C+T*2,height:w+E*2},O=Math.min(s/D.width,u/D.height),k=-D.x*O+(s-D.width*O)/2,A=-D.y*O+(u-D.height*O)/2,toMM=e=>({x:e.x*O+k,y:e.y*O+A}),M=null;if(a&&o){let e=screenToFlow({x:0,y:0},r),t=screenToFlow({x:a,y:o},r),i=toMM(e);M={x:i.x,y:i.y,w:(t.x-e.x)*O,h:(t.y-e.y)*O}}let{handleRef:N,offset:P,isDragging:F}=i({isDisabled:!v}),I=d(null),setRectRef=e=>{I.current=e,N.current=e},L=d(v);L.current=v;let R=d(null);return c(()=>{let e=F.value,t=P.value;if(!L.current)return;if(!e){R.current=null;return}R.current||={vp:r,off:t};let i=R.current,a=i.vp.zoom;L.current({x:i.vp.x-(t.x-i.off.x)/O*a,y:i.vp.y-(t.y-i.off.y)/O*a,zoom:a})}),/* @__PURE__ */ m(`svg`,{"data-position":f,className:e(j.minimap,x),width:s,height:u,role:`img`,"aria-label":b??y??_(g.flow.minimap),children:[t.map(e=>{let t=nodeBounds(e),r=toMM({x:t.x,y:t.y});return/* @__PURE__ */ p(`rect`,{"data-node-id":e.id,className:j.node,x:r.x,y:r.y,width:t.width*O,height:t.height*O,fill:h},e.id)}),M&&/* @__PURE__ */ p(`rect`,{ref:setRectRef,"data-viewport":``,className:j.viewport,x:M.x,y:M.y,width:M.w,height:M.h})]})}var M={panel:`_panel_l0cix_2`};function FlowPanel({position:e=`top-right`,children:t,className:r,...i}){return/* @__PURE__ */ p(`div`,{"data-position":e,className:h(M.panel,r),...i,children:t})}var N={flow:`_flow_vejge_2`},P=0;function Flow({nodes:t,edges:r,onNodesChange:i,onEdgesChange:a,onConnect:o,nodeTypes:c,fitView:u=!0,background:d=!1,controls:h=!1,minimap:g=!1,layout:_,minZoom:v,maxZoom:y,interactive:b=!0,activeEdgeId:x,activeDirection:S,className:C,style:w}){l();let T=useFlow({defaultNodes:_?applyLayout(t,r,_):t,defaultEdges:r,onNodesChange:i,onEdgesChange:a}),E=useViewport(T,{minZoom:v,maxZoom:y,fitOnInit:u}),{connection:D}=useConnection({containerRef:E.containerRef,clientToFlow:(e,t)=>{let r=E.containerRef.current?.getBoundingClientRect();return screenToFlow({x:e-(r?.left??0),y:t-(r?.top??0)},T.viewport.peek())},enabled:b,onConnect:e=>{T.addEdge({id:`e-${++P}`,source:e.source,target:e.target}),o?.(e)}}),select=e=>{T.setNodes(T.nodes.value.map(t=>({...t,selected:t.id===e})))},O=s({}),measure=(e,t)=>{let r=O.peek()[e];r&&r.width===t.width&&r.height===t.height||(O.value={...O.peek(),[e]:t})},k=T.nodes.value,A=T.edges.value,j=T.viewport.value.zoom,M=O.value,F=new Map(k.map(e=>{let t=M[e.id];return[e.id,t?{...e,width:t.width,height:t.height}:e]})),I=D.value,L=/* @__PURE__ */ m(f,{children:[h&&/* @__PURE__ */ p(FlowControls,{onZoomIn:E.zoomIn,onZoomOut:E.zoomOut,onFitView:()=>E.fitView()}),g&&/* @__PURE__ */ p(FlowMiniMap,{nodes:k,viewport:T.viewport.value,containerWidth:E.containerRef.current?.clientWidth,containerHeight:E.containerRef.current?.clientHeight,onViewportChange:T.setViewport})]});return/* @__PURE__ */ m(FlowCanvas,{flow:T,controller:E,minZoom:v,maxZoom:y,chrome:L,className:e(N.flow,C),style:w,children:[d&&/* @__PURE__ */ p(FlowBackground,{...typeof d==`object`?d:{}}),A.map(e=>{let t=F.get(e.source),r=F.get(e.target);if(!t||!r)return null;let i=handleAnchor(t,`right`),a=handleAnchor(r,`left`),o=x===e.id,s=o?S:void 0,c=s===`reverse`?!0:s===`forward`?!1:e.markerStart??!1,l=s===`reverse`?!1:s===`forward`?!0:e.markerEnd??!0;return/* @__PURE__ */ p(FlowEdge,{id:e.id,sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y,type:e.type??`bezier`,animated:e.animated||o,active:o,direction:s,markerStart:c,markerEnd:l,label:e.label,selected:e.selected},e.id)}),I&&/* @__PURE__ */ p(FlowEdge,{sourceX:I.from.x,sourceY:I.from.y,targetX:I.to.x,targetY:I.to.y,markerEnd:!1}),k.map(e=>/* @__PURE__ */ p(FlowNode,{id:e.id,position:e.position,zoom:j,interactive:b,selected:e.selected??!1,onSelect:b?select:void 0,onMeasure:t=>measure(e.id,t),onPositionChange:t=>T.updateNode(e.id,{position:t}),children:c&&e.type&&c[e.type]?c[e.type]({node:e}):/* @__PURE__ */ m(f,{children:[/* @__PURE__ */ p(`span`,{children:String(e.data?.label??e.id)}),b&&/* @__PURE__ */ p(FlowHandle,{type:`target`,position:`left`}),b&&/* @__PURE__ */ p(FlowHandle,{type:`source`,position:`right`})]})},e.id))]})}var F={story:`_story_btt88_2`,overlay:`_overlay_btt88_7`,caption:`_caption_btt88_20`,captionText:`_captionText_btt88_36`,captionDesc:`_captionDesc_btt88_48`,controls:`_controls_btt88_52`,button:`_button_btt88_64`,indicator:`_indicator_btt88_93`},I={width:18,height:18,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0};function FlowStory({nodes:t,edges:r,script:i,loop:a=!0,stepDuration:o=1500,stepGap:s=0,playing:c,currentStep:u,onStepChange:d,controls:f=!0,autoPlay:h=!0,background:v=!0,interactive:y=!1,labels:b,clock:x,className:S,style:C}){l();let w=resolveScript(i,r),T=useStory({steps:w,loop:a,stepDuration:o,stepGap:s,playing:c,defaultPlaying:h,currentStep:u,defaultCurrentStep:0,onStepChange:d,clock:x}),E=T.activeStep.value,D=T.currentStep.value,O=T.playing.value;return/* @__PURE__ */ m(`div`,{className:e(F.story,S),style:C,children:[/* @__PURE__ */ p(Flow,{nodes:t,edges:r,background:v,interactive:y,activeEdgeId:E?.edgeId,activeDirection:E?.direction}),/* @__PURE__ */ m(`div`,{className:F.overlay,children:[/* @__PURE__ */ p(`div`,{className:F.caption,"aria-live":`polite`,children:E?.label&&/* @__PURE__ */ m(`span`,{className:F.captionText,children:[/* @__PURE__ */ p(`strong`,{children:E.label}),E.description&&/* @__PURE__ */ m(`span`,{className:F.captionDesc,children:[` — `,E.description]})]},D)}),f&&/* @__PURE__ */ m(`div`,{className:F.controls,children:[/* @__PURE__ */ p(`button`,{type:`button`,className:F.button,"aria-label":b?.previous??_(g.flow.previous),onClick:T.prev,children:/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M15 6 9 12l6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),/* @__PURE__ */ p(`button`,{type:`button`,className:F.button,"aria-label":O?b?.pause??_(g.flow.pause):b?.play??_(g.flow.play),"aria-pressed":O,onClick:T.toggle,children:O?/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M7 5h3v14H7zM14 5h3v14h-3z`})}):/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M7 5l11 7-11 7z`})})}),/* @__PURE__ */ p(`button`,{type:`button`,className:F.button,"aria-label":b?.next??_(g.flow.next),onClick:T.next,children:/* @__PURE__ */ p(`svg`,{...I,children:/* @__PURE__ */ p(`path`,{d:`M9 6l6 6-6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),/* @__PURE__ */ p(`span`,{className:F.indicator,children:_(g.flow.step,{current:D+1,total:w.length})})]})]})]})}export{v as DEFAULT_NODE_SIZE,Flow,FlowBackground,FlowCanvas,FlowControls,FlowEdge,FlowHandle,FlowMiniMap,FlowNode,FlowPanel,FlowStory,applyLayout,bezierPath,clampZoom,edgePath,fitViewport,flowToScreen,graphBounds,gridLayout,handleAnchor,layeredLayout,nodeBounds,nodeSize,resolveScript,resolveStep,screenToFlow,smoothStepPath,straightPath,useConnection,useFlow,useStory,useViewport};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cascivo/flow",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Flow & diagram components — CSS-native, signal-driven node/edge graphs with pan/zoom, draggable nodes, animated edges, and scripted storylines, zero dependencies",
|
|
6
6
|
"keywords": [
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"provenance": true
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cascivo/core": "^1.
|
|
52
|
-
"@cascivo/i18n": "^1.
|
|
51
|
+
"@cascivo/core": "^1.7.0",
|
|
52
|
+
"@cascivo/i18n": "^1.7.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"react": "^19.2.7",
|
|
63
63
|
"react-dom": "^19.2.7",
|
|
64
64
|
"typescript": "^5",
|
|
65
|
-
"vite-plus": "^0.
|
|
65
|
+
"vite-plus": "^1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@preact/signals-react": ">=3.0.0",
|