@dev-anywhere/relay 0.5.30 → 0.5.31

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.
@@ -527,7 +527,7 @@ ${t}`:e:t}function j_(e,t,n){const r=Ug(t),i=Ug(n);return!r&&!i?null:{kind:"diff
527
527
 
528
528
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
529
529
 
530
- 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},vee="DialogDescriptionWarning",yee=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${jI(vee).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},l1=CI,bee=TI,c1=AI,u1=NI,d1=MI,FI=PI,$I=LI,Pv=zI;function _ee(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 wee(e){const[t,n]=b.useState(void 0);return Ci(()=>{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 See=["top","right","bottom","left"],ul=Math.min,cs=Math.max,qg=Math.round,jm=Math.floor,Eo=e=>({x:e,y:e}),xee={left:"right",right:"left",bottom:"top",top:"bottom"};function N0(e,t,n){return cs(e,ul(t,n))}function oa(e,t){return typeof e=="function"?e(t):e}function aa(e){return e.split("-")[0]}function cd(e){return e.split("-")[1]}function h1(e){return e==="x"?"y":"x"}function f1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function p1(e){return h1(So(e))}function Eee(e,t,n){n===void 0&&(n=!1);const r=cd(e),i=p1(e),s=f1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Vg(o)),[o,Vg(o)]}function Cee(e){const t=Vg(e);return[M0(e),t,M0(t)]}function M0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const RN=["left","right"],AN=["right","left"],kee=["top","bottom"],Tee=["bottom","top"];function Ree(e,t,n){switch(e){case"top":case"bottom":return n?t?AN:RN:t?RN:AN;case"left":case"right":return t?kee:Tee;default:return[]}}function Aee(e,t,n,r){const i=cd(e);let s=Ree(aa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(M0)))),s}function Vg(e){const t=aa(e);return xee[t]+e.slice(t.length)}function Nee(e){return{top:0,right:0,bottom:0,left:0,...e}}function HI(e){return typeof e!="number"?Nee(e):{top:e,right:e,bottom:e,left:e}}function Yg(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 NN(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=p1(t),l=f1(o),u=aa(t),d=s==="y",h=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:h,y:r.y-i.height};break;case"bottom":v={x:h,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(cd(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 Mee(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:h="viewport",elementContext:p="floating",altBoundary:y=!1,padding:v=0}=oa(t,e),_=HI(v),E=l[y?p==="floating"?"reference":"floating":p],x=Yg(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(E)))==null||n?E:E.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),A=await(s.isElement==null?void 0:s.isElement(R))?await(s.getScale==null?void 0:s.getScale(R))||{x:1,y:1}:{x:1,y:1},L=Yg(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(x.top-L.top+_.top)/A.y,bottom:(L.bottom-x.bottom+_.bottom)/A.y,left:(x.left-L.left+_.left)/A.x,right:(L.right-x.right+_.right)/A.x}}const Oee=50,Pee=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:Mee},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=NN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const E=s[w];if(!E)continue;const{name:x,fn:k}=E,{x:R,y:A,data:L,reset:T}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});h=R??h,p=A??p,_[x]={..._[x],...L},T&&v<Oee&&(v++,typeof T=="object"&&(T.placement&&(y=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:p}=NN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:_}},Dee=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:h=0}=oa(e,t)||{};if(d==null)return{};const p=HI(h),y={x:n,y:r},v=p1(i),_=f1(v),w=await o.getDimensions(d),E=v==="y",x=E?"top":"left",k=E?"bottom":"right",R=E?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[v]-y[v]-s.floating[_],L=y[v]-s.reference[v],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let H=T?T[R]:0;(!H||!await(o.isElement==null?void 0:o.isElement(T)))&&(H=l.floating[R]||s.floating[_]);const D=A/2-L/2,U=H/2-w[_]/2-1,W=ul(p[x],U),F=ul(p[k],U),O=W,M=H-w[_]-F,z=H/2-w[_]/2+D,P=N0(O,z,M),N=!u.arrow&&cd(i)!=null&&z!==P&&s.reference[_]/2-(z<O?W:F)-w[_]/2<0,q=N?z<O?z-O:z-M:0;return{[v]:y[v]+q,data:{[v]:P,centerOffset:z-P-q,...N&&{alignmentOffset:q}},reset:N}}}),Lee=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:h=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...E}=oa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=aa(i),k=So(l),R=aa(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),L=y||(R||!w?[Vg(l)]:Cee(l)),T=_!=="none";!y&&T&&L.push(...Aee(l,w,_,A));const H=[l,...L],D=await u.detectOverflow(t,E),U=[];let W=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&U.push(D[x]),p){const z=Eee(i,o,A);U.push(D[z[0]],D[z[1]])}if(W=[...W,{placement:i,overflows:U}],!U.every(z=>z<=0)){var F,O;const z=(((F=s.flip)==null?void 0:F.index)||0)+1,P=H[z];if(P&&(!(p==="alignment"?k!==So(P):!1)||W.every(V=>So(V.placement)===k?V.overflows[0]>0:!0)))return{data:{index:z,overflows:W},reset:{placement:P}};let N=(O=W.filter(q=>q.overflows[0]<=0).sort((q,V)=>q.overflows[1]-V.overflows[1])[0])==null?void 0:O.placement;if(!N)switch(v){case"bestFit":{var M;const q=(M=W.filter(V=>{if(T){const $=So(V.placement);return $===k||$==="y"}return!0}).map(V=>[V.placement,V.overflows.filter($=>$>0).reduce(($,I)=>$+I,0)]).sort((V,$)=>V[1]-$[1])[0])==null?void 0:M[0];q&&(N=q);break}case"initialPlacement":N=l;break}if(i!==N)return{reset:{placement:N}}}return{}}}};function MN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function ON(e){return See.some(t=>e[t]>=0)}const Iee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=oa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=MN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:ON(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=MN(o,n.floating);return{data:{escapedOffsets:l,escaped:ON(l)}}}default:return{}}}}},UI=new Set(["left","top"]);async function zee(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=aa(n),l=cd(n),u=So(n)==="y",d=UI.has(o)?-1:1,h=s&&u?-1:1,p=oa(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*h,y:y*d}:{x:y*d,y:v*h}}const Bee=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 zee(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}}}}},jee=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:R}=x;return{x:k,y:R}}},...d}=oa(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=So(aa(i)),v=h1(y);let _=h[v],w=h[y];if(o){const x=v==="y"?"top":"left",k=v==="y"?"bottom":"right",R=_+p[x],A=_-p[k];_=N0(R,_,A)}if(l){const x=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+p[x],A=w-p[k];w=N0(R,w,A)}const E=u.fn({...t,[v]:_,[y]:w});return{...E,data:{x:E.x-n,y:E.y-r,enabled:{[v]:o,[y]:l}}}}}},Fee=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}=oa(e,t),h={x:n,y:r},p=So(i),y=h1(p);let v=h[y],_=h[p];const w=oa(l,t),E=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const R=y==="y"?"height":"width",A=s.reference[y]-s.floating[R]+E.mainAxis,L=s.reference[y]+s.reference[R]-E.mainAxis;v<A?v=A:v>L&&(v=L)}if(d){var x,k;const R=y==="y"?"width":"height",A=UI.has(aa(i)),L=s.reference[p]-s.floating[R]+(A&&((x=o.offset)==null?void 0:x[p])||0)+(A?0:E.crossAxis),T=s.reference[p]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?E.crossAxis:0);_<L?_=L:_>T&&(_=T)}return{[y]:v,[p]:_}}}},$ee=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}=oa(e,t),h=await o.detectOverflow(t,d),p=aa(i),y=cd(i),v=So(i)==="y",{width:_,height:w}=s.floating;let E,x;p==="top"||p==="bottom"?(E=p,x=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=p,E=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,R=_-h.left-h.right,A=ul(w-h[E],k),L=ul(_-h[x],R),T=!t.middlewareData.shift;let H=A,D=L;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(D=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(H=k),T&&!y){const W=cs(h.left,0),F=cs(h.right,0),O=cs(h.top,0),M=cs(h.bottom,0);v?D=_-2*(W!==0||F!==0?W+F:cs(h.left,h.right)):H=w-2*(O!==0||M!==0?O+M:cs(h.top,h.bottom))}await u({...t,availableWidth:D,availableHeight:H});const U=await o.getDimensions(l.floating);return _!==U.width||w!==U.height?{reset:{rects:!0}}:{}}}};function Dv(){return typeof window<"u"}function ud(e){return WI(e)?(e.nodeName||"").toLowerCase():"#document"}function us(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function No(e){var t;return(t=(WI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function WI(e){return Dv()?e instanceof Node||e instanceof us(e).Node:!1}function Gs(e){return Dv()?e instanceof Element||e instanceof us(e).Element:!1}function ca(e){return Dv()?e instanceof HTMLElement||e instanceof us(e).HTMLElement:!1}function PN(e){return!Dv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof us(e).ShadowRoot}function jf(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Xs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Hee(e){return/^(table|td|th)$/.test(ud(e))}function Lv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Uee=/transform|translate|scale|rotate|perspective|filter/,Wee=/paint|layout|strict|content/,ql=e=>!!e&&e!=="none";let K_;function m1(e){const t=Gs(e)?Xs(e):e;return ql(t.transform)||ql(t.translate)||ql(t.scale)||ql(t.rotate)||ql(t.perspective)||!g1()&&(ql(t.backdropFilter)||ql(t.filter))||Uee.test(t.willChange||"")||Wee.test(t.contain||"")}function qee(e){let t=dl(e);for(;ca(t)&&!Ku(t);){if(m1(t))return t;if(Lv(t))return null;t=dl(t)}return null}function g1(){return K_==null&&(K_=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),K_}function Ku(e){return/^(html|body|#document)$/.test(ud(e))}function Xs(e){return us(e).getComputedStyle(e)}function Iv(e){return Gs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function dl(e){if(ud(e)==="html")return e;const t=e.assignedSlot||e.parentNode||PN(e)&&e.host||No(e);return PN(t)?t.host:t}function qI(e){const t=dl(e);return Ku(t)?e.ownerDocument?e.ownerDocument.body:e.body:ca(t)&&jf(t)?t:qI(t)}function mf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=qI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=us(i);if(s){const l=O0(o);return t.concat(o,o.visualViewport||[],jf(i)?i:[],l&&n?mf(l):[])}else return t.concat(i,mf(i,[],n))}function O0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function VI(e){const t=Xs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=ca(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=qg(n)!==s||qg(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function v1(e){return Gs(e)?e:e.contextElement}function Fu(e){const t=v1(e);if(!ca(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=VI(t);let o=(s?qg(n.width):n.width)/r,l=(s?qg(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Vee=Eo(0);function YI(e){const t=us(e);return!g1()||!t.visualViewport?Vee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Yee(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==us(e)?!1:t}function cc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=v1(e);let o=Eo(1);t&&(r?Gs(r)&&(o=Fu(r)):o=Fu(e));const l=Yee(s,n,r)?YI(s):Eo(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,h=i.width/o.x,p=i.height/o.y;if(s){const y=us(s),v=r&&Gs(r)?us(r):r;let _=y,w=O0(_);for(;w&&r&&v!==_;){const E=Fu(w),x=w.getBoundingClientRect(),k=Xs(w),R=x.left+(w.clientLeft+parseFloat(k.paddingLeft))*E.x,A=x.top+(w.clientTop+parseFloat(k.paddingTop))*E.y;u*=E.x,d*=E.y,h*=E.x,p*=E.y,u+=R,d+=A,_=us(w),w=O0(_)}}return Yg({width:h,height:p,x:u,y:d})}function zv(e,t){const n=Iv(e).scrollLeft;return t?t.left+n:cc(No(e)).left+n}function KI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-zv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Kee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Lv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=Eo(1);const h=Eo(0),p=ca(r);if((p||!p&&!s)&&((ud(r)!=="body"||jf(o))&&(u=Iv(r)),p)){const v=cc(r);d=Fu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?KI(o,u):Eo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function Gee(e){return Array.from(e.getClientRects())}function Xee(e){const t=No(e),n=Iv(e),r=e.ownerDocument.body,i=cs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=cs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+zv(e);const l=-n.scrollTop;return Xs(r).direction==="rtl"&&(o+=cs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const DN=25;function Zee(e,t){const n=us(e),r=No(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=g1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=zv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),v=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-v);_<=DN&&(s-=_)}else d<=DN&&(s+=d);return{width:s,height:o,x:l,y:u}}function Qee(e,t){const n=cc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=ca(e)?Fu(e):Eo(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 LN(e,t,n){let r;if(t==="viewport")r=Zee(e,n);else if(t==="document")r=Xee(No(e));else if(Gs(t))r=Qee(t,n);else{const i=YI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Yg(r)}function GI(e,t){const n=dl(e);return n===t||!Gs(n)||Ku(n)?!1:Xs(n).position==="fixed"||GI(n,t)}function Jee(e,t){const n=t.get(e);if(n)return n;let r=mf(e,[],!1).filter(l=>Gs(l)&&ud(l)!=="body"),i=null;const s=Xs(e).position==="fixed";let o=s?dl(e):e;for(;Gs(o)&&!Ku(o);){const l=Xs(o),u=m1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||jf(o)&&!u&&GI(e,o))?r=r.filter(h=>h!==o):i=l,o=dl(o)}return t.set(e,r),r}function ete(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Lv(t)?[]:Jee(t,this._c):[].concat(n),r],l=LN(t,o[0],i);let u=l.top,d=l.right,h=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const v=LN(t,o[y],i);u=cs(v.top,u),d=ul(v.right,d),h=ul(v.bottom,h),p=cs(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function tte(e){const{width:t,height:n}=VI(e);return{width:t,height:n}}function nte(e,t,n){const r=ca(t),i=No(t),s=n==="fixed",o=cc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=Eo(0);function d(){u.x=zv(i)}if(r||!r&&!s)if((ud(t)!=="body"||jf(i))&&(l=Iv(t)),r){const v=cc(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?KI(i,l):Eo(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function G_(e){return Xs(e).position==="static"}function IN(e,t){if(!ca(e)||Xs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return No(e)===n&&(n=n.ownerDocument.body),n}function XI(e,t){const n=us(e);if(Lv(e))return n;if(!ca(e)){let i=dl(e);for(;i&&!Ku(i);){if(Gs(i)&&!G_(i))return i;i=dl(i)}return n}let r=IN(e,t);for(;r&&Hee(r)&&G_(r);)r=IN(r,t);return r&&Ku(r)&&G_(r)&&!m1(r)?n:r||qee(e)||n}const rte=async function(e){const t=this.getOffsetParent||XI,n=this.getDimensions,r=await n(e.floating);return{reference:nte(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function ite(e){return Xs(e).direction==="rtl"}const ste={convertOffsetParentRelativeRectToViewportRelativeRect:Kee,getDocumentElement:No,getClippingRect:ete,getOffsetParent:XI,getElementRects:rte,getClientRects:Gee,getDimensions:tte,getScale:Fu,isElement:Gs,isRTL:ite};function ZI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ote(e,t){let n=null,r;const i=No(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:h,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const _=jm(p),w=jm(i.clientWidth-(h+y)),E=jm(i.clientHeight-(p+v)),x=jm(h),R={rootMargin:-_+"px "+-w+"px "+-E+"px "+-x+"px",threshold:cs(0,ul(1,u))||1};let A=!0;function L(T){const H=T[0].intersectionRatio;if(H!==u){if(!A)return o();H?o(!1,H):r=setTimeout(()=>{o(!1,1e-7)},1e3)}H===1&&!ZI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(L,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(L,R)}n.observe(e)}return o(!0),s}function ate(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=v1(e),h=i||s?[...d?mf(d):[],...t?mf(t):[]]:[];h.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const p=d&&l?ote(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 R;(R=v)==null||R.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let _,w=u?cc(e):null;u&&E();function E(){const x=cc(e);w&&!ZI(w,x)&&n(),w=x,_=requestAnimationFrame(E)}return n(),()=>{var x;h.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 lte=Bee,cte=jee,ute=Lee,dte=$ee,hte=Iee,zN=Dee,fte=Fee,pte=(e,t,n)=>{const r=new Map,i={platform:ste,...n},s={...i.platform,_c:r};return Pee(e,t,{...i,platform:s})};var mte=typeof document<"u",gte=function(){},_g=mte?b.useLayoutEffect:gte;function Kg(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(!Kg(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)&&!Kg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function QI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function BN(e,t){const n=QI(e);return Math.round(t*n)/n}function X_(e){const t=b.useRef(e);return _g(()=>{t.current=e}),t}function vte(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,[h,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=b.useState(r);Kg(y,r)||v(r);const[_,w]=b.useState(null),[E,x]=b.useState(null),k=b.useCallback(V=>{V!==T.current&&(T.current=V,w(V))},[]),R=b.useCallback(V=>{V!==H.current&&(H.current=V,x(V))},[]),A=s||_,L=o||E,T=b.useRef(null),H=b.useRef(null),D=b.useRef(h),U=u!=null,W=X_(u),F=X_(i),O=X_(d),M=b.useCallback(()=>{if(!T.current||!H.current)return;const V={placement:t,strategy:n,middleware:y};F.current&&(V.platform=F.current),pte(T.current,H.current,V).then($=>{const I={...$,isPositioned:O.current!==!1};z.current&&!Kg(D.current,I)&&(D.current=I,od.flushSync(()=>{p(I)}))})},[y,t,n,F,O]);_g(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,p(V=>({...V,isPositioned:!1})))},[d]);const z=b.useRef(!1);_g(()=>(z.current=!0,()=>{z.current=!1}),[]),_g(()=>{if(A&&(T.current=A),L&&(H.current=L),A&&L){if(W.current)return W.current(A,L,M);M()}},[A,L,M,W,U]);const P=b.useMemo(()=>({reference:T,floating:H,setReference:k,setFloating:R}),[k,R]),N=b.useMemo(()=>({reference:A,floating:L}),[A,L]),q=b.useMemo(()=>{const V={position:n,left:0,top:0};if(!N.floating)return V;const $=BN(N.floating,h.x),I=BN(N.floating,h.y);return l?{...V,transform:"translate("+$+"px, "+I+"px)",...QI(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:I}},[n,l,N.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:M,refs:P,elements:N,floatingStyles:q}),[h,M,P,N,q])}const yte=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?zN({element:r.current,padding:i}).fn(n):{}:r?zN({element:r,padding:i}).fn(n):{}}}},bte=(e,t)=>{const n=lte(e);return{name:n.name,fn:n.fn,options:[e,t]}},_te=(e,t)=>{const n=cte(e);return{name:n.name,fn:n.fn,options:[e,t]}},wte=(e,t)=>({fn:fte(e).fn,options:[e,t]}),Ste=(e,t)=>{const n=ute(e);return{name:n.name,fn:n.fn,options:[e,t]}},xte=(e,t)=>{const n=dte(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ete=(e,t)=>{const n=hte(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cte=(e,t)=>{const n=yte(e);return{name:n.name,fn:n.fn,options:[e,t]}};var kte="Arrow",JI=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Jt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:g.jsx("polygon",{points:"0,0 30,0 15,10"})})});JI.displayName=kte;var Tte=JI,y1="Popper",[ez,wl]=la(y1),[Rte,tz]=ez(y1),nz=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return g.jsx(Rte,{scope:t,anchor:r,onAnchorChange:i,children:n})};nz.displayName=y1;var rz="PopperAnchor",iz=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=tz(rz,n),o=b.useRef(null),l=Bn(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:g.jsx(Jt.div,{...i,ref:l})});iz.displayName=rz;var b1="PopperContent",[Ate,Nte]=ez(b1),sz=b.forwardRef((e,t)=>{var Q,fe,ce,Ee,Me,Ie;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:v="optimized",onPlaced:_,...w}=e,E=tz(b1,n),[x,k]=b.useState(null),R=Bn(t,Ye=>k(Ye)),[A,L]=b.useState(null),T=wee(A),H=(T==null?void 0:T.width)??0,D=(T==null?void 0:T.height)??0,U=r+(s!=="center"?"-"+s:""),W=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},F=Array.isArray(d)?d:[d],O=F.length>0,M={padding:W,boundary:F.filter(Ote),altBoundary:O},{refs:z,floatingStyles:P,placement:N,isPositioned:q,middlewareData:V}=vte({strategy:"fixed",placement:U,whileElementsMounted:(...Ye)=>ate(...Ye,{animationFrame:v==="always"}),elements:{reference:E.anchor},middleware:[bte({mainAxis:i+D,alignmentAxis:o}),u&&_te({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?wte():void 0,...M}),u&&Ste({...M}),xte({...M,apply:({elements:Ye,rects:xt,availableWidth:gn,availableHeight:ge})=>{const{width:rt,height:et}=xt.reference,ye=Ye.floating.style;ye.setProperty("--radix-popper-available-width",`${gn}px`),ye.setProperty("--radix-popper-available-height",`${ge}px`),ye.setProperty("--radix-popper-anchor-width",`${rt}px`),ye.setProperty("--radix-popper-anchor-height",`${et}px`)}}),A&&Cte({element:A,padding:l}),Pte({arrowWidth:H,arrowHeight:D}),y&&Ete({strategy:"referenceHidden",...M})]}),[$,I]=lz(N),Y=To(_);Ci(()=>{q&&(Y==null||Y())},[q,Y]);const G=(Q=V.arrow)==null?void 0:Q.x,j=(fe=V.arrow)==null?void 0:fe.y,ee=((ce=V.arrow)==null?void 0:ce.centerOffset)!==0,[J,te]=b.useState();return Ci(()=>{x&&te(window.getComputedStyle(x).zIndex)},[x]),g.jsx("div",{ref:z.setFloating,"data-radix-popper-content-wrapper":"",style:{...P,transform:q?P.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(Ee=V.transformOrigin)==null?void 0:Ee.x,(Me=V.transformOrigin)==null?void 0:Me.y].join(" "),...((Ie=V.hide)==null?void 0:Ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(Ate,{scope:n,placedSide:$,onArrowChange:L,arrowX:G,arrowY:j,shouldHideArrow:ee,children:g.jsx(Jt.div,{"data-side":$,"data-align":I,...w,ref:R,style:{...w.style,animation:q?void 0:"none"}})})})});sz.displayName=b1;var oz="PopperArrow",Mte={top:"bottom",right:"left",bottom:"top",left:"right"},az=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Nte(oz,r),o=Mte[s.placedSide];return g.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:g.jsx(Tte,{...i,ref:n,style:{...i.style,display:"block"}})})});az.displayName=oz;function Ote(e){return e!==null}var Pte=e=>({name:"transformOrigin",options:e,fn(t){var E,x,k;const{placement:n,rects:r,middlewareData:i}=t,o=((E=i.arrow)==null?void 0:E.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,h]=lz(n),p={start:"0%",center:"50%",end:"100%"}[h],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 lz(e){const[t,n="center"]=e.split("-");return[t,n]}var Bv=nz,Ff=iz,jv=sz,Fv=az,Z_="rovingFocusGroup.onEntryFocus",Dte={bubbles:!1,cancelable:!0},$f="RovingFocusGroup",[P0,cz,Lte]=r1($f),[Ite,uz]=la($f,[Lte]),[zte,Bte]=Ite($f),dz=b.forwardRef((e,t)=>g.jsx(P0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(P0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(jte,{...e,ref:t})})}));dz.displayName=$f;var jte=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...p}=e,y=b.useRef(null),v=Bn(t,y),_=i1(s),[w,E]=ac({prop:o,defaultProp:l??null,onChange:u,caller:$f}),[x,k]=b.useState(!1),R=To(d),A=cz(n),L=b.useRef(!1),[T,H]=b.useState(0);return b.useEffect(()=>{const D=y.current;if(D)return D.addEventListener(Z_,R),()=>D.removeEventListener(Z_,R)},[R]),g.jsx(zte,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(D=>E(D),[E]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>H(D=>D+1),[]),onFocusableItemRemove:b.useCallback(()=>H(D=>D-1),[]),children:g.jsx(Jt.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:St(e.onMouseDown,()=>{L.current=!0}),onFocus:St(e.onFocus,D=>{const U=!L.current;if(D.target===D.currentTarget&&U&&!x){const W=new CustomEvent(Z_,Dte);if(D.currentTarget.dispatchEvent(W),!W.defaultPrevented){const F=A().filter(N=>N.focusable),O=F.find(N=>N.active),M=F.find(N=>N.id===w),P=[O,M,...F].filter(Boolean).map(N=>N.ref.current);pz(P,h)}}L.current=!1}),onBlur:St(e.onBlur,()=>k(!1))})})}),hz="RovingFocusGroupItem",fz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=vi(),d=s||u,h=Bte(hz,n),p=h.currentTabStopId===d,y=cz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=h;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),g.jsx(P0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Jt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:St(e.onMouseDown,E=>{r?h.onItemFocus(d):E.preventDefault()}),onFocus:St(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:St(e.onKeyDown,E=>{if(E.key==="Tab"&&E.shiftKey){h.onItemShiftTab();return}if(E.target!==E.currentTarget)return;const x=Hte(E,h.orientation,h.dir);if(x!==void 0){if(E.metaKey||E.ctrlKey||E.altKey||E.shiftKey)return;E.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(x==="last")R.reverse();else if(x==="prev"||x==="next"){x==="prev"&&R.reverse();const A=R.indexOf(E.currentTarget);R=h.loop?Ute(R,A+1):R.slice(A+1)}setTimeout(()=>pz(R))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});fz.displayName=hz;var Fte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function $te(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Hte(e,t,n){const r=$te(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Fte[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 Ute(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Wte=dz,qte=fz,D0=["Enter"," "],Vte=["ArrowDown","PageUp","Home"],mz=["ArrowUp","PageDown","End"],Yte=[...Vte,...mz],Kte={ltr:[...D0,"ArrowRight"],rtl:[...D0,"ArrowLeft"]},Gte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Hf="Menu",[gf,Xte,Zte]=r1(Hf),[Sc,gz]=la(Hf,[Zte,wl,uz]),$v=wl(),vz=uz(),[Qte,xc]=Sc(Hf),[Jte,Uf]=Sc(Hf),yz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=$v(t),[u,d]=b.useState(null),h=b.useRef(!1),p=To(s),y=i1(i);return b.useEffect(()=>{const v=()=>{h.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>h.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})}},[]),g.jsx(Bv,{...l,children:g.jsx(Qte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(Jte,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};yz.displayName=Hf;var ene="MenuAnchor",_1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=$v(n);return g.jsx(Ff,{...i,...r,ref:t})});_1.displayName=ene;var w1="MenuPortal",[tne,bz]=Sc(w1,{forceMount:void 0}),_z=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=xc(w1,t);return g.jsx(tne,{scope:t,forceMount:n,children:g.jsx(Is,{present:n||s.open,children:g.jsx(ld,{asChild:!0,container:i,children:r})})})};_z.displayName=w1;var Ms="MenuContent",[nne,S1]=Sc(Ms),wz=b.forwardRef((e,t)=>{const n=bz(Ms,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=xc(Ms,e.__scopeMenu),o=Uf(Ms,e.__scopeMenu);return g.jsx(gf.Provider,{scope:e.__scopeMenu,children:g.jsx(Is,{present:r||s.open,children:g.jsx(gf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(rne,{...i,ref:t}):g.jsx(ine,{...i,ref:t})})})})}),rne=b.forwardRef((e,t)=>{const n=xc(Ms,e.__scopeMenu),r=b.useRef(null),i=Bn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Mv(s)},[]),g.jsx(x1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:St(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ine=b.forwardRef((e,t)=>{const n=xc(Ms,e.__scopeMenu);return g.jsx(x1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),sne=cl("MenuContent.ScrollLock"),x1=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,disableOutsideScroll:_,...w}=e,E=xc(Ms,n),x=Uf(Ms,n),k=$v(n),R=vz(n),A=Xte(n),[L,T]=b.useState(null),H=b.useRef(null),D=Bn(t,H,E.onContentChange),U=b.useRef(0),W=b.useRef(""),F=b.useRef(0),O=b.useRef(null),M=b.useRef("right"),z=b.useRef(0),P=_?Bf:b.Fragment,N=_?{as:sne,allowPinchZoom:!0}:void 0,q=$=>{var Q,fe;const I=W.current+$,Y=A().filter(ce=>!ce.disabled),G=document.activeElement,j=(Q=Y.find(ce=>ce.ref.current===G))==null?void 0:Q.textValue,ee=Y.map(ce=>ce.textValue),J=vne(ee,I,j),te=(fe=Y.find(ce=>ce.textValue===J))==null?void 0:fe.ref.current;(function ce(Ee){W.current=Ee,window.clearTimeout(U.current),Ee!==""&&(U.current=window.setTimeout(()=>ce(""),1e3))})(I),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(U.current),[]),Av();const V=b.useCallback($=>{var Y,G;return M.current===((Y=O.current)==null?void 0:Y.side)&&bne($,(G=O.current)==null?void 0:G.area)},[]);return g.jsx(nne,{scope:n,searchRef:W,onItemEnter:b.useCallback($=>{V($)&&$.preventDefault()},[V]),onItemLeave:b.useCallback($=>{var I;V($)||((I=H.current)==null||I.focus(),T(null))},[V]),onTriggerLeave:b.useCallback($=>{V($)&&$.preventDefault()},[V]),pointerGraceTimerRef:F,onPointerGraceIntentChange:b.useCallback($=>{O.current=$},[]),children:g.jsx(P,{...N,children:g.jsx(zf,{asChild:!0,trapped:i,onMountAutoFocus:St(s,$=>{var I;$.preventDefault(),(I=H.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Wte,{asChild:!0,...R,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:L,onCurrentTabStopIdChange:T,onEntryFocus:St(u,$=>{x.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(jv,{role:"menu","aria-orientation":"vertical","data-state":zz(E.open),"data-radix-menu-content":"",dir:x.dir,...k,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:St(w.onKeyDown,$=>{const Y=$.target.closest("[data-radix-menu-content]")===$.currentTarget,G=$.ctrlKey||$.altKey||$.metaKey,j=$.key.length===1;Y&&($.key==="Tab"&&$.preventDefault(),!G&&j&&q($.key));const ee=H.current;if($.target!==ee||!Yte.includes($.key))return;$.preventDefault();const te=A().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);mz.includes($.key)&&te.reverse(),mne(te)}),onBlur:St(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(U.current),W.current="")}),onPointerMove:St(e.onPointerMove,vf($=>{const I=$.target,Y=z.current!==$.clientX;if($.currentTarget.contains(I)&&Y){const G=$.clientX>z.current?"right":"left";M.current=G,z.current=$.clientX}}))})})})})})})});wz.displayName=Ms;var one="MenuGroup",E1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Jt.div,{role:"group",...r,ref:t})});E1.displayName=one;var ane="MenuLabel",Sz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Jt.div,{...r,ref:t})});Sz.displayName=ane;var Gg="MenuItem",jN="menu.itemSelect",Hv=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Uf(Gg,e.__scopeMenu),l=S1(Gg,e.__scopeMenu),u=Bn(t,s),d=b.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(jN,{bubbles:!0,cancelable:!0});p.addEventListener(jN,v=>r==null?void 0:r(v),{once:!0}),cI(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(xz,{...i,ref:u,disabled:n,onClick:St(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:St(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:St(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||D0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Hv.displayName=Gg;var xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=S1(Gg,n),l=vz(n),u=b.useRef(null),d=Bn(t,u),[h,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),g.jsx(gf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(qte,{asChild:!0,...l,focusable:!r,children:g.jsx(Jt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:St(e.onPointerMove,vf(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:St(e.onPointerLeave,vf(_=>o.onItemLeave(_))),onFocus:St(e.onFocus,()=>p(!0)),onBlur:St(e.onBlur,()=>p(!1))})})})}),lne="MenuCheckboxItem",Ez=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(Az,{scope:e.__scopeMenu,checked:n,children:g.jsx(Hv,{role:"menuitemcheckbox","aria-checked":Xg(n)?"mixed":n,...i,ref:t,"data-state":k1(n),onSelect:St(i.onSelect,()=>r==null?void 0:r(Xg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ez.displayName=lne;var Cz="MenuRadioGroup",[cne,une]=Sc(Cz,{value:void 0,onValueChange:()=>{}}),kz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return g.jsx(cne,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(E1,{...i,ref:t})})});kz.displayName=Cz;var Tz="MenuRadioItem",Rz=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=une(Tz,e.__scopeMenu),s=n===i.value;return g.jsx(Az,{scope:e.__scopeMenu,checked:s,children:g.jsx(Hv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":k1(s),onSelect:St(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});Rz.displayName=Tz;var C1="MenuItemIndicator",[Az,dne]=Sc(C1,{checked:!1}),Nz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=dne(C1,n);return g.jsx(Is,{present:r||Xg(s.checked)||s.checked===!0,children:g.jsx(Jt.span,{...i,ref:t,"data-state":k1(s.checked)})})});Nz.displayName=C1;var hne="MenuSeparator",Mz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Jt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Mz.displayName=hne;var fne="MenuArrow",Oz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=$v(n);return g.jsx(Fv,{...i,...r,ref:t})});Oz.displayName=fne;var pne="MenuSub",[PRe,Pz]=Sc(pne),zh="MenuSubTrigger",Dz=b.forwardRef((e,t)=>{const n=xc(zh,e.__scopeMenu),r=Uf(zh,e.__scopeMenu),i=Pz(zh,e.__scopeMenu),s=S1(zh,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>h,[h]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),g.jsx(_1,{asChild:!0,...d,children:g.jsx(xz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":zz(n.open),...e,ref:sa(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:St(e.onPointerMove,vf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:St(e.onPointerLeave,vf(p=>{var v,_;h();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,E=w==="right",x=E?-5:5,k=y[E?"left":"right"],R=y[E?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+x,y:p.clientY},{x:k,y:y.top},{x:R,y:y.top},{x:R,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:St(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Kte[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});Dz.displayName=zh;var Lz="MenuSubContent",Iz=b.forwardRef((e,t)=>{const n=bz(Ms,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=xc(Ms,e.__scopeMenu),o=Uf(Ms,e.__scopeMenu),l=Pz(Lz,e.__scopeMenu),u=b.useRef(null),d=Bn(t,u);return g.jsx(gf.Provider,{scope:e.__scopeMenu,children:g.jsx(Is,{present:r||s.open,children:g.jsx(gf.Slot,{scope:e.__scopeMenu,children:g.jsx(x1,{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:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:St(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:St(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:St(e.onKeyDown,h=>{var v;const p=h.currentTarget.contains(h.target),y=Gte[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),h.preventDefault())})})})})})});Iz.displayName=Lz;function zz(e){return e?"open":"closed"}function Xg(e){return e==="indeterminate"}function k1(e){return Xg(e)?"indeterminate":e?"checked":"unchecked"}function mne(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function gne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function vne(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=gne(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 yne(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,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function bne(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return yne(n,t)}function vf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var _ne=yz,wne=_1,Sne=_z,xne=wz,Ene=E1,Cne=Sz,kne=Hv,Tne=Ez,Rne=kz,Ane=Rz,Nne=Nz,Mne=Mz,One=Oz,Pne=Dz,Dne=Iz,Uv="DropdownMenu",[Lne]=la(Uv,[gz]),Li=gz(),[Ine,Bz]=Lne(Uv),jz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Li(t),d=b.useRef(null),[h,p]=ac({prop:i,defaultProp:s??!1,onChange:o,caller:Uv});return g.jsx(Ine,{scope:t,triggerId:vi(),triggerRef:d,contentId:vi(),open:h,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(_ne,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};jz.displayName=Uv;var Fz="DropdownMenuTrigger",$z=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Bz(Fz,n),o=Li(n);return g.jsx(wne,{asChild:!0,...o,children:g.jsx(Jt.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:sa(t,s.triggerRef),onPointerDown:St(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:St(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});$z.displayName=Fz;var zne="DropdownMenuPortal",Hz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Li(t);return g.jsx(Sne,{...r,...n})};Hz.displayName=zne;var Uz="DropdownMenuContent",Wz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Bz(Uz,n),s=Li(n),o=b.useRef(!1);return g.jsx(xne,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:St(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:St(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(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)"}})});Wz.displayName=Uz;var Bne="DropdownMenuGroup",jne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Ene,{...i,...r,ref:t})});jne.displayName=Bne;var Fne="DropdownMenuLabel",qz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Cne,{...i,...r,ref:t})});qz.displayName=Fne;var $ne="DropdownMenuItem",Vz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(kne,{...i,...r,ref:t})});Vz.displayName=$ne;var Hne="DropdownMenuCheckboxItem",Yz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Tne,{...i,...r,ref:t})});Yz.displayName=Hne;var Une="DropdownMenuRadioGroup",Wne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Rne,{...i,...r,ref:t})});Wne.displayName=Une;var qne="DropdownMenuRadioItem",Vne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Ane,{...i,...r,ref:t})});Vne.displayName=qne;var Yne="DropdownMenuItemIndicator",Kz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Nne,{...i,...r,ref:t})});Kz.displayName=Yne;var Kne="DropdownMenuSeparator",Gz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Mne,{...i,...r,ref:t})});Gz.displayName=Kne;var Gne="DropdownMenuArrow",Xne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(One,{...i,...r,ref:t})});Xne.displayName=Gne;var Zne="DropdownMenuSubTrigger",Qne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Pne,{...i,...r,ref:t})});Qne.displayName=Zne;var Jne="DropdownMenuSubContent",ere=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Dne,{...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)"}})});ere.displayName=Jne;var tre=jz,nre=$z,rre=Hz,ire=Wz,sre=qz,ore=Vz,are=Yz,lre=Kz,cre=Gz;function FN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Wv="Popover",[Xz]=la(Wv,[wl]),Wf=wl(),[ure,Sl]=Xz(Wv),Zz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Wf(t),u=b.useRef(null),[d,h]=b.useState(!1),[p,y]=ac({prop:r,defaultProp:i??!1,onChange:s,caller:Wv});return g.jsx(Bv,{...l,children:g.jsx(ure,{scope:t,contentId:vi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:o,children:n})})};Zz.displayName=Wv;var Qz="PopoverAnchor",dre=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Sl(Qz,n),s=Wf(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(Ff,{...s,...r,ref:t})});dre.displayName=Qz;var Jz="PopoverTrigger",eB=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Sl(Jz,n),s=Wf(n),o=Bn(t,i.triggerRef),l=g.jsx(Jt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":sB(i.open),...r,ref:o,onClick:St(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(Ff,{asChild:!0,...s,children:l})});eB.displayName=Jz;var T1="PopoverPortal",[hre,fre]=Xz(T1,{forceMount:void 0}),tB=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=Sl(T1,t);return g.jsx(hre,{scope:t,forceMount:n,children:g.jsx(Is,{present:n||s.open,children:g.jsx(ld,{asChild:!0,container:i,children:r})})})};tB.displayName=T1;var Gu="PopoverContent",nB=b.forwardRef((e,t)=>{const n=fre(Gu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=Sl(Gu,e.__scopePopover);return g.jsx(Is,{present:r||s.open,children:s.modal?g.jsx(mre,{...i,ref:t}):g.jsx(gre,{...i,ref:t})})});nB.displayName=Gu;var pre=cl("PopoverContent.RemoveScroll"),mre=b.forwardRef((e,t)=>{const n=Sl(Gu,e.__scopePopover),r=b.useRef(null),i=Bn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Mv(o)},[]),g.jsx(Bf,{as:pre,allowPinchZoom:!0,children:g.jsx(rB,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:St(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:St(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:St(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),gre=b.forwardRef((e,t)=>{const n=Sl(Gu,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return g.jsx(rB,{...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()}})}),rB=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,...p}=e,y=Sl(Gu,n),v=Wf(n);return Av(),g.jsx(zf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(jv,{"data-state":sB(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)"}})})})}),iB="PopoverClose",vre=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Sl(iB,n);return g.jsx(Jt.button,{type:"button",...r,ref:t,onClick:St(e.onClick,()=>i.onOpenChange(!1))})});vre.displayName=iB;var yre="PopoverArrow",bre=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Wf(n);return g.jsx(Fv,{...i,...r,ref:t})});bre.displayName=yre;function sB(e){return e?"open":"closed"}var _re=Zz,wre=eB,Sre=tB,xre=nB,Ere=[" ","Enter","ArrowUp","ArrowDown"],Cre=[" ","Enter"],uc="Select",[qv,Vv,kre]=r1(uc),[dd]=la(uc,[kre,wl]),Yv=wl(),[Tre,xl]=dd(uc),[Rre,Are]=dd(uc),oB=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:h,autoComplete:p,disabled:y,required:v,form:_}=e,w=Yv(t),[E,x]=b.useState(null),[k,R]=b.useState(null),[A,L]=b.useState(!1),T=i1(d),[H,D]=ac({prop:r,defaultProp:i??!1,onChange:s,caller:uc}),[U,W]=ac({prop:o,defaultProp:l,onChange:u,caller:uc}),F=b.useRef(null),O=E?_||!!E.closest("form"):!0,[M,z]=b.useState(new Set),P=Array.from(M).map(N=>N.props.value).join(";");return g.jsx(Bv,{...w,children:g.jsxs(Tre,{required:v,scope:t,trigger:E,onTriggerChange:x,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:L,contentId:vi(),value:U,onValueChange:W,open:H,onOpenChange:D,dir:T,triggerPointerDownPosRef:F,disabled:y,children:[g.jsx(qv.Provider,{scope:t,children:g.jsx(Rre,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(N=>{z(q=>new Set(q).add(N))},[]),onNativeOptionRemove:b.useCallback(N=>{z(q=>{const V=new Set(q);return V.delete(N),V})},[]),children:n})}),O?g.jsxs(RB,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:U,onChange:N=>W(N.target.value),disabled:y,form:_,children:[U===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},P):null]})})};oB.displayName=uc;var aB="SelectTrigger",lB=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Yv(n),o=xl(aB,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Vv(n),h=b.useRef("touch"),[p,y,v]=NB(w=>{const E=d().filter(R=>!R.disabled),x=E.find(R=>R.value===o.value),k=MB(E,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 g.jsx(Ff,{asChild:!0,...s,children:g.jsx(Jt.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":AB(o.value)?"":void 0,...i,ref:u,onClick:St(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&_(w)}),onPointerDown:St(i.onPointerDown,w=>{h.current=w.pointerType;const E=w.target;E.hasPointerCapture(w.pointerId)&&E.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:St(i.onKeyDown,w=>{const E=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(E&&w.key===" ")&&Ere.includes(w.key)&&(_(),w.preventDefault())})})})});lB.displayName=aB;var cB="SelectValue",uB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=xl(cB,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ci(()=>{d(h)},[d,h]),g.jsx(Jt.span,{...l,ref:p,style:{pointerEvents:"none"},children:AB(u.value)?g.jsx(g.Fragment,{children:o}):s})});uB.displayName=cB;var Nre="SelectIcon",dB=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Jt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});dB.displayName=Nre;var Mre="SelectPortal",hB=e=>g.jsx(ld,{asChild:!0,...e});hB.displayName=Mre;var dc="SelectContent",fB=b.forwardRef((e,t)=>{const n=xl(dc,e.__scopeSelect),[r,i]=b.useState();if(Ci(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?od.createPortal(g.jsx(pB,{scope:e.__scopeSelect,children:g.jsx(qv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(mB,{...e,ref:t})});fB.displayName=dc;var Ws=10,[pB,El]=dd(dc),Ore="SelectContentImpl",Pre=cl("SelectContent.RemoveScroll"),mB=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:E,...x}=e,k=xl(dc,n),[R,A]=b.useState(null),[L,T]=b.useState(null),H=Bn(t,Q=>A(Q)),[D,U]=b.useState(null),[W,F]=b.useState(null),O=Vv(n),[M,z]=b.useState(!1),P=b.useRef(!1);b.useEffect(()=>{if(R)return Mv(R)},[R]),Av();const N=b.useCallback(Q=>{const[fe,...ce]=O().map(Ie=>Ie.ref.current),[Ee]=ce.slice(-1),Me=document.activeElement;for(const Ie of Q)if(Ie===Me||(Ie==null||Ie.scrollIntoView({block:"nearest"}),Ie===fe&&L&&(L.scrollTop=0),Ie===Ee&&L&&(L.scrollTop=L.scrollHeight),Ie==null||Ie.focus(),document.activeElement!==Me))return},[O,L]),q=b.useCallback(()=>N([D,R]),[N,D,R]);b.useEffect(()=>{M&&q()},[M,q]);const{onOpenChange:V,triggerPointerDownPosRef:$}=k;b.useEffect(()=>{if(R){let Q={x:0,y:0};const fe=Ee=>{var Me,Ie;Q={x:Math.abs(Math.round(Ee.pageX)-(((Me=$.current)==null?void 0:Me.x)??0)),y:Math.abs(Math.round(Ee.pageY)-(((Ie=$.current)==null?void 0:Ie.y)??0))}},ce=Ee=>{Q.x<=10&&Q.y<=10?Ee.preventDefault():R.contains(Ee.target)||V(!1),document.removeEventListener("pointermove",fe),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",fe),document.addEventListener("pointerup",ce,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",fe),document.removeEventListener("pointerup",ce,{capture:!0})}}},[R,V,$]),b.useEffect(()=>{const Q=()=>V(!1);return window.addEventListener("blur",Q),window.addEventListener("resize",Q),()=>{window.removeEventListener("blur",Q),window.removeEventListener("resize",Q)}},[V]);const[I,Y]=NB(Q=>{const fe=O().filter(Me=>!Me.disabled),ce=fe.find(Me=>Me.ref.current===document.activeElement),Ee=MB(fe,Q,ce);Ee&&setTimeout(()=>Ee.ref.current.focus())}),G=b.useCallback((Q,fe,ce)=>{const Ee=!P.current&&!ce;(k.value!==void 0&&k.value===fe||Ee)&&(U(Q),Ee&&(P.current=!0))},[k.value]),j=b.useCallback(()=>R==null?void 0:R.focus(),[R]),ee=b.useCallback((Q,fe,ce)=>{const Ee=!P.current&&!ce;(k.value!==void 0&&k.value===fe||Ee)&&F(Q)},[k.value]),J=r==="popper"?L0:gB,te=J===L0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:E}:{};return g.jsx(pB,{scope:n,content:R,viewport:L,onViewportChange:T,itemRefCallback:G,selectedItem:D,onItemLeave:j,itemTextRefCallback:ee,focusSelectedItem:q,selectedItemText:W,position:r,isPositioned:M,searchRef:I,children:g.jsx(Bf,{as:Pre,allowPinchZoom:!0,children:g.jsx(zf,{asChild:!0,trapped:k.open,onMountAutoFocus:Q=>{Q.preventDefault()},onUnmountAutoFocus:St(i,Q=>{var fe;(fe=k.trigger)==null||fe.focus({preventScroll:!0}),Q.preventDefault()}),children:g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:Q=>Q.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(J,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:Q=>Q.preventDefault(),...x,...te,onPlaced:()=>z(!0),ref:H,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:St(x.onKeyDown,Q=>{const fe=Q.ctrlKey||Q.altKey||Q.metaKey;if(Q.key==="Tab"&&Q.preventDefault(),!fe&&Q.key.length===1&&Y(Q.key),["ArrowUp","ArrowDown","Home","End"].includes(Q.key)){let Ee=O().filter(Me=>!Me.disabled).map(Me=>Me.ref.current);if(["ArrowUp","End"].includes(Q.key)&&(Ee=Ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(Q.key)){const Me=Q.target,Ie=Ee.indexOf(Me);Ee=Ee.slice(Ie+1)}setTimeout(()=>N(Ee)),Q.preventDefault()}})})})})})})});mB.displayName=Ore;var Dre="SelectItemAlignedPosition",gB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=xl(dc,n),o=El(dc,n),[l,u]=b.useState(null),[d,h]=b.useState(null),p=Bn(t,H=>h(H)),y=Vv(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:E,selectedItemText:x,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&E&&x){const H=s.trigger.getBoundingClientRect(),D=d.getBoundingClientRect(),U=s.valueNode.getBoundingClientRect(),W=x.getBoundingClientRect();if(s.dir!=="rtl"){const Me=W.left-D.left,Ie=U.left-Me,Ye=H.left-Ie,xt=H.width+Ye,gn=Math.max(xt,D.width),ge=window.innerWidth-Ws,rt=FN(Ie,[Ws,Math.max(Ws,ge-gn)]);l.style.minWidth=xt+"px",l.style.left=rt+"px"}else{const Me=D.right-W.right,Ie=window.innerWidth-U.right-Me,Ye=window.innerWidth-H.right-Ie,xt=H.width+Ye,gn=Math.max(xt,D.width),ge=window.innerWidth-Ws,rt=FN(Ie,[Ws,Math.max(Ws,ge-gn)]);l.style.minWidth=xt+"px",l.style.right=rt+"px"}const F=y(),O=window.innerHeight-Ws*2,M=w.scrollHeight,z=window.getComputedStyle(d),P=parseInt(z.borderTopWidth,10),N=parseInt(z.paddingTop,10),q=parseInt(z.borderBottomWidth,10),V=parseInt(z.paddingBottom,10),$=P+N+M+V+q,I=Math.min(E.offsetHeight*5,$),Y=window.getComputedStyle(w),G=parseInt(Y.paddingTop,10),j=parseInt(Y.paddingBottom,10),ee=H.top+H.height/2-Ws,J=O-ee,te=E.offsetHeight/2,Q=E.offsetTop+te,fe=P+N+Q,ce=$-fe;if(fe<=ee){const Me=F.length>0&&E===F[F.length-1].ref.current;l.style.bottom="0px";const Ie=d.clientHeight-w.offsetTop-w.offsetHeight,Ye=Math.max(J,te+(Me?j:0)+Ie+q),xt=fe+Ye;l.style.height=xt+"px"}else{const Me=F.length>0&&E===F[0].ref.current;l.style.top="0px";const Ye=Math.max(ee,P+w.offsetTop+(Me?G:0)+te)+ce;l.style.height=Ye+"px",w.scrollTop=fe-ee+w.offsetTop}l.style.margin=`${Ws}px 0`,l.style.minHeight=I+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,E,x,s.dir,r]);Ci(()=>R(),[R]);const[A,L]=b.useState();Ci(()=>{d&&L(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(H=>{H&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return g.jsx(Ire,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:T,children:g.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:g.jsx(Jt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});gB.displayName=Dre;var Lre="SelectPopperPosition",L0=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Ws,...s}=e,o=Yv(n);return g.jsx(jv,{...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)"}})});L0.displayName=Lre;var[Ire,R1]=dd(dc,{}),I0="SelectViewport",vB=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=El(I0,n),o=R1(I0,n),l=Bn(t,s.onViewportChange),u=b.useRef(0);return g.jsxs(g.Fragment,{children:[g.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}),g.jsx(qv.Slot,{scope:n,children:g.jsx(Jt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:St(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const v=Math.abs(u.current-h.scrollTop);if(v>0){const _=window.innerHeight-Ws*2,w=parseFloat(p.style.minHeight),E=parseFloat(p.style.height),x=Math.max(w,E);if(x<_){const k=x+v,R=Math.min(_,k),A=k-R;p.style.height=R+"px",p.style.bottom==="0px"&&(h.scrollTop=A>0?A:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});vB.displayName=I0;var yB="SelectGroup",[zre,Bre]=dd(yB),jre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=vi();return g.jsx(zre,{scope:n,id:i,children:g.jsx(Jt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});jre.displayName=yB;var bB="SelectLabel",Fre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bre(bB,n);return g.jsx(Jt.div,{id:i.id,...r,ref:t})});Fre.displayName=bB;var Zg="SelectItem",[$re,_B]=dd(Zg),wB=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=xl(Zg,n),u=El(Zg,n),d=l.value===r,[h,p]=b.useState(s??""),[y,v]=b.useState(!1),_=Bn(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=vi(),E=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 g.jsx($re,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{p(R=>R||((k==null?void 0:k.textContent)??"").trim())},[]),children:g.jsx(qv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Jt.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:St(o.onFocus,()=>v(!0)),onBlur:St(o.onBlur,()=>v(!1)),onClick:St(o.onClick,()=>{E.current!=="mouse"&&x()}),onPointerUp:St(o.onPointerUp,()=>{E.current==="mouse"&&x()}),onPointerDown:St(o.onPointerDown,k=>{E.current=k.pointerType}),onPointerMove:St(o.onPointerMove,k=>{var R;E.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):E.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:St(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:St(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(Cre.includes(k.key)&&x(),k.key===" "&&k.preventDefault())})})})})});wB.displayName=Zg;var Bh="SelectItemText",SB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=xl(Bh,n),l=El(Bh,n),u=_B(Bh,n),d=Are(Bh,n),[h,p]=b.useState(null),y=Bn(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=h==null?void 0:h.textContent,_=b.useMemo(()=>g.jsx("option",{value:u.value,disabled:u.disabled,children:v},u.value),[u.disabled,u.value,v]),{onNativeOptionAdd:w,onNativeOptionRemove:E}=d;return Ci(()=>(w(_),()=>E(_)),[w,E,_]),g.jsxs(g.Fragment,{children:[g.jsx(Jt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?od.createPortal(s.children,o.valueNode):null]})});SB.displayName=Bh;var xB="SelectItemIndicator",EB=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return _B(xB,n).isSelected?g.jsx(Jt.span,{"aria-hidden":!0,...r,ref:t}):null});EB.displayName=xB;var z0="SelectScrollUpButton",CB=b.forwardRef((e,t)=>{const n=El(z0,e.__scopeSelect),r=R1(z0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ci(()=>{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?g.jsx(TB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});CB.displayName=z0;var B0="SelectScrollDownButton",kB=b.forwardRef((e,t)=>{const n=El(B0,e.__scopeSelect),r=R1(B0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ci(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,h=Math.ceil(u.scrollTop)<d;s(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?g.jsx(TB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});kB.displayName=B0;var TB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=El("SelectScrollButton",n),o=b.useRef(null),l=Vv(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ci(()=>{var h;const d=l().find(p=>p.ref.current===document.activeElement);(h=d==null?void 0:d.ref.current)==null||h.scrollIntoView({block:"nearest"})},[l]),g.jsx(Jt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:St(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:St(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:St(i.onPointerLeave,()=>{u()})})}),Hre="SelectSeparator",Ure=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Jt.div,{"aria-hidden":!0,...r,ref:t})});Ure.displayName=Hre;var j0="SelectArrow",Wre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Yv(n),s=xl(j0,n),o=El(j0,n);return s.open&&o.position==="popper"?g.jsx(Fv,{...i,...r,ref:t}):null});Wre.displayName=j0;var qre="SelectBubbleInput",RB=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=Bn(r,i),o=_ee(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&h){const p=new Event("change",{bubbles:!0});h.call(l,t),l.dispatchEvent(p)}},[o,t]),g.jsx(Jt.select,{...n,style:{...uI,...n.style},ref:s,defaultValue:t})});RB.displayName=qre;function AB(e){return e===""||e===void 0}function NB(e){const t=To(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 MB(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=Vre(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 Vre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Yre=oB,Kre=lB,Gre=uB,Xre=dB,Zre=hB,Qre=fB,Jre=vB,eie=wB,tie=SB,nie=EB,rie=CB,iie=kB,[Kv]=la("Tooltip",[wl]),Gv=wl(),OB="TooltipProvider",sie=700,F0="tooltip.open",[oie,A1]=Kv(OB),PB=e=>{const{__scopeTooltip:t,delayDuration:n=sie,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)},[]),g.jsx(oie,{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})};PB.displayName=OB;var yf="Tooltip",[aie,qf]=Kv(yf),DB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=A1(yf,e.__scopeTooltip),d=Gv(t),[h,p]=b.useState(null),y=vi(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,E=b.useRef(!1),[x,k]=ac({prop:r,defaultProp:i??!1,onChange:H=>{H?(u.onOpen(),document.dispatchEvent(new CustomEvent(F0))):u.onClose(),s==null||s(H)},caller:yf}),R=b.useMemo(()=>x?E.current?"delayed-open":"instant-open":"closed",[x]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,E.current=!1,k(!0)},[k]),L=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{E.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Bv,{...d,children:g.jsx(aie,{scope:t,contentId:y,open:x,stateAttribute:R,trigger:h,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?L():(window.clearTimeout(v.current),v.current=0)},[L,_]),onOpen:A,onClose:L,disableHoverableContent:_,children:n})})};DB.displayName=yf;var $0="TooltipTrigger",LB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=qf($0,n),s=A1($0,n),o=Gv(n),l=b.useRef(null),u=Bn(t,l,i.onTriggerChange),d=b.useRef(!1),h=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),g.jsx(Ff,{asChild:!0,...o,children:g.jsx(Jt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:St(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:St(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:St(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:St(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:St(e.onBlur,i.onClose),onClick:St(e.onClick,i.onClose)})})});LB.displayName=$0;var N1="TooltipPortal",[lie,cie]=Kv(N1,{forceMount:void 0}),IB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=qf(N1,t);return g.jsx(lie,{scope:t,forceMount:n,children:g.jsx(Is,{present:n||s.open,children:g.jsx(ld,{asChild:!0,container:i,children:r})})})};IB.displayName=N1;var Xu="TooltipContent",zB=b.forwardRef((e,t)=>{const n=cie(Xu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=qf(Xu,e.__scopeTooltip);return g.jsx(Is,{present:r||o.open,children:o.disableHoverableContent?g.jsx(BB,{side:i,...s,ref:t}):g.jsx(uie,{side:i,...s,ref:t})})}),uie=b.forwardRef((e,t)=>{const n=qf(Xu,e.__scopeTooltip),r=A1(Xu,e.__scopeTooltip),i=b.useRef(null),s=Bn(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=b.useCallback(()=>{l(null),p(!1)},[p]),v=b.useCallback((_,w)=>{const E=_.currentTarget,x={x:_.clientX,y:_.clientY},k=pie(x,E.getBoundingClientRect()),R=mie(x,k),A=gie(w.getBoundingClientRect()),L=yie([...R,...A]);l(L),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&h){const _=E=>v(E,h),w=E=>v(E,u);return u.addEventListener("pointerleave",_),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),h.removeEventListener("pointerleave",w)}}},[u,h,v,y]),b.useEffect(()=>{if(o){const _=w=>{const E=w.target,x={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(E))||(h==null?void 0:h.contains(E)),R=!vie(x,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,h,o,d,y]),g.jsx(BB,{...e,ref:s})}),[die,hie]=Kv(yf,{isInside:!1}),fie=VQ("TooltipContent"),BB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=qf(Xu,n),d=Gv(n),{onClose:h}=u;return b.useEffect(()=>(document.addEventListener(F0,h),()=>document.removeEventListener(F0,h)),[h]),b.useEffect(()=>{if(u.trigger){const p=y=>{const v=y.target;v!=null&&v.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(jv,{"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:[g.jsx(fie,{children:r}),g.jsx(die,{scope:n,isInside:!0,children:g.jsx(hI,{id:u.contentId,role:"tooltip",children:i||r})})]})})});zB.displayName=Xu;var jB="TooltipArrow",FB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Gv(n);return hie(jB,n).isInside?null:g.jsx(Fv,{...i,...r,ref:t})});FB.displayName=jB;function pie(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 mie(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 gie(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 vie(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,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function yie(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),bie(t)}function bie(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 _ie=PB,wie=DB,Sie=LB,xie=IB,Eie=zB,Cie=FB;function M1({...e}){return g.jsx(_re,{"data-slot":"popover",...e})}function O1({...e}){return g.jsx(wre,{"data-slot":"popover-trigger",...e})}function P1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(Sre,{children:g.jsx(xre,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("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 kie={"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 rc({variant:e,action:t}){const{heading:n,body:r}=kie[e];return e==="no-messages"?g.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:g.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):g.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:[g.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&g.jsx("div",{children:t})]})}const Tie={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Rie={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function $N({status:e,className:t}){return g.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Tie[e],t),role:"status","aria-label":Rie[e]})}function $B({layout:e,variant:t="default"}){const n=Oe(_=>_.proxies),r=Oe(_=>_.proxyListLoaded),i=Oe(_=>_.relayClientAuthIssue),s=Oe(_=>_.selectedProxyId),o=Oe(_=>_.proxySwitchTarget),l=Di(),u=Qs(),[d,h]=b.useState(!1);async function p(_,w){if(o)return;const E=Pt;if(!E){tt.error("请先连接开发机");return}const x=w??_,k=s!==null&&s!==_;Oe.getState().setProxySwitchTarget({proxyId:_,name:x});try{const R=await E.selectProxy(_);if(!R.success){tt.error(`无法连接 ${x}:${R.error??"未知错误"}`);return}k&&($t.getState().prepareForProxySwitch(x),ai.getState().prepareForProxySwitch()),gr("local",cn.proxyId,_),Oe.getState().setProxy(_,w??null),Oe.getState().setProxyOnline(!0),Oe.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestProxyInfo().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const L=ai.getState();L.setHomePath(A.homePath),L.setAgentCli(A.agentCli)}).catch(A=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",A)}),E.requestAgentStatuses().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const L=$t.getState();for(const T of A)L.setAgentStatus(T.sessionId,T.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),E.requestSessionHistory().then(A=>{Oe.getState().selectedProxyId===_&&$t.getState().setHistorySessions(A)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),h(!1),(e==="page"||l.pathname.startsWith("/chat/"))&&u("/sessions")}catch(R){const A=R instanceof Error?R.message:"未知错误";tt.error(`无法连接 ${x}:${A}`)}finally{Oe.getState().setProxySwitchTarget(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(rc,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(rc,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(rc,{variant:"no-proxy"}):g.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[g.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),g.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,E=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||E,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:We("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",w?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",E&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx($N,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),g.jsx(sl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===_.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})]}):g.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:[g.jsx(sl,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});const y=n.find(_=>_.proxyId===s),v=(y==null?void 0:y.name)??(y==null?void 0:y.proxyId)??"未选择开发机";return g.jsxs(M1,{open:d,onOpenChange:h,children:[g.jsx(O1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("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":`当前连接:${v}`,children:[t==="default"&&g.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),g.jsx("span",{className:We("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:v}),g.jsx(vl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(P1,{align:"start",className:"w-[260px] p-1",children:n.length===0?g.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):g.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,E=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||E,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:We("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",w?"bg-accent text-accent-foreground":"hover:bg-accent",E&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线",children:[g.jsx($N,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsx(sl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===_.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&s!==_.proxyId&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})})]})}const HN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,UN=YD,Aie=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return UN(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 h=n==null?void 0:n[d],p=s==null?void 0:s[d];if(h===null)return null;const y=HN(h)||HN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,h)=>{let[p,y]=h;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,h)=>{let{class:p,className:y,...v}=h;return Object.entries(v).every(_=>{let[w,E]=_;return Array.isArray(E)?E.includes({...s,...l}[w]):{...s,...l}[w]===E})?[...d,p,y]:d},[]);return UN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Nie=Aie("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?WQ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(Nie({variant:t,size:n,className:e})),...i})}function Mie({delayDuration:e=0,...t}){return g.jsx(_ie,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Vf({...e}){return g.jsx(wie,{"data-slot":"tooltip",...e})}function Yf({...e}){return g.jsx(Sie,{"data-slot":"tooltip-trigger",...e})}function Kf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(xie,{children:g.jsxs(Eie,{"data-slot":"tooltip-content",sideOffset:t,className:We("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&&g.jsx(Cie,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Xv({...e}){return g.jsx(l1,{"data-slot":"sheet",...e})}function Oie({...e}){return g.jsx(bee,{"data-slot":"sheet-trigger",...e})}function Pie({...e}){return g.jsx(c1,{"data-slot":"sheet-portal",...e})}function Die({className:e,...t}){return g.jsx(u1,{"data-slot":"sheet-overlay",className:We("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 Zv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return g.jsxs(Pie,{children:[g.jsx(Die,{className:t}),g.jsxs(d1,{"data-slot":"sheet-content",className:We("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&&g.jsxs(Pv,{"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:[g.jsx(bc,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function D1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function Qv({className:e,...t}){return g.jsx(FI,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Lie({className:e,...t}){return g.jsx($I,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}function L1({...e}){return g.jsx(tre,{"data-slot":"dropdown-menu",...e})}function I1({...e}){return g.jsx(nre,{"data-slot":"dropdown-menu-trigger",...e})}function z1({className:e,sideOffset:t=4,...n}){return g.jsx(rre,{children:g.jsx(ire,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("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 _o({className:e,inset:t,variant:n="default",...r}){return g.jsx(ore,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("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 Q_({className:e,children:t,checked:n,...r}){return g.jsxs(are,{"data-slot":"dropdown-menu-checkbox-item",className:We("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:[g.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:g.jsx(lre,{children:g.jsx(ra,{className:"size-4"})})}),t]})}function Fm({className:e,inset:t,...n}){return g.jsx(sre,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function J_({className:e,...t}){return g.jsx(cre,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}const Iie={claude:"Claude Code",codex:"Codex"},WN=["claude","codex"];function Jv(e){return Iie[e]}function HB(e,t){return WN.indexOf(e)-WN.indexOf(t)}function H0(e){return e.provider??"claude"}const U0=60*1e3,W0=60*U0,zie=24*W0;function UB(e,t=Date.now()){const n=t-e;if(n<U0)return"刚刚";if(n<W0)return`${Math.floor(n/U0)} 分钟前`;if(n<zie)return`${Math.floor(n/W0)} 小时前`;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 qN={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 q0(e){return e.kind!=="terminal"?qN[e.state]:e.state==="terminated"?qN.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 Bie({session:e}){const t=q0(e);return g.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function jie({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Px:Lx;return g.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:g.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Fie({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Tv(e.name),d=Jx(e),h=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?UB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:We("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&&g.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),g.jsxs("button",{type:"button",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:[g.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[g.jsx(Bie,{session:e}),g.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&g.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&g.jsx(jie,{mode:e.mode}),e.mode&&g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Jv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:We("shrink-0",q0(e).text),children:q0(e).label}),y&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),g.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&g.jsxs(L1,{children:[g.jsx(I1,{asChild:!0,children:g.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:g.jsx(E9,{"aria-hidden":"true"})})}),g.jsxs(z1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(_o,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(_o,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function Ec({...e}){return g.jsx(l1,{"data-slot":"dialog",...e})}function $ie({...e}){return g.jsx(c1,{"data-slot":"dialog-portal",...e})}function Hie({...e}){return g.jsx(Pv,{"data-slot":"dialog-close",...e})}function Uie({className:e,...t}){return g.jsx(u1,{"data-slot":"dialog-overlay",className:We("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 Cc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs($ie,{"data-slot":"dialog-portal",children:[g.jsx(Uie,{}),g.jsxs(d1,{"data-slot":"dialog-content",className:We("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&&g.jsxs(Pv,{"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:[g.jsx(bc,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function kc({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Zu({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&g.jsx(Pv,{asChild:!0,children:g.jsx(Ct,{variant:"outline",children:"Close"})})]})}function hl({className:e,...t}){return g.jsx(FI,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function hc({className:e,...t}){return g.jsx($I,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function fl(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 Wie({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(qie,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:UB(e.updatedAt,t)}),u=g.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return g.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:g.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:We("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,g.jsx(X8,{className:We("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 qie({title:e,modeTag:t}){return g.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&g.jsx(Vie,{mode:t})]})}function Vie({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Px:Lx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:g.jsx(n,{className:"size-3","aria-hidden":"true"})})}function WB({providerLabel:e}){return g.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:g.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[g.jsx(O7,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),g.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Yie({now:e}){const t=$t(F=>F.historySessions),[n,r]=b.useState(null),[i,s]=b.useState(null),[o,l]=b.useState("json"),[u,d]=b.useState("default"),[h,p]=b.useState(!1),[y,v]=b.useState(!1),[_,w]=b.useState(new Set),[E,x]=b.useState(new Set),k=Qs(),R=b.useMemo(()=>{const F=new Map;for(const O of t){const M=H0(O);let z=F.get(M);z||(z=new Map,F.set(M,z));const P=qB(O.projectDir),N=z.get(P);N?N.sessions.push(O):z.set(P,{dir:P,sessions:[O]})}return Array.from(F.entries()).sort(([O],[M])=>HB(O,M)).map(([O,M])=>({provider:O,sessions:Array.from(M.values()).flatMap(z=>z.sessions),projects:Array.from(M.values()).map(z=>({dir:z.dir,shortDir:Tv(z.dir),sessions:z.sessions}))}))},[t]);function A(F){s(F),l(Kie(F)),d("default")}async function L(F,O,M){if(n)return;const z=Pt;if(!z){tt.error("请先连接开发机");return}r(F.id);const P=H0(F);try{const N=await z.createSession({cwd:F.projectDir,mode:O,provider:P,resumeSessionId:F.id,...M?{permissionMode:M}:{}});if(N.error||!N.sessionId){tt.error(`恢复失败:${N.error??"未知错误"}`);return}const q={sessionId:N.sessionId,state:"idle",mode:N.mode??O,provider:N.provider??"claude"};$t.getState().addSession(q),k(`/chat/${N.sessionId}?mode=${N.mode??O}`),s(null)}catch(N){tt.error(`恢复失败:${N instanceof Error?N.message:String(N)}`)}finally{r(null)}}function T(){const F=Pt;!F||h||(p(!0),F.requestSessionHistory().then(O=>$t.getState().setHistorySessions(O)).catch(O=>{tt.error(O instanceof Error?O.message:String(O))}).finally(()=>{p(!1)}))}function H(F,O){const M=VN(F,O);x(z=>{const P=new Set(z);return P.has(M)?P.delete(M):P.add(M),P})}function D(F){w(O=>{const M=new Set(O);return M.has(F)?M.delete(F):M.add(F),M})}const U=t.length>0,W=i?VB():[];return g.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[g.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[g.jsxs("button",{type:"button",onClick:()=>U&&v(F=>!F),disabled:!U,"aria-expanded":U?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:We("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:[g.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",U?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),U?g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:T,disabled:h,"data-slot":"history-refresh",children:g.jsx(Dx,{className:We("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!U&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),U&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(F=>{const O=_.has(F.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>D(F.provider),"aria-expanded":!O,"data-slot":"history-provider-header","data-expanded":!O,className:We("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:[g.jsx("span",{className:"font-mono",children:Jv(F.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:F.sessions.length}),g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!O&&"rotate-90"),"aria-hidden":"true"})]}),!O&&g.jsx("ul",{role:"list",className:"flex flex-col",children:F.projects.map(M=>{const z=VN(F.provider,M.dir),P=E.has(z);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>H(F.provider,M.dir),"aria-expanded":P,"data-slot":"history-group-header","data-expanded":P,className:We("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:[g.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),g.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",P&&"rotate-90"),"aria-hidden":"true"})]}),P&&g.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(N=>g.jsx(Wie,{session:N,now:e,disabled:n!==null,loading:n===N.id,onClick:()=>A(N),modeTag:N.preferredMode},N.id))})]},z)})})]},F.provider)})}),g.jsx(Gie,{session:i,open:i!==null,modes:W,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:F=>{F||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&L(i,o,u)}})]})}function VN(e,t){return`${e}:${qB(t)}`}function qB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function VB(){return["json","pty"]}function Kie(e){const t=VB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Gie({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=b.useState(!1),y=i==="bypassPermissions",v=fl("(min-width: 768px)");b.useEffect(()=>{t||p(!1)},[t]);const _=h?g.jsx(WB,{providerLabel:e?Jv(H0(e)):"Agent"}):g.jsxs("div",{className:"grid min-w-0 gap-4",children:[g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&g.jsx(YN,{checked:r==="json",label:"聊天",icon:g.jsx(Px,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(YN,{checked:r==="pty",label:"终端",icon:g.jsx(Lx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[g.jsx(ew,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(ew,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(ew,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(Ct,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(Ct,{type:"button",variant:h?"destructive":"default",disabled:s,onClick:()=>{if(y&&!h){p(!0);return}d()},"data-slot":h?"bypass-permission-confirm":void 0,children:s?"恢复中...":h?"确认":"恢复"})]});return v?g.jsx(Ec,{open:t,onOpenChange:o,children:g.jsxs(Cc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(kc,{className:"min-w-0",children:[g.jsx(hl,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(hc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),_,g.jsx(Zu,{children:w})]})}):g.jsx(Xv,{open:t,onOpenChange:o,children:g.jsxs(Zv,{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:[g.jsxs(D1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Qv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(Lie,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),g.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:_}),g.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:g.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function YN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:We("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,g.jsx("span",{className:"min-w-0 text-center",children:t}),g.jsx(ra,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function ew({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:We("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:[g.jsx("span",{className:We("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&&g.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:We("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),g.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&g.jsx(ra,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Xie({...e}){return g.jsx(Yre,{"data-slot":"select",...e})}function Zie({...e}){return g.jsx(Gre,{"data-slot":"select-value",...e})}function Qie({className:e,size:t="default",children:n,...r}){return g.jsxs(Kre,{"data-slot":"select-trigger","data-size":t,className:We("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,g.jsx(Xre,{asChild:!0,children:g.jsx(vl,{className:"size-4 opacity-50"})})]})}function Jie({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(Zre,{children:g.jsxs(Qre,{"data-slot":"select-content",className:We("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:[g.jsx(tse,{}),g.jsx(Jre,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),g.jsx(nse,{})]})})}function ese({className:e,children:t,...n}){return g.jsxs(eie,{"data-slot":"select-item",className:We("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:[g.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(nie,{children:g.jsx(ra,{className:"size-4"})})}),g.jsx(tie,{children:t})]})}function tse({className:e,...t}){return g.jsx(rie,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Mx,{className:"size-4"})})}function nse({className:e,...t}){return g.jsx(iie,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(vl,{className:"size-4"})})}function B1(e){return!e||e.endsWith("/")?e:`${e}/`}function rse(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function ise(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function sse(e,t,n){var o;if(t==="insert")return{currentPath:ise(e)||"./",query:rse(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:B1(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 ose(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function ase(e,t){return`${B1(e)}${t.name}${t.isDir?"/":""}`}function KN(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 YB=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ai($=>$.tree),h=ai($=>$.cwd),p=ai($=>$.homePath),y=i==="insert"?h:p||h,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>sse(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,E=b.useMemo(()=>ose(y,w),[y,w]),x=_.query,k=b.useRef(new Set),[R,A]=b.useState(!1),[L,T]=b.useState(""),[H,D]=b.useState(!1);b.useEffect(()=>{if(!E||d.has(E)||k.current.has(E))return;const $=Pt;if(!$)return;let I=!1;return k.current.add(E),$.requestDirectoryList(E).then(Y=>{I||ai.getState().setDirEntries(Y.path,Y.entries)}).catch(()=>{I||ai.getState().setDirEntries(E,[])}).finally(()=>{k.current.delete(E)}),()=>{I=!0}},[E,d]);const U=!d.has(E),W=b.useMemo(()=>{let $=d.get(E)??[];return o&&($=$.filter(I=>I.isDir)),x&&($=$.filter(I=>I.name.toLowerCase().includes(x))),$},[d,E,x,o]),[F,O]=b.useState(0);b.useEffect(()=>O(0),[w,x]),b.useEffect(()=>{A(!1),T("")},[E]),b.useEffect(()=>{F>=W.length&&W.length>0&&O(W.length-1)},[W.length,F]);const M=b.useRef(null),z=b.useRef(!1);b.useEffect(()=>{var I;if(!z.current)return;z.current=!1;const $=(I=M.current)==null?void 0:I.querySelector(`[data-entry-index="${F}"]`);$==null||$.scrollIntoView({block:"nearest"})},[F]);const P=b.useCallback($=>{const I=ase(w,$);return i==="insert"?I.replace(/^\.\//,""):I},[w,i]);async function N(){const $=KN(E,L);if(!(!$||!r)){D(!0);try{const I=await r($);if(!I)return;T(""),A(!1),n(B1(I))}finally{D(!1)}}}b.useImperativeHandle(u,()=>({handleKey($){return W.length===0?!1:$.key==="ArrowDown"?(z.current=!0,O(I=>Math.min(W.length-1,I+1)),!0):$.key==="ArrowUp"?(z.current=!0,O(I=>Math.max(0,I-1)),!0):$.key==="Enter"&&!$.nativeEvent.isComposing?(n(P(W[F])),!0):!1}}),[W,F,P,n]);const q=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",V=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 g.jsxs("div",{className:q,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?g.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?g.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:!E||H,onClick:()=>A($=>!$),children:"新建目录"}):null]}),R?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:L,onChange:$=>T($.target.value),onKeyDown:$=>{$.key==="Enter"&&!$.nativeEvent.isComposing&&($.preventDefault(),N()),$.key==="Escape"&&(A(!1),T(""))},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}),g.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:!KN(E,L)||H,onClick:()=>void N(),children:H?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:V,children:W.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:U?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:W.map(($,I)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(P($)),onMouseEnter:()=>O(I),className:We("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",I===F&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",$.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":$.isDir?"dir":"file","data-entry-index":I,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[$.name,$.isDir?"/":""]})})},$.name))})})]})}),GN="工作目录不存在或不可访问:",lse=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],KB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function cse(e,t){return t!==ei.PATH_NOT_FOUND||!e.startsWith(GN)?null:e.slice(GN.length).trim()||null}function Qg(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function use(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function dse(e,t){return e!=="codex"||KB.some(n=>n.value===t)?t:"default"}async function hse({relay:e,agentCli:t,form:n,timeoutMs:r=Xx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Qg(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?`${na[n.provider]} 不可用:${p}`:`${na[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=cse(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,v=((h=p.name)==null?void 0:h.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 fse({relay:e,timeoutMs:t=Xx}){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 pse({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Qg("claude",e),y=Qg("codex",e),v=e==null?void 0:e[t];return g.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[g.jsxs("div",{className:"flex items-center justify-between",children:[g.jsx("span",{className:"text-sm",children:"Agent CLI"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsx(XN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(XN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),g.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?g.jsx(mse,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(gse,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function XN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Vf,{children:[g.jsx(Yf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:We("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:[g.jsx("span",{className:"text-sm font-medium",children:na[e]}),g.jsx("span",{className:We("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(Kf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:use(e,n)})})]})}function mse({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[g.jsxs("label",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:"sr-only",children:"CLI 路径"}),g.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),o()),l.key==="Escape"&&(l.preventDefault(),s())},placeholder:e==="claude"?"/path/to/claude":"/path/to/codex",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"}),g.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>g.jsx("option",{value:l},l))})]}),g.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[g.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:"取消"}),g.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 gse({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[g.jsx("p",{className:We("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)??"等待检测结果"}),g.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:"指定路径"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),g.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:g.jsx(a7,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:We("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 jh({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[h,p]=b.useState("default"),[y,v]=b.useState(!1),[_,w]=b.useState(!1),[E,x]=b.useState(null),[k,R]=b.useState(!1),[A,L]=b.useState(null),[T,H]=b.useState(""),[D,U]=b.useState(!1),W=b.useRef(null),F=b.useRef(e);F.current=e;const O=Qs(),M=ai(Ee=>Ee.homePath),z=ai(Ee=>Ee.agentCli),P=fl("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&z)return;const Ee=Pt==null?void 0:Pt.requestProxyInfo();Ee&&Ee.then(Me=>{const Ie=ai.getState();Ie.setHomePath(Me.homePath),Ie.setAgentCli(Me.agentCli)}).catch(Me=>{console.error("[create-session-dialog] requestProxyInfo failed",Me)})},[e,M,z]),b.useEffect(()=>{if(!k)return;function Ee(Me){var Ye;const Ie=Me.target;Ie instanceof Node&&((Ye=W.current)!=null&&Ye.contains(Ie))||window.setTimeout(()=>R(!1),0)}return document.addEventListener("pointerdown",Ee,!0),()=>document.removeEventListener("pointerdown",Ee,!0)},[k]);function N(){r(""),s(""),R(!1),l("claude"),d("pty"),p("default"),v(!1),x(null),L(null),H(""),U(!1)}function q(){if(h==="bypassPermissions"){v(!0);return}j()}async function V(){await j(),F.current&&v(!1)}const $=o==="codex"?KB:lse,I=Qg(o,z),Y=_||D||I.disabled;function G(Ee){const Me=dse(Ee,h);Me!==h&&p(Me)}async function j(Ee){x(null),w(!0);try{const Me=await hse({relay:Pt,agentCli:z,form:{cwd:Ee??i,name:n,provider:o,permissionMode:h,mode:u}});if(Me.type==="success"){if($t.getState().addSession(Me.session),!F.current)return;t(!1),N(),O(Me.route);return}if(Me.type==="missing_cwd"&&x(Me.path),tt.error(Me.message),Me.type==="validation_error"||Me.type==="relay_missing")return}finally{w(!1)}}async function ee(Ee){const Me=Pt;if(!Me)return tt.error("请先连接开发机"),null;try{const Ie=await Me.createDirectory(Ee);return Ie.success?(s(Ie.path),x(null),tt.success("目录已创建"),Ie.path):(tt.error(`目录创建失败:${Ie.error??"未知错误"}`),null)}catch(Ie){return tt.error(Ie instanceof Error?Ie.message:String(Ie)),null}}function J(Ee){var Ie;const Me=z==null?void 0:z[Ee];L(Ee),H((Me==null?void 0:Me.command)??((Ie=Me==null?void 0:Me.suggestions)==null?void 0:Ie[0])??"")}async function te(){if(!A)return;const Ee=T.trim();if(!Ee){tt.error("请输入 Agent CLI 路径");return}const Me=Pt;if(!Me){tt.error("请先连接开发机");return}U(!0);try{const Ie=await Me.updateAgentCliPath(A,Ee);if(Ie.error||!Ie.agentCli){tt.error(`路径保存失败:${Ie.error??"未知错误"}`);return}ai.getState().setAgentCli(Ie.agentCli),tt.success(`${na[A]} 路径已保存`),L(null),H("")}catch(Ie){tt.error(Ie instanceof Error?Ie.message:String(Ie))}finally{U(!1)}}function Q(Ee){d(Ee),G(o)}function fe(Ee){var Ie;const Me=Ee.relatedTarget;Me instanceof Node&&((Ie=W.current)!=null&&Ie.contains(Me))||window.setTimeout(()=>R(!1),0)}const ce=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(WB,{providerLabel:na[o]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),g.jsx(Ct,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void V(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):g.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Ee=>{Ee.preventDefault(),q()},children:[g.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[g.jsx("span",{className:"text-sm",children:"名称(可选)"}),g.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Ee=>r(Ee.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:"自动生成"})]}),g.jsxs("div",{ref:W,className:"relative flex min-w-0 flex-col gap-2",onBlur:fe,children:[g.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),g.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:()=>R(!0),onChange:Ee=>{s(Ee.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?g.jsx(YB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ee,onSelect:Ee=>{s(Ee),x(null),R(!0)}}):null]}),E?g.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[g.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),g.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:E})]}):null,g.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"交互方式"}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>Q("pty"),className:We("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:[g.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),g.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>Q("json"),className:We("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:[g.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),g.jsx(pse,{agentCli:z,provider:o,isDesktop:P,editingCliProvider:A,cliPathInput:T,savingCliPath:D,onProviderChange:Ee=>{l(Ee),G(Ee)},onOpenCliPathEditor:J,onCliPathInputChange:H,onCancelCliPathEditor:()=>{L(null),H("")},onSaveCliPath:()=>void te()}),g.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"权限模式"}),g.jsxs(Xie,{value:h,onValueChange:Ee=>p(Ee),children:[g.jsx(Qie,{className:"w-full",children:g.jsx(Zie,{})}),g.jsx(Jie,{children:$.map(Ee=>g.jsx(ese,{value:Ee.value,children:Ee.label},Ee.value))})]})]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),g.jsx(Ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return P?g.jsx(Ec,{open:e,onOpenChange:t,children:g.jsxs(Cc,{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:[g.jsx(kc,{children:g.jsx(hl,{children:y?"跳过全部审批?":"新建会话"})}),ce]})}):g.jsx(Xv,{open:e,onOpenChange:t,children:g.jsxs(Zv,{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:[g.jsx(D1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Qv,{children:y?"跳过全部审批?":"新建会话"})}),ce]})})}function Fh({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),[h,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 g.jsx(Ec,{open:e,onOpenChange:r,children:g.jsx(Cc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:g.jsxs("form",{className:"grid gap-4",onSubmit:v=>void y(v),children:[g.jsxs(kc,{children:[g.jsx(hl,{children:"重命名会话"}),g.jsx(hc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),g.jsxs("div",{className:"grid gap-2",children:[g.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),g.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:We("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:h,onChange:v=>{l(v.target.value),u&&d(null)}}),u?g.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(Ct,{type:"submit",disabled:h,children:"保存"})]})]})})})}function vse(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function yse(e){return(e==null?void 0:e.kind)==="terminal"}function bse(e){return vse(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:yse(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function $m({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=bse(t);function s(){t&&(r(t),n(!1))}return g.jsx(Ec,{open:e,onOpenChange:n,children:g.jsxs(Cc,{"data-slot":"session-termination-dialog",children:[g.jsxs(kc,{children:[g.jsx(hl,{children:i.title}),g.jsx(hc,{children:i.description})]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(Ct,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function GB(e){var t,n,r,i,s,o,l,u,d,h,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"||((h=e.agentStatus)==null?void 0:h.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function _se(e){if(e.session.state==="error")return"error";const t=GB(e);return t==="disconnected"?e.session.state:t}function XB({layout:e}){const t=$t(ee=>ee.sessions),n=$t(ee=>ee.sessionListLoaded),r=$t(ee=>ee.agentStatusBySessionId),i=$t(ee=>ee.ptyStateBySessionId),s=$t(ee=>ee.renameSession),o=Xt(ee=>ee.bySessionId),l=kU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Oe(ee=>!!ee.selectedProxyId),h=Oe(ee=>ee.proxyListLoaded),p=Oe(ee=>ee.proxySwitchTarget),y=$t(ee=>ee.loadingProxyName),v=p!==null||!h||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",E=Qs(),[x,k]=b.useState(!1),[R,A]=b.useState(!1),[L,T]=b.useState(null),[H,D]=b.useState(null),{creatingTerminal:U,createTerminal:W}=ZB(),[F,O]=b.useState(new Set),[M,z]=b.useState(()=>Date.now());b.useEffect(()=>{const ee=setInterval(()=>z(Date.now()),6e4);return()=>clearInterval(ee)},[]);function P(ee,J){E(`/chat/${ee}?mode=${J??"json"}`,{replace:!1})}function N(ee){const J=ee.sessionId,te=Pt;if(!te){tt.error("请先连接开发机");return}te.sendControl({type:"session_terminate",sessionId:J}),$t.getState().removeSession(J),Xt.getState().clearSession(J),J===u&&E("/sessions"),(ee==null?void 0:ee.mode)==="pty"&&ee.ptyOwner==="local-terminal"?tt.info("已断开页面连接,本地终端仍在运行"):tt.info("正在终止会话",{duration:1500})}async function q(ee,J){const te=Pt;if(!te)throw new Error("请先连接开发机");const Q=await te.renameSession(ee,J);if(!Q.success)throw new Error(Q.error??"重命名失败");s(ee,Q.name??J),tt.success("已重命名会话")}function V(ee){O(J=>{const te=new Set(J);return te.has(ee)?te.delete(ee):te.add(ee),te})}function $(ee){var Q;const J=ee.mode==="json"&&(((Q=o[ee.sessionId])==null?void 0:Q.pendingApprovals.some(fe=>fe.status==="pending"))??!1),te=_se({session:ee,agentStatus:r[ee.sessionId],ptyState:i[ee.sessionId],hasPendingApproval:J});return te===ee.state?ee:{...ee,state:te}}const I=t.length>0;if(e==="sidebar"&&(v||!d))return g.jsxs(g.Fragment,{children:[g.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:"请先连接开发机"}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]});if(e==="page"&&v)return g.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:[g.jsx(sl,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsx("div",{className:"flex-1",children:g.jsx(rc,{variant:"no-proxy"})}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]});const Y=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",I?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),G=I?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:wse(t).map(ee=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>V(ee.provider),"aria-expanded":!F.has(ee.provider),className:We("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:[g.jsx("span",{className:"font-mono",children:Sse(ee.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:ee.sessions.length}),g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(ee.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(ee.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:ee.sessions.map(J=>g.jsx(Fie,{session:$(J),selected:J.sessionId===u,now:M,onClick:()=>P(J.sessionId,J.mode),onRename:()=>T(J),onTerminate:()=>D(J)},J.sessionId))})]},ee.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),j=g.jsx(Yie,{now:M});return e==="page"?g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,G,j]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(Ct,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[g.jsx(ID,{"aria-hidden":"true"}),"新建"]})}),g.jsx(Ese,{open:R,creatingTerminal:U,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>void W(()=>A(!1))}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,G,j]}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]})}function wse(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])=>xse(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Sse(e){return e==="terminal"?"终端":Jv(e)}function xse(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:HB(e,t)}function ZB(){const e=Qs(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await fse({relay:Pt});if(s.type!=="success"){tt.error(s.message);return}$t.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function ZN({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Oe(x=>!!x.selectedProxyId),l=Oe(x=>x.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:h}=ZB();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,h()}function _(x){x.preventDefault(),p()}const w=g.jsxs(Ct,{variant:"outline","data-slot":"create-session-trigger",className:We(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:[g.jsx(ID,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),E=u?g.jsxs(L1,{children:[g.jsx(I1,{asChild:!0,children:w}),g.jsxs(z1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:x=>{s.current&&(s.current=!1,x.preventDefault())},children:[g.jsxs(_o,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[g.jsx(LD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(_o,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[g.jsx(uf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return g.jsxs(g.Fragment,{children:[u?E:g.jsxs(Vf,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[g.jsx(Yf,{asChild:!0,children:E}),g.jsx(Kf,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),g.jsx(jh,{open:t,onOpenChange:n})]})}function Ese({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=b.useRef(!1);function o(l){s.current=!0,l()}return g.jsx(Xv,{open:e,onOpenChange:n,children:g.jsxs(Zv,{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:[g.jsx(D1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Qv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.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:[g.jsx(LD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.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:[g.jsx(uf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Cse="0.5.30",kse={version:Cse},Tse={playback:"playback",capture:"play-and-record"};function Rse(){return typeof navigator>"u"?null:navigator.audioSession??null}function Ase(){return{setMode:()=>{},release:()=>{}}}class Nse{constructor(t=Rse){bt(this,"leases",new Map);bt(this,"session",null);bt(this,"baselineType",null);bt(this,"nextLeaseId",1);bt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Ase();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(Tse[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 j1=new Nse,V0=64,QN=-60,QB=32;function JN(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-QN)/-QN));return e<0?-r:r}function eM(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,h=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),h=Math.max(h,y)}s.push({min:d,max:h})}return s}function Mse(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 Ose(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 JB{constructor(t,n=24e3,r={}){bt(this,"nextStartTime",0);bt(this,"activityEndToken",0);bt(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=Mse(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*QB/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,h=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),y=Ose(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,E;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(E=(w=this.options).onPlaybackChunk)==null||E.call(w,p)},h)}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 tw={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},tM="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",Pse=800,nM=300,Dse=1600;function Y0(e,t){return e.filter(n=>!n.model||n.model===t)}function rM({label:e,children:t,help:n}){return g.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:[g.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.jsx("div",{className:"mt-2 min-w-0",children:t}),n?g.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Hm({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),h=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!e3(h).detail;return g.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:[g.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.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:[g.jsx(iM,{label:h,muted:!d&&!t}),g.jsx(vl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?g.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 g.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:[g.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?g.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(iM,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function iM({label:e,muted:t=!1}){const n=e3(e);return g.jsxs("span",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?g.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Lse({scrollRef:e}={}){const[t,n]=b.useState(tw),[r,i]=b.useState(String(tw.turnIdleSeconds)),[s,o]=b.useState(()=>Am()),[l,u]=b.useState(""),[d,h]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),E=b.useRef(null),x=b.useRef(null),k=b.useRef(null),R=b.useRef(null);b.useEffect(()=>{const te=Pt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let Q=!1;return _({kind:"loading"}),te.requestVoiceConfig().then(fe=>{if(!Q){if(fe.error||!fe.config){_({kind:"error",message:fe.error??"读取语音设置失败"});return}n(fe.config),i(String(fe.config.turnIdleSeconds)),u(""),h(!1),y(!0),_({kind:"idle"})}}).catch(fe=>{Q||_({kind:"error",message:fe instanceof Error?fe.message:"读取语音设置失败"})}),()=>{Q=!0}},[]),b.useEffect(()=>{const te=Pt;if(!te||!p)return;let Q=!1;return te.requestVoiceCapabilities({region:t.region}).then(fe=>{if(!Q){if(fe.error||!fe.capabilities){o(Am());return}o(fe.capabilities)}}).catch(()=>{Q||o(Am())}),()=>{Q=!0}},[t.region,p]),b.useEffect(()=>()=>{G(),j()},[]);const A=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]),L=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",T=b.useMemo(()=>Y0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),D=T.some(te=>te.value===t.ttsVoice)?t.ttsVoice:"",U=T.length===0?"当前模型暂无可用音色":D?null:"请选择可用音色",W=b.useMemo(()=>jse(r),[r]),F=W?null:"请输入正整数秒数",O=U??F,M=L||!!O,z=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>aM(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),N=b.useMemo(()=>Fse(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),q=b.useMemo(()=>aM(T,D),[T,D]);function V(){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:W??tw.turnIdleSeconds}}async function $(){if(L)return;if(O){_({kind:"error",message:O});return}const te=Pt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}const Q=V();j(),_({kind:"saving"});const fe=performance.now();try{const ce=await te.updateVoiceConfig(Q),Ee=performance.now()-fe;if(Ee<nM&&await Bse(nM-Ee),!ce.success||ce.error||!ce.config){_({kind:"error",message:ce.error??"保存语音设置失败"});return}n(ce.config),i(String(ce.config.turnIdleSeconds)),u(""),h(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(Me=>Me.kind==="saved"?{kind:"idle"}:Me)},Dse),te.requestVoiceCapabilities({region:ce.config.region}).then(Me=>{Me.capabilities&&o(Me.capabilities)}).catch(()=>{o(Am())})}catch(ce){_({kind:"error",message:ce instanceof Error?ce.message:"保存语音设置失败"})}}async function I(){if(L)return;if(O){_({kind:"error",message:O});return}const te=Pt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let Q;try{Q=Y()}catch(fe){_({kind:"error",message:oM(fe)});return}_({kind:"testing"});try{const[fe]=await Promise.all([te.testVoiceConfig(V()),Q.ready]);if(!fe.success||fe.error){G(),_({kind:"error",message:fe.error??"语音配置测试失败"});return}const ce=await ee(fe,Q.context);_({kind:"playingTest",transcript:fe.transcript}),k.current=setTimeout(()=>{k.current=null,G(),_({kind:"testPassed",transcript:fe.transcript})},ce)}catch(fe){G(),_({kind:"error",message:oM(fe)})}}function Y(){G();const te=j1.acquire("playback");E.current=te;try{const Q=zse();return w.current=Q,{context:Q,ready:sM(Q)}}catch(Q){throw te.release(),E.current=null,Q}}function G(){var te,Q,fe;k.current&&(clearTimeout(k.current),k.current=null),(te=x.current)==null||te.stop(),x.current=null,(Q=w.current)==null||Q.close(),w.current=null,(fe=E.current)==null||fe.release(),E.current=null}function j(){R.current&&(clearTimeout(R.current),R.current=null)}async function ee(te,Q){if(!te.audioBase64)throw new Error("语音测试未返回可播放音频");if(te.audioEncoding&&te.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const fe=te.audioSampleRate??24e3,ce=Ise(te.audioBase64);if(ce.byteLength===0||ce.byteLength%2!==0)throw new Error("测试音频数据无效");await sM(Q);const Ee=new JB(Q,fe);x.current=Ee,Ee.enqueue(ce);const Me=Math.ceil(ce.byteLength/2/fe*1e3);return Math.max(Pse,Me)}function J(te){var Q;return((Q=Y0(s.ttsVoices,te)[0])==null?void 0:Q.value)??""}return g.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:te=>{te.preventDefault(),$()},children:[g.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:g.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:g.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[g.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),g.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),g.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"})]})}),g.jsx(rM,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:g.jsxs("div",{className:"flex min-w-0 gap-2",children:[g.jsxs("div",{className:"relative min-w-0 flex-1",children:[g.jsx(jD,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),g.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:te=>{u(te.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${tM} w-full pl-9`})]}),t.configured&&g.jsxs(Ct,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),h(!0)},children:[g.jsx(N7,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(Hm,{label:"地域",value:t.region,options:z,onChange:te=>n(Q=>({...Q,region:te==="intl"?"intl":"cn"}))}),g.jsx(Hm,{label:"语音识别模型",value:t.asrModel,options:P,onChange:te=>n(Q=>({...Q,asrModel:te}))}),g.jsx(Hm,{label:"语音合成模型",value:t.ttsModel,options:N,onChange:te=>n(Q=>({...Q,ttsModel:te,ttsVoice:J(te)}))}),g.jsx(Hm,{label:"语音音色",value:D,options:q,placeholder:T.length===0?"暂无可用音色":"请选择音色",onChange:te=>n(Q=>({...Q,ttsVoice:te})),help:U}),g.jsx(rM,{label:"结束停顿时间(秒)",help:F,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:te=>i(te.target.value),className:`${tM} w-full`})})]})})}),g.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[g.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),g.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[A?g.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:A}):null,g.jsxs(Ct,{type:"button",variant:"outline",disabled:M,onClick:()=>void I(),children:[g.jsx(HD,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(Ct,{type:"submit",disabled:M,children:[g.jsx(v7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Ise(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 zse(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function sM(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function oM(e){return e instanceof Error?e.message:"语音配置测试失败"}function Bse(e){return new Promise(t=>setTimeout(t,e))}function jse(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function aM(e,t){const n=e.map(r=>({value:r.value,label:t3(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Fse(e,t,n){const r=e.map(i=>{const s=Y0(t,i.value).length===0;return{value:i.value,label:`${t3(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function e3(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 t3(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 $se=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Hse=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],F1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function n3(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 Use(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Wse(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function qse(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function K0({open:e,onOpenChange:t}){const n=Oe(U=>U.relayUrl),r=Oe(U=>U.latencyMonitorEnabled),i=Oe(U=>U.setLatencyMonitorEnabled),s=Oe(U=>U.sessionIdleNotificationsEnabled),o=Oe(U=>U.setSessionIdleNotificationsEnabled),l=Oe(U=>U.inputModePreference),u=Oe(U=>U.setInputModePreference),d=Oe(U=>U.themePreference),h=Oe(U=>U.setThemePreference),p=Oe(U=>U.ptyScrollTraceEnabled),y=Oe(U=>U.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,E]=b.useState({kind:"idle"}),x=b.useRef(null),k=b.useRef(null),R=BQ(),A=b.useMemo(()=>kv().osName==="iPad",[]),L=b.useCallback(async U=>{if(!U){o(!1);return}const W=await fQ();if(W==="granted"){o(!0);return}if(W==="denied"){tt.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(W==="default"){tt.info("未授予通知权限,会话通知保持关闭");return}tt.error("当前浏览器不支持系统通知")},[o]),T=b.useCallback(async U=>{E({kind:"loading"});try{const W=await fetch(Use(n),{cache:"no-store",signal:U});if(!W.ok)throw new Error(`HTTP ${W.status}`);const F=await W.json();if(F.status!=="ok")throw new Error("状态异常");E({kind:"ready",version:F.version??"未知",uptime:F.uptime??0})}catch(W){if(W instanceof DOMException&&W.name==="AbortError")return;E({kind:"error",message:W instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const U=new AbortController;return T(U.signal),()=>U.abort()},[T,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const U=window.requestAnimationFrame(()=>{var W;(W=x.current)==null||W.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(U)},[e,v]);const H=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",D=w.kind==="ready"?`运行 ${n3(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(Ec,{open:e,onOpenChange:t,children:g.jsxs(Cc,{className:We("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:[g.jsx(kc,{className:We(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"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-start gap-2",children:[g.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:g.jsx(wv,{className:"size-4","aria-hidden":"true"})}),g.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[g.jsx(hl,{children:Wse(v)}),g.jsx(hc,{className:"max-w-[28rem] leading-5",children:qse(v)})]})]}),v==="voice"?g.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):g.jsxs(g.Fragment,{children:[g.jsx(hl,{children:"设置"}),g.jsx(hc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(Vse,{relayVersion:H,relayDetail:D,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(Kse,{saved:R}):v==="clients"?g.jsx(Jse,{}):v==="voice"?g.jsx(Lse,{scrollRef:k}):g.jsx(Yse,{relayTokenSaved:R,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:L,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function Vse({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:F1,"data-slot":"settings-dialog-body",children:[g.jsx(cM,{icon:g.jsx($D,{className:"size-4","aria-hidden":"true"}),label:"Web",value:kse.version,detail:"当前浏览器加载的版本"}),g.jsx(cM,{icon:g.jsx(UD,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Yse({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:h,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:v,onOpenClients:_,onOpenVersion:w}){return g.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:[g.jsxs(hu,{title:"服务",children:[g.jsx(Um,{icon:g.jsx(e9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx(Um,{icon:g.jsx(jD,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx(Um,{icon:g.jsx(z7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),g.jsx(hu,{title:"外观",children:g.jsx(lM,{icon:g.jsx(T7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:$se,onValueChange:n})}),g.jsx(hu,{title:"通知",children:g.jsx(rw,{icon:g.jsx(n9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(hu,{title:"交互",children:g.jsx(lM,{icon:g.jsx(FD,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Hse,onValueChange:i})}):null,g.jsxs(hu,{title:"高级诊断",children:[g.jsx(rw,{icon:g.jsx(uf,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(rw,{icon:g.jsx(PD,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(hu,{title:"关于",children:g.jsx(Um,{icon:g.jsx(UD,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function hu({title:e,children:t}){return g.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[g.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),g.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function lM({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return g.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,g.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 g.jsx("button",{type:"button",role:"radio","aria-checked":d,className:We("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 Kse({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{aI().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}if(!sI(h)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),tt.error(p);return}o(null),tt.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{oI(),l()};return g.jsxs("form",{className:F1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[g.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[g.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),g.jsx("input",{id:t,type:"password",value:r,onChange:h=>{i(h.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?g.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),g.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?g.jsx(Ct,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(Ct,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Gse(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Xse(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Gse(e)}function Zse(e){return VX(e)}function Qse(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return n3(t)}function nw({label:e,value:t,title:n}){return g.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[g.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),g.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function Jse(){const e=Oe(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]),h=b.useCallback(async()=>{const y=Pt;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(()=>{h()},[h]);const p=b.useCallback(async y=>{const v=Pt;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(E=>E.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:F1,"data-slot":"settings-dialog-body",children:[g.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),g.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Dx,{className:We("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?g.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?g.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 g.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:g.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[g.jsxs("div",{className:"min-w-0 space-y-1.5",children:[g.jsx("div",{className:"min-w-0",children:g.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Zse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(nw,{label:"已连接",value:Qse(y.connectedAt)}),y.proxyId?g.jsx(nw,{label:"连接到",value:Xse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(nw,{label:"来源 IP",value:y.remoteAddress}):null]})]}),v?g.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:"当前设备"}):g.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:[g.jsx(Y9,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function rw({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return g.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:[g.jsx("div",{className:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),g.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),g.jsx("span",{className:We("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:g.jsx("span",{className:We("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 Um({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return g.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:[g.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}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),g.jsx(Qh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function cM({icon:e,label:t,value:n,detail:r,muted:i=!1}){return g.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[g.jsx("div",{className:We("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}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[g.jsx("div",{className:"text-sm text-muted-foreground",children:t}),g.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const eoe="xterm-helper-textarea";function toe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(eoe)?!1:(e.blur(),!0)}function uM(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&&noe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function noe(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 roe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&toe()},[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 h=(n.current??u.clientY)-u.clientY;n.current=u.clientY,uM(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(uM(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function ioe({className:e}){const t=Oe(o=>o.sidebarCollapsed),n=Oe(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=roe();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("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:[g.jsx(hM,{collapsed:!0,onClick:n}),g.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),g.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[g.jsx(dM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(ZN,{compact:!0})]})]}),g.jsx(K0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("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:[g.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:g.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx(lL,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(hM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx($B,{layout:"dropdown",variant:"sidebarChrome"})})]})}),g.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:g.jsx("div",{className:"flex-1 min-h-0",children:g.jsx(XB,{layout:"sidebar"})})}),g.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:[g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(ZN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(dM,{onClick:()=>i(!0)})})]})]}),g.jsx(K0,{open:r,onOpenChange:i})]})}function dM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Vf,{delayDuration:500,children:[g.jsx(Yf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("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:[g.jsx(WD,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(Kf,{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 hM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?r7:t7;return g.jsxs(Vf,{delayDuration:500,children:[g.jsx(Yf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("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:g.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(Kf,{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 soe=1500,ooe=300,fM=70,pM=35;function r3({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 h=setInterval(()=>s(p=>!p),530);return()=>clearInterval(h)},[]),b.useEffect(()=>{let h;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)),h=setTimeout(y,fM)):(o.current="paused",h=setTimeout(y,soe))}else v==="paused"?(o.current="deleting",h=setTimeout(y,pM)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),h=setTimeout(y,pM)):(u.current+=1,o.current="waiting",h=setTimeout(y,ooe)):(o.current="typing",h=setTimeout(y,fM))};return h=setTimeout(y,500),()=>clearTimeout(h)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return g.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[g.jsx("span",{className:"text-green-500",children:"> "}),g.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),g.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),g.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const i3=["DEV Anywhere","/unlimited @anytime"];function aoe({subtitle:e,action:t}){return g.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:g.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[g.jsx(r3,{texts:i3,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),g.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?g.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const loe=3e3,coe=1e4,Wm=12,uoe=4,mM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},doe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function iw(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 fu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function $h(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function gM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function s3(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function hoe(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 foe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?$h(e.rttMs):"等待检测"}function poe(){const e=Ei("local",cn.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 vM(e){gr("local",cn.latencyMonitorPosition,JSON.stringify(e))}function moe(){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 sw(e,t){const n=moe(),r=Wm,i=Wm,s=Math.max(r,n.width-t.width-Wm),o=Math.max(i,n.height-t.height-Wm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function goe(){const e=Oe(T=>T.latencyMonitorEnabled),t=Oe(T=>T.connected),n=Oe(T=>T.proxyOnline),r=Oe(T=>T.selectedProxyId),[i,s]=b.useState(doe),[o,l]=b.useState(()=>poe()),u=b.useRef(!1),d=b.useRef(null),h=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,H)=>gM(H.state)-gM(T.state))[0]??{state:"idle"}).state,[i]),v=s3(y);async function _(){if(u.current)return;const T=Pt;if(!T||!t){const W=fu("Relay 服务器未连接");s({webRelay:W,relayProxy:W,webProxy:W});return}u.current=!0,s(W=>({webRelay:{...W.webRelay,state:"measuring"},relayProxy:n?{...W.relayProxy,state:"measuring"}:fu("未连接开发机"),webProxy:n?{...W.webProxy,state:"measuring"}:fu("未连接开发机")}));const[H,D,U]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:H.status==="fulfilled"?iw(H.value):fu(H.reason instanceof Error?H.reason.message:"测速失败"),relayProxy:D.status==="fulfilled"?iw(D.value):fu(D.reason instanceof Error?D.reason.message:"测速失败"),webProxy:U.status==="fulfilled"?iw(U.value):fu(U.reason instanceof Error?U.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,H=null;const D=async()=>{await _(),!T&&(H=setTimeout(D,document.hidden?coe:loe))};return D(),()=>{T=!0,u.current=!1,H&&clearTimeout(H)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const H=T.getBoundingClientRect(),D=sw(o,{width:H.width,height:H.height});D.x===o.x&&D.y===o.y||(l(D),vM(D))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,E=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(T){var D,U;if(T.button!==0)return;const H=T.currentTarget.getBoundingClientRect();h.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:H.left,originY:H.top,width:H.width,height:H.height,dragging:!1},(U=(D=T.currentTarget).setPointerCapture)==null||U.call(D,T.pointerId)}function k(T){const H=h.current;if(!H||H.pointerId!==T.pointerId)return;const D=T.clientX-H.startX,U=T.clientY-H.startY;if(!H.dragging&&Math.hypot(D,U)<uoe)return;H.dragging=!0,T.preventDefault();const W=sw({x:H.originX+D,y:H.originY+U},{width:H.width,height:H.height});l(W)}function R(T){var F,O;const H=h.current;if(!H||H.pointerId!==T.pointerId||(h.current=null,(O=(F=T.currentTarget).releasePointerCapture)==null||O.call(F,T.pointerId),!H.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const D=T.clientX-H.startX,U=T.clientY-H.startY,W=sw({x:H.originX+D,y:H.originY+U},{width:H.width,height:H.height});l(W),vM(W)}function A(T){var D,U;const H=h.current;!H||H.pointerId!==T.pointerId||(h.current=null,(U=(D=T.currentTarget).releasePointerCapture)==null||U.call(D,T.pointerId))}function L(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:We("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",hoe(v)),style:E,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${$h(i.webRelay.rttMs)},开发机 ${$h(w.rttMs)}`,onPointerDown:x,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:L,children:[g.jsx(PD,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),g.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",$h(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",$h(w.rttMs)]}),g.jsx(vl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(P1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),g.jsx(Ct,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:g.jsx(Dx,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(mM).map(T=>g.jsx(voe,{label:mM[T],measurement:i[T]},T))})]})]})}function voe({label:e,measurement:t}){const n=s3(t.state);return g.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:[g.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:We("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"}),g.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:foe(t)})]})]})}const o3="/__dev_anywhere_debug/browser-state-dumps",yoe=1500,boe=10,ow=80,$1=500,_oe=["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"],woe=["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 yM(){if(typeof window>"u")return"off";const e=p3("debugDump");return e==="auto"?"auto":e!==null||Noe("debugInput")?"manual":"off"}function Soe(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:koe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:bM(document.activeElement),selection:Toe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>bM(i)).filter(i=>!!i),root:a3(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(()=>_M(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:pu(()=>_M(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:pu(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function xoe(e="manual"){const t=Soe(e);return Eoe(t)}async function Eoe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Coe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:o3}}catch(r){const i=m3(r),s=Roe(e.createdAt);return Aoe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Coe(e){const t=await fetch(o3,{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 a3(e,t,n){if(n.count>=yoe||t>boe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=wM(e.textContent??"");return u?{kind:"text",text:ey(u,$1)}:{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,ow))u.nodeType===Node.TEXT_NODE&&!wM(u.textContent??"")||r.push(a3(u,t+1,n));s.length>ow&&(i=s.length-ow,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:f3(e),attrs:l3(e),rect:c3(e),scroll:u3(e),style:d3(e)},l=h3(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function bM(e){if(!(e instanceof HTMLElement))return null;const t=h3(e);return{path:f3(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:l3(e),rect:c3(e),scroll:u3(e),style:d3(e),...t?{value:t}:{}}}function koe(){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 l3(e){const t={};for(const n of _oe){const r=e.getAttribute(n);r!==null&&(t[n]=ey(r,500))}return t}function c3(e){const t=e.getBoundingClientRect();return{x:Ki(t.x),y:Ki(t.y),width:Ki(t.width),height:Ki(t.height),top:Ki(t.top),right:Ki(t.right),bottom:Ki(t.bottom),left:Ki(t.left)}}function u3(e){return{top:Ki(e.scrollTop),left:Ki(e.scrollLeft),height:Ki(e.scrollHeight),width:Ki(e.scrollWidth),clientHeight:Ki(e.clientHeight),clientWidth:Ki(e.clientWidth)}}function d3(e){const t=window.getComputedStyle(e),n={};for(const r of woe)n[r]=t.getPropertyValue(r);return n}function h3(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:ey(e.value,$1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Toe(){var e;try{return ey(((e=window.getSelection())==null?void 0:e.toString())??"",$1)}catch{return null}}function f3(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 Roe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Aoe(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 Noe(e){return p3(e)!==null}function p3(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 _M(e){return e?Jg(e.slice(-200)):null}function pu(e){try{return Jg(e())}catch(t){return{error:m3(t)}}}function Jg(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(Jg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Jg(r);return t}return String(e)}function wM(e){return e.replace(/\s+/g," ").trim()}function ey(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Ki(e){return Math.round(e*100)/100}function m3(e){return e instanceof Error?e.message:String(e)}const Moe=500,Ooe=1e3,Poe=60;function Doe(){const[e,t]=b.useState(()=>yM()),[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),h=b.useRef(null);b.useEffect(()=>{const _=()=>t(yM());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 xoe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&Loe(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,R;if(e!=="auto")return;const _=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=A=>{d.current>=Poe||(_(),h.current=window.setTimeout(()=>{h.current=null;const L=Date.now(),T=Ooe-(L-u.current);if(T>0){h.current=window.setTimeout(()=>w(A),T);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${A}`)},Moe))};w("initial");const E=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=A=>w(A.type);return E.forEach(A=>window.addEventListener(A,x,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",x),(R=window.visualViewport)==null||R.addEventListener("scroll",x),()=>{var A,L;_(),E.forEach(T=>window.removeEventListener(T,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(L=window.visualViewport)==null||L.removeEventListener("scroll",x)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=Ioe(i);return g.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?g.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,g.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?g.jsx(sl,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(P9,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function Loe(e){if(e.status==="saved"){tt.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){tt.info(`诊断已下载: ${e.filename}`);return}tt.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Ioe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function zoe(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 H1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:zoe(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 h=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&h.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const v=h.indexOf(y);v>=0&&v!==h.length-1&&(h.splice(v,1),h.push(y)),u(h);return}}}if(h.push(d),i&&s.set(d.event,d),h.length>r){const p=h.splice(0,h.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(h)},getAll:l}}function Tn(e){return Math.round(e*10)/10}function Ka(e){return e.length===0?"":`${Tn(Math.min(...e))}..${Tn(Math.max(...e))}`}function Ou(e){return[...new Set(e.filter(t=>t!==void 0).map(Tn))]}function g3(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 Boe="dev_anywhere_pty_input_latency_trace",SM=80,joe=1e4,Foe=new TextDecoder;let $oe=0;const Qu=new Map,Tc=H1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Boe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Hoe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Voe)}function Uoe(e,t){if(!Tc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++$oe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Goe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Qu.get(e)??[];return s.push(i),W1(s,r),Qu.set(e,s),Gf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function xM(e,t){if(!e||!Tc.isEnabled())return;const n=performance.now(),r=Yoe(e.sessionId,e.inputId);r&&(r.sentAt=n),Gf({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 Woe(e,t,n){if(!Tc.isEnabled())return;const r=performance.now(),i=U1(e,r),s=Qoe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Zoe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Gf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:q1(i,r),details:Joe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function qoe(e,t,n=1){if(!Tc.isEnabled())return;const r=performance.now(),i=U1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Gf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:q1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Koe(e,s))}function Voe(){const e=Tc.getAll(),t=e.slice(-200),n=[...Qu.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Tn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Tn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Tn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Tn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Tn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Tn(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?"":Tn(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(`
530
+ 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},vee="DialogDescriptionWarning",yee=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${jI(vee).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},l1=CI,bee=TI,c1=AI,u1=NI,d1=MI,FI=PI,$I=LI,Pv=zI;function _ee(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 wee(e){const[t,n]=b.useState(void 0);return Ci(()=>{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 See=["top","right","bottom","left"],ul=Math.min,cs=Math.max,qg=Math.round,jm=Math.floor,Eo=e=>({x:e,y:e}),xee={left:"right",right:"left",bottom:"top",top:"bottom"};function N0(e,t,n){return cs(e,ul(t,n))}function oa(e,t){return typeof e=="function"?e(t):e}function aa(e){return e.split("-")[0]}function cd(e){return e.split("-")[1]}function h1(e){return e==="x"?"y":"x"}function f1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function p1(e){return h1(So(e))}function Eee(e,t,n){n===void 0&&(n=!1);const r=cd(e),i=p1(e),s=f1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Vg(o)),[o,Vg(o)]}function Cee(e){const t=Vg(e);return[M0(e),t,M0(t)]}function M0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const RN=["left","right"],AN=["right","left"],kee=["top","bottom"],Tee=["bottom","top"];function Ree(e,t,n){switch(e){case"top":case"bottom":return n?t?AN:RN:t?RN:AN;case"left":case"right":return t?kee:Tee;default:return[]}}function Aee(e,t,n,r){const i=cd(e);let s=Ree(aa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(M0)))),s}function Vg(e){const t=aa(e);return xee[t]+e.slice(t.length)}function Nee(e){return{top:0,right:0,bottom:0,left:0,...e}}function HI(e){return typeof e!="number"?Nee(e):{top:e,right:e,bottom:e,left:e}}function Yg(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 NN(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=p1(t),l=f1(o),u=aa(t),d=s==="y",h=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:h,y:r.y-i.height};break;case"bottom":v={x:h,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(cd(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 Mee(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:h="viewport",elementContext:p="floating",altBoundary:y=!1,padding:v=0}=oa(t,e),_=HI(v),E=l[y?p==="floating"?"reference":"floating":p],x=Yg(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(E)))==null||n?E:E.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),A=await(s.isElement==null?void 0:s.isElement(R))?await(s.getScale==null?void 0:s.getScale(R))||{x:1,y:1}:{x:1,y:1},L=Yg(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(x.top-L.top+_.top)/A.y,bottom:(L.bottom-x.bottom+_.bottom)/A.y,left:(x.left-L.left+_.left)/A.x,right:(L.right-x.right+_.right)/A.x}}const Oee=50,Pee=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:Mee},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=NN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const E=s[w];if(!E)continue;const{name:x,fn:k}=E,{x:R,y:A,data:L,reset:T}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});h=R??h,p=A??p,_[x]={..._[x],...L},T&&v<Oee&&(v++,typeof T=="object"&&(T.placement&&(y=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:p}=NN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:_}},Dee=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:h=0}=oa(e,t)||{};if(d==null)return{};const p=HI(h),y={x:n,y:r},v=p1(i),_=f1(v),w=await o.getDimensions(d),E=v==="y",x=E?"top":"left",k=E?"bottom":"right",R=E?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[v]-y[v]-s.floating[_],L=y[v]-s.reference[v],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let H=T?T[R]:0;(!H||!await(o.isElement==null?void 0:o.isElement(T)))&&(H=l.floating[R]||s.floating[_]);const D=A/2-L/2,U=H/2-w[_]/2-1,W=ul(p[x],U),F=ul(p[k],U),O=W,M=H-w[_]-F,z=H/2-w[_]/2+D,P=N0(O,z,M),N=!u.arrow&&cd(i)!=null&&z!==P&&s.reference[_]/2-(z<O?W:F)-w[_]/2<0,q=N?z<O?z-O:z-M:0;return{[v]:y[v]+q,data:{[v]:P,centerOffset:z-P-q,...N&&{alignmentOffset:q}},reset:N}}}),Lee=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:h=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...E}=oa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=aa(i),k=So(l),R=aa(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),L=y||(R||!w?[Vg(l)]:Cee(l)),T=_!=="none";!y&&T&&L.push(...Aee(l,w,_,A));const H=[l,...L],D=await u.detectOverflow(t,E),U=[];let W=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&U.push(D[x]),p){const z=Eee(i,o,A);U.push(D[z[0]],D[z[1]])}if(W=[...W,{placement:i,overflows:U}],!U.every(z=>z<=0)){var F,O;const z=(((F=s.flip)==null?void 0:F.index)||0)+1,P=H[z];if(P&&(!(p==="alignment"?k!==So(P):!1)||W.every(V=>So(V.placement)===k?V.overflows[0]>0:!0)))return{data:{index:z,overflows:W},reset:{placement:P}};let N=(O=W.filter(q=>q.overflows[0]<=0).sort((q,V)=>q.overflows[1]-V.overflows[1])[0])==null?void 0:O.placement;if(!N)switch(v){case"bestFit":{var M;const q=(M=W.filter(V=>{if(T){const $=So(V.placement);return $===k||$==="y"}return!0}).map(V=>[V.placement,V.overflows.filter($=>$>0).reduce(($,I)=>$+I,0)]).sort((V,$)=>V[1]-$[1])[0])==null?void 0:M[0];q&&(N=q);break}case"initialPlacement":N=l;break}if(i!==N)return{reset:{placement:N}}}return{}}}};function MN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function ON(e){return See.some(t=>e[t]>=0)}const Iee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=oa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=MN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:ON(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=MN(o,n.floating);return{data:{escapedOffsets:l,escaped:ON(l)}}}default:return{}}}}},UI=new Set(["left","top"]);async function zee(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=aa(n),l=cd(n),u=So(n)==="y",d=UI.has(o)?-1:1,h=s&&u?-1:1,p=oa(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*h,y:y*d}:{x:y*d,y:v*h}}const Bee=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 zee(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}}}}},jee=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:R}=x;return{x:k,y:R}}},...d}=oa(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=So(aa(i)),v=h1(y);let _=h[v],w=h[y];if(o){const x=v==="y"?"top":"left",k=v==="y"?"bottom":"right",R=_+p[x],A=_-p[k];_=N0(R,_,A)}if(l){const x=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+p[x],A=w-p[k];w=N0(R,w,A)}const E=u.fn({...t,[v]:_,[y]:w});return{...E,data:{x:E.x-n,y:E.y-r,enabled:{[v]:o,[y]:l}}}}}},Fee=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}=oa(e,t),h={x:n,y:r},p=So(i),y=h1(p);let v=h[y],_=h[p];const w=oa(l,t),E=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const R=y==="y"?"height":"width",A=s.reference[y]-s.floating[R]+E.mainAxis,L=s.reference[y]+s.reference[R]-E.mainAxis;v<A?v=A:v>L&&(v=L)}if(d){var x,k;const R=y==="y"?"width":"height",A=UI.has(aa(i)),L=s.reference[p]-s.floating[R]+(A&&((x=o.offset)==null?void 0:x[p])||0)+(A?0:E.crossAxis),T=s.reference[p]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?E.crossAxis:0);_<L?_=L:_>T&&(_=T)}return{[y]:v,[p]:_}}}},$ee=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}=oa(e,t),h=await o.detectOverflow(t,d),p=aa(i),y=cd(i),v=So(i)==="y",{width:_,height:w}=s.floating;let E,x;p==="top"||p==="bottom"?(E=p,x=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=p,E=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,R=_-h.left-h.right,A=ul(w-h[E],k),L=ul(_-h[x],R),T=!t.middlewareData.shift;let H=A,D=L;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(D=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(H=k),T&&!y){const W=cs(h.left,0),F=cs(h.right,0),O=cs(h.top,0),M=cs(h.bottom,0);v?D=_-2*(W!==0||F!==0?W+F:cs(h.left,h.right)):H=w-2*(O!==0||M!==0?O+M:cs(h.top,h.bottom))}await u({...t,availableWidth:D,availableHeight:H});const U=await o.getDimensions(l.floating);return _!==U.width||w!==U.height?{reset:{rects:!0}}:{}}}};function Dv(){return typeof window<"u"}function ud(e){return WI(e)?(e.nodeName||"").toLowerCase():"#document"}function us(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function No(e){var t;return(t=(WI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function WI(e){return Dv()?e instanceof Node||e instanceof us(e).Node:!1}function Gs(e){return Dv()?e instanceof Element||e instanceof us(e).Element:!1}function ca(e){return Dv()?e instanceof HTMLElement||e instanceof us(e).HTMLElement:!1}function PN(e){return!Dv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof us(e).ShadowRoot}function jf(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Xs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Hee(e){return/^(table|td|th)$/.test(ud(e))}function Lv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Uee=/transform|translate|scale|rotate|perspective|filter/,Wee=/paint|layout|strict|content/,ql=e=>!!e&&e!=="none";let K_;function m1(e){const t=Gs(e)?Xs(e):e;return ql(t.transform)||ql(t.translate)||ql(t.scale)||ql(t.rotate)||ql(t.perspective)||!g1()&&(ql(t.backdropFilter)||ql(t.filter))||Uee.test(t.willChange||"")||Wee.test(t.contain||"")}function qee(e){let t=dl(e);for(;ca(t)&&!Ku(t);){if(m1(t))return t;if(Lv(t))return null;t=dl(t)}return null}function g1(){return K_==null&&(K_=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),K_}function Ku(e){return/^(html|body|#document)$/.test(ud(e))}function Xs(e){return us(e).getComputedStyle(e)}function Iv(e){return Gs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function dl(e){if(ud(e)==="html")return e;const t=e.assignedSlot||e.parentNode||PN(e)&&e.host||No(e);return PN(t)?t.host:t}function qI(e){const t=dl(e);return Ku(t)?e.ownerDocument?e.ownerDocument.body:e.body:ca(t)&&jf(t)?t:qI(t)}function mf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=qI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=us(i);if(s){const l=O0(o);return t.concat(o,o.visualViewport||[],jf(i)?i:[],l&&n?mf(l):[])}else return t.concat(i,mf(i,[],n))}function O0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function VI(e){const t=Xs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=ca(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=qg(n)!==s||qg(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function v1(e){return Gs(e)?e:e.contextElement}function Fu(e){const t=v1(e);if(!ca(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=VI(t);let o=(s?qg(n.width):n.width)/r,l=(s?qg(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Vee=Eo(0);function YI(e){const t=us(e);return!g1()||!t.visualViewport?Vee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Yee(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==us(e)?!1:t}function cc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=v1(e);let o=Eo(1);t&&(r?Gs(r)&&(o=Fu(r)):o=Fu(e));const l=Yee(s,n,r)?YI(s):Eo(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,h=i.width/o.x,p=i.height/o.y;if(s){const y=us(s),v=r&&Gs(r)?us(r):r;let _=y,w=O0(_);for(;w&&r&&v!==_;){const E=Fu(w),x=w.getBoundingClientRect(),k=Xs(w),R=x.left+(w.clientLeft+parseFloat(k.paddingLeft))*E.x,A=x.top+(w.clientTop+parseFloat(k.paddingTop))*E.y;u*=E.x,d*=E.y,h*=E.x,p*=E.y,u+=R,d+=A,_=us(w),w=O0(_)}}return Yg({width:h,height:p,x:u,y:d})}function zv(e,t){const n=Iv(e).scrollLeft;return t?t.left+n:cc(No(e)).left+n}function KI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-zv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Kee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Lv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=Eo(1);const h=Eo(0),p=ca(r);if((p||!p&&!s)&&((ud(r)!=="body"||jf(o))&&(u=Iv(r)),p)){const v=cc(r);d=Fu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?KI(o,u):Eo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function Gee(e){return Array.from(e.getClientRects())}function Xee(e){const t=No(e),n=Iv(e),r=e.ownerDocument.body,i=cs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=cs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+zv(e);const l=-n.scrollTop;return Xs(r).direction==="rtl"&&(o+=cs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const DN=25;function Zee(e,t){const n=us(e),r=No(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=g1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=zv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),v=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-v);_<=DN&&(s-=_)}else d<=DN&&(s+=d);return{width:s,height:o,x:l,y:u}}function Qee(e,t){const n=cc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=ca(e)?Fu(e):Eo(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 LN(e,t,n){let r;if(t==="viewport")r=Zee(e,n);else if(t==="document")r=Xee(No(e));else if(Gs(t))r=Qee(t,n);else{const i=YI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Yg(r)}function GI(e,t){const n=dl(e);return n===t||!Gs(n)||Ku(n)?!1:Xs(n).position==="fixed"||GI(n,t)}function Jee(e,t){const n=t.get(e);if(n)return n;let r=mf(e,[],!1).filter(l=>Gs(l)&&ud(l)!=="body"),i=null;const s=Xs(e).position==="fixed";let o=s?dl(e):e;for(;Gs(o)&&!Ku(o);){const l=Xs(o),u=m1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||jf(o)&&!u&&GI(e,o))?r=r.filter(h=>h!==o):i=l,o=dl(o)}return t.set(e,r),r}function ete(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Lv(t)?[]:Jee(t,this._c):[].concat(n),r],l=LN(t,o[0],i);let u=l.top,d=l.right,h=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const v=LN(t,o[y],i);u=cs(v.top,u),d=ul(v.right,d),h=ul(v.bottom,h),p=cs(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function tte(e){const{width:t,height:n}=VI(e);return{width:t,height:n}}function nte(e,t,n){const r=ca(t),i=No(t),s=n==="fixed",o=cc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=Eo(0);function d(){u.x=zv(i)}if(r||!r&&!s)if((ud(t)!=="body"||jf(i))&&(l=Iv(t)),r){const v=cc(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?KI(i,l):Eo(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function G_(e){return Xs(e).position==="static"}function IN(e,t){if(!ca(e)||Xs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return No(e)===n&&(n=n.ownerDocument.body),n}function XI(e,t){const n=us(e);if(Lv(e))return n;if(!ca(e)){let i=dl(e);for(;i&&!Ku(i);){if(Gs(i)&&!G_(i))return i;i=dl(i)}return n}let r=IN(e,t);for(;r&&Hee(r)&&G_(r);)r=IN(r,t);return r&&Ku(r)&&G_(r)&&!m1(r)?n:r||qee(e)||n}const rte=async function(e){const t=this.getOffsetParent||XI,n=this.getDimensions,r=await n(e.floating);return{reference:nte(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function ite(e){return Xs(e).direction==="rtl"}const ste={convertOffsetParentRelativeRectToViewportRelativeRect:Kee,getDocumentElement:No,getClippingRect:ete,getOffsetParent:XI,getElementRects:rte,getClientRects:Gee,getDimensions:tte,getScale:Fu,isElement:Gs,isRTL:ite};function ZI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ote(e,t){let n=null,r;const i=No(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:h,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const _=jm(p),w=jm(i.clientWidth-(h+y)),E=jm(i.clientHeight-(p+v)),x=jm(h),R={rootMargin:-_+"px "+-w+"px "+-E+"px "+-x+"px",threshold:cs(0,ul(1,u))||1};let A=!0;function L(T){const H=T[0].intersectionRatio;if(H!==u){if(!A)return o();H?o(!1,H):r=setTimeout(()=>{o(!1,1e-7)},1e3)}H===1&&!ZI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(L,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(L,R)}n.observe(e)}return o(!0),s}function ate(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=v1(e),h=i||s?[...d?mf(d):[],...t?mf(t):[]]:[];h.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const p=d&&l?ote(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 R;(R=v)==null||R.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let _,w=u?cc(e):null;u&&E();function E(){const x=cc(e);w&&!ZI(w,x)&&n(),w=x,_=requestAnimationFrame(E)}return n(),()=>{var x;h.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 lte=Bee,cte=jee,ute=Lee,dte=$ee,hte=Iee,zN=Dee,fte=Fee,pte=(e,t,n)=>{const r=new Map,i={platform:ste,...n},s={...i.platform,_c:r};return Pee(e,t,{...i,platform:s})};var mte=typeof document<"u",gte=function(){},_g=mte?b.useLayoutEffect:gte;function Kg(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(!Kg(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)&&!Kg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function QI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function BN(e,t){const n=QI(e);return Math.round(t*n)/n}function X_(e){const t=b.useRef(e);return _g(()=>{t.current=e}),t}function vte(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,[h,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=b.useState(r);Kg(y,r)||v(r);const[_,w]=b.useState(null),[E,x]=b.useState(null),k=b.useCallback(V=>{V!==T.current&&(T.current=V,w(V))},[]),R=b.useCallback(V=>{V!==H.current&&(H.current=V,x(V))},[]),A=s||_,L=o||E,T=b.useRef(null),H=b.useRef(null),D=b.useRef(h),U=u!=null,W=X_(u),F=X_(i),O=X_(d),M=b.useCallback(()=>{if(!T.current||!H.current)return;const V={placement:t,strategy:n,middleware:y};F.current&&(V.platform=F.current),pte(T.current,H.current,V).then($=>{const I={...$,isPositioned:O.current!==!1};z.current&&!Kg(D.current,I)&&(D.current=I,od.flushSync(()=>{p(I)}))})},[y,t,n,F,O]);_g(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,p(V=>({...V,isPositioned:!1})))},[d]);const z=b.useRef(!1);_g(()=>(z.current=!0,()=>{z.current=!1}),[]),_g(()=>{if(A&&(T.current=A),L&&(H.current=L),A&&L){if(W.current)return W.current(A,L,M);M()}},[A,L,M,W,U]);const P=b.useMemo(()=>({reference:T,floating:H,setReference:k,setFloating:R}),[k,R]),N=b.useMemo(()=>({reference:A,floating:L}),[A,L]),q=b.useMemo(()=>{const V={position:n,left:0,top:0};if(!N.floating)return V;const $=BN(N.floating,h.x),I=BN(N.floating,h.y);return l?{...V,transform:"translate("+$+"px, "+I+"px)",...QI(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:I}},[n,l,N.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:M,refs:P,elements:N,floatingStyles:q}),[h,M,P,N,q])}const yte=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?zN({element:r.current,padding:i}).fn(n):{}:r?zN({element:r,padding:i}).fn(n):{}}}},bte=(e,t)=>{const n=lte(e);return{name:n.name,fn:n.fn,options:[e,t]}},_te=(e,t)=>{const n=cte(e);return{name:n.name,fn:n.fn,options:[e,t]}},wte=(e,t)=>({fn:fte(e).fn,options:[e,t]}),Ste=(e,t)=>{const n=ute(e);return{name:n.name,fn:n.fn,options:[e,t]}},xte=(e,t)=>{const n=dte(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ete=(e,t)=>{const n=hte(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cte=(e,t)=>{const n=yte(e);return{name:n.name,fn:n.fn,options:[e,t]}};var kte="Arrow",JI=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Jt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:g.jsx("polygon",{points:"0,0 30,0 15,10"})})});JI.displayName=kte;var Tte=JI,y1="Popper",[ez,wl]=la(y1),[Rte,tz]=ez(y1),nz=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return g.jsx(Rte,{scope:t,anchor:r,onAnchorChange:i,children:n})};nz.displayName=y1;var rz="PopperAnchor",iz=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=tz(rz,n),o=b.useRef(null),l=Bn(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:g.jsx(Jt.div,{...i,ref:l})});iz.displayName=rz;var b1="PopperContent",[Ate,Nte]=ez(b1),sz=b.forwardRef((e,t)=>{var Q,fe,ce,Ee,Me,Ie;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:v="optimized",onPlaced:_,...w}=e,E=tz(b1,n),[x,k]=b.useState(null),R=Bn(t,Ye=>k(Ye)),[A,L]=b.useState(null),T=wee(A),H=(T==null?void 0:T.width)??0,D=(T==null?void 0:T.height)??0,U=r+(s!=="center"?"-"+s:""),W=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},F=Array.isArray(d)?d:[d],O=F.length>0,M={padding:W,boundary:F.filter(Ote),altBoundary:O},{refs:z,floatingStyles:P,placement:N,isPositioned:q,middlewareData:V}=vte({strategy:"fixed",placement:U,whileElementsMounted:(...Ye)=>ate(...Ye,{animationFrame:v==="always"}),elements:{reference:E.anchor},middleware:[bte({mainAxis:i+D,alignmentAxis:o}),u&&_te({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?wte():void 0,...M}),u&&Ste({...M}),xte({...M,apply:({elements:Ye,rects:xt,availableWidth:gn,availableHeight:ge})=>{const{width:rt,height:et}=xt.reference,ye=Ye.floating.style;ye.setProperty("--radix-popper-available-width",`${gn}px`),ye.setProperty("--radix-popper-available-height",`${ge}px`),ye.setProperty("--radix-popper-anchor-width",`${rt}px`),ye.setProperty("--radix-popper-anchor-height",`${et}px`)}}),A&&Cte({element:A,padding:l}),Pte({arrowWidth:H,arrowHeight:D}),y&&Ete({strategy:"referenceHidden",...M})]}),[$,I]=lz(N),Y=To(_);Ci(()=>{q&&(Y==null||Y())},[q,Y]);const G=(Q=V.arrow)==null?void 0:Q.x,j=(fe=V.arrow)==null?void 0:fe.y,ee=((ce=V.arrow)==null?void 0:ce.centerOffset)!==0,[J,te]=b.useState();return Ci(()=>{x&&te(window.getComputedStyle(x).zIndex)},[x]),g.jsx("div",{ref:z.setFloating,"data-radix-popper-content-wrapper":"",style:{...P,transform:q?P.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(Ee=V.transformOrigin)==null?void 0:Ee.x,(Me=V.transformOrigin)==null?void 0:Me.y].join(" "),...((Ie=V.hide)==null?void 0:Ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(Ate,{scope:n,placedSide:$,onArrowChange:L,arrowX:G,arrowY:j,shouldHideArrow:ee,children:g.jsx(Jt.div,{"data-side":$,"data-align":I,...w,ref:R,style:{...w.style,animation:q?void 0:"none"}})})})});sz.displayName=b1;var oz="PopperArrow",Mte={top:"bottom",right:"left",bottom:"top",left:"right"},az=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Nte(oz,r),o=Mte[s.placedSide];return g.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:g.jsx(Tte,{...i,ref:n,style:{...i.style,display:"block"}})})});az.displayName=oz;function Ote(e){return e!==null}var Pte=e=>({name:"transformOrigin",options:e,fn(t){var E,x,k;const{placement:n,rects:r,middlewareData:i}=t,o=((E=i.arrow)==null?void 0:E.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,h]=lz(n),p={start:"0%",center:"50%",end:"100%"}[h],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 lz(e){const[t,n="center"]=e.split("-");return[t,n]}var Bv=nz,Ff=iz,jv=sz,Fv=az,Z_="rovingFocusGroup.onEntryFocus",Dte={bubbles:!1,cancelable:!0},$f="RovingFocusGroup",[P0,cz,Lte]=r1($f),[Ite,uz]=la($f,[Lte]),[zte,Bte]=Ite($f),dz=b.forwardRef((e,t)=>g.jsx(P0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(P0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(jte,{...e,ref:t})})}));dz.displayName=$f;var jte=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...p}=e,y=b.useRef(null),v=Bn(t,y),_=i1(s),[w,E]=ac({prop:o,defaultProp:l??null,onChange:u,caller:$f}),[x,k]=b.useState(!1),R=To(d),A=cz(n),L=b.useRef(!1),[T,H]=b.useState(0);return b.useEffect(()=>{const D=y.current;if(D)return D.addEventListener(Z_,R),()=>D.removeEventListener(Z_,R)},[R]),g.jsx(zte,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(D=>E(D),[E]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>H(D=>D+1),[]),onFocusableItemRemove:b.useCallback(()=>H(D=>D-1),[]),children:g.jsx(Jt.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:St(e.onMouseDown,()=>{L.current=!0}),onFocus:St(e.onFocus,D=>{const U=!L.current;if(D.target===D.currentTarget&&U&&!x){const W=new CustomEvent(Z_,Dte);if(D.currentTarget.dispatchEvent(W),!W.defaultPrevented){const F=A().filter(N=>N.focusable),O=F.find(N=>N.active),M=F.find(N=>N.id===w),P=[O,M,...F].filter(Boolean).map(N=>N.ref.current);pz(P,h)}}L.current=!1}),onBlur:St(e.onBlur,()=>k(!1))})})}),hz="RovingFocusGroupItem",fz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=vi(),d=s||u,h=Bte(hz,n),p=h.currentTabStopId===d,y=cz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=h;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),g.jsx(P0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Jt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:St(e.onMouseDown,E=>{r?h.onItemFocus(d):E.preventDefault()}),onFocus:St(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:St(e.onKeyDown,E=>{if(E.key==="Tab"&&E.shiftKey){h.onItemShiftTab();return}if(E.target!==E.currentTarget)return;const x=Hte(E,h.orientation,h.dir);if(x!==void 0){if(E.metaKey||E.ctrlKey||E.altKey||E.shiftKey)return;E.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(x==="last")R.reverse();else if(x==="prev"||x==="next"){x==="prev"&&R.reverse();const A=R.indexOf(E.currentTarget);R=h.loop?Ute(R,A+1):R.slice(A+1)}setTimeout(()=>pz(R))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});fz.displayName=hz;var Fte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function $te(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Hte(e,t,n){const r=$te(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Fte[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 Ute(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Wte=dz,qte=fz,D0=["Enter"," "],Vte=["ArrowDown","PageUp","Home"],mz=["ArrowUp","PageDown","End"],Yte=[...Vte,...mz],Kte={ltr:[...D0,"ArrowRight"],rtl:[...D0,"ArrowLeft"]},Gte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Hf="Menu",[gf,Xte,Zte]=r1(Hf),[Sc,gz]=la(Hf,[Zte,wl,uz]),$v=wl(),vz=uz(),[Qte,xc]=Sc(Hf),[Jte,Uf]=Sc(Hf),yz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=$v(t),[u,d]=b.useState(null),h=b.useRef(!1),p=To(s),y=i1(i);return b.useEffect(()=>{const v=()=>{h.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>h.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})}},[]),g.jsx(Bv,{...l,children:g.jsx(Qte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(Jte,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};yz.displayName=Hf;var ene="MenuAnchor",_1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=$v(n);return g.jsx(Ff,{...i,...r,ref:t})});_1.displayName=ene;var w1="MenuPortal",[tne,bz]=Sc(w1,{forceMount:void 0}),_z=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=xc(w1,t);return g.jsx(tne,{scope:t,forceMount:n,children:g.jsx(Is,{present:n||s.open,children:g.jsx(ld,{asChild:!0,container:i,children:r})})})};_z.displayName=w1;var Ms="MenuContent",[nne,S1]=Sc(Ms),wz=b.forwardRef((e,t)=>{const n=bz(Ms,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=xc(Ms,e.__scopeMenu),o=Uf(Ms,e.__scopeMenu);return g.jsx(gf.Provider,{scope:e.__scopeMenu,children:g.jsx(Is,{present:r||s.open,children:g.jsx(gf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(rne,{...i,ref:t}):g.jsx(ine,{...i,ref:t})})})})}),rne=b.forwardRef((e,t)=>{const n=xc(Ms,e.__scopeMenu),r=b.useRef(null),i=Bn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Mv(s)},[]),g.jsx(x1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:St(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ine=b.forwardRef((e,t)=>{const n=xc(Ms,e.__scopeMenu);return g.jsx(x1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),sne=cl("MenuContent.ScrollLock"),x1=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,disableOutsideScroll:_,...w}=e,E=xc(Ms,n),x=Uf(Ms,n),k=$v(n),R=vz(n),A=Xte(n),[L,T]=b.useState(null),H=b.useRef(null),D=Bn(t,H,E.onContentChange),U=b.useRef(0),W=b.useRef(""),F=b.useRef(0),O=b.useRef(null),M=b.useRef("right"),z=b.useRef(0),P=_?Bf:b.Fragment,N=_?{as:sne,allowPinchZoom:!0}:void 0,q=$=>{var Q,fe;const I=W.current+$,Y=A().filter(ce=>!ce.disabled),G=document.activeElement,j=(Q=Y.find(ce=>ce.ref.current===G))==null?void 0:Q.textValue,ee=Y.map(ce=>ce.textValue),J=vne(ee,I,j),te=(fe=Y.find(ce=>ce.textValue===J))==null?void 0:fe.ref.current;(function ce(Ee){W.current=Ee,window.clearTimeout(U.current),Ee!==""&&(U.current=window.setTimeout(()=>ce(""),1e3))})(I),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(U.current),[]),Av();const V=b.useCallback($=>{var Y,G;return M.current===((Y=O.current)==null?void 0:Y.side)&&bne($,(G=O.current)==null?void 0:G.area)},[]);return g.jsx(nne,{scope:n,searchRef:W,onItemEnter:b.useCallback($=>{V($)&&$.preventDefault()},[V]),onItemLeave:b.useCallback($=>{var I;V($)||((I=H.current)==null||I.focus(),T(null))},[V]),onTriggerLeave:b.useCallback($=>{V($)&&$.preventDefault()},[V]),pointerGraceTimerRef:F,onPointerGraceIntentChange:b.useCallback($=>{O.current=$},[]),children:g.jsx(P,{...N,children:g.jsx(zf,{asChild:!0,trapped:i,onMountAutoFocus:St(s,$=>{var I;$.preventDefault(),(I=H.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Wte,{asChild:!0,...R,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:L,onCurrentTabStopIdChange:T,onEntryFocus:St(u,$=>{x.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(jv,{role:"menu","aria-orientation":"vertical","data-state":zz(E.open),"data-radix-menu-content":"",dir:x.dir,...k,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:St(w.onKeyDown,$=>{const Y=$.target.closest("[data-radix-menu-content]")===$.currentTarget,G=$.ctrlKey||$.altKey||$.metaKey,j=$.key.length===1;Y&&($.key==="Tab"&&$.preventDefault(),!G&&j&&q($.key));const ee=H.current;if($.target!==ee||!Yte.includes($.key))return;$.preventDefault();const te=A().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);mz.includes($.key)&&te.reverse(),mne(te)}),onBlur:St(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(U.current),W.current="")}),onPointerMove:St(e.onPointerMove,vf($=>{const I=$.target,Y=z.current!==$.clientX;if($.currentTarget.contains(I)&&Y){const G=$.clientX>z.current?"right":"left";M.current=G,z.current=$.clientX}}))})})})})})})});wz.displayName=Ms;var one="MenuGroup",E1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Jt.div,{role:"group",...r,ref:t})});E1.displayName=one;var ane="MenuLabel",Sz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Jt.div,{...r,ref:t})});Sz.displayName=ane;var Gg="MenuItem",jN="menu.itemSelect",Hv=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Uf(Gg,e.__scopeMenu),l=S1(Gg,e.__scopeMenu),u=Bn(t,s),d=b.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(jN,{bubbles:!0,cancelable:!0});p.addEventListener(jN,v=>r==null?void 0:r(v),{once:!0}),cI(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(xz,{...i,ref:u,disabled:n,onClick:St(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:St(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:St(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||D0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Hv.displayName=Gg;var xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=S1(Gg,n),l=vz(n),u=b.useRef(null),d=Bn(t,u),[h,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),g.jsx(gf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(qte,{asChild:!0,...l,focusable:!r,children:g.jsx(Jt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:St(e.onPointerMove,vf(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:St(e.onPointerLeave,vf(_=>o.onItemLeave(_))),onFocus:St(e.onFocus,()=>p(!0)),onBlur:St(e.onBlur,()=>p(!1))})})})}),lne="MenuCheckboxItem",Ez=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(Az,{scope:e.__scopeMenu,checked:n,children:g.jsx(Hv,{role:"menuitemcheckbox","aria-checked":Xg(n)?"mixed":n,...i,ref:t,"data-state":k1(n),onSelect:St(i.onSelect,()=>r==null?void 0:r(Xg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ez.displayName=lne;var Cz="MenuRadioGroup",[cne,une]=Sc(Cz,{value:void 0,onValueChange:()=>{}}),kz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return g.jsx(cne,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(E1,{...i,ref:t})})});kz.displayName=Cz;var Tz="MenuRadioItem",Rz=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=une(Tz,e.__scopeMenu),s=n===i.value;return g.jsx(Az,{scope:e.__scopeMenu,checked:s,children:g.jsx(Hv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":k1(s),onSelect:St(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});Rz.displayName=Tz;var C1="MenuItemIndicator",[Az,dne]=Sc(C1,{checked:!1}),Nz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=dne(C1,n);return g.jsx(Is,{present:r||Xg(s.checked)||s.checked===!0,children:g.jsx(Jt.span,{...i,ref:t,"data-state":k1(s.checked)})})});Nz.displayName=C1;var hne="MenuSeparator",Mz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Jt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Mz.displayName=hne;var fne="MenuArrow",Oz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=$v(n);return g.jsx(Fv,{...i,...r,ref:t})});Oz.displayName=fne;var pne="MenuSub",[PRe,Pz]=Sc(pne),zh="MenuSubTrigger",Dz=b.forwardRef((e,t)=>{const n=xc(zh,e.__scopeMenu),r=Uf(zh,e.__scopeMenu),i=Pz(zh,e.__scopeMenu),s=S1(zh,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>h,[h]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),g.jsx(_1,{asChild:!0,...d,children:g.jsx(xz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":zz(n.open),...e,ref:sa(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:St(e.onPointerMove,vf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:St(e.onPointerLeave,vf(p=>{var v,_;h();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,E=w==="right",x=E?-5:5,k=y[E?"left":"right"],R=y[E?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+x,y:p.clientY},{x:k,y:y.top},{x:R,y:y.top},{x:R,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:St(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Kte[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});Dz.displayName=zh;var Lz="MenuSubContent",Iz=b.forwardRef((e,t)=>{const n=bz(Ms,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=xc(Ms,e.__scopeMenu),o=Uf(Ms,e.__scopeMenu),l=Pz(Lz,e.__scopeMenu),u=b.useRef(null),d=Bn(t,u);return g.jsx(gf.Provider,{scope:e.__scopeMenu,children:g.jsx(Is,{present:r||s.open,children:g.jsx(gf.Slot,{scope:e.__scopeMenu,children:g.jsx(x1,{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:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:St(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:St(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:St(e.onKeyDown,h=>{var v;const p=h.currentTarget.contains(h.target),y=Gte[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),h.preventDefault())})})})})})});Iz.displayName=Lz;function zz(e){return e?"open":"closed"}function Xg(e){return e==="indeterminate"}function k1(e){return Xg(e)?"indeterminate":e?"checked":"unchecked"}function mne(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function gne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function vne(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=gne(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 yne(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,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function bne(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return yne(n,t)}function vf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var _ne=yz,wne=_1,Sne=_z,xne=wz,Ene=E1,Cne=Sz,kne=Hv,Tne=Ez,Rne=kz,Ane=Rz,Nne=Nz,Mne=Mz,One=Oz,Pne=Dz,Dne=Iz,Uv="DropdownMenu",[Lne]=la(Uv,[gz]),Li=gz(),[Ine,Bz]=Lne(Uv),jz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Li(t),d=b.useRef(null),[h,p]=ac({prop:i,defaultProp:s??!1,onChange:o,caller:Uv});return g.jsx(Ine,{scope:t,triggerId:vi(),triggerRef:d,contentId:vi(),open:h,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(_ne,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};jz.displayName=Uv;var Fz="DropdownMenuTrigger",$z=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Bz(Fz,n),o=Li(n);return g.jsx(wne,{asChild:!0,...o,children:g.jsx(Jt.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:sa(t,s.triggerRef),onPointerDown:St(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:St(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});$z.displayName=Fz;var zne="DropdownMenuPortal",Hz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Li(t);return g.jsx(Sne,{...r,...n})};Hz.displayName=zne;var Uz="DropdownMenuContent",Wz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Bz(Uz,n),s=Li(n),o=b.useRef(!1);return g.jsx(xne,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:St(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:St(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(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)"}})});Wz.displayName=Uz;var Bne="DropdownMenuGroup",jne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Ene,{...i,...r,ref:t})});jne.displayName=Bne;var Fne="DropdownMenuLabel",qz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Cne,{...i,...r,ref:t})});qz.displayName=Fne;var $ne="DropdownMenuItem",Vz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(kne,{...i,...r,ref:t})});Vz.displayName=$ne;var Hne="DropdownMenuCheckboxItem",Yz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Tne,{...i,...r,ref:t})});Yz.displayName=Hne;var Une="DropdownMenuRadioGroup",Wne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Rne,{...i,...r,ref:t})});Wne.displayName=Une;var qne="DropdownMenuRadioItem",Vne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Ane,{...i,...r,ref:t})});Vne.displayName=qne;var Yne="DropdownMenuItemIndicator",Kz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Nne,{...i,...r,ref:t})});Kz.displayName=Yne;var Kne="DropdownMenuSeparator",Gz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Mne,{...i,...r,ref:t})});Gz.displayName=Kne;var Gne="DropdownMenuArrow",Xne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(One,{...i,...r,ref:t})});Xne.displayName=Gne;var Zne="DropdownMenuSubTrigger",Qne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Pne,{...i,...r,ref:t})});Qne.displayName=Zne;var Jne="DropdownMenuSubContent",ere=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Li(n);return g.jsx(Dne,{...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)"}})});ere.displayName=Jne;var tre=jz,nre=$z,rre=Hz,ire=Wz,sre=qz,ore=Vz,are=Yz,lre=Kz,cre=Gz;function FN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Wv="Popover",[Xz]=la(Wv,[wl]),Wf=wl(),[ure,Sl]=Xz(Wv),Zz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Wf(t),u=b.useRef(null),[d,h]=b.useState(!1),[p,y]=ac({prop:r,defaultProp:i??!1,onChange:s,caller:Wv});return g.jsx(Bv,{...l,children:g.jsx(ure,{scope:t,contentId:vi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:o,children:n})})};Zz.displayName=Wv;var Qz="PopoverAnchor",dre=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Sl(Qz,n),s=Wf(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(Ff,{...s,...r,ref:t})});dre.displayName=Qz;var Jz="PopoverTrigger",eB=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Sl(Jz,n),s=Wf(n),o=Bn(t,i.triggerRef),l=g.jsx(Jt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":sB(i.open),...r,ref:o,onClick:St(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(Ff,{asChild:!0,...s,children:l})});eB.displayName=Jz;var T1="PopoverPortal",[hre,fre]=Xz(T1,{forceMount:void 0}),tB=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=Sl(T1,t);return g.jsx(hre,{scope:t,forceMount:n,children:g.jsx(Is,{present:n||s.open,children:g.jsx(ld,{asChild:!0,container:i,children:r})})})};tB.displayName=T1;var Gu="PopoverContent",nB=b.forwardRef((e,t)=>{const n=fre(Gu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=Sl(Gu,e.__scopePopover);return g.jsx(Is,{present:r||s.open,children:s.modal?g.jsx(mre,{...i,ref:t}):g.jsx(gre,{...i,ref:t})})});nB.displayName=Gu;var pre=cl("PopoverContent.RemoveScroll"),mre=b.forwardRef((e,t)=>{const n=Sl(Gu,e.__scopePopover),r=b.useRef(null),i=Bn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Mv(o)},[]),g.jsx(Bf,{as:pre,allowPinchZoom:!0,children:g.jsx(rB,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:St(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:St(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:St(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),gre=b.forwardRef((e,t)=>{const n=Sl(Gu,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return g.jsx(rB,{...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()}})}),rB=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,...p}=e,y=Sl(Gu,n),v=Wf(n);return Av(),g.jsx(zf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(jv,{"data-state":sB(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)"}})})})}),iB="PopoverClose",vre=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Sl(iB,n);return g.jsx(Jt.button,{type:"button",...r,ref:t,onClick:St(e.onClick,()=>i.onOpenChange(!1))})});vre.displayName=iB;var yre="PopoverArrow",bre=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Wf(n);return g.jsx(Fv,{...i,...r,ref:t})});bre.displayName=yre;function sB(e){return e?"open":"closed"}var _re=Zz,wre=eB,Sre=tB,xre=nB,Ere=[" ","Enter","ArrowUp","ArrowDown"],Cre=[" ","Enter"],uc="Select",[qv,Vv,kre]=r1(uc),[dd]=la(uc,[kre,wl]),Yv=wl(),[Tre,xl]=dd(uc),[Rre,Are]=dd(uc),oB=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:h,autoComplete:p,disabled:y,required:v,form:_}=e,w=Yv(t),[E,x]=b.useState(null),[k,R]=b.useState(null),[A,L]=b.useState(!1),T=i1(d),[H,D]=ac({prop:r,defaultProp:i??!1,onChange:s,caller:uc}),[U,W]=ac({prop:o,defaultProp:l,onChange:u,caller:uc}),F=b.useRef(null),O=E?_||!!E.closest("form"):!0,[M,z]=b.useState(new Set),P=Array.from(M).map(N=>N.props.value).join(";");return g.jsx(Bv,{...w,children:g.jsxs(Tre,{required:v,scope:t,trigger:E,onTriggerChange:x,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:L,contentId:vi(),value:U,onValueChange:W,open:H,onOpenChange:D,dir:T,triggerPointerDownPosRef:F,disabled:y,children:[g.jsx(qv.Provider,{scope:t,children:g.jsx(Rre,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(N=>{z(q=>new Set(q).add(N))},[]),onNativeOptionRemove:b.useCallback(N=>{z(q=>{const V=new Set(q);return V.delete(N),V})},[]),children:n})}),O?g.jsxs(RB,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:U,onChange:N=>W(N.target.value),disabled:y,form:_,children:[U===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},P):null]})})};oB.displayName=uc;var aB="SelectTrigger",lB=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Yv(n),o=xl(aB,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Vv(n),h=b.useRef("touch"),[p,y,v]=NB(w=>{const E=d().filter(R=>!R.disabled),x=E.find(R=>R.value===o.value),k=MB(E,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 g.jsx(Ff,{asChild:!0,...s,children:g.jsx(Jt.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":AB(o.value)?"":void 0,...i,ref:u,onClick:St(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&_(w)}),onPointerDown:St(i.onPointerDown,w=>{h.current=w.pointerType;const E=w.target;E.hasPointerCapture(w.pointerId)&&E.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:St(i.onKeyDown,w=>{const E=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(E&&w.key===" ")&&Ere.includes(w.key)&&(_(),w.preventDefault())})})})});lB.displayName=aB;var cB="SelectValue",uB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=xl(cB,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ci(()=>{d(h)},[d,h]),g.jsx(Jt.span,{...l,ref:p,style:{pointerEvents:"none"},children:AB(u.value)?g.jsx(g.Fragment,{children:o}):s})});uB.displayName=cB;var Nre="SelectIcon",dB=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Jt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});dB.displayName=Nre;var Mre="SelectPortal",hB=e=>g.jsx(ld,{asChild:!0,...e});hB.displayName=Mre;var dc="SelectContent",fB=b.forwardRef((e,t)=>{const n=xl(dc,e.__scopeSelect),[r,i]=b.useState();if(Ci(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?od.createPortal(g.jsx(pB,{scope:e.__scopeSelect,children:g.jsx(qv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(mB,{...e,ref:t})});fB.displayName=dc;var Ws=10,[pB,El]=dd(dc),Ore="SelectContentImpl",Pre=cl("SelectContent.RemoveScroll"),mB=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:E,...x}=e,k=xl(dc,n),[R,A]=b.useState(null),[L,T]=b.useState(null),H=Bn(t,Q=>A(Q)),[D,U]=b.useState(null),[W,F]=b.useState(null),O=Vv(n),[M,z]=b.useState(!1),P=b.useRef(!1);b.useEffect(()=>{if(R)return Mv(R)},[R]),Av();const N=b.useCallback(Q=>{const[fe,...ce]=O().map(Ie=>Ie.ref.current),[Ee]=ce.slice(-1),Me=document.activeElement;for(const Ie of Q)if(Ie===Me||(Ie==null||Ie.scrollIntoView({block:"nearest"}),Ie===fe&&L&&(L.scrollTop=0),Ie===Ee&&L&&(L.scrollTop=L.scrollHeight),Ie==null||Ie.focus(),document.activeElement!==Me))return},[O,L]),q=b.useCallback(()=>N([D,R]),[N,D,R]);b.useEffect(()=>{M&&q()},[M,q]);const{onOpenChange:V,triggerPointerDownPosRef:$}=k;b.useEffect(()=>{if(R){let Q={x:0,y:0};const fe=Ee=>{var Me,Ie;Q={x:Math.abs(Math.round(Ee.pageX)-(((Me=$.current)==null?void 0:Me.x)??0)),y:Math.abs(Math.round(Ee.pageY)-(((Ie=$.current)==null?void 0:Ie.y)??0))}},ce=Ee=>{Q.x<=10&&Q.y<=10?Ee.preventDefault():R.contains(Ee.target)||V(!1),document.removeEventListener("pointermove",fe),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",fe),document.addEventListener("pointerup",ce,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",fe),document.removeEventListener("pointerup",ce,{capture:!0})}}},[R,V,$]),b.useEffect(()=>{const Q=()=>V(!1);return window.addEventListener("blur",Q),window.addEventListener("resize",Q),()=>{window.removeEventListener("blur",Q),window.removeEventListener("resize",Q)}},[V]);const[I,Y]=NB(Q=>{const fe=O().filter(Me=>!Me.disabled),ce=fe.find(Me=>Me.ref.current===document.activeElement),Ee=MB(fe,Q,ce);Ee&&setTimeout(()=>Ee.ref.current.focus())}),G=b.useCallback((Q,fe,ce)=>{const Ee=!P.current&&!ce;(k.value!==void 0&&k.value===fe||Ee)&&(U(Q),Ee&&(P.current=!0))},[k.value]),j=b.useCallback(()=>R==null?void 0:R.focus(),[R]),ee=b.useCallback((Q,fe,ce)=>{const Ee=!P.current&&!ce;(k.value!==void 0&&k.value===fe||Ee)&&F(Q)},[k.value]),J=r==="popper"?L0:gB,te=J===L0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:E}:{};return g.jsx(pB,{scope:n,content:R,viewport:L,onViewportChange:T,itemRefCallback:G,selectedItem:D,onItemLeave:j,itemTextRefCallback:ee,focusSelectedItem:q,selectedItemText:W,position:r,isPositioned:M,searchRef:I,children:g.jsx(Bf,{as:Pre,allowPinchZoom:!0,children:g.jsx(zf,{asChild:!0,trapped:k.open,onMountAutoFocus:Q=>{Q.preventDefault()},onUnmountAutoFocus:St(i,Q=>{var fe;(fe=k.trigger)==null||fe.focus({preventScroll:!0}),Q.preventDefault()}),children:g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:Q=>Q.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(J,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:Q=>Q.preventDefault(),...x,...te,onPlaced:()=>z(!0),ref:H,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:St(x.onKeyDown,Q=>{const fe=Q.ctrlKey||Q.altKey||Q.metaKey;if(Q.key==="Tab"&&Q.preventDefault(),!fe&&Q.key.length===1&&Y(Q.key),["ArrowUp","ArrowDown","Home","End"].includes(Q.key)){let Ee=O().filter(Me=>!Me.disabled).map(Me=>Me.ref.current);if(["ArrowUp","End"].includes(Q.key)&&(Ee=Ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(Q.key)){const Me=Q.target,Ie=Ee.indexOf(Me);Ee=Ee.slice(Ie+1)}setTimeout(()=>N(Ee)),Q.preventDefault()}})})})})})})});mB.displayName=Ore;var Dre="SelectItemAlignedPosition",gB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=xl(dc,n),o=El(dc,n),[l,u]=b.useState(null),[d,h]=b.useState(null),p=Bn(t,H=>h(H)),y=Vv(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:E,selectedItemText:x,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&E&&x){const H=s.trigger.getBoundingClientRect(),D=d.getBoundingClientRect(),U=s.valueNode.getBoundingClientRect(),W=x.getBoundingClientRect();if(s.dir!=="rtl"){const Me=W.left-D.left,Ie=U.left-Me,Ye=H.left-Ie,xt=H.width+Ye,gn=Math.max(xt,D.width),ge=window.innerWidth-Ws,rt=FN(Ie,[Ws,Math.max(Ws,ge-gn)]);l.style.minWidth=xt+"px",l.style.left=rt+"px"}else{const Me=D.right-W.right,Ie=window.innerWidth-U.right-Me,Ye=window.innerWidth-H.right-Ie,xt=H.width+Ye,gn=Math.max(xt,D.width),ge=window.innerWidth-Ws,rt=FN(Ie,[Ws,Math.max(Ws,ge-gn)]);l.style.minWidth=xt+"px",l.style.right=rt+"px"}const F=y(),O=window.innerHeight-Ws*2,M=w.scrollHeight,z=window.getComputedStyle(d),P=parseInt(z.borderTopWidth,10),N=parseInt(z.paddingTop,10),q=parseInt(z.borderBottomWidth,10),V=parseInt(z.paddingBottom,10),$=P+N+M+V+q,I=Math.min(E.offsetHeight*5,$),Y=window.getComputedStyle(w),G=parseInt(Y.paddingTop,10),j=parseInt(Y.paddingBottom,10),ee=H.top+H.height/2-Ws,J=O-ee,te=E.offsetHeight/2,Q=E.offsetTop+te,fe=P+N+Q,ce=$-fe;if(fe<=ee){const Me=F.length>0&&E===F[F.length-1].ref.current;l.style.bottom="0px";const Ie=d.clientHeight-w.offsetTop-w.offsetHeight,Ye=Math.max(J,te+(Me?j:0)+Ie+q),xt=fe+Ye;l.style.height=xt+"px"}else{const Me=F.length>0&&E===F[0].ref.current;l.style.top="0px";const Ye=Math.max(ee,P+w.offsetTop+(Me?G:0)+te)+ce;l.style.height=Ye+"px",w.scrollTop=fe-ee+w.offsetTop}l.style.margin=`${Ws}px 0`,l.style.minHeight=I+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,E,x,s.dir,r]);Ci(()=>R(),[R]);const[A,L]=b.useState();Ci(()=>{d&&L(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(H=>{H&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return g.jsx(Ire,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:T,children:g.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:g.jsx(Jt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});gB.displayName=Dre;var Lre="SelectPopperPosition",L0=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Ws,...s}=e,o=Yv(n);return g.jsx(jv,{...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)"}})});L0.displayName=Lre;var[Ire,R1]=dd(dc,{}),I0="SelectViewport",vB=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=El(I0,n),o=R1(I0,n),l=Bn(t,s.onViewportChange),u=b.useRef(0);return g.jsxs(g.Fragment,{children:[g.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}),g.jsx(qv.Slot,{scope:n,children:g.jsx(Jt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:St(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const v=Math.abs(u.current-h.scrollTop);if(v>0){const _=window.innerHeight-Ws*2,w=parseFloat(p.style.minHeight),E=parseFloat(p.style.height),x=Math.max(w,E);if(x<_){const k=x+v,R=Math.min(_,k),A=k-R;p.style.height=R+"px",p.style.bottom==="0px"&&(h.scrollTop=A>0?A:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});vB.displayName=I0;var yB="SelectGroup",[zre,Bre]=dd(yB),jre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=vi();return g.jsx(zre,{scope:n,id:i,children:g.jsx(Jt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});jre.displayName=yB;var bB="SelectLabel",Fre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bre(bB,n);return g.jsx(Jt.div,{id:i.id,...r,ref:t})});Fre.displayName=bB;var Zg="SelectItem",[$re,_B]=dd(Zg),wB=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=xl(Zg,n),u=El(Zg,n),d=l.value===r,[h,p]=b.useState(s??""),[y,v]=b.useState(!1),_=Bn(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=vi(),E=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 g.jsx($re,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{p(R=>R||((k==null?void 0:k.textContent)??"").trim())},[]),children:g.jsx(qv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Jt.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:St(o.onFocus,()=>v(!0)),onBlur:St(o.onBlur,()=>v(!1)),onClick:St(o.onClick,()=>{E.current!=="mouse"&&x()}),onPointerUp:St(o.onPointerUp,()=>{E.current==="mouse"&&x()}),onPointerDown:St(o.onPointerDown,k=>{E.current=k.pointerType}),onPointerMove:St(o.onPointerMove,k=>{var R;E.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):E.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:St(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:St(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(Cre.includes(k.key)&&x(),k.key===" "&&k.preventDefault())})})})})});wB.displayName=Zg;var Bh="SelectItemText",SB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=xl(Bh,n),l=El(Bh,n),u=_B(Bh,n),d=Are(Bh,n),[h,p]=b.useState(null),y=Bn(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=h==null?void 0:h.textContent,_=b.useMemo(()=>g.jsx("option",{value:u.value,disabled:u.disabled,children:v},u.value),[u.disabled,u.value,v]),{onNativeOptionAdd:w,onNativeOptionRemove:E}=d;return Ci(()=>(w(_),()=>E(_)),[w,E,_]),g.jsxs(g.Fragment,{children:[g.jsx(Jt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?od.createPortal(s.children,o.valueNode):null]})});SB.displayName=Bh;var xB="SelectItemIndicator",EB=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return _B(xB,n).isSelected?g.jsx(Jt.span,{"aria-hidden":!0,...r,ref:t}):null});EB.displayName=xB;var z0="SelectScrollUpButton",CB=b.forwardRef((e,t)=>{const n=El(z0,e.__scopeSelect),r=R1(z0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ci(()=>{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?g.jsx(TB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});CB.displayName=z0;var B0="SelectScrollDownButton",kB=b.forwardRef((e,t)=>{const n=El(B0,e.__scopeSelect),r=R1(B0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ci(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,h=Math.ceil(u.scrollTop)<d;s(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?g.jsx(TB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});kB.displayName=B0;var TB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=El("SelectScrollButton",n),o=b.useRef(null),l=Vv(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ci(()=>{var h;const d=l().find(p=>p.ref.current===document.activeElement);(h=d==null?void 0:d.ref.current)==null||h.scrollIntoView({block:"nearest"})},[l]),g.jsx(Jt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:St(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:St(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:St(i.onPointerLeave,()=>{u()})})}),Hre="SelectSeparator",Ure=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Jt.div,{"aria-hidden":!0,...r,ref:t})});Ure.displayName=Hre;var j0="SelectArrow",Wre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Yv(n),s=xl(j0,n),o=El(j0,n);return s.open&&o.position==="popper"?g.jsx(Fv,{...i,...r,ref:t}):null});Wre.displayName=j0;var qre="SelectBubbleInput",RB=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=Bn(r,i),o=_ee(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&h){const p=new Event("change",{bubbles:!0});h.call(l,t),l.dispatchEvent(p)}},[o,t]),g.jsx(Jt.select,{...n,style:{...uI,...n.style},ref:s,defaultValue:t})});RB.displayName=qre;function AB(e){return e===""||e===void 0}function NB(e){const t=To(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 MB(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=Vre(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 Vre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Yre=oB,Kre=lB,Gre=uB,Xre=dB,Zre=hB,Qre=fB,Jre=vB,eie=wB,tie=SB,nie=EB,rie=CB,iie=kB,[Kv]=la("Tooltip",[wl]),Gv=wl(),OB="TooltipProvider",sie=700,F0="tooltip.open",[oie,A1]=Kv(OB),PB=e=>{const{__scopeTooltip:t,delayDuration:n=sie,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)},[]),g.jsx(oie,{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})};PB.displayName=OB;var yf="Tooltip",[aie,qf]=Kv(yf),DB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=A1(yf,e.__scopeTooltip),d=Gv(t),[h,p]=b.useState(null),y=vi(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,E=b.useRef(!1),[x,k]=ac({prop:r,defaultProp:i??!1,onChange:H=>{H?(u.onOpen(),document.dispatchEvent(new CustomEvent(F0))):u.onClose(),s==null||s(H)},caller:yf}),R=b.useMemo(()=>x?E.current?"delayed-open":"instant-open":"closed",[x]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,E.current=!1,k(!0)},[k]),L=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{E.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Bv,{...d,children:g.jsx(aie,{scope:t,contentId:y,open:x,stateAttribute:R,trigger:h,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?L():(window.clearTimeout(v.current),v.current=0)},[L,_]),onOpen:A,onClose:L,disableHoverableContent:_,children:n})})};DB.displayName=yf;var $0="TooltipTrigger",LB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=qf($0,n),s=A1($0,n),o=Gv(n),l=b.useRef(null),u=Bn(t,l,i.onTriggerChange),d=b.useRef(!1),h=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),g.jsx(Ff,{asChild:!0,...o,children:g.jsx(Jt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:St(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:St(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:St(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:St(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:St(e.onBlur,i.onClose),onClick:St(e.onClick,i.onClose)})})});LB.displayName=$0;var N1="TooltipPortal",[lie,cie]=Kv(N1,{forceMount:void 0}),IB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=qf(N1,t);return g.jsx(lie,{scope:t,forceMount:n,children:g.jsx(Is,{present:n||s.open,children:g.jsx(ld,{asChild:!0,container:i,children:r})})})};IB.displayName=N1;var Xu="TooltipContent",zB=b.forwardRef((e,t)=>{const n=cie(Xu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=qf(Xu,e.__scopeTooltip);return g.jsx(Is,{present:r||o.open,children:o.disableHoverableContent?g.jsx(BB,{side:i,...s,ref:t}):g.jsx(uie,{side:i,...s,ref:t})})}),uie=b.forwardRef((e,t)=>{const n=qf(Xu,e.__scopeTooltip),r=A1(Xu,e.__scopeTooltip),i=b.useRef(null),s=Bn(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=b.useCallback(()=>{l(null),p(!1)},[p]),v=b.useCallback((_,w)=>{const E=_.currentTarget,x={x:_.clientX,y:_.clientY},k=pie(x,E.getBoundingClientRect()),R=mie(x,k),A=gie(w.getBoundingClientRect()),L=yie([...R,...A]);l(L),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&h){const _=E=>v(E,h),w=E=>v(E,u);return u.addEventListener("pointerleave",_),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),h.removeEventListener("pointerleave",w)}}},[u,h,v,y]),b.useEffect(()=>{if(o){const _=w=>{const E=w.target,x={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(E))||(h==null?void 0:h.contains(E)),R=!vie(x,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,h,o,d,y]),g.jsx(BB,{...e,ref:s})}),[die,hie]=Kv(yf,{isInside:!1}),fie=VQ("TooltipContent"),BB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=qf(Xu,n),d=Gv(n),{onClose:h}=u;return b.useEffect(()=>(document.addEventListener(F0,h),()=>document.removeEventListener(F0,h)),[h]),b.useEffect(()=>{if(u.trigger){const p=y=>{const v=y.target;v!=null&&v.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),g.jsx(ad,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(jv,{"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:[g.jsx(fie,{children:r}),g.jsx(die,{scope:n,isInside:!0,children:g.jsx(hI,{id:u.contentId,role:"tooltip",children:i||r})})]})})});zB.displayName=Xu;var jB="TooltipArrow",FB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Gv(n);return hie(jB,n).isInside?null:g.jsx(Fv,{...i,...r,ref:t})});FB.displayName=jB;function pie(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 mie(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 gie(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 vie(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,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function yie(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),bie(t)}function bie(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 _ie=PB,wie=DB,Sie=LB,xie=IB,Eie=zB,Cie=FB;function M1({...e}){return g.jsx(_re,{"data-slot":"popover",...e})}function O1({...e}){return g.jsx(wre,{"data-slot":"popover-trigger",...e})}function P1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(Sre,{children:g.jsx(xre,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("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 kie={"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 rc({variant:e,action:t}){const{heading:n,body:r}=kie[e];return e==="no-messages"?g.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:g.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):g.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:[g.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&g.jsx("div",{children:t})]})}const Tie={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Rie={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function $N({status:e,className:t}){return g.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Tie[e],t),role:"status","aria-label":Rie[e]})}function $B({layout:e,variant:t="default"}){const n=Oe(_=>_.proxies),r=Oe(_=>_.proxyListLoaded),i=Oe(_=>_.relayClientAuthIssue),s=Oe(_=>_.selectedProxyId),o=Oe(_=>_.proxySwitchTarget),l=Di(),u=Qs(),[d,h]=b.useState(!1);async function p(_,w){if(o)return;const E=Pt;if(!E){tt.error("请先连接开发机");return}const x=w??_,k=s!==null&&s!==_;Oe.getState().setProxySwitchTarget({proxyId:_,name:x});try{const R=await E.selectProxy(_);if(!R.success){tt.error(`无法连接 ${x}:${R.error??"未知错误"}`);return}k&&($t.getState().prepareForProxySwitch(x),ai.getState().prepareForProxySwitch()),gr("local",cn.proxyId,_),Oe.getState().setProxy(_,w??null),Oe.getState().setProxyOnline(!0),Oe.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestProxyInfo().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const L=ai.getState();L.setHomePath(A.homePath),L.setAgentCli(A.agentCli)}).catch(A=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",A)}),E.requestAgentStatuses().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const L=$t.getState();for(const T of A)L.setAgentStatus(T.sessionId,T.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),E.requestSessionHistory().then(A=>{Oe.getState().selectedProxyId===_&&$t.getState().setHistorySessions(A)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),h(!1),(e==="page"||l.pathname.startsWith("/chat/"))&&u("/sessions")}catch(R){const A=R instanceof Error?R.message:"未知错误";tt.error(`无法连接 ${x}:${A}`)}finally{Oe.getState().setProxySwitchTarget(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(rc,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(rc,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(rc,{variant:"no-proxy"}):g.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[g.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),g.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,E=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||E,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:We("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",w?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",E&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx($N,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),g.jsx(sl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===_.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})]}):g.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:[g.jsx(sl,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});const y=n.find(_=>_.proxyId===s),v=(y==null?void 0:y.name)??(y==null?void 0:y.proxyId)??"未选择开发机";return g.jsxs(M1,{open:d,onOpenChange:h,children:[g.jsx(O1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("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":`当前连接:${v}`,children:[t==="default"&&g.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),g.jsx("span",{className:We("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:v}),g.jsx(vl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(P1,{align:"start",className:"w-[260px] p-1",children:n.length===0?g.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):g.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,E=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||E,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:We("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",w?"bg-accent text-accent-foreground":"hover:bg-accent",E&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线",children:[g.jsx($N,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsx(sl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===_.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&s!==_.proxyId&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})})]})}const HN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,UN=YD,Aie=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return UN(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 h=n==null?void 0:n[d],p=s==null?void 0:s[d];if(h===null)return null;const y=HN(h)||HN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,h)=>{let[p,y]=h;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,h)=>{let{class:p,className:y,...v}=h;return Object.entries(v).every(_=>{let[w,E]=_;return Array.isArray(E)?E.includes({...s,...l}[w]):{...s,...l}[w]===E})?[...d,p,y]:d},[]);return UN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Nie=Aie("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?WQ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(Nie({variant:t,size:n,className:e})),...i})}function Mie({delayDuration:e=0,...t}){return g.jsx(_ie,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Vf({...e}){return g.jsx(wie,{"data-slot":"tooltip",...e})}function Yf({...e}){return g.jsx(Sie,{"data-slot":"tooltip-trigger",...e})}function Kf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(xie,{children:g.jsxs(Eie,{"data-slot":"tooltip-content",sideOffset:t,className:We("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&&g.jsx(Cie,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Xv({...e}){return g.jsx(l1,{"data-slot":"sheet",...e})}function Oie({...e}){return g.jsx(bee,{"data-slot":"sheet-trigger",...e})}function Pie({...e}){return g.jsx(c1,{"data-slot":"sheet-portal",...e})}function Die({className:e,...t}){return g.jsx(u1,{"data-slot":"sheet-overlay",className:We("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 Zv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return g.jsxs(Pie,{children:[g.jsx(Die,{className:t}),g.jsxs(d1,{"data-slot":"sheet-content",className:We("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&&g.jsxs(Pv,{"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:[g.jsx(bc,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function D1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function Qv({className:e,...t}){return g.jsx(FI,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Lie({className:e,...t}){return g.jsx($I,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}function L1({...e}){return g.jsx(tre,{"data-slot":"dropdown-menu",...e})}function I1({...e}){return g.jsx(nre,{"data-slot":"dropdown-menu-trigger",...e})}function z1({className:e,sideOffset:t=4,...n}){return g.jsx(rre,{children:g.jsx(ire,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("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 _o({className:e,inset:t,variant:n="default",...r}){return g.jsx(ore,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("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 Q_({className:e,children:t,checked:n,...r}){return g.jsxs(are,{"data-slot":"dropdown-menu-checkbox-item",className:We("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:[g.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:g.jsx(lre,{children:g.jsx(ra,{className:"size-4"})})}),t]})}function Fm({className:e,inset:t,...n}){return g.jsx(sre,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function J_({className:e,...t}){return g.jsx(cre,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}const Iie={claude:"Claude Code",codex:"Codex"},WN=["claude","codex"];function Jv(e){return Iie[e]}function HB(e,t){return WN.indexOf(e)-WN.indexOf(t)}function H0(e){return e.provider??"claude"}const U0=60*1e3,W0=60*U0,zie=24*W0;function UB(e,t=Date.now()){const n=t-e;if(n<U0)return"刚刚";if(n<W0)return`${Math.floor(n/U0)} 分钟前`;if(n<zie)return`${Math.floor(n/W0)} 小时前`;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 qN={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 q0(e){return e.kind!=="terminal"?qN[e.state]:e.state==="terminated"?qN.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 Bie({session:e}){const t=q0(e);return g.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function jie({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Px:Lx;return g.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:g.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Fie({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Tv(e.name),d=Jx(e),h=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?UB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:We("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&&g.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),g.jsxs("button",{type:"button",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:[g.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[g.jsx(Bie,{session:e}),g.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&g.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&g.jsx(jie,{mode:e.mode}),e.mode&&g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Jv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:We("shrink-0",q0(e).text),children:q0(e).label}),y&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),g.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&g.jsxs(L1,{children:[g.jsx(I1,{asChild:!0,children:g.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:g.jsx(E9,{"aria-hidden":"true"})})}),g.jsxs(z1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(_o,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(_o,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function Ec({...e}){return g.jsx(l1,{"data-slot":"dialog",...e})}function $ie({...e}){return g.jsx(c1,{"data-slot":"dialog-portal",...e})}function Hie({...e}){return g.jsx(Pv,{"data-slot":"dialog-close",...e})}function Uie({className:e,...t}){return g.jsx(u1,{"data-slot":"dialog-overlay",className:We("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 Cc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs($ie,{"data-slot":"dialog-portal",children:[g.jsx(Uie,{}),g.jsxs(d1,{"data-slot":"dialog-content",className:We("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&&g.jsxs(Pv,{"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:[g.jsx(bc,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function kc({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Zu({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&g.jsx(Pv,{asChild:!0,children:g.jsx(Ct,{variant:"outline",children:"Close"})})]})}function hl({className:e,...t}){return g.jsx(FI,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function hc({className:e,...t}){return g.jsx($I,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function fl(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 Wie({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(qie,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:UB(e.updatedAt,t)}),u=g.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return g.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:g.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:We("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,g.jsx(X8,{className:We("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 qie({title:e,modeTag:t}){return g.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&g.jsx(Vie,{mode:t})]})}function Vie({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Px:Lx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:g.jsx(n,{className:"size-3","aria-hidden":"true"})})}function WB({providerLabel:e}){return g.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:g.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[g.jsx(O7,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),g.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Yie({now:e}){const t=$t(F=>F.historySessions),[n,r]=b.useState(null),[i,s]=b.useState(null),[o,l]=b.useState("json"),[u,d]=b.useState("default"),[h,p]=b.useState(!1),[y,v]=b.useState(!1),[_,w]=b.useState(new Set),[E,x]=b.useState(new Set),k=Qs(),R=b.useMemo(()=>{const F=new Map;for(const O of t){const M=H0(O);let z=F.get(M);z||(z=new Map,F.set(M,z));const P=qB(O.projectDir),N=z.get(P);N?N.sessions.push(O):z.set(P,{dir:P,sessions:[O]})}return Array.from(F.entries()).sort(([O],[M])=>HB(O,M)).map(([O,M])=>({provider:O,sessions:Array.from(M.values()).flatMap(z=>z.sessions),projects:Array.from(M.values()).map(z=>({dir:z.dir,shortDir:Tv(z.dir),sessions:z.sessions}))}))},[t]);function A(F){s(F),l(Kie(F)),d("default")}async function L(F,O,M){if(n)return;const z=Pt;if(!z){tt.error("请先连接开发机");return}r(F.id);const P=H0(F);try{const N=await z.createSession({cwd:F.projectDir,mode:O,provider:P,resumeSessionId:F.id,...M?{permissionMode:M}:{}});if(N.error||!N.sessionId){tt.error(`恢复失败:${N.error??"未知错误"}`);return}const q={sessionId:N.sessionId,state:"idle",mode:N.mode??O,provider:N.provider??"claude"};$t.getState().addSession(q),k(`/chat/${N.sessionId}?mode=${N.mode??O}`),s(null)}catch(N){tt.error(`恢复失败:${N instanceof Error?N.message:String(N)}`)}finally{r(null)}}function T(){const F=Pt;!F||h||(p(!0),F.requestSessionHistory().then(O=>$t.getState().setHistorySessions(O)).catch(O=>{tt.error(O instanceof Error?O.message:String(O))}).finally(()=>{p(!1)}))}function H(F,O){const M=VN(F,O);x(z=>{const P=new Set(z);return P.has(M)?P.delete(M):P.add(M),P})}function D(F){w(O=>{const M=new Set(O);return M.has(F)?M.delete(F):M.add(F),M})}const U=t.length>0,W=i?VB():[];return g.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[g.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[g.jsxs("button",{type:"button",onClick:()=>U&&v(F=>!F),disabled:!U,"aria-expanded":U?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:We("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:[g.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",U?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),U?g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:T,disabled:h,"data-slot":"history-refresh",children:g.jsx(Dx,{className:We("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!U&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),U&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(F=>{const O=_.has(F.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>D(F.provider),"aria-expanded":!O,"data-slot":"history-provider-header","data-expanded":!O,className:We("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:[g.jsx("span",{className:"font-mono",children:Jv(F.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:F.sessions.length}),g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!O&&"rotate-90"),"aria-hidden":"true"})]}),!O&&g.jsx("ul",{role:"list",className:"flex flex-col",children:F.projects.map(M=>{const z=VN(F.provider,M.dir),P=E.has(z);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>H(F.provider,M.dir),"aria-expanded":P,"data-slot":"history-group-header","data-expanded":P,className:We("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:[g.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),g.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",P&&"rotate-90"),"aria-hidden":"true"})]}),P&&g.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(N=>g.jsx(Wie,{session:N,now:e,disabled:n!==null,loading:n===N.id,onClick:()=>A(N),modeTag:N.preferredMode},N.id))})]},z)})})]},F.provider)})}),g.jsx(Gie,{session:i,open:i!==null,modes:W,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:F=>{F||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&L(i,o,u)}})]})}function VN(e,t){return`${e}:${qB(t)}`}function qB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function VB(){return["json","pty"]}function Kie(e){const t=VB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Gie({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=b.useState(!1),y=i==="bypassPermissions",v=fl("(min-width: 768px)");b.useEffect(()=>{t||p(!1)},[t]);const _=h?g.jsx(WB,{providerLabel:e?Jv(H0(e)):"Agent"}):g.jsxs("div",{className:"grid min-w-0 gap-4",children:[g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&g.jsx(YN,{checked:r==="json",label:"聊天",icon:g.jsx(Px,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(YN,{checked:r==="pty",label:"终端",icon:g.jsx(Lx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[g.jsx(ew,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(ew,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(ew,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(Ct,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(Ct,{type:"button",variant:h?"destructive":"default",disabled:s,onClick:()=>{if(y&&!h){p(!0);return}d()},"data-slot":h?"bypass-permission-confirm":void 0,children:s?"恢复中...":h?"确认":"恢复"})]});return v?g.jsx(Ec,{open:t,onOpenChange:o,children:g.jsxs(Cc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(kc,{className:"min-w-0",children:[g.jsx(hl,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(hc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),_,g.jsx(Zu,{children:w})]})}):g.jsx(Xv,{open:t,onOpenChange:o,children:g.jsxs(Zv,{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:[g.jsxs(D1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Qv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(Lie,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),g.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:_}),g.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:g.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function YN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:We("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,g.jsx("span",{className:"min-w-0 text-center",children:t}),g.jsx(ra,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function ew({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:We("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:[g.jsx("span",{className:We("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&&g.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:We("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),g.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&g.jsx(ra,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Xie({...e}){return g.jsx(Yre,{"data-slot":"select",...e})}function Zie({...e}){return g.jsx(Gre,{"data-slot":"select-value",...e})}function Qie({className:e,size:t="default",children:n,...r}){return g.jsxs(Kre,{"data-slot":"select-trigger","data-size":t,className:We("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,g.jsx(Xre,{asChild:!0,children:g.jsx(vl,{className:"size-4 opacity-50"})})]})}function Jie({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(Zre,{children:g.jsxs(Qre,{"data-slot":"select-content",className:We("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:[g.jsx(tse,{}),g.jsx(Jre,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),g.jsx(nse,{})]})})}function ese({className:e,children:t,...n}){return g.jsxs(eie,{"data-slot":"select-item",className:We("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:[g.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(nie,{children:g.jsx(ra,{className:"size-4"})})}),g.jsx(tie,{children:t})]})}function tse({className:e,...t}){return g.jsx(rie,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Mx,{className:"size-4"})})}function nse({className:e,...t}){return g.jsx(iie,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(vl,{className:"size-4"})})}function B1(e){return!e||e.endsWith("/")?e:`${e}/`}function rse(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function ise(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function sse(e,t,n){var o;if(t==="insert")return{currentPath:ise(e)||"./",query:rse(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:B1(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 ose(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function ase(e,t){return`${B1(e)}${t.name}${t.isDir?"/":""}`}function KN(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 YB=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ai($=>$.tree),h=ai($=>$.cwd),p=ai($=>$.homePath),y=i==="insert"?h:p||h,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>sse(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,E=b.useMemo(()=>ose(y,w),[y,w]),x=_.query,k=b.useRef(new Set),[R,A]=b.useState(!1),[L,T]=b.useState(""),[H,D]=b.useState(!1);b.useEffect(()=>{if(!E||d.has(E)||k.current.has(E))return;const $=Pt;if(!$)return;let I=!1;return k.current.add(E),$.requestDirectoryList(E).then(Y=>{I||ai.getState().setDirEntries(Y.path,Y.entries)}).catch(()=>{I||ai.getState().setDirEntries(E,[])}).finally(()=>{k.current.delete(E)}),()=>{I=!0}},[E,d]);const U=!d.has(E),W=b.useMemo(()=>{let $=d.get(E)??[];return o&&($=$.filter(I=>I.isDir)),x&&($=$.filter(I=>I.name.toLowerCase().includes(x))),$},[d,E,x,o]),[F,O]=b.useState(0);b.useEffect(()=>O(0),[w,x]),b.useEffect(()=>{A(!1),T("")},[E]),b.useEffect(()=>{F>=W.length&&W.length>0&&O(W.length-1)},[W.length,F]);const M=b.useRef(null),z=b.useRef(!1);b.useEffect(()=>{var I;if(!z.current)return;z.current=!1;const $=(I=M.current)==null?void 0:I.querySelector(`[data-entry-index="${F}"]`);$==null||$.scrollIntoView({block:"nearest"})},[F]);const P=b.useCallback($=>{const I=ase(w,$);return i==="insert"?I.replace(/^\.\//,""):I},[w,i]);async function N(){const $=KN(E,L);if(!(!$||!r)){D(!0);try{const I=await r($);if(!I)return;T(""),A(!1),n(B1(I))}finally{D(!1)}}}b.useImperativeHandle(u,()=>({handleKey($){return W.length===0?!1:$.key==="ArrowDown"?(z.current=!0,O(I=>Math.min(W.length-1,I+1)),!0):$.key==="ArrowUp"?(z.current=!0,O(I=>Math.max(0,I-1)),!0):$.key==="Enter"&&!$.nativeEvent.isComposing?(n(P(W[F])),!0):!1}}),[W,F,P,n]);const q=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",V=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 g.jsxs("div",{className:q,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?g.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?g.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:!E||H,onClick:()=>A($=>!$),children:"新建目录"}):null]}),R?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:L,onChange:$=>T($.target.value),onKeyDown:$=>{$.key==="Enter"&&!$.nativeEvent.isComposing&&($.preventDefault(),N()),$.key==="Escape"&&(A(!1),T(""))},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}),g.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:!KN(E,L)||H,onClick:()=>void N(),children:H?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:V,children:W.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:U?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:W.map(($,I)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(P($)),onMouseEnter:()=>O(I),className:We("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",I===F&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",$.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":$.isDir?"dir":"file","data-entry-index":I,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[$.name,$.isDir?"/":""]})})},$.name))})})]})}),GN="工作目录不存在或不可访问:",lse=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],KB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function cse(e,t){return t!==ei.PATH_NOT_FOUND||!e.startsWith(GN)?null:e.slice(GN.length).trim()||null}function Qg(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function use(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function dse(e,t){return e!=="codex"||KB.some(n=>n.value===t)?t:"default"}async function hse({relay:e,agentCli:t,form:n,timeoutMs:r=Xx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Qg(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?`${na[n.provider]} 不可用:${p}`:`${na[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=cse(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,v=((h=p.name)==null?void 0:h.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 fse({relay:e,timeoutMs:t=Xx}){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 pse({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Qg("claude",e),y=Qg("codex",e),v=e==null?void 0:e[t];return g.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[g.jsxs("div",{className:"flex items-center justify-between",children:[g.jsx("span",{className:"text-sm",children:"Agent CLI"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsx(XN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(XN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),g.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?g.jsx(mse,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(gse,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function XN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Vf,{children:[g.jsx(Yf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:We("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:[g.jsx("span",{className:"text-sm font-medium",children:na[e]}),g.jsx("span",{className:We("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(Kf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:use(e,n)})})]})}function mse({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[g.jsxs("label",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:"sr-only",children:"CLI 路径"}),g.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),o()),l.key==="Escape"&&(l.preventDefault(),s())},placeholder:e==="claude"?"/path/to/claude":"/path/to/codex",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"}),g.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>g.jsx("option",{value:l},l))})]}),g.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[g.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:"取消"}),g.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 gse({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[g.jsx("p",{className:We("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)??"等待检测结果"}),g.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:"指定路径"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),g.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:g.jsx(a7,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:We("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 jh({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[h,p]=b.useState("default"),[y,v]=b.useState(!1),[_,w]=b.useState(!1),[E,x]=b.useState(null),[k,R]=b.useState(!1),[A,L]=b.useState(null),[T,H]=b.useState(""),[D,U]=b.useState(!1),W=b.useRef(null),F=b.useRef(e);F.current=e;const O=Qs(),M=ai(Ee=>Ee.homePath),z=ai(Ee=>Ee.agentCli),P=fl("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&z)return;const Ee=Pt==null?void 0:Pt.requestProxyInfo();Ee&&Ee.then(Me=>{const Ie=ai.getState();Ie.setHomePath(Me.homePath),Ie.setAgentCli(Me.agentCli)}).catch(Me=>{console.error("[create-session-dialog] requestProxyInfo failed",Me)})},[e,M,z]),b.useEffect(()=>{if(!k)return;function Ee(Me){var Ye;const Ie=Me.target;Ie instanceof Node&&((Ye=W.current)!=null&&Ye.contains(Ie))||window.setTimeout(()=>R(!1),0)}return document.addEventListener("pointerdown",Ee,!0),()=>document.removeEventListener("pointerdown",Ee,!0)},[k]);function N(){r(""),s(""),R(!1),l("claude"),d("pty"),p("default"),v(!1),x(null),L(null),H(""),U(!1)}function q(){if(h==="bypassPermissions"){v(!0);return}j()}async function V(){await j(),F.current&&v(!1)}const $=o==="codex"?KB:lse,I=Qg(o,z),Y=_||D||I.disabled;function G(Ee){const Me=dse(Ee,h);Me!==h&&p(Me)}async function j(Ee){x(null),w(!0);try{const Me=await hse({relay:Pt,agentCli:z,form:{cwd:Ee??i,name:n,provider:o,permissionMode:h,mode:u}});if(Me.type==="success"){if($t.getState().addSession(Me.session),!F.current)return;t(!1),N(),O(Me.route);return}if(Me.type==="missing_cwd"&&x(Me.path),tt.error(Me.message),Me.type==="validation_error"||Me.type==="relay_missing")return}finally{w(!1)}}async function ee(Ee){const Me=Pt;if(!Me)return tt.error("请先连接开发机"),null;try{const Ie=await Me.createDirectory(Ee);return Ie.success?(s(Ie.path),x(null),tt.success("目录已创建"),Ie.path):(tt.error(`目录创建失败:${Ie.error??"未知错误"}`),null)}catch(Ie){return tt.error(Ie instanceof Error?Ie.message:String(Ie)),null}}function J(Ee){var Ie;const Me=z==null?void 0:z[Ee];L(Ee),H((Me==null?void 0:Me.command)??((Ie=Me==null?void 0:Me.suggestions)==null?void 0:Ie[0])??"")}async function te(){if(!A)return;const Ee=T.trim();if(!Ee){tt.error("请输入 Agent CLI 路径");return}const Me=Pt;if(!Me){tt.error("请先连接开发机");return}U(!0);try{const Ie=await Me.updateAgentCliPath(A,Ee);if(Ie.error||!Ie.agentCli){tt.error(`路径保存失败:${Ie.error??"未知错误"}`);return}ai.getState().setAgentCli(Ie.agentCli),tt.success(`${na[A]} 路径已保存`),L(null),H("")}catch(Ie){tt.error(Ie instanceof Error?Ie.message:String(Ie))}finally{U(!1)}}function Q(Ee){d(Ee),G(o)}function fe(Ee){var Ie;const Me=Ee.relatedTarget;Me instanceof Node&&((Ie=W.current)!=null&&Ie.contains(Me))||window.setTimeout(()=>R(!1),0)}const ce=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(WB,{providerLabel:na[o]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),g.jsx(Ct,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void V(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):g.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Ee=>{Ee.preventDefault(),q()},children:[g.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[g.jsx("span",{className:"text-sm",children:"名称(可选)"}),g.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Ee=>r(Ee.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:"自动生成"})]}),g.jsxs("div",{ref:W,className:"relative flex min-w-0 flex-col gap-2",onBlur:fe,children:[g.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),g.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:()=>R(!0),onChange:Ee=>{s(Ee.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?g.jsx(YB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ee,onSelect:Ee=>{s(Ee),x(null),R(!0)}}):null]}),E?g.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[g.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),g.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:E})]}):null,g.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"交互方式"}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>Q("pty"),className:We("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:[g.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),g.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>Q("json"),className:We("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:[g.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),g.jsx(pse,{agentCli:z,provider:o,isDesktop:P,editingCliProvider:A,cliPathInput:T,savingCliPath:D,onProviderChange:Ee=>{l(Ee),G(Ee)},onOpenCliPathEditor:J,onCliPathInputChange:H,onCancelCliPathEditor:()=>{L(null),H("")},onSaveCliPath:()=>void te()}),g.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"权限模式"}),g.jsxs(Xie,{value:h,onValueChange:Ee=>p(Ee),children:[g.jsx(Qie,{className:"w-full",children:g.jsx(Zie,{})}),g.jsx(Jie,{children:$.map(Ee=>g.jsx(ese,{value:Ee.value,children:Ee.label},Ee.value))})]})]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),g.jsx(Ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return P?g.jsx(Ec,{open:e,onOpenChange:t,children:g.jsxs(Cc,{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:[g.jsx(kc,{children:g.jsx(hl,{children:y?"跳过全部审批?":"新建会话"})}),ce]})}):g.jsx(Xv,{open:e,onOpenChange:t,children:g.jsxs(Zv,{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:[g.jsx(D1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Qv,{children:y?"跳过全部审批?":"新建会话"})}),ce]})})}function Fh({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),[h,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 g.jsx(Ec,{open:e,onOpenChange:r,children:g.jsx(Cc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:g.jsxs("form",{className:"grid gap-4",onSubmit:v=>void y(v),children:[g.jsxs(kc,{children:[g.jsx(hl,{children:"重命名会话"}),g.jsx(hc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),g.jsxs("div",{className:"grid gap-2",children:[g.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),g.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:We("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:h,onChange:v=>{l(v.target.value),u&&d(null)}}),u?g.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(Ct,{type:"submit",disabled:h,children:"保存"})]})]})})})}function vse(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function yse(e){return(e==null?void 0:e.kind)==="terminal"}function bse(e){return vse(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:yse(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function $m({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=bse(t);function s(){t&&(r(t),n(!1))}return g.jsx(Ec,{open:e,onOpenChange:n,children:g.jsxs(Cc,{"data-slot":"session-termination-dialog",children:[g.jsxs(kc,{children:[g.jsx(hl,{children:i.title}),g.jsx(hc,{children:i.description})]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(Ct,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function GB(e){var t,n,r,i,s,o,l,u,d,h,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"||((h=e.agentStatus)==null?void 0:h.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function _se(e){if(e.session.state==="error")return"error";const t=GB(e);return t==="disconnected"?e.session.state:t}function XB({layout:e}){const t=$t(ee=>ee.sessions),n=$t(ee=>ee.sessionListLoaded),r=$t(ee=>ee.agentStatusBySessionId),i=$t(ee=>ee.ptyStateBySessionId),s=$t(ee=>ee.renameSession),o=Xt(ee=>ee.bySessionId),l=kU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Oe(ee=>!!ee.selectedProxyId),h=Oe(ee=>ee.proxyListLoaded),p=Oe(ee=>ee.proxySwitchTarget),y=$t(ee=>ee.loadingProxyName),v=p!==null||!h||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",E=Qs(),[x,k]=b.useState(!1),[R,A]=b.useState(!1),[L,T]=b.useState(null),[H,D]=b.useState(null),{creatingTerminal:U,createTerminal:W}=ZB(),[F,O]=b.useState(new Set),[M,z]=b.useState(()=>Date.now());b.useEffect(()=>{const ee=setInterval(()=>z(Date.now()),6e4);return()=>clearInterval(ee)},[]);function P(ee,J){E(`/chat/${ee}?mode=${J??"json"}`,{replace:!1})}function N(ee){const J=ee.sessionId,te=Pt;if(!te){tt.error("请先连接开发机");return}te.sendControl({type:"session_terminate",sessionId:J}),$t.getState().removeSession(J),Xt.getState().clearSession(J),J===u&&E("/sessions"),(ee==null?void 0:ee.mode)==="pty"&&ee.ptyOwner==="local-terminal"?tt.info("已断开页面连接,本地终端仍在运行"):tt.info("正在终止会话",{duration:1500})}async function q(ee,J){const te=Pt;if(!te)throw new Error("请先连接开发机");const Q=await te.renameSession(ee,J);if(!Q.success)throw new Error(Q.error??"重命名失败");s(ee,Q.name??J),tt.success("已重命名会话")}function V(ee){O(J=>{const te=new Set(J);return te.has(ee)?te.delete(ee):te.add(ee),te})}function $(ee){var Q;const J=ee.mode==="json"&&(((Q=o[ee.sessionId])==null?void 0:Q.pendingApprovals.some(fe=>fe.status==="pending"))??!1),te=_se({session:ee,agentStatus:r[ee.sessionId],ptyState:i[ee.sessionId],hasPendingApproval:J});return te===ee.state?ee:{...ee,state:te}}const I=t.length>0;if(e==="sidebar"&&(v||!d))return g.jsxs(g.Fragment,{children:[g.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:"请先连接开发机"}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]});if(e==="page"&&v)return g.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:[g.jsx(sl,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsx("div",{className:"flex-1",children:g.jsx(rc,{variant:"no-proxy"})}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]});const Y=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",I?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),G=I?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:wse(t).map(ee=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>V(ee.provider),"aria-expanded":!F.has(ee.provider),className:We("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:[g.jsx("span",{className:"font-mono",children:Sse(ee.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:ee.sessions.length}),g.jsx(Qh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(ee.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(ee.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:ee.sessions.map(J=>g.jsx(Fie,{session:$(J),selected:J.sessionId===u,now:M,onClick:()=>P(J.sessionId,J.mode),onRename:()=>T(J),onTerminate:()=>D(J)},J.sessionId))})]},ee.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),j=g.jsx(Yie,{now:M});return e==="page"?g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,G,j]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(Ct,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[g.jsx(ID,{"aria-hidden":"true"}),"新建"]})}),g.jsx(Ese,{open:R,creatingTerminal:U,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>void W(()=>A(!1))}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,G,j]}),g.jsx(jh,{open:x,onOpenChange:k}),g.jsx($m,{open:H!==null,session:H,onOpenChange:ee=>{ee||D(null)},onConfirm:N}),g.jsx(Fh,{open:L!==null,sessionId:(L==null?void 0:L.sessionId)??null,initialName:L==null?void 0:L.name,onOpenChange:ee=>{ee||T(null)},onRename:q})]})}function wse(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])=>xse(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Sse(e){return e==="terminal"?"终端":Jv(e)}function xse(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:HB(e,t)}function ZB(){const e=Qs(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await fse({relay:Pt});if(s.type!=="success"){tt.error(s.message);return}$t.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function ZN({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Oe(x=>!!x.selectedProxyId),l=Oe(x=>x.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:h}=ZB();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,h()}function _(x){x.preventDefault(),p()}const w=g.jsxs(Ct,{variant:"outline","data-slot":"create-session-trigger",className:We(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:[g.jsx(ID,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),E=u?g.jsxs(L1,{children:[g.jsx(I1,{asChild:!0,children:w}),g.jsxs(z1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:x=>{s.current&&(s.current=!1,x.preventDefault())},children:[g.jsxs(_o,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[g.jsx(LD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(_o,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[g.jsx(uf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return g.jsxs(g.Fragment,{children:[u?E:g.jsxs(Vf,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[g.jsx(Yf,{asChild:!0,children:E}),g.jsx(Kf,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),g.jsx(jh,{open:t,onOpenChange:n})]})}function Ese({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=b.useRef(!1);function o(l){s.current=!0,l()}return g.jsx(Xv,{open:e,onOpenChange:n,children:g.jsxs(Zv,{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:[g.jsx(D1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Qv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.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:[g.jsx(LD,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.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:[g.jsx(uf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Cse="0.5.31",kse={version:Cse},Tse={playback:"playback",capture:"play-and-record"};function Rse(){return typeof navigator>"u"?null:navigator.audioSession??null}function Ase(){return{setMode:()=>{},release:()=>{}}}class Nse{constructor(t=Rse){bt(this,"leases",new Map);bt(this,"session",null);bt(this,"baselineType",null);bt(this,"nextLeaseId",1);bt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Ase();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(Tse[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 j1=new Nse,V0=64,QN=-60,QB=32;function JN(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-QN)/-QN));return e<0?-r:r}function eM(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,h=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),h=Math.max(h,y)}s.push({min:d,max:h})}return s}function Mse(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 Ose(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 JB{constructor(t,n=24e3,r={}){bt(this,"nextStartTime",0);bt(this,"activityEndToken",0);bt(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=Mse(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*QB/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,h=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),y=Ose(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,E;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(E=(w=this.options).onPlaybackChunk)==null||E.call(w,p)},h)}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 tw={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},tM="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",Pse=800,nM=300,Dse=1600;function Y0(e,t){return e.filter(n=>!n.model||n.model===t)}function rM({label:e,children:t,help:n}){return g.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:[g.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.jsx("div",{className:"mt-2 min-w-0",children:t}),n?g.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Hm({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),h=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!e3(h).detail;return g.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:[g.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.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:[g.jsx(iM,{label:h,muted:!d&&!t}),g.jsx(vl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?g.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 g.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:[g.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?g.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(iM,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function iM({label:e,muted:t=!1}){const n=e3(e);return g.jsxs("span",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?g.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Lse({scrollRef:e}={}){const[t,n]=b.useState(tw),[r,i]=b.useState(String(tw.turnIdleSeconds)),[s,o]=b.useState(()=>Am()),[l,u]=b.useState(""),[d,h]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),E=b.useRef(null),x=b.useRef(null),k=b.useRef(null),R=b.useRef(null);b.useEffect(()=>{const te=Pt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let Q=!1;return _({kind:"loading"}),te.requestVoiceConfig().then(fe=>{if(!Q){if(fe.error||!fe.config){_({kind:"error",message:fe.error??"读取语音设置失败"});return}n(fe.config),i(String(fe.config.turnIdleSeconds)),u(""),h(!1),y(!0),_({kind:"idle"})}}).catch(fe=>{Q||_({kind:"error",message:fe instanceof Error?fe.message:"读取语音设置失败"})}),()=>{Q=!0}},[]),b.useEffect(()=>{const te=Pt;if(!te||!p)return;let Q=!1;return te.requestVoiceCapabilities({region:t.region}).then(fe=>{if(!Q){if(fe.error||!fe.capabilities){o(Am());return}o(fe.capabilities)}}).catch(()=>{Q||o(Am())}),()=>{Q=!0}},[t.region,p]),b.useEffect(()=>()=>{G(),j()},[]);const A=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]),L=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",T=b.useMemo(()=>Y0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),D=T.some(te=>te.value===t.ttsVoice)?t.ttsVoice:"",U=T.length===0?"当前模型暂无可用音色":D?null:"请选择可用音色",W=b.useMemo(()=>jse(r),[r]),F=W?null:"请输入正整数秒数",O=U??F,M=L||!!O,z=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>aM(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),N=b.useMemo(()=>Fse(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),q=b.useMemo(()=>aM(T,D),[T,D]);function V(){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:W??tw.turnIdleSeconds}}async function $(){if(L)return;if(O){_({kind:"error",message:O});return}const te=Pt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}const Q=V();j(),_({kind:"saving"});const fe=performance.now();try{const ce=await te.updateVoiceConfig(Q),Ee=performance.now()-fe;if(Ee<nM&&await Bse(nM-Ee),!ce.success||ce.error||!ce.config){_({kind:"error",message:ce.error??"保存语音设置失败"});return}n(ce.config),i(String(ce.config.turnIdleSeconds)),u(""),h(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(Me=>Me.kind==="saved"?{kind:"idle"}:Me)},Dse),te.requestVoiceCapabilities({region:ce.config.region}).then(Me=>{Me.capabilities&&o(Me.capabilities)}).catch(()=>{o(Am())})}catch(ce){_({kind:"error",message:ce instanceof Error?ce.message:"保存语音设置失败"})}}async function I(){if(L)return;if(O){_({kind:"error",message:O});return}const te=Pt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let Q;try{Q=Y()}catch(fe){_({kind:"error",message:oM(fe)});return}_({kind:"testing"});try{const[fe]=await Promise.all([te.testVoiceConfig(V()),Q.ready]);if(!fe.success||fe.error){G(),_({kind:"error",message:fe.error??"语音配置测试失败"});return}const ce=await ee(fe,Q.context);_({kind:"playingTest",transcript:fe.transcript}),k.current=setTimeout(()=>{k.current=null,G(),_({kind:"testPassed",transcript:fe.transcript})},ce)}catch(fe){G(),_({kind:"error",message:oM(fe)})}}function Y(){G();const te=j1.acquire("playback");E.current=te;try{const Q=zse();return w.current=Q,{context:Q,ready:sM(Q)}}catch(Q){throw te.release(),E.current=null,Q}}function G(){var te,Q,fe;k.current&&(clearTimeout(k.current),k.current=null),(te=x.current)==null||te.stop(),x.current=null,(Q=w.current)==null||Q.close(),w.current=null,(fe=E.current)==null||fe.release(),E.current=null}function j(){R.current&&(clearTimeout(R.current),R.current=null)}async function ee(te,Q){if(!te.audioBase64)throw new Error("语音测试未返回可播放音频");if(te.audioEncoding&&te.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const fe=te.audioSampleRate??24e3,ce=Ise(te.audioBase64);if(ce.byteLength===0||ce.byteLength%2!==0)throw new Error("测试音频数据无效");await sM(Q);const Ee=new JB(Q,fe);x.current=Ee,Ee.enqueue(ce);const Me=Math.ceil(ce.byteLength/2/fe*1e3);return Math.max(Pse,Me)}function J(te){var Q;return((Q=Y0(s.ttsVoices,te)[0])==null?void 0:Q.value)??""}return g.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:te=>{te.preventDefault(),$()},children:[g.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:g.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:g.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[g.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),g.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),g.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"})]})}),g.jsx(rM,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:g.jsxs("div",{className:"flex min-w-0 gap-2",children:[g.jsxs("div",{className:"relative min-w-0 flex-1",children:[g.jsx(jD,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),g.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:te=>{u(te.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${tM} w-full pl-9`})]}),t.configured&&g.jsxs(Ct,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),h(!0)},children:[g.jsx(N7,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(Hm,{label:"地域",value:t.region,options:z,onChange:te=>n(Q=>({...Q,region:te==="intl"?"intl":"cn"}))}),g.jsx(Hm,{label:"语音识别模型",value:t.asrModel,options:P,onChange:te=>n(Q=>({...Q,asrModel:te}))}),g.jsx(Hm,{label:"语音合成模型",value:t.ttsModel,options:N,onChange:te=>n(Q=>({...Q,ttsModel:te,ttsVoice:J(te)}))}),g.jsx(Hm,{label:"语音音色",value:D,options:q,placeholder:T.length===0?"暂无可用音色":"请选择音色",onChange:te=>n(Q=>({...Q,ttsVoice:te})),help:U}),g.jsx(rM,{label:"结束停顿时间(秒)",help:F,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:te=>i(te.target.value),className:`${tM} w-full`})})]})})}),g.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[g.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),g.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[A?g.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:A}):null,g.jsxs(Ct,{type:"button",variant:"outline",disabled:M,onClick:()=>void I(),children:[g.jsx(HD,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(Ct,{type:"submit",disabled:M,children:[g.jsx(v7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Ise(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 zse(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function sM(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function oM(e){return e instanceof Error?e.message:"语音配置测试失败"}function Bse(e){return new Promise(t=>setTimeout(t,e))}function jse(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function aM(e,t){const n=e.map(r=>({value:r.value,label:t3(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Fse(e,t,n){const r=e.map(i=>{const s=Y0(t,i.value).length===0;return{value:i.value,label:`${t3(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function e3(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 t3(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 $se=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Hse=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],F1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function n3(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 Use(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Wse(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function qse(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function K0({open:e,onOpenChange:t}){const n=Oe(U=>U.relayUrl),r=Oe(U=>U.latencyMonitorEnabled),i=Oe(U=>U.setLatencyMonitorEnabled),s=Oe(U=>U.sessionIdleNotificationsEnabled),o=Oe(U=>U.setSessionIdleNotificationsEnabled),l=Oe(U=>U.inputModePreference),u=Oe(U=>U.setInputModePreference),d=Oe(U=>U.themePreference),h=Oe(U=>U.setThemePreference),p=Oe(U=>U.ptyScrollTraceEnabled),y=Oe(U=>U.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,E]=b.useState({kind:"idle"}),x=b.useRef(null),k=b.useRef(null),R=BQ(),A=b.useMemo(()=>kv().osName==="iPad",[]),L=b.useCallback(async U=>{if(!U){o(!1);return}const W=await fQ();if(W==="granted"){o(!0);return}if(W==="denied"){tt.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(W==="default"){tt.info("未授予通知权限,会话通知保持关闭");return}tt.error("当前浏览器不支持系统通知")},[o]),T=b.useCallback(async U=>{E({kind:"loading"});try{const W=await fetch(Use(n),{cache:"no-store",signal:U});if(!W.ok)throw new Error(`HTTP ${W.status}`);const F=await W.json();if(F.status!=="ok")throw new Error("状态异常");E({kind:"ready",version:F.version??"未知",uptime:F.uptime??0})}catch(W){if(W instanceof DOMException&&W.name==="AbortError")return;E({kind:"error",message:W instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const U=new AbortController;return T(U.signal),()=>U.abort()},[T,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const U=window.requestAnimationFrame(()=>{var W;(W=x.current)==null||W.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(U)},[e,v]);const H=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",D=w.kind==="ready"?`运行 ${n3(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(Ec,{open:e,onOpenChange:t,children:g.jsxs(Cc,{className:We("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:[g.jsx(kc,{className:We(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"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-start gap-2",children:[g.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:g.jsx(wv,{className:"size-4","aria-hidden":"true"})}),g.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[g.jsx(hl,{children:Wse(v)}),g.jsx(hc,{className:"max-w-[28rem] leading-5",children:qse(v)})]})]}),v==="voice"?g.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):g.jsxs(g.Fragment,{children:[g.jsx(hl,{children:"设置"}),g.jsx(hc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(Vse,{relayVersion:H,relayDetail:D,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(Kse,{saved:R}):v==="clients"?g.jsx(Jse,{}):v==="voice"?g.jsx(Lse,{scrollRef:k}):g.jsx(Yse,{relayTokenSaved:R,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:L,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function Vse({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:F1,"data-slot":"settings-dialog-body",children:[g.jsx(cM,{icon:g.jsx($D,{className:"size-4","aria-hidden":"true"}),label:"Web",value:kse.version,detail:"当前浏览器加载的版本"}),g.jsx(cM,{icon:g.jsx(UD,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Yse({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:h,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:v,onOpenClients:_,onOpenVersion:w}){return g.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:[g.jsxs(hu,{title:"服务",children:[g.jsx(Um,{icon:g.jsx(e9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx(Um,{icon:g.jsx(jD,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx(Um,{icon:g.jsx(z7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),g.jsx(hu,{title:"外观",children:g.jsx(lM,{icon:g.jsx(T7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:$se,onValueChange:n})}),g.jsx(hu,{title:"通知",children:g.jsx(rw,{icon:g.jsx(n9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(hu,{title:"交互",children:g.jsx(lM,{icon:g.jsx(FD,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Hse,onValueChange:i})}):null,g.jsxs(hu,{title:"高级诊断",children:[g.jsx(rw,{icon:g.jsx(uf,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(rw,{icon:g.jsx(PD,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(hu,{title:"关于",children:g.jsx(Um,{icon:g.jsx(UD,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function hu({title:e,children:t}){return g.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[g.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),g.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function lM({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return g.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,g.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 g.jsx("button",{type:"button",role:"radio","aria-checked":d,className:We("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 Kse({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{aI().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}if(!sI(h)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),tt.error(p);return}o(null),tt.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{oI(),l()};return g.jsxs("form",{className:F1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[g.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[g.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),g.jsx("input",{id:t,type:"password",value:r,onChange:h=>{i(h.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?g.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),g.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?g.jsx(Ct,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(Ct,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Gse(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Xse(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Gse(e)}function Zse(e){return VX(e)}function Qse(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return n3(t)}function nw({label:e,value:t,title:n}){return g.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[g.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),g.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function Jse(){const e=Oe(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]),h=b.useCallback(async()=>{const y=Pt;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(()=>{h()},[h]);const p=b.useCallback(async y=>{const v=Pt;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(E=>E.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:F1,"data-slot":"settings-dialog-body",children:[g.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),g.jsx(Ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Dx,{className:We("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?g.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?g.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 g.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:g.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[g.jsxs("div",{className:"min-w-0 space-y-1.5",children:[g.jsx("div",{className:"min-w-0",children:g.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Zse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(nw,{label:"已连接",value:Qse(y.connectedAt)}),y.proxyId?g.jsx(nw,{label:"连接到",value:Xse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(nw,{label:"来源 IP",value:y.remoteAddress}):null]})]}),v?g.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:"当前设备"}):g.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:[g.jsx(Y9,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function rw({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return g.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:[g.jsx("div",{className:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),g.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),g.jsx("span",{className:We("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:g.jsx("span",{className:We("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 Um({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return g.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:[g.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}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),g.jsx(Qh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function cM({icon:e,label:t,value:n,detail:r,muted:i=!1}){return g.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[g.jsx("div",{className:We("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}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[g.jsx("div",{className:"text-sm text-muted-foreground",children:t}),g.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const eoe="xterm-helper-textarea";function toe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(eoe)?!1:(e.blur(),!0)}function uM(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&&noe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function noe(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 roe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&toe()},[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 h=(n.current??u.clientY)-u.clientY;n.current=u.clientY,uM(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(uM(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function ioe({className:e}){const t=Oe(o=>o.sidebarCollapsed),n=Oe(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=roe();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("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:[g.jsx(hM,{collapsed:!0,onClick:n}),g.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),g.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[g.jsx(dM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(ZN,{compact:!0})]})]}),g.jsx(K0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("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:[g.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:g.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx(lL,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(hM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx($B,{layout:"dropdown",variant:"sidebarChrome"})})]})}),g.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:g.jsx("div",{className:"flex-1 min-h-0",children:g.jsx(XB,{layout:"sidebar"})})}),g.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:[g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(ZN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(dM,{onClick:()=>i(!0)})})]})]}),g.jsx(K0,{open:r,onOpenChange:i})]})}function dM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Vf,{delayDuration:500,children:[g.jsx(Yf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("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:[g.jsx(WD,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(Kf,{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 hM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?r7:t7;return g.jsxs(Vf,{delayDuration:500,children:[g.jsx(Yf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("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:g.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(Kf,{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 soe=1500,ooe=300,fM=70,pM=35;function r3({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 h=setInterval(()=>s(p=>!p),530);return()=>clearInterval(h)},[]),b.useEffect(()=>{let h;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)),h=setTimeout(y,fM)):(o.current="paused",h=setTimeout(y,soe))}else v==="paused"?(o.current="deleting",h=setTimeout(y,pM)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),h=setTimeout(y,pM)):(u.current+=1,o.current="waiting",h=setTimeout(y,ooe)):(o.current="typing",h=setTimeout(y,fM))};return h=setTimeout(y,500),()=>clearTimeout(h)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return g.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[g.jsx("span",{className:"text-green-500",children:"> "}),g.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),g.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),g.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const i3=["DEV Anywhere","/unlimited @anytime"];function aoe({subtitle:e,action:t}){return g.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:g.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[g.jsx(r3,{texts:i3,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),g.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?g.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const loe=3e3,coe=1e4,Wm=12,uoe=4,mM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},doe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function iw(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 fu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function $h(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function gM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function s3(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function hoe(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 foe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?$h(e.rttMs):"等待检测"}function poe(){const e=Ei("local",cn.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 vM(e){gr("local",cn.latencyMonitorPosition,JSON.stringify(e))}function moe(){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 sw(e,t){const n=moe(),r=Wm,i=Wm,s=Math.max(r,n.width-t.width-Wm),o=Math.max(i,n.height-t.height-Wm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function goe(){const e=Oe(T=>T.latencyMonitorEnabled),t=Oe(T=>T.connected),n=Oe(T=>T.proxyOnline),r=Oe(T=>T.selectedProxyId),[i,s]=b.useState(doe),[o,l]=b.useState(()=>poe()),u=b.useRef(!1),d=b.useRef(null),h=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,H)=>gM(H.state)-gM(T.state))[0]??{state:"idle"}).state,[i]),v=s3(y);async function _(){if(u.current)return;const T=Pt;if(!T||!t){const W=fu("Relay 服务器未连接");s({webRelay:W,relayProxy:W,webProxy:W});return}u.current=!0,s(W=>({webRelay:{...W.webRelay,state:"measuring"},relayProxy:n?{...W.relayProxy,state:"measuring"}:fu("未连接开发机"),webProxy:n?{...W.webProxy,state:"measuring"}:fu("未连接开发机")}));const[H,D,U]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:H.status==="fulfilled"?iw(H.value):fu(H.reason instanceof Error?H.reason.message:"测速失败"),relayProxy:D.status==="fulfilled"?iw(D.value):fu(D.reason instanceof Error?D.reason.message:"测速失败"),webProxy:U.status==="fulfilled"?iw(U.value):fu(U.reason instanceof Error?U.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,H=null;const D=async()=>{await _(),!T&&(H=setTimeout(D,document.hidden?coe:loe))};return D(),()=>{T=!0,u.current=!1,H&&clearTimeout(H)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const H=T.getBoundingClientRect(),D=sw(o,{width:H.width,height:H.height});D.x===o.x&&D.y===o.y||(l(D),vM(D))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,E=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(T){var D,U;if(T.button!==0)return;const H=T.currentTarget.getBoundingClientRect();h.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:H.left,originY:H.top,width:H.width,height:H.height,dragging:!1},(U=(D=T.currentTarget).setPointerCapture)==null||U.call(D,T.pointerId)}function k(T){const H=h.current;if(!H||H.pointerId!==T.pointerId)return;const D=T.clientX-H.startX,U=T.clientY-H.startY;if(!H.dragging&&Math.hypot(D,U)<uoe)return;H.dragging=!0,T.preventDefault();const W=sw({x:H.originX+D,y:H.originY+U},{width:H.width,height:H.height});l(W)}function R(T){var F,O;const H=h.current;if(!H||H.pointerId!==T.pointerId||(h.current=null,(O=(F=T.currentTarget).releasePointerCapture)==null||O.call(F,T.pointerId),!H.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const D=T.clientX-H.startX,U=T.clientY-H.startY,W=sw({x:H.originX+D,y:H.originY+U},{width:H.width,height:H.height});l(W),vM(W)}function A(T){var D,U;const H=h.current;!H||H.pointerId!==T.pointerId||(h.current=null,(U=(D=T.currentTarget).releasePointerCapture)==null||U.call(D,T.pointerId))}function L(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:We("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",hoe(v)),style:E,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${$h(i.webRelay.rttMs)},开发机 ${$h(w.rttMs)}`,onPointerDown:x,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:L,children:[g.jsx(PD,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),g.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",$h(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",$h(w.rttMs)]}),g.jsx(vl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(P1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),g.jsx(Ct,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:g.jsx(Dx,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(mM).map(T=>g.jsx(voe,{label:mM[T],measurement:i[T]},T))})]})]})}function voe({label:e,measurement:t}){const n=s3(t.state);return g.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:[g.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:We("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"}),g.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:foe(t)})]})]})}const o3="/__dev_anywhere_debug/browser-state-dumps",yoe=1500,boe=10,ow=80,$1=500,_oe=["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"],woe=["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 yM(){if(typeof window>"u")return"off";const e=p3("debugDump");return e==="auto"?"auto":e!==null||Noe("debugInput")?"manual":"off"}function Soe(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:koe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:bM(document.activeElement),selection:Toe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>bM(i)).filter(i=>!!i),root:a3(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(()=>_M(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:pu(()=>_M(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:pu(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function xoe(e="manual"){const t=Soe(e);return Eoe(t)}async function Eoe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Coe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:o3}}catch(r){const i=m3(r),s=Roe(e.createdAt);return Aoe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Coe(e){const t=await fetch(o3,{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 a3(e,t,n){if(n.count>=yoe||t>boe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=wM(e.textContent??"");return u?{kind:"text",text:ey(u,$1)}:{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,ow))u.nodeType===Node.TEXT_NODE&&!wM(u.textContent??"")||r.push(a3(u,t+1,n));s.length>ow&&(i=s.length-ow,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:f3(e),attrs:l3(e),rect:c3(e),scroll:u3(e),style:d3(e)},l=h3(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function bM(e){if(!(e instanceof HTMLElement))return null;const t=h3(e);return{path:f3(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:l3(e),rect:c3(e),scroll:u3(e),style:d3(e),...t?{value:t}:{}}}function koe(){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 l3(e){const t={};for(const n of _oe){const r=e.getAttribute(n);r!==null&&(t[n]=ey(r,500))}return t}function c3(e){const t=e.getBoundingClientRect();return{x:Ki(t.x),y:Ki(t.y),width:Ki(t.width),height:Ki(t.height),top:Ki(t.top),right:Ki(t.right),bottom:Ki(t.bottom),left:Ki(t.left)}}function u3(e){return{top:Ki(e.scrollTop),left:Ki(e.scrollLeft),height:Ki(e.scrollHeight),width:Ki(e.scrollWidth),clientHeight:Ki(e.clientHeight),clientWidth:Ki(e.clientWidth)}}function d3(e){const t=window.getComputedStyle(e),n={};for(const r of woe)n[r]=t.getPropertyValue(r);return n}function h3(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:ey(e.value,$1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Toe(){var e;try{return ey(((e=window.getSelection())==null?void 0:e.toString())??"",$1)}catch{return null}}function f3(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 Roe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Aoe(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 Noe(e){return p3(e)!==null}function p3(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 _M(e){return e?Jg(e.slice(-200)):null}function pu(e){try{return Jg(e())}catch(t){return{error:m3(t)}}}function Jg(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(Jg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Jg(r);return t}return String(e)}function wM(e){return e.replace(/\s+/g," ").trim()}function ey(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Ki(e){return Math.round(e*100)/100}function m3(e){return e instanceof Error?e.message:String(e)}const Moe=500,Ooe=1e3,Poe=60;function Doe(){const[e,t]=b.useState(()=>yM()),[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),h=b.useRef(null);b.useEffect(()=>{const _=()=>t(yM());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 xoe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&Loe(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,R;if(e!=="auto")return;const _=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=A=>{d.current>=Poe||(_(),h.current=window.setTimeout(()=>{h.current=null;const L=Date.now(),T=Ooe-(L-u.current);if(T>0){h.current=window.setTimeout(()=>w(A),T);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${A}`)},Moe))};w("initial");const E=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=A=>w(A.type);return E.forEach(A=>window.addEventListener(A,x,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",x),(R=window.visualViewport)==null||R.addEventListener("scroll",x),()=>{var A,L;_(),E.forEach(T=>window.removeEventListener(T,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(L=window.visualViewport)==null||L.removeEventListener("scroll",x)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=Ioe(i);return g.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?g.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,g.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?g.jsx(sl,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(P9,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function Loe(e){if(e.status==="saved"){tt.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){tt.info(`诊断已下载: ${e.filename}`);return}tt.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Ioe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function zoe(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 H1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:zoe(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 h=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&h.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const v=h.indexOf(y);v>=0&&v!==h.length-1&&(h.splice(v,1),h.push(y)),u(h);return}}}if(h.push(d),i&&s.set(d.event,d),h.length>r){const p=h.splice(0,h.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(h)},getAll:l}}function Tn(e){return Math.round(e*10)/10}function Ka(e){return e.length===0?"":`${Tn(Math.min(...e))}..${Tn(Math.max(...e))}`}function Ou(e){return[...new Set(e.filter(t=>t!==void 0).map(Tn))]}function g3(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 Boe="dev_anywhere_pty_input_latency_trace",SM=80,joe=1e4,Foe=new TextDecoder;let $oe=0;const Qu=new Map,Tc=H1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Boe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Hoe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Voe)}function Uoe(e,t){if(!Tc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++$oe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Goe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Qu.get(e)??[];return s.push(i),W1(s,r),Qu.set(e,s),Gf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function xM(e,t){if(!e||!Tc.isEnabled())return;const n=performance.now(),r=Yoe(e.sessionId,e.inputId);r&&(r.sentAt=n),Gf({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 Woe(e,t,n){if(!Tc.isEnabled())return;const r=performance.now(),i=U1(e,r),s=Qoe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Zoe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Gf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:q1(i,r),details:Joe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function qoe(e,t,n=1){if(!Tc.isEnabled())return;const r=performance.now(),i=U1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Gf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:q1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Koe(e,s))}function Voe(){const e=Tc.getAll(),t=e.slice(-200),n=[...Qu.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Tn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Tn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Tn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Tn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Tn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Tn(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?"":Tn(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(`
531
531
  `)}function Gf(e){Tc.append(e)}function U1(e,t){const n=Qu.get(e)??[];return W1(n,t),Qu.set(e,n),n}function W1(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>joe;(i||s)&&e.splice(n,1)}e.length>SM&&e.splice(0,e.length-SM)}function Yoe(e,t){return(Qu.get(e)??[]).find(n=>n.inputId===t)??null}function Koe(e,t){if(!Tc.isEnabled())return;const n=performance.now(),r=U1(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)}Gf({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:q1(r,n),details:i>0?`paint=${i}`:""}),W1(r,n)}function q1(e,t){const n=e[0];return n?t-n.startedAt:null}function Goe(e){return e==="\r"||e===`
532
532
  `?"enter":e.startsWith("\x1B")?"escape":Xoe(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function Xoe(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 Zoe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function Qoe(e){try{return Foe.decode(e)}catch{return""}}function Joe(e){return e.filter(Boolean).join(" ")}function Ys(e,t){if(!e||!t)return;const n=Uoe(e,t),r=nc;if(!r){xM(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});xM(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const EM=-1;function eae({sessionId:e,enabled:t,waiting:n,approvalSeq:r,sendRawInput:i=Ys}){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=EM,i(e,"\r");return}if(s.current===EM){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function tae(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=Fx(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 nae({target:e,sendRawInput:t}){return eae({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function rae({sendRawInput:e=Ys}){const t=Oe(d=>d.connected),n=Oe(d=>d.proxyOnline),r=Oe(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=>tae({proxyId:r,session:d,ptyState:s[d.sessionId],agentStatus:o[d.sessionId],autoYesBySessionKey:l,connected:t,proxyOnline:n})).filter(d=>d!==null);return g.jsx(g.Fragment,{children:u.map(d=>g.jsx(nae,{target:d,sendRawInput:e},d.key))})}function iae(e,t,n){const r=e.some(s=>s.sessionId===t)?e.map(s=>s.sessionId===t?{...s,touchedAt:n.now}:s):[...e,{sessionId:t,touchedAt:n.now}];if(r.length<=n.capacity)return r;const i=r.filter(s=>s.sessionId!==n.activeSessionId).sort((s,o)=>s.touchedAt-o.touchedAt)[0];return i?r.filter(s=>s.sessionId!==i.sessionId):r.slice(-3)}var ec=function(e,t){return Number(e.toFixed(t))},sae=function(e,t){return t},Dn=function(e,t,n){n&&typeof n=="function"&&n(e,t)},oae=function(e){return-Math.cos(e*Math.PI)/2+.5},aae=function(e){return e},lae=function(e){return e*e},cae=function(e){return e*(2-e)},uae=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},dae=function(e){return e*e*e},hae=function(e){return--e*e*e+1},fae=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},pae=function(e){return e*e*e*e},mae=function(e){return 1- --e*e*e*e},gae=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},vae=function(e){return e*e*e*e*e},yae=function(e){return 1+--e*e*e*e*e},bae=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},v3={easeOut:oae,linear:aae,easeInQuad:lae,easeOutQuad:cae,easeInOutQuad:uae,easeInCubic:dae,easeOutCubic:hae,easeInOutCubic:fae,easeInQuart:pae,easeOutQuart:mae,easeInOutQuart:gae,easeInQuint:vae,easeOutQuint:yae,easeInOutQuint:bae},y3=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Vs=function(e){e.mounted&&(y3(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function b3(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Vs(e),e.animation=function(){if(!e.mounted)return y3(e.animation);var o=new Date().getTime()-i,l=o/n,u=v3[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function _ae(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function Cl(e,t,n,r){var i=_ae(t);if(!(!e.mounted||!i)){var s=e.setState,o=e.state,l=o.scale,u=o.positionX,d=o.positionY,h=t.scale-l,p=t.positionX-u,y=t.positionY-d;n===0?s(t.scale,t.positionX,t.positionY):b3(e,r,n,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+h*v,w=u+p*v,E=d+y*v;s(_,w,E)})}}function wae(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,h=i-u;return{wrapperWidth:r,wrapperHeight:i,newContentWidth:l,newDiffWidth:d,newContentHeight:u,newDiffHeight:h}}var Sae=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,h=l,p=r-i-u,y=u;return{minPositionX:d,maxPositionX:h,minPositionY:p,maxPositionY:y,scaleWidthFactor:l,scaleHeightFactor:u}},V1=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=wae(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,h=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,v=l.newDiffHeight,_=Sae(u,h,y,d,p,v,!!s),w=u>=h&&d>=p;o&&w&&!s&&(_.minPositionX=0,_.maxPositionX=0,_.minPositionY=0,_.maxPositionY=0);var E=e.setup,x=E.minPositionX,k=E.maxPositionX,R=E.minPositionY,A=E.maxPositionY;return x!=null&&(_.minPositionX=u*(1-t)+x*t),k!=null&&(_.maxPositionX=k*t),R!=null&&(_.minPositionY=d*(1-t)+R*t),A!=null&&(_.maxPositionY=A*t),_},bf=function(e,t,n,r){return r?e<t?ec(t,2):e>n?ec(n,2):ec(e,2):ec(e,2)},Ju=function(e,t){var n=V1(e,t);return e.bounds=n,n};function Xf(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,h=n.maxPositionY,p=0,y=0;o&&(p=i,y=s);var v=bf(e,l-p,d+p,r),_=bf(t,u-y,h+y,r);return{x:v,y:_}}function ty(e,t,n,r,i,s){var o=e.state,l=o.scale,u=o.positionX,d=o.positionY,h=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*h,y=d-n*h,v=Xf(p,y,i,s,0,0,null);return v}var CM=1e-7;function Zf(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,CM),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,CM)}var kM=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(h){return h instanceof Element?i==null?void 0:i.contains(h):!1}):i==null?void 0:i.contains(s),u=r&&s&&l;if(!u)return!1;var d=Qf(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},TM=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},xae=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}},Eae=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 Cae(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 h=e.bounds,p=h.maxPositionX,y=h.minPositionX,v=h.maxPositionY,_=h.minPositionY,w=n>p||n<y,E=r>v||r<_,x=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>v?d.offsetHeight:e.setup.minPositionY||0,R=ty(e,x,k,i,e.bounds,l||u),A=R.x,L=R.y;return{scale:i,positionX:w?A:n,positionY:E?L:r}}}function _3(e,t,n,r,i){var s=e.setup.limitToBounds,o=e.wrapperComponent,l=e.bounds,u=e.state,d=u.scale,h=u.positionX,p=u.positionY;if(!(o===null||l===null||t===h&&n===p)){var y=Xf(t,n,l,s,r,i,o),v=y.x,_=y.y;e.setState(d,v,_)}}var kae=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 h=t-r.x,p=n-r.y,y=o?u:h,v=l?d:p;return{x:y,y:v}},pl=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},rl;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(rl||(rl={}));var Tae=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 h=n.offsetWidth<r.offsetWidth*u||n.offsetHeight<r.offsetHeight*u;return h},Rae=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 Aae(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 RM(e,t,n,r,i,s,o,l,u,d){if(i){if(t>o&&n>o){var h=o+(e-o)*d;return h>u?u:h<o?o:h}if(t<s&&n<s){var h=s+(e-s)*d;return h<l?l:h>s?s:h}}return r?t:bf(e,s,o,i)}function Nae(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var aw=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 Mae(e,t,n){var r,i,s=Tae(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,h=u.velocityAnimation,p=h.maxStrengthMouse,y=h.maxStrengthTouch,v=h.sensitivityTouch,_=h.sensitivityMouse,w=Date.now();if(o&&l&&d){var E=Nae(d),x=(r={},r[rl.TOUCH]=v,r[rl.MOUSE]=_,r)[n],k=(i={},i[rl.TOUCH]=y,i[rl.MOUSE]=p,i)[n],R=t.x-o.x,A=t.y-o.y,L=aw(R/E,k,x),T=aw(A/E,k,x),H=w-l,D=R*R+A*A,U=aw(Math.sqrt(D)/H,k,x);e.velocity={velocityX:L,velocityY:T,total:U}}e.lastMousePosition=t,e.velocityTime=w}}function Oae(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Rae(e);if(!(!s||!t||!n||!i)){var o=t.velocityX,l=t.velocityY,u=t.total,d=n.maxPositionX,h=n.minPositionX,p=n.maxPositionY,y=n.minPositionY,v=r.limitToBounds,_=r.autoAlignment,w=r.zoomAnimation,E=r.panning,x=E.lockAxisY,k=E.lockAxisX,R=w.animationType,A=_.sizeX,L=_.sizeY,T=_.velocityAlignmentTime,H=T,D=Aae(e,u),U=Math.max(D,H),W=pl(e,A),F=pl(e,L),O=W*i.offsetWidth/100,M=F*i.offsetHeight/100,z=d+O,P=h-O,N=p+M,q=y-M,V=e.state,$=new Date().getTime();b3(e,R,U,function(I){var Y=e.state,G=Y.scale,j=Y.positionX,ee=Y.positionY,J=new Date().getTime()-$,te=J/H,Q=v3[_.animationType],fe=1-Q(Math.min(1,te)),ce=1-I,Ee=j+o*ce,Me=ee+l*ce,Ie=RM(Ee,V.positionX,j,k,v,h,d,P,z,fe),Ye=RM(Me,V.positionY,ee,x,v,y,p,q,N,fe);if(j!==Ee||ee!==Me){e.setState(G,Ie,Ye);var xt=e.props.onPanning;xt&&xt(Rn(e),{})}})}}function AM(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},Vs(e),Ju(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?Eae(e,t):xae(e,t)}function w3(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,h=s.animationType,p=o||n<i||!l&&!u;if(!p){var y=Cae(e);y&&Cl(e,y,d,h)}}function NM(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=kae(e,t,n),h=d.x,p=d.y,y=pl(e,l),v=pl(e,u);Mae(e,{x:h,y:p},r),_3(e,h,p,y,v)}}function Pae(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 h=o-d.x,p=l-d.y;if(h*h+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,E=!e.setup.limitToBounds||y<_||v<w,x=!t&&n&&n.total>.1&&E;x?Oae(e):w3(e)}}function Y1(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Zf(ec(t,2),s,o,0,!1),d=Ju(e,u),h=ty(e,n,r,u,d,l),p=h.x,y=h.y;return{scale:u,positionX:p,positionY:y}}function K1(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,h=d.disabled,p=d.animationTime,y=d.animationType,v=r>=o&&r<=l,_=h||v;if((r>=1||u)&&w3(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,E=n||i.offsetHeight/2,x=r<o?o:l,k=Y1(e,x,w,E);k&&Cl(e,k,p,y)}}var As=function(){return As=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},As.apply(this,arguments)};function MM(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 lw={scale:1,positionX:0,positionY:0},Ql={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"}},G0={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},S3=function(e){var t,n,r,i,s,o,l,u,d,h=Math.max((t=e.minScale)!==null&&t!==void 0?t:Ql.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:Ql.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:lw.scale,v=Math.min(Math.max(y,h),p),_=bf((i=e.initialPositionX)!==null&&i!==void 0?i:lw.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=bf((l=e.initialPositionY)!==null&&l!==void 0?l:lw.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}},OM=function(e){var t=As({},Ql);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Ql[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Ql[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=As(As({},Ql[r]),e[r]):u?t[r]=MM(MM([],Ql[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},x3=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,h=u.size;if(!i)throw new Error("Wrapper is not mounted");var p=d?r*Math.exp(t*n):r+t*n,y=Zf(ec(p,3),l,o,h,!1);return y};function E3(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,h=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,E=(_/2-h)/d,x=(w/2-p)/d,k=x3(e,t,n),R=Y1(e,k,E,x);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,L=A.onZoomStart,T=A.onZoom,H=A.onZoomStop,D=new MouseEvent("mousemove",{bubbles:!0}),U=Rn(e);Dn(U,D,L),Dn(U,D,T),Cl(e,R,v,i);var W=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;W&&W.setTimeout(function(){e.mounted&&Dn(Rn(e),D,H)},v)}function C3(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,h=o.centerOnInit,p=S3(e.props),y=e.state,v=y.scale,_=y.positionX,w=y.positionY;if(l){var E=p.positionX,x=p.positionY;if(h&&u){var k=G1(p.scale,l,u);E=k.positionX,x=k.positionY}var R=V1(e,p.scale),A=Xf(E,x,R,d,0,0,l),L={scale:p.scale,positionX:A.x,positionY:A.y};if(!(v===p.scale&&_===p.positionX&&w===p.positionY)){r==null||r();var T=e.props,H=T.onZoomStart,D=T.onZoom,U=T.onZoomStop,W=new MouseEvent("mousemove",{bubbles:!0}),F=Rn(e);Dn(F,W,H),Dn(F,W,D),Cl(e,L,t,n);var O=(s=(i=l.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&s!==void 0?s:typeof window<"u"?window:null;O&&O.setTimeout(function(){e.mounted&&Dn(Rn(e),W,U)},t)}}}function Dae(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 Lae(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,h=u.minScale,p=u.maxScale;if(!s||!o)return l;var y=s.getBoundingClientRect(),v=t.getBoundingClientRect(),_=Dae(t,s,o,l),w=_.x,E=_.y,x=v.width/l.scale,k=v.height/l.scale,R=s.offsetWidth/x,A=s.offsetHeight/k,L=Zf(n||Math.min(R,A),h,p,0,!1),T=(y.width-x*L)/2,H=(y.height-k*L)/2,D=(y.left-w)*L+T+r,U=(y.top-E)*L+H+i,W=V1(e,L),F=Xf(D,U,W,d,0,0,s),O=F.x,M=F.y;return{positionX:O,positionY:M,scale:L}}var Iae=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),E3(e,1,t,n,r)}},zae=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),E3(e,-1,t,n,r)}},Bae=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,h=e.wrapperComponent,p=e.contentComponent,y=e.setup.disabled;if(!(y||!h||!p)){var v={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};Cl(e,v,i,s)}}},jae=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),C3(e,t,n)}},Fae=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=G1(t||i.scale,s,o);Cl(e,l,n,r)}}},$ae=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),Vs(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=Lae(e,u,n,s,o);Cl(e,d,r,i)}}},X0=function(e){return{instance:e,state:e.state,zoomIn:Iae(e),zoomOut:zae(e),setTransform:Bae(e),resetTransform:jae(e),centerView:Fae(e),zoomToElement:$ae(e)}},Hae=function(e){return{instance:e,state:e.state}},Rn=function(e){var t={};return Object.assign(t,Hae(e)),Object.assign(t,X0(e)),t},cw=!1;function uw(){try{var e={get passive(){return cw=!0,!1}};return e}catch{return cw=!1,cw}}var qm=".".concat(G0.wrapperClass),Qf=function(e,t){return t.some(function(n){return e.matches("".concat(qm," ").concat(n,", ").concat(qm," .").concat(n,", ").concat(qm," ").concat(n," *, ").concat(qm," .").concat(n," *"))})},_f=function(e){e&&clearTimeout(e)},Uae=function(e){return Number.parseFloat(e.toFixed(8))},k3=function(e,t,n){var r=Uae(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},G1=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 Wae(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function qae(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var T3=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,h=l&&!u&&!r&&d;if(!h||i&&!t.ctrlKey||s&&t.ctrlKey)return!1;var p=Qf(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},Vae=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=T3(e,t);if(l)return!1;var u=t.target,d=Qf(u,o);if(d)return!1;var h=e.isPressingKeys(s);return!!h},Yae=function(e){return e?e.deltaY<0?1:-1:0};function Kae(e,t){var n=Yae(e),r=sae(t,n);return r}function R3(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 Gae=function(e,t,n,r,i){var s=e.state.scale,o=e.wrapperComponent,l=e.setup,u=l.maxScale,d=l.minScale,h=l.zoomAnimation,p=l.disablePadding,y=h.size,v=h.disabled;if(!o)throw new Error("Wrapper is not mounted");var _=s+t*n,w=r?!1:!v,E=Zf(_,d,u,y,w&&!p);return E},A3=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},Xae=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=Qf(o,i);return!u},Zae=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},Qae=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}},N3=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))},Jae=5,ele=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,h=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/Jae),E=n+w,x=E===1/0?0:ec(E,10);return Zf(x,o,s,h,!p&&!u)},M3=160,O3=100,tle=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(Vs(e),Dn(Rn(e),t,r),Dn(Rn(e),t,i))},nle=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,h=o.centerZoomedOut,p=o.zoomAnimation,y=o.wheel,v=o.disablePadding,_=o.smooth,w=p.size,E=p.disabled,x=y.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var k=Kae(t,null),R=_?x*Math.abs(t.deltaY):x,A=Gae(e,k,R,!t.ctrlKey);if(u!==A){var L=Ju(e,A),T=R3(t,s,u),H=E||w===0||h||v,D=d&&H,U=ty(e,T.x,T.y,A,L,D),W=U.x,F=U.y;e.previousWheelEvent=t,e.setState(A,W,F),Dn(Rn(e),t,r),Dn(Rn(e),t,i)}},rle=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;_f(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(K1(e,t.x,t.y),e.wheelAnimationTimer=null)},O3);var s=A3(e,t);s&&(_f(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Dn(Rn(e),t,r),Dn(Rn(e),t,i))},M3))},ile=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(Vs(e),Dn(Rn(e),t,r),Dn(Rn(e),t,i))},sle=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;_f(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(K1(e,t.x,t.y),e.wheelAnimationTimer=null)},O3);var s=A3(e,t);s&&(_f(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Dn(Rn(e),t,r),Dn(Rn(e),t,i))},M3))},P3=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}},ole=function(e,t){var n=N3(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=P3(t),Vs(e)},ale=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,h=l.zoomAnimation,p=l.autoAlignment,y=l.pinch,v=l.panning,_=h.disabled,w=h.size,E=y.allowPanning;if(!(r===null||!n)){var x=Qae(t,o,n);if(!(!Number.isFinite(x.x)||!Number.isFinite(x.y))){var k=N3(t),R=ele(e,k),A=P3(t),L=o/R,T=(A.x-((s==null?void 0:s.x)||0))*L,H=(A.y-((s==null?void 0:s.y)||0))*L;if(!(R===o&&T===0&&H===0)){e.pinchPreviousCenter=A;var D=Ju(e,R),U=_||w===0||d,W=u&&U,F=ty(e,x.x,x.y,R,D,W),O=F.x,M=F.y;if(e.pinchMidpoint=x,e.lastDistance=k,v.disabled||!E)e.setState(R,O,M);else{var z=p.sizeX,P=p.sizeY,N=pl(e,z,R),q=pl(e,P,R),V=O+T,$=M+H,I=Xf(V,$,D,u,N,q,i),Y=I.x,G=I.y;e.setState(R,Y,G)}}}}},lle=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,K1(e,t==null?void 0:t.x,t==null?void 0:t.y)},D3=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;_f(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,Dn(Rn(e),t,n)},r)},cle=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;Dn(Rn(e),t,r),C3(e,o,l,function(){return Dn(Rn(e),t,i)}),D3(e,t)};function ule(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function dle(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,h=n.doubleClick,p=h.disabled,y=h.mode,v=h.step,_=h.animationTime,w=h.animationType;if(!p&&!r){if(y==="reset")return cle(e,t);if(!s)return console.error("No ContentComponent found");var E=ule(y,e.state.scale),x=x3(e,E,v);if(o!==x){Dn(Rn(e),t,u);var k=R3(t,s,o),R=Y1(e,x,k.x,k.y);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");Dn(Rn(e),t,d),Cl(e,R,_,w),D3(e,t)}}}var hle=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),h=n&&u&&d&&!o;if(!h)return!1;var p=Qf(u,l);return!p},fle=(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&&Ju(n,n.state.scale),n.setup=OM(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=uw(),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=uw(),d=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,h=d==null?void 0:d.defaultView;h==null||h.removeEventListener("mousedown",n.onPanningStart,u),h==null||h.removeEventListener("mousemove",n.onPanning,u),h==null||h.removeEventListener("mouseup",n.onPanningStop,u),d==null||d.removeEventListener("mouseleave",n.clearPanning,u),h==null||h.removeEventListener("keyup",n.setKeyUnPressed,u),h==null||h.removeEventListener("keydown",n.setKeyPressed,u),h==null||h.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),Vs(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=uw();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(Rn(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(Rn(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=T3(n,r);s&&(tle(n,r),nle(n,r),rle(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=Vae(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,h=d.positionX,p=d.positionY,y=h-r.deltaX,v=p-r.deltaY,_=o?h:y,w=l?p:v,E=n.setup.autoAlignment,x=E.sizeX,k=E.sizeY,R=pl(n,x),A=pl(n,k);_===h&&w===p||(ile(n,r),_3(n,_,w,R,A),Dn(Rn(n),r,i),sle(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=kM(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(),Vs(n),AM(n,r),Dn(Rn(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=TM(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),NM(n,r.clientX,r.clientY,rl.MOUSE),Dn(Rn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(Pae(n,i),Dn(Rn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=Xae(n,r);o&&(ole(n,r),Vs(n),Dn(Rn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=Zae(n);o&&(r.preventDefault(),r.stopPropagation(),ale(n,r),Dn(Rn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(lle(n),Dn(Rn(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,Vs(n);var h=r.touches,p=h.length===1,y=h.length===2,v=kM(n,r);if(p){if(!v)return;Vs(n),AM(n,r),Dn(Rn(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=TM(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];NM(n,l.clientX,l.clientY,rl.TOUCH),Dn(Rn(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=hle(n,r);s&&dle(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=G1(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):k3(r,i,s)},this.getContext=function(){return Rn(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:Rn(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=Rn(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),Dn(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,Ju(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=Rn(n);Dn(s,void 0,n.props.onInit),Wae(n.props.ref,s)},this.props=t,this.setup=OM(this.props),this.state=S3(this.props)}return e})(),ny=Je.createContext(null),ple=function(e,t){return typeof e=="function"?e(t):e},mle=Je.forwardRef(function(e,t){var n=b.useRef(new fle(e)).current,r=ple(e.children,X0(n));return b.useImperativeHandle(t,function(){return X0(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),g.jsx(ny.Provider,As({value:n},{children:r}))});Je.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(ny);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]),g.jsx("div",As({},e,{ref:qae([n,t])}))});function gle(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 vle=`.transform-component-module_wrapper__SPB86 {
533
533
  position: relative;
@@ -664,7 +664,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
664
664
  `))return null;const n=Zge(t);return!n||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||yE(n)||n.split("/").includes("...")?null:n}function Jge(e){return e.includes("/")?!1:_E(e)}function eve(e){const t=e.split("/").pop()??e;if(/^\d+(?:\.\d+)+$/.test(t))return!1;if(e.includes("/"))return!0;const n=e.replace(Fj,""),r=n.split("/").pop()??n;return/[A-Za-z_-]/.test(r)}function tve(e){const t=Qge(e);return!t||Jge(t)||!eve(t)?null:Xge.test(t)?{kind:"image-preview",path:t}:Fj.test(t)?{kind:"file-download",path:t}:null}const nve=16,rve=24,Eh=6,ive=425,Gh=-1;function tg(e,t){return e.pointerId===t||t===Gh}function vu(e){return Math.hypot(e.lastX-e.startX,e.lastY-e.startY)}function Ri(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 sve({terminalRef:e,suppressPtyFocus:t,focusTerminal:n,onLongPressCandidateStart:r,onTap:i,isTapCandidate:s,onLongPressStart:o,onLongPressMove:l,onLongPressEnd:u}){const d=b.useRef(null),h=b.useCallback(F=>{F.longPressTimer!==null&&(window.clearTimeout(F.longPressTimer),F.longPressTimer=null)},[]),p=b.useCallback(F=>{F.longPressed||F.moved||(F.longPressed=!0,F.longPressArmed=!1,h(F),t(),o==null||o({clientX:F.startX,clientY:F.startY}))},[h,o,t]),y=b.useCallback(F=>{if(!(F.longPressed||F.longPressArmed||F.moved)){if(vu(F)>Eh){h(F),Ri("longpress:cancel-drift",{distance:vu(F),threshold:Eh});return}if(s!=null&&s({clientX:F.startX,clientY:F.startY})){F.longPressArmed=!0,h(F),Ri("longpress:arm-link",{clientX:F.startX,clientY:F.startY});return}p(F)}},[h,s,p]),v=b.useCallback(F=>{if(F.longPressDelivered||!F.longPressed||F.moved)return;F.longPressDelivered=!0;const O={clientX:F.lastX,clientY:F.lastY};window.setTimeout(()=>u==null?void 0:u(O),0)},[u]),_=b.useCallback((F,O,M,z=!1)=>{const P={pointerId:F,startX:O,startY:M,lastX:O,lastY:M,moved:!1,longPressArmed:!1,longPressed:!1,longPressDelivered:!1,touchEventStream:z,longPressTimer:null};P.longPressTimer=window.setTimeout(()=>{d.current===P&&y(P)},ive),d.current=P,Ri("start",{pointerId:F,clientX:O,clientY:M,touchEventStream:z}),r==null||r({clientX:O,clientY:M})},[y,r]),w=b.useCallback((F,O,M)=>{const z=d.current;if(!z||!tg(z,F))return!1;z.lastX=O,z.lastY=M;const P=vu(z);if(z.longPressArmed&&P>Eh&&(z.longPressArmed=!1,Ri("longpress:cancel-armed-drift",{pointerId:F,clientX:O,clientY:M,distance:P,threshold:Eh})),z.longPressed)return Ri("move",{pointerId:F,clientX:O,clientY:M,distance:P,moved:z.moved,longPressed:!0}),l==null||l({clientX:O,clientY:M}),!0;const N=O-z.startX,q=M-z.startY;return!z.moved&&P>=nve&&(z.moved=!0,h(z)),Ri("move",{pointerId:F,clientX:O,clientY:M,dx:N,dy:q,distance:P,moved:z.moved,longPressed:!1}),z.moved},[h,l]),E=b.useCallback((F,O)=>{var N;const M=d.current;if(!M||!tg(M,F))return null;O&&(M.lastX=O.clientX,M.lastY=O.clientY),d.current=null,h(M);const z=vu(M);let P;if(M.longPressArmed){if(z<=Eh)return p(M),v(M),P="longpress",Ri("finish",{pointerId:F,result:P,point:O,moved:M.moved,distance:z,longPressed:!0,longPressArmed:!0}),P;M.longPressArmed=!1}return M.longPressed?(v(M),P="longpress",Ri("finish",{pointerId:F,result:P,point:O,moved:M.moved,longPressArmed:M.longPressArmed,distance:z,longPressed:!0}),P):M.moved?O&&vu(M)<=rve&&(i!=null&&i(O))?(t(),P="link",Ri("finish",{pointerId:F,result:P,point:O,moved:!0,distance:z,longPressed:!1}),P):(t(),P="scroll",Ri("finish",{pointerId:F,result:P,point:O,moved:!0,distance:z,longPressed:!1}),P):O&&(i!=null&&i(O))?(t(),P="link",Ri("finish",{pointerId:F,result:P,point:O,moved:!1,distance:z,longPressed:!1}),P):(n?n():(N=e.current)==null||N.focus(),P="tap",Ri("finish",{pointerId:F,result:P,point:O,moved:!1,distance:z,longPressed:!1}),P)},[h,v,n,i,p,t,e]),x=b.useCallback(F=>{const O=d.current;return!O||!tg(O,F)?null:(h(O),d.current=null,O.longPressed?(v(O),Ri("cancel",{pointerId:F,result:"longpress"}),"longpress"):(O.longPressArmed&&Ri("cancel",{pointerId:F,result:"armed"}),t(),Ri("cancel",{pointerId:F,result:"scroll",moved:O.moved,distance:vu(O)}),"scroll"))},[h,v,t]),k=b.useCallback(F=>{if(F.pointerType!=="touch")return;const O=F.target;!(O instanceof Element)||!O.closest(".xterm")||(_(F.pointerId,F.clientX,F.clientY),F.stopPropagation())},[_]),R=b.useCallback(F=>{if(F.pointerType!=="touch")return;const O=w(F.pointerId,F.clientX,F.clientY),M=d.current;M&&O&&(F.stopPropagation(),M.longPressed&&F.preventDefault())},[w]),A=b.useCallback(F=>{const O=E(F.pointerId,{clientX:F.clientX,clientY:F.clientY});O&&(F.stopPropagation(),O==="link"&&F.cancelable&&F.preventDefault())},[E]),L=b.useCallback(F=>{const O=d.current;if(F.pointerType==="touch"&&O&&tg(O,F.pointerId)&&O.touchEventStream&&!O.longPressed){F.stopPropagation();return}x(F.pointerId)&&F.stopPropagation()},[x]),T=b.useCallback(F=>{const O=F.target;if(!(O instanceof Element)||!O.closest(".xterm"))return;if(d.current){d.current.touchEventStream=!0;return}const M=F.touches[0]??F.changedTouches[0];M&&_(Gh,M.clientX,M.clientY,!0)},[_]),H=b.useCallback(F=>{const O=F.touches[0]??F.changedTouches[0];if(!O)return;const M=w(Gh,O.clientX,O.clientY),z=d.current;z&&M&&z.longPressed&&(F.stopPropagation(),F.preventDefault())},[w]),D=b.useCallback(F=>{const O=F.changedTouches[0],M=d.current,z=O?{clientX:O.clientX,clientY:O.clientY}:M?{clientX:M.lastX,clientY:M.lastY}:void 0,P=E(Gh,z);(P==="longpress"||P==="link")&&(F.stopPropagation(),F.cancelable&&F.preventDefault())},[E]),U=b.useCallback(F=>{x(Gh)==="longpress"&&F.stopPropagation()},[x]),W=b.useCallback(F=>{const O=d.current;O&&(F.preventDefault(),F.stopPropagation(),y(O))},[y]);return{onPointerDownCapture:k,onPointerMoveCapture:R,onPointerUpCapture:A,onPointerCancelCapture:L,onTouchStartCapture:T,onTouchMoveCapture:H,onTouchEndCapture:D,onTouchCancelCapture:U,onContextMenuCapture:W}}function ove({terminalRef:e,containerEl:t,suppressPtyFocus:n,focusPtyInput:r,isSelectionActive:i,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:u,onLongPressMove:d,onLongPressEnd:h,onHorizontalScrollIntent:p,onSelectionAutoscroll:y,onHandleDragStart:v,onHandleDragMove:_,onHandleDragEnd:w,onHandleDragCancel:E}){const x=b.useRef(null),k=b.useRef(null),R=b.useRef(null),A=b.useRef(!1),L=b.useRef(null),T=b.useCallback(()=>{var P;(P=L.current)==null||P.call(L),L.current=null,k.current=null,R.current=null,A.current=!1,x.current!==null&&(cancelAnimationFrame(x.current),x.current=null)},[]),H=b.useCallback(()=>{var $;x.current=null;const P=k.current;if(!P||!t||!i())return;const N=t.getBoundingClientRect(),{dx:q,dy:V}=mj({pointerX:P.clientX,pointerY:P.clientY,rect:N,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:44,maxSpeedPx:18});q!==0&&(p==null||p(`selectionGestureAutoscroll dx=${Math.round(q)}`),t.scrollLeft+=q),V!==0&&(t.scrollTop+=V),(q!==0||V!==0)&&(y==null||y({scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}),($=R.current)==null||$.call(R,P)),x.current=requestAnimationFrame(H)},[t,i,p,y]),D=b.useCallback((P,N)=>{k.current=P,R.current=N,x.current===null&&(x.current=requestAnimationFrame(H))},[H]);b.useEffect(()=>T,[T]),b.useEffect(()=>{if(!t)return;const P=N=>{A.current&&N.preventDefault()};return t.addEventListener("touchmove",P,{capture:!0,passive:!1}),document.addEventListener("touchmove",P,{capture:!0,passive:!1}),()=>{t.removeEventListener("touchmove",P,{capture:!0}),document.removeEventListener("touchmove",P,{capture:!0})}},[t]);const U=b.useCallback(P=>{T(),A.current=!0,u(P)},[u,T]),W=b.useCallback(P=>{d(P),D(P,d)},[d,D]),F=b.useCallback(P=>{T(),h(P)},[h,T]),O=sve({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:U,onLongPressMove:W,onLongPressEnd:F}),M=b.useCallback((P,N)=>{N.preventDefault(),N.stopPropagation(),T(),A.current=!0,v(P);let q=()=>{};const V=Y=>{Y.cancelable&&Y.preventDefault();const G={clientX:Y.clientX,clientY:Y.clientY};_(P,G),D(G,j=>_(P,j))},$=Y=>{const G={clientX:Y.clientX,clientY:Y.clientY};q(),L.current=null,T(),w(P,G)},I=()=>{q(),L.current=null,T(),E(P)};q=()=>{window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",$),window.removeEventListener("pointercancel",I)},L.current=q,window.addEventListener("pointermove",V,{passive:!1}),window.addEventListener("pointerup",$,{once:!0}),window.addEventListener("pointercancel",I,{once:!0})},[E,w,_,v,T,D]),z=b.useCallback((P,N)=>{if(L.current||!(N.touches[0]??N.changedTouches[0]))return;N.preventDefault(),N.stopPropagation(),A.current=!0,v(P);let V=()=>{};const $=G=>{const j=G.touches[0]??G.changedTouches[0];if(!j)return;G.cancelable&&G.preventDefault();const ee={clientX:j.clientX,clientY:j.clientY};_(P,ee),D(ee,J=>_(P,J))},I=G=>{const j=G.changedTouches[0],ee=j?{clientX:j.clientX,clientY:j.clientY}:k.current;V(),L.current=null,T(),w(P,ee)},Y=()=>{V(),L.current=null,T(),E(P)};V=()=>{window.removeEventListener("touchmove",$),window.removeEventListener("touchend",I),window.removeEventListener("touchcancel",Y)},L.current=V,window.addEventListener("touchmove",$,{passive:!1}),window.addEventListener("touchend",I,{once:!0}),window.addEventListener("touchcancel",Y,{once:!0})},[E,w,_,v,T,D]);return{pointerHandlers:O,stopPtySelectionGesture:T,handlePtySelectionHandlePointerDown:M,handlePtySelectionHandleTouchStart:z}}const ave=8;function lve(e){const{sessionId:t,terminalRef:n,xtermHostRef:r,scrollControllerRef:i,containerEl:s,scrollState:o,keyboardOffset:l,ptyFontSize:u,suppressPtyFocus:d,focusPtyInput:h,onTap:p,isTapCandidate:y,onDownloadPath:v,onPreviewPath:_}=e,w=b.useRef(null),E=b.useRef(null),x=b.useRef(null),k=b.useRef(null),R=b.useRef(!1),A=b.useRef(null),L=b.useRef(null),T=b.useRef(""),H=b.useRef(null),[D,U]=b.useState(null),[W,F]=b.useState(null),[O,M]=b.useState(null),z=b.useMemo(()=>Yge(u),[u]),P=b.useCallback((ye,Pe)=>{const Ue=window.visualViewport;return jj({clientX:ye,clientY:Pe,viewportWidth:(Ue==null?void 0:Ue.width)??window.innerWidth,viewportHeight:(Ue==null?void 0:Ue.height)??window.innerHeight,viewportOffsetLeft:(Ue==null?void 0:Ue.offsetLeft)??0,viewportOffsetTop:(Ue==null?void 0:Ue.offsetTop)??0})},[]),N=b.useCallback((ye,Pe)=>{const Ue=n.current,mt=r.current;return!Ue||!mt?null:Kge({terminal:Ue,host:mt,anchor:ye,focus:Pe})},[n,r]),q=b.useCallback((ye,Pe)=>{const Ue=Pe??tve(ye);return L.current=Ue,M(Ue),Ue},[]),V=b.useCallback(ye=>{const Pe=window.visualViewport;return Gge({handles:ye,viewportWidth:(Pe==null?void 0:Pe.width)??window.innerWidth,viewportHeight:(Pe==null?void 0:Pe.height)??window.innerHeight,viewportOffsetLeft:(Pe==null?void 0:Pe.offsetLeft)??0,viewportOffsetTop:(Pe==null?void 0:Pe.offsetTop)??0})},[]),$=b.useCallback(()=>{const ye=w.current,Pe=E.current;if(!ye||!Pe){F(null);return}const Ue=N(ye,Pe);if(F(Ue),!Ue){U(null);return}U(mt=>mt&&V(Ue))},[N,V]),I=b.useCallback(()=>{var ye,Pe;(ye=H.current)==null||ye.call(H),x.current=null,k.current=null,w.current=null,E.current=null,R.current=!1,A.current=null,L.current=null,T.current="",(Pe=n.current)==null||Pe.clearSelection(),U(null),F(null),M(null)},[n]),Y=b.useCallback((ye="")=>{w.current=null,E.current=null,R.current=!1,L.current=null,T.current=ye,U(null),F(null),M(null)},[]),G=b.useCallback(({clientX:ye,clientY:Pe})=>{const Ue=n.current,mt=r.current;d({blur:!1}),k.current={clientX:ye,clientY:Pe},x.current=Ue&&mt?Kh({terminal:Ue,host:mt,clientX:ye,clientY:Pe}):null},[d,n,r]),j=b.useCallback(({clientX:ye,clientY:Pe,draggedHandle:Ue="focus"})=>{const mt=n.current,Se=r.current,Ge=w.current,ft=E.current;if(!mt||!Se||!Ge)return null;const de=Kh({terminal:mt,host:Se,clientX:ye,clientY:Pe});if(!de)return null;const Ne=Ue==="anchor"?de:Ge,Ke=Ue==="focus"?de:ft??Ge;w.current=Ne,E.current=Ke,R.current=!0;const Qe=cv({terminal:mt,anchor:Ne,focus:Ke});return T.current=(Qe==null?void 0:Qe.text)??"",q((Qe==null?void 0:Qe.text)??""),F(Qe?N(Ne,Ke):null),Qe},[N,q,n,r]),ee=b.useCallback(({point:ye,clientX:Pe,clientY:Ue,showToolbar:mt=!0})=>{const Se=n.current,Ge=r.current;if(!Se||!Ge)return!1;A.current=null;const ft=ye?sO({terminal:Se,point:ye}):null,de=ft??(ye?XS({terminal:Se,point:ye}):iO({terminal:Se,host:Ge,clientX:Pe,clientY:Ue}));if(!(de!=null&&de.text))return!1;w.current=de.anchor,E.current=de.focus,T.current=de.text,q(de.text,ft==null?void 0:ft.pathAction);const Ne=N(de.anchor,de.focus);return F(Ne),mt&&U(Ne?V(Ne):P(Pe,Ue)),!0},[N,P,V,q,n,r]),J=b.useCallback(()=>{const ye=w.current,Pe=E.current;if(!ye||!Pe){U(null);return}const Ue=N(ye,Pe);F(Ue),U(Ue?V(Ue):null)},[N,V]),te=b.useCallback(ye=>{var mt,Se;const Pe=((Se=(mt=n.current)==null?void 0:mt.getSelection)==null?void 0:Se.call(mt))??"",Ue=q(Pe);T.current=Pe,w.current=null,E.current=null,R.current=!1,F(null),U(Ue?P(ye.clientX,ye.clientY):null)},[P,q,n]);b.useEffect(()=>{const ye=r.current;if(!ye)return;let Pe=!1;const Ue=Ge=>{var de,Ne;if(Ge.pointerType!=="mouse"||Ge.button!==0)return;const ft=Ge.target;!(ft instanceof Element)||!ft.closest(".xterm")||(Pe=!0,Y(((Ne=(de=n.current)==null?void 0:de.getSelection)==null?void 0:Ne.call(de))??""))},mt=Ge=>{if(Ge.pointerType!=="mouse"||!Pe)return;Pe=!1;const ft={clientX:Ge.clientX,clientY:Ge.clientY};window.setTimeout(()=>te(ft),0)},Se=()=>{Pe=!1};return ye.addEventListener("pointerdown",Ue,!0),window.addEventListener("pointerup",mt,!0),window.addEventListener("pointercancel",Se,!0),()=>{ye.removeEventListener("pointerdown",Ue,!0),window.removeEventListener("pointerup",mt,!0),window.removeEventListener("pointercancel",Se,!0)}},[Y,te,n,r]),b.useLayoutEffect(()=>{if(!D&&!W)return;const ye=Pe=>{const Ue=Pe.target;Ue instanceof Element&&Ue.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]')||I()};return document.addEventListener("pointerdown",ye,!0),document.addEventListener("touchstart",ye,!0),()=>{document.removeEventListener("pointerdown",ye,!0),document.removeEventListener("touchstart",ye,!0)}},[I,W,D]),b.useEffect(()=>{if(!s||!D)return;const ye=()=>{const Pe=A.current;Pe&&s.scrollLeft===Pe.scrollLeft&&s.scrollTop===Pe.scrollTop||I()};return s.addEventListener("scroll",ye,{passive:!0}),()=>s.removeEventListener("scroll",ye)},[I,s,D]);const Q=W!==null;b.useLayoutEffect(()=>{var ye;Q&&((ye=i.current)==null||ye.relayout(),$())},[Q,l,$,i]),b.useEffect(()=>{Q&&$()},[Q,$,o.scrollLeft,o.scrollTop]),b.useEffect(()=>{if(!Q)return;const ye=window.visualViewport;let Pe=0,Ue=0;const mt=()=>{cancelAnimationFrame(Pe),window.clearTimeout(Ue),Pe=requestAnimationFrame(()=>{$(),Ue=window.setTimeout(()=>{Pe=requestAnimationFrame(()=>$())},160)})};return mt(),window.addEventListener("resize",mt),ye==null||ye.addEventListener("resize",mt),ye==null||ye.addEventListener("scroll",mt),()=>{cancelAnimationFrame(Pe),window.clearTimeout(Ue),window.removeEventListener("resize",mt),ye==null||ye.removeEventListener("resize",mt),ye==null||ye.removeEventListener("scroll",mt)}},[Q,$]);const fe=b.useCallback(({clientX:ye,clientY:Pe})=>{const Ue=n.current,mt=r.current;if(!Ue||!mt)return;const Se=Kh({terminal:Ue,host:mt,clientX:ye,clientY:Pe})??x.current;if(Ue.clearSelection(),!Se){w.current=null,E.current=null,L.current=null,T.current="",U(null),F(null),M(null);return}w.current=Se,E.current=Se,R.current=!1,L.current=null,T.current="",U(null),F(null),M(null),ee({point:Se,clientX:ye,clientY:Pe,showToolbar:!1})},[ee,n,r]),ce=b.useCallback(({clientX:ye,clientY:Pe})=>{j({clientX:ye,clientY:Pe}),U(null)},[j]),Ee=b.useCallback(({clientX:ye,clientY:Pe})=>{const Ue=n.current,mt=r.current;if(!Ue||!mt)return;const Se=w.current,Ge=Kh({terminal:Ue,host:mt,clientX:ye,clientY:Pe}),ft=Ge??E.current,de=x.current,Ne=k.current,Ke=Ne?Math.hypot(ye-Ne.clientX,Pe-Ne.clientY)>=ave:!1,Qe=de??Ge;if(!R.current&&!Ke&&T.current){J(),x.current=null,k.current=null;return}const ut=!R.current&&!Ke&&Qe?sO({terminal:Ue,point:Qe}):null,jt=Ke?Ge??ft:ft,Ht=(R.current||Ke)&&Se&&jt?cv({terminal:Ue,anchor:Se,focus:jt}):ut??iO({terminal:Ue,host:mt,clientX:ye,clientY:Pe})??(de?XS({terminal:Ue,point:de}):null);if(x.current=null,k.current=null,!(Ht!=null&&Ht.text)){I();return}w.current=Ht.anchor,E.current=Ht.focus,T.current=Ht.text,q(Ht.text,ut==null?void 0:ut.pathAction);const qt=N(Ht.anchor,Ht.focus);F(qt),U(qt?V(qt):P(ye,Pe))},[I,N,P,V,q,J,n,r]),Me=b.useCallback(()=>{var Ue;const ye=n.current,Pe=((Ue=ye==null?void 0:ye.getSelection)==null?void 0:Ue.call(ye))||T.current;Pe&&zj(Pe,{allowLegacyFallback:!0}).then(mt=>{I(),mt==="failed"?tt.error("复制失败"):tt.success("已复制")})},[I,n]),Ie=b.useCallback(()=>{const ye=L.current;ye&&(ye.kind==="image-preview"?_(ye.path):v(ye.path),I())},[I,v,_]),Ye=b.useCallback(()=>w.current!==null,[]),xt=b.useCallback(()=>{U(null)},[]),gn=b.useCallback((ye,{clientX:Pe,clientY:Ue})=>{j({clientX:Pe,clientY:Ue,draggedHandle:ye}),U(null)},[j]),ge=b.useCallback((ye,Pe)=>{Pe&&j({...Pe,draggedHandle:ye}),T.current&&J()},[j,J]),rt=b.useCallback(()=>{U(null)},[]);b.useEffect(()=>{},[I,N,V,t,q,n]);const et=ove({terminalRef:n,containerEl:s,suppressPtyFocus:d,focusPtyInput:h,isSelectionActive:Ye,onTap:p,isTapCandidate:y,onLongPressCandidateStart:G,onLongPressStart:fe,onLongPressMove:ce,onLongPressEnd:Ee,onHorizontalScrollIntent:ye=>{var Pe;return(Pe=i.current)==null?void 0:Pe.markHorizontalScrollIntent(ye)},onSelectionAutoscroll:ye=>{A.current=ye},onHandleDragStart:xt,onHandleDragMove:gn,onHandleDragEnd:ge,onHandleDragCancel:rt});return H.current=et.stopPtySelectionGesture,{pointerHandlers:et.pointerHandlers,ptySelectionToolbar:D,ptySelectionHandles:W,ptySelectionPathAction:O,ptySelectionHandleMetrics:z,copyPtySelection:Me,openPtySelectionPathAction:Ie,handlePtySelectionHandlePointerDown:et.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:et.handlePtySelectionHandleTouchStart}}function cve(){return Oe(e=>e.ptyScrollTraceEnabled)}const uve=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function aO(e){return uve.has(e)}function SE(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!aO(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>aO(r.type))??null}function dve(e){return`${e.startsWith("@")?e:`@${e}`} `}async function $j(e){const t=SE(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await Lj(t),r=await e.relay.uploadClipboardImage(e.sessionId,n);if(!r.success||!r.path)throw new Error(r.error??"剪贴板图片上传失败");return{path:r.path,pathMention:dve(r.path)}}function hve(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 fve({sessionId:e,terminalRef:t,onAfterPaste:n}){return b.useCallback(async r=>{var u;const i=r.clipboardData,s=!!SE(i),o=s?null:hve(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Pt;if(!l){tt.error("请先连接开发机");return}if(s){const d=tt.loading("图片上传中...");try{const h=await $j({clipboardData:i,relay:l,sessionId:e});if(tt.dismiss(d),!h)return;Ys(e,h.pathMention)}catch(h){tt.error(h instanceof Error?h.message:String(h),{id:d});return}}else if(o){const d=await kf({relay:l,sessionId:e,file:o});if(!d)return;Ys(e,`@${d} `)}n==null||n(),(u=t.current)==null||u.focus()},[e,t,n])}const pve=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),lO={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:lpe};function mve({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function gve({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function vve({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function yve({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:pve.has(n)}const cO=8,bve=32;function _ve({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+cO:t?bve:cO}function wve(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"?Yh("\x1B[A",t):e.key==="ArrowDown"?Yh("\x1B[B",t):e.key==="ArrowRight"?Yh("\x1B[C",t):e.key==="ArrowLeft"?Yh("\x1B[D",t):e.key==="Delete"?"\x1B[3~":e.key==="Home"?"\x1B[H":e.key==="End"?"\x1B[F":null}function Sve(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,mobileControlsHeight:o}=e,l=Nge(),u=Dge(),d=cve(),{openImagePreview:h}=Z1(),p=b.useRef(null),y=b.useRef(null),v=b.useRef([]),_=b.useRef(null),w=b.useRef(null),E=b.useRef(n),x=b.useRef(n),k=b.useRef(!1),R=b.useRef(!1),A=b.useRef(!1),L=b.useRef(null),T=b.useRef(null),H=b.useRef(null),D=b.useRef(null),U=b.useRef({keyboardOpen:!1,controlsVisible:!1}),W=b.useRef(!1),F=b.useRef(!1),O=b.useRef(!1),M=b.useRef({mode:"following"}),z=b.useRef(!1),P=b.useRef(null),N=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[q,V]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[$,I]=b.useState(!1),[Y,G]=b.useState(!1),[j,ee]=b.useState({resultIndex:-1,resultCount:0}),J=Oe(me=>me.connected),te=Oe(me=>me.proxyOnline),Q=Oe(me=>me.ptyFontSize),fe=Oe(me=>me.inputModePreference),ce=Oe(me=>me.adaptiveInputModality),Ee=Oe(me=>me.setAdaptiveInputModality),Me=ce==="hardware",Ie=fl("(pointer: coarse), (hover: none)"),{bottomOffset:Ye,layoutBottomInset:xt}=wE(),gn=fe==="hardware",ge=vve({touchEditingSurface:Ie,inputModePreference:fe,detectedPhysicalKeyboard:Me,softKeyboardDetected:Ye>0}),rt=Ie&&!ge,et=ge?0:Ye,ye=et>0,Pe=ge?0:xt;W.current=ge,b.useEffect(()=>{E.current=n},[n]),b.useEffect(()=>{k.current=l.ready},[l.ready]);const Ue=b.useCallback(()=>E.current&&k.current,[]);b.useEffect(()=>{et>0&&I(!0)},[et]);const mt=Pge({containerEl:r,xtermHostRef:s,terminalRef:p}),{ptyInputFocused:Se,suppressPtyFocus:Ge,focusPtyInput:ft,handleFocusCapture:de,handleBlurCapture:Ne}=mt,Ke=mve({softKeyboardEditingSurface:rt,ptyInputFocused:Se,keyboardOpen:ye});N.current={keyboardOffset:et,hasSeenSoftKeyboard:$,showMobilePtyControls:Ke,touchEditingSurface:Ie,ptyInputFocused:Se,containerPaddingBottom:N.current.containerPaddingBottom,mobileControlsBottomInset:Pe};const Qe=u.clearNewFramesWhileAway,ut=u.setHasNewFramesWhileAway;T.current||(T.current=Q2(()=>{var me;(me=w.current)==null||me.relayout()})),H.current||(H.current=Q2(()=>{var Ae,Te;const me=D.current??{reason:"rawInput",force:!1};D.current=null,(Ae=w.current)==null||Ae.traceRawInputFollowFire(),(Te=w.current)==null||Te.scrollToBottom(me.reason,me.force?{force:!0}:void 0),Qe()}));const jt=b.useCallback(()=>{P.current!==null&&(cancelAnimationFrame(P.current),P.current=null)},[]),Ht=b.useCallback(()=>{O.current||(z.current=!1);const me=w.current;me&&(M.current=me.capturePageResumeState(),me.preparePageResumeRestore(M.current)),O.current=!0,jt()},[jt]),qt=b.useCallback(()=>{var me;!O.current||document.visibilityState==="hidden"||((me=w.current)==null||me.preparePageResumeRestore(M.current),jt(),P.current=requestAnimationFrame(()=>{P.current=requestAnimationFrame(()=>{P.current=null;const Ae=w.current;if(!Ae)return;const Te=M.current;Ae.restorePageResume(Te),Te.mode==="following"?Qe():z.current&&ut(!0),z.current=!1,O.current=!1})}))},[jt,Qe,ut]);b.useEffect(()=>()=>{var me,Ae;(me=T.current)==null||me.dispose(),(Ae=H.current)==null||Ae.dispose(),jt(),T.current=null,H.current=null},[jt]),b.useEffect(()=>{const me=()=>{Ht()},Ae=()=>{if(document.visibilityState==="hidden"){me();return}qt()};return document.addEventListener("visibilitychange",Ae),window.addEventListener("pagehide",me),window.addEventListener("pageshow",qt),window.addEventListener("focus",qt),()=>{document.removeEventListener("visibilitychange",Ae),window.removeEventListener("pagehide",me),window.removeEventListener("pageshow",qt),window.removeEventListener("focus",qt),jt()}},[jt,Ht,qt]),b.useEffect(()=>{const me=x.current;if(x.current=n,me!==n){if(!n){Ht();return}qt()}},[n,Ht,qt]);const Ut=b.useCallback((me="rawInput",Ae)=>{var dt,le;const Te=D.current,nt=(Te==null?void 0:Te.force)===!0||(Ae==null?void 0:Ae.force)===!0;D.current={reason:(Ae==null?void 0:Ae.force)===!0||!Te?me:Te.reason,force:nt},(dt=w.current)==null||dt.traceRawInputFollowScheduled(me),(le=H.current)==null||le.schedule()},[]),Qt=b.useCallback((me,Ae)=>{var Te;!me.includes("\r")&&!me.includes(`
665
665
  `)||(Te=w.current)==null||Te.resetHorizontalScroll(Ae,{holdUntilCursorVisible:!0})},[]),Kt=b.useCallback(()=>W.current?"submit":"linefeed",[]),Fn=b.useCallback(()=>W.current,[]);b.useEffect(()=>{if(!n||fe!=="auto"||!Ie)return;const me=Te=>{const nt=s.current,dt=r;return Te instanceof Node?nt!=null&&nt.contains(Te)||Te===document.body||Te===document.documentElement?!0:dt!=null&&dt.contains(Te)?Te instanceof HTMLElement?Te.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:Te===window},Ae=Te=>{var le,xe;if(!yve({active:E.current,touchEditingSurface:Ie,key:Te.key,code:Te.code,altKey:Te.altKey,ctrlKey:Te.ctrlKey,metaKey:Te.metaKey,isComposing:Te.isComposing,targetAcceptsPtyInput:me(Te.target)}))return;Ee("hardware"),W.current=!0,(le=p.current)==null||le.focus();const nt=s.current;if(Te.target instanceof Node&&(nt!=null&&nt.contains(Te.target)))return;const dt=wve(Te,(xe=p.current)==null?void 0:xe.modes);!dt||!Ue()||(Te.preventDefault(),Te.stopPropagation(),Ys(t,dt),Ut("physicalKeyboard"),Qt(dt,"physicalKeyboardEnter"))};return window.addEventListener("keydown",Ae,!0),()=>window.removeEventListener("keydown",Ae,!0)},[n,Ue,r,fe,Qt,Ut,t,Ee,Ie,s]);const dn=b.useCallback(me=>{const Ae=Pt;if(!Ae){tt.error("请先连接开发机");return}const Te=tt.loading(`下载 ${me} ...`);X1({relay:Ae,sessionId:t,path:me}).then(nt=>{nt.ok?tt.success(`已开始下载 ${me}`,{id:Te}):tt.error(nt.error,{id:Te})}).catch(nt=>{tt.error(nt instanceof Error?nt.message:String(nt),{id:Te})})},[t]),or=b.useCallback(me=>{const Ae=p.current;return Ae?lge(Ae,v.current,me):!1},[]),Jn=b.useCallback(me=>{const Ae=p.current;return Ae?age(Ae,v.current,me):!1},[]),Mn=lve({sessionId:t,terminalRef:p,xtermHostRef:s,scrollControllerRef:w,containerEl:r,scrollState:q,keyboardOffset:et,ptyFontSize:Q,suppressPtyFocus:Ge,focusPtyInput:ft,onTap:or,isTapCandidate:Jn,onDownloadPath:dn,onPreviewPath:h});F.current=Mn.ptySelectionHandles!==null;const er=fve({sessionId:t,terminalRef:p,onAfterPaste:()=>Ut("paste")}),Ln=b.useCallback(me=>{if(!Ue()){me.preventDefault();return}er(me)},[Ue,er]),[K,oe]=b.useState(!1),Ce=b.useCallback(me=>{me.dataTransfer.types.includes("Files")&&(me.preventDefault(),oe(Ae=>Ae||!0))},[]),Xe=b.useCallback(me=>{me.currentTarget.contains(me.relatedTarget)||oe(!1)},[]),At=b.useCallback(async me=>{var dt;const Ae=(dt=me.dataTransfer.files)==null?void 0:dt[0];if(!Ae||(me.preventDefault(),oe(!1),!Ue()))return;const Te=Pt;if(!Te){tt.error("请先连接开发机");return}const nt=await kf({relay:Te,sessionId:t,file:Ae});nt&&(Ys(t,`@${nt} `),Ut("dropUpload"))},[Ue,Ut,t]),re=b.useCallback(me=>{var Te;if(!Ue()){me.preventDefault();return}const Ae=me.target;Ae instanceof Element&&Ae.closest(".xterm")||(me.preventDefault(),(Te=p.current)==null||Te.focus())},[Ue]);b.useEffect(()=>{if(!J||!te)return;const me=s.current,Ae=nc,Te=Pt,nt=r,dt=i.current;if(!me||!Ae||!Te||!nt||!dt)return;let le=null,xe=null,qe=null,$e=null,gt=null,_t=null,It=null;const vt=gme({host:me,sessionId:t,ws:Ae,relay:Te,scheduleAutoFocus:rt?()=>{}:void 0,createTerminal:async Et=>{const zt=await dj(Et,{fontSize:Oe.getState().ptyFontSize});return It=zt.serializeAddon,zt},attachRawInput:(Et,zt,Cn)=>Ppe(Et,zt,{...Cn,getPlainEnterBehavior:Kt,isPhysicalKeyboardMode:Fn,physicalKeyboardMode:gn}),isInputEnabled:Ue,canFocus:Ue,onTerminalReady:Et=>{const zt=Et;p.current=zt;const Cn=new zce({highlightLimit:1e3});zt.loadAddon(Cn),y.current=Cn,_t=Cn.onDidChangeResults(nr=>{ee(nr)}),G(!0);const Bt=Fme(zt,h);le=Bt.dispose;const Nn=nge(zt,dn);xe=Nn.dispose,v.current=[Bt.provider,Nn.provider],Ege(()=>p.current);const tr=vpe(me,{serializeRangeAsHtml:(nr,Bi)=>(It==null?void 0:It.serializeAsHTML({range:{startLine:nr,endLine:Math.min(Bi,Math.max(0,zt.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??""});$e=tr.dispose;const mn=O.current;mn&&(A.current=M.current.mode==="reviewing");const sn=lme({container:nt,spacer:dt,host:me,term:zt,hasNewFrame:()=>R.current,consumeNewFrame:()=>{R.current=!1},hasNewFramesWhileAway:()=>u.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:u.setHasNewFramesWhileAway,onAtBottomChange:u.handleAtBottomChange,onScrollStateChange:V,initialUserHasVerticalScrollIntent:mn?!1:A.current,onUserVerticalScrollIntentChange:nr=>{A.current=nr},onTouchReviewStart:Ge,onTouchBoundaryPrevent:Ge,onReviewSnapshotCapture:tr.captureRange,onReviewSnapshotClear:tr.clear});if(w.current=sn,qe=sn.dispose,mn){const nr=M.current;sn.restorePageResume(nr),nr.mode==="following"?Qe():z.current&&ut(!0),z.current=!1,O.current=!1}kge(()=>{var to;const nr=Oo=>{if(!Oo)return null;const ar=Oo.getBoundingClientRect();return{top:ar.top,bottom:ar.bottom,height:ar.height,left:ar.left,right:ar.right,width:ar.width}},Bi=document.querySelector('[data-slot="pty-mobile-controls"]'),zs=document.querySelector("[data-keyboard-offset]"),Zi=window.visualViewport,Kr=nr(Bi),Tl=(Zi==null?void 0:Zi.height)??window.innerHeight;return{...Rge(sn.getDebugProbe,{container:nt,spacer:dt,host:me,term:zt}),mobileLayout:{...N.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:Zi?{height:Zi.height,width:Zi.width,offsetTop:Zi.offsetTop,pageTop:Zi.pageTop,scale:Zi.scale}:null,chatRoot:{dataKeyboardOffset:(zs==null?void 0:zs.getAttribute("data-keyboard-offset"))??null,rect:nr(zs)},ptyViewRect:nr(nt.parentElement),containerRect:nr(nt),controlsRect:Kr,controlsOverflowBelowVisualViewport:Kr===null?null:Kr.bottom-Tl,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(to=document.activeElement.closest("[data-slot]"))==null?void 0:to.getAttribute("data-slot")}:null},frame:{lastWriteAt:L.current,pendingNewFrame:R.current}}}),gt=_pe({container:nt,host:me,onHorizontalScrollIntent:nr=>{var Bi;return(Bi=w.current)==null?void 0:Bi.markHorizontalScrollIntent(nr)}}).dispose},onFramePending:()=>{R.current=!0,O.current&&(z.current=!0),A.current&&!u.hasNewFramesWhileAwayRef.current&&u.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Et;L.current=performance.now(),(Et=T.current)==null||Et.schedule()},onRawInput:Et=>{Ut("rawInput",{force:!0}),Qt(Et,"rawInputEnter")},onError:Et=>{const zt=Et instanceof Error?Et.message:String(Et);tt.error(`终端初始化失败:${zt}`)},...l.transport});return _.current=vt,()=>{gt==null||gt(),qe==null||qe(),$e==null||$e(),_t==null||_t.dispose(),Tge(),le==null||le(),xe==null||xe(),v.current=[],Cge(),y.current=null,G(!1),ee({resultIndex:-1,resultCount:0}),vt.dispose(),p.current=null,w.current=null,_.current=null}},[t,J,te,r,i,s,l.transport,u.handleAtBottomChange,u.hasNewFramesWhileAwayRef,u.setHasNewFramesWhileAway,Ue,gn,Kt,Fn,dn,h,Ge,Ut,Qt]),b.useEffect(()=>{const me=p.current,Ae=w.current;!me||!Ae||dpe(me,Q,Ae.relayout)},[Q]),b.useEffect(()=>{if(!n||!l.ready||rt)return;const me=requestAnimationFrame(()=>{var Ae;return(Ae=p.current)==null?void 0:Ae.focus()});return()=>cancelAnimationFrame(me)},[n,l.ready,rt]);const ie=b.useCallback((me="viewExternal",Ae)=>{var Te;(Te=w.current)==null||Te.scrollToBottom(me,Ae)},[]),he=b.useCallback(()=>{var me;(me=w.current)==null||me.refreshReviewSnapshot()},[]),pe=b.useCallback(me=>{var Ae;(Ae=w.current)==null||Ae.scrollToRatio(me)},[]),Z=b.useCallback(me=>{var Ae;(Ae=w.current)==null||Ae.scrollToXRatio(me)},[]),ne=b.useCallback(me=>{var xe;const Ae=p.current,Te=Ae==null?void 0:Ae.getSelectionPosition();if(!Ae||!Te)return;const nt=Te.start.y;if(nt>=me&&nt<me+Ae.rows)return;const dt=Math.max(0,Ae.buffer.active.length-Ae.rows);if(dt===0)return;const le=Math.max(0,Math.min(dt,nt-Math.floor(Ae.rows/2)));(xe=w.current)==null||xe.scrollToRatio(le/dt)},[]),ae=b.useCallback((me,Ae=!1)=>{const Te=p.current,nt=y.current;if(!Te||!nt||!me)return me||(nt==null||nt.clearDecorations(),Te==null||Te.clearSelection(),ee({resultIndex:-1,resultCount:0})),!1;const dt=Te.buffer.active.viewportY,le=nt.findNext(me,{...lO,incremental:Ae});return le&&ne(dt),le},[ne]),ke=b.useCallback(me=>{const Ae=p.current,Te=y.current;if(!Ae||!Te||!me)return!1;const nt=Ae.buffer.active.viewportY,dt=Te.findPrevious(me,lO);return dt&&ne(nt),dt},[ne]),je=b.useCallback(()=>{var me,Ae;(me=y.current)==null||me.clearDecorations(),(Ae=p.current)==null||Ae.clearSelection(),ee({resultIndex:-1,resultCount:0})},[]),st=b.useCallback(me=>{var Te,nt;if(!Ue())return;const Ae=Yh(me,(Te=p.current)==null?void 0:Te.modes);Ys(t,Ae),Ut("mobileControl",{force:!0}),Qt(me,"mobileControlEnter"),(nt=p.current)==null||nt.focus()},[Ue,Qt,Ut,t]),Ze=b.useCallback(()=>{var Ae,Te,nt;if(!Ue())return;const me=(Te=(Ae=navigator.clipboard)==null?void 0:Ae.readText)==null?void 0:Te.bind(navigator.clipboard);if(!window.isSecureContext||!me){tt.error("无法读取剪贴板"),(nt=p.current)==null||nt.focus();return}me().then(dt=>{if(!dt)return;const le=p.current;if(le){le.paste(dt);return}Ys(t,dt),Ut("paste"),Qt(dt,"pasteEnter")}).catch(dt=>{const le=dt instanceof Error&&dt.message?dt.message:"无法读取剪贴板";tt.error(le)}).finally(()=>{var dt;return(dt=p.current)==null?void 0:dt.focus()})},[Ue,Qt,Ut,t]),ht=_ve({showMobilePtyControls:Ke,horizontalScrollable:q.horizontalScrollable,mobileControlsHeight:o});N.current.containerPaddingBottom=ht,b.useEffect(()=>{var Te,nt;F.current?(Te=w.current)==null||Te.relayout():(nt=T.current)==null||nt.schedule();const me=U.current,Ae=gve({controlsVisible:Ke,keyboardOpen:ye,previous:me});U.current={keyboardOpen:ye,controlsVisible:Ke},Ke&&(F.current?Qe():Ae?Ut("keyboardOffset",{force:!0}):ye||Ut("keyboardOffset"))},[et,ye,Ke,ht,Qe,Ut]);const pt=b.useMemo(()=>({onFocusCapture:de,onBlurCapture:Ne}),[de,Ne]);return{scrollState:q,isAtBottom:u.isAtBottom,hasNewFramesWhileAway:u.hasNewFramesWhileAway,ptyInputFocused:Se,showMobilePtyControls:Ke,touchEditingSurface:Ie,keyboardOffset:et,physicalKeyboardMode:ge,softKeyboardEditingSurface:rt,mobileControlsBottomInset:Pe,connectionReady:l.ready,connectionOverlay:l.overlay,containerPaddingBottom:ht,traceEnabled:d,findReady:Y,findResultIndex:j.resultIndex,findResultCount:j.resultCount,findNext:ae,findPrevious:ke,clearFind:je,refreshReviewSnapshot:he,scrollToBottom:ie,scrollToRatio:pe,scrollToXRatio:Z,clearNewFramesWhileAway:Qe,sendMobileInput:st,pasteMobileClipboard:Ze,handleTerminalContainerMouseDown:re,handlePasteCapture:Ln,pointerHandlers:Mn.pointerHandlers,focusHandlers:pt,ptySelectionToolbar:Mn.ptySelectionToolbar,ptySelectionHandles:Mn.ptySelectionHandles,ptySelectionPathAction:Mn.ptySelectionPathAction,ptySelectionHandleMetrics:Mn.ptySelectionHandleMetrics,copyPtySelection:Mn.copyPtySelection,openPtySelectionPathAction:Mn.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:Mn.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Mn.handlePtySelectionHandleTouchStart,isPtyDragOver:K,handlePtyDragOver:Ce,handlePtyDragLeave:Xe,handlePtyDrop:At}}function xve({sessionId:e,sessionKind:t,provider:n,active:r=!0,findRequest:i}){const[s,o]=b.useState(null),[l,u]=b.useState(0),[d,h]=b.useState(!1),[p,y]=b.useState(""),v=b.useRef(null),_=b.useRef(null),w=Sve({sessionId:e,active:r,containerEl:s,spacerRef:v,xtermHostRef:_,mobileControlsHeight:l}),E=w.ptySelectionHandleMetrics,{clearFind:x,findNext:k,findPrevious:R,findReady:A,findResultCount:L,findResultIndex:T}=w,H=b.useCallback(()=>{R(p)},[R,p]),D=b.useCallback(()=>{k(p)},[k,p]),U=b.useCallback(()=>h(!0),[]),W=b.useCallback(()=>{h(!1),x()},[x]),F=$3({enabled:r,open:d,openRequest:i,onOpen:U,onClose:W,onPrevious:H,onNext:D});return b.useEffect(()=>{!d||!A||(p?k(p,!0):x())},[x,k,d,p,A]),g.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":w.connectionReady?"true":"false","aria-busy":!w.connectionReady,children:[d?g.jsx(Z0,{query:p,resultIndex:T,resultCount:L,focusRequest:F.focusRequest,loading:!!p&&!A,onQueryChange:y,onPrevious:H,onNext:D,onClose:F.closeFind}):null,g.jsx("div",{ref:o,className:"flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${w.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:w.handleTerminalContainerMouseDown,onPointerDownCapture:O=>{w.refreshReviewSnapshot(),w.pointerHandlers.onPointerDownCapture(O)},onPointerMoveCapture:w.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:w.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:w.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:w.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:w.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:w.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:w.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:w.pointerHandlers.onContextMenuCapture,onPasteCapture:w.handlePasteCapture,onDragOver:w.handlePtyDragOver,onDragLeave:w.handlePtyDragLeave,onDrop:w.handlePtyDrop,onFocusCapture:w.focusHandlers.onFocusCapture,onBlurCapture:w.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":w.isPtyDragOver?"true":void 0,children:g.jsx("div",{ref:v,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:g.jsx("div",{ref:_,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})})}),g.jsx(B3,{visible:!w.isAtBottom,hasNewMessages:w.hasNewFramesWhileAway,className:d?"top-14":"top-10",onClick:()=>{w.scrollToBottom("backToBottomBtn",{force:!0}),w.clearNewFramesWhileAway()}}),w.showMobilePtyControls?g.jsx(Gle,{sessionKind:t,provider:n,bottomInset:w.mobileControlsBottomInset,onInput:w.sendMobileInput,onPaste:w.pasteMobileClipboard,onHeightChange:u}):null,w.ptySelectionHandles?g.jsxs(g.Fragment,{children:[g.jsx(uO,{kind:"anchor",position:w.ptySelectionHandles.anchor,metrics:E,"aria-label":"调整选区起点",onPointerDown:O=>w.handlePtySelectionHandlePointerDown("anchor",O),onTouchStart:O=>w.handlePtySelectionHandleTouchStart("anchor",O)}),g.jsx(uO,{kind:"focus",position:w.ptySelectionHandles.focus,metrics:E,"aria-label":"调整选区终点",onPointerDown:O=>w.handlePtySelectionHandlePointerDown("focus",O),onTouchStart:O=>w.handlePtySelectionHandleTouchStart("focus",O)})]}):null,w.ptySelectionToolbar?g.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:w.ptySelectionToolbar.left,top:w.ptySelectionToolbar.top},"data-slot":"pty-selection-toolbar",children:[g.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:O=>O.preventDefault(),onClick:w.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),w.ptySelectionPathAction?g.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:O=>O.preventDefault(),onClick:w.openPtySelectionPathAction,"aria-label":w.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:w.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,g.jsx(rce,{state:w.scrollState,onScrollRatio:w.scrollToRatio}),g.jsx(ice,{state:w.scrollState,onScrollRatio:w.scrollToXRatio}),g.jsx(Ile,{...w.connectionOverlay}),g.jsx(Ble,{ptyInputFocused:w.ptyInputFocused,touchEditingSurface:w.touchEditingSurface,softKeyboardEditingSurface:w.softKeyboardEditingSurface,physicalKeyboardMode:w.physicalKeyboardMode,keyboardOffset:w.keyboardOffset,showMobilePtyControls:w.showMobilePtyControls,mobileControlsBottomInset:w.mobileControlsBottomInset}),w.traceEnabled?g.jsx(Eve,{}):null]})}function uO({kind:e,position:t,metrics:n,"aria-label":r,onPointerDown:i,onTouchStart:s}){const o=n.touchSize/2,l=2,u=n.visualSize,d=Math.max(n.stemSize+2,u+1),h=o-l/2,p=o,y=e==="anchor"?h-u+l:h,v=p+d-u+l,_=e==="anchor"?{borderTopLeftRadius:u,borderBottomLeftRadius:u,borderTopRightRadius:2,borderBottomRightRadius:u}:{borderTopLeftRadius:2,borderBottomLeftRadius:u,borderTopRightRadius:u,borderBottomRightRadius:u};return g.jsxs("button",{type:"button",className:"fixed z-50 touch-none rounded-full bg-transparent p-0 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",style:{left:t.left,top:t.top,width:n.touchSize,height:n.touchSize,transform:"translate(-50%, -50%)"},"data-slot":"pty-selection-handle","data-kind":e,"aria-label":r,onPointerDown:i,onTouchStart:s,children:[g.jsx("span",{className:"pointer-events-none absolute rounded-full bg-primary",style:{left:h,top:p,width:l,height:d},"data-slot":"pty-selection-handle-stem"}),g.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:y,top:v,width:u,height:u,..._},"data-slot":"pty-selection-handle-dot"})]})}function Eve(){const[e,t]=b.useState(!1);async function n(){const r=Dle();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return g.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 Cve=3,kve=1024,Tve=720,ng=.5,Hj=b.createContext(null);function Rve({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Oe(k=>k.selectedProxyId),u=$t(k=>k.sessions),d=$t(k=>k.sessionListLoaded),h=b.useRef(l),p=b.useRef(null),y=b.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
666
666
  `),[u]),v=b.useCallback(k=>{p.current=k.sessionId,i(k),n(R=>iae(R,k.sessionId,{capacity:Cve,now:Date.now(),activeSessionId:k.sessionId}).map(L=>L.sessionId===k.sessionId?{...L,sessionKind:k.sessionKind,provider:k.provider}:L))},[]),_=b.useCallback(k=>{p.current===k&&(p.current=null),i(R=>(R==null?void 0:R.sessionId)===k?null:R),o(R=>p.current===null?null:R)},[]),w=b.useCallback((k,R)=>{p.current===k&&o(A=>!R||A&&Mve(A,R)?A:R)},[]),E=b.useCallback((k,R)=>{R!==void 0&&n(A=>A.map(L=>L.sessionId===k?{...L,findRequest:R}:L))},[]);b.useEffect(()=>{if(!d)return;const k=new Set(y?y.split(`
667
- `):[]);n(R=>R.filter(A=>k.has(A.sessionId))),i(R=>R&&k.has(R.sessionId)?R:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),b.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const x=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:E,updateViewportRect:w}),[v,_,E,w]);return g.jsxs(Hj.Provider,{value:x,children:[e,g.jsx(Nve,{entries:t,activeView:r,viewportRect:s})]})}function Ave({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(Hj),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 h=s.current;if(!h)return;const p=()=>{const v=h.getBoundingClientRect();d(e,{top:v.top,left:v.left,width:v.width,height:v.height})};p();const y=new ResizeObserver(p);return y.observe(h),window.addEventListener("resize",p),()=>{y.disconnect(),window.removeEventListener("resize",p)}},[e,d]),g.jsx("div",{ref:s,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function Nve({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:g.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)??kve,height:(n==null?void 0:n.height)??Tve};return g.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:g.jsx(z3,{sessionId:r.sessionId,children:g.jsx(xve,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function Mve(e,t){return Math.abs(e.top-t.top)<=ng&&Math.abs(e.left-t.left)<=ng&&Math.abs(e.width-t.width)<=ng&&Math.abs(e.height-t.height)<=ng}function xE({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"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}const EE="dev-anywhere:last-chat-route",Uj="dev-anywhere:route-restored",ZS="dev-anywhere:restored-target";function Ove(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function Pve(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(EE))??null}catch{return null}}function Dve(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(EE,e)}catch{}}function Wj(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(EE)}catch{}}function Lve(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(Uj))==="1"}catch{return!1}}function Ive(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(Uj,"1")}catch{}}function zve(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(ZS,e)}catch{}}function Bve(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(ZS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(ZS)),n}catch{return null}}function jve(e){const t=QL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Dg(){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 Fve(){return typeof navigator>"u"?{supported:!0}:jve({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Dg()})}function $ve(){yge(),bge();const e=Di(),t=Qs(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=b.useState(!1),[o,l]=b.useState(()=>Dg()),u=Oe(D=>D.proxies.length),d=Oe(D=>D.proxyListLoaded),h=Oe(D=>D.relayClientAuthIssue),p=Oe(D=>!!D.selectedProxyId),y=Oe(D=>D.selectedProxyId),v=Oe(D=>D.selectedProxyName),_=$t(D=>D.sessions.length),w=Oe(D=>D.pendingToast),E=Oe(D=>D.setPendingToast),x=e.pathname==="/"?"proxy-select":"sessions",k=xE({route:x,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:h}),R=v??y,L=e.pathname==="/sessions"&&d&&u>0?g.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":R?`切换开发机,当前 ${R}`:"切换开发机",onClick:()=>t("/"),children:[g.jsx($D,{className:"size-4 text-primary","aria-hidden":"true"}),g.jsxs("span",{className:"min-w-0 truncate",children:[g.jsx("span",{className:"text-foreground",children:"切换开发机"}),R?g.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",R]}):null]})]}):null;b.useEffect(()=>{if(!w)return;({error:tt.error,info:tt.info,success:tt.success})[w.kind](w.message),E(null)},[w,E]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Dg());return}const D=window.matchMedia("(display-mode: standalone)"),U=window.matchMedia("(display-mode: fullscreen)"),W=()=>l(Dg());return W(),D.addEventListener("change",W),U.addEventListener("change",W),()=>{D.removeEventListener("change",W),U.removeEventListener("change",W)}},[]);const T=b.useRef(!1);b.useEffect(()=>{if(T.current)return;T.current=!0;const D=Ove({pathname:e.pathname,alreadyRestored:Lve(),lastRoute:Pve()});Ive(),D&&(zve(D),t(D,{replace:!0}))},[]);const H=b.useRef(!1);return b.useEffect(()=>{n?(H.current=!0,Dve(`${e.pathname}${e.search}`)):H.current&&(H.current=!1,Wj())},[n,e.pathname,e.search]),g.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&&g.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:g.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:g.jsx(WD,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx(aoe,{subtitle:k,action:L}),g.jsx(rae,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(ioe,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(Rve,{children:g.jsx("div",{className:We("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(JU,{})},r?"top-level":e.pathname)})})]}),g.jsx(K0,{open:i,onOpenChange:s}),g.jsx(Doe,{}),g.jsx(goe,{}),g.jsx(LZ,{})]})}function qj({subtitle:e,action:t}){return g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[g.jsx(r3,{texts:i3,className:"text-2xl md:text-3xl font-bold"}),g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&g.jsx("div",{children:t})]})}function Hve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=xE({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 g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx($B,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(rc,{variant:s}):g.jsx(qj,{subtitle:i})})]})}function Uve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=Ei("local",cn.proxyId)!==null;if(!t&&!i)return g.jsx(QU,{to:"/",replace:!0});const s=xE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx(XB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(qj,{subtitle:s})})]})}function Vj(){if(!(typeof navigator>"u"))return navigator.wakeLock}function Wve(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function Yj(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return Wve(e,typeof((t=Vj())==null?void 0:t.request)=="function")}function qve(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function Vve(){const e=Vj();if(typeof(e==null?void 0:e.request)!="function")throw new Error(qve(Yj()));return e.request("screen")}function Yve(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class Kve{constructor(t={}){bt(this,"activeScopes",new Set);bt(this,"pendingScopes",new Set);bt(this,"listeners",new Map);bt(this,"sentinel",null);bt(this,"requestInFlight",null);bt(this,"requestWakeLock");bt(this,"documentRef");bt(this,"windowRef");bt(this,"unavailableReason");bt(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(()=>{})});bt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??Vve,this.unavailableReason=typeof t.request=="function"?null:Yj(),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(Yve(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 Xa=new Kve;function Kj(e){const[t,n]=b.useState(()=>Xa.getSnapshot(e));b.useEffect(()=>Xa.subscribe(e,n),[e]),b.useEffect(()=>()=>{Xa.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Xa.enable(e),[e]),i=b.useCallback(()=>Xa.disable(e),[e]),s=b.useCallback(()=>Xa.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function Gve(){return new AudioContext}class Xve{constructor(t=Gve){bt(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 Lg=new Xve,dO=400,Lu=[];let Gj=1;function Zve(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Xh(e){const t={sequence:Gj++,timestamp:new Date().toISOString(),monotonicMs:Zve(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Lu.push(t),Lu.length>dO&&Lu.splice(0,Lu.length-dO)}function Qve(){return Lu.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Jve(){Lu.length=0,Gj=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Qve,clear:Jve});function Xj(e){return`voice-pilot:${e}`}function eye(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 tye="modulepreload",nye=function(e){return"/"+e},hO={},rye=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(h=>Promise.resolve(h).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=nye(d),d in hO)return;hO[d]=!0;const h=d.endsWith(".css"),p=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const y=document.createElement("link");if(y.rel=h?"stylesheet":tye,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)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)})},iye="/assets/fvad-DYxbW2my.wasm",td=16e3,sye=20,Za=td*sye/1e3,$w=Za*Int16Array.BYTES_PER_ELEMENT;let fO=null;async function oye(){return fO??(fO=rye(async()=>{const{default:e}=await import("./fvad-xd_70pC7.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?iye:t}))),fO}class CE{constructor(t,n,r){bt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await oye(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc($w);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,td)!==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 CE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==$w)throw new Error(`语音活动检测帧必须为 ${$w} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Za);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 aye{constructor(t={}){bt(this,"startSpeechFrames");bt(this,"endSilenceFrames");bt(this,"active",!1);bt(this,"speechFrames",0);bt(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 lye{constructor(){bt(this,"pending",new Float32Array(Za));bt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Za-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Za&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Za<=t.length;)n(t.slice(r,r+Za)),r+=Za;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const cye="/__dev_anywhere_debug/voice-fixture",uye=td*QB/1e3;function dye(){return CE.create(3)}const hye={createVad:dye,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function fye(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 pye(e){for(const t of e.getTracks())t.stop()}function Zj(e){const t=e.createAudioContext({sampleRate:td});if(t.sampleRate!==td)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function mye(e){const t=Zj(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:td}})}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(),pye(n),t.state!=="closed"&&await t.close()}}}async function gye(e,t){const n=Zj(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 Qj(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:cye}:{kind:"microphone"}}async function vye(e,t=hye){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await gye(e.source.url,t):await mye(t)}catch(h){throw n.destroy(),h}const i=new aye,s=new lye,o=r.context.createScriptProcessor(uye,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=eye(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:fye(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 Jj(e=kv().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function yye(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function bye({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=yye(e);return g.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&g.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),g.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function _ye(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 wye(){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(_ye(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const yu="min-h-9 gap-2.5",rg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function Sye({label:e}){return g.jsxs(mo,{className:"relative",children:[g.jsx(FD,{className:"size-4","aria-hidden":"true"}),g.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 xye({sessionId:e,mode:t,onFind:n}){const r=Jj(),i=Qs(),s=$t(ge=>ge.sessions.find(rt=>rt.sessionId===e)),o=$t(ge=>ge.ptyTitles[e]),l=Oe(ge=>ge.ptyFontSize),u=Oe(ge=>ge.chatContentFontSize),d=Oe(ge=>ge.selectedProxyId),h=Oe(ge=>ge.adjustPtyFontSize),p=Oe(ge=>ge.adjustChatContentFontSize),y=Oe(ge=>ge.setChatContentFontSize),v=Oe(ge=>ge.resetPtyFontSize),_=Oe(ge=>ge.resetChatContentFontSize),w=Oe(ge=>ge.inputModePreference==="hardware"),E=$t(ge=>ge.renameSession),x=Fx(d,e),k=$t(ge=>x?!!ge.ptyAutoYesBySessionKey[x]:!1),R=$t(ge=>ge.setPtyAutoYes),L=fl("(pointer: coarse), (hover: none)")&&!w,T=t==="pty"||(s==null?void 0:s.mode)==="pty",H=(s==null?void 0:s.kind)==="terminal",D=Kj(e),U=ln(ge=>ge.bySessionId[e]??ay),W=ln(ge=>ge.enable),F=ln(ge=>ge.disable),O=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Jx(s),z=O&&(s==null?void 0:s.name)||M||T&&o||(s==null?void 0:s.name)||e.slice(0,8),P=!!(T&&!H&&o&&!O),N=T?l:Bx(u,L),q=!T&&L?dL:cL,V=T?v:_,[$,I]=b.useState(!1),[Y,G]=b.useState(!1),j=U.enabled,ee=D.active||j,J=D.pending||!D.supported||j;function te(ge){if(T){h(ge);return}if(L){y(N+ge);return}p(ge)}function Q(){D.toggle().catch(ge=>{tt.error(ge instanceof Error?ge.message:String(ge))})}async function fe(ge){var et;if(T||H){tt.info("Voice Pilot 目前适用于聊天会话。");return}if(ge!==!0){F(e);return}const rt=Pt;if(!rt){tt.error("请先连接开发机");return}try{if(!((et=(await rt.requestVoiceConfig()).config)!=null&&et.configured)){tt.info("请先在设置里配置 Voice Pilot。");return}I(!0)}catch(ye){tt.error(ye instanceof Error?ye.message:String(ye))}}async function ce(){var ye;G(!0);let ge=null,rt=!1;const et=Xj(e);try{Xh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((ye=navigator.userActivation)==null?void 0:ye.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Pe=Xa.enable(et).then(()=>{Xh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ge=>{throw Xh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ge instanceof Error?Ge.message:String(Ge)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ge})});ge=j1.acquire("capture");const Ue=Lg.prepare(),Se=Qj().kind==="microphone"?wye():Promise.resolve();await Promise.all([Pe,Ue,Se]),W(e),rt=!0,I(!1)}catch(Pe){Xh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Pe instanceof Error?Pe.message:String(Pe)}}),tt.error(Pe instanceof Error?Pe.message:String(Pe))}finally{ge==null||ge.release(),rt||await Xa.disable(et).catch(()=>{}),G(!1)}}const Ee=b.useRef(null),Me=b.useRef(null),[Ie,Ye]=b.useState(!1);async function xt(ge){var Pe;const rt=(Pe=ge.target.files)==null?void 0:Pe[0];if(ge.target.value="",!rt)return;const et=Pt;if(!et){tt.error("请先连接开发机");return}const ye=await kf({relay:et,sessionId:e,file:rt});ye&&Ys(e,`@${ye} `)}async function gn(ge,rt){const et=Pt;if(!et)throw new Error("请先连接开发机");const ye=await et.renameSession(ge,rt);if(!ye.success)throw new Error(ye.error??"重命名失败");E(ge,ye.name??rt),tt.success("已重命名会话")}return g.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[g.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:g.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:[g.jsx("div",{className:"flex justify-start",children:g.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(wv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(bye,{title:z,isPtyTitle:P})}),g.jsxs(L1,{modal:!1,children:[g.jsx(I1,{asChild:!0,children:g.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(S9,{"aria-hidden":"true"})})}),g.jsxs(z1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(Fm,{className:rg,children:"会话"}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(mo,{children:g.jsx(Bg,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-rename",onSelect:()=>Ye(!0),children:[g.jsx(mo,{children:g.jsx(c7,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(Q_,{checked:ee,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:J,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Q,children:[g.jsx(mo,{children:g.jsx(W9,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:D.supported?j?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":D.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),T&&!H&&g.jsxs(Q_,{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:ge=>{x&&R(x,ge===!0)},children:[g.jsx(mo,{children:g.jsx(ra,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!T&&!H&&g.jsxs(Q_,{checked:U.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:fe,children:[g.jsx(mo,{children:g.jsx(X9,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(J_,{}),T&&!H?g.jsxs(g.Fragment,{children:[g.jsx(Fm,{className:rg,children:"快捷键"}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ys(e,""),children:[g.jsx(Sye,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(J_,{}),g.jsx(Fm,{className:rg,children:"文件"}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ge;return(ge=Me.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(Lf,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ge;return(ge=Ee.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(qD,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(J_,{})]}):null,g.jsx(Fm,{className:rg,children:"字号"}),g.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:g.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:[g.jsx(mo,{children:g.jsx(D7,{"aria-hidden":"true"})}),g.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[g.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:N<=q,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ge=>{ge.stopPropagation(),te(-1)},children:g.jsx(Q9,{"aria-hidden":"true"})}),g.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:[N,"px"]}),g.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:N>=uL,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ge=>{ge.stopPropagation(),te(1)},children:g.jsx(h7,{"aria-hidden":"true"})})]})]})}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-font-reset",onClick:V,children:[g.jsx(mo,{children:g.jsx(m7,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(Fh,{open:Ie,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Ye,onRename:gn}),g.jsx(Ec,{open:$&&!U.enabled,onOpenChange:ge=>{Y||I(ge)},children:g.jsxs(Cc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(kc,{children:[g.jsx(hl,{children:"开启 Voice Pilot?"}),g.jsx(hc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"outline",disabled:Y,onClick:()=>I(!1),children:"取消"}),g.jsx(Ct,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Y,onClick:()=>{ce()},children:Y?"正在开启...":"开启 Voice Pilot"})]})]})}),T?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Me,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ge=>{xt(ge)}}),g.jsx("input",{ref:Ee,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ge=>{xt(ge)}})]}):null]})}function bu(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let h;n.key&&((l=n.debug)!=null&&l.call(n))&&(h=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()-h)*100)/100,w=Math.round((Date.now()-v)*100)/100,E=w/16,x=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
667
+ `):[]);n(R=>R.filter(A=>k.has(A.sessionId))),i(R=>R&&k.has(R.sessionId)?R:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),b.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const x=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:E,updateViewportRect:w}),[v,_,E,w]);return g.jsxs(Hj.Provider,{value:x,children:[e,g.jsx(Nve,{entries:t,activeView:r,viewportRect:s})]})}function Ave({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(Hj),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 h=s.current;if(!h)return;const p=()=>{const v=h.getBoundingClientRect();d(e,{top:v.top,left:v.left,width:v.width,height:v.height})};p();const y=new ResizeObserver(p);return y.observe(h),window.addEventListener("resize",p),()=>{y.disconnect(),window.removeEventListener("resize",p)}},[e,d]),g.jsx("div",{ref:s,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function Nve({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:g.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)??kve,height:(n==null?void 0:n.height)??Tve};return g.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:g.jsx(z3,{sessionId:r.sessionId,children:g.jsx(xve,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function Mve(e,t){return Math.abs(e.top-t.top)<=ng&&Math.abs(e.left-t.left)<=ng&&Math.abs(e.width-t.width)<=ng&&Math.abs(e.height-t.height)<=ng}function xE({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"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}const EE="dev-anywhere:last-chat-route",Uj="dev-anywhere:route-restored",ZS="dev-anywhere:restored-target";function Ove(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function Pve(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(EE))??null}catch{return null}}function Dve(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(EE,e)}catch{}}function Wj(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(EE)}catch{}}function Lve(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(Uj))==="1"}catch{return!1}}function Ive(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(Uj,"1")}catch{}}function zve(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(ZS,e)}catch{}}function Bve(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(ZS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(ZS)),n}catch{return null}}function jve(e){const t=QL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Dg(){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 Fve(){return typeof navigator>"u"?{supported:!0}:jve({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Dg()})}function $ve(){yge(),bge();const e=Di(),t=Qs(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=b.useState(!1),[o,l]=b.useState(()=>Dg()),u=Oe(D=>D.proxies.length),d=Oe(D=>D.proxyListLoaded),h=Oe(D=>D.relayClientAuthIssue),p=Oe(D=>!!D.selectedProxyId),y=Oe(D=>D.selectedProxyId),v=Oe(D=>D.selectedProxyName),_=$t(D=>D.sessions.length),w=Oe(D=>D.pendingToast),E=Oe(D=>D.setPendingToast),x=e.pathname==="/"?"proxy-select":"sessions",k=xE({route:x,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:h}),R=v??y,L=e.pathname==="/sessions"&&d&&u>0?g.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":R?`切换开发机,当前 ${R}`:"切换开发机",onClick:()=>t("/"),children:[g.jsx($D,{className:"size-4 text-primary","aria-hidden":"true"}),g.jsxs("span",{className:"min-w-0 truncate",children:[g.jsx("span",{className:"text-foreground",children:"切换开发机"}),R?g.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",R]}):null]})]}):null;b.useEffect(()=>{if(!w)return;({error:tt.error,info:tt.info,success:tt.success})[w.kind](w.message),E(null)},[w,E]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Dg());return}const D=window.matchMedia("(display-mode: standalone)"),U=window.matchMedia("(display-mode: fullscreen)"),W=()=>l(Dg());return W(),D.addEventListener("change",W),U.addEventListener("change",W),()=>{D.removeEventListener("change",W),U.removeEventListener("change",W)}},[]);const T=b.useRef(!1);b.useEffect(()=>{if(T.current)return;T.current=!0;const D=Ove({pathname:e.pathname,alreadyRestored:Lve(),lastRoute:Pve()});Ive(),D&&(zve(D),t(D,{replace:!0}))},[]);const H=b.useRef(!1);return b.useEffect(()=>{n?(H.current=!0,Dve(`${e.pathname}${e.search}`)):H.current&&(H.current=!1,Wj())},[n,e.pathname,e.search]),g.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&&g.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:g.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:g.jsx(WD,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx(aoe,{subtitle:k,action:L}),g.jsx(rae,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(ioe,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(Rve,{children:g.jsx("div",{className:We("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(JU,{})},r?"top-level":e.pathname)})})]}),g.jsx(K0,{open:i,onOpenChange:s}),g.jsx(Doe,{}),g.jsx(goe,{}),g.jsx(LZ,{})]})}function qj({subtitle:e,action:t}){return g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[g.jsx(r3,{texts:i3,className:"text-2xl md:text-3xl font-bold"}),g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&g.jsx("div",{children:t})]})}function Hve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=xE({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 g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx($B,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(rc,{variant:s}):g.jsx(qj,{subtitle:i})})]})}function Uve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=$t(o=>o.sessions.length),i=Ei("local",cn.proxyId)!==null;if(!t&&!i)return g.jsx(QU,{to:"/",replace:!0});const s=xE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx(XB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(qj,{subtitle:s})})]})}function Vj(){if(!(typeof navigator>"u"))return navigator.wakeLock}function Wve(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function Yj(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return Wve(e,typeof((t=Vj())==null?void 0:t.request)=="function")}function qve(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function Vve(){const e=Vj();if(typeof(e==null?void 0:e.request)!="function")throw new Error(qve(Yj()));return e.request("screen")}function Yve(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class Kve{constructor(t={}){bt(this,"activeScopes",new Set);bt(this,"pendingScopes",new Set);bt(this,"listeners",new Map);bt(this,"sentinel",null);bt(this,"requestInFlight",null);bt(this,"requestWakeLock");bt(this,"documentRef");bt(this,"windowRef");bt(this,"unavailableReason");bt(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(()=>{})});bt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??Vve,this.unavailableReason=typeof t.request=="function"?null:Yj(),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(Yve(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 Xa=new Kve;function Kj(e){const[t,n]=b.useState(()=>Xa.getSnapshot(e));b.useEffect(()=>Xa.subscribe(e,n),[e]),b.useEffect(()=>()=>{Xa.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Xa.enable(e),[e]),i=b.useCallback(()=>Xa.disable(e),[e]),s=b.useCallback(()=>Xa.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function Gve(){return new AudioContext}class Xve{constructor(t=Gve){bt(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 Lg=new Xve,dO=400,Lu=[];let Gj=1;function Zve(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Xh(e){const t={sequence:Gj++,timestamp:new Date().toISOString(),monotonicMs:Zve(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Lu.push(t),Lu.length>dO&&Lu.splice(0,Lu.length-dO)}function Qve(){return Lu.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Jve(){Lu.length=0,Gj=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Qve,clear:Jve});function Xj(e){return`voice-pilot:${e}`}function eye(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 tye="modulepreload",nye=function(e){return"/"+e},hO={},rye=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(h=>Promise.resolve(h).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=nye(d),d in hO)return;hO[d]=!0;const h=d.endsWith(".css"),p=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const y=document.createElement("link");if(y.rel=h?"stylesheet":tye,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)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)})},iye="/assets/fvad-DYxbW2my.wasm",td=16e3,sye=20,Za=td*sye/1e3,$w=Za*Int16Array.BYTES_PER_ELEMENT;let fO=null;async function oye(){return fO??(fO=rye(async()=>{const{default:e}=await import("./fvad-vwVWAhiJ.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?iye:t}))),fO}class CE{constructor(t,n,r){bt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await oye(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc($w);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,td)!==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 CE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==$w)throw new Error(`语音活动检测帧必须为 ${$w} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Za);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 aye{constructor(t={}){bt(this,"startSpeechFrames");bt(this,"endSilenceFrames");bt(this,"active",!1);bt(this,"speechFrames",0);bt(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 lye{constructor(){bt(this,"pending",new Float32Array(Za));bt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Za-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Za&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Za<=t.length;)n(t.slice(r,r+Za)),r+=Za;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const cye="/__dev_anywhere_debug/voice-fixture",uye=td*QB/1e3;function dye(){return CE.create(3)}const hye={createVad:dye,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function fye(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 pye(e){for(const t of e.getTracks())t.stop()}function Zj(e){const t=e.createAudioContext({sampleRate:td});if(t.sampleRate!==td)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function mye(e){const t=Zj(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:td}})}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(),pye(n),t.state!=="closed"&&await t.close()}}}async function gye(e,t){const n=Zj(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 Qj(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:cye}:{kind:"microphone"}}async function vye(e,t=hye){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await gye(e.source.url,t):await mye(t)}catch(h){throw n.destroy(),h}const i=new aye,s=new lye,o=r.context.createScriptProcessor(uye,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=eye(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:fye(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 Jj(e=kv().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function yye(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function bye({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=yye(e);return g.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&g.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),g.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function _ye(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 wye(){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(_ye(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const yu="min-h-9 gap-2.5",rg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function Sye({label:e}){return g.jsxs(mo,{className:"relative",children:[g.jsx(FD,{className:"size-4","aria-hidden":"true"}),g.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 xye({sessionId:e,mode:t,onFind:n}){const r=Jj(),i=Qs(),s=$t(ge=>ge.sessions.find(rt=>rt.sessionId===e)),o=$t(ge=>ge.ptyTitles[e]),l=Oe(ge=>ge.ptyFontSize),u=Oe(ge=>ge.chatContentFontSize),d=Oe(ge=>ge.selectedProxyId),h=Oe(ge=>ge.adjustPtyFontSize),p=Oe(ge=>ge.adjustChatContentFontSize),y=Oe(ge=>ge.setChatContentFontSize),v=Oe(ge=>ge.resetPtyFontSize),_=Oe(ge=>ge.resetChatContentFontSize),w=Oe(ge=>ge.inputModePreference==="hardware"),E=$t(ge=>ge.renameSession),x=Fx(d,e),k=$t(ge=>x?!!ge.ptyAutoYesBySessionKey[x]:!1),R=$t(ge=>ge.setPtyAutoYes),L=fl("(pointer: coarse), (hover: none)")&&!w,T=t==="pty"||(s==null?void 0:s.mode)==="pty",H=(s==null?void 0:s.kind)==="terminal",D=Kj(e),U=ln(ge=>ge.bySessionId[e]??ay),W=ln(ge=>ge.enable),F=ln(ge=>ge.disable),O=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Jx(s),z=O&&(s==null?void 0:s.name)||M||T&&o||(s==null?void 0:s.name)||e.slice(0,8),P=!!(T&&!H&&o&&!O),N=T?l:Bx(u,L),q=!T&&L?dL:cL,V=T?v:_,[$,I]=b.useState(!1),[Y,G]=b.useState(!1),j=U.enabled,ee=D.active||j,J=D.pending||!D.supported||j;function te(ge){if(T){h(ge);return}if(L){y(N+ge);return}p(ge)}function Q(){D.toggle().catch(ge=>{tt.error(ge instanceof Error?ge.message:String(ge))})}async function fe(ge){var et;if(T||H){tt.info("Voice Pilot 目前适用于聊天会话。");return}if(ge!==!0){F(e);return}const rt=Pt;if(!rt){tt.error("请先连接开发机");return}try{if(!((et=(await rt.requestVoiceConfig()).config)!=null&&et.configured)){tt.info("请先在设置里配置 Voice Pilot。");return}I(!0)}catch(ye){tt.error(ye instanceof Error?ye.message:String(ye))}}async function ce(){var ye;G(!0);let ge=null,rt=!1;const et=Xj(e);try{Xh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((ye=navigator.userActivation)==null?void 0:ye.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Pe=Xa.enable(et).then(()=>{Xh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ge=>{throw Xh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ge instanceof Error?Ge.message:String(Ge)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ge})});ge=j1.acquire("capture");const Ue=Lg.prepare(),Se=Qj().kind==="microphone"?wye():Promise.resolve();await Promise.all([Pe,Ue,Se]),W(e),rt=!0,I(!1)}catch(Pe){Xh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Pe instanceof Error?Pe.message:String(Pe)}}),tt.error(Pe instanceof Error?Pe.message:String(Pe))}finally{ge==null||ge.release(),rt||await Xa.disable(et).catch(()=>{}),G(!1)}}const Ee=b.useRef(null),Me=b.useRef(null),[Ie,Ye]=b.useState(!1);async function xt(ge){var Pe;const rt=(Pe=ge.target.files)==null?void 0:Pe[0];if(ge.target.value="",!rt)return;const et=Pt;if(!et){tt.error("请先连接开发机");return}const ye=await kf({relay:et,sessionId:e,file:rt});ye&&Ys(e,`@${ye} `)}async function gn(ge,rt){const et=Pt;if(!et)throw new Error("请先连接开发机");const ye=await et.renameSession(ge,rt);if(!ye.success)throw new Error(ye.error??"重命名失败");E(ge,ye.name??rt),tt.success("已重命名会话")}return g.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[g.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:g.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:[g.jsx("div",{className:"flex justify-start",children:g.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(wv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(bye,{title:z,isPtyTitle:P})}),g.jsxs(L1,{modal:!1,children:[g.jsx(I1,{asChild:!0,children:g.jsx(Ct,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(S9,{"aria-hidden":"true"})})}),g.jsxs(z1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(Fm,{className:rg,children:"会话"}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(mo,{children:g.jsx(Bg,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-rename",onSelect:()=>Ye(!0),children:[g.jsx(mo,{children:g.jsx(c7,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(Q_,{checked:ee,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:J,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Q,children:[g.jsx(mo,{children:g.jsx(W9,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:D.supported?j?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":D.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),T&&!H&&g.jsxs(Q_,{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:ge=>{x&&R(x,ge===!0)},children:[g.jsx(mo,{children:g.jsx(ra,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!T&&!H&&g.jsxs(Q_,{checked:U.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:fe,children:[g.jsx(mo,{children:g.jsx(X9,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(J_,{}),T&&!H?g.jsxs(g.Fragment,{children:[g.jsx(Fm,{className:rg,children:"快捷键"}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ys(e,""),children:[g.jsx(Sye,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(J_,{}),g.jsx(Fm,{className:rg,children:"文件"}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ge;return(ge=Me.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(Lf,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ge;return(ge=Ee.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(qD,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(J_,{})]}):null,g.jsx(Fm,{className:rg,children:"字号"}),g.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:g.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:[g.jsx(mo,{children:g.jsx(D7,{"aria-hidden":"true"})}),g.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[g.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:N<=q,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ge=>{ge.stopPropagation(),te(-1)},children:g.jsx(Q9,{"aria-hidden":"true"})}),g.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:[N,"px"]}),g.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:N>=uL,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ge=>{ge.stopPropagation(),te(1)},children:g.jsx(h7,{"aria-hidden":"true"})})]})]})}),g.jsxs(_o,{className:yu,"data-slot":"chat-menu-font-reset",onClick:V,children:[g.jsx(mo,{children:g.jsx(m7,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(Fh,{open:Ie,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Ye,onRename:gn}),g.jsx(Ec,{open:$&&!U.enabled,onOpenChange:ge=>{Y||I(ge)},children:g.jsxs(Cc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(kc,{children:[g.jsx(hl,{children:"开启 Voice Pilot?"}),g.jsx(hc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Zu,{children:[g.jsx(Ct,{type:"button",variant:"outline",disabled:Y,onClick:()=>I(!1),children:"取消"}),g.jsx(Ct,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Y,onClick:()=>{ce()},children:Y?"正在开启...":"开启 Voice Pilot"})]})]})}),T?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Me,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ge=>{xt(ge)}}),g.jsx("input",{ref:Ee,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ge=>{xt(ge)}})]}):null]})}function bu(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let h;n.key&&((l=n.debug)!=null&&l.call(n))&&(h=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()-h)*100)/100,w=Math.round((Date.now()-v)*100)/100,E=w/16,x=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
668
668
  font-size: .6rem;
669
669
  font-weight: bold;
670
670
  color: hsl(${Math.max(0,Math.min(120-120*E,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 pO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Eye=(e,t)=>Math.abs(e-t)<1.01,Cye=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},mO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},kye=e=>e,Tye=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},Rye=(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(mO(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(mO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},gO={passive:!0},vO=typeof window>"u"?!0:"onscrollend"in window,Aye=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&vO?()=>{}:Cye(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=h=>()=>{const{horizontal:p,isRtl:y}=e.options;i=p?n.scrollLeft*(y&&-1||1):n.scrollTop,s(),t(i,h)},l=o(!0),u=o(!1);n.addEventListener("scroll",l,gO);const d=e.options.useScrollendEvent&&vO;return d&&n.addEventListener("scrollend",u,gO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},Nye=(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"]},Mye=(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 Oye{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:kye,rangeExtractor:Tye,onChange:()=>{},measureElement:Nye,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=bu(()=>(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=bu(()=>[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=bu(()=>[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 h=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,h),y=new Array(l).fill(void 0);for(let v=0;v<h;v++){const _=p[v];_&&(y[_.lane]=v)}for(let v=h;v<n;v++){const _=s(v),w=this.laneAssignments.get(v);let E,x;const k=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){E=w;const T=y[E],H=T!==void 0?p[T]:void 0;x=H?H.end+this.options.gap:r+i}else{const T=this.options.lanes===1?p[v-1]:this.getFurthestMeasurement(p,v);x=T?T.end+this.options.gap:r+i,E=T?T.lane:v%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(v,E)}const R=d.get(_),A=typeof R=="number"?R:this.options.estimateSize(v),L=x+A;p[v]={index:v,start:x,size:A,end:L,key:_,lane:E},y[E]=v}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=bu(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?Pye({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=bu(()=>{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=bu(()=>[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 pO(r[e4(0,r.length-1,i=>pO(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&&Eye(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 e4=(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 Pye({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=e4(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(h=>h<n+t);){const h=e[l];u[h.lane]=h.end,l++}const d=Array(r).fill(n+t);for(;o>=0&&d.some(h=>h>=n);){const h=e[o];d[h.lane]=h.start,o--}o=Math.max(0,o-o%r),l=Math.min(i,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}const yO=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Dye({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?od.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new Oye(r));return i.setOptions(r),yO(()=>i._didMount(),[]),yO(()=>i._willUpdate()),i}function Lye(e){return Dye({observeElementRect:Rye,observeElementOffset:Aye,scrollToFn:Mye,...e})}function kE(e){const t=Ej(e).map(n=>({kind:"image",...n}));for(const n of Nj(e)){const{start:r,end:i}=n;t.some(s=>r<s.end&&i>s.start)||t.push({kind:"file",...n})}return t.sort((n,r)=>n.start-r.start)}function Iye(e){const t=kE(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 zye(e){return e.kind==="diff"}const Bye=12e4;function bO(e){return e?e.replace(/\r\n?/gu,`