brsh 3.2.0 → 3.3.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.
@@ -1087,7 +1087,7 @@ var E = e?.default ?? e, D = class {
1087
1087
  this.write("\x1B[2J\x1B[3J\x1B[H");
1088
1088
  }
1089
1089
  reset() {
1090
- this._flushTypeQueue(), this.parser.reset(), this.renderer.flushRender();
1090
+ this._flushTypeQueue(), this.parser.reset(), this.renderer.flushRender(), this._mobileInputBuffer = "", this._mobileInputElement && (this._mobileInputElement.value = "");
1091
1091
  }
1092
1092
  onData(e) {
1093
1093
  return typeof e == "function" ? (this._dataListeners.push(e), () => {
@@ -1202,7 +1202,7 @@ var E = e?.default ?? e, D = class {
1202
1202
  if (!e) return;
1203
1203
  this.screen.viewportOffset > 0 && (this.screen.viewportOffset = 0, this.screen._markAllDirty(), this.renderer.flushRender()), (this._typeQueue || this._typeTimer !== null) && (this._flushTypeQueue(), this.renderer.flushRender(), this._autoScroll());
1204
1204
  let t = e === "\r" || e === "\n" || e === "\r\n";
1205
- this._suppressAnimationUntil = t ? 0 : Date.now() + 80, this._isHandlingInput = !t;
1205
+ t && this._mobileInputElement && (this._mobileInputElement.value = "", this._mobileInputBuffer = ""), this._suppressAnimationUntil = t ? 0 : Date.now() + 80, this._isHandlingInput = !t;
1206
1206
  try {
1207
1207
  for (let t of this._dataListeners) t(e);
1208
1208
  } finally {
@@ -1393,19 +1393,64 @@ var E = e?.default ?? e, D = class {
1393
1393
  _mobileInput() {
1394
1394
  if (typeof document > "u" || !this._el) return;
1395
1395
  let e = document.createElement("input");
1396
- e.type = "text", e.style.position = "fixed", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e.style.opacity = "0", e.style.pointerEvents = "none", e.style.zIndex = "-1", e.setAttribute("aria-hidden", "true"), e.setAttribute("tabindex", "-1"), this._el.appendChild(e), this._mobileInputElement = e, this._mobileInputBuffer = "", this._onMobileInputClick = (t) => {
1397
- t && t.target && t.target.tagName === "A" || typeof e.focus == "function" && e.focus({ preventScroll: !0 });
1398
- }, this._el.addEventListener("click", this._onMobileInputClick), e.addEventListener("keypress", (t) => {
1399
- t.key === "Enter" && (e.value = "", this._mobileInputBuffer = e.value);
1400
- }), e.addEventListener("keyup", (t) => {
1401
- if (t.key === "Unidentified") {
1402
- if (e.value.length < this._mobileInputBuffer.length) this.sendKey("Backspace");
1403
- else if (e.value.length > this._mobileInputBuffer.length) {
1404
- let t = e.value[e.value.length - 1];
1405
- this.sendKey(t);
1396
+ e.type = "text", e.style.position = "fixed", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e.style.opacity = "0", e.style.pointerEvents = "none", e.style.zIndex = "-1", e.setAttribute("aria-hidden", "true"), e.setAttribute("tabindex", "-1"), e.setAttribute("autocapitalize", "none"), e.setAttribute("autocorrect", "off"), e.setAttribute("autocomplete", "off"), e.setAttribute("spellcheck", "false"), e.setAttribute("enterkeyhint", "go"), this._el.appendChild(e), this._mobileInputElement = e, this._mobileInputBuffer = "", this._onMobileInputClick = (t) => {
1397
+ if (!(t && t.target && t.target.tagName === "A") && typeof e.focus == "function" && (e.focus({ preventScroll: !0 }), typeof e.setSelectionRange == "function")) {
1398
+ let t = (e.value || "").length;
1399
+ e.setSelectionRange(t, t);
1400
+ }
1401
+ }, this._el.addEventListener("click", this._onMobileInputClick);
1402
+ let t = () => {
1403
+ let t = this._mobileInputBuffer || "", n = e.value || "";
1404
+ if (t === n) return;
1405
+ let r = 0;
1406
+ for (; r < t.length && r < n.length && t[r] === n[r];) r++;
1407
+ let i = 0;
1408
+ for (; i < t.length - r && i < n.length - r && t[t.length - 1 - i] === n[n.length - 1 - i];) i++;
1409
+ let a = t.length - r - i, o = n.slice(r, n.length - i);
1410
+ if (a > 0) for (let e = 0; e < a; e++) this.sendKey("Backspace");
1411
+ if (o) {
1412
+ let e = o.replace(/\r?\n/g, "\r");
1413
+ this._emitInput(e);
1414
+ }
1415
+ this._mobileInputBuffer = n;
1416
+ };
1417
+ e.addEventListener("input", (n) => {
1418
+ if (!n) {
1419
+ t();
1420
+ return;
1421
+ }
1422
+ let r = n.inputType;
1423
+ if (r === "insertLineBreak" || r === "insertParagraph") {
1424
+ this.sendKey("Enter"), e.value = "", this._mobileInputBuffer = "";
1425
+ return;
1426
+ }
1427
+ if (r === "deleteContentBackward") {
1428
+ this.sendKey("Backspace"), this._mobileInputBuffer = e.value || "";
1429
+ return;
1430
+ }
1431
+ if (r === "deleteContentForward") {
1432
+ this.sendKey("Delete"), this._mobileInputBuffer = e.value || "";
1433
+ return;
1434
+ }
1435
+ if (r === "deleteWordBackward") {
1436
+ this.sendKey("Backspace", { alt: !0 }), this._mobileInputBuffer = e.value || "";
1437
+ return;
1438
+ }
1439
+ if (r === "insertText" && typeof n.data == "string" && n.data.length > 0) {
1440
+ let t = (this._mobileInputBuffer || "").length + n.data.length;
1441
+ if (!e.value || e.value.length === t) {
1442
+ let t = n.data.replace(/\r?\n/g, "\r");
1443
+ this._emitInput(t), this._mobileInputBuffer = e.value || "";
1444
+ return;
1406
1445
  }
1407
- this._mobileInputBuffer = e.value;
1408
1446
  }
1447
+ t();
1448
+ }), e.addEventListener("keydown", (t) => {
1449
+ t && (t.key === "Enter" || t.keyCode === 13) && (t.defaultPrevented || (this.sendKey("Enter"), e.value = "", this._mobileInputBuffer = "", t.preventDefault && t.preventDefault()));
1450
+ }), e.addEventListener("keyup", (e) => {
1451
+ e && e.key === "Unidentified" && t();
1452
+ }), e.addEventListener("compositionend", () => {
1453
+ t();
1409
1454
  });
1410
1455
  }
1411
1456
  _autoScroll() {