"use strict";const CjkInput=(()=>{let e=null,c=null,s=null,r=null,p=!1,u=!1;const n={},l="\u200B",d={ArrowUp:"\x1B[A",ArrowDown:"\x1B[B",ArrowLeft:"\x1B[D",ArrowRight:"\x1B[C",Home:"\x1B[H",End:"\x1B[F",Tab:"	"},k={c:"",d:"",l:"\f",z:"",a:"",e:""};function v(i){return i.replace(/\u200B/g,"")}function f(){e.value=l,e.setSelectionRange(1,1)}function o(){return!!(e&&typeof MobileDetection<"u"&&MobileDetection.isTouchDevice()&&e.classList.contains("cjk-input-visible"))}function y(){o()?e.value="":f()}function a(){return!v(e.value)}function m(){const i=v(e.value);i&&r(i),f()}return{init({send:i}){return p&&this.destroy(),r=i,u=!1,e=document.getElementById("cjkInput"),e?(c=document.getElementById("terminalContainer"),y(),n.mousedown=t=>{t.stopPropagation()},n.focus=()=>{if(window.cjkActive=!0,o()&&e.value===l){e.value="";return}!e.value&&!o()&&f()},n.blur=()=>{window.cjkActive=!1},e.addEventListener("mousedown",n.mousedown),e.addEventListener("focus",n.focus),e.addEventListener("blur",n.blur),n.xtermFocusRedirect=()=>{o()&&e.focus()},c&&(s=c.querySelector(".xterm-helper-textarea"),s&&s.addEventListener("focus",n.xtermFocusRedirect,{capture:!0})),n.compositionstart=()=>{if(u=!0,o()){e.value===l&&(e.value="");return}e.value===l&&(e.value="")},n.compositionend=()=>{u=!1,!o()&&setTimeout(m,0)},e.addEventListener("compositionstart",n.compositionstart),e.addEventListener("compositionend",n.compositionend),n.keydown=t=>{if(t.key==="Enter"){t.preventDefault(),u=!1;const x=v(e.value);r(x?x+"\r":"\r"),y();return}if(t.key==="Escape"){t.preventDefault(),u=!1,y();return}if(t.ctrlKey&&k[t.key]){t.preventDefault(),r(k[t.key]);return}if(!u){if(o()){if(t.key==="Backspace"&&a()){t.preventDefault(),r("\x7F");return}d[t.key]&&a()&&(t.preventDefault(),r(d[t.key]));return}if(t.key==="Backspace"&&a()){t.preventDefault(),r("\x7F"),f();return}if(d[t.key]&&a()){t.preventDefault(),r(d[t.key]);return}if(t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&a()){t.preventDefault(),r(t.key);return}}},e.addEventListener("keydown",n.keydown),n.input=t=>{if(o()){e.value.includes(l)&&(e.value=v(e.value));return}if(t.inputType==="deleteContentBackward"||t.inputType==="deleteWordBackward"){if(a()){r("\x7F"),f();return}e.value.startsWith(l)||(e.value=l+e.value,e.setSelectionRange(1,1));return}if(u){if(t.inputType==="insertText"){m();return}return}m()},e.addEventListener("input",n.input),p=!0,this):this},destroy(){if(e)for(const[i,t]of Object.entries(n))t&&e.removeEventListener(i,t);s&&n.xtermFocusRedirect&&s.removeEventListener("focus",n.xtermFocusRedirect,{capture:!0}),window.cjkActive=!1,u=!1,c=null,s=null;for(const i of Object.keys(n))delete n[i];p=!1},get element(){return e}}})();
