vibelet 1.2.229 → 1.2.230
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/dist/index.cjs +1 -1
- package/dist/inventory-scan-worker.cjs +1 -1
- package/dist/remoteDirect/vibelet-remote-direct-darwin-amd64 +0 -0
- package/dist/remoteDirect/vibelet-remote-direct-darwin-arm64 +0 -0
- package/dist/remoteDirect/vibelet-remote-direct-linux-amd64 +0 -0
- package/dist/remoteDirect/vibelet-remote-direct-linux-arm64 +0 -0
- package/dist/remoteDirect/vibelet-remote-direct-win32-amd64.exe +0 -0
- package/dist/remoteDirect/vibelet-remote-direct-win32-arm64.exe +0 -0
- package/dist/runtime-version.cjs +1 -1
- package/dist/web/assets/App-94_jdzMk.css +1 -0
- package/dist/web/assets/App-CapuoJH2.js +18 -0
- package/dist/web/assets/{BrowserControlPanel-Cxs5WG6_.js → BrowserControlPanel-BTBKDi0n.js} +1 -1
- package/dist/web/assets/{ChipGroup-BVP2S5VF.js → ChipGroup-ImS6VTKx.js} +1 -1
- package/dist/web/assets/{DiffDrawer-BWx4QFFg.js → DiffDrawer-sMBIj4bW.js} +1 -1
- package/dist/web/assets/{FilesControlPanel-CmG4pm47.js → FilesControlPanel-4hHS85Mr.js} +1 -1
- package/dist/web/assets/GlobalPendingDialog-BCLMQc_r.js +1 -0
- package/dist/web/assets/{ImageViewer-Cu953aPv.js → ImageViewer-BvBKQ6wE.js} +1 -1
- package/dist/web/assets/{LanguageSettingsPanel-BQcBduA3.js → LanguageSettingsPanel-DTDvB4l2.js} +1 -1
- package/dist/web/assets/{NewSessionDialog-tL5HWBLl.js → NewSessionDialog-LttGZHY7.js} +1 -1
- package/dist/web/assets/{NotificationSettingsPanel-CAR-3hg5.js → NotificationSettingsPanel-BS01O3sC.js} +1 -1
- package/dist/web/assets/{TerminalControlPanel-BeAaO_xN.js → TerminalControlPanel-B7S_ebVy.js} +1 -1
- package/dist/web/assets/{ThemeSettingsPanel-CehjZMem.js → ThemeSettingsPanel-DVaJ6nGu.js} +1 -1
- package/dist/web/assets/{arrow-right-DfOPiOAm.js → arrow-right-ORILUMdJ.js} +1 -1
- package/dist/web/assets/{collectMessageImages-D5nmo9r7.js → collectMessageImages-lfAaZW_Y.js} +1 -1
- package/dist/web/assets/{file-editor-FileCodeEditor-DnxVv451.js → file-editor-FileCodeEditor-ZAqN9Q2f.js} +3 -3
- package/dist/web/assets/{file-editor-MarkdownLivePreview-DUOOwTFo.js → file-editor-MarkdownLivePreview-DXTFwUnj.js} +1 -1
- package/dist/web/assets/{file-editor-index-B9HLkvhU.js → file-editor-index-BBHGMD89.js} +1 -1
- package/dist/web/assets/{file-editor-index-BWFONDrO.js → file-editor-index-BC0Bqs8t.js} +1 -1
- package/dist/web/assets/{file-editor-index-CSZztQo5.js → file-editor-index-Bo2dEHVF.js} +1 -1
- package/dist/web/assets/{file-editor-index-PzETHMIH.js → file-editor-index-Byun61j6.js} +1 -1
- package/dist/web/assets/{file-editor-index-hO37u8iH.js → file-editor-index-C4S-qKVH.js} +1 -1
- package/dist/web/assets/{file-editor-index-6CjSO29S.js → file-editor-index-DKQvp2Qx.js} +1 -1
- package/dist/web/assets/{file-editor-index-ByUvpdPB.js → file-editor-index-Dc2gxJQY.js} +1 -1
- package/dist/web/assets/{file-editor-index-sNXn6Dlj.js → file-editor-index-Dj3dV82Z.js} +1 -1
- package/dist/web/assets/{folder-plus-ByEha8BZ.js → folder-plus-DHw5YJHP.js} +1 -1
- package/dist/web/assets/{highlighted-body-TPN3WLV5-DBlbFIPA.js → highlighted-body-TPN3WLV5-DDb5MlJt.js} +1 -1
- package/dist/web/assets/{index-CTHbgfqq.css → index-Be6TVbvo.css} +1 -1
- package/dist/web/assets/index-ConcKf33.js +71 -0
- package/dist/web/assets/{mermaid-O7DHMXV3-DkoqfAOM.js → mermaid-O7DHMXV3-D-5FgaAx.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/App-BPS30HWl.css +0 -1
- package/dist/web/assets/App-DcLmCQZc.js +0 -12
- package/dist/web/assets/GlobalPendingDialog-DpTYtgOQ.js +0 -1
- package/dist/web/assets/index-BH_ibxBN.js +0 -71
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as y,r as u,k as g,j as s,E}from"./index-
|
|
1
|
+
import{c as y,r as u,k as g,j as s,E}from"./index-ConcKf33.js";import{a as N,A as R}from"./arrow-right-ORILUMdJ.js";import{X as A,G as x}from"./App-CapuoJH2.js";const B=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],L=y("rotate-cw",B);function C(r){const o=r.trim();if(!o)return null;let a=o;if(/^[a-z][a-z\d+.-]*:/i.test(o)&&!/^[^:/\s]+:\d+(?:[/?#]|$)/.test(o)){if(!/^https?:\/\//i.test(o))return null}else/^(localhost|127\.0\.0\.1|\[::1\])(?::\d+)?(?:[/?#]|$)/i.test(o)?a=`http://${o}`:!/\s/.test(o)&&/^[^/]+\.[^/]+/.test(o)?a=`https://${o}`:a=`https://www.google.com/search?q=${encodeURIComponent(o)}`;try{const l=new URL(a);return/^https?:$/.test(l.protocol)&&!l.username&&!l.password?l.href:null}catch{return null}}const G=(r,o)=>{const a=document.createElement("iframe");a.className="browser-page",a.title=r.getAttribute("aria-label")||"Browser",a.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-downloads"),a.referrerPolicy="no-referrer",r.append(a);const l=[];let t=-1,c=!1;const w=()=>o({url:l[t]||"",title:"",loading:c,canGoBack:t>0,canGoForward:t<l.length-1}),d=()=>{c=!0,a.src=l[t],w()};return a.addEventListener("load",()=>{c=!1,w()}),{navigate:e=>{l.splice(t+1),l.push(e),t++,d()},back:()=>{t>0&&(t--,d())},forward:()=>{t<l.length-1&&(t++,d())},reload:()=>{t>=0&&d()},stop:()=>{c=!1;try{a.contentWindow?.stop()}catch{}w()},destroy:()=>a.remove()}},F={url:"",title:"",loading:!1,canGoBack:!1,canGoForward:!1};function P({t:r,onTitleChange:o,dockActions:a}){const l=u.useRef(null),t=u.useRef(null),c=u.useRef(null),[w,d]=u.useState(""),[e,j]=u.useState(F),[h,b]=u.useState(!1);u.useEffect(()=>{e.url&&o?.(e.title||new URL(e.url).hostname)},[e.title,e.url,r.browser]);const f=!!g().mountBrowser;u.useEffect(()=>{if(!l.current)return;const i=(g().mountBrowser||G)(l.current,p=>{j(p),document.activeElement!==c.current&&d(p.url)});return t.current=i,()=>{t.current=null,i.destroy()}},[]);const v=n=>{n.preventDefault();const i=C(w);if(!i||new URL(i).origin===window.location.origin){b(!0);return}b(!1),d(i),t.current?.navigate(i),c.current?.blur()},m=(n,i,p,k=!1)=>s.jsx("button",{type:"button",title:n,"aria-label":n,onClick:p,disabled:k,children:s.jsx(i,{"aria-hidden":"true"})});return s.jsxs("section",{className:"embedded-browser-panel","aria-label":r.browser,children:[s.jsxs("div",{className:"browser-navigation",children:[a,m(r.browserBack,N,()=>t.current?.back(),!e.canGoBack),m(r.browserForward,R,()=>t.current?.forward(),!e.canGoForward),m(f&&e.loading?r.browserStop:r.browserReload,f&&e.loading?A:L,()=>f&&e.loading?t.current?.stop():t.current?.reload(),!e.url),s.jsx("span",{className:"browser-page-title",title:e.title||e.url,children:e.title||r.browser}),s.jsx("a",{href:e.url||void 0,target:"_blank",rel:"noopener noreferrer","aria-label":r.browserExternal,title:r.browserExternal,"aria-disabled":!e.url,onClick:n=>{e.url||n.preventDefault()},children:s.jsx(E,{"aria-hidden":"true"})})]}),s.jsxs("form",{className:"browser-address",onSubmit:v,children:[s.jsx(x,{"aria-hidden":"true"}),s.jsx("input",{ref:c,value:w,onChange:n=>{d(n.target.value),b(!1)},"aria-label":r.browserAddress,placeholder:r.browserAddress,autoComplete:"off",spellCheck:!1,"aria-invalid":h,onFocus:n=>n.target.select()})]}),h&&s.jsx("p",{className:"browser-status",role:"alert",children:r.browserInvalidAddress}),e.error&&s.jsxs("div",{className:"browser-load-error",role:"alert",children:[s.jsx("p",{children:r.browserLoadFailed}),s.jsx("small",{children:e.error}),s.jsx("button",{type:"button",onClick:()=>t.current?.reload(),children:r.retry})]}),e.loading&&s.jsx("div",{className:"browser-loading",role:"status","aria-label":r.browserLoading}),s.jsx("div",{ref:l,role:"region",className:"browser-surface","aria-label":r.browser,hidden:!e.url||!!e.error}),!e.url&&s.jsxs("div",{className:"browser-empty",children:[s.jsx(x,{"aria-hidden":"true"}),s.jsx("p",{children:r.browserWelcome})]}),!f&&e.url&&s.jsx("p",{className:"browser-status",children:r.browserEmbedHint})]})}export{P as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as l}from"./index-
|
|
1
|
+
import{j as l}from"./index-ConcKf33.js";function i({ariaLabel:r,options:s,value:a,disabled:u,onChange:c}){return l.jsx("div",{className:"chip-group",role:"radiogroup","aria-label":r,children:s.map(e=>l.jsx("button",{"aria-checked":a===e.value,className:a===e.value?"selected":"",disabled:u,onClick:()=>c(e.value),role:"radio",title:e.title??e.label,type:"button",children:e.label},e.value))})}export{i as C};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as a,j as e,u as B}from"./index-
|
|
1
|
+
import{r as a,j as e,u as B}from"./index-ConcKf33.js";import{p as M,l as O,b as _,A as U,X as V,c as z}from"./App-CapuoJH2.js";function H(f){let c=0,n=0;return f.split(`
|
|
2
2
|
`).map(i=>{const t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(i);return t?(c=Number(t[1]),n=Number(t[2]),{text:i,kind:"hunk",oldLine:"",newLine:"",sign:""}):i.startsWith("diff ")||i.startsWith("index ")||i.startsWith("---")||i.startsWith("+++")||!c&&!n?{text:i,kind:"header",oldLine:"",newLine:"",sign:""}:i.startsWith("+")?{text:i.slice(1),kind:"add",oldLine:"",newLine:String(n++),sign:"+"}:i.startsWith("-")?{text:i.slice(1),kind:"del",oldLine:String(c++),newLine:"",sign:"−"}:i.startsWith(" ")?{text:i.slice(1),kind:"ctx",oldLine:String(c++),newLine:String(n++),sign:""}:{text:i,kind:"header",oldLine:"",newLine:"",sign:""}})}function J({patch:f,truncated:c,truncatedLabel:n,loadingLabel:i}){const t=a.useMemo(()=>H(f),[f]),[h,p]=a.useState(400),j=a.useRef(null);return a.useEffect(()=>{p(400)},[f]),a.useEffect(()=>{const r=j.current;if(!r)return;const u=new IntersectionObserver(x=>{x.some(o=>o.isIntersecting)&&p(o=>o+400)},{root:r.closest(".diff-patch"),rootMargin:"200px"});return u.observe(r),()=>u.disconnect()},[h,t.length]),e.jsxs("div",{className:"diff-patch-view",children:[t.slice(0,h).map((r,u)=>e.jsxs("div",{className:`diff-line ${r.kind}`,children:[e.jsx("span",{className:"diff-line-number","aria-hidden":"true",children:r.oldLine}),e.jsx("span",{className:"diff-line-number","aria-hidden":"true",children:r.newLine}),e.jsx("span",{className:"diff-line-sign","aria-hidden":"true",children:r.sign}),e.jsx("span",{className:"diff-line-text",children:r.text||" "})]},u)),h<t.length&&e.jsx("div",{ref:j,className:"diff-more",role:"status",children:i}),c&&e.jsx("p",{className:"diff-empty",children:n})]})}function K(f){const c=a.useRef(void 0);return a.useEffect(()=>()=>c.current?.(),[]),{"data-dock-draggable":!!f,onPointerDown:n=>{if(!f||n.button!==0||n.target.closest("button"))return;c.current?.();const i=n.currentTarget,t={x:n.clientX,y:n.clientY},h=document.querySelector(".workspace-documents");if(!h)return;let p=!1;const j=(o,w)=>{const N=h.getBoundingClientRect();return o>=N.left&&o<=N.right&&w>=N.top&&w<=N.bottom},r=o=>{Math.hypot(o.clientX-t.x,o.clientY-t.y)<6&&!p||(p=!0,document.body.classList.add("dock-dragging"),h.classList.toggle("dock-drop-target",j(o.clientX,o.clientY)))},u=()=>{document.body.classList.remove("dock-dragging"),h.classList.remove("dock-drop-target"),window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",u),i.hasPointerCapture(n.pointerId)&&i.releasePointerCapture(n.pointerId),c.current=void 0},x=o=>{const w=p&&j(o.clientX,o.clientY);u(),w&&f()};c.current=u,i.setPointerCapture(n.pointerId),window.addEventListener("pointermove",r),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",u),n.preventDefault()}}}const R={loading:!1,files:null,error:null};function ee({client:f,sessionId:c,cwd:n,sessionTitle:i,t,onClose:h,onDock:p,dockLabel:j,presentation:r="drawer",initialScope:u="unstaged",initialPath:x}){const o=a.useId(),w=a.useRef(null),[N,X]=a.useState(!1),C=a.useRef(void 0),P=a.useCallback(()=>{if(C.current===void 0){if(r==="workspace"||window.matchMedia("(prefers-reduced-motion: reduce)").matches){h();return}X(!0),C.current=window.setTimeout(h,180)}},[h,r]);a.useEffect(()=>()=>window.clearTimeout(C.current),[]);const Y=B(P,w,r==="drawer"),v=M(f,{sessionId:c,cwd:n},u),[m,A]=a.useState(u),[y,D]=a.useState({unstaged:R,staged:R,[u]:{...R,files:v.data?.files??null}}),[g,k]=a.useState(x??v.data?.files[0]?.path??null),[L,E]=a.useState(v.patches.get(x??v.data?.files[0]?.path??"")?.data??null),[G,T]=a.useState(!1),[$,S]=a.useState(null),I=K(r==="drawer"&&p?()=>p({scope:m,path:g}):void 0),b=y[m],W=a.useCallback(async s=>{D(l=>({...l,[s]:{loading:!0,files:l[s].files,error:null}}));try{const l=await O(f,{sessionId:c,cwd:n},s);D(d=>({...d,[s]:{loading:!1,files:l.files,error:null}}))}catch(l){D(d=>({...d,[s]:{loading:!1,files:null,error:l instanceof Error?l.message:String(l)}}))}},[f,c,n]);a.useEffect(()=>{W(m)},[m,W]),a.useEffect(()=>{const s=b.files;if(s){if(!s.length){k(null);return}k(l=>s.some(d=>d.path===l)?l:s[0].path)}},[b.files]),a.useEffect(()=>{if(!g){E(null),S(null);return}let s=!1;const l=M(f,{sessionId:c,cwd:n},m).patches.get(g)?.data;return E(d=>l??(d?.path===g?d:null)),T(!l&&L?.path!==g),S(null),_(f,{sessionId:c,cwd:n},m,g).then(d=>{s||(E(d),T(!1))}).catch(d=>{s||(S(d instanceof Error?d.message:String(d)),T(!1))}),()=>{s=!0}},[f,c,n,m,g,b.files]);const q=a.useMemo(()=>{const s=l=>l?l.reduce((d,F)=>({adds:d.adds+F.additions,dels:d.dels+F.deletions,count:d.count+1}),{adds:0,dels:0,count:0}):{adds:0,dels:0,count:0};return{unstaged:s(y.unstaged.files),staged:s(y.staged.files)}},[y]);return e.jsxs("div",{"aria-labelledby":o,"aria-modal":r==="drawer"?!0:void 0,className:`diff-drawer ${r==="workspace"?"diff-workspace":""} ${N?"closing":""}`,ref:Y,role:r==="drawer"?"dialog":"region",tabIndex:-1,children:[r==="drawer"&&e.jsx("div",{className:"diff-drawer-backdrop",onClick:P,"aria-hidden":"true"}),e.jsxs("div",{className:"diff-drawer-panel",children:[e.jsxs("header",{className:"diff-drawer-header",...I,children:[p&&r==="drawer"&&e.jsx("button",{type:"button",className:"icon-button","aria-label":j,title:j,onClick:()=>p({scope:m,path:g}),children:e.jsx(U,{})}),e.jsxs("div",{children:[e.jsx("strong",{id:o,children:t.changes}),e.jsx("span",{children:i})]}),e.jsx("button",{"aria-label":t.closeChanges,className:"icon-button",onClick:P,ref:w,type:"button",title:t.closeChanges,children:e.jsx(V,{"aria-hidden":"true"})})]}),e.jsx("div",{className:"diff-tabs",role:"tablist",children:["unstaged","staged"].map(s=>{const l=q[s],d=m===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":d,className:`diff-tab ${d?"active":""}`,onClick:()=>{s!==m&&(k(null),E(null),S(null),A(s))},children:[e.jsx("span",{className:"diff-tab-label",children:s==="unstaged"?t.workingChanges:t.stagedChanges}),l.count>0?e.jsxs("span",{className:"diff-tab-meta",children:[e.jsxs("span",{className:"diff-add",children:["+",l.adds]}),e.jsxs("span",{className:"diff-del",children:["-",l.dels]})]}):null]},s)})}),e.jsxs("div",{className:"diff-body",children:[e.jsxs("aside",{className:"diff-files","aria-label":t.changedFiles,children:[b.loading&&!b.files?e.jsx("p",{className:"diff-empty",children:t.loading}):null,b.error?e.jsx("p",{className:"diff-empty diff-error",children:b.error}):null,b.files&&b.files.length===0?e.jsx("p",{className:"diff-empty",children:t.noChanges}):null,b.files?.map(s=>e.jsxs("button",{type:"button",className:`diff-file diff-file-${s.status} ${g===s.path?"active":""}`,onClick:()=>k(s.path),children:[e.jsx("span",{className:`diff-status diff-status-${s.status}`,children:s.status}),e.jsx("span",{className:"diff-file-path",title:s.path,children:s.path}),e.jsxs("span",{className:"diff-file-stats",children:[s.binary?e.jsx("span",{className:"diff-binary",children:"bin"}):null,!s.binary&&s.additions>0?e.jsxs("span",{className:"diff-add",children:["+",s.additions]}):null,!s.binary&&s.deletions>0?e.jsxs("span",{className:"diff-del",children:["-",s.deletions]}):null]})]},s.path))]}),e.jsx("section",{className:"diff-patch","aria-label":t.fileDiff,children:g?G?e.jsx("p",{className:"diff-empty",children:t.loadingPatch}):$?e.jsx("p",{className:"diff-empty diff-error",children:$}):L?.binary?e.jsx("p",{className:"diff-empty",children:t.binaryDiffUnavailable}):L?e.jsx(J,{patch:L.patch,truncated:L.truncated,truncatedLabel:t.patchTruncated,loadingLabel:t.loadingPatch},`${m}:${g}`):null:e.jsxs("div",{className:"diff-empty",children:[e.jsx(z,{"aria-hidden":"true"}),e.jsx("p",{children:t.selectFileForDiff})]})})]})]})]})}export{ee as DiffDrawer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as z,j as e,i as J,r as u,E as ne,u as ae,e as se,l as ie}from"./index-BH_ibxBN.js";import{X as Q,a as oe,P as le,T as ce,i as Z,w as de,n as O,f as $,j as B,k as H,m as ue,L as ee,R as fe,o as pe,e as te,q as re,s as me,v as he,c as ye}from"./App-DcLmCQZc.js";import{F as xe}from"./folder-plus-ByEha8BZ.js";const ge=[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]],be=z("clipboard-paste",ge);const je=[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],ke=z("file-code-corner",je);const Ee=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],we=z("image",Ee);const De=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]],ve=z("link",De);const Ce=[["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"}]],Ne=z("scissors",Ce);function Se({ops:t,onOpen:f,root:j}){const b=u.useRef(null),d=t.menu;u.useLayoutEffect(()=>{const s=b.current,m=document.activeElement,E=s.getBoundingClientRect();s.style.left=`${Math.max(8,Math.min(d.x,innerWidth-E.width-8))}px`,s.style.top=`${Math.max(8,Math.min(d.y,innerHeight-E.height-8))}px`,s.querySelector("button:not(:disabled)")?.focus();const w=l=>{s.contains(l.target)||t.setMenu(null)},x=()=>t.setMenu(null);return document.addEventListener("pointerdown",w),document.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{document.removeEventListener("pointerdown",w),document.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x),s.contains(document.activeElement)&&m?.focus()}},[]);const o=s=>{s.stopPropagation();const m=Array.from(b.current.querySelectorAll("button:not(:disabled)")),E=m.indexOf(document.activeElement);["ArrowUp","ArrowDown","Home","End","Escape","Tab"].includes(s.key)&&s.preventDefault(),(s.key==="Escape"||s.key==="Tab")&&t.setMenu(null),s.key==="ArrowDown"&&m[(E+1)%m.length]?.focus(),s.key==="ArrowUp"&&m[(E-1+m.length)%m.length]?.focus(),s.key==="Home"&&m[0]?.focus(),s.key==="End"&&m.at(-1)?.focus()},y=s=>{t.setMenu(null),s()};return e.jsxs("div",{ref:b,role:"menu","aria-label":t.strings.open,className:"session-context-menu file-tree-menu",style:{left:d.x,top:d.y},onKeyDown:o,onContextMenu:s=>s.preventDefault(),children:[!d.directory&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>y(f),children:[e.jsx(ne,{}),t.strings.open]}),d.path!==j&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>t.copy(d,!1),children:[e.jsx(oe,{}),t.strings.copy,e.jsx("kbd",{children:"⌘C"})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>t.copy(d,!0),children:[e.jsx(Ne,{}),t.strings.cut,e.jsx("kbd",{children:"⌘X"})]})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!t.canPaste,onClick:()=>y(()=>{t.paste(d)}),children:[e.jsx(be,{}),t.strings.paste,e.jsx("kbd",{children:"⌘V"})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>y(()=>{t.copyPath(d)}),children:[e.jsx(ve,{}),t.strings.copyPath]}),d.path!==j&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"context-menu-separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>t.startRename(d),children:[e.jsx(le,{}),t.strings.rename,e.jsx("kbd",{children:"F2"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"danger",onClick:()=>y(()=>t.setDeleting(d)),children:[e.jsx(ce,{}),t.strings.delete]})]})]})}function Fe({ops:t}){const f=ae(()=>{t.busy||t.setDeleting(null)});return e.jsx("div",{className:"modal-backdrop file-tree-backdrop",children:e.jsxs("div",{ref:f,className:"file-tree-delete-dialog",role:"dialog","aria-modal":"true","aria-label":t.strings.confirmDelete,tabIndex:-1,children:[e.jsx("h2",{children:t.strings.confirmDelete}),e.jsx("p",{children:t.deleting?.path}),e.jsx("p",{children:t.strings.deleteHint}),t.error&&e.jsx("p",{role:"alert",children:t.error}),e.jsxs("div",{className:"file-tree-dialog-actions",children:[e.jsx("button",{type:"button",disabled:t.busy,onClick:()=>t.setDeleting(null),children:t.strings.cancel}),e.jsx("button",{type:"button",className:"danger",disabled:t.busy,onClick:()=>{t.deleteItem()},children:t.strings.delete})]})]})})}function _e({ops:t,root:f,onOpen:j}){return e.jsxs(e.Fragment,{children:[t.menu&&J.createPortal(e.jsx(Se,{ops:t,root:f,onOpen:j}),document.body),t.deleting&&J.createPortal(e.jsx(Fe,{ops:t}),document.body),t.error&&!t.deleting&&e.jsxs("div",{className:"file-tree-notice",role:"alert",children:[e.jsx("span",{children:t.error}),e.jsx("button",{type:"button",title:t.strings.dismiss,"aria-label":t.strings.dismiss,onClick:()=>t.setError(""),children:e.jsx(Q,{})})]}),t.undo&&e.jsxs("div",{className:"file-tree-notice",role:"status",children:[e.jsx("span",{children:t.strings.deleted}),e.jsx("button",{type:"button",disabled:t.busy,onClick:()=>{t.restore()},children:t.strings.undo}),e.jsx("button",{type:"button",title:t.strings.dismiss,"aria-label":t.strings.dismiss,onClick:()=>t.setUndo(null),children:e.jsx(Q,{})})]})]})}function Y(t){return[...t].sort((f,j)=>Number(j.isDirectory)-Number(f.isDirectory)||f.name.localeCompare(j.name,void 0,{numeric:!0,sensitivity:"base"}))}function Te(t,f,j){const[b,d]=u.useState(new Set),[o,y]=u.useState({}),[s,m]=u.useState(new Set),[E,w]=u.useState({}),x=u.useRef(0),l=u.useRef(new Set);return u.useEffect(()=>(x.current++,l.current.clear(),d(new Set),y({}),m(new Set),w({}),()=>{x.current++}),[t]),{refresh:async()=>{const g=++x.current;l.current.clear(),m(new Set(b)),w({});const D=await Promise.all([...b].map(async c=>{try{return[c,Y(await j(c))]}catch{return null}}));g===x.current&&(y(Object.fromEntries(D.filter(c=>c!==null))),d(new Set(D.flatMap(c=>c?[c[0]]:[]))),m(new Set))},expanded:b,children:o,loading:s,errors:E,collapse:g=>d(D=>{const c=new Set(D);return c.delete(g),c}),expand:async g=>{if(d(c=>new Set(c).add(g)),o[g]||l.current.has(g))return;const D=x.current;l.current.add(g),m(c=>new Set(c).add(g)),w(c=>{const S={...c};return delete S[g],S});try{const c=await j(g);x.current===D&&y(S=>({...S,[g]:Y(c)}))}catch{x.current===D&&w(c=>({...c,[g]:"unavailable"}))}finally{x.current===D&&(l.current.delete(g),m(c=>{const S=new Set(c);return S.delete(g),S}))}}}}const Me={copy:"Copy",cut:"Cut",paste:"Paste",copyPath:"Copy path",rename:"Rename",delete:"Delete",cancel:"Cancel",confirmDelete:"Delete this item?",deleteHint:"You can undo this deletion after it finishes.",deleted:"Deleted",undo:"Undo",dismiss:"Dismiss",name:"Name",open:"Open",errors:{destination_exists:"An item with this name already exists.",recursive_destination:"Choose a different folder.",outside_root:"Choose a destination inside this folder.",protected_path:"This location is protected.",invalid_operation:"Enter a valid file name.",unsaved_changes:"Save the open file changes first.",daemon_update_required:"Update Vibelet on the connected computer to enable file operations.",ENOENT:"The file or folder no longer exists. Refresh the tree.",EACCES:"Permission denied.",EXDEV:"Moving between disks is unavailable. Copy the item first.",operation_failed:"File operation failed."}},Le={copy:"复制",cut:"剪切",paste:"粘贴",copyPath:"复制路径",rename:"重命名",delete:"删除",cancel:"取消",confirmDelete:"删除这个项目?",deleteHint:"删除完成后可以撤销。",deleted:"已删除",undo:"撤销",dismiss:"关闭",name:"名称",open:"打开",errors:{destination_exists:"已有同名文件或文件夹,请换一个名称。",recursive_destination:"不能移动或复制到自身目录中。",outside_root:"请选择当前文件夹内的目标目录。",protected_path:"不能操作这个受保护的位置。",invalid_operation:"请输入有效的文件名。",unsaved_changes:"请先保存已打开文件的修改。",daemon_update_required:"请更新被连接电脑上的 Vibelet,以启用文件操作。",ENOENT:"文件或文件夹已不存在,请刷新文件树。",EACCES:"没有操作权限。",EXDEV:"暂不支持跨磁盘移动,请先复制。",operation_failed:"文件操作失败。"}},Pe={copy:"複製",cut:"剪下",paste:"貼上",copyPath:"複製路徑",rename:"重新命名",delete:"刪除",cancel:"取消",confirmDelete:"刪除這個項目?",deleteHint:"刪除完成後可以復原。",deleted:"已刪除",undo:"復原",dismiss:"關閉",name:"名稱",open:"開啟",errors:{destination_exists:"已有同名檔案或資料夾,請換一個名稱。",recursive_destination:"不能移動或複製到自身目錄中。",outside_root:"請選擇目前資料夾內的目標目錄。",protected_path:"不能操作這個受保護的位置。",invalid_operation:"請輸入有效的檔案名稱。",unsaved_changes:"請先儲存已開啟檔案的修改。",daemon_update_required:"請更新被連接電腦上的 Vibelet,以啟用檔案操作。",ENOENT:"檔案或資料夾已不存在,請重新整理檔案樹。",EACCES:"沒有操作權限。",EXDEV:"暫不支援跨磁碟移動,請先複製。",operation_failed:"檔案操作失敗。"}};function Ae(){const t=se(ie().language);return t==="en"?Me:t==="zh-TW"?Pe:Le}let T=null,F=null;const W="application/x-vibelet-file",X="vibelet:file-clipboard";function Re(t,f,j){const b=Ae(),[d,o]=u.useState(null),[y,s]=u.useState(null),[m,E]=u.useState(""),[w,x]=u.useState(null),[l,i]=u.useState(null),[K,_]=u.useState(""),[g,D]=u.useState(!1),c=u.useRef(!1),[S,M]=u.useState(null),[,U]=u.useState(0),I=Z(),C=I?.daemonId;u.useEffect(()=>{const n=()=>U(r=>r+1);return window.addEventListener(X,n),()=>window.removeEventListener(X,n)},[]),u.useEffect(()=>{o(null),s(null),x(null),i(null),_(""),M(null)},[t,f,C]);const N=n=>{const r=n instanceof Error?n.message:"operation_failed";_(b.errors[r]??b.errors.operation_failed)},L=async n=>{if(!I||c.current)return!1;c.current=!0,D(!0),_("");try{const r=await ue({...n,root:t,cwd:f},I);return Z()?.daemonId===C&&(r.action==="delete"&&i(r),await j()),!0}catch(r){return N(r),!1}finally{c.current=!1,D(!1)}},V=(n,r)=>{C&&(T={target:n,cut:r,daemonId:C,root:t,cwd:f},window.dispatchEvent(new Event(X)),o(null),_(""))},q=n=>n.directory?n.path:H(n.path)??t,a=!!(T&&T.daemonId===C),v=async n=>{const r=T;if(!a||!r)return;await L({action:r.cut?"move":"copy",path:r.target.path,sourceRoot:r.root,sourceCwd:r.cwd,target:B(q(n),$(r.target.path)),autoRename:!r.cut&&O(q(n),f)===O(H(r.target.path)??r.root,r.cwd)})&&r.cut&&T===r&&(T=null,window.dispatchEvent(new Event(X)))},k=(n,r,R)=>{c.current||o({...n,x:r,y:R})},h=n=>{s(n),E($(n.path)),o(null),_("")},P=async()=>{if(!y)return;const n=m.trim();if(!n||/[/\\\x00]/.test(n)||n==="."||n===".."){N(new Error("invalid_operation"));return}if(n===$(y.path)){s(null);return}await L({action:"move",path:y.path,target:B(H(y.path)??t,n)})&&s(null)},p=(n,r)=>{if(n.target!==n.currentTarget)return!1;if((n.metaKey||n.ctrlKey)&&["c","x","v"].includes(n.key.toLowerCase()))return n.preventDefault(),n.key.toLowerCase()==="v"?v(r):V(r,n.key.toLowerCase()==="x"),!0;if(n.key==="F2")return n.preventDefault(),h(r),!0;if(n.key==="Delete"||n.metaKey&&n.key==="Backspace")return n.preventDefault(),x(r),!0;if(n.key==="ContextMenu"||n.shiftKey&&n.key==="F10"){n.preventDefault();const G=n.currentTarget.getBoundingClientRect();return k(r,G.left+20,G.top+24),!0}return!1},A=n=>{if(!F||F.daemonId!==C||F.root!==t||F.cwd!==f||c.current)return!1;const r=O(F.target.path,f),R=O(n,f);return R!==r&&!R.startsWith(`${r}/`)&&O(H(F.target.path)??t,f)!==R};return{strings:b,menu:d,setMenu:o,rename:y,setRename:s,name:m,setName:E,deleting:w,setDeleting:x,error:K,setError:_,busy:g,undo:l,setUndo:i,canPaste:a,copy:V,paste:v,key:p,startRename:h,commitRename:P,openMenu:k,copyPath:async n=>{try{await de(O(n.path,f))}catch(r){N(r)}},deleteItem:async()=>{w&&await L({action:"delete",path:w.path})&&x(null)},restore:async()=>{l&&await L({action:"restore",path:l.path,recoveryId:l.recoveryId})&&i(null)},isCut:n=>!!(T?.cut&&T.daemonId===C&&T.target.path===n),dropTarget:S,dragStart:(n,r)=>{if(!C||c.current){n.preventDefault();return}F={target:r,cut:!0,daemonId:C,root:t,cwd:f},n.dataTransfer.setData(W,r.path),n.dataTransfer.effectAllowed="copyMove",o(null)},dragEnd:()=>{F=null,M(null)},dragOver:(n,r)=>{!n.dataTransfer.types.includes(W)||!A(r)||(n.preventDefault(),n.stopPropagation(),n.dataTransfer.dropEffect=n.altKey?"copy":"move",M(r))},dragLeave:n=>{n.currentTarget.contains(n.relatedTarget)||M(null)},drop:(n,r)=>{n.preventDefault(),n.stopPropagation(),M(null),!(!n.dataTransfer.types.includes(W)||!A(r)||!F)&&L({action:n.altKey?"copy":"move",path:F.target.path,target:B(r,$(F.target.path))})}}}function Ie(t){return/\.(png|jpe?g|gif|webp|svg|ico)$/i.test(t)?we:/\.(tsx?|jsx?|json|css|html|py|rs|go|swift|ya?ml|sh)$/i.test(t)?ke:ye}function Oe({cwd:t,entries:f,error:j,loaded:b,loading:d,path:o,selectedPath:y,t:s,onListDirectory:m,onLoadChildren:E,onNewFolder:w,onOpenRemoteFile:x}){const l=Te(o,f,E),i=Re(o,t,async()=>{m(o),await l.refresh()}),K=u.useRef(null),[_,g]=u.useState(!1),[D,c]=u.useState(o),[S,M]=u.useState(y),[U,I]=u.useState();u.useEffect(()=>{c(o)},[o]),u.useEffect(()=>I(void 0),[o,f]),u.useEffect(()=>{M(y)},[y]);const C=(a,v)=>{a.isDirectory?l.expanded.has(v)?l.collapse(v):l.expand(v):(M(v),x(v,t))},N=a=>a?.focus(),L=(a,v,k)=>{if(a.stopPropagation(),i.key(a,{path:k,directory:v.isDirectory})||a.target instanceof HTMLInputElement)return;const h=Array.from(K.current?.querySelectorAll('[role="treeitem"]')??[]),P=h.indexOf(a.currentTarget);["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","Enter"," "].includes(a.key)&&a.preventDefault(),a.key==="ArrowUp"&&N(h[Math.max(0,P-1)]),a.key==="ArrowDown"&&N(h[Math.min(h.length-1,P+1)]),a.key==="Home"&&N(h[0]),a.key==="End"&&N(h.at(-1)),a.key==="ArrowRight"&&v.isDirectory&&(!l.expanded.has(k)||l.errors[k]?l.expand(k):N(a.currentTarget.querySelector('[role="treeitem"]'))),a.key==="ArrowLeft"&&(v.isDirectory&&l.expanded.has(k)?l.collapse(k):N(a.currentTarget.parentElement?.closest('[role="treeitem"]'))),(a.key==="Enter"||a.key===" ")&&C(v,k)},V=Y(f),q=(a,v,k)=>a.map((h,P)=>{const p=B(v,h.name),A=l.expanded.has(p),n=h.isDirectory?A?te:re:Ie(h.name);return e.jsxs("div",{role:"treeitem","aria-label":h.name,"aria-level":k+1,"aria-posinset":P+1,"aria-setsize":a.length,"aria-expanded":h.isDirectory?A:void 0,"aria-selected":S===p,"aria-busy":l.loading.has(p)||void 0,"data-path":p,className:"explorer-tree-item",tabIndex:U===p||!U&&k===0&&P===0?0:-1,onFocus:r=>{r.target===r.currentTarget&&I(p)},onKeyDown:r=>L(r,h,p),children:[e.jsxs("div",{className:"explorer-tree-row",draggable:!i.busy&&i.rename?.path!==p,"data-cut":i.isCut(p)||void 0,"data-drop":i.dropTarget===p||void 0,onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),N(r.currentTarget.parentElement),i.openMenu({path:p,directory:h.isDirectory},r.clientX,r.clientY)},onDragStart:r=>i.dragStart(r,{path:p,directory:h.isDirectory}),onDragEnd:i.dragEnd,onDragOver:r=>h.isDirectory&&i.dragOver(r,p),onDragLeave:i.dragLeave,onDrop:r=>h.isDirectory&&i.drop(r,p),style:{paddingLeft:8+k*14},title:p,onClick:r=>{N(r.currentTarget.parentElement),C(h,p)},children:[e.jsx("span",{className:"explorer-chevron","aria-hidden":"true",children:h.isDirectory&&(l.loading.has(p)?e.jsx(ee,{className:"explorer-spinner"}):A?e.jsx(me,{}):e.jsx(he,{}))}),e.jsx(n,{className:h.isDirectory?"explorer-folder-icon":"explorer-file-icon","aria-hidden":"true"}),e.jsx("span",{className:"explorer-entry-name",children:i.rename?.path===p?e.jsx("input",{className:"explorer-rename","aria-label":i.strings.name,autoFocus:!0,value:i.name,disabled:i.busy,onFocus:r=>r.target.select(),onClick:r=>r.stopPropagation(),onChange:r=>i.setName(r.target.value),onKeyDown:r=>{r.stopPropagation(),r.key==="Enter"&&(r.preventDefault(),i.commitRename()),r.key==="Escape"&&(r.preventDefault(),i.setRename(null))}}):h.name})]}),h.isDirectory&&A&&e.jsxs("div",{role:"group",className:"explorer-tree-group",style:{"--tree-guide-left":`${14+k*14}px`},children:[l.children[p]?q(l.children[p],p,k+1):null,l.errors[p]&&e.jsx("button",{className:"explorer-retry",type:"button",onClick:()=>{l.expand(p)},children:s.retry}),l.children[p]?.length===0&&e.jsx("p",{className:"explorer-empty",style:{paddingLeft:36+k*14},children:s.noFilesInDirectory})]})]},p)});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"explorer-heading",children:[e.jsx("h2",{children:s.fileTree}),e.jsxs("div",{className:"explorer-actions",children:[e.jsx("button",{className:"icon-button",title:s.newFolder,"aria-label":s.newFolder,onClick:w,type:"button",children:e.jsx(xe,{"aria-hidden":"true"})}),e.jsx("button",{className:"icon-button",title:s.refreshFiles,"aria-label":s.refreshFiles,disabled:d,onClick:()=>{m(o),l.refresh()},type:"button",children:d?e.jsx(ee,{className:"explorer-spinner","aria-hidden":"true"}):e.jsx(fe,{"aria-hidden":"true"})}),e.jsx("button",{className:"icon-button",title:s.parentFolder,"aria-label":s.parentFolder,disabled:!H(o),onClick:()=>m(H(o)??o),type:"button",children:e.jsx(pe,{"aria-hidden":"true"})})]})]}),e.jsxs("button",{type:"button",className:"explorer-root-path",onContextMenu:a=>{a.preventDefault(),i.openMenu({path:o,directory:!0},a.clientX,a.clientY)},onDragOver:a=>i.dragOver(a,o),onDragLeave:i.dragLeave,onDrop:a=>i.drop(a,o),"data-drop":i.dropTarget===o||void 0,title:o==="."?t:o,onClick:()=>{c(o),g(a=>!a)},children:[e.jsx(te,{"aria-hidden":"true"}),e.jsx("span",{children:$(o==="."?t:o)||o})]}),_&&e.jsx("form",{className:"explorer-path-form",onSubmit:a=>{a.preventDefault(),D.trim()&&(m(D.trim()),g(!1))},children:e.jsx("input",{autoFocus:!0,"aria-label":s.path,value:D,onChange:a=>c(a.target.value),onKeyDown:a=>{a.key==="Escape"&&g(!1)}})}),j&&e.jsx("p",{className:"empty-copy",role:"alert",children:j}),d&&e.jsx("p",{className:"explorer-empty",role:"status",children:s.loadingFiles}),e.jsx("div",{ref:K,role:"tree","aria-label":s.fileTree,className:"explorer-tree","aria-busy":d||i.busy,"data-drop":i.dropTarget===o||void 0,onContextMenu:a=>{a.preventDefault(),i.openMenu({path:o,directory:!0},a.clientX,a.clientY)},onDragOver:a=>i.dragOver(a,o),onDragLeave:i.dragLeave,onDrop:a=>i.drop(a,o),children:q(V,o,0)}),e.jsx(_e,{ops:i,root:o,onOpen:()=>i.menu&&x(i.menu.path,t)}),b&&!d&&!j&&f.length===0&&e.jsx("p",{className:"explorer-empty",children:s.noFilesInDirectory})]})}function $e({busy:t,onLoadChildren:f,cwd:j,directory:b,newDirName:d,remoteFile:o,t:y,onCreateDirectory:s,onListDirectory:m,onNewDirNameChange:E,onOpenRemoteFile:w}){const[x,l]=u.useState(!1);return e.jsx(e.Fragment,{children:e.jsxs("section",{className:"control-section files-explorer",children:[e.jsx(Oe,{cwd:j,selectedPath:o?.path,onLoadChildren:f,onNewFolder:()=>l(i=>!i),entries:b.entries,error:b.error,loaded:b.loaded,loading:b.loading,path:b.path,t:y,onListDirectory:m,onOpenRemoteFile:w}),x&&e.jsxs("div",{className:"field-row file-tree-create",children:[e.jsx("input",{value:d,onChange:i=>E(i.target.value),placeholder:y.newFolder,"aria-label":y.newFolder,autoFocus:!0,onKeyDown:i=>{i.key==="Escape"&&(l(!1),E("")),i.key==="Enter"&&d.trim()&&!t&&s()}}),e.jsxs("button",{className:"icon-text-button",onClick:s,type:"button",disabled:t||!d.trim(),children:[e.jsx(re,{"aria-hidden":"true"}),y.create]})]})]})})}export{$e as FilesControlPanel};
|
|
1
|
+
import{c as z,j as e,i as J,r as u,E as ne,u as ae,e as se,l as ie}from"./index-ConcKf33.js";import{X as Q,a as oe,P as le,T as ce,i as Z,w as de,n as O,f as $,j as B,k as H,m as ue,L as ee,R as fe,o as pe,e as te,q as re,s as me,t as he,c as ye}from"./App-CapuoJH2.js";import{F as xe}from"./folder-plus-DHw5YJHP.js";const ge=[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]],be=z("clipboard-paste",ge);const je=[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],ke=z("file-code-corner",je);const Ee=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],we=z("image",Ee);const De=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]],ve=z("link",De);const Ce=[["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"}]],Ne=z("scissors",Ce);function Se({ops:t,onOpen:f,root:j}){const b=u.useRef(null),d=t.menu;u.useLayoutEffect(()=>{const s=b.current,m=document.activeElement,E=s.getBoundingClientRect();s.style.left=`${Math.max(8,Math.min(d.x,innerWidth-E.width-8))}px`,s.style.top=`${Math.max(8,Math.min(d.y,innerHeight-E.height-8))}px`,s.querySelector("button:not(:disabled)")?.focus();const w=l=>{s.contains(l.target)||t.setMenu(null)},x=()=>t.setMenu(null);return document.addEventListener("pointerdown",w),document.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{document.removeEventListener("pointerdown",w),document.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x),s.contains(document.activeElement)&&m?.focus()}},[]);const o=s=>{s.stopPropagation();const m=Array.from(b.current.querySelectorAll("button:not(:disabled)")),E=m.indexOf(document.activeElement);["ArrowUp","ArrowDown","Home","End","Escape","Tab"].includes(s.key)&&s.preventDefault(),(s.key==="Escape"||s.key==="Tab")&&t.setMenu(null),s.key==="ArrowDown"&&m[(E+1)%m.length]?.focus(),s.key==="ArrowUp"&&m[(E-1+m.length)%m.length]?.focus(),s.key==="Home"&&m[0]?.focus(),s.key==="End"&&m.at(-1)?.focus()},y=s=>{t.setMenu(null),s()};return e.jsxs("div",{ref:b,role:"menu","aria-label":t.strings.open,className:"session-context-menu file-tree-menu",style:{left:d.x,top:d.y},onKeyDown:o,onContextMenu:s=>s.preventDefault(),children:[!d.directory&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>y(f),children:[e.jsx(ne,{}),t.strings.open]}),d.path!==j&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>t.copy(d,!1),children:[e.jsx(oe,{}),t.strings.copy,e.jsx("kbd",{children:"⌘C"})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>t.copy(d,!0),children:[e.jsx(Ne,{}),t.strings.cut,e.jsx("kbd",{children:"⌘X"})]})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!t.canPaste,onClick:()=>y(()=>{t.paste(d)}),children:[e.jsx(be,{}),t.strings.paste,e.jsx("kbd",{children:"⌘V"})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>y(()=>{t.copyPath(d)}),children:[e.jsx(ve,{}),t.strings.copyPath]}),d.path!==j&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"context-menu-separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>t.startRename(d),children:[e.jsx(le,{}),t.strings.rename,e.jsx("kbd",{children:"F2"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"danger",onClick:()=>y(()=>t.setDeleting(d)),children:[e.jsx(ce,{}),t.strings.delete]})]})]})}function Fe({ops:t}){const f=ae(()=>{t.busy||t.setDeleting(null)});return e.jsx("div",{className:"modal-backdrop file-tree-backdrop",children:e.jsxs("div",{ref:f,className:"file-tree-delete-dialog",role:"dialog","aria-modal":"true","aria-label":t.strings.confirmDelete,tabIndex:-1,children:[e.jsx("h2",{children:t.strings.confirmDelete}),e.jsx("p",{children:t.deleting?.path}),e.jsx("p",{children:t.strings.deleteHint}),t.error&&e.jsx("p",{role:"alert",children:t.error}),e.jsxs("div",{className:"file-tree-dialog-actions",children:[e.jsx("button",{type:"button",disabled:t.busy,onClick:()=>t.setDeleting(null),children:t.strings.cancel}),e.jsx("button",{type:"button",className:"danger",disabled:t.busy,onClick:()=>{t.deleteItem()},children:t.strings.delete})]})]})})}function _e({ops:t,root:f,onOpen:j}){return e.jsxs(e.Fragment,{children:[t.menu&&J.createPortal(e.jsx(Se,{ops:t,root:f,onOpen:j}),document.body),t.deleting&&J.createPortal(e.jsx(Fe,{ops:t}),document.body),t.error&&!t.deleting&&e.jsxs("div",{className:"file-tree-notice",role:"alert",children:[e.jsx("span",{children:t.error}),e.jsx("button",{type:"button",title:t.strings.dismiss,"aria-label":t.strings.dismiss,onClick:()=>t.setError(""),children:e.jsx(Q,{})})]}),t.undo&&e.jsxs("div",{className:"file-tree-notice",role:"status",children:[e.jsx("span",{children:t.strings.deleted}),e.jsx("button",{type:"button",disabled:t.busy,onClick:()=>{t.restore()},children:t.strings.undo}),e.jsx("button",{type:"button",title:t.strings.dismiss,"aria-label":t.strings.dismiss,onClick:()=>t.setUndo(null),children:e.jsx(Q,{})})]})]})}function Y(t){return[...t].sort((f,j)=>Number(j.isDirectory)-Number(f.isDirectory)||f.name.localeCompare(j.name,void 0,{numeric:!0,sensitivity:"base"}))}function Te(t,f,j){const[b,d]=u.useState(new Set),[o,y]=u.useState({}),[s,m]=u.useState(new Set),[E,w]=u.useState({}),x=u.useRef(0),l=u.useRef(new Set);return u.useEffect(()=>(x.current++,l.current.clear(),d(new Set),y({}),m(new Set),w({}),()=>{x.current++}),[t]),{refresh:async()=>{const g=++x.current;l.current.clear(),m(new Set(b)),w({});const D=await Promise.all([...b].map(async c=>{try{return[c,Y(await j(c))]}catch{return null}}));g===x.current&&(y(Object.fromEntries(D.filter(c=>c!==null))),d(new Set(D.flatMap(c=>c?[c[0]]:[]))),m(new Set))},expanded:b,children:o,loading:s,errors:E,collapse:g=>d(D=>{const c=new Set(D);return c.delete(g),c}),expand:async g=>{if(d(c=>new Set(c).add(g)),o[g]||l.current.has(g))return;const D=x.current;l.current.add(g),m(c=>new Set(c).add(g)),w(c=>{const S={...c};return delete S[g],S});try{const c=await j(g);x.current===D&&y(S=>({...S,[g]:Y(c)}))}catch{x.current===D&&w(c=>({...c,[g]:"unavailable"}))}finally{x.current===D&&(l.current.delete(g),m(c=>{const S=new Set(c);return S.delete(g),S}))}}}}const Me={copy:"Copy",cut:"Cut",paste:"Paste",copyPath:"Copy path",rename:"Rename",delete:"Delete",cancel:"Cancel",confirmDelete:"Delete this item?",deleteHint:"You can undo this deletion after it finishes.",deleted:"Deleted",undo:"Undo",dismiss:"Dismiss",name:"Name",open:"Open",errors:{destination_exists:"An item with this name already exists.",recursive_destination:"Choose a different folder.",outside_root:"Choose a destination inside this folder.",protected_path:"This location is protected.",invalid_operation:"Enter a valid file name.",unsaved_changes:"Save the open file changes first.",daemon_update_required:"Update Vibelet on the connected computer to enable file operations.",ENOENT:"The file or folder no longer exists. Refresh the tree.",EACCES:"Permission denied.",EXDEV:"Moving between disks is unavailable. Copy the item first.",operation_failed:"File operation failed."}},Le={copy:"复制",cut:"剪切",paste:"粘贴",copyPath:"复制路径",rename:"重命名",delete:"删除",cancel:"取消",confirmDelete:"删除这个项目?",deleteHint:"删除完成后可以撤销。",deleted:"已删除",undo:"撤销",dismiss:"关闭",name:"名称",open:"打开",errors:{destination_exists:"已有同名文件或文件夹,请换一个名称。",recursive_destination:"不能移动或复制到自身目录中。",outside_root:"请选择当前文件夹内的目标目录。",protected_path:"不能操作这个受保护的位置。",invalid_operation:"请输入有效的文件名。",unsaved_changes:"请先保存已打开文件的修改。",daemon_update_required:"请更新被连接电脑上的 Vibelet,以启用文件操作。",ENOENT:"文件或文件夹已不存在,请刷新文件树。",EACCES:"没有操作权限。",EXDEV:"暂不支持跨磁盘移动,请先复制。",operation_failed:"文件操作失败。"}},Pe={copy:"複製",cut:"剪下",paste:"貼上",copyPath:"複製路徑",rename:"重新命名",delete:"刪除",cancel:"取消",confirmDelete:"刪除這個項目?",deleteHint:"刪除完成後可以復原。",deleted:"已刪除",undo:"復原",dismiss:"關閉",name:"名稱",open:"開啟",errors:{destination_exists:"已有同名檔案或資料夾,請換一個名稱。",recursive_destination:"不能移動或複製到自身目錄中。",outside_root:"請選擇目前資料夾內的目標目錄。",protected_path:"不能操作這個受保護的位置。",invalid_operation:"請輸入有效的檔案名稱。",unsaved_changes:"請先儲存已開啟檔案的修改。",daemon_update_required:"請更新被連接電腦上的 Vibelet,以啟用檔案操作。",ENOENT:"檔案或資料夾已不存在,請重新整理檔案樹。",EACCES:"沒有操作權限。",EXDEV:"暫不支援跨磁碟移動,請先複製。",operation_failed:"檔案操作失敗。"}};function Ae(){const t=se(ie().language);return t==="en"?Me:t==="zh-TW"?Pe:Le}let T=null,F=null;const W="application/x-vibelet-file",X="vibelet:file-clipboard";function Re(t,f,j){const b=Ae(),[d,o]=u.useState(null),[y,s]=u.useState(null),[m,E]=u.useState(""),[w,x]=u.useState(null),[l,i]=u.useState(null),[K,_]=u.useState(""),[g,D]=u.useState(!1),c=u.useRef(!1),[S,M]=u.useState(null),[,U]=u.useState(0),I=Z(),C=I?.daemonId;u.useEffect(()=>{const n=()=>U(r=>r+1);return window.addEventListener(X,n),()=>window.removeEventListener(X,n)},[]),u.useEffect(()=>{o(null),s(null),x(null),i(null),_(""),M(null)},[t,f,C]);const N=n=>{const r=n instanceof Error?n.message:"operation_failed";_(b.errors[r]??b.errors.operation_failed)},L=async n=>{if(!I||c.current)return!1;c.current=!0,D(!0),_("");try{const r=await ue({...n,root:t,cwd:f},I);return Z()?.daemonId===C&&(r.action==="delete"&&i(r),await j()),!0}catch(r){return N(r),!1}finally{c.current=!1,D(!1)}},V=(n,r)=>{C&&(T={target:n,cut:r,daemonId:C,root:t,cwd:f},window.dispatchEvent(new Event(X)),o(null),_(""))},q=n=>n.directory?n.path:H(n.path)??t,a=!!(T&&T.daemonId===C),v=async n=>{const r=T;if(!a||!r)return;await L({action:r.cut?"move":"copy",path:r.target.path,sourceRoot:r.root,sourceCwd:r.cwd,target:B(q(n),$(r.target.path)),autoRename:!r.cut&&O(q(n),f)===O(H(r.target.path)??r.root,r.cwd)})&&r.cut&&T===r&&(T=null,window.dispatchEvent(new Event(X)))},k=(n,r,R)=>{c.current||o({...n,x:r,y:R})},h=n=>{s(n),E($(n.path)),o(null),_("")},P=async()=>{if(!y)return;const n=m.trim();if(!n||/[/\\\x00]/.test(n)||n==="."||n===".."){N(new Error("invalid_operation"));return}if(n===$(y.path)){s(null);return}await L({action:"move",path:y.path,target:B(H(y.path)??t,n)})&&s(null)},p=(n,r)=>{if(n.target!==n.currentTarget)return!1;if((n.metaKey||n.ctrlKey)&&["c","x","v"].includes(n.key.toLowerCase()))return n.preventDefault(),n.key.toLowerCase()==="v"?v(r):V(r,n.key.toLowerCase()==="x"),!0;if(n.key==="F2")return n.preventDefault(),h(r),!0;if(n.key==="Delete"||n.metaKey&&n.key==="Backspace")return n.preventDefault(),x(r),!0;if(n.key==="ContextMenu"||n.shiftKey&&n.key==="F10"){n.preventDefault();const G=n.currentTarget.getBoundingClientRect();return k(r,G.left+20,G.top+24),!0}return!1},A=n=>{if(!F||F.daemonId!==C||F.root!==t||F.cwd!==f||c.current)return!1;const r=O(F.target.path,f),R=O(n,f);return R!==r&&!R.startsWith(`${r}/`)&&O(H(F.target.path)??t,f)!==R};return{strings:b,menu:d,setMenu:o,rename:y,setRename:s,name:m,setName:E,deleting:w,setDeleting:x,error:K,setError:_,busy:g,undo:l,setUndo:i,canPaste:a,copy:V,paste:v,key:p,startRename:h,commitRename:P,openMenu:k,copyPath:async n=>{try{await de(O(n.path,f))}catch(r){N(r)}},deleteItem:async()=>{w&&await L({action:"delete",path:w.path})&&x(null)},restore:async()=>{l&&await L({action:"restore",path:l.path,recoveryId:l.recoveryId})&&i(null)},isCut:n=>!!(T?.cut&&T.daemonId===C&&T.target.path===n),dropTarget:S,dragStart:(n,r)=>{if(!C||c.current){n.preventDefault();return}F={target:r,cut:!0,daemonId:C,root:t,cwd:f},n.dataTransfer.setData(W,r.path),n.dataTransfer.effectAllowed="copyMove",o(null)},dragEnd:()=>{F=null,M(null)},dragOver:(n,r)=>{!n.dataTransfer.types.includes(W)||!A(r)||(n.preventDefault(),n.stopPropagation(),n.dataTransfer.dropEffect=n.altKey?"copy":"move",M(r))},dragLeave:n=>{n.currentTarget.contains(n.relatedTarget)||M(null)},drop:(n,r)=>{n.preventDefault(),n.stopPropagation(),M(null),!(!n.dataTransfer.types.includes(W)||!A(r)||!F)&&L({action:n.altKey?"copy":"move",path:F.target.path,target:B(r,$(F.target.path))})}}}function Ie(t){return/\.(png|jpe?g|gif|webp|svg|ico)$/i.test(t)?we:/\.(tsx?|jsx?|json|css|html|py|rs|go|swift|ya?ml|sh)$/i.test(t)?ke:ye}function Oe({cwd:t,entries:f,error:j,loaded:b,loading:d,path:o,selectedPath:y,t:s,onListDirectory:m,onLoadChildren:E,onNewFolder:w,onOpenRemoteFile:x}){const l=Te(o,f,E),i=Re(o,t,async()=>{m(o),await l.refresh()}),K=u.useRef(null),[_,g]=u.useState(!1),[D,c]=u.useState(o),[S,M]=u.useState(y),[U,I]=u.useState();u.useEffect(()=>{c(o)},[o]),u.useEffect(()=>I(void 0),[o,f]),u.useEffect(()=>{M(y)},[y]);const C=(a,v)=>{a.isDirectory?l.expanded.has(v)?l.collapse(v):l.expand(v):(M(v),x(v,t))},N=a=>a?.focus(),L=(a,v,k)=>{if(a.stopPropagation(),i.key(a,{path:k,directory:v.isDirectory})||a.target instanceof HTMLInputElement)return;const h=Array.from(K.current?.querySelectorAll('[role="treeitem"]')??[]),P=h.indexOf(a.currentTarget);["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","Enter"," "].includes(a.key)&&a.preventDefault(),a.key==="ArrowUp"&&N(h[Math.max(0,P-1)]),a.key==="ArrowDown"&&N(h[Math.min(h.length-1,P+1)]),a.key==="Home"&&N(h[0]),a.key==="End"&&N(h.at(-1)),a.key==="ArrowRight"&&v.isDirectory&&(!l.expanded.has(k)||l.errors[k]?l.expand(k):N(a.currentTarget.querySelector('[role="treeitem"]'))),a.key==="ArrowLeft"&&(v.isDirectory&&l.expanded.has(k)?l.collapse(k):N(a.currentTarget.parentElement?.closest('[role="treeitem"]'))),(a.key==="Enter"||a.key===" ")&&C(v,k)},V=Y(f),q=(a,v,k)=>a.map((h,P)=>{const p=B(v,h.name),A=l.expanded.has(p),n=h.isDirectory?A?te:re:Ie(h.name);return e.jsxs("div",{role:"treeitem","aria-label":h.name,"aria-level":k+1,"aria-posinset":P+1,"aria-setsize":a.length,"aria-expanded":h.isDirectory?A:void 0,"aria-selected":S===p,"aria-busy":l.loading.has(p)||void 0,"data-path":p,className:"explorer-tree-item",tabIndex:U===p||!U&&k===0&&P===0?0:-1,onFocus:r=>{r.target===r.currentTarget&&I(p)},onKeyDown:r=>L(r,h,p),children:[e.jsxs("div",{className:"explorer-tree-row",draggable:!i.busy&&i.rename?.path!==p,"data-cut":i.isCut(p)||void 0,"data-drop":i.dropTarget===p||void 0,onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),N(r.currentTarget.parentElement),i.openMenu({path:p,directory:h.isDirectory},r.clientX,r.clientY)},onDragStart:r=>i.dragStart(r,{path:p,directory:h.isDirectory}),onDragEnd:i.dragEnd,onDragOver:r=>h.isDirectory&&i.dragOver(r,p),onDragLeave:i.dragLeave,onDrop:r=>h.isDirectory&&i.drop(r,p),style:{paddingLeft:8+k*14},title:p,onClick:r=>{N(r.currentTarget.parentElement),C(h,p)},children:[e.jsx("span",{className:"explorer-chevron","aria-hidden":"true",children:h.isDirectory&&(l.loading.has(p)?e.jsx(ee,{className:"explorer-spinner"}):A?e.jsx(me,{}):e.jsx(he,{}))}),e.jsx(n,{className:h.isDirectory?"explorer-folder-icon":"explorer-file-icon","aria-hidden":"true"}),e.jsx("span",{className:"explorer-entry-name",children:i.rename?.path===p?e.jsx("input",{className:"explorer-rename","aria-label":i.strings.name,autoFocus:!0,value:i.name,disabled:i.busy,onFocus:r=>r.target.select(),onClick:r=>r.stopPropagation(),onChange:r=>i.setName(r.target.value),onKeyDown:r=>{r.stopPropagation(),r.key==="Enter"&&(r.preventDefault(),i.commitRename()),r.key==="Escape"&&(r.preventDefault(),i.setRename(null))}}):h.name})]}),h.isDirectory&&A&&e.jsxs("div",{role:"group",className:"explorer-tree-group",style:{"--tree-guide-left":`${14+k*14}px`},children:[l.children[p]?q(l.children[p],p,k+1):null,l.errors[p]&&e.jsx("button",{className:"explorer-retry",type:"button",onClick:()=>{l.expand(p)},children:s.retry}),l.children[p]?.length===0&&e.jsx("p",{className:"explorer-empty",style:{paddingLeft:36+k*14},children:s.noFilesInDirectory})]})]},p)});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"explorer-heading",children:[e.jsx("h2",{children:s.fileTree}),e.jsxs("div",{className:"explorer-actions",children:[e.jsx("button",{className:"icon-button",title:s.newFolder,"aria-label":s.newFolder,onClick:w,type:"button",children:e.jsx(xe,{"aria-hidden":"true"})}),e.jsx("button",{className:"icon-button",title:s.refreshFiles,"aria-label":s.refreshFiles,disabled:d,onClick:()=>{m(o),l.refresh()},type:"button",children:d?e.jsx(ee,{className:"explorer-spinner","aria-hidden":"true"}):e.jsx(fe,{"aria-hidden":"true"})}),e.jsx("button",{className:"icon-button",title:s.parentFolder,"aria-label":s.parentFolder,disabled:!H(o),onClick:()=>m(H(o)??o),type:"button",children:e.jsx(pe,{"aria-hidden":"true"})})]})]}),e.jsxs("button",{type:"button",className:"explorer-root-path",onContextMenu:a=>{a.preventDefault(),i.openMenu({path:o,directory:!0},a.clientX,a.clientY)},onDragOver:a=>i.dragOver(a,o),onDragLeave:i.dragLeave,onDrop:a=>i.drop(a,o),"data-drop":i.dropTarget===o||void 0,title:o==="."?t:o,onClick:()=>{c(o),g(a=>!a)},children:[e.jsx(te,{"aria-hidden":"true"}),e.jsx("span",{children:$(o==="."?t:o)||o})]}),_&&e.jsx("form",{className:"explorer-path-form",onSubmit:a=>{a.preventDefault(),D.trim()&&(m(D.trim()),g(!1))},children:e.jsx("input",{autoFocus:!0,"aria-label":s.path,value:D,onChange:a=>c(a.target.value),onKeyDown:a=>{a.key==="Escape"&&g(!1)}})}),j&&e.jsx("p",{className:"empty-copy",role:"alert",children:j}),d&&e.jsx("p",{className:"explorer-empty",role:"status",children:s.loadingFiles}),e.jsx("div",{ref:K,role:"tree","aria-label":s.fileTree,className:"explorer-tree","aria-busy":d||i.busy,"data-drop":i.dropTarget===o||void 0,onContextMenu:a=>{a.preventDefault(),i.openMenu({path:o,directory:!0},a.clientX,a.clientY)},onDragOver:a=>i.dragOver(a,o),onDragLeave:i.dragLeave,onDrop:a=>i.drop(a,o),children:q(V,o,0)}),e.jsx(_e,{ops:i,root:o,onOpen:()=>i.menu&&x(i.menu.path,t)}),b&&!d&&!j&&f.length===0&&e.jsx("p",{className:"explorer-empty",children:s.noFilesInDirectory})]})}function $e({busy:t,onLoadChildren:f,cwd:j,directory:b,newDirName:d,remoteFile:o,t:y,onCreateDirectory:s,onListDirectory:m,onNewDirNameChange:E,onOpenRemoteFile:w}){const[x,l]=u.useState(!1);return e.jsx(e.Fragment,{children:e.jsxs("section",{className:"control-section files-explorer",children:[e.jsx(Oe,{cwd:j,selectedPath:o?.path,onLoadChildren:f,onNewFolder:()=>l(i=>!i),entries:b.entries,error:b.error,loaded:b.loaded,loading:b.loading,path:b.path,t:y,onListDirectory:m,onOpenRemoteFile:w}),x&&e.jsxs("div",{className:"field-row file-tree-create",children:[e.jsx("input",{value:d,onChange:i=>E(i.target.value),placeholder:y.newFolder,"aria-label":y.newFolder,autoFocus:!0,onKeyDown:i=>{i.key==="Escape"&&(l(!1),E("")),i.key==="Enter"&&d.trim()&&!t&&s()}}),e.jsxs("button",{className:"icon-text-button",onClick:s,type:"button",disabled:t||!d.trim(),children:[e.jsx(re,{"aria-hidden":"true"}),y.create]})]})]})})}export{$e as FilesControlPanel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as y,j as e,r as v,u as k,i as q,t as R}from"./index-ConcKf33.js";import{S as P,d as f,X as c,C as m,K as I}from"./App-CapuoJH2.js";const A=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M22 8c0-2.3-.8-4.3-2-6",key:"5bb3ad"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}],["path",{d:"M4 2C2.8 3.7 2 5.7 2 8",key:"tap9e0"}]],D=y("bell-ring",A);function N({activeApproval:n,activeQuestion:l,busy:a,questionAnswers:o,t:i,onCancelQuestion:h,onQuestionChoice:s,onRespondApproval:r,onRespondQuestion:x}){const u=!!(n||l);return e.jsxs(e.Fragment,{children:[u?null:e.jsxs("section",{className:"control-section",children:[e.jsx("h2",{children:i.pendingActions}),e.jsx("p",{className:"empty-copy",children:i.noPendingActions})]}),n?e.jsxs("section",{className:"attention-panel",children:[e.jsxs("div",{className:"attention-head",children:[e.jsx(P,{"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("h2",{children:i.approvalRequired}),e.jsx("p",{children:n.toolName})]})]}),e.jsx("p",{children:n.description}),e.jsx("pre",{children:f(n.input)}),e.jsxs("div",{className:"attention-actions",children:[e.jsxs("button",{type:"button",className:"danger-button",onClick:()=>r(!1),disabled:a,children:[e.jsx(c,{"aria-hidden":"true"}),i.deny]}),e.jsxs("button",{type:"button",className:"approve-button",onClick:()=>r(!0),disabled:a,children:[e.jsx(m,{"aria-hidden":"true"}),i.approve]})]})]}):null,l?e.jsxs("section",{className:"attention-panel",children:[e.jsxs("div",{className:"attention-head",children:[e.jsx(I,{"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("h2",{children:i.inputNeeded}),e.jsx("p",{children:i.notificationQuestionCount(l.questions.length)})]})]}),l.questions.map(d=>e.jsxs("div",{className:"question-block",children:[e.jsx("strong",{children:d.question}),e.jsx("div",{className:"choice-list",children:d.options.map(t=>{const b=(o[d.id]??[]).includes(t.label);return e.jsxs("button",{className:b?"selected":"",onClick:()=>s(d.id,t.label,d.multiSelect),type:"button",children:[e.jsx("span",{children:t.label}),t.description?e.jsx("small",{children:t.description}):null]},t.label)})})]},d.id)),e.jsxs("div",{className:"attention-actions",children:[e.jsxs("button",{type:"button",className:"danger-button",onClick:h,disabled:a,children:[e.jsx(c,{"aria-hidden":"true"}),i.cancel]}),e.jsxs("button",{type:"button",className:"approve-button",onClick:x,disabled:a,children:[e.jsx(m,{"aria-hidden":"true"}),i.submit]})]})]}):null]})}function M(n){const{activeApproval:l,activeQuestion:a,pendingCount:o,requestKey:i,sessions:h,t:s,errorText:r}=n,[x,u]=v.useState(null),d=o>0&&x!==i,t=()=>u(i),b=k(t,void 0,d),j=g=>{const p=h.find(C=>C.sessionId===g);return p?R(p):g};return o===0?null:q.createPortal(d?e.jsxs("div",{className:"global-pending-layer",children:[e.jsx("div",{className:"global-pending-backdrop","aria-hidden":"true",onClick:t}),e.jsxs("div",{className:"global-pending-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"global-pending-title",tabIndex:-1,ref:b,children:[e.jsxs("header",{className:"global-pending-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"global-pending-title",children:s.pendingActions}),e.jsx("p",{"aria-live":"polite",children:s.pendingActionCount(o)})]}),e.jsxs("div",{className:"global-pending-header-actions",children:[e.jsx("button",{className:"global-pending-clear",type:"button",onClick:n.onClearRequests,children:s.clearPendingRequests}),e.jsx("button",{className:"icon-button",type:"button","aria-label":s.close,title:s.close,onClick:t,children:e.jsx(c,{"aria-hidden":"true"})})]})]}),e.jsxs("div",{className:"global-pending-content",children:[l&&e.jsxs("section",{"data-pending-session":l.sessionId,children:[e.jsxs("div",{className:"global-pending-session-row",children:[e.jsx("p",{className:"global-pending-session",children:j(l.sessionId)}),e.jsx("button",{type:"button","aria-label":s.dismissPendingRequest,title:s.dismissPendingRequest,onClick:()=>n.onDismissRequest("approval",l.sessionId,l.requestId),children:e.jsx(c,{"aria-hidden":"true"})})]}),e.jsx(N,{...n,activeQuestion:null})]}),a&&e.jsxs("section",{"data-pending-session":a.sessionId,children:[e.jsxs("div",{className:"global-pending-session-row",children:[e.jsx("p",{className:"global-pending-session",children:j(a.sessionId)}),e.jsx("button",{type:"button","aria-label":s.dismissPendingRequest,title:s.dismissPendingRequest,onClick:()=>n.onDismissRequest("question",a.sessionId,a.requestId),children:e.jsx(c,{"aria-hidden":"true"})})]}),e.jsx(N,{...n,activeApproval:null})]}),r&&e.jsx("p",{role:"alert",className:"global-pending-error",children:r})]})]})]}):e.jsxs("div",{className:"global-pending-reminder",children:[e.jsxs("button",{type:"button",onClick:()=>u(null),"aria-label":s.pendingActionCount(o),title:s.pendingActions,children:[e.jsx(D,{"aria-hidden":"true"}),e.jsx("span",{children:s.pendingActionCount(o)})]}),e.jsx("button",{type:"button",className:"global-pending-reminder-clear",onClick:n.onClearRequests,"aria-label":s.clearPendingRequests,title:s.clearPendingRequests,children:e.jsx(c,{"aria-hidden":"true"})})]}),document.body)}export{M as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as N,r as p,e as E,l as A,u as L,i as C,j as a,k as M}from"./index-
|
|
1
|
+
import{c as N,r as p,e as E,l as A,u as L,i as C,j as a,k as M}from"./index-ConcKf33.js";import{u as P,r as B,f as D,I as O,L as S,a as T,X as W}from"./App-CapuoJH2.js";import{A as z,a as R}from"./arrow-right-ORILUMdJ.js";const V=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]],F=N("file-image",V);async function h(r){const i=new Image;i.crossOrigin="anonymous",i.src=r,await i.decode();const s=document.createElement("canvas");s.width=i.naturalWidth,s.height=i.naturalHeight;const d=s.getContext("2d");if(!d)throw new Error("Canvas unavailable");return d.drawImage(i,0,0),await new Promise((m,c)=>s.toBlob(t=>t?m(t):c(new Error("Image conversion failed")),"image/png"))}function U({request:r,onClose:i}){const[s,d]=p.useState(r.index),[m,c]=p.useState("idle"),t=r.images[s],{url:n,error:w,fail:y}=P(t.src,t.cwd,null),v=B(t.src),u=t.alt||D(v??t.src),x=E(A().language),o=x==="en"?{title:"Image viewer",previous:"Previous image",next:"Next image",copy:"Copy image",copied:"Image copied",failed:"Could not copy image",open:"Open original in tab",close:"Close",unavailable:"Image unavailable"}:x==="zh-TW"?{title:"圖片檢視器",previous:"上一張",next:"下一張",copy:"複製圖片",copied:"圖片已複製",failed:"圖片複製失敗",open:"在 Tab 開啟原檔案",close:"關閉",unavailable:"無法載入圖片"}:{title:"图片查看器",previous:"上一张",next:"下一张",copy:"复制图片",copied:"图片已复制",failed:"图片复制失败",open:"在 Tab 打开原文件",close:"关闭",unavailable:"无法加载图片"},b=L(i);p.useEffect(()=>{const e=document.getElementById("vibelet-workspace"),g=e?.inert;return e&&(e.inert=!0),()=>{e&&(e.inert=!!g)}},[]),p.useEffect(()=>c("idle"),[s]);const f=e=>d(g=>Math.max(0,Math.min(r.images.length-1,g+e))),j=async()=>{if(n)try{const e=M().writeClipboardImage;e?await e(new Uint8Array(await(await h(n)).arrayBuffer())):await navigator.clipboard.write([new ClipboardItem({"image/png":h(n)})]),c("copied")}catch{c("failed")}},l=(e,g,I,k=!1)=>a.jsx("button",{type:"button",className:"icon-button",title:e,"aria-label":e,onClick:I,disabled:k,children:g});return C.createPortal(a.jsx("div",{className:"image-viewer-backdrop",onClick:e=>{e.target===e.currentTarget&&i()},children:a.jsxs("div",{ref:b,className:"image-viewer",role:"dialog","aria-modal":"true","aria-label":o.title,tabIndex:-1,onKeyDown:e=>{(e.key==="ArrowLeft"||e.key==="ArrowRight")&&(e.preventDefault(),e.stopPropagation(),f(e.key==="ArrowLeft"?-1:1))},children:[a.jsxs("header",{className:"image-viewer-toolbar",children:[a.jsx("span",{className:"image-viewer-caption",title:u,children:u}),a.jsxs("span",{className:"image-viewer-count","aria-live":"polite",children:[s+1," / ",r.images.length]}),l(o.copy,a.jsx(T,{}),()=>{j()},!n||w),l(o.open,a.jsx(F,{}),()=>{i(),r.onOpen(v??t.src,t.cwd)}),l(o.close,a.jsx(W,{}),i)]}),a.jsxs("div",{className:"image-viewer-stage",children:[l(o.previous,a.jsx(R,{}),()=>f(-1),s===0),a.jsx("div",{className:"image-viewer-content",children:w?a.jsxs("p",{role:"status",children:[a.jsx(O,{}),o.unavailable]}):n?a.jsx("img",{src:n,alt:u,onError:y},t.src):a.jsx(S,{className:"session-running-icon","aria-label":o.title})}),l(o.next,a.jsx(z,{}),()=>f(1),s===r.images.length-1)]}),a.jsx("div",{className:"image-viewer-status",role:"status",children:m==="copied"?o.copied:m==="failed"?o.failed:""})]})}),document.body)}export{U as default};
|
package/dist/web/assets/{LanguageSettingsPanel-BQcBduA3.js → LanguageSettingsPanel-DTDvB4l2.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./index-
|
|
1
|
+
import{j as e}from"./index-ConcKf33.js";import{C as o}from"./ChipGroup-ImS6VTKx.js";import{F as r}from"./App-CapuoJH2.js";function m({language:s,t:a,onLanguageChange:l,showFeedback:n=!0}){return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"control-section compact-section",children:[e.jsx("h2",{children:a.language}),e.jsxs("label",{className:"field",children:[e.jsx("span",{children:a.displayLanguage}),e.jsx(o,{ariaLabel:a.displayLanguage,options:[{value:"system",label:a.followSystem},{value:"en",label:a.english},{value:"zh",label:a.chinese},{value:"zh-TW",label:a.traditionalChinese}],value:s,onChange:i=>l(i)})]})]}),n&&e.jsx(r,{language:s})]})}export{m as LanguageSettingsPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as ne,m as F,r as a,u as ae,i as oe,j as t}from"./index-
|
|
1
|
+
import{c as ne,m as F,r as a,u as ae,i as oe,j as t}from"./index-ConcKf33.js";import{j as H,X as le,e as E,g as K,S as ie,h as re}from"./App-CapuoJH2.js";import{F as ce}from"./folder-plus-DHw5YJHP.js";const de=[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]],ue=ne("bot",de),L="vibelet.web.recentCreations";function U(n){try{const s=JSON.parse(F().getItem(L)||"{}")[n];return Array.isArray(s)?s.filter(r=>typeof r.cwd=="string"&&["claude","codex"].includes(r.agent)&&Number.isFinite(r.createdAt)).slice(0,8):[]}catch{return[]}}function he(n,s){try{const r=JSON.parse(F().getItem(L)||"{}");r[n]=[s,...U(n).filter(c=>c.cwd!==s.cwd||c.agent!==s.agent)].slice(0,8),F().setItem(L,JSON.stringify(r))}catch{}}function we(n){const{t:s,device:r,onClose:c,onListDirectories:I}=n,o=s.newSession!=="New session",[l,w]=a.useState(n.cwd),[u,O]=a.useState(n.agent),[y,X]=a.useState(n.approvalMode),[p,C]=a.useState(n.model),[z,G]=a.useState(""),[S,P]=a.useState([]),[R,T]=a.useState(""),B=[{value:"normal",label:s.approvalNormal},{value:"plan",label:s.approvalPlan},{value:"acceptEdits",label:s.approvalEdits},{value:"autoApprove",label:s.approvalAuto}];a.useEffect(()=>{let e=!1;return P([]),T(""),n.onListModels(u).then(i=>{e||P(i)}).catch(()=>{e||T(o?"模型加载失败,请重新选择代理重试。":"Models unavailable. Select the agent again to retry.")}),()=>{e=!0}},[u,n.onListModels,o]);const[d,J]=a.useState([]),[h,V]=a.useState(-1),[x,k]=a.useState(!1),[W,g]=a.useState(""),[Q,D]=a.useState(!1),[N,_]=a.useState(!1),[m,v]=a.useState(null),M=a.useRef(null),Y=ae(c,M),[$]=a.useState(()=>U(r));a.useEffect(()=>{if(J([]),V(-1),g(""),!x||!n.connected)return;let e=!1;const i=/^(?:[a-z]:[\\/]|\\\\)/i.test(l)?l.replaceAll("\\","/"):l,b=i.lastIndexOf("/"),q=b<0?".":i.slice(0,b+1)||"/",te=i.slice(b+1).toLowerCase(),se=window.setTimeout(()=>{D(!0),I(q).then(f=>{e||J(f.filter(j=>j.isDirectory&&j.name.toLowerCase().startsWith(te)).map(j=>H(q,j.name)).slice(0,12))}).catch(f=>{e||g(String(f instanceof Error?f.message:f))}).finally(()=>{e||D(!1)})},180);return()=>{e=!0,window.clearTimeout(se),D(!1)}},[l,x,n.connected,I]);const A=e=>{w(e+(e.endsWith("/")?"":"/")),M.current?.focus()},Z=()=>{!l.trim()||!n.connected||N||(n.onCreate(l.trim(),u,{draft:z,approvalMode:y,model:p}),he(r,{cwd:l.trim(),agent:u,createdAt:Date.now()}),c())},ee=()=>{A(l||n.cwd||"/"),k(!0)};return oe.createPortal(t.jsxs("div",{className:"new-session-layer",children:[t.jsx("div",{className:"new-session-backdrop",onClick:c}),t.jsxs("div",{className:"new-session-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"new-session-title",ref:Y,tabIndex:-1,children:[t.jsxs("header",{children:[t.jsx("h2",{id:"new-session-title",children:s.newSession}),t.jsx("button",{type:"button",className:"icon-button","aria-label":s.close,onClick:c,children:t.jsx(le,{})})]}),t.jsxs("form",{onSubmit:e=>{e.preventDefault(),Z()},children:[t.jsx("div",{className:"new-session-agents",children:["claude","codex"].map(e=>t.jsxs("button",{type:"button","aria-pressed":u===e,onClick:()=>{O(e),C("")},children:[t.jsx(ue,{size:18}),e==="claude"?"Claude":"Codex"]},e))}),t.jsxs("div",{className:"new-session-path-field",children:[t.jsxs("label",{className:"new-session-field",children:[t.jsx("span",{children:s.workingDirectory}),t.jsxs("div",{className:"new-session-path-row",children:[t.jsx("input",{ref:M,value:l,"aria-label":s.workingDirectory,role:"combobox","aria-autocomplete":"list",spellCheck:!1,"aria-expanded":x&&d.length>0,"aria-controls":"new-session-paths","aria-activedescendant":h>=0?`new-session-path-${h}`:void 0,onFocus:()=>k(!0),onBlur:()=>k(!1),onChange:e=>w(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.keyCode===229||!d.length||(e.key==="ArrowDown"||e.key==="ArrowUp"?(e.preventDefault(),V(i=>i<0?e.key==="ArrowDown"?0:d.length-1:(i+(e.key==="ArrowDown"?1:-1)+d.length)%d.length)):(e.key==="Enter"||e.key==="Tab")&&h>=0&&(e.preventDefault(),A(d[h])))}}),t.jsx("button",{type:"button",className:"icon-button","aria-label":s.browseDirectories,title:s.browseDirectories,onMouseDown:e=>e.preventDefault(),onClick:()=>{ee()},children:t.jsx(E,{})}),t.jsx("button",{type:"button",className:"icon-button","aria-label":o?"新建文件夹":"New folder",title:o?"新建文件夹":"New folder",onMouseDown:e=>e.preventDefault(),onClick:()=>v(""),children:t.jsx(ce,{})})]})]}),x&&d.length>0&&t.jsx("div",{className:"new-session-paths",id:"new-session-paths",role:"listbox",children:d.map((e,i)=>t.jsxs("button",{type:"button",id:`new-session-path-${i}`,role:"option","aria-selected":h===i,onMouseDown:b=>b.preventDefault(),onClick:()=>A(e),title:e,children:[t.jsx(E,{size:14}),e]},e))}),t.jsx("small",{className:"new-session-path-status",role:W||R?"alert":"status",title:W||R,children:Q?s.loadingDirectories:" "})]}),m!==null&&t.jsxs("div",{className:"new-session-path-row",children:[t.jsx("input",{"aria-label":o?"文件夹名称":"Folder name",value:m,onChange:e=>v(e.target.value)}),t.jsx("button",{type:"button",disabled:N||!m.trim()||/[/\\]/.test(m),onClick:async()=>{_(!0),g("");try{const e=H(l,m.trim());await n.onCreateDirectory(e),w(e),v(null)}catch(e){g(String(e))}finally{_(!1)}},children:o?"创建文件夹":"Create folder"}),t.jsx("button",{type:"button",onClick:()=>v(null),children:s.close})]}),$.length>0&&t.jsxs("section",{className:"new-session-recent",children:[t.jsx("h3",{children:o?"最近创建":"Recent creations"}),$.map(e=>t.jsxs("button",{type:"button",title:e.cwd,onClick:()=>{w(e.cwd),O(e.agent),C("")},children:[t.jsx(E,{size:14}),t.jsx("span",{children:e.cwd}),t.jsx("small",{children:e.agent==="claude"?"Claude":"Codex"})]},e.cwd+e.agent))]}),t.jsxs("label",{className:"new-session-field",children:[t.jsx("span",{children:o?"初始消息(可选)":"Initial message (optional)"}),t.jsx("textarea",{value:z,onChange:e=>G(e.target.value),rows:3})]}),t.jsxs("div",{className:"new-session-options",children:[t.jsx(K,{icon:ie,label:B.find(e=>e.value===y)?.label??s.approvalMode,menuLabel:s.approvalMode,value:y,onSelect:X,options:B}),t.jsx(K,{icon:re,label:S.find(e=>e.value===p)?.label??(p||(o?"默认模型":"Default model")),menuLabel:o?"模型":"Model",value:p,onSelect:C,options:[...S.some(e=>e.value==="")?[]:[{value:"",label:o?"默认模型":"Default model"}],...S.map(e=>({value:e.value,label:e.label,description:e.desc}))]})]}),!n.connected&&t.jsx("p",{role:"status",children:o?"请先连接设备,再创建会话。":"Connect a device before creating a session."}),t.jsxs("footer",{children:[t.jsx("small",{children:o?"创建后自动发送初始消息":"The initial message is sent after creation"}),t.jsx("button",{type:"button",onClick:c,children:o?"取消":"Cancel"}),t.jsx("button",{className:"primary",type:"submit",disabled:!n.connected||!l.trim()||N,children:s.newSession})]})]})]})]}),document.body)}export{we as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as i,j as e}from"./index-
|
|
1
|
+
import{c as i,j as e}from"./index-ConcKf33.js";const r=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],d=i("bell",r);function h({notificationsBlocked:c,permission:s,settings:t,t:a,onToggleEnabled:n}){return e.jsxs("section",{className:"control-section compact-section",children:[e.jsx("h2",{children:a.notifications}),e.jsxs("label",{className:`toggle-field notification-toggle ${c?"disabled":""}`,children:[e.jsxs("span",{children:[e.jsx(d,{"aria-hidden":"true"}),a.browserAlerts]}),e.jsx("input",{type:"checkbox",role:"switch","aria-checked":t.enabled&&!c&&s==="granted",className:"settings-switch",checked:t.enabled&&!c&&s==="granted",disabled:c,onChange:l=>n(l.target.checked)})]}),c?e.jsx("p",{className:"empty-copy",children:a.notificationsBlocked}):null]})}export{h as NotificationSettingsPanel};
|
package/dist/web/assets/{TerminalControlPanel-BeAaO_xN.js → TerminalControlPanel-B7S_ebVy.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as q,_ as Z,r as T,j as w}from"./index-BH_ibxBN.js";import{B as J,X as W,D as Q}from"./App-DcLmCQZc.js";const tt=[["path",{d:"M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21",key:"g5wo59"}],["path",{d:"m5.082 11.09 8.828 8.828",key:"1wx5vj"}]],et=q("eraser",tt);var Y=(e=>(e[e.CURSOR_KEY_APPLICATION=0]="CURSOR_KEY_APPLICATION",e[e.KEYPAD_KEY_APPLICATION=1]="KEYPAD_KEY_APPLICATION",e[e.IGNORE_KEYPAD_WITH_NUMLOCK=2]="IGNORE_KEYPAD_WITH_NUMLOCK",e[e.ALT_ESC_PREFIX=3]="ALT_ESC_PREFIX",e[e.MODIFY_OTHER_KEYS_STATE_2=4]="MODIFY_OTHER_KEYS_STATE_2",e[e.KITTY_KEYBOARD_FLAGS=5]="KITTY_KEYBOARD_FLAGS",e))(Y||{}),$=(e=>(e[e.RELEASE=0]="RELEASE",e[e.PRESS=1]="PRESS",e[e.REPEAT=2]="REPEAT",e))($||{}),h=(e=>(e[e.UNIDENTIFIED=0]="UNIDENTIFIED",e[e.GRAVE=1]="GRAVE",e[e.BACKSLASH=2]="BACKSLASH",e[e.BRACKET_LEFT=3]="BRACKET_LEFT",e[e.BRACKET_RIGHT=4]="BRACKET_RIGHT",e[e.COMMA=5]="COMMA",e[e.ZERO=6]="ZERO",e[e.ONE=7]="ONE",e[e.TWO=8]="TWO",e[e.THREE=9]="THREE",e[e.FOUR=10]="FOUR",e[e.FIVE=11]="FIVE",e[e.SIX=12]="SIX",e[e.SEVEN=13]="SEVEN",e[e.EIGHT=14]="EIGHT",e[e.NINE=15]="NINE",e[e.EQUAL=16]="EQUAL",e[e.INTL_BACKSLASH=17]="INTL_BACKSLASH",e[e.INTL_RO=18]="INTL_RO",e[e.INTL_YEN=19]="INTL_YEN",e[e.A=20]="A",e[e.B=21]="B",e[e.C=22]="C",e[e.D=23]="D",e[e.E=24]="E",e[e.F=25]="F",e[e.G=26]="G",e[e.H=27]="H",e[e.I=28]="I",e[e.J=29]="J",e[e.K=30]="K",e[e.L=31]="L",e[e.M=32]="M",e[e.N=33]="N",e[e.O=34]="O",e[e.P=35]="P",e[e.Q=36]="Q",e[e.R=37]="R",e[e.S=38]="S",e[e.T=39]="T",e[e.U=40]="U",e[e.V=41]="V",e[e.W=42]="W",e[e.X=43]="X",e[e.Y=44]="Y",e[e.Z=45]="Z",e[e.MINUS=46]="MINUS",e[e.PERIOD=47]="PERIOD",e[e.QUOTE=48]="QUOTE",e[e.SEMICOLON=49]="SEMICOLON",e[e.SLASH=50]="SLASH",e[e.ALT_LEFT=51]="ALT_LEFT",e[e.ALT_RIGHT=52]="ALT_RIGHT",e[e.BACKSPACE=53]="BACKSPACE",e[e.CAPS_LOCK=54]="CAPS_LOCK",e[e.CONTEXT_MENU=55]="CONTEXT_MENU",e[e.CONTROL_LEFT=56]="CONTROL_LEFT",e[e.CONTROL_RIGHT=57]="CONTROL_RIGHT",e[e.ENTER=58]="ENTER",e[e.META_LEFT=59]="META_LEFT",e[e.META_RIGHT=60]="META_RIGHT",e[e.SHIFT_LEFT=61]="SHIFT_LEFT",e[e.SHIFT_RIGHT=62]="SHIFT_RIGHT",e[e.SPACE=63]="SPACE",e[e.TAB=64]="TAB",e[e.CONVERT=65]="CONVERT",e[e.KANA_MODE=66]="KANA_MODE",e[e.NON_CONVERT=67]="NON_CONVERT",e[e.DELETE=68]="DELETE",e[e.END=69]="END",e[e.HELP=70]="HELP",e[e.HOME=71]="HOME",e[e.INSERT=72]="INSERT",e[e.PAGE_DOWN=73]="PAGE_DOWN",e[e.PAGE_UP=74]="PAGE_UP",e[e.DOWN=75]="DOWN",e[e.LEFT=76]="LEFT",e[e.RIGHT=77]="RIGHT",e[e.UP=78]="UP",e[e.NUM_LOCK=79]="NUM_LOCK",e[e.KP_0=80]="KP_0",e[e.KP_1=81]="KP_1",e[e.KP_2=82]="KP_2",e[e.KP_3=83]="KP_3",e[e.KP_4=84]="KP_4",e[e.KP_5=85]="KP_5",e[e.KP_6=86]="KP_6",e[e.KP_7=87]="KP_7",e[e.KP_8=88]="KP_8",e[e.KP_9=89]="KP_9",e[e.KP_PLUS=90]="KP_PLUS",e[e.KP_BACKSPACE=91]="KP_BACKSPACE",e[e.KP_CLEAR=92]="KP_CLEAR",e[e.KP_CLEAR_ENTRY=93]="KP_CLEAR_ENTRY",e[e.KP_COMMA=94]="KP_COMMA",e[e.KP_PERIOD=95]="KP_PERIOD",e[e.KP_DIVIDE=96]="KP_DIVIDE",e[e.KP_ENTER=97]="KP_ENTER",e[e.KP_EQUAL=98]="KP_EQUAL",e[e.KP_MEMORY_ADD=99]="KP_MEMORY_ADD",e[e.KP_MEMORY_CLEAR=100]="KP_MEMORY_CLEAR",e[e.KP_MEMORY_RECALL=101]="KP_MEMORY_RECALL",e[e.KP_MEMORY_STORE=102]="KP_MEMORY_STORE",e[e.KP_MEMORY_SUBTRACT=103]="KP_MEMORY_SUBTRACT",e[e.KP_MULTIPLY=104]="KP_MULTIPLY",e[e.KP_PAREN_LEFT=105]="KP_PAREN_LEFT",e[e.KP_PAREN_RIGHT=106]="KP_PAREN_RIGHT",e[e.KP_MINUS=107]="KP_MINUS",e[e.KP_SEPARATOR=108]="KP_SEPARATOR",e[e.NUMPAD_UP=109]="NUMPAD_UP",e[e.NUMPAD_DOWN=110]="NUMPAD_DOWN",e[e.NUMPAD_RIGHT=111]="NUMPAD_RIGHT",e[e.NUMPAD_LEFT=112]="NUMPAD_LEFT",e[e.NUMPAD_BEGIN=113]="NUMPAD_BEGIN",e[e.NUMPAD_HOME=114]="NUMPAD_HOME",e[e.NUMPAD_END=115]="NUMPAD_END",e[e.NUMPAD_INSERT=116]="NUMPAD_INSERT",e[e.NUMPAD_DELETE=117]="NUMPAD_DELETE",e[e.NUMPAD_PAGE_UP=118]="NUMPAD_PAGE_UP",e[e.NUMPAD_PAGE_DOWN=119]="NUMPAD_PAGE_DOWN",e[e.ESCAPE=120]="ESCAPE",e[e.F1=121]="F1",e[e.F2=122]="F2",e[e.F3=123]="F3",e[e.F4=124]="F4",e[e.F5=125]="F5",e[e.F6=126]="F6",e[e.F7=127]="F7",e[e.F8=128]="F8",e[e.F9=129]="F9",e[e.F10=130]="F10",e[e.F11=131]="F11",e[e.F12=132]="F12",e[e.F13=133]="F13",e[e.F14=134]="F14",e[e.F15=135]="F15",e[e.F16=136]="F16",e[e.F17=137]="F17",e[e.F18=138]="F18",e[e.F19=139]="F19",e[e.F20=140]="F20",e[e.F21=141]="F21",e[e.F22=142]="F22",e[e.F23=143]="F23",e[e.F24=144]="F24",e[e.F25=145]="F25",e[e.FN_LOCK=146]="FN_LOCK",e[e.PRINT_SCREEN=147]="PRINT_SCREEN",e[e.SCROLL_LOCK=148]="SCROLL_LOCK",e[e.PAUSE=149]="PAUSE",e[e.BROWSER_BACK=150]="BROWSER_BACK",e[e.BROWSER_FAVORITES=151]="BROWSER_FAVORITES",e[e.BROWSER_FORWARD=152]="BROWSER_FORWARD",e[e.BROWSER_HOME=153]="BROWSER_HOME",e[e.BROWSER_REFRESH=154]="BROWSER_REFRESH",e[e.BROWSER_SEARCH=155]="BROWSER_SEARCH",e[e.BROWSER_STOP=156]="BROWSER_STOP",e[e.EJECT=157]="EJECT",e[e.LAUNCH_APP_1=158]="LAUNCH_APP_1",e[e.LAUNCH_APP_2=159]="LAUNCH_APP_2",e[e.LAUNCH_MAIL=160]="LAUNCH_MAIL",e[e.MEDIA_PLAY_PAUSE=161]="MEDIA_PLAY_PAUSE",e[e.MEDIA_SELECT=162]="MEDIA_SELECT",e[e.MEDIA_STOP=163]="MEDIA_STOP",e[e.MEDIA_TRACK_NEXT=164]="MEDIA_TRACK_NEXT",e[e.MEDIA_TRACK_PREVIOUS=165]="MEDIA_TRACK_PREVIOUS",e[e.POWER=166]="POWER",e[e.SLEEP=167]="SLEEP",e[e.AUDIO_VOLUME_DOWN=168]="AUDIO_VOLUME_DOWN",e[e.AUDIO_VOLUME_MUTE=169]="AUDIO_VOLUME_MUTE",e[e.AUDIO_VOLUME_UP=170]="AUDIO_VOLUME_UP",e[e.WAKE_UP=171]="WAKE_UP",e[e.COPY=172]="COPY",e[e.CUT=173]="CUT",e[e.PASTE=174]="PASTE",e))(h||{}),k=(e=>(e[e.NONE=0]="NONE",e[e.SHIFT=1]="SHIFT",e[e.CTRL=2]="CTRL",e[e.ALT=4]="ALT",e[e.SUPER=8]="SUPER",e[e.CAPSLOCK=16]="CAPSLOCK",e[e.NUMLOCK=32]="NUMLOCK",e))(k||{}),B=(e=>(e[e.NONE=0]="NONE",e[e.PARTIAL=1]="PARTIAL",e[e.FULL=2]="FULL",e))(B||{});const G=80;var b=(e=>(e[e.BOLD=1]="BOLD",e[e.ITALIC=2]="ITALIC",e[e.UNDERLINE=4]="UNDERLINE",e[e.STRIKETHROUGH=8]="STRIKETHROUGH",e[e.INVERSE=16]="INVERSE",e[e.INVISIBLE=32]="INVISIBLE",e[e.BLINK=64]="BLINK",e[e.FAINT=128]="FAINT",e))(b||{});class N{constructor(t){this.exports=t.exports,this.memory=this.exports.memory}createKeyEncoder(){return new st(this.exports)}createTerminal(t=80,i=24,s){return new it(this.exports,this.memory,t,i,s)}static async load(t){if(t)return N.loadFromPath(t);const i=new URL("/web/assets/ghostty-vt-DOMeXDrv.wasm",import.meta.url),s=[];if(i.protocol==="file:"){let o=i.pathname;o.match(/^\/[A-Za-z]:\//)&&(o=o.slice(1)),s.push(o)}s.push(i.href,"./ghostty-vt.wasm","/ghostty-vt.wasm");let r=null;for(const o of s)try{return await N.loadFromPath(o)}catch(n){r=n instanceof Error?n:new Error(String(n))}throw r||new Error("Failed to load Ghostty WASM")}static async loadFromPath(t){let i;if(typeof Bun<"u"&&typeof Bun.file=="function")try{const o=Bun.file(t);await o.exists()&&(i=await o.arrayBuffer())}catch{}if(!i)try{const o=await(await Z(async()=>{const{readFile:n}=await Promise.resolve().then(()=>St);return{readFile:n}},void 0)).readFile(t);i=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)}catch{}if(!i){const o=await fetch(t);if(!o.ok)throw new Error(`Failed to fetch WASM: ${o.status} ${o.statusText}`);if(i=await o.arrayBuffer(),i.byteLength===0)throw new Error(`WASM file is empty (0 bytes). Check path: ${t}`)}if(!i)throw new Error(`Could not load WASM from path: ${t}`);const s=await WebAssembly.compile(i),r=await WebAssembly.instantiate(s,{env:{log:(o,n)=>{const l=new Uint8Array(r.exports.memory.buffer,o,n);console.log("[ghostty-vt]",new TextDecoder().decode(l))}}});return new N(r)}}class st{constructor(t){this.encoder=0,this.exports=t;const i=this.exports.ghostty_wasm_alloc_opaque(),s=this.exports.ghostty_key_encoder_new(0,i);if(s!==0)throw new Error(`Failed to create key encoder: ${s}`);const r=new DataView(this.exports.memory.buffer);this.encoder=r.getUint32(i,!0),this.exports.ghostty_wasm_free_opaque(i)}setOption(t,i){const s=this.exports.ghostty_wasm_alloc_u8();new DataView(this.exports.memory.buffer).setUint8(s,typeof i=="boolean"?i?1:0:i),this.exports.ghostty_key_encoder_setopt(this.encoder,t,s),this.exports.ghostty_wasm_free_u8(s)}setKittyFlags(t){this.setOption(Y.KITTY_KEYBOARD_FLAGS,t)}encode(t){const i=this.exports.ghostty_wasm_alloc_opaque(),s=this.exports.ghostty_key_event_new(0,i);if(s!==0)throw new Error(`Failed to create key event: ${s}`);const r=new DataView(this.exports.memory.buffer),o=r.getUint32(i,!0);if(this.exports.ghostty_wasm_free_opaque(i),this.exports.ghostty_key_event_set_action(o,t.action),this.exports.ghostty_key_event_set_key(o,t.key),this.exports.ghostty_key_event_set_mods(o,t.mods),t.utf8){const p=new TextEncoder().encode(t.utf8),u=this.exports.ghostty_wasm_alloc_u8_array(p.length);new Uint8Array(this.exports.memory.buffer).set(p,u),this.exports.ghostty_key_event_set_utf8(o,u,p.length),this.exports.ghostty_wasm_free_u8_array(u,p.length)}const n=32,l=this.exports.ghostty_wasm_alloc_u8_array(n),a=this.exports.ghostty_wasm_alloc_usize(),c=this.exports.ghostty_key_encoder_encode(this.encoder,o,l,n,a);if(c!==0)throw this.exports.ghostty_wasm_free_u8_array(l,n),this.exports.ghostty_wasm_free_usize(a),this.exports.ghostty_key_event_free(o),new Error(`Failed to encode key: ${c}`);const d=r.getUint32(a,!0),m=new Uint8Array(this.exports.memory.buffer,l,d).slice();return this.exports.ghostty_wasm_free_u8_array(l,n),this.exports.ghostty_wasm_free_usize(a),this.exports.ghostty_key_event_free(o),m}dispose(){this.encoder&&(this.exports.ghostty_key_encoder_free(this.encoder),this.encoder=0)}}const j=class R{constructor(t,i,s=80,r=24,o){var n;if(this.viewportBufferPtr=0,this.viewportBufferSize=0,this.cellPool=[],this.graphemeBuffer=null,this.graphemeBufferPtr=0,this.exports=t,this.memory=i,this._cols=s,this._rows=r,o){const l=this.exports.ghostty_wasm_alloc_u8_array(G);if(l===0)throw new Error("Failed to allocate config (out of memory)");try{const a=new DataView(this.memory.buffer);let c=l;a.setUint32(c,o.scrollbackLimit??1e4,!0),c+=4,a.setUint32(c,o.fgColor??0,!0),c+=4,a.setUint32(c,o.bgColor??0,!0),c+=4,a.setUint32(c,o.cursorColor??0,!0),c+=4;for(let d=0;d<16;d++)a.setUint32(c,((n=o.palette)==null?void 0:n[d])??0,!0),c+=4;this.handle=this.exports.ghostty_terminal_new_with_config(s,r,l)}finally{this.exports.ghostty_wasm_free_u8_array(l,G)}}else this.handle=this.exports.ghostty_terminal_new(s,r);if(!this.handle)throw new Error("Failed to create terminal");this.initCellPool()}get cols(){return this._cols}get rows(){return this._rows}write(t){const i=typeof t=="string"?new TextEncoder().encode(t):t,s=this.exports.ghostty_wasm_alloc_u8_array(i.length);new Uint8Array(this.memory.buffer).set(i,s),this.exports.ghostty_terminal_write(this.handle,s,i.length),this.exports.ghostty_wasm_free_u8_array(s,i.length)}resize(t,i){t===this._cols&&i===this._rows||(this._cols=t,this._rows=i,this.exports.ghostty_terminal_resize(this.handle,t,i),this.invalidateBuffers(),this.initCellPool())}free(){this.viewportBufferPtr&&(this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=0),this.exports.ghostty_terminal_free(this.handle)}update(){return this.exports.ghostty_render_state_update(this.handle)}getCursor(){return this.update(),{x:this.exports.ghostty_render_state_get_cursor_x(this.handle),y:this.exports.ghostty_render_state_get_cursor_y(this.handle),viewportX:this.exports.ghostty_render_state_get_cursor_x(this.handle),viewportY:this.exports.ghostty_render_state_get_cursor_y(this.handle),visible:this.exports.ghostty_render_state_get_cursor_visible(this.handle),blinking:!1,style:"block"}}getColors(){const t=this.exports.ghostty_render_state_get_bg_color(this.handle),i=this.exports.ghostty_render_state_get_fg_color(this.handle);return{background:{r:t>>16&255,g:t>>8&255,b:t&255},foreground:{r:i>>16&255,g:i>>8&255,b:i&255},cursor:null}}isRowDirty(t){return this.exports.ghostty_render_state_is_row_dirty(this.handle,t)}markClean(){this.exports.ghostty_render_state_mark_clean(this.handle)}getViewport(){const t=this._cols*this._rows,i=t*R.CELL_SIZE;return(!this.viewportBufferPtr||this.viewportBufferSize<i)&&(this.viewportBufferPtr&&this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(i),this.viewportBufferSize=i),this.exports.ghostty_render_state_get_viewport(this.handle,this.viewportBufferPtr,t)<0?this.cellPool:(this.parseCellsIntoPool(this.viewportBufferPtr,t),this.cellPool)}getLine(t){if(t<0||t>=this._rows)return null;this.update();const i=this.getViewport(),s=t*this._cols;return i.slice(s,s+this._cols).map(r=>({...r}))}isDirty(){return this.update()!==B.NONE}needsFullRedraw(){return this.update()===B.FULL}clearDirty(){this.markClean()}isAlternateScreen(){return!!this.exports.ghostty_terminal_is_alternate_screen(this.handle)}hasBracketedPaste(){return this.getMode(2004,!1)}hasFocusEvents(){return this.getMode(1004,!1)}hasMouseTracking(){return this.exports.ghostty_terminal_has_mouse_tracking(this.handle)!==0}getDimensions(){return{cols:this._cols,rows:this._rows}}getScrollbackLength(){return this.exports.ghostty_terminal_get_scrollback_length(this.handle)}getScrollbackLine(t){const i=this._cols*R.CELL_SIZE;(!this.viewportBufferPtr||this.viewportBufferSize<i)&&(this.viewportBufferPtr&&this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(i),this.viewportBufferSize=i),this.update();const s=this.exports.ghostty_terminal_get_scrollback_line(this.handle,t,this.viewportBufferPtr,this._cols);if(s<0)return null;const r=[],o=this.memory.buffer,n=new Uint8Array(o,this.viewportBufferPtr,s*R.CELL_SIZE),l=new DataView(o,this.viewportBufferPtr,s*R.CELL_SIZE);for(let a=0;a<s;a++){const c=a*R.CELL_SIZE;r.push({codepoint:l.getUint32(c,!0),fg_r:n[c+4],fg_g:n[c+5],fg_b:n[c+6],bg_r:n[c+7],bg_g:n[c+8],bg_b:n[c+9],flags:n[c+10],width:n[c+11],hyperlink_id:l.getUint16(c+12,!0),grapheme_len:n[c+14]})}return r}isRowWrapped(t){return this.exports.ghostty_terminal_is_row_wrapped(this.handle,t)!==0}getHyperlinkUri(t){return null}hasResponse(){return this.exports.ghostty_terminal_has_response(this.handle)}readResponse(){if(!this.hasResponse())return null;const t=256,i=this.exports.ghostty_wasm_alloc_u8_array(t);try{const s=this.exports.ghostty_terminal_read_response(this.handle,i,t);if(s<=0)return null;const r=new Uint8Array(this.memory.buffer,i,s);return new TextDecoder().decode(r.slice())}finally{this.exports.ghostty_wasm_free_u8_array(i,t)}}getMode(t,i=!1){return this.exports.ghostty_terminal_get_mode(this.handle,t,i)!==0}initCellPool(){const t=this._cols*this._rows;if(this.cellPool.length<t)for(let i=this.cellPool.length;i<t;i++)this.cellPool.push({codepoint:0,fg_r:204,fg_g:204,fg_b:204,bg_r:0,bg_g:0,bg_b:0,flags:0,width:1,hyperlink_id:0,grapheme_len:0})}parseCellsIntoPool(t,i){const s=this.memory.buffer,r=new Uint8Array(s,t,i*R.CELL_SIZE),o=new DataView(s,t,i*R.CELL_SIZE);for(let n=0;n<i;n++){const l=n*R.CELL_SIZE,a=this.cellPool[n];a.codepoint=o.getUint32(l,!0),a.fg_r=r[l+4],a.fg_g=r[l+5],a.fg_b=r[l+6],a.bg_r=r[l+7],a.bg_g=r[l+8],a.bg_b=r[l+9],a.flags=r[l+10],a.width=r[l+11],a.hyperlink_id=o.getUint16(l+12,!0),a.grapheme_len=r[l+14]}}getGrapheme(t,i){this.graphemeBuffer||(this.graphemeBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(64),this.graphemeBuffer=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,16));const s=this.exports.ghostty_render_state_get_grapheme(this.handle,t,i,this.graphemeBufferPtr,16);if(s<0)return null;const r=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,s);return Array.from(r)}getGraphemeString(t,i){const s=this.getGrapheme(t,i);return!s||s.length===0?" ":String.fromCodePoint(...s)}getScrollbackGrapheme(t,i){this.graphemeBuffer||(this.graphemeBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(64),this.graphemeBuffer=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,16));const s=this.exports.ghostty_terminal_get_scrollback_grapheme(this.handle,t,i,this.graphemeBufferPtr,16);if(s<0)return null;const r=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,s);return Array.from(r)}getScrollbackGraphemeString(t,i){const s=this.getScrollbackGrapheme(t,i);return!s||s.length===0?" ":String.fromCodePoint(...s)}invalidateBuffers(){this.viewportBufferPtr&&(this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=0,this.viewportBufferSize=0)}};j.CELL_SIZE=16;let it=j;class L{constructor(){this.listeners=[],this.event=t=>(this.listeners.push(t),{dispose:()=>{const i=this.listeners.indexOf(t);i>=0&&this.listeners.splice(i,1)}})}fire(t){for(const i of this.listeners)i(t)}dispose(){this.listeners=[]}}class rt{constructor(t){this.bufferChangeEmitter=new L,this.terminal=t}get active(){const t=this.terminal.wasmTerm;return t?t.isAlternateScreen()?this.alternate:this.normal:this.normal}get normal(){return this._normalBuffer||(this._normalBuffer=new z(this.terminal,"normal")),this._normalBuffer}get alternate(){return this._alternateBuffer||(this._alternateBuffer=new z(this.terminal,"alternate")),this._alternateBuffer}get onBufferChange(){return this.bufferChangeEmitter.event}_fireBufferChange(t){this.bufferChangeEmitter.fire(t)}}class z{constructor(t,i){this.terminal=t,this.bufferType=i;const s={codepoint:0,fg_r:204,fg_g:204,fg_b:204,bg_r:0,bg_g:0,bg_b:0,flags:0,width:1,hyperlink_id:0,grapheme_len:0};this.nullCell=new U(s,0)}get type(){return this.bufferType}get cursorX(){const t=this.getWasmTerm();return t?t.getCursor().x:0}get cursorY(){const t=this.getWasmTerm();return t?t.getCursor().y:0}get viewportY(){return 0}get baseY(){return 0}get length(){const t=this.getWasmTerm();return t?this.bufferType==="alternate"?t.rows:t.getScrollbackLength()+t.rows:0}getLine(t){const i=this.getWasmTerm();if(!i||t<0||t>=this.length)return;const s=i.getScrollbackLength();let r,o,n;if(this.bufferType==="normal"&&t<s){const l=t;r=i.getScrollbackLine(l),n=!1}else o=this.bufferType==="normal"?t-s:t,r=i.getLine(o),n=i.isRowWrapped(o);if(r)return new ot(r,n,i.cols)}getNullCell(){return this.nullCell}getWasmTerm(){return this.terminal.wasmTerm}}class ot{constructor(t,i,s){this.cells=t,this._isWrapped=i,this._length=s}get length(){return this._length}get isWrapped(){return this._isWrapped}getCell(t){if(!(t<0||t>=this._length))return t>=this.cells.length?new U({codepoint:0,fg_r:204,fg_g:204,fg_b:204,bg_r:0,bg_g:0,bg_b:0,flags:0,width:1,hyperlink_id:0,grapheme_len:0},t):new U(this.cells[t],t)}translateToString(t=!1,i=0,s=this._length){const r=Math.max(0,Math.min(i,this._length)),o=Math.max(r,Math.min(s,this._length));let n="";for(let l=r;l<o;l++){const a=this.getCell(l);if(a){const c=a.getChars();n+=c}}return t&&(n=n.trimEnd()),n}}class U{constructor(t,i){this.cell=t,this.x=i}getChars(){const t=this.cell.codepoint;return t===0?"":t<0||t>1114111||t>=55296&&t<=57343?"�":String.fromCodePoint(t)}getCode(){return this.cell.codepoint}getWidth(){return this.cell.width}getFgColorMode(){return-1}getBgColorMode(){return-1}getFgColor(){return this.cell.fg_r<<16|this.cell.fg_g<<8|this.cell.fg_b}getBgColor(){return this.cell.bg_r<<16|this.cell.bg_g<<8|this.cell.bg_b}isBold(){return this.cell.flags&b.BOLD?1:0}isItalic(){return this.cell.flags&b.ITALIC?1:0}isUnderline(){return this.cell.flags&b.UNDERLINE?1:0}isStrikethrough(){return this.cell.flags&b.STRIKETHROUGH?1:0}isBlink(){return this.cell.flags&b.BLINK?1:0}isInverse(){return this.cell.flags&b.INVERSE?1:0}isInvisible(){return this.cell.flags&b.INVISIBLE?1:0}isFaint(){return this.cell.flags&b.FAINT?1:0}getHyperlinkId(){return this.cell.hyperlink_id}getCodepoint(){return this.cell.codepoint}isDim(){return(this.cell.flags&b.FAINT)!==0}}const nt={KeyA:h.A,KeyB:h.B,KeyC:h.C,KeyD:h.D,KeyE:h.E,KeyF:h.F,KeyG:h.G,KeyH:h.H,KeyI:h.I,KeyJ:h.J,KeyK:h.K,KeyL:h.L,KeyM:h.M,KeyN:h.N,KeyO:h.O,KeyP:h.P,KeyQ:h.Q,KeyR:h.R,KeyS:h.S,KeyT:h.T,KeyU:h.U,KeyV:h.V,KeyW:h.W,KeyX:h.X,KeyY:h.Y,KeyZ:h.Z,Digit1:h.ONE,Digit2:h.TWO,Digit3:h.THREE,Digit4:h.FOUR,Digit5:h.FIVE,Digit6:h.SIX,Digit7:h.SEVEN,Digit8:h.EIGHT,Digit9:h.NINE,Digit0:h.ZERO,Enter:h.ENTER,Escape:h.ESCAPE,Backspace:h.BACKSPACE,Tab:h.TAB,Space:h.SPACE,Minus:h.MINUS,Equal:h.EQUAL,BracketLeft:h.BRACKET_LEFT,BracketRight:h.BRACKET_RIGHT,Backslash:h.BACKSLASH,Semicolon:h.SEMICOLON,Quote:h.QUOTE,Backquote:h.GRAVE,Comma:h.COMMA,Period:h.PERIOD,Slash:h.SLASH,CapsLock:h.CAPS_LOCK,F1:h.F1,F2:h.F2,F3:h.F3,F4:h.F4,F5:h.F5,F6:h.F6,F7:h.F7,F8:h.F8,F9:h.F9,F10:h.F10,F11:h.F11,F12:h.F12,PrintScreen:h.PRINT_SCREEN,ScrollLock:h.SCROLL_LOCK,Pause:h.PAUSE,Insert:h.INSERT,Home:h.HOME,PageUp:h.PAGE_UP,Delete:h.DELETE,End:h.END,PageDown:h.PAGE_DOWN,ArrowRight:h.RIGHT,ArrowLeft:h.LEFT,ArrowDown:h.DOWN,ArrowUp:h.UP,NumLock:h.NUM_LOCK,NumpadDivide:h.KP_DIVIDE,NumpadMultiply:h.KP_MULTIPLY,NumpadSubtract:h.KP_MINUS,NumpadAdd:h.KP_PLUS,NumpadEnter:h.KP_ENTER,Numpad1:h.KP_1,Numpad2:h.KP_2,Numpad3:h.KP_3,Numpad4:h.KP_4,Numpad5:h.KP_5,Numpad6:h.KP_6,Numpad7:h.KP_7,Numpad8:h.KP_8,Numpad9:h.KP_9,Numpad0:h.KP_0,NumpadDecimal:h.KP_PERIOD,IntlBackslash:h.INTL_BACKSLASH,ContextMenu:h.CONTEXT_MENU,F13:h.F13,F14:h.F14,F15:h.F15,F16:h.F16,F17:h.F17,F18:h.F18,F19:h.F19,F20:h.F20,F21:h.F21,F22:h.F22,F23:h.F23,F24:h.F24};class lt{constructor(t,i,s,r,o,n,l){this.keydownListener=null,this.keypressListener=null,this.pasteListener=null,this.compositionStartListener=null,this.compositionUpdateListener=null,this.compositionEndListener=null,this.isComposing=!1,this.isDisposed=!1,this.encoder=t.createKeyEncoder(),this.container=i,this.onDataCallback=s,this.onBellCallback=r,this.onKeyCallback=o,this.customKeyEventHandler=n,this.getModeCallback=l,this.attach()}setCustomKeyEventHandler(t){this.customKeyEventHandler=t}attach(){typeof this.container.hasAttribute=="function"&&typeof this.container.setAttribute=="function"&&(this.container.hasAttribute("tabindex")||this.container.setAttribute("tabindex","0"),this.container.style&&(this.container.style.outline="none")),this.keydownListener=this.handleKeyDown.bind(this),this.container.addEventListener("keydown",this.keydownListener),this.pasteListener=this.handlePaste.bind(this),this.container.addEventListener("paste",this.pasteListener),this.compositionStartListener=this.handleCompositionStart.bind(this),this.container.addEventListener("compositionstart",this.compositionStartListener),this.compositionUpdateListener=this.handleCompositionUpdate.bind(this),this.container.addEventListener("compositionupdate",this.compositionUpdateListener),this.compositionEndListener=this.handleCompositionEnd.bind(this),this.container.addEventListener("compositionend",this.compositionEndListener)}mapKeyCode(t){return nt[t]??null}extractModifiers(t){let i=k.NONE;return t.shiftKey&&(i|=k.SHIFT),t.ctrlKey&&(i|=k.CTRL),t.altKey&&(i|=k.ALT),t.metaKey&&(i|=k.SUPER),i}isPrintableCharacter(t){return t.ctrlKey&&!t.altKey||t.altKey&&!t.ctrlKey||t.metaKey?!1:t.key.length===1}handleKeyDown(t){if(this.isDisposed||this.isComposing||t.isComposing||t.keyCode===229)return;if(this.onKeyCallback&&this.onKeyCallback({key:t.key,domEvent:t}),this.customKeyEventHandler&&this.customKeyEventHandler(t)){t.preventDefault();return}if((t.ctrlKey||t.metaKey)&&t.code==="KeyV"||t.metaKey&&t.code==="KeyC")return;if(this.isPrintableCharacter(t)){t.preventDefault(),this.onDataCallback(t.key);return}const i=this.mapKeyCode(t.code);if(i===null)return;const s=this.extractModifiers(t);if(s===k.NONE||s===k.SHIFT){let o=null;switch(i){case h.ENTER:o="\r";break;case h.TAB:o=" ";break;case h.BACKSPACE:o="";break;case h.ESCAPE:o="\x1B";break;case h.HOME:o="\x1B[H";break;case h.END:o="\x1B[F";break;case h.INSERT:o="\x1B[2~";break;case h.DELETE:o="\x1B[3~";break;case h.PAGE_UP:o="\x1B[5~";break;case h.PAGE_DOWN:o="\x1B[6~";break;case h.F1:o="\x1BOP";break;case h.F2:o="\x1BOQ";break;case h.F3:o="\x1BOR";break;case h.F4:o="\x1BOS";break;case h.F5:o="\x1B[15~";break;case h.F6:o="\x1B[17~";break;case h.F7:o="\x1B[18~";break;case h.F8:o="\x1B[19~";break;case h.F9:o="\x1B[20~";break;case h.F10:o="\x1B[21~";break;case h.F11:o="\x1B[23~";break;case h.F12:o="\x1B[24~";break}if(o!==null){t.preventDefault(),this.onDataCallback(o);return}}const r=$.PRESS;try{if(this.getModeCallback){const a=this.getModeCallback(1);this.encoder.setOption(Y.CURSOR_KEY_APPLICATION,a)}const o=t.key.length===1&&t.key.charCodeAt(0)<128?t.key.toLowerCase():void 0,n=this.encoder.encode({action:r,key:i,mods:s,utf8:o}),l=new TextDecoder().decode(n);t.preventDefault(),t.stopPropagation(),l.length>0&&this.onDataCallback(l)}catch(o){console.warn("Failed to encode key:",t.code,o)}}handlePaste(t){if(this.isDisposed)return;t.preventDefault(),t.stopPropagation();const i=t.clipboardData;if(!i){console.warn("No clipboard data available");return}const s=i.getData("text/plain");if(!s){console.warn("No text in clipboard");return}this.onDataCallback(s)}handleCompositionStart(t){this.isDisposed||(this.isComposing=!0)}handleCompositionUpdate(t){this.isDisposed}handleCompositionEnd(t){if(this.isDisposed)return;this.isComposing=!1;const i=t.data;if(i&&i.length>0&&this.onDataCallback(i),this.container&&this.container.childNodes)for(let s=this.container.childNodes.length-1;s>=0;s--){const r=this.container.childNodes[s];r.nodeType===3&&this.container.removeChild(r)}}dispose(){this.isDisposed||(this.keydownListener&&(this.container.removeEventListener("keydown",this.keydownListener),this.keydownListener=null),this.keypressListener&&(this.container.removeEventListener("keypress",this.keypressListener),this.keypressListener=null),this.pasteListener&&(this.container.removeEventListener("paste",this.pasteListener),this.pasteListener=null),this.compositionStartListener&&(this.container.removeEventListener("compositionstart",this.compositionStartListener),this.compositionStartListener=null),this.compositionUpdateListener&&(this.container.removeEventListener("compositionupdate",this.compositionUpdateListener),this.compositionUpdateListener=null),this.compositionEndListener&&(this.container.removeEventListener("compositionend",this.compositionEndListener),this.compositionEndListener=null),this.isDisposed=!0)}isActive(){return!this.isDisposed}}class at{constructor(t){this.terminal=t,this.providers=[],this.linkCache=new Map,this.scannedRows=new Set}registerProvider(t){this.providers.push(t),this.invalidateCache()}async getLinkAt(t,i){const s=this.terminal.buffer.active.getLine(i);if(!s||t<0||t>=s.length)return;const r=s.getCell(t);if(!r)return;const o=r.getHyperlinkId();if(o>0){const n=`h${o}`;if(this.linkCache.has(n))return this.linkCache.get(n)}if(this.scannedRows.has(i)||await this.scanRow(i),o>0){const n=`h${o}`,l=this.linkCache.get(n);if(l)return l}for(const n of this.linkCache.values())if(this.isPositionInLink(t,i,n))return n}async scanRow(t){this.scannedRows.add(t);const i=[];for(const s of this.providers){const r=await new Promise(o=>{s.provideLinks(t,o)});r&&i.push(...r)}for(const s of i)this.cacheLink(s)}cacheLink(t){const{start:i}=t.range,s=this.terminal.buffer.active.getLine(i.y);if(s){const l=s.getCell(i.x);if(!l){const{start:c,end:d}=t.range,m=`r${c.y}:${c.x}-${d.x}`;this.linkCache.set(m,t);return}const a=l.getHyperlinkId();if(a>0){this.linkCache.set(`h${a}`,t);return}}const{start:r,end:o}=t.range,n=`r${r.y}:${r.x}-${o.x}`;this.linkCache.set(n,t)}isPositionInLink(t,i,s){const{start:r,end:o}=s.range;return i<r.y||i>o.y?!1:r.y===o.y?t>=r.x&&t<=o.x:i===r.y?t>=r.x:i===o.y?t<=o.x:!0}invalidateCache(){this.linkCache.clear(),this.scannedRows.clear()}invalidateRows(t,i){for(let r=t;r<=i;r++)this.scannedRows.delete(r);const s=[];for(const[r,o]of this.linkCache.entries()){const{start:n,end:l}=o.range;(n.y>=t&&n.y<=i||l.y>=t&&l.y<=i||n.y<t&&l.y>i)&&s.push(r)}for(const r of s)this.linkCache.delete(r)}dispose(){var t;this.linkCache.clear(),this.scannedRows.clear();for(const i of this.providers)(t=i.dispose)==null||t.call(i);this.providers=[]}}class ht{constructor(t){this.terminal=t}provideLinks(t,i){const s=[],r=new Set,o=this.terminal.buffer.active.getLine(t);if(!o){i(void 0);return}for(let n=0;n<o.length;n++){const l=o.getCell(n);if(!l)continue;const a=l.getHyperlinkId();if(a===0||r.has(a))continue;r.add(a);const c=this.findLinkRange(a,t,n);if(!this.terminal.wasmTerm)continue;const d=this.terminal.wasmTerm.getHyperlinkUri(a);d&&s.push({text:d,range:c,activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(d,"_blank","noopener,noreferrer")}})}i(s.length>0?s:void 0)}findLinkRange(t,i,s){const r=this.terminal.buffer.active;let o=i,n=s;for(;n>0;){const d=r.getLine(o);if(!d)break;const m=d.getCell(n-1);if(!m||m.getHyperlinkId()!==t)break;n--}if(n===0&&o>0){let d=o-1;for(;d>=0;){const m=r.getLine(d);if(!m||m.length===0)break;const p=m.getCell(m.length-1);if(!p||p.getHyperlinkId()!==t)break;o=d,n=0;for(let u=m.length-1;u>=0;u--){const f=m.getCell(u);if(!f||f.getHyperlinkId()!==t){n=u+1;break}}if(n===0)d--;else break}}let l=i,a=s;const c=r.getLine(l);if(c){for(;a<c.length-1;){const d=c.getCell(a+1);if(!d||d.getHyperlinkId()!==t)break;a++}if(a===c.length-1){let d=l+1;const m=r.length;for(;d<m;){const p=r.getLine(d);if(!p||p.length===0)break;const u=p.getCell(0);if(!u||u.getHyperlinkId()!==t)break;l=d,a=0;for(let f=0;f<p.length;f++){const _=p.getCell(f);if(!_)break;if(_.getHyperlinkId()!==t){a=f-1;break}a=f}if(a===p.length-1)d++;else break}}}return{start:{x:n,y:o},end:{x:a,y:l}}}dispose(){}}const V=class O{constructor(t){this.terminal=t}provideLinks(t,i){const s=[],r=this.terminal.buffer.active.getLine(t);if(!r){i(void 0);return}const o=this.lineToText(r);O.URL_REGEX.lastIndex=0;let n=O.URL_REGEX.exec(o);for(;n!==null;){let l=n[0];const a=n.index;let c=n.index+l.length-1;const d=l.replace(O.TRAILING_PUNCTUATION,"");d.length<l.length&&(l=d,c=a+l.length-1),l.length>8&&s.push({text:l,range:{start:{x:a,y:t},end:{x:c,y:t}},activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(l,"_blank","noopener,noreferrer")}}),n=O.URL_REGEX.exec(o)}i(s.length>0?s:void 0)}lineToText(t){const i=[];for(let s=0;s<t.length;s++){const r=t.getCell(s);if(!r){i.push(" ");continue}const o=r.getCodepoint();o===0||o<32?i.push(" "):i.push(String.fromCodePoint(o))}return i.join("")}dispose(){}};V.URL_REGEX=/(?:https?:\/\/|mailto:|ftp:\/\/|ssh:\/\/|git:\/\/|tel:|magnet:|gemini:\/\/|gopher:\/\/|news:)[\w\-.~:\/?#@!$&*+,;=%]+/gi;V.TRAILING_PUNCTUATION=/[.,;!?)\]]+$/;let ct=V;const X={foreground:"#d4d4d4",background:"#1e1e1e",cursor:"#ffffff",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"};class dt{constructor(t,i={}){this.cursorVisible=!0,this.lastCursorPosition={x:0,y:0},this.lastViewportY=0,this.currentBuffer=null,this.currentSelectionCoords=null,this.hoveredHyperlinkId=0,this.previousHoveredHyperlinkId=0,this.hoveredLinkRange=null,this.previousHoveredLinkRange=null,this.canvas=t;const s=t.getContext("2d",{alpha:!0});if(!s)throw new Error("Failed to get 2D rendering context");this.ctx=s,this.fontSize=i.fontSize??15,this.fontFamily=i.fontFamily??"monospace",this.cursorStyle=i.cursorStyle??"block",this.cursorBlink=i.cursorBlink??!1,this.theme={...X,...i.theme},this.devicePixelRatio=i.devicePixelRatio??window.devicePixelRatio??1,this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite],this.metrics=this.measureFont(),this.cursorBlink&&this.startCursorBlink()}measureFont(){const t=document.createElement("canvas").getContext("2d");t.font=`${this.fontSize}px ${this.fontFamily}`;const i=t.measureText("M"),s=Math.ceil(i.width),r=i.actualBoundingBoxAscent||this.fontSize*.8,o=i.actualBoundingBoxDescent||this.fontSize*.2,n=Math.ceil(r+o)+2,l=Math.ceil(r)+1;return{width:s,height:n,baseline:l}}remeasureFont(){this.metrics=this.measureFont()}rgbToCSS(t,i,s){return`rgb(${t}, ${i}, ${s})`}resize(t,i){const s=t*this.metrics.width,r=i*this.metrics.height;this.canvas.style.width=`${s}px`,this.canvas.style.height=`${r}px`,this.canvas.width=s*this.devicePixelRatio,this.canvas.height=r*this.devicePixelRatio,this.ctx.scale(this.devicePixelRatio,this.devicePixelRatio),this.ctx.textBaseline="alphabetic",this.ctx.textAlign="left",this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,s,r)}render(t,i=!1,s=0,r,o=1){var n;this.currentBuffer=t;const l=t.getCursor(),a=t.getDimensions(),c=r?r.getScrollbackLength():0;(n=t.needsFullRedraw)!=null&&n.call(t)&&(i=!0),(this.canvas.width!==a.cols*this.metrics.width*this.devicePixelRatio||this.canvas.height!==a.rows*this.metrics.height*this.devicePixelRatio)&&(this.resize(a.cols,a.rows),i=!0),s!==this.lastViewportY&&(i=!0,this.lastViewportY=s);const d=l.x!==this.lastCursorPosition.x||l.y!==this.lastCursorPosition.y;if(d||this.cursorBlink){if(!i&&!t.isRowDirty(l.y)){const g=t.getLine(l.y);g&&this.renderLine(g,l.y,a.cols)}if(d&&this.lastCursorPosition.y!==l.y&&!i&&!t.isRowDirty(this.lastCursorPosition.y)){const g=t.getLine(this.lastCursorPosition.y);g&&this.renderLine(g,this.lastCursorPosition.y,a.cols)}}const m=this.selectionManager&&this.selectionManager.hasSelection(),p=new Set;if(this.currentSelectionCoords=m?this.selectionManager.getSelectionCoords():null,this.currentSelectionCoords){const g=this.currentSelectionCoords;for(let E=g.startRow;E<=g.endRow;E++)p.add(E)}if(this.selectionManager){const g=this.selectionManager.getDirtySelectionRows();if(g.size>0){for(const E of g)p.add(E);this.selectionManager.clearDirtySelectionRows()}}const u=new Set,f=this.hoveredHyperlinkId!==this.previousHoveredHyperlinkId,_=JSON.stringify(this.hoveredLinkRange)!==JSON.stringify(this.previousHoveredLinkRange);if(f){for(let g=0;g<a.rows;g++){let E=null;if(s>0)if(g<s&&r){const y=c-Math.floor(s)+g;E=r.getScrollbackLine(y)}else{const y=g-Math.floor(s);E=t.getLine(y)}else E=t.getLine(g);if(E){for(const y of E)if(y.hyperlink_id===this.hoveredHyperlinkId||y.hyperlink_id===this.previousHoveredHyperlinkId){u.add(g);break}}}this.previousHoveredHyperlinkId=this.hoveredHyperlinkId}if(_){if(this.previousHoveredLinkRange)for(let g=this.previousHoveredLinkRange.startY;g<=this.previousHoveredLinkRange.endY;g++)u.add(g);if(this.hoveredLinkRange)for(let g=this.hoveredLinkRange.startY;g<=this.hoveredLinkRange.endY;g++)u.add(g);this.previousHoveredLinkRange=this.hoveredLinkRange}const v=new Set;for(let g=0;g<a.rows;g++)(s>0||i||t.isRowDirty(g)||p.has(g)||u.has(g))&&(v.add(g),g>0&&v.add(g-1),g<a.rows-1&&v.add(g+1));for(let g=0;g<a.rows;g++){if(!v.has(g))continue;let E=null;if(s>0)if(g<s&&r){const y=c-Math.floor(s)+g;E=r.getScrollbackLine(y)}else{const y=s>0?g-Math.floor(s):g;E=t.getLine(y)}else E=t.getLine(g);E&&this.renderLine(E,g,a.cols)}s===0&&l.visible&&this.cursorVisible&&this.renderCursor(l.x,l.y),r&&o>0&&this.renderScrollbar(s,c,a.rows,o),this.lastCursorPosition={x:l.x,y:l.y},t.clearDirty()}renderLine(t,i,s){const r=i*this.metrics.height;this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,r,s*this.metrics.width,this.metrics.height);for(let o=0;o<t.length;o++){const n=t[o];n.width!==0&&this.renderCellBackground(n,o,i)}for(let o=0;o<t.length;o++){const n=t[o];n.width!==0&&this.renderCellText(n,o,i)}}renderCellBackground(t,i,s){const r=i*this.metrics.width,o=s*this.metrics.height,n=this.metrics.width*t.width;if(this.isInSelection(i,s)){this.ctx.fillStyle=this.theme.selectionBackground,this.ctx.fillRect(r,o,n,this.metrics.height);return}let l=t.bg_r,a=t.bg_g,c=t.bg_b;t.flags&b.INVERSE&&(l=t.fg_r,a=t.fg_g,c=t.fg_b),l===0&&a===0&&c===0||(this.ctx.fillStyle=this.rgbToCSS(l,a,c),this.ctx.fillRect(r,o,n,this.metrics.height))}renderCellText(t,i,s){var r;const o=i*this.metrics.width,n=s*this.metrics.height,l=this.metrics.width*t.width;if(t.flags&b.INVISIBLE)return;const a=this.isInSelection(i,s);let c="";if(t.flags&b.ITALIC&&(c+="italic "),t.flags&b.BOLD&&(c+="bold "),this.ctx.font=`${c}${this.fontSize}px ${this.fontFamily}`,a)this.ctx.fillStyle=this.theme.selectionForeground;else{let u=t.fg_r,f=t.fg_g,_=t.fg_b;t.flags&b.INVERSE&&(u=t.bg_r,f=t.bg_g,_=t.bg_b),this.ctx.fillStyle=this.rgbToCSS(u,f,_)}t.flags&b.FAINT&&(this.ctx.globalAlpha=.5);const d=o,m=n+this.metrics.baseline;let p;if(t.grapheme_len>0&&(r=this.currentBuffer)!=null&&r.getGraphemeString?p=this.currentBuffer.getGraphemeString(s,i):p=String.fromCodePoint(t.codepoint||32),this.ctx.fillText(p,d,m),t.flags&b.FAINT&&(this.ctx.globalAlpha=1),t.flags&b.UNDERLINE){const u=n+this.metrics.baseline+2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,u),this.ctx.lineTo(o+l,u),this.ctx.stroke()}if(t.flags&b.STRIKETHROUGH){const u=n+this.metrics.height/2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,u),this.ctx.lineTo(o+l,u),this.ctx.stroke()}if(t.hyperlink_id>0&&t.hyperlink_id===this.hoveredHyperlinkId){const u=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,u),this.ctx.lineTo(o+l,u),this.ctx.stroke()}if(this.hoveredLinkRange){const u=this.hoveredLinkRange;if(s===u.startY&&i>=u.startX&&(s<u.endY||i<=u.endX)||s>u.startY&&s<u.endY||s===u.endY&&i<=u.endX&&(s>u.startY||i>=u.startX)){const f=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,f),this.ctx.lineTo(o+l,f),this.ctx.stroke()}}}renderCursor(t,i){const s=t*this.metrics.width,r=i*this.metrics.height;switch(this.ctx.fillStyle=this.theme.cursor,this.cursorStyle){case"block":this.ctx.fillRect(s,r,this.metrics.width,this.metrics.height);break;case"underline":const o=Math.max(2,Math.floor(this.metrics.height*.15));this.ctx.fillRect(s,r+this.metrics.height-o,this.metrics.width,o);break;case"bar":const n=Math.max(2,Math.floor(this.metrics.width*.15));this.ctx.fillRect(s,r,n,this.metrics.height);break}}startCursorBlink(){this.cursorBlinkInterval=window.setInterval(()=>{this.cursorVisible=!this.cursorVisible},530)}stopCursorBlink(){this.cursorBlinkInterval!==void 0&&(clearInterval(this.cursorBlinkInterval),this.cursorBlinkInterval=void 0),this.cursorVisible=!0}setTheme(t){this.theme={...X,...t},this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite]}setFontSize(t){this.fontSize=t,this.metrics=this.measureFont()}setFontFamily(t){this.fontFamily=t,this.metrics=this.measureFont()}setCursorStyle(t){this.cursorStyle=t}setCursorBlink(t){t&&!this.cursorBlink?(this.cursorBlink=!0,this.startCursorBlink()):!t&&this.cursorBlink&&(this.cursorBlink=!1,this.stopCursorBlink())}renderScrollbar(t,i,s,r=1){const o=this.ctx,n=this.canvas.height/this.devicePixelRatio,l=this.canvas.width/this.devicePixelRatio,a=8,c=l-a-4,d=4,m=n-d*2;if(o.fillStyle=this.theme.background,o.fillRect(c-2,0,a+6,n),r<=0||i===0)return;const p=i+s,u=Math.max(20,s/p*m),f=t/i,_=d+(m-u)*(1-f);o.fillStyle=`rgba(128, 128, 128, ${.1*r})`,o.fillRect(c,d,a,m);const v=t>0?.5:.3;o.fillStyle=`rgba(128, 128, 128, ${v*r})`,o.fillRect(c,_,a,u)}getMetrics(){return{...this.metrics}}getCanvas(){return this.canvas}setSelectionManager(t){this.selectionManager=t}isInSelection(t,i){const s=this.currentSelectionCoords;if(!s)return!1;const{startCol:r,startRow:o,endCol:n,endRow:l}=s;return o===l?i===o&&t>=r&&t<=n:i===o?t>=r:i===l?t<=n:i>o&&i<l}setHoveredHyperlinkId(t){this.hoveredHyperlinkId=t}setHoveredLinkRange(t){this.hoveredLinkRange=t}get charWidth(){return this.metrics.width}get charHeight(){return this.metrics.height}clear(){this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}dispose(){this.stopCursorBlink()}}const H=class A{constructor(t,i,s,r){this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.mouseDownTarget=null,this.dirtySelectionRows=new Set,this.selectionChangedEmitter=new L,this.boundMouseUpHandler=null,this.boundContextMenuHandler=null,this.boundClickHandler=null,this.boundDocumentMouseMoveHandler=null,this.autoScrollInterval=null,this.autoScrollDirection=0,this.terminal=t,this.renderer=i,this.wasmTerm=s,this.textarea=r,this.attachEventListeners()}getViewportY(){const t=typeof this.terminal.getViewportY=="function"?this.terminal.getViewportY():this.terminal.viewportY||0;return Math.max(0,Math.floor(t))}viewportRowToAbsolute(t){const i=this.wasmTerm.getScrollbackLength(),s=this.getViewportY();return i+t-s}absoluteRowToViewport(t){const i=this.wasmTerm.getScrollbackLength(),s=this.getViewportY();return t-i+s}getSelection(){if(!this.selectionStart||!this.selectionEnd)return"";let{col:t,absoluteRow:i}=this.selectionStart,{col:s,absoluteRow:r}=this.selectionEnd;(i>r||i===r&&t>s)&&([t,s]=[s,t],[i,r]=[r,i]);const o=this.wasmTerm.getScrollbackLength();let n="";for(let l=i;l<=r;l++){let a=null;if(l<o)a=this.wasmTerm.getScrollbackLine(l);else{const u=l-o;a=this.wasmTerm.getLine(u)}if(!a)continue;let c=-1;const d=l===i?t:0,m=l===r?s:a.length-1;let p="";for(let u=d;u<=m;u++){const f=a[u];if(f&&f.codepoint!==0){let _;if(f.grapheme_len>0)if(l<o)_=this.wasmTerm.getScrollbackGraphemeString(l,u);else{const v=l-o;_=this.wasmTerm.getGraphemeString(v,u)}else _=String.fromCodePoint(f.codepoint);p+=_,_.trim()&&(c=p.length)}else p+=" "}c>=0?p=p.substring(0,c):p="",n+=p,l<r&&(n+=`
|
|
1
|
+
import{c as q,_ as Z,r as T,j as w}from"./index-ConcKf33.js";import{z as J,X as W,B as Q}from"./App-CapuoJH2.js";const tt=[["path",{d:"M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21",key:"g5wo59"}],["path",{d:"m5.082 11.09 8.828 8.828",key:"1wx5vj"}]],et=q("eraser",tt);var Y=(e=>(e[e.CURSOR_KEY_APPLICATION=0]="CURSOR_KEY_APPLICATION",e[e.KEYPAD_KEY_APPLICATION=1]="KEYPAD_KEY_APPLICATION",e[e.IGNORE_KEYPAD_WITH_NUMLOCK=2]="IGNORE_KEYPAD_WITH_NUMLOCK",e[e.ALT_ESC_PREFIX=3]="ALT_ESC_PREFIX",e[e.MODIFY_OTHER_KEYS_STATE_2=4]="MODIFY_OTHER_KEYS_STATE_2",e[e.KITTY_KEYBOARD_FLAGS=5]="KITTY_KEYBOARD_FLAGS",e))(Y||{}),$=(e=>(e[e.RELEASE=0]="RELEASE",e[e.PRESS=1]="PRESS",e[e.REPEAT=2]="REPEAT",e))($||{}),h=(e=>(e[e.UNIDENTIFIED=0]="UNIDENTIFIED",e[e.GRAVE=1]="GRAVE",e[e.BACKSLASH=2]="BACKSLASH",e[e.BRACKET_LEFT=3]="BRACKET_LEFT",e[e.BRACKET_RIGHT=4]="BRACKET_RIGHT",e[e.COMMA=5]="COMMA",e[e.ZERO=6]="ZERO",e[e.ONE=7]="ONE",e[e.TWO=8]="TWO",e[e.THREE=9]="THREE",e[e.FOUR=10]="FOUR",e[e.FIVE=11]="FIVE",e[e.SIX=12]="SIX",e[e.SEVEN=13]="SEVEN",e[e.EIGHT=14]="EIGHT",e[e.NINE=15]="NINE",e[e.EQUAL=16]="EQUAL",e[e.INTL_BACKSLASH=17]="INTL_BACKSLASH",e[e.INTL_RO=18]="INTL_RO",e[e.INTL_YEN=19]="INTL_YEN",e[e.A=20]="A",e[e.B=21]="B",e[e.C=22]="C",e[e.D=23]="D",e[e.E=24]="E",e[e.F=25]="F",e[e.G=26]="G",e[e.H=27]="H",e[e.I=28]="I",e[e.J=29]="J",e[e.K=30]="K",e[e.L=31]="L",e[e.M=32]="M",e[e.N=33]="N",e[e.O=34]="O",e[e.P=35]="P",e[e.Q=36]="Q",e[e.R=37]="R",e[e.S=38]="S",e[e.T=39]="T",e[e.U=40]="U",e[e.V=41]="V",e[e.W=42]="W",e[e.X=43]="X",e[e.Y=44]="Y",e[e.Z=45]="Z",e[e.MINUS=46]="MINUS",e[e.PERIOD=47]="PERIOD",e[e.QUOTE=48]="QUOTE",e[e.SEMICOLON=49]="SEMICOLON",e[e.SLASH=50]="SLASH",e[e.ALT_LEFT=51]="ALT_LEFT",e[e.ALT_RIGHT=52]="ALT_RIGHT",e[e.BACKSPACE=53]="BACKSPACE",e[e.CAPS_LOCK=54]="CAPS_LOCK",e[e.CONTEXT_MENU=55]="CONTEXT_MENU",e[e.CONTROL_LEFT=56]="CONTROL_LEFT",e[e.CONTROL_RIGHT=57]="CONTROL_RIGHT",e[e.ENTER=58]="ENTER",e[e.META_LEFT=59]="META_LEFT",e[e.META_RIGHT=60]="META_RIGHT",e[e.SHIFT_LEFT=61]="SHIFT_LEFT",e[e.SHIFT_RIGHT=62]="SHIFT_RIGHT",e[e.SPACE=63]="SPACE",e[e.TAB=64]="TAB",e[e.CONVERT=65]="CONVERT",e[e.KANA_MODE=66]="KANA_MODE",e[e.NON_CONVERT=67]="NON_CONVERT",e[e.DELETE=68]="DELETE",e[e.END=69]="END",e[e.HELP=70]="HELP",e[e.HOME=71]="HOME",e[e.INSERT=72]="INSERT",e[e.PAGE_DOWN=73]="PAGE_DOWN",e[e.PAGE_UP=74]="PAGE_UP",e[e.DOWN=75]="DOWN",e[e.LEFT=76]="LEFT",e[e.RIGHT=77]="RIGHT",e[e.UP=78]="UP",e[e.NUM_LOCK=79]="NUM_LOCK",e[e.KP_0=80]="KP_0",e[e.KP_1=81]="KP_1",e[e.KP_2=82]="KP_2",e[e.KP_3=83]="KP_3",e[e.KP_4=84]="KP_4",e[e.KP_5=85]="KP_5",e[e.KP_6=86]="KP_6",e[e.KP_7=87]="KP_7",e[e.KP_8=88]="KP_8",e[e.KP_9=89]="KP_9",e[e.KP_PLUS=90]="KP_PLUS",e[e.KP_BACKSPACE=91]="KP_BACKSPACE",e[e.KP_CLEAR=92]="KP_CLEAR",e[e.KP_CLEAR_ENTRY=93]="KP_CLEAR_ENTRY",e[e.KP_COMMA=94]="KP_COMMA",e[e.KP_PERIOD=95]="KP_PERIOD",e[e.KP_DIVIDE=96]="KP_DIVIDE",e[e.KP_ENTER=97]="KP_ENTER",e[e.KP_EQUAL=98]="KP_EQUAL",e[e.KP_MEMORY_ADD=99]="KP_MEMORY_ADD",e[e.KP_MEMORY_CLEAR=100]="KP_MEMORY_CLEAR",e[e.KP_MEMORY_RECALL=101]="KP_MEMORY_RECALL",e[e.KP_MEMORY_STORE=102]="KP_MEMORY_STORE",e[e.KP_MEMORY_SUBTRACT=103]="KP_MEMORY_SUBTRACT",e[e.KP_MULTIPLY=104]="KP_MULTIPLY",e[e.KP_PAREN_LEFT=105]="KP_PAREN_LEFT",e[e.KP_PAREN_RIGHT=106]="KP_PAREN_RIGHT",e[e.KP_MINUS=107]="KP_MINUS",e[e.KP_SEPARATOR=108]="KP_SEPARATOR",e[e.NUMPAD_UP=109]="NUMPAD_UP",e[e.NUMPAD_DOWN=110]="NUMPAD_DOWN",e[e.NUMPAD_RIGHT=111]="NUMPAD_RIGHT",e[e.NUMPAD_LEFT=112]="NUMPAD_LEFT",e[e.NUMPAD_BEGIN=113]="NUMPAD_BEGIN",e[e.NUMPAD_HOME=114]="NUMPAD_HOME",e[e.NUMPAD_END=115]="NUMPAD_END",e[e.NUMPAD_INSERT=116]="NUMPAD_INSERT",e[e.NUMPAD_DELETE=117]="NUMPAD_DELETE",e[e.NUMPAD_PAGE_UP=118]="NUMPAD_PAGE_UP",e[e.NUMPAD_PAGE_DOWN=119]="NUMPAD_PAGE_DOWN",e[e.ESCAPE=120]="ESCAPE",e[e.F1=121]="F1",e[e.F2=122]="F2",e[e.F3=123]="F3",e[e.F4=124]="F4",e[e.F5=125]="F5",e[e.F6=126]="F6",e[e.F7=127]="F7",e[e.F8=128]="F8",e[e.F9=129]="F9",e[e.F10=130]="F10",e[e.F11=131]="F11",e[e.F12=132]="F12",e[e.F13=133]="F13",e[e.F14=134]="F14",e[e.F15=135]="F15",e[e.F16=136]="F16",e[e.F17=137]="F17",e[e.F18=138]="F18",e[e.F19=139]="F19",e[e.F20=140]="F20",e[e.F21=141]="F21",e[e.F22=142]="F22",e[e.F23=143]="F23",e[e.F24=144]="F24",e[e.F25=145]="F25",e[e.FN_LOCK=146]="FN_LOCK",e[e.PRINT_SCREEN=147]="PRINT_SCREEN",e[e.SCROLL_LOCK=148]="SCROLL_LOCK",e[e.PAUSE=149]="PAUSE",e[e.BROWSER_BACK=150]="BROWSER_BACK",e[e.BROWSER_FAVORITES=151]="BROWSER_FAVORITES",e[e.BROWSER_FORWARD=152]="BROWSER_FORWARD",e[e.BROWSER_HOME=153]="BROWSER_HOME",e[e.BROWSER_REFRESH=154]="BROWSER_REFRESH",e[e.BROWSER_SEARCH=155]="BROWSER_SEARCH",e[e.BROWSER_STOP=156]="BROWSER_STOP",e[e.EJECT=157]="EJECT",e[e.LAUNCH_APP_1=158]="LAUNCH_APP_1",e[e.LAUNCH_APP_2=159]="LAUNCH_APP_2",e[e.LAUNCH_MAIL=160]="LAUNCH_MAIL",e[e.MEDIA_PLAY_PAUSE=161]="MEDIA_PLAY_PAUSE",e[e.MEDIA_SELECT=162]="MEDIA_SELECT",e[e.MEDIA_STOP=163]="MEDIA_STOP",e[e.MEDIA_TRACK_NEXT=164]="MEDIA_TRACK_NEXT",e[e.MEDIA_TRACK_PREVIOUS=165]="MEDIA_TRACK_PREVIOUS",e[e.POWER=166]="POWER",e[e.SLEEP=167]="SLEEP",e[e.AUDIO_VOLUME_DOWN=168]="AUDIO_VOLUME_DOWN",e[e.AUDIO_VOLUME_MUTE=169]="AUDIO_VOLUME_MUTE",e[e.AUDIO_VOLUME_UP=170]="AUDIO_VOLUME_UP",e[e.WAKE_UP=171]="WAKE_UP",e[e.COPY=172]="COPY",e[e.CUT=173]="CUT",e[e.PASTE=174]="PASTE",e))(h||{}),k=(e=>(e[e.NONE=0]="NONE",e[e.SHIFT=1]="SHIFT",e[e.CTRL=2]="CTRL",e[e.ALT=4]="ALT",e[e.SUPER=8]="SUPER",e[e.CAPSLOCK=16]="CAPSLOCK",e[e.NUMLOCK=32]="NUMLOCK",e))(k||{}),B=(e=>(e[e.NONE=0]="NONE",e[e.PARTIAL=1]="PARTIAL",e[e.FULL=2]="FULL",e))(B||{});const z=80;var b=(e=>(e[e.BOLD=1]="BOLD",e[e.ITALIC=2]="ITALIC",e[e.UNDERLINE=4]="UNDERLINE",e[e.STRIKETHROUGH=8]="STRIKETHROUGH",e[e.INVERSE=16]="INVERSE",e[e.INVISIBLE=32]="INVISIBLE",e[e.BLINK=64]="BLINK",e[e.FAINT=128]="FAINT",e))(b||{});class N{constructor(t){this.exports=t.exports,this.memory=this.exports.memory}createKeyEncoder(){return new st(this.exports)}createTerminal(t=80,i=24,s){return new it(this.exports,this.memory,t,i,s)}static async load(t){if(t)return N.loadFromPath(t);const i=new URL("/web/assets/ghostty-vt-DOMeXDrv.wasm",import.meta.url),s=[];if(i.protocol==="file:"){let o=i.pathname;o.match(/^\/[A-Za-z]:\//)&&(o=o.slice(1)),s.push(o)}s.push(i.href,"./ghostty-vt.wasm","/ghostty-vt.wasm");let r=null;for(const o of s)try{return await N.loadFromPath(o)}catch(n){r=n instanceof Error?n:new Error(String(n))}throw r||new Error("Failed to load Ghostty WASM")}static async loadFromPath(t){let i;if(typeof Bun<"u"&&typeof Bun.file=="function")try{const o=Bun.file(t);await o.exists()&&(i=await o.arrayBuffer())}catch{}if(!i)try{const o=await(await Z(async()=>{const{readFile:n}=await Promise.resolve().then(()=>St);return{readFile:n}},void 0)).readFile(t);i=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)}catch{}if(!i){const o=await fetch(t);if(!o.ok)throw new Error(`Failed to fetch WASM: ${o.status} ${o.statusText}`);if(i=await o.arrayBuffer(),i.byteLength===0)throw new Error(`WASM file is empty (0 bytes). Check path: ${t}`)}if(!i)throw new Error(`Could not load WASM from path: ${t}`);const s=await WebAssembly.compile(i),r=await WebAssembly.instantiate(s,{env:{log:(o,n)=>{const l=new Uint8Array(r.exports.memory.buffer,o,n);console.log("[ghostty-vt]",new TextDecoder().decode(l))}}});return new N(r)}}class st{constructor(t){this.encoder=0,this.exports=t;const i=this.exports.ghostty_wasm_alloc_opaque(),s=this.exports.ghostty_key_encoder_new(0,i);if(s!==0)throw new Error(`Failed to create key encoder: ${s}`);const r=new DataView(this.exports.memory.buffer);this.encoder=r.getUint32(i,!0),this.exports.ghostty_wasm_free_opaque(i)}setOption(t,i){const s=this.exports.ghostty_wasm_alloc_u8();new DataView(this.exports.memory.buffer).setUint8(s,typeof i=="boolean"?i?1:0:i),this.exports.ghostty_key_encoder_setopt(this.encoder,t,s),this.exports.ghostty_wasm_free_u8(s)}setKittyFlags(t){this.setOption(Y.KITTY_KEYBOARD_FLAGS,t)}encode(t){const i=this.exports.ghostty_wasm_alloc_opaque(),s=this.exports.ghostty_key_event_new(0,i);if(s!==0)throw new Error(`Failed to create key event: ${s}`);const r=new DataView(this.exports.memory.buffer),o=r.getUint32(i,!0);if(this.exports.ghostty_wasm_free_opaque(i),this.exports.ghostty_key_event_set_action(o,t.action),this.exports.ghostty_key_event_set_key(o,t.key),this.exports.ghostty_key_event_set_mods(o,t.mods),t.utf8){const p=new TextEncoder().encode(t.utf8),u=this.exports.ghostty_wasm_alloc_u8_array(p.length);new Uint8Array(this.exports.memory.buffer).set(p,u),this.exports.ghostty_key_event_set_utf8(o,u,p.length),this.exports.ghostty_wasm_free_u8_array(u,p.length)}const n=32,l=this.exports.ghostty_wasm_alloc_u8_array(n),a=this.exports.ghostty_wasm_alloc_usize(),c=this.exports.ghostty_key_encoder_encode(this.encoder,o,l,n,a);if(c!==0)throw this.exports.ghostty_wasm_free_u8_array(l,n),this.exports.ghostty_wasm_free_usize(a),this.exports.ghostty_key_event_free(o),new Error(`Failed to encode key: ${c}`);const d=r.getUint32(a,!0),m=new Uint8Array(this.exports.memory.buffer,l,d).slice();return this.exports.ghostty_wasm_free_u8_array(l,n),this.exports.ghostty_wasm_free_usize(a),this.exports.ghostty_key_event_free(o),m}dispose(){this.encoder&&(this.exports.ghostty_key_encoder_free(this.encoder),this.encoder=0)}}const j=class R{constructor(t,i,s=80,r=24,o){var n;if(this.viewportBufferPtr=0,this.viewportBufferSize=0,this.cellPool=[],this.graphemeBuffer=null,this.graphemeBufferPtr=0,this.exports=t,this.memory=i,this._cols=s,this._rows=r,o){const l=this.exports.ghostty_wasm_alloc_u8_array(z);if(l===0)throw new Error("Failed to allocate config (out of memory)");try{const a=new DataView(this.memory.buffer);let c=l;a.setUint32(c,o.scrollbackLimit??1e4,!0),c+=4,a.setUint32(c,o.fgColor??0,!0),c+=4,a.setUint32(c,o.bgColor??0,!0),c+=4,a.setUint32(c,o.cursorColor??0,!0),c+=4;for(let d=0;d<16;d++)a.setUint32(c,((n=o.palette)==null?void 0:n[d])??0,!0),c+=4;this.handle=this.exports.ghostty_terminal_new_with_config(s,r,l)}finally{this.exports.ghostty_wasm_free_u8_array(l,z)}}else this.handle=this.exports.ghostty_terminal_new(s,r);if(!this.handle)throw new Error("Failed to create terminal");this.initCellPool()}get cols(){return this._cols}get rows(){return this._rows}write(t){const i=typeof t=="string"?new TextEncoder().encode(t):t,s=this.exports.ghostty_wasm_alloc_u8_array(i.length);new Uint8Array(this.memory.buffer).set(i,s),this.exports.ghostty_terminal_write(this.handle,s,i.length),this.exports.ghostty_wasm_free_u8_array(s,i.length)}resize(t,i){t===this._cols&&i===this._rows||(this._cols=t,this._rows=i,this.exports.ghostty_terminal_resize(this.handle,t,i),this.invalidateBuffers(),this.initCellPool())}free(){this.viewportBufferPtr&&(this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=0),this.exports.ghostty_terminal_free(this.handle)}update(){return this.exports.ghostty_render_state_update(this.handle)}getCursor(){return this.update(),{x:this.exports.ghostty_render_state_get_cursor_x(this.handle),y:this.exports.ghostty_render_state_get_cursor_y(this.handle),viewportX:this.exports.ghostty_render_state_get_cursor_x(this.handle),viewportY:this.exports.ghostty_render_state_get_cursor_y(this.handle),visible:this.exports.ghostty_render_state_get_cursor_visible(this.handle),blinking:!1,style:"block"}}getColors(){const t=this.exports.ghostty_render_state_get_bg_color(this.handle),i=this.exports.ghostty_render_state_get_fg_color(this.handle);return{background:{r:t>>16&255,g:t>>8&255,b:t&255},foreground:{r:i>>16&255,g:i>>8&255,b:i&255},cursor:null}}isRowDirty(t){return this.exports.ghostty_render_state_is_row_dirty(this.handle,t)}markClean(){this.exports.ghostty_render_state_mark_clean(this.handle)}getViewport(){const t=this._cols*this._rows,i=t*R.CELL_SIZE;return(!this.viewportBufferPtr||this.viewportBufferSize<i)&&(this.viewportBufferPtr&&this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(i),this.viewportBufferSize=i),this.exports.ghostty_render_state_get_viewport(this.handle,this.viewportBufferPtr,t)<0?this.cellPool:(this.parseCellsIntoPool(this.viewportBufferPtr,t),this.cellPool)}getLine(t){if(t<0||t>=this._rows)return null;this.update();const i=this.getViewport(),s=t*this._cols;return i.slice(s,s+this._cols).map(r=>({...r}))}isDirty(){return this.update()!==B.NONE}needsFullRedraw(){return this.update()===B.FULL}clearDirty(){this.markClean()}isAlternateScreen(){return!!this.exports.ghostty_terminal_is_alternate_screen(this.handle)}hasBracketedPaste(){return this.getMode(2004,!1)}hasFocusEvents(){return this.getMode(1004,!1)}hasMouseTracking(){return this.exports.ghostty_terminal_has_mouse_tracking(this.handle)!==0}getDimensions(){return{cols:this._cols,rows:this._rows}}getScrollbackLength(){return this.exports.ghostty_terminal_get_scrollback_length(this.handle)}getScrollbackLine(t){const i=this._cols*R.CELL_SIZE;(!this.viewportBufferPtr||this.viewportBufferSize<i)&&(this.viewportBufferPtr&&this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(i),this.viewportBufferSize=i),this.update();const s=this.exports.ghostty_terminal_get_scrollback_line(this.handle,t,this.viewportBufferPtr,this._cols);if(s<0)return null;const r=[],o=this.memory.buffer,n=new Uint8Array(o,this.viewportBufferPtr,s*R.CELL_SIZE),l=new DataView(o,this.viewportBufferPtr,s*R.CELL_SIZE);for(let a=0;a<s;a++){const c=a*R.CELL_SIZE;r.push({codepoint:l.getUint32(c,!0),fg_r:n[c+4],fg_g:n[c+5],fg_b:n[c+6],bg_r:n[c+7],bg_g:n[c+8],bg_b:n[c+9],flags:n[c+10],width:n[c+11],hyperlink_id:l.getUint16(c+12,!0),grapheme_len:n[c+14]})}return r}isRowWrapped(t){return this.exports.ghostty_terminal_is_row_wrapped(this.handle,t)!==0}getHyperlinkUri(t){return null}hasResponse(){return this.exports.ghostty_terminal_has_response(this.handle)}readResponse(){if(!this.hasResponse())return null;const t=256,i=this.exports.ghostty_wasm_alloc_u8_array(t);try{const s=this.exports.ghostty_terminal_read_response(this.handle,i,t);if(s<=0)return null;const r=new Uint8Array(this.memory.buffer,i,s);return new TextDecoder().decode(r.slice())}finally{this.exports.ghostty_wasm_free_u8_array(i,t)}}getMode(t,i=!1){return this.exports.ghostty_terminal_get_mode(this.handle,t,i)!==0}initCellPool(){const t=this._cols*this._rows;if(this.cellPool.length<t)for(let i=this.cellPool.length;i<t;i++)this.cellPool.push({codepoint:0,fg_r:204,fg_g:204,fg_b:204,bg_r:0,bg_g:0,bg_b:0,flags:0,width:1,hyperlink_id:0,grapheme_len:0})}parseCellsIntoPool(t,i){const s=this.memory.buffer,r=new Uint8Array(s,t,i*R.CELL_SIZE),o=new DataView(s,t,i*R.CELL_SIZE);for(let n=0;n<i;n++){const l=n*R.CELL_SIZE,a=this.cellPool[n];a.codepoint=o.getUint32(l,!0),a.fg_r=r[l+4],a.fg_g=r[l+5],a.fg_b=r[l+6],a.bg_r=r[l+7],a.bg_g=r[l+8],a.bg_b=r[l+9],a.flags=r[l+10],a.width=r[l+11],a.hyperlink_id=o.getUint16(l+12,!0),a.grapheme_len=r[l+14]}}getGrapheme(t,i){this.graphemeBuffer||(this.graphemeBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(64),this.graphemeBuffer=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,16));const s=this.exports.ghostty_render_state_get_grapheme(this.handle,t,i,this.graphemeBufferPtr,16);if(s<0)return null;const r=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,s);return Array.from(r)}getGraphemeString(t,i){const s=this.getGrapheme(t,i);return!s||s.length===0?" ":String.fromCodePoint(...s)}getScrollbackGrapheme(t,i){this.graphemeBuffer||(this.graphemeBufferPtr=this.exports.ghostty_wasm_alloc_u8_array(64),this.graphemeBuffer=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,16));const s=this.exports.ghostty_terminal_get_scrollback_grapheme(this.handle,t,i,this.graphemeBufferPtr,16);if(s<0)return null;const r=new Uint32Array(this.memory.buffer,this.graphemeBufferPtr,s);return Array.from(r)}getScrollbackGraphemeString(t,i){const s=this.getScrollbackGrapheme(t,i);return!s||s.length===0?" ":String.fromCodePoint(...s)}invalidateBuffers(){this.viewportBufferPtr&&(this.exports.ghostty_wasm_free_u8_array(this.viewportBufferPtr,this.viewportBufferSize),this.viewportBufferPtr=0,this.viewportBufferSize=0)}};j.CELL_SIZE=16;let it=j;class L{constructor(){this.listeners=[],this.event=t=>(this.listeners.push(t),{dispose:()=>{const i=this.listeners.indexOf(t);i>=0&&this.listeners.splice(i,1)}})}fire(t){for(const i of this.listeners)i(t)}dispose(){this.listeners=[]}}class rt{constructor(t){this.bufferChangeEmitter=new L,this.terminal=t}get active(){const t=this.terminal.wasmTerm;return t?t.isAlternateScreen()?this.alternate:this.normal:this.normal}get normal(){return this._normalBuffer||(this._normalBuffer=new G(this.terminal,"normal")),this._normalBuffer}get alternate(){return this._alternateBuffer||(this._alternateBuffer=new G(this.terminal,"alternate")),this._alternateBuffer}get onBufferChange(){return this.bufferChangeEmitter.event}_fireBufferChange(t){this.bufferChangeEmitter.fire(t)}}class G{constructor(t,i){this.terminal=t,this.bufferType=i;const s={codepoint:0,fg_r:204,fg_g:204,fg_b:204,bg_r:0,bg_g:0,bg_b:0,flags:0,width:1,hyperlink_id:0,grapheme_len:0};this.nullCell=new U(s,0)}get type(){return this.bufferType}get cursorX(){const t=this.getWasmTerm();return t?t.getCursor().x:0}get cursorY(){const t=this.getWasmTerm();return t?t.getCursor().y:0}get viewportY(){return 0}get baseY(){return 0}get length(){const t=this.getWasmTerm();return t?this.bufferType==="alternate"?t.rows:t.getScrollbackLength()+t.rows:0}getLine(t){const i=this.getWasmTerm();if(!i||t<0||t>=this.length)return;const s=i.getScrollbackLength();let r,o,n;if(this.bufferType==="normal"&&t<s){const l=t;r=i.getScrollbackLine(l),n=!1}else o=this.bufferType==="normal"?t-s:t,r=i.getLine(o),n=i.isRowWrapped(o);if(r)return new ot(r,n,i.cols)}getNullCell(){return this.nullCell}getWasmTerm(){return this.terminal.wasmTerm}}class ot{constructor(t,i,s){this.cells=t,this._isWrapped=i,this._length=s}get length(){return this._length}get isWrapped(){return this._isWrapped}getCell(t){if(!(t<0||t>=this._length))return t>=this.cells.length?new U({codepoint:0,fg_r:204,fg_g:204,fg_b:204,bg_r:0,bg_g:0,bg_b:0,flags:0,width:1,hyperlink_id:0,grapheme_len:0},t):new U(this.cells[t],t)}translateToString(t=!1,i=0,s=this._length){const r=Math.max(0,Math.min(i,this._length)),o=Math.max(r,Math.min(s,this._length));let n="";for(let l=r;l<o;l++){const a=this.getCell(l);if(a){const c=a.getChars();n+=c}}return t&&(n=n.trimEnd()),n}}class U{constructor(t,i){this.cell=t,this.x=i}getChars(){const t=this.cell.codepoint;return t===0?"":t<0||t>1114111||t>=55296&&t<=57343?"�":String.fromCodePoint(t)}getCode(){return this.cell.codepoint}getWidth(){return this.cell.width}getFgColorMode(){return-1}getBgColorMode(){return-1}getFgColor(){return this.cell.fg_r<<16|this.cell.fg_g<<8|this.cell.fg_b}getBgColor(){return this.cell.bg_r<<16|this.cell.bg_g<<8|this.cell.bg_b}isBold(){return this.cell.flags&b.BOLD?1:0}isItalic(){return this.cell.flags&b.ITALIC?1:0}isUnderline(){return this.cell.flags&b.UNDERLINE?1:0}isStrikethrough(){return this.cell.flags&b.STRIKETHROUGH?1:0}isBlink(){return this.cell.flags&b.BLINK?1:0}isInverse(){return this.cell.flags&b.INVERSE?1:0}isInvisible(){return this.cell.flags&b.INVISIBLE?1:0}isFaint(){return this.cell.flags&b.FAINT?1:0}getHyperlinkId(){return this.cell.hyperlink_id}getCodepoint(){return this.cell.codepoint}isDim(){return(this.cell.flags&b.FAINT)!==0}}const nt={KeyA:h.A,KeyB:h.B,KeyC:h.C,KeyD:h.D,KeyE:h.E,KeyF:h.F,KeyG:h.G,KeyH:h.H,KeyI:h.I,KeyJ:h.J,KeyK:h.K,KeyL:h.L,KeyM:h.M,KeyN:h.N,KeyO:h.O,KeyP:h.P,KeyQ:h.Q,KeyR:h.R,KeyS:h.S,KeyT:h.T,KeyU:h.U,KeyV:h.V,KeyW:h.W,KeyX:h.X,KeyY:h.Y,KeyZ:h.Z,Digit1:h.ONE,Digit2:h.TWO,Digit3:h.THREE,Digit4:h.FOUR,Digit5:h.FIVE,Digit6:h.SIX,Digit7:h.SEVEN,Digit8:h.EIGHT,Digit9:h.NINE,Digit0:h.ZERO,Enter:h.ENTER,Escape:h.ESCAPE,Backspace:h.BACKSPACE,Tab:h.TAB,Space:h.SPACE,Minus:h.MINUS,Equal:h.EQUAL,BracketLeft:h.BRACKET_LEFT,BracketRight:h.BRACKET_RIGHT,Backslash:h.BACKSLASH,Semicolon:h.SEMICOLON,Quote:h.QUOTE,Backquote:h.GRAVE,Comma:h.COMMA,Period:h.PERIOD,Slash:h.SLASH,CapsLock:h.CAPS_LOCK,F1:h.F1,F2:h.F2,F3:h.F3,F4:h.F4,F5:h.F5,F6:h.F6,F7:h.F7,F8:h.F8,F9:h.F9,F10:h.F10,F11:h.F11,F12:h.F12,PrintScreen:h.PRINT_SCREEN,ScrollLock:h.SCROLL_LOCK,Pause:h.PAUSE,Insert:h.INSERT,Home:h.HOME,PageUp:h.PAGE_UP,Delete:h.DELETE,End:h.END,PageDown:h.PAGE_DOWN,ArrowRight:h.RIGHT,ArrowLeft:h.LEFT,ArrowDown:h.DOWN,ArrowUp:h.UP,NumLock:h.NUM_LOCK,NumpadDivide:h.KP_DIVIDE,NumpadMultiply:h.KP_MULTIPLY,NumpadSubtract:h.KP_MINUS,NumpadAdd:h.KP_PLUS,NumpadEnter:h.KP_ENTER,Numpad1:h.KP_1,Numpad2:h.KP_2,Numpad3:h.KP_3,Numpad4:h.KP_4,Numpad5:h.KP_5,Numpad6:h.KP_6,Numpad7:h.KP_7,Numpad8:h.KP_8,Numpad9:h.KP_9,Numpad0:h.KP_0,NumpadDecimal:h.KP_PERIOD,IntlBackslash:h.INTL_BACKSLASH,ContextMenu:h.CONTEXT_MENU,F13:h.F13,F14:h.F14,F15:h.F15,F16:h.F16,F17:h.F17,F18:h.F18,F19:h.F19,F20:h.F20,F21:h.F21,F22:h.F22,F23:h.F23,F24:h.F24};class lt{constructor(t,i,s,r,o,n,l){this.keydownListener=null,this.keypressListener=null,this.pasteListener=null,this.compositionStartListener=null,this.compositionUpdateListener=null,this.compositionEndListener=null,this.isComposing=!1,this.isDisposed=!1,this.encoder=t.createKeyEncoder(),this.container=i,this.onDataCallback=s,this.onBellCallback=r,this.onKeyCallback=o,this.customKeyEventHandler=n,this.getModeCallback=l,this.attach()}setCustomKeyEventHandler(t){this.customKeyEventHandler=t}attach(){typeof this.container.hasAttribute=="function"&&typeof this.container.setAttribute=="function"&&(this.container.hasAttribute("tabindex")||this.container.setAttribute("tabindex","0"),this.container.style&&(this.container.style.outline="none")),this.keydownListener=this.handleKeyDown.bind(this),this.container.addEventListener("keydown",this.keydownListener),this.pasteListener=this.handlePaste.bind(this),this.container.addEventListener("paste",this.pasteListener),this.compositionStartListener=this.handleCompositionStart.bind(this),this.container.addEventListener("compositionstart",this.compositionStartListener),this.compositionUpdateListener=this.handleCompositionUpdate.bind(this),this.container.addEventListener("compositionupdate",this.compositionUpdateListener),this.compositionEndListener=this.handleCompositionEnd.bind(this),this.container.addEventListener("compositionend",this.compositionEndListener)}mapKeyCode(t){return nt[t]??null}extractModifiers(t){let i=k.NONE;return t.shiftKey&&(i|=k.SHIFT),t.ctrlKey&&(i|=k.CTRL),t.altKey&&(i|=k.ALT),t.metaKey&&(i|=k.SUPER),i}isPrintableCharacter(t){return t.ctrlKey&&!t.altKey||t.altKey&&!t.ctrlKey||t.metaKey?!1:t.key.length===1}handleKeyDown(t){if(this.isDisposed||this.isComposing||t.isComposing||t.keyCode===229)return;if(this.onKeyCallback&&this.onKeyCallback({key:t.key,domEvent:t}),this.customKeyEventHandler&&this.customKeyEventHandler(t)){t.preventDefault();return}if((t.ctrlKey||t.metaKey)&&t.code==="KeyV"||t.metaKey&&t.code==="KeyC")return;if(this.isPrintableCharacter(t)){t.preventDefault(),this.onDataCallback(t.key);return}const i=this.mapKeyCode(t.code);if(i===null)return;const s=this.extractModifiers(t);if(s===k.NONE||s===k.SHIFT){let o=null;switch(i){case h.ENTER:o="\r";break;case h.TAB:o=" ";break;case h.BACKSPACE:o="";break;case h.ESCAPE:o="\x1B";break;case h.HOME:o="\x1B[H";break;case h.END:o="\x1B[F";break;case h.INSERT:o="\x1B[2~";break;case h.DELETE:o="\x1B[3~";break;case h.PAGE_UP:o="\x1B[5~";break;case h.PAGE_DOWN:o="\x1B[6~";break;case h.F1:o="\x1BOP";break;case h.F2:o="\x1BOQ";break;case h.F3:o="\x1BOR";break;case h.F4:o="\x1BOS";break;case h.F5:o="\x1B[15~";break;case h.F6:o="\x1B[17~";break;case h.F7:o="\x1B[18~";break;case h.F8:o="\x1B[19~";break;case h.F9:o="\x1B[20~";break;case h.F10:o="\x1B[21~";break;case h.F11:o="\x1B[23~";break;case h.F12:o="\x1B[24~";break}if(o!==null){t.preventDefault(),this.onDataCallback(o);return}}const r=$.PRESS;try{if(this.getModeCallback){const a=this.getModeCallback(1);this.encoder.setOption(Y.CURSOR_KEY_APPLICATION,a)}const o=t.key.length===1&&t.key.charCodeAt(0)<128?t.key.toLowerCase():void 0,n=this.encoder.encode({action:r,key:i,mods:s,utf8:o}),l=new TextDecoder().decode(n);t.preventDefault(),t.stopPropagation(),l.length>0&&this.onDataCallback(l)}catch(o){console.warn("Failed to encode key:",t.code,o)}}handlePaste(t){if(this.isDisposed)return;t.preventDefault(),t.stopPropagation();const i=t.clipboardData;if(!i){console.warn("No clipboard data available");return}const s=i.getData("text/plain");if(!s){console.warn("No text in clipboard");return}this.onDataCallback(s)}handleCompositionStart(t){this.isDisposed||(this.isComposing=!0)}handleCompositionUpdate(t){this.isDisposed}handleCompositionEnd(t){if(this.isDisposed)return;this.isComposing=!1;const i=t.data;if(i&&i.length>0&&this.onDataCallback(i),this.container&&this.container.childNodes)for(let s=this.container.childNodes.length-1;s>=0;s--){const r=this.container.childNodes[s];r.nodeType===3&&this.container.removeChild(r)}}dispose(){this.isDisposed||(this.keydownListener&&(this.container.removeEventListener("keydown",this.keydownListener),this.keydownListener=null),this.keypressListener&&(this.container.removeEventListener("keypress",this.keypressListener),this.keypressListener=null),this.pasteListener&&(this.container.removeEventListener("paste",this.pasteListener),this.pasteListener=null),this.compositionStartListener&&(this.container.removeEventListener("compositionstart",this.compositionStartListener),this.compositionStartListener=null),this.compositionUpdateListener&&(this.container.removeEventListener("compositionupdate",this.compositionUpdateListener),this.compositionUpdateListener=null),this.compositionEndListener&&(this.container.removeEventListener("compositionend",this.compositionEndListener),this.compositionEndListener=null),this.isDisposed=!0)}isActive(){return!this.isDisposed}}class at{constructor(t){this.terminal=t,this.providers=[],this.linkCache=new Map,this.scannedRows=new Set}registerProvider(t){this.providers.push(t),this.invalidateCache()}async getLinkAt(t,i){const s=this.terminal.buffer.active.getLine(i);if(!s||t<0||t>=s.length)return;const r=s.getCell(t);if(!r)return;const o=r.getHyperlinkId();if(o>0){const n=`h${o}`;if(this.linkCache.has(n))return this.linkCache.get(n)}if(this.scannedRows.has(i)||await this.scanRow(i),o>0){const n=`h${o}`,l=this.linkCache.get(n);if(l)return l}for(const n of this.linkCache.values())if(this.isPositionInLink(t,i,n))return n}async scanRow(t){this.scannedRows.add(t);const i=[];for(const s of this.providers){const r=await new Promise(o=>{s.provideLinks(t,o)});r&&i.push(...r)}for(const s of i)this.cacheLink(s)}cacheLink(t){const{start:i}=t.range,s=this.terminal.buffer.active.getLine(i.y);if(s){const l=s.getCell(i.x);if(!l){const{start:c,end:d}=t.range,m=`r${c.y}:${c.x}-${d.x}`;this.linkCache.set(m,t);return}const a=l.getHyperlinkId();if(a>0){this.linkCache.set(`h${a}`,t);return}}const{start:r,end:o}=t.range,n=`r${r.y}:${r.x}-${o.x}`;this.linkCache.set(n,t)}isPositionInLink(t,i,s){const{start:r,end:o}=s.range;return i<r.y||i>o.y?!1:r.y===o.y?t>=r.x&&t<=o.x:i===r.y?t>=r.x:i===o.y?t<=o.x:!0}invalidateCache(){this.linkCache.clear(),this.scannedRows.clear()}invalidateRows(t,i){for(let r=t;r<=i;r++)this.scannedRows.delete(r);const s=[];for(const[r,o]of this.linkCache.entries()){const{start:n,end:l}=o.range;(n.y>=t&&n.y<=i||l.y>=t&&l.y<=i||n.y<t&&l.y>i)&&s.push(r)}for(const r of s)this.linkCache.delete(r)}dispose(){var t;this.linkCache.clear(),this.scannedRows.clear();for(const i of this.providers)(t=i.dispose)==null||t.call(i);this.providers=[]}}class ht{constructor(t){this.terminal=t}provideLinks(t,i){const s=[],r=new Set,o=this.terminal.buffer.active.getLine(t);if(!o){i(void 0);return}for(let n=0;n<o.length;n++){const l=o.getCell(n);if(!l)continue;const a=l.getHyperlinkId();if(a===0||r.has(a))continue;r.add(a);const c=this.findLinkRange(a,t,n);if(!this.terminal.wasmTerm)continue;const d=this.terminal.wasmTerm.getHyperlinkUri(a);d&&s.push({text:d,range:c,activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(d,"_blank","noopener,noreferrer")}})}i(s.length>0?s:void 0)}findLinkRange(t,i,s){const r=this.terminal.buffer.active;let o=i,n=s;for(;n>0;){const d=r.getLine(o);if(!d)break;const m=d.getCell(n-1);if(!m||m.getHyperlinkId()!==t)break;n--}if(n===0&&o>0){let d=o-1;for(;d>=0;){const m=r.getLine(d);if(!m||m.length===0)break;const p=m.getCell(m.length-1);if(!p||p.getHyperlinkId()!==t)break;o=d,n=0;for(let u=m.length-1;u>=0;u--){const f=m.getCell(u);if(!f||f.getHyperlinkId()!==t){n=u+1;break}}if(n===0)d--;else break}}let l=i,a=s;const c=r.getLine(l);if(c){for(;a<c.length-1;){const d=c.getCell(a+1);if(!d||d.getHyperlinkId()!==t)break;a++}if(a===c.length-1){let d=l+1;const m=r.length;for(;d<m;){const p=r.getLine(d);if(!p||p.length===0)break;const u=p.getCell(0);if(!u||u.getHyperlinkId()!==t)break;l=d,a=0;for(let f=0;f<p.length;f++){const _=p.getCell(f);if(!_)break;if(_.getHyperlinkId()!==t){a=f-1;break}a=f}if(a===p.length-1)d++;else break}}}return{start:{x:n,y:o},end:{x:a,y:l}}}dispose(){}}const V=class O{constructor(t){this.terminal=t}provideLinks(t,i){const s=[],r=this.terminal.buffer.active.getLine(t);if(!r){i(void 0);return}const o=this.lineToText(r);O.URL_REGEX.lastIndex=0;let n=O.URL_REGEX.exec(o);for(;n!==null;){let l=n[0];const a=n.index;let c=n.index+l.length-1;const d=l.replace(O.TRAILING_PUNCTUATION,"");d.length<l.length&&(l=d,c=a+l.length-1),l.length>8&&s.push({text:l,range:{start:{x:a,y:t},end:{x:c,y:t}},activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(l,"_blank","noopener,noreferrer")}}),n=O.URL_REGEX.exec(o)}i(s.length>0?s:void 0)}lineToText(t){const i=[];for(let s=0;s<t.length;s++){const r=t.getCell(s);if(!r){i.push(" ");continue}const o=r.getCodepoint();o===0||o<32?i.push(" "):i.push(String.fromCodePoint(o))}return i.join("")}dispose(){}};V.URL_REGEX=/(?:https?:\/\/|mailto:|ftp:\/\/|ssh:\/\/|git:\/\/|tel:|magnet:|gemini:\/\/|gopher:\/\/|news:)[\w\-.~:\/?#@!$&*+,;=%]+/gi;V.TRAILING_PUNCTUATION=/[.,;!?)\]]+$/;let ct=V;const X={foreground:"#d4d4d4",background:"#1e1e1e",cursor:"#ffffff",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"};class dt{constructor(t,i={}){this.cursorVisible=!0,this.lastCursorPosition={x:0,y:0},this.lastViewportY=0,this.currentBuffer=null,this.currentSelectionCoords=null,this.hoveredHyperlinkId=0,this.previousHoveredHyperlinkId=0,this.hoveredLinkRange=null,this.previousHoveredLinkRange=null,this.canvas=t;const s=t.getContext("2d",{alpha:!0});if(!s)throw new Error("Failed to get 2D rendering context");this.ctx=s,this.fontSize=i.fontSize??15,this.fontFamily=i.fontFamily??"monospace",this.cursorStyle=i.cursorStyle??"block",this.cursorBlink=i.cursorBlink??!1,this.theme={...X,...i.theme},this.devicePixelRatio=i.devicePixelRatio??window.devicePixelRatio??1,this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite],this.metrics=this.measureFont(),this.cursorBlink&&this.startCursorBlink()}measureFont(){const t=document.createElement("canvas").getContext("2d");t.font=`${this.fontSize}px ${this.fontFamily}`;const i=t.measureText("M"),s=Math.ceil(i.width),r=i.actualBoundingBoxAscent||this.fontSize*.8,o=i.actualBoundingBoxDescent||this.fontSize*.2,n=Math.ceil(r+o)+2,l=Math.ceil(r)+1;return{width:s,height:n,baseline:l}}remeasureFont(){this.metrics=this.measureFont()}rgbToCSS(t,i,s){return`rgb(${t}, ${i}, ${s})`}resize(t,i){const s=t*this.metrics.width,r=i*this.metrics.height;this.canvas.style.width=`${s}px`,this.canvas.style.height=`${r}px`,this.canvas.width=s*this.devicePixelRatio,this.canvas.height=r*this.devicePixelRatio,this.ctx.scale(this.devicePixelRatio,this.devicePixelRatio),this.ctx.textBaseline="alphabetic",this.ctx.textAlign="left",this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,s,r)}render(t,i=!1,s=0,r,o=1){var n;this.currentBuffer=t;const l=t.getCursor(),a=t.getDimensions(),c=r?r.getScrollbackLength():0;(n=t.needsFullRedraw)!=null&&n.call(t)&&(i=!0),(this.canvas.width!==a.cols*this.metrics.width*this.devicePixelRatio||this.canvas.height!==a.rows*this.metrics.height*this.devicePixelRatio)&&(this.resize(a.cols,a.rows),i=!0),s!==this.lastViewportY&&(i=!0,this.lastViewportY=s);const d=l.x!==this.lastCursorPosition.x||l.y!==this.lastCursorPosition.y;if(d||this.cursorBlink){if(!i&&!t.isRowDirty(l.y)){const g=t.getLine(l.y);g&&this.renderLine(g,l.y,a.cols)}if(d&&this.lastCursorPosition.y!==l.y&&!i&&!t.isRowDirty(this.lastCursorPosition.y)){const g=t.getLine(this.lastCursorPosition.y);g&&this.renderLine(g,this.lastCursorPosition.y,a.cols)}}const m=this.selectionManager&&this.selectionManager.hasSelection(),p=new Set;if(this.currentSelectionCoords=m?this.selectionManager.getSelectionCoords():null,this.currentSelectionCoords){const g=this.currentSelectionCoords;for(let E=g.startRow;E<=g.endRow;E++)p.add(E)}if(this.selectionManager){const g=this.selectionManager.getDirtySelectionRows();if(g.size>0){for(const E of g)p.add(E);this.selectionManager.clearDirtySelectionRows()}}const u=new Set,f=this.hoveredHyperlinkId!==this.previousHoveredHyperlinkId,_=JSON.stringify(this.hoveredLinkRange)!==JSON.stringify(this.previousHoveredLinkRange);if(f){for(let g=0;g<a.rows;g++){let E=null;if(s>0)if(g<s&&r){const y=c-Math.floor(s)+g;E=r.getScrollbackLine(y)}else{const y=g-Math.floor(s);E=t.getLine(y)}else E=t.getLine(g);if(E){for(const y of E)if(y.hyperlink_id===this.hoveredHyperlinkId||y.hyperlink_id===this.previousHoveredHyperlinkId){u.add(g);break}}}this.previousHoveredHyperlinkId=this.hoveredHyperlinkId}if(_){if(this.previousHoveredLinkRange)for(let g=this.previousHoveredLinkRange.startY;g<=this.previousHoveredLinkRange.endY;g++)u.add(g);if(this.hoveredLinkRange)for(let g=this.hoveredLinkRange.startY;g<=this.hoveredLinkRange.endY;g++)u.add(g);this.previousHoveredLinkRange=this.hoveredLinkRange}const v=new Set;for(let g=0;g<a.rows;g++)(s>0||i||t.isRowDirty(g)||p.has(g)||u.has(g))&&(v.add(g),g>0&&v.add(g-1),g<a.rows-1&&v.add(g+1));for(let g=0;g<a.rows;g++){if(!v.has(g))continue;let E=null;if(s>0)if(g<s&&r){const y=c-Math.floor(s)+g;E=r.getScrollbackLine(y)}else{const y=s>0?g-Math.floor(s):g;E=t.getLine(y)}else E=t.getLine(g);E&&this.renderLine(E,g,a.cols)}s===0&&l.visible&&this.cursorVisible&&this.renderCursor(l.x,l.y),r&&o>0&&this.renderScrollbar(s,c,a.rows,o),this.lastCursorPosition={x:l.x,y:l.y},t.clearDirty()}renderLine(t,i,s){const r=i*this.metrics.height;this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,r,s*this.metrics.width,this.metrics.height);for(let o=0;o<t.length;o++){const n=t[o];n.width!==0&&this.renderCellBackground(n,o,i)}for(let o=0;o<t.length;o++){const n=t[o];n.width!==0&&this.renderCellText(n,o,i)}}renderCellBackground(t,i,s){const r=i*this.metrics.width,o=s*this.metrics.height,n=this.metrics.width*t.width;if(this.isInSelection(i,s)){this.ctx.fillStyle=this.theme.selectionBackground,this.ctx.fillRect(r,o,n,this.metrics.height);return}let l=t.bg_r,a=t.bg_g,c=t.bg_b;t.flags&b.INVERSE&&(l=t.fg_r,a=t.fg_g,c=t.fg_b),l===0&&a===0&&c===0||(this.ctx.fillStyle=this.rgbToCSS(l,a,c),this.ctx.fillRect(r,o,n,this.metrics.height))}renderCellText(t,i,s){var r;const o=i*this.metrics.width,n=s*this.metrics.height,l=this.metrics.width*t.width;if(t.flags&b.INVISIBLE)return;const a=this.isInSelection(i,s);let c="";if(t.flags&b.ITALIC&&(c+="italic "),t.flags&b.BOLD&&(c+="bold "),this.ctx.font=`${c}${this.fontSize}px ${this.fontFamily}`,a)this.ctx.fillStyle=this.theme.selectionForeground;else{let u=t.fg_r,f=t.fg_g,_=t.fg_b;t.flags&b.INVERSE&&(u=t.bg_r,f=t.bg_g,_=t.bg_b),this.ctx.fillStyle=this.rgbToCSS(u,f,_)}t.flags&b.FAINT&&(this.ctx.globalAlpha=.5);const d=o,m=n+this.metrics.baseline;let p;if(t.grapheme_len>0&&(r=this.currentBuffer)!=null&&r.getGraphemeString?p=this.currentBuffer.getGraphemeString(s,i):p=String.fromCodePoint(t.codepoint||32),this.ctx.fillText(p,d,m),t.flags&b.FAINT&&(this.ctx.globalAlpha=1),t.flags&b.UNDERLINE){const u=n+this.metrics.baseline+2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,u),this.ctx.lineTo(o+l,u),this.ctx.stroke()}if(t.flags&b.STRIKETHROUGH){const u=n+this.metrics.height/2;this.ctx.strokeStyle=this.ctx.fillStyle,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,u),this.ctx.lineTo(o+l,u),this.ctx.stroke()}if(t.hyperlink_id>0&&t.hyperlink_id===this.hoveredHyperlinkId){const u=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,u),this.ctx.lineTo(o+l,u),this.ctx.stroke()}if(this.hoveredLinkRange){const u=this.hoveredLinkRange;if(s===u.startY&&i>=u.startX&&(s<u.endY||i<=u.endX)||s>u.startY&&s<u.endY||s===u.endY&&i<=u.endX&&(s>u.startY||i>=u.startX)){const f=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,f),this.ctx.lineTo(o+l,f),this.ctx.stroke()}}}renderCursor(t,i){const s=t*this.metrics.width,r=i*this.metrics.height;switch(this.ctx.fillStyle=this.theme.cursor,this.cursorStyle){case"block":this.ctx.fillRect(s,r,this.metrics.width,this.metrics.height);break;case"underline":const o=Math.max(2,Math.floor(this.metrics.height*.15));this.ctx.fillRect(s,r+this.metrics.height-o,this.metrics.width,o);break;case"bar":const n=Math.max(2,Math.floor(this.metrics.width*.15));this.ctx.fillRect(s,r,n,this.metrics.height);break}}startCursorBlink(){this.cursorBlinkInterval=window.setInterval(()=>{this.cursorVisible=!this.cursorVisible},530)}stopCursorBlink(){this.cursorBlinkInterval!==void 0&&(clearInterval(this.cursorBlinkInterval),this.cursorBlinkInterval=void 0),this.cursorVisible=!0}setTheme(t){this.theme={...X,...t},this.palette=[this.theme.black,this.theme.red,this.theme.green,this.theme.yellow,this.theme.blue,this.theme.magenta,this.theme.cyan,this.theme.white,this.theme.brightBlack,this.theme.brightRed,this.theme.brightGreen,this.theme.brightYellow,this.theme.brightBlue,this.theme.brightMagenta,this.theme.brightCyan,this.theme.brightWhite]}setFontSize(t){this.fontSize=t,this.metrics=this.measureFont()}setFontFamily(t){this.fontFamily=t,this.metrics=this.measureFont()}setCursorStyle(t){this.cursorStyle=t}setCursorBlink(t){t&&!this.cursorBlink?(this.cursorBlink=!0,this.startCursorBlink()):!t&&this.cursorBlink&&(this.cursorBlink=!1,this.stopCursorBlink())}renderScrollbar(t,i,s,r=1){const o=this.ctx,n=this.canvas.height/this.devicePixelRatio,l=this.canvas.width/this.devicePixelRatio,a=8,c=l-a-4,d=4,m=n-d*2;if(o.fillStyle=this.theme.background,o.fillRect(c-2,0,a+6,n),r<=0||i===0)return;const p=i+s,u=Math.max(20,s/p*m),f=t/i,_=d+(m-u)*(1-f);o.fillStyle=`rgba(128, 128, 128, ${.1*r})`,o.fillRect(c,d,a,m);const v=t>0?.5:.3;o.fillStyle=`rgba(128, 128, 128, ${v*r})`,o.fillRect(c,_,a,u)}getMetrics(){return{...this.metrics}}getCanvas(){return this.canvas}setSelectionManager(t){this.selectionManager=t}isInSelection(t,i){const s=this.currentSelectionCoords;if(!s)return!1;const{startCol:r,startRow:o,endCol:n,endRow:l}=s;return o===l?i===o&&t>=r&&t<=n:i===o?t>=r:i===l?t<=n:i>o&&i<l}setHoveredHyperlinkId(t){this.hoveredHyperlinkId=t}setHoveredLinkRange(t){this.hoveredLinkRange=t}get charWidth(){return this.metrics.width}get charHeight(){return this.metrics.height}clear(){this.ctx.fillStyle=this.theme.background,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}dispose(){this.stopCursorBlink()}}const H=class A{constructor(t,i,s,r){this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.mouseDownTarget=null,this.dirtySelectionRows=new Set,this.selectionChangedEmitter=new L,this.boundMouseUpHandler=null,this.boundContextMenuHandler=null,this.boundClickHandler=null,this.boundDocumentMouseMoveHandler=null,this.autoScrollInterval=null,this.autoScrollDirection=0,this.terminal=t,this.renderer=i,this.wasmTerm=s,this.textarea=r,this.attachEventListeners()}getViewportY(){const t=typeof this.terminal.getViewportY=="function"?this.terminal.getViewportY():this.terminal.viewportY||0;return Math.max(0,Math.floor(t))}viewportRowToAbsolute(t){const i=this.wasmTerm.getScrollbackLength(),s=this.getViewportY();return i+t-s}absoluteRowToViewport(t){const i=this.wasmTerm.getScrollbackLength(),s=this.getViewportY();return t-i+s}getSelection(){if(!this.selectionStart||!this.selectionEnd)return"";let{col:t,absoluteRow:i}=this.selectionStart,{col:s,absoluteRow:r}=this.selectionEnd;(i>r||i===r&&t>s)&&([t,s]=[s,t],[i,r]=[r,i]);const o=this.wasmTerm.getScrollbackLength();let n="";for(let l=i;l<=r;l++){let a=null;if(l<o)a=this.wasmTerm.getScrollbackLine(l);else{const u=l-o;a=this.wasmTerm.getLine(u)}if(!a)continue;let c=-1;const d=l===i?t:0,m=l===r?s:a.length-1;let p="";for(let u=d;u<=m;u++){const f=a[u];if(f&&f.codepoint!==0){let _;if(f.grapheme_len>0)if(l<o)_=this.wasmTerm.getScrollbackGraphemeString(l,u);else{const v=l-o;_=this.wasmTerm.getGraphemeString(v,u)}else _=String.fromCodePoint(f.codepoint);p+=_,_.trim()&&(c=p.length)}else p+=" "}c>=0?p=p.substring(0,c):p="",n+=p,l<r&&(n+=`
|
|
2
2
|
`)}return n}hasSelection(){return!this.selectionStart||!this.selectionEnd?!1:!(this.selectionStart.col===this.selectionEnd.col&&this.selectionStart.absoluteRow===this.selectionEnd.absoluteRow)}clearSelection(){if(!this.hasSelection())return;const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i);this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.requestRender()}selectAll(){const t=this.wasmTerm.getDimensions(),i=this.getViewportY();this.selectionStart={col:0,absoluteRow:i},this.selectionEnd={col:t.cols-1,absoluteRow:i+t.rows-1},this.requestRender(),this.selectionChangedEmitter.fire()}select(t,i,s){const r=this.wasmTerm.getDimensions();i=Math.max(0,Math.min(i,r.rows-1)),t=Math.max(0,Math.min(t,r.cols-1));let o=i,n=t+s-1;for(;n>=r.cols;)n-=r.cols,o++;o=Math.min(o,r.rows-1);const l=this.getViewportY();this.selectionStart={col:t,absoluteRow:l+i},this.selectionEnd={col:n,absoluteRow:l+o},this.requestRender(),this.selectionChangedEmitter.fire()}selectLines(t,i){const s=this.wasmTerm.getDimensions();t=Math.max(0,Math.min(t,s.rows-1)),i=Math.max(0,Math.min(i,s.rows-1)),t>i&&([t,i]=[i,t]);const r=this.getViewportY();this.selectionStart={col:0,absoluteRow:r+t},this.selectionEnd={col:s.cols-1,absoluteRow:r+i},this.requestRender(),this.selectionChangedEmitter.fire()}getSelectionPosition(){const t=this.normalizeSelection();if(t)return{start:{x:t.startCol,y:t.startRow},end:{x:t.endCol,y:t.endRow}}}deselect(){this.clearSelection(),this.selectionChangedEmitter.fire()}focus(){const t=this.renderer.getCanvas();t.parentElement&&t.parentElement.focus()}getSelectionCoords(){return this.normalizeSelection()}getDirtySelectionRows(){return this.dirtySelectionRows}clearDirtySelectionRows(){this.dirtySelectionRows.clear()}get onSelectionChange(){return this.selectionChangedEmitter.event}dispose(){this.selectionChangedEmitter.dispose(),this.stopAutoScroll(),this.boundMouseUpHandler&&(document.removeEventListener("mouseup",this.boundMouseUpHandler),this.boundMouseUpHandler=null),this.boundDocumentMouseMoveHandler&&(document.removeEventListener("mousemove",this.boundDocumentMouseMoveHandler),this.boundDocumentMouseMoveHandler=null),this.boundContextMenuHandler&&(this.renderer.getCanvas().removeEventListener("contextmenu",this.boundContextMenuHandler),this.boundContextMenuHandler=null),this.boundClickHandler&&(document.removeEventListener("click",this.boundClickHandler),this.boundClickHandler=null)}attachEventListeners(){const t=this.renderer.getCanvas();t.addEventListener("mousedown",i=>{if(i.button===0){t.parentElement&&t.parentElement.focus();const s=this.pixelToCell(i.offsetX,i.offsetY);this.hasSelection()&&this.clearSelection();const r=this.viewportRowToAbsolute(s.row);this.selectionStart={col:s.col,absoluteRow:r},this.selectionEnd={col:s.col,absoluteRow:r},this.isSelecting=!0}}),t.addEventListener("mousemove",i=>{if(this.isSelecting){this.markCurrentSelectionDirty();const s=this.pixelToCell(i.offsetX,i.offsetY),r=this.viewportRowToAbsolute(s.row);this.selectionEnd={col:s.col,absoluteRow:r},this.requestRender(),this.updateAutoScroll(i.offsetY,t.clientHeight)}}),t.addEventListener("mouseleave",i=>{if(this.isSelecting){const s=t.getBoundingClientRect();i.clientY<s.top?this.startAutoScroll(-1):i.clientY>s.bottom&&this.startAutoScroll(1)}}),t.addEventListener("mouseenter",()=>{this.isSelecting&&this.stopAutoScroll()}),this.boundDocumentMouseMoveHandler=i=>{if(this.isSelecting){const s=t.getBoundingClientRect(),r=Math.max(s.left,Math.min(i.clientX,s.right)),o=Math.max(s.top,Math.min(i.clientY,s.bottom)),n=r-s.left,l=o-s.top;if((i.clientX<s.left||i.clientX>s.right||i.clientY<s.top||i.clientY>s.bottom)&&(i.clientY<s.top?this.startAutoScroll(-1):i.clientY>s.bottom?this.startAutoScroll(1):this.stopAutoScroll(),this.autoScrollDirection===0)){this.markCurrentSelectionDirty();const a=this.pixelToCell(n,l),c=this.viewportRowToAbsolute(a.row);this.selectionEnd={col:a.col,absoluteRow:c},this.requestRender()}}},document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.addEventListener("mousedown",i=>{this.mouseDownTarget=i.target}),this.boundMouseUpHandler=i=>{if(this.isSelecting){this.isSelecting=!1,this.stopAutoScroll();const s=this.getSelection();s&&(this.copyToClipboard(s),this.selectionChangedEmitter.fire())}},document.addEventListener("mouseup",this.boundMouseUpHandler),t.addEventListener("dblclick",i=>{const s=this.pixelToCell(i.offsetX,i.offsetY),r=this.getWordAtCell(s.col,s.row);if(r){const o=this.viewportRowToAbsolute(s.row);this.selectionStart={col:r.startCol,absoluteRow:o},this.selectionEnd={col:r.endCol,absoluteRow:o},this.requestRender();const n=this.getSelection();n&&(this.copyToClipboard(n),this.selectionChangedEmitter.fire())}}),this.boundContextMenuHandler=i=>{if(this.renderer.getCanvas().getBoundingClientRect(),this.textarea.style.position="fixed",this.textarea.style.left=`${i.clientX}px`,this.textarea.style.top=`${i.clientY}px`,this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.zIndex="1000",this.textarea.style.opacity="0",this.textarea.style.pointerEvents="auto",this.hasSelection()){const s=this.getSelection();this.textarea.value=s,this.textarea.select(),this.textarea.setSelectionRange(0,s.length)}else this.textarea.value="";this.textarea.focus(),setTimeout(()=>{const s=()=>{this.textarea.style.pointerEvents="none",this.textarea.style.zIndex="-10",this.textarea.style.width="0",this.textarea.style.height="0",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.value="",document.removeEventListener("click",s),document.removeEventListener("contextmenu",s),this.textarea.removeEventListener("blur",s)};document.addEventListener("click",s,{once:!0}),document.addEventListener("contextmenu",s,{once:!0}),this.textarea.addEventListener("blur",s,{once:!0})},10)},t.addEventListener("contextmenu",this.boundContextMenuHandler),this.boundClickHandler=i=>{if(this.isSelecting||this.mouseDownTarget&&t.contains(this.mouseDownTarget))return;const s=i.target;t.contains(s)||this.hasSelection()&&this.clearSelection()},document.addEventListener("click",this.boundClickHandler)}markCurrentSelectionDirty(){const t=this.normalizeSelection();if(t)for(let i=t.startRow;i<=t.endRow;i++)this.dirtySelectionRows.add(i)}updateAutoScroll(t,i){const s=A.AUTO_SCROLL_EDGE_SIZE;t<s?this.startAutoScroll(-1):t>i-s?this.startAutoScroll(1):this.stopAutoScroll()}startAutoScroll(t){this.autoScrollInterval!==null&&this.autoScrollDirection===t||(this.stopAutoScroll(),this.autoScrollDirection=t,this.autoScrollInterval=setInterval(()=>{if(!this.isSelecting){this.stopAutoScroll();return}const i=A.AUTO_SCROLL_SPEED*this.autoScrollDirection;if(this.terminal.scrollLines(i),this.selectionEnd){const s=this.wasmTerm.getDimensions();if(this.autoScrollDirection<0){const r=this.viewportRowToAbsolute(0);r<this.selectionEnd.absoluteRow&&(this.selectionEnd={col:0,absoluteRow:r})}else{const r=this.viewportRowToAbsolute(s.rows-1);r>this.selectionEnd.absoluteRow&&(this.selectionEnd={col:s.cols-1,absoluteRow:r})}}this.requestRender()},A.AUTO_SCROLL_INTERVAL))}stopAutoScroll(){this.autoScrollInterval!==null&&(clearInterval(this.autoScrollInterval),this.autoScrollInterval=null),this.autoScrollDirection=0}pixelToCell(t,i){const s=this.renderer.getMetrics(),r=Math.floor(t/s.width),o=Math.floor(i/s.height);return{col:Math.max(0,Math.min(r,this.terminal.cols-1)),row:Math.max(0,Math.min(o,this.terminal.rows-1))}}normalizeSelection(){if(!this.selectionStart||!this.selectionEnd)return null;let{col:t,absoluteRow:i}=this.selectionStart,{col:s,absoluteRow:r}=this.selectionEnd;(i>r||i===r&&t>s)&&([t,s]=[s,t],[i,r]=[r,i]);let o=this.absoluteRowToViewport(i),n=this.absoluteRowToViewport(r);const l=this.wasmTerm.getDimensions(),a=l.rows-1;return n<0||o>a?null:(o<0&&(o=0,t=0),n>a&&(n=a,s=l.cols-1),{startCol:t,startRow:o,endCol:s,endRow:n})}getWordAtCell(t,i){const s=this.wasmTerm.getLine(i);if(!s)return null;const r=l=>{if(!l||l.codepoint===0)return!1;const a=String.fromCodePoint(l.codepoint);return/[\w-]/.test(a)};if(!r(s[t]))return null;let o=t;for(;o>0&&r(s[o-1]);)o--;let n=t;for(;n<s.length-1&&r(s[n+1]);)n++;return{startCol:o,endCol:n}}async copyToClipboard(t){if(navigator.clipboard&&navigator.clipboard.writeText)try{await navigator.clipboard.writeText(t);return}catch{}const i=document.activeElement;try{const s=this.textarea;s.value=t,s.style.position="fixed",s.style.left="-9999px",s.style.top="0",s.style.width="1px",s.style.height="1px",s.style.opacity="0",s.focus(),s.select(),s.setSelectionRange(0,t.length);const r=document.execCommand("copy");i&&i.focus(),r||console.error("❌ execCommand copy failed")}catch(s){console.error("❌ Fallback copy failed:",s),i&&i.focus()}}requestRender(){}};H.AUTO_SCROLL_EDGE_SIZE=30;H.AUTO_SCROLL_SPEED=3;H.AUTO_SCROLL_INTERVAL=50;let ut=H;class mt{constructor(t={}){this.unicode={get activeVersion(){return"15.1"}},this.dataEmitter=new L,this.resizeEmitter=new L,this.bellEmitter=new L,this.selectionChangeEmitter=new L,this.keyEmitter=new L,this.titleChangeEmitter=new L,this.scrollEmitter=new L,this.renderEmitter=new L,this.cursorMoveEmitter=new L,this.onData=this.dataEmitter.event,this.onResize=this.resizeEmitter.event,this.onBell=this.bellEmitter.event,this.onSelectionChange=this.selectionChangeEmitter.event,this.onKey=this.keyEmitter.event,this.onTitleChange=this.titleChangeEmitter.event,this.onScroll=this.scrollEmitter.event,this.onRender=this.renderEmitter.event,this.onCursorMove=this.cursorMoveEmitter.event,this.isOpen=!1,this.isDisposed=!1,this.addons=[],this.currentTitle="",this.viewportY=0,this.targetViewportY=0,this.lastCursorY=0,this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.scrollbarDragStartViewportY=0,this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.SCROLLBAR_HIDE_DELAY_MS=1500,this.SCROLLBAR_FADE_DURATION_MS=200,this.animateScroll=()=>{if(!this.wasmTerm||this.scrollAnimationStartTime===void 0)return;const s=this.options.smoothScrollDuration??100,r=this.targetViewportY-this.viewportY;if(Math.abs(r)<.01){this.viewportY=this.targetViewportY,this.scrollEmitter.fire(Math.floor(this.viewportY)),this.getScrollbackLength()>0&&this.showScrollbar(),this.scrollAnimationFrame=void 0,this.scrollAnimationStartTime=void 0,this.scrollAnimationStartY=void 0;return}const o=1-(1/(s/1e3*60))**2;this.viewportY+=r*o;const n=Math.floor(this.viewportY);this.scrollEmitter.fire(n),this.getScrollbackLength()>0&&this.showScrollbar(),this.scrollAnimationFrame=requestAnimationFrame(this.animateScroll)},this.handleMouseMove=s=>{if(!(!this.canvas||!this.renderer||!this.wasmTerm)){if(this.isDraggingScrollbar){this.processScrollbarDrag(s);return}if(this.linkDetector){if(this.mouseMoveThrottleTimeout){this.pendingMouseMove=s;return}this.processMouseMove(s),this.mouseMoveThrottleTimeout=window.setTimeout(()=>{if(this.mouseMoveThrottleTimeout=void 0,this.pendingMouseMove){const r=this.pendingMouseMove;this.pendingMouseMove=void 0,this.processMouseMove(r)}},16)}}},this.handleMouseLeave=()=>{var s,r;this.renderer&&this.wasmTerm&&((this.renderer.hoveredHyperlinkId||0)>0&&this.renderer.setHoveredHyperlinkId(0),this.renderer.setHoveredLinkRange(null)),this.currentHoveredLink&&((r=(s=this.currentHoveredLink).hover)==null||r.call(s,!1),this.currentHoveredLink=void 0,this.element&&(this.element.style.cursor="text"))},this.handleClick=async s=>{if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const r=this.canvas.getBoundingClientRect(),o=Math.floor((s.clientX-r.left)/this.renderer.charWidth),n=Math.floor((s.clientY-r.top)/this.renderer.charHeight),l=this.wasmTerm.getScrollbackLength();let a;const c=this.getViewportY(),d=Math.max(0,Math.floor(c));if(d>0)if(n<d)a=l-d+n;else{const p=n-d;a=l+p}else a=l+n;const m=await this.linkDetector.getLinkAt(o,a);m&&(m.activate(s),(s.ctrlKey||s.metaKey)&&s.preventDefault())},this.handleWheel=s=>{var r,o,n;if(s.preventDefault(),s.stopPropagation(),!(this.customWheelEventHandler&&this.customWheelEventHandler(s)))if(((r=this.wasmTerm)==null?void 0:r.isAlternateScreen())??!1){const l=s.deltaY>0?"down":"up",a=Math.min(Math.abs(Math.round(s.deltaY/33)),5);for(let c=0;c<a;c++)l==="up"?this.dataEmitter.fire("\x1B[A"):this.dataEmitter.fire("\x1B[B")}else{let l;if(s.deltaMode===WheelEvent.DOM_DELTA_PIXEL){const a=((n=(o=this.renderer)==null?void 0:o.getMetrics())==null?void 0:n.height)??20;l=s.deltaY/a}else s.deltaMode===WheelEvent.DOM_DELTA_LINE?l=s.deltaY:s.deltaMode===WheelEvent.DOM_DELTA_PAGE?l=s.deltaY*this.rows:l=s.deltaY/33;if(l!==0){const a=this.viewportY-l;this.smoothScrollTo(a)}}},this.handleMouseDown=s=>{if(!this.canvas||!this.renderer||!this.wasmTerm)return;const r=this.wasmTerm.getScrollbackLength();if(r===0)return;const o=this.canvas.getBoundingClientRect(),n=s.clientX-o.left,l=s.clientY-o.top,a=o.width,c=o.height,d=8,m=a-d-4,p=4;if(n>=m&&n<=m+d){s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation();const u=c-p*2,f=this.rows,_=r+f,v=Math.max(20,f/_*u),g=this.viewportY/r,E=p+(u-v)*(1-g);if(l>=E&&l<=E+v)this.isDraggingScrollbar=!0,this.scrollbarDragStart=l,this.scrollbarDragStartViewportY=this.viewportY,this.canvas&&(this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none");else{const y=1-(l-p)/u,M=Math.round(y*r);this.scrollToLine(Math.max(0,Math.min(r,M)))}}},this.handleMouseUp=()=>{this.isDraggingScrollbar&&(this.isDraggingScrollbar=!1,this.scrollbarDragStart=null,this.canvas&&(this.canvas.style.userSelect="",this.canvas.style.webkitUserSelect=""),this.scrollbarVisible&&this.getScrollbackLength()>0&&this.showScrollbar())},this.ghostty=t.ghostty??wt();const i={cols:t.cols??80,rows:t.rows??24,cursorBlink:t.cursorBlink??!1,cursorStyle:t.cursorStyle??"block",theme:t.theme??{},scrollback:t.scrollback??1e4,fontSize:t.fontSize??15,fontFamily:t.fontFamily??"monospace",allowTransparency:t.allowTransparency??!1,convertEol:t.convertEol??!1,disableStdin:t.disableStdin??!1,smoothScrollDuration:t.smoothScrollDuration??100};this.options=new Proxy(i,{set:(s,r,o)=>{const n=s[r];return s[r]=o,this.isOpen&&this.handleOptionChange(r,o,n),!0}}),this.cols=this.options.cols,this.rows=this.options.rows,this.buffer=new rt(this)}handleOptionChange(t,i,s){if(i!==s)switch(t){case"disableStdin":break;case"cursorBlink":case"cursorStyle":this.renderer&&(this.renderer.setCursorStyle(this.options.cursorStyle),this.renderer.setCursorBlink(this.options.cursorBlink));break;case"theme":this.renderer&&console.warn("ghostty-web: theme changes after open() are not yet fully supported");break;case"fontSize":this.renderer&&(this.renderer.setFontSize(this.options.fontSize),this.handleFontChange());break;case"fontFamily":this.renderer&&(this.renderer.setFontFamily(this.options.fontFamily),this.handleFontChange());break;case"cols":case"rows":this.resize(this.options.cols,this.options.rows);break}}handleFontChange(){if(!this.renderer||!this.wasmTerm||!this.canvas)return;this.selectionManager&&this.selectionManager.clearSelection(),this.renderer.resize(this.cols,this.rows);const t=this.renderer.getMetrics();this.canvas.width=t.width*this.cols,this.canvas.height=t.height*this.rows,this.canvas.style.width=`${t.width*this.cols}px`,this.canvas.style.height=`${t.height*this.rows}px`,this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}parseColorToHex(t){if(!t)return 0;if(t.startsWith("#")){let s=t.slice(1);s.length===3&&(s=s[0]+s[0]+s[1]+s[1]+s[2]+s[2]);const r=Number.parseInt(s,16);return Number.isNaN(r)?0:r}const i=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(i){const s=Number.parseInt(i[1],10),r=Number.parseInt(i[2],10),o=Number.parseInt(i[3],10);return s<<16|r<<8|o}return 0}buildWasmConfig(){const t=this.options.theme,i=this.options.scrollback;if(!t&&i===1e4)return;const s=[this.parseColorToHex(t?.black),this.parseColorToHex(t?.red),this.parseColorToHex(t?.green),this.parseColorToHex(t?.yellow),this.parseColorToHex(t?.blue),this.parseColorToHex(t?.magenta),this.parseColorToHex(t?.cyan),this.parseColorToHex(t?.white),this.parseColorToHex(t?.brightBlack),this.parseColorToHex(t?.brightRed),this.parseColorToHex(t?.brightGreen),this.parseColorToHex(t?.brightYellow),this.parseColorToHex(t?.brightBlue),this.parseColorToHex(t?.brightMagenta),this.parseColorToHex(t?.brightCyan),this.parseColorToHex(t?.brightWhite)];return{scrollbackLimit:i,fgColor:this.parseColorToHex(t?.foreground),bgColor:this.parseColorToHex(t?.background),cursorColor:this.parseColorToHex(t?.cursor),palette:s}}open(t){if(this.isOpen)throw new Error("Terminal is already open");if(this.isDisposed)throw new Error("Terminal has been disposed");this.element=t,this.isOpen=!0;try{t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.setAttribute("contenteditable","true"),t.addEventListener("beforeinput",r=>r.preventDefault()),t.setAttribute("role","textbox"),t.setAttribute("aria-label","Terminal input"),t.setAttribute("aria-multiline","true");const i=this.buildWasmConfig();this.wasmTerm=this.ghostty.createTerminal(this.cols,this.rows,i),this.canvas=document.createElement("canvas"),this.canvas.style.display="block",t.appendChild(this.canvas),this.textarea=document.createElement("textarea"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.setAttribute("tabindex","0"),this.textarea.setAttribute("aria-label","Terminal input"),this.textarea.style.position="absolute",this.textarea.style.left="0",this.textarea.style.top="0",this.textarea.style.width="1px",this.textarea.style.height="1px",this.textarea.style.padding="0",this.textarea.style.border="none",this.textarea.style.margin="0",this.textarea.style.opacity="0",this.textarea.style.clipPath="inset(50%)",this.textarea.style.overflow="hidden",this.textarea.style.whiteSpace="nowrap",this.textarea.style.resize="none",t.appendChild(this.textarea);const s=this.textarea;this.canvas.addEventListener("mousedown",r=>{r.preventDefault(),s.focus()}),this.canvas.addEventListener("touchend",r=>{r.preventDefault(),s.focus()}),this.renderer=new dt(this.canvas,{fontSize:this.options.fontSize,fontFamily:this.options.fontFamily,cursorStyle:this.options.cursorStyle,cursorBlink:this.options.cursorBlink,theme:this.options.theme}),this.renderer.resize(this.cols,this.rows),this.inputHandler=new lt(this.ghostty,t,r=>{this.options.disableStdin||this.dataEmitter.fire(r)},()=>{this.bellEmitter.fire()},r=>{this.keyEmitter.fire(r)},this.customKeyEventHandler,r=>{var o;return((o=this.wasmTerm)==null?void 0:o.getMode(r,!1))??!1}),this.selectionManager=new ut(this,this.renderer,this.wasmTerm,this.textarea),this.renderer.setSelectionManager(this.selectionManager),this.selectionManager.onSelectionChange(()=>{this.selectionChangeEmitter.fire()}),this.textarea.addEventListener("paste",r=>{var o;r.preventDefault(),r.stopPropagation();const n=(o=r.clipboardData)==null?void 0:o.getData("text");n&&this.paste(n)}),this.linkDetector=new at(this),this.linkDetector.registerProvider(new ht(this)),this.linkDetector.registerProvider(new ct(this)),t.addEventListener("mousedown",this.handleMouseDown,{capture:!0}),t.addEventListener("mousemove",this.handleMouseMove),t.addEventListener("mouseleave",this.handleMouseLeave),t.addEventListener("click",this.handleClick),document.addEventListener("mouseup",this.handleMouseUp),t.addEventListener("wheel",this.handleWheel,{passive:!1,capture:!0}),this.renderer.render(this.wasmTerm,!0,this.viewportY,this,this.scrollbarOpacity),this.startRenderLoop(),this.focus()}catch(i){throw this.isOpen=!1,this.cleanupComponents(),new Error(`Failed to open terminal: ${i}`)}}write(t,i){this.assertOpen(),this.options.convertEol&&typeof t=="string"&&(t=t.replace(/\n/g,`\r
|
|
3
3
|
`)),this.writeInternal(t,i)}writeInternal(t,i){var s;this.wasmTerm.write(t),this.processTerminalResponses(),typeof t=="string"&&t.includes("\x07")?this.bellEmitter.fire():t instanceof Uint8Array&&t.includes(7)&&this.bellEmitter.fire(),(s=this.linkDetector)==null||s.invalidateCache(),this.viewportY!==0&&this.scrollToBottom(),typeof t=="string"&&t.includes("\x1B]")&&this.checkForTitleChange(t),i&&requestAnimationFrame(i)}writeln(t,i){if(typeof t=="string")this.write(t+`\r
|
|
4
4
|
`,i);else{const s=new Uint8Array(t.length+2);s.set(t),s[t.length]=13,s[t.length+1]=10,this.write(s,i)}}paste(t){this.assertOpen(),!this.options.disableStdin&&(this.wasmTerm.hasBracketedPaste()?this.dataEmitter.fire("\x1B[200~"+t+"\x1B[201~"):this.dataEmitter.fire(t))}input(t,i=!1){this.assertOpen(),!this.options.disableStdin&&(i?this.dataEmitter.fire(t):this.write(t))}resize(t,i){if(this.assertOpen(),t===this.cols&&i===this.rows)return;this.cols=t,this.rows=i,this.wasmTerm.resize(t,i),this.renderer.resize(t,i);const s=this.renderer.getMetrics();this.canvas.width=s.width*t,this.canvas.height=s.height*i,this.canvas.style.width=`${s.width*t}px`,this.canvas.style.height=`${s.height*i}px`,this.resizeEmitter.fire({cols:t,rows:i}),this.renderer.render(this.wasmTerm,!0,this.viewportY,this)}clear(){this.assertOpen(),this.wasmTerm.write("\x1B[2J\x1B[H")}reset(){this.assertOpen(),this.wasmTerm&&this.wasmTerm.free();const t=this.buildWasmConfig();this.wasmTerm=this.ghostty.createTerminal(this.cols,this.rows,t),this.renderer.clear(),this.currentTitle=""}focus(){this.isOpen&&this.element&&(this.element.focus(),setTimeout(()=>{var t;(t=this.element)==null||t.focus()},0))}blur(){this.isOpen&&this.element&&this.element.blur()}loadAddon(t){t.activate(this),this.addons.push(t)}getSelection(){var t;return((t=this.selectionManager)==null?void 0:t.getSelection())||""}hasSelection(){var t;return((t=this.selectionManager)==null?void 0:t.hasSelection())||!1}clearSelection(){var t;(t=this.selectionManager)==null||t.clearSelection()}selectAll(){var t;(t=this.selectionManager)==null||t.selectAll()}select(t,i,s){var r;(r=this.selectionManager)==null||r.select(t,i,s)}selectLines(t,i){var s;(s=this.selectionManager)==null||s.selectLines(t,i)}getViewportY(){return this.viewportY}getSelectionPosition(){var t;return(t=this.selectionManager)==null?void 0:t.getSelectionPosition()}attachCustomKeyEventHandler(t){this.customKeyEventHandler=t,this.inputHandler&&this.inputHandler.setCustomKeyEventHandler(t)}attachCustomWheelEventHandler(t){this.customWheelEventHandler=t}registerLinkProvider(t){if(!this.linkDetector)throw new Error("Terminal must be opened before registering link providers");this.linkDetector.registerProvider(t)}scrollLines(t){if(!this.wasmTerm)throw new Error("Terminal not open");const i=this.getScrollbackLength(),s=Math.max(0,Math.min(i,this.viewportY-t));s!==this.viewportY&&(this.viewportY=s,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar())}scrollPages(t){this.scrollLines(t*this.rows)}scrollToTop(){const t=this.getScrollbackLength();t>0&&this.viewportY!==t&&(this.viewportY=t,this.scrollEmitter.fire(this.viewportY),this.showScrollbar())}scrollToBottom(){this.viewportY!==0&&(this.viewportY=0,this.scrollEmitter.fire(this.viewportY),this.getScrollbackLength()>0&&this.showScrollbar())}scrollToLine(t){const i=this.getScrollbackLength(),s=Math.max(0,Math.min(i,t));s!==this.viewportY&&(this.viewportY=s,this.scrollEmitter.fire(this.viewportY),i>0&&this.showScrollbar())}smoothScrollTo(t){if(!this.wasmTerm)return;const i=this.getScrollbackLength(),s=Math.max(0,Math.min(i,t));if((this.options.smoothScrollDuration??100)===0){this.viewportY=s,this.targetViewportY=s,this.scrollEmitter.fire(Math.floor(this.viewportY)),i>0&&this.showScrollbar();return}this.targetViewportY=s,!this.scrollAnimationFrame&&(this.scrollAnimationStartTime=Date.now(),this.scrollAnimationStartY=this.viewportY,this.animateScroll())}dispose(){if(!this.isDisposed){this.isDisposed=!0,this.isOpen=!1,this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.scrollAnimationFrame&&(cancelAnimationFrame(this.scrollAnimationFrame),this.scrollAnimationFrame=void 0),this.mouseMoveThrottleTimeout&&(clearTimeout(this.mouseMoveThrottleTimeout),this.mouseMoveThrottleTimeout=void 0),this.pendingMouseMove=void 0;for(const t of this.addons)t.dispose();this.addons=[],this.cleanupComponents(),this.dataEmitter.dispose(),this.resizeEmitter.dispose(),this.bellEmitter.dispose(),this.selectionChangeEmitter.dispose(),this.keyEmitter.dispose(),this.titleChangeEmitter.dispose(),this.scrollEmitter.dispose(),this.renderEmitter.dispose(),this.cursorMoveEmitter.dispose()}}startRenderLoop(){const t=()=>{if(!this.isDisposed&&this.isOpen){this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity);const i=this.wasmTerm.getCursor();i.y!==this.lastCursorY&&(this.lastCursorY=i.y,this.cursorMoveEmitter.fire()),this.animationFrameId=requestAnimationFrame(t)}};t()}getScrollbackLine(t){return this.wasmTerm?this.wasmTerm.getScrollbackLine(t):null}getScrollbackLength(){return this.wasmTerm?this.wasmTerm.getScrollbackLength():0}cleanupComponents(){this.selectionManager&&(this.selectionManager.dispose(),this.selectionManager=void 0),this.inputHandler&&(this.inputHandler.dispose(),this.inputHandler=void 0),this.renderer&&(this.renderer.dispose(),this.renderer=void 0),this.canvas&&this.canvas.parentNode&&(this.canvas.parentNode.removeChild(this.canvas),this.canvas=void 0),this.textarea&&this.textarea.parentNode&&(this.textarea.parentNode.removeChild(this.textarea),this.textarea=void 0),this.element&&(this.element.removeEventListener("wheel",this.handleWheel),this.element.removeEventListener("mousedown",this.handleMouseDown,{capture:!0}),this.element.removeEventListener("mousemove",this.handleMouseMove),this.element.removeEventListener("mouseleave",this.handleMouseLeave),this.element.removeEventListener("click",this.handleClick),this.element.removeAttribute("contenteditable"),this.element.removeAttribute("role"),this.element.removeAttribute("aria-label"),this.element.removeAttribute("aria-multiline")),this.isOpen&&typeof document<"u"&&document.removeEventListener("mouseup",this.handleMouseUp),this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.linkDetector&&(this.linkDetector.dispose(),this.linkDetector=void 0),this.wasmTerm&&(this.wasmTerm.free(),this.wasmTerm=void 0),this.ghostty=void 0,this.element=void 0,this.textarea=void 0}assertOpen(){if(this.isDisposed)throw new Error("Terminal has been disposed");if(!this.isOpen)throw new Error("Terminal must be opened before use. Call terminal.open(parent) first.")}processMouseMove(t){if(!this.canvas||!this.renderer||!this.linkDetector||!this.wasmTerm)return;const i=this.canvas.getBoundingClientRect(),s=Math.floor((t.clientX-i.left)/this.renderer.charWidth),r=Math.floor((t.clientY-i.top)/this.renderer.charHeight);let o=0,n=null;const l=this.getViewportY(),a=Math.max(0,Math.floor(l));if(a>0){const f=this.wasmTerm.getScrollbackLength();if(r<a){const _=f-a+r;n=this.wasmTerm.getScrollbackLine(_)}else{const _=r-a;n=this.wasmTerm.getLine(_)}}else n=this.wasmTerm.getLine(r);n&&s>=0&&s<n.length&&(o=n[s].hyperlink_id);const c=this.renderer.hoveredHyperlinkId||0;o!==c&&this.renderer.setHoveredHyperlinkId(o);const d=this.wasmTerm.getScrollbackLength();let m;const p=this.getViewportY(),u=Math.max(0,Math.floor(p));if(u>0)if(r<u)m=d-u+r;else{const f=r-u;m=d+f}else m=d+r;this.linkDetector.getLinkAt(s,m).then(f=>{var _,v,g,E;if(f!==this.currentHoveredLink&&((v=(_=this.currentHoveredLink)==null?void 0:_.hover)==null||v.call(_,!1),this.currentHoveredLink=f,(g=f?.hover)==null||g.call(f,!0),this.element&&(this.element.style.cursor=f?"pointer":"text"),this.renderer))if(f){const y=((E=this.wasmTerm)==null?void 0:E.getScrollbackLength())||0,M=this.getViewportY(),P=Math.max(0,Math.floor(M)),C=f.range.start.y-y+P,S=f.range.end.y-y+P;C<this.rows&&S>=0?this.renderer.setHoveredLinkRange({startX:f.range.start.x,startY:Math.max(0,C),endX:f.range.end.x,endY:Math.min(this.rows-1,S)}):this.renderer.setHoveredLinkRange(null)}else this.renderer.setHoveredLinkRange(null)}).catch(f=>{console.warn("Link detection error:",f)})}processScrollbarDrag(t){if(!this.canvas||!this.renderer||!this.wasmTerm||this.scrollbarDragStart===null)return;const i=this.wasmTerm.getScrollbackLength();if(i===0)return;const s=this.canvas.getBoundingClientRect(),r=t.clientY-s.top-this.scrollbarDragStart,o=s.height-8,n=this.rows,l=i+n,a=Math.max(20,n/l*o),c=-r/(o-a),d=Math.round(c*i),m=this.scrollbarDragStartViewportY+d;this.scrollToLine(Math.max(0,Math.min(i,m)))}showScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible?this.scrollbarOpacity=1:(this.scrollbarVisible=!0,this.scrollbarOpacity=0,this.fadeInScrollbar()),this.isDraggingScrollbar||(this.scrollbarHideTimeout=window.setTimeout(()=>{this.hideScrollbar()},this.SCROLLBAR_HIDE_DELAY_MS))}hideScrollbar(){this.scrollbarHideTimeout&&(window.clearTimeout(this.scrollbarHideTimeout),this.scrollbarHideTimeout=void 0),this.scrollbarVisible&&this.fadeOutScrollbar()}fadeInScrollbar(){const t=Date.now(),i=()=>{const s=Date.now()-t,r=Math.min(s/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=r,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),r<1&&requestAnimationFrame(i)};i()}fadeOutScrollbar(){const t=Date.now(),i=this.scrollbarOpacity,s=()=>{const r=Date.now()-t,o=Math.min(r/this.SCROLLBAR_FADE_DURATION_MS,1);this.scrollbarOpacity=i*(1-o),this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,this.scrollbarOpacity),o<1?requestAnimationFrame(s):(this.scrollbarVisible=!1,this.scrollbarOpacity=0,this.renderer&&this.wasmTerm&&this.renderer.render(this.wasmTerm,!1,this.viewportY,this,0))};s()}processTerminalResponses(){if(!this.wasmTerm)return;const t=this.wasmTerm.readResponse();t&&this.dataEmitter.fire(t)}checkForTitleChange(t){const i=/\x1b\]([012]);([^\x07\x1b]*?)(?:\x07|\x1b\\)/g;let s=null;for(;(s=i.exec(t))!==null;){const r=s[1],o=s[2];(r==="0"||r==="2")&&o!==this.currentTitle&&(this.currentTitle=o,this.titleChangeEmitter.fire(o))}}getMode(t,i=!1){return this.assertOpen(),this.wasmTerm.getMode(t,i)}hasBracketedPaste(){return this.assertOpen(),this.wasmTerm.hasBracketedPaste()}hasFocusEvents(){return this.assertOpen(),this.wasmTerm.hasFocusEvents()}hasMouseTracking(){return this.assertOpen(),this.wasmTerm.hasMouseTracking()}}const gt=2,pt=1,ft=15,_t=100;class Et{constructor(){this._isResizing=!1}activate(t){this._terminal=t}dispose(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeDebounceTimer&&(clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=void 0),this._lastCols=void 0,this._lastRows=void 0,this._terminal=void 0}fit(){if(this._isResizing)return;const t=this.proposeDimensions();if(!t||!this._terminal)return;const i=this._terminal,s=i.cols,r=i.rows;if(!(t.cols===this._lastCols&&t.rows===this._lastRows||t.cols===s&&t.rows===r)){this._lastCols=t.cols,this._lastRows=t.rows,this._isResizing=!0;try{i.resize&&typeof i.resize=="function"&&i.resize(t.cols,t.rows)}finally{setTimeout(()=>{this._isResizing=!1},50)}}}proposeDimensions(){var t;if(!((t=this._terminal)!=null&&t.element))return;const i=this._terminal.renderer;if(!i||typeof i.getMetrics!="function")return;const s=i.getMetrics();if(!s||s.width===0||s.height===0)return;const r=this._terminal.element;if(typeof r.clientWidth>"u")return;const o=window.getComputedStyle(r),n=Number.parseInt(o.getPropertyValue("padding-top"))||0,l=Number.parseInt(o.getPropertyValue("padding-bottom"))||0,a=Number.parseInt(o.getPropertyValue("padding-left"))||0,c=Number.parseInt(o.getPropertyValue("padding-right"))||0,d=r.clientWidth,m=r.clientHeight;if(d===0||m===0)return;const p=d-a-c-ft,u=m-n-l,f=Math.max(gt,Math.floor(p/s.width)),_=Math.max(pt,Math.floor(u/s.height));return{cols:f,rows:_}}observeResize(){var t;(t=this._terminal)!=null&&t.element&&(this._resizeObserver||(this._resizeObserver=new ResizeObserver(i=>{this._isResizing||!i[0]||(this._resizeDebounceTimer&&clearTimeout(this._resizeDebounceTimer),this._resizeDebounceTimer=setTimeout(()=>{this.fit()},_t))}),this._resizeObserver.observe(this._terminal.element)))}}function wt(){throw new Error(`ghostty-web not initialized. Call init() before creating Terminal instances.
|