forgeframe 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,7 @@
1
- const p = {
1
+ function ce() {
2
+ return typeof window < "u" && typeof window.location < "u";
3
+ }
4
+ const f = {
2
5
  /** Render component in an iframe */
3
6
  IFRAME: "iframe",
4
7
  /** Render component in a popup window */
@@ -26,14 +29,14 @@ const p = {
26
29
  RESIZE: "resize",
27
30
  /** Emitted when component receives focus */
28
31
  FOCUS: "focus"
29
- }, z = {
32
+ }, k = {
30
33
  /** Default JSON serialization */
31
34
  JSON: "json",
32
35
  /** Base64 encoding for binary or large data */
33
36
  BASE64: "base64",
34
37
  /** Explicit framed-path encoding for nested objects */
35
38
  DOTIFY: "dotify"
36
- }, W = {
39
+ }, j = {
37
40
  /** Request message expecting a response */
38
41
  REQUEST: "request",
39
42
  /** Response to a previous request */
@@ -63,14 +66,107 @@ const p = {
63
66
  CONSUMER_EXPORT: "forgeframe_consumer_export",
64
67
  /** Get sibling components request */
65
68
  GET_SIBLINGS: "forgeframe_get_siblings"
66
- }, j = "__forgeframe__", oe = (() => {
67
- if ("0.0.12".trim().length === 0)
69
+ }, B = "__forgeframe__", ue = (() => {
70
+ if ("0.0.13".trim().length === 0)
68
71
  throw new Error(
69
72
  "ForgeFrame VERSION injection is missing. Configure __FORGEFRAME_VERSION__ in build/test tooling."
70
73
  );
71
- return "0.0.12";
72
- })();
73
- class Ae {
74
+ return "0.0.13";
75
+ })(), ot = [
76
+ "init",
77
+ "close",
78
+ "resize",
79
+ "show",
80
+ "hide",
81
+ "onError",
82
+ "updateProps",
83
+ "export"
84
+ ], ve = 32 * 1024;
85
+ function at(t) {
86
+ const e = ft(t);
87
+ return `${B}${e}`;
88
+ }
89
+ function ze(t) {
90
+ if (!t || !t.startsWith(B))
91
+ return null;
92
+ const e = t.slice(B.length);
93
+ return mt(e);
94
+ }
95
+ function R(t) {
96
+ return typeof t == "object" && t !== null;
97
+ }
98
+ function ct(t) {
99
+ return R(t);
100
+ }
101
+ function ut(t) {
102
+ return R(t) && ot.every(
103
+ (e) => typeof t[e] == "string" && t[e].length > 0
104
+ );
105
+ }
106
+ function lt(t) {
107
+ if (!R(t) || typeof t.tag != "string" || t.tag.length === 0 || typeof t.url != "string" || t.url.length === 0 || t.props !== void 0 && !R(t.props) || t.defaultContext !== void 0 && t.defaultContext !== f.IFRAME && t.defaultContext !== f.POPUP)
108
+ return !1;
109
+ if (t.dimensions !== void 0) {
110
+ if (!R(t.dimensions))
111
+ return !1;
112
+ const { width: e, height: n } = t.dimensions;
113
+ if (e !== void 0 && typeof e != "string" && typeof e != "number" || n !== void 0 && typeof n != "string" && typeof n != "number")
114
+ return !1;
115
+ }
116
+ return !0;
117
+ }
118
+ function dt(t) {
119
+ return R(t) ? Object.values(t).every((e) => lt(e)) : !1;
120
+ }
121
+ function ht(t) {
122
+ return !(!R(t) || typeof t.uid != "string" || t.uid.length === 0 || typeof t.tag != "string" || t.tag.length === 0 || typeof t.version != "string" || t.version.length === 0 || t.version !== ue || t.context !== f.IFRAME && t.context !== f.POPUP || typeof t.consumerDomain != "string" || t.consumerDomain.length === 0 || !ct(t.props) || !ut(t.exports) || t.children !== void 0 && !dt(t.children));
123
+ }
124
+ function le(t = window) {
125
+ try {
126
+ return t.name.startsWith(B);
127
+ } catch {
128
+ return !1;
129
+ }
130
+ }
131
+ function pt(t, e = window) {
132
+ return ze(e.name)?.tag === t;
133
+ }
134
+ function ft(t) {
135
+ try {
136
+ const e = JSON.stringify(t), n = btoa(encodeURIComponent(e)), s = n.length;
137
+ if (s > ve)
138
+ throw new Error(
139
+ `Payload size (${Math.round(s / 1024)}KB) exceeds maximum allowed size (${ve / 1024}KB). Consider reducing the amount of data passed via props.`
140
+ );
141
+ return n;
142
+ } catch (e) {
143
+ throw e instanceof Error && e.message.includes("Payload size") ? e : new Error(`Failed to encode payload: ${e}`);
144
+ }
145
+ }
146
+ function mt(t) {
147
+ try {
148
+ const e = decodeURIComponent(atob(t)), n = JSON.parse(e);
149
+ return ht(n) ? n : null;
150
+ } catch {
151
+ return null;
152
+ }
153
+ }
154
+ function gt(t) {
155
+ return {
156
+ uid: t.uid,
157
+ tag: t.tag,
158
+ version: ue,
159
+ context: t.context,
160
+ consumerDomain: t.consumerDomain,
161
+ props: t.props,
162
+ exports: t.exports,
163
+ children: t.children
164
+ };
165
+ }
166
+ function yt(t = window) {
167
+ return ze(t.name);
168
+ }
169
+ class Le {
74
170
  /**
75
171
  * Internal storage for event listeners mapped by event name.
76
172
  * @internal
@@ -221,249 +317,243 @@ class Ae {
221
317
  return this.listeners.get(e)?.size ?? 0;
222
318
  }
223
319
  }
224
- function tt() {
320
+ function wt() {
225
321
  const t = Date.now().toString(36), e = Math.random().toString(36).slice(2, 11);
226
322
  return `${t}_${e}`;
227
323
  }
228
- function k() {
324
+ function W() {
229
325
  return Math.random().toString(36).slice(2, 11);
230
326
  }
231
- class nt {
327
+ const Te = 500, _t = /* @__PURE__ */ new Set(["__proto__"]);
328
+ function ke(t) {
329
+ return !_t.has(t);
330
+ }
331
+ class de {
232
332
  /**
233
- * Array of registered cleanup tasks awaiting execution.
234
- * @internal
333
+ * Creates a new FunctionBridge instance.
334
+ *
335
+ * @param messenger - The messenger to use for cross-domain calls
235
336
  */
236
- tasks = [];
337
+ constructor(e) {
338
+ this.messenger = e, this.setupCallHandler();
339
+ }
340
+ /** @internal */
341
+ localFunctions = /* @__PURE__ */ new Map();
342
+ /** @internal */
343
+ remoteFunctions = /* @__PURE__ */ new Map();
237
344
  /**
238
- * Flag indicating whether cleanup has already been performed.
345
+ * Tracks function IDs from the current serialization batch.
346
+ * Used for cleanup of stale references when props are updated.
239
347
  * @internal
240
348
  */
241
- cleaned = !1;
349
+ currentBatchIds = /* @__PURE__ */ new Set();
242
350
  /**
243
- * Registers a cleanup task to be executed when {@link cleanup} is called.
244
- *
245
- * @param task - The cleanup function to register
246
- *
247
- * @remarks
248
- * If cleanup has already been performed, the task is scheduled on a microtask
249
- * and executed asynchronously rather than being registered. This ensures
250
- * late-registered tasks are still handled appropriately while safely capturing
251
- * both sync and async task failures.
252
- *
253
- * @example
254
- * ```typescript
255
- * cleanup.register(() => {
256
- * eventEmitter.removeAllListeners();
257
- * });
258
- *
259
- * cleanup.register(async () => {
260
- * await database.close();
261
- * });
262
- * ```
351
+ * Serializes a local function to a transferable reference.
263
352
  *
264
- * @public
353
+ * @param fn - The function to serialize
354
+ * @param name - Optional name for debugging
355
+ * @returns A function reference that can be sent across domains
265
356
  */
266
- register(e) {
267
- if (this.cleaned) {
268
- Promise.resolve().then(() => e()).catch((n) => {
269
- console.error("Error in cleanup task:", n);
270
- });
271
- return;
357
+ serialize(e, n) {
358
+ if (this.localFunctions.size >= Te) {
359
+ const r = this.localFunctions.keys().next().value;
360
+ r && this.localFunctions.delete(r);
272
361
  }
273
- this.tasks.push(e);
362
+ const s = W();
363
+ return this.localFunctions.set(s, e), this.currentBatchIds.add(s), {
364
+ __type__: "function",
365
+ __id__: s,
366
+ __name__: n || e.name || "anonymous"
367
+ };
274
368
  }
275
369
  /**
276
- * Executes all registered cleanup tasks in LIFO order.
277
- *
278
- * @returns A Promise that resolves when all cleanup tasks have completed
370
+ * Deserializes a function reference to a callable wrapper.
279
371
  *
280
372
  * @remarks
281
- * Tasks are executed in reverse order of registration (LIFO pattern).
282
- * Each task is awaited individually, and errors are caught and logged
283
- * to prevent one failing task from blocking subsequent cleanup operations.
284
- * Calling this method multiple times has no effect after the first call.
373
+ * The returned function, when called, will invoke the original function
374
+ * in the remote window via postMessage and return the result.
285
375
  *
286
- * @example
287
- * ```typescript
288
- * // In a component's destroy lifecycle
289
- * async destroy() {
290
- * await this.cleanupManager.cleanup();
291
- * }
292
- * ```
376
+ * @param ref - The function reference to deserialize
377
+ * @param targetWin - The window containing the original function
378
+ * @param targetDomain - The origin of the target window
379
+ * @returns A callable wrapper function
380
+ */
381
+ deserialize(e, n, s) {
382
+ const r = `${e.__id__}`, i = this.remoteFunctions.get(r);
383
+ if (i) return i;
384
+ if (this.remoteFunctions.size >= Te) {
385
+ const a = this.remoteFunctions.keys().next().value;
386
+ a && this.remoteFunctions.delete(a);
387
+ }
388
+ const o = async (...a) => this.messenger.send(n, s, l.CALL, {
389
+ id: e.__id__,
390
+ args: a
391
+ });
392
+ return Object.defineProperty(o, "name", {
393
+ value: e.__name__,
394
+ configurable: !0
395
+ }), this.remoteFunctions.set(r, o), o;
396
+ }
397
+ /**
398
+ * Type guard to check if a value is a function reference.
293
399
  *
294
- * @public
400
+ * @param value - The value to check
401
+ * @returns True if the value is a FunctionRef
295
402
  */
296
- async cleanup() {
297
- if (this.cleaned) return;
298
- this.cleaned = !0;
299
- const e = this.tasks.reverse();
300
- this.tasks = [];
301
- for (const n of e)
302
- try {
303
- await n();
304
- } catch (s) {
305
- console.error("Error in cleanup task:", s);
403
+ static isFunctionRef(e) {
404
+ return typeof e == "object" && e !== null && e.__type__ === "function" && typeof e.__id__ == "string";
405
+ }
406
+ /**
407
+ * Sets up the handler for incoming function call messages.
408
+ * @internal
409
+ */
410
+ setupCallHandler() {
411
+ this.messenger.on(
412
+ l.CALL,
413
+ async ({ id: e, args: n }) => {
414
+ const s = this.localFunctions.get(e);
415
+ if (!s)
416
+ throw new Error(`Function with id "${e}" not found`);
417
+ return s(...n);
306
418
  }
419
+ );
307
420
  }
308
421
  /**
309
- * Checks whether cleanup has already been performed.
422
+ * Removes a local function reference.
310
423
  *
311
- * @returns `true` if {@link cleanup} has been called, `false` otherwise
424
+ * @param id - The function reference ID to remove
425
+ */
426
+ removeLocal(e) {
427
+ this.localFunctions.delete(e);
428
+ }
429
+ /**
430
+ * Starts a new serialization batch.
431
+ *
432
+ * @remarks
433
+ * Call this before serializing a new set of props. After serialization,
434
+ * call {@link finishBatch} to clean up functions from previous batches.
312
435
  *
313
436
  * @example
314
437
  * ```typescript
315
- * if (!cleanupManager.isCleaned()) {
316
- * // Safe to register more tasks
317
- * cleanupManager.register(myTask);
318
- * }
438
+ * bridge.startBatch();
439
+ * const serialized = serializeFunctions(props, bridge);
440
+ * bridge.finishBatch();
319
441
  * ```
320
- *
321
- * @public
322
442
  */
323
- isCleaned() {
324
- return this.cleaned;
443
+ startBatch() {
444
+ this.currentBatchIds.clear();
325
445
  }
326
446
  /**
327
- * Resets the manager to its initial state, allowing it to be reused.
447
+ * Finishes the current batch and removes functions not in this batch.
328
448
  *
329
449
  * @remarks
330
- * This method clears all registered tasks and resets the cleaned flag.
331
- * It is primarily intended for testing scenarios or cases where the
332
- * manager needs to be reused after cleanup.
450
+ * This cleans up function references from previous prop updates that
451
+ * are no longer needed, preventing memory leaks.
333
452
  *
334
- * @example
335
- * ```typescript
336
- * // In a test teardown
337
- * afterEach(() => {
338
- * cleanupManager.reset();
339
- * });
340
- * ```
453
+ * @param keepPrevious - If true, keeps previous batch functions (default: false)
454
+ */
455
+ finishBatch(e = !1) {
456
+ if (e) {
457
+ this.currentBatchIds.clear();
458
+ return;
459
+ }
460
+ for (const n of this.localFunctions.keys())
461
+ this.currentBatchIds.has(n) || this.localFunctions.delete(n);
462
+ this.currentBatchIds.clear();
463
+ }
464
+ /**
465
+ * Clears all remote function references.
341
466
  *
342
- * @public
467
+ * @remarks
468
+ * Call this when the remote window is no longer accessible
469
+ * (e.g., closed or navigated away).
343
470
  */
344
- reset() {
345
- this.tasks = [], this.cleaned = !1;
471
+ clearRemote() {
472
+ this.remoteFunctions.clear();
346
473
  }
347
- }
348
- function Le() {
349
- let t, e;
350
- return { promise: new Promise((s, r) => {
351
- t = s, e = r;
352
- }), resolve: t, reject: e };
353
- }
354
- function st(t, e, n = "Operation timed out") {
355
- return new Promise((s, r) => {
356
- const i = setTimeout(() => {
357
- r(new Error(`${n} (${e}ms)`));
358
- }, e);
359
- t.then((o) => {
360
- clearTimeout(i), s(o);
361
- }).catch((o) => {
362
- clearTimeout(i), r(o);
363
- });
364
- });
365
- }
366
- const I = /* @__PURE__ */ new Map(), rt = 200;
367
- function it(t) {
368
- return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
369
- }
370
- function ot(t) {
371
- if (!t.includes("*"))
372
- return null;
373
- const e = I.get(t);
374
- if (e)
375
- return e;
376
- const n = t.split("*").map((r) => it(r)).join(".*"), s = new RegExp(`^${n}$`);
377
- if (I.size >= rt) {
378
- const r = I.keys().next().value;
379
- r && I.delete(r);
380
- }
381
- return I.set(t, s), s;
382
- }
383
- function at(t, e) {
384
- return t.global || t.sticky ? new RegExp(t.source, t.flags.replace(/[gy]/g, "")).test(e) : t.test(e);
385
- }
386
- function B(t = window) {
387
- try {
388
- return t.location.origin;
389
- } catch {
390
- return "";
391
- }
392
- }
393
- function Me(t, e = window) {
394
- try {
395
- return t.location.origin === e.location.origin;
396
- } catch {
397
- return !1;
398
- }
399
- }
400
- function U(t, e) {
401
- if (typeof t == "string") {
402
- if (t === "*") return !0;
403
- const n = ot(t);
404
- return n ? n.test(e) : t === e;
474
+ /**
475
+ * Returns the current number of registered local functions.
476
+ * Useful for debugging and monitoring.
477
+ */
478
+ get localFunctionCount() {
479
+ return this.localFunctions.size;
405
480
  }
406
- return t instanceof RegExp ? at(t, e) : Array.isArray(t) ? t.some((n) => U(n, e)) : !1;
407
- }
408
- function ne(t) {
409
- if (!t) return !0;
410
- try {
411
- return t.closed;
412
- } catch {
413
- return !0;
481
+ /**
482
+ * Returns the current number of cached remote functions.
483
+ * Useful for debugging and monitoring.
484
+ */
485
+ get remoteFunctionCount() {
486
+ return this.remoteFunctions.size;
414
487
  }
415
- }
416
- function ct(t = window) {
417
- try {
418
- return t.opener;
419
- } catch {
420
- return null;
488
+ /**
489
+ * Cleans up all function references.
490
+ */
491
+ destroy() {
492
+ this.localFunctions.clear(), this.remoteFunctions.clear(), this.currentBatchIds.clear();
421
493
  }
422
494
  }
423
- function ut(t = window) {
424
- try {
425
- const e = t.parent;
426
- return e && e !== t ? e : null;
427
- } catch {
428
- return null;
495
+ function se(t, e, n = /* @__PURE__ */ new WeakSet()) {
496
+ if (typeof t == "function")
497
+ return e.serialize(t);
498
+ if (Array.isArray(t)) {
499
+ if (n.has(t))
500
+ throw new Error("Circular reference detected in props - arrays cannot contain circular references");
501
+ n.add(t);
502
+ try {
503
+ return t.map((s) => se(s, e, n));
504
+ } finally {
505
+ n.delete(t);
506
+ }
429
507
  }
430
- }
431
- function lt(t = window) {
432
- try {
433
- return t.parent !== t;
434
- } catch {
435
- return !0;
508
+ if (typeof t == "object" && t !== null) {
509
+ if (n.has(t))
510
+ throw new Error("Circular reference detected in props - objects cannot contain circular references");
511
+ n.add(t);
512
+ try {
513
+ const s = {};
514
+ for (const [r, i] of Object.entries(t))
515
+ ke(r) && (s[r] = se(i, e, n));
516
+ return s;
517
+ } finally {
518
+ n.delete(t);
519
+ }
436
520
  }
521
+ return t;
437
522
  }
438
- function ht(t = window) {
439
- try {
440
- return t.opener !== null && t.opener !== void 0;
441
- } catch {
442
- return !1;
523
+ function re(t, e, n, s, r = /* @__PURE__ */ new WeakSet()) {
524
+ if (de.isFunctionRef(t))
525
+ return e.deserialize(t, n, s);
526
+ if (Array.isArray(t)) {
527
+ if (r.has(t))
528
+ throw new Error("Circular reference detected in serialized props");
529
+ r.add(t);
530
+ try {
531
+ return t.map(
532
+ (i) => re(i, e, n, s, r)
533
+ );
534
+ } finally {
535
+ r.delete(t);
536
+ }
443
537
  }
444
- }
445
- const De = 100, b = /* @__PURE__ */ new Map();
446
- function dt() {
447
- const t = [];
448
- for (const [e, n] of b.entries())
449
- ne(n) && t.push(e);
450
- for (const e of t)
451
- b.delete(e);
452
- }
453
- function ft(t, e) {
454
- if (b.size >= De && dt(), b.size >= De) {
455
- const n = b.keys().next().value;
456
- n && b.delete(n);
538
+ if (typeof t == "object" && t !== null) {
539
+ if (r.has(t))
540
+ throw new Error("Circular reference detected in serialized props");
541
+ r.add(t);
542
+ try {
543
+ const i = {};
544
+ for (const [o, a] of Object.entries(t))
545
+ ke(o) && (i[o] = re(a, e, n, s, r));
546
+ return i;
547
+ } finally {
548
+ r.delete(t);
549
+ }
457
550
  }
458
- b.set(t, e);
459
- }
460
- function pt(t) {
461
- b.delete(t);
551
+ return t;
462
552
  }
463
- function mt(t, e) {
553
+ function Pt(t, e) {
464
554
  return t.global || t.sticky ? new RegExp(t.source, t.flags.replace(/[gy]/g, "")).test(e) : t.test(e);
465
555
  }
466
- class P {
556
+ class E {
467
557
  /** @internal */
468
558
  _optional = !1;
469
559
  /** @internal */
@@ -530,7 +620,7 @@ class P {
530
620
  return n._default = e, n;
531
621
  }
532
622
  }
533
- class ae extends P {
623
+ class he extends E {
534
624
  /** @internal */
535
625
  _minLength;
536
626
  /** @internal */
@@ -556,7 +646,7 @@ class ae extends P {
556
646
  issues: [
557
647
  { message: `String must be at most ${this._maxLength} characters` }
558
648
  ]
559
- } : this._pattern && !mt(this._pattern, n) ? {
649
+ } : this._pattern && !Pt(this._pattern, n) ? {
560
650
  issues: [
561
651
  {
562
652
  message: this._patternMessage || `String must match pattern ${this._pattern}`
@@ -566,7 +656,7 @@ class ae extends P {
566
656
  }
567
657
  /** @internal */
568
658
  _clone() {
569
- const e = new ae();
659
+ const e = new he();
570
660
  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;
571
661
  }
572
662
  /**
@@ -691,7 +781,7 @@ class ae extends P {
691
781
  return e._minLength = 1, e;
692
782
  }
693
783
  }
694
- class ce extends P {
784
+ class pe extends E {
695
785
  /** @internal */
696
786
  _min;
697
787
  /** @internal */
@@ -706,7 +796,7 @@ class ce extends P {
706
796
  }
707
797
  /** @internal */
708
798
  _clone() {
709
- const e = new ce();
799
+ const e = new pe();
710
800
  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;
711
801
  }
712
802
  /**
@@ -786,7 +876,7 @@ class ce extends P {
786
876
  return e._max = -Number.MIN_VALUE, e;
787
877
  }
788
878
  }
789
- class ue extends P {
879
+ class fe extends E {
790
880
  /** @internal */
791
881
  _validate(e) {
792
882
  return typeof e != "boolean" ? {
@@ -795,11 +885,11 @@ class ue extends P {
795
885
  }
796
886
  /** @internal */
797
887
  _clone() {
798
- const e = new ue();
888
+ const e = new fe();
799
889
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
800
890
  }
801
891
  }
802
- class le extends P {
892
+ class me extends E {
803
893
  /** @internal */
804
894
  _validate(e) {
805
895
  return typeof e != "function" ? {
@@ -808,11 +898,11 @@ class le extends P {
808
898
  }
809
899
  /** @internal */
810
900
  _clone() {
811
- const e = new le();
901
+ const e = new me();
812
902
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
813
903
  }
814
904
  }
815
- class V extends P {
905
+ class V extends E {
816
906
  /** @internal */
817
907
  _itemSchema;
818
908
  /** @internal */
@@ -919,7 +1009,7 @@ class V extends P {
919
1009
  return this.min(1);
920
1010
  }
921
1011
  }
922
- class Y extends P {
1012
+ class Y extends E {
923
1013
  /** @internal */
924
1014
  _shape;
925
1015
  /** @internal */
@@ -1002,7 +1092,7 @@ class Y extends P {
1002
1092
  return e._strict = !0, e;
1003
1093
  }
1004
1094
  }
1005
- class he extends P {
1095
+ class ge extends E {
1006
1096
  /** @internal */
1007
1097
  _value;
1008
1098
  constructor(e) {
@@ -1016,11 +1106,11 @@ class he extends P {
1016
1106
  }
1017
1107
  /** @internal */
1018
1108
  _clone() {
1019
- const e = new he(this._value);
1109
+ const e = new ge(this._value);
1020
1110
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1021
1111
  }
1022
1112
  }
1023
- class de extends P {
1113
+ class ye extends E {
1024
1114
  /** @internal */
1025
1115
  _values;
1026
1116
  /** @internal */
@@ -1040,11 +1130,11 @@ class de extends P {
1040
1130
  }
1041
1131
  /** @internal */
1042
1132
  _clone() {
1043
- const e = new de(this._values);
1133
+ const e = new ye(this._values);
1044
1134
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1045
1135
  }
1046
1136
  }
1047
- class fe extends P {
1137
+ class we extends E {
1048
1138
  constructor() {
1049
1139
  super(), this._nullable = !0;
1050
1140
  }
@@ -1054,11 +1144,11 @@ class fe extends P {
1054
1144
  }
1055
1145
  /** @internal */
1056
1146
  _clone() {
1057
- const e = new fe();
1147
+ const e = new we();
1058
1148
  return e._optional = this._optional, e._nullable = this._nullable, e._default = this._default, e;
1059
1149
  }
1060
1150
  }
1061
- const f = {
1151
+ const p = {
1062
1152
  /**
1063
1153
  * Creates a string schema.
1064
1154
  *
@@ -1071,7 +1161,7 @@ const f = {
1071
1161
  * prop.string().pattern(/^[a-z]+$/)
1072
1162
  * ```
1073
1163
  */
1074
- string: () => new ae(),
1164
+ string: () => new he(),
1075
1165
  /**
1076
1166
  * Creates a number schema.
1077
1167
  *
@@ -1083,7 +1173,7 @@ const f = {
1083
1173
  * prop.number().positive()
1084
1174
  * ```
1085
1175
  */
1086
- number: () => new ce(),
1176
+ number: () => new pe(),
1087
1177
  /**
1088
1178
  * Creates a boolean schema.
1089
1179
  *
@@ -1093,7 +1183,7 @@ const f = {
1093
1183
  * prop.boolean().default(false)
1094
1184
  * ```
1095
1185
  */
1096
- boolean: () => new ue(),
1186
+ boolean: () => new fe(),
1097
1187
  /**
1098
1188
  * Creates a function schema.
1099
1189
  *
@@ -1106,7 +1196,7 @@ const f = {
1106
1196
  * prop.function<(data: { id: string }) => Promise<void>>()
1107
1197
  * ```
1108
1198
  */
1109
- function: () => new le(),
1199
+ function: () => new me(),
1110
1200
  /**
1111
1201
  * Creates an array schema.
1112
1202
  *
@@ -1148,7 +1238,7 @@ const f = {
1148
1238
  * prop.literal(true)
1149
1239
  * ```
1150
1240
  */
1151
- literal: (t) => new he(t),
1241
+ literal: (t) => new ge(t),
1152
1242
  /**
1153
1243
  * Creates an enum schema for a set of allowed values.
1154
1244
  *
@@ -1160,7 +1250,7 @@ const f = {
1160
1250
  * prop.enum([1, 2, 3])
1161
1251
  * ```
1162
1252
  */
1163
- enum: (t) => new de(t),
1253
+ enum: (t) => new ye(t),
1164
1254
  /**
1165
1255
  * Creates a schema that accepts any value.
1166
1256
  *
@@ -1172,173 +1262,404 @@ const f = {
1172
1262
  * prop.any()
1173
1263
  * ```
1174
1264
  */
1175
- any: () => new fe()
1176
- }, R = {
1265
+ any: () => new we()
1266
+ }, D = {
1177
1267
  uid: {
1178
- schema: f.string().optional(),
1268
+ schema: p.string().optional(),
1179
1269
  sendToHost: !0
1180
1270
  },
1181
1271
  tag: {
1182
- schema: f.string().optional(),
1272
+ schema: p.string().optional(),
1183
1273
  sendToHost: !0
1184
1274
  },
1185
1275
  dimensions: {
1186
- schema: f.object().default(() => ({ width: "100%", height: "100%" })),
1276
+ schema: p.object().default(() => ({ width: "100%", height: "100%" })),
1187
1277
  sendToHost: !1
1188
1278
  },
1189
1279
  timeout: {
1190
- schema: f.number().default(1e4),
1280
+ schema: p.number().default(1e4),
1191
1281
  sendToHost: !1
1192
1282
  },
1193
1283
  cspNonce: {
1194
- schema: f.string().optional(),
1284
+ schema: p.string().optional(),
1195
1285
  sendToHost: !0
1196
1286
  },
1197
1287
  // Lifecycle callbacks - not sent to host (consumer-only)
1198
1288
  onDisplay: {
1199
- schema: f.function().optional(),
1289
+ schema: p.function().optional(),
1200
1290
  sendToHost: !1
1201
1291
  },
1202
1292
  onRendered: {
1203
- schema: f.function().optional(),
1293
+ schema: p.function().optional(),
1204
1294
  sendToHost: !1
1205
1295
  },
1206
1296
  onRender: {
1207
- schema: f.function().optional(),
1297
+ schema: p.function().optional(),
1208
1298
  sendToHost: !1
1209
1299
  },
1210
1300
  onPrerendered: {
1211
- schema: f.function().optional(),
1301
+ schema: p.function().optional(),
1212
1302
  sendToHost: !1
1213
1303
  },
1214
1304
  onPrerender: {
1215
- schema: f.function().optional(),
1305
+ schema: p.function().optional(),
1216
1306
  sendToHost: !1
1217
1307
  },
1218
1308
  onClose: {
1219
- schema: f.function().optional(),
1309
+ schema: p.function().optional(),
1220
1310
  sendToHost: !1
1221
1311
  },
1222
1312
  onDestroy: {
1223
- schema: f.function().optional(),
1313
+ schema: p.function().optional(),
1224
1314
  sendToHost: !1
1225
1315
  },
1226
1316
  onResize: {
1227
- schema: f.function().optional(),
1317
+ schema: p.function().optional(),
1228
1318
  sendToHost: !1
1229
1319
  },
1230
1320
  onFocus: {
1231
- schema: f.function().optional(),
1321
+ schema: p.function().optional(),
1232
1322
  sendToHost: !1
1233
1323
  },
1234
1324
  onError: {
1235
- schema: f.function().optional(),
1325
+ schema: p.function().optional(),
1236
1326
  sendToHost: !1
1237
1327
  },
1238
1328
  onProps: {
1239
- schema: f.function().optional(),
1329
+ schema: p.function().optional(),
1240
1330
  sendToHost: !1
1241
1331
  }
1242
- };
1243
- function D(t) {
1244
- return typeof t == "object" && t !== null && "~standard" in t && typeof t["~standard"] == "object" && t["~standard"] !== null && t["~standard"].version === 1 && typeof t["~standard"].vendor == "string" && typeof t["~standard"].validate == "function";
1332
+ }, Et = /* @__PURE__ */ new Set(["__proto__"]), We = "__forgeframe.dotify_path__:", J = "__forgeframe.dotify_empty_object_path__:", je = "__forgeframe.dotify_empty_object__";
1333
+ function Be(t) {
1334
+ return !Et.has(t);
1245
1335
  }
1246
- function gt(t, e, n) {
1247
- const s = t["~standard"].validate(e);
1248
- if (s instanceof Promise)
1249
- throw new Error(
1250
- `Prop "${n}" 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.`
1251
- );
1252
- if (s.issues) {
1253
- const r = s.issues.map((i) => `${yt(i.path, n)}: ${i.message}`);
1254
- throw new Error(`Validation failed: ${r.join("; ")}`);
1336
+ function He(t) {
1337
+ if (t === null || typeof t != "object" || Array.isArray(t))
1338
+ return !1;
1339
+ const e = Object.getPrototypeOf(t);
1340
+ return e === Object.prototype || e === null;
1341
+ }
1342
+ function Ve(t, e = We) {
1343
+ return `${e}${encodeURIComponent(JSON.stringify(t))}`;
1344
+ }
1345
+ function bt(t) {
1346
+ return encodeURIComponent(JSON.stringify(t));
1347
+ }
1348
+ function Ct(t, e) {
1349
+ return `${Ve(t)}=${bt(e)}`;
1350
+ }
1351
+ function Ot(t) {
1352
+ return `${Ve(t, J)}=1`;
1353
+ }
1354
+ function Rt(t, e, n) {
1355
+ Object.defineProperty(t, e, {
1356
+ configurable: !0,
1357
+ enumerable: !0,
1358
+ writable: !0,
1359
+ value: n
1360
+ });
1361
+ }
1362
+ function Ye(t, e = []) {
1363
+ const n = Object.entries(t);
1364
+ if (n.length === 0 && He(t))
1365
+ return e.length === 0 ? je : Ot(e);
1366
+ const s = [];
1367
+ for (const [r, i] of n) {
1368
+ if (i === void 0) continue;
1369
+ const o = [...e, r];
1370
+ He(i) ? s.push(Ye(i, o)) : s.push(Ct(o, i));
1255
1371
  }
1256
- return s.value;
1372
+ return s.filter(Boolean).join("&");
1257
1373
  }
1258
- function yt(t, e) {
1259
- if (!t || t.length === 0)
1260
- return e;
1261
- const n = t.map((s) => {
1262
- if (typeof s == "object" && s !== null) {
1263
- if ("key" in s && s.key !== void 0)
1264
- return String(s.key);
1265
- if ("index" in s && typeof s.index == "number")
1266
- return String(s.index);
1374
+ function Dt(t) {
1375
+ const e = {};
1376
+ if (!t || t === je) return e;
1377
+ const n = t.split("&");
1378
+ for (const s of n) {
1379
+ const r = s.indexOf("=");
1380
+ if (r === -1) continue;
1381
+ const i = s.slice(0, r), o = s.slice(r + 1);
1382
+ if (!i || o === void 0) continue;
1383
+ const a = i.startsWith(J);
1384
+ let c;
1385
+ if (a) {
1386
+ if (o !== "1")
1387
+ throw new Error("Invalid empty-object DOTIFY entry");
1388
+ c = {};
1389
+ } else
1390
+ try {
1391
+ c = JSON.parse(decodeURIComponent(o));
1392
+ } catch {
1393
+ c = decodeURIComponent(o);
1394
+ }
1395
+ const u = St(i);
1396
+ if (u.some((h) => !Be(h))) continue;
1397
+ let d = e;
1398
+ for (let h = 0; h < u.length - 1; h++) {
1399
+ const b = u[h], O = d[b];
1400
+ (!Object.prototype.hasOwnProperty.call(d, b) || typeof O != "object" || O === null || Array.isArray(O)) && (d[b] = {}), d = d[b];
1267
1401
  }
1268
- return String(s);
1269
- });
1270
- return `${e}.${n.join(".")}`;
1402
+ const m = u[u.length - 1];
1403
+ Rt(d, m, c);
1404
+ }
1405
+ return e;
1271
1406
  }
1272
- function F(t) {
1273
- const e = D(t);
1274
- return { isDirectSchema: e, definition: e ? { schema: t } : t };
1407
+ function St(t) {
1408
+ const e = t.startsWith(J) ? J : We;
1409
+ if (!t.startsWith(e))
1410
+ throw new Error("Invalid DOTIFY path framing");
1411
+ const n = decodeURIComponent(t.slice(e.length)), s = JSON.parse(n);
1412
+ if (Array.isArray(s) && s.length > 0 && s.every((r) => typeof r == "string"))
1413
+ return s;
1414
+ throw new Error("Invalid DOTIFY path framing");
1415
+ }
1416
+ function xt(t) {
1417
+ return typeof t == "object" && t !== null && t.__type__ === "dotify" && typeof t.__value__ == "string";
1275
1418
  }
1276
- function Se(t, e, n) {
1419
+ function It(t, e, n) {
1277
1420
  const s = {
1278
- ...R,
1421
+ ...D,
1279
1422
  ...e
1280
1423
  }, r = {};
1281
- for (const [i, o] of Object.entries(s)) {
1282
- const { definition: a } = F(o);
1283
- let c;
1284
- const u = a.alias, d = i in t, m = u && u in t;
1285
- if (d)
1286
- c = t[i];
1287
- else if (m)
1288
- c = t[u];
1289
- else if (a.value)
1290
- c = a.value(n);
1291
- else if (a.default !== void 0)
1292
- c = typeof a.default == "function" ? a.default(n) : a.default;
1293
- else if (a.schema && D(a.schema)) {
1294
- const h = a.schema["~standard"].validate(void 0);
1295
- !(h instanceof Promise) && !h.issues && (c = h.value);
1296
- }
1297
- c !== void 0 && a.decorate && (c = a.decorate({ value: c, props: r })), r[i] = c;
1424
+ for (const [i, o] of Object.entries(t)) {
1425
+ if (o === void 0) continue;
1426
+ const a = s[i];
1427
+ r[i] = vt(o, a, n);
1298
1428
  }
1299
1429
  return r;
1300
1430
  }
1301
- function T(t, e) {
1302
- const n = {
1303
- ...R,
1304
- ...e
1305
- };
1306
- for (const [s, r] of Object.entries(n)) {
1307
- const { isDirectSchema: i, definition: o } = F(r);
1308
- let a = t[s];
1309
- if (o.required && a === void 0)
1310
- throw new Error(`Prop "${s}" is required but was not provided`);
1311
- if (o.schema && D(o.schema))
1312
- (a !== void 0 || i) && (a = gt(o.schema, a, s), t[s] = a);
1313
- else if (a === void 0)
1431
+ function vt(t, e, n) {
1432
+ if (typeof t == "function")
1433
+ return n.serialize(t);
1434
+ const s = e?.serialization ?? k.JSON;
1435
+ if (s === k.BASE64 && typeof t == "object") {
1436
+ const r = JSON.stringify(t);
1437
+ return {
1438
+ __type__: "base64",
1439
+ __value__: btoa(encodeURIComponent(r))
1440
+ };
1441
+ }
1442
+ return s === k.DOTIFY && typeof t == "object" && t !== null && !Array.isArray(t) ? {
1443
+ __type__: "dotify",
1444
+ __value__: Ye(t)
1445
+ } : se(t, n);
1446
+ }
1447
+ function Tt(t, e, n, s, r, i) {
1448
+ const o = {
1449
+ ...D,
1450
+ ...e
1451
+ }, a = {};
1452
+ for (const [c, u] of Object.entries(t)) {
1453
+ if (!Be(c)) continue;
1454
+ const d = o[c];
1455
+ a[c] = Ht(
1456
+ u,
1457
+ d,
1458
+ n,
1459
+ s,
1460
+ r,
1461
+ i
1462
+ );
1463
+ }
1464
+ return a;
1465
+ }
1466
+ function Ht(t, e, n, s, r, i) {
1467
+ if (Ut(t))
1468
+ try {
1469
+ const o = decodeURIComponent(atob(t.__value__));
1470
+ return JSON.parse(o);
1471
+ } catch {
1472
+ return t;
1473
+ }
1474
+ if (xt(t))
1475
+ try {
1476
+ return Dt(t.__value__);
1477
+ } catch {
1478
+ return t;
1479
+ }
1480
+ return re(t, s, r, i);
1481
+ }
1482
+ function Ut(t) {
1483
+ return typeof t == "object" && t !== null && t.__type__ === "base64" && typeof t.__value__ == "string";
1484
+ }
1485
+ const v = /* @__PURE__ */ new Map(), Ft = 200;
1486
+ function Nt(t) {
1487
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1488
+ }
1489
+ function Je(t) {
1490
+ if (!t.includes("*"))
1491
+ return null;
1492
+ const e = v.get(t);
1493
+ if (e)
1494
+ return e;
1495
+ const n = t.split("*").map((r) => Nt(r)).join(".*"), s = new RegExp(`^${n}$`);
1496
+ if (v.size >= Ft) {
1497
+ const r = v.keys().next().value;
1498
+ r && v.delete(r);
1499
+ }
1500
+ return v.set(t, s), s;
1501
+ }
1502
+ function ie(t, e) {
1503
+ return t.global || t.sticky ? new RegExp(t.source, t.flags.replace(/[gy]/g, "")).test(e) : t.test(e);
1504
+ }
1505
+ function q(t = window) {
1506
+ try {
1507
+ return t.location.origin;
1508
+ } catch {
1509
+ return "";
1510
+ }
1511
+ }
1512
+ function qe(t, e = window) {
1513
+ try {
1514
+ return t.location.origin === e.location.origin;
1515
+ } catch {
1516
+ return !1;
1517
+ }
1518
+ }
1519
+ function X(t, e) {
1520
+ if (typeof t == "string") {
1521
+ if (t === "*") return !0;
1522
+ const n = Je(t);
1523
+ return n ? ie(n, e) : t === e;
1524
+ }
1525
+ return t instanceof RegExp ? ie(t, e) : Array.isArray(t) ? t.some((n) => X(n, e)) : !1;
1526
+ }
1527
+ function oe(t) {
1528
+ if (!t) return !0;
1529
+ try {
1530
+ return t.closed;
1531
+ } catch {
1532
+ return !0;
1533
+ }
1534
+ }
1535
+ function At(t = window) {
1536
+ try {
1537
+ return t.opener;
1538
+ } catch {
1539
+ return null;
1540
+ }
1541
+ }
1542
+ function $t(t = window) {
1543
+ try {
1544
+ const e = t.parent;
1545
+ return e && e !== t ? e : null;
1546
+ } catch {
1547
+ return null;
1548
+ }
1549
+ }
1550
+ function Mt(t = window) {
1551
+ try {
1552
+ return t.parent !== t;
1553
+ } catch {
1554
+ return !0;
1555
+ }
1556
+ }
1557
+ function zt(t = window) {
1558
+ try {
1559
+ return t.opener !== null && t.opener !== void 0;
1560
+ } catch {
1561
+ return !1;
1562
+ }
1563
+ }
1564
+ function x(t) {
1565
+ return typeof t == "object" && t !== null && "~standard" in t && typeof t["~standard"] == "object" && t["~standard"] !== null && t["~standard"].version === 1 && typeof t["~standard"].vendor == "string" && typeof t["~standard"].validate == "function";
1566
+ }
1567
+ function Lt(t, e, n) {
1568
+ const s = t["~standard"].validate(e);
1569
+ if (s instanceof Promise)
1570
+ throw new Error(
1571
+ `Prop "${n}" 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.`
1572
+ );
1573
+ if (s.issues) {
1574
+ const r = s.issues.map((i) => `${kt(i.path, n)}: ${i.message}`);
1575
+ throw new Error(`Validation failed: ${r.join("; ")}`);
1576
+ }
1577
+ return s.value;
1578
+ }
1579
+ function kt(t, e) {
1580
+ if (!t || t.length === 0)
1581
+ return e;
1582
+ const n = t.map((s) => {
1583
+ if (typeof s == "object" && s !== null) {
1584
+ if ("key" in s && s.key !== void 0)
1585
+ return String(s.key);
1586
+ if ("index" in s && typeof s.index == "number")
1587
+ return String(s.index);
1588
+ }
1589
+ return String(s);
1590
+ });
1591
+ return `${e}.${n.join(".")}`;
1592
+ }
1593
+ function N(t) {
1594
+ const e = x(t);
1595
+ return { isDirectSchema: e, definition: e ? { schema: t } : t };
1596
+ }
1597
+ function Ue(t, e, n) {
1598
+ const s = {
1599
+ ...D,
1600
+ ...e
1601
+ }, r = {};
1602
+ for (const [i, o] of Object.entries(s)) {
1603
+ const { definition: a } = N(o);
1604
+ let c;
1605
+ const u = a.alias, d = i in t, m = u && u in t;
1606
+ if (d)
1607
+ c = t[i];
1608
+ else if (m)
1609
+ c = t[u];
1610
+ else if (a.value)
1611
+ c = a.value(n);
1612
+ else if (a.default !== void 0)
1613
+ c = typeof a.default == "function" ? a.default(n) : a.default;
1614
+ else if (a.schema && x(a.schema)) {
1615
+ const h = a.schema["~standard"].validate(void 0);
1616
+ !(h instanceof Promise) && !h.issues && (c = h.value);
1617
+ }
1618
+ c !== void 0 && a.decorate && (c = a.decorate({ value: c, props: r })), r[i] = c;
1619
+ }
1620
+ return r;
1621
+ }
1622
+ function H(t, e) {
1623
+ const n = {
1624
+ ...D,
1625
+ ...e
1626
+ };
1627
+ for (const [s, r] of Object.entries(n)) {
1628
+ const { isDirectSchema: i, definition: o } = N(r);
1629
+ let a = t[s];
1630
+ if (o.required && a === void 0)
1631
+ throw new Error(`Prop "${s}" is required but was not provided`);
1632
+ if (o.schema && x(o.schema))
1633
+ (a !== void 0 || i) && (a = Lt(o.schema, a, s), t[s] = a);
1634
+ else if (a === void 0)
1314
1635
  continue;
1315
1636
  o.validate && o.validate({ value: a, props: t });
1316
1637
  }
1317
1638
  }
1318
- function Ie(t, e, n, s) {
1639
+ function Fe(t, e, n, s) {
1319
1640
  const r = {
1320
- ...R,
1641
+ ...D,
1321
1642
  ...e
1322
1643
  }, i = {};
1323
1644
  for (const [o, a] of Object.entries(r)) {
1324
- const { definition: c } = F(a), u = t[o];
1645
+ const { definition: c } = N(a), u = t[o];
1325
1646
  if (c.sendToHost === !1 || c.sameDomain && !s) continue;
1326
1647
  if (c.trustedDomains) {
1327
1648
  const m = c.trustedDomains;
1328
- if (!U(m, n)) continue;
1649
+ if (!X(m, n)) continue;
1329
1650
  }
1330
1651
  let d = u;
1331
1652
  c.hostDecorate && u !== void 0 && (d = c.hostDecorate({ value: u, props: t })), i[o] = d;
1332
1653
  }
1333
1654
  return i;
1334
1655
  }
1335
- function wt(t, e) {
1656
+ function Wt(t, e) {
1336
1657
  const n = new URLSearchParams(), s = {
1337
- ...R,
1658
+ ...D,
1338
1659
  ...e
1339
1660
  };
1340
1661
  for (const [r, i] of Object.entries(s)) {
1341
- const { definition: o } = F(i), a = t[r];
1662
+ const { definition: o } = N(i), a = t[r];
1342
1663
  if (a === void 0 || typeof a == "function" || !o.queryParam) continue;
1343
1664
  const c = typeof o.queryParam == "string" ? o.queryParam : r;
1344
1665
  let u;
@@ -1346,13 +1667,13 @@ function wt(t, e) {
1346
1667
  }
1347
1668
  return n;
1348
1669
  }
1349
- function _t(t, e) {
1670
+ function jt(t, e) {
1350
1671
  const n = new URLSearchParams(), s = {
1351
- ...R,
1672
+ ...D,
1352
1673
  ...e
1353
1674
  };
1354
1675
  for (const [r, i] of Object.entries(s)) {
1355
- const { definition: o } = F(i), a = t[r];
1676
+ const { definition: o } = N(i), a = t[r];
1356
1677
  if (a === void 0 || typeof a == "function" || !o.bodyParam) continue;
1357
1678
  const c = typeof o.bodyParam == "string" ? o.bodyParam : r;
1358
1679
  let u;
@@ -1360,390 +1681,183 @@ function _t(t, e) {
1360
1681
  }
1361
1682
  return n;
1362
1683
  }
1363
- const ve = 500, Pt = /* @__PURE__ */ new Set(["__proto__"]);
1364
- function ze(t) {
1365
- return !Pt.has(t);
1366
- }
1367
- class pe {
1684
+ class Bt {
1368
1685
  /**
1369
- * Creates a new FunctionBridge instance.
1370
- *
1371
- * @param messenger - The messenger to use for cross-domain calls
1686
+ * Array of registered cleanup tasks awaiting execution.
1687
+ * @internal
1372
1688
  */
1373
- constructor(e) {
1374
- this.messenger = e, this.setupCallHandler();
1375
- }
1376
- /** @internal */
1377
- localFunctions = /* @__PURE__ */ new Map();
1378
- /** @internal */
1379
- remoteFunctions = /* @__PURE__ */ new Map();
1689
+ tasks = [];
1380
1690
  /**
1381
- * Tracks function IDs from the current serialization batch.
1382
- * Used for cleanup of stale references when props are updated.
1691
+ * Flag indicating whether cleanup has already been performed.
1383
1692
  * @internal
1384
1693
  */
1385
- currentBatchIds = /* @__PURE__ */ new Set();
1694
+ cleaned = !1;
1386
1695
  /**
1387
- * Serializes a local function to a transferable reference.
1696
+ * Registers a cleanup task to be executed when {@link cleanup} is called.
1388
1697
  *
1389
- * @param fn - The function to serialize
1390
- * @param name - Optional name for debugging
1391
- * @returns A function reference that can be sent across domains
1392
- */
1393
- serialize(e, n) {
1394
- if (this.localFunctions.size >= ve) {
1395
- const r = this.localFunctions.keys().next().value;
1396
- r && this.localFunctions.delete(r);
1397
- }
1398
- const s = k();
1399
- return this.localFunctions.set(s, e), this.currentBatchIds.add(s), {
1400
- __type__: "function",
1401
- __id__: s,
1402
- __name__: n || e.name || "anonymous"
1403
- };
1404
- }
1405
- /**
1406
- * Deserializes a function reference to a callable wrapper.
1698
+ * @param task - The cleanup function to register
1407
1699
  *
1408
1700
  * @remarks
1409
- * The returned function, when called, will invoke the original function
1410
- * in the remote window via postMessage and return the result.
1701
+ * If cleanup has already been performed, the task is scheduled on a microtask
1702
+ * and executed asynchronously rather than being registered. This ensures
1703
+ * late-registered tasks are still handled appropriately while safely capturing
1704
+ * both sync and async task failures.
1411
1705
  *
1412
- * @param ref - The function reference to deserialize
1413
- * @param targetWin - The window containing the original function
1414
- * @param targetDomain - The origin of the target window
1415
- * @returns A callable wrapper function
1706
+ * @example
1707
+ * ```typescript
1708
+ * cleanup.register(() => {
1709
+ * eventEmitter.removeAllListeners();
1710
+ * });
1711
+ *
1712
+ * cleanup.register(async () => {
1713
+ * await database.close();
1714
+ * });
1715
+ * ```
1716
+ *
1717
+ * @public
1416
1718
  */
1417
- deserialize(e, n, s) {
1418
- const r = `${e.__id__}`, i = this.remoteFunctions.get(r);
1419
- if (i) return i;
1420
- if (this.remoteFunctions.size >= ve) {
1421
- const a = this.remoteFunctions.keys().next().value;
1422
- a && this.remoteFunctions.delete(a);
1719
+ register(e) {
1720
+ if (this.cleaned) {
1721
+ Promise.resolve().then(() => e()).catch((n) => {
1722
+ console.error("Error in cleanup task:", n);
1723
+ });
1724
+ return;
1423
1725
  }
1424
- const o = async (...a) => this.messenger.send(n, s, l.CALL, {
1425
- id: e.__id__,
1426
- args: a
1427
- });
1428
- return Object.defineProperty(o, "name", {
1429
- value: e.__name__,
1430
- configurable: !0
1431
- }), this.remoteFunctions.set(r, o), o;
1726
+ this.tasks.push(e);
1432
1727
  }
1433
1728
  /**
1434
- * Type guard to check if a value is a function reference.
1729
+ * Executes all registered cleanup tasks in LIFO order.
1435
1730
  *
1436
- * @param value - The value to check
1437
- * @returns True if the value is a FunctionRef
1438
- */
1439
- static isFunctionRef(e) {
1440
- return typeof e == "object" && e !== null && e.__type__ === "function" && typeof e.__id__ == "string";
1441
- }
1442
- /**
1443
- * Sets up the handler for incoming function call messages.
1444
- * @internal
1445
- */
1446
- setupCallHandler() {
1447
- this.messenger.on(
1448
- l.CALL,
1449
- async ({ id: e, args: n }) => {
1450
- const s = this.localFunctions.get(e);
1451
- if (!s)
1452
- throw new Error(`Function with id "${e}" not found`);
1453
- return s(...n);
1454
- }
1455
- );
1456
- }
1457
- /**
1458
- * Removes a local function reference.
1459
- *
1460
- * @param id - The function reference ID to remove
1461
- */
1462
- removeLocal(e) {
1463
- this.localFunctions.delete(e);
1464
- }
1465
- /**
1466
- * Starts a new serialization batch.
1731
+ * @returns A Promise that resolves when all cleanup tasks have completed
1467
1732
  *
1468
1733
  * @remarks
1469
- * Call this before serializing a new set of props. After serialization,
1470
- * call {@link finishBatch} to clean up functions from previous batches.
1734
+ * Tasks are executed in reverse order of registration (LIFO pattern).
1735
+ * Each task is awaited individually, and errors are caught and logged
1736
+ * to prevent one failing task from blocking subsequent cleanup operations.
1737
+ * Calling this method multiple times has no effect after the first call.
1471
1738
  *
1472
1739
  * @example
1473
1740
  * ```typescript
1474
- * bridge.startBatch();
1475
- * const serialized = serializeFunctions(props, bridge);
1476
- * bridge.finishBatch();
1741
+ * // In a component's destroy lifecycle
1742
+ * async destroy() {
1743
+ * await this.cleanupManager.cleanup();
1744
+ * }
1477
1745
  * ```
1746
+ *
1747
+ * @public
1478
1748
  */
1479
- startBatch() {
1480
- this.currentBatchIds.clear();
1749
+ async cleanup() {
1750
+ if (this.cleaned) return;
1751
+ this.cleaned = !0;
1752
+ const e = this.tasks.reverse();
1753
+ this.tasks = [];
1754
+ for (const n of e)
1755
+ try {
1756
+ await n();
1757
+ } catch (s) {
1758
+ console.error("Error in cleanup task:", s);
1759
+ }
1481
1760
  }
1482
1761
  /**
1483
- * Finishes the current batch and removes functions not in this batch.
1762
+ * Checks whether cleanup has already been performed.
1484
1763
  *
1485
- * @remarks
1486
- * This cleans up function references from previous prop updates that
1487
- * are no longer needed, preventing memory leaks.
1764
+ * @returns `true` if {@link cleanup} has been called, `false` otherwise
1488
1765
  *
1489
- * @param keepPrevious - If true, keeps previous batch functions (default: false)
1766
+ * @example
1767
+ * ```typescript
1768
+ * if (!cleanupManager.isCleaned()) {
1769
+ * // Safe to register more tasks
1770
+ * cleanupManager.register(myTask);
1771
+ * }
1772
+ * ```
1773
+ *
1774
+ * @public
1490
1775
  */
1491
- finishBatch(e = !1) {
1492
- if (e) {
1493
- this.currentBatchIds.clear();
1494
- return;
1495
- }
1496
- for (const n of this.localFunctions.keys())
1497
- this.currentBatchIds.has(n) || this.localFunctions.delete(n);
1498
- this.currentBatchIds.clear();
1776
+ isCleaned() {
1777
+ return this.cleaned;
1499
1778
  }
1500
1779
  /**
1501
- * Clears all remote function references.
1780
+ * Resets the manager to its initial state, allowing it to be reused.
1502
1781
  *
1503
1782
  * @remarks
1504
- * Call this when the remote window is no longer accessible
1505
- * (e.g., closed or navigated away).
1506
- */
1507
- clearRemote() {
1508
- this.remoteFunctions.clear();
1509
- }
1510
- /**
1511
- * Returns the current number of registered local functions.
1512
- * Useful for debugging and monitoring.
1513
- */
1514
- get localFunctionCount() {
1515
- return this.localFunctions.size;
1516
- }
1517
- /**
1518
- * Returns the current number of cached remote functions.
1519
- * Useful for debugging and monitoring.
1520
- */
1521
- get remoteFunctionCount() {
1522
- return this.remoteFunctions.size;
1523
- }
1524
- /**
1525
- * Cleans up all function references.
1783
+ * This method clears all registered tasks and resets the cleaned flag.
1784
+ * It is primarily intended for testing scenarios or cases where the
1785
+ * manager needs to be reused after cleanup.
1786
+ *
1787
+ * @example
1788
+ * ```typescript
1789
+ * // In a test teardown
1790
+ * afterEach(() => {
1791
+ * cleanupManager.reset();
1792
+ * });
1793
+ * ```
1794
+ *
1795
+ * @public
1526
1796
  */
1527
- destroy() {
1528
- this.localFunctions.clear(), this.remoteFunctions.clear(), this.currentBatchIds.clear();
1797
+ reset() {
1798
+ this.tasks = [], this.cleaned = !1;
1529
1799
  }
1530
1800
  }
1531
- function se(t, e, n = /* @__PURE__ */ new WeakSet()) {
1532
- if (typeof t == "function")
1533
- return e.serialize(t);
1534
- if (Array.isArray(t)) {
1535
- if (n.has(t))
1536
- throw new Error("Circular reference detected in props - arrays cannot contain circular references");
1537
- n.add(t);
1538
- try {
1539
- return t.map((s) => se(s, e, n));
1540
- } finally {
1541
- n.delete(t);
1542
- }
1543
- }
1544
- if (typeof t == "object" && t !== null) {
1545
- if (n.has(t))
1546
- throw new Error("Circular reference detected in props - objects cannot contain circular references");
1547
- n.add(t);
1548
- try {
1549
- const s = {};
1550
- for (const [r, i] of Object.entries(t))
1551
- ze(r) && (s[r] = se(i, e, n));
1552
- return s;
1553
- } finally {
1554
- n.delete(t);
1555
- }
1556
- }
1557
- return t;
1801
+ const Ne = 100, C = /* @__PURE__ */ new Map();
1802
+ function Vt() {
1803
+ const t = [];
1804
+ for (const [e, n] of C.entries())
1805
+ oe(n) && t.push(e);
1806
+ for (const e of t)
1807
+ C.delete(e);
1558
1808
  }
1559
- function re(t, e, n, s, r = /* @__PURE__ */ new WeakSet()) {
1560
- if (pe.isFunctionRef(t))
1561
- return e.deserialize(t, n, s);
1562
- if (Array.isArray(t)) {
1563
- if (r.has(t))
1564
- throw new Error("Circular reference detected in serialized props");
1565
- r.add(t);
1566
- try {
1567
- return t.map(
1568
- (i) => re(i, e, n, s, r)
1569
- );
1570
- } finally {
1571
- r.delete(t);
1572
- }
1809
+ function Yt(t, e) {
1810
+ if (C.size >= Ne && Vt(), C.size >= Ne) {
1811
+ const n = C.keys().next().value;
1812
+ n && C.delete(n);
1573
1813
  }
1574
- if (typeof t == "object" && t !== null) {
1575
- if (r.has(t))
1576
- throw new Error("Circular reference detected in serialized props");
1577
- r.add(t);
1578
- try {
1579
- const i = {};
1580
- for (const [o, a] of Object.entries(t))
1581
- ze(o) && (i[o] = re(a, e, n, s, r));
1582
- return i;
1583
- } finally {
1584
- r.delete(t);
1585
- }
1586
- }
1587
- return t;
1588
- }
1589
- const Et = /* @__PURE__ */ new Set(["__proto__"]), ke = "__forgeframe.dotify_path__:", J = "__forgeframe.dotify_empty_object_path__:", We = "__forgeframe.dotify_empty_object__";
1590
- function je(t) {
1591
- return !Et.has(t);
1592
- }
1593
- function Te(t) {
1594
- if (t === null || typeof t != "object" || Array.isArray(t))
1595
- return !1;
1596
- const e = Object.getPrototypeOf(t);
1597
- return e === Object.prototype || e === null;
1598
- }
1599
- function Be(t, e = ke) {
1600
- return `${e}${encodeURIComponent(JSON.stringify(t))}`;
1601
- }
1602
- function bt(t) {
1603
- return encodeURIComponent(JSON.stringify(t));
1604
- }
1605
- function Ct(t, e) {
1606
- return `${Be(t)}=${bt(e)}`;
1607
- }
1608
- function Ot(t) {
1609
- return `${Be(t, J)}=1`;
1814
+ C.set(t, e);
1610
1815
  }
1611
- function Rt(t, e, n) {
1612
- Object.defineProperty(t, e, {
1613
- configurable: !0,
1614
- enumerable: !0,
1615
- writable: !0,
1616
- value: n
1617
- });
1618
- }
1619
- function Ve(t, e = []) {
1620
- const n = Object.entries(t);
1621
- if (n.length === 0 && Te(t))
1622
- return e.length === 0 ? We : Ot(e);
1623
- const s = [];
1624
- for (const [r, i] of n) {
1625
- if (i === void 0) continue;
1626
- const o = [...e, r];
1627
- Te(i) ? s.push(Ve(i, o)) : s.push(Ct(o, i));
1628
- }
1629
- return s.filter(Boolean).join("&");
1816
+ function Jt(t) {
1817
+ C.delete(t);
1630
1818
  }
1631
- function xt(t) {
1632
- const e = {};
1633
- if (!t || t === We) return e;
1634
- const n = t.split("&");
1635
- for (const s of n) {
1636
- const r = s.indexOf("=");
1637
- if (r === -1) continue;
1638
- const i = s.slice(0, r), o = s.slice(r + 1);
1639
- if (!i || o === void 0) continue;
1640
- const a = i.startsWith(J);
1641
- let c;
1642
- if (a) {
1643
- if (o !== "1")
1644
- throw new Error("Invalid empty-object DOTIFY entry");
1645
- c = {};
1646
- } else
1647
- try {
1648
- c = JSON.parse(decodeURIComponent(o));
1649
- } catch {
1650
- c = decodeURIComponent(o);
1651
- }
1652
- const u = Dt(i);
1653
- if (u.some((h) => !je(h))) continue;
1654
- let d = e;
1655
- for (let h = 0; h < u.length - 1; h++) {
1656
- const E = u[h], C = d[E];
1657
- (!Object.prototype.hasOwnProperty.call(d, E) || typeof C != "object" || C === null || Array.isArray(C)) && (d[E] = {}), d = d[E];
1819
+ function w(t, e, ...n) {
1820
+ const s = t[e];
1821
+ if (typeof s == "function")
1822
+ try {
1823
+ const r = s(...n);
1824
+ r && typeof r == "object" && "catch" in r && typeof r.catch == "function" && r.catch((i) => {
1825
+ console.error(`Error in async ${e} callback:`, i);
1826
+ });
1827
+ } catch (r) {
1828
+ console.error(`Error in ${e} callback:`, r);
1658
1829
  }
1659
- const m = u[u.length - 1];
1660
- Rt(d, m, c);
1661
- }
1662
- return e;
1663
1830
  }
1664
- function Dt(t) {
1665
- const e = t.startsWith(J) ? J : ke;
1666
- if (!t.startsWith(e))
1667
- throw new Error("Invalid DOTIFY path framing");
1668
- const n = decodeURIComponent(t.slice(e.length)), s = JSON.parse(n);
1669
- if (Array.isArray(s) && s.length > 0 && s.every((r) => typeof r == "string"))
1670
- return s;
1671
- throw new Error("Invalid DOTIFY path framing");
1831
+ function L(t, e, n) {
1832
+ t.emit(g.ERROR, n), w(e, "onError", n);
1672
1833
  }
1673
- function St(t) {
1674
- return typeof t == "object" && t !== null && t.__type__ === "dotify" && typeof t.__value__ == "string";
1675
- }
1676
- function It(t, e, n) {
1677
- const s = {
1678
- ...R,
1679
- ...e
1680
- }, r = {};
1681
- for (const [i, o] of Object.entries(t)) {
1682
- if (o === void 0) continue;
1683
- const a = s[i];
1684
- r[i] = vt(o, a, n);
1685
- }
1686
- return r;
1687
- }
1688
- function vt(t, e, n) {
1689
- if (typeof t == "function")
1690
- return n.serialize(t);
1691
- const s = e?.serialization ?? z.JSON;
1692
- if (s === z.BASE64 && typeof t == "object") {
1693
- const r = JSON.stringify(t);
1694
- return {
1695
- __type__: "base64",
1696
- __value__: btoa(encodeURIComponent(r))
1834
+ function qt(t, e) {
1835
+ if (!t.children)
1836
+ return;
1837
+ const n = t.children({ props: e }), s = {};
1838
+ for (const [r, i] of Object.entries(n)) {
1839
+ const o = Fn(i);
1840
+ if (!o)
1841
+ throw new Error(`Nested component "${r}" is missing component metadata`);
1842
+ if (typeof o.url != "string")
1843
+ throw new Error(
1844
+ `Nested component "${r}" must use a static string URL. Function URLs are not supported in children.`
1845
+ );
1846
+ s[r] = {
1847
+ tag: o.tag,
1848
+ url: o.url,
1849
+ props: o.props,
1850
+ dimensions: typeof o.dimensions == "function" ? void 0 : o.dimensions,
1851
+ defaultContext: o.defaultContext
1697
1852
  };
1698
1853
  }
1699
- return s === z.DOTIFY && typeof t == "object" && t !== null && !Array.isArray(t) ? {
1700
- __type__: "dotify",
1701
- __value__: Ve(t)
1702
- } : se(t, n);
1854
+ return Object.keys(s).length > 0 ? s : void 0;
1703
1855
  }
1704
- function Ue(t, e, n, s, r, i) {
1705
- const o = {
1706
- ...R,
1707
- ...e
1708
- }, a = {};
1709
- for (const [c, u] of Object.entries(t)) {
1710
- if (!je(c)) continue;
1711
- const d = o[c];
1712
- a[c] = Tt(
1713
- u,
1714
- d,
1715
- n,
1716
- s,
1717
- r,
1718
- i
1719
- );
1720
- }
1721
- return a;
1722
- }
1723
- function Tt(t, e, n, s, r, i) {
1724
- if (Ut(t))
1725
- try {
1726
- const o = decodeURIComponent(atob(t.__value__));
1727
- return JSON.parse(o);
1728
- } catch {
1729
- return t;
1730
- }
1731
- if (St(t))
1732
- try {
1733
- return xt(t.__value__);
1734
- } catch {
1735
- return t;
1736
- }
1737
- return re(t, s, r, i);
1738
- }
1739
- function Ut(t) {
1740
- return typeof t == "object" && t !== null && t.__type__ === "base64" && typeof t.__value__ == "string";
1741
- }
1742
- class Ht {
1856
+ class Kt {
1743
1857
  constructor(e, n, s) {
1744
1858
  this.options = e, this.createPropContext = s, this.inputProps = { ...n };
1745
1859
  const r = this.inputProps, i = this.createPropContext(r);
1746
- this.props = Se(r, this.options.props, i);
1860
+ this.props = Ue(r, this.options.props, i);
1747
1861
  }
1748
1862
  /** Current normalized prop snapshot. */
1749
1863
  props;
@@ -1755,8 +1869,8 @@ class Ht {
1755
1869
  * Builds and validates the next props snapshot.
1756
1870
  */
1757
1871
  buildNextProps(e) {
1758
- const n = { ...this.inputProps, ...e }, s = { ...this.props, ...e }, r = this.createPropContext(s), i = Se(s, this.options.props, r);
1759
- return T(i, this.options.props), this.options.validate?.({ props: i }), { nextInputProps: n, nextProps: i };
1872
+ const n = { ...this.inputProps, ...e }, s = { ...this.props, ...e }, r = this.createPropContext(s), i = Ue(s, this.options.props, r);
1873
+ return H(i, this.options.props), this.options.validate?.({ props: i }), { nextInputProps: n, nextProps: i };
1760
1874
  }
1761
1875
  /**
1762
1876
  * Applies a props update and synchronizes it to the host when connected.
@@ -1805,44 +1919,44 @@ class Ht {
1805
1919
  });
1806
1920
  }
1807
1921
  }
1808
- function x(t, e = "100%") {
1922
+ function S(t, e = "100%") {
1809
1923
  return t === void 0 ? e : typeof t == "number" ? `${t}px` : t;
1810
1924
  }
1811
- function q(t, e) {
1925
+ function K(t, e) {
1812
1926
  if (t === void 0) return e;
1813
1927
  if (typeof t == "number") return t;
1814
1928
  const n = parseInt(t, 10);
1815
1929
  return isNaN(n) ? e : n;
1816
1930
  }
1817
- function Nt(t) {
1931
+ function Xt(t) {
1818
1932
  const { name: e, dimensions: n, attributes: s = {}, style: r = {} } = t, i = document.createElement("iframe");
1819
- return i.name = e, i.setAttribute("frameborder", "0"), i.setAttribute("allowtransparency", "true"), i.setAttribute("scrolling", "auto"), Ye(i, n), zt(i, s), Mt(i, r), kt(i, s), i;
1933
+ return i.name = e, i.setAttribute("frameborder", "0"), i.setAttribute("allowtransparency", "true"), i.setAttribute("scrolling", "auto"), Ke(i, n), nn(i, s), tn(i, r), sn(i, s), i;
1820
1934
  }
1821
- function Ft(t) {
1935
+ function Gt(t) {
1822
1936
  try {
1823
1937
  t.src = "about:blank", t.parentNode?.removeChild(t);
1824
1938
  } catch {
1825
1939
  }
1826
1940
  }
1827
- function $t(t, e) {
1828
- Ye(t, e);
1941
+ function Zt(t, e) {
1942
+ Ke(t, e);
1829
1943
  }
1830
- function At(t) {
1944
+ function Qt(t) {
1831
1945
  t.style.display = "", t.style.visibility = "visible";
1832
1946
  }
1833
- function He(t) {
1947
+ function Ae(t) {
1834
1948
  t.style.display = "none", t.style.visibility = "hidden";
1835
1949
  }
1836
- function Lt(t) {
1950
+ function en(t) {
1837
1951
  try {
1838
1952
  t.focus(), t.contentWindow?.focus();
1839
1953
  } catch {
1840
1954
  }
1841
1955
  }
1842
- function Ye(t, e) {
1843
- e.width !== void 0 && (t.style.width = x(e.width)), e.height !== void 0 && (t.style.height = x(e.height));
1956
+ function Ke(t, e) {
1957
+ e.width !== void 0 && (t.style.width = S(e.width)), e.height !== void 0 && (t.style.height = S(e.height));
1844
1958
  }
1845
- function Mt(t, e) {
1959
+ function tn(t, e) {
1846
1960
  for (const [n, s] of Object.entries(e)) {
1847
1961
  if (s === void 0) continue;
1848
1962
  const r = typeof s == "number" ? `${s}px` : s;
@@ -1852,7 +1966,7 @@ function Mt(t, e) {
1852
1966
  );
1853
1967
  }
1854
1968
  }
1855
- function zt(t, e) {
1969
+ function nn(t, e) {
1856
1970
  for (const [n, s] of Object.entries(e))
1857
1971
  if (s !== void 0) {
1858
1972
  if (typeof s == "boolean") {
@@ -1862,19 +1976,19 @@ function zt(t, e) {
1862
1976
  t.setAttribute(n, s);
1863
1977
  }
1864
1978
  }
1865
- function kt(t, e) {
1979
+ function sn(t, e) {
1866
1980
  e.sandbox === void 0 && t.setAttribute(
1867
1981
  "sandbox",
1868
1982
  "allow-scripts allow-same-origin allow-forms allow-popups"
1869
1983
  );
1870
1984
  }
1871
- class Je extends Error {
1985
+ class Xe extends Error {
1872
1986
  constructor(e = "Popup blocked by browser") {
1873
1987
  super(e), this.name = "PopupOpenError";
1874
1988
  }
1875
1989
  }
1876
- function Wt(t) {
1877
- const { url: e, name: n, dimensions: s } = t, r = q(s.width, 500), i = q(s.height, 500), o = Math.floor(window.screenX + (window.outerWidth - r) / 2), a = Math.floor(window.screenY + (window.outerHeight - i) / 2), c = [
1990
+ function rn(t) {
1991
+ const { url: e, name: n, dimensions: s } = t, r = K(s.width, 500), i = K(s.height, 500), o = Math.floor(window.screenX + (window.outerWidth - r) / 2), a = Math.floor(window.screenY + (window.outerHeight - i) / 2), c = [
1878
1992
  `width=${r}`,
1879
1993
  `height=${i}`,
1880
1994
  `left=${o}`,
@@ -1887,23 +2001,23 @@ function Wt(t) {
1887
2001
  "resizable=yes",
1888
2002
  "scrollbars=yes"
1889
2003
  ].join(","), u = window.open(e, n, c);
1890
- if (!u || Vt(u))
1891
- throw new Je();
2004
+ if (!u || cn(u))
2005
+ throw new Xe();
1892
2006
  return u;
1893
2007
  }
1894
- function jt(t) {
2008
+ function on(t) {
1895
2009
  try {
1896
2010
  t.closed || t.close();
1897
2011
  } catch {
1898
2012
  }
1899
2013
  }
1900
- function Bt(t) {
2014
+ function an(t) {
1901
2015
  try {
1902
2016
  t.closed || t.focus();
1903
2017
  } catch {
1904
2018
  }
1905
2019
  }
1906
- function Vt(t) {
2020
+ function cn(t) {
1907
2021
  if (!t) return !0;
1908
2022
  try {
1909
2023
  return !!(t.closed || t.innerHeight === 0 || t.innerWidth === 0);
@@ -1911,7 +2025,7 @@ function Vt(t) {
1911
2025
  return !0;
1912
2026
  }
1913
2027
  }
1914
- function Yt(t, e, n = {}) {
2028
+ function un(t, e, n = {}) {
1915
2029
  const {
1916
2030
  initialInterval: s = 100,
1917
2031
  // Start fast to catch quick closes
@@ -1945,9 +2059,9 @@ function Yt(t, e, n = {}) {
1945
2059
  c = !0, clearTimeout(a);
1946
2060
  };
1947
2061
  }
1948
- function Jt(t, e) {
2062
+ function ln(t, e) {
1949
2063
  try {
1950
- const n = q(e.width, t.outerWidth), s = q(
2064
+ const n = K(e.width, t.outerWidth), s = K(
1951
2065
  e.height,
1952
2066
  t.outerHeight
1953
2067
  );
@@ -1955,9 +2069,9 @@ function Jt(t, e) {
1955
2069
  } catch {
1956
2070
  }
1957
2071
  }
1958
- const Ne = "forgeframe-spinner-style";
1959
- function qt(t, e) {
1960
- const n = t.getElementById(Ne);
2072
+ const $e = "forgeframe-spinner-style";
2073
+ function dn(t, e) {
2074
+ const n = t.getElementById($e);
1961
2075
  if (n) {
1962
2076
  const r = n.getAttribute("nonce");
1963
2077
  if (!e || r === e)
@@ -1965,32 +2079,32 @@ function qt(t, e) {
1965
2079
  n.remove();
1966
2080
  }
1967
2081
  const s = t.createElement("style");
1968
- s.id = Ne, e && s.setAttribute("nonce", e), s.textContent = `
2082
+ s.id = $e, e && s.setAttribute("nonce", e), s.textContent = `
1969
2083
  @keyframes forgeframe-spin {
1970
2084
  to { transform: rotate(360deg); }
1971
2085
  }
1972
2086
  `, (t.head ?? t.documentElement).appendChild(s);
1973
2087
  }
1974
- function Kt(t) {
2088
+ function hn(t) {
1975
2089
  const { doc: e, dimensions: n, uid: s, tag: r } = t, i = e.createElement("div");
1976
2090
  return i.id = `forgeframe-container-${s}`, i.setAttribute("data-forgeframe-tag", r), Object.assign(i.style, {
1977
2091
  display: "inline-block",
1978
2092
  position: "relative",
1979
- width: x(n.width),
1980
- height: x(n.height),
2093
+ width: S(n.width),
2094
+ height: S(n.height),
1981
2095
  overflow: "hidden"
1982
2096
  }), i;
1983
2097
  }
1984
- function Xt(t) {
2098
+ function pn(t) {
1985
2099
  const { doc: e, dimensions: n, cspNonce: s } = t;
1986
- qt(e, s);
2100
+ dn(e, s);
1987
2101
  const r = e.createElement("div");
1988
2102
  Object.assign(r.style, {
1989
2103
  display: "flex",
1990
2104
  alignItems: "center",
1991
2105
  justifyContent: "center",
1992
- width: x(n.width),
1993
- height: x(n.height),
2106
+ width: S(n.width),
2107
+ height: S(n.height),
1994
2108
  backgroundColor: "#f5f5f5",
1995
2109
  position: "absolute",
1996
2110
  top: "0",
@@ -2007,20 +2121,20 @@ function Xt(t) {
2007
2121
  animation: "forgeframe-spin 1s linear infinite"
2008
2122
  }), r.appendChild(i), r;
2009
2123
  }
2010
- function Gt(t, e = 200) {
2124
+ function fn(t, e = 200) {
2011
2125
  return new Promise((n) => {
2012
2126
  t.style.opacity = "0", t.style.transition = `opacity ${e}ms ease-in`, t.offsetHeight, t.style.opacity = "1", setTimeout(n, e);
2013
2127
  });
2014
2128
  }
2015
- function Zt(t, e = 200) {
2129
+ function mn(t, e = 200) {
2016
2130
  return new Promise((n) => {
2017
2131
  t.style.transition = `opacity ${e}ms ease-out`, t.style.opacity = "0", setTimeout(n, e);
2018
2132
  });
2019
2133
  }
2020
- async function Qt(t, e, n) {
2021
- e && (await Zt(e, 150), e.remove()), n.style.display = "", n.style.visibility = "visible", n.style.opacity = "0", await Gt(n, 150);
2134
+ async function gn(t, e, n) {
2135
+ e && (await mn(e, 150), e.remove()), n.style.display = "", n.style.visibility = "visible", n.style.opacity = "0", await fn(n, 150);
2022
2136
  }
2023
- class en {
2137
+ class yn {
2024
2138
  constructor(e, n, s, r, i) {
2025
2139
  this.options = e, this.uid = n, this.getProps = s, this.resolveDimensions = r, this.callbacks = i, this.context = this.options.defaultContext;
2026
2140
  }
@@ -2055,10 +2169,10 @@ class en {
2055
2169
  if (!this.container) return;
2056
2170
  const s = this.container;
2057
2171
  this.ownedContainer = null;
2058
- const r = this.getProps(), i = this.options.prerenderTemplate ?? Xt, o = this.options.containerTemplate ?? Kt, a = this.resolveDimensions(), c = r.cspNonce;
2059
- if (this.context === p.IFRAME) {
2172
+ const r = this.getProps(), i = this.options.prerenderTemplate ?? pn, o = this.options.containerTemplate ?? hn, a = this.resolveDimensions(), c = r.cspNonce;
2173
+ if (this.context === f.IFRAME) {
2060
2174
  const h = n();
2061
- this.iframe = e(h), He(this.iframe);
2175
+ this.iframe = e(h), Ae(this.iframe);
2062
2176
  }
2063
2177
  const u = {
2064
2178
  uid: this.uid,
@@ -2103,7 +2217,7 @@ class en {
2103
2217
  */
2104
2218
  createIframeElement(e) {
2105
2219
  const n = this.resolveDimensions(), s = this.getProps(), r = typeof this.options.attributes == "function" ? this.options.attributes(s) : this.options.attributes ?? {}, i = typeof this.options.style == "function" ? this.options.style(s) : this.options.style ?? {};
2106
- return Nt({
2220
+ return Xt({
2107
2221
  name: e,
2108
2222
  dimensions: n,
2109
2223
  attributes: r,
@@ -2115,18 +2229,18 @@ class en {
2115
2229
  */
2116
2230
  open(e) {
2117
2231
  const n = e.buildUrl(e.baseUrl), s = e.buildBodyParams(), r = s.toString().length > 0;
2118
- if (this.context === p.IFRAME) {
2232
+ if (this.context === f.IFRAME) {
2119
2233
  if (!this.iframe)
2120
2234
  throw new Error("Iframe not created during prerender");
2121
2235
  return r ? e.submitBodyForm(this.iframe.name, n, s) : this.iframe.src = n, this.iframe.contentWindow;
2122
2236
  }
2123
- const i = e.buildWindowName(), o = Wt({
2237
+ const i = e.buildWindowName(), o = rn({
2124
2238
  url: r ? "about:blank" : n,
2125
2239
  name: i,
2126
2240
  dimensions: this.resolveDimensions()
2127
2241
  });
2128
2242
  r && e.submitBodyForm(i, n, s);
2129
- const a = Yt(o, () => {
2243
+ const a = un(o, () => {
2130
2244
  e.onPopupClose();
2131
2245
  });
2132
2246
  return e.registerCleanup(a), o;
@@ -2135,7 +2249,7 @@ class en {
2135
2249
  * Swaps prerender content with the live iframe after host initialization.
2136
2250
  */
2137
2251
  async swapPrerenderContentIfNeeded() {
2138
- this.context === p.IFRAME && this.iframe && this.container && (await Qt(this.container, this.prerenderElement, this.iframe), this.prerenderElement = null);
2252
+ this.context === f.IFRAME && this.iframe && this.container && (await gn(this.container, this.prerenderElement, this.iframe), this.prerenderElement = null);
2139
2253
  }
2140
2254
  /**
2141
2255
  * Submits a hidden form to navigate a target window via POST.
@@ -2161,59 +2275,96 @@ class en {
2161
2275
  * Focuses iframe/popup context.
2162
2276
  */
2163
2277
  focus(e) {
2164
- this.context === p.IFRAME && this.iframe ? Lt(this.iframe) : this.context === p.POPUP && e && Bt(e);
2278
+ this.context === f.IFRAME && this.iframe ? en(this.iframe) : this.context === f.POPUP && e && an(e);
2165
2279
  }
2166
2280
  /**
2167
2281
  * Resizes iframe/popup context.
2168
2282
  */
2169
2283
  resize(e, n) {
2170
- this.context === p.IFRAME && this.iframe ? $t(this.iframe, e) : this.context === p.POPUP && n && Jt(n, e);
2284
+ this.context === f.IFRAME && this.iframe ? Zt(this.iframe, e) : this.context === f.POPUP && n && ln(n, e);
2171
2285
  }
2172
2286
  /**
2173
2287
  * Shows iframe context.
2174
2288
  */
2175
2289
  show() {
2176
- this.context === p.IFRAME && this.iframe && At(this.iframe);
2290
+ this.context === f.IFRAME && this.iframe && Qt(this.iframe);
2177
2291
  }
2178
2292
  /**
2179
2293
  * Hides iframe context.
2180
2294
  */
2181
2295
  hide() {
2182
- this.context === p.IFRAME && this.iframe && He(this.iframe);
2296
+ this.context === f.IFRAME && this.iframe && Ae(this.iframe);
2183
2297
  }
2184
2298
  /**
2185
2299
  * Destroys rendered iframe/popup DOM artifacts.
2186
2300
  */
2187
2301
  destroy(e) {
2188
- this.iframe && (Ft(this.iframe), this.iframe = null), this.context === p.POPUP && e && jt(e), this.prerenderElement && (this.prerenderElement.remove(), this.prerenderElement = null), this.ownedContainer && (this.ownedContainer.remove(), this.ownedContainer = null), this.container = null;
2302
+ this.iframe && (Gt(this.iframe), this.iframe = null), this.context === f.POPUP && e && on(e), this.prerenderElement && (this.prerenderElement.remove(), this.prerenderElement = null), this.ownedContainer && (this.ownedContainer.remove(), this.ownedContainer = null), this.container = null;
2303
+ }
2304
+ }
2305
+ function wn(t) {
2306
+ const e = [];
2307
+ if (t.options?.anyConsumer) {
2308
+ for (const n of Un())
2309
+ n.instance.uid !== t.uid && e.push({
2310
+ uid: n.instance.uid,
2311
+ tag: n.tag,
2312
+ exports: n.instance.exports
2313
+ });
2314
+ return e;
2189
2315
  }
2316
+ for (const n of Hn(t.tag))
2317
+ n.uid !== t.uid && e.push({
2318
+ uid: n.uid,
2319
+ tag: t.tag,
2320
+ exports: n.exports
2321
+ });
2322
+ return e;
2323
+ }
2324
+ function Ge() {
2325
+ let t, e;
2326
+ return { promise: new Promise((s, r) => {
2327
+ t = s, e = r;
2328
+ }), resolve: t, reject: e };
2329
+ }
2330
+ function _n(t, e, n = "Operation timed out") {
2331
+ return new Promise((s, r) => {
2332
+ const i = setTimeout(() => {
2333
+ r(new Error(`${n} (${e}ms)`));
2334
+ }, e);
2335
+ t.then((o) => {
2336
+ clearTimeout(i), s(o);
2337
+ }).catch((o) => {
2338
+ clearTimeout(i), r(o);
2339
+ });
2340
+ });
2190
2341
  }
2191
- const ie = "forgeframe:";
2192
- function ee(t) {
2193
- return ie + JSON.stringify(t);
2342
+ const ae = "forgeframe:";
2343
+ function ne(t) {
2344
+ return ae + JSON.stringify(t);
2194
2345
  }
2195
- function tn(t) {
2196
- if (typeof t != "string" || !t.startsWith(ie)) return null;
2346
+ function Pn(t) {
2347
+ if (typeof t != "string" || !t.startsWith(ae)) return null;
2197
2348
  try {
2198
- const e = t.slice(ie.length), n = JSON.parse(e);
2349
+ const e = t.slice(ae.length), n = JSON.parse(e);
2199
2350
  return !n.id || !n.type || !n.name || !n.source ? null : n;
2200
2351
  } catch {
2201
2352
  return null;
2202
2353
  }
2203
2354
  }
2204
- function Fe(t, e, n, s) {
2355
+ function Me(t, e, n, s) {
2205
2356
  return {
2206
2357
  id: t,
2207
- type: W.REQUEST,
2358
+ type: j.REQUEST,
2208
2359
  name: e,
2209
2360
  data: n,
2210
2361
  source: s
2211
2362
  };
2212
2363
  }
2213
- function nn(t, e, n, s) {
2364
+ function En(t, e, n, s) {
2214
2365
  return {
2215
2366
  id: t,
2216
- type: W.RESPONSE,
2367
+ type: j.RESPONSE,
2217
2368
  name: "response",
2218
2369
  data: e,
2219
2370
  source: n,
@@ -2223,22 +2374,10 @@ function nn(t, e, n, s) {
2223
2374
  } : void 0
2224
2375
  };
2225
2376
  }
2226
- function sn(t) {
2227
- return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2228
- }
2229
- function rn(t) {
2230
- if (!t.includes("*"))
2231
- return null;
2232
- const e = t.split("*").map((n) => sn(n)).join(".*");
2233
- return new RegExp(`^${e}$`);
2234
- }
2235
- function on(t, e) {
2236
- return t.global || t.sticky ? new RegExp(t.source, t.flags.replace(/[gy]/g, "")).test(e) : t.test(e);
2237
- }
2238
- function an(t, e, n) {
2377
+ function bn(t, e, n) {
2239
2378
  return e !== t.targetWin ? !1 : t.expectedOrigin === "*" ? !0 : n === t.expectedOrigin;
2240
2379
  }
2241
- function cn(t, e) {
2380
+ function Cn(t, e) {
2242
2381
  if (t === "*")
2243
2382
  return "*";
2244
2383
  if (t === "/")
@@ -2249,7 +2388,7 @@ function cn(t, e) {
2249
2388
  return t;
2250
2389
  }
2251
2390
  }
2252
- class qe {
2391
+ class Ze {
2253
2392
  /**
2254
2393
  * Creates a new Messenger instance.
2255
2394
  *
@@ -2289,7 +2428,7 @@ class qe {
2289
2428
  else if (e instanceof RegExp)
2290
2429
  this.allowedOriginPatterns.push(e);
2291
2430
  else {
2292
- const n = rn(e);
2431
+ const n = Je(e);
2293
2432
  n ? this.wildcardPatternRegistry.has(e) || (this.wildcardPatternRegistry.set(e, n), this.allowedOriginPatterns.push(n)) : this.allowedOrigins.add(e);
2294
2433
  }
2295
2434
  }
@@ -2322,7 +2461,7 @@ class qe {
2322
2461
  if (this.allowedOrigins.has(e))
2323
2462
  return !0;
2324
2463
  for (const n of this.allowedOriginPatterns)
2325
- if (on(n, e))
2464
+ if (ie(n, e))
2326
2465
  return !0;
2327
2466
  return !1;
2328
2467
  }
@@ -2334,7 +2473,7 @@ class qe {
2334
2473
  const r = e, i = this.sourceUidRegistry.get(r);
2335
2474
  if (i)
2336
2475
  return { uid: i, domain: n, window: e };
2337
- const o = s && typeof s.uid == "string" && s.uid.length > 0 ? s.uid : k();
2476
+ const o = s && typeof s.uid == "string" && s.uid.length > 0 ? s.uid : W();
2338
2477
  return this.sourceUidRegistry.set(r, o), { uid: o, domain: n, window: e };
2339
2478
  }
2340
2479
  /**
@@ -2353,20 +2492,20 @@ class qe {
2353
2492
  async send(e, n, s, r, i = 1e4) {
2354
2493
  if (this.destroyed)
2355
2494
  throw new Error("Messenger has been destroyed");
2356
- const o = k(), a = Fe(o, s, r, {
2495
+ const o = W(), a = Me(o, s, r, {
2357
2496
  uid: this.uid,
2358
2497
  domain: this.domain
2359
- }), c = Le(), u = setTimeout(() => {
2498
+ }), c = Ge(), u = setTimeout(() => {
2360
2499
  this.pending.delete(o), c.reject(new Error(`Message "${s}" timed out after ${i}ms`));
2361
2500
  }, i);
2362
2501
  this.pending.set(o, {
2363
2502
  deferred: c,
2364
2503
  timeout: u,
2365
2504
  targetWin: e,
2366
- expectedOrigin: cn(n, this.domain)
2505
+ expectedOrigin: Cn(n, this.domain)
2367
2506
  });
2368
2507
  try {
2369
- e.postMessage(ee(a), n);
2508
+ e.postMessage(ne(a), n);
2370
2509
  } catch (d) {
2371
2510
  throw this.pending.delete(o), clearTimeout(u), d;
2372
2511
  }
@@ -2385,11 +2524,11 @@ class qe {
2385
2524
  post(e, n, s, r) {
2386
2525
  if (this.destroyed)
2387
2526
  throw new Error("Messenger has been destroyed");
2388
- const i = k(), o = Fe(i, s, r, {
2527
+ const i = W(), o = Me(i, s, r, {
2389
2528
  uid: this.uid,
2390
2529
  domain: this.domain
2391
2530
  });
2392
- e.postMessage(ee(o), n);
2531
+ e.postMessage(ne(o), n);
2393
2532
  }
2394
2533
  /**
2395
2534
  * Registers a handler for incoming messages of a specific type.
@@ -2411,7 +2550,7 @@ class qe {
2411
2550
  this.listener = (e) => {
2412
2551
  if (e.source === this.win || !this.isOriginTrusted(e.origin))
2413
2552
  return;
2414
- const n = tn(e.data);
2553
+ const n = Pn(e.data);
2415
2554
  if (!n) return;
2416
2555
  const s = e.source;
2417
2556
  !s || typeof s.postMessage != "function" || this.handleMessage(n, s, e.origin);
@@ -2422,10 +2561,10 @@ class qe {
2422
2561
  * @internal
2423
2562
  */
2424
2563
  async handleMessage(e, n, s) {
2425
- if (e.type === W.RESPONSE) {
2564
+ if (e.type === j.RESPONSE) {
2426
2565
  const r = this.pending.get(e.id);
2427
2566
  if (r) {
2428
- if (!an(r, n, s))
2567
+ if (!bn(r, n, s))
2429
2568
  return;
2430
2569
  if (this.pending.delete(e.id), clearTimeout(r.timeout), e.error) {
2431
2570
  const i = new Error(e.error.message);
@@ -2435,156 +2574,62 @@ class qe {
2435
2574
  }
2436
2575
  return;
2437
2576
  }
2438
- if (e.type === W.REQUEST) {
2577
+ if (e.type === j.REQUEST) {
2439
2578
  const r = this.handlers.get(e.name);
2440
2579
  if (!r)
2441
2580
  return;
2442
2581
  let i, o;
2443
- try {
2444
- const c = this.resolveVerifiedSource(
2445
- n,
2446
- s,
2447
- e.source
2448
- );
2449
- i = await r(e.data, c);
2450
- } catch (c) {
2451
- o = c instanceof Error ? c : new Error(String(c));
2452
- }
2453
- const a = nn(
2454
- e.id,
2455
- i,
2456
- { uid: this.uid, domain: this.domain },
2457
- o
2458
- );
2459
- try {
2460
- n.postMessage(ee(a), s);
2461
- } catch {
2462
- }
2463
- }
2464
- }
2465
- /**
2466
- * Cleans up the messenger and releases resources.
2467
- *
2468
- * @remarks
2469
- * Removes the message listener, rejects all pending requests,
2470
- * and clears all handlers.
2471
- */
2472
- destroy() {
2473
- if (!this.destroyed) {
2474
- this.destroyed = !0, this.listener && (this.win.removeEventListener("message", this.listener), this.listener = null);
2475
- for (const e of this.pending.values())
2476
- clearTimeout(e.timeout), e.deferred.reject(new Error("Messenger destroyed"));
2477
- this.pending.clear(), this.handlers.clear();
2478
- }
2479
- }
2480
- /**
2481
- * Checks if the messenger has been destroyed.
2482
- *
2483
- * @returns True if destroy() has been called
2484
- */
2485
- isDestroyed() {
2486
- return this.destroyed;
2487
- }
2488
- }
2489
- const un = [
2490
- "init",
2491
- "close",
2492
- "resize",
2493
- "show",
2494
- "hide",
2495
- "onError",
2496
- "updateProps",
2497
- "export"
2498
- ], $e = 32 * 1024;
2499
- function ln(t) {
2500
- const e = yn(t);
2501
- return `${j}${e}`;
2502
- }
2503
- function Ke(t) {
2504
- if (!t || !t.startsWith(j))
2505
- return null;
2506
- const e = t.slice(j.length);
2507
- return wn(e);
2508
- }
2509
- function O(t) {
2510
- return typeof t == "object" && t !== null;
2511
- }
2512
- function hn(t) {
2513
- return O(t);
2514
- }
2515
- function dn(t) {
2516
- return O(t) && un.every(
2517
- (e) => typeof t[e] == "string" && t[e].length > 0
2518
- );
2519
- }
2520
- function fn(t) {
2521
- if (!O(t) || typeof t.tag != "string" || t.tag.length === 0 || typeof t.url != "string" || t.url.length === 0 || t.props !== void 0 && !O(t.props) || t.defaultContext !== void 0 && t.defaultContext !== p.IFRAME && t.defaultContext !== p.POPUP)
2522
- return !1;
2523
- if (t.dimensions !== void 0) {
2524
- if (!O(t.dimensions))
2525
- return !1;
2526
- const { width: e, height: n } = t.dimensions;
2527
- if (e !== void 0 && typeof e != "string" && typeof e != "number" || n !== void 0 && typeof n != "string" && typeof n != "number")
2528
- return !1;
2529
- }
2530
- return !0;
2531
- }
2532
- function pn(t) {
2533
- return O(t) ? Object.values(t).every((e) => fn(e)) : !1;
2534
- }
2535
- function mn(t) {
2536
- return !(!O(t) || typeof t.uid != "string" || t.uid.length === 0 || typeof t.tag != "string" || t.tag.length === 0 || typeof t.version != "string" || t.version.length === 0 || t.version !== oe || t.context !== p.IFRAME && t.context !== p.POPUP || typeof t.consumerDomain != "string" || t.consumerDomain.length === 0 || !hn(t.props) || !dn(t.exports) || t.children !== void 0 && !pn(t.children));
2537
- }
2538
- function me(t = window) {
2539
- try {
2540
- return t.name.startsWith(j);
2541
- } catch {
2542
- return !1;
2543
- }
2544
- }
2545
- function gn(t, e = window) {
2546
- return Ke(e.name)?.tag === t;
2547
- }
2548
- function yn(t) {
2549
- try {
2550
- const e = JSON.stringify(t), n = btoa(encodeURIComponent(e)), s = n.length;
2551
- if (s > $e)
2552
- throw new Error(
2553
- `Payload size (${Math.round(s / 1024)}KB) exceeds maximum allowed size (${$e / 1024}KB). Consider reducing the amount of data passed via props.`
2582
+ try {
2583
+ const c = this.resolveVerifiedSource(
2584
+ n,
2585
+ s,
2586
+ e.source
2587
+ );
2588
+ i = await r(e.data, c);
2589
+ } catch (c) {
2590
+ o = c instanceof Error ? c : new Error(String(c));
2591
+ }
2592
+ const a = En(
2593
+ e.id,
2594
+ i,
2595
+ { uid: this.uid, domain: this.domain },
2596
+ o
2554
2597
  );
2555
- return n;
2556
- } catch (e) {
2557
- throw e instanceof Error && e.message.includes("Payload size") ? e : new Error(`Failed to encode payload: ${e}`);
2598
+ try {
2599
+ n.postMessage(ne(a), s);
2600
+ } catch {
2601
+ }
2602
+ }
2558
2603
  }
2559
- }
2560
- function wn(t) {
2561
- try {
2562
- const e = decodeURIComponent(atob(t)), n = JSON.parse(e);
2563
- return mn(n) ? n : null;
2564
- } catch {
2565
- return null;
2604
+ /**
2605
+ * Cleans up the messenger and releases resources.
2606
+ *
2607
+ * @remarks
2608
+ * Removes the message listener, rejects all pending requests,
2609
+ * and clears all handlers.
2610
+ */
2611
+ destroy() {
2612
+ if (!this.destroyed) {
2613
+ this.destroyed = !0, this.listener && (this.win.removeEventListener("message", this.listener), this.listener = null);
2614
+ for (const e of this.pending.values())
2615
+ clearTimeout(e.timeout), e.deferred.reject(new Error("Messenger destroyed"));
2616
+ this.pending.clear(), this.handlers.clear();
2617
+ }
2618
+ }
2619
+ /**
2620
+ * Checks if the messenger has been destroyed.
2621
+ *
2622
+ * @returns True if destroy() has been called
2623
+ */
2624
+ isDestroyed() {
2625
+ return this.destroyed;
2566
2626
  }
2567
2627
  }
2568
- function _n(t) {
2569
- return {
2570
- uid: t.uid,
2571
- tag: t.tag,
2572
- version: oe,
2573
- context: t.context,
2574
- consumerDomain: t.consumerDomain,
2575
- props: t.props,
2576
- exports: t.exports,
2577
- children: t.children
2578
- };
2579
- }
2580
- function Pn(t = window) {
2581
- return Ke(t.name);
2582
- }
2583
- class En {
2628
+ class On {
2584
2629
  constructor(e, n, s, r) {
2585
2630
  this.uid = e, this.options = n, this.resolveUrl = s, this.resolveUrlOrigin = r;
2586
2631
  const i = this.buildTrustedDomains();
2587
- this.messenger = new qe(this.uid, window, B(), i), this.bridge = new pe(this.messenger);
2632
+ this.messenger = new Ze(this.uid, window, q(), i), this.bridge = new de(this.messenger);
2588
2633
  }
2589
2634
  /** Messenger for host communication. */
2590
2635
  messenger;
@@ -2612,7 +2657,7 @@ class En {
2612
2657
  * Returns true when the domain option explicitly includes this origin.
2613
2658
  */
2614
2659
  isExplicitDomainTrust(e) {
2615
- return this.options.domain ? U(this.options.domain, e) : !1;
2660
+ return this.options.domain ? X(this.options.domain, e) : !1;
2616
2661
  }
2617
2662
  /**
2618
2663
  * Ensures the messenger trusts the origin for a resolved host URL.
@@ -2634,7 +2679,7 @@ class En {
2634
2679
  * Returns true when the host window is connected and not closed.
2635
2680
  */
2636
2681
  isHostConnected() {
2637
- return !!(this.hostWindow && !ne(this.hostWindow));
2682
+ return !!(this.hostWindow && !oe(this.hostWindow));
2638
2683
  }
2639
2684
  /**
2640
2685
  * Serializes host props while keeping function bridge references in sync.
@@ -2653,13 +2698,13 @@ class En {
2653
2698
  * Sends the current props snapshot to the host window when available.
2654
2699
  */
2655
2700
  async sendPropsUpdateToHost(e, n) {
2656
- if (!this.hostWindow || ne(this.hostWindow))
2701
+ if (!this.hostWindow || oe(this.hostWindow))
2657
2702
  return;
2658
- const s = this.getHostDomain(), r = Ie(
2703
+ const s = this.getHostDomain(), r = Fe(
2659
2704
  e,
2660
2705
  n,
2661
2706
  s,
2662
- Me(this.hostWindow)
2707
+ qe(this.hostWindow)
2663
2708
  ), i = this.serializePropsForHost(
2664
2709
  r,
2665
2710
  n,
@@ -2680,7 +2725,7 @@ class En {
2680
2725
  * Builds the window.name payload for host initialization.
2681
2726
  */
2682
2727
  buildWindowName(e) {
2683
- const n = e.hostDomain ?? this.getHostDomain(), s = Ie(
2728
+ const n = e.hostDomain ?? this.getHostDomain(), s = Fe(
2684
2729
  e.props,
2685
2730
  e.propDefinitions,
2686
2731
  n,
@@ -2688,16 +2733,16 @@ class En {
2688
2733
  ), r = this.serializePropsForHost(
2689
2734
  s,
2690
2735
  e.propDefinitions
2691
- ), i = _n({
2736
+ ), i = gt({
2692
2737
  uid: this.uid,
2693
2738
  tag: e.tag,
2694
2739
  context: e.context,
2695
- consumerDomain: B(),
2740
+ consumerDomain: q(),
2696
2741
  props: r,
2697
2742
  exports: e.exports,
2698
2743
  children: e.children
2699
2744
  });
2700
- return ln(i);
2745
+ return at(i);
2701
2746
  }
2702
2747
  /**
2703
2748
  * Waits for the host to send the initialization handshake.
@@ -2705,10 +2750,10 @@ class En {
2705
2750
  async waitForHost(e, n, s) {
2706
2751
  if (this.hostInitialized)
2707
2752
  return;
2708
- const r = Le();
2753
+ const r = Ge();
2709
2754
  this.initPromise = r;
2710
2755
  try {
2711
- await st(
2756
+ await _n(
2712
2757
  r.promise,
2713
2758
  e,
2714
2759
  `Host component "${n}" (uid: ${this.uid}) did not initialize within ${e}ms. Check that the host page loads correctly and calls the initialization code.`
@@ -2735,7 +2780,10 @@ class En {
2735
2780
  const r = new Error(n.message);
2736
2781
  return r.stack = n.stack, e.onError(r), { success: !0 };
2737
2782
  }
2738
- ), this.messenger.on(l.EXPORT, async (n, s) => this.isHostControlSource(s) ? (e.onExport(n), { success: !0 }) : { success: !1 }), this.messenger.on(l.CONSUMER_EXPORT, async (n, s) => this.isHostControlSource(s) ? (e.onConsumerExport(n), { success: !0 }) : { success: !1 }), this.messenger.on(l.GET_SIBLINGS, async (n, s) => this.isHostControlSource(s) ? e.onGetSiblings(n) : { success: !1 });
2783
+ ), this.messenger.on(l.EXPORT, async (n, s) => this.isHostControlSource(s) ? (e.onExport(n), { success: !0 }) : { success: !1 }), this.messenger.on(l.CONSUMER_EXPORT, async (n, s) => this.isHostControlSource(s) ? (e.onConsumerExport(n), { success: !0 }) : { success: !1 }), this.messenger.on(
2784
+ l.GET_SIBLINGS,
2785
+ async (n, s) => this.isHostControlSource(s) ? e.onGetSiblings(n) : { success: !1 }
2786
+ );
2739
2787
  }
2740
2788
  /**
2741
2789
  * Returns true when a lifecycle/control message came from the opened host window.
@@ -2750,7 +2798,7 @@ class En {
2750
2798
  this.messenger.destroy(), this.bridge.destroy();
2751
2799
  }
2752
2800
  }
2753
- class ge {
2801
+ class _e {
2754
2802
  /** Event emitter for lifecycle events. */
2755
2803
  event;
2756
2804
  /** Arbitrary state storage for the component instance. */
@@ -2784,106 +2832,6 @@ class ge {
2784
2832
  destroyed = !1;
2785
2833
  /** @internal */
2786
2834
  closing = !1;
2787
- /** @internal */
2788
- get props() {
2789
- return this.propsPipeline ? this.propsPipeline.props : {};
2790
- }
2791
- /** @internal */
2792
- set props(e) {
2793
- this.propsPipeline && (this.propsPipeline.props = e);
2794
- }
2795
- /** @internal */
2796
- get inputProps() {
2797
- return this.propsPipeline ? this.propsPipeline.inputProps : {};
2798
- }
2799
- /** @internal */
2800
- set inputProps(e) {
2801
- this.propsPipeline && (this.propsPipeline.inputProps = e);
2802
- }
2803
- /** @internal */
2804
- get pendingPropsUpdate() {
2805
- return this.propsPipeline ? this.propsPipeline.pendingPropsUpdate : null;
2806
- }
2807
- /** @internal */
2808
- set pendingPropsUpdate(e) {
2809
- this.propsPipeline && (this.propsPipeline.pendingPropsUpdate = e);
2810
- }
2811
- /** @internal */
2812
- get context() {
2813
- return this.renderer ? this.renderer.context : this.options.defaultContext;
2814
- }
2815
- /** @internal */
2816
- set context(e) {
2817
- this.renderer && (this.renderer.context = e);
2818
- }
2819
- /** @internal */
2820
- get hostWindow() {
2821
- return this.transport ? this.transport.hostWindow : null;
2822
- }
2823
- /** @internal */
2824
- set hostWindow(e) {
2825
- this.transport && (this.transport.hostWindow = e);
2826
- }
2827
- /** @internal */
2828
- get openedHostDomain() {
2829
- return this.transport ? this.transport.openedHostDomain : null;
2830
- }
2831
- /** @internal */
2832
- set openedHostDomain(e) {
2833
- this.transport && (this.transport.openedHostDomain = e);
2834
- }
2835
- /** @internal */
2836
- get dynamicUrlTrustedOrigin() {
2837
- return this.transport ? this.transport.dynamicUrlTrustedOrigin : null;
2838
- }
2839
- /** @internal */
2840
- set dynamicUrlTrustedOrigin(e) {
2841
- this.transport && (this.transport.dynamicUrlTrustedOrigin = e);
2842
- }
2843
- /** @internal */
2844
- get iframe() {
2845
- return this.renderer ? this.renderer.iframe : null;
2846
- }
2847
- /** @internal */
2848
- set iframe(e) {
2849
- this.renderer && (this.renderer.iframe = e);
2850
- }
2851
- /** @internal */
2852
- get container() {
2853
- return this.renderer ? this.renderer.container : null;
2854
- }
2855
- /** @internal */
2856
- set container(e) {
2857
- this.renderer && (this.renderer.container = e);
2858
- }
2859
- /** @internal */
2860
- get initPromise() {
2861
- return this.transport ? this.transport.initPromise : null;
2862
- }
2863
- /** @internal */
2864
- set initPromise(e) {
2865
- this.transport && (this.transport.initPromise = e);
2866
- }
2867
- /** @internal */
2868
- get hostInitialized() {
2869
- return this.transport ? this.transport.hostInitialized : !1;
2870
- }
2871
- /** @internal */
2872
- set hostInitialized(e) {
2873
- this.transport && (this.transport.hostInitialized = e);
2874
- }
2875
- /** @internal */
2876
- get messenger() {
2877
- if (!this.transport)
2878
- throw new Error("Consumer transport is not initialized");
2879
- return this.transport.messenger;
2880
- }
2881
- /** @internal */
2882
- get bridge() {
2883
- if (!this.transport)
2884
- throw new Error("Consumer transport is not initialized");
2885
- return this.transport.bridge;
2886
- }
2887
2835
  /**
2888
2836
  * Creates a new ConsumerComponent instance.
2889
2837
  *
@@ -2891,25 +2839,25 @@ class ge {
2891
2839
  * @param props - Initial props to pass to the component
2892
2840
  */
2893
2841
  constructor(e, n = {}) {
2894
- this._uid = tt(), this.options = this.normalizeOptions(e), this.event = new Ae(), this.cleanup = new nt(), this.renderer = new en(
2842
+ this._uid = wt(), this.options = this.normalizeOptions(e), this.event = new Le(), this.cleanup = new Bt(), this.renderer = new yn(
2895
2843
  this.options,
2896
2844
  this.uid,
2897
- () => this.props,
2845
+ () => this.propsPipeline.props,
2898
2846
  () => this.resolveDimensions(),
2899
2847
  {
2900
2848
  close: () => this.close(),
2901
2849
  focus: () => this.focus()
2902
2850
  }
2903
- ), this.propsPipeline = new Ht(
2851
+ ), this.propsPipeline = new Kt(
2904
2852
  this.options,
2905
2853
  { ...n },
2906
2854
  (s) => this.createPropContext(s)
2907
- ), this.transport = new En(
2855
+ ), !this.destroyed && (this.transport = new On(
2908
2856
  this.uid,
2909
2857
  this.options,
2910
2858
  () => this.resolveUrl(),
2911
2859
  (s) => this.resolveUrlOrigin(s)
2912
- ), this.setupMessageHandlers(), this.setupCleanup();
2860
+ ), this.setupMessageHandlers(), this.setupCleanup());
2913
2861
  }
2914
2862
  /**
2915
2863
  * Renders the component into a DOM container.
@@ -2934,14 +2882,14 @@ class ge {
2934
2882
  throw new Error("Component has been destroyed");
2935
2883
  if (this.rendered)
2936
2884
  throw new Error("Component has already been rendered");
2937
- this.context = n ?? this.options.defaultContext, this.checkEligibility(), T(this.props, this.options.props), this.options.validate?.({ props: this.props }), this.container = this.resolveContainer(e), this.event.emit(g.PRERENDER), this.callPropCallback("onPrerender"), await this.prerender(), this.event.emit(g.PRERENDERED), this.callPropCallback("onPrerendered"), this.event.emit(g.RENDER), this.callPropCallback("onRender");
2885
+ this.renderer.context = n ?? this.options.defaultContext, this.checkEligibility(), H(this.propsPipeline.props, this.options.props), this.options.validate?.({ props: this.propsPipeline.props }), this.renderer.container = this.resolveContainer(e), this.event.emit(g.PRERENDER), w(this.propsPipeline.props, "onPrerender"), await this.prerender(), this.event.emit(g.PRERENDERED), w(this.propsPipeline.props, "onPrerendered"), this.event.emit(g.RENDER), w(this.propsPipeline.props, "onRender");
2938
2886
  try {
2939
- await this.open(), await this.waitForHost(), this.context === p.IFRAME && this.iframe && await this.renderer.swapPrerenderContentIfNeeded();
2887
+ await this.open(), await this.waitForHost(), this.renderer.context === f.IFRAME && this.renderer.iframe && await this.renderer.swapPrerenderContentIfNeeded();
2940
2888
  } catch (s) {
2941
2889
  throw await this.destroy().catch(() => {
2942
2890
  }), s;
2943
2891
  }
2944
- this.rendered = !0, this.event.emit(g.RENDERED), this.callPropCallback("onRendered"), this.event.emit(g.DISPLAY), this.callPropCallback("onDisplay");
2892
+ this.rendered = !0, this.event.emit(g.RENDERED), w(this.propsPipeline.props, "onRendered"), this.event.emit(g.DISPLAY), w(this.propsPipeline.props, "onDisplay");
2945
2893
  }
2946
2894
  /**
2947
2895
  * Renders the component into a container in a different window.
@@ -2969,7 +2917,8 @@ class ge {
2969
2917
  if (!(this.destroyed || this.closing)) {
2970
2918
  this.closing = !0;
2971
2919
  try {
2972
- this.event.emit(g.CLOSE), this.callPropCallback("onClose"), await this.destroy();
2920
+ const e = this.propsPipeline ? this.propsPipeline.props : {};
2921
+ this.event.emit(g.CLOSE), w(e, "onClose"), await this.destroy();
2973
2922
  } finally {
2974
2923
  this.closing = !1;
2975
2924
  }
@@ -2982,7 +2931,8 @@ class ge {
2982
2931
  * For iframes, focuses the iframe element. For popups, brings the window to front.
2983
2932
  */
2984
2933
  async focus() {
2985
- this.renderer.focus(this.hostWindow), this.event.emit(g.FOCUS), this.callPropCallback("onFocus");
2934
+ const e = this.transport ? this.transport.hostWindow : null, n = this.propsPipeline ? this.propsPipeline.props : {};
2935
+ this.renderer.focus(e), this.event.emit(g.FOCUS), w(n, "onFocus");
2986
2936
  }
2987
2937
  /**
2988
2938
  * Resizes the component to the specified dimensions.
@@ -2990,7 +2940,12 @@ class ge {
2990
2940
  * @param dimensions - New width and height for the component
2991
2941
  */
2992
2942
  async resize(e) {
2993
- this.renderer.resize(e, this.hostWindow), this.event.emit(g.RESIZE, e), this.callPropCallback("onResize", e);
2943
+ const n = this.transport ? this.transport.hostWindow : null, s = this.propsPipeline ? this.propsPipeline.props : {};
2944
+ this.renderer.resize(e, n), this.event.emit(g.RESIZE, e), w(
2945
+ s,
2946
+ "onResize",
2947
+ e
2948
+ );
2994
2949
  }
2995
2950
  /**
2996
2951
  * Shows the component if hidden.
@@ -3032,9 +2987,15 @@ class ge {
3032
2987
  assertStableRenderedOrigin: (s) => this.assertStableRenderedOrigin(s),
3033
2988
  isRendered: () => this.rendered,
3034
2989
  syncTrustedDomainForUrl: (s) => this.syncTrustedDomainForUrl(s),
3035
- shouldSendPropsToHost: () => this.transport.isHostConnected(),
2990
+ shouldSendPropsToHost: () => this.transport ? this.transport.isHostConnected() : !1,
3036
2991
  sendPropsUpdateToHost: (s) => this.sendPropsUpdateToHost(s),
3037
- emitPropsUpdated: () => this.emitPropsUpdated()
2992
+ emitPropsUpdated: (s) => {
2993
+ this.event.emit(g.PROPS, s), w(
2994
+ s,
2995
+ "onProps",
2996
+ s
2997
+ );
2998
+ }
3038
2999
  };
3039
3000
  await this.propsPipeline.updateProps(e, n);
3040
3001
  }
@@ -3043,9 +3004,10 @@ class ge {
3043
3004
  * @internal
3044
3005
  */
3045
3006
  assertStableRenderedOrigin(e) {
3046
- if (this.rendered && this.openedHostDomain && e && e !== this.openedHostDomain)
3007
+ const n = this.transport?.openedHostDomain;
3008
+ if (this.rendered && n && e && e !== n)
3047
3009
  throw new Error(
3048
- `Cannot change component URL origin after render (from "${this.openedHostDomain}" to "${e}")`
3010
+ `Cannot change component URL origin after render (from "${n}" to "${e}")`
3049
3011
  );
3050
3012
  }
3051
3013
  /**
@@ -3053,14 +3015,7 @@ class ge {
3053
3015
  * @internal
3054
3016
  */
3055
3017
  async sendPropsUpdateToHost(e) {
3056
- await this.transport.sendPropsUpdateToHost(e, this.options.props);
3057
- }
3058
- /**
3059
- * Emits prop update lifecycle hooks.
3060
- * @internal
3061
- */
3062
- emitPropsUpdated() {
3063
- this.event.emit(g.PROPS, this.props), this.callPropCallback("onProps", this.props);
3018
+ this.transport && await this.transport.sendPropsUpdateToHost(e, this.options.props);
3064
3019
  }
3065
3020
  /**
3066
3021
  * Creates a clone of this instance with the same props.
@@ -3068,8 +3023,8 @@ class ge {
3068
3023
  * @returns A new unrendered component instance with identical configuration
3069
3024
  */
3070
3025
  clone() {
3071
- const e = new ge(this.options, this.props);
3072
- return e.inputProps = { ...this.inputProps }, e;
3026
+ const e = new _e(this.options, this.propsPipeline.props);
3027
+ return e.propsPipeline.inputProps = { ...this.propsPipeline.inputProps }, e;
3073
3028
  }
3074
3029
  /**
3075
3030
  * Checks if the component is eligible to render based on the eligible option.
@@ -3077,7 +3032,7 @@ class ge {
3077
3032
  * @returns True if eligible or no eligibility check defined
3078
3033
  */
3079
3034
  isEligible() {
3080
- return this.options.eligible ? this.options.eligible({ props: this.props }).eligible : !0;
3035
+ return this.options.eligible ? this.options.eligible({ props: this.propsPipeline.props }).eligible : !0;
3081
3036
  }
3082
3037
  /**
3083
3038
  * Normalizes component options with default values.
@@ -3087,7 +3042,7 @@ class ge {
3087
3042
  return {
3088
3043
  ...e,
3089
3044
  props: e.props ?? {},
3090
- defaultContext: e.defaultContext ?? p.IFRAME,
3045
+ defaultContext: e.defaultContext ?? f.IFRAME,
3091
3046
  dimensions: e.dimensions ?? { width: "100%", height: "100%" },
3092
3047
  timeout: e.timeout ?? 1e4,
3093
3048
  children: e.children
@@ -3097,7 +3052,7 @@ class ge {
3097
3052
  * Resolves the host URL from static or function options.
3098
3053
  * @internal
3099
3054
  */
3100
- resolveUrl(e = this.props) {
3055
+ resolveUrl(e = this.propsPipeline.props) {
3101
3056
  return typeof this.options.url == "function" ? this.options.url(e) : this.options.url;
3102
3057
  }
3103
3058
  /**
@@ -3105,7 +3060,7 @@ class ge {
3105
3060
  * @internal
3106
3061
  */
3107
3062
  resolveDimensions() {
3108
- return typeof this.options.dimensions == "function" ? this.options.dimensions(this.props) : this.options.dimensions;
3063
+ return typeof this.options.dimensions == "function" ? this.options.dimensions(this.propsPipeline.props) : this.options.dimensions;
3109
3064
  }
3110
3065
  /**
3111
3066
  * Resolves a URL to an origin, supporting relative URLs.
@@ -3123,7 +3078,7 @@ class ge {
3123
3078
  * @internal
3124
3079
  */
3125
3080
  isExplicitDomainTrust(e) {
3126
- return this.transport.isExplicitDomainTrust(e);
3081
+ return this.transport ? this.transport.isExplicitDomainTrust(e) : !1;
3127
3082
  }
3128
3083
  /**
3129
3084
  * Ensures the messenger trusts the origin for a resolved host URL.
@@ -3131,20 +3086,25 @@ class ge {
3131
3086
  */
3132
3087
  syncTrustedDomainForUrl(e) {
3133
3088
  const n = this.resolveUrlOrigin(e);
3134
- n && this.isExplicitDomainTrust(n), this.transport.syncTrustedDomainForUrl(e);
3089
+ n && this.isExplicitDomainTrust(n), this.transport && this.transport.syncTrustedDomainForUrl(e);
3135
3090
  }
3136
3091
  /**
3137
3092
  * Creates the prop context passed to prop callbacks and validators.
3138
3093
  * @internal
3139
3094
  */
3140
- createPropContext(e = this.props) {
3095
+ createPropContext(e) {
3096
+ const n = e ?? this.propsPipeline?.props ?? {};
3141
3097
  return {
3142
- props: e,
3098
+ props: n,
3143
3099
  state: this.state,
3144
3100
  close: () => this.close(),
3145
3101
  focus: () => this.focus(),
3146
- onError: (n) => this.handleError(n),
3147
- container: this.container,
3102
+ onError: (s) => L(
3103
+ this.event,
3104
+ this.propsPipeline?.props ?? n,
3105
+ s
3106
+ ),
3107
+ container: this.renderer.container,
3148
3108
  uid: this.uid,
3149
3109
  tag: this.options.tag
3150
3110
  };
@@ -3162,7 +3122,7 @@ class ge {
3162
3122
  */
3163
3123
  checkEligibility() {
3164
3124
  if (!this.options.eligible) return;
3165
- const e = this.options.eligible({ props: this.props });
3125
+ const e = this.options.eligible({ props: this.propsPipeline.props });
3166
3126
  if (!e.eligible)
3167
3127
  throw new Error(`Component not eligible: ${e.reason ?? "Unknown reason"}`);
3168
3128
  }
@@ -3190,7 +3150,7 @@ class ge {
3190
3150
  */
3191
3151
  async open() {
3192
3152
  const e = this.resolveUrl();
3193
- this.syncTrustedDomainForUrl(e), this.openedHostDomain = this.resolveUrlOrigin(e), this.hostWindow = this.renderer.open({
3153
+ this.syncTrustedDomainForUrl(e), this.transport.openedHostDomain = this.resolveUrlOrigin(e), this.transport.hostWindow = this.renderer.open({
3194
3154
  baseUrl: e,
3195
3155
  buildUrl: (n) => this.buildUrl(n),
3196
3156
  buildBodyParams: () => this.buildBodyParams(),
@@ -3202,14 +3162,14 @@ class ge {
3202
3162
  registerCleanup: (n) => {
3203
3163
  this.cleanup.register(n);
3204
3164
  }
3205
- }), this.hostWindow && ft(this.uid, this.hostWindow);
3165
+ }), this.transport.hostWindow && Yt(this.uid, this.transport.hostWindow);
3206
3166
  }
3207
3167
  /**
3208
3168
  * Builds the URL for the host window including query parameters.
3209
3169
  * @internal
3210
3170
  */
3211
3171
  buildUrl(e = this.resolveUrl()) {
3212
- const s = wt(this.props, this.options.props).toString();
3172
+ const s = Wt(this.propsPipeline.props, this.options.props).toString();
3213
3173
  if (!s) return e;
3214
3174
  const r = e.includes("?") ? "&" : "?";
3215
3175
  return `${e}${r}${s}`;
@@ -3219,7 +3179,7 @@ class ge {
3219
3179
  * @internal
3220
3180
  */
3221
3181
  buildBodyParams() {
3222
- return _t(this.props, this.options.props);
3182
+ return jt(this.propsPipeline.props, this.options.props);
3223
3183
  }
3224
3184
  /**
3225
3185
  * Submits a hidden form to navigate a target window via POST.
@@ -3235,39 +3195,14 @@ class ge {
3235
3195
  buildWindowName() {
3236
3196
  return this.transport.buildWindowName({
3237
3197
  tag: this.options.tag,
3238
- context: this.context,
3239
- props: this.props,
3198
+ context: this.renderer.context,
3199
+ props: this.propsPipeline.props,
3240
3200
  propDefinitions: this.options.props,
3241
3201
  hostDomain: this.getHostDomain(),
3242
- children: this.buildNestedHostRefs(),
3202
+ children: qt(this.options, this.propsPipeline.props),
3243
3203
  exports: this.createConsumerExports()
3244
3204
  });
3245
3205
  }
3246
- /**
3247
- * Builds component references for nested host components.
3248
- * @internal
3249
- */
3250
- buildNestedHostRefs() {
3251
- if (!this.options.children) return;
3252
- const e = this.options.children({ props: this.props }), n = {};
3253
- for (const [s, r] of Object.entries(e)) {
3254
- const i = Nn(r);
3255
- if (!i)
3256
- throw new Error(`Nested component "${s}" is missing component metadata`);
3257
- if (typeof i.url != "string")
3258
- throw new Error(
3259
- `Nested component "${s}" must use a static string URL. Function URLs are not supported in children.`
3260
- );
3261
- n[s] = {
3262
- tag: i.tag,
3263
- url: i.url,
3264
- props: i.props,
3265
- dimensions: typeof i.dimensions == "function" ? void 0 : i.dimensions,
3266
- defaultContext: i.defaultContext
3267
- };
3268
- }
3269
- return Object.keys(n).length > 0 ? n : void 0;
3270
- }
3271
3206
  /**
3272
3207
  * Creates the exports object sent to the host.
3273
3208
  * @internal
@@ -3299,7 +3234,11 @@ class ge {
3299
3234
  await this.transport.waitForHost(
3300
3235
  this.options.timeout,
3301
3236
  this.options.tag,
3302
- (e) => this.handleError(e)
3237
+ (e) => L(
3238
+ this.event,
3239
+ this.propsPipeline.props,
3240
+ e
3241
+ )
3303
3242
  );
3304
3243
  }
3305
3244
  /**
@@ -3314,14 +3253,18 @@ class ge {
3314
3253
  onFocus: async () => this.focus(),
3315
3254
  onShow: async () => this.show(),
3316
3255
  onHide: async () => this.hide(),
3317
- onError: (e) => this.handleError(e),
3256
+ onError: (e) => L(
3257
+ this.event,
3258
+ this.propsPipeline.props,
3259
+ e
3260
+ ),
3318
3261
  onExport: (e) => {
3319
3262
  this.exports = e;
3320
3263
  },
3321
3264
  onConsumerExport: (e) => {
3322
3265
  this.consumerExports = e;
3323
3266
  },
3324
- onGetSiblings: (e) => this.getSiblingInstances(e)
3267
+ onGetSiblings: (e) => wn(e)
3325
3268
  });
3326
3269
  }
3327
3270
  /**
@@ -3329,14 +3272,18 @@ class ge {
3329
3272
  * @internal
3330
3273
  */
3331
3274
  async syncSameDomainPropsAfterInit() {
3332
- if (!(!this.hostWindow || !this.transport.isHostConnected()) && Me(this.hostWindow) && this.hasSameDomainPropDefinition())
3275
+ if (!(!this.transport.hostWindow || !this.transport.isHostConnected()) && qe(this.transport.hostWindow) && this.hasSameDomainPropDefinition())
3333
3276
  try {
3334
3277
  await this.propsPipeline.syncCurrentPropsToHost({
3335
3278
  shouldSendPropsToHost: () => this.transport.isHostConnected(),
3336
3279
  sendPropsUpdateToHost: (e) => this.sendPropsUpdateToHost(e)
3337
3280
  });
3338
3281
  } catch (e) {
3339
- this.handleError(e);
3282
+ L(
3283
+ this.event,
3284
+ this.propsPipeline.props,
3285
+ e
3286
+ );
3340
3287
  }
3341
3288
  }
3342
3289
  /**
@@ -3344,30 +3291,7 @@ class ge {
3344
3291
  * @internal
3345
3292
  */
3346
3293
  hasSameDomainPropDefinition() {
3347
- return Object.values(this.options.props).some((e) => !e || D(e) ? !1 : e.sameDomain === !0);
3348
- }
3349
- /**
3350
- * Gets sibling component instances for a request.
3351
- * @internal
3352
- */
3353
- getSiblingInstances(e) {
3354
- const n = [];
3355
- if (e.options?.anyConsumer) {
3356
- for (const s of Hn())
3357
- s.instance.uid !== e.uid && n.push({
3358
- uid: s.instance.uid,
3359
- tag: s.tag,
3360
- exports: s.instance.exports
3361
- });
3362
- return n;
3363
- }
3364
- for (const s of Un(e.tag))
3365
- s.uid !== e.uid && n.push({
3366
- uid: s.uid,
3367
- tag: e.tag,
3368
- exports: s.exports
3369
- });
3370
- return n;
3294
+ return Object.values(this.options.props).some((e) => !e || x(e) ? !1 : e.sameDomain === !0);
3371
3295
  }
3372
3296
  /**
3373
3297
  * Registers cleanup handlers for the instance.
@@ -3375,165 +3299,188 @@ class ge {
3375
3299
  */
3376
3300
  setupCleanup() {
3377
3301
  this.cleanup.register(() => {
3378
- this.messenger.destroy(), this.bridge.destroy(), pt(this.uid);
3302
+ this.transport.destroy(), Jt(this.uid);
3379
3303
  });
3380
3304
  }
3381
- /**
3382
- * Handles errors by emitting events and calling callbacks.
3383
- * @internal
3384
- */
3385
- handleError(e) {
3386
- this.event.emit(g.ERROR, e), this.callPropCallback("onError", e);
3387
- }
3388
- /**
3389
- * Calls a prop callback if it exists.
3390
- * @internal
3391
- */
3392
- callPropCallback(e, ...n) {
3393
- const s = this.props[e];
3394
- if (typeof s == "function")
3395
- try {
3396
- const r = s(...n);
3397
- r && typeof r == "object" && "catch" in r && typeof r.catch == "function" && r.catch((i) => {
3398
- console.error(`Error in async ${e} callback:`, i);
3399
- });
3400
- } catch (r) {
3401
- console.error(`Error in ${e} callback:`, r);
3402
- }
3403
- }
3404
3305
  /**
3405
3306
  * Destroys the component and cleans up all resources.
3406
3307
  * @internal
3407
3308
  */
3408
3309
  async destroy() {
3409
- this.destroyed || (this.destroyed = !0, this.initPromise && (this.initPromise.reject(
3310
+ if (this.destroyed) return;
3311
+ this.destroyed = !0;
3312
+ const e = this.propsPipeline ? this.propsPipeline.props : {}, n = this.transport ? this.transport.hostWindow : null;
3313
+ this.transport && this.transport.initPromise && (this.transport.initPromise.reject(
3410
3314
  new Error(
3411
3315
  `Component "${this.options.tag}" was destroyed before initialization completed`
3412
3316
  )
3413
- ), this.initPromise = null), this.hostInitialized = !1, this.renderer.destroy(this.hostWindow), this.hostWindow = null, this.openedHostDomain = null, this.dynamicUrlTrustedOrigin = null, this.pendingPropsUpdate = null, await this.cleanup.cleanup(), this.event.emit(g.DESTROY), this.callPropCallback("onDestroy"), this.event.removeAllListeners());
3317
+ ), this.transport.initPromise = null), this.transport && (this.transport.hostInitialized = !1), this.renderer.destroy(n), this.transport && (this.transport.hostWindow = null, this.transport.openedHostDomain = null, this.transport.dynamicUrlTrustedOrigin = null), this.propsPipeline && (this.propsPipeline.pendingPropsUpdate = null), await this.cleanup.cleanup(), this.event.emit(g.DESTROY), w(e, "onDestroy"), this.event.removeAllListeners();
3414
3318
  }
3415
3319
  }
3416
- const H = /* @__PURE__ */ new Map(), N = /* @__PURE__ */ new Map();
3417
- function bn(t, e) {
3320
+ const U = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
3321
+ function Rn(t, e) {
3418
3322
  const n = e;
3419
- H.get(n.uid) && Xe(n.uid);
3420
- let r = N.get(t);
3421
- r || (r = /* @__PURE__ */ new Map(), N.set(t, r)), r.set(n.uid, n), H.set(n.uid, { tag: t, instance: n });
3323
+ U.get(n.uid) && Qe(n.uid);
3324
+ let r = F.get(t);
3325
+ r || (r = /* @__PURE__ */ new Map(), F.set(t, r)), r.set(n.uid, n), U.set(n.uid, { tag: t, instance: n });
3422
3326
  }
3423
- function Xe(t) {
3424
- const e = H.get(t);
3327
+ function Qe(t) {
3328
+ const e = U.get(t);
3425
3329
  if (!e)
3426
3330
  return;
3427
- H.delete(t);
3428
- const n = N.get(e.tag);
3429
- n && (n.delete(t), n.size === 0 && N.delete(e.tag));
3331
+ U.delete(t);
3332
+ const n = F.get(e.tag);
3333
+ n && (n.delete(t), n.size === 0 && F.delete(e.tag));
3430
3334
  }
3431
- function Cn(t) {
3432
- return Array.from(N.get(t)?.values() ?? []);
3335
+ function Dn(t) {
3336
+ return Array.from(F.get(t)?.values() ?? []);
3433
3337
  }
3434
- function On() {
3435
- return Array.from(H.values());
3338
+ function Sn() {
3339
+ return Array.from(U.values());
3436
3340
  }
3437
- const Ge = "Could not resolve consumer window", te = "Could not verify consumer origin", Rn = /* @__PURE__ */ new Set([
3438
- "uid",
3439
- "tag",
3440
- "close",
3441
- "focus",
3442
- "resize",
3443
- "show",
3444
- "hide",
3445
- "onProps",
3446
- "onError",
3447
- "getConsumer",
3448
- "getConsumerDomain",
3449
- "export",
3450
- "consumer",
3451
- "getPeerInstances",
3452
- "children"
3453
- ]);
3454
- function v(t) {
3455
- const e = {};
3456
- for (const [n, s] of Object.entries(t))
3457
- Rn.has(n) || (e[n] = s);
3458
- return e;
3341
+ function xn() {
3342
+ return le();
3459
3343
  }
3460
- class xn {
3461
- /**
3462
- * Creates a new HostComponent instance.
3463
- *
3464
- * @param payload - The payload parsed from window.name
3465
- * @param propDefinitions - Optional prop definitions for deserialization
3466
- * @param allowedConsumerDomains - Optional allowlist of consumer domains
3467
- * @param deferInit - Whether to defer INIT until a later explicit flush
3468
- */
3469
- constructor(e, n = {}, s, r = !1) {
3470
- this.propDefinitions = n, this.allowedConsumerDomains = s, this.deferInit = r, this.uid = e.uid, this.tag = e.tag, this.event = new Ae();
3471
- let i = null, o = null;
3344
+ function In() {
3345
+ return le();
3346
+ }
3347
+ function vn() {
3348
+ return window.hostProps;
3349
+ }
3350
+ const G = /* @__PURE__ */ new Map(), et = /* @__PURE__ */ Symbol("forgeframe.component.options");
3351
+ function Tn(t) {
3352
+ if (!t.tag)
3353
+ throw new Error("Component tag is required");
3354
+ if (!/^[a-z][a-z0-9-]*$/.test(t.tag))
3355
+ throw new Error(
3356
+ `Invalid component tag "${t.tag}". Must start with lowercase letter and contain only lowercase letters, numbers, and hyphens.`
3357
+ );
3358
+ if (!t.url)
3359
+ throw new Error("Component url is required");
3360
+ if (typeof t.url == "string")
3472
3361
  try {
3473
- this.consumerWindow = this.resolveConsumerWindow(), this.consumerDomain = this.resolveConsumerDomain(e.consumerDomain), o = new qe(this.uid, window, B(), this.consumerDomain), this.messenger = o, this.setupMessageHandlers(), i = new pe(this.messenger), this.bridge = i, this.hostProps = this.buildHostProps(e), this.exposeHostProps(), this.deferInit || this.flushInit();
3474
- } catch (a) {
3475
- throw i?.destroy(), o?.destroy(), this.event.removeAllListeners(), this.propsHandlers.clear(), a;
3362
+ const e = ce() ? window.location.origin : "https://forgeframe.invalid";
3363
+ new URL(t.url, e);
3364
+ } catch {
3365
+ throw new Error(
3366
+ `Invalid component URL "${t.url}". Must be a valid absolute or relative URL.`
3367
+ );
3476
3368
  }
3369
+ if (G.has(t.tag))
3370
+ throw new Error(`Component "${t.tag}" is already registered`);
3371
+ }
3372
+ function tt(t) {
3373
+ Tn(t);
3374
+ const e = [];
3375
+ let n;
3376
+ const s = () => ce() && pt(t.tag), r = () => {
3377
+ if (n)
3378
+ return n;
3379
+ if (!s())
3380
+ return;
3381
+ const a = Ee(t.props, t.allowedConsumerDomains);
3382
+ if (a)
3383
+ return n = a.hostProps, n;
3384
+ };
3385
+ r();
3386
+ const i = () => (r(), n !== void 0 || s()), o = function(a = {}) {
3387
+ const c = new _e(t, a);
3388
+ return c.destroyed || (e.push(c), Rn(t.tag, c), c.event.once("destroy", () => {
3389
+ const d = e.indexOf(c);
3390
+ d !== -1 && e.splice(d, 1), Qe(c.uid);
3391
+ })), c;
3392
+ };
3393
+ return o.instances = e, o.isHost = () => i(), o.isEmbedded = () => i(), Object.defineProperty(o, "hostProps", {
3394
+ configurable: !0,
3395
+ enumerable: !0,
3396
+ get: () => r()
3397
+ }), o[et] = t, o.canRenderTo = async (a) => a === window, G.set(t.tag, o), o;
3398
+ }
3399
+ function Hn(t) {
3400
+ return Dn(t);
3401
+ }
3402
+ function Un() {
3403
+ return Sn();
3404
+ }
3405
+ function Fn(t) {
3406
+ return t[et];
3407
+ }
3408
+ async function Nn(t) {
3409
+ await t.close();
3410
+ }
3411
+ async function nt(t) {
3412
+ const e = G.get(t);
3413
+ if (!e) return;
3414
+ const n = [...e.instances];
3415
+ await Promise.all(n.map((s) => s.close()));
3416
+ }
3417
+ async function An() {
3418
+ const t = Array.from(G.keys());
3419
+ await Promise.all(t.map((e) => nt(e)));
3420
+ }
3421
+ const $n = /* @__PURE__ */ new Set([
3422
+ "uid",
3423
+ "tag",
3424
+ "close",
3425
+ "focus",
3426
+ "resize",
3427
+ "show",
3428
+ "hide",
3429
+ "onProps",
3430
+ "onError",
3431
+ "getConsumer",
3432
+ "getConsumerDomain",
3433
+ "export",
3434
+ "consumer",
3435
+ "getPeerInstances",
3436
+ "children"
3437
+ ]);
3438
+ function T(t) {
3439
+ const e = {};
3440
+ for (const [n, s] of Object.entries(t))
3441
+ $n.has(n) || (e[n] = s);
3442
+ return e;
3443
+ }
3444
+ class Mn {
3445
+ constructor(e = {}, n) {
3446
+ this.propDefinitions = e, this.options = n;
3477
3447
  }
3478
- /** The hostProps object containing props and control methods passed from the consumer. */
3479
- hostProps;
3480
- /** Event emitter for lifecycle events. */
3481
- event;
3482
- /** @internal */
3483
- uid;
3484
- /** @internal */
3485
- tag;
3486
- /** @internal */
3487
- consumerWindow;
3488
- /** @internal */
3489
- consumerDomain;
3490
- /** @internal */
3491
- consumerDomainVerified = !1;
3492
- /** @internal */
3493
- messenger;
3494
- /** @internal */
3495
- bridge;
3496
- /** @internal */
3497
- propsHandlers = /* @__PURE__ */ new Set();
3498
- /** @internal */
3499
- consumerProps;
3500
- /** @internal */
3501
- initError = null;
3502
- /** @internal */
3503
- destroyed = !1;
3504
- /** @internal */
3505
- initSent = !1;
3506
- /** @internal */
3507
- deferredInitFlushScheduled = !1;
3508
- /**
3509
- * Ensures the INIT handshake is sent at most once.
3510
- * @internal
3511
- */
3512
- flushInit() {
3513
- this.destroyed || this.initSent || (this.initSent = !0, this.sendInit());
3514
- }
3515
- /**
3516
- * Schedules deferred INIT flush on the next microtask.
3517
- * This preserves legacy hostProps-only usage while giving same-tick
3518
- * host configuration a chance to run allowlist checks first.
3519
- * @internal
3520
- */
3521
- scheduleDeferredInitFlush() {
3522
- this.deferredInitFlushScheduled || this.destroyed || this.initSent || (this.deferredInitFlushScheduled = !0, queueMicrotask(() => {
3523
- this.deferredInitFlushScheduled = !1, this.flushInit();
3524
- }));
3448
+ hostProps;
3449
+ consumerProps;
3450
+ propsHandlers = /* @__PURE__ */ new Set();
3451
+ initializeHostProps(e) {
3452
+ const n = this.deserialize(e.props);
3453
+ H(n, this.getBootstrapValidationDefinitions()), this.consumerProps = n;
3454
+ const s = T(n);
3455
+ return this.hostProps = {
3456
+ ...s,
3457
+ uid: this.options.uid,
3458
+ tag: this.options.tag,
3459
+ close: () => this.options.controls.close(),
3460
+ focus: () => this.options.controls.focus(),
3461
+ resize: (r) => this.options.controls.resize(r),
3462
+ show: () => this.options.controls.show(),
3463
+ hide: () => this.options.controls.hide(),
3464
+ onProps: (r) => this.onProps(r),
3465
+ onError: (r) => this.options.controls.onError(r),
3466
+ getConsumer: () => this.options.getConsumerWindow(),
3467
+ getConsumerDomain: () => this.options.getConsumerDomain(),
3468
+ export: (r) => this.options.controls.exportData(r),
3469
+ consumer: {
3470
+ props: this.consumerProps,
3471
+ export: (r) => this.options.controls.consumerExport(r)
3472
+ },
3473
+ getPeerInstances: (r) => this.options.controls.getPeerInstances(r),
3474
+ children: this.buildNestedComponents(e.children)
3475
+ }, this.hostProps;
3525
3476
  }
3526
- /**
3527
- * Exposes hostProps on window and lazily flushes deferred init on first access.
3528
- * @internal
3529
- */
3530
3477
  exposeHostProps() {
3531
3478
  const e = window;
3532
3479
  try {
3533
3480
  Object.defineProperty(e, "hostProps", {
3534
3481
  configurable: !0,
3535
3482
  enumerable: !0,
3536
- get: () => (this.deferInit && !this.initSent && !this.destroyed && this.scheduleDeferredInitFlush(), this.hostProps),
3483
+ get: () => (this.options.onFirstHostPropsAccess(), this.hostProps),
3537
3484
  set: (n) => {
3538
3485
  n && (this.hostProps = n);
3539
3486
  }
@@ -3542,602 +3489,411 @@ class xn {
3542
3489
  e.hostProps = this.hostProps;
3543
3490
  }
3544
3491
  }
3545
- /**
3546
- * Validates that the consumer domain is allowed.
3547
- * @internal
3548
- */
3549
- validateConsumerDomain() {
3550
- if (this.allowedConsumerDomains) {
3551
- if (!this.consumerDomain)
3552
- throw new Error(
3553
- `${te} for component "${this.tag}"`
3554
- );
3555
- if (!U(this.allowedConsumerDomains, this.consumerDomain))
3556
- throw new Error(
3557
- `Consumer domain "${this.consumerDomain}" is not allowed for component "${this.tag}"`
3558
- );
3559
- }
3560
- }
3561
- /**
3562
- * Reads a browser-verifiable consumer origin when available.
3563
- * @internal
3564
- */
3565
- getVerifiedConsumerOrigin() {
3566
- return this.getReferrerOrigin() ?? this.getAccessibleConsumerOrigin();
3567
- }
3568
- /**
3569
- * Updates the tracked consumer origin and keeps trusted messaging origins in sync.
3570
- * @internal
3571
- */
3572
- setConsumerDomain(e, n) {
3573
- const s = this.consumerDomain;
3574
- this.consumerDomain = e, this.consumerDomainVerified = n, !(!this.messenger || !s || s === e) && (this.messenger.removeTrustedDomain(s), this.messenger.addTrustedDomain(e));
3575
- }
3576
- /**
3577
- * Applies host configuration that may arrive after deferred pre-initialization.
3578
- * @internal
3579
- */
3580
- applyHostConfiguration(e, n) {
3581
- n !== void 0 && (this.allowedConsumerDomains = n), e !== void 0 && (this.propDefinitions = e, T(this.consumerProps, this.getBootstrapValidationDefinitions()), Object.assign(this.hostProps, v(this.consumerProps)), this.hostProps.consumer.props = this.consumerProps);
3582
- }
3583
- /**
3584
- * Resolves the consumer origin from browser-provided context and falls back to the
3585
- * claimed bootstrap origin only when no explicit allowlist is configured.
3586
- * @internal
3587
- */
3588
- resolveConsumerDomain(e) {
3589
- const n = this.getVerifiedConsumerOrigin();
3590
- if (n)
3591
- return this.consumerDomainVerified = !0, this.consumerDomain = n, this.validateConsumerDomain(), n;
3592
- if (this.consumerDomainVerified = !1, this.allowedConsumerDomains)
3593
- throw new Error(
3594
- `${te} for component "${this.tag}"`
3595
- );
3596
- return e;
3597
- }
3598
- /**
3599
- * Rechecks allowlist constraints against a browser-verified consumer origin.
3600
- * @internal
3601
- */
3602
- assertAllowedConsumerDomain(e) {
3603
- const n = this.getVerifiedConsumerOrigin();
3604
- if (n && this.setConsumerDomain(n, !0), !this.consumerDomainVerified)
3605
- throw new Error(
3606
- `${te} for component "${this.tag}"`
3607
- );
3608
- if (!U(e, this.consumerDomain))
3609
- throw new Error(
3610
- `Consumer domain "${this.consumerDomain}" is not allowed for component "${this.tag}"`
3611
- );
3612
- }
3613
- /**
3614
- * Reads the consumer origin from the browser-provided referrer when available.
3615
- * @internal
3616
- */
3617
- getReferrerOrigin() {
3618
- if (!document.referrer)
3619
- return null;
3620
- try {
3621
- return new URL(document.referrer, window.location.href).origin;
3622
- } catch {
3623
- return null;
3624
- }
3492
+ applyHostConfiguration(e) {
3493
+ this.propDefinitions = e, H(this.consumerProps, this.getBootstrapValidationDefinitions()), Object.assign(this.hostProps, T(this.consumerProps)), this.hostProps.consumer.props = this.consumerProps;
3625
3494
  }
3626
- /**
3627
- * Reads the consumer origin directly when same-origin access is available.
3628
- * @internal
3629
- */
3630
- getAccessibleConsumerOrigin() {
3495
+ applySerializedProps(e) {
3631
3496
  try {
3632
- return this.consumerWindow.location.origin;
3633
- } catch {
3634
- return null;
3497
+ const n = this.consumerProps, s = this.deserialize(e);
3498
+ H(s, this.propDefinitions), this.removeStaleHostProps(n, s), this.consumerProps = s, Object.assign(this.hostProps, T(s)), this.hostProps.consumer.props = this.consumerProps;
3499
+ for (const r of this.propsHandlers)
3500
+ try {
3501
+ r(s);
3502
+ } catch (i) {
3503
+ console.error("Error in props handler:", i);
3504
+ }
3505
+ return this.options.event.emit(g.PROPS, s), { success: !0 };
3506
+ } catch (n) {
3507
+ const s = n instanceof Error ? n : new Error(String(n));
3508
+ throw console.error("Error deserializing props:", s), this.options.event.emit(g.ERROR, s), s;
3635
3509
  }
3636
3510
  }
3637
- /**
3638
- * Returns the hostProps object.
3639
- *
3640
- * @returns The hostProps object with props and control methods
3641
- */
3642
- getProps() {
3643
- return this.hostProps;
3511
+ destroy() {
3512
+ this.propsHandlers.clear();
3644
3513
  }
3645
- /**
3646
- * Resolves the consumer window reference (iframe parent or popup opener).
3647
- * @internal
3648
- */
3649
- resolveConsumerWindow() {
3650
- if (lt()) {
3651
- const e = ut();
3652
- if (e) return e;
3653
- }
3654
- if (ht()) {
3655
- const e = ct();
3656
- if (e) return e;
3657
- }
3658
- throw new Error(Ge);
3514
+ onProps(e) {
3515
+ return this.propsHandlers.add(e), {
3516
+ cancel: () => this.propsHandlers.delete(e)
3517
+ };
3659
3518
  }
3660
- /**
3661
- * Builds the hostProps object with deserialized props and control methods.
3662
- * @internal
3663
- */
3664
- buildHostProps(e) {
3665
- const n = Ue(
3666
- e.props,
3519
+ deserialize(e) {
3520
+ return Tt(
3521
+ e,
3667
3522
  this.propDefinitions,
3668
- this.messenger,
3669
- this.bridge,
3670
- this.consumerWindow,
3671
- this.consumerDomain
3523
+ this.options.getMessenger(),
3524
+ this.options.getBridge(),
3525
+ this.options.getConsumerWindow(),
3526
+ this.options.getConsumerDomain()
3672
3527
  );
3673
- return T(n, this.getBootstrapValidationDefinitions()), this.consumerProps = n, {
3674
- ...v(n),
3675
- uid: this.uid,
3676
- tag: this.tag,
3677
- close: () => this.close(),
3678
- focus: () => this.focus(),
3679
- resize: (r) => this.resize(r),
3680
- show: () => this.show(),
3681
- hide: () => this.hide(),
3682
- onProps: (r) => this.onProps(r),
3683
- onError: (r) => this.onError(r),
3684
- getConsumer: () => this.consumerWindow,
3685
- getConsumerDomain: () => this.consumerDomain,
3686
- export: (r) => this.exportData(r),
3687
- consumer: {
3688
- props: this.consumerProps,
3689
- export: (r) => this.consumerExport(r)
3690
- },
3691
- getPeerInstances: (r) => this.getPeerInstances(r),
3692
- children: this.buildNestedComponents(e.children)
3693
- };
3694
3528
  }
3695
- /**
3696
- * Relaxes required sameDomain props during bootstrap for verified same-origin hosts.
3697
- * Those props are synchronized after INIT through the live messaging channel.
3698
- * @internal
3699
- */
3700
3529
  getBootstrapValidationDefinitions() {
3701
- if (!this.consumerDomainVerified || this.consumerDomain !== B())
3530
+ if (!this.options.isConsumerDomainVerified() || this.options.getConsumerDomain() !== q())
3702
3531
  return this.propDefinitions;
3703
3532
  let e = !1;
3704
3533
  const n = {
3705
3534
  ...this.propDefinitions
3706
3535
  };
3707
3536
  for (const [s, r] of Object.entries(this.propDefinitions))
3708
- !r || D(r) || !r.sameDomain || (e = !0, n[s] = {
3537
+ !r || x(r) || !r.sameDomain || (e = !0, n[s] = {
3709
3538
  ...r,
3710
3539
  required: !1
3711
3540
  });
3712
3541
  return e ? n : this.propDefinitions;
3713
3542
  }
3714
- /**
3715
- * Sends initialization message to the consumer.
3716
- * @internal
3717
- */
3718
- async sendInit() {
3719
- try {
3720
- await this.messenger.send(
3721
- this.consumerWindow,
3722
- this.consumerDomain,
3723
- l.INIT,
3724
- { uid: this.uid, tag: this.tag }
3725
- );
3726
- } catch (e) {
3727
- const n = e instanceof Error ? e : new Error(String(e));
3728
- this.initError = n, this.event.emit(g.ERROR, {
3729
- type: "init_failed",
3730
- message: `Failed to initialize host component: ${n.message}`,
3731
- error: n
3732
- }), console.error("Failed to send init message:", e);
3733
- }
3543
+ buildNestedComponents(e) {
3544
+ if (!e)
3545
+ return;
3546
+ const n = {};
3547
+ for (const [s, r] of Object.entries(e))
3548
+ try {
3549
+ n[s] = tt({
3550
+ tag: r.tag,
3551
+ url: r.url,
3552
+ props: r.props,
3553
+ dimensions: r.dimensions,
3554
+ defaultContext: r.defaultContext
3555
+ });
3556
+ } catch (i) {
3557
+ console.warn(`Failed to create nested component "${s}":`, i);
3558
+ }
3559
+ return Object.keys(n).length > 0 ? n : void 0;
3560
+ }
3561
+ removeStaleHostProps(e, n) {
3562
+ const s = T(e), r = T(n);
3563
+ for (const i of Object.keys(s))
3564
+ i in r || delete this.hostProps[i];
3565
+ }
3566
+ }
3567
+ const st = "Could not resolve consumer window", Pe = "Could not verify consumer origin";
3568
+ function rt(t, e, n) {
3569
+ if (!e)
3570
+ throw new Error(
3571
+ `${Pe} for component "${n}"`
3572
+ );
3573
+ if (!X(t, e))
3574
+ throw new Error(
3575
+ `Consumer domain "${e}" is not allowed for component "${n}"`
3576
+ );
3577
+ }
3578
+ function zn(t = window) {
3579
+ if (Mt(t)) {
3580
+ const e = $t(t);
3581
+ if (e)
3582
+ return e;
3583
+ }
3584
+ if (zt(t)) {
3585
+ const e = At(t);
3586
+ if (e)
3587
+ return e;
3588
+ }
3589
+ throw new Error(st);
3590
+ }
3591
+ function Ln(t = document, e = window) {
3592
+ if (!t.referrer)
3593
+ return null;
3594
+ try {
3595
+ return new URL(t.referrer, e.location.href).origin;
3596
+ } catch {
3597
+ return null;
3598
+ }
3599
+ }
3600
+ function kn(t) {
3601
+ try {
3602
+ return t.location.origin;
3603
+ } catch {
3604
+ return null;
3605
+ }
3606
+ }
3607
+ function it(t, e = document, n = window) {
3608
+ return Ln(e, n) ?? kn(t);
3609
+ }
3610
+ function Wn(t) {
3611
+ const e = it(t.consumerWindow);
3612
+ if (e)
3613
+ return t.allowedConsumerDomains && rt(
3614
+ t.allowedConsumerDomains,
3615
+ e,
3616
+ t.tag
3617
+ ), {
3618
+ consumerDomain: e,
3619
+ consumerDomainVerified: !0
3620
+ };
3621
+ if (t.allowedConsumerDomains)
3622
+ throw new Error(
3623
+ `${Pe} for component "${t.tag}"`
3624
+ );
3625
+ return {
3626
+ consumerDomain: t.claimedConsumerDomain,
3627
+ consumerDomainVerified: !1
3628
+ };
3629
+ }
3630
+ function jn(t) {
3631
+ const e = it(t.consumerWindow);
3632
+ let n = t.consumerDomain, s = t.consumerDomainVerified;
3633
+ if (e && (e !== n && t.onConsumerDomainChange?.(n, e), n = e, s = !0), !s)
3634
+ throw new Error(
3635
+ `${Pe} for component "${t.tag}"`
3636
+ );
3637
+ return rt(
3638
+ t.allowedConsumerDomains,
3639
+ n,
3640
+ t.tag
3641
+ ), {
3642
+ consumerDomain: n,
3643
+ consumerDomainVerified: s
3644
+ };
3645
+ }
3646
+ class Bn {
3647
+ constructor(e) {
3648
+ this.options = e, this.messenger = new Ze(
3649
+ this.options.uid,
3650
+ window,
3651
+ q(),
3652
+ this.options.consumerDomain
3653
+ ), this.bridge = new de(this.messenger);
3654
+ }
3655
+ messenger;
3656
+ bridge;
3657
+ destroyed = !1;
3658
+ initSent = !1;
3659
+ initError = null;
3660
+ deferredInitFlushScheduled = !1;
3661
+ registerPropsHandler(e) {
3662
+ this.messenger.on(l.PROPS, (n, s) => e.isConsumerSource(s) ? e.applySerializedProps(n) : { success: !1 });
3663
+ }
3664
+ handleHostPropsAccess() {
3665
+ this.options.deferInit && !this.initSent && !this.destroyed && this.scheduleDeferredInitFlush();
3666
+ }
3667
+ flushInit() {
3668
+ this.destroyed || this.initSent || (this.initSent = !0, this.sendInit());
3734
3669
  }
3735
- /**
3736
- * Returns the initialization error if one occurred.
3737
- *
3738
- * @returns The initialization error or null if successful
3739
- */
3740
3670
  getInitError() {
3741
3671
  return this.initError;
3742
3672
  }
3743
- /**
3744
- * Requests the consumer to close this component.
3745
- * @internal
3746
- */
3673
+ updateTrustedConsumerDomain(e, n) {
3674
+ !e || e === n || (this.messenger.removeTrustedDomain(e), this.messenger.addTrustedDomain(n));
3675
+ }
3747
3676
  async close() {
3748
- await this.messenger.send(
3749
- this.consumerWindow,
3750
- this.consumerDomain,
3751
- l.CLOSE,
3752
- {}
3753
- );
3677
+ await this.sendMessage(l.CLOSE, {});
3754
3678
  }
3755
- /**
3756
- * Focuses this window and notifies the consumer.
3757
- * @internal
3758
- */
3759
3679
  async focus() {
3760
- window.focus(), await this.messenger.send(
3761
- this.consumerWindow,
3762
- this.consumerDomain,
3763
- l.FOCUS,
3764
- {}
3765
- );
3680
+ window.focus(), await this.sendMessage(l.FOCUS, {});
3766
3681
  }
3767
- /**
3768
- * Requests the consumer to resize this component.
3769
- * @internal
3770
- */
3771
3682
  async resize(e) {
3772
- await this.messenger.send(
3773
- this.consumerWindow,
3774
- this.consumerDomain,
3775
- l.RESIZE,
3776
- e
3777
- );
3778
- }
3779
- /**
3780
- * Requests the consumer to show this component.
3781
- * @internal
3782
- */
3783
- async show() {
3784
- await this.messenger.send(
3785
- this.consumerWindow,
3786
- this.consumerDomain,
3787
- l.SHOW,
3788
- {}
3789
- );
3790
- }
3791
- /**
3792
- * Requests the consumer to hide this component.
3793
- * @internal
3794
- */
3795
- async hide() {
3796
- await this.messenger.send(
3797
- this.consumerWindow,
3798
- this.consumerDomain,
3799
- l.HIDE,
3800
- {}
3801
- );
3683
+ await this.sendMessage(l.RESIZE, e);
3802
3684
  }
3803
- /**
3804
- * Subscribes to prop updates from the consumer.
3805
- * @internal
3806
- */
3807
- onProps(e) {
3808
- return this.propsHandlers.add(e), {
3809
- cancel: () => this.propsHandlers.delete(e)
3810
- };
3685
+ async show() {
3686
+ await this.sendMessage(l.SHOW, {});
3687
+ }
3688
+ async hide() {
3689
+ await this.sendMessage(l.HIDE, {});
3811
3690
  }
3812
- /**
3813
- * Reports an error to the consumer.
3814
- * @internal
3815
- */
3816
3691
  async onError(e) {
3817
- await this.messenger.send(
3818
- this.consumerWindow,
3819
- this.consumerDomain,
3820
- l.ERROR,
3821
- {
3822
- message: e.message,
3823
- stack: e.stack
3824
- }
3825
- );
3692
+ await this.sendMessage(l.ERROR, {
3693
+ message: e.message,
3694
+ stack: e.stack
3695
+ });
3826
3696
  }
3827
- /**
3828
- * Exports data or methods to the consumer.
3829
- * @internal
3830
- */
3831
3697
  async exportData(e) {
3832
- await this.messenger.send(
3833
- this.consumerWindow,
3834
- this.consumerDomain,
3835
- l.EXPORT,
3836
- e
3837
- );
3698
+ await this.sendMessage(l.EXPORT, e);
3838
3699
  }
3839
- /**
3840
- * Exports data to the consumer for bidirectional communication.
3841
- * @internal
3842
- */
3843
3700
  async consumerExport(e) {
3844
- await this.messenger.send(
3845
- this.consumerWindow,
3846
- this.consumerDomain,
3847
- l.CONSUMER_EXPORT,
3848
- e
3849
- );
3701
+ await this.sendMessage(l.CONSUMER_EXPORT, e);
3850
3702
  }
3851
- /**
3852
- * Gets information about peer component instances.
3853
- * @internal
3854
- */
3855
3703
  async getPeerInstances(e) {
3856
3704
  return await this.messenger.send(
3857
- this.consumerWindow,
3858
- this.consumerDomain,
3705
+ this.options.consumerWindow,
3706
+ this.options.getConsumerDomain(),
3859
3707
  l.GET_SIBLINGS,
3860
- { uid: this.uid, tag: this.tag, options: e }
3708
+ {
3709
+ uid: this.options.uid,
3710
+ tag: this.options.tag,
3711
+ options: e
3712
+ }
3861
3713
  ) ?? [];
3862
3714
  }
3863
- /**
3864
- * Builds nested component factories from refs passed by the consumer.
3865
- * @internal
3866
- */
3867
- buildNestedComponents(e) {
3868
- if (!e) return;
3869
- const n = {};
3870
- for (const [s, r] of Object.entries(e))
3871
- try {
3872
- n[s] = Qe({
3873
- tag: r.tag,
3874
- url: r.url,
3875
- props: r.props,
3876
- dimensions: r.dimensions,
3877
- defaultContext: r.defaultContext
3878
- });
3879
- } catch (i) {
3880
- console.warn(`Failed to create nested component "${s}":`, i);
3881
- }
3882
- return Object.keys(n).length > 0 ? n : void 0;
3715
+ destroy() {
3716
+ this.destroyed || (this.destroyed = !0, this.deferredInitFlushScheduled = !1, this.messenger.destroy(), this.bridge.destroy());
3883
3717
  }
3884
- /**
3885
- * Sets up message handlers for consumer communication.
3886
- * @internal
3887
- */
3888
- setupMessageHandlers() {
3889
- this.messenger.on(l.PROPS, (e, n) => {
3890
- if (!this.isConsumerSource(n))
3891
- return { success: !1 };
3892
- try {
3893
- const s = this.consumerProps, r = Ue(
3894
- e,
3895
- this.propDefinitions,
3896
- this.messenger,
3897
- this.bridge,
3898
- this.consumerWindow,
3899
- this.consumerDomain
3900
- );
3901
- T(r, this.propDefinitions), this.removeStaleHostProps(s, r), this.consumerProps = r, Object.assign(this.hostProps, v(r)), this.hostProps.consumer.props = this.consumerProps;
3902
- for (const i of this.propsHandlers)
3903
- try {
3904
- i(r);
3905
- } catch (o) {
3906
- console.error("Error in props handler:", o);
3907
- }
3908
- return this.event.emit(g.PROPS, r), { success: !0 };
3909
- } catch (s) {
3910
- const r = s instanceof Error ? s : new Error(String(s));
3911
- throw console.error("Error deserializing props:", r), this.event.emit(g.ERROR, r), r;
3912
- }
3913
- });
3718
+ scheduleDeferredInitFlush() {
3719
+ this.deferredInitFlushScheduled || this.destroyed || this.initSent || (this.deferredInitFlushScheduled = !0, queueMicrotask(() => {
3720
+ this.deferredInitFlushScheduled = !1, this.flushInit();
3721
+ }));
3914
3722
  }
3915
- /**
3916
- * Returns true when a stateful inbound message came from the resolved consumer window.
3917
- * @internal
3918
- */
3919
- isConsumerSource(e) {
3920
- return e.window === this.consumerWindow;
3723
+ async sendInit() {
3724
+ try {
3725
+ await this.sendMessage(l.INIT, {
3726
+ uid: this.options.uid,
3727
+ tag: this.options.tag
3728
+ });
3729
+ } catch (e) {
3730
+ const n = e instanceof Error ? e : new Error(String(e));
3731
+ this.initError = n, this.options.event.emit(g.ERROR, {
3732
+ type: "init_failed",
3733
+ message: `Failed to initialize host component: ${n.message}`,
3734
+ error: n
3735
+ }), console.error("Failed to send init message:", e);
3736
+ }
3921
3737
  }
3922
- /**
3923
- * Removes stale prop keys that are no longer present in the latest consumer payload.
3924
- * @internal
3925
- */
3926
- removeStaleHostProps(e, n) {
3927
- const s = v(e), r = v(n);
3928
- for (const i of Object.keys(s))
3929
- i in r || delete this.hostProps[i];
3738
+ async sendMessage(e, n) {
3739
+ await this.messenger.send(
3740
+ this.options.consumerWindow,
3741
+ this.options.getConsumerDomain(),
3742
+ e,
3743
+ n
3744
+ );
3745
+ }
3746
+ }
3747
+ class Vn {
3748
+ event;
3749
+ uid;
3750
+ tag;
3751
+ consumerWindow;
3752
+ consumerDomain;
3753
+ consumerDomainVerified = !1;
3754
+ allowedConsumerDomains;
3755
+ transport;
3756
+ propsRuntime;
3757
+ destroyed = !1;
3758
+ constructor(e, n = {}, s, r = !1) {
3759
+ this.uid = e.uid, this.tag = e.tag, this.event = new Le(), this.allowedConsumerDomains = s;
3760
+ let i = null, o = null;
3761
+ try {
3762
+ this.consumerWindow = zn();
3763
+ const a = Wn({
3764
+ consumerWindow: this.consumerWindow,
3765
+ claimedConsumerDomain: e.consumerDomain,
3766
+ allowedConsumerDomains: this.allowedConsumerDomains,
3767
+ tag: this.tag
3768
+ });
3769
+ this.consumerDomain = a.consumerDomain, this.consumerDomainVerified = a.consumerDomainVerified, i = new Bn({
3770
+ uid: this.uid,
3771
+ tag: this.tag,
3772
+ event: this.event,
3773
+ consumerWindow: this.consumerWindow,
3774
+ consumerDomain: this.consumerDomain,
3775
+ getConsumerDomain: () => this.consumerDomain,
3776
+ deferInit: r
3777
+ }), this.transport = i, o = new Mn(n, {
3778
+ uid: this.uid,
3779
+ tag: this.tag,
3780
+ event: this.event,
3781
+ controls: {
3782
+ close: () => this.transport.close(),
3783
+ focus: () => this.transport.focus(),
3784
+ resize: (c) => this.transport.resize(c),
3785
+ show: () => this.transport.show(),
3786
+ hide: () => this.transport.hide(),
3787
+ onError: (c) => this.transport.onError(c),
3788
+ exportData: (c) => this.transport.exportData(c),
3789
+ consumerExport: (c) => this.transport.consumerExport(c),
3790
+ getPeerInstances: (c) => this.transport.getPeerInstances(c)
3791
+ },
3792
+ getConsumerWindow: () => this.consumerWindow,
3793
+ getConsumerDomain: () => this.consumerDomain,
3794
+ isConsumerDomainVerified: () => this.consumerDomainVerified,
3795
+ getMessenger: () => this.transport.messenger,
3796
+ getBridge: () => this.transport.bridge,
3797
+ onFirstHostPropsAccess: () => this.transport.handleHostPropsAccess()
3798
+ }), this.propsRuntime = o, Object.defineProperties(this, {
3799
+ messenger: {
3800
+ configurable: !0,
3801
+ get: () => this.transport.messenger
3802
+ },
3803
+ bridge: {
3804
+ configurable: !0,
3805
+ get: () => this.transport.bridge
3806
+ },
3807
+ consumerProps: {
3808
+ configurable: !0,
3809
+ get: () => this.propsRuntime.consumerProps
3810
+ },
3811
+ propsHandlers: {
3812
+ configurable: !0,
3813
+ get: () => this.propsRuntime.propsHandlers
3814
+ }
3815
+ }), this.transport.registerPropsHandler({
3816
+ isConsumerSource: (c) => c.window === this.consumerWindow,
3817
+ applySerializedProps: (c) => this.propsRuntime.applySerializedProps(c)
3818
+ }), this.hostProps = this.propsRuntime.initializeHostProps(e), this.propsRuntime.exposeHostProps(), r || this.flushInit();
3819
+ } catch (a) {
3820
+ throw o?.destroy(), i?.destroy(), this.event.removeAllListeners(), a;
3821
+ }
3822
+ }
3823
+ get hostProps() {
3824
+ return this.propsRuntime.hostProps;
3825
+ }
3826
+ set hostProps(e) {
3827
+ this.propsRuntime.hostProps = e;
3828
+ }
3829
+ flushInit() {
3830
+ this.transport.flushInit();
3831
+ }
3832
+ getProps() {
3833
+ return this.hostProps;
3834
+ }
3835
+ getInitError() {
3836
+ return this.transport.getInitError();
3837
+ }
3838
+ applyHostConfiguration(e, n) {
3839
+ n !== void 0 && (this.allowedConsumerDomains = n), e !== void 0 && this.propsRuntime.applyHostConfiguration(e);
3840
+ }
3841
+ assertAllowedConsumerDomain(e) {
3842
+ const n = jn({
3843
+ consumerWindow: this.consumerWindow,
3844
+ consumerDomain: this.consumerDomain,
3845
+ consumerDomainVerified: this.consumerDomainVerified,
3846
+ allowedConsumerDomains: e,
3847
+ tag: this.tag,
3848
+ onConsumerDomainChange: (s, r) => {
3849
+ this.transport.updateTrustedConsumerDomain(s, r);
3850
+ }
3851
+ });
3852
+ this.consumerDomain = n.consumerDomain, this.consumerDomainVerified = n.consumerDomainVerified;
3930
3853
  }
3931
- /**
3932
- * Destroys the host component and cleans up resources.
3933
- */
3934
3854
  destroy() {
3935
- this.destroyed || (this.destroyed = !0, this.deferredInitFlushScheduled = !1, this.messenger.destroy(), this.bridge.destroy(), this.event.removeAllListeners(), this.propsHandlers.clear());
3855
+ this.destroyed || (this.destroyed = !0, this.transport.destroy(), this.event.removeAllListeners(), this.propsRuntime.destroy());
3936
3856
  }
3937
3857
  }
3938
- let w = null;
3939
- function ye(t, e, n = {}) {
3940
- if (w) {
3858
+ let _ = null;
3859
+ function Ee(t, e, n = {}) {
3860
+ if (_) {
3941
3861
  try {
3942
- w.applyHostConfiguration(
3862
+ _.applyHostConfiguration(
3943
3863
  t,
3944
3864
  e
3945
- ), e && w.assertAllowedConsumerDomain(e);
3865
+ ), e && _.assertAllowedConsumerDomain(e);
3946
3866
  } catch (r) {
3947
- throw vn(), r;
3867
+ throw Yn(), r;
3948
3868
  }
3949
- return n.deferInit || w.flushInit(), w;
3869
+ return n.deferInit || _.flushInit(), _;
3950
3870
  }
3951
- if (!me())
3871
+ if (!le())
3952
3872
  return null;
3953
- const s = Pn();
3873
+ const s = yt();
3954
3874
  if (!s)
3955
3875
  return console.error("Failed to parse ForgeFrame payload from window.name"), null;
3956
3876
  try {
3957
- w = new xn(
3877
+ _ = new Vn(
3958
3878
  s,
3959
3879
  t,
3960
3880
  e,
3961
3881
  n.deferInit ?? !1
3962
3882
  );
3963
3883
  } catch (r) {
3964
- if (r instanceof Error && r.message === Ge)
3884
+ if (r instanceof Error && r.message === st)
3965
3885
  return null;
3966
3886
  throw r;
3967
3887
  }
3968
- return w;
3969
- }
3970
- function Dn() {
3971
- return me();
3972
- }
3973
- function Sn() {
3974
- return me();
3975
- }
3976
- function In() {
3977
- return window.hostProps;
3888
+ return _;
3978
3889
  }
3979
- function vn() {
3980
- w && (w.destroy(), w = null), delete window.hostProps;
3981
- }
3982
- function we() {
3983
- return typeof window < "u" && typeof window.location < "u";
3984
- }
3985
- const K = /* @__PURE__ */ new Map(), Ze = /* @__PURE__ */ Symbol("forgeframe.component.options");
3986
- function Tn(t) {
3987
- if (!t.tag)
3988
- throw new Error("Component tag is required");
3989
- if (!/^[a-z][a-z0-9-]*$/.test(t.tag))
3990
- throw new Error(
3991
- `Invalid component tag "${t.tag}". Must start with lowercase letter and contain only lowercase letters, numbers, and hyphens.`
3992
- );
3993
- if (!t.url)
3994
- throw new Error("Component url is required");
3995
- if (typeof t.url == "string")
3996
- try {
3997
- const e = we() ? window.location.origin : "https://forgeframe.invalid";
3998
- new URL(t.url, e);
3999
- } catch {
4000
- throw new Error(
4001
- `Invalid component URL "${t.url}". Must be a valid absolute or relative URL.`
4002
- );
4003
- }
4004
- if (K.has(t.tag))
4005
- throw new Error(`Component "${t.tag}" is already registered`);
4006
- }
4007
- function Qe(t) {
4008
- Tn(t);
4009
- const e = [];
4010
- let n;
4011
- const s = () => we() && gn(t.tag), r = () => {
4012
- if (n)
4013
- return n;
4014
- if (!s())
4015
- return;
4016
- const a = ye(t.props, t.allowedConsumerDomains);
4017
- if (a)
4018
- return n = a.hostProps, n;
4019
- };
4020
- r();
4021
- const i = () => (r(), n !== void 0 || s()), o = function(a = {}) {
4022
- const c = new ge(t, a);
4023
- return e.push(c), bn(t.tag, c), c.event.once("destroy", () => {
4024
- const u = e.indexOf(c);
4025
- u !== -1 && e.splice(u, 1), Xe(c.uid);
4026
- }), c;
4027
- };
4028
- return o.instances = e, o.isHost = () => i(), o.isEmbedded = () => i(), Object.defineProperty(o, "hostProps", {
4029
- configurable: !0,
4030
- enumerable: !0,
4031
- get: () => r()
4032
- }), o[Ze] = t, o.canRenderTo = async (a) => a === window, K.set(t.tag, o), o;
4033
- }
4034
- function Un(t) {
4035
- return Cn(t);
4036
- }
4037
- function Hn() {
4038
- return On();
4039
- }
4040
- function Nn(t) {
4041
- return t[Ze];
4042
- }
4043
- async function Fn(t) {
4044
- await t.close();
4045
- }
4046
- async function et(t) {
4047
- const e = K.get(t);
4048
- if (!e) return;
4049
- const n = [...e.instances];
4050
- await Promise.all(n.map((s) => s.close()));
4051
- }
4052
- async function $n() {
4053
- const t = Array.from(K.keys());
4054
- await Promise.all(t.map((e) => et(e)));
4055
- }
4056
- function An(t, e) {
4057
- const n = Object.keys(t), s = Object.keys(e);
4058
- if (n.length !== s.length)
4059
- return !1;
4060
- for (const r of n)
4061
- if (!Object.prototype.hasOwnProperty.call(e, r) || !Object.is(t[r], e[r]))
4062
- return !1;
4063
- return !0;
4064
- }
4065
- function Ln(t, e) {
4066
- const { React: n } = e, { createElement: s, useRef: r, useEffect: i, useState: o, forwardRef: a } = n, c = a(
4067
- function(m, h) {
4068
- const {
4069
- onRendered: E,
4070
- onError: C,
4071
- onClose: X,
4072
- context: _e,
4073
- className: Pe,
4074
- style: Ee,
4075
- ...G
4076
- } = m, Z = r(null), S = r(null), $ = r(null), be = r(E), A = r(C), Ce = r(X), [Oe, Re] = o(null);
4077
- return i(() => {
4078
- be.current = E, A.current = C, Ce.current = X;
4079
- }, [E, C, X]), i(() => {
4080
- const _ = Z.current;
4081
- if (!_) return;
4082
- Re(null);
4083
- const y = t(G);
4084
- S.current = y, $.current = G;
4085
- const L = y.event.once("rendered", () => {
4086
- be.current?.();
4087
- }), xe = y.event.once("close", () => {
4088
- Ce.current?.();
4089
- }), Q = y.event.on("error", (M) => {
4090
- A.current?.(M);
4091
- });
4092
- return y.render(_, _e).catch((M) => {
4093
- S.current === y && (Re(M), A.current?.(M));
4094
- }), () => {
4095
- y.close().catch(() => {
4096
- }), L(), xe(), Q(), S.current = null, $.current = null;
4097
- };
4098
- }, [_e]), i(() => {
4099
- const _ = S.current;
4100
- if (!_) return;
4101
- const y = G, L = $.current;
4102
- L && An(L, y) || ($.current = y, _.updateProps(y).catch((Q) => {
4103
- S.current === _ && A.current?.(Q);
4104
- }));
4105
- }), i(() => {
4106
- const _ = Z.current;
4107
- if (typeof h == "function")
4108
- return h(_), () => {
4109
- h(null);
4110
- };
4111
- if (h && typeof h == "object")
4112
- return h.current = _, () => {
4113
- h.current = null;
4114
- };
4115
- }, [h]), Oe ? s(
4116
- "div",
4117
- {
4118
- className: Pe,
4119
- style: { color: "red", padding: "16px", ...Ee }
4120
- },
4121
- `Error: ${Oe.message}`
4122
- ) : s("div", {
4123
- ref: Z,
4124
- className: Pe,
4125
- style: {
4126
- display: "inline-block",
4127
- ...Ee
4128
- }
4129
- });
4130
- }
4131
- ), u = `ForgeFrame(${t.name || "Component"})`;
4132
- return c.displayName = u, c;
3890
+ function Yn() {
3891
+ _ && (_.destroy(), _ = null), delete window.hostProps;
4133
3892
  }
4134
- function Mn(t) {
4135
- return function(n) {
4136
- return Ln(n, { React: t });
4137
- };
3893
+ function Jn() {
3894
+ ce() && Ee(void 0, void 0, { deferInit: !0 });
4138
3895
  }
4139
- we() && ye(void 0, void 0, { deferInit: !0 });
4140
- const zn = {
3896
+ const Xn = {
4141
3897
  /**
4142
3898
  * Create a new component definition.
4143
3899
  *
@@ -4162,23 +3918,23 @@ const zn = {
4162
3918
  * await instance.render('#container');
4163
3919
  * ```
4164
3920
  */
4165
- create: Qe,
3921
+ create: tt,
4166
3922
  /**
4167
3923
  * Destroy a single component instance.
4168
3924
  *
4169
3925
  * @param instance - The component instance to destroy
4170
3926
  */
4171
- destroy: Fn,
3927
+ destroy: Nn,
4172
3928
  /**
4173
3929
  * Destroy all instances of a specific component by tag.
4174
3930
  *
4175
3931
  * @param tag - The component tag name
4176
3932
  */
4177
- destroyByTag: et,
3933
+ destroyByTag: nt,
4178
3934
  /**
4179
3935
  * Destroy all ForgeFrame component instances.
4180
3936
  */
4181
- destroyAll: $n,
3937
+ destroyAll: An,
4182
3938
  /**
4183
3939
  * Check if the current window is a host component context.
4184
3940
  *
@@ -4188,7 +3944,7 @@ const zn = {
4188
3944
  *
4189
3945
  * @returns True if running inside a ForgeFrame iframe/popup
4190
3946
  */
4191
- isHost: Dn,
3947
+ isHost: xn,
4192
3948
  /**
4193
3949
  * Check if the current window is embedded by ForgeFrame.
4194
3950
  *
@@ -4197,7 +3953,7 @@ const zn = {
4197
3953
  *
4198
3954
  * @returns True if running inside a ForgeFrame iframe/popup
4199
3955
  */
4200
- isEmbedded: Sn,
3956
+ isEmbedded: In,
4201
3957
  /**
4202
3958
  * Get hostProps from the current host window.
4203
3959
  *
@@ -4206,7 +3962,7 @@ const zn = {
4206
3962
  *
4207
3963
  * @returns The hostProps object if in host context, undefined otherwise
4208
3964
  */
4209
- getHostProps: In,
3965
+ getHostProps: vn,
4210
3966
  /**
4211
3967
  * Flush host initialization in embedded contexts.
4212
3968
  *
@@ -4217,17 +3973,17 @@ const zn = {
4217
3973
  *
4218
3974
  * @returns The host component instance if running embedded, otherwise null
4219
3975
  */
4220
- initHost: ye,
3976
+ initHost: Ee,
4221
3977
  /**
4222
3978
  * Serialization strategy constants.
4223
3979
  * @see {@link PROP_SERIALIZATION}
4224
3980
  */
4225
- PROP_SERIALIZATION: z,
3981
+ PROP_SERIALIZATION: k,
4226
3982
  /**
4227
3983
  * Rendering context constants (IFRAME, POPUP).
4228
3984
  * @see {@link CONTEXT}
4229
3985
  */
4230
- CONTEXT: p,
3986
+ CONTEXT: f,
4231
3987
  /**
4232
3988
  * Lifecycle event name constants.
4233
3989
  * @see {@link EVENT}
@@ -4236,11 +3992,11 @@ const zn = {
4236
3992
  /**
4237
3993
  * Error thrown when popup window fails to open.
4238
3994
  */
4239
- PopupOpenError: Je,
3995
+ PopupOpenError: Xe,
4240
3996
  /**
4241
3997
  * Current library version.
4242
3998
  */
4243
- VERSION: oe,
3999
+ VERSION: ue,
4244
4000
  /**
4245
4001
  * Check if a value is a Standard Schema (Zod, Valibot, ArkType, etc.)
4246
4002
  *
@@ -4257,7 +4013,7 @@ const zn = {
4257
4013
  * }
4258
4014
  * ```
4259
4015
  */
4260
- isStandardSchema: D,
4016
+ isStandardSchema: x,
4261
4017
  /**
4262
4018
  * Prop schema builders for defining component props.
4263
4019
  *
@@ -4280,36 +4036,120 @@ const zn = {
4280
4036
  * });
4281
4037
  * ```
4282
4038
  */
4283
- prop: f
4039
+ prop: p
4284
4040
  };
4041
+ function qn(t, e) {
4042
+ const n = Object.keys(t), s = Object.keys(e);
4043
+ if (n.length !== s.length)
4044
+ return !1;
4045
+ for (const r of n)
4046
+ if (!Object.prototype.hasOwnProperty.call(e, r) || !Object.is(t[r], e[r]))
4047
+ return !1;
4048
+ return !0;
4049
+ }
4050
+ function Kn(t, e) {
4051
+ const { React: n } = e, { createElement: s, useRef: r, useEffect: i, useState: o, forwardRef: a } = n, c = a(
4052
+ function(m, h) {
4053
+ const {
4054
+ onRendered: b,
4055
+ onError: O,
4056
+ onClose: Z,
4057
+ context: be,
4058
+ className: Ce,
4059
+ style: Oe,
4060
+ ...Q
4061
+ } = m, ee = r(null), I = r(null), A = r(null), Re = r(b), $ = r(O), De = r(Z), [Se, xe] = o(null);
4062
+ return i(() => {
4063
+ Re.current = b, $.current = O, De.current = Z;
4064
+ }, [b, O, Z]), i(() => {
4065
+ const P = ee.current;
4066
+ if (!P) return;
4067
+ xe(null);
4068
+ const y = t(Q);
4069
+ I.current = y, A.current = Q;
4070
+ const M = y.event.once("rendered", () => {
4071
+ Re.current?.();
4072
+ }), Ie = y.event.once("close", () => {
4073
+ De.current?.();
4074
+ }), te = y.event.on("error", (z) => {
4075
+ $.current?.(z);
4076
+ });
4077
+ return y.render(P, be).catch((z) => {
4078
+ I.current === y && (xe(z), $.current?.(z));
4079
+ }), () => {
4080
+ y.close().catch(() => {
4081
+ }), M(), Ie(), te(), I.current = null, A.current = null;
4082
+ };
4083
+ }, [be]), i(() => {
4084
+ const P = I.current;
4085
+ if (!P) return;
4086
+ const y = Q, M = A.current;
4087
+ M && qn(M, y) || (A.current = y, P.updateProps(y).catch((te) => {
4088
+ I.current === P && $.current?.(te);
4089
+ }));
4090
+ }), i(() => {
4091
+ const P = ee.current;
4092
+ if (typeof h == "function")
4093
+ return h(P), () => {
4094
+ h(null);
4095
+ };
4096
+ if (h && typeof h == "object")
4097
+ return h.current = P, () => {
4098
+ h.current = null;
4099
+ };
4100
+ }, [h]), Se ? s(
4101
+ "div",
4102
+ {
4103
+ className: Ce,
4104
+ style: { color: "red", padding: "16px", ...Oe }
4105
+ },
4106
+ `Error: ${Se.message}`
4107
+ ) : s("div", {
4108
+ ref: ee,
4109
+ className: Ce,
4110
+ style: {
4111
+ display: "inline-block",
4112
+ ...Oe
4113
+ }
4114
+ });
4115
+ }
4116
+ ), u = `ForgeFrame(${t.name || "Component"})`;
4117
+ return c.displayName = u, c;
4118
+ }
4119
+ function Gn(t) {
4120
+ return function(n) {
4121
+ return Kn(n, { React: t });
4122
+ };
4123
+ }
4124
+ Jn();
4285
4125
  export {
4286
- fe as AnySchema,
4126
+ we as AnySchema,
4287
4127
  V as ArraySchema,
4288
- ue as BooleanSchema,
4289
- p as CONTEXT,
4128
+ fe as BooleanSchema,
4129
+ f as CONTEXT,
4290
4130
  g as EVENT,
4291
- de as EnumSchema,
4292
- zn as ForgeFrame,
4293
- le as FunctionSchema,
4294
- he as LiteralSchema,
4295
- ce as NumberSchema,
4131
+ ye as EnumSchema,
4132
+ Xn as ForgeFrame,
4133
+ me as FunctionSchema,
4134
+ ge as LiteralSchema,
4135
+ pe as NumberSchema,
4296
4136
  Y as ObjectSchema,
4297
- z as PROP_SERIALIZATION,
4298
- Je as PopupOpenError,
4299
- P as PropSchema,
4300
- ae as StringSchema,
4301
- oe as VERSION,
4302
- Qe as create,
4303
- Ln as createReactComponent,
4304
- zn as default,
4305
- Fn as destroy,
4306
- $n as destroyAll,
4307
- et as destroyByTag,
4308
- In as getHostProps,
4309
- ye as initHost,
4310
- Sn as isEmbedded,
4311
- Dn as isHost,
4312
- D as isStandardSchema,
4313
- f as prop,
4314
- Mn as withReactComponent
4137
+ k as PROP_SERIALIZATION,
4138
+ Xe as PopupOpenError,
4139
+ E as PropSchema,
4140
+ he as StringSchema,
4141
+ ue as VERSION,
4142
+ tt as create,
4143
+ Kn as createReactComponent,
4144
+ Xn as default,
4145
+ Nn as destroy,
4146
+ An as destroyAll,
4147
+ nt as destroyByTag,
4148
+ vn as getHostProps,
4149
+ Ee as initHost,
4150
+ In as isEmbedded,
4151
+ xn as isHost,
4152
+ x as isStandardSchema,
4153
+ p as prop,
4154
+ Gn as withReactComponent
4315
4155
  };