gofront 1.6.0 → 1.7.0

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 (80) hide show
  1. package/README.md +35 -39
  2. package/package.json +37 -4
  3. package/src/backend/js/expressions.js +559 -144
  4. package/src/backend/js/index.js +174 -49
  5. package/src/backend/js/runtime.js +1518 -54
  6. package/src/backend/js/statements.js +91 -73
  7. package/src/backend/js/stdlib/base64.js +12 -0
  8. package/src/backend/js/stdlib/binary.js +102 -0
  9. package/src/backend/js/stdlib/bits.js +15 -1
  10. package/src/backend/js/stdlib/builder.js +28 -9
  11. package/src/backend/js/stdlib/bytes.js +75 -18
  12. package/src/backend/js/stdlib/errors.js +25 -1
  13. package/src/backend/js/stdlib/fmt.js +70 -13
  14. package/src/backend/js/stdlib/hex.js +17 -0
  15. package/src/backend/js/stdlib/html.js +1 -1
  16. package/src/backend/js/stdlib/index.js +28 -0
  17. package/src/backend/js/stdlib/io.js +105 -3
  18. package/src/backend/js/stdlib/json.js +972 -0
  19. package/src/backend/js/stdlib/math.js +13 -1
  20. package/src/backend/js/stdlib/path.js +18 -4
  21. package/src/backend/js/stdlib/rand.js +10 -5
  22. package/src/backend/js/stdlib/sha256.js +12 -0
  23. package/src/backend/js/stdlib/simd.js +24 -0
  24. package/src/backend/js/stdlib/slices.js +52 -26
  25. package/src/backend/js/stdlib/strconv.js +21 -5
  26. package/src/backend/js/stdlib/strings.js +148 -15
  27. package/src/backend/js/stdlib/sync.js +13 -0
  28. package/src/backend/js/stdlib/time.js +90 -19
  29. package/src/backend/js/stdlib/unicode.js +2 -2
  30. package/src/backend/wasm/boundary.js +1225 -41
  31. package/src/backend/wasm/const-fold.js +205 -0
  32. package/src/backend/wasm/emit-builtins.js +220 -76
  33. package/src/backend/wasm/emit-exprs.js +475 -276
  34. package/src/backend/wasm/emit-maps.js +144 -8
  35. package/src/backend/wasm/emit-stdlib.js +12 -3005
  36. package/src/backend/wasm/emit-stmts.js +264 -270
  37. package/src/backend/wasm/emit.js +124 -87
  38. package/src/backend/wasm/encode.js +140 -29
  39. package/src/backend/wasm/index.js +1001 -32
  40. package/src/backend/wasm/optimize.js +17 -6
  41. package/src/backend/wasm/stdlib/bytes.js +5039 -0
  42. package/src/backend/wasm/stdlib/core.js +8903 -0
  43. package/src/backend/wasm/stdlib/index.js +43 -0
  44. package/src/backend/wasm/stdlib/io.js +2161 -0
  45. package/src/backend/wasm/stdlib/packages.js +2400 -0
  46. package/src/backend/wasm/stdlib/pure.js +720 -0
  47. package/src/backend/wasm/stdlib/simd.js +234 -0
  48. package/src/backend/wasm/stdlib/time.js +1200 -0
  49. package/src/backend/wasm/types.js +174 -1
  50. package/src/backend/wasm/wat.js +37 -0
  51. package/src/cli-core.js +1 -1
  52. package/src/compiler.js +18 -4
  53. package/src/dts-parser.js +150 -140
  54. package/src/index.js +2 -6
  55. package/src/lexer.js +80 -29
  56. package/src/lower/boxing.js +1 -7
  57. package/src/lower/captures.js +2 -6
  58. package/src/lower/embedding.js +2 -1
  59. package/src/lower/ownership.js +30 -9
  60. package/src/minifier.js +20 -68
  61. package/src/parser/declarations.js +3 -6
  62. package/src/parser/expressions.js +3 -8
  63. package/src/parser/index.js +18 -3
  64. package/src/parser/statements.js +25 -38
  65. package/src/parser/struct-tag.js +144 -0
  66. package/src/parser/types.js +64 -8
  67. package/src/resolver.js +2 -27
  68. package/src/templ-lexer.js +29 -63
  69. package/src/templ-parser.js +22 -45
  70. package/src/typechecker/assignability.js +126 -13
  71. package/src/typechecker/expressions.js +168 -16
  72. package/src/typechecker/index.js +35 -8
  73. package/src/typechecker/resolve.js +187 -8
  74. package/src/typechecker/statements.js +68 -9
  75. package/src/typechecker/stdlib/core.js +280 -89
  76. package/src/typechecker/stdlib/extended.js +490 -1
  77. package/src/typechecker/stdlib/simd.js +73 -0
  78. package/src/typechecker/stdlib.js +2 -0
  79. package/src/typechecker/types.js +362 -9
  80. package/src/vendor.js +86 -11
@@ -43,15 +43,84 @@ export const HELPER_SCLONE = `var __sclone = __sclone || function(x) {
43
43
 
44
44
  // Interface boxing: tag struct values (__v) vs struct pointers (__p) so type
45
45
  // switches can tell T from *T; tags are non-enumerable so __equal/JSON ignore them.
46
- export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x) {
46
+ export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields) {
47
47
  if (x === null || typeof x !== "object") return x;
48
48
  const c = typeof x.__clone === "function" ? x.__clone() : Object.assign(Object.create(Object.getPrototypeOf(x)), x);
49
49
  Object.defineProperty(c, "__v", { value: true, configurable: true });
50
+ if (Array.isArray(ptrFields)) {
51
+ for (const f of ptrFields) {
52
+ if (f.indexOf(".") !== -1) {
53
+ const parts = f.split(".");
54
+ let cur = c;
55
+ for (let j = 0; j < parts.length - 1; j++) cur = cur?.[parts[j]];
56
+ const last = parts[parts.length - 1];
57
+ if (cur?.[last] !== null && typeof cur?.[last] === "object") __ifp(cur[last]);
58
+ } else if (c[f] !== null && typeof c[f] === "object") {
59
+ __ifp(c[f]);
60
+ }
61
+ }
62
+ }
63
+ for (const k of Object.keys(c)) {
64
+ if (c[k] !== null && typeof c[k] === "object" && !Array.isArray(c[k]) && !ArrayBuffer.isView(c[k])) {
65
+ if (!c[k].__v && !c[k].__p && (!Array.isArray(ptrFields) || !ptrFields.includes(k))) {
66
+ Object.defineProperty(c[k], "__v", { value: true, configurable: true });
67
+ }
68
+ }
69
+ }
50
70
  return c;
51
71
  };
52
- var __ifp = __ifp || function(x) {
53
- if (x !== null && typeof x === "object" && x.__p !== true && Object.isExtensible(x))
72
+ var __ifp = __ifp || function(x, ptrFields, seen) {
73
+ if (x === null || typeof x !== "object") return x;
74
+ if (x.__p !== true && Object.isExtensible(x))
54
75
  Object.defineProperty(x, "__p", { value: true, configurable: true });
76
+ if (Array.isArray(ptrFields)) {
77
+ seen = seen || new Set();
78
+ if (seen.has(x)) return x;
79
+ seen.add(x);
80
+ for (const f of ptrFields) {
81
+ if (f.indexOf(".") !== -1) {
82
+ const parts = f.split(".");
83
+ let cur = x;
84
+ for (let j = 0; j < parts.length - 1; j++) cur = cur?.[parts[j]];
85
+ const last = parts[parts.length - 1];
86
+ if (cur?.[last] !== null && typeof cur?.[last] === "object") __ifp(cur[last]);
87
+ } else if (x[f] !== null && typeof x[f] === "object") {
88
+ __ifp(x[f]);
89
+ }
90
+ }
91
+ }
92
+ return x;
93
+ };
94
+ var __ifm = __ifm || function(x) {
95
+ if (x === null || x === undefined) return x;
96
+ if (typeof x !== "object") return x;
97
+ if (x.__map !== true && Object.isExtensible(x))
98
+ Object.defineProperty(x, "__map", { value: true, configurable: true });
99
+ return x;
100
+ };
101
+ var __ifpm = __ifpm || function(x) {
102
+ if (x === null || x === undefined) return x;
103
+ if (typeof x !== "object") return x;
104
+ if (x.__map !== true && Object.isExtensible(x)) {
105
+ Object.defineProperty(x, "__map", { value: true, configurable: true });
106
+ Object.defineProperty(x, "__ptr_map", { value: true, configurable: true });
107
+ }
108
+ return x;
109
+ };
110
+ var __ifs = __ifs || function(x, ptrFields) {
111
+ if (x === null || x === undefined) return x;
112
+ if (x.__slice !== true && Object.isExtensible(x))
113
+ Object.defineProperty(x, "__slice", { value: true, configurable: true });
114
+ if (Array.isArray(ptrFields) && Object.isExtensible(x))
115
+ Object.defineProperty(x, "__ptr_fields", { value: ptrFields, configurable: true });
116
+ return x;
117
+ };
118
+ var __ifps = __ifps || function(x) {
119
+ if (x === null || x === undefined) return x;
120
+ if (x.__slice !== true && Object.isExtensible(x)) {
121
+ Object.defineProperty(x, "__slice", { value: true, configurable: true });
122
+ Object.defineProperty(x, "__ptr_slice", { value: true, configurable: true });
123
+ }
55
124
  return x;
56
125
  };`;
57
126
 
@@ -62,9 +131,21 @@ export const HELPER_NIL_CALL = `var __nilcall = __nilcall || function(x) {
62
131
  return x;
63
132
  };`;
64
133
 
