@cascivo/flow 0.1.18 → 0.16.0

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