@dev-anywhere/relay 0.8.0 → 0.8.1

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.
@@ -531,7 +531,7 @@ ${s}`,l=gB(`${mS(r.kind)}:${r.path}`,o,r.kind);n.push(l.kind==="diff"?{...l,co
531
531
 
532
532
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
533
533
 
534
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Zte="DialogDescriptionWarning",Qte=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${rz(Zte).contentName}}.`;return b.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},cE=UB,Jte=qB,uE=VB,dE=KB,fE=XB,iz=ZB,sz=JB,ay=tz;function ene(e){const t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function tne(e){const[t,n]=b.useState(void 0);return Di(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const u=s.borderBoxSize,d=Array.isArray(u)?u[0]:u;o=d.inlineSize,l=d.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const nne=["top","right","bottom","left"],kl=Math.min,vs=Math.max,xv=Math.round,ug=Math.floor,No=e=>({x:e,y:e}),rne={left:"right",right:"left",bottom:"top",top:"bottom"};function xS(e,t,n){return vs(e,kl(t,n))}function ya(e,t){return typeof e=="function"?e(t):e}function ba(e){return e.split("-")[0]}function Pd(e){return e.split("-")[1]}function hE(e){return e==="x"?"y":"x"}function pE(e){return e==="y"?"height":"width"}function Ro(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function mE(e){return hE(Ro(e))}function ine(e,t,n){n===void 0&&(n=!1);const r=Pd(e),i=mE(e),s=pE(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Ev(o)),[o,Ev(o)]}function sne(e){const t=Ev(e);return[ES(e),t,ES(t)]}function ES(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const LN=["left","right"],DN=["right","left"],one=["top","bottom"],ane=["bottom","top"];function lne(e,t,n){switch(e){case"top":case"bottom":return n?t?DN:LN:t?LN:DN;case"left":case"right":return t?one:ane;default:return[]}}function cne(e,t,n,r){const i=Pd(e);let s=lne(ba(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(ES)))),s}function Ev(e){const t=ba(e);return rne[t]+e.slice(t.length)}function une(e){return{top:0,right:0,bottom:0,left:0,...e}}function oz(e){return typeof e!="number"?une(e):{top:e,right:e,bottom:e,left:e}}function Cv(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function IN(e,t,n){let{reference:r,floating:i}=e;const s=Ro(t),o=mE(t),l=pE(o),u=ba(t),d=s==="y",f=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let v;switch(u){case"top":v={x:f,y:r.y-i.height};break;case"bottom":v={x:f,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:p};break;case"left":v={x:r.x-i.width,y:p};break;default:v={x:r.x,y:r.y}}switch(Pd(t)){case"start":v[o]-=y*(n&&d?-1:1);break;case"end":v[o]+=y*(n&&d?-1:1);break}return v}async function dne(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:f="viewport",elementContext:p="floating",altBoundary:y=!1,padding:v=0}=ya(t,e),_=oz(v),S=l[y?p==="floating"?"reference":"floating":p],x=Cv(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(S)))==null||n?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:f,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),R=await(s.isElement==null?void 0:s.isElement(T))?await(s.getScale==null?void 0:s.getScale(T))||{x:1,y:1}:{x:1,y:1},N=Cv(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:T,strategy:u}):k);return{top:(x.top-N.top+_.top)/R.y,bottom:(N.bottom-x.bottom+_.bottom)/R.y,left:(x.left-N.left+_.left)/R.x,right:(N.right-x.right+_.right)/R.x}}const fne=50,hne=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:dne},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:f,y:p}=IN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const S=s[w];if(!S)continue;const{name:x,fn:k}=S,{x:T,y:R,data:N,reset:A}=await k({x:f,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=T??f,p=R??p,_[x]={..._[x],...N},A&&v<fne&&(v++,typeof A=="object"&&(A.placement&&(y=A.placement),A.rects&&(d=A.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):A.rects),{x:f,y:p}=IN(d,y,u)),w=-1)}return{x:f,y:p,placement:y,strategy:i,middlewareData:_}},pne=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:u}=t,{element:d,padding:f=0}=ya(e,t)||{};if(d==null)return{};const p=oz(f),y={x:n,y:r},v=mE(i),_=pE(v),w=await o.getDimensions(d),S=v==="y",x=S?"top":"left",k=S?"bottom":"right",T=S?"clientHeight":"clientWidth",R=s.reference[_]+s.reference[v]-y[v]-s.floating[_],N=y[v]-s.reference[v],A=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let O=A?A[T]:0;(!O||!await(o.isElement==null?void 0:o.isElement(A)))&&(O=l.floating[T]||s.floating[_]);const D=R/2-N/2,K=O/2-w[_]/2-1,U=kl(p[x],K),X=kl(p[k],K),z=U,M=O-w[_]-X,F=O/2-w[_]/2+D,B=xS(z,F,M),P=!u.arrow&&Pd(i)!=null&&F!==B&&s.reference[_]/2-(F<z?U:X)-w[_]/2<0,I=P?F<z?F-z:F-M:0;return{[v]:y[v]+I,data:{[v]:B,centerOffset:F-B-I,...P&&{alignmentOffset:I}},reset:P}}}),mne=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:u,elements:d}=t,{mainAxis:f=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=ya(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=ba(i),k=Ro(l),T=ba(l)===l,R=await(u.isRTL==null?void 0:u.isRTL(d.floating)),N=y||(T||!w?[Ev(l)]:sne(l)),A=_!=="none";!y&&A&&N.push(...cne(l,w,_,R));const O=[l,...N],D=await u.detectOverflow(t,S),K=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&K.push(D[x]),p){const F=ine(i,o,R);K.push(D[F[0]],D[F[1]])}if(U=[...U,{placement:i,overflows:K}],!K.every(F=>F<=0)){var X,z;const F=(((X=s.flip)==null?void 0:X.index)||0)+1,B=O[F];if(B&&(!(p==="alignment"?k!==Ro(B):!1)||U.every(W=>Ro(W.placement)===k?W.overflows[0]>0:!0)))return{data:{index:F,overflows:U},reset:{placement:B}};let P=(z=U.filter(I=>I.overflows[0]<=0).sort((I,W)=>I.overflows[1]-W.overflows[1])[0])==null?void 0:z.placement;if(!P)switch(v){case"bestFit":{var M;const I=(M=U.filter(W=>{if(A){const j=Ro(W.placement);return j===k||j==="y"}return!0}).map(W=>[W.placement,W.overflows.filter(j=>j>0).reduce((j,L)=>j+L,0)]).sort((W,j)=>W[1]-j[1])[0])==null?void 0:M[0];I&&(P=I);break}case"initialPlacement":P=l;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function BN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function zN(e){return nne.some(t=>e[t]>=0)}const gne=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ya(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=BN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:zN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=BN(o,n.floating);return{data:{escapedOffsets:l,escaped:zN(l)}}}default:return{}}}}},az=new Set(["left","top"]);async function vne(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=ba(n),l=Pd(n),u=Ro(n)==="y",d=az.has(o)?-1:1,f=s&&u?-1:1,p=ya(t,e);let{mainAxis:y,crossAxis:v,alignmentAxis:_}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof _=="number"&&(v=l==="end"?_*-1:_),u?{x:v*f,y:y*d}:{x:y*d,y:v*f}}const yne=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:s,placement:o,middlewareData:l}=t,u=await vne(t,e);return o===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:s+u.y,data:{...u,placement:o}}}}},bne=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:x=>{let{x:k,y:T}=x;return{x:k,y:T}}},...d}=ya(e,t),f={x:n,y:r},p=await s.detectOverflow(t,d),y=Ro(ba(i)),v=hE(y);let _=f[v],w=f[y];if(o){const x=v==="y"?"top":"left",k=v==="y"?"bottom":"right",T=_+p[x],R=_-p[k];_=xS(T,_,R)}if(l){const x=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[x],R=w-p[k];w=xS(T,w,R)}const S=u.fn({...t,[v]:_,[y]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[v]:o,[y]:l}}}}}},_ne=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:u=!0,crossAxis:d=!0}=ya(e,t),f={x:n,y:r},p=Ro(i),y=hE(p);let v=f[y],_=f[p];const w=ya(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const T=y==="y"?"height":"width",R=s.reference[y]-s.floating[T]+S.mainAxis,N=s.reference[y]+s.reference[T]-S.mainAxis;v<R?v=R:v>N&&(v=N)}if(d){var x,k;const T=y==="y"?"width":"height",R=az.has(ba(i)),N=s.reference[p]-s.floating[T]+(R&&((x=o.offset)==null?void 0:x[p])||0)+(R?0:S.crossAxis),A=s.reference[p]+s.reference[T]+(R?0:((k=o.offset)==null?void 0:k[p])||0)-(R?S.crossAxis:0);_<N?_=N:_>A&&(_=A)}return{[y]:v,[p]:_}}}},wne=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:u=()=>{},...d}=ya(e,t),f=await o.detectOverflow(t,d),p=ba(i),y=Pd(i),v=Ro(i)==="y",{width:_,height:w}=s.floating;let S,x;p==="top"||p==="bottom"?(S=p,x=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=p,S=y==="end"?"top":"bottom");const k=w-f.top-f.bottom,T=_-f.left-f.right,R=kl(w-f[S],k),N=kl(_-f[x],T),A=!t.middlewareData.shift;let O=R,D=N;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(D=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(O=k),A&&!y){const U=vs(f.left,0),X=vs(f.right,0),z=vs(f.top,0),M=vs(f.bottom,0);v?D=_-2*(U!==0||X!==0?U+X:vs(f.left,f.right)):O=w-2*(z!==0||M!==0?z+M:vs(f.top,f.bottom))}await u({...t,availableWidth:D,availableHeight:O});const K=await o.getDimensions(l.floating);return _!==K.width||w!==K.height?{reset:{rects:!0}}:{}}}};function ly(){return typeof window<"u"}function Od(e){return lz(e)?(e.nodeName||"").toLowerCase():"#document"}function bs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jo(e){var t;return(t=(lz(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function lz(e){return ly()?e instanceof Node||e instanceof bs(e).Node:!1}function ro(e){return ly()?e instanceof Element||e instanceof bs(e).Element:!1}function Sa(e){return ly()?e instanceof HTMLElement||e instanceof bs(e).HTMLElement:!1}function jN(e){return!ly()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof bs(e).ShadowRoot}function fp(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=io(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Sne(e){return/^(table|td|th)$/.test(Od(e))}function cy(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const xne=/transform|translate|scale|rotate|perspective|filter/,Ene=/paint|layout|strict|content/,lc=e=>!!e&&e!=="none";let Nw;function gE(e){const t=ro(e)?io(e):e;return lc(t.transform)||lc(t.translate)||lc(t.scale)||lc(t.rotate)||lc(t.perspective)||!vE()&&(lc(t.backdropFilter)||lc(t.filter))||xne.test(t.willChange||"")||Ene.test(t.contain||"")}function Cne(e){let t=Tl(e);for(;Sa(t)&&!bd(t);){if(gE(t))return t;if(cy(t))return null;t=Tl(t)}return null}function vE(){return Nw==null&&(Nw=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Nw}function bd(e){return/^(html|body|#document)$/.test(Od(e))}function io(e){return bs(e).getComputedStyle(e)}function uy(e){return ro(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Tl(e){if(Od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||jN(e)&&e.host||jo(e);return jN(t)?t.host:t}function cz(e){const t=Tl(e);return bd(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sa(t)&&fp(t)?t:cz(t)}function $h(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=cz(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=bs(i);if(s){const l=CS(o);return t.concat(o,o.visualViewport||[],fp(i)?i:[],l&&n?$h(l):[])}else return t.concat(i,$h(i,[],n))}function CS(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function uz(e){const t=io(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Sa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=xv(n)!==s||xv(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function yE(e){return ro(e)?e:e.contextElement}function cd(e){const t=yE(e);if(!Sa(t))return No(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=uz(t);let o=(s?xv(n.width):n.width)/r,l=(s?xv(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const kne=No(0);function dz(e){const t=bs(e);return!vE()||!t.visualViewport?kne:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Tne(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==bs(e)?!1:t}function Ac(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=yE(e);let o=No(1);t&&(r?ro(r)&&(o=cd(r)):o=cd(e));const l=Tne(s,n,r)?dz(s):No(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,f=i.width/o.x,p=i.height/o.y;if(s){const y=bs(s),v=r&&ro(r)?bs(r):r;let _=y,w=CS(_);for(;w&&r&&v!==_;){const S=cd(w),x=w.getBoundingClientRect(),k=io(w),T=x.left+(w.clientLeft+parseFloat(k.paddingLeft))*S.x,R=x.top+(w.clientTop+parseFloat(k.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,p*=S.y,u+=T,d+=R,_=bs(w),w=CS(_)}}return Cv({width:f,height:p,x:u,y:d})}function dy(e,t){const n=uy(e).scrollLeft;return t?t.left+n:Ac(jo(e)).left+n}function fz(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-dy(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Rne(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=jo(r),l=t?cy(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=No(1);const f=No(0),p=Sa(r);if((p||!p&&!s)&&((Od(r)!=="body"||fp(o))&&(u=uy(r)),p)){const v=Ac(r);d=cd(r),f.x=v.x+r.clientLeft,f.y=v.y+r.clientTop}const y=o&&!p&&!s?fz(o,u):No(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+f.x+y.x,y:n.y*d.y-u.scrollTop*d.y+f.y+y.y}}function Ane(e){return Array.from(e.getClientRects())}function Mne(e){const t=jo(e),n=uy(e),r=e.ownerDocument.body,i=vs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=vs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+dy(e);const l=-n.scrollTop;return io(r).direction==="rtl"&&(o+=vs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const $N=25;function Nne(e,t){const n=bs(e),r=jo(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const f=vE();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=dy(r);if(d<=0){const f=r.ownerDocument,p=f.body,y=getComputedStyle(p),v=f.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-v);_<=$N&&(s-=_)}else d<=$N&&(s+=d);return{width:s,height:o,x:l,y:u}}function Pne(e,t){const n=Ac(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Sa(e)?cd(e):No(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function FN(e,t,n){let r;if(t==="viewport")r=Nne(e,n);else if(t==="document")r=Mne(jo(e));else if(ro(t))r=Pne(t,n);else{const i=dz(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Cv(r)}function hz(e,t){const n=Tl(e);return n===t||!ro(n)||bd(n)?!1:io(n).position==="fixed"||hz(n,t)}function One(e,t){const n=t.get(e);if(n)return n;let r=$h(e,[],!1).filter(l=>ro(l)&&Od(l)!=="body"),i=null;const s=io(e).position==="fixed";let o=s?Tl(e):e;for(;ro(o)&&!bd(o);){const l=io(o),u=gE(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||fp(o)&&!u&&hz(e,o))?r=r.filter(f=>f!==o):i=l,o=Tl(o)}return t.set(e,r),r}function Lne(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?cy(t)?[]:One(t,this._c):[].concat(n),r],l=FN(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const v=FN(t,o[y],i);u=vs(v.top,u),d=kl(v.right,d),f=kl(v.bottom,f),p=vs(v.left,p)}return{width:d-p,height:f-u,x:p,y:u}}function Dne(e){const{width:t,height:n}=uz(e);return{width:t,height:n}}function Ine(e,t,n){const r=Sa(t),i=jo(t),s=n==="fixed",o=Ac(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=No(0);function d(){u.x=dy(i)}if(r||!r&&!s)if((Od(t)!=="body"||fp(i))&&(l=uy(t)),r){const v=Ac(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const f=i&&!r&&!s?fz(i,l):No(0),p=o.left+l.scrollLeft-u.x-f.x,y=o.top+l.scrollTop-u.y-f.y;return{x:p,y,width:o.width,height:o.height}}function Pw(e){return io(e).position==="static"}function HN(e,t){if(!Sa(e)||io(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return jo(e)===n&&(n=n.ownerDocument.body),n}function pz(e,t){const n=bs(e);if(cy(e))return n;if(!Sa(e)){let i=Tl(e);for(;i&&!bd(i);){if(ro(i)&&!Pw(i))return i;i=Tl(i)}return n}let r=HN(e,t);for(;r&&Sne(r)&&Pw(r);)r=HN(r,t);return r&&bd(r)&&Pw(r)&&!gE(r)?n:r||Cne(e)||n}const Bne=async function(e){const t=this.getOffsetParent||pz,n=this.getDimensions,r=await n(e.floating);return{reference:Ine(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function zne(e){return io(e).direction==="rtl"}const jne={convertOffsetParentRelativeRectToViewportRelativeRect:Rne,getDocumentElement:jo,getClippingRect:Lne,getOffsetParent:pz,getElementRects:Bne,getClientRects:Ane,getDimensions:Dne,getScale:cd,isElement:ro,isRTL:zne};function mz(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $ne(e,t){let n=null,r;const i=jo(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:f,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const _=ug(p),w=ug(i.clientWidth-(f+y)),S=ug(i.clientHeight-(p+v)),x=ug(f),T={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:vs(0,kl(1,u))||1};let R=!0;function N(A){const O=A[0].intersectionRatio;if(O!==u){if(!R)return o();O?o(!1,O):r=setTimeout(()=>{o(!1,1e-7)},1e3)}O===1&&!mz(d,e.getBoundingClientRect())&&o(),R=!1}try{n=new IntersectionObserver(N,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(N,T)}n.observe(e)}return o(!0),s}function Fne(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=yE(e),f=i||s?[...d?$h(d):[],...t?$h(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const p=d&&l?$ne(d,n):null;let y=-1,v=null;o&&(v=new ResizeObserver(x=>{let[k]=x;k&&k.target===d&&v&&t&&(v.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var T;(T=v)==null||T.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let _,w=u?Ac(e):null;u&&S();function S(){const x=Ac(e);w&&!mz(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(x=v)==null||x.disconnect(),v=null,u&&cancelAnimationFrame(_)}}const Hne=yne,Une=bne,Wne=mne,qne=wne,Yne=gne,UN=pne,Vne=_ne,Kne=(e,t,n)=>{const r=new Map,i={platform:jne,...n},s={...i.platform,_c:r};return hne(e,t,{...i,platform:s})};var Xne=typeof document<"u",Gne=function(){},Xg=Xne?b.useLayoutEffect:Gne;function kv(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!kv(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!kv(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function gz(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function WN(e,t){const n=gz(e);return Math.round(t*n)/n}function Ow(e){const t=b.useRef(e);return Xg(()=>{t.current=e}),t}function Zne(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[f,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=b.useState(r);kv(y,r)||v(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),k=b.useCallback(W=>{W!==A.current&&(A.current=W,w(W))},[]),T=b.useCallback(W=>{W!==O.current&&(O.current=W,x(W))},[]),R=s||_,N=o||S,A=b.useRef(null),O=b.useRef(null),D=b.useRef(f),K=u!=null,U=Ow(u),X=Ow(i),z=Ow(d),M=b.useCallback(()=>{if(!A.current||!O.current)return;const W={placement:t,strategy:n,middleware:y};X.current&&(W.platform=X.current),Kne(A.current,O.current,W).then(j=>{const L={...j,isPositioned:z.current!==!1};F.current&&!kv(D.current,L)&&(D.current=L,Hc.flushSync(()=>{p(L)}))})},[y,t,n,X,z]);Xg(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,p(W=>({...W,isPositioned:!1})))},[d]);const F=b.useRef(!1);Xg(()=>(F.current=!0,()=>{F.current=!1}),[]),Xg(()=>{if(R&&(A.current=R),N&&(O.current=N),R&&N){if(U.current)return U.current(R,N,M);M()}},[R,N,M,U,K]);const B=b.useMemo(()=>({reference:A,floating:O,setReference:k,setFloating:T}),[k,T]),P=b.useMemo(()=>({reference:R,floating:N}),[R,N]),I=b.useMemo(()=>{const W={position:n,left:0,top:0};if(!P.floating)return W;const j=WN(P.floating,f.x),L=WN(P.floating,f.y);return l?{...W,transform:"translate("+j+"px, "+L+"px)",...gz(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:j,top:L}},[n,l,P.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:M,refs:B,elements:P,floatingStyles:I}),[f,M,B,P,I])}const Qne=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?UN({element:r.current,padding:i}).fn(n):{}:r?UN({element:r,padding:i}).fn(n):{}}}},Jne=(e,t)=>{const n=Hne(e);return{name:n.name,fn:n.fn,options:[e,t]}},ere=(e,t)=>{const n=Une(e);return{name:n.name,fn:n.fn,options:[e,t]}},tre=(e,t)=>({fn:Vne(e).fn,options:[e,t]}),nre=(e,t)=>{const n=Wne(e);return{name:n.name,fn:n.fn,options:[e,t]}},rre=(e,t)=>{const n=qne(e);return{name:n.name,fn:n.fn,options:[e,t]}},ire=(e,t)=>{const n=Yne(e);return{name:n.name,fn:n.fn,options:[e,t]}},sre=(e,t)=>{const n=Qne(e);return{name:n.name,fn:n.fn,options:[e,t]}};var ore="Arrow",vz=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(hn.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:m.jsx("polygon",{points:"0,0 30,0 15,10"})})});vz.displayName=ore;var are=vz,bE="Popper",[yz,Bl]=wa(bE),[lre,bz]=yz(bE),_z=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(lre,{scope:t,anchor:r,onAnchorChange:i,children:n})};_z.displayName=bE;var wz="PopperAnchor",Sz=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=bz(wz,n),o=b.useRef(null),l=Kn(t,o),u=b.useRef(null);return b.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:m.jsx(hn.div,{...i,ref:l})});Sz.displayName=wz;var _E="PopperContent",[cre,ure]=yz(_E),xz=b.forwardRef((e,t)=>{var ee,pe,ae,me,Ee,De;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:f=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:v="optimized",onPlaced:_,...w}=e,S=bz(_E,n),[x,k]=b.useState(null),T=Kn(t,Se=>k(Se)),[R,N]=b.useState(null),A=tne(R),O=(A==null?void 0:A.width)??0,D=(A==null?void 0:A.height)??0,K=r+(s!=="center"?"-"+s:""),U=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},X=Array.isArray(d)?d:[d],z=X.length>0,M={padding:U,boundary:X.filter(fre),altBoundary:z},{refs:F,floatingStyles:B,placement:P,isPositioned:I,middlewareData:W}=Zne({strategy:"fixed",placement:K,whileElementsMounted:(...Se)=>Fne(...Se,{animationFrame:v==="always"}),elements:{reference:S.anchor},middleware:[Jne({mainAxis:i+D,alignmentAxis:o}),u&&ere({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?tre():void 0,...M}),u&&nre({...M}),rre({...M,apply:({elements:Se,rects:Je,availableWidth:Ht,availableHeight:ye})=>{const{width:Ze,height:Tt}=Je.reference,gt=Se.floating.style;gt.setProperty("--radix-popper-available-width",`${Ht}px`),gt.setProperty("--radix-popper-available-height",`${ye}px`),gt.setProperty("--radix-popper-anchor-width",`${Ze}px`),gt.setProperty("--radix-popper-anchor-height",`${Tt}px`)}}),R&&sre({element:R,padding:l}),hre({arrowWidth:O,arrowHeight:D}),y&&ire({strategy:"referenceHidden",...M})]}),[j,L]=kz(P),Y=Do(_);Di(()=>{I&&(Y==null||Y())},[I,Y]);const V=(ee=W.arrow)==null?void 0:ee.x,$=(pe=W.arrow)==null?void 0:pe.y,te=((ae=W.arrow)==null?void 0:ae.centerOffset)!==0,[re,oe]=b.useState();return Di(()=>{x&&oe(window.getComputedStyle(x).zIndex)},[x]),m.jsx("div",{ref:F.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:I?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:re,"--radix-popper-transform-origin":[(me=W.transformOrigin)==null?void 0:me.x,(Ee=W.transformOrigin)==null?void 0:Ee.y].join(" "),...((De=W.hide)==null?void 0:De.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(cre,{scope:n,placedSide:j,onArrowChange:N,arrowX:V,arrowY:$,shouldHideArrow:te,children:m.jsx(hn.div,{"data-side":j,"data-align":L,...w,ref:T,style:{...w.style,animation:I?void 0:"none"}})})})});xz.displayName=_E;var Ez="PopperArrow",dre={top:"bottom",right:"left",bottom:"top",left:"right"},Cz=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=ure(Ez,r),o=dre[s.placedSide];return m.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:m.jsx(are,{...i,ref:n,style:{...i.style,display:"block"}})})});Cz.displayName=Ez;function fre(e){return e!==null}var hre=e=>({name:"transformOrigin",options:e,fn(t){var S,x,k;const{placement:n,rects:r,middlewareData:i}=t,o=((S=i.arrow)==null?void 0:S.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,f]=kz(n),p={start:"0%",center:"50%",end:"100%"}[f],y=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,v=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?p:`${y}px`,w=`${-u}px`):d==="top"?(_=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?p:`${v}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?p:`${v}px`),{data:{x:_,y:w}}}});function kz(e){const[t,n="center"]=e.split("-");return[t,n]}var fy=_z,hp=Sz,hy=xz,py=Cz,Lw="rovingFocusGroup.onEntryFocus",pre={bubbles:!1,cancelable:!0},pp="RovingFocusGroup",[kS,Tz,mre]=iE(pp),[gre,Rz]=wa(pp,[mre]),[vre,yre]=gre(pp),Az=b.forwardRef((e,t)=>m.jsx(kS.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(kS.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(bre,{...e,ref:t})})}));Az.displayName=pp;var bre=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...p}=e,y=b.useRef(null),v=Kn(t,y),_=sE(s),[w,S]=Tc({prop:o,defaultProp:l??null,onChange:u,caller:pp}),[x,k]=b.useState(!1),T=Do(d),R=Tz(n),N=b.useRef(!1),[A,O]=b.useState(0);return b.useEffect(()=>{const D=y.current;if(D)return D.addEventListener(Lw,T),()=>D.removeEventListener(Lw,T)},[T]),m.jsx(vre,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(D=>S(D),[S]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>O(D=>D+1),[]),onFocusableItemRemove:b.useCallback(()=>O(D=>D-1),[]),children:m.jsx(hn.div,{tabIndex:x||A===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:Mt(e.onMouseDown,()=>{N.current=!0}),onFocus:Mt(e.onFocus,D=>{const K=!N.current;if(D.target===D.currentTarget&&K&&!x){const U=new CustomEvent(Lw,pre);if(D.currentTarget.dispatchEvent(U),!U.defaultPrevented){const X=R().filter(P=>P.focusable),z=X.find(P=>P.active),M=X.find(P=>P.id===w),B=[z,M,...X].filter(Boolean).map(P=>P.ref.current);Pz(B,f)}}N.current=!1}),onBlur:Mt(e.onBlur,()=>k(!1))})})}),Mz="RovingFocusGroupItem",Nz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=Ci(),d=s||u,f=yre(Mz,n),p=f.currentTabStopId===d,y=Tz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),m.jsx(kS.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(hn.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Mt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:Mt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Mt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=Sre(S,f.orientation,f.dir);if(x!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let T=y().filter(R=>R.focusable).map(R=>R.ref.current);if(x==="last")T.reverse();else if(x==="prev"||x==="next"){x==="prev"&&T.reverse();const R=T.indexOf(S.currentTarget);T=f.loop?xre(T,R+1):T.slice(R+1)}setTimeout(()=>Pz(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});Nz.displayName=Mz;var _re={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wre(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Sre(e,t,n){const r=wre(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return _re[r]}function Pz(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function xre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ere=Az,Cre=Nz,TS=["Enter"," "],kre=["ArrowDown","PageUp","Home"],Oz=["ArrowUp","PageDown","End"],Tre=[...kre,...Oz],Rre={ltr:[...TS,"ArrowRight"],rtl:[...TS,"ArrowLeft"]},Are={ltr:["ArrowLeft"],rtl:["ArrowRight"]},mp="Menu",[Fh,Mre,Nre]=iE(mp),[Uc,Lz]=wa(mp,[Nre,Bl,Rz]),my=Bl(),Dz=Rz(),[Pre,Wc]=Uc(mp),[Ore,gp]=Uc(mp),Iz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=my(t),[u,d]=b.useState(null),f=b.useRef(!1),p=Do(s),y=sE(i);return b.useEffect(()=>{const v=()=>{f.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>f.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),m.jsx(fy,{...l,children:m.jsx(Pre,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:m.jsx(Ore,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:f,dir:y,modal:o,children:r})})})};Iz.displayName=mp;var Lre="MenuAnchor",wE=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=my(n);return m.jsx(hp,{...i,...r,ref:t})});wE.displayName=Lre;var SE="MenuPortal",[Dre,Bz]=Uc(SE,{forceMount:void 0}),zz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Wc(SE,t);return m.jsx(Dre,{scope:t,forceMount:n,children:m.jsx(qs,{present:n||s.open,children:m.jsx(Nd,{asChild:!0,container:i,children:r})})})};zz.displayName=SE;var $s="MenuContent",[Ire,xE]=Uc($s),jz=b.forwardRef((e,t)=>{const n=Bz($s,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Wc($s,e.__scopeMenu),o=gp($s,e.__scopeMenu);return m.jsx(Fh.Provider,{scope:e.__scopeMenu,children:m.jsx(qs,{present:r||s.open,children:m.jsx(Fh.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Bre,{...i,ref:t}):m.jsx(zre,{...i,ref:t})})})})}),Bre=b.forwardRef((e,t)=>{const n=Wc($s,e.__scopeMenu),r=b.useRef(null),i=Kn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return sy(s)},[]),m.jsx(EE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Mt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),zre=b.forwardRef((e,t)=>{const n=Wc($s,e.__scopeMenu);return m.jsx(EE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),jre=Cl("MenuContent.ScrollLock"),EE=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:y,onDismiss:v,disableOutsideScroll:_,...w}=e,S=Wc($s,n),x=gp($s,n),k=my(n),T=Dz(n),R=Mre(n),[N,A]=b.useState(null),O=b.useRef(null),D=Kn(t,O,S.onContentChange),K=b.useRef(0),U=b.useRef(""),X=b.useRef(0),z=b.useRef(null),M=b.useRef("right"),F=b.useRef(0),B=_?dp:b.Fragment,P=_?{as:jre,allowPinchZoom:!0}:void 0,I=j=>{var ee,pe;const L=U.current+j,Y=R().filter(ae=>!ae.disabled),V=document.activeElement,$=(ee=Y.find(ae=>ae.ref.current===V))==null?void 0:ee.textValue,te=Y.map(ae=>ae.textValue),re=Zre(te,L,$),oe=(pe=Y.find(ae=>ae.textValue===re))==null?void 0:pe.ref.current;(function ae(me){U.current=me,window.clearTimeout(K.current),me!==""&&(K.current=window.setTimeout(()=>ae(""),1e3))})(L),oe&&setTimeout(()=>oe.focus())};b.useEffect(()=>()=>window.clearTimeout(K.current),[]),ry();const W=b.useCallback(j=>{var Y,V;return M.current===((Y=z.current)==null?void 0:Y.side)&&Jre(j,(V=z.current)==null?void 0:V.area)},[]);return m.jsx(Ire,{scope:n,searchRef:U,onItemEnter:b.useCallback(j=>{W(j)&&j.preventDefault()},[W]),onItemLeave:b.useCallback(j=>{var L;W(j)||((L=O.current)==null||L.focus(),A(null))},[W]),onTriggerLeave:b.useCallback(j=>{W(j)&&j.preventDefault()},[W]),pointerGraceTimerRef:X,onPointerGraceIntentChange:b.useCallback(j=>{z.current=j},[]),children:m.jsx(B,{...P,children:m.jsx(up,{asChild:!0,trapped:i,onMountAutoFocus:Mt(s,j=>{var L;j.preventDefault(),(L=O.current)==null||L.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:m.jsx(Ere,{asChild:!0,...T,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:N,onCurrentTabStopIdChange:A,onEntryFocus:Mt(u,j=>{x.isUsingKeyboardRef.current||j.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(hy,{role:"menu","aria-orientation":"vertical","data-state":t3(S.open),"data-radix-menu-content":"",dir:x.dir,...k,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:Mt(w.onKeyDown,j=>{const Y=j.target.closest("[data-radix-menu-content]")===j.currentTarget,V=j.ctrlKey||j.altKey||j.metaKey,$=j.key.length===1;Y&&(j.key==="Tab"&&j.preventDefault(),!V&&$&&I(j.key));const te=O.current;if(j.target!==te||!Tre.includes(j.key))return;j.preventDefault();const oe=R().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);Oz.includes(j.key)&&oe.reverse(),Xre(oe)}),onBlur:Mt(e.onBlur,j=>{j.currentTarget.contains(j.target)||(window.clearTimeout(K.current),U.current="")}),onPointerMove:Mt(e.onPointerMove,Hh(j=>{const L=j.target,Y=F.current!==j.clientX;if(j.currentTarget.contains(L)&&Y){const V=j.clientX>F.current?"right":"left";M.current=V,F.current=j.clientX}}))})})})})})})});jz.displayName=$s;var $re="MenuGroup",CE=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(hn.div,{role:"group",...r,ref:t})});CE.displayName=$re;var Fre="MenuLabel",$z=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(hn.div,{...r,ref:t})});$z.displayName=Fre;var Tv="MenuItem",qN="menu.itemSelect",gy=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=gp(Tv,e.__scopeMenu),l=xE(Tv,e.__scopeMenu),u=Kn(t,s),d=b.useRef(!1),f=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(qN,{bubbles:!0,cancelable:!0});p.addEventListener(qN,v=>r==null?void 0:r(v),{once:!0}),TB(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(Fz,{...i,ref:u,disabled:n,onClick:Mt(e.onClick,f),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:Mt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:Mt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||TS.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});gy.displayName=Tv;var Fz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=xE(Tv,n),l=Dz(n),u=b.useRef(null),d=Kn(t,u),[f,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),m.jsx(Fh.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:m.jsx(Cre,{asChild:!0,...l,focusable:!r,children:m.jsx(hn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:Mt(e.onPointerMove,Hh(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Mt(e.onPointerLeave,Hh(_=>o.onItemLeave(_))),onFocus:Mt(e.onFocus,()=>p(!0)),onBlur:Mt(e.onBlur,()=>p(!1))})})})}),Hre="MenuCheckboxItem",Hz=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(Vz,{scope:e.__scopeMenu,checked:n,children:m.jsx(gy,{role:"menuitemcheckbox","aria-checked":Rv(n)?"mixed":n,...i,ref:t,"data-state":TE(n),onSelect:Mt(i.onSelect,()=>r==null?void 0:r(Rv(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Hz.displayName=Hre;var Uz="MenuRadioGroup",[Ure,Wre]=Uc(Uz,{value:void 0,onValueChange:()=>{}}),Wz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Do(r);return m.jsx(Ure,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(CE,{...i,ref:t})})});Wz.displayName=Uz;var qz="MenuRadioItem",Yz=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=Wre(qz,e.__scopeMenu),s=n===i.value;return m.jsx(Vz,{scope:e.__scopeMenu,checked:s,children:m.jsx(gy,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":TE(s),onSelect:Mt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});Yz.displayName=qz;var kE="MenuItemIndicator",[Vz,qre]=Uc(kE,{checked:!1}),Kz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=qre(kE,n);return m.jsx(qs,{present:r||Rv(s.checked)||s.checked===!0,children:m.jsx(hn.span,{...i,ref:t,"data-state":TE(s.checked)})})});Kz.displayName=kE;var Yre="MenuSeparator",Xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(hn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Xz.displayName=Yre;var Vre="MenuArrow",Gz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=my(n);return m.jsx(py,{...i,...r,ref:t})});Gz.displayName=Vre;var Kre="MenuSub",[FMe,Zz]=Uc(Kre),oh="MenuSubTrigger",Qz=b.forwardRef((e,t)=>{const n=Wc(oh,e.__scopeMenu),r=gp(oh,e.__scopeMenu),i=Zz(oh,e.__scopeMenu),s=xE(oh,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},f=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>f,[f]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),m.jsx(wE,{asChild:!0,...d,children:m.jsx(Fz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":t3(n.open),...e,ref:va(t,i.onTriggerChange),onClick:p=>{var y;(y=e.onClick)==null||y.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Mt(e.onPointerMove,Hh(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:Mt(e.onPointerLeave,Hh(p=>{var v,_;f();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,S=w==="right",x=S?-5:5,k=y[S?"left":"right"],T=y[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+x,y:p.clientY},{x:k,y:y.top},{x:T,y:y.top},{x:T,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:Mt(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Rre[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});Qz.displayName=oh;var Jz="MenuSubContent",e3=b.forwardRef((e,t)=>{const n=Bz($s,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Wc($s,e.__scopeMenu),o=gp($s,e.__scopeMenu),l=Zz(Jz,e.__scopeMenu),u=b.useRef(null),d=Kn(t,u);return m.jsx(Fh.Provider,{scope:e.__scopeMenu,children:m.jsx(qs,{present:r||s.open,children:m.jsx(Fh.Slot,{scope:e.__scopeMenu,children:m.jsx(EE,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:Mt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Mt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Mt(e.onKeyDown,f=>{var v;const p=f.currentTarget.contains(f.target),y=Are[o.dir].includes(f.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),f.preventDefault())})})})})})});e3.displayName=Jz;function t3(e){return e?"open":"closed"}function Rv(e){return e==="indeterminate"}function TE(e){return Rv(e)?"indeterminate":e?"checked":"unchecked"}function Xre(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Gre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Zre(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Gre(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function Qre(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,f=l.y,p=u.x,y=u.y;f>r!=y>r&&n<(p-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function Jre(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Qre(n,t)}function Hh(e){return t=>t.pointerType==="mouse"?e(t):void 0}var eie=Iz,tie=wE,nie=zz,rie=jz,iie=CE,sie=$z,oie=gy,aie=Hz,lie=Wz,cie=Yz,uie=Kz,die=Xz,fie=Gz,hie=Qz,pie=e3,vy="DropdownMenu",[mie]=wa(vy,[Lz]),Wi=Lz(),[gie,n3]=mie(vy),r3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Wi(t),d=b.useRef(null),[f,p]=Tc({prop:i,defaultProp:s??!1,onChange:o,caller:vy});return m.jsx(gie,{scope:t,triggerId:Ci(),triggerRef:d,contentId:Ci(),open:f,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:m.jsx(eie,{...u,open:f,onOpenChange:p,dir:r,modal:l,children:n})})};r3.displayName=vy;var i3="DropdownMenuTrigger",s3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=n3(i3,n),o=Wi(n);return m.jsx(tie,{asChild:!0,...o,children:m.jsx(hn.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:va(t,s.triggerRef),onPointerDown:Mt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:Mt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});s3.displayName=i3;var vie="DropdownMenuPortal",o3=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Wi(t);return m.jsx(nie,{...r,...n})};o3.displayName=vie;var a3="DropdownMenuContent",l3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=n3(a3,n),s=Wi(n),o=b.useRef(!1);return m.jsx(rie,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Mt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Mt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,f=u.button===2||d;(!i.modal||f)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});l3.displayName=a3;var yie="DropdownMenuGroup",bie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(iie,{...i,...r,ref:t})});bie.displayName=yie;var _ie="DropdownMenuLabel",c3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(sie,{...i,...r,ref:t})});c3.displayName=_ie;var wie="DropdownMenuItem",u3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(oie,{...i,...r,ref:t})});u3.displayName=wie;var Sie="DropdownMenuCheckboxItem",d3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(aie,{...i,...r,ref:t})});d3.displayName=Sie;var xie="DropdownMenuRadioGroup",Eie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(lie,{...i,...r,ref:t})});Eie.displayName=xie;var Cie="DropdownMenuRadioItem",kie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(cie,{...i,...r,ref:t})});kie.displayName=Cie;var Tie="DropdownMenuItemIndicator",f3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(uie,{...i,...r,ref:t})});f3.displayName=Tie;var Rie="DropdownMenuSeparator",h3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(die,{...i,...r,ref:t})});h3.displayName=Rie;var Aie="DropdownMenuArrow",Mie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(fie,{...i,...r,ref:t})});Mie.displayName=Aie;var Nie="DropdownMenuSubTrigger",Pie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(hie,{...i,...r,ref:t})});Pie.displayName=Nie;var Oie="DropdownMenuSubContent",Lie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(pie,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Lie.displayName=Oie;var Die=r3,Iie=s3,Bie=o3,zie=l3,jie=c3,$ie=u3,Fie=d3,Hie=f3,Uie=h3;function YN(e,[t,n]){return Math.min(n,Math.max(t,e))}var yy="Popover",[p3]=wa(yy,[Bl]),vp=Bl(),[Wie,zl]=p3(yy),m3=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=vp(t),u=b.useRef(null),[d,f]=b.useState(!1),[p,y]=Tc({prop:r,defaultProp:i??!1,onChange:s,caller:yy});return m.jsx(fy,{...l,children:m.jsx(Wie,{scope:t,contentId:Ci(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>f(!0),[]),onCustomAnchorRemove:b.useCallback(()=>f(!1),[]),modal:o,children:n})})};m3.displayName=yy;var g3="PopoverAnchor",qie=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=zl(g3,n),s=vp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(hp,{...s,...r,ref:t})});qie.displayName=g3;var v3="PopoverTrigger",y3=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=zl(v3,n),s=vp(n),o=Kn(t,i.triggerRef),l=m.jsx(hn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":x3(i.open),...r,ref:o,onClick:Mt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(hp,{asChild:!0,...s,children:l})});y3.displayName=v3;var RE="PopoverPortal",[Yie,Vie]=p3(RE,{forceMount:void 0}),b3=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=zl(RE,t);return m.jsx(Yie,{scope:t,forceMount:n,children:m.jsx(qs,{present:n||s.open,children:m.jsx(Nd,{asChild:!0,container:i,children:r})})})};b3.displayName=RE;var _d="PopoverContent",_3=b.forwardRef((e,t)=>{const n=Vie(_d,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=zl(_d,e.__scopePopover);return m.jsx(qs,{present:r||s.open,children:s.modal?m.jsx(Xie,{...i,ref:t}):m.jsx(Gie,{...i,ref:t})})});_3.displayName=_d;var Kie=Cl("PopoverContent.RemoveScroll"),Xie=b.forwardRef((e,t)=>{const n=zl(_d,e.__scopePopover),r=b.useRef(null),i=Kn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return sy(o)},[]),m.jsx(dp,{as:Kie,allowPinchZoom:!0,children:m.jsx(w3,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Mt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:Mt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:Mt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Gie=b.forwardRef((e,t)=>{const n=zl(_d,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(w3,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),w3=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,...p}=e,y=zl(_d,n),v=vp(n);return ry(),m.jsx(up,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:m.jsx(hy,{"data-state":x3(y.open),role:"dialog",id:y.contentId,...v,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),S3="PopoverClose",Zie=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=zl(S3,n);return m.jsx(hn.button,{type:"button",...r,ref:t,onClick:Mt(e.onClick,()=>i.onOpenChange(!1))})});Zie.displayName=S3;var Qie="PopoverArrow",Jie=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=vp(n);return m.jsx(py,{...i,...r,ref:t})});Jie.displayName=Qie;function x3(e){return e?"open":"closed"}var ese=m3,tse=y3,nse=b3,rse=_3,ise=[" ","Enter","ArrowUp","ArrowDown"],sse=[" ","Enter"],Mc="Select",[by,_y,ose]=iE(Mc),[Ld]=wa(Mc,[ose,Bl]),wy=Bl(),[ase,jl]=Ld(Mc),[lse,cse]=Ld(Mc),E3=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:f,autoComplete:p,disabled:y,required:v,form:_}=e,w=wy(t),[S,x]=b.useState(null),[k,T]=b.useState(null),[R,N]=b.useState(!1),A=sE(d),[O,D]=Tc({prop:r,defaultProp:i??!1,onChange:s,caller:Mc}),[K,U]=Tc({prop:o,defaultProp:l,onChange:u,caller:Mc}),X=b.useRef(null),z=S?_||!!S.closest("form"):!0,[M,F]=b.useState(new Set),B=Array.from(M).map(P=>P.props.value).join(";");return m.jsx(fy,{...w,children:m.jsxs(ase,{required:v,scope:t,trigger:S,onTriggerChange:x,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:R,onValueNodeHasChildrenChange:N,contentId:Ci(),value:K,onValueChange:U,open:O,onOpenChange:D,dir:A,triggerPointerDownPosRef:X,disabled:y,children:[m.jsx(by.Provider,{scope:t,children:m.jsx(lse,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{F(I=>new Set(I).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{F(I=>{const W=new Set(I);return W.delete(P),W})},[]),children:n})}),z?m.jsxs(Y3,{"aria-hidden":!0,required:v,tabIndex:-1,name:f,autoComplete:p,value:K,onChange:P=>U(P.target.value),disabled:y,form:_,children:[K===void 0?m.jsx("option",{value:""}):null,Array.from(M)]},B):null]})})};E3.displayName=Mc;var C3="SelectTrigger",k3=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=wy(n),o=jl(C3,n),l=o.disabled||r,u=Kn(t,o.onTriggerChange),d=_y(n),f=b.useRef("touch"),[p,y,v]=K3(w=>{const S=d().filter(T=>!T.disabled),x=S.find(T=>T.value===o.value),k=X3(S,w,x);k!==void 0&&o.onValueChange(k.value)}),_=w=>{l||(o.onOpenChange(!0),v()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(hp,{asChild:!0,...s,children:m.jsx(hn.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":V3(o.value)?"":void 0,...i,ref:u,onClick:Mt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:Mt(i.onPointerDown,w=>{f.current=w.pointerType;const S=w.target;S.hasPointerCapture(w.pointerId)&&S.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:Mt(i.onKeyDown,w=>{const S=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(S&&w.key===" ")&&ise.includes(w.key)&&(_(),w.preventDefault())})})})});k3.displayName=C3;var T3="SelectValue",R3=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=jl(T3,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,p=Kn(t,u.onValueNodeChange);return Di(()=>{d(f)},[d,f]),m.jsx(hn.span,{...l,ref:p,style:{pointerEvents:"none"},children:V3(u.value)?m.jsx(m.Fragment,{children:o}):s})});R3.displayName=T3;var use="SelectIcon",A3=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(hn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});A3.displayName=use;var dse="SelectPortal",M3=e=>m.jsx(Nd,{asChild:!0,...e});M3.displayName=dse;var Nc="SelectContent",N3=b.forwardRef((e,t)=>{const n=jl(Nc,e.__scopeSelect),[r,i]=b.useState();if(Di(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?Hc.createPortal(m.jsx(P3,{scope:e.__scopeSelect,children:m.jsx(by.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(O3,{...e,ref:t})});N3.displayName=Nc;var Qs=10,[P3,$l]=Ld(Nc),fse="SelectContentImpl",hse=Cl("SelectContent.RemoveScroll"),O3=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,k=jl(Nc,n),[T,R]=b.useState(null),[N,A]=b.useState(null),O=Kn(t,ee=>R(ee)),[D,K]=b.useState(null),[U,X]=b.useState(null),z=_y(n),[M,F]=b.useState(!1),B=b.useRef(!1);b.useEffect(()=>{if(T)return sy(T)},[T]),ry();const P=b.useCallback(ee=>{const[pe,...ae]=z().map(De=>De.ref.current),[me]=ae.slice(-1),Ee=document.activeElement;for(const De of ee)if(De===Ee||(De==null||De.scrollIntoView({block:"nearest"}),De===pe&&N&&(N.scrollTop=0),De===me&&N&&(N.scrollTop=N.scrollHeight),De==null||De.focus(),document.activeElement!==Ee))return},[z,N]),I=b.useCallback(()=>P([D,T]),[P,D,T]);b.useEffect(()=>{M&&I()},[M,I]);const{onOpenChange:W,triggerPointerDownPosRef:j}=k;b.useEffect(()=>{if(T){let ee={x:0,y:0};const pe=me=>{var Ee,De;ee={x:Math.abs(Math.round(me.pageX)-(((Ee=j.current)==null?void 0:Ee.x)??0)),y:Math.abs(Math.round(me.pageY)-(((De=j.current)==null?void 0:De.y)??0))}},ae=me=>{ee.x<=10&&ee.y<=10?me.preventDefault():T.contains(me.target)||W(!1),document.removeEventListener("pointermove",pe),j.current=null};return j.current!==null&&(document.addEventListener("pointermove",pe),document.addEventListener("pointerup",ae,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",pe),document.removeEventListener("pointerup",ae,{capture:!0})}}},[T,W,j]),b.useEffect(()=>{const ee=()=>W(!1);return window.addEventListener("blur",ee),window.addEventListener("resize",ee),()=>{window.removeEventListener("blur",ee),window.removeEventListener("resize",ee)}},[W]);const[L,Y]=K3(ee=>{const pe=z().filter(Ee=>!Ee.disabled),ae=pe.find(Ee=>Ee.ref.current===document.activeElement),me=X3(pe,ee,ae);me&&setTimeout(()=>me.ref.current.focus())}),V=b.useCallback((ee,pe,ae)=>{const me=!B.current&&!ae;(k.value!==void 0&&k.value===pe||me)&&(K(ee),me&&(B.current=!0))},[k.value]),$=b.useCallback(()=>T==null?void 0:T.focus(),[T]),te=b.useCallback((ee,pe,ae)=>{const me=!B.current&&!ae;(k.value!==void 0&&k.value===pe||me)&&X(ee)},[k.value]),re=r==="popper"?RS:L3,oe=re===RS?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(P3,{scope:n,content:T,viewport:N,onViewportChange:A,itemRefCallback:V,selectedItem:D,onItemLeave:$,itemTextRefCallback:te,focusSelectedItem:I,selectedItemText:U,position:r,isPositioned:M,searchRef:L,children:m.jsx(dp,{as:hse,allowPinchZoom:!0,children:m.jsx(up,{asChild:!0,trapped:k.open,onMountAutoFocus:ee=>{ee.preventDefault()},onUnmountAutoFocus:Mt(i,ee=>{var pe;(pe=k.trigger)==null||pe.focus({preventScroll:!0}),ee.preventDefault()}),children:m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:ee=>ee.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:m.jsx(re,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:ee=>ee.preventDefault(),...x,...oe,onPlaced:()=>F(!0),ref:O,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:Mt(x.onKeyDown,ee=>{const pe=ee.ctrlKey||ee.altKey||ee.metaKey;if(ee.key==="Tab"&&ee.preventDefault(),!pe&&ee.key.length===1&&Y(ee.key),["ArrowUp","ArrowDown","Home","End"].includes(ee.key)){let me=z().filter(Ee=>!Ee.disabled).map(Ee=>Ee.ref.current);if(["ArrowUp","End"].includes(ee.key)&&(me=me.slice().reverse()),["ArrowUp","ArrowDown"].includes(ee.key)){const Ee=ee.target,De=me.indexOf(Ee);me=me.slice(De+1)}setTimeout(()=>P(me)),ee.preventDefault()}})})})})})})});O3.displayName=fse;var pse="SelectItemAlignedPosition",L3=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=jl(Nc,n),o=$l(Nc,n),[l,u]=b.useState(null),[d,f]=b.useState(null),p=Kn(t,O=>f(O)),y=_y(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:k}=o,T=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const O=s.trigger.getBoundingClientRect(),D=d.getBoundingClientRect(),K=s.valueNode.getBoundingClientRect(),U=x.getBoundingClientRect();if(s.dir!=="rtl"){const Ee=U.left-D.left,De=K.left-Ee,Se=O.left-De,Je=O.width+Se,Ht=Math.max(Je,D.width),ye=window.innerWidth-Qs,Ze=YN(De,[Qs,Math.max(Qs,ye-Ht)]);l.style.minWidth=Je+"px",l.style.left=Ze+"px"}else{const Ee=D.right-U.right,De=window.innerWidth-K.right-Ee,Se=window.innerWidth-O.right-De,Je=O.width+Se,Ht=Math.max(Je,D.width),ye=window.innerWidth-Qs,Ze=YN(De,[Qs,Math.max(Qs,ye-Ht)]);l.style.minWidth=Je+"px",l.style.right=Ze+"px"}const X=y(),z=window.innerHeight-Qs*2,M=w.scrollHeight,F=window.getComputedStyle(d),B=parseInt(F.borderTopWidth,10),P=parseInt(F.paddingTop,10),I=parseInt(F.borderBottomWidth,10),W=parseInt(F.paddingBottom,10),j=B+P+M+W+I,L=Math.min(S.offsetHeight*5,j),Y=window.getComputedStyle(w),V=parseInt(Y.paddingTop,10),$=parseInt(Y.paddingBottom,10),te=O.top+O.height/2-Qs,re=z-te,oe=S.offsetHeight/2,ee=S.offsetTop+oe,pe=B+P+ee,ae=j-pe;if(pe<=te){const Ee=X.length>0&&S===X[X.length-1].ref.current;l.style.bottom="0px";const De=d.clientHeight-w.offsetTop-w.offsetHeight,Se=Math.max(re,oe+(Ee?$:0)+De+I),Je=pe+Se;l.style.height=Je+"px"}else{const Ee=X.length>0&&S===X[0].ref.current;l.style.top="0px";const Se=Math.max(te,B+w.offsetTop+(Ee?V:0)+oe)+ae;l.style.height=Se+"px",w.scrollTop=pe-te+w.offsetTop}l.style.margin=`${Qs}px 0`,l.style.minHeight=L+"px",l.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,S,x,s.dir,r]);Di(()=>T(),[T]);const[R,N]=b.useState();Di(()=>{d&&N(window.getComputedStyle(d).zIndex)},[d]);const A=b.useCallback(O=>{O&&_.current===!0&&(T(),k==null||k(),_.current=!1)},[T,k]);return m.jsx(gse,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:A,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:R},children:m.jsx(hn.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});L3.displayName=pse;var mse="SelectPopperPosition",RS=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Qs,...s}=e,o=wy(n);return m.jsx(hy,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});RS.displayName=mse;var[gse,AE]=Ld(Nc,{}),AS="SelectViewport",D3=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=$l(AS,n),o=AE(AS,n),l=Kn(t,s.onViewportChange),u=b.useRef(0);return m.jsxs(m.Fragment,{children:[m.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),m.jsx(by.Slot,{scope:n,children:m.jsx(hn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Mt(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const v=Math.abs(u.current-f.scrollTop);if(v>0){const _=window.innerHeight-Qs*2,w=parseFloat(p.style.minHeight),S=parseFloat(p.style.height),x=Math.max(w,S);if(x<_){const k=x+v,T=Math.min(_,k),R=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(f.scrollTop=R>0?R:0,p.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});D3.displayName=AS;var I3="SelectGroup",[vse,yse]=Ld(I3),bse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Ci();return m.jsx(vse,{scope:n,id:i,children:m.jsx(hn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});bse.displayName=I3;var B3="SelectLabel",_se=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=yse(B3,n);return m.jsx(hn.div,{id:i.id,...r,ref:t})});_se.displayName=B3;var Av="SelectItem",[wse,z3]=Ld(Av),j3=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=jl(Av,n),u=$l(Av,n),d=l.value===r,[f,p]=b.useState(s??""),[y,v]=b.useState(!1),_=Kn(t,k=>{var T;return(T=u.itemRefCallback)==null?void 0:T.call(u,k,r,i)}),w=Ci(),S=b.useRef("touch"),x=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return m.jsx(wse,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:m.jsx(by.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(hn.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:Mt(o.onFocus,()=>v(!0)),onBlur:Mt(o.onBlur,()=>v(!1)),onClick:Mt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:Mt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:Mt(o.onPointerDown,k=>{S.current=k.pointerType}),onPointerMove:Mt(o.onPointerMove,k=>{var T;S.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):S.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Mt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:Mt(o.onKeyDown,k=>{var R;((R=u.searchRef)==null?void 0:R.current)!==""&&k.key===" "||(sse.includes(k.key)&&x(),k.key===" "&&k.preventDefault())})})})})});j3.displayName=Av;var ah="SelectItemText",$3=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=jl(ah,n),l=$l(ah,n),u=z3(ah,n),d=cse(ah,n),[f,p]=b.useState(null),y=Kn(t,x=>p(x),u.onItemTextChange,x=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,x,u.value,u.disabled)}),v=f==null?void 0:f.textContent,_=b.useMemo(()=>m.jsx("option",{value:u.value,disabled:u.disabled,children:v},u.value),[u.disabled,u.value,v]),{onNativeOptionAdd:w,onNativeOptionRemove:S}=d;return Di(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(hn.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Hc.createPortal(s.children,o.valueNode):null]})});$3.displayName=ah;var F3="SelectItemIndicator",H3=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return z3(F3,n).isSelected?m.jsx(hn.span,{"aria-hidden":!0,...r,ref:t}):null});H3.displayName=F3;var MS="SelectScrollUpButton",U3=b.forwardRef((e,t)=>{const n=$l(MS,e.__scopeSelect),r=AE(MS,e.__scopeSelect),[i,s]=b.useState(!1),o=Kn(t,r.onScrollButtonChange);return Di(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollTop>0;s(d)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?m.jsx(q3,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});U3.displayName=MS;var NS="SelectScrollDownButton",W3=b.forwardRef((e,t)=>{const n=$l(NS,e.__scopeSelect),r=AE(NS,e.__scopeSelect),[i,s]=b.useState(!1),o=Kn(t,r.onScrollButtonChange);return Di(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,f=Math.ceil(u.scrollTop)<d;s(f)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?m.jsx(q3,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});W3.displayName=NS;var q3=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=$l("SelectScrollButton",n),o=b.useRef(null),l=_y(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Di(()=>{var f;const d=l().find(p=>p.ref.current===document.activeElement);(f=d==null?void 0:d.ref.current)==null||f.scrollIntoView({block:"nearest"})},[l]),m.jsx(hn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Mt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Mt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Mt(i.onPointerLeave,()=>{u()})})}),Sse="SelectSeparator",xse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(hn.div,{"aria-hidden":!0,...r,ref:t})});xse.displayName=Sse;var PS="SelectArrow",Ese=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=wy(n),s=jl(PS,n),o=$l(PS,n);return s.open&&o.position==="popper"?m.jsx(py,{...i,...r,ref:t}):null});Ese.displayName=PS;var Cse="SelectBubbleInput",Y3=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=Kn(r,i),o=ene(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&f){const p=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(p)}},[o,t]),m.jsx(hn.select,{...n,style:{...RB,...n.style},ref:s,defaultValue:t})});Y3.displayName=Cse;function V3(e){return e===""||e===void 0}function K3(e){const t=Do(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function X3(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=kse(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.textValue.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function kse(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Tse=E3,Rse=k3,Ase=R3,Mse=A3,Nse=M3,Pse=N3,Ose=D3,Lse=j3,Dse=$3,Ise=H3,Bse=U3,zse=W3,[Sy]=wa("Tooltip",[Bl]),xy=Bl(),G3="TooltipProvider",jse=700,OS="tooltip.open",[$se,ME]=Sy(G3),Z3=e=>{const{__scopeTooltip:t,delayDuration:n=jse,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=b.useRef(!0),l=b.useRef(!1),u=b.useRef(0);return b.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),m.jsx($se,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:b.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};Z3.displayName=G3;var Uh="Tooltip",[Fse,yp]=Sy(Uh),Q3=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=ME(Uh,e.__scopeTooltip),d=xy(t),[f,p]=b.useState(null),y=Ci(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,k]=Tc({prop:r,defaultProp:i??!1,onChange:O=>{O?(u.onOpen(),document.dispatchEvent(new CustomEvent(OS))):u.onClose(),s==null||s(O)},caller:Uh}),T=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),R=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,S.current=!1,k(!0)},[k]),N=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{S.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),m.jsx(fy,{...d,children:m.jsx(Fse,{scope:t,contentId:y,open:x,stateAttribute:T,trigger:f,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?A():R()},[u.isOpenDelayedRef,A,R]),onTriggerLeave:b.useCallback(()=>{_?N():(window.clearTimeout(v.current),v.current=0)},[N,_]),onOpen:R,onClose:N,disableHoverableContent:_,children:n})})};Q3.displayName=Uh;var LS="TooltipTrigger",J3=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=yp(LS,n),s=ME(LS,n),o=xy(n),l=b.useRef(null),u=Kn(t,l,i.onTriggerChange),d=b.useRef(!1),f=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),m.jsx(hp,{asChild:!0,...o,children:m.jsx(hn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:Mt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Mt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Mt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:Mt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:Mt(e.onBlur,i.onClose),onClick:Mt(e.onClick,i.onClose)})})});J3.displayName=LS;var NE="TooltipPortal",[Hse,Use]=Sy(NE,{forceMount:void 0}),e5=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=yp(NE,t);return m.jsx(Hse,{scope:t,forceMount:n,children:m.jsx(qs,{present:n||s.open,children:m.jsx(Nd,{asChild:!0,container:i,children:r})})})};e5.displayName=NE;var wd="TooltipContent",t5=b.forwardRef((e,t)=>{const n=Use(wd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=yp(wd,e.__scopeTooltip);return m.jsx(qs,{present:r||o.open,children:o.disableHoverableContent?m.jsx(n5,{side:i,...s,ref:t}):m.jsx(Wse,{side:i,...s,ref:t})})}),Wse=b.forwardRef((e,t)=>{const n=yp(wd,e.__scopeTooltip),r=ME(wd,e.__scopeTooltip),i=b.useRef(null),s=Kn(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:p}=r,y=b.useCallback(()=>{l(null),p(!1)},[p]),v=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},k=Kse(x,S.getBoundingClientRect()),T=Xse(x,k),R=Gse(w.getBoundingClientRect()),N=Qse([...T,...R]);l(N),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&f){const _=S=>v(S,f),w=S=>v(S,u);return u.addEventListener("pointerleave",_),f.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),f.removeEventListener("pointerleave",w)}}},[u,f,v,y]),b.useEffect(()=>{if(o){const _=w=>{const S=w.target,x={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),T=!Zse(x,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,y]),m.jsx(n5,{...e,ref:s})}),[qse,Yse]=Sy(Uh,{isInside:!1}),Vse=kee("TooltipContent"),n5=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=yp(wd,n),d=xy(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(OS,f),()=>document.removeEventListener(OS,f)),[f]),b.useEffect(()=>{if(u.trigger){const p=y=>{const v=y.target;v!=null&&v.contains(u.trigger)&&f()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,f]),m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:f,children:m.jsxs(hy,{"data-state":u.stateAttribute,...d,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[m.jsx(Vse,{children:r}),m.jsx(qse,{scope:n,isInside:!0,children:m.jsx(MB,{id:u.contentId,role:"tooltip",children:i||r})})]})})});t5.displayName=wd;var r5="TooltipArrow",i5=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=xy(n);return Yse(r5,n).isInside?null:m.jsx(py,{...i,...r,ref:t})});i5.displayName=r5;function Kse(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function Xse(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function Gse(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function Zse(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,f=l.y,p=u.x,y=u.y;f>r!=y>r&&n<(p-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function Qse(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),Jse(t)}function Jse(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var eoe=Z3,toe=Q3,noe=J3,roe=e5,ioe=t5,soe=i5;function PE({...e}){return m.jsx(ese,{"data-slot":"popover",...e})}function OE({...e}){return m.jsx(tse,{"data-slot":"popover-trigger",...e})}function LE({className:e,align:t="center",sideOffset:n=4,...r}){return m.jsx(nse,{children:m.jsx(rse,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const VN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,KN=aI,ooe=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return KN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(d=>{const f=n==null?void 0:n[d],p=s==null?void 0:s[d];if(f===null)return null;const y=VN(f)||VN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,y]=f;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:p,className:y,...v}=f;return Object.entries(v).every(_=>{let[w,S]=_;return Array.isArray(S)?S.includes({...s,...l}[w]):{...s,...l}[w]===S})?[...d,p,y]:d},[]);return KN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},aoe=ooe("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-normal whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function Ct({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?Eee:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(aoe({variant:t,size:n,className:e})),...i})}function Ey({...e}){return m.jsx(Die,{"data-slot":"dropdown-menu",...e})}function Cy({...e}){return m.jsx(Iie,{"data-slot":"dropdown-menu-trigger",...e})}function ky({className:e,sideOffset:t=4,...n}){return m.jsx(Bie,{children:m.jsx(zie,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function Js({className:e,inset:t,variant:n="default",...r}){return m.jsx($ie,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Dw({className:e,children:t,checked:n,...r}){return m.jsxs(Fie,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(Hie,{children:m.jsx(Lo,{className:"size-4"})})}),t]})}function dg({className:e,inset:t,...n}){return m.jsx(jie,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Iw({className:e,...t}){return m.jsx(Uie,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}const loe={"no-proxy":{heading:"还没有连接开发机",body:"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。"},"client-token-missing":{heading:"需要 client token",body:"Relay 服务器已启用客户端访问控制。请在设置里填写。"},"client-token-invalid":{heading:"client token 无效",body:"当前浏览器保存的 client token 无效或已过期。请在设置里更新。"},"no-session":{heading:"没有选中的会话",body:""},"no-messages":{heading:"开始对话",body:""}};function Sc({variant:e,action:t}){const{heading:n,body:r}=loe[e];return e==="no-messages"?m.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:m.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[m.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&m.jsx("div",{children:t})]})}const coe={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},uoe={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function DS({status:e,className:t}){return m.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",coe[e],t),role:"status","aria-label":uoe[e]})}function xa({...e}){return m.jsx(cE,{"data-slot":"dialog",...e})}function doe({...e}){return m.jsx(uE,{"data-slot":"dialog-portal",...e})}function foe({...e}){return m.jsx(ay,{"data-slot":"dialog-close",...e})}function hoe({className:e,...t}){return m.jsx(dE,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ea({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return m.jsxs(doe,{"data-slot":"dialog-portal",children:[m.jsx(hoe,{}),m.jsxs(fE,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&m.jsxs(ay,{"data-slot":"dialog-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[m.jsx(jc,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ca({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Rl({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(ay,{asChild:!0,children:m.jsx(Ct,{variant:"outline",children:"Close"})})]})}function Io({className:e,...t}){return m.jsx(iz,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function _a({className:e,...t}){return m.jsx(sz,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function poe(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function moe({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(xa,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Ea,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"移除离线开发机?"}),m.jsx(_a,{children:poe(t)})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(Ct,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(Mo,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const Gg=80,goe=8,voe=1.2;function XN(e){return Math.max(0,Math.min(Gg,e))}function yoe({proxyId:e,name:t,selected:n,revealed:r,disabled:i=!1,onRevealedChange:s,onRemove:o}){const l=t??e,u=b.useRef(null),d=b.useRef(!1),[f,p]=b.useState(null),y=f??(r?Gg:0),v=f!==null;function _(k){var T,R;if(!(i||k.pointerType!=="touch"&&k.pointerType!=="pen")&&!k.target.closest("button")){u.current={pointerId:k.pointerId,startX:k.clientX,startY:k.clientY,startOffset:r?Gg:0,axis:"pending"};try{(R=(T=k.currentTarget).setPointerCapture)==null||R.call(T,k.pointerId)}catch{}}}function w(k){const T=u.current;if(!T||T.pointerId!==k.pointerId)return;const R=k.clientX-T.startX,N=k.clientY-T.startY;if(T.axis==="pending"){if(Math.hypot(R,N)<goe)return;T.axis=Math.abs(R)>Math.abs(N)*voe?"horizontal":"vertical"}T.axis!=="vertical"&&(k.preventDefault(),p(XN(T.startOffset-R)))}function S(k,T=!1){var A,O;const R=u.current;if(!R||R.pointerId!==k.pointerId)return;u.current=null;try{(O=(A=k.currentTarget).releasePointerCapture)==null||O.call(A,k.pointerId)}catch{}if(R.axis!=="horizontal"||T){p(null);return}k.preventDefault();const N=f??XN(R.startOffset-(k.clientX-R.startX));p(null),s(N>=Gg/2),d.current=!0,window.setTimeout(()=>{d.current=!1},0)}function x(k){if(d.current){d.current=!1,k.preventDefault();return}r&&s(!1)}return m.jsxs("li",{className:"relative min-h-11 overflow-hidden rounded-md","data-slot":"proxy-item","data-swipeable":"true","data-proxy-id":e,"data-online":"false","data-revealed":r||void 0,children:[m.jsxs("div",{className:"relative z-10 flex min-h-11 w-full touch-pan-y select-none items-center gap-3 rounded-md border border-border bg-card px-3 text-left text-muted-foreground opacity-60 shadow-sm transition-transform duration-200 ease-out motion-reduce:transition-none",style:{transform:`translateX(-${y}px)`,transitionDuration:v?"0ms":void 0},title:"这台开发机离线。向左滑动可移除。","data-slot":"proxy-swipe-foreground","data-offset":y,onPointerDown:_,onPointerMove:w,onPointerUp:k=>S(k),onPointerCancel:k=>S(k,!0),onClick:x,children:[m.jsx(DS,{status:"offline"}),m.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-normal text-foreground",children:l}),n&&m.jsx(Lo,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}),m.jsx("span",{className:"shrink-0 text-xs",children:"离线"}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon",className:"-mr-2 size-11 text-muted-foreground",disabled:i,"aria-label":`显示移除 ${l} 操作`,"aria-expanded":r,onClick:k=>{k.stopPropagation(),s(!r)},children:m.jsx(A1,{"aria-hidden":"true"})})]}),m.jsxs("button",{type:"button",className:"absolute inset-y-0 right-0 z-0 flex w-20 min-h-11 flex-col items-center justify-center gap-0.5 rounded-r-md bg-destructive text-xs font-medium text-white outline-none transition-colors hover:bg-destructive/90 focus-visible:z-20 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50",tabIndex:r?0:-1,disabled:i,"aria-label":`移除 ${l}`,"data-slot":"proxy-mobile-remove",onFocus:()=>s(!0),onClick:o,children:[m.jsx(O1,{className:"size-4","aria-hidden":"true"}),"移除"]})]})}function s5({layout:e,variant:t="default"}){const n=Le(O=>O.proxies),r=Le(O=>O.proxyListLoaded),i=Le(O=>O.relayClientAuthIssue),s=Le(O=>O.selectedProxyId),o=Le(O=>O.proxySwitchTarget),l=Ui(),u=oo(),[d,f]=b.useState(!1),[p,y]=b.useState(null),[v,_]=b.useState(null),[w,S]=b.useState(null);async function x(O,D){if(o)return;const K=Ut;if(!K){Xe.error("请先连接开发机");return}const U=D??O,X=s!==null&&s!==O;Le.getState().setProxySwitchTarget({proxyId:O,name:U});try{const z=await K.selectProxy(O);if(!z.success){Xe.error(`无法连接 ${U}:${z.error??"未知错误"}`);return}X&&($t.getState().prepareForProxySwitch(U),ni.getState().prepareForProxySwitch()),Cr("local",vn.proxyId,O),Le.getState().setProxy(O,D??null),Le.getState().setProxyOnline(!0),Le.getState().transitionToPhase("session_browsing"),K.sendControl({type:"session_list"}),K.requestProxyInfo().then(M=>{if(Le.getState().selectedProxyId!==O)return;const F=ni.getState();F.setHomePath(M.homePath),F.setAgentCli(M.agentCli)}).catch(M=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",M)}),K.requestAgentStatuses().then(M=>{if(Le.getState().selectedProxyId!==O)return;const F=$t.getState();for(const B of M)F.setAgentStatus(B.sessionId,B.payload)}).catch(M=>{console.error("[proxy-switcher] post-bind data fetch failed",M)}),X1(K).then(M=>{M.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",M.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/"))&&u("/sessions")}catch(z){const M=z instanceof Error?z.message:"未知错误";Xe.error(`无法连接 ${U}:${M}`)}finally{Le.getState().setProxySwitchTarget(null)}}function k(O){O.online||w||(y(null),_({proxyId:O.proxyId,...O.name?{name:O.name}:{}}))}async function T(){const O=v;if(!O||w)return;const D=Ut;if(!D){Xe.error("Relay 连接不可用,请稍后重试");return}const K=Le.getState().proxies.find(U=>U.proxyId===O.proxyId);if(!K){if(!Le.getState().proxyListLoaded){Xe.info("正在重新连接 Relay,请稍后再试");return}Sh(O.proxyId,D)&&u("/"),Xe.info("这台开发机已经不在列表中"),_(null);return}if(K.online){Xe.warning("这台开发机已重新上线,未移除"),_(null);return}S(O.proxyId),vJ(O.proxyId);try{const U=await D.removeOfflineProxy(O.proxyId);if(U.success){ed(O.proxyId),Sh(O.proxyId,D)&&u("/"),Xe.success(`已移除 ${O.name??O.proxyId}`),_(null);return}if(U.errorCode===vr.PROXY_ONLINE){ed(O.proxyId),Xe.warning("这台开发机已重新上线,未移除"),_(null),D.listProxies();return}if(U.errorCode===vr.PROXY_NOT_FOUND){ed(O.proxyId),Sh(O.proxyId,D)&&u("/"),Xe.info("这台开发机已经不在列表中"),_(null),D.listProxies();return}ed(O.proxyId),Xe.error(U.error??"无法移除开发机,请重试")}catch(U){Xe.error(U instanceof Error?U.message:"无法移除开发机,请重试"),D.listProxies()}finally{S(null)}}const R=m.jsx(moe,{open:v!==null,target:v,removing:w!==null,onOpenChange:O=>{O||_(null)},onConfirm:()=>void T()});if(e==="page")return i==="missing_client_token"?m.jsx(Sc,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(Sc,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(Sc,{variant:"no-proxy"}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex h-full flex-col gap-3 overflow-auto p-4",children:[m.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"开发机"}),m.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(O=>{const D=(o==null?void 0:o.proxyId)===O.proxyId,K=o!==null;return O.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":O.proxyId,"data-online":"true","data-selecting":D||void 0,disabled:K||w!==null,"aria-busy":D||void 0,onClick:()=>x(O.proxyId,O.name),className:Ye("flex h-11 min-h-[44px] w-full items-center gap-3 rounded-md border bg-card px-3 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-card",D?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",K&&!D||w!==null?"opacity-50":""),"aria-pressed":s===O.proxyId,children:[m.jsx(DS,{status:"online"}),m.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-normal",children:O.name??O.proxyId}),D?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"正在连接"}),m.jsx(Mo,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===O.proxyId?m.jsx(Lo,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},O.proxyId):m.jsx(yoe,{proxyId:O.proxyId,name:O.name,selected:s===O.proxyId,revealed:p===O.proxyId,disabled:K||w!==null,onRevealedChange:U=>y(U?O.proxyId:null),onRemove:()=>k(O)},O.proxyId)})})]}),R]}):m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[m.jsx(Mo,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const N=n.find(O=>O.proxyId===s),A=(N==null?void 0:N.name)??(N==null?void 0:N.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(PE,{open:d,onOpenChange:f,children:[m.jsx(OE,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${A}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx("span",{className:Ye("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:A}),m.jsx(Ol,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(LE,{align:"start",className:"w-[260px] p-1",children:n.length===0?m.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):m.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(O=>{const D=(o==null?void 0:o.proxyId)===O.proxyId,K=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":O.proxyId,"data-online":O.online,"data-selecting":D||void 0,disabled:!O.online||K,"aria-busy":D||void 0,onClick:()=>x(O.proxyId,O.name),className:Ye("flex h-9 min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",D?"bg-accent text-accent-foreground":"hover:bg-accent",K&&!D?"opacity-50":"",O.online?"":"opacity-50"),"aria-pressed":s===O.proxyId,title:O.online?void 0:"这台开发机离线",children:[m.jsx(DS,{status:O.online?"online":"offline"}),m.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:O.name??O.proxyId}),D?m.jsx(Mo,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===O.proxyId?m.jsx(Lo,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!O.online&&!D&&m.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]}),!O.online&&m.jsxs(Ey,{children:[m.jsx(Cy,{asChild:!0,children:m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:K||w!==null,"aria-label":`${O.name??O.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(A1,{"aria-hidden":"true"})})}),m.jsx(ky,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(Js,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:U=>{U.stopPropagation(),k(O)},children:[m.jsx(O1,{"aria-hidden":"true"}),"移除开发机"]})})]})]},O.proxyId)})})})]}),R]})}function boe({delayDuration:e=0,...t}){return m.jsx(eoe,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function bp({...e}){return m.jsx(toe,{"data-slot":"tooltip",...e})}function _p({...e}){return m.jsx(noe,{"data-slot":"tooltip-trigger",...e})}function wp({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(roe,{children:m.jsxs(ioe,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(soe,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Ty({...e}){return m.jsx(cE,{"data-slot":"sheet",...e})}function _oe({...e}){return m.jsx(Jte,{"data-slot":"sheet-trigger",...e})}function woe({...e}){return m.jsx(uE,{"data-slot":"sheet-portal",...e})}function Soe({className:e,...t}){return m.jsx(dE,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ry({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return m.jsxs(woe,{children:[m.jsx(Soe,{className:t}),m.jsxs(fE,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&m.jsxs(ay,{"data-slot":"sheet-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[m.jsx(jc,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function DE({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function Ay({className:e,...t}){return m.jsx(iz,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function xoe({className:e,...t}){return m.jsx(sz,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}const Eoe={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"},GN=["claude","codex","kimi"];function My(e){return Eoe[e]}function o5(e,t){return GN.indexOf(e)-GN.indexOf(t)}function Wh(e){return e.provider??"claude"}const IS=60*1e3,BS=60*IS,Coe=24*BS;function a5(e,t=Date.now()){const n=t-e;if(n<IS)return"刚刚";if(n<BS)return`${Math.floor(n/IS)} 分钟前`;if(n<Coe)return`${Math.floor(n/BS)} 小时前`;const r=new Date(e),i=r.getMonth()+1,s=r.getDate(),o=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0");return`${i} 月 ${s} 日 ${o}:${l}`}const ZN={idle:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"空闲"},working:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"工作中"},compacting:{dot:"bg-[var(--color-status-compacting)] animate-pulse",text:"text-[var(--color-status-compacting)]",label:"压缩中"},waiting_approval:{dot:"bg-[var(--color-status-warning)]",text:"text-[var(--color-status-warning)]",label:"等待审批"},error:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"出错"},terminated:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已终止"}};function zS(e){return e.kind!=="terminal"?ZN[e.state]:e.state==="terminated"?ZN.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function koe({session:e}){const t=zS(e);return m.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Toe({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?M1:P1;return m.jsx("span",{className:"inline-flex h-5 w-4 shrink-0 items-center justify-center text-muted-foreground",role:"img","aria-label":t,title:t,"data-slot":"session-mode-icon","data-mode":e,children:m.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Roe({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=ny(e.name),d=eE(e),f=e.nameLocked&&e.name?e.name:d||(u==="New Session"?e.sessionId.slice(0,8):u),p=!!e.mode||!!e.provider||o!==void 0,y=o!==void 0?a5(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return m.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&m.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),m.jsxs("button",{type:"button","data-slot":"session-row-select",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx(koe,{session:e}),m.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:f})]}),p&&m.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&m.jsx(Toe,{mode:e.mode}),e.mode&&m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:My(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:Ye("shrink-0",zS(e).text),children:zS(e).label}),y&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&m.jsxs(Ey,{children:[m.jsx(Cy,{asChild:!0,children:m.jsx(Ct,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:m.jsx(A1,{"aria-hidden":"true"})})}),m.jsxs(ky,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(Js,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(Js,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function Al(e){const[t,n]=b.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return b.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function Aoe({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Moe,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:a5(e.updatedAt,t)}),u=m.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return m.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:m.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(gW,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Moe({title:e,modeTag:t}){return m.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[m.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&m.jsx(Noe,{mode:t})]})}function Noe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?M1:P1;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function l5({providerLabel:e}){return m.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:m.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[m.jsx(G7,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),m.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Poe({now:e}){const t=$t(X=>X.historySessions),n=$t(X=>X.historyLoadStatus),[r,i]=b.useState(null),[s,o]=b.useState(null),[l,u]=b.useState("json"),[d,f]=b.useState("default"),[p,y]=b.useState(!1),[v,_]=b.useState(new Set),[w,S]=b.useState(new Set),x=oo(),k=b.useMemo(()=>{const X=new Map;for(const z of t){const M=Wh(z);let F=X.get(M);F||(F=new Map,X.set(M,F));const B=c5(z.projectDir),P=F.get(B);P?P.sessions.push(z):F.set(B,{dir:B,sessions:[z]})}return Array.from(X.entries()).sort(([z],[M])=>o5(z,M)).map(([z,M])=>({provider:z,sessions:Array.from(M.values()).flatMap(F=>F.sessions),projects:Array.from(M.values()).map(F=>({dir:F.dir,shortDir:ny(F.dir),sessions:F.sessions}))}))},[t]);function T(X){o(X),u(Ooe(X)),f(Loe(X))}async function R(X,z,M){if(r)return;const F=Ut;if(!F){Xe.error("请先连接开发机");return}i(X.id);const B=Wh(X);try{const P=await F.createSession({cwd:X.projectDir,mode:z,provider:B,resumeSessionId:X.id,...M?{permissionMode:M}:{}});if(P.error||!P.sessionId){if(P.errorCode===vr.SESSION_ALREADY_ACTIVE){$t.getState().setCodexActiveWriterConflict({...P.activeWriterPid?{activeWriterPid:P.activeWriterPid}:{}}),o(null);return}Xe.error(`恢复失败:${P.error??"未知错误"}`);return}const I={sessionId:P.sessionId,...P.kind!==void 0?{kind:P.kind}:{},...P.name!==void 0?{name:P.name}:{},...P.nameLocked!==void 0?{nameLocked:P.nameLocked}:{},state:"idle",mode:P.mode??z,provider:P.provider??"claude",...P.ptyOwner!==void 0?{ptyOwner:P.ptyOwner}:{}};$t.getState().addSession(I),x(`/chat/${P.sessionId}?mode=${P.mode??z}`),o(null)}catch(P){Xe.error(`恢复失败:${P instanceof Error?P.message:String(P)}`)}finally{i(null)}}function N(){const X=Ut;!X||$t.getState().historyLoadStatus==="loading"||X1(X).then(z=>{z.status==="failed"&&Xe.error(z.error instanceof Error?z.error.message:String(z.error))})}function A(X,z){const M=QN(X,z);S(F=>{const B=new Set(F);return B.has(M)?B.delete(M):B.add(M),B})}function O(X){_(z=>{const M=new Set(z);return M.has(X)?M.delete(X):M.add(X),M})}const D=t.length>0,K=n==="loading",U=s?u5():[];return m.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[m.jsxs("div",{className:"flex min-h-11 w-full items-center gap-1.5 px-4 py-1.5 md:min-h-[36px]",children:[m.jsxs("button",{type:"button",onClick:()=>D&&y(X=>!X),disabled:!D,"aria-expanded":D?p:void 0,"data-slot":"history-section-header","data-expanded":p,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",D?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),D?m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",p&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":K,title:K?"正在加载":"刷新",onClick:N,disabled:K,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(N1,{className:Ye("size-3.5",K&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!D&&K&&m.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-loading",role:"status","aria-live":"polite",children:[m.jsx(Mo,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!D&&n==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!D&&n==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),D&&n==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!D&&n==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),D&&p&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(X=>{const z=v.has(X.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>O(X.provider),"aria-expanded":!z,"data-slot":"history-provider-header","data-expanded":!z,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:My(X.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:X.sessions.length}),m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!z&&"rotate-90"),"aria-hidden":"true"})]}),!z&&m.jsx("ul",{role:"list",className:"flex flex-col",children:X.projects.map(M=>{const F=QN(X.provider,M.dir),B=w.has(F);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>A(X.provider,M.dir),"aria-expanded":B,"data-slot":"history-group-header","data-expanded":B,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),m.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",B&&"rotate-90"),"aria-hidden":"true"})]}),B&&m.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(P=>m.jsx(Aoe,{session:P,now:e,disabled:r!==null,loading:r===P.id,onClick:()=>T(P),modeTag:P.preferredMode},P.id))})]},F)})})]},X.provider)})}),m.jsx(Doe,{session:s,open:s!==null,modes:U,mode:l,permissionMode:d,submitting:r!==null,onOpenChange:X=>{X||o(null)},onModeChange:u,onPermissionModeChange:f,onConfirm:()=>{s&&R(s,l,d)}})]})}function QN(e,t){return`${e}:${c5(t)}`}function c5(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function u5(){return["json","pty"]}function Ooe(e){const t=u5();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Loe(e){return Wh(e)==="codex"?"auto":"default"}function Doe({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[f,p]=b.useState(!1),y=i==="bypassPermissions",v=Al("(min-width: 768px)"),_=e?Wh(e):null,w=_==="codex",S=_==="kimi";b.useEffect(()=>{t||p(!1)},[t]);const x=f?m.jsx(l5,{providerLabel:e?My(Wh(e)):"Agent"}):m.jsxs("div",{className:"grid min-w-0 gap-4",children:[m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&m.jsx(JN,{checked:r==="json",label:"聊天",icon:m.jsx(M1,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(JN,{checked:r==="pty",label:"终端",icon:m.jsx(P1,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[!w&&m.jsx(fg,{checked:i==="default",label:S?"手工审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),m.jsx(fg,{checked:i==="auto",label:w?"按需审批":S?"自动审批":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),S&&m.jsx(fg,{checked:i==="plan",label:"只读规划",description:"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(fg,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(Ct,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?p(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(Ct,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(y&&!f){p(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return v?m.jsx(xa,{open:t,onOpenChange:o,children:m.jsxs(Ea,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Ca,{className:"min-w-0",children:[m.jsx(Io,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(_a,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),x,m.jsx(Rl,{children:k})]})}):m.jsx(Ty,{open:t,onOpenChange:o,children:m.jsxs(Ry,{side:"bottom",focusSurfaceOnOpen:!0,className:"inset-x-2 w-auto max-h-[calc(100dvh-0.75rem)] min-w-0 overflow-hidden rounded-t-xl border bg-background p-0","data-slot":"history-restore-dialog",children:[m.jsxs(DE,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(Ay,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(xoe,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),m.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:x}),m.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:m.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:k})})]})})}function JN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(Lo,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function fg({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),m.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&m.jsx(Lo,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Ioe({...e}){return m.jsx(Tse,{"data-slot":"select",...e})}function Boe({...e}){return m.jsx(Ase,{"data-slot":"select-value",...e})}function zoe({className:e,size:t="default",children:n,...r}){return m.jsxs(Rse,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(Mse,{asChild:!0,children:m.jsx(Ol,{className:"size-4 opacity-50"})})]})}function joe({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return m.jsx(Nse,{children:m.jsxs(Pse,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[m.jsx(Foe,{}),m.jsx(Ose,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(Hoe,{})]})})}function $oe({className:e,children:t,...n}){return m.jsxs(Lse,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(Ise,{children:m.jsx(Lo,{className:"size-4"})})}),m.jsx(Dse,{children:t})]})}function Foe({className:e,...t}){return m.jsx(Bse,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(T1,{className:"size-4"})})}function Hoe({className:e,...t}){return m.jsx(zse,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(Ol,{className:"size-4"})})}function IE(e){return!e||e.endsWith("/")?e:`${e}/`}function Uoe(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function Woe(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function qoe(e,t,n){var o;if(t==="insert")return{currentPath:Woe(e)||"./",query:Uoe(e)};if(!e)return{currentPath:"./",query:""};const r=e.replace(/\/+$/,"")||"/";if(e.endsWith("/")||r===(n==null?void 0:n.baseCwd)||((o=n==null?void 0:n.knownDirs)==null?void 0:o.has(r)))return{currentPath:IE(r),query:""};const s=e.lastIndexOf("/");return{currentPath:s>=0?e.slice(0,s+1):"./",query:s>=0?e.slice(s+1).toLowerCase():e.toLowerCase()}}function Yoe(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function Voe(e,t){return`${IE(e)}${t.name}${t.isDir?"/":""}`}function e2(e,t){const n=e.trim().replace(/\/+$/,"")||"/",r=t.trim().replace(/^\/+|\/+$/g,"");return!n.startsWith("/")||!r||t.trim().startsWith("/")||r.split("/").some(i=>i===""||i==="."||i==="..")?null:n==="/"?`/${r}`:`${n}/${r}`}const d5=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ni(j=>j.tree),f=ni(j=>j.cwd),p=ni(j=>j.homePath),y=i==="insert"?f:p||f,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>qoe(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,S=b.useMemo(()=>Yoe(y,w),[y,w]),x=_.query,k=b.useRef(new Set),[T,R]=b.useState(!1),[N,A]=b.useState(""),[O,D]=b.useState(!1);b.useEffect(()=>{if(!S||d.has(S)||k.current.has(S))return;const j=Ut;if(!j)return;let L=!1;return k.current.add(S),j.requestDirectoryList(S).then(Y=>{L||ni.getState().setDirEntries(Y.path,Y.entries)}).catch(()=>{L||ni.getState().setDirEntries(S,[])}).finally(()=>{k.current.delete(S)}),()=>{L=!0}},[S,d]);const K=!d.has(S),U=b.useMemo(()=>{let j=d.get(S)??[];return o&&(j=j.filter(L=>L.isDir)),x&&(j=j.filter(L=>L.name.toLowerCase().includes(x))),j},[d,S,x,o]),[X,z]=b.useState(0);b.useEffect(()=>z(0),[w,x]),b.useEffect(()=>{R(!1),A("")},[S]),b.useEffect(()=>{X>=U.length&&U.length>0&&z(U.length-1)},[U.length,X]);const M=b.useRef(null),F=b.useRef(!1);b.useEffect(()=>{var L;if(!F.current)return;F.current=!1;const j=(L=M.current)==null?void 0:L.querySelector(`[data-entry-index="${X}"]`);j==null||j.scrollIntoView({block:"nearest"})},[X]);const B=b.useCallback(j=>{const L=Voe(w,j);return i==="insert"?L.replace(/^\.\//,""):L},[w,i]);async function P(){const j=e2(S,N);if(!(!j||!r)){D(!0);try{const L=await r(j);if(!L)return;A(""),R(!1),n(IE(L))}finally{D(!1)}}}b.useImperativeHandle(u,()=>({handleKey(j){return U.length===0?!1:j.key==="ArrowDown"?(F.current=!0,z(L=>Math.min(U.length-1,L+1)),!0):j.key==="ArrowUp"?(F.current=!0,z(L=>Math.max(0,L-1)),!0):j.key==="Enter"&&!j.nativeEvent.isComposing?(n(B(U[X])),!0):!1}}),[U,X,B,n]);const I=s==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":i==="insert"?"absolute bottom-full left-0 right-0 z-50 mb-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden":"absolute left-0 right-0 top-full z-50 mt-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden",W=s==="inline"?"h-44 overflow-y-auto overscroll-contain":i==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return m.jsxs("div",{className:I,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?m.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?m.jsx("button",{type:"button",className:"rounded px-2 py-1 text-xs text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",disabled:!S||O,onClick:()=>R(j=>!j),children:"新建目录"}):null]}),T?m.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[m.jsx("input",{type:"text",value:N,onChange:j=>A(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.nativeEvent.isComposing&&(j.preventDefault(),P()),j.key==="Escape"&&(R(!1),A(""))},placeholder:"目录名称",className:"min-h-11 min-w-0 flex-1 rounded-md border border-border bg-input px-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-8 md:min-h-0 md:text-sm",autoComplete:"off",autoCorrect:"off",spellCheck:!1}),m.jsx("button",{type:"button",className:"min-h-11 rounded-md bg-primary px-3 text-sm text-primary-foreground disabled:cursor-not-allowed disabled:opacity-50 md:h-8 md:min-h-0",disabled:!e2(S,N)||O,onClick:()=>void P(),children:O?"创建中...":"创建目录"})]}):null]}):null,m.jsx("div",{className:W,children:U.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:K?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map((j,L)=>m.jsx("li",{children:m.jsx("button",{type:"button",onClick:()=>n(B(j)),onMouseEnter:()=>z(L),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",L===X&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",j.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":j.isDir?"dir":"file","data-entry-index":L,children:m.jsxs("span",{className:"font-mono text-[13px]",children:[j.name,j.isDir?"/":""]})})},j.name))})})]})}),t2="工作目录不存在或不可访问:",Koe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],f5=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],h5=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],ma={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"};function Xoe(e,t){return t!==vr.PATH_NOT_FOUND||!e.startsWith(t2)?null:e.slice(t2.length).trim()||null}function xh(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n?n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}:{label:"未检测",disabled:!0}}function Goe(e,t){return t.title?t.disabled?`${ma[e]}:${t.title}`:`${ma[e]} 路径:${t.title}`:`${ma[e]}:${t.label}`}function Zoe(e,t){return e==="codex"?f5.some(n=>n.value===t)?t:"auto":e==="kimi"?h5.some(n=>n.value===t)?t:"default":t}async function Qoe({relay:e,agentCli:t,form:n,timeoutMs:r=V1}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(xh(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${ma[n.provider]} 不可用:${p}`:`${ma[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=Xoe(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,v=((f=p.name)==null?void 0:f.trim())||void 0;return{type:"success",session:{sessionId:p.sessionId,...p.kind!==void 0?{kind:p.kind}:{},name:v,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",mode:y,provider:p.provider??l,...p.ptyOwner!==void 0?{ptyOwner:p.ptyOwner}:{}},route:`/chat/${p.sessionId}?mode=${y}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function Joe({relay:e,timeoutMs:t=V1}){var n;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const r=await e.createSession({kind:"terminal",mode:"pty"},t);return r.error||!r.sessionId?{type:"create_error",message:`创建终端失败:${r.error??"未知错误"}`}:{type:"success",session:{sessionId:r.sessionId,kind:"terminal",name:((n=r.name)==null?void 0:n.trim())||void 0,...r.nameLocked!==void 0?{nameLocked:r.nameLocked}:{},state:"idle",mode:"pty",provider:r.provider??"claude",...r.ptyOwner!==void 0?{ptyOwner:r.ptyOwner}:{}},route:`/chat/${r.sessionId}?mode=pty`}}catch(r){return{type:"exception",message:r instanceof Error?r.message:String(r)}}}function eae({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:f}){const p=xh("claude",e),y=xh("codex",e),v=xh("kimi",e),_=e==null?void 0:e[t];return m.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsx("span",{className:"text-sm",children:"Agent CLI"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-3",children:[m.jsx(Bw,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),m.jsx(Bw,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")}),m.jsx(Bw,{provider:"kimi",selected:t==="kimi",status:v,agentCliLoaded:!!e,onClick:()=>o("kimi")})]}),m.jsx("div",{className:"relative min-w-0 rounded-md border border-border bg-muted/20 px-3 py-2.5 md:p-3","data-slot":"agent-cli-path-card",children:r===t?m.jsx(tae,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:f}):m.jsx(nae,{provider:t,selectedCli:_,isDesktop:n,onOpenCliPathEditor:l})})]})}function Bw({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return m.jsxs(bp,{children:[m.jsx(_p,{asChild:!0,children:m.jsxs("button",{type:"button","aria-pressed":t,"aria-label":ma[e],onClick:i,className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:ma[e]}),m.jsx("span",{className:Ye("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),m.jsx(wp,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:m.jsx("span",{className:"break-all font-mono text-xs",children:Goe(e,n)})})]})}function tae({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){var l;return m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),m.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[m.jsxs("label",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"sr-only",children:"CLI 路径"}),m.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),o()),u.key==="Escape"&&(u.preventDefault(),s())},placeholder:`/path/to/${e==="kimi"?"kimi":e}`,className:"min-h-11 w-full rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-10 md:min-h-0 md:text-sm"}),m.jsx("datalist",{id:`agent-cli-path-${e}`,children:(((l=t==null?void 0:t[e])==null?void 0:l.suggestions)??[]).map(u=>m.jsx("option",{value:u},u))})]}),m.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[m.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground md:h-8 md:min-h-0",onClick:s,disabled:r,children:"取消"}),m.jsx(Ct,{type:"button",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium md:h-8 md:min-h-0",onClick:o,disabled:r||!n.trim(),children:r?"保存中...":"保存路径"})]})]})]})}function nae({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),m.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[m.jsx("p",{className:Ye("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),m.jsx(Ct,{type:"button",variant:"outline",className:"h-8 min-h-0 shrink-0 self-end rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground sm:self-auto",onClick:()=>r(e),children:"指定路径"})]})]}):m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 size-11 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/70 hover:text-foreground","aria-label":"指定路径",onClick:()=>r(e),children:m.jsx(k7,{className:"size-4","aria-hidden":"true"})}),m.jsx("p",{className:Ye("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function lh({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,p]=b.useState("default"),[y,v]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[k,T]=b.useState(!1),[R,N]=b.useState(null),[A,O]=b.useState(""),[D,K]=b.useState(!1),U=b.useRef(null),X=b.useRef(e);X.current=e;const z=oo(),M=ni(me=>me.homePath),F=ni(me=>me.agentCli),B=Al("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&F)return;const me=Ut==null?void 0:Ut.requestProxyInfo();me&&me.then(Ee=>{const De=ni.getState();De.setHomePath(Ee.homePath),De.setAgentCli(Ee.agentCli)}).catch(Ee=>{console.error("[create-session-dialog] requestProxyInfo failed",Ee)})},[e,M,F]),b.useEffect(()=>{if(!k)return;function me(Ee){var Se;const De=Ee.target;De instanceof Node&&((Se=U.current)!=null&&Se.contains(De))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",me,!0),()=>document.removeEventListener("pointerdown",me,!0)},[k]);function P(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),v(!1),x(null),N(null),O(""),K(!1)}function I(){if(f==="bypassPermissions"){v(!0);return}$()}async function W(){await $(),X.current&&v(!1)}const j=o==="codex"?f5:o==="kimi"?h5:Koe,L=xh(o,F),Y=_||D||L.disabled;function V(me){const Ee=Zoe(me,f);Ee!==f&&p(Ee)}async function $(me){x(null),w(!0);try{const Ee=await Qoe({relay:Ut,agentCli:F,form:{cwd:me??i,name:n,provider:o,permissionMode:f,mode:u}});if(Ee.type==="success"){if($t.getState().addSession(Ee.session),!X.current)return;t(!1),P(),z(Ee.route);return}if(Ee.type==="missing_cwd"&&x(Ee.path),Xe.error(Ee.message),Ee.type==="validation_error"||Ee.type==="relay_missing")return}finally{w(!1)}}async function te(me){const Ee=Ut;if(!Ee)return Xe.error("请先连接开发机"),null;try{const De=await Ee.createDirectory(me);return De.success?(s(De.path),x(null),Xe.success("目录已创建"),De.path):(Xe.error(`目录创建失败:${De.error??"未知错误"}`),null)}catch(De){return Xe.error(De instanceof Error?De.message:String(De)),null}}function re(me){var De;const Ee=F==null?void 0:F[me];N(me),O((Ee==null?void 0:Ee.command)??((De=Ee==null?void 0:Ee.suggestions)==null?void 0:De[0])??"")}async function oe(){if(!R)return;const me=A.trim();if(!me){Xe.error("请输入 Agent CLI 路径");return}const Ee=Ut;if(!Ee){Xe.error("请先连接开发机");return}K(!0);try{const De=await Ee.updateAgentCliPath(R,me);if(De.error||!De.agentCli){Xe.error(`路径保存失败:${De.error??"未知错误"}`);return}ni.getState().setAgentCli(De.agentCli),Xe.success(`${ma[R]} 路径已保存`),N(null),O("")}catch(De){Xe.error(De instanceof Error?De.message:String(De))}finally{K(!1)}}function ee(me){d(me),V(o)}function pe(me){var De;const Ee=me.relatedTarget;Ee instanceof Node&&((De=U.current)!=null&&De.contains(Ee))||window.setTimeout(()=>T(!1),0)}const ae=y?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(l5,{providerLabel:ma[o]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),m.jsx(Ct,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void W(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:me=>{me.preventDefault(),I()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:me=>r(me.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),m.jsxs("div",{ref:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:pe,children:[m.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),m.jsx("input",{id:"create-session-cwd",type:"text","aria-labelledby":"create-session-cwd-label",name:"dev-anywhere-session-cwd",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:i,onFocus:()=>T(!0),onChange:me=>{s(me.target.value),x(null)},placeholder:"输入绝对路径",className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm"}),k?m.jsx(d5,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:te,onSelect:me=>{s(me),x(null),T(!0)}}):null]}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>ee("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>ee("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(eae,{agentCli:F,provider:o,isDesktop:B,editingCliProvider:R,cliPathInput:A,savingCliPath:D,onProviderChange:me=>{l(me),V(me)},onOpenCliPathEditor:re,onCliPathInputChange:O,onCancelCliPathEditor:()=>{N(null),O("")},onSaveCliPath:()=>void oe()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(Ioe,{value:f,onValueChange:me=>p(me),children:[m.jsx(zoe,{className:"w-full",children:m.jsx(Boe,{})}),m.jsx(joe,{children:j.map(me=>m.jsx($oe,{value:me.value,children:me.label},me.value))})]})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(Ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return B?m.jsx(xa,{open:e,onOpenChange:t,children:m.jsxs(Ea,{className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[44rem]","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[m.jsx(Ca,{children:m.jsx(Io,{children:y?"跳过全部审批?":"新建会话"})}),ae]})}):m.jsx(Ty,{open:e,onOpenChange:t,children:m.jsxs(Ry,{side:"bottom",className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto overflow-x-hidden overflow-y-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[m.jsx(DE,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(Ay,{children:y?"跳过全部审批?":"新建会话"})}),ae]})})}function ch({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=b.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=b.useState(s),[u,d]=b.useState(null),[f,p]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(v){v.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return m.jsx(xa,{open:e,onOpenChange:r,children:m.jsx(Ea,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>void y(v),children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"重命名会话"}),m.jsx(_a,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),m.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:f,onChange:v=>{l(v.target.value),u&&d(null)}}),u?m.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(Ct,{type:"submit",disabled:f,children:"保存"})]})]})})})}function rae(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function iae(e){return(e==null?void 0:e.kind)==="terminal"}function sae(e){return rae(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:iae(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function hg({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=sae(t);function s(){t&&(r(t),n(!1))}return m.jsx(xa,{open:e,onOpenChange:n,children:m.jsxs(Ea,{"data-slot":"session-termination-dialog",children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:i.title}),m.jsx(_a,{children:i.description})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(Ct,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function p5(e){var t,n,r,i,s,o,l,u,d,f,p,y;return e.connected===!1||e.proxyOnline===!1?"disconnected":e.routeSessionEnded||((t=e.session)==null?void 0:t.state)==="terminated"?"terminated":((n=e.session)==null?void 0:n.state)==="error"?"error":e.hasPendingApproval||((r=e.session)==null?void 0:r.state)==="waiting_approval"?"waiting_approval":((i=e.session)==null?void 0:i.state)==="compacting"?"compacting":((s=e.session)==null?void 0:s.state)==="working"?"working":((o=e.session)==null?void 0:o.state)==="idle"?"idle":((l=e.agentStatus)==null?void 0:l.phase)==="waiting_permission"||((u=e.ptyState)==null?void 0:u.state)==="approval_wait"?"waiting_approval":((d=e.agentStatus)==null?void 0:d.phase)==="thinking"||((f=e.agentStatus)==null?void 0:f.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function oae(e){if(e.session.state==="error")return"error";const t=p5(e);return t==="disconnected"?e.session.state:t}function m5({layout:e}){const t=$t(te=>te.sessions),n=$t(te=>te.sessionListLoaded),r=$t(te=>te.agentStatusBySessionId),i=$t(te=>te.ptyStateBySessionId),s=$t(te=>te.renameSession),o=Xt(te=>te.bySessionId),l=Y8("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Le(te=>!!te.selectedProxyId),f=Le(te=>te.proxyListLoaded),p=Le(te=>te.proxySwitchTarget),y=$t(te=>te.loadingProxyName),v=p!==null||!f||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",S=oo(),[x,k]=b.useState(!1),[T,R]=b.useState(!1),[N,A]=b.useState(null),[O,D]=b.useState(null),{creatingTerminal:K,createTerminal:U}=g5(),[X,z]=b.useState(new Set),[M,F]=b.useState(()=>Date.now());b.useEffect(()=>{const te=setInterval(()=>F(Date.now()),6e4);return()=>clearInterval(te)},[]);function B(te,re){S(`/chat/${te}?mode=${re??"json"}`,{replace:!1})}function P(te){const re=te.sessionId,oe=Ut;if(!oe){Xe.error("请先连接开发机");return}oe.sendControl({type:"session_terminate",sessionId:re}),$t.getState().removeSession(re),Xt.getState().clearSession(re),re===u&&S("/sessions"),(te==null?void 0:te.mode)==="pty"&&te.ptyOwner==="local-terminal"?Xe.info("已断开页面连接,本地终端仍在运行"):Xe.info("正在终止会话",{duration:1500})}async function I(te,re){const oe=Ut;if(!oe)throw new Error("请先连接开发机");const ee=await oe.renameSession(te,re);if(!ee.success)throw new Error(ee.error??"重命名失败");s(te,ee.name??re),Xe.success("已重命名会话")}function W(te){z(re=>{const oe=new Set(re);return oe.has(te)?oe.delete(te):oe.add(te),oe})}function j(te){var ee;const re=te.mode==="json"&&(((ee=o[te.sessionId])==null?void 0:ee.pendingApprovals.some(pe=>pe.status==="pending"))??!1),oe=oae({session:te,agentStatus:r[te.sessionId],ptyState:i[te.sessionId],hasPendingApproval:re});return oe===te.state?te:{...te,state:oe}}const L=t.length>0;if(e==="sidebar"&&(v||!d))return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":v?"session-list-loading":void 0,role:v?"status":void 0,"aria-live":v?"polite":void 0,children:v?w:"请先连接开发机"}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]});if(e==="page"&&v)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[m.jsx(Mo,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsx("div",{className:"flex-1",children:m.jsx(Sc,{variant:"no-proxy"})}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]});const Y=m.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",L?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),V=L?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:aae(t).map(te=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>W(te.provider),"aria-expanded":!X.has(te.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:lae(te.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:te.sessions.length}),m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!X.has(te.provider)&&"rotate-90"),"aria-hidden":"true"})]}),X.has(te.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:te.sessions.map(re=>m.jsx(Roe,{session:j(re),selected:re.sessionId===u,now:M,onClick:()=>B(re.sessionId,re.mode),onRename:()=>A(re),onTerminate:()=>D(re)},re.sessionId))})]},te.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),$=m.jsx(Poe,{now:M});return e==="page"?m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,V,$]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(Ct,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>R(!0),children:[m.jsx(GD,{"aria-hidden":"true"}),"新建"]})}),m.jsx(uae,{open:T,creatingTerminal:K,onOpenChange:R,onCreateAgent:()=>{R(!1),k(!0)},onCreateTerminal:()=>void U(()=>R(!1))}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,V,$]}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]})}function aae(e){const t=new Map;for(const n of e){const r=n.kind==="terminal"?"terminal":n.provider,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t.entries()).sort(([n],[r])=>cae(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function lae(e){return e==="terminal"?"终端":My(e)}function cae(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:o5(e,t)}function g5(){const e=oo(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await Joe({relay:Ut});if(s.type!=="success"){Xe.error(s.message);return}$t.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function n2({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Le(x=>!!x.selectedProxyId),l=Le(x=>x.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:f}=g5();function p(){i(!0),window.setTimeout(()=>i(!1),2e3)}function y(){if(!u){p();return}s.current=!0,n(!0)}function v(){if(!u){p();return}s.current=!0,f()}function _(x){x.preventDefault(),p()}const w=m.jsxs(Ct,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!u&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!u,onClick:u?void 0:_,children:[m.jsx(GD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),S=u?m.jsxs(Ey,{children:[m.jsx(Cy,{asChild:!0,children:w}),m.jsxs(ky,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:x=>{s.current&&(s.current=!1,x.preventDefault())},children:[m.jsxs(Js,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[m.jsx(XD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(Js,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[m.jsx(Dh,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return m.jsxs(m.Fragment,{children:[u?S:m.jsxs(bp,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[m.jsx(_p,{asChild:!0,children:S}),m.jsx(wp,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),m.jsx(lh,{open:t,onOpenChange:n})]})}function uae({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=b.useRef(!1);function o(l){s.current=!0,l()}return m.jsx(Ty,{open:e,onOpenChange:n,children:m.jsxs(Ry,{side:"bottom",overlayClassName:"bg-black/10 dark:bg-black/30",className:"inset-x-2 w-auto rounded-t-xl border border-border/80 bg-background px-3 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3 shadow-2xl","data-slot":"create-session-type-sheet",focusSurfaceOnOpen:!0,onCloseAutoFocus:l=>{s.current&&(s.current=!1,l.preventDefault())},children:[m.jsx(DE,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(Ay,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(Ct,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-agent-session-sheet-item",onClick:()=>o(r),children:[m.jsx(XD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(Ct,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-terminal-session-sheet-item",disabled:t,onClick:()=>o(i),children:[m.jsx(Dh,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const dae="0.8.0",fae={version:dae},hae={playback:"playback",capture:"play-and-record"};function pae(){return typeof navigator>"u"?null:navigator.audioSession??null}function mae(){return{setMode:()=>{},release:()=>{}}}class gae{constructor(t=pae){_t(this,"leases",new Map);_t(this,"session",null);_t(this,"baselineType",null);_t(this,"nextLeaseId",1);_t(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return mae();this.leases.size===0&&(this.session=n,this.baselineType=n.type);const r=this.nextLeaseId++;this.leases.set(r,{mode:t,order:this.nextOrder++});try{this.applyActiveMode()}catch(s){throw this.leases.delete(r),this.leases.size===0?this.restoreWhenUnused():this.applyActiveModeBestEffort(),s}let i=!1;return{setMode:s=>{if(i)return;const o=this.leases.get(r);if(!o)return;const l={...o};o.mode=s,o.order=this.nextOrder++;try{this.applyActiveMode()}catch(u){throw this.leases.set(r,l),this.applyActiveModeBestEffort(),u}},release:()=>{if(!i){if(i=!0,this.leases.delete(r),this.leases.size===0){this.restoreWhenUnused();return}this.applyActiveModeBestEffort()}}}}applyActiveMode(){const t=[...this.leases.values()].reduce((n,r)=>!n||r.order>n.order?r:n,null);!t||!this.session||this.setNativeType(hae[t.mode])}applyActiveModeBestEffort(){try{this.applyActiveMode()}catch{}}restoreWhenUnused(){const t=this.session,n=this.baselineType;if(this.session=null,this.baselineType=null,!(!t||n===null))try{t.type=n}catch{}}setNativeType(t){if(!(!this.session||this.session.type===t)){try{this.session.type=t}catch{throw new Error("浏览器无法切换语音音频模式")}if(this.session.type!==t)throw new Error("浏览器无法切换语音音频模式")}}}const BE=new gae,jS=64,r2=-60,v5=32;function i2(e){if(!Number.isFinite(e)||e===0)return 0;const t=Math.min(1,Math.abs(e)),n=20*Math.log10(t),r=Math.max(0,Math.min(1,(n-r2)/-r2));return e<0?-r:r}function s2(e,t=8){const n=Math.floor(e.byteLength/2);if(n===0||!Number.isFinite(t)||t<=0)return[];const r=Math.min(n,Math.max(1,Math.floor(t))),i=new DataView(e.buffer,e.byteOffset,e.byteLength),s=[];for(let o=0;o<r;o+=1){const l=Math.floor(o*n/r),u=Math.max(l+1,Math.floor((o+1)*n/r));let d=1,f=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),f=Math.max(f,y)}s.push({min:d,max:f})}return s}function vae(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=Math.floor(e.byteLength/2),r=new Float32Array(n);for(let i=0;i<n;i+=1)r[i]=t.getInt16(i*2,!0)/32768;return r}function yae(e){if(e.length===0)return 0;const t=Math.max(1,Math.floor(e.length/512));let n=0,r=0;for(let i=0;i<e.length;i+=t){const s=e[i]??0;n+=s*s,r+=1}return r===0?0:Math.min(1,Math.sqrt(n/r)*10)}class y5{constructor(t,n=24e3,r={}){_t(this,"nextStartTime",0);_t(this,"activityEndToken",0);_t(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=vae(t),r=this.context.createBuffer(1,n.length,this.sampleRate);r.getChannelData(0).set(n);const i=this.context.createBufferSource();i.buffer=r,i.connect(this.context.destination);const s=Math.max(this.context.currentTime,this.nextStartTime);i.start(s);const o=s+r.duration;this.nextStartTime=o,this.schedulePlaybackFrames(t,n,s,o);const l=Math.max(0,(o-this.context.currentTime)*1e3);return this.emitPlaybackEvent("pcm-scheduled",{bytes:t.byteLength,durationMs:r.duration*1e3}),typeof i.addEventListener=="function"&&i.addEventListener("ended",()=>{this.emitPlaybackEvent("source-ended",{bytes:t.byteLength,durationMs:r.duration*1e3})},{once:!0}),l}stop(){var t,n;this.nextStartTime=this.context.currentTime,this.activityEndToken+=1;for(const r of this.timelineTimers)clearTimeout(r);this.timelineTimers.clear(),(n=(t=this.options).onActivityLevel)==null||n.call(t,0),this.emitPlaybackEvent("stopped")}snapshot(){const t=this.context.currentTime;return{contextState:String(this.context.state??"unknown"),contextTime:t,nextStartTime:this.nextStartTime,queuedMs:Math.max(0,(this.nextStartTime-t)*1e3)}}schedulePlaybackFrames(t,n,r,i){if(!this.options.onActivityLevel&&!this.options.onPlaybackChunk)return;const s=Math.max(1,Math.round(this.sampleRate*v5/1e3)),o=this.activityEndToken+=1;for(let l=0;l<n.length;l+=s){const u=Math.min(n.length,l+s),d=r+l/this.sampleRate,f=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),y=yae(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,S;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(S=(w=this.options).onPlaybackChunk)==null||S.call(w,p)},f)}if(this.options.onActivityLevel){const l=Math.max(0,(i-this.context.currentTime)*1e3);this.scheduleTimer(()=>{var u,d;o===this.activityEndToken&&((d=(u=this.options).onActivityLevel)==null||d.call(u,0))},l)}}scheduleTimer(t,n){const r=setTimeout(()=>{this.timelineTimers.delete(r),t()},n);this.timelineTimers.add(r)}emitPlaybackEvent(t,n={}){var r,i;(i=(r=this.options).onPlaybackEvent)==null||i.call(r,{event:t,...this.snapshot(),...n})}}const zw={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},o2="min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none transition-colors placeholder:text-muted-foreground/65 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",bae=800,a2=300,_ae=1600;function $S(e,t){return e.filter(n=>!n.model||n.model===t)}function l2({label:e,children:t,help:n}){return m.jsxs("div",{className:"block min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 transition-colors focus-within:border-ring/55 focus-within:bg-card/75 sm:p-3",children:[m.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.jsx("div",{className:"mt-2 min-w-0",children:t}),n?m.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function pg({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=b.useState(!1),u=b.useId(),d=n.find(v=>v.value===t),f=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!b5(f).detail;return m.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:v=>{v.currentTarget.contains(v.relatedTarget)||l(!1)},children:[m.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.jsxs("button",{type:"button","aria-labelledby":u,"aria-haspopup":"listbox","aria-expanded":o,disabled:p.length===0,className:`mt-2 flex w-full min-w-0 items-center justify-between gap-3 rounded-md border border-border bg-input px-3 text-left outline-none transition-colors hover:border-primary/40 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(v=>!v),"data-slot":"voice-settings-choice-trigger",children:[m.jsx(c2,{label:f,muted:!d&&!t}),m.jsx(Ol,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?m.jsx("div",{role:"listbox","aria-labelledby":u,className:"mt-2 max-h-64 overflow-y-auto rounded-md border border-border/80 bg-popover p-1 shadow-sm",children:n.map(v=>{const _=v.value===t;return m.jsxs("button",{type:"button",role:"option","aria-label":v.label,"aria-selected":_,disabled:v.disabled,className:"flex w-full min-w-0 items-center gap-2 rounded-sm px-2.5 py-2.5 text-left text-sm outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-45",onClick:()=>{v.disabled||(r(v.value),l(!1))},children:[m.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?m.jsx(Lo,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(c2,{label:v.label})]},v.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function c2({label:e,muted:t=!1}){const n=b5(e);return m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?m.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function wae({scrollRef:e}={}){const[t,n]=b.useState(zw),[r,i]=b.useState(String(zw.turnIdleSeconds)),[s,o]=b.useState(()=>eg()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),k=b.useRef(null),T=b.useRef(null),R=b.useRef(!1);b.useEffect(()=>{const ee=Ut;if(!ee){_({kind:"error",message:"请先连接 Relay 服务器"});return}let pe=!1;return _({kind:"loading"}),ee.requestVoiceConfig().then(ae=>{if(!pe){if(ae.error||!ae.config){_({kind:"error",message:ae.error??"读取语音设置失败"});return}n(ae.config),i(String(ae.config.turnIdleSeconds)),u(""),f(!1),y(!0),_({kind:"idle"})}}).catch(ae=>{pe||_({kind:"error",message:ae instanceof Error?ae.message:"读取语音设置失败"})}),()=>{pe=!0}},[]),b.useEffect(()=>{const ee=Ut;if(!ee||!p)return;let pe=!1;return ee.requestVoiceCapabilities({region:t.region}).then(ae=>{if(!pe){if(ae.error||!ae.capabilities){o(eg());return}o(ae.capabilities)}}).catch(()=>{pe||o(eg())}),()=>{pe=!0}},[t.region,p]),b.useEffect(()=>(R.current=!0,()=>{R.current=!1,$(),te()}),[]);const N=b.useMemo(()=>v.kind==="loading"?"读取中...":v.kind==="saving"?"保存中...":v.kind==="testing"?"正在测试语音合成":v.kind==="playingTest"?"正在播放测试音频":v.kind==="testPassed"?"测试通过":v.kind==="saved"?"已保存":v.kind==="error"?v.message:null,[v]),A=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",O=b.useMemo(()=>$S(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),K=O.some(ee=>ee.value===t.ttsVoice)?t.ttsVoice:"",U=O.length===0?"当前模型暂无可用音色":K?null:"请选择可用音色",X=b.useMemo(()=>Cae(r),[r]),z=X?null:"请输入正整数秒数",M=U??z,F=A||!!M,B=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>f2(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),I=b.useMemo(()=>kae(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),W=b.useMemo(()=>f2(O,K),[O,K]);function j(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:X??zw.turnIdleSeconds}}async function L(){if(A)return;if(M){_({kind:"error",message:M});return}const ee=Ut;if(!ee){_({kind:"error",message:"请先连接 Relay 服务器"});return}const pe=j();te(),_({kind:"saving"});const ae=performance.now();try{const me=await ee.updateVoiceConfig(pe);if(!R.current)return;const Ee=performance.now()-ae;if(Ee<a2&&await Eae(a2-Ee),!R.current)return;if(!me.success||me.error||!me.config){_({kind:"error",message:me.error??"保存语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,_(De=>De.kind==="saved"?{kind:"idle"}:De)},_ae),ee.requestVoiceCapabilities({region:me.config.region}).then(De=>{R.current&&De.capabilities&&o(De.capabilities)}).catch(()=>{R.current&&o(eg())})}catch(me){if(!R.current)return;_({kind:"error",message:me instanceof Error?me.message:"保存语音设置失败"})}}async function Y(){if(A)return;if(M){_({kind:"error",message:M});return}const ee=Ut;if(!ee){_({kind:"error",message:"请先连接 Relay 服务器"});return}let pe;try{pe=V()}catch(ae){_({kind:"error",message:d2(ae)});return}_({kind:"testing"});try{const[ae]=await Promise.all([ee.testVoiceConfig(j()),pe.ready]);if(!ae.success||ae.error){$(),_({kind:"error",message:ae.error??"语音配置测试失败"});return}const me=await re(ae,pe.context);_({kind:"playingTest",transcript:ae.transcript}),k.current=setTimeout(()=>{k.current=null,$(),_({kind:"testPassed",transcript:ae.transcript})},me)}catch(ae){$(),_({kind:"error",message:d2(ae)})}}function V(){$();const ee=BE.acquire("playback");S.current=ee;try{const pe=xae();return w.current=pe,{context:pe,ready:u2(pe)}}catch(pe){throw ee.release(),S.current=null,pe}}function $(){var ee,pe,ae;k.current&&(clearTimeout(k.current),k.current=null),(ee=x.current)==null||ee.stop(),x.current=null,(pe=w.current)==null||pe.close(),w.current=null,(ae=S.current)==null||ae.release(),S.current=null}function te(){T.current&&(clearTimeout(T.current),T.current=null)}async function re(ee,pe){if(!ee.audioBase64)throw new Error("语音测试未返回可播放音频");if(ee.audioEncoding&&ee.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ae=ee.audioSampleRate??24e3,me=Sae(ee.audioBase64);if(me.byteLength===0||me.byteLength%2!==0)throw new Error("测试音频数据无效");await u2(pe);const Ee=new y5(pe,ae);x.current=Ee,Ee.enqueue(me);const De=Math.ceil(me.byteLength/2/ae*1e3);return Math.max(bae,De)}function oe(ee){var pe;return((pe=$S(s.ttsVoices,ee)[0])==null?void 0:pe.value)??""}return m.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:ee=>{ee.preventDefault(),L()},children:[m.jsx("div",{className:"flex min-h-0 flex-1 flex-col px-4 py-3 sm:px-5 sm:py-3.5","data-slot":"voice-settings-body-frame",children:m.jsx("div",{className:"dev-render-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"voice-settings-scroll",ref:e,children:m.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[m.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsxs("div",{className:"min-w-0",children:[m.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),m.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),m.jsx("span",{className:"shrink-0 rounded-full border border-primary/35 bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:"Bailian"})]})}),m.jsx(l2,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:m.jsxs("div",{className:"flex min-w-0 gap-2",children:[m.jsxs("div",{className:"relative min-w-0 flex-1",children:[m.jsx(JD,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),m.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:ee=>{u(ee.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${o2} w-full pl-9`})]}),t.configured&&m.jsxs(Ct,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),f(!0)},children:[m.jsx(O1,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(pg,{label:"地域",value:t.region,options:B,onChange:ee=>n(pe=>({...pe,region:ee==="intl"?"intl":"cn"}))}),m.jsx(pg,{label:"语音识别模型",value:t.asrModel,options:P,onChange:ee=>n(pe=>({...pe,asrModel:ee}))}),m.jsx(pg,{label:"语音合成模型",value:t.ttsModel,options:I,onChange:ee=>n(pe=>({...pe,ttsModel:ee,ttsVoice:oe(ee)}))}),m.jsx(pg,{label:"语音音色",value:K,options:W,placeholder:O.length===0?"暂无可用音色":"请选择音色",onChange:ee=>n(pe=>({...pe,ttsVoice:ee})),help:U}),m.jsx(l2,{label:"结束停顿时间(秒)",help:z,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:ee=>i(ee.target.value),className:`${o2} w-full`})})]})})}),m.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[m.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),m.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[N?m.jsx("div",{role:v.kind==="error"?"alert":"status","aria-live":"polite",className:v.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:N}):null,m.jsxs(Ct,{type:"button",variant:"outline",disabled:F,onClick:()=>void Y(),children:[m.jsx(nI,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(Ct,{type:"submit",disabled:F,children:[m.jsx(I7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Sae(e){const t=window.atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n}function xae(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function u2(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function d2(e){return e instanceof Error?e.message:"语音配置测试失败"}function Eae(e){return new Promise(t=>setTimeout(t,e))}function Cae(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function f2(e,t){const n=e.map(r=>({value:r.value,label:_5(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function kae(e,t,n){const r=e.map(i=>{const s=$S(t,i.value).length===0;return{value:i.value,label:`${_5(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function b5(e){const t=e.split(" · ").map(n=>n.trim()).filter(Boolean);return t.length<=1?{title:e,detail:null}:{title:t[0],detail:t.slice(1).join(" · ")}}function _5(e){if(!e.age)return e.label;const t=`年龄 ${e.age}`;if(e.label.includes(t))return e.label;const n=` · ${e.age}`;return e.label.endsWith(n)?`${e.label.slice(0,-n.length)} · ${t}`:`${e.label} · ${t}`}const Tae=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Rae=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],zE="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function w5(e){if(!Number.isFinite(e)||e<0)return"未知";if(e<60)return`${Math.floor(e)} 秒`;const t=Math.floor(e/60);if(t<60)return`${t} 分钟`;const n=Math.floor(t/60),r=t%60;if(n<24)return r>0?`${n} 小时 ${r} 分钟`:`${n} 小时`;const i=Math.floor(n/24),s=n%24;return s>0?`${i} 天 ${s} 小时`:`${i} 天`}function Aae(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Mae(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Nae(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function FS({open:e,onOpenChange:t}){const n=Le(K=>K.relayUrl),r=Le(K=>K.latencyMonitorEnabled),i=Le(K=>K.setLatencyMonitorEnabled),s=Le(K=>K.sessionIdleNotificationsEnabled),o=Le(K=>K.setSessionIdleNotificationsEnabled),l=Le(K=>K.inputModePreference),u=Le(K=>K.setInputModePreference),d=Le(K=>K.themePreference),f=Le(K=>K.setThemePreference),p=Le(K=>K.ptyScrollTraceEnabled),y=Le(K=>K.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,S]=b.useState({kind:"idle"}),x=b.useRef(null),k=b.useRef(null),T=yee(),R=b.useMemo(()=>cp().osName==="iPad",[]),N=b.useCallback(async K=>{if(!K){o(!1);return}const U=await VJ();if(U==="granted"){o(!0);return}if(U==="denied"){Xe.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){Xe.info("未授予通知权限,会话通知保持关闭");return}Xe.error("当前浏览器不支持系统通知")},[o]),A=b.useCallback(async K=>{S({kind:"loading"});try{const U=await fetch(Aae(n),{cache:"no-store",signal:K});if(!U.ok)throw new Error(`HTTP ${U.status}`);const X=await U.json();if(X.status!=="ok")throw new Error("状态异常");S({kind:"ready",version:X.version??"未知",uptime:X.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;S({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const K=new AbortController;return A(K.signal),()=>K.abort()},[A,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const K=window.requestAnimationFrame(()=>{var U;(U=x.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(K)},[e,v]);const O=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",D=w.kind==="ready"?`运行 ${w5(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return m.jsx(xa,{open:e,onOpenChange:t,children:m.jsxs(Ea,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",v==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",v==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":v,focusSurfaceOnOpen:!0,ref:x,showCloseButton:v==="menu",children:[m.jsx(Ca,{className:Ye(v==="menu"&&"pr-12 text-left",v!=="menu"&&"text-left",v==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:v!=="menu"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(Ct,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>_("menu"),children:m.jsx(Gv,{className:"size-4","aria-hidden":"true"})}),m.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[m.jsx(Io,{children:Mae(v)}),m.jsx(_a,{className:"max-w-[28rem] leading-5",children:Nae(v)})]})]}),v==="voice"?m.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):m.jsxs(m.Fragment,{children:[m.jsx(Io,{children:"设置"}),m.jsx(_a,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?m.jsx(Pae,{relayVersion:O,relayDetail:D,relayMuted:w.kind==="error"}):v==="relay-token"?m.jsx(Lae,{saved:T}):v==="clients"?m.jsx(jae,{}):v==="voice"?m.jsx(wae,{scrollRef:k}):m.jsx(Oae,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:R,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:N,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function Pae({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:zE,"data-slot":"settings-dialog-body",children:[m.jsx(p2,{icon:m.jsx(tI,{className:"size-4","aria-hidden":"true"}),label:"Web",value:fae.version,detail:"当前浏览器加载的版本"}),m.jsx(p2,{icon:m.jsx(rI,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Oae({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:f,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:v,onOpenClients:_,onOpenVersion:w}){return m.jsxs("div",{className:"dev-render-scroll min-h-0 space-y-4 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"settings-dialog-body",children:[m.jsxs(Mu,{title:"服务",children:[m.jsx(mg,{icon:m.jsx(_W,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),m.jsx(mg,{icon:m.jsx(JD,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),m.jsx(mg,{icon:m.jsx(tq,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(Mu,{title:"外观",children:m.jsx(h2,{icon:m.jsx(Y7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Tae,onValueChange:n})}),m.jsx(Mu,{title:"通知",children:m.jsx($w,{icon:m.jsx(SW,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(Mu,{title:"交互",children:m.jsx(h2,{icon:m.jsx(eI,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Rae,onValueChange:i})}):null,m.jsxs(Mu,{title:"高级诊断",children:[m.jsx($w,{icon:m.jsx(Dh,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx($w,{icon:m.jsx(VD,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:p})]}),m.jsx(Mu,{title:"关于",children:m.jsx(mg,{icon:m.jsx(rI,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function Mu({title:e,children:t}){return m.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[m.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),m.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function h2({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return m.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,m.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return m.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Lae({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{CB().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!xB(f)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),Xe.error(p);return}o(null),Xe.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{EB(),l()};return m.jsxs("form",{className:zE,"data-slot":"settings-dialog-body",onSubmit:f=>{f.preventDefault(),u()},children:[m.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[m.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),m.jsx("input",{id:t,type:"password",value:r,onChange:f=>{i(f.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?m.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),m.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?m.jsx(Ct,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(Ct,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Dae(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Iae(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Dae(e)}function Bae(e){return aQ(e)}function zae(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return w5(t)}function jw({label:e,value:t,title:n}){return m.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[m.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),m.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function jae(){const e=Le(y=>y.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),f=b.useCallback(async()=>{const y=Ut;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(v){o(v instanceof Error?v.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{f()},[f]);const p=b.useCallback(async y=>{const v=Ut;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:zE,"data-slot":"settings-dialog-body",children:[m.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(N1,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?m.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?m.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const v=y.current===!0,_=l===y.clientId;return m.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children:m.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[m.jsxs("div",{className:"min-w-0 space-y-1.5",children:[m.jsx("div",{className:"min-w-0",children:m.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Bae(y)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(jw,{label:"已连接",value:zae(y.connectedAt)}),y.proxyId?m.jsx(jw,{label:"连接到",value:Iae(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?m.jsx(jw,{label:"来源 IP",value:y.remoteAddress}):null]})]}),v?m.jsx("div",{className:"inline-flex h-9 w-full items-center justify-center rounded-md border border-primary/30 bg-primary/10 px-3 text-sm font-normal text-primary","aria-label":"当前设备","data-slot":"relay-client-current-indicator",children:"当前设备"}):m.jsxs(Ct,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[m.jsx(f7,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function $w({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return m.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[m.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),m.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),m.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function mg({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return m.jsxs("button",{type:"button",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:r,"aria-labelledby":i,"aria-describedby":n?s:void 0,"data-slot":"settings-menu-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground transition-colors group-hover:text-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),m.jsx(_h,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function p2({icon:e,label:t,value:n,detail:r,muted:i=!1}){return m.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[m.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[m.jsx("div",{className:"text-sm text-muted-foreground",children:t}),m.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const $ae="xterm-helper-textarea";function Fae(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains($ae)?!1:(e.blur(),!0)}function m2(e,t,n){if(!e||Math.abs(n)<1)return!1;let r=e instanceof Element?e:null;for(;r&&t.contains(r);){if(r instanceof HTMLElement&&Hae(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Hae(e,t){if(e.scrollHeight<=e.clientHeight+1)return!1;const n=window.getComputedStyle(e).overflowY;return n!=="auto"&&n!=="scroll"&&n!=="overlay"?!1:t<0?e.scrollTop>0:e.scrollTop+e.clientHeight<e.scrollHeight-1}function Uae({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Fae()},[e]),i=b.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=b.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const f=(n.current??u.clientY)-u.clientY;n.current=u.clientY,m2(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(m2(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Wae({className:e}){const t=Le(o=>o.sidebarCollapsed),n=Le(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=Uae();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(v2,{collapsed:!0,onClick:n}),m.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),m.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[m.jsx(g2,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(n2,{compact:!0})]})]}),m.jsx(FS,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[m.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:m.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx(SI,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(v2,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(s5,{layout:"dropdown",variant:"sidebarChrome"})})]})}),m.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:m.jsx("div",{className:"flex-1 min-h-0",children:m.jsx(m5,{layout:"sidebar"})})}),m.jsxs("div",{className:"dev-sidebar-fade flex shrink-0 gap-2 px-2 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-2","data-slot":"sidebar-new-session",children:[m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(n2,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(g2,{onClick:()=>i(!0)})})]})]}),m.jsx(FS,{open:r,onOpenChange:i})]})}function g2({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(bp,{delayDuration:500,children:[m.jsx(_p,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(iI,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(wp,{side:t,sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:"设置"})]})}function v2({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?S7:_7;return m.jsxs(bp,{delayDuration:500,children:[m.jsx(_p,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(wp,{side:e?"right":"top",sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:n})]})}const qae=1500,Yae=300,y2=70,b2=35;function S5({texts:e,className:t}){const[n,r]=b.useState(""),[i,s]=b.useState(!0),o=b.useRef("typing"),l=b.useRef(0),u=b.useRef(0);b.useEffect(()=>{const f=setInterval(()=>s(p=>!p),530);return()=>clearInterval(f)},[]),b.useEffect(()=>{let f;const p=()=>e[u.current%e.length],y=()=>{const v=o.current;if(v==="typing"){const _=p();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(y,y2)):(o.current="paused",f=setTimeout(y,qae))}else v==="paused"?(o.current="deleting",f=setTimeout(y,b2)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),f=setTimeout(y,b2)):(u.current+=1,o.current="waiting",f=setTimeout(y,Yae)):(o.current="typing",f=setTimeout(y,y2))};return f=setTimeout(y,500),()=>clearTimeout(f)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return m.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[m.jsx("span",{className:"text-green-500",children:"> "}),m.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),m.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),m.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const x5=["DEV Anywhere","/unlimited @anytime"];function Vae({subtitle:e,action:t}){return m.jsx("section",{className:"dev-mobile-brand-hero border-b border-border/80 px-4 pb-5 pt-[calc(env(safe-area-inset-top)+1.25rem)] md:hidden","data-slot":"mobile-brand-hero","aria-label":"DEV Anywhere",children:m.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[m.jsx(S5,{texts:x5,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),m.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?m.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Kae=3e3,Xae=1e4,gg=12,Gae=4,_2={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Zae={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function Fw(e){if(!e.success||e.rttMs===void 0)return{state:"unavailable",error:e.error??"不可用",updatedAt:Date.now()};const t=e.rttMs;return{state:t<=120?"ok":t<=300?"warn":"bad",rttMs:t,updatedAt:Date.now()}}function Nu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function uh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function w2(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function E5(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Qae(e){switch(e){case"ok":return"border-emerald-500/35 bg-emerald-500/10 text-emerald-300";case"warn":return"border-amber-500/40 bg-amber-500/10 text-amber-300";case"bad":return"border-destructive/55 bg-destructive/10 text-destructive";default:return"border-border bg-card/90 text-muted-foreground"}}function Jae(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?uh(e.rttMs):"等待检测"}function ele(){const e=ki("local",vn.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function S2(e){Cr("local",vn.latencyMonitorPosition,JSON.stringify(e))}function tle(){var e,t;return{width:((e=window.visualViewport)==null?void 0:e.width)??window.innerWidth??document.documentElement.clientWidth??0,height:((t=window.visualViewport)==null?void 0:t.height)??window.innerHeight??document.documentElement.clientHeight??0}}function Hw(e,t){const n=tle(),r=gg,i=gg,s=Math.max(r,n.width-t.width-gg),o=Math.max(i,n.height-t.height-gg);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function nle(){const e=Le(A=>A.latencyMonitorEnabled),t=Le(A=>A.connected),n=Le(A=>A.proxyOnline),r=Le(A=>A.selectedProxyId),[i,s]=b.useState(Zae),[o,l]=b.useState(()=>ele()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((A,O)=>w2(O.state)-w2(A.state))[0]??{state:"idle"}).state,[i]),v=E5(y);async function _(){if(u.current)return;const A=Ut;if(!A||!t){const U=Nu("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:Nu("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:Nu("未连接开发机")}));const[O,D,K]=await Promise.allSettled([A.measureWebRelayLatency(),n?A.measureRelayProxyLatency():Promise.resolve({success:!1}),n?A.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:O.status==="fulfilled"?Fw(O.value):Nu(O.reason instanceof Error?O.reason.message:"测速失败"),relayProxy:D.status==="fulfilled"?Fw(D.value):Nu(D.reason instanceof Error?D.reason.message:"测速失败"),webProxy:K.status==="fulfilled"?Fw(K.value):Nu(K.reason instanceof Error?K.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let A=!1,O=null;const D=async()=>{await _(),!A&&(O=setTimeout(D,document.hidden?Xae:Kae))};return D(),()=>{A=!0,u.current=!1,O&&clearTimeout(O)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const A=d.current;if(!A)return;const O=A.getBoundingClientRect(),D=Hw(o,{width:O.width,height:O.height});D.x===o.x&&D.y===o.y||(l(D),S2(D))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,S=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(A){var D,K;if(A.button!==0)return;const O=A.currentTarget.getBoundingClientRect();f.current={pointerId:A.pointerId,startX:A.clientX,startY:A.clientY,originX:O.left,originY:O.top,width:O.width,height:O.height,dragging:!1},(K=(D=A.currentTarget).setPointerCapture)==null||K.call(D,A.pointerId)}function k(A){const O=f.current;if(!O||O.pointerId!==A.pointerId)return;const D=A.clientX-O.startX,K=A.clientY-O.startY;if(!O.dragging&&Math.hypot(D,K)<Gae)return;O.dragging=!0,A.preventDefault();const U=Hw({x:O.originX+D,y:O.originY+K},{width:O.width,height:O.height});l(U)}function T(A){var X,z;const O=f.current;if(!O||O.pointerId!==A.pointerId||(f.current=null,(z=(X=A.currentTarget).releasePointerCapture)==null||z.call(X,A.pointerId),!O.dragging))return;A.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const D=A.clientX-O.startX,K=A.clientY-O.startY,U=Hw({x:O.originX+D,y:O.originY+K},{width:O.width,height:O.height});l(U),S2(U)}function R(A){var D,K;const O=f.current;!O||O.pointerId!==A.pointerId||(f.current=null,(K=(D=A.currentTarget).releasePointerCapture)==null||K.call(D,A.pointerId))}function N(A){p.current&&(p.current=!1,A.preventDefault(),A.stopPropagation())}return m.jsxs(PE,{children:[m.jsx(OE,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Qae(v)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${uh(i.webRelay.rttMs)},开发机 ${uh(w.rttMs)}`,onPointerDown:x,onPointerMove:k,onPointerUp:T,onPointerCancel:R,onClickCapture:N,children:[m.jsx(VD,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),m.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",uh(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",uh(w.rttMs)]}),m.jsx(Ol,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(LE,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[m.jsxs("div",{className:"flex items-start justify-between gap-3",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(N1,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(_2).map(A=>m.jsx(rle,{label:_2[A],measurement:i[A]},A))})]})]})}function rle({label:e,measurement:t}){const n=E5(t.state);return m.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[m.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Jae(t)})]})]})}const C5="/__dev_anywhere_debug/browser-state-dumps",ile=1500,sle=10,Uw=80,jE=500,ole=["id","class","data-slot","data-state","data-testid","role","aria-label","aria-hidden","name","type","autocomplete","autocorrect","autocapitalize","inputmode","enterkeyhint","virtualkeyboardpolicy","contenteditable","placeholder","href","src"],ale=["display","position","visibility","opacity","pointer-events","z-index","overflow","overflow-x","overflow-y","touch-action","transform","translate","color-scheme","background-color","color","font-size","line-height","padding-top","padding-right","padding-bottom","padding-left","margin-top","margin-right","margin-bottom","margin-left"];function x2(){if(typeof window>"u")return"off";const e=O5("debugDump");return e==="auto"?"auto":e!==null||gle("debugInput")?"manual":"off"}function lle(e="manual"){const t={count:0,truncated:!1},n=window,r={schemaVersion:1,createdAt:new Date().toISOString(),trigger:e,url:{href:window.location.href,origin:window.location.origin,pathname:window.location.pathname,search:window.location.search,hash:window.location.hash},browser:{userAgent:navigator.userAgent,language:navigator.language,languages:Array.from(navigator.languages??[]),platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints??0,cookieEnabled:navigator.cookieEnabled,onLine:navigator.onLine},viewport:fle(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:E2(document.activeElement),selection:hle(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>E2(i)).filter(i=>!!i),root:k5(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:Pu(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:Pu(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:Pu(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:Pu(()=>C2(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:Pu(()=>C2(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:Pu(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function cle(e="manual"){const t=lle(e);return ule(t)}async function ule(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await dle(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:C5}}catch(r){const i=L5(r),s=ple(e.createdAt);return mle(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function dle(e){const t=await fetch(C5,{method:"POST",headers:{"content-type":"application/json"},body:e});if(!t.ok)throw new Error(`${t.status} ${await t.text()}`);const n=await t.json();if(!n.ok||!n.path||typeof n.bytes!="number")throw new Error("debug endpoint returned an invalid response");return{path:n.path,bytes:n.bytes}}function k5(e,t,n){if(n.count>=ile||t>sle)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=k2(e.textContent??"");return u?{kind:"text",text:Ny(u,jE)}:{kind:"text",text:""}}if(!(e instanceof HTMLElement))return{kind:"truncated"};const r=[];let i=0;const s=Array.from(e.childNodes);for(const u of s.slice(0,Uw))u.nodeType===Node.TEXT_NODE&&!k2(u.textContent??"")||r.push(k5(u,t+1,n));s.length>Uw&&(i=s.length-Uw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:P5(e),attrs:T5(e),rect:R5(e),scroll:A5(e),style:M5(e)},l=N5(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function E2(e){if(!(e instanceof HTMLElement))return null;const t=N5(e);return{path:P5(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:T5(e),rect:R5(e),scroll:A5(e),style:M5(e),...t?{value:t}:{}}}function fle(){var n;const e=window.visualViewport,t=((n=screen.orientation)==null?void 0:n.type)??null;return{window:{innerWidth:window.innerWidth,innerHeight:window.innerHeight,outerWidth:window.outerWidth,outerHeight:window.outerHeight,devicePixelRatio:window.devicePixelRatio,scrollX:window.scrollX,scrollY:window.scrollY},visualViewport:e?{width:e.width,height:e.height,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,pageLeft:e.pageLeft,pageTop:e.pageTop,scale:e.scale}:null,screen:{width:screen.width,height:screen.height,availWidth:screen.availWidth,availHeight:screen.availHeight,orientation:t}}}function T5(e){const t={};for(const n of ole){const r=e.getAttribute(n);r!==null&&(t[n]=Ny(r,500))}return t}function R5(e){const t=e.getBoundingClientRect();return{x:ns(t.x),y:ns(t.y),width:ns(t.width),height:ns(t.height),top:ns(t.top),right:ns(t.right),bottom:ns(t.bottom),left:ns(t.left)}}function A5(e){return{top:ns(e.scrollTop),left:ns(e.scrollLeft),height:ns(e.scrollHeight),width:ns(e.scrollWidth),clientHeight:ns(e.clientHeight),clientWidth:ns(e.clientWidth)}}function M5(e){const t=window.getComputedStyle(e),n={};for(const r of ale)n[r]=t.getPropertyValue(r);return n}function N5(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Ny(e.value,jE),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function hle(){var e;try{return Ny(((e=window.getSelection())==null?void 0:e.toString())??"",jE)}catch{return null}}function P5(e){const t=[];let n=e;for(;n&&n!==document.documentElement;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}const i=n.getAttribute("data-slot");i?r+=`[data-slot="${i}"]`:n.classList.length>0&&(r+=`.${Array.from(n.classList).slice(0,3).join(".")}`);const s=n.parentElement;if(s){const o=n.tagName,l=Array.from(s.children).filter(u=>u instanceof HTMLElement&&u.tagName===o);l.length>1&&(r+=`:nth-of-type(${l.indexOf(n)+1})`)}t.unshift(r),n=s}return`html>${t.join(">")}`}function ple(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function mle(e,t,n){if(typeof document>"u")return!1;const r=new Blob([t],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");return s.href=i,s.download=e,s.rel="noopener",document.body.append(s),s.click(),s.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3),!0}function gle(e){return O5(e)!==null}function O5(e){const t=new URLSearchParams(window.location.search);if(t.has(e))return t.get(e)??"";const[,n=""]=window.location.hash.split("?"),r=new URLSearchParams(n);return r.has(e)?r.get(e)??"":null}function C2(e){return e?Mv(e.slice(-200)):null}function Pu(e){try{return Mv(e())}catch(t){return{error:L5(t)}}}function Mv(e){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(Array.isArray(e))return e.map(Mv);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Mv(r);return t}return String(e)}function k2(e){return e.replace(/\s+/g," ").trim()}function Ny(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function ns(e){return Math.round(e*100)/100}function L5(e){return e instanceof Error?e.message:String(e)}const vle=500,yle=1e3,ble=60;function _le(){const[e,t]=b.useState(()=>x2()),[n,r]=b.useState(!1),[i,s]=b.useState(null),o=b.useRef(null),l=b.useRef(!1),u=b.useRef(0),d=b.useRef(0),f=b.useRef(null);b.useEffect(()=>{const _=()=>t(x2());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const p=b.useCallback(async(_="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await cle(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&wle(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),b.useEffect(()=>{var k,T;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=R=>{d.current>=ble||(_(),f.current=window.setTimeout(()=>{f.current=null;const N=Date.now(),A=yle-(N-u.current);if(A>0){f.current=window.setTimeout(()=>w(R),A);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${R}`)},vle))};w("initial");const S=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=R=>w(R.type);return S.forEach(R=>window.addEventListener(R,x,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",x),(T=window.visualViewport)==null||T.addEventListener("scroll",x),()=>{var R,N;_(),S.forEach(A=>window.removeEventListener(A,x,!0)),(R=window.visualViewport)==null||R.removeEventListener("resize",x),(N=window.visualViewport)==null||N.removeEventListener("scroll",x)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=Sle(i);return m.jsxs("div",{className:"fixed bottom-3 right-3 z-[90] flex max-w-[min(360px,calc(100vw-24px))] flex-col items-end gap-1",children:[v?m.jsx("div",{className:"max-w-full truncate rounded-md border border-border/70 bg-popover/95 px-2 py-1 text-[10px] text-muted-foreground shadow",children:v}):null,m.jsxs(Ct,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void p("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?m.jsx(Mo,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(QW,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:y})]})]})}function wle(e){if(e.status==="saved"){Xe.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){Xe.info(`诊断已下载: ${e.filename}`);return}Xe.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Sle(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function xle(e){if(typeof window>"u")return null;try{const t=window.localStorage;return!t||typeof t.getItem!="function"?null:t.getItem(e)}catch{return null}}function $E(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:xle(n)==="1",l=()=>typeof window>"u"?[]:window[t]??[],u=d=>{typeof window>"u"||(window[t]=d)};return{isEnabled:o,append(d){if(typeof window>"u")return;const f=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&f.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const v=f.indexOf(y);v>=0&&v!==f.length-1&&(f.splice(v,1),f.push(y)),u(f);return}}}if(f.push(d),i&&s.set(d.event,d),f.length>r){const p=f.splice(0,f.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(f)},getAll:l}}function Bn(e){return Math.round(e*10)/10}function dl(e){return e.length===0?"":`${Bn(Math.min(...e))}..${Bn(Math.max(...e))}`}function td(e){return[...new Set(e.filter(t=>t!==void 0).map(Bn))]}function D5(e){let t=0,n=0;for(let r=1;r<e.length;r+=1){const i=e[r]-e[r-1];if(Math.abs(i)<1)continue;const s=Math.sign(i);t!==0&&s!==t&&(n+=1),t=s}return n}const Ele="dev_anywhere_pty_input_latency_trace",T2=80,Cle=1e4,kle=new TextDecoder;let Tle=0;const Sd=new Map,qc=$E({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Ele,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Rle(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Ple)}function Ale(e,t){if(!qc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Tle}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Dle(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Sd.get(e)??[];return s.push(i),HE(s,r),Sd.set(e,s),Sp({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function R2(e,t){if(!e||!qc.isEnabled())return;const n=performance.now(),r=Ole(e.sessionId,e.inputId);r&&(r.sentAt=n),Sp({t:n,event:"input:ws-send",sessionId:e.sessionId,inputId:e.inputId,inputKind:r==null?void 0:r.kind,dataLength:r==null?void 0:r.dataLength,sent:t.sent,queueWhenDisconnected:t.queueWhenDisconnected,deltaFromInputMs:r?n-r.startedAt:null,details:t.details})}function Mle(e,t,n){if(!qc.isEnabled())return;const r=performance.now(),i=FE(e,r),s=zle(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Ble(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Sp({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:UE(i,r),details:jle([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Nle(e,t,n=1){if(!qc.isEnabled())return;const r=performance.now(),i=FE(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Sp({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:UE(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Lle(e,s))}function Ple(){const e=qc.getAll(),t=e.slice(-200),n=[...Sd.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Bn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Bn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Bn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Bn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Bn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Bn(s.t),s.repeat&&s.repeat>0?`${s.event} +${s.repeat}`:s.event,s.sessionId,s.inputId??"",s.inputKind??"",s.dataLength??"",s.sent===void 0?"":s.sent?"sent":"not-sent",s.queueWhenDisconnected?"queue-ok":"",s.outputSeq??"",s.bytes??"",s.chunkCount??"",s.pendingInputs??"",s.deltaFromInputMs===void 0||s.deltaFromInputMs===null?"":Bn(s.deltaFromInputMs),s.details??""].join(" "));return["DEV Anywhere PTY input latency trace",`events=${e.length}, included=${t.length}, pendingInputs=${n.length}`,"pending input summary:","inputId sessionId kind len wsSendMs firstOutputMs echoMatchMs xtermWriteMs paintMs",...r,"events:","t event sessionId inputId kind len sent queue outputSeq bytes chunks pending deltaMs details",...i].join(`
534
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Zte="DialogDescriptionWarning",Qte=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${rz(Zte).contentName}}.`;return b.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},cE=UB,Jte=qB,uE=VB,dE=KB,fE=XB,iz=ZB,sz=JB,ay=tz;function ene(e){const t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function tne(e){const[t,n]=b.useState(void 0);return Di(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const u=s.borderBoxSize,d=Array.isArray(u)?u[0]:u;o=d.inlineSize,l=d.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const nne=["top","right","bottom","left"],kl=Math.min,vs=Math.max,xv=Math.round,ug=Math.floor,No=e=>({x:e,y:e}),rne={left:"right",right:"left",bottom:"top",top:"bottom"};function xS(e,t,n){return vs(e,kl(t,n))}function ya(e,t){return typeof e=="function"?e(t):e}function ba(e){return e.split("-")[0]}function Pd(e){return e.split("-")[1]}function hE(e){return e==="x"?"y":"x"}function pE(e){return e==="y"?"height":"width"}function Ro(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function mE(e){return hE(Ro(e))}function ine(e,t,n){n===void 0&&(n=!1);const r=Pd(e),i=mE(e),s=pE(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Ev(o)),[o,Ev(o)]}function sne(e){const t=Ev(e);return[ES(e),t,ES(t)]}function ES(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const LN=["left","right"],DN=["right","left"],one=["top","bottom"],ane=["bottom","top"];function lne(e,t,n){switch(e){case"top":case"bottom":return n?t?DN:LN:t?LN:DN;case"left":case"right":return t?one:ane;default:return[]}}function cne(e,t,n,r){const i=Pd(e);let s=lne(ba(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(ES)))),s}function Ev(e){const t=ba(e);return rne[t]+e.slice(t.length)}function une(e){return{top:0,right:0,bottom:0,left:0,...e}}function oz(e){return typeof e!="number"?une(e):{top:e,right:e,bottom:e,left:e}}function Cv(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function IN(e,t,n){let{reference:r,floating:i}=e;const s=Ro(t),o=mE(t),l=pE(o),u=ba(t),d=s==="y",f=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let v;switch(u){case"top":v={x:f,y:r.y-i.height};break;case"bottom":v={x:f,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:p};break;case"left":v={x:r.x-i.width,y:p};break;default:v={x:r.x,y:r.y}}switch(Pd(t)){case"start":v[o]-=y*(n&&d?-1:1);break;case"end":v[o]+=y*(n&&d?-1:1);break}return v}async function dne(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:f="viewport",elementContext:p="floating",altBoundary:y=!1,padding:v=0}=ya(t,e),_=oz(v),S=l[y?p==="floating"?"reference":"floating":p],x=Cv(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(S)))==null||n?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:f,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),R=await(s.isElement==null?void 0:s.isElement(T))?await(s.getScale==null?void 0:s.getScale(T))||{x:1,y:1}:{x:1,y:1},N=Cv(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:T,strategy:u}):k);return{top:(x.top-N.top+_.top)/R.y,bottom:(N.bottom-x.bottom+_.bottom)/R.y,left:(x.left-N.left+_.left)/R.x,right:(N.right-x.right+_.right)/R.x}}const fne=50,hne=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:dne},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:f,y:p}=IN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const S=s[w];if(!S)continue;const{name:x,fn:k}=S,{x:T,y:R,data:N,reset:A}=await k({x:f,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=T??f,p=R??p,_[x]={..._[x],...N},A&&v<fne&&(v++,typeof A=="object"&&(A.placement&&(y=A.placement),A.rects&&(d=A.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):A.rects),{x:f,y:p}=IN(d,y,u)),w=-1)}return{x:f,y:p,placement:y,strategy:i,middlewareData:_}},pne=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:u}=t,{element:d,padding:f=0}=ya(e,t)||{};if(d==null)return{};const p=oz(f),y={x:n,y:r},v=mE(i),_=pE(v),w=await o.getDimensions(d),S=v==="y",x=S?"top":"left",k=S?"bottom":"right",T=S?"clientHeight":"clientWidth",R=s.reference[_]+s.reference[v]-y[v]-s.floating[_],N=y[v]-s.reference[v],A=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let O=A?A[T]:0;(!O||!await(o.isElement==null?void 0:o.isElement(A)))&&(O=l.floating[T]||s.floating[_]);const D=R/2-N/2,K=O/2-w[_]/2-1,U=kl(p[x],K),X=kl(p[k],K),z=U,M=O-w[_]-X,F=O/2-w[_]/2+D,B=xS(z,F,M),P=!u.arrow&&Pd(i)!=null&&F!==B&&s.reference[_]/2-(F<z?U:X)-w[_]/2<0,I=P?F<z?F-z:F-M:0;return{[v]:y[v]+I,data:{[v]:B,centerOffset:F-B-I,...P&&{alignmentOffset:I}},reset:P}}}),mne=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:u,elements:d}=t,{mainAxis:f=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=ya(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=ba(i),k=Ro(l),T=ba(l)===l,R=await(u.isRTL==null?void 0:u.isRTL(d.floating)),N=y||(T||!w?[Ev(l)]:sne(l)),A=_!=="none";!y&&A&&N.push(...cne(l,w,_,R));const O=[l,...N],D=await u.detectOverflow(t,S),K=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&K.push(D[x]),p){const F=ine(i,o,R);K.push(D[F[0]],D[F[1]])}if(U=[...U,{placement:i,overflows:K}],!K.every(F=>F<=0)){var X,z;const F=(((X=s.flip)==null?void 0:X.index)||0)+1,B=O[F];if(B&&(!(p==="alignment"?k!==Ro(B):!1)||U.every(W=>Ro(W.placement)===k?W.overflows[0]>0:!0)))return{data:{index:F,overflows:U},reset:{placement:B}};let P=(z=U.filter(I=>I.overflows[0]<=0).sort((I,W)=>I.overflows[1]-W.overflows[1])[0])==null?void 0:z.placement;if(!P)switch(v){case"bestFit":{var M;const I=(M=U.filter(W=>{if(A){const j=Ro(W.placement);return j===k||j==="y"}return!0}).map(W=>[W.placement,W.overflows.filter(j=>j>0).reduce((j,L)=>j+L,0)]).sort((W,j)=>W[1]-j[1])[0])==null?void 0:M[0];I&&(P=I);break}case"initialPlacement":P=l;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function BN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function zN(e){return nne.some(t=>e[t]>=0)}const gne=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ya(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=BN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:zN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=BN(o,n.floating);return{data:{escapedOffsets:l,escaped:zN(l)}}}default:return{}}}}},az=new Set(["left","top"]);async function vne(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=ba(n),l=Pd(n),u=Ro(n)==="y",d=az.has(o)?-1:1,f=s&&u?-1:1,p=ya(t,e);let{mainAxis:y,crossAxis:v,alignmentAxis:_}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof _=="number"&&(v=l==="end"?_*-1:_),u?{x:v*f,y:y*d}:{x:y*d,y:v*f}}const yne=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:s,placement:o,middlewareData:l}=t,u=await vne(t,e);return o===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:s+u.y,data:{...u,placement:o}}}}},bne=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:x=>{let{x:k,y:T}=x;return{x:k,y:T}}},...d}=ya(e,t),f={x:n,y:r},p=await s.detectOverflow(t,d),y=Ro(ba(i)),v=hE(y);let _=f[v],w=f[y];if(o){const x=v==="y"?"top":"left",k=v==="y"?"bottom":"right",T=_+p[x],R=_-p[k];_=xS(T,_,R)}if(l){const x=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[x],R=w-p[k];w=xS(T,w,R)}const S=u.fn({...t,[v]:_,[y]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[v]:o,[y]:l}}}}}},_ne=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:u=!0,crossAxis:d=!0}=ya(e,t),f={x:n,y:r},p=Ro(i),y=hE(p);let v=f[y],_=f[p];const w=ya(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const T=y==="y"?"height":"width",R=s.reference[y]-s.floating[T]+S.mainAxis,N=s.reference[y]+s.reference[T]-S.mainAxis;v<R?v=R:v>N&&(v=N)}if(d){var x,k;const T=y==="y"?"width":"height",R=az.has(ba(i)),N=s.reference[p]-s.floating[T]+(R&&((x=o.offset)==null?void 0:x[p])||0)+(R?0:S.crossAxis),A=s.reference[p]+s.reference[T]+(R?0:((k=o.offset)==null?void 0:k[p])||0)-(R?S.crossAxis:0);_<N?_=N:_>A&&(_=A)}return{[y]:v,[p]:_}}}},wne=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:u=()=>{},...d}=ya(e,t),f=await o.detectOverflow(t,d),p=ba(i),y=Pd(i),v=Ro(i)==="y",{width:_,height:w}=s.floating;let S,x;p==="top"||p==="bottom"?(S=p,x=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=p,S=y==="end"?"top":"bottom");const k=w-f.top-f.bottom,T=_-f.left-f.right,R=kl(w-f[S],k),N=kl(_-f[x],T),A=!t.middlewareData.shift;let O=R,D=N;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(D=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(O=k),A&&!y){const U=vs(f.left,0),X=vs(f.right,0),z=vs(f.top,0),M=vs(f.bottom,0);v?D=_-2*(U!==0||X!==0?U+X:vs(f.left,f.right)):O=w-2*(z!==0||M!==0?z+M:vs(f.top,f.bottom))}await u({...t,availableWidth:D,availableHeight:O});const K=await o.getDimensions(l.floating);return _!==K.width||w!==K.height?{reset:{rects:!0}}:{}}}};function ly(){return typeof window<"u"}function Od(e){return lz(e)?(e.nodeName||"").toLowerCase():"#document"}function bs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jo(e){var t;return(t=(lz(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function lz(e){return ly()?e instanceof Node||e instanceof bs(e).Node:!1}function ro(e){return ly()?e instanceof Element||e instanceof bs(e).Element:!1}function Sa(e){return ly()?e instanceof HTMLElement||e instanceof bs(e).HTMLElement:!1}function jN(e){return!ly()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof bs(e).ShadowRoot}function fp(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=io(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Sne(e){return/^(table|td|th)$/.test(Od(e))}function cy(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const xne=/transform|translate|scale|rotate|perspective|filter/,Ene=/paint|layout|strict|content/,lc=e=>!!e&&e!=="none";let Nw;function gE(e){const t=ro(e)?io(e):e;return lc(t.transform)||lc(t.translate)||lc(t.scale)||lc(t.rotate)||lc(t.perspective)||!vE()&&(lc(t.backdropFilter)||lc(t.filter))||xne.test(t.willChange||"")||Ene.test(t.contain||"")}function Cne(e){let t=Tl(e);for(;Sa(t)&&!bd(t);){if(gE(t))return t;if(cy(t))return null;t=Tl(t)}return null}function vE(){return Nw==null&&(Nw=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Nw}function bd(e){return/^(html|body|#document)$/.test(Od(e))}function io(e){return bs(e).getComputedStyle(e)}function uy(e){return ro(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Tl(e){if(Od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||jN(e)&&e.host||jo(e);return jN(t)?t.host:t}function cz(e){const t=Tl(e);return bd(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sa(t)&&fp(t)?t:cz(t)}function $h(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=cz(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=bs(i);if(s){const l=CS(o);return t.concat(o,o.visualViewport||[],fp(i)?i:[],l&&n?$h(l):[])}else return t.concat(i,$h(i,[],n))}function CS(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function uz(e){const t=io(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Sa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=xv(n)!==s||xv(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function yE(e){return ro(e)?e:e.contextElement}function cd(e){const t=yE(e);if(!Sa(t))return No(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=uz(t);let o=(s?xv(n.width):n.width)/r,l=(s?xv(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const kne=No(0);function dz(e){const t=bs(e);return!vE()||!t.visualViewport?kne:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Tne(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==bs(e)?!1:t}function Ac(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=yE(e);let o=No(1);t&&(r?ro(r)&&(o=cd(r)):o=cd(e));const l=Tne(s,n,r)?dz(s):No(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,f=i.width/o.x,p=i.height/o.y;if(s){const y=bs(s),v=r&&ro(r)?bs(r):r;let _=y,w=CS(_);for(;w&&r&&v!==_;){const S=cd(w),x=w.getBoundingClientRect(),k=io(w),T=x.left+(w.clientLeft+parseFloat(k.paddingLeft))*S.x,R=x.top+(w.clientTop+parseFloat(k.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,p*=S.y,u+=T,d+=R,_=bs(w),w=CS(_)}}return Cv({width:f,height:p,x:u,y:d})}function dy(e,t){const n=uy(e).scrollLeft;return t?t.left+n:Ac(jo(e)).left+n}function fz(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-dy(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Rne(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=jo(r),l=t?cy(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=No(1);const f=No(0),p=Sa(r);if((p||!p&&!s)&&((Od(r)!=="body"||fp(o))&&(u=uy(r)),p)){const v=Ac(r);d=cd(r),f.x=v.x+r.clientLeft,f.y=v.y+r.clientTop}const y=o&&!p&&!s?fz(o,u):No(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+f.x+y.x,y:n.y*d.y-u.scrollTop*d.y+f.y+y.y}}function Ane(e){return Array.from(e.getClientRects())}function Mne(e){const t=jo(e),n=uy(e),r=e.ownerDocument.body,i=vs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=vs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+dy(e);const l=-n.scrollTop;return io(r).direction==="rtl"&&(o+=vs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const $N=25;function Nne(e,t){const n=bs(e),r=jo(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const f=vE();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=dy(r);if(d<=0){const f=r.ownerDocument,p=f.body,y=getComputedStyle(p),v=f.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-v);_<=$N&&(s-=_)}else d<=$N&&(s+=d);return{width:s,height:o,x:l,y:u}}function Pne(e,t){const n=Ac(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Sa(e)?cd(e):No(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function FN(e,t,n){let r;if(t==="viewport")r=Nne(e,n);else if(t==="document")r=Mne(jo(e));else if(ro(t))r=Pne(t,n);else{const i=dz(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Cv(r)}function hz(e,t){const n=Tl(e);return n===t||!ro(n)||bd(n)?!1:io(n).position==="fixed"||hz(n,t)}function One(e,t){const n=t.get(e);if(n)return n;let r=$h(e,[],!1).filter(l=>ro(l)&&Od(l)!=="body"),i=null;const s=io(e).position==="fixed";let o=s?Tl(e):e;for(;ro(o)&&!bd(o);){const l=io(o),u=gE(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||fp(o)&&!u&&hz(e,o))?r=r.filter(f=>f!==o):i=l,o=Tl(o)}return t.set(e,r),r}function Lne(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?cy(t)?[]:One(t,this._c):[].concat(n),r],l=FN(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const v=FN(t,o[y],i);u=vs(v.top,u),d=kl(v.right,d),f=kl(v.bottom,f),p=vs(v.left,p)}return{width:d-p,height:f-u,x:p,y:u}}function Dne(e){const{width:t,height:n}=uz(e);return{width:t,height:n}}function Ine(e,t,n){const r=Sa(t),i=jo(t),s=n==="fixed",o=Ac(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=No(0);function d(){u.x=dy(i)}if(r||!r&&!s)if((Od(t)!=="body"||fp(i))&&(l=uy(t)),r){const v=Ac(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const f=i&&!r&&!s?fz(i,l):No(0),p=o.left+l.scrollLeft-u.x-f.x,y=o.top+l.scrollTop-u.y-f.y;return{x:p,y,width:o.width,height:o.height}}function Pw(e){return io(e).position==="static"}function HN(e,t){if(!Sa(e)||io(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return jo(e)===n&&(n=n.ownerDocument.body),n}function pz(e,t){const n=bs(e);if(cy(e))return n;if(!Sa(e)){let i=Tl(e);for(;i&&!bd(i);){if(ro(i)&&!Pw(i))return i;i=Tl(i)}return n}let r=HN(e,t);for(;r&&Sne(r)&&Pw(r);)r=HN(r,t);return r&&bd(r)&&Pw(r)&&!gE(r)?n:r||Cne(e)||n}const Bne=async function(e){const t=this.getOffsetParent||pz,n=this.getDimensions,r=await n(e.floating);return{reference:Ine(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function zne(e){return io(e).direction==="rtl"}const jne={convertOffsetParentRelativeRectToViewportRelativeRect:Rne,getDocumentElement:jo,getClippingRect:Lne,getOffsetParent:pz,getElementRects:Bne,getClientRects:Ane,getDimensions:Dne,getScale:cd,isElement:ro,isRTL:zne};function mz(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $ne(e,t){let n=null,r;const i=jo(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:f,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const _=ug(p),w=ug(i.clientWidth-(f+y)),S=ug(i.clientHeight-(p+v)),x=ug(f),T={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:vs(0,kl(1,u))||1};let R=!0;function N(A){const O=A[0].intersectionRatio;if(O!==u){if(!R)return o();O?o(!1,O):r=setTimeout(()=>{o(!1,1e-7)},1e3)}O===1&&!mz(d,e.getBoundingClientRect())&&o(),R=!1}try{n=new IntersectionObserver(N,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(N,T)}n.observe(e)}return o(!0),s}function Fne(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=yE(e),f=i||s?[...d?$h(d):[],...t?$h(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const p=d&&l?$ne(d,n):null;let y=-1,v=null;o&&(v=new ResizeObserver(x=>{let[k]=x;k&&k.target===d&&v&&t&&(v.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var T;(T=v)==null||T.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let _,w=u?Ac(e):null;u&&S();function S(){const x=Ac(e);w&&!mz(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(x=v)==null||x.disconnect(),v=null,u&&cancelAnimationFrame(_)}}const Hne=yne,Une=bne,Wne=mne,qne=wne,Yne=gne,UN=pne,Vne=_ne,Kne=(e,t,n)=>{const r=new Map,i={platform:jne,...n},s={...i.platform,_c:r};return hne(e,t,{...i,platform:s})};var Xne=typeof document<"u",Gne=function(){},Xg=Xne?b.useLayoutEffect:Gne;function kv(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!kv(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!kv(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function gz(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function WN(e,t){const n=gz(e);return Math.round(t*n)/n}function Ow(e){const t=b.useRef(e);return Xg(()=>{t.current=e}),t}function Zne(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[f,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=b.useState(r);kv(y,r)||v(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),k=b.useCallback(W=>{W!==A.current&&(A.current=W,w(W))},[]),T=b.useCallback(W=>{W!==O.current&&(O.current=W,x(W))},[]),R=s||_,N=o||S,A=b.useRef(null),O=b.useRef(null),D=b.useRef(f),K=u!=null,U=Ow(u),X=Ow(i),z=Ow(d),M=b.useCallback(()=>{if(!A.current||!O.current)return;const W={placement:t,strategy:n,middleware:y};X.current&&(W.platform=X.current),Kne(A.current,O.current,W).then(j=>{const L={...j,isPositioned:z.current!==!1};F.current&&!kv(D.current,L)&&(D.current=L,Hc.flushSync(()=>{p(L)}))})},[y,t,n,X,z]);Xg(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,p(W=>({...W,isPositioned:!1})))},[d]);const F=b.useRef(!1);Xg(()=>(F.current=!0,()=>{F.current=!1}),[]),Xg(()=>{if(R&&(A.current=R),N&&(O.current=N),R&&N){if(U.current)return U.current(R,N,M);M()}},[R,N,M,U,K]);const B=b.useMemo(()=>({reference:A,floating:O,setReference:k,setFloating:T}),[k,T]),P=b.useMemo(()=>({reference:R,floating:N}),[R,N]),I=b.useMemo(()=>{const W={position:n,left:0,top:0};if(!P.floating)return W;const j=WN(P.floating,f.x),L=WN(P.floating,f.y);return l?{...W,transform:"translate("+j+"px, "+L+"px)",...gz(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:j,top:L}},[n,l,P.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:M,refs:B,elements:P,floatingStyles:I}),[f,M,B,P,I])}const Qne=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?UN({element:r.current,padding:i}).fn(n):{}:r?UN({element:r,padding:i}).fn(n):{}}}},Jne=(e,t)=>{const n=Hne(e);return{name:n.name,fn:n.fn,options:[e,t]}},ere=(e,t)=>{const n=Une(e);return{name:n.name,fn:n.fn,options:[e,t]}},tre=(e,t)=>({fn:Vne(e).fn,options:[e,t]}),nre=(e,t)=>{const n=Wne(e);return{name:n.name,fn:n.fn,options:[e,t]}},rre=(e,t)=>{const n=qne(e);return{name:n.name,fn:n.fn,options:[e,t]}},ire=(e,t)=>{const n=Yne(e);return{name:n.name,fn:n.fn,options:[e,t]}},sre=(e,t)=>{const n=Qne(e);return{name:n.name,fn:n.fn,options:[e,t]}};var ore="Arrow",vz=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(hn.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:m.jsx("polygon",{points:"0,0 30,0 15,10"})})});vz.displayName=ore;var are=vz,bE="Popper",[yz,Bl]=wa(bE),[lre,bz]=yz(bE),_z=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(lre,{scope:t,anchor:r,onAnchorChange:i,children:n})};_z.displayName=bE;var wz="PopperAnchor",Sz=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=bz(wz,n),o=b.useRef(null),l=Kn(t,o),u=b.useRef(null);return b.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:m.jsx(hn.div,{...i,ref:l})});Sz.displayName=wz;var _E="PopperContent",[cre,ure]=yz(_E),xz=b.forwardRef((e,t)=>{var ee,pe,ae,me,Ee,De;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:f=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:v="optimized",onPlaced:_,...w}=e,S=bz(_E,n),[x,k]=b.useState(null),T=Kn(t,Se=>k(Se)),[R,N]=b.useState(null),A=tne(R),O=(A==null?void 0:A.width)??0,D=(A==null?void 0:A.height)??0,K=r+(s!=="center"?"-"+s:""),U=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},X=Array.isArray(d)?d:[d],z=X.length>0,M={padding:U,boundary:X.filter(fre),altBoundary:z},{refs:F,floatingStyles:B,placement:P,isPositioned:I,middlewareData:W}=Zne({strategy:"fixed",placement:K,whileElementsMounted:(...Se)=>Fne(...Se,{animationFrame:v==="always"}),elements:{reference:S.anchor},middleware:[Jne({mainAxis:i+D,alignmentAxis:o}),u&&ere({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?tre():void 0,...M}),u&&nre({...M}),rre({...M,apply:({elements:Se,rects:Je,availableWidth:Ht,availableHeight:ye})=>{const{width:Ze,height:Tt}=Je.reference,gt=Se.floating.style;gt.setProperty("--radix-popper-available-width",`${Ht}px`),gt.setProperty("--radix-popper-available-height",`${ye}px`),gt.setProperty("--radix-popper-anchor-width",`${Ze}px`),gt.setProperty("--radix-popper-anchor-height",`${Tt}px`)}}),R&&sre({element:R,padding:l}),hre({arrowWidth:O,arrowHeight:D}),y&&ire({strategy:"referenceHidden",...M})]}),[j,L]=kz(P),Y=Do(_);Di(()=>{I&&(Y==null||Y())},[I,Y]);const V=(ee=W.arrow)==null?void 0:ee.x,$=(pe=W.arrow)==null?void 0:pe.y,te=((ae=W.arrow)==null?void 0:ae.centerOffset)!==0,[re,oe]=b.useState();return Di(()=>{x&&oe(window.getComputedStyle(x).zIndex)},[x]),m.jsx("div",{ref:F.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:I?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:re,"--radix-popper-transform-origin":[(me=W.transformOrigin)==null?void 0:me.x,(Ee=W.transformOrigin)==null?void 0:Ee.y].join(" "),...((De=W.hide)==null?void 0:De.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(cre,{scope:n,placedSide:j,onArrowChange:N,arrowX:V,arrowY:$,shouldHideArrow:te,children:m.jsx(hn.div,{"data-side":j,"data-align":L,...w,ref:T,style:{...w.style,animation:I?void 0:"none"}})})})});xz.displayName=_E;var Ez="PopperArrow",dre={top:"bottom",right:"left",bottom:"top",left:"right"},Cz=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=ure(Ez,r),o=dre[s.placedSide];return m.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:m.jsx(are,{...i,ref:n,style:{...i.style,display:"block"}})})});Cz.displayName=Ez;function fre(e){return e!==null}var hre=e=>({name:"transformOrigin",options:e,fn(t){var S,x,k;const{placement:n,rects:r,middlewareData:i}=t,o=((S=i.arrow)==null?void 0:S.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,f]=kz(n),p={start:"0%",center:"50%",end:"100%"}[f],y=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,v=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?p:`${y}px`,w=`${-u}px`):d==="top"?(_=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?p:`${v}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?p:`${v}px`),{data:{x:_,y:w}}}});function kz(e){const[t,n="center"]=e.split("-");return[t,n]}var fy=_z,hp=Sz,hy=xz,py=Cz,Lw="rovingFocusGroup.onEntryFocus",pre={bubbles:!1,cancelable:!0},pp="RovingFocusGroup",[kS,Tz,mre]=iE(pp),[gre,Rz]=wa(pp,[mre]),[vre,yre]=gre(pp),Az=b.forwardRef((e,t)=>m.jsx(kS.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(kS.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(bre,{...e,ref:t})})}));Az.displayName=pp;var bre=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...p}=e,y=b.useRef(null),v=Kn(t,y),_=sE(s),[w,S]=Tc({prop:o,defaultProp:l??null,onChange:u,caller:pp}),[x,k]=b.useState(!1),T=Do(d),R=Tz(n),N=b.useRef(!1),[A,O]=b.useState(0);return b.useEffect(()=>{const D=y.current;if(D)return D.addEventListener(Lw,T),()=>D.removeEventListener(Lw,T)},[T]),m.jsx(vre,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(D=>S(D),[S]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>O(D=>D+1),[]),onFocusableItemRemove:b.useCallback(()=>O(D=>D-1),[]),children:m.jsx(hn.div,{tabIndex:x||A===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:Mt(e.onMouseDown,()=>{N.current=!0}),onFocus:Mt(e.onFocus,D=>{const K=!N.current;if(D.target===D.currentTarget&&K&&!x){const U=new CustomEvent(Lw,pre);if(D.currentTarget.dispatchEvent(U),!U.defaultPrevented){const X=R().filter(P=>P.focusable),z=X.find(P=>P.active),M=X.find(P=>P.id===w),B=[z,M,...X].filter(Boolean).map(P=>P.ref.current);Pz(B,f)}}N.current=!1}),onBlur:Mt(e.onBlur,()=>k(!1))})})}),Mz="RovingFocusGroupItem",Nz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=Ci(),d=s||u,f=yre(Mz,n),p=f.currentTabStopId===d,y=Tz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),m.jsx(kS.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(hn.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Mt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:Mt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Mt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=Sre(S,f.orientation,f.dir);if(x!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let T=y().filter(R=>R.focusable).map(R=>R.ref.current);if(x==="last")T.reverse();else if(x==="prev"||x==="next"){x==="prev"&&T.reverse();const R=T.indexOf(S.currentTarget);T=f.loop?xre(T,R+1):T.slice(R+1)}setTimeout(()=>Pz(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});Nz.displayName=Mz;var _re={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wre(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Sre(e,t,n){const r=wre(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return _re[r]}function Pz(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function xre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ere=Az,Cre=Nz,TS=["Enter"," "],kre=["ArrowDown","PageUp","Home"],Oz=["ArrowUp","PageDown","End"],Tre=[...kre,...Oz],Rre={ltr:[...TS,"ArrowRight"],rtl:[...TS,"ArrowLeft"]},Are={ltr:["ArrowLeft"],rtl:["ArrowRight"]},mp="Menu",[Fh,Mre,Nre]=iE(mp),[Uc,Lz]=wa(mp,[Nre,Bl,Rz]),my=Bl(),Dz=Rz(),[Pre,Wc]=Uc(mp),[Ore,gp]=Uc(mp),Iz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=my(t),[u,d]=b.useState(null),f=b.useRef(!1),p=Do(s),y=sE(i);return b.useEffect(()=>{const v=()=>{f.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>f.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),m.jsx(fy,{...l,children:m.jsx(Pre,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:m.jsx(Ore,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:f,dir:y,modal:o,children:r})})})};Iz.displayName=mp;var Lre="MenuAnchor",wE=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=my(n);return m.jsx(hp,{...i,...r,ref:t})});wE.displayName=Lre;var SE="MenuPortal",[Dre,Bz]=Uc(SE,{forceMount:void 0}),zz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Wc(SE,t);return m.jsx(Dre,{scope:t,forceMount:n,children:m.jsx(qs,{present:n||s.open,children:m.jsx(Nd,{asChild:!0,container:i,children:r})})})};zz.displayName=SE;var $s="MenuContent",[Ire,xE]=Uc($s),jz=b.forwardRef((e,t)=>{const n=Bz($s,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Wc($s,e.__scopeMenu),o=gp($s,e.__scopeMenu);return m.jsx(Fh.Provider,{scope:e.__scopeMenu,children:m.jsx(qs,{present:r||s.open,children:m.jsx(Fh.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Bre,{...i,ref:t}):m.jsx(zre,{...i,ref:t})})})})}),Bre=b.forwardRef((e,t)=>{const n=Wc($s,e.__scopeMenu),r=b.useRef(null),i=Kn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return sy(s)},[]),m.jsx(EE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Mt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),zre=b.forwardRef((e,t)=>{const n=Wc($s,e.__scopeMenu);return m.jsx(EE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),jre=Cl("MenuContent.ScrollLock"),EE=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:y,onDismiss:v,disableOutsideScroll:_,...w}=e,S=Wc($s,n),x=gp($s,n),k=my(n),T=Dz(n),R=Mre(n),[N,A]=b.useState(null),O=b.useRef(null),D=Kn(t,O,S.onContentChange),K=b.useRef(0),U=b.useRef(""),X=b.useRef(0),z=b.useRef(null),M=b.useRef("right"),F=b.useRef(0),B=_?dp:b.Fragment,P=_?{as:jre,allowPinchZoom:!0}:void 0,I=j=>{var ee,pe;const L=U.current+j,Y=R().filter(ae=>!ae.disabled),V=document.activeElement,$=(ee=Y.find(ae=>ae.ref.current===V))==null?void 0:ee.textValue,te=Y.map(ae=>ae.textValue),re=Zre(te,L,$),oe=(pe=Y.find(ae=>ae.textValue===re))==null?void 0:pe.ref.current;(function ae(me){U.current=me,window.clearTimeout(K.current),me!==""&&(K.current=window.setTimeout(()=>ae(""),1e3))})(L),oe&&setTimeout(()=>oe.focus())};b.useEffect(()=>()=>window.clearTimeout(K.current),[]),ry();const W=b.useCallback(j=>{var Y,V;return M.current===((Y=z.current)==null?void 0:Y.side)&&Jre(j,(V=z.current)==null?void 0:V.area)},[]);return m.jsx(Ire,{scope:n,searchRef:U,onItemEnter:b.useCallback(j=>{W(j)&&j.preventDefault()},[W]),onItemLeave:b.useCallback(j=>{var L;W(j)||((L=O.current)==null||L.focus(),A(null))},[W]),onTriggerLeave:b.useCallback(j=>{W(j)&&j.preventDefault()},[W]),pointerGraceTimerRef:X,onPointerGraceIntentChange:b.useCallback(j=>{z.current=j},[]),children:m.jsx(B,{...P,children:m.jsx(up,{asChild:!0,trapped:i,onMountAutoFocus:Mt(s,j=>{var L;j.preventDefault(),(L=O.current)==null||L.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:m.jsx(Ere,{asChild:!0,...T,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:N,onCurrentTabStopIdChange:A,onEntryFocus:Mt(u,j=>{x.isUsingKeyboardRef.current||j.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(hy,{role:"menu","aria-orientation":"vertical","data-state":t3(S.open),"data-radix-menu-content":"",dir:x.dir,...k,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:Mt(w.onKeyDown,j=>{const Y=j.target.closest("[data-radix-menu-content]")===j.currentTarget,V=j.ctrlKey||j.altKey||j.metaKey,$=j.key.length===1;Y&&(j.key==="Tab"&&j.preventDefault(),!V&&$&&I(j.key));const te=O.current;if(j.target!==te||!Tre.includes(j.key))return;j.preventDefault();const oe=R().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);Oz.includes(j.key)&&oe.reverse(),Xre(oe)}),onBlur:Mt(e.onBlur,j=>{j.currentTarget.contains(j.target)||(window.clearTimeout(K.current),U.current="")}),onPointerMove:Mt(e.onPointerMove,Hh(j=>{const L=j.target,Y=F.current!==j.clientX;if(j.currentTarget.contains(L)&&Y){const V=j.clientX>F.current?"right":"left";M.current=V,F.current=j.clientX}}))})})})})})})});jz.displayName=$s;var $re="MenuGroup",CE=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(hn.div,{role:"group",...r,ref:t})});CE.displayName=$re;var Fre="MenuLabel",$z=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(hn.div,{...r,ref:t})});$z.displayName=Fre;var Tv="MenuItem",qN="menu.itemSelect",gy=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=gp(Tv,e.__scopeMenu),l=xE(Tv,e.__scopeMenu),u=Kn(t,s),d=b.useRef(!1),f=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(qN,{bubbles:!0,cancelable:!0});p.addEventListener(qN,v=>r==null?void 0:r(v),{once:!0}),TB(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(Fz,{...i,ref:u,disabled:n,onClick:Mt(e.onClick,f),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:Mt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:Mt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||TS.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});gy.displayName=Tv;var Fz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=xE(Tv,n),l=Dz(n),u=b.useRef(null),d=Kn(t,u),[f,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),m.jsx(Fh.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:m.jsx(Cre,{asChild:!0,...l,focusable:!r,children:m.jsx(hn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:Mt(e.onPointerMove,Hh(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Mt(e.onPointerLeave,Hh(_=>o.onItemLeave(_))),onFocus:Mt(e.onFocus,()=>p(!0)),onBlur:Mt(e.onBlur,()=>p(!1))})})})}),Hre="MenuCheckboxItem",Hz=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(Vz,{scope:e.__scopeMenu,checked:n,children:m.jsx(gy,{role:"menuitemcheckbox","aria-checked":Rv(n)?"mixed":n,...i,ref:t,"data-state":TE(n),onSelect:Mt(i.onSelect,()=>r==null?void 0:r(Rv(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Hz.displayName=Hre;var Uz="MenuRadioGroup",[Ure,Wre]=Uc(Uz,{value:void 0,onValueChange:()=>{}}),Wz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Do(r);return m.jsx(Ure,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(CE,{...i,ref:t})})});Wz.displayName=Uz;var qz="MenuRadioItem",Yz=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=Wre(qz,e.__scopeMenu),s=n===i.value;return m.jsx(Vz,{scope:e.__scopeMenu,checked:s,children:m.jsx(gy,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":TE(s),onSelect:Mt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});Yz.displayName=qz;var kE="MenuItemIndicator",[Vz,qre]=Uc(kE,{checked:!1}),Kz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=qre(kE,n);return m.jsx(qs,{present:r||Rv(s.checked)||s.checked===!0,children:m.jsx(hn.span,{...i,ref:t,"data-state":TE(s.checked)})})});Kz.displayName=kE;var Yre="MenuSeparator",Xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(hn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Xz.displayName=Yre;var Vre="MenuArrow",Gz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=my(n);return m.jsx(py,{...i,...r,ref:t})});Gz.displayName=Vre;var Kre="MenuSub",[FMe,Zz]=Uc(Kre),oh="MenuSubTrigger",Qz=b.forwardRef((e,t)=>{const n=Wc(oh,e.__scopeMenu),r=gp(oh,e.__scopeMenu),i=Zz(oh,e.__scopeMenu),s=xE(oh,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},f=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>f,[f]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),m.jsx(wE,{asChild:!0,...d,children:m.jsx(Fz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":t3(n.open),...e,ref:va(t,i.onTriggerChange),onClick:p=>{var y;(y=e.onClick)==null||y.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Mt(e.onPointerMove,Hh(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:Mt(e.onPointerLeave,Hh(p=>{var v,_;f();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,S=w==="right",x=S?-5:5,k=y[S?"left":"right"],T=y[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+x,y:p.clientY},{x:k,y:y.top},{x:T,y:y.top},{x:T,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:Mt(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Rre[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});Qz.displayName=oh;var Jz="MenuSubContent",e3=b.forwardRef((e,t)=>{const n=Bz($s,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Wc($s,e.__scopeMenu),o=gp($s,e.__scopeMenu),l=Zz(Jz,e.__scopeMenu),u=b.useRef(null),d=Kn(t,u);return m.jsx(Fh.Provider,{scope:e.__scopeMenu,children:m.jsx(qs,{present:r||s.open,children:m.jsx(Fh.Slot,{scope:e.__scopeMenu,children:m.jsx(EE,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:Mt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Mt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Mt(e.onKeyDown,f=>{var v;const p=f.currentTarget.contains(f.target),y=Are[o.dir].includes(f.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),f.preventDefault())})})})})})});e3.displayName=Jz;function t3(e){return e?"open":"closed"}function Rv(e){return e==="indeterminate"}function TE(e){return Rv(e)?"indeterminate":e?"checked":"unchecked"}function Xre(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Gre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Zre(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Gre(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function Qre(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,f=l.y,p=u.x,y=u.y;f>r!=y>r&&n<(p-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function Jre(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Qre(n,t)}function Hh(e){return t=>t.pointerType==="mouse"?e(t):void 0}var eie=Iz,tie=wE,nie=zz,rie=jz,iie=CE,sie=$z,oie=gy,aie=Hz,lie=Wz,cie=Yz,uie=Kz,die=Xz,fie=Gz,hie=Qz,pie=e3,vy="DropdownMenu",[mie]=wa(vy,[Lz]),Wi=Lz(),[gie,n3]=mie(vy),r3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Wi(t),d=b.useRef(null),[f,p]=Tc({prop:i,defaultProp:s??!1,onChange:o,caller:vy});return m.jsx(gie,{scope:t,triggerId:Ci(),triggerRef:d,contentId:Ci(),open:f,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:m.jsx(eie,{...u,open:f,onOpenChange:p,dir:r,modal:l,children:n})})};r3.displayName=vy;var i3="DropdownMenuTrigger",s3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=n3(i3,n),o=Wi(n);return m.jsx(tie,{asChild:!0,...o,children:m.jsx(hn.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:va(t,s.triggerRef),onPointerDown:Mt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:Mt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});s3.displayName=i3;var vie="DropdownMenuPortal",o3=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Wi(t);return m.jsx(nie,{...r,...n})};o3.displayName=vie;var a3="DropdownMenuContent",l3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=n3(a3,n),s=Wi(n),o=b.useRef(!1);return m.jsx(rie,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Mt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Mt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,f=u.button===2||d;(!i.modal||f)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});l3.displayName=a3;var yie="DropdownMenuGroup",bie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(iie,{...i,...r,ref:t})});bie.displayName=yie;var _ie="DropdownMenuLabel",c3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(sie,{...i,...r,ref:t})});c3.displayName=_ie;var wie="DropdownMenuItem",u3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(oie,{...i,...r,ref:t})});u3.displayName=wie;var Sie="DropdownMenuCheckboxItem",d3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(aie,{...i,...r,ref:t})});d3.displayName=Sie;var xie="DropdownMenuRadioGroup",Eie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(lie,{...i,...r,ref:t})});Eie.displayName=xie;var Cie="DropdownMenuRadioItem",kie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(cie,{...i,...r,ref:t})});kie.displayName=Cie;var Tie="DropdownMenuItemIndicator",f3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(uie,{...i,...r,ref:t})});f3.displayName=Tie;var Rie="DropdownMenuSeparator",h3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(die,{...i,...r,ref:t})});h3.displayName=Rie;var Aie="DropdownMenuArrow",Mie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(fie,{...i,...r,ref:t})});Mie.displayName=Aie;var Nie="DropdownMenuSubTrigger",Pie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(hie,{...i,...r,ref:t})});Pie.displayName=Nie;var Oie="DropdownMenuSubContent",Lie=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Wi(n);return m.jsx(pie,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Lie.displayName=Oie;var Die=r3,Iie=s3,Bie=o3,zie=l3,jie=c3,$ie=u3,Fie=d3,Hie=f3,Uie=h3;function YN(e,[t,n]){return Math.min(n,Math.max(t,e))}var yy="Popover",[p3]=wa(yy,[Bl]),vp=Bl(),[Wie,zl]=p3(yy),m3=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=vp(t),u=b.useRef(null),[d,f]=b.useState(!1),[p,y]=Tc({prop:r,defaultProp:i??!1,onChange:s,caller:yy});return m.jsx(fy,{...l,children:m.jsx(Wie,{scope:t,contentId:Ci(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>f(!0),[]),onCustomAnchorRemove:b.useCallback(()=>f(!1),[]),modal:o,children:n})})};m3.displayName=yy;var g3="PopoverAnchor",qie=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=zl(g3,n),s=vp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(hp,{...s,...r,ref:t})});qie.displayName=g3;var v3="PopoverTrigger",y3=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=zl(v3,n),s=vp(n),o=Kn(t,i.triggerRef),l=m.jsx(hn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":x3(i.open),...r,ref:o,onClick:Mt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(hp,{asChild:!0,...s,children:l})});y3.displayName=v3;var RE="PopoverPortal",[Yie,Vie]=p3(RE,{forceMount:void 0}),b3=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=zl(RE,t);return m.jsx(Yie,{scope:t,forceMount:n,children:m.jsx(qs,{present:n||s.open,children:m.jsx(Nd,{asChild:!0,container:i,children:r})})})};b3.displayName=RE;var _d="PopoverContent",_3=b.forwardRef((e,t)=>{const n=Vie(_d,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=zl(_d,e.__scopePopover);return m.jsx(qs,{present:r||s.open,children:s.modal?m.jsx(Xie,{...i,ref:t}):m.jsx(Gie,{...i,ref:t})})});_3.displayName=_d;var Kie=Cl("PopoverContent.RemoveScroll"),Xie=b.forwardRef((e,t)=>{const n=zl(_d,e.__scopePopover),r=b.useRef(null),i=Kn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return sy(o)},[]),m.jsx(dp,{as:Kie,allowPinchZoom:!0,children:m.jsx(w3,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Mt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:Mt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:Mt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Gie=b.forwardRef((e,t)=>{const n=zl(_d,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(w3,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),w3=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,...p}=e,y=zl(_d,n),v=vp(n);return ry(),m.jsx(up,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:m.jsx(hy,{"data-state":x3(y.open),role:"dialog",id:y.contentId,...v,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),S3="PopoverClose",Zie=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=zl(S3,n);return m.jsx(hn.button,{type:"button",...r,ref:t,onClick:Mt(e.onClick,()=>i.onOpenChange(!1))})});Zie.displayName=S3;var Qie="PopoverArrow",Jie=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=vp(n);return m.jsx(py,{...i,...r,ref:t})});Jie.displayName=Qie;function x3(e){return e?"open":"closed"}var ese=m3,tse=y3,nse=b3,rse=_3,ise=[" ","Enter","ArrowUp","ArrowDown"],sse=[" ","Enter"],Mc="Select",[by,_y,ose]=iE(Mc),[Ld]=wa(Mc,[ose,Bl]),wy=Bl(),[ase,jl]=Ld(Mc),[lse,cse]=Ld(Mc),E3=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:f,autoComplete:p,disabled:y,required:v,form:_}=e,w=wy(t),[S,x]=b.useState(null),[k,T]=b.useState(null),[R,N]=b.useState(!1),A=sE(d),[O,D]=Tc({prop:r,defaultProp:i??!1,onChange:s,caller:Mc}),[K,U]=Tc({prop:o,defaultProp:l,onChange:u,caller:Mc}),X=b.useRef(null),z=S?_||!!S.closest("form"):!0,[M,F]=b.useState(new Set),B=Array.from(M).map(P=>P.props.value).join(";");return m.jsx(fy,{...w,children:m.jsxs(ase,{required:v,scope:t,trigger:S,onTriggerChange:x,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:R,onValueNodeHasChildrenChange:N,contentId:Ci(),value:K,onValueChange:U,open:O,onOpenChange:D,dir:A,triggerPointerDownPosRef:X,disabled:y,children:[m.jsx(by.Provider,{scope:t,children:m.jsx(lse,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{F(I=>new Set(I).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{F(I=>{const W=new Set(I);return W.delete(P),W})},[]),children:n})}),z?m.jsxs(Y3,{"aria-hidden":!0,required:v,tabIndex:-1,name:f,autoComplete:p,value:K,onChange:P=>U(P.target.value),disabled:y,form:_,children:[K===void 0?m.jsx("option",{value:""}):null,Array.from(M)]},B):null]})})};E3.displayName=Mc;var C3="SelectTrigger",k3=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=wy(n),o=jl(C3,n),l=o.disabled||r,u=Kn(t,o.onTriggerChange),d=_y(n),f=b.useRef("touch"),[p,y,v]=K3(w=>{const S=d().filter(T=>!T.disabled),x=S.find(T=>T.value===o.value),k=X3(S,w,x);k!==void 0&&o.onValueChange(k.value)}),_=w=>{l||(o.onOpenChange(!0),v()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(hp,{asChild:!0,...s,children:m.jsx(hn.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":V3(o.value)?"":void 0,...i,ref:u,onClick:Mt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:Mt(i.onPointerDown,w=>{f.current=w.pointerType;const S=w.target;S.hasPointerCapture(w.pointerId)&&S.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:Mt(i.onKeyDown,w=>{const S=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(S&&w.key===" ")&&ise.includes(w.key)&&(_(),w.preventDefault())})})})});k3.displayName=C3;var T3="SelectValue",R3=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=jl(T3,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,p=Kn(t,u.onValueNodeChange);return Di(()=>{d(f)},[d,f]),m.jsx(hn.span,{...l,ref:p,style:{pointerEvents:"none"},children:V3(u.value)?m.jsx(m.Fragment,{children:o}):s})});R3.displayName=T3;var use="SelectIcon",A3=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(hn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});A3.displayName=use;var dse="SelectPortal",M3=e=>m.jsx(Nd,{asChild:!0,...e});M3.displayName=dse;var Nc="SelectContent",N3=b.forwardRef((e,t)=>{const n=jl(Nc,e.__scopeSelect),[r,i]=b.useState();if(Di(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?Hc.createPortal(m.jsx(P3,{scope:e.__scopeSelect,children:m.jsx(by.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(O3,{...e,ref:t})});N3.displayName=Nc;var Qs=10,[P3,$l]=Ld(Nc),fse="SelectContentImpl",hse=Cl("SelectContent.RemoveScroll"),O3=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,k=jl(Nc,n),[T,R]=b.useState(null),[N,A]=b.useState(null),O=Kn(t,ee=>R(ee)),[D,K]=b.useState(null),[U,X]=b.useState(null),z=_y(n),[M,F]=b.useState(!1),B=b.useRef(!1);b.useEffect(()=>{if(T)return sy(T)},[T]),ry();const P=b.useCallback(ee=>{const[pe,...ae]=z().map(De=>De.ref.current),[me]=ae.slice(-1),Ee=document.activeElement;for(const De of ee)if(De===Ee||(De==null||De.scrollIntoView({block:"nearest"}),De===pe&&N&&(N.scrollTop=0),De===me&&N&&(N.scrollTop=N.scrollHeight),De==null||De.focus(),document.activeElement!==Ee))return},[z,N]),I=b.useCallback(()=>P([D,T]),[P,D,T]);b.useEffect(()=>{M&&I()},[M,I]);const{onOpenChange:W,triggerPointerDownPosRef:j}=k;b.useEffect(()=>{if(T){let ee={x:0,y:0};const pe=me=>{var Ee,De;ee={x:Math.abs(Math.round(me.pageX)-(((Ee=j.current)==null?void 0:Ee.x)??0)),y:Math.abs(Math.round(me.pageY)-(((De=j.current)==null?void 0:De.y)??0))}},ae=me=>{ee.x<=10&&ee.y<=10?me.preventDefault():T.contains(me.target)||W(!1),document.removeEventListener("pointermove",pe),j.current=null};return j.current!==null&&(document.addEventListener("pointermove",pe),document.addEventListener("pointerup",ae,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",pe),document.removeEventListener("pointerup",ae,{capture:!0})}}},[T,W,j]),b.useEffect(()=>{const ee=()=>W(!1);return window.addEventListener("blur",ee),window.addEventListener("resize",ee),()=>{window.removeEventListener("blur",ee),window.removeEventListener("resize",ee)}},[W]);const[L,Y]=K3(ee=>{const pe=z().filter(Ee=>!Ee.disabled),ae=pe.find(Ee=>Ee.ref.current===document.activeElement),me=X3(pe,ee,ae);me&&setTimeout(()=>me.ref.current.focus())}),V=b.useCallback((ee,pe,ae)=>{const me=!B.current&&!ae;(k.value!==void 0&&k.value===pe||me)&&(K(ee),me&&(B.current=!0))},[k.value]),$=b.useCallback(()=>T==null?void 0:T.focus(),[T]),te=b.useCallback((ee,pe,ae)=>{const me=!B.current&&!ae;(k.value!==void 0&&k.value===pe||me)&&X(ee)},[k.value]),re=r==="popper"?RS:L3,oe=re===RS?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(P3,{scope:n,content:T,viewport:N,onViewportChange:A,itemRefCallback:V,selectedItem:D,onItemLeave:$,itemTextRefCallback:te,focusSelectedItem:I,selectedItemText:U,position:r,isPositioned:M,searchRef:L,children:m.jsx(dp,{as:hse,allowPinchZoom:!0,children:m.jsx(up,{asChild:!0,trapped:k.open,onMountAutoFocus:ee=>{ee.preventDefault()},onUnmountAutoFocus:Mt(i,ee=>{var pe;(pe=k.trigger)==null||pe.focus({preventScroll:!0}),ee.preventDefault()}),children:m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:ee=>ee.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:m.jsx(re,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:ee=>ee.preventDefault(),...x,...oe,onPlaced:()=>F(!0),ref:O,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:Mt(x.onKeyDown,ee=>{const pe=ee.ctrlKey||ee.altKey||ee.metaKey;if(ee.key==="Tab"&&ee.preventDefault(),!pe&&ee.key.length===1&&Y(ee.key),["ArrowUp","ArrowDown","Home","End"].includes(ee.key)){let me=z().filter(Ee=>!Ee.disabled).map(Ee=>Ee.ref.current);if(["ArrowUp","End"].includes(ee.key)&&(me=me.slice().reverse()),["ArrowUp","ArrowDown"].includes(ee.key)){const Ee=ee.target,De=me.indexOf(Ee);me=me.slice(De+1)}setTimeout(()=>P(me)),ee.preventDefault()}})})})})})})});O3.displayName=fse;var pse="SelectItemAlignedPosition",L3=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=jl(Nc,n),o=$l(Nc,n),[l,u]=b.useState(null),[d,f]=b.useState(null),p=Kn(t,O=>f(O)),y=_y(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:k}=o,T=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const O=s.trigger.getBoundingClientRect(),D=d.getBoundingClientRect(),K=s.valueNode.getBoundingClientRect(),U=x.getBoundingClientRect();if(s.dir!=="rtl"){const Ee=U.left-D.left,De=K.left-Ee,Se=O.left-De,Je=O.width+Se,Ht=Math.max(Je,D.width),ye=window.innerWidth-Qs,Ze=YN(De,[Qs,Math.max(Qs,ye-Ht)]);l.style.minWidth=Je+"px",l.style.left=Ze+"px"}else{const Ee=D.right-U.right,De=window.innerWidth-K.right-Ee,Se=window.innerWidth-O.right-De,Je=O.width+Se,Ht=Math.max(Je,D.width),ye=window.innerWidth-Qs,Ze=YN(De,[Qs,Math.max(Qs,ye-Ht)]);l.style.minWidth=Je+"px",l.style.right=Ze+"px"}const X=y(),z=window.innerHeight-Qs*2,M=w.scrollHeight,F=window.getComputedStyle(d),B=parseInt(F.borderTopWidth,10),P=parseInt(F.paddingTop,10),I=parseInt(F.borderBottomWidth,10),W=parseInt(F.paddingBottom,10),j=B+P+M+W+I,L=Math.min(S.offsetHeight*5,j),Y=window.getComputedStyle(w),V=parseInt(Y.paddingTop,10),$=parseInt(Y.paddingBottom,10),te=O.top+O.height/2-Qs,re=z-te,oe=S.offsetHeight/2,ee=S.offsetTop+oe,pe=B+P+ee,ae=j-pe;if(pe<=te){const Ee=X.length>0&&S===X[X.length-1].ref.current;l.style.bottom="0px";const De=d.clientHeight-w.offsetTop-w.offsetHeight,Se=Math.max(re,oe+(Ee?$:0)+De+I),Je=pe+Se;l.style.height=Je+"px"}else{const Ee=X.length>0&&S===X[0].ref.current;l.style.top="0px";const Se=Math.max(te,B+w.offsetTop+(Ee?V:0)+oe)+ae;l.style.height=Se+"px",w.scrollTop=pe-te+w.offsetTop}l.style.margin=`${Qs}px 0`,l.style.minHeight=L+"px",l.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,S,x,s.dir,r]);Di(()=>T(),[T]);const[R,N]=b.useState();Di(()=>{d&&N(window.getComputedStyle(d).zIndex)},[d]);const A=b.useCallback(O=>{O&&_.current===!0&&(T(),k==null||k(),_.current=!1)},[T,k]);return m.jsx(gse,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:A,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:R},children:m.jsx(hn.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});L3.displayName=pse;var mse="SelectPopperPosition",RS=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Qs,...s}=e,o=wy(n);return m.jsx(hy,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});RS.displayName=mse;var[gse,AE]=Ld(Nc,{}),AS="SelectViewport",D3=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=$l(AS,n),o=AE(AS,n),l=Kn(t,s.onViewportChange),u=b.useRef(0);return m.jsxs(m.Fragment,{children:[m.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),m.jsx(by.Slot,{scope:n,children:m.jsx(hn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Mt(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const v=Math.abs(u.current-f.scrollTop);if(v>0){const _=window.innerHeight-Qs*2,w=parseFloat(p.style.minHeight),S=parseFloat(p.style.height),x=Math.max(w,S);if(x<_){const k=x+v,T=Math.min(_,k),R=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(f.scrollTop=R>0?R:0,p.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});D3.displayName=AS;var I3="SelectGroup",[vse,yse]=Ld(I3),bse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Ci();return m.jsx(vse,{scope:n,id:i,children:m.jsx(hn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});bse.displayName=I3;var B3="SelectLabel",_se=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=yse(B3,n);return m.jsx(hn.div,{id:i.id,...r,ref:t})});_se.displayName=B3;var Av="SelectItem",[wse,z3]=Ld(Av),j3=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=jl(Av,n),u=$l(Av,n),d=l.value===r,[f,p]=b.useState(s??""),[y,v]=b.useState(!1),_=Kn(t,k=>{var T;return(T=u.itemRefCallback)==null?void 0:T.call(u,k,r,i)}),w=Ci(),S=b.useRef("touch"),x=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return m.jsx(wse,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:m.jsx(by.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(hn.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:Mt(o.onFocus,()=>v(!0)),onBlur:Mt(o.onBlur,()=>v(!1)),onClick:Mt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:Mt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:Mt(o.onPointerDown,k=>{S.current=k.pointerType}),onPointerMove:Mt(o.onPointerMove,k=>{var T;S.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):S.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Mt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:Mt(o.onKeyDown,k=>{var R;((R=u.searchRef)==null?void 0:R.current)!==""&&k.key===" "||(sse.includes(k.key)&&x(),k.key===" "&&k.preventDefault())})})})})});j3.displayName=Av;var ah="SelectItemText",$3=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=jl(ah,n),l=$l(ah,n),u=z3(ah,n),d=cse(ah,n),[f,p]=b.useState(null),y=Kn(t,x=>p(x),u.onItemTextChange,x=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,x,u.value,u.disabled)}),v=f==null?void 0:f.textContent,_=b.useMemo(()=>m.jsx("option",{value:u.value,disabled:u.disabled,children:v},u.value),[u.disabled,u.value,v]),{onNativeOptionAdd:w,onNativeOptionRemove:S}=d;return Di(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(hn.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Hc.createPortal(s.children,o.valueNode):null]})});$3.displayName=ah;var F3="SelectItemIndicator",H3=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return z3(F3,n).isSelected?m.jsx(hn.span,{"aria-hidden":!0,...r,ref:t}):null});H3.displayName=F3;var MS="SelectScrollUpButton",U3=b.forwardRef((e,t)=>{const n=$l(MS,e.__scopeSelect),r=AE(MS,e.__scopeSelect),[i,s]=b.useState(!1),o=Kn(t,r.onScrollButtonChange);return Di(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollTop>0;s(d)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?m.jsx(q3,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});U3.displayName=MS;var NS="SelectScrollDownButton",W3=b.forwardRef((e,t)=>{const n=$l(NS,e.__scopeSelect),r=AE(NS,e.__scopeSelect),[i,s]=b.useState(!1),o=Kn(t,r.onScrollButtonChange);return Di(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,f=Math.ceil(u.scrollTop)<d;s(f)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?m.jsx(q3,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});W3.displayName=NS;var q3=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=$l("SelectScrollButton",n),o=b.useRef(null),l=_y(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Di(()=>{var f;const d=l().find(p=>p.ref.current===document.activeElement);(f=d==null?void 0:d.ref.current)==null||f.scrollIntoView({block:"nearest"})},[l]),m.jsx(hn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Mt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Mt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Mt(i.onPointerLeave,()=>{u()})})}),Sse="SelectSeparator",xse=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(hn.div,{"aria-hidden":!0,...r,ref:t})});xse.displayName=Sse;var PS="SelectArrow",Ese=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=wy(n),s=jl(PS,n),o=$l(PS,n);return s.open&&o.position==="popper"?m.jsx(py,{...i,...r,ref:t}):null});Ese.displayName=PS;var Cse="SelectBubbleInput",Y3=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=Kn(r,i),o=ene(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&f){const p=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(p)}},[o,t]),m.jsx(hn.select,{...n,style:{...RB,...n.style},ref:s,defaultValue:t})});Y3.displayName=Cse;function V3(e){return e===""||e===void 0}function K3(e){const t=Do(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function X3(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=kse(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.textValue.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function kse(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Tse=E3,Rse=k3,Ase=R3,Mse=A3,Nse=M3,Pse=N3,Ose=D3,Lse=j3,Dse=$3,Ise=H3,Bse=U3,zse=W3,[Sy]=wa("Tooltip",[Bl]),xy=Bl(),G3="TooltipProvider",jse=700,OS="tooltip.open",[$se,ME]=Sy(G3),Z3=e=>{const{__scopeTooltip:t,delayDuration:n=jse,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=b.useRef(!0),l=b.useRef(!1),u=b.useRef(0);return b.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),m.jsx($se,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:b.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};Z3.displayName=G3;var Uh="Tooltip",[Fse,yp]=Sy(Uh),Q3=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=ME(Uh,e.__scopeTooltip),d=xy(t),[f,p]=b.useState(null),y=Ci(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,k]=Tc({prop:r,defaultProp:i??!1,onChange:O=>{O?(u.onOpen(),document.dispatchEvent(new CustomEvent(OS))):u.onClose(),s==null||s(O)},caller:Uh}),T=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),R=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,S.current=!1,k(!0)},[k]),N=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{S.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),m.jsx(fy,{...d,children:m.jsx(Fse,{scope:t,contentId:y,open:x,stateAttribute:T,trigger:f,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?A():R()},[u.isOpenDelayedRef,A,R]),onTriggerLeave:b.useCallback(()=>{_?N():(window.clearTimeout(v.current),v.current=0)},[N,_]),onOpen:R,onClose:N,disableHoverableContent:_,children:n})})};Q3.displayName=Uh;var LS="TooltipTrigger",J3=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=yp(LS,n),s=ME(LS,n),o=xy(n),l=b.useRef(null),u=Kn(t,l,i.onTriggerChange),d=b.useRef(!1),f=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),m.jsx(hp,{asChild:!0,...o,children:m.jsx(hn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:Mt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Mt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Mt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:Mt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:Mt(e.onBlur,i.onClose),onClick:Mt(e.onClick,i.onClose)})})});J3.displayName=LS;var NE="TooltipPortal",[Hse,Use]=Sy(NE,{forceMount:void 0}),e5=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=yp(NE,t);return m.jsx(Hse,{scope:t,forceMount:n,children:m.jsx(qs,{present:n||s.open,children:m.jsx(Nd,{asChild:!0,container:i,children:r})})})};e5.displayName=NE;var wd="TooltipContent",t5=b.forwardRef((e,t)=>{const n=Use(wd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=yp(wd,e.__scopeTooltip);return m.jsx(qs,{present:r||o.open,children:o.disableHoverableContent?m.jsx(n5,{side:i,...s,ref:t}):m.jsx(Wse,{side:i,...s,ref:t})})}),Wse=b.forwardRef((e,t)=>{const n=yp(wd,e.__scopeTooltip),r=ME(wd,e.__scopeTooltip),i=b.useRef(null),s=Kn(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:p}=r,y=b.useCallback(()=>{l(null),p(!1)},[p]),v=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},k=Kse(x,S.getBoundingClientRect()),T=Xse(x,k),R=Gse(w.getBoundingClientRect()),N=Qse([...T,...R]);l(N),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&f){const _=S=>v(S,f),w=S=>v(S,u);return u.addEventListener("pointerleave",_),f.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),f.removeEventListener("pointerleave",w)}}},[u,f,v,y]),b.useEffect(()=>{if(o){const _=w=>{const S=w.target,x={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),T=!Zse(x,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,y]),m.jsx(n5,{...e,ref:s})}),[qse,Yse]=Sy(Uh,{isInside:!1}),Vse=kee("TooltipContent"),n5=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=yp(wd,n),d=xy(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(OS,f),()=>document.removeEventListener(OS,f)),[f]),b.useEffect(()=>{if(u.trigger){const p=y=>{const v=y.target;v!=null&&v.contains(u.trigger)&&f()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,f]),m.jsx(Md,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:f,children:m.jsxs(hy,{"data-state":u.stateAttribute,...d,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[m.jsx(Vse,{children:r}),m.jsx(qse,{scope:n,isInside:!0,children:m.jsx(MB,{id:u.contentId,role:"tooltip",children:i||r})})]})})});t5.displayName=wd;var r5="TooltipArrow",i5=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=xy(n);return Yse(r5,n).isInside?null:m.jsx(py,{...i,...r,ref:t})});i5.displayName=r5;function Kse(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function Xse(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function Gse(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function Zse(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,f=l.y,p=u.x,y=u.y;f>r!=y>r&&n<(p-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function Qse(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),Jse(t)}function Jse(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var eoe=Z3,toe=Q3,noe=J3,roe=e5,ioe=t5,soe=i5;function PE({...e}){return m.jsx(ese,{"data-slot":"popover",...e})}function OE({...e}){return m.jsx(tse,{"data-slot":"popover-trigger",...e})}function LE({className:e,align:t="center",sideOffset:n=4,...r}){return m.jsx(nse,{children:m.jsx(rse,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const VN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,KN=aI,ooe=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return KN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(d=>{const f=n==null?void 0:n[d],p=s==null?void 0:s[d];if(f===null)return null;const y=VN(f)||VN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,y]=f;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:p,className:y,...v}=f;return Object.entries(v).every(_=>{let[w,S]=_;return Array.isArray(S)?S.includes({...s,...l}[w]):{...s,...l}[w]===S})?[...d,p,y]:d},[]);return KN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},aoe=ooe("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-normal whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function Ct({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?Eee:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(aoe({variant:t,size:n,className:e})),...i})}function Ey({...e}){return m.jsx(Die,{"data-slot":"dropdown-menu",...e})}function Cy({...e}){return m.jsx(Iie,{"data-slot":"dropdown-menu-trigger",...e})}function ky({className:e,sideOffset:t=4,...n}){return m.jsx(Bie,{children:m.jsx(zie,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function Js({className:e,inset:t,variant:n="default",...r}){return m.jsx($ie,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Dw({className:e,children:t,checked:n,...r}){return m.jsxs(Fie,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(Hie,{children:m.jsx(Lo,{className:"size-4"})})}),t]})}function dg({className:e,inset:t,...n}){return m.jsx(jie,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Iw({className:e,...t}){return m.jsx(Uie,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}const loe={"no-proxy":{heading:"还没有连接开发机",body:"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。"},"client-token-missing":{heading:"需要 client token",body:"Relay 服务器已启用客户端访问控制。请在设置里填写。"},"client-token-invalid":{heading:"client token 无效",body:"当前浏览器保存的 client token 无效或已过期。请在设置里更新。"},"no-session":{heading:"没有选中的会话",body:""},"no-messages":{heading:"开始对话",body:""}};function Sc({variant:e,action:t}){const{heading:n,body:r}=loe[e];return e==="no-messages"?m.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:m.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[m.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&m.jsx("div",{children:t})]})}const coe={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},uoe={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function DS({status:e,className:t}){return m.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",coe[e],t),role:"status","aria-label":uoe[e]})}function xa({...e}){return m.jsx(cE,{"data-slot":"dialog",...e})}function doe({...e}){return m.jsx(uE,{"data-slot":"dialog-portal",...e})}function foe({...e}){return m.jsx(ay,{"data-slot":"dialog-close",...e})}function hoe({className:e,...t}){return m.jsx(dE,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ea({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return m.jsxs(doe,{"data-slot":"dialog-portal",children:[m.jsx(hoe,{}),m.jsxs(fE,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&m.jsxs(ay,{"data-slot":"dialog-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[m.jsx(jc,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ca({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Rl({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(ay,{asChild:!0,children:m.jsx(Ct,{variant:"outline",children:"Close"})})]})}function Io({className:e,...t}){return m.jsx(iz,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function _a({className:e,...t}){return m.jsx(sz,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function poe(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function moe({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(xa,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Ea,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"移除离线开发机?"}),m.jsx(_a,{children:poe(t)})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(Ct,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(Mo,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const Gg=80,goe=8,voe=1.2;function XN(e){return Math.max(0,Math.min(Gg,e))}function yoe({proxyId:e,name:t,selected:n,revealed:r,disabled:i=!1,onRevealedChange:s,onRemove:o}){const l=t??e,u=b.useRef(null),d=b.useRef(!1),[f,p]=b.useState(null),y=f??(r?Gg:0),v=f!==null;function _(k){var T,R;if(!(i||k.pointerType!=="touch"&&k.pointerType!=="pen")&&!k.target.closest("button")){u.current={pointerId:k.pointerId,startX:k.clientX,startY:k.clientY,startOffset:r?Gg:0,axis:"pending"};try{(R=(T=k.currentTarget).setPointerCapture)==null||R.call(T,k.pointerId)}catch{}}}function w(k){const T=u.current;if(!T||T.pointerId!==k.pointerId)return;const R=k.clientX-T.startX,N=k.clientY-T.startY;if(T.axis==="pending"){if(Math.hypot(R,N)<goe)return;T.axis=Math.abs(R)>Math.abs(N)*voe?"horizontal":"vertical"}T.axis!=="vertical"&&(k.preventDefault(),p(XN(T.startOffset-R)))}function S(k,T=!1){var A,O;const R=u.current;if(!R||R.pointerId!==k.pointerId)return;u.current=null;try{(O=(A=k.currentTarget).releasePointerCapture)==null||O.call(A,k.pointerId)}catch{}if(R.axis!=="horizontal"||T){p(null);return}k.preventDefault();const N=f??XN(R.startOffset-(k.clientX-R.startX));p(null),s(N>=Gg/2),d.current=!0,window.setTimeout(()=>{d.current=!1},0)}function x(k){if(d.current){d.current=!1,k.preventDefault();return}r&&s(!1)}return m.jsxs("li",{className:"relative min-h-11 overflow-hidden rounded-md","data-slot":"proxy-item","data-swipeable":"true","data-proxy-id":e,"data-online":"false","data-revealed":r||void 0,children:[m.jsxs("div",{className:"relative z-10 flex min-h-11 w-full touch-pan-y select-none items-center gap-3 rounded-md border border-border bg-card px-3 text-left text-muted-foreground opacity-60 shadow-sm transition-transform duration-200 ease-out motion-reduce:transition-none",style:{transform:`translateX(-${y}px)`,transitionDuration:v?"0ms":void 0},title:"这台开发机离线。向左滑动可移除。","data-slot":"proxy-swipe-foreground","data-offset":y,onPointerDown:_,onPointerMove:w,onPointerUp:k=>S(k),onPointerCancel:k=>S(k,!0),onClick:x,children:[m.jsx(DS,{status:"offline"}),m.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-normal text-foreground",children:l}),n&&m.jsx(Lo,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}),m.jsx("span",{className:"shrink-0 text-xs",children:"离线"}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon",className:"-mr-2 size-11 text-muted-foreground",disabled:i,"aria-label":`显示移除 ${l} 操作`,"aria-expanded":r,onClick:k=>{k.stopPropagation(),s(!r)},children:m.jsx(A1,{"aria-hidden":"true"})})]}),m.jsxs("button",{type:"button",className:"absolute inset-y-0 right-0 z-0 flex w-20 min-h-11 flex-col items-center justify-center gap-0.5 rounded-r-md bg-destructive text-xs font-medium text-white outline-none transition-colors hover:bg-destructive/90 focus-visible:z-20 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50",tabIndex:r?0:-1,disabled:i,"aria-label":`移除 ${l}`,"data-slot":"proxy-mobile-remove",onFocus:()=>s(!0),onClick:o,children:[m.jsx(O1,{className:"size-4","aria-hidden":"true"}),"移除"]})]})}function s5({layout:e,variant:t="default"}){const n=Le(O=>O.proxies),r=Le(O=>O.proxyListLoaded),i=Le(O=>O.relayClientAuthIssue),s=Le(O=>O.selectedProxyId),o=Le(O=>O.proxySwitchTarget),l=Ui(),u=oo(),[d,f]=b.useState(!1),[p,y]=b.useState(null),[v,_]=b.useState(null),[w,S]=b.useState(null);async function x(O,D){if(o)return;const K=Ut;if(!K){Xe.error("请先连接开发机");return}const U=D??O,X=s!==null&&s!==O;Le.getState().setProxySwitchTarget({proxyId:O,name:U});try{const z=await K.selectProxy(O);if(!z.success){Xe.error(`无法连接 ${U}:${z.error??"未知错误"}`);return}X&&($t.getState().prepareForProxySwitch(U),ni.getState().prepareForProxySwitch()),Cr("local",vn.proxyId,O),Le.getState().setProxy(O,D??null),Le.getState().setProxyOnline(!0),Le.getState().transitionToPhase("session_browsing"),K.sendControl({type:"session_list"}),K.requestProxyInfo().then(M=>{if(Le.getState().selectedProxyId!==O)return;const F=ni.getState();F.setHomePath(M.homePath),F.setAgentCli(M.agentCli)}).catch(M=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",M)}),K.requestAgentStatuses().then(M=>{if(Le.getState().selectedProxyId!==O)return;const F=$t.getState();for(const B of M)F.setAgentStatus(B.sessionId,B.payload)}).catch(M=>{console.error("[proxy-switcher] post-bind data fetch failed",M)}),X1(K).then(M=>{M.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",M.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/"))&&u("/sessions")}catch(z){const M=z instanceof Error?z.message:"未知错误";Xe.error(`无法连接 ${U}:${M}`)}finally{Le.getState().setProxySwitchTarget(null)}}function k(O){O.online||w||(y(null),_({proxyId:O.proxyId,...O.name?{name:O.name}:{}}))}async function T(){const O=v;if(!O||w)return;const D=Ut;if(!D){Xe.error("Relay 连接不可用,请稍后重试");return}const K=Le.getState().proxies.find(U=>U.proxyId===O.proxyId);if(!K){if(!Le.getState().proxyListLoaded){Xe.info("正在重新连接 Relay,请稍后再试");return}Sh(O.proxyId,D)&&u("/"),Xe.info("这台开发机已经不在列表中"),_(null);return}if(K.online){Xe.warning("这台开发机已重新上线,未移除"),_(null);return}S(O.proxyId),vJ(O.proxyId);try{const U=await D.removeOfflineProxy(O.proxyId);if(U.success){ed(O.proxyId),Sh(O.proxyId,D)&&u("/"),Xe.success(`已移除 ${O.name??O.proxyId}`),_(null);return}if(U.errorCode===vr.PROXY_ONLINE){ed(O.proxyId),Xe.warning("这台开发机已重新上线,未移除"),_(null),D.listProxies();return}if(U.errorCode===vr.PROXY_NOT_FOUND){ed(O.proxyId),Sh(O.proxyId,D)&&u("/"),Xe.info("这台开发机已经不在列表中"),_(null),D.listProxies();return}ed(O.proxyId),Xe.error(U.error??"无法移除开发机,请重试")}catch(U){Xe.error(U instanceof Error?U.message:"无法移除开发机,请重试"),D.listProxies()}finally{S(null)}}const R=m.jsx(moe,{open:v!==null,target:v,removing:w!==null,onOpenChange:O=>{O||_(null)},onConfirm:()=>void T()});if(e==="page")return i==="missing_client_token"?m.jsx(Sc,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(Sc,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(Sc,{variant:"no-proxy"}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex h-full flex-col gap-3 overflow-auto p-4",children:[m.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"开发机"}),m.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(O=>{const D=(o==null?void 0:o.proxyId)===O.proxyId,K=o!==null;return O.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":O.proxyId,"data-online":"true","data-selecting":D||void 0,disabled:K||w!==null,"aria-busy":D||void 0,onClick:()=>x(O.proxyId,O.name),className:Ye("flex h-11 min-h-[44px] w-full items-center gap-3 rounded-md border bg-card px-3 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-card",D?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",K&&!D||w!==null?"opacity-50":""),"aria-pressed":s===O.proxyId,children:[m.jsx(DS,{status:"online"}),m.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-normal",children:O.name??O.proxyId}),D?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"正在连接"}),m.jsx(Mo,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===O.proxyId?m.jsx(Lo,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},O.proxyId):m.jsx(yoe,{proxyId:O.proxyId,name:O.name,selected:s===O.proxyId,revealed:p===O.proxyId,disabled:K||w!==null,onRevealedChange:U=>y(U?O.proxyId:null),onRemove:()=>k(O)},O.proxyId)})})]}),R]}):m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[m.jsx(Mo,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const N=n.find(O=>O.proxyId===s),A=(N==null?void 0:N.name)??(N==null?void 0:N.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(PE,{open:d,onOpenChange:f,children:[m.jsx(OE,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${A}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx("span",{className:Ye("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:A}),m.jsx(Ol,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(LE,{align:"start",className:"w-[260px] p-1",children:n.length===0?m.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):m.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(O=>{const D=(o==null?void 0:o.proxyId)===O.proxyId,K=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":O.proxyId,"data-online":O.online,"data-selecting":D||void 0,disabled:!O.online||K,"aria-busy":D||void 0,onClick:()=>x(O.proxyId,O.name),className:Ye("flex h-9 min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",D?"bg-accent text-accent-foreground":"hover:bg-accent",K&&!D?"opacity-50":"",O.online?"":"opacity-50"),"aria-pressed":s===O.proxyId,title:O.online?void 0:"这台开发机离线",children:[m.jsx(DS,{status:O.online?"online":"offline"}),m.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:O.name??O.proxyId}),D?m.jsx(Mo,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===O.proxyId?m.jsx(Lo,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!O.online&&!D&&m.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]}),!O.online&&m.jsxs(Ey,{children:[m.jsx(Cy,{asChild:!0,children:m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:K||w!==null,"aria-label":`${O.name??O.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(A1,{"aria-hidden":"true"})})}),m.jsx(ky,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(Js,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:U=>{U.stopPropagation(),k(O)},children:[m.jsx(O1,{"aria-hidden":"true"}),"移除开发机"]})})]})]},O.proxyId)})})})]}),R]})}function boe({delayDuration:e=0,...t}){return m.jsx(eoe,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function bp({...e}){return m.jsx(toe,{"data-slot":"tooltip",...e})}function _p({...e}){return m.jsx(noe,{"data-slot":"tooltip-trigger",...e})}function wp({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(roe,{children:m.jsxs(ioe,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(soe,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Ty({...e}){return m.jsx(cE,{"data-slot":"sheet",...e})}function _oe({...e}){return m.jsx(Jte,{"data-slot":"sheet-trigger",...e})}function woe({...e}){return m.jsx(uE,{"data-slot":"sheet-portal",...e})}function Soe({className:e,...t}){return m.jsx(dE,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ry({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return m.jsxs(woe,{children:[m.jsx(Soe,{className:t}),m.jsxs(fE,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&m.jsxs(ay,{"data-slot":"sheet-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[m.jsx(jc,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function DE({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function Ay({className:e,...t}){return m.jsx(iz,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function xoe({className:e,...t}){return m.jsx(sz,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}const Eoe={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"},GN=["claude","codex","kimi"];function My(e){return Eoe[e]}function o5(e,t){return GN.indexOf(e)-GN.indexOf(t)}function Wh(e){return e.provider??"claude"}const IS=60*1e3,BS=60*IS,Coe=24*BS;function a5(e,t=Date.now()){const n=t-e;if(n<IS)return"刚刚";if(n<BS)return`${Math.floor(n/IS)} 分钟前`;if(n<Coe)return`${Math.floor(n/BS)} 小时前`;const r=new Date(e),i=r.getMonth()+1,s=r.getDate(),o=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0");return`${i} 月 ${s} 日 ${o}:${l}`}const ZN={idle:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"空闲"},working:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"工作中"},compacting:{dot:"bg-[var(--color-status-compacting)] animate-pulse",text:"text-[var(--color-status-compacting)]",label:"压缩中"},waiting_approval:{dot:"bg-[var(--color-status-warning)]",text:"text-[var(--color-status-warning)]",label:"等待审批"},error:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"出错"},terminated:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已终止"}};function zS(e){return e.kind!=="terminal"?ZN[e.state]:e.state==="terminated"?ZN.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function koe({session:e}){const t=zS(e);return m.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Toe({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?M1:P1;return m.jsx("span",{className:"inline-flex h-5 w-4 shrink-0 items-center justify-center text-muted-foreground",role:"img","aria-label":t,title:t,"data-slot":"session-mode-icon","data-mode":e,children:m.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Roe({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=ny(e.name),d=eE(e),f=e.nameLocked&&e.name?e.name:d||(u==="New Session"?e.sessionId.slice(0,8):u),p=!!e.mode||!!e.provider||o!==void 0,y=o!==void 0?a5(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return m.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&m.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),m.jsxs("button",{type:"button","data-slot":"session-row-select",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx(koe,{session:e}),m.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:f})]}),p&&m.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&m.jsx(Toe,{mode:e.mode}),e.mode&&m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:My(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:Ye("shrink-0",zS(e).text),children:zS(e).label}),y&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&m.jsxs(Ey,{children:[m.jsx(Cy,{asChild:!0,children:m.jsx(Ct,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:m.jsx(A1,{"aria-hidden":"true"})})}),m.jsxs(ky,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(Js,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(Js,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function Al(e){const[t,n]=b.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return b.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function Aoe({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Moe,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:a5(e.updatedAt,t)}),u=m.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return m.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:m.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(gW,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Moe({title:e,modeTag:t}){return m.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[m.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&m.jsx(Noe,{mode:t})]})}function Noe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?M1:P1;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function l5({providerLabel:e}){return m.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:m.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[m.jsx(G7,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),m.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Poe({now:e}){const t=$t(X=>X.historySessions),n=$t(X=>X.historyLoadStatus),[r,i]=b.useState(null),[s,o]=b.useState(null),[l,u]=b.useState("json"),[d,f]=b.useState("default"),[p,y]=b.useState(!1),[v,_]=b.useState(new Set),[w,S]=b.useState(new Set),x=oo(),k=b.useMemo(()=>{const X=new Map;for(const z of t){const M=Wh(z);let F=X.get(M);F||(F=new Map,X.set(M,F));const B=c5(z.projectDir),P=F.get(B);P?P.sessions.push(z):F.set(B,{dir:B,sessions:[z]})}return Array.from(X.entries()).sort(([z],[M])=>o5(z,M)).map(([z,M])=>({provider:z,sessions:Array.from(M.values()).flatMap(F=>F.sessions),projects:Array.from(M.values()).map(F=>({dir:F.dir,shortDir:ny(F.dir),sessions:F.sessions}))}))},[t]);function T(X){o(X),u(Ooe(X)),f(Loe(X))}async function R(X,z,M){if(r)return;const F=Ut;if(!F){Xe.error("请先连接开发机");return}i(X.id);const B=Wh(X);try{const P=await F.createSession({cwd:X.projectDir,mode:z,provider:B,resumeSessionId:X.id,...M?{permissionMode:M}:{}});if(P.error||!P.sessionId){if(P.errorCode===vr.SESSION_ALREADY_ACTIVE){$t.getState().setCodexActiveWriterConflict({...P.activeWriterPid?{activeWriterPid:P.activeWriterPid}:{}}),o(null);return}Xe.error(`恢复失败:${P.error??"未知错误"}`);return}const I={sessionId:P.sessionId,...P.kind!==void 0?{kind:P.kind}:{},...P.name!==void 0?{name:P.name}:{},...P.nameLocked!==void 0?{nameLocked:P.nameLocked}:{},state:"idle",mode:P.mode??z,provider:P.provider??"claude",...P.ptyOwner!==void 0?{ptyOwner:P.ptyOwner}:{}};$t.getState().addSession(I),x(`/chat/${P.sessionId}?mode=${P.mode??z}`),o(null)}catch(P){Xe.error(`恢复失败:${P instanceof Error?P.message:String(P)}`)}finally{i(null)}}function N(){const X=Ut;!X||$t.getState().historyLoadStatus==="loading"||X1(X).then(z=>{z.status==="failed"&&Xe.error(z.error instanceof Error?z.error.message:String(z.error))})}function A(X,z){const M=QN(X,z);S(F=>{const B=new Set(F);return B.has(M)?B.delete(M):B.add(M),B})}function O(X){_(z=>{const M=new Set(z);return M.has(X)?M.delete(X):M.add(X),M})}const D=t.length>0,K=n==="loading",U=s?u5():[];return m.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[m.jsxs("div",{className:"flex min-h-11 w-full items-center gap-1.5 px-4 py-1.5 md:min-h-[36px]",children:[m.jsxs("button",{type:"button",onClick:()=>D&&y(X=>!X),disabled:!D,"aria-expanded":D?p:void 0,"data-slot":"history-section-header","data-expanded":p,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",D?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),D?m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",p&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":K,title:K?"正在加载":"刷新",onClick:N,disabled:K,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(N1,{className:Ye("size-3.5",K&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!D&&K&&m.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-loading",role:"status","aria-live":"polite",children:[m.jsx(Mo,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!D&&n==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!D&&n==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),D&&n==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!D&&n==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),D&&p&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(X=>{const z=v.has(X.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>O(X.provider),"aria-expanded":!z,"data-slot":"history-provider-header","data-expanded":!z,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:My(X.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:X.sessions.length}),m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!z&&"rotate-90"),"aria-hidden":"true"})]}),!z&&m.jsx("ul",{role:"list",className:"flex flex-col",children:X.projects.map(M=>{const F=QN(X.provider,M.dir),B=w.has(F);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>A(X.provider,M.dir),"aria-expanded":B,"data-slot":"history-group-header","data-expanded":B,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),m.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",B&&"rotate-90"),"aria-hidden":"true"})]}),B&&m.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(P=>m.jsx(Aoe,{session:P,now:e,disabled:r!==null,loading:r===P.id,onClick:()=>T(P),modeTag:P.preferredMode},P.id))})]},F)})})]},X.provider)})}),m.jsx(Doe,{session:s,open:s!==null,modes:U,mode:l,permissionMode:d,submitting:r!==null,onOpenChange:X=>{X||o(null)},onModeChange:u,onPermissionModeChange:f,onConfirm:()=>{s&&R(s,l,d)}})]})}function QN(e,t){return`${e}:${c5(t)}`}function c5(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function u5(){return["json","pty"]}function Ooe(e){const t=u5();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Loe(e){return Wh(e)==="codex"?"auto":"default"}function Doe({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[f,p]=b.useState(!1),y=i==="bypassPermissions",v=Al("(min-width: 768px)"),_=e?Wh(e):null,w=_==="codex",S=_==="kimi";b.useEffect(()=>{t||p(!1)},[t]);const x=f?m.jsx(l5,{providerLabel:e?My(Wh(e)):"Agent"}):m.jsxs("div",{className:"grid min-w-0 gap-4",children:[m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&m.jsx(JN,{checked:r==="json",label:"聊天",icon:m.jsx(M1,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(JN,{checked:r==="pty",label:"终端",icon:m.jsx(P1,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[!w&&m.jsx(fg,{checked:i==="default",label:S?"手工审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),m.jsx(fg,{checked:i==="auto",label:w?"按需审批":S?"自动审批":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),S&&m.jsx(fg,{checked:i==="plan",label:"只读规划",description:"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(fg,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(Ct,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?p(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(Ct,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(y&&!f){p(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return v?m.jsx(xa,{open:t,onOpenChange:o,children:m.jsxs(Ea,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Ca,{className:"min-w-0",children:[m.jsx(Io,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(_a,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),x,m.jsx(Rl,{children:k})]})}):m.jsx(Ty,{open:t,onOpenChange:o,children:m.jsxs(Ry,{side:"bottom",focusSurfaceOnOpen:!0,className:"inset-x-2 w-auto max-h-[calc(100dvh-0.75rem)] min-w-0 overflow-hidden rounded-t-xl border bg-background p-0","data-slot":"history-restore-dialog",children:[m.jsxs(DE,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(Ay,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(xoe,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),m.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:x}),m.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:m.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:k})})]})})}function JN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(Lo,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function fg({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),m.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&m.jsx(Lo,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Ioe({...e}){return m.jsx(Tse,{"data-slot":"select",...e})}function Boe({...e}){return m.jsx(Ase,{"data-slot":"select-value",...e})}function zoe({className:e,size:t="default",children:n,...r}){return m.jsxs(Rse,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(Mse,{asChild:!0,children:m.jsx(Ol,{className:"size-4 opacity-50"})})]})}function joe({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return m.jsx(Nse,{children:m.jsxs(Pse,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[m.jsx(Foe,{}),m.jsx(Ose,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(Hoe,{})]})})}function $oe({className:e,children:t,...n}){return m.jsxs(Lse,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(Ise,{children:m.jsx(Lo,{className:"size-4"})})}),m.jsx(Dse,{children:t})]})}function Foe({className:e,...t}){return m.jsx(Bse,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(T1,{className:"size-4"})})}function Hoe({className:e,...t}){return m.jsx(zse,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(Ol,{className:"size-4"})})}function IE(e){return!e||e.endsWith("/")?e:`${e}/`}function Uoe(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function Woe(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function qoe(e,t,n){var o;if(t==="insert")return{currentPath:Woe(e)||"./",query:Uoe(e)};if(!e)return{currentPath:"./",query:""};const r=e.replace(/\/+$/,"")||"/";if(e.endsWith("/")||r===(n==null?void 0:n.baseCwd)||((o=n==null?void 0:n.knownDirs)==null?void 0:o.has(r)))return{currentPath:IE(r),query:""};const s=e.lastIndexOf("/");return{currentPath:s>=0?e.slice(0,s+1):"./",query:s>=0?e.slice(s+1).toLowerCase():e.toLowerCase()}}function Yoe(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function Voe(e,t){return`${IE(e)}${t.name}${t.isDir?"/":""}`}function e2(e,t){const n=e.trim().replace(/\/+$/,"")||"/",r=t.trim().replace(/^\/+|\/+$/g,"");return!n.startsWith("/")||!r||t.trim().startsWith("/")||r.split("/").some(i=>i===""||i==="."||i==="..")?null:n==="/"?`/${r}`:`${n}/${r}`}const d5=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ni(j=>j.tree),f=ni(j=>j.cwd),p=ni(j=>j.homePath),y=i==="insert"?f:p||f,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>qoe(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,S=b.useMemo(()=>Yoe(y,w),[y,w]),x=_.query,k=b.useRef(new Set),[T,R]=b.useState(!1),[N,A]=b.useState(""),[O,D]=b.useState(!1);b.useEffect(()=>{if(!S||d.has(S)||k.current.has(S))return;const j=Ut;if(!j)return;let L=!1;return k.current.add(S),j.requestDirectoryList(S).then(Y=>{L||ni.getState().setDirEntries(Y.path,Y.entries)}).catch(()=>{L||ni.getState().setDirEntries(S,[])}).finally(()=>{k.current.delete(S)}),()=>{L=!0}},[S,d]);const K=!d.has(S),U=b.useMemo(()=>{let j=d.get(S)??[];return o&&(j=j.filter(L=>L.isDir)),x&&(j=j.filter(L=>L.name.toLowerCase().includes(x))),j},[d,S,x,o]),[X,z]=b.useState(0);b.useEffect(()=>z(0),[w,x]),b.useEffect(()=>{R(!1),A("")},[S]),b.useEffect(()=>{X>=U.length&&U.length>0&&z(U.length-1)},[U.length,X]);const M=b.useRef(null),F=b.useRef(!1);b.useEffect(()=>{var L;if(!F.current)return;F.current=!1;const j=(L=M.current)==null?void 0:L.querySelector(`[data-entry-index="${X}"]`);j==null||j.scrollIntoView({block:"nearest"})},[X]);const B=b.useCallback(j=>{const L=Voe(w,j);return i==="insert"?L.replace(/^\.\//,""):L},[w,i]);async function P(){const j=e2(S,N);if(!(!j||!r)){D(!0);try{const L=await r(j);if(!L)return;A(""),R(!1),n(IE(L))}finally{D(!1)}}}b.useImperativeHandle(u,()=>({handleKey(j){return U.length===0?!1:j.key==="ArrowDown"?(F.current=!0,z(L=>Math.min(U.length-1,L+1)),!0):j.key==="ArrowUp"?(F.current=!0,z(L=>Math.max(0,L-1)),!0):j.key==="Enter"&&!j.nativeEvent.isComposing?(n(B(U[X])),!0):!1}}),[U,X,B,n]);const I=s==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":i==="insert"?"absolute bottom-full left-0 right-0 z-50 mb-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden":"absolute left-0 right-0 top-full z-50 mt-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden",W=s==="inline"?"h-44 overflow-y-auto overscroll-contain":i==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return m.jsxs("div",{className:I,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?m.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?m.jsx("button",{type:"button",className:"rounded px-2 py-1 text-xs text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",disabled:!S||O,onClick:()=>R(j=>!j),children:"新建目录"}):null]}),T?m.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[m.jsx("input",{type:"text",value:N,onChange:j=>A(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.nativeEvent.isComposing&&(j.preventDefault(),P()),j.key==="Escape"&&(R(!1),A(""))},placeholder:"目录名称",className:"min-h-11 min-w-0 flex-1 rounded-md border border-border bg-input px-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-8 md:min-h-0 md:text-sm",autoComplete:"off",autoCorrect:"off",spellCheck:!1}),m.jsx("button",{type:"button",className:"min-h-11 rounded-md bg-primary px-3 text-sm text-primary-foreground disabled:cursor-not-allowed disabled:opacity-50 md:h-8 md:min-h-0",disabled:!e2(S,N)||O,onClick:()=>void P(),children:O?"创建中...":"创建目录"})]}):null]}):null,m.jsx("div",{className:W,children:U.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:K?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map((j,L)=>m.jsx("li",{children:m.jsx("button",{type:"button",onClick:()=>n(B(j)),onMouseEnter:()=>z(L),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",L===X&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",j.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":j.isDir?"dir":"file","data-entry-index":L,children:m.jsxs("span",{className:"font-mono text-[13px]",children:[j.name,j.isDir?"/":""]})})},j.name))})})]})}),t2="工作目录不存在或不可访问:",Koe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],f5=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],h5=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],ma={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"};function Xoe(e,t){return t!==vr.PATH_NOT_FOUND||!e.startsWith(t2)?null:e.slice(t2.length).trim()||null}function xh(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n?n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}:{label:"未检测",disabled:!0}}function Goe(e,t){return t.title?t.disabled?`${ma[e]}:${t.title}`:`${ma[e]} 路径:${t.title}`:`${ma[e]}:${t.label}`}function Zoe(e,t){return e==="codex"?f5.some(n=>n.value===t)?t:"auto":e==="kimi"?h5.some(n=>n.value===t)?t:"default":t}async function Qoe({relay:e,agentCli:t,form:n,timeoutMs:r=V1}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(xh(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${ma[n.provider]} 不可用:${p}`:`${ma[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=Xoe(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,v=((f=p.name)==null?void 0:f.trim())||void 0;return{type:"success",session:{sessionId:p.sessionId,...p.kind!==void 0?{kind:p.kind}:{},name:v,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",mode:y,provider:p.provider??l,...p.ptyOwner!==void 0?{ptyOwner:p.ptyOwner}:{}},route:`/chat/${p.sessionId}?mode=${y}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function Joe({relay:e,timeoutMs:t=V1}){var n;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const r=await e.createSession({kind:"terminal",mode:"pty"},t);return r.error||!r.sessionId?{type:"create_error",message:`创建终端失败:${r.error??"未知错误"}`}:{type:"success",session:{sessionId:r.sessionId,kind:"terminal",name:((n=r.name)==null?void 0:n.trim())||void 0,...r.nameLocked!==void 0?{nameLocked:r.nameLocked}:{},state:"idle",mode:"pty",provider:r.provider??"claude",...r.ptyOwner!==void 0?{ptyOwner:r.ptyOwner}:{}},route:`/chat/${r.sessionId}?mode=pty`}}catch(r){return{type:"exception",message:r instanceof Error?r.message:String(r)}}}function eae({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:f}){const p=xh("claude",e),y=xh("codex",e),v=xh("kimi",e),_=e==null?void 0:e[t];return m.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsx("span",{className:"text-sm",children:"Agent CLI"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-3",children:[m.jsx(Bw,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),m.jsx(Bw,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")}),m.jsx(Bw,{provider:"kimi",selected:t==="kimi",status:v,agentCliLoaded:!!e,onClick:()=>o("kimi")})]}),m.jsx("div",{className:"relative min-w-0 rounded-md border border-border bg-muted/20 px-3 py-2.5 md:p-3","data-slot":"agent-cli-path-card",children:r===t?m.jsx(tae,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:f}):m.jsx(nae,{provider:t,selectedCli:_,isDesktop:n,onOpenCliPathEditor:l})})]})}function Bw({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return m.jsxs(bp,{children:[m.jsx(_p,{asChild:!0,children:m.jsxs("button",{type:"button","aria-pressed":t,"aria-label":ma[e],onClick:i,className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:ma[e]}),m.jsx("span",{className:Ye("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),m.jsx(wp,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:m.jsx("span",{className:"break-all font-mono text-xs",children:Goe(e,n)})})]})}function tae({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){var l;return m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),m.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[m.jsxs("label",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"sr-only",children:"CLI 路径"}),m.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),o()),u.key==="Escape"&&(u.preventDefault(),s())},placeholder:`/path/to/${e==="kimi"?"kimi":e}`,className:"min-h-11 w-full rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-10 md:min-h-0 md:text-sm"}),m.jsx("datalist",{id:`agent-cli-path-${e}`,children:(((l=t==null?void 0:t[e])==null?void 0:l.suggestions)??[]).map(u=>m.jsx("option",{value:u},u))})]}),m.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[m.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground md:h-8 md:min-h-0",onClick:s,disabled:r,children:"取消"}),m.jsx(Ct,{type:"button",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium md:h-8 md:min-h-0",onClick:o,disabled:r||!n.trim(),children:r?"保存中...":"保存路径"})]})]})]})}function nae({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),m.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[m.jsx("p",{className:Ye("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),m.jsx(Ct,{type:"button",variant:"outline",className:"h-8 min-h-0 shrink-0 self-end rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground sm:self-auto",onClick:()=>r(e),children:"指定路径"})]})]}):m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 size-11 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/70 hover:text-foreground","aria-label":"指定路径",onClick:()=>r(e),children:m.jsx(k7,{className:"size-4","aria-hidden":"true"})}),m.jsx("p",{className:Ye("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function lh({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,p]=b.useState("default"),[y,v]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[k,T]=b.useState(!1),[R,N]=b.useState(null),[A,O]=b.useState(""),[D,K]=b.useState(!1),U=b.useRef(null),X=b.useRef(e);X.current=e;const z=oo(),M=ni(me=>me.homePath),F=ni(me=>me.agentCli),B=Al("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&F)return;const me=Ut==null?void 0:Ut.requestProxyInfo();me&&me.then(Ee=>{const De=ni.getState();De.setHomePath(Ee.homePath),De.setAgentCli(Ee.agentCli)}).catch(Ee=>{console.error("[create-session-dialog] requestProxyInfo failed",Ee)})},[e,M,F]),b.useEffect(()=>{if(!k)return;function me(Ee){var Se;const De=Ee.target;De instanceof Node&&((Se=U.current)!=null&&Se.contains(De))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",me,!0),()=>document.removeEventListener("pointerdown",me,!0)},[k]);function P(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),v(!1),x(null),N(null),O(""),K(!1)}function I(){if(f==="bypassPermissions"){v(!0);return}$()}async function W(){await $(),X.current&&v(!1)}const j=o==="codex"?f5:o==="kimi"?h5:Koe,L=xh(o,F),Y=_||D||L.disabled;function V(me){const Ee=Zoe(me,f);Ee!==f&&p(Ee)}async function $(me){x(null),w(!0);try{const Ee=await Qoe({relay:Ut,agentCli:F,form:{cwd:me??i,name:n,provider:o,permissionMode:f,mode:u}});if(Ee.type==="success"){if($t.getState().addSession(Ee.session),!X.current)return;t(!1),P(),z(Ee.route);return}if(Ee.type==="missing_cwd"&&x(Ee.path),Xe.error(Ee.message),Ee.type==="validation_error"||Ee.type==="relay_missing")return}finally{w(!1)}}async function te(me){const Ee=Ut;if(!Ee)return Xe.error("请先连接开发机"),null;try{const De=await Ee.createDirectory(me);return De.success?(s(De.path),x(null),Xe.success("目录已创建"),De.path):(Xe.error(`目录创建失败:${De.error??"未知错误"}`),null)}catch(De){return Xe.error(De instanceof Error?De.message:String(De)),null}}function re(me){var De;const Ee=F==null?void 0:F[me];N(me),O((Ee==null?void 0:Ee.command)??((De=Ee==null?void 0:Ee.suggestions)==null?void 0:De[0])??"")}async function oe(){if(!R)return;const me=A.trim();if(!me){Xe.error("请输入 Agent CLI 路径");return}const Ee=Ut;if(!Ee){Xe.error("请先连接开发机");return}K(!0);try{const De=await Ee.updateAgentCliPath(R,me);if(De.error||!De.agentCli){Xe.error(`路径保存失败:${De.error??"未知错误"}`);return}ni.getState().setAgentCli(De.agentCli),Xe.success(`${ma[R]} 路径已保存`),N(null),O("")}catch(De){Xe.error(De instanceof Error?De.message:String(De))}finally{K(!1)}}function ee(me){d(me),V(o)}function pe(me){var De;const Ee=me.relatedTarget;Ee instanceof Node&&((De=U.current)!=null&&De.contains(Ee))||window.setTimeout(()=>T(!1),0)}const ae=y?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(l5,{providerLabel:ma[o]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),m.jsx(Ct,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void W(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:me=>{me.preventDefault(),I()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:me=>r(me.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),m.jsxs("div",{ref:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:pe,children:[m.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),m.jsx("input",{id:"create-session-cwd",type:"text","aria-labelledby":"create-session-cwd-label",name:"dev-anywhere-session-cwd",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:i,onFocus:()=>T(!0),onChange:me=>{s(me.target.value),x(null)},placeholder:"输入绝对路径",className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm"}),k?m.jsx(d5,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:te,onSelect:me=>{s(me),x(null),T(!0)}}):null]}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>ee("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>ee("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(eae,{agentCli:F,provider:o,isDesktop:B,editingCliProvider:R,cliPathInput:A,savingCliPath:D,onProviderChange:me=>{l(me),V(me)},onOpenCliPathEditor:re,onCliPathInputChange:O,onCancelCliPathEditor:()=>{N(null),O("")},onSaveCliPath:()=>void oe()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(Ioe,{value:f,onValueChange:me=>p(me),children:[m.jsx(zoe,{className:"w-full",children:m.jsx(Boe,{})}),m.jsx(joe,{children:j.map(me=>m.jsx($oe,{value:me.value,children:me.label},me.value))})]})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(Ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return B?m.jsx(xa,{open:e,onOpenChange:t,children:m.jsxs(Ea,{className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[44rem]","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[m.jsx(Ca,{children:m.jsx(Io,{children:y?"跳过全部审批?":"新建会话"})}),ae]})}):m.jsx(Ty,{open:e,onOpenChange:t,children:m.jsxs(Ry,{side:"bottom",className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto overflow-x-hidden overflow-y-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[m.jsx(DE,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(Ay,{children:y?"跳过全部审批?":"新建会话"})}),ae]})})}function ch({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=b.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=b.useState(s),[u,d]=b.useState(null),[f,p]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(v){v.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return m.jsx(xa,{open:e,onOpenChange:r,children:m.jsx(Ea,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>void y(v),children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"重命名会话"}),m.jsx(_a,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),m.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:f,onChange:v=>{l(v.target.value),u&&d(null)}}),u?m.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(Ct,{type:"submit",disabled:f,children:"保存"})]})]})})})}function rae(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function iae(e){return(e==null?void 0:e.kind)==="terminal"}function sae(e){return rae(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:iae(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function hg({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=sae(t);function s(){t&&(r(t),n(!1))}return m.jsx(xa,{open:e,onOpenChange:n,children:m.jsxs(Ea,{"data-slot":"session-termination-dialog",children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:i.title}),m.jsx(_a,{children:i.description})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(Ct,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function p5(e){var t,n,r,i,s,o,l,u,d,f,p,y;return e.connected===!1||e.proxyOnline===!1?"disconnected":e.routeSessionEnded||((t=e.session)==null?void 0:t.state)==="terminated"?"terminated":((n=e.session)==null?void 0:n.state)==="error"?"error":e.hasPendingApproval||((r=e.session)==null?void 0:r.state)==="waiting_approval"?"waiting_approval":((i=e.session)==null?void 0:i.state)==="compacting"?"compacting":((s=e.session)==null?void 0:s.state)==="working"?"working":((o=e.session)==null?void 0:o.state)==="idle"?"idle":((l=e.agentStatus)==null?void 0:l.phase)==="waiting_permission"||((u=e.ptyState)==null?void 0:u.state)==="approval_wait"?"waiting_approval":((d=e.agentStatus)==null?void 0:d.phase)==="thinking"||((f=e.agentStatus)==null?void 0:f.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function oae(e){if(e.session.state==="error")return"error";const t=p5(e);return t==="disconnected"?e.session.state:t}function m5({layout:e}){const t=$t(te=>te.sessions),n=$t(te=>te.sessionListLoaded),r=$t(te=>te.agentStatusBySessionId),i=$t(te=>te.ptyStateBySessionId),s=$t(te=>te.renameSession),o=Xt(te=>te.bySessionId),l=Y8("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Le(te=>!!te.selectedProxyId),f=Le(te=>te.proxyListLoaded),p=Le(te=>te.proxySwitchTarget),y=$t(te=>te.loadingProxyName),v=p!==null||!f||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",S=oo(),[x,k]=b.useState(!1),[T,R]=b.useState(!1),[N,A]=b.useState(null),[O,D]=b.useState(null),{creatingTerminal:K,createTerminal:U}=g5(),[X,z]=b.useState(new Set),[M,F]=b.useState(()=>Date.now());b.useEffect(()=>{const te=setInterval(()=>F(Date.now()),6e4);return()=>clearInterval(te)},[]);function B(te,re){S(`/chat/${te}?mode=${re??"json"}`,{replace:!1})}function P(te){const re=te.sessionId,oe=Ut;if(!oe){Xe.error("请先连接开发机");return}oe.sendControl({type:"session_terminate",sessionId:re}),$t.getState().removeSession(re),Xt.getState().clearSession(re),re===u&&S("/sessions"),(te==null?void 0:te.mode)==="pty"&&te.ptyOwner==="local-terminal"?Xe.info("已断开页面连接,本地终端仍在运行"):Xe.info("正在终止会话",{duration:1500})}async function I(te,re){const oe=Ut;if(!oe)throw new Error("请先连接开发机");const ee=await oe.renameSession(te,re);if(!ee.success)throw new Error(ee.error??"重命名失败");s(te,ee.name??re),Xe.success("已重命名会话")}function W(te){z(re=>{const oe=new Set(re);return oe.has(te)?oe.delete(te):oe.add(te),oe})}function j(te){var ee;const re=te.mode==="json"&&(((ee=o[te.sessionId])==null?void 0:ee.pendingApprovals.some(pe=>pe.status==="pending"))??!1),oe=oae({session:te,agentStatus:r[te.sessionId],ptyState:i[te.sessionId],hasPendingApproval:re});return oe===te.state?te:{...te,state:oe}}const L=t.length>0;if(e==="sidebar"&&(v||!d))return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":v?"session-list-loading":void 0,role:v?"status":void 0,"aria-live":v?"polite":void 0,children:v?w:"请先连接开发机"}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]});if(e==="page"&&v)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[m.jsx(Mo,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsx("div",{className:"flex-1",children:m.jsx(Sc,{variant:"no-proxy"})}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]});const Y=m.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",L?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),V=L?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:aae(t).map(te=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>W(te.provider),"aria-expanded":!X.has(te.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:lae(te.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:te.sessions.length}),m.jsx(_h,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!X.has(te.provider)&&"rotate-90"),"aria-hidden":"true"})]}),X.has(te.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:te.sessions.map(re=>m.jsx(Roe,{session:j(re),selected:re.sessionId===u,now:M,onClick:()=>B(re.sessionId,re.mode),onRename:()=>A(re),onTerminate:()=>D(re)},re.sessionId))})]},te.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),$=m.jsx(Poe,{now:M});return e==="page"?m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,V,$]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(Ct,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>R(!0),children:[m.jsx(GD,{"aria-hidden":"true"}),"新建"]})}),m.jsx(uae,{open:T,creatingTerminal:K,onOpenChange:R,onCreateAgent:()=>{R(!1),k(!0)},onCreateTerminal:()=>void U(()=>R(!1))}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,V,$]}),m.jsx(lh,{open:x,onOpenChange:k}),m.jsx(hg,{open:O!==null,session:O,onOpenChange:te=>{te||D(null)},onConfirm:P}),m.jsx(ch,{open:N!==null,sessionId:(N==null?void 0:N.sessionId)??null,initialName:N==null?void 0:N.name,onOpenChange:te=>{te||A(null)},onRename:I})]})}function aae(e){const t=new Map;for(const n of e){const r=n.kind==="terminal"?"terminal":n.provider,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t.entries()).sort(([n],[r])=>cae(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function lae(e){return e==="terminal"?"终端":My(e)}function cae(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:o5(e,t)}function g5(){const e=oo(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await Joe({relay:Ut});if(s.type!=="success"){Xe.error(s.message);return}$t.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function n2({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Le(x=>!!x.selectedProxyId),l=Le(x=>x.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:f}=g5();function p(){i(!0),window.setTimeout(()=>i(!1),2e3)}function y(){if(!u){p();return}s.current=!0,n(!0)}function v(){if(!u){p();return}s.current=!0,f()}function _(x){x.preventDefault(),p()}const w=m.jsxs(Ct,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!u&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!u,onClick:u?void 0:_,children:[m.jsx(GD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),S=u?m.jsxs(Ey,{children:[m.jsx(Cy,{asChild:!0,children:w}),m.jsxs(ky,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:x=>{s.current&&(s.current=!1,x.preventDefault())},children:[m.jsxs(Js,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[m.jsx(XD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(Js,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[m.jsx(Dh,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return m.jsxs(m.Fragment,{children:[u?S:m.jsxs(bp,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[m.jsx(_p,{asChild:!0,children:S}),m.jsx(wp,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),m.jsx(lh,{open:t,onOpenChange:n})]})}function uae({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=b.useRef(!1);function o(l){s.current=!0,l()}return m.jsx(Ty,{open:e,onOpenChange:n,children:m.jsxs(Ry,{side:"bottom",overlayClassName:"bg-black/10 dark:bg-black/30",className:"inset-x-2 w-auto rounded-t-xl border border-border/80 bg-background px-3 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3 shadow-2xl","data-slot":"create-session-type-sheet",focusSurfaceOnOpen:!0,onCloseAutoFocus:l=>{s.current&&(s.current=!1,l.preventDefault())},children:[m.jsx(DE,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(Ay,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(Ct,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-agent-session-sheet-item",onClick:()=>o(r),children:[m.jsx(XD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(Ct,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-terminal-session-sheet-item",disabled:t,onClick:()=>o(i),children:[m.jsx(Dh,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const dae="0.8.1",fae={version:dae},hae={playback:"playback",capture:"play-and-record"};function pae(){return typeof navigator>"u"?null:navigator.audioSession??null}function mae(){return{setMode:()=>{},release:()=>{}}}class gae{constructor(t=pae){_t(this,"leases",new Map);_t(this,"session",null);_t(this,"baselineType",null);_t(this,"nextLeaseId",1);_t(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return mae();this.leases.size===0&&(this.session=n,this.baselineType=n.type);const r=this.nextLeaseId++;this.leases.set(r,{mode:t,order:this.nextOrder++});try{this.applyActiveMode()}catch(s){throw this.leases.delete(r),this.leases.size===0?this.restoreWhenUnused():this.applyActiveModeBestEffort(),s}let i=!1;return{setMode:s=>{if(i)return;const o=this.leases.get(r);if(!o)return;const l={...o};o.mode=s,o.order=this.nextOrder++;try{this.applyActiveMode()}catch(u){throw this.leases.set(r,l),this.applyActiveModeBestEffort(),u}},release:()=>{if(!i){if(i=!0,this.leases.delete(r),this.leases.size===0){this.restoreWhenUnused();return}this.applyActiveModeBestEffort()}}}}applyActiveMode(){const t=[...this.leases.values()].reduce((n,r)=>!n||r.order>n.order?r:n,null);!t||!this.session||this.setNativeType(hae[t.mode])}applyActiveModeBestEffort(){try{this.applyActiveMode()}catch{}}restoreWhenUnused(){const t=this.session,n=this.baselineType;if(this.session=null,this.baselineType=null,!(!t||n===null))try{t.type=n}catch{}}setNativeType(t){if(!(!this.session||this.session.type===t)){try{this.session.type=t}catch{throw new Error("浏览器无法切换语音音频模式")}if(this.session.type!==t)throw new Error("浏览器无法切换语音音频模式")}}}const BE=new gae,jS=64,r2=-60,v5=32;function i2(e){if(!Number.isFinite(e)||e===0)return 0;const t=Math.min(1,Math.abs(e)),n=20*Math.log10(t),r=Math.max(0,Math.min(1,(n-r2)/-r2));return e<0?-r:r}function s2(e,t=8){const n=Math.floor(e.byteLength/2);if(n===0||!Number.isFinite(t)||t<=0)return[];const r=Math.min(n,Math.max(1,Math.floor(t))),i=new DataView(e.buffer,e.byteOffset,e.byteLength),s=[];for(let o=0;o<r;o+=1){const l=Math.floor(o*n/r),u=Math.max(l+1,Math.floor((o+1)*n/r));let d=1,f=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),f=Math.max(f,y)}s.push({min:d,max:f})}return s}function vae(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=Math.floor(e.byteLength/2),r=new Float32Array(n);for(let i=0;i<n;i+=1)r[i]=t.getInt16(i*2,!0)/32768;return r}function yae(e){if(e.length===0)return 0;const t=Math.max(1,Math.floor(e.length/512));let n=0,r=0;for(let i=0;i<e.length;i+=t){const s=e[i]??0;n+=s*s,r+=1}return r===0?0:Math.min(1,Math.sqrt(n/r)*10)}class y5{constructor(t,n=24e3,r={}){_t(this,"nextStartTime",0);_t(this,"activityEndToken",0);_t(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=vae(t),r=this.context.createBuffer(1,n.length,this.sampleRate);r.getChannelData(0).set(n);const i=this.context.createBufferSource();i.buffer=r,i.connect(this.context.destination);const s=Math.max(this.context.currentTime,this.nextStartTime);i.start(s);const o=s+r.duration;this.nextStartTime=o,this.schedulePlaybackFrames(t,n,s,o);const l=Math.max(0,(o-this.context.currentTime)*1e3);return this.emitPlaybackEvent("pcm-scheduled",{bytes:t.byteLength,durationMs:r.duration*1e3}),typeof i.addEventListener=="function"&&i.addEventListener("ended",()=>{this.emitPlaybackEvent("source-ended",{bytes:t.byteLength,durationMs:r.duration*1e3})},{once:!0}),l}stop(){var t,n;this.nextStartTime=this.context.currentTime,this.activityEndToken+=1;for(const r of this.timelineTimers)clearTimeout(r);this.timelineTimers.clear(),(n=(t=this.options).onActivityLevel)==null||n.call(t,0),this.emitPlaybackEvent("stopped")}snapshot(){const t=this.context.currentTime;return{contextState:String(this.context.state??"unknown"),contextTime:t,nextStartTime:this.nextStartTime,queuedMs:Math.max(0,(this.nextStartTime-t)*1e3)}}schedulePlaybackFrames(t,n,r,i){if(!this.options.onActivityLevel&&!this.options.onPlaybackChunk)return;const s=Math.max(1,Math.round(this.sampleRate*v5/1e3)),o=this.activityEndToken+=1;for(let l=0;l<n.length;l+=s){const u=Math.min(n.length,l+s),d=r+l/this.sampleRate,f=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),y=yae(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,S;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(S=(w=this.options).onPlaybackChunk)==null||S.call(w,p)},f)}if(this.options.onActivityLevel){const l=Math.max(0,(i-this.context.currentTime)*1e3);this.scheduleTimer(()=>{var u,d;o===this.activityEndToken&&((d=(u=this.options).onActivityLevel)==null||d.call(u,0))},l)}}scheduleTimer(t,n){const r=setTimeout(()=>{this.timelineTimers.delete(r),t()},n);this.timelineTimers.add(r)}emitPlaybackEvent(t,n={}){var r,i;(i=(r=this.options).onPlaybackEvent)==null||i.call(r,{event:t,...this.snapshot(),...n})}}const zw={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},o2="min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none transition-colors placeholder:text-muted-foreground/65 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",bae=800,a2=300,_ae=1600;function $S(e,t){return e.filter(n=>!n.model||n.model===t)}function l2({label:e,children:t,help:n}){return m.jsxs("div",{className:"block min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 transition-colors focus-within:border-ring/55 focus-within:bg-card/75 sm:p-3",children:[m.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.jsx("div",{className:"mt-2 min-w-0",children:t}),n?m.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function pg({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=b.useState(!1),u=b.useId(),d=n.find(v=>v.value===t),f=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!b5(f).detail;return m.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:v=>{v.currentTarget.contains(v.relatedTarget)||l(!1)},children:[m.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.jsxs("button",{type:"button","aria-labelledby":u,"aria-haspopup":"listbox","aria-expanded":o,disabled:p.length===0,className:`mt-2 flex w-full min-w-0 items-center justify-between gap-3 rounded-md border border-border bg-input px-3 text-left outline-none transition-colors hover:border-primary/40 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(v=>!v),"data-slot":"voice-settings-choice-trigger",children:[m.jsx(c2,{label:f,muted:!d&&!t}),m.jsx(Ol,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?m.jsx("div",{role:"listbox","aria-labelledby":u,className:"mt-2 max-h-64 overflow-y-auto rounded-md border border-border/80 bg-popover p-1 shadow-sm",children:n.map(v=>{const _=v.value===t;return m.jsxs("button",{type:"button",role:"option","aria-label":v.label,"aria-selected":_,disabled:v.disabled,className:"flex w-full min-w-0 items-center gap-2 rounded-sm px-2.5 py-2.5 text-left text-sm outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-45",onClick:()=>{v.disabled||(r(v.value),l(!1))},children:[m.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?m.jsx(Lo,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(c2,{label:v.label})]},v.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function c2({label:e,muted:t=!1}){const n=b5(e);return m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?m.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function wae({scrollRef:e}={}){const[t,n]=b.useState(zw),[r,i]=b.useState(String(zw.turnIdleSeconds)),[s,o]=b.useState(()=>eg()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),k=b.useRef(null),T=b.useRef(null),R=b.useRef(!1);b.useEffect(()=>{const ee=Ut;if(!ee){_({kind:"error",message:"请先连接 Relay 服务器"});return}let pe=!1;return _({kind:"loading"}),ee.requestVoiceConfig().then(ae=>{if(!pe){if(ae.error||!ae.config){_({kind:"error",message:ae.error??"读取语音设置失败"});return}n(ae.config),i(String(ae.config.turnIdleSeconds)),u(""),f(!1),y(!0),_({kind:"idle"})}}).catch(ae=>{pe||_({kind:"error",message:ae instanceof Error?ae.message:"读取语音设置失败"})}),()=>{pe=!0}},[]),b.useEffect(()=>{const ee=Ut;if(!ee||!p)return;let pe=!1;return ee.requestVoiceCapabilities({region:t.region}).then(ae=>{if(!pe){if(ae.error||!ae.capabilities){o(eg());return}o(ae.capabilities)}}).catch(()=>{pe||o(eg())}),()=>{pe=!0}},[t.region,p]),b.useEffect(()=>(R.current=!0,()=>{R.current=!1,$(),te()}),[]);const N=b.useMemo(()=>v.kind==="loading"?"读取中...":v.kind==="saving"?"保存中...":v.kind==="testing"?"正在测试语音合成":v.kind==="playingTest"?"正在播放测试音频":v.kind==="testPassed"?"测试通过":v.kind==="saved"?"已保存":v.kind==="error"?v.message:null,[v]),A=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",O=b.useMemo(()=>$S(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),K=O.some(ee=>ee.value===t.ttsVoice)?t.ttsVoice:"",U=O.length===0?"当前模型暂无可用音色":K?null:"请选择可用音色",X=b.useMemo(()=>Cae(r),[r]),z=X?null:"请输入正整数秒数",M=U??z,F=A||!!M,B=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>f2(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),I=b.useMemo(()=>kae(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),W=b.useMemo(()=>f2(O,K),[O,K]);function j(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:X??zw.turnIdleSeconds}}async function L(){if(A)return;if(M){_({kind:"error",message:M});return}const ee=Ut;if(!ee){_({kind:"error",message:"请先连接 Relay 服务器"});return}const pe=j();te(),_({kind:"saving"});const ae=performance.now();try{const me=await ee.updateVoiceConfig(pe);if(!R.current)return;const Ee=performance.now()-ae;if(Ee<a2&&await Eae(a2-Ee),!R.current)return;if(!me.success||me.error||!me.config){_({kind:"error",message:me.error??"保存语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,_(De=>De.kind==="saved"?{kind:"idle"}:De)},_ae),ee.requestVoiceCapabilities({region:me.config.region}).then(De=>{R.current&&De.capabilities&&o(De.capabilities)}).catch(()=>{R.current&&o(eg())})}catch(me){if(!R.current)return;_({kind:"error",message:me instanceof Error?me.message:"保存语音设置失败"})}}async function Y(){if(A)return;if(M){_({kind:"error",message:M});return}const ee=Ut;if(!ee){_({kind:"error",message:"请先连接 Relay 服务器"});return}let pe;try{pe=V()}catch(ae){_({kind:"error",message:d2(ae)});return}_({kind:"testing"});try{const[ae]=await Promise.all([ee.testVoiceConfig(j()),pe.ready]);if(!ae.success||ae.error){$(),_({kind:"error",message:ae.error??"语音配置测试失败"});return}const me=await re(ae,pe.context);_({kind:"playingTest",transcript:ae.transcript}),k.current=setTimeout(()=>{k.current=null,$(),_({kind:"testPassed",transcript:ae.transcript})},me)}catch(ae){$(),_({kind:"error",message:d2(ae)})}}function V(){$();const ee=BE.acquire("playback");S.current=ee;try{const pe=xae();return w.current=pe,{context:pe,ready:u2(pe)}}catch(pe){throw ee.release(),S.current=null,pe}}function $(){var ee,pe,ae;k.current&&(clearTimeout(k.current),k.current=null),(ee=x.current)==null||ee.stop(),x.current=null,(pe=w.current)==null||pe.close(),w.current=null,(ae=S.current)==null||ae.release(),S.current=null}function te(){T.current&&(clearTimeout(T.current),T.current=null)}async function re(ee,pe){if(!ee.audioBase64)throw new Error("语音测试未返回可播放音频");if(ee.audioEncoding&&ee.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ae=ee.audioSampleRate??24e3,me=Sae(ee.audioBase64);if(me.byteLength===0||me.byteLength%2!==0)throw new Error("测试音频数据无效");await u2(pe);const Ee=new y5(pe,ae);x.current=Ee,Ee.enqueue(me);const De=Math.ceil(me.byteLength/2/ae*1e3);return Math.max(bae,De)}function oe(ee){var pe;return((pe=$S(s.ttsVoices,ee)[0])==null?void 0:pe.value)??""}return m.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:ee=>{ee.preventDefault(),L()},children:[m.jsx("div",{className:"flex min-h-0 flex-1 flex-col px-4 py-3 sm:px-5 sm:py-3.5","data-slot":"voice-settings-body-frame",children:m.jsx("div",{className:"dev-render-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"voice-settings-scroll",ref:e,children:m.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[m.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsxs("div",{className:"min-w-0",children:[m.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),m.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),m.jsx("span",{className:"shrink-0 rounded-full border border-primary/35 bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:"Bailian"})]})}),m.jsx(l2,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:m.jsxs("div",{className:"flex min-w-0 gap-2",children:[m.jsxs("div",{className:"relative min-w-0 flex-1",children:[m.jsx(JD,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),m.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:ee=>{u(ee.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${o2} w-full pl-9`})]}),t.configured&&m.jsxs(Ct,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),f(!0)},children:[m.jsx(O1,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(pg,{label:"地域",value:t.region,options:B,onChange:ee=>n(pe=>({...pe,region:ee==="intl"?"intl":"cn"}))}),m.jsx(pg,{label:"语音识别模型",value:t.asrModel,options:P,onChange:ee=>n(pe=>({...pe,asrModel:ee}))}),m.jsx(pg,{label:"语音合成模型",value:t.ttsModel,options:I,onChange:ee=>n(pe=>({...pe,ttsModel:ee,ttsVoice:oe(ee)}))}),m.jsx(pg,{label:"语音音色",value:K,options:W,placeholder:O.length===0?"暂无可用音色":"请选择音色",onChange:ee=>n(pe=>({...pe,ttsVoice:ee})),help:U}),m.jsx(l2,{label:"结束停顿时间(秒)",help:z,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:ee=>i(ee.target.value),className:`${o2} w-full`})})]})})}),m.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[m.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),m.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[N?m.jsx("div",{role:v.kind==="error"?"alert":"status","aria-live":"polite",className:v.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:N}):null,m.jsxs(Ct,{type:"button",variant:"outline",disabled:F,onClick:()=>void Y(),children:[m.jsx(nI,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(Ct,{type:"submit",disabled:F,children:[m.jsx(I7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Sae(e){const t=window.atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n}function xae(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function u2(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function d2(e){return e instanceof Error?e.message:"语音配置测试失败"}function Eae(e){return new Promise(t=>setTimeout(t,e))}function Cae(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function f2(e,t){const n=e.map(r=>({value:r.value,label:_5(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function kae(e,t,n){const r=e.map(i=>{const s=$S(t,i.value).length===0;return{value:i.value,label:`${_5(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function b5(e){const t=e.split(" · ").map(n=>n.trim()).filter(Boolean);return t.length<=1?{title:e,detail:null}:{title:t[0],detail:t.slice(1).join(" · ")}}function _5(e){if(!e.age)return e.label;const t=`年龄 ${e.age}`;if(e.label.includes(t))return e.label;const n=` · ${e.age}`;return e.label.endsWith(n)?`${e.label.slice(0,-n.length)} · ${t}`:`${e.label} · ${t}`}const Tae=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Rae=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],zE="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function w5(e){if(!Number.isFinite(e)||e<0)return"未知";if(e<60)return`${Math.floor(e)} 秒`;const t=Math.floor(e/60);if(t<60)return`${t} 分钟`;const n=Math.floor(t/60),r=t%60;if(n<24)return r>0?`${n} 小时 ${r} 分钟`:`${n} 小时`;const i=Math.floor(n/24),s=n%24;return s>0?`${i} 天 ${s} 小时`:`${i} 天`}function Aae(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Mae(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Nae(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function FS({open:e,onOpenChange:t}){const n=Le(K=>K.relayUrl),r=Le(K=>K.latencyMonitorEnabled),i=Le(K=>K.setLatencyMonitorEnabled),s=Le(K=>K.sessionIdleNotificationsEnabled),o=Le(K=>K.setSessionIdleNotificationsEnabled),l=Le(K=>K.inputModePreference),u=Le(K=>K.setInputModePreference),d=Le(K=>K.themePreference),f=Le(K=>K.setThemePreference),p=Le(K=>K.ptyScrollTraceEnabled),y=Le(K=>K.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,S]=b.useState({kind:"idle"}),x=b.useRef(null),k=b.useRef(null),T=yee(),R=b.useMemo(()=>cp().osName==="iPad",[]),N=b.useCallback(async K=>{if(!K){o(!1);return}const U=await VJ();if(U==="granted"){o(!0);return}if(U==="denied"){Xe.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){Xe.info("未授予通知权限,会话通知保持关闭");return}Xe.error("当前浏览器不支持系统通知")},[o]),A=b.useCallback(async K=>{S({kind:"loading"});try{const U=await fetch(Aae(n),{cache:"no-store",signal:K});if(!U.ok)throw new Error(`HTTP ${U.status}`);const X=await U.json();if(X.status!=="ok")throw new Error("状态异常");S({kind:"ready",version:X.version??"未知",uptime:X.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;S({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const K=new AbortController;return A(K.signal),()=>K.abort()},[A,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const K=window.requestAnimationFrame(()=>{var U;(U=x.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(K)},[e,v]);const O=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",D=w.kind==="ready"?`运行 ${w5(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return m.jsx(xa,{open:e,onOpenChange:t,children:m.jsxs(Ea,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",v==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",v==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":v,focusSurfaceOnOpen:!0,ref:x,showCloseButton:v==="menu",children:[m.jsx(Ca,{className:Ye(v==="menu"&&"pr-12 text-left",v!=="menu"&&"text-left",v==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:v!=="menu"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(Ct,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>_("menu"),children:m.jsx(Gv,{className:"size-4","aria-hidden":"true"})}),m.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[m.jsx(Io,{children:Mae(v)}),m.jsx(_a,{className:"max-w-[28rem] leading-5",children:Nae(v)})]})]}),v==="voice"?m.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):m.jsxs(m.Fragment,{children:[m.jsx(Io,{children:"设置"}),m.jsx(_a,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?m.jsx(Pae,{relayVersion:O,relayDetail:D,relayMuted:w.kind==="error"}):v==="relay-token"?m.jsx(Lae,{saved:T}):v==="clients"?m.jsx(jae,{}):v==="voice"?m.jsx(wae,{scrollRef:k}):m.jsx(Oae,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:R,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:N,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function Pae({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:zE,"data-slot":"settings-dialog-body",children:[m.jsx(p2,{icon:m.jsx(tI,{className:"size-4","aria-hidden":"true"}),label:"Web",value:fae.version,detail:"当前浏览器加载的版本"}),m.jsx(p2,{icon:m.jsx(rI,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Oae({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:f,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:v,onOpenClients:_,onOpenVersion:w}){return m.jsxs("div",{className:"dev-render-scroll min-h-0 space-y-4 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"settings-dialog-body",children:[m.jsxs(Mu,{title:"服务",children:[m.jsx(mg,{icon:m.jsx(_W,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),m.jsx(mg,{icon:m.jsx(JD,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),m.jsx(mg,{icon:m.jsx(tq,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(Mu,{title:"外观",children:m.jsx(h2,{icon:m.jsx(Y7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Tae,onValueChange:n})}),m.jsx(Mu,{title:"通知",children:m.jsx($w,{icon:m.jsx(SW,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(Mu,{title:"交互",children:m.jsx(h2,{icon:m.jsx(eI,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Rae,onValueChange:i})}):null,m.jsxs(Mu,{title:"高级诊断",children:[m.jsx($w,{icon:m.jsx(Dh,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx($w,{icon:m.jsx(VD,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:p})]}),m.jsx(Mu,{title:"关于",children:m.jsx(mg,{icon:m.jsx(rI,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function Mu({title:e,children:t}){return m.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[m.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),m.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function h2({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return m.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,m.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return m.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Lae({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{CB().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!xB(f)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),Xe.error(p);return}o(null),Xe.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{EB(),l()};return m.jsxs("form",{className:zE,"data-slot":"settings-dialog-body",onSubmit:f=>{f.preventDefault(),u()},children:[m.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[m.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),m.jsx("input",{id:t,type:"password",value:r,onChange:f=>{i(f.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?m.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),m.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?m.jsx(Ct,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(Ct,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Dae(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Iae(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Dae(e)}function Bae(e){return aQ(e)}function zae(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return w5(t)}function jw({label:e,value:t,title:n}){return m.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[m.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),m.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function jae(){const e=Le(y=>y.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),f=b.useCallback(async()=>{const y=Ut;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(v){o(v instanceof Error?v.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{f()},[f]);const p=b.useCallback(async y=>{const v=Ut;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:zE,"data-slot":"settings-dialog-body",children:[m.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(N1,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?m.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?m.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const v=y.current===!0,_=l===y.clientId;return m.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children:m.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[m.jsxs("div",{className:"min-w-0 space-y-1.5",children:[m.jsx("div",{className:"min-w-0",children:m.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Bae(y)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(jw,{label:"已连接",value:zae(y.connectedAt)}),y.proxyId?m.jsx(jw,{label:"连接到",value:Iae(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?m.jsx(jw,{label:"来源 IP",value:y.remoteAddress}):null]})]}),v?m.jsx("div",{className:"inline-flex h-9 w-full items-center justify-center rounded-md border border-primary/30 bg-primary/10 px-3 text-sm font-normal text-primary","aria-label":"当前设备","data-slot":"relay-client-current-indicator",children:"当前设备"}):m.jsxs(Ct,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[m.jsx(f7,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function $w({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return m.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[m.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),m.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),m.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function mg({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return m.jsxs("button",{type:"button",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:r,"aria-labelledby":i,"aria-describedby":n?s:void 0,"data-slot":"settings-menu-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground transition-colors group-hover:text-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),m.jsx(_h,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function p2({icon:e,label:t,value:n,detail:r,muted:i=!1}){return m.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[m.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[m.jsx("div",{className:"text-sm text-muted-foreground",children:t}),m.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const $ae="xterm-helper-textarea";function Fae(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains($ae)?!1:(e.blur(),!0)}function m2(e,t,n){if(!e||Math.abs(n)<1)return!1;let r=e instanceof Element?e:null;for(;r&&t.contains(r);){if(r instanceof HTMLElement&&Hae(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Hae(e,t){if(e.scrollHeight<=e.clientHeight+1)return!1;const n=window.getComputedStyle(e).overflowY;return n!=="auto"&&n!=="scroll"&&n!=="overlay"?!1:t<0?e.scrollTop>0:e.scrollTop+e.clientHeight<e.scrollHeight-1}function Uae({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Fae()},[e]),i=b.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=b.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const f=(n.current??u.clientY)-u.clientY;n.current=u.clientY,m2(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(m2(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Wae({className:e}){const t=Le(o=>o.sidebarCollapsed),n=Le(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=Uae();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(v2,{collapsed:!0,onClick:n}),m.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),m.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[m.jsx(g2,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(n2,{compact:!0})]})]}),m.jsx(FS,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[m.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:m.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx(SI,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(v2,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(s5,{layout:"dropdown",variant:"sidebarChrome"})})]})}),m.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:m.jsx("div",{className:"flex-1 min-h-0",children:m.jsx(m5,{layout:"sidebar"})})}),m.jsxs("div",{className:"dev-sidebar-fade flex shrink-0 gap-2 px-2 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-2","data-slot":"sidebar-new-session",children:[m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(n2,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(g2,{onClick:()=>i(!0)})})]})]}),m.jsx(FS,{open:r,onOpenChange:i})]})}function g2({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(bp,{delayDuration:500,children:[m.jsx(_p,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(iI,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(wp,{side:t,sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:"设置"})]})}function v2({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?S7:_7;return m.jsxs(bp,{delayDuration:500,children:[m.jsx(_p,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(wp,{side:e?"right":"top",sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:n})]})}const qae=1500,Yae=300,y2=70,b2=35;function S5({texts:e,className:t}){const[n,r]=b.useState(""),[i,s]=b.useState(!0),o=b.useRef("typing"),l=b.useRef(0),u=b.useRef(0);b.useEffect(()=>{const f=setInterval(()=>s(p=>!p),530);return()=>clearInterval(f)},[]),b.useEffect(()=>{let f;const p=()=>e[u.current%e.length],y=()=>{const v=o.current;if(v==="typing"){const _=p();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(y,y2)):(o.current="paused",f=setTimeout(y,qae))}else v==="paused"?(o.current="deleting",f=setTimeout(y,b2)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),f=setTimeout(y,b2)):(u.current+=1,o.current="waiting",f=setTimeout(y,Yae)):(o.current="typing",f=setTimeout(y,y2))};return f=setTimeout(y,500),()=>clearTimeout(f)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return m.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[m.jsx("span",{className:"text-green-500",children:"> "}),m.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),m.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),m.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const x5=["DEV Anywhere","/unlimited @anytime"];function Vae({subtitle:e,action:t}){return m.jsx("section",{className:"dev-mobile-brand-hero border-b border-border/80 px-4 pb-5 pt-[calc(env(safe-area-inset-top)+1.25rem)] md:hidden","data-slot":"mobile-brand-hero","aria-label":"DEV Anywhere",children:m.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[m.jsx(S5,{texts:x5,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),m.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?m.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Kae=3e3,Xae=1e4,gg=12,Gae=4,_2={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Zae={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function Fw(e){if(!e.success||e.rttMs===void 0)return{state:"unavailable",error:e.error??"不可用",updatedAt:Date.now()};const t=e.rttMs;return{state:t<=120?"ok":t<=300?"warn":"bad",rttMs:t,updatedAt:Date.now()}}function Nu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function uh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function w2(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function E5(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Qae(e){switch(e){case"ok":return"border-emerald-500/35 bg-emerald-500/10 text-emerald-300";case"warn":return"border-amber-500/40 bg-amber-500/10 text-amber-300";case"bad":return"border-destructive/55 bg-destructive/10 text-destructive";default:return"border-border bg-card/90 text-muted-foreground"}}function Jae(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?uh(e.rttMs):"等待检测"}function ele(){const e=ki("local",vn.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function S2(e){Cr("local",vn.latencyMonitorPosition,JSON.stringify(e))}function tle(){var e,t;return{width:((e=window.visualViewport)==null?void 0:e.width)??window.innerWidth??document.documentElement.clientWidth??0,height:((t=window.visualViewport)==null?void 0:t.height)??window.innerHeight??document.documentElement.clientHeight??0}}function Hw(e,t){const n=tle(),r=gg,i=gg,s=Math.max(r,n.width-t.width-gg),o=Math.max(i,n.height-t.height-gg);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function nle(){const e=Le(A=>A.latencyMonitorEnabled),t=Le(A=>A.connected),n=Le(A=>A.proxyOnline),r=Le(A=>A.selectedProxyId),[i,s]=b.useState(Zae),[o,l]=b.useState(()=>ele()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((A,O)=>w2(O.state)-w2(A.state))[0]??{state:"idle"}).state,[i]),v=E5(y);async function _(){if(u.current)return;const A=Ut;if(!A||!t){const U=Nu("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:Nu("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:Nu("未连接开发机")}));const[O,D,K]=await Promise.allSettled([A.measureWebRelayLatency(),n?A.measureRelayProxyLatency():Promise.resolve({success:!1}),n?A.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:O.status==="fulfilled"?Fw(O.value):Nu(O.reason instanceof Error?O.reason.message:"测速失败"),relayProxy:D.status==="fulfilled"?Fw(D.value):Nu(D.reason instanceof Error?D.reason.message:"测速失败"),webProxy:K.status==="fulfilled"?Fw(K.value):Nu(K.reason instanceof Error?K.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let A=!1,O=null;const D=async()=>{await _(),!A&&(O=setTimeout(D,document.hidden?Xae:Kae))};return D(),()=>{A=!0,u.current=!1,O&&clearTimeout(O)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const A=d.current;if(!A)return;const O=A.getBoundingClientRect(),D=Hw(o,{width:O.width,height:O.height});D.x===o.x&&D.y===o.y||(l(D),S2(D))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,S=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(A){var D,K;if(A.button!==0)return;const O=A.currentTarget.getBoundingClientRect();f.current={pointerId:A.pointerId,startX:A.clientX,startY:A.clientY,originX:O.left,originY:O.top,width:O.width,height:O.height,dragging:!1},(K=(D=A.currentTarget).setPointerCapture)==null||K.call(D,A.pointerId)}function k(A){const O=f.current;if(!O||O.pointerId!==A.pointerId)return;const D=A.clientX-O.startX,K=A.clientY-O.startY;if(!O.dragging&&Math.hypot(D,K)<Gae)return;O.dragging=!0,A.preventDefault();const U=Hw({x:O.originX+D,y:O.originY+K},{width:O.width,height:O.height});l(U)}function T(A){var X,z;const O=f.current;if(!O||O.pointerId!==A.pointerId||(f.current=null,(z=(X=A.currentTarget).releasePointerCapture)==null||z.call(X,A.pointerId),!O.dragging))return;A.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const D=A.clientX-O.startX,K=A.clientY-O.startY,U=Hw({x:O.originX+D,y:O.originY+K},{width:O.width,height:O.height});l(U),S2(U)}function R(A){var D,K;const O=f.current;!O||O.pointerId!==A.pointerId||(f.current=null,(K=(D=A.currentTarget).releasePointerCapture)==null||K.call(D,A.pointerId))}function N(A){p.current&&(p.current=!1,A.preventDefault(),A.stopPropagation())}return m.jsxs(PE,{children:[m.jsx(OE,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Qae(v)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${uh(i.webRelay.rttMs)},开发机 ${uh(w.rttMs)}`,onPointerDown:x,onPointerMove:k,onPointerUp:T,onPointerCancel:R,onClickCapture:N,children:[m.jsx(VD,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),m.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",uh(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",uh(w.rttMs)]}),m.jsx(Ol,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(LE,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[m.jsxs("div",{className:"flex items-start justify-between gap-3",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),m.jsx(Ct,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(N1,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(_2).map(A=>m.jsx(rle,{label:_2[A],measurement:i[A]},A))})]})]})}function rle({label:e,measurement:t}){const n=E5(t.state);return m.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[m.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Jae(t)})]})]})}const C5="/__dev_anywhere_debug/browser-state-dumps",ile=1500,sle=10,Uw=80,jE=500,ole=["id","class","data-slot","data-state","data-testid","role","aria-label","aria-hidden","name","type","autocomplete","autocorrect","autocapitalize","inputmode","enterkeyhint","virtualkeyboardpolicy","contenteditable","placeholder","href","src"],ale=["display","position","visibility","opacity","pointer-events","z-index","overflow","overflow-x","overflow-y","touch-action","transform","translate","color-scheme","background-color","color","font-size","line-height","padding-top","padding-right","padding-bottom","padding-left","margin-top","margin-right","margin-bottom","margin-left"];function x2(){if(typeof window>"u")return"off";const e=O5("debugDump");return e==="auto"?"auto":e!==null||gle("debugInput")?"manual":"off"}function lle(e="manual"){const t={count:0,truncated:!1},n=window,r={schemaVersion:1,createdAt:new Date().toISOString(),trigger:e,url:{href:window.location.href,origin:window.location.origin,pathname:window.location.pathname,search:window.location.search,hash:window.location.hash},browser:{userAgent:navigator.userAgent,language:navigator.language,languages:Array.from(navigator.languages??[]),platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints??0,cookieEnabled:navigator.cookieEnabled,onLine:navigator.onLine},viewport:fle(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:E2(document.activeElement),selection:hle(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>E2(i)).filter(i=>!!i),root:k5(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:Pu(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:Pu(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:Pu(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:Pu(()=>C2(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:Pu(()=>C2(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:Pu(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function cle(e="manual"){const t=lle(e);return ule(t)}async function ule(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await dle(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:C5}}catch(r){const i=L5(r),s=ple(e.createdAt);return mle(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function dle(e){const t=await fetch(C5,{method:"POST",headers:{"content-type":"application/json"},body:e});if(!t.ok)throw new Error(`${t.status} ${await t.text()}`);const n=await t.json();if(!n.ok||!n.path||typeof n.bytes!="number")throw new Error("debug endpoint returned an invalid response");return{path:n.path,bytes:n.bytes}}function k5(e,t,n){if(n.count>=ile||t>sle)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=k2(e.textContent??"");return u?{kind:"text",text:Ny(u,jE)}:{kind:"text",text:""}}if(!(e instanceof HTMLElement))return{kind:"truncated"};const r=[];let i=0;const s=Array.from(e.childNodes);for(const u of s.slice(0,Uw))u.nodeType===Node.TEXT_NODE&&!k2(u.textContent??"")||r.push(k5(u,t+1,n));s.length>Uw&&(i=s.length-Uw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:P5(e),attrs:T5(e),rect:R5(e),scroll:A5(e),style:M5(e)},l=N5(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function E2(e){if(!(e instanceof HTMLElement))return null;const t=N5(e);return{path:P5(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:T5(e),rect:R5(e),scroll:A5(e),style:M5(e),...t?{value:t}:{}}}function fle(){var n;const e=window.visualViewport,t=((n=screen.orientation)==null?void 0:n.type)??null;return{window:{innerWidth:window.innerWidth,innerHeight:window.innerHeight,outerWidth:window.outerWidth,outerHeight:window.outerHeight,devicePixelRatio:window.devicePixelRatio,scrollX:window.scrollX,scrollY:window.scrollY},visualViewport:e?{width:e.width,height:e.height,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,pageLeft:e.pageLeft,pageTop:e.pageTop,scale:e.scale}:null,screen:{width:screen.width,height:screen.height,availWidth:screen.availWidth,availHeight:screen.availHeight,orientation:t}}}function T5(e){const t={};for(const n of ole){const r=e.getAttribute(n);r!==null&&(t[n]=Ny(r,500))}return t}function R5(e){const t=e.getBoundingClientRect();return{x:ns(t.x),y:ns(t.y),width:ns(t.width),height:ns(t.height),top:ns(t.top),right:ns(t.right),bottom:ns(t.bottom),left:ns(t.left)}}function A5(e){return{top:ns(e.scrollTop),left:ns(e.scrollLeft),height:ns(e.scrollHeight),width:ns(e.scrollWidth),clientHeight:ns(e.clientHeight),clientWidth:ns(e.clientWidth)}}function M5(e){const t=window.getComputedStyle(e),n={};for(const r of ale)n[r]=t.getPropertyValue(r);return n}function N5(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Ny(e.value,jE),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function hle(){var e;try{return Ny(((e=window.getSelection())==null?void 0:e.toString())??"",jE)}catch{return null}}function P5(e){const t=[];let n=e;for(;n&&n!==document.documentElement;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}const i=n.getAttribute("data-slot");i?r+=`[data-slot="${i}"]`:n.classList.length>0&&(r+=`.${Array.from(n.classList).slice(0,3).join(".")}`);const s=n.parentElement;if(s){const o=n.tagName,l=Array.from(s.children).filter(u=>u instanceof HTMLElement&&u.tagName===o);l.length>1&&(r+=`:nth-of-type(${l.indexOf(n)+1})`)}t.unshift(r),n=s}return`html>${t.join(">")}`}function ple(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function mle(e,t,n){if(typeof document>"u")return!1;const r=new Blob([t],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");return s.href=i,s.download=e,s.rel="noopener",document.body.append(s),s.click(),s.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3),!0}function gle(e){return O5(e)!==null}function O5(e){const t=new URLSearchParams(window.location.search);if(t.has(e))return t.get(e)??"";const[,n=""]=window.location.hash.split("?"),r=new URLSearchParams(n);return r.has(e)?r.get(e)??"":null}function C2(e){return e?Mv(e.slice(-200)):null}function Pu(e){try{return Mv(e())}catch(t){return{error:L5(t)}}}function Mv(e){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(Array.isArray(e))return e.map(Mv);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Mv(r);return t}return String(e)}function k2(e){return e.replace(/\s+/g," ").trim()}function Ny(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function ns(e){return Math.round(e*100)/100}function L5(e){return e instanceof Error?e.message:String(e)}const vle=500,yle=1e3,ble=60;function _le(){const[e,t]=b.useState(()=>x2()),[n,r]=b.useState(!1),[i,s]=b.useState(null),o=b.useRef(null),l=b.useRef(!1),u=b.useRef(0),d=b.useRef(0),f=b.useRef(null);b.useEffect(()=>{const _=()=>t(x2());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const p=b.useCallback(async(_="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await cle(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&wle(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),b.useEffect(()=>{var k,T;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=R=>{d.current>=ble||(_(),f.current=window.setTimeout(()=>{f.current=null;const N=Date.now(),A=yle-(N-u.current);if(A>0){f.current=window.setTimeout(()=>w(R),A);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${R}`)},vle))};w("initial");const S=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=R=>w(R.type);return S.forEach(R=>window.addEventListener(R,x,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",x),(T=window.visualViewport)==null||T.addEventListener("scroll",x),()=>{var R,N;_(),S.forEach(A=>window.removeEventListener(A,x,!0)),(R=window.visualViewport)==null||R.removeEventListener("resize",x),(N=window.visualViewport)==null||N.removeEventListener("scroll",x)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=Sle(i);return m.jsxs("div",{className:"fixed bottom-3 right-3 z-[90] flex max-w-[min(360px,calc(100vw-24px))] flex-col items-end gap-1",children:[v?m.jsx("div",{className:"max-w-full truncate rounded-md border border-border/70 bg-popover/95 px-2 py-1 text-[10px] text-muted-foreground shadow",children:v}):null,m.jsxs(Ct,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void p("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?m.jsx(Mo,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(QW,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:y})]})]})}function wle(e){if(e.status==="saved"){Xe.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){Xe.info(`诊断已下载: ${e.filename}`);return}Xe.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Sle(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function xle(e){if(typeof window>"u")return null;try{const t=window.localStorage;return!t||typeof t.getItem!="function"?null:t.getItem(e)}catch{return null}}function $E(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:xle(n)==="1",l=()=>typeof window>"u"?[]:window[t]??[],u=d=>{typeof window>"u"||(window[t]=d)};return{isEnabled:o,append(d){if(typeof window>"u")return;const f=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&f.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const v=f.indexOf(y);v>=0&&v!==f.length-1&&(f.splice(v,1),f.push(y)),u(f);return}}}if(f.push(d),i&&s.set(d.event,d),f.length>r){const p=f.splice(0,f.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(f)},getAll:l}}function Bn(e){return Math.round(e*10)/10}function dl(e){return e.length===0?"":`${Bn(Math.min(...e))}..${Bn(Math.max(...e))}`}function td(e){return[...new Set(e.filter(t=>t!==void 0).map(Bn))]}function D5(e){let t=0,n=0;for(let r=1;r<e.length;r+=1){const i=e[r]-e[r-1];if(Math.abs(i)<1)continue;const s=Math.sign(i);t!==0&&s!==t&&(n+=1),t=s}return n}const Ele="dev_anywhere_pty_input_latency_trace",T2=80,Cle=1e4,kle=new TextDecoder;let Tle=0;const Sd=new Map,qc=$E({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Ele,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Rle(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Ple)}function Ale(e,t){if(!qc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Tle}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Dle(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Sd.get(e)??[];return s.push(i),HE(s,r),Sd.set(e,s),Sp({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function R2(e,t){if(!e||!qc.isEnabled())return;const n=performance.now(),r=Ole(e.sessionId,e.inputId);r&&(r.sentAt=n),Sp({t:n,event:"input:ws-send",sessionId:e.sessionId,inputId:e.inputId,inputKind:r==null?void 0:r.kind,dataLength:r==null?void 0:r.dataLength,sent:t.sent,queueWhenDisconnected:t.queueWhenDisconnected,deltaFromInputMs:r?n-r.startedAt:null,details:t.details})}function Mle(e,t,n){if(!qc.isEnabled())return;const r=performance.now(),i=FE(e,r),s=zle(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Ble(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Sp({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:UE(i,r),details:jle([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Nle(e,t,n=1){if(!qc.isEnabled())return;const r=performance.now(),i=FE(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Sp({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:UE(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Lle(e,s))}function Ple(){const e=qc.getAll(),t=e.slice(-200),n=[...Sd.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Bn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Bn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Bn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Bn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Bn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Bn(s.t),s.repeat&&s.repeat>0?`${s.event} +${s.repeat}`:s.event,s.sessionId,s.inputId??"",s.inputKind??"",s.dataLength??"",s.sent===void 0?"":s.sent?"sent":"not-sent",s.queueWhenDisconnected?"queue-ok":"",s.outputSeq??"",s.bytes??"",s.chunkCount??"",s.pendingInputs??"",s.deltaFromInputMs===void 0||s.deltaFromInputMs===null?"":Bn(s.deltaFromInputMs),s.details??""].join(" "));return["DEV Anywhere PTY input latency trace",`events=${e.length}, included=${t.length}, pendingInputs=${n.length}`,"pending input summary:","inputId sessionId kind len wsSendMs firstOutputMs echoMatchMs xtermWriteMs paintMs",...r,"events:","t event sessionId inputId kind len sent queue outputSeq bytes chunks pending deltaMs details",...i].join(`
535
535
  `)}function Sp(e){qc.append(e)}function FE(e,t){const n=Sd.get(e)??[];return HE(n,t),Sd.set(e,n),n}function HE(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>Cle;(i||s)&&e.splice(n,1)}e.length>T2&&e.splice(0,e.length-T2)}function Ole(e,t){return(Sd.get(e)??[]).find(n=>n.inputId===t)??null}function Lle(e,t){if(!qc.isEnabled())return;const n=performance.now(),r=FE(e,n);let i=0;for(const s of t){const o=r.find(l=>l.inputId===s);!o||o.paintAt!==null||(o.paintAt=n,i+=1)}Sp({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:UE(r,n),details:i>0?`paint=${i}`:""}),HE(r,n)}function UE(e,t){const n=e[0];return n?t-n.startedAt:null}function Dle(e){return e==="\r"||e===`
536
536
  `?"enter":e.startsWith("\x1B")?"escape":Ile(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function Ile(e){for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(n>=0&&n<=8||n>=11&&n<=31||n===127)return!0}return!1}function Ble(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function zle(e){try{return kle.decode(e)}catch{return""}}function jle(e){return e.filter(Boolean).join(" ")}function to(e,t){if(!e||!t)return;const n=Ale(e,t),r=wc;if(!r){R2(n,{sent:!1,queueWhenDisconnected:!1,details:"no-ws-manager"});return}const i={type:"remote_input_raw",sessionId:e,data:t};n&&(i.traceId=n.inputId);const s=r.send(JSON.stringify(i),{queueWhenDisconnected:!0});R2(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const A2=-1;function $le({sessionId:e,enabled:t,waiting:n,approvalSeq:r,sendRawInput:i=to}){const s=b.useRef(void 0),o=b.useRef(e);b.useEffect(()=>{if(o.current!==e&&(o.current=e,s.current=void 0),!n){s.current=void 0;return}if(r===void 0){if(s.current!==void 0)return;s.current=A2,i(e,"\r");return}if(s.current===A2){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function Fle(e){var r,i,s;if(!e.connected||!e.proxyOnline||e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.state==="idle"||e.session.state==="error"||e.session.state==="terminated")return null;const t=K1(e.proxyId,e.session.sessionId);return!t||!e.autoYesBySessionKey[t]||!(e.session.state==="waiting_approval"||((r=e.agentStatus)==null?void 0:r.phase)==="waiting_permission"||((i=e.ptyState)==null?void 0:i.state)==="approval_wait")?null:{key:t,sessionId:e.session.sessionId,waiting:!0,approvalSeq:((s=e.ptyState)==null?void 0:s.state)==="approval_wait"?e.ptyState.seq:void 0}}function Hle({target:e,sendRawInput:t}){return $le({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function Ule({sendRawInput:e=to}){const t=Le(d=>d.connected),n=Le(d=>d.proxyOnline),r=Le(d=>d.selectedProxyId),i=$t(d=>d.sessions),s=$t(d=>d.ptyStateBySessionId),o=$t(d=>d.agentStatusBySessionId),l=$t(d=>d.ptyAutoYesBySessionKey),u=i.map(d=>Fle({proxyId:r,session:d,ptyState:s[d.sessionId],agentStatus:o[d.sessionId],autoYesBySessionKey:l,connected:t,proxyOnline:n})).filter(d=>d!==null);return m.jsx(m.Fragment,{children:u.map(d=>m.jsx(Hle,{target:d,sendRawInput:e},d.key))})}function Wle(e,t){return e.some(n=>n.sessionId===t)?e:[...e,{sessionId:t}]}var yc=function(e,t){return Number(e.toFixed(t))},qle=function(e,t){return t},qn=function(e,t,n){n&&typeof n=="function"&&n(e,t)},Yle=function(e){return-Math.cos(e*Math.PI)/2+.5},Vle=function(e){return e},Kle=function(e){return e*e},Xle=function(e){return e*(2-e)},Gle=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},Zle=function(e){return e*e*e},Qle=function(e){return--e*e*e+1},Jle=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},ece=function(e){return e*e*e*e},tce=function(e){return 1- --e*e*e*e},nce=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},rce=function(e){return e*e*e*e*e},ice=function(e){return 1+--e*e*e*e*e},sce=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},I5={easeOut:Yle,linear:Vle,easeInQuad:Kle,easeOutQuad:Xle,easeInOutQuad:Gle,easeInCubic:Zle,easeOutCubic:Qle,easeInOutCubic:Jle,easeInQuart:ece,easeOutQuart:tce,easeInOutQuart:nce,easeInQuint:rce,easeOutQuint:ice,easeInOutQuint:sce},B5=function(e){typeof e=="number"&&cancelAnimationFrame(e)},eo=function(e){e.mounted&&(B5(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function z5(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;eo(e),e.animation=function(){if(!e.mounted)return B5(e.animation);var o=new Date().getTime()-i,l=o/n,u=I5[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function oce(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function Fl(e,t,n,r){var i=oce(t);if(!(!e.mounted||!i)){var s=e.setState,o=e.state,l=o.scale,u=o.positionX,d=o.positionY,f=t.scale-l,p=t.positionX-u,y=t.positionY-d;n===0?s(t.scale,t.positionX,t.positionY):z5(e,r,n,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+f*v,w=u+p*v,S=d+y*v;s(_,w,S)})}}function ace(e,t,n){var r=e.offsetWidth,i=e.offsetHeight,s=t.offsetWidth,o=t.offsetHeight,l=s*n,u=o*n,d=r-l,f=i-u;return{wrapperWidth:r,wrapperHeight:i,newContentWidth:l,newDiffWidth:d,newContentHeight:u,newDiffHeight:f}}var lce=function(e,t,n,r,i,s,o){var l=e>t?n*(o?.5:1):0,u=r>i?s*(o?.5:1):0,d=e-t-l,f=l,p=r-i-u,y=u;return{minPositionX:d,maxPositionX:f,minPositionY:p,maxPositionY:y,scaleWidthFactor:l,scaleHeightFactor:u}},WE=function(e,t){var n=e.wrapperComponent,r=e.contentComponent,i=e.setup,s=i.centerZoomedOut,o=i.disablePadding;if(!n||!r)throw new Error("Components are not mounted");var l=ace(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,f=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,v=l.newDiffHeight,_=lce(u,f,y,d,p,v,!!s),w=u>=f&&d>=p;o&&w&&!s&&(_.minPositionX=0,_.maxPositionX=0,_.minPositionY=0,_.maxPositionY=0);var S=e.setup,x=S.minPositionX,k=S.maxPositionX,T=S.minPositionY,R=S.maxPositionY;return x!=null&&(_.minPositionX=u*(1-t)+x*t),k!=null&&(_.maxPositionX=k*t),T!=null&&(_.minPositionY=d*(1-t)+T*t),R!=null&&(_.maxPositionY=R*t),_},qh=function(e,t,n,r){return r?e<t?yc(t,2):e>n?yc(n,2):yc(e,2):yc(e,2)},xd=function(e,t){var n=WE(e,t);return e.bounds=n,n};function xp(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,f=n.maxPositionY,p=0,y=0;o&&(p=i,y=s);var v=qh(e,l-p,d+p,r),_=qh(t,u-y,f+y,r);return{x:v,y:_}}function Py(e,t,n,r,i,s){var o=e.state,l=o.scale,u=o.positionX,d=o.positionY,f=r-l;if(typeof t!="number"||typeof n!="number")return console.error("Mouse X and Y position were not provided!"),{x:u,y:d};var p=u-t*f,y=d-n*f,v=xp(p,y,i,s,0,0,null);return v}var M2=1e-7;function Ep(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,M2),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,M2)}var N2=function(e,t){var n=e.setup.panning.excluded,r=e.isInitialized,i=e.wrapperComponent,s=t.target,o="shadowRoot"in s&&"composedPath"in t,l=o?t.composedPath().some(function(f){return f instanceof Element?i==null?void 0:i.contains(f):!1}):i==null?void 0:i.contains(s),u=r&&s&&l;if(!u)return!1;var d=Cp(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},P2=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},cce=function(e,t){var n=e.state,r=n.positionX,i=n.positionY;e.isPanning=!0;var s=t.clientX,o=t.clientY;e.startCoords={x:s-r,y:o-i}},uce=function(e,t){var n=t.touches,r=e.state,i=r.positionX,s=r.positionY;e.isPanning=!0;var o=n.length===1;if(o){var l=n[0].clientX,u=n[0].clientY;e.startCoords={x:l-i,y:u-s}}};function dce(e){var t=e.state,n=t.positionX,r=t.positionY,i=t.scale,s=e.setup,o=s.disabled,l=s.limitToBounds,u=s.centerZoomedOut,d=e.wrapperComponent;if(!(o||!d||!e.bounds)){var f=e.bounds,p=f.maxPositionX,y=f.minPositionX,v=f.maxPositionY,_=f.minPositionY,w=n>p||n<y,S=r>v||r<_,x=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>v?d.offsetHeight:e.setup.minPositionY||0,T=Py(e,x,k,i,e.bounds,l||u),R=T.x,N=T.y;return{scale:i,positionX:w?R:n,positionY:S?N:r}}}function j5(e,t,n,r,i){var s=e.setup.limitToBounds,o=e.wrapperComponent,l=e.bounds,u=e.state,d=u.scale,f=u.positionX,p=u.positionY;if(!(o===null||l===null||t===f&&n===p)){var y=xp(t,n,l,s,r,i,o),v=y.x,_=y.y;e.setState(d,v,_)}}var fce=function(e,t,n){var r=e.startCoords,i=e.state,s=e.setup.panning,o=s.lockAxisX,l=s.lockAxisY,u=i.positionX,d=i.positionY;if(!r)return{x:u,y:d};var f=t-r.x,p=n-r.y,y=o?u:f,v=l?d:p;return{x:y,y:v}},Ml=function(e,t,n){var r=e.setup,i=e.state,s=r.minScale,o=r.disablePadding,l=r.centerZoomedOut,u=n??i.scale;return t>0&&u>=s&&!o&&!l?t:0},bl;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(bl||(bl={}));var hce=function(e){var t=e.mounted,n=e.wrapperComponent,r=e.contentComponent,i=e.setup,s=i.disabled,o=i.velocityAnimation,l=i.limitToBounds,u=e.state.scale,d=o.disabled;if(d||s||!t||!n||!r)return!1;if(!l)return!0;var f=n.offsetWidth<r.offsetWidth*u||n.offsetHeight<r.offsetHeight*u;return f},pce=function(e){var t=e.mounted,n=e.velocity,r=e.bounds,i=e.setup,s=i.disabled,o=i.velocityAnimation,l=o.disabled,u=!l&&!s&&t;return!(!u||!n||!r)};function mce(e,t){var n=e.setup.velocityAnimation,r=n.animationTime,i=n.maxAnimationTime,s=n.inertia;return Math.min(r*Math.max(1,Math.abs(t/s)),i)}function O2(e,t,n,r,i,s,o,l,u,d){if(i){if(t>o&&n>o){var f=o+(e-o)*d;return f>u?u:f<o?o:f}if(t<s&&n<s){var f=s+(e-s)*d;return f<l?l:f>s?s:f}}return r?t:qh(e,s,o,i)}function gce(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var Ww=function(e,t,n){var r=0,i=e*n;return Number.isNaN(i)?r:e<0?Math.max(i,-t):Math.min(i,t)};function vce(e,t,n){var r,i,s=hce(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,f=u.velocityAnimation,p=f.maxStrengthMouse,y=f.maxStrengthTouch,v=f.sensitivityTouch,_=f.sensitivityMouse,w=Date.now();if(o&&l&&d){var S=gce(d),x=(r={},r[bl.TOUCH]=v,r[bl.MOUSE]=_,r)[n],k=(i={},i[bl.TOUCH]=y,i[bl.MOUSE]=p,i)[n],T=t.x-o.x,R=t.y-o.y,N=Ww(T/S,k,x),A=Ww(R/S,k,x),O=w-l,D=T*T+R*R,K=Ww(Math.sqrt(D)/O,k,x);e.velocity={velocityX:N,velocityY:A,total:K}}e.lastMousePosition=t,e.velocityTime=w}}function yce(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=pce(e);if(!(!s||!t||!n||!i)){var o=t.velocityX,l=t.velocityY,u=t.total,d=n.maxPositionX,f=n.minPositionX,p=n.maxPositionY,y=n.minPositionY,v=r.limitToBounds,_=r.autoAlignment,w=r.zoomAnimation,S=r.panning,x=S.lockAxisY,k=S.lockAxisX,T=w.animationType,R=_.sizeX,N=_.sizeY,A=_.velocityAlignmentTime,O=A,D=mce(e,u),K=Math.max(D,O),U=Ml(e,R),X=Ml(e,N),z=U*i.offsetWidth/100,M=X*i.offsetHeight/100,F=d+z,B=f-z,P=p+M,I=y-M,W=e.state,j=new Date().getTime();z5(e,T,K,function(L){var Y=e.state,V=Y.scale,$=Y.positionX,te=Y.positionY,re=new Date().getTime()-j,oe=re/O,ee=I5[_.animationType],pe=1-ee(Math.min(1,oe)),ae=1-L,me=$+o*ae,Ee=te+l*ae,De=O2(me,W.positionX,$,k,v,f,d,B,F,pe),Se=O2(Ee,W.positionY,te,x,v,y,p,I,P,pe);if($!==me||te!==Ee){e.setState(V,De,Se);var Je=e.props.onPanning;Je&&Je(zn(e),{})}})}}function L2(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},eo(e),xd(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?uce(e,t):cce(e,t)}function $5(e,t){var n=e.state.scale,r=e.setup,i=r.minScale,s=r.autoAlignment,o=s.disabled,l=s.sizeX,u=s.sizeY,d=s.animationTime,f=s.animationType,p=o||n<i||!l&&!u;if(!p){var y=dce(e);y&&Fl(e,y,d,f)}}function D2(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=fce(e,t,n),f=d.x,p=d.y,y=Ml(e,l),v=Ml(e,u);vce(e,{x:f,y:p},r),j5(e,f,p,y,v)}}function bce(e,t){if(e.isPanning){var n=e.velocity,r=e.wrapperComponent,i=e.contentComponent;e.isPanning=!1;var s=e.state,o=s.positionX,l=s.positionY,u=s.scale,d=e.panStartPosition;if(e.panStartPosition=null,d){var f=o-d.x,p=l-d.y;if(f*f+p*p<=25)return}e.isAnimating=!1,e.animation=null;var y=(r==null?void 0:r.offsetWidth)||0,v=(r==null?void 0:r.offsetHeight)||0,_=((i==null?void 0:i.offsetWidth)||0)*u,w=((i==null?void 0:i.offsetHeight)||0)*u,S=!e.setup.limitToBounds||y<_||v<w,x=!t&&n&&n.total>.1&&S;x?yce(e):$5(e)}}function qE(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Ep(yc(t,2),s,o,0,!1),d=xd(e,u),f=Py(e,n,r,u,d,l),p=f.x,y=f.y;return{scale:u,positionX:p,positionY:y}}function YE(e,t,n){var r=e.state.scale,i=e.wrapperComponent,s=e.setup,o=s.minScale,l=s.maxScale,u=s.limitToBounds,d=s.zoomAnimation,f=d.disabled,p=d.animationTime,y=d.animationType,v=r>=o&&r<=l,_=f||v;if((r>=1||u)&&$5(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,S=n||i.offsetHeight/2,x=r<o?o:l,k=qE(e,x,w,S);k&&Fl(e,k,p,y)}}var zs=function(){return zs=Object.assign||function(t){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},zs.apply(this,arguments)};function I2(e,t,n){for(var r=0,i=t.length,s;r<i;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}var qw={scale:1,positionX:0,positionY:0},gc={disabled:!1,minPositionX:null,maxPositionX:null,minPositionY:null,maxPositionY:null,minScale:1,maxScale:8,limitToBounds:!0,centerZoomedOut:!1,centerOnInit:!1,disablePadding:!1,smooth:!0,detached:!1,wheel:{step:.015,disabled:!1,wheelDisabled:!1,touchPadDisabled:!1,activationKeys:[],excluded:[]},trackPadPanning:{disabled:!0,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,activationKeys:[],excluded:[]},panning:{disabled:!1,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,allowLeftClickPan:!0,allowMiddleClickPan:!0,allowRightClickPan:!0,activationKeys:[],excluded:[]},pinch:{step:5,disabled:!1,allowPanning:!0,excluded:[]},doubleClick:{disabled:!1,step:.7,mode:"zoomIn",animationType:"easeOut",animationTime:200,excluded:[]},zoomAnimation:{disabled:!1,size:.4,animationTime:200,animationType:"easeOut"},autoAlignment:{disabled:!1,sizeX:100,sizeY:100,animationTime:200,velocityAlignmentTime:400,animationType:"easeOut"},velocityAnimation:{disabled:!1,sensitivityMouse:1,sensitivityTouch:1.2,maxStrengthMouse:20,maxStrengthTouch:40,inertia:1,animationTime:300,maxAnimationTime:800,animationType:"easeOut"}},HS={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},F5=function(e){var t,n,r,i,s,o,l,u,d,f=Math.max((t=e.minScale)!==null&&t!==void 0?t:gc.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:gc.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:qw.scale,v=Math.min(Math.max(y,f),p),_=qh((i=e.initialPositionX)!==null&&i!==void 0?i:qw.positionX,(s=e.minPositionX)!==null&&s!==void 0?s:-1/0,(o=e.maxPositionX)!==null&&o!==void 0?o:1/0,e.minPositionX!=null||e.maxPositionX!=null),w=qh((l=e.initialPositionY)!==null&&l!==void 0?l:qw.positionY,(u=e.minPositionY)!==null&&u!==void 0?u:-1/0,(d=e.maxPositionY)!==null&&d!==void 0?d:1/0,e.minPositionY!=null||e.maxPositionY!=null);return{previousScale:v,scale:v,positionX:_,positionY:w}},B2=function(e){var t=zs({},gc);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof gc[r]<"u";if(s&&i){var o=Object.prototype.toString.call(gc[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=zs(zs({},gc[r]),e[r]):u?t[r]=I2(I2([],gc[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},H5=function(e,t,n){var r=e.state.scale,i=e.wrapperComponent,s=e.setup,o=s.maxScale,l=s.minScale,u=s.zoomAnimation,d=s.smooth,f=u.size;if(!i)throw new Error("Wrapper is not mounted");var p=d?r*Math.exp(t*n):r+t*n,y=Ep(yc(p,3),l,o,f,!1);return y};function U5(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,f=u.positionX,p=u.positionY,y=e.setup.zoomAnimation;if(!l)return console.error("No WrapperComponent found");var v=y.disabled?0:r,_=l.offsetWidth,w=l.offsetHeight,S=(_/2-f)/d,x=(w/2-p)/d,k=H5(e,t,n),T=qE(e,k,S,x);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");var R=e.props,N=R.onZoomStart,A=R.onZoom,O=R.onZoomStop,D=new MouseEvent("mousemove",{bubbles:!0}),K=zn(e);qn(K,D,N),qn(K,D,A),Fl(e,T,v,i);var U=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;U&&U.setTimeout(function(){e.mounted&&qn(zn(e),D,O)},v)}function W5(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,f=o.centerOnInit,p=F5(e.props),y=e.state,v=y.scale,_=y.positionX,w=y.positionY;if(l){var S=p.positionX,x=p.positionY;if(f&&u){var k=VE(p.scale,l,u);S=k.positionX,x=k.positionY}var T=WE(e,p.scale),R=xp(S,x,T,d,0,0,l),N={scale:p.scale,positionX:R.x,positionY:R.y};if(!(v===p.scale&&_===p.positionX&&w===p.positionY)){r==null||r();var A=e.props,O=A.onZoomStart,D=A.onZoom,K=A.onZoomStop,U=new MouseEvent("mousemove",{bubbles:!0}),X=zn(e);qn(X,U,O),qn(X,U,D),Fl(e,N,t,n);var z=(s=(i=l.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&s!==void 0?s:typeof window<"u"?window:null;z&&z.setTimeout(function(){e.mounted&&qn(zn(e),U,K)},t)}}}function _ce(e,t,n,r){var i=e.getBoundingClientRect(),s=t.getBoundingClientRect(),o=n.getBoundingClientRect(),l=s.x*r.scale,u=s.y*r.scale;return{x:(i.x-o.x+l)/r.scale,y:(i.y-o.y+u)/r.scale}}function wce(e,t,n,r,i){r===void 0&&(r=0),i===void 0&&(i=0);var s=e.wrapperComponent,o=e.contentComponent,l=e.state,u=e.setup,d=u.limitToBounds,f=u.minScale,p=u.maxScale;if(!s||!o)return l;var y=s.getBoundingClientRect(),v=t.getBoundingClientRect(),_=_ce(t,s,o,l),w=_.x,S=_.y,x=v.width/l.scale,k=v.height/l.scale,T=s.offsetWidth/x,R=s.offsetHeight/k,N=Ep(n||Math.min(T,R),f,p,0,!1),A=(y.width-x*N)/2,O=(y.height-k*N)/2,D=(y.left-w)*N+A+r,K=(y.top-S)*N+O+i,U=WE(e,N),X=xp(D,K,U,d,0,0,s),z=X.x,M=X.y;return{positionX:z,positionY:M,scale:N}}var Sce=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),U5(e,1,t,n,r)}},xce=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),U5(e,-1,t,n,r)}},Ece=function(e){return function(t,n,r,i,s){i===void 0&&(i=300),s===void 0&&(s="easeOut");var o=e.state,l=o.positionX,u=o.positionY,d=o.scale,f=e.wrapperComponent,p=e.contentComponent,y=e.setup.disabled;if(!(y||!f||!p)){var v={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};Fl(e,v,i,s)}}},Cce=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),W5(e,t,n)}},kce=function(e){return function(t,n,r){n===void 0&&(n=200),r===void 0&&(r="easeOut");var i=e.state,s=e.wrapperComponent,o=e.contentComponent;if(s&&o){var l=VE(t||i.scale,s,o);Fl(e,l,n,r)}}},Tce=function(e){return function(t,n,r,i,s,o){r===void 0&&(r=600),i===void 0&&(i="easeOut"),s===void 0&&(s=0),o===void 0&&(o=0),eo(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=wce(e,u,n,s,o);Fl(e,d,r,i)}}},US=function(e){return{instance:e,state:e.state,zoomIn:Sce(e),zoomOut:xce(e),setTransform:Ece(e),resetTransform:Cce(e),centerView:kce(e),zoomToElement:Tce(e)}},Rce=function(e){return{instance:e,state:e.state}},zn=function(e){var t={};return Object.assign(t,Rce(e)),Object.assign(t,US(e)),t},Yw=!1;function Vw(){try{var e={get passive(){return Yw=!0,!1}};return e}catch{return Yw=!1,Yw}}var vg=".".concat(HS.wrapperClass),Cp=function(e,t){return t.some(function(n){return e.matches("".concat(vg," ").concat(n,", ").concat(vg," .").concat(n,", ").concat(vg," ").concat(n," *, ").concat(vg," .").concat(n," *"))})},Yh=function(e){e&&clearTimeout(e)},Ace=function(e){return Number.parseFloat(e.toFixed(8))},q5=function(e,t,n){var r=Ace(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},VE=function(e,t,n){var r=n.offsetWidth*e,i=n.offsetHeight*e,s=(t.offsetWidth-r)/2,o=(t.offsetHeight-i)/2;return{scale:e,positionX:s,positionY:o}};function Mce(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Nce(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var Y5=function(e,t){var n=e.setup.wheel,r=n.disabled,i=n.wheelDisabled,s=n.touchPadDisabled,o=n.excluded,l=e.isInitialized,u=e.isPanning,d=t.target,f=l&&!u&&!r&&d;if(!f||i&&!t.ctrlKey||s&&t.ctrlKey)return!1;var p=Cp(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},Pce=function(e,t){var n=e.setup,r=n.disabled,i=n.trackPadPanning,s=i.activationKeys,o=i.excluded;if(!e.wrapperComponent||!e.contentComponent||r||i.disabled||t.ctrlKey)return!1;var l=Y5(e,t);if(l)return!1;var u=t.target,d=Cp(u,o);if(d)return!1;var f=e.isPressingKeys(s);return!!f},Oce=function(e){return e?e.deltaY<0?1:-1:0};function Lce(e,t){var n=Oce(e),r=qle(t,n);return r}function V5(e,t,n){var r=t.getBoundingClientRect(),i=0,s=0;if("clientX"in e)i=(e.clientX-r.left)/n,s=(e.clientY-r.top)/n;else{var o=e.touches[0];i=(o.clientX-r.left)/n,s=(o.clientY-r.top)/n}return(Number.isNaN(i)||Number.isNaN(s))&&console.error("No mouse or touch offset found"),{x:i,y:s}}var Dce=function(e,t,n,r,i){var s=e.state.scale,o=e.wrapperComponent,l=e.setup,u=l.maxScale,d=l.minScale,f=l.zoomAnimation,p=l.disablePadding,y=f.size,v=f.disabled;if(!o)throw new Error("Wrapper is not mounted");var _=s+t*n,w=r?!1:!v,S=Ep(_,d,u,y,w&&!p);return S},K5=function(e,t){var n=e.previousWheelEvent,r=e.state.scale,i=e.setup,s=i.maxScale,o=i.minScale;return n?r<s||r>o||Math.sign(n.deltaY)!==Math.sign(t.deltaY)||n.deltaY>0&&n.deltaY<t.deltaY||n.deltaY<0&&n.deltaY>t.deltaY||Math.sign(n.deltaY)!==Math.sign(t.deltaY):!1},Ice=function(e,t){var n=e.setup.pinch,r=n.disabled,i=n.excluded,s=e.isInitialized,o=t.target,l=s&&!r&&o;if(!l)return!1;var u=Cp(o,i);return!u},Bce=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},zce=function(e,t,n){var r=n.getBoundingClientRect(),i=e.touches,s=i[0].clientX-r.left,o=i[0].clientY-r.top,l=i[1].clientX-r.left,u=i[1].clientY-r.top;return{x:(s+l)/2/t,y:(o+u)/2/t}},X5=function(e){return Math.sqrt(Math.pow(e.touches[0].pageX-e.touches[1].pageX,2)+Math.pow(e.touches[0].pageY-e.touches[1].pageY,2))},jce=5,$ce=function(e,t){var n=e.pinchStartScale,r=e.pinchStartDistance,i=e.setup,s=i.maxScale,o=i.minScale,l=i.zoomAnimation,u=i.disablePadding,d=i.pinch,f=l.size,p=l.disabled,y=d.step;if(!n||r===null)throw new Error("Pinch touches distance was not provided");if(t<0)return e.state.scale;var v=t/r,_=v*n,w=(_-n)*(y/jce),S=n+w,x=S===1/0?0:yc(S,10);return Ep(x,o,s,f,!p&&!u)},G5=160,Z5=100,Fce=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(eo(e),qn(zn(e),t,r),qn(zn(e),t,i))},Hce=function(e,t){var n=e.props,r=n.onWheel,i=n.onZoom,s=e.contentComponent,o=e.setup,l=e.state,u=l.scale,d=o.limitToBounds,f=o.centerZoomedOut,p=o.zoomAnimation,y=o.wheel,v=o.disablePadding,_=o.smooth,w=p.size,S=p.disabled,x=y.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var k=Lce(t,null),T=_?x*Math.abs(t.deltaY):x,R=Dce(e,k,T,!t.ctrlKey);if(u!==R){var N=xd(e,R),A=V5(t,s,u),O=S||w===0||f||v,D=d&&O,K=Py(e,A.x,A.y,R,N,D),U=K.x,X=K.y;e.previousWheelEvent=t,e.setState(R,U,X),qn(zn(e),t,r),qn(zn(e),t,i)}},Uce=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;Yh(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(YE(e,t.x,t.y),e.wheelAnimationTimer=null)},Z5);var s=K5(e,t);s&&(Yh(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,qn(zn(e),t,r),qn(zn(e),t,i))},G5))},Wce=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(eo(e),qn(zn(e),t,r),qn(zn(e),t,i))},qce=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;Yh(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(YE(e,t.x,t.y),e.wheelAnimationTimer=null)},Z5);var s=K5(e,t);s&&(Yh(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,qn(zn(e),t,r),qn(zn(e),t,i))},G5))},Q5=function(e){for(var t=0,n=0,r=0;r<2;r+=1)t+=e.touches[r].clientX,n+=e.touches[r].clientY;var i=t/2,s=n/2;return{x:i,y:s}},Yce=function(e,t){var n=X5(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=Q5(t),eo(e)},Vce=function(e,t){var n=e.contentComponent,r=e.pinchStartDistance,i=e.wrapperComponent,s=e.pinchPreviousCenter,o=e.state.scale,l=e.setup,u=l.limitToBounds,d=l.centerZoomedOut,f=l.zoomAnimation,p=l.autoAlignment,y=l.pinch,v=l.panning,_=f.disabled,w=f.size,S=y.allowPanning;if(!(r===null||!n)){var x=zce(t,o,n);if(!(!Number.isFinite(x.x)||!Number.isFinite(x.y))){var k=X5(t),T=$ce(e,k),R=Q5(t),N=o/T,A=(R.x-((s==null?void 0:s.x)||0))*N,O=(R.y-((s==null?void 0:s.y)||0))*N;if(!(T===o&&A===0&&O===0)){e.pinchPreviousCenter=R;var D=xd(e,T),K=_||w===0||d,U=u&&K,X=Py(e,x.x,x.y,T,D,U),z=X.x,M=X.y;if(e.pinchMidpoint=x,e.lastDistance=k,v.disabled||!S)e.setState(T,z,M);else{var F=p.sizeX,B=p.sizeY,P=Ml(e,F,T),I=Ml(e,B,T),W=z+A,j=M+O,L=xp(W,j,D,u,P,I,i),Y=L.x,V=L.y;e.setState(T,Y,V)}}}}},Kce=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,YE(e,t==null?void 0:t.x,t==null?void 0:t.y)},J5=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;Yh(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,qn(zn(e),t,n)},r)},Xce=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;qn(zn(e),t,r),W5(e,o,l,function(){return qn(zn(e),t,i)}),J5(e,t)};function Gce(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function Zce(e,t){var n=e.setup,r=e.doubleClickStopEventTimer,i=e.state,s=e.contentComponent,o=i.scale,l=e.props,u=l.onZoomStart,d=l.onZoom,f=n.doubleClick,p=f.disabled,y=f.mode,v=f.step,_=f.animationTime,w=f.animationType;if(!p&&!r){if(y==="reset")return Xce(e,t);if(!s)return console.error("No ContentComponent found");var S=Gce(y,e.state.scale),x=H5(e,S,v);if(o!==x){qn(zn(e),t,u);var k=V5(t,s,o),T=qE(e,x,k.x,k.y);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");qn(zn(e),t,d),Fl(e,T,_,w),J5(e,t)}}}var Qce=function(e,t){var n=e.isInitialized,r=e.setup,i=e.wrapperComponent,s=r.doubleClick,o=s.disabled,l=s.excluded,u=t.target,d=i==null?void 0:i.contains(u),f=n&&u&&d&&!o;if(!f)return!1;var p=Cp(u,l);return!p},Jce=(function(){function e(t){var n=this;this.mounted=!0,this.onChangeCallbacks=new Set,this.onInitCallbacks=new Set,this.onTransformCallbacks=new Set,this.wrapperComponent=null,this.contentComponent=null,this.isInitialized=!1,this.bounds=null,this.previousWheelEvent=null,this.wheelStopEventTimer=null,this.wheelAnimationTimer=null,this.isPanning=!1,this.isWheelPanning=!1,this.startCoords=null,this.panStartPosition=null,this.lastTouch=null,this.isPinching=!1,this.distance=null,this.lastDistance=null,this.pinchStartDistance=null,this.pinchStartScale=null,this.pinchMidpoint=null,this.pinchPreviousCenter=null,this.doubleClickStopEventTimer=null,this.velocity=null,this.velocityTime=null,this.lastMousePosition=null,this.isAnimating=!1,this.animation=null,this.pressedKeys={},this.mount=function(){n.initializeWindowEvents()},this.unmount=function(){n.cleanupWindowEvents()},this.update=function(r){n.props=r,n.wrapperComponent&&n.contentComponent&&xd(n,n.state.scale),n.setup=B2(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=Vw(),u=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,d=u==null?void 0:u.defaultView;(i=n.wrapperComponent)===null||i===void 0||i.addEventListener("wheel",n.onWheelPanning,l),(s=n.wrapperComponent)===null||s===void 0||s.addEventListener("keyup",n.setKeyUnPressed,l),(o=n.wrapperComponent)===null||o===void 0||o.addEventListener("keydown",n.setKeyPressed,l),d==null||d.addEventListener("mousedown",n.onPanningStart,l),d==null||d.addEventListener("mousemove",n.onPanning,l),d==null||d.addEventListener("mouseup",n.onPanningStop,l),u==null||u.addEventListener("mouseleave",n.clearPanning,l),d==null||d.addEventListener("keyup",n.setKeyUnPressed,l),d==null||d.addEventListener("keydown",n.setKeyPressed,l),d==null||d.addEventListener("blur",n.handleWindowBlur)},this.cleanupWindowEvents=function(){var r,i,s,o,l,u=Vw(),d=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,f=d==null?void 0:d.defaultView;f==null||f.removeEventListener("mousedown",n.onPanningStart,u),f==null||f.removeEventListener("mousemove",n.onPanning,u),f==null||f.removeEventListener("mouseup",n.onPanningStop,u),d==null||d.removeEventListener("mouseleave",n.clearPanning,u),f==null||f.removeEventListener("keyup",n.setKeyUnPressed,u),f==null||f.removeEventListener("keydown",n.setKeyPressed,u),f==null||f.removeEventListener("blur",n.handleWindowBlur),document.removeEventListener("mouseleave",n.clearPanning,u),(i=n.wrapperComponent)===null||i===void 0||i.removeEventListener("wheel",n.onWheelPanning,u),(s=n.wrapperComponent)===null||s===void 0||s.removeEventListener("keyup",n.setKeyUnPressed,u),(o=n.wrapperComponent)===null||o===void 0||o.removeEventListener("keydown",n.setKeyPressed,u),eo(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=Vw();r.addEventListener("wheel",n.onWheelZoom,i),r.addEventListener("dblclick",n.onDoubleClick,i),r.addEventListener("touchstart",n.onTouchPanningStart,i),r.addEventListener("touchmove",n.onTouchPanning,i),r.addEventListener("touchend",n.onTouchPanningStop,i)},this.handleInitialize=function(r){var i=n.setup.centerOnInit;n.applyTransformation(),n.onInitCallbacks.forEach(function(s){return s(zn(n))}),i&&(n.setCenter(),n.observer=new ResizeObserver(function(){var s,o=r.offsetWidth,l=r.offsetHeight;(o>0||l>0)&&(n.onInitCallbacks.forEach(function(u){return u(zn(n))}),n.setCenter(),(s=n.observer)===null||s===void 0||s.disconnect())}),setTimeout(function(){var s;(s=n.observer)===null||s===void 0||s.disconnect()},5e3),n.observer.observe(r))},this.onWheelZoom=function(r){var i=n.setup.disabled;if(!i){n.syncModifierKeys(r);var s=Y5(n,r);s&&(Fce(n,r),Hce(n,r),Uce(n,r))}},this.onWheelPanning=function(r){var i=n.props.onPanning,s=n.setup.trackPadPanning,o=s.lockAxisX,l=s.lockAxisY;n.syncModifierKeys(r);var u=Pce(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,f=d.positionX,p=d.positionY,y=f-r.deltaX,v=p-r.deltaY,_=o?f:y,w=l?p:v,S=n.setup.autoAlignment,x=S.sizeX,k=S.sizeY,T=Ml(n,x),R=Ml(n,k);_===f&&w===p||(Wce(n,r),j5(n,_,w,T,R),qn(zn(n),r,i),qce(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=N2(n,r);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.button===0&&!n.setup.panning.allowLeftClickPan||r.button===1&&!n.setup.panning.allowMiddleClickPan||r.button===2&&!n.setup.panning.allowRightClickPan||(r.preventDefault(),r.stopPropagation(),eo(n),L2(n,r),qn(zn(n),r,s)))}}},this.onPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(!i){if(n.syncModifierKeys(r),n.isPanning&&r.buttons===0){n.clearPanning(r);return}var o=P2(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),D2(n,r.clientX,r.clientY,bl.MOUSE),qn(zn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(bce(n,i),qn(zn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=Ice(n,r);o&&(Yce(n,r),eo(n),qn(zn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=Bce(n);o&&(r.preventDefault(),r.stopPropagation(),Vce(n,r),qn(zn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(Kce(n),qn(zn(n),r,i))},this.onTouchPanningStart=function(r){var i=n.setup,s=i.disabled,o=i.doubleClick,l=n.props.onPanningStart;if(!s){var u=!(o!=null&&o.disabled),d=n.lastTouch&&+new Date-n.lastTouch<200;if(u&&d&&r.touches.length===1)n.onDoubleClick(r);else{n.lastTouch=+new Date,eo(n);var f=r.touches,p=f.length===1,y=f.length===2,v=N2(n,r);if(p){if(!v)return;eo(n),L2(n,r),qn(zn(n),r,l)}y&&n.onPinchStart(r)}}},this.onTouchPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(n.isPanning&&r.touches.length===1){if(i)return;var o=P2(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];D2(n,l.clientX,l.clientY,bl.TOUCH),qn(zn(n),r,s)}else r.touches.length>1&&n.onPinch(r)},this.onTouchPanningStop=function(r){n.onPanningStop(r),n.onPinchStop(r)},this.onDoubleClick=function(r){var i=n.setup.disabled;if(!i){var s=Qce(n,r);s&&Zce(n,r)}},this.clearPanning=function(r){n.isPanning&&n.onPanningStop(r)},this.handleWindowBlur=function(){n.pressedKeys={},n.isPanning&&(n.isPanning=!1,n.startCoords=null)},this.syncModifierKeys=function(r){var i=r.ctrlKey,s=r.metaKey,o=r.shiftKey,l=r.altKey;typeof i=="boolean"&&(n.pressedKeys.Control=i),typeof s=="boolean"&&(n.pressedKeys.Meta=s),typeof o=="boolean"&&(n.pressedKeys.Shift=o),typeof l=="boolean"&&(n.pressedKeys.Alt=l)},this.setKeyPressed=function(r){n.pressedKeys[r.key]=!0},this.setKeyUnPressed=function(r){n.pressedKeys[r.key]=!1},this.isPressingKeys=function(r){return typeof r=="function"?r(Object.entries(n.pressedKeys).filter(function(i){var s=i[1];return s}).map(function(i){var s=i[0];return s})):r.length?!!r.every(function(i){return n.pressedKeys[i]}):!0},this.setCenter=function(){if(n.wrapperComponent&&n.contentComponent){var r=VE(n.state.scale,n.wrapperComponent,n.contentComponent);n.setState(r.scale,r.positionX,r.positionY)}},this.handleTransformStyles=function(r,i,s){return n.props.customTransform?n.props.customTransform(r,i,s):q5(r,i,s)},this.getContext=function(){return zn(n)},this.applyTransformation=function(){if(!(!n.mounted||!n.contentComponent)){var r=n.state,i=r.scale,s=r.positionX,o=r.positionY,l=n.handleTransformStyles(s,o,i);n.props.detached||(n.contentComponent.style.transform=l),n.onTransformCallbacks.forEach(function(u){return u({scale:i,positionX:s,positionY:o,previousScale:n.state.previousScale,ref:zn(n)})})}},this.setState=function(r,i,s){var o=n.props.onTransform;if(!Number.isNaN(r)&&!Number.isNaN(i)&&!Number.isNaN(s)){var l=Math.max(r,1e-7);l!==n.state.scale&&(n.state.previousScale=n.state.scale,n.state.scale=l),n.state.positionX=i,n.state.positionY=s,n.applyTransformation();var u=zn(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),qn(u,{scale:n.state.scale,positionX:i,positionY:s},o)}else console.error("Detected NaN set state values")},this.onTransform=function(r){return n.onTransformCallbacks.has(r)||n.onTransformCallbacks.add(r),function(){n.onTransformCallbacks.delete(r)}},this.onChange=function(r){return n.onChangeCallbacks.has(r)||n.onChangeCallbacks.add(r),function(){n.onChangeCallbacks.delete(r)}},this.onInit=function(r){return n.onInitCallbacks.has(r)||n.onInitCallbacks.add(r),function(){n.onInitCallbacks.delete(r)}},this.init=function(r,i){n.cleanupWindowEvents(),n.wrapperComponent=r,n.contentComponent=i,xd(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=zn(n);qn(s,void 0,n.props.onInit),Mce(n.props.ref,s)},this.props=t,this.setup=B2(this.props),this.state=F5(this.props)}return e})(),Oy=tt.createContext(null),eue=function(e,t){return typeof e=="function"?e(t):e},tue=tt.forwardRef(function(e,t){var n=b.useRef(new Jce(e)).current,r=eue(e.children,US(n));return b.useImperativeHandle(t,function(){return US(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),m.jsx(Oy.Provider,zs({value:n},{children:r}))});tt.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(Oy);return b.useEffect(function(){return r.onChange(function(i){if(n.current){var s=0,o=0;n.current.style.transform=r.handleTransformStyles(s,o,1/i.instance.state.scale)}})},[r]),m.jsx("div",zs({},e,{ref:Nce([n,t])}))});function nue(e,t){t===void 0&&(t={});var n=t.insertAt;if(!(typeof document>"u")){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",n==="top"&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var rue=`.transform-component-module_wrapper__SPB86 {
537
537
  position: relative;
@@ -669,7 +669,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
669
669
  `))return null;const n=sbe(t);return!n||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||bC(n)||n.split("/").includes("...")?null:n}function abe(e){return e.includes("/")?!1:SC(e)}function lbe(e){const t=e.split("/").pop()??e;if(/^\d+(?:\.\d+)+$/.test(t))return!1;if(e.includes("/"))return!0;const n=e.replace(o$,""),r=n.split("/").pop()??n;return/[A-Za-z_-]/.test(r)}function cbe(e){const t=obe(e);return!t||abe(t)||!lbe(t)?null:ibe.test(t)?{kind:"image-preview",path:t}:o$.test(t)?{kind:"file-download",path:t}:null}const ube=16,dbe=24,Vf=6,fbe=425,vh=-1;function Bu(e,t){return e.pointerId===t||t===vh&&e.touchIdentifier!==null}function fc(e,t){if(t===null)return null;for(let n=0;n<e.length;n+=1){const r=e[n];if((r==null?void 0:r.identifier)===t)return r}return null}function Ag(e,t){let n=null,r=Number.POSITIVE_INFINITY;for(let i=0;i<e.length;i+=1){const s=e[i];if(!s)continue;const o=Math.hypot(s.clientX-t.clientX,s.clientY-t.clientY);o>=r||(n=s,r=o)}return n}function zu(e){return Math.hypot(e.lastX-e.startX,e.lastY-e.startY)}function Ai(e,t={}){const n=window.__ccTestPtyTouchGestureEvents;n&&(n.push({event:e,t:performance.now(),...t}),n.length>200&&n.splice(0,n.length-200))}function hbe({terminalRef:e,suppressPtyFocus:t,focusTerminal:n,isGestureTarget:r,onLongPressCandidateStart:i,onTap:s,isTapCandidate:o,onLongPressStart:l,onLongPressMove:u,onLongPressEnd:d,onGestureFinish:f,getScrollPosition:p}){const y=b.useRef(null),v=b.useRef(null);b.useEffect(()=>{const I=j=>{const L=v.current;L&&(L.touchIdentifier!==null&&!fc(j.changedTouches,L.touchIdentifier)||(v.current=null,(L.kind==="longpress"||L.kind==="link")&&j.cancelable&&j.preventDefault()))},W=()=>{v.current=null};return document.addEventListener("touchend",I,{capture:!0,passive:!1}),document.addEventListener("touchcancel",W,{capture:!0}),()=>{document.removeEventListener("touchend",I,{capture:!0}),document.removeEventListener("touchcancel",W,{capture:!0})}},[]);const _=b.useCallback(I=>{I.longPressTimer!==null&&(window.clearTimeout(I.longPressTimer),I.longPressTimer=null)},[]),w=b.useCallback(I=>{I.longPressed||I.moved||(I.longPressed=!0,I.longPressArmed=!1,_(I),t(),l==null||l({clientX:I.startX,clientY:I.startY}))},[_,l,t]),S=b.useCallback(I=>{if(!(I.longPressed||I.longPressArmed||I.moved)){if(zu(I)>Vf){_(I),Ai("longpress:cancel-drift",{distance:zu(I),threshold:Vf});return}if(o!=null&&o({clientX:I.startX,clientY:I.startY})){I.longPressArmed=!0,_(I),Ai("longpress:arm-link",{clientX:I.startX,clientY:I.startY});return}w(I)}},[_,o,w]),x=b.useCallback((I,W=!0)=>{if(I.longPressDelivered||!I.longPressed||I.moved)return;I.longPressDelivered=!0;const j={clientX:I.lastX,clientY:I.lastY};W?window.setTimeout(()=>d==null?void 0:d(j),0):d==null||d(j)},[d]),k=b.useCallback((I,W,j,L=!1,Y=null)=>{v.current=null;const V={pointerId:I,touchIdentifier:Y,startX:W,startY:j,lastX:W,lastY:j,moved:!1,longPressArmed:!1,longPressed:!1,longPressDelivered:!1,touchEventStream:L,longPressTimer:null,scrollPositionAtStart:(p==null?void 0:p())??null};V.longPressTimer=window.setTimeout(()=>{y.current===V&&S(V)},fbe),y.current=V,Ai("start",{pointerId:I,clientX:W,clientY:j,touchEventStream:L}),i==null||i({clientX:W,clientY:j})},[p,S,i]),T=b.useCallback(I=>{const W=I.scrollPositionAtStart,j=(p==null?void 0:p())??null;return!W||!j?!1:Math.abs(j.scrollLeft-W.scrollLeft)>.5||Math.abs(j.scrollTop-W.scrollTop)>.5},[p]),R=b.useCallback((I,W,j)=>{const L=y.current;if(!L||!Bu(L,I))return!1;L.lastX=W,L.lastY=j;const Y=zu(L);if(L.longPressArmed&&Y>Vf&&(L.longPressArmed=!1,Ai("longpress:cancel-armed-drift",{pointerId:I,clientX:W,clientY:j,distance:Y,threshold:Vf})),L.longPressed)return Ai("move",{pointerId:I,clientX:W,clientY:j,distance:Y,moved:L.moved,longPressed:!0}),u==null||u({clientX:W,clientY:j}),!0;const V=W-L.startX,$=j-L.startY;return!L.moved&&Y>=ube&&(L.moved=!0,_(L)),Ai("move",{pointerId:I,clientX:W,clientY:j,dx:V,dy:$,distance:Y,moved:L.moved,longPressed:!1}),L.moved},[_,u]),N=b.useCallback((I,W)=>{var V;const j=y.current;if(!j||!Bu(j,I))return null;W&&(j.lastX=W.clientX,j.lastY=W.clientY),y.current=null,_(j);const L=zu(j);let Y;if(j.longPressArmed){if(L<=Vf)return w(j),x(j),Y="longpress",Ai("finish",{pointerId:I,result:Y,point:W,moved:j.moved,distance:L,longPressed:!0,longPressArmed:!0}),f==null||f(Y),Y;j.longPressArmed=!1}return j.longPressed?(x(j),Y="longpress",Ai("finish",{pointerId:I,result:Y,point:W,moved:j.moved,longPressArmed:j.longPressArmed,distance:L,longPressed:!0}),f==null||f(Y),Y):T(j)?(t(),Y="scroll",Ai("finish",{pointerId:I,result:Y,point:W,moved:j.moved,distance:L,longPressed:!1,containerScrolled:!0}),f==null||f(Y),Y):j.moved?W&&zu(j)<=dbe&&(s!=null&&s(W))?(t(),Y="link",Ai("finish",{pointerId:I,result:Y,point:W,moved:!0,distance:L,longPressed:!1}),f==null||f(Y),Y):(t(),Y="scroll",Ai("finish",{pointerId:I,result:Y,point:W,moved:!0,distance:L,longPressed:!1}),f==null||f(Y),Y):W&&(s!=null&&s(W))?(t(),Y="link",Ai("finish",{pointerId:I,result:Y,point:W,moved:!1,distance:L,longPressed:!1}),f==null||f(Y),Y):(n?n():(V=e.current)==null||V.focus(),Y="tap",Ai("finish",{pointerId:I,result:Y,point:W,moved:!1,distance:L,longPressed:!1}),f==null||f(Y),Y)},[_,x,T,n,f,s,w,t,e]),A=b.useCallback((I,W={})=>{const j=y.current;return!j||!Bu(j,I)?null:(_(j),y.current=null,j.longPressed?(x(j,W.immediateLongPressEnd!==!0),Ai("cancel",{pointerId:I,result:"longpress"}),f==null||f("longpress"),"longpress"):(j.longPressArmed&&Ai("cancel",{pointerId:I,result:"armed"}),t(),Ai("cancel",{pointerId:I,result:"scroll",moved:j.moved,distance:zu(j)}),f==null||f("scroll"),"scroll"))},[_,x,f,t]),O=b.useRef(A);O.current=A,b.useEffect(()=>{const I=()=>{v.current=null;const j=y.current;j&&O.current(j.pointerId,{immediateLongPressEnd:!0})},W=()=>{document.visibilityState==="hidden"&&I()};return window.addEventListener("blur",I),window.addEventListener("pagehide",I),document.addEventListener("visibilitychange",W),()=>{window.removeEventListener("blur",I),window.removeEventListener("pagehide",I),document.removeEventListener("visibilitychange",W);const j=y.current;j&&_(j),y.current=null,v.current=null}},[_]);const D=b.useCallback(I=>{if(I.pointerType!=="touch")return;const W=I.target;if(!(W instanceof Element&&W.closest('[data-slot="pty-selection-handle"]'))&&!(!(W instanceof Element)||!W.closest(".xterm")&&!(r!=null&&r({clientX:I.clientX,clientY:I.clientY})))){if(y.current){I.stopPropagation();return}k(I.pointerId,I.clientX,I.clientY),I.stopPropagation()}},[r,k]),K=b.useCallback(I=>{if(I.pointerType!=="touch")return;const W=y.current;if(W&&!Bu(W,I.pointerId)){I.stopPropagation();return}if(W!=null&&W.touchEventStream&&Bu(W,I.pointerId)){I.stopPropagation();return}const j=R(I.pointerId,I.clientX,I.clientY),L=y.current;L&&j&&(I.stopPropagation(),L.longPressed&&I.preventDefault())},[R]),U=b.useCallback(I=>{const W=y.current,j=N(I.pointerId,{clientX:I.clientX,clientY:I.clientY});j&&(I.pointerType==="touch"&&(v.current={kind:j,touchIdentifier:(W==null?void 0:W.touchIdentifier)??null}),I.stopPropagation(),j==="link"&&I.cancelable&&I.preventDefault())},[N]),X=b.useCallback(I=>{const W=y.current;if(I.pointerType==="touch"&&W&&Bu(W,I.pointerId)&&W.touchEventStream&&!W.longPressed){I.stopPropagation();return}const j=A(I.pointerId);j&&(I.pointerType==="touch"&&(v.current={kind:j,touchIdentifier:(W==null?void 0:W.touchIdentifier)??null}),I.stopPropagation())},[A]),z=b.useCallback(I=>{const W=I.target;if(!(W instanceof Element)||W.closest('[data-slot="pty-selection-handle"]'))return;const j=I.changedTouches[0]??I.touches[0];if(j&&!(!W.closest(".xterm")&&!(r!=null&&r({clientX:j.clientX,clientY:j.clientY})))){if(y.current){if(y.current.touchIdentifier===null){const L=Ag(I.changedTouches,{clientX:y.current.lastX,clientY:y.current.lastY});if(!L)return;y.current.touchIdentifier=L.identifier,y.current.touchEventStream=!0}return}k(vh,j.clientX,j.clientY,!0,j.identifier)}},[r,k]),M=b.useCallback(I=>{const W=y.current;if(!W)return;if(W.touchIdentifier===null){const $=Ag(I.changedTouches.length>0?I.changedTouches:I.touches,{clientX:W.lastX,clientY:W.lastY});if(!$)return;W.touchIdentifier=$.identifier,W.touchEventStream=!0}const j=fc(I.changedTouches,W.touchIdentifier);if(!j&&I.changedTouches.length>0)return;const L=j??fc(I.touches,W.touchIdentifier);if(!L)return;const Y=R(vh,L.clientX,L.clientY),V=y.current;V&&Y&&V.longPressed&&(I.stopPropagation(),I.preventDefault())},[R]),F=b.useCallback(I=>{var V;const W=y.current;if((W==null?void 0:W.touchIdentifier)===null&&I.changedTouches.length>0){const $=Ag(I.changedTouches,{clientX:W.lastX,clientY:W.lastY});$&&(W.touchIdentifier=$.identifier)}const j=W?fc(I.changedTouches,W.touchIdentifier):null;if(W&&!j&&fc(I.touches,W.touchIdentifier))return;const L=j?{clientX:j.clientX,clientY:j.clientY}:W?{clientX:W.lastX,clientY:W.lastY}:void 0,Y=N(vh,L)??((V=v.current)==null?void 0:V.kind);v.current=null,(Y==="longpress"||Y==="link")&&(I.stopPropagation(),I.cancelable&&I.preventDefault())},[N]),B=b.useCallback(I=>{var L;const W=y.current;if((W==null?void 0:W.touchIdentifier)===null&&I.changedTouches.length>0){const Y=Ag(I.changedTouches,{clientX:W.lastX,clientY:W.lastY});Y&&(W.touchIdentifier=Y.identifier)}if(W&&!fc(I.changedTouches,W.touchIdentifier)&&fc(I.touches,W.touchIdentifier))return;const j=A(vh)??((L=v.current)==null?void 0:L.kind);v.current=null,j==="longpress"&&I.stopPropagation()},[A]),P=b.useCallback(I=>{const W=y.current;W&&(I.preventDefault(),I.stopPropagation(),S(W))},[S]);return{onPointerDownCapture:D,onPointerMoveCapture:K,onPointerUpCapture:U,onPointerCancelCapture:X,onTouchStartCapture:z,onTouchMoveCapture:M,onTouchEndCapture:F,onTouchCancelCapture:B,onContextMenuCapture:P}}function pbe({terminalRef:e,containerEl:t,suppressPtyFocus:n,focusPtyInput:r,isSelectionActive:i,isGestureTarget:s,onTap:o,isTapCandidate:l,onLongPressCandidateStart:u,onLongPressStart:d,onLongPressMove:f,onLongPressEnd:p,onGestureFinish:y,getTouchScrollPosition:v,onVerticalScrollIntent:_,onHorizontalScrollIntent:w,onSelectionAutoscroll:S,onHandleDragStart:x,onHandleDragMove:k,onHandleDragEnd:T,onHandleDragCancel:R}){const N=b.useRef(null),A=b.useRef(null),O=b.useRef(null),D=b.useRef(!1),K=b.useRef(!1),U=b.useRef(null),X=b.useRef(null),z=b.useCallback(()=>{A.current=null,O.current=null,D.current=!1,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null)},[]),M=b.useCallback(()=>{var V;(V=U.current)==null||V.call(U),U.current=null,X.current=null,K.current=!1,z()},[z]),F=b.useCallback(()=>{var oe;N.current=null;const V=A.current;if(!V||!t||!i())return;const $=t.getBoundingClientRect(),{dx:te,dy:re}=r$({pointerX:V.clientX,pointerY:V.clientY,rect:$,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:44,maxSpeedPx:18});te!==0&&(w==null||w(`selectionGestureAutoscroll dx=${Math.round(te)}`),t.scrollLeft+=te),re!==0&&(D.current||(_==null||_(`selectionGestureAutoscroll dy=${Math.round(re)}`),D.current=!0),t.scrollTop+=re),(te!==0||re!==0)&&(S==null||S({scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}),(oe=O.current)==null||oe.call(O,V)),N.current=requestAnimationFrame(F)},[t,i,w,S,_]),B=b.useCallback((V,$)=>{A.current=V,O.current=$,N.current===null&&(N.current=requestAnimationFrame(F))},[F]);b.useEffect(()=>M,[M]),b.useEffect(()=>{const V=()=>{const te=X.current;te?te():M()},$=()=>{document.visibilityState==="hidden"&&V()};return window.addEventListener("blur",V),window.addEventListener("pagehide",V),document.addEventListener("visibilitychange",$),()=>{window.removeEventListener("blur",V),window.removeEventListener("pagehide",V),document.removeEventListener("visibilitychange",$)}},[M]),b.useEffect(()=>{if(!t)return;const V=$=>{K.current&&$.preventDefault()};return t.addEventListener("touchmove",V,{capture:!0,passive:!1}),document.addEventListener("touchmove",V,{capture:!0,passive:!1}),()=>{t.removeEventListener("touchmove",V,{capture:!0}),document.removeEventListener("touchmove",V,{capture:!0})}},[t]);const P=b.useCallback(V=>{M(),K.current=!0,d(V)},[d,M]),I=b.useCallback(V=>{if(!f(V)){z();return}B(V,f)},[f,z,B]),W=b.useCallback(V=>{M(),p(V)},[p,M]),j=hbe({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,isGestureTarget:s,onTap:o,isTapCandidate:l,onLongPressCandidateStart:u,onLongPressStart:P,onLongPressMove:I,onLongPressEnd:W,onGestureFinish:y,getScrollPosition:v}),L=b.useCallback((V,$)=>{if($.preventDefault(),$.stopPropagation(),U.current)return;M(),K.current=!0,x(V);const te=$.pointerId,re=$.currentTarget.getBoundingClientRect(),oe={x:$.clientX-(re.left+re.width/2),y:$.clientY-(re.top+re.height/2)},ee=(De,Se)=>({clientX:De-oe.x,clientY:Se-oe.y});let pe=()=>{};const ae=De=>{if(De.pointerId!==te)return;De.cancelable&&De.preventDefault();const Se=ee(De.clientX,De.clientY);k(V,Se),B(Se,Je=>k(V,Je))},me=De=>{if(De.pointerId!==te)return;const Se=ee(De.clientX,De.clientY);pe(),U.current=null,M(),T(V,Se)},Ee=De=>{De.pointerId===te&&(pe(),U.current=null,M(),R(V))};pe=()=>{window.removeEventListener("pointermove",ae),window.removeEventListener("pointerup",me),window.removeEventListener("pointercancel",Ee)},U.current=pe,X.current=()=>{M(),R(V)},window.addEventListener("pointermove",ae,{passive:!1}),window.addEventListener("pointerup",me),window.addEventListener("pointercancel",Ee)},[R,T,k,x,M,B]),Y=b.useCallback((V,$)=>{if(U.current)return;const te=$.touches[0]??$.changedTouches[0];if(!te)return;$.preventDefault(),$.stopPropagation(),K.current=!0,D.current=!1,x(V);const re=te.identifier,oe=$.currentTarget.getBoundingClientRect(),ee={x:te.clientX-(oe.left+oe.width/2),y:te.clientY-(oe.top+oe.height/2)},pe=Je=>{for(let Ht=0;Ht<Je.length;Ht+=1){const ye=Je[Ht];if((ye==null?void 0:ye.identifier)===re)return ye}return null},ae=(Je,Ht)=>({clientX:Je-ee.x,clientY:Ht-ee.y});let me=()=>{};const Ee=Je=>{const Ht=pe(Je.touches)??pe(Je.changedTouches);if(!Ht)return;Je.cancelable&&Je.preventDefault();const ye=ae(Ht.clientX,Ht.clientY);k(V,ye),B(ye,Ze=>k(V,Ze))},De=Je=>{const Ht=pe(Je.changedTouches);if(!Ht)return;const ye=Ht?ae(Ht.clientX,Ht.clientY):A.current;me(),U.current=null,M(),T(V,ye)},Se=Je=>{pe(Je.changedTouches)&&(me(),U.current=null,M(),R(V))};me=()=>{window.removeEventListener("touchmove",Ee),window.removeEventListener("touchend",De),window.removeEventListener("touchcancel",Se)},U.current=me,X.current=()=>{M(),R(V)},window.addEventListener("touchmove",Ee,{passive:!1}),window.addEventListener("touchend",De),window.addEventListener("touchcancel",Se)},[R,T,k,x,M,B]);return{pointerHandlers:j,stopPtySelectionGesture:M,handlePtySelectionHandlePointerDown:L,handlePtySelectionHandleTouchStart:Y}}const mbe=2,bO=600,gbe=160;function CC(){return/^(Macintosh|MacIntel|MacPPC|Mac68K)$/u.test(navigator.platform)}function a$(e,t){return CC()?t.altKey&&e.options.macOptionClickForcesSelection===!0:t.shiftKey}function vbe(e,t){return e.modes.mouseTrackingMode==="none"||a$(e,t)}function ybe(e,t){return t.altKey&&!(CC()&&e.options.macOptionClickForcesSelection===!0)}function _c(e,t){return e.row===t.row?e.column-t.column:e.row-t.row}function uv(e){const t=ms(e.anchor),n=ms(e.focus);return _c(t,n)<=0?{start:t,end:n}:{start:n,end:t}}function bbe(e,t){if(e.columnMode)return t.row>=Math.min(e.anchor.row,e.focus.row)&&t.row<=Math.max(e.anchor.row,e.focus.row)&&t.column>=Math.min(e.anchor.column,e.focus.column)&&t.column<=Math.max(e.anchor.column,e.focus.column);const{start:n,end:r}=uv(e);return _c(t,n)>=0&&_c(t,r)<=0}function _be(e){return e.key.toLowerCase()==="c"&&(CC()?e.metaKey:e.ctrlKey)}function ms(e){return{row:e.row,column:e.column}}function T0(e,t){const n=e.buffer.active;if(n.type!=="normal"||!Number.isInteger(t)||t<0||t>=n.length||!n.getLine(t))return null;let r;try{r=e.registerMarker(t-(n.baseY+n.cursorY))}catch{return null}return!r||r.isDisposed||r.line!==t?(r==null||r.dispose(),null):r}function wbe(e){const{terminalRef:t,xtermHostRef:n,selectionHandleLayerRef:r,scrollControllerRef:i,containerEl:s,keyboardOffset:o,ptyFontSize:l,suppressPtyFocus:u,focusPtyInput:d,onTap:f,isTapCandidate:p,onDownloadPath:y,onPreviewPath:v}=e,_=b.useRef(Kye()),w=b.useRef(null),S=b.useRef(null),x=b.useRef(new Map),k=b.useRef(null),T=b.useRef(null),R=b.useRef(""),N=b.useRef(!1),A=b.useRef(null),O=b.useRef(null),D=b.useRef(null),K=b.useRef(null),U=b.useRef("hide"),X=b.useRef(!1),z=b.useRef(0),M=b.useRef(0),F=b.useRef(null),B=b.useRef(null),P=b.useRef(0),I=b.useRef(o),[W,j]=b.useState(null),[L,Y]=b.useState(null),[V,$]=b.useState(null),te=b.useMemo(()=>tbe(l),[l]),re=b.useCallback(q=>{U.current=q,X.current=!1,z.current+=1,window.clearTimeout(M.current),M.current=0},[]),oe=b.useCallback((q,ne)=>{const G=window.visualViewport;return s$({clientX:q,clientY:ne,viewportWidth:(G==null?void 0:G.width)??window.innerWidth,viewportHeight:(G==null?void 0:G.height)??window.innerHeight,viewportOffsetLeft:(G==null?void 0:G.offsetLeft)??0,viewportOffsetTop:(G==null?void 0:G.offsetTop)??0})},[]),ee=b.useCallback(q=>{const ne=r.current;if(!ne||!s)return null;const G=ne.getBoundingClientRect(),de=s.getBoundingClientRect(),xe=window.visualViewport,Q=Math.max(de.left+s.clientLeft,(xe==null?void 0:xe.offsetLeft)??0),ie=Math.max(de.top+s.clientTop,(xe==null?void 0:xe.offsetTop)??0),le=Math.min(de.left+s.clientLeft+s.clientWidth,((xe==null?void 0:xe.offsetLeft)??0)+((xe==null?void 0:xe.width)??window.innerWidth)),he=Math.min(de.top+s.clientTop+s.clientHeight,((xe==null?void 0:xe.offsetTop)??0)+((xe==null?void 0:xe.height)??window.innerHeight)),Z={anchor:{left:q.anchor.left+G.left,top:q.anchor.top+G.top},focus:{left:q.focus.left+G.left,top:q.focus.top+G.top}},se=ce=>ce.left>=Q&&ce.left<=le&&ce.top>=ie&&ce.top<=he;return{clientHandles:Z,visible:{anchor:se(Z.anchor),focus:se(Z.focus)}}},[s,r]),pe=b.useCallback(q=>{const ne=ee(q);if(!ne)return null;const G=["anchor","focus"].filter(ie=>ne.visible[ie]);if(G.length===0)return null;const de=ne.clientHandles[G[0]],xe=ne.clientHandles[G[1]??G[0]],Q=window.visualViewport;return rbe({handles:{anchor:de,focus:xe},viewportWidth:(Q==null?void 0:Q.width)??window.innerWidth,viewportHeight:(Q==null?void 0:Q.height)??window.innerHeight,viewportOffsetLeft:(Q==null?void 0:Q.offsetLeft)??0,viewportOffsetTop:(Q==null?void 0:Q.offsetTop)??0})},[ee]),ae=b.useCallback(q=>{const ne=t.current,G=n.current;return!ne||!G?null:jv(G,q)??x.current.get(q)??ne.buffer.active.getLine(q)},[t,n]),me=b.useCallback(q=>{const ne=t.current,G=n.current,de=r.current;return!ne||!G||!de?null:nbe({terminal:ne,host:G,coordinateSpace:de,anchor:ms(q.anchor),focus:ms(q.focus),columnMode:q.columnMode,getLine:ae})},[ae,r,t,n]),Ee=b.useCallback(()=>{var ne;const q=t.current;return!q||!s||!q.element?null:(w.current&&S.current===q||((ne=w.current)==null||ne.dispose(),w.current=I4({terminal:q,container:s,getLine:ae}),S.current=q),w.current)},[s,ae,t]),De=b.useCallback((q,ne=!1)=>{const G=t.current,de=n.current;if(!G||!de)return;ne&&(x.current=new Map);const xe=Math.min(q.anchor.row,q.focus.row),Q=Math.max(q.anchor.row,q.focus.row),ie=L4(de);for(const[Z,se]of ie)Z>=xe&&Z<=Q&&x.current.set(Z,N4(se,G.cols));const le=Math.max(xe,G.buffer.active.viewportY),he=Math.min(Q,G.buffer.active.viewportY+G.rows-1);for(let Z=le;Z<=he;Z+=1)ie.has(Z)||x.current.delete(Z)},[t,n]),Se=b.useCallback(q=>{const ne=Math.min(q.anchor.row,q.focus.row),G=Math.max(q.anchor.row,q.focus.row);x.current=new Map(Array.from(x.current).filter(([de])=>de>=ne&&de<=G))},[]),Je=b.useCallback(()=>{const q=t.current,ne=n.current;if(!q||!ne)return null;const G=q.buffer.active,de=new Proxy(G,{get(Q,ie){if(ie==="getLine")return le=>x.current.get(le)??jv(ne,le)??Q.getLine(le);if(ie==="length"){let le=0;for(const he of x.current.keys())le=Math.max(le,he+1);return Math.max(Q.length,le)}return Reflect.get(Q,ie,Q)}}),xe=new Proxy(q.buffer,{get(Q,ie){return ie==="active"?de:Reflect.get(Q,ie,Q)}});return new Proxy(q,{get(Q,ie){return ie==="buffer"?xe:Reflect.get(Q,ie,Q)}})},[t,n]),Ht=b.useCallback((q,ne)=>{const G=ne??cbe(q);return T.current=G,$(G),G},[]),ye=b.useCallback((q,ne)=>{De(q);const G=Je();if(!G)return null;const de=jy({terminal:G,anchor:ms(q.anchor),focus:ms(q.focus),columnMode:q.columnMode});return de?(R.current=de.text,Ht(de.text,ne),de):null},[De,Je,Ht]),Ze=b.useCallback(()=>{const q=Ri(_.current);return q?ye(q):null},[ye]),Tt=b.useCallback((q,ne)=>{var xe;ne.toolbar==="hide"&&re("hide");let G=null;if(ne.toolbar==="hide"){De(q);const Q=Je();if(!Q||q.anchor.column>=Q.cols||q.focus.column>=Q.cols||!Q.buffer.active.getLine(q.anchor.row)||!Q.buffer.active.getLine(q.focus.row))return!1;R.current="",T.current=null,$(null)}else{if(!ye(q,ne.explicitPathAction))return!1;G=T.current}(xe=Ee())==null||xe.render(q),N.current=ne.handles;const de=ne.handles?me(q):null;return Y(de),ne.toolbar==="hide"?j(null):ne.toolbar==="path-only"&&!G?(re("hide"),j(null)):de?(re(ne.toolbar),j(pe(de))):ne.clientPoint?(re(ne.toolbar),j(oe(ne.clientPoint.clientX,ne.clientPoint.clientY))):(re("hide"),j(null)),!0},[Ee,De,Je,me,oe,pe,ye,re]),gt=b.useCallback(()=>{var ne,G;const q=k.current;if(q){k.current=null;for(const de of q.subscriptions)de.dispose();(ne=q.anchor)==null||ne.dispose(),(G=q.focus)==null||G.dispose()}},[]),Ot=b.useCallback(()=>{var q;(q=w.current)==null||q.render(null),N.current=!1,T.current=null,R.current="",re("hide"),j(null),Y(null),$(null)},[re]),an=b.useCallback(()=>{var q,ne,G;(q=B.current)==null||q.call(B),(ne=F.current)==null||ne.call(F),_.current=aa(_.current,{type:"clear-selection"}),x.current=new Map,gt(),A.current=null,O.current=null,D.current=null,K.current=null,(G=w.current)==null||G.dispose(),w.current=null,S.current=null,Ot()},[Ot,gt]),dt=b.useCallback(()=>{var q;an(),(q=t.current)==null||q.clearSelection()},[an,t]),Oe=b.useCallback((q,ne,G=!1)=>{const de=t.current,xe=n.current;return!de||!xe?null:Yye({terminal:de,host:xe,clientX:q,clientY:ne,clampToBuffer:G})},[t,n]),Ke=b.useCallback(()=>{var de;if(!N.current)return;const q=Ri(_.current);if(!q){Y(null),j(null);return}De(q),(de=Ee())==null||de.render(q);const ne=me(q);if(Y(ne),!ne){j(null);return}const G=U.current;j(G!=="hide"&&!X.current&&(G!=="path-only"||T.current)?pe(ne):null)},[De,Ee,me,pe]),ct=b.useCallback(q=>{gt();const ne=t.current;if(!ne)return!1;const G=ne.buffer.active,de=ne.cols,xe=ne.rows;if(G.type==="alternate"){const Z={terminal:ne,buffer:G,cols:de,rows:xe,anchor:null,focus:null,subscriptions:[],sync:()=>{}},se=()=>{k.current===Z&&(gt(),dt())};return Z.sync=()=>{k.current===Z&&(t.current!==ne||ne.buffer.active!==G||ne.cols!==de||ne.rows!==xe)&&se()},k.current=Z,Z.subscriptions.push(ne.onResize(Z.sync),ne.buffer.onBufferChange(se)),!0}const Q=T0(ne,q.anchor.row);if(!Q)return!1;const ie=T0(ne,q.focus.row);if(!ie||ne.buffer.active!==G||Q.isDisposed||Q.line!==q.anchor.row||ie.isDisposed||ie.line!==q.focus.row)return Q.dispose(),ie==null||ie.dispose(),!1;const le={terminal:ne,buffer:G,cols:de,rows:xe,anchor:Q,focus:ie,subscriptions:[],sync:()=>{}},he=()=>{k.current===le&&(gt(),dt())};return le.sync=()=>{var ze;if(k.current!==le)return;if(t.current!==ne||ne.buffer.active!==G||ne.cols!==de||Q.isDisposed||ie.isDisposed||Q.line<0||ie.line<0){he();return}const Z=_.current;if(Z.phase!=="selected"||Z.range.anchor.row===Q.line&&Z.range.focus.row===ie.line)return;const se=Q.line-Z.range.anchor.row,ce=ie.line-Z.range.focus.row;if(se!==ce){he();return}const Me={...Z.range,anchor:{...Z.range.anchor,row:Q.line},focus:{...Z.range.focus,row:ie.line}};if(_.current=aa(Z,{type:"set-selection",range:Me}),x.current=Wf(x.current,se),O.current&&(O.current={...O.current,row:O.current.row+se}),D.current){const Qe=ua(D.current.range,se);if(!Qe){he();return}D.current={range:Qe,lines:Wf(D.current.lines,se)}}(ze=Ee())==null||ze.render(Me),Ke()},k.current=le,le.subscriptions.push(Q.onDispose(he),ie.onDispose(he),ne.onWriteParsed(le.sync),ne.onResize(le.sync),ne.buffer.onBufferChange(he)),!0},[dt,Ee,Ke,gt,t]),ve=b.useCallback(()=>{if(!N.current)return;const q=Ri(_.current),ne=r.current,G=q?me(q):null;if(!ne)return;const de=G?ee(G):null;for(const xe of["anchor","focus"]){const Q=ne.querySelector(`[data-slot="pty-selection-handle"][data-kind="${xe}"]`);if(!Q)continue;const ie=G==null?void 0:G[xe];if(!ie){Q.style.visibility!=="hidden"&&(Q.style.visibility="hidden"),Q.style.pointerEvents!=="none"&&(Q.style.pointerEvents="none");continue}const le=(de==null?void 0:de.visible[xe])===!0||K.current===xe,he=`translate3d(${ie.left}px, ${ie.top}px, 0) translate(-50%, -50%)`,Z=le?"visible":"hidden",se=le?"auto":"none";Q.style.transform!==he&&(Q.style.transform=he),Q.style.visibility!==Z&&(Q.style.visibility=Z),Q.style.pointerEvents!==se&&(Q.style.pointerEvents=se)}},[ee,me,r]),$e=b.useCallback((q,ne,G=!1)=>{const de={anchor:ms(q.anchor),focus:ms(q.focus),columnMode:q.columnMode};return _.current=aa(_.current,{type:"set-selection",range:de}),G&&(x.current=new Map),!Tt(de,ne)||!ct(de)?(dt(),null):de},[ct,dt,Tt]);b.useEffect(()=>()=>{gt()},[gt]),b.useEffect(()=>{var q;return(q=w.current)==null||q.dispose(),w.current=null,S.current=null,()=>{var ne;(ne=w.current)==null||ne.dispose(),w.current=null,S.current=null}},[s]),b.useEffect(()=>{if(!s)return;const q=s.ownerDocument,ne=t.current;let G=null,de=1,xe=null,Q=!1,ie=null,le=()=>{};const he=()=>{var bt;const Pe=ie;if(Pe){ie=null;for(const xt of Pe.subscriptions)xt.dispose();(bt=Pe.marker)==null||bt.dispose()}},Z=()=>{xe!==null&&(cancelAnimationFrame(xe),xe=null)},se=()=>{G=null,Z(),he()};B.current=se;const ce=(Pe,bt)=>{const xt=Ri(_.current);xt&&(G&&(x.current=G.selectionLines),Tt(xt,{handles:!1,toolbar:"hide",clientPoint:{clientX:Pe,clientY:bt}}))},Me=(Pe,bt)=>{he();const xt=Pe.buffer.active,Te=xt.type==="normal"?T0(Pe,bt):null;if(xt.type==="normal"&&!Te)return!1;const nt={terminal:Pe,buffer:xt,cols:Pe.cols,rows:Pe.rows,marker:Te,markerLine:(Te==null?void 0:Te.line)??bt,subscriptions:[]},St=()=>{ie===nt&&(he(),le())},Yt=()=>{if(ie!==nt||!G)return;if(t.current!==Pe||Pe.buffer.active!==xt||Pe.cols!==nt.cols||xt.type==="alternate"&&Pe.rows!==nt.rows||Te!=null&&Te.isDisposed||Te!==null&&Te.line<0){St();return}if(!Te)return;const on=Te.line-nt.markerLine;if(on!==0){if(nt.markerLine=Te.line,_.current=Gye(_.current,on),G.initialRange=G.initialRange?ua(G.initialRange,on):null,G.selectionLines=Wf(G.selectionLines,on),G.selectionLinesBeforePress=Wf(G.selectionLinesBeforePress,on),x.current=Wf(x.current,on),_.current.phase!=="pressed"&&_.current.phase!=="selecting"){St();return}ce(G.lastX,G.lastY)}};return ie=nt,nt.subscriptions.push(Pe.onWriteParsed(Yt),Pe.onResize(Yt),Pe.buffer.onBufferChange(St)),Te&&nt.subscriptions.push(Te.onDispose(St)),!0},ze=(Pe,bt)=>{const xt=Je();return xt?bt==="line"?Vye({terminal:xt,point:Pe}):bt==="word"?E0({terminal:xt,point:Pe})??x0({terminal:xt,point:Pe}):null:null},Qe=Pe=>{if(!G||!Pe||G.unit==="cell"||!G.initialRange)return null;const bt=ze(Pe,G.unit);if(!bt)return G.initialRange;const xt=uv(G.initialRange),Te=uv({anchor:bt.anchor,focus:bt.focus});return _c(Te.end,xt.start)<0?{anchor:xt.end,focus:Te.start}:_c(Te.start,xt.end)>0?{anchor:xt.start,focus:Te.end}:G.initialRange},Ve=()=>{if(!G)return;const Pe=Oe(G.lastX,G.lastY,!0);_.current=aa(_.current,{type:"selection-autoscroll",pointerId:G.id,bufferPoint:Pe,range:Qe(Pe)}),ce(G.lastX,G.lastY)},mt=()=>{var St,Yt;if(xe=null,!G||!Vx(_.current))return;const Pe=s.getBoundingClientRect(),{dx:bt,dy:xt}=r$({pointerX:G.lastX,pointerY:G.lastY,rect:Pe,scrollLeft:s.scrollLeft,scrollTop:s.scrollTop,scrollWidth:s.scrollWidth,scrollHeight:s.scrollHeight,clientWidth:s.clientWidth,clientHeight:s.clientHeight}),Te=s.scrollLeft,nt=s.scrollTop;bt!==0&&((St=i.current)==null||St.markHorizontalScrollIntent(`managedSelectionAutoscroll dx=${Math.round(bt)}`),s.scrollLeft+=bt),xt!==0&&((Yt=i.current)==null||Yt.markSelectionAutoscrollIntent(`managedSelectionAutoscroll dy=${Math.round(xt)}`),s.scrollTop+=xt),(s.scrollLeft!==Te||s.scrollTop!==nt)&&Ve(),xe=requestAnimationFrame(mt)},vt=()=>{xe===null&&Vx(_.current)&&(xe=requestAnimationFrame(mt))},et=(Pe,bt,xt)=>{var Bt;if(!G)return;const Te=G,nt=_.current,St=Pe==="cancel"?"preserve-selection":nt.phase==="pressed"?Te.shiftExtend||Te.unit!=="cell"?"commit-selection":"clear-on-click":"commit-selection";_.current=aa(nt,{type:"gesture-finish",pointerId:Te.id,result:St}),x.current=St==="preserve-selection"?Te.selectionLinesBeforePress:St==="commit-selection"?Te.selectionLines:new Map,se(),St==="preserve-selection"&&((Bt=k.current)==null||Bt.sync());const Yt=Ri(_.current);if(!Yt){x.current=new Map,gt(),Ot();return}if(Se(Yt),!Tt(Yt,{handles:!1,toolbar:"path-only",clientPoint:{clientX:bt,clientY:xt}})){dt();return}St==="commit-selection"&&!ct(Yt)&&dt()};le=()=>{var Pe;G&&((Pe=t.current)==null||Pe.clearSelection(),et("cancel",G.lastX,G.lastY))};const Nt=Pe=>{if(Pe.button!==0)return;const bt=t.current,xt=Pe.target;if(!bt||!(xt instanceof Element))return;const Te=Oe(Pe.clientX,Pe.clientY,!1);if(!xt.closest(".xterm")&&!Te)return;const nt=a$(bt,Pe),St=iye(bt,Pe),Yt=bt.modes.mouseTrackingMode!=="none"&&!nt&&(Pe.metaKey||Pe.ctrlKey)&&St!==null;if(!vbe(bt,Pe)&&!Yt)return;G&&et("cancel",G.lastX,G.lastY),Pe.preventDefault(),Pe.stopImmediatePropagation(),bt.focus(),bt.clearSelection();const on=Ri(_.current),Bt=new Map(x.current),ue=de++,we=Pe.shiftKey&&on!==null&&Te!==null,be=on&&we?on.columnMode:ybe(bt,Pe),Re=we?"cell":Pe.detail===3?"line":Pe.detail===2?"word":"cell",at=we?new Map(Bt):new Map;x.current=at;const Et=Te?ze(Te,Re):null,ft=we?{anchor:on.anchor,focus:Te,columnMode:on.columnMode}:Et?{anchor:ms(Et.anchor),focus:ms(Et.focus)}:null;if(_.current=aa(_.current,{type:"pointer-press",candidate:{pointerId:ue,client:{x:Pe.clientX,y:Pe.clientY},bufferPoint:Te,columnMode:be}}),ft&&(_.current=aa(_.current,{type:"resolve-press-range",pointerId:ue,range:ft}),ce(Pe.clientX,Pe.clientY)),G={id:ue,startX:Pe.clientX,startY:Pe.clientY,lastX:Pe.clientX,lastY:Pe.clientY,shiftExtend:we,unit:Re,initialRange:ft,linkCandidate:Pe.detail===1&&!we&&!nt&&!be?St:null,selectionLinesBeforePress:Bt,selectionLines:at},Te&&!Me(bt,Te.row)){le();return}(we||Re!=="cell")&&queueMicrotask(()=>{t.current===bt&&bt.clearSelection()})},wt=Pe=>{var Te,nt;if(!G)return;if(Pe.buttons===0){(Te=t.current)==null||Te.clearSelection(),et("release",Pe.clientX,Pe.clientY);return}Pe.preventDefault(),Pe.stopImmediatePropagation(),G.lastX=Pe.clientX,G.lastY=Pe.clientY;const bt=_.current;if(bt.phase==="pressed"&&Math.hypot(Pe.clientX-G.startX,Pe.clientY-G.startY)<mbe)return;(nt=t.current)==null||nt.clearSelection(),G.linkCandidate=null;const xt=Oe(Pe.clientX,Pe.clientY,!0);_.current=aa(bt,{type:"pointer-move",pointerId:G.id,client:{x:Pe.clientX,y:Pe.clientY},bufferPoint:xt,range:Qe(xt)}),_.current.phase==="selecting"&&(ce(Pe.clientX,Pe.clientY),vt())},Zt=Pe=>{var nt,St;if(!G||Pe.button!==0)return;const bt=_.current.phase==="pressed"&&G.unit==="cell"&&!G.shiftExtend,xt=bt?G.linkCandidate:null;Pe.preventDefault(),Pe.stopImmediatePropagation(),(nt=t.current)==null||nt.clearSelection(),et("release",Pe.clientX,Pe.clientY),!((xt==null?void 0:xt.activateOnMouseUp(Pe))===!0)&&bt&&xt===null&&(f==null||f({clientX:Pe.clientX,clientY:Pe.clientY,pointerType:"mouse",altKey:Pe.altKey,ctrlKey:Pe.ctrlKey,metaKey:Pe.metaKey,shiftKey:Pe.shiftKey})),(St=t.current)==null||St.focus()},sn=()=>{var Pe;G&&((Pe=t.current)==null||Pe.clearSelection(),et("cancel",G.lastX,G.lastY))},ke=Pe=>{var bt;!G||Pe.pointerType!=="mouse"||((bt=t.current)==null||bt.clearSelection(),et("cancel",Pe.clientX,Pe.clientY))},je=()=>{var Pe;!G||q.visibilityState!=="hidden"||((Pe=t.current)==null||Pe.clearSelection(),et("cancel",G.lastX,G.lastY))},Ge=()=>{var Pe;G&&((Pe=t.current)==null||Pe.clearSelection(),et("cancel",G.lastX,G.lastY))},ot=Pe=>{var xt;const bt=((xt=Ze())==null?void 0:xt.text)??"";!bt||!Pe.clipboardData||(Q=!0,Pe.clipboardData.setData("text/plain",bt),Pe.preventDefault(),Pe.stopImmediatePropagation())},At=Pe=>{var bt;if(Ri(_.current)){if(_be(Pe)){const xt=((bt=Ze())==null?void 0:bt.text)??"";if(!xt)return;Pe.preventDefault(),Pe.stopImmediatePropagation(),Q=!1;try{q.execCommand("copy")}catch{}if(!Q){const Te=q.activeElement instanceof HTMLElement?q.activeElement:null;qx(xt,{allowLegacyFallback:!0}).finally(()=>{Te!=null&&Te.isConnected&&(q.activeElement===q.body||q.activeElement===null)&&Te.focus({preventScroll:!0})})}return}Pe.key==="Shift"||Pe.key==="Control"||Pe.key==="Meta"||Pe.key==="Alt"||dt()}},Kt=Pe=>{var we,be,Re;const bt=t.current,xt=Pe.target,Te=Oe(Pe.clientX,Pe.clientY,!1);if(!bt||!(xt instanceof Element)||!xt.closest(".xterm")&&!Te)return;const nt=Ri(_.current);if(Te&&(!nt||!bbe(nt,Te))){const at=x.current;x.current=new Map;const Et=Je();if(!Et){x.current=at;return}const ft=E0({terminal:Et,point:Te}),Sn=ft??x0({terminal:Et,point:Te});Sn?$e(Sn,{handles:!1,toolbar:"hide",clientPoint:{clientX:Pe.clientX,clientY:Pe.clientY},explicitPathAction:ft==null?void 0:ft.pathAction},!0):x.current=at}if(!Ri(_.current))return;const Yt=((we=Ze())==null?void 0:we.text)??"",on=(be=bt.element)==null?void 0:be.querySelector(".xterm-helper-textarea"),Bt=(Re=bt.element)==null?void 0:Re.querySelector(".xterm-screen");if(!on||!Bt)return;Pe.stopImmediatePropagation();const ue=Bt.getBoundingClientRect();Object.assign(on.style,{width:"20px",height:"20px",left:`${Pe.clientX-ue.left-10}px`,top:`${Pe.clientY-ue.top-10}px`,zIndex:"1000"}),on.value=Yt,on.focus({preventScroll:!0}),on.select()};return s.addEventListener("mousedown",Nt,!0),s.addEventListener("copy",ot,!0),s.addEventListener("keydown",At,!0),s.addEventListener("contextmenu",Kt,!0),q.addEventListener("mousemove",wt,!0),q.addEventListener("mouseup",Zt,!0),q.addEventListener("pointercancel",ke,!0),q.addEventListener("visibilitychange",je),window.addEventListener("blur",sn),window.addEventListener("pagehide",Ge),()=>{G?(ne==null||ne.clearSelection(),et("cancel",G.lastX,G.lastY)):se(),B.current===se&&(B.current=null),s.removeEventListener("mousedown",Nt,!0),s.removeEventListener("copy",ot,!0),s.removeEventListener("keydown",At,!0),s.removeEventListener("contextmenu",Kt,!0),q.removeEventListener("mousemove",wt,!0),q.removeEventListener("mouseup",Zt,!0),q.removeEventListener("pointercancel",ke,!0),q.removeEventListener("visibilitychange",je),window.removeEventListener("blur",sn),window.removeEventListener("pagehide",Ge)}},[ct,dt,Ot,s,Oe,Je,f,Tt,Se,Ze,gt,i,$e,t]),b.useLayoutEffect(()=>{if(!W&&!L&&!V)return;const q=ne=>{const G=ne.target;if(G instanceof Element&&G.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]'))return;const de="pointerType"in ne&&typeof ne.pointerType=="string"?ne.pointerType:null,xe=G instanceof Element&&G.closest(".xterm")!==null,Q=xe||G instanceof Element&&G.closest('[data-slot="pty-spacer"], [data-slot="pty-host"]')!==null,ie=!xe&&Q&&"clientX"in ne&&typeof ne.clientX=="number"&&"clientY"in ne&&typeof ne.clientY=="number"&&Oe(ne.clientX,ne.clientY,!1)!==null,le=G instanceof Element&&G.closest('[data-slot="pty-scrollbar"], [data-slot="pty-horizontal-scrollbar"]')!==null;Jye({hasManagedSelection:Ri(_.current)!==null,eventType:ne.type,pointerType:de,targetIsScrollSurface:le||Q&&(ne.type==="touchstart"||de==="touch")})||de==="mouse"&&(xe||ie)||dt()};return document.addEventListener("pointerdown",q,!0),document.addEventListener("touchstart",q,!0),()=>{document.removeEventListener("pointerdown",q,!0),document.removeEventListener("touchstart",q,!0)}},[dt,Oe,L,V,W]);const lt=L!==null;b.useLayoutEffect(()=>{lt&&ve()},[lt,L,ve]),b.useLayoutEffect(()=>{if(!lt||!s)return;const q=t.current;ve(),s.addEventListener("scroll",ve,{passive:!0});const ne=q==null?void 0:q.onScroll(ve),G=q==null?void 0:q.onRender(ve),de=q==null?void 0:q.onResize(ve),xe=new ResizeObserver(ve);xe.observe(s);const Q=r.current;Q&&xe.observe(Q);const ie=n.current;return ie&&xe.observe(ie),()=>{s.removeEventListener("scroll",ve),ne==null||ne.dispose(),G==null||G.dispose(),de==null||de.dispose(),xe.disconnect()}},[s,lt,r,ve,t,n]),b.useLayoutEffect(()=>{var ne;const q=I.current!==o;I.current=o,q&&(P.current=performance.now()+bO),lt&&((ne=i.current)==null||ne.relayout(),Ke(),ve())},[lt,o,Ke,i,ve]),b.useEffect(()=>{if(!lt)return;const q=window.visualViewport;let ne=0,G=0;const de=()=>{P.current=performance.now()+bO,cancelAnimationFrame(ne),window.clearTimeout(G),ne=requestAnimationFrame(()=>{Ke(),ve(),G=window.setTimeout(()=>{ne=requestAnimationFrame(()=>{Ke(),ve()})},160)})};return Ke(),ve(),window.addEventListener("resize",de),q==null||q.addEventListener("resize",de),q==null||q.addEventListener("scroll",de),()=>{cancelAnimationFrame(ne),window.clearTimeout(G),window.removeEventListener("resize",de),q==null||q.removeEventListener("resize",de),q==null||q.removeEventListener("scroll",de)}},[lt,Ke,ve]);const yt=b.useCallback(({clientX:q,clientY:ne})=>{u({blur:!1}),A.current=Oe(q,ne,!1)},[Oe,u]),pt=b.useCallback(({clientX:q,clientY:ne})=>{const G=t.current;if(!G)return;const de=Oe(q,ne,!1)??A.current;if(G.clearSelection(),!de){dt();return}x.current=new Map;const xe=Je();if(!xe)return;const Q=E0({terminal:xe,point:de}),ie=Q??x0({terminal:xe,point:de});if(!ie){dt();return}O.current=null,$e(ie,{handles:!0,toolbar:"hide",clientPoint:{clientX:q,clientY:ne},explicitPathAction:Q==null?void 0:Q.pathAction},!0)},[dt,Oe,Je,$e,t]),cn=b.useCallback(({clientX:q,clientY:ne})=>{const G=Oe(q,ne,!0),de=Ri(_.current);if(!G||!de)return!1;if(!O.current){const{start:Q,end:ie}=uv(de),le=_c(G,Q),he=_c(G,ie);if(le>=0&&he<=0)return!1;O.current=ms(le<0?ie:Q)}const xe={anchor:O.current,focus:G,text:""};return $e(xe,{handles:!0,toolbar:"hide",clientPoint:{clientX:q,clientY:ne}})!==null},[Oe,$e]),qt=b.useCallback(q=>{const ne=Ri(_.current);ne&&(Se(ne),Tt(ne,{handles:!0,toolbar:"show",clientPoint:q}))},[Tt,Se]),Gt=b.useCallback(()=>{const q=U.current;if(q==="hide"||K.current!==null)return;const ne=Ri(_.current);if(!ne||!Ze()||q==="path-only"&&!T.current)return;const G=me(ne);j(G?pe(G):null)},[me,pe,Ze]);b.useLayoutEffect(()=>{if(!s)return;const q=s.ownerDocument,ne=q.defaultView??window;let G=!1;const de=()=>{window.clearTimeout(M.current),M.current=0},xe=()=>{if(de(),G||!X.current||U.current==="hide"||q.visibilityState==="hidden")return;const ce=++z.current;M.current=window.setTimeout(()=>{M.current=0,!(ce!==z.current||G||U.current==="hide"||q.visibilityState==="hidden")&&(X.current=!1,Gt())},gbe)},Q=()=>{U.current!=="hide"&&(X.current=!0,j(null),xe())},ie=ce=>{ce.touches.length!==0&&(G=!0,z.current+=1,de())},le=ce=>{ce.touches.length>0||(G=!1,xe())},he=()=>{G=!1,z.current+=1,de()},Z=()=>{q.visibilityState==="hidden"?he():xe()},se=()=>xe();return s.addEventListener("scroll",Q,{passive:!0}),s.addEventListener("touchstart",ie,{passive:!0,capture:!0}),q.addEventListener("touchend",le,{passive:!0,capture:!0}),q.addEventListener("touchcancel",le,{passive:!0,capture:!0}),q.addEventListener("visibilitychange",Z),ne.addEventListener("blur",he),ne.addEventListener("focus",se),ne.addEventListener("pagehide",he),ne.addEventListener("pageshow",se),()=>{z.current+=1,X.current=!1,de(),s.removeEventListener("scroll",Q),s.removeEventListener("touchstart",ie,!0),q.removeEventListener("touchend",le,!0),q.removeEventListener("touchcancel",le,!0),q.removeEventListener("visibilitychange",Z),ne.removeEventListener("blur",he),ne.removeEventListener("focus",se),ne.removeEventListener("pagehide",he),ne.removeEventListener("pageshow",se)}},[s,Gt]);const yn=b.useCallback(({clientX:q,clientY:ne})=>{A.current=null,O.current=null,qt({clientX:q,clientY:ne})},[qt]),dn=b.useCallback(()=>{var ne;const q=((ne=Ze())==null?void 0:ne.text)??"";q&&qx(q,{allowLegacyFallback:!0}).then(G=>{dt(),G==="failed"?Xe.error("复制失败"):Xe.success("已复制")})},[dt,Ze]),Ft=b.useCallback(()=>{if(!Ze())return;const q=T.current;q&&(q.kind==="image-preview"?v(q.path):y(q.path),dt())},[dt,y,v,Ze]),nn=b.useCallback(()=>Ri(_.current)!==null,[]),rn=b.useCallback(()=>!s||performance.now()<=P.current?null:{scrollLeft:s.scrollLeft,scrollTop:s.scrollTop},[s]),Yn=b.useCallback(q=>{K.current=q;const ne=Ri(_.current);D.current=ne?{range:{...ne,anchor:{...ne.anchor},focus:{...ne.focus}},lines:new Map(x.current)}:null,re("hide"),j(null)},[re]),Fn=b.useCallback((q,{clientX:ne,clientY:G})=>{const de=Oe(ne,G,!0),xe=Ri(_.current);if(!de||!xe)return;const Q={anchor:q==="anchor"?de:ms(xe.anchor),focus:q==="focus"?de:ms(xe.focus),columnMode:xe.columnMode,text:""};$e(Q,{handles:!0,toolbar:"hide",clientPoint:{clientX:ne,clientY:G}})},[Oe,$e]),Jn=b.useCallback((q,ne)=>{K.current=null,D.current=null,qt(ne??void 0)},[qt]),lr=b.useCallback(()=>{K.current=null;const q=D.current;if(D.current=null,!q){qt();return}if(x.current=q.lines,_.current=aa(_.current,{type:"set-selection",range:q.range}),!Tt(q.range,{handles:!0,toolbar:"show"})){dt();return}ct(q.range)||dt()},[ct,dt,Tt,qt]),fn=pbe({terminalRef:t,containerEl:s,suppressPtyFocus:u,focusPtyInput:d,isSelectionActive:nn,isGestureTarget:({clientX:q,clientY:ne})=>Oe(q,ne,!1)!==null,onTap:f,isTapCandidate:p,onLongPressCandidateStart:yt,onLongPressStart:pt,onLongPressMove:cn,onLongPressEnd:yn,getTouchScrollPosition:rn,onGestureFinish:q=>{ebe(q)&&dt()},onVerticalScrollIntent:q=>{var ne;return(ne=i.current)==null?void 0:ne.markSelectionAutoscrollIntent(q)},onHorizontalScrollIntent:q=>{var ne;return(ne=i.current)==null?void 0:ne.markHorizontalScrollIntent(q)},onHandleDragStart:Yn,onHandleDragMove:Fn,onHandleDragEnd:Jn,onHandleDragCancel:lr});return F.current=fn.stopPtySelectionGesture,{pointerHandlers:fn.pointerHandlers,ptySelectionToolbar:W,ptySelectionHandles:L,ptySelectionPathAction:V,ptySelectionHandleMetrics:te,hasPtySelection:nn,clearManagedPtySelection:an,clearPtySelection:dt,copyPtySelection:dn,openPtySelectionPathAction:Ft,handlePtySelectionHandlePointerDown:fn.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:fn.handlePtySelectionHandleTouchStart}}function Sbe(){return Le(e=>e.ptyScrollTraceEnabled)}const xbe=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function _O(e){return xbe.has(e)}function kC(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!_O(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>_O(r.type))??null}function Ebe(e){return`${e.startsWith("@")?e:`@${e}`} `}async function l$(e){const t=kC(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await t$(t),r=await e.relay.uploadClipboardImage(e.sessionId,n);if(!r.success||!r.path)throw new Error(r.error??"剪贴板图片上传失败");return{path:r.path,pathMention:Ebe(r.path)}}function Cbe(e){if(!(e!=null&&e.files)||e.files.length===0)return null;for(const t of e.files)if(!t.type.startsWith("image/"))return t;return null}function kbe({sessionId:e,terminalRef:t,onAfterPaste:n}){return b.useCallback(async r=>{var u;const i=r.clipboardData,s=!!kC(i),o=s?null:Cbe(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Ut;if(!l){Xe.error("请先连接开发机");return}if(s){const d=Xe.loading("图片上传中...");try{const f=await l$({clipboardData:i,relay:l,sessionId:e});if(Xe.dismiss(d),!f)return;to(e,f.pathMention)}catch(f){Xe.error(f instanceof Error?f.message:String(f),{id:d});return}}else if(o){const d=await Qh({relay:l,sessionId:e,file:o});if(!d)return;to(e,`@${d} `)}n==null||n(),(u=t.current)==null||u.focus()},[e,t,n])}const Tbe=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),wO={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:Fx};function Rbe({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function Abe({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function Mbe({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function Nbe({active:e,touchEditingSurface:t,key:n,code:r,altKey:i=!1,ctrlKey:s=!1,metaKey:o=!1,isComposing:l=!1,targetAcceptsPtyInput:u=!0}){return!e||!t||!u||l||i||s||o||!r||r==="Unidentified"?!1:n.length===1?!0:n==="Unidentified"||n==="Process"||n==="Dead"?!1:Tbe.has(n)}const SO=8,Pbe=32;function Obe({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+SO:t?Pbe:SO}function Lbe(e,t){return e.isComposing||e.altKey||e.ctrlKey||e.metaKey?null:e.key.length===1?e.key:e.key==="Enter"?"\r":e.key==="Backspace"?"":e.key==="Tab"?e.shiftKey?"\x1B[Z":" ":e.key==="Escape"?"\x1B":e.key==="ArrowUp"?gh("\x1B[A",t):e.key==="ArrowDown"?gh("\x1B[B",t):e.key==="ArrowRight"?gh("\x1B[C",t):e.key==="ArrowLeft"?gh("\x1B[D",t):e.key==="Delete"?"\x1B[3~":e.key==="Home"?"\x1B[H":e.key==="End"?"\x1B[F":null}function Dbe(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,selectionHandleLayerRef:o,mobileControlsHeight:l}=e,u=Mye(),d=u.markDisconnected,f=Lye(),p=Sbe(),{openImagePreview:y}=XE(),v=b.useRef(null),_=b.useRef(null),w=b.useRef(null),S=b.useRef(!1),x=b.useRef([]),k=b.useRef(null),T=b.useRef(null),R=b.useRef(n),N=b.useRef(n),A=b.useRef(!1),O=b.useRef(!1),D=b.useRef(!1),K=b.useRef(!1),U=b.useRef(null),X=b.useRef(null),z=b.useRef(null),M=b.useRef(null),F=b.useRef({keyboardOpen:!1,controlsVisible:!1}),B=b.useRef(!1),P=b.useRef(!1),I=b.useRef(!1),W=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[j,L]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[Y,V]=b.useState(!1),[$,te]=b.useState(!1),[re,oe]=b.useState({resultIndex:-1,resultCount:0}),ee=Le(ke=>ke.connected),pe=Le(ke=>ke.proxyOnline),ae=Le(ke=>ke.ptyFontSize),me=Le(ke=>ke.inputModePreference),Ee=Le(ke=>ke.adaptiveInputModality),De=Le(ke=>ke.setAdaptiveInputModality),Se=Ee==="hardware",Je=Al("(pointer: coarse), (hover: none)"),{bottomOffset:Ht,layoutBottomInset:ye}=EC(),Ze=me==="hardware",Tt=Mbe({touchEditingSurface:Je,inputModePreference:me,detectedPhysicalKeyboard:Se,softKeyboardDetected:Ht>0}),gt=Je&&!Tt,Ot=Tt?0:Ht,an=Ot>0,dt=Tt?0:ye,[Oe,Ke]=b.useState(()=>ee&&pe);B.current=Tt,R.current=n,A.current=u.ready,O.current=ee&&pe;const ct=b.useCallback(()=>R.current&&A.current&&O.current,[]);b.useEffect(()=>{ee&&pe&&Ke(!0)},[ee,pe]),b.useEffect(()=>{Ot>0&&V(!0)},[Ot]);const ve=Oye({containerEl:r,xtermHostRef:s,terminalRef:v}),{ptyInputFocused:$e,suppressPtyFocus:lt,focusPtyInput:yt,handleFocusCapture:pt,handleBlurCapture:cn}=ve,qt=Rbe({softKeyboardEditingSurface:gt,ptyInputFocused:$e,keyboardOpen:an});W.current={keyboardOffset:Ot,hasSeenSoftKeyboard:Y,showMobilePtyControls:qt,touchEditingSurface:Je,ptyInputFocused:$e,containerPaddingBottom:W.current.containerPaddingBottom,mobileControlsBottomInset:dt};const Gt=f.clearNewFramesWhileAway;X.current||(X.current=aO(()=>{var ke;(ke=T.current)==null||ke.relayout()}));const yn=b.useCallback(()=>{I.current=!1},[]);z.current||(z.current=aO(()=>{var je,Ge;const ke=M.current??{reason:"rawInput",force:!1};M.current=null,ke.force&&yn(),(je=T.current)==null||je.traceRawInputFollowFire(),(Ge=T.current)==null||Ge.scrollToBottom(ke.reason,ke.force?{force:!0}:void 0),Gt()}));const dn=b.useCallback(()=>{if(I.current)return;const ke=T.current;ke&&ke.preparePageResumeRestore(),I.current=!0},[]),Ft=b.useCallback(()=>{if(!I.current||document.visibilityState==="hidden"||!R.current||!A.current)return;const ke=T.current;ke&&(ke.restorePageResume(),Gt(),I.current=!1)},[Gt]);b.useEffect(()=>()=>{var ke,je;(ke=X.current)==null||ke.dispose(),(je=z.current)==null||je.dispose(),X.current=null,z.current=null},[]),b.useEffect(()=>{const ke=()=>{dn()},je=()=>{if(document.visibilityState==="hidden"){ke();return}Ft()};return document.addEventListener("visibilitychange",je),window.addEventListener("pagehide",ke),window.addEventListener("pageshow",Ft),window.addEventListener("focus",Ft),()=>{document.removeEventListener("visibilitychange",je),window.removeEventListener("pagehide",ke),window.removeEventListener("pageshow",Ft),window.removeEventListener("focus",Ft)}},[dn,Ft]),b.useLayoutEffect(()=>{const ke=N.current;if(N.current=n,!n){ke&&dn();return}(!ke||I.current)&&u.ready&&Ft()},[n,u.ready,dn,Ft]);const nn=b.useCallback((ke="rawInput",je)=>{var At,Kt;const Ge=M.current,ot=(Ge==null?void 0:Ge.force)===!0||(je==null?void 0:je.force)===!0;M.current={reason:(je==null?void 0:je.force)===!0||!Ge?ke:Ge.reason,force:ot},(At=T.current)==null||At.traceRawInputFollowScheduled(ke),(Kt=z.current)==null||Kt.schedule()},[]),rn=b.useCallback((ke,je)=>{var Ge;!ke.includes("\r")&&!ke.includes(`
670
670
  `)||(Ge=T.current)==null||Ge.resetHorizontalScroll(je,{holdUntilCursorVisible:!0})},[]),Yn=b.useCallback(()=>B.current?"submit":"linefeed",[]),Fn=b.useCallback(()=>B.current,[]);b.useEffect(()=>{if(!n||me!=="auto"||!Je)return;const ke=Ge=>{const ot=s.current,At=r;return Ge instanceof Node?ot!=null&&ot.contains(Ge)||Ge===document.body||Ge===document.documentElement?!0:At!=null&&At.contains(Ge)?Ge instanceof HTMLElement?Ge.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:Ge===window},je=Ge=>{var Kt,Pe;if(!Nbe({active:R.current,touchEditingSurface:Je,key:Ge.key,code:Ge.code,altKey:Ge.altKey,ctrlKey:Ge.ctrlKey,metaKey:Ge.metaKey,isComposing:Ge.isComposing,targetAcceptsPtyInput:ke(Ge.target)}))return;De("hardware"),B.current=!0,(Kt=v.current)==null||Kt.focus();const ot=s.current;if(Ge.target instanceof Node&&(ot!=null&&ot.contains(Ge.target)))return;const At=Lbe(Ge,(Pe=v.current)==null?void 0:Pe.modes);!At||!ct()||(Ge.preventDefault(),Ge.stopPropagation(),to(t,At),nn("physicalKeyboard"),rn(At,"physicalKeyboardEnter"))};return window.addEventListener("keydown",je,!0),()=>window.removeEventListener("keydown",je,!0)},[n,ct,r,me,rn,nn,t,De,Je,s]);const Jn=b.useCallback(ke=>{const je=Ut;if(!je){Xe.error("请先连接开发机");return}const Ge=Xe.loading(`下载 ${ke} ...`);KE({relay:je,sessionId:t,path:ke}).then(ot=>{ot.ok?Xe.success(`已开始下载 ${ke}`,{id:Ge}):Xe.error(ot.error,{id:Ge})}).catch(ot=>{Xe.error(ot instanceof Error?ot.message:String(ot),{id:Ge})})},[t]),lr=b.useCallback(ke=>{const je=v.current;return je?aye(je,x.current,ke):!1},[]),fn=b.useCallback(ke=>{const je=v.current;return je?oye(je,x.current,ke):!1},[]),q=wbe({terminalRef:v,xtermHostRef:s,selectionHandleLayerRef:o,scrollControllerRef:T,containerEl:r,keyboardOffset:Ot,ptyFontSize:ae,suppressPtyFocus:lt,focusPtyInput:yt,onTap:lr,isTapCandidate:fn,onDownloadPath:Jn,onPreviewPath:y}),ne=q.clearManagedPtySelection,G=q.clearPtySelection;P.current=q.hasPtySelection();const de=b.useCallback(()=>{const ke=v.current,je=w.current,Ge=S.current&&ke?ZP(ke.getSelectionPosition(),ke.cols):null;je==null||je.render(Ge)},[]),xe=kbe({sessionId:t,terminalRef:v,onAfterPaste:()=>nn("paste")}),Q=b.useCallback(ke=>{if(!ct()){ke.preventDefault();return}xe(ke)},[ct,xe]),[ie,le]=b.useState(!1),he=b.useCallback(ke=>{ke.dataTransfer.types.includes("Files")&&(ke.preventDefault(),le(je=>je||!0))},[]),Z=b.useCallback(ke=>{ke.currentTarget.contains(ke.relatedTarget)||le(!1)},[]),se=b.useCallback(async ke=>{var At;const je=(At=ke.dataTransfer.files)==null?void 0:At[0];if(!je||(ke.preventDefault(),le(!1),!ct()))return;const Ge=Ut;if(!Ge){Xe.error("请先连接开发机");return}const ot=await Qh({relay:Ge,sessionId:t,file:je});ot&&(to(t,`@${ot} `),nn("dropUpload"))},[ct,nn,t]),ce=b.useCallback(ke=>{var Ge;if(!ct()){ke.preventDefault();return}const je=ke.target;je instanceof Element&&je.closest(".xterm")||(ke.preventDefault(),(Ge=v.current)==null||Ge.focus())},[ct]);b.useEffect(()=>{if(!Oe)return;const ke=s.current,je=wc,Ge=Ut,ot=r,At=i.current;if(!ke||!je||!Ge||!ot||!At)return;let Kt=null,Pe=null,bt=null,xt=null,Te=null,nt=null,St=null,Yt=null;const we=wve({host:ke,sessionId:t,ws:je,relay:Ge,scheduleAutoFocus:gt?()=>{}:be=>{requestAnimationFrame(()=>{fO(s.current)&&be()})},createTerminal:async be=>{const Re=await M4(be,{fontSize:Le.getState().ptyFontSize});return Yt=Re.serializeAddon,Re},attachRawInput:(be,Re,at)=>Rge(be,Re,{...at,getPlainEnterBehavior:Yn,isPhysicalKeyboardMode:Fn,physicalKeyboardMode:Ze}),isInputEnabled:ct,canFocus:ct,onTerminalReady:be=>{G();const Re=be;v.current=Re;const at=new xde({highlightLimit:1e3});Re.loadAddon(at),_.current=at,Te=at.onDidChangeResults(Nn=>{oe(Nn),de()}),te(!0);const Et=jve(Re,y);Kt=Et.dispose;const ft=Jve(Re,Jn);Pe=ft.dispose,x.current=[Et.provider,ft.provider],Eye(()=>v.current);const Sn=Qme(Re),sr=oge(ke,{serializeRangeAsHtml:(Nn,_r)=>(Yt==null?void 0:Yt.serializeAsHTML({range:{startLine:Nn,endLine:Math.min(_r,Math.max(0,Re.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??"",getSerializedCell:(Nn,_r)=>{var mi;const Tn=(mi=Re.buffer.active.getLine(Nn))==null?void 0:mi.getCell(_r);return Tn?{text:Tn.getWidth()===0?"":Tn.getChars()||" ",isDim:!!Tn.isDim(),isRenderedFgRGB:Tn.isInverse()?Tn.isBgRGB():Tn.isFgRGB()}:null},getSelectionLine:Nn=>Re.buffer.active.getLine(Nn)??null,getBufferRowIdentityOffset:Sn.getOffset});xt=()=>{sr.dispose(),Sn.dispose()};const Xn=I.current;Xn&&(K.current=!1);const ii=hve({container:ot,spacer:At,host:ke,term:Re,hasNewFrame:()=>D.current,consumeNewFrame:()=>{D.current=!1},hasNewFramesWhileAway:()=>f.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:f.setHasNewFramesWhileAway,onAtBottomChange:f.handleAtBottomChange,onScrollStateChange:L,initialUserHasVerticalScrollIntent:Xn?!1:K.current,onUserVerticalScrollIntentChange:Nn=>{K.current=Nn},onTouchReviewStart:lt,onHistoryProjectionChange:Nn=>{const _r=sr.render(Nn);return _r&&de(),_r},getBufferRowIdentityOffset:Sn.getOffset});T.current=ii,bt=ii.dispose,St=I4({terminal:Re,container:ot,getLine:Nn=>jv(ke,Nn)??Re.buffer.active.getLine(Nn)??null,resolveRange:()=>S.current?ZP(Re.getSelectionPosition(),Re.cols):null,projectionOnly:!0,overlaySlot:"pty-search-selection-overlay",segmentSlot:"pty-search-selection-segment",selectionBackground:Fx.activeMatchBackground,borderColor:Fx.activeMatchBorder,opacity:"0.62"}),w.current=St,nt=Re.onSelectionChange(de),de(),Xn&&(ii.restorePageResume(),Gt(),I.current=!1),kye(()=>{var Ul;const Nn=wr=>{if(!wr)return null;const Pn=wr.getBoundingClientRect();return{top:Pn.top,bottom:Pn.bottom,height:Pn.height,left:Pn.left,right:Pn.right,width:Pn.width}},_r=document.querySelector('[data-slot="pty-mobile-controls"]'),Tn=document.querySelector("[data-keyboard-offset]"),mi=window.visualViewport,lo=Nn(_r),Qt=(mi==null?void 0:mi.height)??window.innerHeight;return{...Rye(ii.getDebugProbe,{container:ot,spacer:At,host:ke,term:Re}),mobileLayout:{...W.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:mi?{height:mi.height,width:mi.width,offsetTop:mi.offsetTop,pageTop:mi.pageTop,scale:mi.scale}:null,chatRoot:{dataKeyboardOffset:(Tn==null?void 0:Tn.getAttribute("data-keyboard-offset"))??null,rect:Nn(Tn)},ptyViewRect:Nn(ot.parentElement),containerRect:Nn(ot),controlsRect:lo,controlsOverflowBelowVisualViewport:lo===null?null:lo.bottom-Qt,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(Ul=document.activeElement.closest("[data-slot]"))==null?void 0:Ul.getAttribute("data-slot")}:null},frame:{lastWriteAt:U.current,pendingNewFrame:D.current}}})},onFramePending:()=>{var be;D.current=!0,(be=T.current)==null||be.markHorizontalLiveFramePending(),K.current&&!f.hasNewFramesWhileAwayRef.current&&f.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var be;U.current=performance.now(),(be=X.current)==null||be.schedule()},onRawInput:be=>{Age(be)||(nn("rawInput",{force:!0}),rn(be,"rawInputEnter"))},onError:be=>{const Re=be instanceof Error?be.message:String(be);Xe.error(`终端初始化失败:${Re}`)},connectTransportInitially:ee&&pe,...u.transport});return k.current=we,()=>{S.current=!1,nt==null||nt.dispose(),St==null||St.dispose(),w.current===St&&(w.current=null),G(),bt==null||bt(),xt==null||xt(),Te==null||Te.dispose(),Tye(),Kt==null||Kt(),Pe==null||Pe(),x.current=[],Cye(),_.current=null,te(!1),oe({resultIndex:-1,resultCount:0}),we.dispose(),v.current=null,T.current=null,k.current=null}},[t,Oe,r,i,s,u.transport,f.handleAtBottomChange,f.hasNewFramesWhileAwayRef,f.setHasNewFramesWhileAway,ct,Ze,Yn,Fn,Jn,y,lt,nn,rn,G,de]),b.useEffect(()=>{if(!Oe)return;const ke=k.current;if(ke){if(!ee||!pe){d(),ke.setTransportActive(!1);return}return xve(t,n?"active":"background",()=>{var je;(je=k.current)==null||je.setTransportActive(!0)})}},[n,ee,d,pe,t,Oe]),b.useEffect(()=>{const ke=v.current,je=T.current;!ke||!je||Zme(ke,ae,je.relayout)},[ae]),b.useEffect(()=>{if(!n||!u.ready||gt)return;const ke=requestAnimationFrame(()=>{var je;fO(s.current)&&((je=v.current)==null||je.focus())});return()=>cancelAnimationFrame(ke)},[n,u.ready,gt,s]);const Me=b.useCallback((ke="viewExternal",je)=>{var Ge;je!=null&&je.force&&yn(),(Ge=T.current)==null||Ge.scrollToBottom(ke,je)},[yn]),ze=b.useCallback(ke=>{var je;(je=T.current)==null||je.scrollToRatio(ke)},[]),Qe=b.useCallback(ke=>{var je;(je=T.current)==null||je.scrollToXRatio(ke)},[]),Ve=b.useCallback(ke=>{var Pe;const je=v.current,Ge=je==null?void 0:je.getSelectionPosition();if(!je||!Ge)return;const ot=Ge.start.y;if(ot>=ke&&ot<ke+je.rows)return;const At=Math.max(0,je.buffer.active.length-je.rows);if(At===0)return;const Kt=Math.max(0,Math.min(At,ot-Math.floor(je.rows/2)));(Pe=T.current)==null||Pe.scrollToRatio(Kt/At)},[]),mt=b.useCallback((ke,je=!1)=>{const Ge=v.current,ot=_.current;if(!Ge||!ot||!ke)return ke||(S.current=!1,ot==null||ot.clearDecorations(),Ge==null||Ge.clearSelection(),ne(),de(),oe({resultIndex:-1,resultCount:0})),!1;ne(),S.current=!0;const At=Ge.buffer.active.viewportY,Kt=ot.findNext(ke,{...wO,incremental:je});return Kt&&Ve(At),de(),Kt},[ne,de,Ve]),vt=b.useCallback(ke=>{const je=v.current,Ge=_.current;if(!je||!Ge||!ke)return!1;ne(),S.current=!0;const ot=je.buffer.active.viewportY,At=Ge.findPrevious(ke,wO);return At&&Ve(ot),de(),At},[ne,de,Ve]),et=b.useCallback(()=>{var ke,je;S.current=!1,(ke=_.current)==null||ke.clearDecorations(),(je=v.current)==null||je.clearSelection(),ne(),de(),oe({resultIndex:-1,resultCount:0})},[ne,de]),Nt=b.useCallback(ke=>{var Ge,ot;if(!ct())return;const je=gh(ke,(Ge=v.current)==null?void 0:Ge.modes);to(t,je),nn("mobileControl",{force:!0}),rn(ke,"mobileControlEnter"),(ot=v.current)==null||ot.focus()},[ct,rn,nn,t]),wt=b.useCallback(()=>{var je,Ge,ot;if(!ct())return;const ke=(Ge=(je=navigator.clipboard)==null?void 0:je.readText)==null?void 0:Ge.bind(navigator.clipboard);if(!window.isSecureContext||!ke){Xe.error("无法读取剪贴板"),(ot=v.current)==null||ot.focus();return}ke().then(At=>{if(!At)return;const Kt=v.current;if(Kt){Kt.paste(At);return}to(t,At),nn("paste"),rn(At,"pasteEnter")}).catch(At=>{const Kt=At instanceof Error&&At.message?At.message:"无法读取剪贴板";Xe.error(Kt)}).finally(()=>{var At;return(At=v.current)==null?void 0:At.focus()})},[ct,rn,nn,t]),Zt=Obe({showMobilePtyControls:qt,horizontalScrollable:j.horizontalScrollable,mobileControlsHeight:l});W.current.containerPaddingBottom=Zt,b.useEffect(()=>{var Ge,ot;P.current?(Ge=T.current)==null||Ge.relayout():(ot=X.current)==null||ot.schedule();const ke=F.current,je=Abe({controlsVisible:qt,keyboardOpen:an,previous:ke});F.current={keyboardOpen:an,controlsVisible:qt},qt&&(P.current?Gt():je&&nn("keyboardOffset",{force:!0}))},[Ot,an,qt,Zt,Gt,nn]);const sn=b.useMemo(()=>({onFocusCapture:pt,onBlurCapture:cn}),[pt,cn]);return{scrollState:j,isAtBottom:f.isAtBottom,hasNewFramesWhileAway:f.hasNewFramesWhileAway,ptyInputFocused:$e,showMobilePtyControls:qt,touchEditingSurface:Je,keyboardOffset:Ot,physicalKeyboardMode:Tt,softKeyboardEditingSurface:gt,mobileControlsBottomInset:dt,connectionReady:u.ready,connectionOverlay:u.overlay,containerPaddingBottom:Zt,traceEnabled:p,findReady:$,findResultIndex:re.resultIndex,findResultCount:re.resultCount,findNext:mt,findPrevious:vt,clearFind:et,scrollToBottom:Me,scrollToRatio:ze,scrollToXRatio:Qe,clearNewFramesWhileAway:Gt,sendMobileInput:Nt,pasteMobileClipboard:wt,handleTerminalContainerMouseDown:ce,handlePasteCapture:Q,pointerHandlers:q.pointerHandlers,focusHandlers:sn,ptySelectionToolbar:q.ptySelectionToolbar,ptySelectionHandles:q.ptySelectionHandles,ptySelectionPathAction:q.ptySelectionPathAction,ptySelectionHandleMetrics:q.ptySelectionHandleMetrics,copyPtySelection:q.copyPtySelection,openPtySelectionPathAction:q.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:q.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:q.handlePtySelectionHandleTouchStart,isPtyDragOver:ie,handlePtyDragOver:he,handlePtyDragLeave:Z,handlePtyDrop:se}}function Ibe({sessionId:e,sessionKind:t,provider:n,active:r=!0,findRequest:i}){const[s,o]=b.useState(null),[l,u]=b.useState(0),[d,f]=b.useState(!1),[p,y]=b.useState(""),v=b.useRef(null),_=b.useRef(null),w=b.useRef(null),S=Dbe({sessionId:e,active:r,containerEl:s,spacerRef:v,xtermHostRef:_,selectionHandleLayerRef:w,mobileControlsHeight:l}),x=S.ptySelectionHandleMetrics,{clearFind:k,findNext:T,findPrevious:R,findReady:N,findResultCount:A,findResultIndex:O}=S,D=b.useCallback(()=>{R(p)},[R,p]),K=b.useCallback(()=>{T(p)},[T,p]),U=b.useCallback(()=>f(!0),[]),X=b.useCallback(()=>{f(!1),k()},[k]),z=oj({enabled:r,open:d,openRequest:i,onOpen:U,onClose:X,onPrevious:D,onNext:K});return b.useEffect(()=>{!d||!N||(p?T(p,!0):k())},[k,T,d,p,N]),m.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":S.connectionReady?"true":"false","aria-busy":!S.connectionReady,children:[d?m.jsx(WS,{query:p,resultIndex:O,resultCount:A,focusRequest:z.focusRequest,loading:!!p&&!N,onQueryChange:y,onPrevious:D,onNext:K,onClose:z.closeFind}):null,m.jsxs("div",{ref:o,className:"relative flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${S.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:S.handleTerminalContainerMouseDown,onPointerDownCapture:M=>{S.pointerHandlers.onPointerDownCapture(M)},onPointerMoveCapture:S.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:S.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:S.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:S.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:S.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:S.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:S.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:S.pointerHandlers.onContextMenuCapture,onPasteCapture:S.handlePasteCapture,onDragOver:S.handlePtyDragOver,onDragLeave:S.handlePtyDragLeave,onDrop:S.handlePtyDrop,onFocusCapture:S.focusHandlers.onFocusCapture,onBlurCapture:S.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":S.isPtyDragOver?"true":void 0,children:[m.jsx("div",{ref:v,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:m.jsx("div",{ref:_,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})}),m.jsx("div",{ref:w,"data-slot":"pty-selection-handle-layer",style:{position:"absolute",left:0,top:0,width:0,height:0,contain:"layout size",overflow:"visible",pointerEvents:"none",zIndex:11}})]}),m.jsx(rj,{visible:!S.isAtBottom,hasNewMessages:S.hasNewFramesWhileAway,className:d?"top-14":"top-10",onClick:()=>{S.scrollToBottom("backToBottomBtn",{force:!0}),S.clearNewFramesWhileAway()}}),S.showMobilePtyControls?m.jsx(Due,{sessionKind:t,provider:n,bottomInset:S.mobileControlsBottomInset,onInput:S.sendMobileInput,onPaste:S.pasteMobileClipboard,onHeightChange:u}):null,S.ptySelectionHandles&&w.current?Hc.createPortal(m.jsxs(m.Fragment,{children:[m.jsx(xO,{kind:"anchor",metrics:x,"aria-label":"调整选区起点",onPointerDown:M=>S.handlePtySelectionHandlePointerDown("anchor",M),onTouchStart:M=>S.handlePtySelectionHandleTouchStart("anchor",M)}),m.jsx(xO,{kind:"focus",metrics:x,"aria-label":"调整选区终点",onPointerDown:M=>S.handlePtySelectionHandlePointerDown("focus",M),onTouchStart:M=>S.handlePtySelectionHandleTouchStart("focus",M)})]}),w.current):null,S.ptySelectionToolbar?m.jsxs("div",{className:"fixed z-50 flex -translate-x-1/2 gap-1 rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-lg",style:{left:S.ptySelectionToolbar.left,top:S.ptySelectionToolbar.top},"data-slot":"pty-selection-toolbar",children:[m.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:M=>M.preventDefault(),onClick:S.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),S.ptySelectionPathAction?m.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:M=>M.preventDefault(),onClick:S.openPtySelectionPathAction,"aria-label":S.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:S.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,m.jsx(Uue,{state:S.scrollState,onScrollRatio:S.scrollToRatio}),m.jsx(Wue,{state:S.scrollState,onScrollRatio:S.scrollToXRatio}),m.jsx(Sue,{...S.connectionOverlay}),m.jsx(Eue,{ptyInputFocused:S.ptyInputFocused,touchEditingSurface:S.touchEditingSurface,softKeyboardEditingSurface:S.softKeyboardEditingSurface,physicalKeyboardMode:S.physicalKeyboardMode,keyboardOffset:S.keyboardOffset,showMobilePtyControls:S.showMobilePtyControls,mobileControlsBottomInset:S.mobileControlsBottomInset}),S.traceEnabled?m.jsx(Bbe,{}):null]})}function xO({kind:e,metrics:t,"aria-label":n,onPointerDown:r,onTouchStart:i}){const s=t.touchSize/2,o=2,l=t.visualSize,u=Math.max(t.stemSize+2,l+1),d=s-o/2,f=s,p=e==="anchor"?d-l+o:d,y=f+u-l+o,v=e==="anchor"?{borderTopLeftRadius:l,borderBottomLeftRadius:l,borderTopRightRadius:2,borderBottomRightRadius:l}:{borderTopLeftRadius:2,borderBottomLeftRadius:l,borderTopRightRadius:l,borderBottomRightRadius:l};return m.jsxs("button",{type:"button",className:"absolute z-50 touch-none rounded-full bg-transparent p-0 pointer-events-auto focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",style:{left:0,top:0,width:t.touchSize,height:t.touchSize,transform:"translate3d(0, 0, 0) translate(-50%, -50%)",visibility:"hidden",willChange:"transform"},"data-slot":"pty-selection-handle","data-kind":e,"aria-label":n,onPointerDown:r,onTouchStart:i,children:[m.jsx("span",{className:"pointer-events-none absolute rounded-full bg-primary",style:{left:d,top:f,width:o,height:u},"data-slot":"pty-selection-handle-stem"}),m.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:p,top:y,width:l,height:l,...v},"data-slot":"pty-selection-handle-dot"})]})}function Bbe(){const[e,t]=b.useState(!1);async function n(){const r=_ue();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return m.jsx("button",{type:"button",className:"absolute left-3 top-3 z-30 rounded border border-border bg-popover/90 px-2 py-1 text-[11px] text-muted-foreground",onPointerDown:r=>r.preventDefault(),onClick:n,"data-slot":"pty-scroll-trace-copy",children:e?"Copied":"Trace"})}const zbe=1024,jbe=720,Mg=.5,c$=b.createContext(null);function $be({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Le(k=>k.selectedProxyId),u=$t(k=>k.sessions),d=$t(k=>k.sessionListLoaded),f=b.useRef(l),p=b.useRef(null),y=b.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
671
671
  `),[u]),v=b.useCallback(k=>{p.current=k.sessionId,i(k),n(T=>Wle(T,k.sessionId).map(N=>N.sessionId===k.sessionId?{...N,sessionKind:k.sessionKind,provider:k.provider}:N))},[]),_=b.useCallback(k=>{p.current===k&&(p.current=null),i(T=>(T==null?void 0:T.sessionId)===k?null:T),o(T=>p.current===null?null:T)},[]),w=b.useCallback((k,T)=>{p.current===k&&o(R=>!T||R&&Ube(R,T)?R:T)},[]),S=b.useCallback((k,T)=>{T!==void 0&&n(R=>R.map(N=>N.sessionId===k?{...N,findRequest:T}:N))},[]);b.useEffect(()=>{if(!d)return;const k=new Set(y?y.split(`
672
- `):[]);n(T=>T.filter(R=>k.has(R.sessionId))),i(T=>T&&k.has(T.sessionId)?T:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),b.useEffect(()=>{const k=f.current;f.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const x=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:S,updateViewportRect:w}),[v,_,S,w]);return m.jsxs(c$.Provider,{value:x,children:[e,m.jsx(Hbe,{entries:t,activeView:r,viewportRect:s})]})}function Fbe({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(c$),s=b.useRef(null);if(!i)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:o,deactivate:l,updateFindRequest:u,updateViewportRect:d}=i;return b.useLayoutEffect(()=>(o({sessionId:e,sessionKind:t,provider:n}),()=>l(e)),[o,l,e,t,n]),b.useLayoutEffect(()=>{u(e,r)},[r,e,u]),b.useLayoutEffect(()=>{const f=s.current;if(!f)return;const p=()=>{const v=f.getBoundingClientRect();d(e,{top:v.top,left:v.left,width:v.width,height:v.height})};p();const y=new ResizeObserver(p);return y.observe(f),window.addEventListener("resize",p),()=>{y.disconnect(),window.removeEventListener("resize",p)}},[e,d]),m.jsx("div",{ref:s,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function Hbe({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:m.jsx("div",{className:"fixed inset-0 z-10 pointer-events-none","data-slot":"pty-keepalive-layer",children:e.map(r=>{const i=(t==null?void 0:t.sessionId)===r.sessionId&&n!==null,s=i?n:{top:-1e5,left:0,width:(n==null?void 0:n.width)??zbe,height:(n==null?void 0:n.height)??jbe};return m.jsx("div",{className:"absolute overflow-hidden bg-background","data-slot":"pty-keepalive-entry","data-session-id":r.sessionId,"data-active":i?"true":"false","aria-hidden":!i,style:{top:s.top,left:s.left,width:s.width,height:s.height,pointerEvents:i?"auto":"none",visibility:i?"visible":"hidden"},children:m.jsx(nj,{sessionId:r.sessionId,children:m.jsx(Ibe,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function Ube(e,t){return Math.abs(e.top-t.top)<=Mg&&Math.abs(e.left-t.left)<=Mg&&Math.abs(e.width-t.width)<=Mg&&Math.abs(e.height-t.height)<=Mg}function Wbe(){const e=$t(r=>r.codexActiveWriterConflict),t=$t(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(xa,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Ea,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"该 Codex 会话仍在运行"}),m.jsxs(_a,{className:"space-y-2 text-left leading-6",children:[m.jsxs("span",{className:"block",children:["另一个 Codex 进程正在使用此会话",e!=null&&e.activeWriterPid?m.jsxs(m.Fragment,{children:["(PID"," ",m.jsx("span",{className:"font-mono text-foreground",children:e.activeWriterPid}),")"]}):null,"。"]}),m.jsx("span",{className:"block",children:"它可能来自本机终端、Codex App 或另一条 DEV Anywhere 会话。请先回到或结束原会话后再重试。"}),m.jsx("span",{className:"block text-muted-foreground/80",children:"DEV Anywhere 不会自动终止该进程。"})]})]}),m.jsx(Rl,{children:m.jsx(Ct,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function TC({route:e,surface:t,proxiesLength:n,hasProxy:r,sessionCount:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 服务器需要 client token。请在设置里填写。":s==="invalid_client_token"?"当前浏览器保存的 client token 无效或已过期。请在设置里更新。":n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。":t==="mobile"&&e==="proxy-select"||!r?"选择要连接的开发机。":i===0?"还没有会话。可以从本地终端接入,也可以新建会话。":t==="desktop"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}function qbe(e){const t=pB(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function dv(){if(typeof window>"u"||typeof navigator>"u")return!1;const e=typeof window.matchMedia=="function"&&(window.matchMedia("(display-mode: standalone)").matches||window.matchMedia("(display-mode: fullscreen)").matches),t=!!navigator.standalone;return e||t}function Ybe(){return typeof navigator>"u"?{supported:!0}:qbe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:dv()})}function Vbe(){yye(),bye();const e=Ui(),t=oo(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=b.useState(!1),[o,l]=b.useState(()=>dv()),u=Le(D=>D.proxies.length),d=Le(D=>D.proxyListLoaded),f=Le(D=>D.relayClientAuthIssue),p=Le(D=>!!D.selectedProxyId),y=Le(D=>D.selectedProxyId),v=Le(D=>D.selectedProxyName),_=$t(D=>D.sessions.length),w=Le(D=>D.pendingToast),S=Le(D=>D.setPendingToast),x=e.pathname==="/"?"proxy-select":"sessions",k=TC({route:x,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:f}),T=v??y,N=e.pathname==="/sessions"&&d&&u>0?m.jsxs(Ct,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":T?`切换开发机,当前 ${T}`:"切换开发机",onClick:()=>t("/"),children:[m.jsx(tI,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 truncate",children:[m.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?m.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;b.useEffect(()=>{if(!w)return;({error:Xe.error,info:Xe.info,success:Xe.success})[w.kind](w.message),S(null)},[w,S]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(dv());return}const D=window.matchMedia("(display-mode: standalone)"),K=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(dv());return U(),D.addEventListener("change",U),K.addEventListener("change",U),()=>{D.removeEventListener("change",U),K.removeEventListener("change",U)}},[]);const A=b.useRef(!1);b.useEffect(()=>{if(A.current)return;A.current=!0;const D=uJ({pathname:e.pathname,alreadyRestored:hJ(),lastRoute:dJ()});pJ(),D&&(mJ(D),t(D,{replace:!0}))},[]);const O=b.useRef(!1);return b.useEffect(()=>{n?(O.current=!0,fJ(`${e.pathname}${e.search}`)):O.current&&(O.current=!1,wv())},[n,e.pathname,e.search]),m.jsxs("div",{className:"flex flex-col bg-background text-foreground",style:{height:"var(--dev-app-shell-height, max(100dvh, var(--dev-visual-viewport-height, 100dvh)))"},"data-slot":"app-shell","data-standalone-display":o?"true":void 0,children:[!n&&m.jsx(Ct,{variant:"ghost",size:"icon",className:"dev-mobile-settings-trigger group fixed right-4 z-30 size-11 rounded-full border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-transparent hover:text-foreground md:hidden","aria-label":"设置","data-slot":"mobile-settings-trigger",onClick:()=>s(!0),children:m.jsx("span",{"data-slot":"mobile-settings-trigger-visual",className:"flex size-7 items-center justify-center rounded-full border border-border/80 bg-card/90 shadow-lg backdrop-blur transition-colors group-hover:border-primary/45 group-hover:bg-accent",children:m.jsx(iI,{className:"size-4","aria-hidden":"true"})})}),!n&&m.jsx(Vae,{subtitle:k,action:N}),m.jsx(Ule,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(Wae,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx($be,{children:m.jsx("div",{className:Ye("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:m.jsx(b9,{})},r?"top-level":e.pathname)})})]}),m.jsx(FS,{open:i,onOpenChange:s}),m.jsx(Wbe,{}),m.jsx(_le,{}),m.jsx(nle,{}),m.jsx(eJ,{})]})}function u$({subtitle:e,action:t}){return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[m.jsx(S5,{texts:x5,className:"text-2xl md:text-3xl font-bold"}),m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&m.jsx("div",{children:t})]})}function Kbe(){const e=Le(o=>o.proxies),t=Le(o=>!!o.selectedProxyId),n=Le(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=TC({route:"proxy-select",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n}),s=n==="missing_client_token"?"client-token-missing":n==="invalid_client_token"?"client-token-invalid":null;return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(s5,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(Sc,{variant:s}):m.jsx(u$,{subtitle:i})})]})}function Xbe(){const e=Le(o=>o.proxies),t=Le(o=>!!o.selectedProxyId),n=Le(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=ki("local",vn.proxyId)!==null;if(!t&&!i)return m.jsx(y9,{to:"/",replace:!0});const s=TC({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(m5,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(u$,{subtitle:s})})]})}function d$(){if(!(typeof navigator>"u"))return navigator.wakeLock}function Gbe(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function f$(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return Gbe(e,typeof((t=d$())==null?void 0:t.request)=="function")}function Zbe(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function Qbe(){const e=d$();if(typeof(e==null?void 0:e.request)!="function")throw new Error(Zbe(f$()));return e.request("screen")}function Jbe(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class e_e{constructor(t={}){_t(this,"activeScopes",new Set);_t(this,"pendingScopes",new Set);_t(this,"listeners",new Map);_t(this,"sentinel",null);_t(this,"requestInFlight",null);_t(this,"requestWakeLock");_t(this,"documentRef");_t(this,"windowRef");_t(this,"unavailableReason");_t(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});_t(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??Qbe,this.unavailableReason=typeof t.request=="function"?null:f$(),this.documentRef=t.document??(typeof document>"u"?void 0:document),this.windowRef=t.window??(typeof window>"u"?void 0:window),(n=this.documentRef)==null||n.addEventListener("visibilitychange",this.handleVisibilityChange),(r=this.windowRef)==null||r.addEventListener("pagehide",this.handlePageHide)}isSupported(){return this.unavailableReason===null}getSnapshot(t){return{active:this.activeScopes.has(t),pending:this.pendingScopes.has(t),supported:this.isSupported(),unavailableReason:this.unavailableReason}}subscribe(t,n){const r=this.listeners.get(t)??new Set;return r.add(n),this.listeners.set(t,r),n(this.getSnapshot(t)),()=>{r.delete(n),r.size===0&&this.listeners.delete(t)}}async enable(t){this.activeScopes.add(t),this.pendingScopes.add(t),this.notify(t);try{await this.ensureWakeLock()}catch(n){throw this.activeScopes.delete(t),new Error(Jbe(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const hl=new e_e;function h$(e){const[t,n]=b.useState(()=>hl.getSnapshot(e));b.useEffect(()=>hl.subscribe(e,n),[e]),b.useEffect(()=>()=>{hl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>hl.enable(e),[e]),i=b.useCallback(()=>hl.disable(e),[e]),s=b.useCallback(()=>hl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function t_e(){return new AudioContext}class n_e{constructor(t=t_e){_t(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const fv=new n_e,EO=400,id=[];let p$=1;function r_e(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function yh(e){const t={sequence:p$++,timestamp:new Date().toISOString(),monotonicMs:r_e(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};id.push(t),id.length>EO&&id.splice(0,id.length-EO)}function i_e(){return id.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function s_e(){id.length=0,p$=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:i_e,clear:s_e});function m$(e){return`voice-pilot:${e}`}function o_e(e){const t=new Int16Array(e.length);for(let n=0;n<e.length;n+=1){const r=Math.max(-1,Math.min(1,e[n]??0));t[n]=r<0?Math.round(r*32768):Math.floor(r*32767)}return new Uint8Array(t.buffer)}const a_e="modulepreload",l_e=function(e){return"/"+e},CO={},c_e=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(f=>Promise.resolve(f).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),u=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=o(n.map(d=>{if(d=l_e(d),d in CO)return;CO[d]=!0;const f=d.endsWith(".css"),p=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const y=document.createElement("link");if(y.rel=f?"stylesheet":a_e,f||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),f)return new Promise((v,_)=>{y.addEventListener("load",v),y.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},u_e="/assets/fvad-DYxbW2my.wasm",Cd=16e3,d_e=20,pl=Cd*d_e/1e3,R0=pl*Int16Array.BYTES_PER_ELEMENT;let kO=null;async function f_e(){return kO??(kO=c_e(async()=>{const{default:e}=await import("./fvad-_D7IP4iB.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?u_e:t}))),kO}class RC{constructor(t,n,r){_t(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await f_e(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(R0);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Cd)!==0)throw n._free(i),n._fvad_free(r),new Error("浏览器语音活动检测器不支持 16 kHz 音频");if(n._fvad_set_mode(r,t)!==0)throw n._free(i),n._fvad_free(r),new Error("无法配置浏览器语音活动检测器");return new RC(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==R0)throw new Error(`语音活动检测帧必须为 ${R0} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,pl);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class h_e{constructor(t={}){_t(this,"startSpeechFrames");_t(this,"endSilenceFrames");_t(this,"active",!1);_t(this,"speechFrames",0);_t(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class p_e{constructor(){_t(this,"pending",new Float32Array(pl));_t(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=pl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===pl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+pl<=t.length;)n(t.slice(r,r+pl)),r+=pl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const m_e="/__dev_anywhere_debug/voice-fixture",g_e=Cd*v5/1e3;function v_e(){return RC.create(3)}const y_e={createVad:v_e,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function b_e(e){if(e.length===0)return 0;let t=0;for(const n of e)t+=n*n;return Math.min(1,Math.sqrt(t/e.length)*10)}function __e(e){for(const t of e.getTracks())t.stop()}function g$(e){const t=e.createAudioContext({sampleRate:Cd});if(t.sampleRate!==Cd)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function w_e(e){const t=g$(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:Cd}})}catch(i){throw await t.close().catch(()=>{}),i}const r=t.createMediaStreamSource(n);return{context:t,input:r,async start(){t.state==="suspended"&&await t.resume()},async stop(){r.disconnect(),__e(n),t.state!=="closed"&&await t.close()}}}async function S_e(e,t){const n=g$(t);try{const r=await t.fetch(e);if(!r.ok)throw new Error(`测试录音读取失败 (${r.status})`);const i=await n.decodeAudioData(await r.arrayBuffer()),s=n.createBufferSource();s.buffer=i;let o=!1,l=!1;return{context:n,input:s,async start(){o||l||(o=!0,n.state==="suspended"&&await n.resume(),s.start())},async stop(){if(!l){if(l=!0,o)try{s.stop()}catch{}s.disconnect(),n.state!=="closed"&&await n.close()}}}}catch(r){throw await n.close().catch(()=>{}),r}}function v$(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:m_e}:{kind:"microphone"}}async function x_e(e,t=y_e){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await S_e(e.source.url,t):await w_e(t)}catch(f){throw n.destroy(),f}const i=new h_e,s=new p_e,o=r.context.createScriptProcessor(g_e,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),p=>{const y=o_e(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:b_e(p)});const _=i.push(v);_==="speech-start"&&e.onSpeechStart(),_==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function y$(e=cp().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function E_e(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function C_e({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=E_e(e);return m.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&m.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),m.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function k_e(e){const t=e instanceof Error?e.name:"";return t==="NotAllowedError"||t==="SecurityError"?"没有麦克风权限,请在浏览器里允许访问麦克风。":t==="NotFoundError"||t==="DevicesNotFoundError"?"未检测到可用麦克风。":t==="NotReadableError"||t==="TrackStartError"?"麦克风正在被其他应用占用。":e instanceof Error?e.message:"无法访问麦克风。"}async function T_e(){var t;if(!((t=navigator.mediaDevices)!=null&&t.getUserMedia))throw new Error("当前浏览器不支持麦克风访问。");let e=null;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(n){throw new Error(k_e(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const ju="min-h-9 gap-2.5",Ng="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function So({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function R_e({label:e}){return m.jsxs(So,{className:"relative",children:[m.jsx(eI,{className:"size-4","aria-hidden":"true"}),m.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3 min-w-4 items-center justify-center rounded-[3px] border border-border bg-popover px-0.5 font-mono text-[7px] leading-none text-muted-foreground shadow-sm",children:e})]})}function A_e({sessionId:e,mode:t,onFind:n}){const r=y$(),i=oo(),s=$t(ye=>ye.sessions.find(Ze=>Ze.sessionId===e)),o=$t(ye=>ye.ptyTitles[e]),l=Le(ye=>ye.ptyFontSize),u=Le(ye=>ye.chatContentFontSize),d=Le(ye=>ye.selectedProxyId),f=Le(ye=>ye.adjustPtyFontSize),p=Le(ye=>ye.adjustChatContentFontSize),y=Le(ye=>ye.setChatContentFontSize),v=Le(ye=>ye.resetPtyFontSize),_=Le(ye=>ye.resetChatContentFontSize),w=Le(ye=>ye.inputModePreference==="hardware"),S=$t(ye=>ye.renameSession),x=K1(d,e),k=$t(ye=>x?!!ye.ptyAutoYesBySessionKey[x]:!1),T=$t(ye=>ye.setPtyAutoYes),N=Al("(pointer: coarse), (hover: none)")&&!w,A=t==="pty"||(s==null?void 0:s.mode)==="pty",O=(s==null?void 0:s.kind)==="terminal",D=h$(e),K=wn(ye=>ye.bySessionId[e]??zy),U=wn(ye=>ye.enable),X=wn(ye=>ye.disable),z=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=eE(s),F=z&&(s==null?void 0:s.name)||M||A&&o||(s==null?void 0:s.name)||e.slice(0,8),B=!!(A&&!O&&o&&!z),P=A?l:I1(u,N),I=!A&&N?CI:xI,W=A?v:_,[j,L]=b.useState(!1),[Y,V]=b.useState(!1),$=K.enabled,te=D.active||$,re=D.pending||!D.supported||$;function oe(ye){if(A){f(ye);return}if(N){y(P+ye);return}p(ye)}function ee(){D.toggle().catch(ye=>{Xe.error(ye instanceof Error?ye.message:String(ye))})}async function pe(ye){var Tt;if(A||O){Xe.info("Voice Pilot 目前适用于聊天会话。");return}if(ye!==!0){X(e);return}const Ze=Ut;if(!Ze){Xe.error("请先连接开发机");return}try{if(!((Tt=(await Ze.requestVoiceConfig()).config)!=null&&Tt.configured)){Xe.info("请先在设置里配置 Voice Pilot。");return}L(!0)}catch(gt){Xe.error(gt instanceof Error?gt.message:String(gt))}}async function ae(){var gt;V(!0);let ye=null,Ze=!1;const Tt=m$(e);try{yh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((gt=navigator.userActivation)==null?void 0:gt.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Ot=hl.enable(Tt).then(()=>{yh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ke=>{throw yh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ke instanceof Error?Ke.message:String(Ke)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ke})});ye=BE.acquire("capture");const an=fv.prepare(),Oe=v$().kind==="microphone"?T_e():Promise.resolve();await Promise.all([Ot,an,Oe]),U(e),Ze=!0,L(!1)}catch(Ot){yh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Ot instanceof Error?Ot.message:String(Ot)}}),Xe.error(Ot instanceof Error?Ot.message:String(Ot))}finally{ye==null||ye.release(),Ze||await hl.disable(Tt).catch(()=>{}),V(!1)}}const me=b.useRef(null),Ee=b.useRef(null),[De,Se]=b.useState(!1);async function Je(ye){var Ot;const Ze=(Ot=ye.target.files)==null?void 0:Ot[0];if(ye.target.value="",!Ze)return;const Tt=Ut;if(!Tt){Xe.error("请先连接开发机");return}const gt=await Qh({relay:Tt,sessionId:e,file:Ze});gt&&to(e,`@${gt} `)}async function Ht(ye,Ze){const Tt=Ut;if(!Tt)throw new Error("请先连接开发机");const gt=await Tt.renameSession(ye,Ze);if(!gt.success)throw new Error(gt.error??"重命名失败");S(ye,gt.name??Ze),Xe.success("已重命名会话")}return m.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[m.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:m.jsxs("div",{className:"grid min-h-12 w-full grid-cols-[2.25rem_minmax(0,1fr)_2.25rem] items-center","data-slot":"chat-header-rail",children:[m.jsx("div",{className:"flex justify-start",children:m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(Gv,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(C_e,{title:F,isPtyTitle:B})}),m.jsxs(Ey,{modal:!1,children:[m.jsx(Cy,{asChild:!0,children:m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:m.jsx(HW,{"aria-hidden":"true"})})}),m.jsxs(ky,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[m.jsx(dg,{className:Ng,children:"会话"}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(So,{children:m.jsx(mv,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-rename",onSelect:()=>Se(!0),children:[m.jsx(So,{children:m.jsx(R7,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(Dw,{checked:te,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:re,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:ee,children:[m.jsx(So,{children:m.jsx(c7,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:D.supported?$?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":D.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),A&&!O&&m.jsxs(Dw,{checked:k,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!x,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ye=>{x&&T(x,ye===!0)},children:[m.jsx(So,{children:m.jsx(Lo,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!A&&!O&&m.jsxs(Dw,{checked:K.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:pe,children:[m.jsx(So,{children:m.jsx(m7,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Iw,{}),A&&!O?m.jsxs(m.Fragment,{children:[m.jsx(dg,{className:Ng,children:"快捷键"}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>to(e,""),children:[m.jsx(R_e,{label:"^O"}),"发送 Ctrl+O"]}),m.jsx(Iw,{}),m.jsx(dg,{className:Ng,children:"文件"}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-upload-image",onClick:()=>{var ye;return(ye=Ee.current)==null?void 0:ye.click()},children:[m.jsx(So,{children:m.jsx(ap,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-upload-file",onClick:()=>{var ye;return(ye=me.current)==null?void 0:ye.click()},children:[m.jsx(So,{children:m.jsx(sI,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Iw,{})]}):null,m.jsx(dg,{className:Ng,children:"字号"}),m.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:m.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[m.jsx(So,{children:m.jsx(Q7,{"aria-hidden":"true"})}),m.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:P<=I,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ye=>{ye.stopPropagation(),oe(-1)},children:m.jsx(v7,{"aria-hidden":"true"})}),m.jsxs("span",{className:"flex h-[22px] min-w-11 items-center justify-center px-1 text-sm font-medium leading-none tabular-nums text-foreground","data-slot":"chat-menu-font-size",children:[P,"px"]}),m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:P>=EI,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ye=>{ye.stopPropagation(),oe(1)},children:m.jsx(N7,{"aria-hidden":"true"})})]})]})}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-font-reset",onClick:W,children:[m.jsx(So,{children:m.jsx(L7,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(ch,{open:De,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Se,onRename:Ht}),m.jsx(xa,{open:j&&!K.enabled,onOpenChange:ye=>{Y||L(ye)},children:m.jsxs(Ea,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"开启 Voice Pilot?"}),m.jsx(_a,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"outline",disabled:Y,onClick:()=>L(!1),children:"取消"}),m.jsx(Ct,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Y,onClick:()=>{ae()},children:Y?"正在开启...":"开启 Voice Pilot"})]})]})}),A?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:Ee,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ye=>{Je(ye)}}),m.jsx("input",{ref:me,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ye=>{Je(ye)}})]}):null]})}function $u(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let f;n.key&&((l=n.debug)!=null&&l.call(n))&&(f=Date.now());const p=e();if(!(p.length!==r.length||p.some((_,w)=>r[w]!==_)))return i;r=p;let v;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(v=Date.now()),i=t(...p),n.key&&((d=n.debug)!=null&&d.call(n))){const _=Math.round((Date.now()-f)*100)/100,w=Math.round((Date.now()-v)*100)/100,S=w/16,x=(k,T)=>{for(k=String(k);k.length<T;)k=" "+k;return k};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
672
+ `):[]);n(T=>T.filter(R=>k.has(R.sessionId))),i(T=>T&&k.has(T.sessionId)?T:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),b.useEffect(()=>{const k=f.current;f.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const x=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:S,updateViewportRect:w}),[v,_,S,w]);return m.jsxs(c$.Provider,{value:x,children:[e,m.jsx(Hbe,{entries:t,activeView:r,viewportRect:s})]})}function Fbe({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(c$),s=b.useRef(null);if(!i)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:o,deactivate:l,updateFindRequest:u,updateViewportRect:d}=i;return b.useLayoutEffect(()=>(o({sessionId:e,sessionKind:t,provider:n}),()=>l(e)),[o,l,e,t,n]),b.useLayoutEffect(()=>{u(e,r)},[r,e,u]),b.useLayoutEffect(()=>{const f=s.current;if(!f)return;const p=()=>{const v=f.getBoundingClientRect();d(e,{top:v.top,left:v.left,width:v.width,height:v.height})};p();const y=new ResizeObserver(p);return y.observe(f),window.addEventListener("resize",p),()=>{y.disconnect(),window.removeEventListener("resize",p)}},[e,d]),m.jsx("div",{ref:s,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function Hbe({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:m.jsx("div",{className:"fixed inset-0 z-10 pointer-events-none","data-slot":"pty-keepalive-layer",children:e.map(r=>{const i=(t==null?void 0:t.sessionId)===r.sessionId&&n!==null,s=i?n:{top:-1e5,left:0,width:(n==null?void 0:n.width)??zbe,height:(n==null?void 0:n.height)??jbe};return m.jsx("div",{className:"absolute overflow-hidden bg-background","data-slot":"pty-keepalive-entry","data-session-id":r.sessionId,"data-active":i?"true":"false","aria-hidden":!i,style:{top:s.top,left:s.left,width:s.width,height:s.height,pointerEvents:i?"auto":"none",visibility:i?"visible":"hidden"},children:m.jsx(nj,{sessionId:r.sessionId,children:m.jsx(Ibe,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function Ube(e,t){return Math.abs(e.top-t.top)<=Mg&&Math.abs(e.left-t.left)<=Mg&&Math.abs(e.width-t.width)<=Mg&&Math.abs(e.height-t.height)<=Mg}function Wbe(){const e=$t(r=>r.codexActiveWriterConflict),t=$t(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(xa,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Ea,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"该 Codex 会话仍在运行"}),m.jsxs(_a,{className:"space-y-2 text-left leading-6",children:[m.jsxs("span",{className:"block",children:["另一个 Codex 进程正在使用此会话",e!=null&&e.activeWriterPid?m.jsxs(m.Fragment,{children:["(PID"," ",m.jsx("span",{className:"font-mono text-foreground",children:e.activeWriterPid}),")"]}):null,"。"]}),m.jsx("span",{className:"block",children:"它可能来自本机终端、Codex App 或另一条 DEV Anywhere 会话。请先回到或结束原会话后再重试。"}),m.jsx("span",{className:"block text-muted-foreground/80",children:"DEV Anywhere 不会自动终止该进程。"})]})]}),m.jsx(Rl,{children:m.jsx(Ct,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function TC({route:e,surface:t,proxiesLength:n,hasProxy:r,sessionCount:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 服务器需要 client token。请在设置里填写。":s==="invalid_client_token"?"当前浏览器保存的 client token 无效或已过期。请在设置里更新。":n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。":t==="mobile"&&e==="proxy-select"||!r?"选择要连接的开发机。":i===0?"还没有会话。可以从本地终端接入,也可以新建会话。":t==="desktop"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}function qbe(e){const t=pB(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function dv(){if(typeof window>"u"||typeof navigator>"u")return!1;const e=typeof window.matchMedia=="function"&&(window.matchMedia("(display-mode: standalone)").matches||window.matchMedia("(display-mode: fullscreen)").matches),t=!!navigator.standalone;return e||t}function Ybe(){return typeof navigator>"u"?{supported:!0}:qbe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:dv()})}function Vbe(){yye(),bye();const e=Ui(),t=oo(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=b.useState(!1),[o,l]=b.useState(()=>dv()),u=Le(D=>D.proxies.length),d=Le(D=>D.proxyListLoaded),f=Le(D=>D.relayClientAuthIssue),p=Le(D=>!!D.selectedProxyId),y=Le(D=>D.selectedProxyId),v=Le(D=>D.selectedProxyName),_=$t(D=>D.sessions.length),w=Le(D=>D.pendingToast),S=Le(D=>D.setPendingToast),x=e.pathname==="/"?"proxy-select":"sessions",k=TC({route:x,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:f}),T=v??y,N=e.pathname==="/sessions"&&d&&u>0?m.jsxs(Ct,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":T?`切换开发机,当前 ${T}`:"切换开发机",onClick:()=>t("/"),children:[m.jsx(tI,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 truncate",children:[m.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?m.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;b.useEffect(()=>{if(!w)return;({error:Xe.error,info:Xe.info,success:Xe.success})[w.kind](w.message),S(null)},[w,S]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(dv());return}const D=window.matchMedia("(display-mode: standalone)"),K=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(dv());return U(),D.addEventListener("change",U),K.addEventListener("change",U),()=>{D.removeEventListener("change",U),K.removeEventListener("change",U)}},[]);const A=b.useRef(!1);b.useEffect(()=>{if(A.current)return;A.current=!0;const D=uJ({pathname:e.pathname,alreadyRestored:hJ(),lastRoute:dJ()});pJ(),D&&(mJ(D),t(D,{replace:!0}))},[]);const O=b.useRef(!1);return b.useEffect(()=>{n?(O.current=!0,fJ(`${e.pathname}${e.search}`)):O.current&&(O.current=!1,wv())},[n,e.pathname,e.search]),m.jsxs("div",{className:"flex flex-col bg-background text-foreground",style:{height:"var(--dev-app-shell-height, max(100dvh, var(--dev-visual-viewport-height, 100dvh)))"},"data-slot":"app-shell","data-standalone-display":o?"true":void 0,children:[!n&&m.jsx(Ct,{variant:"ghost",size:"icon",className:"dev-mobile-settings-trigger group fixed right-4 z-30 size-11 rounded-full border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-transparent hover:text-foreground md:hidden","aria-label":"设置","data-slot":"mobile-settings-trigger",onClick:()=>s(!0),children:m.jsx("span",{"data-slot":"mobile-settings-trigger-visual",className:"flex size-7 items-center justify-center rounded-full border border-border/80 bg-card/90 shadow-lg backdrop-blur transition-colors group-hover:border-primary/45 group-hover:bg-accent",children:m.jsx(iI,{className:"size-4","aria-hidden":"true"})})}),!n&&m.jsx(Vae,{subtitle:k,action:N}),m.jsx(Ule,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(Wae,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx($be,{children:m.jsx("div",{className:Ye("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:m.jsx(b9,{})},r?"top-level":e.pathname)})})]}),m.jsx(FS,{open:i,onOpenChange:s}),m.jsx(Wbe,{}),m.jsx(_le,{}),m.jsx(nle,{}),m.jsx(eJ,{})]})}function u$({subtitle:e,action:t}){return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[m.jsx(S5,{texts:x5,className:"text-2xl md:text-3xl font-bold"}),m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&m.jsx("div",{children:t})]})}function Kbe(){const e=Le(o=>o.proxies),t=Le(o=>!!o.selectedProxyId),n=Le(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=TC({route:"proxy-select",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n}),s=n==="missing_client_token"?"client-token-missing":n==="invalid_client_token"?"client-token-invalid":null;return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(s5,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(Sc,{variant:s}):m.jsx(u$,{subtitle:i})})]})}function Xbe(){const e=Le(o=>o.proxies),t=Le(o=>!!o.selectedProxyId),n=Le(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=ki("local",vn.proxyId)!==null;if(!t&&!i)return m.jsx(y9,{to:"/",replace:!0});const s=TC({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(m5,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(u$,{subtitle:s})})]})}function d$(){if(!(typeof navigator>"u"))return navigator.wakeLock}function Gbe(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function f$(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return Gbe(e,typeof((t=d$())==null?void 0:t.request)=="function")}function Zbe(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function Qbe(){const e=d$();if(typeof(e==null?void 0:e.request)!="function")throw new Error(Zbe(f$()));return e.request("screen")}function Jbe(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class e_e{constructor(t={}){_t(this,"activeScopes",new Set);_t(this,"pendingScopes",new Set);_t(this,"listeners",new Map);_t(this,"sentinel",null);_t(this,"requestInFlight",null);_t(this,"requestWakeLock");_t(this,"documentRef");_t(this,"windowRef");_t(this,"unavailableReason");_t(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});_t(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??Qbe,this.unavailableReason=typeof t.request=="function"?null:f$(),this.documentRef=t.document??(typeof document>"u"?void 0:document),this.windowRef=t.window??(typeof window>"u"?void 0:window),(n=this.documentRef)==null||n.addEventListener("visibilitychange",this.handleVisibilityChange),(r=this.windowRef)==null||r.addEventListener("pagehide",this.handlePageHide)}isSupported(){return this.unavailableReason===null}getSnapshot(t){return{active:this.activeScopes.has(t),pending:this.pendingScopes.has(t),supported:this.isSupported(),unavailableReason:this.unavailableReason}}subscribe(t,n){const r=this.listeners.get(t)??new Set;return r.add(n),this.listeners.set(t,r),n(this.getSnapshot(t)),()=>{r.delete(n),r.size===0&&this.listeners.delete(t)}}async enable(t){this.activeScopes.add(t),this.pendingScopes.add(t),this.notify(t);try{await this.ensureWakeLock()}catch(n){throw this.activeScopes.delete(t),new Error(Jbe(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const hl=new e_e;function h$(e){const[t,n]=b.useState(()=>hl.getSnapshot(e));b.useEffect(()=>hl.subscribe(e,n),[e]),b.useEffect(()=>()=>{hl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>hl.enable(e),[e]),i=b.useCallback(()=>hl.disable(e),[e]),s=b.useCallback(()=>hl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function t_e(){return new AudioContext}class n_e{constructor(t=t_e){_t(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const fv=new n_e,EO=400,id=[];let p$=1;function r_e(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function yh(e){const t={sequence:p$++,timestamp:new Date().toISOString(),monotonicMs:r_e(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};id.push(t),id.length>EO&&id.splice(0,id.length-EO)}function i_e(){return id.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function s_e(){id.length=0,p$=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:i_e,clear:s_e});function m$(e){return`voice-pilot:${e}`}function o_e(e){const t=new Int16Array(e.length);for(let n=0;n<e.length;n+=1){const r=Math.max(-1,Math.min(1,e[n]??0));t[n]=r<0?Math.round(r*32768):Math.floor(r*32767)}return new Uint8Array(t.buffer)}const a_e="modulepreload",l_e=function(e){return"/"+e},CO={},c_e=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(f=>Promise.resolve(f).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),u=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=o(n.map(d=>{if(d=l_e(d),d in CO)return;CO[d]=!0;const f=d.endsWith(".css"),p=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const y=document.createElement("link");if(y.rel=f?"stylesheet":a_e,f||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),f)return new Promise((v,_)=>{y.addEventListener("load",v),y.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},u_e="/assets/fvad-DYxbW2my.wasm",Cd=16e3,d_e=20,pl=Cd*d_e/1e3,R0=pl*Int16Array.BYTES_PER_ELEMENT;let kO=null;async function f_e(){return kO??(kO=c_e(async()=>{const{default:e}=await import("./fvad-RpevwfGI.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?u_e:t}))),kO}class RC{constructor(t,n,r){_t(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await f_e(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(R0);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Cd)!==0)throw n._free(i),n._fvad_free(r),new Error("浏览器语音活动检测器不支持 16 kHz 音频");if(n._fvad_set_mode(r,t)!==0)throw n._free(i),n._fvad_free(r),new Error("无法配置浏览器语音活动检测器");return new RC(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==R0)throw new Error(`语音活动检测帧必须为 ${R0} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,pl);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class h_e{constructor(t={}){_t(this,"startSpeechFrames");_t(this,"endSilenceFrames");_t(this,"active",!1);_t(this,"speechFrames",0);_t(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class p_e{constructor(){_t(this,"pending",new Float32Array(pl));_t(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=pl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===pl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+pl<=t.length;)n(t.slice(r,r+pl)),r+=pl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const m_e="/__dev_anywhere_debug/voice-fixture",g_e=Cd*v5/1e3;function v_e(){return RC.create(3)}const y_e={createVad:v_e,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function b_e(e){if(e.length===0)return 0;let t=0;for(const n of e)t+=n*n;return Math.min(1,Math.sqrt(t/e.length)*10)}function __e(e){for(const t of e.getTracks())t.stop()}function g$(e){const t=e.createAudioContext({sampleRate:Cd});if(t.sampleRate!==Cd)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function w_e(e){const t=g$(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:Cd}})}catch(i){throw await t.close().catch(()=>{}),i}const r=t.createMediaStreamSource(n);return{context:t,input:r,async start(){t.state==="suspended"&&await t.resume()},async stop(){r.disconnect(),__e(n),t.state!=="closed"&&await t.close()}}}async function S_e(e,t){const n=g$(t);try{const r=await t.fetch(e);if(!r.ok)throw new Error(`测试录音读取失败 (${r.status})`);const i=await n.decodeAudioData(await r.arrayBuffer()),s=n.createBufferSource();s.buffer=i;let o=!1,l=!1;return{context:n,input:s,async start(){o||l||(o=!0,n.state==="suspended"&&await n.resume(),s.start())},async stop(){if(!l){if(l=!0,o)try{s.stop()}catch{}s.disconnect(),n.state!=="closed"&&await n.close()}}}}catch(r){throw await n.close().catch(()=>{}),r}}function v$(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:m_e}:{kind:"microphone"}}async function x_e(e,t=y_e){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await S_e(e.source.url,t):await w_e(t)}catch(f){throw n.destroy(),f}const i=new h_e,s=new p_e,o=r.context.createScriptProcessor(g_e,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),p=>{const y=o_e(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:b_e(p)});const _=i.push(v);_==="speech-start"&&e.onSpeechStart(),_==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function y$(e=cp().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function E_e(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function C_e({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=E_e(e);return m.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&m.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),m.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function k_e(e){const t=e instanceof Error?e.name:"";return t==="NotAllowedError"||t==="SecurityError"?"没有麦克风权限,请在浏览器里允许访问麦克风。":t==="NotFoundError"||t==="DevicesNotFoundError"?"未检测到可用麦克风。":t==="NotReadableError"||t==="TrackStartError"?"麦克风正在被其他应用占用。":e instanceof Error?e.message:"无法访问麦克风。"}async function T_e(){var t;if(!((t=navigator.mediaDevices)!=null&&t.getUserMedia))throw new Error("当前浏览器不支持麦克风访问。");let e=null;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(n){throw new Error(k_e(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const ju="min-h-9 gap-2.5",Ng="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function So({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function R_e({label:e}){return m.jsxs(So,{className:"relative",children:[m.jsx(eI,{className:"size-4","aria-hidden":"true"}),m.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3 min-w-4 items-center justify-center rounded-[3px] border border-border bg-popover px-0.5 font-mono text-[7px] leading-none text-muted-foreground shadow-sm",children:e})]})}function A_e({sessionId:e,mode:t,onFind:n}){const r=y$(),i=oo(),s=$t(ye=>ye.sessions.find(Ze=>Ze.sessionId===e)),o=$t(ye=>ye.ptyTitles[e]),l=Le(ye=>ye.ptyFontSize),u=Le(ye=>ye.chatContentFontSize),d=Le(ye=>ye.selectedProxyId),f=Le(ye=>ye.adjustPtyFontSize),p=Le(ye=>ye.adjustChatContentFontSize),y=Le(ye=>ye.setChatContentFontSize),v=Le(ye=>ye.resetPtyFontSize),_=Le(ye=>ye.resetChatContentFontSize),w=Le(ye=>ye.inputModePreference==="hardware"),S=$t(ye=>ye.renameSession),x=K1(d,e),k=$t(ye=>x?!!ye.ptyAutoYesBySessionKey[x]:!1),T=$t(ye=>ye.setPtyAutoYes),N=Al("(pointer: coarse), (hover: none)")&&!w,A=t==="pty"||(s==null?void 0:s.mode)==="pty",O=(s==null?void 0:s.kind)==="terminal",D=h$(e),K=wn(ye=>ye.bySessionId[e]??zy),U=wn(ye=>ye.enable),X=wn(ye=>ye.disable),z=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=eE(s),F=z&&(s==null?void 0:s.name)||M||A&&o||(s==null?void 0:s.name)||e.slice(0,8),B=!!(A&&!O&&o&&!z),P=A?l:I1(u,N),I=!A&&N?CI:xI,W=A?v:_,[j,L]=b.useState(!1),[Y,V]=b.useState(!1),$=K.enabled,te=D.active||$,re=D.pending||!D.supported||$;function oe(ye){if(A){f(ye);return}if(N){y(P+ye);return}p(ye)}function ee(){D.toggle().catch(ye=>{Xe.error(ye instanceof Error?ye.message:String(ye))})}async function pe(ye){var Tt;if(A||O){Xe.info("Voice Pilot 目前适用于聊天会话。");return}if(ye!==!0){X(e);return}const Ze=Ut;if(!Ze){Xe.error("请先连接开发机");return}try{if(!((Tt=(await Ze.requestVoiceConfig()).config)!=null&&Tt.configured)){Xe.info("请先在设置里配置 Voice Pilot。");return}L(!0)}catch(gt){Xe.error(gt instanceof Error?gt.message:String(gt))}}async function ae(){var gt;V(!0);let ye=null,Ze=!1;const Tt=m$(e);try{yh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((gt=navigator.userActivation)==null?void 0:gt.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Ot=hl.enable(Tt).then(()=>{yh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ke=>{throw yh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ke instanceof Error?Ke.message:String(Ke)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ke})});ye=BE.acquire("capture");const an=fv.prepare(),Oe=v$().kind==="microphone"?T_e():Promise.resolve();await Promise.all([Ot,an,Oe]),U(e),Ze=!0,L(!1)}catch(Ot){yh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Ot instanceof Error?Ot.message:String(Ot)}}),Xe.error(Ot instanceof Error?Ot.message:String(Ot))}finally{ye==null||ye.release(),Ze||await hl.disable(Tt).catch(()=>{}),V(!1)}}const me=b.useRef(null),Ee=b.useRef(null),[De,Se]=b.useState(!1);async function Je(ye){var Ot;const Ze=(Ot=ye.target.files)==null?void 0:Ot[0];if(ye.target.value="",!Ze)return;const Tt=Ut;if(!Tt){Xe.error("请先连接开发机");return}const gt=await Qh({relay:Tt,sessionId:e,file:Ze});gt&&to(e,`@${gt} `)}async function Ht(ye,Ze){const Tt=Ut;if(!Tt)throw new Error("请先连接开发机");const gt=await Tt.renameSession(ye,Ze);if(!gt.success)throw new Error(gt.error??"重命名失败");S(ye,gt.name??Ze),Xe.success("已重命名会话")}return m.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[m.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:m.jsxs("div",{className:"grid min-h-12 w-full grid-cols-[2.25rem_minmax(0,1fr)_2.25rem] items-center","data-slot":"chat-header-rail",children:[m.jsx("div",{className:"flex justify-start",children:m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(Gv,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(C_e,{title:F,isPtyTitle:B})}),m.jsxs(Ey,{modal:!1,children:[m.jsx(Cy,{asChild:!0,children:m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:m.jsx(HW,{"aria-hidden":"true"})})}),m.jsxs(ky,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[m.jsx(dg,{className:Ng,children:"会话"}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(So,{children:m.jsx(mv,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-rename",onSelect:()=>Se(!0),children:[m.jsx(So,{children:m.jsx(R7,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(Dw,{checked:te,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:re,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:ee,children:[m.jsx(So,{children:m.jsx(c7,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:D.supported?$?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":D.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),A&&!O&&m.jsxs(Dw,{checked:k,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!x,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ye=>{x&&T(x,ye===!0)},children:[m.jsx(So,{children:m.jsx(Lo,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!A&&!O&&m.jsxs(Dw,{checked:K.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:pe,children:[m.jsx(So,{children:m.jsx(m7,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Iw,{}),A&&!O?m.jsxs(m.Fragment,{children:[m.jsx(dg,{className:Ng,children:"快捷键"}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>to(e,""),children:[m.jsx(R_e,{label:"^O"}),"发送 Ctrl+O"]}),m.jsx(Iw,{}),m.jsx(dg,{className:Ng,children:"文件"}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-upload-image",onClick:()=>{var ye;return(ye=Ee.current)==null?void 0:ye.click()},children:[m.jsx(So,{children:m.jsx(ap,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-upload-file",onClick:()=>{var ye;return(ye=me.current)==null?void 0:ye.click()},children:[m.jsx(So,{children:m.jsx(sI,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Iw,{})]}):null,m.jsx(dg,{className:Ng,children:"字号"}),m.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:m.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[m.jsx(So,{children:m.jsx(Q7,{"aria-hidden":"true"})}),m.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:P<=I,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ye=>{ye.stopPropagation(),oe(-1)},children:m.jsx(v7,{"aria-hidden":"true"})}),m.jsxs("span",{className:"flex h-[22px] min-w-11 items-center justify-center px-1 text-sm font-medium leading-none tabular-nums text-foreground","data-slot":"chat-menu-font-size",children:[P,"px"]}),m.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:P>=EI,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ye=>{ye.stopPropagation(),oe(1)},children:m.jsx(N7,{"aria-hidden":"true"})})]})]})}),m.jsxs(Js,{className:ju,"data-slot":"chat-menu-font-reset",onClick:W,children:[m.jsx(So,{children:m.jsx(L7,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(ch,{open:De,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Se,onRename:Ht}),m.jsx(xa,{open:j&&!K.enabled,onOpenChange:ye=>{Y||L(ye)},children:m.jsxs(Ea,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ca,{children:[m.jsx(Io,{children:"开启 Voice Pilot?"}),m.jsx(_a,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Rl,{children:[m.jsx(Ct,{type:"button",variant:"outline",disabled:Y,onClick:()=>L(!1),children:"取消"}),m.jsx(Ct,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Y,onClick:()=>{ae()},children:Y?"正在开启...":"开启 Voice Pilot"})]})]})}),A?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:Ee,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ye=>{Je(ye)}}),m.jsx("input",{ref:me,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ye=>{Je(ye)}})]}):null]})}function $u(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let f;n.key&&((l=n.debug)!=null&&l.call(n))&&(f=Date.now());const p=e();if(!(p.length!==r.length||p.some((_,w)=>r[w]!==_)))return i;r=p;let v;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(v=Date.now()),i=t(...p),n.key&&((d=n.debug)!=null&&d.call(n))){const _=Math.round((Date.now()-f)*100)/100,w=Math.round((Date.now()-v)*100)/100,S=w/16,x=(k,T)=>{for(k=String(k);k.length<T;)k=" "+k;return k};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
673
673
  font-size: .6rem;
674
674
  font-weight: bold;
675
675
  color: hsl(${Math.max(0,Math.min(120-120*S,120))}deg 100% 31%);`,n==null?void 0:n.key)}return n!=null&&n.onChange&&!(s&&n.skipInitialOnChange)&&n.onChange(i),s=!1,i}return o.updateDeps=l=>{r=l},o}function TO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const M_e=(e,t)=>Math.abs(e-t)<1.01,N_e=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},RO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},P_e=e=>e,O_e=e=>{const t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),r=[];for(let i=t;i<=n;i++)r.push(i);return r},L_e=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const i=o=>{const{width:l,height:u}=o;t({width:Math.round(l),height:Math.round(u)})};if(i(RO(n)),!r.ResizeObserver)return()=>{};const s=new r.ResizeObserver(o=>{const l=()=>{const u=o[0];if(u!=null&&u.borderBoxSize){const d=u.borderBoxSize[0];if(d){i({width:d.inlineSize,height:d.blockSize});return}}i(RO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},AO={passive:!0},MO=typeof window>"u"?!0:"onscrollend"in window,D_e=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&MO?()=>{}:N_e(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=f=>()=>{const{horizontal:p,isRtl:y}=e.options;i=p?n.scrollLeft*(y&&-1||1):n.scrollTop,s(),t(i,f)},l=o(!0),u=o(!1);n.addEventListener("scroll",l,AO);const d=e.options.useScrollendEvent&&MO;return d&&n.addEventListener("scrollend",u,AO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},I_e=(e,t,n)=>{if(t!=null&&t.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},B_e=(e,{adjustments:t=0,behavior:n},r)=>{var i,s;const o=e+t;(s=(i=r.scrollElement)==null?void 0:i.scrollTo)==null||s.call(i,{[r.options.horizontal?"left":"top"]:o,behavior:n})};class z_e{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var n,r,i;return((i=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:i.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(i=>{i.forEach(s=>{const o=()=>{const l=s.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var i;(i=r())==null||i.disconnect(),n=null},observe:i=>{var s;return(s=r())==null?void 0:s.observe(i,{box:"border-box"})},unobserve:i=>{var s;return(s=r())==null?void 0:s.unobserve(i)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([r,i])=>{typeof i>"u"&&delete n[r]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:P_e,rangeExtractor:O_e,onChange:()=>{},measureElement:I_e,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...n}},this.notify=n=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,n)},this.maybeNotify=$u(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,s)=>{this.scrollAdjustments=0,this.scrollDirection=s?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=s,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(n,r)=>{const i=new Map,s=new Map;for(let o=r-1;o>=0;o--){const l=n[o];if(i.has(l.lane))continue;const u=s.get(l.lane);if(u==null||l.end>u.end?s.set(l.lane,l):l.end<u.end&&i.set(l.lane,!0),i.size===this.options.lanes)break}return s.size===this.options.lanes?Array.from(s.values()).sort((o,l)=>o.end===l.end?o.index-l.index:o.end-l.end)[0]:void 0},this.getMeasurementOptions=$u(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(n,r,i,s,o,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:i,getItemKey:s,enabled:o,lanes:l,laneAssignmentMode:u}),{key:!1}),this.getMeasurements=$u(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:i,getItemKey:s,enabled:o,lanes:l,laneAssignmentMode:u},d)=>{if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const v of this.laneAssignments.keys())v>=n&&this.laneAssignments.delete(v);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(v=>{this.itemSizeCache.set(v.key,v.size)}));const f=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1);const p=this.measurementsCache.slice(0,f),y=new Array(l).fill(void 0);for(let v=0;v<f;v++){const _=p[v];_&&(y[_.lane]=v)}for(let v=f;v<n;v++){const _=s(v),w=this.laneAssignments.get(v);let S,x;const k=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){S=w;const A=y[S],O=A!==void 0?p[A]:void 0;x=O?O.end+this.options.gap:r+i}else{const A=this.options.lanes===1?p[v-1]:this.getFurthestMeasurement(p,v);x=A?A.end+this.options.gap:r+i,S=A?A.lane:v%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(v,S)}const T=d.get(_),R=typeof T=="number"?T:this.options.estimateSize(v),N=x+R;p[v]={index:v,start:x,size:R,end:N,key:_,lane:S},y[S]=v}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=$u(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?j_e({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=$u(()=>{let n=null,r=null;const i=this.calculateRange();return i&&(n=i.startIndex,r=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,i,s,o)=>s===null||o===null?[]:n({startIndex:s,endIndex:o,overscan:r,count:i}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,i=n.getAttribute(r);return i?parseInt(i,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const i=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(i!==void 0&&this.range){const s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,i-s),l=Math.min(this.options.count-1,i+s);return n>=o&&n<=l}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((o,l)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(l))});return}const r=this.indexFromElement(n),i=this.options.getItemKey(r),s=this.elementsCache.get(i);s!==n&&(s&&this.observer.unobserve(s),this.observer.observe(n),this.elementsCache.set(i,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var i;const s=this.measurementsCache[n];if(!s)return;const o=this.itemSizeCache.get(s.key)??s.size,l=r-o;l!==0&&(((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(s,l,this):s.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=l,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(s.index),this.itemSizeCache=new Map(this.itemSizeCache.set(s.key,r)),this.notify(!1))},this.getVirtualItems=$u(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const i=[];for(let s=0,o=n.length;s<o;s++){const l=n[s],u=r[l];i.push(u)}return i},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length!==0)return TO(r[b$(0,r.length-1,i=>TO(r[i]).start,n)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(n,r,i=0)=>{if(!this.scrollElement)return 0;const s=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=n>=o+s?"end":"start"),r==="center"?n+=(i-s)/2:r==="end"&&(n-=s);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.getSize(),s=this.getScrollOffset(),o=this.measurementsCache[n];if(!o)return;if(r==="auto")if(o.end>=s+i-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,o.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:i="auto"}={})=>{const s=this.getOffsetForAlignment(n,r),o=this.now();this.scrollState={index:null,align:r,behavior:i,startedAt:o,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:i="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const s=this.getOffsetForIndex(n,r);if(!s)return;const[o,l]=s,u=this.now();this.scrollState={index:n,align:l,behavior:i,startedAt:u,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const i=this.getScrollOffset()+n,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((n=r[r.length-1])==null?void 0:n.end)??0;else{const s=Array(this.options.lanes).fill(null);let o=r.length-1;for(;o>=0&&s.some(l=>l===null);){const l=r[o];s[l.lane]===null&&(s[l.lane]=l.end),o--}i=Math.max(...s.filter(l=>l!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:i})=>{this.options.scrollToFn(n,{behavior:i,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(t)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=r?r[0]:this.scrollState.lastTargetOffset,s=1,o=i!==this.scrollState.lastTargetOffset;if(!o&&M_e(i,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.scrollState=null;return}}else this.scrollState.stableFrames=0,o&&(this.scrollState.lastTargetOffset=i,this.scrollState.behavior="auto",this._scrollToOffset(i,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const b$=(e,t,n,r)=>{for(;e<=t;){const i=(e+t)/2|0,s=n(i);if(s<r)e=i+1;else if(s>r)t=i-1;else return i}return e>0?e-1:0};function j_e({measurements:e,outerSize:t,scrollOffset:n,lanes:r}){const i=e.length-1,s=u=>e[u].start;if(e.length<=r)return{startIndex:0,endIndex:i};let o=b$(0,i,s,n),l=o;if(r===1)for(;l<i&&e[l].end<n+t;)l++;else if(r>1){const u=Array(r).fill(0);for(;l<i&&u.some(f=>f<n+t);){const f=e[l];u[f.lane]=f.end,l++}const d=Array(r).fill(n+t);for(;o>=0&&d.some(f=>f>=n);){const f=e[o];d[f.lane]=f.start,o--}o=Math.max(0,o-o%r),l=Math.min(i,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}const NO=typeof document<"u"?b.useLayoutEffect:b.useEffect;function $_e({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?Hc.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new z_e(r));return i.setOptions(r),NO(()=>i._didMount(),[]),NO(()=>i._willUpdate()),i}function F_e(e){return $_e({observeElementRect:L_e,observeElementOffset:D_e,scrollToFn:B_e,...e})}function H_e(e){var n;const t=[];for(const r of e.matchAll(new RegExp("(?<!\\S)@(.+?)(?=\\s+@|\\s*$)","gu"))){const i=r[1]??"",s=r.index??-1;if(s<0||!i)continue;const o=_C(i)?"image":xC(i,{allowBare:!0})?"file":null;o&&t.push({kind:o,path:i,start:s,end:s+(((n=r[0])==null?void 0:n.length)??0)})}return t}function U_e(e){const t=H_e(e),n=[];let r=e.trimEnd().length;for(let i=t.length-1;i>=0;i-=1){const s=t[i];if(s){if(!/^\s*$/u.test(e.slice(s.end,r))||e[s.start]!=="@")break;n.unshift({kind:s.kind,path:s.path}),r=s.start}}return n.length===0?{bodyText:e,attachments:[]}:{bodyText:e.slice(0,r).trimEnd(),attachments:n}}function W_e(e){return e.kind==="diff"}const q_e=12e4;function PO(e){return e?e.replace(/\r\n?/gu,`