brsh 3.5.0 → 3.6.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
@@ -483,15 +483,15 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
483
483
  }, u.prototype.readUint32BE = u.prototype.readUInt32BE = function(e, t) {
484
484
  return e >>>= 0, t || H(e, 4, this.length), this[e] * 16777216 + (this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3]);
485
485
  }, u.prototype.readBigUInt64LE = $(function(e) {
486
- e >>>= 0, X(e, "offset");
486
+ e >>>= 0, Z(e, "offset");
487
487
  let t = this[e], n = this[e + 7];
488
- (t === void 0 || n === void 0) && Z(e, this.length - 8);
488
+ (t === void 0 || n === void 0) && re(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
491
  }), u.prototype.readBigUInt64BE = $(function(e) {
492
- e >>>= 0, X(e, "offset");
492
+ e >>>= 0, Z(e, "offset");
493
493
  let t = this[e], n = this[e + 7];
494
- (t === void 0 || n === void 0) && Z(e, this.length - 8);
494
+ (t === void 0 || n === void 0) && re(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) {
@@ -519,15 +519,15 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
519
519
  }, u.prototype.readInt32BE = function(e, t) {
520
520
  return e >>>= 0, t || H(e, 4, this.length), this[e] << 24 | this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3];
521
521
  }, u.prototype.readBigInt64LE = $(function(e) {
522
- e >>>= 0, X(e, "offset");
522
+ e >>>= 0, Z(e, "offset");
523
523
  let t = this[e], n = this[e + 7];
524
- (t === void 0 || n === void 0) && Z(e, this.length - 8);
524
+ (t === void 0 || n === void 0) && re(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
527
  }), u.prototype.readBigInt64BE = $(function(e) {
528
- e >>>= 0, X(e, "offset");
528
+ e >>>= 0, Z(e, "offset");
529
529
  let t = this[e], n = this[e + 7];
530
- (t === void 0 || n === void 0) && Z(e, this.length - 8);
530
+ (t === void 0 || n === void 0) && re(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,14 +572,14 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
572
572
  return e = +e, t >>>= 0, n || U(this, e, t, 4, 4294967295, 0), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
573
573
  };
574
574
  function W(e, t, n, r, i) {
575
- re(t, r, i, e, n, 7);
575
+ ne(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
581
  function G(e, t, n, r, i) {
582
- re(t, r, i, e, n, 7);
582
+ ne(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));
@@ -620,24 +620,24 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
620
620
  }), u.prototype.writeBigInt64BE = $(function(e, t = 0) {
621
621
  return G(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
622
622
  });
623
- function ee(e, t, n, r, i, a) {
623
+ function K(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 K(e, t, r, i, a) {
627
- return t = +t, r >>>= 0, a || ee(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
626
+ function q(e, t, r, i, a) {
627
+ return t = +t, r >>>= 0, a || K(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 K(this, e, t, !0, n);
630
+ return q(this, e, t, !0, n);
631
631
  }, u.prototype.writeFloatBE = function(e, t, n) {
632
- return K(this, e, t, !1, n);
632
+ return q(this, e, t, !1, n);
633
633
  };
634
- function q(e, t, r, i, a) {
635
- return t = +t, r >>>= 0, a || ee(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
634
+ function J(e, t, r, i, a) {
635
+ return t = +t, r >>>= 0, a || K(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 q(this, e, t, !0, n);
638
+ return J(this, e, t, !0, n);
639
639
  }, u.prototype.writeDoubleBE = function(e, t, n) {
640
- return q(this, e, t, !1, n);
640
+ return J(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 J = {};
672
- function Y(e, t, n) {
673
- J[e] = class extends n {
671
+ let Y = {};
672
+ function X(e, t, n) {
673
+ Y[e] = class extends n {
674
674
  constructor() {
675
675
  super(), Object.defineProperty(this, "message", {
676
676
  value: t.apply(this, arguments),
@@ -694,34 +694,34 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
694
694
  }
695
695
  };
696
696
  }
697
- Y("ERR_BUFFER_OUT_OF_BOUNDS", function(e) {
697
+ X("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), Y("ERR_INVALID_ARG_TYPE", function(e, t) {
699
+ }, RangeError), X("ERR_INVALID_ARG_TYPE", function(e, t) {
700
700
  return `The "${e}" argument must be of type number. Received type ${typeof t}`;
701
- }, TypeError), Y("ERR_OUT_OF_RANGE", function(e, t, n) {
701
+ }, TypeError), X("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 = te(String(n)) : typeof n == "bigint" && (i = String(n), (n > BigInt(2) ** BigInt(32) || n < -(BigInt(2) ** BigInt(32))) && (i = te(i)), i += "n"), r += ` It must be ${t}. Received ${i}`, r;
703
+ return Number.isInteger(n) && Math.abs(n) > 2 ** 32 ? i = ee(String(n)) : typeof n == "bigint" && (i = String(n), (n > BigInt(2) ** BigInt(32) || n < -(BigInt(2) ** BigInt(32))) && (i = ee(i)), i += "n"), r += ` It must be ${t}. Received ${i}`, r;
704
704
  }, RangeError);
705
- function te(e) {
705
+ function ee(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 ne(e, t, n) {
711
- X(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && Z(t, e.length - (n + 1));
710
+ function te(e, t, n) {
711
+ Z(t, "offset"), (e[t] === void 0 || e[t + n] === void 0) && re(t, e.length - (n + 1));
712
712
  }
713
- function re(e, t, n, r, i, a) {
713
+ function ne(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 J.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 Y.ERR_OUT_OF_RANGE("value", i, e);
717
717
  }
718
- ne(r, i, a);
718
+ te(r, i, a);
719
719
  }
720
- function X(e, t) {
721
- if (typeof e != "number") throw new J.ERR_INVALID_ARG_TYPE(t, "number", e);
720
+ function Z(e, t) {
721
+ if (typeof e != "number") throw new Y.ERR_INVALID_ARG_TYPE(t, "number", e);
722
722
  }
723
- function Z(e, t, n) {
724
- throw Math.floor(e) === e ? t < 0 ? new J.ERR_BUFFER_OUT_OF_BOUNDS() : new J.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (X(e, n), new J.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
723
+ function re(e, t, n) {
724
+ throw Math.floor(e) === e ? t < 0 ? new Y.ERR_BUFFER_OUT_OF_BOUNDS() : new Y.ERR_OUT_OF_RANGE(n || "offset", `>= ${+!!n} and <= ${t}`, e) : (Z(e, n), new Y.ERR_OUT_OF_RANGE(n || "offset", "an integer", e));
725
725
  }
726
726
  let ie = /[^+/0-9A-Za-z-_]/g;
727
727
  function ae(e) {
@@ -1706,7 +1706,7 @@ function I(e, t) {
1706
1706
  this.fun = e, this.array = t;
1707
1707
  }
1708
1708
  function L() {}
1709
- var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1709
+ var R, z, B, V, H, U, W, G, K, q, J = e((() => {
1710
1710
  R = { exports: {} }, z = R.exports = {}, (function() {
1711
1711
  try {
1712
1712
  B = typeof setTimeout == "function" ? setTimeout : A;
@@ -1734,8 +1734,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1734
1734
  throw Error("process.chdir is not supported");
1735
1735
  }, z.umask = function() {
1736
1736
  return 0;
1737
- }, ee = R.exports, K = /* @__PURE__ */ k(ee);
1738
- })), J = /* @__PURE__ */ t(((e, t) => {
1737
+ }, K = R.exports, q = /* @__PURE__ */ k(K);
1738
+ })), Y = /* @__PURE__ */ t(((e, t) => {
1739
1739
  var n = T();
1740
1740
  t.exports = class extends n {
1741
1741
  get captureInput() {
@@ -1765,8 +1765,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1765
1765
  });
1766
1766
  }
1767
1767
  };
1768
- })), Y = /* @__PURE__ */ t(((e, t) => {
1769
- b(), q();
1768
+ })), X = /* @__PURE__ */ t(((e, t) => {
1769
+ b(), J();
1770
1770
  var { BinaryFile: n, SymlinkRef: r } = O(), i = new Uint8Array([
1771
1771
  66,
1772
1772
  82,
@@ -1871,7 +1871,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1871
1871
  let t = e.$c;
1872
1872
  if (m[t]) return m[t];
1873
1873
  if (f.inlineCommands && f.inlineCommands[t]) try {
1874
- let e = T(), n = J();
1874
+ let e = T(), n = Y();
1875
1875
  return Function("Command", "InteractiveCommand", `return (${f.inlineCommands[t]});`)(e, n);
1876
1876
  } catch {
1877
1877
  return null;
@@ -1903,8 +1903,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1903
1903
  let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
1904
1904
  return new Uint8Array(r);
1905
1905
  }
1906
- if (K !== void 0 && typeof K.getBuiltinModule == "function") {
1907
- let t = K.getBuiltinModule("zlib");
1906
+ if (q !== void 0 && typeof q.getBuiltinModule == "function") {
1907
+ let t = q.getBuiltinModule("zlib");
1908
1908
  if (t) return new Uint8Array(t.gunzipSync(y.from(e.buffer, e.byteOffset, e.byteLength)));
1909
1909
  }
1910
1910
  throw Error("Gzip decompression is not supported in this environment");
@@ -1923,8 +1923,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1923
1923
  return f(new Uint8Array(n), t);
1924
1924
  }
1925
1925
  if (typeof e == "string") {
1926
- if (!/^https?:\/\//i.test(e) && K !== void 0 && typeof K.getBuiltinModule == "function" && typeof window > "u") try {
1927
- let n = K.getBuiltinModule("fs");
1926
+ if (!/^https?:\/\//i.test(e) && q !== void 0 && typeof q.getBuiltinModule == "function" && typeof window > "u") try {
1927
+ let n = q.getBuiltinModule("fs");
1928
1928
  if (n && n.existsSync(e)) {
1929
1929
  let r = await n.promises.readFile(e);
1930
1930
  return f(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
@@ -2036,7 +2036,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2036
2036
  }
2037
2037
  }
2038
2038
  };
2039
- })), te = /* @__PURE__ */ t(((e, t) => {
2039
+ })), ee = /* @__PURE__ */ t(((e, t) => {
2040
2040
  b();
2041
2041
  var n = O(), { BinaryFile: r, SymlinkRef: i } = n;
2042
2042
  function a(e) {
@@ -2061,20 +2061,20 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2061
2061
  t.exports = class extends n {
2062
2062
  constructor(e = "/", t = {}, n = {}, r = null) {
2063
2063
  if (super(), t instanceof Uint8Array || t instanceof ArrayBuffer) {
2064
- let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
2064
+ let { deserializeBinaryFilesystem: e } = X(), r = e(t);
2065
2065
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
2066
2066
  } 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)) {
2067
- let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
2067
+ let { deserializeBinaryFilesystem: e } = X(), r = e(t);
2068
2068
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
2069
2069
  }
2070
2070
  a(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e, this._onChange = r, this._changeScheduled = !1;
2071
2071
  }
2072
2072
  toBinaryContainer(e = {}) {
2073
- let { serializeBinaryFilesystem: t } = Y();
2073
+ let { serializeBinaryFilesystem: t } = X();
2074
2074
  return t(this.fileSystem, this.permissions, e);
2075
2075
  }
2076
2076
  static fromBinaryContainer(e, t = {}) {
2077
- let { deserializeBinaryFilesystem: n } = Y();
2077
+ let { deserializeBinaryFilesystem: n } = X();
2078
2078
  return n(e, t);
2079
2079
  }
2080
2080
  getFileByPath(e) {
@@ -2252,10 +2252,10 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2252
2252
  return null;
2253
2253
  }
2254
2254
  }, t.exports.BinaryFile = r, t.exports.SymlinkRef = i;
2255
- })), ne = /* @__PURE__ */ t(((e, t) => {
2255
+ })), te = /* @__PURE__ */ t(((e, t) => {
2256
2256
  t.exports = null;
2257
- })), re = /* @__PURE__ */ t(((e, t) => {
2258
- q();
2257
+ })), ne = /* @__PURE__ */ t(((e, t) => {
2258
+ J();
2259
2259
  function n(e) {
2260
2260
  if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
2261
2261
  }
@@ -2293,7 +2293,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2293
2293
  resolve: function() {
2294
2294
  for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
2295
2295
  var o;
2296
- a >= 0 ? o = arguments[a] : (i === void 0 && (i = K.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
2296
+ a >= 0 ? o = arguments[a] : (i === void 0 && (i = q.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
2297
2297
  }
2298
2298
  return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
2299
2299
  },
@@ -2422,19 +2422,76 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2422
2422
  posix: null
2423
2423
  };
2424
2424
  a.posix = a, t.exports = a;
2425
- })), X = /* @__PURE__ */ t(((e, t) => {
2425
+ })), Z = /* @__PURE__ */ t(((e, t) => {
2426
2426
  b();
2427
- var n = D(), { BinaryFile: r } = te(), i = 0, a = 8, o = 20, s = 28, c = 31, l = 44, u = 54, d = 70, f = 0, p = 2, m = 3, h = 4, g = 1, _ = 2, v = 4, x = 8, S = 1, C = class extends n {
2427
+ var n = D(), { BinaryFile: r } = ee(), i = 0, a = 8, o = 20, s = 28, c = 31, l = 44, u = 54, d = 70, f = 0, p = 2, m = 3, h = 4, g = 1, _ = 2, v = 4, x = 8, S = 1, C = class extends n {
2428
2428
  get name() {
2429
2429
  return "wasm";
2430
2430
  }
2431
2431
  get requiresFilesystem() {
2432
2432
  return !0;
2433
2433
  }
2434
+ get interactive() {
2435
+ if ((this.arguments || []).some((e) => e === "--help" || e === "-h" || e === "--version" || e === "-V" || e === "-v")) return !1;
2436
+ if (this._isInteractive !== void 0) return !!this._isInteractive;
2437
+ if (this._pkgMeta && this._pkgMeta.interactive !== void 0) return !!this._pkgMeta.interactive;
2438
+ let e = (this.script || this.name || "").toLowerCase();
2439
+ return e === "nano" || e.endsWith("/nano") || e.endsWith("nano.wasm");
2440
+ }
2441
+ get captureInput() {
2442
+ return this.interactive;
2443
+ }
2444
+ _enterAltScreen() {
2445
+ 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"));
2446
+ }
2447
+ _exitAltScreen() {
2448
+ 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"));
2449
+ }
2450
+ _keyToBytes(e) {
2451
+ if (!e) return null;
2452
+ if (typeof e != "string") return e instanceof Uint8Array ? e : new Uint8Array([Number(e) & 255]);
2453
+ let t = e.match(/^\^([A-Za-z@\[\\\]^_?])$/);
2454
+ if (t) {
2455
+ let e = t[1].toUpperCase();
2456
+ return e === "?" ? new Uint8Array([127]) : new Uint8Array([e.charCodeAt(0) - 64]);
2457
+ }
2458
+ let n = {
2459
+ Enter: "\r",
2460
+ Return: "\r",
2461
+ Backspace: "",
2462
+ Tab: " ",
2463
+ Escape: "\x1B",
2464
+ ArrowUp: "\x1B[A",
2465
+ ArrowDown: "\x1B[B",
2466
+ ArrowRight: "\x1B[C",
2467
+ ArrowLeft: "\x1B[D",
2468
+ Home: "\x1B[H",
2469
+ End: "\x1B[F",
2470
+ PageUp: "\x1B[5~",
2471
+ PageDown: "\x1B[6~",
2472
+ Delete: "\x1B[3~",
2473
+ Insert: "\x1B[2~"
2474
+ };
2475
+ return n[e] ? new TextEncoder().encode(n[e]) : new TextEncoder().encode(e);
2476
+ }
2477
+ onInput(e) {
2478
+ if (!this._handlingStreamData) {
2479
+ if (typeof this._externalKeyHandler == "function") {
2480
+ this._externalKeyHandler(e);
2481
+ return;
2482
+ }
2483
+ this.stdinStream && this.stdinStream.isRaw;
2484
+ }
2485
+ }
2486
+ runCommand() {
2487
+ return super.runCommand().finally(() => {
2488
+ this._inAltScreen && this._exitAltScreen();
2489
+ });
2490
+ }
2434
2491
  run() {
2435
2492
  let e = this.script, t = (() => {
2436
2493
  try {
2437
- return ne();
2494
+ return te();
2438
2495
  } catch {
2439
2496
  return null;
2440
2497
  }
@@ -2502,29 +2559,61 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2502
2559
  let t = {
2503
2560
  1: "",
2504
2561
  2: ""
2505
- }, n = new TextDecoder(), b = new TextEncoder(), C = null, w = (e, n) => {
2562
+ }, n = new TextDecoder(), b = new TextEncoder(), C = null, w = null, T = !1, E = 0, D = null, O = null, k = null, A = null, N = !!(this.interactive && (this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY)), P = (e, n) => {
2563
+ if (N && (e === 1 || e === 2)) {
2564
+ if (e === 1 && this.stdout) {
2565
+ this.stdout.write(n);
2566
+ return;
2567
+ }
2568
+ if (e === 2 && this.stderr) {
2569
+ this.stderr.write(n);
2570
+ return;
2571
+ }
2572
+ }
2506
2573
  t[e] = (t[e] || "") + n;
2507
2574
  let r = t[e].split("\n");
2508
2575
  t[e] = r.pop();
2509
2576
  for (let t of r) e === 1 ? this.stdOut = t : this.stdErr = t;
2510
- }, T = () => {
2511
- t[1] &&= (this.stdOut = t[1], ""), t[2] &&= (this.stdErr = t[2], "");
2512
- }, E = typeof this.stdin == "string" ? b.encode(this.stdin) : this.stdin instanceof Uint8Array ? this.stdin : y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), D = 0, O = this.context && this.context.fs ? this.context.fs : this.fs, k = 5, A = new Map([[3, {
2577
+ }, F = () => {
2578
+ t[1] &&= (N && this.stdout ? this.stdout.write(t[1]) : this.stdOut = t[1], ""), t[2] &&= (N && this.stderr ? this.stderr.write(t[2]) : this.stdErr = t[2], "");
2579
+ }, I = [], L = (e) => {
2580
+ if (!(!e || e.length === 0)) {
2581
+ for (let t = 0; t < e.length; t++) I.push(e[t]);
2582
+ if (O) {
2583
+ let e = O;
2584
+ O = null, e();
2585
+ }
2586
+ }
2587
+ };
2588
+ A = (e) => {
2589
+ this._handlingStreamData = !0;
2590
+ try {
2591
+ L(typeof e == "string" ? b.encode(e) : e instanceof Uint8Array ? e : y !== void 0 && y.isBuffer(e) ? new Uint8Array(e) : b.encode(String(e ?? "")));
2592
+ } finally {
2593
+ this._handlingStreamData = !1;
2594
+ }
2595
+ }, this._externalKeyHandler = (e) => {
2596
+ if (this._handlingStreamData) return;
2597
+ let t = this._keyToBytes(e);
2598
+ t && L(t);
2599
+ }, N && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", A), N && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", A);
2600
+ let R = !N && typeof this.stdin == "string" ? b.encode(this.stdin) : !N && this.stdin instanceof Uint8Array ? this.stdin : !N && y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), z = 0, B = this.context && this.context.fs ? this.context.fs : this.fs, V = 5, H = new Map([[3, {
2513
2601
  type: "preopen",
2514
2602
  path: "/",
2515
2603
  guestName: "/"
2516
2604
  }], [4, {
2517
2605
  type: "preopen",
2518
- path: O && O.cwd || "/",
2606
+ path: B && B.cwd || "/",
2519
2607
  guestName: "."
2520
- }]]), N = (e, t) => {
2521
- let n = A.get(e);
2608
+ }]]), U = (e, t) => {
2609
+ let n = H.get(e);
2522
2610
  if (!n || n.type !== "preopen" && n.type !== "dir") return null;
2523
- if (t.startsWith("/")) return O.absolutePath(t);
2611
+ if (t.startsWith("/")) return B.absolutePath(t);
2612
+ if (!t || t === ".") return B.absolutePath(n.path);
2524
2613
  let r = n.path.endsWith("/") ? n.path : n.path + "/";
2525
- return O.absolutePath(r + t);
2526
- }, P = (e) => {
2527
- if (!(!e || e.type !== "file" || !e.dirty || !O)) try {
2614
+ return B.absolutePath(r + t);
2615
+ }, W = (e) => {
2616
+ if (!(!e || e.type !== "file" || !e.dirty || !B)) try {
2528
2617
  let t = !0;
2529
2618
  for (let n = 0; n < e.bytes.length; n++) if (e.bytes[n] === 0) {
2530
2619
  t = !1;
@@ -2532,14 +2621,20 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2532
2621
  }
2533
2622
  if (t) {
2534
2623
  let t = n.decode(e.bytes);
2535
- O.setFileByPath(e.path, t, !0);
2624
+ B.setFileByPath(e.path, t, !0);
2536
2625
  } else {
2537
2626
  let t = new Uint8Array(e.bytes.length);
2538
- t.set(e.bytes), O.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
2627
+ t.set(e.bytes), B.setFileByPath(e.path, new r(t.buffer, "application/octet-stream"), !0);
2539
2628
  }
2540
2629
  e.dirty = !1;
2541
2630
  } catch {}
2542
- }, F = Object.entries(this.context && this.context.vars || {}).map(([e, t]) => `${e}=${t}`), I = new Proxy({
2631
+ }, G = {
2632
+ TERM: "xterm-256color",
2633
+ COLORTERM: "truecolor",
2634
+ COLUMNS: String(this.stdout && this.stdout.columns || this.context && typeof this.context.getVar == "function" && this.context.getVar("COLUMNS") || 80),
2635
+ LINES: String(this.stdout && this.stdout.rows || this.context && typeof this.context.getVar == "function" && this.context.getVar("LINES") || 24),
2636
+ ...this.context && this.context.vars || {}
2637
+ }, K = Object.entries(G).map(([e, t]) => `${e}=${t}`), q = new Proxy({
2543
2638
  fd_write: (e, t, r, o) => {
2544
2639
  if (!C) return a;
2545
2640
  let s = new DataView(C.buffer);
@@ -2547,11 +2642,11 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2547
2642
  let a = 0;
2548
2643
  for (let i = 0; i < r; i++) {
2549
2644
  let r = s.getUint32(t + i * 8, !0), o = s.getUint32(t + i * 8 + 4, !0);
2550
- o > 0 && w(e, n.decode(new Uint8Array(C.buffer, r, o))), a += o;
2645
+ o > 0 && P(e, n.decode(new Uint8Array(C.buffer, r, o))), a += o;
2551
2646
  }
2552
2647
  return s.setUint32(o, a, !0), i;
2553
2648
  }
2554
- let c = A.get(e);
2649
+ let c = H.get(e);
2555
2650
  if (!c || c.type !== "file") return a;
2556
2651
  let l = 0;
2557
2652
  for (let e = 0; e < r; e++) {
@@ -2571,14 +2666,36 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2571
2666
  if (!C) return a;
2572
2667
  let o = new DataView(C.buffer);
2573
2668
  if (e === 0) {
2669
+ if (N && T) {
2670
+ if ((typeof w?.exports?.asyncify_get_state == "function" ? w.exports.asyncify_get_state() : 0) === 2) {
2671
+ w.exports.asyncify_stop_rewind();
2672
+ let e = 0;
2673
+ for (let r = 0; r < n && I.length > 0; r++) {
2674
+ let n = o.getUint32(t + r * 8, !0), i = o.getUint32(t + r * 8 + 4, !0), a = Math.min(i, I.length), s = I.splice(0, a);
2675
+ new Uint8Array(C.buffer).set(s, n), e += a;
2676
+ }
2677
+ return o.setUint32(r, e, !0), i;
2678
+ }
2679
+ if (I.length > 0) {
2680
+ let e = 0;
2681
+ for (let r = 0; r < n && I.length > 0; r++) {
2682
+ let n = o.getUint32(t + r * 8, !0), i = o.getUint32(t + r * 8 + 4, !0), a = Math.min(i, I.length), s = I.splice(0, a);
2683
+ new Uint8Array(C.buffer).set(s, n), e += a;
2684
+ }
2685
+ return o.setUint32(r, e, !0), i;
2686
+ }
2687
+ return w.exports.asyncify_start_unwind(E), D = new Promise((e) => {
2688
+ O = e;
2689
+ }), o.setUint32(r, 0, !0), i;
2690
+ }
2574
2691
  let e = 0;
2575
- for (let r = 0; r < n && D < E.length; r++) {
2576
- let n = o.getUint32(t + r * 8, !0), i = o.getUint32(t + r * 8 + 4, !0), a = Math.min(i, E.length - D);
2577
- new Uint8Array(C.buffer).set(E.slice(D, D + a), n), D += a, e += a;
2692
+ for (let r = 0; r < n && z < R.length; r++) {
2693
+ let n = o.getUint32(t + r * 8, !0), i = o.getUint32(t + r * 8 + 4, !0), a = Math.min(i, R.length - z);
2694
+ new Uint8Array(C.buffer).set(R.slice(z, z + a), n), z += a, e += a;
2578
2695
  }
2579
2696
  return o.setUint32(r, e, !0), i;
2580
2697
  }
2581
- let s = A.get(e);
2698
+ let s = H.get(e);
2582
2699
  if (!s || s.type !== "file") return a;
2583
2700
  let c = 0;
2584
2701
  for (let e = 0; e < n && s.pos < s.bytes.length; e++) {
@@ -2590,7 +2707,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2590
2707
  fd_seek: (e, t, n, r, o) => {
2591
2708
  if (!C) return a;
2592
2709
  if (e <= 2) return d;
2593
- let c = A.get(e);
2710
+ let c = H.get(e);
2594
2711
  if (!c || c.type !== "file") return a;
2595
2712
  let l, u, f;
2596
2713
  typeof t == "bigint" ? (l = Number(t), u = n, f = r) : (l = t, u = r, f = o);
@@ -2603,32 +2720,32 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2603
2720
  },
2604
2721
  fd_tell: (e, t) => {
2605
2722
  if (!C) return a;
2606
- let n = A.get(e);
2723
+ let n = H.get(e);
2607
2724
  return !n || n.type !== "file" ? a : (new DataView(C.buffer).setBigUint64(t, BigInt(n.pos), !0), i);
2608
2725
  },
2609
2726
  fd_close: (e) => {
2610
2727
  if (e <= 2) return i;
2611
- let t = A.get(e);
2612
- return t ? (P(t), A.delete(e), i) : a;
2728
+ let t = H.get(e);
2729
+ return t ? (W(t), H.delete(e), i) : a;
2613
2730
  },
2614
2731
  fd_sync: (e) => {
2615
- let t = A.get(e);
2616
- return t && P(t), i;
2732
+ let t = H.get(e);
2733
+ return t && W(t), i;
2617
2734
  },
2618
2735
  fd_datasync: (e) => {
2619
- let t = A.get(e);
2620
- return t && P(t), i;
2736
+ let t = H.get(e);
2737
+ return t && W(t), i;
2621
2738
  },
2622
2739
  fd_prestat_get: (e, t) => {
2623
2740
  if (!C) return a;
2624
- let n = A.get(e);
2741
+ let n = H.get(e);
2625
2742
  if (!n || n.type !== "preopen") return a;
2626
2743
  let r = new DataView(C.buffer), o = b.encode(n.guestName);
2627
2744
  return r.setUint8(t, 0), r.setUint32(t + 4, o.length, !0), i;
2628
2745
  },
2629
2746
  fd_prestat_dir_name: (e, t, n) => {
2630
2747
  if (!C) return a;
2631
- let r = A.get(e);
2748
+ let r = H.get(e);
2632
2749
  if (!r || r.type !== "preopen") return a;
2633
2750
  let o = b.encode(r.guestName);
2634
2751
  return new Uint8Array(C.buffer, t, Math.min(n, o.length)).set(o.subarray(0, n)), i;
@@ -2638,7 +2755,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2638
2755
  let n = new DataView(C.buffer), r = f;
2639
2756
  if (e <= 2) r = p;
2640
2757
  else {
2641
- let t = A.get(e);
2758
+ let t = H.get(e);
2642
2759
  if (!t) return a;
2643
2760
  r = t.type === "preopen" || t.type === "dir" ? m : h;
2644
2761
  }
@@ -2651,22 +2768,22 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2651
2768
  let n = new DataView(C.buffer);
2652
2769
  for (let e = 0; e < 64; e++) n.setUint8(t + e, 0);
2653
2770
  if (e <= 2) return n.setUint8(t + 16, p), i;
2654
- let r = A.get(e);
2771
+ let r = H.get(e);
2655
2772
  if (!r) return a;
2656
2773
  let o = r.type === "preopen" || r.type === "dir";
2657
2774
  return n.setUint8(t + 16, o ? m : h), n.setBigUint64(t + 24, 1n, !0), n.setBigUint64(t + 32, BigInt(r.bytes ? r.bytes.length : 0), !0), i;
2658
2775
  },
2659
2776
  path_open: (e, t, r, s, d, f, p, m, h) => {
2660
- if (!C || !O) return a;
2661
- let y = N(e, n.decode(new Uint8Array(C.buffer, r, s)));
2777
+ if (!C || !B) return a;
2778
+ let y = U(e, n.decode(new Uint8Array(C.buffer, r, s)));
2662
2779
  if (!y) return a;
2663
- let w = O.stat(y), T = w !== null;
2780
+ let w = B.stat(y), T = w !== null;
2664
2781
  if (d & v && d & g && T) return o;
2665
2782
  if (d & _) {
2666
2783
  if (!T) return l;
2667
2784
  if (!w.isDirectory) return u;
2668
- let e = k++;
2669
- return A.set(e, {
2785
+ let e = V++;
2786
+ return H.set(e, {
2670
2787
  type: "dir",
2671
2788
  path: y
2672
2789
  }), new DataView(C.buffer).setUint32(h, e, !0), i;
@@ -2675,55 +2792,68 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2675
2792
  if (!T && !(d & g)) return l;
2676
2793
  let E = new Uint8Array(), D = !1;
2677
2794
  if (T && !(d & x)) {
2678
- let e = O.getFileByPath(y);
2795
+ let e = B.getFileByPath(y);
2679
2796
  e != null && (E = typeof e == "string" ? b.encode(e) : new Uint8Array(this._contentToBytes(e)));
2680
2797
  } else D = !0;
2681
- let j = k++;
2682
- return A.set(j, {
2798
+ let O = V++;
2799
+ return H.set(O, {
2683
2800
  type: "file",
2684
2801
  path: y,
2685
2802
  bytes: E,
2686
2803
  pos: m & S ? E.length : 0,
2687
2804
  append: !!(m & S),
2688
2805
  dirty: D
2689
- }), new DataView(C.buffer).setUint32(h, j, !0), i;
2806
+ }), new DataView(C.buffer).setUint32(h, O, !0), i;
2690
2807
  },
2691
2808
  path_filestat_get: (e, t, r, o, s) => {
2692
- if (!C || !O) return a;
2693
- let c = N(e, n.decode(new Uint8Array(C.buffer, r, o)));
2809
+ if (!C || !B) return a;
2810
+ let c = U(e, n.decode(new Uint8Array(C.buffer, r, o)));
2694
2811
  if (!c) return a;
2695
- let u = O.stat(c);
2812
+ let u = B.stat(c);
2696
2813
  if (!u) return l;
2697
2814
  let d = new DataView(C.buffer);
2698
2815
  for (let e = 0; e < 64; e++) d.setUint8(s + e, 0);
2699
- return d.setUint8(s + 16, u.isDirectory ? m : h), d.setBigUint64(s + 24, 1n, !0), d.setBigUint64(s + 32, BigInt(O.getSize(c) || 0), !0), i;
2816
+ return d.setUint8(s + 16, u.isDirectory ? m : h), d.setBigUint64(s + 24, 1n, !0), d.setBigUint64(s + 32, BigInt(B.getSize(c) || 0), !0), i;
2700
2817
  },
2701
2818
  path_create_directory: (e, t, r) => {
2702
- if (!C || !O) return a;
2703
- let o = N(e, n.decode(new Uint8Array(C.buffer, t, r)));
2819
+ if (!C || !B) return a;
2820
+ let o = U(e, n.decode(new Uint8Array(C.buffer, t, r)));
2704
2821
  if (!o) return a;
2705
2822
  try {
2706
- return O.setFileByPath(o, {}, !0), i;
2823
+ return B.setFileByPath(o, {}, !0), i;
2707
2824
  } catch {
2708
2825
  return s;
2709
2826
  }
2710
2827
  },
2711
2828
  path_unlink_file: (e, t, r) => {
2712
- if (!C || !O) return a;
2713
- let o = N(e, n.decode(new Uint8Array(C.buffer, t, r)));
2714
- if (!o || !O.exists(o)) return l;
2829
+ if (!C || !B) return a;
2830
+ let o = U(e, n.decode(new Uint8Array(C.buffer, t, r)));
2831
+ if (!o || !B.exists(o)) return l;
2715
2832
  try {
2716
- return O.deleteFileByPath(o), i;
2833
+ return B.deleteFileByPath(o), i;
2717
2834
  } catch {
2718
2835
  return s;
2719
2836
  }
2720
2837
  },
2721
2838
  path_remove_directory: (e, t, r) => {
2722
- if (!C || !O) return a;
2723
- let o = N(e, n.decode(new Uint8Array(C.buffer, t, r)));
2724
- if (!o || !O.exists(o)) return l;
2839
+ if (!C || !B) return a;
2840
+ let o = U(e, n.decode(new Uint8Array(C.buffer, t, r)));
2841
+ if (!o || !B.exists(o)) return l;
2725
2842
  try {
2726
- return O.deleteFileByPath(o), i;
2843
+ return B.deleteFileByPath(o), i;
2844
+ } catch {
2845
+ return s;
2846
+ }
2847
+ },
2848
+ path_rename: (e, t, r, o, c, u) => {
2849
+ if (!C || !B) return a;
2850
+ let d = n.decode(new Uint8Array(C.buffer, t, r)), f = n.decode(new Uint8Array(C.buffer, c, u)), p = U(e, d), m = U(o, f);
2851
+ if (!p || !m) return a;
2852
+ if (!B.exists(p)) return l;
2853
+ for (let e of H.values()) e.path === p && (W(e), e.path = m);
2854
+ try {
2855
+ let e = B.getFileByPath(p);
2856
+ return B.setFileByPath(m, e, !0), B.deleteFileByPath(p), i;
2727
2857
  } catch {
2728
2858
  return s;
2729
2859
  }
@@ -2752,16 +2882,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2752
2882
  environ_sizes_get: (e, t) => {
2753
2883
  if (!C) return s;
2754
2884
  let n = new DataView(C.buffer);
2755
- n.setUint32(e, F.length, !0);
2756
- let r = F.reduce((e, t) => e + b.encode(t).length + 1, 0);
2885
+ n.setUint32(e, K.length, !0);
2886
+ let r = K.reduce((e, t) => e + b.encode(t).length + 1, 0);
2757
2887
  return n.setUint32(t, r, !0), i;
2758
2888
  },
2759
2889
  environ_get: (e, t) => {
2760
2890
  if (!C) return s;
2761
2891
  let n = new DataView(C.buffer), r = t;
2762
- for (let t = 0; t < F.length; t++) {
2892
+ for (let t = 0; t < K.length; t++) {
2763
2893
  n.setUint32(e + t * 4, r, !0);
2764
- let i = b.encode(F[t] + "\0");
2894
+ let i = b.encode(K[t] + "\0");
2765
2895
  new Uint8Array(C.buffer).set(i, r), r += i.length;
2766
2896
  }
2767
2897
  return i;
@@ -2782,7 +2912,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2782
2912
  }
2783
2913
  }, { get(e, t) {
2784
2914
  return t in e ? e[t] : () => 0;
2785
- } }), L = (e) => {
2915
+ } }), J = (e) => {
2786
2916
  if (!C || !e) return "";
2787
2917
  try {
2788
2918
  let t = new DataView(C.buffer).getUint32(e - 4, !0), n = new Uint16Array(C.buffer, e, t >>> 1);
@@ -2790,33 +2920,33 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2790
2920
  } catch {
2791
2921
  return "";
2792
2922
  }
2793
- }, R = {
2794
- wasi_snapshot_preview1: I,
2795
- wasi_unstable: I,
2923
+ }, Y = {
2924
+ wasi_snapshot_preview1: q,
2925
+ wasi_unstable: q,
2796
2926
  env: new Proxy({
2797
2927
  print: (e, t) => {
2798
- C && w(1, n.decode(new Uint8Array(C.buffer, e, t)));
2928
+ C && P(1, n.decode(new Uint8Array(C.buffer, e, t)));
2799
2929
  },
2800
2930
  eprint: (e, t) => {
2801
- C && w(2, n.decode(new Uint8Array(C.buffer, e, t)));
2931
+ C && P(2, n.decode(new Uint8Array(C.buffer, e, t)));
2802
2932
  },
2803
2933
  log: (e) => {
2804
- w(1, L(e) + "\n");
2934
+ P(1, J(e) + "\n");
2805
2935
  },
2806
2936
  logi: (e) => {
2807
- w(1, String(e) + "\n");
2937
+ P(1, String(e) + "\n");
2808
2938
  },
2809
2939
  logf: (e) => {
2810
- w(1, String(e) + "\n");
2940
+ P(1, String(e) + "\n");
2811
2941
  },
2812
2942
  trace: (e, t, ...n) => {
2813
2943
  let r = t > 0 ? " " + n.slice(0, t).join(", ") : "";
2814
- w(1, `trace: ${L(e)}${r}\n`);
2944
+ P(1, `trace: ${J(e)}${r}\n`);
2815
2945
  },
2816
2946
  seed: () => Date.now() * Math.random(),
2817
2947
  abort: (e, t, n, r) => {
2818
- let i = L(e), a = L(t);
2819
- throw (i || a) && w(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
2948
+ let i = J(e), a = J(t);
2949
+ throw (i || a) && P(2, `abort: ${i || "aborted"} at ${a || this.script}:${n || 0}:${r || 0}\n`), this.exitCode = 134, {
2820
2950
  _wasmExit: !0,
2821
2951
  code: 134
2822
2952
  };
@@ -2832,44 +2962,66 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2832
2962
  initial: 1,
2833
2963
  maximum: 256
2834
2964
  });
2835
- C = t, R[e.module] || (R[e.module] = {}), R[e.module][e.name] = t;
2965
+ C = t, Y[e.module] || (Y[e.module] = {}), Y[e.module][e.name] = t;
2966
+ }
2967
+ if (w = await WebAssembly.instantiate(t, Y), w.exports.memory && (C = w.exports.memory), T = !!(w.exports.asyncify_start_unwind && w.exports.asyncify_stop_unwind), T && C) {
2968
+ try {
2969
+ E = C.grow(1) * 65536;
2970
+ } catch {
2971
+ E = 16;
2972
+ }
2973
+ let e = E + 8, t = E + 65536 - 8;
2974
+ new Int32Array(C.buffer, E, 2).set([e, t]);
2836
2975
  }
2837
- let n = await WebAssembly.instantiate(t, R);
2838
- n.exports.memory && (C = n.exports.memory);
2839
- let r = n.exports._start || n.exports.__wasi_command || n.exports.main || n.exports.run;
2840
- if (r) try {
2841
- await r();
2976
+ if (N) {
2977
+ this._enterAltScreen();
2978
+ 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;
2979
+ if (typeof w.exports.set_terminal_size == "function") try {
2980
+ w.exports.set_terminal_size(e, t);
2981
+ } catch {}
2982
+ k = () => {
2983
+ let e = this.stdout && this.stdout.columns || 80, t = this.stdout && this.stdout.rows || 24;
2984
+ if (typeof w?.exports?.set_terminal_size == "function") try {
2985
+ w.exports.set_terminal_size(e, t);
2986
+ } catch {}
2987
+ }, this.stdout && typeof this.stdout.on == "function" && this.stdout.on("resize", k), this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("resize", k);
2988
+ }
2989
+ let n = w.exports._start || w.exports.__wasi_command || w.exports.main || w.exports.run;
2990
+ if (n) try {
2991
+ let e = n();
2992
+ for (e && typeof e.then == "function" && (e = await e); T && typeof w.exports.asyncify_get_state == "function" && w.exports.asyncify_get_state() === 1;) w.exports.asyncify_stop_unwind(), D &&= (await D, null), w.exports.asyncify_start_rewind(E), e = n(), e && typeof e.then == "function" && (e = await e);
2842
2993
  } catch (e) {
2843
2994
  (!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
2844
2995
  }
2845
2996
  else {
2846
- let e = Object.entries(n.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
2997
+ let e = Object.entries(w.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
2847
2998
  this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
2848
2999
  }
2849
3000
  } catch (e) {
2850
3001
  (!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
2851
3002
  } finally {
2852
- for (let e of A.values()) P(e);
3003
+ N && this._exitAltScreen(), N && A && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", A), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", A)), k && (this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", k), this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", k)), this._externalKeyHandler = null;
3004
+ for (let e of H.values()) W(e);
2853
3005
  }
2854
- T();
2855
- let z = this.arguments || [];
3006
+ F();
3007
+ let X = this.arguments || [];
2856
3008
  if (!(this.result && this.result.getStdOutput && this.result.getStdOutput().length > 0) && (this.exitCode === 0 || this.exitCode === void 0)) {
2857
3009
  let t = (this.script || "wasm").split("/").pop(), n = Object.assign({
2858
3010
  name: t,
2859
3011
  version: "wasi",
2860
3012
  description: `WebAssembly WASI binary (${this.script})`
2861
3013
  }, this._pkgMeta || {});
2862
- if (z.includes("--help") || z.includes("-h")) {
3014
+ if (X.includes("--help") || X.includes("-h")) {
2863
3015
  let r = j(e);
2864
3016
  for (let e of M(t, n, r)) this.stdOut = e;
2865
- } else (z.includes("--version") || z.includes("-V") || z.includes("-v")) && (this.stdOut = `${t} (${n.name} ${n.version} wasm)`);
3017
+ } else (X.includes("--version") || X.includes("-V") || X.includes("-v")) && (this.stdOut = `${t} (${n.name} ${n.version} wasm)`);
2866
3018
  }
2867
3019
  }
2868
3020
  }, w = /* @__PURE__ */ new Map();
2869
3021
  function T(e, t) {
2870
3022
  if (!e || !e.exists(t)) return null;
2871
3023
  if (e.isRealFilesystem) try {
2872
- let n = ne();
3024
+ let n = te();
2873
3025
  return new Uint8Array(n.readFileSync(e.absolutePath(t)));
2874
3026
  } catch {}
2875
3027
  let n = e.getFileByPath(t);
@@ -2898,7 +3050,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
2898
3050
  o.set(a);
2899
3051
  let s = new r(o.buffer, i);
2900
3052
  if (e.isRealFilesystem) try {
2901
- let n = ne(), r = re(), i = e.absolutePath(t);
3053
+ let n = te(), r = ne(), i = e.absolutePath(t);
2902
3054
  n.mkdirSync(r.dirname(i), { recursive: !0 }), n.writeFileSync(i, y.from(a.buffer, a.byteOffset, a.byteLength));
2903
3055
  return;
2904
3056
  } catch {
@@ -3271,8 +3423,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
3271
3423
  return a;
3272
3424
  }
3273
3425
  C.readBytesFromFs = T, C.writeBytesToFs = O, C.loadModule = k, C.extractHelpFromText = A, C.inspectWasmBytes = j, C.formatWasmHelp = M, C.createGenericWasmCommand = N, C.createCommand = N, t.exports = C;
3274
- })), Z = /* @__PURE__ */ t(((e, t) => {
3275
- var n = J(), { 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 {
3426
+ })), re = /* @__PURE__ */ t(((e, t) => {
3427
+ var n = Y(), { 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 {
3276
3428
  get requiresFilesystem() {
3277
3429
  return !0;
3278
3430
  }
@@ -3722,14 +3874,15 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
3722
3874
  name: "nano",
3723
3875
  bin: "nano",
3724
3876
  aliases: ["nano-wasm"],
3725
- version: "8.0.0",
3877
+ version: "8.0.1",
3726
3878
  description: "GNU nano 8.0 text editor compiled to WebAssembly (wasm32-wasip1) with ncurses",
3727
3879
  details: "GNU nano is a small, user-friendly command-line text editor compiled to WebAssembly with wide-character ncurses 6.5, built-in terminfo fallbacks (xterm-256color, vt100, etc.), dynamic terminal dimensions (TIOCGWINSZ / LINES & COLUMNS), and zero custom imports (standard wasi_snapshot_preview1).",
3728
3880
  homepage: "https://github.com/eliotstocker/nano-wasm",
3729
3881
  cdnUrl: "https://cdn.jsdelivr.net/gh/eliotstocker/nano-wasm@main/dist/nano.wasm",
3730
3882
  wasmUrl: "https://cdn.jsdelivr.net/gh/eliotstocker/nano-wasm@main/dist/nano.wasm",
3731
3883
  type: "custom-wasm",
3732
- size: "574 KB"
3884
+ interactive: !0,
3885
+ size: "680 KB"
3733
3886
  }
3734
3887
  }, r = {
3735
3888
  sqlite: "sqlite3",
@@ -3796,7 +3949,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
3796
3949
  }
3797
3950
  return i;
3798
3951
  }
3799
- var { readBytesFromFs: a, writeBytesToFs: o, loadModule: s, extractHelpFromText: c, inspectWasmBytes: l, formatWasmHelp: u } = X();
3952
+ var { readBytesFromFs: a, writeBytesToFs: o, loadModule: s, extractHelpFromText: c, inspectWasmBytes: l, formatWasmHelp: u } = Z();
3800
3953
  t.exports = {
3801
3954
  formatTable: n,
3802
3955
  formatPipeList: r,
@@ -3810,7 +3963,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
3810
3963
  };
3811
3964
  })), oe = /* @__PURE__ */ t(((e, t) => {
3812
3965
  T();
3813
- var n = Z(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = ae(), o = {
3966
+ var n = re(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = ae(), o = {
3814
3967
  smol: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
3815
3968
  smollm: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
3816
3969
  smollm2: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
@@ -4705,7 +4858,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
4705
4858
  }), 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;
4706
4859
  })), se = /* @__PURE__ */ t(((e, t) => {
4707
4860
  b();
4708
- var r = E(), i = X(), a = Z(), { DEFAULT_REGISTRY: o, resolvePackageName: s } = ie(), c = oe(), { writeBytesToFs: l, createGenericWasmCommand: u } = i, { createReplWasmCommand: d } = a, f = "/var/lib/wbt/installed.json", p = "/var/cache/wbt";
4861
+ var r = E(), i = Z(), a = re(), { DEFAULT_REGISTRY: o, resolvePackageName: s } = ie(), c = oe(), { writeBytesToFs: l, createGenericWasmCommand: u } = i, { createReplWasmCommand: d } = a, f = "/var/lib/wbt/installed.json", p = "/var/cache/wbt";
4709
4862
  function m(e, t, n = {}) {
4710
4863
  class r extends i {
4711
4864
  static get name() {
@@ -4717,6 +4870,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
4717
4870
  get requiresFilesystem() {
4718
4871
  return !0;
4719
4872
  }
4873
+ get interactive() {
4874
+ return (this.arguments || []).some((e) => e === "--help" || e === "-h" || e === "--version" || e === "-V" || e === "-v") ? !1 : this._isInteractive === void 0 ? !!(n.interactive || e === "nano") : !!this._isInteractive;
4875
+ }
4876
+ get captureInput() {
4877
+ return this.interactive;
4878
+ }
4720
4879
  constructor(e, r) {
4721
4880
  super(t, e, r), this.script = t, this.arguments = e || [], this.context = r || null, r && r.fs && !this.fs && (this.fs = r.fs), this._pkgMeta = n;
4722
4881
  }
@@ -4733,6 +4892,20 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
4733
4892
  get requiresFilesystem() {
4734
4893
  return !0;
4735
4894
  }
4895
+ get interactive() {
4896
+ if (this._activeSubCommand && this._activeSubCommand.interactive !== void 0) return !!this._activeSubCommand.interactive;
4897
+ if (this.arguments && this.arguments[0] === "run" && this.arguments[1]) {
4898
+ let e = this.arguments[1].toLowerCase(), t = this._getRegistry()[e];
4899
+ if (t && t.interactive) return !this.arguments.slice(2).some((e) => e === "--help" || e === "-h" || e === "--version" || e === "-V" || e === "-v");
4900
+ }
4901
+ return !1;
4902
+ }
4903
+ get captureInput() {
4904
+ return this._activeSubCommand && this._activeSubCommand.captureInput !== void 0 ? !!this._activeSubCommand.captureInput : this.interactive;
4905
+ }
4906
+ onInput(e) {
4907
+ this._activeSubCommand && typeof this._activeSubCommand.onInput == "function" && this._activeSubCommand.onInput(e);
4908
+ }
4736
4909
  static get _config() {
4737
4910
  return this.__wbtConfig || {};
4738
4911
  }
@@ -5316,11 +5489,29 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
5316
5489
  this.stdErr = `E: Unable to locate package ${t}`, this.exitCode = 100;
5317
5490
  return;
5318
5491
  }
5492
+ if ((i.type === "custom-wasm" || i.type === "wasm") && !i.wasmPath) try {
5493
+ let e = await this._pullPackageWasm(i, !0);
5494
+ e && (i = Object.assign({}, i, { wasmPath: e }));
5495
+ } catch (e) {
5496
+ this.stdErr = `E: Failed to fetch ${i.name}: ${e.message || e}`, this.exitCode = 1;
5497
+ return;
5498
+ }
5319
5499
  let a = this._buildCommandsForPackage(i), o = (a.find((e) => e.bin === t.toLowerCase()) || a[0]).Cmd, c = new o(e, this.context);
5320
- c.requiresFilesystem && (c.fs = this.context.fs.sandbox()), this.stdin !== void 0 && (c.stdin = this.stdin);
5321
- let l = await c.runCommand();
5322
- for (let e of l.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
5323
- this.exitCode = l.getExitCode();
5500
+ c.requiresFilesystem && (c.fs = this.context.fs.sandbox()), this._activeSubCommand = c, c.stdinStream = this.stdinStream, c.stdin = this.stdin && !this.stdin.isTTY ? this.stdin : this.stdinStream;
5501
+ let l = (e) => {
5502
+ this.stdout && typeof this.stdout.write == "function" && this.stdout.write(e);
5503
+ }, u = (e) => {
5504
+ this.stderr && typeof this.stderr.write == "function" && this.stderr.write(e);
5505
+ };
5506
+ c.stdout && typeof c.stdout.on == "function" && c.stdout.on("data", l), c.stderr && typeof c.stderr.on == "function" && c.stderr.on("data", u);
5507
+ let d;
5508
+ try {
5509
+ d = await c.runCommand();
5510
+ } finally {
5511
+ this._activeSubCommand = null, c.stdout && typeof c.stdout.off == "function" && c.stdout.off("data", l), c.stderr && typeof c.stderr.off == "function" && c.stderr.off("data", u);
5512
+ }
5513
+ if (!c.interactive && d) for (let e of d.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
5514
+ this.exitCode = d ? d.getExitCode() : 0;
5324
5515
  }
5325
5516
  _printHelp() {
5326
5517
  [