@picked/client 0.0.39-next.1 → 0.0.39-next.2

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