@fabiofiorita/porcelain 0.63.2 → 0.63.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.
- package/README.md +1 -1
- package/main/daemon/server.js +56 -64
- package/package.json +1 -1
- package/renderer/assets/{browser-Jr_b0elB.js → browser-DjHhN4s0.js} +1 -1
- package/renderer/assets/{canvas-view-GPMnUkVs.js → canvas-view-DhzIJ8ZV.js} +1 -1
- package/renderer/assets/{changeset-view-DvTXGqVY.js → changeset-view-yBQtdgrZ.js} +1 -1
- package/renderer/assets/{commit-view-ccK7mA-z.js → commit-view-Cz3IR74x.js} +1 -1
- package/renderer/assets/{diff-mode-toggle-D41-9y4s.js → diff-mode-toggle-DTeqhuLC.js} +1 -1
- package/renderer/assets/{diff-view-Cu-uShqQ.js → diff-view-DqanYaSe.js} +1 -1
- package/renderer/assets/file-content-BX3OYiQC.js +5 -0
- package/renderer/assets/{html-view-CDZotjAw.js → html-view-BPOrX4do.js} +8 -8
- package/renderer/assets/{hunks-view-DW93fMKk.js → hunks-view-CXQMQon9.js} +1 -1
- package/renderer/assets/index-CS0Dcjbz.css +1 -0
- package/renderer/assets/index-CuWbxCsX.js +282 -0
- package/renderer/assets/{search-view-CG_TGBsR.js → search-view-BDExg3Xl.js} +1 -1
- package/renderer/assets/{surface-DPTIuMCk.js → surface-BsSU1Fob.js} +1 -1
- package/renderer/assets/{unfold-vertical-C146gwHO.js → unfold-vertical-CIpACs4g.js} +1 -1
- package/renderer/assets/{virtual-rows-BdkQ29uq.js → virtual-rows-CsZNdhfp.js} +1 -1
- package/renderer/index.html +2 -2
- package/renderer/assets/file-content-CiKOU2BI.js +0 -5
- package/renderer/assets/index-BG75F5tP.js +0 -282
- package/renderer/assets/index-Cv4ANasQ.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as x,c as u,ac as p,j as t,A as d,y as m,z as f}from"./index-
|
|
1
|
+
import{b as x,c as u,ac as p,j as t,A as d,y as m,z as f}from"./index-CuWbxCsX.js";function b({query:n}){const a=x(),o=u(e=>e.openTab),{matches:s,error:r}=p(n);if(r)return t.jsx("p",{className:"p-4 text-sm text-destructive",children:r.message});if(s===void 0)return t.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Searching…"});const l=(e,c)=>{if(a===null)return;const i=d(e);o(m("file",`${a}/${e}`,{title:i,line:c},f()))};return t.jsxs("div",{className:"h-full overflow-y-auto px-4 py-2",children:[t.jsxs("p",{className:"pb-2 text-xs text-muted-foreground",children:[s.length," ",s.length===1?"match":"matches"," for"," ",t.jsx("span",{className:"font-mono text-foreground",children:n})]}),s.map(e=>t.jsxs("button",{type:"button",onClick:()=>l(e.path,e.line),className:"block w-full truncate rounded-sm px-1 py-0.5 text-left font-mono text-xs hover:bg-accent/50",children:[t.jsxs("span",{className:"text-muted-foreground",children:[e.path,":",e.line]})," ",e.text.trim()]},`${e.path}:${e.line}`))]})}export{b as SearchView};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{bk as ct,bu as et}from"./index-BG75F5tP.js";const _t=["Unidentified","Backquote","Backslash","BracketLeft","BracketRight","Comma","Digit0","Digit1","Digit2","Digit3","Digit4","Digit5","Digit6","Digit7","Digit8","Digit9","Equal","IntlBackslash","IntlRo","IntlYen","KeyA","KeyB","KeyC","KeyD","KeyE","KeyF","KeyG","KeyH","KeyI","KeyJ","KeyK","KeyL","KeyM","KeyN","KeyO","KeyP","KeyQ","KeyR","KeyS","KeyT","KeyU","KeyV","KeyW","KeyX","KeyY","KeyZ","Minus","Period","Quote","Semicolon","Slash","AltLeft","AltRight","Backspace","CapsLock","ContextMenu","ControlLeft","ControlRight","Enter","MetaLeft","MetaRight","ShiftLeft","ShiftRight","Space","Tab","Convert","KanaMode","NonConvert","Delete","End","Help","Home","Insert","PageDown","PageUp","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","NumLock","Numpad0","Numpad1","Numpad2","Numpad3","Numpad4","Numpad5","Numpad6","Numpad7","Numpad8","Numpad9","NumpadAdd","NumpadBackspace","NumpadClear","NumpadClearEntry","NumpadComma","NumpadDecimal","NumpadDivide","NumpadEnter","NumpadEqual","NumpadMemoryAdd","NumpadMemoryClear","NumpadMemoryRecall","NumpadMemoryStore","NumpadMemorySubtract","NumpadMultiply","NumpadParenLeft","NumpadParenRight","NumpadSubtract","NumpadSeparator","NumpadArrowUp","NumpadArrowDown","NumpadArrowRight","NumpadArrowLeft","NumpadBegin","NumpadHome","NumpadEnd","NumpadInsert","NumpadDelete","NumpadPageUp","NumpadPageDown","Escape","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24","F25","Fn","FnLock","PrintScreen","ScrollLock","Pause","BrowserBack","BrowserFavorites","BrowserForward","BrowserHome","BrowserRefresh","BrowserSearch","BrowserStop","Eject","LaunchApp1","LaunchApp2","LaunchMail","MediaPlayPause","MediaSelect","MediaStop","MediaTrackNext","MediaTrackPrevious","Power","Sleep","AudioVolumeDown","AudioVolumeMute","AudioVolumeUp","WakeUp","Copy","Cut","Paste"],bt=new Map(_t.map((s,t)=>[s,t]));function St(s){return bt.get(s)??0}const vt=new Map([["!","1"],["@","2"],["#","3"],["$","4"],["%","5"],["^","6"],["&","7"],["*","8"],["(","9"],[")","0"],["~","`"],["_","-"],["+","="],["{","["],["}","]"],["|","\\"],[":",";"],['"',"'"],["<",","],[">","."],["?","/"]]);let K;async function kt(s){try{return await s()}catch{return}}function Tt(s){ct(Mt().then(s),"fallback")}function Mt(){if(K)return K;const t=globalThis.navigator?.keyboard,e=t===void 0?Promise.resolve(void 0):kt(()=>t.getLayoutMap());return K=e,e}function xt(s,t){if([...s.key].length!==1)return 0;const e=t?.get(s.code);if(e&&[...e].length===1)return e.codePointAt(0)??0;if(/^[A-Z]$/u.test(s.key))return s.key.charCodeAt(0)+32;if(s.shiftKey){const i=vt.get(s.key);if(i)return i.codePointAt(0)??0;const r=s.key.toLowerCase();return r!==s.key&&[...r].length===1?r.codePointAt(0)??0:0}return s.key.codePointAt(0)??0}const Et=""+new URL("ghostty-vt-DdA0Zryv.wasm",import.meta.url).href,At=""+new URL("ghostty-write-pty-CVPirtOQ.wasm",import.meta.url).href,W=new TextDecoder;class j{constructor(t){this.ptyWriters=new Map,this.nextPtyWriterId=1,this.writePtyFunctionIndex=0,this.exports=t.exports;const e=t.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("libghostty-vt did not export WebAssembly memory");this.memory=e;const i=this.call("ghostty_type_json"),r=new Uint8Array(e.buffer);let n=i;for(;n<r.length&&r[n]!==0;)n+=1;this.layouts=JSON.parse(W.decode(r.subarray(i,n)))}static async load(){const t=await fetch(Et);if(!t.ok)throw new Error(`Unable to load libghostty-vt (${t.status})`);let e;const i={env:{log:(h,c)=>{if(!e)return;const d=e.exports.memory;if(!(d instanceof WebAssembly.Memory))return;const f=W.decode(new Uint8Array(d.buffer,h,c));console.debug("[libghostty-vt]",f)}}},r=await WebAssembly.instantiate(await t.arrayBuffer(),i);e=r.instance;const n=new j(r.instance);return await n.installWritePtyTrampoline(),n}call(t,...e){const i=this.exports[t];if(typeof i!="function")throw new Error(`libghostty-vt export is unavailable: ${t}`);return i(...e)}layout(t){const e=this.layouts[t];if(!e)throw new Error(`libghostty-vt type layout is unavailable: ${t}`);return e}alloc(t){const e=this.call("ghostty_wasm_alloc_u8_array",t);if(e===0)throw new Error(`libghostty-vt failed to allocate ${t} bytes`);return new Uint8Array(this.memory.buffer,e,t).fill(0),e}free(t,e){t!==0&&this.call("ghostty_wasm_free_u8_array",t,e)}allocOpaque(){const t=this.call("ghostty_wasm_alloc_opaque");if(t===0)throw new Error("libghostty-vt failed to allocate an opaque pointer");return new DataView(this.memory.buffer).setUint32(t,0,!0),t}freeOpaque(t){t!==0&&this.call("ghostty_wasm_free_opaque",t)}readPointer(t){return new DataView(this.memory.buffer).getUint32(t,!0)}attachPtyWriter(t,e){if(this.writePtyFunctionIndex===0)throw new Error("libghostty-vt PTY callback trampoline is unavailable");const i=this.nextPtyWriterId++;return this.ptyWriters.set(i,e),this.call("ghostty_terminal_set",t,0,i),this.call("ghostty_terminal_set",t,1,this.writePtyFunctionIndex),i}detachPtyWriter(t,e){this.call("ghostty_terminal_set",t,1,0),this.call("ghostty_terminal_set",t,0,0),this.ptyWriters.delete(e)}view(t,e){return new DataView(this.memory.buffer,t,e)}bytes(t,e){return new Uint8Array(this.memory.buffer,t,e)}setField(t,e,i,r){const n=this.layout(e).fields[i];if(!n)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const h=this.view(t+n.offset,n.size);switch(n.type){case"bool":case"u8":h.setUint8(0,r);return;case"u16":h.setUint16(0,r,!0);return;case"i32":h.setInt32(0,r,!0);return;case"u32":case"enum":h.setUint32(0,r,!0);return;case"u64":h.setBigUint64(0,BigInt(r),!0);return;default:throw new Error(`Unsupported libghostty-vt field type: ${n.type}`)}}readField(t,e,i){const r=this.layout(e).fields[i];if(!r)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const n=this.view(t+r.offset,r.size);switch(r.type){case"bool":case"u8":return n.getUint8(0);case"u16":return n.getUint16(0,!0);case"i32":return n.getInt32(0,!0);case"u32":case"enum":return n.getUint32(0,!0);case"u64":return Number(n.getBigUint64(0,!0));default:throw new Error(`Unsupported libghostty-vt field type: ${r.type}`)}}async installWritePtyTrampoline(){const t=await fetch(At);if(!t.ok)throw new Error(`Unable to load the libghostty-vt PTY trampoline (${t.status})`);const i=(await WebAssembly.instantiate(await t.arrayBuffer(),{env:{porcelain_write_pty:(h,c,d,f)=>{const p=this.ptyWriters.get(c);!p||f===0||p(W.decode(new Uint8Array(this.memory.buffer,d,f)))}}})).instance.exports.ghostty_write_pty,r=this.exports.__indirect_function_table;if(typeof i!="function"||!(r instanceof WebAssembly.Table))throw new Error("libghostty-vt did not expose its callback table");const n=r.length;r.grow(1),r.set(n,i),this.writePtyFunctionIndex=n}}let Y=null;function Lt(){return Y??=j.load().catch(s=>{throw Y=null,s}),Y}const k=0,D=-3,Ct=1e4,N=16;function F(s,t){const e=s.fields[t];if(!e)throw new Error(`libghostty-vt layout field is unavailable: ${t}`);return e}const A={cols:1,rows:2,dirty:3,rowIterator:4,background:5,foreground:6,cursor:7,cursorHasValue:8,cursorStyle:10,cursorVisible:11,cursorBlinking:12,cursorInViewport:14,cursorX:15,cursorY:16},H={dirty:1,raw:2,cells:3},I={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},Pt={wide:3},Rt={spacerTail:2},B=new TextDecoder,q=new TextEncoder;function Ft(s,t){const e=(i,r)=>Math.floor((i*155+r*100)/255);return{r:e(s.r,t.r),g:e(s.g,t.g),b:e(s.b,t.b)}}function It(s,t){return s.r===t.r&&s.g===t.g&&s.b===t.b}class Q{constructor(t){this.terminalSlot=0,this.terminal=0,this.renderStateSlot=0,this.renderState=0,this.rowIteratorSlot=0,this.rowCellsSlot=0,this.keyEncoderSlot=0,this.keyEncoder=0,this.keyEventSlot=0,this.keyEvent=0,this.mouseEncoderSlot=0,this.mouseEncoder=0,this.mouseEventSlot=0,this.mouseEvent=0,this.ptyWriterId=0,this.ptyWriter=null,this.scratch=0,this.style=0,this.scrollbar=0,this.rows=[],this.disposed=!1,this.runtime=t,Tt(e=>{this.disposed||(this.keyboardLayoutMap=e)})}static async create(t,e,i,r,n,h){const c=new Q(await Lt());try{return c.initialize(t,e,i,r,n,h),c}catch(d){throw c.dispose(),d}}initialize(t,e,i,r,n,h){const c=this.runtime.layout("GhosttyTerminalOptions").size,d=this.runtime.alloc(c);this.runtime.setField(d,"GhosttyTerminalOptions","cols",t),this.runtime.setField(d,"GhosttyTerminalOptions","rows",e),this.runtime.setField(d,"GhosttyTerminalOptions","max_scrollback",Ct),this.terminalSlot=this.runtime.allocOpaque();const f=this.runtime.call("ghostty_terminal_new",0,this.terminalSlot,d);this.runtime.free(d,c),this.assertSuccess("ghostty_terminal_new",f),this.terminal=this.runtime.readPointer(this.terminalSlot),this.applyDefaultCursorBlink(),this.ptyWriter=h,this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,h),this.renderStateSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_new",this.runtime.call("ghostty_render_state_new",0,this.renderStateSlot)),this.renderState=this.runtime.readPointer(this.renderStateSlot),this.rowIteratorSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_iterator_new",this.runtime.call("ghostty_render_state_row_iterator_new",0,this.rowIteratorSlot)),this.rowCellsSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_cells_new",this.runtime.call("ghostty_render_state_row_cells_new",0,this.rowCellsSlot)),this.keyEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_encoder_new",this.runtime.call("ghostty_key_encoder_new",0,this.keyEncoderSlot)),this.keyEncoder=this.runtime.readPointer(this.keyEncoderSlot),this.keyEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_event_new",this.runtime.call("ghostty_key_event_new",0,this.keyEventSlot)),this.keyEvent=this.runtime.readPointer(this.keyEventSlot),this.mouseEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_encoder_new",this.runtime.call("ghostty_mouse_encoder_new",0,this.mouseEncoderSlot)),this.mouseEncoder=this.runtime.readPointer(this.mouseEncoderSlot),this.mouseEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_event_new",this.runtime.call("ghostty_mouse_event_new",0,this.mouseEventSlot)),this.mouseEvent=this.runtime.readPointer(this.mouseEventSlot),this.scratch=this.runtime.alloc(16);const p=this.runtime.layout("GhosttyStyle").size;this.style=this.runtime.alloc(p),this.runtime.setField(this.style,"GhosttyStyle","size",p),this.scrollbar=this.runtime.alloc(this.runtime.layout("GhosttyTerminalScrollbar").size),this.setTheme(n),this.resize(t,e,i,r)}write(t){this.ensureActive();const e=typeof t=="string"?q.encode(t):t;if(e.length===0)return;const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.call("ghostty_terminal_vt_write",this.terminal,i,e.length),this.runtime.free(i,e.length)}resetAndWrite(t){if(this.ensureActive(),this.runtime.call("ghostty_terminal_reset",this.terminal),this.applyDefaultCursorBlink(),this.rows=[],t.length===0)return;const e=this.ptyWriter;this.ptyWriterId!==0&&(this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.ptyWriterId=0);try{this.write(t)}finally{e!==null&&!this.disposed&&(this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,e))}}resize(t,e,i,r){this.ensureActive(),this.assertSuccess("ghostty_terminal_resize",this.runtime.call("ghostty_terminal_resize",this.terminal,Math.max(1,Math.min(65535,t)),Math.max(1,Math.min(65535,e)),Math.max(1,Math.round(i)),Math.max(1,Math.round(r))))}applyDefaultCursorBlink(){const t=this.runtime.alloc(1);this.runtime.bytes(t,1)[0]=1,this.runtime.call("ghostty_terminal_set",this.terminal,23,t),this.runtime.free(t,1)}setTheme(t){this.ensureActive();const e=this.runtime.alloc(3);for(const[i,r]of[[11,t.foreground],[12,t.background],[13,t.cursor]])this.runtime.bytes(e,3).set([r.r,r.g,r.b]),this.runtime.call("ghostty_terminal_set",this.terminal,i,e);this.runtime.free(e,3)}scroll(t){this.ensureActive();const e=this.runtime.layout("GhosttyTerminalScrollViewport"),i=this.runtime.alloc(e.size);this.runtime.setField(i,"GhosttyTerminalScrollViewport","tag",2);const r=F(e,"value");this.runtime.view(i+r.offset,r.size).setInt32(0,t,!0),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,i),this.runtime.free(i,e.size)}scrollToBottom(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollViewport"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttyTerminalScrollViewport","tag",1),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,e),this.runtime.free(e,t.size)}isViewportActive(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,32,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}scrollbarState(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollbar");return this.runtime.bytes(this.scrollbar,t.size).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,9,this.scrollbar)!==k?null:{total:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","total"),offset:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","offset"),len:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","len")}}isMouseTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,11,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}isMouseAnyEventTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1003,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}mouseTrackingMode(){this.ensureActive();for(const[t,e]of[[1003,"any"],[1002,"drag"],[1e3,"vt200"],[9,"x10"]])if(this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,t,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0)return e;return"none"}isAlternateScreen(){return this.ensureActive(),this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,6,this.scratch)===k&&this.runtime.view(this.scratch,4).getUint32(0,!0)===1}isApplicationCursorKeys(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}encodeKey(t,e="press"){this.ensureActive(),this.runtime.call("ghostty_key_encoder_setopt_from_terminal",this.keyEncoder,this.terminal),this.runtime.call("ghostty_key_event_set_action",this.keyEvent,e==="release"?0:t.repeat?2:1),this.runtime.call("ghostty_key_event_set_key",this.keyEvent,St(t.code));const i=(t.shiftKey?1:0)|(t.ctrlKey?2:0)|(t.altKey?4:0)|(t.metaKey?8:0)|(t.getModifierState("CapsLock")?16:0)|(t.getModifierState("NumLock")?32:0);this.runtime.call("ghostty_key_event_set_mods",this.keyEvent,i),this.runtime.call("ghostty_key_event_set_consumed_mods",this.keyEvent,0),this.runtime.call("ghostty_key_event_set_composing",this.keyEvent,t.isComposing?1:0),this.runtime.call("ghostty_key_event_set_unshifted_codepoint",this.keyEvent,xt(t,this.keyboardLayoutMap));const r=t.key.length===1?t.key:"",n=q.encode(r),h=n.length===0?0:this.runtime.alloc(n.length);h!==0&&this.runtime.bytes(h,n.length).set(n),this.runtime.call("ghostty_key_event_set_utf8",this.keyEvent,h,n.length);const c=this.runtime.call("ghostty_wasm_alloc_usize"),d=this.encodeOutput(c,(f,p)=>this.runtime.call("ghostty_key_encoder_encode",this.keyEncoder,this.keyEvent,f,p,c));return this.runtime.call("ghostty_wasm_free_usize",c),h!==0&&this.runtime.free(h,n.length),d}encodePaste(t){this.ensureActive();const e=q.encode(t);if(e.length===0)return"";const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.bytes(this.scratch,1)[0]=0;const r=this.runtime.call("ghostty_terminal_mode_get",this.terminal,2004,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0,n=this.runtime.call("ghostty_wasm_alloc_usize");let h="";const c=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,0,0,n),d=this.runtime.view(n,4).getUint32(0,!0);if(c===D&&d>0){const f=this.runtime.alloc(d),p=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,f,d,n),o=this.runtime.view(n,4).getUint32(0,!0);h=p===k?B.decode(this.runtime.bytes(f,o)):"",this.runtime.free(f,d)}return this.runtime.call("ghostty_wasm_free_usize",n),this.runtime.free(i,e.length),h}encodeMouse(t){this.ensureActive(),this.runtime.call("ghostty_mouse_encoder_setopt_from_terminal",this.mouseEncoder,this.terminal);const e=this.runtime.layout("GhosttyMouseEncoderSize"),i=this.runtime.alloc(e.size);for(const[f,p]of[["size",e.size],["screen_width",t.screenWidth],["screen_height",t.screenHeight],["cell_width",t.cellWidth],["cell_height",t.cellHeight],["padding_top",t.paddingTop],["padding_bottom",t.paddingBottom],["padding_right",t.paddingRight],["padding_left",t.paddingLeft]])this.runtime.setField(i,"GhosttyMouseEncoderSize",f,Math.max(0,Math.round(p)));this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,2,i),this.runtime.free(i,e.size),this.runtime.bytes(this.scratch,1)[0]=t.anyButtonPressed?1:0,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,3,this.scratch),this.runtime.bytes(this.scratch,1)[0]=1,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,4,this.scratch),this.runtime.call("ghostty_mouse_event_set_action",this.mouseEvent,t.action==="press"?0:t.action==="release"?1:2),t.button===null?this.runtime.call("ghostty_mouse_event_clear_button",this.mouseEvent):this.runtime.call("ghostty_mouse_event_set_button",this.mouseEvent,t.button),this.runtime.call("ghostty_mouse_event_set_mods",this.mouseEvent,t.mods);const r=this.runtime.layout("GhosttyMousePosition"),n=this.runtime.alloc(r.size),h=this.runtime.view(n,r.size);h.setFloat32(F(r,"x").offset,t.x,!0),h.setFloat32(F(r,"y").offset,t.y,!0),this.runtime.call("ghostty_mouse_event_set_position",this.mouseEvent,n),this.runtime.free(n,r.size);const c=this.runtime.call("ghostty_wasm_alloc_usize"),d=this.encodeOutput(c,(f,p)=>this.runtime.call("ghostty_mouse_encoder_encode",this.mouseEncoder,this.mouseEvent,f,p,c));return this.runtime.call("ghostty_wasm_free_usize",c),d}setSelection(t,e){this.ensureActive();const i=this.runtime.layout("GhosttySelection"),r=this.runtime.layout("GhosttyGridRef").size,n=this.runtime.alloc(i.size);let h=0,c=0;try{this.runtime.setField(n,"GhosttySelection","size",i.size),h=this.gridRef(t.x,t.y,t.tag??1),c=this.gridRef(e.x,e.y,e.tag??1);const d=F(i,"start"),f=F(i,"end");this.runtime.bytes(n+d.offset,d.size).set(this.runtime.bytes(h,d.size)),this.runtime.bytes(n+f.offset,f.size).set(this.runtime.bytes(c,f.size)),this.runtime.call("ghostty_terminal_set",this.terminal,21,n)}finally{this.runtime.free(h,r),this.runtime.free(c,r),this.runtime.free(n,i.size)}}selectAll(){this.ensureActive();const t=this.runtime.layout("GhosttySelection"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttySelection","size",t.size),this.runtime.call("ghostty_terminal_select_all",this.terminal,e)===k&&this.runtime.call("ghostty_terminal_set",this.terminal,21,e),this.runtime.free(e,t.size)}selectWord(t,e){return this.selectAt("GhosttyTerminalSelectWordOptions","ghostty_terminal_select_word",t,e)}selectLine(t,e){return this.selectAt("GhosttyTerminalSelectLineOptions","ghostty_terminal_select_line",t,e)}hyperlinkAt(t,e){this.ensureActive();const i=this.gridRef(t,e),r=this.runtime.call("ghostty_wasm_alloc_usize"),n=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,0,0,r),h=this.runtime.view(r,4).getUint32(0,!0);let c=null;if(n===D&&h>0){const d=this.runtime.alloc(h),f=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,d,h,r),p=this.runtime.view(r,4).getUint32(0,!0);f===k&&p>0&&(c=B.decode(this.runtime.bytes(d,p))),this.runtime.free(d,h)}return this.runtime.call("ghostty_wasm_free_usize",r),this.runtime.free(i,this.runtime.layout("GhosttyGridRef").size),c}clearSelection(){this.ensureActive(),this.runtime.call("ghostty_terminal_set",this.terminal,21,0)}snapshot(){this.ensureActive(),this.assertSuccess("ghostty_render_state_update",this.runtime.call("ghostty_render_state_update",this.renderState,this.terminal));const t=this.getU16(A.cols),e=this.getU16(A.rows),i=this.getU32(A.dirty),r=this.getColor(A.foreground,{r:229,g:231,b:235}),n=this.getColor(A.background,{r:0,g:0,b:0}),c=this.getBool(A.cursorHasValue)?this.getColor(A.cursor,r):r,d=this.getBool(A.cursorInViewport),f=this.getBool(A.cursorVisible)&&d,p=d?this.getU16(A.cursorX):-1,o=d?this.getU16(A.cursorY):-1;(this.rows.length!==e||this.rows.some(y=>y.cells.length!==t))&&(this.rows=Array.from({length:e},()=>({cells:Array.from({length:t},()=>this.emptyCell(r,n)),text:"",isWrapContinuation:!1,wrapsToNext:!1})));const m=new Set;if(i!==0){this.assertSuccess("ghostty_render_state_get(row iterator)",this.runtime.call("ghostty_render_state_get",this.renderState,A.rowIterator,this.rowIteratorSlot));const y=this.runtime.readPointer(this.rowIteratorSlot);let _=0;for(;_<e&&this.runtime.call("ghostty_render_state_row_iterator_next",y)!==0;)(i===2||this.getRowBool(y,H.dirty))&&(this.rows[_]=this.readRow(y,t,r,n),m.add(_),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_set",y,0,this.scratch)),_+=1;this.runtime.view(this.scratch,4).setUint32(0,0,!0),this.runtime.call("ghostty_render_state_set",this.renderState,0,this.scratch)}return{cols:t,rows:e,foreground:r,background:n,cursor:c,cursorX:p,cursorY:o,cursorVisible:f,cursorBlinking:this.getBool(A.cursorBlinking),cursorStyle:this.getU32(A.cursorStyle),dirtyRows:m,rowData:this.rows}}selectionText(){this.ensureActive();const t=this.runtime.alloc(N),e=this.runtime.view(t,N);e.setUint32(0,N,!0),e.setUint32(4,0,!0),e.setUint8(8,1),e.setUint8(9,1),e.setUint32(12,0,!0);const i=this.runtime.call("ghostty_wasm_alloc_usize"),r=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,0,0,i),n=this.runtime.view(i,4).getUint32(0,!0);let h="";if(r===D&&n>0){const c=this.runtime.alloc(n),d=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,c,n,i),f=this.runtime.view(i,4).getUint32(0,!0);d===k&&(h=B.decode(this.runtime.bytes(c,f))),this.runtime.free(c,n)}return this.runtime.call("ghostty_wasm_free_usize",i),this.runtime.free(t,N),h}viewportPointToScreen(t,e){return this.convertPoint(t,e,1,2)}screenPointToViewport(t,e){return this.convertPoint(t,e,2,1)}convertPoint(t,e,i,r){this.ensureActive();const n=this.gridRef(t,e,i),h=this.pointFromGridRef(n,r);return this.runtime.free(n,this.runtime.layout("GhosttyGridRef").size),h}dispose(){if(!this.disposed){if(this.disposed=!0,this.mouseEvent&&this.runtime.call("ghostty_mouse_event_free",this.mouseEvent),this.mouseEncoder&&this.runtime.call("ghostty_mouse_encoder_free",this.mouseEncoder),this.keyEvent&&this.runtime.call("ghostty_key_event_free",this.keyEvent),this.keyEncoder&&this.runtime.call("ghostty_key_encoder_free",this.keyEncoder),this.rowCellsSlot){const t=this.runtime.readPointer(this.rowCellsSlot);t&&this.runtime.call("ghostty_render_state_row_cells_free",t)}if(this.rowIteratorSlot){const t=this.runtime.readPointer(this.rowIteratorSlot);t&&this.runtime.call("ghostty_render_state_row_iterator_free",t)}this.renderState&&this.runtime.call("ghostty_render_state_free",this.renderState),this.terminal&&(this.ptyWriterId&&this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.runtime.call("ghostty_terminal_free",this.terminal)),this.style&&this.runtime.free(this.style,this.runtime.layout("GhosttyStyle").size),this.scrollbar&&this.runtime.free(this.scrollbar,this.runtime.layout("GhosttyTerminalScrollbar").size),this.scratch&&this.runtime.free(this.scratch,16);for(const t of[this.mouseEventSlot,this.mouseEncoderSlot,this.keyEventSlot,this.keyEncoderSlot,this.rowCellsSlot,this.rowIteratorSlot,this.renderStateSlot,this.terminalSlot])this.runtime.freeOpaque(t)}}encodeOutput(t,e){const i=e(0,0),r=this.runtime.view(t,4).getUint32(0,!0);if(i===k&&r===0||i!==D||r===0)return"";const n=this.runtime.alloc(r),h=e(n,r),c=this.runtime.view(t,4).getUint32(0,!0),d=h===k?B.decode(this.runtime.bytes(n,c)):"";return this.runtime.free(n,r),d}readRow(t,e,i,r){this.assertSuccess("ghostty_render_state_row_get(raw)",this.runtime.call("ghostty_render_state_row_get",t,H.raw,this.scratch));const n=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap continuation)",this.runtime.call("ghostty_row_get",n,2,this.scratch+8));const h=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap)",this.runtime.call("ghostty_row_get",n,1,this.scratch+8));const c=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.assertSuccess("ghostty_render_state_row_get(cells)",this.runtime.call("ghostty_render_state_row_get",t,H.cells,this.rowCellsSlot));const d=this.runtime.readPointer(this.rowCellsSlot),f=[];for(;f.length<e&&this.runtime.call("ghostty_render_state_row_cells_next",d)!==0;){let p=this.getCellColor(d,I.foreground,i),o=this.getCellColor(d,I.background,r);const m=this.runtime.layout("GhosttyStyle").size;this.runtime.bytes(this.style,m).fill(0),this.runtime.setField(this.style,"GhosttyStyle","size",m),this.runtime.call("ghostty_render_state_row_cells_get",d,I.style,this.style),this.runtime.readField(this.style,"GhosttyStyle","inverse")!==0&&([p,o]=[o,p]),this.runtime.readField(this.style,"GhosttyStyle","faint")!==0&&(p=Ft(p,o));const _=this.getCellU32(d,I.graphemesLength);let w="";if(_>0){const v=_*4,x=this.runtime.alloc(v);if(this.runtime.call("ghostty_render_state_row_cells_get",d,I.graphemes,x)===k){const M=this.runtime.view(x,v),S=[];for(let T=0;T<_;T+=1)S.push(M.getUint32(T*4,!0));w=String.fromCodePoint(...S)}this.runtime.free(x,v)}let b=0;if(w.length===0&&f.at(-1)?.text.length){this.assertSuccess("ghostty_render_state_row_cells_get(raw)",this.runtime.call("ghostty_render_state_row_cells_get",d,I.raw,this.scratch));const v=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.view(this.scratch+8,4).setUint32(0,0,!0),this.assertSuccess("ghostty_cell_get(wide)",this.runtime.call("ghostty_cell_get",v,Pt.wide,this.scratch+8)),b=this.runtime.view(this.scratch+8,4).getUint32(0,!0)}f.push({text:w,wide:b,foreground:p,background:o,bold:this.runtime.readField(this.style,"GhosttyStyle","bold")!==0,italic:this.runtime.readField(this.style,"GhosttyStyle","italic")!==0,invisible:this.runtime.readField(this.style,"GhosttyStyle","invisible")!==0,strikethrough:this.runtime.readField(this.style,"GhosttyStyle","strikethrough")!==0,overline:this.runtime.readField(this.style,"GhosttyStyle","overline")!==0,underline:this.runtime.readField(this.style,"GhosttyStyle","underline")!==0,selected:this.getCellBool(d,I.selected)})}for(;f.length<e;)f.push(this.emptyCell(i,r));return{cells:f,text:f.map(p=>p.text||" ").join("").trimEnd(),isWrapContinuation:h,wrapsToNext:c}}gridRef(t,e,i=1){const r=this.runtime.layout("GhosttyPoint"),n=this.runtime.alloc(r.size);this.runtime.setField(n,"GhosttyPoint","tag",i);const h=F(r,"value"),c=h.offset,d=this.runtime.view(n+c,h.size);d.setUint16(0,Math.max(0,t),!0),d.setUint32(4,Math.max(0,e),!0);const f=this.runtime.layout("GhosttyGridRef").size,p=this.runtime.alloc(f);this.runtime.setField(p,"GhosttyGridRef","size",f);const o=this.runtime.call("ghostty_terminal_grid_ref",this.terminal,n,p);return this.runtime.free(n,r.size),o!==k&&(this.runtime.free(p,f),this.assertSuccess("ghostty_terminal_grid_ref",o)),p}selectAt(t,e,i,r){this.ensureActive();const n=this.runtime.layout(t),h=this.runtime.layout("GhosttySelection"),c=this.runtime.alloc(n.size);let d=0,f=0,p=null;try{this.runtime.setField(c,t,"size",n.size),d=this.gridRef(i,r);const o=F(n,"ref");if(this.runtime.bytes(c+o.offset,o.size).set(this.runtime.bytes(d,o.size)),f=this.runtime.alloc(h.size),this.runtime.setField(f,"GhosttySelection","size",h.size),this.runtime.call(e,this.terminal,c,f)===k){const y=f+F(h,"start").offset,_=f+F(h,"end").offset,w=this.pointFromGridRef(y,1),b=this.pointFromGridRef(_,1),v=this.pointFromGridRef(y,2),x=this.pointFromGridRef(_,2);w&&b&&v&&x&&(p={viewport:{start:w,end:b},screen:{start:v,end:x}}),this.runtime.call("ghostty_terminal_set",this.terminal,21,f)}}finally{this.runtime.free(f,h.size),this.runtime.free(d,this.runtime.layout("GhosttyGridRef").size),this.runtime.free(c,n.size)}return p}pointFromGridRef(t,e){const i=this.runtime.layout("GhosttyPointCoordinate"),r=this.runtime.alloc(i.size),h=this.runtime.call("ghostty_terminal_point_from_grid_ref",this.terminal,t,e,r)===k?{x:this.runtime.readField(r,"GhosttyPointCoordinate","x"),y:this.runtime.readField(r,"GhosttyPointCoordinate","y")}:null;return this.runtime.free(r,i.size),h}getU16(t){return this.runtime.bytes(this.scratch,2).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,2).getUint16(0,!0)}getU32(t){return this.runtime.bytes(this.scratch,4).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,4).getUint32(0,!0)}getBool(t){return this.runtime.bytes(this.scratch,1)[0]=0,this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.bytes(this.scratch,1)[0]!==0}getColor(t,e){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)===k?this.readColor(this.scratch):e}getRowBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_get",t,e,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellU32(t,e){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===k?this.runtime.view(this.scratch,4).getUint32(0,!0):0}getCellBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellColor(t,e,i){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===k?this.readColor(this.scratch):i}readColor(t){const e=this.runtime.bytes(t,3);return{r:e[0]??0,g:e[1]??0,b:e[2]??0}}emptyCell(t,e){return{text:"",wide:0,foreground:t,background:e,bold:!1,italic:!1,invisible:!1,strikethrough:!1,overline:!1,underline:!1,selected:!1}}assertSuccess(t,e){if(e!==k)throw new Error(`${t} failed with result ${e}`)}ensureActive(){if(this.disposed)throw new Error("libghostty-vt terminal has been disposed")}}function O(s,t){return It(s,t)}const zt=""+new URL("SymbolsNerdFontMono-Regular-aK5vsLov.woff2",import.meta.url).href,Dt=/https?:\/\/[^\s"'`<>]+/g,Nt=/(?:~\/|\.{1,2}\/|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}/g,Bt=/[.,;!?]+$/;function Ut(s){let t=s.replace(Bt,"");if(t.length===0)return t;const e=(i,r)=>{for(;t.endsWith(r);){const n=t.split(i).length-1,h=t.split(r).length-1;if(n>=h)return;t=t.slice(0,-1)}};return e("(",")"),e("[","]"),e("{","}"),t}function Gt(s,t){return s.start<t.end&&t.start<s.end}function it(s,t,e,i){const r=[];e.lastIndex=0;for(const n of s.matchAll(e)){const h=n[0],c=n.index??-1;if(c<0||h.length===0)continue;const d=Ut(h);if(d.length===0||t==="path"&&/^https?:\/\//i.test(d))continue;const f={kind:t,text:d,start:c,end:c+d.length};[...i,...r].some(o=>Gt(f,o))||r.push(f)}return r}function Ot(s){const t=it(s,"url",Dt,[]),e=it(s,"path",Nt,t);return[...t,...e].toSorted((i,r)=>i.start-r.start)}function Kt(s,t){const e=t(s-1);if(!e)return null;let i=s,r=e;for(;i>1&&r.isWrapped;){const d=t(i-2);if(!d)return null;i-=1,r=d}const n=[];let h=0,c=i;for(;;){const d=t(c-1);if(!d)break;const p=t(c)?.isWrapped===!0,o=d.translateToString(!p);if(n.push({bufferLineNumber:c,text:o,startIndex:h,endIndex:h+o.length}),h+=o.length,!p)break;c+=1}return{text:n.map(d=>d.text).join(""),segments:n}}const Wt=["normal 400","normal 700","italic 400","italic 700"],Yt=["i","M","W","0","@","#","."," "],Ht=.01;function qt(s){const t=s.split(",").map(e=>e.trim()).filter(e=>e.length>0);return t.length>0?t.join(", "):null}function $t(s){const t=qt(s);if(t===null||typeof document>"u")return!0;try{const e=document.createElement("canvas").getContext("2d");return e===null?!0:Wt.every(i=>{e.font=`${i} 32px ${t}, monospace`;const r=Yt.map(h=>e.measureText(h).width),n=r[0];return n!==void 0&&n>0&&r.every(h=>Math.abs(h-n)<Ht)})}catch{return!0}}const l=0,a=1,u=2,g=3,Vt=new Set([9581,9582,9583,9584]),ut=new Map([[9472,[l,a,l,a]],[9473,[l,u,l,u]],[9474,[a,l,a,l]],[9475,[u,l,u,l]],[9484,[l,a,a,l]],[9485,[l,u,a,l]],[9486,[l,a,u,l]],[9487,[l,u,u,l]],[9488,[l,l,a,a]],[9489,[l,l,a,u]],[9490,[l,l,u,a]],[9491,[l,l,u,u]],[9492,[a,a,l,l]],[9493,[a,u,l,l]],[9494,[u,a,l,l]],[9495,[u,u,l,l]],[9496,[a,l,l,a]],[9497,[a,l,l,u]],[9498,[u,l,l,a]],[9499,[u,l,l,u]],[9500,[a,a,a,l]],[9501,[a,u,a,l]],[9502,[u,a,a,l]],[9503,[a,a,u,l]],[9504,[u,a,u,l]],[9505,[u,u,a,l]],[9506,[a,u,u,l]],[9507,[u,u,u,l]],[9508,[a,l,a,a]],[9509,[a,l,a,u]],[9510,[u,l,a,a]],[9511,[a,l,u,a]],[9512,[u,l,u,a]],[9513,[u,l,a,u]],[9514,[a,l,u,u]],[9515,[u,l,u,u]],[9516,[l,a,a,a]],[9517,[l,a,a,u]],[9518,[l,u,a,a]],[9519,[l,u,a,u]],[9520,[l,a,u,a]],[9521,[l,a,u,u]],[9522,[l,u,u,a]],[9523,[l,u,u,u]],[9524,[a,a,l,a]],[9525,[a,a,l,u]],[9526,[a,u,l,a]],[9527,[a,u,l,u]],[9528,[u,a,l,a]],[9529,[u,a,l,u]],[9530,[u,u,l,a]],[9531,[u,u,l,u]],[9532,[a,a,a,a]],[9533,[a,a,a,u]],[9534,[a,u,a,a]],[9535,[a,u,a,u]],[9536,[u,a,a,a]],[9537,[a,a,u,a]],[9538,[u,a,u,a]],[9539,[u,a,a,u]],[9540,[u,u,a,a]],[9541,[a,a,u,u]],[9542,[a,u,u,a]],[9543,[u,u,a,u]],[9544,[a,u,u,u]],[9545,[u,a,u,u]],[9546,[u,u,u,a]],[9547,[u,u,u,u]],[9552,[l,g,l,g]],[9553,[g,l,g,l]],[9554,[l,g,a,l]],[9555,[l,a,g,l]],[9556,[l,g,g,l]],[9557,[l,l,a,g]],[9558,[l,l,g,a]],[9559,[l,l,g,g]],[9560,[a,g,l,l]],[9561,[g,a,l,l]],[9562,[g,g,l,l]],[9563,[a,l,l,g]],[9564,[g,l,l,a]],[9565,[g,l,l,g]],[9566,[a,g,a,l]],[9567,[g,a,g,l]],[9568,[g,g,g,l]],[9569,[a,l,a,g]],[9570,[g,l,g,a]],[9571,[g,l,g,g]],[9572,[l,g,a,g]],[9573,[l,a,g,a]],[9574,[l,g,g,g]],[9575,[a,g,l,g]],[9576,[g,a,l,a]],[9577,[g,g,l,g]],[9578,[a,g,a,g]],[9579,[g,a,g,a]],[9580,[g,g,g,g]],[9581,[l,a,a,l]],[9582,[l,l,a,a]],[9583,[a,l,l,a]],[9584,[a,a,l,l]],[9588,[l,l,l,a]],[9589,[a,l,l,l]],[9590,[l,a,l,l]],[9591,[l,l,a,l]],[9592,[l,l,l,u]],[9593,[u,l,l,l]],[9594,[l,u,l,l]],[9595,[l,l,u,l]]]);function J(s){if(s.length===0)return!1;const t=s.codePointAt(0);return t===void 0||s.length!==String.fromCodePoint(t).length?!1:t>=9600&&t<=9631?!0:ut.has(t)}function E(s,t,e,i,r){if(i<=t||r<=e)return;const n=typeof s.getTransform=="function"?s.getTransform():null,h=n!==null&&n.a>0?n.a:1,c=n!==null&&n.d>0?n.d:1,d=Math.round(t*h)/h,f=Math.round(e*c)/c,p=Math.max(1/h,Math.round(i*h)/h-d),o=Math.max(1/c,Math.round(r*c)/c-f);s.fillRect(d,f,p,o)}function Xt(s,t,e){const{left:i,right:r,top:n,bottom:h}=e,c=r-i,d=h-n,f=o=>h-d*o/8,p=o=>i+c*o/8;return t===9600?(E(s,i,n,r,n+d/2),!0):t>=9601&&t<=9608?(E(s,i,f(t-9600),r,h),!0):t>=9609&&t<=9615?(E(s,i,n,p(9616-t),h),!0):t===9616?(E(s,i+c/2,n,r,h),!0):t===9620?(E(s,i,n,r,n+d/8),!0):t===9621?(E(s,r-c/8,n,r,h),!0):!1}const Zt=new Map([[9622,[!1,!1,!0,!1]],[9623,[!1,!1,!1,!0]],[9624,[!0,!1,!1,!1]],[9625,[!0,!1,!0,!0]],[9626,[!0,!1,!1,!0]],[9627,[!0,!0,!0,!1]],[9628,[!0,!0,!1,!0]],[9629,[!1,!0,!1,!1]],[9630,[!1,!0,!0,!1]],[9631,[!1,!0,!0,!0]]]);function jt(s,t,e){const i=Zt.get(t);if(i===void 0)return!1;const r=(e.left+e.right)/2,n=(e.top+e.bottom)/2,[h,c,d,f]=i;return h&&E(s,e.left,e.top,r,n),c&&E(s,r,e.top,e.right,n),d&&E(s,e.left,n,r,e.bottom),f&&E(s,r,n,e.right,e.bottom),!0}function st(s,t,e,i,r,n,h){return s&&t?e?[[i,n],[h,r]]:[[i,r]]:s?[[i,e?n:h]]:t?[[e?h:n,r]]:[]}function Qt(s){const t=Math.max(1,Math.round(s/8));return{light:t,heavy:t*2,offset:t*2}}function rt(s,t){return s===u?t.heavy:t.light}function Jt(s,t,e){const i=ut.get(t);if(i===void 0)return!1;const[r,n,h,c]=i,d=Qt(e.right-e.left),f=(e.left+e.right)/2,p=(e.top+e.bottom)/2,{offset:o}=d;if(Vt.has(t))return te(s,i,e,d),!0;if(r===g||h===g)for(const m of[-1,1]){const y=f+m*o,_=(m===-1?c:n)!==l;for(const[w,b]of st(r!==l,h!==l,_,e.top,e.bottom,p-o,p+o))E(s,y-d.light/2,w,y+d.light/2,b)}else if(r!==l||h!==l){const m=rt(r!==l?r:h,d)/2,y=r!==l?e.top:p-m,_=h!==l?e.bottom:p+m;E(s,f-m,y,f+m,_)}if(c===g||n===g)for(const m of[-1,1]){const y=p+m*o,_=(m===-1?r:h)!==l;for(const[w,b]of st(c!==l,n!==l,_,e.left,e.right,f-o,f+o))E(s,w,y-d.light/2,b,y+d.light/2)}else if(c!==l||n!==l){const m=rt(c!==l?c:n,d)/2,y=c!==l?e.left:f-m,_=n!==l?e.right:f+m;E(s,y,p-m,_,p+m)}return!0}function te(s,t,e,i){const[,r,n]=t,h=(e.left+e.right)/2,c=(e.top+e.bottom)/2,d=r!==l?e.right:e.left,f=n!==l?e.bottom:e.top;s.save(),s.beginPath(),s.lineWidth=i.light,s.strokeStyle=s.fillStyle,s.lineCap="butt",s.moveTo(h,f),s.quadraticCurveTo(h,c,d,c),s.stroke(),s.restore()}function nt(s,t,e,i){if(!J(t))return!1;const r=t.codePointAt(0);if(r===void 0)return!1;s.save(),s.fillStyle=i;let n=!1;return r>=9617&&r<=9619?(s.globalAlpha=(r-9616)/4,E(s,e.left,e.top,e.right,e.bottom),n=!0):r>=9600&&r<=9621?n=Xt(s,r,e):r>=9622&&r<=9631?n=jt(s,r,e):n=Jt(s,r,e),s.restore(),n}const ee="rgba(72, 122, 191, 0.35)";function R(s){return`rgb(${s.r}, ${s.g}, ${s.b})`}function ie(s,t){return O(s.foreground,t.foreground)&&s.bold===t.bold&&s.italic===t.italic&&s.invisible===t.invisible}function se(s,t,e){let i=t+1;for(;i<s.length;){const r=s[i];if(!r)break;if(r.wide===Rt.spacerTail){i+=1;continue}if(r.text.length===0||J(r.text)||!e(r))break;i+=1}return i}function ot(s,t,e){const i=s.italic?"italic":"normal",r=s.bold?"700":"400";return`${i} ${r} ${t}px ${e}`}function $(s,t,e){s.font=`normal 400 ${t}px ${e}`;const i=s.measureText("M"),r=s.measureText("Mg"),n=r.actualBoundingBoxAscent||t,h=r.actualBoundingBoxDescent,c=n+h,d=Math.max(1,Math.round(t*1.35),Math.ceil(c));return{width:Math.max(1,i.width),height:d,baseline:Math.round((d-c)/2+n)}}function lt(s,t,e,i){return{cols:Math.max(1,Math.floor((s-i*2)/e.width)),rows:Math.max(1,Math.floor((t-i*2)/e.height))}}function re(s){const{context:t,snapshot:e,metrics:i,fontSize:r,fontFamily:n,padding:h,forceFull:c,cursorOn:d,previousCursorY:f}=s,p=s.focused??!0,o=s.selectionBackground??ee,m=s.hoveredLinkRange??null,y=s.originY??h,_=c?Array.from({length:e.rows},(w,b)=>b):[...e.dirtyRows];f!=null&&f>=0&&!_.includes(f)&&_.push(f),e.cursorVisible&&e.cursorY>=0&&!_.includes(e.cursorY)&&_.push(e.cursorY),c&&(t.save(),t.resetTransform(),t.fillStyle=R(e.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore()),t.textBaseline="alphabetic";for(const w of _){const b=e.rowData[w];if(!b)continue;const v=y+w*i.height;t.fillStyle=R(e.background),t.fillRect(h,v,e.cols*i.width,i.height);let x=0;for(;x<b.cells.length;){const S=b.cells[x];if(!S)break;let T=x+1;for(;T<b.cells.length;){const L=b.cells[T];if(!L||L.selected!==S.selected||!O(L.background,S.background))break;T+=1}if(S.selected||!O(S.background,e.background)){const L=h+x*i.width,P=(T-x)*i.width;O(S.background,e.background)||(t.fillStyle=R(S.background),t.fillRect(L,v,P,i.height)),S.selected&&(t.fillStyle=o,t.fillRect(L,v,P,i.height))}x=T}let M=0;for(;M<b.cells.length;){const S=b.cells[M];if(!S)break;if(S.text.length===0){M+=1;continue}if(J(S.text)){S.invisible||nt(t,S.text,{left:h+M*i.width,right:h+(M+1)*i.width,top:v,bottom:v+i.height},R(S.foreground)),M+=1;continue}const T=se(b.cells,M,P=>ie(P,S)),L=b.cells.slice(M,T).map(P=>P.text).join("");!S.invisible&&L.trim().length>0&&(t.save(),t.beginPath(),t.rect(h+M*i.width,v,(T-M)*i.width,i.height),t.clip(),t.font=ot(S,r,n),t.fillStyle=R(S.foreground),t.fillText(L,h+M*i.width,v+i.baseline,(T-M)*i.width),t.restore()),M=T}for(let S=0;S<b.cells.length;S+=1){const T=b.cells[S],L=m!==null&&w>=m.start.y&&w<=m.end.y&&(w>m.start.y||S>=m.start.x)&&(w<m.end.y||S<=m.end.x);if(!T||!T.underline&&!T.strikethrough&&!T.overline&&!L)continue;t.fillStyle=R(T.foreground);const P=h+S*i.width;(T.underline||L)&&t.fillRect(P,v+i.height-2,i.width,1),T.strikethrough&&t.fillRect(P,v+Math.floor(i.height*.55),i.width,1),T.overline&&t.fillRect(P,v+1,i.width,1)}}if(d&&e.cursorVisible&&e.cursorX>=0&&e.cursorY>=0){const w=h+e.cursorX*i.width,b=y+e.cursorY*i.height;if(t.fillStyle=R(e.cursor),!p)t.strokeStyle=R(e.cursor),t.strokeRect(w+.5,b+.5,i.width-1,i.height-1);else if(e.cursorStyle===0)t.fillRect(w,b,2,i.height);else if(e.cursorStyle===2)t.fillRect(w,b+i.height-2,i.width,2);else if(e.cursorStyle===3)t.strokeStyle=R(e.cursor),t.strokeRect(w+.5,b+.5,i.width-1,i.height-1);else{t.fillRect(w,b,i.width,i.height);const v=e.rowData[e.cursorY]?.cells[e.cursorX];if(v?.text){const x=R(e.background),M={left:w,right:w+i.width,top:b,bottom:b+i.height};nt(t,v.text,M,x)||(t.font=ot(v,r,n),t.fillStyle=x,t.fillText(v.text,w,b+i.baseline,i.width))}}}}function tt(s){return/mac|iphone|ipad|ipod/i.test(s)}const ne=12,oe=6,le=32,dt='"Symbols Nerd Font Mono", "Symbols Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "FiraCode Nerd Font", "Hack Nerd Font", "MesloLGS NF", "CaskaydiaCove Nerd Font", "PowerlineSymbols", monospace',X=`"SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", ${dt}`,C=4,he=18,ae=500,ce="iMW0@# .",ue=["normal 400","normal 700","italic 400","italic 700"];let U=null;function de(){return U!==null||(U=(async()=>{try{const s=new FontFace("Symbols Nerd Font Mono",`url(${zt})`);document.fonts.add(await s.load())}catch{}})()),U}function mt(s){return s.split(",").map(t=>{const e=t.trim();return e.length===0?"":/^(['"]).*\1$/.test(e)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(e)?e:`"${e.replaceAll('"',"")}"`}).filter(t=>t.length>0).join(", ")}function ft(s){const t=s===void 0?"":mt(s);return t.length===0?X:`${t}, ${dt}`}function pt(s){const t=s===void 0?"":mt(s);return t.length===0||!$t(t)?X:ft(t)}async function ht(s,t,e){const i=ft(s),r=e?.load??((n,h)=>document.fonts.load(n,h));try{await Promise.all(ue.map(n=>r(`${n} ${t}px ${i}`,ce)))}catch{}return(e?.resolve??pt)(s)}function V(s){return s===void 0||!Number.isFinite(s)?ne:Math.max(oe,Math.min(le,Math.round(s)))}function me(s){return s.focused&&s.cursorBlinking&&s.cursorVisible&&!s.reducedMotion}function fe(s,t,e,i,r){if(!r)return t;const n=s-t*2-e*i;return t+Math.max(0,n)}function Z(s,t){const e=Math.max(0,s.total),i=Math.max(0,Math.min(s.len,e)),r=Math.max(0,e-i);if(t<=0||i<=0||r===0)return null;const n=Math.min(t,Math.max(he,t*i/e)),h=Math.max(0,t-n),c=Math.max(0,Math.min(s.offset,r));return{thumbHeight:n,thumbTop:h*(c/r),maxOffset:r}}function pe(s,t,e,i){const r=Z(s,t);if(r===null)return 0;const n=Math.max(0,t-r.thumbHeight);if(n===0)return 0;const h=Math.max(0,Math.min(e-i,n));return Math.round(h/n*r.maxOffset)}function ye(s){const{bounds:t,clientX:e,clientY:i,cols:r,rows:n,metrics:h,padding:c,originY:d}=s,f=e-t.left-c,p=i-t.top-d;return f<0||p<0||f>=r*h.width||p>=n*h.height?null:{x:Math.floor(f/h.width),y:Math.floor(p/h.height)}}function ge(s,t){const e=s.cells.map(i=>i.text||" ").join("");return t?e.trimEnd():e}function yt(s,t){let e=0;for(let i=0;i<t;i+=1)e+=s.cells[i]?.text.length||1;return e}function we(s,t,e){return gt(s,t,e)?.text??null}function at(s,t){for(let e=0;e<s.cells.length;e+=1){const i=yt(s,e+1);if(t<i)return e}return Math.max(0,s.cells.length-1)}function gt(s,t,e){const i=Kt(t+1,o=>{const m=s[o];return m?{isWrapped:m.isWrapContinuation,translateToString:(y=!1)=>ge(m,y)}:null});if(!i)return null;const r=i.segments[0];if(r&&s[r.bufferLineNumber-1]?.isWrapContinuation)return null;const n=i.segments.find(o=>o.bufferLineNumber===t+1),h=s[t];if(!n||!h)return null;const c=i.segments.at(-1),f=(c?s[c.bufferLineNumber-1]:void 0)?.wrapsToNext??!1,p=n.startIndex+yt(h,e);for(const o of Ot(i.text))if(p>=o.start&&p<o.end){if(o.end===i.text.length&&f)return null;const m=i.segments.find(b=>o.start>=b.startIndex&&o.start<b.endIndex),y=i.segments.find(b=>o.end-1>=b.startIndex&&o.end-1<b.endIndex),_=m?s[m.bufferLineNumber-1]:void 0,w=y?s[y.bufferLineNumber-1]:void 0;return!m||!y||!_||!w?null:{text:o.text,range:{start:{x:at(_,o.start-m.startIndex),y:m.bufferLineNumber-1},end:{x:at(w,o.end-1-y.startIndex),y:y.bufferLineNumber-1}}}}return null}function Ae(s,t){return we([s],0,t)}function _e(s,t=navigator.platform){return s.key.toLowerCase()!=="c"?!1:tt(t)?s.metaKey:s.ctrlKey&&s.shiftKey}function be(s,t=navigator.platform){return s.key.toLowerCase()!=="v"?!1:tt(t)?s.metaKey:s.ctrlKey&&s.shiftKey}function Se(s){return s.inputType===""||s.inputType==="insertCompositionText"||s.inputType==="insertFromComposition"}function ve(s){return s.getModifierState("AltGraph")&&[...s.key].length===1}function G(s,t){return s&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey}function ke(s,t,e,i){const r=s.deltaMode===1?s.deltaY*t:s.deltaMode===2?s.deltaY*e*t:s.deltaY,n=i+r/t,h=Math.trunc(n);return{rows:h,remainder:n-h}}function Le(s,t){return s===0?"":(s<0?t?"\x1BOA":"\x1B[A":t?"\x1BOB":"\x1B[B").repeat(Math.abs(s))}function z(s,t=navigator.platform){return tt(t)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey}function Te(s,t){return!s||t}function Me(s){switch(s){case 0:return 1;case 1:return 3;case 2:return 2;case 3:return 4;case 4:return 5;default:return null}}function xe(s,t){return{count:s!==null&&t.timeStamp-s.time<=500&&Math.hypot(t.clientX-s.x,t.clientY-s.y)<=4?s.count>=3?1:s.count+1:1,time:t.timeStamp,x:t.clientX,y:t.clientY}}class wt{constructor(t,e,i,r,n,h,c,d,f,p){this.cols=1,this.rows=1,this.fontEpoch=0,this.pendingFontEpoch=null,this.snapshot=null,this.frame=0,this.cursorTimer=null,this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null,this.cursorOn=!0,this.renderedCursorY=null,this.forceFullRender=!0,this.scrollbarDirty=!0,this.scrollbarState=null,this.scrollbarPointerId=null,this.scrollbarPointerOffset=0,this.disposed=!1,this.resizeNotifyTimer=null,this.originY=C,this.mountHeight=0,this.selectionEnd=null,this.selectionAnchorScreen=null,this.selectionEndScreen=null,this.selectionMode="cell",this.selectionBase=null,this.selectionScrollTimer=null,this.selectionScrollDelta=0,this.selectionPointer=null,this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.linkActivationPointerId=null,this.hoveredLink=null,this.hoverPointer=null,this.linkModifierActive=!1,this.selectionClickSequence=null,this.selectionMoved=!1,this.composing=!1,this.focused=!1,this.resizeNotified=!1,this.canvasConfigured=!1,this.suppressedKeyCodes=new Set,this.pasteShortcutToken=0,this.wheelRemainder=0,this.viewportCleared=!1,this.dprMedia=null,this.reducedMotionMedia=window.matchMedia?.("(prefers-reduced-motion: reduce)"),this.inputLeft=-1,this.inputTop=-1,this.onReducedMotionChange=()=>{this.disposed||(this.cursorOn=!0,this.requestRender())},this.onFontsLoaded=()=>{if(this.disposed||this.pendingFontEpoch!==null)return;const o=pt(this.requestedFontFamily);if(o!==this.fontFamily){this.fontFamily=o,this.applyFontMetrics();return}const m=$(this.context,this.fontSize,this.fontFamily);m.width===this.metrics.width&&m.height===this.metrics.height&&m.baseline===this.metrics.baseline||this.applyFontMetrics()},this.onKeyDown=o=>{if(this.updateLinkModifier(o),ve(o)||!this.options.beforeKey(o)){this.suppressedKeyCodes.add(o.code);return}if(_e(o)&&this.hasSelection()){o.preventDefault(),this.suppressedKeyCodes.add(o.code),this.options.onCopy(this.getSelection());return}if(be(o)){this.suppressedKeyCodes.add(o.code);const y=navigator.clipboard;if(typeof y?.readText=="function"){const _=++this.pasteShortcutToken;ct(y.readText().then(w=>{this.disposed||this.pasteShortcutToken!==_||(this.pasteShortcutToken+=1,w.length>0&&this.options.onData(this.core.encodePaste(w)))}),"clipboard")}return}if(o.isComposing||this.composing||o.key==="Process"||o.keyCode===229)return;const m=this.core.encodeKey(o);m.length!==0&&(this.suppressedKeyCodes.delete(o.code),o.preventDefault(),o.stopPropagation(),this.options.onData(m))},this.onKeyUp=o=>{if(this.updateLinkModifier(o),this.suppressedKeyCodes.delete(o.code)||o.isComposing||this.composing||o.key==="Process"||o.keyCode===229)return;const m=this.core.encodeKey(o,"release");m.length!==0&&(o.preventDefault(),o.stopPropagation(),this.options.onData(m))},this.onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender()},this.onBlur=()=>{this.focused=!1,this.linkModifierActive=!1,this.refreshHoveredLink(),this.cursorOn=!0,this.requestRender()},this.onDevicePixelRatioChange=()=>{this.watchDevicePixelRatio(),this.resizeToMount()},this.onPaste=o=>{if(o.preventDefault(),this.options.onPaste!==void 0){this.pasteShortcutToken+=1,this.options.onPaste(o);return}const m=o.clipboardData?.getData("text/plain")??"";m.length!==0&&(this.pasteShortcutToken+=1,this.options.onData(this.core.encodePaste(m)))},this.onCompositionStart=()=>{this.clearCompositionInputSuppression(),this.composing=!0},this.onCompositionEnd=o=>{this.composing=!1;const m=this.input.value||o.data;m.length>0&&this.options.onData(m),this.input.value="",this.compositionInputToSuppress=m,this.compositionSuppressionTimer=window.setTimeout(()=>{this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null},100)},this.onInput=o=>{const m=o;if(this.composing||m.isComposing)return;const y=this.input.value||m.data||"";if(y===this.compositionInputToSuppress&&Se(m)){this.clearCompositionInputSuppression(),this.input.value="";return}this.clearCompositionInputSuppression(),y.length>0&&this.options.onData(y),this.input.value=""},this.onPointerDown=o=>{if(this.focus(),G(this.core.isMouseTracking(),o)){const w=Me(o.button);if(w===null)return;o.preventDefault(),o.stopPropagation(),this.clearHoveredLink("default"),this.mouseReportingPointerId=o.pointerId,this.mouseReportingButton=w,this.sendMouse("press",w,o),this.canvas.setPointerCapture(o.pointerId);return}if(o.button!==0)return;if(z(o)){o.preventDefault(),o.stopPropagation(),this.linkActivationPointerId=o.pointerId,this.canvas.setPointerCapture(o.pointerId);return}this.clearHoveredLink();const m=this.cellAt(o.clientX,o.clientY);this.selectionMoved=!1,this.selectionClickSequence=xe(this.selectionClickSequence,o);const y=this.selectionClickSequence.count;this.selectionMode=y>=3?"line":y===2?"word":"cell";const _=this.selectionMode==="line"?this.core.selectLine(m.x,m.y):this.selectionMode==="word"?this.core.selectWord(m.x,m.y):null;if(_)this.selectionBase=_.screen,this.selectionEnd=_.viewport.end,this.selectionAnchorScreen=_.screen.start,this.selectionEndScreen=_.screen.end,this.options.onSelectionChange();else{this.selectionMode="cell",this.selectionBase=null,this.selectionEnd=m;const w=this.core.viewportPointToScreen(m.x,m.y);this.selectionAnchorScreen=w,this.selectionEndScreen=w,w?this.core.setSelection({...w,tag:2},{...w,tag:2}):this.core.setSelection(m,m)}this.forceFullRender=!0,this.canvas.setPointerCapture(o.pointerId),this.requestRender()},this.onPointerMove=o=>{if(this.linkActivationPointerId===o.pointerId)return;if(this.mouseReportingPointerId===o.pointerId||G(this.core.isMouseAnyEventTracking(),o)){o.preventDefault(),this.hoverPointer={x:o.clientX,y:o.clientY},this.linkModifierActive=z(o),this.setHoveredLink(null),this.canvas.style.cursor="default",this.sendMouse("motion",this.buttonFromButtons(o.buttons),o);return}if(!this.selectionAnchorScreen||!this.canvas.hasPointerCapture(o.pointerId)){this.updateHoverCursor(o);return}this.clearHoveredLink(),this.selectionPointer={x:o.clientX,y:o.clientY};const m=this.canvas.getBoundingClientRect();this.setSelectionAutoscroll(o.clientY<m.top?-1:o.clientY>m.bottom?1:0);const y=this.cellAt(o.clientX,o.clientY);y.x===this.selectionEnd?.x&&y.y===this.selectionEnd.y||this.extendSelectionTo(o.clientX,o.clientY)},this.onPointerLeave=()=>{this.clearHoveredLink()},this.onPointerUp=o=>{if(this.setSelectionAutoscroll(0),this.linkActivationPointerId===o.pointerId){if(o.preventDefault(),o.stopPropagation(),this.linkActivationPointerId=null,this.canvas.hasPointerCapture(o.pointerId)&&this.canvas.releasePointerCapture(o.pointerId),o.type!=="pointercancel"){const m=this.linkAt(o.clientX,o.clientY);m&&this.options.onLinkActivate(m.text,o)}return}if(this.mouseReportingPointerId===o.pointerId){o.preventDefault(),o.stopPropagation(),this.sendMouse("release",this.mouseReportingButton,o),this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.canvas.hasPointerCapture(o.pointerId)&&this.canvas.releasePointerCapture(o.pointerId),o.type==="pointercancel"?this.clearHoveredLink():(this.hoverPointer={x:o.clientX,y:o.clientY},this.linkModifierActive=z(o),this.refreshHoveredLink());return}this.canvas.hasPointerCapture(o.pointerId)&&this.canvas.releasePointerCapture(o.pointerId),o.button===0&&(!this.selectionMoved&&this.selectionMode==="cell"&&this.clearSelection(),this.options.onSelectionChange())},this.onWheel=o=>{if(o.deltaY===0)return;o.preventDefault();const m=ke(o,this.metrics.height,this.rows,this.wheelRemainder);if(this.wheelRemainder=m.remainder,m.rows===0)return;const y=Math.abs(m.rows);if(G(this.core.isMouseTracking(),o)){const _=m.rows<0?4:5;for(let w=0;w<y;w+=1)this.sendMouse("press",_,o);return}et({bufferType:this.core.isAlternateScreen()?"alternate":"normal",mouseTrackingMode:this.core.mouseTrackingMode(),cols:this.cols,rows:this.rows,scrollLines:_=>this.scrollViewport(_),input:_=>this.options.onData(_)},m.rows)},this.onMouseDown=o=>{o.button===0&&o.preventDefault(),this.focus()},this.onContextMenu=o=>{G(this.core.isMouseTracking(),o)&&o.preventDefault()},this.onScrollbarPointerDown=o=>{if(o.button!==0)return;const m=this.readScrollbarState();if(m===null)return;const y=this.scrollbar.getBoundingClientRect(),_=Z(m,y.height);_!==null&&(o.preventDefault(),o.stopPropagation(),this.scrollbarPointerId=o.pointerId,this.scrollbarPointerOffset=o.target===this.scrollbarThumb?o.clientY-y.top-_.thumbTop:_.thumbHeight/2,this.scrollbar.setPointerCapture(o.pointerId),this.scrollbarToPointer(o.clientY,y))},this.onScrollbarPointerMove=o=>{o.pointerId!==this.scrollbarPointerId||this.scrollbarState===null||(o.preventDefault(),this.scrollbarToPointer(o.clientY,this.scrollbar.getBoundingClientRect()))},this.onScrollbarPointerUp=o=>{o.pointerId===this.scrollbarPointerId&&(o.preventDefault(),this.scrollbarPointerId=null,this.scrollbar.hasPointerCapture(o.pointerId)&&this.scrollbar.releasePointerCapture(o.pointerId))},this.onScrollbarKeyDown=o=>{const m=this.readScrollbarState();if(m===null)return;let y=0;switch(o.key){case"ArrowUp":y=-1;break;case"ArrowDown":y=1;break;case"PageUp":y=-Math.max(1,m.len);break;case"PageDown":y=Math.max(1,m.len);break;case"Home":y=-m.offset;break;case"End":y=m.total-m.len-m.offset;break;default:return}o.preventDefault(),o.stopPropagation(),this.scrollViewport(y)},this.mount=t,this.canvas=e,this.input=i,this.scrollbar=r,this.scrollbarThumb=n,this.context=h,this.core=c,this.metrics=d,this.options=p,this.theme=p.theme,this.fontFamily=f,this.requestedFontFamily=p.font?.family,this.fontSize=V(p.font?.size),this.resizeObserver=new ResizeObserver(()=>this.resizeToMount()),this.installEvents(),this.watchDevicePixelRatio(),this.reducedMotionMedia?.addEventListener("change",this.onReducedMotionChange),document.fonts.addEventListener("loadingdone",this.onFontsLoaded),this.resizeObserver.observe(t)}static async create(t,e){const i=document.createElement("canvas");i.className="porcelain-ghostty-canvas",i.style.cssText="display:block;width:100%;height:100%;",i.setAttribute("aria-hidden","true");const r=document.createElement("textarea");r.className="porcelain-ghostty-input",r.setAttribute("aria-label","Terminal input"),r.autocapitalize="off",r.autocomplete="off",r.spellcheck=!1,r.style.cssText="position:absolute;left:4px;top:4px;width:1px;height:1px;opacity:0;padding:0;border:0;resize:none;pointer-events:none;";const n=document.createElement("div");n.className="porcelain-ghostty-scrollbar",n.setAttribute("role","scrollbar"),n.setAttribute("aria-label","Terminal scrollback"),n.setAttribute("aria-orientation","vertical"),n.tabIndex=0,n.hidden=!0;const h=document.createElement("div");h.className="porcelain-ghostty-scrollbar-thumb",n.append(h),t.replaceChildren(i,r,n);const c=i.getContext("2d",{alpha:!1});if(!c)throw new Error("Canvas 2D is unavailable");c.fillStyle=`rgb(${e.theme.background.r}, ${e.theme.background.g}, ${e.theme.background.b})`,c.fillRect(0,0,i.width,i.height);const d=V(e.font?.size);try{await de()}catch{}const f=await ht(e.font?.family,d),p=$(c,d,f),o=lt(t.clientWidth,t.clientHeight,p,C),m=await Q.create(o.cols,o.rows,p.width,p.height,e.theme,e.onData),y=new wt(t,i,r,n,h,c,m,p,f,e);return y.resizeToMount(),y.requestRender(),y}write(t){this.disposed||(this.viewportCleared=!1,this.core.write(t),this.cursorOn=!0,this.scrollbarDirty=!0,this.requestRender())}resetAndWrite(t){this.disposed||(this.viewportCleared=!1,this.core.resetAndWrite(t),this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}setTheme(t){this.disposed||(this.theme=t,this.core.setTheme(t),this.forceFullRender=!0,this.requestRender())}async setFont(t){if(this.disposed)return;const e=V(t.size),i=++this.fontEpoch;this.pendingFontEpoch=i;const r=await ht(t.family,e);this.disposed||i!==this.fontEpoch||(this.pendingFontEpoch=null,this.fontFamily=r,this.requestedFontFamily=t.family,this.fontSize=e,this.applyFontMetrics())}applyFontMetrics(){this.metrics=$(this.context,this.fontSize,this.fontFamily),this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height),this.inputLeft=-1,this.inputTop=-1,this.forceFullRender=!0,this.scrollbarDirty=!0,this.resizeToMount(),this.requestRender()}resizeToMount(){if(this.disposed)return!1;const t=this.mount.clientWidth,e=this.mount.clientHeight;if(t<=0||e<=0)return!1;const i=window.devicePixelRatio||1,r=Math.max(1,Math.round(t*i)),n=Math.max(1,Math.round(e*i));let h=!1;(this.canvas.width!==r||this.canvas.height!==n||!this.canvasConfigured)&&(this.canvas.width=r,this.canvas.height=n,this.context.setTransform(i,0,0,i,0,0),this.canvasConfigured=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,h=!0);const c=lt(t,e,this.metrics,C);return this.mountHeight=e,(c.cols!==this.cols||c.rows!==this.rows||!this.resizeNotified)&&(this.cols=c.cols,this.rows=c.rows,this.core.resize(c.cols,c.rows,this.metrics.width,this.metrics.height),this.notifyResize(),this.forceFullRender=!0,this.scrollbarDirty=!0,h=!0),h&&this.renderFrame(),!0}notifyResize(){this.resizeNotified=!0,this.resizeNotifyTimer!==null&&window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=window.setTimeout(()=>{this.resizeNotifyTimer=null,this.disposed||this.options.onResize(this.cols,this.rows)},150)}focus(){this.input.focus({preventScroll:!0})}blur(){this.input.blur()}isFocused(){return document.activeElement===this.input}paste(t){if(this.disposed||t.length===0)return;const e=this.core.encodePaste(t);e.length>0&&this.options.onData(e)}selectAll(){this.disposed||(this.core.selectAll(),this.options.onSelectionChange(),this.forceFullRender=!0,this.requestRender())}textContentForTesting(){return this.disposed||this.viewportCleared?"":(this.snapshot??this.core.snapshot()).rowData.map(e=>e.cells.map(i=>i.text||" ").join("").trimEnd()).join(`
|
|
1
|
+
import{bm as ct,bw as et}from"./index-CuWbxCsX.js";const _t=["Unidentified","Backquote","Backslash","BracketLeft","BracketRight","Comma","Digit0","Digit1","Digit2","Digit3","Digit4","Digit5","Digit6","Digit7","Digit8","Digit9","Equal","IntlBackslash","IntlRo","IntlYen","KeyA","KeyB","KeyC","KeyD","KeyE","KeyF","KeyG","KeyH","KeyI","KeyJ","KeyK","KeyL","KeyM","KeyN","KeyO","KeyP","KeyQ","KeyR","KeyS","KeyT","KeyU","KeyV","KeyW","KeyX","KeyY","KeyZ","Minus","Period","Quote","Semicolon","Slash","AltLeft","AltRight","Backspace","CapsLock","ContextMenu","ControlLeft","ControlRight","Enter","MetaLeft","MetaRight","ShiftLeft","ShiftRight","Space","Tab","Convert","KanaMode","NonConvert","Delete","End","Help","Home","Insert","PageDown","PageUp","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","NumLock","Numpad0","Numpad1","Numpad2","Numpad3","Numpad4","Numpad5","Numpad6","Numpad7","Numpad8","Numpad9","NumpadAdd","NumpadBackspace","NumpadClear","NumpadClearEntry","NumpadComma","NumpadDecimal","NumpadDivide","NumpadEnter","NumpadEqual","NumpadMemoryAdd","NumpadMemoryClear","NumpadMemoryRecall","NumpadMemoryStore","NumpadMemorySubtract","NumpadMultiply","NumpadParenLeft","NumpadParenRight","NumpadSubtract","NumpadSeparator","NumpadArrowUp","NumpadArrowDown","NumpadArrowRight","NumpadArrowLeft","NumpadBegin","NumpadHome","NumpadEnd","NumpadInsert","NumpadDelete","NumpadPageUp","NumpadPageDown","Escape","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24","F25","Fn","FnLock","PrintScreen","ScrollLock","Pause","BrowserBack","BrowserFavorites","BrowserForward","BrowserHome","BrowserRefresh","BrowserSearch","BrowserStop","Eject","LaunchApp1","LaunchApp2","LaunchMail","MediaPlayPause","MediaSelect","MediaStop","MediaTrackNext","MediaTrackPrevious","Power","Sleep","AudioVolumeDown","AudioVolumeMute","AudioVolumeUp","WakeUp","Copy","Cut","Paste"],bt=new Map(_t.map((s,t)=>[s,t]));function St(s){return bt.get(s)??0}const vt=new Map([["!","1"],["@","2"],["#","3"],["$","4"],["%","5"],["^","6"],["&","7"],["*","8"],["(","9"],[")","0"],["~","`"],["_","-"],["+","="],["{","["],["}","]"],["|","\\"],[":",";"],['"',"'"],["<",","],[">","."],["?","/"]]);let K;async function kt(s){try{return await s()}catch{return}}function Tt(s){ct(Mt().then(s),"fallback")}function Mt(){if(K)return K;const t=globalThis.navigator?.keyboard,e=t===void 0?Promise.resolve(void 0):kt(()=>t.getLayoutMap());return K=e,e}function xt(s,t){if([...s.key].length!==1)return 0;const e=t?.get(s.code);if(e&&[...e].length===1)return e.codePointAt(0)??0;if(/^[A-Z]$/u.test(s.key))return s.key.charCodeAt(0)+32;if(s.shiftKey){const i=vt.get(s.key);if(i)return i.codePointAt(0)??0;const r=s.key.toLowerCase();return r!==s.key&&[...r].length===1?r.codePointAt(0)??0:0}return s.key.codePointAt(0)??0}const Et=""+new URL("ghostty-vt-DdA0Zryv.wasm",import.meta.url).href,At=""+new URL("ghostty-write-pty-CVPirtOQ.wasm",import.meta.url).href,W=new TextDecoder;class j{constructor(t){this.ptyWriters=new Map,this.nextPtyWriterId=1,this.writePtyFunctionIndex=0,this.exports=t.exports;const e=t.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("libghostty-vt did not export WebAssembly memory");this.memory=e;const i=this.call("ghostty_type_json"),r=new Uint8Array(e.buffer);let n=i;for(;n<r.length&&r[n]!==0;)n+=1;this.layouts=JSON.parse(W.decode(r.subarray(i,n)))}static async load(){const t=await fetch(Et);if(!t.ok)throw new Error(`Unable to load libghostty-vt (${t.status})`);let e;const i={env:{log:(h,c)=>{if(!e)return;const d=e.exports.memory;if(!(d instanceof WebAssembly.Memory))return;const f=W.decode(new Uint8Array(d.buffer,h,c));console.debug("[libghostty-vt]",f)}}},r=await WebAssembly.instantiate(await t.arrayBuffer(),i);e=r.instance;const n=new j(r.instance);return await n.installWritePtyTrampoline(),n}call(t,...e){const i=this.exports[t];if(typeof i!="function")throw new Error(`libghostty-vt export is unavailable: ${t}`);return i(...e)}layout(t){const e=this.layouts[t];if(!e)throw new Error(`libghostty-vt type layout is unavailable: ${t}`);return e}alloc(t){const e=this.call("ghostty_wasm_alloc_u8_array",t);if(e===0)throw new Error(`libghostty-vt failed to allocate ${t} bytes`);return new Uint8Array(this.memory.buffer,e,t).fill(0),e}free(t,e){t!==0&&this.call("ghostty_wasm_free_u8_array",t,e)}allocOpaque(){const t=this.call("ghostty_wasm_alloc_opaque");if(t===0)throw new Error("libghostty-vt failed to allocate an opaque pointer");return new DataView(this.memory.buffer).setUint32(t,0,!0),t}freeOpaque(t){t!==0&&this.call("ghostty_wasm_free_opaque",t)}readPointer(t){return new DataView(this.memory.buffer).getUint32(t,!0)}attachPtyWriter(t,e){if(this.writePtyFunctionIndex===0)throw new Error("libghostty-vt PTY callback trampoline is unavailable");const i=this.nextPtyWriterId++;return this.ptyWriters.set(i,e),this.call("ghostty_terminal_set",t,0,i),this.call("ghostty_terminal_set",t,1,this.writePtyFunctionIndex),i}detachPtyWriter(t,e){this.call("ghostty_terminal_set",t,1,0),this.call("ghostty_terminal_set",t,0,0),this.ptyWriters.delete(e)}view(t,e){return new DataView(this.memory.buffer,t,e)}bytes(t,e){return new Uint8Array(this.memory.buffer,t,e)}setField(t,e,i,r){const n=this.layout(e).fields[i];if(!n)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const h=this.view(t+n.offset,n.size);switch(n.type){case"bool":case"u8":h.setUint8(0,r);return;case"u16":h.setUint16(0,r,!0);return;case"i32":h.setInt32(0,r,!0);return;case"u32":case"enum":h.setUint32(0,r,!0);return;case"u64":h.setBigUint64(0,BigInt(r),!0);return;default:throw new Error(`Unsupported libghostty-vt field type: ${n.type}`)}}readField(t,e,i){const r=this.layout(e).fields[i];if(!r)throw new Error(`libghostty-vt field is unavailable: ${e}.${i}`);const n=this.view(t+r.offset,r.size);switch(r.type){case"bool":case"u8":return n.getUint8(0);case"u16":return n.getUint16(0,!0);case"i32":return n.getInt32(0,!0);case"u32":case"enum":return n.getUint32(0,!0);case"u64":return Number(n.getBigUint64(0,!0));default:throw new Error(`Unsupported libghostty-vt field type: ${r.type}`)}}async installWritePtyTrampoline(){const t=await fetch(At);if(!t.ok)throw new Error(`Unable to load the libghostty-vt PTY trampoline (${t.status})`);const i=(await WebAssembly.instantiate(await t.arrayBuffer(),{env:{porcelain_write_pty:(h,c,d,f)=>{const p=this.ptyWriters.get(c);!p||f===0||p(W.decode(new Uint8Array(this.memory.buffer,d,f)))}}})).instance.exports.ghostty_write_pty,r=this.exports.__indirect_function_table;if(typeof i!="function"||!(r instanceof WebAssembly.Table))throw new Error("libghostty-vt did not expose its callback table");const n=r.length;r.grow(1),r.set(n,i),this.writePtyFunctionIndex=n}}let Y=null;function Lt(){return Y??=j.load().catch(s=>{throw Y=null,s}),Y}const k=0,D=-3,Ct=1e4,N=16;function F(s,t){const e=s.fields[t];if(!e)throw new Error(`libghostty-vt layout field is unavailable: ${t}`);return e}const A={cols:1,rows:2,dirty:3,rowIterator:4,background:5,foreground:6,cursor:7,cursorHasValue:8,cursorStyle:10,cursorVisible:11,cursorBlinking:12,cursorInViewport:14,cursorX:15,cursorY:16},H={dirty:1,raw:2,cells:3},I={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},Pt={wide:3},Rt={spacerTail:2},B=new TextDecoder,q=new TextEncoder;function Ft(s,t){const e=(i,r)=>Math.floor((i*155+r*100)/255);return{r:e(s.r,t.r),g:e(s.g,t.g),b:e(s.b,t.b)}}function It(s,t){return s.r===t.r&&s.g===t.g&&s.b===t.b}class Q{constructor(t){this.terminalSlot=0,this.terminal=0,this.renderStateSlot=0,this.renderState=0,this.rowIteratorSlot=0,this.rowCellsSlot=0,this.keyEncoderSlot=0,this.keyEncoder=0,this.keyEventSlot=0,this.keyEvent=0,this.mouseEncoderSlot=0,this.mouseEncoder=0,this.mouseEventSlot=0,this.mouseEvent=0,this.ptyWriterId=0,this.ptyWriter=null,this.scratch=0,this.style=0,this.scrollbar=0,this.rows=[],this.disposed=!1,this.runtime=t,Tt(e=>{this.disposed||(this.keyboardLayoutMap=e)})}static async create(t,e,i,r,n,h){const c=new Q(await Lt());try{return c.initialize(t,e,i,r,n,h),c}catch(d){throw c.dispose(),d}}initialize(t,e,i,r,n,h){const c=this.runtime.layout("GhosttyTerminalOptions").size,d=this.runtime.alloc(c);this.runtime.setField(d,"GhosttyTerminalOptions","cols",t),this.runtime.setField(d,"GhosttyTerminalOptions","rows",e),this.runtime.setField(d,"GhosttyTerminalOptions","max_scrollback",Ct),this.terminalSlot=this.runtime.allocOpaque();const f=this.runtime.call("ghostty_terminal_new",0,this.terminalSlot,d);this.runtime.free(d,c),this.assertSuccess("ghostty_terminal_new",f),this.terminal=this.runtime.readPointer(this.terminalSlot),this.applyDefaultCursorBlink(),this.ptyWriter=h,this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,h),this.renderStateSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_new",this.runtime.call("ghostty_render_state_new",0,this.renderStateSlot)),this.renderState=this.runtime.readPointer(this.renderStateSlot),this.rowIteratorSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_iterator_new",this.runtime.call("ghostty_render_state_row_iterator_new",0,this.rowIteratorSlot)),this.rowCellsSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_render_state_row_cells_new",this.runtime.call("ghostty_render_state_row_cells_new",0,this.rowCellsSlot)),this.keyEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_encoder_new",this.runtime.call("ghostty_key_encoder_new",0,this.keyEncoderSlot)),this.keyEncoder=this.runtime.readPointer(this.keyEncoderSlot),this.keyEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_key_event_new",this.runtime.call("ghostty_key_event_new",0,this.keyEventSlot)),this.keyEvent=this.runtime.readPointer(this.keyEventSlot),this.mouseEncoderSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_encoder_new",this.runtime.call("ghostty_mouse_encoder_new",0,this.mouseEncoderSlot)),this.mouseEncoder=this.runtime.readPointer(this.mouseEncoderSlot),this.mouseEventSlot=this.runtime.allocOpaque(),this.assertSuccess("ghostty_mouse_event_new",this.runtime.call("ghostty_mouse_event_new",0,this.mouseEventSlot)),this.mouseEvent=this.runtime.readPointer(this.mouseEventSlot),this.scratch=this.runtime.alloc(16);const p=this.runtime.layout("GhosttyStyle").size;this.style=this.runtime.alloc(p),this.runtime.setField(this.style,"GhosttyStyle","size",p),this.scrollbar=this.runtime.alloc(this.runtime.layout("GhosttyTerminalScrollbar").size),this.setTheme(n),this.resize(t,e,i,r)}write(t){this.ensureActive();const e=typeof t=="string"?q.encode(t):t;if(e.length===0)return;const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.call("ghostty_terminal_vt_write",this.terminal,i,e.length),this.runtime.free(i,e.length)}resetAndWrite(t){if(this.ensureActive(),this.runtime.call("ghostty_terminal_reset",this.terminal),this.applyDefaultCursorBlink(),this.rows=[],t.length===0)return;const e=this.ptyWriter;this.ptyWriterId!==0&&(this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.ptyWriterId=0);try{this.write(t)}finally{e!==null&&!this.disposed&&(this.ptyWriterId=this.runtime.attachPtyWriter(this.terminal,e))}}resize(t,e,i,r){this.ensureActive(),this.assertSuccess("ghostty_terminal_resize",this.runtime.call("ghostty_terminal_resize",this.terminal,Math.max(1,Math.min(65535,t)),Math.max(1,Math.min(65535,e)),Math.max(1,Math.round(i)),Math.max(1,Math.round(r))))}applyDefaultCursorBlink(){const t=this.runtime.alloc(1);this.runtime.bytes(t,1)[0]=1,this.runtime.call("ghostty_terminal_set",this.terminal,23,t),this.runtime.free(t,1)}setTheme(t){this.ensureActive();const e=this.runtime.alloc(3);for(const[i,r]of[[11,t.foreground],[12,t.background],[13,t.cursor]])this.runtime.bytes(e,3).set([r.r,r.g,r.b]),this.runtime.call("ghostty_terminal_set",this.terminal,i,e);this.runtime.free(e,3)}scroll(t){this.ensureActive();const e=this.runtime.layout("GhosttyTerminalScrollViewport"),i=this.runtime.alloc(e.size);this.runtime.setField(i,"GhosttyTerminalScrollViewport","tag",2);const r=F(e,"value");this.runtime.view(i+r.offset,r.size).setInt32(0,t,!0),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,i),this.runtime.free(i,e.size)}scrollToBottom(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollViewport"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttyTerminalScrollViewport","tag",1),this.runtime.call("ghostty_terminal_scroll_viewport",this.terminal,e),this.runtime.free(e,t.size)}isViewportActive(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,32,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}scrollbarState(){this.ensureActive();const t=this.runtime.layout("GhosttyTerminalScrollbar");return this.runtime.bytes(this.scrollbar,t.size).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,9,this.scrollbar)!==k?null:{total:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","total"),offset:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","offset"),len:this.runtime.readField(this.scrollbar,"GhosttyTerminalScrollbar","len")}}isMouseTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_get",this.terminal,11,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}isMouseAnyEventTracking(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1003,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}mouseTrackingMode(){this.ensureActive();for(const[t,e]of[[1003,"any"],[1002,"drag"],[1e3,"vt200"],[9,"x10"]])if(this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,t,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0)return e;return"none"}isAlternateScreen(){return this.ensureActive(),this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_terminal_get",this.terminal,6,this.scratch)===k&&this.runtime.view(this.scratch,4).getUint32(0,!0)===1}isApplicationCursorKeys(){return this.ensureActive(),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_terminal_mode_get",this.terminal,1,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}encodeKey(t,e="press"){this.ensureActive(),this.runtime.call("ghostty_key_encoder_setopt_from_terminal",this.keyEncoder,this.terminal),this.runtime.call("ghostty_key_event_set_action",this.keyEvent,e==="release"?0:t.repeat?2:1),this.runtime.call("ghostty_key_event_set_key",this.keyEvent,St(t.code));const i=(t.shiftKey?1:0)|(t.ctrlKey?2:0)|(t.altKey?4:0)|(t.metaKey?8:0)|(t.getModifierState("CapsLock")?16:0)|(t.getModifierState("NumLock")?32:0);this.runtime.call("ghostty_key_event_set_mods",this.keyEvent,i),this.runtime.call("ghostty_key_event_set_consumed_mods",this.keyEvent,0),this.runtime.call("ghostty_key_event_set_composing",this.keyEvent,t.isComposing?1:0),this.runtime.call("ghostty_key_event_set_unshifted_codepoint",this.keyEvent,xt(t,this.keyboardLayoutMap));const r=t.key.length===1?t.key:"",n=q.encode(r),h=n.length===0?0:this.runtime.alloc(n.length);h!==0&&this.runtime.bytes(h,n.length).set(n),this.runtime.call("ghostty_key_event_set_utf8",this.keyEvent,h,n.length);const c=this.runtime.call("ghostty_wasm_alloc_usize"),d=this.encodeOutput(c,(f,p)=>this.runtime.call("ghostty_key_encoder_encode",this.keyEncoder,this.keyEvent,f,p,c));return this.runtime.call("ghostty_wasm_free_usize",c),h!==0&&this.runtime.free(h,n.length),d}encodePaste(t){this.ensureActive();const e=q.encode(t);if(e.length===0)return"";const i=this.runtime.alloc(e.length);this.runtime.bytes(i,e.length).set(e),this.runtime.bytes(this.scratch,1)[0]=0;const r=this.runtime.call("ghostty_terminal_mode_get",this.terminal,2004,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0,n=this.runtime.call("ghostty_wasm_alloc_usize");let h="";const c=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,0,0,n),d=this.runtime.view(n,4).getUint32(0,!0);if(c===D&&d>0){const f=this.runtime.alloc(d),p=this.runtime.call("ghostty_paste_encode",i,e.length,r?1:0,f,d,n),o=this.runtime.view(n,4).getUint32(0,!0);h=p===k?B.decode(this.runtime.bytes(f,o)):"",this.runtime.free(f,d)}return this.runtime.call("ghostty_wasm_free_usize",n),this.runtime.free(i,e.length),h}encodeMouse(t){this.ensureActive(),this.runtime.call("ghostty_mouse_encoder_setopt_from_terminal",this.mouseEncoder,this.terminal);const e=this.runtime.layout("GhosttyMouseEncoderSize"),i=this.runtime.alloc(e.size);for(const[f,p]of[["size",e.size],["screen_width",t.screenWidth],["screen_height",t.screenHeight],["cell_width",t.cellWidth],["cell_height",t.cellHeight],["padding_top",t.paddingTop],["padding_bottom",t.paddingBottom],["padding_right",t.paddingRight],["padding_left",t.paddingLeft]])this.runtime.setField(i,"GhosttyMouseEncoderSize",f,Math.max(0,Math.round(p)));this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,2,i),this.runtime.free(i,e.size),this.runtime.bytes(this.scratch,1)[0]=t.anyButtonPressed?1:0,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,3,this.scratch),this.runtime.bytes(this.scratch,1)[0]=1,this.runtime.call("ghostty_mouse_encoder_setopt",this.mouseEncoder,4,this.scratch),this.runtime.call("ghostty_mouse_event_set_action",this.mouseEvent,t.action==="press"?0:t.action==="release"?1:2),t.button===null?this.runtime.call("ghostty_mouse_event_clear_button",this.mouseEvent):this.runtime.call("ghostty_mouse_event_set_button",this.mouseEvent,t.button),this.runtime.call("ghostty_mouse_event_set_mods",this.mouseEvent,t.mods);const r=this.runtime.layout("GhosttyMousePosition"),n=this.runtime.alloc(r.size),h=this.runtime.view(n,r.size);h.setFloat32(F(r,"x").offset,t.x,!0),h.setFloat32(F(r,"y").offset,t.y,!0),this.runtime.call("ghostty_mouse_event_set_position",this.mouseEvent,n),this.runtime.free(n,r.size);const c=this.runtime.call("ghostty_wasm_alloc_usize"),d=this.encodeOutput(c,(f,p)=>this.runtime.call("ghostty_mouse_encoder_encode",this.mouseEncoder,this.mouseEvent,f,p,c));return this.runtime.call("ghostty_wasm_free_usize",c),d}setSelection(t,e){this.ensureActive();const i=this.runtime.layout("GhosttySelection"),r=this.runtime.layout("GhosttyGridRef").size,n=this.runtime.alloc(i.size);let h=0,c=0;try{this.runtime.setField(n,"GhosttySelection","size",i.size),h=this.gridRef(t.x,t.y,t.tag??1),c=this.gridRef(e.x,e.y,e.tag??1);const d=F(i,"start"),f=F(i,"end");this.runtime.bytes(n+d.offset,d.size).set(this.runtime.bytes(h,d.size)),this.runtime.bytes(n+f.offset,f.size).set(this.runtime.bytes(c,f.size)),this.runtime.call("ghostty_terminal_set",this.terminal,21,n)}finally{this.runtime.free(h,r),this.runtime.free(c,r),this.runtime.free(n,i.size)}}selectAll(){this.ensureActive();const t=this.runtime.layout("GhosttySelection"),e=this.runtime.alloc(t.size);this.runtime.setField(e,"GhosttySelection","size",t.size),this.runtime.call("ghostty_terminal_select_all",this.terminal,e)===k&&this.runtime.call("ghostty_terminal_set",this.terminal,21,e),this.runtime.free(e,t.size)}selectWord(t,e){return this.selectAt("GhosttyTerminalSelectWordOptions","ghostty_terminal_select_word",t,e)}selectLine(t,e){return this.selectAt("GhosttyTerminalSelectLineOptions","ghostty_terminal_select_line",t,e)}hyperlinkAt(t,e){this.ensureActive();const i=this.gridRef(t,e),r=this.runtime.call("ghostty_wasm_alloc_usize"),n=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,0,0,r),h=this.runtime.view(r,4).getUint32(0,!0);let c=null;if(n===D&&h>0){const d=this.runtime.alloc(h),f=this.runtime.call("ghostty_grid_ref_hyperlink_uri",i,d,h,r),p=this.runtime.view(r,4).getUint32(0,!0);f===k&&p>0&&(c=B.decode(this.runtime.bytes(d,p))),this.runtime.free(d,h)}return this.runtime.call("ghostty_wasm_free_usize",r),this.runtime.free(i,this.runtime.layout("GhosttyGridRef").size),c}clearSelection(){this.ensureActive(),this.runtime.call("ghostty_terminal_set",this.terminal,21,0)}snapshot(){this.ensureActive(),this.assertSuccess("ghostty_render_state_update",this.runtime.call("ghostty_render_state_update",this.renderState,this.terminal));const t=this.getU16(A.cols),e=this.getU16(A.rows),i=this.getU32(A.dirty),r=this.getColor(A.foreground,{r:229,g:231,b:235}),n=this.getColor(A.background,{r:0,g:0,b:0}),c=this.getBool(A.cursorHasValue)?this.getColor(A.cursor,r):r,d=this.getBool(A.cursorInViewport),f=this.getBool(A.cursorVisible)&&d,p=d?this.getU16(A.cursorX):-1,o=d?this.getU16(A.cursorY):-1;(this.rows.length!==e||this.rows.some(y=>y.cells.length!==t))&&(this.rows=Array.from({length:e},()=>({cells:Array.from({length:t},()=>this.emptyCell(r,n)),text:"",isWrapContinuation:!1,wrapsToNext:!1})));const m=new Set;if(i!==0){this.assertSuccess("ghostty_render_state_get(row iterator)",this.runtime.call("ghostty_render_state_get",this.renderState,A.rowIterator,this.rowIteratorSlot));const y=this.runtime.readPointer(this.rowIteratorSlot);let _=0;for(;_<e&&this.runtime.call("ghostty_render_state_row_iterator_next",y)!==0;)(i===2||this.getRowBool(y,H.dirty))&&(this.rows[_]=this.readRow(y,t,r,n),m.add(_),this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_set",y,0,this.scratch)),_+=1;this.runtime.view(this.scratch,4).setUint32(0,0,!0),this.runtime.call("ghostty_render_state_set",this.renderState,0,this.scratch)}return{cols:t,rows:e,foreground:r,background:n,cursor:c,cursorX:p,cursorY:o,cursorVisible:f,cursorBlinking:this.getBool(A.cursorBlinking),cursorStyle:this.getU32(A.cursorStyle),dirtyRows:m,rowData:this.rows}}selectionText(){this.ensureActive();const t=this.runtime.alloc(N),e=this.runtime.view(t,N);e.setUint32(0,N,!0),e.setUint32(4,0,!0),e.setUint8(8,1),e.setUint8(9,1),e.setUint32(12,0,!0);const i=this.runtime.call("ghostty_wasm_alloc_usize"),r=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,0,0,i),n=this.runtime.view(i,4).getUint32(0,!0);let h="";if(r===D&&n>0){const c=this.runtime.alloc(n),d=this.runtime.call("ghostty_terminal_selection_format_buf",this.terminal,t,c,n,i),f=this.runtime.view(i,4).getUint32(0,!0);d===k&&(h=B.decode(this.runtime.bytes(c,f))),this.runtime.free(c,n)}return this.runtime.call("ghostty_wasm_free_usize",i),this.runtime.free(t,N),h}viewportPointToScreen(t,e){return this.convertPoint(t,e,1,2)}screenPointToViewport(t,e){return this.convertPoint(t,e,2,1)}convertPoint(t,e,i,r){this.ensureActive();const n=this.gridRef(t,e,i),h=this.pointFromGridRef(n,r);return this.runtime.free(n,this.runtime.layout("GhosttyGridRef").size),h}dispose(){if(!this.disposed){if(this.disposed=!0,this.mouseEvent&&this.runtime.call("ghostty_mouse_event_free",this.mouseEvent),this.mouseEncoder&&this.runtime.call("ghostty_mouse_encoder_free",this.mouseEncoder),this.keyEvent&&this.runtime.call("ghostty_key_event_free",this.keyEvent),this.keyEncoder&&this.runtime.call("ghostty_key_encoder_free",this.keyEncoder),this.rowCellsSlot){const t=this.runtime.readPointer(this.rowCellsSlot);t&&this.runtime.call("ghostty_render_state_row_cells_free",t)}if(this.rowIteratorSlot){const t=this.runtime.readPointer(this.rowIteratorSlot);t&&this.runtime.call("ghostty_render_state_row_iterator_free",t)}this.renderState&&this.runtime.call("ghostty_render_state_free",this.renderState),this.terminal&&(this.ptyWriterId&&this.runtime.detachPtyWriter(this.terminal,this.ptyWriterId),this.runtime.call("ghostty_terminal_free",this.terminal)),this.style&&this.runtime.free(this.style,this.runtime.layout("GhosttyStyle").size),this.scrollbar&&this.runtime.free(this.scrollbar,this.runtime.layout("GhosttyTerminalScrollbar").size),this.scratch&&this.runtime.free(this.scratch,16);for(const t of[this.mouseEventSlot,this.mouseEncoderSlot,this.keyEventSlot,this.keyEncoderSlot,this.rowCellsSlot,this.rowIteratorSlot,this.renderStateSlot,this.terminalSlot])this.runtime.freeOpaque(t)}}encodeOutput(t,e){const i=e(0,0),r=this.runtime.view(t,4).getUint32(0,!0);if(i===k&&r===0||i!==D||r===0)return"";const n=this.runtime.alloc(r),h=e(n,r),c=this.runtime.view(t,4).getUint32(0,!0),d=h===k?B.decode(this.runtime.bytes(n,c)):"";return this.runtime.free(n,r),d}readRow(t,e,i,r){this.assertSuccess("ghostty_render_state_row_get(raw)",this.runtime.call("ghostty_render_state_row_get",t,H.raw,this.scratch));const n=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap continuation)",this.runtime.call("ghostty_row_get",n,2,this.scratch+8));const h=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.runtime.bytes(this.scratch+8,1)[0]=0,this.assertSuccess("ghostty_row_get(wrap)",this.runtime.call("ghostty_row_get",n,1,this.scratch+8));const c=this.runtime.bytes(this.scratch+8,1)[0]!==0;this.assertSuccess("ghostty_render_state_row_get(cells)",this.runtime.call("ghostty_render_state_row_get",t,H.cells,this.rowCellsSlot));const d=this.runtime.readPointer(this.rowCellsSlot),f=[];for(;f.length<e&&this.runtime.call("ghostty_render_state_row_cells_next",d)!==0;){let p=this.getCellColor(d,I.foreground,i),o=this.getCellColor(d,I.background,r);const m=this.runtime.layout("GhosttyStyle").size;this.runtime.bytes(this.style,m).fill(0),this.runtime.setField(this.style,"GhosttyStyle","size",m),this.runtime.call("ghostty_render_state_row_cells_get",d,I.style,this.style),this.runtime.readField(this.style,"GhosttyStyle","inverse")!==0&&([p,o]=[o,p]),this.runtime.readField(this.style,"GhosttyStyle","faint")!==0&&(p=Ft(p,o));const _=this.getCellU32(d,I.graphemesLength);let w="";if(_>0){const v=_*4,x=this.runtime.alloc(v);if(this.runtime.call("ghostty_render_state_row_cells_get",d,I.graphemes,x)===k){const M=this.runtime.view(x,v),S=[];for(let T=0;T<_;T+=1)S.push(M.getUint32(T*4,!0));w=String.fromCodePoint(...S)}this.runtime.free(x,v)}let b=0;if(w.length===0&&f.at(-1)?.text.length){this.assertSuccess("ghostty_render_state_row_cells_get(raw)",this.runtime.call("ghostty_render_state_row_cells_get",d,I.raw,this.scratch));const v=this.runtime.view(this.scratch,8).getBigUint64(0,!0);this.runtime.view(this.scratch+8,4).setUint32(0,0,!0),this.assertSuccess("ghostty_cell_get(wide)",this.runtime.call("ghostty_cell_get",v,Pt.wide,this.scratch+8)),b=this.runtime.view(this.scratch+8,4).getUint32(0,!0)}f.push({text:w,wide:b,foreground:p,background:o,bold:this.runtime.readField(this.style,"GhosttyStyle","bold")!==0,italic:this.runtime.readField(this.style,"GhosttyStyle","italic")!==0,invisible:this.runtime.readField(this.style,"GhosttyStyle","invisible")!==0,strikethrough:this.runtime.readField(this.style,"GhosttyStyle","strikethrough")!==0,overline:this.runtime.readField(this.style,"GhosttyStyle","overline")!==0,underline:this.runtime.readField(this.style,"GhosttyStyle","underline")!==0,selected:this.getCellBool(d,I.selected)})}for(;f.length<e;)f.push(this.emptyCell(i,r));return{cells:f,text:f.map(p=>p.text||" ").join("").trimEnd(),isWrapContinuation:h,wrapsToNext:c}}gridRef(t,e,i=1){const r=this.runtime.layout("GhosttyPoint"),n=this.runtime.alloc(r.size);this.runtime.setField(n,"GhosttyPoint","tag",i);const h=F(r,"value"),c=h.offset,d=this.runtime.view(n+c,h.size);d.setUint16(0,Math.max(0,t),!0),d.setUint32(4,Math.max(0,e),!0);const f=this.runtime.layout("GhosttyGridRef").size,p=this.runtime.alloc(f);this.runtime.setField(p,"GhosttyGridRef","size",f);const o=this.runtime.call("ghostty_terminal_grid_ref",this.terminal,n,p);return this.runtime.free(n,r.size),o!==k&&(this.runtime.free(p,f),this.assertSuccess("ghostty_terminal_grid_ref",o)),p}selectAt(t,e,i,r){this.ensureActive();const n=this.runtime.layout(t),h=this.runtime.layout("GhosttySelection"),c=this.runtime.alloc(n.size);let d=0,f=0,p=null;try{this.runtime.setField(c,t,"size",n.size),d=this.gridRef(i,r);const o=F(n,"ref");if(this.runtime.bytes(c+o.offset,o.size).set(this.runtime.bytes(d,o.size)),f=this.runtime.alloc(h.size),this.runtime.setField(f,"GhosttySelection","size",h.size),this.runtime.call(e,this.terminal,c,f)===k){const y=f+F(h,"start").offset,_=f+F(h,"end").offset,w=this.pointFromGridRef(y,1),b=this.pointFromGridRef(_,1),v=this.pointFromGridRef(y,2),x=this.pointFromGridRef(_,2);w&&b&&v&&x&&(p={viewport:{start:w,end:b},screen:{start:v,end:x}}),this.runtime.call("ghostty_terminal_set",this.terminal,21,f)}}finally{this.runtime.free(f,h.size),this.runtime.free(d,this.runtime.layout("GhosttyGridRef").size),this.runtime.free(c,n.size)}return p}pointFromGridRef(t,e){const i=this.runtime.layout("GhosttyPointCoordinate"),r=this.runtime.alloc(i.size),h=this.runtime.call("ghostty_terminal_point_from_grid_ref",this.terminal,t,e,r)===k?{x:this.runtime.readField(r,"GhosttyPointCoordinate","x"),y:this.runtime.readField(r,"GhosttyPointCoordinate","y")}:null;return this.runtime.free(r,i.size),h}getU16(t){return this.runtime.bytes(this.scratch,2).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,2).getUint16(0,!0)}getU32(t){return this.runtime.bytes(this.scratch,4).fill(0),this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.view(this.scratch,4).getUint32(0,!0)}getBool(t){return this.runtime.bytes(this.scratch,1)[0]=0,this.assertSuccess("ghostty_render_state_get",this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)),this.runtime.bytes(this.scratch,1)[0]!==0}getColor(t,e){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_get",this.renderState,t,this.scratch)===k?this.readColor(this.scratch):e}getRowBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_get",t,e,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellU32(t,e){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===k?this.runtime.view(this.scratch,4).getUint32(0,!0):0}getCellBool(t,e){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===k&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellColor(t,e,i){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call("ghostty_render_state_row_cells_get",t,e,this.scratch)===k?this.readColor(this.scratch):i}readColor(t){const e=this.runtime.bytes(t,3);return{r:e[0]??0,g:e[1]??0,b:e[2]??0}}emptyCell(t,e){return{text:"",wide:0,foreground:t,background:e,bold:!1,italic:!1,invisible:!1,strikethrough:!1,overline:!1,underline:!1,selected:!1}}assertSuccess(t,e){if(e!==k)throw new Error(`${t} failed with result ${e}`)}ensureActive(){if(this.disposed)throw new Error("libghostty-vt terminal has been disposed")}}function O(s,t){return It(s,t)}const zt=""+new URL("SymbolsNerdFontMono-Regular-aK5vsLov.woff2",import.meta.url).href,Dt=/https?:\/\/[^\s"'`<>]+/g,Nt=/(?:~\/|\.{1,2}\/|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}/g,Bt=/[.,;!?]+$/;function Ut(s){let t=s.replace(Bt,"");if(t.length===0)return t;const e=(i,r)=>{for(;t.endsWith(r);){const n=t.split(i).length-1,h=t.split(r).length-1;if(n>=h)return;t=t.slice(0,-1)}};return e("(",")"),e("[","]"),e("{","}"),t}function Gt(s,t){return s.start<t.end&&t.start<s.end}function it(s,t,e,i){const r=[];e.lastIndex=0;for(const n of s.matchAll(e)){const h=n[0],c=n.index??-1;if(c<0||h.length===0)continue;const d=Ut(h);if(d.length===0||t==="path"&&/^https?:\/\//i.test(d))continue;const f={kind:t,text:d,start:c,end:c+d.length};[...i,...r].some(o=>Gt(f,o))||r.push(f)}return r}function Ot(s){const t=it(s,"url",Dt,[]),e=it(s,"path",Nt,t);return[...t,...e].toSorted((i,r)=>i.start-r.start)}function Kt(s,t){const e=t(s-1);if(!e)return null;let i=s,r=e;for(;i>1&&r.isWrapped;){const d=t(i-2);if(!d)return null;i-=1,r=d}const n=[];let h=0,c=i;for(;;){const d=t(c-1);if(!d)break;const p=t(c)?.isWrapped===!0,o=d.translateToString(!p);if(n.push({bufferLineNumber:c,text:o,startIndex:h,endIndex:h+o.length}),h+=o.length,!p)break;c+=1}return{text:n.map(d=>d.text).join(""),segments:n}}const Wt=["normal 400","normal 700","italic 400","italic 700"],Yt=["i","M","W","0","@","#","."," "],Ht=.01;function qt(s){const t=s.split(",").map(e=>e.trim()).filter(e=>e.length>0);return t.length>0?t.join(", "):null}function $t(s){const t=qt(s);if(t===null||typeof document>"u")return!0;try{const e=document.createElement("canvas").getContext("2d");return e===null?!0:Wt.every(i=>{e.font=`${i} 32px ${t}, monospace`;const r=Yt.map(h=>e.measureText(h).width),n=r[0];return n!==void 0&&n>0&&r.every(h=>Math.abs(h-n)<Ht)})}catch{return!0}}const l=0,a=1,u=2,g=3,Vt=new Set([9581,9582,9583,9584]),ut=new Map([[9472,[l,a,l,a]],[9473,[l,u,l,u]],[9474,[a,l,a,l]],[9475,[u,l,u,l]],[9484,[l,a,a,l]],[9485,[l,u,a,l]],[9486,[l,a,u,l]],[9487,[l,u,u,l]],[9488,[l,l,a,a]],[9489,[l,l,a,u]],[9490,[l,l,u,a]],[9491,[l,l,u,u]],[9492,[a,a,l,l]],[9493,[a,u,l,l]],[9494,[u,a,l,l]],[9495,[u,u,l,l]],[9496,[a,l,l,a]],[9497,[a,l,l,u]],[9498,[u,l,l,a]],[9499,[u,l,l,u]],[9500,[a,a,a,l]],[9501,[a,u,a,l]],[9502,[u,a,a,l]],[9503,[a,a,u,l]],[9504,[u,a,u,l]],[9505,[u,u,a,l]],[9506,[a,u,u,l]],[9507,[u,u,u,l]],[9508,[a,l,a,a]],[9509,[a,l,a,u]],[9510,[u,l,a,a]],[9511,[a,l,u,a]],[9512,[u,l,u,a]],[9513,[u,l,a,u]],[9514,[a,l,u,u]],[9515,[u,l,u,u]],[9516,[l,a,a,a]],[9517,[l,a,a,u]],[9518,[l,u,a,a]],[9519,[l,u,a,u]],[9520,[l,a,u,a]],[9521,[l,a,u,u]],[9522,[l,u,u,a]],[9523,[l,u,u,u]],[9524,[a,a,l,a]],[9525,[a,a,l,u]],[9526,[a,u,l,a]],[9527,[a,u,l,u]],[9528,[u,a,l,a]],[9529,[u,a,l,u]],[9530,[u,u,l,a]],[9531,[u,u,l,u]],[9532,[a,a,a,a]],[9533,[a,a,a,u]],[9534,[a,u,a,a]],[9535,[a,u,a,u]],[9536,[u,a,a,a]],[9537,[a,a,u,a]],[9538,[u,a,u,a]],[9539,[u,a,a,u]],[9540,[u,u,a,a]],[9541,[a,a,u,u]],[9542,[a,u,u,a]],[9543,[u,u,a,u]],[9544,[a,u,u,u]],[9545,[u,a,u,u]],[9546,[u,u,u,a]],[9547,[u,u,u,u]],[9552,[l,g,l,g]],[9553,[g,l,g,l]],[9554,[l,g,a,l]],[9555,[l,a,g,l]],[9556,[l,g,g,l]],[9557,[l,l,a,g]],[9558,[l,l,g,a]],[9559,[l,l,g,g]],[9560,[a,g,l,l]],[9561,[g,a,l,l]],[9562,[g,g,l,l]],[9563,[a,l,l,g]],[9564,[g,l,l,a]],[9565,[g,l,l,g]],[9566,[a,g,a,l]],[9567,[g,a,g,l]],[9568,[g,g,g,l]],[9569,[a,l,a,g]],[9570,[g,l,g,a]],[9571,[g,l,g,g]],[9572,[l,g,a,g]],[9573,[l,a,g,a]],[9574,[l,g,g,g]],[9575,[a,g,l,g]],[9576,[g,a,l,a]],[9577,[g,g,l,g]],[9578,[a,g,a,g]],[9579,[g,a,g,a]],[9580,[g,g,g,g]],[9581,[l,a,a,l]],[9582,[l,l,a,a]],[9583,[a,l,l,a]],[9584,[a,a,l,l]],[9588,[l,l,l,a]],[9589,[a,l,l,l]],[9590,[l,a,l,l]],[9591,[l,l,a,l]],[9592,[l,l,l,u]],[9593,[u,l,l,l]],[9594,[l,u,l,l]],[9595,[l,l,u,l]]]);function J(s){if(s.length===0)return!1;const t=s.codePointAt(0);return t===void 0||s.length!==String.fromCodePoint(t).length?!1:t>=9600&&t<=9631?!0:ut.has(t)}function E(s,t,e,i,r){if(i<=t||r<=e)return;const n=typeof s.getTransform=="function"?s.getTransform():null,h=n!==null&&n.a>0?n.a:1,c=n!==null&&n.d>0?n.d:1,d=Math.round(t*h)/h,f=Math.round(e*c)/c,p=Math.max(1/h,Math.round(i*h)/h-d),o=Math.max(1/c,Math.round(r*c)/c-f);s.fillRect(d,f,p,o)}function Xt(s,t,e){const{left:i,right:r,top:n,bottom:h}=e,c=r-i,d=h-n,f=o=>h-d*o/8,p=o=>i+c*o/8;return t===9600?(E(s,i,n,r,n+d/2),!0):t>=9601&&t<=9608?(E(s,i,f(t-9600),r,h),!0):t>=9609&&t<=9615?(E(s,i,n,p(9616-t),h),!0):t===9616?(E(s,i+c/2,n,r,h),!0):t===9620?(E(s,i,n,r,n+d/8),!0):t===9621?(E(s,r-c/8,n,r,h),!0):!1}const Zt=new Map([[9622,[!1,!1,!0,!1]],[9623,[!1,!1,!1,!0]],[9624,[!0,!1,!1,!1]],[9625,[!0,!1,!0,!0]],[9626,[!0,!1,!1,!0]],[9627,[!0,!0,!0,!1]],[9628,[!0,!0,!1,!0]],[9629,[!1,!0,!1,!1]],[9630,[!1,!0,!0,!1]],[9631,[!1,!0,!0,!0]]]);function jt(s,t,e){const i=Zt.get(t);if(i===void 0)return!1;const r=(e.left+e.right)/2,n=(e.top+e.bottom)/2,[h,c,d,f]=i;return h&&E(s,e.left,e.top,r,n),c&&E(s,r,e.top,e.right,n),d&&E(s,e.left,n,r,e.bottom),f&&E(s,r,n,e.right,e.bottom),!0}function st(s,t,e,i,r,n,h){return s&&t?e?[[i,n],[h,r]]:[[i,r]]:s?[[i,e?n:h]]:t?[[e?h:n,r]]:[]}function Qt(s){const t=Math.max(1,Math.round(s/8));return{light:t,heavy:t*2,offset:t*2}}function rt(s,t){return s===u?t.heavy:t.light}function Jt(s,t,e){const i=ut.get(t);if(i===void 0)return!1;const[r,n,h,c]=i,d=Qt(e.right-e.left),f=(e.left+e.right)/2,p=(e.top+e.bottom)/2,{offset:o}=d;if(Vt.has(t))return te(s,i,e,d),!0;if(r===g||h===g)for(const m of[-1,1]){const y=f+m*o,_=(m===-1?c:n)!==l;for(const[w,b]of st(r!==l,h!==l,_,e.top,e.bottom,p-o,p+o))E(s,y-d.light/2,w,y+d.light/2,b)}else if(r!==l||h!==l){const m=rt(r!==l?r:h,d)/2,y=r!==l?e.top:p-m,_=h!==l?e.bottom:p+m;E(s,f-m,y,f+m,_)}if(c===g||n===g)for(const m of[-1,1]){const y=p+m*o,_=(m===-1?r:h)!==l;for(const[w,b]of st(c!==l,n!==l,_,e.left,e.right,f-o,f+o))E(s,w,y-d.light/2,b,y+d.light/2)}else if(c!==l||n!==l){const m=rt(c!==l?c:n,d)/2,y=c!==l?e.left:f-m,_=n!==l?e.right:f+m;E(s,y,p-m,_,p+m)}return!0}function te(s,t,e,i){const[,r,n]=t,h=(e.left+e.right)/2,c=(e.top+e.bottom)/2,d=r!==l?e.right:e.left,f=n!==l?e.bottom:e.top;s.save(),s.beginPath(),s.lineWidth=i.light,s.strokeStyle=s.fillStyle,s.lineCap="butt",s.moveTo(h,f),s.quadraticCurveTo(h,c,d,c),s.stroke(),s.restore()}function nt(s,t,e,i){if(!J(t))return!1;const r=t.codePointAt(0);if(r===void 0)return!1;s.save(),s.fillStyle=i;let n=!1;return r>=9617&&r<=9619?(s.globalAlpha=(r-9616)/4,E(s,e.left,e.top,e.right,e.bottom),n=!0):r>=9600&&r<=9621?n=Xt(s,r,e):r>=9622&&r<=9631?n=jt(s,r,e):n=Jt(s,r,e),s.restore(),n}const ee="rgba(72, 122, 191, 0.35)";function R(s){return`rgb(${s.r}, ${s.g}, ${s.b})`}function ie(s,t){return O(s.foreground,t.foreground)&&s.bold===t.bold&&s.italic===t.italic&&s.invisible===t.invisible}function se(s,t,e){let i=t+1;for(;i<s.length;){const r=s[i];if(!r)break;if(r.wide===Rt.spacerTail){i+=1;continue}if(r.text.length===0||J(r.text)||!e(r))break;i+=1}return i}function ot(s,t,e){const i=s.italic?"italic":"normal",r=s.bold?"700":"400";return`${i} ${r} ${t}px ${e}`}function $(s,t,e){s.font=`normal 400 ${t}px ${e}`;const i=s.measureText("M"),r=s.measureText("Mg"),n=r.actualBoundingBoxAscent||t,h=r.actualBoundingBoxDescent,c=n+h,d=Math.max(1,Math.round(t*1.35),Math.ceil(c));return{width:Math.max(1,i.width),height:d,baseline:Math.round((d-c)/2+n)}}function lt(s,t,e,i){return{cols:Math.max(1,Math.floor((s-i*2)/e.width)),rows:Math.max(1,Math.floor((t-i*2)/e.height))}}function re(s){const{context:t,snapshot:e,metrics:i,fontSize:r,fontFamily:n,padding:h,forceFull:c,cursorOn:d,previousCursorY:f}=s,p=s.focused??!0,o=s.selectionBackground??ee,m=s.hoveredLinkRange??null,y=s.originY??h,_=c?Array.from({length:e.rows},(w,b)=>b):[...e.dirtyRows];f!=null&&f>=0&&!_.includes(f)&&_.push(f),e.cursorVisible&&e.cursorY>=0&&!_.includes(e.cursorY)&&_.push(e.cursorY),c&&(t.save(),t.resetTransform(),t.fillStyle=R(e.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore()),t.textBaseline="alphabetic";for(const w of _){const b=e.rowData[w];if(!b)continue;const v=y+w*i.height;t.fillStyle=R(e.background),t.fillRect(h,v,e.cols*i.width,i.height);let x=0;for(;x<b.cells.length;){const S=b.cells[x];if(!S)break;let T=x+1;for(;T<b.cells.length;){const L=b.cells[T];if(!L||L.selected!==S.selected||!O(L.background,S.background))break;T+=1}if(S.selected||!O(S.background,e.background)){const L=h+x*i.width,P=(T-x)*i.width;O(S.background,e.background)||(t.fillStyle=R(S.background),t.fillRect(L,v,P,i.height)),S.selected&&(t.fillStyle=o,t.fillRect(L,v,P,i.height))}x=T}let M=0;for(;M<b.cells.length;){const S=b.cells[M];if(!S)break;if(S.text.length===0){M+=1;continue}if(J(S.text)){S.invisible||nt(t,S.text,{left:h+M*i.width,right:h+(M+1)*i.width,top:v,bottom:v+i.height},R(S.foreground)),M+=1;continue}const T=se(b.cells,M,P=>ie(P,S)),L=b.cells.slice(M,T).map(P=>P.text).join("");!S.invisible&&L.trim().length>0&&(t.save(),t.beginPath(),t.rect(h+M*i.width,v,(T-M)*i.width,i.height),t.clip(),t.font=ot(S,r,n),t.fillStyle=R(S.foreground),t.fillText(L,h+M*i.width,v+i.baseline,(T-M)*i.width),t.restore()),M=T}for(let S=0;S<b.cells.length;S+=1){const T=b.cells[S],L=m!==null&&w>=m.start.y&&w<=m.end.y&&(w>m.start.y||S>=m.start.x)&&(w<m.end.y||S<=m.end.x);if(!T||!T.underline&&!T.strikethrough&&!T.overline&&!L)continue;t.fillStyle=R(T.foreground);const P=h+S*i.width;(T.underline||L)&&t.fillRect(P,v+i.height-2,i.width,1),T.strikethrough&&t.fillRect(P,v+Math.floor(i.height*.55),i.width,1),T.overline&&t.fillRect(P,v+1,i.width,1)}}if(d&&e.cursorVisible&&e.cursorX>=0&&e.cursorY>=0){const w=h+e.cursorX*i.width,b=y+e.cursorY*i.height;if(t.fillStyle=R(e.cursor),!p)t.strokeStyle=R(e.cursor),t.strokeRect(w+.5,b+.5,i.width-1,i.height-1);else if(e.cursorStyle===0)t.fillRect(w,b,2,i.height);else if(e.cursorStyle===2)t.fillRect(w,b+i.height-2,i.width,2);else if(e.cursorStyle===3)t.strokeStyle=R(e.cursor),t.strokeRect(w+.5,b+.5,i.width-1,i.height-1);else{t.fillRect(w,b,i.width,i.height);const v=e.rowData[e.cursorY]?.cells[e.cursorX];if(v?.text){const x=R(e.background),M={left:w,right:w+i.width,top:b,bottom:b+i.height};nt(t,v.text,M,x)||(t.font=ot(v,r,n),t.fillStyle=x,t.fillText(v.text,w,b+i.baseline,i.width))}}}}function tt(s){return/mac|iphone|ipad|ipod/i.test(s)}const ne=12,oe=6,le=32,dt='"Symbols Nerd Font Mono", "Symbols Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "FiraCode Nerd Font", "Hack Nerd Font", "MesloLGS NF", "CaskaydiaCove Nerd Font", "PowerlineSymbols", monospace',X=`"SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", ${dt}`,C=4,he=18,ae=500,ce="iMW0@# .",ue=["normal 400","normal 700","italic 400","italic 700"];let U=null;function de(){return U!==null||(U=(async()=>{try{const s=new FontFace("Symbols Nerd Font Mono",`url(${zt})`);document.fonts.add(await s.load())}catch{}})()),U}function mt(s){return s.split(",").map(t=>{const e=t.trim();return e.length===0?"":/^(['"]).*\1$/.test(e)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(e)?e:`"${e.replaceAll('"',"")}"`}).filter(t=>t.length>0).join(", ")}function ft(s){const t=s===void 0?"":mt(s);return t.length===0?X:`${t}, ${dt}`}function pt(s){const t=s===void 0?"":mt(s);return t.length===0||!$t(t)?X:ft(t)}async function ht(s,t,e){const i=ft(s),r=e?.load??((n,h)=>document.fonts.load(n,h));try{await Promise.all(ue.map(n=>r(`${n} ${t}px ${i}`,ce)))}catch{}return(e?.resolve??pt)(s)}function V(s){return s===void 0||!Number.isFinite(s)?ne:Math.max(oe,Math.min(le,Math.round(s)))}function me(s){return s.focused&&s.cursorBlinking&&s.cursorVisible&&!s.reducedMotion}function fe(s,t,e,i,r){if(!r)return t;const n=s-t*2-e*i;return t+Math.max(0,n)}function Z(s,t){const e=Math.max(0,s.total),i=Math.max(0,Math.min(s.len,e)),r=Math.max(0,e-i);if(t<=0||i<=0||r===0)return null;const n=Math.min(t,Math.max(he,t*i/e)),h=Math.max(0,t-n),c=Math.max(0,Math.min(s.offset,r));return{thumbHeight:n,thumbTop:h*(c/r),maxOffset:r}}function pe(s,t,e,i){const r=Z(s,t);if(r===null)return 0;const n=Math.max(0,t-r.thumbHeight);if(n===0)return 0;const h=Math.max(0,Math.min(e-i,n));return Math.round(h/n*r.maxOffset)}function ye(s){const{bounds:t,clientX:e,clientY:i,cols:r,rows:n,metrics:h,padding:c,originY:d}=s,f=e-t.left-c,p=i-t.top-d;return f<0||p<0||f>=r*h.width||p>=n*h.height?null:{x:Math.floor(f/h.width),y:Math.floor(p/h.height)}}function ge(s,t){const e=s.cells.map(i=>i.text||" ").join("");return t?e.trimEnd():e}function yt(s,t){let e=0;for(let i=0;i<t;i+=1)e+=s.cells[i]?.text.length||1;return e}function we(s,t,e){return gt(s,t,e)?.text??null}function at(s,t){for(let e=0;e<s.cells.length;e+=1){const i=yt(s,e+1);if(t<i)return e}return Math.max(0,s.cells.length-1)}function gt(s,t,e){const i=Kt(t+1,o=>{const m=s[o];return m?{isWrapped:m.isWrapContinuation,translateToString:(y=!1)=>ge(m,y)}:null});if(!i)return null;const r=i.segments[0];if(r&&s[r.bufferLineNumber-1]?.isWrapContinuation)return null;const n=i.segments.find(o=>o.bufferLineNumber===t+1),h=s[t];if(!n||!h)return null;const c=i.segments.at(-1),f=(c?s[c.bufferLineNumber-1]:void 0)?.wrapsToNext??!1,p=n.startIndex+yt(h,e);for(const o of Ot(i.text))if(p>=o.start&&p<o.end){if(o.end===i.text.length&&f)return null;const m=i.segments.find(b=>o.start>=b.startIndex&&o.start<b.endIndex),y=i.segments.find(b=>o.end-1>=b.startIndex&&o.end-1<b.endIndex),_=m?s[m.bufferLineNumber-1]:void 0,w=y?s[y.bufferLineNumber-1]:void 0;return!m||!y||!_||!w?null:{text:o.text,range:{start:{x:at(_,o.start-m.startIndex),y:m.bufferLineNumber-1},end:{x:at(w,o.end-1-y.startIndex),y:y.bufferLineNumber-1}}}}return null}function Ae(s,t){return we([s],0,t)}function _e(s,t=navigator.platform){return s.key.toLowerCase()!=="c"?!1:tt(t)?s.metaKey:s.ctrlKey&&s.shiftKey}function be(s,t=navigator.platform){return s.key.toLowerCase()!=="v"?!1:tt(t)?s.metaKey:s.ctrlKey&&s.shiftKey}function Se(s){return s.inputType===""||s.inputType==="insertCompositionText"||s.inputType==="insertFromComposition"}function ve(s){return s.getModifierState("AltGraph")&&[...s.key].length===1}function G(s,t){return s&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey}function ke(s,t,e,i){const r=s.deltaMode===1?s.deltaY*t:s.deltaMode===2?s.deltaY*e*t:s.deltaY,n=i+r/t,h=Math.trunc(n);return{rows:h,remainder:n-h}}function Le(s,t){return s===0?"":(s<0?t?"\x1BOA":"\x1B[A":t?"\x1BOB":"\x1B[B").repeat(Math.abs(s))}function z(s,t=navigator.platform){return tt(t)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey}function Te(s,t){return!s||t}function Me(s){switch(s){case 0:return 1;case 1:return 3;case 2:return 2;case 3:return 4;case 4:return 5;default:return null}}function xe(s,t){return{count:s!==null&&t.timeStamp-s.time<=500&&Math.hypot(t.clientX-s.x,t.clientY-s.y)<=4?s.count>=3?1:s.count+1:1,time:t.timeStamp,x:t.clientX,y:t.clientY}}class wt{constructor(t,e,i,r,n,h,c,d,f,p){this.cols=1,this.rows=1,this.fontEpoch=0,this.pendingFontEpoch=null,this.snapshot=null,this.frame=0,this.cursorTimer=null,this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null,this.cursorOn=!0,this.renderedCursorY=null,this.forceFullRender=!0,this.scrollbarDirty=!0,this.scrollbarState=null,this.scrollbarPointerId=null,this.scrollbarPointerOffset=0,this.disposed=!1,this.resizeNotifyTimer=null,this.originY=C,this.mountHeight=0,this.selectionEnd=null,this.selectionAnchorScreen=null,this.selectionEndScreen=null,this.selectionMode="cell",this.selectionBase=null,this.selectionScrollTimer=null,this.selectionScrollDelta=0,this.selectionPointer=null,this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.linkActivationPointerId=null,this.hoveredLink=null,this.hoverPointer=null,this.linkModifierActive=!1,this.selectionClickSequence=null,this.selectionMoved=!1,this.composing=!1,this.focused=!1,this.resizeNotified=!1,this.canvasConfigured=!1,this.suppressedKeyCodes=new Set,this.pasteShortcutToken=0,this.wheelRemainder=0,this.viewportCleared=!1,this.dprMedia=null,this.reducedMotionMedia=window.matchMedia?.("(prefers-reduced-motion: reduce)"),this.inputLeft=-1,this.inputTop=-1,this.onReducedMotionChange=()=>{this.disposed||(this.cursorOn=!0,this.requestRender())},this.onFontsLoaded=()=>{if(this.disposed||this.pendingFontEpoch!==null)return;const o=pt(this.requestedFontFamily);if(o!==this.fontFamily){this.fontFamily=o,this.applyFontMetrics();return}const m=$(this.context,this.fontSize,this.fontFamily);m.width===this.metrics.width&&m.height===this.metrics.height&&m.baseline===this.metrics.baseline||this.applyFontMetrics()},this.onKeyDown=o=>{if(this.updateLinkModifier(o),ve(o)||!this.options.beforeKey(o)){this.suppressedKeyCodes.add(o.code);return}if(_e(o)&&this.hasSelection()){o.preventDefault(),this.suppressedKeyCodes.add(o.code),this.options.onCopy(this.getSelection());return}if(be(o)){this.suppressedKeyCodes.add(o.code);const y=navigator.clipboard;if(typeof y?.readText=="function"){const _=++this.pasteShortcutToken;ct(y.readText().then(w=>{this.disposed||this.pasteShortcutToken!==_||(this.pasteShortcutToken+=1,w.length>0&&this.options.onData(this.core.encodePaste(w)))}),"clipboard")}return}if(o.isComposing||this.composing||o.key==="Process"||o.keyCode===229)return;const m=this.core.encodeKey(o);m.length!==0&&(this.suppressedKeyCodes.delete(o.code),o.preventDefault(),o.stopPropagation(),this.options.onData(m))},this.onKeyUp=o=>{if(this.updateLinkModifier(o),this.suppressedKeyCodes.delete(o.code)||o.isComposing||this.composing||o.key==="Process"||o.keyCode===229)return;const m=this.core.encodeKey(o,"release");m.length!==0&&(o.preventDefault(),o.stopPropagation(),this.options.onData(m))},this.onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender()},this.onBlur=()=>{this.focused=!1,this.linkModifierActive=!1,this.refreshHoveredLink(),this.cursorOn=!0,this.requestRender()},this.onDevicePixelRatioChange=()=>{this.watchDevicePixelRatio(),this.resizeToMount()},this.onPaste=o=>{if(o.preventDefault(),this.options.onPaste!==void 0){this.pasteShortcutToken+=1,this.options.onPaste(o);return}const m=o.clipboardData?.getData("text/plain")??"";m.length!==0&&(this.pasteShortcutToken+=1,this.options.onData(this.core.encodePaste(m)))},this.onCompositionStart=()=>{this.clearCompositionInputSuppression(),this.composing=!0},this.onCompositionEnd=o=>{this.composing=!1;const m=this.input.value||o.data;m.length>0&&this.options.onData(m),this.input.value="",this.compositionInputToSuppress=m,this.compositionSuppressionTimer=window.setTimeout(()=>{this.compositionInputToSuppress=null,this.compositionSuppressionTimer=null},100)},this.onInput=o=>{const m=o;if(this.composing||m.isComposing)return;const y=this.input.value||m.data||"";if(y===this.compositionInputToSuppress&&Se(m)){this.clearCompositionInputSuppression(),this.input.value="";return}this.clearCompositionInputSuppression(),y.length>0&&this.options.onData(y),this.input.value=""},this.onPointerDown=o=>{if(this.focus(),G(this.core.isMouseTracking(),o)){const w=Me(o.button);if(w===null)return;o.preventDefault(),o.stopPropagation(),this.clearHoveredLink("default"),this.mouseReportingPointerId=o.pointerId,this.mouseReportingButton=w,this.sendMouse("press",w,o),this.canvas.setPointerCapture(o.pointerId);return}if(o.button!==0)return;if(z(o)){o.preventDefault(),o.stopPropagation(),this.linkActivationPointerId=o.pointerId,this.canvas.setPointerCapture(o.pointerId);return}this.clearHoveredLink();const m=this.cellAt(o.clientX,o.clientY);this.selectionMoved=!1,this.selectionClickSequence=xe(this.selectionClickSequence,o);const y=this.selectionClickSequence.count;this.selectionMode=y>=3?"line":y===2?"word":"cell";const _=this.selectionMode==="line"?this.core.selectLine(m.x,m.y):this.selectionMode==="word"?this.core.selectWord(m.x,m.y):null;if(_)this.selectionBase=_.screen,this.selectionEnd=_.viewport.end,this.selectionAnchorScreen=_.screen.start,this.selectionEndScreen=_.screen.end,this.options.onSelectionChange();else{this.selectionMode="cell",this.selectionBase=null,this.selectionEnd=m;const w=this.core.viewportPointToScreen(m.x,m.y);this.selectionAnchorScreen=w,this.selectionEndScreen=w,w?this.core.setSelection({...w,tag:2},{...w,tag:2}):this.core.setSelection(m,m)}this.forceFullRender=!0,this.canvas.setPointerCapture(o.pointerId),this.requestRender()},this.onPointerMove=o=>{if(this.linkActivationPointerId===o.pointerId)return;if(this.mouseReportingPointerId===o.pointerId||G(this.core.isMouseAnyEventTracking(),o)){o.preventDefault(),this.hoverPointer={x:o.clientX,y:o.clientY},this.linkModifierActive=z(o),this.setHoveredLink(null),this.canvas.style.cursor="default",this.sendMouse("motion",this.buttonFromButtons(o.buttons),o);return}if(!this.selectionAnchorScreen||!this.canvas.hasPointerCapture(o.pointerId)){this.updateHoverCursor(o);return}this.clearHoveredLink(),this.selectionPointer={x:o.clientX,y:o.clientY};const m=this.canvas.getBoundingClientRect();this.setSelectionAutoscroll(o.clientY<m.top?-1:o.clientY>m.bottom?1:0);const y=this.cellAt(o.clientX,o.clientY);y.x===this.selectionEnd?.x&&y.y===this.selectionEnd.y||this.extendSelectionTo(o.clientX,o.clientY)},this.onPointerLeave=()=>{this.clearHoveredLink()},this.onPointerUp=o=>{if(this.setSelectionAutoscroll(0),this.linkActivationPointerId===o.pointerId){if(o.preventDefault(),o.stopPropagation(),this.linkActivationPointerId=null,this.canvas.hasPointerCapture(o.pointerId)&&this.canvas.releasePointerCapture(o.pointerId),o.type!=="pointercancel"){const m=this.linkAt(o.clientX,o.clientY);m&&this.options.onLinkActivate(m.text,o)}return}if(this.mouseReportingPointerId===o.pointerId){o.preventDefault(),o.stopPropagation(),this.sendMouse("release",this.mouseReportingButton,o),this.mouseReportingPointerId=null,this.mouseReportingButton=null,this.canvas.hasPointerCapture(o.pointerId)&&this.canvas.releasePointerCapture(o.pointerId),o.type==="pointercancel"?this.clearHoveredLink():(this.hoverPointer={x:o.clientX,y:o.clientY},this.linkModifierActive=z(o),this.refreshHoveredLink());return}this.canvas.hasPointerCapture(o.pointerId)&&this.canvas.releasePointerCapture(o.pointerId),o.button===0&&(!this.selectionMoved&&this.selectionMode==="cell"&&this.clearSelection(),this.options.onSelectionChange())},this.onWheel=o=>{if(o.deltaY===0)return;o.preventDefault();const m=ke(o,this.metrics.height,this.rows,this.wheelRemainder);if(this.wheelRemainder=m.remainder,m.rows===0)return;const y=Math.abs(m.rows);if(G(this.core.isMouseTracking(),o)){const _=m.rows<0?4:5;for(let w=0;w<y;w+=1)this.sendMouse("press",_,o);return}et({bufferType:this.core.isAlternateScreen()?"alternate":"normal",mouseTrackingMode:this.core.mouseTrackingMode(),cols:this.cols,rows:this.rows,scrollLines:_=>this.scrollViewport(_),input:_=>this.options.onData(_)},m.rows)},this.onMouseDown=o=>{o.button===0&&o.preventDefault(),this.focus()},this.onContextMenu=o=>{G(this.core.isMouseTracking(),o)&&o.preventDefault()},this.onScrollbarPointerDown=o=>{if(o.button!==0)return;const m=this.readScrollbarState();if(m===null)return;const y=this.scrollbar.getBoundingClientRect(),_=Z(m,y.height);_!==null&&(o.preventDefault(),o.stopPropagation(),this.scrollbarPointerId=o.pointerId,this.scrollbarPointerOffset=o.target===this.scrollbarThumb?o.clientY-y.top-_.thumbTop:_.thumbHeight/2,this.scrollbar.setPointerCapture(o.pointerId),this.scrollbarToPointer(o.clientY,y))},this.onScrollbarPointerMove=o=>{o.pointerId!==this.scrollbarPointerId||this.scrollbarState===null||(o.preventDefault(),this.scrollbarToPointer(o.clientY,this.scrollbar.getBoundingClientRect()))},this.onScrollbarPointerUp=o=>{o.pointerId===this.scrollbarPointerId&&(o.preventDefault(),this.scrollbarPointerId=null,this.scrollbar.hasPointerCapture(o.pointerId)&&this.scrollbar.releasePointerCapture(o.pointerId))},this.onScrollbarKeyDown=o=>{const m=this.readScrollbarState();if(m===null)return;let y=0;switch(o.key){case"ArrowUp":y=-1;break;case"ArrowDown":y=1;break;case"PageUp":y=-Math.max(1,m.len);break;case"PageDown":y=Math.max(1,m.len);break;case"Home":y=-m.offset;break;case"End":y=m.total-m.len-m.offset;break;default:return}o.preventDefault(),o.stopPropagation(),this.scrollViewport(y)},this.mount=t,this.canvas=e,this.input=i,this.scrollbar=r,this.scrollbarThumb=n,this.context=h,this.core=c,this.metrics=d,this.options=p,this.theme=p.theme,this.fontFamily=f,this.requestedFontFamily=p.font?.family,this.fontSize=V(p.font?.size),this.resizeObserver=new ResizeObserver(()=>this.resizeToMount()),this.installEvents(),this.watchDevicePixelRatio(),this.reducedMotionMedia?.addEventListener("change",this.onReducedMotionChange),document.fonts.addEventListener("loadingdone",this.onFontsLoaded),this.resizeObserver.observe(t)}static async create(t,e){const i=document.createElement("canvas");i.className="porcelain-ghostty-canvas",i.style.cssText="display:block;width:100%;height:100%;",i.setAttribute("aria-hidden","true");const r=document.createElement("textarea");r.className="porcelain-ghostty-input",r.setAttribute("aria-label","Terminal input"),r.autocapitalize="off",r.autocomplete="off",r.spellcheck=!1,r.style.cssText="position:absolute;left:4px;top:4px;width:1px;height:1px;opacity:0;padding:0;border:0;resize:none;pointer-events:none;";const n=document.createElement("div");n.className="porcelain-ghostty-scrollbar",n.setAttribute("role","scrollbar"),n.setAttribute("aria-label","Terminal scrollback"),n.setAttribute("aria-orientation","vertical"),n.tabIndex=0,n.hidden=!0;const h=document.createElement("div");h.className="porcelain-ghostty-scrollbar-thumb",n.append(h),t.replaceChildren(i,r,n);const c=i.getContext("2d",{alpha:!1});if(!c)throw new Error("Canvas 2D is unavailable");c.fillStyle=`rgb(${e.theme.background.r}, ${e.theme.background.g}, ${e.theme.background.b})`,c.fillRect(0,0,i.width,i.height);const d=V(e.font?.size);try{await de()}catch{}const f=await ht(e.font?.family,d),p=$(c,d,f),o=lt(t.clientWidth,t.clientHeight,p,C),m=await Q.create(o.cols,o.rows,p.width,p.height,e.theme,e.onData),y=new wt(t,i,r,n,h,c,m,p,f,e);return y.resizeToMount(),y.requestRender(),y}write(t){this.disposed||(this.viewportCleared=!1,this.core.write(t),this.cursorOn=!0,this.scrollbarDirty=!0,this.requestRender())}resetAndWrite(t){this.disposed||(this.viewportCleared=!1,this.core.resetAndWrite(t),this.cursorOn=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}setTheme(t){this.disposed||(this.theme=t,this.core.setTheme(t),this.forceFullRender=!0,this.requestRender())}async setFont(t){if(this.disposed)return;const e=V(t.size),i=++this.fontEpoch;this.pendingFontEpoch=i;const r=await ht(t.family,e);this.disposed||i!==this.fontEpoch||(this.pendingFontEpoch=null,this.fontFamily=r,this.requestedFontFamily=t.family,this.fontSize=e,this.applyFontMetrics())}applyFontMetrics(){this.metrics=$(this.context,this.fontSize,this.fontFamily),this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height),this.inputLeft=-1,this.inputTop=-1,this.forceFullRender=!0,this.scrollbarDirty=!0,this.resizeToMount(),this.requestRender()}resizeToMount(){if(this.disposed)return!1;const t=this.mount.clientWidth,e=this.mount.clientHeight;if(t<=0||e<=0)return!1;const i=window.devicePixelRatio||1,r=Math.max(1,Math.round(t*i)),n=Math.max(1,Math.round(e*i));let h=!1;(this.canvas.width!==r||this.canvas.height!==n||!this.canvasConfigured)&&(this.canvas.width=r,this.canvas.height=n,this.context.setTransform(i,0,0,i,0,0),this.canvasConfigured=!0,this.forceFullRender=!0,this.scrollbarDirty=!0,h=!0);const c=lt(t,e,this.metrics,C);return this.mountHeight=e,(c.cols!==this.cols||c.rows!==this.rows||!this.resizeNotified)&&(this.cols=c.cols,this.rows=c.rows,this.core.resize(c.cols,c.rows,this.metrics.width,this.metrics.height),this.notifyResize(),this.forceFullRender=!0,this.scrollbarDirty=!0,h=!0),h&&this.renderFrame(),!0}notifyResize(){this.resizeNotified=!0,this.resizeNotifyTimer!==null&&window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=window.setTimeout(()=>{this.resizeNotifyTimer=null,this.disposed||this.options.onResize(this.cols,this.rows)},150)}focus(){this.input.focus({preventScroll:!0})}blur(){this.input.blur()}isFocused(){return document.activeElement===this.input}paste(t){if(this.disposed||t.length===0)return;const e=this.core.encodePaste(t);e.length>0&&this.options.onData(e)}selectAll(){this.disposed||(this.core.selectAll(),this.options.onSelectionChange(),this.forceFullRender=!0,this.requestRender())}textContentForTesting(){return this.disposed||this.viewportCleared?"":(this.snapshot??this.core.snapshot()).rowData.map(e=>e.cells.map(i=>i.text||" ").join("").trimEnd()).join(`
|
|
2
2
|
`)}applicationCursorKeys(){return!this.disposed&&this.core.isApplicationCursorKeys()}scrollTouch(t){this.disposed||t===0||et({bufferType:this.core.isAlternateScreen()?"alternate":"normal",mouseTrackingMode:this.core.mouseTrackingMode(),cols:this.cols,rows:this.rows,scrollLines:e=>this.scrollViewport(e),input:e=>this.options.onData(e)},t)}clearViewport(){this.disposed||(this.viewportCleared=!0,this.context.save(),this.context.resetTransform(),this.context.fillStyle=`rgb(${this.theme.background.r}, ${this.theme.background.g}, ${this.theme.background.b})`,this.context.fillRect(0,0,this.canvas.width,this.canvas.height),this.context.restore())}hasSelection(){return this.core.selectionText().length>0}getSelection(){return this.core.selectionText()}getSelectionPosition(){return!this.selectionAnchorScreen||!this.selectionEndScreen||!this.hasSelection()?null:this.selectionAnchorScreen.y<this.selectionEndScreen.y||this.selectionAnchorScreen.y===this.selectionEndScreen.y&&this.selectionAnchorScreen.x<=this.selectionEndScreen.x?{start:this.selectionAnchorScreen,end:this.selectionEndScreen}:{start:this.selectionEndScreen,end:this.selectionAnchorScreen}}getSelectionEndClientRect(){const t=this.getSelectionPosition();if(!t)return null;const e=this.core.screenPointToViewport(t.end.x,t.end.y);if(!e)return null;const i=this.canvas.getBoundingClientRect();return{right:i.left+C+(e.x+1)*this.metrics.width,bottom:i.top+this.originY+(e.y+1)*this.metrics.height}}clearSelection(){this.core.clearSelection(),this.selectionEnd=null,this.selectionAnchorScreen=null,this.selectionEndScreen=null,this.selectionMode="cell",this.selectionBase=null,this.setSelectionAutoscroll(0),this.options.onSelectionChange(),this.forceFullRender=!0,this.requestRender()}scrollToBottom(){this.core.scrollToBottom(),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender()}isAtBottom(){return this.core.isViewportActive()}dispose(){this.disposed||(this.disposed=!0,this.resizeObserver.disconnect(),document.fonts.removeEventListener("loadingdone",this.onFontsLoaded),this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=null,this.reducedMotionMedia?.removeEventListener("change",this.onReducedMotionChange),this.selectionScrollTimer!==null&&window.clearInterval(this.selectionScrollTimer),this.resizeNotifyTimer!==null&&(window.clearTimeout(this.resizeNotifyTimer),this.resizeNotifyTimer=null,this.options.onResize(this.cols,this.rows)),this.frame!==0&&window.cancelAnimationFrame(this.frame),this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.compositionSuppressionTimer!==null&&window.clearTimeout(this.compositionSuppressionTimer),this.removeEvents(),this.core.dispose(),(this.canvas.parentElement===this.mount||this.input.parentElement===this.mount||this.scrollbar.parentElement===this.mount)&&(this.canvas.remove(),this.input.remove(),this.scrollbar.remove()))}watchDevicePixelRatio(){this.dprMedia?.removeEventListener("change",this.onDevicePixelRatioChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDevicePixelRatioChange)}clearCompositionInputSuppression(){this.compositionSuppressionTimer!==null&&(window.clearTimeout(this.compositionSuppressionTimer),this.compositionSuppressionTimer=null),this.compositionInputToSuppress=null}extendSelectionTo(t,e){const i=this.selectionAnchorScreen;if(i===null)return;const r=this.cellAt(t,e);this.selectionMoved=!0,this.selectionEnd=r;const n=this.selectionMode==="line"?this.core.selectLine(r.x,r.y):this.selectionMode==="word"?this.core.selectWord(r.x,r.y):null,h=this.core.viewportPointToScreen(r.x,r.y);if(h===null)return;const c=this.selectionBase,d=c!==null&&(h.y<c.start.y||h.y===c.start.y&&h.x<c.start.x),f=c===null?i:d?c.end:c.start,p=n===null?h:d?n.screen.start:n.screen.end;this.selectionAnchorScreen=f,this.selectionEndScreen=p,this.core.setSelection({...f,tag:2},{...p,tag:2}),this.options.onSelectionChange(),this.forceFullRender=!0,this.requestRender()}setSelectionAutoscroll(t){if(this.selectionScrollDelta=t,t===0){this.selectionScrollTimer!==null&&(window.clearInterval(this.selectionScrollTimer),this.selectionScrollTimer=null);return}this.selectionScrollTimer===null&&(this.selectionScrollTimer=window.setInterval(()=>{if(this.disposed||this.selectionScrollDelta===0)return;this.scrollViewport(this.selectionScrollDelta);const e=this.selectionPointer;e&&this.extendSelectionTo(e.x,e.y)},80))}updateHoverCursor(t){this.hoverPointer={x:t.clientX,y:t.clientY},this.linkModifierActive=z(t),this.refreshHoveredLink()}updateLinkModifier(t){const e=z(t);e!==this.linkModifierActive&&(this.linkModifierActive=e,this.refreshHoveredLink())}clearHoveredLink(t=""){this.hoverPointer=null,this.setHoveredLink(null),this.canvas.style.cursor=t}refreshHoveredLink(){const t=this.hoverPointer,e=t&&Te(this.core.isMouseTracking(),this.linkModifierActive)?this.linkAt(t.x,t.y):null;this.setHoveredLink(e)}setHoveredLink(t){const e=this.hoveredLink,i=e?.text===t?.text&&e?.range.start.x===t?.range.start.x&&e?.range.start.y===t?.range.start.y&&e?.range.end.x===t?.range.end.x&&e?.range.end.y===t?.range.end.y;this.canvas.style.cursor=t?"pointer":"",!i&&(this.hoveredLink=t,this.forceFullRender=!0,this.requestRender())}installEvents(){this.input.addEventListener("keydown",this.onKeyDown),this.input.addEventListener("keyup",this.onKeyUp),this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("blur",this.onBlur),this.input.addEventListener("input",this.onInput),this.input.addEventListener("paste",this.onPaste),this.input.addEventListener("compositionstart",this.onCompositionStart),this.input.addEventListener("compositionend",this.onCompositionEnd),this.canvas.addEventListener("pointerdown",this.onPointerDown),this.canvas.addEventListener("pointermove",this.onPointerMove),this.canvas.addEventListener("pointerleave",this.onPointerLeave),this.canvas.addEventListener("pointerup",this.onPointerUp),this.canvas.addEventListener("pointercancel",this.onPointerUp),this.canvas.addEventListener("wheel",this.onWheel,{passive:!1}),this.canvas.addEventListener("mousedown",this.onMouseDown),this.canvas.addEventListener("contextmenu",this.onContextMenu),this.scrollbar.addEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.addEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.addEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.addEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.addEventListener("keydown",this.onScrollbarKeyDown)}removeEvents(){this.input.removeEventListener("keydown",this.onKeyDown),this.input.removeEventListener("keyup",this.onKeyUp),this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("blur",this.onBlur),this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("paste",this.onPaste),this.input.removeEventListener("compositionstart",this.onCompositionStart),this.input.removeEventListener("compositionend",this.onCompositionEnd),this.canvas.removeEventListener("pointerdown",this.onPointerDown),this.canvas.removeEventListener("pointermove",this.onPointerMove),this.canvas.removeEventListener("pointerleave",this.onPointerLeave),this.canvas.removeEventListener("pointerup",this.onPointerUp),this.canvas.removeEventListener("pointercancel",this.onPointerUp),this.canvas.removeEventListener("wheel",this.onWheel),this.canvas.removeEventListener("mousedown",this.onMouseDown),this.canvas.removeEventListener("contextmenu",this.onContextMenu),this.scrollbar.removeEventListener("pointerdown",this.onScrollbarPointerDown),this.scrollbar.removeEventListener("pointermove",this.onScrollbarPointerMove),this.scrollbar.removeEventListener("pointerup",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("pointercancel",this.onScrollbarPointerUp),this.scrollbar.removeEventListener("keydown",this.onScrollbarKeyDown)}scrollViewport(t){let e=Math.trunc(t);const i=this.readScrollbarState();if(i!==null){const r=Math.max(0,i.total-i.len),n=Math.max(0,Math.min(i.offset+e,r));e=n-i.offset,this.scrollbarState={...i,offset:n}}e!==0&&(this.core.scroll(e),this.forceFullRender=!0,this.scrollbarDirty=!0,this.requestRender())}scrollbarToPointer(t,e){const i=this.scrollbarState;if(i===null)return;const r=pe(i,e.height,t-e.top,this.scrollbarPointerOffset);this.scrollViewport(r-i.offset)}updateScrollbar(){const t=this.readScrollbarState(),e=t===null?null:Z(t,Math.max(0,this.mount.clientHeight-C*2));this.scrollbar.hidden=e===null,!(t===null||e===null)&&(this.scrollbar.setAttribute("aria-valuemin","0"),this.scrollbar.setAttribute("aria-valuemax",String(e.maxOffset)),this.scrollbar.setAttribute("aria-valuenow",String(Math.max(0,Math.min(t.offset,e.maxOffset)))),this.scrollbarThumb.style.height=`${e.thumbHeight}px`,this.scrollbarThumb.style.transform=`translateY(${e.thumbTop}px)`)}readScrollbarState(){const t=this.core.scrollbarState();return this.scrollbarState=t,t}requestRender(){this.disposed||this.frame!==0||(this.frame=window.requestAnimationFrame(()=>{this.frame=0,this.renderFrame()}))}renderFrame(){if(this.disposed)return;if(this.frame!==0&&(window.cancelAnimationFrame(this.frame),this.frame=0),this.snapshot=this.core.snapshot(),this.viewportCleared){this.positionInput(),this.scheduleCursorBlink();return}this.blinkEnabled()||(this.cursorOn=!0);const t=this.readScrollbarState(),e=t!==null&&t.total>t.len,i=fe(this.mountHeight,C,this.rows,this.metrics.height,e);i!==this.originY&&(this.originY=i,this.forceFullRender=!0),this.refreshHoveredLink(),re({context:this.context,snapshot:this.snapshot,metrics:this.metrics,fontSize:this.fontSize,fontFamily:this.fontFamily,padding:C,originY:this.originY,forceFull:this.forceFullRender,cursorOn:this.cursorOn,previousCursorY:this.renderedCursorY,focused:this.focused,hoveredLinkRange:this.hoveredLink?.range??null,...this.theme.selectionBackground!==void 0?{selectionBackground:this.theme.selectionBackground}:{}}),this.positionInput(),this.renderedCursorY=this.cursorOn&&this.snapshot.cursorVisible&&this.snapshot.cursorY>=0?this.snapshot.cursorY:null,this.scrollbarDirty&&(this.scrollbarDirty=!1,this.updateScrollbar()),this.forceFullRender=!1,this.scheduleCursorBlink()}scheduleCursorBlink(){this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,this.blinkEnabled()&&(this.cursorTimer=window.setTimeout(()=>{this.cursorTimer=null,this.cursorOn=!this.cursorOn,this.requestRender()},ae))}blinkEnabled(){const t=this.snapshot;return t?me({focused:this.focused,cursorBlinking:t.cursorBlinking,cursorVisible:t.cursorVisible,reducedMotion:this.reducedMotionMedia?.matches??!1}):!1}positionInput(){const t=this.snapshot;if(!t?.cursorVisible||t.cursorX<0||t.cursorY<0)return;const e=C+t.cursorX*this.metrics.width,i=this.originY+t.cursorY*this.metrics.height;e===this.inputLeft&&i===this.inputTop||(this.inputLeft=e,this.inputTop=i,this.input.style.left=`${e}px`,this.input.style.top=`${i}px`,this.input.style.height=`${this.metrics.height}px`)}cellAt(t,e){const i=this.canvas.getBoundingClientRect();return{x:Math.max(0,Math.min(this.cols-1,Math.floor((t-i.left-C)/this.metrics.width))),y:Math.max(0,Math.min(this.rows-1,Math.floor((e-i.top-this.originY)/this.metrics.height)))}}linkAt(t,e){if(!this.snapshot)return null;const i=ye({bounds:this.canvas.getBoundingClientRect(),clientX:t,clientY:e,cols:this.cols,rows:this.rows,metrics:this.metrics,padding:C,originY:this.originY});if(!i)return null;const r=this.core.hyperlinkAt(i.x,i.y);if(r){const n={...i},h={...i};for(;;){const c=n.x>0?{x:n.x-1,y:n.y}:n.y>0&&this.snapshot.rowData[n.y]?.isWrapContinuation?{x:this.cols-1,y:n.y-1}:null;if(!c||this.core.hyperlinkAt(c.x,c.y)!==r)break;n.x=c.x,n.y=c.y}for(;;){const c=h.x+1<this.cols?{x:h.x+1,y:h.y}:h.y+1<this.rows&&this.snapshot.rowData[h.y]?.wrapsToNext?{x:0,y:h.y+1}:null;if(!c||this.core.hyperlinkAt(c.x,c.y)!==r)break;h.x=c.x,h.y=c.y}return{text:r,range:{start:n,end:h}}}return gt(this.snapshot.rowData,i.y,i.x)}sendMouse(t,e,i){const r=this.canvas.getBoundingClientRect(),n=this.core.encodeMouse({action:t,button:e,mods:(i.shiftKey?1:0)|(i.ctrlKey?2:0)|(i.altKey?4:0)|(i.metaKey?8:0),x:Math.max(0,i.clientX-r.left),y:Math.max(0,i.clientY-r.top),screenWidth:r.width,screenHeight:r.height,cellWidth:this.metrics.width,cellHeight:this.metrics.height,paddingLeft:C,paddingRight:C,paddingTop:this.originY,paddingBottom:Math.max(0,r.height-this.originY-this.rows*this.metrics.height),anyButtonPressed:i.buttons!==0});n.length>0&&this.options.onData(n)}buttonFromButtons(t){return(t&1)!==0?1:(t&4)!==0?3:(t&2)!==0?2:(t&8)!==0?4:(t&16)!==0?5:null}}export{X as DEFAULT_TERMINAL_FONT_FAMILY,ne as DEFAULT_TERMINAL_FONT_SIZE,wt as GhosttyTerminalSurface,xe as advanceTerminalSelectionClickSequence,Me as ghosttyMouseButton,ve as isTerminalAltGraphText,Se as isTerminalCompositionCommitInput,_e as isTerminalCopyShortcut,z as isTerminalLinkPointerGesture,be as isTerminalPasteShortcut,ht as loadTerminalFontFamily,me as shouldBlinkTerminalCursor,G as shouldReportTerminalMouse,Te as shouldShowTerminalLinkHover,fe as terminalContentOriginY,pt as terminalFontFamily,V as terminalFontSize,ye as terminalGridCellAt,Ae as terminalLinkAtColumn,we as terminalLinkAtPosition,gt as terminalLinkAtPositionWithRange,Z as terminalScrollbarGeometry,pe as terminalScrollbarOffsetAtPointer,Le as terminalWheelArrowData,ke as terminalWheelDeltaRows};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e}from"./index-
|
|
1
|
+
import{$ as e}from"./index-CuWbxCsX.js";const t=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],h=e("fold-vertical",t);const a=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]],y=e("unfold-vertical",a);export{h as F,y as U};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as b,aD as j,j as _,n as T}from"./index-BG75F5tP.js";function D(a,d,t){const e=new Array(a);return new Proxy(e,{get(s,n,o){if(typeof n=="string"){const i=n.charCodeAt(0);if(i>=48&&i<=57){const l=+n;if(Number.isInteger(l)&&l>=0&&l<a){let h=s[l];if(!h){const c=d[l*2];h=s[l]={index:l,key:t(l),start:c,size:d[l*2+1],end:c+d[l*2+1],lane:0}}return h}}if(n==="length")return a}return Reflect.get(s,n,o)}})}function O(a,d,t){let e=t.initialDeps??[],s,n=!0;function o(){const i=a();return(i.length!==e.length||i.some((h,c)=>e[c]!==h))&&(e=i,s=d(...i),t?.onChange&&!(n&&t.skipInitialOnChange)&&t.onChange(s),n=!1),s}return o.updateDeps=i=>{e=i},o}function F(a,d){if(a===void 0)throw new Error("Unexpected undefined");return a}const L=(a,d)=>Math.abs(a-d)<1.01,V=(a,d,t)=>{let e;return function(...s){a.clearTimeout(e),e=a.setTimeout(()=>d.apply(this,s),t)}};let y;const C=()=>{if(y!==void 0)return y;if(typeof navigator>"u")return y=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return y=!0;const a=navigator.maxTouchPoints;return y=navigator.platform==="MacIntel"&&a!==void 0&&a>0},k=a=>{const{offsetWidth:d,offsetHeight:t}=a;return{width:d,height:t}},K=a=>a,P=a=>{const d=Math.max(a.startIndex-a.overscan,0),e=Math.min(a.endIndex+a.overscan,a.count-1)-d+1,s=new Array(e);for(let n=0;n<e;n++)s[n]=d+n;return s},N=(a,d)=>{const t=a.scrollElement;if(!t)return;const e=a.targetWindow;if(!e)return;const s=o=>{const{width:i,height:l}=o;d({width:Math.round(i),height:Math.round(l)})};if(s(k(t)),!e.ResizeObserver)return()=>{};const n=new e.ResizeObserver(o=>{const i=()=>{const l=o[0];if(l?.borderBoxSize){const h=l.borderBoxSize[0];if(h){s({width:h.inlineSize,height:h.blockSize});return}}s(k(t))};a.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()});return n.observe(t,{box:"border-box"}),()=>{n.unobserve(t)}},M={passive:!0},B=typeof window>"u"?!0:"onscrollend"in window,H=(a,d,t)=>{const e=a.scrollElement;if(!e)return;const s=a.targetWindow;if(!s)return;const n=a.options.useScrollendEvent&&B;let o=0;const i=n?null:V(s,()=>d(o,!1),a.options.isScrollingResetDelay),l=f=>()=>{o=t(e),i?.(),d(o,f)},h=l(!0),c=l(!1);return e.addEventListener("scroll",h,M),n&&e.addEventListener("scrollend",c,M),()=>{e.removeEventListener("scroll",h),n&&e.removeEventListener("scrollend",c)}},$=(a,d)=>H(a,d,t=>{const{horizontal:e,isRtl:s}=a.options;return e?t.scrollLeft*(s&&-1||1):t.scrollTop}),J=(a,d,t)=>{if(t.options.useCachedMeasurements){const e=t.indexFromElement(a),s=t.options.getItemKey(e);return t.itemSizeCache.get(s)??t.options.estimateSize(e)}if(d?.borderBoxSize){const e=d.borderBoxSize[0];if(e)return Math.round(e[t.options.horizontal?"inlineSize":"blockSize"])}if(!d){const e=t.indexFromElement(a),s=t.options.getItemKey(e),n=t.itemSizeCache.get(s);if(n!==void 0)return n}return a[t.options.horizontal?"offsetWidth":"offsetHeight"]},q=(a,{adjustments:d=0,behavior:t},e)=>{var s,n;(n=(s=e.scrollElement)==null?void 0:s.scrollTo)==null||n.call(s,{[e.options.horizontal?"left":"top"]:a+d,behavior:t})},U=q;class X{constructor(d){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var t,e,s;return((s=(e=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:e.now)==null?void 0:s.call(e))??Date.now()},this.observer=(()=>{let t=null;const e=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(s=>{s.forEach(n=>{const o=()=>{const i=n.target,l=this.indexFromElement(i);if(!i.isConnected){this.observer.unobserve(i);for(const[h,c]of this.elementsCache)if(c===i){this.elementsCache.delete(h);break}return}this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(i,n,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var s;(s=e())==null||s.disconnect(),t=null},observe:s=>{var n;return(n=e())==null?void 0:n.observe(s,{box:"border-box"})},unobserve:s=>{var n;return(n=e())==null?void 0:n.unobserve(s)}}})(),this.range=null,this.setOptions=t=>{var e,s;const n={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:K,rangeExtractor:P,onChange:()=>{},measureElement:J,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const r in t){const m=t[r];m!==void 0&&(n[r]=m)}const o=this.options;let i=null,l=null,h=!1;if(o!==void 0&&o.enabled&&n.enabled&&n.anchorTo==="end"&&this.scrollElement!==null){const r=o.count,m=n.count,u=this.getMeasurements(),p=r>0?((e=u[0])==null?void 0:e.key)??o.getItemKey(0):null,S=r>0?((s=u[r-1])==null?void 0:s.key)??o.getItemKey(r-1):null;if(m!==r||r>0&&m>0&&(n.getItemKey(0)!==p||n.getItemKey(m-1)!==S)){h=!0;const g=r>0?this.getVirtualItemForOffset(this.getScrollOffset())??u[0]:null;g&&(i=[g.key,this.getScrollOffset()-g.start]);const x=n.followOnAppend===!0?"auto":n.followOnAppend||null;x&&m>r&&this.isAtEnd(o.scrollEndThreshold)&&(r===0||n.getItemKey(m-1)!==S)&&(l=x)}}this.options=n,h&&(this.pendingMin=0,this.itemSizeCacheVersion++);let c=!1,f=0;if(i&&this.scrollOffset!==null){const[r,m]=i,u=this.getMeasurements(),{count:p,getItemKey:S}=this.options;let v=0;for(;v<p&&S(v)!==r;)v++;if(v<p){const E=u[v];if(E){const g=E.start+m;g!==this.scrollOffset&&(f=g-this.scrollOffset,this.scrollOffset=g,c=!0)}}}(c||l)&&(this.pendingScrollAnchor=[c?i[0]:null,c?i[1]:0,l,f])},this.notify=t=>{var e,s;(s=(e=this.options).onChange)==null||s.call(e,this,t)},this.maybeNotify=O(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(n=>{this.observer.observe(n)}),this.unsubs.push(this.options.observeElementRect(this,n=>{this.scrollRect=n,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(n,o)=>{this._intendedScrollOffset!==null&&Math.abs(n-this._intendedScrollOffset)<1.5&&(n=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<n?"forward":"backward":null,this.scrollOffset=n,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const n=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},i=()=>{this._iosTouching=!1,!(!C()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};n.addEventListener("touchstart",o,M),n.addEventListener("touchend",i,M),this.unsubs.push(()=>{n.removeEventListener("touchstart",o),n.removeEventListener("touchend",i),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){const[n,o,i,l]=s;n!==null&&!i&&(C()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?l!==0&&(this._iosDeferredAdjustment+=l):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),i&&this.scrollToEnd({behavior:i})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const t=this.getScrollOffset(),e=this.getMaxScrollOffset();if(t<0||t>e)return;const s=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=s,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(t,e)=>{const s=new Map,n=new Map;for(let o=e-1;o>=0;o--){const i=t[o];if(s.has(i.lane))continue;const l=n.get(i.lane);if(l==null||i.end>l.end?n.set(i.lane,i):i.end<l.end&&s.set(i.lane,!0),s.size===this.options.lanes)break}return n.size===this.options.lanes?Array.from(n.values()).sort((o,i)=>o.end===i.end?o.index-i.index:o.end-i.end)[0]:void 0},this.getMeasurementOptions=O(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(t,e,s,n,o,i,l)=>(this.prevLanes!==void 0&&this.prevLanes!==i&&(this.lanesChangedFlag=!0),this.prevLanes=i,this.pendingMin=null,{count:t,paddingStart:e,scrollMargin:s,getItemKey:n,enabled:o,lanes:i,laneAssignmentMode:l}),{key:!1}),this.getMeasurements=O(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:e,scrollMargin:s,getItemKey:n,enabled:o,lanes:i,laneAssignmentMode:l},h)=>{const c=this.itemSizeCache;if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const u of this.laneAssignments.keys())u>=t&&this.laneAssignments.delete(u);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const f=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),i===1){const u=this.options.gap,p=t*2;let S=this._flatMeasurements;if(!S||S.length<p){const g=new Float64Array(p);S&&f>0&&g.set(S.subarray(0,f*2)),S=g,this._flatMeasurements=S}let v;if(f===0)v=e+s;else{const g=f-1;v=S[g*2]+S[g*2+1]+u}for(let g=f;g<t;g++){const x=n(g),I=c.get(x),w=typeof I=="number"?I:this.options.estimateSize(g);S[g*2]=v,S[g*2+1]=w,v+=w+u}const E=D(t,S,n);return this.measurementsCache=E,E}const r=this.measurementsCache.slice(0,f),m=new Array(i).fill(void 0);for(let u=0;u<f;u++){const p=r[u];p&&(m[p.lane]=u)}for(let u=f;u<t;u++){const p=n(u),S=this.laneAssignments.get(u);let v,E;const g=l==="estimate"||c.has(p);if(S!==void 0&&this.options.lanes>1){v=S;const z=m[v],R=z!==void 0?r[z]:void 0;E=R?R.end+this.options.gap:e+s}else{const z=this.options.lanes===1?r[u-1]:this.getFurthestMeasurement(r,u);E=z?z.end+this.options.gap:e+s,v=z?z.lane:u%this.options.lanes,this.options.lanes>1&&g&&this.laneAssignments.set(u,v)}const x=c.get(p),I=typeof x=="number"?x:this.options.estimateSize(u),w=E+I;r[u]={index:u,start:E,size:I,end:w,key:p,lane:v},m[v]=u}return this.measurementsCache=r,r},{key:!1,debug:()=>this.options.debug}),this.calculateRange=O(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,e,s,n)=>this.range=t.length>0&&e>0?G({measurements:t,outerSize:e,scrollOffset:s,lanes:n,flat:n===1&&this._flatMeasurements!=null?this._flatMeasurements:null}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=O(()=>{let t=null,e=null;const s=this.calculateRange();return s&&(t=s.startIndex,e=s.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,e]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,e]},(t,e,s,n,o)=>n===null||o===null?[]:t({startIndex:n,endIndex:o,overscan:e,count:s}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const e=this.options.indexAttribute,s=t.getAttribute(e);return s?parseInt(s,10):(console.warn(`Missing attribute name '${e}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var e;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const s=this.scrollState.index??((e=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:e.index);if(s!==void 0&&this.range){const n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,s-n),i=Math.min(this.options.count-1,s+n);return t>=o&&t<=i}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((o,i)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(i))});return}const e=this.indexFromElement(t),s=this.options.getItemKey(e),n=this.elementsCache.get(s);n!==t&&(n&&this.observer.unobserve(n),this.observer.observe(t),this.elementsCache.set(s,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(e)&&this.resizeItem(e,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,e)=>{var s,n;if(t<0||t>=this.options.count)return;let o,i,l;const h=this._flatMeasurements;if(this.options.lanes===1&&h!==null)l=this.options.getItemKey(t),i=h[t*2],o=h[t*2+1];else{const r=this.measurementsCache[t];if(!r)return;l=r.key,i=r.start,o=r.size}const c=this.itemSizeCache.get(l)??o,f=e-c;if(f!==0){const r=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,m=r?this.getTotalSize():0,u=((n=this.scrollState)==null?void 0:n.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:l,start:i,size:o,end:i+o,lane:0},f,this):i<this.getScrollOffset()+this.scrollAdjustments&&this.scrollDirection!=="backward");(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(l,e),this.itemSizeCacheVersion++,r?this.applyScrollAdjustment(this.getTotalSize()-m):u&&this.applyScrollAdjustment(f),this.notify(!1)}},this.getVirtualItems=O(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,e)=>{const s=[];for(let n=0,o=t.length;n<o;n++){const i=t[n],l=e[i];s.push(l)}return s},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const e=this.getMeasurements();if(e.length===0)return;const s=this._flatMeasurements,n=this.options.lanes===1&&s!=null,o=W(0,e.length-1,n?i=>s[i*2]:i=>F(e[i]).start,t);return F(e[o])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,e,s=0)=>{if(!this.scrollElement)return 0;const n=this.getSize(),o=this.getScrollOffset();e==="auto"&&(e=t>=o+n?"end":"start"),e==="center"?t+=(s-n)/2:e==="end"&&(t-=n);const i=this.getMaxScrollOffset();return Math.max(Math.min(i,t),0)},this.getOffsetForIndex=(t,e="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const s=this.getSize(),n=this.getScrollOffset(),o=this.measurementsCache[t];if(!o)return;if(e==="auto")if(o.end>=n+s-this.options.scrollPaddingEnd)e="end";else if(o.start<=n+this.options.scrollPaddingStart)e="start";else return[n,e];if(e==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),e];const i=e==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(i,e,o.size),e]},this.scrollToOffset=(t,{align:e="start",behavior:s="auto"}={})=>{const n=this.getOffsetForAlignment(t,e),o=this.now();this.scrollState={index:null,align:e,behavior:s,startedAt:o,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:e="auto",behavior:s="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const n=this.getOffsetForIndex(t,e);if(!n)return;const[o,i]=n,l=this.now();this.scrollState={index:t,align:i,behavior:s,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:e="auto"}={})=>{const s=this.getScrollOffset()+t,n=this.now();this.scrollState={index:null,align:"start",behavior:e,startedAt:n,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:e}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t;const e=this.getMeasurements();let s;if(e.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){const n=e.length-1,o=this._flatMeasurements;o!=null?s=o[n*2]+o[n*2+1]:s=((t=e[n])==null?void 0:t.end)??0}else{const n=Array(this.options.lanes).fill(null);let o=e.length-1;for(;o>=0&&n.some(i=>i===null);){const i=e[o];n[i.lane]===null&&(n[i.lane]=i.end),o--}s=Math.max(...n.filter(i=>i!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const t=[];if(this.itemSizeCache.size===0)return t;const e=this.getMeasurements();for(const s of e)s&&this.itemSizeCache.has(s.key)&&t.push({index:s.index,key:s.key,start:s.start,size:s.size,end:s.end,lane:s.lane});return t},this._scrollToOffset=(t,{adjustments:e,behavior:s})=>{this._intendedScrollOffset=t+(e??0),this.options.scrollToFn(t,{behavior:s,adjustments:e},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(d)}applyScrollAdjustment(d,t){d!==0&&(C()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=d:this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=d,behavior:t}))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const e=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,s=e?e[0]:this.scrollState.lastTargetOffset,n=1,o=s!==this.scrollState.lastTargetOffset;if(!o&&L(s,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=n){this.getScrollOffset()!==s&&this._scrollToOffset(s,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){const i=this.getSize()||600,l=Math.abs(s-this.getScrollOffset()),h=this.scrollState.behavior==="smooth"&&l>i;this.scrollState.lastTargetOffset=s,h||(this.scrollState.behavior="auto"),this._scrollToOffset(s,{adjustments:void 0,behavior:h?"smooth":"auto"})}this.scheduleScrollReconcile()}}const W=(a,d,t,e)=>{for(;a<=d;){const s=(a+d)/2|0,n=t(s);if(n<e)a=s+1;else if(n>e)d=s-1;else return s}return a>0?a-1:0};function G({measurements:a,outerSize:d,scrollOffset:t,lanes:e,flat:s}){const n=a.length-1,o=s?c=>s[c*2]:c=>a[c].start,i=s?c=>s[c*2]+s[c*2+1]:c=>a[c].end;if(a.length<=e)return{startIndex:0,endIndex:n};let l=W(0,n,o,t),h=l;if(e===1)for(;h<n&&i(h)<t+d;)h++;else if(e>1){const c=Array(e).fill(0);for(;h<n&&c.some(r=>r<t+d);){const r=a[h];c[r.lane]=r.end,h++}const f=Array(e).fill(t+d);for(;l>=0&&f.some(r=>r>=t);){const r=a[l];f[r.lane]=r.start,l--}l=Math.max(0,l-l%e),h=Math.min(n,h+(e-1-h%e))}return{startIndex:l,endIndex:h}}const A=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Q({useFlushSync:a=!0,directDomUpdates:d=!1,directDomUpdatesMode:t="transform",...e}){const s=b.useReducer(h=>h+1,0)[1],n=b.useRef({enabled:d,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});n.current.enabled=d,n.current.mode=t;const o=h=>{const c=n.current;if(!c.enabled)return;const f=h.getTotalSize();if(c.container&&f!==c.lastSize){c.lastSize=f;const v=h.options.horizontal?"width":"height";c.container.style[v]=`${f}px`}const r=!!h.options.horizontal,m=c.mode==="transform",u=r?"left":"top",p=h.options.scrollMargin,S=h.getVirtualItems();for(const v of S){const E=v.start-p,g=h.elementsCache.get(v.key);g&&c.lastPositions.get(g)!==E&&(c.lastPositions.set(g,E),m?g.style.transform=r?`translate3d(${E}px, 0, 0)`:`translate3d(0, ${E}px, 0)`:g.style[u]=`${E}px`)}},i={...e,onChange:(h,c)=>{var f;const r=n.current;let m=!0;if(r.enabled){o(h);const u=h.range,p=r.prevRange;m=!p||p.isScrolling!==h.isScrolling||p.startIndex!==u?.startIndex||p.endIndex!==u?.endIndex,m&&(r.prevRange=u?{startIndex:u.startIndex,endIndex:u.endIndex,isScrolling:h.isScrolling}:null)}m&&(a&&c?j.flushSync(s):s()),(f=e.onChange)==null||f.call(e,h,c)}},[l]=b.useState(()=>{const h=new X(i);return Object.assign(h,{containerRef:c=>{const f=n.current;if(f.container=c,f.lastSize=null,c&&f.enabled){const r=h.getTotalSize();f.lastSize=r;const m=h.options.horizontal?"width":"height";c.style[m]=`${r}px`}}})});return l.setOptions(i),A(()=>l._didMount(),[]),A(()=>l._willUpdate()),A(()=>{o(l)}),l}function Y(a){return Q({observeElementRect:N,observeElementOffset:$,scrollToFn:U,...a})}const Z=20;function et({rows:a,renderRow:d,className:t,scrollToLine:e,scrollNonce:s,scrollAlign:n="center",onTopRow:o,fitWidth:i=!1,dynamicHeight:l=!1}){const h=b.useRef(null),c=Y({count:a.length,getScrollElement:()=>h.current,estimateSize:()=>Z,overscan:30}),f=b.useRef(c);return b.useEffect(()=>{f.current=c}),b.useEffect(()=>{e!==void 0&&e>=1&&f.current.scrollToIndex(e-1,{align:n})},[e,s,n]),b.useEffect(()=>{const r=h.current;if(!r||!o)return;let m=-1;const u=()=>{const p=f.current.getVirtualItems().find(S=>S.end>r.scrollTop);p&&p.index!==m&&(m=p.index,o(p.index))};return u(),r.addEventListener("scroll",u,{passive:!0}),()=>r.removeEventListener("scroll",u)},[o]),b.useEffect(()=>{const r=h.current;if(!r||!l)return;const m=()=>r.style.setProperty("--vrows-vw",`${r.clientWidth}px`);m();const u=new ResizeObserver(m);return u.observe(r),()=>u.disconnect()},[l]),_.jsx("div",{ref:h,className:T("h-full overflow-auto font-mono text-xs",t),children:_.jsx("div",{className:T("relative",i?"w-full":"w-max min-w-full"),style:{height:c.getTotalSize()},children:c.getVirtualItems().map(r=>{const m=a[r.index];return m===void 0?null:_.jsx("div",{"data-index":r.index,ref:l?c.measureElement:void 0,className:T("absolute left-0",i?"w-full":"w-max min-w-full"),style:l?{top:r.start}:{top:r.start,height:r.size},children:d(m,r.index)},r.key)})})})}export{Z as R,et as V};
|
|
1
|
+
import{r as b,aF as j,j as _,n as T}from"./index-CuWbxCsX.js";function D(a,d,t){const e=new Array(a);return new Proxy(e,{get(s,n,o){if(typeof n=="string"){const i=n.charCodeAt(0);if(i>=48&&i<=57){const l=+n;if(Number.isInteger(l)&&l>=0&&l<a){let h=s[l];if(!h){const c=d[l*2];h=s[l]={index:l,key:t(l),start:c,size:d[l*2+1],end:c+d[l*2+1],lane:0}}return h}}if(n==="length")return a}return Reflect.get(s,n,o)}})}function O(a,d,t){let e=t.initialDeps??[],s,n=!0;function o(){const i=a();return(i.length!==e.length||i.some((h,c)=>e[c]!==h))&&(e=i,s=d(...i),t?.onChange&&!(n&&t.skipInitialOnChange)&&t.onChange(s),n=!1),s}return o.updateDeps=i=>{e=i},o}function F(a,d){if(a===void 0)throw new Error("Unexpected undefined");return a}const L=(a,d)=>Math.abs(a-d)<1.01,V=(a,d,t)=>{let e;return function(...s){a.clearTimeout(e),e=a.setTimeout(()=>d.apply(this,s),t)}};let y;const C=()=>{if(y!==void 0)return y;if(typeof navigator>"u")return y=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return y=!0;const a=navigator.maxTouchPoints;return y=navigator.platform==="MacIntel"&&a!==void 0&&a>0},k=a=>{const{offsetWidth:d,offsetHeight:t}=a;return{width:d,height:t}},K=a=>a,P=a=>{const d=Math.max(a.startIndex-a.overscan,0),e=Math.min(a.endIndex+a.overscan,a.count-1)-d+1,s=new Array(e);for(let n=0;n<e;n++)s[n]=d+n;return s},N=(a,d)=>{const t=a.scrollElement;if(!t)return;const e=a.targetWindow;if(!e)return;const s=o=>{const{width:i,height:l}=o;d({width:Math.round(i),height:Math.round(l)})};if(s(k(t)),!e.ResizeObserver)return()=>{};const n=new e.ResizeObserver(o=>{const i=()=>{const l=o[0];if(l?.borderBoxSize){const h=l.borderBoxSize[0];if(h){s({width:h.inlineSize,height:h.blockSize});return}}s(k(t))};a.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()});return n.observe(t,{box:"border-box"}),()=>{n.unobserve(t)}},M={passive:!0},B=typeof window>"u"?!0:"onscrollend"in window,H=(a,d,t)=>{const e=a.scrollElement;if(!e)return;const s=a.targetWindow;if(!s)return;const n=a.options.useScrollendEvent&&B;let o=0;const i=n?null:V(s,()=>d(o,!1),a.options.isScrollingResetDelay),l=f=>()=>{o=t(e),i?.(),d(o,f)},h=l(!0),c=l(!1);return e.addEventListener("scroll",h,M),n&&e.addEventListener("scrollend",c,M),()=>{e.removeEventListener("scroll",h),n&&e.removeEventListener("scrollend",c)}},$=(a,d)=>H(a,d,t=>{const{horizontal:e,isRtl:s}=a.options;return e?t.scrollLeft*(s&&-1||1):t.scrollTop}),J=(a,d,t)=>{if(t.options.useCachedMeasurements){const e=t.indexFromElement(a),s=t.options.getItemKey(e);return t.itemSizeCache.get(s)??t.options.estimateSize(e)}if(d?.borderBoxSize){const e=d.borderBoxSize[0];if(e)return Math.round(e[t.options.horizontal?"inlineSize":"blockSize"])}if(!d){const e=t.indexFromElement(a),s=t.options.getItemKey(e),n=t.itemSizeCache.get(s);if(n!==void 0)return n}return a[t.options.horizontal?"offsetWidth":"offsetHeight"]},q=(a,{adjustments:d=0,behavior:t},e)=>{var s,n;(n=(s=e.scrollElement)==null?void 0:s.scrollTo)==null||n.call(s,{[e.options.horizontal?"left":"top"]:a+d,behavior:t})},U=q;class X{constructor(d){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var t,e,s;return((s=(e=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:e.now)==null?void 0:s.call(e))??Date.now()},this.observer=(()=>{let t=null;const e=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(s=>{s.forEach(n=>{const o=()=>{const i=n.target,l=this.indexFromElement(i);if(!i.isConnected){this.observer.unobserve(i);for(const[h,c]of this.elementsCache)if(c===i){this.elementsCache.delete(h);break}return}this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(i,n,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var s;(s=e())==null||s.disconnect(),t=null},observe:s=>{var n;return(n=e())==null?void 0:n.observe(s,{box:"border-box"})},unobserve:s=>{var n;return(n=e())==null?void 0:n.unobserve(s)}}})(),this.range=null,this.setOptions=t=>{var e,s;const n={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:K,rangeExtractor:P,onChange:()=>{},measureElement:J,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const r in t){const m=t[r];m!==void 0&&(n[r]=m)}const o=this.options;let i=null,l=null,h=!1;if(o!==void 0&&o.enabled&&n.enabled&&n.anchorTo==="end"&&this.scrollElement!==null){const r=o.count,m=n.count,u=this.getMeasurements(),p=r>0?((e=u[0])==null?void 0:e.key)??o.getItemKey(0):null,S=r>0?((s=u[r-1])==null?void 0:s.key)??o.getItemKey(r-1):null;if(m!==r||r>0&&m>0&&(n.getItemKey(0)!==p||n.getItemKey(m-1)!==S)){h=!0;const g=r>0?this.getVirtualItemForOffset(this.getScrollOffset())??u[0]:null;g&&(i=[g.key,this.getScrollOffset()-g.start]);const x=n.followOnAppend===!0?"auto":n.followOnAppend||null;x&&m>r&&this.isAtEnd(o.scrollEndThreshold)&&(r===0||n.getItemKey(m-1)!==S)&&(l=x)}}this.options=n,h&&(this.pendingMin=0,this.itemSizeCacheVersion++);let c=!1,f=0;if(i&&this.scrollOffset!==null){const[r,m]=i,u=this.getMeasurements(),{count:p,getItemKey:S}=this.options;let v=0;for(;v<p&&S(v)!==r;)v++;if(v<p){const E=u[v];if(E){const g=E.start+m;g!==this.scrollOffset&&(f=g-this.scrollOffset,this.scrollOffset=g,c=!0)}}}(c||l)&&(this.pendingScrollAnchor=[c?i[0]:null,c?i[1]:0,l,f])},this.notify=t=>{var e,s;(s=(e=this.options).onChange)==null||s.call(e,this,t)},this.maybeNotify=O(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(n=>{this.observer.observe(n)}),this.unsubs.push(this.options.observeElementRect(this,n=>{this.scrollRect=n,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(n,o)=>{this._intendedScrollOffset!==null&&Math.abs(n-this._intendedScrollOffset)<1.5&&(n=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<n?"forward":"backward":null,this.scrollOffset=n,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const n=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},i=()=>{this._iosTouching=!1,!(!C()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};n.addEventListener("touchstart",o,M),n.addEventListener("touchend",i,M),this.unsubs.push(()=>{n.removeEventListener("touchstart",o),n.removeEventListener("touchend",i),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){const[n,o,i,l]=s;n!==null&&!i&&(C()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?l!==0&&(this._iosDeferredAdjustment+=l):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),i&&this.scrollToEnd({behavior:i})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const t=this.getScrollOffset(),e=this.getMaxScrollOffset();if(t<0||t>e)return;const s=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=s,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(t,e)=>{const s=new Map,n=new Map;for(let o=e-1;o>=0;o--){const i=t[o];if(s.has(i.lane))continue;const l=n.get(i.lane);if(l==null||i.end>l.end?n.set(i.lane,i):i.end<l.end&&s.set(i.lane,!0),s.size===this.options.lanes)break}return n.size===this.options.lanes?Array.from(n.values()).sort((o,i)=>o.end===i.end?o.index-i.index:o.end-i.end)[0]:void 0},this.getMeasurementOptions=O(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(t,e,s,n,o,i,l)=>(this.prevLanes!==void 0&&this.prevLanes!==i&&(this.lanesChangedFlag=!0),this.prevLanes=i,this.pendingMin=null,{count:t,paddingStart:e,scrollMargin:s,getItemKey:n,enabled:o,lanes:i,laneAssignmentMode:l}),{key:!1}),this.getMeasurements=O(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:e,scrollMargin:s,getItemKey:n,enabled:o,lanes:i,laneAssignmentMode:l},h)=>{const c=this.itemSizeCache;if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const u of this.laneAssignments.keys())u>=t&&this.laneAssignments.delete(u);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const f=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),i===1){const u=this.options.gap,p=t*2;let S=this._flatMeasurements;if(!S||S.length<p){const g=new Float64Array(p);S&&f>0&&g.set(S.subarray(0,f*2)),S=g,this._flatMeasurements=S}let v;if(f===0)v=e+s;else{const g=f-1;v=S[g*2]+S[g*2+1]+u}for(let g=f;g<t;g++){const x=n(g),I=c.get(x),w=typeof I=="number"?I:this.options.estimateSize(g);S[g*2]=v,S[g*2+1]=w,v+=w+u}const E=D(t,S,n);return this.measurementsCache=E,E}const r=this.measurementsCache.slice(0,f),m=new Array(i).fill(void 0);for(let u=0;u<f;u++){const p=r[u];p&&(m[p.lane]=u)}for(let u=f;u<t;u++){const p=n(u),S=this.laneAssignments.get(u);let v,E;const g=l==="estimate"||c.has(p);if(S!==void 0&&this.options.lanes>1){v=S;const z=m[v],R=z!==void 0?r[z]:void 0;E=R?R.end+this.options.gap:e+s}else{const z=this.options.lanes===1?r[u-1]:this.getFurthestMeasurement(r,u);E=z?z.end+this.options.gap:e+s,v=z?z.lane:u%this.options.lanes,this.options.lanes>1&&g&&this.laneAssignments.set(u,v)}const x=c.get(p),I=typeof x=="number"?x:this.options.estimateSize(u),w=E+I;r[u]={index:u,start:E,size:I,end:w,key:p,lane:v},m[v]=u}return this.measurementsCache=r,r},{key:!1,debug:()=>this.options.debug}),this.calculateRange=O(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,e,s,n)=>this.range=t.length>0&&e>0?G({measurements:t,outerSize:e,scrollOffset:s,lanes:n,flat:n===1&&this._flatMeasurements!=null?this._flatMeasurements:null}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=O(()=>{let t=null,e=null;const s=this.calculateRange();return s&&(t=s.startIndex,e=s.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,e]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,e]},(t,e,s,n,o)=>n===null||o===null?[]:t({startIndex:n,endIndex:o,overscan:e,count:s}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const e=this.options.indexAttribute,s=t.getAttribute(e);return s?parseInt(s,10):(console.warn(`Missing attribute name '${e}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var e;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const s=this.scrollState.index??((e=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:e.index);if(s!==void 0&&this.range){const n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,s-n),i=Math.min(this.options.count-1,s+n);return t>=o&&t<=i}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((o,i)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(i))});return}const e=this.indexFromElement(t),s=this.options.getItemKey(e),n=this.elementsCache.get(s);n!==t&&(n&&this.observer.unobserve(n),this.observer.observe(t),this.elementsCache.set(s,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(e)&&this.resizeItem(e,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,e)=>{var s,n;if(t<0||t>=this.options.count)return;let o,i,l;const h=this._flatMeasurements;if(this.options.lanes===1&&h!==null)l=this.options.getItemKey(t),i=h[t*2],o=h[t*2+1];else{const r=this.measurementsCache[t];if(!r)return;l=r.key,i=r.start,o=r.size}const c=this.itemSizeCache.get(l)??o,f=e-c;if(f!==0){const r=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,m=r?this.getTotalSize():0,u=((n=this.scrollState)==null?void 0:n.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:l,start:i,size:o,end:i+o,lane:0},f,this):i<this.getScrollOffset()+this.scrollAdjustments&&this.scrollDirection!=="backward");(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(l,e),this.itemSizeCacheVersion++,r?this.applyScrollAdjustment(this.getTotalSize()-m):u&&this.applyScrollAdjustment(f),this.notify(!1)}},this.getVirtualItems=O(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,e)=>{const s=[];for(let n=0,o=t.length;n<o;n++){const i=t[n],l=e[i];s.push(l)}return s},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const e=this.getMeasurements();if(e.length===0)return;const s=this._flatMeasurements,n=this.options.lanes===1&&s!=null,o=W(0,e.length-1,n?i=>s[i*2]:i=>F(e[i]).start,t);return F(e[o])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,e,s=0)=>{if(!this.scrollElement)return 0;const n=this.getSize(),o=this.getScrollOffset();e==="auto"&&(e=t>=o+n?"end":"start"),e==="center"?t+=(s-n)/2:e==="end"&&(t-=n);const i=this.getMaxScrollOffset();return Math.max(Math.min(i,t),0)},this.getOffsetForIndex=(t,e="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const s=this.getSize(),n=this.getScrollOffset(),o=this.measurementsCache[t];if(!o)return;if(e==="auto")if(o.end>=n+s-this.options.scrollPaddingEnd)e="end";else if(o.start<=n+this.options.scrollPaddingStart)e="start";else return[n,e];if(e==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),e];const i=e==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(i,e,o.size),e]},this.scrollToOffset=(t,{align:e="start",behavior:s="auto"}={})=>{const n=this.getOffsetForAlignment(t,e),o=this.now();this.scrollState={index:null,align:e,behavior:s,startedAt:o,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:e="auto",behavior:s="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const n=this.getOffsetForIndex(t,e);if(!n)return;const[o,i]=n,l=this.now();this.scrollState={index:t,align:i,behavior:s,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:e="auto"}={})=>{const s=this.getScrollOffset()+t,n=this.now();this.scrollState={index:null,align:"start",behavior:e,startedAt:n,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:e}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t;const e=this.getMeasurements();let s;if(e.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){const n=e.length-1,o=this._flatMeasurements;o!=null?s=o[n*2]+o[n*2+1]:s=((t=e[n])==null?void 0:t.end)??0}else{const n=Array(this.options.lanes).fill(null);let o=e.length-1;for(;o>=0&&n.some(i=>i===null);){const i=e[o];n[i.lane]===null&&(n[i.lane]=i.end),o--}s=Math.max(...n.filter(i=>i!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const t=[];if(this.itemSizeCache.size===0)return t;const e=this.getMeasurements();for(const s of e)s&&this.itemSizeCache.has(s.key)&&t.push({index:s.index,key:s.key,start:s.start,size:s.size,end:s.end,lane:s.lane});return t},this._scrollToOffset=(t,{adjustments:e,behavior:s})=>{this._intendedScrollOffset=t+(e??0),this.options.scrollToFn(t,{behavior:s,adjustments:e},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(d)}applyScrollAdjustment(d,t){d!==0&&(C()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=d:this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=d,behavior:t}))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const e=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,s=e?e[0]:this.scrollState.lastTargetOffset,n=1,o=s!==this.scrollState.lastTargetOffset;if(!o&&L(s,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=n){this.getScrollOffset()!==s&&this._scrollToOffset(s,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){const i=this.getSize()||600,l=Math.abs(s-this.getScrollOffset()),h=this.scrollState.behavior==="smooth"&&l>i;this.scrollState.lastTargetOffset=s,h||(this.scrollState.behavior="auto"),this._scrollToOffset(s,{adjustments:void 0,behavior:h?"smooth":"auto"})}this.scheduleScrollReconcile()}}const W=(a,d,t,e)=>{for(;a<=d;){const s=(a+d)/2|0,n=t(s);if(n<e)a=s+1;else if(n>e)d=s-1;else return s}return a>0?a-1:0};function G({measurements:a,outerSize:d,scrollOffset:t,lanes:e,flat:s}){const n=a.length-1,o=s?c=>s[c*2]:c=>a[c].start,i=s?c=>s[c*2]+s[c*2+1]:c=>a[c].end;if(a.length<=e)return{startIndex:0,endIndex:n};let l=W(0,n,o,t),h=l;if(e===1)for(;h<n&&i(h)<t+d;)h++;else if(e>1){const c=Array(e).fill(0);for(;h<n&&c.some(r=>r<t+d);){const r=a[h];c[r.lane]=r.end,h++}const f=Array(e).fill(t+d);for(;l>=0&&f.some(r=>r>=t);){const r=a[l];f[r.lane]=r.start,l--}l=Math.max(0,l-l%e),h=Math.min(n,h+(e-1-h%e))}return{startIndex:l,endIndex:h}}const A=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Q({useFlushSync:a=!0,directDomUpdates:d=!1,directDomUpdatesMode:t="transform",...e}){const s=b.useReducer(h=>h+1,0)[1],n=b.useRef({enabled:d,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});n.current.enabled=d,n.current.mode=t;const o=h=>{const c=n.current;if(!c.enabled)return;const f=h.getTotalSize();if(c.container&&f!==c.lastSize){c.lastSize=f;const v=h.options.horizontal?"width":"height";c.container.style[v]=`${f}px`}const r=!!h.options.horizontal,m=c.mode==="transform",u=r?"left":"top",p=h.options.scrollMargin,S=h.getVirtualItems();for(const v of S){const E=v.start-p,g=h.elementsCache.get(v.key);g&&c.lastPositions.get(g)!==E&&(c.lastPositions.set(g,E),m?g.style.transform=r?`translate3d(${E}px, 0, 0)`:`translate3d(0, ${E}px, 0)`:g.style[u]=`${E}px`)}},i={...e,onChange:(h,c)=>{var f;const r=n.current;let m=!0;if(r.enabled){o(h);const u=h.range,p=r.prevRange;m=!p||p.isScrolling!==h.isScrolling||p.startIndex!==u?.startIndex||p.endIndex!==u?.endIndex,m&&(r.prevRange=u?{startIndex:u.startIndex,endIndex:u.endIndex,isScrolling:h.isScrolling}:null)}m&&(a&&c?j.flushSync(s):s()),(f=e.onChange)==null||f.call(e,h,c)}},[l]=b.useState(()=>{const h=new X(i);return Object.assign(h,{containerRef:c=>{const f=n.current;if(f.container=c,f.lastSize=null,c&&f.enabled){const r=h.getTotalSize();f.lastSize=r;const m=h.options.horizontal?"width":"height";c.style[m]=`${r}px`}}})});return l.setOptions(i),A(()=>l._didMount(),[]),A(()=>l._willUpdate()),A(()=>{o(l)}),l}function Y(a){return Q({observeElementRect:N,observeElementOffset:$,scrollToFn:U,...a})}const Z=20;function et({rows:a,renderRow:d,className:t,scrollToLine:e,scrollNonce:s,scrollAlign:n="center",onTopRow:o,fitWidth:i=!1,dynamicHeight:l=!1}){const h=b.useRef(null),c=Y({count:a.length,getScrollElement:()=>h.current,estimateSize:()=>Z,overscan:30}),f=b.useRef(c);return b.useEffect(()=>{f.current=c}),b.useEffect(()=>{e!==void 0&&e>=1&&f.current.scrollToIndex(e-1,{align:n})},[e,s,n]),b.useEffect(()=>{const r=h.current;if(!r||!o)return;let m=-1;const u=()=>{const p=f.current.getVirtualItems().find(S=>S.end>r.scrollTop);p&&p.index!==m&&(m=p.index,o(p.index))};return u(),r.addEventListener("scroll",u,{passive:!0}),()=>r.removeEventListener("scroll",u)},[o]),b.useEffect(()=>{const r=h.current;if(!r||!l)return;const m=()=>r.style.setProperty("--vrows-vw",`${r.clientWidth}px`);m();const u=new ResizeObserver(m);return u.observe(r),()=>u.disconnect()},[l]),_.jsx("div",{ref:h,className:T("h-full overflow-auto font-mono text-xs",t),children:_.jsx("div",{className:T("relative",i?"w-full":"w-max min-w-full"),style:{height:c.getTotalSize()},children:c.getVirtualItems().map(r=>{const m=a[r.index];return m===void 0?null:_.jsx("div",{"data-index":r.index,ref:l?c.measureElement:void 0,className:T("absolute left-0",i?"w-full":"w-max min-w-full"),style:l?{top:r.start}:{top:r.start,height:r.size},children:d(m,r.index)},r.key)})})})}export{Z as R,et as V};
|
package/renderer/index.html
CHANGED
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
http-equiv="Content-Security-Policy"
|
|
32
32
|
content="default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self' http://127.0.0.1:* ws://127.0.0.1:* http: https: ws: wss:; frame-src 'self' http: https:"
|
|
33
33
|
/>
|
|
34
|
-
<script type="module" crossorigin src="./assets/index-
|
|
35
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
34
|
+
<script type="module" crossorigin src="./assets/index-CuWbxCsX.js"></script>
|
|
35
|
+
<link rel="stylesheet" crossorigin href="./assets/index-CS0Dcjbz.css">
|
|
36
36
|
</head>
|
|
37
37
|
|
|
38
38
|
<body>
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{$ as Re,r as o,a1 as ue,ad as xe,ae as me,af as Pe,ag as fe,b as te,ah as ne,j as e,C as he,q as pe,a6 as je,n as F,ai as Ae,T as J,aj as Q,ak as H,s as ge,t as j,al as _,am as B,an as Z,ao as ve,ap as ze,aq as re,M as E,ar as ee,as as Ce,at as we,au as ke,x as oe,a8 as be,c as se,av as Ie,aw as q,ax as He,B as D,ab as De,_ as Oe,ay as Ke,a7 as Ve,u as R,g as _e,az as Be,aA as qe,v as Ue,k as Ge,l as We,o as $e,w as Xe,P as ye,Q as U,aB as Qe,aC as Ye}from"./index-BG75F5tP.js";import{i as Je,a as Ze,M as es,H as ss}from"./html-view-CDZotjAw.js";import{b as ts,l as ns,c as rs}from"./line-selection-CDQurM1g.js";import{R as os,V as as}from"./virtual-rows-BdkQ29uq.js";const is=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],ls=Re("scissors",is);function Se(t,r){return!r||r.length===0?!1:r.some(n=>t>=n.start&&t<=n.end)}const cs=5e3,ds=800,Y="pointer-events-none absolute bottom-2 right-3 rounded-md border-transparent bg-muted/80 text-2xs",us=o.memo(be),xs=8;function ms({path:t,initialContent:r,highlightLine:n,highlightRanges:i,commentsByLine:a}){const[d,p]=o.useState(r),[g,x]=o.useState(r),[u,C]=o.useState(""),[c,w]=o.useState(!1),[m,k]=o.useState(null),[f,N]=o.useState(null),b=o.useRef(null),L=o.useRef(null),S=o.useRef(null),T=ue(t),M=o.useDeferredValue(d),P=xe(M,T),{findReferences:O,copyPath:K,copyRelativePath:V,reveal:G}=me(t),{save:A,isSaving:W,error:z}=Pe(t),v=fe(),y=te()??void 0,ae=ne(y,t),Ne=o.useMemo(()=>{if(!m||m.startLine===void 0)return null;const s=new Set,l=m.endLine??m.startLine;for(let h=m.startLine;h<=l;h++)s.add(h);return s},[m]),Le=o.useMemo(()=>{if(!c||u===""||!f)return null;const s=new Set;for(let l=f.startLine;l<=f.endLine;l++)s.add(l);return s},[c,u,f]),$=o.useEffectEvent(()=>{if(S.current&&clearTimeout(S.current),d===g)return;const s=d;A(s,()=>x(s))}),ie=s=>{p(s);const l=se.getState().panes.flatMap(h=>h.tabs).find(h=>h.kind==="file"&&h.path===t);se.getState().pinTab(l?.id??Ie("file",t)),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>$(),ds)};o.useEffect(()=>()=>{S.current&&clearTimeout(S.current),$()},[]);const le=o.useRef(r);o.useEffect(()=>{r!==le.current&&d===g&&(le.current=r,p(r),x(r))},[r,d,g]),o.useEffect(()=>{const s=L.current;!s||n===void 0||(s.scrollTop=Math.max(0,(n-1)*20-s.clientHeight/2+10))},[n]);const ce=s=>{const l=b.current;if(!l)return;const{selectionStart:h,selectionEnd:X,value:I}=l;ie(I.slice(0,h)+s+I.slice(X)),requestAnimationFrame(()=>{l.focus(),l.selectionStart=l.selectionEnd=h+s.length})},Me=()=>{const s=b.current;return s?s.value.slice(s.selectionStart,s.selectionEnd):""},Te=()=>{navigator.clipboard?.readText&&B(async()=>{ce(await navigator.clipboard.readText())},s=>{q("Paste",s)})},Ee=d!==g;return e.jsxs(e.Fragment,{children:[e.jsxs(he,{onOpenChange:s=>{if(w(s),s){C(Me());const l=b.current;N(l?ts(l.value,l.selectionStart,l.selectionEnd):null)}},children:[e.jsxs(pe,{className:"relative block h-full select-text overflow-hidden",children:[e.jsx("div",{ref:L,className:"h-full overflow-auto",children:e.jsxs("div",{className:"relative min-h-full w-max min-w-full",children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-0 px-4 py-2 font-mono text-xs leading-5",children:e.jsx("div",{className:"w-max min-w-full",children:d.split(`
|
|
2
|
-
`).map((s,l)=>{const h=l+1,X=(Ne?.has(h)??!1)||(Le?.has(h)??!1),I=je(a?.get(h),X)??(h===n?"bg-primary/15":void 0),Fe=!I&&Se(h,i);return e.jsxs("div",{className:F("flex",I,Fe&&"border-l-2 border-l-diff-add bg-diff-add/10"),children:[e.jsx("span",{className:"w-10 shrink-0 select-none pr-3 text-right text-muted-foreground/50",children:h}),e.jsx(us,{tokens:P?.[l]??null,text:s})]},l)})})}),a&&a.size>0&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-20 font-mono text-xs leading-5",children:[...a.entries()].map(([s,l])=>e.jsx("div",{className:"pointer-events-auto absolute left-1 flex h-5 items-center",style:{top:xs+(s-1)*os},children:e.jsx(Ae,{comments:l})},s))}),e.jsx("textarea",{ref:b,value:d,onChange:s=>ie(s.target.value),onKeyDown:s=>{s.key==="s"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),$())},spellCheck:!1,wrap:"off","aria-label":`Edit ${t}`,"data-testid":J.fileEditor,className:"relative z-10 block min-h-full min-w-full resize-none whitespace-pre bg-transparent py-2 pl-14 pr-4 font-mono text-xs leading-5 text-transparent caret-foreground outline-none field-sizing-content"})]})}),z?e.jsx(Q,{variant:"outline",className:F(Y,"text-destructive"),children:z.message}):W?e.jsx(Q,{variant:"outline",className:F(Y,"text-muted-foreground"),children:"Saving…"}):Ee?e.jsxs(Q,{variant:"outline",className:F(Y,"text-muted-foreground"),children:["Unsaved ",e.jsx(H,{className:"[@media(hover:none)]:hidden",tokens:["mod","S"]})]}):null]}),e.jsxs(ge,{className:"w-60",children:[e.jsxs(j,{disabled:u==="",onClick:()=>{B(async()=>{await Z(u),ce("")},s=>{q("Cut",s)})},children:[e.jsx(ls,{})," Cut",e.jsx(_,{children:e.jsx(H,{tokens:["mod","X"]})})]}),e.jsxs(j,{disabled:u==="",onClick:()=>{B(()=>Z(u),s=>{q("Copy",s)})},children:[e.jsx(ve,{})," Copy",e.jsx(_,{children:e.jsx(H,{tokens:["mod","C"]})})]}),e.jsxs(j,{onClick:()=>Te(),children:[e.jsx(ze,{})," Paste",e.jsx(_,{children:e.jsx(H,{tokens:["mod","V"]})})]}),e.jsxs(j,{disabled:u.trim()==="",onClick:()=>O(u),children:[e.jsx(re,{})," Find references"]}),e.jsxs(j,{disabled:u==="",onClick:()=>{f&&k({path:ae,startLine:f.startLine,endLine:f.endLine,anchorText:u.slice(0,2e3)})},children:[e.jsx(E,{})," Add comment"]}),e.jsx(ee,{}),e.jsxs(j,{onClick:()=>k({path:ae}),children:[e.jsx(E,{})," Comment on file"]}),e.jsxs(j,{onClick:()=>{K()},children:[e.jsx(Ce,{})," Copy path"]}),e.jsxs(j,{onClick:()=>{V()},children:[e.jsx(we,{})," Copy relative path"]}),v&&e.jsxs(j,{onClick:()=>{G()},children:[e.jsx(ke,{})," Reveal in Finder"]})]})]}),e.jsx(oe,{anchor:m,open:m!==null,onOpenChange:s=>{s||k(null)}})]})}function fs({content:t,onClose:r,onMatchLine:n}){const[i,a]=o.useState(""),[d,p]=o.useState(0),g=o.useRef(null),x=o.useMemo(()=>{const c=i.toLowerCase();if(c==="")return[];const w=[];return t.split(`
|
|
3
|
-
`).forEach((m,k)=>{m.toLowerCase().includes(c)&&w.push(k+1)}),w},[t,i]),u=x.length===0?0:(d%x.length+x.length)%x.length,C=x.length===0?void 0:x[u];return o.useEffect(()=>{n(C)},[C,n]),o.useEffect(()=>{g.current?.focus()},[]),e.jsxs("div",{className:"absolute right-3 top-3 z-30 flex items-center gap-1 rounded-lg border bg-popover px-2 py-1 shadow-lg",children:[e.jsx(re,{className:"size-3.5 shrink-0 text-muted-foreground"}),e.jsx(He,{ref:g,value:i,onChange:c=>{a(c.target.value),p(0)},onKeyDown:c=>{c.key==="Escape"&&r(),c.key==="Enter"&&p(w=>w+(c.shiftKey?-1:1))},placeholder:"Find in file…","aria-label":"Find in file",className:"h-6 max-w-64 border-none bg-transparent text-xs shadow-none focus-visible:ring-0"}),e.jsx("span",{className:"shrink-0 text-2xs text-muted-foreground tabular-nums",children:i===""?"":x.length===0?"No results":`${u+1}/${x.length}`}),e.jsx(D,{variant:"ghost",size:"icon-xs",disabled:x.length===0,onClick:()=>p(c=>c-1),"aria-label":"Previous match",children:e.jsx(De,{})}),e.jsx(D,{variant:"ghost",size:"icon-xs",disabled:x.length===0,onClick:()=>p(c=>c+1),"aria-label":"Next match",children:e.jsx(Oe,{})}),e.jsx(D,{variant:"ghost",size:"icon-xs",onClick:r,"aria-label":"Close find bar",children:e.jsx(Ke,{})})]})}function de({path:t,children:r}){const[n,i]=o.useState(""),[a,d]=o.useState(null),[p,g]=o.useState(null),x=te()??void 0,{copyPath:u,copyRelativePath:C,reveal:c,findReferences:w}=me(t),m=fe(),k=ne(x,t);return e.jsxs(e.Fragment,{children:[e.jsxs(he,{onOpenChange:f=>{if(!f){d(null);return}i(window.getSelection()?.toString()??"")},children:[e.jsx(pe,{className:"block h-full select-text",onContextMenu:f=>{const N=ns();if(N){d(N);return}const b=f.target.closest("[data-line]"),L=b?Number.parseInt(b.getAttribute("data-line")??"",10):Number.NaN;d(Number.isFinite(L)?{startLine:L,endLine:L,text:""}:null)},children:r}),e.jsx(ge,{className:"w-56",children:n!==""?e.jsxs(e.Fragment,{children:[e.jsxs(j,{onClick:()=>{B(()=>Z(n),f=>{q("Copy",f)})},children:[e.jsx(ve,{})," Copy",e.jsx(_,{children:e.jsx(H,{tokens:["mod","C"]})})]}),e.jsxs(j,{disabled:n.trim()==="",onClick:()=>w(n),children:[e.jsx(re,{})," Find references"]}),a&&e.jsxs(j,{onClick:()=>g({path:k,startLine:a.startLine,endLine:a.endLine,anchorText:a.text.slice(0,2e3)}),children:[e.jsx(E,{})," Add comment"]})]}):e.jsxs(e.Fragment,{children:[a?e.jsxs(j,{onClick:()=>g({path:k,startLine:a.startLine,endLine:a.endLine}),children:[e.jsx(E,{})," Add comment"]}):e.jsxs(j,{onClick:()=>g({path:k}),children:[e.jsx(E,{})," Comment on file"]}),e.jsx(ee,{}),e.jsxs(j,{onClick:()=>{u()},children:[e.jsx(Ce,{})," Copy path"]}),e.jsxs(j,{onClick:()=>{C()},children:[e.jsx(we,{})," Copy relative path"]}),m&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{}),e.jsxs(j,{onClick:()=>{c()},children:[e.jsx(ke,{})," Reveal in Finder"]})]})]})})]}),e.jsx(oe,{anchor:p,open:p!==null,onOpenChange:f=>{f||g(null)}})]})}function hs({path:t,content:r,highlightLine:n,highlightRanges:i,commentsByLine:a}){const d=ue(t),p=r.split(`
|
|
4
|
-
`),g=xe(r,d);return e.jsx(as,{rows:p,className:"px-4 py-2 leading-5",scrollToLine:n,renderRow:(x,u)=>{const C=u+1,c=a?.get(C),w=je(c),m=!w&&Se(C,i);return e.jsxs("div",{"data-line":C,className:F("relative flex",!w&&C===n&&"bg-primary/15",w,m&&"border-l-2 border-l-diff-add bg-diff-add/10"),children:[e.jsx(Ve,{comments:c}),e.jsx("span",{className:"w-10 shrink-0 select-none pr-3 text-right text-muted-foreground/50",children:C}),e.jsx(be,{tokens:g?.[u]??null,text:x})]})}})}function ps(){const t=R(n=>n.markdownMode),r=R(n=>n.setMarkdownMode);return e.jsxs(ye,{value:[t],onValueChange:n=>{const i=n[0];(i==="reader"||i==="source")&&r(i)},children:[e.jsx(U,{value:"reader",size:"sm",children:"Reader"}),e.jsx(U,{value:"source",size:"sm",children:"Source"})]})}function js(){const t=R(n=>n.htmlMode)??"preview",r=R(n=>n.setHtmlMode);return e.jsxs(ye,{value:[t],onValueChange:n=>{const i=n[0];(i==="preview"||i==="source")&&r(i)},children:[e.jsx(U,{value:"preview",size:"sm",children:"Preview"}),e.jsx(U,{value:"source",size:"sm",children:"Source"})]})}function gs({path:t,content:r,line:n,highlightRanges:i,paneIndex:a}){const d=te()??void 0,p=R(v=>v.markdownMode),g=R(v=>v.htmlMode)??"preview",[x,u]=o.useState(!1),[C,c]=o.useState(void 0),[w,m]=o.useState(null),[k,f]=o.useState(null),N=ne(d,t),b=_e(N),L=Je(t),S=Ze(t),T=L&&p==="reader",M=S&&g==="preview",{html:P,error:O}=Be(t,M),K=qe(t,M&&P!==null),V=r.split(`
|
|
5
|
-
`).length,G=!T&&!M&&V<=cs,A=i&&i.reduce((v,y)=>v+(y.end-y.start+1),0)/V>=.9?void 0:i,W=n??A?.[0]?.start,z=x&&C!==void 0?C:W;return o.useEffect(()=>{const v=y=>{if(se.getState().activePaneIndex===a&&y.key==="f"&&(y.metaKey||y.ctrlKey)&&!y.shiftKey&&!y.altKey){if(T||M)return;y.preventDefault(),u(!0)}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[a,T,M]),e.jsxs("div",{"data-testid":J.codeWell,className:Ue,children:[e.jsxs("div",{"data-testid":J.codeCard,className:F(Xe,"flex h-full min-h-0 flex-col"),children:[e.jsxs("div",{className:"flex h-9 shrink-0 items-center justify-between gap-2 border-b px-3",children:[e.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:N}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Ge,{children:[e.jsx(We,{render:e.jsx(D,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>m({path:N}),"aria-label":"Comment on file",children:e.jsx(E,{})})}),e.jsx($e,{children:"Comment on file"})]}),L&&e.jsx(ps,{}),S&&e.jsx(js,{})]})]}),e.jsxs("div",{className:"relative min-h-0 flex-1",children:[x&&!T&&!M&&e.jsx(fs,{content:r,onClose:()=>u(!1),onMatchLine:c}),T?e.jsx(de,{path:t,children:e.jsx(es,{content:r,commentsByLine:b.byLine})}):M?O?e.jsx("p",{className:"p-4 text-sm text-destructive",children:O.message}):P===void 0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"}):P===null?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"HTML preview unavailable (missing or too large). Switch to Source to edit the raw file."}):K===null?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"}):e.jsxs("div",{className:"relative h-full",children:[e.jsx(ss,{src:K,title:t.split("/").at(-1)??"HTML preview",onSelection:f}),k!==null&&e.jsx("div",{className:"absolute bottom-4 left-1/2 z-20 -translate-x-1/2 rounded-lg border bg-popover p-1 shadow-lg",children:e.jsxs(D,{size:"sm",onClick:()=>{const v=rs(r,k);m({path:N,anchorText:k,...v?{startLine:v.startLine,endLine:v.endLine}:{}}),f(null)},children:[e.jsx(E,{})," Add comment"]})})]}):G?e.jsx(ms,{path:t,initialContent:r,highlightLine:z,highlightRanges:A,commentsByLine:b.byLine}):e.jsx(de,{path:t,children:e.jsx(hs,{path:t,content:r,highlightLine:z,highlightRanges:A,commentsByLine:b.byLine})})]})]}),e.jsx(oe,{anchor:w,open:w!==null,onOpenChange:v=>{v||m(null)}})]})}function bs({path:t,line:r,highlight:n,paneIndex:i}){const{view:a,error:d}=Qe(t),p=Ye();return o.useEffect(()=>{a?.type==="not-found"&&p()},[a,p]),d?e.jsx("p",{className:"p-4 text-sm text-destructive",children:d.message}):a===void 0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"}):a.type==="not-found"?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"This file no longer exists."}):a.type==="image"?e.jsx("div",{className:"flex h-full items-center justify-center p-8",children:e.jsx("img",{src:a.dataUrl,alt:t,className:"max-h-full max-w-full object-contain"})}):a.type==="binary"?e.jsxs("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:["Binary file · ",(a.size/1024).toFixed(1)," KB"]}):a.type==="too-large"?e.jsxs("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:["File too large to preview · ",(a.size/(1024*1024)).toFixed(1)," MB"]}):e.jsx(gs,{path:t,content:a.content,line:r,highlightRanges:n,paneIndex:i})}export{bs as FileContent};
|