@metapages/metapage 1.8.12 → 1.8.15

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