@metapages/metapage 1.9.1 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +2 -3
  2. package/dist/index.d.ts +20 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +4525 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/metapage/Constants.d.ts +6 -0
  7. package/dist/metapage/Constants.d.ts.map +1 -0
  8. package/dist/metapage/Metaframe.d.ts +79 -0
  9. package/dist/metapage/Metaframe.d.ts.map +1 -0
  10. package/dist/metapage/Metapage.d.ts +105 -0
  11. package/dist/metapage/Metapage.d.ts.map +1 -0
  12. package/dist/metapage/MetapageIFrameRpcClient.d.ts +64 -0
  13. package/dist/metapage/MetapageIFrameRpcClient.d.ts.map +1 -0
  14. package/dist/metapage/MetapageTools.d.ts +21 -0
  15. package/dist/metapage/MetapageTools.d.ts.map +1 -0
  16. package/dist/metapage/Shared.d.ts +16 -0
  17. package/dist/metapage/Shared.d.ts.map +1 -0
  18. package/dist/metapage/conversions-metaframe.d.ts +15 -0
  19. package/dist/metapage/conversions-metaframe.d.ts.map +1 -0
  20. package/dist/metapage/conversions-metapage.d.ts +9 -0
  21. package/dist/metapage/conversions-metapage.d.ts.map +1 -0
  22. package/dist/metapage/core.d.ts +7 -0
  23. package/dist/metapage/core.d.ts.map +1 -0
  24. package/dist/metapage/data.d.ts +25 -0
  25. package/dist/metapage/data.d.ts.map +1 -0
  26. package/dist/metapage/errors/MissingMetaframeJson.d.ts +10 -0
  27. package/dist/metapage/errors/MissingMetaframeJson.d.ts.map +1 -0
  28. package/dist/metapage/errors/RootMetapageError.d.ts +10 -0
  29. package/dist/metapage/errors/RootMetapageError.d.ts.map +1 -0
  30. package/dist/metapage/events.d.ts +24 -0
  31. package/dist/metapage/events.d.ts.map +1 -0
  32. package/dist/metapage/jsonrpc.d.ts +35 -0
  33. package/dist/metapage/jsonrpc.d.ts.map +1 -0
  34. package/dist/metapage/jsonrpc2.d.ts +35 -0
  35. package/dist/metapage/jsonrpc2.d.ts.map +1 -0
  36. package/dist/metapage/metapageRenderer.d.ts +42 -0
  37. package/dist/metapage/metapageRenderer.d.ts.map +1 -0
  38. package/dist/metapage/metapageRendererExample.d.ts +13 -0
  39. package/dist/metapage/metapageRendererExample.d.ts.map +1 -0
  40. package/dist/metapage/util.d.ts +8 -0
  41. package/dist/metapage/util.d.ts.map +1 -0
  42. package/dist/metapage/v0_1_0/all.d.ts +110 -0
  43. package/dist/metapage/v0_1_0/all.d.ts.map +1 -0
  44. package/dist/metapage/v0_2/all.d.ts +68 -0
  45. package/dist/metapage/v0_2/all.d.ts.map +1 -0
  46. package/dist/metapage/v0_3/JsonRpcMethods.d.ts +42 -0
  47. package/dist/metapage/v0_3/JsonRpcMethods.d.ts.map +1 -0
  48. package/dist/metapage/v0_3/all.d.ts +11 -0
  49. package/dist/metapage/v0_3/all.d.ts.map +1 -0
  50. package/dist/metapage/v0_4/index.d.ts +3 -0
  51. package/dist/metapage/v0_4/index.d.ts.map +1 -0
  52. package/dist/metapage/v0_4/metaframe.d.ts +136 -0
  53. package/dist/metapage/v0_4/metaframe.d.ts.map +1 -0
  54. package/dist/metapage/v0_4/metapage.d.ts +34 -0
  55. package/dist/metapage/v0_4/metapage.d.ts.map +1 -0
  56. package/dist/metapage/v1/index.d.ts +3 -0
  57. package/dist/metapage/v1/index.d.ts.map +1 -0
  58. package/dist/metapage/v1/metaframe.d.ts +59 -0
  59. package/dist/metapage/v1/metaframe.d.ts.map +1 -0
  60. package/dist/metapage/v1/metapage.d.ts +26 -0
  61. package/dist/metapage/v1/metapage.d.ts.map +1 -0
  62. package/dist/metapage/v2/index.d.ts +3 -0
  63. package/dist/metapage/v2/index.d.ts.map +1 -0
  64. package/dist/metapage/v2/metaframe.d.ts +38 -0
  65. package/dist/metapage/v2/metaframe.d.ts.map +1 -0
  66. package/dist/metapage/v2/metapage.d.ts +22 -0
  67. package/dist/metapage/v2/metapage.d.ts.map +1 -0
  68. package/dist/metapage/versions.d.ts +7 -0
  69. package/dist/metapage/versions.d.ts.map +1 -0
  70. package/package.json +7 -2
  71. package/src/metapage/data.ts +251 -204
