herdr-remote-relay 0.3.28 → 0.3.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "herdr-remote-relay",
3
- "version": "0.3.28",
3
+ "version": "0.3.30",
4
4
  "description": "Standalone relay server and web terminal for Herdr Remote",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -58,4 +58,4 @@ ${n.slice(-6).map(a=>` ${a.event}${a.count>1?` ×${a.count}`:""}`).join(`
58
58
  *
59
59
  * Copyright (c) 2021 The xterm.js authors. All rights reserved.
60
60
  * @license MIT
61
- */function ab(l){if(!l)throw new Error("value must not be falsy");return l}const sM={"▀":[{x:0,y:0,w:8,h:4}],"▁":[{x:0,y:7,w:8,h:1}],"▂":[{x:0,y:6,w:8,h:2}],"▃":[{x:0,y:5,w:8,h:3}],"▄":[{x:0,y:4,w:8,h:4}],"▅":[{x:0,y:3,w:8,h:5}],"▆":[{x:0,y:2,w:8,h:6}],"▇":[{x:0,y:1,w:8,h:7}],"█":[{x:0,y:0,w:8,h:8}],"▉":[{x:0,y:0,w:7,h:8}],"▊":[{x:0,y:0,w:6,h:8}],"▋":[{x:0,y:0,w:5,h:8}],"▌":[{x:0,y:0,w:4,h:8}],"▍":[{x:0,y:0,w:3,h:8}],"▎":[{x:0,y:0,w:2,h:8}],"▏":[{x:0,y:0,w:1,h:8}],"▐":[{x:4,y:0,w:4,h:8}],"▔":[{x:0,y:0,w:8,h:1}],"▕":[{x:7,y:0,w:1,h:8}],"▖":[{x:0,y:4,w:4,h:4}],"▗":[{x:4,y:4,w:4,h:4}],"▘":[{x:0,y:0,w:4,h:4}],"▙":[{x:0,y:0,w:4,h:8},{x:0,y:4,w:8,h:4}],"▚":[{x:0,y:0,w:4,h:4},{x:4,y:4,w:4,h:4}],"▛":[{x:0,y:0,w:4,h:8},{x:4,y:0,w:4,h:4}],"▜":[{x:0,y:0,w:8,h:4},{x:4,y:0,w:4,h:8}],"▝":[{x:4,y:0,w:4,h:4}],"▞":[{x:4,y:0,w:4,h:4},{x:0,y:4,w:4,h:4}],"▟":[{x:4,y:0,w:4,h:8},{x:0,y:4,w:8,h:4}],"🭰":[{x:1,y:0,w:1,h:8}],"🭱":[{x:2,y:0,w:1,h:8}],"🭲":[{x:3,y:0,w:1,h:8}],"🭳":[{x:4,y:0,w:1,h:8}],"🭴":[{x:5,y:0,w:1,h:8}],"🭵":[{x:6,y:0,w:1,h:8}],"🭶":[{x:0,y:1,w:8,h:1}],"🭷":[{x:0,y:2,w:8,h:1}],"🭸":[{x:0,y:3,w:8,h:1}],"🭹":[{x:0,y:4,w:8,h:1}],"🭺":[{x:0,y:5,w:8,h:1}],"🭻":[{x:0,y:6,w:8,h:1}],"🭼":[{x:0,y:0,w:1,h:8},{x:0,y:7,w:8,h:1}],"🭽":[{x:0,y:0,w:1,h:8},{x:0,y:0,w:8,h:1}],"🭾":[{x:7,y:0,w:1,h:8},{x:0,y:0,w:8,h:1}],"🭿":[{x:7,y:0,w:1,h:8},{x:0,y:7,w:8,h:1}],"🮀":[{x:0,y:0,w:8,h:1},{x:0,y:7,w:8,h:1}],"🮁":[{x:0,y:0,w:8,h:1},{x:0,y:2,w:8,h:1},{x:0,y:4,w:8,h:1},{x:0,y:7,w:8,h:1}],"🮂":[{x:0,y:0,w:8,h:2}],"🮃":[{x:0,y:0,w:8,h:3}],"🮄":[{x:0,y:0,w:8,h:5}],"🮅":[{x:0,y:0,w:8,h:6}],"🮆":[{x:0,y:0,w:8,h:7}],"🮇":[{x:6,y:0,w:2,h:8}],"🮈":[{x:5,y:0,w:3,h:8}],"🮉":[{x:3,y:0,w:5,h:8}],"🮊":[{x:2,y:0,w:6,h:8}],"🮋":[{x:1,y:0,w:7,h:8}],"🮕":[{x:0,y:0,w:2,h:2},{x:4,y:0,w:2,h:2},{x:2,y:2,w:2,h:2},{x:6,y:2,w:2,h:2},{x:0,y:4,w:2,h:2},{x:4,y:4,w:2,h:2},{x:2,y:6,w:2,h:2},{x:6,y:6,w:2,h:2}],"🮖":[{x:2,y:0,w:2,h:2},{x:6,y:0,w:2,h:2},{x:0,y:2,w:2,h:2},{x:4,y:2,w:2,h:2},{x:2,y:4,w:2,h:2},{x:6,y:4,w:2,h:2},{x:0,y:6,w:2,h:2},{x:4,y:6,w:2,h:2}],"🮗":[{x:0,y:2,w:8,h:2},{x:0,y:6,w:8,h:2}]},oM={"░":[[1,0,0,0],[0,0,0,0],[0,0,1,0],[0,0,0,0]],"▒":[[1,0],[0,0],[0,1],[0,0]],"▓":[[0,1],[1,1],[1,0],[1,1]]},rM={"─":{1:"M0,.5 L1,.5"},"━":{3:"M0,.5 L1,.5"},"│":{1:"M.5,0 L.5,1"},"┃":{3:"M.5,0 L.5,1"},"┌":{1:"M0.5,1 L.5,.5 L1,.5"},"┏":{3:"M0.5,1 L.5,.5 L1,.5"},"┐":{1:"M0,.5 L.5,.5 L.5,1"},"┓":{3:"M0,.5 L.5,.5 L.5,1"},"└":{1:"M.5,0 L.5,.5 L1,.5"},"┗":{3:"M.5,0 L.5,.5 L1,.5"},"┘":{1:"M.5,0 L.5,.5 L0,.5"},"┛":{3:"M.5,0 L.5,.5 L0,.5"},"├":{1:"M.5,0 L.5,1 M.5,.5 L1,.5"},"┣":{3:"M.5,0 L.5,1 M.5,.5 L1,.5"},"┤":{1:"M.5,0 L.5,1 M.5,.5 L0,.5"},"┫":{3:"M.5,0 L.5,1 M.5,.5 L0,.5"},"┬":{1:"M0,.5 L1,.5 M.5,.5 L.5,1"},"┳":{3:"M0,.5 L1,.5 M.5,.5 L.5,1"},"┴":{1:"M0,.5 L1,.5 M.5,.5 L.5,0"},"┻":{3:"M0,.5 L1,.5 M.5,.5 L.5,0"},"┼":{1:"M0,.5 L1,.5 M.5,0 L.5,1"},"╋":{3:"M0,.5 L1,.5 M.5,0 L.5,1"},"╴":{1:"M.5,.5 L0,.5"},"╸":{3:"M.5,.5 L0,.5"},"╵":{1:"M.5,.5 L.5,0"},"╹":{3:"M.5,.5 L.5,0"},"╶":{1:"M.5,.5 L1,.5"},"╺":{3:"M.5,.5 L1,.5"},"╷":{1:"M.5,.5 L.5,1"},"╻":{3:"M.5,.5 L.5,1"},"═":{1:(l,n)=>`M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n}`},"║":{1:(l,n)=>`M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1`},"╒":{1:(l,n)=>`M.5,1 L.5,${.5-n} L1,${.5-n} M.5,${.5+n} L1,${.5+n}`},"╓":{1:(l,n)=>`M${.5-l},1 L${.5-l},.5 L1,.5 M${.5+l},.5 L${.5+l},1`},"╔":{1:(l,n)=>`M1,${.5-n} L${.5-l},${.5-n} L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1`},"╕":{1:(l,n)=>`M0,${.5-n} L.5,${.5-n} L.5,1 M0,${.5+n} L.5,${.5+n}`},"╖":{1:(l,n)=>`M${.5+l},1 L${.5+l},.5 L0,.5 M${.5-l},.5 L${.5-l},1`},"╗":{1:(l,n)=>`M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M0,${.5-n} L${.5+l},${.5-n} L${.5+l},1`},"╘":{1:(l,n)=>`M.5,0 L.5,${.5+n} L1,${.5+n} M.5,${.5-n} L1,${.5-n}`},"╙":{1:(l,n)=>`M1,.5 L${.5-l},.5 L${.5-l},0 M${.5+l},.5 L${.5+l},0`},"╚":{1:(l,n)=>`M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0 M1,${.5+n} L${.5-l},${.5+n} L${.5-l},0`},"╛":{1:(l,n)=>`M0,${.5+n} L.5,${.5+n} L.5,0 M0,${.5-n} L.5,${.5-n}`},"╜":{1:(l,n)=>`M0,.5 L${.5+l},.5 L${.5+l},0 M${.5-l},.5 L${.5-l},0`},"╝":{1:(l,n)=>`M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0 M0,${.5+n} L${.5+l},${.5+n} L${.5+l},0`},"╞":{1:(l,n)=>`M.5,0 L.5,1 M.5,${.5-n} L1,${.5-n} M.5,${.5+n} L1,${.5+n}`},"╟":{1:(l,n)=>`M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1 M${.5+l},.5 L1,.5`},"╠":{1:(l,n)=>`M${.5-l},0 L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1 M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0`},"╡":{1:(l,n)=>`M.5,0 L.5,1 M0,${.5-n} L.5,${.5-n} M0,${.5+n} L.5,${.5+n}`},"╢":{1:(l,n)=>`M0,.5 L${.5-l},.5 M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1`},"╣":{1:(l,n)=>`M${.5+l},0 L${.5+l},1 M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0`},"╤":{1:(l,n)=>`M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n} M.5,${.5+n} L.5,1`},"╥":{1:(l,n)=>`M0,.5 L1,.5 M${.5-l},.5 L${.5-l},1 M${.5+l},.5 L${.5+l},1`},"╦":{1:(l,n)=>`M0,${.5-n} L1,${.5-n} M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1`},"╧":{1:(l,n)=>`M.5,0 L.5,${.5-n} M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n}`},"╨":{1:(l,n)=>`M0,.5 L1,.5 M${.5-l},.5 L${.5-l},0 M${.5+l},.5 L${.5+l},0`},"╩":{1:(l,n)=>`M0,${.5+n} L1,${.5+n} M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0 M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0`},"╪":{1:(l,n)=>`M.5,0 L.5,1 M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n}`},"╫":{1:(l,n)=>`M0,.5 L1,.5 M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1`},"╬":{1:(l,n)=>`M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1 M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0 M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0`},"╱":{1:"M1,0 L0,1"},"╲":{1:"M0,0 L1,1"},"╳":{1:"M1,0 L0,1 M0,0 L1,1"},"╼":{1:"M.5,.5 L0,.5",3:"M.5,.5 L1,.5"},"╽":{1:"M.5,.5 L.5,0",3:"M.5,.5 L.5,1"},"╾":{1:"M.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"╿":{1:"M.5,.5 L.5,1",3:"M.5,.5 L.5,0"},"┍":{1:"M.5,.5 L.5,1",3:"M.5,.5 L1,.5"},"┎":{1:"M.5,.5 L1,.5",3:"M.5,.5 L.5,1"},"┑":{1:"M.5,.5 L.5,1",3:"M.5,.5 L0,.5"},"┒":{1:"M.5,.5 L0,.5",3:"M.5,.5 L.5,1"},"┕":{1:"M.5,.5 L.5,0",3:"M.5,.5 L1,.5"},"┖":{1:"M.5,.5 L1,.5",3:"M.5,.5 L.5,0"},"┙":{1:"M.5,.5 L.5,0",3:"M.5,.5 L0,.5"},"┚":{1:"M.5,.5 L0,.5",3:"M.5,.5 L.5,0"},"┝":{1:"M.5,0 L.5,1",3:"M.5,.5 L1,.5"},"┞":{1:"M0.5,1 L.5,.5 L1,.5",3:"M.5,.5 L.5,0"},"┟":{1:"M.5,0 L.5,.5 L1,.5",3:"M.5,.5 L.5,1"},"┠":{1:"M.5,.5 L1,.5",3:"M.5,0 L.5,1"},"┡":{1:"M.5,.5 L.5,1",3:"M.5,0 L.5,.5 L1,.5"},"┢":{1:"M.5,.5 L.5,0",3:"M0.5,1 L.5,.5 L1,.5"},"┥":{1:"M.5,0 L.5,1",3:"M.5,.5 L0,.5"},"┦":{1:"M0,.5 L.5,.5 L.5,1",3:"M.5,.5 L.5,0"},"┧":{1:"M.5,0 L.5,.5 L0,.5",3:"M.5,.5 L.5,1"},"┨":{1:"M.5,.5 L0,.5",3:"M.5,0 L.5,1"},"┩":{1:"M.5,.5 L.5,1",3:"M.5,0 L.5,.5 L0,.5"},"┪":{1:"M.5,.5 L.5,0",3:"M0,.5 L.5,.5 L.5,1"},"┭":{1:"M0.5,1 L.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"┮":{1:"M0,.5 L.5,.5 L.5,1",3:"M.5,.5 L1,.5"},"┯":{1:"M.5,.5 L.5,1",3:"M0,.5 L1,.5"},"┰":{1:"M0,.5 L1,.5",3:"M.5,.5 L.5,1"},"┱":{1:"M.5,.5 L1,.5",3:"M0,.5 L.5,.5 L.5,1"},"┲":{1:"M.5,.5 L0,.5",3:"M0.5,1 L.5,.5 L1,.5"},"┵":{1:"M.5,0 L.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"┶":{1:"M.5,0 L.5,.5 L0,.5",3:"M.5,.5 L1,.5"},"┷":{1:"M.5,.5 L.5,0",3:"M0,.5 L1,.5"},"┸":{1:"M0,.5 L1,.5",3:"M.5,.5 L.5,0"},"┹":{1:"M.5,.5 L1,.5",3:"M.5,0 L.5,.5 L0,.5"},"┺":{1:"M.5,.5 L0,.5",3:"M.5,0 L.5,.5 L1,.5"},"┽":{1:"M.5,0 L.5,1 M.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"┾":{1:"M.5,0 L.5,1 M.5,.5 L0,.5",3:"M.5,.5 L1,.5"},"┿":{1:"M.5,0 L.5,1",3:"M0,.5 L1,.5"},"╀":{1:"M0,.5 L1,.5 M.5,.5 L.5,1",3:"M.5,.5 L.5,0"},"╁":{1:"M.5,.5 L.5,0 M0,.5 L1,.5",3:"M.5,.5 L.5,1"},"╂":{1:"M0,.5 L1,.5",3:"M.5,0 L.5,1"},"╃":{1:"M0.5,1 L.5,.5 L1,.5",3:"M.5,0 L.5,.5 L0,.5"},"╄":{1:"M0,.5 L.5,.5 L.5,1",3:"M.5,0 L.5,.5 L1,.5"},"╅":{1:"M.5,0 L.5,.5 L1,.5",3:"M0,.5 L.5,.5 L.5,1"},"╆":{1:"M.5,0 L.5,.5 L0,.5",3:"M0.5,1 L.5,.5 L1,.5"},"╇":{1:"M.5,.5 L.5,1",3:"M.5,.5 L.5,0 M0,.5 L1,.5"},"╈":{1:"M.5,.5 L.5,0",3:"M0,.5 L1,.5 M.5,.5 L.5,1"},"╉":{1:"M.5,.5 L1,.5",3:"M.5,0 L.5,1 M.5,.5 L0,.5"},"╊":{1:"M.5,.5 L0,.5",3:"M.5,0 L.5,1 M.5,.5 L1,.5"},"╌":{1:"M.1,.5 L.4,.5 M.6,.5 L.9,.5"},"╍":{3:"M.1,.5 L.4,.5 M.6,.5 L.9,.5"},"┄":{1:"M.0667,.5 L.2667,.5 M.4,.5 L.6,.5 M.7333,.5 L.9333,.5"},"┅":{3:"M.0667,.5 L.2667,.5 M.4,.5 L.6,.5 M.7333,.5 L.9333,.5"},"┈":{1:"M.05,.5 L.2,.5 M.3,.5 L.45,.5 M.55,.5 L.7,.5 M.8,.5 L.95,.5"},"┉":{3:"M.05,.5 L.2,.5 M.3,.5 L.45,.5 M.55,.5 L.7,.5 M.8,.5 L.95,.5"},"╎":{1:"M.5,.1 L.5,.4 M.5,.6 L.5,.9"},"╏":{3:"M.5,.1 L.5,.4 M.5,.6 L.5,.9"},"┆":{1:"M.5,.0667 L.5,.2667 M.5,.4 L.5,.6 M.5,.7333 L.5,.9333"},"┇":{3:"M.5,.0667 L.5,.2667 M.5,.4 L.5,.6 M.5,.7333 L.5,.9333"},"┊":{1:"M.5,.05 L.5,.2 M.5,.3 L.5,.45 L.5,.55 M.5,.7 L.5,.95"},"┋":{3:"M.5,.05 L.5,.2 M.5,.3 L.5,.45 L.5,.55 M.5,.7 L.5,.95"},"╭":{1:(l,n)=>`M.5,1 L.5,${.5+n/.15*.5} C.5,${.5+n/.15*.5},.5,.5,1,.5`},"╮":{1:(l,n)=>`M.5,1 L.5,${.5+n/.15*.5} C.5,${.5+n/.15*.5},.5,.5,0,.5`},"╯":{1:(l,n)=>`M.5,0 L.5,${.5-n/.15*.5} C.5,${.5-n/.15*.5},.5,.5,0,.5`},"╰":{1:(l,n)=>`M.5,0 L.5,${.5-n/.15*.5} C.5,${.5-n/.15*.5},.5,.5,1,.5`}},As={"":{d:"M0,0 L1,.5 L0,1",type:0,rightPadding:2},"":{d:"M-1,-.5 L1,.5 L-1,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M1,0 L0,.5 L1,1",type:0,leftPadding:2},"":{d:"M2,-.5 L0,.5 L2,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M0,0 L0,1 C0.552,1,1,0.776,1,.5 C1,0.224,0.552,0,0,0",type:0,rightPadding:1},"":{d:"M.2,1 C.422,1,.8,.826,.78,.5 C.8,.174,0.422,0,.2,0",type:1,rightPadding:1},"":{d:"M1,0 L1,1 C0.448,1,0,0.776,0,.5 C0,0.224,0.448,0,1,0",type:0,leftPadding:1},"":{d:"M.8,1 C0.578,1,0.2,.826,.22,.5 C0.2,0.174,0.578,0,0.8,0",type:1,leftPadding:1},"":{d:"M-.5,-.5 L1.5,1.5 L-.5,1.5",type:0},"":{d:"M-.5,-.5 L1.5,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M1.5,-.5 L-.5,1.5 L1.5,1.5",type:0},"":{d:"M1.5,-.5 L-.5,1.5 L-.5,-.5",type:0},"":{d:"M1.5,-.5 L-.5,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M-.5,-.5 L1.5,1.5 L1.5,-.5",type:0}};As[""]=As[""];As[""]=As[""];function cM(l,n,a,s,r,c,f,m){const p=sM[n];if(p)return uM(l,p,a,s,r,c),!0;const g=oM[n];if(g)return dM(l,g,a,s,r,c),!0;const y=rM[n];if(y)return fM(l,y,a,s,r,c,m),!0;const v=As[n];return v?(hM(l,v,a,s,r,c,f,m),!0):!1}function uM(l,n,a,s,r,c){for(let f=0;f<n.length;f++){const m=n[f],p=r/8,g=c/8;l.fillRect(a+m.x*p,s+m.y*g,m.w*p,m.h*g)}}const sb=new Map;function dM(l,n,a,s,r,c){let f=sb.get(n);f||(f=new Map,sb.set(n,f));const m=l.fillStyle;if(typeof m!="string")throw new Error(`Unexpected fillStyle type "${m}"`);let p=f.get(m);if(!p){const g=n[0].length,y=n.length,v=l.canvas.ownerDocument.createElement("canvas");v.width=g,v.height=y;const w=ab(v.getContext("2d")),x=new ImageData(g,y);let S,T,A,k;if(m.startsWith("#"))S=parseInt(m.slice(1,3),16),T=parseInt(m.slice(3,5),16),A=parseInt(m.slice(5,7),16),k=m.length>7&&parseInt(m.slice(7,9),16)||1;else if(m.startsWith("rgba"))[S,T,A,k]=m.substring(5,m.length-1).split(",").map(E=>parseFloat(E));else throw new Error(`Unexpected fillStyle color format "${m}" when drawing pattern glyph`);for(let E=0;E<y;E++)for(let N=0;N<g;N++)x.data[(E*g+N)*4]=S,x.data[(E*g+N)*4+1]=T,x.data[(E*g+N)*4+2]=A,x.data[(E*g+N)*4+3]=n[E][N]*(k*255);w.putImageData(x,0,0),p=ab(l.createPattern(v,null)),f.set(m,p)}l.fillStyle=p,l.fillRect(a,s,r,c)}function fM(l,n,a,s,r,c,f){l.strokeStyle=l.fillStyle;for(const[m,p]of Object.entries(n)){l.beginPath(),l.lineWidth=f*Number.parseInt(m,10);let g;if(typeof p=="function"){const v=.15/c*r;g=p(.15,v)}else g=p;for(const y of g.split(" ")){const v=y[0],w=Zy[v];if(!w){console.error(`Could not find drawing instructions for "${v}"`);continue}const x=y.substring(1).split(",");!x[0]||!x[1]||w(l,Wy(x,r,c,a,s,!0,f))}l.stroke(),l.closePath()}}function hM(l,n,a,s,r,c,f,m){const p=new Path2D;p.rect(a,s,r,c),l.clip(p),l.beginPath();const g=f/12;l.lineWidth=m*g;for(const y of n.d.split(" ")){const v=y[0],w=Zy[v];if(!w){console.error(`Could not find drawing instructions for "${v}"`);continue}const x=y.substring(1).split(",");!x[0]||!x[1]||w(l,Wy(x,r,c,a,s,!1,m,(n.leftPadding??0)*(g/2),(n.rightPadding??0)*(g/2)))}n.type===1?(l.strokeStyle=l.fillStyle,l.stroke()):l.fill(),l.closePath()}function ob(l,n,a=0){return Math.max(Math.min(l,n),a)}const Zy={C:(l,n)=>l.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]),L:(l,n)=>l.lineTo(n[0],n[1]),M:(l,n)=>l.moveTo(n[0],n[1])};function Wy(l,n,a,s,r,c,f,m=0,p=0){const g=l.map(y=>parseFloat(y)||parseInt(y,10));if(g.length<2)throw new Error("Too few arguments for instruction");for(let y=0;y<g.length;y+=2)g[y]*=n-m*f-p*f,c&&g[y]!==0&&(g[y]=ob(Math.round(g[y]+.5)-.5,n,0)),g[y]+=s+m*f;for(let y=1;y<g.length;y+=2)g[y]*=a,c&&g[y]!==0&&(g[y]=ob(Math.round(g[y]+.5)-.5,a,0)),g[y]+=r;return g}const Xd=.5,mM=1024,pM=6;function gM(l){return/Firefox\//.test(l)||/Edge\/\d/.test(l)?"bottom":"ideographic"}class bM{constructor(n,a=typeof navigator<"u"?navigator.userAgent:""){$(this,"pages",[]);$(this,"slots",new Map);$(this,"inkCache",new Map);$(this,"metrics",null);$(this,"font",null);$(this,"baseline");$(this,"generation",0);$(this,"scratch");this.document=n,this.baseline=gM(a)}configure(n,a){const s=this.metrics&&this.font&&this.metrics.cellWidth===n.cellWidth&&this.metrics.cellHeight===n.cellHeight&&this.metrics.charWidth===n.charWidth&&this.metrics.charHeight===n.charHeight&&this.metrics.charLeft===n.charLeft&&this.metrics.charTop===n.charTop&&this.metrics.dpr===n.dpr&&this.font.fontFamily===a.fontFamily&&this.font.fontSize===a.fontSize&&this.font.fontWeight===a.fontWeight&&this.font.fontWeightBold===a.fontWeightBold&&this.font.customGlyphs===a.customGlyphs;this.metrics={...n},this.font={...a},s||this.clear()}clear(){this.slots.clear(),this.inkCache.clear();for(const n of this.pages)n.shelfX=0,n.shelfY=0;this.generation++}dispose(){this.slots.clear(),this.inkCache.clear();for(const n of this.pages)n.canvas.width=0,n.canvas.height=0;this.pages=[]}get pageCount(){return this.pages.length}fontString(n,a){const s=this.font,r=n?s.fontWeightBold:s.fontWeight;return`${a?"italic ":""}${r} ${s.fontSize*this.metrics.dpr}px ${s.fontFamily}`}overflow(n,a,s){if(!this.metrics||!this.font||n.length===1&&n.charCodeAt(0)<128)return 0;const r=`${a?1:0}${s?1:0}${n}`,c=this.inkCache.get(r);if(c!==void 0)return c;let f=0;const m=this.scratchContext();if(m&&!(this.font.customGlyphs&&Qy(n))){m.font=this.fontString(a,s),m.textBaseline=this.baseline;const p=m.measureText(n),g=typeof p.actualBoundingBoxRight=="number"?p.actualBoundingBoxRight:p.width;f=Math.max(0,Math.ceil(this.metrics.charLeft+g-this.metrics.cellWidth))}return this.inkCache.set(r,f),f}get(n){const a=this.metrics,s=this.font;if(!a||!s||a.cellWidth<=0||a.cellHeight<=0)return null;const r=`${n.cells}${n.bold?1:0}${n.italic?1:0}${n.dim?1:0}${n.fg}\0${n.bg}\0${n.chars}`,c=this.slots.get(r);if(c)return c;const f=a.cellWidth*n.cells,m=a.cellHeight,p=this.allocate(f,m);if(!p)return null;const{page:g,x:y,y:v}=p,w=g.ctx;w.save(),w.beginPath(),w.rect(y,v,f,m),w.clip(),w.globalAlpha=1,w.fillStyle=n.bg,w.fillRect(y,v,f,m),w.fillStyle=n.fg,n.dim&&(w.globalAlpha=Xd);let x=!1;s.customGlyphs&&(x=cM(w,n.chars,y,v,a.cellWidth,a.cellHeight,s.fontSize,a.dpr)),x||(w.font=this.fontString(n.bold,n.italic),w.textBaseline=this.baseline,w.fillText(n.chars,y+a.charLeft,v+a.charTop+a.charHeight)),w.restore();const S={source:g.canvas,x:y,y:v,width:f,height:m};return this.slots.set(r,S),S}allocate(n,a){for(const s of this.pages){const r=this.fit(s,n,a);if(r)return r}if(this.pages.length<pM){const s=this.createPage(Math.max(mM,n,a));return s?(this.pages.push(s),this.fit(s,n,a)):null}return this.clear(),this.pages[0]?this.fit(this.pages[0],n,a):null}fit(n,a,s){if(n.shelfX+a>n.canvas.width&&(n.shelfX=0,n.shelfY+=s),n.shelfY+s>n.canvas.height||a>n.canvas.width)return null;const r={page:n,x:n.shelfX,y:n.shelfY};return n.shelfX+=a,r}createPage(n){const a=this.document.createElement("canvas");a.width=n,a.height=n;const s=a.getContext("2d",{alpha:!1});return s?{canvas:a,ctx:s,shelfX:0,shelfY:0}:null}scratchContext(){if(this.scratch===void 0){const n=this.document.createElement("canvas");n.width=1,n.height=1,this.scratch=n.getContext("2d")}return this.scratch}}function Qy(l){if(l.length!==1)return!1;const n=l.charCodeAt(0);return n>=9472&&n<=9631||n>=57504&&n<=57558}function yM(l,n){return(l&(st.UNDERLINE|st.STRIKETHROUGH))!==0||(n&ji.OVERLINE)!==0}function vM(l,n,{px:a,py:s,cells:r,fgWord:c,bgWord:f,ext:m,fgCss:p},{fontSize:g,dpr:y,colors:v,boldBright:w}){const x=(c&st.UNDERLINE)!==0,S=(c&st.STRIKETHROUGH)!==0,T=(f&ji.OVERLINE)!==0,A=r*n.cell.width;l.save(),l.beginPath(),l.rect(a,s,A,n.cell.height),l.clip(),Ms(f)&&(l.globalAlpha=Xd);const k=Math.max(1,Math.floor(g*y/15)),E=k%2===1?.5:0;if(x){const N=qC(m);let B=p;if(N){let R=N;w&&sa(c)&&(R&50331648)!==50331648&&(R&255)<8&&(R+=8),B=Dy(R,v,p)}l.strokeStyle=B,l.lineWidth=k;const L=s+n.char.top+Math.ceil(n.char.height)-E-k*2,D=m?VC(m):ta.SINGLE;switch(l.beginPath(),D){case ta.DOUBLE:l.moveTo(a,L),l.lineTo(a+A,L),l.moveTo(a,L+k*2),l.lineTo(a+A,L+k*2);break;case ta.CURLY:{const R=L+k,z=Math.max(1,k);for(let K=0;K<r;K++){const V=a+K*n.cell.width,te=V+n.cell.width/2,Z=V+n.cell.width;l.moveTo(V,R),l.bezierCurveTo(V,R-z,te,R-z,te,R),l.bezierCurveTo(te,R+z,Z,R+z,Z,R)}break}case ta.DOTTED:l.setLineDash([k,k]),l.moveTo(a,L),l.lineTo(a+A,L);break;case ta.DASHED:{const R=Math.floor(.6*n.cell.width),z=Math.floor(.3*n.cell.width);l.setLineDash([R,z,n.cell.width-R-z]),l.moveTo(a,L),l.lineTo(a+A,L);break}default:l.moveTo(a,L),l.lineTo(a+A,L)}l.stroke(),l.setLineDash([])}if(T&&(l.strokeStyle=p,l.lineWidth=k,l.beginPath(),l.moveTo(a,s+n.char.top+E),l.lineTo(a+A,s+n.char.top+E),l.stroke()),S){const N=Math.max(1,Math.floor(g*y/10)),B=s+n.char.top+Math.floor(n.char.height/2)-(N%2===1?.5:0);l.strokeStyle=p,l.lineWidth=N,l.beginPath(),l.moveTo(a,B),l.lineTo(a+A,B),l.stroke()}l.restore()}const ld=4,xM=3;class wM{constructor(n,a,s,r){$(this,"atlas");$(this,"fades",new lM);$(this,"cols",0);$(this,"rows",0);$(this,"painted",{content:new Uint32Array(0),fg:new Uint32Array(0),bg:new Uint32Array(0),ext:new Uint32Array(0),meta:new Uint32Array(0),combined:[]});$(this,"row",{content:new Uint32Array(0),fg:new Uint32Array(0),bg:new Uint32Array(0),ext:new Uint32Array(0),combined:[]});$(this,"work",$C());this.ctx=n,this.core=s,this.dimensions=r,this.atlas=new bM(a)}resize(n,a){this.cols=n,this.rows=a,this.fades.clear();const s=n*a;this.painted={content:new Uint32Array(s).fill(ea),fg:new Uint32Array(s),bg:new Uint32Array(s),ext:new Uint32Array(s),meta:new Uint32Array(s).fill(ea),combined:new Array(s).fill("")},this.row={content:new Uint32Array(n),fg:new Uint32Array(n),bg:new Uint32Array(n),ext:new Uint32Array(n),combined:new Array(n).fill("")}}invalidate(){this.painted.content.fill(ea),this.painted.meta.fill(ea),this.fades.clear()}hasPaintedInk(n,a){const s=this.dimensions.device;if(!s.cell.width||!s.cell.height)return!1;const r=Math.min(this.cols,Math.floor(n/s.cell.width)),c=Math.min(this.rows,Math.floor(a/s.cell.height)),f=this.painted;for(let m=0;m<c;m++)for(let p=0;p<r;p++){const g=m*this.cols+p,y=f.content[g];if(y===ea||f.meta[g]===ld||ia(f.fg[g]))continue;const v=y&We.CODEPOINT_MASK;if(y&We.IS_COMBINED_MASK?f.combined[g]!=="":v!==0&&v!==32)return!0}return!1}loadRow(n,a){const{content:s,fg:r,bg:c,ext:f,combined:m}=this.row,p=this.work;for(let g=0;g<this.cols;g++)n&&g<n.length?(n.loadCell(g,p),s[g]=p.content,r[g]=p.fg,c[g]=p.bg,f[g]=jy(p),m[g]=p.content&We.IS_COMBINED_MASK?p.combinedData:""):(s[g]=1<<We.WIDTH_SHIFT,r[g]=0,c[g]=0,f[g]=0,m[g]="");if(a)for(const g of a){const y=g.col;if(y<0||y+g.width>this.cols)continue;y>0&&!(s[y]>>>We.WIDTH_SHIFT)&&this.blankAt(y-1);const v=y+g.width;v<this.cols&&!(s[v]>>>We.WIDTH_SHIFT)&&s[v-1]>>>We.WIDTH_SHIFT===2&&this.blankAt(v);const w=XC(g.chars,g.width);s[y]=w.content,m[y]=w.combinedData,r[y]=g.style.fg,c[y]=g.style.bg,f[y]=g.style.ext,g.width===2&&(s[y+1]=0,m[y+1]="",r[y+1]=g.style.fg,c[y+1]=g.style.bg,f[y+1]=g.style.ext)}}blankAt(n){this.row.content[n]=32|1<<We.WIDTH_SHIFT,this.row.combined[n]=""}paintRow(n,a,s=null,r=0){const c=this.cols,{content:f,fg:m,bg:p,ext:g,combined:y}=this.row,v=this.painted,w=n*c;s&&this.fades.begin(n,c,s,v,this.row,r);let x=0,S=-1,T=-1,A="";const k=()=>{S<0||(this.fillCells(S,n,T-S,A),S=-1)};let E=0;for(;E<c;){let B=f[E]>>>We.WIDTH_SHIFT;B===0&&(B=1),E+B>c&&(B=c-E),B===1&&E+1<c&&this.overflowsInto(E)&&(B=2);const L=a&&a.y===n&&a.x>=E&&a.x<E+B?a.shape:Zn.NONE,D=B|L<<xM,R=this.fades.size>0?this.fades.at(w+E,E,this.row,r):null;let z=R!==null||this.differs(w+E,E,D);for(let K=1;K<B;K++)this.differs(w+E+K,E+K,ld)&&(z=!0);if(z){for(let V=0;V<B;V++){const te=w+E+V;v.content[te]=f[E+V],v.fg[te]=m[E+V],v.bg[te]=p[E+V],v.ext[te]=g[E+V],v.meta[te]=V===0?R?D|iM:D:ld,v.combined[te]=y[E+V]}x+=B;const K=R?null:this.plainFill(E,L);K!==null?S>=0&&T===E&&A===K?T=E+B:(k(),S=E,T=E+B,A=K):(k(),this.paintCell(E,n,B,L,R))}E+=B}return k(),x}differs(n,a,s){const r=this.painted,c=this.row;return r.meta[n]!==s||r.content[n]!==c.content[a]||r.fg[n]!==c.fg[a]||r.bg[n]!==c.bg[a]||r.ext[n]!==c.ext[a]||r.combined[n]!==c.combined[a]}overflowsInto(n){const{content:a,fg:s,bg:r,ext:c}=this.row,f=a[n];if((f&We.CODEPOINT_MASK)<128&&!(f&We.IS_COMBINED_MASK)||f>>>We.WIDTH_SHIFT!==1||ia(s[n]))return!1;const p=a[n+1],g=p&We.CODEPOINT_MASK;if(p>>>We.WIDTH_SHIFT!==1||p&We.IS_COMBINED_MASK||g!==0&&g!==32||r[n]!==r[n+1]||c[n+1]!==0||(s[n]&st.INVERSE)!==(s[n+1]&st.INVERSE)||s[n]&st.INVERSE&&s[n]!==s[n+1]||s[n+1]&(st.UNDERLINE|st.STRIKETHROUGH)||r[n+1]&ji.OVERLINE)return!1;const y=this.charsAt(n);return this.core.optionsService.rawOptions.customGlyphs!==!1&&Qy(y)?!1:this.atlas.overflow(y,sa(s[n]),ys(r[n]))>0}charsAt(n){const a=this.row.content[n];if(a&We.IS_COMBINED_MASK)return this.row.combined[n];const s=a&We.CODEPOINT_MASK;return s?String.fromCodePoint(s):""}plainFill(n,a){if(a!==Zn.NONE)return null;const{content:s,fg:r,bg:c}=this.row,f=s[n],m=f&We.CODEPOINT_MASK,p=!(f&We.IS_COMBINED_MASK)&&(m===0||m===32),g=ia(r[n]);return!p&&!g||(r[n]&(st.UNDERLINE|st.STRIKETHROUGH)||c[n]&ji.OVERLINE)&&!g?null:bs(r[n],c[n],this.colors(),this.boldBright()).bg}paintCell(n,a,s,r,c=null){const f=this.ctx,m=this.dimensions.device,p=this.colors(),g=this.row.fg[n],y=this.row.bg[n],v=this.row.ext[n],w=bs(g,y,p,this.boldBright());let x=w.fg,S=w.bg;r===Zn.BLOCK&&(S=p.cursor.css,x=p.cursorAccent.css);const T=ia(g),A=this.charsAt(n),k=n*m.cell.width,E=a*m.cell.height,N=s*m.cell.width,B=m.cell.height,L=T||A===""||A===" ",D=L?null:this.atlas.get({chars:A,bold:sa(g),italic:ys(y),dim:Ms(y),fg:x,bg:S,cells:s}),R=c&&!c.gone?c.alpha:1;if(D&&R===1?f.drawImage(D.source,D.x,D.y,D.width,D.height,k,E,N,B):(f.fillStyle=S,f.fillRect(k,E,N,B),D?(f.globalAlpha=R,f.drawImage(D.source,D.x,D.y,D.width,D.height,k,E,N,B),f.globalAlpha=1):L||(f.save(),f.beginPath(),f.rect(k,E,N,B),f.clip(),f.fillStyle=x,f.globalAlpha=(Ms(y)?Xd:1)*R,f.font=this.atlas.fontString(sa(g),ys(y)),f.fillText(A,k+m.char.left,E+m.char.top+m.char.height),f.restore())),c!=null&&c.gone){const K=r===Zn.BLOCK||(g&st.INVERSE)!==0?x:bs(c.gone.fg,c.gone.bg,p,this.boldBright()).fg;aM(f,this.atlas,c,{fg:K,bg:S},{px:k,py:E,width:N,height:B,cells:s})}!T&&yM(g,y)&&vM(f,m,{px:k,py:E,cells:s,fgWord:g,bgWord:y,ext:v,fgCss:x},{fontSize:this.core.optionsService.rawOptions.fontSize,dpr:this.core._coreBrowserService.dpr,colors:p,boldBright:this.boldBright()}),r!==Zn.NONE&&r!==Zn.BLOCK&&Xy(f,m,k,E,N,r,{css:p.cursor.css,dpr:this.core._coreBrowserService.dpr,cursorWidth:this.core.optionsService.rawOptions.cursorWidth})}fillCells(n,a,s,r){const c=this.dimensions.device;this.ctx.fillStyle=r,this.ctx.fillRect(n*c.cell.width,a*c.cell.height,s*c.cell.width,c.cell.height)}fillBackground(){this.ctx.fillStyle=this.colors().background.css,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}configureAtlas(){const n=this.dimensions.device,a=this.core.optionsService.rawOptions;this.atlas.configure({cellWidth:n.cell.width,cellHeight:n.cell.height,charWidth:n.char.width,charHeight:n.char.height,charLeft:n.char.left,charTop:n.char.top,dpr:this.core._coreBrowserService.dpr},{fontFamily:a.fontFamily,fontSize:a.fontSize,fontWeight:a.fontWeight,fontWeightBold:a.fontWeightBold,customGlyphs:a.customGlyphs!==!1})}colors(){return this.core._themeService.colors}boldBright(){return this.core.optionsService.rawOptions.drawBoldTextInBrightColors!==!1}}function SM(){return{css:{canvas:{width:0,height:0},cell:{width:0,height:0}},device:{canvas:{width:0,height:0},cell:{width:0,height:0},char:{width:0,height:0,left:0,top:0}}}}function CM(l,n,a,s){const r=n._charSizeService;if(!r.hasValidSize)return!1;const c=n._coreBrowserService.dpr,f=n.optionsService.rawOptions;return l.device.char.width=Math.floor(r.width*c),l.device.char.height=Math.ceil(r.height*c),l.device.cell.height=Math.floor(l.device.char.height*f.lineHeight),l.device.char.top=f.lineHeight===1?0:Math.round((l.device.cell.height-l.device.char.height)/2),l.device.cell.width=l.device.char.width+Math.round(f.letterSpacing),l.device.char.left=Math.floor(f.letterSpacing/2),l.device.canvas.height=s*l.device.cell.height,l.device.canvas.width=a*l.device.cell.width,l.css.canvas.height=Math.round(l.device.canvas.height/c),l.css.canvas.width=Math.round(l.device.canvas.width/c),l.css.cell.height=l.css.canvas.height/s,l.css.cell.width=l.css.canvas.width/a,!0}function TM(l,n,a){if(!l||typeof l.ResizeObserver!="function")return null;let s=new l.ResizeObserver(r=>{var p;const c=r.find(g=>g.target===n);if(!c)return;if(!("devicePixelContentBoxSize"in c)||!((p=c.devicePixelContentBoxSize)!=null&&p[0])){s==null||s.disconnect(),s=null;return}const f=c.devicePixelContentBoxSize[0].inlineSize,m=c.devicePixelContentBoxSize[0].blockSize;f<=0||m<=0||f===n.width&&m===n.height||a(f,m)});try{s.observe(n,{box:"device-pixel-content-box"})}catch{s.disconnect(),s=null}return{dispose:()=>s==null?void 0:s.disconnect()}}function MM(l){if(!l)return[];const n=l.cells.map(a=>a.row);return l.cursor&&n.push(l.cursor.row),n}function AM(l){const n=new Map;for(const a of(l==null?void 0:l.cells)??[]){const s=n.get(a.row);s?s.push(a):n.set(a.row,[a])}return n}class EM{constructor(n){$(this,"canvas");$(this,"ctx");$(this,"selection",null);$(this,"link",null);this.canvas=n.createElement("canvas"),this.canvas.classList.add("xterm-decor-layer"),this.canvas.style.zIndex="2";const a=this.canvas.getContext("2d");if(!a)throw new Error("2D canvas unavailable");this.ctx=a}setSelection(n,a,s){this.selection=n&&a&&!(n[0]===a[0]&&n[1]===a[1])?{start:[n[0],n[1]],end:[a[0],a[1]],columnSelectMode:s}:null}paint({dims:n,rows:a,cols:s,ydisp:r,colors:c,focused:f,dpr:m,cursorWidth:p,caret:g}){var S;const y=this.ctx;if(y.clearRect(0,0,this.canvas.width,this.canvas.height),!n.cell.width||!a)return;const{selection:v,link:w}=this,x=(T,A,k,E)=>y.fillRect(T*n.cell.width,A*n.cell.height,k*n.cell.width,E*n.cell.height);if(v){const T=v.start[1]-r,A=v.end[1]-r,k=Math.max(T,0),E=Math.min(A,a-1);if(k<a&&E>=0)if(y.fillStyle=(f?c.selectionBackgroundTransparent:c.selectionInactiveBackgroundTransparent).css,v.columnSelectMode)x(v.start[0],k,v.end[0]-v.start[0],E-k+1);else{const N=T===k?v.start[0]:0,B=k===A?v.end[0]:s;x(N,k,B-N,1),x(0,k+1,s,Math.max(E-k-1,0)),k!==E&&x(0,E,A===E?v.end[0]:s,1)}}if(w){y.fillStyle=w.fg===257?c.background.css:w.fg!==void 0&&w.fg<256?((S=c.ansi[w.fg])==null?void 0:S.css)??c.foreground.css:c.foreground.css;const T=(A,k,E)=>y.fillRect(A*n.cell.width,(k+1)*n.cell.height-m-1,E*n.cell.width,m);if(w.y1===w.y2)T(w.x1,w.y1,w.x2-w.x1);else{T(w.x1,w.y1,w.cols-w.x1);for(let A=w.y1+1;A<w.y2;A++)T(0,A,w.cols);T(0,w.y2,w.x2)}}if(g){const T=Math.round(g.x*n.cell.width),A=g.y*n.cell.height;g.shape===Zn.BLOCK?(y.fillStyle=g.css,y.fillRect(T,A,n.cell.width,n.cell.height)):Xy(y,n,T,A,n.cell.width,g.shape,{css:g.css,dpr:m,cursorWidth:p})}}}class kM{constructor(n,a){$(this,"text");$(this,"textContext");$(this,"decor");this.screen=a,this.text=n.createElement("canvas"),this.text.classList.add("xterm-text-layer"),this.text.style.zIndex="0";const s=this.text.getContext("2d",{alpha:!1});if(!s)throw new Error("2D canvas unavailable");this.textContext=s,this.decor=new EM(n),a.appendChild(this.text),a.appendChild(this.decor.canvas)}size(n){for(const a of[this.text,this.decor.canvas])a.width=n.device.canvas.width,a.height=n.device.canvas.height,a.style.width=`${n.css.canvas.width}px`,a.style.height=`${n.css.canvas.height}px`;this.screen.style.width=`${n.css.canvas.width}px`,this.screen.style.height=`${n.css.canvas.height}px`}watchDevicePixels(n,a,s,r){return TM(n,this.text,(c,f)=>{const m=a.css.canvas;if(!(Math.abs(c-m.width*s())>2||Math.abs(f-m.height*s())>2)){a.device.canvas.width=c,a.device.canvas.height=f;for(const p of[this.text,this.decor.canvas])p.width=c,p.height=f;r()}})}remove(){this.text.remove(),this.decor.canvas.remove()}}function NM(l,n){const a=l.fonts;return!a||typeof a.addEventListener!="function"?null:(a.addEventListener("loadingdone",n),{dispose:()=>a.removeEventListener("loadingdone",n)})}class _M{constructor(n,a,s){$(this,"startedAt",null);$(this,"held",null);$(this,"timer",null);this.now=n,this.maxHoldMs=a,this.onExpire=s}get pending(){return this.held}hold(n,a){const s=this.now();return this.startedAt===null&&(this.startedAt=s),s-this.startedAt>=this.maxHoldMs?!1:(this.held=this.held?{start:Math.min(this.held.start,n),end:Math.max(this.held.end,a)}:{start:n,end:a},this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.onExpire()},this.maxHoldMs)),!0)}release(n,a){return this.held&&(n=Math.min(n,this.held.start),a=Math.max(a,this.held.end)),this.held=null,this.startedAt=null,this.timer&&(clearTimeout(this.timer),this.timer=null),{start:n,end:a}}dispose(){this.timer&&clearTimeout(this.timer)}}const LM=150;class Zd{constructor(n,a){$(this,"dimensions",SM());$(this,"redraw",new ZC);$(this,"onRequestRedraw",this.redraw.event);$(this,"stats",{frames:0,heldFrames:0,lastPaintMs:0,lastCells:0,lastInputToPaintMs:null});$(this,"surface");$(this,"cells");$(this,"disposables",[]);$(this,"now");$(this,"syncHold");$(this,"cols",0);$(this,"rows",0);$(this,"overlayProvider",null);$(this,"typingZoneProvider",null);$(this,"reducedMotion");$(this,"paintedOverlayRows",new Set);$(this,"paintedCursorRow",-1);$(this,"lastYdisp",0);$(this,"inputAt",null);$(this,"blink",new XT(()=>this.requestCursorRow()));$(this,"glide",new WT);$(this,"slidingCaret",null);$(this,"disposed",!1);$(this,"isSynchronizing");$(this,"dprUsed",0);var f,m;this.core=n,this.now=a.now??(()=>performance.now()),this.syncHold=new _M(this.now,a.maxSyncHoldMs??LM,()=>this.flushHeld()),this.isSynchronizing=a.isSynchronizing??(()=>!1),this.reducedMotion=(m=(f=n._coreBrowserService.window).matchMedia)==null?void 0:m.call(f,"(prefers-reduced-motion: reduce)");const s=n._coreBrowserService.mainDocument;this.surface=new kM(s,n.screenElement),this.cells=new wM(this.surface.textContext,s,n,this.dimensions),this.disposables.push(n._themeService.onChangeColors(()=>{this.cells.atlas.clear(),this.invalidateAll(),this.redrawDecor()}),n.optionsService.onOptionChange(p=>{(p==="cursorBlink"||p==="cursorStyle")&&this.restartBlink()})),n.linkifier&&this.disposables.push(n.linkifier.onShowLinkUnderline(p=>{this.surface.decor.link=p,this.redrawDecor()}),n.linkifier.onHideLinkUnderline(()=>{this.surface.decor.link=null,this.redrawDecor()}));const r=this.surface.watchDevicePixels(n._coreBrowserService.window,this.dimensions,()=>n._coreBrowserService.dpr,()=>{this.invalidateAll(),this.cells.fillBackground(),this.redrawDecor(),this.redraw.fire({start:0,end:Math.max(0,this.rows-1)})});r&&this.disposables.push(r);const c=NM(s,()=>this.clearTextureAtlas());c&&this.disposables.push(c),this.restartBlink()}static install(n,a={}){const s=zy(n);if(!s)return null;const r=new Zd(s,a);return s._renderService.setRenderer(r),s._renderService.handleResize(s._bufferService.cols,s._bufferService.rows),r}setOverlayProvider(n){this.overlayProvider=n,this.invalidateOverlay()}setTypingZoneProvider(n){this.typingZoneProvider=n}invalidateOverlay(){var s;const n=((s=this.overlayProvider)==null?void 0:s.call(this))??null,a=new Set(this.paintedOverlayRows);for(const r of MM(n))a.add(r);this.paintedCursorRow>=0&&a.add(this.paintedCursorRow+this.buffer().ydisp),this.requestAbsoluteRows(a)}markInput(){this.inputAt=this.now()}flushHeld(){const n=this.syncHold.pending;n&&this.redraw.fire({start:n.start,end:n.end})}handleDevicePixelRatioChange(){this.dimensions.device.cell.width&&this.dprUsed!==this.core._coreBrowserService.dpr&&this.handleResize(this.core._bufferService.cols,this.core._bufferService.rows)}handleResize(n,a){CM(this.dimensions,this.core,n,a)&&(this.dprUsed=this.core._coreBrowserService.dpr),this.surface.size(this.dimensions),this.cols=n,this.rows=a,this.cells.resize(n,a),this.paintedOverlayRows.clear(),this.paintedCursorRow=-1,this.cells.configureAtlas(),this.cells.fillBackground(),this.redrawDecor()}handleCharSizeChanged(){this.handleResize(this.core._bufferService.cols,this.core._bufferService.rows)}handleBlur(){this.blink.stop(),this.requestCursorRow(),this.redrawDecor()}handleFocus(){this.restartBlink(),this.requestCursorRow(),this.redrawDecor()}handleSelectionChanged(n,a,s){this.surface.decor.setSelection(n,a,s),this.redrawDecor()}handleCursorMove(){this.blink.running&&this.restartBlink()}clear(){this.invalidateAll(),this.cells.fillBackground()}clearTextureAtlas(){this.cells.atlas.clear(),this.invalidateAll(),this.redraw.fire({start:0,end:Math.max(0,this.rows-1)})}renderRows(n,a){if(this.disposed||!this.cols||!this.rows||!this.dimensions.device.cell.width)return;if(this.isSynchronizing()&&this.syncHold.hold(n,a)){this.stats.heldFrames++;return}const s=this.syncHold.release(n,a);this.paint(Math.max(0,s.start),Math.min(this.rows-1,s.end))}dispose(){if(!this.disposed){this.disposed=!0,this.blink.stop(),this.syncHold.dispose();for(const n of this.disposables)n.dispose();this.disposables.length=0,this.redraw.dispose(),this.cells.atlas.dispose(),this.surface.remove()}}uninstall(){const n=this.core._createRenderer;typeof n=="function"&&(this.core._renderService.setRenderer(n.call(this.core)),this.core._renderService.handleResize(this.core._bufferService.cols,this.core._bufferService.rows)),this.dispose()}get textCanvas(){return this.surface.text}hasPaintedInk(n,a){return this.cells.hasPaintedInk(n,a)}paint(n,a){var k,E,N;const s=this.now(),r=this.buffer(),c=r.ydisp;c!==this.lastYdisp&&(this.lastYdisp=c,this.cells.fades.clear(),this.redrawDecor());const f=(k=this.reducedMotion)!=null&&k.matches?null:((E=this.typingZoneProvider)==null?void 0:E.call(this))??null,m=f?f.row-c:-1,p=((N=this.overlayProvider)==null?void 0:N.call(this))??null,g=AM(p),y=this.cursorState(p),v=QT(y,p,c,this.colors()),w=this.glide.update(v,m,s),x=w?null:y,S=w&&(v==null?void 0:v.plain);S&&g.set(S.row,[...g.get(S.row)??[],S]);const T=new Set;for(let B=n;B<=a;B++)T.add(B);for(const B of this.paintedOverlayRows)ms(T,B-c,this.rows);for(const B of g.keys())ms(T,B-c,this.rows);this.paintedCursorRow>=0&&ms(T,this.paintedCursorRow,this.rows),x&&ms(T,x.y,this.rows);for(const B of this.cells.fades.rows(this.cols))ms(T,B,this.rows);let A=0;for(const B of T){this.cells.loadRow(r.lines.get(c+B),g.get(B+c));const L=B===m?{start:f.startCol,end:f.endCol}:null;A+=this.cells.paintRow(B,x,L,s)}this.cells.fades.size>0&&this.requestAbsoluteRows([...this.cells.fades.rows(this.cols)].map(B=>B+c)),(w||this.slidingCaret)&&(this.slidingCaret=w,this.redrawDecor(),w&&this.requestAbsoluteRows([w.y+c])),this.paintedOverlayRows=new Set(g.keys()),this.paintedCursorRow=x?x.y:-1,this.stats.frames++,this.stats.lastCells=A,this.stats.lastPaintMs=this.now()-s,this.inputAt!==null&&A>0&&(this.stats.lastInputToPaintMs=this.now()-this.inputAt,this.inputAt=null)}cursorState(n){return qT(this.core,this.buffer(),n,{rows:this.rows,cols:this.cols},this.blink.hidden)}restartBlink(){if(this.blink.stop(),this.disposed||!this.core.optionsService.rawOptions.cursorBlink||!this.core._coreBrowserService.isFocused){this.requestCursorRow();return}this.blink.start(),this.requestCursorRow()}requestCursorRow(){if(!this.rows)return;const n=this.buffer(),a=new Set;a.add(n.ybase+n.y),this.paintedCursorRow>=0&&a.add(this.paintedCursorRow+n.ydisp),this.requestAbsoluteRows(a)}redrawDecor(){this.surface.decor.paint({dims:this.dimensions.device,rows:this.rows,cols:this.cols,ydisp:this.buffer().ydisp,colors:this.colors(),focused:this.core._coreBrowserService.isFocused,dpr:this.core._coreBrowserService.dpr,cursorWidth:this.core.optionsService.rawOptions.cursorWidth,caret:this.slidingCaret})}invalidateAll(){this.cells.invalidate(),this.paintedCursorRow=-1}buffer(){return this.core._bufferService.buffer}colors(){return this.core._themeService.colors}requestAbsoluteRows(n){if(!this.rows)return;const a=this.buffer().ydisp;let s=1/0,r=-1/0;for(const c of n){const f=c-a;f<0||f>=this.rows||(s=Math.min(s,f),r=Math.max(r,f))}s<=r&&this.redraw.fire({start:s,end:r})}}function ms(l,n,a){n>=0&&n<a&&l.add(n)}const RM=30,Jy=640,e0=240,ir=1,jM=720*60*60*1e3;function t0(){const l=ws("local",At.rendererProbe);if(!l)return{v:ir,ua:{}};try{const n=JSON.parse(l);return typeof n=="object"&&n!==null&&n.v===ir&&typeof n.ua=="object"&&n.ua!==null?n:{v:ir,ua:{}}}catch{return{v:ir,ua:{}}}}function OM(l,n=Date.now()){const a=t0();a.ua[l]={failedAt:n},Li("local",At.rendererProbe,JSON.stringify(a))}function DM(l,n=Date.now()){const a=typeof navigator<"u"?navigator.userAgent:"";if(!a)return!1;const r=t0().ua[a];return!(!r||typeof r.failedAt!="number"||n-r.failedAt>jM)}function rb(l,n=Date.now()){const a=typeof navigator<"u"?navigator.userAgent:"";a&&OM(a,n)}function zM(l){if(l.length<4)return!0;const n=l[0],a=l[1],s=l[2],r=l[3];for(let c=4;c<l.length;c+=4)if(l[c]!==n||l[c+1]!==a||l[c+2]!==s||l[c+3]!==r)return!1;return!0}function HM(l){if(!l||l.width<=0||l.height<=0)return console.debug("Canvas probe inconclusive: text layer canvas missing or zero dimensions"),"inconclusive";let n=null;try{n=l.getContext("2d",{willReadFrequently:!0})||l.getContext("2d")}catch(r){return console.debug("Canvas probe inconclusive: failed to acquire 2D context:",r),"inconclusive"}if(!n)return console.debug("Canvas probe inconclusive: 2D context is null"),"inconclusive";const a=Math.min(l.width,Jy),s=Math.min(l.height,e0);if(a<=0||s<=0)return console.debug("Canvas probe inconclusive: calculated sample dimensions are zero"),"inconclusive";try{const r=n.getImageData(0,0,a,s);return zM(r.data)?"blank":"healthy"}catch(r){return console.debug("Canvas probe inconclusive: getImageData threw exception:",r),"inconclusive"}}function cb(l=2){return new Promise(n=>{if(typeof requestAnimationFrame!="function"){setTimeout(n,32);return}let a=l;const s=()=>{a--,a<=0?n():requestAnimationFrame(s)};requestAnimationFrame(s)})}const ad={kind:"dom",canvas:null,dispose:()=>{},verify:async()=>{}};function BM(l,n={}){if(DM())return ad;let a;try{a=Zd.install(l,{isSynchronizing:n.isSynchronizing})}catch(m){return console.debug("Canvas renderer unavailable, using the DOM renderer:",m),rb(),ad}if(!a)return ad;let s=a,r=null;const c=()=>{var p;if(!s)return;rb();const m=s;s=null;try{m.uninstall()}catch{}(p=n.onRendererSwapped)==null||p.call(n,"dom")};return{get kind(){return s?"canvas":"dom"},get canvas(){return s},dispose:()=>{const m=s;s=null;try{m==null||m.dispose()}catch{}},verify:async()=>{if(s)return r||(r=(async()=>{try{const m=s.stats.frames;await cb(2);for(let g=0;g<RM&&s&&s.stats.frames===m;g++)await cb(1);if(!s)return;const p=HM(s.textCanvas);p==="blank"&&s.hasPaintedInk(Jy,e0)?c():p==="blank"?console.debug("Canvas probe inconclusive: uniform, but no character was painted there"):p==="inconclusive"&&console.debug("Canvas probe inconclusive; retaining canvas renderer without blacklisting")}catch(m){console.debug("Canvas probe inconclusive: unexpected error during verify():",m)}finally{r=null}})(),r)}}}function UM(l,n,a){l.writeln(" ___ ___ .___ "),l.writeln(` / | \\ ____ _______| _/______ \x1B[1m${n}\x1B[0m`),l.writeln(`/ ~ \\/ __ \\\\_ __ \\ __/ ___/ \x1B[2m${a}\x1B[0m`),l.writeln("\\ Y / ___/ | | \\/|_ \\___ \\ "),l.writeln(" \\___|_ / \\___ >|__| /___/____ >"),l.writeln(" \\/ \\/ \\/ "),l.writeln("")}var KM=jx(),sd={exports:{}},ub;function IM(){return ub||(ub=1,(function(l,n){(function(a,s){l.exports=s()})(self,(()=>(()=>{var a={6:(f,m)=>{function p(y){try{const v=new URL(y),w=v.password&&v.username?`${v.protocol}//${v.username}:${v.password}@${v.host}`:v.username?`${v.protocol}//${v.username}@${v.host}`:`${v.protocol}//${v.host}`;return y.toLocaleLowerCase().startsWith(w.toLocaleLowerCase())}catch{return!1}}Object.defineProperty(m,"__esModule",{value:!0}),m.LinkComputer=m.WebLinkProvider=void 0,m.WebLinkProvider=class{constructor(y,v,w,x={}){this._terminal=y,this._regex=v,this._handler=w,this._options=x}provideLinks(y,v){const w=g.computeLink(y,this._regex,this._terminal,this._handler);v(this._addCallbacks(w))}_addCallbacks(y){return y.map((v=>(v.leave=this._options.leave,v.hover=(w,x)=>{if(this._options.hover){const{range:S}=v;this._options.hover(w,x,S)}},v)))}};class g{static computeLink(v,w,x,S){const T=new RegExp(w.source,(w.flags||"")+"g"),[A,k]=g._getWindowedLineStrings(v-1,x),E=A.join("");let N;const B=[];for(;N=T.exec(E);){const L=N[0];if(!p(L))continue;const[D,R]=g._mapStrIdx(x,k,0,N.index),[z,K]=g._mapStrIdx(x,D,R,L.length);if(D===-1||R===-1||z===-1||K===-1)continue;const V={start:{x:R+1,y:D+1},end:{x:K,y:z+1}};B.push({range:V,text:L,activate:S})}return B}static _getWindowedLineStrings(v,w){let x,S=v,T=v,A=0,k="";const E=[];if(x=w.buffer.active.getLine(v)){const N=x.translateToString(!0);if(x.isWrapped&&N[0]!==" "){for(A=0;(x=w.buffer.active.getLine(--S))&&A<2048&&(k=x.translateToString(!0),A+=k.length,E.push(k),x.isWrapped&&k.indexOf(" ")===-1););E.reverse()}for(E.push(N),A=0;(x=w.buffer.active.getLine(++T))&&x.isWrapped&&A<2048&&(k=x.translateToString(!0),A+=k.length,E.push(k),k.indexOf(" ")===-1););}return[E,S]}static _mapStrIdx(v,w,x,S){const T=v.buffer.active,A=T.getNullCell();let k=x;for(;S;){const E=T.getLine(w);if(!E)return[-1,-1];for(let N=k;N<E.length;++N){E.getCell(N,A);const B=A.getChars();if(A.getWidth()&&(S-=B.length||1,N===E.length-1&&B==="")){const L=T.getLine(w+1);L&&L.isWrapped&&(L.getCell(0,A),A.getWidth()===2&&(S+=1))}if(S<0)return[w,N]}w++,k=0}return[w,k]}}m.LinkComputer=g}},s={};function r(f){var m=s[f];if(m!==void 0)return m.exports;var p=s[f]={exports:{}};return a[f](p,p.exports,r),p.exports}var c={};return(()=>{var f=c;Object.defineProperty(f,"__esModule",{value:!0}),f.WebLinksAddon=void 0;const m=r(6),p=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function g(y,v){const w=window.open();if(w){try{w.opener=null}catch{}w.location.href=v}else console.warn("Opening link blocked as opener could not be cleared")}f.WebLinksAddon=class{constructor(y=g,v={}){this._handler=y,this._options=v}activate(y){this._terminal=y;const v=this._options,w=v.urlRegex||p;this._linkProvider=this._terminal.registerLinkProvider(new m.WebLinkProvider(this._terminal,w,this._handler,v))}dispose(){var y;(y=this._linkProvider)==null||y.dispose()}}})(),c})()))})(sd)),sd.exports}var FM=IM(),GM=Ox();function YM({fontSize:l,fontFamily:n,theme:a,cols:s,rows:r}){const c=new GM.Terminal({fontSize:l,fontFamily:n,lineHeight:1.15,...a?{theme:{...a}}:{},allowProposedApi:!0,convertEol:!0,scrollback:5e3,cols:s,rows:r,screenReaderMode:!1,linkHandler:{activate:(f,m)=>{Ed(m)}}});try{const f=new KM.Unicode11Addon;c.loadAddon(f),c.unicode.activeVersion="11"}catch(f){console.debug("Unicode11 addon unavailable, using default width table:",f)}try{c.loadAddon(new FM.WebLinksAddon((f,m)=>{Ed(m)}))}catch(f){console.debug("WebLinks addon unavailable, URLs stay plain text:",f)}return c}function ps(l){var n,a;if(!l)return!1;try{const s=l.modes;if(s&&typeof s.mouseTrackingMode=="string"&&s.mouseTrackingMode!=="none")return!0;const r=l._core;if((n=r==null?void 0:r._coreMouseService)!=null&&n.areMouseEventsActive||(a=r==null?void 0:r.coreMouseService)!=null&&a.areMouseEventsActive||r!=null&&r.mouseMode&&r.mouseMode!=="none")return!0}catch{}return!1}function PM(l,n){const a=n.button??0,s=n.buttons??(l==="mouseup"?0:1);return new MouseEvent(l,{bubbles:!0,cancelable:!0,clientX:n.clientX,clientY:n.clientY,screenX:n.clientX,screenY:n.clientY,button:a,buttons:s})}function n0(l,n,a){const s=PM(n,a);return l.dispatchEvent(s)}function i0(l){var n;try{return((n=l.buffer)==null?void 0:n.active)||null}catch{return null}}function od(l){var a;const n=(a=i0(l))==null?void 0:a.viewportY;return typeof n=="number"&&Number.isFinite(n)?n:null}function $M(l){var n;try{(n=l.blur)==null||n.call(l)}catch{}}function db(l){var a,s;const n=l;return n.coreMouseService||((a=n._core)==null?void 0:a.coreMouseService)||((s=n._core)==null?void 0:s._coreMouseService)||null}function VM(l){var a;const n=l;return n.coreService||((a=n._core)==null?void 0:a.coreService)||null}class qM{constructor(n){this.options=n}getLogicalCoordinates(n,a){const s=this.options.getScale?this.options.getScale():1,r=this.options.getSurfaceElement?this.options.getSurfaceElement():null;if(s!==1&&r&&typeof r.getBoundingClientRect=="function"){const c=r.getBoundingClientRect();return qy(n,a,c,s)}return{clientX:n,clientY:a}}getViewportElement(n){var r;const a=this.options.getSurfaceElement?this.options.getSurfaceElement():null;return(a==null?void 0:a.querySelector(".xterm-viewport"))||((r=n.element)==null?void 0:r.querySelector(".xterm-viewport"))||null}isInputLineHit(n,a){var E;const s=(E=a.buffer)==null?void 0:E.active,r=this.options.getSurfaceElement?this.options.getSurfaceElement():null,c=(r==null?void 0:r.querySelector(".xterm-screen"))||a.element||r,f=rl(a);if(!c||typeof c.getBoundingClientRect!="function"||f.cellHeight<=0)return!1;const m=c.getBoundingClientRect(),p=this.getLogicalCoordinates(n.clientX,n.clientY),g=m.width>0&&m.height>0;if(![s==null?void 0:s.cursorY,s==null?void 0:s.viewportY,s==null?void 0:s.baseY].every(N=>typeof N=="number"&&Number.isFinite(N)))return!1;const v=s==null?void 0:s.cursorY,w=s==null?void 0:s.viewportY,S=(s==null?void 0:s.baseY)+v-w,T=m.top+S*f.cellHeight,A=T+f.cellHeight,k=Number(a.rows);return S>=0&&(!Number.isFinite(k)||S<k)&&p.clientY>=T-2&&p.clientY<=A+2&&(!g||p.clientX>=m.left&&p.clientX<=m.right)}resolveDispatchTarget(n,a){var m;const s=this.options.getSurfaceElement?this.options.getSurfaceElement():null,r=(s==null?void 0:s.querySelector(".xterm-screen"))||a.querySelector(".xterm-screen")||null,c=((m=r==null?void 0:r.closest)==null?void 0:m.call(r,".xterm"))||null;let f=null;return typeof document<"u"&&typeof document.elementFromPoint=="function"&&(f=document.elementFromPoint(n.clientX,n.clientY)),f&&c&&(f===c||c.contains(f))?f:r||s||a}getMouseReport(n,a){const s=this.options.getSurfaceElement?this.options.getSurfaceElement():null,r=(s==null?void 0:s.querySelector(".xterm-screen"))||a.element;if(!r||typeof r.getBoundingClientRect!="function")return null;const c=r.getBoundingClientRect(),f=this.getLogicalCoordinates(n.clientX,n.clientY),m=rl(a);if(m.cellWidth<=0||m.cellHeight<=0)return null;const p=Math.max(1,c.width||a.cols*m.cellWidth),g=Math.max(1,c.height||a.rows*m.cellHeight),y=Math.max(0,Math.min(p-1,f.clientX-c.left)),v=Math.max(0,Math.min(g-1,f.clientY-c.top)),w=Math.max(0,Math.min(a.cols-1,Math.floor(y/m.cellWidth))),x=Math.max(0,Math.min(a.rows-1,Math.floor(v/m.cellHeight)));return{col:w,row:x,x:Math.floor(y),y:Math.floor(v),button:0,action:0}}getWheelDispatchTarget(n){const a=this.options.getSurfaceElement?this.options.getSurfaceElement():null;return(a==null?void 0:a.querySelector(".xterm"))||n.element||null}dispatchWheel(n,a,s,r){const c=this.getWheelDispatchTarget(s);if(!c||typeof WheelEvent>"u"||a===0)return!1;const f=this.getLogicalCoordinates(n.clientX,n.clientY),m=a<0?-1:1;let p=0;for(let g=0;g<Math.abs(a);g+=1)try{const y=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,clientX:f.clientX,clientY:f.clientY,deltaX:0,deltaY:m,deltaMode:1,ctrlKey:!!(r!=null&&r.ctrlKey),altKey:!!(r!=null&&r.altKey),shiftKey:!!(r!=null&&r.shiftKey)});c.dispatchEvent(y),p+=1}catch{return p>0}return p>0}emitWheel(n,a,s,r){if(a===0)return!1;if(this.dispatchWheel(n,a,s,r))return!0;const c=db(s);if(!(c!=null&&c.triggerMouseEvent))return!1;let f=0;for(let m=0;m<Math.abs(a);m+=1){const p=this.getMouseReport(n,s);p&&(p.button=4,p.action=a<0?0:1,p.ctrl=!!(r!=null&&r.ctrlKey),p.alt=!!(r!=null&&r.altKey),p.shift=!!(r!=null&&r.shiftKey),c.triggerMouseEvent(p)&&(f+=1))}return f>0}scrollAlternateBuffer(n,a,s,r){var f;if(a===0)return"none";const c=ps(s);if(!c&&!this.options.getIsController())return"none";if(this.emitWheel(n,a,s,r))return c?"application-mouse":"application-keys";if(!c){const m=VM(s);if(!(m!=null&&m.triggerDataEvent))return"none";const g=`\x1B${!!((f=m.decPrivateModes)!=null&&f.applicationCursorKeys)?"O":"["}${a<0?"A":"B"}`;return m.triggerDataEvent(g.repeat(Math.abs(a)),!0),"application-keys"}return"none"}emitMouse(n,a,s,r){const c=this.options.getTerminal();if(!c)return;const f=db(c);if(f!=null&&f.triggerMouseEvent){const p=this.getMouseReport(a,c);p&&(p.action=n==="mousedown"?1:n==="mouseup"?0:32,p.ctrl=!!(s!=null&&s.ctrlKey),p.alt=!!(s!=null&&s.altKey),p.shift=!!(s!=null&&s.shiftKey),f.triggerMouseEvent(p));return}if(this.options.allowSyntheticMouseFallback===!1||!r)return;const m=this.getLogicalCoordinates(a.clientX,a.clientY);n0(r,n,{clientX:m.clientX,clientY:m.clientY,button:0,buttons:n==="mouseup"?0:1})}}class XM{constructor(n){$(this,"options");$(this,"state","idle");$(this,"startX",0);$(this,"startY",0);$(this,"lastX",0);$(this,"lastY",0);$(this,"activeTarget",null);$(this,"longPressTimer",null);$(this,"longPressMenuTimer",null);$(this,"capturedPointerId",null);$(this,"captureElement",null);$(this,"scrollRemainderY",0);$(this,"delivery");this.options={longPressDelayMs:500,longPressMenuDelayMs:2500,dragThresholdPx:8,scrollLineHeightPx:18,...n},this.delivery=new qM(this.options)}getState(){return this.state}setGestureState(n){var a,s;this.state!==n&&(this.state=n,(s=(a=this.options).onGestureStateChange)==null||s.call(a,n))}beginGesture(n,a){this.startX=n.clientX,this.startY=n.clientY,this.lastX=n.clientX,this.lastY=n.clientY,this.setGestureState("pending"),this.scrollRemainderY=0,this.activeTarget=this.delivery.resolveDispatchTarget(n,a),this.clearLongPressTimer(),this.longPressTimer=setTimeout(()=>{var s,r;this.state==="pending"&&(this.setGestureState("longpress"),(r=(s=this.options).onLongPress)==null||r.call(s,{clientX:this.startX,clientY:this.startY}))},this.options.longPressDelayMs),this.longPressMenuTimer=setTimeout(()=>{var s,r;this.longPressMenuTimer=null,this.state==="longpress"&&((r=(s=this.options).onLongPressMenu)==null||r.call(s,{clientX:this.startX,clientY:this.startY}))},this.options.longPressMenuDelayMs)}moveGesture(n,a){var g,y,v,w;if(this.state==="idle")return;const s=n.clientX-this.startX,r=n.clientY-this.startY,c=Math.hypot(s,r);if(this.state==="longpress"){c>(this.options.dragThresholdPx||8)&&this.clearLongPressMenuTimer(),(y=(g=this.options).onSelectionExtend)==null||y.call(g,{clientX:n.clientX,clientY:n.clientY}),a!=null&&a.cancelable&&((v=a.preventDefault)==null||v.call(a));return}if(this.state==="scrolling"){this.scrollGesture(n,a);return}const f=this.options.getTerminal(),m=this.options.getIsController(),p=ps(f);if(!(c<=(this.options.dragThresholdPx||8))){if(this.clearLongPressTimer(),Math.abs(r)>=Math.abs(s)||!p||!m){this.setGestureState("scrolling"),f&&$M(f),this.lastX=n.clientX,this.lastY=this.startY,this.scrollRemainderY=0,this.scrollGesture(n,a);return}if(p&&m){this.state==="pending"&&(this.setGestureState("dragging"),this.delivery.emitMouse("mousedown",{clientX:this.startX,clientY:this.startY},a,this.activeTarget)),this.state==="dragging"&&(this.lastX=n.clientX,this.lastY=n.clientY,this.delivery.emitMouse("mousemove",n,a,this.activeTarget),a!=null&&a.cancelable&&((w=a.preventDefault)==null||w.call(a)));return}this.lastX=n.clientX,this.lastY=n.clientY}}scrollGesture(n,a){var S,T,A;const s=this.options.getTerminal();if(!s)return;const r=n.clientY-this.lastY;this.lastX=n.clientX,this.lastY=n.clientY;const c=rl(s),f=c.measured?c.cellHeight:this.options.scrollLineHeightPx||c.cellHeight||18;this.scrollRemainderY+=r;const m=Math.trunc(this.scrollRemainderY/f),p=-m;let g=!1,y="none";const v=i0(s),w=ps(s);if(p!==0){if((v==null?void 0:v.type)==="alternate")y=this.delivery.scrollAlternateBuffer(n,p,s,a),g=y!=="none";else{const k=od(s);s.scrollLines(p);const E=od(s);y="buffer",g=k===null||E===null||k!==E}this.scrollRemainderY-=m*f}const x=this.delivery.getViewportElement(s);(T=(S=this.options).onGestureScroll)==null||T.call(S,{deltaY:r,lines:p,viewportY:od(s),scrollTop:(x==null?void 0:x.scrollTop)??null,scrollHeight:(x==null?void 0:x.scrollHeight)??null,clientHeight:(x==null?void 0:x.clientHeight)??null,moved:g,bufferType:(v==null?void 0:v.type)||null,baseY:typeof(v==null?void 0:v.baseY)=="number"?v.baseY:null,cursorY:typeof(v==null?void 0:v.cursorY)=="number"?v.cursorY:null,hasScrollback:typeof(v==null?void 0:v.hasScrollback)=="boolean"?v.hasScrollback:null,mouseTracking:w,scrollMode:y}),a!=null&&a.cancelable&&((A=a.preventDefault)==null||A.call(a))}endGesture(n,a){var f,m,p;this.clearLongPressTimer();const s=this.options.getTerminal(),r=this.options.getIsController(),c=ps(s);if(this.state==="pending"){if(c&&r){const y={clientX:this.startX,clientY:this.startY};this.delivery.emitMouse("mousedown",y,a,this.activeTarget),this.delivery.emitMouse("mouseup",y,a,this.activeTarget)}const g={clientX:this.startX,clientY:this.startY};r&&s&&this.delivery.isInputLineHit(g,s)&&((m=(f=this.options).onFocus)==null||m.call(f))}else if(this.state==="dragging"&&c&&r){const g=n??{clientX:this.lastX,clientY:this.lastY};this.delivery.emitMouse("mouseup",g,a,this.activeTarget),a!=null&&a.cancelable&&((p=a.preventDefault)==null||p.call(a))}this.reset()}handlePointerDown(n,a){if(n.pointerType==="mouse")return!1;if(!n.isPrimary)return this.releasePointerCapture(),this.reset(),!1;if(n.cancelable&&n.preventDefault(),this.beginGesture(n,a),n.pointerType!=="touch")try{typeof a.setPointerCapture=="function"&&(a.setPointerCapture(n.pointerId),this.capturedPointerId=n.pointerId,this.captureElement=a)}catch{}return!0}handlePointerMove(n){n.pointerType==="mouse"||this.state==="idle"||this.moveGesture(n,n)}handlePointerUp(n){n.pointerType==="mouse"||this.state==="idle"||(this.releasePointerCapture(),this.endGesture(n,n))}handlePointerCancel(n){n&&n.pointerType==="mouse"||(this.releasePointerCapture(),this.cancelGesture())}handleTouchStart(n,a){if(n.touches.length!==1){this.reset();return}n.cancelable&&n.preventDefault(),this.beginGesture(n.touches[0],a)}handleTouchMove(n){n.touches.length===1&&this.moveGesture(n.touches[0],n)}handleTouchEnd(n){n.cancelable&&n.preventDefault(),this.endGesture(null,n)}handleTouchCancel(){this.cancelGesture()}cancelGesture(){this.clearLongPressTimer();const n=this.options.getTerminal(),a=this.options.getIsController(),s=ps(n);if(this.state==="dragging"&&s&&a&&this.activeTarget){const r=this.delivery.getLogicalCoordinates(this.lastX,this.lastY);n0(this.activeTarget,"mouseup",{clientX:r.clientX,clientY:r.clientY,button:0,buttons:0})}this.reset()}releasePointerCapture(){const n=this.captureElement,a=this.capturedPointerId;if(this.captureElement=null,this.capturedPointerId=null,!(!n||a===null))try{typeof n.releasePointerCapture=="function"&&(typeof n.hasPointerCapture!="function"||n.hasPointerCapture(a))&&n.releasePointerCapture(a)}catch{}}clearLongPressTimer(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressTimer=null),this.clearLongPressMenuTimer()}clearLongPressMenuTimer(){this.longPressMenuTimer&&(clearTimeout(this.longPressMenuTimer),this.longPressMenuTimer=null)}reset(){this.clearLongPressTimer(),this.releasePointerCapture(),this.setGestureState("idle"),this.activeTarget=null}}function ZM({container:l,term:n,isTouchDevice:a,debug:s,getTerminal:r,getIsController:c,getScale:f,getSurfaceElement:m,getSelection:p,onFocus:g}){const y=new XM({getTerminal:r,getIsController:c,getScale:f,getSurfaceElement:m,allowSyntheticMouseFallback:!1,onFocus:()=>{try{n.focus()}catch{}s==null||s(L=>({...L,focused:document.activeElement===n.textarea})),g()},onGestureStateChange:L=>{s==null||s(D=>({...D,state:L}))},onGestureScroll:({deltaY:L,lines:D,viewportY:R,scrollTop:z,scrollHeight:K,clientHeight:V,moved:te,bufferType:Z,baseY:ie,cursorY:re,hasScrollback:ce,mouseTracking:O,scrollMode:J})=>{s==null||s(I=>({...I,deltaY:L,lines:D,viewportY:R,scrollTop:z,scrollHeight:K,clientHeight:V,moved:te,focused:document.activeElement===n.textarea,bufferType:Z,baseY:ie,cursorY:re,hasScrollback:ce,mouseTracking:O,scrollMode:J,scrollCalls:I.scrollCalls+(D!==0?1:0),lastScrollLines:D}))},longPressDelayMs:500,longPressMenuDelayMs:2500,dragThresholdPx:8,scrollLineHeightPx:18,onLongPress:a?L=>p().handleLongPress(L):void 0,onLongPressMenu:a?()=>p().openMenuAtGesture():void 0,onSelectionExtend:a?L=>p().handleSelectionExtend(L):void 0}),v=typeof window<"u"&&"PointerEvent"in window,w=typeof TouchEvent<"u",x=[],S={passive:!1,capture:!0},T=(L,D)=>{document.addEventListener(L,D,S),x.push(()=>document.removeEventListener(L,D,S))},A=(L,D=!1)=>{const R=L.target;return R instanceof Node&&l.contains(R)||D&&y.getState()!=="idle"},k=(L,D)=>{s==null||s(R=>({...R,[L]:R[L]+1,lastInputEvent:D}))},E=L=>{const D=p();return D.hasOpenMenu()?(D.clearSelection(),L.cancelable&&L.preventDefault(),L.stopPropagation(),!0):!1},N=()=>{const L=p();y.getState()==="longpress"&&L.hasSelectionExtension()&&!L.hasOpenMenu()&&L.openMenuAtGesture()};if(v){if(T("pointerdown",L=>{if(!A(L)||(k("pointerEvents","pointerdown"),E(L)))return;y.handlePointerDown(L,l)&&L.stopPropagation()}),T("pointermove",L=>{A(L,!0)&&(k("pointerEvents","pointermove"),y.handlePointerMove(L),L.pointerType!=="mouse"&&L.stopPropagation())}),T("pointerup",L=>{A(L,!0)&&(k("pointerEvents","pointerup"),N(),y.handlePointerUp(L),L.pointerType!=="mouse"&&L.stopPropagation())}),T("pointercancel",L=>{A(L,!0)&&(k("pointerEvents","pointercancel"),p().clearSelection(),y.handlePointerCancel(L),L.pointerType!=="mouse"&&L.stopPropagation())}),w){const L=D=>{A(D,!0)&&(s==null||s(R=>({...R,touchEvents:R.touchEvents+1})),D.cancelable&&D.preventDefault(),D.stopPropagation())};for(const D of["touchstart","touchmove","touchend","touchcancel"])T(D,L)}}else T("touchstart",L=>{A(L)&&(k("touchEvents","touchstart"),!E(L)&&(L.touches.length===1&&L.stopPropagation(),y.handleTouchStart(L,l)))}),T("touchmove",L=>{A(L,!0)&&(k("touchEvents","touchmove"),L.touches.length===1&&L.stopPropagation(),y.handleTouchMove(L))}),T("touchend",L=>{A(L,!0)&&(k("touchEvents","touchend"),N(),L.stopPropagation(),y.handleTouchEnd(L))}),T("touchcancel",L=>{A(L,!0)&&(k("touchEvents","touchcancel"),p().clearSelection(),L.stopPropagation(),y.handleTouchCancel())});const B=L=>{L.preventDefault()};return l.addEventListener("contextmenu",B),x.push(()=>l.removeEventListener("contextmenu",B)),()=>{y.handlePointerCancel();for(const L of x)L()}}function WM(l,{requestFit:n,onPageVisible:a}){const s=new ResizeObserver(()=>{n()});s.observe(l);const r=()=>{n()},c=()=>{document.visibilityState==="visible"&&a()};window.addEventListener("resize",r),window.addEventListener("orientationchange",r),document.addEventListener("visibilitychange",c),window.addEventListener("pageshow",c);const f=()=>{n()};return typeof window<"u"&&window.visualViewport&&(window.visualViewport.addEventListener("resize",f),window.visualViewport.addEventListener("scroll",f)),()=>{s.disconnect(),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),document.removeEventListener("visibilitychange",c),window.removeEventListener("pageshow",c),typeof window<"u"&&window.visualViewport&&(window.visualViewport.removeEventListener("resize",f),window.visualViewport.removeEventListener("scroll",f))}}function tl(l){if(l)try{l.refresh(0,Math.max(0,l.rows-1))}catch{}}function QM({containerRef:l,surfaceRef:n,termRef:a,rendererRef:s,currentScaleRef:r,initialBannerWrittenRef:c,live:f,selection:m,prediction:p,fit:g,isTouchDevice:y,debug:v,terminalFontSize:w,terminalFontFamily:x,hostTheme:S,glyphRevision:T,terminalResetVersion:A,isActive:k,subscribeToOutput:E,onOutput:N,onTitle:B,onRendererKind:L}){const{requestFit:D,scheduleBoundedFit:R,fitNow:z,seedFit:K,cancelPendingFits:V}=g;M.useEffect(()=>{var tt,Je;if(!l.current||!n.current)return;const Z=l.current,ie=Rd(Z,oa(),pd()),re=rl(null,fa),ce=Vy({width:ie.width,height:ie.height,cellWidth:re.cellWidth,cellHeight:re.cellHeight});f.current.sendResize(ce.cols,ce.rows),K(ie);const O=YM({fontSize:dg(w,ie.width),fontFamily:x,theme:f.current.hostTheme,cols:ce.cols,rows:ce.rows});O.open(n.current),a.current=O;const J=O.onTitleChange(Se=>{B(Ad(Se)||null)}),{screenState:I,fieldProbe:le,overlay:P}=p.attach(O);y&&O.textarea&&(O.textarea.readOnly=!1,O.textarea.tabIndex=0,O.textarea.inputMode="text");let fe=()=>{};if(v&&O.textarea){const Se=()=>{v(Me=>({...Me,focused:document.activeElement===O.textarea}))};O.textarea.addEventListener("focus",Se),O.textarea.addEventListener("blur",Se),fe=()=>{var Me,ot;(Me=O.textarea)==null||Me.removeEventListener("focus",Se),(ot=O.textarea)==null||ot.removeEventListener("blur",Se)},Se()}const ve=async Se=>{p.discard("paste");const Me=_y(Se);if(Me){if(Se.preventDefault(),Se.stopPropagation(),!f.current.isController){f.current.warnViewerMode();return}await f.current.uploadImage(Me)}};(tt=O.textarea)==null||tt.addEventListener("paste",ve),Z.addEventListener("paste",ve);const X=BM(O,{isSynchronizing:I.isSynchronizing,onRendererSwapped:Se=>{var Me;Z.dataset.renderer=Se,L(Se),(Me=p.overlayRef.current)==null||Me.attach(null),tl(O)}});P.attach(X.canvas),(Je=X.canvas)==null||Je.setTypingZoneProvider(()=>{const Se=le.detect();return Se&&{row:Se.row,startCol:Se.startCol,endCol:Se.endCol}});const ue=I.onSyncEnd(()=>{var Se,Me;return(Me=(Se=s.current)==null?void 0:Se.canvas)==null?void 0:Me.flushHeld()});if(s.current=X,Z.dataset.renderer=X.kind,L(X.kind),UM(O,f.current.t("terminal.bannerTitle"),f.current.t("terminal.bannerSubtitle")),c.current=!0,O.write("",()=>void X.verify()),!y)try{O.focus()}catch{}const oe=typeof document<"u"?document.fonts:void 0;typeof(oe==null?void 0:oe.load)=="function"&&oe.load('13px "Symbols Nerd Font Mono"').then(()=>{a.current&&(tl(a.current),R(5))}).catch(()=>{});const pe=O.onData(Se=>{const{isController:Me}=f.current;let ot=Se;if(Me&&Iy(Se)==="keys"&&$x(Se)){const bt=f.current.consumeModifierLatch();bt&&(ot=sr(Se,bt))}const nt=zd(ot);if(!Me&&!cr(nt)){f.current.warnViewerMode();return}p.onUserInput(nt),f.current.sendBinary(nt)}),se=O.onBinary(Se=>{const Me=new Uint8Array(Se.length);for(let ot=0;ot<Se.length;ot++)Me[ot]=Se.charCodeAt(ot)&255;!f.current.isController&&!cr(Me)||f.current.sendBinary(Me)}),xe=typeof O.onWriteParsed=="function"?O.onWriteParsed(()=>{var bt;if(m.current.onTerminalContentChanged(),le.invalidate(),I.isSynchronizing())return;const Se=O.buffer.active,Me=Se.baseY+Se.cursorY,ot=Array.from({length:8},(yn,vn)=>{var Nn;return((Nn=Se.getLine(Me-7+vn))==null?void 0:Nn.translateToString(!0))??""}),nt=Yw(ot,f.current.platform);nt&&f.current.reportShellProfile(nt),(bt=p.predictorRef.current)==null||bt.onServerOutput(),p.sync()}):{dispose:()=>{}},ae=typeof O.onRender=="function"?O.onRender(Se=>{var Me;if(f.current.glyphScan){const ot=O.buffer.active.viewportY??0;let nt="";for(let bt=Se.start;bt<=Se.end;bt+=1)nt+=((Me=O.buffer.active.getLine(ot+bt))==null?void 0:Me.translateToString(!0))??"";/[^\x00-\x7f]/.test(nt)&&f.current.ensureHostGlyphs(nt)}m.current.onTerminalRender(O,Se.start,Se.end)}):{dispose:()=>{}},we=typeof O.onScroll=="function"?O.onScroll(()=>{m.current.onTerminalScroll(O),p.discard("scroll")}):{dispose:()=>{}},ke=ZM({container:Z,term:O,isTouchDevice:y,debug:v,getTerminal:()=>a.current,getIsController:()=>f.current.isController,getScale:()=>r.current,getSurfaceElement:()=>n.current,getSelection:()=>m.current,onFocus:()=>{var Se,Me;return(Me=(Se=f.current).onTerminalFocus)==null?void 0:Me.call(Se)}}),Ie=WM(Z,{requestFit:D,onPageVisible:()=>{R(10),tl(a.current)}});return()=>{var Se;pe.dispose(),se.dispose(),ae.dispose(),we.dispose(),xe.dispose(),J.dispose(),ue.dispose(),p.detach(),I.dispose(),ke(),Ie(),V(),fe(),(Se=O.textarea)==null||Se.removeEventListener("paste",ve),Z.removeEventListener("paste",ve),X.dispose(),s.current=null,O.dispose(),a.current=null}},[]),M.useEffect(()=>{const Z=a.current;if(!Z)return;const ie=Rd(l.current,oa(),pd()),re=dg(w,ie.width),ce=Z.options.fontSize!==re||Z.options.fontFamily!==x;Z.options.fontSize=re,Z.options.fontFamily=x,tl(Z),ce&&z(),R(10)},[w,x]),M.useEffect(()=>{var ie,re;const Z=a.current;!Z||!T||((re=(ie=s.current)==null?void 0:ie.canvas)==null||re.clearTextureAtlas(),tl(Z))},[T]);const te=M.useRef(A);M.useEffect(()=>{var ie;if(te.current===A)return;te.current=A,p.forget("resetVersion");const Z=a.current;if(Z)try{(ie=Z.reset)==null||ie.call(Z),Z.clear(),Z.refresh(0,Math.max(0,Z.rows-1))}catch{}},[A]),M.useEffect(()=>{const Z=a.current;!Z||!S||(Z.options.theme={...S},tl(Z))},[S]),M.useEffect(()=>E(ie=>{const re=a.current;if(!re)throw new Error("terminal not ready");re.write(ie),N==null||N(ie.byteLength)}),[E,a,N]),M.useEffect(()=>{if(!k)return;R(10);const Z=a.current;if(Z&&(tl(Z),!y))try{Z.focus()}catch{}},[k,y,R,a])}const JM=({onTerminalFocus:l,isActive:n=!0})=>{var Nn;const a=M.useRef(null),s=M.useRef(null),r=M.useRef(null),c=M.useRef(null),f=M.useRef(null),m=M.useRef(1),p=M.useRef(null),g=M.useRef(!1),y=fw(),v=y||typeof navigator<"u"&&navigator.maxTouchPoints>0||typeof window<"u"&&"ontouchstart"in window,w=yC(),[x,S]=M.useState(bC),{metrics:T,record:A}=vC(w),[k,E]=M.useState(null),{settings:N,terminalFontFamily:B,terminalFontSize:L,hostFont:D,ensureHostGlyphs:R,profiles:z,activeProfileId:K,t:V}=Ee(),{isController:te,connectionState:Z,hostPalette:ie,herdrPrefixKeys:re,terminalResetVersion:ce,agentStatus:O,platform:J,reportShellProfile:I,connect:le,rttMs:P}=it(),{addToast:fe}=dn(),{sendResize:ve,sendBinary:X,observeKeyInput:ue,consumeModifierLatch:oe,warnViewerMode:pe,subscribeToOutput:se,subscribeToPasteFileReady:xe}=Sr(),{uploadImage:ae}=Cr(),we=Jn.useMemo(()=>Sw(ie),[ie]),ke=En({isController:te,sendBinary:X,sendResize:ve,warnViewerMode:pe,uploadImage:ae,t:V,consumeModifierLatch:oe,hostTheme:we,onTerminalFocus:l,ensureHostGlyphs:R,glyphScan:D.glyphs.status==="ready",platform:J,reportShellProfile:I}),Ie=En(n),tt=kT({termRef:f,rendererRef:p,mode:N.predictiveEcho,connectionState:Z,observeKeyInput:ue,herdrPrefixKeys:re}),[Je,Se]=M.useState(null),Me=PT({termRef:f,surfaceRef:r,mainRef:c,currentScaleRef:m,addToast:fe,t:V}),ot=En(Me),nt=TC({termRef:f,isController:te,warnViewerMode:pe,uploadImage:ae,addToast:fe,t:V,onPaste:()=>tt.discard("paste"),subscribeToPasteFileReady:xe}),bt=zT({termRef:f,containerRef:a,frameRef:s,surfaceRef:r,currentScaleRef:m,rendererRef:p,initialBannerWrittenRef:g,isActiveRef:Ie,sendResize:ve,onResized:()=>tt.forget("resize")});QM({containerRef:a,surfaceRef:r,termRef:f,rendererRef:p,currentScaleRef:m,initialBannerWrittenRef:g,live:ke,selection:ot,prediction:tt,fit:bt,isTouchDevice:y,debug:w?S:null,terminalFontSize:L,terminalFontFamily:B,hostTheme:we,glyphRevision:D.glyphRevision,terminalResetVersion:ce,isActive:n,subscribeToOutput:se,onOutput:w?A:null,onTitle:Se,onRendererKind:E});const yn=Jn.useMemo(()=>{var qt;return((qt=z.find(ut=>ut.id===K))==null?void 0:qt.displayName)??null},[z,K]);M.useEffect(()=>{Z!=="connected"&&Se(null)},[Z]),M.useEffect(()=>{const qt=n&&Z==="connected",ut=N.agentAlertBadge?Ts(O):null;lC(qt?Je:null,yn,ut)},[n,Z,Je,yn,O,N.agentAlertBadge]),M.useEffect(()=>{Z==="disconnected"&&le()},[]);const vn=qt=>{qt.preventDefault()};return h.jsxs("main",{ref:c,className:"flex-1 w-full min-w-0 min-h-0 overflow-hidden relative flex flex-col",onContextMenu:vn,"aria-label":V("terminal.windowAriaLabel"),children:[h.jsx("div",{id:"terminal-container",ref:a,className:"absolute inset-0 overflow-hidden cursor-text",style:{touchAction:v?"none":"auto"},tabIndex:0,onContextMenu:vn,"aria-label":V("terminal.bufferAriaLabel"),role:"region",children:h.jsx("div",{id:"terminal-frame",ref:s,className:"relative overflow-hidden",style:{width:"100%",height:"100%"},children:h.jsx("div",{id:"terminal-surface",ref:r,className:"absolute top-0 left-0",style:{transformOrigin:"top left",width:"100%",height:"100%"}})})}),w&&h.jsx(CC,{debug:x,rttMs:P,metrics:T,rendererKind:k,predictiveEcho:N.predictiveEcho,predictor:tt.predictorRef.current,field:((Nn=tt.fieldProbeRef.current)==null?void 0:Nn.detect())??null,renderer:p.current}),y&&Me.selectionRect&&Me.isHighlightVisible&&h.jsx($T,{term:f.current,surface:r.current,main:c.current,rect:Me.selectionRect,viewportY:Me.viewportY}),y&&Me.selectionMenu&&h.jsx(gC,{anchorPoint:Me.selectionMenu,hasSelection:!!Me.selectionSnapshot,isController:te,vibrateOnKeyPress:N.vibrateOnKeyPress,linkUrl:Me.selectionMenu.link??null,onOpenLink:qt=>{Ed(qt)||fe("warning",V("clipboard.openLinkFailed"))},onCopySelection:Me.handleCopySelection,onCopyLine:Me.handleCopyLine,onCopyScreen:Me.handleCopyScreen,onPaste:nt.handlePaste,onClose:Me.clearSelection}),y&&nt.isPasteFallbackOpen&&h.jsx(pC,{isOpen:nt.isPasteFallbackOpen,onClose:nt.closePasteFallback,onSend:nt.handleFallbackPasteSend,onSendImage:nt.handleFallbackImageSend})]})},e5=2e3;function Wd(){const{t:l}=Ee(),{addToast:n}=dn(),[a,s]=M.useState(null),r=M.useRef(null);M.useEffect(()=>()=>{r.current&&clearTimeout(r.current)},[]);const c=M.useCallback((f,m,p="success")=>{qd(f).then(g=>{if(g==="failed"){n("error",l("clipboard.copyFailed"));return}s(f),n(p,m),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>s(null),e5)})},[n,l]);return{copied:a,copy:c}}const il="herdr-remote pair",fb="herdr-remote",t5=({onPairedSuccess:l})=>{const{settings:n,updateSettings:a,t:s}=Ee(),{connect:r,connectionState:c,stateDetail:f}=it(),{addToast:m}=dn(),[p,g]=M.useState(""),{copied:y,copy:v}=Wd(),[w,x]=M.useState(!1),[S,T]=M.useState(n.wsUrl||Ut),[A,k]=M.useState(n.token||""),[E,N]=M.useState(n.clientId||""),B=z=>v(z,s("toasts.commandCopied")),L=z=>{z.preventDefault();const K=p.trim().toUpperCase();if(!K&&!A.trim()){m("warning",s("toasts.connectionError"));return}const V={pairCode:K,wsUrl:S.trim()||Ut,clientId:E.trim()||n.clientId};A.trim()&&(V.token=A.trim()),a(V),r({pairCode:K||void 0,token:A.trim()||void 0,wsUrl:S.trim()||Ut,clientId:E.trim()||n.clientId}),l&&l()},D=c==="connecting"||c==="reconnecting",R=({n:z})=>h.jsxs("span",{"aria-hidden":"true",className:"shrink-0 font-bold text-tui-accent",children:["[",z,"]"]});return h.jsx("div",{className:"flex h-full w-full flex-1 justify-center overflow-y-auto bg-tui-crust p-2 sm:p-4",children:h.jsxs("div",{className:"my-auto w-full max-w-3xl space-y-3",children:[h.jsxs("div",{className:"border border-tui-border bg-tui-base px-3 py-2",children:[h.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[h.jsx("span",{"aria-hidden":"true",className:"font-bold text-tui-accent",children:"herdr-remote"}),h.jsx("h1",{className:"text-tui font-bold text-tui-text",children:s("onboarding.title")}),h.jsx("span",{className:"text-tui uppercase text-tui-warn",children:s("onboarding.firstTimeSetup")})]}),h.jsx("p",{className:"mt-0.5 text-tui leading-snug text-tui-muted",children:s("onboarding.description")})]}),c==="error"&&h.jsxs(Ri,{tone:"warn",action:h.jsx(Ae,{variant:"warn",onClick:()=>r(),children:s("common.retry")}),children:[h.jsx("span",{className:"block font-bold",children:s("onboarding.authRequired")}),h.jsx("span",{className:"block text-tui-muted",children:f||s("onboarding.authRequiredDesc")})]}),h.jsxs("form",{onSubmit:L,className:"grid gap-3",children:[h.jsx(Et,{title:s("onboarding.step1Title"),className:"min-w-0",children:h.jsxs("div",{className:"space-y-2",children:[h.jsxs("p",{className:"flex items-start gap-2 text-tui text-tui-muted",children:[h.jsx(R,{n:1}),h.jsx("span",{className:"leading-snug",children:s("onboarding.step1Desc")})]}),h.jsxs("div",{className:"flex items-center gap-2 border border-tui-border bg-tui-mantle px-2 py-1",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 select-none text-tui-ok",children:"$"}),h.jsx("code",{className:"min-w-0 flex-1 truncate text-tui text-tui-text",children:il}),h.jsx(Ae,{onClick:()=>B(il),glyph:y===il?_e.check:"⧉",className:ne("shrink-0",y===il&&"border-tui-ok text-tui-ok"),children:s(y===il?"common.copied":"common.copy")})]}),h.jsx("div",{className:"space-y-0.5 text-tui-sm",children:h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsx("span",{className:"truncate text-tui-faint",children:s("onboarding.step1TuiNote")}),h.jsx("button",{type:"button",onClick:()=>B(fb),className:"shrink-0 cursor-pointer border border-tui-border-dim px-1 text-tui-muted hover:border-tui-accent hover:text-tui-accent",title:s("common.clickToCopy"),children:h.jsx("code",{children:fb})})]})})]})}),h.jsx(Et,{title:s("onboarding.step2Title"),className:"min-w-0",children:h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(R,{n:2}),h.jsx(un,{type:"text",value:p,onChange:z=>g(z.target.value.toUpperCase()),placeholder:s("onboarding.step2Placeholder"),maxLength:12,autoFocus:!0,"aria-label":s("onboarding.step2Title"),className:"font-bold uppercase"})]}),h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:s("onboarding.step2Note")})]})}),h.jsx(Ae,{variant:"primary",type:"submit",block:!0,disabled:D,className:"py-1.5",children:D?h.jsx(ol,{label:s("onboarding.connectingAndPairing")}):s("onboarding.connectAndPair")}),h.jsxs("div",{className:"border border-tui-border bg-tui-base",children:[h.jsxs("button",{type:"button",onClick:()=>x(!w),"aria-expanded":w,className:"tui-focusable flex w-full items-center gap-2 px-2 py-1 text-left text-tui text-tui-muted transition-colors hover:text-tui-accent",children:[h.jsx("span",{"aria-hidden":"true",className:"text-tui-accent",children:w?_e.chevronDown:_e.chevronRight}),h.jsx("span",{className:"uppercase",children:s("onboarding.advancedTitle")})]}),w&&h.jsxs("div",{className:"space-y-2.5 border-t border-tui-border-dim px-2 py-2",children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"onboarding-token",children:s("onboarding.manualTokenLabel")}),h.jsx(un,{id:"onboarding-token",type:"password",value:A,onChange:z=>k(z.target.value),placeholder:s("onboarding.manualTokenPlaceholder")})]}),h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"onboarding-ws",children:s("onboarding.wsEndpointLabel")}),h.jsx(un,{id:"onboarding-ws",type:"text",value:S,onChange:z=>T(z.target.value),placeholder:s("onboarding.wsEndpointPlaceholder")})]}),h.jsx($S,{}),h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"onboarding-client-id",children:s("onboarding.clientIdLabel")}),h.jsx(un,{id:"onboarding-client-id",type:"text",value:E,onChange:z=>N(z.target.value)})]})]})]})]})]})})},ei="tui-focusable inline-flex shrink-0 select-none items-center justify-center gap-1 whitespace-nowrap border text-tui font-medium transition-colors",Ns="border-tui-border bg-tui-surface text-tui-text hover:border-tui-accent hover:text-tui-accent active:bg-tui-selection",n5="border-tui-accent bg-tui-accent text-tui-crust font-bold",i5="border-tui-ok bg-transparent text-tui-ok hover:bg-tui-ok hover:text-tui-crust font-bold",l0={default:Ns,bad:"border-tui-bad text-tui-bad hover:bg-tui-bad hover:text-tui-crust",warn:"border-tui-warn text-tui-warn hover:bg-tui-warn hover:text-tui-crust"};function l5(l){return{capHeight:l?"h-8":"h-7",keyClass:l?"h-8 min-w-[2rem] px-1.5":"h-7 min-w-[1.75rem] px-1.5",squareKeyClass:l?"h-8 w-8":"h-7 w-7",drawerToggleClass:l?"h-8 px-1.5":"h-7 px-1.5"}}const a5={left:{glyph:"󰜱",box:[0,660,34,686]},up:{glyph:"󰜷",box:[0,652,30,690]},down:{glyph:"󰜮",box:[0,652,30,690]},right:{glyph:"󰜴",box:[0,660,34,686]},enter:{glyph:"󱞦",box:[0,709,-36,756]},backspace:{glyph:"󰁮",box:[0,1e3,-15,735]},shift:{glyph:"󰘶",box:[0,832,26,694]},open:{glyph:"󰍠",box:[91,509,256,464]},close:{glyph:"󰍝",box:[91,509,256,464]},image:{glyph:"󰋩",box:[0,750,-15,735]},customize:{glyph:"󰙪",box:[0,750,-15,735]},admin:{glyph:"󰢏",box:[0,750,-99,819]}},s5={"←":"left","↑":"up","↓":"down","→":"right","⏎":"enter","⌫":"backspace","⇧":"shift"},o5=.9,r5=.86,rd=1e3;function c5([l,n,a,s]){const r=o5*rd/Math.max(n-l,s-a),c=(l+n)/2/rd,f=r5-(a+s)/2/rd;return{fontSize:`${r}em`,left:`${(.5-r*c)*100}%`,top:`${(.5-r*f)*100}%`}}function sn({name:l}){const n=a5[l];return h.jsx("span",{"aria-hidden":"true","data-key-icon":l,className:"relative inline-block size-[1em] shrink-0 overflow-visible",children:h.jsx("span",{className:"absolute leading-none",style:c5(n.box),children:n.glyph})})}function a0({text:l}){return h.jsx("span",{className:"inline-flex items-center",children:[...l].map((n,a)=>{const s=s5[n];return s?h.jsx(sn,{name:s},a):n})})}function u5({keyClass:l,squareKeyClass:n,onCustomize:a,sendCombo:s}){const{settings:r,t:c}=Ee(),{agentProfile:f,shellProfile:m}=it(),p=rw(f,r.agentKeymaps[f],m),g=v=>{let w="";try{w=na(v.combo)}catch{}const x=v.custom?v.customLabel||"":c(`agentActions.${v.labelKey}`),S=v.labelKey==="interrupt"&&v.combo.trim().toLowerCase()==="ctrl+c"?"bad":v.combo.trim().toLowerCase()==="ctrl+z"?"warn":"default";return h.jsx("button",{type:"button","data-testid":`agent-key-${v.id}`,onClick:()=>s(v.combo),className:ne(ei,l,"font-bold",l0[S]),title:`${w} ${x}`.trim(),"aria-label":`${w} ${x}`.trim(),children:h.jsx(a0,{text:w||x})},v.id)},y=[...p.agentActions,...p.genericActions];return y.length===0&&!a?null:h.jsxs("div",{"data-testid":"agent-key-actions",role:"group","aria-label":`${nl[f].name} ${c("agentKeymaps.agentGroup")}`,className:"flex shrink-0 items-center gap-1",children:[h.jsx("span",{"aria-hidden":"true",className:"mx-1 h-5 w-px shrink-0 bg-tui-border-dim"}),y.map(g),a&&h.jsx("button",{type:"button","data-testid":"agent-key-customize",onClick:a,className:ne(ei,n,"border-tui-border-dim bg-transparent text-tui-faint hover:border-tui-accent hover:text-tui-accent"),title:c("agentKeymaps.customizeBar"),"aria-label":c("agentKeymaps.customizeBar"),children:h.jsx(sn,{name:"customize"})})]})}const s0="scrollbar-none flex items-center gap-1 overflow-x-auto border-b border-tui-border-dim bg-tui-crust p-1.5";function d5({capHeight:l,onKey:n}){return h.jsx("div",{className:"grid grid-cols-6 gap-1 border-b border-tui-border-dim bg-tui-crust p-1.5 sm:grid-cols-12",children:[1,2,3,4,5,6,7,8,9,10,11,12].map(a=>{const s=`F${a}`;return h.jsxs("button",{type:"button",onClick:()=>n(de[s]),className:ne(ei,Ns,l),children:["F",a]},s)})})}const f5=[{code:de.CTRL_C,caption:"^C",title:"virtualKeyboard.ctrlCTitle",badge:"virtualKeyboard.badgeSigint",tone:"bad"},{code:de.CTRL_D,caption:"^D",title:"virtualKeyboard.ctrlDTitle",badge:"virtualKeyboard.badgeEof"},{code:de.CTRL_Z,caption:"^Z",title:"virtualKeyboard.ctrlZTitle",badge:"virtualKeyboard.badgeTstp",tone:"warn"},{code:de.CTRL_L,caption:"^L",title:"virtualKeyboard.ctrlLTitle",badge:"virtualKeyboard.badgeClear"},{code:de.CTRL_R,caption:"^R",title:"virtualKeyboard.ctrlRTitle",badge:"virtualKeyboard.badgeSearch"},{code:de.CTRL_A,caption:"^A",title:"virtualKeyboard.ctrlATitle",badge:"virtualKeyboard.badgeStart"},{code:de.CTRL_E,caption:"^E",title:"virtualKeyboard.ctrlETitle",badge:"virtualKeyboard.badgeEnd"},{code:de.CTRL_K,caption:"^K",title:"virtualKeyboard.ctrlKTitle",badge:"virtualKeyboard.badgeKill"}];function h5({capHeight:l,onKey:n}){const{t:a}=Ee();return h.jsx("div",{className:s0,children:f5.map(s=>h.jsxs("button",{type:"button",onClick:()=>n(s.code,!1),className:ne(ei,l,"gap-1.5 px-2",l0[s.tone??"default"]),title:a(s.title),children:[h.jsx("span",{className:"font-bold",children:s.caption}),h.jsx("span",{className:"text-tui-sm opacity-70",children:a(s.badge)})]},s.caption))})}const m5=["|","~","/","\\","-","_","$","&",";",":","`",'"',"'",">","<","=","#","@","{","}","[","]"];function p5({squareKeyClass:l,onKey:n}){return h.jsx("div",{className:s0,children:m5.map(a=>h.jsx("button",{type:"button",onClick:()=>n(a,!0),className:ne(ei,Ns,l,"font-bold"),children:a},a))})}const hb="image/png,image/jpeg,image/webp,image/gif,image/*";function mb({fileInputRef:l}){const{uploadImage:n}=Cr(),a=s=>{var c;const r=(c=s.target.files)==null?void 0:c[0];s.target.value="",r&&n(r)};return h.jsxs(h.Fragment,{children:[h.jsx("input",{ref:l,type:"file",accept:hb,className:"hidden","data-testid":"key-toolbar-file-input",onChange:a}),h.jsx("input",{type:"file",accept:hb,capture:"environment",className:"hidden","data-testid":"key-toolbar-camera-input",onChange:a})]})}function pb({collapsed:l}){const{uploadProgress:n}=Cr();return n.active?h.jsx("div",{"data-testid":l?"key-toolbar-progress-collapsed":"key-toolbar-progress",className:"w-full border-b border-tui-border-dim bg-tui-crust px-2 py-1",children:h.jsx(XS,{ratio:n.ratio,label:n.statusText,tone:n.phase==="completed"?"ok":n.phase==="error"?"bad":"accent","aria-label":n.statusText})}):null}function g5({fileInputRef:l,keyClass:n,squareKeyClass:a,vibrate:s}){const{t:r}=Ee(),{isController:c}=it(),{warnViewerMode:f}=Sr(),{uploadProgress:m}=Cr(),p=m.active,g=()=>{var y;if(s(),!c){f();return}p||(y=l.current)==null||y.click()};return h.jsx("button",{type:"button","data-testid":"image-upload-btn",onClick:g,disabled:p,className:ne(ei,p?n:a,p?"border-tui-border-dim bg-tui-surface opacity-60 cursor-not-allowed":Ns),title:p?m.statusText:r("virtualKeyboard.uploadImageTitle"),"aria-label":r("virtualKeyboard.uploadImage"),children:p?h.jsx("span",{children:`${m.percent}%`}):h.jsx(sn,{name:"image"})})}function b5(){const{settings:l}=Ee(),{isController:n}=it(),{sendKey:a,warnViewerMode:s,consumeModifierLatch:r}=Sr(),c=M.useRef([]);M.useEffect(()=>()=>{for(const g of c.current)clearTimeout(g);c.current=[]},[]);const f=M.useCallback(()=>{if(l.vibrateOnKeyPress&&typeof navigator<"u"&&navigator.vibrate)try{navigator.vibrate(8)}catch{}},[l.vibrateOnKeyPress]),m=M.useCallback((g,y=!0)=>{if(f(),!n){s();return}const v=r();a(y&&v?sr(g,v):g)},[n,a,s,f,r]),p=M.useCallback(g=>{if(f(),!n){s();return}let y;try{y=cn(g)}catch{return}if(r(),y.length===1){a(y[0]);return}y.forEach((v,w)=>{const x=setTimeout(()=>{c.current=c.current.filter(S=>S!==x),a(v)},w*120);c.current.push(x)})},[r,n,a,f,s]);return{vibrate:f,pressKey:m,sendCombo:p}}function y5({squareKeyClass:l}){const{platform:n,adminTerminalSupported:a,adapter:s}=it(),{t:r}=Ee();if(n!=="win32")return null;const c=a!==!1;return h.jsx("button",{type:"button","data-testid":"new-admin-terminal",onClick:()=>s==null?void 0:s.sendAdminTabOpen(),disabled:!c,className:ne(ei,l,"border-amber-500/50 bg-amber-500/10 text-amber-200 hover:border-amber-400 hover:bg-amber-500/20 disabled:cursor-not-allowed disabled:opacity-50"),title:r(c?"terminal.adminTerminalSetup":"terminal.adminTerminalUpdate"),"aria-label":r("terminal.newAdminTerminal"),children:h.jsx(sn,{name:"admin"})})}const v5=new Set(["left","up","down","right","enter"]),x5=500,w5=8,S5=({compact:l=!1,onCustomize:n})=>{const{settings:a,updateSettings:s,t:r}=Ee(),{modifierLatch:c,toggleModifierLatch:f}=Sr(),{vibrate:m,pressKey:p,sendCombo:g}=b5(),{capHeight:y,keyClass:v,squareKeyClass:w,drawerToggleClass:x}=l5(l),S=M.useRef(null),T=M.useRef(null),A=M.useRef(null),k=M.useRef(!1);M.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const[E,N]=M.useState(!1),[B,L]=M.useState(!1),[D,R]=M.useState(!1),z=M.useRef(null),[K,V]=M.useState(!1),te=M.useCallback(()=>{const X=z.current;V(!!X&&X.scrollLeft+X.clientWidth<X.scrollWidth-1)},[]);M.useEffect(te),M.useEffect(()=>{const X=z.current;if(!X||typeof ResizeObserver!="function")return;const ue=new ResizeObserver(te);return ue.observe(X),()=>ue.disconnect()},[te,a.toolbarVisible]);const Z=()=>{T.current&&clearTimeout(T.current),T.current=null},ie=(X,ue)=>{const oe=X.modifierType;X.type!=="modifier"||ue.button!==0||oe!=="ctrl"&&oe!=="alt"&&oe!=="shift"||(Z(),k.current=!1,A.current={pointerId:ue.pointerId,clientX:ue.clientX,clientY:ue.clientY,triggered:!1},T.current=setTimeout(()=>{const pe=A.current;!pe||pe.pointerId!==ue.pointerId||(pe.triggered=!0,k.current=!0,c[oe]||f(oe),m())},x5))},re=X=>{const ue=A.current;!ue||ue.pointerId!==X.pointerId||Math.hypot(X.clientX-ue.clientX,X.clientY-ue.clientY)<=w5||(Z(),ue.triggered||(A.current=null))},ce=X=>{const ue=A.current;!ue||ue.pointerId!==X.pointerId||(Z(),A.current=null,ue.triggered&&setTimeout(()=>{k.current=!1},0))},O=X=>{const ue=A.current;!ue||ue.pointerId!==X.pointerId||(Z(),A.current=null,k.current=!1)};if(!a.toolbarVisible)return h.jsxs("div",{"data-testid":"key-toolbar-collapsed",className:"z-20 flex shrink-0 flex-col border-t border-tui-border bg-tui-mantle pb-[max(env(safe-area-inset-bottom,0px),0.125rem)]",children:[h.jsx(mb,{fileInputRef:S}),h.jsx(pb,{collapsed:!0}),h.jsx("div",{className:"flex items-center justify-center px-2 py-0.5",children:h.jsxs("button",{type:"button",onClick:()=>s({toolbarVisible:!0}),className:"tui-focusable flex h-6 w-28 items-center justify-center gap-1 text-tui uppercase text-tui-faint transition-colors hover:text-tui-accent",title:r("virtualKeyboard.expandToolbar"),"aria-label":r("virtualKeyboard.expandToolbar"),"aria-expanded":!1,children:[h.jsx(sn,{name:"open"}),h.jsx("span",{"aria-hidden":"true",children:r("common.keyBar")})]})})]});const J=a.virtualKeys&&a.virtualKeys.length>0?a.virtualKeys.filter(X=>X.enabled):Wb,I=X=>X.id==="left"?h.jsx(sn,{name:"left"}):X.id==="up"?h.jsx(sn,{name:"up"}):X.id==="down"?h.jsx(sn,{name:"down"}):X.id==="right"?h.jsx(sn,{name:"right"}):X.id==="enter"?h.jsx(sn,{name:"enter"}):X.id==="drawer_chords"?h.jsx("span",{children:"^C"}):X.id==="drawer_fn"?h.jsxs(h.Fragment,{children:[h.jsx("span",{children:"Fn"}),h.jsx(sn,{name:E?"close":"open"})]}):h.jsx(a0,{text:X.label}),le=X=>{if(m(),X.type==="modifier"){X.modifierType==="ctrl"||X.modifierType==="alt"||X.modifierType==="shift"?f(X.modifierType):X.modifierType==="meta"&&p(de.ESC);return}if(X.type==="drawer"){X.drawerType==="fn"?(N(!E),L(!1),R(!1)):X.drawerType==="chords"?(R(!D),N(!1),L(!1)):X.drawerType==="symbols"&&(L(!B),N(!1),R(!1));return}p(X.code,X.type!=="chord")},P=X=>{if(X.type==="modifier"){if(X.modifierType==="ctrl")return c.ctrl;if(X.modifierType==="alt")return c.alt;if(X.modifierType==="shift")return c.shift}if(X.type==="drawer"){if(X.drawerType==="fn")return E;if(X.drawerType==="chords")return D;if(X.drawerType==="symbols")return B}return!1},fe=X=>{const ue=P(X),oe=xd(X,r);return h.jsx("button",{type:"button",onPointerDown:pe=>ie(X,pe),onPointerMove:re,onPointerUp:ce,onPointerCancel:O,onClick:()=>{if(k.current){k.current=!1;return}le(X)},className:ne(ei,v5.has(X.id)?w:X.type==="drawer"?x:v,X.id==="enter"?i5:ue?n5:Ns),title:oe,"aria-label":oe,"aria-pressed":ue,children:I(X)},X.id)},ve=J.find(X=>X.id==="enter");return h.jsxs("div",{"data-testid":"key-toolbar",className:ne("z-20 flex shrink-0 select-none flex-col border-t border-tui-border bg-tui-mantle",l?"pb-[max(env(safe-area-inset-bottom,0px),0.125rem)]":"pb-[max(env(safe-area-inset-bottom,0px),0.25rem)]"),role:"toolbar","aria-label":r("virtualKeyboard.touchKeyboardShortcuts"),children:[h.jsx(mb,{fileInputRef:S}),h.jsx(pb,{collapsed:!1}),E&&h.jsx(d5,{capHeight:y,onKey:p}),D&&h.jsx(h5,{capHeight:y,onKey:p}),B&&h.jsx(p5,{squareKeyClass:w,onKey:p}),h.jsxs("div",{"data-testid":"key-toolbar-row",className:ne("flex flex-nowrap items-center justify-start gap-1",l?"px-1.5 py-1":"px-2 py-1.5"),children:[h.jsxs("div",{className:"relative min-w-0",children:[h.jsxs("div",{ref:z,"data-testid":"key-toolbar-scroll",onScroll:te,className:"scrollbar-none flex flex-nowrap touch-pan-x items-center gap-1 overflow-x-auto overscroll-x-contain",children:[h.jsx("button",{type:"button",onClick:()=>s({toolbarVisible:!1}),className:ne(ei,w,"mr-1 border-tui-border-dim bg-transparent text-tui-faint hover:border-tui-border hover:text-tui-text"),title:r("virtualKeyboard.collapseToolbar"),"aria-label":r("virtualKeyboard.collapseToolbar"),"aria-expanded":!0,children:h.jsx(sn,{name:"close"})}),J.filter(X=>X.id!=="enter").map(fe),h.jsx(y5,{squareKeyClass:w}),h.jsx(u5,{keyClass:v,squareKeyClass:w,onCustomize:n,sendCombo:g}),h.jsx(g5,{fileInputRef:S,keyClass:v,squareKeyClass:w,vibrate:m})]}),K&&h.jsx("span",{"aria-hidden":"true","data-testid":"key-toolbar-more",className:"pointer-events-none absolute inset-y-0 right-0 w-4 bg-gradient-to-l from-tui-mantle"})]}),ve&&fe(ve)]})]})},C5=({hint:l,children:n})=>{const{t:a}=Ee(),[s,r]=M.useState(!1);return h.jsxs("div",{className:"border border-tui-border-dim",children:[h.jsxs("button",{type:"button",onClick:()=>r(!s),"aria-expanded":s,className:"tui-focusable flex w-full items-center gap-2 px-2 py-1 text-left text-tui text-tui-muted transition-colors hover:text-tui-accent",children:[h.jsx("span",{"aria-hidden":"true",className:"text-tui-accent",children:s?_e.chevronDown:_e.chevronRight}),h.jsx("span",{children:a("pairing.advancedTitle")}),h.jsx("span",{className:"min-w-0 truncate text-tui-sm text-tui-faint",children:l})]}),s&&h.jsx("div",{className:"space-y-2.5 border-t border-tui-border-dim px-2 py-2",children:n})]})},T5=({isOpen:l,onClose:n})=>{const{t:a,addProfileAndConnect:s}=Ee(),{addToast:r}=dn(),[c,f]=M.useState(""),[m,p]=M.useState(Ut),[g,y]=M.useState("");M.useEffect(()=>{l&&(f(""),p(Ut),y(""))},[l]);const v=w=>{w.preventDefault();const x=c.trim().toUpperCase();if(!x&&!g.trim()){r("warning",a("pairing.credentialsRequired"));return}s({wsUrl:m.trim()||Ut,pairCode:x,token:g.trim()}),n()};return h.jsx(ma,{isOpen:l,onClose:n,title:a("pairing.addTitle"),subtitle:a("pairing.addSubtitle"),closeLabel:a("common.closeDialog"),size:"sm",hints:[{keys:"esc",action:a("common.close")},{keys:"⏎",action:a("pairing.pairAndConnect")}],footer:h.jsx(Ae,{variant:"primary",type:"submit",form:"add-host-form",children:a("pairing.pairAndConnect")}),children:h.jsxs("form",{id:"add-host-form",onSubmit:v,className:"space-y-3",children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"add-host-code",hint:a("pairing.pairCodeNote"),children:a("pairing.pairCodeLabel")}),h.jsx(un,{id:"add-host-code",type:"text",value:c,onChange:w=>f(w.target.value.toUpperCase()),placeholder:a("pairing.pairCodePlaceholder"),maxLength:12,autoComplete:"off",autoFocus:!0,className:"font-bold uppercase"}),h.jsx("p",{className:"text-tui-sm text-tui-faint",children:a("pairing.pairCodeHelp")})]}),h.jsxs(C5,{hint:a("pairing.advancedHint"),children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"add-host-ws",children:a("pairing.wsUrlLabel")}),h.jsx(un,{id:"add-host-ws",type:"text",value:m,onChange:w=>p(w.target.value),placeholder:a("onboarding.wsEndpointPlaceholder")})]}),h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"add-host-token",hint:a("pairing.tokenNote"),children:a("pairing.tokenLabel")}),h.jsx(un,{id:"add-host-token",type:"password",value:g,onChange:w=>y(w.target.value),placeholder:a("onboarding.manualTokenPlaceholder")})]})]})]})})},_i=ne(Mr,"py-0"),M5="h-7 py-0",jd="h-7 py-0 px-1.5",xr="text-tui-bad hover:border-tui-bad hover:text-tui-bad",A5=["grid items-center gap-x-2 gap-y-1 py-1","grid-cols-[4rem_minmax(0,1fr)_9rem] [grid-template-areas:'cap_label_actions'_'combo_combo_default']","sm:grid-cols-[4rem_minmax(0,1fr)_9rem_9rem_7rem] sm:[grid-template-areas:'cap_label_combo_default_actions']"].join(" ");function o0(l){return{offLabel:l("settings.toggleOff"),onLabel:l("settings.toggleOn")}}const E5=["ctrl","alt","shift"],k5=[[..."1234567890"].map(l=>({token:l,label:l})),[..."qwertyuiop"].map(l=>({token:l,label:l.toUpperCase()})),[..."asdfghjkl"].map(l=>({token:l,label:l.toUpperCase()})),[..."zxcvbnm"].map(l=>({token:l,label:l.toUpperCase()})),["-","=","[","]","backslash",";","'",",",".","/","plus"].map(l=>({token:l,label:l==="backslash"?"\\":l==="plus"?"+":l}))],N5=[{token:"esc",label:"ESC"},{token:"tab",label:"TAB"},{token:"space",label:"SPACE"},{token:"enter",label:"ENTER"},{token:"backspace",label:"⌫"},{token:"delete",label:"DEL"},{token:"insert",label:"INS"},{token:"home",label:"HOME"},{token:"end",label:"END"},{token:"pageup",label:"PGUP"},{token:"pagedown",label:"PGDN"},{token:"left",label:"←"},{token:"up",label:"↑"},{token:"down",label:"↓"},{token:"right",label:"→"},...Array.from({length:12},(l,n)=>({token:`f${n+1}`,label:`F${n+1}`}))],cd="tui-focusable min-w-0 border border-tui-border bg-tui-mantle px-1.5 py-1 text-tui-sm font-bold text-tui-text transition-colors hover:border-tui-accent hover:text-tui-accent";function _5(l){const n=l.trim();if(!n)return[];try{return cn(n),n.split(/\s+/)}catch{return[]}}function L5({isOpen:l,value:n,onClose:a,onApply:s}){const{t:r}=Ee(),[c,f]=M.useState([]),m=M.useRef(0),[p,g]=M.useState([]);M.useEffect(()=>{l&&(m.current=0,f(_5(n).map(S=>({id:m.current++,combo:S}))),g([]))},[l,n]);const y=S=>{g(T=>T.includes(S)?T.filter(A=>A!==S):[...T,S])},v=S=>{if(c.length>=8)return;const T=[...p,S].join("+");f(A=>[...A,{id:m.current++,combo:T}]),g([])},w=c.map(S=>S.combo).join(" "),x=c.length>0&&p.length===0;return h.jsx(ma,{isOpen:l,onClose:a,title:r("agentKeymaps.comboPickerTitle"),closeLabel:r("common.closeDialog"),size:"lg",footer:h.jsxs(h.Fragment,{children:[h.jsx(Ae,{variant:"ghost",onClick:a,children:r("common.cancel")}),h.jsx(Ae,{variant:"primary",disabled:!x,onClick:()=>s(w),"data-testid":"combo-picker-apply",children:r("agentKeymaps.comboPickerApply")})]}),children:h.jsxs("div",{className:"space-y-3",children:[h.jsx("p",{className:"text-tui-sm text-tui-faint",children:r("agentKeymaps.comboPickerHint")}),h.jsxs("div",{className:"space-y-1",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsx("span",{className:"text-tui-sm text-tui-muted",children:r("agentKeymaps.comboPickerSelection")}),h.jsx(Ae,{variant:"ghost",disabled:c.length===0&&p.length===0,onClick:()=>{f([]),g([])},children:r("agentKeymaps.comboPickerClear")})]}),h.jsxs("div",{"data-testid":"combo-picker-selection",className:"flex min-h-9 flex-wrap items-center gap-1 border border-tui-border-dim bg-tui-crust p-1",children:[c.map((S,T)=>{let A=S.combo;try{A=na(S.combo)}catch{}return h.jsxs("span",{className:"inline-flex items-center gap-1",children:[h.jsx(pr,{children:A}),h.jsx("button",{type:"button","aria-label":r("agentKeymaps.comboPickerRemoveStep",{step:T+1}),className:"tui-focusable text-tui-faint hover:text-tui-bad",onClick:()=>f(k=>k.filter(E=>E.id!==S.id)),children:"×"})]},S.id)}),p.map(S=>h.jsx(pr,{active:!0,children:S.toUpperCase()},S)),c.length===0&&p.length===0&&h.jsx("span",{className:"px-1 text-tui-sm text-tui-faint",children:r("agentKeymaps.comboPickerEmpty")})]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"mb-1 text-tui-sm text-tui-muted",children:r("agentKeymaps.comboPickerModifiers")}),h.jsx("div",{className:"flex gap-1",children:E5.map(S=>h.jsx("button",{type:"button","aria-pressed":p.includes(S),onClick:()=>y(S),className:`${cd} ${p.includes(S)?"border-tui-accent bg-tui-accent text-tui-crust":""}`,children:S.toUpperCase()},S))})]}),h.jsxs("fieldset",{className:"space-y-1.5",children:[h.jsx("legend",{className:"sr-only",children:r("agentKeymaps.comboPickerKeyboard")}),k5.map(S=>h.jsx("div",{className:"grid grid-cols-10 gap-1",children:S.map(({token:T,label:A})=>h.jsx("button",{type:"button","aria-label":A,className:cd,disabled:c.length>=8,onClick:()=>v(T),children:A},T))},S.map(({token:T})=>T).join("-"))),h.jsx("div",{className:"flex flex-wrap gap-1",children:N5.map(({token:S,label:T})=>h.jsx("button",{type:"button","aria-label":T,className:cd,disabled:c.length>=8,onClick:()=>v(S),children:T},S))})]})]})})}const R5=({profile:l,onProfileChange:n})=>{const{settings:a,updateSettings:s,t:r}=Ee(),{agentProfile:c}=it(),[f,m]=M.useState({}),p=M.useRef({}),[g,y]=M.useState(""),[v,w]=M.useState(""),[x,S]=M.useState(null),T=l||c,A=a.agentKeymaps[T]||{},k=Rb(T,A),E=jb(T,A),N=E.filter(I=>!I.hidden).length,B=I=>I.custom?I.customLabel||"":r(`agentActions.${I.labelKey}`),L=I=>{try{return na(I.combo)}catch{return I.combo}},D=I=>{s({agentKeymaps:{...a.agentKeymaps,[T]:I}})},R=(I,le)=>{var P;D({...A,actions:{...A.actions,[I]:{...(P=A.actions)==null?void 0:P[I],...le}}})},z=I=>{R(I.id,{keys:I.defaultCombo})},K=(I,le)=>{const P=I+(le==="up"?-1:1);if(P<0||P>=k.length)return;const fe=k.map(ve=>ve.id);[fe[I],fe[P]]=[fe[P],fe[I]],D({...A,order:fe})},V=I=>{var le;D({...A,custom:(A.custom||[]).filter(P=>P.id!==I),order:(le=A.order)==null?void 0:le.filter(P=>P!==I)})},te=()=>D(cw(A)),Z=()=>{const I={...a.agentKeymaps};delete I[T],s({agentKeymaps:I})},ie=()=>{const I=g.trim();if(!I)return;try{cn(v)}catch{return}const le=`custom-${Date.now().toString(36)}`;D({...A,custom:[...A.custom||[],{id:le,label:I,keys:v.trim()}],order:[...k.map(P=>P.id),le]}),y(""),w("")},re=I=>I instanceof pn?r(`agentKeymaps.errors.${I.code}`,I.params):String(I),ce=(I,le)=>`${I}:${le}`,O=(I,le)=>{const P=ce(T,I);p.current={...p.current,[P]:le},m(p.current);try{cn(le),R(I,{keys:le})}catch{}},J=I=>{const le=ce(T,I),P=p.current[le];if(P!==void 0){delete p.current[le],m({...p.current});try{cn(P),R(I,{keys:P})}catch{}}};return h.jsxs("div",{className:"space-y-4",children:[h.jsx(gn,{title:r("agentKeymaps.settingsProfileLabel"),aside:h.jsx(Ae,{variant:"ghost",onClick:Z,className:ne(xr,jd),children:r("agentKeymaps.restoreProfile")}),children:h.jsx(Bt,{label:r("agentKeymaps.profileRowLabel"),htmlFor:"agent-keymap-profile",hint:nl[T].configHint?r("agentKeymaps.configHint",{path:nl[T].configHint}):void 0,control:h.jsx(Tr,{id:"agent-keymap-profile","aria-label":r("agentKeymaps.settingsProfileLabel"),value:T,onChange:I=>n(I.target.value),className:_i,children:Qx.map(I=>h.jsx("option",{value:I,children:nl[I].name},I))})})}),h.jsx(gn,{title:r("agentKeymaps.barGroup"),aside:h.jsx(Ae,{variant:"ghost",onClick:te,className:ne(xr,jd),children:r("agentKeymaps.restoreBar")}),children:h.jsxs("div",{className:"space-y-2 py-1.5",children:[h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:r("agentKeymaps.barHint",{profile:nl[T].name,count:N})}),h.jsx("div",{role:"group","aria-label":r("agentKeymaps.barGroup"),"data-testid":"agent-bar-choices",className:"flex flex-wrap gap-1",children:E.map(I=>{const le=B(I),P=L(I),fe=!I.hidden;return h.jsxs("button",{type:"button","data-testid":`agent-bar-toggle-${I.id}`,"aria-pressed":fe,onClick:()=>R(I.id,{hidden:fe}),title:`${P} ${le}`.trim(),className:ne("tui-focusable inline-flex h-7 select-none items-center gap-1 border px-1.5 text-tui-sm transition-colors",fe?"border-tui-accent bg-tui-accent text-tui-crust":"border-tui-border text-tui-muted hover:border-tui-accent hover:text-tui-accent"),children:[h.jsx("span",{"aria-hidden":"true",className:"font-bold",children:fe?_e.check:"+"}),h.jsx("span",{className:"font-bold",children:P}),h.jsx("span",{className:fe?void 0:"opacity-80",children:le})]},I.id)})})]})}),h.jsx(gn,{title:r("agentKeymaps.listGroup",{profile:nl[T].name}),children:k.map((I,le)=>{var se,xe;const P=B(I),fe=r("agentKeymaps.defaultCombo",{combo:na(I.defaultCombo)}),ve=((xe=(se=A.actions)==null?void 0:se[I.id])==null?void 0:xe.keys)??I.combo,X=ce(T,I.id),ue=f[X]??ve;let oe="",pe=null;try{cn(ue),oe=na(ue)}catch(ae){pe=re(ae)}return h.jsxs("div",{"data-testid":`agent-setting-row-${I.id}`,className:A5,children:[h.jsx(pr,{className:"w-full overflow-hidden whitespace-nowrap font-bold [grid-area:cap]",children:oe||"—"}),h.jsxs("span",{className:"min-w-0 break-words text-tui text-tui-text [grid-area:label]",title:P,children:[P,!I.verified&&h.jsx("span",{className:"ml-1 text-tui-sm text-tui-faint",children:r("agentKeymaps.unverified")})]}),h.jsxs("label",{className:"sr-only",htmlFor:`agent-combo-${I.id}`,children:[r("agentKeymaps.shortcutLabel")," ",P]}),h.jsx(un,{id:`agent-combo-${I.id}`,"aria-label":`${r("agentKeymaps.shortcutLabel")} ${P}`,value:ue,onChange:ae=>O(I.id,ae.target.value),onClick:()=>S({kind:"action",actionId:I.id,value:ue}),inputMode:"none",onBlur:()=>J(I.id),onKeyDown:ae=>{ae.key==="Enter"&&ae.currentTarget.blur()},placeholder:r("agentKeymaps.comboPlaceholder"),"aria-invalid":!!pe,className:ne("w-full min-w-0 [grid-area:combo]",M5)}),h.jsx("span",{className:"min-w-0 break-words text-tui-sm text-tui-faint [grid-area:default]",title:fe,children:fe}),h.jsxs("div",{className:"flex items-center justify-end [grid-area:actions]",children:[h.jsx(ll,{onClick:()=>z(I),title:r("agentKeymaps.resetAction"),"aria-label":`${r("agentKeymaps.resetAction")} ${P}`,children:"↺"}),h.jsx(ll,{disabled:le===0,onClick:()=>K(le,"up"),title:r("agentKeymaps.moveUp"),"aria-label":`${r("agentKeymaps.moveUp")} ${P}`,children:"↑"}),h.jsx(ll,{disabled:le===k.length-1,onClick:()=>K(le,"down"),title:r("agentKeymaps.moveDown"),"aria-label":`${r("agentKeymaps.moveDown")} ${P}`,children:"↓"}),I.custom?h.jsx(ll,{variant:"danger",onClick:()=>V(I.id),title:r("agentKeymaps.removeCustom"),"aria-label":`${r("agentKeymaps.removeCustom")} ${P}`,children:_e.cross}):h.jsx("span",{"aria-hidden":"true",className:"h-7 w-7 shrink-0"})]}),pe&&h.jsx("p",{className:"col-span-full text-tui-sm text-tui-bad",role:"alert",children:r("agentKeymaps.invalidCombo",{error:pe})})]},I.id)})}),h.jsx(gn,{title:r("agentKeymaps.addCustom"),children:h.jsxs("div",{className:"space-y-1 py-1.5",children:[h.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[h.jsxs("label",{className:"min-w-[9rem] flex-1 space-y-1 text-tui-sm text-tui-muted",children:[h.jsx("span",{children:r("agentKeymaps.customLabel")}),h.jsx(un,{value:g,onChange:I=>y(I.target.value),className:_i})]}),h.jsxs("label",{className:"min-w-[9rem] flex-1 space-y-1 text-tui-sm text-tui-muted",children:[h.jsx("span",{children:r("agentKeymaps.customCombo")}),h.jsx(un,{value:v,onChange:I=>w(I.target.value),onClick:()=>S({kind:"custom",value:v}),inputMode:"none",placeholder:r("agentKeymaps.comboPlaceholder"),className:_i})]}),h.jsx(Ae,{variant:"primary",glyph:"+",onClick:ie,disabled:!g.trim()||!v.trim(),className:_i,children:r("agentKeymaps.addAction")})]}),v.trim()&&(()=>{try{return cn(v),h.jsx("p",{className:"text-tui-sm text-tui-info",children:na(v)})}catch(I){const le=re(I);return h.jsx("p",{className:"text-tui-sm text-tui-bad",role:"alert",children:le})}})()]})}),x&&h.jsx(L5,{isOpen:!0,value:x.value,onClose:()=>S(null),onApply:I=>{x.kind==="custom"?w(I):(O(x.actionId,I),J(x.actionId)),S(null)}})]})},r0={"gnome-terminal":"GNOME Terminal",ptyxis:"Ptyxis",tilix:"Tilix",konsole:"Konsole","xfce4-terminal":"Xfce Terminal",kitty:"kitty",alacritty:"Alacritty",ghostty:"Ghostty",wezterm:"WezTerm",foot:"foot",vscode:"VS Code",iterm2:"iTerm2","apple-terminal":"Terminal",xterm:"xterm",urxvt:"urxvt"},j5=["host_font_unavailable","host_font_timeout","disconnected","font_api_unavailable"],O5=()=>{const{hostFont:l,loadHostFont:n,declineHostFont:a,settings:s,activeProfile:r,t:c}=Ee(),{herdrLaunch:f,hostname:m}=it(),{addToast:p}=dn(),{font:g,status:y,glyphs:v}=l,w=y==="loading"||v.status==="loading",x=y==="failed"||v.status==="failed",S=M.useRef(!1);M.useEffect(()=>{S.current&&!w&&!x&&l.interactive&&p("success",c("hostFont.loaded")),S.current=w&&l.interactive},[w,x,l.interactive,p,c]);const T=y==="available"||v.status==="available",A=l.interactive&&(w||x);if(!(g&&s.fontFamily==="host"&&!f&&(T||A)))return null;const E=y==="available"||l.interactive&&(y==="loading"||y==="failed"),N=v.source&&(v.status==="available"||l.interactive&&(v.status==="loading"||v.status==="failed")),B=m||(r==null?void 0:r.displayName)||c("herdrLaunch.thisHost"),L=[g.sizePx?`${Math.round(g.sizePx)}px`:null,g.source?r0[g.source]||g.source:null].filter(Boolean).join(c("hostFont.detailSeparator")),D=l.error&&j5.includes(l.error)?l.error:"other",R=l.totalBytes?l.receivedBytes/l.totalBytes:0;return h.jsx("div",{"data-testid":"host-font-prompt",className:"absolute inset-0 z-30 flex items-center justify-center bg-tui-crust/85 p-3",children:h.jsxs(Et,{title:c("hostFont.title"),tone:y==="failed"?"bad":"accent",className:"w-full max-w-md",bodyClassName:"space-y-3","aria-label":c("hostFont.title"),children:[h.jsx("p",{className:"leading-snug text-tui-text",children:E||!v.source?c("hostFont.body",{host:B,family:g.family,detail:L?c("hostFont.detail",{detail:L}):""}):c("hostFont.bodyGlyphsOnly",{host:B,family:v.source.family})}),w?h.jsxs("div",{className:"space-y-1",role:"status",children:[h.jsx(qS,{value:R,width:32,className:"max-w-full overflow-hidden"}),h.jsx("p",{className:"text-tui-sm text-tui-muted",children:c("hostFont.loading",{received:Vu(l.receivedBytes),total:Vu(l.totalBytes)})})]}):h.jsxs(h.Fragment,{children:[x?h.jsx(Ri,{tone:"bad",children:c("hostFont.failed",{reason:c(`hostFont.reasons.${D}`)})}):h.jsxs("div",{className:"space-y-1 text-tui-sm leading-snug text-tui-faint",children:[E&&g.faces.length?h.jsx("p",{children:c("hostFont.download",{count:g.faces.length,size:Vu(l.totalBytes)})}):null,N&&v.source?h.jsx("p",{children:c(v.source.scope==="all"?"hostFont.glyphsAll":"hostFont.glyphs",{family:v.source.family})}):null]}),h.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[h.jsx(Ae,{onClick:a,children:c("hostFont.decline")}),h.jsx(Ae,{variant:"primary",onClick:n,autoFocus:!0,children:c(x?"common.retry":"hostFont.load")})]})]})]})})},D5=({onOpenAdmin:l})=>{var L;const{settings:n,updateSettings:a,language:s,setLanguage:r,t:c,hostFont:f,syncHostFont:m,terminalFontFamily:p,terminalFontSize:g}=Ee(),{connectionState:y}=it(),v=gd.find(D=>D.id===n.fontFamily),w=(D,R)=>D==="host"||D==="system"?c(`fontPresets.${D}`):R,x=(()=>{const{font:D,status:R}=f,z=f.totalBytes?Math.round(f.receivedBytes/f.totalBytes*100):0,K=c(`settings.hostFontStatus.${R}`,{percent:z});return D?[D.family,D.sizePx?`${Math.round(D.sizePx)}px`:null,D.source?r0[D.source]||D.source:null,K].filter(Boolean).join(" · "):K})(),S=(L=f.font)!=null&&L.sizePx?ra(f.font.sizePx):null,T=f.glyphs.source&&f.glyphs.status!=="none"?c("settings.hostGlyphLine",{family:f.glyphs.source.family,status:c(`settings.hostGlyphStatus.${f.glyphs.status}`,{count:f.glyphs.covered.toLocaleString()})}):null,A=typeof window<"u"&&window.isSecureContext&&"Notification"in window,k=10,E=24,N=o0(c),B=S?c("settings.fontSizeFollowHost",{size:S}):c("settings.fontSizeFollowHostUnknown");return h.jsxs("div",{className:"space-y-4",children:[h.jsx(gn,{title:c("settings.sectionInterface"),children:h.jsx(Bt,{label:c("settings.languageLabel"),hint:c("settings.languageHint"),control:h.jsx(gr,{name:"ui-language","aria-label":c("settings.languageLabel"),value:s,onChange:r,options:[{value:"zh",label:"简体中文"},{value:"en",label:"English"}]})})}),h.jsxs(gn,{title:c("settings.sectionFont"),children:[h.jsx(Bt,{label:c("settings.fontFamilyLabel"),htmlFor:"terminal-font-select",control:h.jsxs(Tr,{id:"terminal-font-select",value:n.fontFamily,onChange:D=>a({fontFamily:D.target.value}),"aria-label":c("settings.fontFamilyLabel"),className:_i,children:[!v&&h.jsx("option",{value:n.fontFamily,children:n.fontFamily}),gd.map(D=>h.jsx("option",{value:D.id,children:w(D.id,D.name)},D.id))]})}),n.fontFamily==="host"&&h.jsx(Bt,{label:c("settings.hostFontLabel"),hint:h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-testid":"host-font-status",className:"block break-words text-tui-info",children:x}),T?h.jsx("span",{"data-testid":"host-glyph-status",className:"block break-words",children:T}):null]}),control:h.jsx(Ae,{block:!0,onClick:m,disabled:y!=="connected"||f.status==="loading"||f.glyphs.status==="loading",className:_i,children:c("settings.hostFontSync")})}),h.jsx(Bt,{label:c("settings.fontSizeLabel",{size:g}),hint:c("settings.fontSizeHint"),htmlFor:"terminal-font-size",control:h.jsx("div",{className:ne("flex items-center",Mr),children:h.jsx("input",{id:"terminal-font-size",type:"range",min:k,max:E,step:1,value:g,onChange:D=>a({fontSize:Number(D.target.value),fontSizeFollowsHost:!1}),className:"h-1 w-full cursor-pointer appearance-none bg-tui-border accent-tui-accent"})})}),h.jsx(Bt,{label:B,control:h.jsx(Ni,{label:B,...N,checked:n.fontSizeFollowsHost,onChange:D=>a(D?{fontSizeFollowsHost:!0}:{fontSizeFollowsHost:!1,fontSize:g})})}),h.jsx("div",{className:"py-1.5",children:h.jsxs("div",{className:"overflow-x-auto whitespace-nowrap border border-tui-border bg-tui-mantle px-2 py-1.5 leading-snug text-tui-text",style:{fontFamily:p,fontSize:`${g}px`},children:[h.jsx("span",{className:"text-tui-ok",children:"$"}),' echo "Herdr 0O 1lI ',' [] () -> => !="']})})]}),h.jsxs(gn,{title:c("settings.sectionInput"),children:[h.jsx(Bt,{label:c("settings.predictiveEchoLabel"),hint:c("settings.predictiveEchoDesc"),control:h.jsx(gr,{name:"predictive-echo","aria-label":c("settings.predictiveEchoLabel"),value:n.predictiveEcho,onChange:D=>a({predictiveEcho:D}),options:[{value:"auto",label:c("settings.predictiveEchoAuto")},{value:"always",label:c("settings.predictiveEchoAlways")},{value:"off",label:c("settings.predictiveEchoOff")}]})}),h.jsx(Bt,{label:c("settings.touchKeyToolbar"),hint:c("settings.touchKeyToolbarDesc"),control:h.jsx(Ni,{label:c("settings.touchKeyToolbar"),...N,checked:n.toolbarVisible,onChange:D=>a({toolbarVisible:D})})}),h.jsx(Bt,{label:c("settings.touchHaptics"),hint:c("settings.touchHapticsDesc"),control:h.jsx(Ni,{label:c("settings.touchHaptics"),...N,checked:n.vibrateOnKeyPress,onChange:D=>a({vibrateOnKeyPress:D})})})]}),h.jsxs(gn,{title:c("settings.agentAlertsLabel"),children:[h.jsx(Bt,{label:c("settings.agentAlertBadge"),hint:c("settings.agentAlertBadgeDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertBadge"),...N,checked:n.agentAlertBadge,onChange:D=>a({agentAlertBadge:D})})}),h.jsx(Bt,{label:c("settings.agentAlertVibrate"),hint:c("settings.agentAlertVibrateDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertVibrate"),...N,checked:n.agentAlertVibrate,onChange:D=>a({agentAlertVibrate:D})})}),h.jsx(Bt,{label:c("settings.agentAlertSound"),hint:c("settings.agentAlertSoundDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertSound"),...N,checked:n.agentAlertSound,onChange:D=>{a({agentAlertSound:D}),D&&(ry(),cy("done"))}})}),A&&h.jsx(Bt,{label:c("settings.agentAlertNotify"),hint:c("settings.agentAlertNotifyDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertNotify"),...N,checked:n.agentAlertNotify,onChange:D=>{if(D&&Notification.permission!=="granted"){Notification.requestPermission().then(R=>a({agentAlertNotify:R==="granted"}));return}a({agentAlertNotify:D})}})})]}),l&&h.jsx(gn,{title:c("settings.sectionAdmin"),children:h.jsx(Bt,{label:c("settings.adminEntry"),hint:c("settings.adminEntryHint"),control:h.jsx(Ae,{block:!0,variant:"primary",glyph:_e.arrowRight,onClick:l,className:_i,children:c("settings.adminEntryOpen")})})})]})},z5=()=>{const{settings:l,updateSettings:n,t:a}=Ee(),{addToast:s}=dn(),[r,c]=M.useState(!1),f=o0(a),m=l.virtualKeys&&l.virtualKeys.length>0?l.virtualKeys:Cs(),p=x=>{const S=m.map(T=>T.id===x?{...T,enabled:!T.enabled}:T);n({virtualKeys:S})},g=(x,S)=>{const T=S==="up"?x-1:x+1;if(T<0||T>=m.length)return;const A=[...m],k=A[x];A[x]=A[T],A[T]=k,n({virtualKeys:A})},y=x=>{if(m.some(T=>T.id===x.id)){const T=m.map(A=>A.id===x.id?{...A,enabled:!0}:A);n({virtualKeys:T})}else{const T=[...m,{...x,enabled:!0}];n({virtualKeys:T})}c(!1)},v=x=>{const S=m.filter(T=>T.id!==x);n({virtualKeys:S})},w=()=>{n({virtualKeys:Cs()}),s("info",a("toasts.keyLayoutReset"))};return h.jsxs("div",{className:"space-y-3",children:[h.jsx(gn,{title:a("virtualKeyboard.customizeTitle"),aside:h.jsx(Ae,{variant:"ghost",onClick:w,className:ne(xr,jd),children:a("virtualKeyboard.resetLayout")}),children:m.map((x,S)=>{const T=xd(x,a);return h.jsxs("div",{className:"flex items-center gap-2 py-1",children:[h.jsx(pr,{className:ne("w-16 shrink-0 truncate",!x.enabled&&"opacity-50"),children:x.label}),h.jsx("span",{className:ne("min-w-0 flex-1 break-words text-tui",x.enabled?"text-tui-text":"text-tui-faint"),children:T}),h.jsx(Ni,{label:`${a("virtualKeyboard.enableKey")} ${x.label}`,...f,checked:x.enabled,onChange:()=>p(x.id),className:"h-7 w-24 shrink-0"}),h.jsx(ll,{disabled:S===0,onClick:()=>g(S,"up"),title:a("virtualKeyboard.moveUp"),"aria-label":a("virtualKeyboard.moveUp"),children:"↑"}),h.jsx(ll,{disabled:S===m.length-1,onClick:()=>g(S,"down"),title:a("virtualKeyboard.moveDown"),"aria-label":a("virtualKeyboard.moveDown"),children:"↓"}),h.jsx(ll,{variant:"danger",onClick:()=>v(x.id),title:a("virtualKeyboard.deleteKeyTitle"),"aria-label":a("virtualKeyboard.deleteKeyTitle"),children:_e.cross})]},x.id)})}),h.jsx(Ae,{block:!0,glyph:"+",onClick:()=>c(!r),className:ne("border-dashed",_i),children:a("virtualKeyboard.addKey")}),r&&h.jsx(gn,{title:a("virtualKeyboard.availableKeys"),children:h.jsx("div",{className:"flex flex-wrap gap-1 py-1.5",children:E1.map(x=>{const S=m.some(T=>T.id===x.id);return h.jsxs("button",{type:"button",onClick:()=>y(x),title:xd(x,a),className:ne("tui-focusable flex h-7 select-none items-center gap-1 border px-1.5 text-tui-sm transition-colors",S?"border-tui-border-dim text-tui-faint":"border-tui-border text-tui-text hover:border-tui-accent hover:text-tui-accent"),children:[h.jsx("span",{children:x.label}),h.jsx("span",{"aria-hidden":"true",className:S?"text-tui-ok":"text-tui-accent",children:S?_e.check:"+"})]},x.id)})})})]})},H5=({isOpen:l,onClose:n,initialTab:a,onOpenAdmin:s})=>{const{updateSettings:r,t:c,activeProfile:f}=Ee(),{addToast:m}=dn(),[p,g]=M.useState("general"),[y,v]=M.useState(null);if(M.useEffect(()=>{!l||!a||(g(a),v(null))},[l,a]),!l)return null;const w=()=>{const x=ey();r({fontSize:x.fontSize,fontSizeFollowsHost:x.fontSizeFollowsHost,fontFamily:x.fontFamily,toolbarVisible:x.toolbarVisible,vibrateOnKeyPress:x.vibrateOnKeyPress,predictiveEcho:x.predictiveEcho,agentAlertBadge:x.agentAlertBadge,agentAlertSound:x.agentAlertSound,agentAlertVibrate:x.agentAlertVibrate,agentAlertNotify:x.agentAlertNotify,virtualKeys:x.virtualKeys}),m("info",c("settings.resetDefaultsToast"))};return h.jsxs(ma,{isOpen:l,onClose:n,title:c("settings.title"),subtitle:f?c("settings.subtitleInstance",{name:f.displayName}):c("settings.subtitle"),closeLabel:c("common.closeDialog"),size:"lg",fixedHeight:!0,hints:[{keys:"esc",action:c("common.close")}],footer:h.jsxs(h.Fragment,{children:[h.jsx(Ae,{variant:"ghost",onClick:w,className:xr,children:c("settings.resetDefaults")}),h.jsx(Ae,{variant:"primary",onClick:n,children:c("common.done")})]}),children:[h.jsx(Pd,{tabs:[{id:"general",label:c("settings.tabGeneral"),index:1},{id:"virtualKeys",label:c("settings.tabVirtualKeys"),index:2},{id:"agentKeymaps",label:c("settings.tabAgentKeymaps"),index:3}],activeId:p,onSelect:x=>g(x),className:"mb-3 border-b border-tui-border-dim pb-1"}),p==="general"&&h.jsx(D5,{onOpenAdmin:s}),p==="virtualKeys"&&h.jsx(z5,{}),p==="agentKeymaps"&&h.jsx(R5,{profile:y,onProfileChange:v})]})},B5={success:"ok",warning:"warn",error:"bad",info:"accent"},U5={success:_e.check,warning:_e.warn,error:_e.cross,info:"›"},K5=()=>{const{t:l}=Ee(),{toasts:n,removeToast:a}=dn();return n.length===0?null:h.jsx("div",{className:"pointer-events-none fixed right-2 top-12 z-50 flex w-[calc(100vw-16px)] max-w-sm flex-col gap-1","aria-live":"polite","aria-atomic":"true",children:n.map(s=>{const r=B5[s.type];return h.jsxs("div",{className:ne("pointer-events-auto flex items-start gap-2 border border-tui-border border-l-2 bg-tui-base px-2 py-1 text-tui",rn[r].edgeL),role:"alert",children:[h.jsx("span",{"aria-hidden":"true",className:ne("shrink-0 font-bold",rn[r].text),children:U5[s.type]}),h.jsx("div",{className:"min-w-0 flex-1 break-words leading-snug text-tui-text",children:s.message}),s.count>1&&h.jsxs("span",{className:"shrink-0 border border-tui-border-dim px-1 text-tui-sm text-tui-muted",children:["×",s.count]}),h.jsx("button",{type:"button",onClick:()=>a(s.id),className:"tui-focusable shrink-0 select-none px-0.5 text-tui-faint transition-colors hover:text-tui-bad","aria-label":l("common.dismissNotification"),children:h.jsx("span",{"aria-hidden":"true",children:_e.cross})})]},s.id)})})};function Qd(l,n){const a=(s,r)=>n?n(s):r;switch(l){case"connected":return{label:a("connection.live","Live"),level:"ok",needsAttention:!1};case"connecting":return{label:a("connection.connecting","Connecting"),level:"warn",needsAttention:!0};case"reconnecting":return{label:a("connection.reconnecting","Reconnecting"),level:"warn",needsAttention:!0,actionLabel:a("connection.reconnectNow","Reconnect now")};case"error":return{label:a("connection.error","Error"),level:"bad",needsAttention:!0,actionLabel:a("connection.retry","Retry")};default:return{label:a("connection.offline","Offline"),level:"idle",needsAttention:!0,actionLabel:a("connection.connect","Connect")}}}const c0=[{status:"blocked",level:"warn"},{status:"done",level:"ok"},{status:"working",level:"accent"}];function I5(l){return l?l.total>0||c0.some(({status:n})=>{var a;return(((a=l.counts)==null?void 0:a[n])??0)>0}):!1}const u0=({className:l,compact:n=!1})=>{const{t:a}=Ee(),{agentStatus:s}=it();if(!s)return null;const r=c0.map(({status:f,level:m})=>{var p;return{status:f,level:m,count:((p=s.counts)==null?void 0:p[f])??0}}).filter(f=>f.count>0),c=n?r.slice(0,1):r;return c.length===0?s.total===0?null:h.jsxs("span",{"data-testid":"agent-status-chip",className:ne("flex shrink-0 items-center gap-1 px-1 text-tui-muted",l),title:a("agents.title"),children:[h.jsx(bn,{level:"idle"}),h.jsx("span",{className:"text-tui-faint",children:a("agents.allIdle")})]}):h.jsx("span",{"data-testid":"agent-status-chip",className:ne("flex shrink-0 items-center gap-2 px-1",l),title:a("agents.title"),children:c.map(({status:f,level:m,count:p})=>h.jsxs("span",{className:"flex items-center gap-1 text-tui-muted",children:[h.jsx(bn,{level:m}),h.jsx("span",{className:"text-tui-text",children:p}),h.jsx("span",{className:"text-tui-faint",children:a(`agents.${f}`)})]},f))})},Jd=({onAddProfile:l,mobile:n=!1,statusBar:a=!1})=>{const{profiles:s,activeProfileId:r,activeProfile:c,switchProfile:f,renameProfile:m,removeProfile:p,t:g}=Ee(),{connectionState:y}=it(),[v,w]=M.useState(!1),[x,S]=M.useState(null),[T,A]=M.useState(""),k=M.useRef(null);M.useEffect(()=>{if(!v)return;const R=z=>{k.current&&!k.current.contains(z.target)&&w(!1)};return document.addEventListener("pointerdown",R),()=>document.removeEventListener("pointerdown",R)},[v]);const E=(R,z)=>{S(R),A(z)},N=R=>{const z=T.trim();z&&m(R,z),S(null)},B=R=>{typeof window<"u"&&!window.confirm(g("profiles.removeConfirm"))||(p(R),S(null))},L=(c==null?void 0:c.displayName)||g("profiles.addHost"),D=y==="connected"?"ok":y==="connecting"||y==="reconnecting"?"warn":y==="error"?"bad":"idle";return h.jsxs("div",{ref:k,className:ne("relative min-w-0",n&&"w-full",a&&"flex-1",!n&&!a&&"h-full",!n&&!a&&"shrink-0"),children:[h.jsxs("button",{type:"button","aria-haspopup":"menu","aria-expanded":v,"aria-label":g("profiles.switcherLabel"),onClick:()=>w(R=>!R),className:ne("tui-focusable flex min-w-0 items-center gap-1.5 border border-transparent text-left text-tui-muted transition-colors hover:border-tui-border hover:text-tui-accent",a?"min-h-11 w-full max-w-none px-2":n?"min-h-11 w-full px-2":"h-full max-w-[18rem] px-1"),children:[h.jsx(bn,{level:D}),h.jsx("span",{className:ne("min-w-0 truncate text-tui-text",a&&"flex-1"),children:L}),h.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-tui-faint",children:v?_e.chevronDown:_e.chevronRight})]}),v&&h.jsxs("div",{role:"menu","aria-label":g("profiles.switcherLabel"),className:ne("absolute bottom-full left-0 z-[100] mb-1 max-h-[min(70vh,24rem)] overflow-y-auto border border-tui-border bg-tui-base p-1 shadow-lg",a?"w-80 max-w-[calc(100vw-1rem)]":n?"inset-x-0 bottom-auto top-full mt-1 mb-0 w-full":"w-80 max-w-[calc(100vw-1rem)]"),children:[h.jsx("div",{className:"border-b border-tui-border-dim px-2 py-1 text-tui-sm uppercase text-tui-faint",children:g("profiles.title")}),s.length===0?h.jsx("p",{className:"px-2 py-2 text-tui-sm text-tui-muted",children:g("profiles.empty")}):s.map(R=>{const z=R.id===r,K=R.id===x;return h.jsxs("div",{role:"none",className:"border-b border-tui-border-dim last:border-b-0",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsxs("button",{type:"button",role:"menuitem","aria-current":z?"true":void 0,onClick:()=>{f(R.id),w(!1)},className:ne("tui-focusable flex min-h-11 min-w-0 flex-1 items-center gap-2 px-2 text-left text-tui transition-colors hover:bg-tui-selection",z?"text-tui-accent":"text-tui-text"),children:[h.jsx("span",{"aria-hidden":"true",className:"w-3 shrink-0",children:z?_e.cursor:""}),h.jsxs("span",{className:"min-w-0 flex-1",children:[h.jsx("span",{className:"block truncate font-bold",children:R.displayName}),h.jsx("span",{className:"block truncate text-tui-sm text-tui-faint",title:R.hostname||R.hostId,children:R.hostname||R.hostId||R.wsUrl})]}),z&&h.jsx("span",{className:"shrink-0 text-tui-sm text-tui-ok",children:g("profiles.current")})]}),h.jsx("button",{type:"button",role:"menuitem","aria-label":g("profiles.rename"),title:g("profiles.rename"),onClick:()=>E(R.id,R.displayName),className:"tui-focusable min-h-11 min-w-11 px-2 text-tui-muted hover:text-tui-accent",children:_e.ellipsis})]}),K&&h.jsxs("div",{className:"grid grid-cols-2 gap-1 px-2 pb-2",children:[h.jsx("input",{autoFocus:!0,value:T,maxLength:64,onChange:V=>A(V.target.value),onKeyDown:V=>{V.key==="Enter"&&N(R.id),V.key==="Escape"&&S(null)},"aria-label":g("profiles.rename"),className:"tui-input col-span-2 h-11 min-w-0 px-2 py-1 text-tui"}),h.jsx(Ae,{onClick:()=>N(R.id),variant:"primary",className:"h-11 w-full min-w-0 whitespace-nowrap",children:g("common.save")}),h.jsx(Ae,{onClick:()=>B(R.id),variant:"danger",className:"h-11 w-full min-w-0 whitespace-nowrap",children:g("profiles.remove")})]})]},R.id)}),h.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{w(!1),l()},className:"tui-focusable flex min-h-11 w-full items-center gap-2 px-2 text-left text-tui-accent hover:bg-tui-selection",children:[h.jsx("span",{"aria-hidden":"true",children:"+"}),h.jsx("span",{children:g("profiles.addHost")})]})]})]})},d0=({compact:l=!1,className:n})=>{const{settings:a,updateSettings:s,t:r}=Ee(),{connectionState:c,sharedWindowCount:f,assignedClientId:m}=it(),p=a.observerMode,g=h.jsx(gr,{name:"control-mode","aria-label":r("role.modeLabel"),value:p?"observe":"control",onChange:y=>s({observerMode:y==="observe"}),tone:p?"warn":"ok",size:l?"sm":"md",options:[{value:"control",label:r("role.sharedControl")},{value:"observe",label:r("common.viewer")}],className:n});return l?g:h.jsxs("div",{className:"flex w-full flex-col gap-1",children:[g,h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:r(p?"role.observerHint":"role.controlHint")}),c==="connected"&&f>1?h.jsx("p",{className:"text-tui-sm text-tui-muted",children:r("role.sharedWindows",{count:f})}):null,m?h.jsx(An,{label:r("role.thisWindow"),labelWidth:9,className:"text-tui-sm",children:h.jsx("span",{className:"truncate text-tui-muted",children:m})}):null]})},F5="dibin666/herdr-remote",f0=`https://github.com/${F5}/releases`,G5=`${f0}/latest/download/herdr-remote.tgz`;function Y5(l){return`${f0}/download/herdr-remote-v${l}/herdr-remote-${l}.tgz`}function h0(){const{updateStatus:l,ignoredUpdate:n,hostVersion:a}=it();return a===null||!!(l!=null&&l.updateAvailable)&&n!==(l==null?void 0:l.latest)}const P5="Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like '*node_modules\\herdr-remote*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }",m0=({compact:l=!1,className:n})=>{const{t:a}=Ee(),{updateStatus:s}=it(),r=h0(),[c,f]=M.useState(!1);if(!r)return null;const m=s!=null&&s.updateAvailable?s:null,p=m?m.restartPending?a("update.chipRestart",{version:m.latest}):l?a("update.chipCompact",{version:m.latest}):a("update.chip",{version:m.latest}):a("update.chipOutdated");return h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button","data-testid":"update-chip",onClick:()=>f(!0),title:a("update.title"),className:ne("tui-focusable shrink-0 whitespace-nowrap px-1 text-tui-warn hover:underline",n),children:p}),h.jsx($5,{isOpen:c,onClose:()=>f(!1)})]})},al=({command:l})=>{const{t:n}=Ee(),{addToast:a}=dn();return h.jsxs("div",{className:"flex items-center gap-2 border border-tui-border bg-tui-mantle px-2 py-1",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 select-none text-tui-ok",children:"$"}),h.jsx("code",{className:"min-w-0 flex-1 break-all text-tui-text",children:l}),h.jsx(Ae,{glyph:"⧉",className:"shrink-0",onClick:()=>{qd(l).then(s=>{a(s==="failed"?"error":"success",n(s==="failed"?"clipboard.copyFailed":"toasts.commandCopied"))})},children:n("common.copy")})]})},$5=({isOpen:l,onClose:n})=>{const{t:a}=Ee(),{updateStatus:s,ignoreUpdate:r,hostname:c,hostId:f,platform:m}=it();if(!(s!=null&&s.updateAvailable))return h.jsx(V5,{isOpen:l,onClose:n,host:c||f,win:m==="win32"});const{current:p,installed:g,latest:y,restartPending:v,updateCommand:w}=s;return h.jsx(ma,{isOpen:l,onClose:n,title:a("update.title"),closeLabel:a("common.closeDialog"),size:"md",footer:h.jsxs(h.Fragment,{children:[h.jsx(Ae,{variant:"ghost",onClick:()=>{r(y),n()},children:a("update.ignore")}),h.jsx(Ae,{variant:"primary",onClick:n,children:a("common.done")})]}),children:h.jsxs("div",{className:"space-y-3","data-testid":"update-modal",children:[h.jsxs("div",{className:"space-y-0.5",children:[h.jsx(An,{label:a("common.host"),labelWidth:10,children:c||f||"—"}),h.jsx(An,{label:a("update.running"),labelWidth:10,children:p}),g!==p?h.jsx(An,{label:a("update.installed"),labelWidth:10,children:g}):null,h.jsx(An,{label:a("update.latest"),labelWidth:10,children:h.jsx("span",{className:"text-tui-ok",children:y})})]}),v?h.jsxs(h.Fragment,{children:[h.jsx("p",{className:"leading-snug text-tui-text",children:a("update.restartPending",{version:g})}),h.jsx(al,{command:"herdr-remote restart"})]}):h.jsxs(h.Fragment,{children:[h.jsxs("p",{className:"leading-snug text-tui-text",children:[h.jsx("span",{"aria-hidden":"true",className:"mr-1 text-tui-accent",children:_e.arrowRight}),a("update.stepTui")]}),h.jsx("p",{className:"leading-snug text-tui-muted",children:a("update.stepCli")}),w?h.jsx(al,{command:"herdr-remote update"}):h.jsxs(h.Fragment,{children:[h.jsx(al,{command:`npm install -g ${Y5(y)}`}),h.jsx(al,{command:"herdr-remote restart"})]}),h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:a("update.restartNote")})]})]})})},V5=({isOpen:l,onClose:n,host:a,win:s})=>{const{t:r}=Ee();return h.jsx(ma,{isOpen:l,onClose:n,title:r("update.title"),closeLabel:r("common.closeDialog"),size:"md",footer:h.jsx(Ae,{variant:"primary",onClick:n,children:r("common.done")}),children:h.jsxs("div",{className:"space-y-3","data-testid":"update-modal",children:[h.jsxs("div",{className:"space-y-0.5",children:[h.jsx(An,{label:r("common.host"),labelWidth:10,children:a||"—"}),h.jsx(An,{label:r("update.running"),labelWidth:10,children:h.jsx("span",{className:"text-tui-warn",children:r("update.outdatedVersion")})})]}),h.jsx("p",{className:"leading-snug text-tui-text",children:r("update.outdated")}),s?h.jsxs(h.Fragment,{children:[h.jsx("p",{className:"leading-snug text-tui-muted",children:r("update.windowsStop")}),h.jsx(al,{command:P5})]}):null,h.jsx(al,{command:`npm install -g ${G5}`}),h.jsx(al,{command:"herdr-remote restart"}),h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:r("update.restartNote")})]})})},ud="shrink-0 whitespace-nowrap",gb="min-w-0 truncate whitespace-nowrap",q5=({onAddProfile:l=()=>{}})=>{const{settings:n,t:a}=Ee(),{connectionState:s,hostId:r,assignedClientId:c,sharedWindowCount:f,rttMs:m,agentStatus:p}=it(),g=Qd(s,a),y=s==="connected",v=h0();return h.jsx(ky,{left:h.jsxs(h.Fragment,{children:[h.jsx(Jd,{onAddProfile:l}),h.jsx(Md,{"data-testid":"status-line-segments",items:[h.jsxs("span",{className:ne(ud,"flex items-center gap-1"),children:[h.jsx(bn,{level:g.level}),h.jsx("span",{className:"text-tui-text",children:g.label})]},"status"),y?h.jsx(d0,{compact:!0,className:ne(ud,"h-full w-auto")},"role"):null,y&&f>1?h.jsx("span",{className:ne(ud,"text-tui-muted"),children:a("role.sharedWindows",{count:f})},"windows"):null,r?h.jsxs("span",{className:gb,children:[h.jsxs("span",{className:"text-tui-faint",children:[a("common.host"),":"]})," ",h.jsx("span",{className:"text-tui-text",children:r})]},"host"):null,h.jsxs("span",{className:gb,children:[h.jsx("span",{className:"text-tui-faint",children:a("header.clientIdLabel")})," ",h.jsx("span",{className:"text-tui-text",children:c||n.clientId})]},"client")]})]}),right:h.jsx(Md,{items:[v?h.jsx(m0,{},"update"):null,y&&I5(p)?h.jsx(u0,{},"agents"):null,m!==null?h.jsxs("span",{className:"text-tui-muted",children:[a("header.latencyTitle"),": ",h.jsxs("span",{className:"text-tui-text",children:[m,"ms"]})]},"rtt"):null,h.jsx("span",{className:"hidden text-tui-faint sm:inline",children:a("header.tagline")},"mode")]})})},X5=({wsUrl:l,adminUrl:n,onOpenRemoteAdmin:a,onSignIn:s})=>{const{t:r}=Ee();return h.jsxs(Et,{title:r("admin.remoteRelayTitle"),bodyClassName:"space-y-2",children:[h.jsx("p",{className:"text-tui leading-snug text-tui-muted",children:r("admin.remoteRelayNotice")}),h.jsxs("div",{className:"space-y-0.5 border border-tui-border-dim bg-tui-mantle px-2 py-1.5",children:[h.jsx(An,{label:r("admin.remoteRelayEndpoint"),labelWidth:18,children:h.jsx("code",{className:"break-all text-tui-accent",children:l})}),h.jsx(An,{label:r("admin.remoteRelayAdminUrl"),labelWidth:18,children:h.jsx("code",{className:"break-all text-tui-ok",children:n})})]}),h.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.jsx(Ae,{variant:"primary",onClick:a,glyph:_e.arrowRight,children:r("admin.openRemoteAdminBtn")}),h.jsx(Ae,{onClick:s,children:r("admin.relayAdminLoginBtn")})]})]})},Z5=({adminConfigured:l,isAuthError:n,tokenInput:a,onTokenInput:s,onSubmit:r,isSameOriginRelay:c,onBackToTerminal:f,showBack:m,onCancel:p})=>{const{t:g}=Ee();return h.jsxs(Et,{title:g("admin.relayAdminTitle"),bodyClassName:"space-y-2",children:[l===!1?h.jsx(Ri,{tone:"warn",children:g("admin.relayAdminNotConfigured")}):n?h.jsx(Ri,{tone:"bad",children:g("admin.relayAdminAuthError")}):h.jsx(Ri,{tone:"accent",children:g("admin.relayAdminPrompt")}),h.jsxs("form",{onSubmit:r,className:"space-y-2",children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"relay-admin-token",children:g("admin.relayAdminTokenLabel")}),h.jsx(un,{id:"relay-admin-token",type:"password",autoComplete:"current-password",value:a,onChange:y=>s(y.target.value),placeholder:g("admin.relayAdminTokenPlaceholder")})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Ae,{variant:"primary",type:"submit",disabled:!a.trim(),children:g("admin.relayAdminLoginBtn")}),c?f&&!m?h.jsx(Ae,{variant:"ghost",onClick:f,children:g("admin.returnToTerminal")}):null:h.jsx(Ae,{variant:"ghost",onClick:p,children:g("common.cancel")})]})]})]})},W5=({onOpenPairing:l,onRetry:n})=>{const{t:a}=Ee(),{copied:s,copy:r}=Wd(),c=s!==null,f=()=>r(il,a("toasts.commandCopied"));return h.jsxs(Et,{title:a("admin.unauthorizedTitle"),tone:"bad",bodyClassName:"space-y-2",children:[h.jsx(Ri,{tone:"bad",children:a("admin.unauthorizedDesc")}),h.jsxs("div",{className:"space-y-1.5 border border-tui-border-dim bg-tui-mantle px-2 py-1.5",children:[h.jsx("span",{className:"block text-tui-sm uppercase text-tui-muted",children:a("admin.pairingStepsTitle")}),h.jsxs("div",{className:"flex items-center gap-2 border border-tui-border bg-tui-crust px-2 py-1",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 select-none text-tui-ok",children:"$"}),h.jsx("code",{className:"min-w-0 flex-1 truncate text-tui-text",children:il}),h.jsx(Ae,{onClick:f,glyph:c?_e.check:"⧉",className:ne("shrink-0",c&&"border-tui-ok text-tui-ok"),children:a(c?"admin.copiedJson":"common.copy")})]}),h.jsx("p",{className:"text-tui-sm text-tui-faint",children:a("admin.pairingStepsHelp")})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[l&&h.jsx(Ae,{variant:"primary",onClick:l,children:a("admin.enterPairCodeBtn")}),h.jsx(Ae,{onClick:n,children:a("admin.retryFetchBtn")})]})]})},Q5=[[/\biPhone\b/i,"iPhone"],[/\biPad\b/i,"iPad"],[/\biPod\b/i,"iPod"],[/\bAndroid\b/i,"Android"],[/\bCrOS\b/i,"ChromeOS"],[/\bWindows NT\b/i,"Windows"],[/\bMac OS X\b|\bMacintosh\b/i,"macOS"],[/\bLinux\b/i,"Linux"]],J5=[[/\bEdgA?\/|\bEdge\//i,"Edge"],[/\bOPR\/|\bOpera\//i,"Opera"],[/\bSamsungBrowser\//i,"Samsung Internet"],[/\bFirefox\/|\bFxiOS\//i,"Firefox"],[/\bCriOS\//i,"Chrome"],[/\bChrome\//i,"Chrome"],[/\bSafari\//i,"Safari"]];function bb(l,n){for(const[a,s]of l)if(a.test(n))return s;return null}function ef(l){const n=typeof l=="string"?l.trim():"";if(!n)return{label:"",raw:""};const a=bb(Q5,n),s=bb(J5,n);return a&&s?{label:`${a} · ${s}`,raw:n}:a?{label:a,raw:n}:s?{label:s,raw:n}:{label:n.length>32?`${n.slice(0,32)}…`:n,raw:n}}function la(l){if(!l||l<=0)return"0 B";const n=1024,a=["B","KB","MB","GB","TB"],s=Math.min(a.length-1,Math.floor(Math.log(l)/Math.log(n)));return`${(l/n**s).toFixed(1)} ${a[s]}`}function yb(l,n,a=!1){const s=Math.max(0,Math.floor(l)),r=Math.floor(s/86400),c=Math.floor(s%86400/3600),f=Math.floor(s%3600/60),m=s%60,p=(y,v)=>`${y}${n(`admin.unit${v}`)}`,g=r>0?[p(r,"Day"),p(c,"Hour"),p(f,"Minute")]:c>0?[p(c,"Hour"),p(f,"Minute"),p(m,"Second")]:[p(f,"Minute"),p(m,"Second")];return(a?g.slice(0,2):g).join(" ")}function tf(l,n,a=Date.now()){if(!l)return"—";const s=new Date(l).getTime();if(Number.isNaN(s))return"—";const r=Math.max(0,Math.floor((a-s)/1e3));return r<60?n("admin.relJustNow"):r<3600?n("admin.relMinutes",{count:Math.floor(r/60)}):r<86400?n("admin.relHours",{count:Math.floor(r/3600)}):n("admin.relDays",{count:Math.floor(r/86400)})}function nf(l){if(!l)return"";const n=new Date(l);return Number.isNaN(n.getTime())?"":n.toLocaleString()}function p0(l=[]){const n=new Map;for(const a of l)a.deviceId&&n.set(a.deviceId,(n.get(a.deviceId)||0)+1);return n}const eA=({clients:l})=>{const{t:n}=Ee(),a=l.some(r=>r.hostId),s=[{key:"id",header:n("admin.colClientId"),render:r=>h.jsxs("span",{className:"flex items-center gap-1.5",children:[h.jsx(bn,{level:"ok"}),h.jsx("span",{className:"font-bold text-tui-text",children:r.id})]})},...a?[{key:"host",header:n("admin.colHost"),render:r=>h.jsx("span",{className:"text-tui-text",children:r.hostId||"—"})}]:[],{key:"role",header:n("admin.colRole"),width:10,render:r=>{const c=r.role==="controller";return h.jsx(Ay,{tone:c?"ok":"warn",className:"text-tui-sm",children:n(c?"common.controller":"common.viewer")})}},{key:"device",header:n("admin.colDevice"),render:r=>{const c=ef(r.userAgent);return h.jsxs("span",{className:"flex min-w-0 items-baseline gap-1.5",children:[h.jsx("span",{className:c.label?"text-tui-text":"text-tui-faint",title:c.raw,children:c.label||n("admin.unknownDevice")}),r.deviceId?h.jsx("code",{className:"text-tui-sm text-tui-faint",children:r.deviceId}):null]})}},{key:"ip",header:n("admin.colIp"),render:r=>h.jsx("span",{className:"text-tui-muted",children:r.ip||"127.0.0.1"})},{key:"connectedAt",header:n("admin.colConnectedAt"),render:r=>h.jsx("span",{className:"whitespace-nowrap text-tui-muted",title:nf(r.connectedAt),children:r.connectedAt?tf(r.connectedAt,n):n("admin.startedRecently")})},{key:"traffic",header:n("admin.colTraffic"),align:"right",render:r=>h.jsxs("span",{className:"whitespace-nowrap",children:[h.jsxs("span",{className:"text-tui-accent",children:["↓",la(r.bytesReceived||0)]}),h.jsx("span",{"aria-hidden":"true",className:"mx-1 text-tui-faint",children:"/"}),h.jsxs("span",{className:"text-tui-ok",children:["↑",la(r.bytesSent||0)]})]})}];return h.jsx(Et,{title:n("admin.connectedClientsTitle",{count:l.length}),bodyClassName:"-mx-1",children:h.jsx($d,{columns:s,items:l,rowKey:r=>r.id,empty:n("admin.noClients")})})},tA=({devices:l,clients:n,onRevoke:a})=>{const{t:s}=Ee(),[r,c]=M.useState(null),[f,m]=M.useState(null),p=p0(n),g=[...l].sort((w,x)=>{const S=+!!p.get(x.deviceId)-+!!p.get(w.deviceId);return S||(Date.parse(x.lastSeenAt)||0)-(Date.parse(w.lastSeenAt)||0)}),y=async w=>{if(r!==w){c(w);return}m(w);try{await a(w)}finally{m(null),c(null)}},v=[{key:"status",header:s("admin.colStatus"),width:12,render:w=>{const x=p.get(w.deviceId)||0;return h.jsxs("span",{className:ne("flex items-center gap-1.5 whitespace-nowrap",x?"text-tui-ok":"text-tui-faint"),children:[h.jsx(bn,{level:x?"ok":"idle"}),s(x?"admin.hostStatusOnline":"admin.hostStatusOffline")]})}},{key:"device",header:s("admin.colDevice"),render:w=>{const x=ef(w.userAgent);return h.jsxs("span",{className:"flex min-w-0 items-baseline gap-1.5",children:[h.jsx("span",{className:"text-tui-text",title:x.raw,children:x.label||s("admin.unknownDevice")}),h.jsx("code",{className:"text-tui-sm text-tui-faint",children:w.deviceId})]})}},{key:"host",header:s("admin.colHost"),render:w=>h.jsx("span",{className:"text-tui-text",children:w.hostId||"—"})},{key:"ip",header:s("admin.colIp"),render:w=>h.jsx("span",{className:"text-tui-muted",children:w.lastIp||"—"})},{key:"lastSeen",header:s("admin.colLastSeen"),render:w=>{const x=p.get(w.deviceId)||0;return h.jsx("span",{className:ne("whitespace-nowrap",x?"text-tui-ok":"text-tui-muted"),title:nf(w.lastSeenAt),children:x?s("admin.deviceWindows",{count:x}):tf(w.lastSeenAt,s)})}},{key:"actions",header:s("admin.colActions"),align:"right",render:w=>{const x=r===w.deviceId,S=f===w.deviceId;return h.jsx(Ae,{variant:"danger",disabled:S,onClick:()=>void y(w.deviceId),onBlur:()=>c(T=>T===w.deviceId?null:T),"aria-label":s("admin.revokeDevice"),className:ne("h-6 py-0 text-tui-sm",x&&"bg-tui-bad text-tui-crust"),children:S?h.jsx(ol,{}):s(x?"admin.revokeConfirm":"admin.revokeDevice")})}}];return h.jsx(Et,{title:s("admin.pairedDevicesTitle",{count:l.length}),bodyClassName:"-mx-1",children:h.jsx($d,{columns:v,items:g,rowKey:w=>w.deviceId,empty:s("admin.noDevices")})})},vb={online:"ok",busy:"ok",reconnecting:"warn",offline:"idle"};function nA(l=[],n=[]){const a=new Map;for(const c of n){if(!(c!=null&&c.hostId))continue;const f=a.get(c.hostId);f?f.push(c):a.set(c.hostId,[c])}const s=l.map(c=>{const f=a.get(c.id)||[];return{id:c.id,hostname:c.hostname||c.id,status:c.status||"online",connectedDeviceCount:c.connectedDeviceCount??0,pairedDeviceCount:c.pairedDeviceCount??f.length,activePtyCount:c.activePtyCount??0,version:c.version,latestVersion:c.latestVersion,devices:f,fromRosterOnly:!1}}),r=new Set(s.map(c=>c.id));for(const[c,f]of a)r.has(c)||s.push({id:c,hostname:c,status:"offline",connectedDeviceCount:0,pairedDeviceCount:f.length,activePtyCount:0,devices:f,fromRosterOnly:!0});return s.sort((c,f)=>c.fromRosterOnly!==f.fromRosterOnly?c.fromRosterOnly?1:-1:c.hostname.localeCompare(f.hostname))}const iA=({hosts:l,devices:n,clients:a})=>{const{t:s}=Ee(),r=nA(l,n),c=p0(a),f={online:s("admin.hostStatusOnline"),busy:s("admin.hostStatusBusy"),reconnecting:s("admin.hostStatusReconnecting"),offline:s("admin.hostStatusOffline")};return h.jsx(Et,{title:s("admin.hostsTitle",{count:r.length}),bodyClassName:"space-y-2",children:r.length===0?h.jsx("p",{className:"px-1 py-2 text-tui text-tui-faint",children:s("admin.noHosts")}):r.map(m=>h.jsxs("div",{className:"border border-tui-border-dim bg-tui-mantle",children:[h.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-tui-border-dim px-2 py-1",children:[h.jsxs("span",{className:"flex min-w-0 flex-auto items-center gap-1.5 text-tui",children:[h.jsx(bn,{level:vb[m.status]}),h.jsx("span",{className:"truncate font-bold text-tui-text",children:m.hostname}),m.hostname!==m.id?h.jsx("code",{className:"truncate text-tui-sm text-tui-faint",children:m.id}):null,h.jsx(Ay,{tone:vb[m.status],className:"ml-1 text-tui-sm",children:f[m.status]})]}),h.jsx(Md,{className:"shrink-0 text-tui-sm",items:[h.jsx("span",{className:m.connectedDeviceCount?"text-tui-ok":"text-tui-faint",children:s("admin.hostConnectedDevices",{count:m.connectedDeviceCount})},"connected"),h.jsx("span",{className:"text-tui-muted",children:s("admin.hostPairedDevices",{count:m.pairedDeviceCount})},"paired"),m.version===void 0?null:h.jsx("span",{className:m.version&&!m.latestVersion?"text-tui-muted":"text-tui-warn",children:m.version?m.latestVersion?s("admin.hostVersionBehind",{version:m.version,latest:m.latestVersion}):s("admin.hostVersion",{version:m.version}):s("admin.hostVersionUnknown")},"version"),m.fromRosterOnly?null:h.jsx("span",{className:m.activePtyCount?"text-tui-info":"text-tui-faint",children:s("admin.hostPtys",{count:m.activePtyCount})},"ptys")]})]}),m.devices.length>0?h.jsx("ul",{className:"divide-y divide-tui-border-dim",children:m.devices.map(p=>{const g=ef(p.userAgent),y=c.get(p.deviceId)||0;return h.jsxs("li",{className:"grid grid-cols-[1ch_minmax(0,1fr)_auto] items-baseline gap-x-2 px-2 py-0.5 text-tui sm:grid-cols-[1ch_minmax(0,18ch)_minmax(0,1fr)_16ch_16ch]",children:[h.jsx(bn,{level:y?"ok":"idle"}),h.jsx("span",{className:"truncate text-tui-text",title:g.raw,children:g.label||s("admin.unknownDevice")}),h.jsx("code",{className:"hidden truncate text-tui-sm text-tui-faint sm:block",children:p.deviceId}),h.jsx("span",{className:"hidden truncate text-tui-sm text-tui-muted sm:block",children:p.lastIp||"—"}),h.jsx("span",{className:ne("whitespace-nowrap text-right text-tui-sm",y?"text-tui-ok":"text-tui-faint"),title:nf(p.lastSeenAt),children:y?s("admin.deviceWindows",{count:y}):tf(p.lastSeenAt,s)})]},p.deviceId)})}):h.jsx("p",{className:"px-2 py-1 text-tui-sm text-tui-faint",children:m.pairedDeviceCount>0?s("admin.hostRosterOperatorOnly"):s("admin.noDevices")})]},m.id))})},lA=({data:l})=>{var r,c,f,m,p,g,y,v,w,x;const{t:n}=Ee(),a=l.activeUserCount??((r=l.clients)==null?void 0:r.length)??0,s=new Set((l.devices||[]).map(S=>S.hostId).filter(S=>S&&!(l.hosts||[]).some(T=>T.id===S))).size;return h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 xl:grid-cols-6",children:[h.jsx(Zl,{label:n("admin.connectedHosts"),value:((c=l.hosts)==null?void 0:c.length)||0,sub:s?n("admin.hostsOfflineSub",{count:s}):void 0,tone:(f=l.hosts)!=null&&f.length?"ok":"idle"}),h.jsx(Zl,{label:n("admin.activeUsers"),value:a,sub:n("admin.acrossWindows",{count:((m=l.clients)==null?void 0:m.length)||0}),tone:a?"accent":"idle"}),h.jsx(Zl,{label:n("admin.activePtys"),value:((p=l.ptys)==null?void 0:p.length)||0,sub:n("admin.terminalShells"),tone:(g=l.ptys)!=null&&g.length?"info":"idle"}),h.jsx(Zl,{label:n("admin.statInbound"),value:n("admin.perSecond",{value:la(((y=l.throughput)==null?void 0:y.bytesInPerSec)||0)}),sub:n("admin.statTotal",{value:la(((v=l.throughput)==null?void 0:v.bytesIn)||0)}),tone:"accent"}),h.jsx(Zl,{label:n("admin.statOutbound"),value:n("admin.perSecond",{value:la(((w=l.throughput)==null?void 0:w.bytesOutPerSec)||0)}),sub:n("admin.statTotal",{value:la(((x=l.throughput)==null?void 0:x.bytesOut)||0)}),tone:"ok"}),h.jsx(Zl,{label:n("admin.uptime"),value:yb(l.uptimeSeconds||0,n,!0),title:yb(l.uptimeSeconds||0,n),sub:l.startTime?n("admin.startedAt",{time:new Date(l.startTime).toLocaleTimeString()}):n("admin.startedRecently")})]}),h.jsx(iA,{hosts:l.hosts||[],devices:l.devices,clients:l.clients||[]})]})},aA=({ptys:l})=>{const{t:n}=Ee(),a=l.some(r=>r.hostId),s=[{key:"id",header:n("admin.colPtyId"),render:r=>h.jsx("span",{className:"font-bold text-tui-accent",children:r.id})},...a?[{key:"host",header:n("admin.colHost"),render:r=>h.jsx("span",{className:"text-tui-text",children:r.hostId})}]:[],{key:"pid",header:n("admin.colPid"),width:9,render:r=>h.jsx("span",{className:"text-tui-muted",children:r.pid})},{key:"command",header:n("admin.colCommand"),render:r=>h.jsx("code",{className:"border border-tui-border-dim bg-tui-mantle px-1 text-tui-text",children:r.command})},{key:"grid",header:n("admin.colGrid"),width:11,render:r=>h.jsxs("span",{className:"whitespace-nowrap text-tui-muted",children:[r.cols,h.jsx("span",{"aria-hidden":"true",className:"mx-0.5 text-tui-faint",children:"×"}),r.rows]})},{key:"cwd",header:n("admin.colCwd"),className:"max-w-xs truncate",render:r=>h.jsx("span",{className:"text-tui-muted",children:r.cwd||"~"})},{key:"viewers",header:n("admin.colViewers"),align:"right",width:9,render:r=>h.jsx("span",{className:"font-bold text-tui-ok",children:r.activeClients})}];return h.jsx(Et,{title:n("admin.activePtysTitle",{count:l.length}),bodyClassName:"-mx-1",children:h.jsx($d,{columns:s,items:l,rowKey:r=>r.id,empty:n("admin.noPtys")})})};function Od(l){if(typeof window>"u"||!l||l.startsWith("/"))return"";try{const n=new URL(l.replace(/^ws/,"http")),a=n.pathname.replace(/\/ws\/client\/?$/,"").replace(/\/+$/,"");return n.origin===window.location.origin&&!a?"":`${n.origin}${a}`}catch{return""}}function Es(l,n){const a=Od(l);return a?`${a}${n.startsWith("/")?n:`/${n}`}`:n}async function sA(l){try{const a=await fetch(Es(l,"/api/info"),{headers:{Accept:"application/json"}});if(a.ok)return await a.json()}catch{}return{ok:!0,version:"0.1.0",protocol:1,relayMode:!!(l&&!l.startsWith("/")&&!l.includes("localhost")&&!l.includes("127.0.0.1")&&typeof window<"u"&&!l.startsWith(window.location.origin.replace("http","ws")))?"remote":"local",adminConfigured:!1,adminPath:"/admin",adminStatusPath:"/api/admin/status"}}async function xb(l,n){const a=await fetch(l,{headers:{Accept:"application/json",...n}});if(a.status===401||a.status===403)return{kind:"denied",status:a.status};if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);return{kind:"ok",data:await a.json()}}async function oA(l,n,a){return(await fetch(Es(l,`/api/admin/devices/${encodeURIComponent(a)}`),{method:"DELETE",headers:{Accept:"application/json","X-Relay-Admin-Token":n}})).ok}function rA(l,n,a){return l!=null&&l.adminPath?l.publicUrl?`${l.publicUrl.replace(/\/$/,"")}${l.adminPath}`:Es(a,l.adminPath):n!=null&&n.remoteAdminUrl?n.remoteAdminUrl:a?Es(a,"/admin"):"/admin"}function cA({wsUrl:l,deviceToken:n,adminToken:a,relayOrigin:s,refreshInterval:r,t:c}){const[f,m]=M.useState(null),[p,g]=M.useState(null),[y,v]=M.useState(!1),[w,x]=M.useState(!0),[S,T]=M.useState(null),[A,k]=M.useState(!1),[E,N]=M.useState(null);M.useEffect(()=>{m(null),g(null),v(!1)},[s]),M.useEffect(()=>{let K=!0;return x(!0),sA(l).then(V=>{K&&(g(V),v(!0))}),()=>{K=!1}},[l,s]);const B=(p==null?void 0:p.relayMode)==="remote",L=M.useCallback((K,V)=>{if(K.kind==="denied"){k(!0),T(V),m(null);return}m(K.data),T(null),k(!1),N(new Date)},[]),D=M.useCallback((K,V)=>{k(!1),T(K instanceof Error?K.message:V),m(null)},[]),R=M.useCallback(async()=>{if(y){if(B){if(!a){m(null),x(!1),T(null),k(!1);return}try{x(!0);const K=await xb(Es(l,(p==null?void 0:p.adminStatusPath)||"/api/admin/status"),{"X-Relay-Admin-Token":a});L(K,c("admin.relayAdminAuthError"))}catch(K){console.warn("GET /api/admin/status request failed:",K),D(K,"Failed to fetch remote admin status")}finally{x(!1)}return}try{x(!0);const K=await xb("/api/status",n?{Authorization:`Bearer ${n}`}:{});L(K,K.kind==="denied"?`Authentication failed (HTTP ${K.status}): Access denied. Please configure an authorized token or pair with the host.`:"")}catch(K){console.warn("GET /api/status request failed:",K),D(K,"Failed to fetch status")}finally{x(!1)}}},[y,B,a,p,n,l,s,c]),z=M.useCallback(async K=>{try{if(!await oA(l,a,K)){T(c("admin.revokeFailed"));return}await R()}catch{T(c("admin.revokeFailed"))}},[a,R,l,c]);return M.useEffect(()=>{if(!y)return;R();let K=null;const V=()=>{r>0&&!K&&(K=setInterval(()=>{document.visibilityState==="visible"&&R()},r))},te=()=>{K&&(clearInterval(K),K=null)},Z=()=>{document.visibilityState==="visible"?(R(),V()):te()};return V(),document.addEventListener("visibilitychange",Z),()=>{te(),document.removeEventListener("visibilitychange",Z)}},[y,R,r]),{data:f,relayInfo:p,infoLoaded:y,isRemoteRelay:B,loading:w,error:S,isAuthError:A,lastUpdated:E,fetchStatus:R,revokeDevice:z}}const dd="h-7 py-0",uA=({onBackToTerminal:l,onOpenPairing:n,showBack:a=!1})=>{var ve,X,ue;const{settings:s,updateSettings:r,t:c}=Ee(),f=Od(s.wsUrl)||(typeof window<"u"?window.location.origin:"local"),m=((ve=s.adminTokens)==null?void 0:ve[f])||(f===(typeof window<"u"?window.location.origin:"local")?s.adminToken:"")||"",[p,g]=M.useState(3e3),[y,v]=M.useState("overview"),[w,x]=M.useState(m),[S,T]=M.useState(m),[A,k]=M.useState(!!m),E=!Od(s.wsUrl);M.useEffect(()=>{x(m),T(m),k(!!m)},[f]);const{data:N,relayInfo:B,infoLoaded:L,isRemoteRelay:D,loading:R,error:z,isAuthError:K,lastUpdated:V,fetchStatus:te,revokeDevice:Z}=cA({wsUrl:s.wsUrl,deviceToken:s.token,adminToken:S,relayOrigin:f,refreshInterval:p,t:c}),ie=oe=>{oe.preventDefault();const pe=w.trim();r({adminToken:pe,adminTokens:{...s.adminTokens||{},[f]:pe}}),T(pe),k(!!pe)},re=rA(B,N,s.wsUrl),ce=N?[{id:"overview",label:c("admin.tabOverview"),index:1},{id:"clients",label:c("admin.tabClients",{count:((X=N.clients)==null?void 0:X.length)||0}),index:2},{id:"ptys",label:c("admin.tabPtys",{count:((ue=N.ptys)==null?void 0:ue.length)||0}),index:3},...N.devices?[{id:"devices",label:c("admin.tabDevices",{count:N.devices.length}),index:4}]:[]]:[],O=ce.map(oe=>oe.id).join("|");M.useEffect(()=>{const oe=O?O.split("|"):[],pe=se=>{if(se.ctrlKey||se.altKey||se.metaKey)return;const xe=se.target;if(xe instanceof HTMLInputElement||xe instanceof HTMLTextAreaElement||xe instanceof HTMLSelectElement||xe!=null&&xe.isContentEditable||document.querySelector('[role="dialog"]'))return;if(se.key==="Escape"&&l){se.preventDefault(),l();return}if(se.key.toLowerCase()==="r"){se.preventDefault(),te();return}const ae=Number.parseInt(se.key,10)-1;Number.isInteger(ae)&&ae>=0&&ae<oe.length&&(se.preventDefault(),v(oe[ae]))};return window.addEventListener("keydown",pe),()=>window.removeEventListener("keydown",pe)},[te,l,O]);const J=(B==null?void 0:B.version)||(N==null?void 0:N.version)||"0.1.0",I=a&&l?h.jsx(Ae,{variant:"ghost",onClick:l,title:c("admin.returnToTerminal"),"aria-label":c("admin.returnToTerminal"),glyph:_e.arrowLeft,brackets:!1,className:dd,children:h.jsx("span",{className:"sr-only",children:c("admin.returnToTerminal")})}):null,le=h.jsxs(h.Fragment,{children:[h.jsxs("span",{className:"hidden items-center gap-1.5 whitespace-nowrap text-tui-sm sm:flex",children:[h.jsxs("span",{className:"text-tui-faint",children:["v",J]}),h.jsx(Yd,{}),h.jsx("span",{className:D?"text-tui-alt":"text-tui-ok",children:c(D?"admin.modeRemote":"admin.localWorkstationBadge")})]}),N?h.jsxs(h.Fragment,{children:[h.jsxs("label",{className:"hidden items-center gap-1.5 text-tui-sm text-tui-muted md:flex",children:[h.jsx("span",{children:c("admin.autoRefresh")}),h.jsxs(Tr,{value:p,onChange:oe=>g(Number(oe.target.value)),"aria-label":c("admin.autoRefresh"),className:ne("w-auto",dd),children:[h.jsx("option",{value:0,children:c("admin.paused")}),h.jsx("option",{value:1e3,children:"1s"}),h.jsx("option",{value:3e3,children:"3s"}),h.jsx("option",{value:5e3,children:"5s"}),h.jsx("option",{value:1e4,children:"10s"})]})]}),h.jsx(Ae,{variant:"primary",onClick:te,disabled:R,title:c("admin.refreshNow"),className:dd,children:R?h.jsx(ol,{}):c("admin.refreshNow")})]}):null]}),P=L&&D&&!A&&!E,fe=L&&D&&(A||E)&&!N;return h.jsxs(WS,{tabs:ce,activeTabId:y,onSelectTab:oe=>v(oe),tabsAriaLabel:c("header.mainNavigationAria"),toolbarStart:I,toolbarAside:le,hints:[...N?[{keys:"1–4",action:c("admin.hintTabs")},{keys:"r",action:c("admin.hintRefresh")}]:[],...l?[{keys:"esc",action:c("admin.hintBack")}]:[]],footerAside:V?h.jsx("span",{className:"text-tui-faint",children:c("admin.updatedAt",{time:V.toLocaleTimeString()})}):null,bodyClassName:"space-y-3 pb-2",children:[!L&&h.jsx("div",{className:"flex items-center justify-center gap-2 border border-tui-border bg-tui-base px-3 py-8 text-tui text-tui-muted",children:h.jsx(ol,{label:c("admin.loadingStatus")})}),P&&h.jsx(X5,{wsUrl:s.wsUrl,adminUrl:re,onOpenRemoteAdmin:()=>window.open(re,"_blank","noopener,noreferrer"),onSignIn:()=>k(!0)}),fe&&h.jsx(Z5,{adminConfigured:B==null?void 0:B.adminConfigured,isAuthError:K,tokenInput:w,onTokenInput:x,onSubmit:ie,isSameOriginRelay:E,onBackToTerminal:l,showBack:a,onCancel:()=>k(!1)}),L&&!D&&K&&h.jsx(W5,{onOpenPairing:n,onRetry:te}),L&&z&&!K&&h.jsx(Ri,{tone:"warn",action:h.jsx(Ae,{variant:"warn",onClick:te,children:c("common.retry")}),children:c("admin.errorConnecting",{error:z})}),N&&h.jsxs(h.Fragment,{children:[y==="overview"&&h.jsx(lA,{data:N}),y==="clients"&&h.jsx(eA,{clients:N.clients||[]}),y==="ptys"&&h.jsx(aA,{ptys:N.ptys||[]}),y==="devices"&&h.jsx(tA,{devices:N.devices||[],clients:N.clients||[],onRevoke:Z})]})]})},fd="tui-focusable group flex h-11 w-full select-none items-center gap-2 border px-2 text-left text-tui transition-colors",hd="border-tui-border text-tui-muted hover:border-tui-accent hover:text-tui-accent active:bg-tui-selection",dA="border-tui-accent bg-tui-selection text-tui-accent",md=({active:l=!1})=>h.jsx("span",{"aria-hidden":"true",className:ne("shrink-0",l?"text-tui-accent":"text-tui-faint group-hover:text-tui-accent"),children:_e.cursor}),fA=({onClose:l,onOpenSettings:n,onAddProfile:a=()=>{}})=>{const{settings:s,updateSettings:r,language:c,setLanguage:f,t:m}=Ee(),{connectionState:p,stateDetail:g,rttMs:y,hostId:v,connect:w}=it(),{addToast:x}=dn(),{copied:S,copy:T}=Wd(),A=S!==null,k=Qd(p,m),E=L=>()=>{var R;const D=document.activeElement;(R=D==null?void 0:D.blur)==null||R.call(D),L()},N=()=>T(s.clientId,m("toasts.clientIdCopied",{id:s.clientId}),"info"),B=()=>{const L=c==="zh"?"en":"zh";f(L),x("info",Dd(L,"toasts.switchedLanguage",{lang:L==="zh"?"简体中文":"English"}))};return h.jsxs("div",{className:"flex flex-col gap-3 px-3 pb-2 pt-2",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-tui-border pb-1.5",children:[h.jsx("h2",{className:"text-tui font-bold uppercase text-tui-accent",children:m("mobile.sessionControls")}),h.jsx(Ae,{variant:"ghost",onClick:l,"aria-label":m("mobile.closeSessionControls"),children:"esc"})]}),h.jsx(Et,{title:m("profiles.title"),tone:"accent",bodyClassName:"space-y-1",children:h.jsx(Jd,{mobile:!0,onAddProfile:a})}),h.jsxs(Et,{title:m("common.status"),tone:k.level==="ok"?"ok":k.level==="bad"?"bad":"warn",bodyClassName:"space-y-1.5",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[h.jsx(bn,{level:k.level}),h.jsx("span",{className:"truncate text-tui uppercase text-tui-text",children:k.label}),p==="connected"&&y!==null&&h.jsxs("span",{className:"text-tui-sm text-tui-muted",children:[y,"ms"]})]}),k.actionLabel&&h.jsx(Ae,{variant:"primary",onClick:()=>w(),className:"shrink-0",children:k.actionLabel})]}),k.needsAttention&&g&&h.jsx("p",{className:"text-tui-sm leading-snug text-tui-muted",children:g}),v&&h.jsx(An,{label:m("common.host"),labelWidth:9,children:v}),h.jsxs("button",{type:"button",onClick:N,className:"tui-focusable flex w-full items-baseline gap-2 text-left text-tui",title:m("header.copyClientIdTitle"),children:[h.jsx("span",{className:"shrink-0 text-tui-muted",style:{width:"9ch"},children:m("header.clientIdLabel")}),h.jsx("span",{className:"min-w-0 flex-1 truncate text-tui-text",children:s.clientId}),h.jsx("span",{"aria-hidden":"true",className:ne("shrink-0",A?"text-tui-ok":"text-tui-faint"),children:A?_e.check:"⧉"})]})]}),h.jsx(Et,{title:m("mobile.inputControl"),tone:"accent","aria-label":m("mobile.terminalControlAria"),children:h.jsx(d0,{className:"h-11"})}),h.jsxs(Et,{title:m("mobile.menu"),tone:"accent",bodyClassName:"flex flex-col gap-1",children:[h.jsxs("button",{type:"button",onClick:B,className:ne(fd,hd),"aria-label":m("header.languageToggleTitle"),children:[h.jsx(md,{}),h.jsx("span",{className:"truncate",children:c==="zh"?"English":"中文"})]}),h.jsxs("button",{type:"button",onClick:E(n),className:ne(fd,hd),"aria-label":m("mobile.settingsAria"),children:[h.jsx(md,{}),h.jsx("span",{className:"truncate",children:m("common.settings")})]}),h.jsxs("button",{type:"button",onClick:()=>r({toolbarVisible:!s.toolbarVisible}),className:ne(fd,s.toolbarVisible?dA:hd),"aria-label":m("mobile.keybarAria"),"aria-pressed":s.toolbarVisible,children:[h.jsx(md,{active:s.toolbarVisible}),h.jsx("span",{className:"truncate",children:m("common.keyBar")}),h.jsx("span",{"aria-hidden":"true",className:"ml-auto shrink-0 text-tui-sm",children:s.toolbarVisible?"[x]":"[ ]"})]})]})]})},hA=({onAddProfile:l})=>{const{t:n}=Ee(),{rttMs:a}=it();return h.jsxs("footer",{"data-testid":"mobile-status-bar",role:"status","aria-label":n("mobile.statusBarAria"),className:"absolute inset-x-0 bottom-0 z-40 flex h-11 shrink-0 items-center gap-2 border-t border-tui-border bg-tui-mantle px-1 text-tui-sm",children:[h.jsx(Jd,{statusBar:!0,onAddProfile:l}),h.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-tui-border",children:"│"}),h.jsx(u0,{compact:!0}),h.jsx(m0,{compact:!0}),h.jsxs("span",{className:"flex shrink-0 items-center gap-1 px-1 text-tui-muted",title:n("header.latencyTitle"),children:[h.jsx("span",{className:"text-tui-faint",children:"RTT"}),h.jsx("span",{className:ne(a===null?"text-tui-faint":"text-tui-text"),children:a===null?"—":`${a}ms`})]})]})},mA=({onOpenSettings:l,onAddProfile:n=()=>{}})=>{const{t:a}=Ee(),{connectionState:s,isController:r}=it(),[c,f]=M.useState(!1),m=M.useRef(null),p=M.useCallback(()=>f(!1),[]);M.useEffect(()=>{if(!c)return;const y=v=>{if(!(v.ctrlKey||v.altKey||v.metaKey)&&v.key==="Escape"){const w=v.target;w&&typeof w.closest=="function"&&!!w.closest("#terminal-container")||(v.stopPropagation(),v.preventDefault(),p())}};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[c,p]),M.useEffect(()=>{var y;c&&((y=m.current)==null||y.focus({preventScroll:!0}))},[c]);const g=Qd(s,a);return h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":"mobile-topbar",role:"toolbar","aria-label":a("mobile.sessionControls"),className:"pointer-events-none absolute inset-x-0 top-0 z-40 flex h-12 items-center justify-between gap-2 border-b border-tui-border bg-tui-mantle px-2 text-tui",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-tui-sm text-tui-muted",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 font-bold text-tui-accent",children:"herdr"}),h.jsx(Yd,{className:"shrink-0"}),h.jsx(bn,{level:g.level}),h.jsx("span",{className:"truncate uppercase",children:g.label})]}),h.jsxs("button",{type:"button","data-testid":"mobile-chrome-trigger",onClick:()=>f(!0),"aria-label":a("mobile.sessionControls"),"aria-expanded":c,"aria-haspopup":"dialog",className:ne("tui-focusable pointer-events-auto flex h-9 shrink-0 select-none items-center gap-1.5 border px-2 text-tui uppercase transition-colors",g.needsAttention?"border-tui-warn text-tui-warn":r?"border-tui-border text-tui-muted":"border-tui-accent text-tui-accent"),children:[!r&&!g.needsAttention&&h.jsx("span",{className:"max-w-[8rem] truncate",children:a("common.viewer")}),h.jsx("span",{"aria-hidden":"true",className:"text-tui",children:_e.chevronDown}),h.jsx("span",{"aria-hidden":"true",children:a("mobile.menu")})]})]}),c&&h.jsxs(h.Fragment,{children:[h.jsx("div",{"data-testid":"mobile-sheet-scrim",className:"absolute inset-0 z-40 bg-tui-crust/70",onClick:p,"aria-hidden":"true"}),h.jsx("div",{ref:m,"data-testid":"mobile-control-sheet",role:"dialog","aria-modal":"true","aria-label":a("mobile.sessionControls"),tabIndex:-1,className:"herdr-sheet absolute inset-x-0 bottom-0 z-50 max-h-[85%] overflow-y-auto border-t border-tui-border bg-tui-base pb-3 focus:outline-none",children:h.jsx(fA,{onClose:p,onOpenSettings:()=>{p(),l()},onAddProfile:()=>{p(),n()}})})]}),h.jsx(hA,{onAddProfile:n})]})},pA=()=>{const{activeProfile:l,t:n}=Ee(),{herdrLaunch:a,startHerdr:s,hostname:r}=it();if(!a)return null;const c=r||(l==null?void 0:l.displayName)||n("herdrLaunch.thisHost"),f=a.phase==="failed";return h.jsx("div",{"data-testid":"herdr-start-prompt",className:"absolute inset-0 z-30 flex items-center justify-center bg-tui-crust/85 p-3",children:h.jsx(Et,{title:n(f?"herdrLaunch.failedTitle":"herdrLaunch.title"),tone:f?"bad":"warn",className:"w-full max-w-md",bodyClassName:"space-y-3","aria-label":n("herdrLaunch.title"),children:a.phase==="starting"?h.jsxs("p",{className:"flex items-center gap-2 text-tui-text",role:"status",children:[h.jsx(ol,{}),h.jsx("span",{children:n("herdrLaunch.starting",{host:c})})]}):h.jsxs(h.Fragment,{children:[h.jsx("p",{className:"leading-snug text-tui-text",children:n("herdrLaunch.body",{host:c})}),f&&a.message?h.jsx(Ri,{tone:"bad",children:h.jsx("pre",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap break-words font-mono text-tui-sm",children:a.message})}):null,h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:n("herdrLaunch.scope")}),h.jsx("div",{className:"flex justify-end",children:h.jsx(Ae,{variant:"primary",onClick:s,autoFocus:!0,children:n(f?"common.retry":"herdrLaunch.start")})})]})})})},g0="--app-height",b0="--keyboard-inset",gA=80;function bA(){if(typeof window>"u")return{height:768,keyboardInset:0};const l=window.innerHeight||768,n=window.visualViewport;if(n&&typeof n.height=="number"&&n.height>0){const a=l-n.height-(n.offsetTop||0),s=a>=gA?Math.round(a):0;return{height:Math.round(n.height),keyboardInset:s}}return{height:l,keyboardInset:0}}function wb(l,n=bA()){return l.style.setProperty(g0,`${n.height}px`),l.style.setProperty(b0,`${n.keyboardInset}px`),n}function yA(l=typeof document<"u"?document.documentElement:null){if(!l||typeof window>"u")return()=>{};let n=null;const a=()=>{n=null,wb(l)},s=()=>{if(n===null){if(typeof requestAnimationFrame!="function"){a();return}n=requestAnimationFrame(a)}};wb(l);const r=window.visualViewport;return r==null||r.addEventListener("resize",s),r==null||r.addEventListener("scroll",s),window.addEventListener("resize",s),window.addEventListener("orientationchange",s),()=>{n!==null&&typeof cancelAnimationFrame=="function"&&(cancelAnimationFrame(n),n=null),r==null||r.removeEventListener("resize",s),r==null||r.removeEventListener("scroll",s),window.removeEventListener("resize",s),window.removeEventListener("orientationchange",s),l.style.removeProperty(g0),l.style.removeProperty(b0)}}const vA=900;function Sb(){if(typeof window>"u")return!1;const l=oa();return l<Bd?!0:l<=vA}function xA(){const[l,n]=M.useState(Sb);return M.useEffect(()=>{var r,c;const a=()=>{const f=Sb();n(m=>m===f?m:f)};a();let s=null;try{s=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)"):null}catch{s=null}return(r=s==null?void 0:s.addEventListener)==null||r.call(s,"change",a),window.addEventListener("resize",a),window.addEventListener("orientationchange",a),(c=window.visualViewport)==null||c.addEventListener("resize",a),()=>{var f,m;(f=s==null?void 0:s.removeEventListener)==null||f.call(s,"change",a),window.removeEventListener("resize",a),window.removeEventListener("orientationchange",a),(m=window.visualViewport)==null||m.removeEventListener("resize",a)}},[]),l}function wA(l){const n=l.target;if(!n)return!1;if(n.id==="terminal-container"||n.id==="terminal-frame"||n.id==="terminal-surface"||n.classList.contains("xterm-helper-textarea")||n.classList.contains("xterm")||n.closest("#terminal-container")||n.closest(".xterm"))return!0;if(typeof document<"u"&&document.activeElement){const a=document.activeElement;if(a.id==="terminal-container"||a.classList.contains("xterm-helper-textarea")||a.closest("#terminal-container")||a.closest(".xterm"))return!0}return!1}function SA(l,n={}){if(typeof window>"u")return()=>{};const a=s=>{var r;s.ctrlKey||s.altKey||s.metaKey||s.key==="Escape"&&(n.isModalOpen||n.isSheetOpen)&&(wA(s)||(s.preventDefault(),s.stopPropagation(),(r=l.onCloseModals)==null||r.call(l)))};return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}}function CA(){const[l,n]=M.useState("terminal"),[a,s]=M.useState(!1),[r,c]=M.useState(!1),[f,m]=M.useState(void 0),p=V=>{m(V),c(!0)},{updateSettings:g,addProfileAndConnect:y,settings:v}=Ee(),{connectionState:w,stateDetail:x,stateCode:S,lastPairedAt:T}=it();J1();const A=xA();M.useEffect(()=>yA(),[]),M.useEffect(()=>{zb()},[]),M.useEffect(()=>{const V=a||r;if(V)return SA({onCloseModals:()=>{s(!1),c(!1)}},{isModalOpen:V})},[a,r]),M.useEffect(()=>{var te;const V=()=>{const Z=window.location.pathname,ie=window.location.hash;n(Z==="/admin"||ie==="#admin"?"admin":"terminal")};V(),window.addEventListener("popstate",V),window.addEventListener("hashchange",V);try{const Z=new URL(window.location.href),ie=(te=Z.searchParams.get("pairCode"))==null?void 0:te.toUpperCase();ie&&hr().token?y({wsUrl:Ut,pairCode:ie}):ie&&g({pairCode:ie});let re=!1;if(Z.searchParams.has("token")&&(Z.searchParams.delete("token"),re=!0),Z.searchParams.has("pairCode")&&(Z.searchParams.delete("pairCode"),re=!0),re){const ce=Z.searchParams.toString(),O=Z.pathname+(ce?`?${ce}`:"")+Z.hash;window.history.replaceState({},"",O)}}catch(Z){console.warn("Failed to parse URL query params:",Z)}return()=>{window.removeEventListener("popstate",V),window.removeEventListener("hashchange",V)}},[g,y]);const k=()=>s(!0),E=V=>{n(V),V==="admin"?window.history.pushState({},"","/admin"):window.history.pushState({},"","/")},N=!v.token&&!v.pairCode&&w!=="connected",B=w==="error"&&(["auth_required","unauthorized","device_revoked"].includes(S||"")||/auth|unauthor|forbidden|permission|token|pair/i.test(x||"")),L=N||B,[D,R]=M.useState(!L);M.useEffect(()=>{L||R(!0)},[L]),M.useEffect(()=>{T&&(s(!1),R(!0),n("terminal"))},[T]);const z=l==="terminal"&&!L,K=V=>({visibility:V?"visible":"hidden",opacity:V?1:0,pointerEvents:V?"auto":"none",zIndex:V?1:0});return h.jsxs("div",{"data-testid":"app-shell",style:A?{paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"env(safe-area-inset-bottom, 0px)",paddingLeft:"env(safe-area-inset-left, 0px)",paddingRight:"env(safe-area-inset-right, 0px)"}:void 0,className:"flex h-full w-full select-none flex-col overflow-hidden bg-tui-crust font-mono text-tui text-tui-text",onContextMenu:V=>{V.preventDefault(),V.stopPropagation()},children:[!A&&h.jsx(eC,{currentView:l,onNavigate:E,onOpenSettings:()=>p()}),!A&&!L&&h.jsx(tC,{}),h.jsxs("div",{className:"flex-1 min-h-0 w-full overflow-hidden relative",children:[D&&h.jsxs("div",{"data-testid":"terminal-layer",className:`absolute ${A?"inset-x-0 top-12 bottom-11":"inset-0"} flex flex-col min-h-0 w-full overflow-hidden`,style:K(z),"aria-hidden":!z,children:[h.jsx(JM,{isActive:z}),h.jsx(S5,{compact:A,onCustomize:()=>p("agentKeymaps")}),h.jsx(pA,{}),h.jsx(O5,{})]}),l==="terminal"&&L&&h.jsx("div",{"data-testid":"onboarding-layer",className:"absolute inset-0 flex flex-col min-h-0 w-full overflow-hidden z-10",children:h.jsx(t5,{onPairedSuccess:()=>{}})}),l==="admin"&&h.jsx("div",{"data-testid":"admin-layer",className:"absolute inset-0 flex flex-col min-h-0 w-full overflow-hidden z-20",children:h.jsx(uA,{onBackToTerminal:()=>E("terminal"),onOpenPairing:k,showBack:A})}),A&&z&&h.jsx(mA,{onOpenSettings:()=>p(),onAddProfile:k})]}),!A&&l!=="admin"&&h.jsx(q5,{onAddProfile:k}),h.jsx(T5,{isOpen:a,onClose:()=>s(!1)}),h.jsx(H5,{isOpen:r,initialTab:f,onClose:()=>c(!1),onOpenAdmin:()=>{c(!1),E("admin")}}),h.jsx(K5,{})]})}function TA(){return h.jsx(I1,{children:h.jsx(CA,{})})}const y0=document.getElementById("root");if(!y0)throw new Error("Root element not found");Fx.createRoot(y0).render(h.jsx(Jn.StrictMode,{children:h.jsx(TA,{})}));
61
+ */function ab(l){if(!l)throw new Error("value must not be falsy");return l}const sM={"▀":[{x:0,y:0,w:8,h:4}],"▁":[{x:0,y:7,w:8,h:1}],"▂":[{x:0,y:6,w:8,h:2}],"▃":[{x:0,y:5,w:8,h:3}],"▄":[{x:0,y:4,w:8,h:4}],"▅":[{x:0,y:3,w:8,h:5}],"▆":[{x:0,y:2,w:8,h:6}],"▇":[{x:0,y:1,w:8,h:7}],"█":[{x:0,y:0,w:8,h:8}],"▉":[{x:0,y:0,w:7,h:8}],"▊":[{x:0,y:0,w:6,h:8}],"▋":[{x:0,y:0,w:5,h:8}],"▌":[{x:0,y:0,w:4,h:8}],"▍":[{x:0,y:0,w:3,h:8}],"▎":[{x:0,y:0,w:2,h:8}],"▏":[{x:0,y:0,w:1,h:8}],"▐":[{x:4,y:0,w:4,h:8}],"▔":[{x:0,y:0,w:8,h:1}],"▕":[{x:7,y:0,w:1,h:8}],"▖":[{x:0,y:4,w:4,h:4}],"▗":[{x:4,y:4,w:4,h:4}],"▘":[{x:0,y:0,w:4,h:4}],"▙":[{x:0,y:0,w:4,h:8},{x:0,y:4,w:8,h:4}],"▚":[{x:0,y:0,w:4,h:4},{x:4,y:4,w:4,h:4}],"▛":[{x:0,y:0,w:4,h:8},{x:4,y:0,w:4,h:4}],"▜":[{x:0,y:0,w:8,h:4},{x:4,y:0,w:4,h:8}],"▝":[{x:4,y:0,w:4,h:4}],"▞":[{x:4,y:0,w:4,h:4},{x:0,y:4,w:4,h:4}],"▟":[{x:4,y:0,w:4,h:8},{x:0,y:4,w:8,h:4}],"🭰":[{x:1,y:0,w:1,h:8}],"🭱":[{x:2,y:0,w:1,h:8}],"🭲":[{x:3,y:0,w:1,h:8}],"🭳":[{x:4,y:0,w:1,h:8}],"🭴":[{x:5,y:0,w:1,h:8}],"🭵":[{x:6,y:0,w:1,h:8}],"🭶":[{x:0,y:1,w:8,h:1}],"🭷":[{x:0,y:2,w:8,h:1}],"🭸":[{x:0,y:3,w:8,h:1}],"🭹":[{x:0,y:4,w:8,h:1}],"🭺":[{x:0,y:5,w:8,h:1}],"🭻":[{x:0,y:6,w:8,h:1}],"🭼":[{x:0,y:0,w:1,h:8},{x:0,y:7,w:8,h:1}],"🭽":[{x:0,y:0,w:1,h:8},{x:0,y:0,w:8,h:1}],"🭾":[{x:7,y:0,w:1,h:8},{x:0,y:0,w:8,h:1}],"🭿":[{x:7,y:0,w:1,h:8},{x:0,y:7,w:8,h:1}],"🮀":[{x:0,y:0,w:8,h:1},{x:0,y:7,w:8,h:1}],"🮁":[{x:0,y:0,w:8,h:1},{x:0,y:2,w:8,h:1},{x:0,y:4,w:8,h:1},{x:0,y:7,w:8,h:1}],"🮂":[{x:0,y:0,w:8,h:2}],"🮃":[{x:0,y:0,w:8,h:3}],"🮄":[{x:0,y:0,w:8,h:5}],"🮅":[{x:0,y:0,w:8,h:6}],"🮆":[{x:0,y:0,w:8,h:7}],"🮇":[{x:6,y:0,w:2,h:8}],"🮈":[{x:5,y:0,w:3,h:8}],"🮉":[{x:3,y:0,w:5,h:8}],"🮊":[{x:2,y:0,w:6,h:8}],"🮋":[{x:1,y:0,w:7,h:8}],"🮕":[{x:0,y:0,w:2,h:2},{x:4,y:0,w:2,h:2},{x:2,y:2,w:2,h:2},{x:6,y:2,w:2,h:2},{x:0,y:4,w:2,h:2},{x:4,y:4,w:2,h:2},{x:2,y:6,w:2,h:2},{x:6,y:6,w:2,h:2}],"🮖":[{x:2,y:0,w:2,h:2},{x:6,y:0,w:2,h:2},{x:0,y:2,w:2,h:2},{x:4,y:2,w:2,h:2},{x:2,y:4,w:2,h:2},{x:6,y:4,w:2,h:2},{x:0,y:6,w:2,h:2},{x:4,y:6,w:2,h:2}],"🮗":[{x:0,y:2,w:8,h:2},{x:0,y:6,w:8,h:2}]},oM={"░":[[1,0,0,0],[0,0,0,0],[0,0,1,0],[0,0,0,0]],"▒":[[1,0],[0,0],[0,1],[0,0]],"▓":[[0,1],[1,1],[1,0],[1,1]]},rM={"─":{1:"M0,.5 L1,.5"},"━":{3:"M0,.5 L1,.5"},"│":{1:"M.5,0 L.5,1"},"┃":{3:"M.5,0 L.5,1"},"┌":{1:"M0.5,1 L.5,.5 L1,.5"},"┏":{3:"M0.5,1 L.5,.5 L1,.5"},"┐":{1:"M0,.5 L.5,.5 L.5,1"},"┓":{3:"M0,.5 L.5,.5 L.5,1"},"└":{1:"M.5,0 L.5,.5 L1,.5"},"┗":{3:"M.5,0 L.5,.5 L1,.5"},"┘":{1:"M.5,0 L.5,.5 L0,.5"},"┛":{3:"M.5,0 L.5,.5 L0,.5"},"├":{1:"M.5,0 L.5,1 M.5,.5 L1,.5"},"┣":{3:"M.5,0 L.5,1 M.5,.5 L1,.5"},"┤":{1:"M.5,0 L.5,1 M.5,.5 L0,.5"},"┫":{3:"M.5,0 L.5,1 M.5,.5 L0,.5"},"┬":{1:"M0,.5 L1,.5 M.5,.5 L.5,1"},"┳":{3:"M0,.5 L1,.5 M.5,.5 L.5,1"},"┴":{1:"M0,.5 L1,.5 M.5,.5 L.5,0"},"┻":{3:"M0,.5 L1,.5 M.5,.5 L.5,0"},"┼":{1:"M0,.5 L1,.5 M.5,0 L.5,1"},"╋":{3:"M0,.5 L1,.5 M.5,0 L.5,1"},"╴":{1:"M.5,.5 L0,.5"},"╸":{3:"M.5,.5 L0,.5"},"╵":{1:"M.5,.5 L.5,0"},"╹":{3:"M.5,.5 L.5,0"},"╶":{1:"M.5,.5 L1,.5"},"╺":{3:"M.5,.5 L1,.5"},"╷":{1:"M.5,.5 L.5,1"},"╻":{3:"M.5,.5 L.5,1"},"═":{1:(l,n)=>`M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n}`},"║":{1:(l,n)=>`M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1`},"╒":{1:(l,n)=>`M.5,1 L.5,${.5-n} L1,${.5-n} M.5,${.5+n} L1,${.5+n}`},"╓":{1:(l,n)=>`M${.5-l},1 L${.5-l},.5 L1,.5 M${.5+l},.5 L${.5+l},1`},"╔":{1:(l,n)=>`M1,${.5-n} L${.5-l},${.5-n} L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1`},"╕":{1:(l,n)=>`M0,${.5-n} L.5,${.5-n} L.5,1 M0,${.5+n} L.5,${.5+n}`},"╖":{1:(l,n)=>`M${.5+l},1 L${.5+l},.5 L0,.5 M${.5-l},.5 L${.5-l},1`},"╗":{1:(l,n)=>`M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M0,${.5-n} L${.5+l},${.5-n} L${.5+l},1`},"╘":{1:(l,n)=>`M.5,0 L.5,${.5+n} L1,${.5+n} M.5,${.5-n} L1,${.5-n}`},"╙":{1:(l,n)=>`M1,.5 L${.5-l},.5 L${.5-l},0 M${.5+l},.5 L${.5+l},0`},"╚":{1:(l,n)=>`M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0 M1,${.5+n} L${.5-l},${.5+n} L${.5-l},0`},"╛":{1:(l,n)=>`M0,${.5+n} L.5,${.5+n} L.5,0 M0,${.5-n} L.5,${.5-n}`},"╜":{1:(l,n)=>`M0,.5 L${.5+l},.5 L${.5+l},0 M${.5-l},.5 L${.5-l},0`},"╝":{1:(l,n)=>`M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0 M0,${.5+n} L${.5+l},${.5+n} L${.5+l},0`},"╞":{1:(l,n)=>`M.5,0 L.5,1 M.5,${.5-n} L1,${.5-n} M.5,${.5+n} L1,${.5+n}`},"╟":{1:(l,n)=>`M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1 M${.5+l},.5 L1,.5`},"╠":{1:(l,n)=>`M${.5-l},0 L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1 M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0`},"╡":{1:(l,n)=>`M.5,0 L.5,1 M0,${.5-n} L.5,${.5-n} M0,${.5+n} L.5,${.5+n}`},"╢":{1:(l,n)=>`M0,.5 L${.5-l},.5 M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1`},"╣":{1:(l,n)=>`M${.5+l},0 L${.5+l},1 M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0`},"╤":{1:(l,n)=>`M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n} M.5,${.5+n} L.5,1`},"╥":{1:(l,n)=>`M0,.5 L1,.5 M${.5-l},.5 L${.5-l},1 M${.5+l},.5 L${.5+l},1`},"╦":{1:(l,n)=>`M0,${.5-n} L1,${.5-n} M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1`},"╧":{1:(l,n)=>`M.5,0 L.5,${.5-n} M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n}`},"╨":{1:(l,n)=>`M0,.5 L1,.5 M${.5-l},.5 L${.5-l},0 M${.5+l},.5 L${.5+l},0`},"╩":{1:(l,n)=>`M0,${.5+n} L1,${.5+n} M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0 M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0`},"╪":{1:(l,n)=>`M.5,0 L.5,1 M0,${.5-n} L1,${.5-n} M0,${.5+n} L1,${.5+n}`},"╫":{1:(l,n)=>`M0,.5 L1,.5 M${.5-l},0 L${.5-l},1 M${.5+l},0 L${.5+l},1`},"╬":{1:(l,n)=>`M0,${.5+n} L${.5-l},${.5+n} L${.5-l},1 M1,${.5+n} L${.5+l},${.5+n} L${.5+l},1 M0,${.5-n} L${.5-l},${.5-n} L${.5-l},0 M1,${.5-n} L${.5+l},${.5-n} L${.5+l},0`},"╱":{1:"M1,0 L0,1"},"╲":{1:"M0,0 L1,1"},"╳":{1:"M1,0 L0,1 M0,0 L1,1"},"╼":{1:"M.5,.5 L0,.5",3:"M.5,.5 L1,.5"},"╽":{1:"M.5,.5 L.5,0",3:"M.5,.5 L.5,1"},"╾":{1:"M.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"╿":{1:"M.5,.5 L.5,1",3:"M.5,.5 L.5,0"},"┍":{1:"M.5,.5 L.5,1",3:"M.5,.5 L1,.5"},"┎":{1:"M.5,.5 L1,.5",3:"M.5,.5 L.5,1"},"┑":{1:"M.5,.5 L.5,1",3:"M.5,.5 L0,.5"},"┒":{1:"M.5,.5 L0,.5",3:"M.5,.5 L.5,1"},"┕":{1:"M.5,.5 L.5,0",3:"M.5,.5 L1,.5"},"┖":{1:"M.5,.5 L1,.5",3:"M.5,.5 L.5,0"},"┙":{1:"M.5,.5 L.5,0",3:"M.5,.5 L0,.5"},"┚":{1:"M.5,.5 L0,.5",3:"M.5,.5 L.5,0"},"┝":{1:"M.5,0 L.5,1",3:"M.5,.5 L1,.5"},"┞":{1:"M0.5,1 L.5,.5 L1,.5",3:"M.5,.5 L.5,0"},"┟":{1:"M.5,0 L.5,.5 L1,.5",3:"M.5,.5 L.5,1"},"┠":{1:"M.5,.5 L1,.5",3:"M.5,0 L.5,1"},"┡":{1:"M.5,.5 L.5,1",3:"M.5,0 L.5,.5 L1,.5"},"┢":{1:"M.5,.5 L.5,0",3:"M0.5,1 L.5,.5 L1,.5"},"┥":{1:"M.5,0 L.5,1",3:"M.5,.5 L0,.5"},"┦":{1:"M0,.5 L.5,.5 L.5,1",3:"M.5,.5 L.5,0"},"┧":{1:"M.5,0 L.5,.5 L0,.5",3:"M.5,.5 L.5,1"},"┨":{1:"M.5,.5 L0,.5",3:"M.5,0 L.5,1"},"┩":{1:"M.5,.5 L.5,1",3:"M.5,0 L.5,.5 L0,.5"},"┪":{1:"M.5,.5 L.5,0",3:"M0,.5 L.5,.5 L.5,1"},"┭":{1:"M0.5,1 L.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"┮":{1:"M0,.5 L.5,.5 L.5,1",3:"M.5,.5 L1,.5"},"┯":{1:"M.5,.5 L.5,1",3:"M0,.5 L1,.5"},"┰":{1:"M0,.5 L1,.5",3:"M.5,.5 L.5,1"},"┱":{1:"M.5,.5 L1,.5",3:"M0,.5 L.5,.5 L.5,1"},"┲":{1:"M.5,.5 L0,.5",3:"M0.5,1 L.5,.5 L1,.5"},"┵":{1:"M.5,0 L.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"┶":{1:"M.5,0 L.5,.5 L0,.5",3:"M.5,.5 L1,.5"},"┷":{1:"M.5,.5 L.5,0",3:"M0,.5 L1,.5"},"┸":{1:"M0,.5 L1,.5",3:"M.5,.5 L.5,0"},"┹":{1:"M.5,.5 L1,.5",3:"M.5,0 L.5,.5 L0,.5"},"┺":{1:"M.5,.5 L0,.5",3:"M.5,0 L.5,.5 L1,.5"},"┽":{1:"M.5,0 L.5,1 M.5,.5 L1,.5",3:"M.5,.5 L0,.5"},"┾":{1:"M.5,0 L.5,1 M.5,.5 L0,.5",3:"M.5,.5 L1,.5"},"┿":{1:"M.5,0 L.5,1",3:"M0,.5 L1,.5"},"╀":{1:"M0,.5 L1,.5 M.5,.5 L.5,1",3:"M.5,.5 L.5,0"},"╁":{1:"M.5,.5 L.5,0 M0,.5 L1,.5",3:"M.5,.5 L.5,1"},"╂":{1:"M0,.5 L1,.5",3:"M.5,0 L.5,1"},"╃":{1:"M0.5,1 L.5,.5 L1,.5",3:"M.5,0 L.5,.5 L0,.5"},"╄":{1:"M0,.5 L.5,.5 L.5,1",3:"M.5,0 L.5,.5 L1,.5"},"╅":{1:"M.5,0 L.5,.5 L1,.5",3:"M0,.5 L.5,.5 L.5,1"},"╆":{1:"M.5,0 L.5,.5 L0,.5",3:"M0.5,1 L.5,.5 L1,.5"},"╇":{1:"M.5,.5 L.5,1",3:"M.5,.5 L.5,0 M0,.5 L1,.5"},"╈":{1:"M.5,.5 L.5,0",3:"M0,.5 L1,.5 M.5,.5 L.5,1"},"╉":{1:"M.5,.5 L1,.5",3:"M.5,0 L.5,1 M.5,.5 L0,.5"},"╊":{1:"M.5,.5 L0,.5",3:"M.5,0 L.5,1 M.5,.5 L1,.5"},"╌":{1:"M.1,.5 L.4,.5 M.6,.5 L.9,.5"},"╍":{3:"M.1,.5 L.4,.5 M.6,.5 L.9,.5"},"┄":{1:"M.0667,.5 L.2667,.5 M.4,.5 L.6,.5 M.7333,.5 L.9333,.5"},"┅":{3:"M.0667,.5 L.2667,.5 M.4,.5 L.6,.5 M.7333,.5 L.9333,.5"},"┈":{1:"M.05,.5 L.2,.5 M.3,.5 L.45,.5 M.55,.5 L.7,.5 M.8,.5 L.95,.5"},"┉":{3:"M.05,.5 L.2,.5 M.3,.5 L.45,.5 M.55,.5 L.7,.5 M.8,.5 L.95,.5"},"╎":{1:"M.5,.1 L.5,.4 M.5,.6 L.5,.9"},"╏":{3:"M.5,.1 L.5,.4 M.5,.6 L.5,.9"},"┆":{1:"M.5,.0667 L.5,.2667 M.5,.4 L.5,.6 M.5,.7333 L.5,.9333"},"┇":{3:"M.5,.0667 L.5,.2667 M.5,.4 L.5,.6 M.5,.7333 L.5,.9333"},"┊":{1:"M.5,.05 L.5,.2 M.5,.3 L.5,.45 L.5,.55 M.5,.7 L.5,.95"},"┋":{3:"M.5,.05 L.5,.2 M.5,.3 L.5,.45 L.5,.55 M.5,.7 L.5,.95"},"╭":{1:(l,n)=>`M.5,1 L.5,${.5+n/.15*.5} C.5,${.5+n/.15*.5},.5,.5,1,.5`},"╮":{1:(l,n)=>`M.5,1 L.5,${.5+n/.15*.5} C.5,${.5+n/.15*.5},.5,.5,0,.5`},"╯":{1:(l,n)=>`M.5,0 L.5,${.5-n/.15*.5} C.5,${.5-n/.15*.5},.5,.5,0,.5`},"╰":{1:(l,n)=>`M.5,0 L.5,${.5-n/.15*.5} C.5,${.5-n/.15*.5},.5,.5,1,.5`}},As={"":{d:"M0,0 L1,.5 L0,1",type:0,rightPadding:2},"":{d:"M-1,-.5 L1,.5 L-1,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M1,0 L0,.5 L1,1",type:0,leftPadding:2},"":{d:"M2,-.5 L0,.5 L2,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M0,0 L0,1 C0.552,1,1,0.776,1,.5 C1,0.224,0.552,0,0,0",type:0,rightPadding:1},"":{d:"M.2,1 C.422,1,.8,.826,.78,.5 C.8,.174,0.422,0,.2,0",type:1,rightPadding:1},"":{d:"M1,0 L1,1 C0.448,1,0,0.776,0,.5 C0,0.224,0.448,0,1,0",type:0,leftPadding:1},"":{d:"M.8,1 C0.578,1,0.2,.826,.22,.5 C0.2,0.174,0.578,0,0.8,0",type:1,leftPadding:1},"":{d:"M-.5,-.5 L1.5,1.5 L-.5,1.5",type:0},"":{d:"M-.5,-.5 L1.5,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M1.5,-.5 L-.5,1.5 L1.5,1.5",type:0},"":{d:"M1.5,-.5 L-.5,1.5 L-.5,-.5",type:0},"":{d:"M1.5,-.5 L-.5,1.5",type:1,leftPadding:1,rightPadding:1},"":{d:"M-.5,-.5 L1.5,1.5 L1.5,-.5",type:0}};As[""]=As[""];As[""]=As[""];function cM(l,n,a,s,r,c,f,m){const p=sM[n];if(p)return uM(l,p,a,s,r,c),!0;const g=oM[n];if(g)return dM(l,g,a,s,r,c),!0;const y=rM[n];if(y)return fM(l,y,a,s,r,c,m),!0;const v=As[n];return v?(hM(l,v,a,s,r,c,f,m),!0):!1}function uM(l,n,a,s,r,c){for(let f=0;f<n.length;f++){const m=n[f],p=r/8,g=c/8;l.fillRect(a+m.x*p,s+m.y*g,m.w*p,m.h*g)}}const sb=new Map;function dM(l,n,a,s,r,c){let f=sb.get(n);f||(f=new Map,sb.set(n,f));const m=l.fillStyle;if(typeof m!="string")throw new Error(`Unexpected fillStyle type "${m}"`);let p=f.get(m);if(!p){const g=n[0].length,y=n.length,v=l.canvas.ownerDocument.createElement("canvas");v.width=g,v.height=y;const w=ab(v.getContext("2d")),x=new ImageData(g,y);let S,T,A,k;if(m.startsWith("#"))S=parseInt(m.slice(1,3),16),T=parseInt(m.slice(3,5),16),A=parseInt(m.slice(5,7),16),k=m.length>7&&parseInt(m.slice(7,9),16)||1;else if(m.startsWith("rgba"))[S,T,A,k]=m.substring(5,m.length-1).split(",").map(E=>parseFloat(E));else throw new Error(`Unexpected fillStyle color format "${m}" when drawing pattern glyph`);for(let E=0;E<y;E++)for(let N=0;N<g;N++)x.data[(E*g+N)*4]=S,x.data[(E*g+N)*4+1]=T,x.data[(E*g+N)*4+2]=A,x.data[(E*g+N)*4+3]=n[E][N]*(k*255);w.putImageData(x,0,0),p=ab(l.createPattern(v,null)),f.set(m,p)}l.fillStyle=p,l.fillRect(a,s,r,c)}function fM(l,n,a,s,r,c,f){l.strokeStyle=l.fillStyle;for(const[m,p]of Object.entries(n)){l.beginPath(),l.lineWidth=f*Number.parseInt(m,10);let g;if(typeof p=="function"){const v=.15/c*r;g=p(.15,v)}else g=p;for(const y of g.split(" ")){const v=y[0],w=Zy[v];if(!w){console.error(`Could not find drawing instructions for "${v}"`);continue}const x=y.substring(1).split(",");!x[0]||!x[1]||w(l,Wy(x,r,c,a,s,!0,f))}l.stroke(),l.closePath()}}function hM(l,n,a,s,r,c,f,m){const p=new Path2D;p.rect(a,s,r,c),l.clip(p),l.beginPath();const g=f/12;l.lineWidth=m*g;for(const y of n.d.split(" ")){const v=y[0],w=Zy[v];if(!w){console.error(`Could not find drawing instructions for "${v}"`);continue}const x=y.substring(1).split(",");!x[0]||!x[1]||w(l,Wy(x,r,c,a,s,!1,m,(n.leftPadding??0)*(g/2),(n.rightPadding??0)*(g/2)))}n.type===1?(l.strokeStyle=l.fillStyle,l.stroke()):l.fill(),l.closePath()}function ob(l,n,a=0){return Math.max(Math.min(l,n),a)}const Zy={C:(l,n)=>l.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]),L:(l,n)=>l.lineTo(n[0],n[1]),M:(l,n)=>l.moveTo(n[0],n[1])};function Wy(l,n,a,s,r,c,f,m=0,p=0){const g=l.map(y=>parseFloat(y)||parseInt(y,10));if(g.length<2)throw new Error("Too few arguments for instruction");for(let y=0;y<g.length;y+=2)g[y]*=n-m*f-p*f,c&&g[y]!==0&&(g[y]=ob(Math.round(g[y]+.5)-.5,n,0)),g[y]+=s+m*f;for(let y=1;y<g.length;y+=2)g[y]*=a,c&&g[y]!==0&&(g[y]=ob(Math.round(g[y]+.5)-.5,a,0)),g[y]+=r;return g}const Xd=.5,mM=1024,pM=6;function gM(l){return/Firefox\//.test(l)||/Edge\/\d/.test(l)?"bottom":"ideographic"}class bM{constructor(n,a=typeof navigator<"u"?navigator.userAgent:""){$(this,"pages",[]);$(this,"slots",new Map);$(this,"inkCache",new Map);$(this,"metrics",null);$(this,"font",null);$(this,"baseline");$(this,"generation",0);$(this,"scratch");this.document=n,this.baseline=gM(a)}configure(n,a){const s=this.metrics&&this.font&&this.metrics.cellWidth===n.cellWidth&&this.metrics.cellHeight===n.cellHeight&&this.metrics.charWidth===n.charWidth&&this.metrics.charHeight===n.charHeight&&this.metrics.charLeft===n.charLeft&&this.metrics.charTop===n.charTop&&this.metrics.dpr===n.dpr&&this.font.fontFamily===a.fontFamily&&this.font.fontSize===a.fontSize&&this.font.fontWeight===a.fontWeight&&this.font.fontWeightBold===a.fontWeightBold&&this.font.customGlyphs===a.customGlyphs;this.metrics={...n},this.font={...a},s||this.clear()}clear(){this.slots.clear(),this.inkCache.clear();for(const n of this.pages)n.shelfX=0,n.shelfY=0;this.generation++}dispose(){this.slots.clear(),this.inkCache.clear();for(const n of this.pages)n.canvas.width=0,n.canvas.height=0;this.pages=[]}get pageCount(){return this.pages.length}fontString(n,a){const s=this.font,r=n?s.fontWeightBold:s.fontWeight;return`${a?"italic ":""}${r} ${s.fontSize*this.metrics.dpr}px ${s.fontFamily}`}overflow(n,a,s){if(!this.metrics||!this.font||n.length===1&&n.charCodeAt(0)<128)return 0;const r=`${a?1:0}${s?1:0}${n}`,c=this.inkCache.get(r);if(c!==void 0)return c;let f=0;const m=this.scratchContext();if(m&&!(this.font.customGlyphs&&Qy(n))){m.font=this.fontString(a,s),m.textBaseline=this.baseline;const p=m.measureText(n),g=typeof p.actualBoundingBoxRight=="number"?p.actualBoundingBoxRight:p.width;f=Math.max(0,Math.ceil(this.metrics.charLeft+g-this.metrics.cellWidth))}return this.inkCache.set(r,f),f}get(n){const a=this.metrics,s=this.font;if(!a||!s||a.cellWidth<=0||a.cellHeight<=0)return null;const r=`${n.cells}${n.bold?1:0}${n.italic?1:0}${n.dim?1:0}${n.fg}\0${n.bg}\0${n.chars}`,c=this.slots.get(r);if(c)return c;const f=a.cellWidth*n.cells,m=a.cellHeight,p=this.allocate(f,m);if(!p)return null;const{page:g,x:y,y:v}=p,w=g.ctx;w.save(),w.beginPath(),w.rect(y,v,f,m),w.clip(),w.globalAlpha=1,w.fillStyle=n.bg,w.fillRect(y,v,f,m),w.fillStyle=n.fg,n.dim&&(w.globalAlpha=Xd);let x=!1;s.customGlyphs&&(x=cM(w,n.chars,y,v,a.cellWidth,a.cellHeight,s.fontSize,a.dpr)),x||(w.font=this.fontString(n.bold,n.italic),w.textBaseline=this.baseline,w.fillText(n.chars,y+a.charLeft,v+a.charTop+a.charHeight)),w.restore();const S={source:g.canvas,x:y,y:v,width:f,height:m};return this.slots.set(r,S),S}allocate(n,a){for(const s of this.pages){const r=this.fit(s,n,a);if(r)return r}if(this.pages.length<pM){const s=this.createPage(Math.max(mM,n,a));return s?(this.pages.push(s),this.fit(s,n,a)):null}return this.clear(),this.pages[0]?this.fit(this.pages[0],n,a):null}fit(n,a,s){if(n.shelfX+a>n.canvas.width&&(n.shelfX=0,n.shelfY+=s),n.shelfY+s>n.canvas.height||a>n.canvas.width)return null;const r={page:n,x:n.shelfX,y:n.shelfY};return n.shelfX+=a,r}createPage(n){const a=this.document.createElement("canvas");a.width=n,a.height=n;const s=a.getContext("2d",{alpha:!1});return s?{canvas:a,ctx:s,shelfX:0,shelfY:0}:null}scratchContext(){if(this.scratch===void 0){const n=this.document.createElement("canvas");n.width=1,n.height=1,this.scratch=n.getContext("2d")}return this.scratch}}function Qy(l){if(l.length!==1)return!1;const n=l.charCodeAt(0);return n>=9472&&n<=9631||n>=57504&&n<=57558}function yM(l,n){return(l&(st.UNDERLINE|st.STRIKETHROUGH))!==0||(n&ji.OVERLINE)!==0}function vM(l,n,{px:a,py:s,cells:r,fgWord:c,bgWord:f,ext:m,fgCss:p},{fontSize:g,dpr:y,colors:v,boldBright:w}){const x=(c&st.UNDERLINE)!==0,S=(c&st.STRIKETHROUGH)!==0,T=(f&ji.OVERLINE)!==0,A=r*n.cell.width;l.save(),l.beginPath(),l.rect(a,s,A,n.cell.height),l.clip(),Ms(f)&&(l.globalAlpha=Xd);const k=Math.max(1,Math.floor(g*y/15)),E=k%2===1?.5:0;if(x){const N=qC(m);let B=p;if(N){let R=N;w&&sa(c)&&(R&50331648)!==50331648&&(R&255)<8&&(R+=8),B=Dy(R,v,p)}l.strokeStyle=B,l.lineWidth=k;const L=s+n.char.top+Math.ceil(n.char.height)-E-k*2,D=m?VC(m):ta.SINGLE;switch(l.beginPath(),D){case ta.DOUBLE:l.moveTo(a,L),l.lineTo(a+A,L),l.moveTo(a,L+k*2),l.lineTo(a+A,L+k*2);break;case ta.CURLY:{const R=L+k,z=Math.max(1,k);for(let K=0;K<r;K++){const V=a+K*n.cell.width,te=V+n.cell.width/2,Z=V+n.cell.width;l.moveTo(V,R),l.bezierCurveTo(V,R-z,te,R-z,te,R),l.bezierCurveTo(te,R+z,Z,R+z,Z,R)}break}case ta.DOTTED:l.setLineDash([k,k]),l.moveTo(a,L),l.lineTo(a+A,L);break;case ta.DASHED:{const R=Math.floor(.6*n.cell.width),z=Math.floor(.3*n.cell.width);l.setLineDash([R,z,n.cell.width-R-z]),l.moveTo(a,L),l.lineTo(a+A,L);break}default:l.moveTo(a,L),l.lineTo(a+A,L)}l.stroke(),l.setLineDash([])}if(T&&(l.strokeStyle=p,l.lineWidth=k,l.beginPath(),l.moveTo(a,s+n.char.top+E),l.lineTo(a+A,s+n.char.top+E),l.stroke()),S){const N=Math.max(1,Math.floor(g*y/10)),B=s+n.char.top+Math.floor(n.char.height/2)-(N%2===1?.5:0);l.strokeStyle=p,l.lineWidth=N,l.beginPath(),l.moveTo(a,B),l.lineTo(a+A,B),l.stroke()}l.restore()}const ld=4,xM=3;class wM{constructor(n,a,s,r){$(this,"atlas");$(this,"fades",new lM);$(this,"cols",0);$(this,"rows",0);$(this,"painted",{content:new Uint32Array(0),fg:new Uint32Array(0),bg:new Uint32Array(0),ext:new Uint32Array(0),meta:new Uint32Array(0),combined:[]});$(this,"row",{content:new Uint32Array(0),fg:new Uint32Array(0),bg:new Uint32Array(0),ext:new Uint32Array(0),combined:[]});$(this,"work",$C());this.ctx=n,this.core=s,this.dimensions=r,this.atlas=new bM(a)}resize(n,a){this.cols=n,this.rows=a,this.fades.clear();const s=n*a;this.painted={content:new Uint32Array(s).fill(ea),fg:new Uint32Array(s),bg:new Uint32Array(s),ext:new Uint32Array(s),meta:new Uint32Array(s).fill(ea),combined:new Array(s).fill("")},this.row={content:new Uint32Array(n),fg:new Uint32Array(n),bg:new Uint32Array(n),ext:new Uint32Array(n),combined:new Array(n).fill("")}}invalidate(){this.painted.content.fill(ea),this.painted.meta.fill(ea),this.fades.clear()}hasPaintedInk(n,a){const s=this.dimensions.device;if(!s.cell.width||!s.cell.height)return!1;const r=Math.min(this.cols,Math.floor(n/s.cell.width)),c=Math.min(this.rows,Math.floor(a/s.cell.height)),f=this.painted;for(let m=0;m<c;m++)for(let p=0;p<r;p++){const g=m*this.cols+p,y=f.content[g];if(y===ea||f.meta[g]===ld||ia(f.fg[g]))continue;const v=y&We.CODEPOINT_MASK;if(y&We.IS_COMBINED_MASK?f.combined[g]!=="":v!==0&&v!==32)return!0}return!1}loadRow(n,a){const{content:s,fg:r,bg:c,ext:f,combined:m}=this.row,p=this.work;for(let g=0;g<this.cols;g++)n&&g<n.length?(n.loadCell(g,p),s[g]=p.content,r[g]=p.fg,c[g]=p.bg,f[g]=jy(p),m[g]=p.content&We.IS_COMBINED_MASK?p.combinedData:""):(s[g]=1<<We.WIDTH_SHIFT,r[g]=0,c[g]=0,f[g]=0,m[g]="");if(a)for(const g of a){const y=g.col;if(y<0||y+g.width>this.cols)continue;y>0&&!(s[y]>>>We.WIDTH_SHIFT)&&this.blankAt(y-1);const v=y+g.width;v<this.cols&&!(s[v]>>>We.WIDTH_SHIFT)&&s[v-1]>>>We.WIDTH_SHIFT===2&&this.blankAt(v);const w=XC(g.chars,g.width);s[y]=w.content,m[y]=w.combinedData,r[y]=g.style.fg,c[y]=g.style.bg,f[y]=g.style.ext,g.width===2&&(s[y+1]=0,m[y+1]="",r[y+1]=g.style.fg,c[y+1]=g.style.bg,f[y+1]=g.style.ext)}}blankAt(n){this.row.content[n]=32|1<<We.WIDTH_SHIFT,this.row.combined[n]=""}paintRow(n,a,s=null,r=0){const c=this.cols,{content:f,fg:m,bg:p,ext:g,combined:y}=this.row,v=this.painted,w=n*c;s&&this.fades.begin(n,c,s,v,this.row,r);let x=0,S=-1,T=-1,A="";const k=()=>{S<0||(this.fillCells(S,n,T-S,A),S=-1)};let E=0;for(;E<c;){let B=f[E]>>>We.WIDTH_SHIFT;B===0&&(B=1),E+B>c&&(B=c-E),B===1&&E+1<c&&this.overflowsInto(E)&&(B=2);const L=a&&a.y===n&&a.x>=E&&a.x<E+B?a.shape:Zn.NONE,D=B|L<<xM,R=this.fades.size>0?this.fades.at(w+E,E,this.row,r):null;let z=R!==null||this.differs(w+E,E,D);for(let K=1;K<B;K++)this.differs(w+E+K,E+K,ld)&&(z=!0);if(z){for(let V=0;V<B;V++){const te=w+E+V;v.content[te]=f[E+V],v.fg[te]=m[E+V],v.bg[te]=p[E+V],v.ext[te]=g[E+V],v.meta[te]=V===0?R?D|iM:D:ld,v.combined[te]=y[E+V]}x+=B;const K=R?null:this.plainFill(E,L);K!==null?S>=0&&T===E&&A===K?T=E+B:(k(),S=E,T=E+B,A=K):(k(),this.paintCell(E,n,B,L,R))}E+=B}return k(),x}differs(n,a,s){const r=this.painted,c=this.row;return r.meta[n]!==s||r.content[n]!==c.content[a]||r.fg[n]!==c.fg[a]||r.bg[n]!==c.bg[a]||r.ext[n]!==c.ext[a]||r.combined[n]!==c.combined[a]}overflowsInto(n){const{content:a,fg:s,bg:r,ext:c}=this.row,f=a[n];if((f&We.CODEPOINT_MASK)<128&&!(f&We.IS_COMBINED_MASK)||f>>>We.WIDTH_SHIFT!==1||ia(s[n]))return!1;const p=a[n+1],g=p&We.CODEPOINT_MASK;if(p>>>We.WIDTH_SHIFT!==1||p&We.IS_COMBINED_MASK||g!==0&&g!==32||r[n]!==r[n+1]||c[n+1]!==0||(s[n]&st.INVERSE)!==(s[n+1]&st.INVERSE)||s[n]&st.INVERSE&&s[n]!==s[n+1]||s[n+1]&(st.UNDERLINE|st.STRIKETHROUGH)||r[n+1]&ji.OVERLINE)return!1;const y=this.charsAt(n);return this.core.optionsService.rawOptions.customGlyphs!==!1&&Qy(y)?!1:this.atlas.overflow(y,sa(s[n]),ys(r[n]))>0}charsAt(n){const a=this.row.content[n];if(a&We.IS_COMBINED_MASK)return this.row.combined[n];const s=a&We.CODEPOINT_MASK;return s?String.fromCodePoint(s):""}plainFill(n,a){if(a!==Zn.NONE)return null;const{content:s,fg:r,bg:c}=this.row,f=s[n],m=f&We.CODEPOINT_MASK,p=!(f&We.IS_COMBINED_MASK)&&(m===0||m===32),g=ia(r[n]);return!p&&!g||(r[n]&(st.UNDERLINE|st.STRIKETHROUGH)||c[n]&ji.OVERLINE)&&!g?null:bs(r[n],c[n],this.colors(),this.boldBright()).bg}paintCell(n,a,s,r,c=null){const f=this.ctx,m=this.dimensions.device,p=this.colors(),g=this.row.fg[n],y=this.row.bg[n],v=this.row.ext[n],w=bs(g,y,p,this.boldBright());let x=w.fg,S=w.bg;r===Zn.BLOCK&&(S=p.cursor.css,x=p.cursorAccent.css);const T=ia(g),A=this.charsAt(n),k=n*m.cell.width,E=a*m.cell.height,N=s*m.cell.width,B=m.cell.height,L=T||A===""||A===" ",D=L?null:this.atlas.get({chars:A,bold:sa(g),italic:ys(y),dim:Ms(y),fg:x,bg:S,cells:s}),R=c&&!c.gone?c.alpha:1;if(D&&R===1?f.drawImage(D.source,D.x,D.y,D.width,D.height,k,E,N,B):(f.fillStyle=S,f.fillRect(k,E,N,B),D?(f.globalAlpha=R,f.drawImage(D.source,D.x,D.y,D.width,D.height,k,E,N,B),f.globalAlpha=1):L||(f.save(),f.beginPath(),f.rect(k,E,N,B),f.clip(),f.fillStyle=x,f.globalAlpha=(Ms(y)?Xd:1)*R,f.font=this.atlas.fontString(sa(g),ys(y)),f.fillText(A,k+m.char.left,E+m.char.top+m.char.height),f.restore())),c!=null&&c.gone){const K=r===Zn.BLOCK||(g&st.INVERSE)!==0?x:bs(c.gone.fg,c.gone.bg,p,this.boldBright()).fg;aM(f,this.atlas,c,{fg:K,bg:S},{px:k,py:E,width:N,height:B,cells:s})}!T&&yM(g,y)&&vM(f,m,{px:k,py:E,cells:s,fgWord:g,bgWord:y,ext:v,fgCss:x},{fontSize:this.core.optionsService.rawOptions.fontSize,dpr:this.core._coreBrowserService.dpr,colors:p,boldBright:this.boldBright()}),r!==Zn.NONE&&r!==Zn.BLOCK&&Xy(f,m,k,E,N,r,{css:p.cursor.css,dpr:this.core._coreBrowserService.dpr,cursorWidth:this.core.optionsService.rawOptions.cursorWidth})}fillCells(n,a,s,r){const c=this.dimensions.device;this.ctx.fillStyle=r,this.ctx.fillRect(n*c.cell.width,a*c.cell.height,s*c.cell.width,c.cell.height)}fillBackground(){this.ctx.fillStyle=this.colors().background.css,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}configureAtlas(){const n=this.dimensions.device,a=this.core.optionsService.rawOptions;this.atlas.configure({cellWidth:n.cell.width,cellHeight:n.cell.height,charWidth:n.char.width,charHeight:n.char.height,charLeft:n.char.left,charTop:n.char.top,dpr:this.core._coreBrowserService.dpr},{fontFamily:a.fontFamily,fontSize:a.fontSize,fontWeight:a.fontWeight,fontWeightBold:a.fontWeightBold,customGlyphs:a.customGlyphs!==!1})}colors(){return this.core._themeService.colors}boldBright(){return this.core.optionsService.rawOptions.drawBoldTextInBrightColors!==!1}}function SM(){return{css:{canvas:{width:0,height:0},cell:{width:0,height:0}},device:{canvas:{width:0,height:0},cell:{width:0,height:0},char:{width:0,height:0,left:0,top:0}}}}function CM(l,n,a,s){const r=n._charSizeService;if(!r.hasValidSize)return!1;const c=n._coreBrowserService.dpr,f=n.optionsService.rawOptions;return l.device.char.width=Math.floor(r.width*c),l.device.char.height=Math.ceil(r.height*c),l.device.cell.height=Math.floor(l.device.char.height*f.lineHeight),l.device.char.top=f.lineHeight===1?0:Math.round((l.device.cell.height-l.device.char.height)/2),l.device.cell.width=l.device.char.width+Math.round(f.letterSpacing),l.device.char.left=Math.floor(f.letterSpacing/2),l.device.canvas.height=s*l.device.cell.height,l.device.canvas.width=a*l.device.cell.width,l.css.canvas.height=Math.round(l.device.canvas.height/c),l.css.canvas.width=Math.round(l.device.canvas.width/c),l.css.cell.height=l.css.canvas.height/s,l.css.cell.width=l.css.canvas.width/a,!0}function TM(l,n,a){if(!l||typeof l.ResizeObserver!="function")return null;let s=new l.ResizeObserver(r=>{var p;const c=r.find(g=>g.target===n);if(!c)return;if(!("devicePixelContentBoxSize"in c)||!((p=c.devicePixelContentBoxSize)!=null&&p[0])){s==null||s.disconnect(),s=null;return}const f=c.devicePixelContentBoxSize[0].inlineSize,m=c.devicePixelContentBoxSize[0].blockSize;f<=0||m<=0||f===n.width&&m===n.height||a(f,m)});try{s.observe(n,{box:"device-pixel-content-box"})}catch{s.disconnect(),s=null}return{dispose:()=>s==null?void 0:s.disconnect()}}function MM(l){if(!l)return[];const n=l.cells.map(a=>a.row);return l.cursor&&n.push(l.cursor.row),n}function AM(l){const n=new Map;for(const a of(l==null?void 0:l.cells)??[]){const s=n.get(a.row);s?s.push(a):n.set(a.row,[a])}return n}class EM{constructor(n){$(this,"canvas");$(this,"ctx");$(this,"selection",null);$(this,"link",null);this.canvas=n.createElement("canvas"),this.canvas.classList.add("xterm-decor-layer"),this.canvas.style.zIndex="2";const a=this.canvas.getContext("2d");if(!a)throw new Error("2D canvas unavailable");this.ctx=a}setSelection(n,a,s){this.selection=n&&a&&!(n[0]===a[0]&&n[1]===a[1])?{start:[n[0],n[1]],end:[a[0],a[1]],columnSelectMode:s}:null}paint({dims:n,rows:a,cols:s,ydisp:r,colors:c,focused:f,dpr:m,cursorWidth:p,caret:g}){var S;const y=this.ctx;if(y.clearRect(0,0,this.canvas.width,this.canvas.height),!n.cell.width||!a)return;const{selection:v,link:w}=this,x=(T,A,k,E)=>y.fillRect(T*n.cell.width,A*n.cell.height,k*n.cell.width,E*n.cell.height);if(v){const T=v.start[1]-r,A=v.end[1]-r,k=Math.max(T,0),E=Math.min(A,a-1);if(k<a&&E>=0)if(y.fillStyle=(f?c.selectionBackgroundTransparent:c.selectionInactiveBackgroundTransparent).css,v.columnSelectMode)x(v.start[0],k,v.end[0]-v.start[0],E-k+1);else{const N=T===k?v.start[0]:0,B=k===A?v.end[0]:s;x(N,k,B-N,1),x(0,k+1,s,Math.max(E-k-1,0)),k!==E&&x(0,E,A===E?v.end[0]:s,1)}}if(w){y.fillStyle=w.fg===257?c.background.css:w.fg!==void 0&&w.fg<256?((S=c.ansi[w.fg])==null?void 0:S.css)??c.foreground.css:c.foreground.css;const T=(A,k,E)=>y.fillRect(A*n.cell.width,(k+1)*n.cell.height-m-1,E*n.cell.width,m);if(w.y1===w.y2)T(w.x1,w.y1,w.x2-w.x1);else{T(w.x1,w.y1,w.cols-w.x1);for(let A=w.y1+1;A<w.y2;A++)T(0,A,w.cols);T(0,w.y2,w.x2)}}if(g){const T=Math.round(g.x*n.cell.width),A=g.y*n.cell.height;g.shape===Zn.BLOCK?(y.fillStyle=g.css,y.fillRect(T,A,n.cell.width,n.cell.height)):Xy(y,n,T,A,n.cell.width,g.shape,{css:g.css,dpr:m,cursorWidth:p})}}}class kM{constructor(n,a){$(this,"text");$(this,"textContext");$(this,"decor");this.screen=a,this.text=n.createElement("canvas"),this.text.classList.add("xterm-text-layer"),this.text.style.zIndex="0";const s=this.text.getContext("2d",{alpha:!1});if(!s)throw new Error("2D canvas unavailable");this.textContext=s,this.decor=new EM(n),a.appendChild(this.text),a.appendChild(this.decor.canvas)}size(n){for(const a of[this.text,this.decor.canvas])a.width=n.device.canvas.width,a.height=n.device.canvas.height,a.style.width=`${n.css.canvas.width}px`,a.style.height=`${n.css.canvas.height}px`;this.screen.style.width=`${n.css.canvas.width}px`,this.screen.style.height=`${n.css.canvas.height}px`}watchDevicePixels(n,a,s,r){return TM(n,this.text,(c,f)=>{const m=a.css.canvas;if(!(Math.abs(c-m.width*s())>2||Math.abs(f-m.height*s())>2)){a.device.canvas.width=c,a.device.canvas.height=f;for(const p of[this.text,this.decor.canvas])p.width=c,p.height=f;r()}})}remove(){this.text.remove(),this.decor.canvas.remove()}}function NM(l,n){const a=l.fonts;return!a||typeof a.addEventListener!="function"?null:(a.addEventListener("loadingdone",n),{dispose:()=>a.removeEventListener("loadingdone",n)})}class _M{constructor(n,a,s){$(this,"startedAt",null);$(this,"held",null);$(this,"timer",null);this.now=n,this.maxHoldMs=a,this.onExpire=s}get pending(){return this.held}hold(n,a){const s=this.now();return this.startedAt===null&&(this.startedAt=s),s-this.startedAt>=this.maxHoldMs?!1:(this.held=this.held?{start:Math.min(this.held.start,n),end:Math.max(this.held.end,a)}:{start:n,end:a},this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.onExpire()},this.maxHoldMs)),!0)}release(n,a){return this.held&&(n=Math.min(n,this.held.start),a=Math.max(a,this.held.end)),this.held=null,this.startedAt=null,this.timer&&(clearTimeout(this.timer),this.timer=null),{start:n,end:a}}dispose(){this.timer&&clearTimeout(this.timer)}}const LM=150;class Zd{constructor(n,a){$(this,"dimensions",SM());$(this,"redraw",new ZC);$(this,"onRequestRedraw",this.redraw.event);$(this,"stats",{frames:0,heldFrames:0,lastPaintMs:0,lastCells:0,lastInputToPaintMs:null});$(this,"surface");$(this,"cells");$(this,"disposables",[]);$(this,"now");$(this,"syncHold");$(this,"cols",0);$(this,"rows",0);$(this,"overlayProvider",null);$(this,"typingZoneProvider",null);$(this,"reducedMotion");$(this,"paintedOverlayRows",new Set);$(this,"paintedCursorRow",-1);$(this,"lastYdisp",0);$(this,"inputAt",null);$(this,"blink",new XT(()=>this.requestCursorRow()));$(this,"glide",new WT);$(this,"slidingCaret",null);$(this,"disposed",!1);$(this,"isSynchronizing");$(this,"dprUsed",0);var f,m;this.core=n,this.now=a.now??(()=>performance.now()),this.syncHold=new _M(this.now,a.maxSyncHoldMs??LM,()=>this.flushHeld()),this.isSynchronizing=a.isSynchronizing??(()=>!1),this.reducedMotion=(m=(f=n._coreBrowserService.window).matchMedia)==null?void 0:m.call(f,"(prefers-reduced-motion: reduce)");const s=n._coreBrowserService.mainDocument;this.surface=new kM(s,n.screenElement),this.cells=new wM(this.surface.textContext,s,n,this.dimensions),this.disposables.push(n._themeService.onChangeColors(()=>{this.cells.atlas.clear(),this.invalidateAll(),this.redrawDecor()}),n.optionsService.onOptionChange(p=>{(p==="cursorBlink"||p==="cursorStyle")&&this.restartBlink()})),n.linkifier&&this.disposables.push(n.linkifier.onShowLinkUnderline(p=>{this.surface.decor.link=p,this.redrawDecor()}),n.linkifier.onHideLinkUnderline(()=>{this.surface.decor.link=null,this.redrawDecor()}));const r=this.surface.watchDevicePixels(n._coreBrowserService.window,this.dimensions,()=>n._coreBrowserService.dpr,()=>{this.invalidateAll(),this.cells.fillBackground(),this.redrawDecor(),this.redraw.fire({start:0,end:Math.max(0,this.rows-1)})});r&&this.disposables.push(r);const c=NM(s,()=>this.clearTextureAtlas());c&&this.disposables.push(c),this.restartBlink()}static install(n,a={}){const s=zy(n);if(!s)return null;const r=new Zd(s,a);return s._renderService.setRenderer(r),s._renderService.handleResize(s._bufferService.cols,s._bufferService.rows),r}setOverlayProvider(n){this.overlayProvider=n,this.invalidateOverlay()}setTypingZoneProvider(n){this.typingZoneProvider=n}invalidateOverlay(){var s;const n=((s=this.overlayProvider)==null?void 0:s.call(this))??null,a=new Set(this.paintedOverlayRows);for(const r of MM(n))a.add(r);this.paintedCursorRow>=0&&a.add(this.paintedCursorRow+this.buffer().ydisp),this.requestAbsoluteRows(a)}markInput(){this.inputAt=this.now()}flushHeld(){const n=this.syncHold.pending;n&&this.redraw.fire({start:n.start,end:n.end})}handleDevicePixelRatioChange(){this.dimensions.device.cell.width&&this.dprUsed!==this.core._coreBrowserService.dpr&&this.handleResize(this.core._bufferService.cols,this.core._bufferService.rows)}handleResize(n,a){CM(this.dimensions,this.core,n,a)&&(this.dprUsed=this.core._coreBrowserService.dpr),this.surface.size(this.dimensions),this.cols=n,this.rows=a,this.cells.resize(n,a),this.paintedOverlayRows.clear(),this.paintedCursorRow=-1,this.cells.configureAtlas(),this.cells.fillBackground(),this.redrawDecor()}handleCharSizeChanged(){this.handleResize(this.core._bufferService.cols,this.core._bufferService.rows)}handleBlur(){this.blink.stop(),this.requestCursorRow(),this.redrawDecor()}handleFocus(){this.restartBlink(),this.requestCursorRow(),this.redrawDecor()}handleSelectionChanged(n,a,s){this.surface.decor.setSelection(n,a,s),this.redrawDecor()}handleCursorMove(){this.blink.running&&this.restartBlink()}clear(){this.invalidateAll(),this.cells.fillBackground()}clearTextureAtlas(){this.cells.atlas.clear(),this.invalidateAll(),this.redraw.fire({start:0,end:Math.max(0,this.rows-1)})}renderRows(n,a){if(this.disposed||!this.cols||!this.rows||!this.dimensions.device.cell.width)return;if(this.isSynchronizing()&&this.syncHold.hold(n,a)){this.stats.heldFrames++;return}const s=this.syncHold.release(n,a);this.paint(Math.max(0,s.start),Math.min(this.rows-1,s.end))}dispose(){if(!this.disposed){this.disposed=!0,this.blink.stop(),this.syncHold.dispose();for(const n of this.disposables)n.dispose();this.disposables.length=0,this.redraw.dispose(),this.cells.atlas.dispose(),this.surface.remove()}}uninstall(){const n=this.core._createRenderer;typeof n=="function"&&(this.core._renderService.setRenderer(n.call(this.core)),this.core._renderService.handleResize(this.core._bufferService.cols,this.core._bufferService.rows)),this.dispose()}get textCanvas(){return this.surface.text}hasPaintedInk(n,a){return this.cells.hasPaintedInk(n,a)}paint(n,a){var k,E,N;const s=this.now(),r=this.buffer(),c=r.ydisp;c!==this.lastYdisp&&(this.lastYdisp=c,this.cells.fades.clear(),this.redrawDecor());const f=(k=this.reducedMotion)!=null&&k.matches?null:((E=this.typingZoneProvider)==null?void 0:E.call(this))??null,m=f?f.row-c:-1,p=((N=this.overlayProvider)==null?void 0:N.call(this))??null,g=AM(p),y=this.cursorState(p),v=QT(y,p,c,this.colors()),w=this.glide.update(v,m,s),x=w?null:y,S=w&&(v==null?void 0:v.plain);S&&g.set(S.row,[...g.get(S.row)??[],S]);const T=new Set;for(let B=n;B<=a;B++)T.add(B);for(const B of this.paintedOverlayRows)ms(T,B-c,this.rows);for(const B of g.keys())ms(T,B-c,this.rows);this.paintedCursorRow>=0&&ms(T,this.paintedCursorRow,this.rows),x&&ms(T,x.y,this.rows);for(const B of this.cells.fades.rows(this.cols))ms(T,B,this.rows);let A=0;for(const B of T){this.cells.loadRow(r.lines.get(c+B),g.get(B+c));const L=B===m?{start:f.startCol,end:f.endCol}:null;A+=this.cells.paintRow(B,x,L,s)}this.cells.fades.size>0&&this.requestAbsoluteRows([...this.cells.fades.rows(this.cols)].map(B=>B+c)),(w||this.slidingCaret)&&(this.slidingCaret=w,this.redrawDecor(),w&&this.requestAbsoluteRows([w.y+c])),this.paintedOverlayRows=new Set(g.keys()),this.paintedCursorRow=x?x.y:-1,this.stats.frames++,this.stats.lastCells=A,this.stats.lastPaintMs=this.now()-s,this.inputAt!==null&&A>0&&(this.stats.lastInputToPaintMs=this.now()-this.inputAt,this.inputAt=null)}cursorState(n){return qT(this.core,this.buffer(),n,{rows:this.rows,cols:this.cols},this.blink.hidden)}restartBlink(){if(this.blink.stop(),this.disposed||!this.core.optionsService.rawOptions.cursorBlink||!this.core._coreBrowserService.isFocused){this.requestCursorRow();return}this.blink.start(),this.requestCursorRow()}requestCursorRow(){if(!this.rows)return;const n=this.buffer(),a=new Set;a.add(n.ybase+n.y),this.paintedCursorRow>=0&&a.add(this.paintedCursorRow+n.ydisp),this.requestAbsoluteRows(a)}redrawDecor(){this.surface.decor.paint({dims:this.dimensions.device,rows:this.rows,cols:this.cols,ydisp:this.buffer().ydisp,colors:this.colors(),focused:this.core._coreBrowserService.isFocused,dpr:this.core._coreBrowserService.dpr,cursorWidth:this.core.optionsService.rawOptions.cursorWidth,caret:this.slidingCaret})}invalidateAll(){this.cells.invalidate(),this.paintedCursorRow=-1}buffer(){return this.core._bufferService.buffer}colors(){return this.core._themeService.colors}requestAbsoluteRows(n){if(!this.rows)return;const a=this.buffer().ydisp;let s=1/0,r=-1/0;for(const c of n){const f=c-a;f<0||f>=this.rows||(s=Math.min(s,f),r=Math.max(r,f))}s<=r&&this.redraw.fire({start:s,end:r})}}function ms(l,n,a){n>=0&&n<a&&l.add(n)}const RM=30,Jy=640,e0=240,ir=1,jM=720*60*60*1e3;function t0(){const l=ws("local",At.rendererProbe);if(!l)return{v:ir,ua:{}};try{const n=JSON.parse(l);return typeof n=="object"&&n!==null&&n.v===ir&&typeof n.ua=="object"&&n.ua!==null?n:{v:ir,ua:{}}}catch{return{v:ir,ua:{}}}}function OM(l,n=Date.now()){const a=t0();a.ua[l]={failedAt:n},Li("local",At.rendererProbe,JSON.stringify(a))}function DM(l,n=Date.now()){const a=typeof navigator<"u"?navigator.userAgent:"";if(!a)return!1;const r=t0().ua[a];return!(!r||typeof r.failedAt!="number"||n-r.failedAt>jM)}function rb(l,n=Date.now()){const a=typeof navigator<"u"?navigator.userAgent:"";a&&OM(a,n)}function zM(l){if(l.length<4)return!0;const n=l[0],a=l[1],s=l[2],r=l[3];for(let c=4;c<l.length;c+=4)if(l[c]!==n||l[c+1]!==a||l[c+2]!==s||l[c+3]!==r)return!1;return!0}function HM(l){if(!l||l.width<=0||l.height<=0)return console.debug("Canvas probe inconclusive: text layer canvas missing or zero dimensions"),"inconclusive";let n=null;try{n=l.getContext("2d",{willReadFrequently:!0})||l.getContext("2d")}catch(r){return console.debug("Canvas probe inconclusive: failed to acquire 2D context:",r),"inconclusive"}if(!n)return console.debug("Canvas probe inconclusive: 2D context is null"),"inconclusive";const a=Math.min(l.width,Jy),s=Math.min(l.height,e0);if(a<=0||s<=0)return console.debug("Canvas probe inconclusive: calculated sample dimensions are zero"),"inconclusive";try{const r=n.getImageData(0,0,a,s);return zM(r.data)?"blank":"healthy"}catch(r){return console.debug("Canvas probe inconclusive: getImageData threw exception:",r),"inconclusive"}}function cb(l=2){return new Promise(n=>{if(typeof requestAnimationFrame!="function"){setTimeout(n,32);return}let a=l;const s=()=>{a--,a<=0?n():requestAnimationFrame(s)};requestAnimationFrame(s)})}const ad={kind:"dom",canvas:null,dispose:()=>{},verify:async()=>{}};function BM(l,n={}){if(DM())return ad;let a;try{a=Zd.install(l,{isSynchronizing:n.isSynchronizing})}catch(m){return console.debug("Canvas renderer unavailable, using the DOM renderer:",m),rb(),ad}if(!a)return ad;let s=a,r=null;const c=()=>{var p;if(!s)return;rb();const m=s;s=null;try{m.uninstall()}catch{}(p=n.onRendererSwapped)==null||p.call(n,"dom")};return{get kind(){return s?"canvas":"dom"},get canvas(){return s},dispose:()=>{const m=s;s=null;try{m==null||m.dispose()}catch{}},verify:async()=>{if(s)return r||(r=(async()=>{try{const m=s.stats.frames;await cb(2);for(let g=0;g<RM&&s&&s.stats.frames===m;g++)await cb(1);if(!s)return;const p=HM(s.textCanvas);p==="blank"&&s.hasPaintedInk(Jy,e0)?c():p==="blank"?console.debug("Canvas probe inconclusive: uniform, but no character was painted there"):p==="inconclusive"&&console.debug("Canvas probe inconclusive; retaining canvas renderer without blacklisting")}catch(m){console.debug("Canvas probe inconclusive: unexpected error during verify():",m)}finally{r=null}})(),r)}}}function UM(l,n,a){l.writeln(" ___ ___ .___ "),l.writeln(` / | \\ ____ _______| _/______ \x1B[1m${n}\x1B[0m`),l.writeln(`/ ~ \\/ __ \\\\_ __ \\ __/ ___/ \x1B[2m${a}\x1B[0m`),l.writeln("\\ Y / ___/ | | \\/|_ \\___ \\ "),l.writeln(" \\___|_ / \\___ >|__| /___/____ >"),l.writeln(" \\/ \\/ \\/ "),l.writeln("")}var KM=jx(),sd={exports:{}},ub;function IM(){return ub||(ub=1,(function(l,n){(function(a,s){l.exports=s()})(self,(()=>(()=>{var a={6:(f,m)=>{function p(y){try{const v=new URL(y),w=v.password&&v.username?`${v.protocol}//${v.username}:${v.password}@${v.host}`:v.username?`${v.protocol}//${v.username}@${v.host}`:`${v.protocol}//${v.host}`;return y.toLocaleLowerCase().startsWith(w.toLocaleLowerCase())}catch{return!1}}Object.defineProperty(m,"__esModule",{value:!0}),m.LinkComputer=m.WebLinkProvider=void 0,m.WebLinkProvider=class{constructor(y,v,w,x={}){this._terminal=y,this._regex=v,this._handler=w,this._options=x}provideLinks(y,v){const w=g.computeLink(y,this._regex,this._terminal,this._handler);v(this._addCallbacks(w))}_addCallbacks(y){return y.map((v=>(v.leave=this._options.leave,v.hover=(w,x)=>{if(this._options.hover){const{range:S}=v;this._options.hover(w,x,S)}},v)))}};class g{static computeLink(v,w,x,S){const T=new RegExp(w.source,(w.flags||"")+"g"),[A,k]=g._getWindowedLineStrings(v-1,x),E=A.join("");let N;const B=[];for(;N=T.exec(E);){const L=N[0];if(!p(L))continue;const[D,R]=g._mapStrIdx(x,k,0,N.index),[z,K]=g._mapStrIdx(x,D,R,L.length);if(D===-1||R===-1||z===-1||K===-1)continue;const V={start:{x:R+1,y:D+1},end:{x:K,y:z+1}};B.push({range:V,text:L,activate:S})}return B}static _getWindowedLineStrings(v,w){let x,S=v,T=v,A=0,k="";const E=[];if(x=w.buffer.active.getLine(v)){const N=x.translateToString(!0);if(x.isWrapped&&N[0]!==" "){for(A=0;(x=w.buffer.active.getLine(--S))&&A<2048&&(k=x.translateToString(!0),A+=k.length,E.push(k),x.isWrapped&&k.indexOf(" ")===-1););E.reverse()}for(E.push(N),A=0;(x=w.buffer.active.getLine(++T))&&x.isWrapped&&A<2048&&(k=x.translateToString(!0),A+=k.length,E.push(k),k.indexOf(" ")===-1););}return[E,S]}static _mapStrIdx(v,w,x,S){const T=v.buffer.active,A=T.getNullCell();let k=x;for(;S;){const E=T.getLine(w);if(!E)return[-1,-1];for(let N=k;N<E.length;++N){E.getCell(N,A);const B=A.getChars();if(A.getWidth()&&(S-=B.length||1,N===E.length-1&&B==="")){const L=T.getLine(w+1);L&&L.isWrapped&&(L.getCell(0,A),A.getWidth()===2&&(S+=1))}if(S<0)return[w,N]}w++,k=0}return[w,k]}}m.LinkComputer=g}},s={};function r(f){var m=s[f];if(m!==void 0)return m.exports;var p=s[f]={exports:{}};return a[f](p,p.exports,r),p.exports}var c={};return(()=>{var f=c;Object.defineProperty(f,"__esModule",{value:!0}),f.WebLinksAddon=void 0;const m=r(6),p=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function g(y,v){const w=window.open();if(w){try{w.opener=null}catch{}w.location.href=v}else console.warn("Opening link blocked as opener could not be cleared")}f.WebLinksAddon=class{constructor(y=g,v={}){this._handler=y,this._options=v}activate(y){this._terminal=y;const v=this._options,w=v.urlRegex||p;this._linkProvider=this._terminal.registerLinkProvider(new m.WebLinkProvider(this._terminal,w,this._handler,v))}dispose(){var y;(y=this._linkProvider)==null||y.dispose()}}})(),c})()))})(sd)),sd.exports}var FM=IM(),GM=Ox();function YM({fontSize:l,fontFamily:n,theme:a,cols:s,rows:r}){const c=new GM.Terminal({fontSize:l,fontFamily:n,lineHeight:1.15,...a?{theme:{...a}}:{},allowProposedApi:!0,convertEol:!0,scrollback:5e3,cols:s,rows:r,screenReaderMode:!1,linkHandler:{activate:(f,m)=>{Ed(m)}}});try{const f=new KM.Unicode11Addon;c.loadAddon(f),c.unicode.activeVersion="11"}catch(f){console.debug("Unicode11 addon unavailable, using default width table:",f)}try{c.loadAddon(new FM.WebLinksAddon((f,m)=>{Ed(m)}))}catch(f){console.debug("WebLinks addon unavailable, URLs stay plain text:",f)}return c}function ps(l){var n,a;if(!l)return!1;try{const s=l.modes;if(s&&typeof s.mouseTrackingMode=="string"&&s.mouseTrackingMode!=="none")return!0;const r=l._core;if((n=r==null?void 0:r._coreMouseService)!=null&&n.areMouseEventsActive||(a=r==null?void 0:r.coreMouseService)!=null&&a.areMouseEventsActive||r!=null&&r.mouseMode&&r.mouseMode!=="none")return!0}catch{}return!1}function PM(l,n){const a=n.button??0,s=n.buttons??(l==="mouseup"?0:1);return new MouseEvent(l,{bubbles:!0,cancelable:!0,clientX:n.clientX,clientY:n.clientY,screenX:n.clientX,screenY:n.clientY,button:a,buttons:s})}function n0(l,n,a){const s=PM(n,a);return l.dispatchEvent(s)}function i0(l){var n;try{return((n=l.buffer)==null?void 0:n.active)||null}catch{return null}}function od(l){var a;const n=(a=i0(l))==null?void 0:a.viewportY;return typeof n=="number"&&Number.isFinite(n)?n:null}function $M(l){var n;try{(n=l.blur)==null||n.call(l)}catch{}}function db(l){var a,s;const n=l;return n.coreMouseService||((a=n._core)==null?void 0:a.coreMouseService)||((s=n._core)==null?void 0:s._coreMouseService)||null}function VM(l){var a;const n=l;return n.coreService||((a=n._core)==null?void 0:a.coreService)||null}class qM{constructor(n){this.options=n}getLogicalCoordinates(n,a){const s=this.options.getScale?this.options.getScale():1,r=this.options.getSurfaceElement?this.options.getSurfaceElement():null;if(s!==1&&r&&typeof r.getBoundingClientRect=="function"){const c=r.getBoundingClientRect();return qy(n,a,c,s)}return{clientX:n,clientY:a}}getViewportElement(n){var r;const a=this.options.getSurfaceElement?this.options.getSurfaceElement():null;return(a==null?void 0:a.querySelector(".xterm-viewport"))||((r=n.element)==null?void 0:r.querySelector(".xterm-viewport"))||null}isInputLineHit(n,a){var E;const s=(E=a.buffer)==null?void 0:E.active,r=this.options.getSurfaceElement?this.options.getSurfaceElement():null,c=(r==null?void 0:r.querySelector(".xterm-screen"))||a.element||r,f=rl(a);if(!c||typeof c.getBoundingClientRect!="function"||f.cellHeight<=0)return!1;const m=c.getBoundingClientRect(),p=this.getLogicalCoordinates(n.clientX,n.clientY),g=m.width>0&&m.height>0;if(![s==null?void 0:s.cursorY,s==null?void 0:s.viewportY,s==null?void 0:s.baseY].every(N=>typeof N=="number"&&Number.isFinite(N)))return!1;const v=s==null?void 0:s.cursorY,w=s==null?void 0:s.viewportY,S=(s==null?void 0:s.baseY)+v-w,T=m.top+S*f.cellHeight,A=T+f.cellHeight,k=Number(a.rows);return S>=0&&(!Number.isFinite(k)||S<k)&&p.clientY>=T-2&&p.clientY<=A+2&&(!g||p.clientX>=m.left&&p.clientX<=m.right)}resolveDispatchTarget(n,a){var m;const s=this.options.getSurfaceElement?this.options.getSurfaceElement():null,r=(s==null?void 0:s.querySelector(".xterm-screen"))||a.querySelector(".xterm-screen")||null,c=((m=r==null?void 0:r.closest)==null?void 0:m.call(r,".xterm"))||null;let f=null;return typeof document<"u"&&typeof document.elementFromPoint=="function"&&(f=document.elementFromPoint(n.clientX,n.clientY)),f&&c&&(f===c||c.contains(f))?f:r||s||a}getMouseReport(n,a){const s=this.options.getSurfaceElement?this.options.getSurfaceElement():null,r=(s==null?void 0:s.querySelector(".xterm-screen"))||a.element;if(!r||typeof r.getBoundingClientRect!="function")return null;const c=r.getBoundingClientRect(),f=this.getLogicalCoordinates(n.clientX,n.clientY),m=rl(a);if(m.cellWidth<=0||m.cellHeight<=0)return null;const p=Math.max(1,c.width||a.cols*m.cellWidth),g=Math.max(1,c.height||a.rows*m.cellHeight),y=Math.max(0,Math.min(p-1,f.clientX-c.left)),v=Math.max(0,Math.min(g-1,f.clientY-c.top)),w=Math.max(0,Math.min(a.cols-1,Math.floor(y/m.cellWidth))),x=Math.max(0,Math.min(a.rows-1,Math.floor(v/m.cellHeight)));return{col:w,row:x,x:Math.floor(y),y:Math.floor(v),button:0,action:0}}getWheelDispatchTarget(n){const a=this.options.getSurfaceElement?this.options.getSurfaceElement():null;return(a==null?void 0:a.querySelector(".xterm"))||n.element||null}dispatchWheel(n,a,s,r){const c=this.getWheelDispatchTarget(s);if(!c||typeof WheelEvent>"u"||a===0)return!1;const f=this.getLogicalCoordinates(n.clientX,n.clientY),m=a<0?-1:1;let p=0;for(let g=0;g<Math.abs(a);g+=1)try{const y=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,clientX:f.clientX,clientY:f.clientY,deltaX:0,deltaY:m,deltaMode:1,ctrlKey:!!(r!=null&&r.ctrlKey),altKey:!!(r!=null&&r.altKey),shiftKey:!!(r!=null&&r.shiftKey)});c.dispatchEvent(y),p+=1}catch{return p>0}return p>0}emitWheel(n,a,s,r){if(a===0)return!1;if(this.dispatchWheel(n,a,s,r))return!0;const c=db(s);if(!(c!=null&&c.triggerMouseEvent))return!1;let f=0;for(let m=0;m<Math.abs(a);m+=1){const p=this.getMouseReport(n,s);p&&(p.button=4,p.action=a<0?0:1,p.ctrl=!!(r!=null&&r.ctrlKey),p.alt=!!(r!=null&&r.altKey),p.shift=!!(r!=null&&r.shiftKey),c.triggerMouseEvent(p)&&(f+=1))}return f>0}scrollAlternateBuffer(n,a,s,r){var f;if(a===0)return"none";const c=ps(s);if(!c&&!this.options.getIsController())return"none";if(this.emitWheel(n,a,s,r))return c?"application-mouse":"application-keys";if(!c){const m=VM(s);if(!(m!=null&&m.triggerDataEvent))return"none";const g=`\x1B${!!((f=m.decPrivateModes)!=null&&f.applicationCursorKeys)?"O":"["}${a<0?"A":"B"}`;return m.triggerDataEvent(g.repeat(Math.abs(a)),!0),"application-keys"}return"none"}emitMouse(n,a,s,r){const c=this.options.getTerminal();if(!c)return;const f=db(c);if(f!=null&&f.triggerMouseEvent){const p=this.getMouseReport(a,c);p&&(p.action=n==="mousedown"?1:n==="mouseup"?0:32,p.ctrl=!!(s!=null&&s.ctrlKey),p.alt=!!(s!=null&&s.altKey),p.shift=!!(s!=null&&s.shiftKey),f.triggerMouseEvent(p));return}if(this.options.allowSyntheticMouseFallback===!1||!r)return;const m=this.getLogicalCoordinates(a.clientX,a.clientY);n0(r,n,{clientX:m.clientX,clientY:m.clientY,button:0,buttons:n==="mouseup"?0:1})}}class XM{constructor(n){$(this,"options");$(this,"state","idle");$(this,"startX",0);$(this,"startY",0);$(this,"lastX",0);$(this,"lastY",0);$(this,"activeTarget",null);$(this,"longPressTimer",null);$(this,"longPressMenuTimer",null);$(this,"capturedPointerId",null);$(this,"captureElement",null);$(this,"scrollRemainderY",0);$(this,"delivery");this.options={longPressDelayMs:500,longPressMenuDelayMs:1e3,dragThresholdPx:8,scrollLineHeightPx:18,...n},this.delivery=new qM(this.options)}getState(){return this.state}setGestureState(n){var a,s;this.state!==n&&(this.state=n,(s=(a=this.options).onGestureStateChange)==null||s.call(a,n))}beginGesture(n,a){this.startX=n.clientX,this.startY=n.clientY,this.lastX=n.clientX,this.lastY=n.clientY,this.setGestureState("pending"),this.scrollRemainderY=0,this.activeTarget=this.delivery.resolveDispatchTarget(n,a),this.clearLongPressTimer(),this.longPressTimer=setTimeout(()=>{var s,r;this.state==="pending"&&(this.setGestureState("longpress"),(r=(s=this.options).onLongPress)==null||r.call(s,{clientX:this.startX,clientY:this.startY}))},this.options.longPressDelayMs),this.longPressMenuTimer=setTimeout(()=>{var s,r;this.longPressMenuTimer=null,this.state==="longpress"&&((r=(s=this.options).onLongPressMenu)==null||r.call(s,{clientX:this.startX,clientY:this.startY}))},this.options.longPressMenuDelayMs)}moveGesture(n,a){var g,y,v,w;if(this.state==="idle")return;const s=n.clientX-this.startX,r=n.clientY-this.startY,c=Math.hypot(s,r);if(this.state==="longpress"){c>(this.options.dragThresholdPx||8)&&this.clearLongPressMenuTimer(),(y=(g=this.options).onSelectionExtend)==null||y.call(g,{clientX:n.clientX,clientY:n.clientY}),a!=null&&a.cancelable&&((v=a.preventDefault)==null||v.call(a));return}if(this.state==="scrolling"){this.scrollGesture(n,a);return}const f=this.options.getTerminal(),m=this.options.getIsController(),p=ps(f);if(!(c<=(this.options.dragThresholdPx||8))){if(this.clearLongPressTimer(),Math.abs(r)>=Math.abs(s)||!p||!m){this.setGestureState("scrolling"),f&&$M(f),this.lastX=n.clientX,this.lastY=this.startY,this.scrollRemainderY=0,this.scrollGesture(n,a);return}if(p&&m){this.state==="pending"&&(this.setGestureState("dragging"),this.delivery.emitMouse("mousedown",{clientX:this.startX,clientY:this.startY},a,this.activeTarget)),this.state==="dragging"&&(this.lastX=n.clientX,this.lastY=n.clientY,this.delivery.emitMouse("mousemove",n,a,this.activeTarget),a!=null&&a.cancelable&&((w=a.preventDefault)==null||w.call(a)));return}this.lastX=n.clientX,this.lastY=n.clientY}}scrollGesture(n,a){var S,T,A;const s=this.options.getTerminal();if(!s)return;const r=n.clientY-this.lastY;this.lastX=n.clientX,this.lastY=n.clientY;const c=rl(s),f=c.measured?c.cellHeight:this.options.scrollLineHeightPx||c.cellHeight||18;this.scrollRemainderY+=r;const m=Math.trunc(this.scrollRemainderY/f),p=-m;let g=!1,y="none";const v=i0(s),w=ps(s);if(p!==0){if((v==null?void 0:v.type)==="alternate")y=this.delivery.scrollAlternateBuffer(n,p,s,a),g=y!=="none";else{const k=od(s);s.scrollLines(p);const E=od(s);y="buffer",g=k===null||E===null||k!==E}this.scrollRemainderY-=m*f}const x=this.delivery.getViewportElement(s);(T=(S=this.options).onGestureScroll)==null||T.call(S,{deltaY:r,lines:p,viewportY:od(s),scrollTop:(x==null?void 0:x.scrollTop)??null,scrollHeight:(x==null?void 0:x.scrollHeight)??null,clientHeight:(x==null?void 0:x.clientHeight)??null,moved:g,bufferType:(v==null?void 0:v.type)||null,baseY:typeof(v==null?void 0:v.baseY)=="number"?v.baseY:null,cursorY:typeof(v==null?void 0:v.cursorY)=="number"?v.cursorY:null,hasScrollback:typeof(v==null?void 0:v.hasScrollback)=="boolean"?v.hasScrollback:null,mouseTracking:w,scrollMode:y}),a!=null&&a.cancelable&&((A=a.preventDefault)==null||A.call(a))}endGesture(n,a){var f,m,p;this.clearLongPressTimer();const s=this.options.getTerminal(),r=this.options.getIsController(),c=ps(s);if(this.state==="pending"){if(c&&r){const y={clientX:this.startX,clientY:this.startY};this.delivery.emitMouse("mousedown",y,a,this.activeTarget),this.delivery.emitMouse("mouseup",y,a,this.activeTarget)}const g={clientX:this.startX,clientY:this.startY};r&&s&&this.delivery.isInputLineHit(g,s)&&((m=(f=this.options).onFocus)==null||m.call(f))}else if(this.state==="dragging"&&c&&r){const g=n??{clientX:this.lastX,clientY:this.lastY};this.delivery.emitMouse("mouseup",g,a,this.activeTarget),a!=null&&a.cancelable&&((p=a.preventDefault)==null||p.call(a))}this.reset()}handlePointerDown(n,a){if(n.pointerType==="mouse")return!1;if(!n.isPrimary)return this.releasePointerCapture(),this.reset(),!1;if(n.cancelable&&n.preventDefault(),this.beginGesture(n,a),n.pointerType!=="touch")try{typeof a.setPointerCapture=="function"&&(a.setPointerCapture(n.pointerId),this.capturedPointerId=n.pointerId,this.captureElement=a)}catch{}return!0}handlePointerMove(n){n.pointerType==="mouse"||this.state==="idle"||this.moveGesture(n,n)}handlePointerUp(n){n.pointerType==="mouse"||this.state==="idle"||(this.releasePointerCapture(),this.endGesture(n,n))}handlePointerCancel(n){n&&n.pointerType==="mouse"||(this.releasePointerCapture(),this.cancelGesture())}handleTouchStart(n,a){if(n.touches.length!==1){this.reset();return}n.cancelable&&n.preventDefault(),this.beginGesture(n.touches[0],a)}handleTouchMove(n){n.touches.length===1&&this.moveGesture(n.touches[0],n)}handleTouchEnd(n){n.cancelable&&n.preventDefault(),this.endGesture(null,n)}handleTouchCancel(){this.cancelGesture()}cancelGesture(){this.clearLongPressTimer();const n=this.options.getTerminal(),a=this.options.getIsController(),s=ps(n);if(this.state==="dragging"&&s&&a&&this.activeTarget){const r=this.delivery.getLogicalCoordinates(this.lastX,this.lastY);n0(this.activeTarget,"mouseup",{clientX:r.clientX,clientY:r.clientY,button:0,buttons:0})}this.reset()}releasePointerCapture(){const n=this.captureElement,a=this.capturedPointerId;if(this.captureElement=null,this.capturedPointerId=null,!(!n||a===null))try{typeof n.releasePointerCapture=="function"&&(typeof n.hasPointerCapture!="function"||n.hasPointerCapture(a))&&n.releasePointerCapture(a)}catch{}}clearLongPressTimer(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressTimer=null),this.clearLongPressMenuTimer()}clearLongPressMenuTimer(){this.longPressMenuTimer&&(clearTimeout(this.longPressMenuTimer),this.longPressMenuTimer=null)}reset(){this.clearLongPressTimer(),this.releasePointerCapture(),this.setGestureState("idle"),this.activeTarget=null}}function ZM({container:l,term:n,isTouchDevice:a,debug:s,getTerminal:r,getIsController:c,getScale:f,getSurfaceElement:m,getSelection:p,onFocus:g}){const y=new XM({getTerminal:r,getIsController:c,getScale:f,getSurfaceElement:m,allowSyntheticMouseFallback:!1,onFocus:()=>{try{n.focus()}catch{}s==null||s(L=>({...L,focused:document.activeElement===n.textarea})),g()},onGestureStateChange:L=>{s==null||s(D=>({...D,state:L}))},onGestureScroll:({deltaY:L,lines:D,viewportY:R,scrollTop:z,scrollHeight:K,clientHeight:V,moved:te,bufferType:Z,baseY:ie,cursorY:re,hasScrollback:ce,mouseTracking:O,scrollMode:J})=>{s==null||s(I=>({...I,deltaY:L,lines:D,viewportY:R,scrollTop:z,scrollHeight:K,clientHeight:V,moved:te,focused:document.activeElement===n.textarea,bufferType:Z,baseY:ie,cursorY:re,hasScrollback:ce,mouseTracking:O,scrollMode:J,scrollCalls:I.scrollCalls+(D!==0?1:0),lastScrollLines:D}))},longPressDelayMs:500,longPressMenuDelayMs:1e3,dragThresholdPx:8,scrollLineHeightPx:18,onLongPress:a?L=>p().handleLongPress(L):void 0,onLongPressMenu:a?()=>p().openMenuAtGesture():void 0,onSelectionExtend:a?L=>p().handleSelectionExtend(L):void 0}),v=typeof window<"u"&&"PointerEvent"in window,w=typeof TouchEvent<"u",x=[],S={passive:!1,capture:!0},T=(L,D)=>{document.addEventListener(L,D,S),x.push(()=>document.removeEventListener(L,D,S))},A=(L,D=!1)=>{const R=L.target;return R instanceof Node&&l.contains(R)||D&&y.getState()!=="idle"},k=(L,D)=>{s==null||s(R=>({...R,[L]:R[L]+1,lastInputEvent:D}))},E=L=>{const D=p();return D.hasOpenMenu()?(D.clearSelection(),L.cancelable&&L.preventDefault(),L.stopPropagation(),!0):!1},N=()=>{const L=p();y.getState()==="longpress"&&L.hasSelectionExtension()&&!L.hasOpenMenu()&&L.openMenuAtGesture()};if(v){if(T("pointerdown",L=>{if(!A(L)||(k("pointerEvents","pointerdown"),E(L)))return;y.handlePointerDown(L,l)&&L.stopPropagation()}),T("pointermove",L=>{A(L,!0)&&(k("pointerEvents","pointermove"),y.handlePointerMove(L),L.pointerType!=="mouse"&&L.stopPropagation())}),T("pointerup",L=>{A(L,!0)&&(k("pointerEvents","pointerup"),N(),y.handlePointerUp(L),L.pointerType!=="mouse"&&L.stopPropagation())}),T("pointercancel",L=>{A(L,!0)&&(k("pointerEvents","pointercancel"),p().clearSelection(),y.handlePointerCancel(L),L.pointerType!=="mouse"&&L.stopPropagation())}),w){const L=D=>{A(D,!0)&&(s==null||s(R=>({...R,touchEvents:R.touchEvents+1})),D.cancelable&&D.preventDefault(),D.stopPropagation())};for(const D of["touchstart","touchmove","touchend","touchcancel"])T(D,L)}}else T("touchstart",L=>{A(L)&&(k("touchEvents","touchstart"),!E(L)&&(L.touches.length===1&&L.stopPropagation(),y.handleTouchStart(L,l)))}),T("touchmove",L=>{A(L,!0)&&(k("touchEvents","touchmove"),L.touches.length===1&&L.stopPropagation(),y.handleTouchMove(L))}),T("touchend",L=>{A(L,!0)&&(k("touchEvents","touchend"),N(),L.stopPropagation(),y.handleTouchEnd(L))}),T("touchcancel",L=>{A(L,!0)&&(k("touchEvents","touchcancel"),p().clearSelection(),L.stopPropagation(),y.handleTouchCancel())});const B=L=>{L.preventDefault()};return l.addEventListener("contextmenu",B),x.push(()=>l.removeEventListener("contextmenu",B)),()=>{y.handlePointerCancel();for(const L of x)L()}}function WM(l,{requestFit:n,onPageVisible:a}){const s=new ResizeObserver(()=>{n()});s.observe(l);const r=()=>{n()},c=()=>{document.visibilityState==="visible"&&a()};window.addEventListener("resize",r),window.addEventListener("orientationchange",r),document.addEventListener("visibilitychange",c),window.addEventListener("pageshow",c);const f=()=>{n()};return typeof window<"u"&&window.visualViewport&&(window.visualViewport.addEventListener("resize",f),window.visualViewport.addEventListener("scroll",f)),()=>{s.disconnect(),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),document.removeEventListener("visibilitychange",c),window.removeEventListener("pageshow",c),typeof window<"u"&&window.visualViewport&&(window.visualViewport.removeEventListener("resize",f),window.visualViewport.removeEventListener("scroll",f))}}function tl(l){if(l)try{l.refresh(0,Math.max(0,l.rows-1))}catch{}}function QM({containerRef:l,surfaceRef:n,termRef:a,rendererRef:s,currentScaleRef:r,initialBannerWrittenRef:c,live:f,selection:m,prediction:p,fit:g,isTouchDevice:y,debug:v,terminalFontSize:w,terminalFontFamily:x,hostTheme:S,glyphRevision:T,terminalResetVersion:A,isActive:k,subscribeToOutput:E,onOutput:N,onTitle:B,onRendererKind:L}){const{requestFit:D,scheduleBoundedFit:R,fitNow:z,seedFit:K,cancelPendingFits:V}=g;M.useEffect(()=>{var tt,Je;if(!l.current||!n.current)return;const Z=l.current,ie=Rd(Z,oa(),pd()),re=rl(null,fa),ce=Vy({width:ie.width,height:ie.height,cellWidth:re.cellWidth,cellHeight:re.cellHeight});f.current.sendResize(ce.cols,ce.rows),K(ie);const O=YM({fontSize:dg(w,ie.width),fontFamily:x,theme:f.current.hostTheme,cols:ce.cols,rows:ce.rows});O.open(n.current),a.current=O;const J=O.onTitleChange(Se=>{B(Ad(Se)||null)}),{screenState:I,fieldProbe:le,overlay:P}=p.attach(O);y&&O.textarea&&(O.textarea.readOnly=!1,O.textarea.tabIndex=0,O.textarea.inputMode="text");let fe=()=>{};if(v&&O.textarea){const Se=()=>{v(Me=>({...Me,focused:document.activeElement===O.textarea}))};O.textarea.addEventListener("focus",Se),O.textarea.addEventListener("blur",Se),fe=()=>{var Me,ot;(Me=O.textarea)==null||Me.removeEventListener("focus",Se),(ot=O.textarea)==null||ot.removeEventListener("blur",Se)},Se()}const ve=async Se=>{p.discard("paste");const Me=_y(Se);if(Me){if(Se.preventDefault(),Se.stopPropagation(),!f.current.isController){f.current.warnViewerMode();return}await f.current.uploadImage(Me)}};(tt=O.textarea)==null||tt.addEventListener("paste",ve),Z.addEventListener("paste",ve);const X=BM(O,{isSynchronizing:I.isSynchronizing,onRendererSwapped:Se=>{var Me;Z.dataset.renderer=Se,L(Se),(Me=p.overlayRef.current)==null||Me.attach(null),tl(O)}});P.attach(X.canvas),(Je=X.canvas)==null||Je.setTypingZoneProvider(()=>{const Se=le.detect();return Se&&{row:Se.row,startCol:Se.startCol,endCol:Se.endCol}});const ue=I.onSyncEnd(()=>{var Se,Me;return(Me=(Se=s.current)==null?void 0:Se.canvas)==null?void 0:Me.flushHeld()});if(s.current=X,Z.dataset.renderer=X.kind,L(X.kind),UM(O,f.current.t("terminal.bannerTitle"),f.current.t("terminal.bannerSubtitle")),c.current=!0,O.write("",()=>void X.verify()),!y)try{O.focus()}catch{}const oe=typeof document<"u"?document.fonts:void 0;typeof(oe==null?void 0:oe.load)=="function"&&oe.load('13px "Symbols Nerd Font Mono"').then(()=>{a.current&&(tl(a.current),R(5))}).catch(()=>{});const pe=O.onData(Se=>{const{isController:Me}=f.current;let ot=Se;if(Me&&Iy(Se)==="keys"&&$x(Se)){const bt=f.current.consumeModifierLatch();bt&&(ot=sr(Se,bt))}const nt=zd(ot);if(!Me&&!cr(nt)){f.current.warnViewerMode();return}p.onUserInput(nt),f.current.sendBinary(nt)}),se=O.onBinary(Se=>{const Me=new Uint8Array(Se.length);for(let ot=0;ot<Se.length;ot++)Me[ot]=Se.charCodeAt(ot)&255;!f.current.isController&&!cr(Me)||f.current.sendBinary(Me)}),xe=typeof O.onWriteParsed=="function"?O.onWriteParsed(()=>{var bt;if(m.current.onTerminalContentChanged(),le.invalidate(),I.isSynchronizing())return;const Se=O.buffer.active,Me=Se.baseY+Se.cursorY,ot=Array.from({length:8},(yn,vn)=>{var Nn;return((Nn=Se.getLine(Me-7+vn))==null?void 0:Nn.translateToString(!0))??""}),nt=Yw(ot,f.current.platform);nt&&f.current.reportShellProfile(nt),(bt=p.predictorRef.current)==null||bt.onServerOutput(),p.sync()}):{dispose:()=>{}},ae=typeof O.onRender=="function"?O.onRender(Se=>{var Me;if(f.current.glyphScan){const ot=O.buffer.active.viewportY??0;let nt="";for(let bt=Se.start;bt<=Se.end;bt+=1)nt+=((Me=O.buffer.active.getLine(ot+bt))==null?void 0:Me.translateToString(!0))??"";/[^\x00-\x7f]/.test(nt)&&f.current.ensureHostGlyphs(nt)}m.current.onTerminalRender(O,Se.start,Se.end)}):{dispose:()=>{}},we=typeof O.onScroll=="function"?O.onScroll(()=>{m.current.onTerminalScroll(O),p.discard("scroll")}):{dispose:()=>{}},ke=ZM({container:Z,term:O,isTouchDevice:y,debug:v,getTerminal:()=>a.current,getIsController:()=>f.current.isController,getScale:()=>r.current,getSurfaceElement:()=>n.current,getSelection:()=>m.current,onFocus:()=>{var Se,Me;return(Me=(Se=f.current).onTerminalFocus)==null?void 0:Me.call(Se)}}),Ie=WM(Z,{requestFit:D,onPageVisible:()=>{R(10),tl(a.current)}});return()=>{var Se;pe.dispose(),se.dispose(),ae.dispose(),we.dispose(),xe.dispose(),J.dispose(),ue.dispose(),p.detach(),I.dispose(),ke(),Ie(),V(),fe(),(Se=O.textarea)==null||Se.removeEventListener("paste",ve),Z.removeEventListener("paste",ve),X.dispose(),s.current=null,O.dispose(),a.current=null}},[]),M.useEffect(()=>{const Z=a.current;if(!Z)return;const ie=Rd(l.current,oa(),pd()),re=dg(w,ie.width),ce=Z.options.fontSize!==re||Z.options.fontFamily!==x;Z.options.fontSize=re,Z.options.fontFamily=x,tl(Z),ce&&z(),R(10)},[w,x]),M.useEffect(()=>{var ie,re;const Z=a.current;!Z||!T||((re=(ie=s.current)==null?void 0:ie.canvas)==null||re.clearTextureAtlas(),tl(Z))},[T]);const te=M.useRef(A);M.useEffect(()=>{var ie;if(te.current===A)return;te.current=A,p.forget("resetVersion");const Z=a.current;if(Z)try{(ie=Z.reset)==null||ie.call(Z),Z.clear(),Z.refresh(0,Math.max(0,Z.rows-1))}catch{}},[A]),M.useEffect(()=>{const Z=a.current;!Z||!S||(Z.options.theme={...S},tl(Z))},[S]),M.useEffect(()=>E(ie=>{const re=a.current;if(!re)throw new Error("terminal not ready");re.write(ie),N==null||N(ie.byteLength)}),[E,a,N]),M.useEffect(()=>{if(!k)return;R(10);const Z=a.current;if(Z&&(tl(Z),!y))try{Z.focus()}catch{}},[k,y,R,a])}const JM=({onTerminalFocus:l,isActive:n=!0})=>{var Nn;const a=M.useRef(null),s=M.useRef(null),r=M.useRef(null),c=M.useRef(null),f=M.useRef(null),m=M.useRef(1),p=M.useRef(null),g=M.useRef(!1),y=fw(),v=y||typeof navigator<"u"&&navigator.maxTouchPoints>0||typeof window<"u"&&"ontouchstart"in window,w=yC(),[x,S]=M.useState(bC),{metrics:T,record:A}=vC(w),[k,E]=M.useState(null),{settings:N,terminalFontFamily:B,terminalFontSize:L,hostFont:D,ensureHostGlyphs:R,profiles:z,activeProfileId:K,t:V}=Ee(),{isController:te,connectionState:Z,hostPalette:ie,herdrPrefixKeys:re,terminalResetVersion:ce,agentStatus:O,platform:J,reportShellProfile:I,connect:le,rttMs:P}=it(),{addToast:fe}=dn(),{sendResize:ve,sendBinary:X,observeKeyInput:ue,consumeModifierLatch:oe,warnViewerMode:pe,subscribeToOutput:se,subscribeToPasteFileReady:xe}=Sr(),{uploadImage:ae}=Cr(),we=Jn.useMemo(()=>Sw(ie),[ie]),ke=En({isController:te,sendBinary:X,sendResize:ve,warnViewerMode:pe,uploadImage:ae,t:V,consumeModifierLatch:oe,hostTheme:we,onTerminalFocus:l,ensureHostGlyphs:R,glyphScan:D.glyphs.status==="ready",platform:J,reportShellProfile:I}),Ie=En(n),tt=kT({termRef:f,rendererRef:p,mode:N.predictiveEcho,connectionState:Z,observeKeyInput:ue,herdrPrefixKeys:re}),[Je,Se]=M.useState(null),Me=PT({termRef:f,surfaceRef:r,mainRef:c,currentScaleRef:m,addToast:fe,t:V}),ot=En(Me),nt=TC({termRef:f,isController:te,warnViewerMode:pe,uploadImage:ae,addToast:fe,t:V,onPaste:()=>tt.discard("paste"),subscribeToPasteFileReady:xe}),bt=zT({termRef:f,containerRef:a,frameRef:s,surfaceRef:r,currentScaleRef:m,rendererRef:p,initialBannerWrittenRef:g,isActiveRef:Ie,sendResize:ve,onResized:()=>tt.forget("resize")});QM({containerRef:a,surfaceRef:r,termRef:f,rendererRef:p,currentScaleRef:m,initialBannerWrittenRef:g,live:ke,selection:ot,prediction:tt,fit:bt,isTouchDevice:y,debug:w?S:null,terminalFontSize:L,terminalFontFamily:B,hostTheme:we,glyphRevision:D.glyphRevision,terminalResetVersion:ce,isActive:n,subscribeToOutput:se,onOutput:w?A:null,onTitle:Se,onRendererKind:E});const yn=Jn.useMemo(()=>{var qt;return((qt=z.find(ut=>ut.id===K))==null?void 0:qt.displayName)??null},[z,K]);M.useEffect(()=>{Z!=="connected"&&Se(null)},[Z]),M.useEffect(()=>{const qt=n&&Z==="connected",ut=N.agentAlertBadge?Ts(O):null;lC(qt?Je:null,yn,ut)},[n,Z,Je,yn,O,N.agentAlertBadge]),M.useEffect(()=>{Z==="disconnected"&&le()},[]);const vn=qt=>{qt.preventDefault()};return h.jsxs("main",{ref:c,className:"flex-1 w-full min-w-0 min-h-0 overflow-hidden relative flex flex-col",onContextMenu:vn,"aria-label":V("terminal.windowAriaLabel"),children:[h.jsx("div",{id:"terminal-container",ref:a,className:"absolute inset-0 overflow-hidden cursor-text",style:{touchAction:v?"none":"auto"},tabIndex:0,onContextMenu:vn,"aria-label":V("terminal.bufferAriaLabel"),role:"region",children:h.jsx("div",{id:"terminal-frame",ref:s,className:"relative overflow-hidden",style:{width:"100%",height:"100%"},children:h.jsx("div",{id:"terminal-surface",ref:r,className:"absolute top-0 left-0",style:{transformOrigin:"top left",width:"100%",height:"100%"}})})}),w&&h.jsx(CC,{debug:x,rttMs:P,metrics:T,rendererKind:k,predictiveEcho:N.predictiveEcho,predictor:tt.predictorRef.current,field:((Nn=tt.fieldProbeRef.current)==null?void 0:Nn.detect())??null,renderer:p.current}),y&&Me.selectionRect&&Me.isHighlightVisible&&h.jsx($T,{term:f.current,surface:r.current,main:c.current,rect:Me.selectionRect,viewportY:Me.viewportY}),y&&Me.selectionMenu&&h.jsx(gC,{anchorPoint:Me.selectionMenu,hasSelection:!!Me.selectionSnapshot,isController:te,vibrateOnKeyPress:N.vibrateOnKeyPress,linkUrl:Me.selectionMenu.link??null,onOpenLink:qt=>{Ed(qt)||fe("warning",V("clipboard.openLinkFailed"))},onCopySelection:Me.handleCopySelection,onCopyLine:Me.handleCopyLine,onCopyScreen:Me.handleCopyScreen,onPaste:nt.handlePaste,onClose:Me.clearSelection}),y&&nt.isPasteFallbackOpen&&h.jsx(pC,{isOpen:nt.isPasteFallbackOpen,onClose:nt.closePasteFallback,onSend:nt.handleFallbackPasteSend,onSendImage:nt.handleFallbackImageSend})]})},e5=2e3;function Wd(){const{t:l}=Ee(),{addToast:n}=dn(),[a,s]=M.useState(null),r=M.useRef(null);M.useEffect(()=>()=>{r.current&&clearTimeout(r.current)},[]);const c=M.useCallback((f,m,p="success")=>{qd(f).then(g=>{if(g==="failed"){n("error",l("clipboard.copyFailed"));return}s(f),n(p,m),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>s(null),e5)})},[n,l]);return{copied:a,copy:c}}const il="herdr-remote pair",fb="herdr-remote",t5=({onPairedSuccess:l})=>{const{settings:n,updateSettings:a,t:s}=Ee(),{connect:r,connectionState:c,stateDetail:f}=it(),{addToast:m}=dn(),[p,g]=M.useState(""),{copied:y,copy:v}=Wd(),[w,x]=M.useState(!1),[S,T]=M.useState(n.wsUrl||Ut),[A,k]=M.useState(n.token||""),[E,N]=M.useState(n.clientId||""),B=z=>v(z,s("toasts.commandCopied")),L=z=>{z.preventDefault();const K=p.trim().toUpperCase();if(!K&&!A.trim()){m("warning",s("toasts.connectionError"));return}const V={pairCode:K,wsUrl:S.trim()||Ut,clientId:E.trim()||n.clientId};A.trim()&&(V.token=A.trim()),a(V),r({pairCode:K||void 0,token:A.trim()||void 0,wsUrl:S.trim()||Ut,clientId:E.trim()||n.clientId}),l&&l()},D=c==="connecting"||c==="reconnecting",R=({n:z})=>h.jsxs("span",{"aria-hidden":"true",className:"shrink-0 font-bold text-tui-accent",children:["[",z,"]"]});return h.jsx("div",{className:"flex h-full w-full flex-1 justify-center overflow-y-auto bg-tui-crust p-2 sm:p-4",children:h.jsxs("div",{className:"my-auto w-full max-w-3xl space-y-3",children:[h.jsxs("div",{className:"border border-tui-border bg-tui-base px-3 py-2",children:[h.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[h.jsx("span",{"aria-hidden":"true",className:"font-bold text-tui-accent",children:"herdr-remote"}),h.jsx("h1",{className:"text-tui font-bold text-tui-text",children:s("onboarding.title")}),h.jsx("span",{className:"text-tui uppercase text-tui-warn",children:s("onboarding.firstTimeSetup")})]}),h.jsx("p",{className:"mt-0.5 text-tui leading-snug text-tui-muted",children:s("onboarding.description")})]}),c==="error"&&h.jsxs(Ri,{tone:"warn",action:h.jsx(Ae,{variant:"warn",onClick:()=>r(),children:s("common.retry")}),children:[h.jsx("span",{className:"block font-bold",children:s("onboarding.authRequired")}),h.jsx("span",{className:"block text-tui-muted",children:f||s("onboarding.authRequiredDesc")})]}),h.jsxs("form",{onSubmit:L,className:"grid gap-3",children:[h.jsx(Et,{title:s("onboarding.step1Title"),className:"min-w-0",children:h.jsxs("div",{className:"space-y-2",children:[h.jsxs("p",{className:"flex items-start gap-2 text-tui text-tui-muted",children:[h.jsx(R,{n:1}),h.jsx("span",{className:"leading-snug",children:s("onboarding.step1Desc")})]}),h.jsxs("div",{className:"flex items-center gap-2 border border-tui-border bg-tui-mantle px-2 py-1",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 select-none text-tui-ok",children:"$"}),h.jsx("code",{className:"min-w-0 flex-1 truncate text-tui text-tui-text",children:il}),h.jsx(Ae,{onClick:()=>B(il),glyph:y===il?_e.check:"⧉",className:ne("shrink-0",y===il&&"border-tui-ok text-tui-ok"),children:s(y===il?"common.copied":"common.copy")})]}),h.jsx("div",{className:"space-y-0.5 text-tui-sm",children:h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsx("span",{className:"truncate text-tui-faint",children:s("onboarding.step1TuiNote")}),h.jsx("button",{type:"button",onClick:()=>B(fb),className:"shrink-0 cursor-pointer border border-tui-border-dim px-1 text-tui-muted hover:border-tui-accent hover:text-tui-accent",title:s("common.clickToCopy"),children:h.jsx("code",{children:fb})})]})})]})}),h.jsx(Et,{title:s("onboarding.step2Title"),className:"min-w-0",children:h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(R,{n:2}),h.jsx(un,{type:"text",value:p,onChange:z=>g(z.target.value.toUpperCase()),placeholder:s("onboarding.step2Placeholder"),maxLength:12,autoFocus:!0,"aria-label":s("onboarding.step2Title"),className:"font-bold uppercase"})]}),h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:s("onboarding.step2Note")})]})}),h.jsx(Ae,{variant:"primary",type:"submit",block:!0,disabled:D,className:"py-1.5",children:D?h.jsx(ol,{label:s("onboarding.connectingAndPairing")}):s("onboarding.connectAndPair")}),h.jsxs("div",{className:"border border-tui-border bg-tui-base",children:[h.jsxs("button",{type:"button",onClick:()=>x(!w),"aria-expanded":w,className:"tui-focusable flex w-full items-center gap-2 px-2 py-1 text-left text-tui text-tui-muted transition-colors hover:text-tui-accent",children:[h.jsx("span",{"aria-hidden":"true",className:"text-tui-accent",children:w?_e.chevronDown:_e.chevronRight}),h.jsx("span",{className:"uppercase",children:s("onboarding.advancedTitle")})]}),w&&h.jsxs("div",{className:"space-y-2.5 border-t border-tui-border-dim px-2 py-2",children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"onboarding-token",children:s("onboarding.manualTokenLabel")}),h.jsx(un,{id:"onboarding-token",type:"password",value:A,onChange:z=>k(z.target.value),placeholder:s("onboarding.manualTokenPlaceholder")})]}),h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"onboarding-ws",children:s("onboarding.wsEndpointLabel")}),h.jsx(un,{id:"onboarding-ws",type:"text",value:S,onChange:z=>T(z.target.value),placeholder:s("onboarding.wsEndpointPlaceholder")})]}),h.jsx($S,{}),h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"onboarding-client-id",children:s("onboarding.clientIdLabel")}),h.jsx(un,{id:"onboarding-client-id",type:"text",value:E,onChange:z=>N(z.target.value)})]})]})]})]})]})})},ei="tui-focusable inline-flex shrink-0 select-none items-center justify-center gap-1 whitespace-nowrap border text-tui font-medium transition-colors",Ns="border-tui-border bg-tui-surface text-tui-text hover:border-tui-accent hover:text-tui-accent active:bg-tui-selection",n5="border-tui-accent bg-tui-accent text-tui-crust font-bold",i5="border-tui-ok bg-transparent text-tui-ok hover:bg-tui-ok hover:text-tui-crust font-bold",l0={default:Ns,bad:"border-tui-bad text-tui-bad hover:bg-tui-bad hover:text-tui-crust",warn:"border-tui-warn text-tui-warn hover:bg-tui-warn hover:text-tui-crust"};function l5(l){return{capHeight:l?"h-8":"h-7",keyClass:l?"h-8 min-w-[2rem] px-1.5":"h-7 min-w-[1.75rem] px-1.5",squareKeyClass:l?"h-8 w-8":"h-7 w-7",drawerToggleClass:l?"h-8 px-1.5":"h-7 px-1.5"}}const a5={left:{glyph:"󰜱",box:[0,660,34,686]},up:{glyph:"󰜷",box:[0,652,30,690]},down:{glyph:"󰜮",box:[0,652,30,690]},right:{glyph:"󰜴",box:[0,660,34,686]},enter:{glyph:"󱞦",box:[0,709,-36,756]},backspace:{glyph:"󰁮",box:[0,1e3,-15,735]},shift:{glyph:"󰘶",box:[0,832,26,694]},open:{glyph:"󰍠",box:[91,509,256,464]},close:{glyph:"󰍝",box:[91,509,256,464]},image:{glyph:"󰋩",box:[0,750,-15,735]},customize:{glyph:"󰙪",box:[0,750,-15,735]},admin:{glyph:"󰢏",box:[0,750,-99,819]}},s5={"←":"left","↑":"up","↓":"down","→":"right","⏎":"enter","⌫":"backspace","⇧":"shift"},o5=.9,r5=.86,rd=1e3;function c5([l,n,a,s]){const r=o5*rd/Math.max(n-l,s-a),c=(l+n)/2/rd,f=r5-(a+s)/2/rd;return{fontSize:`${r}em`,left:`${(.5-r*c)*100}%`,top:`${(.5-r*f)*100}%`}}function sn({name:l}){const n=a5[l];return h.jsx("span",{"aria-hidden":"true","data-key-icon":l,className:"relative inline-block size-[1em] shrink-0 overflow-visible",children:h.jsx("span",{className:"absolute leading-none",style:c5(n.box),children:n.glyph})})}function a0({text:l}){return h.jsx("span",{className:"inline-flex items-center",children:[...l].map((n,a)=>{const s=s5[n];return s?h.jsx(sn,{name:s},a):n})})}function u5({keyClass:l,squareKeyClass:n,onCustomize:a,sendCombo:s}){const{settings:r,t:c}=Ee(),{agentProfile:f,shellProfile:m}=it(),p=rw(f,r.agentKeymaps[f],m),g=v=>{let w="";try{w=na(v.combo)}catch{}const x=v.custom?v.customLabel||"":c(`agentActions.${v.labelKey}`),S=v.labelKey==="interrupt"&&v.combo.trim().toLowerCase()==="ctrl+c"?"bad":v.combo.trim().toLowerCase()==="ctrl+z"?"warn":"default";return h.jsx("button",{type:"button","data-testid":`agent-key-${v.id}`,onClick:()=>s(v.combo),className:ne(ei,l,"font-bold",l0[S]),title:`${w} ${x}`.trim(),"aria-label":`${w} ${x}`.trim(),children:h.jsx(a0,{text:w||x})},v.id)},y=[...p.agentActions,...p.genericActions];return y.length===0&&!a?null:h.jsxs("div",{"data-testid":"agent-key-actions",role:"group","aria-label":`${nl[f].name} ${c("agentKeymaps.agentGroup")}`,className:"flex shrink-0 items-center gap-1",children:[h.jsx("span",{"aria-hidden":"true",className:"mx-1 h-5 w-px shrink-0 bg-tui-border-dim"}),y.map(g),a&&h.jsx("button",{type:"button","data-testid":"agent-key-customize",onClick:a,className:ne(ei,n,"border-tui-border-dim bg-transparent text-tui-faint hover:border-tui-accent hover:text-tui-accent"),title:c("agentKeymaps.customizeBar"),"aria-label":c("agentKeymaps.customizeBar"),children:h.jsx(sn,{name:"customize"})})]})}const s0="scrollbar-none flex items-center gap-1 overflow-x-auto border-b border-tui-border-dim bg-tui-crust p-1.5";function d5({capHeight:l,onKey:n}){return h.jsx("div",{className:"grid grid-cols-6 gap-1 border-b border-tui-border-dim bg-tui-crust p-1.5 sm:grid-cols-12",children:[1,2,3,4,5,6,7,8,9,10,11,12].map(a=>{const s=`F${a}`;return h.jsxs("button",{type:"button",onClick:()=>n(de[s]),className:ne(ei,Ns,l),children:["F",a]},s)})})}const f5=[{code:de.CTRL_C,caption:"^C",title:"virtualKeyboard.ctrlCTitle",badge:"virtualKeyboard.badgeSigint",tone:"bad"},{code:de.CTRL_D,caption:"^D",title:"virtualKeyboard.ctrlDTitle",badge:"virtualKeyboard.badgeEof"},{code:de.CTRL_Z,caption:"^Z",title:"virtualKeyboard.ctrlZTitle",badge:"virtualKeyboard.badgeTstp",tone:"warn"},{code:de.CTRL_L,caption:"^L",title:"virtualKeyboard.ctrlLTitle",badge:"virtualKeyboard.badgeClear"},{code:de.CTRL_R,caption:"^R",title:"virtualKeyboard.ctrlRTitle",badge:"virtualKeyboard.badgeSearch"},{code:de.CTRL_A,caption:"^A",title:"virtualKeyboard.ctrlATitle",badge:"virtualKeyboard.badgeStart"},{code:de.CTRL_E,caption:"^E",title:"virtualKeyboard.ctrlETitle",badge:"virtualKeyboard.badgeEnd"},{code:de.CTRL_K,caption:"^K",title:"virtualKeyboard.ctrlKTitle",badge:"virtualKeyboard.badgeKill"}];function h5({capHeight:l,onKey:n}){const{t:a}=Ee();return h.jsx("div",{className:s0,children:f5.map(s=>h.jsxs("button",{type:"button",onClick:()=>n(s.code,!1),className:ne(ei,l,"gap-1.5 px-2",l0[s.tone??"default"]),title:a(s.title),children:[h.jsx("span",{className:"font-bold",children:s.caption}),h.jsx("span",{className:"text-tui-sm opacity-70",children:a(s.badge)})]},s.caption))})}const m5=["|","~","/","\\","-","_","$","&",";",":","`",'"',"'",">","<","=","#","@","{","}","[","]"];function p5({squareKeyClass:l,onKey:n}){return h.jsx("div",{className:s0,children:m5.map(a=>h.jsx("button",{type:"button",onClick:()=>n(a,!0),className:ne(ei,Ns,l,"font-bold"),children:a},a))})}const hb="image/png,image/jpeg,image/webp,image/gif,image/*";function mb({fileInputRef:l}){const{uploadImage:n}=Cr(),a=s=>{var c;const r=(c=s.target.files)==null?void 0:c[0];s.target.value="",r&&n(r)};return h.jsxs(h.Fragment,{children:[h.jsx("input",{ref:l,type:"file",accept:hb,className:"hidden","data-testid":"key-toolbar-file-input",onChange:a}),h.jsx("input",{type:"file",accept:hb,capture:"environment",className:"hidden","data-testid":"key-toolbar-camera-input",onChange:a})]})}function pb({collapsed:l}){const{uploadProgress:n}=Cr();return n.active?h.jsx("div",{"data-testid":l?"key-toolbar-progress-collapsed":"key-toolbar-progress",className:"w-full border-b border-tui-border-dim bg-tui-crust px-2 py-1",children:h.jsx(XS,{ratio:n.ratio,label:n.statusText,tone:n.phase==="completed"?"ok":n.phase==="error"?"bad":"accent","aria-label":n.statusText})}):null}function g5({fileInputRef:l,keyClass:n,squareKeyClass:a,vibrate:s}){const{t:r}=Ee(),{isController:c}=it(),{warnViewerMode:f}=Sr(),{uploadProgress:m}=Cr(),p=m.active,g=()=>{var y;if(s(),!c){f();return}p||(y=l.current)==null||y.click()};return h.jsx("button",{type:"button","data-testid":"image-upload-btn",onClick:g,disabled:p,className:ne(ei,p?n:a,p?"border-tui-border-dim bg-tui-surface opacity-60 cursor-not-allowed":Ns),title:p?m.statusText:r("virtualKeyboard.uploadImageTitle"),"aria-label":r("virtualKeyboard.uploadImage"),children:p?h.jsx("span",{children:`${m.percent}%`}):h.jsx(sn,{name:"image"})})}function b5(){const{settings:l}=Ee(),{isController:n}=it(),{sendKey:a,warnViewerMode:s,consumeModifierLatch:r}=Sr(),c=M.useRef([]);M.useEffect(()=>()=>{for(const g of c.current)clearTimeout(g);c.current=[]},[]);const f=M.useCallback(()=>{if(l.vibrateOnKeyPress&&typeof navigator<"u"&&navigator.vibrate)try{navigator.vibrate(8)}catch{}},[l.vibrateOnKeyPress]),m=M.useCallback((g,y=!0)=>{if(f(),!n){s();return}const v=r();a(y&&v?sr(g,v):g)},[n,a,s,f,r]),p=M.useCallback(g=>{if(f(),!n){s();return}let y;try{y=cn(g)}catch{return}if(r(),y.length===1){a(y[0]);return}y.forEach((v,w)=>{const x=setTimeout(()=>{c.current=c.current.filter(S=>S!==x),a(v)},w*120);c.current.push(x)})},[r,n,a,f,s]);return{vibrate:f,pressKey:m,sendCombo:p}}function y5({squareKeyClass:l}){const{platform:n,adminTerminalSupported:a,adapter:s}=it(),{t:r}=Ee();if(n!=="win32")return null;const c=a!==!1;return h.jsx("button",{type:"button","data-testid":"new-admin-terminal",onClick:()=>s==null?void 0:s.sendAdminTabOpen(),disabled:!c,className:ne(ei,l,"border-amber-500/50 bg-amber-500/10 text-amber-200 hover:border-amber-400 hover:bg-amber-500/20 disabled:cursor-not-allowed disabled:opacity-50"),title:r(c?"terminal.adminTerminalSetup":"terminal.adminTerminalUpdate"),"aria-label":r("terminal.newAdminTerminal"),children:h.jsx(sn,{name:"admin"})})}const v5=new Set(["left","up","down","right","enter"]),x5=500,w5=8,S5=({compact:l=!1,onCustomize:n})=>{const{settings:a,updateSettings:s,t:r}=Ee(),{modifierLatch:c,toggleModifierLatch:f}=Sr(),{vibrate:m,pressKey:p,sendCombo:g}=b5(),{capHeight:y,keyClass:v,squareKeyClass:w,drawerToggleClass:x}=l5(l),S=M.useRef(null),T=M.useRef(null),A=M.useRef(null),k=M.useRef(!1);M.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const[E,N]=M.useState(!1),[B,L]=M.useState(!1),[D,R]=M.useState(!1),z=M.useRef(null),[K,V]=M.useState(!1),te=M.useCallback(()=>{const X=z.current;V(!!X&&X.scrollLeft+X.clientWidth<X.scrollWidth-1)},[]);M.useEffect(te),M.useEffect(()=>{const X=z.current;if(!X||typeof ResizeObserver!="function")return;const ue=new ResizeObserver(te);return ue.observe(X),()=>ue.disconnect()},[te,a.toolbarVisible]);const Z=()=>{T.current&&clearTimeout(T.current),T.current=null},ie=(X,ue)=>{const oe=X.modifierType;X.type!=="modifier"||ue.button!==0||oe!=="ctrl"&&oe!=="alt"&&oe!=="shift"||(Z(),k.current=!1,A.current={pointerId:ue.pointerId,clientX:ue.clientX,clientY:ue.clientY,triggered:!1},T.current=setTimeout(()=>{const pe=A.current;!pe||pe.pointerId!==ue.pointerId||(pe.triggered=!0,k.current=!0,c[oe]||f(oe),m())},x5))},re=X=>{const ue=A.current;!ue||ue.pointerId!==X.pointerId||Math.hypot(X.clientX-ue.clientX,X.clientY-ue.clientY)<=w5||(Z(),ue.triggered||(A.current=null))},ce=X=>{const ue=A.current;!ue||ue.pointerId!==X.pointerId||(Z(),A.current=null,ue.triggered&&setTimeout(()=>{k.current=!1},0))},O=X=>{const ue=A.current;!ue||ue.pointerId!==X.pointerId||(Z(),A.current=null,k.current=!1)};if(!a.toolbarVisible)return h.jsxs("div",{"data-testid":"key-toolbar-collapsed",className:"z-20 flex shrink-0 flex-col border-t border-tui-border bg-tui-mantle pb-[max(env(safe-area-inset-bottom,0px),0.125rem)]",children:[h.jsx(mb,{fileInputRef:S}),h.jsx(pb,{collapsed:!0}),h.jsx("div",{className:"flex items-center justify-center px-2 py-0.5",children:h.jsxs("button",{type:"button",onClick:()=>s({toolbarVisible:!0}),className:"tui-focusable flex h-6 w-28 items-center justify-center gap-1 text-tui uppercase text-tui-faint transition-colors hover:text-tui-accent",title:r("virtualKeyboard.expandToolbar"),"aria-label":r("virtualKeyboard.expandToolbar"),"aria-expanded":!1,children:[h.jsx(sn,{name:"open"}),h.jsx("span",{"aria-hidden":"true",children:r("common.keyBar")})]})})]});const J=a.virtualKeys&&a.virtualKeys.length>0?a.virtualKeys.filter(X=>X.enabled):Wb,I=X=>X.id==="left"?h.jsx(sn,{name:"left"}):X.id==="up"?h.jsx(sn,{name:"up"}):X.id==="down"?h.jsx(sn,{name:"down"}):X.id==="right"?h.jsx(sn,{name:"right"}):X.id==="enter"?h.jsx(sn,{name:"enter"}):X.id==="drawer_chords"?h.jsx("span",{children:"^C"}):X.id==="drawer_fn"?h.jsxs(h.Fragment,{children:[h.jsx("span",{children:"Fn"}),h.jsx(sn,{name:E?"close":"open"})]}):h.jsx(a0,{text:X.label}),le=X=>{if(m(),X.type==="modifier"){X.modifierType==="ctrl"||X.modifierType==="alt"||X.modifierType==="shift"?f(X.modifierType):X.modifierType==="meta"&&p(de.ESC);return}if(X.type==="drawer"){X.drawerType==="fn"?(N(!E),L(!1),R(!1)):X.drawerType==="chords"?(R(!D),N(!1),L(!1)):X.drawerType==="symbols"&&(L(!B),N(!1),R(!1));return}p(X.code,X.type!=="chord")},P=X=>{if(X.type==="modifier"){if(X.modifierType==="ctrl")return c.ctrl;if(X.modifierType==="alt")return c.alt;if(X.modifierType==="shift")return c.shift}if(X.type==="drawer"){if(X.drawerType==="fn")return E;if(X.drawerType==="chords")return D;if(X.drawerType==="symbols")return B}return!1},fe=X=>{const ue=P(X),oe=xd(X,r);return h.jsx("button",{type:"button",onPointerDown:pe=>ie(X,pe),onPointerMove:re,onPointerUp:ce,onPointerCancel:O,onClick:()=>{if(k.current){k.current=!1;return}le(X)},className:ne(ei,v5.has(X.id)?w:X.type==="drawer"?x:v,X.id==="enter"?i5:ue?n5:Ns),title:oe,"aria-label":oe,"aria-pressed":ue,children:I(X)},X.id)},ve=J.find(X=>X.id==="enter");return h.jsxs("div",{"data-testid":"key-toolbar",className:ne("z-20 flex shrink-0 select-none flex-col border-t border-tui-border bg-tui-mantle",l?"pb-[max(env(safe-area-inset-bottom,0px),0.125rem)]":"pb-[max(env(safe-area-inset-bottom,0px),0.25rem)]"),role:"toolbar","aria-label":r("virtualKeyboard.touchKeyboardShortcuts"),children:[h.jsx(mb,{fileInputRef:S}),h.jsx(pb,{collapsed:!1}),E&&h.jsx(d5,{capHeight:y,onKey:p}),D&&h.jsx(h5,{capHeight:y,onKey:p}),B&&h.jsx(p5,{squareKeyClass:w,onKey:p}),h.jsxs("div",{"data-testid":"key-toolbar-row",className:ne("flex flex-nowrap items-center justify-start gap-1",l?"px-1.5 py-1":"px-2 py-1.5"),children:[h.jsxs("div",{className:"relative min-w-0",children:[h.jsxs("div",{ref:z,"data-testid":"key-toolbar-scroll",onScroll:te,className:"scrollbar-none flex flex-nowrap touch-pan-x items-center gap-1 overflow-x-auto overscroll-x-contain",children:[h.jsx("button",{type:"button",onClick:()=>s({toolbarVisible:!1}),className:ne(ei,w,"mr-1 border-tui-border-dim bg-transparent text-tui-faint hover:border-tui-border hover:text-tui-text"),title:r("virtualKeyboard.collapseToolbar"),"aria-label":r("virtualKeyboard.collapseToolbar"),"aria-expanded":!0,children:h.jsx(sn,{name:"close"})}),J.filter(X=>X.id!=="enter").map(fe),h.jsx(y5,{squareKeyClass:w}),h.jsx(u5,{keyClass:v,squareKeyClass:w,onCustomize:n,sendCombo:g}),h.jsx(g5,{fileInputRef:S,keyClass:v,squareKeyClass:w,vibrate:m})]}),K&&h.jsx("span",{"aria-hidden":"true","data-testid":"key-toolbar-more",className:"pointer-events-none absolute inset-y-0 right-0 w-4 bg-gradient-to-l from-tui-mantle"})]}),ve&&fe(ve)]})]})},C5=({hint:l,children:n})=>{const{t:a}=Ee(),[s,r]=M.useState(!1);return h.jsxs("div",{className:"border border-tui-border-dim",children:[h.jsxs("button",{type:"button",onClick:()=>r(!s),"aria-expanded":s,className:"tui-focusable flex w-full items-center gap-2 px-2 py-1 text-left text-tui text-tui-muted transition-colors hover:text-tui-accent",children:[h.jsx("span",{"aria-hidden":"true",className:"text-tui-accent",children:s?_e.chevronDown:_e.chevronRight}),h.jsx("span",{children:a("pairing.advancedTitle")}),h.jsx("span",{className:"min-w-0 truncate text-tui-sm text-tui-faint",children:l})]}),s&&h.jsx("div",{className:"space-y-2.5 border-t border-tui-border-dim px-2 py-2",children:n})]})},T5=({isOpen:l,onClose:n})=>{const{t:a,addProfileAndConnect:s}=Ee(),{addToast:r}=dn(),[c,f]=M.useState(""),[m,p]=M.useState(Ut),[g,y]=M.useState("");M.useEffect(()=>{l&&(f(""),p(Ut),y(""))},[l]);const v=w=>{w.preventDefault();const x=c.trim().toUpperCase();if(!x&&!g.trim()){r("warning",a("pairing.credentialsRequired"));return}s({wsUrl:m.trim()||Ut,pairCode:x,token:g.trim()}),n()};return h.jsx(ma,{isOpen:l,onClose:n,title:a("pairing.addTitle"),subtitle:a("pairing.addSubtitle"),closeLabel:a("common.closeDialog"),size:"sm",hints:[{keys:"esc",action:a("common.close")},{keys:"⏎",action:a("pairing.pairAndConnect")}],footer:h.jsx(Ae,{variant:"primary",type:"submit",form:"add-host-form",children:a("pairing.pairAndConnect")}),children:h.jsxs("form",{id:"add-host-form",onSubmit:v,className:"space-y-3",children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"add-host-code",hint:a("pairing.pairCodeNote"),children:a("pairing.pairCodeLabel")}),h.jsx(un,{id:"add-host-code",type:"text",value:c,onChange:w=>f(w.target.value.toUpperCase()),placeholder:a("pairing.pairCodePlaceholder"),maxLength:12,autoComplete:"off",autoFocus:!0,className:"font-bold uppercase"}),h.jsx("p",{className:"text-tui-sm text-tui-faint",children:a("pairing.pairCodeHelp")})]}),h.jsxs(C5,{hint:a("pairing.advancedHint"),children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"add-host-ws",children:a("pairing.wsUrlLabel")}),h.jsx(un,{id:"add-host-ws",type:"text",value:m,onChange:w=>p(w.target.value),placeholder:a("onboarding.wsEndpointPlaceholder")})]}),h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"add-host-token",hint:a("pairing.tokenNote"),children:a("pairing.tokenLabel")}),h.jsx(un,{id:"add-host-token",type:"password",value:g,onChange:w=>y(w.target.value),placeholder:a("onboarding.manualTokenPlaceholder")})]})]})]})})},_i=ne(Mr,"py-0"),M5="h-7 py-0",jd="h-7 py-0 px-1.5",xr="text-tui-bad hover:border-tui-bad hover:text-tui-bad",A5=["grid items-center gap-x-2 gap-y-1 py-1","grid-cols-[4rem_minmax(0,1fr)_9rem] [grid-template-areas:'cap_label_actions'_'combo_combo_default']","sm:grid-cols-[4rem_minmax(0,1fr)_9rem_9rem_7rem] sm:[grid-template-areas:'cap_label_combo_default_actions']"].join(" ");function o0(l){return{offLabel:l("settings.toggleOff"),onLabel:l("settings.toggleOn")}}const E5=["ctrl","alt","shift"],k5=[[..."1234567890"].map(l=>({token:l,label:l})),[..."qwertyuiop"].map(l=>({token:l,label:l.toUpperCase()})),[..."asdfghjkl"].map(l=>({token:l,label:l.toUpperCase()})),[..."zxcvbnm"].map(l=>({token:l,label:l.toUpperCase()})),["-","=","[","]","backslash",";","'",",",".","/","plus"].map(l=>({token:l,label:l==="backslash"?"\\":l==="plus"?"+":l}))],N5=[{token:"esc",label:"ESC"},{token:"tab",label:"TAB"},{token:"space",label:"SPACE"},{token:"enter",label:"ENTER"},{token:"backspace",label:"⌫"},{token:"delete",label:"DEL"},{token:"insert",label:"INS"},{token:"home",label:"HOME"},{token:"end",label:"END"},{token:"pageup",label:"PGUP"},{token:"pagedown",label:"PGDN"},{token:"left",label:"←"},{token:"up",label:"↑"},{token:"down",label:"↓"},{token:"right",label:"→"},...Array.from({length:12},(l,n)=>({token:`f${n+1}`,label:`F${n+1}`}))],cd="tui-focusable min-w-0 border border-tui-border bg-tui-mantle px-1.5 py-1 text-tui-sm font-bold text-tui-text transition-colors hover:border-tui-accent hover:text-tui-accent";function _5(l){const n=l.trim();if(!n)return[];try{return cn(n),n.split(/\s+/)}catch{return[]}}function L5({isOpen:l,value:n,onClose:a,onApply:s}){const{t:r}=Ee(),[c,f]=M.useState([]),m=M.useRef(0),[p,g]=M.useState([]);M.useEffect(()=>{l&&(m.current=0,f(_5(n).map(S=>({id:m.current++,combo:S}))),g([]))},[l,n]);const y=S=>{g(T=>T.includes(S)?T.filter(A=>A!==S):[...T,S])},v=S=>{if(c.length>=8)return;const T=[...p,S].join("+");f(A=>[...A,{id:m.current++,combo:T}]),g([])},w=c.map(S=>S.combo).join(" "),x=c.length>0&&p.length===0;return h.jsx(ma,{isOpen:l,onClose:a,title:r("agentKeymaps.comboPickerTitle"),closeLabel:r("common.closeDialog"),size:"lg",footer:h.jsxs(h.Fragment,{children:[h.jsx(Ae,{variant:"ghost",onClick:a,children:r("common.cancel")}),h.jsx(Ae,{variant:"primary",disabled:!x,onClick:()=>s(w),"data-testid":"combo-picker-apply",children:r("agentKeymaps.comboPickerApply")})]}),children:h.jsxs("div",{className:"space-y-3",children:[h.jsx("p",{className:"text-tui-sm text-tui-faint",children:r("agentKeymaps.comboPickerHint")}),h.jsxs("div",{className:"space-y-1",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsx("span",{className:"text-tui-sm text-tui-muted",children:r("agentKeymaps.comboPickerSelection")}),h.jsx(Ae,{variant:"ghost",disabled:c.length===0&&p.length===0,onClick:()=>{f([]),g([])},children:r("agentKeymaps.comboPickerClear")})]}),h.jsxs("div",{"data-testid":"combo-picker-selection",className:"flex min-h-9 flex-wrap items-center gap-1 border border-tui-border-dim bg-tui-crust p-1",children:[c.map((S,T)=>{let A=S.combo;try{A=na(S.combo)}catch{}return h.jsxs("span",{className:"inline-flex items-center gap-1",children:[h.jsx(pr,{children:A}),h.jsx("button",{type:"button","aria-label":r("agentKeymaps.comboPickerRemoveStep",{step:T+1}),className:"tui-focusable text-tui-faint hover:text-tui-bad",onClick:()=>f(k=>k.filter(E=>E.id!==S.id)),children:"×"})]},S.id)}),p.map(S=>h.jsx(pr,{active:!0,children:S.toUpperCase()},S)),c.length===0&&p.length===0&&h.jsx("span",{className:"px-1 text-tui-sm text-tui-faint",children:r("agentKeymaps.comboPickerEmpty")})]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"mb-1 text-tui-sm text-tui-muted",children:r("agentKeymaps.comboPickerModifiers")}),h.jsx("div",{className:"flex gap-1",children:E5.map(S=>h.jsx("button",{type:"button","aria-pressed":p.includes(S),onClick:()=>y(S),className:`${cd} ${p.includes(S)?"border-tui-accent bg-tui-accent text-tui-crust":""}`,children:S.toUpperCase()},S))})]}),h.jsxs("fieldset",{className:"space-y-1.5",children:[h.jsx("legend",{className:"sr-only",children:r("agentKeymaps.comboPickerKeyboard")}),k5.map(S=>h.jsx("div",{className:"grid grid-cols-10 gap-1",children:S.map(({token:T,label:A})=>h.jsx("button",{type:"button","aria-label":A,className:cd,disabled:c.length>=8,onClick:()=>v(T),children:A},T))},S.map(({token:T})=>T).join("-"))),h.jsx("div",{className:"flex flex-wrap gap-1",children:N5.map(({token:S,label:T})=>h.jsx("button",{type:"button","aria-label":T,className:cd,disabled:c.length>=8,onClick:()=>v(S),children:T},S))})]})]})})}const R5=({profile:l,onProfileChange:n})=>{const{settings:a,updateSettings:s,t:r}=Ee(),{agentProfile:c}=it(),[f,m]=M.useState({}),p=M.useRef({}),[g,y]=M.useState(""),[v,w]=M.useState(""),[x,S]=M.useState(null),T=l||c,A=a.agentKeymaps[T]||{},k=Rb(T,A),E=jb(T,A),N=E.filter(I=>!I.hidden).length,B=I=>I.custom?I.customLabel||"":r(`agentActions.${I.labelKey}`),L=I=>{try{return na(I.combo)}catch{return I.combo}},D=I=>{s({agentKeymaps:{...a.agentKeymaps,[T]:I}})},R=(I,le)=>{var P;D({...A,actions:{...A.actions,[I]:{...(P=A.actions)==null?void 0:P[I],...le}}})},z=I=>{R(I.id,{keys:I.defaultCombo})},K=(I,le)=>{const P=I+(le==="up"?-1:1);if(P<0||P>=k.length)return;const fe=k.map(ve=>ve.id);[fe[I],fe[P]]=[fe[P],fe[I]],D({...A,order:fe})},V=I=>{var le;D({...A,custom:(A.custom||[]).filter(P=>P.id!==I),order:(le=A.order)==null?void 0:le.filter(P=>P!==I)})},te=()=>D(cw(A)),Z=()=>{const I={...a.agentKeymaps};delete I[T],s({agentKeymaps:I})},ie=()=>{const I=g.trim();if(!I)return;try{cn(v)}catch{return}const le=`custom-${Date.now().toString(36)}`;D({...A,custom:[...A.custom||[],{id:le,label:I,keys:v.trim()}],order:[...k.map(P=>P.id),le]}),y(""),w("")},re=I=>I instanceof pn?r(`agentKeymaps.errors.${I.code}`,I.params):String(I),ce=(I,le)=>`${I}:${le}`,O=(I,le)=>{const P=ce(T,I);p.current={...p.current,[P]:le},m(p.current);try{cn(le),R(I,{keys:le})}catch{}},J=I=>{const le=ce(T,I),P=p.current[le];if(P!==void 0){delete p.current[le],m({...p.current});try{cn(P),R(I,{keys:P})}catch{}}};return h.jsxs("div",{className:"space-y-4",children:[h.jsx(gn,{title:r("agentKeymaps.settingsProfileLabel"),aside:h.jsx(Ae,{variant:"ghost",onClick:Z,className:ne(xr,jd),children:r("agentKeymaps.restoreProfile")}),children:h.jsx(Bt,{label:r("agentKeymaps.profileRowLabel"),htmlFor:"agent-keymap-profile",hint:nl[T].configHint?r("agentKeymaps.configHint",{path:nl[T].configHint}):void 0,control:h.jsx(Tr,{id:"agent-keymap-profile","aria-label":r("agentKeymaps.settingsProfileLabel"),value:T,onChange:I=>n(I.target.value),className:_i,children:Qx.map(I=>h.jsx("option",{value:I,children:nl[I].name},I))})})}),h.jsx(gn,{title:r("agentKeymaps.barGroup"),aside:h.jsx(Ae,{variant:"ghost",onClick:te,className:ne(xr,jd),children:r("agentKeymaps.restoreBar")}),children:h.jsxs("div",{className:"space-y-2 py-1.5",children:[h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:r("agentKeymaps.barHint",{profile:nl[T].name,count:N})}),h.jsx("div",{role:"group","aria-label":r("agentKeymaps.barGroup"),"data-testid":"agent-bar-choices",className:"flex flex-wrap gap-1",children:E.map(I=>{const le=B(I),P=L(I),fe=!I.hidden;return h.jsxs("button",{type:"button","data-testid":`agent-bar-toggle-${I.id}`,"aria-pressed":fe,onClick:()=>R(I.id,{hidden:fe}),title:`${P} ${le}`.trim(),className:ne("tui-focusable inline-flex h-7 select-none items-center gap-1 border px-1.5 text-tui-sm transition-colors",fe?"border-tui-accent bg-tui-accent text-tui-crust":"border-tui-border text-tui-muted hover:border-tui-accent hover:text-tui-accent"),children:[h.jsx("span",{"aria-hidden":"true",className:"font-bold",children:fe?_e.check:"+"}),h.jsx("span",{className:"font-bold",children:P}),h.jsx("span",{className:fe?void 0:"opacity-80",children:le})]},I.id)})})]})}),h.jsx(gn,{title:r("agentKeymaps.listGroup",{profile:nl[T].name}),children:k.map((I,le)=>{var se,xe;const P=B(I),fe=r("agentKeymaps.defaultCombo",{combo:na(I.defaultCombo)}),ve=((xe=(se=A.actions)==null?void 0:se[I.id])==null?void 0:xe.keys)??I.combo,X=ce(T,I.id),ue=f[X]??ve;let oe="",pe=null;try{cn(ue),oe=na(ue)}catch(ae){pe=re(ae)}return h.jsxs("div",{"data-testid":`agent-setting-row-${I.id}`,className:A5,children:[h.jsx(pr,{className:"w-full overflow-hidden whitespace-nowrap font-bold [grid-area:cap]",children:oe||"—"}),h.jsxs("span",{className:"min-w-0 break-words text-tui text-tui-text [grid-area:label]",title:P,children:[P,!I.verified&&h.jsx("span",{className:"ml-1 text-tui-sm text-tui-faint",children:r("agentKeymaps.unverified")})]}),h.jsxs("label",{className:"sr-only",htmlFor:`agent-combo-${I.id}`,children:[r("agentKeymaps.shortcutLabel")," ",P]}),h.jsx(un,{id:`agent-combo-${I.id}`,"aria-label":`${r("agentKeymaps.shortcutLabel")} ${P}`,value:ue,onChange:ae=>O(I.id,ae.target.value),onClick:()=>S({kind:"action",actionId:I.id,value:ue}),inputMode:"none",onBlur:()=>J(I.id),onKeyDown:ae=>{ae.key==="Enter"&&ae.currentTarget.blur()},placeholder:r("agentKeymaps.comboPlaceholder"),"aria-invalid":!!pe,className:ne("w-full min-w-0 [grid-area:combo]",M5)}),h.jsx("span",{className:"min-w-0 break-words text-tui-sm text-tui-faint [grid-area:default]",title:fe,children:fe}),h.jsxs("div",{className:"flex items-center justify-end [grid-area:actions]",children:[h.jsx(ll,{onClick:()=>z(I),title:r("agentKeymaps.resetAction"),"aria-label":`${r("agentKeymaps.resetAction")} ${P}`,children:"↺"}),h.jsx(ll,{disabled:le===0,onClick:()=>K(le,"up"),title:r("agentKeymaps.moveUp"),"aria-label":`${r("agentKeymaps.moveUp")} ${P}`,children:"↑"}),h.jsx(ll,{disabled:le===k.length-1,onClick:()=>K(le,"down"),title:r("agentKeymaps.moveDown"),"aria-label":`${r("agentKeymaps.moveDown")} ${P}`,children:"↓"}),I.custom?h.jsx(ll,{variant:"danger",onClick:()=>V(I.id),title:r("agentKeymaps.removeCustom"),"aria-label":`${r("agentKeymaps.removeCustom")} ${P}`,children:_e.cross}):h.jsx("span",{"aria-hidden":"true",className:"h-7 w-7 shrink-0"})]}),pe&&h.jsx("p",{className:"col-span-full text-tui-sm text-tui-bad",role:"alert",children:r("agentKeymaps.invalidCombo",{error:pe})})]},I.id)})}),h.jsx(gn,{title:r("agentKeymaps.addCustom"),children:h.jsxs("div",{className:"space-y-1 py-1.5",children:[h.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[h.jsxs("label",{className:"min-w-[9rem] flex-1 space-y-1 text-tui-sm text-tui-muted",children:[h.jsx("span",{children:r("agentKeymaps.customLabel")}),h.jsx(un,{value:g,onChange:I=>y(I.target.value),className:_i})]}),h.jsxs("label",{className:"min-w-[9rem] flex-1 space-y-1 text-tui-sm text-tui-muted",children:[h.jsx("span",{children:r("agentKeymaps.customCombo")}),h.jsx(un,{value:v,onChange:I=>w(I.target.value),onClick:()=>S({kind:"custom",value:v}),inputMode:"none",placeholder:r("agentKeymaps.comboPlaceholder"),className:_i})]}),h.jsx(Ae,{variant:"primary",glyph:"+",onClick:ie,disabled:!g.trim()||!v.trim(),className:_i,children:r("agentKeymaps.addAction")})]}),v.trim()&&(()=>{try{return cn(v),h.jsx("p",{className:"text-tui-sm text-tui-info",children:na(v)})}catch(I){const le=re(I);return h.jsx("p",{className:"text-tui-sm text-tui-bad",role:"alert",children:le})}})()]})}),x&&h.jsx(L5,{isOpen:!0,value:x.value,onClose:()=>S(null),onApply:I=>{x.kind==="custom"?w(I):(O(x.actionId,I),J(x.actionId)),S(null)}})]})},r0={"gnome-terminal":"GNOME Terminal",ptyxis:"Ptyxis",tilix:"Tilix",konsole:"Konsole","xfce4-terminal":"Xfce Terminal",kitty:"kitty",alacritty:"Alacritty",ghostty:"Ghostty",wezterm:"WezTerm",foot:"foot",vscode:"VS Code",iterm2:"iTerm2","apple-terminal":"Terminal",xterm:"xterm",urxvt:"urxvt"},j5=["host_font_unavailable","host_font_timeout","disconnected","font_api_unavailable"],O5=()=>{const{hostFont:l,loadHostFont:n,declineHostFont:a,settings:s,activeProfile:r,t:c}=Ee(),{herdrLaunch:f,hostname:m}=it(),{addToast:p}=dn(),{font:g,status:y,glyphs:v}=l,w=y==="loading"||v.status==="loading",x=y==="failed"||v.status==="failed",S=M.useRef(!1);M.useEffect(()=>{S.current&&!w&&!x&&l.interactive&&p("success",c("hostFont.loaded")),S.current=w&&l.interactive},[w,x,l.interactive,p,c]);const T=y==="available"||v.status==="available",A=l.interactive&&(w||x);if(!(g&&s.fontFamily==="host"&&!f&&(T||A)))return null;const E=y==="available"||l.interactive&&(y==="loading"||y==="failed"),N=v.source&&(v.status==="available"||l.interactive&&(v.status==="loading"||v.status==="failed")),B=m||(r==null?void 0:r.displayName)||c("herdrLaunch.thisHost"),L=[g.sizePx?`${Math.round(g.sizePx)}px`:null,g.source?r0[g.source]||g.source:null].filter(Boolean).join(c("hostFont.detailSeparator")),D=l.error&&j5.includes(l.error)?l.error:"other",R=l.totalBytes?l.receivedBytes/l.totalBytes:0;return h.jsx("div",{"data-testid":"host-font-prompt",className:"absolute inset-0 z-30 flex items-center justify-center bg-tui-crust/85 p-3",children:h.jsxs(Et,{title:c("hostFont.title"),tone:y==="failed"?"bad":"accent",className:"w-full max-w-md",bodyClassName:"space-y-3","aria-label":c("hostFont.title"),children:[h.jsx("p",{className:"leading-snug text-tui-text",children:E||!v.source?c("hostFont.body",{host:B,family:g.family,detail:L?c("hostFont.detail",{detail:L}):""}):c("hostFont.bodyGlyphsOnly",{host:B,family:v.source.family})}),w?h.jsxs("div",{className:"space-y-1",role:"status",children:[h.jsx(qS,{value:R,width:32,className:"max-w-full overflow-hidden"}),h.jsx("p",{className:"text-tui-sm text-tui-muted",children:c("hostFont.loading",{received:Vu(l.receivedBytes),total:Vu(l.totalBytes)})})]}):h.jsxs(h.Fragment,{children:[x?h.jsx(Ri,{tone:"bad",children:c("hostFont.failed",{reason:c(`hostFont.reasons.${D}`)})}):h.jsxs("div",{className:"space-y-1 text-tui-sm leading-snug text-tui-faint",children:[E&&g.faces.length?h.jsx("p",{children:c("hostFont.download",{count:g.faces.length,size:Vu(l.totalBytes)})}):null,N&&v.source?h.jsx("p",{children:c(v.source.scope==="all"?"hostFont.glyphsAll":"hostFont.glyphs",{family:v.source.family})}):null]}),h.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[h.jsx(Ae,{onClick:a,children:c("hostFont.decline")}),h.jsx(Ae,{variant:"primary",onClick:n,autoFocus:!0,children:c(x?"common.retry":"hostFont.load")})]})]})]})})},D5=({onOpenAdmin:l})=>{var L;const{settings:n,updateSettings:a,language:s,setLanguage:r,t:c,hostFont:f,syncHostFont:m,terminalFontFamily:p,terminalFontSize:g}=Ee(),{connectionState:y}=it(),v=gd.find(D=>D.id===n.fontFamily),w=(D,R)=>D==="host"||D==="system"?c(`fontPresets.${D}`):R,x=(()=>{const{font:D,status:R}=f,z=f.totalBytes?Math.round(f.receivedBytes/f.totalBytes*100):0,K=c(`settings.hostFontStatus.${R}`,{percent:z});return D?[D.family,D.sizePx?`${Math.round(D.sizePx)}px`:null,D.source?r0[D.source]||D.source:null,K].filter(Boolean).join(" · "):K})(),S=(L=f.font)!=null&&L.sizePx?ra(f.font.sizePx):null,T=f.glyphs.source&&f.glyphs.status!=="none"?c("settings.hostGlyphLine",{family:f.glyphs.source.family,status:c(`settings.hostGlyphStatus.${f.glyphs.status}`,{count:f.glyphs.covered.toLocaleString()})}):null,A=typeof window<"u"&&window.isSecureContext&&"Notification"in window,k=10,E=24,N=o0(c),B=S?c("settings.fontSizeFollowHost",{size:S}):c("settings.fontSizeFollowHostUnknown");return h.jsxs("div",{className:"space-y-4",children:[h.jsx(gn,{title:c("settings.sectionInterface"),children:h.jsx(Bt,{label:c("settings.languageLabel"),hint:c("settings.languageHint"),control:h.jsx(gr,{name:"ui-language","aria-label":c("settings.languageLabel"),value:s,onChange:r,options:[{value:"zh",label:"简体中文"},{value:"en",label:"English"}]})})}),h.jsxs(gn,{title:c("settings.sectionFont"),children:[h.jsx(Bt,{label:c("settings.fontFamilyLabel"),htmlFor:"terminal-font-select",control:h.jsxs(Tr,{id:"terminal-font-select",value:n.fontFamily,onChange:D=>a({fontFamily:D.target.value}),"aria-label":c("settings.fontFamilyLabel"),className:_i,children:[!v&&h.jsx("option",{value:n.fontFamily,children:n.fontFamily}),gd.map(D=>h.jsx("option",{value:D.id,children:w(D.id,D.name)},D.id))]})}),n.fontFamily==="host"&&h.jsx(Bt,{label:c("settings.hostFontLabel"),hint:h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-testid":"host-font-status",className:"block break-words text-tui-info",children:x}),T?h.jsx("span",{"data-testid":"host-glyph-status",className:"block break-words",children:T}):null]}),control:h.jsx(Ae,{block:!0,onClick:m,disabled:y!=="connected"||f.status==="loading"||f.glyphs.status==="loading",className:_i,children:c("settings.hostFontSync")})}),h.jsx(Bt,{label:c("settings.fontSizeLabel",{size:g}),hint:c("settings.fontSizeHint"),htmlFor:"terminal-font-size",control:h.jsx("div",{className:ne("flex items-center",Mr),children:h.jsx("input",{id:"terminal-font-size",type:"range",min:k,max:E,step:1,value:g,onChange:D=>a({fontSize:Number(D.target.value),fontSizeFollowsHost:!1}),className:"h-1 w-full cursor-pointer appearance-none bg-tui-border accent-tui-accent"})})}),h.jsx(Bt,{label:B,control:h.jsx(Ni,{label:B,...N,checked:n.fontSizeFollowsHost,onChange:D=>a(D?{fontSizeFollowsHost:!0}:{fontSizeFollowsHost:!1,fontSize:g})})}),h.jsx("div",{className:"py-1.5",children:h.jsxs("div",{className:"overflow-x-auto whitespace-nowrap border border-tui-border bg-tui-mantle px-2 py-1.5 leading-snug text-tui-text",style:{fontFamily:p,fontSize:`${g}px`},children:[h.jsx("span",{className:"text-tui-ok",children:"$"}),' echo "Herdr 0O 1lI ',' [] () -> => !="']})})]}),h.jsxs(gn,{title:c("settings.sectionInput"),children:[h.jsx(Bt,{label:c("settings.predictiveEchoLabel"),hint:c("settings.predictiveEchoDesc"),control:h.jsx(gr,{name:"predictive-echo","aria-label":c("settings.predictiveEchoLabel"),value:n.predictiveEcho,onChange:D=>a({predictiveEcho:D}),options:[{value:"auto",label:c("settings.predictiveEchoAuto")},{value:"always",label:c("settings.predictiveEchoAlways")},{value:"off",label:c("settings.predictiveEchoOff")}]})}),h.jsx(Bt,{label:c("settings.touchKeyToolbar"),hint:c("settings.touchKeyToolbarDesc"),control:h.jsx(Ni,{label:c("settings.touchKeyToolbar"),...N,checked:n.toolbarVisible,onChange:D=>a({toolbarVisible:D})})}),h.jsx(Bt,{label:c("settings.touchHaptics"),hint:c("settings.touchHapticsDesc"),control:h.jsx(Ni,{label:c("settings.touchHaptics"),...N,checked:n.vibrateOnKeyPress,onChange:D=>a({vibrateOnKeyPress:D})})})]}),h.jsxs(gn,{title:c("settings.agentAlertsLabel"),children:[h.jsx(Bt,{label:c("settings.agentAlertBadge"),hint:c("settings.agentAlertBadgeDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertBadge"),...N,checked:n.agentAlertBadge,onChange:D=>a({agentAlertBadge:D})})}),h.jsx(Bt,{label:c("settings.agentAlertVibrate"),hint:c("settings.agentAlertVibrateDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertVibrate"),...N,checked:n.agentAlertVibrate,onChange:D=>a({agentAlertVibrate:D})})}),h.jsx(Bt,{label:c("settings.agentAlertSound"),hint:c("settings.agentAlertSoundDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertSound"),...N,checked:n.agentAlertSound,onChange:D=>{a({agentAlertSound:D}),D&&(ry(),cy("done"))}})}),A&&h.jsx(Bt,{label:c("settings.agentAlertNotify"),hint:c("settings.agentAlertNotifyDesc"),control:h.jsx(Ni,{label:c("settings.agentAlertNotify"),...N,checked:n.agentAlertNotify,onChange:D=>{if(D&&Notification.permission!=="granted"){Notification.requestPermission().then(R=>a({agentAlertNotify:R==="granted"}));return}a({agentAlertNotify:D})}})})]}),l&&h.jsx(gn,{title:c("settings.sectionAdmin"),children:h.jsx(Bt,{label:c("settings.adminEntry"),hint:c("settings.adminEntryHint"),control:h.jsx(Ae,{block:!0,variant:"primary",glyph:_e.arrowRight,onClick:l,className:_i,children:c("settings.adminEntryOpen")})})})]})},z5=()=>{const{settings:l,updateSettings:n,t:a}=Ee(),{addToast:s}=dn(),[r,c]=M.useState(!1),f=o0(a),m=l.virtualKeys&&l.virtualKeys.length>0?l.virtualKeys:Cs(),p=x=>{const S=m.map(T=>T.id===x?{...T,enabled:!T.enabled}:T);n({virtualKeys:S})},g=(x,S)=>{const T=S==="up"?x-1:x+1;if(T<0||T>=m.length)return;const A=[...m],k=A[x];A[x]=A[T],A[T]=k,n({virtualKeys:A})},y=x=>{if(m.some(T=>T.id===x.id)){const T=m.map(A=>A.id===x.id?{...A,enabled:!0}:A);n({virtualKeys:T})}else{const T=[...m,{...x,enabled:!0}];n({virtualKeys:T})}c(!1)},v=x=>{const S=m.filter(T=>T.id!==x);n({virtualKeys:S})},w=()=>{n({virtualKeys:Cs()}),s("info",a("toasts.keyLayoutReset"))};return h.jsxs("div",{className:"space-y-3",children:[h.jsx(gn,{title:a("virtualKeyboard.customizeTitle"),aside:h.jsx(Ae,{variant:"ghost",onClick:w,className:ne(xr,jd),children:a("virtualKeyboard.resetLayout")}),children:m.map((x,S)=>{const T=xd(x,a);return h.jsxs("div",{className:"flex items-center gap-2 py-1",children:[h.jsx(pr,{className:ne("w-16 shrink-0 truncate",!x.enabled&&"opacity-50"),children:x.label}),h.jsx("span",{className:ne("min-w-0 flex-1 break-words text-tui",x.enabled?"text-tui-text":"text-tui-faint"),children:T}),h.jsx(Ni,{label:`${a("virtualKeyboard.enableKey")} ${x.label}`,...f,checked:x.enabled,onChange:()=>p(x.id),className:"h-7 w-24 shrink-0"}),h.jsx(ll,{disabled:S===0,onClick:()=>g(S,"up"),title:a("virtualKeyboard.moveUp"),"aria-label":a("virtualKeyboard.moveUp"),children:"↑"}),h.jsx(ll,{disabled:S===m.length-1,onClick:()=>g(S,"down"),title:a("virtualKeyboard.moveDown"),"aria-label":a("virtualKeyboard.moveDown"),children:"↓"}),h.jsx(ll,{variant:"danger",onClick:()=>v(x.id),title:a("virtualKeyboard.deleteKeyTitle"),"aria-label":a("virtualKeyboard.deleteKeyTitle"),children:_e.cross})]},x.id)})}),h.jsx(Ae,{block:!0,glyph:"+",onClick:()=>c(!r),className:ne("border-dashed",_i),children:a("virtualKeyboard.addKey")}),r&&h.jsx(gn,{title:a("virtualKeyboard.availableKeys"),children:h.jsx("div",{className:"flex flex-wrap gap-1 py-1.5",children:E1.map(x=>{const S=m.some(T=>T.id===x.id);return h.jsxs("button",{type:"button",onClick:()=>y(x),title:xd(x,a),className:ne("tui-focusable flex h-7 select-none items-center gap-1 border px-1.5 text-tui-sm transition-colors",S?"border-tui-border-dim text-tui-faint":"border-tui-border text-tui-text hover:border-tui-accent hover:text-tui-accent"),children:[h.jsx("span",{children:x.label}),h.jsx("span",{"aria-hidden":"true",className:S?"text-tui-ok":"text-tui-accent",children:S?_e.check:"+"})]},x.id)})})})]})},H5=({isOpen:l,onClose:n,initialTab:a,onOpenAdmin:s})=>{const{updateSettings:r,t:c,activeProfile:f}=Ee(),{addToast:m}=dn(),[p,g]=M.useState("general"),[y,v]=M.useState(null);if(M.useEffect(()=>{!l||!a||(g(a),v(null))},[l,a]),!l)return null;const w=()=>{const x=ey();r({fontSize:x.fontSize,fontSizeFollowsHost:x.fontSizeFollowsHost,fontFamily:x.fontFamily,toolbarVisible:x.toolbarVisible,vibrateOnKeyPress:x.vibrateOnKeyPress,predictiveEcho:x.predictiveEcho,agentAlertBadge:x.agentAlertBadge,agentAlertSound:x.agentAlertSound,agentAlertVibrate:x.agentAlertVibrate,agentAlertNotify:x.agentAlertNotify,virtualKeys:x.virtualKeys}),m("info",c("settings.resetDefaultsToast"))};return h.jsxs(ma,{isOpen:l,onClose:n,title:c("settings.title"),subtitle:f?c("settings.subtitleInstance",{name:f.displayName}):c("settings.subtitle"),closeLabel:c("common.closeDialog"),size:"lg",fixedHeight:!0,hints:[{keys:"esc",action:c("common.close")}],footer:h.jsxs(h.Fragment,{children:[h.jsx(Ae,{variant:"ghost",onClick:w,className:xr,children:c("settings.resetDefaults")}),h.jsx(Ae,{variant:"primary",onClick:n,children:c("common.done")})]}),children:[h.jsx(Pd,{tabs:[{id:"general",label:c("settings.tabGeneral"),index:1},{id:"virtualKeys",label:c("settings.tabVirtualKeys"),index:2},{id:"agentKeymaps",label:c("settings.tabAgentKeymaps"),index:3}],activeId:p,onSelect:x=>g(x),className:"mb-3 border-b border-tui-border-dim pb-1"}),p==="general"&&h.jsx(D5,{onOpenAdmin:s}),p==="virtualKeys"&&h.jsx(z5,{}),p==="agentKeymaps"&&h.jsx(R5,{profile:y,onProfileChange:v})]})},B5={success:"ok",warning:"warn",error:"bad",info:"accent"},U5={success:_e.check,warning:_e.warn,error:_e.cross,info:"›"},K5=()=>{const{t:l}=Ee(),{toasts:n,removeToast:a}=dn();return n.length===0?null:h.jsx("div",{className:"pointer-events-none fixed right-2 top-12 z-50 flex w-[calc(100vw-16px)] max-w-sm flex-col gap-1","aria-live":"polite","aria-atomic":"true",children:n.map(s=>{const r=B5[s.type];return h.jsxs("div",{className:ne("pointer-events-auto flex items-start gap-2 border border-tui-border border-l-2 bg-tui-base px-2 py-1 text-tui",rn[r].edgeL),role:"alert",children:[h.jsx("span",{"aria-hidden":"true",className:ne("shrink-0 font-bold",rn[r].text),children:U5[s.type]}),h.jsx("div",{className:"min-w-0 flex-1 break-words leading-snug text-tui-text",children:s.message}),s.count>1&&h.jsxs("span",{className:"shrink-0 border border-tui-border-dim px-1 text-tui-sm text-tui-muted",children:["×",s.count]}),h.jsx("button",{type:"button",onClick:()=>a(s.id),className:"tui-focusable shrink-0 select-none px-0.5 text-tui-faint transition-colors hover:text-tui-bad","aria-label":l("common.dismissNotification"),children:h.jsx("span",{"aria-hidden":"true",children:_e.cross})})]},s.id)})})};function Qd(l,n){const a=(s,r)=>n?n(s):r;switch(l){case"connected":return{label:a("connection.live","Live"),level:"ok",needsAttention:!1};case"connecting":return{label:a("connection.connecting","Connecting"),level:"warn",needsAttention:!0};case"reconnecting":return{label:a("connection.reconnecting","Reconnecting"),level:"warn",needsAttention:!0,actionLabel:a("connection.reconnectNow","Reconnect now")};case"error":return{label:a("connection.error","Error"),level:"bad",needsAttention:!0,actionLabel:a("connection.retry","Retry")};default:return{label:a("connection.offline","Offline"),level:"idle",needsAttention:!0,actionLabel:a("connection.connect","Connect")}}}const c0=[{status:"blocked",level:"warn"},{status:"done",level:"ok"},{status:"working",level:"accent"}];function I5(l){return l?l.total>0||c0.some(({status:n})=>{var a;return(((a=l.counts)==null?void 0:a[n])??0)>0}):!1}const u0=({className:l,compact:n=!1})=>{const{t:a}=Ee(),{agentStatus:s}=it();if(!s)return null;const r=c0.map(({status:f,level:m})=>{var p;return{status:f,level:m,count:((p=s.counts)==null?void 0:p[f])??0}}).filter(f=>f.count>0),c=n?r.slice(0,1):r;return c.length===0?s.total===0?null:h.jsxs("span",{"data-testid":"agent-status-chip",className:ne("flex shrink-0 items-center gap-1 px-1 text-tui-muted",l),title:a("agents.title"),children:[h.jsx(bn,{level:"idle"}),h.jsx("span",{className:"text-tui-faint",children:a("agents.allIdle")})]}):h.jsx("span",{"data-testid":"agent-status-chip",className:ne("flex shrink-0 items-center gap-2 px-1",l),title:a("agents.title"),children:c.map(({status:f,level:m,count:p})=>h.jsxs("span",{className:"flex items-center gap-1 text-tui-muted",children:[h.jsx(bn,{level:m}),h.jsx("span",{className:"text-tui-text",children:p}),h.jsx("span",{className:"text-tui-faint",children:a(`agents.${f}`)})]},f))})},Jd=({onAddProfile:l,mobile:n=!1,statusBar:a=!1})=>{const{profiles:s,activeProfileId:r,activeProfile:c,switchProfile:f,renameProfile:m,removeProfile:p,t:g}=Ee(),{connectionState:y}=it(),[v,w]=M.useState(!1),[x,S]=M.useState(null),[T,A]=M.useState(""),k=M.useRef(null);M.useEffect(()=>{if(!v)return;const R=z=>{k.current&&!k.current.contains(z.target)&&w(!1)};return document.addEventListener("pointerdown",R),()=>document.removeEventListener("pointerdown",R)},[v]);const E=(R,z)=>{S(R),A(z)},N=R=>{const z=T.trim();z&&m(R,z),S(null)},B=R=>{typeof window<"u"&&!window.confirm(g("profiles.removeConfirm"))||(p(R),S(null))},L=(c==null?void 0:c.displayName)||g("profiles.addHost"),D=y==="connected"?"ok":y==="connecting"||y==="reconnecting"?"warn":y==="error"?"bad":"idle";return h.jsxs("div",{ref:k,className:ne("relative min-w-0",n&&"w-full",a&&"flex-1",!n&&!a&&"h-full",!n&&!a&&"shrink-0"),children:[h.jsxs("button",{type:"button","aria-haspopup":"menu","aria-expanded":v,"aria-label":g("profiles.switcherLabel"),onClick:()=>w(R=>!R),className:ne("tui-focusable flex min-w-0 items-center gap-1.5 border border-transparent text-left text-tui-muted transition-colors hover:border-tui-border hover:text-tui-accent",a?"min-h-11 w-full max-w-none px-2":n?"min-h-11 w-full px-2":"h-full max-w-[18rem] px-1"),children:[h.jsx(bn,{level:D}),h.jsx("span",{className:ne("min-w-0 truncate text-tui-text",a&&"flex-1"),children:L}),h.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-tui-faint",children:v?_e.chevronDown:_e.chevronRight})]}),v&&h.jsxs("div",{role:"menu","aria-label":g("profiles.switcherLabel"),className:ne("absolute bottom-full left-0 z-[100] mb-1 max-h-[min(70vh,24rem)] overflow-y-auto border border-tui-border bg-tui-base p-1 shadow-lg",a?"w-80 max-w-[calc(100vw-1rem)]":n?"inset-x-0 bottom-auto top-full mt-1 mb-0 w-full":"w-80 max-w-[calc(100vw-1rem)]"),children:[h.jsx("div",{className:"border-b border-tui-border-dim px-2 py-1 text-tui-sm uppercase text-tui-faint",children:g("profiles.title")}),s.length===0?h.jsx("p",{className:"px-2 py-2 text-tui-sm text-tui-muted",children:g("profiles.empty")}):s.map(R=>{const z=R.id===r,K=R.id===x;return h.jsxs("div",{role:"none",className:"border-b border-tui-border-dim last:border-b-0",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsxs("button",{type:"button",role:"menuitem","aria-current":z?"true":void 0,onClick:()=>{f(R.id),w(!1)},className:ne("tui-focusable flex min-h-11 min-w-0 flex-1 items-center gap-2 px-2 text-left text-tui transition-colors hover:bg-tui-selection",z?"text-tui-accent":"text-tui-text"),children:[h.jsx("span",{"aria-hidden":"true",className:"w-3 shrink-0",children:z?_e.cursor:""}),h.jsxs("span",{className:"min-w-0 flex-1",children:[h.jsx("span",{className:"block truncate font-bold",children:R.displayName}),h.jsx("span",{className:"block truncate text-tui-sm text-tui-faint",title:R.hostname||R.hostId,children:R.hostname||R.hostId||R.wsUrl})]}),z&&h.jsx("span",{className:"shrink-0 text-tui-sm text-tui-ok",children:g("profiles.current")})]}),h.jsx("button",{type:"button",role:"menuitem","aria-label":g("profiles.rename"),title:g("profiles.rename"),onClick:()=>E(R.id,R.displayName),className:"tui-focusable min-h-11 min-w-11 px-2 text-tui-muted hover:text-tui-accent",children:_e.ellipsis})]}),K&&h.jsxs("div",{className:"grid grid-cols-2 gap-1 px-2 pb-2",children:[h.jsx("input",{autoFocus:!0,value:T,maxLength:64,onChange:V=>A(V.target.value),onKeyDown:V=>{V.key==="Enter"&&N(R.id),V.key==="Escape"&&S(null)},"aria-label":g("profiles.rename"),className:"tui-input col-span-2 h-11 min-w-0 px-2 py-1 text-tui"}),h.jsx(Ae,{onClick:()=>N(R.id),variant:"primary",className:"h-11 w-full min-w-0 whitespace-nowrap",children:g("common.save")}),h.jsx(Ae,{onClick:()=>B(R.id),variant:"danger",className:"h-11 w-full min-w-0 whitespace-nowrap",children:g("profiles.remove")})]})]},R.id)}),h.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{w(!1),l()},className:"tui-focusable flex min-h-11 w-full items-center gap-2 px-2 text-left text-tui-accent hover:bg-tui-selection",children:[h.jsx("span",{"aria-hidden":"true",children:"+"}),h.jsx("span",{children:g("profiles.addHost")})]})]})]})},d0=({compact:l=!1,className:n})=>{const{settings:a,updateSettings:s,t:r}=Ee(),{connectionState:c,sharedWindowCount:f,assignedClientId:m}=it(),p=a.observerMode,g=h.jsx(gr,{name:"control-mode","aria-label":r("role.modeLabel"),value:p?"observe":"control",onChange:y=>s({observerMode:y==="observe"}),tone:p?"warn":"ok",size:l?"sm":"md",options:[{value:"control",label:r("role.sharedControl")},{value:"observe",label:r("common.viewer")}],className:n});return l?g:h.jsxs("div",{className:"flex w-full flex-col gap-1",children:[g,h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:r(p?"role.observerHint":"role.controlHint")}),c==="connected"&&f>1?h.jsx("p",{className:"text-tui-sm text-tui-muted",children:r("role.sharedWindows",{count:f})}):null,m?h.jsx(An,{label:r("role.thisWindow"),labelWidth:9,className:"text-tui-sm",children:h.jsx("span",{className:"truncate text-tui-muted",children:m})}):null]})},F5="dibin666/herdr-remote",f0=`https://github.com/${F5}/releases`,G5=`${f0}/latest/download/herdr-remote.tgz`;function Y5(l){return`${f0}/download/herdr-remote-v${l}/herdr-remote-${l}.tgz`}function h0(){const{updateStatus:l,ignoredUpdate:n,hostVersion:a}=it();return a===null||!!(l!=null&&l.updateAvailable)&&n!==(l==null?void 0:l.latest)}const P5="Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like '*node_modules\\herdr-remote*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }",m0=({compact:l=!1,className:n})=>{const{t:a}=Ee(),{updateStatus:s}=it(),r=h0(),[c,f]=M.useState(!1);if(!r)return null;const m=s!=null&&s.updateAvailable?s:null,p=m?m.restartPending?a("update.chipRestart",{version:m.latest}):l?a("update.chipCompact",{version:m.latest}):a("update.chip",{version:m.latest}):a("update.chipOutdated");return h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button","data-testid":"update-chip",onClick:()=>f(!0),title:a("update.title"),className:ne("tui-focusable shrink-0 whitespace-nowrap px-1 text-tui-warn hover:underline",n),children:p}),h.jsx($5,{isOpen:c,onClose:()=>f(!1)})]})},al=({command:l})=>{const{t:n}=Ee(),{addToast:a}=dn();return h.jsxs("div",{className:"flex items-center gap-2 border border-tui-border bg-tui-mantle px-2 py-1",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 select-none text-tui-ok",children:"$"}),h.jsx("code",{className:"min-w-0 flex-1 break-all text-tui-text",children:l}),h.jsx(Ae,{glyph:"⧉",className:"shrink-0",onClick:()=>{qd(l).then(s=>{a(s==="failed"?"error":"success",n(s==="failed"?"clipboard.copyFailed":"toasts.commandCopied"))})},children:n("common.copy")})]})},$5=({isOpen:l,onClose:n})=>{const{t:a}=Ee(),{updateStatus:s,ignoreUpdate:r,hostname:c,hostId:f,platform:m}=it();if(!(s!=null&&s.updateAvailable))return h.jsx(V5,{isOpen:l,onClose:n,host:c||f,win:m==="win32"});const{current:p,installed:g,latest:y,restartPending:v,updateCommand:w}=s;return h.jsx(ma,{isOpen:l,onClose:n,title:a("update.title"),closeLabel:a("common.closeDialog"),size:"md",footer:h.jsxs(h.Fragment,{children:[h.jsx(Ae,{variant:"ghost",onClick:()=>{r(y),n()},children:a("update.ignore")}),h.jsx(Ae,{variant:"primary",onClick:n,children:a("common.done")})]}),children:h.jsxs("div",{className:"space-y-3","data-testid":"update-modal",children:[h.jsxs("div",{className:"space-y-0.5",children:[h.jsx(An,{label:a("common.host"),labelWidth:10,children:c||f||"—"}),h.jsx(An,{label:a("update.running"),labelWidth:10,children:p}),g!==p?h.jsx(An,{label:a("update.installed"),labelWidth:10,children:g}):null,h.jsx(An,{label:a("update.latest"),labelWidth:10,children:h.jsx("span",{className:"text-tui-ok",children:y})})]}),v?h.jsxs(h.Fragment,{children:[h.jsx("p",{className:"leading-snug text-tui-text",children:a("update.restartPending",{version:g})}),h.jsx(al,{command:"herdr-remote restart"})]}):h.jsxs(h.Fragment,{children:[h.jsxs("p",{className:"leading-snug text-tui-text",children:[h.jsx("span",{"aria-hidden":"true",className:"mr-1 text-tui-accent",children:_e.arrowRight}),a("update.stepTui")]}),h.jsx("p",{className:"leading-snug text-tui-muted",children:a("update.stepCli")}),w?h.jsx(al,{command:"herdr-remote update"}):h.jsxs(h.Fragment,{children:[h.jsx(al,{command:`npm install -g ${Y5(y)}`}),h.jsx(al,{command:"herdr-remote restart"})]}),h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:a("update.restartNote")})]})]})})},V5=({isOpen:l,onClose:n,host:a,win:s})=>{const{t:r}=Ee();return h.jsx(ma,{isOpen:l,onClose:n,title:r("update.title"),closeLabel:r("common.closeDialog"),size:"md",footer:h.jsx(Ae,{variant:"primary",onClick:n,children:r("common.done")}),children:h.jsxs("div",{className:"space-y-3","data-testid":"update-modal",children:[h.jsxs("div",{className:"space-y-0.5",children:[h.jsx(An,{label:r("common.host"),labelWidth:10,children:a||"—"}),h.jsx(An,{label:r("update.running"),labelWidth:10,children:h.jsx("span",{className:"text-tui-warn",children:r("update.outdatedVersion")})})]}),h.jsx("p",{className:"leading-snug text-tui-text",children:r("update.outdated")}),s?h.jsxs(h.Fragment,{children:[h.jsx("p",{className:"leading-snug text-tui-muted",children:r("update.windowsStop")}),h.jsx(al,{command:P5})]}):null,h.jsx(al,{command:`npm install -g ${G5}`}),h.jsx(al,{command:"herdr-remote restart"}),h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:r("update.restartNote")})]})})},ud="shrink-0 whitespace-nowrap",gb="min-w-0 truncate whitespace-nowrap",q5=({onAddProfile:l=()=>{}})=>{const{settings:n,t:a}=Ee(),{connectionState:s,hostId:r,assignedClientId:c,sharedWindowCount:f,rttMs:m,agentStatus:p}=it(),g=Qd(s,a),y=s==="connected",v=h0();return h.jsx(ky,{left:h.jsxs(h.Fragment,{children:[h.jsx(Jd,{onAddProfile:l}),h.jsx(Md,{"data-testid":"status-line-segments",items:[h.jsxs("span",{className:ne(ud,"flex items-center gap-1"),children:[h.jsx(bn,{level:g.level}),h.jsx("span",{className:"text-tui-text",children:g.label})]},"status"),y?h.jsx(d0,{compact:!0,className:ne(ud,"h-full w-auto")},"role"):null,y&&f>1?h.jsx("span",{className:ne(ud,"text-tui-muted"),children:a("role.sharedWindows",{count:f})},"windows"):null,r?h.jsxs("span",{className:gb,children:[h.jsxs("span",{className:"text-tui-faint",children:[a("common.host"),":"]})," ",h.jsx("span",{className:"text-tui-text",children:r})]},"host"):null,h.jsxs("span",{className:gb,children:[h.jsx("span",{className:"text-tui-faint",children:a("header.clientIdLabel")})," ",h.jsx("span",{className:"text-tui-text",children:c||n.clientId})]},"client")]})]}),right:h.jsx(Md,{items:[v?h.jsx(m0,{},"update"):null,y&&I5(p)?h.jsx(u0,{},"agents"):null,m!==null?h.jsxs("span",{className:"text-tui-muted",children:[a("header.latencyTitle"),": ",h.jsxs("span",{className:"text-tui-text",children:[m,"ms"]})]},"rtt"):null,h.jsx("span",{className:"hidden text-tui-faint sm:inline",children:a("header.tagline")},"mode")]})})},X5=({wsUrl:l,adminUrl:n,onOpenRemoteAdmin:a,onSignIn:s})=>{const{t:r}=Ee();return h.jsxs(Et,{title:r("admin.remoteRelayTitle"),bodyClassName:"space-y-2",children:[h.jsx("p",{className:"text-tui leading-snug text-tui-muted",children:r("admin.remoteRelayNotice")}),h.jsxs("div",{className:"space-y-0.5 border border-tui-border-dim bg-tui-mantle px-2 py-1.5",children:[h.jsx(An,{label:r("admin.remoteRelayEndpoint"),labelWidth:18,children:h.jsx("code",{className:"break-all text-tui-accent",children:l})}),h.jsx(An,{label:r("admin.remoteRelayAdminUrl"),labelWidth:18,children:h.jsx("code",{className:"break-all text-tui-ok",children:n})})]}),h.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.jsx(Ae,{variant:"primary",onClick:a,glyph:_e.arrowRight,children:r("admin.openRemoteAdminBtn")}),h.jsx(Ae,{onClick:s,children:r("admin.relayAdminLoginBtn")})]})]})},Z5=({adminConfigured:l,isAuthError:n,tokenInput:a,onTokenInput:s,onSubmit:r,isSameOriginRelay:c,onBackToTerminal:f,showBack:m,onCancel:p})=>{const{t:g}=Ee();return h.jsxs(Et,{title:g("admin.relayAdminTitle"),bodyClassName:"space-y-2",children:[l===!1?h.jsx(Ri,{tone:"warn",children:g("admin.relayAdminNotConfigured")}):n?h.jsx(Ri,{tone:"bad",children:g("admin.relayAdminAuthError")}):h.jsx(Ri,{tone:"accent",children:g("admin.relayAdminPrompt")}),h.jsxs("form",{onSubmit:r,className:"space-y-2",children:[h.jsxs("div",{className:"space-y-1",children:[h.jsx(sl,{htmlFor:"relay-admin-token",children:g("admin.relayAdminTokenLabel")}),h.jsx(un,{id:"relay-admin-token",type:"password",autoComplete:"current-password",value:a,onChange:y=>s(y.target.value),placeholder:g("admin.relayAdminTokenPlaceholder")})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Ae,{variant:"primary",type:"submit",disabled:!a.trim(),children:g("admin.relayAdminLoginBtn")}),c?f&&!m?h.jsx(Ae,{variant:"ghost",onClick:f,children:g("admin.returnToTerminal")}):null:h.jsx(Ae,{variant:"ghost",onClick:p,children:g("common.cancel")})]})]})]})},W5=({onOpenPairing:l,onRetry:n})=>{const{t:a}=Ee(),{copied:s,copy:r}=Wd(),c=s!==null,f=()=>r(il,a("toasts.commandCopied"));return h.jsxs(Et,{title:a("admin.unauthorizedTitle"),tone:"bad",bodyClassName:"space-y-2",children:[h.jsx(Ri,{tone:"bad",children:a("admin.unauthorizedDesc")}),h.jsxs("div",{className:"space-y-1.5 border border-tui-border-dim bg-tui-mantle px-2 py-1.5",children:[h.jsx("span",{className:"block text-tui-sm uppercase text-tui-muted",children:a("admin.pairingStepsTitle")}),h.jsxs("div",{className:"flex items-center gap-2 border border-tui-border bg-tui-crust px-2 py-1",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 select-none text-tui-ok",children:"$"}),h.jsx("code",{className:"min-w-0 flex-1 truncate text-tui-text",children:il}),h.jsx(Ae,{onClick:f,glyph:c?_e.check:"⧉",className:ne("shrink-0",c&&"border-tui-ok text-tui-ok"),children:a(c?"admin.copiedJson":"common.copy")})]}),h.jsx("p",{className:"text-tui-sm text-tui-faint",children:a("admin.pairingStepsHelp")})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[l&&h.jsx(Ae,{variant:"primary",onClick:l,children:a("admin.enterPairCodeBtn")}),h.jsx(Ae,{onClick:n,children:a("admin.retryFetchBtn")})]})]})},Q5=[[/\biPhone\b/i,"iPhone"],[/\biPad\b/i,"iPad"],[/\biPod\b/i,"iPod"],[/\bAndroid\b/i,"Android"],[/\bCrOS\b/i,"ChromeOS"],[/\bWindows NT\b/i,"Windows"],[/\bMac OS X\b|\bMacintosh\b/i,"macOS"],[/\bLinux\b/i,"Linux"]],J5=[[/\bEdgA?\/|\bEdge\//i,"Edge"],[/\bOPR\/|\bOpera\//i,"Opera"],[/\bSamsungBrowser\//i,"Samsung Internet"],[/\bFirefox\/|\bFxiOS\//i,"Firefox"],[/\bCriOS\//i,"Chrome"],[/\bChrome\//i,"Chrome"],[/\bSafari\//i,"Safari"]];function bb(l,n){for(const[a,s]of l)if(a.test(n))return s;return null}function ef(l){const n=typeof l=="string"?l.trim():"";if(!n)return{label:"",raw:""};const a=bb(Q5,n),s=bb(J5,n);return a&&s?{label:`${a} · ${s}`,raw:n}:a?{label:a,raw:n}:s?{label:s,raw:n}:{label:n.length>32?`${n.slice(0,32)}…`:n,raw:n}}function la(l){if(!l||l<=0)return"0 B";const n=1024,a=["B","KB","MB","GB","TB"],s=Math.min(a.length-1,Math.floor(Math.log(l)/Math.log(n)));return`${(l/n**s).toFixed(1)} ${a[s]}`}function yb(l,n,a=!1){const s=Math.max(0,Math.floor(l)),r=Math.floor(s/86400),c=Math.floor(s%86400/3600),f=Math.floor(s%3600/60),m=s%60,p=(y,v)=>`${y}${n(`admin.unit${v}`)}`,g=r>0?[p(r,"Day"),p(c,"Hour"),p(f,"Minute")]:c>0?[p(c,"Hour"),p(f,"Minute"),p(m,"Second")]:[p(f,"Minute"),p(m,"Second")];return(a?g.slice(0,2):g).join(" ")}function tf(l,n,a=Date.now()){if(!l)return"—";const s=new Date(l).getTime();if(Number.isNaN(s))return"—";const r=Math.max(0,Math.floor((a-s)/1e3));return r<60?n("admin.relJustNow"):r<3600?n("admin.relMinutes",{count:Math.floor(r/60)}):r<86400?n("admin.relHours",{count:Math.floor(r/3600)}):n("admin.relDays",{count:Math.floor(r/86400)})}function nf(l){if(!l)return"";const n=new Date(l);return Number.isNaN(n.getTime())?"":n.toLocaleString()}function p0(l=[]){const n=new Map;for(const a of l)a.deviceId&&n.set(a.deviceId,(n.get(a.deviceId)||0)+1);return n}const eA=({clients:l})=>{const{t:n}=Ee(),a=l.some(r=>r.hostId),s=[{key:"id",header:n("admin.colClientId"),render:r=>h.jsxs("span",{className:"flex items-center gap-1.5",children:[h.jsx(bn,{level:"ok"}),h.jsx("span",{className:"font-bold text-tui-text",children:r.id})]})},...a?[{key:"host",header:n("admin.colHost"),render:r=>h.jsx("span",{className:"text-tui-text",children:r.hostId||"—"})}]:[],{key:"role",header:n("admin.colRole"),width:10,render:r=>{const c=r.role==="controller";return h.jsx(Ay,{tone:c?"ok":"warn",className:"text-tui-sm",children:n(c?"common.controller":"common.viewer")})}},{key:"device",header:n("admin.colDevice"),render:r=>{const c=ef(r.userAgent);return h.jsxs("span",{className:"flex min-w-0 items-baseline gap-1.5",children:[h.jsx("span",{className:c.label?"text-tui-text":"text-tui-faint",title:c.raw,children:c.label||n("admin.unknownDevice")}),r.deviceId?h.jsx("code",{className:"text-tui-sm text-tui-faint",children:r.deviceId}):null]})}},{key:"ip",header:n("admin.colIp"),render:r=>h.jsx("span",{className:"text-tui-muted",children:r.ip||"127.0.0.1"})},{key:"connectedAt",header:n("admin.colConnectedAt"),render:r=>h.jsx("span",{className:"whitespace-nowrap text-tui-muted",title:nf(r.connectedAt),children:r.connectedAt?tf(r.connectedAt,n):n("admin.startedRecently")})},{key:"traffic",header:n("admin.colTraffic"),align:"right",render:r=>h.jsxs("span",{className:"whitespace-nowrap",children:[h.jsxs("span",{className:"text-tui-accent",children:["↓",la(r.bytesReceived||0)]}),h.jsx("span",{"aria-hidden":"true",className:"mx-1 text-tui-faint",children:"/"}),h.jsxs("span",{className:"text-tui-ok",children:["↑",la(r.bytesSent||0)]})]})}];return h.jsx(Et,{title:n("admin.connectedClientsTitle",{count:l.length}),bodyClassName:"-mx-1",children:h.jsx($d,{columns:s,items:l,rowKey:r=>r.id,empty:n("admin.noClients")})})},tA=({devices:l,clients:n,onRevoke:a})=>{const{t:s}=Ee(),[r,c]=M.useState(null),[f,m]=M.useState(null),p=p0(n),g=[...l].sort((w,x)=>{const S=+!!p.get(x.deviceId)-+!!p.get(w.deviceId);return S||(Date.parse(x.lastSeenAt)||0)-(Date.parse(w.lastSeenAt)||0)}),y=async w=>{if(r!==w){c(w);return}m(w);try{await a(w)}finally{m(null),c(null)}},v=[{key:"status",header:s("admin.colStatus"),width:12,render:w=>{const x=p.get(w.deviceId)||0;return h.jsxs("span",{className:ne("flex items-center gap-1.5 whitespace-nowrap",x?"text-tui-ok":"text-tui-faint"),children:[h.jsx(bn,{level:x?"ok":"idle"}),s(x?"admin.hostStatusOnline":"admin.hostStatusOffline")]})}},{key:"device",header:s("admin.colDevice"),render:w=>{const x=ef(w.userAgent);return h.jsxs("span",{className:"flex min-w-0 items-baseline gap-1.5",children:[h.jsx("span",{className:"text-tui-text",title:x.raw,children:x.label||s("admin.unknownDevice")}),h.jsx("code",{className:"text-tui-sm text-tui-faint",children:w.deviceId})]})}},{key:"host",header:s("admin.colHost"),render:w=>h.jsx("span",{className:"text-tui-text",children:w.hostId||"—"})},{key:"ip",header:s("admin.colIp"),render:w=>h.jsx("span",{className:"text-tui-muted",children:w.lastIp||"—"})},{key:"lastSeen",header:s("admin.colLastSeen"),render:w=>{const x=p.get(w.deviceId)||0;return h.jsx("span",{className:ne("whitespace-nowrap",x?"text-tui-ok":"text-tui-muted"),title:nf(w.lastSeenAt),children:x?s("admin.deviceWindows",{count:x}):tf(w.lastSeenAt,s)})}},{key:"actions",header:s("admin.colActions"),align:"right",render:w=>{const x=r===w.deviceId,S=f===w.deviceId;return h.jsx(Ae,{variant:"danger",disabled:S,onClick:()=>void y(w.deviceId),onBlur:()=>c(T=>T===w.deviceId?null:T),"aria-label":s("admin.revokeDevice"),className:ne("h-6 py-0 text-tui-sm",x&&"bg-tui-bad text-tui-crust"),children:S?h.jsx(ol,{}):s(x?"admin.revokeConfirm":"admin.revokeDevice")})}}];return h.jsx(Et,{title:s("admin.pairedDevicesTitle",{count:l.length}),bodyClassName:"-mx-1",children:h.jsx($d,{columns:v,items:g,rowKey:w=>w.deviceId,empty:s("admin.noDevices")})})},vb={online:"ok",busy:"ok",reconnecting:"warn",offline:"idle"};function nA(l=[],n=[]){const a=new Map;for(const c of n){if(!(c!=null&&c.hostId))continue;const f=a.get(c.hostId);f?f.push(c):a.set(c.hostId,[c])}const s=l.map(c=>{const f=a.get(c.id)||[];return{id:c.id,hostname:c.hostname||c.id,status:c.status||"online",connectedDeviceCount:c.connectedDeviceCount??0,pairedDeviceCount:c.pairedDeviceCount??f.length,activePtyCount:c.activePtyCount??0,version:c.version,latestVersion:c.latestVersion,devices:f,fromRosterOnly:!1}}),r=new Set(s.map(c=>c.id));for(const[c,f]of a)r.has(c)||s.push({id:c,hostname:c,status:"offline",connectedDeviceCount:0,pairedDeviceCount:f.length,activePtyCount:0,devices:f,fromRosterOnly:!0});return s.sort((c,f)=>c.fromRosterOnly!==f.fromRosterOnly?c.fromRosterOnly?1:-1:c.hostname.localeCompare(f.hostname))}const iA=({hosts:l,devices:n,clients:a})=>{const{t:s}=Ee(),r=nA(l,n),c=p0(a),f={online:s("admin.hostStatusOnline"),busy:s("admin.hostStatusBusy"),reconnecting:s("admin.hostStatusReconnecting"),offline:s("admin.hostStatusOffline")};return h.jsx(Et,{title:s("admin.hostsTitle",{count:r.length}),bodyClassName:"space-y-2",children:r.length===0?h.jsx("p",{className:"px-1 py-2 text-tui text-tui-faint",children:s("admin.noHosts")}):r.map(m=>h.jsxs("div",{className:"border border-tui-border-dim bg-tui-mantle",children:[h.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-tui-border-dim px-2 py-1",children:[h.jsxs("span",{className:"flex min-w-0 flex-auto items-center gap-1.5 text-tui",children:[h.jsx(bn,{level:vb[m.status]}),h.jsx("span",{className:"truncate font-bold text-tui-text",children:m.hostname}),m.hostname!==m.id?h.jsx("code",{className:"truncate text-tui-sm text-tui-faint",children:m.id}):null,h.jsx(Ay,{tone:vb[m.status],className:"ml-1 text-tui-sm",children:f[m.status]})]}),h.jsx(Md,{className:"shrink-0 text-tui-sm",items:[h.jsx("span",{className:m.connectedDeviceCount?"text-tui-ok":"text-tui-faint",children:s("admin.hostConnectedDevices",{count:m.connectedDeviceCount})},"connected"),h.jsx("span",{className:"text-tui-muted",children:s("admin.hostPairedDevices",{count:m.pairedDeviceCount})},"paired"),m.version===void 0?null:h.jsx("span",{className:m.version&&!m.latestVersion?"text-tui-muted":"text-tui-warn",children:m.version?m.latestVersion?s("admin.hostVersionBehind",{version:m.version,latest:m.latestVersion}):s("admin.hostVersion",{version:m.version}):s("admin.hostVersionUnknown")},"version"),m.fromRosterOnly?null:h.jsx("span",{className:m.activePtyCount?"text-tui-info":"text-tui-faint",children:s("admin.hostPtys",{count:m.activePtyCount})},"ptys")]})]}),m.devices.length>0?h.jsx("ul",{className:"divide-y divide-tui-border-dim",children:m.devices.map(p=>{const g=ef(p.userAgent),y=c.get(p.deviceId)||0;return h.jsxs("li",{className:"grid grid-cols-[1ch_minmax(0,1fr)_auto] items-baseline gap-x-2 px-2 py-0.5 text-tui sm:grid-cols-[1ch_minmax(0,18ch)_minmax(0,1fr)_16ch_16ch]",children:[h.jsx(bn,{level:y?"ok":"idle"}),h.jsx("span",{className:"truncate text-tui-text",title:g.raw,children:g.label||s("admin.unknownDevice")}),h.jsx("code",{className:"hidden truncate text-tui-sm text-tui-faint sm:block",children:p.deviceId}),h.jsx("span",{className:"hidden truncate text-tui-sm text-tui-muted sm:block",children:p.lastIp||"—"}),h.jsx("span",{className:ne("whitespace-nowrap text-right text-tui-sm",y?"text-tui-ok":"text-tui-faint"),title:nf(p.lastSeenAt),children:y?s("admin.deviceWindows",{count:y}):tf(p.lastSeenAt,s)})]},p.deviceId)})}):h.jsx("p",{className:"px-2 py-1 text-tui-sm text-tui-faint",children:m.pairedDeviceCount>0?s("admin.hostRosterOperatorOnly"):s("admin.noDevices")})]},m.id))})},lA=({data:l})=>{var r,c,f,m,p,g,y,v,w,x;const{t:n}=Ee(),a=l.activeUserCount??((r=l.clients)==null?void 0:r.length)??0,s=new Set((l.devices||[]).map(S=>S.hostId).filter(S=>S&&!(l.hosts||[]).some(T=>T.id===S))).size;return h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 xl:grid-cols-6",children:[h.jsx(Zl,{label:n("admin.connectedHosts"),value:((c=l.hosts)==null?void 0:c.length)||0,sub:s?n("admin.hostsOfflineSub",{count:s}):void 0,tone:(f=l.hosts)!=null&&f.length?"ok":"idle"}),h.jsx(Zl,{label:n("admin.activeUsers"),value:a,sub:n("admin.acrossWindows",{count:((m=l.clients)==null?void 0:m.length)||0}),tone:a?"accent":"idle"}),h.jsx(Zl,{label:n("admin.activePtys"),value:((p=l.ptys)==null?void 0:p.length)||0,sub:n("admin.terminalShells"),tone:(g=l.ptys)!=null&&g.length?"info":"idle"}),h.jsx(Zl,{label:n("admin.statInbound"),value:n("admin.perSecond",{value:la(((y=l.throughput)==null?void 0:y.bytesInPerSec)||0)}),sub:n("admin.statTotal",{value:la(((v=l.throughput)==null?void 0:v.bytesIn)||0)}),tone:"accent"}),h.jsx(Zl,{label:n("admin.statOutbound"),value:n("admin.perSecond",{value:la(((w=l.throughput)==null?void 0:w.bytesOutPerSec)||0)}),sub:n("admin.statTotal",{value:la(((x=l.throughput)==null?void 0:x.bytesOut)||0)}),tone:"ok"}),h.jsx(Zl,{label:n("admin.uptime"),value:yb(l.uptimeSeconds||0,n,!0),title:yb(l.uptimeSeconds||0,n),sub:l.startTime?n("admin.startedAt",{time:new Date(l.startTime).toLocaleTimeString()}):n("admin.startedRecently")})]}),h.jsx(iA,{hosts:l.hosts||[],devices:l.devices,clients:l.clients||[]})]})},aA=({ptys:l})=>{const{t:n}=Ee(),a=l.some(r=>r.hostId),s=[{key:"id",header:n("admin.colPtyId"),render:r=>h.jsx("span",{className:"font-bold text-tui-accent",children:r.id})},...a?[{key:"host",header:n("admin.colHost"),render:r=>h.jsx("span",{className:"text-tui-text",children:r.hostId})}]:[],{key:"pid",header:n("admin.colPid"),width:9,render:r=>h.jsx("span",{className:"text-tui-muted",children:r.pid})},{key:"command",header:n("admin.colCommand"),render:r=>h.jsx("code",{className:"border border-tui-border-dim bg-tui-mantle px-1 text-tui-text",children:r.command})},{key:"grid",header:n("admin.colGrid"),width:11,render:r=>h.jsxs("span",{className:"whitespace-nowrap text-tui-muted",children:[r.cols,h.jsx("span",{"aria-hidden":"true",className:"mx-0.5 text-tui-faint",children:"×"}),r.rows]})},{key:"cwd",header:n("admin.colCwd"),className:"max-w-xs truncate",render:r=>h.jsx("span",{className:"text-tui-muted",children:r.cwd||"~"})},{key:"viewers",header:n("admin.colViewers"),align:"right",width:9,render:r=>h.jsx("span",{className:"font-bold text-tui-ok",children:r.activeClients})}];return h.jsx(Et,{title:n("admin.activePtysTitle",{count:l.length}),bodyClassName:"-mx-1",children:h.jsx($d,{columns:s,items:l,rowKey:r=>r.id,empty:n("admin.noPtys")})})};function Od(l){if(typeof window>"u"||!l||l.startsWith("/"))return"";try{const n=new URL(l.replace(/^ws/,"http")),a=n.pathname.replace(/\/ws\/client\/?$/,"").replace(/\/+$/,"");return n.origin===window.location.origin&&!a?"":`${n.origin}${a}`}catch{return""}}function Es(l,n){const a=Od(l);return a?`${a}${n.startsWith("/")?n:`/${n}`}`:n}async function sA(l){try{const a=await fetch(Es(l,"/api/info"),{headers:{Accept:"application/json"}});if(a.ok)return await a.json()}catch{}return{ok:!0,version:"0.1.0",protocol:1,relayMode:!!(l&&!l.startsWith("/")&&!l.includes("localhost")&&!l.includes("127.0.0.1")&&typeof window<"u"&&!l.startsWith(window.location.origin.replace("http","ws")))?"remote":"local",adminConfigured:!1,adminPath:"/admin",adminStatusPath:"/api/admin/status"}}async function xb(l,n){const a=await fetch(l,{headers:{Accept:"application/json",...n}});if(a.status===401||a.status===403)return{kind:"denied",status:a.status};if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);return{kind:"ok",data:await a.json()}}async function oA(l,n,a){return(await fetch(Es(l,`/api/admin/devices/${encodeURIComponent(a)}`),{method:"DELETE",headers:{Accept:"application/json","X-Relay-Admin-Token":n}})).ok}function rA(l,n,a){return l!=null&&l.adminPath?l.publicUrl?`${l.publicUrl.replace(/\/$/,"")}${l.adminPath}`:Es(a,l.adminPath):n!=null&&n.remoteAdminUrl?n.remoteAdminUrl:a?Es(a,"/admin"):"/admin"}function cA({wsUrl:l,deviceToken:n,adminToken:a,relayOrigin:s,refreshInterval:r,t:c}){const[f,m]=M.useState(null),[p,g]=M.useState(null),[y,v]=M.useState(!1),[w,x]=M.useState(!0),[S,T]=M.useState(null),[A,k]=M.useState(!1),[E,N]=M.useState(null);M.useEffect(()=>{m(null),g(null),v(!1)},[s]),M.useEffect(()=>{let K=!0;return x(!0),sA(l).then(V=>{K&&(g(V),v(!0))}),()=>{K=!1}},[l,s]);const B=(p==null?void 0:p.relayMode)==="remote",L=M.useCallback((K,V)=>{if(K.kind==="denied"){k(!0),T(V),m(null);return}m(K.data),T(null),k(!1),N(new Date)},[]),D=M.useCallback((K,V)=>{k(!1),T(K instanceof Error?K.message:V),m(null)},[]),R=M.useCallback(async()=>{if(y){if(B){if(!a){m(null),x(!1),T(null),k(!1);return}try{x(!0);const K=await xb(Es(l,(p==null?void 0:p.adminStatusPath)||"/api/admin/status"),{"X-Relay-Admin-Token":a});L(K,c("admin.relayAdminAuthError"))}catch(K){console.warn("GET /api/admin/status request failed:",K),D(K,"Failed to fetch remote admin status")}finally{x(!1)}return}try{x(!0);const K=await xb("/api/status",n?{Authorization:`Bearer ${n}`}:{});L(K,K.kind==="denied"?`Authentication failed (HTTP ${K.status}): Access denied. Please configure an authorized token or pair with the host.`:"")}catch(K){console.warn("GET /api/status request failed:",K),D(K,"Failed to fetch status")}finally{x(!1)}}},[y,B,a,p,n,l,s,c]),z=M.useCallback(async K=>{try{if(!await oA(l,a,K)){T(c("admin.revokeFailed"));return}await R()}catch{T(c("admin.revokeFailed"))}},[a,R,l,c]);return M.useEffect(()=>{if(!y)return;R();let K=null;const V=()=>{r>0&&!K&&(K=setInterval(()=>{document.visibilityState==="visible"&&R()},r))},te=()=>{K&&(clearInterval(K),K=null)},Z=()=>{document.visibilityState==="visible"?(R(),V()):te()};return V(),document.addEventListener("visibilitychange",Z),()=>{te(),document.removeEventListener("visibilitychange",Z)}},[y,R,r]),{data:f,relayInfo:p,infoLoaded:y,isRemoteRelay:B,loading:w,error:S,isAuthError:A,lastUpdated:E,fetchStatus:R,revokeDevice:z}}const dd="h-7 py-0",uA=({onBackToTerminal:l,onOpenPairing:n,showBack:a=!1})=>{var ve,X,ue;const{settings:s,updateSettings:r,t:c}=Ee(),f=Od(s.wsUrl)||(typeof window<"u"?window.location.origin:"local"),m=((ve=s.adminTokens)==null?void 0:ve[f])||(f===(typeof window<"u"?window.location.origin:"local")?s.adminToken:"")||"",[p,g]=M.useState(3e3),[y,v]=M.useState("overview"),[w,x]=M.useState(m),[S,T]=M.useState(m),[A,k]=M.useState(!!m),E=!Od(s.wsUrl);M.useEffect(()=>{x(m),T(m),k(!!m)},[f]);const{data:N,relayInfo:B,infoLoaded:L,isRemoteRelay:D,loading:R,error:z,isAuthError:K,lastUpdated:V,fetchStatus:te,revokeDevice:Z}=cA({wsUrl:s.wsUrl,deviceToken:s.token,adminToken:S,relayOrigin:f,refreshInterval:p,t:c}),ie=oe=>{oe.preventDefault();const pe=w.trim();r({adminToken:pe,adminTokens:{...s.adminTokens||{},[f]:pe}}),T(pe),k(!!pe)},re=rA(B,N,s.wsUrl),ce=N?[{id:"overview",label:c("admin.tabOverview"),index:1},{id:"clients",label:c("admin.tabClients",{count:((X=N.clients)==null?void 0:X.length)||0}),index:2},{id:"ptys",label:c("admin.tabPtys",{count:((ue=N.ptys)==null?void 0:ue.length)||0}),index:3},...N.devices?[{id:"devices",label:c("admin.tabDevices",{count:N.devices.length}),index:4}]:[]]:[],O=ce.map(oe=>oe.id).join("|");M.useEffect(()=>{const oe=O?O.split("|"):[],pe=se=>{if(se.ctrlKey||se.altKey||se.metaKey)return;const xe=se.target;if(xe instanceof HTMLInputElement||xe instanceof HTMLTextAreaElement||xe instanceof HTMLSelectElement||xe!=null&&xe.isContentEditable||document.querySelector('[role="dialog"]'))return;if(se.key==="Escape"&&l){se.preventDefault(),l();return}if(se.key.toLowerCase()==="r"){se.preventDefault(),te();return}const ae=Number.parseInt(se.key,10)-1;Number.isInteger(ae)&&ae>=0&&ae<oe.length&&(se.preventDefault(),v(oe[ae]))};return window.addEventListener("keydown",pe),()=>window.removeEventListener("keydown",pe)},[te,l,O]);const J=(B==null?void 0:B.version)||(N==null?void 0:N.version)||"0.1.0",I=a&&l?h.jsx(Ae,{variant:"ghost",onClick:l,title:c("admin.returnToTerminal"),"aria-label":c("admin.returnToTerminal"),glyph:_e.arrowLeft,brackets:!1,className:dd,children:h.jsx("span",{className:"sr-only",children:c("admin.returnToTerminal")})}):null,le=h.jsxs(h.Fragment,{children:[h.jsxs("span",{className:"hidden items-center gap-1.5 whitespace-nowrap text-tui-sm sm:flex",children:[h.jsxs("span",{className:"text-tui-faint",children:["v",J]}),h.jsx(Yd,{}),h.jsx("span",{className:D?"text-tui-alt":"text-tui-ok",children:c(D?"admin.modeRemote":"admin.localWorkstationBadge")})]}),N?h.jsxs(h.Fragment,{children:[h.jsxs("label",{className:"hidden items-center gap-1.5 text-tui-sm text-tui-muted md:flex",children:[h.jsx("span",{children:c("admin.autoRefresh")}),h.jsxs(Tr,{value:p,onChange:oe=>g(Number(oe.target.value)),"aria-label":c("admin.autoRefresh"),className:ne("w-auto",dd),children:[h.jsx("option",{value:0,children:c("admin.paused")}),h.jsx("option",{value:1e3,children:"1s"}),h.jsx("option",{value:3e3,children:"3s"}),h.jsx("option",{value:5e3,children:"5s"}),h.jsx("option",{value:1e4,children:"10s"})]})]}),h.jsx(Ae,{variant:"primary",onClick:te,disabled:R,title:c("admin.refreshNow"),className:dd,children:R?h.jsx(ol,{}):c("admin.refreshNow")})]}):null]}),P=L&&D&&!A&&!E,fe=L&&D&&(A||E)&&!N;return h.jsxs(WS,{tabs:ce,activeTabId:y,onSelectTab:oe=>v(oe),tabsAriaLabel:c("header.mainNavigationAria"),toolbarStart:I,toolbarAside:le,hints:[...N?[{keys:"1–4",action:c("admin.hintTabs")},{keys:"r",action:c("admin.hintRefresh")}]:[],...l?[{keys:"esc",action:c("admin.hintBack")}]:[]],footerAside:V?h.jsx("span",{className:"text-tui-faint",children:c("admin.updatedAt",{time:V.toLocaleTimeString()})}):null,bodyClassName:"space-y-3 pb-2",children:[!L&&h.jsx("div",{className:"flex items-center justify-center gap-2 border border-tui-border bg-tui-base px-3 py-8 text-tui text-tui-muted",children:h.jsx(ol,{label:c("admin.loadingStatus")})}),P&&h.jsx(X5,{wsUrl:s.wsUrl,adminUrl:re,onOpenRemoteAdmin:()=>window.open(re,"_blank","noopener,noreferrer"),onSignIn:()=>k(!0)}),fe&&h.jsx(Z5,{adminConfigured:B==null?void 0:B.adminConfigured,isAuthError:K,tokenInput:w,onTokenInput:x,onSubmit:ie,isSameOriginRelay:E,onBackToTerminal:l,showBack:a,onCancel:()=>k(!1)}),L&&!D&&K&&h.jsx(W5,{onOpenPairing:n,onRetry:te}),L&&z&&!K&&h.jsx(Ri,{tone:"warn",action:h.jsx(Ae,{variant:"warn",onClick:te,children:c("common.retry")}),children:c("admin.errorConnecting",{error:z})}),N&&h.jsxs(h.Fragment,{children:[y==="overview"&&h.jsx(lA,{data:N}),y==="clients"&&h.jsx(eA,{clients:N.clients||[]}),y==="ptys"&&h.jsx(aA,{ptys:N.ptys||[]}),y==="devices"&&h.jsx(tA,{devices:N.devices||[],clients:N.clients||[],onRevoke:Z})]})]})},fd="tui-focusable group flex h-11 w-full select-none items-center gap-2 border px-2 text-left text-tui transition-colors",hd="border-tui-border text-tui-muted hover:border-tui-accent hover:text-tui-accent active:bg-tui-selection",dA="border-tui-accent bg-tui-selection text-tui-accent",md=({active:l=!1})=>h.jsx("span",{"aria-hidden":"true",className:ne("shrink-0",l?"text-tui-accent":"text-tui-faint group-hover:text-tui-accent"),children:_e.cursor}),fA=({onClose:l,onOpenSettings:n,onAddProfile:a=()=>{}})=>{const{settings:s,updateSettings:r,language:c,setLanguage:f,t:m}=Ee(),{connectionState:p,stateDetail:g,rttMs:y,hostId:v,connect:w}=it(),{addToast:x}=dn(),{copied:S,copy:T}=Wd(),A=S!==null,k=Qd(p,m),E=L=>()=>{var R;const D=document.activeElement;(R=D==null?void 0:D.blur)==null||R.call(D),L()},N=()=>T(s.clientId,m("toasts.clientIdCopied",{id:s.clientId}),"info"),B=()=>{const L=c==="zh"?"en":"zh";f(L),x("info",Dd(L,"toasts.switchedLanguage",{lang:L==="zh"?"简体中文":"English"}))};return h.jsxs("div",{className:"flex flex-col gap-3 px-3 pb-2 pt-2",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-tui-border pb-1.5",children:[h.jsx("h2",{className:"text-tui font-bold uppercase text-tui-accent",children:m("mobile.sessionControls")}),h.jsx(Ae,{variant:"ghost",onClick:l,"aria-label":m("mobile.closeSessionControls"),children:"esc"})]}),h.jsx(Et,{title:m("profiles.title"),tone:"accent",bodyClassName:"space-y-1",children:h.jsx(Jd,{mobile:!0,onAddProfile:a})}),h.jsxs(Et,{title:m("common.status"),tone:k.level==="ok"?"ok":k.level==="bad"?"bad":"warn",bodyClassName:"space-y-1.5",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[h.jsx(bn,{level:k.level}),h.jsx("span",{className:"truncate text-tui uppercase text-tui-text",children:k.label}),p==="connected"&&y!==null&&h.jsxs("span",{className:"text-tui-sm text-tui-muted",children:[y,"ms"]})]}),k.actionLabel&&h.jsx(Ae,{variant:"primary",onClick:()=>w(),className:"shrink-0",children:k.actionLabel})]}),k.needsAttention&&g&&h.jsx("p",{className:"text-tui-sm leading-snug text-tui-muted",children:g}),v&&h.jsx(An,{label:m("common.host"),labelWidth:9,children:v}),h.jsxs("button",{type:"button",onClick:N,className:"tui-focusable flex w-full items-baseline gap-2 text-left text-tui",title:m("header.copyClientIdTitle"),children:[h.jsx("span",{className:"shrink-0 text-tui-muted",style:{width:"9ch"},children:m("header.clientIdLabel")}),h.jsx("span",{className:"min-w-0 flex-1 truncate text-tui-text",children:s.clientId}),h.jsx("span",{"aria-hidden":"true",className:ne("shrink-0",A?"text-tui-ok":"text-tui-faint"),children:A?_e.check:"⧉"})]})]}),h.jsx(Et,{title:m("mobile.inputControl"),tone:"accent","aria-label":m("mobile.terminalControlAria"),children:h.jsx(d0,{className:"h-11"})}),h.jsxs(Et,{title:m("mobile.menu"),tone:"accent",bodyClassName:"flex flex-col gap-1",children:[h.jsxs("button",{type:"button",onClick:B,className:ne(fd,hd),"aria-label":m("header.languageToggleTitle"),children:[h.jsx(md,{}),h.jsx("span",{className:"truncate",children:c==="zh"?"English":"中文"})]}),h.jsxs("button",{type:"button",onClick:E(n),className:ne(fd,hd),"aria-label":m("mobile.settingsAria"),children:[h.jsx(md,{}),h.jsx("span",{className:"truncate",children:m("common.settings")})]}),h.jsxs("button",{type:"button",onClick:()=>r({toolbarVisible:!s.toolbarVisible}),className:ne(fd,s.toolbarVisible?dA:hd),"aria-label":m("mobile.keybarAria"),"aria-pressed":s.toolbarVisible,children:[h.jsx(md,{active:s.toolbarVisible}),h.jsx("span",{className:"truncate",children:m("common.keyBar")}),h.jsx("span",{"aria-hidden":"true",className:"ml-auto shrink-0 text-tui-sm",children:s.toolbarVisible?"[x]":"[ ]"})]})]})]})},hA=({onAddProfile:l})=>{const{t:n}=Ee(),{rttMs:a}=it();return h.jsxs("footer",{"data-testid":"mobile-status-bar",role:"status","aria-label":n("mobile.statusBarAria"),className:"absolute inset-x-0 bottom-0 z-40 flex h-11 shrink-0 items-center gap-2 border-t border-tui-border bg-tui-mantle px-1 text-tui-sm",children:[h.jsx(Jd,{statusBar:!0,onAddProfile:l}),h.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-tui-border",children:"│"}),h.jsx(u0,{compact:!0}),h.jsx(m0,{compact:!0}),h.jsxs("span",{className:"flex shrink-0 items-center gap-1 px-1 text-tui-muted",title:n("header.latencyTitle"),children:[h.jsx("span",{className:"text-tui-faint",children:"RTT"}),h.jsx("span",{className:ne(a===null?"text-tui-faint":"text-tui-text"),children:a===null?"—":`${a}ms`})]})]})},mA=({onOpenSettings:l,onAddProfile:n=()=>{}})=>{const{t:a}=Ee(),{connectionState:s,isController:r}=it(),[c,f]=M.useState(!1),m=M.useRef(null),p=M.useCallback(()=>f(!1),[]);M.useEffect(()=>{if(!c)return;const y=v=>{if(!(v.ctrlKey||v.altKey||v.metaKey)&&v.key==="Escape"){const w=v.target;w&&typeof w.closest=="function"&&!!w.closest("#terminal-container")||(v.stopPropagation(),v.preventDefault(),p())}};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[c,p]),M.useEffect(()=>{var y;c&&((y=m.current)==null||y.focus({preventScroll:!0}))},[c]);const g=Qd(s,a);return h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":"mobile-topbar",role:"toolbar","aria-label":a("mobile.sessionControls"),className:"pointer-events-none absolute inset-x-0 top-0 z-40 flex h-12 items-center justify-between gap-2 border-b border-tui-border bg-tui-mantle px-2 text-tui",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-tui-sm text-tui-muted",children:[h.jsx("span",{"aria-hidden":"true",className:"shrink-0 font-bold text-tui-accent",children:"herdr"}),h.jsx(Yd,{className:"shrink-0"}),h.jsx(bn,{level:g.level}),h.jsx("span",{className:"truncate uppercase",children:g.label})]}),h.jsxs("button",{type:"button","data-testid":"mobile-chrome-trigger",onClick:()=>f(!0),"aria-label":a("mobile.sessionControls"),"aria-expanded":c,"aria-haspopup":"dialog",className:ne("tui-focusable pointer-events-auto flex h-9 shrink-0 select-none items-center gap-1.5 border px-2 text-tui uppercase transition-colors",g.needsAttention?"border-tui-warn text-tui-warn":r?"border-tui-border text-tui-muted":"border-tui-accent text-tui-accent"),children:[!r&&!g.needsAttention&&h.jsx("span",{className:"max-w-[8rem] truncate",children:a("common.viewer")}),h.jsx("span",{"aria-hidden":"true",className:"text-tui",children:_e.chevronDown}),h.jsx("span",{"aria-hidden":"true",children:a("mobile.menu")})]})]}),c&&h.jsxs(h.Fragment,{children:[h.jsx("div",{"data-testid":"mobile-sheet-scrim",className:"absolute inset-0 z-40 bg-tui-crust/70",onClick:p,"aria-hidden":"true"}),h.jsx("div",{ref:m,"data-testid":"mobile-control-sheet",role:"dialog","aria-modal":"true","aria-label":a("mobile.sessionControls"),tabIndex:-1,className:"herdr-sheet absolute inset-x-0 bottom-0 z-50 max-h-[85%] overflow-y-auto border-t border-tui-border bg-tui-base pb-3 focus:outline-none",children:h.jsx(fA,{onClose:p,onOpenSettings:()=>{p(),l()},onAddProfile:()=>{p(),n()}})})]}),h.jsx(hA,{onAddProfile:n})]})},pA=()=>{const{activeProfile:l,t:n}=Ee(),{herdrLaunch:a,startHerdr:s,hostname:r}=it();if(!a)return null;const c=r||(l==null?void 0:l.displayName)||n("herdrLaunch.thisHost"),f=a.phase==="failed";return h.jsx("div",{"data-testid":"herdr-start-prompt",className:"absolute inset-0 z-30 flex items-center justify-center bg-tui-crust/85 p-3",children:h.jsx(Et,{title:n(f?"herdrLaunch.failedTitle":"herdrLaunch.title"),tone:f?"bad":"warn",className:"w-full max-w-md",bodyClassName:"space-y-3","aria-label":n("herdrLaunch.title"),children:a.phase==="starting"?h.jsxs("p",{className:"flex items-center gap-2 text-tui-text",role:"status",children:[h.jsx(ol,{}),h.jsx("span",{children:n("herdrLaunch.starting",{host:c})})]}):h.jsxs(h.Fragment,{children:[h.jsx("p",{className:"leading-snug text-tui-text",children:n("herdrLaunch.body",{host:c})}),f&&a.message?h.jsx(Ri,{tone:"bad",children:h.jsx("pre",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap break-words font-mono text-tui-sm",children:a.message})}):null,h.jsx("p",{className:"text-tui-sm leading-snug text-tui-faint",children:n("herdrLaunch.scope")}),h.jsx("div",{className:"flex justify-end",children:h.jsx(Ae,{variant:"primary",onClick:s,autoFocus:!0,children:n(f?"common.retry":"herdrLaunch.start")})})]})})})},g0="--app-height",b0="--keyboard-inset",gA=80;function bA(){if(typeof window>"u")return{height:768,keyboardInset:0};const l=window.innerHeight||768,n=window.visualViewport;if(n&&typeof n.height=="number"&&n.height>0){const a=l-n.height-(n.offsetTop||0),s=a>=gA?Math.round(a):0;return{height:Math.round(n.height),keyboardInset:s}}return{height:l,keyboardInset:0}}function wb(l,n=bA()){return l.style.setProperty(g0,`${n.height}px`),l.style.setProperty(b0,`${n.keyboardInset}px`),n}function yA(l=typeof document<"u"?document.documentElement:null){if(!l||typeof window>"u")return()=>{};let n=null;const a=()=>{n=null,wb(l)},s=()=>{if(n===null){if(typeof requestAnimationFrame!="function"){a();return}n=requestAnimationFrame(a)}};wb(l);const r=window.visualViewport;return r==null||r.addEventListener("resize",s),r==null||r.addEventListener("scroll",s),window.addEventListener("resize",s),window.addEventListener("orientationchange",s),()=>{n!==null&&typeof cancelAnimationFrame=="function"&&(cancelAnimationFrame(n),n=null),r==null||r.removeEventListener("resize",s),r==null||r.removeEventListener("scroll",s),window.removeEventListener("resize",s),window.removeEventListener("orientationchange",s),l.style.removeProperty(g0),l.style.removeProperty(b0)}}const vA=900;function Sb(){if(typeof window>"u")return!1;const l=oa();return l<Bd?!0:l<=vA}function xA(){const[l,n]=M.useState(Sb);return M.useEffect(()=>{var r,c;const a=()=>{const f=Sb();n(m=>m===f?m:f)};a();let s=null;try{s=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)"):null}catch{s=null}return(r=s==null?void 0:s.addEventListener)==null||r.call(s,"change",a),window.addEventListener("resize",a),window.addEventListener("orientationchange",a),(c=window.visualViewport)==null||c.addEventListener("resize",a),()=>{var f,m;(f=s==null?void 0:s.removeEventListener)==null||f.call(s,"change",a),window.removeEventListener("resize",a),window.removeEventListener("orientationchange",a),(m=window.visualViewport)==null||m.removeEventListener("resize",a)}},[]),l}function wA(l){const n=l.target;if(!n)return!1;if(n.id==="terminal-container"||n.id==="terminal-frame"||n.id==="terminal-surface"||n.classList.contains("xterm-helper-textarea")||n.classList.contains("xterm")||n.closest("#terminal-container")||n.closest(".xterm"))return!0;if(typeof document<"u"&&document.activeElement){const a=document.activeElement;if(a.id==="terminal-container"||a.classList.contains("xterm-helper-textarea")||a.closest("#terminal-container")||a.closest(".xterm"))return!0}return!1}function SA(l,n={}){if(typeof window>"u")return()=>{};const a=s=>{var r;s.ctrlKey||s.altKey||s.metaKey||s.key==="Escape"&&(n.isModalOpen||n.isSheetOpen)&&(wA(s)||(s.preventDefault(),s.stopPropagation(),(r=l.onCloseModals)==null||r.call(l)))};return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}}function CA(){const[l,n]=M.useState("terminal"),[a,s]=M.useState(!1),[r,c]=M.useState(!1),[f,m]=M.useState(void 0),p=V=>{m(V),c(!0)},{updateSettings:g,addProfileAndConnect:y,settings:v}=Ee(),{connectionState:w,stateDetail:x,stateCode:S,lastPairedAt:T}=it();J1();const A=xA();M.useEffect(()=>yA(),[]),M.useEffect(()=>{zb()},[]),M.useEffect(()=>{const V=a||r;if(V)return SA({onCloseModals:()=>{s(!1),c(!1)}},{isModalOpen:V})},[a,r]),M.useEffect(()=>{var te;const V=()=>{const Z=window.location.pathname,ie=window.location.hash;n(Z==="/admin"||ie==="#admin"?"admin":"terminal")};V(),window.addEventListener("popstate",V),window.addEventListener("hashchange",V);try{const Z=new URL(window.location.href),ie=(te=Z.searchParams.get("pairCode"))==null?void 0:te.toUpperCase();ie&&hr().token?y({wsUrl:Ut,pairCode:ie}):ie&&g({pairCode:ie});let re=!1;if(Z.searchParams.has("token")&&(Z.searchParams.delete("token"),re=!0),Z.searchParams.has("pairCode")&&(Z.searchParams.delete("pairCode"),re=!0),re){const ce=Z.searchParams.toString(),O=Z.pathname+(ce?`?${ce}`:"")+Z.hash;window.history.replaceState({},"",O)}}catch(Z){console.warn("Failed to parse URL query params:",Z)}return()=>{window.removeEventListener("popstate",V),window.removeEventListener("hashchange",V)}},[g,y]);const k=()=>s(!0),E=V=>{n(V),V==="admin"?window.history.pushState({},"","/admin"):window.history.pushState({},"","/")},N=!v.token&&!v.pairCode&&w!=="connected",B=w==="error"&&(["auth_required","unauthorized","device_revoked"].includes(S||"")||/auth|unauthor|forbidden|permission|token|pair/i.test(x||"")),L=N||B,[D,R]=M.useState(!L);M.useEffect(()=>{L||R(!0)},[L]),M.useEffect(()=>{T&&(s(!1),R(!0),n("terminal"))},[T]);const z=l==="terminal"&&!L,K=V=>({visibility:V?"visible":"hidden",opacity:V?1:0,pointerEvents:V?"auto":"none",zIndex:V?1:0});return h.jsxs("div",{"data-testid":"app-shell",style:A?{paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"env(safe-area-inset-bottom, 0px)",paddingLeft:"env(safe-area-inset-left, 0px)",paddingRight:"env(safe-area-inset-right, 0px)"}:void 0,className:"flex h-full w-full select-none flex-col overflow-hidden bg-tui-crust font-mono text-tui text-tui-text",onContextMenu:V=>{V.preventDefault(),V.stopPropagation()},children:[!A&&h.jsx(eC,{currentView:l,onNavigate:E,onOpenSettings:()=>p()}),!A&&!L&&h.jsx(tC,{}),h.jsxs("div",{className:"flex-1 min-h-0 w-full overflow-hidden relative",children:[D&&h.jsxs("div",{"data-testid":"terminal-layer",className:`absolute ${A?"inset-x-0 top-12 bottom-11":"inset-0"} flex flex-col min-h-0 w-full overflow-hidden`,style:K(z),"aria-hidden":!z,children:[h.jsx(JM,{isActive:z}),h.jsx(S5,{compact:A,onCustomize:()=>p("agentKeymaps")}),h.jsx(pA,{}),h.jsx(O5,{})]}),l==="terminal"&&L&&h.jsx("div",{"data-testid":"onboarding-layer",className:"absolute inset-0 flex flex-col min-h-0 w-full overflow-hidden z-10",children:h.jsx(t5,{onPairedSuccess:()=>{}})}),l==="admin"&&h.jsx("div",{"data-testid":"admin-layer",className:"absolute inset-0 flex flex-col min-h-0 w-full overflow-hidden z-20",children:h.jsx(uA,{onBackToTerminal:()=>E("terminal"),onOpenPairing:k,showBack:A})}),A&&z&&h.jsx(mA,{onOpenSettings:()=>p(),onAddProfile:k})]}),!A&&l!=="admin"&&h.jsx(q5,{onAddProfile:k}),h.jsx(T5,{isOpen:a,onClose:()=>s(!1)}),h.jsx(H5,{isOpen:r,initialTab:f,onClose:()=>c(!1),onOpenAdmin:()=>{c(!1),E("admin")}}),h.jsx(K5,{})]})}function TA(){return h.jsx(I1,{children:h.jsx(CA,{})})}const y0=document.getElementById("root");if(!y0)throw new Error("Root element not found");Fx.createRoot(y0).render(h.jsx(Jn.StrictMode,{children:h.jsx(TA,{})}));
@@ -28,7 +28,7 @@
28
28
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
29
29
  <meta name="description" content="Mobile-first remote terminal WebUI for Herdr agent multiplexer" />
30
30
  <title>Herdr Remote WebUI</title>
31
- <script type="module" crossorigin src="/assets/index-BxVyQeOw.js"></script>
31
+ <script type="module" crossorigin src="/assets/index-BeCHdlFG.js"></script>
32
32
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-CYSfZuHu.js">
33
33
  <link rel="modulepreload" crossorigin href="/assets/vendor-xterm-BhCxil_4.js">
34
34
  <link rel="stylesheet" crossorigin href="/assets/index-CI0UHcI0.css">