brsh 2.6.0 → 2.8.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/CHANGELOG.md +20 -0
- package/Readme.md +145 -1
- package/bin/Readme.md +6 -3
- package/bin/brsh-shell.js +68 -9
- package/bin/exportFileSystem.js +192 -80
- package/dist/shell.es.js +2497 -1300
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +21 -14
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +101 -0
- package/dist/terminal.cjs.js.map +1 -0
- package/dist/terminal.es.js +290 -6965
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +4 -25
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +3974 -0
- package/dist/wbt.es.js.map +1 -0
- package/dist/wbt.min.js +10 -0
- package/dist/wbt.min.js.map +1 -0
- package/index.js +160 -20
- package/lib/BinaryContainer.js +528 -0
- package/lib/Command.js +2 -1
- package/lib/FileSystem.js +31 -0
- package/lib/NodeFileSystem.js +19 -9
- package/lib/ReplCommand.js +520 -0
- package/lib/ScriptCommand.js +1 -1
- package/lib/Terminal.js +45 -10
- package/lib/WasmCommand.js +1123 -35
- package/lib/buildFilesystemStructure.js +15 -4
- package/lib/local/curl.js +60 -2
- package/lib/wbt/index.js +756 -0
- package/lib/wbt/packages/wllama.js +1051 -0
- package/lib/wbt/registry.js +193 -0
- package/lib/wbt/utils.js +118 -0
- package/package.json +11 -3
- package/test/binary-filesystem.test.js +248 -0
- package/test/curl.test.js +166 -0
- package/test/exportFileSystem.test.js +78 -0
- package/test/terminal.test.js +113 -0
- package/test/wasm-cli.test.js +127 -0
- package/test/wbt.test.js +1175 -0
- package/vite.config.demo.js +4 -0
- package/vite.config.js +4 -0
- package/vite.config.terminal.js +16 -12
- package/vite.config.wbt.js +21 -0
- package/vitest.config.js +6 -0
package/dist/wbt.es.js
ADDED
|
@@ -0,0 +1,3974 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var e = (e, t) => () => (e && (t = e(e = 0)), t), t = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), n = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
3
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
4
|
+
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
+
}), r = /* @__PURE__ */ t(((e, t) => {
|
|
6
|
+
var n = typeof Reflect == "object" ? Reflect : null, r = n && typeof n.apply == "function" ? n.apply : function(e, t, n) {
|
|
7
|
+
return Function.prototype.apply.call(e, t, n);
|
|
8
|
+
}, i = n && typeof n.ownKeys == "function" ? n.ownKeys : Object.getOwnPropertySymbols ? function(e) {
|
|
9
|
+
return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e));
|
|
10
|
+
} : function(e) {
|
|
11
|
+
return Object.getOwnPropertyNames(e);
|
|
12
|
+
};
|
|
13
|
+
function a(e) {
|
|
14
|
+
console && console.warn && console.warn(e);
|
|
15
|
+
}
|
|
16
|
+
var o = Number.isNaN || function(e) {
|
|
17
|
+
return e !== e;
|
|
18
|
+
};
|
|
19
|
+
function s() {
|
|
20
|
+
s.init.call(this);
|
|
21
|
+
}
|
|
22
|
+
t.exports = s, t.exports.once = y, s.EventEmitter = s, s.prototype._events = void 0, s.prototype._eventsCount = 0, s.prototype._maxListeners = void 0;
|
|
23
|
+
var c = 10;
|
|
24
|
+
function l(e) {
|
|
25
|
+
if (typeof e != "function") throw TypeError("The \"listener\" argument must be of type Function. Received type " + typeof e);
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(s, "defaultMaxListeners", {
|
|
28
|
+
enumerable: !0,
|
|
29
|
+
get: function() {
|
|
30
|
+
return c;
|
|
31
|
+
},
|
|
32
|
+
set: function(e) {
|
|
33
|
+
if (typeof e != "number" || e < 0 || o(e)) throw RangeError("The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received " + e + ".");
|
|
34
|
+
c = e;
|
|
35
|
+
}
|
|
36
|
+
}), s.init = function() {
|
|
37
|
+
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
|
|
38
|
+
}, s.prototype.setMaxListeners = function(e) {
|
|
39
|
+
if (typeof e != "number" || e < 0 || o(e)) throw RangeError("The value of \"n\" is out of range. It must be a non-negative number. Received " + e + ".");
|
|
40
|
+
return this._maxListeners = e, this;
|
|
41
|
+
};
|
|
42
|
+
function u(e) {
|
|
43
|
+
return e._maxListeners === void 0 ? s.defaultMaxListeners : e._maxListeners;
|
|
44
|
+
}
|
|
45
|
+
s.prototype.getMaxListeners = function() {
|
|
46
|
+
return u(this);
|
|
47
|
+
}, s.prototype.emit = function(e) {
|
|
48
|
+
for (var t = [], n = 1; n < arguments.length; n++) t.push(arguments[n]);
|
|
49
|
+
var i = e === "error", a = this._events;
|
|
50
|
+
if (a !== void 0) i &&= a.error === void 0;
|
|
51
|
+
else if (!i) return !1;
|
|
52
|
+
if (i) {
|
|
53
|
+
var o;
|
|
54
|
+
if (t.length > 0 && (o = t[0]), o instanceof Error) throw o;
|
|
55
|
+
var s = /* @__PURE__ */ Error("Unhandled error." + (o ? " (" + o.message + ")" : ""));
|
|
56
|
+
throw s.context = o, s;
|
|
57
|
+
}
|
|
58
|
+
var c = a[e];
|
|
59
|
+
if (c === void 0) return !1;
|
|
60
|
+
if (typeof c == "function") r(c, this, t);
|
|
61
|
+
else for (var l = c.length, u = g(c, l), n = 0; n < l; ++n) r(u[n], this, t);
|
|
62
|
+
return !0;
|
|
63
|
+
};
|
|
64
|
+
function d(e, t, n, r) {
|
|
65
|
+
var i, o, s;
|
|
66
|
+
if (l(n), o = e._events, o === void 0 ? (o = e._events = Object.create(null), e._eventsCount = 0) : (o.newListener !== void 0 && (e.emit("newListener", t, n.listener ? n.listener : n), o = e._events), s = o[t]), s === void 0) s = o[t] = n, ++e._eventsCount;
|
|
67
|
+
else if (typeof s == "function" ? s = o[t] = r ? [n, s] : [s, n] : r ? s.unshift(n) : s.push(n), i = u(e), i > 0 && s.length > i && !s.warned) {
|
|
68
|
+
s.warned = !0;
|
|
69
|
+
var c = /* @__PURE__ */ Error("Possible EventEmitter memory leak detected. " + s.length + " " + String(t) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
70
|
+
c.name = "MaxListenersExceededWarning", c.emitter = e, c.type = t, c.count = s.length, a(c);
|
|
71
|
+
}
|
|
72
|
+
return e;
|
|
73
|
+
}
|
|
74
|
+
s.prototype.addListener = function(e, t) {
|
|
75
|
+
return d(this, e, t, !1);
|
|
76
|
+
}, s.prototype.on = s.prototype.addListener, s.prototype.prependListener = function(e, t) {
|
|
77
|
+
return d(this, e, t, !0);
|
|
78
|
+
};
|
|
79
|
+
function f() {
|
|
80
|
+
if (!this.fired) return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
|
|
81
|
+
}
|
|
82
|
+
function p(e, t, n) {
|
|
83
|
+
var r = {
|
|
84
|
+
fired: !1,
|
|
85
|
+
wrapFn: void 0,
|
|
86
|
+
target: e,
|
|
87
|
+
type: t,
|
|
88
|
+
listener: n
|
|
89
|
+
}, i = f.bind(r);
|
|
90
|
+
return i.listener = n, r.wrapFn = i, i;
|
|
91
|
+
}
|
|
92
|
+
s.prototype.once = function(e, t) {
|
|
93
|
+
return l(t), this.on(e, p(this, e, t)), this;
|
|
94
|
+
}, s.prototype.prependOnceListener = function(e, t) {
|
|
95
|
+
return l(t), this.prependListener(e, p(this, e, t)), this;
|
|
96
|
+
}, s.prototype.removeListener = function(e, t) {
|
|
97
|
+
var n, r, i, a, o;
|
|
98
|
+
if (l(t), r = this._events, r === void 0 || (n = r[e], n === void 0)) return this;
|
|
99
|
+
if (n === t || n.listener === t) --this._eventsCount === 0 ? this._events = Object.create(null) : (delete r[e], r.removeListener && this.emit("removeListener", e, n.listener || t));
|
|
100
|
+
else if (typeof n != "function") {
|
|
101
|
+
for (i = -1, a = n.length - 1; a >= 0; a--) if (n[a] === t || n[a].listener === t) {
|
|
102
|
+
o = n[a].listener, i = a;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (i < 0) return this;
|
|
106
|
+
i === 0 ? n.shift() : _(n, i), n.length === 1 && (r[e] = n[0]), r.removeListener !== void 0 && this.emit("removeListener", e, o || t);
|
|
107
|
+
}
|
|
108
|
+
return this;
|
|
109
|
+
}, s.prototype.off = s.prototype.removeListener, s.prototype.removeAllListeners = function(e) {
|
|
110
|
+
var t, n = this._events, r;
|
|
111
|
+
if (n === void 0) return this;
|
|
112
|
+
if (n.removeListener === void 0) return arguments.length === 0 ? (this._events = Object.create(null), this._eventsCount = 0) : n[e] !== void 0 && (--this._eventsCount === 0 ? this._events = Object.create(null) : delete n[e]), this;
|
|
113
|
+
if (arguments.length === 0) {
|
|
114
|
+
var i = Object.keys(n), a;
|
|
115
|
+
for (r = 0; r < i.length; ++r) a = i[r], a !== "removeListener" && this.removeAllListeners(a);
|
|
116
|
+
return this.removeAllListeners("removeListener"), this._events = Object.create(null), this._eventsCount = 0, this;
|
|
117
|
+
}
|
|
118
|
+
if (t = n[e], typeof t == "function") this.removeListener(e, t);
|
|
119
|
+
else if (t !== void 0) for (r = t.length - 1; r >= 0; r--) this.removeListener(e, t[r]);
|
|
120
|
+
return this;
|
|
121
|
+
};
|
|
122
|
+
function m(e, t, n) {
|
|
123
|
+
var r = e._events;
|
|
124
|
+
if (r === void 0) return [];
|
|
125
|
+
var i = r[t];
|
|
126
|
+
return i === void 0 ? [] : typeof i == "function" ? n ? [i.listener || i] : [i] : n ? v(i) : g(i, i.length);
|
|
127
|
+
}
|
|
128
|
+
s.prototype.listeners = function(e) {
|
|
129
|
+
return m(this, e, !0);
|
|
130
|
+
}, s.prototype.rawListeners = function(e) {
|
|
131
|
+
return m(this, e, !1);
|
|
132
|
+
}, s.listenerCount = function(e, t) {
|
|
133
|
+
return typeof e.listenerCount == "function" ? e.listenerCount(t) : h.call(e, t);
|
|
134
|
+
}, s.prototype.listenerCount = h;
|
|
135
|
+
function h(e) {
|
|
136
|
+
var t = this._events;
|
|
137
|
+
if (t !== void 0) {
|
|
138
|
+
var n = t[e];
|
|
139
|
+
if (typeof n == "function") return 1;
|
|
140
|
+
if (n !== void 0) return n.length;
|
|
141
|
+
}
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
s.prototype.eventNames = function() {
|
|
145
|
+
return this._eventsCount > 0 ? i(this._events) : [];
|
|
146
|
+
};
|
|
147
|
+
function g(e, t) {
|
|
148
|
+
for (var n = Array(t), r = 0; r < t; ++r) n[r] = e[r];
|
|
149
|
+
return n;
|
|
150
|
+
}
|
|
151
|
+
function _(e, t) {
|
|
152
|
+
for (; t + 1 < e.length; t++) e[t] = e[t + 1];
|
|
153
|
+
e.pop();
|
|
154
|
+
}
|
|
155
|
+
function v(e) {
|
|
156
|
+
for (var t = Array(e.length), n = 0; n < t.length; ++n) t[n] = e[n].listener || e[n];
|
|
157
|
+
return t;
|
|
158
|
+
}
|
|
159
|
+
function y(e, t) {
|
|
160
|
+
return new Promise(function(n, r) {
|
|
161
|
+
function i(n) {
|
|
162
|
+
e.removeListener(t, a), r(n);
|
|
163
|
+
}
|
|
164
|
+
function a() {
|
|
165
|
+
typeof e.removeListener == "function" && e.removeListener("error", i), n([].slice.call(arguments));
|
|
166
|
+
}
|
|
167
|
+
x(e, t, a, { once: !0 }), t !== "error" && b(e, i, { once: !0 });
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function b(e, t, n) {
|
|
171
|
+
typeof e.on == "function" && x(e, "error", t, n);
|
|
172
|
+
}
|
|
173
|
+
function x(e, t, n, r) {
|
|
174
|
+
if (typeof e.on == "function") r.once ? e.once(t, n) : e.on(t, n);
|
|
175
|
+
else if (typeof e.addEventListener == "function") e.addEventListener(t, function i(a) {
|
|
176
|
+
r.once && e.removeEventListener(t, i), n(a);
|
|
177
|
+
});
|
|
178
|
+
else throw TypeError("The \"emitter\" argument must be of type EventEmitter. Received type " + typeof e);
|
|
179
|
+
}
|
|
180
|
+
})), i = /* @__PURE__ */ t(((e, t) => {
|
|
181
|
+
var n = ["out", "err"];
|
|
182
|
+
t.exports = class {
|
|
183
|
+
constructor(e, t) {
|
|
184
|
+
if (!n.includes(e)) throw Error("incorrect std output type");
|
|
185
|
+
this.type = e, this.string = t;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
})), a = /* @__PURE__ */ t(((e, t) => {
|
|
189
|
+
var n = i();
|
|
190
|
+
t.exports = class {
|
|
191
|
+
constructor(e = [], t = 0) {
|
|
192
|
+
if (typeof t != "number") throw Error("Command Result ExitCode must be a number");
|
|
193
|
+
if (!Array.isArray(e)) throw Error("Command Result be array");
|
|
194
|
+
this.std = e, this.exitCode = t;
|
|
195
|
+
}
|
|
196
|
+
addStdOutLine(e) {
|
|
197
|
+
this.std.push(new n("out", e));
|
|
198
|
+
}
|
|
199
|
+
addStdErrLine(e) {
|
|
200
|
+
this.std.push(new n("err", e));
|
|
201
|
+
}
|
|
202
|
+
getStdOutput() {
|
|
203
|
+
return this.std;
|
|
204
|
+
}
|
|
205
|
+
getExitCode() {
|
|
206
|
+
return this.exitCode;
|
|
207
|
+
}
|
|
208
|
+
flush() {
|
|
209
|
+
let e = this.std;
|
|
210
|
+
return this.std = [], e;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
})), o = /* @__PURE__ */ t(((e, t) => {
|
|
214
|
+
var n = r(), i = a(), o = n.EventEmitter || n.default || n;
|
|
215
|
+
t.exports = class extends o {
|
|
216
|
+
constructor(e, t) {
|
|
217
|
+
super(), this.arguments = e, this.result = new i(), this.context = t || null;
|
|
218
|
+
}
|
|
219
|
+
get name() {
|
|
220
|
+
return "unnamed";
|
|
221
|
+
}
|
|
222
|
+
run() {
|
|
223
|
+
return Promise.reject("Command not implemented...");
|
|
224
|
+
}
|
|
225
|
+
runCommand() {
|
|
226
|
+
return Promise.resolve().then(() => this.run()).then((e) => (e && e.split(/\r?\n/).forEach((e) => this.stdOut = e), this.result)).catch((e) => {
|
|
227
|
+
if (e && e.__type) throw e;
|
|
228
|
+
return e && (this.stdErr = e.message || e), this.exitCode = 127, this.result;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
onInput(e) {}
|
|
232
|
+
set exitCode(e) {
|
|
233
|
+
this.result.exitCode = e;
|
|
234
|
+
}
|
|
235
|
+
set stdOut(e) {
|
|
236
|
+
this.result.addStdOutLine(e);
|
|
237
|
+
}
|
|
238
|
+
set stdErr(e) {
|
|
239
|
+
this.result.addStdErrLine(e);
|
|
240
|
+
}
|
|
241
|
+
flush() {
|
|
242
|
+
this.emit("flush", this.result.flush());
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
})), s = /* @__PURE__ */ t(((e, t) => {
|
|
246
|
+
var n = o();
|
|
247
|
+
t.exports = class extends n {
|
|
248
|
+
constructor(e, t) {
|
|
249
|
+
super(e, t);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}));
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region node_modules/vite-plugin-node-polyfills/shims/buffer/dist/index.js
|
|
255
|
+
function c(e) {
|
|
256
|
+
var t = e.length;
|
|
257
|
+
if (t % 4 > 0) throw Error("Invalid string. Length must be a multiple of 4");
|
|
258
|
+
var n = e.indexOf("=");
|
|
259
|
+
n === -1 && (n = t);
|
|
260
|
+
var r = n === t ? 0 : 4 - n % 4;
|
|
261
|
+
return [n, r];
|
|
262
|
+
}
|
|
263
|
+
function l(e) {
|
|
264
|
+
var t = c(e), n = t[0], r = t[1];
|
|
265
|
+
return (n + r) * 3 / 4 - r;
|
|
266
|
+
}
|
|
267
|
+
function u(e, t, n) {
|
|
268
|
+
return (t + n) * 3 / 4 - n;
|
|
269
|
+
}
|
|
270
|
+
function d(e) {
|
|
271
|
+
var t, n = c(e), r = n[0], i = n[1], a = new y(u(e, r, i)), o = 0, s = i > 0 ? r - 4 : r, l;
|
|
272
|
+
for (l = 0; l < s; l += 4) t = v[e.charCodeAt(l)] << 18 | v[e.charCodeAt(l + 1)] << 12 | v[e.charCodeAt(l + 2)] << 6 | v[e.charCodeAt(l + 3)], a[o++] = t >> 16 & 255, a[o++] = t >> 8 & 255, a[o++] = t & 255;
|
|
273
|
+
return i === 2 && (t = v[e.charCodeAt(l)] << 2 | v[e.charCodeAt(l + 1)] >> 4, a[o++] = t & 255), i === 1 && (t = v[e.charCodeAt(l)] << 10 | v[e.charCodeAt(l + 1)] << 4 | v[e.charCodeAt(l + 2)] >> 2, a[o++] = t >> 8 & 255, a[o++] = t & 255), a;
|
|
274
|
+
}
|
|
275
|
+
function f(e) {
|
|
276
|
+
return _[e >> 18 & 63] + _[e >> 12 & 63] + _[e >> 6 & 63] + _[e & 63];
|
|
277
|
+
}
|
|
278
|
+
function p(e, t, n) {
|
|
279
|
+
for (var r, i = [], a = t; a < n; a += 3) r = (e[a] << 16 & 16711680) + (e[a + 1] << 8 & 65280) + (e[a + 2] & 255), i.push(f(r));
|
|
280
|
+
return i.join("");
|
|
281
|
+
}
|
|
282
|
+
function m(e) {
|
|
283
|
+
for (var t, n = e.length, r = n % 3, i = [], a = 16383, o = 0, s = n - r; o < s; o += a) i.push(p(e, o, o + a > s ? s : o + a));
|
|
284
|
+
return r === 1 ? (t = e[n - 1], i.push(_[t >> 2] + _[t << 4 & 63] + "==")) : r === 2 && (t = (e[n - 2] << 8) + e[n - 1], i.push(_[t >> 10] + _[t >> 4 & 63] + _[t << 2 & 63] + "=")), i.join("");
|
|
285
|
+
}
|
|
286
|
+
var h, g, _, v, y, b, x, S, C, w, T = e((() => {
|
|
287
|
+
for (h = {}, g = {}, g.byteLength = l, g.toByteArray = d, g.fromByteArray = m, _ = [], v = [], y = typeof Uint8Array < "u" ? Uint8Array : Array, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", x = 0, S = b.length; x < S; ++x) _[x] = b[x], v[b.charCodeAt(x)] = x;
|
|
288
|
+
v[45] = 62, v[95] = 63, C = {}, C.read = function(e, t, n, r, i) {
|
|
289
|
+
var a, o, s = i * 8 - r - 1, c = (1 << s) - 1, l = c >> 1, u = -7, d = n ? i - 1 : 0, f = n ? -1 : 1, p = e[t + d];
|
|
290
|
+
for (d += f, a = p & (1 << -u) - 1, p >>= -u, u += s; u > 0; a = a * 256 + e[t + d], d += f, u -= 8);
|
|
291
|
+
for (o = a & (1 << -u) - 1, a >>= -u, u += r; u > 0; o = o * 256 + e[t + d], d += f, u -= 8);
|
|
292
|
+
if (a === 0) a = 1 - l;
|
|
293
|
+
else if (a === c) return o ? NaN : (p ? -1 : 1) * Infinity;
|
|
294
|
+
else o += 2 ** r, a -= l;
|
|
295
|
+
return (p ? -1 : 1) * o * 2 ** (a - r);
|
|
296
|
+
}, C.write = function(e, t, n, r, i, a) {
|
|
297
|
+
var o, s, c, l = a * 8 - i - 1, u = (1 << l) - 1, d = u >> 1, f = i === 23 ? 2 ** -24 - 2 ** -77 : 0, p = r ? 0 : a - 1, m = r ? 1 : -1, h = +(t < 0 || t === 0 && 1 / t < 0);
|
|
298
|
+
for (t = Math.abs(t), isNaN(t) || t === Infinity ? (s = +!!isNaN(t), o = u) : (o = Math.floor(Math.log(t) / Math.LN2), t * (c = 2 ** -o) < 1 && (o--, c *= 2), o + d >= 1 ? t += f / c : t += f * 2 ** (1 - d), t * c >= 2 && (o++, c /= 2), o + d >= u ? (s = 0, o = u) : o + d >= 1 ? (s = (t * c - 1) * 2 ** i, o += d) : (s = t * 2 ** (d - 1) * 2 ** i, o = 0)); i >= 8; e[n + p] = s & 255, p += m, s /= 256, i -= 8);
|
|
299
|
+
for (o = o << i | s, l += i; l > 0; e[n + p] = o & 255, p += m, o /= 256, l -= 8);
|
|
300
|
+
e[n + p - m] |= h * 128;
|
|
301
|
+
}, (function(e) {
|
|
302
|
+
let t = g, n = C, r = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
303
|
+
e.Buffer = u, e.SlowBuffer = S, e.INSPECT_MAX_BYTES = 50;
|
|
304
|
+
let i = 2147483647;
|
|
305
|
+
e.kMaxLength = i;
|
|
306
|
+
let { Uint8Array: a, ArrayBuffer: o, SharedArrayBuffer: s } = globalThis;
|
|
307
|
+
u.TYPED_ARRAY_SUPPORT = c(), !u.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");
|
|
308
|
+
function c() {
|
|
309
|
+
try {
|
|
310
|
+
let e = new a(1), t = { foo: function() {
|
|
311
|
+
return 42;
|
|
312
|
+
} };
|
|
313
|
+
return Object.setPrototypeOf(t, a.prototype), Object.setPrototypeOf(e, t), e.foo() === 42;
|
|
314
|
+
} catch {
|
|
315
|
+
return !1;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
Object.defineProperty(u.prototype, "parent", {
|
|
319
|
+
enumerable: !0,
|
|
320
|
+
get: function() {
|
|
321
|
+
if (u.isBuffer(this)) return this.buffer;
|
|
322
|
+
}
|
|
323
|
+
}), Object.defineProperty(u.prototype, "offset", {
|
|
324
|
+
enumerable: !0,
|
|
325
|
+
get: function() {
|
|
326
|
+
if (u.isBuffer(this)) return this.byteOffset;
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
function l(e) {
|
|
330
|
+
if (e > i) throw RangeError("The value \"" + e + "\" is invalid for option \"size\"");
|
|
331
|
+
let t = new a(e);
|
|
332
|
+
return Object.setPrototypeOf(t, u.prototype), t;
|
|
333
|
+
}
|
|
334
|
+
function u(e, t, n) {
|
|
335
|
+
if (typeof e == "number") {
|
|
336
|
+
if (typeof t == "string") throw TypeError("The \"string\" argument must be of type string. Received type number");
|
|
337
|
+
return m(e);
|
|
338
|
+
}
|
|
339
|
+
return d(e, t, n);
|
|
340
|
+
}
|
|
341
|
+
u.poolSize = 8192;
|
|
342
|
+
function d(e, t, n) {
|
|
343
|
+
if (typeof e == "string") return h(e, t);
|
|
344
|
+
if (o.isView(e)) return v(e);
|
|
345
|
+
if (e == null) throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof e);
|
|
346
|
+
if (Q(e, o) || e && Q(e.buffer, o) || s !== void 0 && (Q(e, s) || e && Q(e.buffer, s))) return y(e, t, n);
|
|
347
|
+
if (typeof e == "number") throw TypeError("The \"value\" argument must not be of type number. Received type number");
|
|
348
|
+
let r = e.valueOf && e.valueOf();
|
|
349
|
+
if (r != null && r !== e) return u.from(r, t, n);
|
|
350
|
+
let i = b(e);
|
|
351
|
+
if (i) return i;
|
|
352
|
+
if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof e[Symbol.toPrimitive] == "function") return u.from(e[Symbol.toPrimitive]("string"), t, n);
|
|
353
|
+
throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof e);
|
|
354
|
+
}
|
|
355
|
+
u.from = function(e, t, n) {
|
|
356
|
+
return d(e, t, n);
|
|
357
|
+
}, Object.setPrototypeOf(u.prototype, a.prototype), Object.setPrototypeOf(u, a);
|
|
358
|
+
function f(e) {
|
|
359
|
+
if (typeof e != "number") throw TypeError("\"size\" argument must be of type number");
|
|
360
|
+
if (e < 0) throw RangeError("The value \"" + e + "\" is invalid for option \"size\"");
|
|
361
|
+
}
|
|
362
|
+
function p(e, t, n) {
|
|
363
|
+
return f(e), e <= 0 || t === void 0 ? l(e) : typeof n == "string" ? l(e).fill(t, n) : l(e).fill(t);
|
|
364
|
+
}
|
|
365
|
+
u.alloc = function(e, t, n) {
|
|
366
|
+
return p(e, t, n);
|
|
367
|
+
};
|
|
368
|
+
function m(e) {
|
|
369
|
+
return f(e), l(e < 0 ? 0 : x(e) | 0);
|
|
370
|
+
}
|
|
371
|
+
u.allocUnsafe = function(e) {
|
|
372
|
+
return m(e);
|
|
373
|
+
}, u.allocUnsafeSlow = function(e) {
|
|
374
|
+
return m(e);
|
|
375
|
+
};
|
|
376
|
+
function h(e, t) {
|
|
377
|
+
if ((typeof t != "string" || t === "") && (t = "utf8"), !u.isEncoding(t)) throw TypeError("Unknown encoding: " + t);
|
|
378
|
+
let n = w(e, t) | 0, r = l(n), i = r.write(e, t);
|
|
379
|
+
return i !== n && (r = r.slice(0, i)), r;
|
|
380
|
+
}
|
|
381
|
+
function _(e) {
|
|
382
|
+
let t = e.length < 0 ? 0 : x(e.length) | 0, n = l(t);
|
|
383
|
+
for (let r = 0; r < t; r += 1) n[r] = e[r] & 255;
|
|
384
|
+
return n;
|
|
385
|
+
}
|
|
386
|
+
function v(e) {
|
|
387
|
+
if (Q(e, a)) {
|
|
388
|
+
let t = new a(e);
|
|
389
|
+
return y(t.buffer, t.byteOffset, t.byteLength);
|
|
390
|
+
}
|
|
391
|
+
return _(e);
|
|
392
|
+
}
|
|
393
|
+
function y(e, t, n) {
|
|
394
|
+
if (t < 0 || e.byteLength < t) throw RangeError("\"offset\" is outside of buffer bounds");
|
|
395
|
+
if (e.byteLength < t + (n || 0)) throw RangeError("\"length\" is outside of buffer bounds");
|
|
396
|
+
let r;
|
|
397
|
+
return r = t === void 0 && n === void 0 ? new a(e) : n === void 0 ? new a(e, t) : new a(e, t, n), Object.setPrototypeOf(r, u.prototype), r;
|
|
398
|
+
}
|
|
399
|
+
function b(e) {
|
|
400
|
+
if (u.isBuffer(e)) {
|
|
401
|
+
let t = x(e.length) | 0, n = l(t);
|
|
402
|
+
return n.length === 0 || e.copy(n, 0, 0, t), n;
|
|
403
|
+
}
|
|
404
|
+
if (e.length !== void 0) return typeof e.length != "number" || de(e.length) ? l(0) : _(e);
|
|
405
|
+
if (e.type === "Buffer" && Array.isArray(e.data)) return _(e.data);
|
|
406
|
+
}
|
|
407
|
+
function x(e) {
|
|
408
|
+
if (e >= i) throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + i.toString(16) + " bytes");
|
|
409
|
+
return e | 0;
|
|
410
|
+
}
|
|
411
|
+
function S(e) {
|
|
412
|
+
return +e != e && (e = 0), u.alloc(+e);
|
|
413
|
+
}
|
|
414
|
+
u.isBuffer = function(e) {
|
|
415
|
+
return e != null && e._isBuffer === !0 && e !== u.prototype;
|
|
416
|
+
}, u.compare = function(e, t) {
|
|
417
|
+
if (Q(e, a) && (e = u.from(e, e.offset, e.byteLength)), Q(t, a) && (t = u.from(t, t.offset, t.byteLength)), !u.isBuffer(e) || !u.isBuffer(t)) throw TypeError("The \"buf1\", \"buf2\" arguments must be one of type Buffer or Uint8Array");
|
|
418
|
+
if (e === t) return 0;
|
|
419
|
+
let n = e.length, r = t.length;
|
|
420
|
+
for (let i = 0, a = Math.min(n, r); i < a; ++i) if (e[i] !== t[i]) {
|
|
421
|
+
n = e[i], r = t[i];
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
return n < r ? -1 : +(r < n);
|
|
425
|
+
}, u.isEncoding = function(e) {
|
|
426
|
+
switch (String(e).toLowerCase()) {
|
|
427
|
+
case "hex":
|
|
428
|
+
case "utf8":
|
|
429
|
+
case "utf-8":
|
|
430
|
+
case "ascii":
|
|
431
|
+
case "latin1":
|
|
432
|
+
case "binary":
|
|
433
|
+
case "base64":
|
|
434
|
+
case "ucs2":
|
|
435
|
+
case "ucs-2":
|
|
436
|
+
case "utf16le":
|
|
437
|
+
case "utf-16le": return !0;
|
|
438
|
+
default: return !1;
|
|
439
|
+
}
|
|
440
|
+
}, u.concat = function(e, t) {
|
|
441
|
+
if (!Array.isArray(e)) throw TypeError("\"list\" argument must be an Array of Buffers");
|
|
442
|
+
if (e.length === 0) return u.alloc(0);
|
|
443
|
+
let n;
|
|
444
|
+
if (t === void 0) for (t = 0, n = 0; n < e.length; ++n) t += e[n].length;
|
|
445
|
+
let r = u.allocUnsafe(t), i = 0;
|
|
446
|
+
for (n = 0; n < e.length; ++n) {
|
|
447
|
+
let t = e[n];
|
|
448
|
+
if (Q(t, a)) i + t.length > r.length ? (u.isBuffer(t) || (t = u.from(t)), t.copy(r, i)) : a.prototype.set.call(r, t, i);
|
|
449
|
+
else if (u.isBuffer(t)) t.copy(r, i);
|
|
450
|
+
else throw TypeError("\"list\" argument must be an Array of Buffers");
|
|
451
|
+
i += t.length;
|
|
452
|
+
}
|
|
453
|
+
return r;
|
|
454
|
+
};
|
|
455
|
+
function w(e, t) {
|
|
456
|
+
if (u.isBuffer(e)) return e.length;
|
|
457
|
+
if (o.isView(e) || Q(e, o)) return e.byteLength;
|
|
458
|
+
if (typeof e != "string") throw TypeError("The \"string\" argument must be one of type string, Buffer, or ArrayBuffer. Received type " + typeof e);
|
|
459
|
+
let n = e.length, r = arguments.length > 2 && arguments[2] === !0;
|
|
460
|
+
if (!r && n === 0) return 0;
|
|
461
|
+
let i = !1;
|
|
462
|
+
for (;;) switch (t) {
|
|
463
|
+
case "ascii":
|
|
464
|
+
case "latin1":
|
|
465
|
+
case "binary": return n;
|
|
466
|
+
case "utf8":
|
|
467
|
+
case "utf-8": return oe(e).length;
|
|
468
|
+
case "ucs2":
|
|
469
|
+
case "ucs-2":
|
|
470
|
+
case "utf16le":
|
|
471
|
+
case "utf-16le": return n * 2;
|
|
472
|
+
case "hex": return n >>> 1;
|
|
473
|
+
case "base64": return le(e).length;
|
|
474
|
+
default:
|
|
475
|
+
if (i) return r ? -1 : oe(e).length;
|
|
476
|
+
t = ("" + t).toLowerCase(), i = !0;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
u.byteLength = w;
|
|
480
|
+
function T(e, t, n) {
|
|
481
|
+
let r = !1;
|
|
482
|
+
if ((t === void 0 || t < 0) && (t = 0), t > this.length || ((n === void 0 || n > this.length) && (n = this.length), n <= 0) || (n >>>= 0, t >>>= 0, n <= t)) return "";
|
|
483
|
+
for (e ||= "utf8";;) switch (e) {
|
|
484
|
+
case "hex": return B(this, t, n);
|
|
485
|
+
case "utf8":
|
|
486
|
+
case "utf-8": return F(this, t, n);
|
|
487
|
+
case "ascii": return R(this, t, n);
|
|
488
|
+
case "latin1":
|
|
489
|
+
case "binary": return z(this, t, n);
|
|
490
|
+
case "base64": return P(this, t, n);
|
|
491
|
+
case "ucs2":
|
|
492
|
+
case "ucs-2":
|
|
493
|
+
case "utf16le":
|
|
494
|
+
case "utf-16le": return V(this, t, n);
|
|
495
|
+
default:
|
|
496
|
+
if (r) throw TypeError("Unknown encoding: " + e);
|
|
497
|
+
e = (e + "").toLowerCase(), r = !0;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
u.prototype._isBuffer = !0;
|
|
501
|
+
function E(e, t, n) {
|
|
502
|
+
let r = e[t];
|
|
503
|
+
e[t] = e[n], e[n] = r;
|
|
504
|
+
}
|
|
505
|
+
u.prototype.swap16 = function() {
|
|
506
|
+
let e = this.length;
|
|
507
|
+
if (e % 2 != 0) throw RangeError("Buffer size must be a multiple of 16-bits");
|
|
508
|
+
for (let t = 0; t < e; t += 2) E(this, t, t + 1);
|
|
509
|
+
return this;
|
|
510
|
+
}, u.prototype.swap32 = function() {
|
|
511
|
+
let e = this.length;
|
|
512
|
+
if (e % 4 != 0) throw RangeError("Buffer size must be a multiple of 32-bits");
|
|
513
|
+
for (let t = 0; t < e; t += 4) E(this, t, t + 3), E(this, t + 1, t + 2);
|
|
514
|
+
return this;
|
|
515
|
+
}, u.prototype.swap64 = function() {
|
|
516
|
+
let e = this.length;
|
|
517
|
+
if (e % 8 != 0) throw RangeError("Buffer size must be a multiple of 64-bits");
|
|
518
|
+
for (let t = 0; t < e; t += 8) E(this, t, t + 7), E(this, t + 1, t + 6), E(this, t + 2, t + 5), E(this, t + 3, t + 4);
|
|
519
|
+
return this;
|
|
520
|
+
}, u.prototype.toString = function() {
|
|
521
|
+
let e = this.length;
|
|
522
|
+
return e === 0 ? "" : arguments.length === 0 ? F(this, 0, e) : T.apply(this, arguments);
|
|
523
|
+
}, u.prototype.toLocaleString = u.prototype.toString, u.prototype.equals = function(e) {
|
|
524
|
+
if (!u.isBuffer(e)) throw TypeError("Argument must be a Buffer");
|
|
525
|
+
return this === e ? !0 : u.compare(this, e) === 0;
|
|
526
|
+
}, u.prototype.inspect = function() {
|
|
527
|
+
let t = "", n = e.INSPECT_MAX_BYTES;
|
|
528
|
+
return t = this.toString("hex", 0, n).replace(/(.{2})/g, "$1 ").trim(), this.length > n && (t += " ... "), "<Buffer " + t + ">";
|
|
529
|
+
}, r && (u.prototype[r] = u.prototype.inspect), u.prototype.compare = function(e, t, n, r, i) {
|
|
530
|
+
if (Q(e, a) && (e = u.from(e, e.offset, e.byteLength)), !u.isBuffer(e)) throw TypeError("The \"target\" argument must be one of type Buffer or Uint8Array. Received type " + typeof e);
|
|
531
|
+
if (t === void 0 && (t = 0), n === void 0 && (n = e ? e.length : 0), r === void 0 && (r = 0), i === void 0 && (i = this.length), t < 0 || n > e.length || r < 0 || i > this.length) throw RangeError("out of range index");
|
|
532
|
+
if (r >= i && t >= n) return 0;
|
|
533
|
+
if (r >= i) return -1;
|
|
534
|
+
if (t >= n) return 1;
|
|
535
|
+
if (t >>>= 0, n >>>= 0, r >>>= 0, i >>>= 0, this === e) return 0;
|
|
536
|
+
let o = i - r, s = n - t, c = Math.min(o, s), l = this.slice(r, i), d = e.slice(t, n);
|
|
537
|
+
for (let e = 0; e < c; ++e) if (l[e] !== d[e]) {
|
|
538
|
+
o = l[e], s = d[e];
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
return o < s ? -1 : +(s < o);
|
|
542
|
+
};
|
|
543
|
+
function D(e, t, n, r, i) {
|
|
544
|
+
if (e.length === 0) return -1;
|
|
545
|
+
if (typeof n == "string" ? (r = n, n = 0) : n > 2147483647 ? n = 2147483647 : n < -2147483648 && (n = -2147483648), n = +n, de(n) && (n = i ? 0 : e.length - 1), n < 0 && (n = e.length + n), n >= e.length) {
|
|
546
|
+
if (i) return -1;
|
|
547
|
+
n = e.length - 1;
|
|
548
|
+
} else if (n < 0) if (i) n = 0;
|
|
549
|
+
else return -1;
|
|
550
|
+
if (typeof t == "string" && (t = u.from(t, r)), u.isBuffer(t)) return t.length === 0 ? -1 : O(e, t, n, r, i);
|
|
551
|
+
if (typeof t == "number") return t &= 255, typeof a.prototype.indexOf == "function" ? i ? a.prototype.indexOf.call(e, t, n) : a.prototype.lastIndexOf.call(e, t, n) : O(e, [t], n, r, i);
|
|
552
|
+
throw TypeError("val must be string, number or Buffer");
|
|
553
|
+
}
|
|
554
|
+
function O(e, t, n, r, i) {
|
|
555
|
+
let a = 1, o = e.length, s = t.length;
|
|
556
|
+
if (r !== void 0 && (r = String(r).toLowerCase(), r === "ucs2" || r === "ucs-2" || r === "utf16le" || r === "utf-16le")) {
|
|
557
|
+
if (e.length < 2 || t.length < 2) return -1;
|
|
558
|
+
a = 2, o /= 2, s /= 2, n /= 2;
|
|
559
|
+
}
|
|
560
|
+
function c(e, t) {
|
|
561
|
+
return a === 1 ? e[t] : e.readUInt16BE(t * a);
|
|
562
|
+
}
|
|
563
|
+
let l;
|
|
564
|
+
if (i) {
|
|
565
|
+
let r = -1;
|
|
566
|
+
for (l = n; l < o; l++) if (c(e, l) === c(t, r === -1 ? 0 : l - r)) {
|
|
567
|
+
if (r === -1 && (r = l), l - r + 1 === s) return r * a;
|
|
568
|
+
} else r !== -1 && (l -= l - r), r = -1;
|
|
569
|
+
} else for (n + s > o && (n = o - s), l = n; l >= 0; l--) {
|
|
570
|
+
let n = !0;
|
|
571
|
+
for (let r = 0; r < s; r++) if (c(e, l + r) !== c(t, r)) {
|
|
572
|
+
n = !1;
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
if (n) return l;
|
|
576
|
+
}
|
|
577
|
+
return -1;
|
|
578
|
+
}
|
|
579
|
+
u.prototype.includes = function(e, t, n) {
|
|
580
|
+
return this.indexOf(e, t, n) !== -1;
|
|
581
|
+
}, u.prototype.indexOf = function(e, t, n) {
|
|
582
|
+
return D(this, e, t, n, !0);
|
|
583
|
+
}, u.prototype.lastIndexOf = function(e, t, n) {
|
|
584
|
+
return D(this, e, t, n, !1);
|
|
585
|
+
};
|
|
586
|
+
function k(e, t, n, r) {
|
|
587
|
+
n = Number(n) || 0;
|
|
588
|
+
let i = e.length - n;
|
|
589
|
+
r ? (r = Number(r), r > i && (r = i)) : r = i;
|
|
590
|
+
let a = t.length;
|
|
591
|
+
r > a / 2 && (r = a / 2);
|
|
592
|
+
let o;
|
|
593
|
+
for (o = 0; o < r; ++o) {
|
|
594
|
+
let r = parseInt(t.substr(o * 2, 2), 16);
|
|
595
|
+
if (de(r)) return o;
|
|
596
|
+
e[n + o] = r;
|
|
597
|
+
}
|
|
598
|
+
return o;
|
|
599
|
+
}
|
|
600
|
+
function A(e, t, n, r) {
|
|
601
|
+
return ue(oe(t, e.length - n), e, n, r);
|
|
602
|
+
}
|
|
603
|
+
function j(e, t, n, r) {
|
|
604
|
+
return ue(se(t), e, n, r);
|
|
605
|
+
}
|
|
606
|
+
function M(e, t, n, r) {
|
|
607
|
+
return ue(le(t), e, n, r);
|
|
608
|
+
}
|
|
609
|
+
function N(e, t, n, r) {
|
|
610
|
+
return ue(ce(t, e.length - n), e, n, r);
|
|
611
|
+
}
|
|
612
|
+
u.prototype.write = function(e, t, n, r) {
|
|
613
|
+
if (t === void 0) r = "utf8", n = this.length, t = 0;
|
|
614
|
+
else if (n === void 0 && typeof t == "string") r = t, n = this.length, t = 0;
|
|
615
|
+
else if (isFinite(t)) t >>>= 0, isFinite(n) ? (n >>>= 0, r === void 0 && (r = "utf8")) : (r = n, n = void 0);
|
|
616
|
+
else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
617
|
+
let i = this.length - t;
|
|
618
|
+
if ((n === void 0 || n > i) && (n = i), e.length > 0 && (n < 0 || t < 0) || t > this.length) throw RangeError("Attempt to write outside buffer bounds");
|
|
619
|
+
r ||= "utf8";
|
|
620
|
+
let a = !1;
|
|
621
|
+
for (;;) switch (r) {
|
|
622
|
+
case "hex": return k(this, e, t, n);
|
|
623
|
+
case "utf8":
|
|
624
|
+
case "utf-8": return A(this, e, t, n);
|
|
625
|
+
case "ascii":
|
|
626
|
+
case "latin1":
|
|
627
|
+
case "binary": return j(this, e, t, n);
|
|
628
|
+
case "base64": return M(this, e, t, n);
|
|
629
|
+
case "ucs2":
|
|
630
|
+
case "ucs-2":
|
|
631
|
+
case "utf16le":
|
|
632
|
+
case "utf-16le": return N(this, e, t, n);
|
|
633
|
+
default:
|
|
634
|
+
if (a) throw TypeError("Unknown encoding: " + r);
|
|
635
|
+
r = ("" + r).toLowerCase(), a = !0;
|
|
636
|
+
}
|
|
637
|
+
}, u.prototype.toJSON = function() {
|
|
638
|
+
return {
|
|
639
|
+
type: "Buffer",
|
|
640
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
641
|
+
};
|
|
642
|
+
};
|
|
643
|
+
function P(e, n, r) {
|
|
644
|
+
return n === 0 && r === e.length ? t.fromByteArray(e) : t.fromByteArray(e.slice(n, r));
|
|
645
|
+
}
|
|
646
|
+
function F(e, t, n) {
|
|
647
|
+
n = Math.min(e.length, n);
|
|
648
|
+
let r = [], i = t;
|
|
649
|
+
for (; i < n;) {
|
|
650
|
+
let t = e[i], a = null, o = t > 239 ? 4 : t > 223 ? 3 : t > 191 ? 2 : 1;
|
|
651
|
+
if (i + o <= n) {
|
|
652
|
+
let n, r, s, c;
|
|
653
|
+
switch (o) {
|
|
654
|
+
case 1:
|
|
655
|
+
t < 128 && (a = t);
|
|
656
|
+
break;
|
|
657
|
+
case 2:
|
|
658
|
+
n = e[i + 1], (n & 192) == 128 && (c = (t & 31) << 6 | n & 63, c > 127 && (a = c));
|
|
659
|
+
break;
|
|
660
|
+
case 3:
|
|
661
|
+
n = e[i + 1], r = e[i + 2], (n & 192) == 128 && (r & 192) == 128 && (c = (t & 15) << 12 | (n & 63) << 6 | r & 63, c > 2047 && (c < 55296 || c > 57343) && (a = c));
|
|
662
|
+
break;
|
|
663
|
+
case 4: n = e[i + 1], r = e[i + 2], s = e[i + 3], (n & 192) == 128 && (r & 192) == 128 && (s & 192) == 128 && (c = (t & 15) << 18 | (n & 63) << 12 | (r & 63) << 6 | s & 63, c > 65535 && c < 1114112 && (a = c));
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
a === null ? (a = 65533, o = 1) : a > 65535 && (a -= 65536, r.push(a >>> 10 & 1023 | 55296), a = 56320 | a & 1023), r.push(a), i += o;
|
|
667
|
+
}
|
|
668
|
+
return L(r);
|
|
669
|
+
}
|
|
670
|
+
let I = 4096;
|
|
671
|
+
function L(e) {
|
|
672
|
+
let t = e.length;
|
|
673
|
+
if (t <= I) return String.fromCharCode.apply(String, e);
|
|
674
|
+
let n = "", r = 0;
|
|
675
|
+
for (; r < t;) n += String.fromCharCode.apply(String, e.slice(r, r += I));
|
|
676
|
+
return n;
|
|
677
|
+
}
|
|
678
|
+
function R(e, t, n) {
|
|
679
|
+
let r = "";
|
|
680
|
+
n = Math.min(e.length, n);
|
|
681
|
+
for (let i = t; i < n; ++i) r += String.fromCharCode(e[i] & 127);
|
|
682
|
+
return r;
|
|
683
|
+
}
|
|
684
|
+
function z(e, t, n) {
|
|
685
|
+
let r = "";
|
|
686
|
+
n = Math.min(e.length, n);
|
|
687
|
+
for (let i = t; i < n; ++i) r += String.fromCharCode(e[i]);
|
|
688
|
+
return r;
|
|
689
|
+
}
|
|
690
|
+
function B(e, t, n) {
|
|
691
|
+
let r = e.length;
|
|
692
|
+
(!t || t < 0) && (t = 0), (!n || n < 0 || n > r) && (n = r);
|
|
693
|
+
let i = "";
|
|
694
|
+
for (let r = t; r < n; ++r) i += fe[e[r]];
|
|
695
|
+
return i;
|
|
696
|
+
}
|
|
697
|
+
function V(e, t, n) {
|
|
698
|
+
let r = e.slice(t, n), i = "";
|
|
699
|
+
for (let e = 0; e < r.length - 1; e += 2) i += String.fromCharCode(r[e] + r[e + 1] * 256);
|
|
700
|
+
return i;
|
|
701
|
+
}
|
|
702
|
+
u.prototype.slice = function(e, t) {
|
|
703
|
+
let n = this.length;
|
|
704
|
+
e = ~~e, t = t === void 0 ? n : ~~t, e < 0 ? (e += n, e < 0 && (e = 0)) : e > n && (e = n), t < 0 ? (t += n, t < 0 && (t = 0)) : t > n && (t = n), t < e && (t = e);
|
|
705
|
+
let r = this.subarray(e, t);
|
|
706
|
+
return Object.setPrototypeOf(r, u.prototype), r;
|
|
707
|
+
};
|
|
708
|
+
function H(e, t, n) {
|
|
709
|
+
if (e % 1 != 0 || e < 0) throw RangeError("offset is not uint");
|
|
710
|
+
if (e + t > n) throw RangeError("Trying to access beyond buffer length");
|
|
711
|
+
}
|
|
712
|
+
u.prototype.readUintLE = u.prototype.readUIntLE = function(e, t, n) {
|
|
713
|
+
e >>>= 0, t >>>= 0, n || H(e, t, this.length);
|
|
714
|
+
let r = this[e], i = 1, a = 0;
|
|
715
|
+
for (; ++a < t && (i *= 256);) r += this[e + a] * i;
|
|
716
|
+
return r;
|
|
717
|
+
}, u.prototype.readUintBE = u.prototype.readUIntBE = function(e, t, n) {
|
|
718
|
+
e >>>= 0, t >>>= 0, n || H(e, t, this.length);
|
|
719
|
+
let r = this[e + --t], i = 1;
|
|
720
|
+
for (; t > 0 && (i *= 256);) r += this[e + --t] * i;
|
|
721
|
+
return r;
|
|
722
|
+
}, u.prototype.readUint8 = u.prototype.readUInt8 = function(e, t) {
|
|
723
|
+
return e >>>= 0, t || H(e, 1, this.length), this[e];
|
|
724
|
+
}, u.prototype.readUint16LE = u.prototype.readUInt16LE = function(e, t) {
|
|
725
|
+
return e >>>= 0, t || H(e, 2, this.length), this[e] | this[e + 1] << 8;
|
|
726
|
+
}, u.prototype.readUint16BE = u.prototype.readUInt16BE = function(e, t) {
|
|
727
|
+
return e >>>= 0, t || H(e, 2, this.length), this[e] << 8 | this[e + 1];
|
|
728
|
+
}, u.prototype.readUint32LE = u.prototype.readUInt32LE = function(e, t) {
|
|
729
|
+
return e >>>= 0, t || H(e, 4, this.length), (this[e] | this[e + 1] << 8 | this[e + 2] << 16) + this[e + 3] * 16777216;
|
|
730
|
+
}, u.prototype.readUint32BE = u.prototype.readUInt32BE = function(e, t) {
|
|
731
|
+
return e >>>= 0, t || H(e, 4, this.length), this[e] * 16777216 + (this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3]);
|
|
732
|
+
}, u.prototype.readBigUInt64LE = $(function(e) {
|
|
733
|
+
e >>>= 0, X(e, "offset");
|
|
734
|
+
let t = this[e], n = this[e + 7];
|
|
735
|
+
(t === void 0 || n === void 0) && Z(e, this.length - 8);
|
|
736
|
+
let r = t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24, i = this[++e] + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + n * 2 ** 24;
|
|
737
|
+
return BigInt(r) + (BigInt(i) << BigInt(32));
|
|
738
|
+
}), u.prototype.readBigUInt64BE = $(function(e) {
|
|
739
|
+
e >>>= 0, X(e, "offset");
|
|
740
|
+
let t = this[e], n = this[e + 7];
|
|
741
|
+
(t === void 0 || n === void 0) && Z(e, this.length - 8);
|
|
742
|
+
let r = t * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e], i = this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + n;
|
|
743
|
+
return (BigInt(r) << BigInt(32)) + BigInt(i);
|
|
744
|
+
}), u.prototype.readIntLE = function(e, t, n) {
|
|
745
|
+
e >>>= 0, t >>>= 0, n || H(e, t, this.length);
|
|
746
|
+
let r = this[e], i = 1, a = 0;
|
|
747
|
+
for (; ++a < t && (i *= 256);) r += this[e + a] * i;
|
|
748
|
+
return i *= 128, r >= i && (r -= 2 ** (8 * t)), r;
|
|
749
|
+
}, u.prototype.readIntBE = function(e, t, n) {
|
|
750
|
+
e >>>= 0, t >>>= 0, n || H(e, t, this.length);
|
|
751
|
+
let r = t, i = 1, a = this[e + --r];
|
|
752
|
+
for (; r > 0 && (i *= 256);) a += this[e + --r] * i;
|
|
753
|
+
return i *= 128, a >= i && (a -= 2 ** (8 * t)), a;
|
|
754
|
+
}, u.prototype.readInt8 = function(e, t) {
|
|
755
|
+
return e >>>= 0, t || H(e, 1, this.length), this[e] & 128 ? (255 - this[e] + 1) * -1 : this[e];
|
|
756
|
+
}, u.prototype.readInt16LE = function(e, t) {
|
|
757
|
+
e >>>= 0, t || H(e, 2, this.length);
|
|
758
|
+
let n = this[e] | this[e + 1] << 8;
|
|
759
|
+
return n & 32768 ? n | 4294901760 : n;
|
|
760
|
+
}, u.prototype.readInt16BE = function(e, t) {
|
|
761
|
+
e >>>= 0, t || H(e, 2, this.length);
|
|
762
|
+
let n = this[e + 1] | this[e] << 8;
|
|
763
|
+
return n & 32768 ? n | 4294901760 : n;
|
|
764
|
+
}, u.prototype.readInt32LE = function(e, t) {
|
|
765
|
+
return e >>>= 0, t || H(e, 4, this.length), this[e] | this[e + 1] << 8 | this[e + 2] << 16 | this[e + 3] << 24;
|
|
766
|
+
}, u.prototype.readInt32BE = function(e, t) {
|
|
767
|
+
return e >>>= 0, t || H(e, 4, this.length), this[e] << 24 | this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3];
|
|
768
|
+
}, u.prototype.readBigInt64LE = $(function(e) {
|
|
769
|
+
e >>>= 0, X(e, "offset");
|
|
770
|
+
let t = this[e], n = this[e + 7];
|
|
771
|
+
(t === void 0 || n === void 0) && Z(e, this.length - 8);
|
|
772
|
+
let r = this[e + 4] + this[e + 5] * 2 ** 8 + this[e + 6] * 2 ** 16 + (n << 24);
|
|
773
|
+
return (BigInt(r) << BigInt(32)) + BigInt(t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24);
|
|
774
|
+
}), u.prototype.readBigInt64BE = $(function(e) {
|
|
775
|
+
e >>>= 0, X(e, "offset");
|
|
776
|
+
let t = this[e], n = this[e + 7];
|
|
777
|
+
(t === void 0 || n === void 0) && Z(e, this.length - 8);
|
|
778
|
+
let r = (t << 24) + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e];
|
|
779
|
+
return (BigInt(r) << BigInt(32)) + BigInt(this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + n);
|
|
780
|
+
}), u.prototype.readFloatLE = function(e, t) {
|
|
781
|
+
return e >>>= 0, t || H(e, 4, this.length), n.read(this, e, !0, 23, 4);
|
|
782
|
+
}, u.prototype.readFloatBE = function(e, t) {
|
|
783
|
+
return e >>>= 0, t || H(e, 4, this.length), n.read(this, e, !1, 23, 4);
|
|
784
|
+
}, u.prototype.readDoubleLE = function(e, t) {
|
|
785
|
+
return e >>>= 0, t || H(e, 8, this.length), n.read(this, e, !0, 52, 8);
|
|
786
|
+
}, u.prototype.readDoubleBE = function(e, t) {
|
|
787
|
+
return e >>>= 0, t || H(e, 8, this.length), n.read(this, e, !1, 52, 8);
|
|
788
|
+
};
|
|
789
|
+
function U(e, t, n, r, i, a) {
|
|
790
|
+
if (!u.isBuffer(e)) throw TypeError("\"buffer\" argument must be a Buffer instance");
|
|
791
|
+
if (t > i || t < a) throw RangeError("\"value\" argument is out of bounds");
|
|
792
|
+
if (n + r > e.length) throw RangeError("Index out of range");
|
|
793
|
+
}
|
|
794
|
+
u.prototype.writeUintLE = u.prototype.writeUIntLE = function(e, t, n, r) {
|
|
795
|
+
if (e = +e, t >>>= 0, n >>>= 0, !r) {
|
|
796
|
+
let r = 2 ** (8 * n) - 1;
|
|
797
|
+
U(this, e, t, n, r, 0);
|
|
798
|
+
}
|
|
799
|
+
let i = 1, a = 0;
|
|
800
|
+
for (this[t] = e & 255; ++a < n && (i *= 256);) this[t + a] = e / i & 255;
|
|
801
|
+
return t + n;
|
|
802
|
+
}, u.prototype.writeUintBE = u.prototype.writeUIntBE = function(e, t, n, r) {
|
|
803
|
+
if (e = +e, t >>>= 0, n >>>= 0, !r) {
|
|
804
|
+
let r = 2 ** (8 * n) - 1;
|
|
805
|
+
U(this, e, t, n, r, 0);
|
|
806
|
+
}
|
|
807
|
+
let i = n - 1, a = 1;
|
|
808
|
+
for (this[t + i] = e & 255; --i >= 0 && (a *= 256);) this[t + i] = e / a & 255;
|
|
809
|
+
return t + n;
|
|
810
|
+
}, u.prototype.writeUint8 = u.prototype.writeUInt8 = function(e, t, n) {
|
|
811
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 1, 255, 0), this[t] = e & 255, t + 1;
|
|
812
|
+
}, u.prototype.writeUint16LE = u.prototype.writeUInt16LE = function(e, t, n) {
|
|
813
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 2, 65535, 0), this[t] = e & 255, this[t + 1] = e >>> 8, t + 2;
|
|
814
|
+
}, u.prototype.writeUint16BE = u.prototype.writeUInt16BE = function(e, t, n) {
|
|
815
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 2, 65535, 0), this[t] = e >>> 8, this[t + 1] = e & 255, t + 2;
|
|
816
|
+
}, u.prototype.writeUint32LE = u.prototype.writeUInt32LE = function(e, t, n) {
|
|
817
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 4, 4294967295, 0), this[t + 3] = e >>> 24, this[t + 2] = e >>> 16, this[t + 1] = e >>> 8, this[t] = e & 255, t + 4;
|
|
818
|
+
}, u.prototype.writeUint32BE = u.prototype.writeUInt32BE = function(e, t, n) {
|
|
819
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 4, 4294967295, 0), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
|
|
820
|
+
};
|
|
821
|
+
function W(e, t, n, r, i) {
|
|
822
|
+
Y(t, r, i, e, n, 7);
|
|
823
|
+
let a = Number(t & BigInt(4294967295));
|
|
824
|
+
e[n++] = a, a >>= 8, e[n++] = a, a >>= 8, e[n++] = a, a >>= 8, e[n++] = a;
|
|
825
|
+
let o = Number(t >> BigInt(32) & BigInt(4294967295));
|
|
826
|
+
return e[n++] = o, o >>= 8, e[n++] = o, o >>= 8, e[n++] = o, o >>= 8, e[n++] = o, n;
|
|
827
|
+
}
|
|
828
|
+
function ee(e, t, n, r, i) {
|
|
829
|
+
Y(t, r, i, e, n, 7);
|
|
830
|
+
let a = Number(t & BigInt(4294967295));
|
|
831
|
+
e[n + 7] = a, a >>= 8, e[n + 6] = a, a >>= 8, e[n + 5] = a, a >>= 8, e[n + 4] = a;
|
|
832
|
+
let o = Number(t >> BigInt(32) & BigInt(4294967295));
|
|
833
|
+
return e[n + 3] = o, o >>= 8, e[n + 2] = o, o >>= 8, e[n + 1] = o, o >>= 8, e[n] = o, n + 8;
|
|
834
|
+
}
|
|
835
|
+
u.prototype.writeBigUInt64LE = $(function(e, t = 0) {
|
|
836
|
+
return W(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
837
|
+
}), u.prototype.writeBigUInt64BE = $(function(e, t = 0) {
|
|
838
|
+
return ee(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
839
|
+
}), u.prototype.writeIntLE = function(e, t, n, r) {
|
|
840
|
+
if (e = +e, t >>>= 0, !r) {
|
|
841
|
+
let r = 2 ** (8 * n - 1);
|
|
842
|
+
U(this, e, t, n, r - 1, -r);
|
|
843
|
+
}
|
|
844
|
+
let i = 0, a = 1, o = 0;
|
|
845
|
+
for (this[t] = e & 255; ++i < n && (a *= 256);) e < 0 && o === 0 && this[t + i - 1] !== 0 && (o = 1), this[t + i] = (e / a >> 0) - o & 255;
|
|
846
|
+
return t + n;
|
|
847
|
+
}, u.prototype.writeIntBE = function(e, t, n, r) {
|
|
848
|
+
if (e = +e, t >>>= 0, !r) {
|
|
849
|
+
let r = 2 ** (8 * n - 1);
|
|
850
|
+
U(this, e, t, n, r - 1, -r);
|
|
851
|
+
}
|
|
852
|
+
let i = n - 1, a = 1, o = 0;
|
|
853
|
+
for (this[t + i] = e & 255; --i >= 0 && (a *= 256);) e < 0 && o === 0 && this[t + i + 1] !== 0 && (o = 1), this[t + i] = (e / a >> 0) - o & 255;
|
|
854
|
+
return t + n;
|
|
855
|
+
}, u.prototype.writeInt8 = function(e, t, n) {
|
|
856
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 1, 127, -128), e < 0 && (e = 255 + e + 1), this[t] = e & 255, t + 1;
|
|
857
|
+
}, u.prototype.writeInt16LE = function(e, t, n) {
|
|
858
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 2, 32767, -32768), this[t] = e & 255, this[t + 1] = e >>> 8, t + 2;
|
|
859
|
+
}, u.prototype.writeInt16BE = function(e, t, n) {
|
|
860
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 2, 32767, -32768), this[t] = e >>> 8, this[t + 1] = e & 255, t + 2;
|
|
861
|
+
}, u.prototype.writeInt32LE = function(e, t, n) {
|
|
862
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 4, 2147483647, -2147483648), this[t] = e & 255, this[t + 1] = e >>> 8, this[t + 2] = e >>> 16, this[t + 3] = e >>> 24, t + 4;
|
|
863
|
+
}, u.prototype.writeInt32BE = function(e, t, n) {
|
|
864
|
+
return e = +e, t >>>= 0, n || U(this, e, t, 4, 2147483647, -2147483648), e < 0 && (e = 4294967295 + e + 1), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
|
|
865
|
+
}, u.prototype.writeBigInt64LE = $(function(e, t = 0) {
|
|
866
|
+
return W(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
867
|
+
}), u.prototype.writeBigInt64BE = $(function(e, t = 0) {
|
|
868
|
+
return ee(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
869
|
+
});
|
|
870
|
+
function G(e, t, n, r, i, a) {
|
|
871
|
+
if (n + r > e.length || n < 0) throw RangeError("Index out of range");
|
|
872
|
+
}
|
|
873
|
+
function te(e, t, r, i, a) {
|
|
874
|
+
return t = +t, r >>>= 0, a || G(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
|
|
875
|
+
}
|
|
876
|
+
u.prototype.writeFloatLE = function(e, t, n) {
|
|
877
|
+
return te(this, e, t, !0, n);
|
|
878
|
+
}, u.prototype.writeFloatBE = function(e, t, n) {
|
|
879
|
+
return te(this, e, t, !1, n);
|
|
880
|
+
};
|
|
881
|
+
function ne(e, t, r, i, a) {
|
|
882
|
+
return t = +t, r >>>= 0, a || G(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
|
|
883
|
+
}
|
|
884
|
+
u.prototype.writeDoubleLE = function(e, t, n) {
|
|
885
|
+
return ne(this, e, t, !0, n);
|
|
886
|
+
}, u.prototype.writeDoubleBE = function(e, t, n) {
|
|
887
|
+
return ne(this, e, t, !1, n);
|
|
888
|
+
}, u.prototype.copy = function(e, t, n, r) {
|
|
889
|
+
if (!u.isBuffer(e)) throw TypeError("argument should be a Buffer");
|
|
890
|
+
if (n ||= 0, !r && r !== 0 && (r = this.length), t >= e.length && (t = e.length), t ||= 0, r > 0 && r < n && (r = n), r === n || e.length === 0 || this.length === 0) return 0;
|
|
891
|
+
if (t < 0) throw RangeError("targetStart out of bounds");
|
|
892
|
+
if (n < 0 || n >= this.length) throw RangeError("Index out of range");
|
|
893
|
+
if (r < 0) throw RangeError("sourceEnd out of bounds");
|
|
894
|
+
r > this.length && (r = this.length), e.length - t < r - n && (r = e.length - t + n);
|
|
895
|
+
let i = r - n;
|
|
896
|
+
return this === e && typeof a.prototype.copyWithin == "function" ? this.copyWithin(t, n, r) : a.prototype.set.call(e, this.subarray(n, r), t), i;
|
|
897
|
+
}, u.prototype.fill = function(e, t, n, r) {
|
|
898
|
+
if (typeof e == "string") {
|
|
899
|
+
if (typeof t == "string" ? (r = t, t = 0, n = this.length) : typeof n == "string" && (r = n, n = this.length), r !== void 0 && typeof r != "string") throw TypeError("encoding must be a string");
|
|
900
|
+
if (typeof r == "string" && !u.isEncoding(r)) throw TypeError("Unknown encoding: " + r);
|
|
901
|
+
if (e.length === 1) {
|
|
902
|
+
let t = e.charCodeAt(0);
|
|
903
|
+
(r === "utf8" && t < 128 || r === "latin1") && (e = t);
|
|
904
|
+
}
|
|
905
|
+
} else typeof e == "number" ? e &= 255 : typeof e == "boolean" && (e = Number(e));
|
|
906
|
+
if (t < 0 || this.length < t || this.length < n) throw RangeError("Out of range index");
|
|
907
|
+
if (n <= t) return this;
|
|
908
|
+
t >>>= 0, n = n === void 0 ? this.length : n >>> 0, e ||= 0;
|
|
909
|
+
let i;
|
|
910
|
+
if (typeof e == "number") for (i = t; i < n; ++i) this[i] = e;
|
|
911
|
+
else {
|
|
912
|
+
let a = u.isBuffer(e) ? e : u.from(e, r), o = a.length;
|
|
913
|
+
if (o === 0) throw TypeError("The value \"" + e + "\" is invalid for argument \"value\"");
|
|
914
|
+
for (i = 0; i < n - t; ++i) this[i + t] = a[i % o];
|
|
915
|
+
}
|
|
916
|
+
return this;
|
|
917
|
+
};
|
|
918
|
+
let K = {};
|
|
919
|
+
function q(e, t, n) {
|
|
920
|
+
K[e] = class extends n {
|
|
921
|
+
constructor() {
|
|
922
|
+
super(), Object.defineProperty(this, "message", {
|
|
923
|
+
value: t.apply(this, arguments),
|
|
924
|
+
writable: !0,
|
|
925
|
+
configurable: !0
|
|
926
|
+
}), this.name = `${this.name} [${e}]`, this.stack, delete this.name;
|
|
927
|
+
}
|
|
928
|
+
get code() {
|
|
929
|
+
return e;
|
|
930
|
+
}
|
|
931
|
+
set code(e) {
|
|
932
|
+
Object.defineProperty(this, "code", {
|
|
933
|
+
configurable: !0,
|
|
934
|
+
enumerable: !0,
|
|
935
|
+
value: e,
|
|
936
|
+
writable: !0
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
toString() {
|
|
940
|
+
return `${this.name} [${e}]: ${this.message}`;
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
q("ERR_BUFFER_OUT_OF_BOUNDS", function(e) {
|
|
945
|
+
return e ? `${e} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
|
|
946
|
+
}, RangeError), q("ERR_INVALID_ARG_TYPE", function(e, t) {
|
|
947
|
+
return `The "${e}" argument must be of type number. Received type ${typeof t}`;
|
|
948
|
+
}, TypeError), q("ERR_OUT_OF_RANGE", function(e, t, n) {
|
|
949
|
+
let r = `The value of "${e}" is out of range.`, i = n;
|
|
950
|
+
return Number.isInteger(n) && Math.abs(n) > 2 ** 32 ? i = J(String(n)) : typeof n == "bigint" && (i = String(n), (n > BigInt(2) ** BigInt(32) || n < -(BigInt(2) ** BigInt(32))) && (i = J(i)), i += "n"), r += ` It must be ${t}. Received ${i}`, r;
|
|
951
|
+
}, RangeError);
|
|
952
|
+
function J(e) {
|
|
953
|
+
let t = "", n = e.length, r = +(e[0] === "-");
|
|
954
|
+
for (; n >= r + 4; n -= 3) t = `_${e.slice(n - 3, n)}${t}`;
|
|
955
|
+
return `${e.slice(0, n)}${t}`;
|
|
956
|
+
}
|
|
957
|
+
function re(e, t, n) {
|
|
958
|
+
X(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && Z(t, e.length - (n + 1));
|
|
959
|
+
}
|
|
960
|
+
function Y(e, t, n, r, i, a) {
|
|
961
|
+
if (e > n || e < t) {
|
|
962
|
+
let r = typeof t == "bigint" ? "n" : "", i;
|
|
963
|
+
throw i = a > 3 ? t === 0 || t === BigInt(0) ? `>= 0${r} and < 2${r} ** ${(a + 1) * 8}${r}` : `>= -(2${r} ** ${(a + 1) * 8 - 1}${r}) and < 2 ** ${(a + 1) * 8 - 1}${r}` : `>= ${t}${r} and <= ${n}${r}`, new K.ERR_OUT_OF_RANGE("value", i, e);
|
|
964
|
+
}
|
|
965
|
+
re(r, i, a);
|
|
966
|
+
}
|
|
967
|
+
function X(e, t) {
|
|
968
|
+
if (typeof e != "number") throw new K.ERR_INVALID_ARG_TYPE(t, "number", e);
|
|
969
|
+
}
|
|
970
|
+
function Z(e, t, n) {
|
|
971
|
+
throw Math.floor(e) === e ? t < 0 ? new K.ERR_BUFFER_OUT_OF_BOUNDS() : new K.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (X(e, n), new K.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
|
|
972
|
+
}
|
|
973
|
+
let ie = /[^+/0-9A-Za-z-_]/g;
|
|
974
|
+
function ae(e) {
|
|
975
|
+
if (e = e.split("=")[0], e = e.trim().replace(ie, ""), e.length < 2) return "";
|
|
976
|
+
for (; e.length % 4 != 0;) e += "=";
|
|
977
|
+
return e;
|
|
978
|
+
}
|
|
979
|
+
function oe(e, t) {
|
|
980
|
+
t ||= Infinity;
|
|
981
|
+
let n, r = e.length, i = null, a = [];
|
|
982
|
+
for (let o = 0; o < r; ++o) {
|
|
983
|
+
if (n = e.charCodeAt(o), n > 55295 && n < 57344) {
|
|
984
|
+
if (!i) {
|
|
985
|
+
if (n > 56319) {
|
|
986
|
+
(t -= 3) > -1 && a.push(239, 191, 189);
|
|
987
|
+
continue;
|
|
988
|
+
} else if (o + 1 === r) {
|
|
989
|
+
(t -= 3) > -1 && a.push(239, 191, 189);
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
i = n;
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (n < 56320) {
|
|
996
|
+
(t -= 3) > -1 && a.push(239, 191, 189), i = n;
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
n = (i - 55296 << 10 | n - 56320) + 65536;
|
|
1000
|
+
} else i && (t -= 3) > -1 && a.push(239, 191, 189);
|
|
1001
|
+
if (i = null, n < 128) {
|
|
1002
|
+
if (--t < 0) break;
|
|
1003
|
+
a.push(n);
|
|
1004
|
+
} else if (n < 2048) {
|
|
1005
|
+
if ((t -= 2) < 0) break;
|
|
1006
|
+
a.push(n >> 6 | 192, n & 63 | 128);
|
|
1007
|
+
} else if (n < 65536) {
|
|
1008
|
+
if ((t -= 3) < 0) break;
|
|
1009
|
+
a.push(n >> 12 | 224, n >> 6 & 63 | 128, n & 63 | 128);
|
|
1010
|
+
} else if (n < 1114112) {
|
|
1011
|
+
if ((t -= 4) < 0) break;
|
|
1012
|
+
a.push(n >> 18 | 240, n >> 12 & 63 | 128, n >> 6 & 63 | 128, n & 63 | 128);
|
|
1013
|
+
} else throw Error("Invalid code point");
|
|
1014
|
+
}
|
|
1015
|
+
return a;
|
|
1016
|
+
}
|
|
1017
|
+
function se(e) {
|
|
1018
|
+
let t = [];
|
|
1019
|
+
for (let n = 0; n < e.length; ++n) t.push(e.charCodeAt(n) & 255);
|
|
1020
|
+
return t;
|
|
1021
|
+
}
|
|
1022
|
+
function ce(e, t) {
|
|
1023
|
+
let n, r, i, a = [];
|
|
1024
|
+
for (let o = 0; o < e.length && !((t -= 2) < 0); ++o) n = e.charCodeAt(o), r = n >> 8, i = n % 256, a.push(i), a.push(r);
|
|
1025
|
+
return a;
|
|
1026
|
+
}
|
|
1027
|
+
function le(e) {
|
|
1028
|
+
return t.toByteArray(ae(e));
|
|
1029
|
+
}
|
|
1030
|
+
function ue(e, t, n, r) {
|
|
1031
|
+
let i;
|
|
1032
|
+
for (i = 0; i < r && !(i + n >= t.length || i >= e.length); ++i) t[i + n] = e[i];
|
|
1033
|
+
return i;
|
|
1034
|
+
}
|
|
1035
|
+
function Q(e, t) {
|
|
1036
|
+
return e instanceof t || e != null && e.constructor != null && e.constructor.name != null && e.constructor.name === t.name;
|
|
1037
|
+
}
|
|
1038
|
+
function de(e) {
|
|
1039
|
+
return e !== e;
|
|
1040
|
+
}
|
|
1041
|
+
let fe = (function() {
|
|
1042
|
+
let e = "0123456789abcdef", t = Array(256);
|
|
1043
|
+
for (let n = 0; n < 16; ++n) {
|
|
1044
|
+
let r = n * 16;
|
|
1045
|
+
for (let i = 0; i < 16; ++i) t[r + i] = e[n] + e[i];
|
|
1046
|
+
}
|
|
1047
|
+
return t;
|
|
1048
|
+
})();
|
|
1049
|
+
function $(e) {
|
|
1050
|
+
return typeof BigInt > "u" ? pe : e;
|
|
1051
|
+
}
|
|
1052
|
+
function pe() {
|
|
1053
|
+
throw Error("BigInt not supported");
|
|
1054
|
+
}
|
|
1055
|
+
})(h), w = h.Buffer, h.Blob, h.BlobOptions, h.Buffer, h.File, h.FileOptions, h.INSPECT_MAX_BYTES, h.SlowBuffer, h.TranscodeEncoding, h.atob, h.btoa, h.constants, h.isAscii, h.isUtf8, h.kMaxLength, h.kStringMaxLength, h.resolveObjectURL, h.transcode;
|
|
1056
|
+
})), E = /* @__PURE__ */ t(((e, t) => {
|
|
1057
|
+
var n = s();
|
|
1058
|
+
function r(e) {
|
|
1059
|
+
return /^#!\/(sh\.js|bin\/(sh|brsh))/.test(e);
|
|
1060
|
+
}
|
|
1061
|
+
t.exports = class extends n {
|
|
1062
|
+
constructor(e, t, n, r = !1) {
|
|
1063
|
+
super(t, n), this.script = e, this.source = r;
|
|
1064
|
+
}
|
|
1065
|
+
get captureInput() {
|
|
1066
|
+
return !!(this.sandbox && this.sandbox.runningCommand && this.sandbox.runningCommand.captureInput);
|
|
1067
|
+
}
|
|
1068
|
+
onInput(e) {
|
|
1069
|
+
this.sandbox && this.sandbox.onInput(e);
|
|
1070
|
+
}
|
|
1071
|
+
run() {
|
|
1072
|
+
let e = this.context.fs.isRealFilesystem ? { useRealFilesystem: !0 } : {
|
|
1073
|
+
filesystem: this.context.fs.getRaw(),
|
|
1074
|
+
permissions: this.context.fs.getRawPermissions()
|
|
1075
|
+
};
|
|
1076
|
+
this.sandbox = new globalThis.shell({
|
|
1077
|
+
cwd: this.context.fs.cwd,
|
|
1078
|
+
...e,
|
|
1079
|
+
subshell: !0
|
|
1080
|
+
}), this.sandbox.context.source(this.context), this.sandbox.on("stdOut", (e) => {
|
|
1081
|
+
this.stdOut = e, this.flush();
|
|
1082
|
+
}), this.sandbox.on("stdErr", (e) => {
|
|
1083
|
+
this.stdErr = e, this.flush();
|
|
1084
|
+
}), this._scriptFunctions = {};
|
|
1085
|
+
let t = this.script.split(/\r?\n/);
|
|
1086
|
+
if (!r(t[0])) {
|
|
1087
|
+
let e = t[0].startsWith("#!") ? t[0].slice(2).split(/\s/)[0] : t[0];
|
|
1088
|
+
return Promise.reject(`${e}: bad interpreter: No such file or directory`);
|
|
1089
|
+
}
|
|
1090
|
+
let n = this._parseLines(t.slice(1));
|
|
1091
|
+
return this._executeNodes(n).catch((e) => {
|
|
1092
|
+
if (e && e.__type === "return") this.sandbox.lastCode = e.code;
|
|
1093
|
+
else if (e && e.__type === "errexit") this.sandbox.lastCode = e.code;
|
|
1094
|
+
else if (e && (e.__type === "break" || e.__type === "continue")) this.stdErr = `${e.__type}: only meaningful in a for or while loop`, this.sandbox.lastCode = 1;
|
|
1095
|
+
else return Promise.reject(e);
|
|
1096
|
+
}).then(() => {
|
|
1097
|
+
this.exitCode = this.sandbox.lastCode, this.source && this.context.source(this.sandbox.context);
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
_parseLines(e) {
|
|
1101
|
+
let t = [], n = 0;
|
|
1102
|
+
for (; n < e.length;) {
|
|
1103
|
+
let r = e[n].trim();
|
|
1104
|
+
if (!r || r.startsWith("#")) {
|
|
1105
|
+
n++;
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
if (r.startsWith("if ") || r === "if") {
|
|
1109
|
+
let r = this._parseIf(e, n);
|
|
1110
|
+
t.push(r.node), n += r.consumed;
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
if (r.startsWith("while ")) {
|
|
1114
|
+
let r = this._parseWhile(e, n);
|
|
1115
|
+
t.push(r.node), n += r.consumed;
|
|
1116
|
+
continue;
|
|
1117
|
+
}
|
|
1118
|
+
if (r.startsWith("for ")) {
|
|
1119
|
+
let r = this._parseFor(e, n);
|
|
1120
|
+
t.push(r.node), n += r.consumed;
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
if (r.startsWith("case ") || r === "case") {
|
|
1124
|
+
let r = this._parseCase(e, n);
|
|
1125
|
+
t.push(r.node), n += r.consumed;
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
if (/^(?:function\s+[\w\d_]+|[\w\d_]+\s*\(\s*\))\s*(?:\{.*)?$/.test(r)) {
|
|
1129
|
+
let r = this._parseFunction(e, n);
|
|
1130
|
+
t.push(r.node), n += r.consumed;
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
t.push({
|
|
1134
|
+
type: "command",
|
|
1135
|
+
line: r
|
|
1136
|
+
}), n++;
|
|
1137
|
+
}
|
|
1138
|
+
return t;
|
|
1139
|
+
}
|
|
1140
|
+
_parseIf(e, t) {
|
|
1141
|
+
let n = (e) => e.replace(/^(?:if|elif)\s+/, "").replace(/\s*;\s*then\s*$/, "").replace(/\s+then\s*$/, "").trim(), r = [{
|
|
1142
|
+
condition: n(e[t].trim()),
|
|
1143
|
+
bodyLines: []
|
|
1144
|
+
}], i = [], a = r[0], o = !1, s = 1, c = t + 1;
|
|
1145
|
+
for (c < e.length && e[c].trim() === "then" && c++; c < e.length;) {
|
|
1146
|
+
let t = e[c].trim();
|
|
1147
|
+
if ((t.startsWith("if ") || t === "if") && s++, t === "fi" && (s--, s === 0)) {
|
|
1148
|
+
c++;
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
if (s === 1 && t.startsWith("elif ")) {
|
|
1152
|
+
let i = {
|
|
1153
|
+
condition: n(t),
|
|
1154
|
+
bodyLines: []
|
|
1155
|
+
};
|
|
1156
|
+
r.push(i), a = i, c++, c < e.length && e[c].trim() === "then" && c++;
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
1159
|
+
if (s === 1 && t === "else") {
|
|
1160
|
+
o = !0, c++;
|
|
1161
|
+
continue;
|
|
1162
|
+
}
|
|
1163
|
+
o ? i.push(e[c]) : a.bodyLines.push(e[c]), c++;
|
|
1164
|
+
}
|
|
1165
|
+
return {
|
|
1166
|
+
node: {
|
|
1167
|
+
type: "if",
|
|
1168
|
+
clauses: r,
|
|
1169
|
+
elseLines: i
|
|
1170
|
+
},
|
|
1171
|
+
consumed: c - t
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
_parseWhile(e, t) {
|
|
1175
|
+
let n = e[t].trim().replace(/^while\s+/, "").replace(/\s*;\s*do\s*$/, "").replace(/\s+do\s*$/, "").trim(), r = t + 1;
|
|
1176
|
+
r < e.length && e[r].trim() === "do" && r++;
|
|
1177
|
+
let i = [], a = 1;
|
|
1178
|
+
for (; r < e.length;) {
|
|
1179
|
+
let t = e[r].trim();
|
|
1180
|
+
if ((t.startsWith("while ") || t.startsWith("for ")) && a++, t === "done" && (a--, a === 0)) {
|
|
1181
|
+
r++;
|
|
1182
|
+
break;
|
|
1183
|
+
}
|
|
1184
|
+
i.push(e[r]), r++;
|
|
1185
|
+
}
|
|
1186
|
+
return {
|
|
1187
|
+
node: {
|
|
1188
|
+
type: "while",
|
|
1189
|
+
condition: n,
|
|
1190
|
+
bodyLines: i
|
|
1191
|
+
},
|
|
1192
|
+
consumed: r - t
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
_parseFor(e, t) {
|
|
1196
|
+
let n = e[t].trim().replace(/\s*;\s*do\s*$/, "").replace(/\s+do\s*$/, "").match(/^for\s+(\w+)\s+in\s+(.+)$/), r = n ? n[1] : "", i = n ? n[2].trim() : "", a = t + 1;
|
|
1197
|
+
a < e.length && e[a].trim() === "do" && a++;
|
|
1198
|
+
let o = [], s = 1;
|
|
1199
|
+
for (; a < e.length;) {
|
|
1200
|
+
let t = e[a].trim();
|
|
1201
|
+
if ((t.startsWith("while ") || t.startsWith("for ")) && s++, t === "done" && (s--, s === 0)) {
|
|
1202
|
+
a++;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
o.push(e[a]), a++;
|
|
1206
|
+
}
|
|
1207
|
+
return {
|
|
1208
|
+
node: {
|
|
1209
|
+
type: "for",
|
|
1210
|
+
variable: r,
|
|
1211
|
+
list: i,
|
|
1212
|
+
bodyLines: o
|
|
1213
|
+
},
|
|
1214
|
+
consumed: a - t
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
async _executeNodes(e) {
|
|
1218
|
+
for (let t of e) await this._executeNode(t);
|
|
1219
|
+
}
|
|
1220
|
+
_executeNode(e) {
|
|
1221
|
+
if (e.type === "function") {
|
|
1222
|
+
let t = e.name, n = e.bodyLines, r = this, i = s(), a = class extends i {
|
|
1223
|
+
static get name() {
|
|
1224
|
+
return t;
|
|
1225
|
+
}
|
|
1226
|
+
run() {
|
|
1227
|
+
let e = this.arguments.map((e, t) => ({
|
|
1228
|
+
key: String(t + 1),
|
|
1229
|
+
prev: r.sandbox.context.getVar(String(t + 1))
|
|
1230
|
+
}));
|
|
1231
|
+
this.arguments.forEach((e, t) => r.sandbox.context.setVar(String(t + 1), e));
|
|
1232
|
+
let t = () => e.forEach(({ key: e, prev: t }) => t ? r.sandbox.context.setVar(e, t) : r.sandbox.context.unsetVar(e));
|
|
1233
|
+
return r._executeFunctionBody(n).then(() => {
|
|
1234
|
+
t();
|
|
1235
|
+
}).catch((e) => {
|
|
1236
|
+
if (t(), e && e.__type === "return") {
|
|
1237
|
+
this.exitCode = e.code;
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
return Promise.reject(e);
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
return this.sandbox.context.setCommand(a), Promise.resolve();
|
|
1245
|
+
}
|
|
1246
|
+
if (e.type === "command") {
|
|
1247
|
+
if (/^return(\s+\d+)?\s*$/.test(e.line.trim())) {
|
|
1248
|
+
let t = e.line.trim().match(/^return\s+(\d+)/), n = t ? parseInt(t[1], 10) : 0;
|
|
1249
|
+
return Promise.reject({
|
|
1250
|
+
__type: "return",
|
|
1251
|
+
code: n
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
if (/^break(\s+\d+)?\s*$/.test(e.line.trim())) {
|
|
1255
|
+
let t = e.line.trim().match(/^break\s+(\d+)/), n = t ? parseInt(t[1], 10) : 1;
|
|
1256
|
+
return Promise.reject({
|
|
1257
|
+
__type: "break",
|
|
1258
|
+
count: n
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
if (/^continue(\s+\d+)?\s*$/.test(e.line.trim())) {
|
|
1262
|
+
let t = e.line.trim().match(/^continue\s+(\d+)/), n = t ? parseInt(t[1], 10) : 1;
|
|
1263
|
+
return Promise.reject({
|
|
1264
|
+
__type: "continue",
|
|
1265
|
+
count: n
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
return (this.sandbox.context.getVar("-") || "").includes("x") && (this.stdErr = `+ ${e.line.trim()}`, this.flush()), this.sandbox.onCommand(e.line, !1).then(() => {
|
|
1269
|
+
if ((this.sandbox.context.getVar("-") || "").includes("e") && this.sandbox.lastCode !== 0) return Promise.reject({
|
|
1270
|
+
__type: "errexit",
|
|
1271
|
+
code: this.sandbox.lastCode
|
|
1272
|
+
});
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
return e.type === "if" ? this._executeIf(e) : e.type === "while" ? this._executeWhile(e) : e.type === "for" ? this._executeFor(e) : e.type === "case" ? this._executeCase(e) : Promise.resolve();
|
|
1276
|
+
}
|
|
1277
|
+
async _executeIf(e) {
|
|
1278
|
+
for (let t of e.clauses) if (await this.sandbox.onCommand(t.condition, !1), this.sandbox.lastCode === 0) return this._executeNodes(this._parseLines(t.bodyLines));
|
|
1279
|
+
if (e.elseLines.length > 0) return this._executeNodes(this._parseLines(e.elseLines));
|
|
1280
|
+
}
|
|
1281
|
+
async _executeWhile(e) {
|
|
1282
|
+
for (; await this.sandbox.onCommand(e.condition, !1), this.sandbox.lastCode === 0;) try {
|
|
1283
|
+
await this._executeNodes(this._parseLines(e.bodyLines));
|
|
1284
|
+
} catch (e) {
|
|
1285
|
+
if (e && e.__type === "break") {
|
|
1286
|
+
if (e.count <= 1) break;
|
|
1287
|
+
throw {
|
|
1288
|
+
__type: "break",
|
|
1289
|
+
count: e.count - 1
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
if (e && e.__type === "continue") {
|
|
1293
|
+
if (e.count <= 1) continue;
|
|
1294
|
+
throw {
|
|
1295
|
+
__type: "continue",
|
|
1296
|
+
count: e.count - 1
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
throw e;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
async _executeFor(e) {
|
|
1303
|
+
let t = e.list.replace(/\${?([\w\d]+)}?/g, (e, t) => this.sandbox.context.getVar(t) || "").split(/\s+/).filter(Boolean);
|
|
1304
|
+
for (let n of t) {
|
|
1305
|
+
this.sandbox.context.setVar(e.variable, n);
|
|
1306
|
+
try {
|
|
1307
|
+
await this._executeNodes(this._parseLines(e.bodyLines));
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
if (e && e.__type === "break") {
|
|
1310
|
+
if (e.count <= 1) break;
|
|
1311
|
+
throw {
|
|
1312
|
+
__type: "break",
|
|
1313
|
+
count: e.count - 1
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
if (e && e.__type === "continue") {
|
|
1317
|
+
if (e.count <= 1) continue;
|
|
1318
|
+
throw {
|
|
1319
|
+
__type: "continue",
|
|
1320
|
+
count: e.count - 1
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
throw e;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
_parseFunction(e, t) {
|
|
1328
|
+
let n = e[t].trim(), r = n.match(/^function\s+([\w\d_]+)/) || n.match(/^([\w\d_]+)\s*\(/), i = r ? r[1] : "", a = t + 1;
|
|
1329
|
+
if (!n.includes("{")) {
|
|
1330
|
+
for (; a < e.length && !e[a].includes("{");) a++;
|
|
1331
|
+
a++;
|
|
1332
|
+
}
|
|
1333
|
+
let o = [], s = 1;
|
|
1334
|
+
for (; a < e.length;) {
|
|
1335
|
+
if (e[a].trim() === "}") {
|
|
1336
|
+
a++;
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
let t = (e[a].match(/\{/g) || []).length, n = (e[a].match(/\}/g) || []).length;
|
|
1340
|
+
if (s += t - n, s <= 0) {
|
|
1341
|
+
a++;
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
o.push(e[a]), a++;
|
|
1345
|
+
}
|
|
1346
|
+
return {
|
|
1347
|
+
node: {
|
|
1348
|
+
type: "function",
|
|
1349
|
+
name: i,
|
|
1350
|
+
bodyLines: o
|
|
1351
|
+
},
|
|
1352
|
+
consumed: a - t
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
_parseCase(e, t) {
|
|
1356
|
+
let n = e[t].trim().match(/^case\s+(.+?)\s+in\s*$/), r = n ? n[1] : "", i = t + 1, a = [], o = null, s = [];
|
|
1357
|
+
for (; i < e.length;) {
|
|
1358
|
+
let t = e[i], n = t.trim();
|
|
1359
|
+
if (i++, !(!n || n.startsWith("#"))) {
|
|
1360
|
+
if (n === "esac") break;
|
|
1361
|
+
if (o === null) {
|
|
1362
|
+
let e = n.match(/^(.+?)\)\s*(.*)$/);
|
|
1363
|
+
if (e) {
|
|
1364
|
+
o = e[1].trim();
|
|
1365
|
+
let t = e[2].trim();
|
|
1366
|
+
if (t === ";;") a.push({
|
|
1367
|
+
pattern: o,
|
|
1368
|
+
bodyLines: []
|
|
1369
|
+
}), o = null;
|
|
1370
|
+
else if (t.endsWith(";;")) {
|
|
1371
|
+
let e = t.slice(0, -2).trim();
|
|
1372
|
+
a.push({
|
|
1373
|
+
pattern: o,
|
|
1374
|
+
bodyLines: e ? [e] : []
|
|
1375
|
+
}), o = null;
|
|
1376
|
+
} else s = t ? [t] : [];
|
|
1377
|
+
}
|
|
1378
|
+
} else n === ";;" ? (a.push({
|
|
1379
|
+
pattern: o,
|
|
1380
|
+
bodyLines: s
|
|
1381
|
+
}), o = null, s = []) : n.endsWith(";;") ? (s.push(n.slice(0, -2).trim()), a.push({
|
|
1382
|
+
pattern: o,
|
|
1383
|
+
bodyLines: s
|
|
1384
|
+
}), o = null, s = []) : s.push(t);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return o !== null && a.push({
|
|
1388
|
+
pattern: o,
|
|
1389
|
+
bodyLines: s
|
|
1390
|
+
}), {
|
|
1391
|
+
node: {
|
|
1392
|
+
type: "case",
|
|
1393
|
+
word: r,
|
|
1394
|
+
clauses: a
|
|
1395
|
+
},
|
|
1396
|
+
consumed: i - t
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
_executeFunctionBody(e) {
|
|
1400
|
+
return this._executeNodes(this._parseLines(e));
|
|
1401
|
+
}
|
|
1402
|
+
async _executeCase(e) {
|
|
1403
|
+
let t = await this.sandbox._replaceVariables(e.word), n = t.startsWith("\"") && t.endsWith("\"") || t.startsWith("'") && t.endsWith("'") ? t.slice(1, -1) : t;
|
|
1404
|
+
for (let t of e.clauses) if (this._matchPattern(t.pattern, n)) return this._executeNodes(this._parseLines(t.bodyLines));
|
|
1405
|
+
}
|
|
1406
|
+
_matchPattern(e, t) {
|
|
1407
|
+
let n = "", r = 0;
|
|
1408
|
+
for (; r < e.length;) {
|
|
1409
|
+
let t = e[r];
|
|
1410
|
+
if (t === "[") {
|
|
1411
|
+
let t = e.indexOf("]", r + 1);
|
|
1412
|
+
t === -1 ? (n += "\\[", r++) : (n += e.slice(r, t + 1), r = t + 1);
|
|
1413
|
+
} else t === "*" ? (n += ".*", r++) : t === "?" ? (n += ".", r++) : /[.+^${}()|\\]/.test(t) ? (n += "\\" + t, r++) : (n += t, r++);
|
|
1414
|
+
}
|
|
1415
|
+
try {
|
|
1416
|
+
return RegExp("^" + n + "$").test(t);
|
|
1417
|
+
} catch {
|
|
1418
|
+
return !1;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}, t.exports.isKnownInterpreter = r;
|
|
1422
|
+
})), D = /* @__PURE__ */ t(((e, t) => {
|
|
1423
|
+
var n = new Set([
|
|
1424
|
+
"getFileByPath",
|
|
1425
|
+
"setFileByPath",
|
|
1426
|
+
"deleteFileByPath",
|
|
1427
|
+
"exists",
|
|
1428
|
+
"stat",
|
|
1429
|
+
"absolutePath",
|
|
1430
|
+
"getMode",
|
|
1431
|
+
"setMode",
|
|
1432
|
+
"isReadable",
|
|
1433
|
+
"isWritable",
|
|
1434
|
+
"isExecutable",
|
|
1435
|
+
"getSize",
|
|
1436
|
+
"autoComplete",
|
|
1437
|
+
"isRealFilesystem",
|
|
1438
|
+
"isSymlink",
|
|
1439
|
+
"readSymlink",
|
|
1440
|
+
"createSymlink"
|
|
1441
|
+
]);
|
|
1442
|
+
t.exports = class {
|
|
1443
|
+
isReadable(e) {
|
|
1444
|
+
let t = this.getMode(e);
|
|
1445
|
+
return t === null ? !1 : (t & 256) != 0;
|
|
1446
|
+
}
|
|
1447
|
+
isWritable(e) {
|
|
1448
|
+
let t = this.getMode(e);
|
|
1449
|
+
return t === null ? !1 : (t & 128) != 0;
|
|
1450
|
+
}
|
|
1451
|
+
isExecutable(e) {
|
|
1452
|
+
let t = this.getMode(e);
|
|
1453
|
+
return t === null ? !1 : (t & 64) != 0;
|
|
1454
|
+
}
|
|
1455
|
+
sandbox() {
|
|
1456
|
+
let e = this;
|
|
1457
|
+
return new Proxy(Object.create(null), {
|
|
1458
|
+
get(t, r) {
|
|
1459
|
+
if (!n.has(r)) return;
|
|
1460
|
+
let i = e[r];
|
|
1461
|
+
return typeof i == "function" ? i.bind(e) : i;
|
|
1462
|
+
},
|
|
1463
|
+
set() {
|
|
1464
|
+
return !1;
|
|
1465
|
+
},
|
|
1466
|
+
has(e, t) {
|
|
1467
|
+
return n.has(t);
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
_triggerChange() {
|
|
1472
|
+
!this._onChange || this._changeScheduled || (this._changeScheduled = !0, Promise.resolve().then(() => {
|
|
1473
|
+
this._changeScheduled = !1, typeof this._onChange == "function" && this._onChange(this.getRaw(), this.getRawPermissions());
|
|
1474
|
+
}));
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
}));
|
|
1478
|
+
//#endregion
|
|
1479
|
+
//#region node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js
|
|
1480
|
+
function O(e) {
|
|
1481
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
1482
|
+
}
|
|
1483
|
+
function k() {
|
|
1484
|
+
throw Error("setTimeout has not been defined");
|
|
1485
|
+
}
|
|
1486
|
+
function A() {
|
|
1487
|
+
throw Error("clearTimeout has not been defined");
|
|
1488
|
+
}
|
|
1489
|
+
function j(e) {
|
|
1490
|
+
if (z === setTimeout) return setTimeout(e, 0);
|
|
1491
|
+
if ((z === k || !z) && setTimeout) return z = setTimeout, setTimeout(e, 0);
|
|
1492
|
+
try {
|
|
1493
|
+
return z(e, 0);
|
|
1494
|
+
} catch {
|
|
1495
|
+
try {
|
|
1496
|
+
return z.call(null, e, 0);
|
|
1497
|
+
} catch {
|
|
1498
|
+
return z.call(this, e, 0);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
function M(e) {
|
|
1503
|
+
if (B === clearTimeout) return clearTimeout(e);
|
|
1504
|
+
if ((B === A || !B) && clearTimeout) return B = clearTimeout, clearTimeout(e);
|
|
1505
|
+
try {
|
|
1506
|
+
return B(e);
|
|
1507
|
+
} catch {
|
|
1508
|
+
try {
|
|
1509
|
+
return B.call(null, e);
|
|
1510
|
+
} catch {
|
|
1511
|
+
return B.call(this, e);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
function N() {
|
|
1516
|
+
!H || !U || (H = !1, U.length ? V = U.concat(V) : W = -1, V.length && P());
|
|
1517
|
+
}
|
|
1518
|
+
function P() {
|
|
1519
|
+
if (!H) {
|
|
1520
|
+
var e = j(N);
|
|
1521
|
+
H = !0;
|
|
1522
|
+
for (var t = V.length; t;) {
|
|
1523
|
+
for (U = V, V = []; ++W < t;) U && U[W].run();
|
|
1524
|
+
W = -1, t = V.length;
|
|
1525
|
+
}
|
|
1526
|
+
U = null, H = !1, M(e);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
function F(e, t) {
|
|
1530
|
+
this.fun = e, this.array = t;
|
|
1531
|
+
}
|
|
1532
|
+
function I() {}
|
|
1533
|
+
var L, R, z, B, V, H, U, W, ee, G, te = e((() => {
|
|
1534
|
+
L = { exports: {} }, R = L.exports = {}, (function() {
|
|
1535
|
+
try {
|
|
1536
|
+
z = typeof setTimeout == "function" ? setTimeout : k;
|
|
1537
|
+
} catch {
|
|
1538
|
+
z = k;
|
|
1539
|
+
}
|
|
1540
|
+
try {
|
|
1541
|
+
B = typeof clearTimeout == "function" ? clearTimeout : A;
|
|
1542
|
+
} catch {
|
|
1543
|
+
B = A;
|
|
1544
|
+
}
|
|
1545
|
+
})(), V = [], H = !1, W = -1, R.nextTick = function(e) {
|
|
1546
|
+
var t = Array(arguments.length - 1);
|
|
1547
|
+
if (arguments.length > 1) for (var n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
|
|
1548
|
+
V.push(new F(e, t)), V.length === 1 && !H && j(P);
|
|
1549
|
+
}, F.prototype.run = function() {
|
|
1550
|
+
this.fun.apply(null, this.array);
|
|
1551
|
+
}, R.title = "browser", R.browser = !0, R.env = {}, R.argv = [], R.version = "", R.versions = {}, R.on = I, R.addListener = I, R.once = I, R.off = I, R.removeListener = I, R.removeAllListeners = I, R.emit = I, R.prependListener = I, R.prependOnceListener = I, R.listeners = function(e) {
|
|
1552
|
+
return [];
|
|
1553
|
+
}, R.binding = function(e) {
|
|
1554
|
+
throw Error("process.binding is not supported");
|
|
1555
|
+
}, R.cwd = function() {
|
|
1556
|
+
return "/";
|
|
1557
|
+
}, R.chdir = function(e) {
|
|
1558
|
+
throw Error("process.chdir is not supported");
|
|
1559
|
+
}, R.umask = function() {
|
|
1560
|
+
return 0;
|
|
1561
|
+
}, ee = L.exports, G = /* @__PURE__ */ O(ee);
|
|
1562
|
+
})), ne = /* @__PURE__ */ t(((e, t) => {
|
|
1563
|
+
var n = o();
|
|
1564
|
+
t.exports = class extends n {
|
|
1565
|
+
get captureInput() {
|
|
1566
|
+
return !0;
|
|
1567
|
+
}
|
|
1568
|
+
get interactive() {
|
|
1569
|
+
return !0;
|
|
1570
|
+
}
|
|
1571
|
+
get terminalSize() {
|
|
1572
|
+
return {
|
|
1573
|
+
cols: parseInt(this.context.getVar("COLUMNS"), 10) || 80,
|
|
1574
|
+
rows: parseInt(this.context.getVar("LINES"), 10) || 24
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
})), K = /* @__PURE__ */ t(((e, t) => {
|
|
1579
|
+
T(), te();
|
|
1580
|
+
var { BinaryFile: n, SymlinkRef: r } = q(), i = new Uint8Array([
|
|
1581
|
+
66,
|
|
1582
|
+
82,
|
|
1583
|
+
70,
|
|
1584
|
+
83
|
|
1585
|
+
]), a = 2;
|
|
1586
|
+
function s(e) {
|
|
1587
|
+
if (!e) return !1;
|
|
1588
|
+
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength) : null;
|
|
1589
|
+
return !t || t.length < 12 ? !1 : t[0] === i[0] && t[1] === i[1] && t[2] === i[2] && t[3] === i[3];
|
|
1590
|
+
}
|
|
1591
|
+
function c(e = {}, t = {}, n = {}) {
|
|
1592
|
+
let o = new TextEncoder(), s = [], c = 0, l = (e) => {
|
|
1593
|
+
let t = e instanceof Uint8Array ? e : new Uint8Array(e), n = c;
|
|
1594
|
+
return s.push(t), c += t.byteLength, [n, t.byteLength];
|
|
1595
|
+
}, u = {}, d = (e, t) => {
|
|
1596
|
+
if (e == null) return null;
|
|
1597
|
+
if (e instanceof r) return { $l: e.target };
|
|
1598
|
+
if (e instanceof Uint8Array || w !== void 0 && w.isBuffer(e)) {
|
|
1599
|
+
let n = e instanceof Uint8Array ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : new Uint8Array(e), r = e.mimeType || (t.endsWith(".wasm") ? "application/wasm" : "application/octet-stream"), [i, a] = l(n);
|
|
1600
|
+
return { $b: [
|
|
1601
|
+
i,
|
|
1602
|
+
a,
|
|
1603
|
+
r
|
|
1604
|
+
] };
|
|
1605
|
+
}
|
|
1606
|
+
if (typeof e == "function") return n.commandsBundle || (u[t] = e.toString()), { $c: t };
|
|
1607
|
+
if (typeof e == "string") {
|
|
1608
|
+
if (e.startsWith("data:")) {
|
|
1609
|
+
let t = e.indexOf(";"), n = e.indexOf(",", t);
|
|
1610
|
+
if (t !== -1 && n !== -1 && e.slice(t + 1, n) === "base64") {
|
|
1611
|
+
let r = e.slice(5, t), i = e.slice(n + 1), a;
|
|
1612
|
+
if (w !== void 0) a = new Uint8Array(w.from(i, "base64"));
|
|
1613
|
+
else {
|
|
1614
|
+
let e = atob(i);
|
|
1615
|
+
a = new Uint8Array(e.length);
|
|
1616
|
+
for (let t = 0; t < e.length; t++) a[t] = e.charCodeAt(t);
|
|
1617
|
+
}
|
|
1618
|
+
let [o, s] = l(a);
|
|
1619
|
+
return { $b: [
|
|
1620
|
+
o,
|
|
1621
|
+
s,
|
|
1622
|
+
r
|
|
1623
|
+
] };
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
let [t, n] = l(o.encode(e));
|
|
1627
|
+
return { $t: [t, n] };
|
|
1628
|
+
}
|
|
1629
|
+
if (typeof e == "object") {
|
|
1630
|
+
let n = {};
|
|
1631
|
+
for (let r of Object.keys(e)) {
|
|
1632
|
+
let i = `${t}/${r}`, a = d(e[r], i);
|
|
1633
|
+
a !== null && (n[r] = a);
|
|
1634
|
+
}
|
|
1635
|
+
return { $d: n };
|
|
1636
|
+
}
|
|
1637
|
+
return null;
|
|
1638
|
+
}, f = d(e, "") || { $d: {} }, p = null;
|
|
1639
|
+
n.commandsBundle && typeof n.commandsBundle == "string" && (p = l(o.encode(n.commandsBundle)));
|
|
1640
|
+
let m = {
|
|
1641
|
+
v: a,
|
|
1642
|
+
tree: f,
|
|
1643
|
+
permissions: Object.assign({}, t)
|
|
1644
|
+
};
|
|
1645
|
+
p && (m.commandsSlice = p), Object.keys(u).length > 0 && (m.inlineCommands = u);
|
|
1646
|
+
let h = o.encode(JSON.stringify(m)), g = 12 + h.byteLength + c, _ = new Uint8Array(g);
|
|
1647
|
+
_.set(i, 0);
|
|
1648
|
+
let v = new DataView(_.buffer, _.byteOffset, _.byteLength);
|
|
1649
|
+
v.setUint32(4, a, !0), v.setUint32(8, h.byteLength, !0), _.set(h, 12);
|
|
1650
|
+
let y = 12 + h.byteLength;
|
|
1651
|
+
for (let e of s) _.set(e, y), y += e.byteLength;
|
|
1652
|
+
return _;
|
|
1653
|
+
}
|
|
1654
|
+
function l(e, t = {}) {
|
|
1655
|
+
let i = e instanceof Uint8Array ? e : new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength);
|
|
1656
|
+
if (!s(i)) throw Error("Invalid BRFS binary container (missing BRFS magic header)");
|
|
1657
|
+
let c = new DataView(i.buffer, i.byteOffset, i.byteLength), l = c.getUint32(4, !0);
|
|
1658
|
+
if (l > a) throw Error(`Unsupported BRFS container version: ${l}`);
|
|
1659
|
+
let u = 12 + c.getUint32(8, !0);
|
|
1660
|
+
if (u > i.byteLength) throw Error("Corrupt BRFS binary container (header length exceeds buffer)");
|
|
1661
|
+
let d = new TextDecoder(), f = d.decode(i.subarray(12, u)), p = JSON.parse(f), m = i.subarray(u), h = Object.assign({}, t);
|
|
1662
|
+
if (Array.isArray(p.commandsSlice)) {
|
|
1663
|
+
let [e, t] = p.commandsSlice, n = d.decode(m.subarray(e, e + t));
|
|
1664
|
+
try {
|
|
1665
|
+
let e = Function(n)();
|
|
1666
|
+
e && typeof e == "object" && Object.assign(h, e);
|
|
1667
|
+
} catch {}
|
|
1668
|
+
}
|
|
1669
|
+
let g = (e) => {
|
|
1670
|
+
if (!e || typeof e != "object") return e;
|
|
1671
|
+
if ("$t" in e) {
|
|
1672
|
+
let [t, n] = e.$t;
|
|
1673
|
+
return d.decode(m.subarray(t, t + n));
|
|
1674
|
+
}
|
|
1675
|
+
if ("$b" in e) {
|
|
1676
|
+
let [t, r, i] = e.$b;
|
|
1677
|
+
return new n(m.slice(t, t + r).buffer, i || "application/octet-stream");
|
|
1678
|
+
}
|
|
1679
|
+
if ("$l" in e) return new r(e.$l);
|
|
1680
|
+
if ("$c" in e) {
|
|
1681
|
+
let t = e.$c;
|
|
1682
|
+
if (h[t]) return h[t];
|
|
1683
|
+
if (p.inlineCommands && p.inlineCommands[t]) try {
|
|
1684
|
+
let e = o(), n = ne();
|
|
1685
|
+
return Function("Command", "InteractiveCommand", `return (${p.inlineCommands[t]});`)(e, n);
|
|
1686
|
+
} catch {
|
|
1687
|
+
return null;
|
|
1688
|
+
}
|
|
1689
|
+
return null;
|
|
1690
|
+
}
|
|
1691
|
+
if ("$d" in e) {
|
|
1692
|
+
let t = {};
|
|
1693
|
+
for (let [n, r] of Object.entries(e.$d)) {
|
|
1694
|
+
let e = g(r);
|
|
1695
|
+
e !== null && (t[n] = e);
|
|
1696
|
+
}
|
|
1697
|
+
return t;
|
|
1698
|
+
}
|
|
1699
|
+
return e;
|
|
1700
|
+
};
|
|
1701
|
+
return {
|
|
1702
|
+
filesystem: g(p.tree) || {},
|
|
1703
|
+
permissions: Object.assign({}, p.permissions || {})
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
function u(e) {
|
|
1707
|
+
if (!e) return !1;
|
|
1708
|
+
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : null;
|
|
1709
|
+
return !!(t && t.byteLength >= 2 && t[0] === 31 && t[1] === 139);
|
|
1710
|
+
}
|
|
1711
|
+
async function d(e) {
|
|
1712
|
+
if (typeof DecompressionStream < "u" && typeof Response < "u") {
|
|
1713
|
+
let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
|
|
1714
|
+
return new Uint8Array(r);
|
|
1715
|
+
}
|
|
1716
|
+
if (G !== void 0 && typeof G.getBuiltinModule == "function") {
|
|
1717
|
+
let t = G.getBuiltinModule("zlib");
|
|
1718
|
+
if (t) return new Uint8Array(t.gunzipSync(w.from(e.buffer, e.byteOffset, e.byteLength)));
|
|
1719
|
+
}
|
|
1720
|
+
throw Error("Gzip decompression is not supported in this environment");
|
|
1721
|
+
}
|
|
1722
|
+
function f(e) {
|
|
1723
|
+
return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" || u(e)) : !1;
|
|
1724
|
+
}
|
|
1725
|
+
async function p(e, t = {}) {
|
|
1726
|
+
if (!e) return {
|
|
1727
|
+
filesystem: {},
|
|
1728
|
+
permissions: t
|
|
1729
|
+
};
|
|
1730
|
+
if (typeof e.then == "function") return p(await e, t);
|
|
1731
|
+
if (typeof e.arrayBuffer == "function") {
|
|
1732
|
+
let n = await e.arrayBuffer();
|
|
1733
|
+
return p(new Uint8Array(n), t);
|
|
1734
|
+
}
|
|
1735
|
+
if (typeof e == "string") {
|
|
1736
|
+
if (!/^https?:\/\//i.test(e) && G !== void 0 && typeof G.getBuiltinModule == "function" && typeof window > "u") try {
|
|
1737
|
+
let n = G.getBuiltinModule("fs");
|
|
1738
|
+
if (n && n.existsSync(e)) {
|
|
1739
|
+
let r = await n.promises.readFile(e);
|
|
1740
|
+
return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
|
|
1741
|
+
}
|
|
1742
|
+
} catch {}
|
|
1743
|
+
let n = await fetch(e);
|
|
1744
|
+
if (!n.ok) throw Error(`Failed to load filesystem from ${e}: HTTP ${n.status}`);
|
|
1745
|
+
let r = await n.arrayBuffer();
|
|
1746
|
+
return p(new Uint8Array(r), t);
|
|
1747
|
+
}
|
|
1748
|
+
if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
|
|
1749
|
+
let n = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
1750
|
+
if (u(n) && (n = await d(n)), s(n)) {
|
|
1751
|
+
let e = l(n);
|
|
1752
|
+
return {
|
|
1753
|
+
filesystem: e.filesystem,
|
|
1754
|
+
permissions: Object.assign({}, e.permissions, t)
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
let r = new TextDecoder("utf-8").decode(n);
|
|
1758
|
+
try {
|
|
1759
|
+
let e = JSON.parse(r);
|
|
1760
|
+
return e && typeof e == "object" && e.filesystem && typeof e.permissions == "object" ? {
|
|
1761
|
+
filesystem: e.filesystem,
|
|
1762
|
+
permissions: Object.assign({}, e.permissions, t)
|
|
1763
|
+
} : {
|
|
1764
|
+
filesystem: e,
|
|
1765
|
+
permissions: t
|
|
1766
|
+
};
|
|
1767
|
+
} catch {
|
|
1768
|
+
let e = Function("return " + r)();
|
|
1769
|
+
return e && typeof e == "object" && e.filesystem && typeof e.permissions == "object" ? {
|
|
1770
|
+
filesystem: e.filesystem,
|
|
1771
|
+
permissions: Object.assign({}, e.permissions, t)
|
|
1772
|
+
} : {
|
|
1773
|
+
filesystem: e || {},
|
|
1774
|
+
permissions: t
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return typeof e == "object" && e.filesystem && typeof e.permissions == "object" ? f(e.filesystem) || s(e.filesystem) ? p(e.filesystem, Object.assign({}, e.permissions, t)) : {
|
|
1779
|
+
filesystem: e.filesystem,
|
|
1780
|
+
permissions: Object.assign({}, e.permissions, t)
|
|
1781
|
+
} : {
|
|
1782
|
+
filesystem: e,
|
|
1783
|
+
permissions: t
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
t.exports = {
|
|
1787
|
+
MAGIC: i,
|
|
1788
|
+
FORMAT_VERSION: a,
|
|
1789
|
+
isBinaryContainer: s,
|
|
1790
|
+
isGzipBytes: u,
|
|
1791
|
+
isAsyncFilesystemSource: f,
|
|
1792
|
+
resolveFilesystemSource: p,
|
|
1793
|
+
serializeBinaryFilesystem: c,
|
|
1794
|
+
deserializeBinaryFilesystem: l,
|
|
1795
|
+
FilesystemStorage: class {
|
|
1796
|
+
static async save(e, t = "brsh-rootfs") {
|
|
1797
|
+
let n = e.context ? e.context.fs : e, r = c(n.getRaw(), n.getRawPermissions());
|
|
1798
|
+
return typeof indexedDB < "u" && await this._idbPut(t, r), r;
|
|
1799
|
+
}
|
|
1800
|
+
static async load(e = "brsh-rootfs") {
|
|
1801
|
+
if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return p(e);
|
|
1802
|
+
if (typeof indexedDB < "u" && typeof e == "string") {
|
|
1803
|
+
let t = await this._idbGet(e);
|
|
1804
|
+
if (t && s(t)) return l(t);
|
|
1805
|
+
}
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
static async loadOrFetch(e = "brsh-rootfs", t = {}) {
|
|
1809
|
+
return await this.load(e) || p(t);
|
|
1810
|
+
}
|
|
1811
|
+
static createAutoSave(e = "brsh-rootfs", t = null) {
|
|
1812
|
+
return (n, r) => {
|
|
1813
|
+
let i = c(n, r);
|
|
1814
|
+
typeof indexedDB < "u" && this._idbPut(e, i).catch(() => {}), typeof t == "function" && t(i, n, r);
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
static _openIdb() {
|
|
1818
|
+
return new Promise((e, t) => {
|
|
1819
|
+
let n = indexedDB.open("brsh_fs_storage", 1);
|
|
1820
|
+
n.onupgradeneeded = () => {
|
|
1821
|
+
n.result.createObjectStore("snapshots");
|
|
1822
|
+
}, n.onsuccess = () => e(n.result), n.onerror = () => t(n.error);
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
static async _idbPut(e, t) {
|
|
1826
|
+
let n = await this._openIdb();
|
|
1827
|
+
return new Promise((r, i) => {
|
|
1828
|
+
let a = n.transaction("snapshots", "readwrite");
|
|
1829
|
+
a.objectStore("snapshots").put(t, e), a.oncomplete = () => {
|
|
1830
|
+
n.close(), r();
|
|
1831
|
+
}, a.onerror = () => {
|
|
1832
|
+
n.close(), i(a.error);
|
|
1833
|
+
};
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
static async _idbGet(e) {
|
|
1837
|
+
let t = await this._openIdb();
|
|
1838
|
+
return new Promise((n, r) => {
|
|
1839
|
+
let i = t.transaction("snapshots", "readonly").objectStore("snapshots").get(e);
|
|
1840
|
+
i.onsuccess = () => {
|
|
1841
|
+
t.close(), n(i.result || null);
|
|
1842
|
+
}, i.onerror = () => {
|
|
1843
|
+
t.close(), r(i.error);
|
|
1844
|
+
};
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
})), q = /* @__PURE__ */ t(((e, t) => {
|
|
1850
|
+
T();
|
|
1851
|
+
var n = D(), r = class extends Uint8Array {
|
|
1852
|
+
constructor(e, t) {
|
|
1853
|
+
super(e), Object.defineProperty(this, "mimeType", {
|
|
1854
|
+
value: t,
|
|
1855
|
+
enumerable: !1,
|
|
1856
|
+
configurable: !1,
|
|
1857
|
+
writable: !1
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
toString() {
|
|
1861
|
+
if (w !== void 0) return `data:${this.mimeType};base64,${w.from(this).toString("base64")}`;
|
|
1862
|
+
let e = "", t = 8192;
|
|
1863
|
+
for (let n = 0; n < this.length; n += t) e += String.fromCharCode(...this.subarray(n, n + t));
|
|
1864
|
+
return `data:${this.mimeType};base64,${btoa(e)}`;
|
|
1865
|
+
}
|
|
1866
|
+
}, i = class {
|
|
1867
|
+
constructor(e) {
|
|
1868
|
+
this.target = e;
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
function a(e) {
|
|
1872
|
+
for (let t of Object.keys(e)) {
|
|
1873
|
+
let n = e[t];
|
|
1874
|
+
if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i)) a(n);
|
|
1875
|
+
else if (typeof n == "string" && n.startsWith("data:")) {
|
|
1876
|
+
let i = n.indexOf(";"), a = n.indexOf(",", i);
|
|
1877
|
+
if (i !== -1 && a !== -1 && n.slice(i + 1, a) === "base64") {
|
|
1878
|
+
let o = n.slice(5, i), s = n.slice(a + 1), c;
|
|
1879
|
+
if (w !== void 0) c = new Uint8Array(w.from(s, "base64"));
|
|
1880
|
+
else {
|
|
1881
|
+
let e = atob(s);
|
|
1882
|
+
c = new Uint8Array(e.length);
|
|
1883
|
+
for (let t = 0; t < e.length; t++) c[t] = e.charCodeAt(t);
|
|
1884
|
+
}
|
|
1885
|
+
e[t] = new r(c.buffer, o);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
t.exports = class extends n {
|
|
1891
|
+
constructor(e = "/", t = {}, n = {}, r = null) {
|
|
1892
|
+
if (super(), t instanceof Uint8Array || t instanceof ArrayBuffer) {
|
|
1893
|
+
let { deserializeBinaryFilesystem: e } = K(), r = e(t);
|
|
1894
|
+
t = r.filesystem, n = Object.assign({}, r.permissions, n);
|
|
1895
|
+
} else if (t && typeof t == "object" && t.filesystem && (t.filesystem instanceof Uint8Array || typeof t.filesystem == "object") && (n = Object.assign({}, t.permissions || {}, n), t = t.filesystem, t instanceof Uint8Array || t instanceof ArrayBuffer)) {
|
|
1896
|
+
let { deserializeBinaryFilesystem: e } = K(), r = e(t);
|
|
1897
|
+
t = r.filesystem, n = Object.assign({}, r.permissions, n);
|
|
1898
|
+
}
|
|
1899
|
+
a(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e, this._onChange = r, this._changeScheduled = !1;
|
|
1900
|
+
}
|
|
1901
|
+
toBinaryContainer(e = {}) {
|
|
1902
|
+
let { serializeBinaryFilesystem: t } = K();
|
|
1903
|
+
return t(this.fileSystem, this.permissions, e);
|
|
1904
|
+
}
|
|
1905
|
+
static fromBinaryContainer(e, t = {}) {
|
|
1906
|
+
let { deserializeBinaryFilesystem: n } = K();
|
|
1907
|
+
return n(e, t);
|
|
1908
|
+
}
|
|
1909
|
+
getFileByPath(e) {
|
|
1910
|
+
let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !0);
|
|
1911
|
+
return t == null || !this.isReadable(e) ? null : t;
|
|
1912
|
+
}
|
|
1913
|
+
_getFileRaw(e) {
|
|
1914
|
+
return this._getFileByAbsolutePath(this._pathToAbsolute(e));
|
|
1915
|
+
}
|
|
1916
|
+
exists(e) {
|
|
1917
|
+
return this._resolveByAbsolutePath(this._pathToAbsolute(e), !0) != null;
|
|
1918
|
+
}
|
|
1919
|
+
isSymlink(e) {
|
|
1920
|
+
return this._resolveByAbsolutePath(this._pathToAbsolute(e), !1) instanceof i;
|
|
1921
|
+
}
|
|
1922
|
+
readSymlink(e) {
|
|
1923
|
+
let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !1);
|
|
1924
|
+
return t instanceof i ? t.target : null;
|
|
1925
|
+
}
|
|
1926
|
+
createSymlink(e, t) {
|
|
1927
|
+
this._setFileRaw(t, new i(e));
|
|
1928
|
+
}
|
|
1929
|
+
stat(e) {
|
|
1930
|
+
let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !1);
|
|
1931
|
+
return t == null ? null : t instanceof i ? {
|
|
1932
|
+
isDirectory: !1,
|
|
1933
|
+
isFile: !1,
|
|
1934
|
+
isCommand: !1,
|
|
1935
|
+
isBinary: !1,
|
|
1936
|
+
isSymlink: !0
|
|
1937
|
+
} : {
|
|
1938
|
+
isDirectory: t.constructor === Object,
|
|
1939
|
+
isFile: typeof t == "string" || t instanceof Uint8Array,
|
|
1940
|
+
isCommand: typeof t == "function",
|
|
1941
|
+
isBinary: t instanceof Uint8Array,
|
|
1942
|
+
isSymlink: !1
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
_pathToAbsolute(e) {
|
|
1946
|
+
return e.startsWith("./") && (e = e.substring(2)), e.startsWith("/") || (e = this.cwd + e), this._traverseComplexAbsolutePath(e);
|
|
1947
|
+
}
|
|
1948
|
+
_traverseComplexAbsolutePath(e) {
|
|
1949
|
+
let t = e.split("/");
|
|
1950
|
+
for (; t.includes("..");) {
|
|
1951
|
+
let e = t.indexOf("..") - 1;
|
|
1952
|
+
t.splice(e, 2);
|
|
1953
|
+
}
|
|
1954
|
+
return t.join("/");
|
|
1955
|
+
}
|
|
1956
|
+
absolutePath(e) {
|
|
1957
|
+
return this._pathToAbsolute(e);
|
|
1958
|
+
}
|
|
1959
|
+
setFileByPath(e, t, n = !1) {
|
|
1960
|
+
let r = this._pathToAbsolute(e);
|
|
1961
|
+
if (this._getFileByAbsolutePath(r) != null) {
|
|
1962
|
+
if (!this.isWritable(e)) throw Error("Permission denied");
|
|
1963
|
+
} else {
|
|
1964
|
+
let e = r.split("/");
|
|
1965
|
+
e.pop();
|
|
1966
|
+
let t = e.join("/") || "/", n = this.getMode(t);
|
|
1967
|
+
if (n !== null && !(n & 128)) throw Error("Permission denied");
|
|
1968
|
+
}
|
|
1969
|
+
this._setFileByAbsolutePath(r, t, n), this._triggerChange();
|
|
1970
|
+
}
|
|
1971
|
+
_setFileRaw(e, t, n = !1) {
|
|
1972
|
+
let r = this._pathToAbsolute(e);
|
|
1973
|
+
this._setFileByAbsolutePath(r, t, n), this._triggerChange();
|
|
1974
|
+
}
|
|
1975
|
+
_setFileByAbsolutePath(e, t, n = !0) {
|
|
1976
|
+
let r = e.split("/");
|
|
1977
|
+
r.shift();
|
|
1978
|
+
let a = r.pop(), o = this.fileSystem, s = [];
|
|
1979
|
+
for (let e of r) {
|
|
1980
|
+
if (s.push(e), !Object.prototype.hasOwnProperty.call(o, e)) {
|
|
1981
|
+
if (!n) throw Error(`${e}: No such file or directory`);
|
|
1982
|
+
o[e] = {};
|
|
1983
|
+
}
|
|
1984
|
+
let t = o[e];
|
|
1985
|
+
if (t instanceof i) {
|
|
1986
|
+
let n = "/" + s.slice(0, -1).join("/"), r = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(n + "/" + t.target);
|
|
1987
|
+
if (t = this._resolveByAbsolutePath(r, !0), typeof t != "object" || !t || t instanceof i) throw Error(`${e}: Not a directory`);
|
|
1988
|
+
}
|
|
1989
|
+
o = t;
|
|
1990
|
+
}
|
|
1991
|
+
o[a] = t;
|
|
1992
|
+
}
|
|
1993
|
+
_resolveByAbsolutePath(e, t = !0, n = 0) {
|
|
1994
|
+
if (n > 10) return null;
|
|
1995
|
+
let r = e.split("/");
|
|
1996
|
+
r.shift(), r.length > 0 && r[r.length - 1].length < 1 && r.pop();
|
|
1997
|
+
let a = this.fileSystem, o = [];
|
|
1998
|
+
for (let e = 0; e < r.length; e++) {
|
|
1999
|
+
let s = r[e], c = e === r.length - 1;
|
|
2000
|
+
if (typeof a != "object" || !a || a instanceof i || !Object.prototype.hasOwnProperty.call(a, s)) return null;
|
|
2001
|
+
if (a = a[s], o.push(s), a instanceof i && (!c || t)) {
|
|
2002
|
+
let e = "/" + o.slice(0, -1).join("/"), t = a.target.startsWith("/") ? this._traverseComplexAbsolutePath(a.target) : this._traverseComplexAbsolutePath(e + "/" + a.target);
|
|
2003
|
+
if (a = this._resolveByAbsolutePath(t, !0, n + 1), a == null) return null;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
return a;
|
|
2007
|
+
}
|
|
2008
|
+
_getFileByAbsolutePath(e) {
|
|
2009
|
+
let t = e.split("/");
|
|
2010
|
+
return t.shift(), t[t.length - 1].length < 1 && t.pop(), t.reduce((e, t) => typeof e != "object" || !e || !Object.prototype.hasOwnProperty.call(e, t) ? null : e[t], this.fileSystem);
|
|
2011
|
+
}
|
|
2012
|
+
deleteFileByPath(e) {
|
|
2013
|
+
let t = this._pathToAbsolute(e), n = t.split("/");
|
|
2014
|
+
n.pop();
|
|
2015
|
+
let r = n.join("/") || "/", i = this.getMode(r);
|
|
2016
|
+
if (i !== null && !(i & 128)) throw Error(`${e}: Permission denied`);
|
|
2017
|
+
this._deleteByAbsolutePath(t);
|
|
2018
|
+
let a = t + "/";
|
|
2019
|
+
Object.keys(this.permissions).forEach((e) => {
|
|
2020
|
+
(e === t || e.startsWith(a)) && delete this.permissions[e];
|
|
2021
|
+
}), this._triggerChange();
|
|
2022
|
+
}
|
|
2023
|
+
_deleteByAbsolutePath(e) {
|
|
2024
|
+
let t = e.split("/");
|
|
2025
|
+
t.shift(), t[t.length - 1] === "" && t.pop();
|
|
2026
|
+
let n = t.pop();
|
|
2027
|
+
if (!n) return;
|
|
2028
|
+
let r = this.fileSystem, a = [];
|
|
2029
|
+
for (let e of t) {
|
|
2030
|
+
if (a.push(e), !Object.prototype.hasOwnProperty.call(r, e)) return;
|
|
2031
|
+
let t = r[e];
|
|
2032
|
+
if (t instanceof i) {
|
|
2033
|
+
let e = "/" + a.slice(0, -1).join("/"), n = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(e + "/" + t.target);
|
|
2034
|
+
if (t = this._resolveByAbsolutePath(n, !0), typeof t != "object" || !t || t instanceof i) return;
|
|
2035
|
+
}
|
|
2036
|
+
r = t;
|
|
2037
|
+
}
|
|
2038
|
+
r && n in r && delete r[n];
|
|
2039
|
+
}
|
|
2040
|
+
getMode(e) {
|
|
2041
|
+
let t = this._pathToAbsolute(e);
|
|
2042
|
+
if (this.permissions[t] !== void 0) return this.permissions[t];
|
|
2043
|
+
let n = this._resolveByAbsolutePath(t, !0);
|
|
2044
|
+
return n == null ? null : n.constructor === Object ? 493 : typeof n == "function" ? 365 : 420;
|
|
2045
|
+
}
|
|
2046
|
+
setMode(e, t) {
|
|
2047
|
+
let n = this._pathToAbsolute(e);
|
|
2048
|
+
this.permissions[n] = t, this._triggerChange();
|
|
2049
|
+
}
|
|
2050
|
+
getSize(e) {
|
|
2051
|
+
let t = this._pathToAbsolute(e), n = this._resolveByAbsolutePath(t, !0);
|
|
2052
|
+
return n == null ? 0 : n.constructor === Object ? JSON.stringify(n).length : n instanceof Uint8Array ? n.length : n.toString().length;
|
|
2053
|
+
}
|
|
2054
|
+
getRawPermissions() {
|
|
2055
|
+
return Object.assign({}, this.permissions);
|
|
2056
|
+
}
|
|
2057
|
+
setCwd(e) {
|
|
2058
|
+
this.cwd = this._pathToAbsolute(e.endsWith("/") ? e : e + "/");
|
|
2059
|
+
}
|
|
2060
|
+
getRaw() {
|
|
2061
|
+
return this.fileSystem;
|
|
2062
|
+
}
|
|
2063
|
+
addFiles(e) {
|
|
2064
|
+
Object.entries(e).forEach(([e, t]) => {
|
|
2065
|
+
this._setFileRaw(e, t, !0);
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
autoComplete(e, t) {
|
|
2069
|
+
let n = this._pathToAbsolute(e).split("/"), r = n.pop(), i = this._getFileRaw(n.length > 1 ? n.join("/") : "/"), a = this._getFileRaw(t);
|
|
2070
|
+
if (i && i.constructor === Object) {
|
|
2071
|
+
let t = Object.keys(i).filter((e) => e.startsWith(r));
|
|
2072
|
+
r.length < 1 && (t = t.filter((e) => !e.startsWith(".")));
|
|
2073
|
+
let n = e.split("/");
|
|
2074
|
+
n.pop();
|
|
2075
|
+
let o = i;
|
|
2076
|
+
if (t.length < 1 && n.length < 1 && a && (t = Object.keys(a).filter((e) => e.startsWith(r)), o = a), t.length) return {
|
|
2077
|
+
path: n.length ? n.join("/") : null,
|
|
2078
|
+
options: t.map((e) => o[e] && o[e].constructor === Object ? e.concat("/") : e)
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
return null;
|
|
2082
|
+
}
|
|
2083
|
+
}, t.exports.BinaryFile = r, t.exports.SymlinkRef = i;
|
|
2084
|
+
})), J = /* @__PURE__ */ t(((e, t) => {
|
|
2085
|
+
t.exports = null;
|
|
2086
|
+
})), re = /* @__PURE__ */ t(((e, t) => {
|
|
2087
|
+
te();
|
|
2088
|
+
function n(e) {
|
|
2089
|
+
if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
|
|
2090
|
+
}
|
|
2091
|
+
function r(e, t) {
|
|
2092
|
+
for (var n = "", r = 0, i = -1, a = 0, o, s = 0; s <= e.length; ++s) {
|
|
2093
|
+
if (s < e.length) o = e.charCodeAt(s);
|
|
2094
|
+
else if (o === 47) break;
|
|
2095
|
+
else o = 47;
|
|
2096
|
+
if (o === 47) {
|
|
2097
|
+
if (!(i === s - 1 || a === 1)) if (i !== s - 1 && a === 2) {
|
|
2098
|
+
if (n.length < 2 || r !== 2 || n.charCodeAt(n.length - 1) !== 46 || n.charCodeAt(n.length - 2) !== 46) {
|
|
2099
|
+
if (n.length > 2) {
|
|
2100
|
+
var c = n.lastIndexOf("/");
|
|
2101
|
+
if (c !== n.length - 1) {
|
|
2102
|
+
c === -1 ? (n = "", r = 0) : (n = n.slice(0, c), r = n.length - 1 - n.lastIndexOf("/")), i = s, a = 0;
|
|
2103
|
+
continue;
|
|
2104
|
+
}
|
|
2105
|
+
} else if (n.length === 2 || n.length === 1) {
|
|
2106
|
+
n = "", r = 0, i = s, a = 0;
|
|
2107
|
+
continue;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
t && (n.length > 0 ? n += "/.." : n = "..", r = 2);
|
|
2111
|
+
} else n.length > 0 ? n += "/" + e.slice(i + 1, s) : n = e.slice(i + 1, s), r = s - i - 1;
|
|
2112
|
+
i = s, a = 0;
|
|
2113
|
+
} else o === 46 && a !== -1 ? ++a : a = -1;
|
|
2114
|
+
}
|
|
2115
|
+
return n;
|
|
2116
|
+
}
|
|
2117
|
+
function i(e, t) {
|
|
2118
|
+
var n = t.dir || t.root, r = t.base || (t.name || "") + (t.ext || "");
|
|
2119
|
+
return n ? n === t.root ? n + r : n + e + r : r;
|
|
2120
|
+
}
|
|
2121
|
+
var a = {
|
|
2122
|
+
resolve: function() {
|
|
2123
|
+
for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
|
|
2124
|
+
var o;
|
|
2125
|
+
a >= 0 ? o = arguments[a] : (i === void 0 && (i = G.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
|
|
2126
|
+
}
|
|
2127
|
+
return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
|
|
2128
|
+
},
|
|
2129
|
+
normalize: function(e) {
|
|
2130
|
+
if (n(e), e.length === 0) return ".";
|
|
2131
|
+
var t = e.charCodeAt(0) === 47, i = e.charCodeAt(e.length - 1) === 47;
|
|
2132
|
+
return e = r(e, !t), e.length === 0 && !t && (e = "."), e.length > 0 && i && (e += "/"), t ? "/" + e : e;
|
|
2133
|
+
},
|
|
2134
|
+
isAbsolute: function(e) {
|
|
2135
|
+
return n(e), e.length > 0 && e.charCodeAt(0) === 47;
|
|
2136
|
+
},
|
|
2137
|
+
join: function() {
|
|
2138
|
+
if (arguments.length === 0) return ".";
|
|
2139
|
+
for (var e, t = 0; t < arguments.length; ++t) {
|
|
2140
|
+
var r = arguments[t];
|
|
2141
|
+
n(r), r.length > 0 && (e === void 0 ? e = r : e += "/" + r);
|
|
2142
|
+
}
|
|
2143
|
+
return e === void 0 ? "." : a.normalize(e);
|
|
2144
|
+
},
|
|
2145
|
+
relative: function(e, t) {
|
|
2146
|
+
if (n(e), n(t), e === t || (e = a.resolve(e), t = a.resolve(t), e === t)) return "";
|
|
2147
|
+
for (var r = 1; r < e.length && e.charCodeAt(r) === 47; ++r);
|
|
2148
|
+
for (var i = e.length, o = i - r, s = 1; s < t.length && t.charCodeAt(s) === 47; ++s);
|
|
2149
|
+
for (var c = t.length - s, l = o < c ? o : c, u = -1, d = 0; d <= l; ++d) {
|
|
2150
|
+
if (d === l) {
|
|
2151
|
+
if (c > l) {
|
|
2152
|
+
if (t.charCodeAt(s + d) === 47) return t.slice(s + d + 1);
|
|
2153
|
+
if (d === 0) return t.slice(s + d);
|
|
2154
|
+
} else o > l && (e.charCodeAt(r + d) === 47 ? u = d : d === 0 && (u = 0));
|
|
2155
|
+
break;
|
|
2156
|
+
}
|
|
2157
|
+
var f = e.charCodeAt(r + d);
|
|
2158
|
+
if (f !== t.charCodeAt(s + d)) break;
|
|
2159
|
+
f === 47 && (u = d);
|
|
2160
|
+
}
|
|
2161
|
+
var p = "";
|
|
2162
|
+
for (d = r + u + 1; d <= i; ++d) (d === i || e.charCodeAt(d) === 47) && (p.length === 0 ? p += ".." : p += "/..");
|
|
2163
|
+
return p.length > 0 ? p + t.slice(s + u) : (s += u, t.charCodeAt(s) === 47 && ++s, t.slice(s));
|
|
2164
|
+
},
|
|
2165
|
+
_makeLong: function(e) {
|
|
2166
|
+
return e;
|
|
2167
|
+
},
|
|
2168
|
+
dirname: function(e) {
|
|
2169
|
+
if (n(e), e.length === 0) return ".";
|
|
2170
|
+
for (var t = e.charCodeAt(0), r = t === 47, i = -1, a = !0, o = e.length - 1; o >= 1; --o) if (t = e.charCodeAt(o), t === 47) {
|
|
2171
|
+
if (!a) {
|
|
2172
|
+
i = o;
|
|
2173
|
+
break;
|
|
2174
|
+
}
|
|
2175
|
+
} else a = !1;
|
|
2176
|
+
return i === -1 ? r ? "/" : "." : r && i === 1 ? "//" : e.slice(0, i);
|
|
2177
|
+
},
|
|
2178
|
+
basename: function(e, t) {
|
|
2179
|
+
if (t !== void 0 && typeof t != "string") throw TypeError("\"ext\" argument must be a string");
|
|
2180
|
+
n(e);
|
|
2181
|
+
var r = 0, i = -1, a = !0, o;
|
|
2182
|
+
if (t !== void 0 && t.length > 0 && t.length <= e.length) {
|
|
2183
|
+
if (t.length === e.length && t === e) return "";
|
|
2184
|
+
var s = t.length - 1, c = -1;
|
|
2185
|
+
for (o = e.length - 1; o >= 0; --o) {
|
|
2186
|
+
var l = e.charCodeAt(o);
|
|
2187
|
+
if (l === 47) {
|
|
2188
|
+
if (!a) {
|
|
2189
|
+
r = o + 1;
|
|
2190
|
+
break;
|
|
2191
|
+
}
|
|
2192
|
+
} else c === -1 && (a = !1, c = o + 1), s >= 0 && (l === t.charCodeAt(s) ? --s === -1 && (i = o) : (s = -1, i = c));
|
|
2193
|
+
}
|
|
2194
|
+
return r === i ? i = c : i === -1 && (i = e.length), e.slice(r, i);
|
|
2195
|
+
} else {
|
|
2196
|
+
for (o = e.length - 1; o >= 0; --o) if (e.charCodeAt(o) === 47) {
|
|
2197
|
+
if (!a) {
|
|
2198
|
+
r = o + 1;
|
|
2199
|
+
break;
|
|
2200
|
+
}
|
|
2201
|
+
} else i === -1 && (a = !1, i = o + 1);
|
|
2202
|
+
return i === -1 ? "" : e.slice(r, i);
|
|
2203
|
+
}
|
|
2204
|
+
},
|
|
2205
|
+
extname: function(e) {
|
|
2206
|
+
n(e);
|
|
2207
|
+
for (var t = -1, r = 0, i = -1, a = !0, o = 0, s = e.length - 1; s >= 0; --s) {
|
|
2208
|
+
var c = e.charCodeAt(s);
|
|
2209
|
+
if (c === 47) {
|
|
2210
|
+
if (!a) {
|
|
2211
|
+
r = s + 1;
|
|
2212
|
+
break;
|
|
2213
|
+
}
|
|
2214
|
+
continue;
|
|
2215
|
+
}
|
|
2216
|
+
i === -1 && (a = !1, i = s + 1), c === 46 ? t === -1 ? t = s : o !== 1 && (o = 1) : t !== -1 && (o = -1);
|
|
2217
|
+
}
|
|
2218
|
+
return t === -1 || i === -1 || o === 0 || o === 1 && t === i - 1 && t === r + 1 ? "" : e.slice(t, i);
|
|
2219
|
+
},
|
|
2220
|
+
format: function(e) {
|
|
2221
|
+
if (typeof e != "object" || !e) throw TypeError("The \"pathObject\" argument must be of type Object. Received type " + typeof e);
|
|
2222
|
+
return i("/", e);
|
|
2223
|
+
},
|
|
2224
|
+
parse: function(e) {
|
|
2225
|
+
n(e);
|
|
2226
|
+
var t = {
|
|
2227
|
+
root: "",
|
|
2228
|
+
dir: "",
|
|
2229
|
+
base: "",
|
|
2230
|
+
ext: "",
|
|
2231
|
+
name: ""
|
|
2232
|
+
};
|
|
2233
|
+
if (e.length === 0) return t;
|
|
2234
|
+
var r = e.charCodeAt(0), i = r === 47, a;
|
|
2235
|
+
i ? (t.root = "/", a = 1) : a = 0;
|
|
2236
|
+
for (var o = -1, s = 0, c = -1, l = !0, u = e.length - 1, d = 0; u >= a; --u) {
|
|
2237
|
+
if (r = e.charCodeAt(u), r === 47) {
|
|
2238
|
+
if (!l) {
|
|
2239
|
+
s = u + 1;
|
|
2240
|
+
break;
|
|
2241
|
+
}
|
|
2242
|
+
continue;
|
|
2243
|
+
}
|
|
2244
|
+
c === -1 && (l = !1, c = u + 1), r === 46 ? o === -1 ? o = u : d !== 1 && (d = 1) : o !== -1 && (d = -1);
|
|
2245
|
+
}
|
|
2246
|
+
return o === -1 || c === -1 || d === 0 || d === 1 && o === c - 1 && o === s + 1 ? c !== -1 && (s === 0 && i ? t.base = t.name = e.slice(1, c) : t.base = t.name = e.slice(s, c)) : (s === 0 && i ? (t.name = e.slice(1, o), t.base = e.slice(1, c)) : (t.name = e.slice(s, o), t.base = e.slice(s, c)), t.ext = e.slice(o, c)), s > 0 ? t.dir = e.slice(0, s - 1) : i && (t.dir = "/"), t;
|
|
2247
|
+
},
|
|
2248
|
+
sep: "/",
|
|
2249
|
+
delimiter: ":",
|
|
2250
|
+
win32: null,
|
|
2251
|
+
posix: null
|
|
2252
|
+
};
|
|
2253
|
+
a.posix = a, t.exports = a;
|
|
2254
|
+
})), Y = /* @__PURE__ */ t(((e, t) => {
|
|
2255
|
+
T();
|
|
2256
|
+
var n = E(), { BinaryFile: r } = q(), i = 0, a = 8, o = 20, c = 28, l = 31, u = 44, d = 54, f = 70, p = 0, m = 2, h = 3, g = 4, _ = 1, v = 2, y = 4, b = 8, x = 1, S = class extends n {
|
|
2257
|
+
get name() {
|
|
2258
|
+
return "wasm";
|
|
2259
|
+
}
|
|
2260
|
+
get requiresFilesystem() {
|
|
2261
|
+
return !0;
|
|
2262
|
+
}
|
|
2263
|
+
run() {
|
|
2264
|
+
let e = this.script, t = (() => {
|
|
2265
|
+
try {
|
|
2266
|
+
return J();
|
|
2267
|
+
} catch {
|
|
2268
|
+
return null;
|
|
2269
|
+
}
|
|
2270
|
+
})();
|
|
2271
|
+
return this._loadBytes(e, t).then(({ bytes: e, isWat: t }) => t ? this._runWat(e) : this._runWasm(e)).catch((e) => {
|
|
2272
|
+
this.stdErr = e.message || String(e), this.exitCode = 1;
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
_loadBytes(e, t) {
|
|
2276
|
+
if (this.context.fs.isRealFilesystem && t) try {
|
|
2277
|
+
let n = t.readFileSync(this.context.fs.absolutePath(e)), r = new Uint8Array(n);
|
|
2278
|
+
return Promise.resolve({
|
|
2279
|
+
bytes: r,
|
|
2280
|
+
isWat: this._isWat(e, r)
|
|
2281
|
+
});
|
|
2282
|
+
} catch (t) {
|
|
2283
|
+
return Promise.reject(/* @__PURE__ */ Error(`${e}: ${t.message}`));
|
|
2284
|
+
}
|
|
2285
|
+
let n = this.context.fs.getFileByPath(e);
|
|
2286
|
+
if (n == null) return Promise.reject(/* @__PURE__ */ Error(`${e}: No such file or directory`));
|
|
2287
|
+
let r = this._contentToBytes(n);
|
|
2288
|
+
return Promise.resolve({
|
|
2289
|
+
bytes: r,
|
|
2290
|
+
isWat: this._isWat(e, r)
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
_isWat(e, t) {
|
|
2294
|
+
return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
|
|
2295
|
+
}
|
|
2296
|
+
_contentToBytes(e) {
|
|
2297
|
+
if (e instanceof Uint8Array) return e;
|
|
2298
|
+
if (w !== void 0 && w.isBuffer(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
2299
|
+
if (e instanceof ArrayBuffer) return new Uint8Array(e);
|
|
2300
|
+
let t = new Uint8Array(e.length);
|
|
2301
|
+
for (let n = 0; n < e.length; n++) t[n] = e.charCodeAt(n) & 255;
|
|
2302
|
+
return t;
|
|
2303
|
+
}
|
|
2304
|
+
async _runWat(e) {
|
|
2305
|
+
let t = new TextDecoder().decode(e), n, r;
|
|
2306
|
+
try {
|
|
2307
|
+
r = await import(
|
|
2308
|
+
/* @vite-ignore */
|
|
2309
|
+
"wabt"
|
|
2310
|
+
);
|
|
2311
|
+
} catch {
|
|
2312
|
+
this.stdErr = `${this.script}: WAT execution requires the 'wabt' package\nInstall it with: npm install wabt`, this.exitCode = 1;
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
try {
|
|
2316
|
+
let e = r.default ?? r, { buffer: i } = (typeof e == "function" ? await e() : e).parseWat(this.script, t, { mutable_globals: !0 }).toBinary({});
|
|
2317
|
+
n = new Uint8Array(i);
|
|
2318
|
+
} catch (e) {
|
|
2319
|
+
this.stdErr = `${this.script}: WAT compilation error: ${e.message}`, this.exitCode = 1;
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
return this._runWasm(n);
|
|
2323
|
+
}
|
|
2324
|
+
async _runWasm(e) {
|
|
2325
|
+
if (typeof WebAssembly > "u") {
|
|
2326
|
+
this.stdErr = `${this.script}: WebAssembly is not available in this environment`, this.exitCode = 1;
|
|
2327
|
+
return;
|
|
2328
|
+
}
|
|
2329
|
+
let t = {
|
|
2330
|
+
1: "",
|
|
2331
|
+
2: ""
|
|
2332
|
+
}, n = new TextDecoder(), s = new TextEncoder(), S = null, C = (e, n) => {
|
|
2333
|
+
t[e] = (t[e] || "") + n;
|
|
2334
|
+
let r = t[e].split("\n");
|
|
2335
|
+
t[e] = r.pop();
|
|
2336
|
+
for (let t of r) e === 1 ? this.stdOut = t : this.stdErr = t;
|
|
2337
|
+
}, w = () => {
|
|
2338
|
+
t[1] &&= (this.stdOut = t[1], ""), t[2] &&= (this.stdErr = t[2], "");
|
|
2339
|
+
}, T = s.encode(this.stdin || ""), E = 0, D = this.context && this.context.fs ? this.context.fs : this.fs, O = 5, k = new Map([[3, {
|
|
2340
|
+
type: "preopen",
|
|
2341
|
+
path: "/",
|
|
2342
|
+
guestName: "/"
|
|
2343
|
+
}], [4, {
|
|
2344
|
+
type: "preopen",
|
|
2345
|
+
path: D && D.cwd || "/",
|
|
2346
|
+
guestName: "."
|
|
2347
|
+
}]]), A = (e, t) => {
|
|
2348
|
+
let n = k.get(e);
|
|
2349
|
+
if (!n || n.type !== "preopen" && n.type !== "dir") return null;
|
|
2350
|
+
if (t.startsWith("/")) return D.absolutePath(t);
|
|
2351
|
+
let r = n.path.endsWith("/") ? n.path : n.path + "/";
|
|
2352
|
+
return D.absolutePath(r + t);
|
|
2353
|
+
}, N = (e) => {
|
|
2354
|
+
if (!(!e || e.type !== "file" || !e.dirty || !D)) try {
|
|
2355
|
+
let t = !0;
|
|
2356
|
+
for (let n = 0; n < e.bytes.length; n++) if (e.bytes[n] === 0) {
|
|
2357
|
+
t = !1;
|
|
2358
|
+
break;
|
|
2359
|
+
}
|
|
2360
|
+
if (t) {
|
|
2361
|
+
let t = n.decode(e.bytes);
|
|
2362
|
+
D.setFileByPath(e.path, t, !0);
|
|
2363
|
+
} else {
|
|
2364
|
+
let t = new Uint8Array(e.bytes.length);
|
|
2365
|
+
t.set(e.bytes), D.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
|
|
2366
|
+
}
|
|
2367
|
+
e.dirty = !1;
|
|
2368
|
+
} catch {}
|
|
2369
|
+
}, P = Object.entries(this.context && this.context.vars || {}).map(([e, t]) => `${e}=${t}`), F = new Proxy({
|
|
2370
|
+
fd_write: (e, t, r, o) => {
|
|
2371
|
+
if (!S) return a;
|
|
2372
|
+
let s = new DataView(S.buffer);
|
|
2373
|
+
if (e === 1 || e === 2) {
|
|
2374
|
+
let a = 0;
|
|
2375
|
+
for (let i = 0; i < r; i++) {
|
|
2376
|
+
let r = s.getUint32(t + i * 8, !0), o = s.getUint32(t + i * 8 + 4, !0);
|
|
2377
|
+
o > 0 && C(e, n.decode(new Uint8Array(S.buffer, r, o))), a += o;
|
|
2378
|
+
}
|
|
2379
|
+
return s.setUint32(o, a, !0), i;
|
|
2380
|
+
}
|
|
2381
|
+
let c = k.get(e);
|
|
2382
|
+
if (!c || c.type !== "file") return a;
|
|
2383
|
+
let l = 0;
|
|
2384
|
+
for (let e = 0; e < r; e++) {
|
|
2385
|
+
let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0);
|
|
2386
|
+
if (r > 0) {
|
|
2387
|
+
let e = new Uint8Array(S.buffer, n, r), t = c.append ? c.bytes.length : c.pos, i = t + r;
|
|
2388
|
+
if (i > c.bytes.length) {
|
|
2389
|
+
let e = new Uint8Array(i);
|
|
2390
|
+
e.set(c.bytes), c.bytes = e;
|
|
2391
|
+
}
|
|
2392
|
+
c.bytes.set(e, t), c.pos = t + r, c.dirty = !0, l += r;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
return s.setUint32(o, l, !0), i;
|
|
2396
|
+
},
|
|
2397
|
+
fd_read: (e, t, n, r) => {
|
|
2398
|
+
if (!S) return a;
|
|
2399
|
+
let o = new DataView(S.buffer);
|
|
2400
|
+
if (e === 0) {
|
|
2401
|
+
let e = 0;
|
|
2402
|
+
for (let r = 0; r < n && E < T.length; r++) {
|
|
2403
|
+
let n = o.getUint32(t + r * 8, !0), i = o.getUint32(t + r * 8 + 4, !0), a = Math.min(i, T.length - E);
|
|
2404
|
+
new Uint8Array(S.buffer).set(T.slice(E, E + a), n), E += a, e += a;
|
|
2405
|
+
}
|
|
2406
|
+
return o.setUint32(r, e, !0), i;
|
|
2407
|
+
}
|
|
2408
|
+
let s = k.get(e);
|
|
2409
|
+
if (!s || s.type !== "file") return a;
|
|
2410
|
+
let c = 0;
|
|
2411
|
+
for (let e = 0; e < n && s.pos < s.bytes.length; e++) {
|
|
2412
|
+
let n = o.getUint32(t + e * 8, !0), r = o.getUint32(t + e * 8 + 4, !0), i = Math.min(r, s.bytes.length - s.pos);
|
|
2413
|
+
new Uint8Array(S.buffer).set(s.bytes.subarray(s.pos, s.pos + i), n), s.pos += i, c += i;
|
|
2414
|
+
}
|
|
2415
|
+
return o.setUint32(r, c, !0), i;
|
|
2416
|
+
},
|
|
2417
|
+
fd_seek: (e, t, n, r, o) => {
|
|
2418
|
+
if (!S) return a;
|
|
2419
|
+
if (e <= 2) return f;
|
|
2420
|
+
let s = k.get(e);
|
|
2421
|
+
if (!s || s.type !== "file") return a;
|
|
2422
|
+
let l, u, d;
|
|
2423
|
+
typeof t == "bigint" ? (l = Number(t), u = n, d = r) : (l = t, u = r, d = o);
|
|
2424
|
+
let p = s.pos;
|
|
2425
|
+
if (u === 0) p = l;
|
|
2426
|
+
else if (u === 1) p = s.pos + l;
|
|
2427
|
+
else if (u === 2) p = s.bytes.length + l;
|
|
2428
|
+
else return c;
|
|
2429
|
+
return p < 0 ? c : (s.pos = p, d && new DataView(S.buffer).setBigUint64(d, BigInt(s.pos), !0), i);
|
|
2430
|
+
},
|
|
2431
|
+
fd_tell: (e, t) => {
|
|
2432
|
+
if (!S) return a;
|
|
2433
|
+
let n = k.get(e);
|
|
2434
|
+
return !n || n.type !== "file" ? a : (new DataView(S.buffer).setBigUint64(t, BigInt(n.pos), !0), i);
|
|
2435
|
+
},
|
|
2436
|
+
fd_close: (e) => {
|
|
2437
|
+
if (e <= 2) return i;
|
|
2438
|
+
let t = k.get(e);
|
|
2439
|
+
return t ? (N(t), k.delete(e), i) : a;
|
|
2440
|
+
},
|
|
2441
|
+
fd_sync: (e) => {
|
|
2442
|
+
let t = k.get(e);
|
|
2443
|
+
return t && N(t), i;
|
|
2444
|
+
},
|
|
2445
|
+
fd_datasync: (e) => {
|
|
2446
|
+
let t = k.get(e);
|
|
2447
|
+
return t && N(t), i;
|
|
2448
|
+
},
|
|
2449
|
+
fd_prestat_get: (e, t) => {
|
|
2450
|
+
if (!S) return a;
|
|
2451
|
+
let n = k.get(e);
|
|
2452
|
+
if (!n || n.type !== "preopen") return a;
|
|
2453
|
+
let r = new DataView(S.buffer), o = s.encode(n.guestName);
|
|
2454
|
+
return r.setUint8(t, 0), r.setUint32(t + 4, o.length, !0), i;
|
|
2455
|
+
},
|
|
2456
|
+
fd_prestat_dir_name: (e, t, n) => {
|
|
2457
|
+
if (!S) return a;
|
|
2458
|
+
let r = k.get(e);
|
|
2459
|
+
if (!r || r.type !== "preopen") return a;
|
|
2460
|
+
let o = s.encode(r.guestName);
|
|
2461
|
+
return new Uint8Array(S.buffer, t, Math.min(n, o.length)).set(o.subarray(0, n)), i;
|
|
2462
|
+
},
|
|
2463
|
+
fd_fdstat_get: (e, t) => {
|
|
2464
|
+
if (!S) return a;
|
|
2465
|
+
let n = new DataView(S.buffer), r = p;
|
|
2466
|
+
if (e <= 2) r = m;
|
|
2467
|
+
else {
|
|
2468
|
+
let t = k.get(e);
|
|
2469
|
+
if (!t) return a;
|
|
2470
|
+
r = t.type === "preopen" || t.type === "dir" ? h : g;
|
|
2471
|
+
}
|
|
2472
|
+
for (let e = 0; e < 24; e++) n.setUint8(t + e, 0);
|
|
2473
|
+
return n.setUint8(t, r), n.setBigUint64(t + 8, 18446744073709551615n, !0), n.setBigUint64(t + 16, 18446744073709551615n, !0), i;
|
|
2474
|
+
},
|
|
2475
|
+
fd_fdstat_set_flags: () => i,
|
|
2476
|
+
fd_filestat_get: (e, t) => {
|
|
2477
|
+
if (!S) return a;
|
|
2478
|
+
let n = new DataView(S.buffer);
|
|
2479
|
+
for (let e = 0; e < 64; e++) n.setUint8(t + e, 0);
|
|
2480
|
+
if (e <= 2) return n.setUint8(t + 16, m), i;
|
|
2481
|
+
let r = k.get(e);
|
|
2482
|
+
if (!r) return a;
|
|
2483
|
+
let o = r.type === "preopen" || r.type === "dir";
|
|
2484
|
+
return n.setUint8(t + 16, o ? h : g), n.setBigUint64(t + 24, 1n, !0), n.setBigUint64(t + 32, BigInt(r.bytes ? r.bytes.length : 0), !0), i;
|
|
2485
|
+
},
|
|
2486
|
+
path_open: (e, t, r, c, f, p, m, h, g) => {
|
|
2487
|
+
if (!S || !D) return a;
|
|
2488
|
+
let C = A(e, n.decode(new Uint8Array(S.buffer, r, c)));
|
|
2489
|
+
if (!C) return a;
|
|
2490
|
+
let w = D.stat(C), T = w !== null;
|
|
2491
|
+
if (f & y && f & _ && T) return o;
|
|
2492
|
+
if (f & v) {
|
|
2493
|
+
if (!T) return u;
|
|
2494
|
+
if (!w.isDirectory) return d;
|
|
2495
|
+
let e = O++;
|
|
2496
|
+
return k.set(e, {
|
|
2497
|
+
type: "dir",
|
|
2498
|
+
path: C
|
|
2499
|
+
}), new DataView(S.buffer).setUint32(g, e, !0), i;
|
|
2500
|
+
}
|
|
2501
|
+
if (T && w.isDirectory) return l;
|
|
2502
|
+
if (!T && !(f & _)) return u;
|
|
2503
|
+
let E = new Uint8Array(), j = !1;
|
|
2504
|
+
if (T && !(f & b)) {
|
|
2505
|
+
let e = D.getFileByPath(C);
|
|
2506
|
+
e != null && (E = typeof e == "string" ? s.encode(e) : new Uint8Array(this._contentToBytes(e)));
|
|
2507
|
+
} else j = !0;
|
|
2508
|
+
let M = O++;
|
|
2509
|
+
return k.set(M, {
|
|
2510
|
+
type: "file",
|
|
2511
|
+
path: C,
|
|
2512
|
+
bytes: E,
|
|
2513
|
+
pos: h & x ? E.length : 0,
|
|
2514
|
+
append: !!(h & x),
|
|
2515
|
+
dirty: j
|
|
2516
|
+
}), new DataView(S.buffer).setUint32(g, M, !0), i;
|
|
2517
|
+
},
|
|
2518
|
+
path_filestat_get: (e, t, r, o, s) => {
|
|
2519
|
+
if (!S || !D) return a;
|
|
2520
|
+
let c = A(e, n.decode(new Uint8Array(S.buffer, r, o)));
|
|
2521
|
+
if (!c) return a;
|
|
2522
|
+
let l = D.stat(c);
|
|
2523
|
+
if (!l) return u;
|
|
2524
|
+
let d = new DataView(S.buffer);
|
|
2525
|
+
for (let e = 0; e < 64; e++) d.setUint8(s + e, 0);
|
|
2526
|
+
return d.setUint8(s + 16, l.isDirectory ? h : g), d.setBigUint64(s + 24, 1n, !0), d.setBigUint64(s + 32, BigInt(D.getSize(c) || 0), !0), i;
|
|
2527
|
+
},
|
|
2528
|
+
path_create_directory: (e, t, r) => {
|
|
2529
|
+
if (!S || !D) return a;
|
|
2530
|
+
let o = A(e, n.decode(new Uint8Array(S.buffer, t, r)));
|
|
2531
|
+
if (!o) return a;
|
|
2532
|
+
try {
|
|
2533
|
+
return D.setFileByPath(o, {}, !0), i;
|
|
2534
|
+
} catch {
|
|
2535
|
+
return c;
|
|
2536
|
+
}
|
|
2537
|
+
},
|
|
2538
|
+
path_unlink_file: (e, t, r) => {
|
|
2539
|
+
if (!S || !D) return a;
|
|
2540
|
+
let o = A(e, n.decode(new Uint8Array(S.buffer, t, r)));
|
|
2541
|
+
if (!o || !D.exists(o)) return u;
|
|
2542
|
+
try {
|
|
2543
|
+
return D.deleteFileByPath(o), i;
|
|
2544
|
+
} catch {
|
|
2545
|
+
return c;
|
|
2546
|
+
}
|
|
2547
|
+
},
|
|
2548
|
+
path_remove_directory: (e, t, r) => {
|
|
2549
|
+
if (!S || !D) return a;
|
|
2550
|
+
let o = A(e, n.decode(new Uint8Array(S.buffer, t, r)));
|
|
2551
|
+
if (!o || !D.exists(o)) return u;
|
|
2552
|
+
try {
|
|
2553
|
+
return D.deleteFileByPath(o), i;
|
|
2554
|
+
} catch {
|
|
2555
|
+
return c;
|
|
2556
|
+
}
|
|
2557
|
+
},
|
|
2558
|
+
proc_exit: (e) => {
|
|
2559
|
+
throw e !== 0 && (this.exitCode = e), {
|
|
2560
|
+
_wasmExit: !0,
|
|
2561
|
+
code: e
|
|
2562
|
+
};
|
|
2563
|
+
},
|
|
2564
|
+
args_sizes_get: (e, t) => {
|
|
2565
|
+
if (!S) return c;
|
|
2566
|
+
let n = [this.script, ...this.arguments || []], r = new DataView(S.buffer);
|
|
2567
|
+
return r.setUint32(e, n.length, !0), r.setUint32(t, n.reduce((e, t) => e + s.encode(t).length + 1, 0), !0), i;
|
|
2568
|
+
},
|
|
2569
|
+
args_get: (e, t) => {
|
|
2570
|
+
if (!S) return c;
|
|
2571
|
+
let n = [this.script, ...this.arguments || []], r = new DataView(S.buffer), a = t;
|
|
2572
|
+
for (let t = 0; t < n.length; t++) {
|
|
2573
|
+
r.setUint32(e + t * 4, a, !0);
|
|
2574
|
+
let i = s.encode(n[t] + "\0");
|
|
2575
|
+
new Uint8Array(S.buffer).set(i, a), a += i.length;
|
|
2576
|
+
}
|
|
2577
|
+
return i;
|
|
2578
|
+
},
|
|
2579
|
+
environ_sizes_get: (e, t) => {
|
|
2580
|
+
if (!S) return c;
|
|
2581
|
+
let n = new DataView(S.buffer);
|
|
2582
|
+
n.setUint32(e, P.length, !0);
|
|
2583
|
+
let r = P.reduce((e, t) => e + s.encode(t).length + 1, 0);
|
|
2584
|
+
return n.setUint32(t, r, !0), i;
|
|
2585
|
+
},
|
|
2586
|
+
environ_get: (e, t) => {
|
|
2587
|
+
if (!S) return c;
|
|
2588
|
+
let n = new DataView(S.buffer), r = t;
|
|
2589
|
+
for (let t = 0; t < P.length; t++) {
|
|
2590
|
+
n.setUint32(e + t * 4, r, !0);
|
|
2591
|
+
let i = s.encode(P[t] + "\0");
|
|
2592
|
+
new Uint8Array(S.buffer).set(i, r), r += i.length;
|
|
2593
|
+
}
|
|
2594
|
+
return i;
|
|
2595
|
+
},
|
|
2596
|
+
clock_time_get: (e, t, n) => {
|
|
2597
|
+
if (S) {
|
|
2598
|
+
let e = BigInt(Date.now()) * 1000000n;
|
|
2599
|
+
new DataView(S.buffer).setBigUint64(n, e, !0);
|
|
2600
|
+
}
|
|
2601
|
+
return i;
|
|
2602
|
+
},
|
|
2603
|
+
random_get: (e, t) => {
|
|
2604
|
+
if (S) {
|
|
2605
|
+
let n = new Uint8Array(S.buffer, e, t);
|
|
2606
|
+
for (let e = 0; e < t; e++) n[e] = Math.random() * 256 | 0;
|
|
2607
|
+
}
|
|
2608
|
+
return i;
|
|
2609
|
+
}
|
|
2610
|
+
}, { get(e, t) {
|
|
2611
|
+
return t in e ? e[t] : () => 0;
|
|
2612
|
+
} }), I = (e) => {
|
|
2613
|
+
if (!S || !e) return "";
|
|
2614
|
+
try {
|
|
2615
|
+
let t = new DataView(S.buffer).getUint32(e - 4, !0), n = new Uint16Array(S.buffer, e, t >>> 1);
|
|
2616
|
+
return String.fromCharCode(...n);
|
|
2617
|
+
} catch {
|
|
2618
|
+
return "";
|
|
2619
|
+
}
|
|
2620
|
+
}, L = {
|
|
2621
|
+
wasi_snapshot_preview1: F,
|
|
2622
|
+
wasi_unstable: F,
|
|
2623
|
+
env: new Proxy({
|
|
2624
|
+
print: (e, t) => {
|
|
2625
|
+
S && C(1, n.decode(new Uint8Array(S.buffer, e, t)));
|
|
2626
|
+
},
|
|
2627
|
+
eprint: (e, t) => {
|
|
2628
|
+
S && C(2, n.decode(new Uint8Array(S.buffer, e, t)));
|
|
2629
|
+
},
|
|
2630
|
+
log: (e) => {
|
|
2631
|
+
C(1, I(e) + "\n");
|
|
2632
|
+
},
|
|
2633
|
+
logi: (e) => {
|
|
2634
|
+
C(1, String(e) + "\n");
|
|
2635
|
+
},
|
|
2636
|
+
logf: (e) => {
|
|
2637
|
+
C(1, String(e) + "\n");
|
|
2638
|
+
},
|
|
2639
|
+
trace: (e, t, ...n) => {
|
|
2640
|
+
let r = t > 0 ? " " + n.slice(0, t).join(", ") : "";
|
|
2641
|
+
C(1, `trace: ${I(e)}${r}\n`);
|
|
2642
|
+
},
|
|
2643
|
+
seed: () => Date.now() * Math.random(),
|
|
2644
|
+
abort: (e, t, n, r) => {
|
|
2645
|
+
let i = I(e), a = I(t);
|
|
2646
|
+
throw (i || a) && C(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
|
|
2647
|
+
_wasmExit: !0,
|
|
2648
|
+
code: 134
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
}, { get(e, t) {
|
|
2652
|
+
return t in e ? e[t] : () => 0;
|
|
2653
|
+
} })
|
|
2654
|
+
};
|
|
2655
|
+
try {
|
|
2656
|
+
let t = await WebAssembly.compile(e);
|
|
2657
|
+
for (let e of WebAssembly.Module.imports(t)) if (e.kind === "memory") {
|
|
2658
|
+
let t = new WebAssembly.Memory({
|
|
2659
|
+
initial: 1,
|
|
2660
|
+
maximum: 256
|
|
2661
|
+
});
|
|
2662
|
+
S = t, L[e.module] || (L[e.module] = {}), L[e.module][e.name] = t;
|
|
2663
|
+
}
|
|
2664
|
+
let n = await WebAssembly.instantiate(t, L);
|
|
2665
|
+
n.exports.memory && (S = n.exports.memory);
|
|
2666
|
+
let r = n.exports._start || n.exports.__wasi_command || n.exports.main || n.exports.run;
|
|
2667
|
+
if (r) try {
|
|
2668
|
+
await r();
|
|
2669
|
+
} catch (e) {
|
|
2670
|
+
(!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
2671
|
+
}
|
|
2672
|
+
else {
|
|
2673
|
+
let e = Object.entries(n.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
|
|
2674
|
+
this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
|
|
2675
|
+
}
|
|
2676
|
+
} catch (e) {
|
|
2677
|
+
(!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
2678
|
+
} finally {
|
|
2679
|
+
for (let e of k.values()) N(e);
|
|
2680
|
+
}
|
|
2681
|
+
w();
|
|
2682
|
+
let R = this.arguments || [];
|
|
2683
|
+
if (!(this.result && this.result.getStdOutput && this.result.getStdOutput().length > 0) && (this.exitCode === 0 || this.exitCode === void 0)) {
|
|
2684
|
+
let t = (this.script || "wasm").split("/").pop(), n = Object.assign({
|
|
2685
|
+
name: t,
|
|
2686
|
+
version: "wasi",
|
|
2687
|
+
description: `WebAssembly WASI binary (${this.script})`
|
|
2688
|
+
}, this._pkgMeta || {});
|
|
2689
|
+
if (R.includes("--help") || R.includes("-h")) {
|
|
2690
|
+
let r = j(e);
|
|
2691
|
+
for (let e of M(t, n, r)) this.stdOut = e;
|
|
2692
|
+
} else (R.includes("--version") || R.includes("-V") || R.includes("-v")) && (this.stdOut = `${t} (${n.name} ${n.version} wasm)`);
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
}, C = /* @__PURE__ */ new Map();
|
|
2696
|
+
function D(e, t) {
|
|
2697
|
+
if (!e || !e.exists(t)) return null;
|
|
2698
|
+
if (e.isRealFilesystem) try {
|
|
2699
|
+
let n = J();
|
|
2700
|
+
return new Uint8Array(n.readFileSync(e.absolutePath(t)));
|
|
2701
|
+
} catch {
|
|
2702
|
+
return null;
|
|
2703
|
+
}
|
|
2704
|
+
let n = e.getFileByPath(t);
|
|
2705
|
+
if (n == null) return null;
|
|
2706
|
+
if (n instanceof Uint8Array || w !== void 0 && w.isBuffer(n)) return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
2707
|
+
if (n instanceof ArrayBuffer) return new Uint8Array(n);
|
|
2708
|
+
if (typeof n == "string") {
|
|
2709
|
+
if (n.startsWith("data:")) {
|
|
2710
|
+
let e = n.indexOf(",");
|
|
2711
|
+
if (e !== -1) {
|
|
2712
|
+
let t = n.slice(e + 1);
|
|
2713
|
+
if (w !== void 0) return new Uint8Array(w.from(t, "base64"));
|
|
2714
|
+
let r = atob(t), i = new Uint8Array(r.length);
|
|
2715
|
+
for (let e = 0; e < r.length; e++) i[e] = r.charCodeAt(e);
|
|
2716
|
+
return i;
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
let e = new Uint8Array(n.length);
|
|
2720
|
+
for (let t = 0; t < n.length; t++) e[t] = n.charCodeAt(t) & 255;
|
|
2721
|
+
return e;
|
|
2722
|
+
}
|
|
2723
|
+
return null;
|
|
2724
|
+
}
|
|
2725
|
+
function O(e, t, n, i = "application/octet-stream") {
|
|
2726
|
+
let a = n instanceof Uint8Array ? n : new Uint8Array(n);
|
|
2727
|
+
if (e.isRealFilesystem) {
|
|
2728
|
+
let n = J(), r = re(), i = e.absolutePath(t);
|
|
2729
|
+
n.mkdirSync(r.dirname(i), { recursive: !0 }), n.writeFileSync(i, w.from(a.buffer, a.byteOffset, a.byteLength));
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
let o = new Uint8Array(a.byteLength);
|
|
2733
|
+
o.set(a);
|
|
2734
|
+
let s = new r(o.buffer, i);
|
|
2735
|
+
e.setFileByPath(t, s, !0);
|
|
2736
|
+
}
|
|
2737
|
+
async function k(e, t, n = null) {
|
|
2738
|
+
if (typeof n == "function") {
|
|
2739
|
+
let r = await n(e, t);
|
|
2740
|
+
if (r) return r;
|
|
2741
|
+
}
|
|
2742
|
+
try {
|
|
2743
|
+
let t = await import(
|
|
2744
|
+
/* @vite-ignore */
|
|
2745
|
+
e
|
|
2746
|
+
);
|
|
2747
|
+
if (t) return t;
|
|
2748
|
+
} catch {}
|
|
2749
|
+
if (t) try {
|
|
2750
|
+
return await import(
|
|
2751
|
+
/* @vite-ignore */
|
|
2752
|
+
t
|
|
2753
|
+
);
|
|
2754
|
+
} catch (n) {
|
|
2755
|
+
throw Error(`Failed to load WASM package '${e}' from ${t}: ${n.message || n}`);
|
|
2756
|
+
}
|
|
2757
|
+
throw Error(`Package '${e}' could not be loaded`);
|
|
2758
|
+
}
|
|
2759
|
+
function A(e, t = !1) {
|
|
2760
|
+
let n = {
|
|
2761
|
+
usage: null,
|
|
2762
|
+
options: []
|
|
2763
|
+
};
|
|
2764
|
+
if (!e || typeof e != "string") return n;
|
|
2765
|
+
let r = e.split(/\r?\n/).map((e) => e.trim()).filter(Boolean), i = /* @__PURE__ */ new Set();
|
|
2766
|
+
for (let e of r) !n.usage && /^usage:\s*(.+)/i.test(e) ? n.usage = e.replace(/^usage:\s*/i, "").trim() : /^(?:-[a-zA-Z0-9?]|--[a-zA-Z0-9][-a-zA-Z0-9]*)(?:\s|,|=|<|\[|$)/.test(e) && e.length <= 120 && !/^(?:-[hHvV],\s*)?--(?:help|version)\b/i.test(e) && (i.has(e) || (i.add(e), n.options.push(e)));
|
|
2767
|
+
if (t && n.options.length === 0) {
|
|
2768
|
+
let t = e.match(/--[a-z][a-z0-9-]{1,24}/g) || [];
|
|
2769
|
+
for (let e of Array.from(new Set(t)).slice(0, 12)) e !== "--help" && e !== "--version" && n.options.push(e);
|
|
2770
|
+
}
|
|
2771
|
+
return n;
|
|
2772
|
+
}
|
|
2773
|
+
function j(e) {
|
|
2774
|
+
let t = {
|
|
2775
|
+
usage: null,
|
|
2776
|
+
options: [],
|
|
2777
|
+
exports: [],
|
|
2778
|
+
wasiImports: []
|
|
2779
|
+
};
|
|
2780
|
+
if (!(e instanceof Uint8Array) || e.length < 8) return t;
|
|
2781
|
+
try {
|
|
2782
|
+
if (typeof WebAssembly < "u" && WebAssembly.Module) {
|
|
2783
|
+
let n = new WebAssembly.Module(e);
|
|
2784
|
+
t.exports = WebAssembly.Module.exports(n).filter((e) => e.kind === "function").map((e) => e.name), t.wasiImports = WebAssembly.Module.imports(n).filter((e) => e.module.startsWith("wasi_")).map((e) => e.name);
|
|
2785
|
+
}
|
|
2786
|
+
} catch {}
|
|
2787
|
+
try {
|
|
2788
|
+
let n = [], r = "";
|
|
2789
|
+
for (let t = 0; t < e.length; t++) {
|
|
2790
|
+
let i = e[t];
|
|
2791
|
+
i >= 32 && i <= 126 || i === 9 || i === 10 ? r += String.fromCharCode(i) : (r.length >= 4 && n.push(r), r = "");
|
|
2792
|
+
}
|
|
2793
|
+
r.length >= 4 && n.push(r);
|
|
2794
|
+
let i = A(n.join("\n"), !0);
|
|
2795
|
+
t.usage = i.usage, t.options = i.options;
|
|
2796
|
+
} catch {}
|
|
2797
|
+
return t;
|
|
2798
|
+
}
|
|
2799
|
+
function M(e, t = {}, n = null) {
|
|
2800
|
+
let r = t.name || e, i = t.version || "wasm", a = t.description || "WebAssembly binary", o = t && typeof t.repl == "object" ? t.repl : t.repl ? {} : null, s = n && n.usage || t.usage, c = o ? `${e} [options] ${o.evalFlag ? `[${o.evalFlag} <code>] ` : ""}[file] [args...]` : `${e} [options] [args...]`, l = [`${e} (${r} ${i} wasm) — ${a}`, `Usage: ${s || c}`];
|
|
2801
|
+
t.details && l.push("", t.details), l.push("", "Options:");
|
|
2802
|
+
let u = n && n.options && n.options.length > 0 ? n.options : Array.isArray(t.options) ? t.options : [];
|
|
2803
|
+
if (u.length > 0) for (let e of u) l.push(` ${e}`);
|
|
2804
|
+
else o && (o.evalFlag && l.push(` ${o.evalFlag.padEnd(20)}Evaluate inline code and print result`), l.push(` (no arguments) Start interactive ${e} REPL shell`));
|
|
2805
|
+
return l.push(" -h, --help Show this help message and exit"), l.push(" -V, --version Show WebAssembly binary version and exit"), n && n.exports && n.exports.length > 0 && l.push("", `WASM Exports: ${n.exports.join(", ")}`), Array.isArray(t.aliases) && t.aliases.length > 0 && l.push("", `Aliases: ${t.aliases.join(", ")}`), (t.homepage || t.cdnUrl || t.wasmUrl) && l.push(`Source: ${t.homepage || t.cdnUrl || t.wasmUrl}`), l;
|
|
2806
|
+
}
|
|
2807
|
+
function N(e, t = {}, n = null) {
|
|
2808
|
+
let r = s(), i = (n || e.bin || e.name).toLowerCase();
|
|
2809
|
+
class a extends r {
|
|
2810
|
+
static get name() {
|
|
2811
|
+
return i;
|
|
2812
|
+
}
|
|
2813
|
+
get name() {
|
|
2814
|
+
return i;
|
|
2815
|
+
}
|
|
2816
|
+
get requiresFilesystem() {
|
|
2817
|
+
return !0;
|
|
2818
|
+
}
|
|
2819
|
+
async run() {
|
|
2820
|
+
let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
|
|
2821
|
+
this._inspectedWasm = null;
|
|
2822
|
+
try {
|
|
2823
|
+
if (e.type === "wasm" && e.wasmUrl && !t.moduleLoader) {
|
|
2824
|
+
let t = await this._fetchWasmBytes(e.wasmUrl);
|
|
2825
|
+
r && (this._inspectedWasm = j(t)), await this._runRawWasmBytes(t, n);
|
|
2826
|
+
} else {
|
|
2827
|
+
let o = e.cdnUrl || e.wasmUrl || `https://esm.sh/${e.name}`, s = await k(e.name, o, t.moduleLoader), c = s && s.default !== void 0 ? s.default : s;
|
|
2828
|
+
if (c instanceof Uint8Array || c instanceof ArrayBuffer) {
|
|
2829
|
+
let e = c instanceof Uint8Array ? c : new Uint8Array(c);
|
|
2830
|
+
r && (this._inspectedWasm = j(e)), await this._runRawWasmBytes(e, n);
|
|
2831
|
+
} else if (c && (c.wasmBytes instanceof Uint8Array || c.wasm instanceof Uint8Array)) {
|
|
2832
|
+
let e = c.wasmBytes || c.wasm;
|
|
2833
|
+
r && (this._inspectedWasm = j(e)), await this._runRawWasmBytes(e, n);
|
|
2834
|
+
} else if (typeof c == "function") await this._runFunctionOrEmscripten(c, n, r);
|
|
2835
|
+
else if (c && typeof c == "object") {
|
|
2836
|
+
c.ready && await c.ready, r && (c.HEAPU8 instanceof Uint8Array || c.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = j(c.wasmBinary || c.HEAPU8));
|
|
2837
|
+
let t = c.main || c.run || c.callMain || c.exec;
|
|
2838
|
+
if (typeof t == "function") await this._invokeCliFunction(t.bind(c), n);
|
|
2839
|
+
else if (!r && !a) {
|
|
2840
|
+
this.stdErr = `${i}: unsupported WASM module format for '${e.name}'`, this.exitCode = 1;
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
} else if (!r && !a) {
|
|
2844
|
+
this.stdErr = `${i}: unsupported WASM module format for '${e.name}'`, this.exitCode = 1;
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
} catch (e) {
|
|
2849
|
+
if (!r && !a) {
|
|
2850
|
+
if (e && typeof e.status == "number") {
|
|
2851
|
+
this.exitCode = e.status;
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
this.stdErr = `${i}: ${e.message || e}`, this.exitCode = 1;
|
|
2855
|
+
return;
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
if (r || a) {
|
|
2859
|
+
let t = this.result && this.result.getStdOutput ? this.result.getStdOutput() : [], n = t.map((e) => e.string).join("\n"), o = r ? A(n) : null, s = r && !!(o && (o.usage || o.options.length > 0) || t.some((e) => /\b(usage|options):/i.test(e.string))), c = t.filter((e) => e.type === "out").map((e) => e.string), l = a && c.length > 0 && (this.exitCode === 0 || this.exitCode === void 0);
|
|
2860
|
+
if (r) if (s) {
|
|
2861
|
+
let e = t.map((e) => e.string);
|
|
2862
|
+
this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
|
|
2863
|
+
for (let t of e) this.stdOut = t;
|
|
2864
|
+
} else {
|
|
2865
|
+
this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
|
|
2866
|
+
for (let t of M(i, e, this._inspectedWasm)) this.stdOut = t;
|
|
2867
|
+
}
|
|
2868
|
+
else a && !l ? (this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0, this.stdOut = `${i} (${e.name} ${e.version || "wasm"} wasm)`) : this.exitCode = 0;
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
async _fetchWasmBytes(e) {
|
|
2872
|
+
if (C.has(e)) return C.get(e);
|
|
2873
|
+
let n = t.fetch || (typeof fetch == "function" ? fetch : null);
|
|
2874
|
+
if (!n) throw Error("fetch is not available in this environment");
|
|
2875
|
+
let r = await n(e);
|
|
2876
|
+
if (!r || !r.ok) throw Error(`HTTP ${r ? r.status : "error"} fetching ${e}`);
|
|
2877
|
+
let i = new Uint8Array(await r.arrayBuffer());
|
|
2878
|
+
return C.set(e, i), i;
|
|
2879
|
+
}
|
|
2880
|
+
async _runRawWasmBytes(t, n) {
|
|
2881
|
+
let r = new S(i, n, this.context);
|
|
2882
|
+
r.script = i, r.arguments = n, r.context = this.context, r.fs = this.fs, r._pkgMeta = e, this.stdin !== void 0 && (r.stdin = this.stdin), await r._runWasm(t);
|
|
2883
|
+
for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
2884
|
+
this.exitCode = r.result.getExitCode();
|
|
2885
|
+
}
|
|
2886
|
+
_createIoBridge(e, t, n) {
|
|
2887
|
+
let r = (e) => ({ write(t) {
|
|
2888
|
+
(t instanceof Uint8Array ? new TextDecoder().decode(t) : String(t ?? "")).replace(/\r?\n$/, "").split(/\r?\n/).forEach((t) => e.push(t));
|
|
2889
|
+
} });
|
|
2890
|
+
return {
|
|
2891
|
+
binName: i,
|
|
2892
|
+
args: e,
|
|
2893
|
+
stdin: this.stdin !== void 0 && this.stdin !== null ? String(this.stdin) : "",
|
|
2894
|
+
fs: this.fs,
|
|
2895
|
+
context: this.context,
|
|
2896
|
+
stdout: Object.assign((e) => t.push(String(e)), r(t)),
|
|
2897
|
+
stderr: Object.assign((e) => n.push(String(e)), r(n)),
|
|
2898
|
+
readFile: (e, t) => {
|
|
2899
|
+
if (!this.fs) return null;
|
|
2900
|
+
let n = t && t !== "." && !e.startsWith("/") ? `${t.replace(/\/+$/, "")}/${e}` : e, r = this.fs.getFileByPath(n) ?? this.fs.getFileByPath(e);
|
|
2901
|
+
return r == null ? null : typeof r == "string" ? r : new TextDecoder().decode(r);
|
|
2902
|
+
},
|
|
2903
|
+
readBytes: (e) => D(this.fs, e),
|
|
2904
|
+
writeFile: (e, t, n) => {
|
|
2905
|
+
if (!this.fs) return;
|
|
2906
|
+
let r = n && n !== "." && !e.startsWith("/") ? `${n.replace(/\/+$/, "")}/${e}` : e;
|
|
2907
|
+
if (t instanceof Uint8Array || ArrayBuffer.isView(t)) {
|
|
2908
|
+
let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
|
|
2909
|
+
O(this.fs, r, t, e);
|
|
2910
|
+
} else this.fs.setFileByPath(r, String(t), !0);
|
|
2911
|
+
if (r.endsWith(".wasm") || r.endsWith(".wat")) try {
|
|
2912
|
+
this.context && this.context.fs ? this.context.fs.setMode(r, 493) : this.fs.setMode(r, 493);
|
|
2913
|
+
} catch {}
|
|
2914
|
+
},
|
|
2915
|
+
listFiles: (e, t) => {
|
|
2916
|
+
if (!this.fs) return [];
|
|
2917
|
+
let n = t && t !== "." && !e.startsWith("/") ? `${t.replace(/\/+$/, "")}/${e}` : e, r = this.fs.getFileByPath(n);
|
|
2918
|
+
return r && typeof r == "object" && !(r instanceof Uint8Array) ? Object.keys(r) : [];
|
|
2919
|
+
}
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2922
|
+
async _runFunctionOrEmscripten(e, t, n = !1) {
|
|
2923
|
+
let r = [], i = [], a = new TextEncoder().encode(this.stdin || ""), o = 0, s = /* @__PURE__ */ new Set(), c = {
|
|
2924
|
+
arguments: t,
|
|
2925
|
+
noInitialRun: !0,
|
|
2926
|
+
print: (e) => {
|
|
2927
|
+
r.push(String(e));
|
|
2928
|
+
},
|
|
2929
|
+
printErr: (e) => {
|
|
2930
|
+
i.push(String(e));
|
|
2931
|
+
},
|
|
2932
|
+
stdin: () => o < a.length ? a[o++] : null,
|
|
2933
|
+
preRun: [(e) => {
|
|
2934
|
+
e && e.FS && (s = this._syncBrshToEmscriptenFs(e.FS, t));
|
|
2935
|
+
}]
|
|
2936
|
+
}, l = this._createIoBridge(t, r, i), u;
|
|
2937
|
+
try {
|
|
2938
|
+
u = e.prototype && e.prototype.constructor === e && Object.getOwnPropertyNames(e.prototype).length > 1 ? new e(c, l) : await e(c, l);
|
|
2939
|
+
} catch (e) {
|
|
2940
|
+
if (e && typeof e.status == "number") this.exitCode = e.status;
|
|
2941
|
+
else throw e;
|
|
2942
|
+
}
|
|
2943
|
+
if (u && typeof u == "object") if (n && (u.wasmBinary instanceof Uint8Array || u.HEAPU8 instanceof Uint8Array) && (this._inspectedWasm = j(u.wasmBinary || u.HEAPU8)), typeof u.callMain == "function") {
|
|
2944
|
+
u.FS && s.size === 0 && (s = this._syncBrshToEmscriptenFs(u.FS, t));
|
|
2945
|
+
try {
|
|
2946
|
+
let e = await u.callMain(t);
|
|
2947
|
+
typeof e == "number" && e !== 0 && (this.exitCode = e);
|
|
2948
|
+
} catch (e) {
|
|
2949
|
+
e && typeof e.status == "number" ? this.exitCode = e.status : (i.push(e.message || String(e)), this.exitCode = 1);
|
|
2950
|
+
}
|
|
2951
|
+
u.FS && this._syncEmscriptenFsToBrsh(u.FS, t, s);
|
|
2952
|
+
} else if (typeof u.exec == "function" && typeof u.writeFile == "function") await this._runVirtualFsInstance(u, t, r, i);
|
|
2953
|
+
else if (typeof u.main == "function" || typeof u.run == "function") {
|
|
2954
|
+
let e = (u.main || u.run).bind(u);
|
|
2955
|
+
await this._invokeCliFunction(e, t, r, i);
|
|
2956
|
+
} else typeof u.stdout == "string" && u.stdout && u.stdout.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => r.push(e)), typeof u.stderr == "string" && u.stderr && u.stderr.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => i.push(e)), u.error && i.length === 0 && (i.push(u.error.message || String(u.error)), this.exitCode = 1), typeof u.exitCode == "number" && (this.exitCode = u.exitCode);
|
|
2957
|
+
else typeof u == "string" ? u.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => r.push(e)) : typeof u == "number" && (this.exitCode = u);
|
|
2958
|
+
r.forEach((e) => {
|
|
2959
|
+
this.stdOut = e;
|
|
2960
|
+
}), i.forEach((e) => {
|
|
2961
|
+
this.stdErr = e;
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
async _runVirtualFsInstance(t, n, r, i) {
|
|
2965
|
+
typeof t.on == "function" && t.on("log", ({ message: e }) => {
|
|
2966
|
+
e && r.push(e);
|
|
2967
|
+
}), !t.loaded && typeof t.load == "function" && await t.load(e.coreUrl ? { coreURL: e.coreUrl } : void 0);
|
|
2968
|
+
let a = /* @__PURE__ */ new Set(), o = [];
|
|
2969
|
+
for (let e of n) if (!e.startsWith("-") && (o.push(e), this.fs.exists(e))) {
|
|
2970
|
+
let n = D(this.fs, e);
|
|
2971
|
+
n && (await t.writeFile(e, n), a.add(e));
|
|
2972
|
+
}
|
|
2973
|
+
let s = await t.exec(n);
|
|
2974
|
+
for (let e of o) if (!a.has(e)) try {
|
|
2975
|
+
if (typeof t.readFile == "function") {
|
|
2976
|
+
let n = await t.readFile(e);
|
|
2977
|
+
n && O(this.fs, e, n);
|
|
2978
|
+
}
|
|
2979
|
+
} catch {}
|
|
2980
|
+
typeof s == "number" && s !== 0 && (this.exitCode = s, i.length === 0 && r.length > 0 && i.push(...r.splice(0, r.length)));
|
|
2981
|
+
}
|
|
2982
|
+
async _invokeCliFunction(e, t, n = null, r = null) {
|
|
2983
|
+
let i = n || [], a = r || [], o = await e(t, this._createIoBridge(t, i, a));
|
|
2984
|
+
typeof o == "string" ? o.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => i.push(e)) : typeof o == "number" ? this.exitCode = o : o && typeof o == "object" && (typeof o.stdout == "string" && o.stdout && o.stdout.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => i.push(e)), typeof o.stderr == "string" && o.stderr && o.stderr.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => a.push(e)), o.error ? (a.length === 0 && a.push(o.error.message || String(o.error)), this.exitCode = typeof o.exitCode == "number" ? o.exitCode : 1) : typeof o.exitCode == "number" && (this.exitCode = o.exitCode)), n || (i.forEach((e) => {
|
|
2985
|
+
this.stdOut = e;
|
|
2986
|
+
}), a.forEach((e) => {
|
|
2987
|
+
this.stdErr = e;
|
|
2988
|
+
}));
|
|
2989
|
+
}
|
|
2990
|
+
_syncBrshToEmscriptenFs(e, t) {
|
|
2991
|
+
let n = /* @__PURE__ */ new Set();
|
|
2992
|
+
if (!this.fs || !e || typeof e.writeFile != "function") return n;
|
|
2993
|
+
for (let r of t) if (!r.startsWith("-") && this.fs.exists(r)) {
|
|
2994
|
+
let t = D(this.fs, r);
|
|
2995
|
+
if (t) try {
|
|
2996
|
+
e.writeFile(r, t), n.add(r);
|
|
2997
|
+
} catch {}
|
|
2998
|
+
}
|
|
2999
|
+
return n;
|
|
3000
|
+
}
|
|
3001
|
+
_syncEmscriptenFsToBrsh(e, t, n) {
|
|
3002
|
+
if (!(!this.fs || !e || typeof e.readFile != "function")) {
|
|
3003
|
+
for (let r of t) if (!(r.startsWith("-") || n.has(r))) try {
|
|
3004
|
+
let t = e.readFile(r);
|
|
3005
|
+
if (t) {
|
|
3006
|
+
let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
|
|
3007
|
+
if (O(this.fs, r, t, e), r.endsWith(".wasm") || r.endsWith(".wat")) try {
|
|
3008
|
+
this.context && this.context.fs ? this.context.fs.setMode(r, 493) : this.fs.setMode(r, 493);
|
|
3009
|
+
} catch {}
|
|
3010
|
+
}
|
|
3011
|
+
} catch {}
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
return a;
|
|
3016
|
+
}
|
|
3017
|
+
S.readBytesFromFs = D, S.writeBytesToFs = O, S.loadModule = k, S.extractHelpFromText = A, S.inspectWasmBytes = j, S.formatWasmHelp = M, S.createGenericWasmCommand = N, S.createCommand = N, t.exports = S;
|
|
3018
|
+
})), X = /* @__PURE__ */ t(((e, t) => {
|
|
3019
|
+
var n = ne(), { createGenericWasmCommand: r } = Y(), i = "\x1B[2J\x1B[H", a = "\x1B[0m", o = "\x1B[7m", s = "\x1B[1m", c = "\x1B[2m", l = "\x1B[36m", u = "\x1B[31m", d = "\x1B[32m", f = class extends n {
|
|
3020
|
+
get requiresFilesystem() {
|
|
3021
|
+
return !0;
|
|
3022
|
+
}
|
|
3023
|
+
get interactive() {
|
|
3024
|
+
return this.shouldBeInteractive();
|
|
3025
|
+
}
|
|
3026
|
+
get captureInput() {
|
|
3027
|
+
return this.shouldBeInteractive();
|
|
3028
|
+
}
|
|
3029
|
+
shouldBeInteractive() {
|
|
3030
|
+
return !!this._dynamicReplActive;
|
|
3031
|
+
}
|
|
3032
|
+
getReplTitle() {
|
|
3033
|
+
return this._dynamicReplOpts && this._dynamicReplOpts.title || `${this.name} interactive shell`;
|
|
3034
|
+
}
|
|
3035
|
+
getReplPrompt() {
|
|
3036
|
+
return this._dynamicReplMultiline && this._dynamicReplOpts && this._dynamicReplOpts.continuePrompt ? this._dynamicReplOpts.continuePrompt : this._dynamicReplOpts && this._dynamicReplOpts.prompt || `${this.name}> `;
|
|
3037
|
+
}
|
|
3038
|
+
getReplWelcome() {
|
|
3039
|
+
return this._dynamicReplOpts && this._dynamicReplOpts.banner || [`Welcome to ${this.name}. Type .exit or Ctrl+D to quit.`];
|
|
3040
|
+
}
|
|
3041
|
+
async initRepl() {}
|
|
3042
|
+
async evaluateReplLine(e) {
|
|
3043
|
+
if (this._dynamicReplOpts && typeof this._dynamicReplOpts.onEvaluate == "function") {
|
|
3044
|
+
let t = await this._dynamicReplOpts.onEvaluate(e);
|
|
3045
|
+
return { output: Array.isArray(t) ? t : t == null ? [] : [String(t)] };
|
|
3046
|
+
}
|
|
3047
|
+
return { output: [] };
|
|
3048
|
+
}
|
|
3049
|
+
async cleanupRepl() {
|
|
3050
|
+
this._dynamicReplOpts && typeof this._dynamicReplOpts.onClose == "function" && await this._dynamicReplOpts.onClose();
|
|
3051
|
+
}
|
|
3052
|
+
async runNonInteractive() {}
|
|
3053
|
+
startRepl(e = {}) {
|
|
3054
|
+
return this._dynamicReplActive = !0, this._dynamicReplOpts = e, this._dynamicReplBuffer = "", this._dynamicReplMultiline = !1, this._launchInteractiveReplLoop();
|
|
3055
|
+
}
|
|
3056
|
+
run() {
|
|
3057
|
+
return this.shouldBeInteractive() ? this._launchInteractiveReplLoop() : Promise.resolve(this.runNonInteractive());
|
|
3058
|
+
}
|
|
3059
|
+
_launchInteractiveReplLoop() {
|
|
3060
|
+
return this._replHistory = [], this._replHistoryIdx = null, this._replInput = "", this._replCursor = 0, this._replLog = [], this._replBusy = !0, this._replStatus = "Initializing WASM runtime...", this._scrollOffset = 0, this._renderRepl(), new Promise((e) => {
|
|
3061
|
+
this._replResolve = e, Promise.resolve().then(() => this.initRepl()).then(() => {
|
|
3062
|
+
this._replBusy = !1, this._replStatus = "^D / .exit: Quit | ^L: Clear | Up/Down: History";
|
|
3063
|
+
for (let e of this.getReplWelcome()) this._appendReplLog(e, "info");
|
|
3064
|
+
this._renderRepl();
|
|
3065
|
+
}).catch((e) => {
|
|
3066
|
+
this._replBusy = !1, this.stdErr = e.message || String(e), this.exitCode = 1, this._exitRepl();
|
|
3067
|
+
});
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
_appendReplLog(e, t = "out") {
|
|
3071
|
+
let n = String(e ?? "").split(/\r?\n/);
|
|
3072
|
+
for (let e of n) this._replLog.push({
|
|
3073
|
+
text: e,
|
|
3074
|
+
type: t
|
|
3075
|
+
});
|
|
3076
|
+
this._scrollOffset = 0;
|
|
3077
|
+
}
|
|
3078
|
+
onInput(e) {
|
|
3079
|
+
if (this.shouldBeInteractive()) {
|
|
3080
|
+
if (e === "^D" || e === "^X") {
|
|
3081
|
+
this._exitRepl();
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
if (e === "^C") {
|
|
3085
|
+
this._replInput.length > 0 || this._dynamicReplBuffer ? (this._appendReplLog(`${this.getReplPrompt()}${this._replInput}^C`, "prompt"), this._replInput = "", this._replCursor = 0, this._dynamicReplBuffer = "", this._dynamicReplMultiline = !1, this._renderRepl()) : this._exitRepl();
|
|
3086
|
+
return;
|
|
3087
|
+
}
|
|
3088
|
+
if (!this._replBusy) {
|
|
3089
|
+
if (e === "^L") {
|
|
3090
|
+
this._replLog = [], this._scrollOffset = 0, this._renderRepl();
|
|
3091
|
+
return;
|
|
3092
|
+
}
|
|
3093
|
+
if (e === "Enter") {
|
|
3094
|
+
let e = this._replInput;
|
|
3095
|
+
this._replInput = "", this._replCursor = 0, this._replHistoryIdx = null, e.trim() && this._replHistory.push(e), this._appendReplLog(`${this.getReplPrompt()}${e}`, "prompt");
|
|
3096
|
+
let t = e.trim();
|
|
3097
|
+
if (this._dynamicReplOpts && typeof this._dynamicReplOpts.isExitCommand == "function" && this._dynamicReplOpts.isExitCommand(t) || t === ".exit" || t === ".quit" || t === "\\q" || t === "exit" || t === "quit" || t === "exit()" || t === "quit()") {
|
|
3098
|
+
this._exitRepl();
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
if (t === ".clear" || t === "\\! clear") {
|
|
3102
|
+
this._replLog = [], this._renderRepl();
|
|
3103
|
+
return;
|
|
3104
|
+
}
|
|
3105
|
+
if (this._dynamicReplOpts && typeof this._dynamicReplOpts.needsMoreInput == "function" && (this._dynamicReplBuffer = this._dynamicReplBuffer ? `${this._dynamicReplBuffer}\n${e}` : e, this._dynamicReplOpts.needsMoreInput(this._dynamicReplBuffer))) {
|
|
3106
|
+
this._dynamicReplMultiline = !0, this._renderRepl();
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
let n = this._dynamicReplBuffer || e;
|
|
3110
|
+
this._dynamicReplBuffer = "", this._dynamicReplMultiline = !1, this._replBusy = !0, this._replStatus = "Running...", this._renderRepl(), Promise.resolve().then(() => this.evaluateReplLine(n)).then((e) => {
|
|
3111
|
+
if (this._replBusy = !1, this._replStatus = "^D / .exit: Quit | ^L: Clear | Up/Down: History", e) {
|
|
3112
|
+
if (e.clear && (this._replLog = []), Array.isArray(e.output)) for (let t of e.output) this._appendReplLog(t, "out");
|
|
3113
|
+
else typeof e.output == "string" && e.output.length > 0 && this._appendReplLog(e.output, "out");
|
|
3114
|
+
if (e.error && this._appendReplLog(e.error, "err"), e.exit) {
|
|
3115
|
+
this._exitRepl();
|
|
3116
|
+
return;
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
this._renderRepl();
|
|
3120
|
+
}).catch((e) => {
|
|
3121
|
+
this._replBusy = !1, this._replStatus = "^D / .exit: Quit | ^L: Clear | Up/Down: History", this._appendReplLog(`Error: ${e.message || e}`, "err"), this._renderRepl();
|
|
3122
|
+
});
|
|
3123
|
+
return;
|
|
3124
|
+
}
|
|
3125
|
+
if (e === "Backspace") {
|
|
3126
|
+
this._replCursor > 0 && (this._replInput = this._replInput.slice(0, this._replCursor - 1) + this._replInput.slice(this._replCursor), this._replCursor--, this._renderRepl());
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
if (e === "Delete") {
|
|
3130
|
+
this._replCursor < this._replInput.length && (this._replInput = this._replInput.slice(0, this._replCursor) + this._replInput.slice(this._replCursor + 1), this._renderRepl());
|
|
3131
|
+
return;
|
|
3132
|
+
}
|
|
3133
|
+
if (e === "ArrowLeft") {
|
|
3134
|
+
this._replCursor > 0 && (this._replCursor--, this._renderRepl());
|
|
3135
|
+
return;
|
|
3136
|
+
}
|
|
3137
|
+
if (e === "ArrowRight") {
|
|
3138
|
+
this._replCursor < this._replInput.length && (this._replCursor++, this._renderRepl());
|
|
3139
|
+
return;
|
|
3140
|
+
}
|
|
3141
|
+
if (e === "Home" || e === "^A") {
|
|
3142
|
+
this._replCursor = 0, this._renderRepl();
|
|
3143
|
+
return;
|
|
3144
|
+
}
|
|
3145
|
+
if (e === "End" || e === "^E") {
|
|
3146
|
+
this._replCursor = this._replInput.length, this._renderRepl();
|
|
3147
|
+
return;
|
|
3148
|
+
}
|
|
3149
|
+
if (e === "ArrowUp") {
|
|
3150
|
+
if (this._replHistory.length === 0) return;
|
|
3151
|
+
this._replHistoryIdx === null ? this._replHistoryIdx = this._replHistory.length - 1 : this._replHistoryIdx > 0 && this._replHistoryIdx--, this._replInput = this._replHistory[this._replHistoryIdx], this._replCursor = this._replInput.length, this._renderRepl();
|
|
3152
|
+
return;
|
|
3153
|
+
}
|
|
3154
|
+
if (e === "ArrowDown") {
|
|
3155
|
+
if (this._replHistoryIdx === null) return;
|
|
3156
|
+
this._replHistoryIdx < this._replHistory.length - 1 ? (this._replHistoryIdx++, this._replInput = this._replHistory[this._replHistoryIdx]) : (this._replHistoryIdx = null, this._replInput = ""), this._replCursor = this._replInput.length, this._renderRepl();
|
|
3157
|
+
return;
|
|
3158
|
+
}
|
|
3159
|
+
if (e === "PageUp") {
|
|
3160
|
+
let e = Math.max(0, this._replLog.length - 5);
|
|
3161
|
+
this._scrollOffset = Math.min(e, this._scrollOffset + 5), this._renderRepl();
|
|
3162
|
+
return;
|
|
3163
|
+
}
|
|
3164
|
+
if (e === "PageDown") {
|
|
3165
|
+
this._scrollOffset = Math.max(0, this._scrollOffset - 5), this._renderRepl();
|
|
3166
|
+
return;
|
|
3167
|
+
}
|
|
3168
|
+
e.length === 1 && !e.startsWith("^") && (this._replInput = this._replInput.slice(0, this._replCursor) + e + this._replInput.slice(this._replCursor), this._replCursor++, this._renderRepl());
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
_renderRepl() {
|
|
3173
|
+
let { cols: e, rows: t } = this.terminalSize, n = Math.max(3, t - 3), r = `${o}${s}${` ${this.getReplTitle()} `.padEnd(e).slice(0, e)}${a}`, f = this._replLog.length, p = Math.max(0, f - this._scrollOffset), m = Math.max(0, p - n), h = this._replLog.slice(m, p), g = [];
|
|
3174
|
+
for (let e = 0; e < n; e++) {
|
|
3175
|
+
let t = h[e];
|
|
3176
|
+
if (!t) {
|
|
3177
|
+
g.push("");
|
|
3178
|
+
continue;
|
|
3179
|
+
}
|
|
3180
|
+
t.type === "prompt" ? g.push(`${l}${t.text}${a}`) : t.type === "err" ? g.push(`${u}${t.text}${a}`) : t.type === "info" ? g.push(`${c}${t.text}${a}`) : g.push(t.text);
|
|
3181
|
+
}
|
|
3182
|
+
let _ = this.getReplPrompt(), v = this._replInput.slice(0, this._replCursor), y = this._replCursor < this._replInput.length ? this._replInput[this._replCursor] : " ", b = this._replCursor < this._replInput.length ? this._replInput.slice(this._replCursor + 1) : "", x = this._replBusy ? `${c}${this._replStatus}${a}` : `${d}${s}${_}${a}${v}${o}${y}${a}${b}`, S = `${o}${` ${this._replStatus} `.padEnd(e).slice(0, e)}${a}`, C = [
|
|
3183
|
+
i + r,
|
|
3184
|
+
...g,
|
|
3185
|
+
x,
|
|
3186
|
+
S
|
|
3187
|
+
].join("\n");
|
|
3188
|
+
this.stdOut = C, this.flush();
|
|
3189
|
+
}
|
|
3190
|
+
_exitRepl() {
|
|
3191
|
+
Promise.resolve().then(() => this.cleanupRepl()).catch(() => {}).finally(() => {
|
|
3192
|
+
if (this._replResolve) {
|
|
3193
|
+
let e = this._replResolve;
|
|
3194
|
+
this._replResolve = null, e();
|
|
3195
|
+
}
|
|
3196
|
+
});
|
|
3197
|
+
}
|
|
3198
|
+
};
|
|
3199
|
+
function p(e, t = {}, n = null) {
|
|
3200
|
+
let i = (n || e.bin || e.name).toLowerCase(), a = r(e, t, i), o = e && typeof e.repl == "object" ? e.repl : {};
|
|
3201
|
+
class s extends f {
|
|
3202
|
+
static get name() {
|
|
3203
|
+
return i;
|
|
3204
|
+
}
|
|
3205
|
+
get name() {
|
|
3206
|
+
return i;
|
|
3207
|
+
}
|
|
3208
|
+
constructor(e, t) {
|
|
3209
|
+
super(e, t), this._sessionArgs = [], this._isInteractiveMode = this._detectInteractiveMode(e || []);
|
|
3210
|
+
}
|
|
3211
|
+
_detectInteractiveMode(e) {
|
|
3212
|
+
if (e.includes("--help") || e.includes("-h") || e.includes("--version") || e.includes("-V") || e.includes("-v")) return !1;
|
|
3213
|
+
if (e.length === 0) return !0;
|
|
3214
|
+
if (o.sessionArg && e.length === 1 && !e[0].startsWith("-")) {
|
|
3215
|
+
let t = e[0].trim();
|
|
3216
|
+
if (!/^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|PRAGMA|WITH|BEGIN|EXPLAIN|\.)\b/i.test(t)) return this._sessionArgs = [e[0]], !0;
|
|
3217
|
+
}
|
|
3218
|
+
return !1;
|
|
3219
|
+
}
|
|
3220
|
+
shouldBeInteractive() {
|
|
3221
|
+
return this._dynamicReplActive ? !0 : this.stdin !== void 0 && this.stdin !== null && String(this.stdin).trim().length > 0 ? !1 : this._isInteractiveMode;
|
|
3222
|
+
}
|
|
3223
|
+
getReplTitle() {
|
|
3224
|
+
let t = this._sessionArgs.length > 0 ? ` — ${this._sessionArgs.join(" ")}` : "";
|
|
3225
|
+
return o.title || `${i} (${e.name} ${e.version || "wasm"})${t}`;
|
|
3226
|
+
}
|
|
3227
|
+
getReplPrompt() {
|
|
3228
|
+
return this._dynamicReplMultiline && o.continuePrompt ? o.continuePrompt : o.prompt || `${i}> `;
|
|
3229
|
+
}
|
|
3230
|
+
getReplWelcome() {
|
|
3231
|
+
return o.banner || [`${e.name} (${e.version || "wasm"}) interactive shell`, "Type \".exit\" or Ctrl+D to quit."];
|
|
3232
|
+
}
|
|
3233
|
+
async evaluateReplLine(e) {
|
|
3234
|
+
let t = o.evalFlag, n = t ? [
|
|
3235
|
+
...this._sessionArgs,
|
|
3236
|
+
t,
|
|
3237
|
+
e
|
|
3238
|
+
] : [...this._sessionArgs, e], r = t ? void 0 : e, { out: i, err: a } = await this._captureBaseWasmOutput(n, r);
|
|
3239
|
+
return {
|
|
3240
|
+
output: i,
|
|
3241
|
+
error: a.length > 0 ? a.join("\n") : void 0
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
3244
|
+
async runNonInteractive() {
|
|
3245
|
+
await this._delegateToBaseWasm([...this.arguments || []]);
|
|
3246
|
+
}
|
|
3247
|
+
async _delegateToBaseWasm(e) {
|
|
3248
|
+
let t = new a(e, this.context);
|
|
3249
|
+
t.fs = this.fs, this.stdin !== void 0 && (t.stdin = this.stdin), await t.run();
|
|
3250
|
+
for (let e of t.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
3251
|
+
this.exitCode = t.exitCode || t.result.getExitCode();
|
|
3252
|
+
}
|
|
3253
|
+
async _captureBaseWasmOutput(e, t) {
|
|
3254
|
+
let n = new a(e, this.context);
|
|
3255
|
+
n.fs = this.fs, t !== void 0 && (n.stdin = t), await n.run();
|
|
3256
|
+
let r = [], i = [];
|
|
3257
|
+
for (let e of n.result.getStdOutput()) e.type === "err" ? i.push(e.string) : r.push(e.string);
|
|
3258
|
+
return {
|
|
3259
|
+
out: r,
|
|
3260
|
+
err: i
|
|
3261
|
+
};
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
return s;
|
|
3265
|
+
}
|
|
3266
|
+
f.createReplWasmCommand = p, f.createCommand = p, t.exports = f;
|
|
3267
|
+
})), Z = /* @__PURE__ */ t(((e, t) => {
|
|
3268
|
+
var n = {
|
|
3269
|
+
sqlite3: {
|
|
3270
|
+
name: "sqlite3",
|
|
3271
|
+
bin: "sqlite3",
|
|
3272
|
+
aliases: ["sqlite"],
|
|
3273
|
+
version: "1.13.0",
|
|
3274
|
+
description: "SQLite compiled to WebAssembly (via sql.js) with filesystem persistence",
|
|
3275
|
+
details: "SQLite3 WASM allows creating, querying, and modifying SQLite database files directly in the brsh filesystem. Supports interactive SQL shell, piped SQL input, and one-shot queries.",
|
|
3276
|
+
homepage: "https://sql.js.org",
|
|
3277
|
+
cdnUrl: "https://esm.sh/sql.js@1.13.0",
|
|
3278
|
+
wasmUrl: "https://cdn.jsdelivr.net/npm/sql.js@1.13.0/dist/sql-wasm.wasm",
|
|
3279
|
+
type: "generic-runtime",
|
|
3280
|
+
repl: {
|
|
3281
|
+
prompt: "sqlite> ",
|
|
3282
|
+
sessionArg: !0
|
|
3283
|
+
},
|
|
3284
|
+
size: "680 KB"
|
|
3285
|
+
},
|
|
3286
|
+
assemblyscript: {
|
|
3287
|
+
name: "assemblyscript",
|
|
3288
|
+
bin: "asc",
|
|
3289
|
+
aliases: [
|
|
3290
|
+
"asrun",
|
|
3291
|
+
"asnode",
|
|
3292
|
+
"assemblyscript"
|
|
3293
|
+
],
|
|
3294
|
+
version: "0.27.31",
|
|
3295
|
+
description: "AssemblyScript compiler (asc) and JIT/AOT runtime runner (asrun / asnode)",
|
|
3296
|
+
details: "AssemblyScript compiles a strict variant of TypeScript to WebAssembly. Includes `asc` (ahead-of-time compiler to .wasm/.wat) and `asrun` / `asnode`.",
|
|
3297
|
+
homepage: "https://www.assemblyscript.org",
|
|
3298
|
+
cdnUrl: "https://esm.sh/assemblyscript@0.27.31/asc",
|
|
3299
|
+
type: "generic-runtime",
|
|
3300
|
+
repl: {
|
|
3301
|
+
prompt: "as> ",
|
|
3302
|
+
evalFlag: "-e"
|
|
3303
|
+
},
|
|
3304
|
+
size: "1.4 MB"
|
|
3305
|
+
},
|
|
3306
|
+
jq: {
|
|
3307
|
+
name: "jq",
|
|
3308
|
+
bin: "jq",
|
|
3309
|
+
aliases: [],
|
|
3310
|
+
version: "1.7.1",
|
|
3311
|
+
description: "Command-line JSON processor compiled to WebAssembly (jq-web)",
|
|
3312
|
+
details: "jq is like sed for JSON data — you can use it to slice, filter, map, and transform structured JSON data from files or piped standard input.",
|
|
3313
|
+
homepage: "https://jqlang.github.io/jq/",
|
|
3314
|
+
cdnUrl: "https://esm.sh/jq-web@0.5.3",
|
|
3315
|
+
type: "generic-runtime",
|
|
3316
|
+
size: "620 KB"
|
|
3317
|
+
},
|
|
3318
|
+
python3: {
|
|
3319
|
+
name: "python3",
|
|
3320
|
+
bin: "python3",
|
|
3321
|
+
aliases: ["python", "py"],
|
|
3322
|
+
version: "3.12.1",
|
|
3323
|
+
description: "CPython 3.12 compiled to WebAssembly (via Pyodide)",
|
|
3324
|
+
details: "Full Python 3.12 runtime in WebAssembly powered by Pyodide. Supports interactive Python REPL (`>>>`), running `.py` scripts from the brsh filesystem, `-c` inline code evaluation, and piped standard input.",
|
|
3325
|
+
homepage: "https://pyodide.org",
|
|
3326
|
+
cdnUrl: "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.mjs",
|
|
3327
|
+
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/",
|
|
3328
|
+
type: "generic-runtime",
|
|
3329
|
+
repl: {
|
|
3330
|
+
prompt: ">>> ",
|
|
3331
|
+
evalFlag: "-c"
|
|
3332
|
+
},
|
|
3333
|
+
size: "6.4 MB"
|
|
3334
|
+
},
|
|
3335
|
+
duckdb: {
|
|
3336
|
+
name: "duckdb",
|
|
3337
|
+
bin: "duckdb",
|
|
3338
|
+
aliases: [],
|
|
3339
|
+
version: "1.29.0",
|
|
3340
|
+
description: "In-process analytical SQL OLAP database compiled to WebAssembly",
|
|
3341
|
+
details: "DuckDB-WASM executes analytical SQL queries directly in WebAssembly, including querying CSV and JSON files stored in the brsh filesystem, interactive SQL shell, and one-shot / piped queries.",
|
|
3342
|
+
homepage: "https://duckdb.org",
|
|
3343
|
+
cdnUrl: "https://esm.sh/@duckdb/duckdb-wasm@1.29.0",
|
|
3344
|
+
type: "generic-runtime",
|
|
3345
|
+
repl: {
|
|
3346
|
+
prompt: "D ",
|
|
3347
|
+
continuePrompt: " > ",
|
|
3348
|
+
evalFlag: "-c"
|
|
3349
|
+
},
|
|
3350
|
+
size: "4.2 MB"
|
|
3351
|
+
},
|
|
3352
|
+
graphviz: {
|
|
3353
|
+
name: "graphviz",
|
|
3354
|
+
bin: "dot",
|
|
3355
|
+
aliases: ["graphviz"],
|
|
3356
|
+
version: "1.13.0",
|
|
3357
|
+
description: "Graphviz graph visualization compiler (`dot`) compiled to WebAssembly",
|
|
3358
|
+
details: "Powered by @hpcc-js/wasm-graphviz. Compiles DOT language graph descriptions (`.dot` / `.gv`) into SVG, DOT, canon, or JSON formats (`dot -Tsvg input.dot -o output.svg`).",
|
|
3359
|
+
homepage: "https://graphviz.org",
|
|
3360
|
+
cdnUrl: "https://esm.sh/@hpcc-js/wasm-graphviz@1.13.0",
|
|
3361
|
+
type: "generic-runtime",
|
|
3362
|
+
size: "1.1 MB"
|
|
3363
|
+
},
|
|
3364
|
+
ffmpeg: {
|
|
3365
|
+
name: "ffmpeg",
|
|
3366
|
+
bin: "ffmpeg",
|
|
3367
|
+
aliases: [],
|
|
3368
|
+
version: "0.12.10",
|
|
3369
|
+
description: "FFmpeg multimedia framework compiled to WebAssembly (@ffmpeg/ffmpeg)",
|
|
3370
|
+
details: "Record, convert, transcode, and inspect audio, video, and image files directly inside the brsh filesystem using WebAssembly (`ffmpeg -i input.mp4 output.webm`).",
|
|
3371
|
+
homepage: "https://ffmpegwasm.netlify.app",
|
|
3372
|
+
cdnUrl: "https://esm.sh/@ffmpeg/ffmpeg@0.12.10",
|
|
3373
|
+
coreUrl: "https://unpkg.com/@ffmpeg/core@0.12.6/dist/esm/ffmpeg-core.js",
|
|
3374
|
+
type: "generic-runtime",
|
|
3375
|
+
size: "8.5 MB"
|
|
3376
|
+
},
|
|
3377
|
+
wabt: {
|
|
3378
|
+
name: "wabt",
|
|
3379
|
+
bin: "wat2wasm",
|
|
3380
|
+
aliases: ["wasm2wat"],
|
|
3381
|
+
version: "1.0.36",
|
|
3382
|
+
description: "WebAssembly Binary Toolkit (wat2wasm & wasm2wat)",
|
|
3383
|
+
details: "WABT provides tools for translating between WebAssembly Text Format (.wat) and the WebAssembly binary format (.wasm), as well as inspecting WASM modules.",
|
|
3384
|
+
homepage: "https://github.com/WebAssembly/wabt",
|
|
3385
|
+
cdnUrl: "https://esm.sh/wabt@1.0.36",
|
|
3386
|
+
type: "generic-runtime",
|
|
3387
|
+
size: "540 KB"
|
|
3388
|
+
},
|
|
3389
|
+
quickjs: {
|
|
3390
|
+
name: "quickjs",
|
|
3391
|
+
bin: "qjs",
|
|
3392
|
+
aliases: ["quickjs"],
|
|
3393
|
+
version: "0.31.0",
|
|
3394
|
+
description: "Sandboxed QuickJS JavaScript engine compiled to WebAssembly",
|
|
3395
|
+
details: "QuickJS is a small and embeddable Javascript engine supporting ES2023. Runs JS code and files inside an isolated WebAssembly sandbox.",
|
|
3396
|
+
homepage: "https://bellard.org/quickjs/",
|
|
3397
|
+
cdnUrl: "https://esm.sh/quickjs-emscripten@0.31.0",
|
|
3398
|
+
type: "generic-runtime",
|
|
3399
|
+
repl: {
|
|
3400
|
+
prompt: "qjs > ",
|
|
3401
|
+
evalFlag: "-e"
|
|
3402
|
+
},
|
|
3403
|
+
size: "820 KB"
|
|
3404
|
+
},
|
|
3405
|
+
lua: {
|
|
3406
|
+
name: "lua",
|
|
3407
|
+
bin: "lua",
|
|
3408
|
+
aliases: [],
|
|
3409
|
+
version: "5.4.6",
|
|
3410
|
+
description: "Lua 5.4 interpreter compiled to WebAssembly (via wasmoon)",
|
|
3411
|
+
details: "Full Lua 5.4 virtual machine compiled to WebAssembly. Supports interactive REPL, script execution from the brsh filesystem, and `-e` one-liners.",
|
|
3412
|
+
homepage: "https://www.lua.org",
|
|
3413
|
+
cdnUrl: "https://esm.sh/wasmoon@1.16.0",
|
|
3414
|
+
type: "generic-runtime",
|
|
3415
|
+
repl: {
|
|
3416
|
+
prompt: "lua> ",
|
|
3417
|
+
evalFlag: "-e"
|
|
3418
|
+
},
|
|
3419
|
+
size: "410 KB"
|
|
3420
|
+
},
|
|
3421
|
+
wllama: {
|
|
3422
|
+
name: "wllama",
|
|
3423
|
+
bin: "wllama",
|
|
3424
|
+
aliases: ["llama", "llama-cli"],
|
|
3425
|
+
version: "3.8.1",
|
|
3426
|
+
description: "WebAssembly & WebGPU LLM inference engine powered by llama.cpp (@wllama/wllama)",
|
|
3427
|
+
details: "Wllama v3 runs GGUF large language models in WebAssembly with automatic WebGPU hardware acceleration. Supports one-shot chat/text completions, interactive chat REPL, model inspection, embeddings, benchmarks, and Hugging Face & local filesystem GGUF loading.",
|
|
3428
|
+
homepage: "https://github.com/ngxson/wllama",
|
|
3429
|
+
cdnUrl: "https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/esm/index.js",
|
|
3430
|
+
wasmUrl: "https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/src/wasm/wllama.wasm",
|
|
3431
|
+
type: "builtin-adapter",
|
|
3432
|
+
adapter: "wllama",
|
|
3433
|
+
size: "8.8 MB"
|
|
3434
|
+
}
|
|
3435
|
+
}, r = {
|
|
3436
|
+
sqlite: "sqlite3",
|
|
3437
|
+
"sqlite-wasm": "sqlite3",
|
|
3438
|
+
asc: "assemblyscript",
|
|
3439
|
+
asrun: "assemblyscript",
|
|
3440
|
+
asnode: "assemblyscript",
|
|
3441
|
+
python: "python3",
|
|
3442
|
+
py: "python3",
|
|
3443
|
+
pyodide: "python3",
|
|
3444
|
+
dot: "graphviz",
|
|
3445
|
+
wat2wasm: "wabt",
|
|
3446
|
+
wasm2wat: "wabt",
|
|
3447
|
+
qjs: "quickjs",
|
|
3448
|
+
llama: "wllama",
|
|
3449
|
+
"llama-cli": "wllama",
|
|
3450
|
+
"llama.cpp": "wllama",
|
|
3451
|
+
"@wllama/wllama": "wllama"
|
|
3452
|
+
};
|
|
3453
|
+
function i(e) {
|
|
3454
|
+
if (!e) return null;
|
|
3455
|
+
let t = e.toLowerCase().replace(/^(npm|esm):/i, "").replace(/@[\d.^~><=*]+$/, "");
|
|
3456
|
+
return r[t] || t;
|
|
3457
|
+
}
|
|
3458
|
+
t.exports = {
|
|
3459
|
+
DEFAULT_REGISTRY: n,
|
|
3460
|
+
PACKAGE_ALIASES: r,
|
|
3461
|
+
resolvePackageName: i
|
|
3462
|
+
};
|
|
3463
|
+
})), ie = /* @__PURE__ */ t(((e, t) => {
|
|
3464
|
+
function n(e, t, n = {}) {
|
|
3465
|
+
let { showRowCount: r = !0 } = n;
|
|
3466
|
+
if (!e || e.length === 0) return [];
|
|
3467
|
+
let i = e.map((e) => String(e)), a = i.map((e) => e.length), o = (t || []).map((e) => i.map((t, n) => {
|
|
3468
|
+
let r = Array.isArray(e) ? e[n] : e[t], i = r == null ? "NULL" : String(r);
|
|
3469
|
+
return i.length > a[n] && (a[n] = i.length), i;
|
|
3470
|
+
})), s = [], c = i.map((e, t) => " " + e.padEnd(a[t]) + " ").join("|"), l = a.map((e) => "-".repeat(e + 2)).join("+");
|
|
3471
|
+
s.push(c), s.push(l);
|
|
3472
|
+
for (let e of o) s.push(e.map((e, t) => " " + e.padEnd(a[t]) + " ").join("|"));
|
|
3473
|
+
return r && s.push(`(${o.length} row${o.length === 1 ? "" : "s"})`), s;
|
|
3474
|
+
}
|
|
3475
|
+
function r(e, t, n = !1) {
|
|
3476
|
+
let r = [], i = (e || []).map((e) => String(e));
|
|
3477
|
+
n && i.length > 0 && r.push(i.join("|"));
|
|
3478
|
+
for (let e of t || []) {
|
|
3479
|
+
let t = i.map((t, n) => {
|
|
3480
|
+
let r = Array.isArray(e) ? e[n] : e[t];
|
|
3481
|
+
return r == null ? "" : String(r);
|
|
3482
|
+
});
|
|
3483
|
+
r.push(t.join("|"));
|
|
3484
|
+
}
|
|
3485
|
+
return r;
|
|
3486
|
+
}
|
|
3487
|
+
function i(e, t, n = !0) {
|
|
3488
|
+
let r = (e) => {
|
|
3489
|
+
let t = e == null ? "" : String(e);
|
|
3490
|
+
return /[",\r\n]/.test(t) ? "\"" + t.replace(/"/g, "\"\"") + "\"" : t;
|
|
3491
|
+
}, i = [], a = (e || []).map((e) => String(e));
|
|
3492
|
+
n && a.length > 0 && i.push(a.map(r).join(","));
|
|
3493
|
+
for (let e of t || []) {
|
|
3494
|
+
let t = a.map((t, n) => r(Array.isArray(e) ? e[n] : e[t]));
|
|
3495
|
+
i.push(t.join(","));
|
|
3496
|
+
}
|
|
3497
|
+
return i;
|
|
3498
|
+
}
|
|
3499
|
+
var { readBytesFromFs: a, writeBytesToFs: o, loadModule: s, extractHelpFromText: c, inspectWasmBytes: l, formatWasmHelp: u } = Y();
|
|
3500
|
+
t.exports = {
|
|
3501
|
+
formatTable: n,
|
|
3502
|
+
formatPipeList: r,
|
|
3503
|
+
formatCsv: i,
|
|
3504
|
+
readBytesFromFs: a,
|
|
3505
|
+
writeBytesToFs: o,
|
|
3506
|
+
loadModule: s,
|
|
3507
|
+
extractHelpFromText: c,
|
|
3508
|
+
inspectWasmBytes: l,
|
|
3509
|
+
formatWasmHelp: u
|
|
3510
|
+
};
|
|
3511
|
+
})), ae = /* @__PURE__ */ t(((e, t) => {
|
|
3512
|
+
var r = s(), i = Y(), a = X(), { DEFAULT_REGISTRY: o, resolvePackageName: c } = Z(), { writeBytesToFs: l, createGenericWasmCommand: u } = i, { createReplWasmCommand: d } = a, f = "/var/lib/wbt/installed.json", p = "/var/cache/wbt";
|
|
3513
|
+
function m(e, t, n = {}) {
|
|
3514
|
+
class r extends i {
|
|
3515
|
+
static get name() {
|
|
3516
|
+
return e;
|
|
3517
|
+
}
|
|
3518
|
+
get name() {
|
|
3519
|
+
return e;
|
|
3520
|
+
}
|
|
3521
|
+
constructor(e, r) {
|
|
3522
|
+
super(t, e, r), this.script = t, this.arguments = e || [], this.context = r || null, this._pkgMeta = n;
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
return r;
|
|
3526
|
+
}
|
|
3527
|
+
var h = class extends r {
|
|
3528
|
+
static get name() {
|
|
3529
|
+
return "wbt";
|
|
3530
|
+
}
|
|
3531
|
+
get name() {
|
|
3532
|
+
return "wbt";
|
|
3533
|
+
}
|
|
3534
|
+
get requiresFilesystem() {
|
|
3535
|
+
return !0;
|
|
3536
|
+
}
|
|
3537
|
+
static get _config() {
|
|
3538
|
+
return this.__wbtConfig || {};
|
|
3539
|
+
}
|
|
3540
|
+
static get _adapters() {
|
|
3541
|
+
return this.__adapters ||= /* @__PURE__ */ new Map(), this.__adapters;
|
|
3542
|
+
}
|
|
3543
|
+
static registerAdapter(e, t) {
|
|
3544
|
+
this._adapters.set(e, t);
|
|
3545
|
+
}
|
|
3546
|
+
static configure(e = {}) {
|
|
3547
|
+
class t extends h {
|
|
3548
|
+
static get name() {
|
|
3549
|
+
return "wbt";
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
return t.__wbtConfig = Object.assign({}, this._config, e), t;
|
|
3553
|
+
}
|
|
3554
|
+
static restoreInstalled(e, t = {}) {
|
|
3555
|
+
let n = e.context || e;
|
|
3556
|
+
if (!n || !n.fs) return;
|
|
3557
|
+
let r = new (this.configure(t))([], n);
|
|
3558
|
+
r.fs = n.fs.sandbox(), r._restoreCommands();
|
|
3559
|
+
}
|
|
3560
|
+
_getRegistry() {
|
|
3561
|
+
let e = this.constructor._config || {}, t = Object.assign({}, o, e.registry || {});
|
|
3562
|
+
try {
|
|
3563
|
+
let e = this.context.fs._getFileRaw(`${p}/remote-registry.json`);
|
|
3564
|
+
if (typeof e == "string" && e.trim()) {
|
|
3565
|
+
let n = JSON.parse(e);
|
|
3566
|
+
Object.assign(t, n);
|
|
3567
|
+
}
|
|
3568
|
+
} catch {}
|
|
3569
|
+
return t;
|
|
3570
|
+
}
|
|
3571
|
+
_readState() {
|
|
3572
|
+
try {
|
|
3573
|
+
let e = this.context.fs._getFileRaw(f);
|
|
3574
|
+
if (typeof e == "string" && e.trim()) {
|
|
3575
|
+
let t = JSON.parse(e);
|
|
3576
|
+
if (t && typeof t == "object" && t.packages) return t;
|
|
3577
|
+
}
|
|
3578
|
+
} catch {}
|
|
3579
|
+
return { packages: {} };
|
|
3580
|
+
}
|
|
3581
|
+
_writeState(e) {
|
|
3582
|
+
this.context.fs._setFileRaw(f, JSON.stringify(e, null, 2), !0);
|
|
3583
|
+
}
|
|
3584
|
+
_buildCommandsForPackage(e) {
|
|
3585
|
+
let t = this.constructor._config || {};
|
|
3586
|
+
if (e.type === "custom-wasm" && e.wasmPath) {
|
|
3587
|
+
let t = (e.bin || e.name).toLowerCase();
|
|
3588
|
+
return [{
|
|
3589
|
+
bin: t,
|
|
3590
|
+
Cmd: m(t, e.wasmPath, e)
|
|
3591
|
+
}];
|
|
3592
|
+
}
|
|
3593
|
+
let r = e.adapter || e.name, i = this.constructor._adapters && this.constructor._adapters.get(r);
|
|
3594
|
+
if (!i && e.adapter) try {
|
|
3595
|
+
let t = n(`./packages/${e.adapter}`);
|
|
3596
|
+
i = t.buildEntries || t.createAdapter || t;
|
|
3597
|
+
} catch {}
|
|
3598
|
+
if (typeof i == "function") {
|
|
3599
|
+
let n = i(e, t);
|
|
3600
|
+
if (Array.isArray(n)) return n;
|
|
3601
|
+
if (n) return [{
|
|
3602
|
+
bin: (e.bin || e.name).toLowerCase(),
|
|
3603
|
+
Cmd: n
|
|
3604
|
+
}];
|
|
3605
|
+
}
|
|
3606
|
+
let a = e.repl ? d : u, o = (e.bin || e.name.split("/").pop()).toLowerCase(), s = [{
|
|
3607
|
+
bin: o,
|
|
3608
|
+
Cmd: a(e, t, o)
|
|
3609
|
+
}];
|
|
3610
|
+
for (let n of e.aliases || []) {
|
|
3611
|
+
let r = n.toLowerCase();
|
|
3612
|
+
r !== o && s.push({
|
|
3613
|
+
bin: r,
|
|
3614
|
+
Cmd: a(e, t, r)
|
|
3615
|
+
});
|
|
3616
|
+
}
|
|
3617
|
+
return s;
|
|
3618
|
+
}
|
|
3619
|
+
_registerPackageIntoContext(e) {
|
|
3620
|
+
let t = this.context.getVar("PATH") || "/bin", n = this._buildCommandsForPackage(e), r = [];
|
|
3621
|
+
for (let { bin: e, Cmd: i } of n) {
|
|
3622
|
+
let n = e.toLowerCase();
|
|
3623
|
+
this._installBin(t, n, i), r.push(n);
|
|
3624
|
+
}
|
|
3625
|
+
for (let i of e.aliases || []) {
|
|
3626
|
+
let e = i.toLowerCase();
|
|
3627
|
+
if (!r.includes(e) && n.length > 0) {
|
|
3628
|
+
let i = n[0].Cmd;
|
|
3629
|
+
class a extends i {
|
|
3630
|
+
static get name() {
|
|
3631
|
+
return e;
|
|
3632
|
+
}
|
|
3633
|
+
get name() {
|
|
3634
|
+
return e;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
this._installBin(t, e, a), r.push(e);
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
return r;
|
|
3641
|
+
}
|
|
3642
|
+
_installBin(e, t, n) {
|
|
3643
|
+
let r = `${e}/${t}`;
|
|
3644
|
+
this.context.fs.addFiles({ [r]: n }), this.context.fs.setMode(r, 365);
|
|
3645
|
+
}
|
|
3646
|
+
_removeBin(e, t) {
|
|
3647
|
+
let n = `${e}/${t.toLowerCase()}`;
|
|
3648
|
+
if (this.context.fs._deleteByAbsolutePath) this.context.fs._deleteByAbsolutePath(n), this.context.fs._triggerChange();
|
|
3649
|
+
else try {
|
|
3650
|
+
this.context.fs.deleteFileByPath(n);
|
|
3651
|
+
} catch {}
|
|
3652
|
+
}
|
|
3653
|
+
_restoreCommands() {
|
|
3654
|
+
let e = this._readState(), t = this._getRegistry();
|
|
3655
|
+
for (let [n, r] of Object.entries(e.packages)) {
|
|
3656
|
+
let e = t[n] || r;
|
|
3657
|
+
if (e) try {
|
|
3658
|
+
this._registerPackageIntoContext(e);
|
|
3659
|
+
} catch {}
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
async run() {
|
|
3663
|
+
let e = [...this.arguments || []], t = e.length >= 2 && e[0].toLowerCase() === "run";
|
|
3664
|
+
if (e.length === 0 || !t && (e.includes("--help") || e.includes("-h") || e[0] === "help")) {
|
|
3665
|
+
this._printHelp();
|
|
3666
|
+
return;
|
|
3667
|
+
}
|
|
3668
|
+
if (!t && (e.includes("--version") || e.includes("-v"))) {
|
|
3669
|
+
this.stdOut = "wbt 1.1.0 (Web Binary Tool for brsh)";
|
|
3670
|
+
return;
|
|
3671
|
+
}
|
|
3672
|
+
let n = e.shift().toLowerCase();
|
|
3673
|
+
switch (n) {
|
|
3674
|
+
case "install":
|
|
3675
|
+
case "add":
|
|
3676
|
+
await this._handleInstall(e);
|
|
3677
|
+
break;
|
|
3678
|
+
case "remove":
|
|
3679
|
+
case "uninstall":
|
|
3680
|
+
case "purge":
|
|
3681
|
+
await this._handleRemove(e);
|
|
3682
|
+
break;
|
|
3683
|
+
case "list":
|
|
3684
|
+
this._handleList(e);
|
|
3685
|
+
break;
|
|
3686
|
+
case "search":
|
|
3687
|
+
this._handleSearch(e);
|
|
3688
|
+
break;
|
|
3689
|
+
case "show":
|
|
3690
|
+
case "info":
|
|
3691
|
+
this._handleShow(e);
|
|
3692
|
+
break;
|
|
3693
|
+
case "update":
|
|
3694
|
+
await this._handleUpdate(e);
|
|
3695
|
+
break;
|
|
3696
|
+
case "run":
|
|
3697
|
+
await this._handleRun(e);
|
|
3698
|
+
break;
|
|
3699
|
+
default: this.stdErr = `E: Invalid operation ${n}`, this.stdErr = "Run 'wbt --help' for usage information.", this.exitCode = 100;
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
async _handleInstall(e) {
|
|
3703
|
+
let t = [], n = [], r = null;
|
|
3704
|
+
for (let i = 0; i < e.length; i++) {
|
|
3705
|
+
let a = e[i];
|
|
3706
|
+
a === "--as" && i + 1 < e.length ? r = e[++i] : a.startsWith("--as=") ? r = a.slice(5) : a.startsWith("-") ? t.push(a) : n.push(a);
|
|
3707
|
+
}
|
|
3708
|
+
let i = t.includes("-q") || t.includes("--quiet"), a = t.includes("--generic") || t.includes("--npm");
|
|
3709
|
+
if (n.length === 0) {
|
|
3710
|
+
this.stdErr = "E: Specify at least one package to install", this.exitCode = 1;
|
|
3711
|
+
return;
|
|
3712
|
+
}
|
|
3713
|
+
let o = (e) => /^(https?:\/\/|data:)/i.test(e), s = (e) => e.startsWith("data:") ? "custom-wasm" : e.split("/").pop().split("?")[0].replace(/\.(wasm|wat|mjs|js)$/i, "") || "custom-wasm", l = this._getRegistry(), u = this._readState(), d = !1;
|
|
3714
|
+
for (let e = 0; e < n.length; e++) {
|
|
3715
|
+
let f = n[e];
|
|
3716
|
+
if (!o(f) && e + 1 < n.length && o(n[e + 1])) {
|
|
3717
|
+
let t = n[++e], a = (r || f).toLowerCase();
|
|
3718
|
+
if (await this._installCustomUrl(a, t, i, u), this.exitCode) return;
|
|
3719
|
+
continue;
|
|
3720
|
+
}
|
|
3721
|
+
if (o(f)) {
|
|
3722
|
+
let e = f, t = (r || s(e)).toLowerCase();
|
|
3723
|
+
if (await this._installCustomUrl(t, e, i, u), this.exitCode) return;
|
|
3724
|
+
continue;
|
|
3725
|
+
}
|
|
3726
|
+
!i && !d && (this.stdOut = "Reading package lists... Done", this.stdOut = "Building dependency tree... Done", this.flush(), d = !0);
|
|
3727
|
+
let p = l[c(f)];
|
|
3728
|
+
if (!p && (a || f.startsWith("npm:") || f.startsWith("esm:"))) {
|
|
3729
|
+
let e = f.replace(/^(npm|esm):/i, ""), t = (r || e.replace(/^@[^/]+\//, "").split("@")[0]).toLowerCase();
|
|
3730
|
+
p = {
|
|
3731
|
+
name: t,
|
|
3732
|
+
bin: t,
|
|
3733
|
+
version: "latest",
|
|
3734
|
+
description: `Dynamic WASM/ESM package from https://esm.sh/${e}`,
|
|
3735
|
+
cdnUrl: `https://esm.sh/${e}`,
|
|
3736
|
+
type: "generic-runtime"
|
|
3737
|
+
};
|
|
3738
|
+
}
|
|
3739
|
+
if (!p) {
|
|
3740
|
+
this.stdErr = `E: Unable to locate package ${f}`, this.exitCode = 100;
|
|
3741
|
+
return;
|
|
3742
|
+
}
|
|
3743
|
+
if (u.packages[p.name] && !t.includes("--reinstall") && !t.includes("-f")) {
|
|
3744
|
+
i || (this.stdOut = `${p.name} is already the newest version (${p.version}).`);
|
|
3745
|
+
continue;
|
|
3746
|
+
}
|
|
3747
|
+
if (i || (this.stdOut = `Get:1 ${p.cdnUrl} ${p.name} ${p.version} [${p.size || "WASM"}]`, this.stdOut = `Unpacking ${p.name} (${p.version}) ...`, this.flush()), t.includes("--preload")) {
|
|
3748
|
+
let e = this.constructor._config || {}, { loadModule: t } = ie();
|
|
3749
|
+
try {
|
|
3750
|
+
await t(p.name, p.cdnUrl, e.moduleLoader);
|
|
3751
|
+
} catch (e) {
|
|
3752
|
+
this.stdErr = `E: Failed to fetch ${p.name}: ${e.message || e}`, this.exitCode = 1;
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
let m = this._registerPackageIntoContext(p);
|
|
3757
|
+
u.packages[p.name] = {
|
|
3758
|
+
name: p.name,
|
|
3759
|
+
bin: p.bin,
|
|
3760
|
+
bins: m,
|
|
3761
|
+
aliases: p.aliases || [],
|
|
3762
|
+
version: p.version,
|
|
3763
|
+
description: p.description,
|
|
3764
|
+
cdnUrl: p.cdnUrl,
|
|
3765
|
+
wasmUrl: p.wasmUrl,
|
|
3766
|
+
type: p.type,
|
|
3767
|
+
adapter: p.adapter,
|
|
3768
|
+
repl: p.repl,
|
|
3769
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3770
|
+
}, i || (this.stdOut = `Setting up ${p.name} (${p.version}) -> /bin/${m.join(", /bin/")} ...`);
|
|
3771
|
+
}
|
|
3772
|
+
this._writeState(u);
|
|
3773
|
+
}
|
|
3774
|
+
async _installCustomUrl(e, t, n = !1, r = null) {
|
|
3775
|
+
if (!/\.(wasm|wat)(\?.*)?$/i.test(t) && (/^https?:\/\/esm\.sh\//i.test(t) || /\.(mjs|js)(\?.*)?$/i.test(t))) {
|
|
3776
|
+
let i = {
|
|
3777
|
+
name: e,
|
|
3778
|
+
bin: e,
|
|
3779
|
+
bins: [e],
|
|
3780
|
+
version: "custom-esm",
|
|
3781
|
+
description: `Custom ESM/WASM module from ${t}`,
|
|
3782
|
+
cdnUrl: t,
|
|
3783
|
+
type: "generic-runtime",
|
|
3784
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3785
|
+
};
|
|
3786
|
+
this._registerPackageIntoContext(i);
|
|
3787
|
+
let a = r || this._readState();
|
|
3788
|
+
a.packages[e] = i, this._writeState(a), n || (this.stdOut = `Setting up ${e} (generic runtime) -> /bin/${e} ...`);
|
|
3789
|
+
return;
|
|
3790
|
+
}
|
|
3791
|
+
let i = (this.constructor._config || {}).fetch || (typeof fetch == "function" ? fetch : null);
|
|
3792
|
+
if (!i) {
|
|
3793
|
+
this.stdErr = "E: fetch is not available in this environment", this.exitCode = 1;
|
|
3794
|
+
return;
|
|
3795
|
+
}
|
|
3796
|
+
n || (this.stdOut = `Get:1 ${t} ${e}`, this.flush());
|
|
3797
|
+
let a = t.replace(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/(?:blob|raw)\/([^/]+)\/(.+)$/i, "https://raw.githubusercontent.com/$1/$2/$3/$4"), o;
|
|
3798
|
+
try {
|
|
3799
|
+
o = await i(a);
|
|
3800
|
+
} catch (e) {
|
|
3801
|
+
if (/^https?:\/\/github\.com\/[^/]+\/[^/]+\/releases\/download\//i.test(a)) try {
|
|
3802
|
+
o = await i(`https://corsproxy.io/?${encodeURIComponent(a)}`);
|
|
3803
|
+
} catch {
|
|
3804
|
+
this.stdErr = `E: Failed to fetch ${t} (GitHub Releases blocks browser CORS requests; host the .wasm on jsDelivr/unpkg/raw.githubusercontent.com): ${e.message || e}`, this.exitCode = 1;
|
|
3805
|
+
return;
|
|
3806
|
+
}
|
|
3807
|
+
else {
|
|
3808
|
+
this.stdErr = `E: Failed to fetch ${t}: ${e.message || e}`, this.exitCode = 1;
|
|
3809
|
+
return;
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
if (!o || !o.ok) {
|
|
3813
|
+
this.stdErr = `E: HTTP ${o ? o.status : "error"} fetching ${t}`, this.exitCode = 1;
|
|
3814
|
+
return;
|
|
3815
|
+
}
|
|
3816
|
+
let s = t.endsWith(".wat"), c = `/var/lib/wbt/wasm/${e}${s ? ".wat" : ".wasm"}`;
|
|
3817
|
+
if (s) {
|
|
3818
|
+
let e = await o.text();
|
|
3819
|
+
this.context.fs._setFileRaw(c, e, !0);
|
|
3820
|
+
} else {
|
|
3821
|
+
let e = await o.arrayBuffer();
|
|
3822
|
+
l(this.fs, c, new Uint8Array(e), "application/wasm");
|
|
3823
|
+
}
|
|
3824
|
+
this.context.fs.setMode(c, 493);
|
|
3825
|
+
let u = {
|
|
3826
|
+
name: e,
|
|
3827
|
+
bin: e,
|
|
3828
|
+
bins: [e],
|
|
3829
|
+
version: "custom",
|
|
3830
|
+
description: `Custom WebAssembly binary from ${t}`,
|
|
3831
|
+
cdnUrl: t,
|
|
3832
|
+
type: "custom-wasm",
|
|
3833
|
+
wasmPath: c,
|
|
3834
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3835
|
+
};
|
|
3836
|
+
this._registerPackageIntoContext(u);
|
|
3837
|
+
let d = r || this._readState();
|
|
3838
|
+
d.packages[e] = u, this._writeState(d), n || (this.stdOut = `Setting up ${e} (custom) -> /bin/${e} ...`);
|
|
3839
|
+
}
|
|
3840
|
+
async _handleRemove(e) {
|
|
3841
|
+
let t = e.filter((e) => !e.startsWith("-"));
|
|
3842
|
+
if (t.length === 0) {
|
|
3843
|
+
this.stdErr = "E: Specify at least one package to remove", this.exitCode = 1;
|
|
3844
|
+
return;
|
|
3845
|
+
}
|
|
3846
|
+
let n = this._readState(), r = this.context.getVar("PATH") || "/bin";
|
|
3847
|
+
for (let e of t) {
|
|
3848
|
+
let t = c(e), i = n.packages[t] || n.packages[e.toLowerCase()];
|
|
3849
|
+
if (!i) {
|
|
3850
|
+
this.stdErr = `E: Package '${e}' is not installed, so not removed`, this.exitCode = 1;
|
|
3851
|
+
return;
|
|
3852
|
+
}
|
|
3853
|
+
let a = i.bins || [i.bin || i.name, ...i.aliases || []];
|
|
3854
|
+
for (let e of a) this._removeBin(r, e);
|
|
3855
|
+
if (i.wasmPath) try {
|
|
3856
|
+
this.context.fs.deleteFileByPath(i.wasmPath);
|
|
3857
|
+
} catch {}
|
|
3858
|
+
delete n.packages[i.name], this.stdOut = `Removing ${i.name} (${i.version}) ...`;
|
|
3859
|
+
}
|
|
3860
|
+
this._writeState(n);
|
|
3861
|
+
}
|
|
3862
|
+
_handleList(e) {
|
|
3863
|
+
let t = e.includes("--installed") || e.includes("-i"), n = this._getRegistry(), r = this._readState();
|
|
3864
|
+
this.stdOut = "Listing...";
|
|
3865
|
+
let i = t ? Object.keys(r.packages).sort() : Array.from(new Set([...Object.keys(n), ...Object.keys(r.packages)])).sort();
|
|
3866
|
+
for (let e of i) {
|
|
3867
|
+
let t = n[e], i = r.packages[e], a = i || t;
|
|
3868
|
+
if (!a) continue;
|
|
3869
|
+
let o = i ? "[installed]" : "[available]", s = a.bin && a.bin !== a.name ? ` (bin: ${a.bin})` : "";
|
|
3870
|
+
this.stdOut = `${a.name}/wasm ${a.version} wasm ${o}${s} - ${a.description || ""}`;
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
_handleSearch(e) {
|
|
3874
|
+
let t = e.filter((e) => !e.startsWith("-")).join(" ").toLowerCase(), n = this._getRegistry(), r = this._readState();
|
|
3875
|
+
this.stdOut = "Sorting... Done", this.stdOut = "Full Text Search... Done";
|
|
3876
|
+
let i = Object.values(n).filter((e) => t ? e.name.toLowerCase().includes(t) || e.bin && e.bin.toLowerCase().includes(t) || e.aliases && e.aliases.some((e) => e.toLowerCase().includes(t)) || e.description && e.description.toLowerCase().includes(t) || e.details && e.details.toLowerCase().includes(t) : !0);
|
|
3877
|
+
for (let e of i) {
|
|
3878
|
+
let t = r.packages[e.name] ? " [installed]" : "";
|
|
3879
|
+
this.stdOut = `${e.name}/wasm ${e.version} wasm${t}`, this.stdOut = ` ${e.description}`;
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
_handleShow(e) {
|
|
3883
|
+
let t = e.find((e) => !e.startsWith("-"));
|
|
3884
|
+
if (!t) {
|
|
3885
|
+
this.stdErr = "E: No packages found — specify a package name", this.exitCode = 1;
|
|
3886
|
+
return;
|
|
3887
|
+
}
|
|
3888
|
+
let n = c(t), r = this._getRegistry(), i = this._readState(), a = i.packages[n] || r[n];
|
|
3889
|
+
if (!a) {
|
|
3890
|
+
this.stdErr = `E: No packages found matching ${t}`, this.exitCode = 100;
|
|
3891
|
+
return;
|
|
3892
|
+
}
|
|
3893
|
+
let o = Object.assign({}, r[n] || {}, a), s = !!i.packages[o.name];
|
|
3894
|
+
this.stdOut = `Package: ${o.name}`, this.stdOut = `Version: ${o.version}`, this.stdOut = `State: ${s ? "installed" : "not installed"}`, this.stdOut = `Binary: ${o.bin || o.name}`, o.aliases && o.aliases.length > 0 && (this.stdOut = `Aliases: ${o.aliases.join(", ")}`), o.size && (this.stdOut = `Download-Size: ${o.size}`), o.cdnUrl && (this.stdOut = `APT-Sources: ${o.cdnUrl}`), o.homepage && (this.stdOut = `Homepage: ${o.homepage}`), this.stdOut = `Description: ${o.description || ""}`, o.details && (this.stdOut = ` ${o.details}`);
|
|
3895
|
+
}
|
|
3896
|
+
async _handleUpdate() {
|
|
3897
|
+
let e = this.constructor._config || {}, t = e.sources || [], n = e.fetch || (typeof fetch == "function" ? fetch : null), r = {}, i = 1;
|
|
3898
|
+
this.stdOut = "Hit:1 https://registry.brsh.dev/wbt wasm InRelease";
|
|
3899
|
+
for (let e of t) if (i++, n) try {
|
|
3900
|
+
let t = await n(e);
|
|
3901
|
+
if (t && t.ok) {
|
|
3902
|
+
let n = await t.json();
|
|
3903
|
+
Object.assign(r, n), this.stdOut = `Get:${i} ${e} Packages`;
|
|
3904
|
+
}
|
|
3905
|
+
} catch (t) {
|
|
3906
|
+
this.stdErr = `W: Failed to fetch ${e}: ${t.message || t}`;
|
|
3907
|
+
}
|
|
3908
|
+
Object.keys(r).length > 0 && this.context.fs._setFileRaw(`${p}/remote-registry.json`, JSON.stringify(r, null, 2), !0), this._restoreCommands();
|
|
3909
|
+
let a = this._getRegistry();
|
|
3910
|
+
this.stdOut = `Reading package lists... Done (${Object.keys(a).length} packages available)`;
|
|
3911
|
+
}
|
|
3912
|
+
async _handleRun(e) {
|
|
3913
|
+
if (e.length === 0) {
|
|
3914
|
+
this.stdErr = "E: Specify a package to run (e.g. wbt run sqlite3 --version)", this.exitCode = 1;
|
|
3915
|
+
return;
|
|
3916
|
+
}
|
|
3917
|
+
let t = e.shift(), n = c(t), r = this._getRegistry(), i = this._readState().packages[n] || r[n];
|
|
3918
|
+
if (!i && (t.startsWith("npm:") || t.startsWith("esm:"))) {
|
|
3919
|
+
let e = t.replace(/^(npm|esm):/i, ""), n = e.replace(/^@[^/]+\//, "").split("@")[0].toLowerCase();
|
|
3920
|
+
i = {
|
|
3921
|
+
name: n,
|
|
3922
|
+
bin: n,
|
|
3923
|
+
version: "latest",
|
|
3924
|
+
cdnUrl: `https://esm.sh/${e}`,
|
|
3925
|
+
type: "generic-runtime"
|
|
3926
|
+
};
|
|
3927
|
+
}
|
|
3928
|
+
if (!i) {
|
|
3929
|
+
this.stdErr = `E: Unable to locate package ${t}`, this.exitCode = 100;
|
|
3930
|
+
return;
|
|
3931
|
+
}
|
|
3932
|
+
let a = this._buildCommandsForPackage(i), o = (a.find((e) => e.bin === t.toLowerCase()) || a[0]).Cmd, s = new o(e, this.context);
|
|
3933
|
+
s.requiresFilesystem && (s.fs = this.context.fs.sandbox()), this.stdin !== void 0 && (s.stdin = this.stdin);
|
|
3934
|
+
let l = await s.runCommand();
|
|
3935
|
+
for (let e of l.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
3936
|
+
this.exitCode = l.getExitCode();
|
|
3937
|
+
}
|
|
3938
|
+
_printHelp() {
|
|
3939
|
+
[
|
|
3940
|
+
"wbt 1.1.0 — Web Binary Tool (WASM binary manager & runtime for brsh)",
|
|
3941
|
+
"Usage: wbt [options] command [package ...]",
|
|
3942
|
+
"",
|
|
3943
|
+
"Commands:",
|
|
3944
|
+
" install <pkg> [url] Install a WASM binary from registry, npm:<pkg>, or a custom URL",
|
|
3945
|
+
" remove <pkg> Remove an installed WASM binary",
|
|
3946
|
+
" update Update package index and restore installed binaries",
|
|
3947
|
+
" list [--installed] List available or installed WASM binaries",
|
|
3948
|
+
" search <query> Search available WASM binaries by name or description",
|
|
3949
|
+
" show <pkg> Show detailed information about a package",
|
|
3950
|
+
" run <pkg> [args...] Run a WASM binary without permanently installing it",
|
|
3951
|
+
"",
|
|
3952
|
+
"Curated WASM Packages:",
|
|
3953
|
+
" sqlite3 SQLite3 compiled to WebAssembly (sqlite3, sqlite)",
|
|
3954
|
+
" assemblyscript AssemblyScript compiler & ts-node style runtime (asc, asrun, asnode)",
|
|
3955
|
+
" jq Command-line JSON processor (jq)",
|
|
3956
|
+
" python3 CPython 3.12 via Pyodide (python3, python, py)",
|
|
3957
|
+
" duckdb DuckDB analytical SQL OLAP engine (duckdb)",
|
|
3958
|
+
" graphviz Graphviz DOT diagram compiler (dot)",
|
|
3959
|
+
" ffmpeg FFmpeg multimedia transcoder (ffmpeg)",
|
|
3960
|
+
" wabt WebAssembly Binary Toolkit (wat2wasm, wasm2wat)",
|
|
3961
|
+
" quickjs Sandboxed QuickJS JavaScript engine (qjs)",
|
|
3962
|
+
" lua Lua 5.4 WebAssembly interpreter (lua)",
|
|
3963
|
+
" wllama WASM & WebGPU LLM inference engine (wllama, llama, llama-cli)"
|
|
3964
|
+
].forEach((e) => {
|
|
3965
|
+
this.stdOut = e;
|
|
3966
|
+
});
|
|
3967
|
+
}
|
|
3968
|
+
};
|
|
3969
|
+
t.exports = h, t.exports.Wbt = h, t.exports.DEFAULT_REGISTRY = o, t.exports.createGenericWasmCommand = u, t.exports.createReplWasmCommand = d;
|
|
3970
|
+
}));
|
|
3971
|
+
//#endregion
|
|
3972
|
+
export default ae();
|
|
3973
|
+
|
|
3974
|
+
//# sourceMappingURL=wbt.es.js.map
|