brsh 3.10.0 → 3.10.1

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/dist/wbt.es.js CHANGED
@@ -96,7 +96,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
96
96
  if (typeof e == "string") return g(e, t);
97
97
  if (o.isView(e)) return y(e);
98
98
  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);
99
- if ($(e, o) || e && $(e.buffer, o) || s !== void 0 && ($(e, s) || e && $(e.buffer, s))) return b(e, t, n);
99
+ if (Q(e, o) || e && Q(e.buffer, o) || s !== void 0 && (Q(e, s) || e && Q(e.buffer, s))) return b(e, t, n);
100
100
  if (typeof e == "number") throw TypeError("The \"value\" argument must not be of type number. Received type number");
101
101
  let r = e.valueOf && e.valueOf();
102
102
  if (r != null && r !== e) return u.from(r, t, n);
@@ -137,7 +137,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
137
137
  return n;
138
138
  }
139
139
  function y(e) {
140
- if ($(e, a)) {
140
+ if (Q(e, a)) {
141
141
  let t = new a(e);
142
142
  return b(t.buffer, t.byteOffset, t.byteLength);
143
143
  }
@@ -154,7 +154,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
154
154
  let t = S(e.length) | 0, n = l(t);
155
155
  return n.length === 0 || e.copy(n, 0, 0, t), n;
156
156
  }
157
- if (e.length !== void 0) return typeof e.length != "number" || ue(e.length) ? l(0) : _(e);
157
+ if (e.length !== void 0) return typeof e.length != "number" || de(e.length) ? l(0) : _(e);
158
158
  if (e.type === "Buffer" && Array.isArray(e.data)) return _(e.data);
159
159
  }
