@cascivo/flow 0.1.5 → 0.1.10

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/dist/index.js ADDED
@@ -0,0 +1,1137 @@
1
+ "use client";
2
+ import { cn as e, useComputed as t, useControllableSignal as n, useDraggable as r, useResizeObserver as i, useSignal as a, useSignalEffect as o, useSignals as s } from "@cascivo/core";
3
+ import { useId as c, useRef as l } from "react";
4
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
5
+ import { builtin as p, t as m } from "@cascivo/i18n";
6
+ //#region src/engine/types.ts
7
+ var h = {
8
+ width: 150,
9
+ height: 40
10
+ }, g = {
11
+ x: 0,
12
+ y: 0,
13
+ zoom: 1
14
+ };
15
+ function _(e = {}) {
16
+ let [t, r] = n({
17
+ value: e.nodes,
18
+ defaultValue: e.defaultNodes ?? [],
19
+ onChange: e.onNodesChange
20
+ }), [i, a] = n({
21
+ value: e.edges,
22
+ defaultValue: e.defaultEdges ?? [],
23
+ onChange: e.onEdgesChange
24
+ }), [o, s] = n({
25
+ value: e.viewport,
26
+ defaultValue: e.defaultViewport ?? g,
27
+ onChange: e.onViewportChange
28
+ });
29
+ return {
30
+ nodes: t,
31
+ edges: i,
32
+ viewport: o,
33
+ setNodes: r,
34
+ updateNode: (e, n) => {
35
+ r(t.value.map((t) => t.id === e ? {
36
+ ...t,
37
+ ...n
38
+ } : t));
39
+ },
40
+ setEdges: a,
41
+ addEdge: (e) => {
42
+ a([...i.value, e]);
43
+ },
44
+ setViewport: s
45
+ };
46
+ }
47
+ //#endregion
48
+ //#region src/engine/transform.ts
49
+ function v(e, t = .2, n = 2) {
50
+ return Math.min(n, Math.max(t, e));
51
+ }
52
+ function y(e, t) {
53
+ return {
54
+ x: (e.x - t.x) / t.zoom,
55
+ y: (e.y - t.y) / t.zoom
56
+ };
57
+ }
58
+ function b(e, t) {
59
+ return {
60
+ x: e.x * t.zoom + t.x,
61
+ y: e.y * t.zoom + t.y
62
+ };
63
+ }
64
+ //#endregion
65
+ //#region src/engine/geometry.ts
66
+ function x(e) {
67
+ return {
68
+ width: e.width ?? h.width,
69
+ height: e.height ?? h.height
70
+ };
71
+ }
72
+ function S(e) {
73
+ let { width: t, height: n } = x(e);
74
+ return {
75
+ x: e.position.x,
76
+ y: e.position.y,
77
+ width: t,
78
+ height: n
79
+ };
80
+ }
81
+ function C(e, t) {
82
+ let { x: n, y: r, width: i, height: a } = S(e);
83
+ switch (t) {
84
+ case "top": return {
85
+ x: n + i / 2,
86
+ y: r
87
+ };
88
+ case "right": return {
89
+ x: n + i,
90
+ y: r + a / 2
91
+ };
92
+ case "bottom": return {
93
+ x: n + i / 2,
94
+ y: r + a
95
+ };
96
+ case "left": return {
97
+ x: n,
98
+ y: r + a / 2
99
+ };
100
+ }
101
+ }
102
+ function w(e) {
103
+ if (e.length === 0) return null;
104
+ let t = Infinity, n = Infinity, r = -Infinity, i = -Infinity;
105
+ for (let a of e) {
106
+ let e = S(a);
107
+ t = Math.min(t, e.x), n = Math.min(n, e.y), r = Math.max(r, e.x + e.width), i = Math.max(i, e.y + e.height);
108
+ }
109
+ return {
110
+ x: t,
111
+ y: n,
112
+ width: r - t,
113
+ height: i - n
114
+ };
115
+ }
116
+ function T(e, t, n = {}) {
117
+ let { padding: r = .1, minZoom: i = .2, maxZoom: a = 2 } = n;
118
+ if (e.width <= 0 || e.height <= 0 || t.width <= 0 || t.height <= 0) return {
119
+ x: t.width / 2 - e.x,
120
+ y: t.height / 2 - e.y,
121
+ zoom: 1
122
+ };
123
+ let o = t.width / (e.width * (1 + r * 2)), s = t.height / (e.height * (1 + r * 2)), c = v(Math.min(o, s), i, a);
124
+ return {
125
+ x: t.width / 2 - (e.x + e.width / 2) * c,
126
+ y: t.height / 2 - (e.y + e.height / 2) * c,
127
+ zoom: c
128
+ };
129
+ }
130
+ //#endregion
131
+ //#region src/engine/path.ts
132
+ var E = (e) => Number.isInteger(e) ? String(e) : e.toFixed(2).replace(/\.?0+$/, ""), D = (e, t) => ({
133
+ x: (e.x + t.x) / 2,
134
+ y: (e.y + t.y) / 2
135
+ });
136
+ function O(e) {
137
+ switch (e) {
138
+ case "top": return {
139
+ x: 0,
140
+ y: -1
141
+ };
142
+ case "bottom": return {
143
+ x: 0,
144
+ y: 1
145
+ };
146
+ case "left": return {
147
+ x: -1,
148
+ y: 0
149
+ };
150
+ case "right": return {
151
+ x: 1,
152
+ y: 0
153
+ };
154
+ }
155
+ }
156
+ function k({ source: e, target: t }) {
157
+ return {
158
+ d: `M${E(e.x)},${E(e.y)} L${E(t.x)},${E(t.y)}`,
159
+ mid: D(e, t)
160
+ };
161
+ }
162
+ function A(e) {
163
+ let { source: t, target: n, curvature: r = .25 } = e, i = e.sourcePosition ?? "right", a = e.targetPosition ?? "left", o = Math.hypot(n.x - t.x, n.y - t.y), s = Math.max(r * o, 20), c = O(i), l = O(a), u = {
164
+ x: t.x + c.x * s,
165
+ y: t.y + c.y * s
166
+ }, d = {
167
+ x: n.x + l.x * s,
168
+ y: n.y + l.y * s
169
+ }, f = {
170
+ x: (t.x + 3 * u.x + 3 * d.x + n.x) / 8,
171
+ y: (t.y + 3 * u.y + 3 * d.y + n.y) / 8
172
+ };
173
+ return {
174
+ d: `M${E(t.x)},${E(t.y)} C${E(u.x)},${E(u.y)} ${E(d.x)},${E(d.y)} ${E(n.x)},${E(n.y)}`,
175
+ mid: f
176
+ };
177
+ }
178
+ function j(e, t) {
179
+ return Math.hypot(t.x - e.x, t.y - e.y);
180
+ }
181
+ function M(e, t, n) {
182
+ let r = j(e, t) || 1;
183
+ return {
184
+ x: e.x + (t.x - e.x) / r * n,
185
+ y: e.y + (t.y - e.y) / r * n
186
+ };
187
+ }
188
+ function N(e, t) {
189
+ if (e.length < 2) return "";
190
+ let n = e[0], r = `M${E(n.x)},${E(n.y)}`;
191
+ for (let n = 1; n < e.length - 1; n++) {
192
+ let i = e[n - 1], a = e[n], o = e[n + 1], s = Math.min(t, j(i, a) / 2, j(a, o) / 2), c = M(a, i, s), l = M(a, o, s);
193
+ r += ` L${E(c.x)},${E(c.y)} Q${E(a.x)},${E(a.y)} ${E(l.x)},${E(l.y)}`;
194
+ }
195
+ let i = e[e.length - 1];
196
+ return r += ` L${E(i.x)},${E(i.y)}`, r;
197
+ }
198
+ function P(e) {
199
+ let { source: t, target: n, borderRadius: r = 8 } = e, i = e.sourcePosition ?? "right", a = i === "left" || i === "right", o = [t];
200
+ if (a) {
201
+ let e = (t.x + n.x) / 2;
202
+ o.push({
203
+ x: e,
204
+ y: t.y
205
+ }, {
206
+ x: e,
207
+ y: n.y
208
+ });
209
+ } else {
210
+ let e = (t.y + n.y) / 2;
211
+ o.push({
212
+ x: t.x,
213
+ y: e
214
+ }, {
215
+ x: n.x,
216
+ y: e
217
+ });
218
+ }
219
+ return o.push(n), {
220
+ d: N(o, r),
221
+ mid: D(t, n)
222
+ };
223
+ }
224
+ function F(e, t) {
225
+ switch (e) {
226
+ case "straight": return k(t);
227
+ case "smoothstep": return P(t);
228
+ case "bezier": return A(t);
229
+ }
230
+ }
231
+ //#endregion
232
+ //#region src/engine/layout.ts
233
+ function I(e, t = {}) {
234
+ let n = t.gap ?? 40, r = t.nodeWidth ?? h.width, i = t.nodeHeight ?? h.height, a = t.columns ?? Math.max(1, Math.ceil(Math.sqrt(e.length)));
235
+ return e.map((e, t) => {
236
+ let o = t % a, s = Math.floor(t / a);
237
+ return {
238
+ ...e,
239
+ position: {
240
+ x: o * (r + n),
241
+ y: s * (i + n)
242
+ }
243
+ };
244
+ });
245
+ }
246
+ function L(e, t, n = {}) {
247
+ let r = n.direction ?? "LR", i = n.gap ?? 60, a = n.nodeWidth ?? h.width, o = n.nodeHeight ?? h.height, s = new Set(e.map((e) => e.id)), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
248
+ for (let t of e) l.set(t.id, 0);
249
+ for (let e of t) !s.has(e.source) || !s.has(e.target) || (c.set(e.source, [...c.get(e.source) ?? [], e.target]), l.set(e.target, (l.get(e.target) ?? 0) + 1));
250
+ let u = /* @__PURE__ */ new Map(), d = e.filter((e) => (l.get(e.id) ?? 0) === 0).map((e) => e.id);
251
+ for (let e of d) u.set(e, 0);
252
+ let f = new Map(l);
253
+ for (; d.length > 0;) {
254
+ let e = [];
255
+ for (let t of d) {
256
+ let n = u.get(t) ?? 0;
257
+ for (let r of c.get(t) ?? []) u.set(r, Math.max(u.get(r) ?? 0, n + 1)), f.set(r, (f.get(r) ?? 0) - 1), (f.get(r) ?? 0) === 0 && e.push(r);
258
+ }
259
+ d = e;
260
+ }
261
+ for (let t of e) u.has(t.id) || u.set(t.id, 0);
262
+ let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
263
+ for (let t of e) {
264
+ let e = u.get(t.id) ?? 0, n = m.get(e) ?? 0;
265
+ p.set(t.id, n), m.set(e, n + 1);
266
+ }
267
+ return e.map((e) => {
268
+ let t = u.get(e.id) ?? 0, n = p.get(e.id) ?? 0, s = r === "LR" ? {
269
+ x: t * (a + i),
270
+ y: n * (o + i)
271
+ } : {
272
+ x: n * (a + i),
273
+ y: t * (o + i)
274
+ };
275
+ return {
276
+ ...e,
277
+ position: s
278
+ };
279
+ });
280
+ }
281
+ function R(e, t, n) {
282
+ return n === "grid" ? I(e) : n === "layered" ? L(e, t) : n(e, t);
283
+ }
284
+ //#endregion
285
+ //#region src/engine/script.ts
286
+ function z(e) {
287
+ return "edge" in e;
288
+ }
289
+ function B(e, t) {
290
+ let n = {
291
+ label: e.label,
292
+ description: e.description,
293
+ duration: e.duration
294
+ };
295
+ if (z(e)) {
296
+ let r = t.find((t) => t.id === e.edge);
297
+ if (!r) throw Error(`FlowStory: step references unknown edge "${e.edge}"`);
298
+ return {
299
+ edgeId: r.id,
300
+ direction: e.reverse ? "reverse" : "forward",
301
+ ...n
302
+ };
303
+ }
304
+ let r = t.find((t) => t.source === e.from && t.target === e.to);
305
+ if (r) return {
306
+ edgeId: r.id,
307
+ direction: "forward",
308
+ ...n
309
+ };
310
+ let i = t.find((t) => t.source === e.to && t.target === e.from);
311
+ if (i) return {
312
+ edgeId: i.id,
313
+ direction: "reverse",
314
+ ...n
315
+ };
316
+ throw Error(`FlowStory: no edge connects "${e.from}" and "${e.to}"`);
317
+ }
318
+ function V(e, t) {
319
+ return e.map((e) => B(e, t));
320
+ }
321
+ //#endregion
322
+ //#region src/core/use-viewport.ts
323
+ var H = 1.2;
324
+ function U(e, t = {}) {
325
+ let { minZoom: n = .2, maxZoom: a = 2, panOnDrag: s = !0, zoomOnScroll: c = !0, fitPadding: u = .1, fitOnInit: d = !1 } = t, { viewport: f, setViewport: p } = e, { ref: m, size: h } = i(), { handleRef: g, offset: _, isDragging: b } = r({ isDisabled: !s }), x = (e, t) => {
326
+ let n = f.peek();
327
+ p({
328
+ x: n.x + e,
329
+ y: n.y + t,
330
+ zoom: n.zoom
331
+ });
332
+ }, S = (e, t) => {
333
+ let r = f.peek(), i = v(e, n, a);
334
+ if (!t) {
335
+ p({
336
+ x: r.x,
337
+ y: r.y,
338
+ zoom: i
339
+ });
340
+ return;
341
+ }
342
+ let o = y(t, r);
343
+ p({
344
+ x: t.x - o.x * i,
345
+ y: t.y - o.y * i,
346
+ zoom: i
347
+ });
348
+ }, C = () => {
349
+ let e = m.current;
350
+ if (e) return {
351
+ x: e.clientWidth / 2,
352
+ y: e.clientHeight / 2
353
+ };
354
+ }, E = () => S(f.peek().zoom * H, C()), D = () => S(f.peek().zoom / H, C()), O = () => {
355
+ let e = h.peek();
356
+ if (e && e.width > 0 && e.height > 0) return e;
357
+ let t = m.current;
358
+ return t && t.clientWidth > 0 ? {
359
+ width: t.clientWidth,
360
+ height: t.clientHeight
361
+ } : null;
362
+ }, k = (t) => {
363
+ let r = w(e.nodes.peek());
364
+ if (!r) return;
365
+ let i = t ?? O();
366
+ i && p(T(r, i, {
367
+ padding: u,
368
+ minZoom: n,
369
+ maxZoom: a
370
+ }));
371
+ }, A = l(null);
372
+ o(() => {
373
+ let e = b.value, t = _.value;
374
+ if (!s) return;
375
+ if (!e) {
376
+ A.current = null;
377
+ return;
378
+ }
379
+ A.current ||= {
380
+ vp: f.peek(),
381
+ off: t
382
+ };
383
+ let n = A.current;
384
+ p({
385
+ x: n.vp.x + (t.x - n.off.x),
386
+ y: n.vp.y + (t.y - n.off.y),
387
+ zoom: n.vp.zoom
388
+ });
389
+ }), o(() => {
390
+ if (!c || typeof window > "u") return;
391
+ let e = m.current;
392
+ if (!e) return;
393
+ let t = (t) => {
394
+ t.preventDefault();
395
+ let n = e.getBoundingClientRect(), r = {
396
+ x: t.clientX - n.left,
397
+ y: t.clientY - n.top
398
+ }, i = t.deltaY < 0 ? H : 1 / H;
399
+ S(f.peek().zoom * i, r);
400
+ };
401
+ return e.addEventListener("wheel", t, { passive: !1 }), () => e.removeEventListener("wheel", t);
402
+ });
403
+ let j = l(!1);
404
+ return o(() => {
405
+ if (!d || j.current) return;
406
+ let e = h.value;
407
+ !e || e.width === 0 || (j.current = !0, k(e));
408
+ }), {
409
+ containerRef: m,
410
+ panHandleRef: g,
411
+ viewport: f,
412
+ pan: x,
413
+ zoomTo: S,
414
+ zoomIn: E,
415
+ zoomOut: D,
416
+ fitView: k
417
+ };
418
+ }
419
+ //#endregion
420
+ //#region src/core/use-connection.ts
421
+ var ee = "[data-flow-handle][data-handle-type=\"source\"]", te = "[data-flow-handle][data-handle-type=\"target\"]";
422
+ function W(e) {
423
+ let { containerRef: t } = e, n = a(null), r = l(e.onConnect);
424
+ r.current = e.onConnect;
425
+ let i = l(e.isValid);
426
+ i.current = e.isValid;
427
+ let s = l(e.clientToFlow);
428
+ s.current = e.clientToFlow;
429
+ let c = a(e.enabled ?? !0);
430
+ return c.value = e.enabled ?? !0, o(() => {
431
+ if (!c.value || typeof window > "u") return;
432
+ let e = t.current;
433
+ if (!e) return;
434
+ let a = (e) => {
435
+ let t = n.peek();
436
+ t && (n.value = {
437
+ ...t,
438
+ to: s.current(e.clientX, e.clientY)
439
+ });
440
+ }, o = (e) => {
441
+ let t = n.peek();
442
+ if (window.removeEventListener("pointermove", a), window.removeEventListener("pointerup", o), n.value = null, !t) return;
443
+ let s = e.target, c = s instanceof Element ? s.closest(te) : null, l = c?.closest("[data-node-id]");
444
+ if (!l) return;
445
+ let u = {
446
+ source: t.source,
447
+ target: l.getAttribute("data-node-id") ?? "",
448
+ sourceHandle: t.sourceHandle,
449
+ targetHandle: c?.getAttribute("data-handle-id") ?? void 0
450
+ };
451
+ !u.target || u.source === u.target || i.current && !i.current(u) || r.current?.(u);
452
+ }, l = (e) => {
453
+ let t = e.target;
454
+ if (!(t instanceof Element)) return;
455
+ let r = t.closest(ee);
456
+ if (!r) return;
457
+ let i = r.closest("[data-node-id]");
458
+ if (!i) return;
459
+ e.stopPropagation();
460
+ let c = r.getBoundingClientRect();
461
+ n.value = {
462
+ source: i.getAttribute("data-node-id") ?? "",
463
+ sourceHandle: r.getAttribute("data-handle-id") ?? void 0,
464
+ from: s.current(c.left + c.width / 2, c.top + c.height / 2),
465
+ to: s.current(e.clientX, e.clientY)
466
+ }, window.addEventListener("pointermove", a), window.addEventListener("pointerup", o);
467
+ };
468
+ return e.addEventListener("pointerdown", l), () => {
469
+ e.removeEventListener("pointerdown", l), window.removeEventListener("pointermove", a), window.removeEventListener("pointerup", o);
470
+ };
471
+ }), { connection: n };
472
+ }
473
+ //#endregion
474
+ //#region src/core/use-story.ts
475
+ var ne = 1500;
476
+ function re(e) {
477
+ let { steps: r, loop: i = !0, stepDuration: a = ne, stepGap: s = 0 } = e, [c, u] = n({
478
+ value: e.currentStep,
479
+ defaultValue: e.defaultCurrentStep ?? 0,
480
+ onChange: e.onStepChange
481
+ }), [d, f] = n({
482
+ value: e.playing,
483
+ defaultValue: e.defaultPlaying ?? !0,
484
+ onChange: e.onPlayingChange
485
+ }), p = t(() => r[c.value] ?? null), m = l(e.clock);
486
+ m.current = e.clock;
487
+ let h = l(r);
488
+ h.current = r;
489
+ let g = () => m.current ?? {
490
+ setTimeout: (e, t) => window.setTimeout(e, t),
491
+ clearTimeout: (e) => window.clearTimeout(e)
492
+ }, _ = (e) => {
493
+ let t = h.current.length;
494
+ if (t === 0) return;
495
+ let n = c.peek() + e;
496
+ u(i ? (n % t + t) % t : Math.max(0, Math.min(t - 1, n)));
497
+ };
498
+ return o(() => {
499
+ if (!d.value) return;
500
+ let e = c.value, t = r.length;
501
+ if (t === 0 || typeof window > "u" && !m.current) return;
502
+ let n = (r[e]?.duration ?? a) + s, o = g(), l = o.setTimeout(() => {
503
+ let n = e + 1;
504
+ n >= t ? i ? u(0) : f(!1) : u(n);
505
+ }, n);
506
+ return () => o.clearTimeout(l);
507
+ }), {
508
+ currentStep: c,
509
+ playing: d,
510
+ activeStep: p,
511
+ play: () => f(!0),
512
+ pause: () => f(!1),
513
+ toggle: () => f(!d.peek()),
514
+ next: () => _(1),
515
+ prev: () => _(-1),
516
+ restart: () => {
517
+ u(0), f(!0);
518
+ }
519
+ };
520
+ }
521
+ var G = {
522
+ canvas: "_canvas_6fiig_2",
523
+ pane: "_pane_6fiig_13",
524
+ panSurface: "_panSurface_6fiig_24"
525
+ };
526
+ //#endregion
527
+ //#region src/core/flow-canvas/flow-canvas.tsx
528
+ function ie({ children: t, flow: n, viewport: r, defaultViewport: i, onViewportChange: a, minZoom: o, maxZoom: c, panOnDrag: l = !0, zoomOnScroll: u = !0, fitView: p = !1, controller: m, chrome: h, className: g, role: v = "application", ...y }) {
529
+ s();
530
+ let b = _({
531
+ viewport: r,
532
+ defaultViewport: i,
533
+ onViewportChange: a
534
+ }), x = n ?? b, S = U(x, {
535
+ minZoom: o,
536
+ maxZoom: c,
537
+ panOnDrag: l,
538
+ zoomOnScroll: u,
539
+ fitOnInit: p
540
+ }), C = m ?? S, w = x.viewport.value;
541
+ return /* @__PURE__ */ f("div", {
542
+ ref: C.containerRef,
543
+ className: e(G.canvas, g),
544
+ role: v,
545
+ ...y,
546
+ children: [/* @__PURE__ */ f("div", {
547
+ className: G.pane,
548
+ style: {
549
+ "--flow-tx": `${w.x}px`,
550
+ "--flow-ty": `${w.y}px`,
551
+ "--flow-scale": String(w.zoom)
552
+ },
553
+ children: [/* @__PURE__ */ d("div", {
554
+ ref: C.panHandleRef,
555
+ className: G.panSurface,
556
+ "aria-hidden": "true"
557
+ }), t]
558
+ }), h]
559
+ });
560
+ }
561
+ var ae = { background: "_background_1pu9x_2" };
562
+ //#endregion
563
+ //#region src/flows/flow-background/flow-background.tsx
564
+ function oe({ variant: t = "dots", gap: n = 20, size: r = 1, color: i, className: a, style: o, ...s }) {
565
+ return /* @__PURE__ */ d("div", {
566
+ "data-variant": t,
567
+ "aria-hidden": "true",
568
+ className: e(ae.background, a),
569
+ style: {
570
+ "--flow-bg-gap": `${n}px`,
571
+ "--flow-bg-size": `${r}px`,
572
+ "--flow-bg-thick": `${Math.max(1, r)}px`,
573
+ ...i ? { "--flow-bg-color": i } : {},
574
+ ...o
575
+ },
576
+ ...s
577
+ });
578
+ }
579
+ var se = { node: "_node_9zyg4_2" };
580
+ //#endregion
581
+ //#region src/flows/flow-node/flow-node.tsx
582
+ function ce({ id: t, position: i, defaultPosition: a, onPositionChange: c, onMeasure: u, zoom: f = 1, selected: p = !1, draggable: m = !0, interactive: h = !0, onSelect: g, children: _, className: v, onClick: y, onKeyDown: b, ...x }) {
583
+ s();
584
+ let S = m && h, [C, w] = n({
585
+ value: i,
586
+ defaultValue: a ?? i ?? {
587
+ x: 0,
588
+ y: 0
589
+ },
590
+ onChange: c
591
+ }), { handleRef: T, targetRef: E, offset: D, isDragging: O } = r({ isDisabled: !S }), k = l(null), A = (e) => {
592
+ k.current = e, T.current = e, E.current = e;
593
+ }, j = l(u);
594
+ j.current = u, o(() => {
595
+ let e = k.current;
596
+ if (!e || typeof ResizeObserver > "u") return;
597
+ let t = () => {
598
+ let t = e.offsetWidth, n = e.offsetHeight;
599
+ t > 0 && n > 0 && j.current?.({
600
+ width: t,
601
+ height: n
602
+ });
603
+ };
604
+ t();
605
+ let n = new ResizeObserver(t);
606
+ return n.observe(e), () => n.disconnect();
607
+ });
608
+ let M = l(f);
609
+ M.current = f;
610
+ let N = l(null);
611
+ o(() => {
612
+ let e = O.value, t = D.value;
613
+ if (!S) return;
614
+ if (!e) {
615
+ N.current = null;
616
+ return;
617
+ }
618
+ N.current ||= {
619
+ pos: C.peek(),
620
+ off: t
621
+ };
622
+ let n = N.current, r = M.current || 1;
623
+ w({
624
+ x: n.pos.x + (t.x - n.off.x) / r,
625
+ y: n.pos.y + (t.y - n.off.y) / r
626
+ });
627
+ });
628
+ let P = C.value;
629
+ return /* @__PURE__ */ d("div", {
630
+ ref: A,
631
+ "data-node-id": t,
632
+ "data-selected": p || void 0,
633
+ "data-dragging": O.value || void 0,
634
+ "data-static": !h || void 0,
635
+ role: "group",
636
+ tabIndex: h ? 0 : void 0,
637
+ className: e(se.node, v),
638
+ style: {
639
+ "--flow-x": `${P.x}px`,
640
+ "--flow-y": `${P.y}px`
641
+ },
642
+ onClick: (e) => {
643
+ h && g?.(t), y?.(e);
644
+ },
645
+ onKeyDown: (e) => {
646
+ h && (e.key === "Enter" || e.key === " ") && (e.preventDefault(), g?.(t)), b?.(e);
647
+ },
648
+ ...x,
649
+ children: _
650
+ });
651
+ }
652
+ var le = {
653
+ handle: "_handle_8a1xa_2",
654
+ dot: "_dot_8a1xa_41"
655
+ };
656
+ //#endregion
657
+ //#region src/flows/flow-handle/flow-handle.tsx
658
+ function ue(e) {
659
+ return e === "source" ? "right" : "left";
660
+ }
661
+ function K({ type: t, position: n, id: r, isConnectable: i = !0, className: a, ...o }) {
662
+ return /* @__PURE__ */ d("div", {
663
+ "data-handle-type": t,
664
+ "data-handle-pos": n ?? ue(t),
665
+ "data-handle-id": r,
666
+ "data-connectable": i || void 0,
667
+ "data-flow-handle": "",
668
+ tabIndex: i ? 0 : -1,
669
+ className: e(le.handle, a),
670
+ ...o,
671
+ children: /* @__PURE__ */ d("span", {
672
+ className: le.dot,
673
+ "aria-hidden": "true"
674
+ })
675
+ });
676
+ }
677
+ var q = {
678
+ edgeSvg: "_edgeSvg_789n0_2",
679
+ edgePath: "_edgePath_789n0_11",
680
+ hit: "_hit_789n0_18",
681
+ arrow: "_arrow_789n0_26",
682
+ "cascivo-flow-dash": "_cascivo-flow-dash_789n0_1",
683
+ label: "_label_789n0_64"
684
+ };
685
+ //#endregion
686
+ //#region src/flows/flow-edge/flow-edge.tsx
687
+ function J({ id: t, sourceX: n, sourceY: r, targetX: i, targetY: a, sourcePosition: o = "right", targetPosition: s = "left", type: l = "bezier", animated: p = !1, label: m, selected: h = !1, markerStart: g = !1, markerEnd: _ = !0, direction: v = "forward", active: y, className: b }) {
688
+ let x = c(), S = `flow-arrow-${t ?? x}`, C = g || _, { d: w, mid: T } = F(l, {
689
+ source: {
690
+ x: n,
691
+ y: r
692
+ },
693
+ target: {
694
+ x: i,
695
+ y: a
696
+ },
697
+ sourcePosition: o,
698
+ targetPosition: s
699
+ });
700
+ return /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ f("svg", {
701
+ className: e(q.edgeSvg, b),
702
+ "data-edge-id": t,
703
+ "data-animated": p || void 0,
704
+ "data-selected": h || void 0,
705
+ "data-active": y || void 0,
706
+ "data-direction": v,
707
+ "aria-hidden": "true",
708
+ children: [
709
+ C && /* @__PURE__ */ d("defs", { children: /* @__PURE__ */ d("marker", {
710
+ id: S,
711
+ viewBox: "0 0 10 10",
712
+ refX: "9",
713
+ refY: "5",
714
+ markerWidth: "7",
715
+ markerHeight: "7",
716
+ orient: "auto-start-reverse",
717
+ children: /* @__PURE__ */ d("path", {
718
+ className: q.arrow,
719
+ d: "M0,0 L10,5 L0,10 z"
720
+ })
721
+ }) }),
722
+ /* @__PURE__ */ d("path", {
723
+ className: q.hit,
724
+ d: w
725
+ }),
726
+ /* @__PURE__ */ d("path", {
727
+ className: q.edgePath,
728
+ d: w,
729
+ markerStart: g ? `url(#${S})` : void 0,
730
+ markerEnd: _ ? `url(#${S})` : void 0
731
+ })
732
+ ]
733
+ }), m != null && /* @__PURE__ */ d("div", {
734
+ className: q.label,
735
+ style: {
736
+ "--flow-label-x": `${T.x}px`,
737
+ "--flow-label-y": `${T.y}px`
738
+ },
739
+ children: m
740
+ })] });
741
+ }
742
+ var Y = {
743
+ controls: "_controls_c0e5r_2",
744
+ button: "_button_c0e5r_32"
745
+ }, X = {
746
+ width: 18,
747
+ height: 18,
748
+ viewBox: "0 0 24 24",
749
+ fill: "none",
750
+ "aria-hidden": !0
751
+ };
752
+ function de({ position: t = "bottom-left", showZoom: n = !0, showFitView: r = !0, onZoomIn: i, onZoomOut: a, onFitView: o, labels: c, className: l, ...h }) {
753
+ return s(), /* @__PURE__ */ f("div", {
754
+ "data-position": t,
755
+ className: e(Y.controls, l),
756
+ ...h,
757
+ children: [n && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("button", {
758
+ type: "button",
759
+ className: Y.button,
760
+ "aria-label": c?.zoomIn ?? m(p.flow.zoomIn),
761
+ onClick: i,
762
+ children: /* @__PURE__ */ d("svg", {
763
+ ...X,
764
+ children: /* @__PURE__ */ d("path", {
765
+ d: "M12 5v14M5 12h14",
766
+ stroke: "currentColor",
767
+ strokeWidth: "2",
768
+ strokeLinecap: "round"
769
+ })
770
+ })
771
+ }), /* @__PURE__ */ d("button", {
772
+ type: "button",
773
+ className: Y.button,
774
+ "aria-label": c?.zoomOut ?? m(p.flow.zoomOut),
775
+ onClick: a,
776
+ children: /* @__PURE__ */ d("svg", {
777
+ ...X,
778
+ children: /* @__PURE__ */ d("path", {
779
+ d: "M5 12h14",
780
+ stroke: "currentColor",
781
+ strokeWidth: "2",
782
+ strokeLinecap: "round"
783
+ })
784
+ })
785
+ })] }), r && /* @__PURE__ */ d("button", {
786
+ type: "button",
787
+ className: Y.button,
788
+ "aria-label": c?.fitView ?? m(p.flow.fitView),
789
+ onClick: o,
790
+ children: /* @__PURE__ */ d("svg", {
791
+ ...X,
792
+ children: /* @__PURE__ */ d("path", {
793
+ 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",
794
+ stroke: "currentColor",
795
+ strokeWidth: "2",
796
+ strokeLinecap: "round",
797
+ strokeLinejoin: "round"
798
+ })
799
+ })
800
+ })]
801
+ });
802
+ }
803
+ var Z = {
804
+ minimap: "_minimap_rdahv_2",
805
+ node: "_node_rdahv_28",
806
+ viewport: "_viewport_rdahv_32"
807
+ };
808
+ //#endregion
809
+ //#region src/flows/flow-minimap/flow-minimap.tsx
810
+ function fe({ nodes: t, viewport: n, containerWidth: i, containerHeight: a, width: c = 200, height: u = 150, position: h = "bottom-right", nodeColor: g, onViewportChange: _, label: v, className: b }) {
811
+ s();
812
+ let x = w(t) ?? {
813
+ x: 0,
814
+ y: 0,
815
+ width: 1,
816
+ height: 1
817
+ }, C = x.width || 1, T = x.height || 1, E = C * .1, D = T * .1, O = {
818
+ x: x.x - E,
819
+ y: x.y - D,
820
+ width: C + E * 2,
821
+ height: T + D * 2
822
+ }, k = Math.min(c / O.width, u / O.height), A = -O.x * k + (c - O.width * k) / 2, j = -O.y * k + (u - O.height * k) / 2, M = (e) => ({
823
+ x: e.x * k + A,
824
+ y: e.y * k + j
825
+ }), N = null;
826
+ if (i && a) {
827
+ let e = y({
828
+ x: 0,
829
+ y: 0
830
+ }, n), t = y({
831
+ x: i,
832
+ y: a
833
+ }, n), r = M(e);
834
+ N = {
835
+ x: r.x,
836
+ y: r.y,
837
+ w: (t.x - e.x) * k,
838
+ h: (t.y - e.y) * k
839
+ };
840
+ }
841
+ let { handleRef: P, offset: F, isDragging: I } = r({ isDisabled: !_ }), L = l(null), R = (e) => {
842
+ L.current = e, P.current = e;
843
+ }, z = l(_);
844
+ z.current = _;
845
+ let B = l(null);
846
+ return o(() => {
847
+ let e = I.value, t = F.value;
848
+ if (!z.current) return;
849
+ if (!e) {
850
+ B.current = null;
851
+ return;
852
+ }
853
+ B.current ||= {
854
+ vp: n,
855
+ off: t
856
+ };
857
+ let r = B.current, i = r.vp.zoom;
858
+ z.current({
859
+ x: r.vp.x - (t.x - r.off.x) / k * i,
860
+ y: r.vp.y - (t.y - r.off.y) / k * i,
861
+ zoom: i
862
+ });
863
+ }), /* @__PURE__ */ f("svg", {
864
+ "data-position": h,
865
+ className: e(Z.minimap, b),
866
+ width: c,
867
+ height: u,
868
+ role: "img",
869
+ "aria-label": v ?? m(p.flow.minimap),
870
+ children: [t.map((e) => {
871
+ let t = S(e), n = M({
872
+ x: t.x,
873
+ y: t.y
874
+ });
875
+ return /* @__PURE__ */ d("rect", {
876
+ "data-node-id": e.id,
877
+ className: Z.node,
878
+ x: n.x,
879
+ y: n.y,
880
+ width: t.width * k,
881
+ height: t.height * k,
882
+ fill: g
883
+ }, e.id);
884
+ }), N && /* @__PURE__ */ d("rect", {
885
+ ref: R,
886
+ "data-viewport": "",
887
+ className: Z.viewport,
888
+ x: N.x,
889
+ y: N.y,
890
+ width: N.w,
891
+ height: N.h
892
+ })]
893
+ });
894
+ }
895
+ var pe = { panel: "_panel_l0cix_2" };
896
+ //#endregion
897
+ //#region src/flows/flow-panel/flow-panel.tsx
898
+ function me({ position: t = "top-right", children: n, className: r, ...i }) {
899
+ return /* @__PURE__ */ d("div", {
900
+ "data-position": t,
901
+ className: e(pe.panel, r),
902
+ ...i,
903
+ children: n
904
+ });
905
+ }
906
+ var he = { flow: "_flow_vejge_2" }, ge = 0;
907
+ function _e({ nodes: t, edges: n, onNodesChange: r, onEdgesChange: i, onConnect: o, nodeTypes: c, fitView: l = !0, background: p = !1, controls: m = !1, minimap: h = !1, layout: g, minZoom: v, maxZoom: b, interactive: x = !0, activeEdgeId: S, activeDirection: w, className: T, style: E }) {
908
+ s();
909
+ let D = _({
910
+ defaultNodes: g ? R(t, n, g) : t,
911
+ defaultEdges: n,
912
+ onNodesChange: r,
913
+ onEdgesChange: i
914
+ }), O = U(D, {
915
+ minZoom: v,
916
+ maxZoom: b,
917
+ fitOnInit: l
918
+ }), { connection: k } = W({
919
+ containerRef: O.containerRef,
920
+ clientToFlow: (e, t) => {
921
+ let n = O.containerRef.current?.getBoundingClientRect();
922
+ return y({
923
+ x: e - (n?.left ?? 0),
924
+ y: t - (n?.top ?? 0)
925
+ }, D.viewport.peek());
926
+ },
927
+ enabled: x,
928
+ onConnect: (e) => {
929
+ D.addEdge({
930
+ id: `e-${++ge}`,
931
+ source: e.source,
932
+ target: e.target
933
+ }), o?.(e);
934
+ }
935
+ }), A = (e) => {
936
+ D.setNodes(D.nodes.value.map((t) => ({
937
+ ...t,
938
+ selected: t.id === e
939
+ })));
940
+ }, j = a({}), M = (e, t) => {
941
+ let n = j.peek()[e];
942
+ n && n.width === t.width && n.height === t.height || (j.value = {
943
+ ...j.peek(),
944
+ [e]: t
945
+ });
946
+ }, N = D.nodes.value, P = D.edges.value, F = D.viewport.value.zoom, I = j.value, L = new Map(N.map((e) => {
947
+ let t = I[e.id];
948
+ return [e.id, t ? {
949
+ ...e,
950
+ width: t.width,
951
+ height: t.height
952
+ } : e];
953
+ })), z = k.value;
954
+ return /* @__PURE__ */ f(ie, {
955
+ flow: D,
956
+ controller: O,
957
+ minZoom: v,
958
+ maxZoom: b,
959
+ chrome: /* @__PURE__ */ f(u, { children: [m && /* @__PURE__ */ d(de, {
960
+ onZoomIn: O.zoomIn,
961
+ onZoomOut: O.zoomOut,
962
+ onFitView: () => O.fitView()
963
+ }), h && /* @__PURE__ */ d(fe, {
964
+ nodes: N,
965
+ viewport: D.viewport.value,
966
+ containerWidth: O.containerRef.current?.clientWidth,
967
+ containerHeight: O.containerRef.current?.clientHeight,
968
+ onViewportChange: D.setViewport
969
+ })] }),
970
+ className: e(he.flow, T),
971
+ style: E,
972
+ children: [
973
+ p && /* @__PURE__ */ d(oe, { ...typeof p == "object" ? p : {} }),
974
+ P.map((e) => {
975
+ let t = L.get(e.source), n = L.get(e.target);
976
+ if (!t || !n) return null;
977
+ let r = C(t, "right"), i = C(n, "left"), a = S === e.id, o = a ? w : void 0, s = o === "reverse" ? !0 : o === "forward" ? !1 : e.markerStart ?? !1, c = o === "reverse" ? !1 : o === "forward" ? !0 : e.markerEnd ?? !0;
978
+ return /* @__PURE__ */ d(J, {
979
+ id: e.id,
980
+ sourceX: r.x,
981
+ sourceY: r.y,
982
+ targetX: i.x,
983
+ targetY: i.y,
984
+ type: e.type ?? "bezier",
985
+ animated: e.animated || a,
986
+ active: a,
987
+ direction: o,
988
+ markerStart: s,
989
+ markerEnd: c,
990
+ label: e.label,
991
+ selected: e.selected
992
+ }, e.id);
993
+ }),
994
+ z && /* @__PURE__ */ d(J, {
995
+ sourceX: z.from.x,
996
+ sourceY: z.from.y,
997
+ targetX: z.to.x,
998
+ targetY: z.to.y,
999
+ markerEnd: !1
1000
+ }),
1001
+ N.map((e) => /* @__PURE__ */ d(ce, {
1002
+ id: e.id,
1003
+ position: e.position,
1004
+ zoom: F,
1005
+ interactive: x,
1006
+ selected: e.selected ?? !1,
1007
+ onSelect: x ? A : void 0,
1008
+ onMeasure: (t) => M(e.id, t),
1009
+ onPositionChange: (t) => D.updateNode(e.id, { position: t }),
1010
+ children: c && e.type && c[e.type] ? c[e.type]({ node: e }) : /* @__PURE__ */ f(u, { children: [
1011
+ /* @__PURE__ */ d("span", { children: String(e.data?.label ?? e.id) }),
1012
+ x && /* @__PURE__ */ d(K, {
1013
+ type: "target",
1014
+ position: "left"
1015
+ }),
1016
+ x && /* @__PURE__ */ d(K, {
1017
+ type: "source",
1018
+ position: "right"
1019
+ })
1020
+ ] })
1021
+ }, e.id))
1022
+ ]
1023
+ });
1024
+ }
1025
+ var Q = {
1026
+ story: "_story_7qja0_2",
1027
+ overlay: "_overlay_7qja0_7",
1028
+ caption: "_caption_7qja0_20",
1029
+ captionText: "_captionText_7qja0_36",
1030
+ captionDesc: "_captionDesc_7qja0_48",
1031
+ controls: "_controls_7qja0_52",
1032
+ button: "_button_7qja0_64",
1033
+ indicator: "_indicator_7qja0_93"
1034
+ }, $ = {
1035
+ width: 18,
1036
+ height: 18,
1037
+ viewBox: "0 0 24 24",
1038
+ fill: "currentColor",
1039
+ "aria-hidden": !0
1040
+ };
1041
+ function ve({ nodes: t, edges: n, script: r, loop: i = !0, stepDuration: a = 1500, stepGap: o = 0, playing: c, currentStep: l, onStepChange: u, controls: h = !0, autoPlay: g = !0, background: _ = !0, interactive: v = !1, labels: y, clock: b, className: x, style: S }) {
1042
+ s();
1043
+ let C = V(r, n), w = re({
1044
+ steps: C,
1045
+ loop: i,
1046
+ stepDuration: a,
1047
+ stepGap: o,
1048
+ playing: c,
1049
+ defaultPlaying: g,
1050
+ currentStep: l,
1051
+ defaultCurrentStep: 0,
1052
+ onStepChange: u,
1053
+ clock: b
1054
+ }), T = w.activeStep.value, E = w.currentStep.value, D = w.playing.value;
1055
+ return /* @__PURE__ */ f("div", {
1056
+ className: e(Q.story, x),
1057
+ style: S,
1058
+ children: [/* @__PURE__ */ d(_e, {
1059
+ nodes: t,
1060
+ edges: n,
1061
+ background: _,
1062
+ interactive: v,
1063
+ activeEdgeId: T?.edgeId,
1064
+ activeDirection: T?.direction
1065
+ }), /* @__PURE__ */ f("div", {
1066
+ className: Q.overlay,
1067
+ children: [/* @__PURE__ */ d("div", {
1068
+ className: Q.caption,
1069
+ "aria-live": "polite",
1070
+ children: T?.label && /* @__PURE__ */ f("span", {
1071
+ className: Q.captionText,
1072
+ children: [/* @__PURE__ */ d("strong", { children: T.label }), T.description && /* @__PURE__ */ f("span", {
1073
+ className: Q.captionDesc,
1074
+ children: [" — ", T.description]
1075
+ })]
1076
+ }, E)
1077
+ }), h && /* @__PURE__ */ f("div", {
1078
+ className: Q.controls,
1079
+ children: [
1080
+ /* @__PURE__ */ d("button", {
1081
+ type: "button",
1082
+ className: Q.button,
1083
+ "aria-label": y?.previous ?? m(p.flow.previous),
1084
+ onClick: w.prev,
1085
+ children: /* @__PURE__ */ d("svg", {
1086
+ ...$,
1087
+ children: /* @__PURE__ */ d("path", {
1088
+ d: "M15 6 9 12l6 6",
1089
+ stroke: "currentColor",
1090
+ strokeWidth: "2",
1091
+ fill: "none"
1092
+ })
1093
+ })
1094
+ }),
1095
+ /* @__PURE__ */ d("button", {
1096
+ type: "button",
1097
+ className: Q.button,
1098
+ "aria-label": D ? y?.pause ?? m(p.flow.pause) : y?.play ?? m(p.flow.play),
1099
+ "aria-pressed": D,
1100
+ onClick: w.toggle,
1101
+ children: D ? /* @__PURE__ */ d("svg", {
1102
+ ...$,
1103
+ children: /* @__PURE__ */ d("path", { d: "M7 5h3v14H7zM14 5h3v14h-3z" })
1104
+ }) : /* @__PURE__ */ d("svg", {
1105
+ ...$,
1106
+ children: /* @__PURE__ */ d("path", { d: "M7 5l11 7-11 7z" })
1107
+ })
1108
+ }),
1109
+ /* @__PURE__ */ d("button", {
1110
+ type: "button",
1111
+ className: Q.button,
1112
+ "aria-label": y?.next ?? m(p.flow.next),
1113
+ onClick: w.next,
1114
+ children: /* @__PURE__ */ d("svg", {
1115
+ ...$,
1116
+ children: /* @__PURE__ */ d("path", {
1117
+ d: "M9 6l6 6-6 6",
1118
+ stroke: "currentColor",
1119
+ strokeWidth: "2",
1120
+ fill: "none"
1121
+ })
1122
+ })
1123
+ }),
1124
+ /* @__PURE__ */ d("span", {
1125
+ className: Q.indicator,
1126
+ children: m(p.flow.step, {
1127
+ current: E + 1,
1128
+ total: C.length
1129
+ })
1130
+ })
1131
+ ]
1132
+ })]
1133
+ })]
1134
+ });
1135
+ }
1136
+ //#endregion
1137
+ export { h as DEFAULT_NODE_SIZE, _e as Flow, oe as FlowBackground, ie as FlowCanvas, de as FlowControls, J as FlowEdge, K as FlowHandle, fe as FlowMiniMap, ce as FlowNode, me as FlowPanel, ve as FlowStory, R as applyLayout, A as bezierPath, v as clampZoom, F as edgePath, T as fitViewport, b as flowToScreen, w as graphBounds, I as gridLayout, C as handleAnchor, L as layeredLayout, S as nodeBounds, x as nodeSize, V as resolveScript, B as resolveStep, y as screenToFlow, P as smoothStepPath, k as straightPath, W as useConnection, _ as useFlow, re as useStory, U as useViewport };