@cascivo/flow 1.0.0 → 1.1.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.
@@ -1,1138 +1 @@
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 V(e) {
288
- return "edge" in e;
289
- }
290
- function ee(e, t) {
291
- let n = {
292
- label: e.label,
293
- description: e.description,
294
- duration: e.duration
295
- };
296
- if (V(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 te(e, t) {
320
- return e.map((e) => ee(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 ie(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 ae = 1500;
477
- function oe(e) {
478
- let { steps: r, loop: i = !0, stepDuration: a = ae, 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 W = {
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 se({ 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(W.canvas, g),
545
- role: _,
546
- ...v,
547
- children: [/* @__PURE__ */ p("div", {
548
- className: W.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: W.panSurface,
557
- "aria-hidden": "true"
558
- }), t]
559
- }), h]
560
- });
561
- }
562
- var ce = { background: "_background_1pu9x_2" };
563
- //#endregion
564
- //#region src/flows/flow-background/flow-background.tsx
565
- function le({ 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(ce.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 ue = { node: "_node_9zyg4_2" };
581
- //#endregion
582
- //#region src/flows/flow-node/flow-node.tsx
583
- function de({ 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(ue.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 G = {
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(G.handle, i),
671
- ...a,
672
- children: /* @__PURE__ */ f("span", {
673
- className: G.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, ariaLabel: y, className: b }) {
812
- c();
813
- let S = E(t) ?? {
814
- x: 0,
815
- y: 0,
816
- width: 1,
817
- height: 1
818
- }, C = S.width || 1, T = S.height || 1, D = C * .1, O = T * .1, k = {
819
- x: S.x - D,
820
- y: S.y - O,
821
- width: C + D * 2,
822
- height: T + O * 2
823
- }, A = Math.min(o / k.width, l / k.height), j = -k.x * A + (o - k.width * A) / 2, M = -k.y * A + (l - k.height * A) / 2, N = (e) => ({
824
- x: e.x * A + j,
825
- y: e.y * A + M
826
- }), P = 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 = N(e);
835
- P = {
836
- x: r.x,
837
- y: r.y,
838
- w: (t.x - e.x) * A,
839
- h: (t.y - e.y) * A
840
- };
841
- }
842
- let { handleRef: F, offset: I, isDragging: L } = r({ isDisabled: !_ }), R = u(null), z = (e) => {
843
- R.current = e, F.current = e;
844
- }, B = u(_);
845
- B.current = _;
846
- let V = u(null);
847
- return s(() => {
848
- let e = L.value, t = I.value;
849
- if (!B.current) return;
850
- if (!e) {
851
- V.current = null;
852
- return;
853
- }
854
- V.current ||= {
855
- vp: n,
856
- off: t
857
- };
858
- let r = V.current, i = r.vp.zoom;
859
- B.current({
860
- x: r.vp.x - (t.x - r.off.x) / A * i,
861
- y: r.vp.y - (t.y - r.off.y) / A * i,
862
- zoom: i
863
- });
864
- }), /* @__PURE__ */ p("svg", {
865
- "data-position": d,
866
- className: e(Z.minimap, b),
867
- width: o,
868
- height: l,
869
- role: "img",
870
- "aria-label": y ?? v ?? g(h.flow.minimap),
871
- children: [t.map((e) => {
872
- let t = w(e), n = N({
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 * A,
882
- height: t.height * A,
883
- fill: m
884
- }, e.id);
885
- }), P && /* @__PURE__ */ f("rect", {
886
- ref: z,
887
- "data-viewport": "",
888
- className: Z.viewport,
889
- x: P.x,
890
- y: P.y,
891
- width: P.w,
892
- height: P.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 } = ie({
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(se, {
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(le, { ...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(de, {
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 = te(r, n), w = oe({
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, le as FlowBackground, se as FlowCanvas, pe as FlowControls, J as FlowEdge, K as FlowHandle, me as FlowMiniMap, de 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, te as resolveScript, ee as resolveStep, x as screenToFlow, I as smoothStepPath, j as straightPath, ie as useConnection, y as useFlow, oe as useStory, U as useViewport };
1
+ "use client";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";import{useId as l,useRef as u}from"react";import{Fragment as d,jsx as f,jsxs as p}from"react/jsx-runtime";import{cn as m}from"@cascivo/core/pure";import{builtin as h,t as g}from"@cascivo/i18n";var _={width:150,height:40},v={x:0,y:0,zoom:1};function y(e={}){let[t,r]=n({value:e.nodes,defaultValue:e.defaultNodes??[],onChange:e.onNodesChange}),[i,a]=n({value:e.edges,defaultValue:e.defaultEdges??[],onChange:e.onEdgesChange}),[o,s]=n({value:e.viewport,defaultValue:e.defaultViewport??v,onChange:e.onViewportChange});return{nodes:t,edges:i,viewport:o,setNodes:r,updateNode:(e,n)=>{r(t.value.map(t=>t.id===e?{...t,...n}:t))},setEdges:a,addEdge:e=>{a([...i.value,e])},setViewport:s}}function b(e,t=.2,n=2){return Math.min(n,Math.max(t,e))}function x(e,t){return{x:(e.x-t.x)/t.zoom,y:(e.y-t.y)/t.zoom}}function S(e,t){return{x:e.x*t.zoom+t.x,y:e.y*t.zoom+t.y}}function C(e){return{width:e.width??_.width,height:e.height??_.height}}function w(e){let{width:t,height:n}=C(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}function T(e,t){let{x:n,y:r,width:i,height:a}=w(e);switch(t){case`top`:return{x:n+i/2,y:r};case`right`:return{x:n+i,y:r+a/2};case`bottom`:return{x:n+i/2,y:r+a};case`left`:return{x:n,y:r+a/2}}}function E(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e){let e=w(a);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)}return{x:t,y:n,width:r-t,height:i-n}}function D(e,t,n={}){let{padding:r=.1,minZoom:i=.2,maxZoom:a=2}=n;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 o=t.width/(e.width*(1+r*2)),s=t.height/(e.height*(1+r*2)),c=b(Math.min(o,s),i,a);return{x:t.width/2-(e.x+e.width/2)*c,y:t.height/2-(e.y+e.height/2)*c,zoom:c}}var O=e=>Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,``),k=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});function A(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 j({source:e,target:t}){return{d:`M${O(e.x)},${O(e.y)} L${O(t.x)},${O(t.y)}`,mid:k(e,t)}}function M(e){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={x:t.x+c.x*s,y:t.y+c.y*s},d={x:n.x+l.x*s,y:n.y+l.y*s},f={x:(t.x+3*u.x+3*d.x+n.x)/8,y:(t.y+3*u.y+3*d.y+n.y)/8};return{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)}`,mid:f}}function N(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function P(e,t,n){let r=N(e,t)||1;return{x:e.x+(t.x-e.x)/r*n,y:e.y+(t.y-e.y)/r*n}}function F(e,t){if(e.length<2)return``;let n=e[0],r=`M${O(n.x)},${O(n.y)}`;for(let n=1;n<e.length-1;n++){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);r+=` L${O(c.x)},${O(c.y)} Q${O(a.x)},${O(a.y)} ${O(l.x)},${O(l.y)}`}let i=e[e.length-1];return r+=` L${O(i.x)},${O(i.y)}`,r}function I(e){let{source:t,target:n,borderRadius:r=8}=e,i=e.sourcePosition??`right`,a=i===`left`||i===`right`,o=[t];if(a){let e=(t.x+n.x)/2;o.push({x:e,y:t.y},{x:e,y:n.y})}else{let e=(t.y+n.y)/2;o.push({x:t.x,y:e},{x:n.x,y:e})}return o.push(n),{d:F(o,r),mid:k(t,n)}}function L(e,t){switch(e){case`straight`:return j(t);case`smoothstep`:return I(t);case`bezier`:return M(t)}}function R(e,t={}){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)));return e.map((e,t)=>{let o=t%a,s=Math.floor(t/a);return{...e,position:{x:o*(r+n),y:s*(i+n)}}})}function z(e,t,n={}){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=new Map,l=new Map;for(let t of e)l.set(t.id,0);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));let u=new Map,d=e.filter(e=>(l.get(e.id)??0)===0).map(e=>e.id);for(let e of d)u.set(e,0);let f=new Map(l);for(;d.length>0;){let e=[];for(let t of d){let n=u.get(t)??0;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)}d=e}for(let t of e)u.has(t.id)||u.set(t.id,0);let p=new Map,m=new Map;for(let t of e){let e=u.get(t.id)??0,n=m.get(e)??0;p.set(t.id,n),m.set(e,n+1)}return e.map(e=>{let t=u.get(e.id)??0,n=p.get(e.id)??0,s=r===`LR`?{x:t*(a+i),y:n*(o+i)}:{x:n*(a+i),y:t*(o+i)};return{...e,position:s}})}function B(e,t,n){return n===`grid`?R(e):n===`layered`?z(e,t):n(e,t)}function V(e){return`edge`in e}function ee(e,t){let n={label:e.label,description:e.description,duration:e.duration};if(V(e)){let r=t.find(t=>t.id===e.edge);if(!r)throw Error(`FlowStory: step references unknown edge "${e.edge}"`);return{edgeId:r.id,direction:e.reverse?`reverse`:`forward`,...n}}let r=t.find(t=>t.source===e.from&&t.target===e.to);if(r)return{edgeId:r.id,direction:`forward`,...n};let i=t.find(t=>t.source===e.to&&t.target===e.from);if(i)return{edgeId:i.id,direction:`reverse`,...n};throw Error(`FlowStory: no edge connects "${e.from}" and "${e.to}"`)}function te(e,t){return e.map(e=>ee(e,t))}var H=1.2;function U(e,t={}){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)=>{let n=f.peek();p({x:n.x+e,y:n.y+t,zoom:n.zoom})},S=(e,t)=>{let r=f.peek(),a=b(e,n,i);if(!t){p({x:r.x,y:r.y,zoom:a});return}let o=x(t,r);p({x:t.x-o.x*a,y:t.y-o.y*a,zoom:a})},C=()=>{let e=m.current;if(e)return{x:e.clientWidth/2,y:e.clientHeight/2}},w=()=>S(f.peek().zoom*H,C()),T=()=>S(f.peek().zoom/H,C()),O=()=>{let e=h.peek();if(e&&e.width>0&&e.height>0)return e;let t=m.current;return t&&t.clientWidth>0?{width:t.clientWidth,height:t.clientHeight}:null},k=t=>{let r=E(e.nodes.peek());if(!r)return;let a=t??O();a&&p(D(r,a,{padding:l,minZoom:n,maxZoom:i}))},A=u(null);s(()=>{let e=v.value,t=_.value;if(!o)return;if(!e){A.current=null;return}A.current||={vp:f.peek(),off:t};let n=A.current;p({x:n.vp.x+(t.x-n.off.x),y:n.vp.y+(t.y-n.off.y),zoom:n.vp.zoom})}),s(()=>{if(!c||typeof window>`u`)return;let e=m.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect(),r={x:t.clientX-n.left,y:t.clientY-n.top},i=t.deltaY<0?H:1/H;S(f.peek().zoom*i,r)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)});let j=u(!1);return s(()=>{if(!d||j.current)return;let e=h.value;!e||e.width===0||(j.current=!0,k(e))}),{containerRef:m,panHandleRef:g,viewport:f,pan:y,zoomTo:S,zoomIn:w,zoomOut:T,fitView:k}}var ne=`[data-flow-handle][data-handle-type="source"]`,re=`[data-flow-handle][data-handle-type="target"]`;function ie(e){let{containerRef:t}=e,n=o(null),r=u(e.onConnect);r.current=e.onConnect;let a=u(e.isValid);a.current=e.isValid;let c=u(e.clientToFlow);c.current=e.clientToFlow;let l=i(e.enabled??!0);return s(()=>{if(!l.value||typeof window>`u`)return;let e=t.current;if(!e)return;let i=e=>{let t=n.peek();t&&(n.value={...t,to:c.current(e.clientX,e.clientY)})},o=e=>{let t=n.peek();if(window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,o),n.value=null,!t)return;let s=e.target,c=s instanceof Element?s.closest(re):null,l=c?.closest(`[data-node-id]`);if(!l)return;let u={source:t.source,target:l.getAttribute(`data-node-id`)??``,sourceHandle:t.sourceHandle,targetHandle:c?.getAttribute(`data-handle-id`)??void 0};!u.target||u.source===u.target||a.current&&!a.current(u)||r.current?.(u)},s=e=>{let t=e.target;if(!(t instanceof Element))return;let r=t.closest(ne);if(!r)return;let a=r.closest(`[data-node-id]`);if(!a)return;e.stopPropagation();let s=r.getBoundingClientRect();n.value={source:a.getAttribute(`data-node-id`)??``,sourceHandle:r.getAttribute(`data-handle-id`)??void 0,from:c.current(s.left+s.width/2,s.top+s.height/2),to:c.current(e.clientX,e.clientY)},window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,o)};return e.addEventListener(`pointerdown`,s),()=>{e.removeEventListener(`pointerdown`,s),window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,o)}}),{connection:n}}var ae=1500;function oe(e){let{steps:r,loop:i=!0,stepDuration:a=ae,stepGap:o=0}=e,[c,l]=n({value:e.currentStep,defaultValue:e.defaultCurrentStep??0,onChange:e.onStepChange}),[d,f]=n({value:e.playing,defaultValue:e.defaultPlaying??!0,onChange:e.onPlayingChange}),p=t(()=>r[c.value]??null),m=u(e.clock);m.current=e.clock;let h=u(r);h.current=r;let g=()=>m.current??{setTimeout:(e,t)=>window.setTimeout(e,t),clearTimeout:e=>window.clearTimeout(e)},_=e=>{let t=h.current.length;if(t===0)return;let n=c.peek()+e;l(i?(n%t+t)%t:Math.max(0,Math.min(t-1,n)))};return s(()=>{if(!d.value)return;let e=c.value,t=r.length;if(t===0||typeof window>`u`&&!m.current)return;let n=(r[e]?.duration??a)+o,s=g(),u=s.setTimeout(()=>{let n=e+1;n>=t?i?l(0):f(!1):l(n)},n);return()=>s.clearTimeout(u)}),{currentStep:c,playing:d,activeStep:p,play:()=>f(!0),pause:()=>f(!1),toggle:()=>f(!d.peek()),next:()=>_(1),prev:()=>_(-1),restart:()=>{l(0),f(!0)}}}var W={canvas:`_canvas_6fiig_2`,pane:`_pane_6fiig_13`,panSurface:`_panSurface_6fiig_24`};function se({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}){c();let b=y({viewport:r,defaultViewport:i,onViewportChange:a}),x=n??b,S=U(x,{minZoom:o,maxZoom:s,panOnDrag:l,zoomOnScroll:u,fitOnInit:d}),C=m??S,w=x.viewport.value;return p(`div`,{ref:C.containerRef,className:e(W.canvas,g),role:_,...v,children:[p(`div`,{className:W.pane,style:{"--flow-tx":`${w.x}px`,"--flow-ty":`${w.y}px`,"--flow-scale":String(w.zoom)},children:[f(`div`,{ref:C.panHandleRef,className:W.panSurface,"aria-hidden":`true`}),t]}),h]})}var ce={background:`_background_1pu9x_2`};function le({variant:e=`dots`,gap:t=20,size:n=1,color:r,className:i,style:a,...o}){return f(`div`,{"data-variant":e,"aria-hidden":`true`,className:m(ce.background,i),style:{"--flow-bg-gap":`${t}px`,"--flow-bg-size":`${n}px`,"--flow-bg-thick":`${Math.max(1,n)}px`,...r?{"--flow-bg-color":r}:{},...a},...o})}var ue={node:`_node_9zyg4_2`};function de({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}){c();let S=m&&h,[C,w]=n({value:i,defaultValue:a??i??{x:0,y:0},onChange:o}),{handleRef:T,targetRef:E,offset:D,isDragging:O}=r({isDisabled:!S}),k=u(null),A=e=>{k.current=e,T.current=e,E.current=e},j=u(l);j.current=l,s(()=>{let e=k.current;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.offsetWidth,n=e.offsetHeight;t>0&&n>0&&j.current?.({width:t,height:n})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()});let M=u(d);M.current=d;let N=u(null);s(()=>{let e=O.value,t=D.value;if(!S)return;if(!e){N.current=null;return}N.current||={pos:C.peek(),off:t};let n=N.current,r=M.current||1;w({x:n.pos.x+(t.x-n.off.x)/r,y:n.pos.y+(t.y-n.off.y)/r})});let P=C.value;return f(`div`,{ref:A,"data-node-id":t,"data-selected":p||void 0,"data-dragging":O.value||void 0,"data-static":!h||void 0,role:`group`,tabIndex:h?0:void 0,className:e(ue.node,v),style:{"--flow-x":`${P.x}px`,"--flow-y":`${P.y}px`},onClick:e=>{h&&g?.(t),y?.(e)},onKeyDown:e=>{h&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g?.(t)),b?.(e)},...x,children:_})}var G={handle:`_handle_8a1xa_2`,dot:`_dot_8a1xa_41`};function fe(e){return e===`source`?`right`:`left`}function K({type:e,position:t,id:n,isConnectable:r=!0,className:i,...a}){return f(`div`,{"data-handle-type":e,"data-handle-pos":t??fe(e),"data-handle-id":n,"data-connectable":r||void 0,"data-flow-handle":``,tabIndex:r?0:-1,className:m(G.handle,i),...a,children:f(`span`,{className:G.dot,"aria-hidden":`true`})})}var q={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 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}){let x=l(),S=`flow-arrow-${t??x}`,C=g||_,{d:w,mid:T}=L(c,{source:{x:n,y:r},target:{x:i,y:a},sourcePosition:o,targetPosition:s});return p(d,{children:[p(`svg`,{className:e(q.edgeSvg,b),"data-edge-id":t,"data-animated":u||void 0,"data-selected":h||void 0,"data-active":y||void 0,"data-direction":v,"aria-hidden":`true`,children:[C&&f(`defs`,{children:f(`marker`,{id:S,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:f(`path`,{className:q.arrow,d:`M0,0 L10,5 L0,10 z`})})}),f(`path`,{className:q.hit,d:w}),f(`path`,{className:q.edgePath,d:w,markerStart:g?`url(#${S})`:void 0,markerEnd:_?`url(#${S})`:void 0})]}),m!=null&&f(`div`,{className:q.label,style:{"--flow-label-x":`${T.x}px`,"--flow-label-y":`${T.y}px`},children:m})]})}var Y={controls:`_controls_s32im_2`,button:`_button_s32im_32`},X={width:18,height:18,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":!0};function pe({position:t=`bottom-left`,showZoom:n=!0,showFitView:r=!0,onZoomIn:i,onZoomOut:a,onFitView:o,labels:s,className:l,...u}){return c(),p(`div`,{"data-position":t,className:e(Y.controls,l),...u,children:[n&&p(d,{children:[f(`button`,{type:`button`,className:Y.button,"aria-label":s?.zoomIn??g(h.flow.zoomIn),onClick:i,children:f(`svg`,{...X,children:f(`path`,{d:`M12 5v14M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})}),f(`button`,{type:`button`,className:Y.button,"aria-label":s?.zoomOut??g(h.flow.zoomOut),onClick:a,children:f(`svg`,{...X,children:f(`path`,{d:`M5 12h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})})]}),r&&f(`button`,{type:`button`,className:Y.button,"aria-label":s?.fitView??g(h.flow.fitView),onClick:o,children:f(`svg`,{...X,children:f(`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 Z={minimap:`_minimap_rdahv_2`,node:`_node_rdahv_28`,viewport:`_viewport_rdahv_32`};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,ariaLabel:y,className:b}){c();let S=E(t)??{x:0,y:0,width:1,height:1},C=S.width||1,T=S.height||1,D=C*.1,O=T*.1,k={x:S.x-D,y:S.y-O,width:C+D*2,height:T+O*2},A=Math.min(o/k.width,l/k.height),j=-k.x*A+(o-k.width*A)/2,M=-k.y*A+(l-k.height*A)/2,N=e=>({x:e.x*A+j,y:e.y*A+M}),P=null;if(i&&a){let e=x({x:0,y:0},n),t=x({x:i,y:a},n),r=N(e);P={x:r.x,y:r.y,w:(t.x-e.x)*A,h:(t.y-e.y)*A}}let{handleRef:F,offset:I,isDragging:L}=r({isDisabled:!_}),R=u(null),z=e=>{R.current=e,F.current=e},B=u(_);B.current=_;let V=u(null);return s(()=>{let e=L.value,t=I.value;if(!B.current)return;if(!e){V.current=null;return}V.current||={vp:n,off:t};let r=V.current,i=r.vp.zoom;B.current({x:r.vp.x-(t.x-r.off.x)/A*i,y:r.vp.y-(t.y-r.off.y)/A*i,zoom:i})}),p(`svg`,{"data-position":d,className:e(Z.minimap,b),width:o,height:l,role:`img`,"aria-label":y??v??g(h.flow.minimap),children:[t.map(e=>{let t=w(e),n=N({x:t.x,y:t.y});return f(`rect`,{"data-node-id":e.id,className:Z.node,x:n.x,y:n.y,width:t.width*A,height:t.height*A,fill:m},e.id)}),P&&f(`rect`,{ref:z,"data-viewport":``,className:Z.viewport,x:P.x,y:P.y,width:P.w,height:P.h})]})}var he={panel:`_panel_l0cix_2`};function ge({position:e=`top-right`,children:t,className:n,...r}){return f(`div`,{"data-position":e,className:m(he.panel,n),...r,children:t})}var _e={flow:`_flow_vejge_2`},ve=0;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}){c();let D=y({defaultNodes:g?B(t,n,g):t,defaultEdges:n,onNodesChange:r,onEdgesChange:i}),O=U(D,{minZoom:_,maxZoom:v,fitOnInit:l}),{connection:k}=ie({containerRef:O.containerRef,clientToFlow:(e,t)=>{let n=O.containerRef.current?.getBoundingClientRect();return x({x:e-(n?.left??0),y:t-(n?.top??0)},D.viewport.peek())},enabled:b,onConnect:e=>{D.addEdge({id:`e-${++ve}`,source:e.source,target:e.target}),a?.(e)}}),A=e=>{D.setNodes(D.nodes.value.map(t=>({...t,selected:t.id===e})))},j=o({}),M=(e,t)=>{let n=j.peek()[e];n&&n.width===t.width&&n.height===t.height||(j.value={...j.peek(),[e]:t})},N=D.nodes.value,P=D.edges.value,F=D.viewport.value.zoom,I=j.value,L=new Map(N.map(e=>{let t=I[e.id];return[e.id,t?{...e,width:t.width,height:t.height}:e]})),R=k.value;return p(se,{flow:D,controller:O,minZoom:_,maxZoom:v,chrome:p(d,{children:[m&&f(pe,{onZoomIn:O.zoomIn,onZoomOut:O.zoomOut,onFitView:()=>O.fitView()}),h&&f(me,{nodes:N,viewport:D.viewport.value,containerWidth:O.containerRef.current?.clientWidth,containerHeight:O.containerRef.current?.clientHeight,onViewportChange:D.setViewport})]}),className:e(_e.flow,w),style:E,children:[u&&f(le,{...typeof u==`object`?u:{}}),P.map(e=>{let t=L.get(e.source),n=L.get(e.target);if(!t||!n)return null;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;return f(J,{id:e.id,sourceX:r.x,sourceY:r.y,targetX:i.x,targetY:i.y,type:e.type??`bezier`,animated:e.animated||a,active:a,direction:o,markerStart:s,markerEnd:c,label:e.label,selected:e.selected},e.id)}),R&&f(J,{sourceX:R.from.x,sourceY:R.from.y,targetX:R.to.x,targetY:R.to.y,markerEnd:!1}),N.map(e=>f(de,{id:e.id,position:e.position,zoom:F,interactive:b,selected:e.selected??!1,onSelect:b?A:void 0,onMeasure:t=>M(e.id,t),onPositionChange:t=>D.updateNode(e.id,{position:t}),children:s&&e.type&&s[e.type]?s[e.type]({node:e}):p(d,{children:[f(`span`,{children:String(e.data?.label??e.id)}),b&&f(K,{type:`target`,position:`left`}),b&&f(K,{type:`source`,position:`right`})]})},e.id))]})}var Q={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`},$={width:18,height:18,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0};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}){c();let C=te(r,n),w=oe({steps:C,loop:i,stepDuration:a,stepGap:o,playing:s,defaultPlaying:m,currentStep:l,defaultCurrentStep:0,onStepChange:u,clock:b}),T=w.activeStep.value,E=w.currentStep.value,D=w.playing.value;return p(`div`,{className:e(Q.story,x),style:S,children:[f(ye,{nodes:t,edges:n,background:_,interactive:v,activeEdgeId:T?.edgeId,activeDirection:T?.direction}),p(`div`,{className:Q.overlay,children:[f(`div`,{className:Q.caption,"aria-live":`polite`,children:T?.label&&p(`span`,{className:Q.captionText,children:[f(`strong`,{children:T.label}),T.description&&p(`span`,{className:Q.captionDesc,children:[` — `,T.description]})]},E)}),d&&p(`div`,{className:Q.controls,children:[f(`button`,{type:`button`,className:Q.button,"aria-label":y?.previous??g(h.flow.previous),onClick:w.prev,children:f(`svg`,{...$,children:f(`path`,{d:`M15 6 9 12l6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),f(`button`,{type:`button`,className:Q.button,"aria-label":D?y?.pause??g(h.flow.pause):y?.play??g(h.flow.play),"aria-pressed":D,onClick:w.toggle,children:D?f(`svg`,{...$,children:f(`path`,{d:`M7 5h3v14H7zM14 5h3v14h-3z`})}):f(`svg`,{...$,children:f(`path`,{d:`M7 5l11 7-11 7z`})})}),f(`button`,{type:`button`,className:Q.button,"aria-label":y?.next??g(h.flow.next),onClick:w.next,children:f(`svg`,{...$,children:f(`path`,{d:`M9 6l6 6-6 6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`})})}),f(`span`,{className:Q.indicator,children:g(h.flow.step,{current:E+1,total:C.length})})]})]})]})}export{_ as DEFAULT_NODE_SIZE,ye as Flow,le as FlowBackground,se as FlowCanvas,pe as FlowControls,J as FlowEdge,K as FlowHandle,me as FlowMiniMap,de 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,te as resolveScript,ee as resolveStep,x as screenToFlow,I as smoothStepPath,j as straightPath,ie as useConnection,y as useFlow,oe as useStory,U as useViewport};