tmux-weblink 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var wt="https://esm.sh/ghostty-web@0.4.0",vt=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function M(o){return o.replace(vt,"")}var D;function gt(){return D||(document.querySelector("link[data-tmux-web-xterm-css]")?D=Promise.resolve():(D=new Promise(o=>{let e=document.createElement("link");e.rel="stylesheet",e.href="/assets/xterm.css",e.setAttribute("data-tmux-web-xterm-css",""),e.addEventListener("load",()=>o(),{once:!0}),e.addEventListener("error",()=>o(),{once:!0}),document.head.appendChild(e)}),D))}var O=class J{terminal;fitAddon;container;constructor(e,i,r){this.container=e,this.terminal=i,this.fitAddon=r,this.terminal.loadAddon(this.fitAddon),this.terminal.open(e)}static async create(e,i,r){let[{Terminal:s},{FitAddon:f}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),gt()]),v=new s({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:i,convertEol:!1,theme:r});return new J(e,v,new f)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(e){return new Promise(i=>this.terminal.write(e,i))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(e){this.terminal.scrollToLine(Math.max(0,e))}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){let e=U(this.container);return e.width<=0||e.height<=0?!1:(this.fitAddon.fit(),!0)}focus(){this.terminal.focus()}pasteText(e){this.terminal.paste(e)}input(e){this.terminal.input(e,!1)}onData(e){this.terminal.onData(e),this.terminal.onBinary(e)}onResize(e){this.terminal.onResize(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return!!e&&(e===this.container||this.container.contains(e))}},yt=class _{terminal;container;colsValue=80;rowsValue=24;charW=0;charH=0;resizeCallbacks=[];constructor(e,i){this.container=e,this.terminal=i,this.terminal.open(e)}static async create(e,i,r){let s=await import(wt);await s.init();let f=new s.Terminal({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:i,convertEol:!1,theme:r});return new _(e,f)}get cols(){return this.colsValue}get rows(){return this.rowsValue}write(e){return new Promise(i=>this.terminal.write(e,i))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom?.()}scrollToLine(e){this.terminal.scrollToLine?.(Math.max(0,e))}isNearScrollbackTop(){let e=this.terminal.buffer?.active;return e?e.viewportY>=e.baseY:!1}viewportY(){return this.terminal.buffer?.active?.viewportY??0}baseY(){return this.terminal.buffer?.active?.baseY??0}fit(){let e=U(this.container);if(e.width<=0||e.height<=0)return!1;this.updateCellMetrics(!this.charW||!this.charH);let i=Math.floor(e.width/this.charW),r=Math.floor(e.height/this.charH);if(i<10||r<5)return!1;if(i!==this.colsValue||r!==this.rowsValue){this.colsValue=i,this.rowsValue=r,this.terminal.resize(i,r);for(let s of this.resizeCallbacks)s({cols:i,rows:r})}return!0}focus(){(this.terminal.textarea||this.container.querySelector("textarea")||this.container)?.focus?.()}pasteText(e){let i=this.terminal.getMode?.(2004)??!1;this.input(i?"\x1B[200~"+e+"\x1B[201~":e)}input(e){this.terminal.input?.(e,!1)}onData(e){this.terminal.onData(i=>e(i))}onResize(e){this.resizeCallbacks.push(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return!!e&&(e===this.container||e===this.terminal.textarea||this.container.contains(e))}updateCellMetrics(e=!1){let i=this.container.querySelector("canvas");if(i instanceof HTMLElement&&i.offsetWidth>0&&i.offsetHeight>0&&this.colsValue>0&&this.rowsValue>0){let r=i.offsetWidth/this.colsValue,s=i.offsetHeight/this.rowsValue;(e||!this.charW||!this.charH)&&(this.charW=r,this.charH=s)}(!this.charW||!this.charH)&&(this.charW=9,this.charH=18)}};function U(o){let e=o.getBoundingClientRect(),i=window.visualViewport;return i?{width:Math.min(e.width,i.width),height:Math.max(0,Math.min(e.height,i.height-Math.max(0,e.top)))}:e}function bt(o,e,i){return o.innerHTML="",o.classList.add("terminal-pending"),(async()=>{let r;if(i.renderer==="ghostty")try{r=await yt.create(o,i.scrollback,i.theme)}catch{console.error("[tmux-web] ghostty-web failed; falling back to xterm.js"),r=await O.create(o,i.scrollback,i.theme)}else r=await O.create(o,i.scrollback,i.theme);let s,f=0,v,l=null,Y=0,p="connecting",x=0,L=!1,k=[],w="",P=!1,g=1e3,C=!1,d="",u,G=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/"+encodeURIComponent(e),Q="/api/session/"+encodeURIComponent(e)+"/upload",Z=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function $(){return k.join("")+w}async function tt(t,n=0){let a=t?r.viewportY():0,h=t?r.baseY():0,m=M($());if(r.reset(),!m){t||r.scrollToBottom();return}await r.write(m),t?r.scrollToLine(h+a+n):r.scrollToBottom()}function y(t){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(t))}function et(t){let n;try{n=JSON.parse(t)}catch{p==="live"&&(w+=t,r.write(M(t)));return}if(n.type==="auth.required"){let a=localStorage.getItem("tmux-web-token");a?y({type:"auth.token",token:a}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(n.type==="auth.ok"){n.token&&localStorage.setItem("tmux-web-token",n.token),g=1e3,T(),y({type:"resize",cols:r.cols,rows:r.rows}),c();return}if(n.type==="auth.failed"){if(n.permanentLock||n.retryAfterMs&&n.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(n.message);return}return}if(n.type==="snapshot"&&typeof n.data=="string"){let a=M(n.data);k=[a],w="",x=typeof n.lines=="number"?n.lines:i.terminal.initialLines,p="live",r.reset(),r.write(a).then(()=>r.scrollToBottom());return}if(n.type==="window_changed"&&typeof n.activeIndex=="number"){let a=new URL(location.href);a.searchParams.get("window")!==String(n.activeIndex)&&(a.searchParams.set("window",String(n.activeIndex)),history.replaceState(history.state,"",a)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:n.windows}));return}if(n.type==="history"&&typeof n.data=="string"){L=!1,n.lines>0&&n.data&&(k.unshift(n.data),x+=n.lines,tt(!0,n.lines));return}if(n.type==="data"&&typeof n.data=="string"){let a=M(n.data);if(p==="connecting"){p="live",w=a,r.write(a);return}p==="live"&&(w+=a,r.write(a))}}function V(){let t=G,n=localStorage.getItem("tmux-web-token");n&&(t+=(t.includes("?")?"&":"?")+"token="+encodeURIComponent(n)),s=new WebSocket(t),s.onopen=()=>{p="connecting",x=0,L=!1,k=[],w="",r.reset(),g=1e3},s.onmessage=a=>{typeof a.data=="string"&&et(a.data)},s.onclose=()=>{P||(p="connecting",setTimeout(()=>{g=Math.min(g*2,1e4),P||V()},g))},s.onerror=()=>s?.close()}function b(t){y({type:"input",data:t})}function z(){d&&(b(d),d="")}function T(){return r.fit()}function B(){o.classList.remove("terminal-pending")}function c(){f&&cancelAnimationFrame(f),v&&clearTimeout(v),T(),f=requestAnimationFrame(()=>{f=0,T()&&B()}),v=setTimeout(()=>{T()&&B()},120)}function nt(){c(),setTimeout(c,50),setTimeout(c,150),setTimeout(c,300)}function I(t){return typeof t=="string"&&t.startsWith("image/")}function W(t){return t?.files?.length?t.files[0]??null:null}function rt(t){if(!t?.items)return null;for(let n=0;n<t.items.length;n++){let a=t.items[n];if(a?.kind==="file"&&I(a.type))return a.getAsFile()}return null}async function it(t){let n=new FormData,a=t instanceof File&&t.name?t.name:"upload";n.append("file",t,a);let h=localStorage.getItem("tmux-web-token"),m={};h&&(m.Authorization="Bearer "+h);let A=await fetch(Q,{method:"POST",body:n,headers:m});if(!A.ok){let j="upload failed";try{let N=await A.json();N.error&&(j=N.error)}catch{}throw new Error(j)}let q=await A.json();if(!q.path)throw new Error("no path in response");return q.path}async function H(t){try{let n=await it(t);b(n)}catch{}}o.addEventListener("compositionstart",()=>{C=!0},!0),o.addEventListener("compositionend",t=>{C=!1,clearTimeout(u),u=void 0,d="",t.data&&b(t.data)},!0),r.onData(t=>{if(!C){if(d&&t.startsWith(d)&&t.length>d.length){d=t,clearTimeout(u),u=setTimeout(()=>{z(),u=void 0},40);return}d&&(clearTimeout(u),u=void 0,z()),clearTimeout(u),d=t,u=setTimeout(()=>{z(),u=void 0},15)}}),r.onResize(({cols:t,rows:n})=>y({type:"resize",cols:t,rows:n})),r.onScroll(()=>{p!=="live"||L||!r.isNearScrollbackTop()||(L=!0,y({type:"load_history",before:x}))}),r.attachCustomKeyEventHandler(t=>t.type!=="keydown"?!0:(t.ctrlKey||t.metaKey)&&t.code==="KeyV"?(t.preventDefault(),(async()=>{try{if(navigator.clipboard?.read){let n=await navigator.clipboard.read();for(let a of n)for(let h of a.types)if(I(h)){let m=await a.getType(h);await H(m);return}}}catch{}try{let n=await navigator.clipboard?.readText();n&&r.pasteText(F(n))}catch{}})(),!1):!0);let S=0;function F(t){return t.split(`\r
|
|
2
|
+
`).join(`
|
|
3
|
+
`).split(`
|
|
4
|
+
`).join("\r")}async function at(t){let n=rt(t.clipboardData);if(n){t.preventDefault(),t.stopPropagation();let m=Date.now();if(m-S<50)return;S=m,await H(n);return}let a=t.clipboardData?.getData("text/plain");if(!a)return;t.preventDefault(),t.stopPropagation();let h=Date.now();h-S<50||(S=h,r.pasteText(F(a)))}let E=0;function ot(t){t.preventDefault(),E++,W(t.dataTransfer)&&o.classList.add("terminal-drag-over")}function st(t){t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy")}function lt(t){t.preventDefault(),E--,E<=0&&(E=0,o.classList.remove("terminal-drag-over"))}async function ct(t){t.preventDefault(),E=0,o.classList.remove("terminal-drag-over");let n=W(t.dataTransfer);n&&await H(n)}function R(t){!Z||t.key!=="Escape"||t.defaultPrevented||t.repeat||t.metaKey||t.ctrlKey||t.altKey||r.isFocused()&&(t.preventDefault(),t.stopPropagation(),b("\x1B"))}o.addEventListener("paste",at),o.addEventListener("dragenter",ot),o.addEventListener("dragover",st),o.addEventListener("dragleave",lt),o.addEventListener("drop",ct),document.addEventListener("keydown",R,!0);function ut(t){if(t.touches.length!==1){l=null;return}let n=t.touches[0];n&&(l={startX:n.clientX,startY:n.clientY,lastX:n.clientX,lastY:n.clientY,scrolling:!1},t.stopPropagation())}function ht(t){if(!l||t.touches.length!==1)return;let n=t.touches[0];if(!n)return;let a=n.clientY-l.startY,h=n.clientX-l.startX;if(!l.scrolling){if(Math.abs(a)<8||Math.abs(a)<Math.abs(h))return;l.scrolling=!0,Y=Date.now()+500}t.preventDefault(),t.stopPropagation(),pt(-(n.clientY-l.lastY),n.clientX,n.clientY),l.lastX=n.clientX,l.lastY=n.clientY}function dt(t){if(!l)return;let n=l.scrolling;l=null,t.stopPropagation(),n?(Y=Date.now()+500,t.preventDefault()):r.focus()}function mt(t){l=null,t.stopPropagation()}function ft(t){t.pointerType==="touch"&&Date.now()<Y&&(t.preventDefault(),t.stopPropagation())}function pt(t,n,a){(o.querySelector(".xterm-screen")??o).dispatchEvent(new WheelEvent("wheel",{deltaY:t,deltaMode:WheelEvent.DOM_DELTA_PIXEL,clientX:n,clientY:a,bubbles:!0,cancelable:!0}))}o.addEventListener("touchstart",ut,{passive:!0,capture:!0}),o.addEventListener("touchmove",ht,{passive:!1,capture:!0}),o.addEventListener("touchend",dt,{passive:!1,capture:!0}),o.addEventListener("touchcancel",mt,{passive:!0,capture:!0}),o.addEventListener("pointerup",ft,!0);function K(){c()}window.addEventListener("resize",K),window.visualViewport?.addEventListener("resize",c),window.visualViewport?.addEventListener("scroll",c);let X=new ResizeObserver(()=>c());return X.observe(o),document.fonts?.ready.then(()=>{c(),setTimeout(c,50),setTimeout(c,200)}),o.addEventListener("focusin",nt,!0),requestAnimationFrame(()=>{T()&&B(),V(),c()}),{destroy(){if(P=!0,clearTimeout(u),u=void 0,s){try{s.close(1e3,"session switch")}catch{}s=void 0}o.innerHTML="",o.classList.remove("terminal-pending"),window.removeEventListener("resize",K),X.disconnect(),document.removeEventListener("keydown",R,!0)},focus(){r.focus()},sendInput(t){b(t)}}})()}export{bt as a};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as F}from"./chunk-
|
|
1
|
+
import{a as F}from"./chunk-7KLKPQJJ.js";var h=window.__TMUX_WEB_SHELL__,l=null,c=null,D="sessions",m="",B="",x="",H="",i=document.getElementById("sidebar-content"),g=document.getElementById("main-placeholder"),f=document.getElementById("terminal-container"),k=document.getElementById("file-editor"),P=document.getElementById("fe-path"),o=document.getElementById("fe-status"),E=document.getElementById("fe-content"),y=document.getElementById("fe-save"),R=document.getElementById("fe-delete"),V=document.getElementById("fe-back"),S=document.getElementById("fe-new-name"),$=document.getElementById("fe-new-btn"),T=document.getElementById("settings-backdrop"),N=document.getElementById("settings-popover"),j=document.querySelector(".sidebar");function J(){return window.matchMedia("(max-width: 640px)").matches}function O(){J()&&j.classList.add("collapsed")}function z(){j.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{z(),_("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{z(),_("files")});function _(e){D=e,document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));let t=document.getElementById(e==="sessions"?"mode-sessions":"mode-files");t&&t.classList.add("active"),e==="sessions"?L():U()}async function L(){i.innerHTML='<div class="sidebar-section-label">Sessions</div><button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';try{let t=(await(await fetch("/api/sidebar/sessions")).json()).recent||[];for(let n of t){let a=document.createElement("div");a.className="session-item"+(n.name===c?" active":""),a.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${n.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
2
2
|
<span>${b(n.name)}</span>
|
|
3
3
|
<button class="session-edit-btn" data-session="${b(n.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>
|
|
4
4
|
`,a.addEventListener("click",p=>{p.target.closest(".session-edit-btn")||M(n.name)}),i.appendChild(a);let s=a.querySelector(".session-edit-btn");s&&s.addEventListener("click",p=>{p.stopPropagation(),Z(n.name,s)})}}catch{i.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}let e=document.getElementById("ns-btn");e&&e.addEventListener("click",()=>document.getElementById("new-session-modal")?.classList.add("open"))}function b(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function M(e){if(!(c===e&&l)){k.style.display="none",g.style.display="none",f.style.display="",f.classList.add("terminal-pending"),O(),l&&(l.destroy(),l=null),c=e;try{l=await F(f,e,{terminal:h.terminal,scrollback:h.scrollback,theme:h.theme,renderer:h.renderer})}catch(t){console.error("[shell] terminal init failed:",t);let n=t&&typeof t=="object"&&"message"in t?t.message:String(t);f.textContent="Failed to open terminal for "+e+": "+n,f.classList.remove("terminal-pending")}}}var I=[];function U(){if(I=h.fsRoots||[],I.length===0){if(c){q(c);return}i.innerHTML='<div class="file-tree-info">Open a session first, then switch to Files to browse its directory.</div>';return}i.innerHTML="";for(let e of I){let t=document.createElement("div");t.className="file-tree-item",t.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${b(e)}`,t.addEventListener("click",()=>u(e)),i.appendChild(t)}}async function q(e){i.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let t=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(e))).json();t.path?u(t.path):i.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{i.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function u(e){m=e,i.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let t=await(await fetch("/api/fs/list?path="+encodeURIComponent(e))).json();i.innerHTML="";let n=A(e);if(n&&!I.some(s=>e===s)){let s=document.createElement("div");s.className="file-tree-item",s.innerHTML="..",s.addEventListener("click",()=>u(n)),i.appendChild(s)}if(t.dirs)for(let s of t.dirs){let p=s.split("/").pop()||s.split("\\").pop(),d=document.createElement("div");d.className="file-tree-item",d.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${b(p)}`,d.addEventListener("click",()=>u(s)),i.appendChild(d)}else i.innerHTML="";let a=t.files||[];for(let s of a){let p=s.split("/").pop()||s.split("\\").pop(),d=document.createElement("div");d.className="file-tree-item file",d.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${b(p)}`,d.addEventListener("click",()=>W(s)),i.appendChild(d)}}catch{i.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function A(e){let t=e.lastIndexOf("/");return t<=0?null:e.substring(0,t)}async function W(e){B=e,f.style.display="none",l&&(l.destroy(),l=null,c=null),O(),g.style.display="none",k.style.display="flex",P.textContent=e,o.textContent="Loading...",y.style.display="none";try{let t=await fetch("/api/file?path="+encodeURIComponent(e));if(!t.ok){let a=await t.json();o.textContent=a.error||"Failed to load",E.value="";return}let n=await t.json();E.value=n.content,x=n.content,H=n.content,o.textContent=n.size+" bytes",y.style.display=""}catch{o.textContent="Failed to load",E.value=""}}E.addEventListener("input",()=>{x=E.value}),y.addEventListener("click",async()=>{y.textContent="Saving...",y.disabled=!0;try{let e=await fetch("/api/file",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:B,content:x})});if(!e.ok){let t=await e.json();o.textContent=t.error||"Save failed";return}H=x,o.textContent="Saved"}catch{o.textContent="Save failed"}finally{y.disabled=!1,y.textContent="Save"}}),R.addEventListener("click",async()=>{if(confirm("Delete "+B+"?"))try{let e=await fetch("/api/file/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:B})});if(!e.ok){let t=await e.json();o.textContent=t.error||"Delete failed";return}k.style.display="none",g.style.display="flex",m&&u(m)}catch{o.textContent="Delete failed"}}),V.addEventListener("click",()=>{k.style.display="none",g.style.display="flex",m&&u(m)}),$.addEventListener("click",async()=>{let e=S.value.trim();if(!e)return;let t=m+"/"+e;try{let n=await fetch("/api/file/touch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok){let a=await n.json();o.textContent=a.error||"Create failed";return}S.value="",m&&u(m)}catch{o.textContent="Create failed"}}),document.getElementById("mode-settings").addEventListener("click",()=>{let e=N.classList.toggle("open");T.classList.toggle("open",e)}),T.addEventListener("click",()=>{N.classList.remove("open"),T.classList.remove("open")});var v="",w=document.createElement("div");w.className="session-popover-backdrop",document.body.appendChild(w);var r=document.createElement("div");r.id="session-popover",r.className="session-popover",r.style.display="none",r.innerHTML=`<div class="sp-field">
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
1
|
+
import{a as t}from"./chunk-7KLKPQJJ.js";var e=window.__TMUX_WEB_TERMINAL__;if(!e)throw new Error("missing tmux-web terminal config");var r=document.getElementById("terminal-container");if(!r)throw new Error("missing terminal container");var{sessionName:o,...m}=e;t(r,o,m).then(n=>{window.tmuxWeb={sendInput:i=>n.sendInput(i),focusTerminal:()=>n.focus()}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const pt="https://esm.sh/ghostty-web@0.4.0",wt=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function M(a){return a.replace(wt,"")}let E;function gt(){return E||(document.querySelector("link[data-tmux-web-xterm-css]")?E=Promise.resolve():(E=new Promise(e=>{const r=document.createElement("link");r.rel="stylesheet",r.href="/assets/xterm.css",r.setAttribute("data-tmux-web-xterm-css",""),r.addEventListener("load",()=>e(),{once:!0}),r.addEventListener("error",()=>e(),{once:!0}),document.head.appendChild(r)}),E))}class Y{terminal;fitAddon;container;constructor(e,r,i){this.container=e,this.terminal=r,this.fitAddon=i,this.terminal.loadAddon(this.fitAddon),this.terminal.open(e)}static async create(e,r,i){const[{Terminal:s},{FitAddon:m}]=await Promise.all([import("@xterm/xterm"),import("@xterm/addon-fit"),gt()]),g=new s({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:r,convertEol:!1,theme:i});return new Y(e,g,new m)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(e){return new Promise(r=>this.terminal.write(e,r))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(e){this.terminal.scrollToLine(Math.max(0,e))}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){const e=N(this.container);return e.width<=0||e.height<=0?!1:(this.fitAddon.fit(),!0)}focus(){this.terminal.focus()}pasteText(e){this.terminal.paste(e)}input(e){this.terminal.input(e,!1)}onData(e){this.terminal.onData(e),this.terminal.onBinary(e)}onResize(e){this.terminal.onResize(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){const e=document.activeElement;return!!e&&(e===this.container||this.container.contains(e))}}class R{terminal;container;colsValue=80;rowsValue=24;charW=0;charH=0;resizeCallbacks=[];constructor(e,r){this.container=e,this.terminal=r,this.terminal.open(e)}static async create(e,r,i){const s=await import(pt);await s.init();const m=new s.Terminal({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:r,convertEol:!1,theme:i});return new R(e,m)}get cols(){return this.colsValue}get rows(){return this.rowsValue}write(e){return new Promise(r=>this.terminal.write(e,r))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom?.()}scrollToLine(e){this.terminal.scrollToLine?.(Math.max(0,e))}isNearScrollbackTop(){const e=this.terminal.buffer?.active;return e?e.viewportY>=e.baseY:!1}viewportY(){return this.terminal.buffer?.active?.viewportY??0}baseY(){return this.terminal.buffer?.active?.baseY??0}fit(){const e=N(this.container);if(e.width<=0||e.height<=0)return!1;this.updateCellMetrics(!this.charW||!this.charH);const r=Math.floor(e.width/this.charW),i=Math.floor(e.height/this.charH);if(r<10||i<5)return!1;if(r!==this.colsValue||i!==this.rowsValue){this.colsValue=r,this.rowsValue=i,this.terminal.resize(r,i);for(const s of this.resizeCallbacks)s({cols:r,rows:i})}return!0}focus(){(this.terminal.textarea||this.container.querySelector("textarea")||this.container)?.focus?.()}pasteText(e){const r=this.terminal.getMode?.(2004)??!1;this.input(r?"\x1B[200~"+e+"\x1B[201~":e)}input(e){this.terminal.input?.(e,!1)}onData(e){this.terminal.onData(r=>e(r))}onResize(e){this.resizeCallbacks.push(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){const e=document.activeElement;return!!e&&(e===this.container||e===this.terminal.textarea||this.container.contains(e))}updateCellMetrics(e=!1){const r=this.container.querySelector("canvas");if(r instanceof HTMLElement&&r.offsetWidth>0&&r.offsetHeight>0&&this.colsValue>0&&this.rowsValue>0){const i=r.offsetWidth/this.colsValue,s=r.offsetHeight/this.rowsValue;(e||!this.charW||!this.charH)&&(this.charW=i,this.charH=s)}(!this.charW||!this.charH)&&(this.charW=9,this.charH=18)}}function N(a){const e=a.getBoundingClientRect(),r=window.visualViewport;return r?{width:Math.min(e.width,r.width),height:Math.max(0,Math.min(e.height,r.height-Math.max(0,e.top)))}:e}function vt(a,e,r){return a.innerHTML="",a.classList.add("terminal-pending"),(async()=>{let i;if(r.renderer==="ghostty")try{i=await R.create(a,r.scrollback,r.theme)}catch{console.error("[tmux-web] ghostty-web failed; falling back to xterm.js"),i=await Y.create(a,r.scrollback,r.theme)}else i=await Y.create(a,r.scrollback,r.theme);let s,m=0,g,l=null,C=0,p="connecting",L=0,S=!1,k=[],w="",P=!1,y=1e3,F=!1,h="",f;const J=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/"+encodeURIComponent(e),G="/api/session/"+encodeURIComponent(e)+"/upload",Q=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Z(){return k.join("")+w}async function $(t,n=0){const o=t?i.viewportY():0,u=t?i.baseY():0,d=M(Z());if(i.reset(),!d){t||i.scrollToBottom();return}await i.write(d),t?i.scrollToLine(u+o+n):i.scrollToBottom()}function v(t){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(t))}function tt(t){let n;try{n=JSON.parse(t)}catch{p==="live"&&(w+=t,i.write(M(t)));return}if(n.type==="auth.required"){const o=localStorage.getItem("tmux-web-token");o?v({type:"auth.token",token:o}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(n.type==="auth.ok"){n.token&&localStorage.setItem("tmux-web-token",n.token),y=1e3,b(),v({type:"resize",cols:i.cols,rows:i.rows}),c();return}if(n.type==="auth.failed"){if(n.permanentLock||n.retryAfterMs&&n.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(n.message);return}return}if(n.type==="snapshot"&&typeof n.data=="string"){const o=M(n.data);k=[o],w="",L=typeof n.lines=="number"?n.lines:r.terminal.initialLines,p="live",i.reset(),i.write(o).then(()=>i.scrollToBottom());return}if(n.type==="window_changed"&&typeof n.activeIndex=="number"){const o=new URL(location.href);o.searchParams.get("window")!==String(n.activeIndex)&&(o.searchParams.set("window",String(n.activeIndex)),history.replaceState(history.state,"",o)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:n.windows}));return}if(n.type==="history"&&typeof n.data=="string"){S=!1,n.lines>0&&n.data&&(k.unshift(n.data),L+=n.lines,$(!0,n.lines));return}if(n.type==="data"&&typeof n.data=="string"){const o=M(n.data);if(p==="connecting"){p="live",w=o,i.write(o);return}p==="live"&&(w+=o,i.write(o))}}function W(){let t=J;const n=localStorage.getItem("tmux-web-token");n&&(t+=(t.includes("?")?"&":"?")+"token="+encodeURIComponent(n)),s=new WebSocket(t),s.onopen=()=>{p="connecting",L=0,S=!1,k=[],w="",i.reset(),y=1e3},s.onmessage=o=>{typeof o.data=="string"&&tt(o.data)},s.onclose=()=>{P||(p="connecting",setTimeout(()=>{y=Math.min(y*2,1e4),P||W()},y))},s.onerror=()=>s?.close()}function T(t){v({type:"input",data:t})}function I(){h&&(T(h),h="")}function b(){return i.fit()}function z(){a.classList.remove("terminal-pending")}function c(){m&&cancelAnimationFrame(m),g&&clearTimeout(g),b(),m=requestAnimationFrame(()=>{m=0,b()&&z()}),g=setTimeout(()=>{b()&&z()},120)}function et(){c(),setTimeout(c,50),setTimeout(c,150),setTimeout(c,300)}function A(t){return typeof t=="string"&&t.startsWith("image/")}function V(t){return t?.files?.length?t.files[0]??null:null}function nt(t){if(!t?.items)return null;for(let n=0;n<t.items.length;n++){const o=t.items[n];if(o?.kind==="file"&&A(o.type))return o.getAsFile()}return null}async function rt(t){const n=new FormData,o=t instanceof File&&t.name?t.name:"upload";n.append("file",t,o);const u=localStorage.getItem("tmux-web-token"),d={};u&&(d.Authorization="Bearer "+u);const B=await fetch(G,{method:"POST",body:n,headers:d});if(!B.ok){let j="upload failed";try{const q=await B.json();q.error&&(j=q.error)}catch{}throw new Error(j)}const _=await B.json();if(!_.path)throw new Error("no path in response");return _.path}async function H(t){try{const n=await rt(t);T(n)}catch{}}a.addEventListener("compositionstart",()=>{F=!0},!0),a.addEventListener("compositionend",t=>{F=!1,clearTimeout(f),f=void 0,h="",t.data&&T(t.data)},!0),i.onData(t=>{if(!F){if(h&&t.startsWith(h)&&t.length>h.length){h=t,clearTimeout(f),f=setTimeout(()=>{I(),f=void 0},40);return}h&&(clearTimeout(f),f=void 0,I()),clearTimeout(f),h=t,f=setTimeout(()=>{I(),f=void 0},15)}}),i.onResize(({cols:t,rows:n})=>v({type:"resize",cols:t,rows:n})),i.onScroll(()=>{p!=="live"||S||!i.isNearScrollbackTop()||(S=!0,v({type:"load_history",before:L}))}),i.attachCustomKeyEventHandler(t=>t.type!=="keydown"?!0:(t.ctrlKey||t.metaKey)&&t.code==="KeyV"?(t.preventDefault(),(async()=>{try{if(navigator.clipboard?.read){const n=await navigator.clipboard.read();for(const o of n)for(const u of o.types)if(A(u)){const d=await o.getType(u);await H(d);return}}}catch{}try{const n=await navigator.clipboard?.readText();n&&i.pasteText(O(n))}catch{}})(),!1):!0);let D=0;function O(t){return t.split(`\r
|
|
2
2
|
`).join(`
|
|
3
3
|
`).split(`
|
|
4
|
-
`).join("\r")}async function
|
|
4
|
+
`).join("\r")}async function it(t){const n=nt(t.clipboardData);if(n){t.preventDefault(),t.stopPropagation();const d=Date.now();if(d-D<50)return;D=d,await H(n);return}const o=t.clipboardData?.getData("text/plain");if(!o)return;t.preventDefault(),t.stopPropagation();const u=Date.now();u-D<50||(D=u,i.pasteText(O(o)))}let x=0;function ot(t){t.preventDefault(),x++,V(t.dataTransfer)&&a.classList.add("terminal-drag-over")}function at(t){t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy")}function st(t){t.preventDefault(),x--,x<=0&&(x=0,a.classList.remove("terminal-drag-over"))}async function lt(t){t.preventDefault(),x=0,a.classList.remove("terminal-drag-over");const n=V(t.dataTransfer);n&&await H(n)}function K(t){!Q||t.key!=="Escape"||t.defaultPrevented||t.repeat||t.metaKey||t.ctrlKey||t.altKey||i.isFocused()&&(t.preventDefault(),t.stopPropagation(),T("\x1B"))}a.addEventListener("paste",it),a.addEventListener("dragenter",ot),a.addEventListener("dragover",at),a.addEventListener("dragleave",st),a.addEventListener("drop",lt),document.addEventListener("keydown",K,!0);function ct(t){if(t.touches.length!==1){l=null;return}const n=t.touches[0];n&&(l={startX:n.clientX,startY:n.clientY,lastX:n.clientX,lastY:n.clientY,scrolling:!1},t.stopPropagation())}function ut(t){if(!l||t.touches.length!==1)return;const n=t.touches[0];if(!n)return;const o=n.clientY-l.startY,u=n.clientX-l.startX;if(!l.scrolling){if(Math.abs(o)<8||Math.abs(o)<Math.abs(u))return;l.scrolling=!0,C=Date.now()+500}t.preventDefault(),t.stopPropagation(),mt(-(n.clientY-l.lastY),n.clientX,n.clientY),l.lastX=n.clientX,l.lastY=n.clientY}function ft(t){if(!l)return;const n=l.scrolling;l=null,t.stopPropagation(),n?(C=Date.now()+500,t.preventDefault()):i.focus()}function ht(t){l=null,t.stopPropagation()}function dt(t){t.pointerType==="touch"&&Date.now()<C&&(t.preventDefault(),t.stopPropagation())}function mt(t,n,o){(a.querySelector(".xterm-screen")??a).dispatchEvent(new WheelEvent("wheel",{deltaY:t,deltaMode:WheelEvent.DOM_DELTA_PIXEL,clientX:n,clientY:o,bubbles:!0,cancelable:!0}))}a.addEventListener("touchstart",ct,{passive:!0,capture:!0}),a.addEventListener("touchmove",ut,{passive:!1,capture:!0}),a.addEventListener("touchend",ft,{passive:!1,capture:!0}),a.addEventListener("touchcancel",ht,{passive:!0,capture:!0}),a.addEventListener("pointerup",dt,!0);function U(){c()}window.addEventListener("resize",U),window.visualViewport?.addEventListener("resize",c),window.visualViewport?.addEventListener("scroll",c);const X=new ResizeObserver(()=>c());return X.observe(a),document.fonts?.ready.then(()=>{c(),setTimeout(c,50),setTimeout(c,200)}),a.addEventListener("focusin",et,!0),requestAnimationFrame(()=>{b()&&z(),W(),c()}),{destroy(){if(P=!0,clearTimeout(f),f=void 0,s){try{s.close(1e3,"session switch")}catch{}s=void 0}a.innerHTML="",a.classList.remove("terminal-pending"),window.removeEventListener("resize",U),X.disconnect(),document.removeEventListener("keydown",K,!0)},focus(){i.focus()},sendInput(t){T(t)}}})()}export{vt as initTerminal};
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
var dt="https://esm.sh/ghostty-web@0.4.0",mt=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function k(a){return a.replace(mt,"")}var S;function ft(){return S||(document.querySelector("link[data-tmux-web-xterm-css]")?S=Promise.resolve():(S=new Promise(a=>{let e=document.createElement("link");e.rel="stylesheet",e.href="/assets/xterm.css",e.setAttribute("data-tmux-web-xterm-css",""),e.addEventListener("load",()=>a(),{once:!0}),e.addEventListener("error",()=>a(),{once:!0}),document.head.appendChild(e)}),S))}var X=class j{terminal;fitAddon;container;constructor(e,i,r){this.container=e,this.terminal=i,this.fitAddon=r,this.terminal.loadAddon(this.fitAddon),this.terminal.open(e)}static async create(e,i,r){let[{Terminal:s},{FitAddon:d}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),ft()]),p=new s({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:i,convertEol:!1,theme:r});return new j(e,p,new d)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(e){return new Promise(i=>this.terminal.write(e,i))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(e){this.terminal.scrollToLine(Math.max(0,e))}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){let e=q(this.container);return e.width<=0||e.height<=0?!1:(this.fitAddon.fit(),!0)}focus(){this.terminal.focus()}pasteText(e){this.terminal.paste(e)}input(e){this.terminal.input(e,!1)}onData(e){this.terminal.onData(e),this.terminal.onBinary(e)}onResize(e){this.terminal.onResize(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return!!e&&(e===this.container||this.container.contains(e))}},pt=class N{terminal;container;colsValue=80;rowsValue=24;charW=0;charH=0;resizeCallbacks=[];constructor(e,i){this.container=e,this.terminal=i,this.terminal.open(e)}static async create(e,i,r){let s=await import(dt);await s.init();let d=new s.Terminal({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:i,convertEol:!1,theme:r});return new N(e,d)}get cols(){return this.colsValue}get rows(){return this.rowsValue}write(e){return new Promise(i=>this.terminal.write(e,i))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom?.()}scrollToLine(e){this.terminal.scrollToLine?.(Math.max(0,e))}isNearScrollbackTop(){let e=this.terminal.buffer?.active;return e?e.viewportY>=e.baseY:!1}viewportY(){return this.terminal.buffer?.active?.viewportY??0}baseY(){return this.terminal.buffer?.active?.baseY??0}fit(){let e=q(this.container);if(e.width<=0||e.height<=0)return!1;this.updateCellMetrics(!this.charW||!this.charH);let i=Math.floor(e.width/this.charW),r=Math.floor(e.height/this.charH);if(i<10||r<5)return!1;if(i!==this.colsValue||r!==this.rowsValue){this.colsValue=i,this.rowsValue=r,this.terminal.resize(i,r);for(let s of this.resizeCallbacks)s({cols:i,rows:r})}return!0}focus(){(this.terminal.textarea||this.container.querySelector("textarea")||this.container)?.focus?.()}pasteText(e){let i=this.terminal.getMode?.(2004)??!1;this.input(i?"\x1B[200~"+e+"\x1B[201~":e)}input(e){this.terminal.input?.(e,!1)}onData(e){this.terminal.onData(i=>e(i))}onResize(e){this.resizeCallbacks.push(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return!!e&&(e===this.container||e===this.terminal.textarea||this.container.contains(e))}updateCellMetrics(e=!1){let i=this.container.querySelector("canvas");if(i instanceof HTMLElement&&i.offsetWidth>0&&i.offsetHeight>0&&this.colsValue>0&&this.rowsValue>0){let r=i.offsetWidth/this.colsValue,s=i.offsetHeight/this.rowsValue;(e||!this.charW||!this.charH)&&(this.charW=r,this.charH=s)}(!this.charW||!this.charH)&&(this.charW=9,this.charH=18)}};function q(a){let e=a.getBoundingClientRect(),i=window.visualViewport;return i?{width:Math.min(e.width,i.width),height:Math.max(0,Math.min(e.height,i.height-Math.max(0,e.top)))}:e}function wt(a,e,i){return a.innerHTML="",a.classList.add("terminal-pending"),(async()=>{let r;if(i.renderer==="ghostty")try{r=await pt.create(a,i.scrollback,i.theme)}catch{console.error("[tmux-web] ghostty-web failed; falling back to xterm.js"),r=await X.create(a,i.scrollback,i.theme)}else r=await X.create(a,i.scrollback,i.theme);let s,d=0,p,l=null,M=0,m="connecting",b=0,E=!1,T=[],f="",D=!1,w=1e3,O=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/"+encodeURIComponent(e),U="/api/session/"+encodeURIComponent(e)+"/upload",J=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function _(){return T.join("")+f}async function G(t,n=0){let o=t?r.viewportY():0,u=t?r.baseY():0,h=k(_());if(r.reset(),!h){t||r.scrollToBottom();return}await r.write(h),t?r.scrollToLine(u+o+n):r.scrollToBottom()}function v(t){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(t))}function Q(t){let n;try{n=JSON.parse(t)}catch{m==="live"&&(f+=t,r.write(k(t)));return}if(n.type==="auth.required"){let o=localStorage.getItem("tmux-web-token");o?v({type:"auth.token",token:o}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(n.type==="auth.ok"){n.token&&localStorage.setItem("tmux-web-token",n.token),w=1e3,g(),v({type:"resize",cols:r.cols,rows:r.rows}),c();return}if(n.type==="auth.failed"){if(n.permanentLock||n.retryAfterMs&&n.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(n.message);return}return}if(n.type==="snapshot"&&typeof n.data=="string"){let o=k(n.data);T=[o],f="",b=typeof n.lines=="number"?n.lines:i.terminal.initialLines,m="live",r.reset(),r.write(o).then(()=>r.scrollToBottom());return}if(n.type==="window_changed"&&typeof n.activeIndex=="number"){let o=new URL(location.href);o.searchParams.get("window")!==String(n.activeIndex)&&(o.searchParams.set("window",String(n.activeIndex)),history.replaceState(history.state,"",o)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:n.windows}));return}if(n.type==="history"&&typeof n.data=="string"){E=!1,n.lines>0&&n.data&&(T.unshift(n.data),b+=n.lines,G(!0,n.lines));return}if(n.type==="data"&&typeof n.data=="string"){let o=k(n.data);if(m==="connecting"){m="live",f=o,r.write(o);return}m==="live"&&(f+=o,r.write(o))}}function z(){let t=O,n=localStorage.getItem("tmux-web-token");n&&(t+=(t.includes("?")?"&":"?")+"token="+encodeURIComponent(n)),s=new WebSocket(t),s.onopen=()=>{m="connecting",b=0,E=!1,T=[],f="",r.reset(),w=1e3},s.onmessage=o=>{typeof o.data=="string"&&Q(o.data)},s.onclose=()=>{D||(m="connecting",setTimeout(()=>{w=Math.min(w*2,1e4),D||z()},w))},s.onerror=()=>s?.close()}function x(t){v({type:"input",data:t})}function g(){return r.fit()}function Y(){a.classList.remove("terminal-pending")}function c(){d&&cancelAnimationFrame(d),p&&clearTimeout(p),g(),d=requestAnimationFrame(()=>{d=0,g()&&Y()}),p=setTimeout(()=>{g()&&Y()},120)}function Z(){c(),setTimeout(c,50),setTimeout(c,150),setTimeout(c,300)}function B(t){return typeof t=="string"&&t.startsWith("image/")}function H(t){return t?.files?.length?t.files[0]??null:null}function $(t){if(!t?.items)return null;for(let n=0;n<t.items.length;n++){let o=t.items[n];if(o?.kind==="file"&&B(o.type))return o.getAsFile()}return null}async function tt(t){let n=new FormData,o=t instanceof File&&t.name?t.name:"upload";n.append("file",t,o);let u=localStorage.getItem("tmux-web-token"),h={};u&&(h.Authorization="Bearer "+u);let C=await fetch(U,{method:"POST",body:n,headers:h});if(!C.ok){let R="upload failed";try{let K=await C.json();K.error&&(R=K.error)}catch{}throw new Error(R)}let W=await C.json();if(!W.path)throw new Error("no path in response");return W.path}async function P(t){try{let n=await tt(t);x(n)}catch{}}r.onData(t=>x(t)),r.onResize(({cols:t,rows:n})=>v({type:"resize",cols:t,rows:n})),r.onScroll(()=>{m!=="live"||E||!r.isNearScrollbackTop()||(E=!0,v({type:"load_history",before:b}))}),r.attachCustomKeyEventHandler(t=>t.type!=="keydown"?!0:(t.ctrlKey||t.metaKey)&&t.code==="KeyV"?(t.preventDefault(),(async()=>{try{if(navigator.clipboard?.read){let n=await navigator.clipboard.read();for(let o of n)for(let u of o.types)if(B(u)){let h=await o.getType(u);await P(h);return}}}catch{}try{let n=await navigator.clipboard?.readText();n&&r.pasteText(A(n))}catch{}})(),!1):!0);let L=0;function A(t){return t.split(`\r
|
|
2
|
-
`).join(`
|
|
3
|
-
`).split(`
|
|
4
|
-
`).join("\r")}async function et(t){let n=$(t.clipboardData);if(n){t.preventDefault(),t.stopPropagation();let h=Date.now();if(h-L<50)return;L=h,await P(n);return}let o=t.clipboardData?.getData("text/plain");if(!o)return;t.preventDefault(),t.stopPropagation();let u=Date.now();u-L<50||(L=u,r.pasteText(A(o)))}let y=0;function nt(t){t.preventDefault(),y++,H(t.dataTransfer)&&a.classList.add("terminal-drag-over")}function rt(t){t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy")}function it(t){t.preventDefault(),y--,y<=0&&(y=0,a.classList.remove("terminal-drag-over"))}async function ot(t){t.preventDefault(),y=0,a.classList.remove("terminal-drag-over");let n=H(t.dataTransfer);n&&await P(n)}function V(t){!J||t.key!=="Escape"||t.defaultPrevented||t.repeat||t.metaKey||t.ctrlKey||t.altKey||r.isFocused()&&(t.preventDefault(),t.stopPropagation(),x("\x1B"))}a.addEventListener("paste",et),a.addEventListener("dragenter",nt),a.addEventListener("dragover",rt),a.addEventListener("dragleave",it),a.addEventListener("drop",ot),document.addEventListener("keydown",V,!0);function at(t){if(t.touches.length!==1){l=null;return}let n=t.touches[0];n&&(l={startX:n.clientX,startY:n.clientY,lastX:n.clientX,lastY:n.clientY,scrolling:!1},t.stopPropagation())}function st(t){if(!l||t.touches.length!==1)return;let n=t.touches[0];if(!n)return;let o=n.clientY-l.startY,u=n.clientX-l.startX;if(!l.scrolling){if(Math.abs(o)<8||Math.abs(o)<Math.abs(u))return;l.scrolling=!0,M=Date.now()+500}t.preventDefault(),t.stopPropagation(),ht(-(n.clientY-l.lastY),n.clientX,n.clientY),l.lastX=n.clientX,l.lastY=n.clientY}function lt(t){if(!l)return;let n=l.scrolling;l=null,t.stopPropagation(),n?(M=Date.now()+500,t.preventDefault()):r.focus()}function ct(t){l=null,t.stopPropagation()}function ut(t){t.pointerType==="touch"&&Date.now()<M&&(t.preventDefault(),t.stopPropagation())}function ht(t,n,o){(a.querySelector(".xterm-screen")??a).dispatchEvent(new WheelEvent("wheel",{deltaY:t,deltaMode:WheelEvent.DOM_DELTA_PIXEL,clientX:n,clientY:o,bubbles:!0,cancelable:!0}))}a.addEventListener("touchstart",at,{passive:!0,capture:!0}),a.addEventListener("touchmove",st,{passive:!1,capture:!0}),a.addEventListener("touchend",lt,{passive:!1,capture:!0}),a.addEventListener("touchcancel",ct,{passive:!0,capture:!0}),a.addEventListener("pointerup",ut,!0);function I(){c()}window.addEventListener("resize",I),window.visualViewport?.addEventListener("resize",c),window.visualViewport?.addEventListener("scroll",c);let F=new ResizeObserver(()=>c());return F.observe(a),document.fonts?.ready.then(()=>{c(),setTimeout(c,50),setTimeout(c,200)}),a.addEventListener("focusin",Z,!0),requestAnimationFrame(()=>{g()&&Y(),z(),c()}),{destroy(){if(D=!0,s){try{s.close(1e3,"session switch")}catch{}s=void 0}a.innerHTML="",a.classList.remove("terminal-pending"),window.removeEventListener("resize",I),F.disconnect(),document.removeEventListener("keydown",V,!0)},focus(){r.focus()},sendInput(t){x(t)}}})()}export{wt as a};
|