script.jsvar d=!1;scrapbox.addListener("lines:changed",()=>d=!1);scrapbox.addListener("layout:changed",()=>d=!1);var l=(e,n)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError(`"${n}" must be HTMLTextAreaElement but actual is "${e}"`)};var i=()=>{let e=document.getElementById("text-input");if(!!e)return l(e,"textarea#text-input"),e};var a=(e,n)=>{let{noModifiedKeys:s=!1,...o}=n??{},r={bubbles:!0,cancelable:!0,keyCode:x[e],...s?{}:{...o}},t=i();if(!t)throw Error("#text-input must exist.");t.dispatchEvent(new KeyboardEvent("keydown",r)),t.dispatchEvent(new KeyboardEvent("keyup",r))},x={Backspace:8,Tab:9,Enter:13,Delete:46,Escape:27," ":32,PageUp:33,PageDown:34,End:35,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40,a:65,A:65,b:66,B:66,c:67,C:67,d:68,D:68,e:69,E:69,f:70,F:70,g:71,G:71,h:72,H:72,i:73,I:73,j:74,J:74,k:75,K:75,l:76,L:76,m:77,M:77,n:78,N:78,o:79,O:79,p:80,P:80,q:81,Q:81,r:82,R:82,s:83,S:83,t:84,T:84,u:85,U:85,v:86,V:86,w:87,W:87,x:88,X:88,y:89,Y:89,z:90,Z:90,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,F1:113,F2:114,F3:115,F4:116,F5:117,F6:118,F7:119,F8:120,F9:121,F10:122,F11:123,F12:124,":":186,"*":186,";":187,"+":187,"-":189,"=":189,".":190,">":190,"/":191,"?":191,"@":192,"`":192,"[":219,"{":219,"\\":220,"|":220,"]":221,"}":221,"^":222,"~":222,_:226};var c=e=>new Promise(n=>setTimeout(()=>n(),e));var u=()=>{let e=i();if(!e)throw Error("#text-input is not found.");let n=Object.keys(e).find(t=>t.startsWith("__reactFiber"));if(!n)throw Error('#text-input must has the property whose name starts with "__reactFiber"');let s=e[n].return.return.stateNode._stores,o=s.find(t=>t.constructor.name==="Cursor");if(!o)throw Error('#text-input must has a "Cursor" store.');let r=s.find(t=>t.constructor.name==="Selection");if(!r)throw Error('#text-input must has a "Selection" store.');return{cursor:o,selection:r}};var p=e=>{if(!e.isTrusted||e.data.length===0||!(e.target instanceof HTMLTextAreaElement)||e.target.id!=="text-input")return;let{cursor:n,selection:s}=u();if(!!s.hasSingleLineSelection())switch([...e.data].pop()){case"「":{let o=document.getElementsByClassName("button link-button")?.[0];if(!(o instanceof HTMLElement))return;o.click();let r=e.target;(async()=>{await c(100),r.blur(),await new Promise(t=>{document.addEventListener("compositionend",t,{capture:!0,once:!0})}),a("Backspace"),r.focus(),n.focus()})();break}default:break}},ht=()=>(document.addEventListener("compositionupdate",p,{capture:!0}),()=>{document.removeEventListener("compositionupdate",p,{capture:!0})});export{ht as setup};