@metapages/metapage 1.9.1 → 1.9.2

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