@crunchloop/ghostty-web 0.4.3 → 0.4.4

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.
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./terminal-core-0895062a.cjs"),q={KeyA:a.Key.A,KeyB:a.Key.B,KeyC:a.Key.C,KeyD:a.Key.D,KeyE:a.Key.E,KeyF:a.Key.F,KeyG:a.Key.G,KeyH:a.Key.H,KeyI:a.Key.I,KeyJ:a.Key.J,KeyK:a.Key.K,KeyL:a.Key.L,KeyM:a.Key.M,KeyN:a.Key.N,KeyO:a.Key.O,KeyP:a.Key.P,KeyQ:a.Key.Q,KeyR:a.Key.R,KeyS:a.Key.S,KeyT:a.Key.T,KeyU:a.Key.U,KeyV:a.Key.V,KeyW:a.Key.W,KeyX:a.Key.X,KeyY:a.Key.Y,KeyZ:a.Key.Z,Digit1:a.Key.ONE,Digit2:a.Key.TWO,Digit3:a.Key.THREE,Digit4:a.Key.FOUR,Digit5:a.Key.FIVE,Digit6:a.Key.SIX,Digit7:a.Key.SEVEN,Digit8:a.Key.EIGHT,Digit9:a.Key.NINE,Digit0:a.Key.ZERO,Enter:a.Key.ENTER,Escape:a.Key.ESCAPE,Backspace:a.Key.BACKSPACE,Tab:a.Key.TAB,Space:a.Key.SPACE,Minus:a.Key.MINUS,Equal:a.Key.EQUAL,BracketLeft:a.Key.BRACKET_LEFT,BracketRight:a.Key.BRACKET_RIGHT,Backslash:a.Key.BACKSLASH,Semicolon:a.Key.SEMICOLON,Quote:a.Key.QUOTE,Backquote:a.Key.GRAVE,Comma:a.Key.COMMA,Period:a.Key.PERIOD,Slash:a.Key.SLASH,CapsLock:a.Key.CAPS_LOCK,F1:a.Key.F1,F2:a.Key.F2,F3:a.Key.F3,F4:a.Key.F4,F5:a.Key.F5,F6:a.Key.F6,F7:a.Key.F7,F8:a.Key.F8,F9:a.Key.F9,F10:a.Key.F10,F11:a.Key.F11,F12:a.Key.F12,PrintScreen:a.Key.PRINT_SCREEN,ScrollLock:a.Key.SCROLL_LOCK,Pause:a.Key.PAUSE,Insert:a.Key.INSERT,Home:a.Key.HOME,PageUp:a.Key.PAGE_UP,Delete:a.Key.DELETE,End:a.Key.END,PageDown:a.Key.PAGE_DOWN,ArrowRight:a.Key.RIGHT,ArrowLeft:a.Key.LEFT,ArrowDown:a.Key.DOWN,ArrowUp:a.Key.UP,NumLock:a.Key.NUM_LOCK,NumpadDivide:a.Key.KP_DIVIDE,NumpadMultiply:a.Key.KP_MULTIPLY,NumpadSubtract:a.Key.KP_MINUS,NumpadAdd:a.Key.KP_PLUS,NumpadEnter:a.Key.KP_ENTER,Numpad1:a.Key.KP_1,Numpad2:a.Key.KP_2,Numpad3:a.Key.KP_3,Numpad4:a.Key.KP_4,Numpad5:a.Key.KP_5,Numpad6:a.Key.KP_6,Numpad7:a.Key.KP_7,Numpad8:a.Key.KP_8,Numpad9:a.Key.KP_9,Numpad0:a.Key.KP_0,NumpadDecimal:a.Key.KP_PERIOD,IntlBackslash:a.Key.INTL_BACKSLASH,ContextMenu:a.Key.CONTEXT_MENU,F13:a.Key.F13,F14:a.Key.F14,F15:a.Key.F15,F16:a.Key.F16,F17:a.Key.F17,F18:a.Key.F18,F19:a.Key.F19,F20:a.Key.F20,F21:a.Key.F21,F22:a.Key.F22,F23:a.Key.F23,F24:a.Key.F24},B=class x{constructor(t,i,e,s,r,n,o,h,c,l){this.keydownListener=null,this.keypressListener=null,this.pasteListener=null,this.beforeInputListener=null,this.compositionStartListener=null,this.compositionUpdateListener=null,this.compositionEndListener=null,this.mousedownListener=null,this.mouseupListener=null,this.mousemoveListener=null,this.wheelListener=null,this.isComposing=!1,this.compositionJustEnded=!1,this.pendingKeyAfterComposition=null,this.isDisposed=!1,this.mouseButtonsPressed=0,this.lastKeyDownData=null,this.lastKeyDownTime=0,this.lastPasteData=null,this.lastPasteTime=0,this.lastPasteSource=null,this.lastCompositionData=null,this.lastCompositionTime=0,this.lastBeforeInputData=null,this.lastBeforeInputTime=0,this.syncedEncoderOptions=new Map,this.decoder=new TextDecoder,this.encoder=t.createKeyEncoder(),this.encoder.setOption(a.KeyEncoderOption.ALT_ESC_PREFIX,!0),this.container=i,this.inputElement=c,this.onDataCallback=e,this.onBellCallback=s,this.onKeyCallback=r,this.customKeyEventHandler=n,this.getModeCallback=o,this.onCopyCallback=h,this.mouseConfig=l,this.attach()}setCustomKeyEventHandler(t){this.customKeyEventHandler=t}attach(){typeof this.container.hasAttribute=="function"&&typeof this.container.setAttribute=="function"&&(this.container.hasAttribute("tabindex")||this.container.setAttribute("tabindex","0"),this.container.style&&(this.container.style.outline="none")),this.keydownListener=this.handleKeyDown.bind(this),this.container.addEventListener("keydown",this.keydownListener),this.pasteListener=this.handlePaste.bind(this),this.container.addEventListener("paste",this.pasteListener),this.inputElement&&this.inputElement!==this.container&&this.inputElement.addEventListener("paste",this.pasteListener),this.inputElement&&(this.beforeInputListener=this.handleBeforeInput.bind(this),this.inputElement.addEventListener("beforeinput",this.beforeInputListener));const t=this.inputElement||this.container;this.compositionStartListener=this.handleCompositionStart.bind(this),t.addEventListener("compositionstart",this.compositionStartListener),this.compositionUpdateListener=this.handleCompositionUpdate.bind(this),t.addEventListener("compositionupdate",this.compositionUpdateListener),this.compositionEndListener=this.handleCompositionEnd.bind(this),t.addEventListener("compositionend",this.compositionEndListener),this.mousedownListener=this.handleMouseDown.bind(this),this.container.addEventListener("mousedown",this.mousedownListener),this.mouseupListener=this.handleMouseUp.bind(this),this.container.addEventListener("mouseup",this.mouseupListener),this.mousemoveListener=this.handleMouseMove.bind(this),this.container.addEventListener("mousemove",this.mousemoveListener),this.wheelListener=this.handleWheel.bind(this),this.container.addEventListener("wheel",this.wheelListener,{passive:!1})}mapKeyCode(t){return q[t]??null}syncEncoderOption(t,i){this.syncedEncoderOptions.get(t)!==i&&(this.encoder.setOption(t,i),this.syncedEncoderOptions.set(t,i))}extractModifiers(t){let i=a.Mods.NONE;return t.shiftKey&&(i|=a.Mods.SHIFT),t.ctrlKey&&(i|=a.Mods.CTRL),t.altKey&&(i|=a.Mods.ALT),t.metaKey&&(i|=a.Mods.SUPER),i}handleKeyDown(t){if(this.isDisposed||t.isComposing||t.keyCode===229)return;if(this.isComposing){this.pendingKeyAfterComposition=t.key,t.preventDefault();return}if(this.compositionJustEnded){this.compositionJustEnded=!1;return}if(this.onKeyCallback&&this.onKeyCallback({key:t.key,domEvent:t}),this.customKeyEventHandler&&this.customKeyEventHandler(t)){t.preventDefault();return}if((t.ctrlKey||t.metaKey)&&t.code==="KeyV"){const n=this.encoder.encode({key:a.Key.V,mods:t.ctrlKey?a.Mods.CTRL:a.Mods.SUPER,action:a.KeyAction.PRESS});n.length>0&&this.onDataCallback(new TextDecoder().decode(n));return}if(t.metaKey&&t.code==="KeyC"){this.onCopyCallback&&this.onCopyCallback()&&t.preventDefault();return}const i=this.mapKeyCode(t.code);if(i===null)return;const e=this.extractModifiers(t);let s;if(t.key.length>0&&t.key!=="Dead"&&t.key!=="Unidentified"){const n=t.key.codePointAt(0),o=n!==void 0&&n>65535?2:1;t.key.length===o&&(t.altKey&&n!==void 0&&n>127?t.code.startsWith("Key")&&t.code.length===4&&(s=t.code[3].toLowerCase()):s=t.key)}this.getModeCallback&&(this.syncEncoderOption(a.KeyEncoderOption.CURSOR_KEY_APPLICATION,this.getModeCallback(1)),this.syncEncoderOption(a.KeyEncoderOption.KEYPAD_KEY_APPLICATION,this.getModeCallback(66))),t.preventDefault(),t.stopPropagation();let r;try{const n=this.encoder.encode({action:a.KeyAction.PRESS,key:i,mods:e,utf8:s});r=n.length===0?"":this.decoder.decode(n)}catch(n){console.warn("Failed to encode key:",t.code,n);return}r.length>0&&(this.onDataCallback(r),this.recordKeyDownData(r))}handlePaste(t){if(this.isDisposed)return;const i=t.clipboardData;if(!i)return;const e=i.getData("text/plain");e&&(t.preventDefault(),t.stopPropagation(),!this.shouldIgnorePasteEvent(e,"paste")&&(this.emitPasteData(e),this.recordPasteData(e,"paste")))}handleBeforeInput(t){if(this.isDisposed||this.isComposing||t.isComposing)return;const i=t.inputType,e=t.data??"";let s=null;switch(i){case"insertText":case"insertReplacementText":s=e.length>0?e.replace(/\n/g,"\r"):null;break;case"insertLineBreak":case"insertParagraph":s="\r";break;case"deleteContentBackward":s="";break;case"deleteContentForward":s="\x1B[3~";break;case"insertFromPaste":if(!e)return;if(this.shouldIgnorePasteEvent(e,"beforeinput")){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),t.stopPropagation(),this.emitPasteData(e),this.recordPasteData(e,"beforeinput");return;default:return}if(s){if(this.shouldIgnoreBeforeInput(s)){t.preventDefault(),t.stopPropagation();return}if(e&&this.shouldIgnoreBeforeInputFromComposition(e)){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),t.stopPropagation(),this.onDataCallback(s),e&&this.recordBeforeInputData(e)}}handleCompositionStart(t){this.isDisposed||(this.isComposing=!0)}handleCompositionUpdate(t){this.isDisposed}handleCompositionEnd(t){if(this.isDisposed)return;this.isComposing=!1;const i=t.data;if(i&&i.length>0){if(this.shouldIgnoreCompositionEnd(i)){this.cleanupCompositionTextNodes(),this.processPendingKeyAfterComposition();return}this.onDataCallback(i),this.recordCompositionData(i)}this.cleanupCompositionTextNodes(),this.processPendingKeyAfterComposition()}processPendingKeyAfterComposition(){if(this.pendingKeyAfterComposition){const t=this.pendingKeyAfterComposition;this.pendingKeyAfterComposition=null,this.onDataCallback(t)}}cleanupCompositionTextNodes(){if(this.container&&this.container.childNodes)for(let t=this.container.childNodes.length-1;t>=0;t--){const i=this.container.childNodes[t];i.nodeType===3&&this.container.removeChild(i)}}pixelToCell(t){if(!this.mouseConfig)return null;const i=this.mouseConfig.getCellDimensions(),e=this.mouseConfig.getCanvasOffset();if(i.width<=0||i.height<=0)return null;const s=t.clientX-e.left,r=t.clientY-e.top,n=Math.floor(s/i.width)+1,o=Math.floor(r/i.height)+1;return{col:Math.max(1,n),row:Math.max(1,o)}}getMouseModifiers(t){let i=0;return t.shiftKey&&(i|=4),t.metaKey&&(i|=8),t.ctrlKey&&(i|=16),i}encodeMouseSGR(t,i,e,s,r){return`\x1B[<${t+r};${i};${e}${s?"m":"M"}`}encodeMouseX10(t,i,e,s){const r=t+s+32,n=String.fromCharCode(Math.min(i+32,255)),o=String.fromCharCode(Math.min(e+32,255));return`\x1B[M${String.fromCharCode(r)}${n}${o}`}sendMouseEvent(t,i,e,s,r){var c,l;const n=this.getMouseModifiers(r),o=((l=(c=this.mouseConfig)==null?void 0:c.hasSgrMouseMode)==null?void 0:l.call(c))??!0;let h;if(o)h=this.encodeMouseSGR(t,i,e,s,n);else{const u=s?3:t;h=this.encodeMouseX10(u,i,e,n)}this.onDataCallback(h)}handleMouseDown(t){var s;if(this.isDisposed||!((s=this.mouseConfig)!=null&&s.hasMouseTracking()))return;const i=this.pixelToCell(t);if(!i)return;const e=t.button;this.mouseButtonsPressed|=1<<e,this.sendMouseEvent(e,i.col,i.row,!1,t)}handleMouseUp(t){var s;if(this.isDisposed||!((s=this.mouseConfig)!=null&&s.hasMouseTracking()))return;const i=this.pixelToCell(t);if(!i)return;const e=t.button;this.mouseButtonsPressed&=~(1<<e),this.sendMouseEvent(e,i.col,i.row,!0,t)}handleMouseMove(t){var n,o,h;if(this.isDisposed||!((n=this.mouseConfig)!=null&&n.hasMouseTracking()))return;const i=((o=this.getModeCallback)==null?void 0:o.call(this,1002))??!1,e=((h=this.getModeCallback)==null?void 0:h.call(this,1003))??!1;if(!i&&!e||i&&!e&&this.mouseButtonsPressed===0)return;const s=this.pixelToCell(t);if(!s)return;let r=32;this.mouseButtonsPressed&1?r+=0:this.mouseButtonsPressed&2?r+=1:this.mouseButtonsPressed&4&&(r+=2),this.sendMouseEvent(r,s.col,s.row,!1,t)}handleWheel(t){var i;this.isDisposed||(i=this.mouseConfig)!=null&&i.hasMouseTracking()&&(this.sendWheelMouseEvent(t),t.preventDefault())}handleWheelEvent(t){this.isDisposed||this.sendWheelMouseEvent(t)}sendWheelMouseEvent(t){const i=this.pixelToCell(t);if(!i)return;const e=t.deltaY<0?64:65;this.sendMouseEvent(e,i.col,i.row,!1,t)}emitPasteData(t){var e;((e=this.getModeCallback)==null?void 0:e.call(this,2004))??!1?this.onDataCallback("\x1B[200~"+t+"\x1B[201~"):this.onDataCallback(t)}recordKeyDownData(t){this.lastKeyDownData=t,this.lastKeyDownTime=this.getNow()}recordPasteData(t,i){this.lastPasteData=t,this.lastPasteTime=this.getNow(),this.lastPasteSource=i}shouldIgnoreBeforeInput(t){if(!this.lastKeyDownData)return!1;const e=this.getNow()-this.lastKeyDownTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastKeyDownData===t;return this.lastKeyDownData=null,e}shouldIgnoreBeforeInputFromComposition(t){if(!this.lastCompositionData)return!1;const e=this.getNow()-this.lastCompositionTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastCompositionData===t;return e&&(this.lastCompositionData=null),e}shouldIgnoreCompositionEnd(t){if(!this.lastBeforeInputData)return!1;const e=this.getNow()-this.lastBeforeInputTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastBeforeInputData===t;return e&&(this.lastBeforeInputData=null),e}recordBeforeInputData(t){this.lastBeforeInputData=t,this.lastBeforeInputTime=this.getNow()}recordCompositionData(t){this.lastCompositionData=t,this.lastCompositionTime=this.getNow()}shouldIgnorePasteEvent(t,i){if(!this.lastPasteData||this.lastPasteSource===i)return!1;const s=this.getNow()-this.lastPasteTime<x.BEFORE_INPUT_IGNORE_MS&&this.lastPasteData===t;return s&&(this.lastPasteData=null,this.lastPasteSource=null),s}getNow(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}dispose(){if(this.isDisposed)return;this.keydownListener&&(this.container.removeEventListener("keydown",this.keydownListener),this.keydownListener=null),this.keypressListener&&(this.container.removeEventListener("keypress",this.keypressListener),this.keypressListener=null),this.pasteListener&&(this.container.removeEventListener("paste",this.pasteListener),this.inputElement&&this.inputElement!==this.container&&this.inputElement.removeEventListener("paste",this.pasteListener),this.pasteListener=null),this.beforeInputListener&&this.inputElement&&(this.inputElement.removeEventListener("beforeinput",this.beforeInputListener),this.beforeInputListener=null);const t=this.inputElement||this.container;this.compositionStartListener&&(t.removeEventListener("compositionstart",this.compositionStartListener),this.compositionStartListener=null),this.compositionUpdateListener&&(t.removeEventListener("compositionupdate",this.compositionUpdateListener),this.compositionUpdateListener=null),this.compositionEndListener&&(t.removeEventListener("compositionend",this.compositionEndListener),this.compositionEndListener=null),this.mousedownListener&&(this.container.removeEventListener("mousedown",this.mousedownListener),this.mousedownListener=null),this.mouseupListener&&(this.container.removeEventListener("mouseup",this.mouseupListener),this.mouseupListener=null),this.mousemoveListener&&(this.container.removeEventListener("mousemove",this.mousemoveListener),this.mousemoveListener=null),this.wheelListener&&(this.container.removeEventListener("wheel",this.wheelListener),this.wheelListener=null),this.isDisposed=!0}isActive(){return!this.isDisposed}};B.BEFORE_INPUT_IGNORE_MS=100;let F=B;class O{constructor(t){this.terminal=t,this.providers=[],this.linkCache=new Map,this.scannedRows=new Set}registerProvider(t){this.providers.push(t),this.invalidateCache()}async getLinkAt(t,i){const e=this.terminal.buffer.active.getLine(i);if(!(!e||t<0||t>=e.length||!e.getCell(t))){for(const r of this.linkCache.values())if(this.isPositionInLink(t,i,r))return r;this.scannedRows.has(i)||await this.scanRow(i);for(const r of this.linkCache.values())if(this.isPositionInLink(t,i,r))return r}}async scanRow(t){this.scannedRows.add(t);const i=[];for(const e of this.providers){const s=await new Promise(r=>{e.provideLinks(t,r)});s&&i.push(...s)}for(const e of i)this.cacheLink(e)}cacheLink(t){const{start:i,end:e}=t.range,s=`r${i.y}:${i.x}-${e.x}`;this.linkCache.has(s)||this.linkCache.set(s,t)}isPositionInLink(t,i,e){const{start:s,end:r}=e.range;return i<s.y||i>r.y?!1:s.y===r.y?t>=s.x&&t<=r.x:i===s.y?t>=s.x:i===r.y?t<=r.x:!0}invalidateCache(){this.linkCache.clear(),this.scannedRows.clear()}invalidateRows(t,i){for(let s=t;s<=i;s++)this.scannedRows.delete(s);const e=[];for(const[s,r]of this.linkCache.entries()){const{start:n,end:o}=r.range;(n.y>=t&&n.y<=i||o.y>=t&&o.y<=i||n.y<t&&o.y>i)&&e.push(s)}for(const s of e)this.linkCache.delete(s)}dispose(){var t;this.linkCache.clear(),this.scannedRows.clear();for(const i of this.providers)(t=i.dispose)==null||t.call(i);this.providers=[]}}class Y{constructor(t){this.terminal=t}provideLinks(t,i){const e=[],s=new Set,r=this.terminal.buffer.active.getLine(t);if(!r){i(void 0);return}for(let n=0;n<r.length;n++){if(s.has(n))continue;const o=r.getCell(n);if(!o||o.getHyperlinkId()===0||!this.terminal.wasmTerm)continue;const c=this.terminal.wasmTerm.getScrollbackLength(),l=t-c;let u;if(l<0?u=this.terminal.wasmTerm.getScrollbackHyperlinkUri(t,n):u=this.terminal.wasmTerm.getHyperlinkUri(l,n),u){let d=n;for(let m=n+1;m<r.length;m++){const g=r.getCell(m);if(!g||g.getHyperlinkId()===0||(l<0?this.terminal.wasmTerm.getScrollbackHyperlinkUri(t,m):this.terminal.wasmTerm.getHyperlinkUri(l,m))!==u)break;d=m}for(let m=n;m<=d;m++)s.add(m);const p={start:{x:n,y:t},end:{x:d,y:t}};e.push({text:u,range:p,activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(u,"_blank","noopener,noreferrer")}})}}i(e.length>0?e:void 0)}findLinkRange(t,i,e){const s=this.terminal.buffer.active;let r=i,n=e;for(;n>0;){const l=s.getLine(r);if(!l)break;const u=l.getCell(n-1);if(!u||u.getHyperlinkId()!==t)break;n--}if(n===0&&r>0){let l=r-1;for(;l>=0;){const u=s.getLine(l);if(!u||u.length===0)break;const d=u.getCell(u.length-1);if(!d||d.getHyperlinkId()!==t)break;r=l,n=0;for(let p=u.length-1;p>=0;p--){const m=u.getCell(p);if(!m||m.getHyperlinkId()!==t){n=p+1;break}}if(n===0)l--;else break}}let o=i,h=e;const c=s.getLine(o);if(c){for(;h<c.length-1;){const l=c.getCell(h+1);if(!l||l.getHyperlinkId()!==t)break;h++}if(h===c.length-1){let l=o+1;const u=s.length;for(;l<u;){const d=s.getLine(l);if(!d||d.length===0)break;const p=d.getCell(0);if(!p||p.getHyperlinkId()!==t)break;o=l,h=0;for(let m=0;m<d.length;m++){const g=d.getCell(m);if(!g)break;if(g.getHyperlinkId()!==t){h=m-1;break}h=m}if(h===d.length-1)l++;else break}}}return{start:{x:n,y:r},end:{x:h,y:o}}}dispose(){}}const K=class E{constructor(t){this.terminal=t}provideLinks(t,i){const e=[],s=this.terminal.buffer.active.getLine(t);if(!s){i(void 0);return}const r=this.lineToText(s);E.URL_REGEX.lastIndex=0;let n=E.URL_REGEX.exec(r);for(;n!==null;){let o=n[0];const h=n.index;let c=n.index+o.length-1;const l=o.replace(E.TRAILING_PUNCTUATION,"");for(l.length<o.length&&(o=l,c=h+o.length-1);o.endsWith(")");){const u=o.split("(").length-1;if(o.split(")").length-1>u)o=o.slice(0,-1),c--;else break}o.length>8&&e.push({text:o,range:{start:{x:h,y:t},end:{x:c,y:t}},activate:u=>{(u.ctrlKey||u.metaKey)&&window.open(o,"_blank","noopener,noreferrer")}}),n=E.URL_REGEX.exec(r)}i(e.length>0?e:void 0)}lineToText(t){const i=[];for(let e=0;e<t.length;e++){const s=t.getCell(e);if(!s){i.push(" ");continue}const r=s.getCodepoint();r===0||r<32?i.push(" "):i.push(String.fromCodePoint(r))}return i.join("")}dispose(){}};K.URL_REGEX=/(?:https?:\/\/|mailto:|ftp:\/\/|ssh:\/\/|git:\/\/|tel:|magnet:|gemini:\/\/|gopher:\/\/|news:)[\w\-.~:\/?#@!$&*+,;=%()]+/gi;K.TRAILING_PUNCTUATION=/[.,;!?\]]+$/;let N=K;const $=[773,781,782,784,786,829,830,831,838,842,843,844,848,849,850,855,859,867,868,869,870,871,872,873,874,875,876,877,878,879,1155,1156,1157,1158,1159,1426,1427,1428,1429,1431,1432,1433,1436,1437,1438,1439,1440,1441,1448,1449,1451,1452,1455,1476,1552,1553,1554,1555,1556,1557,1558,1559,1623,1624,1625,1626,1627,1629,1630,1750,1751,1752,1753,1754,1755,1756,1759,1760,1761,1762,1764,1767,1768,1771,1772,1840,1842,1843,1845,1846,1850,1853,1855,1856,1857,1859,1861,1863,1865,1866,2027,2028,2029,2030,2031,2032,2033,2035,2070,2071,2072,2073,2075,2076,2077,2078,2079,2080,2081,2082,2083,2085,2086,2087,2089,2090,2091,2092,2093,2385,2387,2388,3970,3971,3974,3975,4957,4958,4959,6109,6458,6679,6773,6774,6775,6776,6777,6778,6779,6780,7019,7021,7022,7023,7024,7025,7026,7027,7376,7377,7378,7386,7387,7392,7616,7617,7619,7620,7621,7622,7623,7624,7625,7627,7628,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643,7644,7645,7646,7647,7648,7649,7650,7651,7652,7653,7654,7678,8400,8401,8404,8405,8406,8407,8411,8412,8417,8423,8425,8432,11503,11504,11505,11744,11745,11746,11747,11748,11749,11750,11751,11752,11753,11754,11755,11756,11757,11758,11759,11760,11761,11762,11763,11764,11765,11766,11767,11768,11769,11770,11771,11772,11773,11774,11775,42607,42620,42621,42736,42737,43232,43233,43234,43235,43236,43237,43238,43239,43240,43241,43242,43243,43244,43245,43246,43247,43248,43249,43696,43698,43699,43703,43704,43710,43711,43713,65056,65057,65058,65059,65060,65061,65062,68111,68152,119173,119174,119175,119176,119177,119210,119211,119212,119213,119362,119363,119364],Q=new Map($.map((v,t)=>[v,t]));function D(v){return Q.get(v)??-1}const X=1109742,T={foreground:"#d4d4d4",background:"#1e1e1e",cursor:"#ffffff",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"};function _(v,t){return v.width===t.width&&v.height===t.height&&v.format===t.format&&v.dataPtr===t.data.byteOffset&&v.dataLen===t.data.length}class U{constructor(t,i={}){this.cursorVisible=!0,this.lastCursorPosition={x:0,y:0},this.onRequestRender=null,this.lastViewportY=0,this.currentBuffer=null,this.kittyImageCache=new Map,this.kittyVirtualPlacements=new Map,this.currentDirectPlacements=[],this.lastKittyDirectSigs=new Map,this.kittyDamagedRows=new Set,this.currentRenderBuffer=null,this.currentKittyGraphics=null,this.currentSelectionCoords=null,this.hoveredHyperlinkId=0,this.previousHoveredHyperlinkId=0,this.hoveredLinkRange=null,this.previousHoveredLinkRange=null,this.canvas=t;const e=t.getContext("2d",{alpha:!0});if(!e)throw new Error("Failed to get 2D rendering context");this.ctx=e,this.fontSize=i.fontSize??15,this.fontFamily=i.fontFamily??"monospace",this.cursorStyle=i.cursorStyle??"block",this.cursorBlink=i.cursorBlink??!1,this.theme={...T,...i.theme},this.devicePixelRatio=i.devicePixelRatio??window.devicePixelRatio??1,this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite],this.metrics=this.measureFont(),this.cursorBlink&&this.startCursorBlink()}buildFontString(t=""){const i=this.fontFamily.split(",").map(e=>{const s=e.trim();return s.startsWith('"')||s.startsWith("'")||!s.includes(" ")?s:`"${s}"`}).join(", ");return`${t}${this.fontSize}px ${i}`}measureFont(){const i=document.createElement("canvas").getContext("2d");i.font=this.buildFontString();const e=i.measureText("M"),s=e.fontBoundingBoxAscent||e.actualBoundingBoxAscent||this.fontSize*.8,r=e.fontBoundingBoxDescent||e.actualBoundingBoxDescent||this.fontSize*.2,n=this.devicePixelRatio,o=Math.ceil(e.width*n)/n,h=Math.ceil((s+r)*n)/n,c=Math.ceil(s*n)/n;return{width:o,height:h,baseline:c}}remeasureFont(){this.metrics=this.measureFont()}rgbToCSS(t,i,e){return`rgb(${t}, ${i}, ${e})`}resize(t,i){const e=t*this.metrics.width,s=i*this.metrics.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${s}px`,this.canvas.width=e*this.devicePixelRatio,this.canvas.height=s*this.devicePixelRatio,this.ctx.scale(this.devicePixelRatio,this.devicePixelRatio),this.ctx.textBaseline="alphabetic",this.ctx.textAlign="left",this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,e,s)}render(t,i=!1,e=0,s,r=1){var y;this.currentBuffer=t,this.currentRenderBuffer=t;const n=t.getCursor(),o=t.getDimensions();this.precomputeKittyState(t,o.rows);const h=s?s.getScrollbackLength():0;(y=t.needsFullRedraw)!=null&&y.call(t)&&(i=!0),(this.canvas.width!==o.cols*this.metrics.width*this.devicePixelRatio||this.canvas.height!==o.rows*this.metrics.height*this.devicePixelRatio)&&(this.resize(o.cols,o.rows),i=!0),e!==this.lastViewportY&&(i=!0,this.lastViewportY=e);const l=n.x!==this.lastCursorPosition.x||n.y!==this.lastCursorPosition.y;if(l||this.cursorBlink){if(!i&&!t.isRowDirty(n.y)){const f=t.getLine(n.y);f&&this.renderLine(f,n.y,o.cols)}if(l&&!i){const f=t.getLine(this.lastCursorPosition.y);f&&this.renderLine(f,this.lastCursorPosition.y,o.cols)}}const u=this.selectionManager&&this.selectionManager.hasSelection(),d=new Set;if(this.currentSelectionCoords=u?this.selectionManager.getSelectionCoords():null,this.currentSelectionCoords){const f=this.currentSelectionCoords;for(let b=f.startRow;b<=f.endRow;b++)d.add(b)}if(this.selectionManager){const f=this.selectionManager.getDirtySelectionRows();if(f.size>0){for(const b of f)d.add(b);this.selectionManager.clearDirtySelectionRows()}}const p=new Set,m=this.hoveredHyperlinkId!==this.previousHoveredHyperlinkId,g=JSON.stringify(this.hoveredLinkRange)!==JSON.stringify(this.previousHoveredLinkRange);if(m){for(let f=0;f<o.rows;f++){let b=null;if(e>0)if(f<e&&s){const S=h-Math.floor(e)+f;b=s.getScrollbackLine(S)}else{const S=f-Math.floor(e);b=t.getLine(S)}else b=t.getLine(f);if(b){for(const S of b)if(S.hyperlink_id===this.hoveredHyperlinkId||S.hyperlink_id===this.previousHoveredHyperlinkId){p.add(f);break}}}this.previousHoveredHyperlinkId=this.hoveredHyperlinkId}if(g){if(this.previousHoveredLinkRange)for(let f=this.previousHoveredLinkRange.startY;f<=this.previousHoveredLinkRange.endY;f++)p.add(f);if(this.hoveredLinkRange)for(let f=this.hoveredLinkRange.startY;f<=this.hoveredLinkRange.endY;f++)p.add(f);this.previousHoveredLinkRange=this.hoveredLinkRange}let w=!1;const C=new Set;for(let f=0;f<o.rows;f++)(e>0?!0:i||t.isRowDirty(f)||d.has(f)||p.has(f)||this.kittyDamagedRows.has(f))&&(C.add(f),f>0&&C.add(f-1),f<o.rows-1&&C.add(f+1));for(let f=0;f<o.rows;f++){if(!C.has(f))continue;w=!0;let b=null;if(e>0)if(f<e&&s){const S=h-Math.floor(e)+f;b=s.getScrollbackLine(S)}else{const S=e>0?f-Math.floor(e):f;b=t.getLine(S)}else b=t.getLine(f);b&&this.renderLine(b,f,o.cols)}if(this.currentDirectPlacements.length>0&&w&&this.renderKittyImages(),e===0&&n.visible&&this.cursorVisible){const f=n.style??this.cursorStyle;this.renderCursor(n.x,n.y,f)}s&&r>0&&this.renderScrollbar(e,h,o.rows,r),this.lastCursorPosition={x:n.x,y:n.y},t.clearDirty()}renderLine(t,i,e){const s=i*this.metrics.height,r=e*this.metrics.width;this.ctx.clearRect(0,s,r,this.metrics.height),this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,s,r,this.metrics.height);for(let n=0;n<t.length;n++){const o=t[n];o.width!==0&&this.renderCellBackground(o,n,i)}for(let n=0;n<t.length;n++){const o=t[n];o.width!==0&&this.renderCellText(o,n,i)}}renderCellBackground(t,i,e){const s=i*this.metrics.width,r=e*this.metrics.height,n=this.metrics.width*t.width;if(this.isInSelection(i,e)){this.ctx.fillStyle=this.theme.selectionBackground,this.ctx.fillRect(s,r,n,this.metrics.height);return}let h=t.bg_r,c=t.bg_g,l=t.bg_b;t.flags&a.CellFlags.INVERSE&&(h=t.fg_r,c=t.fg_g,l=t.fg_b),(t.flags&a.CellFlags.INVERSE?t.fgIsDefault:t.bgIsDefault)||(this.ctx.fillStyle=this.rgbToCSS(h,c,l),this.ctx.fillRect(s,r,n,this.metrics.height))}renderCellText(t,i,e,s){var C;const r=i*this.metrics.width,n=e*this.metrics.height,o=this.metrics.width*t.width;if(t.codepoint===X&&this.renderPlaceholderCell(t,i,e)||t.flags&a.CellFlags.INVISIBLE)return;const h=this.isInSelection(i,e);let c="";t.flags&a.CellFlags.ITALIC&&(c+="italic "),t.flags&a.CellFlags.BOLD&&(c+="bold "),this.ctx.font=this.buildFontString(c);let l=t.fg_r,u=t.fg_g,d=t.fg_b;if(t.flags&a.CellFlags.INVERSE&&(l=t.bg_r,u=t.bg_g,d=t.bg_b),s)this.ctx.fillStyle=s;else if(h)this.ctx.fillStyle=this.theme.selectionForeground;else{const y=t.flags&a.CellFlags.INVERSE?t.bgIsDefault:t.fgIsDefault;this.ctx.fillStyle=y?this.theme.foreground:this.rgbToCSS(l,u,d)}t.flags&a.CellFlags.FAINT&&(this.ctx.globalAlpha=.5);const p=r,m=n+this.metrics.baseline;let g;t.grapheme_len>0&&((C=this.currentBuffer)!=null&&C.getGraphemeString)?g=this.currentBuffer.getGraphemeString(e,i):g=String.fromCodePoint(t.codepoint||32);const w=t.codepoint||32;if(this.renderBlockChar(w,r,n,o)||this.renderPowerlineGlyph(w,r,n,o)||this.ctx.fillText(g,p,m),t.flags&a.CellFlags.FAINT&&(this.ctx.globalAlpha=1),t.flags&a.CellFlags.UNDERLINE){const y=n+this.metrics.baseline+2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,y),this.ctx.lineTo(r+o,y),this.ctx.stroke()}if(t.flags&a.CellFlags.STRIKETHROUGH){const y=n+this.metrics.height/2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,y),this.ctx.lineTo(r+o,y),this.ctx.stroke()}if(t.hyperlink_id>0&&t.hyperlink_id===this.hoveredHyperlinkId){const f=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,f),this.ctx.lineTo(r+o,f),this.ctx.stroke()}if(this.hoveredLinkRange){const y=this.hoveredLinkRange;if(e===y.startY&&i>=y.startX&&(e<y.endY||i<=y.endX)||e>y.startY&&e<y.endY||e===y.endY&&i<=y.endX&&(e>y.startY||i>=y.startX)){const b=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,b),this.ctx.lineTo(r+o,b),this.ctx.stroke()}}}renderBlockChar(t,i,e,s){const r=this.metrics.height;switch(t){case 9600:return this.ctx.fillRect(i,e,s,r/2),!0;case 9601:return this.ctx.fillRect(i,e+r*7/8,s,r/8),!0;case 9602:return this.ctx.fillRect(i,e+r*3/4,s,r/4),!0;case 9603:return this.ctx.fillRect(i,e+r*5/8,s,r*3/8),!0;case 9604:return this.ctx.fillRect(i,e+r/2,s,r/2),!0;case 9605:return this.ctx.fillRect(i,e+r*3/8,s,r*5/8),!0;case 9606:return this.ctx.fillRect(i,e+r/4,s,r*3/4),!0;case 9607:return this.ctx.fillRect(i,e+r/8,s,r*7/8),!0;case 9608:return this.ctx.fillRect(i,e,s,r),!0;case 9609:return this.ctx.fillRect(i,e,s*7/8,r),!0;case 9610:return this.ctx.fillRect(i,e,s*3/4,r),!0;case 9611:return this.ctx.fillRect(i,e,s*5/8,r),!0;case 9612:return this.ctx.fillRect(i,e,s/2,r),!0;case 9613:return this.ctx.fillRect(i,e,s*3/8,r),!0;case 9614:return this.ctx.fillRect(i,e,s/4,r),!0;case 9615:return this.ctx.fillRect(i,e,s/8,r),!0;case 9616:return this.ctx.fillRect(i+s/2,e,s/2,r),!0;case 9620:return this.ctx.fillRect(i,e,s,r/8),!0;case 9621:return this.ctx.fillRect(i+s*7/8,e,s/8,r),!0;default:return!1}}renderPowerlineGlyph(t,i,e,s){const r=this.metrics.height,n=this.ctx;switch(t){case 57520:return n.beginPath(),n.moveTo(i,e),n.lineTo(i+s,e+r/2),n.lineTo(i,e+r),n.closePath(),n.fill(),!0;case 57521:return n.beginPath(),n.moveTo(i,e),n.lineTo(i+s,e+r/2),n.lineTo(i,e+r),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57522:return n.beginPath(),n.moveTo(i+s,e),n.lineTo(i,e+r/2),n.lineTo(i+s,e+r),n.closePath(),n.fill(),!0;case 57523:return n.beginPath(),n.moveTo(i+s,e),n.lineTo(i,e+r/2),n.lineTo(i+s,e+r),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57524:return n.beginPath(),n.moveTo(i,e),n.ellipse(i,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!1),n.closePath(),n.fill(),!0;case 57525:return n.beginPath(),n.moveTo(i,e),n.ellipse(i,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!1),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57526:return n.beginPath(),n.moveTo(i+s,e),n.ellipse(i+s,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!0),n.closePath(),n.fill(),!0;case 57527:return n.beginPath(),n.moveTo(i+s,e),n.ellipse(i+s,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!0),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;default:return!1}}precomputeKittyState(t,i){var n;this.kittyVirtualPlacements.clear(),this.currentDirectPlacements=[],this.kittyDamagedRows.clear(),this.currentKittyGraphics=null;const e=new Map,s=this.metrics.height,r=(o,h)=>{const c=Math.max(0,Math.floor(o)),l=Math.min(i,Math.ceil(o+h/s));for(let u=c;u<l;u++)this.kittyDamagedRows.add(u)};if(t.getKittyGraphics&&t.iterPlacements){const o=t.getKittyGraphics();if(o!==null){this.currentKittyGraphics=o;for(const h of t.iterPlacements(o,!1)){if(h.isVirtual){this.kittyVirtualPlacements.set(h.imageId,h);continue}this.currentDirectPlacements.push(h);const c=(n=t.getKittyImagePixels)==null?void 0:n.call(t,o,h.imageId),l={viewportCol:h.viewportCol,viewportRow:h.viewportRow,pixelWidth:h.pixelWidth,pixelHeight:h.pixelHeight,sourceX:h.sourceX,sourceY:h.sourceY,sourceWidth:h.sourceWidth,sourceHeight:h.sourceHeight,imgWidth:(c==null?void 0:c.width)??0,imgHeight:(c==null?void 0:c.height)??0,imgFormat:(c==null?void 0:c.format)??0,dataPtr:(c==null?void 0:c.data.byteOffset)??0,dataLen:(c==null?void 0:c.data.length)??0};e.set(h.imageId,l);const u=this.lastKittyDirectSigs.get(h.imageId);(!u||u.viewportCol!==l.viewportCol||u.viewportRow!==l.viewportRow||u.pixelWidth!==l.pixelWidth||u.pixelHeight!==l.pixelHeight||u.sourceX!==l.sourceX||u.sourceY!==l.sourceY||u.sourceWidth!==l.sourceWidth||u.sourceHeight!==l.sourceHeight||u.imgWidth!==l.imgWidth||u.imgHeight!==l.imgHeight||u.imgFormat!==l.imgFormat||u.dataPtr!==l.dataPtr||u.dataLen!==l.dataLen)&&(r(l.viewportRow,l.pixelHeight),u&&r(u.viewportRow,u.pixelHeight))}}}for(const[o,h]of this.lastKittyDirectSigs)e.has(o)||r(h.viewportRow,h.pixelHeight);this.lastKittyDirectSigs=e}getOrDecodeKittyImage(t,i,e){var o;const s=this.kittyImageCache.get(e),r=(o=t.getKittyImagePixels)==null?void 0:o.call(t,i,e);if(!r)return(s==null?void 0:s.canvas)??null;if(s&&_(s,r))return s.canvas;const n=this.decodeKittyImageToCanvas(r);return n?(this.kittyImageCache.set(e,{canvas:n,width:r.width,height:r.height,format:r.format,dataPtr:r.data.byteOffset,dataLen:r.data.length}),n):null}renderBlockElement(t,i,e,s){if(t<9600||t>9631)return!1;const r=s,n=this.metrics.height;if(t===9600)return this.ctx.fillRect(i,e,r,Math.round(n/2)),!0;if(t>=9601&&t<=9608){const g=t-9600,w=Math.round(n*g/8);return this.ctx.fillRect(i,e+n-w,r,w),!0}if(t>=9609&&t<=9615){const g=9616-t,w=Math.round(r*g/8);return this.ctx.fillRect(i,e,w,n),!0}if(t===9616){const g=Math.round(r/2);return this.ctx.fillRect(i+g,e,r-g,n),!0}if(t>=9617&&t<=9619){const g=[.25,.5,.75][t-9617],w=this.ctx.globalAlpha;return this.ctx.globalAlpha=w*g,this.ctx.fillRect(i,e,r,n),this.ctx.globalAlpha=w,!0}if(t===9620)return this.ctx.fillRect(i,e,r,Math.round(n/8)),!0;if(t===9621){const g=Math.round(r*7/8);return this.ctx.fillRect(i+g,e,r-g,n),!0}const o=8,h=4,c=2,l=1,d={9622:c,9623:l,9624:o,9625:o|c|l,9626:o|l,9627:o|h|c,9628:o|h|l,9629:h,9630:h|c,9631:h|c|l}[t];if(d===void 0)return!1;const p=Math.round(r/2),m=Math.round(n/2);return d&o&&this.ctx.fillRect(i,e,p,m),d&h&&this.ctx.fillRect(i+p,e,r-p,m),d&c&&this.ctx.fillRect(i,e+m,p,n-m),d&l&&this.ctx.fillRect(i+p,e+m,r-p,n-m),!0}renderPlaceholderCell(t,i,e){var S;const s=this.currentRenderBuffer,r=this.currentKittyGraphics;if(!s||r===null||!s.getGrapheme)return!1;const n=s.getGrapheme(e,i);if(!n||n.length<3)return!1;const o=D(n[1]),h=D(n[2]);if(o<0||h<0)return!1;const c=t.fg_r<<16|t.fg_g<<8|t.fg_b;let l=c;if(n.length>=4){const k=D(n[3]);k>=0&&(l=k<<24|c)}const u=this.kittyVirtualPlacements.get(l);if(!u)return!1;const d=(S=s.getKittyImagePixels)==null?void 0:S.call(s,r,l);if(!d)return!1;const p=this.getOrDecodeKittyImage(s,r,l);if(!p)return!1;const m=d.width/u.gridCols,g=d.height/u.gridRows,w=h*m,C=o*g,y=i*this.metrics.width,f=e*this.metrics.height,b=this.ctx.imageSmoothingEnabled;return this.ctx.imageSmoothingEnabled=!1,this.ctx.drawImage(p,w,C,m,g,y,f,this.metrics.width,this.metrics.height),this.ctx.imageSmoothingEnabled=b,!0}renderKittyImages(){const t=this.currentRenderBuffer,i=this.currentKittyGraphics;if(!(!t||i===null||!t.getKittyImagePixels))for(const e of this.currentDirectPlacements){let s=this.kittyImageCache.get(e.imageId);const r=t.getKittyImagePixels(i,e.imageId);if(r){if(!s||!_(s,r)){const n=this.decodeKittyImageToCanvas(r);if(!n)continue;s={canvas:n,width:r.width,height:r.height,format:r.format,dataPtr:r.data.byteOffset,dataLen:r.data.length},this.kittyImageCache.set(e.imageId,s)}this.ctx.drawImage(s.canvas,e.sourceX,e.sourceY,e.sourceWidth,e.sourceHeight,e.viewportCol*this.metrics.width,e.viewportRow*this.metrics.height,e.pixelWidth,e.pixelHeight)}}}decodeKittyImageToCanvas(t){const{width:i,height:e,format:s,data:r}=t;if(i===0||e===0)return null;const n=new Uint8ClampedArray(new ArrayBuffer(i*e*4));switch(s){case a.KittyImageFormat.RGBA:n.set(r);break;case a.KittyImageFormat.RGB:for(let c=0,l=0;c<r.length;c+=3,l+=4)n[l]=r[c],n[l+1]=r[c+1],n[l+2]=r[c+2],n[l+3]=255;break;case a.KittyImageFormat.GRAY:for(let c=0,l=0;c<r.length;c++,l+=4){const u=r[c];n[l]=u,n[l+1]=u,n[l+2]=u,n[l+3]=255}break;case a.KittyImageFormat.GRAY_ALPHA:for(let c=0,l=0;c<r.length;c+=2,l+=4){const u=r[c];n[l]=u,n[l+1]=u,n[l+2]=u,n[l+3]=r[c+1]}break;default:return null}const o=document.createElement("canvas");o.width=i,o.height=e;const h=o.getContext("2d");return h?(h.putImageData(new ImageData(n,i,e),0,0),o):null}renderCursor(t,i,e){var o;const s=t*this.metrics.width,r=i*this.metrics.height,n=e??this.cursorStyle;switch(this.ctx.fillStyle=this.theme.cursor,n){case"block":this.ctx.fillRect(s,r,this.metrics.width,this.metrics.height);{const l=(o=this.currentBuffer)==null?void 0:o.getLine(i);l!=null&&l[t]&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(s,r,this.metrics.width,this.metrics.height),this.ctx.clip(),this.renderCellText(l[t],t,i,this.theme.cursorAccent),this.ctx.restore())}break;case"underline":const h=Math.max(2,Math.floor(this.metrics.height*.15));this.ctx.fillRect(s,r+this.metrics.height-h,this.metrics.width,h);break;case"bar":const c=Math.max(2,Math.floor(this.metrics.width*.15));this.ctx.fillRect(s,r,c,this.metrics.height);break}}setOnRequestRender(t){this.onRequestRender=t}startCursorBlink(){this.cursorBlinkInterval=window.setInterval(()=>{var t;this.cursorVisible=!this.cursorVisible,(t=this.onRequestRender)==null||t.call(this)},530)}stopCursorBlink(){this.cursorBlinkInterval!==void 0&&(clearInterval(this.cursorBlinkInterval),this.cursorBlinkInterval=void 0),this.cursorVisible=!0}setTheme(t){this.theme={...T,...t},this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite]}setFontSize(t){this.fontSize=t,this.metrics=this.measureFont()}setFontFamily(t){this.fontFamily=t,this.metrics=this.measureFont()}setCursorStyle(t){this.cursorStyle=t}setCursorBlink(t){t&&!this.cursorBlink?(this.cursorBlink=!0,this.startCursorBlink()):!t&&this.cursorBlink&&(this.cursorBlink=!1,this.stopCursorBlink())}renderScrollbar(t,i,e,s=1){const r=this.ctx,n=this.canvas.height/this.devicePixelRatio,o=this.canvas.width/this.devicePixelRatio,h=8,c=o-h-4,l=4,u=n-l*2;if(r.clearRect(c-2,0,h+6,n),r.fillStyle=this.theme.background,r.fillRect(c-2,0,h+6,n),s<=0||i===0)return;const d=i+e,p=Math.max(20,e/d*u),m=t/i,g=l+(u-p)*(1-m);r.fillStyle=`rgba(128, 128, 128, ${.1*s})`,r.fillRect(c,l,h,u);const C=t>0?.5:.3;r.fillStyle=`rgba(128, 128, 128, ${C*s})`,r.fillRect(c,g,h,p)}getMetrics(){return{...this.metrics}}getCanvas(){return this.canvas}setSelectionManager(t){this.selectionManager=t}isInSelection(t,i){const e=this.currentSelectionCoords;if(!e)return!1;const{startCol:s,startRow:r,endCol:n,endRow:o}=e;return r===o?i===r&&t>=s&&t<=n:i===r?t>=s:i===o?t<=n:i>r&&i<o}setHoveredHyperlinkId(t){var i;this.hoveredHyperlinkId!==t&&(this.hoveredHyperlinkId=t,(i=this.onRequestRender)==null||i.call(this))}setHoveredLinkRange(t){var i;this.hoveredLinkRange!==t&&(this.hoveredLinkRange=t,(i=this.onRequestRender)==null||i.call(this))}get charWidth(){return this.metrics.width}get charHeight(){return this.metrics.height}clear(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}dispose(){this.stopCursorBlink()}}const M=class L{constructor(t,i,e,s){this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.mouseDownX=0,this.mouseDownY=0,this.dragThresholdMet=!1,this.mouseDownTarget=null,this.dirtySelectionRows=new Set,this.selectionChangedEmitter=new a.EventEmitter,this.boundMouseUpHandler=null,this.boundContextMenuHandler=null,this.boundClickHandler=null,this.boundDocumentMouseMoveHandler=null,this.autoScrollInterval=null,this.autoScrollDirection=0,this.terminal=t,this.renderer=i,this.wasmTerm=e,this.textarea=s,this.attachEventListeners()}getViewportY(){const t=typeof this.terminal.getViewportY=="function"?this.terminal.getViewportY():this.terminal.viewportY||0;return Math.max(0,Math.floor(t))}viewportRowToAbsolute(t){const i=this.wasmTerm.getScrollbackLength(),e=this.getViewportY();return i+t-e}absoluteRowToViewport(t){const i=this.wasmTerm.getScrollbackLength(),e=this.getViewportY();return t-i+e}getSelection(){if(!this.selectionStart||!this.selectionEnd)return"";let{col:t,absoluteRow:i}=this.selectionStart,{col:e,absoluteRow:s}=this.selectionEnd;(i>s||i===s&&t>e)&&([t,e]=[e,t],[i,s]=[s,i]);const r=this.wasmTerm.getScrollbackLength();let n="";for(let o=i;o<=s;o++){let h=null;if(o<r)h=this.wasmTerm.getScrollbackLine(o);else{const p=o-r;h=this.wasmTerm.getLine(p)}if(!h)continue;let c=-1;const l=o===i?t:0,u=o===s?e:h.length-1;let d="";for(let p=l;p<=u;p++){const m=h[p];if(m&&m.codepoint!==0){let g;if(m.grapheme_len>0)if(o<r)g=this.wasmTerm.getScrollbackGraphemeString(o,p);else{const w=o-r;g=this.wasmTerm.getGraphemeString(w,p)}else g=String.fromCodePoint(m.codepoint);d+=g,g.trim()&&(c=d.length)}else(!m||m.width!==0)&&(d+=" ")}c>=0?d=d.substring(0,c):d="",n+=d,o<s&&(n+=`
2
- `)}return n}hasSelection(){return!(!this.selectionStart||!this.selectionEnd||this.isSelecting&&!this.dragThresholdMet)}copySelection(){if(!this.hasSelection())return!1;const t=this.getSelection();return t?(this.copyToClipboard(t),!0):!1}clearSelection(){if(!this.hasSelection())return;const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i);this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.requestRender()}selectAll(){const t=this.wasmTerm.getDimensions(),i=this.getViewportY();this.selectionStart={col:0,absoluteRow:i},this.selectionEnd={col:t.cols-1,absoluteRow:i+t.rows-1},this.requestRender(),this.selectionChangedEmitter.fire()}select(t,i,e){const s=this.wasmTerm.getDimensions();i=Math.max(0,Math.min(i,s.rows-1)),t=Math.max(0,Math.min(t,s.cols-1));let r=i,n=t+e-1;for(;n>=s.cols;)n-=s.cols,r++;r=Math.min(r,s.rows-1);const o=this.getViewportY();this.selectionStart={col:t,absoluteRow:o+i},this.selectionEnd={col:n,absoluteRow:o+r},this.requestRender(),this.selectionChangedEmitter.fire()}selectLines(t,i){const e=this.wasmTerm.getDimensions();t=Math.max(0,Math.min(t,e.rows-1)),i=Math.max(0,Math.min(i,e.rows-1)),t>i&&([t,i]=[i,t]),this.selectionStart={col:0,absoluteRow:this.viewportRowToAbsolute(t)},this.selectionEnd={col:e.cols-1,absoluteRow:this.viewportRowToAbsolute(i)},this.requestRender(),this.selectionChangedEmitter.fire()}getSelectionPosition(){const t=this.normalizeSelection();if(t)return{start:{x:t.startCol,y:t.startRow},end:{x:t.endCol,y:t.endRow}}}deselect(){this.clearSelection(),this.selectionChangedEmitter.fire()}focus(){const t=this.renderer.getCanvas();t.parentElement&&t.parentElement.focus()}getSelectionCoords(){return this.normalizeSelection()}getDirtySelectionRows(){return this.dirtySelectionRows}clearDirtySelectionRows(){this.dirtySelectionRows.clear()}get onSelectionChange(){return this.selectionChangedEmitter.event}dispose(){this.selectionChangedEmitter.dispose(),this.stopAutoScroll(),this.boundMouseUpHandler&&(document.removeEventListener("mouseup",this.boundMouseUpHandler),this.boundMouseUpHandler=null),this.boundDocumentMouseMoveHandler&&(document.removeEventListener("mousemove",this.boundDocumentMouseMoveHandler),this.boundDocumentMouseMoveHandler=null),this.boundContextMenuHandler&&(this.renderer.getCanvas().removeEventListener("contextmenu",this.boundContextMenuHandler),this.boundContextMenuHandler=null),this.boundClickHandler&&(document.removeEventListener("click",this.boundClickHandler),this.boundClickHandler=null)}attachEventListeners(){const t=this.renderer.getCanvas();t.addEventListener("mousedown",i=>{if(i.button===0){t.parentElement&&t.parentElement.focus();const e=this.pixelToCell(i.offsetX,i.offsetY);this.hasSelection()&&this.clearSelection();const r=this.viewportRowToAbsolute(e.row);this.selectionStart={col:e.col,absoluteRow:r},this.selectionEnd={col:e.col,absoluteRow:r},this.isSelecting=!0,this.mouseDownX=i.offsetX,this.mouseDownY=i.offsetY,this.dragThresholdMet=!1}}),t.addEventListener("mousemove",i=>{if(this.isSelecting){if(!this.dragThresholdMet){const r=i.offsetX-this.mouseDownX,n=i.offsetY-this.mouseDownY,o=this.renderer.getMetrics().width*.5;if(r*r+n*n<o*o)return;this.dragThresholdMet=!0}this.markCurrentSelectionDirty();const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.viewportRowToAbsolute(e.row);this.selectionEnd={col:e.col,absoluteRow:s},this.requestRender(),this.updateAutoScroll(i.offsetY,t.clientHeight)}}),t.addEventListener("mouseleave",i=>{if(this.isSelecting){const e=t.getBoundingClientRect();i.clientY<e.top?this.startAutoScroll(-1):i.clientY>e.bottom&&this.startAutoScroll(1)}}),t.addEventListener("mouseenter",()=>{this.isSelecting&&this.stopAutoScroll()}),this.boundDocumentMouseMoveHandler=i=>{if(this.isSelecting){if(!this.dragThresholdMet){const h=i.clientX-(t.getBoundingClientRect().left+this.mouseDownX),c=i.clientY-(t.getBoundingClientRect().top+this.mouseDownY),l=this.renderer.getMetrics().width*.5;if(h*h+c*c<l*l)return;this.dragThresholdMet=!0}const e=t.getBoundingClientRect(),s=Math.max(e.left,Math.min(i.clientX,e.right)),r=Math.max(e.top,Math.min(i.clientY,e.bottom)),n=s-e.left,o=r-e.top;if((i.clientX<e.left||i.clientX>e.right||i.clientY<e.top||i.clientY>e.bottom)&&(i.clientY<e.top?this.startAutoScroll(-1):i.clientY>e.bottom?this.startAutoScroll(1):this.stopAutoScroll(),this.autoScrollDirection===0)){this.markCurrentSelectionDirty();const h=this.pixelToCell(n,o),c=this.viewportRowToAbsolute(h.row);this.selectionEnd={col:h.col,absoluteRow:c},this.requestRender()}}},document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.addEventListener("mousedown",i=>{this.mouseDownTarget=i.target}),this.boundMouseUpHandler=i=>{if(this.isSelecting){if(this.isSelecting=!1,this.stopAutoScroll(),!this.dragThresholdMet){this.clearSelection();return}if(this.hasSelection()){try{const e=this.getSelection();e&&this.copyToClipboard(e)}catch{}this.selectionChangedEmitter.fire()}}},document.addEventListener("mouseup",this.boundMouseUpHandler),t.addEventListener("click",i=>{if(i.detail===2){const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.getWordAtCell(e.col,e.row);if(s){const r=this.viewportRowToAbsolute(e.row);this.selectionStart={col:s.startCol,absoluteRow:r},this.selectionEnd={col:s.endCol,absoluteRow:r},this.requestRender();try{const n=this.getSelection();n&&this.copyToClipboard(n)}catch{}this.selectionChangedEmitter.fire()}}else if(i.detail>=3){const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.viewportRowToAbsolute(e.row),r=this.wasmTerm.getScrollbackLength();let n=null;if(s<r)n=this.wasmTerm.getScrollbackLine(s);else{const h=s-r;n=this.wasmTerm.getLine(h)}let o=-1;if(n){for(let h=n.length-1;h>=0;h--)if(n[h]&&n[h].codepoint!==0&&n[h].codepoint!==32){o=h;break}}if(o>=0){this.selectionStart={col:0,absoluteRow:s},this.selectionEnd={col:o,absoluteRow:s},this.requestRender();try{const h=this.getSelection();h&&this.copyToClipboard(h)}catch{}this.selectionChangedEmitter.fire()}}}),this.boundContextMenuHandler=i=>{if(this.renderer.getCanvas().getBoundingClientRect(),this.textarea.style.position="fixed",this.textarea.style.left=`${i.clientX}px`,this.textarea.style.top=`${i.clientY}px`,this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.zIndex="1000",this.textarea.style.opacity="0",this.textarea.style.pointerEvents="auto",this.hasSelection()){const s=this.getSelection();this.textarea.value=s,this.textarea.select(),this.textarea.setSelectionRange(0,s.length)}else this.textarea.value="";this.textarea.focus(),setTimeout(()=>{const s=()=>{this.textarea.style.pointerEvents="none",this.textarea.style.zIndex="-10",this.textarea.style.width="0",this.textarea.style.height="0",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.value="",document.removeEventListener("click",s),document.removeEventListener("contextmenu",s),this.textarea.removeEventListener("blur",s)};document.addEventListener("click",s,{once:!0}),document.addEventListener("contextmenu",s,{once:!0}),this.textarea.addEventListener("blur",s,{once:!0})},10)},t.addEventListener("contextmenu",this.boundContextMenuHandler),this.boundClickHandler=i=>{if(this.isSelecting||this.mouseDownTarget&&t.contains(this.mouseDownTarget))return;const s=i.target;t.contains(s)||this.hasSelection()&&this.clearSelection()},document.addEventListener("click",this.boundClickHandler)}markCurrentSelectionDirty(){const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i)}updateAutoScroll(t,i){const e=L.AUTO_SCROLL_EDGE_SIZE;t<e?this.startAutoScroll(-1):t>i-e?this.startAutoScroll(1):this.stopAutoScroll()}startAutoScroll(t){this.autoScrollInterval!==null&&this.autoScrollDirection===t||(this.stopAutoScroll(),this.autoScrollDirection=t,this.autoScrollInterval=setInterval(()=>{if(!this.isSelecting){this.stopAutoScroll();return}const i=L.AUTO_SCROLL_SPEED*this.autoScrollDirection;if(this.terminal.scrollLines(i),this.selectionEnd){const e=this.wasmTerm.getDimensions();if(this.autoScrollDirection<0){const s=this.viewportRowToAbsolute(0);s<this.selectionEnd.absoluteRow&&(this.selectionEnd={col:0,absoluteRow:s})}else{const s=this.viewportRowToAbsolute(e.rows-1);s>this.selectionEnd.absoluteRow&&(this.selectionEnd={col:e.cols-1,absoluteRow:s})}}this.requestRender()},L.AUTO_SCROLL_INTERVAL))}stopAutoScroll(){this.autoScrollInterval!==null&&(clearInterval(this.autoScrollInterval),this.autoScrollInterval=null),this.autoScrollDirection=0}pixelToCell(t,i){const e=this.renderer.getMetrics(),s=Math.floor(t/e.width),r=Math.floor(i/e.height);return{col:Math.max(0,Math.min(s,this.terminal.cols-1)),row:Math.max(0,Math.min(r,this.terminal.rows-1))}}normalizeSelection(){if(!this.selectionStart||!this.selectionEnd)return null;let{col:t,absoluteRow:i}=this.selectionStart,{col:e,absoluteRow:s}=this.selectionEnd;(i>s||i===s&&t>e)&&([t,e]=[e,t],[i,s]=[s,i]);let r=this.absoluteRowToViewport(i),n=this.absoluteRowToViewport(s);const o=this.wasmTerm.getDimensions(),h=o.rows-1;return n<0||r>h?null:(r<0&&(r=0,t=0),n>h&&(n=h,e=o.cols-1),{startCol:t,startRow:r,endCol:e,endRow:n})}getWordAtCell(t,i){const e=this.viewportRowToAbsolute(i),s=this.wasmTerm.getScrollbackLength();let r;try{if(e<s)r=this.wasmTerm.getScrollbackLine(e);else{const c=e-s;r=this.wasmTerm.getLine(c)}}catch{return null}if(!r)return null;const n=c=>{if(!c||c.codepoint===0)return!1;const l=String.fromCodePoint(c.codepoint);return/[\w\-./~@+]/.test(l)};if(!n(r[t]))return null;let o=t;for(;o>0&&n(r[o-1]);)o--;let h=t;for(;h<r.length-1&&n(r[h+1]);)h++;return{startCol:o,endCol:h}}copyToClipboard(t){if(navigator.clipboard&&typeof ClipboardItem<"u")try{const i=new Blob([t],{type:"text/plain"}),e=new ClipboardItem({"text/plain":i});navigator.clipboard.write([e]).catch(s=>{console.warn("ClipboardItem write failed, trying writeText:",s),this.copyWithWriteText(t)});return}catch{}if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(t).catch(i=>{console.warn("Clipboard writeText failed, trying execCommand:",i),this.copyWithExecCommand(t)});return}this.copyWithExecCommand(t)}copyWithWriteText(t){navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(t).catch(i=>{console.warn("Clipboard writeText failed, trying execCommand:",i),this.copyWithExecCommand(t)}):this.copyWithExecCommand(t)}copyWithExecCommand(t){const i=document.activeElement;try{const e=this.textarea;e.value=t,e.style.position="fixed",e.style.left="-9999px",e.style.top="0",e.style.width="1px",e.style.height="1px",e.style.opacity="0",e.focus(),e.select(),e.setSelectionRange(0,t.length);const s=document.execCommand("copy");i&&i.focus(),s||console.warn("execCommand copy failed")}catch(e){console.warn("execCommand copy threw:",e),i&&i.focus()}}requestRender(){}};M.AUTO_SCROLL_EDGE_SIZE=30;M.AUTO_SCROLL_SPEED=3;M.AUTO_SCROLL_INTERVAL=50;let V=M;function H(v,t){const i=String(v||"").trim();if(!i)return t;if(i.startsWith("#")){const s=i.slice(1),r=s.length===3?s.split("").map(n=>n+n).join(""):s;if(/^[0-9a-fA-F]{6}$/.test(r)){const n=Number.parseInt(r,16);return{r:n>>16&255,g:n>>8&255,b:n&255}}}const e=i.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);return e?{r:Number.parseInt(e[1],10),g:Number.parseInt(e[2],10),b:Number.parseInt(e[3],10)}:t}function J(v,t,i){const e=H(i.foreground,{r:212,g:212,b:212}),s=H(i.background,{r:30,g:30,b:30}),r={codepoint:32,fg_r:e.r,fg_g:e.g,fg_b:e.b,bg_r:s.r,bg_g:s.g,bg_b:s.b,fgIsDefault:!1,bgIsDefault:!1,flags:0,width:1,hyperlink_id:0,grapheme_len:0};return Array.from({length:t},()=>Array.from({length:v},()=>({...r})))}const W=class z extends a.TerminalCore{constructor(t={}){const i=t.ghostty??G();super(i,t),this.unicode={get activeVersion(){return"15.1"}},this.selectionChangeEmitter=new a.EventEmitter,this.keyEmitter=new a.EventEmitter,this.renderEmitter=new a.EventEmitter,this.mouseCursorChangeEmitter=new a.EventEmitter,this.onSelectionChange=this.selectionChangeEmitter.event,this.onKey=this.keyEmitter.event,this.onRender=this.renderEmitter.event,this.onMouseCursorChange=this.mouseCursorChangeEmitter.event,this.isOpen=!1,this.writeQueue=[],this.awaitingEcho=!1,this.syncOutputStartTime=void 0,this.currentTheme={...T},this.targetViewportY=0,this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.scrollbarDragStartViewportY=0,this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.SCROLLBAR_HIDE_DELAY_MS=1500,this.SCROLLBAR_FADE_DURATION_MS=200,this.bootstrapCells=null,this.bootstrapDirty=!1,this.renderTick=()=>{if(this.animationFrameId=void 0,this.isDisposed||!this.isOpen)return;if(this.wasmTerm.getMode(2026,!1)){const s=performance.now();if(this.syncOutputStartTime===void 0&&(this.syncOutputStartTime=s),s-this.syncOutputStartTime<z.SYNC_OUTPUT_TIMEOUT_MS){this.requestRender();return}}this.syncOutputStartTime=void 0,this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),this.renderEmitter.fire({start:0,end:this.rows-1});const e=this.wasmTerm.getCursor();(e.x!==this.lastCursorX||e.y!==this.lastCursorY)&&(this.lastCursorX=e.x,this.lastCursorY=e.y,this.cursorMoveEmitter.fire()),this.syncTextareaToCursor(e.x,e.y)},this.lastOsc22Cursor="",this.animateScroll=()=>{if(!this.wasmTerm||this.scrollAnimationStartTime===void 0)return;const e=this.options.smoothScrollDuration??100,s=this.targetViewportY-this.viewportY;if(Math.abs(s)<.01){this.viewportY=this.targetViewportY,this.scrollEmitter.fire(Math.floor(this.viewportY)),this.getScrollbackLength()>0&&this.showScrollbar(),this.scrollAnimationFrame=void 0,this.scrollAnimationStartTime=void 0,this.scrollAnimationStartY=void 0,this.requestRender();return}const o=1-(1/(e/1e3*60))**2;this.viewportY+=s*o;const h=Math.floor(this.viewportY);this.scrollEmitter.fire(h),this.getScrollbackLength()>0&&this.showScrollbar(),this.requestRender(),this.scrollAnimationFrame=requestAnimationFrame(this.animateScroll)},this.handleMouseMove=e=>{if(!(!this.canvas||!this.renderer||!this.wasmTerm)){if(this.isDraggingScrollbar){this.processScrollbarDrag(e);return}if(this.linkDetector){if(this.mouseMoveThrottleTimeout){this.pendingMouseMove=e;return}this.processMouseMove(e),this.mouseMoveThrottleTimeout=window.setTimeout(()=>{if(this.mouseMoveThrottleTimeout=void 0,this.pendingMouseMove){const s=this.pendingMouseMove;this.pendingMouseMove=void 0,this.processMouseMove(s)}},16)}}},this.handleMouseLeave=()=>{var e,s;this.renderer&&this.wasmTerm&&((this.renderer.hoveredHyperlinkId||0)>0&&this.renderer.setHoveredHyperlinkId(0),this.renderer.setHoveredLinkRange(null)),this.currentHoveredLink&&((s=(e=this.currentHoveredLink).hover)==null||s.call(e,!1),this.currentHoveredLink=void 0,this.element&&(this.element.style.cursor="text",this.canvas&&(this.canvas.style.cursor="text")))},this.handleClick=async e=>{if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const s=this.canvas.getBoundingClientRect(),r=Math.floor((e.clientX-s.left)/this.renderer.charWidth),o=Math.floor((e.clientY-s.top)/this.renderer.charHeight),h=this.wasmTerm.getScrollbackLength();let c;const l=this.getViewportY(),u=Math.max(0,Math.floor(l));if(u>0)if(o<u)c=h-u+o;else{const p=o-u;c=h+p}else c=h+o;const d=await this.linkDetector.getLinkAt(r,c);d&&(d.activate(e),(e.ctrlKey||e.metaKey)&&e.preventDefault())},this.handleWheel=e=>{var r,n,o,h,c,l,u;if(e.preventDefault(),e.stopPropagation(),this.customWheelEventHandler&&this.customWheelEventHandler(e))return;if((r=this.wasmTerm)!=null&&r.hasMouseTracking()){(n=this.inputHandler)==null||n.handleWheelEvent(e);return}if(((o=this.wasmTerm)==null?void 0:o.isAlternateScreen())??!1){if((h=this.wasmTerm)!=null&&h.hasMouseTracking()){const m=(c=this.renderer)==null?void 0:c.getMetrics(),g=this.canvas;if(m&&g){const w=g.getBoundingClientRect(),C=Math.max(1,Math.floor((e.clientX-w.left)/m.width)+1),y=Math.max(1,Math.floor((e.clientY-w.top)/m.height)+1),f=e.deltaY<0?64:65;this.dataEmitter.fire(`\x1B[<${f};${C};${y}M`)}return}const d=e.deltaY>0?"down":"up",p=Math.min(Math.abs(Math.round(e.deltaY/33)),5);for(let m=0;m<p;m++)this.dataEmitter.fire(d==="up"?"\x1B[A":"\x1B[B")}else{let d;if(e.deltaMode===WheelEvent.DOM_DELTA_PIXEL){const p=((u=(l=this.renderer)==null?void 0:l.getMetrics())==null?void 0:u.height)??20;d=e.deltaY/p}else e.deltaMode===WheelEvent.DOM_DELTA_LINE?d=e.deltaY:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?d=e.deltaY*this.rows:d=e.deltaY/33;if(d!==0){const p=this.viewportY-d;this.smoothScrollTo(p)}}},this.handleMouseDown=e=>{if(!this.canvas||!this.renderer||!this.wasmTerm)return;const s=this.wasmTerm.getScrollbackLength();if(s===0)return;const r=this.canvas.getBoundingClientRect(),n=e.clientX-r.left,o=e.clientY-r.top,h=r.width,c=r.height,l=8,u=h-l-4,d=4;if(n>=u&&n<=u+l){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const p=c-d*2,m=this.rows,g=s+m,w=Math.max(20,m/g*p),C=this.viewportY/s,y=d+(p-w)*(1-C);if(o>=y&&o<=y+w)this.isDraggingScrollbar=!0,this.scrollbarDragStart=o,this.scrollbarDragStartViewportY=this.viewportY,this.canvas&&(this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none");else{const b=1-(o-d)/p,S=Math.round(b*s);this.scrollToLine(Math.max(0,Math.min(s,S)))}}},this.handleMouseUp=()=>{this.isDraggingScrollbar&&(this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.canvas&&(this.canvas.style.userSelect="",this.canvas.style.webkitUserSelect=""),this.scrollbarVisible&&this.getScrollbackLength()>0&&this.showScrollbar())},this.currentTheme={...T,...t.theme},this.bootstrapBuffer={getLine:e=>{var s;return this.bootstrapCells&&e>=0&&e<this.bootstrapCells.length?this.bootstrapCells[e]:((s=this.wasmTerm)==null?void 0:s.getLine(e))??null},getCursor:()=>{var e;return this.bootstrapCells?{x:0,y:0,visible:!0}:((e=this.wasmTerm)==null?void 0:e.getCursor())??{x:0,y:0,visible:!0}},getDimensions:()=>({cols:this.cols,rows:this.rows}),isRowDirty:e=>{var s;return this.bootstrapDirty?!0:this.bootstrapCells?!1:((s=this.wasmTerm)==null?void 0:s.isRowDirty(e))??!1},needsFullRedraw:()=>{var s;if(this.bootstrapDirty)return!0;if(this.bootstrapCells)return!1;const e=this.wasmTerm;return((s=e==null?void 0:e.needsFullRedraw)==null?void 0:s.call(e))??!1},clearDirty:()=>{var e;this.bootstrapDirty=!1,(e=this.wasmTerm)==null||e.clearDirty()},getGraphemeString:(e,s)=>{var n,o;if(this.bootstrapCells&&e>=0&&e<this.bootstrapCells.length){const h=(n=this.bootstrapCells[e])==null?void 0:n[s];return h?String.fromCodePoint(h.codepoint||32):" "}const r=this.wasmTerm;return((o=r==null?void 0:r.getGraphemeString)==null?void 0:o.call(r,e,s))??" "}}}get viewportY(){return this._viewportY}set viewportY(t){this._viewportY=t}handleOptionChange(t,i,e){if(i!==e)switch(t){case"disableStdin":break;case"cursorBlink":case"cursorStyle":this.renderer&&(this.renderer.setCursorStyle(this.options.cursorStyle),this.renderer.setCursorBlink(this.options.cursorBlink));break;case"theme":if(this.renderer&&this.wasmTerm){const s=i&&typeof i=="object"?i:{},r=Object.keys(s).length>0;this.currentTheme=r?{...this.currentTheme,...s}:{...T},this.renderer.setTheme(this.currentTheme),this.wasmTerm.setColors(this.buildThemeColorsConfig(this.currentTheme))}break;case"fontSize":this.renderer&&(this.renderer.setFontSize(this.options.fontSize),this.handleFontChange());break;case"fontFamily":this.renderer&&(this.renderer.setFontFamily(this.options.fontFamily),this.handleFontChange());break;case"cols":case"rows":this.resize(this.options.cols,this.options.rows);break}}handleFontChange(){if(!this.renderer||!this.wasmTerm||!this.canvas)return;this.selectionManager&&this.selectionManager.clearSelection(),this.renderer.resize(this.cols,this.rows);const t=this.renderer.getMetrics();this.canvas.width=t.width*this.cols,this.canvas.height=t.height*this.rows,this.canvas.style.width=`${t.width*this.cols}px`,this.canvas.style.height=`${t.height*this.rows}px`,this.updateWasmPixelSize(),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}buildThemeColorsConfig(t){return{fgColor:this.parseColorToHex(t.foreground),bgColor:this.parseColorToHex(t.background),cursorColor:this.parseColorToHex(t.cursor),palette:[this.parseColorToHex(t.black),this.parseColorToHex(t.red),this.parseColorToHex(t.green),this.parseColorToHex(t.yellow),this.parseColorToHex(t.blue),this.parseColorToHex(t.magenta),this.parseColorToHex(t.cyan),this.parseColorToHex(t.white),this.parseColorToHex(t.brightBlack),this.parseColorToHex(t.brightRed),this.parseColorToHex(t.brightGreen),this.parseColorToHex(t.brightYellow),this.parseColorToHex(t.brightBlue),this.parseColorToHex(t.brightMagenta),this.parseColorToHex(t.brightCyan),this.parseColorToHex(t.brightWhite)]}}open(t){if(this.isOpen)throw new Error("Terminal is already open");if(this.isDisposed)throw new Error("Terminal has been disposed");this.element=t,this.isOpen=!0;try{t.setAttribute("tabindex","-1"),t.setAttribute("role","textbox"),t.setAttribute("aria-label","Terminal input"),t.setAttribute("aria-multiline","true"),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.cursor="text",t.appendChild(this.canvas),this.textarea=document.createElement("textarea"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.setAttribute("tabindex","0"),this.textarea.setAttribute("aria-label","Terminal input"),this.textarea.style.position="absolute",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.padding="0",this.textarea.style.border="none",this.textarea.style.margin="0",this.textarea.style.opacity="0",this.textarea.style.clipPath="inset(50%)",this.textarea.style.overflow="hidden",this.textarea.style.whiteSpace="nowrap",this.textarea.style.resize="none",t.appendChild(this.textarea);const i=this.textarea;this.canvas.addEventListener("mousedown",o=>{o.preventDefault(),i.focus()}),this.canvas.addEventListener("touchend",o=>{o.preventDefault(),i.focus()}),t.addEventListener("mousedown",o=>{o.target===t&&(o.preventDefault(),i.focus())}),t.addEventListener("focus",()=>{var o;i.focus(),(o=this.wasmTerm)!=null&&o.hasFocusEvents()&&this.dataEmitter.fire("\x1B[I")}),t.addEventListener("blur",()=>{var o;(o=this.wasmTerm)!=null&&o.hasFocusEvents()&&this.dataEmitter.fire("\x1B[O")}),this.renderer=new U(this.canvas,{fontSize:this.options.fontSize,fontFamily:this.options.fontFamily,cursorStyle:this.options.cursorStyle,cursorBlink:this.options.cursorBlink,theme:this.options.theme,devicePixelRatio:this.options.devicePixelRatio}),this.renderer.resize(this.cols,this.rows),this.updateWasmPixelSize();const e=this.canvas,s=this.renderer,r=this.wasmTerm,n={hasMouseTracking:()=>(r==null?void 0:r.hasMouseTracking())??!1,hasSgrMouseMode:()=>(r==null?void 0:r.getMode(1006,!1))??!0,getCellDimensions:()=>({width:s.charWidth,height:s.charHeight}),getCanvasOffset:()=>{const o=e.getBoundingClientRect();return{left:o.left,top:o.top}}};this.inputHandler=new F(this.ghostty,t,o=>{var h;this.options.disableStdin||((h=this.selectionManager)==null||h.clearSelection(),this.awaitingEcho=!0,this.dataEmitter.fire(o))},()=>{this.bellEmitter.fire()},o=>{this.keyEmitter.fire(o)},this.customKeyEventHandler,o=>{var h;return((h=this.wasmTerm)==null?void 0:h.getMode(o,!1))??!1},()=>this.copySelection(),this.textarea,n),this.selectionManager=new V(this,this.renderer,this.wasmTerm,this.textarea),this.renderer.setSelectionManager(this.selectionManager),this.selectionManager.onSelectionChange(()=>{this.selectionChangeEmitter.fire(),this.requestRender()}),this.linkDetector=new O(this),this.linkDetector.registerProvider(new Y(this)),this.linkDetector.registerProvider(new N(this)),t.addEventListener("mousedown",this.handleMouseDown,{capture:!0}),t.addEventListener("mousemove",this.handleMouseMove),t.addEventListener("mouseleave",this.handleMouseLeave),t.addEventListener("click",this.handleClick),document.addEventListener("mouseup",this.handleMouseUp),t.addEventListener("wheel",this.handleWheel,{passive:!1,capture:!0}),this.armBootstrapBlank(),this.renderer.render(this.bootstrapBuffer,!0,this.viewportY,this,this.scrollbarOpacity),this.renderer.setOnRequestRender(()=>this.requestRender()),this.renderTick(),this.options.focusOnOpen!==!1&&this.focus()}catch(i){throw this.isOpen=!1,this.cleanupComponents(),new Error(`Failed to open terminal: ${i}`)}}write(t,i){this.assertOpen(),this.options.convertEol&&typeof t=="string"&&(t=t.replace(/\n/g,`\r
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./terminal-core-0895062a.cjs"),q={KeyA:a.Key.A,KeyB:a.Key.B,KeyC:a.Key.C,KeyD:a.Key.D,KeyE:a.Key.E,KeyF:a.Key.F,KeyG:a.Key.G,KeyH:a.Key.H,KeyI:a.Key.I,KeyJ:a.Key.J,KeyK:a.Key.K,KeyL:a.Key.L,KeyM:a.Key.M,KeyN:a.Key.N,KeyO:a.Key.O,KeyP:a.Key.P,KeyQ:a.Key.Q,KeyR:a.Key.R,KeyS:a.Key.S,KeyT:a.Key.T,KeyU:a.Key.U,KeyV:a.Key.V,KeyW:a.Key.W,KeyX:a.Key.X,KeyY:a.Key.Y,KeyZ:a.Key.Z,Digit1:a.Key.ONE,Digit2:a.Key.TWO,Digit3:a.Key.THREE,Digit4:a.Key.FOUR,Digit5:a.Key.FIVE,Digit6:a.Key.SIX,Digit7:a.Key.SEVEN,Digit8:a.Key.EIGHT,Digit9:a.Key.NINE,Digit0:a.Key.ZERO,Enter:a.Key.ENTER,Escape:a.Key.ESCAPE,Backspace:a.Key.BACKSPACE,Tab:a.Key.TAB,Space:a.Key.SPACE,Minus:a.Key.MINUS,Equal:a.Key.EQUAL,BracketLeft:a.Key.BRACKET_LEFT,BracketRight:a.Key.BRACKET_RIGHT,Backslash:a.Key.BACKSLASH,Semicolon:a.Key.SEMICOLON,Quote:a.Key.QUOTE,Backquote:a.Key.GRAVE,Comma:a.Key.COMMA,Period:a.Key.PERIOD,Slash:a.Key.SLASH,CapsLock:a.Key.CAPS_LOCK,F1:a.Key.F1,F2:a.Key.F2,F3:a.Key.F3,F4:a.Key.F4,F5:a.Key.F5,F6:a.Key.F6,F7:a.Key.F7,F8:a.Key.F8,F9:a.Key.F9,F10:a.Key.F10,F11:a.Key.F11,F12:a.Key.F12,PrintScreen:a.Key.PRINT_SCREEN,ScrollLock:a.Key.SCROLL_LOCK,Pause:a.Key.PAUSE,Insert:a.Key.INSERT,Home:a.Key.HOME,PageUp:a.Key.PAGE_UP,Delete:a.Key.DELETE,End:a.Key.END,PageDown:a.Key.PAGE_DOWN,ArrowRight:a.Key.RIGHT,ArrowLeft:a.Key.LEFT,ArrowDown:a.Key.DOWN,ArrowUp:a.Key.UP,NumLock:a.Key.NUM_LOCK,NumpadDivide:a.Key.KP_DIVIDE,NumpadMultiply:a.Key.KP_MULTIPLY,NumpadSubtract:a.Key.KP_MINUS,NumpadAdd:a.Key.KP_PLUS,NumpadEnter:a.Key.KP_ENTER,Numpad1:a.Key.KP_1,Numpad2:a.Key.KP_2,Numpad3:a.Key.KP_3,Numpad4:a.Key.KP_4,Numpad5:a.Key.KP_5,Numpad6:a.Key.KP_6,Numpad7:a.Key.KP_7,Numpad8:a.Key.KP_8,Numpad9:a.Key.KP_9,Numpad0:a.Key.KP_0,NumpadDecimal:a.Key.KP_PERIOD,IntlBackslash:a.Key.INTL_BACKSLASH,ContextMenu:a.Key.CONTEXT_MENU,F13:a.Key.F13,F14:a.Key.F14,F15:a.Key.F15,F16:a.Key.F16,F17:a.Key.F17,F18:a.Key.F18,F19:a.Key.F19,F20:a.Key.F20,F21:a.Key.F21,F22:a.Key.F22,F23:a.Key.F23,F24:a.Key.F24},F=class T{constructor(t,i,e,s,r,n,o,h,c,l){this.keydownListener=null,this.keypressListener=null,this.pasteListener=null,this.beforeInputListener=null,this.compositionStartListener=null,this.compositionUpdateListener=null,this.compositionEndListener=null,this.mousedownListener=null,this.mouseupListener=null,this.mousemoveListener=null,this.wheelListener=null,this.isComposing=!1,this.compositionJustEnded=!1,this.pendingKeyAfterComposition=null,this.isDisposed=!1,this.mouseButtonsPressed=0,this.lastKeyDownData=null,this.lastKeyDownTime=0,this.lastPasteData=null,this.lastPasteTime=0,this.lastPasteSource=null,this.lastCompositionData=null,this.lastCompositionTime=0,this.lastBeforeInputData=null,this.lastBeforeInputTime=0,this.syncedEncoderOptions=new Map,this.decoder=new TextDecoder,this.encoder=t.createKeyEncoder(),this.encoder.setOption(a.KeyEncoderOption.ALT_ESC_PREFIX,!0),this.container=i,this.inputElement=c,this.onDataCallback=e,this.onBellCallback=s,this.onKeyCallback=r,this.customKeyEventHandler=n,this.getModeCallback=o,this.onCopyCallback=h,this.mouseConfig=l,this.attach()}setCustomKeyEventHandler(t){this.customKeyEventHandler=t}attach(){typeof this.container.hasAttribute=="function"&&typeof this.container.setAttribute=="function"&&(this.container.hasAttribute("tabindex")||this.container.setAttribute("tabindex","0"),this.container.style&&(this.container.style.outline="none")),this.keydownListener=this.handleKeyDown.bind(this),this.container.addEventListener("keydown",this.keydownListener),this.pasteListener=this.handlePaste.bind(this),this.container.addEventListener("paste",this.pasteListener),this.inputElement&&this.inputElement!==this.container&&this.inputElement.addEventListener("paste",this.pasteListener),this.inputElement&&(this.beforeInputListener=this.handleBeforeInput.bind(this),this.inputElement.addEventListener("beforeinput",this.beforeInputListener));const t=this.inputElement||this.container;this.compositionStartListener=this.handleCompositionStart.bind(this),t.addEventListener("compositionstart",this.compositionStartListener),this.compositionUpdateListener=this.handleCompositionUpdate.bind(this),t.addEventListener("compositionupdate",this.compositionUpdateListener),this.compositionEndListener=this.handleCompositionEnd.bind(this),t.addEventListener("compositionend",this.compositionEndListener),this.mousedownListener=this.handleMouseDown.bind(this),this.container.addEventListener("mousedown",this.mousedownListener),this.mouseupListener=this.handleMouseUp.bind(this),this.container.addEventListener("mouseup",this.mouseupListener),this.mousemoveListener=this.handleMouseMove.bind(this),this.container.addEventListener("mousemove",this.mousemoveListener),this.wheelListener=this.handleWheel.bind(this),this.container.addEventListener("wheel",this.wheelListener,{passive:!1})}mapKeyCode(t){return q[t]??null}syncEncoderOption(t,i){this.syncedEncoderOptions.get(t)!==i&&(this.encoder.setOption(t,i),this.syncedEncoderOptions.set(t,i))}extractModifiers(t){let i=a.Mods.NONE;return t.shiftKey&&(i|=a.Mods.SHIFT),t.ctrlKey&&(i|=a.Mods.CTRL),t.altKey&&(i|=a.Mods.ALT),t.metaKey&&(i|=a.Mods.SUPER),i}handleKeyDown(t){if(this.isDisposed||t.isComposing||t.keyCode===229)return;if(this.isComposing){this.pendingKeyAfterComposition=t.key,t.preventDefault();return}if(this.compositionJustEnded){this.compositionJustEnded=!1;return}if(this.onKeyCallback&&this.onKeyCallback({key:t.key,domEvent:t}),this.customKeyEventHandler&&this.customKeyEventHandler(t)){t.preventDefault();return}if((t.ctrlKey||t.metaKey)&&t.code==="KeyV"){const n=this.encoder.encode({key:a.Key.V,mods:t.ctrlKey?a.Mods.CTRL:a.Mods.SUPER,action:a.KeyAction.PRESS});n.length>0&&this.onDataCallback(new TextDecoder().decode(n));return}if(t.metaKey&&t.code==="KeyC"){this.onCopyCallback&&this.onCopyCallback()&&t.preventDefault();return}const i=this.mapKeyCode(t.code);if(i===null)return;const e=this.extractModifiers(t);let s;if(t.key.length>0&&t.key!=="Dead"&&t.key!=="Unidentified"){const n=t.key.codePointAt(0),o=n!==void 0&&n>65535?2:1;t.key.length===o&&(t.altKey&&n!==void 0&&n>127?t.code.startsWith("Key")&&t.code.length===4&&(s=t.code[3].toLowerCase()):s=t.key)}this.getModeCallback&&(this.syncEncoderOption(a.KeyEncoderOption.CURSOR_KEY_APPLICATION,this.getModeCallback(1)),this.syncEncoderOption(a.KeyEncoderOption.KEYPAD_KEY_APPLICATION,this.getModeCallback(66))),t.preventDefault(),t.stopPropagation();let r;try{const n=this.encoder.encode({action:a.KeyAction.PRESS,key:i,mods:e,utf8:s});r=n.length===0?"":this.decoder.decode(n)}catch(n){console.warn("Failed to encode key:",t.code,n);return}r.length>0&&(this.onDataCallback(r),this.recordKeyDownData(r))}handlePaste(t){if(this.isDisposed)return;const i=t.clipboardData;if(!i)return;const e=i.getData("text/plain");e&&(t.preventDefault(),t.stopPropagation(),!this.shouldIgnorePasteEvent(e,"paste")&&(this.emitPasteData(e),this.recordPasteData(e,"paste")))}handleBeforeInput(t){if(this.isDisposed||this.isComposing||t.isComposing)return;const i=t.inputType,e=t.data??"";let s=null;switch(i){case"insertText":case"insertReplacementText":s=e.length>0?e.replace(/\n/g,"\r"):null;break;case"insertLineBreak":case"insertParagraph":s="\r";break;case"deleteContentBackward":s="";break;case"deleteContentForward":s="\x1B[3~";break;case"insertFromPaste":if(!e)return;if(this.shouldIgnorePasteEvent(e,"beforeinput")){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),t.stopPropagation(),this.emitPasteData(e),this.recordPasteData(e,"beforeinput");return;default:return}if(s){if(this.shouldIgnoreBeforeInput(s)){t.preventDefault(),t.stopPropagation();return}if(e&&this.shouldIgnoreBeforeInputFromComposition(e)){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),t.stopPropagation(),this.onDataCallback(s),e&&this.recordBeforeInputData(e)}}handleCompositionStart(t){this.isDisposed||(this.isComposing=!0)}handleCompositionUpdate(t){this.isDisposed}handleCompositionEnd(t){if(this.isDisposed)return;this.isComposing=!1;const i=t.data;if(i&&i.length>0){if(this.shouldIgnoreCompositionEnd(i)){this.cleanupCompositionTextNodes(),this.processPendingKeyAfterComposition();return}this.onDataCallback(i),this.recordCompositionData(i)}this.cleanupCompositionTextNodes(),this.processPendingKeyAfterComposition()}processPendingKeyAfterComposition(){if(this.pendingKeyAfterComposition){const t=this.pendingKeyAfterComposition;this.pendingKeyAfterComposition=null,this.onDataCallback(t)}}cleanupCompositionTextNodes(){if(this.container&&this.container.childNodes)for(let t=this.container.childNodes.length-1;t>=0;t--){const i=this.container.childNodes[t];i.nodeType===3&&this.container.removeChild(i)}}pixelToCell(t){if(!this.mouseConfig)return null;const i=this.mouseConfig.getCellDimensions(),e=this.mouseConfig.getCanvasOffset();if(i.width<=0||i.height<=0)return null;const s=t.clientX-e.left,r=t.clientY-e.top,n=Math.floor(s/i.width)+1,o=Math.floor(r/i.height)+1;return{col:Math.max(1,n),row:Math.max(1,o)}}getMouseModifiers(t){let i=0;return t.shiftKey&&(i|=4),t.metaKey&&(i|=8),t.ctrlKey&&(i|=16),i}encodeMouseSGR(t,i,e,s,r){return`\x1B[<${t+r};${i};${e}${s?"m":"M"}`}encodeMouseX10(t,i,e,s){const r=t+s+32,n=String.fromCharCode(Math.min(i+32,255)),o=String.fromCharCode(Math.min(e+32,255));return`\x1B[M${String.fromCharCode(r)}${n}${o}`}sendMouseEvent(t,i,e,s,r){var c,l;const n=this.getMouseModifiers(r),o=((l=(c=this.mouseConfig)==null?void 0:c.hasSgrMouseMode)==null?void 0:l.call(c))??!0;let h;if(o)h=this.encodeMouseSGR(t,i,e,s,n);else{const u=s?3:t;h=this.encodeMouseX10(u,i,e,n)}this.onDataCallback(h)}handleMouseDown(t){var s;if(this.isDisposed||!((s=this.mouseConfig)!=null&&s.hasMouseTracking()))return;const i=this.pixelToCell(t);if(!i)return;const e=t.button;this.mouseButtonsPressed|=1<<e,this.sendMouseEvent(e,i.col,i.row,!1,t)}handleMouseUp(t){var s;if(this.isDisposed||!((s=this.mouseConfig)!=null&&s.hasMouseTracking()))return;const i=this.pixelToCell(t);if(!i)return;const e=t.button;this.mouseButtonsPressed&=~(1<<e),this.sendMouseEvent(e,i.col,i.row,!0,t)}handleMouseMove(t){var n,o,h;if(this.isDisposed||!((n=this.mouseConfig)!=null&&n.hasMouseTracking()))return;const i=((o=this.getModeCallback)==null?void 0:o.call(this,1002))??!1,e=((h=this.getModeCallback)==null?void 0:h.call(this,1003))??!1;if(!i&&!e||i&&!e&&this.mouseButtonsPressed===0)return;const s=this.pixelToCell(t);if(!s)return;let r=32;this.mouseButtonsPressed&1?r+=0:this.mouseButtonsPressed&2?r+=1:this.mouseButtonsPressed&4&&(r+=2),this.sendMouseEvent(r,s.col,s.row,!1,t)}handleWheel(t){var i;this.isDisposed||(i=this.mouseConfig)!=null&&i.hasMouseTracking()&&(this.sendWheelMouseEvent(t),t.preventDefault())}handleWheelEvent(t){this.isDisposed||this.sendWheelMouseEvent(t)}sendWheelMouseEvent(t){const i=this.pixelToCell(t);if(!i)return;const e=t.deltaY<0?64:65;this.sendMouseEvent(e,i.col,i.row,!1,t)}emitPasteData(t){var e;((e=this.getModeCallback)==null?void 0:e.call(this,2004))??!1?this.onDataCallback("\x1B[200~"+t+"\x1B[201~"):this.onDataCallback(t)}recordKeyDownData(t){this.lastKeyDownData=t,this.lastKeyDownTime=this.getNow()}recordPasteData(t,i){this.lastPasteData=t,this.lastPasteTime=this.getNow(),this.lastPasteSource=i}shouldIgnoreBeforeInput(t){if(!this.lastKeyDownData)return!1;const e=this.getNow()-this.lastKeyDownTime<T.BEFORE_INPUT_IGNORE_MS&&this.lastKeyDownData===t;return this.lastKeyDownData=null,e}shouldIgnoreBeforeInputFromComposition(t){if(!this.lastCompositionData)return!1;const e=this.getNow()-this.lastCompositionTime<T.BEFORE_INPUT_IGNORE_MS&&this.lastCompositionData===t;return e&&(this.lastCompositionData=null),e}shouldIgnoreCompositionEnd(t){if(!this.lastBeforeInputData)return!1;const e=this.getNow()-this.lastBeforeInputTime<T.BEFORE_INPUT_IGNORE_MS&&this.lastBeforeInputData===t;return e&&(this.lastBeforeInputData=null),e}recordBeforeInputData(t){this.lastBeforeInputData=t,this.lastBeforeInputTime=this.getNow()}recordCompositionData(t){this.lastCompositionData=t,this.lastCompositionTime=this.getNow()}shouldIgnorePasteEvent(t,i){if(!this.lastPasteData||this.lastPasteSource===i)return!1;const s=this.getNow()-this.lastPasteTime<T.BEFORE_INPUT_IGNORE_MS&&this.lastPasteData===t;return s&&(this.lastPasteData=null,this.lastPasteSource=null),s}getNow(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}dispose(){if(this.isDisposed)return;this.keydownListener&&(this.container.removeEventListener("keydown",this.keydownListener),this.keydownListener=null),this.keypressListener&&(this.container.removeEventListener("keypress",this.keypressListener),this.keypressListener=null),this.pasteListener&&(this.container.removeEventListener("paste",this.pasteListener),this.inputElement&&this.inputElement!==this.container&&this.inputElement.removeEventListener("paste",this.pasteListener),this.pasteListener=null),this.beforeInputListener&&this.inputElement&&(this.inputElement.removeEventListener("beforeinput",this.beforeInputListener),this.beforeInputListener=null);const t=this.inputElement||this.container;this.compositionStartListener&&(t.removeEventListener("compositionstart",this.compositionStartListener),this.compositionStartListener=null),this.compositionUpdateListener&&(t.removeEventListener("compositionupdate",this.compositionUpdateListener),this.compositionUpdateListener=null),this.compositionEndListener&&(t.removeEventListener("compositionend",this.compositionEndListener),this.compositionEndListener=null),this.mousedownListener&&(this.container.removeEventListener("mousedown",this.mousedownListener),this.mousedownListener=null),this.mouseupListener&&(this.container.removeEventListener("mouseup",this.mouseupListener),this.mouseupListener=null),this.mousemoveListener&&(this.container.removeEventListener("mousemove",this.mousemoveListener),this.mousemoveListener=null),this.wheelListener&&(this.container.removeEventListener("wheel",this.wheelListener),this.wheelListener=null),this.isDisposed=!0}isActive(){return!this.isDisposed}};F.BEFORE_INPUT_IGNORE_MS=100;let B=F;class O{constructor(t){this.terminal=t,this.providers=[],this.linkCache=new Map,this.scannedRows=new Set}registerProvider(t){this.providers.push(t),this.invalidateCache()}async getLinkAt(t,i){const e=this.terminal.buffer.active.getLine(i);if(!(!e||t<0||t>=e.length||!e.getCell(t))){for(const r of this.linkCache.values())if(this.isPositionInLink(t,i,r))return r;this.scannedRows.has(i)||await this.scanRow(i);for(const r of this.linkCache.values())if(this.isPositionInLink(t,i,r))return r}}async scanRow(t){this.scannedRows.add(t);const i=[];for(const e of this.providers){const s=await new Promise(r=>{e.provideLinks(t,r)});s&&i.push(...s)}for(const e of i)this.cacheLink(e)}cacheLink(t){const{start:i,end:e}=t.range,s=`r${i.y}:${i.x}-${e.x}`;this.linkCache.has(s)||this.linkCache.set(s,t)}isPositionInLink(t,i,e){const{start:s,end:r}=e.range;return i<s.y||i>r.y?!1:s.y===r.y?t>=s.x&&t<=r.x:i===s.y?t>=s.x:i===r.y?t<=r.x:!0}invalidateCache(){this.linkCache.clear(),this.scannedRows.clear()}invalidateRows(t,i){for(let s=t;s<=i;s++)this.scannedRows.delete(s);const e=[];for(const[s,r]of this.linkCache.entries()){const{start:n,end:o}=r.range;(n.y>=t&&n.y<=i||o.y>=t&&o.y<=i||n.y<t&&o.y>i)&&e.push(s)}for(const s of e)this.linkCache.delete(s)}dispose(){var t;this.linkCache.clear(),this.scannedRows.clear();for(const i of this.providers)(t=i.dispose)==null||t.call(i);this.providers=[]}}class Y{constructor(t){this.terminal=t}provideLinks(t,i){const e=[],s=new Set,r=this.terminal.buffer.active.getLine(t);if(!r){i(void 0);return}for(let n=0;n<r.length;n++){if(s.has(n))continue;const o=r.getCell(n);if(!o||o.getHyperlinkId()===0||!this.terminal.wasmTerm)continue;const c=this.terminal.wasmTerm.getScrollbackLength(),l=t-c;let u;if(l<0?u=this.terminal.wasmTerm.getScrollbackHyperlinkUri(t,n):u=this.terminal.wasmTerm.getHyperlinkUri(l,n),u){let d=n;for(let f=n+1;f<r.length;f++){const g=r.getCell(f);if(!g||g.getHyperlinkId()===0||(l<0?this.terminal.wasmTerm.getScrollbackHyperlinkUri(t,f):this.terminal.wasmTerm.getHyperlinkUri(l,f))!==u)break;d=f}for(let f=n;f<=d;f++)s.add(f);const p={start:{x:n,y:t},end:{x:d,y:t}};e.push({text:u,range:p,activate:f=>{(f.ctrlKey||f.metaKey)&&window.open(u,"_blank","noopener,noreferrer")}})}}i(e.length>0?e:void 0)}findLinkRange(t,i,e){const s=this.terminal.buffer.active;let r=i,n=e;for(;n>0;){const l=s.getLine(r);if(!l)break;const u=l.getCell(n-1);if(!u||u.getHyperlinkId()!==t)break;n--}if(n===0&&r>0){let l=r-1;for(;l>=0;){const u=s.getLine(l);if(!u||u.length===0)break;const d=u.getCell(u.length-1);if(!d||d.getHyperlinkId()!==t)break;r=l,n=0;for(let p=u.length-1;p>=0;p--){const f=u.getCell(p);if(!f||f.getHyperlinkId()!==t){n=p+1;break}}if(n===0)l--;else break}}let o=i,h=e;const c=s.getLine(o);if(c){for(;h<c.length-1;){const l=c.getCell(h+1);if(!l||l.getHyperlinkId()!==t)break;h++}if(h===c.length-1){let l=o+1;const u=s.length;for(;l<u;){const d=s.getLine(l);if(!d||d.length===0)break;const p=d.getCell(0);if(!p||p.getHyperlinkId()!==t)break;o=l,h=0;for(let f=0;f<d.length;f++){const g=d.getCell(f);if(!g)break;if(g.getHyperlinkId()!==t){h=f-1;break}h=f}if(h===d.length-1)l++;else break}}}return{start:{x:n,y:r},end:{x:h,y:o}}}dispose(){}}const K=class E{constructor(t){this.terminal=t}provideLinks(t,i){const e=[],s=this.terminal.buffer.active.getLine(t);if(!s){i(void 0);return}const r=this.lineToText(s);E.URL_REGEX.lastIndex=0;let n=E.URL_REGEX.exec(r);for(;n!==null;){let o=n[0];const h=n.index;let c=n.index+o.length-1;const l=o.replace(E.TRAILING_PUNCTUATION,"");for(l.length<o.length&&(o=l,c=h+o.length-1);o.endsWith(")");){const u=o.split("(").length-1;if(o.split(")").length-1>u)o=o.slice(0,-1),c--;else break}o.length>8&&e.push({text:o,range:{start:{x:h,y:t},end:{x:c,y:t}},activate:u=>{(u.ctrlKey||u.metaKey)&&window.open(o,"_blank","noopener,noreferrer")}}),n=E.URL_REGEX.exec(r)}i(e.length>0?e:void 0)}lineToText(t){const i=[];for(let e=0;e<t.length;e++){const s=t.getCell(e);if(!s){i.push(" ");continue}const r=s.getCodepoint();r===0||r<32?i.push(" "):i.push(String.fromCodePoint(r))}return i.join("")}dispose(){}};K.URL_REGEX=/(?:https?:\/\/|mailto:|ftp:\/\/|ssh:\/\/|git:\/\/|tel:|magnet:|gemini:\/\/|gopher:\/\/|news:)[\w\-.~:\/?#@!$&*+,;=%()]+/gi;K.TRAILING_PUNCTUATION=/[.,;!?\]]+$/;let N=K;const $=[773,781,782,784,786,829,830,831,838,842,843,844,848,849,850,855,859,867,868,869,870,871,872,873,874,875,876,877,878,879,1155,1156,1157,1158,1159,1426,1427,1428,1429,1431,1432,1433,1436,1437,1438,1439,1440,1441,1448,1449,1451,1452,1455,1476,1552,1553,1554,1555,1556,1557,1558,1559,1623,1624,1625,1626,1627,1629,1630,1750,1751,1752,1753,1754,1755,1756,1759,1760,1761,1762,1764,1767,1768,1771,1772,1840,1842,1843,1845,1846,1850,1853,1855,1856,1857,1859,1861,1863,1865,1866,2027,2028,2029,2030,2031,2032,2033,2035,2070,2071,2072,2073,2075,2076,2077,2078,2079,2080,2081,2082,2083,2085,2086,2087,2089,2090,2091,2092,2093,2385,2387,2388,3970,3971,3974,3975,4957,4958,4959,6109,6458,6679,6773,6774,6775,6776,6777,6778,6779,6780,7019,7021,7022,7023,7024,7025,7026,7027,7376,7377,7378,7386,7387,7392,7616,7617,7619,7620,7621,7622,7623,7624,7625,7627,7628,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643,7644,7645,7646,7647,7648,7649,7650,7651,7652,7653,7654,7678,8400,8401,8404,8405,8406,8407,8411,8412,8417,8423,8425,8432,11503,11504,11505,11744,11745,11746,11747,11748,11749,11750,11751,11752,11753,11754,11755,11756,11757,11758,11759,11760,11761,11762,11763,11764,11765,11766,11767,11768,11769,11770,11771,11772,11773,11774,11775,42607,42620,42621,42736,42737,43232,43233,43234,43235,43236,43237,43238,43239,43240,43241,43242,43243,43244,43245,43246,43247,43248,43249,43696,43698,43699,43703,43704,43710,43711,43713,65056,65057,65058,65059,65060,65061,65062,68111,68152,119173,119174,119175,119176,119177,119210,119211,119212,119213,119362,119363,119364],Q=new Map($.map((v,t)=>[v,t]));function D(v){return Q.get(v)??-1}const X=1109742,x={foreground:"#d4d4d4",background:"#1e1e1e",cursor:"#ffffff",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"};function _(v,t){return v.width===t.width&&v.height===t.height&&v.format===t.format&&v.dataPtr===t.data.byteOffset&&v.dataLen===t.data.length}class U{constructor(t,i={}){this.cursorVisible=!0,this.lastCursorPosition={x:0,y:0},this.onRequestRender=null,this.lastViewportY=0,this.currentBuffer=null,this.kittyImageCache=new Map,this.kittyVirtualPlacements=new Map,this.currentDirectPlacements=[],this.lastKittyDirectSigs=new Map,this.kittyDamagedRows=new Set,this.currentRenderBuffer=null,this.currentKittyGraphics=null,this.currentSelectionCoords=null,this.hoveredHyperlinkId=0,this.previousHoveredHyperlinkId=0,this.hoveredLinkRange=null,this.previousHoveredLinkRange=null,this.canvas=t;const e=t.getContext("2d",{alpha:!0});if(!e)throw new Error("Failed to get 2D rendering context");this.ctx=e,this.fontSize=i.fontSize??15,this.fontFamily=i.fontFamily??"monospace",this.cursorStyle=i.cursorStyle??"block",this.cursorBlink=i.cursorBlink??!1,this.theme={...x,...i.theme},this.devicePixelRatio=i.devicePixelRatio??window.devicePixelRatio??1,this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite],this.metrics=this.measureFont(),this.cursorBlink&&this.startCursorBlink()}buildFontString(t=""){const i=this.fontFamily.split(",").map(e=>{const s=e.trim();return s.startsWith('"')||s.startsWith("'")||!s.includes(" ")?s:`"${s}"`}).join(", ");return`${t}${this.fontSize}px ${i}`}measureFont(){const i=document.createElement("canvas").getContext("2d");i.font=this.buildFontString();const e=i.measureText("M"),s=e.fontBoundingBoxAscent||e.actualBoundingBoxAscent||this.fontSize*.8,r=e.fontBoundingBoxDescent||e.actualBoundingBoxDescent||this.fontSize*.2,n=this.devicePixelRatio,o=Math.ceil(e.width*n)/n,h=Math.ceil((s+r)*n)/n,c=Math.ceil(s*n)/n;return{width:o,height:h,baseline:c}}remeasureFont(){this.metrics=this.measureFont()}rgbToCSS(t,i,e){return`rgb(${t}, ${i}, ${e})`}resize(t,i){const e=t*this.metrics.width,s=i*this.metrics.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${s}px`,this.canvas.width=e*this.devicePixelRatio,this.canvas.height=s*this.devicePixelRatio,this.ctx.scale(this.devicePixelRatio,this.devicePixelRatio),this.ctx.textBaseline="alphabetic",this.ctx.textAlign="left",this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,e,s)}render(t,i=!1,e=0,s,r=1){var y;this.currentBuffer=t,this.currentRenderBuffer=t;const n=t.getCursor(),o=t.getDimensions();this.precomputeKittyState(t,o.rows);const h=s?s.getScrollbackLength():0;(y=t.needsFullRedraw)!=null&&y.call(t)&&(i=!0),(this.canvas.width!==o.cols*this.metrics.width*this.devicePixelRatio||this.canvas.height!==o.rows*this.metrics.height*this.devicePixelRatio)&&(this.resize(o.cols,o.rows),i=!0),e!==this.lastViewportY&&(i=!0,this.lastViewportY=e);const l=n.x!==this.lastCursorPosition.x||n.y!==this.lastCursorPosition.y;if(l||this.cursorBlink){if(!i&&!t.isRowDirty(n.y)){const m=t.getLine(n.y);m&&this.renderLine(m,n.y,o.cols)}if(l&&!i){const m=t.getLine(this.lastCursorPosition.y);m&&this.renderLine(m,this.lastCursorPosition.y,o.cols)}}const u=this.selectionManager&&this.selectionManager.hasSelection(),d=new Set;if(this.currentSelectionCoords=u?this.selectionManager.getSelectionCoords():null,this.currentSelectionCoords){const m=this.currentSelectionCoords;for(let b=m.startRow;b<=m.endRow;b++)d.add(b)}if(this.selectionManager){const m=this.selectionManager.getDirtySelectionRows();if(m.size>0){for(const b of m)d.add(b);this.selectionManager.clearDirtySelectionRows()}}const p=new Set,f=this.hoveredHyperlinkId!==this.previousHoveredHyperlinkId,g=JSON.stringify(this.hoveredLinkRange)!==JSON.stringify(this.previousHoveredLinkRange);if(f){for(let m=0;m<o.rows;m++){let b=null;if(e>0)if(m<e&&s){const S=h-Math.floor(e)+m;b=s.getScrollbackLine(S)}else{const S=m-Math.floor(e);b=t.getLine(S)}else b=t.getLine(m);if(b){for(const S of b)if(S.hyperlink_id===this.hoveredHyperlinkId||S.hyperlink_id===this.previousHoveredHyperlinkId){p.add(m);break}}}this.previousHoveredHyperlinkId=this.hoveredHyperlinkId}if(g){if(this.previousHoveredLinkRange)for(let m=this.previousHoveredLinkRange.startY;m<=this.previousHoveredLinkRange.endY;m++)p.add(m);if(this.hoveredLinkRange)for(let m=this.hoveredLinkRange.startY;m<=this.hoveredLinkRange.endY;m++)p.add(m);this.previousHoveredLinkRange=this.hoveredLinkRange}let w=!1;const C=new Set;for(let m=0;m<o.rows;m++)(e>0?!0:i||t.isRowDirty(m)||d.has(m)||p.has(m)||this.kittyDamagedRows.has(m))&&(C.add(m),m>0&&C.add(m-1),m<o.rows-1&&C.add(m+1));for(let m=0;m<o.rows;m++){if(!C.has(m))continue;w=!0;let b=null;if(e>0)if(m<e&&s){const S=h-Math.floor(e)+m;b=s.getScrollbackLine(S)}else{const S=e>0?m-Math.floor(e):m;b=t.getLine(S)}else b=t.getLine(m);b&&this.renderLine(b,m,o.cols)}if(this.currentDirectPlacements.length>0&&w&&this.renderKittyImages(),e===0&&n.visible&&this.cursorVisible){const m=n.style??this.cursorStyle;this.renderCursor(n.x,n.y,m)}s&&r>0&&this.renderScrollbar(e,h,o.rows,r),this.lastCursorPosition={x:n.x,y:n.y},t.clearDirty()}renderLine(t,i,e){const s=i*this.metrics.height,r=e*this.metrics.width;this.ctx.clearRect(0,s,r,this.metrics.height),this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,s,r,this.metrics.height);for(let n=0;n<t.length;n++){const o=t[n];o.width!==0&&this.renderCellBackground(o,n,i)}for(let n=0;n<t.length;n++){const o=t[n];o.width!==0&&this.renderCellText(o,n,i)}}renderCellBackground(t,i,e){const s=i*this.metrics.width,r=e*this.metrics.height,n=this.metrics.width*t.width;if(this.isInSelection(i,e)){this.ctx.fillStyle=this.theme.selectionBackground,this.ctx.fillRect(s,r,n,this.metrics.height);return}let h=t.bg_r,c=t.bg_g,l=t.bg_b;t.flags&a.CellFlags.INVERSE&&(h=t.fg_r,c=t.fg_g,l=t.fg_b),t.flags&a.CellFlags.INVERSE?(this.ctx.fillStyle=t.fgIsDefault?this.theme.foreground:this.rgbToCSS(h,c,l),this.ctx.fillRect(s,r,n,this.metrics.height)):t.bgIsDefault||(this.ctx.fillStyle=this.rgbToCSS(h,c,l),this.ctx.fillRect(s,r,n,this.metrics.height))}renderCellText(t,i,e,s){var C;const r=i*this.metrics.width,n=e*this.metrics.height,o=this.metrics.width*t.width;if(t.codepoint===X&&this.renderPlaceholderCell(t,i,e)||t.flags&a.CellFlags.INVISIBLE)return;const h=this.isInSelection(i,e);let c="";t.flags&a.CellFlags.ITALIC&&(c+="italic "),t.flags&a.CellFlags.BOLD&&(c+="bold "),this.ctx.font=this.buildFontString(c);let l=t.fg_r,u=t.fg_g,d=t.fg_b;if(t.flags&a.CellFlags.INVERSE&&(l=t.bg_r,u=t.bg_g,d=t.bg_b),s)this.ctx.fillStyle=s;else if(h)this.ctx.fillStyle=this.theme.selectionForeground;else{const y=t.flags&a.CellFlags.INVERSE?t.bgIsDefault:t.fgIsDefault,m=t.flags&a.CellFlags.INVERSE?this.theme.background:this.theme.foreground;this.ctx.fillStyle=y?m:this.rgbToCSS(l,u,d)}t.flags&a.CellFlags.FAINT&&(this.ctx.globalAlpha=.5);const p=r,f=n+this.metrics.baseline;let g;t.grapheme_len>0&&((C=this.currentBuffer)!=null&&C.getGraphemeString)?g=this.currentBuffer.getGraphemeString(e,i):g=String.fromCodePoint(t.codepoint||32);const w=t.codepoint||32;if(this.renderBlockChar(w,r,n,o)||this.renderPowerlineGlyph(w,r,n,o)||this.ctx.fillText(g,p,f),t.flags&a.CellFlags.FAINT&&(this.ctx.globalAlpha=1),t.flags&a.CellFlags.UNDERLINE){const y=n+this.metrics.baseline+2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,y),this.ctx.lineTo(r+o,y),this.ctx.stroke()}if(t.flags&a.CellFlags.STRIKETHROUGH){const y=n+this.metrics.height/2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,y),this.ctx.lineTo(r+o,y),this.ctx.stroke()}if(t.hyperlink_id>0&&t.hyperlink_id===this.hoveredHyperlinkId){const m=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,m),this.ctx.lineTo(r+o,m),this.ctx.stroke()}if(this.hoveredLinkRange){const y=this.hoveredLinkRange;if(e===y.startY&&i>=y.startX&&(e<y.endY||i<=y.endX)||e>y.startY&&e<y.endY||e===y.endY&&i<=y.endX&&(e>y.startY||i>=y.startX)){const b=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(r,b),this.ctx.lineTo(r+o,b),this.ctx.stroke()}}}renderBlockChar(t,i,e,s){const r=this.metrics.height;switch(t){case 9600:return this.ctx.fillRect(i,e,s,r/2),!0;case 9601:return this.ctx.fillRect(i,e+r*7/8,s,r/8),!0;case 9602:return this.ctx.fillRect(i,e+r*3/4,s,r/4),!0;case 9603:return this.ctx.fillRect(i,e+r*5/8,s,r*3/8),!0;case 9604:return this.ctx.fillRect(i,e+r/2,s,r/2),!0;case 9605:return this.ctx.fillRect(i,e+r*3/8,s,r*5/8),!0;case 9606:return this.ctx.fillRect(i,e+r/4,s,r*3/4),!0;case 9607:return this.ctx.fillRect(i,e+r/8,s,r*7/8),!0;case 9608:return this.ctx.fillRect(i,e,s,r),!0;case 9609:return this.ctx.fillRect(i,e,s*7/8,r),!0;case 9610:return this.ctx.fillRect(i,e,s*3/4,r),!0;case 9611:return this.ctx.fillRect(i,e,s*5/8,r),!0;case 9612:return this.ctx.fillRect(i,e,s/2,r),!0;case 9613:return this.ctx.fillRect(i,e,s*3/8,r),!0;case 9614:return this.ctx.fillRect(i,e,s/4,r),!0;case 9615:return this.ctx.fillRect(i,e,s/8,r),!0;case 9616:return this.ctx.fillRect(i+s/2,e,s/2,r),!0;case 9620:return this.ctx.fillRect(i,e,s,r/8),!0;case 9621:return this.ctx.fillRect(i+s*7/8,e,s/8,r),!0;default:return!1}}renderPowerlineGlyph(t,i,e,s){const r=this.metrics.height,n=this.ctx;switch(t){case 57520:return n.beginPath(),n.moveTo(i,e),n.lineTo(i+s,e+r/2),n.lineTo(i,e+r),n.closePath(),n.fill(),!0;case 57521:return n.beginPath(),n.moveTo(i,e),n.lineTo(i+s,e+r/2),n.lineTo(i,e+r),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57522:return n.beginPath(),n.moveTo(i+s,e),n.lineTo(i,e+r/2),n.lineTo(i+s,e+r),n.closePath(),n.fill(),!0;case 57523:return n.beginPath(),n.moveTo(i+s,e),n.lineTo(i,e+r/2),n.lineTo(i+s,e+r),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57524:return n.beginPath(),n.moveTo(i,e),n.ellipse(i,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!1),n.closePath(),n.fill(),!0;case 57525:return n.beginPath(),n.moveTo(i,e),n.ellipse(i,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!1),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;case 57526:return n.beginPath(),n.moveTo(i+s,e),n.ellipse(i+s,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!0),n.closePath(),n.fill(),!0;case 57527:return n.beginPath(),n.moveTo(i+s,e),n.ellipse(i+s,e+r/2,s,r/2,0,-Math.PI/2,Math.PI/2,!0),n.strokeStyle=n.fillStyle,n.lineWidth=1,n.stroke(),!0;default:return!1}}precomputeKittyState(t,i){var n;this.kittyVirtualPlacements.clear(),this.currentDirectPlacements=[],this.kittyDamagedRows.clear(),this.currentKittyGraphics=null;const e=new Map,s=this.metrics.height,r=(o,h)=>{const c=Math.max(0,Math.floor(o)),l=Math.min(i,Math.ceil(o+h/s));for(let u=c;u<l;u++)this.kittyDamagedRows.add(u)};if(t.getKittyGraphics&&t.iterPlacements){const o=t.getKittyGraphics();if(o!==null){this.currentKittyGraphics=o;for(const h of t.iterPlacements(o,!1)){if(h.isVirtual){this.kittyVirtualPlacements.set(h.imageId,h);continue}this.currentDirectPlacements.push(h);const c=(n=t.getKittyImagePixels)==null?void 0:n.call(t,o,h.imageId),l={viewportCol:h.viewportCol,viewportRow:h.viewportRow,pixelWidth:h.pixelWidth,pixelHeight:h.pixelHeight,sourceX:h.sourceX,sourceY:h.sourceY,sourceWidth:h.sourceWidth,sourceHeight:h.sourceHeight,imgWidth:(c==null?void 0:c.width)??0,imgHeight:(c==null?void 0:c.height)??0,imgFormat:(c==null?void 0:c.format)??0,dataPtr:(c==null?void 0:c.data.byteOffset)??0,dataLen:(c==null?void 0:c.data.length)??0};e.set(h.imageId,l);const u=this.lastKittyDirectSigs.get(h.imageId);(!u||u.viewportCol!==l.viewportCol||u.viewportRow!==l.viewportRow||u.pixelWidth!==l.pixelWidth||u.pixelHeight!==l.pixelHeight||u.sourceX!==l.sourceX||u.sourceY!==l.sourceY||u.sourceWidth!==l.sourceWidth||u.sourceHeight!==l.sourceHeight||u.imgWidth!==l.imgWidth||u.imgHeight!==l.imgHeight||u.imgFormat!==l.imgFormat||u.dataPtr!==l.dataPtr||u.dataLen!==l.dataLen)&&(r(l.viewportRow,l.pixelHeight),u&&r(u.viewportRow,u.pixelHeight))}}}for(const[o,h]of this.lastKittyDirectSigs)e.has(o)||r(h.viewportRow,h.pixelHeight);this.lastKittyDirectSigs=e}getOrDecodeKittyImage(t,i,e){var o;const s=this.kittyImageCache.get(e),r=(o=t.getKittyImagePixels)==null?void 0:o.call(t,i,e);if(!r)return(s==null?void 0:s.canvas)??null;if(s&&_(s,r))return s.canvas;const n=this.decodeKittyImageToCanvas(r);return n?(this.kittyImageCache.set(e,{canvas:n,width:r.width,height:r.height,format:r.format,dataPtr:r.data.byteOffset,dataLen:r.data.length}),n):null}renderBlockElement(t,i,e,s){if(t<9600||t>9631)return!1;const r=s,n=this.metrics.height;if(t===9600)return this.ctx.fillRect(i,e,r,Math.round(n/2)),!0;if(t>=9601&&t<=9608){const g=t-9600,w=Math.round(n*g/8);return this.ctx.fillRect(i,e+n-w,r,w),!0}if(t>=9609&&t<=9615){const g=9616-t,w=Math.round(r*g/8);return this.ctx.fillRect(i,e,w,n),!0}if(t===9616){const g=Math.round(r/2);return this.ctx.fillRect(i+g,e,r-g,n),!0}if(t>=9617&&t<=9619){const g=[.25,.5,.75][t-9617],w=this.ctx.globalAlpha;return this.ctx.globalAlpha=w*g,this.ctx.fillRect(i,e,r,n),this.ctx.globalAlpha=w,!0}if(t===9620)return this.ctx.fillRect(i,e,r,Math.round(n/8)),!0;if(t===9621){const g=Math.round(r*7/8);return this.ctx.fillRect(i+g,e,r-g,n),!0}const o=8,h=4,c=2,l=1,d={9622:c,9623:l,9624:o,9625:o|c|l,9626:o|l,9627:o|h|c,9628:o|h|l,9629:h,9630:h|c,9631:h|c|l}[t];if(d===void 0)return!1;const p=Math.round(r/2),f=Math.round(n/2);return d&o&&this.ctx.fillRect(i,e,p,f),d&h&&this.ctx.fillRect(i+p,e,r-p,f),d&c&&this.ctx.fillRect(i,e+f,p,n-f),d&l&&this.ctx.fillRect(i+p,e+f,r-p,n-f),!0}renderPlaceholderCell(t,i,e){var S;const s=this.currentRenderBuffer,r=this.currentKittyGraphics;if(!s||r===null||!s.getGrapheme)return!1;const n=s.getGrapheme(e,i);if(!n||n.length<3)return!1;const o=D(n[1]),h=D(n[2]);if(o<0||h<0)return!1;const c=t.fg_r<<16|t.fg_g<<8|t.fg_b;let l=c;if(n.length>=4){const k=D(n[3]);k>=0&&(l=k<<24|c)}const u=this.kittyVirtualPlacements.get(l);if(!u)return!1;const d=(S=s.getKittyImagePixels)==null?void 0:S.call(s,r,l);if(!d)return!1;const p=this.getOrDecodeKittyImage(s,r,l);if(!p)return!1;const f=d.width/u.gridCols,g=d.height/u.gridRows,w=h*f,C=o*g,y=i*this.metrics.width,m=e*this.metrics.height,b=this.ctx.imageSmoothingEnabled;return this.ctx.imageSmoothingEnabled=!1,this.ctx.drawImage(p,w,C,f,g,y,m,this.metrics.width,this.metrics.height),this.ctx.imageSmoothingEnabled=b,!0}renderKittyImages(){const t=this.currentRenderBuffer,i=this.currentKittyGraphics;if(!(!t||i===null||!t.getKittyImagePixels))for(const e of this.currentDirectPlacements){let s=this.kittyImageCache.get(e.imageId);const r=t.getKittyImagePixels(i,e.imageId);if(r){if(!s||!_(s,r)){const n=this.decodeKittyImageToCanvas(r);if(!n)continue;s={canvas:n,width:r.width,height:r.height,format:r.format,dataPtr:r.data.byteOffset,dataLen:r.data.length},this.kittyImageCache.set(e.imageId,s)}this.ctx.drawImage(s.canvas,e.sourceX,e.sourceY,e.sourceWidth,e.sourceHeight,e.viewportCol*this.metrics.width,e.viewportRow*this.metrics.height,e.pixelWidth,e.pixelHeight)}}}decodeKittyImageToCanvas(t){const{width:i,height:e,format:s,data:r}=t;if(i===0||e===0)return null;const n=new Uint8ClampedArray(new ArrayBuffer(i*e*4));switch(s){case a.KittyImageFormat.RGBA:n.set(r);break;case a.KittyImageFormat.RGB:for(let c=0,l=0;c<r.length;c+=3,l+=4)n[l]=r[c],n[l+1]=r[c+1],n[l+2]=r[c+2],n[l+3]=255;break;case a.KittyImageFormat.GRAY:for(let c=0,l=0;c<r.length;c++,l+=4){const u=r[c];n[l]=u,n[l+1]=u,n[l+2]=u,n[l+3]=255}break;case a.KittyImageFormat.GRAY_ALPHA:for(let c=0,l=0;c<r.length;c+=2,l+=4){const u=r[c];n[l]=u,n[l+1]=u,n[l+2]=u,n[l+3]=r[c+1]}break;default:return null}const o=document.createElement("canvas");o.width=i,o.height=e;const h=o.getContext("2d");return h?(h.putImageData(new ImageData(n,i,e),0,0),o):null}renderCursor(t,i,e){var o;const s=t*this.metrics.width,r=i*this.metrics.height,n=e??this.cursorStyle;switch(this.ctx.fillStyle=this.theme.cursor,n){case"block":this.ctx.fillRect(s,r,this.metrics.width,this.metrics.height);{const l=(o=this.currentBuffer)==null?void 0:o.getLine(i);l!=null&&l[t]&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(s,r,this.metrics.width,this.metrics.height),this.ctx.clip(),this.renderCellText(l[t],t,i,this.theme.cursorAccent),this.ctx.restore())}break;case"underline":const h=Math.max(2,Math.floor(this.metrics.height*.15));this.ctx.fillRect(s,r+this.metrics.height-h,this.metrics.width,h);break;case"bar":const c=Math.max(2,Math.floor(this.metrics.width*.15));this.ctx.fillRect(s,r,c,this.metrics.height);break}}setOnRequestRender(t){this.onRequestRender=t}startCursorBlink(){this.cursorBlinkInterval=window.setInterval(()=>{var t;this.cursorVisible=!this.cursorVisible,(t=this.onRequestRender)==null||t.call(this)},530)}stopCursorBlink(){this.cursorBlinkInterval!==void 0&&(clearInterval(this.cursorBlinkInterval),this.cursorBlinkInterval=void 0),this.cursorVisible=!0}setTheme(t){this.theme={...x,...t},this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite]}setFontSize(t){this.fontSize=t,this.metrics=this.measureFont()}setFontFamily(t){this.fontFamily=t,this.metrics=this.measureFont()}setCursorStyle(t){this.cursorStyle=t}setCursorBlink(t){t&&!this.cursorBlink?(this.cursorBlink=!0,this.startCursorBlink()):!t&&this.cursorBlink&&(this.cursorBlink=!1,this.stopCursorBlink())}renderScrollbar(t,i,e,s=1){const r=this.ctx,n=this.canvas.height/this.devicePixelRatio,o=this.canvas.width/this.devicePixelRatio,h=8,c=o-h-4,l=4,u=n-l*2;if(r.clearRect(c-2,0,h+6,n),r.fillStyle=this.theme.background,r.fillRect(c-2,0,h+6,n),s<=0||i===0)return;const d=i+e,p=Math.max(20,e/d*u),f=t/i,g=l+(u-p)*(1-f);r.fillStyle=`rgba(128, 128, 128, ${.1*s})`,r.fillRect(c,l,h,u);const C=t>0?.5:.3;r.fillStyle=`rgba(128, 128, 128, ${C*s})`,r.fillRect(c,g,h,p)}getMetrics(){return{...this.metrics}}getCanvas(){return this.canvas}setSelectionManager(t){this.selectionManager=t}isInSelection(t,i){const e=this.currentSelectionCoords;if(!e)return!1;const{startCol:s,startRow:r,endCol:n,endRow:o}=e;return r===o?i===r&&t>=s&&t<=n:i===r?t>=s:i===o?t<=n:i>r&&i<o}setHoveredHyperlinkId(t){var i;this.hoveredHyperlinkId!==t&&(this.hoveredHyperlinkId=t,(i=this.onRequestRender)==null||i.call(this))}setHoveredLinkRange(t){var i;this.hoveredLinkRange!==t&&(this.hoveredLinkRange=t,(i=this.onRequestRender)==null||i.call(this))}get charWidth(){return this.metrics.width}get charHeight(){return this.metrics.height}clear(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}dispose(){this.stopCursorBlink()}}const M=class L{constructor(t,i,e,s){this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.mouseDownX=0,this.mouseDownY=0,this.dragThresholdMet=!1,this.mouseDownTarget=null,this.dirtySelectionRows=new Set,this.selectionChangedEmitter=new a.EventEmitter,this.boundMouseUpHandler=null,this.boundContextMenuHandler=null,this.boundClickHandler=null,this.boundDocumentMouseMoveHandler=null,this.autoScrollInterval=null,this.autoScrollDirection=0,this.terminal=t,this.renderer=i,this.wasmTerm=e,this.textarea=s,this.attachEventListeners()}getViewportY(){const t=typeof this.terminal.getViewportY=="function"?this.terminal.getViewportY():this.terminal.viewportY||0;return Math.max(0,Math.floor(t))}viewportRowToAbsolute(t){const i=this.wasmTerm.getScrollbackLength(),e=this.getViewportY();return i+t-e}absoluteRowToViewport(t){const i=this.wasmTerm.getScrollbackLength(),e=this.getViewportY();return t-i+e}getSelection(){if(!this.selectionStart||!this.selectionEnd)return"";let{col:t,absoluteRow:i}=this.selectionStart,{col:e,absoluteRow:s}=this.selectionEnd;(i>s||i===s&&t>e)&&([t,e]=[e,t],[i,s]=[s,i]);const r=this.wasmTerm.getScrollbackLength();let n="";for(let o=i;o<=s;o++){let h=null;if(o<r)h=this.wasmTerm.getScrollbackLine(o);else{const p=o-r;h=this.wasmTerm.getLine(p)}if(!h)continue;let c=-1;const l=o===i?t:0,u=o===s?e:h.length-1;let d="";for(let p=l;p<=u;p++){const f=h[p];if(f&&f.codepoint!==0){let g;if(f.grapheme_len>0)if(o<r)g=this.wasmTerm.getScrollbackGraphemeString(o,p);else{const w=o-r;g=this.wasmTerm.getGraphemeString(w,p)}else g=String.fromCodePoint(f.codepoint);d+=g,g.trim()&&(c=d.length)}else(!f||f.width!==0)&&(d+=" ")}c>=0?d=d.substring(0,c):d="",n+=d,o<s&&(n+=`
2
+ `)}return n}hasSelection(){return!(!this.selectionStart||!this.selectionEnd||this.isSelecting&&!this.dragThresholdMet)}copySelection(){if(!this.hasSelection())return!1;const t=this.getSelection();return t?(this.copyToClipboard(t),!0):!1}clearSelection(){if(!this.hasSelection())return;const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i);this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.requestRender()}selectAll(){const t=this.wasmTerm.getDimensions(),i=this.getViewportY();this.selectionStart={col:0,absoluteRow:i},this.selectionEnd={col:t.cols-1,absoluteRow:i+t.rows-1},this.requestRender(),this.selectionChangedEmitter.fire()}select(t,i,e){const s=this.wasmTerm.getDimensions();i=Math.max(0,Math.min(i,s.rows-1)),t=Math.max(0,Math.min(t,s.cols-1));let r=i,n=t+e-1;for(;n>=s.cols;)n-=s.cols,r++;r=Math.min(r,s.rows-1);const o=this.getViewportY();this.selectionStart={col:t,absoluteRow:o+i},this.selectionEnd={col:n,absoluteRow:o+r},this.requestRender(),this.selectionChangedEmitter.fire()}selectLines(t,i){const e=this.wasmTerm.getDimensions();t=Math.max(0,Math.min(t,e.rows-1)),i=Math.max(0,Math.min(i,e.rows-1)),t>i&&([t,i]=[i,t]),this.selectionStart={col:0,absoluteRow:this.viewportRowToAbsolute(t)},this.selectionEnd={col:e.cols-1,absoluteRow:this.viewportRowToAbsolute(i)},this.requestRender(),this.selectionChangedEmitter.fire()}getSelectionPosition(){const t=this.normalizeSelection();if(t)return{start:{x:t.startCol,y:t.startRow},end:{x:t.endCol,y:t.endRow}}}deselect(){this.clearSelection(),this.selectionChangedEmitter.fire()}focus(){const t=this.renderer.getCanvas();t.parentElement&&t.parentElement.focus()}getSelectionCoords(){return this.normalizeSelection()}getDirtySelectionRows(){return this.dirtySelectionRows}clearDirtySelectionRows(){this.dirtySelectionRows.clear()}get onSelectionChange(){return this.selectionChangedEmitter.event}dispose(){this.selectionChangedEmitter.dispose(),this.stopAutoScroll(),this.boundMouseUpHandler&&(document.removeEventListener("mouseup",this.boundMouseUpHandler),this.boundMouseUpHandler=null),this.boundDocumentMouseMoveHandler&&(document.removeEventListener("mousemove",this.boundDocumentMouseMoveHandler),this.boundDocumentMouseMoveHandler=null),this.boundContextMenuHandler&&(this.renderer.getCanvas().removeEventListener("contextmenu",this.boundContextMenuHandler),this.boundContextMenuHandler=null),this.boundClickHandler&&(document.removeEventListener("click",this.boundClickHandler),this.boundClickHandler=null)}attachEventListeners(){const t=this.renderer.getCanvas();t.addEventListener("mousedown",i=>{if(i.button===0){t.parentElement&&t.parentElement.focus();const e=this.pixelToCell(i.offsetX,i.offsetY);this.hasSelection()&&this.clearSelection();const r=this.viewportRowToAbsolute(e.row);this.selectionStart={col:e.col,absoluteRow:r},this.selectionEnd={col:e.col,absoluteRow:r},this.isSelecting=!0,this.mouseDownX=i.offsetX,this.mouseDownY=i.offsetY,this.dragThresholdMet=!1}}),t.addEventListener("mousemove",i=>{if(this.isSelecting){if(!this.dragThresholdMet){const r=i.offsetX-this.mouseDownX,n=i.offsetY-this.mouseDownY,o=this.renderer.getMetrics().width*.5;if(r*r+n*n<o*o)return;this.dragThresholdMet=!0}this.markCurrentSelectionDirty();const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.viewportRowToAbsolute(e.row);this.selectionEnd={col:e.col,absoluteRow:s},this.requestRender(),this.updateAutoScroll(i.offsetY,t.clientHeight)}}),t.addEventListener("mouseleave",i=>{if(this.isSelecting){const e=t.getBoundingClientRect();i.clientY<e.top?this.startAutoScroll(-1):i.clientY>e.bottom&&this.startAutoScroll(1)}}),t.addEventListener("mouseenter",()=>{this.isSelecting&&this.stopAutoScroll()}),this.boundDocumentMouseMoveHandler=i=>{if(this.isSelecting){if(!this.dragThresholdMet){const h=i.clientX-(t.getBoundingClientRect().left+this.mouseDownX),c=i.clientY-(t.getBoundingClientRect().top+this.mouseDownY),l=this.renderer.getMetrics().width*.5;if(h*h+c*c<l*l)return;this.dragThresholdMet=!0}const e=t.getBoundingClientRect(),s=Math.max(e.left,Math.min(i.clientX,e.right)),r=Math.max(e.top,Math.min(i.clientY,e.bottom)),n=s-e.left,o=r-e.top;if((i.clientX<e.left||i.clientX>e.right||i.clientY<e.top||i.clientY>e.bottom)&&(i.clientY<e.top?this.startAutoScroll(-1):i.clientY>e.bottom?this.startAutoScroll(1):this.stopAutoScroll(),this.autoScrollDirection===0)){this.markCurrentSelectionDirty();const h=this.pixelToCell(n,o),c=this.viewportRowToAbsolute(h.row);this.selectionEnd={col:h.col,absoluteRow:c},this.requestRender()}}},document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.addEventListener("mousedown",i=>{this.mouseDownTarget=i.target}),this.boundMouseUpHandler=i=>{if(this.isSelecting){if(this.isSelecting=!1,this.stopAutoScroll(),!this.dragThresholdMet){this.clearSelection();return}if(this.hasSelection()){try{const e=this.getSelection();e&&this.copyToClipboard(e)}catch{}this.selectionChangedEmitter.fire()}}},document.addEventListener("mouseup",this.boundMouseUpHandler),t.addEventListener("click",i=>{if(i.detail===2){const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.getWordAtCell(e.col,e.row);if(s){const r=this.viewportRowToAbsolute(e.row);this.selectionStart={col:s.startCol,absoluteRow:r},this.selectionEnd={col:s.endCol,absoluteRow:r},this.requestRender();try{const n=this.getSelection();n&&this.copyToClipboard(n)}catch{}this.selectionChangedEmitter.fire()}}else if(i.detail>=3){const e=this.pixelToCell(i.offsetX,i.offsetY),s=this.viewportRowToAbsolute(e.row),r=this.wasmTerm.getScrollbackLength();let n=null;if(s<r)n=this.wasmTerm.getScrollbackLine(s);else{const h=s-r;n=this.wasmTerm.getLine(h)}let o=-1;if(n){for(let h=n.length-1;h>=0;h--)if(n[h]&&n[h].codepoint!==0&&n[h].codepoint!==32){o=h;break}}if(o>=0){this.selectionStart={col:0,absoluteRow:s},this.selectionEnd={col:o,absoluteRow:s},this.requestRender();try{const h=this.getSelection();h&&this.copyToClipboard(h)}catch{}this.selectionChangedEmitter.fire()}}}),this.boundContextMenuHandler=i=>{if(this.renderer.getCanvas().getBoundingClientRect(),this.textarea.style.position="fixed",this.textarea.style.left=`${i.clientX}px`,this.textarea.style.top=`${i.clientY}px`,this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.zIndex="1000",this.textarea.style.opacity="0",this.textarea.style.pointerEvents="auto",this.hasSelection()){const s=this.getSelection();this.textarea.value=s,this.textarea.select(),this.textarea.setSelectionRange(0,s.length)}else this.textarea.value="";this.textarea.focus(),setTimeout(()=>{const s=()=>{this.textarea.style.pointerEvents="none",this.textarea.style.zIndex="-10",this.textarea.style.width="0",this.textarea.style.height="0",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.value="",document.removeEventListener("click",s),document.removeEventListener("contextmenu",s),this.textarea.removeEventListener("blur",s)};document.addEventListener("click",s,{once:!0}),document.addEventListener("contextmenu",s,{once:!0}),this.textarea.addEventListener("blur",s,{once:!0})},10)},t.addEventListener("contextmenu",this.boundContextMenuHandler),this.boundClickHandler=i=>{if(this.isSelecting||this.mouseDownTarget&&t.contains(this.mouseDownTarget))return;const s=i.target;t.contains(s)||this.hasSelection()&&this.clearSelection()},document.addEventListener("click",this.boundClickHandler)}markCurrentSelectionDirty(){const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i)}updateAutoScroll(t,i){const e=L.AUTO_SCROLL_EDGE_SIZE;t<e?this.startAutoScroll(-1):t>i-e?this.startAutoScroll(1):this.stopAutoScroll()}startAutoScroll(t){this.autoScrollInterval!==null&&this.autoScrollDirection===t||(this.stopAutoScroll(),this.autoScrollDirection=t,this.autoScrollInterval=setInterval(()=>{if(!this.isSelecting){this.stopAutoScroll();return}const i=L.AUTO_SCROLL_SPEED*this.autoScrollDirection;if(this.terminal.scrollLines(i),this.selectionEnd){const e=this.wasmTerm.getDimensions();if(this.autoScrollDirection<0){const s=this.viewportRowToAbsolute(0);s<this.selectionEnd.absoluteRow&&(this.selectionEnd={col:0,absoluteRow:s})}else{const s=this.viewportRowToAbsolute(e.rows-1);s>this.selectionEnd.absoluteRow&&(this.selectionEnd={col:e.cols-1,absoluteRow:s})}}this.requestRender()},L.AUTO_SCROLL_INTERVAL))}stopAutoScroll(){this.autoScrollInterval!==null&&(clearInterval(this.autoScrollInterval),this.autoScrollInterval=null),this.autoScrollDirection=0}pixelToCell(t,i){const e=this.renderer.getMetrics(),s=Math.floor(t/e.width),r=Math.floor(i/e.height);return{col:Math.max(0,Math.min(s,this.terminal.cols-1)),row:Math.max(0,Math.min(r,this.terminal.rows-1))}}normalizeSelection(){if(!this.selectionStart||!this.selectionEnd)return null;let{col:t,absoluteRow:i}=this.selectionStart,{col:e,absoluteRow:s}=this.selectionEnd;(i>s||i===s&&t>e)&&([t,e]=[e,t],[i,s]=[s,i]);let r=this.absoluteRowToViewport(i),n=this.absoluteRowToViewport(s);const o=this.wasmTerm.getDimensions(),h=o.rows-1;return n<0||r>h?null:(r<0&&(r=0,t=0),n>h&&(n=h,e=o.cols-1),{startCol:t,startRow:r,endCol:e,endRow:n})}getWordAtCell(t,i){const e=this.viewportRowToAbsolute(i),s=this.wasmTerm.getScrollbackLength();let r;try{if(e<s)r=this.wasmTerm.getScrollbackLine(e);else{const c=e-s;r=this.wasmTerm.getLine(c)}}catch{return null}if(!r)return null;const n=c=>{if(!c||c.codepoint===0)return!1;const l=String.fromCodePoint(c.codepoint);return/[\w\-./~@+]/.test(l)};if(!n(r[t]))return null;let o=t;for(;o>0&&n(r[o-1]);)o--;let h=t;for(;h<r.length-1&&n(r[h+1]);)h++;return{startCol:o,endCol:h}}copyToClipboard(t){if(navigator.clipboard&&typeof ClipboardItem<"u")try{const i=new Blob([t],{type:"text/plain"}),e=new ClipboardItem({"text/plain":i});navigator.clipboard.write([e]).catch(s=>{console.warn("ClipboardItem write failed, trying writeText:",s),this.copyWithWriteText(t)});return}catch{}if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(t).catch(i=>{console.warn("Clipboard writeText failed, trying execCommand:",i),this.copyWithExecCommand(t)});return}this.copyWithExecCommand(t)}copyWithWriteText(t){navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(t).catch(i=>{console.warn("Clipboard writeText failed, trying execCommand:",i),this.copyWithExecCommand(t)}):this.copyWithExecCommand(t)}copyWithExecCommand(t){const i=document.activeElement;try{const e=this.textarea;e.value=t,e.style.position="fixed",e.style.left="-9999px",e.style.top="0",e.style.width="1px",e.style.height="1px",e.style.opacity="0",e.focus(),e.select(),e.setSelectionRange(0,t.length);const s=document.execCommand("copy");i&&i.focus(),s||console.warn("execCommand copy failed")}catch(e){console.warn("execCommand copy threw:",e),i&&i.focus()}}requestRender(){}};M.AUTO_SCROLL_EDGE_SIZE=30;M.AUTO_SCROLL_SPEED=3;M.AUTO_SCROLL_INTERVAL=50;let V=M;function H(v,t){const i=String(v||"").trim();if(!i)return t;if(i.startsWith("#")){const s=i.slice(1),r=s.length===3?s.split("").map(n=>n+n).join(""):s;if(/^[0-9a-fA-F]{6}$/.test(r)){const n=Number.parseInt(r,16);return{r:n>>16&255,g:n>>8&255,b:n&255}}}const e=i.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);return e?{r:Number.parseInt(e[1],10),g:Number.parseInt(e[2],10),b:Number.parseInt(e[3],10)}:t}function J(v,t,i){const e=H(i.foreground,{r:212,g:212,b:212}),s=H(i.background,{r:30,g:30,b:30}),r={codepoint:32,fg_r:e.r,fg_g:e.g,fg_b:e.b,bg_r:s.r,bg_g:s.g,bg_b:s.b,fgIsDefault:!1,bgIsDefault:!1,flags:0,width:1,hyperlink_id:0,grapheme_len:0};return Array.from({length:t},()=>Array.from({length:v},()=>({...r})))}const W=class z extends a.TerminalCore{constructor(t={}){const i=t.ghostty??G();super(i,t),this.unicode={get activeVersion(){return"15.1"}},this.selectionChangeEmitter=new a.EventEmitter,this.keyEmitter=new a.EventEmitter,this.renderEmitter=new a.EventEmitter,this.mouseCursorChangeEmitter=new a.EventEmitter,this.onSelectionChange=this.selectionChangeEmitter.event,this.onKey=this.keyEmitter.event,this.onRender=this.renderEmitter.event,this.onMouseCursorChange=this.mouseCursorChangeEmitter.event,this.isOpen=!1,this.writeQueue=[],this.awaitingEcho=!1,this.syncOutputStartTime=void 0,this.currentTheme={...x},this.targetViewportY=0,this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.scrollbarDragStartViewportY=0,this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.SCROLLBAR_HIDE_DELAY_MS=1500,this.SCROLLBAR_FADE_DURATION_MS=200,this.bootstrapCells=null,this.bootstrapDirty=!1,this.renderTick=()=>{if(this.animationFrameId=void 0,this.isDisposed||!this.isOpen)return;if(this.wasmTerm.getMode(2026,!1)){const s=performance.now();if(this.syncOutputStartTime===void 0&&(this.syncOutputStartTime=s),s-this.syncOutputStartTime<z.SYNC_OUTPUT_TIMEOUT_MS){this.requestRender();return}}this.syncOutputStartTime=void 0,this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),this.renderEmitter.fire({start:0,end:this.rows-1});const e=this.wasmTerm.getCursor();(e.x!==this.lastCursorX||e.y!==this.lastCursorY)&&(this.lastCursorX=e.x,this.lastCursorY=e.y,this.cursorMoveEmitter.fire()),this.syncTextareaToCursor(e.x,e.y)},this.lastOsc22Cursor="",this.animateScroll=()=>{if(!this.wasmTerm||this.scrollAnimationStartTime===void 0)return;const e=this.options.smoothScrollDuration??100,s=this.targetViewportY-this.viewportY;if(Math.abs(s)<.01){this.viewportY=this.targetViewportY,this.scrollEmitter.fire(Math.floor(this.viewportY)),this.getScrollbackLength()>0&&this.showScrollbar(),this.scrollAnimationFrame=void 0,this.scrollAnimationStartTime=void 0,this.scrollAnimationStartY=void 0,this.requestRender();return}const o=1-(1/(e/1e3*60))**2;this.viewportY+=s*o;const h=Math.floor(this.viewportY);this.scrollEmitter.fire(h),this.getScrollbackLength()>0&&this.showScrollbar(),this.requestRender(),this.scrollAnimationFrame=requestAnimationFrame(this.animateScroll)},this.handleMouseMove=e=>{if(!(!this.canvas||!this.renderer||!this.wasmTerm)){if(this.isDraggingScrollbar){this.processScrollbarDrag(e);return}if(this.linkDetector){if(this.mouseMoveThrottleTimeout){this.pendingMouseMove=e;return}this.processMouseMove(e),this.mouseMoveThrottleTimeout=window.setTimeout(()=>{if(this.mouseMoveThrottleTimeout=void 0,this.pendingMouseMove){const s=this.pendingMouseMove;this.pendingMouseMove=void 0,this.processMouseMove(s)}},16)}}},this.handleMouseLeave=()=>{var e,s;this.renderer&&this.wasmTerm&&((this.renderer.hoveredHyperlinkId||0)>0&&this.renderer.setHoveredHyperlinkId(0),this.renderer.setHoveredLinkRange(null)),this.currentHoveredLink&&((s=(e=this.currentHoveredLink).hover)==null||s.call(e,!1),this.currentHoveredLink=void 0,this.element&&(this.element.style.cursor="text",this.canvas&&(this.canvas.style.cursor="text")))},this.handleClick=async e=>{if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const s=this.canvas.getBoundingClientRect(),r=Math.floor((e.clientX-s.left)/this.renderer.charWidth),o=Math.floor((e.clientY-s.top)/this.renderer.charHeight),h=this.wasmTerm.getScrollbackLength();let c;const l=this.getViewportY(),u=Math.max(0,Math.floor(l));if(u>0)if(o<u)c=h-u+o;else{const p=o-u;c=h+p}else c=h+o;const d=await this.linkDetector.getLinkAt(r,c);d&&(d.activate(e),(e.ctrlKey||e.metaKey)&&e.preventDefault())},this.handleWheel=e=>{var r,n,o,h,c,l,u;if(e.preventDefault(),e.stopPropagation(),this.customWheelEventHandler&&this.customWheelEventHandler(e))return;if((r=this.wasmTerm)!=null&&r.hasMouseTracking()){(n=this.inputHandler)==null||n.handleWheelEvent(e);return}if(((o=this.wasmTerm)==null?void 0:o.isAlternateScreen())??!1){if((h=this.wasmTerm)!=null&&h.hasMouseTracking()){const f=(c=this.renderer)==null?void 0:c.getMetrics(),g=this.canvas;if(f&&g){const w=g.getBoundingClientRect(),C=Math.max(1,Math.floor((e.clientX-w.left)/f.width)+1),y=Math.max(1,Math.floor((e.clientY-w.top)/f.height)+1),m=e.deltaY<0?64:65;this.dataEmitter.fire(`\x1B[<${m};${C};${y}M`)}return}const d=e.deltaY>0?"down":"up",p=Math.min(Math.abs(Math.round(e.deltaY/33)),5);for(let f=0;f<p;f++)this.dataEmitter.fire(d==="up"?"\x1B[A":"\x1B[B")}else{let d;if(e.deltaMode===WheelEvent.DOM_DELTA_PIXEL){const p=((u=(l=this.renderer)==null?void 0:l.getMetrics())==null?void 0:u.height)??20;d=e.deltaY/p}else e.deltaMode===WheelEvent.DOM_DELTA_LINE?d=e.deltaY:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?d=e.deltaY*this.rows:d=e.deltaY/33;if(d!==0){const p=this.viewportY-d;this.smoothScrollTo(p)}}},this.handleMouseDown=e=>{if(!this.canvas||!this.renderer||!this.wasmTerm)return;const s=this.wasmTerm.getScrollbackLength();if(s===0)return;const r=this.canvas.getBoundingClientRect(),n=e.clientX-r.left,o=e.clientY-r.top,h=r.width,c=r.height,l=8,u=h-l-4,d=4;if(n>=u&&n<=u+l){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const p=c-d*2,f=this.rows,g=s+f,w=Math.max(20,f/g*p),C=this.viewportY/s,y=d+(p-w)*(1-C);if(o>=y&&o<=y+w)this.isDraggingScrollbar=!0,this.scrollbarDragStart=o,this.scrollbarDragStartViewportY=this.viewportY,this.canvas&&(this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none");else{const b=1-(o-d)/p,S=Math.round(b*s);this.scrollToLine(Math.max(0,Math.min(s,S)))}}},this.handleMouseUp=()=>{this.isDraggingScrollbar&&(this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.canvas&&(this.canvas.style.userSelect="",this.canvas.style.webkitUserSelect=""),this.scrollbarVisible&&this.getScrollbackLength()>0&&this.showScrollbar())},this.currentTheme={...x,...t.theme},this.bootstrapBuffer={getLine:e=>{var s;return this.bootstrapCells&&e>=0&&e<this.bootstrapCells.length?this.bootstrapCells[e]:((s=this.wasmTerm)==null?void 0:s.getLine(e))??null},getCursor:()=>{var e;return this.bootstrapCells?{x:0,y:0,visible:!0}:((e=this.wasmTerm)==null?void 0:e.getCursor())??{x:0,y:0,visible:!0}},getDimensions:()=>({cols:this.cols,rows:this.rows}),isRowDirty:e=>{var s;return this.bootstrapDirty?!0:this.bootstrapCells?!1:((s=this.wasmTerm)==null?void 0:s.isRowDirty(e))??!1},needsFullRedraw:()=>{var s;if(this.bootstrapDirty)return!0;if(this.bootstrapCells)return!1;const e=this.wasmTerm;return((s=e==null?void 0:e.needsFullRedraw)==null?void 0:s.call(e))??!1},clearDirty:()=>{var e;this.bootstrapDirty=!1,(e=this.wasmTerm)==null||e.clearDirty()},getGraphemeString:(e,s)=>{var n,o;if(this.bootstrapCells&&e>=0&&e<this.bootstrapCells.length){const h=(n=this.bootstrapCells[e])==null?void 0:n[s];return h?String.fromCodePoint(h.codepoint||32):" "}const r=this.wasmTerm;return((o=r==null?void 0:r.getGraphemeString)==null?void 0:o.call(r,e,s))??" "}}}get viewportY(){return this._viewportY}set viewportY(t){this._viewportY=t}handleOptionChange(t,i,e){if(i!==e)switch(t){case"disableStdin":break;case"cursorBlink":case"cursorStyle":this.renderer&&(this.renderer.setCursorStyle(this.options.cursorStyle),this.renderer.setCursorBlink(this.options.cursorBlink));break;case"theme":if(this.renderer&&this.wasmTerm){const s=i&&typeof i=="object"?i:{},r=Object.keys(s).length>0;this.currentTheme=r?{...this.currentTheme,...s}:{...x},this.renderer.setTheme(this.currentTheme),this.wasmTerm.setColors(this.buildThemeColorsConfig(this.currentTheme))}break;case"fontSize":this.renderer&&(this.renderer.setFontSize(this.options.fontSize),this.handleFontChange());break;case"fontFamily":this.renderer&&(this.renderer.setFontFamily(this.options.fontFamily),this.handleFontChange());break;case"cols":case"rows":this.resize(this.options.cols,this.options.rows);break}}handleFontChange(){if(!this.renderer||!this.wasmTerm||!this.canvas)return;this.selectionManager&&this.selectionManager.clearSelection(),this.renderer.resize(this.cols,this.rows);const t=this.renderer.getMetrics();this.canvas.width=t.width*this.cols,this.canvas.height=t.height*this.rows,this.canvas.style.width=`${t.width*this.cols}px`,this.canvas.style.height=`${t.height*this.rows}px`,this.updateWasmPixelSize(),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}buildThemeColorsConfig(t){return{fgColor:this.parseColorToHex(t.foreground),bgColor:this.parseColorToHex(t.background),cursorColor:this.parseColorToHex(t.cursor),palette:[this.parseColorToHex(t.black),this.parseColorToHex(t.red),this.parseColorToHex(t.green),this.parseColorToHex(t.yellow),this.parseColorToHex(t.blue),this.parseColorToHex(t.magenta),this.parseColorToHex(t.cyan),this.parseColorToHex(t.white),this.parseColorToHex(t.brightBlack),this.parseColorToHex(t.brightRed),this.parseColorToHex(t.brightGreen),this.parseColorToHex(t.brightYellow),this.parseColorToHex(t.brightBlue),this.parseColorToHex(t.brightMagenta),this.parseColorToHex(t.brightCyan),this.parseColorToHex(t.brightWhite)]}}open(t){if(this.isOpen)throw new Error("Terminal is already open");if(this.isDisposed)throw new Error("Terminal has been disposed");this.element=t,this.isOpen=!0;try{t.setAttribute("tabindex","-1"),t.setAttribute("role","textbox"),t.setAttribute("aria-label","Terminal input"),t.setAttribute("aria-multiline","true"),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.cursor="text",t.appendChild(this.canvas),this.textarea=document.createElement("textarea"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.setAttribute("tabindex","0"),this.textarea.setAttribute("aria-label","Terminal input"),this.textarea.style.position="absolute",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.padding="0",this.textarea.style.border="none",this.textarea.style.margin="0",this.textarea.style.opacity="0",this.textarea.style.clipPath="inset(50%)",this.textarea.style.overflow="hidden",this.textarea.style.whiteSpace="nowrap",this.textarea.style.resize="none",t.appendChild(this.textarea);const i=this.textarea;this.canvas.addEventListener("mousedown",o=>{o.preventDefault(),i.focus()}),this.canvas.addEventListener("touchend",o=>{o.preventDefault(),i.focus()}),t.addEventListener("mousedown",o=>{o.target===t&&(o.preventDefault(),i.focus())}),t.addEventListener("focus",()=>{var o;i.focus(),(o=this.wasmTerm)!=null&&o.hasFocusEvents()&&this.dataEmitter.fire("\x1B[I")}),t.addEventListener("blur",()=>{var o;(o=this.wasmTerm)!=null&&o.hasFocusEvents()&&this.dataEmitter.fire("\x1B[O")}),this.renderer=new U(this.canvas,{fontSize:this.options.fontSize,fontFamily:this.options.fontFamily,cursorStyle:this.options.cursorStyle,cursorBlink:this.options.cursorBlink,theme:this.options.theme,devicePixelRatio:this.options.devicePixelRatio}),this.renderer.resize(this.cols,this.rows),this.updateWasmPixelSize();const e=this.canvas,s=this.renderer,r=this.wasmTerm,n={hasMouseTracking:()=>(r==null?void 0:r.hasMouseTracking())??!1,hasSgrMouseMode:()=>(r==null?void 0:r.getMode(1006,!1))??!0,getCellDimensions:()=>({width:s.charWidth,height:s.charHeight}),getCanvasOffset:()=>{const o=e.getBoundingClientRect();return{left:o.left,top:o.top}}};this.inputHandler=new B(this.ghostty,t,o=>{var h;this.options.disableStdin||((h=this.selectionManager)==null||h.clearSelection(),this.awaitingEcho=!0,this.dataEmitter.fire(o))},()=>{this.bellEmitter.fire()},o=>{this.keyEmitter.fire(o)},this.customKeyEventHandler,o=>{var h;return((h=this.wasmTerm)==null?void 0:h.getMode(o,!1))??!1},()=>this.copySelection(),this.textarea,n),this.selectionManager=new V(this,this.renderer,this.wasmTerm,this.textarea),this.renderer.setSelectionManager(this.selectionManager),this.selectionManager.onSelectionChange(()=>{this.selectionChangeEmitter.fire(),this.requestRender()}),this.linkDetector=new O(this),this.linkDetector.registerProvider(new Y(this)),this.linkDetector.registerProvider(new N(this)),t.addEventListener("mousedown",this.handleMouseDown,{capture:!0}),t.addEventListener("mousemove",this.handleMouseMove),t.addEventListener("mouseleave",this.handleMouseLeave),t.addEventListener("click",this.handleClick),document.addEventListener("mouseup",this.handleMouseUp),t.addEventListener("wheel",this.handleWheel,{passive:!1,capture:!0}),this.armBootstrapBlank(),this.renderer.render(this.bootstrapBuffer,!0,this.viewportY,this,this.scrollbarOpacity),this.renderer.setOnRequestRender(()=>this.requestRender()),this.renderTick(),this.options.focusOnOpen!==!1&&this.focus()}catch(i){throw this.isOpen=!1,this.cleanupComponents(),new Error(`Failed to open terminal: ${i}`)}}write(t,i){this.assertOpen(),this.options.convertEol&&typeof t=="string"&&(t=t.replace(/\n/g,`\r
3
3
  `)),typeof t=="string"&&t.includes("\x1B]22;")&&this.interceptOsc22(t),this.writeInternal(t,i)}stripUnimplementedTitleSequences(t){if(typeof t=="string")return t.replace(/\x1bk[^\x1b\x07]*(?:\x1b\\|\x07)/g,"");let i=0,e=-1,s=null;for(;i<t.length;){if(t[i]===27&&i+1<t.length&&t[i+1]===107){let r=i+2;for(;r<t.length;){if(t[r]===7){r++;break}if(t[r]===27&&r+1<t.length&&t[r+1]===92){r+=2;break}r++}s===null&&(s=new Uint8Array(t.length),s.set(t.subarray(0,i)),e=i),i=r;continue}s!==null&&(s[e++]=t[i]),i++}return s===null?t:s.subarray(0,e)}writeInternal(t,i){var o;this.disarmBootstrapBlank();const e=this.stripUnimplementedTitleSequences(t),s=this.options.preserveScrollOnWrite===!0,r=s?this.viewportY:0,n=s&&r>0?this.wasmTerm.getScrollbackLength():0;if(this.wasmTerm.write(e),this.options.emitTerminalResponses&&this.processTerminalResponses(),typeof t=="string"&&t.includes("\x07")?this.bellEmitter.fire():t instanceof Uint8Array&&t.includes(7)&&this.bellEmitter.fire(),(o=this.linkDetector)==null||o.invalidateCache(),s){if(r>0){const h=this.wasmTerm.getScrollbackLength(),c=h-n,l=Math.max(0,Math.min(r+c,h));l!==r&&(this.viewportY=l,this.scrollEmitter.fire(this.viewportY),h>0&&this.showScrollbar())}}else this.viewportY!==0&&this.scrollToBottom();typeof t=="string"&&t.includes("\x1B]")&&(this.checkForTitleChange(t),this.checkForShellIntegration(t)),typeof t=="string"&&(t.includes(`
4
4
  `)||t.includes(`\r
5
5
  `))?this.lineFeedEmitter.fire():t instanceof Uint8Array&&t.includes(10)&&this.lineFeedEmitter.fire(),this.checkCursorMove(),i?requestAnimationFrame(()=>{i(),this.writeParsedEmitter.fire()}):this.writeParsedEmitter.fire(),this.awaitingEcho&&this.renderer&&this.wasmTerm&&(this.awaitingEcho=!1,this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity)),this.requestRender()}writeln(t,i){if(typeof t=="string")this.write(t+`\r
6
- `,i);else{const e=new Uint8Array(t.length+2);e.set(t),e[t.length]=13,e[t.length+1]=10,this.write(e,i)}}paste(t){this.assertOpen(),!this.options.disableStdin&&(this.awaitingEcho=!0,this.wasmTerm.hasBracketedPaste()?this.dataEmitter.fire("\x1B[200~"+t+"\x1B[201~"):this.dataEmitter.fire(t))}input(t,i=!1){this.assertOpen(),!this.options.disableStdin&&(i?(this.awaitingEcho=!0,this.dataEmitter.fire(t)):this.write(t))}resize(t,i){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.wasmTerm)throw new Error("Terminal not initialized");if(!(t===this.cols&&i===this.rows)){this.isOpen&&this.cancelRenderLoop();try{if(this.cols=t,this.rows=i,this.wasmTerm.resize(t,i),this.renderer&&this.canvas){this.renderer.resize(t,i);const e=this.renderer.getMetrics();this.canvas.width=e.width*t,this.canvas.height=e.height*i,this.canvas.style.width=`${e.width*t}px`,this.canvas.style.height=`${e.height*i}px`,this.updateWasmPixelSize(),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}this.resizeEmitter.fire({cols:t,rows:i})}catch(e){console.error("Terminal resize failed:",e)}this.isOpen&&(this.flushWriteQueue(),this.requestRender())}}reset(){this.assertOpen(),this.wasmTerm&&this.wasmTerm.free();const t=this.buildWasmConfig();this.wasmTerm=this.ghostty.createTerminal(this.cols,this.rows,t),this.updateWasmPixelSize(),this.armBootstrapBlank(),this.renderer.clear(),this.renderer.render(this.bootstrapBuffer,!0,this.viewportY,this,this.scrollbarOpacity),this.currentTitle=""}clear(){this.assertOpen(),this.wasmTerm.write("\x1B[2J\x1B[H")}focus(){if(this.isOpen){const t=this.textarea||this.element;t&&(t.focus(),setTimeout(()=>t==null?void 0:t.focus(),0))}}blur(){this.isOpen&&this.element&&this.element.blur()}loadAddon(t){t.activate(this),this.addons.push(t)}getMode(t,i=!1){return this.wasmTerm?this.wasmTerm.getMode(t,i):!1}hasBracketedPaste(){return this.wasmTerm?this.wasmTerm.hasBracketedPaste():!1}hasFocusEvents(){return this.wasmTerm?this.wasmTerm.hasFocusEvents():!1}hasMouseTracking(){return this.wasmTerm?this.wasmTerm.hasMouseTracking():!1}getSelection(){var t;return((t=this.selectionManager)==null?void 0:t.getSelection())||""}hasSelection(){var t;return((t=this.selectionManager)==null?void 0:t.hasSelection())||!1}clearSelection(){var t;(t=this.selectionManager)==null||t.clearSelection()}copySelection(){var t;return((t=this.selectionManager)==null?void 0:t.copySelection())||!1}selectAll(){var t;(t=this.selectionManager)==null||t.selectAll()}select(t,i,e){var s;(s=this.selectionManager)==null||s.select(t,i,e)}selectLines(t,i){var e;(e=this.selectionManager)==null||e.selectLines(t,i)}getSelectionPosition(){var t;return(t=this.selectionManager)==null?void 0:t.getSelectionPosition()}attachCustomKeyEventHandler(t){this.customKeyEventHandler=t,this.inputHandler&&this.inputHandler.setCustomKeyEventHandler(t)}attachCustomWheelEventHandler(t){this.customWheelEventHandler=t}registerLinkProvider(t){if(!this.linkDetector)throw new Error("Terminal must be opened before registering link providers");this.linkDetector.registerProvider(t)}scrollLines(t){if(!this.wasmTerm)throw new Error("Terminal not open");const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,this.viewportY-t));e!==this.viewportY&&(this.viewportY=e,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar(),this.requestRender())}scrollPages(t){this.scrollLines(t*this.rows)}scrollToTop(){const t=this.getScrollbackLength();t>0&&this.viewportY!==t&&(this.viewportY=t,this.scrollEmitter.fire(this.viewportY),this.showScrollbar(),this.requestRender())}scrollToBottom(){this.viewportY!==0&&(this.viewportY=0,this.scrollEmitter.fire(this.viewportY),this.getScrollbackLength()>0&&this.showScrollbar(),this.requestRender())}scrollToLine(t){const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,t));e!==this.viewportY&&(this.viewportY=e,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar(),this.requestRender())}dispose(){this.isDisposed||(this.isOpen=!1,this.cancelRenderLoop(),this.writeQueue.length=0,this.scrollAnimationFrame&&(cancelAnimationFrame(this.scrollAnimationFrame),this.scrollAnimationFrame=void 0),this.mouseMoveThrottleTimeout&&(clearTimeout(this.mouseMoveThrottleTimeout),this.mouseMoveThrottleTimeout=void 0),this.pendingMouseMove=void 0,this.cleanupComponents(),this.selectionChangeEmitter.dispose(),this.keyEmitter.dispose(),this.renderEmitter.dispose(),this.mouseCursorChangeEmitter.dispose(),super.dispose())}processTerminalResponses(){if(this.wasmTerm)for(;;){const t=this.wasmTerm.readResponse();if(t===null)break;this.dataEmitter.fire(t)}}updateWasmPixelSize(){if(!this.renderer||!this.wasmTerm)return;const t=this.renderer.getMetrics();this.wasmTerm.setCellPixelSize(t.width,t.height)}cancelRenderLoop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}flushWriteQueue(){for(;this.writeQueue.length>0;){const t=this.writeQueue.shift();this.wasmTerm.write(t)}}requestRender(){this.animationFrameId===void 0&&(this.isDisposed||!this.isOpen||(this.animationFrameId=requestAnimationFrame(this.renderTick)))}syncTextareaToCursor(t,i){if(!this.textarea||!this.renderer)return;const e=this.renderer.charWidth,s=this.renderer.charHeight;!e||!s||(this.textarea.style.left=`${t*e}px`,this.textarea.style.top=`${i*s}px`)}interceptOsc22(t){const i=/\x1b\]22;([^\x07\x1b]*)(?:\x07|\x1b\\)/g;let e;for(;(e=i.exec(t))!==null;){const s=e[1].replace(/_/g,"-")||"default";s!==this.lastOsc22Cursor&&(this.lastOsc22Cursor=s,this.canvas&&(this.canvas.style.cursor=s),this.element&&(this.element.style.cursor=s),this.mouseCursorChangeEmitter.fire(s))}}armBootstrapBlank(){const t={...T,...this.options.theme};this.bootstrapCells=J(this.cols,this.rows,{foreground:t.foreground,background:t.background}),this.bootstrapDirty=!0}disarmBootstrapBlank(){this.bootstrapCells&&(this.bootstrapCells=null,this.bootstrapDirty=!0)}cleanupComponents(){this.selectionManager&&(this.selectionManager.dispose(),this.selectionManager=void 0),this.inputHandler&&(this.inputHandler.dispose(),this.inputHandler=void 0),this.renderer&&(this.renderer.dispose(),this.renderer=void 0),this.canvas&&this.canvas.parentNode&&(this.canvas.parentNode.removeChild(this.canvas),this.canvas=void 0),this.textarea&&this.textarea.parentNode&&(this.textarea.parentNode.removeChild(this.textarea),this.textarea=void 0),this.element&&(this.element.removeEventListener("wheel",this.handleWheel),this.element.removeEventListener("mousedown",this.handleMouseDown,{capture:!0}),this.element.removeEventListener("mousemove",this.handleMouseMove),this.element.removeEventListener("mouseleave",this.handleMouseLeave),this.element.removeEventListener("click",this.handleClick),this.element.removeAttribute("role"),this.element.removeAttribute("aria-label"),this.element.removeAttribute("aria-multiline")),this.isOpen&&typeof document<"u"&&document.removeEventListener("mouseup",this.handleMouseUp),this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.linkDetector&&(this.linkDetector.dispose(),this.linkDetector=void 0),this.element=void 0,this.textarea=void 0}assertOpen(){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.isOpen)throw new Error("Terminal must be opened before use. Call terminal.open(parent) first.")}smoothScrollTo(t){if(!this.wasmTerm)return;const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,t));if((this.options.smoothScrollDuration??100)===0){this.viewportY=e,this.targetViewportY=e,this.scrollEmitter.fire(Math.floor(this.viewportY)),i>0&&this.showScrollbar(),this.requestRender();return}this.targetViewportY=e,!this.scrollAnimationFrame&&(this.scrollAnimationStartTime=Date.now(),this.scrollAnimationStartY=this.viewportY,this.animateScroll())}showScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible?this.scrollbarOpacity=1:(this.scrollbarVisible=!0,this.scrollbarOpacity=0,this.fadeInScrollbar()),this.isDraggingScrollbar||(this.scrollbarHideTimeout=window.setTimeout(()=>{this.hideScrollbar()},this.SCROLLBAR_HIDE_DELAY_MS))}hideScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible&&this.fadeOutScrollbar()}fadeInScrollbar(){const t=Date.now(),i=()=>{const e=Date.now()-t,s=Math.min(e/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=s,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),s<1&&requestAnimationFrame(i)};i()}fadeOutScrollbar(){const t=Date.now(),i=this.scrollbarOpacity,e=()=>{const s=Date.now()-t,r=Math.min(s/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=i*(1-r),this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),r<1?requestAnimationFrame(e):(this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,0))};e()}processMouseMove(t){if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const i=this.canvas.getBoundingClientRect(),e=Math.floor((t.clientX-i.left)/this.renderer.charWidth),r=Math.floor((t.clientY-i.top)/this.renderer.charHeight);let n=0,o=null;const h=this.getViewportY(),c=Math.max(0,Math.floor(h));if(c>0){const g=this.wasmTerm.getScrollbackLength();if(r<c){const w=g-c+r;o=this.wasmTerm.getScrollbackLine(w)}else{const w=r-c;o=this.wasmTerm.getLine(w)}}else o=this.wasmTerm.getLine(r);o&&e>=0&&e<o.length&&(n=o[e].hyperlink_id);const l=this.renderer.hoveredHyperlinkId||0;n!==l&&this.renderer.setHoveredHyperlinkId(n);const u=this.wasmTerm.getScrollbackLength();let d;const p=this.getViewportY(),m=Math.max(0,Math.floor(p));if(m>0)if(r<m)d=u-m+r;else{const g=r-m;d=u+g}else d=u+r;this.linkDetector.getLinkAt(e,d).then(g=>{var w,C,y,f;if(g!==this.currentHoveredLink){(C=(w=this.currentHoveredLink)==null?void 0:w.hover)==null||C.call(w,!1),this.currentHoveredLink=g,(y=g==null?void 0:g.hover)==null||y.call(g,!0);const b=g?"pointer":"text";if(this.element&&(this.element.style.cursor=b),this.canvas&&(this.canvas.style.cursor=b),this.renderer)if(g){const S=((f=this.wasmTerm)==null?void 0:f.getScrollbackLength())||0,k=this.getViewportY(),I=Math.max(0,Math.floor(k)),P=g.range.start.y-S+I,A=g.range.end.y-S+I;P<this.rows&&A>=0?this.renderer.setHoveredLinkRange({startX:g.range.start.x,startY:Math.max(0,P),endX:g.range.end.x,endY:Math.min(this.rows-1,A)}):this.renderer.setHoveredLinkRange(null)}else this.renderer.setHoveredLinkRange(null)}}).catch(g=>{console.warn("Link detection error:",g)})}processScrollbarDrag(t){if(!this.canvas||!this.renderer||!this.wasmTerm||this.scrollbarDragStart===null)return;const i=this.wasmTerm.getScrollbackLength();if(i===0)return;const e=this.canvas.getBoundingClientRect(),r=t.clientY-e.top-this.scrollbarDragStart,h=e.height-4*2,c=this.rows,l=i+c,u=Math.max(20,c/l*h),d=-r/(h-u),p=Math.round(d*i),m=this.scrollbarDragStartViewportY+p;this.scrollToLine(Math.max(0,Math.min(i,m)))}};W.SYNC_OUTPUT_TIMEOUT_MS=500;let j=W;const Z=2,tt=1,et=15,it=100;class st{constructor(){this._isResizing=!1}activate(t){this._terminal=t}dispose(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeDebounceTimer&&(clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=void 0),this._lastCols=void 0,this._lastRows=void 0,this._terminal=void 0}fit(){if(this._isResizing)return;const t=this.proposeDimensions();if(!t||!this._terminal)return;const i=this._terminal,e=i.cols,s=i.rows;if(!(t.cols===this._lastCols&&t.rows===this._lastRows||t.cols===e&&t.rows===s)){this._lastCols=t.cols,this._lastRows=t.rows,this._isResizing=!0;try{i.resize&&typeof i.resize=="function"&&i.resize(t.cols,t.rows)}finally{setTimeout(()=>{this._isResizing=!1},50)}}}proposeDimensions(){var w;if(!((w=this._terminal)!=null&&w.element))return;const i=this._terminal.renderer;if(!i||typeof i.getMetrics!="function")return;const e=i.getMetrics();if(!e||e.width===0||e.height===0)return;const s=this._terminal.element;if(typeof s.clientWidth>"u")return;const r=window.getComputedStyle(s),n=Number.parseInt(r.getPropertyValue("padding-top"))||0,o=Number.parseInt(r.getPropertyValue("padding-bottom"))||0,h=Number.parseInt(r.getPropertyValue("padding-left"))||0,c=Number.parseInt(r.getPropertyValue("padding-right"))||0,l=s.clientWidth,u=s.clientHeight;if(l===0||u===0)return;const d=l-h-c-et,p=u-n-o,m=Math.max(Z,Math.floor(d/e.width)),g=Math.max(tt,Math.floor(p/e.height));return{cols:m,rows:g}}observeResize(){var t;(t=this._terminal)!=null&&t.element&&(this._resizeObserver||(this._resizeObserver=new ResizeObserver(i=>{this._isResizing||!i[0]||(this._resizeDebounceTimer&&clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=setTimeout(()=>{this.fit()},it))}),this._resizeObserver.observe(this._terminal.element)))}}class rt{constructor(){this._pasteListener=null,this._emitter=new a.EventEmitter,this.onImagePaste=this._emitter.event}activate(t){this._terminal=t;const i=t.element;i&&this._attachListener(i)}dispose(){this._detachListener(),this._emitter.dispose(),this._terminal=void 0}_attachListener(t){this._pasteListener=i=>{const e=i.clipboardData;if(e!=null&&e.items){for(const s of Array.from(e.items))if(s.kind==="file"&&s.type.startsWith("image/")){const r=s.getAsFile();if(r){i.preventDefault(),i.stopPropagation();const n=new FileReader;n.onload=()=>{const h=n.result.split(",")[1];if(h){const c=r.type.split("/")[1]||"png";this._emitter.fire({name:`clipboard_${Date.now()}.${c}`,dataBase64:h})}},n.readAsDataURL(r);return}}}},t.addEventListener("paste",this._pasteListener)}_detachListener(){var t;this._pasteListener&&((t=this._terminal)!=null&&t.element)&&this._terminal.element.removeEventListener("paste",this._pasteListener),this._pasteListener=null}}let R=null;async function nt(){R||(R=await a.Ghostty.load())}function G(){if(!R)throw new Error(`ghostty-web not initialized. Call init() before creating Terminal instances.
6
+ `,i);else{const e=new Uint8Array(t.length+2);e.set(t),e[t.length]=13,e[t.length+1]=10,this.write(e,i)}}paste(t){this.assertOpen(),!this.options.disableStdin&&(this.awaitingEcho=!0,this.wasmTerm.hasBracketedPaste()?this.dataEmitter.fire("\x1B[200~"+t+"\x1B[201~"):this.dataEmitter.fire(t))}input(t,i=!1){this.assertOpen(),!this.options.disableStdin&&(i?(this.awaitingEcho=!0,this.dataEmitter.fire(t)):this.write(t))}resize(t,i){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.wasmTerm)throw new Error("Terminal not initialized");if(!(t===this.cols&&i===this.rows)){this.isOpen&&this.cancelRenderLoop();try{if(this.cols=t,this.rows=i,this.wasmTerm.resize(t,i),this.renderer&&this.canvas){this.renderer.resize(t,i);const e=this.renderer.getMetrics();this.canvas.width=e.width*t,this.canvas.height=e.height*i,this.canvas.style.width=`${e.width*t}px`,this.canvas.style.height=`${e.height*i}px`,this.updateWasmPixelSize(),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}this.resizeEmitter.fire({cols:t,rows:i})}catch(e){console.error("Terminal resize failed:",e)}this.isOpen&&(this.flushWriteQueue(),this.requestRender())}}reset(){this.assertOpen(),this.wasmTerm&&this.wasmTerm.free();const t=this.buildWasmConfig();this.wasmTerm=this.ghostty.createTerminal(this.cols,this.rows,t),this.updateWasmPixelSize(),this.armBootstrapBlank(),this.renderer.clear(),this.renderer.render(this.bootstrapBuffer,!0,this.viewportY,this,this.scrollbarOpacity),this.currentTitle=""}clear(){this.assertOpen(),this.wasmTerm.write("\x1B[2J\x1B[H")}focus(){if(this.isOpen){const t=this.textarea||this.element;t&&(t.focus(),setTimeout(()=>t==null?void 0:t.focus(),0))}}blur(){this.isOpen&&this.element&&this.element.blur()}loadAddon(t){t.activate(this),this.addons.push(t)}getMode(t,i=!1){return this.wasmTerm?this.wasmTerm.getMode(t,i):!1}hasBracketedPaste(){return this.wasmTerm?this.wasmTerm.hasBracketedPaste():!1}hasFocusEvents(){return this.wasmTerm?this.wasmTerm.hasFocusEvents():!1}hasMouseTracking(){return this.wasmTerm?this.wasmTerm.hasMouseTracking():!1}getSelection(){var t;return((t=this.selectionManager)==null?void 0:t.getSelection())||""}hasSelection(){var t;return((t=this.selectionManager)==null?void 0:t.hasSelection())||!1}clearSelection(){var t;(t=this.selectionManager)==null||t.clearSelection()}copySelection(){var t;return((t=this.selectionManager)==null?void 0:t.copySelection())||!1}selectAll(){var t;(t=this.selectionManager)==null||t.selectAll()}select(t,i,e){var s;(s=this.selectionManager)==null||s.select(t,i,e)}selectLines(t,i){var e;(e=this.selectionManager)==null||e.selectLines(t,i)}getSelectionPosition(){var t;return(t=this.selectionManager)==null?void 0:t.getSelectionPosition()}attachCustomKeyEventHandler(t){this.customKeyEventHandler=t,this.inputHandler&&this.inputHandler.setCustomKeyEventHandler(t)}attachCustomWheelEventHandler(t){this.customWheelEventHandler=t}registerLinkProvider(t){if(!this.linkDetector)throw new Error("Terminal must be opened before registering link providers");this.linkDetector.registerProvider(t)}scrollLines(t){if(!this.wasmTerm)throw new Error("Terminal not open");const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,this.viewportY-t));e!==this.viewportY&&(this.viewportY=e,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar(),this.requestRender())}scrollPages(t){this.scrollLines(t*this.rows)}scrollToTop(){const t=this.getScrollbackLength();t>0&&this.viewportY!==t&&(this.viewportY=t,this.scrollEmitter.fire(this.viewportY),this.showScrollbar(),this.requestRender())}scrollToBottom(){this.viewportY!==0&&(this.viewportY=0,this.scrollEmitter.fire(this.viewportY),this.getScrollbackLength()>0&&this.showScrollbar(),this.requestRender())}scrollToLine(t){const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,t));e!==this.viewportY&&(this.viewportY=e,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar(),this.requestRender())}dispose(){this.isDisposed||(this.isOpen=!1,this.cancelRenderLoop(),this.writeQueue.length=0,this.scrollAnimationFrame&&(cancelAnimationFrame(this.scrollAnimationFrame),this.scrollAnimationFrame=void 0),this.mouseMoveThrottleTimeout&&(clearTimeout(this.mouseMoveThrottleTimeout),this.mouseMoveThrottleTimeout=void 0),this.pendingMouseMove=void 0,this.cleanupComponents(),this.selectionChangeEmitter.dispose(),this.keyEmitter.dispose(),this.renderEmitter.dispose(),this.mouseCursorChangeEmitter.dispose(),super.dispose())}processTerminalResponses(){if(this.wasmTerm)for(;;){const t=this.wasmTerm.readResponse();if(t===null)break;this.dataEmitter.fire(t)}}updateWasmPixelSize(){if(!this.renderer||!this.wasmTerm)return;const t=this.renderer.getMetrics();this.wasmTerm.setCellPixelSize(t.width,t.height)}cancelRenderLoop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}flushWriteQueue(){for(;this.writeQueue.length>0;){const t=this.writeQueue.shift();this.wasmTerm.write(t)}}requestRender(){this.animationFrameId===void 0&&(this.isDisposed||!this.isOpen||(this.animationFrameId=requestAnimationFrame(this.renderTick)))}syncTextareaToCursor(t,i){if(!this.textarea||!this.renderer)return;const e=this.renderer.charWidth,s=this.renderer.charHeight;!e||!s||(this.textarea.style.left=`${t*e}px`,this.textarea.style.top=`${i*s}px`)}interceptOsc22(t){const i=/\x1b\]22;([^\x07\x1b]*)(?:\x07|\x1b\\)/g;let e;for(;(e=i.exec(t))!==null;){const s=e[1].replace(/_/g,"-")||"default";s!==this.lastOsc22Cursor&&(this.lastOsc22Cursor=s,this.canvas&&(this.canvas.style.cursor=s),this.element&&(this.element.style.cursor=s),this.mouseCursorChangeEmitter.fire(s))}}armBootstrapBlank(){const t={...x,...this.options.theme};this.bootstrapCells=J(this.cols,this.rows,{foreground:t.foreground,background:t.background}),this.bootstrapDirty=!0}disarmBootstrapBlank(){this.bootstrapCells&&(this.bootstrapCells=null,this.bootstrapDirty=!0)}cleanupComponents(){this.selectionManager&&(this.selectionManager.dispose(),this.selectionManager=void 0),this.inputHandler&&(this.inputHandler.dispose(),this.inputHandler=void 0),this.renderer&&(this.renderer.dispose(),this.renderer=void 0),this.canvas&&this.canvas.parentNode&&(this.canvas.parentNode.removeChild(this.canvas),this.canvas=void 0),this.textarea&&this.textarea.parentNode&&(this.textarea.parentNode.removeChild(this.textarea),this.textarea=void 0),this.element&&(this.element.removeEventListener("wheel",this.handleWheel),this.element.removeEventListener("mousedown",this.handleMouseDown,{capture:!0}),this.element.removeEventListener("mousemove",this.handleMouseMove),this.element.removeEventListener("mouseleave",this.handleMouseLeave),this.element.removeEventListener("click",this.handleClick),this.element.removeAttribute("role"),this.element.removeAttribute("aria-label"),this.element.removeAttribute("aria-multiline")),this.isOpen&&typeof document<"u"&&document.removeEventListener("mouseup",this.handleMouseUp),this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.linkDetector&&(this.linkDetector.dispose(),this.linkDetector=void 0),this.element=void 0,this.textarea=void 0}assertOpen(){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.isOpen)throw new Error("Terminal must be opened before use. Call terminal.open(parent) first.")}smoothScrollTo(t){if(!this.wasmTerm)return;const i=this.getScrollbackLength(),e=Math.max(0,Math.min(i,t));if((this.options.smoothScrollDuration??100)===0){this.viewportY=e,this.targetViewportY=e,this.scrollEmitter.fire(Math.floor(this.viewportY)),i>0&&this.showScrollbar(),this.requestRender();return}this.targetViewportY=e,!this.scrollAnimationFrame&&(this.scrollAnimationStartTime=Date.now(),this.scrollAnimationStartY=this.viewportY,this.animateScroll())}showScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible?this.scrollbarOpacity=1:(this.scrollbarVisible=!0,this.scrollbarOpacity=0,this.fadeInScrollbar()),this.isDraggingScrollbar||(this.scrollbarHideTimeout=window.setTimeout(()=>{this.hideScrollbar()},this.SCROLLBAR_HIDE_DELAY_MS))}hideScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible&&this.fadeOutScrollbar()}fadeInScrollbar(){const t=Date.now(),i=()=>{const e=Date.now()-t,s=Math.min(e/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=s,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),s<1&&requestAnimationFrame(i)};i()}fadeOutScrollbar(){const t=Date.now(),i=this.scrollbarOpacity,e=()=>{const s=Date.now()-t,r=Math.min(s/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=i*(1-r),this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),r<1?requestAnimationFrame(e):(this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,0))};e()}processMouseMove(t){if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const i=this.canvas.getBoundingClientRect(),e=Math.floor((t.clientX-i.left)/this.renderer.charWidth),r=Math.floor((t.clientY-i.top)/this.renderer.charHeight);let n=0,o=null;const h=this.getViewportY(),c=Math.max(0,Math.floor(h));if(c>0){const g=this.wasmTerm.getScrollbackLength();if(r<c){const w=g-c+r;o=this.wasmTerm.getScrollbackLine(w)}else{const w=r-c;o=this.wasmTerm.getLine(w)}}else o=this.wasmTerm.getLine(r);o&&e>=0&&e<o.length&&(n=o[e].hyperlink_id);const l=this.renderer.hoveredHyperlinkId||0;n!==l&&this.renderer.setHoveredHyperlinkId(n);const u=this.wasmTerm.getScrollbackLength();let d;const p=this.getViewportY(),f=Math.max(0,Math.floor(p));if(f>0)if(r<f)d=u-f+r;else{const g=r-f;d=u+g}else d=u+r;this.linkDetector.getLinkAt(e,d).then(g=>{var w,C,y,m;if(g!==this.currentHoveredLink){(C=(w=this.currentHoveredLink)==null?void 0:w.hover)==null||C.call(w,!1),this.currentHoveredLink=g,(y=g==null?void 0:g.hover)==null||y.call(g,!0);const b=g?"pointer":"text";if(this.element&&(this.element.style.cursor=b),this.canvas&&(this.canvas.style.cursor=b),this.renderer)if(g){const S=((m=this.wasmTerm)==null?void 0:m.getScrollbackLength())||0,k=this.getViewportY(),I=Math.max(0,Math.floor(k)),P=g.range.start.y-S+I,A=g.range.end.y-S+I;P<this.rows&&A>=0?this.renderer.setHoveredLinkRange({startX:g.range.start.x,startY:Math.max(0,P),endX:g.range.end.x,endY:Math.min(this.rows-1,A)}):this.renderer.setHoveredLinkRange(null)}else this.renderer.setHoveredLinkRange(null)}}).catch(g=>{console.warn("Link detection error:",g)})}processScrollbarDrag(t){if(!this.canvas||!this.renderer||!this.wasmTerm||this.scrollbarDragStart===null)return;const i=this.wasmTerm.getScrollbackLength();if(i===0)return;const e=this.canvas.getBoundingClientRect(),r=t.clientY-e.top-this.scrollbarDragStart,h=e.height-4*2,c=this.rows,l=i+c,u=Math.max(20,c/l*h),d=-r/(h-u),p=Math.round(d*i),f=this.scrollbarDragStartViewportY+p;this.scrollToLine(Math.max(0,Math.min(i,f)))}};W.SYNC_OUTPUT_TIMEOUT_MS=500;let j=W;const Z=2,tt=1,et=15,it=100;class st{constructor(){this._isResizing=!1}activate(t){this._terminal=t}dispose(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeDebounceTimer&&(clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=void 0),this._lastCols=void 0,this._lastRows=void 0,this._terminal=void 0}fit(){if(this._isResizing)return;const t=this.proposeDimensions();if(!t||!this._terminal)return;const i=this._terminal,e=i.cols,s=i.rows;if(!(t.cols===this._lastCols&&t.rows===this._lastRows||t.cols===e&&t.rows===s)){this._lastCols=t.cols,this._lastRows=t.rows,this._isResizing=!0;try{i.resize&&typeof i.resize=="function"&&i.resize(t.cols,t.rows)}finally{setTimeout(()=>{this._isResizing=!1},50)}}}proposeDimensions(){var w;if(!((w=this._terminal)!=null&&w.element))return;const i=this._terminal.renderer;if(!i||typeof i.getMetrics!="function")return;const e=i.getMetrics();if(!e||e.width===0||e.height===0)return;const s=this._terminal.element;if(typeof s.clientWidth>"u")return;const r=window.getComputedStyle(s),n=Number.parseInt(r.getPropertyValue("padding-top"))||0,o=Number.parseInt(r.getPropertyValue("padding-bottom"))||0,h=Number.parseInt(r.getPropertyValue("padding-left"))||0,c=Number.parseInt(r.getPropertyValue("padding-right"))||0,l=s.clientWidth,u=s.clientHeight;if(l===0||u===0)return;const d=l-h-c-et,p=u-n-o,f=Math.max(Z,Math.floor(d/e.width)),g=Math.max(tt,Math.floor(p/e.height));return{cols:f,rows:g}}observeResize(){var t;(t=this._terminal)!=null&&t.element&&(this._resizeObserver||(this._resizeObserver=new ResizeObserver(i=>{this._isResizing||!i[0]||(this._resizeDebounceTimer&&clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=setTimeout(()=>{this.fit()},it))}),this._resizeObserver.observe(this._terminal.element)))}}class rt{constructor(){this._pasteListener=null,this._emitter=new a.EventEmitter,this.onImagePaste=this._emitter.event}activate(t){this._terminal=t;const i=t.element;i&&this._attachListener(i)}dispose(){this._detachListener(),this._emitter.dispose(),this._terminal=void 0}_attachListener(t){this._pasteListener=i=>{const e=i.clipboardData;if(e!=null&&e.items){for(const s of Array.from(e.items))if(s.kind==="file"&&s.type.startsWith("image/")){const r=s.getAsFile();if(r){i.preventDefault(),i.stopPropagation();const n=new FileReader;n.onload=()=>{const h=n.result.split(",")[1];if(h){const c=r.type.split("/")[1]||"png";this._emitter.fire({name:`clipboard_${Date.now()}.${c}`,dataBase64:h})}},n.readAsDataURL(r);return}}}},t.addEventListener("paste",this._pasteListener)}_detachListener(){var t;this._pasteListener&&((t=this._terminal)!=null&&t.element)&&this._terminal.element.removeEventListener("paste",this._pasteListener),this._pasteListener=null}}let R=null;async function nt(){R||(R=await a.Ghostty.load())}function G(){if(!R)throw new Error(`ghostty-web not initialized. Call init() before creating Terminal instances.
7
7
  Example:
8
8
  import { init, Terminal } from "ghostty-web";
9
9
  await init();
@@ -12,4 +12,4 @@ Example:
12
12
  For tests, pass a Ghostty instance directly:
13
13
  import { Ghostty, Terminal } from "ghostty-web";
14
14
  const ghostty = await Ghostty.load();
15
- const term = new Terminal({ ghostty });`);return R}exports.CellFlags=a.CellFlags;exports.DirtyState=a.DirtyState;exports.EventEmitter=a.EventEmitter;exports.Ghostty=a.Ghostty;exports.GhosttyTerminal=a.GhosttyTerminal;exports.Key=a.Key;exports.KeyAction=a.KeyAction;exports.KeyEncoder=a.KeyEncoder;exports.KeyEncoderOption=a.KeyEncoderOption;exports.Mods=a.Mods;exports.TerminalCore=a.TerminalCore;exports.CanvasRenderer=U;exports.FitAddon=st;exports.ImagePasteAddon=rt;exports.InputHandler=F;exports.LinkDetector=O;exports.OSC8LinkProvider=Y;exports.SelectionManager=V;exports.Terminal=j;exports.UrlRegexProvider=N;exports.getGhostty=G;exports.init=nt;
15
+ const term = new Terminal({ ghostty });`);return R}exports.CellFlags=a.CellFlags;exports.DirtyState=a.DirtyState;exports.EventEmitter=a.EventEmitter;exports.Ghostty=a.Ghostty;exports.GhosttyTerminal=a.GhosttyTerminal;exports.Key=a.Key;exports.KeyAction=a.KeyAction;exports.KeyEncoder=a.KeyEncoder;exports.KeyEncoderOption=a.KeyEncoderOption;exports.Mods=a.Mods;exports.TerminalCore=a.TerminalCore;exports.CanvasRenderer=U;exports.FitAddon=st;exports.ImagePasteAddon=rt;exports.InputHandler=B;exports.LinkDetector=O;exports.OSC8LinkProvider=Y;exports.SelectionManager=V;exports.Terminal=j;exports.UrlRegexProvider=N;exports.getGhostty=G;exports.init=nt;
@@ -677,14 +677,14 @@ class J {
677
677
  let u;
678
678
  if (h < 0 ? u = this.terminal.wasmTerm.getScrollbackHyperlinkUri(t, n) : u = this.terminal.wasmTerm.getHyperlinkUri(h, n), u) {
679
679
  let d = n;
680
- for (let m = n + 1; m < r.length; m++) {
681
- const g = r.getCell(m);
682
- if (!g || g.getHyperlinkId() === 0 || (h < 0 ? this.terminal.wasmTerm.getScrollbackHyperlinkUri(t, m) : this.terminal.wasmTerm.getHyperlinkUri(h, m)) !== u)
680
+ for (let f = n + 1; f < r.length; f++) {
681
+ const g = r.getCell(f);
682
+ if (!g || g.getHyperlinkId() === 0 || (h < 0 ? this.terminal.wasmTerm.getScrollbackHyperlinkUri(t, f) : this.terminal.wasmTerm.getHyperlinkUri(h, f)) !== u)
683
683
  break;
684
- d = m;
684
+ d = f;
685
685
  }
686
- for (let m = n; m <= d; m++)
687
- s.add(m);
686
+ for (let f = n; f <= d; f++)
687
+ s.add(f);
688
688
  const p = {
689
689
  start: { x: n, y: t },
690
690
  end: { x: d, y: t }
@@ -692,8 +692,8 @@ class J {
692
692
  e.push({
693
693
  text: u,
694
694
  range: p,
695
- activate: (m) => {
696
- (m.ctrlKey || m.metaKey) && window.open(u, "_blank", "noopener,noreferrer");
695
+ activate: (f) => {
696
+ (f.ctrlKey || f.metaKey) && window.open(u, "_blank", "noopener,noreferrer");
697
697
  }
698
698
  });
699
699
  }
@@ -727,8 +727,8 @@ class J {
727
727
  break;
728
728
  r = h, n = 0;
729
729
  for (let p = u.length - 1; p >= 0; p--) {
730
- const m = u.getCell(p);
731
- if (!m || m.getHyperlinkId() !== t) {
730
+ const f = u.getCell(p);
731
+ if (!f || f.getHyperlinkId() !== t) {
732
732
  n = p + 1;
733
733
  break;
734
734
  }
@@ -759,15 +759,15 @@ class J {
759
759
  if (!p || p.getHyperlinkId() !== t)
760
760
  break;
761
761
  o = h, a = 0;
762
- for (let m = 0; m < d.length; m++) {
763
- const g = d.getCell(m);
762
+ for (let f = 0; f < d.length; f++) {
763
+ const g = d.getCell(f);
764
764
  if (!g)
765
765
  break;
766
766
  if (g.getHyperlinkId() !== t) {
767
- a = m - 1;
767
+ a = f - 1;
768
768
  break;
769
769
  }
770
- a = m;
770
+ a = f;
771
771
  }
772
772
  if (a === d.length - 1)
773
773
  h++;
@@ -1261,46 +1261,46 @@ class it {
1261
1261
  const h = n.x !== this.lastCursorPosition.x || n.y !== this.lastCursorPosition.y;
1262
1262
  if (h || this.cursorBlink) {
1263
1263
  if (!i && !t.isRowDirty(n.y)) {
1264
- const f = t.getLine(n.y);
1265
- f && this.renderLine(f, n.y, o.cols);
1264
+ const m = t.getLine(n.y);
1265
+ m && this.renderLine(m, n.y, o.cols);
1266
1266
  }
1267
1267
  if (h && !i) {
1268
- const f = t.getLine(this.lastCursorPosition.y);
1269
- f && this.renderLine(f, this.lastCursorPosition.y, o.cols);
1268
+ const m = t.getLine(this.lastCursorPosition.y);
1269
+ m && this.renderLine(m, this.lastCursorPosition.y, o.cols);
1270
1270
  }
1271
1271
  }
1272
1272
  const u = this.selectionManager && this.selectionManager.hasSelection(), d = /* @__PURE__ */ new Set();
1273
1273
  if (this.currentSelectionCoords = u ? this.selectionManager.getSelectionCoords() : null, this.currentSelectionCoords) {
1274
- const f = this.currentSelectionCoords;
1275
- for (let v = f.startRow; v <= f.endRow; v++)
1274
+ const m = this.currentSelectionCoords;
1275
+ for (let v = m.startRow; v <= m.endRow; v++)
1276
1276
  d.add(v);
1277
1277
  }
1278
1278
  if (this.selectionManager) {
1279
- const f = this.selectionManager.getDirtySelectionRows();
1280
- if (f.size > 0) {
1281
- for (const v of f)
1279
+ const m = this.selectionManager.getDirtySelectionRows();
1280
+ if (m.size > 0) {
1281
+ for (const v of m)
1282
1282
  d.add(v);
1283
1283
  this.selectionManager.clearDirtySelectionRows();
1284
1284
  }
1285
1285
  }
1286
- const p = /* @__PURE__ */ new Set(), m = this.hoveredHyperlinkId !== this.previousHoveredHyperlinkId, g = JSON.stringify(this.hoveredLinkRange) !== JSON.stringify(this.previousHoveredLinkRange);
1287
- if (m) {
1288
- for (let f = 0; f < o.rows; f++) {
1286
+ const p = /* @__PURE__ */ new Set(), f = this.hoveredHyperlinkId !== this.previousHoveredHyperlinkId, g = JSON.stringify(this.hoveredLinkRange) !== JSON.stringify(this.previousHoveredLinkRange);
1287
+ if (f) {
1288
+ for (let m = 0; m < o.rows; m++) {
1289
1289
  let v = null;
1290
1290
  if (e > 0)
1291
- if (f < e && s) {
1292
- const C = a - Math.floor(e) + f;
1291
+ if (m < e && s) {
1292
+ const C = a - Math.floor(e) + m;
1293
1293
  v = s.getScrollbackLine(C);
1294
1294
  } else {
1295
- const C = f - Math.floor(e);
1295
+ const C = m - Math.floor(e);
1296
1296
  v = t.getLine(C);
1297
1297
  }
1298
1298
  else
1299
- v = t.getLine(f);
1299
+ v = t.getLine(m);
1300
1300
  if (v) {
1301
1301
  for (const C of v)
1302
1302
  if (C.hyperlink_id === this.hoveredHyperlinkId || C.hyperlink_id === this.previousHoveredHyperlinkId) {
1303
- p.add(f);
1303
+ p.add(m);
1304
1304
  break;
1305
1305
  }
1306
1306
  }
@@ -1309,37 +1309,37 @@ class it {
1309
1309
  }
1310
1310
  if (g) {
1311
1311
  if (this.previousHoveredLinkRange)
1312
- for (let f = this.previousHoveredLinkRange.startY; f <= this.previousHoveredLinkRange.endY; f++)
1313
- p.add(f);
1312
+ for (let m = this.previousHoveredLinkRange.startY; m <= this.previousHoveredLinkRange.endY; m++)
1313
+ p.add(m);
1314
1314
  if (this.hoveredLinkRange)
1315
- for (let f = this.hoveredLinkRange.startY; f <= this.hoveredLinkRange.endY; f++)
1316
- p.add(f);
1315
+ for (let m = this.hoveredLinkRange.startY; m <= this.hoveredLinkRange.endY; m++)
1316
+ p.add(m);
1317
1317
  this.previousHoveredLinkRange = this.hoveredLinkRange;
1318
1318
  }
1319
1319
  let w = !1;
1320
1320
  const S = /* @__PURE__ */ new Set();
1321
- for (let f = 0; f < o.rows; f++)
1322
- (e > 0 ? !0 : i || t.isRowDirty(f) || d.has(f) || p.has(f) || this.kittyDamagedRows.has(f)) && (S.add(f), f > 0 && S.add(f - 1), f < o.rows - 1 && S.add(f + 1));
1323
- for (let f = 0; f < o.rows; f++) {
1324
- if (!S.has(f))
1321
+ for (let m = 0; m < o.rows; m++)
1322
+ (e > 0 ? !0 : i || t.isRowDirty(m) || d.has(m) || p.has(m) || this.kittyDamagedRows.has(m)) && (S.add(m), m > 0 && S.add(m - 1), m < o.rows - 1 && S.add(m + 1));
1323
+ for (let m = 0; m < o.rows; m++) {
1324
+ if (!S.has(m))
1325
1325
  continue;
1326
1326
  w = !0;
1327
1327
  let v = null;
1328
1328
  if (e > 0)
1329
- if (f < e && s) {
1330
- const C = a - Math.floor(e) + f;
1329
+ if (m < e && s) {
1330
+ const C = a - Math.floor(e) + m;
1331
1331
  v = s.getScrollbackLine(C);
1332
1332
  } else {
1333
- const C = e > 0 ? f - Math.floor(e) : f;
1333
+ const C = e > 0 ? m - Math.floor(e) : m;
1334
1334
  v = t.getLine(C);
1335
1335
  }
1336
1336
  else
1337
- v = t.getLine(f);
1338
- v && this.renderLine(v, f, o.cols);
1337
+ v = t.getLine(m);
1338
+ v && this.renderLine(v, m, o.cols);
1339
1339
  }
1340
1340
  if (this.currentDirectPlacements.length > 0 && w && this.renderKittyImages(), e === 0 && n.visible && this.cursorVisible) {
1341
- const f = n.style ?? this.cursorStyle;
1342
- this.renderCursor(n.x, n.y, f);
1341
+ const m = n.style ?? this.cursorStyle;
1342
+ this.renderCursor(n.x, n.y, m);
1343
1343
  }
1344
1344
  s && r > 0 && this.renderScrollbar(e, a, o.rows, r), this.lastCursorPosition = { x: n.x, y: n.y }, t.clearDirty();
1345
1345
  }
@@ -1378,7 +1378,7 @@ class it {
1378
1378
  return;
1379
1379
  }
1380
1380
  let a = t.bg_r, l = t.bg_g, h = t.bg_b;
1381
- t.flags & x.INVERSE && (a = t.fg_r, l = t.fg_g, h = t.fg_b), (t.flags & x.INVERSE ? t.fgIsDefault : t.bgIsDefault) || (this.ctx.fillStyle = this.rgbToCSS(a, l, h), this.ctx.fillRect(s, r, n, this.metrics.height));
1381
+ t.flags & x.INVERSE && (a = t.fg_r, l = t.fg_g, h = t.fg_b), t.flags & x.INVERSE ? (this.ctx.fillStyle = t.fgIsDefault ? this.theme.foreground : this.rgbToCSS(a, l, h), this.ctx.fillRect(s, r, n, this.metrics.height)) : t.bgIsDefault || (this.ctx.fillStyle = this.rgbToCSS(a, l, h), this.ctx.fillRect(s, r, n, this.metrics.height));
1382
1382
  }
1383
1383
  /**
1384
1384
  * Render a cell's text and decorations (Pass 2 of two-pass rendering)
@@ -1398,15 +1398,15 @@ class it {
1398
1398
  else if (a)
1399
1399
  this.ctx.fillStyle = this.theme.selectionForeground;
1400
1400
  else {
1401
- const b = t.flags & x.INVERSE ? t.bgIsDefault : t.fgIsDefault;
1402
- this.ctx.fillStyle = b ? this.theme.foreground : this.rgbToCSS(h, u, d);
1401
+ const b = t.flags & x.INVERSE ? t.bgIsDefault : t.fgIsDefault, m = t.flags & x.INVERSE ? this.theme.background : this.theme.foreground;
1402
+ this.ctx.fillStyle = b ? m : this.rgbToCSS(h, u, d);
1403
1403
  }
1404
1404
  t.flags & x.FAINT && (this.ctx.globalAlpha = 0.5);
1405
- const p = r, m = n + this.metrics.baseline;
1405
+ const p = r, f = n + this.metrics.baseline;
1406
1406
  let g;
1407
1407
  t.grapheme_len > 0 && ((S = this.currentBuffer) != null && S.getGraphemeString) ? g = this.currentBuffer.getGraphemeString(e, i) : g = String.fromCodePoint(t.codepoint || 32);
1408
1408
  const w = t.codepoint || 32;
1409
- if (this.renderBlockChar(w, r, n, o) || this.renderPowerlineGlyph(w, r, n, o) || this.ctx.fillText(g, p, m), t.flags & x.FAINT && (this.ctx.globalAlpha = 1), t.flags & x.UNDERLINE) {
1409
+ if (this.renderBlockChar(w, r, n, o) || this.renderPowerlineGlyph(w, r, n, o) || this.ctx.fillText(g, p, f), t.flags & x.FAINT && (this.ctx.globalAlpha = 1), t.flags & x.UNDERLINE) {
1410
1410
  const b = n + this.metrics.baseline + 2;
1411
1411
  this.ctx.strokeStyle = this.ctx.fillStyle, this.ctx.lineWidth = 1, this.ctx.beginPath(), this.ctx.moveTo(r, b), this.ctx.lineTo(r + o, b), this.ctx.stroke();
1412
1412
  }
@@ -1415,8 +1415,8 @@ class it {
1415
1415
  this.ctx.strokeStyle = this.ctx.fillStyle, this.ctx.lineWidth = 1, this.ctx.beginPath(), this.ctx.moveTo(r, b), this.ctx.lineTo(r + o, b), this.ctx.stroke();
1416
1416
  }
1417
1417
  if (t.hyperlink_id > 0 && t.hyperlink_id === this.hoveredHyperlinkId) {
1418
- const f = n + this.metrics.baseline + 2;
1419
- this.ctx.strokeStyle = "#4A90E2", this.ctx.lineWidth = 1, this.ctx.beginPath(), this.ctx.moveTo(r, f), this.ctx.lineTo(r + o, f), this.ctx.stroke();
1418
+ const m = n + this.metrics.baseline + 2;
1419
+ this.ctx.strokeStyle = "#4A90E2", this.ctx.lineWidth = 1, this.ctx.beginPath(), this.ctx.moveTo(r, m), this.ctx.lineTo(r + o, m), this.ctx.stroke();
1420
1420
  }
1421
1421
  if (this.hoveredLinkRange) {
1422
1422
  const b = this.hoveredLinkRange;
@@ -1680,8 +1680,8 @@ class it {
1680
1680
  }[t];
1681
1681
  if (d === void 0)
1682
1682
  return !1;
1683
- const p = Math.round(r / 2), m = Math.round(n / 2);
1684
- return d & o && this.ctx.fillRect(i, e, p, m), d & a && this.ctx.fillRect(i + p, e, r - p, m), d & l && this.ctx.fillRect(i, e + m, p, n - m), d & h && this.ctx.fillRect(i + p, e + m, r - p, n - m), !0;
1683
+ const p = Math.round(r / 2), f = Math.round(n / 2);
1684
+ return d & o && this.ctx.fillRect(i, e, p, f), d & a && this.ctx.fillRect(i + p, e, r - p, f), d & l && this.ctx.fillRect(i, e + f, p, n - f), d & h && this.ctx.fillRect(i + p, e + f, r - p, n - f), !0;
1685
1685
  }
1686
1686
  /**
1687
1687
  * Substitute a cell's text rendering with a slice of a kitty graphics
@@ -1724,15 +1724,15 @@ class it {
1724
1724
  const p = this.getOrDecodeKittyImage(s, r, h);
1725
1725
  if (!p)
1726
1726
  return !1;
1727
- const m = d.width / u.gridCols, g = d.height / u.gridRows, w = a * m, S = o * g, b = i * this.metrics.width, f = e * this.metrics.height, v = this.ctx.imageSmoothingEnabled;
1727
+ const f = d.width / u.gridCols, g = d.height / u.gridRows, w = a * f, S = o * g, b = i * this.metrics.width, m = e * this.metrics.height, v = this.ctx.imageSmoothingEnabled;
1728
1728
  return this.ctx.imageSmoothingEnabled = !1, this.ctx.drawImage(
1729
1729
  p,
1730
1730
  w,
1731
1731
  S,
1732
- m,
1732
+ f,
1733
1733
  g,
1734
1734
  b,
1735
- f,
1735
+ m,
1736
1736
  this.metrics.width,
1737
1737
  this.metrics.height
1738
1738
  ), this.ctx.imageSmoothingEnabled = v, !0;
@@ -1922,7 +1922,7 @@ class it {
1922
1922
  const r = this.ctx, n = this.canvas.height / this.devicePixelRatio, o = this.canvas.width / this.devicePixelRatio, a = 8, l = o - a - 4, h = 4, u = n - h * 2;
1923
1923
  if (r.clearRect(l - 2, 0, a + 6, n), r.fillStyle = this.theme.background, r.fillRect(l - 2, 0, a + 6, n), s <= 0 || i === 0)
1924
1924
  return;
1925
- const d = i + e, p = Math.max(20, e / d * u), m = t / i, g = h + (u - p) * (1 - m);
1925
+ const d = i + e, p = Math.max(20, e / d * u), f = t / i, g = h + (u - p) * (1 - f);
1926
1926
  r.fillStyle = `rgba(128, 128, 128, ${0.1 * s})`, r.fillRect(l, h, a, u);
1927
1927
  const S = t > 0 ? 0.5 : 0.3;
1928
1928
  r.fillStyle = `rgba(128, 128, 128, ${S * s})`, r.fillRect(l, g, a, p);
@@ -2048,10 +2048,10 @@ const _ = class I {
2048
2048
  const h = o === i ? t : 0, u = o === s ? e : a.length - 1;
2049
2049
  let d = "";
2050
2050
  for (let p = h; p <= u; p++) {
2051
- const m = a[p];
2052
- if (m && m.codepoint !== 0) {
2051
+ const f = a[p];
2052
+ if (f && f.codepoint !== 0) {
2053
2053
  let g;
2054
- if (m.grapheme_len > 0)
2054
+ if (f.grapheme_len > 0)
2055
2055
  if (o < r)
2056
2056
  g = this.wasmTerm.getScrollbackGraphemeString(o, p);
2057
2057
  else {
@@ -2059,10 +2059,10 @@ const _ = class I {
2059
2059
  g = this.wasmTerm.getGraphemeString(w, p);
2060
2060
  }
2061
2061
  else
2062
- g = String.fromCodePoint(m.codepoint);
2062
+ g = String.fromCodePoint(f.codepoint);
2063
2063
  d += g, g.trim() && (l = d.length);
2064
2064
  } else
2065
- (!m || m.width !== 0) && (d += " ");
2065
+ (!f || f.width !== 0) && (d += " ");
2066
2066
  }
2067
2067
  l >= 0 ? d = d.substring(0, l) : d = "", n += d, o < s && (n += `
2068
2068
  `);
@@ -2588,15 +2588,15 @@ const W = class z extends G {
2588
2588
  }
2589
2589
  if (((o = this.wasmTerm) == null ? void 0 : o.isAlternateScreen()) ?? !1) {
2590
2590
  if ((a = this.wasmTerm) != null && a.hasMouseTracking()) {
2591
- const m = (l = this.renderer) == null ? void 0 : l.getMetrics(), g = this.canvas;
2592
- if (m && g) {
2593
- const w = g.getBoundingClientRect(), S = Math.max(1, Math.floor((e.clientX - w.left) / m.width) + 1), b = Math.max(1, Math.floor((e.clientY - w.top) / m.height) + 1), f = e.deltaY < 0 ? 64 : 65;
2594
- this.dataEmitter.fire(`\x1B[<${f};${S};${b}M`);
2591
+ const f = (l = this.renderer) == null ? void 0 : l.getMetrics(), g = this.canvas;
2592
+ if (f && g) {
2593
+ const w = g.getBoundingClientRect(), S = Math.max(1, Math.floor((e.clientX - w.left) / f.width) + 1), b = Math.max(1, Math.floor((e.clientY - w.top) / f.height) + 1), m = e.deltaY < 0 ? 64 : 65;
2594
+ this.dataEmitter.fire(`\x1B[<${m};${S};${b}M`);
2595
2595
  }
2596
2596
  return;
2597
2597
  }
2598
2598
  const d = e.deltaY > 0 ? "down" : "up", p = Math.min(Math.abs(Math.round(e.deltaY / 33)), 5);
2599
- for (let m = 0; m < p; m++)
2599
+ for (let f = 0; f < p; f++)
2600
2600
  this.dataEmitter.fire(d === "up" ? "\x1B[A" : "\x1B[B");
2601
2601
  } else {
2602
2602
  let d;
@@ -2619,7 +2619,7 @@ const W = class z extends G {
2619
2619
  const r = this.canvas.getBoundingClientRect(), n = e.clientX - r.left, o = e.clientY - r.top, a = r.width, l = r.height, h = 8, u = a - h - 4, d = 4;
2620
2620
  if (n >= u && n <= u + h) {
2621
2621
  e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
2622
- const p = l - d * 2, m = this.rows, g = s + m, w = Math.max(20, m / g * p), S = this.viewportY / s, b = d + (p - w) * (1 - S);
2622
+ const p = l - d * 2, f = this.rows, g = s + f, w = Math.max(20, f / g * p), S = this.viewportY / s, b = d + (p - w) * (1 - S);
2623
2623
  if (o >= b && o <= b + w)
2624
2624
  this.isDraggingScrollbar = !0, this.scrollbarDragStart = o, this.scrollbarDragStartViewportY = this.viewportY, this.canvas && (this.canvas.style.userSelect = "none", this.canvas.style.webkitUserSelect = "none");
2625
2625
  else {
@@ -3163,24 +3163,24 @@ const W = class z extends G {
3163
3163
  n !== h && this.renderer.setHoveredHyperlinkId(n);
3164
3164
  const u = this.wasmTerm.getScrollbackLength();
3165
3165
  let d;
3166
- const p = this.getViewportY(), m = Math.max(0, Math.floor(p));
3167
- if (m > 0)
3168
- if (r < m)
3169
- d = u - m + r;
3166
+ const p = this.getViewportY(), f = Math.max(0, Math.floor(p));
3167
+ if (f > 0)
3168
+ if (r < f)
3169
+ d = u - f + r;
3170
3170
  else {
3171
- const g = r - m;
3171
+ const g = r - f;
3172
3172
  d = u + g;
3173
3173
  }
3174
3174
  else
3175
3175
  d = u + r;
3176
3176
  this.linkDetector.getLinkAt(e, d).then((g) => {
3177
- var w, S, b, f;
3177
+ var w, S, b, m;
3178
3178
  if (g !== this.currentHoveredLink) {
3179
3179
  (S = (w = this.currentHoveredLink) == null ? void 0 : w.hover) == null || S.call(w, !1), this.currentHoveredLink = g, (b = g == null ? void 0 : g.hover) == null || b.call(g, !0);
3180
3180
  const v = g ? "pointer" : "text";
3181
3181
  if (this.element && (this.element.style.cursor = v), this.canvas && (this.canvas.style.cursor = v), this.renderer)
3182
3182
  if (g) {
3183
- const C = ((f = this.wasmTerm) == null ? void 0 : f.getScrollbackLength()) || 0, M = this.getViewportY(), F = Math.max(0, Math.floor(M)), O = g.range.start.y - C + F, K = g.range.end.y - C + F;
3183
+ const C = ((m = this.wasmTerm) == null ? void 0 : m.getScrollbackLength()) || 0, M = this.getViewportY(), F = Math.max(0, Math.floor(M)), O = g.range.start.y - C + F, K = g.range.end.y - C + F;
3184
3184
  O < this.rows && K >= 0 ? this.renderer.setHoveredLinkRange({
3185
3185
  startX: g.range.start.x,
3186
3186
  startY: Math.max(0, O),
@@ -3200,8 +3200,8 @@ const W = class z extends G {
3200
3200
  const i = this.wasmTerm.getScrollbackLength();
3201
3201
  if (i === 0)
3202
3202
  return;
3203
- const e = this.canvas.getBoundingClientRect(), r = t.clientY - e.top - this.scrollbarDragStart, a = e.height - 4 * 2, l = this.rows, h = i + l, u = Math.max(20, l / h * a), d = -r / (a - u), p = Math.round(d * i), m = this.scrollbarDragStartViewportY + p;
3204
- this.scrollToLine(Math.max(0, Math.min(i, m)));
3203
+ const e = this.canvas.getBoundingClientRect(), r = t.clientY - e.top - this.scrollbarDragStart, a = e.height - 4 * 2, l = this.rows, h = i + l, u = Math.max(20, l / h * a), d = -r / (a - u), p = Math.round(d * i), f = this.scrollbarDragStartViewportY + p;
3204
+ this.scrollToLine(Math.max(0, Math.min(i, f)));
3205
3205
  }
3206
3206
  };
3207
3207
  W.SYNC_OUTPUT_TIMEOUT_MS = 500;
@@ -3274,8 +3274,8 @@ class dt {
3274
3274
  const r = window.getComputedStyle(s), n = Number.parseInt(r.getPropertyValue("padding-top")) || 0, o = Number.parseInt(r.getPropertyValue("padding-bottom")) || 0, a = Number.parseInt(r.getPropertyValue("padding-left")) || 0, l = Number.parseInt(r.getPropertyValue("padding-right")) || 0, h = s.clientWidth, u = s.clientHeight;
3275
3275
  if (h === 0 || u === 0)
3276
3276
  return;
3277
- const d = h - a - l - at, p = u - n - o, m = Math.max(nt, Math.floor(d / e.width)), g = Math.max(ot, Math.floor(p / e.height));
3278
- return { cols: m, rows: g };
3277
+ const d = h - a - l - at, p = u - n - o, f = Math.max(nt, Math.floor(d / e.width)), g = Math.max(ot, Math.floor(p / e.height));
3278
+ return { cols: f, rows: g };
3279
3279
  }
3280
3280
  /**
3281
3281
  * Observe the terminal's container for resize events
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crunchloop/ghostty-web",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Web-based terminal emulator using Ghostty's VT100 parser via WebAssembly",
5
5
  "type": "module",
6
6
  "main": "./dist/ghostty-web.cjs.js",