134
+ // Interface equality: named non-struct values are boxed in interfaces, so two
135
+ // boxes are equal when they share a type and hold the same value (as in Go).
136
+ export const HELPER_IFEQ = `var __ifeq = __ifeq || function(a, b) {
137
+ if (a === b) return true;
138
+ if (a === null || a === undefined || b === null || b === undefined) return a == null && b == null;
139
+ if (typeof a === "object" && typeof b === "object" && a.constructor === b.constructor && typeof a.__gfUnbox === "function") {
140
+ return a.__gfUnbox() === b.__gfUnbox();
141
+ }
142
+ return false;
143
+ };`;
144
+
65
145
  export const HELPER_EQUAL = `var __equal = __equal || function __equal(a, b) {
66
146
  if (a === b) return true;
67
147
  if (a === null || b === null) return false;
148
+ if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
68
149
  if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
69
150
  if (a.byteLength !== b.byteLength || a.length !== b.length) return false;
70
151
  for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
@@ -124,10 +205,124 @@ var __recover = __recover || function(ok) {
124
205
 
125
206
  export const HELPER_SPRINTF = `var __sprintf = __sprintf || function(f, ...a) {
126
207
  let i = 0;
127
- return f.replace(/%([#+\\- 0]*)([0-9]*)\\.?([0-9]*)[sdvftxXqobeEgGw%]/g, (m) => {
208
+ const ptrMap = new WeakMap();
209
+ const ptrSet = new WeakSet();
210
+ let ptrCounter = 1;
211
+ const getPtr = (o) => {
212
+ let p = ptrMap.get(o);
213
+ if (!p) {
214
+ p = "0x" + (ptrCounter++).toString(16);
215
+ ptrMap.set(o, p);
216
+ }
217
+ return p;
218
+ };
219
+ const markPtr = (o) => {
220
+ if (o !== null && typeof o === "object") ptrSet.add(o);
221
+ };
222
+ const isPointer = (o) => {
223
+ return o !== null && typeof o === "object" && (o.__p === true || ptrSet.has(o));
224
+ };
225
+ const formatV = (val, isPlus, isTopLevel) => {
226
+ if (val === null || val === undefined) return "<nil>";
227
+ if (typeof val === "boolean") return String(val);
228
+ if (typeof val === "number" || typeof val === "bigint") return String(val);
229
+ if (typeof val === "string") return val;
230
+ if (typeof val === "object") {
231
+ if (val._d instanceof Date) {
232
+ return typeof __timeFmt === "function" ? __timeFmt(val, "2006-01-02 15:04:05.999999999 -0700 MST") : String(val._d);
233
+ }
234
+ if ("re" in val && "im" in val) {
235
+ const sign = val.im >= 0 ? "+" : "";
236
+ return "(" + val.re + sign + val.im + "i)";
237
+ }
238
+ if (typeof val.Error === "function") {
239
+ return String(val.Error());
240
+ }
241
+ if (typeof val.__gfUnbox === "function") return formatV(val.__gfUnbox(), isPlus, isTopLevel);
242
+ if (Array.isArray(val) || ArrayBuffer.isView(val)) {
243
+ const isElemPtr = val.__ptr_slice === true;
244
+ const pf = val.__ptr_fields;
245
+ const parts = [];
246
+ for (let j = 0; j < val.length; j++) {
247
+ const item = val[j];
248
+ if (isElemPtr && item !== null && typeof item === "object") {
249
+ markPtr(item);
250
+ } else if (Array.isArray(pf) && item !== null && typeof item === "object") {
251
+ for (const f of pf) {
252
+ if (f.indexOf(".") !== -1) {
253
+ const fparts = f.split(".");
254
+ let cur = item;
255
+ for (let k = 0; k < fparts.length - 1; k++) cur = cur?.[fparts[k]];
256
+ const last = fparts[fparts.length - 1];
257
+ if (cur?.[last] !== null && typeof cur?.[last] === "object") markPtr(cur[last]);
258
+ } else if (item[f] !== null && typeof item[f] === "object") {
259
+ markPtr(item[f]);
260
+ }
261
+ }
262
+ }
263
+ parts.push(formatV(item, isPlus, false));
264
+ }
265
+ return "[" + parts.join(" ") + "]";
266
+ }
267
+ if (val instanceof Map || val.__map === true) {
268
+ const isElemPtr = val.__ptr_map === true;
269
+ const parts = [];
270
+ if (val instanceof Map) {
271
+ const entries = Array.from(val.entries()).sort(([k1], [k2]) => {
272
+ if (typeof k1 === "number" && typeof k2 === "number") return k1 - k2;
273
+ const na = Number(k1), nb = Number(k2);
274
+ if (!Number.isNaN(na) && !Number.isNaN(nb)) return na - nb;
275
+ return String(k1).localeCompare(String(k2));
276
+ });
277
+ for (const [k, v] of entries) {
278
+ if (isElemPtr && v !== null && typeof v === "object") {
279
+ markPtr(v);
280
+ }
281
+ parts.push(formatV(k, isPlus, false) + ":" + formatV(v, isPlus, false));
282
+ }
283
+ } else {
284
+ const keys = Object.keys(val).sort((a, b) => {
285
+ const na = Number(a), nb = Number(b);
286
+ if (!Number.isNaN(na) && !Number.isNaN(nb)) return na - nb;
287
+ return a.localeCompare(b);
288
+ });
289
+ for (const k of keys) {
290
+ const v = val[k];
291
+ if (isElemPtr && v !== null && typeof v === "object") {
292
+ markPtr(v);
293
+ }
294
+ parts.push(formatV(k, isPlus, false) + ":" + formatV(v, isPlus, false));
295
+ }
296
+ }
297
+ return "map[" + parts.join(" ") + "]";
298
+ }
299
+ if ("value" in val && (val.__box === true || (!val.__struct && !("__v" in val) && Object.keys(val).length === 1 && (val.constructor === Object || !val.constructor || val.constructor?.name === "Object")))) {
300
+ return getPtr(val);
301
+ }
302
+ const isPtr = isPointer(val);
303
+ if (isPtr) {
304
+ if (!isTopLevel) {
305
+ return getPtr(val);
306
+ }
307
+ getPtr(val);
308
+ }
309
+ const prefix = isPtr ? "&{" : "{";
310
+ const keys = Object.keys(val);
311
+ const parts = [];
312
+ for (const k of keys) {
313
+ const fv = formatV(val[k], isPlus, false);
314
+ parts.push(isPlus ? k + ":" + fv : fv);
315
+ }
316
+ return prefix + parts.join(" ") + "}";
317
+ }
318
+ return String(val);
319
+ };
320
+ return f.replace(/%([#+\\- 0]*)([0-9]*)\\.?([0-9]*)[sdvftxXqobeEgGwc%]/g, (m) => {
128
321
  if (m === "%%") return "%";
129
322
  const verb = m.slice(-1);
130
- const v = a[i++];
323
+ let v = a[i++];
324
+ // Boxed named values format as their underlying value; Error() still applies to %v/%s/%q/%w.
325
+ if (v && typeof v.__gfUnbox === "function" && !(typeof v.Error === "function" && "vsqw".includes(verb))) v = v.__gfUnbox();
131
326
  const [, flags, width, prec] = m.match(/^%([#+\\- 0]*)([0-9]*)\\.?([0-9]*)/) || [];
132
327
  const zero = flags?.includes("0") && !flags?.includes("-");
133
328
  const pad = (s, w, z) => {
@@ -138,30 +333,46 @@ export const HELPER_SPRINTF = `var __sprintf = __sprintf || function(f, ...a) {
138
333
  };
139
334
  switch (verb) {
140
335
  case "s": return pad(String(v == null ? "<nil>" : v), width, false);
141
- case "d": return pad(String(Math.trunc(Number(v))), width, zero);
336
+ case "c": return pad(String.fromCodePoint(Number(v)), width, false);
337
+ case "d": return pad(String(typeof v === "bigint" ? v : Math.trunc(Number(v))), width, zero);
142
338
  case "v": {
143
- if (typeof v === "object" && v !== null) {
144
- if ("re" in v && "im" in v) {
145
- const sign = v.im >= 0 ? "+" : "";
146
- return pad("(" + v.re + sign + v.im + "i)", width, false);
147
- }
148
- if (typeof v.Error === "function") {
149
- return pad(String(v.Error()), width, false);
150
- }
151
- try {
152
- return pad(JSON.stringify(v), width, false);
153
- } catch {
154
- return pad(String(v), width, false);
155
- }
156
- }
157
- return pad(String(v == null ? "<nil>" : v), width, false);
339
+ const isPlus = flags?.includes("+") ?? false;
340
+ return pad(formatV(v, isPlus, true), width, false);
158
341
  }
159
342
  case "f": { const n = Number(v), p = prec !== "" ? parseInt(prec) : 6; return pad(n.toFixed(p), width, zero); }
160
343
  case "t": return pad(String(!!v), width, false);
161
- case "x": return pad((Number(v) >>> 0).toString(16), width, zero);
162
- case "X": return pad((Number(v) >>> 0).toString(16).toUpperCase(), width, zero);
163
- case "o": return pad((Number(v) >>> 0).toString(8), width, zero);
164
- case "b": return pad((Number(v) >>> 0).toString(2), width, zero);
344
+ case "x": {
345
+ let hex;
346
+ if (Array.isArray(v) || ArrayBuffer.isView(v)) {
347
+ hex = Array.from(v).map((b) => (Number(b) & 0xff).toString(16).padStart(2, "0")).join("");
348
+ } else if (typeof v === "string") {
349
+ hex = Array.from(new TextEncoder().encode(v)).map((b) => b.toString(16).padStart(2, "0")).join("");
350
+ } else if (typeof v === "bigint") {
351
+ hex = BigInt.asUintN(64, v).toString(16);
352
+ } else if (Math.abs(Number(v)) > 0xffffffff) {
353
+ hex = (Math.trunc(Number(v) / 0x100000000) >>> 0).toString(16) + (Number(v) >>> 0).toString(16).padStart(8, "0");
354
+ } else {
355
+ hex = (Number(v) >>> 0).toString(16);
356
+ }
357
+ return pad(hex, width, zero);
358
+ }
359
+ case "X": {
360
+ let hex;
361
+ if (Array.isArray(v) || ArrayBuffer.isView(v)) {
362
+ hex = Array.from(v).map((b) => (Number(b) & 0xff).toString(16).padStart(2, "0").toUpperCase()).join("");
363
+ } else if (typeof v === "string") {
364
+ hex = Array.from(new TextEncoder().encode(v)).map((b) => b.toString(16).padStart(2, "0").toUpperCase()).join("");
365
+ } else if (typeof v === "bigint") {
366
+ hex = BigInt.asUintN(64, v).toString(16).toUpperCase();
367
+ } else if (Math.abs(Number(v)) > 0xffffffff) {
368
+ hex = (Math.trunc(Number(v) / 0x100000000) >>> 0).toString(16).toUpperCase() + (Number(v) >>> 0).toString(16).padStart(8, "0").toUpperCase();
369
+ } else {
370
+ hex = (Number(v) >>> 0).toString(16).toUpperCase();
371
+ }
372
+ return pad(hex, width, zero);
373
+ }
374
+ case "o": return pad((typeof v === "bigint" ? BigInt.asUintN(64, v).toString(8) : (Number(v) >>> 0).toString(8)), width, zero);
375
+ case "b": return pad((typeof v === "bigint" ? BigInt.asUintN(64, v).toString(2) : (Number(v) >>> 0).toString(2)), width, zero);
165
376
  case "q": return pad('"' + String(v == null ? "" : v).replace(/\\\\/g, "\\\\\\\\").replace(/"/g, '\\\\"') + '"', width, false);
166
377
  case "e": case "E": { const n = Number(v), p = prec !== "" ? parseInt(prec) : 6; return pad(n.toExponential(p), width, zero); }
167
378
  case "g": case "G": { const n = Number(v); return pad(prec !== "" ? n.toPrecision(parseInt(prec)) : String(n), width, zero); }
@@ -175,17 +386,95 @@ export const HELPER_ERROR = `var __error = __error || function(msg, cause) {
175
386
  return { Error() { return msg; }, toString() { return msg; }, _msg: msg, _cause: cause ?? null };
176
387
  };`;
177
388
 
178
- export const HELPER_ERROR_IS = `var __errorIs = __errorIs || function(err, target) {
179
- while (err !== null && err !== undefined) {
180
- if (err === target) return true;
181
- if (typeof err === "object" && typeof target === "object" &&
182
- err._msg !== undefined && target._msg !== undefined &&
183
- err._msg === target._msg) return true;
184
- err = err?._cause ?? null;
389
+ export const HELPER_STRCONV_ERROR = `var __strconv_err_syntax = __strconv_err_syntax || __error("invalid syntax");
390
+ var __strconv_err_range = __strconv_err_range || __error("value out of range");`;
391
+
392
+ export const HELPER_PATH_ERROR = `var __path_err_bad_pattern = __path_err_bad_pattern || __error("syntax error in pattern");`;
393
+
394
+ export const HELPER_IO_EOF = `var __io_eof = __io_eof || __error("EOF");`;
395
+
396
+ export const HELPER_ERROR_IS = `var __errorIs = __errorIs || function __errorIs(err, target) {
397
+ if (err === null || err === undefined) return false;
398
+ if (err === target) return true;
399
+ if (typeof err === "object" && typeof target === "object" && target !== null &&
400
+ typeof err.__gfUnbox === "function" && err.constructor === target.constructor &&
401
+ err.__gfUnbox() === target.__gfUnbox()) return true;
402
+ if (typeof err === "object" && typeof target === "object" &&
403
+ err._msg !== undefined && target._msg !== undefined &&
404
+ err._msg === target._msg) return true;
405
+ if (typeof err.Is === "function" && err.Is(target)) return true;
406
+ if (Array.isArray(err._errs)) {
407
+ for (const sub of err._errs) {
408
+ if (__errorIs(sub, target)) return true;
409
+ }
410
+ }
411
+ if (typeof err.Unwrap === "function") {
412
+ const unwrapped = err.Unwrap();
413
+ if (Array.isArray(unwrapped)) {
414
+ for (const sub of unwrapped) {
415
+ if (__errorIs(sub, target)) return true;
416
+ }
417
+ } else if (unwrapped !== null && unwrapped !== undefined) {
418
+ if (__errorIs(unwrapped, target)) return true;
419
+ }
420
+ }
421
+ if (err._cause !== undefined && err._cause !== null) {
422
+ return __errorIs(err._cause, target);
423
+ }
424
+ return false;
425
+ };`;
426
+
427
+ export const HELPER_ERROR_AS = `var __errorAs = __errorAs || function(err, target, matcher, extract) {
428
+ if (err === null || err === undefined || target === null || typeof target !== "object") return false;
429
+ let cur = err;
430
+ while (cur !== null && cur !== undefined) {
431
+ const unboxed = cur?.value ?? cur;
432
+ if (typeof cur.As === "function" && cur.As(target)) return true;
433
+ if (matcher ? matcher(unboxed) : (unboxed !== err && typeof unboxed === "object" && !("_msg" in unboxed && "_cause" in unboxed))) {
434
+ if ("value" in target) {
435
+ target.value = extract ? extract(unboxed) : unboxed;
436
+ } else {
437
+ Object.assign(target, unboxed);
438
+ }
439
+ return true;
440
+ }
441
+ if (Array.isArray(cur._errs)) {
442
+ for (const sub of cur._errs) {
443
+ if (__errorAs(sub, target, matcher, extract)) return true;
444
+ }
445
+ }
446
+ if (typeof cur.Unwrap === "function") {
447
+ const unwrapped = cur.Unwrap();
448
+ if (Array.isArray(unwrapped)) {
449
+ for (const sub of unwrapped) {
450
+ if (__errorAs(sub, target, matcher, extract)) return true;
451
+ }
452
+ } else if (unwrapped !== null && unwrapped !== undefined) {
453
+ if (__errorAs(unwrapped, target, matcher, extract)) return true;
454
+ }
455
+ }
456
+ cur = cur?._cause ?? null;
185
457
  }
186
458
  return false;
187
459
  };`;
188
460
 
461
+ export const HELPER_ERROR_JOIN = `var __errorJoin = __errorJoin || function(...errs) {
462
+ const filtered = [];
463
+ for (const e of errs) {
464
+ if (Array.isArray(e)) {
465
+ for (const sub of e) if (sub !== null && sub !== undefined) filtered.push(sub);
466
+ } else if (e !== null && e !== undefined) {
467
+ filtered.push(e);
468
+ }
469
+ }
470
+ if (filtered.length === 0) return null;
471
+ const msg = filtered.map(e => (typeof e === "object" && typeof e.Error === "function") ? e.Error() : String(e)).join("\\n");
472
+ const joined = __error(msg);
473
+ joined._errs = filtered;
474
+ joined.Unwrap = function() { return filtered; };
475
+ return joined;
476
+ };`;
477
+
189
478
  // Go-semantics strconv parsers shared by the JS backend and the wasm runtime
190
479
  // imports (boundary.js), so both targets agree. Each parser returns
191
480
  // [value, errorMessage | null]; integer values are BigInt (the wasm side
@@ -222,6 +511,32 @@ var __strconv_parse_int = __strconv_parse_int || function(s, base, bits) {
222
511
  if (v > max || v < min) return [v > max ? max : min, 'strconv.ParseInt: parsing "' + s + '": value out of range'];
223
512
  return [v, null];
224
513
  };
514
+ var __strconv_parse_uint = __strconv_parse_uint || function(s, base, bits) {
515
+ let str = s;
516
+ if (str[0] === "+") { str = str.slice(1); }
517
+ if (str[0] === "-") {
518
+ return [0n, 'strconv.ParseUint: parsing "' + s + '": invalid syntax'];
519
+ }
520
+ if (base === 0) {
521
+ if (/^0[xX]/.test(str)) { base = 16; str = str.slice(2); }
522
+ else if (/^0[bB]/.test(str)) { base = 2; str = str.slice(2); }
523
+ else if (/^0[oO]/.test(str)) { base = 8; str = str.slice(2); }
524
+ else if (/^0[0-9]/.test(str)) { base = 8; str = str.slice(1); }
525
+ else base = 10;
526
+ str = str.replaceAll("_", "");
527
+ }
528
+ if (base < 2 || base > 36) return [0n, 'strconv.ParseUint: parsing "' + s + '": invalid base ' + base];
529
+ const digits = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base);
530
+ if (str === "" || [...str.toLowerCase()].some((c) => !digits.includes(c))) {
531
+ return [0n, 'strconv.ParseUint: parsing "' + s + '": invalid syntax'];
532
+ }
533
+ let v = 0n; const B = BigInt(base);
534
+ for (const c of str.toLowerCase()) v = v * B + BigInt(digits.indexOf(c));
535
+ const w = bits === 0 ? 64 : bits;
536
+ const max = w >= 64 ? 18446744073709551615n : (1n << BigInt(w)) - 1n;
537
+ if (v > max) return [max, 'strconv.ParseUint: parsing "' + s + '": value out of range'];
538
+ return [v, null];
539
+ };
225
540
  var __strconv_parse_float = __strconv_parse_float || function(s) {
226
541
  const str = s.replaceAll("_", "");
227
542
  if (/^[+-]?(inf|infinity)$/i.test(str)) return [str[0] === "-" ? -Infinity : Infinity, null];
@@ -264,37 +579,159 @@ export const HELPER_PATH_CLEAN = `var __pathClean = __pathClean || function(p) {
264
579
  return acc;
265
580
  }, []);
266
581
  return (abs ? "/" : "") + (parts.join("/") || ".");
582
+ };
583
+ var __pathMatch = __pathMatch || function(pat, name) {
584
+ let rx = "^";
585
+ let hasErr = false;
586
+ let i = 0;
587
+ while (i < pat.length) {
588
+ const c = pat[i];
589
+ if (c === "\\\\") {
590
+ if (i + 1 >= pat.length) { hasErr = true; break; }
591
+ const next = pat[++i];
592
+ if (/[.^$*+?()|{}\\[\\]\\\\]/.test(next)) rx += "\\\\" + next;
593
+ else rx += next;
594
+ i++;
595
+ } else if (c === "*") {
596
+ rx += "[^/]*";
597
+ i++;
598
+ } else if (c === "?") {
599
+ rx += "[^/]";
600
+ i++;
601
+ } else if (c === "[") {
602
+ i++;
603
+ let negated = false;
604
+ if (i < pat.length && pat[i] === "^") {
605
+ negated = true;
606
+ i++;
607
+ }
608
+ if (i >= pat.length || pat[i] === "]") {
609
+ return [false, true];
610
+ }
611
+ let classContent = "";
612
+ let closed = false;
613
+ while (i < pat.length) {
614
+ let ch = pat[i];
615
+ if (ch === "]") {
616
+ closed = true;
617
+ i++;
618
+ break;
619
+ }
620
+ if (ch === "\\\\") {
621
+ if (i + 1 >= pat.length) { hasErr = true; break; }
622
+ ch = pat[++i];
623
+ }
624
+ if (ch === "/") {
625
+ return [false, true];
626
+ }
627
+ i++;
628
+ if (i + 1 < pat.length && pat[i] === "-" && pat[i + 1] !== "]") {
629
+ i++;
630
+ let end = pat[i];
631
+ if (end === "\\\\") {
632
+ if (i + 1 >= pat.length) { hasErr = true; break; }
633
+ end = pat[++i];
634
+ }
635
+ if (end === "/") return [false, true];
636
+ i++;
637
+ if (ch.charCodeAt(0) > end.charCodeAt(0)) return [false, true];
638
+ if (ch.charCodeAt(0) <= 47 && 47 <= end.charCodeAt(0)) return [false, true];
639
+ const isSpec = (c) => c === "-" || c === "^" || c === "\\\\" || c === "[" || c === "]";
640
+ const escCh = isSpec(ch) ? "\\\\" + ch : ch;
641
+ const escEnd = isSpec(end) ? "\\\\" + end : end;
642
+ classContent += escCh + "-" + escEnd;
643
+ } else {
644
+ const isSpec = (c) => c === "-" || c === "^" || c === "\\\\" || c === "[" || c === "]";
645
+ const escCh = isSpec(ch) ? "\\\\" + ch : ch;
646
+ classContent += escCh;
647
+ }
648
+ }
649
+ if (!closed || hasErr) return [false, true];
650
+ if (negated) {
651
+ rx += "[^/" + classContent + "]";
652
+ } else {
653
+ rx += "[" + classContent + "]";
654
+ }
655
+ } else if (/[.^$*+?()|{}\\[\\]\\\\]/.test(c)) {
656
+ rx += "\\\\" + c;
657
+ i++;
658
+ } else {
659
+ rx += c;
660
+ i++;
661
+ }
662
+ }
663
+ if (hasErr) return [false, true];
664
+ try {
665
+ const re = new RegExp(rx + "$");
666
+ return [re.test(name), false];
667
+ } catch (e) {
668
+ return [false, true];
669
+ }
267
670
  };`;
268
671
 
269
672
  export const HELPER_TIME_FMT = `var __timeFmt = __timeFmt || function(d, layout) {
673
+ const dt = d instanceof Date ? d : (d?._d ?? d);
674
+ const isUtc = d?._offset === 0;
270
675
  const pad = (n, w = 2) => String(n).padStart(w, "0");
271
676
  const DAYS = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
272
677
  const MONTHS = ["January","February","March","April","May","June","July","August","September","October","November","December"];
273
- return layout.replace(/2006|06|Monday|Mon|January|Jan|01|1|02|2|15|PM|3|04|4|05|5|Z07:00|\\.000|\\.999/g, t => {
678
+ const getFullYear = () => isUtc ? dt.getUTCFullYear() : dt.getFullYear();
679
+ const getMonth = () => isUtc ? dt.getUTCMonth() : dt.getMonth();
680
+ const getDate = () => isUtc ? dt.getUTCDate() : dt.getDate();
681
+ const getDay = () => isUtc ? dt.getUTCDay() : dt.getDay();
682
+ const getHours = () => isUtc ? dt.getUTCHours() : dt.getHours();
683
+ const getMinutes = () => isUtc ? dt.getUTCMinutes() : dt.getMinutes();
684
+ const getSeconds = () => isUtc ? dt.getUTCSeconds() : dt.getSeconds();
685
+ const getMilliseconds = () => isUtc ? dt.getUTCMilliseconds() : dt.getMilliseconds();
686
+ const getTimezoneOffset = () => isUtc ? 0 : dt.getTimezoneOffset();
687
+ return layout.replace(/2006|06|Monday|Mon|January|Jan|01|02|15|PM|pm|03|04|05|Z07:00|-07:00|-0700|MST|\\.(?:0+|9+)|1|2|3|4|5/g, t => {
688
+ if (t.startsWith(".")) {
689
+ const isZeroPad = t.includes("0");
690
+ const maxLen = t.length - 1;
691
+ const ms = getMilliseconds();
692
+ let frac = pad(ms, 3);
693
+ if (maxLen > 3) frac = frac.padEnd(maxLen, "0");
694
+ else frac = frac.slice(0, maxLen);
695
+ if (!isZeroPad) {
696
+ frac = frac.replace(/0+$/, "");
697
+ return frac.length > 0 ? "." + frac : "";
698
+ } else {
699
+ return "." + frac;
700
+ }
701
+ }
274
702
  switch (t) {
275
- case "2006": return d.getFullYear();
276
- case "06": return String(d.getFullYear()).slice(-2);
277
- case "Monday": return DAYS[d.getDay()];
278
- case "Mon": return DAYS[d.getDay()].slice(0, 3);
279
- case "January": return MONTHS[d.getMonth()];
280
- case "Jan": return MONTHS[d.getMonth()].slice(0, 3);
281
- case "01": return pad(d.getMonth() + 1);
282
- case "1": return String(d.getMonth() + 1);
283
- case "02": return pad(d.getDate());
284
- case "2": return String(d.getDate());
285
- case "15": return pad(d.getHours());
286
- case "PM": return d.getHours() < 12 ? "AM" : "PM";
287
- case "3": return String(d.getHours() % 12 || 12);
288
- case "04": return pad(d.getMinutes());
289
- case "4": return String(d.getMinutes());
290
- case "05": return pad(d.getSeconds());
291
- case "5": return String(d.getSeconds());
703
+ case "2006": return getFullYear();
704
+ case "06": return String(getFullYear()).slice(-2);
705
+ case "Monday": return DAYS[getDay()];
706
+ case "Mon": return DAYS[getDay()].slice(0, 3);
707
+ case "January": return MONTHS[getMonth()];
708
+ case "Jan": return MONTHS[getMonth()].slice(0, 3);
709
+ case "01": return pad(getMonth() + 1);
710
+ case "1": return String(getMonth() + 1);
711
+ case "02": return pad(getDate());
712
+ case "2": return String(getDate());
713
+ case "15": return pad(getHours());
714
+ case "PM": return getHours() < 12 ? "AM" : "PM";
715
+ case "pm": return getHours() < 12 ? "am" : "pm";
716
+ case "03": return pad(getHours() % 12 || 12);
717
+ case "3": return String(getHours() % 12 || 12);
718
+ case "04": return pad(getMinutes());
719
+ case "4": return String(getMinutes());
720
+ case "05": return pad(getSeconds());
721
+ case "5": return String(getSeconds());
292
722
  case "Z07:00": {
293
- const o = -d.getTimezoneOffset();
723
+ const o = -getTimezoneOffset();
294
724
  return o === 0 ? "Z" : (o > 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + ":" + pad(Math.abs(o) % 60);
295
725
  }
296
- case ".000": return "." + pad(d.getMilliseconds(), 3);
297
- case ".999": return d.getMilliseconds() > 0 ? "." + String(d.getMilliseconds()).replace(/0+$/, "") : "";
726
+ case "-07:00": {
727
+ const o = -getTimezoneOffset();
728
+ return (o >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + ":" + pad(Math.abs(o) % 60);
729
+ }
730
+ case "-0700": {
731
+ const o = -getTimezoneOffset();
732
+ return (o >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + pad(Math.abs(o) % 60);
733
+ }
734
+ case "MST": return isUtc ? "UTC" : "LOCAL";
298
735
  default: return t;
299
736
  }
300
737
  });
@@ -306,7 +743,7 @@ export const HELPER_TIME_PARSE = `var __timeParse = __timeParse || function(layo
306
743
  if (isNaN(d.getTime())) throw 0;
307
744
  return [{ _d: d }, null];
308
745
  } catch {
309
- return [{ _d: new Date(0) }, "parsing time: cannot parse"];
746
+ return [{ _d: new Date(0) }, { Error() { return "parsing time: cannot parse"; }, toString() { return "parsing time: cannot parse"; }, _msg: "parsing time: cannot parse", _cause: null }];
310
747
  }
311
748
  };`;
312
749
 
@@ -425,3 +862,1030 @@ export const HELPER_INJECT_STYLES = `var __injectStyles = __injectStyles || func
425
862
  }
426
863
  s.textContent += "\\n" + css;
427
864
  };`;
865
+
866
+ export const HELPER_DURATION = `var __durationString = __durationString || function(d) {
867
+ d = BigInt(d);
868
+ if (d === 0n) return "0s";
869
+ let neg = false;
870
+ if (d < 0n) { neg = true; d = -d; }
871
+ let s = "";
872
+ const totalSec = d / 1000000000n;
873
+ const sec = totalSec % 60n;
874
+ const min = (totalSec / 60n) % 60n;
875
+ const hr = totalSec / 3600n;
876
+
877
+ if (hr > 0n) s += hr + "h";
878
+ const remAfterHr = d % 3600000000000n;
879
+ if (min > 0n || (hr > 0n && remAfterHr > 0n)) s += min + "m";
880
+ if (totalSec > 0n) {
881
+ const frac = d % 1000000000n;
882
+ if (sec > 0n || frac > 0n || (hr === 0n && min === 0n)) {
883
+ if (frac === 0n) {
884
+ s += sec + "s";
885
+ } else {
886
+ let fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
887
+ s += sec + "." + fracStr + "s";
888
+ }
889
+ }
890
+ } else {
891
+ const ms = (d / 1000000n) % 1000n;
892
+ const us = (d / 1000n) % 1000n;
893
+ const ns = d % 1000n;
894
+ if (ms > 0n) {
895
+ const frac = d % 1000000n;
896
+ if (frac === 0n) s += ms + "ms";
897
+ else {
898
+ let fracStr = frac.toString().padStart(6, "0").replace(/0+$/, "");
899
+ s += ms + "." + fracStr + "ms";
900
+ }
901
+ } else if (us > 0n) {
902
+ const frac = d % 1000n;
903
+ if (frac === 0n) s += us + "µs";
904
+ else {
905
+ let fracStr = frac.toString().padStart(3, "0").replace(/0+$/, "");
906
+ s += us + "." + fracStr + "µs";
907
+ }
908
+ } else {
909
+ s += ns + "ns";
910
+ }
911
+ }
912
+ return neg ? "-" + s : s;
913
+ };`;
914
+
915
+ export const HELPER_SYNC = `var __sync_mutex = __sync_mutex || function() {
916
+ return { Lock() {}, Unlock() {}, TryLock() { return true; } };
917
+ };
918
+ var __sync_rwmutex = __sync_rwmutex || function() {
919
+ return { Lock() {}, Unlock() {}, RLock() {}, RUnlock() {}, TryLock() { return true; }, TryRLock() { return true; } };
920
+ };
921
+ var __sync_once = __sync_once || function() {
922
+ return { done: 0, Do(f) { if (!this.done) { this.done = 1; f(); } } };
923
+ };
924
+ var __sync_waitgroup = __sync_waitgroup || function() {
925
+ return { counter: 0, Add(d) { this.counter = (this.counter || 0) + d; }, Done() { this.counter = (this.counter || 0) - 1; }, Wait() {} };
926
+ };`;
927
+
928
+ export const HELPER_CRYPTO_RAND = `var __crypto_rand_read = __crypto_rand_read || function(b) {
929
+ if (!b || b.length === 0) return [0, null];
930
+ const u8 = ArrayBuffer.isView(b) ? b : new Uint8Array(b.length);
931
+ const c = typeof crypto !== "undefined" ? crypto : (typeof globalThis !== "undefined" ? globalThis.crypto : null);
932
+ const CHUNK = 65536;
933
+ if (c && typeof c.getRandomValues === "function") {
934
+ for (let offset = 0; offset < u8.length; offset += CHUNK) {
935
+ const slice = u8.subarray(offset, Math.min(offset + CHUNK, u8.length));
936
+ c.getRandomValues(slice);
937
+ }
938
+ } else {
939
+ for (let i = 0; i < u8.length; i++) u8[i] = Math.floor(Math.random() * 256);
940
+ }
941
+ if (!ArrayBuffer.isView(b)) {
942
+ for (let i = 0; i < u8.length; i++) b[i] = u8[i];
943
+ }
944
+ return [b.length, null];
945
+ };
946
+ var __crypto_rand_reader = __crypto_rand_reader || {
947
+ Read: function(b) { return __crypto_rand_read(b); }
948
+ };`;
949
+
950
+ export const HELPER_SHA256 = `var __sha256 = __sha256 || (function() {
951
+ const K = [
952
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
953
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
954
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
955
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
956
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
957
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
958
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
959
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
960
+ ];
961
+ function rotr(x, n) { return (x >>> n) | (x << (32 - n)); }
962
+ function block(H, M) {
963
+ const W = new Int32Array(64);
964
+ for (let i = 0; i < 16; i++) {
965
+ W[i] = (M[i * 4] << 24) | (M[i * 4 + 1] << 16) | (M[i * 4 + 2] << 8) | M[i * 4 + 3];
966
+ }
967
+ for (let i = 16; i < 64; i++) {
968
+ const s0 = rotr(W[i - 15], 7) ^ rotr(W[i - 15], 18) ^ (W[i - 15] >>> 3);
969
+ const s1 = rotr(W[i - 2], 17) ^ rotr(W[i - 2], 19) ^ (W[i - 2] >>> 10);
970
+ W[i] = (W[i - 16] + s0 + W[i - 7] + s1) | 0;
971
+ }
972
+ let [a, b, c, d, e, f, g, h] = H;
973
+ for (let i = 0; i < 64; i++) {
974
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
975
+ const ch = (e & f) ^ (~e & g);
976
+ const t1 = (h + S1 + ch + K[i] + W[i]) | 0;
977
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
978
+ const maj = (a & b) ^ (a & c) ^ (b & c);
979
+ const t2 = (S0 + maj) | 0;
980
+ h = g; g = f; f = e; e = (d + t1) | 0;
981
+ d = c; c = b; b = a; a = (t1 + t2) | 0;
982
+ }
983
+ H[0] = (H[0] + a) | 0; H[1] = (H[1] + b) | 0; H[2] = (H[2] + c) | 0; H[3] = (H[3] + d) | 0;
984
+ H[4] = (H[4] + e) | 0; H[5] = (H[5] + f) | 0; H[6] = (H[6] + g) | 0; H[7] = (H[7] + h) | 0;
985
+ }
986
+ function digest(bytes) {
987
+ const H = new Int32Array([
988
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
989
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
990
+ ]);
991
+ const len = bytes ? bytes.length : 0;
992
+ const padLen = (len % 64 < 56) ? (56 - (len % 64)) : (120 - (len % 64));
993
+ const total = len + padLen + 8;
994
+ const buf = new Uint8Array(total);
995
+ if (bytes) {
996
+ if (ArrayBuffer.isView(bytes)) buf.set(bytes);
997
+ else for (let i = 0; i < len; i++) buf[i] = bytes[i];
998
+ }
999
+ buf[len] = 0x80;
1000
+ const bits = BigInt(len) * 8n;
1001
+ for (let i = 0; i < 8; i++) {
1002
+ buf[total - 1 - i] = Number((bits >> BigInt(i * 8)) & 0xffn);
1003
+ }
1004
+ for (let i = 0; i < total; i += 64) {
1005
+ block(H, buf.subarray(i, i + 64));
1006
+ }
1007
+ const out = new Uint8Array(32);
1008
+ for (let i = 0; i < 8; i++) {
1009
+ out[i * 4] = (H[i] >>> 24) & 0xff;
1010
+ out[i * 4 + 1] = (H[i] >>> 16) & 0xff;
1011
+ out[i * 4 + 2] = (H[i] >>> 8) & 0xff;
1012
+ out[i * 4 + 3] = H[i] & 0xff;
1013
+ }
1014
+ return out;
1015
+ }
1016
+ class Hash {
1017
+ constructor() { this.Reset(); }
1018
+ Reset() { this.buf = []; }
1019
+ Write(p) {
1020
+ if (p) {
1021
+ for (let i = 0; i < p.length; i++) this.buf.push(p[i]);
1022
+ }
1023
+ return [p ? p.length : 0, null];
1024
+ }
1025
+ Sum(b) {
1026
+ const d = digest(this.buf);
1027
+ if (!b || b.length === 0) return d;
1028
+ const res = new Uint8Array(b.length + d.length);
1029
+ res.set(b, 0);
1030
+ res.set(d, b.length);
1031
+ return res;
1032
+ }
1033
+ Size() { return 32; }
1034
+ BlockSize() { return 64; }
1035
+ }
1036
+ return {
1037
+ Sum256: digest,
1038
+ New: () => new Hash()
1039
+ };
1040
+ })();`;
1041
+
1042
+ export const HELPER_BINARY = `var __binary_le = __binary_le || {
1043
+ Uint16: function(b) { return (b[0] | (b[1] << 8)) & 0xffff; },
1044
+ Uint32: function(b) { return ((b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0); },
1045
+ Uint64: function(b) {
1046
+ const lo = BigInt((b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0);
1047
+ const hi = BigInt((b[4] | (b[5] << 8) | (b[6] << 16) | (b[7] << 24)) >>> 0);
1048
+ return Number(lo | (hi << 32n));
1049
+ },
1050
+ PutUint16: function(b, v) { b[0] = v & 0xff; b[1] = (v >> 8) & 0xff; },
1051
+ PutUint32: function(b, v) { b[0] = v & 0xff; b[1] = (v >> 8) & 0xff; b[2] = (v >> 16) & 0xff; b[3] = (v >>> 24) & 0xff; },
1052
+ PutUint64: function(b, v) {
1053
+ const bv = BigInt(v);
1054
+ for (let i = 0n; i < 8n; i++) b[Number(i)] = Number((bv >> (i * 8n)) & 0xffn);
1055
+ },
1056
+ AppendUint16: function(b, v) {
1057
+ const len = b ? b.length : 0;
1058
+ const res = new Uint8Array(len + 2);
1059
+ if (len > 0) res.set(b, 0);
1060
+ res[len] = v & 0xff;
1061
+ res[len + 1] = (v >> 8) & 0xff;
1062
+ return res;
1063
+ },
1064
+ AppendUint32: function(b, v) {
1065
+ const len = b ? b.length : 0;
1066
+ const res = new Uint8Array(len + 4);
1067
+ if (len > 0) res.set(b, 0);
1068
+ res[len] = v & 0xff;
1069
+ res[len + 1] = (v >> 8) & 0xff;
1070
+ res[len + 2] = (v >> 16) & 0xff;
1071
+ res[len + 3] = (v >>> 24) & 0xff;
1072
+ return res;
1073
+ },
1074
+ AppendUint64: function(b, v) {
1075
+ const len = b ? b.length : 0;
1076
+ const res = new Uint8Array(len + 8);
1077
+ if (len > 0) res.set(b, 0);
1078
+ const bv = BigInt(v);
1079
+ for (let i = 0n; i < 8n; i++) res[len + Number(i)] = Number((bv >> (i * 8n)) & 0xffn);
1080
+ return res;
1081
+ },
1082
+ String: function() { return "LittleEndian"; }
1083
+ };
1084
+ var __binary_be = __binary_be || {
1085
+ Uint16: function(b) { return ((b[0] << 8) | b[1]) & 0xffff; },
1086
+ Uint32: function(b) { return (((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) >>> 0); },
1087
+ Uint64: function(b) {
1088
+ const hi = BigInt(((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) >>> 0);
1089
+ const lo = BigInt(((b[4] << 24) | (b[5] << 16) | (b[6] << 8) | b[7]) >>> 0);
1090
+ return Number((hi << 32n) | lo);
1091
+ },
1092
+ PutUint16: function(b, v) { b[0] = (v >> 8) & 0xff; b[1] = v & 0xff; },
1093
+ PutUint32: function(b, v) { b[0] = (v >>> 24) & 0xff; b[1] = (v >> 16) & 0xff; b[2] = (v >> 8) & 0xff; b[3] = v & 0xff; },
1094
+ PutUint64: function(b, v) {
1095
+ const bv = BigInt(v);
1096
+ for (let i = 0n; i < 8n; i++) b[Number(7n - i)] = Number((bv >> (i * 8n)) & 0xffn);
1097
+ },
1098
+ AppendUint16: function(b, v) {
1099
+ const len = b ? b.length : 0;
1100
+ const res = new Uint8Array(len + 2);
1101
+ if (len > 0) res.set(b, 0);
1102
+ res[len] = (v >> 8) & 0xff;
1103
+ res[len + 1] = v & 0xff;
1104
+ return res;
1105
+ },
1106
+ AppendUint32: function(b, v) {
1107
+ const len = b ? b.length : 0;
1108
+ const res = new Uint8Array(len + 4);
1109
+ if (len > 0) res.set(b, 0);
1110
+ res[len] = (v >>> 24) & 0xff;
1111
+ res[len + 1] = (v >> 16) & 0xff;
1112
+ res[len + 2] = (v >> 8) & 0xff;
1113
+ res[len + 3] = v & 0xff;
1114
+ return res;
1115
+ },
1116
+ AppendUint64: function(b, v) {
1117
+ const len = b ? b.length : 0;
1118
+ const res = new Uint8Array(len + 8);
1119
+ if (len > 0) res.set(b, 0);
1120
+ const bv = BigInt(v);
1121
+ for (let i = 0n; i < 8n; i++) res[len + Number(i)] = Number((bv >> ((7n - i) * 8n)) & 0xffn);
1122
+ return res;
1123
+ },
1124
+ String: function() { return "BigEndian"; }
1125
+ };
1126
+ var __binary_size = __binary_size || function(v) {
1127
+ if (typeof v === "number" || typeof v === "bigint") return 8;
1128
+ if (Array.isArray(v) || ArrayBuffer.isView(v)) return v.length;
1129
+ if (v && typeof v === "object") {
1130
+ let s = 0;
1131
+ for (const k of Object.keys(v)) { if (!k.startsWith("_") && typeof v[k] !== "function") s += __binary_size(v[k]); }
1132
+ return s;
1133
+ }
1134
+ return -1;
1135
+ };
1136
+ var __binary_read = __binary_read || function(r, order, data, sz, typeTag) {
1137
+ const targetR = r?.value ?? r;
1138
+ const readChunk = function(buf) {
1139
+ if (typeof targetR?.Read === "function") return targetR.Read(buf);
1140
+ if (Array.isArray(targetR?._buf)) {
1141
+ const n = Math.min(buf.length, targetR._buf.length);
1142
+ for (let i = 0; i < n; i++) buf[i] = targetR._buf.shift();
1143
+ return [n, n < buf.length ? __io_eof : null];
1144
+ }
1145
+ return [0, __error("binary.Read: unsupported reader")];
1146
+ };
1147
+ const isBox = data && typeof data === "object" && Object.prototype.hasOwnProperty.call(data, "value") && (data.__box === true || (Object.keys(data).length <= 2 && (data.constructor === Object || !data.constructor || data.constructor?.name === "Object")));
1148
+ const target = isBox ? data : null;
1149
+ if (!target && data && typeof data === "object" && !Array.isArray(data) && !ArrayBuffer.isView(data)) {
1150
+ for (const k of Object.keys(data)) {
1151
+ if (k.startsWith("_") || typeof data[k] === "function") continue;
1152
+ const fBox = { value: data[k], __box: true };
1153
+ const err = __binary_read(r, order, fBox);
1154
+ if (err) return err;
1155
+ data[k] = fBox.value;
1156
+ }
1157
+ return null;
1158
+ }
1159
+ const s = sz || (target ? (typeof target.value === "bigint" ? 8 : (typeof target.value === "number" ? 4 : 4)) : __binary_size(data?.value ?? data));
1160
+ if (s <= 0) return __error("binary.Read: invalid type");
1161
+ const buf = new Uint8Array(s);
1162
+ const [n, err] = readChunk(buf);
1163
+ if (err) return err;
1164
+ if (n < s) return __io_eof;
1165
+ if (target) {
1166
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
1167
+ const isLe = order.String() === "LittleEndian";
1168
+ if (typeTag === "float32") target.value = view.getFloat32(0, isLe);
1169
+ else if (typeTag === "float64") target.value = view.getFloat64(0, isLe);
1170
+ else if (typeTag === "int8") target.value = view.getInt8(0);
1171
+ else if (typeTag === "uint8" || typeTag === "byte" || typeTag === "bool") target.value = view.getUint8(0);
1172
+ else if (typeTag === "int16") target.value = view.getInt16(0, isLe);
1173
+ else if (typeTag === "uint16") target.value = view.getUint16(0, isLe);
1174
+ else if (typeTag === "int32" || typeTag === "rune") target.value = view.getInt32(0, isLe);
1175
+ else if (typeTag === "uint32") target.value = view.getUint32(0, isLe);
1176
+ else if (typeTag === "int64") target.value = Number(view.getBigInt64(0, isLe));
1177
+ else if (typeTag === "uint64") target.value = Number(view.getBigUint64(0, isLe));
1178
+ else if (s === 1) target.value = buf[0];
1179
+ else if (s === 2) target.value = order.Uint16(buf);
1180
+ else if (s === 4) target.value = order.Uint32(buf);
1181
+ else if (s === 8) target.value = order.Uint64(buf);
1182
+ return null;
1183
+ }
1184
+ if (Array.isArray(data) || ArrayBuffer.isView(data)) {
1185
+ for (let i = 0; i < s; i++) data[i] = buf[i];
1186
+ return null;
1187
+ }
1188
+ return null;
1189
+ };
1190
+ var __binary_write = __binary_write || function(w, order, data, sz, typeTag) {
1191
+ const targetW = w?.value ?? w;
1192
+ const writeChunk = function(chunk) {
1193
+ if (typeof targetW?.Write === "function") return targetW.Write(chunk);
1194
+ if (Array.isArray(targetW?._buf)) {
1195
+ for (let i = 0; i < chunk.length; i++) targetW._buf.push(chunk[i]);
1196
+ return [chunk.length, null];
1197
+ }
1198
+ if (typeof targetW?._buf === "string") {
1199
+ targetW._buf += new TextDecoder().decode(chunk);
1200
+ return [chunk.length, null];
1201
+ }
1202
+ return [0, __error("binary.Write: unsupported writer")];
1203
+ };
1204
+ const isBox = data && typeof data === "object" && Object.prototype.hasOwnProperty.call(data, "value") && (data.__box === true || (Object.keys(data).length <= 2 && (data.constructor === Object || !data.constructor || data.constructor?.name === "Object")));
1205
+ const v = isBox ? data.value : data;
1206
+ if (!isBox && typeof data === "object" && data !== null && !Array.isArray(data) && !ArrayBuffer.isView(data)) {
1207
+ for (const k of Object.keys(data)) {
1208
+ if (k.startsWith("_") || typeof data[k] === "function") continue;
1209
+ const err = __binary_write(w, order, data[k]);
1210
+ if (err) return err;
1211
+ }
1212
+ return null;
1213
+ }
1214
+ if (typeof v === "number" || typeof v === "bigint" || typeof v === "boolean") {
1215
+ const s = sz || (typeof v === "bigint" ? 8 : (typeTag === "float64" ? 8 : 4));
1216
+ const buf = new Uint8Array(s);
1217
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
1218
+ const isLe = order.String() === "LittleEndian";
1219
+ if (typeTag === "float32") view.setFloat32(0, Number(v), isLe);
1220
+ else if (typeTag === "float64") view.setFloat64(0, Number(v), isLe);
1221
+ else if (s === 1) buf[0] = Number(v) & 0xff;
1222
+ else if (s === 2) order.PutUint16(buf, Number(v));
1223
+ else if (s === 4) order.PutUint32(buf, Number(v));
1224
+ else order.PutUint64(buf, v);
1225
+ const [, err] = writeChunk(buf);
1226
+ return err;
1227
+ }
1228
+ if (Array.isArray(v) || ArrayBuffer.isView(v)) {
1229
+ const [, err] = writeChunk(v);
1230
+ return err;
1231
+ }
1232
+ return __error("binary.Write: unsupported type");
1233
+ };`;
1234
+
1235
+ export const HELPER_HEX = `var __hex_encode_to_string = __hex_encode_to_string || function(src) {
1236
+ if (!src || src.length === 0) return "";
1237
+ let s = "";
1238
+ for (let i = 0; i < src.length; i++) s += src[i].toString(16).padStart(2, "0");
1239
+ return s;
1240
+ };
1241
+ var __hex_decode_string = __hex_decode_string || function(s) {
1242
+ if (s.length % 2 !== 0) return [new Uint8Array(0), __error("encoding/hex: odd length hex string")];
1243
+ const out = new Uint8Array(s.length / 2);
1244
+ for (let i = 0; i < s.length; i += 2) {
1245
+ const pair = s.slice(i, i + 2);
1246
+ if (!/^[0-9a-fA-F]{2}$/.test(pair)) {
1247
+ return [out.subarray(0, i / 2), __error("encoding/hex: invalid byte: " + pair)];
1248
+ }
1249
+ out[i / 2] = parseInt(pair, 16);
1250
+ }
1251
+ return [out, null];
1252
+ };
1253
+ var __hex_encode = __hex_encode || function(dst, src) {
1254
+ const hex = __hex_encode_to_string(src);
1255
+ for (let i = 0; i < hex.length; i++) dst[i] = hex.charCodeAt(i);
1256
+ return hex.length;
1257
+ };
1258
+ var __hex_decode = __hex_decode || function(dst, src) {
1259
+ const str = typeof src === "string" ? src : (src instanceof Uint8Array ? new TextDecoder().decode(src) : String.fromCharCode(...src));
1260
+ const [res, err] = __hex_decode_string(str);
1261
+ for (let i = 0; i < res.length; i++) dst[i] = res[i];
1262
+ return [res.length, err];
1263
+ };`;
1264
+
1265
+ export const HELPER_BASE64 = `var __base64_make = __base64_make || function(alphabet, padChar) {
1266
+ const encMap = alphabet.split("");
1267
+ const decMap = {};
1268
+ for (let i = 0; i < 64; i++) decMap[alphabet[i]] = i;
1269
+ return {
1270
+ EncodeToString: function(src) {
1271
+ if (!src || src.length === 0) return "";
1272
+ let res = "";
1273
+ let i = 0;
1274
+ for (; i + 2 < src.length; i += 3) {
1275
+ const n = (src[i] << 16) | (src[i + 1] << 8) | src[i + 2];
1276
+ res += encMap[(n >> 18) & 63] + encMap[(n >> 12) & 63] + encMap[(n >> 6) & 63] + encMap[n & 63];
1277
+ }
1278
+ if (i < src.length) {
1279
+ if (src.length - i === 1) {
1280
+ const n = src[i] << 16;
1281
+ res += encMap[(n >> 18) & 63] + encMap[(n >> 12) & 63];
1282
+ if (padChar) res += padChar + padChar;
1283
+ } else {
1284
+ const n = (src[i] << 16) | (src[i + 1] << 8);
1285
+ res += encMap[(n >> 18) & 63] + encMap[(n >> 12) & 63] + encMap[(n >> 6) & 63];
1286
+ if (padChar) res += padChar;
1287
+ }
1288
+ }
1289
+ return res;
1290
+ },
1291
+ DecodeString: function(s) {
1292
+ let str = s.replace(/\\s+/g, "");
1293
+ if (padChar) {
1294
+ if (str.length % 4 !== 0) return [new Uint8Array(0), __error("illegal base64 data at input byte " + str.length)];
1295
+ if (str.endsWith(padChar + padChar)) {
1296
+ if (str.endsWith(padChar + padChar + padChar)) return [new Uint8Array(0), __error("illegal base64 data at input byte " + (str.length - 3))];
1297
+ str = str.slice(0, -2);
1298
+ if (str.length % 4 !== 2) return [new Uint8Array(0), __error("illegal base64 data at input byte " + str.length)];
1299
+ } else if (str.endsWith(padChar)) {
1300
+ str = str.slice(0, -1);
1301
+ if (str.length % 4 !== 3) return [new Uint8Array(0), __error("illegal base64 data at input byte " + str.length)];
1302
+ }
1303
+ }
1304
+ const out = [];
1305
+ let i = 0;
1306
+ for (; i + 3 < str.length; i += 4) {
1307
+ const c0 = decMap[str[i]], c1 = decMap[str[i+1]], c2 = decMap[str[i+2]], c3 = decMap[str[i+3]];
1308
+ if (c0 === undefined || c1 === undefined || c2 === undefined || c3 === undefined) return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
1309
+ const n = (c0 << 18) | (c1 << 12) | (c2 << 6) | c3;
1310
+ out.push((n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff);
1311
+ }
1312
+ const rem = str.length - i;
1313
+ if (rem === 2) {
1314
+ const c0 = decMap[str[i]], c1 = decMap[str[i+1]];
1315
+ if (c0 === undefined || c1 === undefined) return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
1316
+ out.push((c0 << 2) | (c1 >> 4));
1317
+ } else if (rem === 3) {
1318
+ const c0 = decMap[str[i]], c1 = decMap[str[i+1]], c2 = decMap[str[i+2]];
1319
+ if (c0 === undefined || c1 === undefined || c2 === undefined) return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
1320
+ out.push((c0 << 2) | (c1 >> 4), ((c1 & 15) << 4) | (c2 >> 2));
1321
+ } else if (rem === 1) {
1322
+ return [new Uint8Array(out), __error("illegal base64 data at input byte " + i)];
1323
+ }
1324
+ return [new Uint8Array(out), null];
1325
+ },
1326
+ Encode: function(dst, src) {
1327
+ const s = this.EncodeToString(src);
1328
+ for (let i = 0; i < s.length; i++) dst[i] = s.charCodeAt(i);
1329
+ },
1330
+ Decode: function(dst, src) {
1331
+ const str = String.fromCharCode(...src);
1332
+ const [res, err] = this.DecodeString(str);
1333
+ for (let i = 0; i < res.length; i++) dst[i] = res[i];
1334
+ return [res.length, err];
1335
+ },
1336
+ EncodedLen: function(n) { return padChar ? Math.ceil(n / 3) * 4 : Math.floor((n * 8 + 5) / 6); },
1337
+ DecodedLen: function(n) { return padChar ? Math.floor(n * 3 / 4) : Math.floor(n * 6 / 8); },
1338
+ WithPadding: function(p) { return __base64_make(alphabet, p === -1 ? "" : String.fromCharCode(p)); }
1339
+ };
1340
+ };
1341
+ var __base64_std = __base64_std || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "=");
1342
+ var __base64_url = __base64_url || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "=");
1343
+ var __base64_raw_std = __base64_raw_std || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "");
1344
+ var __base64_raw_url = __base64_raw_url || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "");`;
1345
+
1346
+ export const HELPER_JSON = `var __json_esc = __json_esc || function(s) {
1347
+ if (typeof s !== "string") s = String(s);
1348
+ return JSON.stringify(s)
1349
+ .replace(/[<>&]/g, function(c) {
1350
+ return c === "<" ? "\\\\u003c" : (c === ">" ? "\\\\u003e" : "\\\\u0026");
1351
+ })
1352
+ .replace(/\\u2028/g, "\\\\u2028")
1353
+ .replace(/\\u2029/g, "\\\\u2029");
1354
+ };
1355
+ var __json_err = __json_err || function(msg) {
1356
+ return typeof __error === "function" ? __error("json: " + msg) : new Error("json: " + msg);
1357
+ };
1358
+ // Decode error context, as in Go: innermost struct being decoded plus the path
1359
+ // of JSON field names from the root. Reset by every __json_unmarshal call.
1360
+ var __json_structs = __json_structs || [];
1361
+ var __json_path = __json_path || [];
1362
+ var __json_ctx = __json_ctx || function(typeName) {
1363
+ if (__json_path.length > 0 && __json_structs.length > 0) {
1364
+ return "Go struct field " + __json_structs[__json_structs.length - 1] + "." + __json_path.join(".") + " of type " + typeName;
1365
+ }
1366
+ return "Go value of type " + typeName;
1367
+ };
1368
+ // The JSON source text of a number, for "cannot unmarshal number <literal>" messages.
1369
+ var __json_lit = __json_lit || function(v, raw) {
1370
+ if (raw !== undefined && raw !== null) return String(raw).trim();
1371
+ return typeof v === "string" ? v.replace(/__bigint$/, "") : String(v);
1372
+ };
1373
+ var __json_float_decode = __json_float_decode || function(v, bits, ctxType, raw) {
1374
+ var n = __json_number_value(v);
1375
+ if (typeof n !== "number") return __json_err("cannot unmarshal " + __json_type(v) + " into " + __json_ctx(ctxType));
1376
+ var f = bits === 32 ? Math.fround(n) : n;
1377
+ if (!isFinite(f)) return __json_err("cannot unmarshal number " + __json_lit(v, raw) + " into " + __json_ctx(ctxType));
1378
+ return f;
1379
+ };
1380
+ // []byte accepts a base64 string or (like Go) an array of uint8 values.
1381
+ var __json_bytes_decode = __json_bytes_decode || function(v) {
1382
+ if (Array.isArray(v)) {
1383
+ var u8 = new Uint8Array(v.length);
1384
+ for (var i = 0; i < v.length; i++) {
1385
+ var b = __json_int_decode(v[i], "uint8", "uint8", __json_raw_child(v, i));
1386
+ if (b && b._msg) return b;
1387
+ u8[i] = b;
1388
+ }
1389
+ return u8;
1390
+ }
1391
+ if (typeof v !== "string") return __json_err("cannot unmarshal " + __json_type(v) + " into " + __json_ctx("[]uint8"));
1392
+ return __json_b64_dec(v);
1393
+ };
1394
+ var __json_esc_noh = __json_esc_noh || function(s) {
1395
+ return JSON.stringify(String(s)).replace(/\\u2028/g, "\\\\u2028").replace(/\\u2029/g, "\\\\u2029");
1396
+ };
1397
+ var __json_syntax_msg = __json_syntax_msg || function(s) {
1398
+ var t = String(s).trim();
1399
+ if (t === "") return "unexpected end of JSON input";
1400
+ var m;
1401
+ try { JSON.parse(t); } catch (e) { m = String(e && e.message); }
1402
+ if (m && /end of JSON input|Unterminated/.test(m)) return "unexpected end of JSON input";
1403
+ var pos = m && /after JSON at position (\\d+)/.exec(m);
1404
+ if (pos) return "invalid character '" + t[Number(pos[1])] + "' after top-level value";
1405
+ if ("{[\\"-0123456789tfn".indexOf(t[0]) < 0) return "invalid character '" + t[0] + "' looking for beginning of value";
1406
+ return "invalid character in JSON value";
1407
+ };
1408
+ // Validates and compacts JSON text, escaping <, >, & and U+2028/U+2029 inside strings.
1409
+ var __json_compact = __json_compact || function(s) {
1410
+ try { JSON.parse(s); } catch (e) { return null; }
1411
+ var out = "", inStr = false, esc = false;
1412
+ for (var i = 0; i < s.length; i++) {
1413
+ var c = s[i];
1414
+ if (inStr) {
1415
+ if (esc) { esc = false; out += c; continue; }
1416
+ if (c === "\\\\") { esc = true; out += c; continue; }
1417
+ if (c === '"') inStr = false;
1418
+ if (c === "<") out += "\\\\u003c";
1419
+ else if (c === ">") out += "\\\\u003e";
1420
+ else if (c === "&") out += "\\\\u0026";
1421
+ else if (c === "\\u2028") out += "\\\\u2028";
1422
+ else if (c === "\\u2029") out += "\\\\u2029";
1423
+ else out += c;
1424
+ continue;
1425
+ }
1426
+ if (c === '"') { inStr = true; out += c; continue; }
1427
+ if (c === " " || c === "\\t" || c === "\\n" || c === "\\r") continue;
1428
+ out += c;
1429
+ }
1430
+ return out;
1431
+ };
1432
+ var __json_marshaler_out = __json_marshaler_out || function(res, typeName) {
1433
+ var err = res && res[1];
1434
+ if (err) throw new Error("json: error calling MarshalJSON for type " + typeName + ": " + (typeof err.Error === "function" ? err.Error() : String(err)));
1435
+ var b = res ? res[0] : null;
1436
+ var s = b === null || b === undefined ? "" : (typeof b === "string" ? b : new TextDecoder().decode(b));
1437
+ var c = __json_compact(s);
1438
+ if (c === null) throw new Error("json: error calling MarshalJSON for type " + typeName + ": " + __json_syntax_msg(s));
1439
+ return c;
1440
+ };
1441
+ // Keeps user errors returned by UnmarshalJSON intact while fitting the decoders'
1442
+ // "_msg"-tagged error protocol; __json_unmarshal unwraps __userErr.
1443
+ var __json_user_err = __json_user_err || function(e) {
1444
+ if (e && e._msg !== undefined) return e;
1445
+ return { _msg: e && typeof e.Error === "function" ? e.Error() : String(e), __userErr: e };
1446
+ };
1447
+ // Decodes the JSON string payload of a ,string field. Returns { v } or an error.
1448
+ var __json_unquote = __json_unquote || function(val, kind, typeStr) {
1449
+ if (val === null) return { v: null, lit: "null" };
1450
+ if (typeof val !== "string" || val.endsWith("__bigint")) {
1451
+ return __json_err("invalid use of ,string struct tag, trying to unmarshal unquoted value into " + typeStr);
1452
+ }
1453
+ var invalid = function() {
1454
+ return __json_err("invalid use of ,string struct tag, trying to unmarshal " + JSON.stringify(val) + " into " + typeStr);
1455
+ };
1456
+ var inner;
1457
+ try { inner = JSON.parse(__json_preserve_int64(val)); } catch (e) {
1458
+ if (kind !== "string" && kind !== "bool" && /^-?[0-9]/.test(val)) return __json_err("cannot unmarshal number " + val + " into " + __json_ctx(typeStr));
1459
+ return invalid();
1460
+ }
1461
+ if (inner === null) return { v: null, lit: val };
1462
+ if (kind === "string") return typeof inner === "string" ? { v: inner, lit: val } : invalid();
1463
+ if (kind === "bool") return typeof inner === "number" ? invalid() : { v: inner, lit: val };
1464
+ return typeof inner === "boolean" ? invalid() : { v: inner, lit: val };
1465
+ };
1466
+ var __json_type = __json_type || function(v) {
1467
+ if (v === null) return "null";
1468
+ if (Array.isArray(v)) return "array";
1469
+ var t = typeof v;
1470
+ if (t === "number" || t === "bigint") return "number";
1471
+ if (t === "string") return "string";
1472
+ if (t === "boolean") return "bool";
1473
+ if (t === "object") return "object";
1474
+ return t;
1475
+ };
1476
+ var __json_raw_index = __json_raw_index || new WeakMap();
1477
+ var __json_parse_raw_node = __json_parse_raw_node || function(s) {
1478
+ var i = 0;
1479
+ function ws() { while (i < s.length && /[\\t\\n\\r ]/.test(s[i])) i++; }
1480
+ function stringEnd() {
1481
+ i++;
1482
+ while (i < s.length) {
1483
+ if (s[i] === "\\\\") i += 2;
1484
+ else if (s[i++] === '"') break;
1485
+ }
1486
+ }
1487
+ function value() {
1488
+ ws();
1489
+ var start = i;
1490
+ var node = { children: null };
1491
+ if (s[i] === "{") {
1492
+ i++;
1493
+ node.children = new Map();
1494
+ ws();
1495
+ while (s[i] !== "}") {
1496
+ var keyStart = i;
1497
+ stringEnd();
1498
+ var key = JSON.parse(s.slice(keyStart, i));
1499
+ ws();
1500
+ i++;
1501
+ var child = value();
1502
+ node.children.set(key, child);
1503
+ ws();
1504
+ if (s[i] === ",") { i++; ws(); }
1505
+ else break;
1506
+ }
1507
+ i++;
1508
+ } else if (s[i] === "[") {
1509
+ i++;
1510
+ node.children = new Map();
1511
+ ws();
1512
+ var index = 0;
1513
+ while (s[i] !== "]") {
1514
+ node.children.set(String(index++), value());
1515
+ ws();
1516
+ if (s[i] === ",") { i++; ws(); }
1517
+ else break;
1518
+ }
1519
+ i++;
1520
+ } else if (s[i] === '"') {
1521
+ stringEnd();
1522
+ } else {
1523
+ while (i < s.length && !/[\\t\\n\\r ,}\\]]/.test(s[i])) i++;
1524
+ }
1525
+ node.raw = s.slice(start, i);
1526
+ return node;
1527
+ }
1528
+ return value();
1529
+ };
1530
+ var __json_bind_raw = __json_bind_raw || function(value, node) {
1531
+ if (value === null || typeof value !== "object" || !node?.children) return;
1532
+ __json_raw_index.set(value, node.children);
1533
+ for (const [key, child] of node.children) __json_bind_raw(value[key], child);
1534
+ };
1535
+ var __json_raw_child = __json_raw_child || function(parent, key) {
1536
+ return __json_raw_index.get(parent)?.get(String(key))?.raw;
1537
+ };
1538
+ var __json_raw_bytes = __json_raw_bytes || function(raw) {
1539
+ return new TextEncoder().encode(raw ?? "null");
1540
+ };
1541
+ var __json_match_field = __json_match_field || function(obj, tagName, fieldName) {
1542
+ if (Object.prototype.hasOwnProperty.call(obj, tagName)) return tagName;
1543
+ if (Object.prototype.hasOwnProperty.call(obj, fieldName)) return fieldName;
1544
+ var tagFold = tagName.toLowerCase();
1545
+ var fieldFold = fieldName.toLowerCase();
1546
+ for (const key of Object.keys(obj)) {
1547
+ var keyFold = key.toLowerCase();
1548
+ if (keyFold === tagFold || keyFold === fieldFold) return key;
1549
+ }
1550
+ return null;
1551
+ };
1552
+ var __json_float32 = __json_float32 || function(v) {
1553
+ var f = Math.fround(v);
1554
+ if (!isFinite(f)) throw new Error("json: unsupported value: " + f);
1555
+ if (Object.is(f, -0)) return "-0";
1556
+ var candidate;
1557
+ for (var precision = 1; precision <= 9; precision++) {
1558
+ candidate = f.toPrecision(precision);
1559
+ if (Math.fround(Number(candidate)) === f) break;
1560
+ }
1561
+ var n = Number(candidate);
1562
+ var expText = n.toExponential();
1563
+ var match = /e([+-]?)(\\d+)$/.exec(expText);
1564
+ var exponent = Number(match[2]) * (match[1] === "-" ? -1 : 1);
1565
+ if (exponent < -6 || exponent >= 21) {
1566
+ var mantissa = expText.slice(0, expText.indexOf("e"));
1567
+ var sign = exponent >= 0 ? "+" : "-";
1568
+ return mantissa + "e" + sign + String(Math.abs(exponent));
1569
+ }
1570
+ return n.toString();
1571
+ };
1572
+ var __json_number_value = __json_number_value || function(v) {
1573
+ return typeof v === "string" && v.endsWith("__bigint") ? Number(v.slice(0, -8)) : v;
1574
+ };
1575
+ var __json_int_decode = __json_int_decode || function(v, typeName, ctxType, raw) {
1576
+ var type = typeof v === "string" && v.endsWith("__bigint") ? "number" : __json_type(v);
1577
+ var fail = function() {
1578
+ return __json_err("cannot unmarshal " + (type === "number" ? "number " + __json_lit(v, raw) : type) + " into " + __json_ctx(ctxType));
1579
+ };
1580
+ if (type !== "number") return fail();
1581
+ // Go parses integers with strconv.ParseInt: "1.0" and "1e2" are not integers.
1582
+ if (raw !== undefined && raw !== null && !/^-?(0|[1-9][0-9]*)$/.test(String(raw).trim())) return fail();
1583
+ var integer;
1584
+ var signed = typeName === "int" || typeName.startsWith("int");
1585
+ if (typeName === "int64" || typeName === "uint64") {
1586
+ if (typeof v === "string" && v.endsWith("__bigint")) {
1587
+ try { integer = BigInt(v.slice(0, -8)); } catch (_) {}
1588
+ } else if (typeof v === "number" && Number.isSafeInteger(v)) {
1589
+ integer = BigInt(v);
1590
+ }
1591
+ if (integer !== undefined) {
1592
+ var min64 = typeName === "int64" ? -(1n << 63n) : 0n;
1593
+ var max64 = typeName === "int64" ? (1n << 63n) - 1n : (1n << 64n) - 1n;
1594
+ if (integer >= min64 && integer <= max64) return typeof v === "number" ? v : integer;
1595
+ }
1596
+ return fail();
1597
+ }
1598
+ if (typeof v === "number" && Number.isSafeInteger(v)) {
1599
+ if (typeName === "int") return v;
1600
+ var bits = typeName === "uint" ? 53 : Number(typeName.replace(/^(u?int|byte|rune)/, ""));
1601
+ if (!bits) bits = typeName === "byte" ? 8 : typeName === "rune" ? 32 : 53;
1602
+ var min = signed ? -(2 ** (bits - 1)) : 0;
1603
+ var max = signed ? (2 ** (bits - 1)) - 1 : (2 ** bits) - 1;
1604
+ if (v >= min && v <= max) return v;
1605
+ }
1606
+ return fail();
1607
+ };
1608
+ var __json_b64 = __json_b64 || function(u8) {
1609
+ if (u8 === null || u8 === undefined) return "null";
1610
+ if (typeof __base64_std !== "undefined") return '"' + __base64_std.EncodeToString(u8) + '"';
1611
+ var bstr = "";
1612
+ for (var i = 0; i < u8.length; i++) bstr += String.fromCharCode(u8[i]);
1613
+ return '"' + (typeof btoa !== "undefined" ? btoa(bstr) : Buffer.from(u8).toString("base64")) + '"';
1614
+ };
1615
+ var __json_b64_dec = __json_b64_dec || function(str) {
1616
+ if (typeof __base64_std !== "undefined") {
1617
+ var res = __base64_std.DecodeString(str);
1618
+ if (!res[1]) return res[0];
1619
+ }
1620
+ var bin = typeof atob !== "undefined" ? atob(str) : Buffer.from(str, "base64").toString("binary");
1621
+ var u8 = new Uint8Array(bin.length);
1622
+ for (var i = 0; i < bin.length; i++) u8[i] = bin.charCodeAt(i);
1623
+ return u8;
1624
+ };
1625
+ var __json_is_zero = __json_is_zero || function(val, isStruct) {
1626
+ if (isStruct) return false;
1627
+ if (val === null || val === undefined || val === false || val === 0 || val === "") return true;
1628
+ if (typeof val === "bigint") return val === 0n;
1629
+ if (Array.isArray(val) || (ArrayBuffer.isView(val) && !val.__raw)) return val.length === 0;
1630
+ if (val instanceof Map) return val.size === 0;
1631
+ if (val && val.__map) return Object.keys(val).filter(function(k) { return !k.startsWith("__"); }).length === 0;
1632
+ return false;
1633
+ };
1634
+ var __json_preserve_int64 = __json_preserve_int64 || function(str) {
1635
+ return str.replace(/"(?:\\\\.|[^"\\\\])*"|(?<=[,:\\[{\\s]|^)(-?\\d{16,})(?=[,\\]}\\s]|$)/g, function(m, num) {
1636
+ if (num) {
1637
+ try {
1638
+ var b = BigInt(num);
1639
+ if (b > 9007199254740991n || b < -9007199254740991n) return '"' + num + '__bigint"';
1640
+ } catch (e) {}
1641
+ }
1642
+ return m;
1643
+ });
1644
+ };
1645
+ var __json_enc_any = __json_enc_any || function(v) {
1646
+ if (v === null || v === undefined) return "null";
1647
+ var t = typeof v;
1648
+ if (t === "boolean") return v ? "true" : "false";
1649
+ if (t === "number") {
1650
+ if (!isFinite(v)) throw new Error("json: unsupported value: " + v);
1651
+ return String(v);
1652
+ }
1653
+ if (t === "bigint") return v.toString();
1654
+ if (t === "string") return __json_esc(v);
1655
+ if ((typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(v)) || v instanceof Uint8Array) {
1656
+ if (v.__raw) {
1657
+ var s = (typeof v === "string" ? v : new TextDecoder().decode(v)).trim();
1658
+ return s.length > 0 ? s : "null";
1659
+ }
1660
+ return __json_b64(v);
1661
+ }
1662
+ if (Array.isArray(v)) {
1663
+ var items = [];
1664
+ for (var i = 0; i < v.length; i++) items.push(__json_enc_any(v[i]));
1665
+ return "[" + items.join(",") + "]";
1666
+ }
1667
+ if (v instanceof Map) {
1668
+ var mkeys = Array.from(v.keys()).map(String).sort();
1669
+ var mentries = [];
1670
+ for (var mi = 0; mi < mkeys.length; mi++) {
1671
+ mentries.push(__json_esc(mkeys[mi]) + ":" + __json_enc_any(v.get(mkeys[mi])));
1672
+ }
1673
+ return "{" + mentries.join(",") + "}";
1674
+ }
1675
+ if (typeof v.__json_enc === "function") return v.__json_enc();
1676
+ if (typeof v.MarshalJSON === "function" && !(v.__v === true && v.MarshalJSON.__ptrRecv)) {
1677
+ return __json_marshaler_out(v.MarshalJSON(), v.constructor && v.constructor.name ? v.constructor.name : "value");
1678
+ }
1679
+ // Boxed named values (from an interface) encode as their value; *T boxes as the pointee.
1680
+ if (typeof v.__gfUnbox === "function") {
1681
+ var inner = v.__gfUnbox();
1682
+ if (Object.prototype.hasOwnProperty.call(v, "_p")) inner = inner == null ? null : inner.value;
1683
+ return __json_enc_any(inner);
1684
+ }
1685
+ if (typeof v === "object") {
1686
+ var okeys = Object.keys(v).filter(function(k) { return !k.startsWith("__") || k === "__proto__"; });
1687
+ if (!v.__map && v.constructor && v.constructor !== Object && v.constructor.name !== "Object") {
1688
+ okeys = okeys.filter(function(k) { return !(k.length > 0 && k[0] >= "a" && k[0] <= "z"); });
1689
+ }
1690
+ okeys.sort();
1691
+ var oentries = [];
1692
+ for (var oi = 0; oi < okeys.length; oi++) {
1693
+ oentries.push(__json_esc(okeys[oi]) + ":" + __json_enc_any(v[okeys[oi]]));
1694
+ }
1695
+ return "{" + oentries.join(",") + "}";
1696
+ }
1697
+ return "null";
1698
+ };
1699
+ var __json_dec_any = __json_dec_any || function(parsed) {
1700
+ if (parsed === null) return null;
1701
+ if (typeof parsed === "string") {
1702
+ if (parsed.endsWith("__bigint")) return Number(parsed.slice(0, -8));
1703
+ return parsed;
1704
+ }
1705
+ if (typeof parsed === "number" || typeof parsed === "boolean") return parsed;
1706
+ if (Array.isArray(parsed)) {
1707
+ var outSlice = [];
1708
+ for (var i = 0; i < parsed.length; i++) outSlice.push(__json_dec_any(parsed[i]));
1709
+ return outSlice;
1710
+ }
1711
+ if (typeof parsed === "object") {
1712
+ var outMap = Object.create(null);
1713
+ outMap.__map = true;
1714
+ for (var k in parsed) {
1715
+ if (Object.prototype.hasOwnProperty.call(parsed, k)) {
1716
+ outMap[k] = __json_dec_any(parsed[k]);
1717
+ }
1718
+ }
1719
+ return outMap;
1720
+ }
1721
+ return parsed;
1722
+ };
1723
+ var __json_dec_any_target = __json_dec_any_target || function(parsed, target, box) {
1724
+ var out = __json_dec_any(parsed);
1725
+ if (box) box.value = out;
1726
+ else if (target && typeof target === "object") {
1727
+ for (const k of Object.keys(out)) Object.defineProperty(target, k, { value: out[k], writable: true, enumerable: true, configurable: true });
1728
+ }
1729
+ return null;
1730
+ };
1731
+ var __json_enc_slice = __json_enc_slice || function(slice, elemEnc) {
1732
+ if (slice === null || slice === undefined) return "null";
1733
+ var items = [];
1734
+ for (var i = 0; i < slice.length; i++) items.push(elemEnc(slice[i]));
1735
+ return "[" + items.join(",") + "]";
1736
+ };
1737
+ var __json_enc_map = __json_enc_map || function(m, valEnc) {
1738
+ if (m === null || m === undefined) return "null";
1739
+ if (m instanceof Map) {
1740
+ var mkeys = Array.from(m.keys()).map(String).sort();
1741
+ var mentries = [];
1742
+ for (var i = 0; i < mkeys.length; i++) {
1743
+ mentries.push(__json_esc(mkeys[i]) + ":" + valEnc(m.get(mkeys[i])));
1744
+ }
1745
+ return "{" + mentries.join(",") + "}";
1746
+ }
1747
+ var keys = Object.keys(m).filter(function(k) { return !k.startsWith("__") || k === "__proto__"; }).sort();
1748
+ var entries = [];
1749
+ for (var j = 0; j < keys.length; j++) {
1750
+ entries.push(__json_esc(keys[j]) + ":" + valEnc(m[keys[j]]));
1751
+ }
1752
+ return "{" + entries.join(",") + "}";
1753
+ };
1754
+ var __json_marshal = __json_marshal || function(enc, val) {
1755
+ try {
1756
+ var str = enc(val);
1757
+ return [new TextEncoder().encode(str), null];
1758
+ } catch (e) {
1759
+ return [new Uint8Array(0), typeof __error === "function" ? __error(e.message) : e];
1760
+ }
1761
+ };
1762
+ var __json_indent = __json_indent || function(jsonStr, prefix, indent) {
1763
+ var out = "";
1764
+ var depth = 0;
1765
+ var inString = false;
1766
+ var escaped = false;
1767
+ for (var i = 0; i < jsonStr.length; i++) {
1768
+ var c = jsonStr[i];
1769
+ if (inString) {
1770
+ out += c;
1771
+ if (escaped) escaped = false;
1772
+ else if (c === "\\\\") escaped = true;
1773
+ else if (c === '"') inString = false;
1774
+ continue;
1775
+ }
1776
+ if (c === '"') { inString = true; out += c; continue; }
1777
+ if (c === "{" || c === "[") {
1778
+ out += c;
1779
+ depth++;
1780
+ var next = jsonStr[i + 1];
1781
+ if ((c === "{" && next === "}") || (c === "[" && next === "]")) {
1782
+ out += next;
1783
+ i++;
1784
+ depth--;
1785
+ continue;
1786
+ }
1787
+ out += "\\n" + prefix + indent.repeat(depth);
1788
+ } else if (c === "}" || c === "]") {
1789
+ depth--;
1790
+ out += "\\n" + prefix + indent.repeat(depth) + c;
1791
+ } else if (c === ",") {
1792
+ out += ",\\n" + prefix + indent.repeat(depth);
1793
+ } else if (c === ":") {
1794
+ out += ": ";
1795
+ } else if (c !== " " && c !== "\\t" && c !== "\\n" && c !== "\\r") {
1796
+ out += c;
1797
+ }
1798
+ }
1799
+ return out;
1800
+ };
1801
+ var __json_marshal_indent = __json_marshal_indent || function(enc, val, prefix, indent) {
1802
+ var res = __json_marshal(enc, val);
1803
+ if (res[1]) return res;
1804
+ var rawStr = new TextDecoder().decode(res[0]);
1805
+ var formatted = __json_indent(rawStr, prefix, indent);
1806
+ return [new TextEncoder().encode(formatted), null];
1807
+ };
1808
+ var __json_valid = __json_valid || function(data) {
1809
+ try {
1810
+ var s = typeof data === "string" ? data : new TextDecoder().decode(((typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(data)) || data instanceof Uint8Array) ? data : new Uint8Array(data));
1811
+ JSON.parse(s);
1812
+ return true;
1813
+ } catch (e) {
1814
+ return false;
1815
+ }
1816
+ };
1817
+ var __json_unmarshal = __json_unmarshal || function(dec, data, target) {
1818
+ __json_structs.length = 0;
1819
+ __json_path.length = 0;
1820
+ if (target === null || target === undefined) {
1821
+ return typeof __error === "function" ? __error("json: Unmarshal(nil)") : new Error("json: Unmarshal(nil)");
1822
+ }
1823
+ if (typeof target !== "object" || target.__v === true) {
1824
+ return typeof __error === "function" ? __error("json: Unmarshal(non-pointer " + typeof target + ")") : new Error("json: Unmarshal(non-pointer " + typeof target + ")");
1825
+ }
1826
+ var str;
1827
+ try {
1828
+ str = typeof data === "string" ? data : new TextDecoder().decode(((typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(data)) || data instanceof Uint8Array) ? data : new Uint8Array(data));
1829
+ } catch (e) {
1830
+ return typeof __error === "function" ? __error("invalid UTF-8 data") : e;
1831
+ }
1832
+ var safeStr = __json_preserve_int64(str);
1833
+ var parsed;
1834
+ try {
1835
+ parsed = JSON.parse(safeStr);
1836
+ } catch (e) {
1837
+ return typeof __error === "function" ? __error(e.message) : e;
1838
+ }
1839
+ var rootRaw = __json_parse_raw_node(str);
1840
+ __json_bind_raw(parsed, rootRaw);
1841
+ var isBox = target && typeof target === "object" && (Object.prototype.hasOwnProperty.call(target, "value") || typeof target.__gfUnbox === "function");
1842
+ var dest = isBox ? target.value : target;
1843
+ var err = dec(parsed, dest, isBox ? target : null, data, rootRaw.raw);
1844
+ if (err) return err.__userErr || err;
1845
+ return null;
1846
+ };`;
1847
+
1848
+ export const HELPER_SIMD = `var __simd_f32x4 = __simd_f32x4 || function(a, b, c, d) {
1849
+ return Object.freeze([Math.fround(Number(a ?? 0)), Math.fround(Number(b ?? 0)), Math.fround(Number(c ?? 0)), Math.fround(Number(d ?? 0))]);
1850
+ };
1851
+ var __simd_splat = __simd_splat || function(v) {
1852
+ var s = Math.fround(Number(v ?? 0));
1853
+ return Object.freeze([s, s, s, s]);
1854
+ };
1855
+ var __simd_add = __simd_add || function(a, b) {
1856
+ return Object.freeze([Math.fround(a[0] + b[0]), Math.fround(a[1] + b[1]), Math.fround(a[2] + b[2]), Math.fround(a[3] + b[3])]);
1857
+ };
1858
+ var __simd_sub = __simd_sub || function(a, b) {
1859
+ return Object.freeze([Math.fround(a[0] - b[0]), Math.fround(a[1] - b[1]), Math.fround(a[2] - b[2]), Math.fround(a[3] - b[3])]);
1860
+ };
1861
+ var __simd_mul = __simd_mul || function(a, b) {
1862
+ return Object.freeze([Math.fround(a[0] * b[0]), Math.fround(a[1] * b[1]), Math.fround(a[2] * b[2]), Math.fround(a[3] * b[3])]);
1863
+ };
1864
+ var __simd_div = __simd_div || function(a, b) {
1865
+ return Object.freeze([Math.fround(a[0] / b[0]), Math.fround(a[1] / b[1]), Math.fround(a[2] / b[2]), Math.fround(a[3] / b[3])]);
1866
+ };
1867
+ var __simd_min = __simd_min || function(a, b) {
1868
+ return Object.freeze([Math.fround(Math.min(a[0], b[0])), Math.fround(Math.min(a[1], b[1])), Math.fround(Math.min(a[2], b[2])), Math.fround(Math.min(a[3], b[3]))]);
1869
+ };
1870
+ var __simd_max = __simd_max || function(a, b) {
1871
+ return Object.freeze([Math.fround(Math.max(a[0], b[0])), Math.fround(Math.max(a[1], b[1])), Math.fround(Math.max(a[2], b[2])), Math.fround(Math.max(a[3], b[3]))]);
1872
+ };
1873
+ var __simd_dot3 = __simd_dot3 || function(a, b) {
1874
+ return Math.fround(Math.fround(Math.fround(a[0] * b[0]) + Math.fround(a[1] * b[1])) + Math.fround(a[2] * b[2]));
1875
+ };
1876
+ var __simd_dot4 = __simd_dot4 || function(a, b) {
1877
+ return Math.fround(Math.fround(Math.fround(Math.fround(a[0] * b[0]) + Math.fround(a[1] * b[1])) + Math.fround(a[2] * b[2])) + Math.fround(a[3] * b[3]));
1878
+ };
1879
+ var __simd_with_lane = __simd_with_lane || function(a, i, v) {
1880
+ var r = [a[0], a[1], a[2], a[3]];
1881
+ r[i] = Math.fround(v);
1882
+ return Object.freeze(r);
1883
+ };
1884
+ var __simd_load = __simd_load || function(buf, i) {
1885
+ if (i < 0 || i + 4 > buf.length) throw new Error("panic: runtime error: index out of range");
1886
+ return Object.freeze([Math.fround(buf[i]), Math.fround(buf[i + 1]), Math.fround(buf[i + 2]), Math.fround(buf[i + 3])]);
1887
+ };
1888
+ var __simd_store = __simd_store || function(buf, i, v) {
1889
+ if (i < 0 || i + 4 > buf.length) throw new Error("panic: runtime error: index out of range");
1890
+ buf[i] = v[0]; buf[i + 1] = v[1]; buf[i + 2] = v[2]; buf[i + 3] = v[3];
1891
+ };`;