gofront 1.7.0 → 1.9.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.
- package/README.md +14 -14
- package/package.json +10 -38
- package/src/backend/js/expressions.js +2060 -389
- package/src/backend/js/index.js +586 -174
- package/src/backend/js/natives.js +383 -0
- package/src/backend/js/runtime.js +936 -1644
- package/src/backend/js/statements.js +1349 -132
- package/src/backend/js/stdlib/index.js +51 -94
- package/src/backend/js/templ.js +67 -118
- package/src/backend/js/type-info.js +436 -0
- package/src/backend/shared/fixed-float.js +20 -0
- package/src/backend/shared/fmt-types.js +80 -0
- package/src/backend/shared/host-unicode.js +36 -0
- package/src/backend/wasm/boundary.js +753 -872
- package/src/backend/wasm/emit-builtins.js +914 -237
- package/src/backend/wasm/emit-exprs.js +1456 -195
- package/src/backend/wasm/emit-maps.js +78 -380
- package/src/backend/wasm/emit-stmts.js +1659 -214
- package/src/backend/wasm/emit.js +614 -88
- package/src/backend/wasm/encode.js +43 -13
- package/src/backend/wasm/globals.js +491 -0
- package/src/backend/wasm/glue.js +2 -4
- package/src/backend/wasm/index.js +406 -3195
- package/src/backend/wasm/method-expr.js +392 -0
- package/src/backend/wasm/module-emitter.js +1615 -0
- package/src/backend/wasm/monomorph.js +164 -9
- package/src/backend/wasm/natives.js +596 -0
- package/src/backend/wasm/prescan.js +249 -0
- package/src/backend/wasm/prune-funcs.js +89 -0
- package/src/backend/wasm/stdlib/index.js +2 -37
- package/src/backend/wasm/stdlib/simd.js +293 -28
- package/src/backend/wasm/types.js +260 -27
- package/src/backend/wasm/variadic.js +93 -0
- package/src/backend/wasm/wat.js +47 -20
- package/src/{cli-core.js → cli/cli-core.js} +241 -11
- package/src/{test-runner.js → cli/test-runner.js} +188 -122
- package/src/{vendor.js → cli/vendor.js} +3 -4
- package/src/compiler.js +202 -386
- package/src/index.js +15 -169
- package/src/{lexer.js → lexer/lexer.js} +203 -62
- package/src/{templ-lexer.js → lexer/templ-lexer.js} +61 -18
- package/src/{tokens.js → lexer/tokens.js} +2 -0
- package/src/link/sourcemap.js +97 -0
- package/src/link/stdlib.js +737 -0
- package/src/link/type-names.js +148 -0
- package/src/link/wasm.js +318 -0
- package/src/lower/bounds.js +547 -0
- package/src/lower/boxing.js +1 -1
- package/src/lower/captures.js +267 -64
- package/src/lower/embedding.js +32 -3
- package/src/lower/errors-as.js +196 -0
- package/src/lower/fmt-formatters.js +905 -0
- package/src/lower/functions.js +2 -0
- package/src/lower/gen-types.js +274 -0
- package/src/lower/index.js +33 -19
- package/src/lower/json-codecs.js +1379 -0
- package/src/lower/ownership.js +47 -8
- package/src/lower/range.js +86 -1
- package/src/lower/reachability.js +150 -0
- package/src/lower/walk.js +12 -0
- package/src/parser/declarations.js +83 -15
- package/src/parser/expressions.js +110 -18
- package/src/parser/index.js +2 -1
- package/src/parser/statements.js +38 -22
- package/src/{templ-parser.js → parser/templ.js} +179 -17
- package/src/parser/types.js +70 -9
- package/src/resolver.js +21 -1
- package/src/typechecker/assignability.js +291 -19
- package/src/typechecker/const-fold.js +399 -0
- package/src/typechecker/constants.js +282 -0
- package/src/typechecker/expressions.js +1220 -183
- package/src/typechecker/index.js +659 -92
- package/src/typechecker/init-order.js +426 -0
- package/src/typechecker/operand-text.js +40 -0
- package/src/typechecker/resolve.js +613 -62
- package/src/typechecker/statements.js +212 -20
- package/src/typechecker/stdlib/excluded.js +902 -0
- package/src/typechecker/stdlib/index.js +38 -0
- package/src/typechecker/stdlib/simd.js +65 -15
- package/src/typechecker/termination.js +11 -2
- package/src/typechecker/types.js +268 -514
- package/stdlib/bytes/buffer.go +479 -0
- package/stdlib/bytes/bytes.go +1010 -0
- package/stdlib/bytes/reader.go +161 -0
- package/stdlib/cmp/cmp.go +65 -0
- package/stdlib/context/context.go +115 -0
- package/stdlib/crypto/rand/rand.go +34 -0
- package/stdlib/crypto/sha256/sha256.go +249 -0
- package/stdlib/encoding/base64/base64.go +331 -0
- package/stdlib/encoding/binary/binary.go +332 -0
- package/stdlib/encoding/hex/hex.go +140 -0
- package/stdlib/encoding/json/errors.go +31 -0
- package/stdlib/encoding/json/indent.go +71 -0
- package/stdlib/encoding/json/json.go +62 -0
- package/stdlib/encoding/json/number.go +12 -0
- package/stdlib/encoding/json/stream.go +173 -0
- package/stdlib/errors/errors.go +174 -0
- package/stdlib/fmt/errors.go +110 -0
- package/stdlib/fmt/format.go +732 -0
- package/stdlib/fmt/print.go +1232 -0
- package/stdlib/gom/gom.go +293 -0
- package/stdlib/hash/hash.go +53 -0
- package/stdlib/html/html.go +251 -0
- package/stdlib/internal/fmtrt/fmtrt.go +163 -0
- package/stdlib/internal/jsonrt/dec.go +871 -0
- package/stdlib/internal/jsonrt/enc.go +516 -0
- package/stdlib/internal/jsonrt/indent.go +135 -0
- package/stdlib/internal/jsonrt/number.go +27 -0
- package/stdlib/internal/jsonrt/reader.go +73 -0
- package/stdlib/internal/jsonrt/scanner.go +658 -0
- package/stdlib/io/io.go +502 -0
- package/stdlib/iter/iter.go +18 -0
- package/stdlib/maps/maps.go +131 -0
- package/stdlib/math/bits/bits.go +507 -0
- package/stdlib/math/extra.go +272 -0
- package/stdlib/math/math.go +439 -0
- package/stdlib/math/rand/rand.go +297 -0
- package/stdlib/os/os.go +93 -0
- package/stdlib/path/filepath/filepath.go +47 -0
- package/stdlib/path/path.go +394 -0
- package/stdlib/regexp/regexp.go +231 -0
- package/stdlib/slices/slices.go +526 -0
- package/stdlib/slices/sort.go +209 -0
- package/stdlib/slices/zsort_cmp.go +480 -0
- package/stdlib/slices/zsort_ordered.go +482 -0
- package/stdlib/sort/sort.go +500 -0
- package/stdlib/sort/zsort_func.go +480 -0
- package/stdlib/sort/zsort_iface.go +480 -0
- package/stdlib/strconv/float.go +1699 -0
- package/stdlib/strconv/isprint.go +752 -0
- package/stdlib/strconv/quote.go +526 -0
- package/stdlib/strconv/strconv.go +616 -0
- package/stdlib/strings/builder.go +95 -0
- package/stdlib/strings/reader.go +163 -0
- package/stdlib/strings/replacer.go +102 -0
- package/stdlib/strings/strings.go +807 -0
- package/stdlib/sync/sync.go +268 -0
- package/stdlib/testing/async_js.go +61 -0
- package/stdlib/testing/benchmark.go +297 -0
- package/stdlib/testing/testing.go +523 -0
- package/stdlib/time/duration.go +233 -0
- package/stdlib/time/format.go +745 -0
- package/stdlib/time/parse.go +790 -0
- package/stdlib/time/sleep_js.go +63 -0
- package/stdlib/time/time.go +834 -0
- package/stdlib/unicode/unicode.go +250 -0
- package/stdlib/unicode/utf8/utf8.go +464 -0
- package/src/backend/js/stdlib/base64.js +0 -12
- package/src/backend/js/stdlib/binary.js +0 -102
- package/src/backend/js/stdlib/bits.js +0 -46
- package/src/backend/js/stdlib/builder.js +0 -63
- package/src/backend/js/stdlib/bytes.js +0 -122
- package/src/backend/js/stdlib/errors.js +0 -44
- package/src/backend/js/stdlib/fmt.js +0 -178
- package/src/backend/js/stdlib/gom.js +0 -155
- package/src/backend/js/stdlib/hex.js +0 -17
- package/src/backend/js/stdlib/html.js +0 -20
- package/src/backend/js/stdlib/io.js +0 -137
- package/src/backend/js/stdlib/json.js +0 -972
- package/src/backend/js/stdlib/maps.js +0 -45
- package/src/backend/js/stdlib/math.js +0 -69
- package/src/backend/js/stdlib/os.js +0 -13
- package/src/backend/js/stdlib/path.js +0 -48
- package/src/backend/js/stdlib/rand.js +0 -32
- package/src/backend/js/stdlib/regexp.js +0 -54
- package/src/backend/js/stdlib/sha256.js +0 -12
- package/src/backend/js/stdlib/shared.js +0 -17
- package/src/backend/js/stdlib/simd.js +0 -24
- package/src/backend/js/stdlib/slices.js +0 -77
- package/src/backend/js/stdlib/sort.js +0 -30
- package/src/backend/js/stdlib/strconv.js +0 -74
- package/src/backend/js/stdlib/strings.js +0 -222
- package/src/backend/js/stdlib/sync.js +0 -13
- package/src/backend/js/stdlib/testing.js +0 -34
- package/src/backend/js/stdlib/time.js +0 -128
- package/src/backend/js/stdlib/unicode.js +0 -25
- package/src/backend/js/stdlib/utf8.js +0 -26
- package/src/backend/wasm/const-fold.js +0 -205
- package/src/backend/wasm/emit-stdlib.js +0 -13
- package/src/backend/wasm/stdlib/bytes.js +0 -5039
- package/src/backend/wasm/stdlib/core.js +0 -8903
- package/src/backend/wasm/stdlib/io.js +0 -2161
- package/src/backend/wasm/stdlib/packages.js +0 -2400
- package/src/backend/wasm/stdlib/pure.js +0 -720
- package/src/backend/wasm/stdlib/time.js +0 -1200
- package/src/typechecker/stdlib/core.js +0 -801
- package/src/typechecker/stdlib/extended.js +0 -914
- package/src/typechecker/stdlib.js +0 -22
- /package/src/{asset-manager.js → cli/asset-manager.js} +0 -0
- /package/src/{colors.js → cli/colors.js} +0 -0
- /package/src/{dev-server.js → cli/dev-server.js} +0 -0
- /package/src/{minifier.js → cli/minifier.js} +0 -0
- /package/src/{project-config.js → cli/project-config.js} +0 -0
- /package/src/{pwa.js → cli/pwa.js} +0 -0
|
@@ -7,33 +7,288 @@ export const HELPER_LEN = `var __len = __len || function(a) {
|
|
|
7
7
|
return a?.length ?? 0;
|
|
8
8
|
};`;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
// string -> []byte: UTF-8, except that a lone surrogate U+DC80-U+DCFF (a raw
|
|
11
|
+
// byte from a \xNN escape) encodes as that single byte.
|
|
12
|
+
export const HELPER_U8ENC = `var __u8e = __u8e || new TextEncoder();
|
|
13
|
+
var __u8enc = __u8enc || function(s) {
|
|
14
|
+
const e = __u8e;
|
|
15
|
+
if (s.isWellFormed()) return e.encode(s);
|
|
16
|
+
const out = [];
|
|
17
|
+
for (let i = 0; i < s.length; i++) {
|
|
18
|
+
const c = s.charCodeAt(i);
|
|
19
|
+
if (c >= 0xdc80 && c <= 0xdcff && !(i > 0 && (s.charCodeAt(i - 1) & 0xfc00) === 0xd800)) { out.push(c - 0xdc00); continue; }
|
|
20
|
+
const cp = s.codePointAt(i);
|
|
21
|
+
if (cp > 0xffff) i++;
|
|
22
|
+
for (const b of e.encode(String.fromCodePoint(cp))) out.push(b);
|
|
23
|
+
}
|
|
24
|
+
return Uint8Array.from(out);
|
|
25
|
+
};`;
|
|
26
|
+
|
|
27
|
+
// []byte -> string: UTF-8 with U+FFFD for invalid bytes. A typed array is
|
|
28
|
+
// decoded in place; anything else is copied into one first.
|
|
29
|
+
export const HELPER_U8DEC = `var __u8d = __u8d || null;
|
|
30
|
+
var __u8dec = __u8dec || function(b) {
|
|
31
|
+
return (__u8d ??= new TextDecoder()).decode(ArrayBuffer.isView(b) ? b : new Uint8Array(b));
|
|
32
|
+
};`;
|
|
33
|
+
|
|
34
|
+
// Slice views (Go's `b[lo:hi:max]` shares the backing store). A view of a
|
|
35
|
+
// plain array is a Proxy over an empty `__SV` array that holds the backing
|
|
36
|
+
// array `b`, offset `o`, length `n` and capacity `c`: Array.isArray, length,
|
|
37
|
+
// indexing, iteration and the Array.prototype methods work through the traps,
|
|
38
|
+
// so the rest of the runtime and JS callers see an ordinary array (`__SV`
|
|
39
|
+
// makes Array.prototype methods return plain arrays and Node print the
|
|
40
|
+
// elements). A view covering its whole backing array is that array. A
|
|
41
|
+
// typed-array view is a `subarray`; a capacity beyond its length is kept in a
|
|
42
|
+
// WeakMap shared by every compiled module. `__slice` also accepts strings
|
|
43
|
+
// (generic code). `__reslice` is `x = x[lo:hi]`: within `len(x)` a plain
|
|
44
|
+
// array is copied instead (a Proxy is much slower to index, and the old
|
|
45
|
+
// value of `x` is usually dead), see docs/go-compatibility.md.
|
|
46
|
+
// The copy keeps the capacity of the old value: its `__rcap` symbol property
|
|
47
|
+
// (shared by every compiled module) is `{b, o, c, s, so, own}` (backing array,
|
|
48
|
+
// offset, capacity, snapshot of the copy, its offset in `s`, and false while
|
|
49
|
+
// `s` is shared with another copy). An index
|
|
50
|
+
// write `x[i] = v` to a chain that the package self-reslices is followed by
|
|
51
|
+
// `__rcs(x, i)`, which writes the element through to `b` (and `s`), so it is
|
|
52
|
+
// ordered with writes through other slices of `b`. A slice or `append`
|
|
53
|
+
// beyond the copy's length writes the remaining elements that differ from the
|
|
54
|
+
// snapshot (written through other references to the copy) back into `b`
|
|
55
|
+
// first and continues with a view over `b`. `__mkslice` is `make([]T, n, cap)`.
|
|
56
|
+
// `__sv` is its own helper ("sv") so range loops can unwrap a view without
|
|
57
|
+
// pulling in the rest.
|
|
58
|
+
export const HELPER_SV = `var __sv = __sv || Symbol.for("gofront.sliceView");`;
|
|
59
|
+
|
|
60
|
+
export const HELPER_SLICE = `var __tcap = __tcap || (globalThis[Symbol.for("gofront.typedCap")] ??= new WeakMap());
|
|
61
|
+
var __SV = __SV || class extends Array {
|
|
62
|
+
static get [Symbol.species]() { return Array; }
|
|
63
|
+
[Symbol.for("nodejs.util.inspect.custom")]() { return Array.from(this); }
|
|
64
|
+
};
|
|
65
|
+
var __rcap = __rcap || Symbol.for("gofront.resliceCap");
|
|
66
|
+
var __svh = __svh || {
|
|
67
|
+
get(t, k) {
|
|
68
|
+
if (typeof k === "string") {
|
|
69
|
+
const ch = k.charCodeAt(0);
|
|
70
|
+
if (ch >= 48 && ch <= 57) { const i = +k; return i < t.n ? t.b[t.o + i] : undefined; }
|
|
71
|
+
if (k === "length") return t.n;
|
|
72
|
+
} else if (k === __sv) return t;
|
|
73
|
+
return t[k];
|
|
74
|
+
},
|
|
75
|
+
set(t, k, v) {
|
|
76
|
+
if (typeof k === "string") {
|
|
77
|
+
const ch = k.charCodeAt(0);
|
|
78
|
+
if (ch >= 48 && ch <= 57) { const i = +k; if (i < t.n) t.b[t.o + i] = v; return true; }
|
|
79
|
+
if (k === "length") return true;
|
|
80
|
+
}
|
|
81
|
+
t[k] = v;
|
|
82
|
+
return true;
|
|
83
|
+
},
|
|
84
|
+
has(t, k) {
|
|
85
|
+
if (typeof k === "string") {
|
|
86
|
+
const ch = k.charCodeAt(0);
|
|
87
|
+
if (ch >= 48 && ch <= 57) return +k < t.n;
|
|
88
|
+
}
|
|
89
|
+
return k in t;
|
|
90
|
+
},
|
|
91
|
+
defineProperty(t, k, d) {
|
|
92
|
+
if (typeof k === "string") {
|
|
93
|
+
const ch = k.charCodeAt(0);
|
|
94
|
+
if (ch >= 48 && ch <= 57) {
|
|
95
|
+
const i = +k;
|
|
96
|
+
if (i >= t.n || d.get || d.set || d.configurable === false) return false;
|
|
97
|
+
if ("value" in d) t.b[t.o + i] = d.value;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return Reflect.defineProperty(t, k, d);
|
|
102
|
+
},
|
|
103
|
+
preventExtensions() { return false; },
|
|
104
|
+
deleteProperty(t, k) {
|
|
105
|
+
if (typeof k === "string" && k.charCodeAt(0) >= 48 && k.charCodeAt(0) <= 57) return true;
|
|
106
|
+
return delete t[k];
|
|
107
|
+
},
|
|
108
|
+
ownKeys(t) {
|
|
109
|
+
const ks = [];
|
|
110
|
+
for (let i = 0; i < t.n; i++) ks.push(String(i));
|
|
111
|
+
ks.push("length");
|
|
112
|
+
return ks;
|
|
113
|
+
},
|
|
114
|
+
getOwnPropertyDescriptor(t, k) {
|
|
115
|
+
if (typeof k === "string") {
|
|
116
|
+
const ch = k.charCodeAt(0);
|
|
117
|
+
if (ch >= 48 && ch <= 57) {
|
|
118
|
+
const i = +k;
|
|
119
|
+
return i < t.n ? { value: t.b[t.o + i], writable: true, enumerable: true, configurable: true } : undefined;
|
|
120
|
+
}
|
|
121
|
+
if (k === "length") return { value: t.n, writable: true, enumerable: false, configurable: false };
|
|
122
|
+
}
|
|
123
|
+
return Reflect.getOwnPropertyDescriptor(t, k);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
var __mkview = __mkview || function(b, o, n, c, f) {
|
|
127
|
+
if (o === 0 && n === b.length && c === n && !f) return b;
|
|
128
|
+
if (c === 0) return [];
|
|
129
|
+
const t = new __SV();
|
|
130
|
+
t.b = b; t.o = o; t.n = n; t.c = c;
|
|
131
|
+
return new Proxy(t, __svh);
|
|
132
|
+
};
|
|
133
|
+
var __cap = __cap || function(a) {
|
|
134
|
+
if (a == null) return 0;
|
|
135
|
+
const s = a[__sv];
|
|
136
|
+
if (s !== undefined) return s.c;
|
|
137
|
+
if (ArrayBuffer.isView(a)) return __tcap.get(a) ?? a.length;
|
|
138
|
+
return a[__rcap]?.c ?? a.length;
|
|
139
|
+
};
|
|
140
|
+
// A snapshot shared by a copy of a copy (e.own false) is cloned before it is
|
|
141
|
+
// updated, so the update does not reach the other copy's snapshot (whose
|
|
142
|
+
// write-back would then revert the element).
|
|
143
|
+
var __rcown = __rcown || function(e, a) {
|
|
144
|
+
if (e.own === false) { e.s = e.s.slice(e.so, e.so + a.length); e.so = 0; e.own = true; }
|
|
145
|
+
return e.s;
|
|
146
|
+
};
|
|
147
|
+
// Write back only the elements of a __reslice copy that changed since it was
|
|
148
|
+
// made (e.s from e.so is its snapshot, kept up to date by __rcs), so writes
|
|
149
|
+
// made meanwhile through other slices of the backing array are kept.
|
|
150
|
+
var __rcput = __rcput || function(e, a, from, to) {
|
|
151
|
+
for (let i = from; i < to; i++) {
|
|
152
|
+
const v = a[i];
|
|
153
|
+
if (!Object.is(v, e.s[e.so + i])) { e.b[e.o + i] = v; __rcown(e, a)[e.so + i] = v; }
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// After an index write to a possible __reslice copy: write element i through.
|
|
157
|
+
var __rcs = __rcs || function(a, i) {
|
|
158
|
+
const e = a?.[__rcap];
|
|
159
|
+
if (e !== undefined && i >= 0 && i < e.c && i < a.length) { const v = a[i]; e.b[e.o + i] = v; __rcown(e, a)[e.so + i] = v; }
|
|
160
|
+
};
|
|
161
|
+
var __rcdef = __rcdef || function(r, e) {
|
|
162
|
+
Object.defineProperty(r, __rcap, { value: e, writable: true });
|
|
163
|
+
};
|
|
164
|
+
var __rcflush = __rcflush || function(a) {
|
|
165
|
+
const e = a[__rcap];
|
|
166
|
+
if (e !== undefined) __rcput(e, a, 0, a.length);
|
|
167
|
+
return e;
|
|
168
|
+
};
|
|
169
|
+
var __slice = __slice || function(a, lo, hi, max) {
|
|
170
|
+
if (typeof a === "string") return a.slice(lo, hi);
|
|
171
|
+
const s = a == null ? undefined : a[__sv];
|
|
172
|
+
const n = s !== undefined ? s.n : a == null ? 0 : a.length;
|
|
173
|
+
const c = s !== undefined ? s.c : __cap(a);
|
|
174
|
+
const mx = max;
|
|
175
|
+
if (hi === undefined) hi = n;
|
|
176
|
+
if (max === undefined) max = c;
|
|
177
|
+
if (!(lo >= 0 && lo <= hi && hi <= max && max <= c)) throw new Error("runtime error: slice bounds out of range");
|
|
178
|
+
if (a == null) return a;
|
|
179
|
+
if (s !== undefined) return __mkview(s.b, s.o + lo, hi - lo, max - lo);
|
|
180
|
+
if (c > n && Array.isArray(a)) {
|
|
181
|
+
// a is a __reslice copy (only those have cap > len): reach past its
|
|
182
|
+
// length or capacity through the backing array, else stay on the copy
|
|
183
|
+
// (an explicit max needs a view: the copy itself keeps the old cap).
|
|
184
|
+
if (hi <= n && (mx === undefined || mx <= n)) return __mkview(a, lo, hi - lo, Math.min(max, n) - lo, mx !== undefined);
|
|
185
|
+
else { const e = __rcflush(a); return __mkview(e.b, e.o + lo, hi - lo, max - lo); }
|
|
186
|
+
}
|
|
187
|
+
if (ArrayBuffer.isView(a)) {
|
|
188
|
+
const r = hi <= n ? a.subarray(lo, hi) : new a.constructor(a.buffer, a.byteOffset + lo * a.BYTES_PER_ELEMENT, hi - lo);
|
|
189
|
+
if (max - lo > hi - lo) __tcap.set(r, max - lo);
|
|
190
|
+
return r;
|
|
191
|
+
}
|
|
192
|
+
return __mkview(a, lo, hi - lo, max - lo);
|
|
193
|
+
};
|
|
194
|
+
var __reslice = __reslice || function(a, lo, hi) {
|
|
195
|
+
if (Array.isArray(a) && a[__sv] === undefined) {
|
|
196
|
+
const n = a.length;
|
|
197
|
+
if (hi === undefined) hi = n;
|
|
198
|
+
if (lo >= 0 && lo <= hi && hi <= n) {
|
|
199
|
+
if (lo === 0 && hi === n) return a;
|
|
200
|
+
const e = a[__rcap];
|
|
201
|
+
const r = a.slice(lo, hi);
|
|
202
|
+
if (e === undefined) {
|
|
203
|
+
__rcdef(r, { b: a, o: lo, c: n - lo, s: a.slice(lo, hi), so: 0 });
|
|
204
|
+
return r;
|
|
205
|
+
}
|
|
206
|
+
// A copy of a copy: write back the changed elements it drops and share
|
|
207
|
+
// the snapshot (copied on write, __rcown), so a pop costs no more than
|
|
208
|
+
// the copy itself.
|
|
209
|
+
if (lo > 0) __rcput(e, a, 0, lo);
|
|
210
|
+
__rcput(e, a, hi, n);
|
|
211
|
+
e.own = false;
|
|
212
|
+
__rcdef(r, { b: e.b, o: e.o + lo, c: e.c - lo, s: e.s, so: e.so + lo, own: false });
|
|
213
|
+
return r;
|
|
214
|
+
}
|
|
16
215
|
}
|
|
17
|
-
return a
|
|
216
|
+
return __slice(a, lo, hi);
|
|
217
|
+
};
|
|
218
|
+
var __mkslice = __mkslice || function(n, b) {
|
|
219
|
+
if (!(n >= 0 && n <= b.length)) throw new Error("runtime error: makeslice: cap out of range");
|
|
220
|
+
return __slice(b, 0, n);
|
|
18
221
|
};`;
|
|
19
222
|
|
|
20
|
-
|
|
223
|
+
// `make([]T, n, cap)` argument checks with Go's messages: a negative length is
|
|
224
|
+
// a len panic, a negative capacity (or one below the length) a cap panic.
|
|
225
|
+
export const HELPER_MKLEN = `var __mkn = __mkn || function(n) {
|
|
226
|
+
if (!(n >= 0)) throw new Error("runtime error: makeslice: len out of range");
|
|
227
|
+
return n;
|
|
228
|
+
};
|
|
229
|
+
var __mkc = __mkc || function(c) {
|
|
230
|
+
if (!(c >= 0)) throw new Error("runtime error: makeslice: cap out of range");
|
|
231
|
+
return c;
|
|
232
|
+
};`;
|
|
21
233
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
234
|
+
// string(rune): an out-of-range rune or a surrogate is U+FFFD.
|
|
235
|
+
export const HELPER_RUNESTR = `var __rstr = __rstr || function(c) {
|
|
236
|
+
return String.fromCodePoint(c >= 0 && c <= 0x10ffff && !(c >= 0xd800 && c <= 0xdfff) ? c : 0xfffd);
|
|
237
|
+
};`;
|
|
238
|
+
|
|
239
|
+
export const HELPER_APPEND = `var __tn = __tn || function(c) {
|
|
240
|
+
return Object.hasOwn(c, "__tnil") ? c.__tnil : Object.defineProperty(c, "__tnil", { value: Object.defineProperty(new c(0), "__nilt", { value: true }) }).__tnil;
|
|
241
|
+
};
|
|
242
|
+
// Append the elements of the array-like b to a typed array.
|
|
243
|
+
var __tapp = __tapp || function(a, b) {
|
|
244
|
+
const c = __tcap.get(a);
|
|
245
|
+
if (c !== undefined && a.length + b.length <= c) {
|
|
246
|
+
const r = new a.constructor(a.buffer, a.byteOffset, a.length + b.length);
|
|
247
|
+
r.set(b, a.length);
|
|
248
|
+
if (c > r.length) __tcap.set(r, c);
|
|
249
|
+
return r;
|
|
250
|
+
}
|
|
251
|
+
// Grow with spare capacity so repeated appends cost O(1) amortized.
|
|
252
|
+
const n = a.length + b.length;
|
|
253
|
+
const cap = Math.max(n, a.length * 2);
|
|
254
|
+
const res = new a.constructor(new a.constructor(cap).buffer, 0, n);
|
|
255
|
+
res.set(a);
|
|
256
|
+
res.set(b, a.length);
|
|
257
|
+
__tcap.set(res, cap);
|
|
258
|
+
return res;
|
|
259
|
+
};
|
|
260
|
+
var __append = __append || function(a, ...b) {
|
|
261
|
+
if (b.length === 0) return a !== null && a !== undefined && a.__nilt === true ? null : a;
|
|
262
|
+
if (a && ArrayBuffer.isView(a)) return __tapp(a, b);
|
|
263
|
+
const s = a ? a[__sv] : undefined;
|
|
264
|
+
if (s !== undefined && s.n + b.length <= s.c) {
|
|
265
|
+
for (let i = 0; i < b.length; i++) s.b[s.o + s.n + i] = b[i];
|
|
266
|
+
return __mkview(s.b, s.o, s.n + b.length, s.c);
|
|
267
|
+
}
|
|
268
|
+
if (s === undefined && a) {
|
|
269
|
+
const e = a[__rcap];
|
|
270
|
+
if (e !== undefined && a.length + b.length <= e.c) {
|
|
271
|
+
__rcflush(a);
|
|
272
|
+
for (let i = 0; i < b.length; i++) e.b[e.o + a.length + i] = b[i];
|
|
273
|
+
return __mkview(e.b, e.o, a.length + b.length, e.c);
|
|
274
|
+
}
|
|
34
275
|
}
|
|
276
|
+
return a ? [...a, ...b] : b;
|
|
277
|
+
};
|
|
278
|
+
// append(a, b...) of a typed array with one source: no argument spread.
|
|
279
|
+
var __appendv = __appendv || function(a, b) {
|
|
280
|
+
if (b.length === 0) return a !== null && a !== undefined && a.__nilt === true ? null : a;
|
|
281
|
+
return __tapp(a, b);
|
|
35
282
|
};`;
|
|
36
283
|
|
|
284
|
+
// `s = append(s, x)` in the json codecs, where the slice is a local that no
|
|
285
|
+
// other slice shares: a plain array grows in place. A view with spare
|
|
286
|
+
// capacity, a reslice copy or a typed array takes the general __append.
|
|
287
|
+
export const HELPER_PUSHS =
|
|
288
|
+
"var __pushs = __pushs || function(a, x) { if (a == null) return [x]; if (!Array.isArray(a) || a[__sv] !== undefined || a[__rcap] !== undefined) return __append(a, x); a.push(x); return a; };";
|
|
289
|
+
|
|
290
|
+
export const HELPER_S = "var __s = __s || function(a) { return a || []; };";
|
|
291
|
+
|
|
37
292
|
// Copy of a struct value whose class is not statically known.
|
|
38
293
|
export const HELPER_SCLONE = `var __sclone = __sclone || function(x) {
|
|
39
294
|
if (x === null || typeof x !== "object") return x;
|
|
@@ -41,11 +296,46 @@ export const HELPER_SCLONE = `var __sclone = __sclone || function(x) {
|
|
|
41
296
|
return Object.assign(Object.create(Object.getPrototypeOf(x)), x);
|
|
42
297
|
};`;
|
|
43
298
|
|
|
299
|
+
// Variadic prologue. `f(xs...)` to a Go-compiled variadic function passes
|
|
300
|
+
// `{ __sp: xs }`, so the parameter is the caller's slice itself (or nil).
|
|
301
|
+
export const HELPER_VA = `var __va = __va || function(a, nilEmpty) {
|
|
302
|
+
const f = a.length === 1 ? a[0] : undefined;
|
|
303
|
+
if (a.length === 0 && nilEmpty) return null;
|
|
304
|
+
return f !== null && typeof f === "object" && f.__sp !== undefined ? f.__sp : a;
|
|
305
|
+
};`;
|
|
306
|
+
|
|
307
|
+
// Copy of a value whose type is a type parameter. `z` is the argument's
|
|
308
|
+
// zero-value factory: an object zero means a struct or array (copied by
|
|
309
|
+
// value); anything else (scalars, pointers, interfaces) is returned as is.
|
|
310
|
+
export const HELPER_VCLONE = `var __vclone = __vclone || function __vclone(z, x) {
|
|
311
|
+
if (x === null || typeof x !== "object") return x;
|
|
312
|
+
const zero = z?.();
|
|
313
|
+
if (zero === null || zero === undefined || typeof zero !== "object") return x;
|
|
314
|
+
const cp = (v) => {
|
|
315
|
+
if (v === null || typeof v !== "object") return v;
|
|
316
|
+
if (Array.isArray(v)) return v.map(cp);
|
|
317
|
+
if (typeof v.__clone === "function") return v.__clone();
|
|
318
|
+
return Object.assign(Object.create(Object.getPrototypeOf(v)), v);
|
|
319
|
+
};
|
|
320
|
+
return cp(x);
|
|
321
|
+
};`;
|
|
322
|
+
|
|
323
|
+
// == on type-parameter operands: structs and arrays compare by value, other
|
|
324
|
+
// type arguments with ===. Decided at run time from the zero-value factory.
|
|
325
|
+
export const HELPER_GEQ = `var __geq = __geq || function(z, a, b) {
|
|
326
|
+
if (a === b) return true;
|
|
327
|
+
if (z?.k === "iface") return __ifeq(a, b);
|
|
328
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
329
|
+
const zero = z?.();
|
|
330
|
+
if (zero === null || zero === undefined || typeof zero !== "object") return false;
|
|
331
|
+
return __equal(a, b);
|
|
332
|
+
};`;
|
|
333
|
+
|
|
44
334
|
// Interface boxing: tag struct values (__v) vs struct pointers (__p) so type
|
|
45
335
|
// 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, ptrFields) {
|
|
336
|
+
export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields, fresh) {
|
|
47
337
|
if (x === null || typeof x !== "object") return x;
|
|
48
|
-
const c = typeof x.__clone === "function" ? x.__clone() : Object.assign(Object.create(Object.getPrototypeOf(x)), x);
|
|
338
|
+
const c = fresh === true ? x : typeof x.__clone === "function" ? x.__clone() : Object.assign(Object.create(Object.getPrototypeOf(x)), x);
|
|
49
339
|
Object.defineProperty(c, "__v", { value: true, configurable: true });
|
|
50
340
|
if (Array.isArray(ptrFields)) {
|
|
51
341
|
for (const f of ptrFields) {
|
|
@@ -60,10 +350,11 @@ export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields) {
|
|
|
60
350
|
}
|
|
61
351
|
}
|
|
62
352
|
}
|
|
63
|
-
for (const k
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
353
|
+
for (const k in c) {
|
|
354
|
+
const v = c[k];
|
|
355
|
+
if (v !== null && typeof v === "object" && !Array.isArray(v) && !ArrayBuffer.isView(v)) {
|
|
356
|
+
if (!v.__v && !v.__p && Object.isExtensible(v) && (!Array.isArray(ptrFields) || !ptrFields.includes(k))) {
|
|
357
|
+
Object.defineProperty(v, "__v", { value: true, configurable: true });
|
|
67
358
|
}
|
|
68
359
|
}
|
|
69
360
|
}
|
|
@@ -72,7 +363,7 @@ export const HELPER_IFACE_BOX = `var __ifv = __ifv || function(x, ptrFields) {
|
|
|
72
363
|
var __ifp = __ifp || function(x, ptrFields, seen) {
|
|
73
364
|
if (x === null || typeof x !== "object") return x;
|
|
74
365
|
if (x.__p !== true && Object.isExtensible(x))
|
|
75
|
-
Object.defineProperty(x, "__p", { value: true, configurable: true });
|
|
366
|
+
Object.defineProperty(x, "__p", { value: true, configurable: true, writable: true });
|
|
76
367
|
if (Array.isArray(ptrFields)) {
|
|
77
368
|
seen = seen || new Set();
|
|
78
369
|
if (seen.has(x)) return x;
|
|
@@ -91,6 +382,31 @@ var __ifp = __ifp || function(x, ptrFields, seen) {
|
|
|
91
382
|
}
|
|
92
383
|
return x;
|
|
93
384
|
};
|
|
385
|
+
var __mknil = __mknil || function(C) {
|
|
386
|
+
const s = Object.create(C.prototype);
|
|
387
|
+
Object.defineProperty(s, "__nilp", { value: true });
|
|
388
|
+
Object.defineProperty(s, "__p", { value: true });
|
|
389
|
+
const vm = C.__vm || [];
|
|
390
|
+
for (const k of Object.getOwnPropertyNames(C.prototype)) {
|
|
391
|
+
const f = C.prototype[k];
|
|
392
|
+
if (k === "constructor" || k === "toString" || k.startsWith("__") || typeof f !== "function") continue;
|
|
393
|
+
Object.defineProperty(s, k, { value: vm.includes(k)
|
|
394
|
+
? function() { throw new Error("runtime error: invalid memory address or nil pointer dereference"); }
|
|
395
|
+
: function(...a) { return f.apply(null, a); } });
|
|
396
|
+
}
|
|
397
|
+
Object.defineProperty(C, "__nil", { value: s });
|
|
398
|
+
return s;
|
|
399
|
+
};
|
|
400
|
+
var __ifn = __ifn || function(x, C) {
|
|
401
|
+
return x === null ? (Object.hasOwn(C, "__nil") ? C.__nil : __mknil(C)) : x;
|
|
402
|
+
};
|
|
403
|
+
var __pbs = __pbs || function(p) {
|
|
404
|
+
var e = p !== null && typeof p === "object" ? p.value : undefined;
|
|
405
|
+
return e !== null && typeof e === "object" && e.value === e ? e : p;
|
|
406
|
+
};
|
|
407
|
+
var __unnil = __unnil || function(x) {
|
|
408
|
+
return x != null && x.__nilp === true ? null : x;
|
|
409
|
+
};
|
|
94
410
|
var __ifm = __ifm || function(x) {
|
|
95
411
|
if (x === null || x === undefined) return x;
|
|
96
412
|
if (typeof x !== "object") return x;
|
|
@@ -122,29 +438,411 @@ var __ifps = __ifps || function(x) {
|
|
|
122
438
|
Object.defineProperty(x, "__ptr_slice", { value: true, configurable: true });
|
|
123
439
|
}
|
|
124
440
|
return x;
|
|
441
|
+
};
|
|
442
|
+
var __ity = __ity || function(x, t, ptr) {
|
|
443
|
+
// The frozen nil map cannot carry a tag: a copy of it keeps its map type.
|
|
444
|
+
if (x !== null && x !== undefined && x.__nilm === true && x.__t === undefined)
|
|
445
|
+
return Object.freeze(Object.defineProperties({}, { __map: { value: true }, __nilm: { value: true }, __t: { value: t } }));
|
|
446
|
+
if (x === null || x === undefined) {
|
|
447
|
+
// A nil slice keeps its type as an empty tagged array (not a nil interface).
|
|
448
|
+
if (!ptr && t.charCodeAt(0) !== 91) return x;
|
|
449
|
+
const n = ptr ? {} : [];
|
|
450
|
+
if (!ptr) Object.defineProperty(n, "__nils", { value: true });
|
|
451
|
+
Object.defineProperty(n, "__nilp", { value: true });
|
|
452
|
+
Object.defineProperty(n, "__t", { value: t });
|
|
453
|
+
return n;
|
|
454
|
+
}
|
|
455
|
+
if ((typeof x === "object" || typeof x === "function") && Object.isExtensible(x))
|
|
456
|
+
Object.defineProperty(x, "__t", { value: t, configurable: true, writable: true });
|
|
457
|
+
return x;
|
|
458
|
+
};
|
|
459
|
+
var __isty = __isty || function(v, t, k, c, n) {
|
|
460
|
+
if (v === null || v === undefined || (typeof v !== "object" && typeof v !== "function")) return false;
|
|
461
|
+
if (k === "func") return typeof v === "function" && (v.__t === undefined || t === "" || v.__t === t);
|
|
462
|
+
if (v.__t !== undefined && t !== "") return v.__t === t;
|
|
463
|
+
if (v.__nilp === true) return false;
|
|
464
|
+
if (k === "named" || k === "struct") return false;
|
|
465
|
+
if (k === "ptr") {
|
|
466
|
+
if (!(typeof v === "object" && "value" in v && v.value !== v && typeof v.__gfUnbox !== "function" && !(v instanceof Array))) return false;
|
|
467
|
+
// An untagged pointer (to a type parameter's variable): the pointee's
|
|
468
|
+
// shape picks the pointer type; a nil slice or map is decoded as an any.
|
|
469
|
+
if (t.charCodeAt(0) === 42) {
|
|
470
|
+
var pt = t.slice(1), pe = v.value;
|
|
471
|
+
if (pe === null || pe === undefined) return pt === "interface {}";
|
|
472
|
+
if (typeof pe === "number") return pt === "float64";
|
|
473
|
+
if (typeof pe === "string") return pt === "string";
|
|
474
|
+
if (typeof pe === "boolean") return pt === "bool";
|
|
475
|
+
if (typeof pe === "bigint") return pt === "int64";
|
|
476
|
+
if (ArrayBuffer.isView(pe)) return pt.startsWith("[]");
|
|
477
|
+
if (typeof pe === "object" && !Array.isArray(pe)) return pt === "interface {}";
|
|
478
|
+
}
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
if (k === "map") return typeof v === "object" && (v.__map === true || Object.getPrototypeOf(v) === Object.prototype);
|
|
482
|
+
if (k === "array") return Array.isArray(v) && v.length === n;
|
|
483
|
+
if (c) return v instanceof c;
|
|
484
|
+
if (!Array.isArray(v)) return false;
|
|
485
|
+
// An untagged array (a value of a type parameter's type): its first element
|
|
486
|
+
// must at least have the shape of the tag's element type.
|
|
487
|
+
if (k === "slice" && v.length > 0 && t.startsWith("[]")) {
|
|
488
|
+
var x = t.slice(2), e = v[0];
|
|
489
|
+
if (x === "bool") return typeof e === "boolean";
|
|
490
|
+
if (x === "string") return typeof e === "string";
|
|
491
|
+
if (x === "int64" || x === "uint64") return typeof e === "bigint";
|
|
492
|
+
if (/^(u?int(8|16|32)?|uintptr|float(32|64))$/.test(x)) return typeof e === "number";
|
|
493
|
+
}
|
|
494
|
+
return true;
|
|
495
|
+
};
|
|
496
|
+
var __dtn = __dtn || function(v) {
|
|
497
|
+
if (v === null || v === undefined) return "nil";
|
|
498
|
+
switch (typeof v) {
|
|
499
|
+
case "string": return "string";
|
|
500
|
+
case "boolean": return "bool";
|
|
501
|
+
case "number": return Number.isInteger(v) ? "int" : "float64";
|
|
502
|
+
case "bigint": return "int64";
|
|
503
|
+
}
|
|
504
|
+
if (v.__t !== undefined) return v.__t;
|
|
505
|
+
if (Array.isArray(v)) return "[]interface {}";
|
|
506
|
+
const c = v.constructor;
|
|
507
|
+
if (c && c !== Object && typeof c.name === "string" && c.name !== "") {
|
|
508
|
+
const ptr = c.name.endsWith("$Ptr");
|
|
509
|
+
const n = ptr ? c.name.slice(0, -4) : c.name;
|
|
510
|
+
const i = n.indexOf("$$");
|
|
511
|
+
const q = i < 0 ? "main." + n : n.slice(i + 2) + "." + n.slice(0, i);
|
|
512
|
+
return (ptr || v.__v !== true && typeof v.__gfUnbox !== "function" ? "*" : "") + q;
|
|
513
|
+
}
|
|
514
|
+
return typeof v === "function" ? "func()" : "map[string]interface {}";
|
|
515
|
+
};
|
|
516
|
+
var __tafail = __tafail || function(src, v, target, methods) {
|
|
517
|
+
if (methods) {
|
|
518
|
+
if (v === null || v === undefined) return new Error("interface conversion: interface is nil, not " + target);
|
|
519
|
+
const m = methods.find((n) => typeof v[n] !== "function") ?? methods[0];
|
|
520
|
+
return new Error("interface conversion: " + __dtn(v) + " is not " + target + ": missing method " + m);
|
|
521
|
+
}
|
|
522
|
+
return new Error("interface conversion: " + src + " is " + __dtn(v) + ", not " + target);
|
|
125
523
|
};`;
|
|
126
524
|
|
|
127
525
|
// Nil-interface method call guard (strict mode only): matches Go's panic
|
|
128
526
|
// message instead of a JS TypeError.
|
|
527
|
+
// 64-bit shifts: count is converted to BigInt; negative count panics;
|
|
528
|
+
// wraps with BigInt.asIntN / BigInt.asUintN.
|
|
529
|
+
export const HELPER_SHIFT = `var __shc = __shc || function(n) {
|
|
530
|
+
if (n < 0) throw new Error("runtime error: negative shift amount");
|
|
531
|
+
return n;
|
|
532
|
+
};
|
|
533
|
+
var __shl64 = __shl64 || function(x, n, u) {
|
|
534
|
+
var b = BigInt(n);
|
|
535
|
+
if (b < 0n) throw new Error("runtime error: negative shift amount");
|
|
536
|
+
if (typeof x === "bigint") {
|
|
537
|
+
if (b >= 64n) return 0n;
|
|
538
|
+
var bx = u ? BigInt.asUintN(64, x) : BigInt.asIntN(64, x);
|
|
539
|
+
var r = bx << b;
|
|
540
|
+
return u ? BigInt.asUintN(64, r) : BigInt.asIntN(64, r);
|
|
541
|
+
}
|
|
542
|
+
if (b >= 64n) return 0;
|
|
543
|
+
var nb = Number(b);
|
|
544
|
+
var r = x * 2 ** nb;
|
|
545
|
+
if (Number.isSafeInteger(r)) return r;
|
|
546
|
+
var bxx = BigInt(Math.trunc(x)) << b;
|
|
547
|
+
return Number(u ? BigInt.asUintN(64, bxx) : BigInt.asIntN(64, bxx));
|
|
548
|
+
};
|
|
549
|
+
var __shr64 = __shr64 || function(x, n, u) {
|
|
550
|
+
var b = BigInt(n);
|
|
551
|
+
if (b < 0n) throw new Error("runtime error: negative shift amount");
|
|
552
|
+
if (typeof x === "bigint") {
|
|
553
|
+
var bx = u ? BigInt.asUintN(64, x) : BigInt.asIntN(64, x);
|
|
554
|
+
if (b >= 64n) return u || bx >= 0n ? 0n : -1n;
|
|
555
|
+
var r = bx >> b;
|
|
556
|
+
return u ? BigInt.asUintN(64, r) : BigInt.asIntN(64, r);
|
|
557
|
+
}
|
|
558
|
+
if (b >= 64n) return u || x >= 0 ? 0 : -1;
|
|
559
|
+
return Math.floor(x / 2 ** Number(b));
|
|
560
|
+
};`;
|
|
561
|
+
|
|
562
|
+
export const HELPER_TO64 = `var __to_i64 = __to_i64 || function(v) {
|
|
563
|
+
if (typeof v === "bigint") return BigInt.asIntN(64, v);
|
|
564
|
+
return Number.isFinite(v) ? BigInt.asIntN(64, BigInt(Math.trunc(v))) : -9223372036854775808n;
|
|
565
|
+
};
|
|
566
|
+
var __to_u64 = __to_u64 || function(v) {
|
|
567
|
+
if (typeof v === "bigint") return BigInt.asUintN(64, v);
|
|
568
|
+
return Number.isFinite(v) ? BigInt.asUintN(64, BigInt(Math.trunc(v))) : 9223372036854775808n;
|
|
569
|
+
};`;
|
|
570
|
+
|
|
129
571
|
export const HELPER_NIL_CALL = `var __nilcall = __nilcall || function(x) {
|
|
130
572
|
if (x == null) throw new Error("runtime error: invalid memory address or nil pointer dereference");
|
|
131
573
|
return x;
|
|
132
574
|
};`;
|
|
133
575
|
|
|
576
|
+
// Strict-mode index checks (`both` packages): Go's out-of-range panic for
|
|
577
|
+
// slices, arrays and strings. `__at` reads an element; `__ix` returns the
|
|
578
|
+
// checked index for writes, compound assignments and string reads. A nil
|
|
579
|
+
// slice (`null`) has length 0.
|
|
580
|
+
export const HELPER_BOUNDS = `var __ixerr = __ixerr || function(i, n) {
|
|
581
|
+
throw new Error(i < 0 ? "runtime error: index out of range [" + i + "]" : "runtime error: index out of range [" + i + "] with length " + n);
|
|
582
|
+
};
|
|
583
|
+
var __at = __at || function(a, i) {
|
|
584
|
+
if (a != null && i >= 0 && i < a.length) return a[i];
|
|
585
|
+
return __ixerr(i, a == null ? 0 : a.length);
|
|
586
|
+
};
|
|
587
|
+
var __ix = __ix || function(a, i) {
|
|
588
|
+
if (a != null && i >= 0 && i < a.length) return i;
|
|
589
|
+
return __ixerr(i, a == null ? 0 : a.length);
|
|
590
|
+
};
|
|
591
|
+
var __lv;`;
|
|
592
|
+
|
|
593
|
+
// Generic zero values (generics are erased in JS): a generic function takes
|
|
594
|
+
// one zero-value factory per type parameter as leading arguments, and an
|
|
595
|
+
// instance of a generic struct keeps its factories under the `__tz` symbol
|
|
596
|
+
// (a symbol, so field iteration, equality and JSON never see it). Shared
|
|
597
|
+
// factories for the common zero values avoid a closure per call.
|
|
598
|
+
export const HELPER_GENERICS = `var __tz = __tz || Symbol.for("gofront.typeArgs");
|
|
599
|
+
var __zn = __zn || (() => null);
|
|
600
|
+
var __z0 = __z0 || (() => 0);
|
|
601
|
+
var __zs = __zs || (() => "");
|
|
602
|
+
var __zf = __zf || (() => false);
|
|
603
|
+
var __z64 = __z64 || Object.assign(() => 0n, { k: "int64" });
|
|
604
|
+
var __zu64 = __zu64 || Object.assign(() => 0n, { k: "uint64" });
|
|
605
|
+
var __tbox = __tbox || function(f, x) {
|
|
606
|
+
return f && f.b ? f.b(x) : x;
|
|
607
|
+
};
|
|
608
|
+
var __ti = __ti || function(f, k, id, is, u, b, fb) {
|
|
609
|
+
const g = () => f();
|
|
610
|
+
g.k = k; g.id = id; g.is = is; g.u = u; g.b = b; g.fb = fb;
|
|
611
|
+
return g;
|
|
612
|
+
};
|
|
613
|
+
var __tar = __tar || function(f, op, a, b) {
|
|
614
|
+
const k = f?.k;
|
|
615
|
+
const dz = () => { throw new Error("runtime error: integer divide by zero"); };
|
|
616
|
+
const ns = () => { throw new Error("runtime error: negative shift amount"); };
|
|
617
|
+
if (typeof a === "bigint") {
|
|
618
|
+
const sh = op === "<<" || op === ">>";
|
|
619
|
+
if (sh) { b = Number(b); if (b < 0) ns(); }
|
|
620
|
+
else if (typeof b !== "bigint") b = BigInt(b);
|
|
621
|
+
const w = k === "uint64" ? (v) => BigInt.asUintN(64, v) : (v) => BigInt.asIntN(64, v);
|
|
622
|
+
switch (op) {
|
|
623
|
+
case "+": return w(a + b);
|
|
624
|
+
case "-": return w(a - b);
|
|
625
|
+
case "*": return w(a * b);
|
|
626
|
+
case "/": return b === 0n ? dz() : w(a / b);
|
|
627
|
+
case "%": return b === 0n ? dz() : w(a % b);
|
|
628
|
+
case "&": return w(a & b);
|
|
629
|
+
case "|": return w(a | b);
|
|
630
|
+
case "^": return w(a ^ b);
|
|
631
|
+
case "&^": return w(a & ~b);
|
|
632
|
+
case "<<": return b >= 64 ? 0n : w(a << BigInt(b));
|
|
633
|
+
default: return b >= 64 ? (k === "uint64" || a >= 0n ? 0n : -1n) : w(a >> BigInt(b));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
let bits = 0, signed = true;
|
|
637
|
+
switch (k) {
|
|
638
|
+
case "int8": bits = 8; break;
|
|
639
|
+
case "int16": bits = 16; break;
|
|
640
|
+
case "int32": case "rune": bits = 32; break;
|
|
641
|
+
case "uint8": case "byte": bits = 8; signed = false; break;
|
|
642
|
+
case "uint16": bits = 16; signed = false; break;
|
|
643
|
+
case "uint32": bits = 32; signed = false; break;
|
|
644
|
+
}
|
|
645
|
+
const w = bits === 0 ? (v) => v
|
|
646
|
+
: bits === 32 ? (signed ? (v) => v | 0 : (v) => v >>> 0)
|
|
647
|
+
: signed ? (v) => (v << (32 - bits)) >> (32 - bits)
|
|
648
|
+
: (v) => v & ((1 << bits) - 1);
|
|
649
|
+
const int = bits !== 0 || k === "int" || k === "uint" || k === "uintptr";
|
|
650
|
+
switch (op) {
|
|
651
|
+
case "+": return k === "float32" ? Math.fround(a + b) : w(a + b);
|
|
652
|
+
case "-": return k === "float32" ? Math.fround(a - b) : w(a - b);
|
|
653
|
+
case "*": return k === "float32" ? Math.fround(a * b) : bits === 0 ? a * b : w(Math.imul(a, b));
|
|
654
|
+
case "/": return int ? (b === 0 ? dz() : w(Math.trunc(a / b))) : k === "float32" ? Math.fround(a / b) : a / b;
|
|
655
|
+
case "%": return int && b === 0 ? dz() : w(a % b);
|
|
656
|
+
case "&": return bits === 0 ? a & b : w(a & b);
|
|
657
|
+
case "|": return bits === 0 ? a | b : w(a | b);
|
|
658
|
+
case "^": return bits === 0 ? a ^ b : w(a ^ b);
|
|
659
|
+
case "&^": return bits === 0 ? a & ~b : w(a & ~b);
|
|
660
|
+
}
|
|
661
|
+
b = Number(b);
|
|
662
|
+
if (b < 0) ns();
|
|
663
|
+
if (bits === 0) return op === "<<" ? a << b : a >> b;
|
|
664
|
+
if (b >= bits) return op === ">>" && signed && a < 0 ? -1 : 0;
|
|
665
|
+
return op === "<<" ? w(a << b) : signed ? a >> b : a >>> b;
|
|
666
|
+
};
|
|
667
|
+
var __tid = __tid || function(...ids) {
|
|
668
|
+
return ids.every((i) => i !== undefined) ? ids.join(",") : undefined;
|
|
669
|
+
};
|
|
670
|
+
var __tconv = __tconv || function(f, v) {
|
|
671
|
+
switch (f?.k) {
|
|
672
|
+
case "int64": return typeof v === "bigint" ? BigInt.asIntN(64, v) : (typeof v === "number" ? BigInt.asIntN(64, BigInt(Math.trunc(v))) : v);
|
|
673
|
+
case "uint64": return typeof v === "bigint" ? BigInt.asUintN(64, v) : (typeof v === "number" ? BigInt.asUintN(64, BigInt(Math.trunc(v))) : v);
|
|
674
|
+
case "int": case "uint": case "uintptr": return Math.trunc(Number(typeof v === "bigint" ? Number(v) : v));
|
|
675
|
+
case "int8": return (Number(typeof v === "bigint" ? Number(v) : v) << 24) >> 24;
|
|
676
|
+
case "int16": return (Number(typeof v === "bigint" ? Number(v) : v) << 16) >> 16;
|
|
677
|
+
case "int32": case "rune": return Number(typeof v === "bigint" ? Number(v) : v) | 0;
|
|
678
|
+
case "uint8": case "byte": return Number(typeof v === "bigint" ? Number(v) : v) & 0xFF;
|
|
679
|
+
case "uint16": return Number(typeof v === "bigint" ? Number(v) : v) & 0xFFFF;
|
|
680
|
+
case "uint32": return Number(typeof v === "bigint" ? Number(v) : v) >>> 0;
|
|
681
|
+
case "float32": return Math.fround(Number(typeof v === "bigint" ? Number(v) : v));
|
|
682
|
+
case "float64": return Number(typeof v === "bigint" ? Number(v) : v);
|
|
683
|
+
default: return typeof v === "number" && f && (f() === 0n || typeof f() === "bigint") ? BigInt(v) : v;
|
|
684
|
+
}
|
|
685
|
+
};`;
|
|
686
|
+
|
|
687
|
+
// Strict-mode nil maps: the zero value of a map type is one frozen empty
|
|
688
|
+
// object, so reads, `len` and `range` behave as on an empty map, and every
|
|
689
|
+
// write goes through `__mw`, which panics with Go's message.
|
|
690
|
+
export const HELPER_NIL_MAP = `var __nilmap = __nilmap || Object.freeze(Object.defineProperties({}, { __map: { value: true }, __nilm: { value: true } }));
|
|
691
|
+
var __mw = __mw || function(m) {
|
|
692
|
+
if (m == null || m.__nilm === true) throw new Error("assignment to entry in nil map");
|
|
693
|
+
return m;
|
|
694
|
+
};
|
|
695
|
+
var __isnm = __isnm || function(m) {
|
|
696
|
+
return m == null || m.__nilm === true || (m.__nm === true && Object.keys(m).length === 0);
|
|
697
|
+
};`;
|
|
698
|
+
|
|
699
|
+
// js-package nil maps: the zero value is a fresh `{}` carrying a hidden tag;
|
|
700
|
+
// `m == nil` holds while it stays empty (writes are allowed, as in plain JS).
|
|
701
|
+
export const HELPER_NM = `var __nm = __nm || function() { return Object.defineProperty({}, "__nm", { value: true }); };
|
|
702
|
+
var __isnm = __isnm || function(m) {
|
|
703
|
+
return m == null || m.__nilm === true || (m.__nm === true && Object.keys(m).length === 0);
|
|
704
|
+
};`;
|
|
705
|
+
|
|
706
|
+
// Struct map keys: a JS object key is a string, so a struct key is coerced
|
|
707
|
+
// through `toString` to an injective encoding, and the key value is kept in
|
|
708
|
+
// a table so ranging and fmt can recover it.
|
|
709
|
+
export const HELPER_STRUCT_KEY = `var __kt = __kt || new Map();
|
|
710
|
+
var __kcl = __kcl || function(o) {
|
|
711
|
+
if (o === null || typeof o !== "object") return o;
|
|
712
|
+
if (typeof o.__clone === "function") return o.__clone();
|
|
713
|
+
if (ArrayBuffer.isView(o)) return o.slice();
|
|
714
|
+
if (Array.isArray(o)) return o.map(__kcl);
|
|
715
|
+
const c = Object.create(Object.getPrototypeOf(o));
|
|
716
|
+
for (const f of Object.keys(o)) c[f] = __kcl(o[f]);
|
|
717
|
+
return c;
|
|
718
|
+
};
|
|
719
|
+
var __sk = __sk || function(o) {
|
|
720
|
+
const s = "\\u0001" + JSON.stringify(o, (k, v) => typeof v === "bigint" ? v.toString() + "n" : typeof v === "number" && !Number.isFinite(v) ? { $f: String(v) } : v);
|
|
721
|
+
if (!__kt.has(s)) __kt.set(s, __kcl(o));
|
|
722
|
+
return s;
|
|
723
|
+
};
|
|
724
|
+
// Pointer keys compare by identity: a per-object id (a pointer to an element
|
|
725
|
+
// is its container plus index) keys the property, and the pointer is kept
|
|
726
|
+
// in the table so ranging and fmt can recover it.
|
|
727
|
+
var __pids = __pids || new WeakMap();
|
|
728
|
+
var __pidn = __pidn || { n: 0 };
|
|
729
|
+
var __pid = __pid || function(o) {
|
|
730
|
+
let id = __pids.get(o);
|
|
731
|
+
if (id === undefined) __pids.set(o, id = ++__pidn.n);
|
|
732
|
+
return id;
|
|
733
|
+
};
|
|
734
|
+
var __pk = __pk || function(p) {
|
|
735
|
+
if (p === null || p === undefined) return "\\u0001nil";
|
|
736
|
+
const s = "\\u0001*" + (p.__target !== undefined && p.__target !== null ? __pid(p.__target) + ":" + p.__index : __pid(p));
|
|
737
|
+
if (!__kt.has(s)) __kt.set(s, p);
|
|
738
|
+
return s;
|
|
739
|
+
};
|
|
740
|
+
var __ik = __ik || function(k, tag) {
|
|
741
|
+
const t = typeof k;
|
|
742
|
+
if (k === null || k === undefined) return "\\u0001nil";
|
|
743
|
+
if (tag !== undefined) {
|
|
744
|
+
if (tag === "*") return __pk(k);
|
|
745
|
+
if (tag.charCodeAt(0) === 33) throw new Error("runtime error: hash of unhashable type " + tag.slice(1));
|
|
746
|
+
if (t === "number" || t === "bigint") {
|
|
747
|
+
const s = "\\u0001" + tag + ":" + String(k);
|
|
748
|
+
if (!__kt.has(s)) __kt.set(s, k);
|
|
749
|
+
return s;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
if (t === "number" || t === "boolean" || t === "bigint") return "\\u0001" + t + ":" + String(k);
|
|
753
|
+
// A slice, map or func in an \`any\` carries its type tag: Go cannot hash it.
|
|
754
|
+
if ((t === "object" || t === "function") && typeof k.__t === "string" && /^(\\[\\]|map\\[|func\\()/.test(k.__t))
|
|
755
|
+
throw new Error("runtime error: hash of unhashable type " + k.__t.replace(/ void$/, ""));
|
|
756
|
+
if (k !== null && t === "object" && typeof k.__gfUnbox === "function" && !k.constructor.name.endsWith("$Ptr")) {
|
|
757
|
+
const v = k.__gfUnbox(), vt = typeof v;
|
|
758
|
+
if (vt === "string" || vt === "number" || vt === "boolean" || vt === "bigint") {
|
|
759
|
+
const s = "\\u0001" + k.constructor.name + ":" + vt + ":" + String(v);
|
|
760
|
+
if (!__kt.has(s)) __kt.set(s, k);
|
|
761
|
+
return s;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return k;
|
|
765
|
+
};
|
|
766
|
+
// A key typed by a type parameter whose factory is \`f\`: interface type
|
|
767
|
+
// arguments key by dynamic type; \`box\` (an \`any\`-keyed map) boxes a named
|
|
768
|
+
// basic value first, other keys are left as they are.
|
|
769
|
+
var __ikt = __ikt || function(f, k, box) {
|
|
770
|
+
if (f?.k === "iface") return __ik(k);
|
|
771
|
+
return box ? __ik(f?.b ? f.b(k) : k) : k;
|
|
772
|
+
};
|
|
773
|
+
var __kd = __kd || function(s, copy) {
|
|
774
|
+
if (typeof s !== "string" || s.charCodeAt(0) !== 1) return s;
|
|
775
|
+
const k = __kt.get(s);
|
|
776
|
+
if (s === "\\u0001nil") return null;
|
|
777
|
+
if (k !== undefined && s.charCodeAt(1) === 42) return k;
|
|
778
|
+
if (k === undefined) {
|
|
779
|
+
if (s.startsWith("\\u0001number:")) return Number(s.slice(8));
|
|
780
|
+
if (s.startsWith("\\u0001boolean:")) return s.slice(9) === "true";
|
|
781
|
+
if (s.startsWith("\\u0001bigint:")) return BigInt(s.slice(8));
|
|
782
|
+
return s;
|
|
783
|
+
}
|
|
784
|
+
return copy ? __kcl(k) : k;
|
|
785
|
+
};
|
|
786
|
+
var __kdt = __kdt || function(f, s) {
|
|
787
|
+
if (typeof s !== "string") return s;
|
|
788
|
+
const z = f?.();
|
|
789
|
+
switch (typeof z) {
|
|
790
|
+
case "number": return Number(s);
|
|
791
|
+
case "bigint": return BigInt(s);
|
|
792
|
+
case "boolean": return s === "true";
|
|
793
|
+
case "string": return s;
|
|
794
|
+
default: return __kd(s, true);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
// Interface keys of different dynamic types sort by type first: nil, named
|
|
798
|
+
// types, strings, bools, numbers.
|
|
799
|
+
var __krank = __krank || function(v) {
|
|
800
|
+
if (v === null || v === undefined) return 0;
|
|
801
|
+
const t = typeof v;
|
|
802
|
+
if (t === "object" && typeof v.__gfUnbox === "function") return 1;
|
|
803
|
+
return t === "string" ? 2 : t === "boolean" ? 3 : t === "number" || t === "bigint" ? 4 : 5;
|
|
804
|
+
};
|
|
805
|
+
var __kcmp = __kcmp || function(a, b) {
|
|
806
|
+
const ra = __krank(a), rb = __krank(b);
|
|
807
|
+
if (ra !== rb) return ra - rb;
|
|
808
|
+
if (ra === 1) {
|
|
809
|
+
const na = a.constructor.name, nb = b.constructor.name;
|
|
810
|
+
if (na !== nb) return na < nb ? -1 : 1;
|
|
811
|
+
a = a.__gfUnbox();
|
|
812
|
+
b = b.__gfUnbox();
|
|
813
|
+
}
|
|
814
|
+
if (a !== null && b !== null && typeof a === "object" && typeof b === "object") {
|
|
815
|
+
for (const f of Object.keys(a)) {
|
|
816
|
+
const c = __kcmp(a[f], b[f]);
|
|
817
|
+
if (c !== 0) return c;
|
|
818
|
+
}
|
|
819
|
+
return 0;
|
|
820
|
+
}
|
|
821
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
822
|
+
};`;
|
|
823
|
+
|
|
134
824
|
// Interface equality: named non-struct values are boxed in interfaces, so two
|
|
135
825
|
// boxes are equal when they share a type and hold the same value (as in Go).
|
|
136
826
|
export const HELPER_IFEQ = `var __ifeq = __ifeq || function(a, b) {
|
|
137
827
|
if (a === b) return true;
|
|
138
828
|
if (a === null || a === undefined || b === null || b === undefined) return a == null && b == null;
|
|
829
|
+
if (a.__nilp === true && b.__nilp === true && a.__t !== undefined) return a.__t === b.__t;
|
|
139
830
|
if (typeof a === "object" && typeof b === "object" && a.constructor === b.constructor && typeof a.__gfUnbox === "function") {
|
|
140
831
|
return a.__gfUnbox() === b.__gfUnbox();
|
|
141
832
|
}
|
|
833
|
+
// Struct values boxed by __ifv compare field by field.
|
|
834
|
+
if (typeof a === "object" && typeof b === "object" && a.__v === true && b.__v === true && a.constructor === b.constructor) {
|
|
835
|
+
return __equal(a, b);
|
|
836
|
+
}
|
|
142
837
|
return false;
|
|
143
838
|
};`;
|
|
144
839
|
|
|
145
840
|
export const HELPER_EQUAL = `var __equal = __equal || function __equal(a, b) {
|
|
146
|
-
if (a === b) return true;
|
|
841
|
+
if (a === b && !Array.isArray(a)) return true;
|
|
147
842
|
if (a === null || b === null) return false;
|
|
843
|
+
if (a.__target !== undefined && b.__target !== undefined) {
|
|
844
|
+
return a.__target === b.__target && a.__index === b.__index;
|
|
845
|
+
}
|
|
148
846
|
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
149
847
|
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
150
848
|
if (a.byteLength !== b.byteLength || a.length !== b.length) return false;
|
|
@@ -174,10 +872,22 @@ export const HELPER_CDIV = `var __cdiv = __cdiv || function(a, b) {
|
|
|
174
872
|
return { re: (a.re * b.re + a.im * b.im) / d, im: (a.im * b.re - a.re * b.im) / d };
|
|
175
873
|
};`;
|
|
176
874
|
|
|
177
|
-
|
|
178
|
-
|
|
875
|
+
export const HELPER_PTREQ = `var __ptreq = __ptreq || function __ptreq(a, b) {
|
|
876
|
+
if (a === b) return true;
|
|
877
|
+
if (!a || !b) return false;
|
|
878
|
+
if (a.__target !== undefined && b.__target !== undefined) {
|
|
879
|
+
return a.__target === b.__target && a.__index === b.__index;
|
|
880
|
+
}
|
|
881
|
+
return false;
|
|
882
|
+
};`;
|
|
883
|
+
|
|
884
|
+
// Panic/defer runtime. `stack` holds the in-flight panic of every frame
|
|
885
|
+
// currently running its defers; `armed` is set right before a deferred
|
|
179
886
|
// function is invoked and consumed by that function's prologue, so recover()
|
|
180
887
|
// only takes effect when called directly by the deferred function (Go spec).
|
|
888
|
+
// panic(v): a string panics with that message; any other value is kept in
|
|
889
|
+
// the thrown error's pv field so recover() returns it unchanged (an error's
|
|
890
|
+
// message is its Error()).
|
|
181
891
|
export const HELPER_PANIC = `var __gopanic = __gopanic || { stack: [], armed: false };
|
|
182
892
|
var __runDefers = __runDefers || function(defers, frame) {
|
|
183
893
|
for (let i = defers.length - 1; i >= 0; i--) {
|
|
@@ -194,664 +904,52 @@ var __runDefers = __runDefers || function(defers, frame) {
|
|
|
194
904
|
if (!frame.pn.recovered) throw frame.pn.err;
|
|
195
905
|
}
|
|
196
906
|
};
|
|
907
|
+
var __gopanicv = __gopanicv || function(v) {
|
|
908
|
+
if (typeof v === "string") {
|
|
909
|
+
// The value rides in pv so recover() returns the string itself, never a
|
|
910
|
+
// runtime error value, however the message reads.
|
|
911
|
+
const se = new Error(v);
|
|
912
|
+
se.pv = { v };
|
|
913
|
+
throw se;
|
|
914
|
+
}
|
|
915
|
+
let msg;
|
|
916
|
+
try { msg = typeof v?.Error === "function" ? v.Error() : String(v); } catch { msg = String(v); }
|
|
917
|
+
const e = new Error(msg);
|
|
918
|
+
e.pv = { v };
|
|
919
|
+
throw e;
|
|
920
|
+
};
|
|
197
921
|
var __recover = __recover || function(ok) {
|
|
198
922
|
if (!ok) return null;
|
|
199
923
|
const s = __gopanic.stack;
|
|
200
924
|
const top = s.length > 0 ? s[s.length - 1] : null;
|
|
201
925
|
if (top === null || top.recovered) return null;
|
|
202
926
|
top.recovered = true;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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) => {
|
|
321
|
-
if (m === "%%") return "%";
|
|
322
|
-
const verb = m.slice(-1);
|
|
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();
|
|
326
|
-
const [, flags, width, prec] = m.match(/^%([#+\\- 0]*)([0-9]*)\\.?([0-9]*)/) || [];
|
|
327
|
-
const zero = flags?.includes("0") && !flags?.includes("-");
|
|
328
|
-
const pad = (s, w, z) => {
|
|
329
|
-
w = parseInt(w) || 0;
|
|
330
|
-
if (!w) return s;
|
|
331
|
-
const p = (z ? "0" : " ").repeat(Math.max(0, w - s.length));
|
|
332
|
-
return flags.includes("-") ? s + p : p + s;
|
|
333
|
-
};
|
|
334
|
-
switch (verb) {
|
|
335
|
-
case "s": return pad(String(v == null ? "<nil>" : v), width, false);
|
|
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);
|
|
338
|
-
case "v": {
|
|
339
|
-
const isPlus = flags?.includes("+") ?? false;
|
|
340
|
-
return pad(formatV(v, isPlus, true), width, false);
|
|
341
|
-
}
|
|
342
|
-
case "f": { const n = Number(v), p = prec !== "" ? parseInt(prec) : 6; return pad(n.toFixed(p), width, zero); }
|
|
343
|
-
case "t": return pad(String(!!v), width, false);
|
|
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);
|
|
376
|
-
case "q": return pad('"' + String(v == null ? "" : v).replace(/\\\\/g, "\\\\\\\\").replace(/"/g, '\\\\"') + '"', width, false);
|
|
377
|
-
case "e": case "E": { const n = Number(v), p = prec !== "" ? parseInt(prec) : 6; return pad(n.toExponential(p), width, zero); }
|
|
378
|
-
case "g": case "G": { const n = Number(v); return pad(prec !== "" ? n.toPrecision(parseInt(prec)) : String(n), width, zero); }
|
|
379
|
-
case "w": return pad(String(v == null ? "<nil>" : typeof v === "object" && v.Error ? v.Error() : v), width, false);
|
|
380
|
-
default: return m;
|
|
381
|
-
}
|
|
382
|
-
});
|
|
927
|
+
const e = top.err;
|
|
928
|
+
if (e && e.pv) return e.pv.v;
|
|
929
|
+
// A JS TypeError from using null as a pointer is Go's nil dereference.
|
|
930
|
+
if (e && e.name === "TypeError" && /of null|undefined or null/.test(e.message))
|
|
931
|
+
return __error("runtime error: invalid memory address or nil pointer dereference");
|
|
932
|
+
const msg = e?.message ?? String(e);
|
|
933
|
+
// A Go runtime panic recovers as an error value (runtime.Error).
|
|
934
|
+
if (/^(runtime error: |assignment to entry in nil map$|interface conversion: )/.test(msg)) return __error(msg);
|
|
935
|
+
return msg;
|
|
383
936
|
};`;
|
|
384
937
|
|
|
938
|
+
// A runtime error value (\`fmt.Errorf\`, parse failures, io.EOF). A wrapped
|
|
939
|
+
// cause is exposed through \`Unwrap() error\`; an array of causes (several %w
|
|
940
|
+
// verbs) through \`Unwrap() []error\`, tagged \`__multi\` so type assertions tell
|
|
941
|
+
// the two apart.
|
|
385
942
|
export const HELPER_ERROR = `var __error = __error || function(msg, cause) {
|
|
386
|
-
|
|
943
|
+
const e = { Error() { return msg; }, toString() { return msg; }, _msg: msg, _cause: cause ?? null };
|
|
944
|
+
if (Array.isArray(cause)) {
|
|
945
|
+
e.Unwrap = function() { return cause; };
|
|
946
|
+
e.Unwrap.__multi = true;
|
|
947
|
+
} else if (cause !== undefined && cause !== null) {
|
|
948
|
+
e.Unwrap = function() { return cause; };
|
|
949
|
+
}
|
|
950
|
+
return e;
|
|
387
951
|
};`;
|
|
388
952
|
|
|
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;
|
|
457
|
-
}
|
|
458
|
-
return false;
|
|
459
|
-
};`;
|
|
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
|
-
|
|
478
|
-
// Go-semantics strconv parsers shared by the JS backend and the wasm runtime
|
|
479
|
-
// imports (boundary.js), so both targets agree. Each parser returns
|
|
480
|
-
// [value, errorMessage | null]; integer values are BigInt (the wasm side
|
|
481
|
-
// needs i64, the JS side converts with Number()).
|
|
482
|
-
export const HELPER_STRCONV = `var __strconv_atoi = __strconv_atoi || function(s) {
|
|
483
|
-
if (!/^[+-]?[0-9]+$/.test(s)) return [0n, 'strconv.Atoi: parsing "' + s + '": invalid syntax'];
|
|
484
|
-
const v = BigInt(s);
|
|
485
|
-
if (v > 9223372036854775807n || v < -9223372036854775808n) {
|
|
486
|
-
return [v > 0n ? 9223372036854775807n : -9223372036854775808n, 'strconv.Atoi: parsing "' + s + '": value out of range'];
|
|
487
|
-
}
|
|
488
|
-
return [v, null];
|
|
489
|
-
};
|
|
490
|
-
var __strconv_parse_int = __strconv_parse_int || function(s, base, bits) {
|
|
491
|
-
let str = s, neg = false;
|
|
492
|
-
if (str[0] === "-" || str[0] === "+") { neg = str[0] === "-"; str = str.slice(1); }
|
|
493
|
-
if (base === 0) {
|
|
494
|
-
if (/^0[xX]/.test(str)) { base = 16; str = str.slice(2); }
|
|
495
|
-
else if (/^0[bB]/.test(str)) { base = 2; str = str.slice(2); }
|
|
496
|
-
else if (/^0[oO]/.test(str)) { base = 8; str = str.slice(2); }
|
|
497
|
-
else if (/^0[0-9]/.test(str)) { base = 8; str = str.slice(1); }
|
|
498
|
-
else base = 10;
|
|
499
|
-
str = str.replaceAll("_", "");
|
|
500
|
-
}
|
|
501
|
-
if (base < 2 || base > 36) return [0n, 'strconv.ParseInt: parsing "' + s + '": invalid base ' + base];
|
|
502
|
-
const digits = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base);
|
|
503
|
-
if (str === "" || [...str.toLowerCase()].some((c) => !digits.includes(c))) {
|
|
504
|
-
return [0n, 'strconv.ParseInt: parsing "' + s + '": invalid syntax'];
|
|
505
|
-
}
|
|
506
|
-
let v = 0n; const B = BigInt(base);
|
|
507
|
-
for (const c of str.toLowerCase()) v = v * B + BigInt(digits.indexOf(c));
|
|
508
|
-
if (neg) v = -v;
|
|
509
|
-
const w = bits === 0 ? 64 : bits;
|
|
510
|
-
const max = (1n << BigInt(w - 1)) - 1n, min = -(1n << BigInt(w - 1));
|
|
511
|
-
if (v > max || v < min) return [v > max ? max : min, 'strconv.ParseInt: parsing "' + s + '": value out of range'];
|
|
512
|
-
return [v, null];
|
|
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
|
-
};
|
|
540
|
-
var __strconv_parse_float = __strconv_parse_float || function(s) {
|
|
541
|
-
const str = s.replaceAll("_", "");
|
|
542
|
-
if (/^[+-]?(inf|infinity)$/i.test(str)) return [str[0] === "-" ? -Infinity : Infinity, null];
|
|
543
|
-
if (/^[+-]?nan$/i.test(str)) return [NaN, null];
|
|
544
|
-
if (str === "" || !/^[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?$|^[+-]?0[xX][0-9a-fA-F]+$/.test(str)) {
|
|
545
|
-
return [0, 'strconv.ParseFloat: parsing "' + s + '": invalid syntax'];
|
|
546
|
-
}
|
|
547
|
-
return [Number(str), null];
|
|
548
|
-
};
|
|
549
|
-
var __strconv_parse_bool = __strconv_parse_bool || function(s) {
|
|
550
|
-
if (["1", "t", "T", "TRUE", "true", "True"].includes(s)) return [true, null];
|
|
551
|
-
if (["0", "f", "F", "FALSE", "false", "False"].includes(s)) return [false, null];
|
|
552
|
-
return [false, 'strconv.ParseBool: parsing "' + s + '": invalid syntax'];
|
|
553
|
-
};
|
|
554
|
-
var __strconv_format_float = __strconv_format_float || function(f, fmtc, prec) {
|
|
555
|
-
const c = String.fromCharCode(fmtc);
|
|
556
|
-
if (!Number.isFinite(f)) return f !== f ? "NaN" : (f > 0 ? "+Inf" : "-Inf");
|
|
557
|
-
if (c === "f") return prec < 0 ? String(f) : f.toFixed(prec);
|
|
558
|
-
if (c === "e" || c === "E") {
|
|
559
|
-
const r = prec < 0 ? f.toExponential() : f.toExponential(prec);
|
|
560
|
-
const o = r.replace(/e([+-])(\\d)$/, "e$10$2");
|
|
561
|
-
return c === "E" ? o.toUpperCase() : o;
|
|
562
|
-
}
|
|
563
|
-
if (c === "g" || c === "G") {
|
|
564
|
-
const r = prec < 0 ? String(f) : f.toPrecision(prec);
|
|
565
|
-
return c === "G" ? r.toUpperCase() : r;
|
|
566
|
-
}
|
|
567
|
-
return String(f);
|
|
568
|
-
};`;
|
|
569
|
-
|
|
570
|
-
export const HELPER_PATH_CLEAN = `var __pathClean = __pathClean || function(p) {
|
|
571
|
-
if (!p) return ".";
|
|
572
|
-
const abs = p.startsWith("/");
|
|
573
|
-
const parts = p.split("/").reduce((acc, s) => {
|
|
574
|
-
if (s === "" || s === ".") return acc;
|
|
575
|
-
if (s === "..") {
|
|
576
|
-
if (acc.length && acc[acc.length - 1] !== "..") acc.pop();
|
|
577
|
-
else if (!abs) acc.push("..");
|
|
578
|
-
} else acc.push(s);
|
|
579
|
-
return acc;
|
|
580
|
-
}, []);
|
|
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
|
-
}
|
|
670
|
-
};`;
|
|
671
|
-
|
|
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;
|
|
675
|
-
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
676
|
-
const DAYS = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
|
|
677
|
-
const MONTHS = ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
|
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
|
-
}
|
|
702
|
-
switch (t) {
|
|
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());
|
|
722
|
-
case "Z07:00": {
|
|
723
|
-
const o = -getTimezoneOffset();
|
|
724
|
-
return o === 0 ? "Z" : (o > 0 ? "+" : "-") + pad(Math.floor(Math.abs(o) / 60)) + ":" + pad(Math.abs(o) % 60);
|
|
725
|
-
}
|
|
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";
|
|
735
|
-
default: return t;
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
};`;
|
|
739
|
-
|
|
740
|
-
export const HELPER_TIME_PARSE = `var __timeParse = __timeParse || function(layout, value) {
|
|
741
|
-
try {
|
|
742
|
-
const d = new Date(value);
|
|
743
|
-
if (isNaN(d.getTime())) throw 0;
|
|
744
|
-
return [{ _d: d }, null];
|
|
745
|
-
} catch {
|
|
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 }];
|
|
747
|
-
}
|
|
748
|
-
};`;
|
|
749
|
-
|
|
750
|
-
export const HELPER_TESTING = `var __GoFront_FailNow = __GoFront_FailNow || class extends Error {
|
|
751
|
-
constructor() { super("FailNow"); this.name = "__GoFront_FailNow"; }
|
|
752
|
-
};
|
|
753
|
-
var __GoFront_SkipNow = __GoFront_SkipNow || class extends Error {
|
|
754
|
-
constructor() { super("SkipNow"); this.name = "__GoFront_SkipNow"; }
|
|
755
|
-
};
|
|
756
|
-
var __GoFront_T = __GoFront_T || class {
|
|
757
|
-
constructor(name = "", parent = null) {
|
|
758
|
-
this._name = name;
|
|
759
|
-
this._parent = parent;
|
|
760
|
-
this.failed = false;
|
|
761
|
-
this.skipped = false;
|
|
762
|
-
this._logs = [];
|
|
763
|
-
this._start = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
764
|
-
}
|
|
765
|
-
Name() { return this._name; }
|
|
766
|
-
Fail() {
|
|
767
|
-
this.failed = true;
|
|
768
|
-
if (this._parent) this._parent.Fail();
|
|
769
|
-
}
|
|
770
|
-
Failed() { return this.failed; }
|
|
771
|
-
FailNow() {
|
|
772
|
-
this.Fail();
|
|
773
|
-
throw new __GoFront_FailNow();
|
|
774
|
-
}
|
|
775
|
-
Log(...args) {
|
|
776
|
-
const msg = args.map(a => {
|
|
777
|
-
if (typeof a === "object" && a !== null) {
|
|
778
|
-
try { return JSON.stringify(a); } catch { return String(a); }
|
|
779
|
-
}
|
|
780
|
-
return String(a);
|
|
781
|
-
}).join(" ");
|
|
782
|
-
this._logs.push(msg);
|
|
783
|
-
}
|
|
784
|
-
Logf(format, ...args) {
|
|
785
|
-
const msg = typeof __sprintf === "function" ? __sprintf(format, ...args) : format;
|
|
786
|
-
this._logs.push(msg);
|
|
787
|
-
}
|
|
788
|
-
Error(...args) {
|
|
789
|
-
this.Fail();
|
|
790
|
-
this.Log(...args);
|
|
791
|
-
}
|
|
792
|
-
Errorf(format, ...args) {
|
|
793
|
-
this.Fail();
|
|
794
|
-
this.Logf(format, ...args);
|
|
795
|
-
}
|
|
796
|
-
Fatal(...args) {
|
|
797
|
-
this.Log(...args);
|
|
798
|
-
this.FailNow();
|
|
799
|
-
}
|
|
800
|
-
Fatalf(format, ...args) {
|
|
801
|
-
this.Logf(format, ...args);
|
|
802
|
-
this.FailNow();
|
|
803
|
-
}
|
|
804
|
-
Skip(...args) {
|
|
805
|
-
this.skipped = true;
|
|
806
|
-
if (args.length > 0) this.Log(...args);
|
|
807
|
-
throw new __GoFront_SkipNow();
|
|
808
|
-
}
|
|
809
|
-
Skipf(format, ...args) {
|
|
810
|
-
this.skipped = true;
|
|
811
|
-
this.Logf(format, ...args);
|
|
812
|
-
throw new __GoFront_SkipNow();
|
|
813
|
-
}
|
|
814
|
-
Skipped() { return this.skipped; }
|
|
815
|
-
Helper() {}
|
|
816
|
-
Run(name, fn) {
|
|
817
|
-
const subName = this._name ? \`\${this._name}/\${name}\` : name;
|
|
818
|
-
const subT = new __GoFront_T(subName, this);
|
|
819
|
-
if (typeof globalThis.__onSubtestStart === "function") globalThis.__onSubtestStart(subName);
|
|
820
|
-
try {
|
|
821
|
-
const res = fn(subT);
|
|
822
|
-
if (res && typeof res.then === "function") {
|
|
823
|
-
return res.then(() => {
|
|
824
|
-
if (typeof globalThis.__onSubtestEnd === "function") globalThis.__onSubtestEnd(subT);
|
|
825
|
-
return !subT.failed;
|
|
826
|
-
}).catch(e => {
|
|
827
|
-
if (e instanceof __GoFront_FailNow) {
|
|
828
|
-
// expected
|
|
829
|
-
} else if (e instanceof __GoFront_SkipNow) {
|
|
830
|
-
// expected
|
|
831
|
-
} else {
|
|
832
|
-
subT.Fail();
|
|
833
|
-
subT.Log("panic: " + (e?.message ?? String(e)));
|
|
834
|
-
}
|
|
835
|
-
if (typeof globalThis.__onSubtestEnd === "function") globalThis.__onSubtestEnd(subT);
|
|
836
|
-
return false;
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
} catch (e) {
|
|
840
|
-
if (e instanceof __GoFront_FailNow) {
|
|
841
|
-
// expected on FailNow
|
|
842
|
-
} else if (e instanceof __GoFront_SkipNow) {
|
|
843
|
-
// expected on Skip
|
|
844
|
-
} else {
|
|
845
|
-
subT.Fail();
|
|
846
|
-
subT.Log("panic: " + (e?.message ?? String(e)));
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
if (typeof globalThis.__onSubtestEnd === "function") globalThis.__onSubtestEnd(subT);
|
|
850
|
-
return !subT.failed;
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
var __testing_T = __GoFront_T;`;
|
|
854
|
-
|
|
855
953
|
export const HELPER_INJECT_STYLES = `var __injectStyles = __injectStyles || function(css) {
|
|
856
954
|
if (typeof document === "undefined" || !document || !document.head || !css) return;
|
|
857
955
|
let s = document.getElementById("gofront-styles");
|
|
@@ -863,986 +961,119 @@ export const HELPER_INJECT_STYLES = `var __injectStyles = __injectStyles || func
|
|
|
863
961
|
s.textContent += "\\n" + css;
|
|
864
962
|
};`;
|
|
865
963
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
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";
|
|
964
|
+
// internal/jsonrt's encoder writes into `e.buf[0:e.n]`; these helpers append
|
|
965
|
+
// to it directly (see the jsonrt natives in natives.js).
|
|
966
|
+
export const HELPER_JSONRT = `var __jte = __jte || new TextEncoder();
|
|
967
|
+
var __jroom = __jroom || function(e, k) {
|
|
968
|
+
var need = e.n + k;
|
|
969
|
+
if (need > e.buf.length) {
|
|
970
|
+
var nb = new Uint8Array(Math.max(need, e.buf.length * 2));
|
|
971
|
+
nb.set(e.buf.subarray(0, e.n));
|
|
972
|
+
e.buf = nb;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
var __jput = __jput || function(e, s) {
|
|
976
|
+
var l = s.length, i = 0;
|
|
977
|
+
__jroom(e, l);
|
|
978
|
+
var buf = e.buf, n = e.n;
|
|
979
|
+
for (; i < l; i++) {
|
|
980
|
+
var c = s.charCodeAt(i);
|
|
981
|
+
if (c > 127) break;
|
|
982
|
+
buf[n + i] = c;
|
|
983
|
+
}
|
|
984
|
+
e.n = n + i;
|
|
985
|
+
if (i < l) {
|
|
986
|
+
var u = __jte.encode(s.slice(i));
|
|
987
|
+
__jroom(e, u.length);
|
|
988
|
+
e.buf.set(u, e.n);
|
|
989
|
+
e.n += u.length;
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
var __jint = __jint || function(e, v) { __jput(e, String(v)); };
|
|
993
|
+
var __jfloat = __jfloat || function(e, f, bits) {
|
|
994
|
+
if (bits === 32) {
|
|
995
|
+
var g = Math.fround(f);
|
|
996
|
+
for (var p = 1; p <= 9; p++) {
|
|
997
|
+
var t = g.toPrecision(p);
|
|
998
|
+
if (Math.fround(+t) === g) { f = +t; break; }
|
|
910
999
|
}
|
|
911
1000
|
}
|
|
912
|
-
|
|
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];
|
|
1001
|
+
__jput(e, String(f));
|
|
945
1002
|
};
|
|
946
|
-
var
|
|
947
|
-
|
|
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;
|
|
1003
|
+
var __jescRe = __jescRe || /[\\u0000-\\u001f"\\\\<>&\\u2028\\u2029\\ud800-\\udfff]/;
|
|
1004
|
+
var __jescRe2 = __jescRe2 || /[\\u0000-\\u001f"\\\\\\u2028\\u2029\\ud800-\\udfff]/;
|
|
1005
|
+
var __jesc = __jesc || function(s, html) {
|
|
1006
|
+
var out = "", start = 0;
|
|
1412
1007
|
for (var i = 0; i < s.length; i++) {
|
|
1413
|
-
var c = s
|
|
1414
|
-
if (
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
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) {}
|
|
1008
|
+
var c = s.charCodeAt(i), r = null;
|
|
1009
|
+
if (c < 0x20) {
|
|
1010
|
+
r = c === 8 ? "\\\\b" : c === 12 ? "\\\\f" : c === 10 ? "\\\\n" : c === 13 ? "\\\\r" : c === 9 ? "\\\\t" : "\\\\u00" + (c < 16 ? "0" : "") + c.toString(16);
|
|
1011
|
+
} else if (c === 34) r = '\\\\"';
|
|
1012
|
+
else if (c === 92) r = "\\\\\\\\";
|
|
1013
|
+
else if (html && (c === 60 || c === 62 || c === 38)) r = "\\\\u00" + c.toString(16);
|
|
1014
|
+
else if (c === 0x2028 || c === 0x2029) r = "\\\\u202" + (c & 15).toString(16);
|
|
1015
|
+
else if (c >= 0xd800 && c <= 0xdfff) {
|
|
1016
|
+
var d = i + 1 < s.length ? s.charCodeAt(i + 1) : 0;
|
|
1017
|
+
if (c < 0xdc00 && d >= 0xdc00 && d <= 0xdfff) { i++; continue; }
|
|
1018
|
+
r = "\\ufffd";
|
|
1641
1019
|
}
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
if (
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
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])));
|
|
1020
|
+
if (r !== null) { out += s.slice(start, i) + r; start = i + 1; }
|
|
1021
|
+
}
|
|
1022
|
+
return out + s.slice(start);
|
|
1023
|
+
};
|
|
1024
|
+
var __jtd = __jtd || new TextDecoder("utf-8", { ignoreBOM: true });
|
|
1025
|
+
var __jrstr = __jrstr || function(d, unquote) {
|
|
1026
|
+
var data = d.data, p = d.pos + 1, start = p, n = data.length, esc = false;
|
|
1027
|
+
for (; p < n; p++) {
|
|
1028
|
+
var c = data[p];
|
|
1029
|
+
if (c === 34) break;
|
|
1030
|
+
if (c === 92) { esc = true; p++; }
|
|
1031
|
+
}
|
|
1032
|
+
d.pos = p + 1;
|
|
1033
|
+
if (esc) return unquote(data.subarray(start, p));
|
|
1034
|
+
if (p - start < 32) {
|
|
1035
|
+
var s = "";
|
|
1036
|
+
for (var i = start; i < p; i++) {
|
|
1037
|
+
var b = data[i];
|
|
1038
|
+
if (b > 127) return __jtd.decode(data.subarray(start, p));
|
|
1039
|
+
s += String.fromCharCode(b);
|
|
1672
1040
|
}
|
|
1673
|
-
return
|
|
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;
|
|
1041
|
+
return s;
|
|
1720
1042
|
}
|
|
1721
|
-
return
|
|
1043
|
+
return __jtd.decode(data.subarray(start, p));
|
|
1722
1044
|
};
|
|
1723
|
-
var
|
|
1724
|
-
var
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
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];
|
|
1045
|
+
var __jrnum = __jrnum || function(d) {
|
|
1046
|
+
var data = d.data, p = d.pos, start = p, n = data.length, s = "";
|
|
1047
|
+
for (; p < n; p++) {
|
|
1048
|
+
var c = data[p];
|
|
1049
|
+
if (!((c >= 48 && c <= 57) || c === 45 || c === 43 || c === 46 || c === 101 || c === 69)) break;
|
|
1050
|
+
s += String.fromCharCode(c);
|
|
1760
1051
|
}
|
|
1052
|
+
d.pos = p;
|
|
1053
|
+
return s;
|
|
1761
1054
|
};
|
|
1762
|
-
var
|
|
1763
|
-
|
|
1764
|
-
var
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
var
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
if (
|
|
1772
|
-
else if (c ===
|
|
1773
|
-
else if (c ===
|
|
1774
|
-
continue;
|
|
1055
|
+
var __jvalid = __jvalid || function(data) {
|
|
1056
|
+
if (data === null || data === undefined) return false;
|
|
1057
|
+
var n = data.length;
|
|
1058
|
+
if (n > 10000) {
|
|
1059
|
+
// encoding/json stops at a nesting depth of 10000.
|
|
1060
|
+
var depth = 0, inStr = false;
|
|
1061
|
+
for (var i = 0; i < n; i++) {
|
|
1062
|
+
var c = data[i];
|
|
1063
|
+
if (inStr) { if (c === 92) i++; else if (c === 34) inStr = false; }
|
|
1064
|
+
else if (c === 34) inStr = true;
|
|
1065
|
+
else if (c === 91 || c === 123) { if (++depth > 10000) return false; }
|
|
1066
|
+
else if (c === 93 || c === 125) depth--;
|
|
1775
1067
|
}
|
|
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
1068
|
}
|
|
1069
|
+
try { JSON.parse(__jtd.decode(data)); return true; } catch (e) { return false; }
|
|
1816
1070
|
};
|
|
1817
|
-
var
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
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;
|
|
1071
|
+
var __jquote = __jquote || function(e, s) {
|
|
1072
|
+
__jroom(e, 1);
|
|
1073
|
+
e.buf[e.n++] = 34;
|
|
1074
|
+
__jput(e, (e.EscapeHTML ? __jescRe : __jescRe2).test(s) ? __jesc(s, e.EscapeHTML) : s);
|
|
1075
|
+
__jroom(e, 1);
|
|
1076
|
+
e.buf[e.n++] = 34;
|
|
1846
1077
|
};`;
|
|
1847
1078
|
|
|
1848
1079
|
export const HELPER_SIMD = `var __simd_f32x4 = __simd_f32x4 || function(a, b, c, d) {
|
|
@@ -1881,6 +1112,59 @@ var __simd_with_lane = __simd_with_lane || function(a, i, v) {
|
|
|
1881
1112
|
r[i] = Math.fround(v);
|
|
1882
1113
|
return Object.freeze(r);
|
|
1883
1114
|
};
|
|
1115
|
+
var __simd_map = __simd_map || function(a, f) {
|
|
1116
|
+
return Object.freeze([Math.fround(f(a[0])), Math.fround(f(a[1])), Math.fround(f(a[2])), Math.fround(f(a[3]))]);
|
|
1117
|
+
};
|
|
1118
|
+
var __simd_neg = __simd_neg || function(a) { return __simd_map(a, function(x) { return -x; }); };
|
|
1119
|
+
var __simd_abs = __simd_abs || function(a) { return __simd_map(a, Math.abs); };
|
|
1120
|
+
var __simd_sqrt = __simd_sqrt || function(a) { return __simd_map(a, Math.sqrt); };
|
|
1121
|
+
var __simd_floor = __simd_floor || function(a) { return __simd_map(a, Math.floor); };
|
|
1122
|
+
var __simd_ceil = __simd_ceil || function(a) { return __simd_map(a, Math.ceil); };
|
|
1123
|
+
var __simd_trunc = __simd_trunc || function(a) { return __simd_map(a, Math.trunc); };
|
|
1124
|
+
var __simd_nearest = __simd_nearest || function(a) {
|
|
1125
|
+
return __simd_map(a, function(x) {
|
|
1126
|
+
if (!isFinite(x)) return x;
|
|
1127
|
+
var f = Math.floor(x), d = x - f, r;
|
|
1128
|
+
if (d < 0.5) r = f; else if (d > 0.5) r = f + 1; else r = (f % 2 === 0) ? f : f + 1;
|
|
1129
|
+
return (r === 0 && (x < 0 || Object.is(x, -0))) ? -0 : r;
|
|
1130
|
+
});
|
|
1131
|
+
};
|
|
1132
|
+
var __simd_muladd = __simd_muladd || function(a, b, c) {
|
|
1133
|
+
return Object.freeze([Math.fround(Math.fround(a[0] * b[0]) + c[0]), Math.fround(Math.fround(a[1] * b[1]) + c[1]), Math.fround(Math.fround(a[2] * b[2]) + c[2]), Math.fround(Math.fround(a[3] * b[3]) + c[3])]);
|
|
1134
|
+
};
|
|
1135
|
+
var __simd_sum = __simd_sum || function(a) {
|
|
1136
|
+
return Math.fround(Math.fround(Math.fround(a[0] + a[1]) + a[2]) + a[3]);
|
|
1137
|
+
};
|
|
1138
|
+
var __simd_cmp = __simd_cmp || function(a, b, f) {
|
|
1139
|
+
return Object.freeze([f(a[0], b[0]), f(a[1], b[1]), f(a[2], b[2]), f(a[3], b[3])]);
|
|
1140
|
+
};
|
|
1141
|
+
var __simd_eq = __simd_eq || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x === y; }); };
|
|
1142
|
+
var __simd_ne = __simd_ne || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x !== y; }); };
|
|
1143
|
+
var __simd_lt = __simd_lt || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x < y; }); };
|
|
1144
|
+
var __simd_le = __simd_le || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x <= y; }); };
|
|
1145
|
+
var __simd_gt = __simd_gt || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x > y; }); };
|
|
1146
|
+
var __simd_ge = __simd_ge || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x >= y; }); };
|
|
1147
|
+
var __simd_equal = __simd_equal || function(a, b) {
|
|
1148
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
1149
|
+
};
|
|
1150
|
+
var __simd_mask_and = __simd_mask_and || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x && y; }); };
|
|
1151
|
+
var __simd_mask_or = __simd_mask_or || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x || y; }); };
|
|
1152
|
+
var __simd_mask_xor = __simd_mask_xor || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x !== y; }); };
|
|
1153
|
+
var __simd_mask_andnot = __simd_mask_andnot || function(a, b) { return __simd_cmp(a, b, function(x, y) { return x && !y; }); };
|
|
1154
|
+
var __simd_mask_not = __simd_mask_not || function(a) { return Object.freeze([!a[0], !a[1], !a[2], !a[3]]); };
|
|
1155
|
+
var __simd_mask_any = __simd_mask_any || function(a) { return a[0] || a[1] || a[2] || a[3]; };
|
|
1156
|
+
var __simd_mask_all = __simd_mask_all || function(a) { return a[0] && a[1] && a[2] && a[3]; };
|
|
1157
|
+
var __simd_mask_bits = __simd_mask_bits || function(a) { return (a[0] ? 1 : 0) | (a[1] ? 2 : 0) | (a[2] ? 4 : 0) | (a[3] ? 8 : 0); };
|
|
1158
|
+
var __simd_select = __simd_select || function(m, a, b) {
|
|
1159
|
+
return Object.freeze([m[0] ? a[0] : b[0], m[1] ? a[1] : b[1], m[2] ? a[2] : b[2], m[3] ? a[3] : b[3]]);
|
|
1160
|
+
};
|
|
1161
|
+
var __simd_shuffle = __simd_shuffle || function(a, b, i0, i1, i2, i3) {
|
|
1162
|
+
var c = [a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]];
|
|
1163
|
+
return Object.freeze([c[i0], c[i1], c[i2], c[i3]]);
|
|
1164
|
+
};
|
|
1165
|
+
var __simd_swizzle = __simd_swizzle || function(a, i0, i1, i2, i3) {
|
|
1166
|
+
return Object.freeze([a[i0], a[i1], a[i2], a[i3]]);
|
|
1167
|
+
};
|
|
1884
1168
|
var __simd_load = __simd_load || function(buf, i) {
|
|
1885
1169
|
if (i < 0 || i + 4 > buf.length) throw new Error("panic: runtime error: index out of range");
|
|
1886
1170
|
return Object.freeze([Math.fround(buf[i]), Math.fround(buf[i + 1]), Math.fround(buf[i + 2]), Math.fround(buf[i + 3])]);
|
|
@@ -1888,4 +1172,12 @@ var __simd_load = __simd_load || function(buf, i) {
|
|
|
1888
1172
|
var __simd_store = __simd_store || function(buf, i, v) {
|
|
1889
1173
|
if (i < 0 || i + 4 > buf.length) throw new Error("panic: runtime error: index out of range");
|
|
1890
1174
|
buf[i] = v[0]; buf[i + 1] = v[1]; buf[i + 2] = v[2]; buf[i + 3] = v[3];
|
|
1175
|
+
};
|
|
1176
|
+
var __simd_load_slice = __simd_load_slice || function(xs, i) {
|
|
1177
|
+
if (xs == null || i < 0 || i + 4 > xs.length) throw new Error("panic: runtime error: index out of range");
|
|
1178
|
+
return Object.freeze([xs[i], xs[i + 1], xs[i + 2], xs[i + 3]]);
|
|
1179
|
+
};
|
|
1180
|
+
var __simd_store_slice = __simd_store_slice || function(xs, i, v) {
|
|
1181
|
+
if (xs == null || i < 0 || i + 4 > xs.length) throw new Error("panic: runtime error: index out of range");
|
|
1182
|
+
xs[i] = v[0]; xs[i + 1] = v[1]; xs[i + 2] = v[2]; xs[i + 3] = v[3];
|
|
1891
1183
|
};`;
|