package/dist/index.js ADDED
@@ -0,0 +1,4525 @@
1
+ const pn = [
2
+ "0.3",
3
+ "0.4",
4
+ "0.5",
5
+ "0.6",
6
+ "1",
7
+ "2"
8
+ ], hn = ["0.2", "0.3", "1", "2"], ye = "2", Gt = "2", Vi = "metaframe.json", Gi = "metapage/definition", Ji = "metapage/state", Tn = hn[hn.length - 1], ys = pn[pn.length - 1], gs = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i, dn = (t) => {
9
+ if (typeof t != "string")
10
+ throw new TypeError("Invalid argument expected string");
11
+ const e = t.match(gs);
12
+ if (!e)
13
+ throw new Error(`Invalid argument not valid semver ('${t}' received)`);
14
+ return e.shift(), e;
15
+ }, mn = (t) => t === "*" || t === "x" || t === "X", yn = (t) => {
16
+ const e = parseInt(t, 10);
17
+ return isNaN(e) ? t : e;
18
+ }, bs = (t, e) => typeof t != typeof e ? [String(t), String(e)] : [t, e], _s = (t, e) => {
19
+ if (mn(t) || mn(e))
20
+ return 0;
21
+ const [n, s] = bs(yn(t), yn(e));
22
+ return n > s ? 1 : n < s ? -1 : 0;
23
+ }, gn = (t, e) => {
24
+ for (let n = 0; n < Math.max(t.length, e.length); n++) {
25
+ const s = _s(t[n] || "0", e[n] || "0");
26
+ if (s !== 0)
27
+ return s;
28
+ }
29
+ return 0;
30
+ }, F = (t, e) => {
31
+ const n = dn(t), s = dn(e), r = n.pop(), o = s.pop(), i = gn(n, s);
32
+ return i !== 0 ? i : r && o ? gn(r.split("."), o.split(".")) : r || o ? r ? -1 : 1 : 0;
33
+ };
34
+ var ws = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
35
+ function ze(t) {
36
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
37
+ }
38
+ var Dn = { exports: {} };
39
+ (function(t, e) {
40
+ (function(n, s) {
41
+ t.exports = s();
42
+ })(ws, function() {
43
+ var n = function(o, i) {
44
+ if (i = i || {}, typeof o != "function")
45
+ throw new r("fetch must be a function");
46
+ if (typeof i != "object")
47
+ throw new r("defaults must be an object");
48
+ if (i.retries !== void 0 && !s(i.retries))
49
+ throw new r("retries must be a positive integer");
50
+ if (i.retryDelay !== void 0 && !s(i.retryDelay) && typeof i.retryDelay != "function")
51
+ throw new r("retryDelay must be a positive integer or a function returning a positive integer");
52
+ if (i.retryOn !== void 0 && !Array.isArray(i.retryOn) && typeof i.retryOn != "function")
53
+ throw new r("retryOn property expects an array or function");
54
+ var a = {
55
+ retries: 3,
56
+ retryDelay: 1e3,
57
+ retryOn: []
58
+ };
59
+ return i = Object.assign(a, i), function(c, l) {
60
+ var f = i.retries, m = i.retryDelay, g = i.retryOn;
61
+ if (l && l.retries !== void 0)
62
+ if (s(l.retries))
63
+ f = l.retries;
64
+ else
65
+ throw new r("retries must be a positive integer");
66
+ if (l && l.retryDelay !== void 0)
67
+ if (s(l.retryDelay) || typeof l.retryDelay == "function")
68
+ m = l.retryDelay;
69
+ else
70
+ throw new r("retryDelay must be a positive integer or a function returning a positive integer");
71
+ if (l && l.retryOn)
72
+ if (Array.isArray(l.retryOn) || typeof l.retryOn == "function")
73
+ g = l.retryOn;
74
+ else
75
+ throw new r("retryOn property expects an array or function");
76
+ return new Promise(function(y, R) {
77
+ var O = function(w) {
78
+ var A = typeof Request < "u" && c instanceof Request ? c.clone() : c;
79
+ o(A, l).then(function(T) {
80
+ if (Array.isArray(g) && g.indexOf(T.status) === -1)
81
+ y(T);
82
+ else if (typeof g == "function")
83
+ try {
84
+ return Promise.resolve(g(w, null, T)).then(function(S) {
85
+ S ? E(w, null, T) : y(T);
86
+ }).catch(R);
87
+ } catch (S) {
88
+ R(S);
89
+ }
90
+ else
91
+ w < f ? E(w, null, T) : y(T);
92
+ }).catch(function(T) {
93
+ if (typeof g == "function")
94
+ try {
95
+ Promise.resolve(g(w, T, null)).then(function(S) {
96
+ S ? E(w, T, null) : R(T);
97
+ }).catch(function(S) {
98
+ R(S);
99
+ });
100
+ } catch (S) {
101
+ R(S);
102
+ }
103
+ else
104
+ w < f ? E(w, T, null) : R(T);
105
+ });
106
+ };
107
+ function E(w, A, T) {
108
+ var S = typeof m == "function" ? m(w, A, T) : m;
109
+ setTimeout(function() {
110
+ O(++w);
111
+ }, S);
112
+ }
113
+ O(0);
114
+ });
115
+ };
116
+ };
117
+ function s(o) {
118
+ return Number.isInteger(o) && o >= 0;
119
+ }
120
+ function r(o) {
121
+ this.name = "ArgumentError", this.message = o;
122
+ }
123
+ return n;
124
+ });
125
+ })(Dn);
126
+ var vs = Dn.exports;
127
+ const Fe = /* @__PURE__ */ ze(vs), J = {
128
+ Remove: "remove",
129
+ Replace: "replace",
130
+ Add: "add"
131
+ }, kn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), Os = Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"), ee = Symbol.iterator, nt = {
132
+ mutable: "mutable",
133
+ immutable: "immutable"
134
+ }, Ve = {};
135
+ function Ht(t, e) {
136
+ return t instanceof Map ? t.has(e) : Object.prototype.hasOwnProperty.call(t, e);
137
+ }
138
+ function bn(t, e) {
139
+ if (e in t) {
140
+ let n = Reflect.getPrototypeOf(t);
141
+ for (; n; ) {
142
+ const s = Reflect.getOwnPropertyDescriptor(n, e);
143
+ if (s)
144
+ return s;
145
+ n = Reflect.getPrototypeOf(n);
146
+ }
147
+ }
148
+ }
149
+ function Ge(t) {
150
+ return Object.getPrototypeOf(t) === Set.prototype;
151
+ }
152
+ function Je(t) {
153
+ return Object.getPrototypeOf(t) === Map.prototype;
154
+ }
155
+ function tt(t) {
156
+ var e;
157
+ return (e = t.copy) !== null && e !== void 0 ? e : t.original;
158
+ }
159
+ function St(t) {
160
+ return !!P(t);
161
+ }
162
+ function P(t) {
163
+ return typeof t != "object" ? null : t == null ? void 0 : t[kn];
164
+ }
165
+ function We(t) {
166
+ var e;
167
+ const n = P(t);
168
+ return n ? (e = n.copy) !== null && e !== void 0 ? e : n.original : t;
169
+ }
170
+ function ut(t, e) {
171
+ if (!t || typeof t != "object")
172
+ return !1;
173
+ let n;
174
+ return Object.getPrototypeOf(t) === Object.prototype || Array.isArray(t) || t instanceof Map || t instanceof Set || !!(e != null && e.mark) && ((n = e.mark(t, nt)) === nt.immutable || typeof n == "function");
175
+ }
176
+ function Ln(t, e = []) {
177
+ if (Object.hasOwnProperty.call(t, "key")) {
178
+ const n = t.parent.copy, s = P(bt(n, t.key));
179
+ if (s !== null && (s == null ? void 0 : s.original) !== t.original)
180
+ return null;
181
+ const r = t.parent.type === 3, o = r ? Array.from(t.parent.setMap.keys()).indexOf(t.key) : t.key;
182
+ if (!(r && n.size > o || Ht(n, o)))
183
+ return null;
184
+ e.push(o);
185
+ }
186
+ if (t.parent)
187
+ return Ln(t.parent, e);
188
+ e.reverse();
189
+ try {
190
+ Ss(t.copy, e);
191
+ } catch {
192
+ return null;
193
+ }
194
+ return e;
195
+ }
196
+ function $t(t) {
197
+ return Array.isArray(t) ? 1 : t instanceof Map ? 2 : t instanceof Set ? 3 : 0;
198
+ }
199
+ function bt(t, e) {
200
+ return $t(t) === 2 ? t.get(e) : t[e];
201
+ }
202
+ function Jt(t, e, n) {
203
+ $t(t) === 2 ? t.set(e, n) : t[e] = n;
204
+ }
205
+ function Se(t, e) {
206
+ const n = P(t);
207
+ return (n ? tt(n) : t)[e];
208
+ }
209
+ function gt(t, e) {
210
+ return t === e ? t !== 0 || 1 / t === 1 / e : t !== t && e !== e;
211
+ }
212
+ function xe(t) {
213
+ if (t)
214
+ for (; t.finalities.revoke.length > 0; )
215
+ t.finalities.revoke.pop()();
216
+ }
217
+ function Et(t, e) {
218
+ return e ? t : [""].concat(t).map((n) => {
219
+ const s = `${n}`;
220
+ return s.indexOf("/") === -1 && s.indexOf("~") === -1 ? s : s.replace(/~/g, "~0").replace(/\//g, "~1");
221
+ }).join("/");
222
+ }
223
+ function Ss(t, e) {
224
+ for (let n = 0; n < e.length - 1; n += 1) {
225
+ const s = e[n];
226
+ if (t = bt($t(t) === 3 ? Array.from(t) : t, s), typeof t != "object")
227
+ throw new Error(`Cannot resolve patch at '${e.join("/")}'.`);
228
+ }
229
+ return t;
230
+ }
231
+ function Rs(t) {
232
+ const e = Object.create(Object.getPrototypeOf(t));
233
+ return Reflect.ownKeys(t).forEach((n) => {
234
+ let s = Reflect.getOwnPropertyDescriptor(t, n);
235
+ if (s.enumerable && s.configurable && s.writable) {
236
+ e[n] = t[n];
237
+ return;
238
+ }
239
+ s.writable || (s.writable = !0, s.configurable = !0), (s.get || s.set) && (s = {
240
+ configurable: !0,
241
+ writable: !0,
242
+ enumerable: s.enumerable,
243
+ value: t[n]
244
+ }), Reflect.defineProperty(e, n, s);
245
+ }), e;
246
+ }
247
+ const As = Object.prototype.propertyIsEnumerable;
248
+ function jn(t, e) {
249
+ let n;
250
+ if (Array.isArray(t))
251
+ return Array.prototype.concat.call(t);
252
+ if (t instanceof Set) {
253
+ if (!Ge(t)) {
254
+ const s = Object.getPrototypeOf(t).constructor;
255
+ return new s(t.values());
256
+ }
257
+ return Set.prototype.difference ? Set.prototype.difference.call(t, /* @__PURE__ */ new Set()) : new Set(t.values());
258
+ } else if (t instanceof Map) {
259
+ if (!Je(t)) {
260
+ const s = Object.getPrototypeOf(t).constructor;
261
+ return new s(t);
262
+ }
263
+ return new Map(t);
264
+ } else if (e != null && e.mark && (n = e.mark(t, nt), n !== void 0) && n !== nt.mutable) {
265
+ if (n === nt.immutable)
266
+ return Rs(t);
267
+ if (typeof n == "function") {
268
+ if (e.enablePatches || e.enableAutoFreeze)
269
+ throw new Error("You can't use mark and patches or auto freeze together.");
270
+ return n();
271
+ }
272
+ throw new Error(`Unsupported mark result: ${n}`);
273
+ } else if (typeof t == "object" && Object.getPrototypeOf(t) === Object.prototype) {
274
+ const s = {};
275
+ return Object.keys(t).forEach((r) => {
276
+ s[r] = t[r];
277
+ }), Object.getOwnPropertySymbols(t).forEach((r) => {
278
+ As.call(t, r) && (s[r] = t[r]);
279
+ }), s;
280
+ } else
281
+ throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
282
+ }
283
+ function Q(t) {
284
+ t.copy || (t.copy = jn(t.original, t.options));
285
+ }
286
+ function kt(t) {
287
+ if (!ut(t))
288
+ return We(t);
289
+ if (Array.isArray(t))
290
+ return t.map(kt);
291
+ if (t instanceof Map) {
292
+ const n = Array.from(t.entries()).map(([s, r]) => [
293
+ s,
294
+ kt(r)
295
+ ]);
296
+ if (!Je(t)) {
297
+ const s = Object.getPrototypeOf(t).constructor;
298
+ return new s(n);
299
+ }
300
+ return new Map(n);
301
+ }
302
+ if (t instanceof Set) {
303
+ const n = Array.from(t).map(kt);
304
+ if (!Ge(t)) {
305
+ const s = Object.getPrototypeOf(t).constructor;
306
+ return new s(n);
307
+ }
308
+ return new Set(n);
309
+ }
310
+ const e = Object.create(Object.getPrototypeOf(t));
311
+ for (const n in t)
312
+ e[n] = kt(t[n]);
313
+ return e;
314
+ }
315
+ function ne(t) {
316
+ return St(t) ? kt(t) : t;
317
+ }
318
+ function ht(t) {
319
+ var e;
320
+ t.assignedMap = (e = t.assignedMap) !== null && e !== void 0 ? e : /* @__PURE__ */ new Map(), t.operated || (t.operated = !0, t.parent && ht(t.parent));
321
+ }
322
+ function _n() {
323
+ throw new Error("Cannot modify frozen object");
324
+ }
325
+ function Tt(t, e, n, s, r) {
326
+ {
327
+ n = n ?? /* @__PURE__ */ new WeakMap(), s = s ?? [], r = r ?? [];
328
+ const i = n.has(t) ? n.get(t) : t;
329
+ if (s.length > 0) {
330
+ const a = s.indexOf(i);
331
+ if (i && typeof i == "object" && a !== -1)
332
+ throw s[0] === i ? new Error("Forbids circular reference") : new Error(`Forbids circular reference: ~/${r.slice(0, a).map((u, c) => {
333
+ if (typeof u == "symbol")
334
+ return `[${u.toString()}]`;
335
+ const l = s[c];
336
+ return typeof u == "object" && (l instanceof Map || l instanceof Set) ? Array.from(l.keys()).indexOf(u) : u;
337
+ }).join("/")}`);
338
+ s.push(i), r.push(e);
339
+ } else
340
+ s.push(i);
341
+ }
342
+ if (Object.isFrozen(t) || St(t)) {
343
+ s.pop(), r.pop();
344
+ return;
345
+ }
346
+ switch ($t(t)) {
347
+ case 2:
348
+ for (const [a, u] of t)
349
+ Tt(a, a, n, s, r), Tt(u, a, n, s, r);
350
+ t.set = t.clear = t.delete = _n;
351
+ break;
352
+ case 3:
353
+ for (const a of t)
354
+ Tt(a, a, n, s, r);
355
+ t.add = t.clear = t.delete = _n;
356
+ break;
357
+ case 1:
358
+ Object.freeze(t);
359
+ let i = 0;
360
+ for (const a of t)
361
+ Tt(a, i, n, s, r), i += 1;
362
+ break;
363
+ default:
364
+ Object.freeze(t), Object.keys(t).forEach((a) => {
365
+ const u = t[a];
366
+ Tt(u, a, n, s, r);
367
+ });
368
+ }
369
+ s.pop(), r.pop();
370
+ }
371
+ function Ke(t, e) {
372
+ const n = $t(t);
373
+ if (n === 0)
374
+ Reflect.ownKeys(t).forEach((s) => {
375
+ e(s, t[s], t);
376
+ });
377
+ else if (n === 1) {
378
+ let s = 0;
379
+ for (const r of t)
380
+ e(s, r, t), s += 1;
381
+ } else
382
+ t.forEach((s, r) => e(r, s, t));
383
+ }
384
+ function Nn(t, e, n) {
385
+ if (St(t) || !ut(t, n) || e.has(t) || Object.isFrozen(t))
386
+ return;
387
+ const s = t instanceof Set, r = s ? /* @__PURE__ */ new Map() : void 0;
388
+ if (e.add(t), Ke(t, (o, i) => {
389
+ var a;
390
+ if (St(i)) {
391
+ const u = P(i);
392
+ Q(u);
393
+ const c = !((a = u.assignedMap) === null || a === void 0) && a.size || u.operated ? u.copy : u.original;
394
+ Jt(s ? r : t, o, c);
395
+ } else
396
+ Nn(i, e, n);
397
+ }), r) {
398
+ const o = t, i = Array.from(o);
399
+ o.clear(), i.forEach((a) => {
400
+ o.add(r.has(a) ? r.get(a) : a);
401
+ });
402
+ }
403
+ }
404
+ function Ms(t, e) {
405
+ const n = t.type === 3 ? t.setMap : t.copy;
406
+ t.finalities.revoke.length > 1 && t.assignedMap.get(e) && n && Nn(bt(n, e), t.finalities.handledSet, t.options);
407
+ }
408
+ function Pe(t) {
409
+ t.type === 3 && t.copy && (t.copy.clear(), t.setMap.forEach((e) => {
410
+ t.copy.add(We(e));
411
+ }));
412
+ }
413
+ function Te(t, e, n, s) {
414
+ if (t.operated && t.assignedMap && t.assignedMap.size > 0 && !t.finalized) {
415
+ if (n && s) {
416
+ const o = Ln(t);
417
+ o && e(t, o, n, s);
418
+ }
419
+ t.finalized = !0;
420
+ }
421
+ }
422
+ function Xe(t, e, n, s) {
423
+ const r = P(n);
424
+ r && (r.callbacks || (r.callbacks = []), r.callbacks.push((o, i) => {
425
+ var a;
426
+ const u = t.type === 3 ? t.setMap : t.copy;
427
+ if (gt(bt(u, e), n)) {
428
+ let c = r.original;
429
+ r.copy && (c = r.copy), Pe(t), Te(t, s, o, i), t.options.enableAutoFreeze && (t.options.updatedValues = (a = t.options.updatedValues) !== null && a !== void 0 ? a : /* @__PURE__ */ new WeakMap(), t.options.updatedValues.set(c, r.original)), Jt(u, e, c);
430
+ }
431
+ }), t.options.enableAutoFreeze && r.finalities !== t.finalities && (t.options.enableAutoFreeze = !1)), ut(n, t.options) && t.finalities.draft.push(() => {
432
+ const o = t.type === 3 ? t.setMap : t.copy;
433
+ gt(bt(o, e), n) && Ms(t, e);
434
+ });
435
+ }
436
+ function Es(t, e, n, s, r) {
437
+ let { original: o, assignedMap: i, options: a } = t, u = t.copy;
438
+ u.length < o.length && ([o, u] = [u, o], [n, s] = [s, n]);
439
+ for (let c = 0; c < o.length; c += 1)
440
+ if (i.get(c.toString()) && u[c] !== o[c]) {
441
+ const l = e.concat([c]), f = Et(l, r);
442
+ n.push({
443
+ op: J.Replace,
444
+ path: f,
445
+ // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
446
+ value: ne(u[c])
447
+ }), s.push({
448
+ op: J.Replace,
449
+ path: f,
450
+ // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
451
+ value: ne(o[c])
452
+ });
453
+ }
454
+ for (let c = o.length; c < u.length; c += 1) {
455
+ const l = e.concat([c]), f = Et(l, r);
456
+ n.push({
457
+ op: J.Add,
458
+ path: f,
459
+ // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
460
+ value: ne(u[c])
461
+ });
462
+ }
463
+ if (o.length < u.length) {
464
+ const { arrayLengthAssignment: c = !0 } = a.enablePatches;
465
+ if (c) {
466
+ const l = e.concat(["length"]), f = Et(l, r);
467
+ s.push({
468
+ op: J.Replace,
469
+ path: f,
470
+ value: o.length
471
+ });
472
+ } else
473
+ for (let l = u.length; o.length < l; l -= 1) {
474
+ const f = e.concat([l - 1]), m = Et(f, r);
475
+ s.push({
476
+ op: J.Remove,
477
+ path: m
478
+ });
479
+ }
480
+ }
481
+ }
482
+ function Is({ original: t, copy: e, assignedMap: n }, s, r, o, i) {
483
+ n.forEach((a, u) => {
484
+ const c = bt(t, u), l = ne(bt(e, u)), f = a ? Ht(t, u) ? J.Replace : J.Add : J.Remove;
485
+ if (gt(c, l) && f === J.Replace)
486
+ return;
487
+ const m = s.concat(u), g = Et(m, i);
488
+ r.push(f === J.Remove ? { op: f, path: g } : { op: f, path: g, value: l }), o.push(f === J.Add ? { op: J.Remove, path: g } : f === J.Remove ? { op: J.Add, path: g, value: c } : { op: J.Replace, path: g, value: c });
489
+ });
490
+ }
491
+ function Cs({ original: t, copy: e }, n, s, r, o) {
492
+ let i = 0;
493
+ t.forEach((a) => {
494
+ if (!e.has(a)) {
495
+ const u = n.concat([i]), c = Et(u, o);
496
+ s.push({
497
+ op: J.Remove,
498
+ path: c,
499
+ value: a
500
+ }), r.unshift({
501
+ op: J.Add,
502
+ path: c,
503
+ value: a
504
+ });
505
+ }
506
+ i += 1;
507
+ }), i = 0, e.forEach((a) => {
508
+ if (!t.has(a)) {
509
+ const u = n.concat([i]), c = Et(u, o);
510
+ s.push({
511
+ op: J.Add,
512
+ path: c,
513
+ value: a
514
+ }), r.unshift({
515
+ op: J.Remove,
516
+ path: c,
517
+ value: a
518
+ });
519
+ }
520
+ i += 1;
521
+ });
522
+ }
523
+ function zt(t, e, n, s) {
524
+ const { pathAsArray: r = !0 } = t.options.enablePatches;
525
+ switch (t.type) {
526
+ case 0:
527
+ case 2:
528
+ return Is(t, e, n, s, r);
529
+ case 1:
530
+ return Es(t, e, n, s, r);
531
+ case 3:
532
+ return Cs(t, e, n, s, r);
533
+ }
534
+ }
535
+ let $s = !1;
536
+ const oe = (t, e, n = !1) => {
537
+ if (typeof t == "object" && t !== null && (!ut(t, e) || n) && !$s)
538
+ throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
539
+ }, De = {
540
+ get size() {
541
+ return tt(P(this)).size;
542
+ },
543
+ has(t) {
544
+ return tt(P(this)).has(t);
545
+ },
546
+ set(t, e) {
547
+ const n = P(this), s = tt(n);
548
+ return (!s.has(t) || !gt(s.get(t), e)) && (Q(n), ht(n), n.assignedMap.set(t, !0), n.copy.set(t, e), Xe(n, t, e, zt)), this;
549
+ },
550
+ delete(t) {
551
+ if (!this.has(t))
552
+ return !1;
553
+ const e = P(this);
554
+ return Q(e), ht(e), e.original.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.copy.delete(t), !0;
555
+ },
556
+ clear() {
557
+ const t = P(this);
558
+ if (this.size) {
559
+ Q(t), ht(t), t.assignedMap = /* @__PURE__ */ new Map();
560
+ for (const [e] of t.original)
561
+ t.assignedMap.set(e, !1);
562
+ t.copy.clear();
563
+ }
564
+ },
565
+ forEach(t, e) {
566
+ const n = P(this);
567
+ tt(n).forEach((s, r) => {
568
+ t.call(e, this.get(r), r, this);
569
+ });
570
+ },
571
+ get(t) {
572
+ var e, n;
573
+ const s = P(this), r = tt(s).get(t), o = ((n = (e = s.options).mark) === null || n === void 0 ? void 0 : n.call(e, r, nt)) === nt.mutable;
574
+ if (s.options.strict && oe(r, s.options, o), o || s.finalized || !ut(r, s.options) || r !== s.original.get(t))
575
+ return r;
576
+ const i = Ve.createDraft({
577
+ original: r,
578
+ parentDraft: s,
579
+ key: t,
580
+ finalities: s.finalities,
581
+ options: s.options
582
+ });
583
+ return Q(s), s.copy.set(t, i), i;
584
+ },
585
+ keys() {
586
+ return tt(P(this)).keys();
587
+ },
588
+ values() {
589
+ const t = this.keys();
590
+ return {
591
+ [ee]: () => this.values(),
592
+ next: () => {
593
+ const e = t.next();
594
+ return e.done ? e : {
595
+ done: !1,
596
+ value: this.get(e.value)
597
+ };
598
+ }
599
+ };
600
+ },
601
+ entries() {
602
+ const t = this.keys();
603
+ return {
604
+ [ee]: () => this.entries(),
605
+ next: () => {
606
+ const e = t.next();
607
+ if (e.done)
608
+ return e;
609
+ const n = this.get(e.value);
610
+ return {
611
+ done: !1,
612
+ value: [e.value, n]
613
+ };
614
+ }
615
+ };
616
+ },
617
+ [ee]() {
618
+ return this.entries();
619
+ }
620
+ }, xs = Reflect.ownKeys(De), wn = (t, e, { isValuesIterator: n }) => () => {
621
+ var s, r;
622
+ const o = e.next();
623
+ if (o.done)
624
+ return o;
625
+ const i = o.value;
626
+ let a = t.setMap.get(i);
627
+ const u = P(a), c = ((r = (s = t.options).mark) === null || r === void 0 ? void 0 : r.call(s, a, nt)) === nt.mutable;
628
+ if (t.options.strict && oe(i, t.options, c), !c && !u && ut(i, t.options) && !t.finalized && t.original.has(i)) {
629
+ const l = Ve.createDraft({
630
+ original: i,
631
+ parentDraft: t,
632
+ key: i,
633
+ finalities: t.finalities,
634
+ options: t.options
635
+ });
636
+ t.setMap.set(i, l), a = l;
637
+ } else
638
+ u && (a = u.proxy);
639
+ return {
640
+ done: !1,
641
+ value: n ? a : [a, a]
642
+ };
643
+ }, ae = {
644
+ get size() {
645
+ return P(this).setMap.size;
646
+ },
647
+ has(t) {
648
+ const e = P(this);
649
+ if (e.setMap.has(t))
650
+ return !0;
651
+ Q(e);
652
+ const n = P(t);
653
+ return !!(n && e.setMap.has(n.original));
654
+ },
655
+ add(t) {
656
+ const e = P(this);
657
+ return this.has(t) || (Q(e), ht(e), e.assignedMap.set(t, !0), e.setMap.set(t, t), Xe(e, t, t, zt)), this;
658
+ },
659
+ delete(t) {
660
+ if (!this.has(t))
661
+ return !1;
662
+ const e = P(this);
663
+ Q(e), ht(e);
664
+ const n = P(t);
665
+ return n && e.setMap.has(n.original) ? (e.assignedMap.set(n.original, !1), e.setMap.delete(n.original)) : (!n && e.setMap.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.setMap.delete(t));
666
+ },
667
+ clear() {
668
+ if (!this.size)
669
+ return;
670
+ const t = P(this);
671
+ Q(t), ht(t);
672
+ for (const e of t.original)
673
+ t.assignedMap.set(e, !1);
674
+ t.setMap.clear();
675
+ },
676
+ values() {
677
+ const t = P(this);
678
+ Q(t);
679
+ const e = t.setMap.keys();
680
+ return {
681
+ [Symbol.iterator]: () => this.values(),
682
+ next: wn(t, e, { isValuesIterator: !0 })
683
+ };
684
+ },
685
+ entries() {
686
+ const t = P(this);
687
+ Q(t);
688
+ const e = t.setMap.keys();
689
+ return {
690
+ [Symbol.iterator]: () => this.entries(),
691
+ next: wn(t, e, {
692
+ isValuesIterator: !1
693
+ })
694
+ };
695
+ },
696
+ keys() {
697
+ return this.values();
698
+ },
699
+ [ee]() {
700
+ return this.values();
701
+ },
702
+ forEach(t, e) {
703
+ const n = this.values();
704
+ let s = n.next();
705
+ for (; !s.done; )
706
+ t.call(e, s.value, s.value, this), s = n.next();
707
+ }
708
+ };
709
+ Set.prototype.difference && Object.assign(ae, {
710
+ intersection(t) {
711
+ return Set.prototype.intersection.call(new Set(this.values()), t);
712
+ },
713
+ union(t) {
714
+ return Set.prototype.union.call(new Set(this.values()), t);
715
+ },
716
+ difference(t) {
717
+ return Set.prototype.difference.call(new Set(this.values()), t);
718
+ },
719
+ symmetricDifference(t) {
720
+ return Set.prototype.symmetricDifference.call(new Set(this.values()), t);
721
+ },
722
+ isSubsetOf(t) {
723
+ return Set.prototype.isSubsetOf.call(new Set(this.values()), t);
724
+ },
725
+ isSupersetOf(t) {
726
+ return Set.prototype.isSupersetOf.call(new Set(this.values()), t);
727
+ },
728
+ isDisjointFrom(t) {
729
+ return Set.prototype.isDisjointFrom.call(new Set(this.values()), t);
730
+ }
731
+ });
732
+ const Ps = Reflect.ownKeys(ae), Hn = {
733
+ get(t, e, n) {
734
+ var s, r;
735
+ const o = (s = t.copy) === null || s === void 0 ? void 0 : s[e];
736
+ if (o && t.finalities.draftsCache.has(o))
737
+ return o;
738
+ if (e === kn)
739
+ return t;
740
+ let i;
741
+ if (t.options.mark) {
742
+ const c = e === "size" && (t.original instanceof Map || t.original instanceof Set) ? Reflect.get(t.original, e) : Reflect.get(t.original, e, n);
743
+ if (i = t.options.mark(c, nt), i === nt.mutable)
744
+ return t.options.strict && oe(c, t.options, !0), c;
745
+ }
746
+ const a = tt(t);
747
+ if (a instanceof Map && xs.includes(e))
748
+ return e === "size" ? Object.getOwnPropertyDescriptor(De, "size").get.call(t.proxy) : De[e].bind(t.proxy);
749
+ if (a instanceof Set && Ps.includes(e))
750
+ return e === "size" ? Object.getOwnPropertyDescriptor(ae, "size").get.call(t.proxy) : ae[e].bind(t.proxy);
751
+ if (!Ht(a, e)) {
752
+ const c = bn(a, e);
753
+ return c ? "value" in c ? c.value : (
754
+ // !case: support for getter
755
+ (r = c.get) === null || r === void 0 ? void 0 : r.call(t.proxy)
756
+ ) : void 0;
757
+ }
758
+ const u = a[e];
759
+ if (t.options.strict && oe(u, t.options), t.finalized || !ut(u, t.options))
760
+ return u;
761
+ if (u === Se(t.original, e)) {
762
+ if (Q(t), t.copy[e] = Ye({
763
+ original: t.original[e],
764
+ parentDraft: t,
765
+ key: t.type === 1 ? Number(e) : e,
766
+ finalities: t.finalities,
767
+ options: t.options
768
+ }), typeof i == "function") {
769
+ const c = P(t.copy[e]);
770
+ return Q(c), ht(c), c.copy;
771
+ }
772
+ return t.copy[e];
773
+ }
774
+ return St(u) && t.finalities.draftsCache.add(u), u;
775
+ },
776
+ set(t, e, n) {
777
+ var s;
778
+ if (t.type === 3 || t.type === 2)
779
+ throw new Error("Map/Set draft does not support any property assignment.");
780
+ let r;
781
+ if (t.type === 1 && e !== "length" && !(Number.isInteger(r = Number(e)) && r >= 0 && (e === 0 || r === 0 || String(r) === String(e))))
782
+ throw new Error("Only supports setting array indices and the 'length' property.");
783
+ const o = bn(tt(t), e);
784
+ if (o != null && o.set)
785
+ return o.set.call(t.proxy, n), !0;
786
+ const i = Se(tt(t), e), a = P(i);
787
+ return a && gt(a.original, n) ? (t.copy[e] = n, t.assignedMap = (s = t.assignedMap) !== null && s !== void 0 ? s : /* @__PURE__ */ new Map(), t.assignedMap.set(e, !1), !0) : (gt(n, i) && (n !== void 0 || Ht(t.original, e)) || (Q(t), ht(t), Ht(t.original, e) && gt(n, t.original[e]) ? t.assignedMap.delete(e) : t.assignedMap.set(e, !0), t.copy[e] = n, Xe(t, e, n, zt)), !0);
788
+ },
789
+ has(t, e) {
790
+ return e in tt(t);
791
+ },
792
+ ownKeys(t) {
793
+ return Reflect.ownKeys(tt(t));
794
+ },
795
+ getOwnPropertyDescriptor(t, e) {
796
+ const n = tt(t), s = Reflect.getOwnPropertyDescriptor(n, e);
797
+ return s && {
798
+ writable: !0,
799
+ configurable: t.type !== 1 || e !== "length",
800
+ enumerable: s.enumerable,
801
+ value: n[e]
802
+ };
803
+ },
804
+ getPrototypeOf(t) {
805
+ return Reflect.getPrototypeOf(t.original);
806
+ },
807
+ setPrototypeOf() {
808
+ throw new Error("Cannot call 'setPrototypeOf()' on drafts");
809
+ },
810
+ defineProperty() {
811
+ throw new Error("Cannot call 'defineProperty()' on drafts");
812
+ },
813
+ deleteProperty(t, e) {
814
+ var n;
815
+ return t.type === 1 ? Hn.set.call(this, t, e, void 0, t.proxy) : (Se(t.original, e) !== void 0 || e in t.original ? (Q(t), ht(t), t.assignedMap.set(e, !1)) : (t.assignedMap = (n = t.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), t.assignedMap.delete(e)), t.copy && delete t.copy[e], !0);
816
+ }
817
+ };
818
+ function Ye(t) {
819
+ const { original: e, parentDraft: n, key: s, finalities: r, options: o } = t, i = $t(e), a = {
820
+ type: i,
821
+ finalized: !1,
822
+ parent: n,
823
+ original: e,
824
+ copy: null,
825
+ proxy: null,
826
+ finalities: r,
827
+ options: o,
828
+ // Mapping of draft Set items to their corresponding draft values.
829
+ setMap: i === 3 ? new Map(e.entries()) : void 0
830
+ };
831
+ (s || "key" in t) && (a.key = s);
832
+ const { proxy: u, revoke: c } = Proxy.revocable(i === 1 ? Object.assign([], a) : a, Hn);
833
+ if (r.revoke.push(c), a.proxy = u, n) {
834
+ const l = n;
835
+ l.finalities.draft.push((f, m) => {
836
+ var g, y;
837
+ const R = P(u);
838
+ let O = l.type === 3 ? l.setMap : l.copy;
839
+ const E = bt(O, s), w = P(E);
840
+ if (w) {
841
+ let A = w.original;
842
+ w.operated && (A = We(E)), Pe(w), Te(w, zt, f, m), l.options.enableAutoFreeze && (l.options.updatedValues = (g = l.options.updatedValues) !== null && g !== void 0 ? g : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(A, w.original)), Jt(O, s, A);
843
+ }
844
+ (y = R.callbacks) === null || y === void 0 || y.forEach((A) => {
845
+ A(f, m);
846
+ });
847
+ });
848
+ } else {
849
+ const l = P(u);
850
+ l.finalities.draft.push((f, m) => {
851
+ Pe(l), Te(l, zt, f, m);
852
+ });
853
+ }
854
+ return u;
855
+ }
856
+ Ve.createDraft = Ye;
857
+ function Ts(t, e, n, s, r) {
858
+ var o;
859
+ const i = P(t), a = (o = i == null ? void 0 : i.original) !== null && o !== void 0 ? o : t, u = !!e.length;
860
+ if (i != null && i.operated)
861
+ for (; i.finalities.draft.length > 0; )
862
+ i.finalities.draft.pop()(n, s);
863
+ const c = u ? e[0] : i ? i.operated ? i.copy : i.original : t;
864
+ return i && xe(i), r && Tt(c, c, i == null ? void 0 : i.options.updatedValues), [
865
+ c,
866
+ n && u ? [{ op: J.Replace, path: [], value: e[0] }] : n,
867
+ s && u ? [{ op: J.Replace, path: [], value: a }] : s
868
+ ];
869
+ }
870
+ function Ds(t, e) {
871
+ var n;
872
+ const s = {
873
+ draft: [],
874
+ revoke: [],
875
+ handledSet: /* @__PURE__ */ new WeakSet(),
876
+ draftsCache: /* @__PURE__ */ new WeakSet()
877
+ };
878
+ let r, o;
879
+ e.enablePatches && (r = [], o = []);
880
+ const a = ((n = e.mark) === null || n === void 0 ? void 0 : n.call(e, t, nt)) === nt.mutable || !ut(t, e) ? t : Ye({
881
+ original: t,
882
+ parentDraft: null,
883
+ finalities: s,
884
+ options: e
885
+ });
886
+ return [
887
+ a,
888
+ (u = []) => {
889
+ const [c, l, f] = Ts(a, u, r, o, e.enableAutoFreeze);
890
+ return e.enablePatches ? [c, l, f] : c;
891
+ }
892
+ ];
893
+ }
894
+ function ke(t) {
895
+ const { rootDraft: e, value: n, useRawReturn: s = !1, isRoot: r = !0 } = t;
896
+ Ke(n, (o, i, a) => {
897
+ const u = P(i);
898
+ if (u && e && u.finalities === e.finalities) {
899
+ t.isContainDraft = !0;
900
+ const c = u.original;
901
+ if (a instanceof Set) {
902
+ const l = Array.from(a);
903
+ a.clear(), l.forEach((f) => a.add(o === f ? c : f));
904
+ } else
905
+ Jt(a, o, c);
906
+ } else
907
+ typeof i == "object" && i !== null && (t.value = i, t.isRoot = !1, ke(t));
908
+ }), r && (t.isContainDraft || console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."), s && console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."));
909
+ }
910
+ function Un(t) {
911
+ var e;
912
+ const n = P(t);
913
+ if (!ut(t, n == null ? void 0 : n.options))
914
+ return t;
915
+ const s = $t(t);
916
+ if (n && !n.operated)
917
+ return n.original;
918
+ let r;
919
+ function o() {
920
+ r = s === 2 ? Je(t) ? new Map(t) : new (Object.getPrototypeOf(t)).constructor(t) : s === 3 ? Array.from(n.setMap.values()) : jn(t, n == null ? void 0 : n.options);
921
+ }
922
+ if (n) {
923
+ n.finalized = !0;
924
+ try {
925
+ o();
926
+ } finally {
927
+ n.finalized = !1;
928
+ }
929
+ } else
930
+ r = t;
931
+ if (Ke(r, (i, a) => {
932
+ if (n && gt(bt(n.original, i), a))
933
+ return;
934
+ const u = Un(a);
935
+ u !== a && (r === t && o(), Jt(r, i, u));
936
+ }), s === 3) {
937
+ const i = (e = n == null ? void 0 : n.original) !== null && e !== void 0 ? e : r;
938
+ return Ge(i) ? new Set(r) : new (Object.getPrototypeOf(i)).constructor(r);
939
+ }
940
+ return r;
941
+ }
942
+ function vn(t) {
943
+ if (!St(t))
944
+ throw new Error(`current() is only used for Draft, parameter: ${t}`);
945
+ return Un(t);
946
+ }
947
+ const ks = (t) => {
948
+ if (t !== void 0 && Object.prototype.toString.call(t) !== "[object Object]")
949
+ throw new Error(`Invalid options: ${String(t)}, 'options' should be an object.`);
950
+ return function e(n, s, r) {
951
+ var o, i, a;
952
+ if (typeof n == "function" && typeof s != "function")
953
+ return function(S, ...D) {
954
+ return e(S, (j) => n.call(this, j, ...D), s);
955
+ };
956
+ const u = n, c = s;
957
+ let l = r;
958
+ if (typeof s != "function" && (l = s), l !== void 0 && Object.prototype.toString.call(l) !== "[object Object]")
959
+ throw new Error(`Invalid options: ${l}, 'options' should be an object.`);
960
+ l = Object.assign(Object.assign({}, t), l);
961
+ const f = St(u) ? vn(u) : u, m = Array.isArray(l.mark) ? (S, D) => {
962
+ for (const j of l.mark) {
963
+ if (typeof j != "function")
964
+ throw new Error(`Invalid mark: ${j}, 'mark' should be a function.`);
965
+ const _ = j(S, D);
966
+ if (_)
967
+ return _;
968
+ }
969
+ } : l.mark, g = (o = l.enablePatches) !== null && o !== void 0 ? o : !1, y = (i = l.strict) !== null && i !== void 0 ? i : !1, O = {
970
+ enableAutoFreeze: (a = l.enableAutoFreeze) !== null && a !== void 0 ? a : !1,
971
+ mark: m,
972
+ strict: y,
973
+ enablePatches: g
974
+ };
975
+ if (!ut(f, O) && typeof f == "object" && f !== null)
976
+ throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
977
+ const [E, w] = Ds(f, O);
978
+ if (typeof s != "function") {
979
+ if (!ut(f, O))
980
+ throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
981
+ return [E, w];
982
+ }
983
+ let A;
984
+ try {
985
+ A = c(E);
986
+ } catch (S) {
987
+ throw xe(P(E)), S;
988
+ }
989
+ const T = (S) => {
990
+ const D = P(E);
991
+ if (!St(S)) {
992
+ if (S !== void 0 && !gt(S, E) && (D != null && D.operated))
993
+ throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");
994
+ const _ = S == null ? void 0 : S[Os];
995
+ if (_) {
996
+ const M = _[0];
997
+ return O.strict && typeof S == "object" && S !== null && ke({
998
+ rootDraft: D,
999
+ value: S,
1000
+ useRawReturn: !0
1001
+ }), w([M]);
1002
+ }
1003
+ if (S !== void 0)
1004
+ return typeof S == "object" && S !== null && ke({ rootDraft: D, value: S }), w([S]);
1005
+ }
1006
+ if (S === E || S === void 0)
1007
+ return w([]);
1008
+ const j = P(S);
1009
+ if (O === j.options) {
1010
+ if (j.operated)
1011
+ throw new Error("Cannot return a modified child draft.");
1012
+ return w([vn(S)]);
1013
+ }
1014
+ return w([S]);
1015
+ };
1016
+ return A instanceof Promise ? A.then(T, (S) => {
1017
+ throw xe(P(E)), S;
1018
+ }) : T(A);
1019
+ };
1020
+ }, C = ks();
1021
+ Object.prototype.constructor.toString();
1022
+ const Ls = Fe(fetch), Bn = async (t, e) => {
1023
+ if (!t)
1024
+ throw "Metapage definition null";
1025
+ if (t.version || (t = C(t, (s) => {
1026
+ s.version = "0.3";
1027
+ })), !e)
1028
+ throw 'Missing "version" argument';
1029
+ if (F(e, Gt) > 0)
1030
+ try {
1031
+ return await (await Ls(`https://module.metapage.io/conversion/metapage/v${e}`, {
1032
+ redirect: "follow",
1033
+ retries: 3,
1034
+ retryDelay: 1e3,
1035
+ method: "POST",
1036
+ body: JSON.stringify(t),
1037
+ headers: {
1038
+ "Content-Type": "application/json"
1039
+ }
1040
+ })).json();
1041
+ } catch (s) {
1042
+ throw `Error converting metapage definition to version ${e}: ${s}`;
1043
+ }
1044
+ return Ns(t, e);
1045
+ }, js = async (t) => Bn(t, Gt), Ns = (t, e) => {
1046
+ if (!t)
1047
+ throw "Metapage definition null";
1048
+ if (!t.version)
1049
+ throw `Missing "version" key in metapage definition: ${JSON.stringify(t)}`;
1050
+ let n = wt(t.version);
1051
+ if (n === e)
1052
+ return t;
1053
+ let s = t;
1054
+ for (; n !== e; )
1055
+ switch (n) {
1056
+ case "0.2": {
1057
+ if (F(e, n) > 0)
1058
+ s = Hs(s), n = wt(s.version);
1059
+ else
1060
+ throw `Cannot convert from version ${n} to ${e}`;
1061
+ break;
1062
+ }
1063
+ case "0.3": {
1064
+ F(e, n) > 0 ? (s = Bs(s), n = wt(s.version)) : (s = Us(s), n = wt(s.version));
1065
+ break;
1066
+ }
1067
+ case "1": {
1068
+ F(e, n) > 0 ? (s = Vs(s), n = wt(s.version)) : (s = zs(s), n = wt(s.version));
1069
+ break;
1070
+ }
1071
+ case "2": {
1072
+ if (F(e, n) > 0)
1073
+ throw `Cannot convert from version ${n} to ${e}, 1 is the latest version`;
1074
+ s = Fs(s), n = wt(s.version);
1075
+ break;
1076
+ }
1077
+ default:
1078
+ throw `Unknow version ${n} to ${e}`;
1079
+ }
1080
+ return s;
1081
+ }, Hs = (t) => C(t, (e) => {
1082
+ e.version = "0.3";
1083
+ }), Us = (t) => C(t, (e) => {
1084
+ e.version = "0.2";
1085
+ }), Bs = (t) => C(t, (e) => {
1086
+ const n = e;
1087
+ delete n.plugins, n.version = "1";
1088
+ }), zs = (t) => C(t, (e) => (e.version = "0.3", e)), Fs = (t) => C(t, (e) => {
1089
+ var n, s;
1090
+ return e.version = "1", (n = e == null ? void 0 : e.meta) != null && n.tags && (e.meta.keywords = e.meta.tags, delete e.meta.tags), (s = e == null ? void 0 : e.meta) != null && s.authors && (e.meta.author = e.meta.authors[0], delete e.meta.authors), e;
1091
+ }), Vs = (t) => C(t, (e) => {
1092
+ var n, s;
1093
+ return e.version = "2", (n = e == null ? void 0 : e.meta) != null && n.keywords && (e.meta.tags = e.meta.keywords, delete e.meta.keywords), (s = e == null ? void 0 : e.meta) != null && s.author && (e.meta.authors = [e.meta.author], delete e.meta.author), e;
1094
+ }), wt = (t) => {
1095
+ if (t === "latest")
1096
+ return Gt;
1097
+ if (F(t, "0.2") < 0)
1098
+ throw `Unknown version: ${t}`;
1099
+ if (F(t, "0.2") <= 0 && F(t, "0.3") < 0)
1100
+ return "0.2";
1101
+ if (F(t, "0.3") <= 0)
1102
+ return "0.3";
1103
+ if (F(t, "1") <= 0)
1104
+ return "1";
1105
+ if (t === "2")
1106
+ return "2";
1107
+ throw `Unknown version: ${t}`;
1108
+ }, Gs = Fe(fetch), Js = (t) => {
1109
+ if (t) {
1110
+ if (Array.isArray(t)) {
1111
+ const e = {};
1112
+ for (const n of t)
1113
+ e[n] = {};
1114
+ return e;
1115
+ }
1116
+ return t;
1117
+ }
1118
+ }, zn = async (t, e) => {
1119
+ if (!t)
1120
+ throw "Metaframe definition null";
1121
+ if (!t.version)
1122
+ throw `Missing "version" key in metaframe definition: ${JSON.stringify(t)}`;
1123
+ if (!e)
1124
+ throw 'Missing "version" argument';
1125
+ if (F(e, ye) > 0)
1126
+ try {
1127
+ return await (await Gs(`https://module.metapage.io/conversion/metaframe/v${e}`, {
1128
+ redirect: "follow",
1129
+ retries: 3,
1130
+ retryDelay: 1e3,
1131
+ method: "POST",
1132
+ body: JSON.stringify(t),
1133
+ headers: {
1134
+ "Content-Type": "application/json"
1135
+ }
1136
+ })).json();
1137
+ } catch (s) {
1138
+ throw `Error converting metapage definition to version ${e}: ${s}`;
1139
+ }
1140
+ return Ks(t, e);
1141
+ }, Ws = async (t) => zn(t, ye), Ks = (t, e) => {
1142
+ if (!t)
1143
+ throw "Metaframe definition null";
1144
+ t.version || (t = C(t, (r) => {
1145
+ r.version = "0.3";
1146
+ }));
1147
+ let n = ot(t.version);
1148
+ if (n === e)
1149
+ return t;
1150
+ let s = t;
1151
+ for (; n !== e; )
1152
+ switch (n) {
1153
+ case "0.3": {
1154
+ if (F(e, n) > 0)
1155
+ s = Ys(s), n = ot(s.version);
1156
+ else
1157
+ throw `Cannot convert from version ${n} to ${e}`;
1158
+ break;
1159
+ }
1160
+ case "0.4": {
1161
+ F(e, n) > 0 ? (s = qs(s), n = ot(s.version)) : (s = Xs(s), n = ot(s.version));
1162
+ break;
1163
+ }
1164
+ case "0.5": {
1165
+ F(e, n) > 0 ? (s = sr(s), n = ot(s.version)) : (s = Qs(s), n = ot(s.version));
1166
+ break;
1167
+ }
1168
+ case "0.6": {
1169
+ F(e, n) > 0 ? (s = Zs(s), n = ot(s.version)) : (s = rr(s), n = ot(s.version));
1170
+ break;
1171
+ }
1172
+ case "1": {
1173
+ F(e, n) > 0 ? (s = nr(s), n = ot(s.version)) : (s = tr(s), n = ot(s.version));
1174
+ break;
1175
+ }
1176
+ case "2": {
1177
+ if (F(e, n) > 0)
1178
+ throw `Cannot convert from version ${n} to ${e}`;
1179
+ s = er(s), n = ot(s.version);
1180
+ break;
1181
+ }
1182
+ default:
1183
+ throw `Unknow version ${n} to ${e}`;
1184
+ }
1185
+ return s;
1186
+ }, Le = async (t, e) => {
1187
+ if (!t)
1188
+ return;
1189
+ const n = await Ws(t);
1190
+ return n != null && n.hashParams && (n.hashParams = Js(n.hashParams)), n;
1191
+ }, Xs = (t) => C(t, (e) => {
1192
+ e.version = "0.3", delete e.allow;
1193
+ }), Ys = (t) => C(t, (e) => {
1194
+ e.version = "0.4";
1195
+ }), qs = (t) => C(t, (e) => {
1196
+ if (e.version = "0.5", !(e != null && e.metadata))
1197
+ return;
1198
+ const n = e.metadata.title;
1199
+ delete e.metadata.title, e.metadata.name = n;
1200
+ const s = e.metadata.descriptionUrl;
1201
+ delete e.metadata.descriptionUrl, e.metadata.description = s;
1202
+ const r = e.metadata.keywords;
1203
+ delete e.metadata.keywords, e.metadata.tags = r;
1204
+ }), Qs = (t) => C(t, (e) => {
1205
+ if (e.version = "0.4", !(e != null && e.metadata))
1206
+ return;
1207
+ const n = e.metadata.name;
1208
+ delete e.metadata.name, e.metadata.title = n;
1209
+ const s = e.metadata.description;
1210
+ delete e.metadata.description, e.metadata.descriptionUrl = s;
1211
+ const r = e.metadata.tags;
1212
+ delete e.metadata.tags, e.metadata.keywords = r;
1213
+ }), Zs = (t) => C(t, (e) => {
1214
+ var n;
1215
+ e.version = "1", (n = e == null ? void 0 : e.metadata) != null && n.operations && delete e.metadata.operations;
1216
+ }), tr = (t) => C(t, (e) => {
1217
+ var n;
1218
+ e.version = "0.6", (n = e == null ? void 0 : e.metadata) != null && n.operations && delete e.metadata.operations;
1219
+ }), er = (t) => C(t, (e) => {
1220
+ var n, s;
1221
+ return e.version = "1", (n = e == null ? void 0 : e.metadata) != null && n.authors && (e.metadata.author = (s = e == null ? void 0 : e.metadata) == null ? void 0 : s.authors[0], delete e.metadata.authors), e;
1222
+ }), nr = (t) => C(t, (e) => {
1223
+ var n;
1224
+ return e.version = "2", (n = e == null ? void 0 : e.metadata) != null && n.author && (e.metadata.authors = [
1225
+ e.metadata.author
1226
+ ], delete e.metadata.author), e;
1227
+ }), sr = (t) => C(t, (e) => {
1228
+ var n;
1229
+ e.version = "0.6", (n = e == null ? void 0 : e.metadata) != null && n.operations && delete e.metadata.operations;
1230
+ }), rr = (t) => C(t, (e) => {
1231
+ var n;
1232
+ e.version = "0.5", (n = e == null ? void 0 : e.metadata) != null && n.operations && delete e.metadata.operations;
1233
+ }), ot = (t) => {
1234
+ if (t === "latest")
1235
+ return ye;
1236
+ if (F(t, "0.3") < 0)
1237
+ throw `Unknown version: ${t}`;
1238
+ if (F(t, "0.3") <= 0)
1239
+ return "0.3";
1240
+ if (F(t, "0.4") <= 0)
1241
+ return "0.4";
1242
+ if (F(t, "0.5") <= 0)
1243
+ return "0.5";
1244
+ if (F(t, "0.6") <= 0)
1245
+ return "0.6";
1246
+ if (F(t, "1") <= 0)
1247
+ return "1";
1248
+ if (t === "2")
1249
+ return "2";
1250
+ throw `Unknown version: ${t}`;
1251
+ };
1252
+ var On = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", Lt = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
1253
+ for (var Zt = 0; Zt < On.length; Zt++)
1254
+ Lt[On.charCodeAt(Zt)] = Zt;
1255
+ var vt = function(t) {
1256
+ var e = t.length * 0.75, n = t.length, s, r = 0, o, i, a, u;
1257
+ t[t.length - 1] === "=" && (e--, t[t.length - 2] === "=" && e--);
1258
+ var c = new ArrayBuffer(e), l = new Uint8Array(c);
1259
+ for (s = 0; s < n; s += 4)
1260
+ o = Lt[t.charCodeAt(s)], i = Lt[t.charCodeAt(s + 1)], a = Lt[t.charCodeAt(s + 2)], u = Lt[t.charCodeAt(s + 3)], l[r++] = o << 2 | i >> 4, l[r++] = (i & 15) << 4 | a >> 2, l[r++] = (a & 3) << 6 | u & 63;
1261
+ return c;
1262
+ };
1263
+ const Wt = {
1264
+ TEXT: "text/plain",
1265
+ JSON: "application/json",
1266
+ OCTET_STREAM: "application/octet-stream",
1267
+ // For typed arrays, we'll use application/octet-stream with a type parameter
1268
+ TYPED_ARRAY: "application/octet-stream;type=",
1269
+ // Custom MIME type for URLs that should be treated as data references
1270
+ URI: "text/x-uri"
1271
+ }, X = {
1272
+ Remove: "remove",
1273
+ Replace: "replace",
1274
+ Add: "add"
1275
+ }, Fn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), se = Symbol.iterator, at = {
1276
+ mutable: "mutable",
1277
+ immutable: "immutable"
1278
+ }, qe = {};
1279
+ function Ut(t, e) {
1280
+ return t instanceof Map ? t.has(e) : Object.prototype.hasOwnProperty.call(t, e);
1281
+ }
1282
+ function Sn(t, e) {
1283
+ if (e in t) {
1284
+ let n = Reflect.getPrototypeOf(t);
1285
+ for (; n; ) {
1286
+ const s = Reflect.getOwnPropertyDescriptor(n, e);
1287
+ if (s)
1288
+ return s;
1289
+ n = Reflect.getPrototypeOf(n);
1290
+ }
1291
+ }
1292
+ }
1293
+ function Vn(t) {
1294
+ return Object.getPrototypeOf(t) === Set.prototype;
1295
+ }
1296
+ function Gn(t) {
1297
+ return Object.getPrototypeOf(t) === Map.prototype;
1298
+ }
1299
+ function et(t) {
1300
+ var e;
1301
+ return (e = t.copy) !== null && e !== void 0 ? e : t.original;
1302
+ }
1303
+ function ue(t) {
1304
+ return !!k(t);
1305
+ }
1306
+ function k(t) {
1307
+ return typeof t != "object" ? null : t == null ? void 0 : t[Fn];
1308
+ }
1309
+ function Qe(t) {
1310
+ var e;
1311
+ const n = k(t);
1312
+ return n ? (e = n.copy) !== null && e !== void 0 ? e : n.original : t;
1313
+ }
1314
+ function xt(t, e) {
1315
+ if (!t || typeof t != "object")
1316
+ return !1;
1317
+ let n;
1318
+ return Object.getPrototypeOf(t) === Object.prototype || Array.isArray(t) || t instanceof Map || t instanceof Set || !!(e != null && e.mark) && ((n = e.mark(t, at)) === at.immutable || typeof n == "function");
1319
+ }
1320
+ function Jn(t, e = []) {
1321
+ if (Object.hasOwnProperty.call(t, "key")) {
1322
+ const n = t.parent.copy, s = k(Rt(n, t.key));
1323
+ if (s !== null && (s == null ? void 0 : s.original) !== t.original)
1324
+ return null;
1325
+ const r = t.parent.type === 3, o = r ? Array.from(t.parent.setMap.keys()).indexOf(t.key) : t.key;
1326
+ if (!(r && n.size > o || Ut(n, o)))
1327
+ return null;
1328
+ e.push(o);
1329
+ }
1330
+ if (t.parent)
1331
+ return Jn(t.parent, e);
1332
+ e.reverse();
1333
+ try {
1334
+ ir(t.copy, e);
1335
+ } catch {
1336
+ return null;
1337
+ }
1338
+ return e;
1339
+ }
1340
+ function Kt(t) {
1341
+ return Array.isArray(t) ? 1 : t instanceof Map ? 2 : t instanceof Set ? 3 : 0;
1342
+ }
1343
+ function Rt(t, e) {
1344
+ return Kt(t) === 2 ? t.get(e) : t[e];
1345
+ }
1346
+ function Ze(t, e, n) {
1347
+ Kt(t) === 2 ? t.set(e, n) : t[e] = n;
1348
+ }
1349
+ function Re(t, e) {
1350
+ const n = k(t);
1351
+ return (n ? et(n) : t)[e];
1352
+ }
1353
+ function Ct(t, e) {
1354
+ return t === e ? t !== 0 || 1 / t === 1 / e : t !== t && e !== e;
1355
+ }
1356
+ function It(t, e) {
1357
+ return e ? t : [""].concat(t).map((n) => {
1358
+ const s = `${n}`;
1359
+ return s.indexOf("/") === -1 && s.indexOf("~") === -1 ? s : s.replace(/~/g, "~0").replace(/\//g, "~1");
1360
+ }).join("/");
1361
+ }
1362
+ function ir(t, e) {
1363
+ for (let n = 0; n < e.length - 1; n += 1) {
1364
+ const s = e[n];
1365
+ if (t = Rt(Kt(t) === 3 ? Array.from(t) : t, s), typeof t != "object")
1366
+ throw new Error(`Cannot resolve patch at '${e.join("/")}'.`);
1367
+ }
1368
+ return t;
1369
+ }
1370
+ function or(t) {
1371
+ const e = Object.create(Object.getPrototypeOf(t));
1372
+ return Reflect.ownKeys(t).forEach((n) => {
1373
+ let s = Reflect.getOwnPropertyDescriptor(t, n);
1374
+ if (s.enumerable && s.configurable && s.writable) {
1375
+ e[n] = t[n];
1376
+ return;
1377
+ }
1378
+ s.writable || (s.writable = !0, s.configurable = !0), (s.get || s.set) && (s = {
1379
+ configurable: !0,
1380
+ writable: !0,
1381
+ enumerable: s.enumerable,
1382
+ value: t[n]
1383
+ }), Reflect.defineProperty(e, n, s);
1384
+ }), e;
1385
+ }
1386
+ const ar = Object.prototype.propertyIsEnumerable;
1387
+ function ur(t, e) {
1388
+ let n;
1389
+ if (Array.isArray(t))
1390
+ return Array.prototype.concat.call(t);
1391
+ if (t instanceof Set) {
1392
+ if (!Vn(t)) {
1393
+ const s = Object.getPrototypeOf(t).constructor;
1394
+ return new s(t.values());
1395
+ }
1396
+ return Set.prototype.difference ? Set.prototype.difference.call(t, /* @__PURE__ */ new Set()) : new Set(t.values());
1397
+ } else if (t instanceof Map) {
1398
+ if (!Gn(t)) {
1399
+ const s = Object.getPrototypeOf(t).constructor;
1400
+ return new s(t);
1401
+ }
1402
+ return new Map(t);
1403
+ } else if (e != null && e.mark && (n = e.mark(t, at), n !== void 0) && n !== at.mutable) {
1404
+ if (n === at.immutable)
1405
+ return or(t);
1406
+ if (typeof n == "function") {
1407
+ if (e.enablePatches || e.enableAutoFreeze)
1408
+ throw new Error("You can't use mark and patches or auto freeze together.");
1409
+ return n();
1410
+ }
1411
+ throw new Error(`Unsupported mark result: ${n}`);
1412
+ } else if (typeof t == "object" && Object.getPrototypeOf(t) === Object.prototype) {
1413
+ const s = {};
1414
+ return Object.keys(t).forEach((r) => {
1415
+ s[r] = t[r];
1416
+ }), Object.getOwnPropertySymbols(t).forEach((r) => {
1417
+ ar.call(t, r) && (s[r] = t[r]);
1418
+ }), s;
1419
+ } else
1420
+ throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
1421
+ }
1422
+ function Z(t) {
1423
+ t.copy || (t.copy = ur(t.original, t.options));
1424
+ }
1425
+ function jt(t) {
1426
+ if (!xt(t))
1427
+ return Qe(t);
1428
+ if (Array.isArray(t))
1429
+ return t.map(jt);
1430
+ if (t instanceof Map) {
1431
+ const n = Array.from(t.entries()).map(([s, r]) => [
1432
+ s,
1433
+ jt(r)
1434
+ ]);
1435
+ if (!Gn(t)) {
1436
+ const s = Object.getPrototypeOf(t).constructor;
1437
+ return new s(n);
1438
+ }
1439
+ return new Map(n);
1440
+ }
1441
+ if (t instanceof Set) {
1442
+ const n = Array.from(t).map(jt);
1443
+ if (!Vn(t)) {
1444
+ const s = Object.getPrototypeOf(t).constructor;
1445
+ return new s(n);
1446
+ }
1447
+ return new Set(n);
1448
+ }
1449
+ const e = Object.create(Object.getPrototypeOf(t));
1450
+ for (const n in t)
1451
+ e[n] = jt(t[n]);
1452
+ return e;
1453
+ }
1454
+ function re(t) {
1455
+ return ue(t) ? jt(t) : t;
1456
+ }
1457
+ function dt(t) {
1458
+ var e;
1459
+ t.assignedMap = (e = t.assignedMap) !== null && e !== void 0 ? e : /* @__PURE__ */ new Map(), t.operated || (t.operated = !0, t.parent && dt(t.parent));
1460
+ }
1461
+ function cr(t, e) {
1462
+ const n = Kt(t);
1463
+ if (n === 0)
1464
+ Reflect.ownKeys(t).forEach((s) => {
1465
+ e(s, t[s], t);
1466
+ });
1467
+ else if (n === 1) {
1468
+ let s = 0;
1469
+ for (const r of t)
1470
+ e(s, r, t), s += 1;
1471
+ } else
1472
+ t.forEach((s, r) => e(r, s, t));
1473
+ }
1474
+ function Wn(t, e, n) {
1475
+ if (ue(t) || !xt(t, n) || e.has(t) || Object.isFrozen(t))
1476
+ return;
1477
+ const s = t instanceof Set, r = s ? /* @__PURE__ */ new Map() : void 0;
1478
+ if (e.add(t), cr(t, (o, i) => {
1479
+ var a;
1480
+ if (ue(i)) {
1481
+ const u = k(i);
1482
+ Z(u);
1483
+ const c = !((a = u.assignedMap) === null || a === void 0) && a.size || u.operated ? u.copy : u.original;
1484
+ Ze(s ? r : t, o, c);
1485
+ } else
1486
+ Wn(i, e, n);
1487
+ }), r) {
1488
+ const o = t, i = Array.from(o);
1489
+ o.clear(), i.forEach((a) => {
1490
+ o.add(r.has(a) ? r.get(a) : a);
1491
+ });
1492
+ }
1493
+ }
1494
+ function lr(t, e) {
1495
+ const n = t.type === 3 ? t.setMap : t.copy;
1496
+ t.finalities.revoke.length > 1 && t.assignedMap.get(e) && n && Wn(Rt(n, e), t.finalities.handledSet, t.options);
1497
+ }
1498
+ function je(t) {
1499
+ t.type === 3 && t.copy && (t.copy.clear(), t.setMap.forEach((e) => {
1500
+ t.copy.add(Qe(e));
1501
+ }));
1502
+ }
1503
+ function Ne(t, e, n, s) {
1504
+ if (t.operated && t.assignedMap && t.assignedMap.size > 0 && !t.finalized) {
1505
+ if (n && s) {
1506
+ const r = Jn(t);
1507
+ r && e(t, r, n, s);
1508
+ }
1509
+ t.finalized = !0;
1510
+ }
1511
+ }
1512
+ function tn(t, e, n, s) {
1513
+ const r = k(n);
1514
+ r && (r.callbacks || (r.callbacks = []), r.callbacks.push((o, i) => {
1515
+ var a;
1516
+ const u = t.type === 3 ? t.setMap : t.copy;
1517
+ if (Ct(Rt(u, e), n)) {
1518
+ let c = r.original;
1519
+ r.copy && (c = r.copy), je(t), Ne(t, s, o, i), t.options.enableAutoFreeze && (t.options.updatedValues = (a = t.options.updatedValues) !== null && a !== void 0 ? a : /* @__PURE__ */ new WeakMap(), t.options.updatedValues.set(c, r.original)), Ze(u, e, c);
1520
+ }
1521
+ }), t.options.enableAutoFreeze && r.finalities !== t.finalities && (t.options.enableAutoFreeze = !1)), xt(n, t.options) && t.finalities.draft.push(() => {
1522
+ const o = t.type === 3 ? t.setMap : t.copy;
1523
+ Ct(Rt(o, e), n) && lr(t, e);
1524
+ });
1525
+ }
1526
+ function fr(t, e, n, s, r) {
1527
+ let { original: o, assignedMap: i, options: a } = t, u = t.copy;
1528
+ u.length < o.length && ([o, u] = [u, o], [n, s] = [s, n]);
1529
+ for (let c = 0; c < o.length; c += 1)
1530
+ if (i.get(c.toString()) && u[c] !== o[c]) {
1531
+ const l = e.concat([c]), f = It(l, r);
1532
+ n.push({
1533
+ op: X.Replace,
1534
+ path: f,
1535
+ // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
1536
+ value: re(u[c])
1537
+ }), s.push({
1538
+ op: X.Replace,
1539
+ path: f,
1540
+ // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
1541
+ value: re(o[c])
1542
+ });
1543
+ }
1544
+ for (let c = o.length; c < u.length; c += 1) {
1545
+ const l = e.concat([c]), f = It(l, r);
1546
+ n.push({
1547
+ op: X.Add,
1548
+ path: f,
1549
+ // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
1550
+ value: re(u[c])
1551
+ });
1552
+ }
1553
+ if (o.length < u.length) {
1554
+ const { arrayLengthAssignment: c = !0 } = a.enablePatches;
1555
+ if (c) {
1556
+ const l = e.concat(["length"]), f = It(l, r);
1557
+ s.push({
1558
+ op: X.Replace,
1559
+ path: f,
1560
+ value: o.length
1561
+ });
1562
+ } else
1563
+ for (let l = u.length; o.length < l; l -= 1) {
1564
+ const f = e.concat([l - 1]), m = It(f, r);
1565
+ s.push({
1566
+ op: X.Remove,
1567
+ path: m
1568
+ });
1569
+ }
1570
+ }
1571
+ }
1572
+ function pr({ original: t, copy: e, assignedMap: n }, s, r, o, i) {
1573
+ n.forEach((a, u) => {
1574
+ const c = Rt(t, u), l = re(Rt(e, u)), f = a ? Ut(t, u) ? X.Replace : X.Add : X.Remove;
1575
+ if (Ct(c, l) && f === X.Replace)
1576
+ return;
1577
+ const m = s.concat(u), g = It(m, i);
1578
+ r.push(f === X.Remove ? { op: f, path: g } : { op: f, path: g, value: l }), o.push(f === X.Add ? { op: X.Remove, path: g } : f === X.Remove ? { op: X.Add, path: g, value: c } : { op: X.Replace, path: g, value: c });
1579
+ });
1580
+ }
1581
+ function hr({ original: t, copy: e }, n, s, r, o) {
1582
+ let i = 0;
1583
+ t.forEach((a) => {
1584
+ if (!e.has(a)) {
1585
+ const u = n.concat([i]), c = It(u, o);
1586
+ s.push({
1587
+ op: X.Remove,
1588
+ path: c,
1589
+ value: a
1590
+ }), r.unshift({
1591
+ op: X.Add,
1592
+ path: c,
1593
+ value: a
1594
+ });
1595
+ }
1596
+ i += 1;
1597
+ }), i = 0, e.forEach((a) => {
1598
+ if (!t.has(a)) {
1599
+ const u = n.concat([i]), c = It(u, o);
1600
+ s.push({
1601
+ op: X.Add,
1602
+ path: c,
1603
+ value: a
1604
+ }), r.unshift({
1605
+ op: X.Remove,
1606
+ path: c,
1607
+ value: a
1608
+ });
1609
+ }
1610
+ i += 1;
1611
+ });
1612
+ }
1613
+ function Ft(t, e, n, s) {
1614
+ const { pathAsArray: r = !0 } = t.options.enablePatches;
1615
+ switch (t.type) {
1616
+ case 0:
1617
+ case 2:
1618
+ return pr(t, e, n, s, r);
1619
+ case 1:
1620
+ return fr(t, e, n, s, r);
1621
+ case 3:
1622
+ return hr(t, e, n, s, r);
1623
+ }
1624
+ }
1625
+ let dr = !1;
1626
+ const ce = (t, e, n = !1) => {
1627
+ if (typeof t == "object" && t !== null && (!xt(t, e) || n) && !dr)
1628
+ throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
1629
+ }, He = {
1630
+ get size() {
1631
+ return et(k(this)).size;
1632
+ },
1633
+ has(t) {
1634
+ return et(k(this)).has(t);
1635
+ },
1636
+ set(t, e) {
1637
+ const n = k(this), s = et(n);
1638
+ return (!s.has(t) || !Ct(s.get(t), e)) && (Z(n), dt(n), n.assignedMap.set(t, !0), n.copy.set(t, e), tn(n, t, e, Ft)), this;
1639
+ },
1640
+ delete(t) {
1641
+ if (!this.has(t))
1642
+ return !1;
1643
+ const e = k(this);
1644
+ return Z(e), dt(e), e.original.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.copy.delete(t), !0;
1645
+ },
1646
+ clear() {
1647
+ const t = k(this);
1648
+ if (this.size) {
1649
+ Z(t), dt(t), t.assignedMap = /* @__PURE__ */ new Map();
1650
+ for (const [e] of t.original)
1651
+ t.assignedMap.set(e, !1);
1652
+ t.copy.clear();
1653
+ }
1654
+ },
1655
+ forEach(t, e) {
1656
+ const n = k(this);
1657
+ et(n).forEach((s, r) => {
1658
+ t.call(e, this.get(r), r, this);
1659
+ });
1660
+ },
1661
+ get(t) {
1662
+ var e, n;
1663
+ const s = k(this), r = et(s).get(t), o = ((n = (e = s.options).mark) === null || n === void 0 ? void 0 : n.call(e, r, at)) === at.mutable;
1664
+ if (s.options.strict && ce(r, s.options, o), o || s.finalized || !xt(r, s.options) || r !== s.original.get(t))
1665
+ return r;
1666
+ const i = qe.createDraft({
1667
+ original: r,
1668
+ parentDraft: s,
1669
+ key: t,
1670
+ finalities: s.finalities,
1671
+ options: s.options
1672
+ });
1673
+ return Z(s), s.copy.set(t, i), i;
1674
+ },
1675
+ keys() {
1676
+ return et(k(this)).keys();
1677
+ },
1678
+ values() {
1679
+ const t = this.keys();
1680
+ return {
1681
+ [se]: () => this.values(),
1682
+ next: () => {
1683
+ const e = t.next();
1684
+ return e.done ? e : {
1685
+ done: !1,
1686
+ value: this.get(e.value)
1687
+ };
1688
+ }
1689
+ };
1690
+ },
1691
+ entries() {
1692
+ const t = this.keys();
1693
+ return {
1694
+ [se]: () => this.entries(),
1695
+ next: () => {
1696
+ const e = t.next();
1697
+ if (e.done)
1698
+ return e;
1699
+ const n = this.get(e.value);
1700
+ return {
1701
+ done: !1,
1702
+ value: [e.value, n]
1703
+ };
1704
+ }
1705
+ };
1706
+ },
1707
+ [se]() {
1708
+ return this.entries();
1709
+ }
1710
+ }, mr = Reflect.ownKeys(He), Rn = (t, e, { isValuesIterator: n }) => () => {
1711
+ var s, r;
1712
+ const o = e.next();
1713
+ if (o.done)
1714
+ return o;
1715
+ const i = o.value;
1716
+ let a = t.setMap.get(i);
1717
+ const u = k(a), c = ((r = (s = t.options).mark) === null || r === void 0 ? void 0 : r.call(s, a, at)) === at.mutable;
1718
+ if (t.options.strict && ce(i, t.options, c), !c && !u && xt(i, t.options) && !t.finalized && t.original.has(i)) {
1719
+ const l = qe.createDraft({
1720
+ original: i,
1721
+ parentDraft: t,
1722
+ key: i,
1723
+ finalities: t.finalities,
1724
+ options: t.options
1725
+ });
1726
+ t.setMap.set(i, l), a = l;
1727
+ } else
1728
+ u && (a = u.proxy);
1729
+ return {
1730
+ done: !1,
1731
+ value: n ? a : [a, a]
1732
+ };
1733
+ }, le = {
1734
+ get size() {
1735
+ return k(this).setMap.size;
1736
+ },
1737
+ has(t) {
1738
+ const e = k(this);
1739
+ if (e.setMap.has(t))
1740
+ return !0;
1741
+ Z(e);
1742
+ const n = k(t);
1743
+ return !!(n && e.setMap.has(n.original));
1744
+ },
1745
+ add(t) {
1746
+ const e = k(this);
1747
+ return this.has(t) || (Z(e), dt(e), e.assignedMap.set(t, !0), e.setMap.set(t, t), tn(e, t, t, Ft)), this;
1748
+ },
1749
+ delete(t) {
1750
+ if (!this.has(t))
1751
+ return !1;
1752
+ const e = k(this);
1753
+ Z(e), dt(e);
1754
+ const n = k(t);
1755
+ return n && e.setMap.has(n.original) ? (e.assignedMap.set(n.original, !1), e.setMap.delete(n.original)) : (!n && e.setMap.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.setMap.delete(t));
1756
+ },
1757
+ clear() {
1758
+ if (!this.size)
1759
+ return;
1760
+ const t = k(this);
1761
+ Z(t), dt(t);
1762
+ for (const e of t.original)
1763
+ t.assignedMap.set(e, !1);
1764
+ t.setMap.clear();
1765
+ },
1766
+ values() {
1767
+ const t = k(this);
1768
+ Z(t);
1769
+ const e = t.setMap.keys();
1770
+ return {
1771
+ [Symbol.iterator]: () => this.values(),
1772
+ next: Rn(t, e, { isValuesIterator: !0 })
1773
+ };
1774
+ },
1775
+ entries() {
1776
+ const t = k(this);
1777
+ Z(t);
1778
+ const e = t.setMap.keys();
1779
+ return {
1780
+ [Symbol.iterator]: () => this.entries(),
1781
+ next: Rn(t, e, {
1782
+ isValuesIterator: !1
1783
+ })
1784
+ };
1785
+ },
1786
+ keys() {
1787
+ return this.values();
1788
+ },
1789
+ [se]() {
1790
+ return this.values();
1791
+ },
1792
+ forEach(t, e) {
1793
+ const n = this.values();
1794
+ let s = n.next();
1795
+ for (; !s.done; )
1796
+ t.call(e, s.value, s.value, this), s = n.next();
1797
+ }
1798
+ };
1799
+ Set.prototype.difference && Object.assign(le, {
1800
+ intersection(t) {
1801
+ return Set.prototype.intersection.call(new Set(this.values()), t);
1802
+ },
1803
+ union(t) {
1804
+ return Set.prototype.union.call(new Set(this.values()), t);
1805
+ },
1806
+ difference(t) {
1807
+ return Set.prototype.difference.call(new Set(this.values()), t);
1808
+ },
1809
+ symmetricDifference(t) {
1810
+ return Set.prototype.symmetricDifference.call(new Set(this.values()), t);
1811
+ },
1812
+ isSubsetOf(t) {
1813
+ return Set.prototype.isSubsetOf.call(new Set(this.values()), t);
1814
+ },
1815
+ isSupersetOf(t) {
1816
+ return Set.prototype.isSupersetOf.call(new Set(this.values()), t);
1817
+ },
1818
+ isDisjointFrom(t) {
1819
+ return Set.prototype.isDisjointFrom.call(new Set(this.values()), t);
1820
+ }
1821
+ });
1822
+ const yr = Reflect.ownKeys(le), Kn = {
1823
+ get(t, e, n) {
1824
+ var s, r;
1825
+ const o = (s = t.copy) === null || s === void 0 ? void 0 : s[e];
1826
+ if (o && t.finalities.draftsCache.has(o))
1827
+ return o;
1828
+ if (e === Fn)
1829
+ return t;
1830
+ let i;
1831
+ if (t.options.mark) {
1832
+ const c = e === "size" && (t.original instanceof Map || t.original instanceof Set) ? Reflect.get(t.original, e) : Reflect.get(t.original, e, n);
1833
+ if (i = t.options.mark(c, at), i === at.mutable)
1834
+ return t.options.strict && ce(c, t.options, !0), c;
1835
+ }
1836
+ const a = et(t);
1837
+ if (a instanceof Map && mr.includes(e))
1838
+ return e === "size" ? Object.getOwnPropertyDescriptor(He, "size").get.call(t.proxy) : He[e].bind(t.proxy);
1839
+ if (a instanceof Set && yr.includes(e))
1840
+ return e === "size" ? Object.getOwnPropertyDescriptor(le, "size").get.call(t.proxy) : le[e].bind(t.proxy);
1841
+ if (!Ut(a, e)) {
1842
+ const c = Sn(a, e);
1843
+ return c ? "value" in c ? c.value : (
1844
+ // !case: support for getter
1845
+ (r = c.get) === null || r === void 0 ? void 0 : r.call(t.proxy)
1846
+ ) : void 0;
1847
+ }
1848
+ const u = a[e];
1849
+ if (t.options.strict && ce(u, t.options), t.finalized || !xt(u, t.options))
1850
+ return u;
1851
+ if (u === Re(t.original, e)) {
1852
+ if (Z(t), t.copy[e] = Xn({
1853
+ original: t.original[e],
1854
+ parentDraft: t,
1855
+ key: t.type === 1 ? Number(e) : e,
1856
+ finalities: t.finalities,
1857
+ options: t.options
1858
+ }), typeof i == "function") {
1859
+ const c = k(t.copy[e]);
1860
+ return Z(c), dt(c), c.copy;
1861
+ }
1862
+ return t.copy[e];
1863
+ }
1864
+ return ue(u) && t.finalities.draftsCache.add(u), u;
1865
+ },
1866
+ set(t, e, n) {
1867
+ var s;
1868
+ if (t.type === 3 || t.type === 2)
1869
+ throw new Error("Map/Set draft does not support any property assignment.");
1870
+ let r;
1871
+ if (t.type === 1 && e !== "length" && !(Number.isInteger(r = Number(e)) && r >= 0 && (e === 0 || r === 0 || String(r) === String(e))))
1872
+ throw new Error("Only supports setting array indices and the 'length' property.");
1873
+ const o = Sn(et(t), e);
1874
+ if (o != null && o.set)
1875
+ return o.set.call(t.proxy, n), !0;
1876
+ const i = Re(et(t), e), a = k(i);
1877
+ return a && Ct(a.original, n) ? (t.copy[e] = n, t.assignedMap = (s = t.assignedMap) !== null && s !== void 0 ? s : /* @__PURE__ */ new Map(), t.assignedMap.set(e, !1), !0) : (Ct(n, i) && (n !== void 0 || Ut(t.original, e)) || (Z(t), dt(t), Ut(t.original, e) && Ct(n, t.original[e]) ? t.assignedMap.delete(e) : t.assignedMap.set(e, !0), t.copy[e] = n, tn(t, e, n, Ft)), !0);
1878
+ },
1879
+ has(t, e) {
1880
+ return e in et(t);
1881
+ },
1882
+ ownKeys(t) {
1883
+ return Reflect.ownKeys(et(t));
1884
+ },
1885
+ getOwnPropertyDescriptor(t, e) {
1886
+ const n = et(t), s = Reflect.getOwnPropertyDescriptor(n, e);
1887
+ return s && {
1888
+ writable: !0,
1889
+ configurable: t.type !== 1 || e !== "length",
1890
+ enumerable: s.enumerable,
1891
+ value: n[e]
1892
+ };
1893
+ },
1894
+ getPrototypeOf(t) {
1895
+ return Reflect.getPrototypeOf(t.original);
1896
+ },
1897
+ setPrototypeOf() {
1898
+ throw new Error("Cannot call 'setPrototypeOf()' on drafts");
1899
+ },
1900
+ defineProperty() {
1901
+ throw new Error("Cannot call 'defineProperty()' on drafts");
1902
+ },
1903
+ deleteProperty(t, e) {
1904
+ var n;
1905
+ return t.type === 1 ? Kn.set.call(this, t, e, void 0, t.proxy) : (Re(t.original, e) !== void 0 || e in t.original ? (Z(t), dt(t), t.assignedMap.set(e, !1)) : (t.assignedMap = (n = t.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), t.assignedMap.delete(e)), t.copy && delete t.copy[e], !0);
1906
+ }
1907
+ };
1908
+ function Xn(t) {
1909
+ const { original: e, parentDraft: n, key: s, finalities: r, options: o } = t, i = Kt(e), a = {
1910
+ type: i,
1911
+ finalized: !1,
1912
+ parent: n,
1913
+ original: e,
1914
+ copy: null,
1915
+ proxy: null,
1916
+ finalities: r,
1917
+ options: o,
1918
+ // Mapping of draft Set items to their corresponding draft values.
1919
+ setMap: i === 3 ? new Map(e.entries()) : void 0
1920
+ };
1921
+ (s || "key" in t) && (a.key = s);
1922
+ const { proxy: u, revoke: c } = Proxy.revocable(i === 1 ? Object.assign([], a) : a, Kn);
1923
+ if (r.revoke.push(c), a.proxy = u, n) {
1924
+ const l = n;
1925
+ l.finalities.draft.push((f, m) => {
1926
+ var g, y;
1927
+ const R = k(u);
1928
+ let O = l.type === 3 ? l.setMap : l.copy;
1929
+ const E = Rt(O, s), w = k(E);
1930
+ if (w) {
1931
+ let A = w.original;
1932
+ w.operated && (A = Qe(E)), je(w), Ne(w, Ft, f, m), l.options.enableAutoFreeze && (l.options.updatedValues = (g = l.options.updatedValues) !== null && g !== void 0 ? g : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(A, w.original)), Ze(O, s, A);
1933
+ }
1934
+ (y = R.callbacks) === null || y === void 0 || y.forEach((A) => {
1935
+ A(f, m);
1936
+ });
1937
+ });
1938
+ } else {
1939
+ const l = k(u);
1940
+ l.finalities.draft.push((f, m) => {
1941
+ je(l), Ne(l, Ft, f, m);
1942
+ });
1943
+ }
1944
+ return u;
1945
+ }
1946
+ qe.createDraft = Xn;
1947
+ Object.prototype.constructor.toString();
1948
+ const gr = (t) => typeof t == "string" && t.startsWith("data:"), fe = (t) => {
1949
+ const e = t.match(/^data:([^;]+)/);
1950
+ return e ? e[1] : Wt.OCTET_STREAM;
1951
+ }, Yn = (t) => {
1952
+ var e;
1953
+ const n = {}, s = (e = t.match(/^data:[^;]+;([^,]+),/)) == null ? void 0 : e[1];
1954
+ return s && s.split(";").forEach((r) => {
1955
+ const [o, i] = r.split("=");
1956
+ o && i && (n[o] = i);
1957
+ }), n;
1958
+ }, br = (t) => {
1959
+ const e = new Uint8Array(t), n = btoa(String.fromCharCode(...e));
1960
+ return `data:${Wt.OCTET_STREAM};base64,${n}`;
1961
+ }, _r = (t, e) => {
1962
+ const n = t.buffer, s = new Uint8Array(n), r = btoa(String.fromCharCode(...s));
1963
+ return `data:${Wt.TYPED_ARRAY}${e};base64,${r}`;
1964
+ }, ie = async (t, e) => {
1965
+ if (Or(t)) {
1966
+ const o = vr(t);
1967
+ if (!o)
1968
+ throw new Error("Invalid URL data URL");
1969
+ const i = await fetch(o, { ...e, redirect: "follow" });
1970
+ if (!i.ok)
1971
+ throw new Error(`Failed to fetch ${o}: ${i.statusText}`);
1972
+ return i.arrayBuffer();
1973
+ }
1974
+ const n = t.indexOf(",");
1975
+ if (n === -1)
1976
+ throw new Error("Invalid data URL format");
1977
+ const s = t.substring(0, n), r = t.substring(n + 1);
1978
+ if (s.includes(";base64")) {
1979
+ if (!r)
1980
+ return new ArrayBuffer(0);
1981
+ const o = atob(r), i = new Uint8Array(o.length);
1982
+ for (let a = 0; a < o.length; a++)
1983
+ i[a] = o.charCodeAt(a);
1984
+ return i.buffer;
1985
+ } else {
1986
+ const o = r ? decodeURIComponent(r) : "";
1987
+ return new TextEncoder().encode(o).buffer;
1988
+ }
1989
+ }, wr = async (t, e) => {
1990
+ const n = Yn(t).type;
1991
+ if (!n)
1992
+ throw new Error("Data URL does not contain type parameter");
1993
+ const s = await ie(t, e), r = globalThis[n];
1994
+ return new r(s);
1995
+ }, vr = (t) => fe(t) !== Wt.URI ? null : decodeURIComponent(t.split(",")[1]), Or = (t) => fe(t) === Wt.URI;
1996
+ var An = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", Sr = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
1997
+ for (var te = 0; te < An.length; te++)
1998
+ Sr[An.charCodeAt(te)] = te;
1999
+ var pe;
2000
+ (function(t) {
2001
+ t.base64 = "base64", t.url = "url", t.utf8 = "utf8", t.json = "json", t.key = "key";
2002
+ })(pe || (pe = {}));
2003
+ const Rr = Object.keys(pe).filter((t) => isNaN(Number(t)));
2004
+ new Set(Rr);
2005
+ pe.utf8;
2006
+ new TextEncoder();
2007
+ const Ar = (t) => t instanceof ArrayBuffer || t instanceof Blob || ArrayBuffer.isView(t), Mr = (t) => typeof t == "string" ? t.startsWith("data:") : !!(t && typeof t == "object" && (t._s === !0 && t._c || t.ref === "base64" && t.c)), ge = async (t) => {
2008
+ const e = Object.keys(t), n = [];
2009
+ for (const r of e)
2010
+ Ar(t[r]) && n.push(r);
2011
+ if (n.length === 0)
2012
+ return t;
2013
+ const s = { ...t };
2014
+ for (const r of n)
2015
+ s[r] = await Er(t[r]);
2016
+ return s;
2017
+ }, Bt = async (t) => {
2018
+ const e = Object.keys(t), n = [];
2019
+ for (const r of e)
2020
+ Mr(t[r]) && n.push(r);
2021
+ if (n.length === 0)
2022
+ return t;
2023
+ const s = { ...t };
2024
+ for (const r of n)
2025
+ s[r] = await nn(t[r]);
2026
+ return s;
2027
+ }, en = /* @__PURE__ */ new Set([
2028
+ "Int8Array",
2029
+ "Uint8Array",
2030
+ "Uint8ClampedArray",
2031
+ "Int16Array",
2032
+ "Uint16Array",
2033
+ "Int32Array",
2034
+ "Uint32Array",
2035
+ "Float32Array",
2036
+ "Float64Array",
2037
+ "BigInt64Array",
2038
+ "BigUint64Array"
2039
+ ]), Er = async (t) => {
2040
+ if (t instanceof Int8Array || t instanceof Uint8Array || t instanceof Uint8ClampedArray || t instanceof Int16Array || t instanceof Uint16Array || t instanceof Int32Array || t instanceof Uint32Array || t instanceof Float32Array || t instanceof Float64Array)
2041
+ return _r(t, t.constructor.name);
2042
+ if (t instanceof File) {
2043
+ const e = await t.arrayBuffer(), n = new Uint8Array(e), s = btoa(String.fromCharCode(...n)), r = t.type || "application/octet-stream", o = encodeURIComponent(t.name);
2044
+ return `data:${r};file=true;name=${o};lastModified=${t.lastModified};base64,${s}`;
2045
+ } else if (t instanceof Blob) {
2046
+ const e = await t.arrayBuffer(), n = new Uint8Array(e), s = btoa(String.fromCharCode(...n));
2047
+ return `data:${t.type || "application/octet-stream"};blob=true;base64,${s}`;
2048
+ } else if (t instanceof ArrayBuffer)
2049
+ return br(t);
2050
+ return t;
2051
+ }, nn = async (t) => gr(t) ? Ir(t) : !t || typeof t != "object" ? t : t._s === !0 && t._c ? Cr(t) : t.ref === "base64" && t.c ? $r(t) : t, Wi = async (t) => {
2052
+ const e = await nn(t);
2053
+ if (e instanceof File)
2054
+ return e;
2055
+ if (e instanceof Blob)
2056
+ return new File([e], "file", { type: e.type });
2057
+ if (e instanceof ArrayBuffer)
2058
+ return new File([e], "file", {
2059
+ type: "application/octet-stream"
2060
+ });
2061
+ if (ArrayBuffer.isView(e))
2062
+ return new File([e], "file", {
2063
+ type: "application/octet-stream"
2064
+ });
2065
+ }, Ki = async (t, e, n) => {
2066
+ if (t = await nn(t), n = n || {}, n.type || (n.type = "application/octet-stream"), t instanceof ArrayBuffer)
2067
+ return new File([t], e, n);
2068
+ if (t instanceof File || t instanceof Blob) {
2069
+ const r = await t.arrayBuffer();
2070
+ return t instanceof File && (n.type = t.type), new File([r], e, n);
2071
+ }
2072
+ if (ArrayBuffer.isView(t))
2073
+ return new File([t.buffer], e, n);
2074
+ if (typeof t == "string") {
2075
+ const r = new Blob([t], { type: "text/plain" });
2076
+ return n.type = "text/plain", new File([r], e, n);
2077
+ }
2078
+ if (typeof t == "object") {
2079
+ const r = new Blob([JSON.stringify(t)], {
2080
+ type: "application/json"
2081
+ });
2082
+ return n.type = "application/json", new File([r], e, n);
2083
+ }
2084
+ const s = new Blob([t], { type: "text/plain" });
2085
+ return n.type = "text/plain", new File([s], e, n);
2086
+ };
2087
+ async function Ir(t) {
2088
+ const e = Yn(t);
2089
+ if (e.type && en.has(e.type))
2090
+ return wr(t);
2091
+ if (e.file === "true") {
2092
+ const n = e.name ? decodeURIComponent(e.name) : "file", s = e.lastModified ? parseInt(e.lastModified, 10) : void 0, r = fe(t), o = await ie(t);
2093
+ return new File([o], n, { type: r, lastModified: s });
2094
+ }
2095
+ if (e.blob === "true") {
2096
+ const n = fe(t), s = await ie(t);
2097
+ return new Blob([s], { type: n });
2098
+ }
2099
+ return ie(t);
2100
+ }
2101
+ function Cr(t) {
2102
+ const e = t._c;
2103
+ if (e === "Blob") {
2104
+ const s = t;
2105
+ return new Blob([vt(t.value)], { type: s.fileType });
2106
+ } else if (e === "File") {
2107
+ const s = t;
2108
+ return new File([vt(t.value)], s.name, {
2109
+ type: s.fileType,
2110
+ lastModified: s.lastModified
2111
+ });
2112
+ } else if (e === "ArrayBuffer")
2113
+ return vt(t.value);
2114
+ const n = vt(t.value);
2115
+ if (en.has(e))
2116
+ try {
2117
+ return new globalThis[e](n);
2118
+ } catch {
2119
+ }
2120
+ return t;
2121
+ }
2122
+ function $r(t) {
2123
+ const e = t.c;
2124
+ if (e === "Blob")
2125
+ return new Blob([vt(t.value)], {
2126
+ type: t.fileType || void 0
2127
+ });
2128
+ if (e === "File")
2129
+ return new File([vt(t.value)], t.name || "file", {
2130
+ type: t.fileType || void 0,
2131
+ lastModified: t.lastModified || void 0
2132
+ });
2133
+ if (e === "ArrayBuffer")
2134
+ return vt(t.value);
2135
+ const n = vt(t.value);
2136
+ if (en.has(e))
2137
+ try {
2138
+ return new globalThis[e](n);
2139
+ } catch {
2140
+ }
2141
+ return t;
2142
+ }
2143
+ var I;
2144
+ (function(t) {
2145
+ t.Inputs = "inputs", t.Outputs = "outputs", t.State = "state", t.Definition = "definition", t.Error = "error", t.Warning = "warning", t.UrlHashUpdate = "urlhashupdate", t.Message = "Message";
2146
+ })(I || (I = {}));
2147
+ var q;
2148
+ (function(t) {
2149
+ t.InputsUpdate = "InputsUpdate", t.OutputsUpdate = "OutputsUpdate", t.SetupIframeClientRequest = "SetupIframeClientRequest", t.SetupIframeServerResponseAck = "SetupIframeServerResponseAck", t.HashParamsUpdate = "HashParamsUpdate";
2150
+ })(q || (q = {}));
2151
+ var Ot;
2152
+ (function(t) {
2153
+ t.InputsUpdate = "InputsUpdate", t.MessageAck = "MessageAck", t.SetupIframeServerResponse = "SetupIframeServerResponse";
2154
+ })(Ot || (Ot = {}));
2155
+ const Xi = -32700, Yi = -32600, qi = -32601, Qi = -32602, Zi = -32603;
2156
+ function to(t) {
2157
+ switch (typeof t) {
2158
+ case "string":
2159
+ return !0;
2160
+ case "number":
2161
+ return t % 1 != 0;
2162
+ case "object":
2163
+ return t === null ? (console.warn("Use of null ID in JSONRPC 2.0 is discouraged."), !0) : !1;
2164
+ default:
2165
+ return !1;
2166
+ }
2167
+ }
2168
+ var qn = { exports: {} };
2169
+ (function(t) {
2170
+ var e = Object.prototype.hasOwnProperty, n = "~";
2171
+ function s() {
2172
+ }
2173
+ Object.create && (s.prototype = /* @__PURE__ */ Object.create(null), new s().__proto__ || (n = !1));
2174
+ function r(u, c, l) {
2175
+ this.fn = u, this.context = c, this.once = l || !1;
2176
+ }
2177
+ function o(u, c, l, f, m) {
2178
+ if (typeof l != "function")
2179
+ throw new TypeError("The listener must be a function");
2180
+ var g = new r(l, f || u, m), y = n ? n + c : c;
2181
+ return u._events[y] ? u._events[y].fn ? u._events[y] = [u._events[y], g] : u._events[y].push(g) : (u._events[y] = g, u._eventsCount++), u;
2182
+ }
2183
+ function i(u, c) {
2184
+ --u._eventsCount === 0 ? u._events = new s() : delete u._events[c];
2185
+ }
2186
+ function a() {
2187
+ this._events = new s(), this._eventsCount = 0;
2188
+ }
2189
+ a.prototype.eventNames = function() {
2190
+ var c = [], l, f;
2191
+ if (this._eventsCount === 0)
2192
+ return c;
2193
+ for (f in l = this._events)
2194
+ e.call(l, f) && c.push(n ? f.slice(1) : f);
2195
+ return Object.getOwnPropertySymbols ? c.concat(Object.getOwnPropertySymbols(l)) : c;
2196
+ }, a.prototype.listeners = function(c) {
2197
+ var l = n ? n + c : c, f = this._events[l];
2198
+ if (!f)
2199
+ return [];
2200
+ if (f.fn)
2201
+ return [f.fn];
2202
+ for (var m = 0, g = f.length, y = new Array(g); m < g; m++)
2203
+ y[m] = f[m].fn;
2204
+ return y;
2205
+ }, a.prototype.listenerCount = function(c) {
2206
+ var l = n ? n + c : c, f = this._events[l];
2207
+ return f ? f.fn ? 1 : f.length : 0;
2208
+ }, a.prototype.emit = function(c, l, f, m, g, y) {
2209
+ var R = n ? n + c : c;
2210
+ if (!this._events[R])
2211
+ return !1;
2212
+ var O = this._events[R], E = arguments.length, w, A;
2213
+ if (O.fn) {
2214
+ switch (O.once && this.removeListener(c, O.fn, void 0, !0), E) {
2215
+ case 1:
2216
+ return O.fn.call(O.context), !0;
2217
+ case 2:
2218
+ return O.fn.call(O.context, l), !0;
2219
+ case 3:
2220
+ return O.fn.call(O.context, l, f), !0;
2221
+ case 4:
2222
+ return O.fn.call(O.context, l, f, m), !0;
2223
+ case 5:
2224
+ return O.fn.call(O.context, l, f, m, g), !0;
2225
+ case 6:
2226
+ return O.fn.call(O.context, l, f, m, g, y), !0;
2227
+ }
2228
+ for (A = 1, w = new Array(E - 1); A < E; A++)
2229
+ w[A - 1] = arguments[A];
2230
+ O.fn.apply(O.context, w);
2231
+ } else {
2232
+ var T = O.length, S;
2233
+ for (A = 0; A < T; A++)
2234
+ switch (O[A].once && this.removeListener(c, O[A].fn, void 0, !0), E) {
2235
+ case 1:
2236
+ O[A].fn.call(O[A].context);
2237
+ break;
2238
+ case 2:
2239
+ O[A].fn.call(O[A].context, l);
2240
+ break;
2241
+ case 3:
2242
+ O[A].fn.call(O[A].context, l, f);
2243
+ break;
2244
+ case 4:
2245
+ O[A].fn.call(O[A].context, l, f, m);
2246
+ break;
2247
+ default:
2248
+ if (!w)
2249
+ for (S = 1, w = new Array(E - 1); S < E; S++)
2250
+ w[S - 1] = arguments[S];
2251
+ O[A].fn.apply(O[A].context, w);
2252
+ }
2253
+ }
2254
+ return !0;
2255
+ }, a.prototype.on = function(c, l, f) {
2256
+ return o(this, c, l, f, !1);
2257
+ }, a.prototype.once = function(c, l, f) {
2258
+ return o(this, c, l, f, !0);
2259
+ }, a.prototype.removeListener = function(c, l, f, m) {
2260
+ var g = n ? n + c : c;
2261
+ if (!this._events[g])
2262
+ return this;
2263
+ if (!l)
2264
+ return i(this, g), this;
2265
+ var y = this._events[g];
2266
+ if (y.fn)
2267
+ y.fn === l && (!m || y.once) && (!f || y.context === f) && i(this, g);
2268
+ else {
2269
+ for (var R = 0, O = [], E = y.length; R < E; R++)
2270
+ (y[R].fn !== l || m && !y[R].once || f && y[R].context !== f) && O.push(y[R]);
2271
+ O.length ? this._events[g] = O.length === 1 ? O[0] : O : i(this, g);
2272
+ }
2273
+ return this;
2274
+ }, a.prototype.removeAllListeners = function(c) {
2275
+ var l;
2276
+ return c ? (l = n ? n + c : c, this._events[l] && i(this, l)) : (this._events = new s(), this._eventsCount = 0), this;
2277
+ }, a.prototype.off = a.prototype.removeListener, a.prototype.addListener = a.prototype.on, a.prefixed = n, a.EventEmitter = a, t.exports = a;
2278
+ })(qn);
2279
+ var sn = qn.exports;
2280
+ function xr(t) {
2281
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
2282
+ }
2283
+ var Pr = function(t, e) {
2284
+ e || (e = {}), typeof e == "function" && (e = { cmp: e });
2285
+ var n = typeof e.cycles == "boolean" ? e.cycles : !1, s = e.cmp && /* @__PURE__ */ function(o) {
2286
+ return function(i) {
2287
+ return function(a, u) {
2288
+ var c = { key: a, value: i[a] }, l = { key: u, value: i[u] };
2289
+ return o(c, l);
2290
+ };
2291
+ };
2292
+ }(e.cmp), r = [];
2293
+ return function o(i) {
2294
+ if (i && i.toJSON && typeof i.toJSON == "function" && (i = i.toJSON()), i !== void 0) {
2295
+ if (typeof i == "number")
2296
+ return isFinite(i) ? "" + i : "null";
2297
+ if (typeof i != "object")
2298
+ return JSON.stringify(i);
2299
+ var a, u;
2300
+ if (Array.isArray(i)) {
2301
+ for (u = "[", a = 0; a < i.length; a++)
2302
+ a && (u += ","), u += o(i[a]) || "null";
2303
+ return u + "]";
2304
+ }
2305
+ if (i === null)
2306
+ return "null";
2307
+ if (r.indexOf(i) !== -1) {
2308
+ if (n)
2309
+ return JSON.stringify("__cycle__");
2310
+ throw new TypeError("Converting circular structure to JSON");
2311
+ }
2312
+ var c = r.push(i) - 1, l = Object.keys(i).sort(s && s(i));
2313
+ for (u = "", a = 0; a < l.length; a++) {
2314
+ var f = l[a], m = o(i[f]);
2315
+ m && (u && (u += ","), u += JSON.stringify(f) + ":" + m);
2316
+ }
2317
+ return r.splice(c, 1), "{" + u + "}";
2318
+ }
2319
+ }(t);
2320
+ };
2321
+ const Tr = /* @__PURE__ */ xr(Pr), Dr = (t) => Qn(Tr(t)), kr = (t) => {
2322
+ if (t && t.length > 0)
2323
+ try {
2324
+ return JSON.parse(Zn(t));
2325
+ } catch {
2326
+ return JSON.parse(decodeURIComponent(atob(decodeURIComponent(t))));
2327
+ }
2328
+ }, Qn = (t) => btoa(encodeURIComponent(t)), Zn = (t) => {
2329
+ try {
2330
+ return decodeURIComponent(atob(t));
2331
+ } catch {
2332
+ return decodeURIComponent(atob(decodeURIComponent(t)));
2333
+ }
2334
+ }, ts = (t) => {
2335
+ const e = t instanceof URL ? t : new URL(t);
2336
+ return es(e.hash);
2337
+ }, es = (t) => {
2338
+ let e = t;
2339
+ for (; e.startsWith("#"); )
2340
+ e = e.substring(1);
2341
+ const n = e.indexOf("?");
2342
+ if (n === -1)
2343
+ return [e, {}];
2344
+ const s = e.substring(0, n);
2345
+ e = e.substring(n + 1);
2346
+ const r = {};
2347
+ return e.split("&").filter((o) => o.length > 0).map((o) => {
2348
+ const i = o.indexOf("=");
2349
+ if (i === -1)
2350
+ return [o, ""];
2351
+ const a = o.substring(0, i), u = o.substring(i + 1);
2352
+ return [a, u];
2353
+ }).forEach(([o, i]) => {
2354
+ r[o] = i;
2355
+ }), Object.keys(r).forEach((o) => {
2356
+ r[o] = r[o];
2357
+ }), [s, r];
2358
+ }, Xt = (t, e) => {
2359
+ const [n, s] = ts(t);
2360
+ return s[e];
2361
+ }, Lr = (t) => jr()[1][t], jr = () => ts(window.location.href), Dt = (t, e, n) => {
2362
+ const s = window.location.hash.startsWith("#") ? window.location.hash.substring(1) : window.location.hash, r = Nr(s, t, e);
2363
+ r !== s && (n != null && n.modifyHistory ? window.location.hash = r : (window.history.replaceState(null, document.title, `${window.location.pathname}${window.location.search}${r.startsWith("#") ? "" : "#"}${r}`), window.dispatchEvent(new HashChangeEvent("hashchange"))));
2364
+ }, Nr = (t, e, n) => {
2365
+ const [s, r] = es(t);
2366
+ let o = !1;
2367
+ if (r.hasOwnProperty(e) && n === null || n === void 0 ? (delete r[e], o = !0) : r[e] !== n && (r[e] = n, o = !0), !o)
2368
+ return t;
2369
+ const i = Object.keys(r);
2370
+ i.sort();
2371
+ const a = i.map((u, c) => {
2372
+ const l = r[u];
2373
+ return /^[A-Za-z0-9+/]+={0,2}$/.test(l) && l.length % 4, `${u}=${l}`;
2374
+ }).join("&");
2375
+ return !s && !a ? "" : `${s || ""}${a ? "?" + a : ""}`;
2376
+ }, rn = (t, e) => {
2377
+ const n = Xt(t, e);
2378
+ if (n && n !== "")
2379
+ return kr(n);
2380
+ }, Hr = (t, e, n) => {
2381
+ const s = e ? Dr(e) : void 0;
2382
+ Dt(t, s, n);
2383
+ }, Ur = (t) => rn(window.location.href, t), Br = (t, e) => {
2384
+ const n = Xt(t, e);
2385
+ return n ? parseFloat(n) : void 0;
2386
+ }, ns = (t, e, n) => {
2387
+ Dt(t, e != null ? e.toString() : void 0, n);
2388
+ }, zr = (t) => Br(window.location.href, t), Fr = (t, e) => {
2389
+ const n = Xt(t, e);
2390
+ return n ? parseInt(n) : void 0;
2391
+ }, Vr = (t, e, n) => {
2392
+ ns(t, e, n);
2393
+ }, Gr = (t) => Fr(window.location.href, t), Jr = (t, e) => Xt(t, e) === "true", Wr = (t, e, n) => {
2394
+ Dt(t, e ? "true" : void 0, n);
2395
+ }, Kr = (t) => Jr(window.location.href, t), Xr = (t, e) => {
2396
+ const n = Xt(t, e);
2397
+ return n && n !== "" ? Zn(n) : void 0;
2398
+ }, Yr = (t, e, n) => {
2399
+ const s = e == null ? void 0 : Qn(e);
2400
+ Dt(t, s, n);
2401
+ }, qr = (t) => Xr(window.location.href, t);
2402
+ var Qr = function(t, e) {
2403
+ e || (e = {}), typeof e == "function" && (e = { cmp: e });
2404
+ var n = typeof e.cycles == "boolean" ? e.cycles : !1, s = e.cmp && function(o) {
2405
+ return function(i) {
2406
+ return function(a, u) {
2407
+ var c = { key: a, value: i[a] }, l = { key: u, value: i[u] };
2408
+ return o(c, l);
2409
+ };
2410
+ };
2411
+ }(e.cmp), r = [];
2412
+ return function o(i) {
2413
+ if (i && i.toJSON && typeof i.toJSON == "function" && (i = i.toJSON()), i !== void 0) {
2414
+ if (typeof i == "number")
2415
+ return isFinite(i) ? "" + i : "null";
2416
+ if (typeof i != "object")
2417
+ return JSON.stringify(i);
2418
+ var a, u;
2419
+ if (Array.isArray(i)) {
2420
+ for (u = "[", a = 0; a < i.length; a++)
2421
+ a && (u += ","), u += o(i[a]) || "null";
2422
+ return u + "]";
2423
+ }
2424
+ if (i === null)
2425
+ return "null";
2426
+ if (r.indexOf(i) !== -1) {
2427
+ if (n)
2428
+ return JSON.stringify("__cycle__");
2429
+ throw new TypeError("Converting circular structure to JSON");
2430
+ }
2431
+ var c = r.push(i) - 1, l = Object.keys(i).sort(s && s(i));
2432
+ for (u = "", a = 0; a < l.length; a++) {
2433
+ var f = l[a], m = o(i[f]);
2434
+ m && (u && (u += ","), u += JSON.stringify(f) + ":" + m);
2435
+ }
2436
+ return r.splice(c, 1), "{" + u + "}";
2437
+ }
2438
+ }(t);
2439
+ };
2440
+ const ss = /* @__PURE__ */ ze(Qr);
2441
+ var Vt;
2442
+ (function(t) {
2443
+ t.mp_debug = "mp_debug";
2444
+ })(Vt || (Vt = {}));
2445
+ const Zr = () => {
2446
+ try {
2447
+ return window !== window.top;
2448
+ } catch {
2449
+ return !1;
2450
+ }
2451
+ }, rs = {
2452
+ version: Gt,
2453
+ metaframes: {}
2454
+ };
2455
+ class ti extends sn.EventEmitter {
2456
+ constructor() {
2457
+ super(), this._definition = rs, this.getDefinition = this.getDefinition.bind(this);
2458
+ }
2459
+ error(e) {
2460
+ throw "Subclass should implement";
2461
+ }
2462
+ getDefinition() {
2463
+ return this._definition;
2464
+ }
2465
+ }
2466
+ const he = (t, e) => e ? C(t, (n) => {
2467
+ Object.keys(e).forEach((s) => {
2468
+ e[s] === void 0 ? delete n[s] : n[s] = e[s];
2469
+ });
2470
+ }) : t, eo = (t) => window.location.search ? new URLSearchParams(window.location.search).get(t) : null, no = () => new URLSearchParams(window.location.search).has(Vt.mp_debug), Ue = () => {
2471
+ const t = new URLSearchParams(window.location.search).get(Vt.mp_debug);
2472
+ return t === "true" || t === "1";
2473
+ }, so = (t = 8) => on(t), ei = (t = 8) => on(t), ro = (t = 8) => on(t), Mn = "abcdefghijklmnopqrstuvwxyz0123456789", on = (t = 8) => {
2474
+ for (var e = "", n = Mn.length, s = 0; s < t; s++)
2475
+ e += Mn.charAt(Math.floor(Math.random() * n));
2476
+ return e;
2477
+ }, an = (t, e, n) => {
2478
+ e = e || "000", e && e.trim() == "" && (e = void 0);
2479
+ let s;
2480
+ if (typeof t == "string" ? s = t : typeof t == "number" ? s = t + "" : s = JSON.stringify(t, null, " "), e && e.trim() != "") {
2481
+ var r = `color: #${e}`;
2482
+ n && (r = `${r}; background: #${n}`), s = `%c${s}`, window.console.log(s, r);
2483
+ } else
2484
+ window.console.log(s);
2485
+ }, is = (t) => si(ni(t)), ni = (t) => {
2486
+ var e = 0;
2487
+ for (let n = 0; n < t.length; n++)
2488
+ e = t.charCodeAt(n) + ((e << 5) - e);
2489
+ return e;
2490
+ }, si = (t) => {
2491
+ var e = (t & 16777215).toString(16).toUpperCase();
2492
+ return "00000".substring(0, 6 - e.length) + e;
2493
+ }, Ae = () => document.readyState == "complete" || document.readyState == "interactive", be = async () => Ae() ? Promise.resolve() : new Promise((t) => {
2494
+ if (Ae()) {
2495
+ t();
2496
+ return;
2497
+ }
2498
+ let e = !1;
2499
+ window.addEventListener("load", () => {
2500
+ e || (e = !0, t());
2501
+ }), setTimeout(() => {
2502
+ !e && Ae() && (e = !0, t());
2503
+ }, 200);
2504
+ }), io = async (t) => {
2505
+ const e = ss(t);
2506
+ return await os(e);
2507
+ }, oo = async (t) => {
2508
+ const e = ss({
2509
+ version: t.version,
2510
+ metaframes: t.metaframes
2511
+ });
2512
+ return await os(e);
2513
+ };
2514
+ async function os(t) {
2515
+ const n = new TextEncoder().encode(t), s = await crypto.subtle.digest("SHA-256", n);
2516
+ return btoa(String.fromCharCode(...new Uint8Array(s)));
2517
+ }
2518
+ var ft;
2519
+ (function(t) {
2520
+ t.WaitingForPageLoad = "WaitingForPageLoad", t.SentSetupIframeClientRequest = "SentSetupIframeClientRequest", t.Ready = "Ready";
2521
+ })(ft || (ft = {}));
2522
+ var G;
2523
+ (function(t) {
2524
+ t.Connected = "connected", t.Error = "error", t.Input = "input", t.Inputs = "inputs", t.Message = "message";
2525
+ })(G || (G = {}));
2526
+ class ct extends sn.EventEmitter {
2527
+ constructor(e) {
2528
+ if (super(), this._inputPipeValues = {}, this._outputPipeValues = {}, this._state = ft.WaitingForPageLoad, this._messageSendCount = 0, this.debug = Ue(), this.isInputOutputBlobSerialization = !0, this.id = window.name, this.debug = Ue(), this._isIframe = Zr(), this.addListener = this.addListener.bind(this), this.dispose = this.dispose.bind(this), this.error = this.error.bind(this), this.getInput = this.getInput.bind(this), this.getInputs = this.getInputs.bind(this), this.log = this.log.bind(this), this.logInternal = this.logInternal.bind(this), this.onInput = this.onInput.bind(this), this.onInputs = this.onInputs.bind(this), this.onMessage = this.onMessage.bind(this), this.sendRpc = this.sendRpc.bind(this), this.setInput = this.setInput.bind(this), this.setInputs = this.setInputs.bind(this), this.setInternalInputsAndNotify = this.setInternalInputsAndNotify.bind(this), this.setOutput = this.setOutput.bind(this), this.setOutputs = this.setOutputs.bind(this), this.warn = this.warn.bind(this), this._resolveSetupIframeServerResponse = this._resolveSetupIframeServerResponse.bind(this), this.addListenerReturnDisposer = this.addListenerReturnDisposer.bind(this), this.connected = this.connected.bind(this), this.isConnected = this.isConnected.bind(this), this.disableNotifyOnHashUrlChange = this.disableNotifyOnHashUrlChange.bind(this), this._onHashUrlChange = this._onHashUrlChange.bind(this), this.setParameter = this.setParameter.bind(this), this.setParameterBoolean = this.setParameterBoolean.bind(this), this.setParameterJson = this.setParameterJson.bind(this), this.setParameterBase64 = this.setParameterBase64.bind(this), this.setParameterFloat = this.setParameterFloat.bind(this), this.setParameterInt = this.setParameterInt.bind(this), this.getParameter = this.getParameter.bind(this), this.getParameterBoolean = this.getParameterBoolean.bind(this), this.getParameterJson = this.getParameterJson.bind(this), this.getParameterBase64 = this.getParameterBase64.bind(this), this.getParameterFloat = this.getParameterFloat.bind(this), this.getParameterInt = this.getParameterInt.bind(this), this.deleteParameter = this.deleteParameter.bind(this), !this._isIframe) {
2529
+ this.log("Not an iframe, metaframe code disabled");
2530
+ return;
2531
+ }
2532
+ const n = this;
2533
+ be().then(() => {
2534
+ this.log("pageLoaded"), window.addEventListener("message", this.onMessage), n.sendRpc(q.SetupIframeClientRequest, {
2535
+ version: ct.version
2536
+ }), n._state = ft.SentSetupIframeClientRequest;
2537
+ }), e && e.disableHashChangeEvent || window.addEventListener("hashchange", this._onHashUrlChange);
2538
+ }
2539
+ _resolveSetupIframeServerResponse(e) {
2540
+ if (this._state === ft.WaitingForPageLoad)
2541
+ throw "Got message but page has not finished loading, we should never get in this state";
2542
+ (async () => this._parentId ? this.log("Got JsonRpcMethods.SetupIframeServerResponse but already resolved") : (this._parentVersion = e.version, this.color = is(this.id), this._parentId = e.parentId, this.log(`metapage[${this._parentId}](v${this._parentVersion ? this._parentVersion : "unknown"}) registered`), e.state && e.state.inputs && (this.isInputOutputBlobSerialization ? this._inputPipeValues = await Bt(e.state.inputs) : this._inputPipeValues = e.state.inputs), this._state = ft.Ready, this.sendRpc(q.SetupIframeServerResponseAck, {
2543
+ version: ct.version
2544
+ }), this._inputPipeValues && Object.keys(this._inputPipeValues).length > 0 && (this.emit(G.Inputs, this._inputPipeValues), this.listenerCount(G.Input) > 0 && Object.keys(this._inputPipeValues).forEach((n) => this.emit(G.Input, n, this._inputPipeValues[n]))), this.emit(G.Connected), this.sendRpc(q.OutputsUpdate, this._outputPipeValues)))();
2545
+ }
2546
+ isConnected() {
2547
+ return this._state === ft.Ready;
2548
+ }
2549
+ async connected() {
2550
+ return new Promise((e, n) => {
2551
+ if (this._state === ft.Ready) {
2552
+ e();
2553
+ return;
2554
+ }
2555
+ let s;
2556
+ s = this.addListenerReturnDisposer(G.Connected, () => {
2557
+ e(), s();
2558
+ });
2559
+ });
2560
+ }
2561
+ addListenerReturnDisposer(e, n) {
2562
+ return super.addListener(e, n), () => {
2563
+ super.removeListener(e, n);
2564
+ };
2565
+ }
2566
+ log(e, n, s) {
2567
+ this.debug && this.logInternal(e, n || this.color);
2568
+ }
2569
+ warn(e) {
2570
+ this.debug && this.logInternal(e, "000", this.color);
2571
+ }
2572
+ error(e) {
2573
+ this.logInternal(e, this.color, "f00");
2574
+ }
2575
+ logInternal(e, n, s) {
2576
+ let r;
2577
+ typeof e == "string" ? r = e : typeof e == "number" ? r = e + "" : r = JSON.stringify(e), n = n && n + "", r = (this.id ? `Metaframe[${this.id}] ` : "") + `${r}`, an(r, n, s);
2578
+ }
2579
+ dispose() {
2580
+ super.removeAllListeners(), window.removeEventListener("message", this.onMessage), this.disableNotifyOnHashUrlChange(), this._inputPipeValues = void 0, this._outputPipeValues = void 0;
2581
+ }
2582
+ addListener(e, n) {
2583
+ return super.addListener(e, n), e === G.Inputs && window.setTimeout(() => {
2584
+ this._inputPipeValues && n(this._inputPipeValues);
2585
+ }, 0), this;
2586
+ }
2587
+ onInput(e, n) {
2588
+ return this.addListenerReturnDisposer(G.Input, (s, r) => {
2589
+ e === s && n(r);
2590
+ });
2591
+ }
2592
+ onInputs(e) {
2593
+ return this.addListenerReturnDisposer(G.Inputs, e);
2594
+ }
2595
+ setInput(e, n) {
2596
+ var s = {};
2597
+ s[e] = n, this.setInputs(s);
2598
+ }
2599
+ async setInputs(e) {
2600
+ this.isInputOutputBlobSerialization && (e = await Bt(e)), this.sendRpc(q.InputsUpdate, e);
2601
+ }
2602
+ async setInternalInputsAndNotify(e) {
2603
+ this.isInputOutputBlobSerialization && (e = await Bt(e));
2604
+ const n = e;
2605
+ if (this._inputPipeValues = he(this._inputPipeValues, e), this._inputPipeValues !== n) {
2606
+ Object.keys(e).forEach((s) => {
2607
+ try {
2608
+ this.emit(G.Input, s, e[s]);
2609
+ } catch (r) {
2610
+ console.error(`Error emitting input ${s}: ${r}`), this.emit(G.Error, `Error emitting input ${s}: ${r}`);
2611
+ }
2612
+ });
2613
+ try {
2614
+ this.emit(G.Inputs, e);
2615
+ } catch (s) {
2616
+ console.error(`Error emitting inputs: ${s}`), this.emit(G.Error, `Error emitting inputs: ${s}`);
2617
+ }
2618
+ }
2619
+ }
2620
+ getInput(e) {
2621
+ return console.assert(!!e), this._inputPipeValues[e];
2622
+ }
2623
+ getInputs() {
2624
+ return this._inputPipeValues;
2625
+ }
2626
+ setOutput(e, n) {
2627
+ console.assert(!!e);
2628
+ var s = {};
2629
+ s[e] = n, this.setOutputs(s);
2630
+ }
2631
+ async setOutputs(e) {
2632
+ this.isInputOutputBlobSerialization && (e = await ge(e));
2633
+ const n = e;
2634
+ this._outputPipeValues = he(this._outputPipeValues, e), this._outputPipeValues !== n && this._state === ft.Ready && this.sendRpc(q.OutputsUpdate, e);
2635
+ }
2636
+ disableNotifyOnHashUrlChange() {
2637
+ window.removeEventListener("hashchange", this._onHashUrlChange);
2638
+ }
2639
+ _onHashUrlChange(e) {
2640
+ const n = {
2641
+ hash: window.location.hash,
2642
+ metaframe: this.id
2643
+ };
2644
+ this.sendRpc(q.HashParamsUpdate, n);
2645
+ }
2646
+ sendRpc(e, n) {
2647
+ if (this._isIframe) {
2648
+ const s = {
2649
+ jsonrpc: "2.0",
2650
+ id: ++this._messageSendCount,
2651
+ method: e,
2652
+ params: n,
2653
+ iframeId: this.id,
2654
+ parentId: this._parentId
2655
+ };
2656
+ window.parent && window.parent.postMessage(s, "*");
2657
+ } else
2658
+ this.log("Cannot send JSON-RPC window message: there is no window.parent which means we are not an iframe");
2659
+ }
2660
+ onMessage(e) {
2661
+ if (typeof e.data == "object") {
2662
+ let s = e.data;
2663
+ if (s.jsonrpc === "2.0") {
2664
+ var n = s.method;
2665
+ if (!(n == "SetupIframeServerResponse" || s.parentId == this._parentId && s.iframeId == this.id)) {
2666
+ this.log(`window.message: received message (method=${n}) but jsonrpc.parentId=${s.parentId} _parentId=${this._parentId} jsonrpc.iframeId=${s.iframeId} id=${this.id}`);
2667
+ return;
2668
+ }
2669
+ switch (n) {
2670
+ case Ot.SetupIframeServerResponse:
2671
+ this._resolveSetupIframeServerResponse(s.params);
2672
+ break;
2673
+ case Ot.InputsUpdate:
2674
+ if (this._state !== ft.Ready)
2675
+ throw "Got InputsUpdate but metaframe is not MetaframeLoadingState.Ready";
2676
+ this.setInternalInputsAndNotify(s.params.inputs);
2677
+ break;
2678
+ case Ot.MessageAck:
2679
+ this.debug && this.log(`ACK: ${JSON.stringify(s)}`);
2680
+ break;
2681
+ default:
2682
+ this.debug && this.log(`window.message: unknown JSON-RPC method: ${JSON.stringify(s)}`);
2683
+ break;
2684
+ }
2685
+ this.listenerCount(G.Message) > 0 && this.emit(G.Message, s);
2686
+ }
2687
+ }
2688
+ }
2689
+ setParameter(e, n) {
2690
+ Dt(e, n);
2691
+ }
2692
+ getParameter(e) {
2693
+ return Lr(e);
2694
+ }
2695
+ setParameterBoolean(e, n) {
2696
+ Wr(e, n);
2697
+ }
2698
+ getParameterBoolean(e) {
2699
+ return Kr(e);
2700
+ }
2701
+ setParameterJson(e, n) {
2702
+ Hr(e, n);
2703
+ }
2704
+ getParameterJson(e) {
2705
+ return Ur(e);
2706
+ }
2707
+ setParameterBase64(e, n) {
2708
+ Yr(e, n);
2709
+ }
2710
+ getParameterBase64(e) {
2711
+ return qr(e);
2712
+ }
2713
+ setParameterFloat(e, n) {
2714
+ ns(e, n);
2715
+ }
2716
+ getParameterFloat(e) {
2717
+ return zr(e);
2718
+ }
2719
+ setParameterInt(e, n) {
2720
+ Vr(e, n);
2721
+ }
2722
+ getParameterInt(e) {
2723
+ return Gr(e);
2724
+ }
2725
+ deleteParameter(e) {
2726
+ Dt(e, void 0);
2727
+ }
2728
+ }
2729
+ ct.version = ys;
2730
+ ct.ERROR = G.Error;
2731
+ ct.CONNECTED = G.Connected;
2732
+ ct.INPUT = G.Input;
2733
+ ct.INPUTS = G.Inputs;
2734
+ ct.MESSAGE = G.Message;
2735
+ ct.deserializeInputs = Bt;
2736
+ ct.serializeInputs = ge;
2737
+ var _e = {};
2738
+ const lt = "\\\\/", En = `[^${lt}]`, yt = "\\.", ri = "\\+", ii = "\\?", we = "\\/", oi = "(?=.)", as = "[^/]", un = `(?:${we}|$)`, us = `(?:^|${we})`, cn = `${yt}{1,2}${un}`, ai = `(?!${yt})`, ui = `(?!${us}${cn})`, ci = `(?!${yt}{0,1}${un})`, li = `(?!${cn})`, fi = `[^.${we}]`, pi = `${as}*?`, hi = "/", cs = {
2739
+ DOT_LITERAL: yt,
2740
+ PLUS_LITERAL: ri,
2741
+ QMARK_LITERAL: ii,
2742
+ SLASH_LITERAL: we,
2743
+ ONE_CHAR: oi,
2744
+ QMARK: as,
2745
+ END_ANCHOR: un,
2746
+ DOTS_SLASH: cn,
2747
+ NO_DOT: ai,
2748
+ NO_DOTS: ui,
2749
+ NO_DOT_SLASH: ci,
2750
+ NO_DOTS_SLASH: li,
2751
+ QMARK_NO_DOT: fi,
2752
+ STAR: pi,
2753
+ START_ANCHOR: us,
2754
+ SEP: hi
2755
+ }, di = {
2756
+ ...cs,
2757
+ SLASH_LITERAL: `[${lt}]`,
2758
+ QMARK: En,
2759
+ STAR: `${En}*?`,
2760
+ DOTS_SLASH: `${yt}{1,2}(?:[${lt}]|$)`,
2761
+ NO_DOT: `(?!${yt})`,
2762
+ NO_DOTS: `(?!(?:^|[${lt}])${yt}{1,2}(?:[${lt}]|$))`,
2763
+ NO_DOT_SLASH: `(?!${yt}{0,1}(?:[${lt}]|$))`,
2764
+ NO_DOTS_SLASH: `(?!${yt}{1,2}(?:[${lt}]|$))`,
2765
+ QMARK_NO_DOT: `[^.${lt}]`,
2766
+ START_ANCHOR: `(?:^|[${lt}])`,
2767
+ END_ANCHOR: `(?:[${lt}]|$)`,
2768
+ SEP: "\\"
2769
+ }, mi = {
2770
+ alnum: "a-zA-Z0-9",
2771
+ alpha: "a-zA-Z",
2772
+ ascii: "\\x00-\\x7F",
2773
+ blank: " \\t",
2774
+ cntrl: "\\x00-\\x1F\\x7F",
2775
+ digit: "0-9",
2776
+ graph: "\\x21-\\x7E",
2777
+ lower: "a-z",
2778
+ print: "\\x20-\\x7E ",
2779
+ punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
2780
+ space: " \\t\\r\\n\\v\\f",
2781
+ upper: "A-Z",
2782
+ word: "A-Za-z0-9_",
2783
+ xdigit: "A-Fa-f0-9"
2784
+ };
2785
+ var ve = {
2786
+ MAX_LENGTH: 1024 * 64,
2787
+ POSIX_REGEX_SOURCE: mi,
2788
+ // regular expressions
2789
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
2790
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
2791
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
2792
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
2793
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
2794
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
2795
+ // Replace globs with equivalent patterns to reduce parsing time.
2796
+ REPLACEMENTS: {
2797
+ __proto__: null,
2798
+ "***": "*",
2799
+ "**/**": "**",
2800
+ "**/**/**": "**"
2801
+ },
2802
+ // Digits
2803
+ CHAR_0: 48,
2804
+ /* 0 */
2805
+ CHAR_9: 57,
2806
+ /* 9 */
2807
+ // Alphabet chars.
2808
+ CHAR_UPPERCASE_A: 65,
2809
+ /* A */
2810
+ CHAR_LOWERCASE_A: 97,
2811
+ /* a */
2812
+ CHAR_UPPERCASE_Z: 90,
2813
+ /* Z */
2814
+ CHAR_LOWERCASE_Z: 122,
2815
+ /* z */
2816
+ CHAR_LEFT_PARENTHESES: 40,
2817
+ /* ( */
2818
+ CHAR_RIGHT_PARENTHESES: 41,
2819
+ /* ) */
2820
+ CHAR_ASTERISK: 42,
2821
+ /* * */
2822
+ // Non-alphabetic chars.
2823
+ CHAR_AMPERSAND: 38,
2824
+ /* & */
2825
+ CHAR_AT: 64,
2826
+ /* @ */
2827
+ CHAR_BACKWARD_SLASH: 92,
2828
+ /* \ */
2829
+ CHAR_CARRIAGE_RETURN: 13,
2830
+ /* \r */
2831
+ CHAR_CIRCUMFLEX_ACCENT: 94,
2832
+ /* ^ */
2833
+ CHAR_COLON: 58,
2834
+ /* : */
2835
+ CHAR_COMMA: 44,
2836
+ /* , */
2837
+ CHAR_DOT: 46,
2838
+ /* . */
2839
+ CHAR_DOUBLE_QUOTE: 34,
2840
+ /* " */
2841
+ CHAR_EQUAL: 61,
2842
+ /* = */
2843
+ CHAR_EXCLAMATION_MARK: 33,
2844
+ /* ! */
2845
+ CHAR_FORM_FEED: 12,
2846
+ /* \f */
2847
+ CHAR_FORWARD_SLASH: 47,
2848
+ /* / */
2849
+ CHAR_GRAVE_ACCENT: 96,
2850
+ /* ` */
2851
+ CHAR_HASH: 35,
2852
+ /* # */
2853
+ CHAR_HYPHEN_MINUS: 45,
2854
+ /* - */
2855
+ CHAR_LEFT_ANGLE_BRACKET: 60,
2856
+ /* < */
2857
+ CHAR_LEFT_CURLY_BRACE: 123,
2858
+ /* { */
2859
+ CHAR_LEFT_SQUARE_BRACKET: 91,
2860
+ /* [ */
2861
+ CHAR_LINE_FEED: 10,
2862
+ /* \n */
2863
+ CHAR_NO_BREAK_SPACE: 160,
2864
+ /* \u00A0 */
2865
+ CHAR_PERCENT: 37,
2866
+ /* % */
2867
+ CHAR_PLUS: 43,
2868
+ /* + */
2869
+ CHAR_QUESTION_MARK: 63,
2870
+ /* ? */
2871
+ CHAR_RIGHT_ANGLE_BRACKET: 62,
2872
+ /* > */
2873
+ CHAR_RIGHT_CURLY_BRACE: 125,
2874
+ /* } */
2875
+ CHAR_RIGHT_SQUARE_BRACKET: 93,
2876
+ /* ] */
2877
+ CHAR_SEMICOLON: 59,
2878
+ /* ; */
2879
+ CHAR_SINGLE_QUOTE: 39,
2880
+ /* ' */
2881
+ CHAR_SPACE: 32,
2882
+ /* */
2883
+ CHAR_TAB: 9,
2884
+ /* \t */
2885
+ CHAR_UNDERSCORE: 95,
2886
+ /* _ */
2887
+ CHAR_VERTICAL_LINE: 124,
2888
+ /* | */
2889
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
2890
+ /* \uFEFF */
2891
+ /**
2892
+ * Create EXTGLOB_CHARS
2893
+ */
2894
+ extglobChars(t) {
2895
+ return {
2896
+ "!": { type: "negate", open: "(?:(?!(?:", close: `))${t.STAR})` },
2897
+ "?": { type: "qmark", open: "(?:", close: ")?" },
2898
+ "+": { type: "plus", open: "(?:", close: ")+" },
2899
+ "*": { type: "star", open: "(?:", close: ")*" },
2900
+ "@": { type: "at", open: "(?:", close: ")" }
2901
+ };
2902
+ },
2903
+ /**
2904
+ * Create GLOB_CHARS
2905
+ */
2906
+ globChars(t) {
2907
+ return t === !0 ? di : cs;
2908
+ }
2909
+ };
2910
+ (function(t) {
2911
+ const {
2912
+ REGEX_BACKSLASH: e,
2913
+ REGEX_REMOVE_BACKSLASH: n,
2914
+ REGEX_SPECIAL_CHARS: s,
2915
+ REGEX_SPECIAL_CHARS_GLOBAL: r
2916
+ } = ve;
2917
+ t.isObject = (o) => o !== null && typeof o == "object" && !Array.isArray(o), t.hasRegexChars = (o) => s.test(o), t.isRegexChar = (o) => o.length === 1 && t.hasRegexChars(o), t.escapeRegex = (o) => o.replace(r, "\\$1"), t.toPosixSlashes = (o) => o.replace(e, "/"), t.isWindows = () => {
2918
+ if (typeof navigator < "u" && navigator.platform) {
2919
+ const o = navigator.platform.toLowerCase();
2920
+ return o === "win32" || o === "windows";
2921
+ }
2922
+ return typeof process < "u" && process.platform ? process.platform === "win32" : !1;
2923
+ }, t.removeBackslashes = (o) => o.replace(n, (i) => i === "\\" ? "" : i), t.escapeLast = (o, i, a) => {
2924
+ const u = o.lastIndexOf(i, a);
2925
+ return u === -1 ? o : o[u - 1] === "\\" ? t.escapeLast(o, i, u - 1) : `${o.slice(0, u)}\\${o.slice(u)}`;
2926
+ }, t.removePrefix = (o, i = {}) => {
2927
+ let a = o;
2928
+ return a.startsWith("./") && (a = a.slice(2), i.prefix = "./"), a;
2929
+ }, t.wrapOutput = (o, i = {}, a = {}) => {
2930
+ const u = a.contains ? "" : "^", c = a.contains ? "" : "$";
2931
+ let l = `${u}(?:${o})${c}`;
2932
+ return i.negated === !0 && (l = `(?:^(?!${l}).*$)`), l;
2933
+ }, t.basename = (o, { windows: i } = {}) => {
2934
+ const a = o.split(i ? /[\\/]/ : "/"), u = a[a.length - 1];
2935
+ return u === "" ? a[a.length - 2] : u;
2936
+ };
2937
+ })(_e);
2938
+ const In = _e, {
2939
+ CHAR_ASTERISK: Me,
2940
+ /* * */
2941
+ CHAR_AT: yi,
2942
+ /* @ */
2943
+ CHAR_BACKWARD_SLASH: Nt,
2944
+ /* \ */
2945
+ CHAR_COMMA: gi,
2946
+ /* , */
2947
+ CHAR_DOT: Ee,
2948
+ /* . */
2949
+ CHAR_EXCLAMATION_MARK: Ie,
2950
+ /* ! */
2951
+ CHAR_FORWARD_SLASH: ls,
2952
+ /* / */
2953
+ CHAR_LEFT_CURLY_BRACE: Ce,
2954
+ /* { */
2955
+ CHAR_LEFT_PARENTHESES: $e,
2956
+ /* ( */
2957
+ CHAR_LEFT_SQUARE_BRACKET: bi,
2958
+ /* [ */
2959
+ CHAR_PLUS: _i,
2960
+ /* + */
2961
+ CHAR_QUESTION_MARK: Cn,
2962
+ /* ? */
2963
+ CHAR_RIGHT_CURLY_BRACE: wi,
2964
+ /* } */
2965
+ CHAR_RIGHT_PARENTHESES: $n,
2966
+ /* ) */
2967
+ CHAR_RIGHT_SQUARE_BRACKET: vi
2968
+ /* ] */
2969
+ } = ve, xn = (t) => t === ls || t === Nt, Pn = (t) => {
2970
+ t.isPrefix !== !0 && (t.depth = t.isGlobstar ? 1 / 0 : 1);
2971
+ }, Oi = (t, e) => {
2972
+ const n = e || {}, s = t.length - 1, r = n.parts === !0 || n.scanToEnd === !0, o = [], i = [], a = [];
2973
+ let u = t, c = -1, l = 0, f = 0, m = !1, g = !1, y = !1, R = !1, O = !1, E = !1, w = !1, A = !1, T = !1, S = !1, D = 0, j, _, M = { value: "", depth: 0, isGlob: !1 };
2974
+ const p = () => c >= s, U = () => u.charCodeAt(c + 1), V = () => (j = _, u.charCodeAt(++c));
2975
+ for (; c < s; ) {
2976
+ _ = V();
2977
+ let L;
2978
+ if (_ === Nt) {
2979
+ w = M.backslashes = !0, _ = V(), _ === Ce && (E = !0);
2980
+ continue;
2981
+ }
2982
+ if (E === !0 || _ === Ce) {
2983
+ for (D++; p() !== !0 && (_ = V()); ) {
2984
+ if (_ === Nt) {
2985
+ w = M.backslashes = !0, V();
2986
+ continue;
2987
+ }
2988
+ if (_ === Ce) {
2989
+ D++;
2990
+ continue;
2991
+ }
2992
+ if (E !== !0 && _ === Ee && (_ = V()) === Ee) {
2993
+ if (m = M.isBrace = !0, y = M.isGlob = !0, S = !0, r === !0)
2994
+ continue;
2995
+ break;
2996
+ }
2997
+ if (E !== !0 && _ === gi) {
2998
+ if (m = M.isBrace = !0, y = M.isGlob = !0, S = !0, r === !0)
2999
+ continue;
3000
+ break;
3001
+ }
3002
+ if (_ === wi && (D--, D === 0)) {
3003
+ E = !1, m = M.isBrace = !0, S = !0;
3004
+ break;
3005
+ }
3006
+ }
3007
+ if (r === !0)
3008
+ continue;
3009
+ break;
3010
+ }
3011
+ if (_ === ls) {
3012
+ if (o.push(c), i.push(M), M = { value: "", depth: 0, isGlob: !1 }, S === !0)
3013
+ continue;
3014
+ if (j === Ee && c === l + 1) {
3015
+ l += 2;
3016
+ continue;
3017
+ }
3018
+ f = c + 1;
3019
+ continue;
3020
+ }
3021
+ if (n.noext !== !0 && (_ === _i || _ === yi || _ === Me || _ === Cn || _ === Ie) === !0 && U() === $e) {
3022
+ if (y = M.isGlob = !0, R = M.isExtglob = !0, S = !0, _ === Ie && c === l && (T = !0), r === !0) {
3023
+ for (; p() !== !0 && (_ = V()); ) {
3024
+ if (_ === Nt) {
3025
+ w = M.backslashes = !0, _ = V();
3026
+ continue;
3027
+ }
3028
+ if (_ === $n) {
3029
+ y = M.isGlob = !0, S = !0;
3030
+ break;
3031
+ }
3032
+ }
3033
+ continue;
3034
+ }
3035
+ break;
3036
+ }
3037
+ if (_ === Me) {
3038
+ if (j === Me && (O = M.isGlobstar = !0), y = M.isGlob = !0, S = !0, r === !0)
3039
+ continue;
3040
+ break;
3041
+ }
3042
+ if (_ === Cn) {
3043
+ if (y = M.isGlob = !0, S = !0, r === !0)
3044
+ continue;
3045
+ break;
3046
+ }
3047
+ if (_ === bi) {
3048
+ for (; p() !== !0 && (L = V()); ) {
3049
+ if (L === Nt) {
3050
+ w = M.backslashes = !0, V();
3051
+ continue;
3052
+ }
3053
+ if (L === vi) {
3054
+ g = M.isBracket = !0, y = M.isGlob = !0, S = !0;
3055
+ break;
3056
+ }
3057
+ }
3058
+ if (r === !0)
3059
+ continue;
3060
+ break;
3061
+ }
3062
+ if (n.nonegate !== !0 && _ === Ie && c === l) {
3063
+ A = M.negated = !0, l++;
3064
+ continue;
3065
+ }
3066
+ if (n.noparen !== !0 && _ === $e) {
3067
+ if (y = M.isGlob = !0, r === !0) {
3068
+ for (; p() !== !0 && (_ = V()); ) {
3069
+ if (_ === $e) {
3070
+ w = M.backslashes = !0, _ = V();
3071
+ continue;
3072
+ }
3073
+ if (_ === $n) {
3074
+ S = !0;
3075
+ break;
3076
+ }
3077
+ }
3078
+ continue;
3079
+ }
3080
+ break;
3081
+ }
3082
+ if (y === !0) {
3083
+ if (S = !0, r === !0)
3084
+ continue;
3085
+ break;
3086
+ }
3087
+ }
3088
+ n.noext === !0 && (R = !1, y = !1);
3089
+ let N = u, h = "", d = "";
3090
+ l > 0 && (h = u.slice(0, l), u = u.slice(l), f -= l), N && y === !0 && f > 0 ? (N = u.slice(0, f), d = u.slice(f)) : y === !0 ? (N = "", d = u) : N = u, N && N !== "" && N !== "/" && N !== u && xn(N.charCodeAt(N.length - 1)) && (N = N.slice(0, -1)), n.unescape === !0 && (d && (d = In.removeBackslashes(d)), N && w === !0 && (N = In.removeBackslashes(N)));
3091
+ const st = {
3092
+ prefix: h,
3093
+ input: t,
3094
+ start: l,
3095
+ base: N,
3096
+ glob: d,
3097
+ isBrace: m,
3098
+ isBracket: g,
3099
+ isGlob: y,
3100
+ isExtglob: R,
3101
+ isGlobstar: O,
3102
+ negated: A,
3103
+ negatedExtglob: T
3104
+ };
3105
+ if (n.tokens === !0 && (st.maxDepth = 0, xn(_) || i.push(M), st.tokens = i), n.parts === !0 || n.tokens === !0) {
3106
+ let L;
3107
+ for (let B = 0; B < o.length; B++) {
3108
+ const mt = L ? L + 1 : l, rt = o[B], _t = t.slice(mt, rt);
3109
+ n.tokens && (B === 0 && l !== 0 ? (i[B].isPrefix = !0, i[B].value = h) : i[B].value = _t, Pn(i[B]), st.maxDepth += i[B].depth), (B !== 0 || _t !== "") && a.push(_t), L = rt;
3110
+ }
3111
+ if (L && L + 1 < t.length) {
3112
+ const B = t.slice(L + 1);
3113
+ a.push(B), n.tokens && (i[i.length - 1].value = B, Pn(i[i.length - 1]), st.maxDepth += i[i.length - 1].depth);
3114
+ }
3115
+ st.slashes = o, st.parts = a;
3116
+ }
3117
+ return st;
3118
+ };
3119
+ var Si = Oi;
3120
+ const de = ve, pt = _e, {
3121
+ MAX_LENGTH: me,
3122
+ POSIX_REGEX_SOURCE: Ri,
3123
+ REGEX_NON_SPECIAL_CHARS: Ai,
3124
+ REGEX_SPECIAL_CHARS_BACKREF: Mi,
3125
+ REPLACEMENTS: fs
3126
+ } = de, Ei = (t, e) => {
3127
+ if (typeof e.expandRange == "function")
3128
+ return e.expandRange(...t, e);
3129
+ t.sort();
3130
+ const n = `[${t.join("-")}]`;
3131
+ try {
3132
+ new RegExp(n);
3133
+ } catch {
3134
+ return t.map((r) => pt.escapeRegex(r)).join("..");
3135
+ }
3136
+ return n;
3137
+ }, Pt = (t, e) => `Missing ${t}: "${e}" - use "\\\\${e}" to match literal characters`, ln = (t, e) => {
3138
+ if (typeof t != "string")
3139
+ throw new TypeError("Expected a string");
3140
+ t = fs[t] || t;
3141
+ const n = { ...e }, s = typeof n.maxLength == "number" ? Math.min(me, n.maxLength) : me;
3142
+ let r = t.length;
3143
+ if (r > s)
3144
+ throw new SyntaxError(`Input length: ${r}, exceeds maximum allowed length: ${s}`);
3145
+ const o = { type: "bos", value: "", output: n.prepend || "" }, i = [o], a = n.capture ? "" : "?:", u = de.globChars(n.windows), c = de.extglobChars(u), {
3146
+ DOT_LITERAL: l,
3147
+ PLUS_LITERAL: f,
3148
+ SLASH_LITERAL: m,
3149
+ ONE_CHAR: g,
3150
+ DOTS_SLASH: y,
3151
+ NO_DOT: R,
3152
+ NO_DOT_SLASH: O,
3153
+ NO_DOTS_SLASH: E,
3154
+ QMARK: w,
3155
+ QMARK_NO_DOT: A,
3156
+ STAR: T,
3157
+ START_ANCHOR: S
3158
+ } = u, D = (v) => `(${a}(?:(?!${S}${v.dot ? y : l}).)*?)`, j = n.dot ? "" : R, _ = n.dot ? w : A;
3159
+ let M = n.bash === !0 ? D(n) : T;
3160
+ n.capture && (M = `(${M})`), typeof n.noext == "boolean" && (n.noextglob = n.noext);
3161
+ const p = {
3162
+ input: t,
3163
+ index: -1,
3164
+ start: 0,
3165
+ dot: n.dot === !0,
3166
+ consumed: "",
3167
+ output: "",
3168
+ prefix: "",
3169
+ backtrack: !1,
3170
+ negated: !1,
3171
+ brackets: 0,
3172
+ braces: 0,
3173
+ parens: 0,
3174
+ quotes: 0,
3175
+ globstar: !1,
3176
+ tokens: i
3177
+ };
3178
+ t = pt.removePrefix(t, p), r = t.length;
3179
+ const U = [], V = [], N = [];
3180
+ let h = o, d;
3181
+ const st = () => p.index === r - 1, L = p.peek = (v = 1) => t[p.index + v], B = p.advance = () => t[++p.index] || "", mt = () => t.slice(p.index + 1), rt = (v = "", H = 0) => {
3182
+ p.consumed += v, p.index += H;
3183
+ }, _t = (v) => {
3184
+ p.output += v.output != null ? v.output : v.value, rt(v.value);
3185
+ }, ds = () => {
3186
+ let v = 1;
3187
+ for (; L() === "!" && (L(2) !== "(" || L(3) === "?"); )
3188
+ B(), p.start++, v++;
3189
+ return v % 2 === 0 ? !1 : (p.negated = !0, p.start++, !0);
3190
+ }, Yt = (v) => {
3191
+ p[v]++, N.push(v);
3192
+ }, At = (v) => {
3193
+ p[v]--, N.pop();
3194
+ }, x = (v) => {
3195
+ if (h.type === "globstar") {
3196
+ const H = p.braces > 0 && (v.type === "comma" || v.type === "brace"), b = v.extglob === !0 || U.length && (v.type === "pipe" || v.type === "paren");
3197
+ v.type !== "slash" && v.type !== "paren" && !H && !b && (p.output = p.output.slice(0, -h.output.length), h.type = "star", h.value = "*", h.output = M, p.output += h.output);
3198
+ }
3199
+ if (U.length && v.type !== "paren" && (U[U.length - 1].inner += v.value), (v.value || v.output) && _t(v), h && h.type === "text" && v.type === "text") {
3200
+ h.output = (h.output || h.value) + v.value, h.value += v.value;
3201
+ return;
3202
+ }
3203
+ v.prev = h, i.push(v), h = v;
3204
+ }, qt = (v, H) => {
3205
+ const b = { ...c[H], conditions: 1, inner: "" };
3206
+ b.prev = h, b.parens = p.parens, b.output = p.output;
3207
+ const $ = (n.capture ? "(" : "") + b.open;
3208
+ Yt("parens"), x({ type: v, value: H, output: p.output ? "" : g }), x({ type: "paren", extglob: !0, value: B(), output: $ }), U.push(b);
3209
+ }, ms = (v) => {
3210
+ let H = v.close + (n.capture ? ")" : ""), b;
3211
+ if (v.type === "negate") {
3212
+ let $ = M;
3213
+ if (v.inner && v.inner.length > 1 && v.inner.includes("/") && ($ = D(n)), ($ !== M || st() || /^\)+$/.test(mt())) && (H = v.close = `)$))${$}`), v.inner.includes("*") && (b = mt()) && /^\.[^\\/.]+$/.test(b)) {
3214
+ const z = ln(b, { ...e, fastpaths: !1 }).output;
3215
+ H = v.close = `)${z})${$})`;
3216
+ }
3217
+ v.prev.type === "bos" && (p.negatedExtglob = !0);
3218
+ }
3219
+ x({ type: "paren", extglob: !0, value: d, output: H }), At("parens");
3220
+ };
3221
+ if (n.fastpaths !== !1 && !/(^[*!]|[/()[\]{}"])/.test(t)) {
3222
+ let v = !1, H = t.replace(Mi, (b, $, z, Y, K, Oe) => Y === "\\" ? (v = !0, b) : Y === "?" ? $ ? $ + Y + (K ? w.repeat(K.length) : "") : Oe === 0 ? _ + (K ? w.repeat(K.length) : "") : w.repeat(z.length) : Y === "." ? l.repeat(z.length) : Y === "*" ? $ ? $ + Y + (K ? M : "") : M : $ ? b : `\\${b}`);
3223
+ return v === !0 && (n.unescape === !0 ? H = H.replace(/\\/g, "") : H = H.replace(/\\+/g, (b) => b.length % 2 === 0 ? "\\\\" : b ? "\\" : "")), H === t && n.contains === !0 ? (p.output = t, p) : (p.output = pt.wrapOutput(H, p, e), p);
3224
+ }
3225
+ for (; !st(); ) {
3226
+ if (d = B(), d === "\0")
3227
+ continue;
3228
+ if (d === "\\") {
3229
+ const b = L();
3230
+ if (b === "/" && n.bash !== !0 || b === "." || b === ";")
3231
+ continue;
3232
+ if (!b) {
3233
+ d += "\\", x({ type: "text", value: d });
3234
+ continue;
3235
+ }
3236
+ const $ = /^\\+/.exec(mt());
3237
+ let z = 0;
3238
+ if ($ && $[0].length > 2 && (z = $[0].length, p.index += z, z % 2 !== 0 && (d += "\\")), n.unescape === !0 ? d = B() : d += B(), p.brackets === 0) {
3239
+ x({ type: "text", value: d });
3240
+ continue;
3241
+ }
3242
+ }
3243
+ if (p.brackets > 0 && (d !== "]" || h.value === "[" || h.value === "[^")) {
3244
+ if (n.posix !== !1 && d === ":") {
3245
+ const b = h.value.slice(1);
3246
+ if (b.includes("[") && (h.posix = !0, b.includes(":"))) {
3247
+ const $ = h.value.lastIndexOf("["), z = h.value.slice(0, $), Y = h.value.slice($ + 2), K = Ri[Y];
3248
+ if (K) {
3249
+ h.value = z + K, p.backtrack = !0, B(), !o.output && i.indexOf(h) === 1 && (o.output = g);
3250
+ continue;
3251
+ }
3252
+ }
3253
+ }
3254
+ (d === "[" && L() !== ":" || d === "-" && L() === "]") && (d = `\\${d}`), d === "]" && (h.value === "[" || h.value === "[^") && (d = `\\${d}`), n.posix === !0 && d === "!" && h.value === "[" && (d = "^"), h.value += d, _t({ value: d });
3255
+ continue;
3256
+ }
3257
+ if (p.quotes === 1 && d !== '"') {
3258
+ d = pt.escapeRegex(d), h.value += d, _t({ value: d });
3259
+ continue;
3260
+ }
3261
+ if (d === '"') {
3262
+ p.quotes = p.quotes === 1 ? 0 : 1, n.keepQuotes === !0 && x({ type: "text", value: d });
3263
+ continue;
3264
+ }
3265
+ if (d === "(") {
3266
+ Yt("parens"), x({ type: "paren", value: d });
3267
+ continue;
3268
+ }
3269
+ if (d === ")") {
3270
+ if (p.parens === 0 && n.strictBrackets === !0)
3271
+ throw new SyntaxError(Pt("opening", "("));
3272
+ const b = U[U.length - 1];
3273
+ if (b && p.parens === b.parens + 1) {
3274
+ ms(U.pop());
3275
+ continue;
3276
+ }
3277
+ x({ type: "paren", value: d, output: p.parens ? ")" : "\\)" }), At("parens");
3278
+ continue;
3279
+ }
3280
+ if (d === "[") {
3281
+ if (n.nobracket === !0 || !mt().includes("]")) {
3282
+ if (n.nobracket !== !0 && n.strictBrackets === !0)
3283
+ throw new SyntaxError(Pt("closing", "]"));
3284
+ d = `\\${d}`;
3285
+ } else
3286
+ Yt("brackets");
3287
+ x({ type: "bracket", value: d });
3288
+ continue;
3289
+ }
3290
+ if (d === "]") {
3291
+ if (n.nobracket === !0 || h && h.type === "bracket" && h.value.length === 1) {
3292
+ x({ type: "text", value: d, output: `\\${d}` });
3293
+ continue;
3294
+ }
3295
+ if (p.brackets === 0) {
3296
+ if (n.strictBrackets === !0)
3297
+ throw new SyntaxError(Pt("opening", "["));
3298
+ x({ type: "text", value: d, output: `\\${d}` });
3299
+ continue;
3300
+ }
3301
+ At("brackets");
3302
+ const b = h.value.slice(1);
3303
+ if (h.posix !== !0 && b[0] === "^" && !b.includes("/") && (d = `/${d}`), h.value += d, _t({ value: d }), n.literalBrackets === !1 || pt.hasRegexChars(b))
3304
+ continue;
3305
+ const $ = pt.escapeRegex(h.value);
3306
+ if (p.output = p.output.slice(0, -h.value.length), n.literalBrackets === !0) {
3307
+ p.output += $, h.value = $;
3308
+ continue;
3309
+ }
3310
+ h.value = `(${a}${$}|${h.value})`, p.output += h.value;
3311
+ continue;
3312
+ }
3313
+ if (d === "{" && n.nobrace !== !0) {
3314
+ Yt("braces");
3315
+ const b = {
3316
+ type: "brace",
3317
+ value: d,
3318
+ output: "(",
3319
+ outputIndex: p.output.length,
3320
+ tokensIndex: p.tokens.length
3321
+ };
3322
+ V.push(b), x(b);
3323
+ continue;
3324
+ }
3325
+ if (d === "}") {
3326
+ const b = V[V.length - 1];
3327
+ if (n.nobrace === !0 || !b) {
3328
+ x({ type: "text", value: d, output: d });
3329
+ continue;
3330
+ }
3331
+ let $ = ")";
3332
+ if (b.dots === !0) {
3333
+ const z = i.slice(), Y = [];
3334
+ for (let K = z.length - 1; K >= 0 && (i.pop(), z[K].type !== "brace"); K--)
3335
+ z[K].type !== "dots" && Y.unshift(z[K].value);
3336
+ $ = Ei(Y, n), p.backtrack = !0;
3337
+ }
3338
+ if (b.comma !== !0 && b.dots !== !0) {
3339
+ const z = p.output.slice(0, b.outputIndex), Y = p.tokens.slice(b.tokensIndex);
3340
+ b.value = b.output = "\\{", d = $ = "\\}", p.output = z;
3341
+ for (const K of Y)
3342
+ p.output += K.output || K.value;
3343
+ }
3344
+ x({ type: "brace", value: d, output: $ }), At("braces"), V.pop();
3345
+ continue;
3346
+ }
3347
+ if (d === "|") {
3348
+ U.length > 0 && U[U.length - 1].conditions++, x({ type: "text", value: d });
3349
+ continue;
3350
+ }
3351
+ if (d === ",") {
3352
+ let b = d;
3353
+ const $ = V[V.length - 1];
3354
+ $ && N[N.length - 1] === "braces" && ($.comma = !0, b = "|"), x({ type: "comma", value: d, output: b });
3355
+ continue;
3356
+ }
3357
+ if (d === "/") {
3358
+ if (h.type === "dot" && p.index === p.start + 1) {
3359
+ p.start = p.index + 1, p.consumed = "", p.output = "", i.pop(), h = o;
3360
+ continue;
3361
+ }
3362
+ x({ type: "slash", value: d, output: m });
3363
+ continue;
3364
+ }
3365
+ if (d === ".") {
3366
+ if (p.braces > 0 && h.type === "dot") {
3367
+ h.value === "." && (h.output = l);
3368
+ const b = V[V.length - 1];
3369
+ h.type = "dots", h.output += d, h.value += d, b.dots = !0;
3370
+ continue;
3371
+ }
3372
+ if (p.braces + p.parens === 0 && h.type !== "bos" && h.type !== "slash") {
3373
+ x({ type: "text", value: d, output: l });
3374
+ continue;
3375
+ }
3376
+ x({ type: "dot", value: d, output: l });
3377
+ continue;
3378
+ }
3379
+ if (d === "?") {
3380
+ if (!(h && h.value === "(") && n.noextglob !== !0 && L() === "(" && L(2) !== "?") {
3381
+ qt("qmark", d);
3382
+ continue;
3383
+ }
3384
+ if (h && h.type === "paren") {
3385
+ const $ = L();
3386
+ let z = d;
3387
+ (h.value === "(" && !/[!=<:]/.test($) || $ === "<" && !/<([!=]|\w+>)/.test(mt())) && (z = `\\${d}`), x({ type: "text", value: d, output: z });
3388
+ continue;
3389
+ }
3390
+ if (n.dot !== !0 && (h.type === "slash" || h.type === "bos")) {
3391
+ x({ type: "qmark", value: d, output: A });
3392
+ continue;
3393
+ }
3394
+ x({ type: "qmark", value: d, output: w });
3395
+ continue;
3396
+ }
3397
+ if (d === "!") {
3398
+ if (n.noextglob !== !0 && L() === "(" && (L(2) !== "?" || !/[!=<:]/.test(L(3)))) {
3399
+ qt("negate", d);
3400
+ continue;
3401
+ }
3402
+ if (n.nonegate !== !0 && p.index === 0) {
3403
+ ds();
3404
+ continue;
3405
+ }
3406
+ }
3407
+ if (d === "+") {
3408
+ if (n.noextglob !== !0 && L() === "(" && L(2) !== "?") {
3409
+ qt("plus", d);
3410
+ continue;
3411
+ }
3412
+ if (h && h.value === "(" || n.regex === !1) {
3413
+ x({ type: "plus", value: d, output: f });
3414
+ continue;
3415
+ }
3416
+ if (h && (h.type === "bracket" || h.type === "paren" || h.type === "brace") || p.parens > 0) {
3417
+ x({ type: "plus", value: d });
3418
+ continue;
3419
+ }
3420
+ x({ type: "plus", value: f });
3421
+ continue;
3422
+ }
3423
+ if (d === "@") {
3424
+ if (n.noextglob !== !0 && L() === "(" && L(2) !== "?") {
3425
+ x({ type: "at", extglob: !0, value: d, output: "" });
3426
+ continue;
3427
+ }
3428
+ x({ type: "text", value: d });
3429
+ continue;
3430
+ }
3431
+ if (d !== "*") {
3432
+ (d === "$" || d === "^") && (d = `\\${d}`);
3433
+ const b = Ai.exec(mt());
3434
+ b && (d += b[0], p.index += b[0].length), x({ type: "text", value: d });
3435
+ continue;
3436
+ }
3437
+ if (h && (h.type === "globstar" || h.star === !0)) {
3438
+ h.type = "star", h.star = !0, h.value += d, h.output = M, p.backtrack = !0, p.globstar = !0, rt(d);
3439
+ continue;
3440
+ }
3441
+ let v = mt();
3442
+ if (n.noextglob !== !0 && /^\([^?]/.test(v)) {
3443
+ qt("star", d);
3444
+ continue;
3445
+ }
3446
+ if (h.type === "star") {
3447
+ if (n.noglobstar === !0) {
3448
+ rt(d);
3449
+ continue;
3450
+ }
3451
+ const b = h.prev, $ = b.prev, z = b.type === "slash" || b.type === "bos", Y = $ && ($.type === "star" || $.type === "globstar");
3452
+ if (n.bash === !0 && (!z || v[0] && v[0] !== "/")) {
3453
+ x({ type: "star", value: d, output: "" });
3454
+ continue;
3455
+ }
3456
+ const K = p.braces > 0 && (b.type === "comma" || b.type === "brace"), Oe = U.length && (b.type === "pipe" || b.type === "paren");
3457
+ if (!z && b.type !== "paren" && !K && !Oe) {
3458
+ x({ type: "star", value: d, output: "" });
3459
+ continue;
3460
+ }
3461
+ for (; v.slice(0, 3) === "/**"; ) {
3462
+ const Qt = t[p.index + 4];
3463
+ if (Qt && Qt !== "/")
3464
+ break;
3465
+ v = v.slice(3), rt("/**", 3);
3466
+ }
3467
+ if (b.type === "bos" && st()) {
3468
+ h.type = "globstar", h.value += d, h.output = D(n), p.output = h.output, p.globstar = !0, rt(d);
3469
+ continue;
3470
+ }
3471
+ if (b.type === "slash" && b.prev.type !== "bos" && !Y && st()) {
3472
+ p.output = p.output.slice(0, -(b.output + h.output).length), b.output = `(?:${b.output}`, h.type = "globstar", h.output = D(n) + (n.strictSlashes ? ")" : "|$)"), h.value += d, p.globstar = !0, p.output += b.output + h.output, rt(d);
3473
+ continue;
3474
+ }
3475
+ if (b.type === "slash" && b.prev.type !== "bos" && v[0] === "/") {
3476
+ const Qt = v[1] !== void 0 ? "|$" : "";
3477
+ p.output = p.output.slice(0, -(b.output + h.output).length), b.output = `(?:${b.output}`, h.type = "globstar", h.output = `${D(n)}${m}|${m}${Qt})`, h.value += d, p.output += b.output + h.output, p.globstar = !0, rt(d + B()), x({ type: "slash", value: "/", output: "" });
3478
+ continue;
3479
+ }
3480
+ if (b.type === "bos" && v[0] === "/") {
3481
+ h.type = "globstar", h.value += d, h.output = `(?:^|${m}|${D(n)}${m})`, p.output = h.output, p.globstar = !0, rt(d + B()), x({ type: "slash", value: "/", output: "" });
3482
+ continue;
3483
+ }
3484
+ p.output = p.output.slice(0, -h.output.length), h.type = "globstar", h.output = D(n), h.value += d, p.output += h.output, p.globstar = !0, rt(d);
3485
+ continue;
3486
+ }
3487
+ const H = { type: "star", value: d, output: M };
3488
+ if (n.bash === !0) {
3489
+ H.output = ".*?", (h.type === "bos" || h.type === "slash") && (H.output = j + H.output), x(H);
3490
+ continue;
3491
+ }
3492
+ if (h && (h.type === "bracket" || h.type === "paren") && n.regex === !0) {
3493
+ H.output = d, x(H);
3494
+ continue;
3495
+ }
3496
+ (p.index === p.start || h.type === "slash" || h.type === "dot") && (h.type === "dot" ? (p.output += O, h.output += O) : n.dot === !0 ? (p.output += E, h.output += E) : (p.output += j, h.output += j), L() !== "*" && (p.output += g, h.output += g)), x(H);
3497
+ }
3498
+ for (; p.brackets > 0; ) {
3499
+ if (n.strictBrackets === !0)
3500
+ throw new SyntaxError(Pt("closing", "]"));
3501
+ p.output = pt.escapeLast(p.output, "["), At("brackets");
3502
+ }
3503
+ for (; p.parens > 0; ) {
3504
+ if (n.strictBrackets === !0)
3505
+ throw new SyntaxError(Pt("closing", ")"));
3506
+ p.output = pt.escapeLast(p.output, "("), At("parens");
3507
+ }
3508
+ for (; p.braces > 0; ) {
3509
+ if (n.strictBrackets === !0)
3510
+ throw new SyntaxError(Pt("closing", "}"));
3511
+ p.output = pt.escapeLast(p.output, "{"), At("braces");
3512
+ }
3513
+ if (n.strictSlashes !== !0 && (h.type === "star" || h.type === "bracket") && x({ type: "maybe_slash", value: "", output: `${m}?` }), p.backtrack === !0) {
3514
+ p.output = "";
3515
+ for (const v of p.tokens)
3516
+ p.output += v.output != null ? v.output : v.value, v.suffix && (p.output += v.suffix);
3517
+ }
3518
+ return p;
3519
+ };
3520
+ ln.fastpaths = (t, e) => {
3521
+ const n = { ...e }, s = typeof n.maxLength == "number" ? Math.min(me, n.maxLength) : me, r = t.length;
3522
+ if (r > s)
3523
+ throw new SyntaxError(`Input length: ${r}, exceeds maximum allowed length: ${s}`);
3524
+ t = fs[t] || t;
3525
+ const {
3526
+ DOT_LITERAL: o,
3527
+ SLASH_LITERAL: i,
3528
+ ONE_CHAR: a,
3529
+ DOTS_SLASH: u,
3530
+ NO_DOT: c,
3531
+ NO_DOTS: l,
3532
+ NO_DOTS_SLASH: f,
3533
+ STAR: m,
3534
+ START_ANCHOR: g
3535
+ } = de.globChars(n.windows), y = n.dot ? l : c, R = n.dot ? f : c, O = n.capture ? "" : "?:", E = { negated: !1, prefix: "" };
3536
+ let w = n.bash === !0 ? ".*?" : m;
3537
+ n.capture && (w = `(${w})`);
3538
+ const A = (j) => j.noglobstar === !0 ? w : `(${O}(?:(?!${g}${j.dot ? u : o}).)*?)`, T = (j) => {
3539
+ switch (j) {
3540
+ case "*":
3541
+ return `${y}${a}${w}`;
3542
+ case ".*":
3543
+ return `${o}${a}${w}`;
3544
+ case "*.*":
3545
+ return `${y}${w}${o}${a}${w}`;
3546
+ case "*/*":
3547
+ return `${y}${w}${i}${a}${R}${w}`;
3548
+ case "**":
3549
+ return y + A(n);
3550
+ case "**/*":
3551
+ return `(?:${y}${A(n)}${i})?${R}${a}${w}`;
3552
+ case "**/*.*":
3553
+ return `(?:${y}${A(n)}${i})?${R}${w}${o}${a}${w}`;
3554
+ case "**/.*":
3555
+ return `(?:${y}${A(n)}${i})?${o}${a}${w}`;
3556
+ default: {
3557
+ const _ = /^(.*?)\.(\w+)$/.exec(j);
3558
+ if (!_)
3559
+ return;
3560
+ const M = T(_[1]);
3561
+ return M ? M + o + _[2] : void 0;
3562
+ }
3563
+ }
3564
+ }, S = pt.removePrefix(t, E);
3565
+ let D = T(S);
3566
+ return D && n.strictSlashes !== !0 && (D += `${i}?`), D;
3567
+ };
3568
+ var Ii = ln;
3569
+ const Ci = Si, Be = Ii, ps = _e, $i = ve, xi = (t) => t && typeof t == "object" && !Array.isArray(t), W = (t, e, n = !1) => {
3570
+ if (Array.isArray(t)) {
3571
+ const l = t.map((m) => W(m, e, n));
3572
+ return (m) => {
3573
+ for (const g of l) {
3574
+ const y = g(m);
3575
+ if (y)
3576
+ return y;
3577
+ }
3578
+ return !1;
3579
+ };
3580
+ }
3581
+ const s = xi(t) && t.tokens && t.input;
3582
+ if (t === "" || typeof t != "string" && !s)
3583
+ throw new TypeError("Expected pattern to be a non-empty string");
3584
+ const r = e || {}, o = r.windows, i = s ? W.compileRe(t, e) : W.makeRe(t, e, !1, !0), a = i.state;
3585
+ delete i.state;
3586
+ let u = () => !1;
3587
+ if (r.ignore) {
3588
+ const l = { ...e, ignore: null, onMatch: null, onResult: null };
3589
+ u = W(r.ignore, l, n);
3590
+ }
3591
+ const c = (l, f = !1) => {
3592
+ const { isMatch: m, match: g, output: y } = W.test(l, i, e, { glob: t, posix: o }), R = { glob: t, state: a, regex: i, posix: o, input: l, output: y, match: g, isMatch: m };
3593
+ return typeof r.onResult == "function" && r.onResult(R), m === !1 ? (R.isMatch = !1, f ? R : !1) : u(l) ? (typeof r.onIgnore == "function" && r.onIgnore(R), R.isMatch = !1, f ? R : !1) : (typeof r.onMatch == "function" && r.onMatch(R), f ? R : !0);
3594
+ };
3595
+ return n && (c.state = a), c;
3596
+ };
3597
+ W.test = (t, e, n, { glob: s, posix: r } = {}) => {
3598
+ if (typeof t != "string")
3599
+ throw new TypeError("Expected input to be a string");
3600
+ if (t === "")
3601
+ return { isMatch: !1, output: "" };
3602
+ const o = n || {}, i = o.format || (r ? ps.toPosixSlashes : null);
3603
+ let a = t === s, u = a && i ? i(t) : t;
3604
+ return a === !1 && (u = i ? i(t) : t, a = u === s), (a === !1 || o.capture === !0) && (o.matchBase === !0 || o.basename === !0 ? a = W.matchBase(t, e, n, r) : a = e.exec(u)), { isMatch: !!a, match: a, output: u };
3605
+ };
3606
+ W.matchBase = (t, e, n) => (e instanceof RegExp ? e : W.makeRe(e, n)).test(ps.basename(t));
3607
+ W.isMatch = (t, e, n) => W(e, n)(t);
3608
+ W.parse = (t, e) => Array.isArray(t) ? t.map((n) => W.parse(n, e)) : Be(t, { ...e, fastpaths: !1 });
3609
+ W.scan = (t, e) => Ci(t, e);
3610
+ W.compileRe = (t, e, n = !1, s = !1) => {
3611
+ if (n === !0)
3612
+ return t.output;
3613
+ const r = e || {}, o = r.contains ? "" : "^", i = r.contains ? "" : "$";
3614
+ let a = `${o}(?:${t.output})${i}`;
3615
+ t && t.negated === !0 && (a = `^(?!${a}).*$`);
3616
+ const u = W.toRegex(a, e);
3617
+ return s === !0 && (u.state = t), u;
3618
+ };
3619
+ W.makeRe = (t, e = {}, n = !1, s = !1) => {
3620
+ if (!t || typeof t != "string")
3621
+ throw new TypeError("Expected a non-empty string");
3622
+ let r = { negated: !1, fastpaths: !0 };
3623
+ return e.fastpaths !== !1 && (t[0] === "." || t[0] === "*") && (r.output = Be.fastpaths(t, e)), r.output || (r = Be(t, e)), W.compileRe(r, e, n, s);
3624
+ };
3625
+ W.toRegex = (t, e) => {
3626
+ try {
3627
+ const n = e || {};
3628
+ return new RegExp(t, n.flags || (n.nocase ? "i" : ""));
3629
+ } catch (n) {
3630
+ if (e && e.debug === !0)
3631
+ throw n;
3632
+ return /$^/;
3633
+ }
3634
+ };
3635
+ W.constants = $i;
3636
+ var Pi = W, Ti = Pi;
3637
+ const Di = /* @__PURE__ */ ze(Ti), hs = Fe(fetch), ki = async (t, e) => {
3638
+ const n = new URL(t);
3639
+ n.pathname = n.pathname + (n.pathname.endsWith("/") ? "metapage.json" : "/metapage.json");
3640
+ const r = await (await hs(n.href, {
3641
+ redirect: "follow",
3642
+ retries: 3,
3643
+ retryDelay: 1e3
3644
+ })).json();
3645
+ return await Bn(r, e || Gt);
3646
+ }, Li = async (t, e) => {
3647
+ if (t.startsWith("data:") || t.startsWith("https://docs.google.com"))
3648
+ return;
3649
+ const n = new URL(t);
3650
+ if (n.origin.endsWith(".notion.site"))
3651
+ return;
3652
+ let s = rn(t, "definition");
3653
+ if (s != null && s.version)
3654
+ return Le(s);
3655
+ n.pathname.endsWith("metaframe.json") || (n.pathname = n.pathname + (n.pathname.endsWith("/") ? "metaframe.json" : "/metaframe.json"));
3656
+ try {
3657
+ const r = await hs(n.href, {
3658
+ redirect: "follow",
3659
+ retries: 3,
3660
+ retryDelay: 1e3
3661
+ });
3662
+ if (r.status !== 200)
3663
+ return;
3664
+ const o = await r.json();
3665
+ return await zn(o, e || ye);
3666
+ } catch (r) {
3667
+ console.error(`Error fetching metaframe definition from ${n.href}: ${r}`);
3668
+ return;
3669
+ }
3670
+ }, ao = (t) => t ? !(t != null && t.inputs && Object.keys(t.inputs).length > 0 || t != null && t.outputs && Object.keys(t.outputs).length > 0 || t != null && t.allow || t != null && t.metadata && Object.keys(t.metadata).length > 0) : !0;
3671
+ class ji extends sn.EventEmitter {
3672
+ constructor(e, n, s, r, o, i = !1) {
3673
+ if (super(), this.inputs = {}, this.outputs = {}, this._disposables = [], this._rpcListeners = [], this._loaded = !1, this._onLoaded = [], this._sendInputsAfterRegistration = !1, this._cachedEventInputsUpdate = {
3674
+ iframeId: void 0,
3675
+ inputs: void 0
3676
+ }, this._cachedEventOutputsUpdate = {
3677
+ iframeId: null,
3678
+ inputs: null
3679
+ }, !n.startsWith("data:") && !n.startsWith("http")) {
3680
+ for (; n.startsWith("/"); )
3681
+ n = n.substring(1);
3682
+ n = window.location.protocol + "//" + window.location.hostname + (window.location.port && window.location.port != "" ? ":" + window.location.port : "") + "/" + n;
3683
+ }
3684
+ if (this.url = n, this._metapage = e, this._debug = i, i) {
3685
+ var a = new URL(this.url);
3686
+ a.searchParams.set(Vt.mp_debug, "true"), this.url = a.href;
3687
+ }
3688
+ this.id = s, this._parentId = r, this._color = is(this.id), this._consoleBackgroundColor = o, this._iframe = document.createElement("iframe"), this._iframe.name = this.id;
3689
+ const u = this;
3690
+ this.iframe = new Promise((c) => {
3691
+ be().then(async () => {
3692
+ var l, f, m, g;
3693
+ if (u._iframe) {
3694
+ if ((g = (m = (f = (l = this._metapage) == null ? void 0 : l._definition) == null ? void 0 : f.metaframes) == null ? void 0 : m[this.id]) != null && g.allow)
3695
+ u._iframe.allow = this._metapage._definition.metaframes[this.id].allow, this._debug && this.log(`mf allow=${u._iframe.allow} from this._metapage?._definition`);
3696
+ else {
3697
+ let y = rn(this.url, "definition");
3698
+ if (y = y && (y != null && y.version) ? await Le(y) : void 0, !u._iframe)
3699
+ return;
3700
+ if (y != null && y.allow)
3701
+ u._iframe.allow = y.allow;
3702
+ else {
3703
+ let R = await u.getDefinition();
3704
+ if (this._debug && this.log(`mf metaframeDef=${JSON.stringify(R)}`), R = R && (R != null && R.version) ? await Le(R) : void 0, this._debug && this.log(`mf metaframeDef=${JSON.stringify(R)}`), !u._iframe)
3705
+ return;
3706
+ R && R.allow && (u._iframe.allow = R.allow);
3707
+ }
3708
+ }
3709
+ this._debug && this.log(`mf allow=${u._iframe.allow} from ${this.url}`), u._iframe.src = this.url, c(u._iframe);
3710
+ }
3711
+ });
3712
+ }), this.ack = this.ack.bind(this), this.dispose = this.dispose.bind(this), this.getDefinition = this.getDefinition.bind(this), this.getDefinitionUrl = this.getDefinitionUrl.bind(this), this.log = this.log.bind(this), this.logInternal = this.logInternal.bind(this), this.onInput = this.onInput.bind(this), this.onInputs = this.onInputs.bind(this), this.onOutput = this.onOutput.bind(this), this.onOutputs = this.onOutputs.bind(this), this.register = this.register.bind(this), this.registered = this.registered.bind(this), this.sendInputs = this.sendInputs.bind(this), this.sendOrBufferPostMessage = this.sendOrBufferPostMessage.bind(this), this.sendRpc = this.sendRpc.bind(this), this.sendRpcInternal = this.sendRpcInternal.bind(this), this.setInput = this.setInput.bind(this), this.setInputs = this.setInputs.bind(this), this.setMetapage = this.setMetapage.bind(this), this.setOutput = this.setOutput.bind(this), this.setOutputs = this.setOutputs.bind(this), this.addListenerReturnDisposer = this.addListenerReturnDisposer.bind(this), this.isDisposed = this.isDisposed.bind(this);
3713
+ }
3714
+ addListenerReturnDisposer(e, n) {
3715
+ return super.addListener(e, n), () => {
3716
+ super.removeListener(e, n);
3717
+ };
3718
+ }
3719
+ setMetapage(e) {
3720
+ return this._metapage = e, this;
3721
+ }
3722
+ getDefinitionUrl() {
3723
+ var e = new URL(this.url);
3724
+ return e.pathname = e.pathname + (e.pathname.endsWith("/") ? "metaframe.json" : "/metaframe.json"), e.href;
3725
+ }
3726
+ async getDefinition() {
3727
+ if (this._definition)
3728
+ return this._definition;
3729
+ try {
3730
+ const n = await Li(this.url);
3731
+ if (n)
3732
+ return this._definition = n, this._definition;
3733
+ } catch (n) {
3734
+ var e = this.getDefinitionUrl();
3735
+ this.emit(I.Warning, `Failed to fetch or convert: ${e}
3736
+ Error: ${n != null && n.message ? n == null ? void 0 : n.message : n == null ? void 0 : n.toString()}`);
3737
+ }
3738
+ }
3739
+ setInput(e, n) {
3740
+ console.assert(!!e);
3741
+ var s = {};
3742
+ s[e] = n, this.setInputs(s);
3743
+ }
3744
+ setInputs(e) {
3745
+ this.log({ m: "MetapageIFrameRpcClient", inputs: e });
3746
+ const n = e;
3747
+ if (this.inputs = he(this.inputs, e), this.inputs === n)
3748
+ return this;
3749
+ if (this._loaded || (this._sendInputsAfterRegistration = !0), this._iframe.parentNode && this._loaded && this.sendInputs(e), this.emit(I.Inputs, this.inputs), this._metapage.listenerCount(I.Inputs) > 0) {
3750
+ var s = {};
3751
+ s[this.id] = e, this._metapage.emit(I.Inputs, s);
3752
+ }
3753
+ return this;
3754
+ }
3755
+ setOutput(e, n) {
3756
+ console.assert(!!e);
3757
+ var s = {};
3758
+ s[e] = n, this.setOutputs(s);
3759
+ }
3760
+ setOutputs(e) {
3761
+ const n = e;
3762
+ if (this.outputs = he(this.outputs, e), this.outputs === n)
3763
+ return this;
3764
+ if (this.emit(I.Outputs, e), this._metapage.listenerCount(I.Outputs) > 0) {
3765
+ var s = {};
3766
+ s[this.id] = e, this._metapage.emit(I.Outputs, s);
3767
+ }
3768
+ }
3769
+ onInputs(e) {
3770
+ return this.addListenerReturnDisposer(I.Inputs, e);
3771
+ }
3772
+ onInput(e, n) {
3773
+ var s = function(r) {
3774
+ r.hasOwnProperty(e) && n(r[e]);
3775
+ };
3776
+ return this.addListenerReturnDisposer(I.Inputs, s);
3777
+ }
3778
+ onOutputs(e) {
3779
+ return this.addListenerReturnDisposer(I.Outputs, e);
3780
+ }
3781
+ onOutput(e, n) {
3782
+ var s = function(r) {
3783
+ r.hasOwnProperty(e) && n(r[e]);
3784
+ };
3785
+ return this.addListenerReturnDisposer(I.Outputs, s);
3786
+ }
3787
+ isDisposed() {
3788
+ return this.inputs === void 0;
3789
+ }
3790
+ dispose() {
3791
+ for (super.removeAllListeners(); this._disposables && this._disposables.length > 0; ) {
3792
+ const e = this._disposables.pop();
3793
+ e && e();
3794
+ }
3795
+ this._rpcListeners = void 0, this.inputs = void 0, this.outputs = void 0, this._iframe && this._iframe.parentNode && this._iframe.parentNode.removeChild(this._iframe), this._iframe = void 0, this._bufferMessages = void 0, this._bufferTimeout && (window.clearInterval(this._bufferTimeout), this._bufferTimeout = void 0), this._metapage = void 0;
3796
+ }
3797
+ register() {
3798
+ var e = {
3799
+ iframeId: this.id,
3800
+ parentId: this._parentId,
3801
+ state: {
3802
+ inputs: this.inputs
3803
+ },
3804
+ version: Tn
3805
+ };
3806
+ this.sendRpcInternal(Ot.SetupIframeServerResponse, e);
3807
+ }
3808
+ registered(e) {
3809
+ if (this.log({ m: "MetapageIFrameRpcClient.registered", inputs: this.inputs }), !this._loaded) {
3810
+ if (!e)
3811
+ throw "Cannot register without a version";
3812
+ for (this.version = e, this._loaded = !0; this._onLoaded && this._onLoaded.length > 0; )
3813
+ this._onLoaded.pop()();
3814
+ this._sendInputsAfterRegistration && this.sendInputs(this.inputs);
3815
+ }
3816
+ }
3817
+ async sendInputs(e) {
3818
+ e && (e = await ge(e), !this.isDisposed() && this.sendRpc(Ot.InputsUpdate, {
3819
+ inputs: e,
3820
+ parentId: this._parentId
3821
+ }));
3822
+ }
3823
+ sendRpc(e, n) {
3824
+ var s, r;
3825
+ if ((s = this == null ? void 0 : this._iframe) != null && s.parentNode && this._loaded)
3826
+ this.sendRpcInternal(e, n);
3827
+ else {
3828
+ (r = this == null ? void 0 : this._metapage) == null || r.error("sending rpc later");
3829
+ const o = this;
3830
+ this == null || this._onLoaded.push(() => {
3831
+ o.sendRpcInternal(e, n);
3832
+ });
3833
+ }
3834
+ }
3835
+ ack(e) {
3836
+ if (this._debug) {
3837
+ this.log("⚒ ⚒ ⚒ sending ack from client to frame");
3838
+ var n = {
3839
+ message: e
3840
+ };
3841
+ this.sendRpc(Ot.MessageAck, n);
3842
+ }
3843
+ }
3844
+ log(e) {
3845
+ this._debug && this.logInternal(e);
3846
+ }
3847
+ logInternal(e) {
3848
+ let n;
3849
+ typeof e == "string" ? n = e : typeof e == "string" ? n = e + "" : n = JSON.stringify(e), an(`Metapage[${this._parentId}] Metaframe[${this.id}] ${n}`, this._color, this._consoleBackgroundColor);
3850
+ }
3851
+ sendRpcInternal(e, n) {
3852
+ const s = {
3853
+ id: "_",
3854
+ iframeId: this.id,
3855
+ jsonrpc: "2.0",
3856
+ method: e,
3857
+ params: n,
3858
+ parentId: this._parentId
3859
+ };
3860
+ this._iframe ? this.sendOrBufferPostMessage(s) : this._metapage ? this._metapage.error(`Cannot send to child iframe messageJSON=${JSON.stringify(s).substring(0, 200)}`) : console.error(`Cannot send to child iframe messageJSON=${JSON.stringify(s).substring(0, 200)}`);
3861
+ }
3862
+ sendOrBufferPostMessage(e) {
3863
+ if (this._iframe && this._iframe.contentWindow)
3864
+ this._iframe.contentWindow.postMessage(e, this.url);
3865
+ else if (this._bufferMessages)
3866
+ this._bufferMessages.push(e);
3867
+ else {
3868
+ this._bufferMessages = [e];
3869
+ const n = this;
3870
+ this._bufferTimeout = window.setInterval(function() {
3871
+ n._iframe && n._iframe.contentWindow && (n._bufferMessages.forEach((s) => n._iframe.contentWindow.postMessage(s, n.url)), window.clearInterval(n._bufferTimeout), n._bufferTimeout = void 0, n._bufferMessages = void 0);
3872
+ }, 0);
3873
+ }
3874
+ }
3875
+ }
3876
+ const Mt = C({
3877
+ metaframes: {
3878
+ inputs: {},
3879
+ outputs: {}
3880
+ }
3881
+ }, (t) => t), uo = (t) => wt(t), Ni = (t, e) => !!(!e || e === "**" || t === e || Di.isMatch(t, e)), Hi = "bcbcbc";
3882
+ class it extends ti {
3883
+ static async from(e, n) {
3884
+ if (e == null)
3885
+ throw "Metapage definition cannot be null";
3886
+ if (typeof e == "string")
3887
+ try {
3888
+ e = JSON.parse(e);
3889
+ } catch {
3890
+ throw "Cannot parse into JSON:\n${metaPageDef}";
3891
+ }
3892
+ var s = new it();
3893
+ return s.setDefinition(e);
3894
+ }
3895
+ constructor(e) {
3896
+ super(), this._state = Mt, this._metaframes = C({}, (n) => n), this.debug = Ue(), this._internalReceivedMessageCounter = 0, this._cachedInputLookupMap = C({}, (n) => n), this._inputMap = {}, this._id = e && e.id ? e.id : ei(), this._consoleBackgroundColor = e && e.color ? e.color : Hi, this.addPipe = this.addPipe.bind(this), this.dispose = this.dispose.bind(this), this.addMetaframe = this.addMetaframe.bind(this), this.getInputsFromOutput = this.getInputsFromOutput.bind(this), this.getMetaframe = this.getMetaframe.bind(this), this.getMetaframeIds = this.getMetaframeIds.bind(this), this.getMetaframe = this.getMetaframe.bind(this), this.getMetaframes = this.getMetaframes.bind(this), this.getState = this.getState.bind(this), this.getStateMetaframes = this.getStateMetaframes.bind(this), this.isValidJSONRpcMessage = this.isValidJSONRpcMessage.bind(this), this.log = this.log.bind(this), this.logInternal = this.logInternal.bind(this), this.metaframeIds = this.metaframeIds.bind(this), this.metaframes = this.metaframes.bind(this), this.onMessage = this.onMessage.bind(this), this.onMessageJsonRpc = this.onMessageJsonRpc.bind(this), this.removeAll = this.removeAll.bind(this), this.removeMetaframe = this.removeMetaframe.bind(this), this.setDebugFromUrlParams = this.setDebugFromUrlParams.bind(this), this.setDefinition = this.setDefinition.bind(this), this.setInput = this.setInput.bind(this), this.setInputs = this.setInputs.bind(this), this.setOutputs = this.setOutputs.bind(this), this.onInputs = this.onInputs.bind(this), this.onOutputs = this.onOutputs.bind(this), this.onState = this.onState.bind(this), this.setMetaframeOutputs = this.setMetaframeOutputs.bind(this), this.setInputStateOnlyMetaframeInputValue = this.setInputStateOnlyMetaframeInputValue.bind(this), this.setInputStateOnlyMetaframeInputMap = this.setInputStateOnlyMetaframeInputMap.bind(this), this.setInputStateOnlyMetapageInstanceInputs = this.setInputStateOnlyMetapageInstanceInputs.bind(this), this.setOutputStateOnlyMetaframeInputValue = this.setOutputStateOnlyMetaframeInputValue.bind(this), this.setOutputStateOnlyMetaframeInputMap = this.setOutputStateOnlyMetaframeInputMap.bind(this), this.setOutputStateOnlyMetapageInstanceInputs = this.setOutputStateOnlyMetapageInstanceInputs.bind(this), this.setMetadata = this.setMetadata.bind(this), this.setMetaframeClientInputAndSentClientEvent = this.setMetaframeClientInputAndSentClientEvent.bind(this), this.setState = this.setState.bind(this), this.isDisposed = this.isDisposed.bind(this), this._emitDefinitionEvent = this._emitDefinitionEvent.bind(this), be().then(() => {
3897
+ this.isDisposed() || (window.addEventListener("message", this.onMessage), this.log("Initialized"));
3898
+ });
3899
+ }
3900
+ isDisposed() {
3901
+ return this._metaframes === void 0;
3902
+ }
3903
+ addListenerReturnDisposer(e, n) {
3904
+ return super.addListener(e, n), () => {
3905
+ super.removeListener(e, n);
3906
+ };
3907
+ }
3908
+ onInputs(e) {
3909
+ return this.addListenerReturnDisposer(I.Inputs, e);
3910
+ }
3911
+ onOutputs(e) {
3912
+ return this.addListenerReturnDisposer(I.Outputs, e);
3913
+ }
3914
+ onState(e) {
3915
+ return this.addListenerReturnDisposer(I.State, e);
3916
+ }
3917
+ setDebugFromUrlParams() {
3918
+ const e = new URL(window.location.href);
3919
+ return this.debug = ["debug", "mp_debug"].reduce((n, s) => n || e.searchParams.get(s) === "true" || e.searchParams.get(s) === "1", !1), this;
3920
+ }
3921
+ getState() {
3922
+ return this._state;
3923
+ }
3924
+ setState(e) {
3925
+ this._state = C(e, (n) => n), this.getMetaframeIds().forEach((n) => {
3926
+ var s, r;
3927
+ (s = this.getMetaframe(n)) == null || s.setInputs(this._state.metaframes.inputs[n]), (r = this.getMetaframe(n)) == null || r.setOutputs(this._state.metaframes.outputs[n]);
3928
+ }), this.listenerCount(I.State) > 0 && Mt !== this._state && this.emit(I.State, this._state);
3929
+ }
3930
+ getStateMetaframes() {
3931
+ return this._state.metaframes;
3932
+ }
3933
+ getDefinition() {
3934
+ return this._definition;
3935
+ }
3936
+ async setDefinition(e, n) {
3937
+ if (!e.version)
3938
+ throw "Metapage definition must have a version";
3939
+ const s = await js(e);
3940
+ if (this.isDisposed())
3941
+ return this;
3942
+ s.metaframes && Object.keys(s.metaframes).forEach((o) => {
3943
+ var i = s.metaframes[o];
3944
+ if (typeof i != "object")
3945
+ throw this.emitErrorMessage(`Metaframe "${o}" is not an object`), `Metaframe "${o}" is not an object`;
3946
+ if (!i.url)
3947
+ throw this.emitErrorMessage(`Metaframe "${o}" missing field: url`), `Metaframe "${o}" missing field: url`;
3948
+ });
3949
+ const r = this._definition;
3950
+ return this._definition = s, Object.keys(this._metaframes).forEach((o) => {
3951
+ (!s.metaframes || !s.metaframes[o]) && this.removeMetaframe(o);
3952
+ }), n && (this._state = C(n, (o) => o)), s.metaframes && Object.keys(s.metaframes).forEach((o) => {
3953
+ if (!this._metaframes.hasOwnProperty(o)) {
3954
+ const i = s.metaframes[o];
3955
+ this.addMetaframe(o, i);
3956
+ }
3957
+ }), r !== rs && window.setTimeout(() => {
3958
+ !this.isDisposed() && s === this._definition && (this._emitDefinitionEvent(), n && this.listenerCount(I.State) > 0 && Mt !== this._state && this.emit(I.State, this._state));
3959
+ }, 0), this;
3960
+ }
3961
+ setMetadata(e) {
3962
+ this._definition = C(this._definition, (n) => {
3963
+ n.meta = e;
3964
+ }), this._emitDefinitionEvent();
3965
+ }
3966
+ _emitDefinitionEvent() {
3967
+ if (this.listenerCount(I.Definition) > 0) {
3968
+ const e = {
3969
+ definition: this._definition,
3970
+ metaframes: this._metaframes
3971
+ };
3972
+ this.emit(I.Definition, e);
3973
+ }
3974
+ }
3975
+ addPipe(e, n) {
3976
+ this._inputMap = C(this._inputMap, (s) => {
3977
+ s[e] || (s[e] = []), s[e].push(n);
3978
+ });
3979
+ }
3980
+ removeMetaframe(e) {
3981
+ this._metaframes[e] && (this._metaframes[e].dispose(), this._metaframes = C(this._metaframes, (n) => {
3982
+ delete n[e];
3983
+ }), this._state = C(this._state, (n) => {
3984
+ delete n.metaframes.inputs[e], delete n.metaframes.outputs[e];
3985
+ }), this._inputMap = C(this._inputMap, (n) => {
3986
+ delete n[e], Object.keys(n).forEach((s) => {
3987
+ const r = n[s];
3988
+ let o = 0;
3989
+ for (; o <= r.length; )
3990
+ r[o] && r[o].metaframe === e ? r.splice(o, 1) : o++;
3991
+ });
3992
+ }), this._cachedInputLookupMap = C({}, (n) => n));
3993
+ }
3994
+ removeAll() {
3995
+ Object.keys(this._metaframes).forEach((e) => this._metaframes[e].dispose()), this._metaframes = C({}, (e) => e), this._state = Mt, this._inputMap = C({}, (e) => e), this._cachedInputLookupMap = C({}, (e) => e);
3996
+ }
3997
+ metaframes() {
3998
+ return this.getMetaframes();
3999
+ }
4000
+ metaframeIds() {
4001
+ return this.getMetaframeIds();
4002
+ }
4003
+ getMetaframeIds() {
4004
+ return Object.keys(this._metaframes);
4005
+ }
4006
+ getMetaframes() {
4007
+ return this._metaframes;
4008
+ }
4009
+ getMetaframe(e) {
4010
+ var n;
4011
+ return (n = this == null ? void 0 : this._metaframes) == null ? void 0 : n[e];
4012
+ }
4013
+ addMetaframe(e, n) {
4014
+ if (!e)
4015
+ throw "addMetaframe missing metaframeId";
4016
+ if (!n)
4017
+ throw "addMetaframe missing definition";
4018
+ if (this._metaframes[e])
4019
+ throw this.emitErrorMessage(`Existing metaframe for id=${e}`), `Existing metaframe for id=${e}`;
4020
+ if (!n.url)
4021
+ throw this.emitErrorMessage(`Metaframe definition missing url id=${e}`), `Metaframe definition missing url id=${e}`;
4022
+ var s = new ji(this, n.url, e, this._id, this._consoleBackgroundColor, this.debug).setMetapage(this);
4023
+ return this._metaframes = C(this._metaframes, (r) => {
4024
+ r[e] = s;
4025
+ }), s.addListener(I.Error, (r) => {
4026
+ this.emit(I.Error, {
4027
+ metaframeId: s.id,
4028
+ metaframeUrl: s.url,
4029
+ error: r
4030
+ });
4031
+ }), n.inputs && n.inputs.forEach((r) => this.addPipe(e, r)), s.setInputs(this._state.metaframes.inputs[e]), s;
4032
+ }
4033
+ dispose() {
4034
+ this.log("disposing"), super.removeAllListeners(), window.removeEventListener("message", this.onMessage), this._metaframes && Object.keys(this._metaframes).forEach((e) => this._metaframes[e].dispose()), this._id = void 0, this._metaframes = void 0, this._state = void 0, this._cachedInputLookupMap = void 0, this._inputMap = void 0;
4035
+ }
4036
+ log(e, n, s) {
4037
+ this.debug && this.logInternal(e, n, s);
4038
+ }
4039
+ error(e) {
4040
+ this.logInternal(e, "f00", this._consoleBackgroundColor), this.emitErrorMessage(`${e}`);
4041
+ }
4042
+ emitErrorMessage(e) {
4043
+ this.emit(I.Error, e);
4044
+ }
4045
+ getInputsFromOutput(e, n) {
4046
+ return this._cachedInputLookupMap[e] || (this._cachedInputLookupMap = C(this._cachedInputLookupMap, (s) => {
4047
+ s[e] = C({}, (r) => r);
4048
+ })), this._cachedInputLookupMap[e][n] || (this._cachedInputLookupMap = C(this._cachedInputLookupMap, (s) => {
4049
+ var r = [];
4050
+ s[e][n] = r, Object.keys(this._inputMap).forEach((o) => {
4051
+ o !== e && this._inputMap[o].forEach((i) => {
4052
+ if (i.metaframe === e && Ni(n, i.source)) {
4053
+ var a = i.target || "";
4054
+ !i.target || i.target.startsWith("*") || i.target === "" ? a = n : a && a.endsWith("/") && (a = a + n), r.push({ metaframe: o, pipe: a });
4055
+ }
4056
+ });
4057
+ });
4058
+ })), this._cachedInputLookupMap[e][n];
4059
+ }
4060
+ isValidJSONRpcMessage(e) {
4061
+ if (e.jsonrpc !== "2.0")
4062
+ return !1;
4063
+ switch (e.method) {
4064
+ case q.SetupIframeClientRequest:
4065
+ return !0;
4066
+ default:
4067
+ var s = e.iframeId;
4068
+ return s && e.parentId === this._id && !!this._metaframes[s];
4069
+ }
4070
+ }
4071
+ setInput(e, n, s) {
4072
+ var r, o;
4073
+ typeof e == "object" ? this.setInputStateOnlyMetapageInstanceInputs(e) : typeof n == "string" ? this.setInputStateOnlyMetaframeInputValue(e, n, s) : this.setInputStateOnlyMetaframeInputMap(e, n || {}), this.setMetaframeClientInputAndSentClientEvent(e, n, s), (this.listenerCount(I.State) > 0 || this.listenerCount(I.Inputs) > 0) && Mt !== this._state && (this.emit(I.State, this._state), this.emit(I.Inputs, (o = (r = this._state) == null ? void 0 : r.metaframes) == null ? void 0 : o.inputs));
4074
+ }
4075
+ setMetaframeClientInputAndSentClientEvent(e, n, s) {
4076
+ if (typeof e == "object") {
4077
+ if (n || s)
4078
+ throw "bad arguments, see API docs";
4079
+ const r = e;
4080
+ Object.keys(r).forEach((o) => {
4081
+ var i = o, a = r[i];
4082
+ if (typeof a != "object")
4083
+ throw "bad arguments, see API docs";
4084
+ var u = this._metaframes[i];
4085
+ u ? u.setInputs(a) : this.error("No iframe id=$metaframeId");
4086
+ });
4087
+ } else if (typeof e == "string") {
4088
+ const r = this._metaframes[e];
4089
+ if (r == null && this.error(`No iframe id=${e}`), typeof n == "string")
4090
+ r.setInput(n, s);
4091
+ else if (typeof n == "object")
4092
+ r.setInputs(n);
4093
+ else
4094
+ throw "bad arguments, see API docs";
4095
+ } else
4096
+ throw "bad arguments, see API docs";
4097
+ }
4098
+ setInputs(e, n, s) {
4099
+ this.setInput(e, n, s);
4100
+ }
4101
+ setOutputStateOnlyMetapageInstanceInputs(e) {
4102
+ this._setStateOnlyMetaframes(!1, e);
4103
+ }
4104
+ setOutputStateOnlyMetaframeInputValue(e, n, s) {
4105
+ this._setStateOnlyMetaframeInputValue(!1, e, n, s);
4106
+ }
4107
+ setOutputStateOnlyMetaframeInputMap(e, n) {
4108
+ this._setStateOnlyMetaframeInputMap(!1, e, n);
4109
+ }
4110
+ setInputStateOnlyMetapageInstanceInputs(e) {
4111
+ this._setStateOnlyMetaframes(!0, e);
4112
+ }
4113
+ setInputStateOnlyMetaframeInputValue(e, n, s) {
4114
+ this._setStateOnlyMetaframeInputValue(!0, e, n, s);
4115
+ }
4116
+ setInputStateOnlyMetaframeInputMap(e, n) {
4117
+ this._setStateOnlyMetaframeInputMap(!0, e, n);
4118
+ }
4119
+ _setStateOnlyMetaframeInputValue(e, n, s, r) {
4120
+ this._state = C(this._state, (o) => {
4121
+ if (!this._metaframes.hasOwnProperty(n))
4122
+ throw `No metaframe: ${n}`;
4123
+ o.metaframes || (o.metaframes = { inputs: {}, outputs: {} }), e ? o.metaframes.inputs || (o.metaframes.inputs = {}) : o.metaframes.outputs || (o.metaframes.outputs = {});
4124
+ let a = e ? o.metaframes.inputs : o.metaframes.outputs;
4125
+ a = a || {}, a[n] = a[n] ? a[n] : {}, r === void 0 ? delete a[n][s] : a[n][s] = r;
4126
+ });
4127
+ }
4128
+ _setStateOnlyMetaframeInputMap(e, n, s) {
4129
+ !s || Object.keys(s).length === 0 || (this._state = C(this._state, (r) => {
4130
+ if (!this._metaframes.hasOwnProperty(n))
4131
+ throw `No metaframe: ${n}`;
4132
+ let i = e ? r.metaframes.inputs : r.metaframes.outputs;
4133
+ i[n] = i[n] ? i[n] : {}, Object.keys(s).forEach((a) => {
4134
+ s[a] === void 0 ? delete i[n][a] : i[n][a] = s[a];
4135
+ });
4136
+ }));
4137
+ }
4138
+ _setStateOnlyMetaframes(e, n) {
4139
+ !n || Object.keys(n).length === 0 || (this._state = C(this._state, (s) => {
4140
+ Object.keys(n).forEach((r) => {
4141
+ var o = n[r];
4142
+ if (typeof o != "object")
4143
+ throw "Object values must be objects";
4144
+ if (!this._metaframes.hasOwnProperty(r))
4145
+ throw "No metaframe: ${metaframeId}";
4146
+ const a = e ? s.metaframes.inputs : s.metaframes.outputs;
4147
+ a[r] = a[r] ? a[r] : {}, Object.keys(o).forEach((u) => {
4148
+ o[u] === void 0 ? delete a[r][u] : a[r][u] = o[u];
4149
+ });
4150
+ });
4151
+ }));
4152
+ }
4153
+ setMetaframeOutputs(e, n) {
4154
+ this.onMessageJsonRpc({
4155
+ iframeId: e,
4156
+ parentId: this._id,
4157
+ jsonrpc: "2.0",
4158
+ method: q.OutputsUpdate,
4159
+ id: "_",
4160
+ params: n
4161
+ });
4162
+ }
4163
+ setOutputs(e) {
4164
+ if (this._metaframes)
4165
+ for (const n in e)
4166
+ this.setMetaframeOutputs(n, e[n]);
4167
+ }
4168
+ onMessage(e) {
4169
+ if (typeof e.data == "object") {
4170
+ const n = e.data;
4171
+ if (!this.isValidJSONRpcMessage(n))
4172
+ return;
4173
+ this.onMessageJsonRpc(n);
4174
+ }
4175
+ }
4176
+ onMessageJsonRpc(e) {
4177
+ var n = e.method;
4178
+ const s = e.iframeId;
4179
+ if (!s || n !== "SetupIframeClientRequest" && e.parentId !== this._id)
4180
+ return;
4181
+ const r = this.getMetaframe(s);
4182
+ if (r) {
4183
+ switch (e._messageCount = ++this._internalReceivedMessageCounter, this.debug && this.log(`processing ${JSON.stringify(e, null, " ").substring(0, 500)}`), n) {
4184
+ case q.SetupIframeClientRequest:
4185
+ r.register();
4186
+ break;
4187
+ case q.SetupIframeServerResponseAck:
4188
+ if (r) {
4189
+ const c = e.params;
4190
+ r.registered(c.version);
4191
+ }
4192
+ break;
4193
+ case q.OutputsUpdate:
4194
+ const u = e.params;
4195
+ if (!u || Object.keys(u).length === 0)
4196
+ break;
4197
+ if (this._metaframes[s]) {
4198
+ var o = this._metaframes[s];
4199
+ this.setOutputStateOnlyMetaframeInputMap(s, u), o.setOutputs(u);
4200
+ var i = !1;
4201
+ const c = Object.keys(u), l = {};
4202
+ c.forEach((f, m) => {
4203
+ const g = this.getInputsFromOutput(s, f);
4204
+ g.length > 0 && g.forEach((y) => {
4205
+ l[y.metaframe] || (l[y.metaframe] = {}), l[y.metaframe][y.pipe] = u[f], i = !0;
4206
+ });
4207
+ }), i && (this.setInputStateOnlyMetapageInstanceInputs(l), Object.keys(l).forEach((f) => {
4208
+ this._metaframes[f].setInputs(l[f]);
4209
+ })), this.listenerCount(I.State) > 0 && Mt !== this._state && this.emit(I.State, this._state), this.debug && o.ack({ jsonrpc: e, state: this._state });
4210
+ } else
4211
+ this.error(`missing metaframe=${s}`);
4212
+ break;
4213
+ case q.InputsUpdate:
4214
+ var a = e.params;
4215
+ this.debug && this.log(`inputs ${JSON.stringify(a)} from ${s}`), this._metaframes[s] ? (this.setInputStateOnlyMetaframeInputMap(s, a), this._metaframes[s].setInputs(a), this.listenerCount(I.State) > 0 && Mt !== this._state && this.emit(I.State, this._state), this.debug && this._metaframes[s].ack({
4216
+ jsonrpc: e,
4217
+ state: this._state
4218
+ })) : (console.error(`InputsUpdate failed no metaframe id: "${s}"`), this.error(`InputsUpdate failed no metaframe id: "${s}"`));
4219
+ break;
4220
+ case q.HashParamsUpdate:
4221
+ if (r) {
4222
+ const c = e.params, l = new URL(r.url);
4223
+ l.hash = c.hash, r.url = l.href, this._definition = C(this._definition, (f) => {
4224
+ f.metaframes[c.metaframe].url = l.href;
4225
+ }), this._emitDefinitionEvent();
4226
+ }
4227
+ break;
4228
+ default:
4229
+ this.debug && this.log(`Unknown RPC method: "${n}"`);
4230
+ }
4231
+ this.listenerCount(I.Message) > 0 && this.emit(I.Message, e);
4232
+ }
4233
+ }
4234
+ logInternal(e, n, s) {
4235
+ s = s || this._consoleBackgroundColor;
4236
+ let r;
4237
+ typeof e == "string" ? r = e : typeof e == "number" ? r = e + "" : r = JSON.stringify(e), r = this._id ? `Metapage[${this._id}] ${r}` : r, an(r, n, s);
4238
+ }
4239
+ }
4240
+ it.version = Tn;
4241
+ it.DEFINITION = I.Definition;
4242
+ it.ERROR = I.Error;
4243
+ it.INPUTS = I.Inputs;
4244
+ it.MESSAGE = I.Message;
4245
+ it.OUTPUTS = I.Outputs;
4246
+ it.STATE = I.State;
4247
+ it.deserializeInputs = Bt;
4248
+ it.serializeInputs = ge;
4249
+ function fn(t) {
4250
+ return t.startsWith("data:") ? t.includes("type=metapage-divider") : !1;
4251
+ }
4252
+ function Ui(t) {
4253
+ const e = JSON.parse(JSON.stringify(t));
4254
+ e.meta || (e.meta = {}), e.meta.layouts || (e.meta.layouts = {}), e.meta.layouts["react-grid-layout"] || (e.meta.layouts["react-grid-layout"] = {
4255
+ docs: "https://www.npmjs.com/package/react-grid-layout",
4256
+ props: {
4257
+ cols: 12,
4258
+ margin: [20, 40],
4259
+ rowHeight: 100,
4260
+ containerPadding: [5, 5]
4261
+ },
4262
+ layout: []
4263
+ });
4264
+ const n = e.meta.layouts["react-grid-layout"];
4265
+ if (e.metaframes) {
4266
+ Object.keys(e.metaframes).forEach((r) => {
4267
+ if (!n.layout.some((o) => o.i === r)) {
4268
+ const o = n.layout.length > 0 ? Math.max(...n.layout.map((i) => (i.y || 0) + (i.h || 2))) : 0;
4269
+ n.layout.push({
4270
+ i: r,
4271
+ x: 0,
4272
+ y: o,
4273
+ w: n.props.cols,
4274
+ h: fn(e.metaframes[r].url) ? 1 : 3
4275
+ });
4276
+ }
4277
+ });
4278
+ const s = new Set(Object.keys(e.metaframes));
4279
+ n.layout = n.layout.filter((r) => s.has(r.i)), n.layout.forEach((r) => {
4280
+ r.x = r.x || 0, r.y = r.y || 0, r.w = r.w || 1, r.h = r.h || 1;
4281
+ });
4282
+ }
4283
+ return e;
4284
+ }
4285
+ const Bi = (t) => {
4286
+ var c, l, f;
4287
+ const e = (l = (c = t == null ? void 0 : t.meta) == null ? void 0 : c.layouts) == null ? void 0 : l["react-grid-layout"], n = e == null ? void 0 : e.layout;
4288
+ if (!e || !n)
4289
+ throw new Error("No valid layout found in metapage definition");
4290
+ const s = /* @__PURE__ */ new Set(), r = n.map((m, g) => {
4291
+ const y = t.metaframes[m.i];
4292
+ return y && fn(y.url) ? { index: g, y: m.y, id: m.i } : null;
4293
+ }).filter((m) => m !== null);
4294
+ if (r.length > 0) {
4295
+ const m = r.reduce((y, R) => R.y < y.y ? R : y), g = ((f = n.find((y) => y.i === m.id)) == null ? void 0 : f.y) ?? 0;
4296
+ n.forEach((y) => {
4297
+ y.y >= g && s.add(y.i);
4298
+ });
4299
+ }
4300
+ const o = Object.keys(t.metaframes).filter((m) => !s.has(m)), i = Object.keys(t.metaframes).filter((m) => s.has(m));
4301
+ let a = n.filter((m) => o.includes(m.i));
4302
+ a.sort((m, g) => m.y !== g.y ? m.y - g.y : m.x - g.x);
4303
+ const u = a.reduce((m, g) => Math.max(m, g.y + g.h), 0);
4304
+ return {
4305
+ visibleLayoutItems: a,
4306
+ hiddenMetaframeIds: new Set(i),
4307
+ visibleMetaframeIds: new Set(o),
4308
+ totalVisibleGridHeight: u
4309
+ };
4310
+ };
4311
+ async function co(t) {
4312
+ var T, S, D, j;
4313
+ let { url: e, definition: n, onOutputs: s, rootDiv: r, options: o = {} } = t;
4314
+ if (!e && !n)
4315
+ throw new Error("Either url or definition must be provided");
4316
+ if (e && n)
4317
+ throw new Error("Either url or definition must be provided, not both");
4318
+ if (e && (n = await ki(e)), !n)
4319
+ throw new Error("Failed to fetch metapage definition");
4320
+ n = Ui(n), n = await Fi(n), await be();
4321
+ const i = new it();
4322
+ i.debug = o.debug || !1;
4323
+ try {
4324
+ await i.setDefinition(JSON.parse(JSON.stringify(n)));
4325
+ } catch (_) {
4326
+ throw i.dispose(), new Error(`Failed to set metapage definition: ${_}`);
4327
+ }
4328
+ const a = [];
4329
+ s && a.push(i.addListenerReturnDisposer(I.Outputs, s));
4330
+ const u = (S = (T = n == null ? void 0 : n.meta) == null ? void 0 : T.layouts) == null ? void 0 : S["react-grid-layout"], c = u == null ? void 0 : u.layout;
4331
+ if (!u || !c)
4332
+ throw new Error("No valid layout found in metapage definition");
4333
+ let { visibleLayoutItems: l, hiddenMetaframeIds: f, visibleMetaframeIds: m } = Bi(i.getDefinition());
4334
+ if (l.length === 0)
4335
+ return {
4336
+ metapage: i,
4337
+ setInputs: (_) => {
4338
+ i.isDisposed() || i.setInputs(_);
4339
+ },
4340
+ setOutputs: (_) => {
4341
+ i.isDisposed() || i.setOutputs(_);
4342
+ },
4343
+ dispose: () => {
4344
+ a.forEach((_) => _()), i.dispose();
4345
+ }
4346
+ };
4347
+ l.sort((_, M) => _.y !== M.y ? _.y - M.y : _.x - M.x);
4348
+ const g = {
4349
+ display: "grid",
4350
+ gridTemplateColumns: "repeat(1, 1fr)",
4351
+ gridAutoRows: "1fr",
4352
+ gap: `${((D = u.props.margin) == null ? void 0 : D[0]) || 10}px`,
4353
+ width: "100%",
4354
+ height: "100%",
4355
+ maxHeight: "100%",
4356
+ padding: ((j = u.props.containerPadding) == null ? void 0 : j[0]) || 0,
4357
+ minHeight: 0,
4358
+ alignContent: "start",
4359
+ alignItems: "start",
4360
+ overflow: "hidden"
4361
+ }, y = {
4362
+ width: "100%",
4363
+ height: "100%",
4364
+ overflow: "hidden",
4365
+ display: "flex",
4366
+ flexDirection: "column"
4367
+ }, R = document.createElement("div");
4368
+ Object.assign(R.style, y);
4369
+ const O = document.createElement("div");
4370
+ Object.assign(O.style, g);
4371
+ const E = [];
4372
+ for (const _ of m) {
4373
+ const M = c.find((h) => h.i === _);
4374
+ if (!M)
4375
+ continue;
4376
+ const p = i.getMetaframes()[_], U = await p.iframe;
4377
+ if (!p)
4378
+ continue;
4379
+ E.push(M);
4380
+ const V = {
4381
+ gridColumn: `${M.x + 1} / span ${M.w}`,
4382
+ gridRow: `${M.y + 1} / span ${M.h}`,
4383
+ overflow: "hidden",
4384
+ width: "100%",
4385
+ height: "100%",
4386
+ border: o.hideFrameBorders ? "none" : "1px solid #e0e0e0",
4387
+ position: "relative",
4388
+ alignSelf: "stretch",
4389
+ justifySelf: "stretch"
4390
+ }, N = document.createElement("div");
4391
+ Object.assign(N.style, V), N.appendChild(U), O.appendChild(N);
4392
+ }
4393
+ const w = Math.max(...E.map((_) => _.x + _.w));
4394
+ Math.max(...E.map((_) => _.y + _.h)), O.style.gridTemplateColumns = `repeat(${Math.max(1, w)}, 1fr)`;
4395
+ const A = document.createElement("div");
4396
+ A.style.position = "absolute", A.style.top = "-9999px", A.style.left = "-9999px", A.style.width = "1px", A.style.height = "1px", A.style.overflow = "hidden", A.style.pointerEvents = "none";
4397
+ for (const _ of Object.keys(i.getMetaframes()).filter((M) => f.has(M))) {
4398
+ const M = i.getMetaframes()[_];
4399
+ if (!M)
4400
+ continue;
4401
+ const p = document.createElement("div");
4402
+ p.setAttribute("data-metaframe-id", _), p.style.width = "100px", p.style.height = "100px";
4403
+ let U;
4404
+ M.iframe ? U = await M.iframe : (U = document.createElement("iframe"), U.src = M.url, U.style.border = "none", U.style.width = "100%", U.style.height = "100%"), p.appendChild(U), A.appendChild(p);
4405
+ }
4406
+ return R.appendChild(O), R.appendChild(A), r.appendChild(R), {
4407
+ metapage: i,
4408
+ setInputs: (_) => {
4409
+ i.isDisposed() || i.setInputs(_);
4410
+ },
4411
+ setOutputs: (_) => {
4412
+ i.isDisposed() || i.setOutputs(_);
4413
+ },
4414
+ dispose: () => {
4415
+ a.forEach((_) => _()), i.dispose(), R.parentNode && R.parentNode.removeChild(R);
4416
+ }
4417
+ };
4418
+ }
4419
+ const lo = (t, e) => {
4420
+ var i, a, u;
4421
+ const n = (a = (i = t == null ? void 0 : t.meta) == null ? void 0 : i.layouts) == null ? void 0 : a["react-grid-layout"], s = n == null ? void 0 : n.layout;
4422
+ if (!n || !s)
4423
+ throw new Error("No valid layout found in metapage definition");
4424
+ const r = /* @__PURE__ */ new Set(), o = s.map((c, l) => {
4425
+ var m;
4426
+ const f = (m = t == null ? void 0 : t.metaframes) == null ? void 0 : m[c.i];
4427
+ return f && fn(f.url) ? { index: l, y: c.y, id: c.i } : null;
4428
+ }).filter((c) => c !== null);
4429
+ if (o.length > 0) {
4430
+ const c = o.reduce((f, m) => m.y < f.y ? m : f), l = ((u = s.find((f) => f.i === c.id)) == null ? void 0 : u.y) ?? 0;
4431
+ s.forEach((f) => {
4432
+ f.y >= l && r.add(f.i);
4433
+ });
4434
+ }
4435
+ return r.has(e);
4436
+ }, zi = (t) => {
4437
+ var n;
4438
+ if (!t)
4439
+ return;
4440
+ typeof t == "string" && (t.startsWith("/") && (t = "https://metapage.io" + t), t = new URL(t));
4441
+ let e = (n = /\/m?f\/([0-9a-zA-Z-]{3,})\/?(metaframe\.json)?.*$/g.exec(t.pathname)) == null ? void 0 : n[1];
4442
+ return e || (t.searchParams.get("mfk") ?? void 0);
4443
+ }, Fi = async (t) => {
4444
+ if (!(t != null && t.metaframes))
4445
+ return t;
4446
+ for (const [e, n] of Object.entries(t.metaframes)) {
4447
+ if (!(n.url.startsWith("https://metapage.io/mf/") || n.url.startsWith("https://metapage.io/f/")))
4448
+ continue;
4449
+ const s = zi(n.url);
4450
+ if (!s)
4451
+ continue;
4452
+ const r = await fetch(`https://metapage.io/f/${s}/definition.json`).then((o) => o.json());
4453
+ r != null && r.url && (n.url = r == null ? void 0 : r.url);
4454
+ }
4455
+ return t;
4456
+ };
4457
+ export {
4458
+ rs as INITIAL_NULL_METAPAGE_DEFINITION,
4459
+ Zi as INTERNAL_ERROR,
4460
+ Qi as INVALID_PARAMS,
4461
+ Yi as INVALID_REQUEST,
4462
+ q as JsonRpcMethodsFromChild,
4463
+ Ot as JsonRpcMethodsFromParent,
4464
+ Vi as METAFRAME_JSON_FILE,
4465
+ Gi as METAPAGE_KEY_DEFINITION,
4466
+ Ji as METAPAGE_KEY_STATE,
4467
+ qi as METHOD_NOT_FOUND,
4468
+ ct as Metaframe,
4469
+ G as MetaframeEvents,
4470
+ ft as MetaframeLoadingState,
4471
+ ye as MetaframeVersionCurrent,
4472
+ pn as MetaframeVersionsAll,
4473
+ it as Metapage,
4474
+ I as MetapageEvents,
4475
+ Vt as MetapageHashParams,
4476
+ ji as MetapageIFrameRpcClient,
4477
+ ti as MetapageShared,
4478
+ Gt as MetapageVersionCurrent,
4479
+ hn as MetapageVersionsAll,
4480
+ Xi as PARSE_ERROR,
4481
+ ys as VERSION_METAFRAME,
4482
+ Tn as VERSION_METAPAGE,
4483
+ Ws as convertMetaframeDefinitionToCurrentVersion,
4484
+ zn as convertMetaframeDefinitionToVersion,
4485
+ Le as convertMetaframeJsonToCurrentVersion,
4486
+ js as convertMetapageDefinitionToCurrentVersion,
4487
+ Bn as convertMetapageDefinitionToVersion,
4488
+ Bt as deserializeInputs,
4489
+ on as generateId,
4490
+ so as generateMetaframeId,
4491
+ ei as generateMetapageId,
4492
+ ro as generateNonce,
4493
+ uo as getLibraryVersionMatching,
4494
+ ot as getMatchingMetaframeVersion,
4495
+ wt as getMatchingMetapageVersion,
4496
+ Li as getMetaframeDefinitionFromUrl,
4497
+ ki as getMetapageDefinitionFromUrl,
4498
+ eo as getUrlParam,
4499
+ no as getUrlParamDebug,
4500
+ Bi as getVisibleGridLayoutData,
4501
+ ni as hashCode,
4502
+ si as intToRGB,
4503
+ Ue as isDebugFromUrlsParams,
4504
+ ao as isEmptyMetaframeDefinition,
4505
+ Zr as isIframe,
4506
+ to as isJsonRpcId,
4507
+ fn as isMetaframeDivider,
4508
+ lo as isMetaframeHidden,
4509
+ Ae as isPageLoaded,
4510
+ an as log,
4511
+ Ni as matchPipe,
4512
+ he as merge,
4513
+ io as metapageAllSha256Hash,
4514
+ oo as metapageOnlyEssentailSha256Hash,
4515
+ Js as normalizeHashParams,
4516
+ be as pageLoaded,
4517
+ Wi as possiblyDeserializeDatarefToFile,
4518
+ nn as possiblyDeserializeDatarefToValue,
4519
+ Er as possiblySerializeValueToDataref,
4520
+ co as renderMetapage,
4521
+ ge as serializeInputs,
4522
+ is as stringToRgb,
4523
+ Ki as valueToFile
4524
+ };
4525
+ //# sourceMappingURL=index.js.map