forgeframe 0.0.1 → 0.0.3

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.
@@ -33,7 +33,7 @@ const p = {
33
33
  BASE64: "base64",
34
34
  /** Dot notation for nested objects (e.g., "a.b.c=value") */
35
35
  DOTIFY: "dotify"
36
- }, D = {
36
+ }, T = {
37
37
  /** Request message expecting a response */
38
38
  REQUEST: "request",
39
39
  /** Response to a previous request */
@@ -63,8 +63,14 @@ const p = {
63
63
  CONSUMER_EXPORT: "forgeframe_consumer_export",
64
64
  /** Get sibling components request */
65
65
  GET_SIBLINGS: "forgeframe_get_siblings"
66
- }, N = "__forgeframe__", pe = "0.0.1";
67
- class me {
66
+ }, F = "__forgeframe__", ye = (() => {
67
+ if ("0.0.3".trim().length === 0)
68
+ throw new Error(
69
+ "ForgeFrame VERSION injection is missing. Configure __FORGEFRAME_VERSION__ in build/test tooling."
70
+ );
71
+ return "0.0.3";
72
+ })();
73
+ class we {
68
74
  /**
69
75
  * Internal storage for event listeners mapped by event name.
70
76
  * @internal
@@ -87,8 +93,8 @@ class me {
87
93
  *
88
94
  * @public
89
95
  */
90
- on(e, s) {
91
- return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(s), () => this.off(e, s);
96
+ on(e, t) {
97
+ return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), () => this.off(e, t);
92
98
  }
93
99
  /**
94
100
  * Subscribes a handler to an event that will automatically unsubscribe after the first invocation.
@@ -111,8 +117,8 @@ class me {
111
117
  *
112
118
  * @public
113
119
  */
114
- once(e, s) {
115
- const n = (i) => (this.off(e, n), s(i));
120
+ once(e, t) {
121
+ const n = (i) => (this.off(e, n), t(i));
116
122
  return this.on(e, n);
117
123
  }
118
124
  /**
@@ -134,12 +140,12 @@ class me {
134
140
  *
135
141
  * @public
136
142
  */
137
- emit(e, s) {
143
+ emit(e, t) {
138
144
  const n = this.listeners.get(e);
139
145
  if (n)
140
146
  for (const i of n)
141
147
  try {
142
- const r = i(s);
148
+ const r = i(t);
143
149
  r && typeof r == "object" && "catch" in r && typeof r.catch == "function" && r.catch((o) => {
144
150
  console.error(`Error in async event handler for "${e}":`, o);
145
151
  });
@@ -168,13 +174,13 @@ class me {
168
174
  *
169
175
  * @public
170
176
  */
171
- off(e, s) {
172
- if (!s) {
177
+ off(e, t) {
178
+ if (!t) {
173
179
  this.listeners.delete(e);
174
180
  return;
175
181
  }
176
182
  const n = this.listeners.get(e);
177
- n && (n.delete(s), n.size === 0 && this.listeners.delete(e));
183
+ n && (n.delete(t), n.size === 0 && this.listeners.delete(e));
178
184
  }
179
185
  /**
180
186
  * Removes all event listeners from the emitter.
@@ -215,14 +221,14 @@ class me {
215
221
  return this.listeners.get(e)?.size ?? 0;
216
222
  }
217
223
  }
218
- function Ie() {
219
- const t = Date.now().toString(36), e = Math.random().toString(36).slice(2, 11);
220
- return `${t}_${e}`;
224
+ function Fe() {
225
+ const s = Date.now().toString(36), e = Math.random().toString(36).slice(2, 11);
226
+ return `${s}_${e}`;
221
227
  }
222
- function W() {
228
+ function z() {
223
229
  return Math.random().toString(36).slice(2, 11);
224
230
  }
225
- class De {
231
+ class Ne {
226
232
  /**
227
233
  * Array of registered cleanup tasks awaiting execution.
228
234
  * @internal
@@ -260,8 +266,8 @@ class De {
260
266
  if (this.cleaned) {
261
267
  try {
262
268
  e();
263
- } catch (s) {
264
- console.error("Error in cleanup task:", s);
269
+ } catch (t) {
270
+ console.error("Error in cleanup task:", t);
265
271
  }
266
272
  return;
267
273
  }
@@ -293,9 +299,9 @@ class De {
293
299
  this.cleaned = !0;
294
300
  const e = this.tasks.reverse();
295
301
  this.tasks = [];
296
- for (const s of e)
302
+ for (const t of e)
297
303
  try {
298
- await s();
304
+ await t();
299
305
  } catch (n) {
300
306
  console.error("Error in cleanup task:", n);
301
307
  }
@@ -340,60 +346,60 @@ class De {
340
346
  this.tasks = [], this.cleaned = !1;
341
347
  }
342
348
  }
343
- function ge() {
344
- let t, e;
349
+ function _e() {
350
+ let s, e;
345
351
  return { promise: new Promise((n, i) => {
346
- t = n, e = i;
347
- }), resolve: t, reject: e };
352
+ s = n, e = i;
353
+ }), resolve: s, reject: e };
348
354
  }
349
- function Ne(t, e, s = "Operation timed out") {
355
+ function ke(s, e, t = "Operation timed out") {
350
356
  return new Promise((n, i) => {
351
357
  const r = setTimeout(() => {
352
- i(new Error(`${s} (${e}ms)`));
358
+ i(new Error(`${t} (${e}ms)`));
353
359
  }, e);
354
- t.then((o) => {
360
+ s.then((o) => {
355
361
  clearTimeout(r), n(o);
356
362
  }).catch((o) => {
357
363
  clearTimeout(r), i(o);
358
364
  });
359
365
  });
360
366
  }
361
- const z = "forgeframe:";
362
- function A(t) {
363
- return z + JSON.stringify(t);
367
+ const j = "forgeframe:";
368
+ function M(s) {
369
+ return j + JSON.stringify(s);
364
370
  }
365
- function Te(t) {
366
- if (typeof t != "string" || !t.startsWith(z)) return null;
371
+ function $e(s) {
372
+ if (typeof s != "string" || !s.startsWith(j)) return null;
367
373
  try {
368
- const e = t.slice(z.length), s = JSON.parse(e);
369
- return !s.id || !s.type || !s.name || !s.source ? null : s;
374
+ const e = s.slice(j.length), t = JSON.parse(e);
375
+ return !t.id || !t.type || !t.name || !t.source ? null : t;
370
376
  } catch {
371
377
  return null;
372
378
  }
373
379
  }
374
- function re(t, e, s, n) {
380
+ function ce(s, e, t, n) {
375
381
  return {
376
- id: t,
377
- type: D.REQUEST,
382
+ id: s,
383
+ type: T.REQUEST,
378
384
  name: e,
379
- data: s,
385
+ data: t,
380
386
  source: n
381
387
  };
382
388
  }
383
- function ke(t, e, s, n) {
389
+ function Le(s, e, t, n) {
384
390
  return {
385
- id: t,
386
- type: D.RESPONSE,
391
+ id: s,
392
+ type: T.RESPONSE,
387
393
  name: "response",
388
394
  data: e,
389
- source: s,
395
+ source: t,
390
396
  error: n ? {
391
397
  message: n.message,
392
398
  stack: n.stack
393
399
  } : void 0
394
400
  };
395
401
  }
396
- class ye {
402
+ class Ee {
397
403
  /**
398
404
  * Creates a new Messenger instance.
399
405
  *
@@ -402,8 +408,8 @@ class ye {
402
408
  * @param domain - The origin domain of this messenger
403
409
  * @param trustedDomains - Optional domains to trust for incoming messages
404
410
  */
405
- constructor(e, s = window, n = window.location.origin, i) {
406
- this.uid = e, this.win = s, this.domain = n, this.allowedOrigins.add(n), i && this.addTrustedDomain(i), this.setupListener();
411
+ constructor(e, t = window, n = window.location.origin, i) {
412
+ this.uid = e, this.win = t, this.domain = n, this.allowedOrigins.add(n), i && this.addTrustedDomain(i), this.setupListener();
407
413
  }
408
414
  /** @internal */
409
415
  pending = /* @__PURE__ */ new Map();
@@ -424,10 +430,21 @@ class ye {
424
430
  */
425
431
  addTrustedDomain(e) {
426
432
  if (Array.isArray(e))
427
- for (const s of e)
428
- this.allowedOrigins.add(s);
433
+ for (const t of e)
434
+ this.allowedOrigins.add(t);
429
435
  else e instanceof RegExp ? this.allowedOriginPatterns.push(e) : this.allowedOrigins.add(e);
430
436
  }
437
+ /**
438
+ * Removes a trusted domain from this messenger.
439
+ *
440
+ * @param domain - Domain pattern to remove (string, RegExp, or array)
441
+ */
442
+ removeTrustedDomain(e) {
443
+ if (Array.isArray(e))
444
+ for (const t of e)
445
+ this.allowedOrigins.delete(t);
446
+ else e instanceof RegExp ? this.allowedOriginPatterns = this.allowedOriginPatterns.filter((t) => t !== e) : this.allowedOrigins.delete(e);
447
+ }
431
448
  /**
432
449
  * Checks if an origin is trusted.
433
450
  *
@@ -438,8 +455,8 @@ class ye {
438
455
  isOriginTrusted(e) {
439
456
  if (this.allowedOrigins.has(e))
440
457
  return !0;
441
- for (const s of this.allowedOriginPatterns)
442
- if (s.test(e))
458
+ for (const t of this.allowedOriginPatterns)
459
+ if (t.test(e))
443
460
  return !0;
444
461
  return !1;
445
462
  }
@@ -456,13 +473,13 @@ class ye {
456
473
  * @returns Promise resolving to the response data
457
474
  * @throws Error if messenger is destroyed or timeout occurs
458
475
  */
459
- async send(e, s, n, i, r = 1e4) {
476
+ async send(e, t, n, i, r = 1e4) {
460
477
  if (this.destroyed)
461
478
  throw new Error("Messenger has been destroyed");
462
- const o = W(), a = re(o, n, i, {
479
+ const o = z(), a = ce(o, n, i, {
463
480
  uid: this.uid,
464
481
  domain: this.domain
465
- }), c = ge(), l = setTimeout(() => {
482
+ }), c = _e(), l = setTimeout(() => {
466
483
  this.pending.delete(o), c.reject(new Error(`Message "${n}" timed out after ${r}ms`));
467
484
  }, r);
468
485
  this.pending.set(o, {
@@ -470,7 +487,7 @@ class ye {
470
487
  timeout: l
471
488
  });
472
489
  try {
473
- e.postMessage(A(a), s);
490
+ e.postMessage(M(a), t);
474
491
  } catch (h) {
475
492
  throw this.pending.delete(o), clearTimeout(l), h;
476
493
  }
@@ -486,14 +503,14 @@ class ye {
486
503
  * @param data - Optional data payload
487
504
  * @throws Error if messenger is destroyed
488
505
  */
489
- post(e, s, n, i) {
506
+ post(e, t, n, i) {
490
507
  if (this.destroyed)
491
508
  throw new Error("Messenger has been destroyed");
492
- const r = W(), o = re(r, n, i, {
509
+ const r = z(), o = ce(r, n, i, {
493
510
  uid: this.uid,
494
511
  domain: this.domain
495
512
  });
496
- e.postMessage(A(o), s);
513
+ e.postMessage(M(o), t);
497
514
  }
498
515
  /**
499
516
  * Registers a handler for incoming messages of a specific type.
@@ -504,8 +521,8 @@ class ye {
504
521
  * @param handler - The handler function
505
522
  * @returns Function to unregister the handler
506
523
  */
507
- on(e, s) {
508
- return this.handlers.set(e, s), () => this.handlers.delete(e);
524
+ on(e, t) {
525
+ return this.handlers.set(e, t), () => this.handlers.delete(e);
509
526
  }
510
527
  /**
511
528
  * Sets up the postMessage event listener.
@@ -515,16 +532,16 @@ class ye {
515
532
  this.listener = (e) => {
516
533
  if (e.source === this.win || !this.isOriginTrusted(e.origin))
517
534
  return;
518
- const s = Te(e.data);
519
- s && this.handleMessage(s, e.source, e.origin);
535
+ const t = $e(e.data);
536
+ t && this.handleMessage(t, e.source, e.origin);
520
537
  }, this.win.addEventListener("message", this.listener);
521
538
  }
522
539
  /**
523
540
  * Processes a received message.
524
541
  * @internal
525
542
  */
526
- async handleMessage(e, s, n) {
527
- if (e.type === D.RESPONSE) {
543
+ async handleMessage(e, t, n) {
544
+ if (e.type === T.RESPONSE) {
528
545
  const i = this.pending.get(e.id);
529
546
  if (i)
530
547
  if (this.pending.delete(e.id), clearTimeout(i.timeout), e.error) {
@@ -534,7 +551,7 @@ class ye {
534
551
  i.deferred.resolve(e.data);
535
552
  return;
536
553
  }
537
- if (e.type === D.REQUEST) {
554
+ if (e.type === T.REQUEST) {
538
555
  const i = this.handlers.get(e.name);
539
556
  if (!i)
540
557
  return;
@@ -544,14 +561,14 @@ class ye {
544
561
  } catch (c) {
545
562
  o = c instanceof Error ? c : new Error(String(c));
546
563
  }
547
- const a = ke(
564
+ const a = Le(
548
565
  e.id,
549
566
  r,
550
567
  { uid: this.uid, domain: this.domain },
551
568
  o
552
569
  );
553
570
  try {
554
- s.postMessage(A(a), n);
571
+ t.postMessage(M(a), n);
555
572
  } catch {
556
573
  }
557
574
  }
@@ -580,8 +597,8 @@ class ye {
580
597
  return this.destroyed;
581
598
  }
582
599
  }
583
- const oe = 500;
584
- class B {
600
+ const le = 500;
601
+ class J {
585
602
  /**
586
603
  * Creates a new FunctionBridge instance.
587
604
  *
@@ -607,16 +624,16 @@ class B {
607
624
  * @param name - Optional name for debugging
608
625
  * @returns A function reference that can be sent across domains
609
626
  */
610
- serialize(e, s) {
611
- if (this.localFunctions.size >= oe) {
627
+ serialize(e, t) {
628
+ if (this.localFunctions.size >= le) {
612
629
  const i = this.localFunctions.keys().next().value;
613
630
  i && this.localFunctions.delete(i);
614
631
  }
615
- const n = W();
632
+ const n = z();
616
633
  return this.localFunctions.set(n, e), this.currentBatchIds.add(n), {
617
634
  __type__: "function",
618
635
  __id__: n,
619
- __name__: s || e.name || "anonymous"
636
+ __name__: t || e.name || "anonymous"
620
637
  };
621
638
  }
622
639
  /**
@@ -631,14 +648,14 @@ class B {
631
648
  * @param targetDomain - The origin of the target window
632
649
  * @returns A callable wrapper function
633
650
  */
634
- deserialize(e, s, n) {
651
+ deserialize(e, t, n) {
635
652
  const i = `${e.__id__}`, r = this.remoteFunctions.get(i);
636
653
  if (r) return r;
637
- if (this.remoteFunctions.size >= oe) {
654
+ if (this.remoteFunctions.size >= le) {
638
655
  const a = this.remoteFunctions.keys().next().value;
639
656
  a && this.remoteFunctions.delete(a);
640
657
  }
641
- const o = async (...a) => this.messenger.send(s, n, u.CALL, {
658
+ const o = async (...a) => this.messenger.send(t, n, u.CALL, {
642
659
  id: e.__id__,
643
660
  args: a
644
661
  });
@@ -663,11 +680,11 @@ class B {
663
680
  setupCallHandler() {
664
681
  this.messenger.on(
665
682
  u.CALL,
666
- async ({ id: e, args: s }) => {
683
+ async ({ id: e, args: t }) => {
667
684
  const n = this.localFunctions.get(e);
668
685
  if (!n)
669
686
  throw new Error(`Function with id "${e}" not found`);
670
- return n(...s);
687
+ return n(...t);
671
688
  }
672
689
  );
673
690
  }
@@ -710,8 +727,8 @@ class B {
710
727
  this.currentBatchIds.clear();
711
728
  return;
712
729
  }
713
- for (const s of this.localFunctions.keys())
714
- this.currentBatchIds.has(s) || this.localFunctions.delete(s);
730
+ for (const t of this.localFunctions.keys())
731
+ this.currentBatchIds.has(t) || this.localFunctions.delete(t);
715
732
  this.currentBatchIds.clear();
716
733
  }
717
734
  /**
@@ -745,175 +762,175 @@ class B {
745
762
  this.localFunctions.clear(), this.remoteFunctions.clear(), this.currentBatchIds.clear();
746
763
  }
747
764
  }
748
- function M(t, e, s = /* @__PURE__ */ new WeakSet()) {
749
- if (typeof t == "function")
750
- return e.serialize(t);
751
- if (Array.isArray(t)) {
752
- if (s.has(t))
765
+ function B(s, e, t = /* @__PURE__ */ new WeakSet()) {
766
+ if (typeof s == "function")
767
+ return e.serialize(s);
768
+ if (Array.isArray(s)) {
769
+ if (t.has(s))
753
770
  throw new Error("Circular reference detected in props - arrays cannot contain circular references");
754
- return s.add(t), t.map((n) => M(n, e, s));
771
+ return t.add(s), s.map((n) => B(n, e, t));
755
772
  }
756
- if (typeof t == "object" && t !== null) {
757
- if (s.has(t))
773
+ if (typeof s == "object" && s !== null) {
774
+ if (t.has(s))
758
775
  throw new Error("Circular reference detected in props - objects cannot contain circular references");
759
- s.add(t);
776
+ t.add(s);
760
777
  const n = {};
761
- for (const [i, r] of Object.entries(t))
762
- n[i] = M(r, e, s);
778
+ for (const [i, r] of Object.entries(s))
779
+ n[i] = B(r, e, t);
763
780
  return n;
764
781
  }
765
- return t;
782
+ return s;
766
783
  }
767
- function U(t, e, s, n, i = /* @__PURE__ */ new WeakSet()) {
768
- if (B.isFunctionRef(t))
769
- return e.deserialize(t, s, n);
770
- if (Array.isArray(t)) {
771
- if (i.has(t))
784
+ function V(s, e, t, n, i = /* @__PURE__ */ new WeakSet()) {
785
+ if (J.isFunctionRef(s))
786
+ return e.deserialize(s, t, n);
787
+ if (Array.isArray(s)) {
788
+ if (i.has(s))
772
789
  throw new Error("Circular reference detected in serialized props");
773
- return i.add(t), t.map(
774
- (r) => U(r, e, s, n, i)
790
+ return i.add(s), s.map(
791
+ (r) => V(r, e, t, n, i)
775
792
  );
776
793
  }
777
- if (typeof t == "object" && t !== null) {
778
- if (i.has(t))
794
+ if (typeof s == "object" && s !== null) {
795
+ if (i.has(s))
779
796
  throw new Error("Circular reference detected in serialized props");
780
- i.add(t);
797
+ i.add(s);
781
798
  const r = {};
782
- for (const [o, a] of Object.entries(t))
783
- r[o] = U(a, e, s, n, i);
799
+ for (const [o, a] of Object.entries(s))
800
+ r[o] = V(a, e, t, n, i);
784
801
  return r;
785
802
  }
786
- return t;
803
+ return s;
787
804
  }
788
- function j(t = window) {
805
+ function q(s = window) {
789
806
  try {
790
- return t.location.origin;
807
+ return s.location.origin;
791
808
  } catch {
792
809
  return "";
793
810
  }
794
811
  }
795
- function _e(t, e = window) {
812
+ function be(s, e = window) {
796
813
  try {
797
- return t.location.origin === e.location.origin;
814
+ return s.location.origin === e.location.origin;
798
815
  } catch {
799
816
  return !1;
800
817
  }
801
818
  }
802
- function we(t, e) {
803
- return typeof t == "string" ? t === "*" ? !0 : t === e : t instanceof RegExp ? t.test(e) : Array.isArray(t) ? t.some((s) => we(s, e)) : !1;
819
+ function L(s, e) {
820
+ return typeof s == "string" ? s === "*" ? !0 : s === e : s instanceof RegExp ? s.test(e) : Array.isArray(s) ? s.some((t) => L(t, e)) : !1;
804
821
  }
805
- function Ee(t) {
806
- if (!t) return !0;
822
+ function Pe(s) {
823
+ if (!s) return !0;
807
824
  try {
808
- return t.closed;
825
+ return s.closed;
809
826
  } catch {
810
827
  return !0;
811
828
  }
812
829
  }
813
- function $e(t = window) {
830
+ function He(s = window) {
814
831
  try {
815
- return t.opener;
832
+ return s.opener;
816
833
  } catch {
817
834
  return null;
818
835
  }
819
836
  }
820
- function Fe(t = window) {
837
+ function Ae(s = window) {
821
838
  try {
822
- const e = t.parent;
823
- return e && e !== t ? e : null;
839
+ const e = s.parent;
840
+ return e && e !== s ? e : null;
824
841
  } catch {
825
842
  return null;
826
843
  }
827
844
  }
828
- function Le(t = window) {
845
+ function Ue(s = window) {
829
846
  try {
830
- return t.parent !== t;
847
+ return s.parent !== s;
831
848
  } catch {
832
849
  return !0;
833
850
  }
834
851
  }
835
- function Ae(t = window) {
852
+ function Me(s = window) {
836
853
  try {
837
- return t.opener !== null && t.opener !== void 0;
854
+ return s.opener !== null && s.opener !== void 0;
838
855
  } catch {
839
856
  return !1;
840
857
  }
841
858
  }
842
- const ae = 32 * 1024;
843
- function He(t) {
844
- const e = We(t);
845
- return `${N}${e}`;
859
+ const ue = 32 * 1024;
860
+ function We(s) {
861
+ const e = ze(s);
862
+ return `${F}${e}`;
846
863
  }
847
- function be(t) {
848
- if (!t || !t.startsWith(N))
864
+ function Oe(s) {
865
+ if (!s || !s.startsWith(F))
849
866
  return null;
850
- const e = t.slice(N.length);
851
- return ze(e);
867
+ const e = s.slice(F.length);
868
+ return je(e);
852
869
  }
853
- function J(t = window) {
870
+ function X(s = window) {
854
871
  try {
855
- return t.name.startsWith(N);
872
+ return s.name.startsWith(F);
856
873
  } catch {
857
874
  return !1;
858
875
  }
859
876
  }
860
- function H(t, e = window) {
861
- return be(e.name)?.tag === t;
877
+ function W(s, e = window) {
878
+ return Oe(e.name)?.tag === s;
862
879
  }
863
- function We(t) {
880
+ function ze(s) {
864
881
  try {
865
- const e = JSON.stringify(t), s = btoa(encodeURIComponent(e)), n = new Blob([s]).size;
866
- if (n > ae)
882
+ const e = JSON.stringify(s), t = btoa(encodeURIComponent(e)), n = new Blob([t]).size;
883
+ if (n > ue)
867
884
  throw new Error(
868
- `Payload size (${Math.round(n / 1024)}KB) exceeds maximum allowed size (${ae / 1024}KB). Consider reducing the amount of data passed via props.`
885
+ `Payload size (${Math.round(n / 1024)}KB) exceeds maximum allowed size (${ue / 1024}KB). Consider reducing the amount of data passed via props.`
869
886
  );
870
- return s;
887
+ return t;
871
888
  } catch (e) {
872
889
  throw e instanceof Error && e.message.includes("Payload size") ? e : new Error(`Failed to encode payload: ${e}`);
873
890
  }
874
891
  }
875
- function ze(t) {
892
+ function je(s) {
876
893
  try {
877
- const e = decodeURIComponent(atob(t));
894
+ const e = decodeURIComponent(atob(s));
878
895
  return JSON.parse(e);
879
896
  } catch {
880
897
  return null;
881
898
  }
882
899
  }
883
- function Me(t) {
900
+ function Be(s) {
884
901
  return {
885
- uid: t.uid,
886
- tag: t.tag,
887
- version: pe,
888
- context: t.context,
889
- consumerDomain: t.consumerDomain,
890
- props: t.props,
891
- exports: t.exports,
892
- children: t.children
902
+ uid: s.uid,
903
+ tag: s.tag,
904
+ version: ye,
905
+ context: s.context,
906
+ consumerDomain: s.consumerDomain,
907
+ props: s.props,
908
+ exports: s.exports,
909
+ children: s.children
893
910
  };
894
911
  }
895
- function Ue(t = window) {
896
- return be(t.name);
912
+ function Ve(s = window) {
913
+ return Oe(s.name);
897
914
  }
898
- const ce = 100, w = /* @__PURE__ */ new Map();
899
- function je() {
900
- const t = [];
901
- for (const [e, s] of w.entries())
902
- Ee(s) && t.push(e);
903
- for (const e of t)
904
- w.delete(e);
915
+ const he = 100, E = /* @__PURE__ */ new Map();
916
+ function qe() {
917
+ const s = [];
918
+ for (const [e, t] of E.entries())
919
+ Pe(t) && s.push(e);
920
+ for (const e of s)
921
+ E.delete(e);
905
922
  }
906
- function Be(t, e) {
907
- if (w.size >= ce && je(), w.size >= ce) {
908
- const s = w.keys().next().value;
909
- s && w.delete(s);
923
+ function Je(s, e) {
924
+ if (E.size >= he && qe(), E.size >= he) {
925
+ const t = E.keys().next().value;
926
+ t && E.delete(t);
910
927
  }
911
- w.set(t, e);
928
+ E.set(s, e);
912
929
  }
913
- function Je(t) {
914
- w.delete(t);
930
+ function Xe(s) {
931
+ E.delete(s);
915
932
  }
916
- class m {
933
+ class y {
917
934
  /** @internal */
918
935
  _optional = !1;
919
936
  /** @internal */
@@ -976,11 +993,11 @@ class m {
976
993
  * ```
977
994
  */
978
995
  default(e) {
979
- const s = this._clone();
980
- return s._default = e, s;
996
+ const t = this._clone();
997
+ return t._default = e, t;
981
998
  }
982
999
  }
983
- class V extends m {
1000
+ class K extends y {
984
1001
  /** @internal */
985
1002
  _minLength;
986
1003
  /** @internal */
@@ -997,26 +1014,26 @@ class V extends m {
997
1014
  return {
998
1015
  issues: [{ message: `Expected string, got ${typeof e}` }]
999
1016
  };
1000
- const s = this._trim ? e.trim() : e;
1001
- return this._minLength !== void 0 && s.length < this._minLength ? {
1017
+ const t = this._trim ? e.trim() : e;
1018
+ return this._minLength !== void 0 && t.length < this._minLength ? {
1002
1019
  issues: [
1003
1020
  { message: `String must be at least ${this._minLength} characters` }
1004
1021
  ]
1005
- } : this._maxLength !== void 0 && s.length > this._maxLength ? {
1022
+ } : this._maxLength !== void 0 && t.length > this._maxLength ? {
1006
1023
  issues: [
1007
1024
  { message: `String must be at most ${this._maxLength} characters` }
1008
1025
  ]
1009
- } : this._pattern && !this._pattern.test(s) ? {
1026
+ } : this._pattern && !this._pattern.test(t) ? {
1010
1027
  issues: [
1011
1028
  {
1012
1029
  message: this._patternMessage || `String must match pattern ${this._pattern}`
1013
1030
  }
1014
1031
  ]
1015
- } : { value: s };
1032
+ } : { value: t };
1016
1033
  }
1017
1034
  /** @internal */
1018
1035
  _clone() {
1019
- const e = new V();
1036
+ const e = new K();
1020
1037
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e._minLength = this._minLength, e._maxLength = this._maxLength, e._pattern = this._pattern, e._patternMessage = this._patternMessage, e._trim = this._trim, e;
1021
1038
  }
1022
1039
  /**
@@ -1030,8 +1047,8 @@ class V extends m {
1030
1047
  * ```
1031
1048
  */
1032
1049
  min(e) {
1033
- const s = this._clone();
1034
- return s._minLength = e, s;
1050
+ const t = this._clone();
1051
+ return t._minLength = e, t;
1035
1052
  }
1036
1053
  /**
1037
1054
  * Requires maximum string length.
@@ -1044,8 +1061,8 @@ class V extends m {
1044
1061
  * ```
1045
1062
  */
1046
1063
  max(e) {
1047
- const s = this._clone();
1048
- return s._maxLength = e, s;
1064
+ const t = this._clone();
1065
+ return t._maxLength = e, t;
1049
1066
  }
1050
1067
  /**
1051
1068
  * Requires exact string length.
@@ -1058,8 +1075,8 @@ class V extends m {
1058
1075
  * ```
1059
1076
  */
1060
1077
  length(e) {
1061
- const s = this._clone();
1062
- return s._minLength = e, s._maxLength = e, s;
1078
+ const t = this._clone();
1079
+ return t._minLength = e, t._maxLength = e, t;
1063
1080
  }
1064
1081
  /**
1065
1082
  * Requires string to match a regex pattern.
@@ -1072,9 +1089,9 @@ class V extends m {
1072
1089
  * slug: prop.string().pattern(/^[a-z0-9-]+$/, 'Invalid slug format')
1073
1090
  * ```
1074
1091
  */
1075
- pattern(e, s) {
1092
+ pattern(e, t) {
1076
1093
  const n = this._clone();
1077
- return n._pattern = e, n._patternMessage = s, n;
1094
+ return n._pattern = e, n._patternMessage = t, n;
1078
1095
  }
1079
1096
  /**
1080
1097
  * Validates as email address.
@@ -1141,7 +1158,7 @@ class V extends m {
1141
1158
  return e._minLength = 1, e;
1142
1159
  }
1143
1160
  }
1144
- class q extends m {
1161
+ class G extends y {
1145
1162
  /** @internal */
1146
1163
  _min;
1147
1164
  /** @internal */
@@ -1156,7 +1173,7 @@ class q extends m {
1156
1173
  }
1157
1174
  /** @internal */
1158
1175
  _clone() {
1159
- const e = new q();
1176
+ const e = new G();
1160
1177
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e._min = this._min, e._max = this._max, e._int = this._int, e;
1161
1178
  }
1162
1179
  /**
@@ -1170,8 +1187,8 @@ class q extends m {
1170
1187
  * ```
1171
1188
  */
1172
1189
  min(e) {
1173
- const s = this._clone();
1174
- return s._min = e, s;
1190
+ const t = this._clone();
1191
+ return t._min = e, t;
1175
1192
  }
1176
1193
  /**
1177
1194
  * Requires maximum value.
@@ -1184,8 +1201,8 @@ class q extends m {
1184
1201
  * ```
1185
1202
  */
1186
1203
  max(e) {
1187
- const s = this._clone();
1188
- return s._max = e, s;
1204
+ const t = this._clone();
1205
+ return t._max = e, t;
1189
1206
  }
1190
1207
  /**
1191
1208
  * Requires integer value.
@@ -1236,7 +1253,7 @@ class q extends m {
1236
1253
  return e._max = -Number.MIN_VALUE, e;
1237
1254
  }
1238
1255
  }
1239
- class X extends m {
1256
+ class Y extends y {
1240
1257
  /** @internal */
1241
1258
  _validate(e) {
1242
1259
  return typeof e != "boolean" ? {
@@ -1245,11 +1262,11 @@ class X extends m {
1245
1262
  }
1246
1263
  /** @internal */
1247
1264
  _clone() {
1248
- const e = new X();
1265
+ const e = new Y();
1249
1266
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1250
1267
  }
1251
1268
  }
1252
- class Y extends m {
1269
+ class Z extends y {
1253
1270
  /** @internal */
1254
1271
  _validate(e) {
1255
1272
  return typeof e != "function" ? {
@@ -1258,11 +1275,11 @@ class Y extends m {
1258
1275
  }
1259
1276
  /** @internal */
1260
1277
  _clone() {
1261
- const e = new Y();
1278
+ const e = new Z();
1262
1279
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1263
1280
  }
1264
1281
  }
1265
- class T extends m {
1282
+ class N extends y {
1266
1283
  /** @internal */
1267
1284
  _itemSchema;
1268
1285
  /** @internal */
@@ -1288,7 +1305,7 @@ class T extends m {
1288
1305
  ]
1289
1306
  };
1290
1307
  if (this._itemSchema) {
1291
- const s = [];
1308
+ const t = [];
1292
1309
  for (let n = 0; n < e.length; n++) {
1293
1310
  const i = this._itemSchema["~standard"].validate(e[n]);
1294
1311
  if (i instanceof Promise)
@@ -1302,15 +1319,15 @@ class T extends m {
1302
1319
  path: [n, ...r.path || []]
1303
1320
  }))
1304
1321
  };
1305
- s.push(i.value);
1322
+ t.push(i.value);
1306
1323
  }
1307
- return { value: s };
1324
+ return { value: t };
1308
1325
  }
1309
1326
  return { value: e };
1310
1327
  }
1311
1328
  /** @internal */
1312
1329
  _clone() {
1313
- const e = new T();
1330
+ const e = new N();
1314
1331
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e._itemSchema = this._itemSchema, e._minLength = this._minLength, e._maxLength = this._maxLength, e;
1315
1332
  }
1316
1333
  /**
@@ -1326,8 +1343,8 @@ class T extends m {
1326
1343
  * ```
1327
1344
  */
1328
1345
  of(e) {
1329
- const s = new T();
1330
- return s._optional = this._optional, s._nullable = this._nullable, s._itemSchema = e, s._minLength = this._minLength, s._maxLength = this._maxLength, s;
1346
+ const t = new N();
1347
+ return t._optional = this._optional, t._nullable = this._nullable, t._itemSchema = e, t._minLength = this._minLength, t._maxLength = this._maxLength, t;
1331
1348
  }
1332
1349
  /**
1333
1350
  * Requires minimum array length.
@@ -1340,8 +1357,8 @@ class T extends m {
1340
1357
  * ```
1341
1358
  */
1342
1359
  min(e) {
1343
- const s = this._clone();
1344
- return s._minLength = e, s;
1360
+ const t = this._clone();
1361
+ return t._minLength = e, t;
1345
1362
  }
1346
1363
  /**
1347
1364
  * Requires maximum array length.
@@ -1354,8 +1371,8 @@ class T extends m {
1354
1371
  * ```
1355
1372
  */
1356
1373
  max(e) {
1357
- const s = this._clone();
1358
- return s._maxLength = e, s;
1374
+ const t = this._clone();
1375
+ return t._maxLength = e, t;
1359
1376
  }
1360
1377
  /**
1361
1378
  * Requires non-empty array.
@@ -1369,7 +1386,7 @@ class T extends m {
1369
1386
  return this.min(1);
1370
1387
  }
1371
1388
  }
1372
- class k extends m {
1389
+ class k extends y {
1373
1390
  /** @internal */
1374
1391
  _shape;
1375
1392
  /** @internal */
@@ -1384,18 +1401,18 @@ class k extends m {
1384
1401
  }
1385
1402
  ]
1386
1403
  };
1387
- const s = e, n = {};
1404
+ const t = e, n = {};
1388
1405
  if (this._shape) {
1389
1406
  if (this._strict) {
1390
1407
  const i = new Set(Object.keys(this._shape));
1391
- for (const r of Object.keys(s))
1408
+ for (const r of Object.keys(t))
1392
1409
  if (!i.has(r))
1393
1410
  return {
1394
1411
  issues: [{ message: `Unknown key: ${r}`, path: [r] }]
1395
1412
  };
1396
1413
  }
1397
1414
  for (const [i, r] of Object.entries(this._shape)) {
1398
- const o = r["~standard"].validate(s[i]);
1415
+ const o = r["~standard"].validate(t[i]);
1399
1416
  if (o instanceof Promise)
1400
1417
  throw new Error(
1401
1418
  "Async schema validation is not supported. Use synchronous schemas."
@@ -1410,8 +1427,8 @@ class k extends m {
1410
1427
  n[i] = o.value;
1411
1428
  }
1412
1429
  if (!this._strict)
1413
- for (const i of Object.keys(s))
1414
- i in this._shape || (n[i] = s[i]);
1430
+ for (const i of Object.keys(t))
1431
+ i in this._shape || (n[i] = t[i]);
1415
1432
  return { value: n };
1416
1433
  }
1417
1434
  return { value: e };
@@ -1436,8 +1453,8 @@ class k extends m {
1436
1453
  * ```
1437
1454
  */
1438
1455
  shape(e) {
1439
- const s = new k();
1440
- return s._optional = this._optional, s._nullable = this._nullable, s._shape = e, s._strict = this._strict, s;
1456
+ const t = new k();
1457
+ return t._optional = this._optional, t._nullable = this._nullable, t._shape = e, t._strict = this._strict, t;
1441
1458
  }
1442
1459
  /**
1443
1460
  * Rejects objects with unknown keys.
@@ -1452,7 +1469,7 @@ class k extends m {
1452
1469
  return e._strict = !0, e;
1453
1470
  }
1454
1471
  }
1455
- class Z extends m {
1472
+ class Q extends y {
1456
1473
  /** @internal */
1457
1474
  _value;
1458
1475
  constructor(e) {
@@ -1466,11 +1483,11 @@ class Z extends m {
1466
1483
  }
1467
1484
  /** @internal */
1468
1485
  _clone() {
1469
- const e = new Z(this._value);
1486
+ const e = new Q(this._value);
1470
1487
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1471
1488
  }
1472
1489
  }
1473
- class G extends m {
1490
+ class ee extends y {
1474
1491
  /** @internal */
1475
1492
  _values;
1476
1493
  constructor(e) {
@@ -1481,18 +1498,18 @@ class G extends m {
1481
1498
  return this._values.includes(e) ? { value: e } : {
1482
1499
  issues: [
1483
1500
  {
1484
- message: `Expected one of [${this._values.map((s) => JSON.stringify(s)).join(", ")}], got ${JSON.stringify(e)}`
1501
+ message: `Expected one of [${this._values.map((t) => JSON.stringify(t)).join(", ")}], got ${JSON.stringify(e)}`
1485
1502
  }
1486
1503
  ]
1487
1504
  };
1488
1505
  }
1489
1506
  /** @internal */
1490
1507
  _clone() {
1491
- const e = new G(this._values);
1508
+ const e = new ee(this._values);
1492
1509
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1493
1510
  }
1494
1511
  }
1495
- class K extends m {
1512
+ class te extends y {
1496
1513
  constructor() {
1497
1514
  super(), this._nullable = !0;
1498
1515
  }
@@ -1502,7 +1519,7 @@ class K extends m {
1502
1519
  }
1503
1520
  /** @internal */
1504
1521
  _clone() {
1505
- const e = new K();
1522
+ const e = new te();
1506
1523
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1507
1524
  }
1508
1525
  }
@@ -1519,7 +1536,7 @@ const d = {
1519
1536
  * prop.string().pattern(/^[a-z]+$/)
1520
1537
  * ```
1521
1538
  */
1522
- string: () => new V(),
1539
+ string: () => new K(),
1523
1540
  /**
1524
1541
  * Creates a number schema.
1525
1542
  *
@@ -1531,7 +1548,7 @@ const d = {
1531
1548
  * prop.number().positive()
1532
1549
  * ```
1533
1550
  */
1534
- number: () => new q(),
1551
+ number: () => new G(),
1535
1552
  /**
1536
1553
  * Creates a boolean schema.
1537
1554
  *
@@ -1541,7 +1558,7 @@ const d = {
1541
1558
  * prop.boolean().default(false)
1542
1559
  * ```
1543
1560
  */
1544
- boolean: () => new X(),
1561
+ boolean: () => new Y(),
1545
1562
  /**
1546
1563
  * Creates a function schema.
1547
1564
  *
@@ -1554,7 +1571,7 @@ const d = {
1554
1571
  * prop.function<(data: { id: string }) => Promise<void>>()
1555
1572
  * ```
1556
1573
  */
1557
- function: () => new Y(),
1574
+ function: () => new Z(),
1558
1575
  /**
1559
1576
  * Creates an array schema.
1560
1577
  *
@@ -1567,7 +1584,7 @@ const d = {
1567
1584
  * prop.array().of(prop.number()).min(1).max(10)
1568
1585
  * ```
1569
1586
  */
1570
- array: () => new T(),
1587
+ array: () => new N(),
1571
1588
  /**
1572
1589
  * Creates an object schema.
1573
1590
  *
@@ -1596,7 +1613,7 @@ const d = {
1596
1613
  * prop.literal(true)
1597
1614
  * ```
1598
1615
  */
1599
- literal: (t) => new Z(t),
1616
+ literal: (s) => new Q(s),
1600
1617
  /**
1601
1618
  * Creates an enum schema for a set of allowed values.
1602
1619
  *
@@ -1608,7 +1625,7 @@ const d = {
1608
1625
  * prop.enum([1, 2, 3])
1609
1626
  * ```
1610
1627
  */
1611
- enum: (t) => new G(t),
1628
+ enum: (s) => new ee(s),
1612
1629
  /**
1613
1630
  * Creates a schema that accepts any value.
1614
1631
  *
@@ -1620,8 +1637,8 @@ const d = {
1620
1637
  * prop.any()
1621
1638
  * ```
1622
1639
  */
1623
- any: () => new K()
1624
- }, R = {
1640
+ any: () => new te()
1641
+ }, P = {
1625
1642
  uid: {
1626
1643
  schema: d.string().optional(),
1627
1644
  sendToHost: !0
@@ -1688,118 +1705,140 @@ const d = {
1688
1705
  sendToHost: !1
1689
1706
  }
1690
1707
  };
1691
- function E(t) {
1692
- return typeof t == "object" && t !== null && "~standard" in t && typeof t["~standard"] == "object" && t["~standard"] !== null && t["~standard"].version === 1 && typeof t["~standard"].validate == "function";
1708
+ function b(s) {
1709
+ return typeof s == "object" && s !== null && "~standard" in s && typeof s["~standard"] == "object" && s["~standard"] !== null && s["~standard"].version === 1 && typeof s["~standard"].vendor == "string" && typeof s["~standard"].validate == "function";
1693
1710
  }
1694
- function Ve(t, e, s) {
1695
- const n = t["~standard"].validate(e);
1711
+ function Ke(s, e, t) {
1712
+ const n = s["~standard"].validate(e);
1696
1713
  if (n instanceof Promise)
1697
1714
  throw new Error(
1698
- `Prop "${s}" uses an async schema. ForgeFrame only supports synchronous schema validation. Please use a synchronous schema or remove async operations (like database lookups) from your schema definition.`
1715
+ `Prop "${t}" uses an async schema. ForgeFrame only supports synchronous schema validation. Please use a synchronous schema or remove async operations (like database lookups) from your schema definition.`
1699
1716
  );
1700
1717
  if (n.issues) {
1701
- const i = n.issues.map((r) => `${qe(r.path, s)}: ${r.message}`);
1718
+ const i = n.issues.map((r) => `${Ge(r.path, t)}: ${r.message}`);
1702
1719
  throw new Error(`Validation failed: ${i.join("; ")}`);
1703
1720
  }
1704
1721
  return n.value;
1705
1722
  }
1706
- function qe(t, e) {
1707
- if (!t || t.length === 0)
1723
+ function Ge(s, e) {
1724
+ if (!s || s.length === 0)
1708
1725
  return e;
1709
- const s = t.map((n) => typeof n == "object" && n !== null && "key" in n ? String(n.key) : String(n));
1710
- return `${e}.${s.join(".")}`;
1726
+ const t = s.map((n) => {
1727
+ if (typeof n == "object" && n !== null) {
1728
+ if ("key" in n && n.key !== void 0)
1729
+ return String(n.key);
1730
+ if ("index" in n && typeof n.index == "number")
1731
+ return String(n.index);
1732
+ }
1733
+ return String(n);
1734
+ });
1735
+ return `${e}.${t.join(".")}`;
1711
1736
  }
1712
- function le(t, e, s) {
1737
+ function de(s, e, t) {
1713
1738
  const n = {
1714
- ...R,
1739
+ ...P,
1715
1740
  ...e
1716
1741
  }, i = {};
1717
1742
  for (const [r, o] of Object.entries(n)) {
1718
- const c = E(o) ? { schema: o } : o;
1743
+ const c = b(o) ? { schema: o } : o;
1719
1744
  let l;
1720
- const h = c.alias, g = r in t, y = h && h in t;
1721
- if (g)
1722
- l = t[r];
1723
- else if (y)
1724
- l = t[h];
1745
+ const h = c.alias, w = r in s, _ = h && h in s;
1746
+ if (w)
1747
+ l = s[r];
1748
+ else if (_)
1749
+ l = s[h];
1725
1750
  else if (c.value)
1726
- l = c.value(s);
1751
+ l = c.value(t);
1727
1752
  else if (c.default !== void 0)
1728
- l = typeof c.default == "function" ? c.default(s) : c.default;
1729
- else if (c.schema && E(c.schema)) {
1730
- const b = c.schema["~standard"].validate(void 0);
1731
- !(b instanceof Promise) && !b.issues && (l = b.value);
1753
+ l = typeof c.default == "function" ? c.default(t) : c.default;
1754
+ else if (c.schema && b(c.schema)) {
1755
+ const O = c.schema["~standard"].validate(void 0);
1756
+ !(O instanceof Promise) && !O.issues && (l = O.value);
1732
1757
  }
1733
1758
  l !== void 0 && c.decorate && (l = c.decorate({ value: l, props: i })), i[r] = l;
1734
1759
  }
1735
1760
  return i;
1736
1761
  }
1737
- function Xe(t, e) {
1738
- const s = {
1739
- ...R,
1762
+ function Ye(s, e) {
1763
+ const t = {
1764
+ ...P,
1740
1765
  ...e
1741
1766
  };
1742
- for (const [n, i] of Object.entries(s)) {
1743
- const r = E(i), o = r ? { schema: i } : i;
1744
- let a = t[n];
1767
+ for (const [n, i] of Object.entries(t)) {
1768
+ const r = b(i), o = r ? { schema: i } : i;
1769
+ let a = s[n];
1745
1770
  if (o.required && a === void 0)
1746
1771
  throw new Error(`Prop "${n}" is required but was not provided`);
1747
- if (o.schema && E(o.schema))
1748
- (a !== void 0 || r) && (a = Ve(o.schema, a, n), t[n] = a);
1772
+ if (o.schema && b(o.schema))
1773
+ (a !== void 0 || r) && (a = Ke(o.schema, a, n), s[n] = a);
1749
1774
  else if (a === void 0)
1750
1775
  continue;
1751
- o.validate && o.validate({ value: a, props: t });
1776
+ o.validate && o.validate({ value: a, props: s });
1752
1777
  }
1753
1778
  }
1754
- function ue(t, e, s, n) {
1779
+ function fe(s, e, t, n) {
1755
1780
  const i = {
1756
- ...R,
1781
+ ...P,
1757
1782
  ...e
1758
1783
  }, r = {};
1759
1784
  for (const [o, a] of Object.entries(i)) {
1760
- const l = E(a) ? { schema: a } : a, h = t[o];
1785
+ const l = b(a) ? { schema: a } : a, h = s[o];
1761
1786
  if (l.sendToHost === !1 || l.sameDomain && !n) continue;
1762
1787
  if (l.trustedDomains) {
1763
- const y = l.trustedDomains;
1764
- if (!we(y, s)) continue;
1788
+ const _ = l.trustedDomains;
1789
+ if (!L(_, t)) continue;
1765
1790
  }
1766
- let g = h;
1767
- l.hostDecorate && h !== void 0 && (g = l.hostDecorate({ value: h, props: t })), r[o] = g;
1791
+ let w = h;
1792
+ l.hostDecorate && h !== void 0 && (w = l.hostDecorate({ value: h, props: s })), r[o] = w;
1768
1793
  }
1769
1794
  return r;
1770
1795
  }
1771
- function Ye(t, e) {
1772
- const s = new URLSearchParams(), n = {
1773
- ...R,
1796
+ function Ze(s, e) {
1797
+ const t = new URLSearchParams(), n = {
1798
+ ...P,
1774
1799
  ...e
1775
1800
  };
1776
1801
  for (const [i, r] of Object.entries(n)) {
1777
- const a = E(r) ? { schema: r } : r, c = t[i];
1802
+ const a = b(r) ? { schema: r } : r, c = s[i];
1778
1803
  if (c === void 0 || typeof c == "function" || !a.queryParam) continue;
1779
1804
  const l = typeof a.queryParam == "string" ? a.queryParam : i;
1780
1805
  let h;
1781
- typeof a.queryParam == "function" ? h = a.queryParam({ value: c }) : typeof c == "object" ? h = JSON.stringify(c) : h = String(c), s.set(l, h);
1806
+ typeof a.queryParam == "function" ? h = a.queryParam({ value: c }) : typeof c == "object" ? h = JSON.stringify(c) : h = String(c), t.set(l, h);
1782
1807
  }
1783
- return s;
1808
+ return t;
1784
1809
  }
1785
- function Pe(t, e = "") {
1786
- const s = [];
1787
- for (const [n, i] of Object.entries(t)) {
1810
+ function Qe(s, e) {
1811
+ const t = new URLSearchParams(), n = {
1812
+ ...P,
1813
+ ...e
1814
+ };
1815
+ for (const [i, r] of Object.entries(n)) {
1816
+ const a = b(r) ? { schema: r } : r, c = s[i];
1817
+ if (c === void 0 || typeof c == "function" || !a.bodyParam) continue;
1818
+ const l = typeof a.bodyParam == "string" ? a.bodyParam : i;
1819
+ let h;
1820
+ typeof a.bodyParam == "function" ? h = a.bodyParam({ value: c }) : typeof c == "object" ? h = JSON.stringify(c) : h = String(c), t.set(l, h);
1821
+ }
1822
+ return t;
1823
+ }
1824
+ function Re(s, e = "") {
1825
+ const t = [];
1826
+ for (const [n, i] of Object.entries(s)) {
1788
1827
  const r = e ? `${e}.${n}` : n;
1789
1828
  if (i !== null && typeof i == "object" && !Array.isArray(i))
1790
- s.push(Pe(i, r));
1829
+ t.push(Re(i, r));
1791
1830
  else {
1792
1831
  const o = encodeURIComponent(JSON.stringify(i));
1793
- s.push(`${r}=${o}`);
1832
+ t.push(`${r}=${o}`);
1794
1833
  }
1795
1834
  }
1796
- return s.filter(Boolean).join("&");
1835
+ return t.filter(Boolean).join("&");
1797
1836
  }
1798
- function Ze(t) {
1837
+ function et(s) {
1799
1838
  const e = {};
1800
- if (!t) return e;
1801
- const s = t.split("&");
1802
- for (const n of s) {
1839
+ if (!s) return e;
1840
+ const t = s.split("&");
1841
+ for (const n of t) {
1803
1842
  const [i, r] = n.split("=");
1804
1843
  if (!i || r === void 0) continue;
1805
1844
  let o;
@@ -1818,48 +1857,48 @@ function Ze(t) {
1818
1857
  }
1819
1858
  return e;
1820
1859
  }
1821
- function Ge(t) {
1822
- return typeof t == "object" && t !== null && t.__type__ === "dotify" && typeof t.__value__ == "string";
1860
+ function tt(s) {
1861
+ return typeof s == "object" && s !== null && s.__type__ === "dotify" && typeof s.__value__ == "string";
1823
1862
  }
1824
- function he(t, e, s) {
1863
+ function pe(s, e, t) {
1825
1864
  const n = {
1826
- ...R,
1865
+ ...P,
1827
1866
  ...e
1828
1867
  }, i = {};
1829
- for (const [r, o] of Object.entries(t)) {
1868
+ for (const [r, o] of Object.entries(s)) {
1830
1869
  if (o === void 0) continue;
1831
1870
  const a = n[r];
1832
- i[r] = Ke(o, a, s);
1871
+ i[r] = st(o, a, t);
1833
1872
  }
1834
1873
  return i;
1835
1874
  }
1836
- function Ke(t, e, s) {
1837
- if (typeof t == "function")
1838
- return s.serialize(t);
1875
+ function st(s, e, t) {
1876
+ if (typeof s == "function")
1877
+ return t.serialize(s);
1839
1878
  const n = e?.serialization ?? I.JSON;
1840
- if (n === I.BASE64 && typeof t == "object") {
1841
- const i = JSON.stringify(t);
1879
+ if (n === I.BASE64 && typeof s == "object") {
1880
+ const i = JSON.stringify(s);
1842
1881
  return {
1843
1882
  __type__: "base64",
1844
1883
  __value__: btoa(encodeURIComponent(i))
1845
1884
  };
1846
1885
  }
1847
- return n === I.DOTIFY && typeof t == "object" && t !== null && !Array.isArray(t) ? {
1886
+ return n === I.DOTIFY && typeof s == "object" && s !== null && !Array.isArray(s) ? {
1848
1887
  __type__: "dotify",
1849
- __value__: Pe(t)
1850
- } : M(t, s);
1888
+ __value__: Re(s)
1889
+ } : B(s, t);
1851
1890
  }
1852
- function de(t, e, s, n, i, r) {
1891
+ function me(s, e, t, n, i, r) {
1853
1892
  const o = {
1854
- ...R,
1893
+ ...P,
1855
1894
  ...e
1856
1895
  }, a = {};
1857
- for (const [c, l] of Object.entries(t)) {
1896
+ for (const [c, l] of Object.entries(s)) {
1858
1897
  const h = o[c];
1859
- a[c] = Qe(
1898
+ a[c] = nt(
1860
1899
  l,
1861
1900
  h,
1862
- s,
1901
+ t,
1863
1902
  n,
1864
1903
  i,
1865
1904
  r
@@ -1867,65 +1906,65 @@ function de(t, e, s, n, i, r) {
1867
1906
  }
1868
1907
  return a;
1869
1908
  }
1870
- function Qe(t, e, s, n, i, r) {
1871
- if (et(t))
1909
+ function nt(s, e, t, n, i, r) {
1910
+ if (it(s))
1872
1911
  try {
1873
- const o = decodeURIComponent(atob(t.__value__));
1912
+ const o = decodeURIComponent(atob(s.__value__));
1874
1913
  return JSON.parse(o);
1875
1914
  } catch {
1876
- return t;
1915
+ return s;
1877
1916
  }
1878
- if (Ge(t))
1917
+ if (tt(s))
1879
1918
  try {
1880
- return Ze(t.__value__);
1919
+ return et(s.__value__);
1881
1920
  } catch {
1882
- return t;
1921
+ return s;
1883
1922
  }
1884
- return U(t, n, i, r);
1923
+ return V(s, n, i, r);
1885
1924
  }
1886
- function et(t) {
1887
- return typeof t == "object" && t !== null && t.__type__ === "base64" && typeof t.__value__ == "string";
1925
+ function it(s) {
1926
+ return typeof s == "object" && s !== null && s.__type__ === "base64" && typeof s.__value__ == "string";
1888
1927
  }
1889
- function P(t, e = "100%") {
1890
- return t === void 0 ? e : typeof t == "number" ? `${t}px` : t;
1928
+ function R(s, e = "100%") {
1929
+ return s === void 0 ? e : typeof s == "number" ? `${s}px` : s;
1891
1930
  }
1892
- function $(t, e) {
1893
- if (t === void 0) return e;
1894
- if (typeof t == "number") return t;
1895
- const s = parseInt(t, 10);
1896
- return isNaN(s) ? e : s;
1931
+ function $(s, e) {
1932
+ if (s === void 0) return e;
1933
+ if (typeof s == "number") return s;
1934
+ const t = parseInt(s, 10);
1935
+ return isNaN(t) ? e : t;
1897
1936
  }
1898
- function tt(t) {
1937
+ function rt(s) {
1899
1938
  try {
1900
- t.src = "about:blank", t.parentNode?.removeChild(t);
1939
+ s.src = "about:blank", s.parentNode?.removeChild(s);
1901
1940
  } catch {
1902
1941
  }
1903
1942
  }
1904
- function st(t, e) {
1905
- rt(t, e);
1943
+ function ot(s, e) {
1944
+ lt(s, e);
1906
1945
  }
1907
- function nt(t) {
1908
- t.style.display = "", t.style.visibility = "visible";
1946
+ function at(s) {
1947
+ s.style.display = "", s.style.visibility = "visible";
1909
1948
  }
1910
- function fe(t) {
1911
- t.style.display = "none", t.style.visibility = "hidden";
1949
+ function ge(s) {
1950
+ s.style.display = "none", s.style.visibility = "hidden";
1912
1951
  }
1913
- function it(t) {
1952
+ function ct(s) {
1914
1953
  try {
1915
- t.focus(), t.contentWindow?.focus();
1954
+ s.focus(), s.contentWindow?.focus();
1916
1955
  } catch {
1917
1956
  }
1918
1957
  }
1919
- function rt(t, e) {
1920
- e.width !== void 0 && (t.style.width = P(e.width)), e.height !== void 0 && (t.style.height = P(e.height));
1958
+ function lt(s, e) {
1959
+ e.width !== void 0 && (s.style.width = R(e.width)), e.height !== void 0 && (s.style.height = R(e.height));
1921
1960
  }
1922
- class Re extends Error {
1961
+ class ve extends Error {
1923
1962
  constructor(e = "Popup blocked by browser") {
1924
1963
  super(e), this.name = "PopupOpenError";
1925
1964
  }
1926
1965
  }
1927
- function ot(t) {
1928
- const { url: e, name: s, dimensions: n } = t, i = $(n.width, 500), r = $(n.height, 500), o = Math.floor(window.screenX + (window.outerWidth - i) / 2), a = Math.floor(window.screenY + (window.outerHeight - r) / 2), c = [
1966
+ function ut(s) {
1967
+ const { url: e, name: t, dimensions: n } = s, i = $(n.width, 500), r = $(n.height, 500), o = Math.floor(window.screenX + (window.outerWidth - i) / 2), a = Math.floor(window.screenY + (window.outerHeight - r) / 2), c = [
1929
1968
  `width=${i}`,
1930
1969
  `height=${r}`,
1931
1970
  `left=${o}`,
@@ -1937,32 +1976,32 @@ function ot(t) {
1937
1976
  "status=no",
1938
1977
  "resizable=yes",
1939
1978
  "scrollbars=yes"
1940
- ].join(","), l = window.open(e, s, c);
1941
- if (!l || lt(l))
1942
- throw new Re();
1979
+ ].join(","), l = window.open(e, t, c);
1980
+ if (!l || ft(l))
1981
+ throw new ve();
1943
1982
  return l;
1944
1983
  }
1945
- function at(t) {
1984
+ function ht(s) {
1946
1985
  try {
1947
- t.closed || t.close();
1986
+ s.closed || s.close();
1948
1987
  } catch {
1949
1988
  }
1950
1989
  }
1951
- function ct(t) {
1990
+ function dt(s) {
1952
1991
  try {
1953
- t.closed || t.focus();
1992
+ s.closed || s.focus();
1954
1993
  } catch {
1955
1994
  }
1956
1995
  }
1957
- function lt(t) {
1958
- if (!t) return !0;
1996
+ function ft(s) {
1997
+ if (!s) return !0;
1959
1998
  try {
1960
- return !!(t.closed || t.innerHeight === 0 || t.innerWidth === 0);
1999
+ return !!(s.closed || s.innerHeight === 0 || s.innerWidth === 0);
1961
2000
  } catch {
1962
2001
  return !0;
1963
2002
  }
1964
2003
  }
1965
- function ut(t, e, s = {}) {
2004
+ function pt(s, e, t = {}) {
1966
2005
  const {
1967
2006
  initialInterval: n = 100,
1968
2007
  // Start fast to catch quick closes
@@ -1970,18 +2009,18 @@ function ut(t, e, s = {}) {
1970
2009
  // Cap at 2 seconds
1971
2010
  multiplier: r = 1.5
1972
2011
  // Exponential backoff multiplier
1973
- } = s;
2012
+ } = t;
1974
2013
  let o = n, a, c = !1;
1975
2014
  const l = () => {
1976
2015
  try {
1977
2016
  e();
1978
- } catch (g) {
1979
- console.error("Error in popup close callback:", g);
2017
+ } catch (w) {
2018
+ console.error("Error in popup close callback:", w);
1980
2019
  }
1981
2020
  }, h = () => {
1982
2021
  if (!c) {
1983
2022
  try {
1984
- if (t.closed) {
2023
+ if (s.closed) {
1985
2024
  l();
1986
2025
  return;
1987
2026
  }
@@ -1996,34 +2035,34 @@ function ut(t, e, s = {}) {
1996
2035
  c = !0, clearTimeout(a);
1997
2036
  };
1998
2037
  }
1999
- function ht(t, e) {
2038
+ function mt(s, e) {
2000
2039
  try {
2001
- const s = $(e.width, t.outerWidth), n = $(
2040
+ const t = $(e.width, s.outerWidth), n = $(
2002
2041
  e.height,
2003
- t.outerHeight
2042
+ s.outerHeight
2004
2043
  );
2005
- t.resizeTo(s, n);
2044
+ s.resizeTo(t, n);
2006
2045
  } catch {
2007
2046
  }
2008
2047
  }
2009
- function dt(t) {
2010
- const { doc: e, dimensions: s, uid: n, tag: i } = t, r = e.createElement("div");
2048
+ function gt(s) {
2049
+ const { doc: e, dimensions: t, uid: n, tag: i } = s, r = e.createElement("div");
2011
2050
  return r.id = `forgeframe-container-${n}`, r.setAttribute("data-forgeframe-tag", i), Object.assign(r.style, {
2012
2051
  display: "inline-block",
2013
2052
  position: "relative",
2014
- width: P(s.width),
2015
- height: P(s.height),
2053
+ width: R(t.width),
2054
+ height: R(t.height),
2016
2055
  overflow: "hidden"
2017
2056
  }), r;
2018
2057
  }
2019
- function ft(t) {
2020
- const { doc: e, dimensions: s, cspNonce: n } = t, i = e.createElement("div");
2058
+ function yt(s) {
2059
+ const { doc: e, dimensions: t, cspNonce: n } = s, i = e.createElement("div");
2021
2060
  Object.assign(i.style, {
2022
2061
  display: "flex",
2023
2062
  alignItems: "center",
2024
2063
  justifyContent: "center",
2025
- width: P(s.width),
2026
- height: P(s.height),
2064
+ width: R(t.width),
2065
+ height: R(t.height),
2027
2066
  backgroundColor: "#f5f5f5",
2028
2067
  position: "absolute",
2029
2068
  top: "0",
@@ -2046,20 +2085,20 @@ function ft(t) {
2046
2085
  }
2047
2086
  `, i.appendChild(o), i.appendChild(r), i;
2048
2087
  }
2049
- function pt(t, e = 200) {
2050
- return new Promise((s) => {
2051
- t.style.opacity = "0", t.style.transition = `opacity ${e}ms ease-in`, t.offsetHeight, t.style.opacity = "1", setTimeout(s, e);
2088
+ function wt(s, e = 200) {
2089
+ return new Promise((t) => {
2090
+ s.style.opacity = "0", s.style.transition = `opacity ${e}ms ease-in`, s.offsetHeight, s.style.opacity = "1", setTimeout(t, e);
2052
2091
  });
2053
2092
  }
2054
- function mt(t, e = 200) {
2055
- return new Promise((s) => {
2056
- t.style.transition = `opacity ${e}ms ease-out`, t.style.opacity = "0", setTimeout(s, e);
2093
+ function _t(s, e = 200) {
2094
+ return new Promise((t) => {
2095
+ s.style.transition = `opacity ${e}ms ease-out`, s.style.opacity = "0", setTimeout(t, e);
2057
2096
  });
2058
2097
  }
2059
- async function gt(t, e, s) {
2060
- e && (await mt(e, 150), e.remove()), s.style.display = "", s.style.visibility = "visible", s.style.opacity = "0", await pt(s, 150);
2098
+ async function Et(s, e, t) {
2099
+ e && (await _t(e, 150), e.remove()), t.style.display = "", t.style.visibility = "visible", t.style.opacity = "0", await wt(t, 150);
2061
2100
  }
2062
- class Q {
2101
+ class se {
2063
2102
  /** Event emitter for lifecycle events. */
2064
2103
  event;
2065
2104
  /** Arbitrary state storage for the component instance. */
@@ -2092,6 +2131,10 @@ class Q {
2092
2131
  /** @internal */
2093
2132
  hostWindow = null;
2094
2133
  /** @internal */
2134
+ openedHostDomain = null;
2135
+ /** @internal */
2136
+ dynamicUrlTrustedOrigin = null;
2137
+ /** @internal */
2095
2138
  iframe = null;
2096
2139
  /** @internal */
2097
2140
  container = null;
@@ -2109,25 +2152,20 @@ class Q {
2109
2152
  * @param options - Component configuration options
2110
2153
  * @param props - Initial props to pass to the component
2111
2154
  */
2112
- constructor(e, s = {}) {
2113
- this._uid = Ie(), this.options = this.normalizeOptions(e), this.context = this.options.defaultContext, this.event = new me(), this.cleanup = new De();
2114
- const n = this.buildTrustedDomains();
2115
- this.messenger = new ye(this.uid, window, j(), n), this.bridge = new B(this.messenger);
2116
- const i = this.createPropContext();
2117
- this.props = le(s, this.options.props, i), this.setupMessageHandlers(), this.setupCleanup();
2155
+ constructor(e, t = {}) {
2156
+ this._uid = Fe(), this.options = this.normalizeOptions(e), this.context = this.options.defaultContext, this.event = new we(), this.cleanup = new Ne();
2157
+ const n = this.createPropContext();
2158
+ this.props = de(t, this.options.props, n);
2159
+ const i = this.buildTrustedDomains();
2160
+ this.messenger = new Ee(this.uid, window, q(), i), this.bridge = new J(this.messenger), this.setupMessageHandlers(), this.setupCleanup();
2118
2161
  }
2119
2162
  /**
2120
2163
  * Builds the list of trusted domains for messenger communication.
2121
2164
  * @internal
2122
2165
  */
2123
2166
  buildTrustedDomains() {
2124
- const e = [], s = typeof this.options.url == "function" ? this.options.url(this.props) : this.options.url;
2125
- try {
2126
- const n = new URL(s);
2127
- e.push(n.origin);
2128
- } catch {
2129
- }
2130
- if (this.options.domain) {
2167
+ const e = [], t = this.resolveUrlOrigin(this.resolveUrl());
2168
+ if (t && (e.push(t), this.dynamicUrlTrustedOrigin = t), this.options.domain) {
2131
2169
  if (typeof this.options.domain == "string")
2132
2170
  e.push(this.options.domain);
2133
2171
  else if (Array.isArray(this.options.domain))
@@ -2155,12 +2193,12 @@ class Q {
2155
2193
  * await instance.render(document.getElementById('target'), 'popup');
2156
2194
  * ```
2157
2195
  */
2158
- async render(e, s) {
2196
+ async render(e, t) {
2159
2197
  if (this.destroyed)
2160
2198
  throw new Error("Component has been destroyed");
2161
2199
  if (this.rendered)
2162
2200
  throw new Error("Component has already been rendered");
2163
- this.context = s ?? this.options.defaultContext, this.checkEligibility(), Xe(this.props, this.options.props), this.container = this.resolveContainer(e), this.event.emit(f.PRERENDER), this.callPropCallback("onPrerender"), await this.prerender(), this.event.emit(f.PRERENDERED), this.callPropCallback("onPrerendered"), this.event.emit(f.RENDER), this.callPropCallback("onRender"), await this.open(), await this.waitForHost(), this.context === p.IFRAME && this.iframe && this.prerenderElement && (await gt(
2201
+ this.context = t ?? this.options.defaultContext, this.checkEligibility(), Ye(this.props, this.options.props), this.options.validate?.({ props: this.props }), this.container = this.resolveContainer(e), this.event.emit(f.PRERENDER), this.callPropCallback("onPrerender"), await this.prerender(), this.event.emit(f.PRERENDERED), this.callPropCallback("onPrerendered"), this.event.emit(f.RENDER), this.callPropCallback("onRender"), await this.open(), await this.waitForHost(), this.context === p.IFRAME && this.iframe && this.prerenderElement && (await Et(
2164
2202
  this.container,
2165
2203
  this.prerenderElement,
2166
2204
  this.iframe
@@ -2177,8 +2215,8 @@ class Q {
2177
2215
  * @param container - CSS selector or HTMLElement to render into
2178
2216
  * @param context - Override the default rendering context
2179
2217
  */
2180
- async renderTo(e, s, n) {
2181
- return this.render(s, n);
2218
+ async renderTo(e, t, n) {
2219
+ return this.render(t, n);
2182
2220
  }
2183
2221
  /**
2184
2222
  * Closes and destroys the component.
@@ -2196,7 +2234,7 @@ class Q {
2196
2234
  * For iframes, focuses the iframe element. For popups, brings the window to front.
2197
2235
  */
2198
2236
  async focus() {
2199
- this.context === p.IFRAME && this.iframe ? it(this.iframe) : this.context === p.POPUP && this.hostWindow && ct(this.hostWindow), this.event.emit(f.FOCUS), this.callPropCallback("onFocus");
2237
+ this.context === p.IFRAME && this.iframe ? ct(this.iframe) : this.context === p.POPUP && this.hostWindow && dt(this.hostWindow), this.event.emit(f.FOCUS), this.callPropCallback("onFocus");
2200
2238
  }
2201
2239
  /**
2202
2240
  * Resizes the component to the specified dimensions.
@@ -2204,7 +2242,7 @@ class Q {
2204
2242
  * @param dimensions - New width and height for the component
2205
2243
  */
2206
2244
  async resize(e) {
2207
- this.context === p.IFRAME && this.iframe ? st(this.iframe, e) : this.context === p.POPUP && this.hostWindow && ht(this.hostWindow, e), this.event.emit(f.RESIZE, e), this.callPropCallback("onResize", e);
2245
+ this.context === p.IFRAME && this.iframe ? ot(this.iframe, e) : this.context === p.POPUP && this.hostWindow && mt(this.hostWindow, e), this.event.emit(f.RESIZE, e), this.callPropCallback("onResize", e);
2208
2246
  }
2209
2247
  /**
2210
2248
  * Shows the component if hidden.
@@ -2213,7 +2251,7 @@ class Q {
2213
2251
  * Only applicable to iframe context.
2214
2252
  */
2215
2253
  async show() {
2216
- this.context === p.IFRAME && this.iframe && nt(this.iframe);
2254
+ this.context === p.IFRAME && this.iframe && at(this.iframe);
2217
2255
  }
2218
2256
  /**
2219
2257
  * Hides the component.
@@ -2222,7 +2260,7 @@ class Q {
2222
2260
  * Only applicable to iframe context.
2223
2261
  */
2224
2262
  async hide() {
2225
- this.context === p.IFRAME && this.iframe && fe(this.iframe);
2263
+ this.context === p.IFRAME && this.iframe && ge(this.iframe);
2226
2264
  }
2227
2265
  /**
2228
2266
  * Updates the component props and sends them to the host.
@@ -2233,27 +2271,33 @@ class Q {
2233
2271
  * @param newProps - Partial props object to merge with existing props
2234
2272
  */
2235
2273
  async updateProps(e) {
2236
- const s = this.createPropContext();
2237
- if (this.props = le(
2274
+ const t = this.createPropContext(), n = de(
2238
2275
  { ...this.props, ...e },
2239
2276
  this.options.props,
2240
- s
2241
- ), this.hostWindow && !Ee(this.hostWindow)) {
2242
- const n = this.getHostDomain(), i = ue(
2243
- this.props,
2244
- this.options.props,
2277
+ t
2278
+ );
2279
+ this.options.validate?.({ props: n });
2280
+ const i = this.resolveUrl(n), r = this.resolveUrlOrigin(i);
2281
+ if (this.rendered && this.openedHostDomain && r && r !== this.openedHostDomain)
2282
+ throw new Error(
2283
+ `Cannot change component URL origin after render (from "${this.openedHostDomain}" to "${r}")`
2284
+ );
2285
+ if (this.props = n, this.rendered || this.syncTrustedDomainForUrl(i), this.hostWindow && !Pe(this.hostWindow)) {
2286
+ const o = this.openedHostDomain ?? this.getHostDomain(), a = fe(
2245
2287
  n,
2246
- _e(this.hostWindow)
2247
- ), r = he(
2248
- i,
2288
+ this.options.props,
2289
+ o,
2290
+ be(this.hostWindow)
2291
+ ), c = pe(
2292
+ a,
2249
2293
  this.options.props,
2250
2294
  this.bridge
2251
2295
  );
2252
2296
  await this.messenger.send(
2253
2297
  this.hostWindow,
2254
- n,
2298
+ o,
2255
2299
  u.PROPS,
2256
- r
2300
+ c
2257
2301
  );
2258
2302
  }
2259
2303
  this.event.emit(f.PROPS, this.props), this.callPropCallback("onProps", this.props);
@@ -2264,7 +2308,7 @@ class Q {
2264
2308
  * @returns A new unrendered component instance with identical configuration
2265
2309
  */
2266
2310
  clone() {
2267
- return new Q(this.options, this.props);
2311
+ return new se(this.options, this.props);
2268
2312
  }
2269
2313
  /**
2270
2314
  * Checks if the component is eligible to render based on the eligible option.
@@ -2283,11 +2327,54 @@ class Q {
2283
2327
  ...e,
2284
2328
  props: e.props ?? {},
2285
2329
  defaultContext: e.defaultContext ?? p.IFRAME,
2286
- dimensions: typeof e.dimensions == "function" ? e.dimensions(this.props) : e.dimensions ?? { width: "100%", height: "100%" },
2330
+ dimensions: e.dimensions ?? { width: "100%", height: "100%" },
2287
2331
  timeout: e.timeout ?? 1e4,
2288
2332
  children: e.children
2289
2333
  };
2290
2334
  }
2335
+ /**
2336
+ * Resolves the host URL from static or function options.
2337
+ * @internal
2338
+ */
2339
+ resolveUrl(e = this.props) {
2340
+ return typeof this.options.url == "function" ? this.options.url(e) : this.options.url;
2341
+ }
2342
+ /**
2343
+ * Resolves dimensions from static or function options.
2344
+ * @internal
2345
+ */
2346
+ resolveDimensions() {
2347
+ return typeof this.options.dimensions == "function" ? this.options.dimensions(this.props) : this.options.dimensions;
2348
+ }
2349
+ /**
2350
+ * Resolves a URL to an origin, supporting relative URLs.
2351
+ * @internal
2352
+ */
2353
+ resolveUrlOrigin(e) {
2354
+ try {
2355
+ return new URL(e, window.location.origin).origin;
2356
+ } catch {
2357
+ return null;
2358
+ }
2359
+ }
2360
+ /**
2361
+ * Returns true when the domain option explicitly includes this origin.
2362
+ * @internal
2363
+ */
2364
+ isExplicitDomainTrust(e) {
2365
+ return !this.options.domain || this.options.domain instanceof RegExp ? !1 : typeof this.options.domain == "string" ? this.options.domain === e : this.options.domain.includes(e);
2366
+ }
2367
+ /**
2368
+ * Ensures the messenger trusts the origin for a resolved host URL.
2369
+ * @internal
2370
+ */
2371
+ syncTrustedDomainForUrl(e) {
2372
+ const t = this.resolveUrlOrigin(e);
2373
+ if (!t)
2374
+ return;
2375
+ const n = this.dynamicUrlTrustedOrigin;
2376
+ n && n !== t && !this.isExplicitDomainTrust(n) && this.messenger.removeTrustedDomain(n), this.messenger.addTrustedDomain(t), this.dynamicUrlTrustedOrigin = t;
2377
+ }
2291
2378
  /**
2292
2379
  * Creates the prop context passed to prop callbacks and validators.
2293
2380
  * @internal
@@ -2312,10 +2399,10 @@ class Q {
2312
2399
  if (!e)
2313
2400
  throw new Error("Container is required for rendering");
2314
2401
  if (typeof e == "string") {
2315
- const s = document.querySelector(e);
2316
- if (!s)
2402
+ const t = document.querySelector(e);
2403
+ if (!t)
2317
2404
  throw new Error(`Container "${e}" not found`);
2318
- return s;
2405
+ return t;
2319
2406
  }
2320
2407
  return e;
2321
2408
  }
@@ -2335,10 +2422,10 @@ class Q {
2335
2422
  */
2336
2423
  async prerender() {
2337
2424
  if (!this.container) return;
2338
- const e = this.options.prerenderTemplate ?? ft, s = this.options.containerTemplate ?? dt, n = this.options.dimensions, i = this.props.cspNonce;
2425
+ const e = this.options.prerenderTemplate ?? yt, t = this.options.containerTemplate ?? gt, n = this.resolveDimensions(), i = this.props.cspNonce;
2339
2426
  if (this.context === p.IFRAME) {
2340
2427
  const c = this.buildWindowName();
2341
- this.iframe = this.createIframeElement(c), fe(this.iframe);
2428
+ this.iframe = this.createIframeElement(c), ge(this.iframe);
2342
2429
  }
2343
2430
  const r = {
2344
2431
  uid: this.uid,
@@ -2368,7 +2455,7 @@ class Q {
2368
2455
  close: () => this.close(),
2369
2456
  focus: () => this.focus(),
2370
2457
  cspNonce: i
2371
- }, a = s(o);
2458
+ }, a = t(o);
2372
2459
  a && (this.container.appendChild(a), this.container = a), this.prerenderElement && !this.prerenderElement.parentNode && this.container.appendChild(this.prerenderElement), this.iframe && !this.iframe.parentNode && this.container.appendChild(this.iframe);
2373
2460
  }
2374
2461
  /**
@@ -2377,82 +2464,112 @@ class Q {
2377
2464
  * @internal
2378
2465
  */
2379
2466
  createIframeElement(e) {
2380
- const s = document.createElement("iframe"), n = this.options.dimensions, i = typeof this.options.attributes == "function" ? this.options.attributes(this.props) : this.options.attributes ?? {}, r = typeof this.options.style == "function" ? this.options.style(this.props) : this.options.style ?? {};
2381
- s.name = e, s.setAttribute("frameborder", "0"), s.setAttribute("allowtransparency", "true"), s.setAttribute("scrolling", "auto"), n.width !== void 0 && (s.style.width = typeof n.width == "number" ? `${n.width}px` : n.width), n.height !== void 0 && (s.style.height = typeof n.height == "number" ? `${n.height}px` : n.height);
2467
+ const t = document.createElement("iframe"), n = this.resolveDimensions(), i = typeof this.options.attributes == "function" ? this.options.attributes(this.props) : this.options.attributes ?? {}, r = typeof this.options.style == "function" ? this.options.style(this.props) : this.options.style ?? {};
2468
+ t.name = e, t.setAttribute("frameborder", "0"), t.setAttribute("allowtransparency", "true"), t.setAttribute("scrolling", "auto"), n.width !== void 0 && (t.style.width = typeof n.width == "number" ? `${n.width}px` : n.width), n.height !== void 0 && (t.style.height = typeof n.height == "number" ? `${n.height}px` : n.height);
2382
2469
  for (const [o, a] of Object.entries(i))
2383
- a !== void 0 && (typeof a == "boolean" ? a && s.setAttribute(o, "") : s.setAttribute(o, a));
2470
+ a !== void 0 && (typeof a == "boolean" ? a && t.setAttribute(o, "") : t.setAttribute(o, a));
2384
2471
  for (const [o, a] of Object.entries(r)) {
2385
2472
  if (a === void 0) continue;
2386
2473
  const c = typeof a == "number" ? `${a}px` : a;
2387
- s.style.setProperty(
2474
+ t.style.setProperty(
2388
2475
  o.replace(/([A-Z])/g, "-$1").toLowerCase(),
2389
2476
  String(c)
2390
2477
  );
2391
2478
  }
2392
- return i.sandbox || s.setAttribute(
2479
+ return i.sandbox || t.setAttribute(
2393
2480
  "sandbox",
2394
2481
  "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
2395
- ), s;
2482
+ ), t;
2396
2483
  }
2397
2484
  /**
2398
2485
  * Opens the host window (iframe or popup).
2399
2486
  * @internal
2400
2487
  */
2401
2488
  async open() {
2402
- const e = this.buildUrl();
2489
+ const e = this.resolveUrl();
2490
+ this.syncTrustedDomainForUrl(e), this.openedHostDomain = this.resolveUrlOrigin(e);
2491
+ const t = this.buildUrl(e), n = this.buildBodyParams(), i = n.toString().length > 0;
2403
2492
  if (this.context === p.IFRAME) {
2404
2493
  if (!this.iframe)
2405
2494
  throw new Error("Iframe not created during prerender");
2406
- this.iframe.src = e, this.hostWindow = this.iframe.contentWindow;
2495
+ i ? this.submitBodyForm(this.iframe.name, t, n) : this.iframe.src = t, this.hostWindow = this.iframe.contentWindow;
2407
2496
  } else {
2408
- const s = this.buildWindowName();
2409
- this.hostWindow = ot({
2410
- url: e,
2411
- name: s,
2412
- dimensions: this.options.dimensions
2413
- });
2414
- const n = ut(this.hostWindow, () => {
2497
+ const r = this.buildWindowName();
2498
+ this.hostWindow = ut({
2499
+ url: i ? "about:blank" : t,
2500
+ name: r,
2501
+ dimensions: this.resolveDimensions()
2502
+ }), i && this.submitBodyForm(r, t, n);
2503
+ const o = pt(this.hostWindow, () => {
2415
2504
  this.destroy();
2416
2505
  });
2417
- this.cleanup.register(n);
2506
+ this.cleanup.register(o);
2418
2507
  }
2419
- this.hostWindow && Be(this.uid, this.hostWindow);
2508
+ this.hostWindow && Je(this.uid, this.hostWindow);
2420
2509
  }
2421
2510
  /**
2422
2511
  * Builds the URL for the host window including query parameters.
2423
2512
  * @internal
2424
2513
  */
2425
- buildUrl() {
2426
- const e = typeof this.options.url == "function" ? this.options.url(this.props) : this.options.url, n = Ye(this.props, this.options.props).toString();
2514
+ buildUrl(e = this.resolveUrl()) {
2515
+ const n = Ze(this.props, this.options.props).toString();
2427
2516
  if (!n) return e;
2428
2517
  const i = e.includes("?") ? "&" : "?";
2429
2518
  return `${e}${i}${n}`;
2430
2519
  }
2520
+ /**
2521
+ * Builds POST body parameters from props marked with bodyParam.
2522
+ * @internal
2523
+ */
2524
+ buildBodyParams() {
2525
+ return Qe(this.props, this.options.props);
2526
+ }
2527
+ /**
2528
+ * Submits a hidden form to navigate a target window via POST.
2529
+ * @internal
2530
+ */
2531
+ submitBodyForm(e, t, n) {
2532
+ const i = this.container?.ownerDocument ?? document, r = i.body ?? i.documentElement;
2533
+ if (!r)
2534
+ throw new Error("Document root is unavailable for bodyParam form submission");
2535
+ const o = i.createElement("form");
2536
+ o.method = "POST", o.action = t, o.target = e, o.style.display = "none";
2537
+ for (const [a, c] of n.entries()) {
2538
+ const l = i.createElement("input");
2539
+ l.type = "hidden", l.name = a, l.value = c, o.appendChild(l);
2540
+ }
2541
+ r.appendChild(o);
2542
+ try {
2543
+ o.submit();
2544
+ } finally {
2545
+ o.remove();
2546
+ }
2547
+ }
2431
2548
  /**
2432
2549
  * Builds the window.name payload for the host window.
2433
2550
  * @internal
2434
2551
  */
2435
2552
  buildWindowName() {
2436
- const e = this.getHostDomain(), s = ue(
2553
+ const e = this.getHostDomain(), t = fe(
2437
2554
  this.props,
2438
2555
  this.options.props,
2439
2556
  e,
2440
2557
  !1
2441
2558
  // Assume cross-domain for initial payload
2442
- ), n = he(
2443
- s,
2559
+ ), n = pe(
2560
+ t,
2444
2561
  this.options.props,
2445
2562
  this.bridge
2446
- ), i = this.buildNestedHostRefs(), r = Me({
2563
+ ), i = this.buildNestedHostRefs(), r = Be({
2447
2564
  uid: this.uid,
2448
2565
  tag: this.options.tag,
2449
2566
  context: this.context,
2450
- consumerDomain: j(),
2567
+ consumerDomain: q(),
2451
2568
  props: n,
2452
2569
  exports: this.createConsumerExports(),
2453
2570
  children: i
2454
2571
  });
2455
- return He(r);
2572
+ return We(r);
2456
2573
  }
2457
2574
  /**
2458
2575
  * Builds component references for nested host components.
@@ -2460,15 +2577,24 @@ class Q {
2460
2577
  */
2461
2578
  buildNestedHostRefs() {
2462
2579
  if (!this.options.children) return;
2463
- const e = this.options.children({ props: this.props }), s = {};
2580
+ const e = this.options.children({ props: this.props }), t = {};
2464
2581
  for (const [n, i] of Object.entries(e)) {
2465
- const r = i;
2466
- s[n] = {
2467
- tag: r.tag ?? n,
2468
- url: typeof r.url == "function" ? r.url.toString() : r.url ?? ""
2582
+ const r = Ct(i);
2583
+ if (!r)
2584
+ throw new Error(`Nested component "${n}" is missing component metadata`);
2585
+ if (typeof r.url != "string")
2586
+ throw new Error(
2587
+ `Nested component "${n}" must use a static string URL. Function URLs are not supported in children.`
2588
+ );
2589
+ t[n] = {
2590
+ tag: r.tag,
2591
+ url: r.url,
2592
+ props: r.props,
2593
+ dimensions: typeof r.dimensions == "function" ? void 0 : r.dimensions,
2594
+ defaultContext: r.defaultContext
2469
2595
  };
2470
2596
  }
2471
- return Object.keys(s).length > 0 ? s : void 0;
2597
+ return Object.keys(t).length > 0 ? t : void 0;
2472
2598
  }
2473
2599
  /**
2474
2600
  * Creates the exports object sent to the host.
@@ -2491,21 +2617,16 @@ class Q {
2491
2617
  * @internal
2492
2618
  */
2493
2619
  getHostDomain() {
2494
- const e = typeof this.options.url == "function" ? this.options.url(this.props) : this.options.url;
2495
- try {
2496
- return new URL(e, window.location.origin).origin;
2497
- } catch {
2498
- return "*";
2499
- }
2620
+ return this.openedHostDomain ? this.openedHostDomain : this.resolveUrlOrigin(this.resolveUrl()) ?? "*";
2500
2621
  }
2501
2622
  /**
2502
2623
  * Waits for the host to send the init message.
2503
2624
  * @internal
2504
2625
  */
2505
2626
  async waitForHost() {
2506
- this.initPromise = ge();
2627
+ this.initPromise = _e();
2507
2628
  try {
2508
- await Ne(
2629
+ await ke(
2509
2630
  this.initPromise.promise,
2510
2631
  this.options.timeout,
2511
2632
  `Host component "${this.options.tag}" (uid: ${this._uid}) did not initialize within ${this.options.timeout}ms. Check that the host page loads correctly and calls the initialization code.`
@@ -2522,21 +2643,21 @@ class Q {
2522
2643
  this.messenger.on(u.INIT, () => (this.initPromise && this.initPromise.resolve(), { success: !0 })), this.messenger.on(u.CLOSE, async () => (await this.close(), { success: !0 })), this.messenger.on(u.RESIZE, async (e) => (await this.resize(e), { success: !0 })), this.messenger.on(u.FOCUS, async () => (await this.focus(), { success: !0 })), this.messenger.on(u.SHOW, async () => (await this.show(), { success: !0 })), this.messenger.on(u.HIDE, async () => (await this.hide(), { success: !0 })), this.messenger.on(
2523
2644
  u.ERROR,
2524
2645
  async (e) => {
2525
- const s = new Error(e.message);
2526
- return s.stack = e.stack, this.handleError(s), { success: !0 };
2646
+ const t = new Error(e.message);
2647
+ return t.stack = e.stack, this.handleError(t), { success: !0 };
2527
2648
  }
2528
2649
  ), this.messenger.on(u.EXPORT, async (e) => (this.exports = e, { success: !0 })), this.messenger.on(u.CONSUMER_EXPORT, async (e) => (this.consumerExports = e, { success: !0 })), this.messenger.on(
2529
2650
  u.GET_SIBLINGS,
2530
2651
  async (e) => {
2531
- const s = [], n = Pt(e.tag);
2652
+ const t = [], n = xt(e.tag);
2532
2653
  if (n)
2533
2654
  for (const i of n.instances)
2534
- i.uid !== e.uid && s.push({
2655
+ i.uid !== e.uid && t.push({
2535
2656
  uid: i.uid,
2536
2657
  tag: e.tag,
2537
2658
  exports: i.exports
2538
2659
  });
2539
- return s;
2660
+ return t;
2540
2661
  }
2541
2662
  );
2542
2663
  }
@@ -2546,7 +2667,7 @@ class Q {
2546
2667
  */
2547
2668
  setupCleanup() {
2548
2669
  this.cleanup.register(() => {
2549
- this.messenger.destroy(), this.bridge.destroy(), this.event.removeAllListeners(), Je(this.uid);
2670
+ this.messenger.destroy(), this.bridge.destroy(), Xe(this.uid);
2550
2671
  });
2551
2672
  }
2552
2673
  /**
@@ -2560,11 +2681,11 @@ class Q {
2560
2681
  * Calls a prop callback if it exists.
2561
2682
  * @internal
2562
2683
  */
2563
- callPropCallback(e, ...s) {
2684
+ callPropCallback(e, ...t) {
2564
2685
  const n = this.props[e];
2565
2686
  if (typeof n == "function")
2566
2687
  try {
2567
- const i = n(...s);
2688
+ const i = n(...t);
2568
2689
  i && typeof i == "object" && "catch" in i && typeof i.catch == "function" && i.catch((r) => {
2569
2690
  console.error(`Error in async ${e} callback:`, r);
2570
2691
  });
@@ -2579,18 +2700,20 @@ class Q {
2579
2700
  async destroy() {
2580
2701
  this.destroyed || (this.destroyed = !0, this.initPromise && (this.initPromise.reject(
2581
2702
  new Error(`Component "${this.options.tag}" was destroyed before initialization completed`)
2582
- ), this.initPromise = null), this.iframe && (tt(this.iframe), this.iframe = null), this.context === p.POPUP && this.hostWindow && at(this.hostWindow), this.hostWindow = null, this.prerenderElement && (this.prerenderElement.remove(), this.prerenderElement = null), await this.cleanup.cleanup(), this.event.emit(f.DESTROY), this.callPropCallback("onDestroy"));
2703
+ ), this.initPromise = null), this.iframe && (rt(this.iframe), this.iframe = null), this.context === p.POPUP && this.hostWindow && ht(this.hostWindow), this.hostWindow = null, this.openedHostDomain = null, this.dynamicUrlTrustedOrigin = null, this.prerenderElement && (this.prerenderElement.remove(), this.prerenderElement = null), await this.cleanup.cleanup(), this.event.emit(f.DESTROY), this.callPropCallback("onDestroy"), this.event.removeAllListeners());
2583
2704
  }
2584
2705
  }
2585
- class yt {
2706
+ class bt {
2586
2707
  /**
2587
2708
  * Creates a new HostComponent instance.
2588
2709
  *
2589
2710
  * @param payload - The payload parsed from window.name
2590
2711
  * @param propDefinitions - Optional prop definitions for deserialization
2712
+ * @param allowedConsumerDomains - Optional allowlist of consumer domains
2713
+ * @param deferInit - Whether to defer INIT until a later explicit flush
2591
2714
  */
2592
- constructor(e, s = {}) {
2593
- this.propDefinitions = s, this.uid = e.uid, this.tag = e.tag, this.consumerDomain = e.consumerDomain, this.event = new me(), this.messenger = new ye(this.uid, window, j(), this.consumerDomain), this.setupMessageHandlers(), this.consumerWindow = this.resolveConsumerWindow(), this.bridge = new B(this.messenger), this.hostProps = this.buildHostProps(e), window.hostProps = this.hostProps, this.sendInit();
2715
+ constructor(e, t = {}, n, i = !1) {
2716
+ this.propDefinitions = t, this.allowedConsumerDomains = n, this.deferInit = i, this.uid = e.uid, this.tag = e.tag, this.consumerDomain = e.consumerDomain, this.validateConsumerDomain(), this.event = new we(), this.messenger = new Ee(this.uid, window, q(), this.consumerDomain), this.setupMessageHandlers(), this.consumerWindow = this.resolveConsumerWindow(), this.bridge = new J(this.messenger), this.hostProps = this.buildHostProps(e), this.exposeHostProps(), this.deferInit || this.flushInit();
2594
2717
  }
2595
2718
  /** The hostProps object containing props and control methods passed from the consumer. */
2596
2719
  hostProps;
@@ -2614,6 +2737,59 @@ class yt {
2614
2737
  consumerProps;
2615
2738
  /** @internal */
2616
2739
  initError = null;
2740
+ /** @internal */
2741
+ destroyed = !1;
2742
+ /** @internal */
2743
+ initSent = !1;
2744
+ /** @internal */
2745
+ deferredInitFlushScheduled = !1;
2746
+ /**
2747
+ * Ensures the INIT handshake is sent at most once.
2748
+ * @internal
2749
+ */
2750
+ flushInit() {
2751
+ this.destroyed || this.initSent || (this.initSent = !0, this.sendInit());
2752
+ }
2753
+ /**
2754
+ * Schedules deferred INIT flush on the next microtask.
2755
+ * This preserves legacy hostProps-only usage while giving same-tick
2756
+ * host configuration a chance to run allowlist checks first.
2757
+ * @internal
2758
+ */
2759
+ scheduleDeferredInitFlush() {
2760
+ this.deferredInitFlushScheduled || this.destroyed || this.initSent || (this.deferredInitFlushScheduled = !0, queueMicrotask(() => {
2761
+ this.deferredInitFlushScheduled = !1, this.flushInit();
2762
+ }));
2763
+ }
2764
+ /**
2765
+ * Exposes hostProps on window and lazily flushes deferred init on first access.
2766
+ * @internal
2767
+ */
2768
+ exposeHostProps() {
2769
+ const e = window;
2770
+ try {
2771
+ Object.defineProperty(e, "hostProps", {
2772
+ configurable: !0,
2773
+ enumerable: !0,
2774
+ get: () => (this.deferInit && !this.initSent && !this.destroyed && this.scheduleDeferredInitFlush(), this.hostProps),
2775
+ set: (t) => {
2776
+ t && (this.hostProps = t);
2777
+ }
2778
+ });
2779
+ } catch {
2780
+ e.hostProps = this.hostProps;
2781
+ }
2782
+ }
2783
+ /**
2784
+ * Validates that the consumer domain is allowed.
2785
+ * @internal
2786
+ */
2787
+ validateConsumerDomain() {
2788
+ if (this.allowedConsumerDomains && !L(this.allowedConsumerDomains, this.consumerDomain))
2789
+ throw new Error(
2790
+ `Consumer domain "${this.consumerDomain}" is not allowed for component "${this.tag}"`
2791
+ );
2792
+ }
2617
2793
  /**
2618
2794
  * Returns the hostProps object.
2619
2795
  *
@@ -2627,12 +2803,12 @@ class yt {
2627
2803
  * @internal
2628
2804
  */
2629
2805
  resolveConsumerWindow() {
2630
- if (Le()) {
2631
- const e = Fe();
2806
+ if (Ue()) {
2807
+ const e = Ae();
2632
2808
  if (e) return e;
2633
2809
  }
2634
- if (Ae()) {
2635
- const e = $e();
2810
+ if (Me()) {
2811
+ const e = He();
2636
2812
  if (e) return e;
2637
2813
  }
2638
2814
  throw new Error("Could not resolve consumer window");
@@ -2642,7 +2818,7 @@ class yt {
2642
2818
  * @internal
2643
2819
  */
2644
2820
  buildHostProps(e) {
2645
- const s = de(
2821
+ const t = me(
2646
2822
  e.props,
2647
2823
  this.propDefinitions,
2648
2824
  this.messenger,
@@ -2650,8 +2826,8 @@ class yt {
2650
2826
  this.consumerWindow,
2651
2827
  this.consumerDomain
2652
2828
  );
2653
- return this.consumerProps = s, {
2654
- ...s,
2829
+ return this.consumerProps = t, {
2830
+ ...t,
2655
2831
  uid: this.uid,
2656
2832
  tag: this.tag,
2657
2833
  close: () => this.close(),
@@ -2685,11 +2861,11 @@ class yt {
2685
2861
  { uid: this.uid, tag: this.tag }
2686
2862
  );
2687
2863
  } catch (e) {
2688
- const s = e instanceof Error ? e : new Error(String(e));
2689
- this.initError = s, this.event.emit(f.ERROR, {
2864
+ const t = e instanceof Error ? e : new Error(String(e));
2865
+ this.initError = t, this.event.emit(f.ERROR, {
2690
2866
  type: "init_failed",
2691
- message: `Failed to initialize host component: ${s.message}`,
2692
- error: s
2867
+ message: `Failed to initialize host component: ${t.message}`,
2868
+ error: t
2693
2869
  }), console.error("Failed to send init message:", e);
2694
2870
  }
2695
2871
  }
@@ -2827,10 +3003,10 @@ class yt {
2827
3003
  */
2828
3004
  buildNestedComponents(e) {
2829
3005
  if (!e) return;
2830
- const s = {};
3006
+ const t = {};
2831
3007
  for (const [n, i] of Object.entries(e))
2832
3008
  try {
2833
- s[n] = Se({
3009
+ t[n] = xe({
2834
3010
  tag: i.tag,
2835
3011
  url: i.url,
2836
3012
  props: i.props,
@@ -2840,7 +3016,7 @@ class yt {
2840
3016
  } catch (r) {
2841
3017
  console.warn(`Failed to create nested component "${n}":`, r);
2842
3018
  }
2843
- return Object.keys(s).length > 0 ? s : void 0;
3019
+ return Object.keys(t).length > 0 ? t : void 0;
2844
3020
  }
2845
3021
  /**
2846
3022
  * Sets up message handlers for consumer communication.
@@ -2849,7 +3025,7 @@ class yt {
2849
3025
  setupMessageHandlers() {
2850
3026
  this.messenger.on(u.PROPS, (e) => {
2851
3027
  try {
2852
- const s = de(
3028
+ const t = me(
2853
3029
  e,
2854
3030
  this.propDefinitions,
2855
3031
  this.messenger,
@@ -2857,16 +3033,16 @@ class yt {
2857
3033
  this.consumerWindow,
2858
3034
  this.consumerDomain
2859
3035
  );
2860
- Object.assign(this.hostProps, s);
3036
+ Object.assign(this.hostProps, t);
2861
3037
  for (const n of this.propsHandlers)
2862
3038
  try {
2863
- n(s);
3039
+ n(t);
2864
3040
  } catch (i) {
2865
3041
  console.error("Error in props handler:", i);
2866
3042
  }
2867
- return this.event.emit(f.PROPS, s), { success: !0 };
2868
- } catch (s) {
2869
- const n = s instanceof Error ? s : new Error(String(s));
3043
+ return this.event.emit(f.PROPS, t), { success: !0 };
3044
+ } catch (t) {
3045
+ const n = t instanceof Error ? t : new Error(String(t));
2870
3046
  throw console.error("Error deserializing props:", n), this.event.emit(f.ERROR, n), n;
2871
3047
  }
2872
3048
  });
@@ -2875,145 +3051,172 @@ class yt {
2875
3051
  * Destroys the host component and cleans up resources.
2876
3052
  */
2877
3053
  destroy() {
2878
- this.messenger.destroy(), this.bridge.destroy(), this.event.removeAllListeners(), this.propsHandlers.clear();
3054
+ this.destroyed || (this.destroyed = !0, this.deferredInitFlushScheduled = !1, this.messenger.destroy(), this.bridge.destroy(), this.event.removeAllListeners(), this.propsHandlers.clear());
2879
3055
  }
2880
3056
  }
2881
- let v = null;
2882
- function xe(t) {
2883
- if (v)
2884
- return v;
2885
- if (!J())
3057
+ let g = null;
3058
+ function ne(s, e, t = {}) {
3059
+ if (g) {
3060
+ if (e) {
3061
+ const i = g.getProps().getConsumerDomain();
3062
+ if (!L(e, i))
3063
+ throw vt(), new Error(
3064
+ `Consumer domain "${i}" is not allowed for this host component`
3065
+ );
3066
+ }
3067
+ return t.deferInit || g.flushInit(), g;
3068
+ }
3069
+ if (!X())
2886
3070
  return null;
2887
- const e = Ue();
2888
- return e ? (v = new yt(
3071
+ const n = Ve();
3072
+ return n ? (g = new bt(
3073
+ n,
3074
+ s,
2889
3075
  e,
2890
- t
2891
- ), v) : (console.error("Failed to parse ForgeFrame payload from window.name"), null);
3076
+ t.deferInit ?? !1
3077
+ ), g) : (console.error("Failed to parse ForgeFrame payload from window.name"), null);
2892
3078
  }
2893
- function _t() {
2894
- return J();
3079
+ function Pt() {
3080
+ return X();
2895
3081
  }
2896
- function wt() {
2897
- return J();
3082
+ function Ot() {
3083
+ return X();
2898
3084
  }
2899
- function Et() {
3085
+ function Rt() {
2900
3086
  return window.hostProps;
2901
3087
  }
2902
- const S = /* @__PURE__ */ new Map();
2903
- function bt(t) {
2904
- if (!t.tag)
3088
+ function vt() {
3089
+ g && (g.destroy(), g = null), delete window.hostProps;
3090
+ }
3091
+ const C = /* @__PURE__ */ new Map(), Se = /* @__PURE__ */ Symbol("forgeframe.component.options");
3092
+ function St(s) {
3093
+ if (!s.tag)
2905
3094
  throw new Error("Component tag is required");
2906
- if (!/^[a-z][a-z0-9-]*$/.test(t.tag))
3095
+ if (!/^[a-z][a-z0-9-]*$/.test(s.tag))
2907
3096
  throw new Error(
2908
- `Invalid component tag "${t.tag}". Must start with lowercase letter and contain only lowercase letters, numbers, and hyphens.`
3097
+ `Invalid component tag "${s.tag}". Must start with lowercase letter and contain only lowercase letters, numbers, and hyphens.`
2909
3098
  );
2910
- if (!t.url)
3099
+ if (!s.url)
2911
3100
  throw new Error("Component url is required");
2912
- if (typeof t.url == "string")
3101
+ if (typeof s.url == "string")
2913
3102
  try {
2914
- new URL(t.url, window.location.origin);
3103
+ new URL(s.url, window.location.origin);
2915
3104
  } catch {
2916
3105
  throw new Error(
2917
- `Invalid component URL "${t.url}". Must be a valid absolute or relative URL.`
3106
+ `Invalid component URL "${s.url}". Must be a valid absolute or relative URL.`
2918
3107
  );
2919
3108
  }
2920
- if (S.has(t.tag))
2921
- throw new Error(`Component "${t.tag}" is already registered`);
3109
+ if (C.has(s.tag))
3110
+ throw new Error(`Component "${s.tag}" is already registered`);
2922
3111
  }
2923
- function Se(t) {
2924
- bt(t);
3112
+ function xe(s) {
3113
+ St(s);
2925
3114
  const e = [];
2926
- let s;
2927
- if (H(t.tag)) {
2928
- const i = xe(t.props);
2929
- i && (s = i.hostProps);
3115
+ let t;
3116
+ if (W(s.tag)) {
3117
+ const i = ne(s.props, s.allowedConsumerDomains);
3118
+ i && (t = i.hostProps);
2930
3119
  }
2931
3120
  const n = function(i = {}) {
2932
- const r = new Q(t, i);
3121
+ const r = new se(s, i);
2933
3122
  return e.push(r), r.event.once("destroy", () => {
2934
3123
  const o = e.indexOf(r);
2935
3124
  o !== -1 && e.splice(o, 1);
2936
3125
  }), r;
2937
3126
  };
2938
- return n.instances = e, n.isHost = () => H(t.tag), n.isEmbedded = () => H(t.tag), n.hostProps = s, n.canRenderTo = async (i) => {
3127
+ return n.instances = e, n.isHost = () => W(s.tag), n.isEmbedded = () => W(s.tag), n.hostProps = t, n[Se] = s, n.canRenderTo = async (i) => {
2939
3128
  try {
2940
- return !!(_e(i) || t.domain);
3129
+ return !!(be(i) || s.domain);
2941
3130
  } catch {
2942
3131
  return !1;
2943
3132
  }
2944
- }, S.set(t.tag, n), n;
3133
+ }, C.set(s.tag, n), n;
2945
3134
  }
2946
- function Pt(t) {
2947
- return S.get(t);
3135
+ function xt(s) {
3136
+ return C.get(s);
2948
3137
  }
2949
- async function Rt(t) {
2950
- await t.close();
3138
+ function Ct(s) {
3139
+ return s[Se];
2951
3140
  }
2952
- async function Oe(t) {
2953
- const e = S.get(t);
3141
+ async function Dt(s) {
3142
+ await s.close();
3143
+ }
3144
+ async function Ce(s) {
3145
+ const e = C.get(s);
2954
3146
  if (!e) return;
2955
- const s = [...e.instances];
2956
- await Promise.all(s.map((n) => n.close()));
3147
+ const t = [...e.instances];
3148
+ await Promise.all(t.map((n) => n.close()));
3149
+ }
3150
+ async function It() {
3151
+ const s = Array.from(C.keys());
3152
+ await Promise.all(s.map((e) => Ce(e)));
2957
3153
  }
2958
- async function xt() {
2959
- const t = Array.from(S.keys());
2960
- await Promise.all(t.map((e) => Oe(e)));
3154
+ function Tt(s, e) {
3155
+ const t = Object.keys(s), n = Object.keys(e);
3156
+ if (t.length !== n.length)
3157
+ return !1;
3158
+ for (const i of t)
3159
+ if (!Object.prototype.hasOwnProperty.call(e, i) || !Object.is(s[i], e[i]))
3160
+ return !1;
3161
+ return !0;
2961
3162
  }
2962
- function St(t, e) {
2963
- const { React: s } = e, { createElement: n, useRef: i, useEffect: r, useState: o, forwardRef: a } = s, c = a(
2964
- function(g, y) {
3163
+ function Ft(s, e) {
3164
+ const { React: t } = e, { createElement: n, useRef: i, useEffect: r, useState: o, forwardRef: a } = t, c = a(
3165
+ function(w, _) {
2965
3166
  const {
2966
- onRendered: b,
2967
- onError: O,
2968
- onClose: ee,
2969
- context: Ce,
2970
- className: te,
2971
- style: se,
2972
- ...F
2973
- } = g, C = i(null), L = i(null), [ne, ve] = o(null);
3167
+ onRendered: O,
3168
+ onError: v,
3169
+ onClose: ie,
3170
+ context: De,
3171
+ className: re,
3172
+ style: oe,
3173
+ ...H
3174
+ } = w, D = i(null), A = i(null), U = i(null), [ae, Ie] = o(null);
2974
3175
  return r(() => {
2975
- const x = C.current;
2976
- if (!x) return;
2977
- const _ = t(F);
2978
- return L.current = _, b && _.event.once("rendered", b), ee && _.event.once("close", ee), O && _.event.on("error", O), _.render(x, Ce).catch((ie) => {
2979
- ve(ie), O?.(ie);
3176
+ const S = D.current;
3177
+ if (!S) return;
3178
+ const m = s(H);
3179
+ return A.current = m, O && m.event.once("rendered", O), ie && m.event.once("close", ie), v && m.event.on("error", v), m.render(S, De).catch((x) => {
3180
+ Ie(x), v?.(x);
2980
3181
  }), () => {
2981
- _.close().catch(() => {
2982
- }), L.current = null;
3182
+ m.close().catch(() => {
3183
+ }), A.current = null, U.current = null;
2983
3184
  };
2984
3185
  }, []), r(() => {
2985
- const x = L.current;
2986
- x && x.updateProps(F).catch((_) => {
2987
- O?.(_);
2988
- });
2989
- }, [JSON.stringify(F)]), r(() => {
2990
- y && typeof y == "object" && C.current && (y.current = C.current);
2991
- }, [y]), ne ? n(
3186
+ const S = A.current;
3187
+ if (!S) return;
3188
+ const m = H, x = U.current;
3189
+ x && Tt(x, m) || (U.current = m, S.updateProps(m).catch((Te) => {
3190
+ v?.(Te);
3191
+ }));
3192
+ }, [H, v]), r(() => {
3193
+ _ && typeof _ == "object" && D.current && (_.current = D.current);
3194
+ }, [_]), ae ? n(
2992
3195
  "div",
2993
3196
  {
2994
- className: te,
2995
- style: { color: "red", padding: "16px", ...se }
3197
+ className: re,
3198
+ style: { color: "red", padding: "16px", ...oe }
2996
3199
  },
2997
- `Error: ${ne.message}`
3200
+ `Error: ${ae.message}`
2998
3201
  ) : n("div", {
2999
- ref: C,
3000
- className: te,
3202
+ ref: D,
3203
+ className: re,
3001
3204
  style: {
3002
3205
  display: "inline-block",
3003
- ...se
3206
+ ...oe
3004
3207
  }
3005
3208
  });
3006
3209
  }
3007
- ), l = `ForgeFrame(${t.name || "Component"})`;
3210
+ ), l = `ForgeFrame(${s.name || "Component"})`;
3008
3211
  return c.displayName = l, c;
3009
3212
  }
3010
- function Ot(t) {
3011
- return function(s) {
3012
- return St(s, { React: t });
3213
+ function kt(s) {
3214
+ return function(t) {
3215
+ return Ft(t, { React: s });
3013
3216
  };
3014
3217
  }
3015
- xe();
3016
- const Ct = {
3218
+ ne(void 0, void 0, { deferInit: !0 });
3219
+ const $t = {
3017
3220
  /**
3018
3221
  * Create a new component definition.
3019
3222
  *
@@ -3038,23 +3241,23 @@ const Ct = {
3038
3241
  * await instance.render('#container');
3039
3242
  * ```
3040
3243
  */
3041
- create: Se,
3244
+ create: xe,
3042
3245
  /**
3043
3246
  * Destroy a single component instance.
3044
3247
  *
3045
3248
  * @param instance - The component instance to destroy
3046
3249
  */
3047
- destroy: Rt,
3250
+ destroy: Dt,
3048
3251
  /**
3049
3252
  * Destroy all instances of a specific component by tag.
3050
3253
  *
3051
3254
  * @param tag - The component tag name
3052
3255
  */
3053
- destroyByTag: Oe,
3256
+ destroyByTag: Ce,
3054
3257
  /**
3055
3258
  * Destroy all ForgeFrame component instances.
3056
3259
  */
3057
- destroyAll: xt,
3260
+ destroyAll: It,
3058
3261
  /**
3059
3262
  * Check if the current window is a host component context.
3060
3263
  *
@@ -3064,7 +3267,7 @@ const Ct = {
3064
3267
  *
3065
3268
  * @returns True if running inside a ForgeFrame iframe/popup
3066
3269
  */
3067
- isHost: _t,
3270
+ isHost: Pt,
3068
3271
  /**
3069
3272
  * Check if the current window is embedded by ForgeFrame.
3070
3273
  *
@@ -3073,7 +3276,7 @@ const Ct = {
3073
3276
  *
3074
3277
  * @returns True if running inside a ForgeFrame iframe/popup
3075
3278
  */
3076
- isEmbedded: wt,
3279
+ isEmbedded: Ot,
3077
3280
  /**
3078
3281
  * Get hostProps from the current host window.
3079
3282
  *
@@ -3082,7 +3285,18 @@ const Ct = {
3082
3285
  *
3083
3286
  * @returns The hostProps object if in host context, undefined otherwise
3084
3287
  */
3085
- getHostProps: Et,
3288
+ getHostProps: Rt,
3289
+ /**
3290
+ * Flush host initialization in embedded contexts.
3291
+ *
3292
+ * @remarks
3293
+ * Only required in host pages that access `window.hostProps` directly
3294
+ * without defining a component via `ForgeFrame.create(...)`.
3295
+ * When `create()` is used on the host side, init is flushed automatically.
3296
+ *
3297
+ * @returns The host component instance if running embedded, otherwise null
3298
+ */
3299
+ initHost: ne,
3086
3300
  /**
3087
3301
  * Serialization strategy constants.
3088
3302
  * @see {@link PROP_SERIALIZATION}
@@ -3101,11 +3315,11 @@ const Ct = {
3101
3315
  /**
3102
3316
  * Error thrown when popup window fails to open.
3103
3317
  */
3104
- PopupOpenError: Re,
3318
+ PopupOpenError: ve,
3105
3319
  /**
3106
3320
  * Current library version.
3107
3321
  */
3108
- VERSION: pe,
3322
+ VERSION: ye,
3109
3323
  /**
3110
3324
  * Check if a value is a Standard Schema (Zod, Valibot, ArkType, etc.)
3111
3325
  *
@@ -3122,7 +3336,7 @@ const Ct = {
3122
3336
  * }
3123
3337
  * ```
3124
3338
  */
3125
- isStandardSchema: E,
3339
+ isStandardSchema: b,
3126
3340
  /**
3127
3341
  * Prop schema builders for defining component props.
3128
3342
  *
@@ -3148,32 +3362,33 @@ const Ct = {
3148
3362
  prop: d
3149
3363
  };
3150
3364
  export {
3151
- K as AnySchema,
3152
- T as ArraySchema,
3153
- X as BooleanSchema,
3365
+ te as AnySchema,
3366
+ N as ArraySchema,
3367
+ Y as BooleanSchema,
3154
3368
  p as CONTEXT,
3155
3369
  f as EVENT,
3156
- G as EnumSchema,
3157
- Ct as ForgeFrame,
3158
- Y as FunctionSchema,
3159
- Z as LiteralSchema,
3160
- q as NumberSchema,
3370
+ ee as EnumSchema,
3371
+ $t as ForgeFrame,
3372
+ Z as FunctionSchema,
3373
+ Q as LiteralSchema,
3374
+ G as NumberSchema,
3161
3375
  k as ObjectSchema,
3162
3376
  I as PROP_SERIALIZATION,
3163
- Re as PopupOpenError,
3164
- m as PropSchema,
3165
- V as StringSchema,
3166
- pe as VERSION,
3167
- Se as create,
3168
- St as createReactComponent,
3169
- Ct as default,
3170
- Rt as destroy,
3171
- xt as destroyAll,
3172
- Oe as destroyByTag,
3173
- Et as getHostProps,
3174
- wt as isEmbedded,
3175
- _t as isHost,
3176
- E as isStandardSchema,
3377
+ ve as PopupOpenError,
3378
+ y as PropSchema,
3379
+ K as StringSchema,
3380
+ ye as VERSION,
3381
+ xe as create,
3382
+ Ft as createReactComponent,
3383
+ $t as default,
3384
+ Dt as destroy,
3385
+ It as destroyAll,
3386
+ Ce as destroyByTag,
3387
+ Rt as getHostProps,
3388
+ ne as initHost,
3389
+ Ot as isEmbedded,
3390
+ Pt as isHost,
3391
+ b as isStandardSchema,
3177
3392
  d as prop,
3178
- Ot as withReactComponent
3393
+ kt as withReactComponent
3179
3394
  };