160
160
  function S(e) {
@@ -167,7 +167,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
167
167
  u.isBuffer = function(e) {
168
168
  return e != null && e._isBuffer === !0 && e !== u.prototype;
169
169
  }, u.compare = function(e, t) {
170
- if ($(e, a) && (e = u.from(e, e.offset, e.byteLength)), $(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");
170
+ 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");
171
171
  if (e === t) return 0;
172
172
  let n = e.length, r = t.length;
173
173
  for (let i = 0, a = Math.min(n, r); i < a; ++i) if (e[i] !== t[i]) {
@@ -198,7 +198,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
198
198
  let r = u.allocUnsafe(t), i = 0;
199
199
  for (n = 0; n < e.length; ++n) {
200
200
  let t = e[n];
201
- if ($(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);
201
+ 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);
202
202
  else if (u.isBuffer(t)) t.copy(r, i);
203
203
  else throw TypeError("\"list\" argument must be an Array of Buffers");
204
204
  i += t.length;
@@ -207,7 +207,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
207
207
  };
208
208
  function w(e, t) {
209
209
  if (u.isBuffer(e)) return e.length;
210
- if (o.isView(e) || $(e, o)) return e.byteLength;
210
+ if (o.isView(e) || Q(e, o)) return e.byteLength;
211
211
  if (typeof e != "string") throw TypeError("The \"string\" argument must be one of type string, Buffer, or ArrayBuffer. Received type " + typeof e);
212
212
  let n = e.length, r = arguments.length > 2 && arguments[2] === !0;
213
213
  if (!r && n === 0) return 0;
@@ -217,15 +217,15 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
217
217
  case "latin1":
218
218
  case "binary": return n;
219
219
  case "utf8":
220
- case "utf-8": return Q(e).length;
220
+ case "utf-8": return Z(e).length;
221
221
  case "ucs2":
222
222
  case "ucs-2":
223
223
  case "utf16le":
224
224
  case "utf-16le": return n * 2;
225
225
  case "hex": return n >>> 1;
226
- case "base64": return ce(e).length;
226
+ case "base64": return le(e).length;
227
227
  default:
228
- if (i) return r ? -1 : Q(e).length;
228
+ if (i) return r ? -1 : Z(e).length;
229
229
  t = ("" + t).toLowerCase(), i = !0;
230
230
  }
231
231
  }
@@ -234,17 +234,17 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
234
234
  let r = !1;
235
235
  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 "";
236
236
  for (e ||= "utf8";;) switch (e) {
237
- case "hex": return B(this, t, n);
237
+ case "hex": return z(this, t, n);
238
238
  case "utf8":
239
239
  case "utf-8": return F(this, t, n);
240
- case "ascii": return R(this, t, n);
240
+ case "ascii": return ee(this, t, n);
241
241
  case "latin1":
242
- case "binary": return z(this, t, n);
242
+ case "binary": return R(this, t, n);
243
243
  case "base64": return P(this, t, n);
244
244
  case "ucs2":
245
245
  case "ucs-2":
246
246
  case "utf16le":
247
- case "utf-16le": return ee(this, t, n);
247
+ case "utf-16le": return B(this, t, n);
248
248
  default:
249
249
  if (r) throw TypeError("Unknown encoding: " + e);
250
250
  e = (e + "").toLowerCase(), r = !0;
@@ -280,7 +280,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
280
280
  let t = "", n = e.INSPECT_MAX_BYTES;
281
281
  return t = this.toString("hex", 0, n).replace(/(.{2})/g, "$1 ").trim(), this.length > n && (t += " ... "), "<Buffer " + t + ">";
282
282
  }, r && (u.prototype[r] = u.prototype.inspect), u.prototype.compare = function(e, t, n, r, i) {
283
- if ($(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);
283
+ 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);
284
284
  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");
285
285
  if (r >= i && t >= n) return 0;
286
286
  if (r >= i) return -1;
@@ -295,7 +295,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
295
295
  };
296
296
  function D(e, t, n, r, i) {
297
297
  if (e.length === 0) return -1;
298
- if (typeof n == "string" ? (r = n, n = 0) : n > 2147483647 ? n = 2147483647 : n < -2147483648 && (n = -2147483648), n = +n, ue(n) && (n = i ? 0 : e.length - 1), n < 0 && (n = e.length + n), n >= e.length) {
298
+ 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) {
299
299
  if (i) return -1;
300
300
  n = e.length - 1;
301
301
  } else if (n < 0) if (i) n = 0;
@@ -345,22 +345,22 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
345
345
  let o;
346
346
  for (o = 0; o < r; ++o) {
347
347
  let r = parseInt(t.substr(o * 2, 2), 16);
348
- if (ue(r)) return o;
348
+ if (de(r)) return o;
349
349
  e[n + o] = r;
350
350
  }
351
351
  return o;
352
352
  }
353
353
  function A(e, t, n, r) {
354
- return le(Q(t, e.length - n), e, n, r);
354
+ return ue(Z(t, e.length - n), e, n, r);
355
355
  }
356
356
  function j(e, t, n, r) {
357
- return le(oe(t), e, n, r);
357
+ return ue(se(t), e, n, r);
358
358
  }
359
359
  function M(e, t, n, r) {
360
- return le(ce(t), e, n, r);
360
+ return ue(le(t), e, n, r);
361
361
  }
362
362
  function N(e, t, n, r) {
363
- return le(se(t, e.length - n), e, n, r);
363
+ return ue(ce(t, e.length - n), e, n, r);
364
364
  }
365
365
  u.prototype.write = function(e, t, n, r) {
366
366
  if (t === void 0) r = "utf8", n = this.length, t = 0;
@@ -428,26 +428,26 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
428
428
  for (; r < t;) n += String.fromCharCode.apply(String, e.slice(r, r += I));
429
429
  return n;
430
430
  }
431
- function R(e, t, n) {
431
+ function ee(e, t, n) {
432
432
  let r = "";
433
433
  n = Math.min(e.length, n);
434
434
  for (let i = t; i < n; ++i) r += String.fromCharCode(e[i] & 127);
435
435
  return r;
436
436
  }
437
- function z(e, t, n) {
437
+ function R(e, t, n) {
438
438
  let r = "";
439
439
  n = Math.min(e.length, n);
440
440
  for (let i = t; i < n; ++i) r += String.fromCharCode(e[i]);
441
441
  return r;
442
442
  }
443
- function B(e, t, n) {
443
+ function z(e, t, n) {
444
444
  let r = e.length;
445
445
  (!t || t < 0) && (t = 0), (!n || n < 0 || n > r) && (n = r);
446
446
  let i = "";
447
- for (let r = t; r < n; ++r) i += de[e[r]];
447
+ for (let r = t; r < n; ++r) i += fe[e[r]];
448
448
  return i;
449
449
  }
450
- function ee(e, t, n) {
450
+ function B(e, t, n) {
451
451
  let r = e.slice(t, n), i = "";
452
452
  for (let e = 0; e < r.length - 1; e += 2) i += String.fromCharCode(r[e] + r[e + 1] * 256);
453
453
  return i;
@@ -482,16 +482,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
482
482
  return e >>>= 0, t || V(e, 4, this.length), (this[e] | this[e + 1] << 8 | this[e + 2] << 16) + this[e + 3] * 16777216;
483
483
  }, u.prototype.readUint32BE = u.prototype.readUInt32BE = function(e, t) {
484
484
  return e >>>= 0, t || V(e, 4, this.length), this[e] * 16777216 + (this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3]);
485
- }, u.prototype.readBigUInt64LE = fe(function(e) {
486
- e >>>= 0, Y(e, "offset");
485
+ }, u.prototype.readBigUInt64LE = $(function(e) {
486
+ e >>>= 0, J(e, "offset");
487
487
  let t = this[e], n = this[e + 7];
488
- (t === void 0 || n === void 0) && X(e, this.length - 8);
488
+ (t === void 0 || n === void 0) && Y(e, this.length - 8);
489
489
  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;
490
490
  return BigInt(r) + (BigInt(i) << BigInt(32));
491
- }), u.prototype.readBigUInt64BE = fe(function(e) {
492
- e >>>= 0, Y(e, "offset");
491
+ }), u.prototype.readBigUInt64BE = $(function(e) {
492
+ e >>>= 0, J(e, "offset");
493
493
  let t = this[e], n = this[e + 7];
494
- (t === void 0 || n === void 0) && X(e, this.length - 8);
494
+ (t === void 0 || n === void 0) && Y(e, this.length - 8);
495
495
  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;
496
496
  return (BigInt(r) << BigInt(32)) + BigInt(i);
497
497
  }), u.prototype.readIntLE = function(e, t, n) {
@@ -518,16 +518,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
518
518
  return e >>>= 0, t || V(e, 4, this.length), this[e] | this[e + 1] << 8 | this[e + 2] << 16 | this[e + 3] << 24;
519
519
  }, u.prototype.readInt32BE = function(e, t) {
520
520
  return e >>>= 0, t || V(e, 4, this.length), this[e] << 24 | this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3];
521
- }, u.prototype.readBigInt64LE = fe(function(e) {
522
- e >>>= 0, Y(e, "offset");
521
+ }, u.prototype.readBigInt64LE = $(function(e) {
522
+ e >>>= 0, J(e, "offset");
523
523
  let t = this[e], n = this[e + 7];
524
- (t === void 0 || n === void 0) && X(e, this.length - 8);
524
+ (t === void 0 || n === void 0) && Y(e, this.length - 8);
525
525
  let r = this[e + 4] + this[e + 5] * 2 ** 8 + this[e + 6] * 2 ** 16 + (n << 24);
526
526
  return (BigInt(r) << BigInt(32)) + BigInt(t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24);
527
- }), u.prototype.readBigInt64BE = fe(function(e) {
528
- e >>>= 0, Y(e, "offset");
527
+ }), u.prototype.readBigInt64BE = $(function(e) {
528
+ e >>>= 0, J(e, "offset");
529
529
  let t = this[e], n = this[e + 7];
530
- (t === void 0 || n === void 0) && X(e, this.length - 8);
530
+ (t === void 0 || n === void 0) && Y(e, this.length - 8);
531
531
  let r = (t << 24) + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e];
532
532
  return (BigInt(r) << BigInt(32)) + BigInt(this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + n);
533
533
  }), u.prototype.readFloatLE = function(e, t) {
@@ -572,23 +572,23 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
572
572
  return e = +e, t >>>= 0, n || H(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;
573
573
  };
574
574
  function U(e, t, n, r, i) {
575
- ie(t, r, i, e, n, 7);
575
+ ae(t, r, i, e, n, 7);
576
576
  let a = Number(t & BigInt(4294967295));
577
577
  e[n++] = a, a >>= 8, e[n++] = a, a >>= 8, e[n++] = a, a >>= 8, e[n++] = a;
578
578
  let o = Number(t >> BigInt(32) & BigInt(4294967295));
579
579
  return e[n++] = o, o >>= 8, e[n++] = o, o >>= 8, e[n++] = o, o >>= 8, e[n++] = o, n;
580
580
  }
581
- function W(e, t, n, r, i) {
582
- ie(t, r, i, e, n, 7);
581
+ function te(e, t, n, r, i) {
582
+ ae(t, r, i, e, n, 7);
583
583
  let a = Number(t & BigInt(4294967295));
584
584
  e[n + 7] = a, a >>= 8, e[n + 6] = a, a >>= 8, e[n + 5] = a, a >>= 8, e[n + 4] = a;
585
585
  let o = Number(t >> BigInt(32) & BigInt(4294967295));
586
586
  return e[n + 3] = o, o >>= 8, e[n + 2] = o, o >>= 8, e[n + 1] = o, o >>= 8, e[n] = o, n + 8;
587
587
  }
588
- u.prototype.writeBigUInt64LE = fe(function(e, t = 0) {
588
+ u.prototype.writeBigUInt64LE = $(function(e, t = 0) {
589
589
  return U(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
590
- }), u.prototype.writeBigUInt64BE = fe(function(e, t = 0) {
591
- return W(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
590
+ }), u.prototype.writeBigUInt64BE = $(function(e, t = 0) {
591
+ return te(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
592
592
  }), u.prototype.writeIntLE = function(e, t, n, r) {
593
593
  if (e = +e, t >>>= 0, !r) {
594
594
  let r = 2 ** (8 * n - 1);
@@ -615,29 +615,29 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
615
615
  return e = +e, t >>>= 0, n || H(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;
616
616
  }, u.prototype.writeInt32BE = function(e, t, n) {
617
617
  return e = +e, t >>>= 0, n || H(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;
618
- }, u.prototype.writeBigInt64LE = fe(function(e, t = 0) {
618
+ }, u.prototype.writeBigInt64LE = $(function(e, t = 0) {
619
619
  return U(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
620
- }), u.prototype.writeBigInt64BE = fe(function(e, t = 0) {
621
- return W(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
620
+ }), u.prototype.writeBigInt64BE = $(function(e, t = 0) {
621
+ return te(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
622
622
  });
623
- function te(e, t, n, r, i, a) {
623
+ function W(e, t, n, r, i, a) {
624
624
  if (n + r > e.length || n < 0) throw RangeError("Index out of range");
625
625
  }
626
- function G(e, t, r, i, a) {
627
- return t = +t, r >>>= 0, a || te(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
626
+ function ne(e, t, r, i, a) {
627
+ return t = +t, r >>>= 0, a || W(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
628
628
  }
629
629
  u.prototype.writeFloatLE = function(e, t, n) {
630
- return G(this, e, t, !0, n);
630
+ return ne(this, e, t, !0, n);
631
631
  }, u.prototype.writeFloatBE = function(e, t, n) {
632
- return G(this, e, t, !1, n);
632
+ return ne(this, e, t, !1, n);
633
633
  };
634
- function K(e, t, r, i, a) {
635
- return t = +t, r >>>= 0, a || te(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
634
+ function re(e, t, r, i, a) {
635
+ return t = +t, r >>>= 0, a || W(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
636
636
  }
637
637
  u.prototype.writeDoubleLE = function(e, t, n) {
638
- return K(this, e, t, !0, n);
638
+ return re(this, e, t, !0, n);
639
639
  }, u.prototype.writeDoubleBE = function(e, t, n) {
640
- return K(this, e, t, !1, n);
640
+ return re(this, e, t, !1, n);
641
641
  }, u.prototype.copy = function(e, t, n, r) {
642
642
  if (!u.isBuffer(e)) throw TypeError("argument should be a Buffer");
643
643
  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;
@@ -668,9 +668,9 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
668
668
  }
669
669
  return this;
670
670
  };
671
- let q = {};
672
- function ne(e, t, n) {
673
- q[e] = class extends n {
671
+ let G = {};
672
+ function K(e, t, n) {
673
+ G[e] = class extends n {
674
674
  constructor() {
675
675
  super(), Object.defineProperty(this, "message", {
676
676
  value: t.apply(this, arguments),
@@ -694,42 +694,42 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
694
694
  }
695
695
  };
696
696
  }
697
- ne("ERR_BUFFER_OUT_OF_BOUNDS", function(e) {
697
+ K("ERR_BUFFER_OUT_OF_BOUNDS", function(e) {
698
698
  return e ? `${e} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
699
- }, RangeError), ne("ERR_INVALID_ARG_TYPE", function(e, t) {
699
+ }, RangeError), K("ERR_INVALID_ARG_TYPE", function(e, t) {
700
700
  return `The "${e}" argument must be of type number. Received type ${typeof t}`;
701
- }, TypeError), ne("ERR_OUT_OF_RANGE", function(e, t, n) {
701
+ }, TypeError), K("ERR_OUT_OF_RANGE", function(e, t, n) {
702
702
  let r = `The value of "${e}" is out of range.`, i = n;
703
- 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;
703
+ return Number.isInteger(n) && Math.abs(n) > 2 ** 32 ? i = q(String(n)) : typeof n == "bigint" && (i = String(n), (n > BigInt(2) ** BigInt(32) || n < -(BigInt(2) ** BigInt(32))) && (i = q(i)), i += "n"), r += ` It must be ${t}. Received ${i}`, r;
704
704
  }, RangeError);
705
- function J(e) {
705
+ function q(e) {
706
706
  let t = "", n = e.length, r = +(e[0] === "-");
707
707
  for (; n >= r + 4; n -= 3) t = `_${e.slice(n - 3, n)}${t}`;
708
708
  return `${e.slice(0, n)}${t}`;
709
709
  }
710
- function re(e, t, n) {
711
- Y(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && X(t, e.length - (n + 1));
710
+ function ie(e, t, n) {
711
+ J(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && Y(t, e.length - (n + 1));
712
712
  }
713
- function ie(e, t, n, r, i, a) {
713
+ function ae(e, t, n, r, i, a) {
714
714
  if (e > n || e < t) {
715
715
  let r = typeof t == "bigint" ? "n" : "", i;
716
- 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 q.ERR_OUT_OF_RANGE("value", i, e);
716
+ 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 G.ERR_OUT_OF_RANGE("value", i, e);
717
717
  }
718
- re(r, i, a);
718
+ ie(r, i, a);
719
719
  }
720
- function Y(e, t) {
721
- if (typeof e != "number") throw new q.ERR_INVALID_ARG_TYPE(t, "number", e);
720
+ function J(e, t) {
721
+ if (typeof e != "number") throw new G.ERR_INVALID_ARG_TYPE(t, "number", e);
722
722
  }
723
- function X(e, t, n) {
724
- throw Math.floor(e) === e ? t < 0 ? new q.ERR_BUFFER_OUT_OF_BOUNDS() : new q.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (Y(e, n), new q.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
723
+ function Y(e, t, n) {
724
+ throw Math.floor(e) === e ? t < 0 ? new G.ERR_BUFFER_OUT_OF_BOUNDS() : new G.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (J(e, n), new G.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
725
725
  }
726
- let Z = /[^+/0-9A-Za-z-_]/g;
727
- function ae(e) {
728
- if (e = e.split("=")[0], e = e.trim().replace(Z, ""), e.length < 2) return "";
726
+ let X = /[^+/0-9A-Za-z-_]/g;
727
+ function oe(e) {
728
+ if (e = e.split("=")[0], e = e.trim().replace(X, ""), e.length < 2) return "";
729
729
  for (; e.length % 4 != 0;) e += "=";
730
730
  return e;
731
731
  }
732
- function Q(e, t) {
732
+ function Z(e, t) {
733
733
  t ||= Infinity;
734
734
  let n, r = e.length, i = null, a = [];
735
735
  for (let o = 0; o < r; ++o) {
@@ -767,31 +767,31 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
767
767
  }
768
768
  return a;
769
769
  }
770
- function oe(e) {
770
+ function se(e) {
771
771
  let t = [];
772
772
  for (let n = 0; n < e.length; ++n) t.push(e.charCodeAt(n) & 255);
773
773
  return t;
774
774
  }
775
- function se(e, t) {
775
+ function ce(e, t) {
776
776
  let n, r, i, a = [];
777
777
  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);
778
778
  return a;
779
779
  }
780
- function ce(e) {
781
- return t.toByteArray(ae(e));
780
+ function le(e) {
781
+ return t.toByteArray(oe(e));
782
782
  }
783
- function le(e, t, n, r) {
783
+ function ue(e, t, n, r) {
784
784
  let i;
785
785
  for (i = 0; i < r && !(i + n >= t.length || i >= e.length); ++i) t[i + n] = e[i];
786
786
  return i;
787
787
  }
788
- function $(e, t) {
788
+ function Q(e, t) {
789
789
  return e instanceof t || e != null && e.constructor != null && e.constructor.name != null && e.constructor.name === t.name;
790
790
  }
791
- function ue(e) {
791
+ function de(e) {
792
792
  return e !== e;
793
793
  }
794
- let de = (function() {
794
+ let fe = (function() {
795
795
  let e = "0123456789abcdef", t = Array(256);
796
796
  for (let n = 0; n < 16; ++n) {
797
797
  let r = n * 16;
@@ -799,7 +799,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
799
799
  }
800
800
  return t;
801
801
  })();
802
- function fe(e) {
802
+ function $(e) {
803
803
  return typeof BigInt > "u" ? pe : e;
804
804
  }
805
805
  function pe() {
@@ -862,7 +862,7 @@ function O(e, t) {
862
862
  this.fun = e, this.array = t;
863
863
  }
864
864
  function k() {}
865
- var A, j, M, N, P, F, I, L, R, z, B = e((() => {
865
+ var A, j, M, N, P, F, I, L, ee, R, z = e((() => {
866
866
  A = { exports: {} }, j = A.exports = {}, (function() {
867
867
  try {
868
868
  M = typeof setTimeout == "function" ? setTimeout : S;
@@ -890,9 +890,9 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
890
890
  throw Error("process.chdir is not supported");
891
891
  }, j.umask = function() {
892
892
  return 0;
893
- }, R = A.exports, z = /* @__PURE__ */ x(R);
894
- })), ee = /* @__PURE__ */ t(((e, t) => {
895
- B();
893
+ }, ee = A.exports, R = /* @__PURE__ */ x(ee);
894
+ })), B = /* @__PURE__ */ t(((e, t) => {
895
+ z();
896
896
  function n(e) {
897
897
  if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
898
898
  }
@@ -930,7 +930,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
930
930
  resolve: function() {
931
931
  for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
932
932
  var o;
933
- a >= 0 ? o = arguments[a] : (i === void 0 && (i = z.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
933
+ a >= 0 ? o = arguments[a] : (i === void 0 && (i = R.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
934
934
  }
935
935
  return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
936
936
  },
@@ -1267,7 +1267,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1267
1267
  return this.std = [], e;
1268
1268
  }
1269
1269
  };
1270
- })), W = /* @__PURE__ */ t(((e, t) => {
1270
+ })), te = /* @__PURE__ */ t(((e, t) => {
1271
1271
  b();
1272
1272
  var n = V(), r = n.EventEmitter || n.default || n;
1273
1273
  function i(e) {
@@ -1291,15 +1291,34 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1291
1291
  D: "ArrowLeft",
1292
1292
  H: "Home",
1293
1293
  F: "End",
1294
+ Z: "BackTab",
1295
+ P: "F1",
1296
+ Q: "F2",
1297
+ R: "F3",
1298
+ S: "F4",
1294
1299
  "1~": "Home",
1300
+ "2~": "Insert",
1295
1301
  "3~": "Delete",
1296
1302
  "4~": "End",
1297
1303
  "5~": "PageUp",
1298
1304
  "6~": "PageDown",
1299
1305
  "7~": "Home",
1300
- "8~": "End"
1306
+ "8~": "End",
1307
+ "15~": "F5",
1308
+ "17~": "F6",
1309
+ "18~": "F7",
1310
+ "19~": "F8",
1311
+ "20~": "F9",
1312
+ "21~": "F10",
1313
+ "23~": "F11",
1314
+ "24~": "F12"
1301
1315
  };
1302
- a[i] && n.push(a[i]), r = e + 1;
1316
+ if (a[i]) n.push(a[i]);
1317
+ else {
1318
+ let e = i.match(/^1;\d+([ABCDHF])$/);
1319
+ e && a[e[1]] && n.push(a[e[1]]);
1320
+ }
1321
+ r = e + 1;
1303
1322
  continue;
1304
1323
  }
1305
1324
  }
@@ -1326,75 +1345,82 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1326
1345
  }
1327
1346
  return n;
1328
1347
  }
1329
- t.exports = {
1330
- TtyStream: class extends r {
1331
- constructor(e = {}) {
1332
- super(), this.isTTY = e.isTTY !== !1, this.readable = !0, this.writable = !0, this.columns = e.columns || 80, this.rows = e.rows || 24, this.isRaw = !1, this._encoding = null, this._onWrite = e.onWrite || null;
1348
+ var a = class extends r {
1349
+ constructor(e = {}) {
1350
+ super(), this.isTTY = e.isTTY !== !1, this.readable = !0, this.writable = !0, this.columns = e.columns || 80, this.rows = e.rows || 24, this.isRaw = !1, this._encoding = null, this._onWrite = e.onWrite || null;
1351
+ }
1352
+ write(e, t, n) {
1353
+ if (e == null) return !0;
1354
+ typeof this._onWrite == "function" && this._onWrite(e), this._isPushing = !0;
1355
+ try {
1356
+ this.emit("data", this._formatChunk(e));
1357
+ } finally {
1358
+ this._isPushing = !1;
1333
1359
  }
1334
- write(e, t, n) {
1335
- if (e == null) return !0;
1336
- typeof this._onWrite == "function" && this._onWrite(e), this._isPushing = !0;
1360
+ return typeof t == "function" ? t() : typeof n == "function" && n(), !0;
1361
+ }
1362
+ pushData(e) {
1363
+ if (e != null) {
1364
+ this._isPushing = !0;
1337
1365
  try {
1338
1366
  this.emit("data", this._formatChunk(e));
1339
1367
  } finally {
1340
1368
  this._isPushing = !1;
1341
1369
  }
1342
- return typeof t == "function" ? t() : typeof n == "function" && n(), !0;
1343
- }
1344
- pushData(e) {
1345
- if (e != null) {
1346
- this._isPushing = !0;
1347
- try {
1348
- this.emit("data", this._formatChunk(e));
1349
- } finally {
1350
- this._isPushing = !1;
1351
- }
1352
- }
1353
- }
1354
- _formatChunk(e) {
1355
- return this._encoding ? typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e) : e;
1356
- }
1357
- setRawMode(e) {
1358
- return this.isRaw = !!e, this;
1359
- }
1360
- setEncoding(e) {
1361
- return this._encoding = e, this;
1362
- }
1363
- getWindowSize() {
1364
- return [this.columns, this.rows];
1365
- }
1366
- resize(e, t) {
1367
- this.columns = e, this.rows = t, this.emit("resize");
1368
- }
1369
- resume() {
1370
- return this;
1371
- }
1372
- pause() {
1373
- return this;
1374
- }
1375
- pipe(e) {
1376
- return this.on("data", (t) => e.write(t)), e;
1377
- }
1378
- unpipe() {
1379
- return this;
1380
- }
1381
- end(e, t, n) {
1382
- return e != null && this.write(e, typeof t == "string" ? t : void 0), this.emit("end"), typeof t == "function" ? t() : typeof n == "function" && n(), this;
1383
- }
1384
- destroy() {
1385
- this.removeAllListeners();
1386
- }
1387
- toString() {
1388
- return "";
1389
1370
  }
1390
- valueOf() {
1391
- return "";
1392
- }
1393
- },
1394
- parseVtKeys: i
1371
+ }
1372
+ _formatChunk(e) {
1373
+ return this._encoding ? typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e) : e;
1374
+ }
1375
+ setRawMode(e) {
1376
+ return this.isRaw = !!e, this;
1377
+ }
1378
+ setEncoding(e) {
1379
+ return this._encoding = e, this;
1380
+ }
1381
+ getWindowSize() {
1382
+ return [this.columns, this.rows];
1383
+ }
1384
+ resize(e, t) {
1385
+ this.columns = e, this.rows = t, this.emit("resize");
1386
+ }
1387
+ resume() {
1388
+ return this;
1389
+ }
1390
+ pause() {
1391
+ return this;
1392
+ }
1393
+ pipe(e) {
1394
+ return this.on("data", (t) => e.write(t)), e;
1395
+ }
1396
+ unpipe() {
1397
+ return this;
1398
+ }
1399
+ end(e, t, n) {
1400
+ return e != null && this.write(e, typeof t == "string" ? t : void 0), this.emit("end"), typeof t == "function" ? t() : typeof n == "function" && n(), this;
1401
+ }
1402
+ destroy() {
1403
+ this.removeAllListeners();
1404
+ }
1405
+ toString() {
1406
+ return "";
1407
+ }
1408
+ valueOf() {
1409
+ return "";
1410
+ }
1395
1411
  };
1396
- })), te = /* @__PURE__ */ t(((e, t) => {
1397
- var n = V(), r = U(), { TtyStream: i, parseVtKeys: a } = W(), o = n.EventEmitter || n.default || n;
1412
+ function o(e) {
1413
+ if (!e || e._managesOwnStdinCapture || !e.stdinStream || typeof e.stdinStream.listenerCount != "function") return !1;
1414
+ let t = e.stdinStream.listenerCount("data");
1415
+ return t === 0 ? !1 : e._onStdinStreamData && typeof e.stdinStream.listeners == "function" ? t > +!!e.stdinStream.listeners("data").includes(e._onStdinStreamData) : t > 0;
1416
+ }
1417
+ t.exports = {
1418
+ TtyStream: a,
1419
+ parseVtKeys: i,
1420
+ hasCustomStdinListener: o
1421
+ };
1422
+ })), W = /* @__PURE__ */ t(((e, t) => {
1423
+ var n = V(), r = U(), { TtyStream: i, parseVtKeys: a } = te(), o = n.EventEmitter || n.default || n;
1398
1424
  t.exports = class extends o {
1399
1425
  constructor(e, t) {
1400
1426
  super(), this.arguments = e, this.result = new r(), this.context = t || null;
@@ -1414,7 +1440,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1414
1440
  if (!this.captureInput) return;
1415
1441
  let t = a(e);
1416
1442
  for (let e of t) {
1417
- if (e === "^C") {
1443
+ if (e === "^C" && !(this.stdinStream && this.stdinStream.isRaw)) {
1418
1444
  this.kill("SIGINT");
1419
1445
  return;
1420
1446
  }
@@ -1468,16 +1494,16 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1468
1494
  this.emit("flush", this.result.flush());
1469
1495
  }
1470
1496
  };
1471
- })), G = /* @__PURE__ */ t(((e, t) => {
1472
- var n = te();
1497
+ })), ne = /* @__PURE__ */ t(((e, t) => {
1498
+ var n = W();
1473
1499
  t.exports = class extends n {
1474
1500
  constructor(e, t) {
1475
1501
  super(e, t);
1476
1502
  }
1477
1503
  };
1478
- })), K = /* @__PURE__ */ t(((e, t) => {
1479
- var n = G();
1480
- function r(e) {
1504
+ })), re = /* @__PURE__ */ t(((e, t) => {
1505
+ var n = ne(), { parseVtKeys: r, hasCustomStdinListener: i } = te();
1506
+ function a(e) {
1481
1507
  return /^#!\/(sh\.js|bin\/(sh|brsh))/.test(e);
1482
1508
  }
1483
1509
  t.exports = class extends n {
@@ -1485,11 +1511,16 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1485
1511
  super(t, n), this.script = e, this.source = r;
1486
1512
  }
1487
1513
  get captureInput() {
1488
- return !!(this.sandbox && this.sandbox.runningCommand && (this.sandbox.runningCommand.captureInput || this.sandbox.runningCommand.interactive));
1514
+ if (!this.sandbox || !this.sandbox.runningCommand) return !1;
1515
+ let e = this.sandbox.runningCommand;
1516
+ return !!(e.captureInput || e.interactive || e._inAltScreen || i(e));
1489
1517
  }
1490
1518
  get interactive() {
1491
1519
  return !!(this.sandbox && this.sandbox.runningCommand && this.sandbox.runningCommand.interactive);
1492
1520
  }
1521
+ get isRaw() {
1522
+ return !!(this.stdinStream && this.stdinStream.isRaw || this.sandbox && this.sandbox.runningCommand && (this.sandbox.runningCommand.isRaw || this.sandbox.runningCommand.stdinStream && this.sandbox.runningCommand.stdinStream.isRaw));
1523
+ }
1493
1524
  get _inAltScreen() {
1494
1525
  return !!(this.__inAltScreen || this.sandbox && this.sandbox.runningCommand && this.sandbox.runningCommand._inAltScreen);
1495
1526
  }
@@ -1503,38 +1534,43 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1503
1534
  this.sandbox && this.sandbox.runningCommand && typeof this.sandbox.runningCommand.kill == "function" && this.sandbox.runningCommand.kill(e), this.sandbox && typeof this.sandbox.destroy == "function" && this.sandbox.destroy(130), super.kill(e);
1504
1535
  }
1505
1536
  run() {
1506
- let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
1507
- filesystem: e && e.getRaw() || {},
1508
- permissions: e && e.getRawPermissions() || {}
1537
+ this._managesOwnStdinCapture = !0;
1538
+ let e = this.context && this.context.fs || this.fs, t = e && e[Symbol.for("brsh.fs.target")] || e, n = t && t.isRealFilesystem ? { useRealFilesystem: !0 } : {
1539
+ filesystem: t && t.getRaw() || {},
1540
+ permissions: t && t.getRawPermissions() || {}
1509
1541
  };
1510
1542
  this.sandbox = new globalThis.shell({
1511
- cwd: e && e.cwd || "/",
1512
- ...t,
1543
+ cwd: t && t.cwd || "/",
1544
+ ...n,
1513
1545
  subshell: !0
1514
1546
  }), this.sandbox.context.source(this.context);
1515
- let n = this.stdinStream && this.stdinStream.columns || 80, i = this.stdinStream && this.stdinStream.rows || 24;
1516
- typeof this.sandbox.setTerminalSize == "function" && this.sandbox.setTerminalSize(n, i), Array.isArray(this.arguments) && (this.arguments.forEach((e, t) => this.sandbox.context.setVar(String(t + 1), e)), this.sandbox.context.setVar("#", String(this.arguments.length)), this.sandbox.context.setVar("@", this.arguments.join(" ")), this.sandbox.context.setVar("*", this.arguments.join(" "))), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData);
1517
- let a = (e) => {
1547
+ let o = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, s = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
1548
+ typeof this.sandbox.setTerminalSize == "function" && this.sandbox.setTerminalSize(o, s), Array.isArray(this.arguments) && (this.arguments.forEach((e, t) => this.sandbox.context.setVar(String(t + 1), e)), this.sandbox.context.setVar("#", String(this.arguments.length)), this.sandbox.context.setVar("@", this.arguments.join(" ")), this.sandbox.context.setVar("*", this.arguments.join(" "))), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData);
1549
+ let c = (e) => {
1518
1550
  if (!this.sandbox || !this.sandbox.runningCommand) return;
1519
- let t = this.sandbox.runningCommand, n = t.stdinStream && t.stdinStream.listenerCount("data") > 1;
1551
+ let t = this.sandbox.runningCommand, n = i(t);
1520
1552
  if (t.interactive || t._inAltScreen || n) {
1521
1553
  t.stdinStream && t.stdinStream.pushData(e);
1522
1554
  return;
1523
1555
  }
1524
1556
  if (t.captureInput && typeof t.onInput == "function") {
1525
- let { parseVtKeys: n } = W();
1526
- for (let r of n(e)) {
1527
- if (r === "^C") {
1557
+ let n = !!(t.isRaw || t.stdinStream && t.stdinStream.isRaw);
1558
+ for (let i of r(e)) {
1559
+ if (i === "^C" && !n) {
1528
1560
  this.kill("SIGINT");
1529
1561
  return;
1530
1562
  }
1531
- (!t.stdinStream || !t.stdinStream.isRaw) && (r === "Enter" ? this.stdout.write("\r\n") : r === "Backspace" ? this.stdout.write("\b \b") : r.length === 1 && this.stdout.write(r)), t.onInput(r);
1563
+ n || (i === "Enter" ? this.stdout.write("\r\n") : i === "Backspace" ? this.stdout.write("\b \b") : i.length === 1 && this.stdout.write(i)), t.onInput(i);
1532
1564
  }
1533
1565
  }
1534
- }, o = () => {
1566
+ }, l = () => {
1535
1567
  this.sandbox && typeof this.sandbox.setTerminalSize == "function" && this.stdinStream && this.sandbox.setTerminalSize(this.stdinStream.columns, this.stdinStream.rows);
1568
+ }, u = () => {
1569
+ this.sandbox && typeof this.sandbox.setTerminalSize == "function" && this.stdout && this.sandbox.setTerminalSize(this.stdout.columns, this.stdout.rows);
1570
+ }, d = () => {
1571
+ this.stdinStream && typeof this.stdinStream.off == "function" && (this.stdinStream.off("data", c), this.stdinStream.off("resize", l)), this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", u);
1536
1572
  };
1537
- this.stdinStream && typeof this.stdinStream.on == "function" && (this.stdinStream.on("data", a), this.stdinStream.on("resize", o)), this.sandbox.on("stdOut", (e) => {
1573
+ this.stdinStream && typeof this.stdinStream.on == "function" && (this.stdinStream.on("data", c), this.stdinStream.on("resize", l)), this.stdout && this.stdout !== this.stdinStream && typeof this.stdout.on == "function" && this.stdout.on("resize", u), this.sandbox.on("stdOut", (e) => {
1538
1574
  this.stdOut = e, this.flush();
1539
1575
  }), this.sandbox.on("stdErr", (e) => {
1540
1576
  this.stdErr = e, this.flush();
@@ -1543,19 +1579,19 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1543
1579
  }), this.sandbox.stderr && typeof this.sandbox.stderr.on == "function" && this.sandbox.stderr.on("data", (e) => {
1544
1580
  this.stderr && typeof this.stderr.write == "function" && this.stderr.write(e);
1545
1581
  }), this._scriptFunctions = {};
1546
- let s = this.script.split(/\r?\n/);
1547
- if (!r(s[0])) {
1548
- let e = s[0].startsWith("#!") ? s[0].slice(2).split(/\s/)[0] : s[0];
1549
- return this.stdinStream && typeof this.stdinStream.off == "function" && (this.stdinStream.off("data", a), this.stdinStream.off("resize", o)), Promise.reject(`${e}: bad interpreter: No such file or directory`);
1582
+ let f = this.script.split(/\r?\n/);
1583
+ if (!a(f[0])) {
1584
+ let e = f[0].startsWith("#!") ? f[0].slice(2).split(/\s/)[0] : f[0];
1585
+ return d(), Promise.reject(`${e}: bad interpreter: No such file or directory`);
1550
1586
  }
1551
- let c = this._parseLines(s.slice(1));
1552
- return this._executeNodes(c).catch((e) => {
1587
+ let p = this._parseLines(f.slice(1));
1588
+ return this._executeNodes(p).catch((e) => {
1553
1589
  if (e && e.__type === "return") this.sandbox.lastCode = e.code;
1554
1590
  else if (e && e.__type === "errexit") this.sandbox.lastCode = e.code;
1555
1591
  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;
1556
1592
  else return Promise.reject(e);
1557
1593
  }).finally(() => {
1558
- this.stdinStream && typeof this.stdinStream.off == "function" && (this.stdinStream.off("data", a), this.stdinStream.off("resize", o));
1594
+ d();
1559
1595
  }).then(() => {
1560
1596
  this.exitCode = this.sandbox.lastCode, this.source && this.context.source(this.sandbox.context);
1561
1597
  });
@@ -1709,7 +1745,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1709
1745
  }
1710
1746
  _executeNode(e) {
1711
1747
  if (e.type === "function") {
1712
- let t = e.name, n = e.bodyLines, r = this, i = G(), a = class extends i {
1748
+ let t = e.name, n = e.bodyLines, r = this, i = ne(), a = class extends i {
1713
1749
  static get name() {
1714
1750
  return t;
1715
1751
  }
@@ -1913,9 +1949,9 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1913
1949
  return !1;
1914
1950
  }
1915
1951
  }
1916
- }, t.exports.isKnownInterpreter = r;
1917
- })), q = /* @__PURE__ */ t(((e, t) => {
1918
- var n = te();
1952
+ }, t.exports.isKnownInterpreter = a;
1953
+ })), G = /* @__PURE__ */ t(((e, t) => {
1954
+ var n = W();
1919
1955
  t.exports = class extends n {
1920
1956
  get captureInput() {
1921
1957
  return !0;
@@ -1924,19 +1960,16 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1924
1960
  return !0;
1925
1961
  }
1926
1962
  get terminalSize() {
1927
- return this.stdout && this.stdout.columns && this.stdout.rows ? {
1928
- cols: parseInt(this.context && this.context.getVar && this.context.getVar("COLUMNS"), 10) || this.stdout.columns || 80,
1929
- rows: parseInt(this.context && this.context.getVar && this.context.getVar("LINES"), 10) || this.stdout.rows || 24
1930
- } : {
1931
- cols: parseInt(this.context.getVar("COLUMNS"), 10) || 80,
1932
- rows: parseInt(this.context.getVar("LINES"), 10) || 24
1963
+ return {
1964
+ cols: this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80,
1965
+ rows: this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24
1933
1966
  };
1934
1967
  }
1935
1968
  _enterAltScreen() {
1936
1969
  this._inAltScreen || (this._inAltScreen = !0, this.stdinStream && this.stdinStream.setRawMode(!0), this.stdout && this.stdout.write("\x1B[?1049h\x1B[2J\x1B[H"));
1937
1970
  }
1938
1971
  _exitAltScreen() {
1939
- this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
1972
+ this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h"));
1940
1973
  }
1941
1974
  kill(e = "SIGINT") {
1942
1975
  this._exitAltScreen(), super.kill(e);
@@ -1947,8 +1980,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
1947
1980
  });
1948
1981
  }
1949
1982
  };
1950
- })), ne = /* @__PURE__ */ t(((e, t) => {
1951
- var n = q(), { createGenericWasmCommand: r } = Z(), 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 {
1983
+ })), K = /* @__PURE__ */ t(((e, t) => {
1984
+ var n = G(), { createGenericWasmCommand: r } = X(), 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 {
1952
1985
  get requiresFilesystem() {
1953
1986
  return !0;
1954
1987
  }
@@ -2217,7 +2250,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2217
2250
  return s;
2218
2251
  }
2219
2252
  f.createReplWasmCommand = p, f.createCommand = p, t.exports = f;
2220
- })), J = /* @__PURE__ */ t(((e, t) => {
2253
+ })), q = /* @__PURE__ */ t(((e, t) => {
2221
2254
  b();
2222
2255
  function n(e) {
2223
2256
  if (!e || e.length === 0) return !0;
@@ -2235,7 +2268,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2235
2268
  }
2236
2269
  }
2237
2270
  t.exports = n, t.exports.isUtf8Text = n;
2238
- })), re = /* @__PURE__ */ t(((e, t) => {
2271
+ })), ie = /* @__PURE__ */ t(((e, t) => {
2239
2272
  b();
2240
2273
  var r = new Set([
2241
2274
  "cwd",
@@ -2266,7 +2299,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2266
2299
  if (typeof t == "function") return t;
2267
2300
  let r = typeof t == "string" ? t : new TextDecoder().decode(t);
2268
2301
  /^\s*export\s+default\s+/m.test(r) && (r = r.replace(/^\s*export\s+default\s+/m, "module.exports = "));
2269
- let i = { exports: {} }, a = te(), o = G(), s = Z(), c = q(), l = ne();
2302
+ let i = { exports: {} }, a = W(), o = ne(), s = X(), c = G(), l = K();
2270
2303
  return Function("module", "exports", "require", "Command", "LocalCommand", "WasmCommand", "InteractiveCommand", "ReplCommand", r)(i, i.exports, n, a, o, s, c, l), i.exports.default === void 0 ? i.exports : i.exports.default;
2271
2304
  }
2272
2305
  isReadable(e) {
@@ -2291,12 +2324,13 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2291
2324
  return n;
2292
2325
  }
2293
2326
  sandbox() {
2294
- let e = this;
2327
+ let e = this, t = Symbol.for("brsh.fs.target");
2295
2328
  return new Proxy(Object.create(null), {
2296
- get(t, n) {
2297
- if (!r.has(n)) return;
2298
- let i = e[n];
2299
- return typeof i == "function" ? i.bind(e) : i;
2329
+ get(n, i) {
2330
+ if (i === t) return e;
2331
+ if (!r.has(i)) return;
2332
+ let a = e[i];
2333
+ return typeof a == "function" ? a.bind(e) : a;
2300
2334
  },
2301
2335
  set() {
2302
2336
  return !1;
@@ -2341,11 +2375,11 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2341
2375
  let e = this.read();
2342
2376
  return e == null ? "" : typeof e == "string" ? e : e.toString();
2343
2377
  }
2344
- }, c = J();
2378
+ }, c = q();
2345
2379
  t.exports = i, t.exports.BinaryFile = a, t.exports.SymlinkRef = o, t.exports.DeviceFile = s, t.exports.isUtf8Text = c;
2346
- })), ie = /* @__PURE__ */ t(((e, t) => {
2347
- b(), B();
2348
- var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = re(), a = new Uint8Array([
2380
+ })), ae = /* @__PURE__ */ t(((e, t) => {
2381
+ b(), z();
2382
+ var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = ie(), a = new Uint8Array([
2349
2383
  66,
2350
2384
  82,
2351
2385
  70,
@@ -2372,7 +2406,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2372
2406
  r
2373
2407
  ] };
2374
2408
  }
2375
- if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
2409
+ if (typeof e == "function") return n.commandsBundle || (d[t] = e.__source || e.toString()), { $c: t };
2376
2410
  if (typeof e == "string") {
2377
2411
  if (e.startsWith("data:")) {
2378
2412
  let t = e.indexOf(";"), n = e.indexOf(",", t);
@@ -2451,7 +2485,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2451
2485
  let t = e.$c;
2452
2486
  if (h[t]) return h[t];
2453
2487
  if (p.inlineCommands && p.inlineCommands[t]) try {
2454
- let e = te(), n = q();
2488
+ let e = W(), n = G();
2455
2489
  return Function("Command", "InteractiveCommand", `return (${p.inlineCommands[t]});`)(e, n);
2456
2490
  } catch {
2457
2491
  return null;
@@ -2483,8 +2517,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2483
2517
  let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
2484
2518
  return new Uint8Array(r);
2485
2519
  }
2486
- if (z !== void 0 && typeof z.getBuiltinModule == "function") {
2487
- let t = z.getBuiltinModule("zlib");
2520
+ if (R !== void 0 && typeof R.getBuiltinModule == "function") {
2521
+ let t = R.getBuiltinModule("zlib");
2488
2522
  if (t) return new Uint8Array(t.gunzipSync(y.from(e.buffer, e.byteOffset, e.byteLength)));
2489
2523
  }
2490
2524
  throw Error("Gzip decompression is not supported in this environment");
@@ -2503,8 +2537,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2503
2537
  return p(new Uint8Array(n), t);
2504
2538
  }
2505
2539
  if (typeof e == "string") {
2506
- if (!/^https?:\/\//i.test(e) && z !== void 0 && typeof z.getBuiltinModule == "function" && typeof window > "u") try {
2507
- let n = z.getBuiltinModule("fs");
2540
+ if (!/^https?:\/\//i.test(e) && R !== void 0 && typeof R.getBuiltinModule == "function" && typeof window > "u") try {
2541
+ let n = R.getBuiltinModule("fs");
2508
2542
  if (n && n.existsSync(e)) {
2509
2543
  let r = await n.promises.readFile(e);
2510
2544
  return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
@@ -2616,9 +2650,9 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2616
2650
  }
2617
2651
  }
2618
2652
  };
2619
- })), Y = /* @__PURE__ */ t(((e, t) => {
2653
+ })), J = /* @__PURE__ */ t(((e, t) => {
2620
2654
  b();
2621
- var n = re(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
2655
+ var n = ie(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
2622
2656
  function o(e) {
2623
2657
  for (let t of Object.keys(e)) {
2624
2658
  let n = e[t];
@@ -2642,10 +2676,10 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2642
2676
  t.exports = class extends n {
2643
2677
  constructor(e = "/", t = {}, n = {}, r = null) {
2644
2678
  if (super(), t instanceof Uint8Array || t instanceof ArrayBuffer) {
2645
- let { deserializeBinaryFilesystem: e } = ie(), r = e(t);
2679
+ let { deserializeBinaryFilesystem: e } = ae(), r = e(t);
2646
2680
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
2647
2681
  } 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)) {
2648
- let { deserializeBinaryFilesystem: e } = ie(), r = e(t);
2682
+ let { deserializeBinaryFilesystem: e } = ae(), r = e(t);
2649
2683
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
2650
2684
  }
2651
2685
  o(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e.endsWith("/") ? e : e + "/", this._onChange = r, this._changeScheduled = !1, this._initDevices();
@@ -2687,11 +2721,11 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2687
2721
  }), this._devices.stdin = new i("/dev/tty"), this._devices.stdout = new i("/dev/tty"), this._devices.stderr = new i("/dev/tty");
2688
2722
  }
2689
2723
  toBinaryContainer(e = {}) {
2690
- let { serializeBinaryFilesystem: t } = ie();
2724
+ let { serializeBinaryFilesystem: t } = ae();
2691
2725
  return t(this.fileSystem, this.permissions, e);
2692
2726
  }
2693
2727
  static fromBinaryContainer(e, t = {}) {
2694
- let { deserializeBinaryFilesystem: n } = ie();
2728
+ let { deserializeBinaryFilesystem: n } = ae();
2695
2729
  return n(e, t);
2696
2730
  }
2697
2731
  getFileByPath(e) {
@@ -2936,18 +2970,18 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2936
2970
  return null;
2937
2971
  }
2938
2972
  }, t.exports.BinaryFile = r, t.exports.SymlinkRef = i;
2939
- })), X = /* @__PURE__ */ t(((e, t) => {
2973
+ })), Y = /* @__PURE__ */ t(((e, t) => {
2940
2974
  t.exports = null;
2941
- })), Z = /* @__PURE__ */ t(((e, t) => {
2975
+ })), X = /* @__PURE__ */ t(((e, t) => {
2942
2976
  b();
2943
- var n = K(), { BinaryFile: r } = Y(), i = 0, a = 6, o = 8, s = 20, c = 28, l = 31, u = 44, d = 54, f = 70, p = 0, m = 2, h = 3, g = 4, _ = 1, v = 2, x = 4, S = 8, C = 1, w = 4, T = class extends n {
2977
+ var n = re(), { BinaryFile: r } = J(), i = 0, a = 6, o = 8, s = 20, c = 27, l = 28, u = 31, d = 44, f = 54, p = 70, m = 0, h = 2, g = 3, _ = 4, v = 1, x = 2, S = 4, C = 8, w = 1, T = 4, E = class extends n {
2944
2978
  constructor(e, t, n) {
2945
2979
  super(e, t, n), this._ensurePkgMeta();
2946
2980
  }
2947
2981
  _ensurePkgMeta() {
2948
2982
  if (this._pkgMeta === void 0 && this.script) {
2949
2983
  let e = this.context && this.context.fs || this.fs;
2950
- e && (this._pkgMeta = F(e, this.script));
2984
+ e && (this._pkgMeta = I(e, this.script));
2951
2985
  }
2952
2986
  return this._pkgMeta || null;
2953
2987
  }
@@ -2987,11 +3021,22 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
2987
3021
  this._inAltScreen || (this._inAltScreen = !0, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[?1049h\x1B[2J\x1B[H"));
2988
3022
  }
2989
3023
  _exitAltScreen() {
2990
- this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!1), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[?1049l\x1B[?25h"));
3024
+ this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!1), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h"));
2991
3025
  }
2992
3026
  _keyToBytes(e) {
2993
3027
  if (!e) return null;
2994
3028
  if (typeof e != "string") return e instanceof Uint8Array ? e : new Uint8Array([Number(e) & 255]);
3029
+ if ([
3030
+ "Control",
3031
+ "Alt",
3032
+ "Shift",
3033
+ "Meta",
3034
+ "CapsLock",
3035
+ "NumLock",
3036
+ "ScrollLock",
3037
+ "Dead",
3038
+ "Unidentified"
3039
+ ].includes(e)) return null;
2995
3040
  let t = e.match(/^\^([A-Za-z@\[\\\]^_?])$/);
2996
3041
  if (t) {
2997
3042
  let e = t[1].toUpperCase();
@@ -3000,19 +3045,40 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3000
3045
  let n = {
3001
3046
  Enter: "\r",
3002
3047
  Return: "\r",
3048
+ Space: " ",
3049
+ Spacebar: " ",
3003
3050
  Backspace: "",
3004
3051
  Tab: " ",
3052
+ BackTab: "\x1B[Z",
3005
3053
  Escape: "\x1B",
3054
+ Esc: "\x1B",
3006
3055
  ArrowUp: "\x1B[A",
3056
+ Up: "\x1B[A",
3007
3057
  ArrowDown: "\x1B[B",
3058
+ Down: "\x1B[B",
3008
3059
  ArrowRight: "\x1B[C",
3060
+ Right: "\x1B[C",
3009
3061
  ArrowLeft: "\x1B[D",
3062
+ Left: "\x1B[D",
3010
3063
  Home: "\x1B[H",
3011
3064
  End: "\x1B[F",
3012
3065
  PageUp: "\x1B[5~",
3013
3066
  PageDown: "\x1B[6~",
3014
3067
  Delete: "\x1B[3~",
3015
- Insert: "\x1B[2~"
3068
+ Del: "\x1B[3~",
3069
+ Insert: "\x1B[2~",
3070
+ F1: "\x1BOP",
3071
+ F2: "\x1BOQ",
3072
+ F3: "\x1BOR",
3073
+ F4: "\x1BOS",
3074
+ F5: "\x1B[15~",
3075
+ F6: "\x1B[17~",
3076
+ F7: "\x1B[18~",
3077
+ F8: "\x1B[19~",
3078
+ F9: "\x1B[20~",
3079
+ F10: "\x1B[21~",
3080
+ F11: "\x1B[23~",
3081
+ F12: "\x1B[24~"
3016
3082
  };
3017
3083
  return n[e] ? new TextEncoder().encode(n[e]) : new TextEncoder().encode(e);
3018
3084
  }
@@ -3033,7 +3099,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3033
3099
  run() {
3034
3100
  let e = this.script, t = (() => {
3035
3101
  try {
3036
- return X();
3102
+ return Y();
3037
3103
  } catch {
3038
3104
  return null;
3039
3105
  }
@@ -3064,7 +3130,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3064
3130
  isWat: this._isWat(e, i)
3065
3131
  });
3066
3132
  }
3067
- return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = j(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
3133
+ return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = M(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
3068
3134
  }
3069
3135
  _isWat(e, t) {
3070
3136
  return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
@@ -3105,12 +3171,12 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3105
3171
  let t = {
3106
3172
  1: "",
3107
3173
  2: ""
3108
- }, n = new TextDecoder(), b = new TextEncoder(), T = null, E = null, D = !1, O = 0, k = null, A = null, N = null, P = null, F = this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY, I = !!(this.interactive && F);
3109
- I && (this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"));
3110
- let L = () => {
3111
- I || !F || (I = !0, this._isInteractive = !0, this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"), this._enterAltScreen(), t[1] &&= (this.stdout && typeof this.stdout.write == "function" && this.stdout.write(t[1]), ""), t[2] &&= (this.stderr && typeof this.stderr.write == "function" && this.stderr.write(t[2]), ""), this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0));
3112
- }, R = (e, n) => {
3113
- if (I && (e === 1 || e === 2)) {
3174
+ }, n = new TextDecoder(), b = new TextEncoder(), E = null, D = null, O = !1, k = 0, A = null, j = null, P = null, F = !1, I = !1, L = !1, ee = null, R = null, z = null, B = this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY, V = !!(this.interactive && B);
3175
+ V && (this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"));
3176
+ let H = () => {
3177
+ V || !B || (V = !0, this._isInteractive = !0, this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive"), this._enterAltScreen(), t[1] &&= (this.stdout && typeof this.stdout.write == "function" && this.stdout.write(t[1]), ""), t[2] &&= (this.stderr && typeof this.stderr.write == "function" && this.stderr.write(t[2]), ""), this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0));
3178
+ }, U = (e, n) => {
3179
+ if (V && (e === 1 || e === 2)) {
3114
3180
  if (e === 1 && this.stdout) {
3115
3181
  this.stdout.write(n);
3116
3182
  return;
@@ -3124,61 +3190,63 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3124
3190
  let r = t[e].split("\n");
3125
3191
  t[e] = r.pop();
3126
3192
  for (let t of r) e === 1 ? this.stdOut = t : this.stdErr = t;
3127
- }, z = () => {
3128
- t[1] &&= (I && this.stdout ? this.stdout.write(t[1]) : this.stdOut = t[1], ""), t[2] &&= (I && this.stderr ? this.stderr.write(t[2]) : this.stdErr = t[2], "");
3129
- }, B = [], ee = (e) => {
3193
+ }, te = () => {
3194
+ t[1] &&= (V && this.stdout ? this.stdout.write(t[1]) : this.stdOut = t[1], ""), t[2] &&= (V && this.stderr ? this.stderr.write(t[2]) : this.stdErr = t[2], "");
3195
+ }, W = [], ne = (e) => {
3130
3196
  if (!(!e || e.length === 0)) {
3131
- for (let t = 0; t < e.length; t++) B.push(e[t]);
3132
- if (A) {
3133
- let e = A;
3134
- A = null, e();
3197
+ for (let t = 0; t < e.length; t++) W.push(e[t]);
3198
+ if (j) {
3199
+ let e = j;
3200
+ j = null, e();
3135
3201
  }
3136
3202
  }
3137
3203
  };
3138
- P = (e) => {
3204
+ z = (e) => {
3139
3205
  this._handlingStreamData = !0;
3140
3206
  try {
3141
- ee(typeof e == "string" ? b.encode(e) : e instanceof Uint8Array ? e : y !== void 0 && y.isBuffer(e) ? new Uint8Array(e) : b.encode(String(e ?? "")));
3207
+ ne(typeof e == "string" ? b.encode(e) : e instanceof Uint8Array ? e : y !== void 0 && y.isBuffer(e) ? new Uint8Array(e) : b.encode(String(e ?? "")));
3142
3208
  } finally {
3143
3209
  this._handlingStreamData = !1;
3144
3210
  }
3145
3211
  }, this._externalKeyHandler = (e) => {
3146
3212
  if (this._handlingStreamData) return;
3147
3213
  let t = this._keyToBytes(e);
3148
- t && ee(t);
3149
- }, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData), F && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", P), F && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", P);
3150
- let V = !F && typeof this.stdin == "string" ? b.encode(this.stdin) : !F && this.stdin instanceof Uint8Array ? this.stdin : !F && y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), H = 0, U = this.context && this.context.fs ? this.context.fs : this.fs, W = this.context && this.context.fs && this.context.fs.cwd || this.fs && this.fs.cwd || this.context && typeof this.context.getVar == "function" && this.context.getVar("PWD") || U && U.cwd || "/", te = W.length > 1 && W.endsWith("/") ? W.slice(0, -1) : W, G = 5, K = new Map([[3, {
3214
+ t && ne(t);
3215
+ };
3216
+ let re = !!(this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.listeners == "function" && this.stdinStream.listeners("data").includes(this._onStdinStreamData));
3217
+ re && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData), B && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", z), B && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", z);
3218
+ let G = !B && typeof this.stdin == "string" ? b.encode(this.stdin) : !B && this.stdin instanceof Uint8Array ? this.stdin : !B && y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), K = 0, q = this.context && this.context.fs ? this.context.fs : this.fs, ie = this.context && this.context.fs && this.context.fs.cwd || this.fs && this.fs.cwd || this.context && typeof this.context.getVar == "function" && this.context.getVar("PWD") || q && q.cwd || "/", ae = ie.length > 1 && ie.endsWith("/") ? ie.slice(0, -1) : ie, J = 5, Y = new Map([[3, {
3151
3219
  type: "preopen",
3152
3220
  path: "/",
3153
3221
  guestName: "/"
3154
3222
  }], [4, {
3155
3223
  type: "preopen",
3156
- path: te,
3224
+ path: ae,
3157
3225
  guestName: "."
3158
- }]]), q = new Map([
3226
+ }]]), X = new Map([
3159
3227
  [0, 0],
3160
3228
  [1, 0],
3161
3229
  [2, 0]
3162
- ]), ne = (e) => {
3230
+ ]), oe = (e) => {
3163
3231
  let t = e.split("/").filter(Boolean);
3164
3232
  return t.pop(), "/" + t.join("/");
3165
- }, J = (e, t) => {
3166
- let n = K.get(e);
3233
+ }, Z = (e, t) => {
3234
+ let n = Y.get(e);
3167
3235
  if (!n || n.type !== "preopen" && n.type !== "dir") return null;
3168
- if (t.startsWith("/")) return U.absolutePath(t);
3169
- if (!t || t === ".") return U.absolutePath(n.path);
3170
- let r = n.path.endsWith("/") ? n.path : n.path + "/", i = U.absolutePath(r + t), a = U.absolutePath("/" + t);
3236
+ if (t.startsWith("/")) return q.absolutePath(t);
3237
+ if (!t || t === ".") return q.absolutePath(n.path);
3238
+ let r = n.path.endsWith("/") ? n.path : n.path + "/", i = q.absolutePath(r + t), a = q.absolutePath("/" + t);
3171
3239
  if (n.path !== "/") {
3172
- if (U.exists(i)) return i;
3173
- if (U.exists(a)) return a;
3174
- let e = U.exists(ne(i));
3175
- return U.exists(ne(a)) && !e ? a : i;
3240
+ if (q.exists(i)) return i;
3241
+ if (q.exists(a)) return a;
3242
+ let e = q.exists(oe(i));
3243
+ return q.exists(oe(a)) && !e ? a : i;
3176
3244
  }
3177
- if (U.exists(i)) return i;
3178
- let o = U.absolutePath(t);
3179
- return U.exists(o) ? o : i;
3180
- }, re = (e) => {
3181
- if (!(!e || e.type !== "file" || !e.dirty || !U)) try {
3245
+ if (q.exists(i)) return i;
3246
+ let o = q.absolutePath(t);
3247
+ return q.exists(o) ? o : i;
3248
+ }, se = (e) => {
3249
+ if (!(!e || e.type !== "file" || !e.dirty || !q)) try {
3182
3250
  let t = !0;
3183
3251
  for (let n = 0; n < e.bytes.length; n++) if (e.bytes[n] === 0) {
3184
3252
  t = !1;
@@ -3186,32 +3254,32 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3186
3254
  }
3187
3255
  if (t) {
3188
3256
  let t = n.decode(e.bytes);
3189
- U.setFileByPath(e.path, t, !0);
3257
+ q.setFileByPath(e.path, t, !0);
3190
3258
  } else {
3191
3259
  let t = new Uint8Array(e.bytes.length);
3192
- t.set(e.bytes), U.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
3260
+ t.set(e.bytes), q.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
3193
3261
  }
3194
3262
  e.dirty = !1;
3195
3263
  } catch {}
3196
- }, ie = {
3264
+ }, ce = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, le = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24, ue = {
3197
3265
  TERM: "xterm-256color",
3198
3266
  COLORTERM: "truecolor",
3199
- COLUMNS: String(this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && this.context.getVar("COLUMNS") || 80),
3200
- LINES: String(this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && this.context.getVar("LINES") || 24),
3201
- ...this.context && this.context.vars || {}
3202
- }, Y = Object.entries(ie).map(([e, t]) => `${e}=${t}`), X = new Proxy({
3267
+ ...this.context && this.context.vars || {},
3268
+ COLUMNS: String(ce),
3269
+ LINES: String(le)
3270
+ }, Q = Object.entries(ue).map(([e, t]) => `${e}=${t}`), de = new Proxy({
3203
3271
  fd_write: (e, t, r, a) => {
3204
- if (!T) return o;
3205
- let s = new DataView(T.buffer);
3272
+ if (!E) return o;
3273
+ let s = new DataView(E.buffer);
3206
3274
  if (e === 1 || e === 2) {
3207
3275
  let o = 0;
3208
3276
  for (let i = 0; i < r; i++) {
3209
3277
  let r = s.getUint32(t + i * 8, !0), a = s.getUint32(t + i * 8 + 4, !0);
3210
- a > 0 && R(e, n.decode(new Uint8Array(T.buffer, r, a))), o += a;
3278
+ a > 0 && U(e, n.decode(new Uint8Array(E.buffer, r, a))), o += a;
3211
3279
  }
3212
3280
  return s.setUint32(a, o, !0), i;
3213
3281
  }
3214
- let c = K.get(e);
3282
+ let c = Y.get(e);
3215
3283
  if (!c) return o;
3216
3284
  if (c.type === "dev_null" || c.type === "dev_zero") {
3217
3285
  let e = 0;
@@ -3222,7 +3290,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3222
3290
  let e = 0;
3223
3291
  for (let i = 0; i < r; i++) {
3224
3292
  let r = s.getUint32(t + i * 8, !0), a = s.getUint32(t + i * 8 + 4, !0);
3225
- a > 0 && R(1, n.decode(new Uint8Array(T.buffer, r, a))), e += a;
3293
+ a > 0 && U(1, n.decode(new Uint8Array(E.buffer, r, a))), e += a;
3226
3294
  }
3227
3295
  return s.setUint32(a, e, !0), i;
3228
3296
  }
@@ -3231,7 +3299,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3231
3299
  for (let e = 0; e < r; e++) {
3232
3300
  let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0);
3233
3301
  if (r > 0) {
3234
- let e = new Uint8Array(T.buffer, n, r), t = c.append ? c.bytes.length : c.pos, i = t + r;
3302
+ let e = new Uint8Array(E.buffer, n, r), t = c.append ? c.bytes.length : c.pos, i = t + r;
3235
3303
  if (i > c.bytes.length) {
3236
3304
  let e = new Uint8Array(i);
3237
3305
  e.set(c.bytes), c.bytes = e;
@@ -3242,276 +3310,282 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3242
3310
  return s.setUint32(a, l, !0), i;
3243
3311
  },
3244
3312
  fd_read: (e, t, n, r) => {
3245
- if (!T) return o;
3246
- let s = new DataView(T.buffer), c = K.get(e), l = !!(c && c.type === "dev_tty");
3247
- if (e === 0 || I && e === 2 || l) {
3248
- (l || e === 2) && L();
3249
- let o = !!((q.get(e) || 0) & w);
3250
- if (D) {
3251
- if ((typeof E?.exports?.asyncify_get_state == "function" ? E.exports.asyncify_get_state() : 0) === 2) {
3252
- E.exports.asyncify_stop_rewind();
3313
+ if (!E) return o;
3314
+ let s = new DataView(E.buffer), l = Y.get(e), u = !!(l && l.type === "dev_tty");
3315
+ if (e === 0 || V && e === 2 || u) {
3316
+ (u || e === 2) && H();
3317
+ let o = !!((X.get(e) || 0) & T);
3318
+ if (O) {
3319
+ if ((typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2) {
3320
+ if (D.exports.asyncify_stop_rewind(), L && W.length === 0) return L = !1, s.setUint32(r, 0, !0), c;
3321
+ L = !1;
3253
3322
  let e = 0;
3254
- for (let r = 0; r < n && B.length > 0; r++) {
3255
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, B.length), o = B.splice(0, a);
3256
- new Uint8Array(T.buffer).set(o, n), e += a;
3323
+ for (let r = 0; r < n && W.length > 0; r++) {
3324
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, W.length), o = W.splice(0, a);
3325
+ new Uint8Array(E.buffer).set(o, n), e += a;
3257
3326
  }
3258
3327
  return s.setUint32(r, e, !0), i;
3259
3328
  }
3260
- if (B.length > 0) {
3329
+ if (W.length > 0) {
3261
3330
  let e = 0;
3262
- for (let r = 0; r < n && B.length > 0; r++) {
3263
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, B.length), o = B.splice(0, a);
3264
- new Uint8Array(T.buffer).set(o, n), e += a;
3331
+ for (let r = 0; r < n && W.length > 0; r++) {
3332
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, W.length), o = W.splice(0, a);
3333
+ new Uint8Array(E.buffer).set(o, n), e += a;
3265
3334
  }
3266
3335
  return s.setUint32(r, e, !0), i;
3267
3336
  }
3268
- return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
3269
- A = e, this._pendingReadResolve = e, this._asyncifyReject = t;
3337
+ return o ? (s.setUint32(r, 0, !0), a) : (L = !1, D.exports.asyncify_start_unwind(k), A = new Promise((e, t) => {
3338
+ let n = () => {
3339
+ L = !1, j = null, P = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3340
+ };
3341
+ j = n, this._pendingReadResolve = n, P = () => {
3342
+ L = !0, j = null, P = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3343
+ }, this._asyncifyReject = t;
3270
3344
  }), s.setUint32(r, 0, !0), i);
3271
3345
  }
3272
- if (B.length > 0) {
3346
+ if (W.length > 0) {
3273
3347
  let e = 0;
3274
- for (let r = 0; r < n && B.length > 0; r++) {
3275
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, B.length), o = B.splice(0, a);
3276
- new Uint8Array(T.buffer).set(o, n), e += a;
3348
+ for (let r = 0; r < n && W.length > 0; r++) {
3349
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = Math.min(i, W.length), o = W.splice(0, a);
3350
+ new Uint8Array(E.buffer).set(o, n), e += a;
3277
3351
  }
3278
3352
  return s.setUint32(r, e, !0), i;
3279
3353
  }
3280
- let c = 0;
3281
- for (let e = 0; e < n && H < V.length; e++) {
3282
- let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, V.length - H);
3283
- new Uint8Array(T.buffer).set(V.slice(H, H + i), n), H += i, c += i;
3354
+ let l = 0;
3355
+ for (let e = 0; e < n && K < G.length; e++) {
3356
+ let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, G.length - K);
3357
+ new Uint8Array(E.buffer).set(G.slice(K, K + i), n), K += i, l += i;
3284
3358
  }
3285
- return c === 0 && o && H >= V.length ? (s.setUint32(r, 0, !0), a) : (s.setUint32(r, c, !0), i);
3359
+ return l === 0 && o && K >= G.length ? (s.setUint32(r, 0, !0), a) : (s.setUint32(r, l, !0), i);
3286
3360
  }
3287
- if (!c) return o;
3288
- if (c.type === "dev_null") return s.setUint32(r, 0, !0), i;
3289
- if (c.type === "dev_zero") {
3361
+ if (!l) return o;
3362
+ if (l.type === "dev_null") return s.setUint32(r, 0, !0), i;
3363
+ if (l.type === "dev_zero") {
3290
3364
  let e = 0;
3291
3365
  for (let r = 0; r < n; r++) {
3292
3366
  let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0);
3293
- new Uint8Array(T.buffer, n, i).fill(0), e += i;
3367
+ new Uint8Array(E.buffer, n, i).fill(0), e += i;
3294
3368
  }
3295
3369
  return s.setUint32(r, e, !0), i;
3296
3370
  }
3297
- if (c.type === "dev_urandom") {
3371
+ if (l.type === "dev_urandom") {
3298
3372
  let e = 0;
3299
3373
  for (let r = 0; r < n; r++) {
3300
- let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = new Uint8Array(T.buffer, n, i);
3374
+ let n = s.getUint32(t + r * 8, !0), i = s.getUint32(t + r * 8 + 4, !0), a = new Uint8Array(E.buffer, n, i);
3301
3375
  if (typeof crypto < "u" && crypto.getRandomValues) crypto.getRandomValues(a);
3302
3376
  else for (let e = 0; e < i; e++) a[e] = Math.floor(Math.random() * 256);
3303
3377
  e += i;
3304
3378
  }
3305
3379
  return s.setUint32(r, e, !0), i;
3306
3380
  }
3307
- if (c.type !== "file") return o;
3308
- let u = 0;
3309
- for (let e = 0; e < n && c.pos < c.bytes.length; e++) {
3310
- let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, c.bytes.length - c.pos);
3311
- new Uint8Array(T.buffer).set(c.bytes.subarray(c.pos, c.pos + i), n), c.pos += i, u += i;
3381
+ if (l.type !== "file") return o;
3382
+ let d = 0;
3383
+ for (let e = 0; e < n && l.pos < l.bytes.length; e++) {
3384
+ let n = s.getUint32(t + e * 8, !0), r = s.getUint32(t + e * 8 + 4, !0), i = Math.min(r, l.bytes.length - l.pos);
3385
+ new Uint8Array(E.buffer).set(l.bytes.subarray(l.pos, l.pos + i), n), l.pos += i, d += i;
3312
3386
  }
3313
- return s.setUint32(r, u, !0), i;
3387
+ return s.setUint32(r, d, !0), i;
3314
3388
  },
3315
3389
  fd_seek: (e, t, n, r, a) => {
3316
- if (!T) return o;
3317
- if (e <= 2) return f;
3318
- let s = K.get(e);
3390
+ if (!E) return o;
3391
+ if (e <= 2) return p;
3392
+ let s = Y.get(e);
3319
3393
  if (!s) return o;
3320
- if (s.type === "dev_tty" || s.type === "dev_null" || s.type === "dev_zero" || s.type === "dev_urandom") return f;
3394
+ if (s.type === "dev_tty" || s.type === "dev_null" || s.type === "dev_zero" || s.type === "dev_urandom") return p;
3321
3395
  if (s.type !== "file") return o;
3322
- let l, u, d;
3323
- typeof t == "bigint" ? (l = Number(t), u = n, d = r) : (l = t, u = r, d = a);
3324
- let p = s.pos;
3325
- if (u === 0) p = l;
3326
- else if (u === 1) p = s.pos + l;
3327
- else if (u === 2) p = s.bytes.length + l;
3328
- else return c;
3329
- return p < 0 ? c : (s.pos = p, d && new DataView(T.buffer).setBigUint64(d, BigInt(s.pos), !0), i);
3396
+ let c, u, d;
3397
+ typeof t == "bigint" ? (c = Number(t), u = n, d = r) : (c = t, u = r, d = a);
3398
+ let f = s.pos;
3399
+ if (u === 0) f = c;
3400
+ else if (u === 1) f = s.pos + c;
3401
+ else if (u === 2) f = s.bytes.length + c;
3402
+ else return l;
3403
+ return f < 0 ? l : (s.pos = f, d && new DataView(E.buffer).setBigUint64(d, BigInt(s.pos), !0), i);
3330
3404
  },
3331
3405
  fd_tell: (e, t) => {
3332
- if (!T) return o;
3333
- let n = K.get(e);
3334
- return !n || n.type !== "file" ? o : (new DataView(T.buffer).setBigUint64(t, BigInt(n.pos), !0), i);
3406
+ if (!E) return o;
3407
+ let n = Y.get(e);
3408
+ return !n || n.type !== "file" ? o : (new DataView(E.buffer).setBigUint64(t, BigInt(n.pos), !0), i);
3335
3409
  },
3336
3410
  fd_close: (e) => {
3337
3411
  if (e <= 2) return i;
3338
- let t = K.get(e);
3339
- return t ? (t.type === "file" && re(t), K.delete(e), q.delete(e), i) : o;
3412
+ let t = Y.get(e);
3413
+ return t ? (t.type === "file" && se(t), Y.delete(e), X.delete(e), i) : o;
3340
3414
  },
3341
3415
  fd_sync: (e) => {
3342
- let t = K.get(e);
3343
- return t && re(t), i;
3416
+ let t = Y.get(e);
3417
+ return t && se(t), i;
3344
3418
  },
3345
3419
  fd_datasync: (e) => {
3346
- let t = K.get(e);
3347
- return t && re(t), i;
3420
+ let t = Y.get(e);
3421
+ return t && se(t), i;
3348
3422
  },
3349
3423
  fd_prestat_get: (e, t) => {
3350
- if (!T) return o;
3351
- let n = K.get(e);
3424
+ if (!E) return o;
3425
+ let n = Y.get(e);
3352
3426
  if (!n || n.type !== "preopen") return o;
3353
- let r = new DataView(T.buffer), a = b.encode(n.guestName);
3427
+ let r = new DataView(E.buffer), a = b.encode(n.guestName);
3354
3428
  return r.setUint8(t, 0), r.setUint32(t + 4, a.length, !0), i;
3355
3429
  },
3356
3430
  fd_prestat_dir_name: (e, t, n) => {
3357
- if (!T) return o;
3358
- let r = K.get(e);
3431
+ if (!E) return o;
3432
+ let r = Y.get(e);
3359
3433
  if (!r || r.type !== "preopen") return o;
3360
3434
  let a = b.encode(r.guestName);
3361
- return new Uint8Array(T.buffer, t, Math.min(n, a.length)).set(a.subarray(0, n)), i;
3435
+ return new Uint8Array(E.buffer, t, Math.min(n, a.length)).set(a.subarray(0, n)), i;
3362
3436
  },
3363
3437
  fd_fdstat_get: (e, t) => {
3364
- if (!T) return o;
3365
- let n = new DataView(T.buffer), r = p;
3366
- if (e <= 2) r = m;
3438
+ if (!E) return o;
3439
+ let n = new DataView(E.buffer), r = m;
3440
+ if (e <= 2) r = h;
3367
3441
  else {
3368
- let t = K.get(e);
3442
+ let t = Y.get(e);
3369
3443
  if (!t) return o;
3370
- r = t.type === "dev_null" || t.type === "dev_zero" || t.type === "dev_urandom" || t.type === "dev_tty" ? m : t.type === "preopen" || t.type === "dir" ? h : g;
3444
+ r = t.type === "dev_null" || t.type === "dev_zero" || t.type === "dev_urandom" || t.type === "dev_tty" ? h : t.type === "preopen" || t.type === "dir" ? g : _;
3371
3445
  }
3372
3446
  for (let e = 0; e < 24; e++) n.setUint8(t + e, 0);
3373
3447
  n.setUint8(t, r);
3374
- let a = q.get(e) || (K.get(e)?.append ? C : 0);
3448
+ let a = X.get(e) || (Y.get(e)?.append ? w : 0);
3375
3449
  return n.setUint16(t + 2, a, !0), n.setBigUint64(t + 8, 18446744073709551615n, !0), n.setBigUint64(t + 16, 18446744073709551615n, !0), i;
3376
3450
  },
3377
3451
  fd_fdstat_set_flags: (e, t) => {
3378
- if (!T || e > 2 && !K.has(e)) return o;
3379
- q.set(e, t);
3380
- let n = K.get(e);
3381
- return n && (n.append = !!(t & C)), (e === 0 || e === 2 || n && n.type === "dev_tty") && t & w && L(), i;
3452
+ if (!E || e > 2 && !Y.has(e)) return o;
3453
+ X.set(e, t);
3454
+ let n = Y.get(e);
3455
+ return n && (n.append = !!(t & w)), (e === 0 || e === 2 || n && n.type === "dev_tty") && t & T && H(), i;
3382
3456
  },
3383
3457
  fd_filestat_get: (e, t) => {
3384
- if (!T) return o;
3385
- let n = new DataView(T.buffer);
3458
+ if (!E) return o;
3459
+ let n = new DataView(E.buffer);
3386
3460
  for (let e = 0; e < 64; e++) n.setUint8(t + e, 0);
3387
- if (e <= 2) return n.setUint8(t + 16, m), i;
3388
- let r = K.get(e);
3461
+ if (e <= 2) return n.setUint8(t + 16, h), i;
3462
+ let r = Y.get(e);
3389
3463
  if (!r) return o;
3390
- if (r.type === "dev_null" || r.type === "dev_zero" || r.type === "dev_urandom" || r.type === "dev_tty") return n.setUint8(t + 16, m), n.setBigUint64(t + 24, 1n, !0), i;
3464
+ if (r.type === "dev_null" || r.type === "dev_zero" || r.type === "dev_urandom" || r.type === "dev_tty") return n.setUint8(t + 16, h), n.setBigUint64(t + 24, 1n, !0), i;
3391
3465
  let a = r.type === "preopen" || r.type === "dir";
3392
- return n.setUint8(t + 16, a ? h : g), n.setBigUint64(t + 24, 1n, !0), n.setBigUint64(t + 32, BigInt(r.bytes ? r.bytes.length : 0), !0), i;
3466
+ return n.setUint8(t + 16, a ? g : _), n.setBigUint64(t + 24, 1n, !0), n.setBigUint64(t + 32, BigInt(r.bytes ? r.bytes.length : 0), !0), i;
3393
3467
  },
3394
- path_open: (e, t, r, a, c, f, p, m, h) => {
3395
- if (!T || !U) return o;
3396
- let g = J(e, n.decode(new Uint8Array(T.buffer, r, a)));
3468
+ path_open: (e, t, r, a, c, l, p, m, h) => {
3469
+ if (!E || !q) return o;
3470
+ let g = Z(e, n.decode(new Uint8Array(E.buffer, r, a)));
3397
3471
  if (!g) return o;
3398
- let y = g.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
3399
- if (y === "/dev/null") {
3400
- let e = G++;
3401
- return K.set(e, {
3472
+ let _ = g.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
3473
+ if (_ === "/dev/null") {
3474
+ let e = J++;
3475
+ return Y.set(e, {
3402
3476
  type: "dev_null",
3403
3477
  path: "/dev/null"
3404
- }), new DataView(T.buffer).setUint32(h, e, !0), i;
3478
+ }), new DataView(E.buffer).setUint32(h, e, !0), i;
3405
3479
  }
3406
- if (y === "/dev/zero") {
3407
- let e = G++;
3408
- return K.set(e, {
3480
+ if (_ === "/dev/zero") {
3481
+ let e = J++;
3482
+ return Y.set(e, {
3409
3483
  type: "dev_zero",
3410
3484
  path: "/dev/zero"
3411
- }), new DataView(T.buffer).setUint32(h, e, !0), i;
3485
+ }), new DataView(E.buffer).setUint32(h, e, !0), i;
3412
3486
  }
3413
- if (y === "/dev/urandom" || y === "/dev/random") {
3414
- let e = G++;
3415
- return K.set(e, {
3487
+ if (_ === "/dev/urandom" || _ === "/dev/random") {
3488
+ let e = J++;
3489
+ return Y.set(e, {
3416
3490
  type: "dev_urandom",
3417
- path: y
3418
- }), new DataView(T.buffer).setUint32(h, e, !0), i;
3491
+ path: _
3492
+ }), new DataView(E.buffer).setUint32(h, e, !0), i;
3419
3493
  }
3420
- if (y === "/dev/tty" || y === "/dev/stdin") {
3421
- L();
3422
- let e = G++;
3423
- return K.set(e, {
3494
+ if (_ === "/dev/tty" || _ === "/dev/stdin") {
3495
+ H();
3496
+ let e = J++;
3497
+ return Y.set(e, {
3424
3498
  type: "dev_tty",
3425
- path: y
3426
- }), new DataView(T.buffer).setUint32(h, e, !0), i;
3499
+ path: _
3500
+ }), new DataView(E.buffer).setUint32(h, e, !0), i;
3427
3501
  }
3428
- if (y === "/dev/stdout") return new DataView(T.buffer).setUint32(h, 1, !0), i;
3429
- if (y === "/dev/stderr") return new DataView(T.buffer).setUint32(h, 2, !0), i;
3430
- let w = U.stat(g), E = w !== null;
3431
- if (c & x && c & _ && E) return s;
3432
- if (c & v) {
3433
- if (!E) return u;
3434
- if (!w.isDirectory) return d;
3435
- let e = G++;
3436
- return K.set(e, {
3502
+ if (_ === "/dev/stdout") return new DataView(E.buffer).setUint32(h, 1, !0), i;
3503
+ if (_ === "/dev/stderr") return new DataView(E.buffer).setUint32(h, 2, !0), i;
3504
+ let y = q.stat(g), T = y !== null;
3505
+ if (c & S && c & v && T) return s;
3506
+ if (c & x) {
3507
+ if (!T) return d;
3508
+ if (!y.isDirectory) return f;
3509
+ let e = J++;
3510
+ return Y.set(e, {
3437
3511
  type: "dir",
3438
3512
  path: g
3439
- }), new DataView(T.buffer).setUint32(h, e, !0), i;
3513
+ }), new DataView(E.buffer).setUint32(h, e, !0), i;
3440
3514
  }
3441
- if (E && w.isDirectory) return l;
3442
- if (!E && !(c & _)) return u;
3515
+ if (T && y.isDirectory) return u;
3516
+ if (!T && !(c & v)) return d;
3443
3517
  let D = new Uint8Array(), O = !1;
3444
- if (E && !(c & S)) {
3445
- let e = U.getFileByPath(g);
3518
+ if (T && !(c & C)) {
3519
+ let e = q.getFileByPath(g);
3446
3520
  e != null && (D = typeof e == "string" ? b.encode(e) : new Uint8Array(this._contentToBytes(e)));
3447
3521
  } else O = !0;
3448
- let k = G++;
3449
- return K.set(k, {
3522
+ let k = J++;
3523
+ return Y.set(k, {
3450
3524
  type: "file",
3451
3525
  path: g,
3452
3526
  bytes: D,
3453
- pos: m & C ? D.length : 0,
3454
- append: !!(m & C),
3527
+ pos: m & w ? D.length : 0,
3528
+ append: !!(m & w),
3455
3529
  dirty: O
3456
- }), new DataView(T.buffer).setUint32(h, k, !0), i;
3530
+ }), new DataView(E.buffer).setUint32(h, k, !0), i;
3457
3531
  },
3458
3532
  path_filestat_get: (e, t, r, a, s) => {
3459
- if (!T || !U) return o;
3460
- let c = J(e, n.decode(new Uint8Array(T.buffer, r, a)));
3533
+ if (!E || !q) return o;
3534
+ let c = Z(e, n.decode(new Uint8Array(E.buffer, r, a)));
3461
3535
  if (!c) return o;
3462
- let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", d = U.stat(c);
3463
- if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty" || l === "/dev/stdin" || l === "/dev/stdout" || l === "/dev/stderr" || d && (d.isDevice || d.isCharacterDevice)) {
3464
- let e = new DataView(T.buffer);
3536
+ let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", u = q.stat(c);
3537
+ if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty" || l === "/dev/stdin" || l === "/dev/stdout" || l === "/dev/stderr" || u && (u.isDevice || u.isCharacterDevice)) {
3538
+ let e = new DataView(E.buffer);
3465
3539
  for (let t = 0; t < 64; t++) e.setUint8(s + t, 0);
3466
- return e.setUint8(s + 16, m), e.setBigUint64(s + 24, 1n, !0), i;
3540
+ return e.setUint8(s + 16, h), e.setBigUint64(s + 24, 1n, !0), i;
3467
3541
  }
3468
- if (!d) return u;
3469
- let f = new DataView(T.buffer);
3542
+ if (!u) return d;
3543
+ let f = new DataView(E.buffer);
3470
3544
  for (let e = 0; e < 64; e++) f.setUint8(s + e, 0);
3471
- return f.setUint8(s + 16, d.isDirectory ? h : g), f.setBigUint64(s + 24, 1n, !0), f.setBigUint64(s + 32, BigInt(U.getSize(c) || 0), !0), i;
3545
+ return f.setUint8(s + 16, u.isDirectory ? g : _), f.setBigUint64(s + 24, 1n, !0), f.setBigUint64(s + 32, BigInt(q.getSize(c) || 0), !0), i;
3472
3546
  },
3473
3547
  path_create_directory: (e, t, r) => {
3474
- if (!T || !U) return o;
3475
- let a = J(e, n.decode(new Uint8Array(T.buffer, t, r)));
3548
+ if (!E || !q) return o;
3549
+ let a = Z(e, n.decode(new Uint8Array(E.buffer, t, r)));
3476
3550
  if (!a) return o;
3477
- if (U.exists(a)) return s;
3551
+ if (q.exists(a)) return s;
3478
3552
  try {
3479
- return U.setFileByPath(a, {}, !0), i;
3553
+ return q.setFileByPath(a, {}, !0), i;
3480
3554
  } catch {
3481
- return c;
3555
+ return l;
3482
3556
  }
3483
3557
  },
3484
3558
  path_unlink_file: (e, t, r) => {
3485
- if (!T || !U) return o;
3486
- let a = J(e, n.decode(new Uint8Array(T.buffer, t, r)));
3487
- if (!a || !U.exists(a)) return u;
3559
+ if (!E || !q) return o;
3560
+ let a = Z(e, n.decode(new Uint8Array(E.buffer, t, r)));
3561
+ if (!a || !q.exists(a)) return d;
3488
3562
  try {
3489
- return U.deleteFileByPath(a), i;
3563
+ return q.deleteFileByPath(a), i;
3490
3564
  } catch {
3491
- return c;
3565
+ return l;
3492
3566
  }
3493
3567
  },
3494
3568
  path_remove_directory: (e, t, r) => {
3495
- if (!T || !U) return o;
3496
- let a = J(e, n.decode(new Uint8Array(T.buffer, t, r)));
3497
- if (!a || !U.exists(a)) return u;
3569
+ if (!E || !q) return o;
3570
+ let a = Z(e, n.decode(new Uint8Array(E.buffer, t, r)));
3571
+ if (!a || !q.exists(a)) return d;
3498
3572
  try {
3499
- return U.deleteFileByPath(a), i;
3573
+ return q.deleteFileByPath(a), i;
3500
3574
  } catch {
3501
- return c;
3575
+ return l;
3502
3576
  }
3503
3577
  },
3504
- path_rename: (e, t, r, a, s, l) => {
3505
- if (!T || !U) return o;
3506
- let d = n.decode(new Uint8Array(T.buffer, t, r)), f = n.decode(new Uint8Array(T.buffer, s, l)), p = J(e, d), m = J(a, f);
3578
+ path_rename: (e, t, r, a, s, c) => {
3579
+ if (!E || !q) return o;
3580
+ let u = n.decode(new Uint8Array(E.buffer, t, r)), f = n.decode(new Uint8Array(E.buffer, s, c)), p = Z(e, u), m = Z(a, f);
3507
3581
  if (!p || !m) return o;
3508
- if (!U.exists(p)) return u;
3509
- for (let e of K.values()) e.path === p && (re(e), e.path = m);
3582
+ if (!q.exists(p)) return d;
3583
+ for (let e of Y.values()) e.path === p && (se(e), e.path = m);
3510
3584
  try {
3511
- let e = U.getFileByPath(p);
3512
- return U.setFileByPath(m, e, !0), U.deleteFileByPath(p), i;
3585
+ let e = q.getFileByPath(p);
3586
+ return q.setFileByPath(m, e, !0), q.deleteFileByPath(p), i;
3513
3587
  } catch {
3514
- return c;
3588
+ return l;
3515
3589
  }
3516
3590
  },
3517
3591
  proc_exit: (e) => {
@@ -3521,76 +3595,85 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3521
3595
  };
3522
3596
  },
3523
3597
  args_sizes_get: (e, t) => {
3524
- if (!T) return c;
3525
- let n = [this.script, ...this.arguments || []], r = new DataView(T.buffer);
3598
+ if (!E) return l;
3599
+ let n = [this.script, ...this.arguments || []], r = new DataView(E.buffer);
3526
3600
  return r.setUint32(e, n.length, !0), r.setUint32(t, n.reduce((e, t) => e + b.encode(t).length + 1, 0), !0), i;
3527
3601
  },
3528
3602
  args_get: (e, t) => {
3529
- if (!T) return c;
3530
- let n = [this.script, ...this.arguments || []], r = new DataView(T.buffer), a = t;
3603
+ if (!E) return l;
3604
+ let n = [this.script, ...this.arguments || []], r = new DataView(E.buffer), a = t;
3531
3605
  for (let t = 0; t < n.length; t++) {
3532
3606
  r.setUint32(e + t * 4, a, !0);
3533
3607
  let i = b.encode(n[t] + "\0");
3534
- new Uint8Array(T.buffer).set(i, a), a += i.length;
3608
+ new Uint8Array(E.buffer).set(i, a), a += i.length;
3535
3609
  }
3536
3610
  return i;
3537
3611
  },
3538
3612
  environ_sizes_get: (e, t) => {
3539
- if (!T) return c;
3540
- let n = new DataView(T.buffer);
3541
- n.setUint32(e, Y.length, !0);
3542
- let r = Y.reduce((e, t) => e + b.encode(t).length + 1, 0);
3613
+ if (!E) return l;
3614
+ let n = new DataView(E.buffer);
3615
+ n.setUint32(e, Q.length, !0);
3616
+ let r = Q.reduce((e, t) => e + b.encode(t).length + 1, 0);
3543
3617
  return n.setUint32(t, r, !0), i;
3544
3618
  },
3545
3619
  environ_get: (e, t) => {
3546
- if (!T) return c;
3547
- let n = new DataView(T.buffer), r = t;
3548
- for (let t = 0; t < Y.length; t++) {
3620
+ if (!E) return l;
3621
+ let n = new DataView(E.buffer), r = t;
3622
+ for (let t = 0; t < Q.length; t++) {
3549
3623
  n.setUint32(e + t * 4, r, !0);
3550
- let i = b.encode(Y[t] + "\0");
3551
- new Uint8Array(T.buffer).set(i, r), r += i.length;
3624
+ let i = b.encode(Q[t] + "\0");
3625
+ new Uint8Array(E.buffer).set(i, r), r += i.length;
3552
3626
  }
3553
3627
  return i;
3554
3628
  },
3555
3629
  clock_time_get: (e, t, n) => {
3556
- if (T) {
3557
- let e = BigInt(Date.now()) * 1000000n;
3558
- new DataView(T.buffer).setBigUint64(n, e, !0);
3630
+ if (E) {
3631
+ let t = e === 1 && typeof performance < "u" && typeof performance.now == "function" ? BigInt(Math.round(performance.now() * 1e6)) : BigInt(Date.now()) * 1000000n;
3632
+ new DataView(E.buffer).setBigUint64(n, t, !0);
3559
3633
  }
3560
3634
  return i;
3561
3635
  },
3562
3636
  random_get: (e, t) => {
3563
- if (T) {
3564
- let n = new Uint8Array(T.buffer, e, t);
3637
+ if (E) {
3638
+ let n = new Uint8Array(E.buffer, e, t);
3565
3639
  for (let e = 0; e < t; e++) n[e] = Math.random() * 256 | 0;
3566
3640
  }
3567
3641
  return i;
3568
3642
  },
3569
3643
  clock_nanosleep: (e, t, n, r, a) => {
3570
- if (!T) return o;
3571
- let s = new DataView(T.buffer).getBigUint64(n, !0), c = 0;
3644
+ if (!E) return o;
3645
+ let s = new DataView(E.buffer).getBigUint64(n, !0), c = 0;
3572
3646
  if (t & 1) {
3573
3647
  let e = BigInt(Date.now()) * 1000000n;
3574
3648
  c = s > e ? Number((s - e) / 1000000n) : 0;
3575
3649
  } else c = Number(s / 1000000n);
3576
- return D && c > 0 ? (typeof E?.exports?.asyncify_get_state == "function" ? E.exports.asyncify_get_state() : 0) === 2 ? (E.exports.asyncify_stop_rewind(), i) : (E.exports.asyncify_start_unwind(O), k = new Promise((e) => setTimeout(e, Math.max(1, c))), i) : i;
3650
+ return O && c > 0 ? (typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2 ? (D.exports.asyncify_stop_rewind(), i) : (D.exports.asyncify_start_unwind(k), A = new Promise((e) => setTimeout(e, Math.max(1, c))), i) : i;
3577
3651
  },
3578
3652
  poll_oneoff: (e, t, n, r) => {
3579
- if (!T) return o;
3580
- let a = new DataView(T.buffer);
3581
- if (D) {
3582
- if ((typeof E?.exports?.asyncify_get_state == "function" ? E.exports.asyncify_get_state() : 0) === 2) {
3583
- E.exports.asyncify_stop_rewind();
3653
+ if (!E) return o;
3654
+ let a = new DataView(E.buffer);
3655
+ if (O) {
3656
+ if ((typeof D?.exports?.asyncify_get_state == "function" ? D.exports.asyncify_get_state() : 0) === 2) {
3657
+ if (D.exports.asyncify_stop_rewind(), I && W.length === 0) return I = !1, a.setUint32(r, 0, !0), c;
3658
+ I = !1;
3584
3659
  let o = 0;
3585
3660
  for (let r = 0; r < n; r++) {
3586
- let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), l = t + o * 32;
3587
- a.setBigUint64(l, s, !0), a.setUint16(l + 8, i, !0), a.setUint8(l + 10, c);
3588
- for (let e = 11; e < 32; e++) a.setUint8(l + e, 0);
3589
- c === 1 && a.setBigUint64(l + 16, BigInt(B.length), !0), o++;
3661
+ let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), l = !1;
3662
+ if (c === 0) l = F;
3663
+ else if (c === 1) {
3664
+ let e = a.getUint32(n + 16, !0), t = Y.get(e), r = !!(t && t.type === "dev_tty");
3665
+ (e === 0 || V && e === 2 || r) && W.length > 0 && (l = !0);
3666
+ } else c === 2 && (l = !0);
3667
+ if (l) {
3668
+ let e = t + o * 32;
3669
+ a.setBigUint64(e, s, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, c);
3670
+ for (let t = 11; t < 32; t++) a.setUint8(e + t, 0);
3671
+ c === 1 && a.setBigUint64(e + 16, BigInt(W.length), !0), o++;
3672
+ }
3590
3673
  }
3591
3674
  return a.setUint32(r, o, !0), i;
3592
3675
  }
3593
- let o = 0, s = Infinity;
3676
+ let o = 0, s = !1, l = Infinity;
3594
3677
  for (let t = 0; t < n; t++) {
3595
3678
  let n = e + t * 48, r = a.getUint8(n + 8);
3596
3679
  if (r === 0) {
@@ -3599,80 +3682,83 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3599
3682
  let t = BigInt(Date.now()) * 1000000n;
3600
3683
  r = e > t ? Number((e - t) / 1000000n) : 0;
3601
3684
  } else r = Number(e / 1000000n);
3602
- r < s && (s = r);
3685
+ r < l && (l = r);
3603
3686
  } else if (r === 1) {
3604
- let e = a.getUint32(n + 16, !0), t = K.get(e), r = !!(t && t.type === "dev_tty");
3605
- (e === 0 || e === 2 || r) && L(), (e === 0 || I && e === 2 || r) && B.length > 0 && o++;
3687
+ s = !0;
3688
+ let e = a.getUint32(n + 16, !0), t = Y.get(e), r = !!(t && t.type === "dev_tty");
3689
+ (e === 0 || e === 2 || r) && H(), (e === 0 || V && e === 2 || r) && W.length > 0 && o++;
3606
3690
  } else r === 2 && o++;
3607
3691
  }
3608
- if (o > 0 || s === 0) {
3692
+ if (o > 0 || l === 0) {
3609
3693
  let o = 0;
3610
3694
  for (let r = 0; r < n; r++) {
3611
- let n = e + r * 48, c = a.getBigUint64(n, !0), l = a.getUint8(n + 8), u = !1;
3612
- if (l === 0 && s === 0) u = !0;
3613
- else if (l === 1) {
3614
- let e = a.getUint32(n + 16, !0), t = K.get(e), r = !!(t && t.type === "dev_tty");
3615
- (e === 0 || I && e === 2 || r) && B.length > 0 && (u = !0);
3616
- } else l === 2 && (u = !0);
3695
+ let n = e + r * 48, s = a.getBigUint64(n, !0), c = a.getUint8(n + 8), u = !1;
3696
+ if (c === 0 && l === 0) u = !0;
3697
+ else if (c === 1) {
3698
+ let e = a.getUint32(n + 16, !0), t = Y.get(e), r = !!(t && t.type === "dev_tty");
3699
+ (e === 0 || V && e === 2 || r) && W.length > 0 && (u = !0);
3700
+ } else c === 2 && (u = !0);
3617
3701
  if (u) {
3618
3702
  let e = t + o * 32;
3619
- a.setBigUint64(e, c, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, l);
3703
+ a.setBigUint64(e, s, !0), a.setUint16(e + 8, i, !0), a.setUint8(e + 10, c);
3620
3704
  for (let t = 11; t < 32; t++) a.setUint8(e + t, 0);
3621
- l === 1 && a.setBigUint64(e + 16, BigInt(B.length), !0), o++;
3705
+ c === 1 && a.setBigUint64(e + 16, BigInt(W.length), !0), o++;
3622
3706
  }
3623
3707
  }
3624
3708
  return a.setUint32(r, o, !0), i;
3625
3709
  }
3626
- return E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
3710
+ return F = !1, I = !1, D.exports.asyncify_start_unwind(k), A = new Promise((e, t) => {
3627
3711
  let n = null;
3628
3712
  this._asyncifyReject = t;
3629
3713
  let r = () => {
3630
- n && clearTimeout(n), A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3714
+ n && clearTimeout(n), F = !1, I = !1, j = null, P = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3631
3715
  };
3632
- A = r, this._pendingReadResolve = r, s !== Infinity && (n = setTimeout(() => {
3633
- A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3634
- }, Math.max(1, s)));
3716
+ s && (j = r, this._pendingReadResolve = r, P = () => {
3717
+ n && clearTimeout(n), F = !1, I = !0, j = null, P = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3718
+ }), l !== Infinity && (n = setTimeout(() => {
3719
+ F = !0, I = !1, j = null, P = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
3720
+ }, Math.max(1, l)));
3635
3721
  }), a.setUint32(r, 0, !0), i;
3636
3722
  }
3637
3723
  return a.setUint32(r, 0, !0), i;
3638
3724
  }
3639
3725
  }, { get(e, t) {
3640
3726
  return t in e ? e[t] : () => 0;
3641
- } }), Z = (e) => {
3642
- if (!T || !e) return "";
3727
+ } }), fe = (e) => {
3728
+ if (!E || !e) return "";
3643
3729
  try {
3644
- let t = new DataView(T.buffer).getUint32(e - 4, !0), n = new Uint16Array(T.buffer, e, t >>> 1);
3730
+ let t = new DataView(E.buffer).getUint32(e - 4, !0), n = new Uint16Array(E.buffer, e, t >>> 1);
3645
3731
  return String.fromCharCode(...n);
3646
3732
  } catch {
3647
3733
  return "";
3648
3734
  }
3649
- }, ae = {
3650
- wasi_snapshot_preview1: X,
3651
- wasi_unstable: X,
3735
+ }, $ = {
3736
+ wasi_snapshot_preview1: de,
3737
+ wasi_unstable: de,
3652
3738
  env: new Proxy({
3653
3739
  print: (e, t) => {
3654
- T && R(1, n.decode(new Uint8Array(T.buffer, e, t)));
3740
+ E && U(1, n.decode(new Uint8Array(E.buffer, e, t)));
3655
3741
  },
3656
3742
  eprint: (e, t) => {
3657
- T && R(2, n.decode(new Uint8Array(T.buffer, e, t)));
3743
+ E && U(2, n.decode(new Uint8Array(E.buffer, e, t)));
3658
3744
  },
3659
3745
  log: (e) => {
3660
- R(1, Z(e) + "\n");
3746
+ U(1, fe(e) + "\n");
3661
3747
  },
3662
3748
  logi: (e) => {
3663
- R(1, String(e) + "\n");
3749
+ U(1, String(e) + "\n");
3664
3750
  },
3665
3751
  logf: (e) => {
3666
- R(1, String(e) + "\n");
3752
+ U(1, String(e) + "\n");
3667
3753
  },
3668
3754
  trace: (e, t, ...n) => {
3669
3755
  let r = t > 0 ? " " + n.slice(0, t).join(", ") : "";
3670
- R(1, `trace: ${Z(e)}${r}\n`);
3756
+ U(1, `trace: ${fe(e)}${r}\n`);
3671
3757
  },
3672
3758
  seed: () => Date.now() * Math.random(),
3673
3759
  abort: (e, t, n, r) => {
3674
- let i = Z(e), a = Z(t);
3675
- throw (i || a) && R(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
3760
+ let i = fe(e), a = fe(t);
3761
+ throw (i || a) && U(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
3676
3762
  _wasmExit: !0,
3677
3763
  code: 134
3678
3764
  };
@@ -3688,85 +3774,100 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3688
3774
  initial: 1,
3689
3775
  maximum: 256
3690
3776
  });
3691
- T = t, ae[e.module] || (ae[e.module] = {}), ae[e.module][e.name] = t;
3777
+ E = t, $[e.module] || ($[e.module] = {}), $[e.module][e.name] = t;
3692
3778
  }
3693
- if (E = await WebAssembly.instantiate(t, ae), E.exports.memory && (T = E.exports.memory), D = !!(E.exports.asyncify_start_unwind && E.exports.asyncify_stop_unwind), D && T) {
3779
+ if (D = await WebAssembly.instantiate(t, $), D.exports.memory && (E = D.exports.memory), O = !!(D.exports.asyncify_start_unwind && D.exports.asyncify_stop_unwind), O && E) {
3694
3780
  try {
3695
- O = T.grow(1) * 65536;
3781
+ k = E.grow(1) * 65536;
3696
3782
  } catch {
3697
- O = 16;
3783
+ k = 16;
3698
3784
  }
3699
- let e = O + 8, t = O + 65536 - 8;
3700
- new Int32Array(T.buffer, O, 2).set([e, t]);
3785
+ let e = k + 8, t = k + 65536 - 8;
3786
+ new Int32Array(E.buffer, k, 2).set([e, t]);
3701
3787
  }
3702
- typeof E.exports.set_terminal_size == "function" && L(), I && this._enterAltScreen();
3703
- let n = this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, r = this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
3704
- if (typeof E.exports.set_terminal_size == "function") try {
3705
- E.exports.set_terminal_size(n, r);
3788
+ typeof D.exports.set_terminal_size == "function" && H(), V && this._enterAltScreen();
3789
+ let n = this.stdout && this.stdout.columns || this.stdinStream && this.stdinStream.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, r = this.stdout && this.stdout.rows || this.stdinStream && this.stdinStream.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
3790
+ if (typeof D.exports.set_terminal_size == "function") try {
3791
+ D.exports.set_terminal_size(n, r);
3706
3792
  } catch {}
3707
- N = () => {
3708
- let e = this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, t = this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24;
3709
- if (typeof E?.exports?.set_terminal_size == "function") try {
3710
- E.exports.set_terminal_size(e, t);
3711
- } catch {}
3712
- }, this.stdout && typeof this.stdout.on == "function" && this.stdout.on("resize", N), this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("resize", N);
3713
- let i = E.exports._start || E.exports.__wasi_command || E.exports.main || E.exports.run;
3714
- if (i) try {
3715
- let e = i();
3716
- for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;) {
3793
+ let i = n, a = r, o = (e, t) => {
3794
+ if (!(!e || !t)) {
3795
+ if (this.stdout && (this.stdout.columns !== e || this.stdout.rows !== t) && (this.stdout.columns = e, this.stdout.rows = t), this.stdinStream && (this.stdinStream.columns !== e || this.stdinStream.rows !== t) && (this.stdinStream.columns = e, this.stdinStream.rows = t), this.context && typeof this.context.setVar == "function") try {
3796
+ this.context.setVar("COLUMNS", String(e)), this.context.setVar("LINES", String(t));
3797
+ } catch {}
3798
+ if (!(e === i && t === a)) {
3799
+ if (i = e, a = t, typeof D?.exports?.set_terminal_size == "function") try {
3800
+ D.exports.set_terminal_size(e, t);
3801
+ } catch {}
3802
+ if (P) {
3803
+ let e = P;
3804
+ P = null, e();
3805
+ }
3806
+ }
3807
+ }
3808
+ };
3809
+ ee = () => {
3810
+ o(this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24);
3811
+ }, R = () => {
3812
+ o(this.stdinStream && this.stdinStream.columns || this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("COLUMNS"), 10) || 80, this.stdinStream && this.stdinStream.rows || this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && parseInt(this.context.getVar("LINES"), 10) || 24);
3813
+ }, this.stdout && typeof this.stdout.on == "function" && this.stdout.on("resize", ee), this.stdinStream && this.stdinStream !== this.stdout && typeof this.stdinStream.on == "function" && this.stdinStream.on("resize", R);
3814
+ let s = D.exports._start || D.exports.__wasi_command || D.exports.main || D.exports.run;
3815
+ if (s) try {
3816
+ let e = s();
3817
+ for (e && typeof e.then == "function" && (e = await e); O && typeof D.exports.asyncify_get_state == "function" && D.exports.asyncify_get_state() === 1;) {
3717
3818
  if (this._killed) {
3718
3819
  this.exitCode = 130;
3719
3820
  break;
3720
3821
  }
3721
- if (E.exports.asyncify_stop_unwind(), k) {
3822
+ if (D.exports.asyncify_stop_unwind(), A) {
3722
3823
  try {
3723
- await k;
3824
+ await A;
3724
3825
  } catch {
3725
3826
  if (this._killed) {
3726
3827
  this.exitCode = 130;
3727
3828
  break;
3728
3829
  }
3729
3830
  }
3730
- k = null;
3831
+ A = null;
3731
3832
  }
3732
3833
  if (this._killed) {
3733
3834
  this.exitCode = 130;
3734
3835
  break;
3735
3836
  }
3736
- E.exports.asyncify_start_rewind(O), e = i(), e && typeof e.then == "function" && (e = await e);
3837
+ D.exports.asyncify_start_rewind(k), e = s(), e && typeof e.then == "function" && (e = await e);
3737
3838
  }
3738
3839
  } catch (e) {
3739
3840
  this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
3740
3841
  }
3741
3842
  else {
3742
- let e = Object.entries(E.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
3843
+ let e = Object.entries(D.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
3743
3844
  this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
3744
3845
  }
3745
3846
  } catch (e) {
3746
3847
  this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
3747
3848
  } finally {
3748
- I && this._exitAltScreen(), P && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", P), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", P)), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), N && (this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", N), this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", N)), this._externalKeyHandler = null;
3749
- for (let e of K.values()) re(e);
3849
+ V && this._exitAltScreen(), z && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", z), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", z)), re && this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), ee && this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", ee), R && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", R), this._externalKeyHandler = null;
3850
+ for (let e of Y.values()) se(e);
3750
3851
  }
3751
- z();
3752
- let Q = this.arguments || [];
3852
+ te();
3853
+ let pe = this.arguments || [];
3753
3854
  if (!(this.result && this.result.getStdOutput && this.result.getStdOutput().length > 0) && (this.exitCode === 0 || this.exitCode === void 0)) {
3754
3855
  let t = this._ensurePkgMeta(), n = t && t.bin || (this.script || "wasm").split("/").pop(), r = Object.assign({
3755
3856
  name: t && t.name || n,
3756
3857
  version: t && t.version || "wasi",
3757
3858
  description: `WebAssembly WASI binary (${this.script})`
3758
3859
  }, t || {});
3759
- if (Q.includes("--help") || Q.includes("-h")) {
3760
- let t = j(e);
3761
- for (let e of M(n, r, t)) this.stdOut = e;
3762
- } else (Q.includes("--version") || Q.includes("-V") || Q.includes("-v")) && (this.stdOut = `${n} (${r.name} ${r.version} wasm)`);
3860
+ if (pe.includes("--help") || pe.includes("-h")) {
3861
+ let t = M(e);
3862
+ for (let e of N(n, r, t)) this.stdOut = e;
3863
+ } else (pe.includes("--version") || pe.includes("-V") || pe.includes("-v")) && (this.stdOut = `${n} (${r.name} ${r.version} wasm)`);
3763
3864
  }
3764
3865
  }
3765
- }, E = /* @__PURE__ */ new Map();
3766
- function D(e, t) {
3866
+ }, D = /* @__PURE__ */ new Map();
3867
+ function O(e, t) {
3767
3868
  if (!e || !e.exists(t)) return null;
3768
3869
  if (e.isRealFilesystem) try {
3769
- let n = X();
3870
+ let n = Y();
3770
3871
  return new Uint8Array(n.readFileSync(e.absolutePath(t)));
3771
3872
  } catch {}
3772
3873
  let n = e.getFileByPath(t);
@@ -3790,7 +3891,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3790
3891
  }
3791
3892
  return null;
3792
3893
  }
3793
- function O(e, t, n, i = "application/octet-stream") {
3894
+ function k(e, t, n, i = "application/octet-stream") {
3794
3895
  let a = n instanceof Uint8Array ? n : new Uint8Array(n);
3795
3896
  if (e && e.isRealFilesystem) {
3796
3897
  e.setFileByPath(t, a, !0);
@@ -3805,7 +3906,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3805
3906
  }
3806
3907
  e.setFileByPath(t, s, !0);
3807
3908
  }
3808
- async function k(e, t, n = null) {
3909
+ async function A(e, t, n = null) {
3809
3910
  if (typeof n == "function") {
3810
3911
  let r = await n(e, t);
3811
3912
  if (r) return r;
@@ -3833,7 +3934,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3833
3934
  }
3834
3935
  throw Error(`Package '${e}' could not be loaded`);
3835
3936
  }
3836
- function A(e, t = !1) {
3937
+ function j(e, t = !1) {
3837
3938
  let n = {
3838
3939
  usage: null,
3839
3940
  options: []
@@ -3850,7 +3951,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3850
3951
  }
3851
3952
  return n;
3852
3953
  }
3853
- function j(e) {
3954
+ function M(e) {
3854
3955
  let t = {
3855
3956
  usage: null,
3856
3957
  options: [],
@@ -3875,12 +3976,12 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3875
3976
  r.length >= 4 && n.push(r);
3876
3977
  let i = n.join("\n");
3877
3978
  t.isInteractive || (i.includes("/dev/tty") || i.includes("\x1B[?1049h") || i.includes("smcup") || i.includes("xterm")) && (t.isInteractive = !0);
3878
- let a = A(i, !0);
3979
+ let a = j(i, !0);
3879
3980
  t.usage = a.usage, t.options = a.options;
3880
3981
  } catch {}
3881
3982
  return t;
3882
3983
  }
3883
- function M(e, t = {}, n = null) {
3984
+ function N(e, t = {}, n = null) {
3884
3985
  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 = s ? s.replace(/%s/g, e) : null, l = o ? `${e} [options] ${o.evalFlag ? `[${o.evalFlag} <code>] ` : ""}[file] [args...]` : `${e} [options] [args...]`, u = [`${e} (${r} ${i} wasm) — ${a}`, `Usage: ${c || l}`];
3885
3986
  t.details && u.push("", t.details), u.push("", "Options:");
3886
3987
  let d = n && n.options && n.options.length > 0 ? n.options : Array.isArray(t.options) ? t.options : [];
@@ -3888,8 +3989,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3888
3989
  else o && (o.evalFlag && u.push(` ${o.evalFlag.padEnd(20)}Evaluate inline code and print result`), u.push(` (no arguments) Start interactive ${e} REPL shell`));
3889
3990
  return u.push(" -h, --help Show this help message and exit"), u.push(" -V, --version Show WebAssembly binary version and exit"), n && n.exports && n.exports.length > 0 && u.push("", `WASM Exports: ${n.exports.join(", ")}`), Array.isArray(t.aliases) && t.aliases.length > 0 && u.push("", `Aliases: ${t.aliases.join(", ")}`), (t.homepage || t.cdnUrl || t.wasmUrl) && u.push(`Source: ${t.homepage || t.cdnUrl || t.wasmUrl}`), u;
3890
3991
  }
3891
- function N(e, t = {}, n = null) {
3892
- let r = G(), i = (n || e.bin || e.name).toLowerCase();
3992
+ function P(e, t = {}, n = null) {
3993
+ let r = W(), i = (n || e.bin || e.name).toLowerCase();
3893
3994
  class a extends r {
3894
3995
  static get name() {
3895
3996
  return i;
@@ -3904,7 +4005,16 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3904
4005
  return this._subCommand ? this._subCommand.interactive : this._isInteractive === void 0 ? !!(e && (e.interactive || e.wasm?.interactive) || this._inspectedWasm && this._inspectedWasm.isInteractive) : !!this._isInteractive;
3905
4006
  }
3906
4007
  get captureInput() {
3907
- return this.interactive;
4008
+ return this._subCommand ? !!this._subCommand.captureInput : this.interactive;
4009
+ }
4010
+ get isRaw() {
4011
+ return !!(this.stdinStream && this.stdinStream.isRaw || this._subCommand && (this._subCommand.isRaw || this._subCommand.stdinStream && this._subCommand.stdinStream.isRaw));
4012
+ }
4013
+ get _inAltScreen() {
4014
+ return !!(this.__inAltScreen || this._subCommand && this._subCommand._inAltScreen);
4015
+ }
4016
+ set _inAltScreen(e) {
4017
+ this.__inAltScreen = !!e;
3908
4018
  }
3909
4019
  kill(e = "SIGINT") {
3910
4020
  this._subCommand && typeof this._subCommand.kill == "function" && this._subCommand.kill(e), super.kill(e);
@@ -3913,8 +4023,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3913
4023
  this._subCommand && typeof this._subCommand.onInput == "function" && this._subCommand.onInput(e);
3914
4024
  }
3915
4025
  async run() {
3916
- let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
3917
- this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? D(this.context && this.context.fs || this.fs, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = j(this._persistedWasmBytes));
4026
+ let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v")), o = this.fs || this.context && this.context.fs;
4027
+ this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? O(o, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = M(this._persistedWasmBytes));
3918
4028
  try {
3919
4029
  if ((e.type === "wasm" || e.type === "custom-wasm") && (this._persistedWasmBytes || e.wasmUrl)) {
3920
4030
  let i = this._persistedWasmBytes;
@@ -3923,7 +4033,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3923
4033
  n instanceof Uint8Array || n instanceof ArrayBuffer ? i = n instanceof Uint8Array ? n : new Uint8Array(n) : n && (n.wasmBytes || n.wasm || n.wasmBinary) && (i = n.wasmBytes || n.wasm || n.wasmBinary);
3924
4034
  } catch {}
3925
4035
  if (!i && e.wasmUrl && (i = await this._fetchWasmBytes(e.wasmUrl)), i) {
3926
- r && (this._inspectedWasm = j(i)), await this._runRawWasmBytes(i, n);
4036
+ r && (this._inspectedWasm = M(i)), await this._runRawWasmBytes(i, n);
3927
4037
  return;
3928
4038
  }
3929
4039
  } else {
@@ -3940,19 +4050,19 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3940
4050
  }
3941
4051
  let c, l;
3942
4052
  try {
3943
- c = await k(e.name, o, t.moduleLoader), l = c && c.default !== void 0 ? c.default : c, l && typeof l.then == "function" && (l = await l);
4053
+ c = await A(e.name, o, t.moduleLoader), l = c && c.default !== void 0 ? c.default : c, l && typeof l.then == "function" && (l = await l);
3944
4054
  } finally {
3945
4055
  s && (globalThis.fetch = s);
3946
4056
  }
3947
4057
  if (l instanceof Uint8Array || l instanceof ArrayBuffer) {
3948
4058
  let e = l instanceof Uint8Array ? l : new Uint8Array(l);
3949
- r && (this._inspectedWasm = j(e)), await this._runRawWasmBytes(e, n);
4059
+ r && (this._inspectedWasm = M(e)), await this._runRawWasmBytes(e, n);
3950
4060
  } else if (l && (l.wasmBytes instanceof Uint8Array || l.wasm instanceof Uint8Array)) {
3951
4061
  let e = l.wasmBytes || l.wasm;
3952
- r && (this._inspectedWasm = j(e)), await this._runRawWasmBytes(e, n);
4062
+ r && (this._inspectedWasm = M(e)), await this._runRawWasmBytes(e, n);
3953
4063
  } else if (typeof l == "function") await this._runFunctionOrEmscripten(l, n, r, a);
3954
4064
  else if (l && typeof l == "object") {
3955
- l.ready && await l.ready, r && (l.HEAPU8 instanceof Uint8Array || l.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = j(l.wasmBinary || l.HEAPU8));
4065
+ l.ready && await l.ready, r && (l.HEAPU8 instanceof Uint8Array || l.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = M(l.wasmBinary || l.HEAPU8));
3956
4066
  let t = l.main || l.run || l.callMain || l.exec;
3957
4067
  if (typeof t == "function") await this._invokeCliFunction(t.bind(l), n);
3958
4068
  else if (l.promised || typeof l.raw == "function" || typeof l.json == "function") {
@@ -3980,34 +4090,38 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
3980
4090
  }
3981
4091
  }
3982
4092
  if (r || a) {
3983
- 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);
4093
+ let t = this.result && this.result.getStdOutput ? this.result.getStdOutput() : [], n = t.map((e) => e.string).join("\n"), o = r ? j(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);
3984
4094
  if (r) if (s) {
3985
4095
  let e = t.map((e) => e.string);
3986
4096
  this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
3987
4097
  for (let t of e) this.stdOut = t;
3988
4098
  } else {
3989
4099
  this.result && Array.isArray(this.result.std) && (this.result.std.length = 0), this.exitCode = 0;
3990
- for (let t of M(i, e, this._inspectedWasm)) this.stdOut = t;
4100
+ for (let t of N(i, e, this._inspectedWasm)) this.stdOut = t;
3991
4101
  }
3992
4102
  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;
3993
4103
  }
3994
4104
  }
3995
4105
  async _fetchWasmBytes(e) {
3996
- if (E.has(e)) return E.get(e);
4106
+ if (D.has(e)) return D.get(e);
3997
4107
  let n = t.fetch || (typeof fetch == "function" ? fetch : null);
3998
4108
  if (!n) throw Error("fetch is not available in this environment");
3999
4109
  let r = await n(e);
4000
4110
  if (!r || !r.ok) throw Error(`HTTP ${r ? r.status : "error"} fetching ${e}`);
4001
4111
  let i = new Uint8Array(await r.arrayBuffer());
4002
- return E.set(e, i), i;
4112
+ return D.set(e, i), i;
4003
4113
  }
4004
4114
  async _runRawWasmBytes(t, n) {
4005
- let r = new T(i, n, this.context);
4006
- 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), this._subCommand = r;
4115
+ let r = new E(i, n, this.context);
4116
+ r.script = i, r.arguments = n, r.context = this.context, r.fs = this.fs, r._pkgMeta = e, r.stdinStream = this.stdinStream, r.stdout = this.stdout, r.stderr = this.stderr, r.stdin = this.stdin && !this.stdin.isTTY ? this.stdin : this.stdinStream, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData);
4117
+ let a = () => {
4118
+ this.emit("interactive"), this.context && typeof this.context.emit == "function" && this.context.emit("interactive");
4119
+ };
4120
+ r.on("interactive", a), this._subCommand = r;
4007
4121
  try {
4008
4122
  await r._runWasm(t);
4009
4123
  } finally {
4010
- this._subCommand = null;
4124
+ r.removeListener("interactive", a), r._inAltScreen && r._exitAltScreen(), this._subCommand = null, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData);
4011
4125
  }
4012
4126
  for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
4013
4127
  this.exitCode = r.result.getExitCode();
@@ -4031,16 +4145,16 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4031
4145
  let n = t && t !== "." && !e.startsWith("/") ? `${t.replace(/\/+$/, "")}/${e}` : e, r = this.fs.getFileByPath(n) ?? this.fs.getFileByPath(e);
4032
4146
  return r == null ? null : typeof r == "string" ? r : new TextDecoder().decode(r);
4033
4147
  },
4034
- readBytes: (e) => D(this.fs, e),
4148
+ readBytes: (e) => O(this.fs, e),
4035
4149
  writeFile: (e, t, n) => {
4036
4150
  if (!this.fs) return;
4037
4151
  let r = n && n !== "." && !e.startsWith("/") ? `${n.replace(/\/+$/, "")}/${e}` : e;
4038
4152
  if (t instanceof Uint8Array || ArrayBuffer.isView(t)) {
4039
4153
  let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
4040
- O(this.fs, r, t, e);
4154
+ k(this.fs, r, t, e);
4041
4155
  } else this.fs.setFileByPath(r, String(t), !0);
4042
4156
  if (r.endsWith(".wasm") || r.endsWith(".wat")) try {
4043
- this.context && this.context.fs ? this.context.fs.setMode(r, 493) : this.fs.setMode(r, 493);
4157
+ this.fs.setMode(r, 493);
4044
4158
  } catch {}
4045
4159
  },
4046
4160
  listFiles: (e, t) => {
@@ -4073,7 +4187,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4073
4187
  if (e && typeof e.status == "number") this.exitCode = e.status;
4074
4188
  else throw e;
4075
4189
  }
4076
- if (f && typeof f == "object") if (r && (f.wasmBinary instanceof Uint8Array || f.HEAPU8 instanceof Uint8Array) && (this._inspectedWasm = j(f.wasmBinary || f.HEAPU8)), typeof f.callMain == "function") {
4190
+ if (f && typeof f == "object") if (r && (f.wasmBinary instanceof Uint8Array || f.HEAPU8 instanceof Uint8Array) && (this._inspectedWasm = M(f.wasmBinary || f.HEAPU8)), typeof f.callMain == "function") {
4077
4191
  f.FS && l.size === 0 && (l = this._syncBrshToEmscriptenFs(f.FS, n));
4078
4192
  try {
4079
4193
  let e = await f.callMain(n);
@@ -4136,14 +4250,14 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4136
4250
  }), !t.loaded && typeof t.load == "function" && await t.load(e.coreUrl ? { coreURL: e.coreUrl } : void 0);
4137
4251
  let a = /* @__PURE__ */ new Set(), o = [];
4138
4252
  for (let e of n) if (!e.startsWith("-") && (o.push(e), this.fs.exists(e))) {
4139
- let n = D(this.fs, e);
4253
+ let n = O(this.fs, e);
4140
4254
  n && (await t.writeFile(e, n), a.add(e));
4141
4255
  }
4142
4256
  let s = await t.exec(n);
4143
4257
  for (let e of o) if (!a.has(e)) try {
4144
4258
  if (typeof t.readFile == "function") {
4145
4259
  let n = await t.readFile(e);
4146
- n && O(this.fs, e, n);
4260
+ n && k(this.fs, e, n);
4147
4261
  }
4148
4262
  } catch {}
4149
4263
  typeof s == "number" && s !== 0 && (this.exitCode = s, i.length === 0 && r.length > 0 && i.push(...r.splice(0, r.length)));
@@ -4160,7 +4274,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4160
4274
  let n = /* @__PURE__ */ new Set();
4161
4275
  if (!this.fs || !e || typeof e.writeFile != "function") return n;
4162
4276
  for (let r of t) if (!r.startsWith("-") && this.fs.exists(r)) {
4163
- let t = D(this.fs, r);
4277
+ let t = O(this.fs, r);
4164
4278
  if (t) try {
4165
4279
  e.writeFile(r, t), n.add(r);
4166
4280
  } catch {}
@@ -4173,8 +4287,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4173
4287
  let t = e.readFile(r);
4174
4288
  if (t) {
4175
4289
  let e = r.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
4176
- if (O(this.fs, r, t, e), r.endsWith(".wasm") || r.endsWith(".wat")) try {
4177
- this.context && this.context.fs ? this.context.fs.setMode(r, 493) : this.fs.setMode(r, 493);
4290
+ if (k(this.fs, r, t, e), r.endsWith(".wasm") || r.endsWith(".wat")) try {
4291
+ this.fs.setMode(r, 493);
4178
4292
  } catch {}
4179
4293
  }
4180
4294
  } catch {}
@@ -4183,10 +4297,10 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4183
4297
  }
4184
4298
  return a;
4185
4299
  }
4186
- function P(e, t) {
4300
+ function F(e, t) {
4187
4301
  return e && (e.endsWith(".wasm") || e.endsWith(".wat")) ? !0 : t instanceof Uint8Array ? t.length >= 4 && t[0] === 0 && t[1] === 97 && t[2] === 115 && t[3] === 109 : typeof t == "string" ? t.charCodeAt(0) === 0 && t.slice(1, 4) === "asm" ? !0 : t.trimStart().startsWith("(module") : !1;
4188
4302
  }
4189
- function F(e, t) {
4303
+ function I(e, t) {
4190
4304
  if (!e || !t || typeof e.exists != "function" || typeof e.getFileByPath != "function") return null;
4191
4305
  try {
4192
4306
  let n = t.split("/").filter(Boolean);
@@ -4199,8 +4313,8 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4199
4313
  } catch {}
4200
4314
  return null;
4201
4315
  }
4202
- T.isWasmFile = P, T.readSiblingPkgMeta = F, T.readBytesFromFs = D, T.writeBytesToFs = O, T.loadModule = k, T.extractHelpFromText = A, T.inspectWasmBytes = j, T.formatWasmHelp = M, T.createGenericWasmCommand = N, T.createCommand = N, t.exports = T;
4203
- })), ae = /* @__PURE__ */ t(((e, t) => {
4316
+ E.isWasmFile = F, E.readSiblingPkgMeta = I, E.readBytesFromFs = O, E.writeBytesToFs = k, E.loadModule = A, E.extractHelpFromText = j, E.inspectWasmBytes = M, E.formatWasmHelp = N, E.createGenericWasmCommand = P, E.createCommand = P, t.exports = E;
4317
+ })), oe = /* @__PURE__ */ t(((e, t) => {
4204
4318
  var n = {
4205
4319
  sqlite3: {
4206
4320
  name: "sqlite3",
@@ -4438,7 +4552,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4438
4552
  PACKAGE_ALIASES: r,
4439
4553
  resolvePackageName: i
4440
4554
  };
4441
- })), Q = /* @__PURE__ */ t(((e, t) => {
4555
+ })), Z = /* @__PURE__ */ t(((e, t) => {
4442
4556
  function n(e, t, n = {}) {
4443
4557
  let { showRowCount: r = !0 } = n;
4444
4558
  if (!e || e.length === 0) return [];
@@ -4474,7 +4588,7 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4474
4588
  }
4475
4589
  return i;
4476
4590
  }
4477
- var { readBytesFromFs: a, writeBytesToFs: o, loadModule: s, extractHelpFromText: c, inspectWasmBytes: l, formatWasmHelp: u } = Z();
4591
+ var { readBytesFromFs: a, writeBytesToFs: o, loadModule: s, extractHelpFromText: c, inspectWasmBytes: l, formatWasmHelp: u } = X();
4478
4592
  t.exports = {
4479
4593
  formatTable: n,
4480
4594
  formatPipeList: r,
@@ -4486,9 +4600,9 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
4486
4600
  inspectWasmBytes: l,
4487
4601
  formatWasmHelp: u
4488
4602
  };
4489
- })), oe = /* @__PURE__ */ t(((e, t) => {
4490
- te();
4491
- var n = ne(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = Q(), o = {
4603
+ })), se = /* @__PURE__ */ t(((e, t) => {
4604
+ W();
4605
+ var n = K(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = Z(), o = {
4492
4606
  smol: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
4493
4607
  smollm: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
4494
4608
  smollm2: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
@@ -5381,9 +5495,9 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
5381
5495
  name: "wllama",
5382
5496
  version: "3.8.1"
5383
5497
  }), t.exports.wllamaInstances = u, t.exports.getDefaultPersistPath = d, t.exports.DEFAULT_PERSIST_DIR = l, t.exports.resolveModelSpec = h, t.exports.formatDownloadProgress = p, t.exports.DEFAULT_MODEL_URL = s, t.exports.MODEL_ALIASES = o;
5384
- })), se = /* @__PURE__ */ t(((e, t) => {
5498
+ })), ce = /* @__PURE__ */ t(((e, t) => {
5385
5499
  b();
5386
- var r = ee(), i = G(), a = Z(), o = ne(), { DEFAULT_REGISTRY: s, resolvePackageName: c } = ae(), l = oe(), { writeBytesToFs: u, createGenericWasmCommand: d } = a, { createReplWasmCommand: f } = o, p = "/var/cache/wbt";
5500
+ var r = B(), i = W(), a = X(), o = K(), { DEFAULT_REGISTRY: s, resolvePackageName: c } = oe(), l = se(), { writeBytesToFs: u, createGenericWasmCommand: d } = a, { createReplWasmCommand: f } = o, p = "/var/cache/wbt";
5387
5501
  function m(e, t, n = {}) {
5388
5502
  class r extends a {
5389
5503
  static get name() {
@@ -5417,6 +5531,45 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
5417
5531
  get requiresFilesystem() {
5418
5532
  return !0;
5419
5533
  }
5534
+ get _fs() {
5535
+ return this.fs || this.context && this.context.fs || null;
5536
+ }
5537
+ get _pathDir() {
5538
+ return this.context && typeof this.context.getVar == "function" && this.context.getVar("PATH") || "/bin";
5539
+ }
5540
+ _withWritableParent(e, t) {
5541
+ let n = this._fs;
5542
+ if (!n) return;
5543
+ let r = (typeof n.absolutePath == "function" ? n.absolutePath(e) : e).split("/");
5544
+ r.pop();
5545
+ let i = r.join("/") || "/", a = typeof n.getMode == "function" ? n.getMode(i) : null, o = a !== null && (a & 128) == 0;
5546
+ if (o) try {
5547
+ n.setMode(i, a | 128);
5548
+ } catch {}
5549
+ try {
5550
+ return t(n);
5551
+ } finally {
5552
+ if (o) try {
5553
+ n.setMode(i, a);
5554
+ } catch {}
5555
+ }
5556
+ }
5557
+ _writeFileSafe(e, t) {
5558
+ this._withWritableParent(e, (n) => {
5559
+ if (n.exists(e)) try {
5560
+ n.setMode(e, 493);
5561
+ } catch {}
5562
+ n.setFileByPath(e, t, !0);
5563
+ });
5564
+ }
5565
+ _writeBytesSafe(e, t, n = "application/wasm") {
5566
+ this._withWritableParent(e, (r) => {
5567
+ if (r.exists(e)) try {
5568
+ r.setMode(e, 493);
5569
+ } catch {}
5570
+ u(r, e, t, n);
5571
+ });
5572
+ }
5420
5573
  get interactive() {
5421
5574
  if (this._activeSubCommand && this._activeSubCommand.interactive !== void 0) return !!this._activeSubCommand.interactive;
5422
5575
  if (this.arguments && this.arguments[0] === "run" && this.arguments[1]) {
@@ -5428,6 +5581,9 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
5428
5581
  get captureInput() {
5429
5582
  return this._activeSubCommand && this._activeSubCommand.captureInput !== void 0 ? !!this._activeSubCommand.captureInput : this.interactive;
5430
5583
  }
5584
+ get isRaw() {
5585
+ return !!(this.stdinStream && this.stdinStream.isRaw || this._activeSubCommand && (this._activeSubCommand.isRaw || this._activeSubCommand.stdinStream && this._activeSubCommand.stdinStream.isRaw));
5586
+ }
5431
5587
  onInput(e) {
5432
5588
  this._activeSubCommand && typeof this._activeSubCommand.onInput == "function" && this._activeSubCommand.onInput(e);
5433
5589
  }
@@ -5452,30 +5608,32 @@ var A, j, M, N, P, F, I, L, R, z, B = e((() => {
5452
5608
  _getRegistry() {
5453
5609
  let e = this.constructor._config || {}, t = Object.assign({}, s, e.registry || {});
5454
5610
  try {
5455
- let e = this.context.fs._getFileRaw(`${p}/remote-registry.json`);
5456
- if (typeof e == "string" && e.trim()) {
5457
- let n = JSON.parse(e);
5458
- Object.assign(t, n);
5611
+ let e = this._fs, n = e ? e.getFileByPath(`${p}/remote-registry.json`) : null;
5612
+ if (typeof n == "string" && n.trim()) {
5613
+ let e = JSON.parse(n);
5614
+ Object.assign(t, e);
5459
5615
  }
5460
5616
  } catch {}
5461
5617
  return t;
5462
5618
  }
5463
5619
  _getInstalledPackages() {
5464
- let e = {}, t = this.context.fs.getFileByPath("/usr/lib");
5465
- if (!t || typeof t != "object") return e;
5466
- let n = this._getRegistry();
5467
- for (let r of Object.keys(t)) {
5468
- if (r.startsWith(".")) continue;
5469
- let t = r.toLowerCase(), i = n[t] || Object.values(n).find((e) => e.name === t || e.bin === t), a = this.context.fs.getFileByPath(`/usr/lib/${r}`) || {}, o = (typeof a == "object" ? Object.keys(a) : []).find((e) => e.endsWith(".wasm") || e.endsWith(".wat")), s = o ? `/usr/lib/${r}/${o}` : this.context.fs.exists(`/usr/lib/${r}/${t}.wasm`) ? `/usr/lib/${r}/${t}.wasm` : null, c = i && i.bin || t, l = [c];
5470
- i && i.aliases && l.push(...i.aliases), i && i.scripts && l.push(...Object.keys(i.scripts)), e[t] = Object.assign({
5471
- name: t,
5472
- bin: c,
5473
- bins: l,
5474
- version: i && i.version || "custom",
5475
- description: i && i.description || `Installed package ${t}`,
5476
- type: i && i.type || (s ? "custom-wasm" : "generic-runtime"),
5477
- wasmPath: s
5478
- }, i || {}), s && (e[t].wasmPath = s);
5620
+ let e = {}, t = this._fs;
5621
+ if (!t) return e;
5622
+ let n = t.getFileByPath("/usr/lib");
5623
+ if (!n || typeof n != "object") return e;
5624
+ let r = this._getRegistry();
5625
+ for (let i of Object.keys(n)) {
5626
+ if (i.startsWith(".")) continue;
5627
+ let n = i.toLowerCase(), a = r[n] || Object.values(r).find((e) => e.name === n || e.bin === n), o = t.getFileByPath(`/usr/lib/${i}`) || {}, s = (typeof o == "object" ? Object.keys(o) : []).find((e) => e.endsWith(".wasm") || e.endsWith(".wat")), c = s ? `/usr/lib/${i}/${s}` : t.exists(`/usr/lib/${i}/${n}.wasm`) ? `/usr/lib/${i}/${n}.wasm` : null, l = a && a.bin || n, u = [l];
5628
+ a && a.aliases && u.push(...a.aliases), a && a.scripts && u.push(...Object.keys(a.scripts)), e[n] = Object.assign({
5629
+ name: n,
5630
+ bin: l,
5631
+ bins: u,
5632
+ version: a && a.version || "custom",
5633
+ description: a && a.description || `Installed package ${n}`,
5634
+ type: a && a.type || (c ? "custom-wasm" : "generic-runtime"),
5635
+ wasmPath: c
5636
+ }, a || {}), c && (e[n].wasmPath = c);
5479
5637
  }
5480
5638
  return e;
5481
5639
  }
@@ -5488,7 +5646,7 @@ try {
5488
5646
  wllamaModule = require(${JSON.stringify(n)});\n} catch (_) {\n try {\n wllamaModule = require('brsh/wbt/packages/wllama');\n } catch (e) {\n wllamaModule = require('./wllama');\n }\n}\nmodule.exports = wllamaModule.createWllamaCommand(${JSON.stringify(e)}, {}, ${JSON.stringify(t)});\n`;
5489
5647
  }
5490
5648
  let n = JSON.stringify(e, null, 2);
5491
- return e.repl ? `'use strict';\nconst pkgMeta = ${n};\nconst ReplCommand = typeof require !== 'undefined' ? require('brsh/ReplCommand') : globalThis.ReplCommand;\nmodule.exports = ReplCommand.createReplWasmCommand(pkgMeta, {}, ${JSON.stringify(t)});\n` : `'use strict';\nconst pkgMeta = ${n};\nconst WasmCommand = typeof require !== 'undefined' ? require('brsh/WasmCommand') : globalThis.WasmCommand;\nmodule.exports = WasmCommand.createGenericWasmCommand(pkgMeta, {}, ${JSON.stringify(t)});\n`;
5649
+ return e.repl ? `'use strict';\nconst pkgMeta = ${n};\nconst _Repl = typeof ReplCommand !== 'undefined' ? ReplCommand : (typeof require !== 'undefined' ? require('brsh/ReplCommand') : globalThis.ReplCommand);\nmodule.exports = _Repl.createReplWasmCommand(pkgMeta, {}, ${JSON.stringify(t)});\n` : `'use strict';\nconst pkgMeta = ${n};\nconst _Wasm = typeof WasmCommand !== 'undefined' ? WasmCommand : (typeof require !== 'undefined' ? require('brsh/WasmCommand') : globalThis.WasmCommand);\nmodule.exports = _Wasm.createGenericWasmCommand(pkgMeta, {}, ${JSON.stringify(t)});\n`;
5492
5650
  }
5493
5651
  _buildCommandsForPackage(e) {
5494
5652
  let t = this.constructor._config || {};
@@ -5526,63 +5684,65 @@ try {
5526
5684
  return s;
5527
5685
  }
5528
5686
  _registerPackageIntoContext(e) {
5529
- let t = this.context.getVar("PATH") || "/bin", n = (e.name || "").split("/").pop().toLowerCase(), r = (e.bin || n).toLowerCase(), i = `/usr/lib/${n}`, a = this._buildCommandsForPackage(e), o = [], s = e.wasmPath || (this.context.fs.exists(`${i}/${r}.wasm`) ? `${i}/${r}.wasm` : null), c = `${i}/package.json`, l = {
5687
+ let t = this._fs, n = this.constructor._config || {}, r = this._pathDir, i = (e.name || "").split("/").pop().toLowerCase(), a = (e.bin || i).toLowerCase(), o = `/usr/lib/${i}`, s = this._buildCommandsForPackage(e), c = [], l = e.adapter || e.name, u = !!(n.moduleLoader || n.fetch || l === "wllama" || this.constructor._adapters && this.constructor._adapters.has(l)), d = e.wasmPath || (t.exists(`${o}/${a}.wasm`) ? `${o}/${a}.wasm` : null), f = `${o}/package.json`, p = {
5530
5688
  name: e.name,
5531
5689
  version: e.version || "1.0.0",
5532
- bin: r,
5690
+ bin: a,
5533
5691
  aliases: e.aliases || [],
5534
- description: e.description || ""
5692
+ description: e.description || "",
5693
+ ...e.interactive ? { interactive: !0 } : {}
5535
5694
  };
5536
- this.context.fs.setFileByPath(c, JSON.stringify(l, null, 2), !0);
5537
- for (let { bin: n, Cmd: r } of a) {
5538
- let a = n.toLowerCase(), c;
5539
- if (s && (!e.type || e.type === "custom-wasm" || e.type === "wasm")) c = s;
5695
+ this._writeFileSafe(f, JSON.stringify(p, null, 2));
5696
+ for (let { bin: n, Cmd: i } of s) {
5697
+ let a = n.toLowerCase(), s;
5698
+ if (d && (!e.type || e.type === "custom-wasm" || e.type === "wasm")) s = d;
5540
5699
  else {
5541
- c = `${i}/${a}.js`;
5542
- let t = this._generateJsCommandSource(e, a);
5543
- this.context.fs.setFileByPath(c, t, !0), !this.context.fs.isRealFilesystem && typeof r == "function" && this.context.fs.setFileByPath(c, r, !0);
5700
+ s = `${o}/${a}.js`;
5701
+ let n = this._generateJsCommandSource(e, a);
5702
+ typeof i == "function" && (i.__source = n), !t.isRealFilesystem && typeof i == "function" && u ? this._writeFileSafe(s, i) : this._writeFileSafe(s, n);
5544
5703
  try {
5545
- this.context.fs.setMode(c, 493);
5704
+ t.setMode(s, 493);
5546
5705
  } catch {}
5547
5706
  }
5548
- this._createBinSymlink(t, a, c), o.push(a);
5707
+ this._createBinSymlink(r, a, s), c.push(a);
5549
5708
  }
5550
- for (let n of e.aliases || []) {
5551
- let c = n.toLowerCase();
5552
- if (!o.includes(c) && a.length > 0) {
5553
- let n = s && (!e.type || e.type === "custom-wasm" || e.type === "wasm") ? s : `${i}/${r}.js`;
5554
- this._createBinSymlink(t, c, n), o.push(c);
5709
+ for (let t of e.aliases || []) {
5710
+ let n = t.toLowerCase();
5711
+ if (!c.includes(n) && s.length > 0) {
5712
+ let t = d && (!e.type || e.type === "custom-wasm" || e.type === "wasm") ? d : `${o}/${a}.js`;
5713
+ this._createBinSymlink(r, n, t), c.push(n);
5555
5714
  }
5556
5715
  }
5557
- let u = e.scriptPaths || {};
5558
- for (let [e, n] of Object.entries(u)) {
5559
- let r = e.toLowerCase();
5560
- !o.includes(r) && this.context.fs.exists(n) && (this._createBinSymlink(t, r, n), o.push(r));
5716
+ let m = e.scriptPaths || {};
5717
+ for (let [e, n] of Object.entries(m)) {
5718
+ let i = e.toLowerCase();
5719
+ !c.includes(i) && t.exists(n) && (this._createBinSymlink(r, i, n), c.push(i));
5561
5720
  }
5562
5721
  if (e.scripts && typeof e.scripts == "object") for (let n of Object.keys(e.scripts)) {
5563
- let e = n.toLowerCase(), r = `${i}/${e}`;
5564
- !o.includes(e) && this.context.fs.exists(r) && (this._createBinSymlink(t, e, r), o.push(e));
5722
+ let e = n.toLowerCase(), i = `${o}/${e}`;
5723
+ !c.includes(e) && t.exists(i) && (this._createBinSymlink(r, e, i), c.push(e));
5565
5724
  }
5566
- return o;
5725
+ return c;
5567
5726
  }
5568
5727
  _createBinSymlink(e, t, n) {
5569
- let r = `${e}/${t.toLowerCase()}`;
5728
+ let r = this._fs, i = `${e}/${t.toLowerCase()}`;
5570
5729
  this._removeBin(e, t);
5571
5730
  try {
5572
- this.context.fs.createSymlink(n, r), this.context.fs.setMode(r, 493);
5731
+ r.createSymlink(n, i), r.setMode(i, 493);
5573
5732
  } catch {
5574
- this.context.fs.addFiles({ [r]: this.context.fs.getFileByPath(n) });
5733
+ this._writeFileSafe(i, r.getFileByPath(n));
5575
5734
  try {
5576
- this.context.fs.setMode(r, 493);
5735
+ r.setMode(i, 493);
5577
5736
  } catch {}
5578
5737
  }
5579
5738
  }
5580
5739
  _removeBin(e, t) {
5581
5740
  let n = `${e}/${t.toLowerCase()}`;
5582
- if (this.context.fs._deleteByAbsolutePath) this.context.fs._deleteByAbsolutePath(n), this.context.fs._triggerChange();
5583
- else try {
5584
- this.context.fs.deleteFileByPath(n);
5585
- } catch {}
5741
+ this._withWritableParent(n, (e) => {
5742
+ try {
5743
+ e.deleteFileByPath(n);
5744
+ } catch {}
5745
+ });
5586
5746
  }
5587
5747
  async run() {
5588
5748
  let e = [...this.arguments || []], t = e.length >= 2 && e[0].toLowerCase() === "run";
@@ -5694,9 +5854,9 @@ try {
5694
5854
  let s;
5695
5855
  s = typeof i.text == "function" ? await i.text() : typeof i.arrayBuffer == "function" ? new TextDecoder().decode(new Uint8Array(await i.arrayBuffer())) : "";
5696
5856
  let c = `${a}/${e}`;
5697
- this.context.fs._setFileRaw(c, s, !0);
5857
+ this._writeFileSafe(c, s);
5698
5858
  try {
5699
- this.context.fs.setMode(c, 493);
5859
+ this._fs.setMode(c, 493);
5700
5860
  } catch {}
5701
5861
  o[e] = c;
5702
5862
  }
@@ -5798,7 +5958,7 @@ try {
5798
5958
  return null;
5799
5959
  }
5800
5960
  async _pullPackageWasm(e, t = !1, n = !1, r = null) {
5801
- let i = this.constructor._config || {}, a = i.fetch || (typeof fetch == "function" ? fetch : null), { loadModule: o } = Q(), s = null, c = null, l = e.wasmUrl || (/\.(wasm|wat)(\?.*)?$/i.test(e.cdnUrl || "") ? e.cdnUrl : null);
5961
+ let i = this.constructor._config || {}, a = i.fetch || (typeof fetch == "function" ? fetch : null), { loadModule: o } = Z(), s = null, c = null, l = e.wasmUrl || (/\.(wasm|wat)(\?.*)?$/i.test(e.cdnUrl || "") ? e.cdnUrl : null);
5802
5962
  if (l && a) try {
5803
5963
  let n = await a(l);
5804
5964
  n && n.ok ? s = await this._readResponseBytes(n, `${e.name}.wasm`, t) : c = /* @__PURE__ */ Error(`HTTP ${n ? n.status : "error"} fetching ${l}`);
@@ -5812,7 +5972,7 @@ try {
5812
5972
  r && r.bytes && (s = r.bytes, e.wasmUrl = r.url, c = null);
5813
5973
  }
5814
5974
  }
5815
- let d = null, f = null;
5975
+ let u = null, d = null;
5816
5976
  if (e.cdnUrl || i.moduleLoader) {
5817
5977
  let t = typeof globalThis.fetch == "function" ? globalThis.fetch : null;
5818
5978
  t && s && s.byteLength > 0 && typeof Response < "u" && (globalThis.fetch = async (e, n) => {
@@ -5823,15 +5983,15 @@ try {
5823
5983
  }) : t(e, n);
5824
5984
  });
5825
5985
  try {
5826
- d = await o(e.name, e.cdnUrl, i.moduleLoader);
5986
+ u = await o(e.name, e.cdnUrl, i.moduleLoader);
5827
5987
  } catch (e) {
5828
- if (f = e, n) throw e;
5988
+ if (d = e, n) throw e;
5829
5989
  } finally {
5830
5990
  t && (globalThis.fetch = t);
5831
5991
  }
5832
5992
  }
5833
- if (!s && d) {
5834
- let e = d.default === void 0 ? d : d.default;
5993
+ if (!s && u) {
5994
+ let e = u.default === void 0 ? u : u.default;
5835
5995
  e instanceof Uint8Array ? s = e : e instanceof ArrayBuffer ? s = new Uint8Array(e) : e && (e.wasmBytes instanceof Uint8Array || e.wasm instanceof Uint8Array || e.wasmBinary instanceof Uint8Array) && (s = e.wasmBytes || e.wasm || e.wasmBinary);
5836
5996
  }
5837
5997
  if (!s && e.cdnUrl && a && !i.moduleLoader) try {
@@ -5878,12 +6038,12 @@ try {
5878
6038
  2,
5879
6039
  0,
5880
6040
  11
5881
- ])), !s && !d && (c || f) && !i.moduleLoader) throw c || f;
6041
+ ])), !s && !u && (c || d) && !i.moduleLoader) throw c || d;
5882
6042
  if (s) {
5883
6043
  let t = (e.name || "").split("/").pop().toLowerCase(), n = (e.bin || t).toLowerCase(), i = `${r || `/usr/lib/${t}`}/${n}.wasm`;
5884
- u(this.context.fs, i, s, "application/wasm");
6044
+ this._writeBytesSafe(i, s, "application/wasm");
5885
6045
  try {
5886
- this.context.fs.setMode(i, 493);
6046
+ this._fs.setMode(i, 493);
5887
6047
  } catch {}
5888
6048
  return i;
5889
6049
  }
@@ -5932,12 +6092,14 @@ try {
5932
6092
  let o = t.endsWith(".wat"), s = o ? ".wat" : ".wasm", c = `${`/usr/lib/${e}`}/${e}${s}`;
5933
6093
  if (o) {
5934
6094
  let e = await a.text();
5935
- this.context.fs._setFileRaw(c, e, !0);
6095
+ this._writeFileSafe(c, e);
5936
6096
  } else {
5937
6097
  let e = await a.arrayBuffer();
5938
- u(this.fs, c, new Uint8Array(e), "application/wasm");
6098
+ this._writeBytesSafe(c, new Uint8Array(e), "application/wasm");
5939
6099
  }
5940
- this.context.fs.setMode(c, 493);
6100
+ try {
6101
+ this._fs.setMode(c, 493);
6102
+ } catch {}
5941
6103
  let l = {
5942
6104
  name: e,
5943
6105
  bin: e,
@@ -5957,7 +6119,7 @@ try {
5957
6119
  this.stdErr = "E: Specify at least one package to remove", this.exitCode = 1;
5958
6120
  return;
5959
6121
  }
5960
- let n = this._getInstalledPackages(), r = this._getRegistry(), i = this.context.getVar("PATH") || "/bin";
6122
+ let n = this._getInstalledPackages(), r = this._getRegistry(), i = this._pathDir;
5961
6123
  for (let e of t) {
5962
6124
  let t = c(e), a = n[t] || n[e.toLowerCase()];
5963
6125
  if (!a) {
@@ -5975,7 +6137,7 @@ try {
5975
6137
  for (let e of s) this._removeBin(i, e);
5976
6138
  let l = `/usr/lib/${t}`;
5977
6139
  try {
5978
- this.context.fs.deleteFileByPath(l);
6140
+ this._fs.deleteFileByPath(l);
5979
6141
  } catch {}
5980
6142
  this.stdOut = `Removing ${a.name} (${a.version}) ...`;
5981
6143
  }
@@ -6026,7 +6188,7 @@ try {
6026
6188
  } catch (t) {
6027
6189
  this.stdErr = `W: Failed to fetch ${e}: ${t.message || t}`;
6028
6190
  }
6029
- Object.keys(r).length > 0 && this.context.fs._setFileRaw(`${p}/remote-registry.json`, JSON.stringify(r, null, 2), !0);
6191
+ Object.keys(r).length > 0 && this._writeFileSafe(`${p}/remote-registry.json`, JSON.stringify(r, null, 2));
6030
6192
  let a = this._getRegistry();
6031
6193
  this.stdOut = `Reading package lists... Done (${Object.keys(a).length} packages available)`;
6032
6194
  }
@@ -6050,10 +6212,10 @@ try {
6050
6212
  this.stdErr = `E: Unable to locate package ${t}`, this.exitCode = 100;
6051
6213
  return;
6052
6214
  }
6053
- let s = null, l = this.context.getVar("PATH") || "/bin", u = !1;
6215
+ let s = this._fs, l = null, u = this._pathDir;
6054
6216
  try {
6055
- if (a || (s = `/tmp/.wbt-run-${n}-${Date.now()}`), (o.type === "custom-wasm" || o.type === "wasm") && !o.wasmPath) try {
6056
- let e = await this._pullPackageWasm(o, !0, !1, s);
6217
+ if (a || (l = `/tmp/.wbt-run-${n}-${Date.now()}`), (o.type === "custom-wasm" || o.type === "wasm") && !o.wasmPath) try {
6218
+ let e = await this._pullPackageWasm(o, !0, !1, l);
6057
6219
  e && (o = Object.assign({}, o, { wasmPath: e }));
6058
6220
  } catch (e) {
6059
6221
  this.stdErr = `E: Failed to fetch ${o.name}: ${e.message || e}`, this.exitCode = 1;
@@ -6062,40 +6224,58 @@ try {
6062
6224
  let r = t.toLowerCase(), i;
6063
6225
  if (o.scripts && o.scripts[r]) {
6064
6226
  let t = o.scriptPaths && o.scriptPaths[r] || `/usr/lib/${n}/${r}`;
6065
- if (!this.context.fs.exists(t)) try {
6066
- let e = await this._pullPackageScripts(o, !0, s);
6227
+ if (!s.exists(t)) try {
6228
+ let e = await this._pullPackageScripts(o, !0, l);
6067
6229
  e && e[r] && (t = e[r]);
6068
6230
  } catch (e) {
6069
6231
  this.stdErr = `E: Failed to fetch script ${r}: ${e.message || e}`, this.exitCode = 1;
6070
6232
  return;
6071
6233
  }
6072
- s && (this.context.setVar("PATH", `${s}:${l}`), u = !0), i = new (K())(this.context.fs.getFileByPath(t), e, this.context);
6234
+ let a = (e) => this.context && typeof this.context.getVar == "function" ? this.context.getVar(e) : "", c = l ? `${l}:${u}` : u, d = this.context && this.context.vars ? Object.assign({}, this.context.vars) : {
6235
+ HOME: a("HOME") || "/root",
6236
+ HOST: a("HOST") || "browser",
6237
+ COLUMNS: String(this.stdout && this.stdout.columns || a("COLUMNS") || 80),
6238
+ LINES: String(this.stdout && this.stdout.rows || a("LINES") || 24)
6239
+ };
6240
+ d.PATH = c;
6241
+ let f = {
6242
+ vars: d,
6243
+ aliases: this.context && this.context.aliases || {},
6244
+ getVar: (e) => e === "PATH" ? c : d[e] || a(e),
6245
+ getAlias: (e) => this.context && typeof this.context.getAlias == "function" ? this.context.getAlias(e) : null,
6246
+ getCommand: (e) => this.context && typeof this.context.getCommand == "function" ? this.context.getCommand(e) : null
6247
+ };
6248
+ i = new (re())(s.getFileByPath(t), e, f), i.fs = s;
6073
6249
  } else {
6074
6250
  let t = this._buildCommandsForPackage(o), n = (t.find((e) => e.bin === r) || t[0]).Cmd;
6075
- i = new n(e, this.context);
6251
+ i = new n(e, this.context), i.requiresFilesystem && (i.fs = typeof s.sandbox == "function" ? s.sandbox() : s);
6076
6252
  }
6077
- i.requiresFilesystem && (i.fs = this.context.fs.sandbox()), this._activeSubCommand = i, i.stdinStream = this.stdinStream, i.stdin = this.stdin && !this.stdin.isTTY ? this.stdin : this.stdinStream;
6078
- let c = (e) => {
6253
+ this._activeSubCommand = i, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData), i.stdinStream = this.stdinStream, i.stdin = this.stdin && !this.stdin.isTTY ? this.stdin : this.stdinStream, i._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", i._onStdinStreamData), this.stdout && i.stdout && (this.stdout.columns && (i.stdout.columns = this.stdout.columns), this.stdout.rows && (i.stdout.rows = this.stdout.rows)), this.stderr && i.stderr && (this.stderr.columns && (i.stderr.columns = this.stderr.columns), this.stderr.rows && (i.stderr.rows = this.stderr.rows));
6254
+ let c = () => {
6255
+ !this.stdout || !i.stdout || (typeof i.stdout.resize == "function" ? i.stdout.resize(this.stdout.columns, this.stdout.rows) : (i.stdout.columns = this.stdout.columns, i.stdout.rows = this.stdout.rows));
6256
+ };
6257
+ this.stdout && typeof this.stdout.on == "function" && this.stdout.on("resize", c);
6258
+ let d = (e) => {
6079
6259
  this.stdout && typeof this.stdout.write == "function" && this.stdout.write(e);
6080
- }, d = (e) => {
6081
- this.stderr && typeof this.stderr.write == "function" && this.stderr.write(e);
6082
6260
  }, f = (e) => {
6261
+ this.stderr && typeof this.stderr.write == "function" && this.stderr.write(e);
6262
+ }, p = (e) => {
6083
6263
  let t = Array.isArray(e) ? e : e && typeof e.getStdOutput == "function" ? e.getStdOutput() : [];
6084
6264
  for (let e of t) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
6085
6265
  this.flush();
6086
6266
  };
6087
- i.stdout && typeof i.stdout.on == "function" && i.stdout.on("data", c), i.stderr && typeof i.stderr.on == "function" && i.stderr.on("data", d), typeof i.on == "function" && i.on("flush", f);
6088
- let p;
6267
+ i.stdout && typeof i.stdout.on == "function" && i.stdout.on("data", d), i.stderr && typeof i.stderr.on == "function" && i.stderr.on("data", f), typeof i.on == "function" && i.on("flush", p);
6268
+ let m;
6089
6269
  try {
6090
- p = await i.runCommand();
6270
+ m = await i.runCommand();
6091
6271
  } finally {
6092
- this._activeSubCommand = null, i.stdout && typeof i.stdout.off == "function" && i.stdout.off("data", c), i.stderr && typeof i.stderr.off == "function" && i.stderr.off("data", d), typeof i.removeListener == "function" && i.removeListener("flush", f);
6272
+ this._activeSubCommand = null, this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", c), i._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", i._onStdinStreamData), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), i.stdout && typeof i.stdout.off == "function" && i.stdout.off("data", d), i.stderr && typeof i.stderr.off == "function" && i.stderr.off("data", f), typeof i.removeListener == "function" && i.removeListener("flush", p);
6093
6273
  }
6094
- if (!i.interactive && p) for (let e of p.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
6095
- this.exitCode = p ? p.getExitCode() : 0;
6274
+ if (!i.interactive && m) for (let e of m.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
6275
+ this.exitCode = m ? m.getExitCode() : 0;
6096
6276
  } finally {
6097
- if (u && this.context.setVar("PATH", l), s) try {
6098
- this.context.fs.deleteFileByPath(s);
6277
+ if (l && s) try {
6278
+ s.deleteFileByPath(l);
6099
6279
  } catch {}
6100
6280
  }
6101
6281
  }
@@ -6135,6 +6315,6 @@ try {
6135
6315
  t.exports = h, t.exports.Wbt = h, t.exports.DEFAULT_REGISTRY = s, t.exports.createGenericWasmCommand = d, t.exports.createReplWasmCommand = f;
6136
6316
  }));
6137
6317
  //#endregion
6138
- export default se();
6318
+ export default ce();
6139
6319
 
6140
6320
  //# sourceMappingURL=wbt.es.js.map