tmux-weblink 2.2.17 → 2.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  var yn=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function Qe(e){return e.replace(/\x1b\[\?1049[hl]/g,"")}function me(e){return e.replace(yn,"")}var Fe;function wn(){return Fe||(document.querySelector("link[data-tmux-web-xterm-css]")?Fe=Promise.resolve():(Fe=new Promise(e=>{let t=document.createElement("link");t.rel="stylesheet",t.href="/assets/xterm.css",t.setAttribute("data-tmux-web-xterm-css",""),t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0}),document.head.appendChild(t)}),Fe))}var bn=class Yt{terminal;fitAddon;container;constructor(t,n,s){this.container=t,this.terminal=n,this.fitAddon=s,this.terminal.loadAddon(this.fitAddon),this.terminal.open(t)}static async create(t,n,s){let[{Terminal:l},{FitAddon:r}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),wn()]),c=new l({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,smoothScrollDuration:120,theme:s});return new Yt(t,c,new r)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(t){return new Promise(n=>this.terminal.write(t,n))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(t,n=!1){this.terminal.scrollToLine(Math.max(0,t),n)}scrollLines(t){let n=this.terminal.buffer?.active;this.terminal.scrollLines(t)}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){let t=Ln(this.container);if(t.width<=0||t.height<=0)return!1;let n=this.terminal._core?._renderService?.dimensions?.css?.cell;if(!n?.width||!n?.height)return this.fitAddon.fit(),!0;let s=n.width,l=n.height,r=this.terminal.element?.querySelector(".xterm-viewport"),c=r?Math.max(0,r.offsetWidth-r.clientWidth):0,o=Math.max(2,Math.floor((t.width-c)/s)),u=Math.max(2,Math.floor(t.height/l));return(o!==this.terminal.cols||u!==this.terminal.rows)&&this.terminal.resize(o,u),!0}focus(){this.terminal.focus()}pasteText(t){this.terminal.paste(t)}input(t){this.terminal.input(t,!1)}onData(t){this.terminal.onData(t),this.terminal.onBinary(t)}onResize(t){this.terminal.onResize(t)}onScroll(t){this.terminal.onScroll(t)}attachCustomKeyEventHandler(t){this.terminal.attachCustomKeyEventHandler(t)}isFocused(){let t=document.activeElement;return t?t===this.container||t===this.terminal.textarea||this.container.contains(t)||!!t.closest?.(".xterm"):!1}getScreenText(){return this.getRowsText(0,this.terminal.rows-1)}getRowsText(t,n){let s=this.terminal.buffer.active,[l,r]=t<=n?[t,n]:[n,t],c=s.viewportY,o=[];for(let u=l;u<=r;u++){let h=s.getLine(c+u);o.push(h?h.translateToString(!0):"")}return o.join(`
2
2
  `)}selectRows(t,n){let s=this.terminal.buffer.active,[l,r]=t<=n?[t,n]:[n,t];this.terminal.selectLines(s.viewportY+l,s.viewportY+r)}selectCells(t,n,s,l){let r=this.terminal.buffer.active,c=Math.min(n,l),o=Math.max(n,l);if(c===o){let u=Math.min(t,s),h=Math.max(t,s);this.terminal.select(u,r.viewportY+c,h-u+1)}else this.terminal.selectLines(r.viewportY+c,r.viewportY+o)}getCellsText(t,n,s,l){let r=this.terminal.buffer.active,c=Math.min(n,l),o=Math.max(n,l),u=n<l?t:n>l?s:Math.min(t,s),h=n<l?s:n>l?t:Math.max(t,s),k=r.viewportY,b=[];for(let M=c;M<=o;M++){let B=r.getLine(k+M);if(!B){b.push("");continue}let Z=M===c?u:0,F=M===o?h:this.terminal.cols-1,N="";for(let se=Z;se<=F;se++){let ie=B.getCell(se);ie&&(N+=ie.getChars())}b.push(N.replace(/\s+$/,""))}return b.join(`
3
- `)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function Ln(e){let t=e.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(t.width,n.width),height:Math.max(0,Math.min(t.height,n.height-Math.max(0,t.top)))}:t}function En(e,t,n){return e.innerHTML="",e.classList.add("terminal-pending"),(async()=>{let s=await bn.create(e,n.scrollback,n.theme),l,r=0,c,o=null,u=null,h=!1,k=/(?:^|\/)(?:vim|nvim|vi|less|more|htop|btop|top|hx|helix|lazygit)$/,b=null;async function M(){try{let i=await fetch("/api/session-program?session="+encodeURIComponent(t));if(i.ok){let a=await i.json();u=typeof a.program=="string"&&a.program?a.program:null,h=u!==null&&k.test(u)}}catch{}}function B(){b&&clearTimeout(b),b=setTimeout(()=>{M()},250)}function Z(i){return u!==null&&/(?:^|\/)(?:vim|nvim|vi)$/.test(u)?i?"":"":i?"\x1B[A":"\x1B[B"}let F=0,N=0,se=.2,ie=10,Ut=.95,Wt=.04;function ke(){F&&(cancelAnimationFrame(F),F=0),N=0}function Ot(i){if(ke(),Math.abs(i)<se)return;N=Math.max(-ie,Math.min(ie,i));let a=()=>{if(_){F=0;return}let d=e.querySelector(".xterm-rows > div"),p=d?d.getBoundingClientRect().height:16,w=p>0?Math.round(N*16/p):N>0?1:-1;w===0&&(w=N>0?1:-1);let I=s.viewportY()-w,V=s.baseY(),Y=Math.max(0,Math.min(I,V));if(s.scrollToLine(Y,!0),N*=Ut,Y!==I){F=0;return}if(Math.abs(N)<Wt){F=0;return}F=requestAnimationFrame(a)};F=requestAnimationFrame(a)}let Ke=0,P="connecting",Se=0,ae=!1,Te=[],G="",_=!1,oe=1e3,qt=location.protocol==="https:"?"wss:":"ws:",Kt=n.wsBase||"/ws",Vt=qt+"//"+location.host+Kt+"/"+encodeURIComponent(t),Xt="/api/session/"+encodeURIComponent(t)+"/upload",Jt=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Qt(){return Te.join("")+G}async function Zt(i,a=0){let d=i?s.viewportY():0,p=me(Qt());if(s.reset(),!p){i||s.scrollToBottom();return}await s.write(p),i?s.scrollToLine(a+d):s.scrollToBottom()}function q(i){l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(i))}function Gt(i){let a;try{a=JSON.parse(i)}catch{P==="live"&&(G+=i,s.write(me(i)));return}if(a.type==="auth.required"){let d=localStorage.getItem("tmux-web-token");d?q({type:"auth.token",token:d}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(a.type==="attach_failed"&&typeof a.message=="string"){Me=!0,P="dead",s.reset(),s.write(`\r
3
+ `)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function Ln(e){let t=e.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(t.width,n.width),height:Math.max(0,Math.min(t.height,n.height-Math.max(0,t.top)))}:t}function En(e,t,n){return e.innerHTML="",e.classList.add("terminal-pending"),(async()=>{let s=await bn.create(e,n.scrollback,n.theme),l,r=0,c,o=null,u=null,h=!1,k=/(?:^|\/)(?:vim|nvim|vi|less|more|htop|btop|top|hx|helix|lazygit)$/,b=null;async function M(){try{let i=(n.wsBase||"/ws").replace(/^\/ws/,"")||"",a=await fetch(i+"/api/session-program?session="+encodeURIComponent(t));if(a.ok){let d=await a.json();u=typeof d.program=="string"&&d.program?d.program:null,h=u!==null&&k.test(u)}}catch{}}function B(){b&&clearTimeout(b),b=setTimeout(()=>{M()},250)}function Z(i){return u!==null&&/(?:^|\/)(?:vim|nvim|vi)$/.test(u)?i?"":"":i?"\x1B[A":"\x1B[B"}let F=0,N=0,se=.2,ie=10,Ut=.95,Wt=.04;function ke(){F&&(cancelAnimationFrame(F),F=0),N=0}function Ot(i){if(ke(),Math.abs(i)<se)return;N=Math.max(-ie,Math.min(ie,i));let a=()=>{if(_){F=0;return}let d=e.querySelector(".xterm-rows > div"),p=d?d.getBoundingClientRect().height:16,w=p>0?Math.round(N*16/p):N>0?1:-1;w===0&&(w=N>0?1:-1);let I=s.viewportY()-w,V=s.baseY(),Y=Math.max(0,Math.min(I,V));if(s.scrollToLine(Y,!0),N*=Ut,Y!==I){F=0;return}if(Math.abs(N)<Wt){F=0;return}F=requestAnimationFrame(a)};F=requestAnimationFrame(a)}let Ke=0,P="connecting",Se=0,ae=!1,Te=[],G="",_=!1,oe=1e3,qt=location.protocol==="https:"?"wss:":"ws:",Kt=n.wsBase||"/ws",Vt=qt+"//"+location.host+Kt+"/"+encodeURIComponent(t),Xt="/api/session/"+encodeURIComponent(t)+"/upload",Jt=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Qt(){return Te.join("")+G}async function Zt(i,a=0){let d=i?s.viewportY():0,p=me(Qt());if(s.reset(),!p){i||s.scrollToBottom();return}await s.write(p),i?s.scrollToLine(a+d):s.scrollToBottom()}function q(i){l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(i))}function Gt(i){let a;try{a=JSON.parse(i)}catch{P==="live"&&(G+=i,s.write(me(i)));return}if(a.type==="auth.required"){let d=localStorage.getItem("tmux-web-token");d?q({type:"auth.token",token:d}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(a.type==="attach_failed"&&typeof a.message=="string"){Me=!0,P="dead",s.reset(),s.write(`\r
4
4
  \x1B[31m`+me(a.message)+`\x1B[0m\r
5
5
  `).then(()=>{Be();try{l?.close()}catch{}});return}if(a.type==="auth.ok"){a.token&&localStorage.setItem("tmux-web-token",a.token),oe=1e3,K(),q({type:"resize",cols:s.cols,rows:s.rows}),S(),M();return}if(a.type==="auth.failed"){if(a.permanentLock||a.retryAfterMs&&a.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(a.message);return}return}if(a.type==="snapshot"&&typeof a.data=="string"){let d=Qe(me(a.data));Te=[d],G="",Se=typeof a.lines=="number"?a.lines:n.terminal.initialLines,P="live",s.reset(),K(),q({type:"resize",cols:s.cols,rows:s.rows}),s.write(d).then(()=>s.scrollToBottom());return}if(a.type==="window_changed"&&typeof a.activeIndex=="number"){let d=new URL(location.href);d.searchParams.get("window")!==String(a.activeIndex)&&(d.searchParams.set("window",String(a.activeIndex)),history.replaceState(history.state,"",d)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:a.windows}));return}if(a.type==="history"&&typeof a.data=="string"){a.lines>0&&a.data?(Te.unshift(Qe(a.data)),Se+=a.lines,Zt(!0,a.lines).finally(()=>{ae=!1})):ae=!1;return}if(a.type==="data"&&typeof a.data=="string"){/\x1b\[\?1049[hl]/.test(a.data)&&B();let d=Qe(me(a.data));if(P==="connecting"){P="live",G=d,s.write(d);return}P==="live"&&(G+=d,s.write(d))}}let Me=!1;function rt(){if(Me)return;let i=Vt,a=localStorage.getItem("tmux-web-token");a&&(i+=(i.includes("?")?"&":"?")+"token="+encodeURIComponent(a)),i+=(i.includes("?")?"&":"?")+"cols="+s.cols+"&rows="+s.rows,l=new WebSocket(i),l.onopen=()=>{P="connecting",Se=0,ae=!1,Te=[],G="",s.reset(),oe=1e3},l.onmessage=d=>{typeof d.data=="string"&&Gt(d.data)},l.onclose=()=>{_||(P="connecting",!Me&&setTimeout(()=>{oe=Math.min(oe*2,1e4),!_&&!Me&&rt()},oe))},l.onerror=()=>l?.close()}function le(i){q({type:"input",data:i})}function K(){return s.fit()}function Be(){e.classList.remove("terminal-pending")}function S(){r&&cancelAnimationFrame(r),c&&clearTimeout(c),K(),r=requestAnimationFrame(()=>{r=0,K()&&Be()}),c=setTimeout(()=>{K()&&Be()},120)}function en(){S(),setTimeout(S,50),setTimeout(S,150),setTimeout(S,300)}function ct(i){return typeof i=="string"&&i.startsWith("image/")}function dt(i){return i?.files?.length?i.files[0]??null:null}function tn(i){if(!i?.items)return null;for(let a=0;a<i.items.length;a++){let d=i.items[a];if(d?.kind==="file"&&ct(d.type))return d.getAsFile()}return null}async function nn(i){let a=new FormData,d=i instanceof File&&i.name?i.name:"upload";a.append("file",i,d);let p=localStorage.getItem("tmux-web-token"),w={};p&&(w.Authorization="Bearer "+p);let I=await fetch(Xt,{method:"POST",body:a,headers:w});if(!I.ok){let Y="upload failed";try{let He=await I.json();He.error&&(Y=He.error)}catch{}throw new Error(Y)}let V=await I.json();if(!V.path)throw new Error("no path in response");return V.path}async function Ve(i){try{let a=await nn(i);le(a)}catch{}}s.onData(i=>le(i)),s.onResize(({cols:i,rows:a})=>q({type:"resize",cols:i,rows:a})),s.onScroll(()=>{P!=="live"||ae||!s.isNearScrollbackTop()||(ae=!0,q({type:"load_history",before:Se}))});let re=!1,ce=!1,L=null,E=null,de=document.createElement("div");de.className="terminal-copy-banner",de.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',de.hidden=!0,e.appendChild(de);let z=document.createElement("div");z.className="terminal-copy-banner terminal-copy-toast",z.textContent="Copied",z.hidden=!0,e.appendChild(z);function ut(i,a){let d=e.querySelector(".xterm-screen, canvas"),p=(d&&d.getBoundingClientRect().width>0?d:e).getBoundingClientRect(),w=p.height>0&&s.rows>0?p.height/s.rows:18,I=p.width>0&&s.cols>0?p.width/s.cols:9;return{row:Math.max(0,Math.min(s.rows-1,Math.floor((a-p.top)/w))),col:Math.max(0,Math.min(s.cols-1,Math.floor((i-p.left)/I)))}}async function Ie(i){if(!i)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(i);return}}catch{}let a=document.createElement("textarea");a.value=i,a.style.position="fixed",a.style.opacity="0",a.style.pointerEvents="none",document.body.appendChild(a),a.focus(),a.select();try{document.execCommand("copy")}catch{}a.remove()}let ue;function De(){z.hidden=!1,ue&&clearTimeout(ue),ue=setTimeout(()=>{z.hidden=!0},1e3)}function ee(i){re=i,de.hidden=!i,e.classList.toggle("terminal-copy-mode-active",i),i&&s.focus()}function pt(){ee(!re)}function sn(i){_||i.button!==0||ce||(re||i.shiftKey)&&(i.preventDefault(),i.stopPropagation(),ce=!0,L=ut(i.clientX,i.clientY),E=L,s.selectCells(L.col,L.row,E.col,E.row),document.addEventListener("mousemove",Xe,!0),document.addEventListener("mouseup",Je,!0))}function Xe(i){_||!ce||!L||(i.preventDefault(),i.stopPropagation(),E=ut(i.clientX,i.clientY),s.selectCells(L.col,L.row,E.col,E.row))}function Je(i){if(_||!ce||!L||!E)return;i.preventDefault(),i.stopPropagation(),document.removeEventListener("mousemove",Xe,!0),document.removeEventListener("mouseup",Je,!0),ce=!1;let a=s.getCellsText(L.col,L.row,E.col,E.row);L=null,E=null,s.clearSelection(),ee(!1),a&&(z.textContent="\u5DF2\u590D\u5236",Ie(a).then(De)),s.focus()}e.addEventListener("mousedown",sn,!0),document.addEventListener("keydown",an,!0);function an(i){if(!(_||!s.isFocused()||i.defaultPrevented||i.isComposing)){if(re){if(i.key==="Escape"){i.preventDefault(),i.stopPropagation(),L=null,E=null,s.clearSelection(),ee(!1);return}if(i.key==="Enter"||(i.ctrlKey||i.metaKey)&&i.code==="KeyC"){i.preventDefault(),i.stopPropagation(),Ie(s.getScreenText()).then(De),ee(!1);return}}if(i.altKey&&i.code==="KeyC"&&!i.ctrlKey&&!i.metaKey){if(i.preventDefault(),i.stopPropagation(),L&&E){let a=s.getCellsText(L.col,L.row,E.col,E.row);L=null,E=null,s.clearSelection(),ee(!1),a&&(z.textContent="Copied",Ie(a).then(De))}else{let a=s.getSelection();a?(s.clearSelection(),z.textContent="Copied",Ie(a).then(De)):pt()}return}if((i.ctrlKey||i.metaKey)&&i.code==="KeyV"){i.preventDefault(),i.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let a=await navigator.clipboard.read();for(let d of a)for(let p of d.types)if(ct(p)){let w=await d.getType(p);await Ve(w);return}}}catch{}try{let a=await navigator.clipboard?.readText();a&&s.pasteText(mt(a))}catch{}})();return}}}let Ae=0;function mt(i){return i.split(`\r
6
6
  `).join(`
@@ -1,6 +1,6 @@
1
1
  const Ht=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function st(a){return a.replace(/\x1b\[\?1049[hl]/g,"")}function U(a){return a.replace(Ht,"")}let N;function Wt(){return N||(document.querySelector("link[data-tmux-web-xterm-css]")?N=Promise.resolve():(N=new Promise(o=>{const r=document.createElement("link");r.rel="stylesheet",r.href="/assets/xterm.css",r.setAttribute("data-tmux-web-xterm-css",""),r.addEventListener("load",()=>o(),{once:!0}),r.addEventListener("error",()=>o(),{once:!0}),document.head.appendChild(r)}),N))}class at{terminal;fitAddon;container;constructor(o,r,n){this.container=o,this.terminal=r,this.fitAddon=n,this.terminal.loadAddon(this.fitAddon),this.terminal.open(o)}static async create(o,r,n){const[{Terminal:l},{FitAddon:f}]=await Promise.all([import("@xterm/xterm"),import("@xterm/addon-fit"),Wt()]),d=new l({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:r,convertEol:!1,smoothScrollDuration:120,theme:n});return new at(o,d,new f)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(o){return new Promise(r=>this.terminal.write(o,r))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(o,r=!1){this.terminal.scrollToLine(Math.max(0,o),r)}scrollLines(o){const r=this.terminal.buffer?.active;this.terminal.scrollLines(o)}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){const o=Vt(this.container);if(o.width<=0||o.height<=0)return!1;const n=this.terminal._core?._renderService?.dimensions?.css?.cell;if(!n?.width||!n?.height)return this.fitAddon.fit(),!0;const l=n.width,f=n.height,d=this.terminal.element?.querySelector(".xterm-viewport"),s=d?Math.max(0,d.offsetWidth-d.clientWidth):0,m=Math.max(2,Math.floor((o.width-s)/l)),g=Math.max(2,Math.floor(o.height/f));return(m!==this.terminal.cols||g!==this.terminal.rows)&&this.terminal.resize(m,g),!0}focus(){this.terminal.focus()}pasteText(o){this.terminal.paste(o)}input(o){this.terminal.input(o,!1)}onData(o){this.terminal.onData(o),this.terminal.onBinary(o)}onResize(o){this.terminal.onResize(o)}onScroll(o){this.terminal.onScroll(o)}attachCustomKeyEventHandler(o){this.terminal.attachCustomKeyEventHandler(o)}isFocused(){const o=document.activeElement;return o?o===this.container||o===this.terminal.textarea||this.container.contains(o)||!!o.closest?.(".xterm"):!1}getScreenText(){return this.getRowsText(0,this.terminal.rows-1)}getRowsText(o,r){const n=this.terminal.buffer.active,[l,f]=o<=r?[o,r]:[r,o],d=n.viewportY,s=[];for(let m=l;m<=f;m++){const g=n.getLine(d+m);s.push(g?g.translateToString(!0):"")}return s.join(`
2
2
  `)}selectRows(o,r){const n=this.terminal.buffer.active,[l,f]=o<=r?[o,r]:[r,o];this.terminal.selectLines(n.viewportY+l,n.viewportY+f)}selectCells(o,r,n,l){const f=this.terminal.buffer.active,d=Math.min(r,l),s=Math.max(r,l);if(d===s){const m=Math.min(o,n),g=Math.max(o,n);this.terminal.select(m,f.viewportY+d,g-m+1)}else this.terminal.selectLines(f.viewportY+d,f.viewportY+s)}getCellsText(o,r,n,l){const f=this.terminal.buffer.active,d=Math.min(r,l),s=Math.max(r,l),m=r<l?o:r>l?n:Math.min(o,n),g=r<l?n:r>l?o:Math.max(o,n),tt=f.viewportY,L=[];for(let M=d;M<=s;M++){const j=f.getLine(tt+M);if(!j){L.push("");continue}const et=M===d?m:0,y=M===s?g:this.terminal.cols-1;let v="";for(let Y=et;Y<=y;Y++){const F=j.getCell(Y);F&&(v+=F.getChars())}L.push(v.replace(/\s+$/,""))}return L.join(`
3
- `)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}}function Vt(a){const o=a.getBoundingClientRect(),r=window.visualViewport;return r?{width:Math.min(o.width,r.width),height:Math.max(0,Math.min(o.height,r.height-Math.max(0,o.top)))}:o}function Jt(a,o,r){return a.innerHTML="",a.classList.add("terminal-pending"),(async()=>{const n=await at.create(a,r.scrollback,r.theme);let l,f=0,d,s=null,m=null,g=!1;const tt=/(?:^|\/)(?:vim|nvim|vi|less|more|htop|btop|top|hx|helix|lazygit)$/;let L=null;async function M(){try{const t=await fetch("/api/session-program?session="+encodeURIComponent(o));if(t.ok){const e=await t.json();m=typeof e.program=="string"&&e.program?e.program:null,g=m!==null&&tt.test(m)}}catch{}}function j(){L&&clearTimeout(L),L=setTimeout(()=>{M()},250)}function et(t){return m!==null&&/(?:^|\/)(?:vim|nvim|vi)$/.test(m)?t?"":"":t?"\x1B[A":"\x1B[B"}let y=0,v=0;const Y=.2,F=10,yt=.95,vt=.04;function H(){y&&(cancelAnimationFrame(y),y=0),v=0}function xt(t){if(H(),Math.abs(t)<Y)return;v=Math.max(-F,Math.min(F,t));const e=()=>{if(S){y=0;return}const i=a.querySelector(".xterm-rows > div"),c=i?i.getBoundingClientRect().height:16;let u=c>0?Math.round(v*16/c):v>0?1:-1;u===0&&(u=v>0?1:-1);const T=n.viewportY()-u,P=n.baseY(),A=Math.max(0,Math.min(T,P));if(n.scrollToLine(A,!0),v*=yt,A!==T){y=0;return}if(Math.abs(v)<vt){y=0;return}y=requestAnimationFrame(e)};y=requestAnimationFrame(e)}let nt=0,b="connecting",W=0,B=!1,V=[],I="",S=!1,K=1e3;const Tt=location.protocol==="https:"?"wss:":"ws:",bt=r.wsBase||"/ws",Et=Tt+"//"+location.host+bt+"/"+encodeURIComponent(o),Mt="/api/session/"+encodeURIComponent(o)+"/upload",St=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Lt(){return V.join("")+I}async function Ct(t,e=0){const i=t?n.viewportY():0,c=U(Lt());if(n.reset(),!c){t||n.scrollToBottom();return}await n.write(c),t?n.scrollToLine(e+i):n.scrollToBottom()}function C(t){l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(t))}function Dt(t){let e;try{e=JSON.parse(t)}catch{b==="live"&&(I+=t,n.write(U(t)));return}if(e.type==="auth.required"){const i=localStorage.getItem("tmux-web-token");i?C({type:"auth.token",token:i}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(e.type==="attach_failed"&&typeof e.message=="string"){J=!0,b="dead",n.reset(),n.write(`\r
3
+ `)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}}function Vt(a){const o=a.getBoundingClientRect(),r=window.visualViewport;return r?{width:Math.min(o.width,r.width),height:Math.max(0,Math.min(o.height,r.height-Math.max(0,o.top)))}:o}function Jt(a,o,r){return a.innerHTML="",a.classList.add("terminal-pending"),(async()=>{const n=await at.create(a,r.scrollback,r.theme);let l,f=0,d,s=null,m=null,g=!1;const tt=/(?:^|\/)(?:vim|nvim|vi|less|more|htop|btop|top|hx|helix|lazygit)$/;let L=null;async function M(){try{const t=(r.wsBase||"/ws").replace(/^\/ws/,"")||"",e=await fetch(t+"/api/session-program?session="+encodeURIComponent(o));if(e.ok){const i=await e.json();m=typeof i.program=="string"&&i.program?i.program:null,g=m!==null&&tt.test(m)}}catch{}}function j(){L&&clearTimeout(L),L=setTimeout(()=>{M()},250)}function et(t){return m!==null&&/(?:^|\/)(?:vim|nvim|vi)$/.test(m)?t?"":"":t?"\x1B[A":"\x1B[B"}let y=0,v=0;const Y=.2,F=10,yt=.95,vt=.04;function H(){y&&(cancelAnimationFrame(y),y=0),v=0}function xt(t){if(H(),Math.abs(t)<Y)return;v=Math.max(-F,Math.min(F,t));const e=()=>{if(S){y=0;return}const i=a.querySelector(".xterm-rows > div"),c=i?i.getBoundingClientRect().height:16;let u=c>0?Math.round(v*16/c):v>0?1:-1;u===0&&(u=v>0?1:-1);const T=n.viewportY()-u,P=n.baseY(),A=Math.max(0,Math.min(T,P));if(n.scrollToLine(A,!0),v*=yt,A!==T){y=0;return}if(Math.abs(v)<vt){y=0;return}y=requestAnimationFrame(e)};y=requestAnimationFrame(e)}let nt=0,b="connecting",W=0,B=!1,V=[],I="",S=!1,K=1e3;const Tt=location.protocol==="https:"?"wss:":"ws:",bt=r.wsBase||"/ws",Et=Tt+"//"+location.host+bt+"/"+encodeURIComponent(o),Mt="/api/session/"+encodeURIComponent(o)+"/upload",St=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Lt(){return V.join("")+I}async function Ct(t,e=0){const i=t?n.viewportY():0,c=U(Lt());if(n.reset(),!c){t||n.scrollToBottom();return}await n.write(c),t?n.scrollToLine(e+i):n.scrollToBottom()}function C(t){l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(t))}function Dt(t){let e;try{e=JSON.parse(t)}catch{b==="live"&&(I+=t,n.write(U(t)));return}if(e.type==="auth.required"){const i=localStorage.getItem("tmux-web-token");i?C({type:"auth.token",token:i}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(e.type==="attach_failed"&&typeof e.message=="string"){J=!0,b="dead",n.reset(),n.write(`\r
4
4
  \x1B[31m`+U(e.message)+`\x1B[0m\r
5
5
  `).then(()=>{$();try{l?.close()}catch{}});return}if(e.type==="auth.ok"){e.token&&localStorage.setItem("tmux-web-token",e.token),K=1e3,D(),C({type:"resize",cols:n.cols,rows:n.rows}),w(),M();return}if(e.type==="auth.failed"){if(e.permanentLock||e.retryAfterMs&&e.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(e.message);return}return}if(e.type==="snapshot"&&typeof e.data=="string"){const i=st(U(e.data));V=[i],I="",W=typeof e.lines=="number"?e.lines:r.terminal.initialLines,b="live",n.reset(),D(),C({type:"resize",cols:n.cols,rows:n.rows}),n.write(i).then(()=>n.scrollToBottom());return}if(e.type==="window_changed"&&typeof e.activeIndex=="number"){const i=new URL(location.href);i.searchParams.get("window")!==String(e.activeIndex)&&(i.searchParams.set("window",String(e.activeIndex)),history.replaceState(history.state,"",i)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:e.windows}));return}if(e.type==="history"&&typeof e.data=="string"){e.lines>0&&e.data?(V.unshift(st(e.data)),W+=e.lines,Ct(!0,e.lines).finally(()=>{B=!1})):B=!1;return}if(e.type==="data"&&typeof e.data=="string"){/\x1b\[\?1049[hl]/.test(e.data)&&j();const i=st(U(e.data));if(b==="connecting"){b="live",I=i,n.write(i);return}b==="live"&&(I+=i,n.write(i))}}let J=!1;function lt(){if(J)return;let t=Et;const e=localStorage.getItem("tmux-web-token");e&&(t+=(t.includes("?")?"&":"?")+"token="+encodeURIComponent(e)),t+=(t.includes("?")?"&":"?")+"cols="+n.cols+"&rows="+n.rows,l=new WebSocket(t),l.onopen=()=>{b="connecting",W=0,B=!1,V=[],I="",n.reset(),K=1e3},l.onmessage=i=>{typeof i.data=="string"&&Dt(i.data)},l.onclose=()=>{S||(b="connecting",!J&&setTimeout(()=>{K=Math.min(K*2,1e4),!S&&!J&&lt()},K))},l.onerror=()=>l?.close()}function z(t){C({type:"input",data:t})}function D(){return n.fit()}function $(){a.classList.remove("terminal-pending")}function w(){f&&cancelAnimationFrame(f),d&&clearTimeout(d),D(),f=requestAnimationFrame(()=>{f=0,D()&&$()}),d=setTimeout(()=>{D()&&$()},120)}function Pt(){w(),setTimeout(w,50),setTimeout(w,150),setTimeout(w,300)}function ct(t){return typeof t=="string"&&t.startsWith("image/")}function ut(t){return t?.files?.length?t.files[0]??null:null}function At(t){if(!t?.items)return null;for(let e=0;e<t.items.length;e++){const i=t.items[e];if(i?.kind==="file"&&ct(i.type))return i.getAsFile()}return null}async function It(t){const e=new FormData,i=t instanceof File&&t.name?t.name:"upload";e.append("file",t,i);const c=localStorage.getItem("tmux-web-token"),u={};c&&(u.Authorization="Bearer "+c);const x=await fetch(Mt,{method:"POST",body:e,headers:u});if(!x.ok){let P="upload failed";try{const A=await x.json();A.error&&(P=A.error)}catch{}throw new Error(P)}const T=await x.json();if(!T.path)throw new Error("no path in response");return T.path}async function ot(t){try{const e=await It(t);z(e)}catch{}}n.onData(t=>z(t)),n.onResize(({cols:t,rows:e})=>C({type:"resize",cols:t,rows:e})),n.onScroll(()=>{b!=="live"||B||!n.isNearScrollbackTop()||(B=!0,C({type:"load_history",before:W}))});let R=!1,X=!1,h=null,p=null;const O=document.createElement("div");O.className="terminal-copy-banner",O.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',O.hidden=!0,a.appendChild(O);const E=document.createElement("div");E.className="terminal-copy-banner terminal-copy-toast",E.textContent="Copied",E.hidden=!0,a.appendChild(E);function ft(t,e){const i=a.querySelector(".xterm-screen, canvas"),u=(i&&i.getBoundingClientRect().width>0?i:a).getBoundingClientRect(),x=u.height>0&&n.rows>0?u.height/n.rows:18,T=u.width>0&&n.cols>0?u.width/n.cols:9;return{row:Math.max(0,Math.min(n.rows-1,Math.floor((e-u.top)/x))),col:Math.max(0,Math.min(n.cols-1,Math.floor((t-u.left)/T)))}}async function G(t){if(!t)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(t);return}}catch{}const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e),e.focus(),e.select();try{document.execCommand("copy")}catch{}e.remove()}let _;function Q(){E.hidden=!1,_&&clearTimeout(_),_=setTimeout(()=>{E.hidden=!0},1e3)}function k(t){R=t,O.hidden=!t,a.classList.toggle("terminal-copy-mode-active",t),t&&n.focus()}function dt(){k(!R)}function kt(t){S||t.button!==0||X||(R||t.shiftKey)&&(t.preventDefault(),t.stopPropagation(),X=!0,h=ft(t.clientX,t.clientY),p=h,n.selectCells(h.col,h.row,p.col,p.row),document.addEventListener("mousemove",it,!0),document.addEventListener("mouseup",rt,!0))}function it(t){S||!X||!h||(t.preventDefault(),t.stopPropagation(),p=ft(t.clientX,t.clientY),n.selectCells(h.col,h.row,p.col,p.row))}function rt(t){if(S||!X||!h||!p)return;t.preventDefault(),t.stopPropagation(),document.removeEventListener("mousemove",it,!0),document.removeEventListener("mouseup",rt,!0),X=!1;const e=n.getCellsText(h.col,h.row,p.col,p.row);h=null,p=null,n.clearSelection(),k(!1),e&&(E.textContent="\u5DF2\u590D\u5236",G(e).then(Q)),n.focus()}a.addEventListener("mousedown",kt,!0),document.addEventListener("keydown",Yt,!0);function Yt(t){if(!(S||!n.isFocused()||t.defaultPrevented||t.isComposing)){if(R){if(t.key==="Escape"){t.preventDefault(),t.stopPropagation(),h=null,p=null,n.clearSelection(),k(!1);return}if(t.key==="Enter"||(t.ctrlKey||t.metaKey)&&t.code==="KeyC"){t.preventDefault(),t.stopPropagation(),G(n.getScreenText()).then(Q),k(!1);return}}if(t.altKey&&t.code==="KeyC"&&!t.ctrlKey&&!t.metaKey){if(t.preventDefault(),t.stopPropagation(),h&&p){const e=n.getCellsText(h.col,h.row,p.col,p.row);h=null,p=null,n.clearSelection(),k(!1),e&&(E.textContent="Copied",G(e).then(Q))}else{const e=n.getSelection();e?(n.clearSelection(),E.textContent="Copied",G(e).then(Q)):dt()}return}if((t.ctrlKey||t.metaKey)&&t.code==="KeyV"){t.preventDefault(),t.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){const e=await navigator.clipboard.read();for(const i of e)for(const c of i.types)if(ct(c)){const u=await i.getType(c);await ot(u);return}}}catch{}try{const e=await navigator.clipboard?.readText();e&&n.pasteText(mt(e))}catch{}})();return}}}let Z=0;function mt(t){return t.split(`\r
6
6
  `).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmux-weblink",
3
- "version": "2.2.17",
3
+ "version": "2.2.18",
4
4
  "description": "Access your tmux sessions from the browser. A continuation of tmux-web and persalink.",
5
5
  "type": "module",
6
6
  "bin": {