@telia-ace/widget-core 0.0.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.
package/index.mjs ADDED
@@ -0,0 +1,910 @@
1
+ import { bootstrapImplementation as H, ConfigurationApi as B } from "@webprovisions/bootstrapping";
2
+ import { selectImplementations as M, createConfigurationApi as V, version as j, Environment as q, Implementation as z, Plugin as Q, WidgetType as F } from "@webprovisions/platform";
3
+ import { uuid as E, Logger as O } from "@telia-ace/widget-utilities";
4
+ class at {
5
+ constructor(t) {
6
+ const { events: e } = t.get("$widget");
7
+ this.events = e.createChild(this);
8
+ }
9
+ action(t, e, s) {
10
+ this.events.dispatch(
11
+ "data:action",
12
+ { action: e, value: s, target: t },
13
+ { bubbles: !0 }
14
+ );
15
+ }
16
+ subscribe(t, e) {
17
+ return this.events.subscribe(
18
+ "data:action",
19
+ (s, { action: i, value: c, target: o }) => t === o && e(t, i, c)
20
+ );
21
+ }
22
+ }
23
+ const pt = (n, t, e = {}) => H(
24
+ n,
25
+ n.bindings,
26
+ () => {
27
+ const s = n.container.get("$runtimecfg").map((i) => {
28
+ const c = i[0];
29
+ if (typeof c == "function")
30
+ return c;
31
+ if (M(c)(n))
32
+ return i[1];
33
+ }).filter((i) => !!i);
34
+ return (t ? [t] : []).concat(
35
+ s
36
+ );
37
+ },
38
+ e.rootElementResolver || (() => document.body)
39
+ ), G = (n) => {
40
+ const t = [];
41
+ return [
42
+ (s, i) => {
43
+ t.push(n.subscribe(s, i));
44
+ },
45
+ () => {
46
+ t.forEach((s) => {
47
+ s();
48
+ });
49
+ }
50
+ ];
51
+ };
52
+ class N {
53
+ constructor(t, e = []) {
54
+ this.platform = t, this.rules = e;
55
+ }
56
+ match(t) {
57
+ return this.rules.every((e) => !(e.id && e.id !== t.id || e.type && e.type !== t.type));
58
+ }
59
+ ofType(t) {
60
+ return this.rules.push({ type: t }), this;
61
+ }
62
+ withId(t) {
63
+ return this.rules.push({ id: t }), this;
64
+ }
65
+ select() {
66
+ return new K(this.platform, this);
67
+ }
68
+ }
69
+ class S {
70
+ constructor(t, e, s) {
71
+ this.platform = t, this.node = e, this.actions = new P(
72
+ t,
73
+ new N(t).withId(e.id),
74
+ s
75
+ );
76
+ const [i, c] = G(
77
+ this.platform.events
78
+ );
79
+ this.subscribe = i, this.unsubscribe = c;
80
+ }
81
+ properties(t) {
82
+ return t && this.node.touchProperties((e) => t(e)), this.node.attributes.properties;
83
+ }
84
+ context(t) {
85
+ return t && this.subscribe("components:context-changed", (e, { node: s }) => {
86
+ s === this.node && t(this.node.attributes.context);
87
+ }), this.node.attributes.context;
88
+ }
89
+ layout(t) {
90
+ return t && this.subscribe("components:layout-changed", (e, { node: s }) => {
91
+ s === this.node && t(this.node.attributes.layout);
92
+ }), this.node.attributes.layout;
93
+ }
94
+ writeProperties(t, e) {
95
+ this.node.writeProperties(t, e);
96
+ }
97
+ writeContext(t, e) {
98
+ this.node.writeProperties(t, e);
99
+ }
100
+ writeLayout(t, e) {
101
+ this.node.writeLayout(t, e);
102
+ }
103
+ dispose() {
104
+ this.unsubscribe(), this.actions.dispose();
105
+ }
106
+ }
107
+ class K {
108
+ constructor(t, e, s = !0) {
109
+ this.platform = t, this.target = e, this.clearOnDispose = s, this.removes = [], this.actions = new P(this.platform, this.target);
110
+ }
111
+ writeProperties(t, e) {
112
+ this.removes.push(
113
+ this.platform.write({
114
+ options: e,
115
+ attributes: { properties: t },
116
+ target: this.target,
117
+ removable: this.clearOnDispose
118
+ })
119
+ );
120
+ }
121
+ writeContext(t, e) {
122
+ this.removes.push(
123
+ this.platform.write({
124
+ options: e,
125
+ attributes: { context: t },
126
+ target: this.target,
127
+ removable: this.clearOnDispose
128
+ })
129
+ );
130
+ }
131
+ writeLayout(t, e) {
132
+ this.removes.push(
133
+ this.platform.write({
134
+ options: e,
135
+ attributes: { layout: t },
136
+ target: this.target,
137
+ removable: this.clearOnDispose
138
+ })
139
+ );
140
+ }
141
+ dispose() {
142
+ this.removes.forEach((t) => {
143
+ t();
144
+ }), this.actions.dispose();
145
+ }
146
+ }
147
+ const U = (n, t, e) => {
148
+ const s = n.concat(), i = (c, o, a) => {
149
+ let u = !0;
150
+ if (s.length) {
151
+ const h = s.shift(), r = (p, l) => (u = !1, i(
152
+ p,
153
+ Object.assign({}, o, l),
154
+ a
155
+ ));
156
+ return Promise.resolve(h(c, r, a)).then(
157
+ (p) => ({
158
+ ...p,
159
+ cancelled: u
160
+ })
161
+ );
162
+ }
163
+ return Promise.resolve({ data: c, cancelled: !1, options: o });
164
+ };
165
+ return i(t, {}, e);
166
+ };
167
+ class P {
168
+ constructor(t, e, s) {
169
+ this.platform = t, this.target = e, this.ns = s, this.subscriptions = [], this.create = this.create.bind(this);
170
+ }
171
+ create(t, e = () => {
172
+ }) {
173
+ const s = {
174
+ key: t,
175
+ fn: e,
176
+ target: this.target,
177
+ ns: this.ns
178
+ };
179
+ this.platform.actionsState.handlers.push(s);
180
+ const i = () => {
181
+ const c = this.platform.actionsState.handlers.indexOf(s);
182
+ c > -1 && this.platform.actionsState.handlers.splice(c, 1);
183
+ };
184
+ return this.subscriptions.push(i), i;
185
+ }
186
+ dispatch(t, e) {
187
+ const s = this.platform.nodes.all.concat(
188
+ this.platform.nodes.detached
189
+ ), i = {}, c = this.platform.actionsState.handlers.filter(
190
+ (o) => o.key === t && (!o.ns || !this.ns || o.ns === this.ns)
191
+ );
192
+ return Promise.all(
193
+ c.map((o) => {
194
+ const a = s.filter(
195
+ (h) => o.target.match(h) && this.target.match(h)
196
+ ), u = this.platform.actionsState.watchers.filter((h) => h.key === t && (!h.ns || !this.ns || h.ns === this.ns) && a.some(
197
+ (r) => h.target.match(r)
198
+ )).map((h) => h.fn);
199
+ return Promise.all(
200
+ a.map((h) => {
201
+ const r = new S(
202
+ this.platform,
203
+ h,
204
+ this.ns
205
+ );
206
+ return U(u, e, r).then(
207
+ (p) => {
208
+ const { data: l = {}, options: d, cancelled: b } = p;
209
+ return Promise.resolve(
210
+ b ? {} : o.fn(l, d, r)
211
+ ).then((g) => {
212
+ i[h.id] = g;
213
+ });
214
+ }
215
+ );
216
+ })
217
+ );
218
+ })
219
+ ).then(() => i);
220
+ }
221
+ watch(t, e) {
222
+ let s = t, i = this.ns;
223
+ const c = t.split(".");
224
+ c.length > 1 && (i = c[0], s = c.splice(1).join("."));
225
+ const o = {
226
+ fn: e,
227
+ target: this.target,
228
+ key: s,
229
+ ns: i
230
+ };
231
+ this.platform.actionsState.watchers.push(o);
232
+ const a = () => {
233
+ const u = this.platform.actionsState.watchers.indexOf(o);
234
+ u > -1 && this.platform.actionsState.watchers.splice(u, 1);
235
+ };
236
+ return this.subscriptions.push(a), a;
237
+ }
238
+ dispose() {
239
+ this.subscriptions.forEach((t) => t());
240
+ }
241
+ }
242
+ const ut = V((n) => {
243
+ n.createCommand("components", (t) => (e) => {
244
+ t.events.subscribeOnce(
245
+ "components:platform-created",
246
+ (s, { platform: i }) => {
247
+ e.handlers && e.handlers.forEach(([c, o]) => {
248
+ i.addComponentHandler(c, o);
249
+ });
250
+ }
251
+ );
252
+ });
253
+ });
254
+ class I {
255
+ constructor(t, e) {
256
+ this.events = t, this.tags = [], this.children = {}, this.changesets = [], this.mountCount = 0, this.id = E(), this.type = e, this.attributes = {
257
+ context: {},
258
+ properties: {},
259
+ layout: {},
260
+ tags: []
261
+ }, this.writeLayout({ size: "full", indent: 0 });
262
+ }
263
+ mount(t, e) {
264
+ let s = t.get("mounted-nodes");
265
+ return s || (s = /* @__PURE__ */ new Map(), t.register("mounted-nodes", s)), s.has(this) ? (process.env.NODE_ENV !== "production" && O.error(
266
+ "Trying to mount an already mounted component node.",
267
+ this
268
+ ), () => {
269
+ }) : (this.events.dispatch("components:node-mounted", { node: this }), this.mountCount === 0 && (this.mountCount = this.mountCount + 1, this.events.dispatch("components:node-enter", { node: this })), () => {
270
+ s.delete(this), this.events.dispatch("components:node-unmounted", { node: this }), this.mountCount = this.mountCount - 1, this.mountCount === 0 && this.events.dispatch("components:node-exit", { node: this });
271
+ });
272
+ }
273
+ appendChild(t, e = "default") {
274
+ if (t.parent) {
275
+ if (t.parent === this)
276
+ return;
277
+ t.parent.removeChild(t);
278
+ }
279
+ t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].push(t), this.events.dispatch("components:node-appended", { node: t });
280
+ }
281
+ prependChild(t, e = "default") {
282
+ if (t.parent) {
283
+ if (t.parent === this)
284
+ return;
285
+ t.parent.removeChild(t);
286
+ }
287
+ t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].unshift(t), this.events.dispatch("components:node-appended", { node: t });
288
+ }
289
+ touchProperties(t, e = {}, s) {
290
+ const c = [{ properties: t }, e];
291
+ return this.changesets.push(c), this.events.dispatch("components:set-properties", { node: this }), () => {
292
+ if (s) {
293
+ const o = this.changesets.indexOf(c);
294
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-properties", { node: this }));
295
+ }
296
+ };
297
+ }
298
+ writeProperties(t, e = {}, s) {
299
+ const c = [{ properties: t }, e];
300
+ return this.changesets.push(c), this.events.dispatch("components:set-properties", { node: this }), () => {
301
+ if (s) {
302
+ const o = this.changesets.indexOf(c);
303
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-properties", { node: this }));
304
+ }
305
+ };
306
+ }
307
+ writeLayout(t, e = {}, s) {
308
+ const c = [{ layout: t }, e];
309
+ return this.changesets.push(c), this.events.dispatch("components:set-layout", { node: this }), () => {
310
+ if (!s)
311
+ return;
312
+ const o = this.changesets.indexOf(c);
313
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-layout", { node: this }));
314
+ };
315
+ }
316
+ writeContext(t, e = {}, s) {
317
+ const c = [{ context: t }, e];
318
+ return this.changesets.push(c), this.events.dispatch("components:set-context", { node: this }), () => {
319
+ if (!s)
320
+ return;
321
+ const o = this.changesets.indexOf(c);
322
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-context", { node: this }));
323
+ };
324
+ }
325
+ getChildren(t = "default") {
326
+ const e = this.children[t] || [];
327
+ return e.reduce((s, i, c) => {
328
+ const { order: o = c } = i.attributes.layout;
329
+ return s[o] ? s.splice(o, 0, i) : s[o] = i, s;
330
+ }, Array(e.length));
331
+ }
332
+ remove() {
333
+ this.parent && this.parent.removeChild(this);
334
+ }
335
+ removeChild(t) {
336
+ Object.keys(this.children).forEach((e) => {
337
+ const s = this.children[e], i = s.indexOf(t);
338
+ i > -1 && (s.splice(i, 1), this.events.dispatch("components:node-removed", {
339
+ node: t,
340
+ parentNode: this
341
+ }));
342
+ }), delete t.parent;
343
+ }
344
+ }
345
+ const D = (n, t, e) => {
346
+ for (let s = 0, i = n.length; s < i && e(n[s]) !== !0; s++) {
347
+ const c = t[n[s].id] || "default", o = n[s].getChildren(c);
348
+ D(o, t, e);
349
+ }
350
+ }, k = (n, t, e) => {
351
+ if (e(n) !== !0) {
352
+ const s = t[n.id] || "default", i = n.children[s];
353
+ D(i, t, e);
354
+ }
355
+ }, x = (n, t) => {
356
+ const e = [];
357
+ return k(n, t, (s) => {
358
+ e.push(s);
359
+ }), e;
360
+ }, W = (n, t, e) => {
361
+ let s;
362
+ return k(n, t, (i) => {
363
+ if (e(i))
364
+ return s = i, !0;
365
+ }), s;
366
+ };
367
+ class Y {
368
+ constructor(t, e, s) {
369
+ this.root = t, this.switches = e, this.all = [], this.visible = [], this.detached = [], s.subscribe(
370
+ "components:node-appended",
371
+ (i, c) => {
372
+ this.all.push(c.node), this.visible = x(t, e);
373
+ }
374
+ ), s.subscribe(
375
+ "components:node-removed",
376
+ (i, c) => {
377
+ let o = this.all.indexOf(c.node);
378
+ o > -1 && this.all.splice(o, 1), o = this.visible.indexOf(c.node), o > -1 && this.visible.splice(o, 1), this.visible = x(t, e);
379
+ }
380
+ ), s.subscribe(
381
+ "components:node-switched",
382
+ (i, c) => {
383
+ this.visible = x(t, e);
384
+ }
385
+ );
386
+ }
387
+ query(t = {}) {
388
+ const e = [];
389
+ return k(this.root, this.switches, (s) => {
390
+ Object.keys(t).every((c) => t[c] === s[c]) && e.push(s);
391
+ }), e;
392
+ }
393
+ get(t) {
394
+ return W(this.root, this.switches, (e) => e.id === t) || this.detached.find((e) => e.id === t);
395
+ }
396
+ }
397
+ class J {
398
+ constructor() {
399
+ this.handlers = /* @__PURE__ */ new Map();
400
+ }
401
+ add(t, e) {
402
+ this.handlers.set(t, e);
403
+ }
404
+ get(t) {
405
+ return this.handlers.get(t);
406
+ }
407
+ }
408
+ const X = (n) => {
409
+ let t = n, e = 0;
410
+ for (; t.parent; )
411
+ e = e + 1, t = t.parent;
412
+ return e;
413
+ }, Z = (n) => n.map(
414
+ ([e, s]) => [X(e), e, s]
415
+ ).sort(([e], [s]) => e - s).map(([, e, s]) => [e, s]), w = (n) => n instanceof Date ? !1 : n && typeof n == "object" && !Array.isArray(n), v = (n, ...t) => {
416
+ if (!t.length)
417
+ return n;
418
+ const e = t.shift();
419
+ if (w(n) && w(e))
420
+ for (const s in e)
421
+ w(e[s]) ? (n[s] || Object.assign(n, { [s]: {} }), v(n[s], e[s])) : Object.assign(n, { [s]: e[s] });
422
+ return v(n, ...t);
423
+ }, tt = (n, t) => !n || n === "all" ? !0 : n.some((e) => t.indexOf(e) > -1), et = (n, t) => {
424
+ let e = [], s = [], i;
425
+ const c = () => {
426
+ process.env.NODE_ENV !== "production" && console.time("state-processor.flush");
427
+ const a = /* @__PURE__ */ new Map(), u = Z(
428
+ e.map((r, p) => [r, s[p]])
429
+ ), h = (r, p) => {
430
+ var T;
431
+ const l = a.get(r) || {}, d = p.context && !l.context, b = p.properties && !l.properties, g = p.layout && !l.layout;
432
+ a.set(r, {
433
+ context: l.context || d,
434
+ properties: l.properties || b,
435
+ layout: l.layout || g
436
+ }), b && (r.attributes.properties = {}), g && (r.attributes.layout = {}), d && (r.attributes.context = v(
437
+ {},
438
+ (T = r.parent) == null ? void 0 : T.attributes.context
439
+ ));
440
+ const $ = [], R = [], A = [];
441
+ if (r.changesets.forEach((f) => {
442
+ const [m, y] = f;
443
+ tt(y.breakpoints, n.breakpoints) && (b && (typeof m.properties == "function" ? $.push(
444
+ m.properties
445
+ ) : v(r.attributes.properties, m.properties)), g && (typeof m.layout == "function" ? R.push(m.layout) : v(r.attributes.layout, m.layout)), d && (typeof m.context == "function" ? A.push(
446
+ m.context
447
+ ) : v(r.attributes.context, m.context)));
448
+ }), $.forEach((f) => {
449
+ v(
450
+ r.attributes.properties,
451
+ f(r.attributes.properties)
452
+ );
453
+ }), R.forEach((f) => {
454
+ v(r.attributes.layout, f(r.attributes.layout));
455
+ }), A.forEach((f) => {
456
+ v(r.attributes.context, f(r.attributes.context));
457
+ }), d || p.recursive) {
458
+ const f = n.getBranch(r), m = p.recursive ? p : {
459
+ context: !!d
460
+ };
461
+ r.getChildren(f).forEach((y) => {
462
+ h(y, m);
463
+ });
464
+ }
465
+ };
466
+ process.env.NODE_ENV !== "production" && console.timeEnd("state-processor.flush"), u.forEach(([r, p]) => {
467
+ h(r, p);
468
+ }), e = [], s = [], t(a);
469
+ }, o = () => {
470
+ clearTimeout(i), i = setTimeout(c, 0);
471
+ };
472
+ return (a, u) => {
473
+ const h = e.indexOf(a);
474
+ if (h > -1) {
475
+ const r = s[h];
476
+ return u.context && (r.context = !0), u.properties && (r.properties = !0), u.layout && (r.layout = !0), u.recursive && (r.recursive = !0), o();
477
+ }
478
+ return e.push(a), s.push(u), o();
479
+ };
480
+ };
481
+ class st {
482
+ constructor(t, e = {}) {
483
+ this.providers = e, this.breakpoints = [], this.actionsState = { handlers: [], watchers: [] }, this.switches = {}, this.changesets = [], this.subscriptions = [], this.customComponentHandler = new J(), this.events = t.events.createChild(this);
484
+ const s = new I(this.events, "root");
485
+ s.name = `root-${t.name}`, this.nodes = new Y(s, this.switches, this.events);
486
+ const i = this.processNode = et(
487
+ this,
488
+ (c) => {
489
+ const o = Array.from(c.keys());
490
+ process.env.NODE_ENV !== "production" && console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
491
+ ${o.map(
492
+ (a) => `${a.name || "<no name>"} (${a.id})
493
+ `
494
+ )}`), o.forEach((a) => {
495
+ const u = c.get(a);
496
+ a.parent && a.parent.type === "root" && this.events.dispatch("components:root-children-changed", { node: a }), u != null && u.context && this.events.dispatch("components:context-changed", { node: a }), u != null && u.properties && this.events.dispatch("components:properties-changed", { node: a }), u != null && u.layout && this.events.dispatch("components:layout-changed", { node: a });
497
+ }), this.events.dispatch(
498
+ "components:component-model-initialized",
499
+ {},
500
+ { bubbles: !0 }
501
+ );
502
+ }
503
+ );
504
+ Promise.all(
505
+ Object.keys(e).map((c) => e[c].load(this))
506
+ ), this.subscriptions.push(
507
+ this.events.subscribe(
508
+ "components:node-appended",
509
+ (c, o) => {
510
+ const { node: a } = o;
511
+ this.changesets.forEach((u) => {
512
+ const { changeset: h, target: r, removes: p } = u, [l, d] = h;
513
+ r.match(o.node) && (l.properties && p.push(a.writeProperties(l.properties, d)), l.context && p.push(a.writeContext(l.context, d)), l.layout && p.push(a.writeLayout(l.layout, d)));
514
+ });
515
+ }
516
+ )
517
+ ), this.subscriptions.push(
518
+ this.events.subscribe(
519
+ "components:node-appended",
520
+ (c, o) => {
521
+ i(o.node, { properties: !0, context: !0 });
522
+ }
523
+ )
524
+ ), this.subscriptions.push(
525
+ this.events.subscribe(
526
+ "components:set-properties",
527
+ (c, o) => {
528
+ i(o.node, { properties: !0 });
529
+ }
530
+ )
531
+ ), this.subscriptions.push(
532
+ this.events.subscribe(
533
+ "components:set-context",
534
+ (c, o) => {
535
+ i(o.node, { properties: !0, context: !0 });
536
+ }
537
+ )
538
+ ), this.subscriptions.push(
539
+ this.events.subscribe(
540
+ "components:set-indent",
541
+ (c, o) => {
542
+ i(o.node, { layout: !0 });
543
+ }
544
+ )
545
+ ), this.subscriptions.push(
546
+ this.events.subscribe(
547
+ "components:set-layout",
548
+ (c, o) => {
549
+ i(o.node, { layout: !0 });
550
+ }
551
+ )
552
+ ), this.subscriptions.push(
553
+ this.events.subscribe(
554
+ "components:node-switched",
555
+ (c, { node: o, branch: a }) => {
556
+ i(o, {
557
+ layout: !0,
558
+ recursive: !0,
559
+ properties: !0,
560
+ context: !0
561
+ });
562
+ }
563
+ )
564
+ ), this.subscriptions.push(
565
+ this.events.subscribe(
566
+ "components:node-removed",
567
+ (c, { parentNode: o }) => {
568
+ i(o, { properties: !0 });
569
+ }
570
+ )
571
+ ), this.events.parent && this.events.parent.dispatch("components:platform-created", {
572
+ platform: this
573
+ });
574
+ }
575
+ static getInstance(t) {
576
+ return t.getAsync("components");
577
+ }
578
+ addBreakpoint(t) {
579
+ this.breakpoints.indexOf(t) === -1 && (this.breakpoints.push(t), this.processNode(this.nodes.root, {
580
+ context: !0,
581
+ properties: !0,
582
+ layout: !0,
583
+ recursive: !0
584
+ }));
585
+ }
586
+ removeBreakpoint(t) {
587
+ const e = this.breakpoints.indexOf(t);
588
+ e > -1 && (this.breakpoints.splice(e, 1), this.processNode(this.nodes.root, {
589
+ context: !0,
590
+ properties: !0,
591
+ layout: !0,
592
+ recursive: !0
593
+ }));
594
+ }
595
+ setSwitch(t, e) {
596
+ this.switches[t.id] = e, this.events.dispatch("components:node-switched", { node: t, branch: e });
597
+ }
598
+ getBranch(t) {
599
+ return this.switches[t.id];
600
+ }
601
+ /**
602
+ * Creates a `ComponentNode` of the specified type.
603
+ * @param type Type of node.
604
+ */
605
+ createNode(t, e = {}) {
606
+ const s = new I(this.events, t);
607
+ return e.detached && this.nodes.detached.push(s), s;
608
+ }
609
+ components() {
610
+ return new N(this);
611
+ }
612
+ actions(t, e) {
613
+ return new P(this, t, e);
614
+ }
615
+ write(t) {
616
+ const {
617
+ provider: e,
618
+ target: s,
619
+ attributes: i,
620
+ options: c = {},
621
+ removable: o
622
+ } = t, a = t.key || E(), h = { changeset: [i, c], target: s, removes: [] };
623
+ if (e) {
624
+ const r = this.providers[e];
625
+ r.write(a, s, i, c), h.removes.push(() => {
626
+ r.remove(a);
627
+ });
628
+ }
629
+ return this.changesets.push(h), this.nodes.all.forEach((r) => {
630
+ if (s.match(r)) {
631
+ let p = () => {
632
+ };
633
+ i.properties && (p = r.writeProperties(
634
+ i.properties,
635
+ c,
636
+ o
637
+ )), i.context && (p = r.writeContext(i.context, c, o)), i.layout && (p = r.writeContext(i.layout, c, o)), h.removes.push(p);
638
+ }
639
+ }), () => {
640
+ if (o) {
641
+ h.removes.forEach((p) => p());
642
+ const r = this.changesets.indexOf(h);
643
+ r > -1 && this.changesets.splice(r, 1);
644
+ }
645
+ };
646
+ }
647
+ addComponentHandler(t, e) {
648
+ this.customComponentHandler.add(t, e);
649
+ }
650
+ getComponentHandler(t) {
651
+ return this.customComponentHandler.get(t);
652
+ }
653
+ dispose() {
654
+ this.subscriptions.forEach((t) => t());
655
+ }
656
+ }
657
+ const nt = (n) => {
658
+ if (Array.isArray(n)) {
659
+ const [t, ...e] = n;
660
+ return {
661
+ definitionId: t,
662
+ overrides: e
663
+ };
664
+ }
665
+ return {
666
+ definitionId: n,
667
+ overrides: []
668
+ };
669
+ }, C = (n, t, e, s, i, c) => {
670
+ e.forEach((o) => {
671
+ const a = nt(o), u = s[a.definitionId];
672
+ if (a.definitionId === "view") {
673
+ const h = n.createNode("view");
674
+ h.name = "view", Object.keys(i).forEach((r) => {
675
+ const p = i[r];
676
+ C(
677
+ n,
678
+ h,
679
+ [p.entry],
680
+ s,
681
+ i,
682
+ r
683
+ );
684
+ }), t.appendChild(h), a.overrides.forEach((r) => {
685
+ r.properties && h.writeProperties(r.properties, {
686
+ breakpoints: r.breakpoints
687
+ }), r.context && h.writeContext(r.context, {
688
+ breakpoints: r.breakpoints
689
+ }), r.layout && h.writeLayout(r.layout, {
690
+ breakpoints: r.breakpoints
691
+ });
692
+ });
693
+ } else if (n.getComponentHandler(u.type)) {
694
+ const h = n.getComponentHandler(u.type);
695
+ h && h(a, {
696
+ platform: n,
697
+ node: t,
698
+ references: e,
699
+ definitions: s,
700
+ views: i,
701
+ branch: c
702
+ });
703
+ } else {
704
+ const h = s[a.definitionId];
705
+ if (process.env.NODE_ENV !== "production" && !h) {
706
+ O.error(
707
+ `No definition found for component type '${a.definitionId}'.`
708
+ );
709
+ return;
710
+ }
711
+ const r = n.createNode(h.type);
712
+ r.name = a.definitionId, r.tags = h.tags || [], h.properties && r.writeProperties(h.properties), h.context && r.writeContext(h.context), h.layout && r.writeLayout(h.layout), t.appendChild(r, c), a.overrides.forEach((p) => {
713
+ const l = { breakpoints: p.breakpoints };
714
+ p.properties && r.writeProperties(p.properties, l), p.context && r.writeContext(p.context, l), p.layout && r.writeLayout(p.layout, l);
715
+ }), h.children && C(
716
+ n,
717
+ r,
718
+ h.children,
719
+ s,
720
+ i
721
+ );
722
+ }
723
+ });
724
+ }, lt = (n, t) => {
725
+ const { entry: e, components: s, breakpoints: i, views: c } = t, o = [];
726
+ return Object.keys(i).forEach((a) => {
727
+ const u = i[a], h = window.matchMedia(u);
728
+ h.matches && n.breakpoints.push(a);
729
+ const r = (p) => {
730
+ p.matches ? n.addBreakpoint(a) : n.removeBreakpoint(a);
731
+ };
732
+ h.addListener(r), o.push(() => h.removeListener(r));
733
+ }), C(n, n.nodes.root, [e], s, c), () => o.forEach((a) => {
734
+ a();
735
+ });
736
+ }, dt = (n, t) => ({
737
+ id: n.id,
738
+ type: n.type,
739
+ name: n.name,
740
+ branch: t || "default"
741
+ }), mt = (n, t, e, s = E(), i = {}) => n.getAsync("components").then((c) => {
742
+ let o;
743
+ if (typeof t == "string") {
744
+ const h = new N(c);
745
+ h.ofType(t), o = h;
746
+ } else
747
+ o = t;
748
+ const a = {}, u = (h) => {
749
+ const r = a[h.id];
750
+ return r ? Promise.resolve(r.controller) : st.getInstance(n).then((p) => new S(p, h, s));
751
+ };
752
+ c.events.subscribe(
753
+ "components:node-enter",
754
+ (h, { node: r }) => {
755
+ o.match(r) && u(r).then((p) => {
756
+ Promise.resolve(e(p)).then((l) => {
757
+ a[r.id] = {
758
+ dispose: l,
759
+ controller: p
760
+ };
761
+ });
762
+ });
763
+ }
764
+ ), c.events.subscribe(
765
+ "components:node-exit",
766
+ (h, { node: r }) => {
767
+ const p = a[r.id];
768
+ p && (p.dispose && p.dispose(), i.reuseController || (p.controller.dispose(), delete a[r.id]));
769
+ }
770
+ );
771
+ });
772
+ class ft {
773
+ constructor(t) {
774
+ this.aliases = /* @__PURE__ */ new Map(), this.components = /* @__PURE__ */ new Map(), this.logger = new O();
775
+ const { events: e } = t.get("$widget");
776
+ this.events = e;
777
+ }
778
+ getComponent(t) {
779
+ const e = this.aliases.get(t), s = this.components.get(e || t) || null;
780
+ return process.env.NODE_ENV !== "production" && (s || this.logger.warn(
781
+ e || t,
782
+ `Unable to resolve component: "${e || t}". You most likely forgot to register the required plugin for: ${e || t}.`
783
+ )), s;
784
+ }
785
+ registerComponent(t, e) {
786
+ return this.components.set(t, e), this.events.dispatch("component-resolver:resolve", t), () => {
787
+ this.components.delete(t);
788
+ };
789
+ }
790
+ registerResolver(t, e) {
791
+ return this.events.subscribe(
792
+ "component-resolver:resolve",
793
+ (s, i) => {
794
+ if (i === t) {
795
+ const c = this.getComponent(t);
796
+ e(c);
797
+ }
798
+ }
799
+ );
800
+ }
801
+ registerAlias(t, e) {
802
+ return this.aliases.set(t, e), this.events.dispatch("component-resolver:resolve", t), () => {
803
+ this.aliases.delete(t);
804
+ };
805
+ }
806
+ }
807
+ const it = "#____version____#", _ = class L extends q {
808
+ constructor(t, e = []) {
809
+ super(t, e, {
810
+ transformPluginSettings: (s, i, c) => {
811
+ const o = c.get("$settings");
812
+ return {
813
+ ...o.plugins && i ? o.plugins[i] || {} : {},
814
+ ...s
815
+ };
816
+ }
817
+ });
818
+ }
819
+ createImplementation(t) {
820
+ const e = super.createImplementation(t);
821
+ return e.bindings = t.bindings, e;
822
+ }
823
+ /**
824
+ * Performs navigation for widgets matching the specified selector by invoking a
825
+ * 'navigate' command.
826
+ * @param selector Widget selector matching the widget(s) to perform navigation on.
827
+ * @param route Route name.
828
+ * @param params Route params.
829
+ */
830
+ navigate(t, e, s) {
831
+ this.widgets.query(t).forEach((i) => i.invoke("navigate", { route: e, params: s }));
832
+ }
833
+ /**
834
+ * Creates a runtime based on provided configuration.
835
+ * @param configuration Runtime configuration.
836
+ */
837
+ static create(t = {}) {
838
+ const e = [B].concat(
839
+ t.configurationApiExtensions || []
840
+ );
841
+ return new L("humany", e);
842
+ }
843
+ /**
844
+ * Creates a widget runtime based on provided configuration and retains configuration handlers
845
+ * registered on global context. Use this factory to fully support the default embed script.
846
+ * Will return any existing widget runtime if available.
847
+ * @param configuration Runtime configuration.
848
+ * @param global Object to read configuration handlers from (default: window).
849
+ */
850
+ static createFromGlobal(t, e = {}) {
851
+ if (this.isRuntime(t))
852
+ return t.patch(e), t;
853
+ const s = [], i = t && t._c;
854
+ i && i.forEach(
855
+ (o) => s.push(o)
856
+ );
857
+ const c = this.create(e);
858
+ return c.container.register("$runtimecfg", s), c;
859
+ }
860
+ /**
861
+ * Determines whether the specified object is a valid widget runtime.
862
+ * @param obj Object to compare.
863
+ */
864
+ static isRuntime(t) {
865
+ return !!(t && typeof t == "object" && t.container && typeof t.container.get == "function" && t.container.get("$environment") === t && t.container.owner === t);
866
+ }
867
+ };
868
+ _.version = `${it} (${j})`;
869
+ let vt = _;
870
+ class bt extends z {
871
+ constructor() {
872
+ super(...arguments), this.bindings = [];
873
+ }
874
+ }
875
+ class gt extends Q {
876
+ constructor(t, e) {
877
+ super(t, e);
878
+ }
879
+ }
880
+ var ot = /* @__PURE__ */ ((n) => (n.open = "open", n.closed = "closed", n.hidden = "hidden", n))(ot || {});
881
+ class yt extends F {
882
+ constructor(t) {
883
+ super(t);
884
+ }
885
+ }
886
+ export {
887
+ at as ActionResolver,
888
+ P as ActionsController,
889
+ I as ComponentNode,
890
+ S as ComponentNodeController,
891
+ st as ComponentPlatform,
892
+ N as ComponentQuery,
893
+ ft as ComponentResolver,
894
+ vt as Environment,
895
+ bt as Implementation,
896
+ gt as Plugin,
897
+ ot as WidgetRenderState,
898
+ yt as WidgetType,
899
+ dt as asDescriptor,
900
+ pt as bootstrap,
901
+ ut as componentConfigurationApi,
902
+ C as createChildren,
903
+ lt as createComponentModel,
904
+ G as createEventSubscriber,
905
+ mt as extendComponent,
906
+ W as findComponent,
907
+ x as findVisibleComponents,
908
+ k as traverseComponents,
909
+ it as version
910
+ };