gofront 1.6.1 → 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.
@@ -131,6 +131,17 @@ export const HELPER_NIL_CALL = `var __nilcall = __nilcall || function(x) {
131
131
  return x;
132
132
  };`;
133
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
+
134
145
  export const HELPER_EQUAL = `var __equal = __equal || function __equal(a, b) {
135
146
  if (a === b) return true;
136
147
  if (a === null || b === null) return false;
@@ -227,6 +238,7 @@ export const HELPER_SPRINTF = `var __sprintf = __sprintf || function(f, ...a) {
227
238
  if (typeof val.Error === "function") {
228
239
  return String(val.Error());
229
240
  }
241
+ if (typeof val.__gfUnbox === "function") return formatV(val.__gfUnbox(), isPlus, isTopLevel);
230
242
  if (Array.isArray(val) || ArrayBuffer.isView(val)) {
231
243
  const isElemPtr = val.__ptr_slice === true;
232
244
  const pf = val.__ptr_fields;
@@ -308,7 +320,9 @@ export const HELPER_SPRINTF = `var __sprintf = __sprintf || function(f, ...a) {
308
320
  return f.replace(/%([#+\\- 0]*)([0-9]*)\\.?([0-9]*)[sdvftxXqobeEgGwc%]/g, (m) => {
309
321
  if (m === "%%") return "%";
310
322
  const verb = m.slice(-1);
311
- 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();
312
326
  const [, flags, width, prec] = m.match(/^%([#+\\- 0]*)([0-9]*)\\.?([0-9]*)/) || [];
313
327
  const zero = flags?.includes("0") && !flags?.includes("-");
314
328
  const pad = (s, w, z) => {
@@ -382,6 +396,9 @@ export const HELPER_IO_EOF = `var __io_eof = __io_eof || __error("EOF");`;
382
396
  export const HELPER_ERROR_IS = `var __errorIs = __errorIs || function __errorIs(err, target) {
383
397
  if (err === null || err === undefined) return false;
384
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;
385
402
  if (typeof err === "object" && typeof target === "object" &&
386
403
  err._msg !== undefined && target._msg !== undefined &&
387
404
  err._msg === target._msg) return true;
@@ -407,7 +424,7 @@ export const HELPER_ERROR_IS = `var __errorIs = __errorIs || function __errorIs(
407
424
  return false;
408
425
  };`;
409
426
 
410
- export const HELPER_ERROR_AS = `var __errorAs = __errorAs || function(err, target, matcher) {
427
+ export const HELPER_ERROR_AS = `var __errorAs = __errorAs || function(err, target, matcher, extract) {
411
428
  if (err === null || err === undefined || target === null || typeof target !== "object") return false;
412
429
  let cur = err;
413
430
  while (cur !== null && cur !== undefined) {
@@ -415,7 +432,7 @@ export const HELPER_ERROR_AS = `var __errorAs = __errorAs || function(err, targe
415
432
  if (typeof cur.As === "function" && cur.As(target)) return true;
416
433
  if (matcher ? matcher(unboxed) : (unboxed !== err && typeof unboxed === "object" && !("_msg" in unboxed && "_cause" in unboxed))) {
417
434
  if ("value" in target) {
418
- target.value = unboxed;
435
+ target.value = extract ? extract(unboxed) : unboxed;
419
436
  } else {
420
437
  Object.assign(target, unboxed);
421
438
  }
@@ -423,17 +440,17 @@ export const HELPER_ERROR_AS = `var __errorAs = __errorAs || function(err, targe
423
440
  }
424
441
  if (Array.isArray(cur._errs)) {
425
442
  for (const sub of cur._errs) {
426
- if (__errorAs(sub, target, matcher)) return true;
443
+ if (__errorAs(sub, target, matcher, extract)) return true;
427
444
  }
428
445
  }
429
446
  if (typeof cur.Unwrap === "function") {
430
447
  const unwrapped = cur.Unwrap();
431
448
  if (Array.isArray(unwrapped)) {
432
449
  for (const sub of unwrapped) {
433
- if (__errorAs(sub, target, matcher)) return true;
450
+ if (__errorAs(sub, target, matcher, extract)) return true;
434
451
  }
435
452
  } else if (unwrapped !== null && unwrapped !== undefined) {
436
- if (__errorAs(unwrapped, target, matcher)) return true;
453
+ if (__errorAs(unwrapped, target, matcher, extract)) return true;
437
454
  }
438
455
  }
439
456
  cur = cur?._cause ?? null;
@@ -1325,3 +1342,550 @@ var __base64_std = __base64_std || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcd
1325
1342
  var __base64_url = __base64_url || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "=");
1326
1343
  var __base64_raw_std = __base64_raw_std || __base64_make("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "");
1327
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
+ };`;