vibelet 1.2.227 → 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-BTBKDi0n.js +1 -0
- package/dist/web/assets/{ChipGroup-FQF2g0Fr.js → ChipGroup-ImS6VTKx.js} +1 -1
- package/dist/web/assets/{DiffDrawer-CHjkoGPE.js → DiffDrawer-sMBIj4bW.js} +2 -2
- package/dist/web/assets/{FilesControlPanel-A7LFhjRm.js → FilesControlPanel-4hHS85Mr.js} +1 -1
- package/dist/web/assets/GlobalPendingDialog-BCLMQc_r.js +1 -0
- package/dist/web/assets/ImageViewer-BvBKQ6wE.js +1 -0
- package/dist/web/assets/LanguageSettingsPanel-DTDvB4l2.js +1 -0
- package/dist/web/assets/NewSessionDialog-LttGZHY7.js +1 -0
- package/dist/web/assets/NewSessionDialog-cuN6a01X.css +1 -0
- package/dist/web/assets/{NotificationSettingsPanel-B_k_PfhC.js → NotificationSettingsPanel-BS01O3sC.js} +1 -1
- package/dist/web/assets/TerminalControlPanel-B7S_ebVy.js +13 -0
- package/dist/web/assets/{ThemeSettingsPanel-DNDIWk0L.js → ThemeSettingsPanel-DVaJ6nGu.js} +1 -1
- package/dist/web/assets/{arrow-right-Boi1uHFr.js → arrow-right-ORILUMdJ.js} +1 -1
- package/dist/web/assets/{collectMessageImages-BROUPbis.js → collectMessageImages-lfAaZW_Y.js} +1 -1
- package/dist/web/assets/{file-editor-FileCodeEditor-CTEWh6kV.js → file-editor-FileCodeEditor-ZAqN9Q2f.js} +3 -3
- package/dist/web/assets/{file-editor-MarkdownLivePreview-Blr8OOKh.js → file-editor-MarkdownLivePreview-DXTFwUnj.js} +1 -1
- package/dist/web/assets/{file-editor-index-iFiQtQEr.js → file-editor-index-BBHGMD89.js} +1 -1
- package/dist/web/assets/{file-editor-index-CxU5Gq1E.js → file-editor-index-BC0Bqs8t.js} +1 -1
- package/dist/web/assets/{file-editor-index-DvdSLdIk.js → file-editor-index-Bo2dEHVF.js} +1 -1
- package/dist/web/assets/{file-editor-index-Cj9yLeGr.js → file-editor-index-Byun61j6.js} +1 -1
- package/dist/web/assets/{file-editor-index-Dv8iMJMj.js → file-editor-index-C4S-qKVH.js} +1 -1
- package/dist/web/assets/{file-editor-index-Ckq0jexT.js → file-editor-index-DKQvp2Qx.js} +1 -1
- package/dist/web/assets/{file-editor-index-C1T947NK.js → file-editor-index-Dc2gxJQY.js} +1 -1
- package/dist/web/assets/{file-editor-index-DvenUGpC.js → file-editor-index-Dj3dV82Z.js} +1 -1
- package/dist/web/assets/{folder-plus-tHXFtdSw.js → folder-plus-DHw5YJHP.js} +1 -1
- package/dist/web/assets/{highlighted-body-TPN3WLV5-D5c7I9mI.js → highlighted-body-TPN3WLV5-DDb5MlJt.js} +1 -1
- package/dist/web/assets/index-Be6TVbvo.css +1 -0
- package/dist/web/assets/index-ConcKf33.js +71 -0
- package/dist/web/assets/{mermaid-O7DHMXV3-BIyESbw5.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-DfyOZYmt.js +0 -12
- package/dist/web/assets/App-t0H-03RW.css +0 -1
- package/dist/web/assets/BrowserControlPanel-dQOp1WlN.js +0 -1
- package/dist/web/assets/GlobalPendingDialog-BeOMI3dc.js +0 -1
- package/dist/web/assets/ImageViewer-BQ9YKQDY.js +0 -1
- package/dist/web/assets/LanguageSettingsPanel-Benilh-Y.js +0 -1
- package/dist/web/assets/NewSessionDialog-B0YMv6RR.js +0 -1
- package/dist/web/assets/NewSessionDialog-CxPwD87T.css +0 -1
- package/dist/web/assets/TerminalControlPanel-DCmHOa9Y.js +0 -13
- package/dist/web/assets/index-CoCv7_xG.css +0 -1
- package/dist/web/assets/index-P4_gSQhN.js +0 -71
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.skill-suggestion-list button[aria-selected=true]{background:var(--card-alt);box-shadow:inset 2px 0 var(--accent)}.composer .send-button{position:relative}.composer .send-button[data-state=sending]:disabled{background:var(--text);color:var(--bg);opacity:1}.composer-send-spinner{animation:composer-send-spin 1s linear infinite}.composer-send-progress{position:absolute;inset:3px;border:1px solid color-mix(in srgb,currentColor 20%,transparent);border-top-color:currentColor;border-radius:50%;animation:composer-send-spin 1.8s linear infinite;pointer-events:none}.composer .send-button .composer-send-stop{width:10px;height:10px;fill:currentColor;stroke-width:0}.composer-send-status{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}@keyframes composer-send-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.composer-send-spinner,.composer-send-progress{animation:none}}.message>.message-actions{justify-content:flex-start;margin-top:8px}.message>.message-markdown-source{padding:0;border:0;background:transparent;box-shadow:none;border-radius:0;font-family:var(--font-mono);font-size:13px;line-height:1.65;-webkit-user-select:text;user-select:text}.message-image-attachments{display:flex;align-items:flex-start;flex-direction:column;gap:8px;margin-top:12px}.message-image-preview{display:flex;width:fit-content;align-items:center;justify-content:center;max-width:100%;padding:0;margin:6px 0;border:1px solid var(--border);border-radius:8px;overflow:hidden;background:var(--card-alt);color:var(--text-secondary);vertical-align:middle;cursor:zoom-in}.message-image-preview img{display:block;max-width:min(100%,480px);max-height:320px;width:auto;height:auto;object-fit:contain}.message-markdown td .message-image-preview img{max-width:160px;max-height:120px}.message-image-placeholder{display:inline-flex;align-items:center;gap:8px;padding:16px;font-size:12px}.message-image-placeholder svg{width:16px;height:16px}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as k,r as c,m as g,j as s,E as y}from"./index-P4_gSQhN.js";import{a as E,A as N}from"./arrow-right-Boi1uHFr.js";import{X as R,G as x}from"./App-DfyOZYmt.js";const A=[["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"}]],B=k("rotate-cw",A);function L(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 t=new URL(a);return/^https?:$/.test(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}const C=(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 t=[];let l=-1,d=!1;const u=()=>o({url:t[l]||"",title:"",loading:d,canGoBack:l>0,canGoForward:l<t.length-1}),e=()=>{d=!0,a.src=t[l],u()};return a.addEventListener("load",()=>{d=!1,u()}),{navigate:p=>{t.splice(l+1),t.push(p),l++,e()},back:()=>{l>0&&(l--,e())},forward:()=>{l<t.length-1&&(l++,e())},reload:()=>{l>=0&&e()},stop:()=>{d=!1;try{a.contentWindow?.stop()}catch{}u()},destroy:()=>a.remove()}},G={url:"",title:"",loading:!1,canGoBack:!1,canGoForward:!1};function S({t:r,onTitleChange:o}){const a=c.useRef(null),t=c.useRef(null),l=c.useRef(null),[d,u]=c.useState(""),[e,p]=c.useState(G),[h,b]=c.useState(!1);c.useEffect(()=>{e.url&&o?.(e.title||new URL(e.url).hostname)},[e.title,e.url,r.browser]);const w=!!g().mountBrowser;c.useEffect(()=>{if(!a.current)return;const i=(g().mountBrowser||C)(a.current,f=>{p(f),document.activeElement!==l.current&&u(f.url)});return t.current=i,()=>{t.current=null,i.destroy()}},[]);const j=n=>{n.preventDefault();const i=L(d);if(!i||new URL(i).origin===window.location.origin){b(!0);return}b(!1),u(i),t.current?.navigate(i),l.current?.blur()},m=(n,i,f,v=!1)=>s.jsx("button",{type:"button",title:n,"aria-label":n,onClick:f,disabled:v,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:[m(r.browserBack,E,()=>t.current?.back(),!e.canGoBack),m(r.browserForward,N,()=>t.current?.forward(),!e.canGoForward),m(w&&e.loading?r.browserStop:r.browserReload,w&&e.loading?R:B,()=>w&&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(y,{"aria-hidden":"true"})})]}),s.jsxs("form",{className:"browser-address",onSubmit:j,children:[s.jsx(x,{"aria-hidden":"true"}),s.jsx("input",{ref:l,value:d,onChange:n=>{u(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:a,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})]}),!w&&e.url&&s.jsx("p",{className:"browser-status",children:r.browserEmbedHint})]})}export{S as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as y,j as e,r as k,u as v,i as f}from"./index-P4_gSQhN.js";import{S as A,d as I,X as p,C as m,K as q,t as S}from"./App-DfyOZYmt.js";const K=[["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"}]],P=y("bell-ring",K);function N({activeApproval:i,activeQuestion:t,busy:d,questionAnswers:c,t:s,onCancelQuestion:h,onQuestionChoice:l,onRespondApproval:o,onRespondQuestion:u}){const r=!!(i||t);return e.jsxs(e.Fragment,{children:[r?null:e.jsxs("section",{className:"control-section",children:[e.jsx("h2",{children:s.pendingActions}),e.jsx("p",{className:"empty-copy",children:s.noPendingActions})]}),i?e.jsxs("section",{className:"attention-panel",children:[e.jsxs("div",{className:"attention-head",children:[e.jsx(A,{"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("h2",{children:s.approvalRequired}),e.jsx("p",{children:i.toolName})]})]}),e.jsx("p",{children:i.description}),e.jsx("pre",{children:I(i.input)}),e.jsxs("div",{className:"attention-actions",children:[e.jsxs("button",{type:"button",className:"danger-button",onClick:()=>o(!1),disabled:d,children:[e.jsx(p,{"aria-hidden":"true"}),s.deny]}),e.jsxs("button",{type:"button",className:"approve-button",onClick:()=>o(!0),disabled:d,children:[e.jsx(m,{"aria-hidden":"true"}),s.approve]})]})]}):null,t?e.jsxs("section",{className:"attention-panel",children:[e.jsxs("div",{className:"attention-head",children:[e.jsx(q,{"aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("h2",{children:s.inputNeeded}),e.jsx("p",{children:s.notificationQuestionCount(t.questions.length)})]})]}),t.questions.map(a=>e.jsxs("div",{className:"question-block",children:[e.jsx("strong",{children:a.question}),e.jsx("div",{className:"choice-list",children:a.options.map(n=>{const x=(c[a.id]??[]).includes(n.label);return e.jsxs("button",{className:x?"selected":"",onClick:()=>l(a.id,n.label,a.multiSelect),type:"button",children:[e.jsx("span",{children:n.label}),n.description?e.jsx("small",{children:n.description}):null]},n.label)})})]},a.id)),e.jsxs("div",{className:"attention-actions",children:[e.jsxs("button",{type:"button",className:"danger-button",onClick:h,disabled:d,children:[e.jsx(p,{"aria-hidden":"true"}),s.cancel]}),e.jsxs("button",{type:"button",className:"approve-button",onClick:u,disabled:d,children:[e.jsx(m,{"aria-hidden":"true"}),s.submit]})]})]}):null]})}function R(i){const{activeApproval:t,activeQuestion:d,pendingCount:c,requestKey:s,sessions:h,t:l,errorText:o}=i,[u,r]=k.useState(null),a=c>0&&u!==s,n=()=>r(s),x=v(n,void 0,a),j=b=>{const g=h.find(C=>C.sessionId===b);return g?S(g):b};return c===0?null:f.createPortal(a?e.jsxs("div",{className:"global-pending-layer",children:[e.jsx("div",{className:"global-pending-backdrop","aria-hidden":"true",onClick:n}),e.jsxs("div",{className:"global-pending-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"global-pending-title",tabIndex:-1,ref:x,children:[e.jsxs("header",{className:"global-pending-header",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"global-pending-title",children:l.pendingActions}),e.jsx("p",{"aria-live":"polite",children:l.pendingActionCount(c)})]}),e.jsx("button",{className:"icon-button",type:"button","aria-label":l.close,title:l.close,onClick:n,children:e.jsx(p,{"aria-hidden":"true"})})]}),e.jsxs("div",{className:"global-pending-content",children:[t&&e.jsxs("section",{"data-pending-session":t.sessionId,children:[e.jsx("p",{className:"global-pending-session",children:j(t.sessionId)}),e.jsx(N,{...i,activeQuestion:null})]}),d&&e.jsxs("section",{"data-pending-session":d.sessionId,children:[e.jsx("p",{className:"global-pending-session",children:j(d.sessionId)}),e.jsx(N,{...i,activeApproval:null})]}),o&&e.jsx("p",{role:"alert",className:"global-pending-error",children:o})]})]})]}):e.jsxs("button",{className:"global-pending-reminder",type:"button",onClick:()=>r(null),"aria-label":l.pendingActionCount(c),title:l.pendingActions,children:[e.jsx(P,{"aria-hidden":"true"}),e.jsx("span",{children:l.pendingActionCount(c)})]}),document.body)}export{R as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as N,r as p,e as k,l as E,u as L,i as A,j as a}from"./index-P4_gSQhN.js";import{u as C,r as M,f as P,I as D,L as O,a as S,X as T}from"./App-DfyOZYmt.js";import{A as W,a as z}from"./arrow-right-Boi1uHFr.js";const B=[["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"}]],R=N("file-image",B);async function F(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,n)=>s.toBlob(t=>t?m(t):n(new Error("Image conversion failed")),"image/png"))}function K({request:r,onClose:i}){const[s,d]=p.useState(r.index),[m,n]=p.useState("idle"),t=r.images[s],{url:c,error:x,fail:w}=C(t.src,t.cwd),v=M(t.src),u=t.alt||P(v??t.src),h=k(E().language),o=h==="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"}:h==="zh-TW"?{title:"圖片檢視器",previous:"上一張",next:"下一張",copy:"複製圖片",copied:"圖片已複製",failed:"圖片複製失敗",open:"在 Tab 開啟原檔案",close:"關閉",unavailable:"無法載入圖片"}:{title:"图片查看器",previous:"上一张",next:"下一张",copy:"复制图片",copied:"图片已复制",failed:"图片复制失败",open:"在 Tab 打开原文件",close:"关闭",unavailable:"无法加载图片"},y=L(i);p.useEffect(()=>{const e=document.getElementById("vibelet-workspace"),g=e?.inert;return e&&(e.inert=!0),()=>{e&&(e.inert=!!g)}},[]),p.useEffect(()=>n("idle"),[s]);const f=e=>d(g=>Math.max(0,Math.min(r.images.length-1,g+e))),b=async()=>{if(c)try{await navigator.clipboard.write([new ClipboardItem({"image/png":F(c)})]),n("copied")}catch{n("failed")}},l=(e,g,j,I=!1)=>a.jsx("button",{type:"button",className:"icon-button",title:e,"aria-label":e,onClick:j,disabled:I,children:g});return A.createPortal(a.jsx("div",{className:"image-viewer-backdrop",onClick:e=>{e.target===e.currentTarget&&i()},children:a.jsxs("div",{ref:y,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(S,{}),()=>{b()},!c||x),l(o.open,a.jsx(R,{}),()=>{i(),r.onOpen(v??t.src,t.cwd)}),l(o.close,a.jsx(T,{}),i)]}),a.jsxs("div",{className:"image-viewer-stage",children:[l(o.previous,a.jsx(z,{}),()=>f(-1),s===0),a.jsx("div",{className:"image-viewer-content",children:x?a.jsxs("p",{role:"status",children:[a.jsx(D,{}),o.unavailable]}):c?a.jsx("img",{src:c,alt:u,onError:w},t.src):a.jsx(O,{className:"session-running-icon","aria-label":o.title})}),l(o.next,a.jsx(W,{}),()=>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{K as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./index-P4_gSQhN.js";import{C as i}from"./ChipGroup-FQF2g0Fr.js";import{F as o}from"./App-DfyOZYmt.js";function h({language:s,t:a,onLanguageChange:l}){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(i,{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:n=>l(n)})]})]}),e.jsx(o,{language:s})]})}export{h as LanguageSettingsPanel};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as G,k as M,r as a,u as Q,i as Y,j as t}from"./index-P4_gSQhN.js";import{j as T,X as Z,e as N,g as ee,S as te}from"./App-DfyOZYmt.js";import{F as se}from"./folder-plus-tHXFtdSw.js";const ne=[["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"}]],ae=G("bot",ne),A="vibelet.web.recentCreations";function V(n){try{const s=JSON.parse(M().getItem(A)||"{}")[n];return Array.isArray(s)?s.filter(i=>typeof i.cwd=="string"&&["claude","codex"].includes(i.agent)&&Number.isFinite(i.createdAt)).slice(0,8):[]}catch{return[]}}function oe(n,s){try{const i=JSON.parse(M().getItem(A)||"{}");i[n]=[s,...V(n).filter(c=>c.cwd!==s.cwd||c.agent!==s.agent)].slice(0,8),M().setItem(A,JSON.stringify(i))}catch{}}function ce(n){const{t:s,device:i,onClose:c,onListDirectories:E}=n,o=s.newSession!=="New session",[l,w]=a.useState(n.cwd),[j,F]=a.useState(n.agent),[I,W]=a.useState(n.approvalMode),[L,y]=a.useState(n.model),[O,_]=a.useState(""),[d,z]=a.useState([]),[u,R]=a.useState(-1),[x,v]=a.useState(!1),[B,b]=a.useState(""),[$,C]=a.useState(!1),[k,J]=a.useState(!1),[h,p]=a.useState(null),S=a.useRef(null),q=Q(c,S),[P]=a.useState(()=>V(i));a.useEffect(()=>{if(z([]),R(-1),b(""),!x||!n.connected)return;let e=!1;const r=l.lastIndexOf("/"),f=r<0?".":l.slice(0,r+1)||"/",U=l.slice(r+1).toLowerCase(),X=window.setTimeout(()=>{C(!0),E(f).then(m=>{e||z(m.filter(g=>g.isDirectory&&g.name.toLowerCase().startsWith(U)).map(g=>T(f,g.name)).slice(0,12))}).catch(m=>{e||b(String(m instanceof Error?m.message:m))}).finally(()=>{e||C(!1)})},180);return()=>{e=!0,window.clearTimeout(X),C(!1)}},[l,x,n.connected,E]);const D=e=>{w(e+(e.endsWith("/")?"":"/")),S.current?.focus()},H=()=>{!l.trim()||!n.connected||k||(n.onCreate(l.trim(),j,{draft:O,approvalMode:I,model:L}),oe(i,{cwd:l.trim(),agent:j,createdAt:Date.now()}),c())},K=()=>{D(l||n.cwd||"/"),v(!0)};return Y.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:q,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(Z,{})})]}),t.jsxs("form",{onSubmit:e=>{e.preventDefault(),H()},children:[t.jsx("div",{className:"new-session-agents",children:["claude","codex"].map(e=>t.jsxs("button",{type:"button","aria-pressed":j===e,onClick:()=>{F(e),y("")},children:[t.jsx(ae,{size:18}),e==="claude"?"Claude":"Codex"]},e))}),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:S,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":u>=0?`new-session-path-${u}`:void 0,onFocus:()=>v(!0),onBlur:()=>v(!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(),R(r=>r<0?e.key==="ArrowDown"?0:d.length-1:(r+(e.key==="ArrowDown"?1:-1)+d.length)%d.length)):(e.key==="Enter"||e.key==="Tab")&&u>=0&&(e.preventDefault(),D(d[u])))}}),t.jsx("button",{type:"button",className:"icon-button","aria-label":s.browseDirectories,title:s.browseDirectories,onMouseDown:e=>e.preventDefault(),onClick:()=>{K()},children:t.jsx(N,{})}),t.jsx("button",{type:"button",className:"icon-button","aria-label":o?"新建文件夹":"New folder",title:o?"新建文件夹":"New folder",onMouseDown:e=>e.preventDefault(),onClick:()=>p(""),children:t.jsx(se,{})})]})]}),x&&d.length>0&&t.jsx("div",{className:"new-session-paths",id:"new-session-paths",role:"listbox",children:d.map((e,r)=>t.jsxs("button",{type:"button",id:`new-session-path-${r}`,role:"option","aria-selected":u===r,onMouseDown:f=>f.preventDefault(),onClick:()=>D(e),title:e,children:[t.jsx(N,{size:14}),e]},e))}),$&&t.jsx("small",{children:s.loadingDirectories}),h!==null&&t.jsxs("div",{className:"new-session-path-row",children:[t.jsx("input",{"aria-label":o?"文件夹名称":"Folder name",value:h,onChange:e=>p(e.target.value)}),t.jsx("button",{type:"button",disabled:k||!h.trim()||/[/\\]/.test(h),onClick:async()=>{J(!0),b("");try{const e=T(l,h.trim());await n.onCreateDirectory(e),w(e),p(null)}catch(e){b(String(e))}finally{J(!1)}},children:o?"创建文件夹":"Create folder"}),t.jsx("button",{type:"button",onClick:()=>p(null),children:s.close})]}),P.length>0&&t.jsxs("section",{className:"new-session-recent",children:[t.jsx("h3",{children:o?"最近创建":"Recent creations"}),P.map(e=>t.jsxs("button",{type:"button",title:e.cwd,onClick:()=>{w(e.cwd),F(e.agent),y("")},children:[t.jsx(N,{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:O,onChange:e=>_(e.target.value),rows:3})]}),t.jsxs("div",{className:"new-session-options",children:[t.jsx(ee,{icon:te,label:s.approvalMode,menuLabel:s.approvalMode,value:I,onSelect:W,options:[{value:"normal",label:s.approvalNormal},{value:"plan",label:s.approvalPlan},{value:"acceptEdits",label:s.approvalEdits},{value:"autoApprove",label:s.approvalAuto}]}),t.jsxs("label",{children:[o?"模型":"Model",t.jsx("input",{"aria-label":o?"模型":"Model",placeholder:"Default",value:L,onChange:e=>y(e.target.value)})]})]}),!n.connected&&t.jsx("p",{role:"status",children:o?"请先连接设备,再创建会话。":"Connect a device before creating a session."}),B&&t.jsx("p",{role:"alert",children:B}),t.jsxs("footer",{children:[t.jsx("small",{children:o?"创建后在聊天中发送消息":"Send your message in the new conversation"}),t.jsx("button",{type:"button",onClick:c,children:o?"取消":"Cancel"}),t.jsx("button",{className:"primary",type:"submit",disabled:!n.connected||!l.trim()||k,children:s.newSession})]})]})]})]}),document.body)}export{ce as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.new-session-layer{position:fixed;inset:0;z-index:1000;display:grid;place-items:center;padding:24px}.new-session-backdrop{position:absolute;inset:0;background:#00000038}.new-session-dialog{position:relative;width:min(580px,100%);max-height:calc(100vh - 64px);overflow:auto;border-radius:16px;background:var(--bg-elevated);color:var(--text);box-shadow:0 16px 70px #0003;border:1px solid var(--border);padding:22px}.new-session-dialog header,.new-session-dialog footer,.new-session-path-row,.new-session-options{display:flex;align-items:center;gap:8px}.new-session-dialog header{justify-content:space-between;margin-bottom:18px}.new-session-dialog h2{font-size:18px;margin:0}.new-session-dialog h3{font-size:12px;font-weight:500;color:var(--text-muted);margin:12px 0 5px}.new-session-field{display:grid;gap:7px;margin-top:18px;font-size:13px}.new-session-dialog input,.new-session-dialog textarea{border:1px solid var(--border);background:transparent;border-radius:7px;padding:9px 10px;min-width:0;color:inherit;font:inherit}.new-session-path-row>input{flex:1}.new-session-dialog input:focus,.new-session-dialog textarea:focus{outline:none;border-color:var(--accent)}.new-session-agents{display:flex;gap:8px}.new-session-agents button{display:flex;align-items:center;gap:8px;padding:10px 16px;border:1px solid var(--border);background:transparent;border-radius:9px}.new-session-agents button[aria-pressed=true]{border-color:var(--accent);background:var(--accent-soft)}.new-session-paths{max-height:160px;overflow:auto;border:1px solid var(--border);border-radius:8px;margin-top:6px;padding:5px}.new-session-paths button,.new-session-recent button{display:flex;align-items:center;gap:8px;width:100%;text-align:left;border:0;background:transparent;padding:7px 8px;border-radius:5px;font-size:12px}.new-session-paths button[aria-selected=true],.new-session-paths button:hover,.new-session-recent button:hover{background:var(--accent-soft)}.new-session-recent span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.new-session-options{margin:12px 0;flex-wrap:wrap}.new-session-options label{display:flex;align-items:center;gap:8px;font-size:12px}.new-session-options input{width:160px}.new-session-dialog footer{margin-top:20px;justify-content:flex-end}.new-session-dialog footer small{margin-right:auto;font-size:11px;color:var(--text-muted)}.new-session-dialog footer button{width:auto;padding:8px 14px;border-radius:7px}.new-session-dialog button{font:inherit;color:inherit;cursor:pointer}.new-session-dialog .icon-button{width:32px;height:32px;display:grid;place-items:center;background:transparent;border:0;border-radius:6px;padding:6px}.new-session-dialog .icon-button svg{width:18px;height:18px}.new-session-dialog button:disabled{opacity:.45;cursor:default}.new-session-dialog input:focus,.new-session-dialog textarea:focus{box-shadow:none;outline:none}.new-session-dialog footer button{background:transparent;border:1px solid var(--border)}.new-session-dialog footer button.primary{background:var(--accent);border-color:var(--accent);color:#fff}.new-session-dialog textarea{resize:vertical}.new-session-dialog .new-session-field input:focus-visible,.new-session-dialog .new-session-field textarea:focus-visible{outline:none;box-shadow:none}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import{c as j,_ as q,r as T,j as w}from"./index-P4_gSQhN.js";import{z as Z,X as V,B as J}from"./App-DfyOZYmt.js";const Q=[["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"}]],tt=j("eraser",Q);var U=(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))(U||{}),X=(e=>(e[e.RELEASE=0]="RELEASE",e[e.PRESS=1]="PRESS",e[e.REPEAT=2]="REPEAT",e))(X||{}),a=(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))(a||{}),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||{}),K=(e=>(e[e.NONE=0]="NONE",e[e.PARTIAL=1]="PARTIAL",e[e.FULL=2]="FULL",e))(K||{});const W=80;var y=(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))(y||{});class O{constructor(t){this.exports=t.exports,this.memory=this.exports.memory}createKeyEncoder(){return new et(this.exports)}createTerminal(t=80,i=24,s){return new st(this.exports,this.memory,t,i,s)}static async load(t){if(t)return O.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 O.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 q(async()=>{const{readFile:n}=await Promise.resolve().then(()=>bt);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 O(r)}}class et{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(U.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 f=new TextEncoder().encode(t.utf8),u=this.exports.ghostty_wasm_alloc_u8_array(f.length);new Uint8Array(this.exports.memory.buffer).set(f,u),this.exports.ghostty_key_event_set_utf8(o,u,f.length),this.exports.ghostty_wasm_free_u8_array(u,f.length)}const n=32,l=this.exports.ghostty_wasm_alloc_u8_array(n),h=this.exports.ghostty_wasm_alloc_usize(),c=this.exports.ghostty_key_encoder_encode(this.encoder,o,l,n,h);if(c!==0)throw this.exports.ghostty_wasm_free_u8_array(l,n),this.exports.ghostty_wasm_free_usize(h),this.exports.ghostty_key_event_free(o),new Error(`Failed to encode key: ${c}`);const d=r.getUint32(h,!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(h),this.exports.ghostty_key_event_free(o),m}dispose(){this.encoder&&(this.exports.ghostty_key_encoder_free(this.encoder),this.encoder=0)}}const $=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(W);if(l===0)throw new Error("Failed to allocate config (out of memory)");try{const h=new DataView(this.memory.buffer);let c=l;h.setUint32(c,o.scrollbackLimit??1e4,!0),c+=4,h.setUint32(c,o.fgColor??0,!0),c+=4,h.setUint32(c,o.bgColor??0,!0),c+=4,h.setUint32(c,o.cursorColor??0,!0),c+=4;for(let d=0;d<16;d++)h.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,W)}}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()!==K.NONE}needsFullRedraw(){return this.update()===K.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 h=0;h<s;h++){const c=h*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,h=this.cellPool[n];h.codepoint=o.getUint32(l,!0),h.fg_r=r[l+4],h.fg_g=r[l+5],h.fg_b=r[l+6],h.bg_r=r[l+7],h.bg_g=r[l+8],h.bg_b=r[l+9],h.flags=r[l+10],h.width=r[l+11],h.hyperlink_id=o.getUint16(l+12,!0),h.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)}};$.CELL_SIZE=16;let st=$;class x{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 it{constructor(t){this.bufferChangeEmitter=new x,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 B(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 rt(r,n,i.cols)}getNullCell(){return this.nullCell}getWasmTerm(){return this.terminal.wasmTerm}}class rt{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 B({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 B(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 h=this.getCell(l);if(h){const c=h.getChars();n+=c}}return t&&(n=n.trimEnd()),n}}class B{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&y.BOLD?1:0}isItalic(){return this.cell.flags&y.ITALIC?1:0}isUnderline(){return this.cell.flags&y.UNDERLINE?1:0}isStrikethrough(){return this.cell.flags&y.STRIKETHROUGH?1:0}isBlink(){return this.cell.flags&y.BLINK?1:0}isInverse(){return this.cell.flags&y.INVERSE?1:0}isInvisible(){return this.cell.flags&y.INVISIBLE?1:0}isFaint(){return this.cell.flags&y.FAINT?1:0}getHyperlinkId(){return this.cell.hyperlink_id}getCodepoint(){return this.cell.codepoint}isDim(){return(this.cell.flags&y.FAINT)!==0}}const ot={KeyA:a.A,KeyB:a.B,KeyC:a.C,KeyD:a.D,KeyE:a.E,KeyF:a.F,KeyG:a.G,KeyH:a.H,KeyI:a.I,KeyJ:a.J,KeyK:a.K,KeyL:a.L,KeyM:a.M,KeyN:a.N,KeyO:a.O,KeyP:a.P,KeyQ:a.Q,KeyR:a.R,KeyS:a.S,KeyT:a.T,KeyU:a.U,KeyV:a.V,KeyW:a.W,KeyX:a.X,KeyY:a.Y,KeyZ:a.Z,Digit1:a.ONE,Digit2:a.TWO,Digit3:a.THREE,Digit4:a.FOUR,Digit5:a.FIVE,Digit6:a.SIX,Digit7:a.SEVEN,Digit8:a.EIGHT,Digit9:a.NINE,Digit0:a.ZERO,Enter:a.ENTER,Escape:a.ESCAPE,Backspace:a.BACKSPACE,Tab:a.TAB,Space:a.SPACE,Minus:a.MINUS,Equal:a.EQUAL,BracketLeft:a.BRACKET_LEFT,BracketRight:a.BRACKET_RIGHT,Backslash:a.BACKSLASH,Semicolon:a.SEMICOLON,Quote:a.QUOTE,Backquote:a.GRAVE,Comma:a.COMMA,Period:a.PERIOD,Slash:a.SLASH,CapsLock:a.CAPS_LOCK,F1:a.F1,F2:a.F2,F3:a.F3,F4:a.F4,F5:a.F5,F6:a.F6,F7:a.F7,F8:a.F8,F9:a.F9,F10:a.F10,F11:a.F11,F12:a.F12,PrintScreen:a.PRINT_SCREEN,ScrollLock:a.SCROLL_LOCK,Pause:a.PAUSE,Insert:a.INSERT,Home:a.HOME,PageUp:a.PAGE_UP,Delete:a.DELETE,End:a.END,PageDown:a.PAGE_DOWN,ArrowRight:a.RIGHT,ArrowLeft:a.LEFT,ArrowDown:a.DOWN,ArrowUp:a.UP,NumLock:a.NUM_LOCK,NumpadDivide:a.KP_DIVIDE,NumpadMultiply:a.KP_MULTIPLY,NumpadSubtract:a.KP_MINUS,NumpadAdd:a.KP_PLUS,NumpadEnter:a.KP_ENTER,Numpad1:a.KP_1,Numpad2:a.KP_2,Numpad3:a.KP_3,Numpad4:a.KP_4,Numpad5:a.KP_5,Numpad6:a.KP_6,Numpad7:a.KP_7,Numpad8:a.KP_8,Numpad9:a.KP_9,Numpad0:a.KP_0,NumpadDecimal:a.KP_PERIOD,IntlBackslash:a.INTL_BACKSLASH,ContextMenu:a.CONTEXT_MENU,F13:a.F13,F14:a.F14,F15:a.F15,F16:a.F16,F17:a.F17,F18:a.F18,F19:a.F19,F20:a.F20,F21:a.F21,F22:a.F22,F23:a.F23,F24:a.F24};class nt{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 ot[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 a.ENTER:o="\r";break;case a.TAB:o=" ";break;case a.BACKSPACE:o="";break;case a.ESCAPE:o="\x1B";break;case a.HOME:o="\x1B[H";break;case a.END:o="\x1B[F";break;case a.INSERT:o="\x1B[2~";break;case a.DELETE:o="\x1B[3~";break;case a.PAGE_UP:o="\x1B[5~";break;case a.PAGE_DOWN:o="\x1B[6~";break;case a.F1:o="\x1BOP";break;case a.F2:o="\x1BOQ";break;case a.F3:o="\x1BOR";break;case a.F4:o="\x1BOS";break;case a.F5:o="\x1B[15~";break;case a.F6:o="\x1B[17~";break;case a.F7:o="\x1B[18~";break;case a.F8:o="\x1B[19~";break;case a.F9:o="\x1B[20~";break;case a.F10:o="\x1B[21~";break;case a.F11:o="\x1B[23~";break;case a.F12:o="\x1B[24~";break}if(o!==null){t.preventDefault(),this.onDataCallback(o);return}}const r=X.PRESS;try{if(this.getModeCallback){const h=this.getModeCallback(1);this.encoder.setOption(U.CURSOR_KEY_APPLICATION,h)}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 lt{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 h=l.getHyperlinkId();if(h>0){this.linkCache.set(`h${h}`,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 at{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 h=l.getHyperlinkId();if(h===0||r.has(h))continue;r.add(h);const c=this.findLinkRange(h,t,n);if(!this.terminal.wasmTerm)continue;const d=this.terminal.wasmTerm.getHyperlinkUri(h);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 f=m.getCell(m.length-1);if(!f||f.getHyperlinkId()!==t)break;o=d,n=0;for(let u=m.length-1;u>=0;u--){const p=m.getCell(u);if(!p||p.getHyperlinkId()!==t){n=u+1;break}}if(n===0)d--;else break}}let l=i,h=s;const c=r.getLine(l);if(c){for(;h<c.length-1;){const d=c.getCell(h+1);if(!d||d.getHyperlinkId()!==t)break;h++}if(h===c.length-1){let d=l+1;const m=r.length;for(;d<m;){const f=r.getLine(d);if(!f||f.length===0)break;const u=f.getCell(0);if(!u||u.getHyperlinkId()!==t)break;l=d,h=0;for(let p=0;p<f.length;p++){const _=f.getCell(p);if(!_)break;if(_.getHyperlinkId()!==t){h=p-1;break}h=p}if(h===f.length-1)d++;else break}}}return{start:{x:n,y:o},end:{x:h,y:l}}}dispose(){}}const Y=class D{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);D.URL_REGEX.lastIndex=0;let n=D.URL_REGEX.exec(o);for(;n!==null;){let l=n[0];const h=n.index;let c=n.index+l.length-1;const d=l.replace(D.TRAILING_PUNCTUATION,"");d.length<l.length&&(l=d,c=h+l.length-1),l.length>8&&s.push({text:l,range:{start:{x:h,y:t},end:{x:c,y:t}},activate:m=>{(m.ctrlKey||m.metaKey)&&window.open(l,"_blank","noopener,noreferrer")}}),n=D.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(){}};Y.URL_REGEX=/(?:https?:\/\/|mailto:|ftp:\/\/|ssh:\/\/|git:\/\/|tel:|magnet:|gemini:\/\/|gopher:\/\/|news:)[\w\-.~:\/?#@!$&*+,;=%]+/gi;Y.TRAILING_PUNCTUATION=/[.,;!?)\]]+$/;let ht=Y;const G={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 ct{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={...G,...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(),h=t.getDimensions(),c=r?r.getScrollbackLength():0;(n=t.needsFullRedraw)!=null&&n.call(t)&&(i=!0),(this.canvas.width!==h.cols*this.metrics.width*this.devicePixelRatio||this.canvas.height!==h.rows*this.metrics.height*this.devicePixelRatio)&&(this.resize(h.cols,h.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,h.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,h.cols)}}const m=this.selectionManager&&this.selectionManager.hasSelection(),f=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++)f.add(E)}if(this.selectionManager){const g=this.selectionManager.getDirtySelectionRows();if(g.size>0){for(const E of g)f.add(E);this.selectionManager.clearDirtySelectionRows()}}const u=new Set,p=this.hoveredHyperlinkId!==this.previousHoveredHyperlinkId,_=JSON.stringify(this.hoveredLinkRange)!==JSON.stringify(this.previousHoveredLinkRange);if(p){for(let g=0;g<h.rows;g++){let E=null;if(s>0)if(g<s&&r){const v=c-Math.floor(s)+g;E=r.getScrollbackLine(v)}else{const v=g-Math.floor(s);E=t.getLine(v)}else E=t.getLine(g);if(E){for(const v of E)if(v.hyperlink_id===this.hoveredHyperlinkId||v.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 b=new Set;for(let g=0;g<h.rows;g++)(s>0||i||t.isRowDirty(g)||f.has(g)||u.has(g))&&(b.add(g),g>0&&b.add(g-1),g<h.rows-1&&b.add(g+1));for(let g=0;g<h.rows;g++){if(!b.has(g))continue;let E=null;if(s>0)if(g<s&&r){const v=c-Math.floor(s)+g;E=r.getScrollbackLine(v)}else{const v=s>0?g-Math.floor(s):g;E=t.getLine(v)}else E=t.getLine(g);E&&this.renderLine(E,g,h.cols)}s===0&&l.visible&&this.cursorVisible&&this.renderCursor(l.x,l.y),r&&o>0&&this.renderScrollbar(s,c,h.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,h=t.bg_g,c=t.bg_b;t.flags&y.INVERSE&&(l=t.fg_r,h=t.fg_g,c=t.fg_b),l===0&&h===0&&c===0||(this.ctx.fillStyle=this.rgbToCSS(l,h,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&y.INVISIBLE)return;const h=this.isInSelection(i,s);let c="";if(t.flags&y.ITALIC&&(c+="italic "),t.flags&y.BOLD&&(c+="bold "),this.ctx.font=`${c}${this.fontSize}px ${this.fontFamily}`,h)this.ctx.fillStyle=this.theme.selectionForeground;else{let u=t.fg_r,p=t.fg_g,_=t.fg_b;t.flags&y.INVERSE&&(u=t.bg_r,p=t.bg_g,_=t.bg_b),this.ctx.fillStyle=this.rgbToCSS(u,p,_)}t.flags&y.FAINT&&(this.ctx.globalAlpha=.5);const d=o,m=n+this.metrics.baseline;let f;if(t.grapheme_len>0&&(r=this.currentBuffer)!=null&&r.getGraphemeString?f=this.currentBuffer.getGraphemeString(s,i):f=String.fromCodePoint(t.codepoint||32),this.ctx.fillText(f,d,m),t.flags&y.FAINT&&(this.ctx.globalAlpha=1),t.flags&y.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&y.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 p=n+this.metrics.baseline+2;this.ctx.strokeStyle="#4A90E2",this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(o,p),this.ctx.lineTo(o+l,p),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={...G,...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,h=8,c=l-h-4,d=4,m=n-d*2;if(o.fillStyle=this.theme.background,o.fillRect(c-2,0,h+6,n),r<=0||i===0)return;const f=i+s,u=Math.max(20,s/f*m),p=t/i,_=d+(m-u)*(1-p);o.fillStyle=`rgba(128, 128, 128, ${.1*r})`,o.fillRect(c,d,h,m);const b=t>0?.5:.3;o.fillStyle=`rgba(128, 128, 128, ${b*r})`,o.fillRect(c,_,h,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 A=class F{constructor(t,i,s,r){this.selectionStart=null,this.selectionEnd=null,this.isSelecting=!1,this.mouseDownTarget=null,this.dirtySelectionRows=new Set,this.selectionChangedEmitter=new x,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 h=null;if(l<o)h=this.wasmTerm.getScrollbackLine(l);else{const u=l-o;h=this.wasmTerm.getLine(u)}if(!h)continue;let c=-1;const d=l===i?t:0,m=l===r?s:h.length-1;let f="";for(let u=d;u<=m;u++){const p=h[u];if(p&&p.codepoint!==0){let _;if(p.grapheme_len>0)if(l<o)_=this.wasmTerm.getScrollbackGraphemeString(l,u);else{const b=l-o;_=this.wasmTerm.getGraphemeString(b,u)}else _=String.fromCodePoint(p.codepoint);f+=_,_.trim()&&(c=f.length)}else f+=" "}c>=0?f=f.substring(0,c):f="",n+=f,l<r&&(n+=`
|
|
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 h=this.pixelToCell(n,l),c=this.viewportRowToAbsolute(h.row);this.selectionEnd={col:h.col,absoluteRow:c},this.requestRender()}}},document.addEventListener("mousemove",this.boundDocumentMouseMoveHandler),document.addEventListener("mousedown",i=>{this.mouseDownTarget=i.target}),this.boundMouseUpHandler=i=>{if(this.isSelecting){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=F.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=F.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()},F.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(),h=l.rows-1;return n<0||o>h?null:(o<0&&(o=0,t=0),n>h&&(n=h,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 h=String.fromCodePoint(l.codepoint);return/[\w-]/.test(h)};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(){}};A.AUTO_SCROLL_EDGE_SIZE=30;A.AUTO_SCROLL_SPEED=3;A.AUTO_SCROLL_INTERVAL=50;let dt=A;class ut{constructor(t={}){this.unicode={get activeVersion(){return"15.1"}},this.dataEmitter=new x,this.resizeEmitter=new x,this.bellEmitter=new x,this.selectionChangeEmitter=new x,this.keyEmitter=new x,this.titleChangeEmitter=new x,this.scrollEmitter=new x,this.renderEmitter=new x,this.cursorMoveEmitter=new x,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 h;const c=this.getViewportY(),d=Math.max(0,Math.floor(c));if(d>0)if(n<d)h=l-d+n;else{const f=n-d;h=l+f}else h=l+n;const m=await this.linkDetector.getLinkAt(o,h);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",h=Math.min(Math.abs(Math.round(s.deltaY/33)),5);for(let c=0;c<h;c++)l==="up"?this.dataEmitter.fire("\x1B[A"):this.dataEmitter.fire("\x1B[B")}else{let l;if(s.deltaMode===WheelEvent.DOM_DELTA_PIXEL){const h=((n=(o=this.renderer)==null?void 0:o.getMetrics())==null?void 0:n.height)??20;l=s.deltaY/h}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 h=this.viewportY-l;this.smoothScrollTo(h)}}},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,h=o.width,c=o.height,d=8,m=h-d-4,f=4;if(n>=m&&n<=m+d){s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation();const u=c-f*2,p=this.rows,_=r+p,b=Math.max(20,p/_*u),g=this.viewportY/r,E=f+(u-b)*(1-g);if(l>=E&&l<=E+b)this.isDraggingScrollbar=!0,this.scrollbarDragStart=l,this.scrollbarDragStartViewportY=this.viewportY,this.canvas&&(this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none");else{const v=1-(l-f)/u,M=Math.round(v*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??Et();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 it(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 ct(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 nt(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 dt(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 lt(this),this.linkDetector.registerProvider(new at(this)),this.linkDetector.registerProvider(new ht(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
|
-
`)),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
|
-
`,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(),h=Math.max(0,Math.floor(l));if(h>0){const p=this.wasmTerm.getScrollbackLength();if(r<h){const _=p-h+r;n=this.wasmTerm.getScrollbackLine(_)}else{const _=r-h;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 f=this.getViewportY(),u=Math.max(0,Math.floor(f));if(u>0)if(r<u)m=d-u+r;else{const p=r-u;m=d+p}else m=d+r;this.linkDetector.getLinkAt(s,m).then(p=>{var _,b,g,E;if(p!==this.currentHoveredLink&&((b=(_=this.currentHoveredLink)==null?void 0:_.hover)==null||b.call(_,!1),this.currentHoveredLink=p,(g=p?.hover)==null||g.call(p,!0),this.element&&(this.element.style.cursor=p?"pointer":"text"),this.renderer))if(p){const v=((E=this.wasmTerm)==null?void 0:E.getScrollbackLength())||0,M=this.getViewportY(),L=Math.max(0,Math.floor(M)),S=p.range.start.y-v+L,C=p.range.end.y-v+L;S<this.rows&&C>=0?this.renderer.setHoveredLinkRange({startX:p.range.start.x,startY:Math.max(0,S),endX:p.range.end.x,endY:Math.min(this.rows-1,C)}):this.renderer.setHoveredLinkRange(null)}else this.renderer.setHoveredLinkRange(null)}).catch(p=>{console.warn("Link detection error:",p)})}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,h=Math.max(20,n/l*o),c=-r/(o-h),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 mt=2,gt=1,pt=15,ft=100;class _t{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,h=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 f=d-h-c-pt,u=m-n-l,p=Math.max(mt,Math.floor(f/s.width)),_=Math.max(gt,Math.floor(u/s.height));return{cols:p,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()},ft))}),this._resizeObserver.observe(this._terminal.element)))}}function Et(){throw new Error(`ghostty-web not initialized. Call init() before creating Terminal instances.
|
|
5
|
-
Example:
|
|
6
|
-
import { init, Terminal } from "ghostty-web";
|
|
7
|
-
await init();
|
|
8
|
-
const term = new Terminal();
|
|
9
|
-
|
|
10
|
-
For tests, pass a Ghostty instance directly:
|
|
11
|
-
import { Ghostty, Terminal } from "ghostty-web";
|
|
12
|
-
const ghostty = await Ghostty.load();
|
|
13
|
-
const term = new Terminal({ ghostty });`)}const wt="/web/assets/ghostty-vt-DOMeXDrv.wasm";function vt(e,t){let i=!1,s="",r=0;const o={capture:!0},n=()=>{i=!0,s=""},l=c=>{i=!1,s=c.data||"",r=Date.now()},h=c=>{const d=c;if(i||d.isComposing||d.inputType!=="insertText"||!d.data)return;const m=s===d.data&&Date.now()-r<200;s="",d.preventDefault(),m||t.input(d.data,!0)};return e.addEventListener("compositionstart",n,o),e.addEventListener("compositionend",l,o),e.addEventListener("beforeinput",h,o),()=>{e.removeEventListener("compositionstart",n,o),e.removeEventListener("compositionend",l,o),e.removeEventListener("beforeinput",h,o)}}let H;async function yt(e){H??=O.load(wt).catch(m=>{throw H=void 0,m});const t=await H,i=m=>{const f=m.match(/\d+/g)?.slice(0,3).map(Number);return f?.length===3?"#"+f.map(u=>u.toString(16).padStart(2,"0")).join(""):"#202020"},s=()=>({background:i(getComputedStyle(e).backgroundColor),foreground:i(getComputedStyle(e).color),cursor:i(getComputedStyle(e).color),selectionBackground:"#80808055"}),r=new ut({ghostty:t,fontSize:12,fontFamily:"SFMono-Regular, Menlo, Monaco, monospace",cursorBlink:!0,scrollback:3e3,theme:s(),cols:80,rows:24}),o=new _t;r.loadAddon(o),r.open(e);const n=vt(e,r),l=()=>{e.clientWidth>0&&e.clientHeight>0&&o.fit()},h=new ResizeObserver(l);h.observe(e);const c=new MutationObserver(()=>{r.options.theme=s(),l()});c.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]});const d=r.dispose.bind(r);return r.dispose=()=>{n(),h.disconnect(),c.disconnect(),d()},l(),{term:r,fit:l}}const I=()=>`shell_${crypto.randomUUID()}`;function Ct({client:e,cwd:t,deviceName:i,visible:s,t:r}){const o=T.useRef(null),n=T.useRef(null),l=T.useRef(null),h=T.useRef(!1),c=T.useRef(s),d=T.useRef(s);d.current=s;const m=T.useRef(0),[f,u]=T.useState(null),[p,_]=T.useState(s&&e?"opening":"idle"),[b,g]=T.useState(""),E=T.useRef(null),v=()=>{m.current++,l.current&&e&&e.send({action:"shell.close",id:I(),terminalId:l.current.terminalId}),l.current=null,n.current?.dispose(),n.current=null,E.current=null,h.current=!1,u(null),_("idle"),g("")};T.useEffect(()=>{if(!e)return;const L=e.onMessage(C=>{C.type!=="shell.output"&&C.type!=="shell.exit"||C.terminalId===l.current?.terminalId&&(C.type==="shell.output"?n.current?.write(C.data):(l.current=null,_("exited")))}),S=e.onClose(()=>{m.current++,l.current=null,h.current=!1,_("disconnected")});return()=>{L(),S(),v()}},[e]),T.useEffect(()=>{s&&(c.current=!0)},[s]),T.useEffect(()=>{if(!s)return;c.current&&e&&(c.current=!1,!l.current&&!h.current&&M());const L=requestAnimationFrame(()=>{E.current?.(),n.current?.focus()});return()=>cancelAnimationFrame(L)},[s,e]);async function M(){if(!e||h.current||!o.current)return;v(),h.current=!0,_("opening");const L=m.current;let S,C;try{if(S=await yt(o.current),L!==m.current){S.term.dispose();return}if(n.current=S.term,E.current=S.fit,S.term.onData(P=>{l.current&&e.send({action:"shell.input",id:I(),terminalId:l.current.terminalId,data:P})}),S.term.onResize(({cols:P,rows:N})=>{l.current&&e.send({action:"shell.resize",id:I(),terminalId:l.current.terminalId,cols:P,rows:N})}),C=await e.request({action:"shell.open",id:I(),cwd:t,cols:S.term.cols,rows:S.term.rows},{timeoutMs:1e4}),L!==m.current){e.send({action:"shell.close",id:I(),terminalId:C.terminalId}),S.term.dispose();return}l.current=C,u(C),_("running"),d.current&&S.term.focus()}catch(P){if(S?.term.dispose(),L===m.current){_("idle");const N=P instanceof Error?P.message:"Terminal failed";g(N.includes("unsupported action")?r.terminal==="终端"?"此设备的 daemon 尚不支持终端,请在该设备更新 Vibelet daemon 后重连。":"This device daemon does not support terminals. Update Vibelet daemon on that device and reconnect.":N)}}finally{L===m.current&&(h.current=!1)}}return w.jsxs("section",{className:"embedded-terminal-panel","aria-label":r.terminal,"data-status":p,children:[w.jsxs("div",{className:"terminal-toolbar",children:[w.jsx("span",{className:"terminal-device",title:i,children:i||r.terminal}),w.jsxs("div",{className:"terminal-actions",children:[w.jsx("button",{type:"button","aria-label":r.openTerminal,title:r.openTerminal,disabled:!e||p==="opening"||p==="running",onClick:()=>{M()},children:w.jsx(Z,{})}),w.jsx("button",{type:"button","aria-label":r.clearTerminal,title:r.clearTerminal,disabled:!f,onClick:()=>n.current?.clear(),children:w.jsx(tt,{})}),w.jsx("button",{type:"button","aria-label":r.closeTerminal,title:r.closeTerminal,disabled:!f&&p!=="opening",onClick:v,children:w.jsx(V,{})})]})]}),w.jsx("div",{className:"terminal-directory",title:f?.cwd||t,children:f?.cwd||t}),!f&&p!=="opening"&&w.jsxs("div",{className:"terminal-empty",children:[w.jsx(J,{}),w.jsx("p",{children:r.terminalDescription}),w.jsx("button",{type:"button",disabled:!e,onClick:()=>{M()},children:r.openTerminal})]}),p==="opening"&&w.jsx("p",{className:"terminal-notice",role:"status",children:r.loading}),b&&w.jsxs("p",{className:"terminal-notice",role:"alert",children:[b,w.jsx("button",{type:"button","aria-label":r.close,title:r.close,onClick:()=>g(""),children:w.jsx(V,{})})]}),p==="exited"&&w.jsx("p",{className:"terminal-notice",role:"status",children:r.terminalExited}),p==="disconnected"&&w.jsx("p",{className:"terminal-notice",role:"status",children:r.terminalDisconnected}),w.jsx("div",{role:"region",className:"terminal-surface",ref:o,"aria-label":r.terminal})]})}const bt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{Ct as default};
|