@picked/client 0.0.1-dev.1770178792114 → 0.0.1-dev.1770181472896

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,810 +0,0 @@
1
- import { createDomain as It, createEvent as k, combine as H, createApi as ut, createEffect as $, attach as F, sample as m, split as Et } from "effector";
2
- import { createFactory as ft, invoke as lt } from "@withease/factories";
3
- import { i as kt, s as dt, a as At } from "./supports-COb-sl36.js";
4
- import { l as x } 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), s = g(e);
40
- if (r === void 0) return n < s;
41
- const a = g(r);
42
- return n < s && s < a;
43
- },
44
- "<=": (t, e, r) => {
45
- const n = g(t), s = g(e);
46
- if (r === void 0) return n <= s;
47
- const a = g(r);
48
- return n <= s && s <= a;
49
- },
50
- "!!": async (t) => await O(t),
51
- "!": async (t) => !await O(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), s = g(e);
60
- if (r === void 0) return n.substr(s);
61
- const a = g(r);
62
- if (a < 0) {
63
- const o = n.substr(s);
64
- return o.substr(0, o.length + a);
65
- }
66
- return n.substr(s, 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 s = n.split(".");
89
- let a = this;
90
- for (const o of s) {
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 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 (!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 O(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 O(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 O(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 O(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 O(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 O(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 O(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 s = 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, s);
226
- }
227
- async function O(t) {
228
- return pt(t) ? O(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 it(t, e, r) {
237
- const n = t.getStateSnapshot(), s = 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: s,
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 s = _t(n.selector).filter(
302
- (a) => !Dt(a, e) && !Rt(a, e)
303
- );
304
- return {
305
- ...n,
306
- elements: s
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 s = Pt(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 st(t) {
354
- return t.type === "conditional";
355
- }
356
- function U(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, s = /* @__PURE__ */ new Set()) => s.has(r.id) ? [] : (s.add(r.id), U(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, s) : [];
371
- })), Ht = (t, e, r) => gt(t, e, r, !0, /* @__PURE__ */ new Set()), mt = (t, e, r, n, s = /* @__PURE__ */ new Set()) => {
372
- if (s.has(r.id)) return [-1, -1];
373
- s.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((P) => P.id === d.destinationNodeId);
379
- if (!S) continue;
380
- const [A, _] = mt(
381
- t,
382
- e,
383
- S,
384
- !1,
385
- new Set(s)
386
- );
387
- A !== -1 && (o = Math.min(o, A + 1), c = Math.max(c, _ + 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 s = e.filter((c) => c.destinationNodeId === r.id);
394
- if (s.length === 0) return [-1, -1];
395
- let a = 1 / 0, o = -1 / 0;
396
- for (const c of s) {
397
- const d = t.find((_) => _.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()), ht = (t) => t.find((r) => r.type === "origin") || null, Q = (t, e, r) => {
409
- if (!t)
410
- return ht(e);
411
- const n = r.find((a) => a.sourceNodeId === t.id);
412
- if (!n)
413
- return null;
414
- const s = e.find((a) => a.id === n.destinationNodeId);
415
- return s || null;
416
- };
417
- async function Wt(t, e, r, n) {
418
- const s = t ? "true" : "false", a = n.find(
419
- (o) => o.sourceNodeHandle === s && o.sourceNodeId === e
420
- );
421
- return r.find((o) => o.id === a?.destinationNodeId);
422
- }
423
- const Y = It("experience-instance"), Gt = ft(
424
- ({
425
- client: t,
426
- experience: e,
427
- target: r
428
- }) => {
429
- const n = k(), s = k(), a = k(), o = k(), c = k(), d = k(), S = e.componentStore, A = Y.store("transitioning"), _ = t.history.entriesStore.map((i) => i.filter((l) => l.experienceId === e.id)), P = _.map((i) => i.filter((l) => U(l.node))), I = _.map((i) => i[i.length - 1]?.node || null), u = H(
430
- e.treeStore,
431
- I,
432
- ({ steps: i }, l) => i.find((f) => l && U(l) && f.id === l.stepId) || null
433
- ), h = H(
434
- e.treeStore,
435
- I,
436
- ({ nodes: i, edges: l }, f) => f ? Ht(i, l, f) : []
437
- ), b = H(
438
- e.treeStore,
439
- I,
440
- ({ nodes: i, edges: l }, f) => f ? Ut(i, l, f) : [-1, -1]
441
- ), T = H(
442
- e.treeStore,
443
- I,
444
- ({ nodes: i, edges: l }, f) => f ? jt(i, l, f) : [-1, -1]
445
- ), v = Y.store(!1), L = ut(v, {
446
- open: () => !0,
447
- close: () => !1,
448
- toggle: (i) => !i,
449
- set: (i, l) => l
450
- }), yt = $(async () => {
451
- t.history.back({ experienceId: e.id });
452
- }), wt = F({
453
- source: e.treeStore,
454
- effect: async (i, l) => {
455
- const f = i.nodes.find((w) => U(w) && w.stepId === l);
456
- f && t.history.push({ experienceId: e.id, node: f });
457
- }
458
- }), Z = F({
459
- source: I,
460
- effect: (i) => {
461
- }
462
- }), V = F({
463
- source: e.treeStore,
464
- effect: async ({ nodes: i }) => ht(i)
465
- }), q = F({
466
- source: e.treeStore,
467
- effect: async ({ nodes: i, edges: l }, f) => {
468
- if (J(f))
469
- return Q(f, i, l);
470
- }
471
- }), X = F({
472
- source: e.treeStore,
473
- effect: async ({ nodes: i, edges: l, conditionals: f }, w) => {
474
- if (!st(w))
475
- return;
476
- const D = f.find((B) => B.id === w.conditionalId);
477
- if (!D)
478
- return;
479
- const E = w.id, y = await it(t, D.condition);
480
- return Wt(!!y, E, i, l);
481
- }
482
- }), tt = F({
483
- source: e.treeStore,
484
- effect: async ({ nodes: i, edges: l }, f) => {
485
- if (!ct(f))
486
- return;
487
- const w = f.action;
488
- if (!w) {
489
- x("warn", `Action node ${f.id} has no action name`);
490
- return;
491
- }
492
- const D = t.actions.getByName(w).getState();
493
- if (!D) {
494
- x("warn", `Action '${w}' not registered on client`);
495
- const E = l.find(
496
- (y) => y.sourceNodeId === f.id && y.sourceNodeHandle === "false"
497
- );
498
- return E ? i.find((y) => y.id === E.destinationNodeId) : null;
499
- }
500
- if (typeof D.action != "function") {
501
- x("warn", `Action '${w}' is not a function`);
502
- const E = l.find(
503
- (y) => y.sourceNodeId === f.id && y.sourceNodeHandle === "false"
504
- );
505
- return E ? i.find((y) => y.id === E.destinationNodeId) : null;
506
- }
507
- try {
508
- x("info", `Executing action: ${w}`), await D.action(w);
509
- const E = l.find(
510
- (B) => B.sourceNodeId === f.id && B.sourceNodeHandle === "true"
511
- );
512
- if (!E)
513
- return x("warn", `No 'true' edge found for action node ${f.id}`), null;
514
- const y = i.find((B) => B.id === E.destinationNodeId);
515
- return x("info", `Action '${w}' succeeded, moving to node ${y?.id}`), y || null;
516
- } catch (E) {
517
- x("warn", `Action '${w}' failed:`, E);
518
- const y = l.find(
519
- (W) => W.sourceNodeId === f.id && W.sourceNodeHandle === "false"
520
- );
521
- if (!y)
522
- return x("warn", `No 'false' edge found for action node ${f.id}`), null;
523
- const B = i.find((W) => W.id === y.destinationNodeId);
524
- return x("info", `Action '${w}' failed, moving to node ${B?.id}`), B || null;
525
- }
526
- }
527
- }), Nt = $((i) => {
528
- if (at(i))
529
- return t.launchExperienceById(i.experienceId);
530
- }), et = F({
531
- source: [I, e.treeStore],
532
- effect: async ([i, { nodes: l, edges: f }]) => Q(i, l, f)
533
- }), C = F({
534
- source: [I, e.treeStore],
535
- effect: async ([i, { nodes: l, edges: f }]) => Q(i, l, f)
536
- }), xt = $((i) => {
537
- t.history.push({ experienceId: e.id, node: i });
538
- }), nt = F({
539
- source: e.configStore,
540
- effect: async ({ initializeOpenLogic: i }) => Ft(i) ? !!await it(t, i) : i ?? !1
541
- }), M = {
542
- id: Math.random().toString(36).substring(7),
543
- // config
544
- experienceId: e.id,
545
- configStore: e.configStore,
546
- target: r,
547
- componentStore: S,
548
- // state
549
- stateStore: A,
550
- // open close
551
- isOpenStore: v,
552
- open: L.open,
553
- close: L.close,
554
- toggleOpen: L.toggle,
555
- setOpen: L.set,
556
- // nodes
557
- treeStore: e.treeStore,
558
- fieldsStore: e.fieldsStore,
559
- currentNodeStore: I,
560
- currentStepStore: u,
561
- nextReachableStepNodesStore: h,
562
- stepsToOriginStore: b,
563
- stepsToLeafStore: T,
564
- // history
565
- goToNextStep: s,
566
- goToPreviousStep: a,
567
- goToStepById: o,
568
- stepsHistoryStore: P
569
- }, z = k(), rt = k();
570
- return m({
571
- source: I,
572
- target: z
573
- }), m({
574
- clock: z,
575
- filter: (i) => i === null,
576
- target: V
577
- }), m({
578
- clock: z,
579
- filter: (i) => i !== null,
580
- target: rt
581
- }), Et({
582
- source: rt,
583
- match: (i) => st(i) ? "condition" : U(i) ? "step" : at(i) ? "launchExperience" : J(i) ? "origin" : ct(i) ? "action" : "other",
584
- cases: {
585
- origin: q,
586
- condition: X,
587
- step: Z,
588
- launchExperience: Nt,
589
- action: tt,
590
- __: k()
591
- }
592
- }), m({
593
- clock: [
594
- X.doneData,
595
- q.doneData,
596
- V.doneData,
597
- C.doneData,
598
- et.doneData,
599
- tt.doneData
600
- ],
601
- filter: Boolean,
602
- target: xt
603
- }), m({
604
- clock: s,
605
- target: C
606
- }), m({
607
- clock: s,
608
- source: u,
609
- filter: Boolean,
610
- target: t.eventBus.prepend((i) => ({
611
- type: "step_submit",
612
- step: i,
613
- experience: e,
614
- experienceInstance: M
615
- }))
616
- }), m({
617
- clock: C.done,
618
- source: u,
619
- filter: Boolean,
620
- target: t.eventBus.prepend((i) => ({
621
- type: "step_submit_success",
622
- step: i,
623
- experience: e,
624
- experienceInstance: M
625
- }))
626
- }), m({
627
- clock: C.fail,
628
- source: u,
629
- filter: Boolean,
630
- target: t.eventBus.prepend((i) => ({
631
- type: "step_submit_error",
632
- step: i,
633
- experience: e,
634
- experienceInstance: M
635
- }))
636
- }), m({
637
- clock: a,
638
- target: yt
639
- }), m({ clock: o, target: wt }), m({
640
- source: H([
641
- X.pending,
642
- q.pending,
643
- V.pending,
644
- C.pending
645
- ]),
646
- fn: (i) => i.some(Boolean) ? "transitioning" : "ready",
647
- target: A
648
- }), m({
649
- clock: Z.doneData,
650
- source: u,
651
- filter: Boolean,
652
- target: t.eventBus.prepend((i) => ({
653
- type: "step_enter",
654
- step: i,
655
- experience: e,
656
- experienceInstance: M
657
- }))
658
- }), m({
659
- clock: d,
660
- target: nt
661
- }), m({
662
- source: nt.doneData,
663
- fn: Boolean,
664
- target: v
665
- }), m({
666
- source: I,
667
- clock: n,
668
- filter: (i) => i ? J(i) : !0,
669
- target: et
670
- }), m({
671
- source: v,
672
- filter: Boolean,
673
- target: n
674
- }), m({
675
- source: v,
676
- filter: Boolean,
677
- target: t.eventBus.prepend(() => ({
678
- type: "experience_open",
679
- experience: e,
680
- experienceInstance: M
681
- }))
682
- }), m({
683
- source: v,
684
- filter: (i) => !i,
685
- target: t.eventBus.prepend(() => ({
686
- type: "experience_close",
687
- experience: e,
688
- experienceInstance: M
689
- }))
690
- }), m({
691
- clock: c,
692
- target: [d]
693
- }), c(), M;
694
- }
695
- );
696
- function Kt(t) {
697
- return lt(Gt, t);
698
- }
699
- const Vt = ft(({ client: t }) => {
700
- const e = Y.store({}), r = k(), n = k(), s = k(), a = ut(e, {
701
- register(u, h) {
702
- const b = [
703
- ...u[h.experienceId] ?? []
704
- ];
705
- return b.push(h), {
706
- ...u,
707
- [h.experienceId]: b
708
- };
709
- },
710
- unregister(u, h) {
711
- const b = h.experienceId, T = u[b]?.filter(
712
- (v) => v !== h
713
- );
714
- return {
715
- ...u,
716
- [b]: T ?? []
717
- };
718
- }
719
- }), o = $(
720
- ({ experience: u, target: h }) => Kt({ client: t, experience: u, target: h })
721
- ), c = $((u) => {
722
- a.register(u);
723
- }), d = $(
724
- (u) => {
725
- u.target && Tt(u.target, () => {
726
- s(u);
727
- });
728
- }
729
- ), S = $((u) => {
730
- a.unregister(u);
731
- }), A = $((u) => {
732
- const h = u.componentStore.getState();
733
- if (!h) {
734
- x("warn", "No app component registered. Skipping init.");
735
- return;
736
- }
737
- const b = h.frameworkStore.getState();
738
- if (!b) {
739
- x(
740
- "error",
741
- `No framework registered for component '${h.name}'. Skipping rendering.`
742
- );
743
- return;
744
- }
745
- const T = u.target;
746
- if (!T) {
747
- x(
748
- "error",
749
- `No target element registered for experience '${u.experienceId}'. Skipping rendering.`
750
- );
751
- return;
752
- }
753
- const v = Mt(T);
754
- try {
755
- b.render(v, h.component, t, u);
756
- } catch (L) {
757
- x("error", L);
758
- }
759
- });
760
- m({
761
- clock: r,
762
- target: o
763
- }), m({
764
- clock: s,
765
- target: S
766
- }), m({
767
- clock: o.doneData,
768
- target: [
769
- c,
770
- d,
771
- n
772
- ]
773
- }), m({
774
- clock: o.doneData,
775
- target: t.eventBus.prepend((u) => ({
776
- type: "experience_initialize",
777
- experienceInstance: u
778
- }))
779
- }), m({
780
- clock: n,
781
- target: A
782
- });
783
- function _(u, h) {
784
- r({ experience: u, target: h });
785
- }
786
- const P = e.map((u) => Object.values(u).flat());
787
- function I(u) {
788
- return e.map((h) => h[u] || [], { skipVoid: !1 });
789
- }
790
- return {
791
- spawn: _,
792
- getByExperienceId: I,
793
- listStore: P
794
- };
795
- });
796
- function ne(t) {
797
- return lt(Vt, t);
798
- }
799
- export {
800
- U as a,
801
- ne as b,
802
- te as c,
803
- Yt as d,
804
- it as e,
805
- Rt as f,
806
- Zt as g,
807
- Kt as h,
808
- Ft as i,
809
- ee as t
810
- };