@picked/client 0.0.38-next.3 → 0.0.39-next.1

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,815 @@
1
+ import { createDomain as xt, createEvent as k, combine as D, createApi as ut, createEffect as M, attach as B, sample as m, split as Et } from "effector";
2
+ import { createFactory as ft, invoke as lt } from "@withease/factories";
3
+ import { j as kt, s as dt, a as At } from "./supports-8YT4QKI7.js";
4
+ import { l as I } from "./logger-C9a75KZn.js";
5
+ import { i as bt } from "./object-JwZ58NOH.js";
6
+ function vt(t) {
7
+ return typeof t == "number" && !isNaN(t);
8
+ }
9
+ function j(t) {
10
+ return typeof t == "string";
11
+ }
12
+ function N(t) {
13
+ return Array.isArray(t);
14
+ }
15
+ function pt(t) {
16
+ return t instanceof Promise;
17
+ }
18
+ function ot(t) {
19
+ return typeof t == "object" && t !== null && !Array.isArray(t) && Object.keys(t).length === 1;
20
+ }
21
+ function g(t) {
22
+ if (vt(t)) return t;
23
+ const e = parseFloat(`${t}`);
24
+ return isNaN(e) ? 0 : e;
25
+ }
26
+ function R(t) {
27
+ return `${t}`;
28
+ }
29
+ const Ot = {
30
+ // eslint-disable-next-line eqeqeq
31
+ "==": (t, e) => t == e,
32
+ "===": (t, e) => t === e,
33
+ // eslint-disable-next-line eqeqeq
34
+ "!=": (t, e) => t != e,
35
+ "!==": (t, e) => t !== e,
36
+ ">": (t, e) => g(t) > g(e),
37
+ ">=": (t, e) => g(t) >= g(e),
38
+ "<": (t, e, r) => {
39
+ const n = g(t), i = g(e);
40
+ if (r === void 0) return n < i;
41
+ const a = g(r);
42
+ return n < i && i < a;
43
+ },
44
+ "<=": (t, e, r) => {
45
+ const n = g(t), i = g(e);
46
+ if (r === void 0) return n <= i;
47
+ const a = g(r);
48
+ return n <= i && i <= a;
49
+ },
50
+ "!!": async (t) => await v(t),
51
+ "!": async (t) => !await v(t),
52
+ "%": (t, e) => g(t) % g(e),
53
+ // eslint-disable-next-line sonarjs/function-return-type
54
+ log: (t) => (console.log(t), t),
55
+ in: (t, e) => e ? j(e) ? e.indexOf(R(t)) !== -1 : N(e) ? e.includes(t) : !1 : !1,
56
+ cat: (...t) => t.map(R).join(""),
57
+ /* eslint-disable sonarjs/deprecation */
58
+ substr: (t, e, r) => {
59
+ const n = R(t), i = g(e);
60
+ if (r === void 0) return n.substr(i);
61
+ const a = g(r);
62
+ if (a < 0) {
63
+ const o = n.substr(i);
64
+ return o.substr(0, o.length + a);
65
+ }
66
+ return n.substr(i, a);
67
+ },
68
+ /* eslint-enable sonarjs/deprecation */
69
+ "+": (...t) => t.reduce((e, r) => g(e) + g(r), 0),
70
+ "*": (...t) => t.reduce((e, r) => g(e) * g(r), 1),
71
+ "-": (t, e) => {
72
+ const r = g(t);
73
+ return e === void 0 ? -r : r - g(e);
74
+ },
75
+ "/": (t, e) => g(t) / g(e),
76
+ min: (...t) => Math.min(...t.map(g)),
77
+ max: (...t) => Math.max(...t.map(g)),
78
+ merge: (...t) => t.reduce((e, r) => N(r) ? e.concat(r) : e.concat([r]), []),
79
+ var(t, e) {
80
+ const r = arguments.length > 1 ? e : null;
81
+ if (t === "" || t === "." || t === null || t === void 0)
82
+ return this;
83
+ if (typeof t == "number" && Array.isArray(this))
84
+ return t >= 0 && t < this.length ? this[t] : r;
85
+ const n = R(t);
86
+ if (n === "" || n === ".")
87
+ return this;
88
+ const i = n.split(".");
89
+ let a = this;
90
+ for (const o of i) {
91
+ if (a == null)
92
+ return r;
93
+ if (Array.isArray(a)) {
94
+ const c = parseInt(o, 10);
95
+ isNaN(c) ? a = a[o] : a = a[c];
96
+ } else
97
+ a = a[o];
98
+ }
99
+ return a !== void 0 ? a : r;
100
+ },
101
+ async missing(...t) {
102
+ const e = N(t[0]) ? t[0] : t, r = [];
103
+ for (const n of e) {
104
+ const i = await p({ var: n }, this);
105
+ (i === null || i === "") && r.push(`${n}`);
106
+ }
107
+ return r;
108
+ },
109
+ async missing_some(t, e) {
110
+ const r = await p({ missing: e }, this);
111
+ if (!N(r) || !N(e)) return [];
112
+ const n = r.filter(j);
113
+ return e.filter(j).length - n.length >= g(t) ? [] : n;
114
+ },
115
+ /**
116
+ * Invoke operator - executes a function with optional arguments
117
+ *
118
+ * Object format (no arguments):
119
+ * { "invoke": { "var": "functionName" } }
120
+ *
121
+ * Array format (with arguments):
122
+ * { "invoke": [{ "var": "functionName" }, arg1, arg2, ...] }
123
+ *
124
+ * Arguments are evaluated as JSONLogic expressions before being passed to the function.
125
+ */
126
+ // eslint-disable-next-line sonarjs/function-return-type
127
+ invoke(...t) {
128
+ const [e, ...r] = t;
129
+ return typeof e != "function" ? null : Reflect.apply(e, null, r);
130
+ },
131
+ regexp_matches(t, e) {
132
+ let r = t, n = "";
133
+ if (N(t)) {
134
+ const [a, o] = t;
135
+ r = a, n = o;
136
+ }
137
+ return !j(r) || !j(n) ? !1 : new RegExp(r, n).test(R(e));
138
+ },
139
+ throw(t) {
140
+ throw new Error(R(t));
141
+ }
142
+ };
143
+ async function p(t, e) {
144
+ if (!t) return t;
145
+ if (pt(t))
146
+ return p(await t, e);
147
+ if (N(t))
148
+ return Promise.all(t.map((o) => p(o, e)));
149
+ if (!ot(t)) return t;
150
+ const r = Bt(t);
151
+ let n = r ? t[r] ?? [] : [];
152
+ switch (N(n) || (n = [n]), r) {
153
+ case "if":
154
+ case "?:":
155
+ for (let o = 0; o < n.length - 1; o += 2)
156
+ if (await v(await p(n[o], e)))
157
+ return p(n[o + 1], e);
158
+ return n.length % 2 === 1 ? p(n[n.length - 1], e) : null;
159
+ case "and": {
160
+ let o = null;
161
+ for (const c of n)
162
+ if (o = await p(c, e), !await v(o))
163
+ return o;
164
+ return o;
165
+ }
166
+ case "or": {
167
+ let o = null;
168
+ for (const c of n)
169
+ if (o = await p(c, e), await v(o)) return o;
170
+ return o;
171
+ }
172
+ case "map": {
173
+ const o = await p(n[0], e);
174
+ return N(o) ? await Promise.all(o.map((c) => p(n[1], c))) : [];
175
+ }
176
+ case "filter": {
177
+ const o = await p(n[0], e);
178
+ return N(o) ? (await Promise.all(
179
+ o.map(async (d) => {
180
+ const S = await v(await p(n[1], d));
181
+ return { item: d, shouldInclude: S };
182
+ })
183
+ )).filter(({ shouldInclude: d }) => d).map(({ item: d }) => d) : [];
184
+ }
185
+ case "reduce": {
186
+ const o = await p(n[0], e);
187
+ if (!N(o))
188
+ return n.length > 2 ? await p(n[2], e) : null;
189
+ const c = n[1];
190
+ let S = n.length > 2 ? await p(n[2], e) : null;
191
+ for (const A of o)
192
+ S = await p(c, { current: A, accumulator: S });
193
+ return S;
194
+ }
195
+ case "all": {
196
+ const o = await p(n[0], e);
197
+ if (!N(o) || o.length === 0) return !1;
198
+ for (const c of o)
199
+ if (!await v(await p(n[1], c))) return !1;
200
+ return !0;
201
+ }
202
+ case "some": {
203
+ const o = await p(n[0], e);
204
+ if (!N(o)) return !1;
205
+ for (const c of o)
206
+ if (await v(await p(n[1], c))) return !0;
207
+ return !1;
208
+ }
209
+ case "none": {
210
+ const o = await p(n[0], e);
211
+ if (!N(o)) return !0;
212
+ for (const c of o)
213
+ if (await v(await p(n[1], c))) return !1;
214
+ return !0;
215
+ }
216
+ case "catch":
217
+ try {
218
+ return await p(n[0], e);
219
+ } catch (o) {
220
+ return ot(o) ? await p(o, e) : n[1] ? await p(n[1], o) : o instanceof Error ? o.message : o;
221
+ }
222
+ }
223
+ const i = await Promise.all(n.map((o) => p(o, e))), a = r ? Ot[r] : void 0;
224
+ if (!a) throw new Error(`Unrecognized operation ${r}`);
225
+ return a.apply(e, i);
226
+ }
227
+ async function v(t) {
228
+ return pt(t) ? v(await t) : !(Array.isArray(t) && t.length === 0) && !!t;
229
+ }
230
+ function Bt(t) {
231
+ return Object.keys(t)[0];
232
+ }
233
+ function Ft(t) {
234
+ return !bt(t);
235
+ }
236
+ async function st(t, e, r) {
237
+ const n = t.getStateSnapshot(), i = t.predicates.listStore.getState().reduce((c, d) => ({
238
+ ...c,
239
+ [d.name]: (...S) => d.predicate({ ...n, args: S })
240
+ }), {}), a = t.features.listStore.getState().reduce((c, d) => ({
241
+ ...c,
242
+ [d.id]: async () => {
243
+ const { bucket: S } = await d.getBucket();
244
+ return S;
245
+ }
246
+ }), {}), o = {
247
+ ...r,
248
+ responses: t.responses.getAllStore.getState(),
249
+ location: typeof n.location == "object" ? {
250
+ hash: n.location.hash,
251
+ host: n.location.host,
252
+ hostname: n.location.hostname,
253
+ href: n.location.href,
254
+ origin: n.location.origin,
255
+ pathname: n.location.pathname,
256
+ port: n.location.port,
257
+ protocol: n.location.protocol,
258
+ search: n.location.search
259
+ } : void 0,
260
+ predicates: i,
261
+ features: a
262
+ };
263
+ return await p(e, o);
264
+ }
265
+ function _t(t) {
266
+ return !At() || !dt() ? [] : Array.from(window.document.querySelectorAll(t)).filter(
267
+ (e) => e instanceof HTMLElement
268
+ );
269
+ }
270
+ const $t = "open";
271
+ function Mt(t) {
272
+ if (!kt())
273
+ throw new Error("Shadow DOM is not supported in this environment");
274
+ return t.attachShadow({ mode: $t });
275
+ }
276
+ function Yt() {
277
+ return new Promise((t, e) => {
278
+ if (!dt()) {
279
+ e();
280
+ return;
281
+ }
282
+ document.readyState !== "loading" ? t() : document.addEventListener("readystatechange", () => t(), { once: !0 });
283
+ });
284
+ }
285
+ function Tt(t, e) {
286
+ const r = new MutationObserver((n) => {
287
+ document.contains(t) || (r.disconnect(), e());
288
+ });
289
+ r.observe(document.body, { childList: !0, subtree: !0 });
290
+ }
291
+ const G = "picked-root", K = "picked-target", Lt = "picked-root";
292
+ function Zt(t, e) {
293
+ return [
294
+ ...t,
295
+ // Target and replace picked-root web components
296
+ {
297
+ selector: `${Lt}[experience-id="${e}"]`,
298
+ placement: "replace"
299
+ }
300
+ ].flatMap((n) => {
301
+ const i = _t(n.selector).filter(
302
+ (a) => !Dt(a, e) && !Rt(a, e)
303
+ );
304
+ return {
305
+ ...n,
306
+ elements: i
307
+ };
308
+ });
309
+ }
310
+ function te(t, e) {
311
+ return t.flatMap((r) => r.elements.map((n) => Ct(n, r.placement, e)));
312
+ }
313
+ function ee(t, e) {
314
+ t.classList.add(K), t.classList.add(`${K}-${e}`);
315
+ }
316
+ function Dt(t, e) {
317
+ return e ? t.classList.contains(`${K}-${e}`) : t.classList.contains(`${K}`);
318
+ }
319
+ function Rt(t, e) {
320
+ return e ? t.classList.contains(`${G}-${e}`) : t.classList.contains(G);
321
+ }
322
+ function Pt(t) {
323
+ const e = document.createElement("div");
324
+ return e.style.display = "block", e.classList.add(G), e.classList.add(`${G}-${t}`), e;
325
+ }
326
+ function Ct(t, e, r) {
327
+ let n;
328
+ const i = Pt(r);
329
+ if (t instanceof Document)
330
+ n = t.body.appendChild(i);
331
+ else {
332
+ switch (e) {
333
+ case "replace":
334
+ t.replaceWith(i);
335
+ break;
336
+ case "before":
337
+ t.before(i);
338
+ break;
339
+ case "after":
340
+ t.after(i);
341
+ break;
342
+ case "prepend":
343
+ t.prepend(i);
344
+ break;
345
+ default:
346
+ t.append(i);
347
+ break;
348
+ }
349
+ n = i;
350
+ }
351
+ return n;
352
+ }
353
+ function it(t) {
354
+ return t.type === "conditional";
355
+ }
356
+ function P(t) {
357
+ return t.type === "step";
358
+ }
359
+ function at(t) {
360
+ return t.type === "experience";
361
+ }
362
+ function J(t) {
363
+ return t.type === "origin";
364
+ }
365
+ function ct(t) {
366
+ return t.type === "action";
367
+ }
368
+ const gt = (t, e, r, n, i = /* @__PURE__ */ new Set()) => i.has(r.id) ? [] : (i.add(r.id), P(r) && !n ? [r] : e.filter((o) => o.sourceNodeId === r.id).flatMap((o) => {
369
+ const c = t.find((d) => d.id === o.destinationNodeId);
370
+ return c ? gt(t, e, c, !1, i) : [];
371
+ })), Ht = (t, e, r) => gt(t, e, r, !0, /* @__PURE__ */ new Set()), mt = (t, e, r, n, i = /* @__PURE__ */ new Set()) => {
372
+ if (i.has(r.id)) return [-1, -1];
373
+ i.add(r.id);
374
+ const a = e.filter((d) => d.sourceNodeId === r.id);
375
+ if (a.length === 0) return [0, 0];
376
+ let o = 1 / 0, c = -1 / 0;
377
+ for (const d of a) {
378
+ const S = t.find((T) => T.id === d.destinationNodeId);
379
+ if (!S) continue;
380
+ const [A, F] = mt(
381
+ t,
382
+ e,
383
+ S,
384
+ !1,
385
+ new Set(i)
386
+ );
387
+ A !== -1 && (o = Math.min(o, A + 1), c = Math.max(c, F + 1));
388
+ }
389
+ return o === 1 / 0 ? [-1, -1] : [o, c];
390
+ }, jt = (t, e, r) => mt(t, e, r, !0, /* @__PURE__ */ new Set()), St = (t, e, r, n = /* @__PURE__ */ new Set()) => {
391
+ if (n.has(r.id)) return [-1, -1];
392
+ if (n.add(r.id), r.type === "origin") return [0, 0];
393
+ const i = e.filter((c) => c.destinationNodeId === r.id);
394
+ if (i.length === 0) return [-1, -1];
395
+ let a = 1 / 0, o = -1 / 0;
396
+ for (const c of i) {
397
+ const d = t.find((F) => F.id === c.sourceNodeId);
398
+ if (!d) continue;
399
+ const [S, A] = St(
400
+ t,
401
+ e,
402
+ d,
403
+ new Set(n)
404
+ );
405
+ S !== -1 && (a = Math.min(a, S + 1), o = Math.max(o, A + 1));
406
+ }
407
+ return a === 1 / 0 ? [-1, -1] : [a, o];
408
+ }, Ut = (t, e, r) => St(t, e, r, /* @__PURE__ */ new Set()), yt = (t) => t.find((r) => r.type === "origin") || null, Q = (t, e, r) => {
409
+ if (!t)
410
+ return yt(e);
411
+ const n = r.find((a) => a.sourceNodeId === t.id);
412
+ if (!n)
413
+ return null;
414
+ const i = e.find((a) => a.id === n.destinationNodeId);
415
+ return i || null;
416
+ };
417
+ async function Wt(t, e, r, n) {
418
+ const i = t ? "true" : "false", a = n.find(
419
+ (o) => o.sourceNodeHandle === i && o.sourceNodeId === e
420
+ );
421
+ return r.find((o) => o.id === a?.destinationNodeId);
422
+ }
423
+ const Y = xt("experience-instance"), Gt = ft(
424
+ ({
425
+ client: t,
426
+ experience: e,
427
+ target: r
428
+ }) => {
429
+ const n = k(), i = k(), a = k(), o = k(), c = k(), d = k(), S = e.componentStore, A = Y.store("transitioning"), F = t.history.entriesStore.map((s) => s.filter((l) => l.experienceId === e.id)), T = F.map((s) => s.filter((l) => P(l.node))), x = F.map((s) => s.at(-1)?.node || null), f = D(
430
+ e.treeStore,
431
+ x,
432
+ ({ steps: s }, l) => s.find((u) => l && P(l) && u.id === l.stepId) || null
433
+ ), y = D(
434
+ e.treeStore,
435
+ T,
436
+ ({ steps: s }, l) => {
437
+ const u = l.at(-2);
438
+ if (!u || !P(u.node))
439
+ return null;
440
+ const h = u.node;
441
+ return s.find(($) => $.id === h.stepId) || null;
442
+ }
443
+ ), b = D(
444
+ e.treeStore,
445
+ x,
446
+ ({ nodes: s, edges: l }, u) => u ? Ht(s, l, u) : []
447
+ ), L = D(
448
+ e.treeStore,
449
+ x,
450
+ ({ nodes: s, edges: l }, u) => u ? Ut(s, l, u) : [-1, -1]
451
+ ), C = D(
452
+ e.treeStore,
453
+ x,
454
+ ({ nodes: s, edges: l }, u) => u ? jt(s, l, u) : [-1, -1]
455
+ ), _ = Y.store(!1), U = ut(_, {
456
+ open: () => !0,
457
+ close: () => !1,
458
+ toggle: (s) => !s,
459
+ set: (s, l) => l
460
+ }), ht = M(async () => {
461
+ t.history.back({ experienceId: e.id });
462
+ }), wt = B({
463
+ source: e.treeStore,
464
+ effect: async (s, l) => {
465
+ const u = s.nodes.find((h) => P(h) && h.stepId === l);
466
+ u && t.history.push({ experienceId: e.id, node: u });
467
+ }
468
+ }), Z = B({
469
+ source: x,
470
+ effect: (s) => {
471
+ }
472
+ }), V = B({
473
+ source: e.treeStore,
474
+ effect: async ({ nodes: s }) => yt(s)
475
+ }), q = B({
476
+ source: e.treeStore,
477
+ effect: async ({ nodes: s, edges: l }, u) => {
478
+ if (J(u))
479
+ return Q(u, s, l);
480
+ }
481
+ }), X = B({
482
+ source: e.treeStore,
483
+ effect: async ({ nodes: s, edges: l, conditionals: u }, h) => {
484
+ if (!it(h))
485
+ return;
486
+ const $ = u.find((O) => O.id === h.conditionalId);
487
+ if (!$)
488
+ return;
489
+ const E = h.id, w = await st(t, $.condition);
490
+ return Wt(!!w, E, s, l);
491
+ }
492
+ }), tt = B({
493
+ source: e.treeStore,
494
+ effect: async ({ nodes: s, edges: l }, u) => {
495
+ if (!ct(u))
496
+ return;
497
+ const h = u.action;
498
+ if (!h) {
499
+ I("warn", `Action node ${u.id} has no action name`);
500
+ return;
501
+ }
502
+ const $ = t.actions.getByName(h).getState();
503
+ if (!$) {
504
+ I("warn", `Action '${h}' not registered on client`);
505
+ const E = l.find(
506
+ (w) => w.sourceNodeId === u.id && w.sourceNodeHandle === "false"
507
+ );
508
+ return E ? s.find((w) => w.id === E.destinationNodeId) : null;
509
+ }
510
+ if (typeof $.action != "function") {
511
+ I("warn", `Action '${h}' is not a function`);
512
+ const E = l.find(
513
+ (w) => w.sourceNodeId === u.id && w.sourceNodeHandle === "false"
514
+ );
515
+ return E ? s.find((w) => w.id === E.destinationNodeId) : null;
516
+ }
517
+ try {
518
+ I("info", `Executing action: ${h}`), await $.action(h);
519
+ const E = l.find(
520
+ (O) => O.sourceNodeId === u.id && O.sourceNodeHandle === "true"
521
+ );
522
+ if (!E)
523
+ return I("warn", `No 'true' edge found for action node ${u.id}`), null;
524
+ const w = s.find((O) => O.id === E.destinationNodeId);
525
+ return I("info", `Action '${h}' succeeded, moving to node ${w?.id}`), w || null;
526
+ } catch (E) {
527
+ I("warn", `Action '${h}' failed:`, E);
528
+ const w = l.find(
529
+ (W) => W.sourceNodeId === u.id && W.sourceNodeHandle === "false"
530
+ );
531
+ if (!w)
532
+ return I("warn", `No 'false' edge found for action node ${u.id}`), null;
533
+ const O = s.find((W) => W.id === w.destinationNodeId);
534
+ return I("info", `Action '${h}' failed, moving to node ${O?.id}`), O || null;
535
+ }
536
+ }
537
+ }), Nt = M((s) => {
538
+ if (at(s))
539
+ return t.launchExperienceById(s.experienceId);
540
+ }), et = B({
541
+ source: [x, e.treeStore],
542
+ effect: async ([s, { nodes: l, edges: u }]) => Q(s, l, u)
543
+ }), H = B({
544
+ source: [x, e.treeStore],
545
+ effect: async ([s, { nodes: l, edges: u }]) => Q(s, l, u)
546
+ }), It = M((s) => {
547
+ t.history.push({ experienceId: e.id, node: s });
548
+ }), nt = B({
549
+ source: e.configStore,
550
+ effect: async ({ initializeOpenLogic: s }) => Ft(s) ? !!await st(t, s) : s ?? !1
551
+ }), z = k(), rt = k();
552
+ return m({
553
+ source: x,
554
+ target: z
555
+ }), m({
556
+ clock: z,
557
+ filter: (s) => s === null,
558
+ target: V
559
+ }), m({
560
+ clock: z,
561
+ filter: (s) => s !== null,
562
+ target: rt
563
+ }), Et({
564
+ source: rt,
565
+ match: (s) => it(s) ? "condition" : P(s) ? "step" : at(s) ? "launchExperience" : J(s) ? "origin" : ct(s) ? "action" : "other",
566
+ cases: {
567
+ origin: q,
568
+ condition: X,
569
+ step: Z,
570
+ launchExperience: Nt,
571
+ action: tt,
572
+ __: k()
573
+ }
574
+ }), m({
575
+ clock: [
576
+ X.doneData,
577
+ q.doneData,
578
+ V.doneData,
579
+ H.doneData,
580
+ et.doneData,
581
+ tt.doneData
582
+ ],
583
+ filter: Boolean,
584
+ target: It
585
+ }), m({
586
+ clock: i,
587
+ target: H
588
+ }), m({
589
+ clock: i,
590
+ source: f,
591
+ filter: Boolean,
592
+ target: t.eventBus.prepend((s) => ({
593
+ type: "step_submit",
594
+ step: s,
595
+ experience: e
596
+ }))
597
+ }), m({
598
+ clock: H.done,
599
+ source: f,
600
+ filter: Boolean,
601
+ target: t.eventBus.prepend((s) => ({
602
+ type: "step_submit_success",
603
+ step: s,
604
+ experience: e
605
+ }))
606
+ }), m({
607
+ clock: H.fail,
608
+ source: f,
609
+ filter: Boolean,
610
+ target: t.eventBus.prepend((s) => ({
611
+ type: "step_submit_error",
612
+ step: s,
613
+ experience: e
614
+ }))
615
+ }), m({
616
+ clock: a,
617
+ target: ht
618
+ }), m({ clock: o, target: wt }), m({
619
+ source: D([
620
+ X.pending,
621
+ q.pending,
622
+ V.pending,
623
+ H.pending
624
+ ]),
625
+ fn: (s) => s.some(Boolean) ? "transitioning" : "ready",
626
+ target: A
627
+ }), m({
628
+ clock: Z.doneData,
629
+ source: f,
630
+ filter: Boolean,
631
+ target: t.eventBus.prepend((s) => ({
632
+ type: "step_enter",
633
+ step: s,
634
+ experience: e
635
+ }))
636
+ }), m({
637
+ clock: d,
638
+ target: nt
639
+ }), m({
640
+ source: nt.doneData,
641
+ fn: Boolean,
642
+ target: _
643
+ }), m({
644
+ source: x,
645
+ clock: n,
646
+ filter: (s) => s ? J(s) : !0,
647
+ target: et
648
+ }), m({
649
+ source: _,
650
+ filter: Boolean,
651
+ target: n
652
+ }), m({
653
+ source: _,
654
+ filter: Boolean,
655
+ target: t.eventBus.prepend(() => ({
656
+ type: "experience_open",
657
+ experience: e
658
+ }))
659
+ }), m({
660
+ source: _,
661
+ filter: (s) => !s,
662
+ target: t.eventBus.prepend(() => ({
663
+ type: "experience_close",
664
+ experience: e
665
+ }))
666
+ }), m({
667
+ clock: c,
668
+ target: [d]
669
+ }), c(), {
670
+ id: Math.random().toString(36).substring(7),
671
+ // config
672
+ experienceId: e.id,
673
+ configStore: e.configStore,
674
+ target: r,
675
+ componentStore: S,
676
+ // state
677
+ stateStore: A,
678
+ // open close
679
+ isOpenStore: _,
680
+ open: U.open,
681
+ close: U.close,
682
+ toggleOpen: U.toggle,
683
+ setOpen: U.set,
684
+ // nodes
685
+ treeStore: e.treeStore,
686
+ fieldsStore: e.fieldsStore,
687
+ currentNodeStore: x,
688
+ currentStepStore: f,
689
+ previousStepStore: y,
690
+ nextReachableStepNodesStore: b,
691
+ stepsToOriginStore: L,
692
+ stepsToLeafStore: C,
693
+ // history
694
+ goToNextStep: i,
695
+ goToPreviousStep: a,
696
+ goToStepById: o,
697
+ stepsHistoryStore: T
698
+ };
699
+ }
700
+ );
701
+ function Kt(t) {
702
+ return lt(Gt, t);
703
+ }
704
+ const Vt = ft(({ client: t }) => {
705
+ const e = Y.store({}), r = k(), n = k(), i = k(), a = ut(e, {
706
+ register(f, y) {
707
+ const b = [
708
+ ...f[y.experienceId] ?? []
709
+ ];
710
+ return b.push(y), {
711
+ ...f,
712
+ [y.experienceId]: b
713
+ };
714
+ },
715
+ unregister(f, y) {
716
+ const b = y.experienceId, L = f[b]?.filter(
717
+ (C) => C !== y
718
+ );
719
+ return {
720
+ ...f,
721
+ [b]: L ?? []
722
+ };
723
+ }
724
+ }), o = M(
725
+ ({ experience: f, target: y }) => Kt({ client: t, experience: f, target: y })
726
+ ), c = M((f) => {
727
+ a.register(f);
728
+ }), d = M(
729
+ (f) => {
730
+ f.target && Tt(f.target, () => {
731
+ i(f);
732
+ });
733
+ }
734
+ ), S = M((f) => {
735
+ a.unregister(f);
736
+ }), A = M((f) => {
737
+ const y = f.componentStore.getState();
738
+ if (!y) {
739
+ I("warn", "No app component registered. Skipping init.");
740
+ return;
741
+ }
742
+ const b = y.frameworkStore.getState();
743
+ if (!b) {
744
+ I(
745
+ "error",
746
+ `No framework registered for component '${y.name}'. Skipping rendering.`
747
+ );
748
+ return;
749
+ }
750
+ const L = f.target;
751
+ if (!L) {
752
+ I(
753
+ "error",
754
+ `No target element registered for experience '${f.experienceId}'. Skipping rendering.`
755
+ );
756
+ return;
757
+ }
758
+ const C = Mt(L);
759
+ try {
760
+ b.render(C, y.component, t, f);
761
+ } catch (_) {
762
+ I("error", _);
763
+ }
764
+ });
765
+ m({
766
+ clock: r,
767
+ target: o
768
+ }), m({
769
+ clock: i,
770
+ target: S
771
+ }), m({
772
+ clock: o.doneData,
773
+ target: [
774
+ c,
775
+ d,
776
+ n
777
+ ]
778
+ }), m({
779
+ clock: o.doneData,
780
+ target: t.eventBus.prepend((f) => ({
781
+ type: "experience_initialize",
782
+ experienceInstance: f
783
+ }))
784
+ }), m({
785
+ clock: n,
786
+ target: A
787
+ });
788
+ function F(f, y) {
789
+ r({ experience: f, target: y });
790
+ }
791
+ const T = e.map((f) => Object.values(f).flat());
792
+ function x(f) {
793
+ return e.map((y) => y[f] || [], { skipVoid: !1 });
794
+ }
795
+ return {
796
+ spawn: F,
797
+ getByExperienceId: x,
798
+ listStore: T
799
+ };
800
+ });
801
+ function ne(t) {
802
+ return lt(Vt, t);
803
+ }
804
+ export {
805
+ P as a,
806
+ ne as b,
807
+ te as c,
808
+ Yt as d,
809
+ st as e,
810
+ Rt as f,
811
+ Zt as g,
812
+ Kt as h,
813
+ Ft as i,
814
+ ee as t
815
+ };