@dev-anywhere/relay 0.5.21 → 0.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/web/assets/{fvad-QBrzThuq.js → fvad-QW-WKQIv.js} +1 -1
- package/assets/web/assets/{index-gVPHGS9-.js → index-C6JjetUL.js} +2 -2
- package/assets/web/index.html +1 -1
- package/assets/web/sw.js +1 -1
- package/dist/{chunk-ZOAJSSWC.js → chunk-TEKJMBGR.js} +28 -15
- package/dist/{chunk-ZOAJSSWC.js.map → chunk-TEKJMBGR.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/remote-file-bridge.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/package.json +2 -2
|
@@ -507,7 +507,7 @@ ${t}`:e:t}function z_(e,t,n){const r=$g(t),i=$g(n);return!r&&!i?null:{kind:"diff
|
|
|
507
507
|
|
|
508
508
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
509
509
|
|
|
510
|
-
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},QJ="DialogDescriptionWarning",JJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${MI(QJ).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},r1=vI,eee=bI,i1=wI,s1=SI,o1=xI,OI=CI,DI=TI,a1=AI;function tee(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 nee(e){const[t,n]=b.useState(void 0);return Ei(()=>{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 ree=["top","right","bottom","left"],al=Math.min,as=Math.max,Ug=Math.round,zm=Math.floor,So=e=>({x:e,y:e}),iee={left:"right",right:"left",bottom:"top",top:"bottom"};function T0(e,t,n){return as(e,al(t,n))}function ra(e,t){return typeof e=="function"?e(t):e}function ia(e){return e.split("-")[0]}function ad(e){return e.split("-")[1]}function l1(e){return e==="x"?"y":"x"}function c1(e){return e==="y"?"height":"width"}function _o(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function u1(e){return l1(_o(e))}function see(e,t,n){n===void 0&&(n=!1);const r=ad(e),i=u1(e),s=c1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Wg(o)),[o,Wg(o)]}function oee(e){const t=Wg(e);return[R0(e),t,R0(t)]}function R0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const wN=["left","right"],SN=["right","left"],aee=["top","bottom"],lee=["bottom","top"];function cee(e,t,n){switch(e){case"top":case"bottom":return n?t?SN:wN:t?wN:SN;case"left":case"right":return t?aee:lee;default:return[]}}function uee(e,t,n,r){const i=ad(e);let s=cee(ia(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(R0)))),s}function Wg(e){const t=ia(e);return iee[t]+e.slice(t.length)}function dee(e){return{top:0,right:0,bottom:0,left:0,...e}}function PI(e){return typeof e!="number"?dee(e):{top:e,right:e,bottom:e,left:e}}function qg(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 xN(e,t,n){let{reference:r,floating:i}=e;const s=_o(t),o=u1(t),l=c1(o),u=ia(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(ad(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 hee(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}=ra(t,e),_=PI(v),x=l[y?p==="floating"?"reference":"floating":p],E=qg(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.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},I=qg(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(E.top-I.top+_.top)/A.y,bottom:(I.bottom-E.bottom+_.bottom)/A.y,left:(E.left-I.left+_.left)/A.x,right:(I.right-E.right+_.right)/A.x}}const fee=50,pee=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:hee},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}=xN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:R,y:A,data:I,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,_[E]={..._[E],...I},T&&v<fee&&(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}=xN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:_}},mee=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}=ra(e,t)||{};if(d==null)return{};const p=PI(h),y={x:n,y:r},v=u1(i),_=c1(v),w=await o.getDimensions(d),x=v==="y",E=x?"top":"left",k=x?"bottom":"right",R=x?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[v]-y[v]-s.floating[_],I=y[v]-s.reference[v],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let $=T?T[R]:0;(!$||!await(o.isElement==null?void 0:o.isElement(T)))&&($=l.floating[R]||s.floating[_]);const P=A/2-I/2,W=$/2-w[_]/2-1,U=al(p[E],W),F=al(p[k],W),D=U,M=$-w[_]-F,B=$/2-w[_]/2+P,O=T0(D,B,M),N=!u.arrow&&ad(i)!=null&&B!==O&&s.reference[_]/2-(B<D?U:F)-w[_]/2<0,V=N?B<D?B-D:B-M:0;return{[v]:y[v]+V,data:{[v]:O,centerOffset:B-O-V,...N&&{alignmentOffset:V}},reset:N}}}),gee=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,...x}=ra(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=ia(i),k=_o(l),R=ia(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),I=y||(R||!w?[Wg(l)]:oee(l)),T=_!=="none";!y&&T&&I.push(...uee(l,w,_,A));const $=[l,...I],P=await u.detectOverflow(t,x),W=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&W.push(P[E]),p){const B=see(i,o,A);W.push(P[B[0]],P[B[1]])}if(U=[...U,{placement:i,overflows:W}],!W.every(B=>B<=0)){var F,D;const B=(((F=s.flip)==null?void 0:F.index)||0)+1,O=$[B];if(O&&(!(p==="alignment"?k!==_o(O):!1)||U.every(q=>_o(q.placement)===k?q.overflows[0]>0:!0)))return{data:{index:B,overflows:U},reset:{placement:O}};let N=(D=U.filter(V=>V.overflows[0]<=0).sort((V,q)=>V.overflows[1]-q.overflows[1])[0])==null?void 0:D.placement;if(!N)switch(v){case"bestFit":{var M;const V=(M=U.filter(q=>{if(T){const H=_o(q.placement);return H===k||H==="y"}return!0}).map(q=>[q.placement,q.overflows.filter(H=>H>0).reduce((H,L)=>H+L,0)]).sort((q,H)=>q[1]-H[1])[0])==null?void 0:M[0];V&&(N=V);break}case"initialPlacement":N=l;break}if(i!==N)return{reset:{placement:N}}}return{}}}};function EN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function CN(e){return ree.some(t=>e[t]>=0)}const vee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ra(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=EN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:CN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=EN(o,n.floating);return{data:{escapedOffsets:l,escaped:CN(l)}}}default:return{}}}}},LI=new Set(["left","top"]);async function yee(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=ia(n),l=ad(n),u=_o(n)==="y",d=LI.has(o)?-1:1,h=s&&u?-1:1,p=ra(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 yee(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}}}}},_ee=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:E=>{let{x:k,y:R}=E;return{x:k,y:R}}},...d}=ra(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=_o(ia(i)),v=l1(y);let _=h[v],w=h[y];if(o){const E=v==="y"?"top":"left",k=v==="y"?"bottom":"right",R=_+p[E],A=_-p[k];_=T0(R,_,A)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+p[E],A=w-p[k];w=T0(R,w,A)}const x=u.fn({...t,[v]:_,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[v]:o,[y]:l}}}}}},wee=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}=ra(e,t),h={x:n,y:r},p=_o(i),y=l1(p);let v=h[y],_=h[p];const w=ra(l,t),x=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]+x.mainAxis,I=s.reference[y]+s.reference[R]-x.mainAxis;v<A?v=A:v>I&&(v=I)}if(d){var E,k;const R=y==="y"?"width":"height",A=LI.has(ia(i)),I=s.reference[p]-s.floating[R]+(A&&((E=o.offset)==null?void 0:E[p])||0)+(A?0:x.crossAxis),T=s.reference[p]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?x.crossAxis:0);_<I?_=I:_>T&&(_=T)}return{[y]:v,[p]:_}}}},See=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}=ra(e,t),h=await o.detectOverflow(t,d),p=ia(i),y=ad(i),v=_o(i)==="y",{width:_,height:w}=s.floating;let x,E;p==="top"||p==="bottom"?(x=p,E=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(E=p,x=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,R=_-h.left-h.right,A=al(w-h[x],k),I=al(_-h[E],R),T=!t.middlewareData.shift;let $=A,P=I;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&($=k),T&&!y){const U=as(h.left,0),F=as(h.right,0),D=as(h.top,0),M=as(h.bottom,0);v?P=_-2*(U!==0||F!==0?U+F:as(h.left,h.right)):$=w-2*(D!==0||M!==0?D+M:as(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:$});const W=await o.getDimensions(l.floating);return _!==W.width||w!==W.height?{reset:{rects:!0}}:{}}}};function Ov(){return typeof window<"u"}function ld(e){return II(e)?(e.nodeName||"").toLowerCase():"#document"}function ls(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Ro(e){var t;return(t=(II(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function II(e){return Ov()?e instanceof Node||e instanceof ls(e).Node:!1}function Gs(e){return Ov()?e instanceof Element||e instanceof ls(e).Element:!1}function oa(e){return Ov()?e instanceof HTMLElement||e instanceof ls(e).HTMLElement:!1}function kN(e){return!Ov()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof ls(e).ShadowRoot}function zf(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 xee(e){return/^(table|td|th)$/.test(ld(e))}function Dv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Eee=/transform|translate|scale|rotate|perspective|filter/,Cee=/paint|layout|strict|content/,Hl=e=>!!e&&e!=="none";let q_;function d1(e){const t=Gs(e)?Xs(e):e;return Hl(t.transform)||Hl(t.translate)||Hl(t.scale)||Hl(t.rotate)||Hl(t.perspective)||!h1()&&(Hl(t.backdropFilter)||Hl(t.filter))||Eee.test(t.willChange||"")||Cee.test(t.contain||"")}function kee(e){let t=ll(e);for(;oa(t)&&!qu(t);){if(d1(t))return t;if(Dv(t))return null;t=ll(t)}return null}function h1(){return q_==null&&(q_=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),q_}function qu(e){return/^(html|body|#document)$/.test(ld(e))}function Xs(e){return ls(e).getComputedStyle(e)}function Pv(e){return Gs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ll(e){if(ld(e)==="html")return e;const t=e.assignedSlot||e.parentNode||kN(e)&&e.host||Ro(e);return kN(t)?t.host:t}function zI(e){const t=ll(e);return qu(t)?e.ownerDocument?e.ownerDocument.body:e.body:oa(t)&&zf(t)?t:zI(t)}function pf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=zI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=ls(i);if(s){const l=A0(o);return t.concat(o,o.visualViewport||[],zf(i)?i:[],l&&n?pf(l):[])}else return t.concat(i,pf(i,[],n))}function A0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function BI(e){const t=Xs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=oa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=Ug(n)!==s||Ug(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function f1(e){return Gs(e)?e:e.contextElement}function Bu(e){const t=f1(e);if(!oa(t))return So(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=BI(t);let o=(s?Ug(n.width):n.width)/r,l=(s?Ug(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Tee=So(0);function jI(e){const t=ls(e);return!h1()||!t.visualViewport?Tee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ree(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==ls(e)?!1:t}function ac(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=f1(e);let o=So(1);t&&(r?Gs(r)&&(o=Bu(r)):o=Bu(e));const l=Ree(s,n,r)?jI(s):So(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=ls(s),v=r&&Gs(r)?ls(r):r;let _=y,w=A0(_);for(;w&&r&&v!==_;){const x=Bu(w),E=w.getBoundingClientRect(),k=Xs(w),R=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,A=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=R,d+=A,_=ls(w),w=A0(_)}}return qg({width:h,height:p,x:u,y:d})}function Lv(e,t){const n=Pv(e).scrollLeft;return t?t.left+n:ac(Ro(e)).left+n}function FI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Lv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Aee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=Ro(r),l=t?Dv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=So(1);const h=So(0),p=oa(r);if((p||!p&&!s)&&((ld(r)!=="body"||zf(o))&&(u=Pv(r)),p)){const v=ac(r);d=Bu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?FI(o,u):So(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 Nee(e){return Array.from(e.getClientRects())}function Mee(e){const t=Ro(e),n=Pv(e),r=e.ownerDocument.body,i=as(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=as(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Lv(e);const l=-n.scrollTop;return Xs(r).direction==="rtl"&&(o+=as(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const TN=25;function Oee(e,t){const n=ls(e),r=Ro(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=h1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Lv(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);_<=TN&&(s-=_)}else d<=TN&&(s+=d);return{width:s,height:o,x:l,y:u}}function Dee(e,t){const n=ac(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=oa(e)?Bu(e):So(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 RN(e,t,n){let r;if(t==="viewport")r=Oee(e,n);else if(t==="document")r=Mee(Ro(e));else if(Gs(t))r=Dee(t,n);else{const i=jI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return qg(r)}function $I(e,t){const n=ll(e);return n===t||!Gs(n)||qu(n)?!1:Xs(n).position==="fixed"||$I(n,t)}function Pee(e,t){const n=t.get(e);if(n)return n;let r=pf(e,[],!1).filter(l=>Gs(l)&&ld(l)!=="body"),i=null;const s=Xs(e).position==="fixed";let o=s?ll(e):e;for(;Gs(o)&&!qu(o);){const l=Xs(o),u=d1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||zf(o)&&!u&&$I(e,o))?r=r.filter(h=>h!==o):i=l,o=ll(o)}return t.set(e,r),r}function Lee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Dv(t)?[]:Pee(t,this._c):[].concat(n),r],l=RN(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=RN(t,o[y],i);u=as(v.top,u),d=al(v.right,d),h=al(v.bottom,h),p=as(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function Iee(e){const{width:t,height:n}=BI(e);return{width:t,height:n}}function zee(e,t,n){const r=oa(t),i=Ro(t),s=n==="fixed",o=ac(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=So(0);function d(){u.x=Lv(i)}if(r||!r&&!s)if((ld(t)!=="body"||zf(i))&&(l=Pv(t)),r){const v=ac(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?FI(i,l):So(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 V_(e){return Xs(e).position==="static"}function AN(e,t){if(!oa(e)||Xs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Ro(e)===n&&(n=n.ownerDocument.body),n}function HI(e,t){const n=ls(e);if(Dv(e))return n;if(!oa(e)){let i=ll(e);for(;i&&!qu(i);){if(Gs(i)&&!V_(i))return i;i=ll(i)}return n}let r=AN(e,t);for(;r&&xee(r)&&V_(r);)r=AN(r,t);return r&&qu(r)&&V_(r)&&!d1(r)?n:r||kee(e)||n}const Bee=async function(e){const t=this.getOffsetParent||HI,n=this.getDimensions,r=await n(e.floating);return{reference:zee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function jee(e){return Xs(e).direction==="rtl"}const Fee={convertOffsetParentRelativeRectToViewportRelativeRect:Aee,getDocumentElement:Ro,getClippingRect:Lee,getOffsetParent:HI,getElementRects:Bee,getClientRects:Nee,getDimensions:Iee,getScale:Bu,isElement:Gs,isRTL:jee};function UI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $ee(e,t){let n=null,r;const i=Ro(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 _=zm(p),w=zm(i.clientWidth-(h+y)),x=zm(i.clientHeight-(p+v)),E=zm(h),R={rootMargin:-_+"px "+-w+"px "+-x+"px "+-E+"px",threshold:as(0,al(1,u))||1};let A=!0;function I(T){const $=T[0].intersectionRatio;if($!==u){if(!A)return o();$?o(!1,$):r=setTimeout(()=>{o(!1,1e-7)},1e3)}$===1&&!UI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(I,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(I,R)}n.observe(e)}return o(!0),s}function Hee(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=f1(e),h=i||s?[...d?pf(d):[],...t?pf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?$ee(d,n):null;let y=-1,v=null;o&&(v=new ResizeObserver(E=>{let[k]=E;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?ac(e):null;u&&x();function x(){const E=ac(e);w&&!UI(w,E)&&n(),w=E,_=requestAnimationFrame(x)}return n(),()=>{var E;h.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(E=v)==null||E.disconnect(),v=null,u&&cancelAnimationFrame(_)}}const Uee=bee,Wee=_ee,qee=gee,Vee=See,Yee=vee,NN=mee,Kee=wee,Gee=(e,t,n)=>{const r=new Map,i={platform:Fee,...n},s={...i.platform,_c:r};return pee(e,t,{...i,platform:s})};var Xee=typeof document<"u",Zee=function(){},yg=Xee?b.useLayoutEffect:Zee;function Vg(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(!Vg(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)&&!Vg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function WI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function MN(e,t){const n=WI(e);return Math.round(t*n)/n}function Y_(e){const t=b.useRef(e);return yg(()=>{t.current=e}),t}function Qee(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);Vg(y,r)||v(r);const[_,w]=b.useState(null),[x,E]=b.useState(null),k=b.useCallback(q=>{q!==T.current&&(T.current=q,w(q))},[]),R=b.useCallback(q=>{q!==$.current&&($.current=q,E(q))},[]),A=s||_,I=o||x,T=b.useRef(null),$=b.useRef(null),P=b.useRef(h),W=u!=null,U=Y_(u),F=Y_(i),D=Y_(d),M=b.useCallback(()=>{if(!T.current||!$.current)return;const q={placement:t,strategy:n,middleware:y};F.current&&(q.platform=F.current),Gee(T.current,$.current,q).then(H=>{const L={...H,isPositioned:D.current!==!1};B.current&&!Vg(P.current,L)&&(P.current=L,id.flushSync(()=>{p(L)}))})},[y,t,n,F,D]);yg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(q=>({...q,isPositioned:!1})))},[d]);const B=b.useRef(!1);yg(()=>(B.current=!0,()=>{B.current=!1}),[]),yg(()=>{if(A&&(T.current=A),I&&($.current=I),A&&I){if(U.current)return U.current(A,I,M);M()}},[A,I,M,U,W]);const O=b.useMemo(()=>({reference:T,floating:$,setReference:k,setFloating:R}),[k,R]),N=b.useMemo(()=>({reference:A,floating:I}),[A,I]),V=b.useMemo(()=>{const q={position:n,left:0,top:0};if(!N.floating)return q;const H=MN(N.floating,h.x),L=MN(N.floating,h.y);return l?{...q,transform:"translate("+H+"px, "+L+"px)",...WI(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:L}},[n,l,N.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:M,refs:O,elements:N,floatingStyles:V}),[h,M,O,N,V])}const Jee=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?NN({element:r.current,padding:i}).fn(n):{}:r?NN({element:r,padding:i}).fn(n):{}}}},ete=(e,t)=>{const n=Uee(e);return{name:n.name,fn:n.fn,options:[e,t]}},tte=(e,t)=>{const n=Wee(e);return{name:n.name,fn:n.fn,options:[e,t]}},nte=(e,t)=>({fn:Kee(e).fn,options:[e,t]}),rte=(e,t)=>{const n=qee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ite=(e,t)=>{const n=Vee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ste=(e,t)=>{const n=Yee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ote=(e,t)=>{const n=Jee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var ate="Arrow",qI=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Zt.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"})})});qI.displayName=ate;var lte=qI,p1="Popper",[VI,yl]=sa(p1),[cte,YI]=VI(p1),KI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return g.jsx(cte,{scope:t,anchor:r,onAnchorChange:i,children:n})};KI.displayName=p1;var GI="PopperAnchor",XI=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=YI(GI,n),o=b.useRef(null),l=zn(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(Zt.div,{...i,ref:l})});XI.displayName=GI;var m1="PopperContent",[ute,dte]=VI(m1),ZI=b.forwardRef((e,t)=>{var ee,me,_e,Ce,Oe,Me;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,x=YI(m1,n),[E,k]=b.useState(null),R=zn(t,Ge=>k(Ge)),[A,I]=b.useState(null),T=nee(A),$=(T==null?void 0:T.width)??0,P=(T==null?void 0:T.height)??0,W=r+(s!=="center"?"-"+s:""),U=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},F=Array.isArray(d)?d:[d],D=F.length>0,M={padding:U,boundary:F.filter(fte),altBoundary:D},{refs:B,floatingStyles:O,placement:N,isPositioned:V,middlewareData:q}=Qee({strategy:"fixed",placement:W,whileElementsMounted:(...Ge)=>Hee(...Ge,{animationFrame:v==="always"}),elements:{reference:x.anchor},middleware:[ete({mainAxis:i+P,alignmentAxis:o}),u&&tte({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?nte():void 0,...M}),u&&rte({...M}),ite({...M,apply:({elements:Ge,rects:ct,availableWidth:At,availableHeight:ve})=>{const{width:Ve,height:Rt}=ct.reference,ye=Ge.floating.style;ye.setProperty("--radix-popper-available-width",`${At}px`),ye.setProperty("--radix-popper-available-height",`${ve}px`),ye.setProperty("--radix-popper-anchor-width",`${Ve}px`),ye.setProperty("--radix-popper-anchor-height",`${Rt}px`)}}),A&&ote({element:A,padding:l}),pte({arrowWidth:$,arrowHeight:P}),y&&ste({strategy:"referenceHidden",...M})]}),[H,L]=ez(N),Y=Co(_);Ei(()=>{V&&(Y==null||Y())},[V,Y]);const K=(ee=q.arrow)==null?void 0:ee.x,z=(me=q.arrow)==null?void 0:me.y,Q=((_e=q.arrow)==null?void 0:_e.centerOffset)!==0,[J,ne]=b.useState();return Ei(()=>{E&&ne(window.getComputedStyle(E).zIndex)},[E]),g.jsx("div",{ref:B.setFloating,"data-radix-popper-content-wrapper":"",style:{...O,transform:V?O.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(Ce=q.transformOrigin)==null?void 0:Ce.x,(Oe=q.transformOrigin)==null?void 0:Oe.y].join(" "),...((Me=q.hide)==null?void 0:Me.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(ute,{scope:n,placedSide:H,onArrowChange:I,arrowX:K,arrowY:z,shouldHideArrow:Q,children:g.jsx(Zt.div,{"data-side":H,"data-align":L,...w,ref:R,style:{...w.style,animation:V?void 0:"none"}})})})});ZI.displayName=m1;var QI="PopperArrow",hte={top:"bottom",right:"left",bottom:"top",left:"right"},JI=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=dte(QI,r),o=hte[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(lte,{...i,ref:n,style:{...i.style,display:"block"}})})});JI.displayName=QI;function fte(e){return e!==null}var pte=e=>({name:"transformOrigin",options:e,fn(t){var x,E,k;const{placement:n,rects:r,middlewareData:i}=t,o=((x=i.arrow)==null?void 0:x.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,h]=ez(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.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 ez(e){const[t,n="center"]=e.split("-");return[t,n]}var Iv=KI,Bf=XI,zv=ZI,Bv=JI,K_="rovingFocusGroup.onEntryFocus",mte={bubbles:!1,cancelable:!0},jf="RovingFocusGroup",[N0,tz,gte]=Qx(jf),[vte,nz]=sa(jf,[gte]),[yte,bte]=vte(jf),rz=b.forwardRef((e,t)=>g.jsx(N0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(N0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(_te,{...e,ref:t})})}));rz.displayName=jf;var _te=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=zn(t,y),_=Jx(s),[w,x]=sc({prop:o,defaultProp:l??null,onChange:u,caller:jf}),[E,k]=b.useState(!1),R=Co(d),A=tz(n),I=b.useRef(!1),[T,$]=b.useState(0);return b.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(K_,R),()=>P.removeEventListener(K_,R)},[R]),g.jsx(yte,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(P=>x(P),[x]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>$(P=>P+1),[]),onFocusableItemRemove:b.useCallback(()=>$(P=>P-1),[]),children:g.jsx(Zt.div,{tabIndex:E||T===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:yt(e.onMouseDown,()=>{I.current=!0}),onFocus:yt(e.onFocus,P=>{const W=!I.current;if(P.target===P.currentTarget&&W&&!E){const U=new CustomEvent(K_,mte);if(P.currentTarget.dispatchEvent(U),!U.defaultPrevented){const F=A().filter(N=>N.focusable),D=F.find(N=>N.active),M=F.find(N=>N.id===w),O=[D,M,...F].filter(Boolean).map(N=>N.ref.current);oz(O,h)}}I.current=!1}),onBlur:yt(e.onBlur,()=>k(!1))})})}),iz="RovingFocusGroupItem",sz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=bte(iz,n),p=h.currentTabStopId===d,y=tz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=h;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),g.jsx(N0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Zt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:yt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:yt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:yt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=xte(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(E==="last")R.reverse();else if(E==="prev"||E==="next"){E==="prev"&&R.reverse();const A=R.indexOf(x.currentTarget);R=h.loop?Ete(R,A+1):R.slice(A+1)}setTimeout(()=>oz(R))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});sz.displayName=iz;var wte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ste(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function xte(e,t,n){const r=Ste(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return wte[r]}function oz(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ete(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Cte=rz,kte=sz,M0=["Enter"," "],Tte=["ArrowDown","PageUp","Home"],az=["ArrowUp","PageDown","End"],Rte=[...Tte,...az],Ate={ltr:[...M0,"ArrowRight"],rtl:[...M0,"ArrowLeft"]},Nte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ff="Menu",[mf,Mte,Ote]=Qx(Ff),[bc,lz]=sa(Ff,[Ote,yl,nz]),jv=yl(),cz=nz(),[Dte,_c]=bc(Ff),[Pte,$f]=bc(Ff),uz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=jv(t),[u,d]=b.useState(null),h=b.useRef(!1),p=Co(s),y=Jx(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(Iv,{...l,children:g.jsx(Dte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(Pte,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};uz.displayName=Ff;var Lte="MenuAnchor",g1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bf,{...i,...r,ref:t})});g1.displayName=Lte;var v1="MenuPortal",[Ite,dz]=bc(v1,{forceMount:void 0}),hz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=_c(v1,t);return g.jsx(Ite,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(od,{asChild:!0,container:i,children:r})})})};hz.displayName=v1;var As="MenuContent",[zte,y1]=bc(As),fz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_c(As,e.__scopeMenu),o=$f(As,e.__scopeMenu);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(Bte,{...i,ref:t}):g.jsx(jte,{...i,ref:t})})})})}),Bte=b.forwardRef((e,t)=>{const n=_c(As,e.__scopeMenu),r=b.useRef(null),i=zn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Nv(s)},[]),g.jsx(b1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),jte=b.forwardRef((e,t)=>{const n=_c(As,e.__scopeMenu);return g.jsx(b1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Fte=ol("MenuContent.ScrollLock"),b1=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,x=_c(As,n),E=$f(As,n),k=jv(n),R=cz(n),A=Mte(n),[I,T]=b.useState(null),$=b.useRef(null),P=zn(t,$,x.onContentChange),W=b.useRef(0),U=b.useRef(""),F=b.useRef(0),D=b.useRef(null),M=b.useRef("right"),B=b.useRef(0),O=_?If:b.Fragment,N=_?{as:Fte,allowPinchZoom:!0}:void 0,V=H=>{var ee,me;const L=U.current+H,Y=A().filter(_e=>!_e.disabled),K=document.activeElement,z=(ee=Y.find(_e=>_e.ref.current===K))==null?void 0:ee.textValue,Q=Y.map(_e=>_e.textValue),J=Qte(Q,L,z),ne=(me=Y.find(_e=>_e.textValue===J))==null?void 0:me.ref.current;(function _e(Ce){U.current=Ce,window.clearTimeout(W.current),Ce!==""&&(W.current=window.setTimeout(()=>_e(""),1e3))})(L),ne&&setTimeout(()=>ne.focus())};b.useEffect(()=>()=>window.clearTimeout(W.current),[]),Rv();const q=b.useCallback(H=>{var Y,K;return M.current===((Y=D.current)==null?void 0:Y.side)&&ene(H,(K=D.current)==null?void 0:K.area)},[]);return g.jsx(zte,{scope:n,searchRef:U,onItemEnter:b.useCallback(H=>{q(H)&&H.preventDefault()},[q]),onItemLeave:b.useCallback(H=>{var L;q(H)||((L=$.current)==null||L.focus(),T(null))},[q]),onTriggerLeave:b.useCallback(H=>{q(H)&&H.preventDefault()},[q]),pointerGraceTimerRef:F,onPointerGraceIntentChange:b.useCallback(H=>{D.current=H},[]),children:g.jsx(O,{...N,children:g.jsx(Lf,{asChild:!0,trapped:i,onMountAutoFocus:yt(s,H=>{var L;H.preventDefault(),(L=$.current)==null||L.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(sd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Cte,{asChild:!0,...R,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:T,onEntryFocus:yt(u,H=>{E.isUsingKeyboardRef.current||H.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(zv,{role:"menu","aria-orientation":"vertical","data-state":Az(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:yt(w.onKeyDown,H=>{const Y=H.target.closest("[data-radix-menu-content]")===H.currentTarget,K=H.ctrlKey||H.altKey||H.metaKey,z=H.key.length===1;Y&&(H.key==="Tab"&&H.preventDefault(),!K&&z&&V(H.key));const Q=$.current;if(H.target!==Q||!Rte.includes(H.key))return;H.preventDefault();const ne=A().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);az.includes(H.key)&&ne.reverse(),Xte(ne)}),onBlur:yt(e.onBlur,H=>{H.currentTarget.contains(H.target)||(window.clearTimeout(W.current),U.current="")}),onPointerMove:yt(e.onPointerMove,gf(H=>{const L=H.target,Y=B.current!==H.clientX;if(H.currentTarget.contains(L)&&Y){const K=H.clientX>B.current?"right":"left";M.current=K,B.current=H.clientX}}))})})})})})})});fz.displayName=As;var $te="MenuGroup",_1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Zt.div,{role:"group",...r,ref:t})});_1.displayName=$te;var Hte="MenuLabel",pz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Zt.div,{...r,ref:t})});pz.displayName=Hte;var Yg="MenuItem",ON="menu.itemSelect",Fv=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=$f(Yg,e.__scopeMenu),l=y1(Yg,e.__scopeMenu),u=zn(t,s),d=b.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(ON,{bubbles:!0,cancelable:!0});p.addEventListener(ON,v=>r==null?void 0:r(v),{once:!0}),tI(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(mz,{...i,ref:u,disabled:n,onClick:yt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:yt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:yt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||M0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Fv.displayName=Yg;var mz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=y1(Yg,n),l=cz(n),u=b.useRef(null),d=zn(t,u),[h,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),g.jsx(mf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(kte,{asChild:!0,...l,focusable:!r,children:g.jsx(Zt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:yt(e.onPointerMove,gf(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:yt(e.onPointerLeave,gf(_=>o.onItemLeave(_))),onFocus:yt(e.onFocus,()=>p(!0)),onBlur:yt(e.onBlur,()=>p(!1))})})})}),Ute="MenuCheckboxItem",gz=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(wz,{scope:e.__scopeMenu,checked:n,children:g.jsx(Fv,{role:"menuitemcheckbox","aria-checked":Kg(n)?"mixed":n,...i,ref:t,"data-state":S1(n),onSelect:yt(i.onSelect,()=>r==null?void 0:r(Kg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});gz.displayName=Ute;var vz="MenuRadioGroup",[Wte,qte]=bc(vz,{value:void 0,onValueChange:()=>{}}),yz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Co(r);return g.jsx(Wte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(_1,{...i,ref:t})})});yz.displayName=vz;var bz="MenuRadioItem",_z=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=qte(bz,e.__scopeMenu),s=n===i.value;return g.jsx(wz,{scope:e.__scopeMenu,checked:s,children:g.jsx(Fv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":S1(s),onSelect:yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});_z.displayName=bz;var w1="MenuItemIndicator",[wz,Vte]=bc(w1,{checked:!1}),Sz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=Vte(w1,n);return g.jsx(Ps,{present:r||Kg(s.checked)||s.checked===!0,children:g.jsx(Zt.span,{...i,ref:t,"data-state":S1(s.checked)})})});Sz.displayName=w1;var Yte="MenuSeparator",xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Zt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});xz.displayName=Yte;var Kte="MenuArrow",Ez=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bv,{...i,...r,ref:t})});Ez.displayName=Kte;var Gte="MenuSub",[nRe,Cz]=bc(Gte),Ih="MenuSubTrigger",kz=b.forwardRef((e,t)=>{const n=_c(Ih,e.__scopeMenu),r=$f(Ih,e.__scopeMenu),i=Cz(Ih,e.__scopeMenu),s=y1(Ih,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(g1,{asChild:!0,...d,children:g.jsx(mz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Az(n.open),...e,ref:na(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:yt(e.onPointerMove,gf(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:yt(e.onPointerLeave,gf(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,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],R=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,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:yt(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Ate[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});kz.displayName=Ih;var Tz="MenuSubContent",Rz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_c(As,e.__scopeMenu),o=$f(As,e.__scopeMenu),l=Cz(Tz,e.__scopeMenu),u=b.useRef(null),d=zn(t,u);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:g.jsx(b1,{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:yt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:yt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:yt(e.onKeyDown,h=>{var v;const p=h.currentTarget.contains(h.target),y=Nte[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),h.preventDefault())})})})})})});Rz.displayName=Tz;function Az(e){return e?"open":"closed"}function Kg(e){return e==="indeterminate"}function S1(e){return Kg(e)?"indeterminate":e?"checked":"unchecked"}function Xte(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Zte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Qte(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=Zte(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 Jte(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 ene(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Jte(n,t)}function gf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var tne=uz,nne=g1,rne=hz,ine=fz,sne=_1,one=pz,ane=Fv,lne=gz,cne=yz,une=_z,dne=Sz,hne=xz,fne=Ez,pne=kz,mne=Rz,$v="DropdownMenu",[gne]=sa($v,[lz]),Pi=lz(),[vne,Nz]=gne($v),Mz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Pi(t),d=b.useRef(null),[h,p]=sc({prop:i,defaultProp:s??!1,onChange:o,caller:$v});return g.jsx(vne,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(tne,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};Mz.displayName=$v;var Oz="DropdownMenuTrigger",Dz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Nz(Oz,n),o=Pi(n);return g.jsx(nne,{asChild:!0,...o,children:g.jsx(Zt.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:na(t,s.triggerRef),onPointerDown:yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Dz.displayName=Oz;var yne="DropdownMenuPortal",Pz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Pi(t);return g.jsx(rne,{...r,...n})};Pz.displayName=yne;var Lz="DropdownMenuContent",Iz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Nz(Lz,n),s=Pi(n),o=b.useRef(!1);return g.jsx(ine,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:yt(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)"}})});Iz.displayName=Lz;var bne="DropdownMenuGroup",_ne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(sne,{...i,...r,ref:t})});_ne.displayName=bne;var wne="DropdownMenuLabel",zz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(one,{...i,...r,ref:t})});zz.displayName=wne;var Sne="DropdownMenuItem",Bz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(ane,{...i,...r,ref:t})});Bz.displayName=Sne;var xne="DropdownMenuCheckboxItem",jz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(lne,{...i,...r,ref:t})});jz.displayName=xne;var Ene="DropdownMenuRadioGroup",Cne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(cne,{...i,...r,ref:t})});Cne.displayName=Ene;var kne="DropdownMenuRadioItem",Tne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(une,{...i,...r,ref:t})});Tne.displayName=kne;var Rne="DropdownMenuItemIndicator",Fz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(dne,{...i,...r,ref:t})});Fz.displayName=Rne;var Ane="DropdownMenuSeparator",$z=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(hne,{...i,...r,ref:t})});$z.displayName=Ane;var Nne="DropdownMenuArrow",Mne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(fne,{...i,...r,ref:t})});Mne.displayName=Nne;var One="DropdownMenuSubTrigger",Dne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(pne,{...i,...r,ref:t})});Dne.displayName=One;var Pne="DropdownMenuSubContent",Lne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(mne,{...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)"}})});Lne.displayName=Pne;var Ine=Mz,zne=Dz,Bne=Pz,jne=Iz,Fne=zz,$ne=Bz,Hne=jz,Une=Fz,Wne=$z;function DN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Hv="Popover",[Hz]=sa(Hv,[yl]),Hf=yl(),[qne,bl]=Hz(Hv),Uz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Hf(t),u=b.useRef(null),[d,h]=b.useState(!1),[p,y]=sc({prop:r,defaultProp:i??!1,onChange:s,caller:Hv});return g.jsx(Iv,{...l,children:g.jsx(qne,{scope:t,contentId:gi(),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})})};Uz.displayName=Hv;var Wz="PopoverAnchor",Vne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bl(Wz,n),s=Hf(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(Bf,{...s,...r,ref:t})});Vne.displayName=Wz;var qz="PopoverTrigger",Vz=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bl(qz,n),s=Hf(n),o=zn(t,i.triggerRef),l=g.jsx(Zt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Zz(i.open),...r,ref:o,onClick:yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(Bf,{asChild:!0,...s,children:l})});Vz.displayName=qz;var x1="PopoverPortal",[Yne,Kne]=Hz(x1,{forceMount:void 0}),Yz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=bl(x1,t);return g.jsx(Yne,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(od,{asChild:!0,container:i,children:r})})})};Yz.displayName=x1;var Vu="PopoverContent",Kz=b.forwardRef((e,t)=>{const n=Kne(Vu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=bl(Vu,e.__scopePopover);return g.jsx(Ps,{present:r||s.open,children:s.modal?g.jsx(Xne,{...i,ref:t}):g.jsx(Zne,{...i,ref:t})})});Kz.displayName=Vu;var Gne=ol("PopoverContent.RemoveScroll"),Xne=b.forwardRef((e,t)=>{const n=bl(Vu,e.__scopePopover),r=b.useRef(null),i=zn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Nv(o)},[]),g.jsx(If,{as:Gne,allowPinchZoom:!0,children:g.jsx(Gz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:yt(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:yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Zne=b.forwardRef((e,t)=>{const n=bl(Vu,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return g.jsx(Gz,{...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()}})}),Gz=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=bl(Vu,n),v=Hf(n);return Rv(),g.jsx(Lf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(sd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(zv,{"data-state":Zz(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)"}})})})}),Xz="PopoverClose",Qne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bl(Xz,n);return g.jsx(Zt.button,{type:"button",...r,ref:t,onClick:yt(e.onClick,()=>i.onOpenChange(!1))})});Qne.displayName=Xz;var Jne="PopoverArrow",ere=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Hf(n);return g.jsx(Bv,{...i,...r,ref:t})});ere.displayName=Jne;function Zz(e){return e?"open":"closed"}var tre=Uz,nre=Vz,rre=Yz,ire=Kz,sre=[" ","Enter","ArrowUp","ArrowDown"],ore=[" ","Enter"],lc="Select",[Uv,Wv,are]=Qx(lc),[cd]=sa(lc,[are,yl]),qv=yl(),[lre,_l]=cd(lc),[cre,ure]=cd(lc),Qz=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=qv(t),[x,E]=b.useState(null),[k,R]=b.useState(null),[A,I]=b.useState(!1),T=Jx(d),[$,P]=sc({prop:r,defaultProp:i??!1,onChange:s,caller:lc}),[W,U]=sc({prop:o,defaultProp:l,onChange:u,caller:lc}),F=b.useRef(null),D=x?_||!!x.closest("form"):!0,[M,B]=b.useState(new Set),O=Array.from(M).map(N=>N.props.value).join(";");return g.jsx(Iv,{...w,children:g.jsxs(lre,{required:v,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:I,contentId:gi(),value:W,onValueChange:U,open:$,onOpenChange:P,dir:T,triggerPointerDownPosRef:F,disabled:y,children:[g.jsx(Uv.Provider,{scope:t,children:g.jsx(cre,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(N=>{B(V=>new Set(V).add(N))},[]),onNativeOptionRemove:b.useCallback(N=>{B(V=>{const q=new Set(V);return q.delete(N),q})},[]),children:n})}),D?g.jsxs(_B,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:W,onChange:N=>U(N.target.value),disabled:y,form:_,children:[W===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},O):null]})})};Qz.displayName=lc;var Jz="SelectTrigger",eB=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=qv(n),o=_l(Jz,n),l=o.disabled||r,u=zn(t,o.onTriggerChange),d=Wv(n),h=b.useRef("touch"),[p,y,v]=SB(w=>{const x=d().filter(R=>!R.disabled),E=x.find(R=>R.value===o.value),k=xB(x,w,E);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(Bf,{asChild:!0,...s,children:g.jsx(Zt.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":wB(o.value)?"":void 0,...i,ref:u,onClick:yt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&_(w)}),onPointerDown:yt(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:yt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&sre.includes(w.key)&&(_(),w.preventDefault())})})})});eB.displayName=Jz;var tB="SelectValue",nB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=_l(tB,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=zn(t,u.onValueNodeChange);return Ei(()=>{d(h)},[d,h]),g.jsx(Zt.span,{...l,ref:p,style:{pointerEvents:"none"},children:wB(u.value)?g.jsx(g.Fragment,{children:o}):s})});nB.displayName=tB;var dre="SelectIcon",rB=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Zt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});rB.displayName=dre;var hre="SelectPortal",iB=e=>g.jsx(od,{asChild:!0,...e});iB.displayName=hre;var cc="SelectContent",sB=b.forwardRef((e,t)=>{const n=_l(cc,e.__scopeSelect),[r,i]=b.useState();if(Ei(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?id.createPortal(g.jsx(oB,{scope:e.__scopeSelect,children:g.jsx(Uv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(aB,{...e,ref:t})});sB.displayName=cc;var Us=10,[oB,wl]=cd(cc),fre="SelectContentImpl",pre=ol("SelectContent.RemoveScroll"),aB=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:x,...E}=e,k=_l(cc,n),[R,A]=b.useState(null),[I,T]=b.useState(null),$=zn(t,ee=>A(ee)),[P,W]=b.useState(null),[U,F]=b.useState(null),D=Wv(n),[M,B]=b.useState(!1),O=b.useRef(!1);b.useEffect(()=>{if(R)return Nv(R)},[R]),Rv();const N=b.useCallback(ee=>{const[me,..._e]=D().map(Me=>Me.ref.current),[Ce]=_e.slice(-1),Oe=document.activeElement;for(const Me of ee)if(Me===Oe||(Me==null||Me.scrollIntoView({block:"nearest"}),Me===me&&I&&(I.scrollTop=0),Me===Ce&&I&&(I.scrollTop=I.scrollHeight),Me==null||Me.focus(),document.activeElement!==Oe))return},[D,I]),V=b.useCallback(()=>N([P,R]),[N,P,R]);b.useEffect(()=>{M&&V()},[M,V]);const{onOpenChange:q,triggerPointerDownPosRef:H}=k;b.useEffect(()=>{if(R){let ee={x:0,y:0};const me=Ce=>{var Oe,Me;ee={x:Math.abs(Math.round(Ce.pageX)-(((Oe=H.current)==null?void 0:Oe.x)??0)),y:Math.abs(Math.round(Ce.pageY)-(((Me=H.current)==null?void 0:Me.y)??0))}},_e=Ce=>{ee.x<=10&&ee.y<=10?Ce.preventDefault():R.contains(Ce.target)||q(!1),document.removeEventListener("pointermove",me),H.current=null};return H.current!==null&&(document.addEventListener("pointermove",me),document.addEventListener("pointerup",_e,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",me),document.removeEventListener("pointerup",_e,{capture:!0})}}},[R,q,H]),b.useEffect(()=>{const ee=()=>q(!1);return window.addEventListener("blur",ee),window.addEventListener("resize",ee),()=>{window.removeEventListener("blur",ee),window.removeEventListener("resize",ee)}},[q]);const[L,Y]=SB(ee=>{const me=D().filter(Oe=>!Oe.disabled),_e=me.find(Oe=>Oe.ref.current===document.activeElement),Ce=xB(me,ee,_e);Ce&&setTimeout(()=>Ce.ref.current.focus())}),K=b.useCallback((ee,me,_e)=>{const Ce=!O.current&&!_e;(k.value!==void 0&&k.value===me||Ce)&&(W(ee),Ce&&(O.current=!0))},[k.value]),z=b.useCallback(()=>R==null?void 0:R.focus(),[R]),Q=b.useCallback((ee,me,_e)=>{const Ce=!O.current&&!_e;(k.value!==void 0&&k.value===me||Ce)&&F(ee)},[k.value]),J=r==="popper"?O0:lB,ne=J===O0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:x}:{};return g.jsx(oB,{scope:n,content:R,viewport:I,onViewportChange:T,itemRefCallback:K,selectedItem:P,onItemLeave:z,itemTextRefCallback:Q,focusSelectedItem:V,selectedItemText:U,position:r,isPositioned:M,searchRef:L,children:g.jsx(If,{as:pre,allowPinchZoom:!0,children:g.jsx(Lf,{asChild:!0,trapped:k.open,onMountAutoFocus:ee=>{ee.preventDefault()},onUnmountAutoFocus:yt(i,ee=>{var me;(me=k.trigger)==null||me.focus({preventScroll:!0}),ee.preventDefault()}),children:g.jsx(sd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:ee=>ee.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(J,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:ee=>ee.preventDefault(),...E,...ne,onPlaced:()=>B(!0),ref:$,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:yt(E.onKeyDown,ee=>{const me=ee.ctrlKey||ee.altKey||ee.metaKey;if(ee.key==="Tab"&&ee.preventDefault(),!me&&ee.key.length===1&&Y(ee.key),["ArrowUp","ArrowDown","Home","End"].includes(ee.key)){let Ce=D().filter(Oe=>!Oe.disabled).map(Oe=>Oe.ref.current);if(["ArrowUp","End"].includes(ee.key)&&(Ce=Ce.slice().reverse()),["ArrowUp","ArrowDown"].includes(ee.key)){const Oe=ee.target,Me=Ce.indexOf(Oe);Ce=Ce.slice(Me+1)}setTimeout(()=>N(Ce)),ee.preventDefault()}})})})})})})});aB.displayName=fre;var mre="SelectItemAlignedPosition",lB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=_l(cc,n),o=wl(cc,n),[l,u]=b.useState(null),[d,h]=b.useState(null),p=zn(t,$=>h($)),y=Wv(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const $=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),W=s.valueNode.getBoundingClientRect(),U=E.getBoundingClientRect();if(s.dir!=="rtl"){const Oe=U.left-P.left,Me=W.left-Oe,Ge=$.left-Me,ct=$.width+Ge,At=Math.max(ct,P.width),ve=window.innerWidth-Us,Ve=DN(Me,[Us,Math.max(Us,ve-At)]);l.style.minWidth=ct+"px",l.style.left=Ve+"px"}else{const Oe=P.right-U.right,Me=window.innerWidth-W.right-Oe,Ge=window.innerWidth-$.right-Me,ct=$.width+Ge,At=Math.max(ct,P.width),ve=window.innerWidth-Us,Ve=DN(Me,[Us,Math.max(Us,ve-At)]);l.style.minWidth=ct+"px",l.style.right=Ve+"px"}const F=y(),D=window.innerHeight-Us*2,M=w.scrollHeight,B=window.getComputedStyle(d),O=parseInt(B.borderTopWidth,10),N=parseInt(B.paddingTop,10),V=parseInt(B.borderBottomWidth,10),q=parseInt(B.paddingBottom,10),H=O+N+M+q+V,L=Math.min(x.offsetHeight*5,H),Y=window.getComputedStyle(w),K=parseInt(Y.paddingTop,10),z=parseInt(Y.paddingBottom,10),Q=$.top+$.height/2-Us,J=D-Q,ne=x.offsetHeight/2,ee=x.offsetTop+ne,me=O+N+ee,_e=H-me;if(me<=Q){const Oe=F.length>0&&x===F[F.length-1].ref.current;l.style.bottom="0px";const Me=d.clientHeight-w.offsetTop-w.offsetHeight,Ge=Math.max(J,ne+(Oe?z:0)+Me+V),ct=me+Ge;l.style.height=ct+"px"}else{const Oe=F.length>0&&x===F[0].ref.current;l.style.top="0px";const Ge=Math.max(Q,O+w.offsetTop+(Oe?K:0)+ne)+_e;l.style.height=Ge+"px",w.scrollTop=me-Q+w.offsetTop}l.style.margin=`${Us}px 0`,l.style.minHeight=L+"px",l.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ei(()=>R(),[R]);const[A,I]=b.useState();Ei(()=>{d&&I(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback($=>{$&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return g.jsx(vre,{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(Zt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});lB.displayName=mre;var gre="SelectPopperPosition",O0=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Us,...s}=e,o=qv(n);return g.jsx(zv,{...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)"}})});O0.displayName=gre;var[vre,E1]=cd(cc,{}),D0="SelectViewport",cB=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=wl(D0,n),o=E1(D0,n),l=zn(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(Uv.Slot,{scope:n,children:g.jsx(Zt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:yt(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-Us*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<_){const k=E+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})})})]})});cB.displayName=D0;var uB="SelectGroup",[yre,bre]=cd(uB),_re=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return g.jsx(yre,{scope:n,id:i,children:g.jsx(Zt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});_re.displayName=uB;var dB="SelectLabel",wre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bre(dB,n);return g.jsx(Zt.div,{id:i.id,...r,ref:t})});wre.displayName=dB;var Gg="SelectItem",[Sre,hB]=cd(Gg),fB=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=_l(Gg,n),u=wl(Gg,n),d=l.value===r,[h,p]=b.useState(s??""),[y,v]=b.useState(!1),_=zn(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=gi(),x=b.useRef("touch"),E=()=>{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(Sre,{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(Uv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Zt.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:yt(o.onFocus,()=>v(!0)),onBlur:yt(o.onBlur,()=>v(!1)),onClick:yt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:yt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:yt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:yt(o.onPointerMove,k=>{var R;x.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:yt(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:yt(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(ore.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});fB.displayName=Gg;var zh="SelectItemText",pB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=_l(zh,n),l=wl(zh,n),u=hB(zh,n),d=ure(zh,n),[h,p]=b.useState(null),y=zn(t,E=>p(E),u.onItemTextChange,E=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,E,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:x}=d;return Ei(()=>(w(_),()=>x(_)),[w,x,_]),g.jsxs(g.Fragment,{children:[g.jsx(Zt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?id.createPortal(s.children,o.valueNode):null]})});pB.displayName=zh;var mB="SelectItemIndicator",gB=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return hB(mB,n).isSelected?g.jsx(Zt.span,{"aria-hidden":!0,...r,ref:t}):null});gB.displayName=mB;var P0="SelectScrollUpButton",vB=b.forwardRef((e,t)=>{const n=wl(P0,e.__scopeSelect),r=E1(P0,e.__scopeSelect),[i,s]=b.useState(!1),o=zn(t,r.onScrollButtonChange);return Ei(()=>{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(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});vB.displayName=P0;var L0="SelectScrollDownButton",yB=b.forwardRef((e,t)=>{const n=wl(L0,e.__scopeSelect),r=E1(L0,e.__scopeSelect),[i,s]=b.useState(!1),o=zn(t,r.onScrollButtonChange);return Ei(()=>{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(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});yB.displayName=L0;var bB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=wl("SelectScrollButton",n),o=b.useRef(null),l=Wv(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ei(()=>{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(Zt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:yt(i.onPointerLeave,()=>{u()})})}),xre="SelectSeparator",Ere=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Zt.div,{"aria-hidden":!0,...r,ref:t})});Ere.displayName=xre;var I0="SelectArrow",Cre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qv(n),s=_l(I0,n),o=wl(I0,n);return s.open&&o.position==="popper"?g.jsx(Bv,{...i,...r,ref:t}):null});Cre.displayName=I0;var kre="SelectBubbleInput",_B=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=zn(r,i),o=tee(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(Zt.select,{...n,style:{...nI,...n.style},ref:s,defaultValue:t})});_B.displayName=kre;function wB(e){return e===""||e===void 0}function SB(e){const t=Co(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 xB(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=Tre(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 Tre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Rre=Qz,Are=eB,Nre=nB,Mre=rB,Ore=iB,Dre=sB,Pre=cB,Lre=fB,Ire=pB,zre=gB,Bre=vB,jre=yB,[Vv]=sa("Tooltip",[yl]),Yv=yl(),EB="TooltipProvider",Fre=700,z0="tooltip.open",[$re,C1]=Vv(EB),CB=e=>{const{__scopeTooltip:t,delayDuration:n=Fre,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($re,{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})};CB.displayName=EB;var vf="Tooltip",[Hre,Uf]=Vv(vf),kB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=C1(vf,e.__scopeTooltip),d=Yv(t),[h,p]=b.useState(null),y=gi(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,x=b.useRef(!1),[E,k]=sc({prop:r,defaultProp:i??!1,onChange:$=>{$?(u.onOpen(),document.dispatchEvent(new CustomEvent(z0))):u.onClose(),s==null||s($)},caller:vf}),R=b.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,k(!0)},[k]),I=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Iv,{...d,children:g.jsx(Hre,{scope:t,contentId:y,open:E,stateAttribute:R,trigger:h,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?I():(window.clearTimeout(v.current),v.current=0)},[I,_]),onOpen:A,onClose:I,disableHoverableContent:_,children:n})})};kB.displayName=vf;var B0="TooltipTrigger",TB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Uf(B0,n),s=C1(B0,n),o=Yv(n),l=b.useRef(null),u=zn(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(Bf,{asChild:!0,...o,children:g.jsx(Zt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:yt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:yt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:yt(e.onBlur,i.onClose),onClick:yt(e.onClick,i.onClose)})})});TB.displayName=B0;var k1="TooltipPortal",[Ure,Wre]=Vv(k1,{forceMount:void 0}),RB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Uf(k1,t);return g.jsx(Ure,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(od,{asChild:!0,container:i,children:r})})})};RB.displayName=k1;var Yu="TooltipContent",AB=b.forwardRef((e,t)=>{const n=Wre(Yu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Uf(Yu,e.__scopeTooltip);return g.jsx(Ps,{present:r||o.open,children:o.disableHoverableContent?g.jsx(NB,{side:i,...s,ref:t}):g.jsx(qre,{side:i,...s,ref:t})})}),qre=b.forwardRef((e,t)=>{const n=Uf(Yu,e.__scopeTooltip),r=C1(Yu,e.__scopeTooltip),i=b.useRef(null),s=zn(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 x=_.currentTarget,E={x:_.clientX,y:_.clientY},k=Gre(E,x.getBoundingClientRect()),R=Xre(E,k),A=Zre(w.getBoundingClientRect()),I=Jre([...R,...A]);l(I),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&h){const _=x=>v(x,h),w=x=>v(x,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 x=w.target,E={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),R=!Qre(E,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,h,o,d,y]),g.jsx(NB,{...e,ref:s})}),[Vre,Yre]=Vv(vf,{isInside:!1}),Kre=TQ("TooltipContent"),NB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Uf(Yu,n),d=Yv(n),{onClose:h}=u;return b.useEffect(()=>(document.addEventListener(z0,h),()=>document.removeEventListener(z0,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(sd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(zv,{"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(Kre,{children:r}),g.jsx(Vre,{scope:n,isInside:!0,children:g.jsx(iI,{id:u.contentId,role:"tooltip",children:i||r})})]})})});AB.displayName=Yu;var MB="TooltipArrow",OB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Yv(n);return Yre(MB,n).isInside?null:g.jsx(Bv,{...i,...r,ref:t})});OB.displayName=MB;function Gre(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 Xre(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 Zre(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 Qre(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,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 Jre(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),eie(t)}function eie(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 tie=CB,nie=kB,rie=TB,iie=RB,sie=AB,oie=OB;function T1({...e}){return g.jsx(tre,{"data-slot":"popover",...e})}function R1({...e}){return g.jsx(nre,{"data-slot":"popover-trigger",...e})}function A1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(rre,{children:g.jsx(ire,{"data-slot":"popover-content",align:t,sideOffset:n,className:qe("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 aie={"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 tc({variant:e,action:t}){const{heading:n,body:r}=aie[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 lie={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},cie={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function PN({status:e,className:t}){return g.jsx("span",{className:qe("inline-block w-2 h-2 rounded-full shrink-0",lie[e],t),role:"status","aria-label":cie[e]})}function DB({layout:e,variant:t="default"}){const n=Ne(_=>_.proxies),r=Ne(_=>_.proxyListLoaded),i=Ne(_=>_.relayClientAuthIssue),s=Ne(_=>_.selectedProxyId),o=Ne(_=>_.proxySwitchTarget),l=Di(),u=Qs(),[d,h]=b.useState(!1);async function p(_,w){if(o)return;const x=Nt;if(!x){Je.error("请先连接开发机");return}const E=w??_,k=s!==null&&s!==_;Ne.getState().setProxySwitchTarget({proxyId:_,name:E});try{const R=await x.selectProxy(_);if(!R.success){Je.error(`无法连接 ${E}:${R.error??"未知错误"}`);return}k&&(zt.getState().prepareForProxySwitch(E),ii.getState().prepareForProxySwitch()),dr("local",cn.proxyId,_),Ne.getState().setProxy(_,w??null),Ne.getState().setProxyOnline(!0),Ne.getState().transitionToPhase("session_browsing"),x.sendControl({type:"session_list"}),x.requestProxyInfo().then(A=>{if(Ne.getState().selectedProxyId!==_)return;const I=ii.getState();I.setHomePath(A.homePath),I.setAgentCli(A.agentCli)}).catch(A=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",A)}),x.requestAgentStatuses().then(A=>{if(Ne.getState().selectedProxyId!==_)return;const I=zt.getState();for(const T of A)I.setAgentStatus(T.sessionId,T.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),x.requestSessionHistory().then(A=>{Ne.getState().selectedProxyId===_&&zt.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:"未知错误";Je.error(`无法连接 ${E}:${A}`)}finally{Ne.getState().setProxySwitchTarget(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(tc,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(tc,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(tc,{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,x=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||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:qe("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",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx(PN,{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(Jl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===_.proxyId?g.jsx(ta,{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(Jl,{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(T1,{open:d,onOpenChange:h,children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:qe("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:qe("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:v}),g.jsx(pl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(A1,{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,x=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||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:qe("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",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线",children:[g.jsx(PN,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsx(Jl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===_.proxyId?g.jsx(ta,{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 LN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,IN=BP,uie=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return IN(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=LN(h)||LN(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,x]=_;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return IN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},die=uie("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 bt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?CQ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:qe(die({variant:t,size:n,className:e})),...i})}function hie({delayDuration:e=0,...t}){return g.jsx(tie,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Wf({...e}){return g.jsx(nie,{"data-slot":"tooltip",...e})}function qf({...e}){return g.jsx(rie,{"data-slot":"tooltip-trigger",...e})}function Vf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(iie,{children:g.jsxs(sie,{"data-slot":"tooltip-content",sideOffset:t,className:qe("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(oie,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Kv({...e}){return g.jsx(r1,{"data-slot":"sheet",...e})}function fie({...e}){return g.jsx(eee,{"data-slot":"sheet-trigger",...e})}function pie({...e}){return g.jsx(i1,{"data-slot":"sheet-portal",...e})}function mie({className:e,...t}){return g.jsx(s1,{"data-slot":"sheet-overlay",className:qe("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 Gv({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(mie,{className:t}),g.jsxs(o1,{"data-slot":"sheet-content",className:qe("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(a1,{"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(ed,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function N1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:qe("flex flex-col gap-1.5 p-4",e),...t})}function Xv({className:e,...t}){return g.jsx(OI,{"data-slot":"sheet-title",className:qe("font-semibold text-foreground",e),...t})}function gie({className:e,...t}){return g.jsx(DI,{"data-slot":"sheet-description",className:qe("text-sm text-muted-foreground",e),...t})}function M1({...e}){return g.jsx(Ine,{"data-slot":"dropdown-menu",...e})}function O1({...e}){return g.jsx(zne,{"data-slot":"dropdown-menu-trigger",...e})}function D1({className:e,sideOffset:t=4,...n}){return g.jsx(Bne,{children:g.jsx(jne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:qe("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 yo({className:e,inset:t,variant:n="default",...r}){return g.jsx($ne,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:qe("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 G_({className:e,children:t,checked:n,...r}){return g.jsxs(Hne,{"data-slot":"dropdown-menu-checkbox-item",className:qe("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(Une,{children:g.jsx(ta,{className:"size-4"})})}),t]})}function Bm({className:e,inset:t,...n}){return g.jsx(Fne,{"data-slot":"dropdown-menu-label","data-inset":t,className:qe("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function X_({className:e,...t}){return g.jsx(Wne,{"data-slot":"dropdown-menu-separator",className:qe("-mx-1 my-1 h-px bg-border",e),...t})}const vie={claude:"Claude Code",codex:"Codex"},zN=["claude","codex"];function Zv(e){return vie[e]}function PB(e,t){return zN.indexOf(e)-zN.indexOf(t)}function j0(e){return e.provider??"claude"}const F0=60*1e3,$0=60*F0,yie=24*$0;function LB(e,t=Date.now()){const n=t-e;if(n<F0)return"刚刚";if(n<$0)return`${Math.floor(n/F0)} 分钟前`;if(n<yie)return`${Math.floor(n/$0)} 小时前`;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 BN={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 H0(e){return e.kind!=="terminal"?BN[e.state]:e.state==="terminated"?BN.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=H0(e);return g.jsx("span",{className:qe("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function _ie({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;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 wie({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=kv(e.name),d=Kx(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?LB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:qe("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(_ie,{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:Zv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:qe("shrink-0",H0(e).text),children:H0(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(M1,{children:[g.jsx(O1,{asChild:!0,children:g.jsx(bt,{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(f8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(yo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(yo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function wc({...e}){return g.jsx(r1,{"data-slot":"dialog",...e})}function Sie({...e}){return g.jsx(i1,{"data-slot":"dialog-portal",...e})}function xie({className:e,...t}){return g.jsx(s1,{"data-slot":"dialog-overlay",className:qe("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 Sc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs(Sie,{"data-slot":"dialog-portal",children:[g.jsx(xie,{}),g.jsxs(o1,{"data-slot":"dialog-content",className:qe("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(a1,{"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(ed,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function xc({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:qe("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Ku({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:qe("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(a1,{asChild:!0,children:g.jsx(bt,{variant:"outline",children:"Close"})})]})}function cl({className:e,...t}){return g.jsx(OI,{"data-slot":"dialog-title",className:qe("text-lg leading-none font-semibold",e),...t})}function uc({className:e,...t}){return g.jsx(DI,{"data-slot":"dialog-description",className:qe("text-sm text-muted-foreground",e),...t})}function ul(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 Eie({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(Cie,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:LB(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:qe("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(j9,{className:qe("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 Cie({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(kie,{mode:t})]})}function kie({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:qe("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 IB({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(m7,{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 Tie({now:e}){const t=zt(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),[x,E]=b.useState(new Set),k=Qs(),R=b.useMemo(()=>{const F=new Map;for(const D of t){const M=j0(D);let B=F.get(M);B||(B=new Map,F.set(M,B));const O=zB(D.projectDir),N=B.get(O);N?N.sessions.push(D):B.set(O,{dir:O,sessions:[D]})}return Array.from(F.entries()).sort(([D],[M])=>PB(D,M)).map(([D,M])=>({provider:D,sessions:Array.from(M.values()).flatMap(B=>B.sessions),projects:Array.from(M.values()).map(B=>({dir:B.dir,shortDir:kv(B.dir),sessions:B.sessions}))}))},[t]);function A(F){s(F),l(Rie(F)),d("default")}async function I(F,D,M){if(n)return;const B=Nt;if(!B){Je.error("请先连接开发机");return}r(F.id);const O=j0(F);try{const N=await B.createSession({cwd:F.projectDir,mode:D,provider:O,resumeSessionId:F.id,...M?{permissionMode:M}:{}});if(N.error||!N.sessionId){Je.error(`恢复失败:${N.error??"未知错误"}`);return}const V={sessionId:N.sessionId,state:"idle",mode:N.mode??D,provider:N.provider??"claude"};zt.getState().addSession(V),k(`/chat/${N.sessionId}?mode=${N.mode??D}`),s(null)}catch(N){Je.error(`恢复失败:${N instanceof Error?N.message:String(N)}`)}finally{r(null)}}function T(){const F=Nt;!F||h||(p(!0),F.requestSessionHistory().then(D=>zt.getState().setHistorySessions(D)).catch(D=>{Je.error(D instanceof Error?D.message:String(D))}).finally(()=>{p(!1)}))}function $(F,D){const M=jN(F,D);E(B=>{const O=new Set(B);return O.has(M)?O.delete(M):O.add(M),O})}function P(F){w(D=>{const M=new Set(D);return M.has(F)?M.delete(F):M.add(F),M})}const W=t.length>0,U=i?BB():[];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:()=>W&&v(F=>!F),disabled:!W,"aria-expanded":W?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:qe("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:["全部会话",W?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),W?g.jsx(Xh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(bt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:T,disabled:h,"data-slot":"history-refresh",children:g.jsx(Nx,{className:qe("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!W&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),W&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(F=>{const D=_.has(F.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>P(F.provider),"aria-expanded":!D,"data-slot":"history-provider-header","data-expanded":!D,className:qe("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:Zv(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(Xh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!D&&"rotate-90"),"aria-hidden":"true"})]}),!D&&g.jsx("ul",{role:"list",className:"flex flex-col",children:F.projects.map(M=>{const B=jN(F.provider,M.dir),O=x.has(B);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>$(F.provider,M.dir),"aria-expanded":O,"data-slot":"history-group-header","data-expanded":O,className:qe("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(Xh,{className:qe("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:M.sessions.map(N=>g.jsx(Eie,{session:N,now:e,disabled:n!==null,loading:n===N.id,onClick:()=>A(N),modeTag:N.preferredMode},N.id))})]},B)})})]},F.provider)})}),g.jsx(Aie,{session:i,open:i!==null,modes:U,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:F=>{F||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&I(i,o,u)}})]})}function jN(e,t){return`${e}:${zB(t)}`}function zB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function BB(){return["json","pty"]}function Rie(e){const t=BB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Aie({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=ul("(min-width: 768px)");b.useEffect(()=>{t||p(!1)},[t]);const _=h?g.jsx(IB,{providerLabel:e?Zv(j0(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(FN,{checked:r==="json",label:"聊天",icon:g.jsx(Ax,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(FN,{checked:r==="pty",label:"终端",icon:g.jsx(Mx,{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(Z_,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(Z_,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(Z_,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(bt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(bt,{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(wc,{open:t,onOpenChange:o,children:g.jsxs(Sc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(xc,{className:"min-w-0",children:[g.jsx(cl,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(uc,{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(Ku,{children:w})]})}):g.jsx(Kv,{open:t,onOpenChange:o,children:g.jsxs(Gv,{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(N1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Xv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(gie,{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 FN({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:qe("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(ta,{className:qe("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Z_({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:qe("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:qe("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:qe("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:qe("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(ta,{className:qe("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Nie({...e}){return g.jsx(Rre,{"data-slot":"select",...e})}function Mie({...e}){return g.jsx(Nre,{"data-slot":"select-value",...e})}function Oie({className:e,size:t="default",children:n,...r}){return g.jsxs(Are,{"data-slot":"select-trigger","data-size":t,className:qe("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(Mre,{asChild:!0,children:g.jsx(pl,{className:"size-4 opacity-50"})})]})}function Die({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(Ore,{children:g.jsxs(Dre,{"data-slot":"select-content",className:qe("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(Lie,{}),g.jsx(Pre,{className:qe("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(Iie,{})]})})}function Pie({className:e,children:t,...n}){return g.jsxs(Lre,{"data-slot":"select-item",className:qe("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(zre,{children:g.jsx(ta,{className:"size-4"})})}),g.jsx(Ire,{children:t})]})}function Lie({className:e,...t}){return g.jsx(Bre,{"data-slot":"select-scroll-up-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Rx,{className:"size-4"})})}function Iie({className:e,...t}){return g.jsx(jre,{"data-slot":"select-scroll-down-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(pl,{className:"size-4"})})}function P1(e){return!e||e.endsWith("/")?e:`${e}/`}function zie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function Bie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function jie(e,t,n){var o;if(t==="insert")return{currentPath:Bie(e)||"./",query:zie(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:P1(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 Fie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function $ie(e,t){return`${P1(e)}${t.name}${t.isDir?"/":""}`}function $N(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 jB=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ii(H=>H.tree),h=ii(H=>H.cwd),p=ii(H=>H.homePath),y=i==="insert"?h:p||h,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>jie(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,x=b.useMemo(()=>Fie(y,w),[y,w]),E=_.query,k=b.useRef(new Set),[R,A]=b.useState(!1),[I,T]=b.useState(""),[$,P]=b.useState(!1);b.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const H=Nt;if(!H)return;let L=!1;return k.current.add(x),H.requestDirectoryList(x).then(Y=>{L||ii.getState().setDirEntries(Y.path,Y.entries)}).catch(()=>{L||ii.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{L=!0}},[x,d]);const W=!d.has(x),U=b.useMemo(()=>{let H=d.get(x)??[];return o&&(H=H.filter(L=>L.isDir)),E&&(H=H.filter(L=>L.name.toLowerCase().includes(E))),H},[d,x,E,o]),[F,D]=b.useState(0);b.useEffect(()=>D(0),[w,E]),b.useEffect(()=>{A(!1),T("")},[x]),b.useEffect(()=>{F>=U.length&&U.length>0&&D(U.length-1)},[U.length,F]);const M=b.useRef(null),B=b.useRef(!1);b.useEffect(()=>{var L;if(!B.current)return;B.current=!1;const H=(L=M.current)==null?void 0:L.querySelector(`[data-entry-index="${F}"]`);H==null||H.scrollIntoView({block:"nearest"})},[F]);const O=b.useCallback(H=>{const L=$ie(w,H);return i==="insert"?L.replace(/^\.\//,""):L},[w,i]);async function N(){const H=$N(x,I);if(!(!H||!r)){P(!0);try{const L=await r(H);if(!L)return;T(""),A(!1),n(P1(L))}finally{P(!1)}}}b.useImperativeHandle(u,()=>({handleKey(H){return U.length===0?!1:H.key==="ArrowDown"?(B.current=!0,D(L=>Math.min(U.length-1,L+1)),!0):H.key==="ArrowUp"?(B.current=!0,D(L=>Math.max(0,L-1)),!0):H.key==="Enter"&&!H.nativeEvent.isComposing?(n(O(U[F])),!0):!1}}),[U,F,O,n]);const V=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",q=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:V,"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:!x||$,onClick:()=>A(H=>!H),children:"新建目录"}):null]}),R?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:I,onChange:H=>T(H.target.value),onKeyDown:H=>{H.key==="Enter"&&!H.nativeEvent.isComposing&&(H.preventDefault(),N()),H.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:!$N(x,I)||$,onClick:()=>void N(),children:$?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:q,children:U.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:W?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map((H,L)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(O(H)),onMouseEnter:()=>D(L),className:qe("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",L===F&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",H.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":H.isDir?"dir":"file","data-entry-index":L,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[H.name,H.isDir?"/":""]})})},H.name))})})]})}),HN="工作目录不存在或不可访问:",Hie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],FB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],ea={claude:"Claude Code",codex:"Codex"};function Uie(e,t){return t!==Zr.PATH_NOT_FOUND||!e.startsWith(HN)?null:e.slice(HN.length).trim()||null}function Xg(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 Wie(e,t){return t.title?t.disabled?`${ea[e]}:${t.title}`:`${ea[e]} 路径:${t.title}`:`${ea[e]}:${t.label}`}function qie(e,t){return e!=="codex"||FB.some(n=>n.value===t)?t:"default"}async function Vie({relay:e,agentCli:t,form:n,timeoutMs:r=Vx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Xg(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?`${ea[n.provider]} 不可用:${p}`:`${ea[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=Uie(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 Yie({relay:e,timeoutMs:t=Vx}){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 Kie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Xg("claude",e),y=Xg("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(UN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(UN,{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(Gie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(Xie,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function UN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Wf,{children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":ea[e],onClick:i,className:qe("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:ea[e]}),g.jsx("span",{className:qe("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(Vf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:Wie(e,n)})})]})}function Gie({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"?"/home/dev/.local/bin/claude":"/home/dev/.local/bin/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(bt,{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(bt,{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 Xie({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:qe("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(bt,{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(bt,{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(W8,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:qe("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 Bh({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),[x,E]=b.useState(null),[k,R]=b.useState(!1),[A,I]=b.useState(null),[T,$]=b.useState(""),[P,W]=b.useState(!1),U=b.useRef(null),F=b.useRef(e);F.current=e;const D=Qs(),M=ii(Ce=>Ce.homePath),B=ii(Ce=>Ce.agentCli),O=ul("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&B)return;const Ce=Nt==null?void 0:Nt.requestProxyInfo();Ce&&Ce.then(Oe=>{const Me=ii.getState();Me.setHomePath(Oe.homePath),Me.setAgentCli(Oe.agentCli)}).catch(Oe=>{console.error("[create-session-dialog] requestProxyInfo failed",Oe)})},[e,M,B]),b.useEffect(()=>{if(!k)return;function Ce(Oe){var Ge;const Me=Oe.target;Me instanceof Node&&((Ge=U.current)!=null&&Ge.contains(Me))||window.setTimeout(()=>R(!1),0)}return document.addEventListener("pointerdown",Ce,!0),()=>document.removeEventListener("pointerdown",Ce,!0)},[k]);function N(){r(""),s(""),R(!1),l("claude"),d("pty"),p("default"),v(!1),E(null),I(null),$(""),W(!1)}function V(){if(h==="bypassPermissions"){v(!0);return}z()}async function q(){await z(),F.current&&v(!1)}const H=o==="codex"?FB:Hie,L=Xg(o,B),Y=_||P||L.disabled;function K(Ce){const Oe=qie(Ce,h);Oe!==h&&p(Oe)}async function z(Ce){E(null),w(!0);try{const Oe=await Vie({relay:Nt,agentCli:B,form:{cwd:Ce??i,name:n,provider:o,permissionMode:h,mode:u}});if(Oe.type==="success"){if(zt.getState().addSession(Oe.session),!F.current)return;t(!1),N(),D(Oe.route);return}if(Oe.type==="missing_cwd"&&E(Oe.path),Je.error(Oe.message),Oe.type==="validation_error"||Oe.type==="relay_missing")return}finally{w(!1)}}async function Q(Ce){const Oe=Nt;if(!Oe)return Je.error("请先连接开发机"),null;try{const Me=await Oe.createDirectory(Ce);return Me.success?(s(Me.path),E(null),Je.success("目录已创建"),Me.path):(Je.error(`目录创建失败:${Me.error??"未知错误"}`),null)}catch(Me){return Je.error(Me instanceof Error?Me.message:String(Me)),null}}function J(Ce){var Me;const Oe=B==null?void 0:B[Ce];I(Ce),$((Oe==null?void 0:Oe.command)??((Me=Oe==null?void 0:Oe.suggestions)==null?void 0:Me[0])??"")}async function ne(){if(!A)return;const Ce=T.trim();if(!Ce){Je.error("请输入 Agent CLI 路径");return}const Oe=Nt;if(!Oe){Je.error("请先连接开发机");return}W(!0);try{const Me=await Oe.updateAgentCliPath(A,Ce);if(Me.error||!Me.agentCli){Je.error(`路径保存失败:${Me.error??"未知错误"}`);return}ii.getState().setAgentCli(Me.agentCli),Je.success(`${ea[A]} 路径已保存`),I(null),$("")}catch(Me){Je.error(Me instanceof Error?Me.message:String(Me))}finally{W(!1)}}function ee(Ce){d(Ce),K(o)}function me(Ce){var Me;const Oe=Ce.relatedTarget;Oe instanceof Node&&((Me=U.current)!=null&&Me.contains(Oe))||window.setTimeout(()=>R(!1),0)}const _e=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(IB,{providerLabel:ea[o]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),g.jsx(bt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void q(),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:Ce=>{Ce.preventDefault(),V()},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:Ce=>r(Ce.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:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:me,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:Ce=>{s(Ce.target.value),E(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(jB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:Q,onSelect:Ce=>{s(Ce),E(null),R(!0)}}):null]}),x?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:x})]}):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:()=>ee("pty"),className:qe("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:()=>ee("json"),className:qe("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(Kie,{agentCli:B,provider:o,isDesktop:O,editingCliProvider:A,cliPathInput:T,savingCliPath:P,onProviderChange:Ce=>{l(Ce),K(Ce)},onOpenCliPathEditor:J,onCliPathInputChange:$,onCancelCliPathEditor:()=>{I(null),$("")},onSaveCliPath:()=>void ne()}),g.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"权限模式"}),g.jsxs(Nie,{value:h,onValueChange:Ce=>p(Ce),children:[g.jsx(Oie,{className:"w-full",children:g.jsx(Mie,{})}),g.jsx(Die,{children:H.map(Ce=>g.jsx(Pie,{value:Ce.value,children:Ce.label},Ce.value))})]})]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),g.jsx(bt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return O?g.jsx(wc,{open:e,onOpenChange:t,children:g.jsxs(Sc,{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(xc,{children:g.jsx(cl,{children:y?"跳过全部审批?":"新建会话"})}),_e]})}):g.jsx(Kv,{open:e,onOpenChange:t,children:g.jsxs(Gv,{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(N1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:y?"跳过全部审批?":"新建会话"})}),_e]})})}function jh({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(wc,{open:e,onOpenChange:r,children:g.jsx(Sc,{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(xc,{children:[g.jsx(cl,{children:"重命名会话"}),g.jsx(uc,{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:qe("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(Ku,{children:[g.jsx(bt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(bt,{type:"submit",disabled:h,children:"保存"})]})]})})})}function Zie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function Qie(e){return(e==null?void 0:e.kind)==="terminal"}function Jie(e){return Zie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Qie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function jm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Jie(t);function s(){t&&(r(t),n(!1))}return g.jsx(wc,{open:e,onOpenChange:n,children:g.jsxs(Sc,{"data-slot":"session-termination-dialog",children:[g.jsxs(xc,{children:[g.jsx(cl,{children:i.title}),g.jsx(uc,{children:i.description})]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(bt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function $B(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 ese(e){if(e.session.state==="error")return"error";const t=$B(e);return t==="disconnected"?e.session.state:t}function HB({layout:e}){const t=zt(Q=>Q.sessions),n=zt(Q=>Q.sessionListLoaded),r=zt(Q=>Q.agentStatusBySessionId),i=zt(Q=>Q.ptyStateBySessionId),s=zt(Q=>Q.renameSession),o=Xt(Q=>Q.bySessionId),l=mU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Ne(Q=>!!Q.selectedProxyId),h=Ne(Q=>Q.proxyListLoaded),p=Ne(Q=>Q.proxySwitchTarget),y=zt(Q=>Q.loadingProxyName),v=p!==null||!h||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",x=Qs(),[E,k]=b.useState(!1),[R,A]=b.useState(!1),[I,T]=b.useState(null),[$,P]=b.useState(null),{creatingTerminal:W,createTerminal:U}=UB(),[F,D]=b.useState(new Set),[M,B]=b.useState(()=>Date.now());b.useEffect(()=>{const Q=setInterval(()=>B(Date.now()),6e4);return()=>clearInterval(Q)},[]);function O(Q,J){x(`/chat/${Q}?mode=${J??"json"}`,{replace:!1})}function N(Q){const J=Q.sessionId,ne=Nt;if(!ne){Je.error("请先连接开发机");return}ne.sendControl({type:"session_terminate",sessionId:J}),zt.getState().removeSession(J),Xt.getState().clearSession(J),J===u&&x("/sessions"),(Q==null?void 0:Q.mode)==="pty"&&Q.ptyOwner==="local-terminal"?Je.info("已断开页面连接,本地终端仍在运行"):Je.info("正在终止会话",{duration:1500})}async function V(Q,J){const ne=Nt;if(!ne)throw new Error("请先连接开发机");const ee=await ne.renameSession(Q,J);if(!ee.success)throw new Error(ee.error??"重命名失败");s(Q,ee.name??J),Je.success("已重命名会话")}function q(Q){D(J=>{const ne=new Set(J);return ne.has(Q)?ne.delete(Q):ne.add(Q),ne})}function H(Q){var ee;const J=Q.mode==="json"&&(((ee=o[Q.sessionId])==null?void 0:ee.pendingApprovals.some(me=>me.status==="pending"))??!1),ne=ese({session:Q,agentStatus:r[Q.sessionId],ptyState:i[Q.sessionId],hasPendingApproval:J});return ne===Q.state?Q:{...Q,state:ne}}const L=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(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]});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(Jl,{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(tc,{variant:"no-proxy"})}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]});const Y=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",L?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=L?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:tse(t).map(Q=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>q(Q.provider),"aria-expanded":!F.has(Q.provider),className:qe("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:nse(Q.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:Q.sessions.length}),g.jsx(Xh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(Q.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(Q.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:Q.sessions.map(J=>g.jsx(wie,{session:H(J),selected:J.sessionId===u,now:M,onClick:()=>O(J.sessionId,J.mode),onRename:()=>T(J),onTerminate:()=>P(J)},J.sessionId))})]},Q.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),z=g.jsx(Tie,{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,K,z]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(bt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[g.jsx(TP,{"aria-hidden":"true"}),"新建"]})}),g.jsx(ise,{open:R,creatingTerminal:W,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>void U(()=>A(!1))}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,z]}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]})}function tse(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])=>rse(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function nse(e){return e==="terminal"?"终端":Zv(e)}function rse(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:PB(e,t)}function UB(){const e=Qs(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await Yie({relay:Nt});if(s.type!=="success"){Je.error(s.message);return}zt.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function WN({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Ne(E=>!!E.selectedProxyId),l=Ne(E=>E.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:h}=UB();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 _(E){E.preventDefault(),p()}const w=g.jsxs(bt,{variant:"outline","data-slot":"create-session-trigger",className:qe(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(TP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),x=u?g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:w}),g.jsxs(D1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:E=>{s.current&&(s.current=!1,E.preventDefault())},children:[g.jsxs(yo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[g.jsx(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(yo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[g.jsx(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return g.jsxs(g.Fragment,{children:[u?x:g.jsxs(Wf,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[g.jsx(qf,{asChild:!0,children:x}),g.jsx(Vf,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),g.jsx(Bh,{open:t,onOpenChange:n})]})}function ise({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(Kv,{open:e,onOpenChange:n,children:g.jsxs(Gv,{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(N1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.jsxs(bt,{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(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(bt,{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(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const sse="0.5.21",ose={version:sse},ase={playback:"playback",capture:"play-and-record"};function lse(){return typeof navigator>"u"?null:navigator.audioSession??null}function cse(){return{setMode:()=>{},release:()=>{}}}class use{constructor(t=lse){vt(this,"leases",new Map);vt(this,"session",null);vt(this,"baselineType",null);vt(this,"nextLeaseId",1);vt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return cse();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(ase[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 L1=new use,U0=64,qN=-60,WB=32;function VN(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 YN(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 dse(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 hse(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 qB{constructor(t,n=24e3,r={}){vt(this,"nextStartTime",0);vt(this,"activityEndToken",0);vt(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=dse(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*WB/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=hse(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,x;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(x=(w=this.options).onPlaybackChunk)==null||x.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 Q_={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},KN="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",fse=800,GN=300,pse=1600;function W0(e,t){return e.filter(n=>!n.model||n.model===t)}function XN({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 Fm({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=!!VB(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(ZN,{label:h,muted:!d&&!t}),g.jsx(pl,{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(ta,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(ZN,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function ZN({label:e,muted:t=!1}){const n=VB(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 mse({scrollRef:e}={}){const[t,n]=b.useState(Q_),[r,i]=b.useState(String(Q_.turnIdleSeconds)),[s,o]=b.useState(()=>Tm()),[l,u]=b.useState(""),[d,h]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),x=b.useRef(null),E=b.useRef(null),k=b.useRef(null),R=b.useRef(null);b.useEffect(()=>{const ne=Nt;if(!ne){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ee=!1;return _({kind:"loading"}),ne.requestVoiceConfig().then(me=>{if(!ee){if(me.error||!me.config){_({kind:"error",message:me.error??"读取语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),h(!1),y(!0),_({kind:"idle"})}}).catch(me=>{ee||_({kind:"error",message:me instanceof Error?me.message:"读取语音设置失败"})}),()=>{ee=!0}},[]),b.useEffect(()=>{const ne=Nt;if(!ne||!p)return;let ee=!1;return ne.requestVoiceCapabilities({region:t.region}).then(me=>{if(!ee){if(me.error||!me.capabilities){o(Tm());return}o(me.capabilities)}}).catch(()=>{ee||o(Tm())}),()=>{ee=!0}},[t.region,p]),b.useEffect(()=>()=>{K(),z()},[]);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]),I=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",T=b.useMemo(()=>W0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=T.some(ne=>ne.value===t.ttsVoice)?t.ttsVoice:"",W=T.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",U=b.useMemo(()=>bse(r),[r]),F=U?null:"请输入正整数秒数",D=W??F,M=I||!!D,B=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),O=b.useMemo(()=>eM(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),N=b.useMemo(()=>_se(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),V=b.useMemo(()=>eM(T,P),[T,P]);function q(){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:U??Q_.turnIdleSeconds}}async function H(){if(I)return;if(D){_({kind:"error",message:D});return}const ne=Nt;if(!ne){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ee=q();z(),_({kind:"saving"});const me=performance.now();try{const _e=await ne.updateVoiceConfig(ee),Ce=performance.now()-me;if(Ce<GN&&await yse(GN-Ce),!_e.success||_e.error||!_e.config){_({kind:"error",message:_e.error??"保存语音设置失败"});return}n(_e.config),i(String(_e.config.turnIdleSeconds)),u(""),h(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(Oe=>Oe.kind==="saved"?{kind:"idle"}:Oe)},pse),ne.requestVoiceCapabilities({region:_e.config.region}).then(Oe=>{Oe.capabilities&&o(Oe.capabilities)}).catch(()=>{o(Tm())})}catch(_e){_({kind:"error",message:_e instanceof Error?_e.message:"保存语音设置失败"})}}async function L(){if(I)return;if(D){_({kind:"error",message:D});return}const ne=Nt;if(!ne){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ee;try{ee=Y()}catch(me){_({kind:"error",message:JN(me)});return}_({kind:"testing"});try{const[me]=await Promise.all([ne.testVoiceConfig(q()),ee.ready]);if(!me.success||me.error){K(),_({kind:"error",message:me.error??"语音配置测试失败"});return}const _e=await Q(me,ee.context);_({kind:"playingTest",transcript:me.transcript}),k.current=setTimeout(()=>{k.current=null,K(),_({kind:"testPassed",transcript:me.transcript})},_e)}catch(me){K(),_({kind:"error",message:JN(me)})}}function Y(){K();const ne=L1.acquire("playback");x.current=ne;try{const ee=vse();return w.current=ee,{context:ee,ready:QN(ee)}}catch(ee){throw ne.release(),x.current=null,ee}}function K(){var ne,ee,me;k.current&&(clearTimeout(k.current),k.current=null),(ne=E.current)==null||ne.stop(),E.current=null,(ee=w.current)==null||ee.close(),w.current=null,(me=x.current)==null||me.release(),x.current=null}function z(){R.current&&(clearTimeout(R.current),R.current=null)}async function Q(ne,ee){if(!ne.audioBase64)throw new Error("语音测试未返回可播放音频");if(ne.audioEncoding&&ne.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const me=ne.audioSampleRate??24e3,_e=gse(ne.audioBase64);if(_e.byteLength===0||_e.byteLength%2!==0)throw new Error("测试音频数据无效");await QN(ee);const Ce=new qB(ee,me);E.current=Ce,Ce.enqueue(_e);const Oe=Math.ceil(_e.byteLength/2/me*1e3);return Math.max(fse,Oe)}function J(ne){var ee;return((ee=W0(s.ttsVoices,ne)[0])==null?void 0:ee.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:ne=>{ne.preventDefault(),H()},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(XN,{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(NP,{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:ne=>{u(ne.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${KN} w-full pl-9`})]}),t.configured&&g.jsxs(bt,{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(f7,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(Fm,{label:"地域",value:t.region,options:B,onChange:ne=>n(ee=>({...ee,region:ne==="intl"?"intl":"cn"}))}),g.jsx(Fm,{label:"语音识别模型",value:t.asrModel,options:O,onChange:ne=>n(ee=>({...ee,asrModel:ne}))}),g.jsx(Fm,{label:"语音合成模型",value:t.ttsModel,options:N,onChange:ne=>n(ee=>({...ee,ttsModel:ne,ttsVoice:J(ne)}))}),g.jsx(Fm,{label:"语音音色",value:P,options:V,placeholder:T.length===0?"暂无可用音色":"请选择音色",onChange:ne=>n(ee=>({...ee,ttsVoice:ne})),help:W}),g.jsx(XN,{label:"结束停顿时间(秒)",help:F,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:ne=>i(ne.target.value),className:`${KN} 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(bt,{type:"button",variant:"outline",disabled:M,onClick:()=>void L(),children:[g.jsx(DP,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(bt,{type:"submit",disabled:M,children:[g.jsx(e7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function gse(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 vse(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function QN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function JN(e){return e instanceof Error?e.message:"语音配置测试失败"}function yse(e){return new Promise(t=>setTimeout(t,e))}function bse(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function eM(e,t){const n=e.map(r=>({value:r.value,label:YB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function _se(e,t,n){const r=e.map(i=>{const s=W0(t,i.value).length===0;return{value:i.value,label:`${YB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function VB(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 YB(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 wse=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Sse=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],I1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function KB(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 xse(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Ese(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Cse(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function q0({open:e,onOpenChange:t}){const n=Ne(W=>W.relayUrl),r=Ne(W=>W.latencyMonitorEnabled),i=Ne(W=>W.setLatencyMonitorEnabled),s=Ne(W=>W.sessionIdleNotificationsEnabled),o=Ne(W=>W.setSessionIdleNotificationsEnabled),l=Ne(W=>W.inputModePreference),u=Ne(W=>W.setInputModePreference),d=Ne(W=>W.themePreference),h=Ne(W=>W.setThemePreference),p=Ne(W=>W.ptyScrollTraceEnabled),y=Ne(W=>W.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,x]=b.useState({kind:"idle"}),E=b.useRef(null),k=b.useRef(null),R=bQ(),A=b.useMemo(()=>Cv().osName==="iPad",[]),I=b.useCallback(async W=>{if(!W){o(!1);return}const U=await KZ();if(U==="granted"){o(!0);return}if(U==="denied"){Je.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){Je.info("未授予通知权限,会话通知保持关闭");return}Je.error("当前浏览器不支持系统通知")},[o]),T=b.useCallback(async W=>{x({kind:"loading"});try{const U=await fetch(xse(n),{cache:"no-store",signal:W});if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=await U.json();if(F.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:F.version??"未知",uptime:F.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;x({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const W=new AbortController;return T(W.signal),()=>W.abort()},[T,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const W=window.requestAnimationFrame(()=>{var U;(U=E.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(W)},[e,v]);const $=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${KB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(wc,{open:e,onOpenChange:t,children:g.jsxs(Sc,{className:qe("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:E,showCloseButton:v==="menu",children:[g.jsx(xc,{className:qe(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(bt,{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(bv,{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(cl,{children:Ese(v)}),g.jsx(uc,{className:"max-w-[28rem] leading-5",children:Cse(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(cl,{children:"设置"}),g.jsx(uc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(kse,{relayVersion:$,relayDetail:P,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(Rse,{saved:R}):v==="clients"?g.jsx(Dse,{}):v==="voice"?g.jsx(mse,{scrollRef:k}):g.jsx(Tse,{relayTokenSaved:R,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:I,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function kse({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:I1,"data-slot":"settings-dialog-body",children:[g.jsx(nM,{icon:g.jsx(OP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:ose.version,detail:"当前浏览器加载的版本"}),g.jsx(nM,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Tse({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(uu,{title:"服务",children:[g.jsx($m,{icon:g.jsx(U9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx($m,{icon:g.jsx(NP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx($m,{icon:g.jsx(_7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),g.jsx(uu,{title:"外观",children:g.jsx(tM,{icon:g.jsx(u7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:wse,onValueChange:n})}),g.jsx(uu,{title:"通知",children:g.jsx(ew,{icon:g.jsx(q9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(uu,{title:"交互",children:g.jsx(tM,{icon:g.jsx(MP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Sse,onValueChange:i})}):null,g.jsxs(uu,{title:"高级诊断",children:[g.jsx(ew,{icon:g.jsx(lf,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(ew,{icon:g.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(uu,{title:"关于",children:g.jsx($m,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function uu({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 tM({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:qe("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 Rse({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{JL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}if(!ZL(h)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),Je.error(p);return}o(null),Je.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{QL(),l()};return g.jsxs("form",{className:I1,"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(bt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(bt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Ase(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Nse(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Ase(e)}function Mse(e){return CX(e)}function Ose(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return KB(t)}function J_({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 Dse(){const e=Ne(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=Nt;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=Nt;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:I1,"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(bt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Nx,{className:qe("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:Mse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(J_,{label:"已连接",value:Ose(y.connectedAt)}),y.proxyId?g.jsx(J_,{label:"连接到",value:Nse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(J_,{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(bt,{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(N8,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function ew({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:qe("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:qe("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:qe("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 $m({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(Xh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function nM({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:qe("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 Pse="xterm-helper-textarea";function Lse(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Pse)?!1:(e.blur(),!0)}function rM(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&&Ise(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Ise(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 zse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Lse()},[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,rM(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(rM(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Bse({className:e}){const t=Ne(o=>o.sidebarCollapsed),n=Ne(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=zse();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:qe("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(sM,{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(iM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(WN,{compact:!0})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:qe("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(JP,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(sM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx(DB,{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(HB,{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(WN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(iM,{onClick:()=>i(!0)})})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]})}function iM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:qe("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(LP,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(Vf,{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 sM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?F8:B8;return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:qe("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:qe("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(Vf,{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 jse=1500,Fse=300,oM=70,aM=35;function GB({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,oM)):(o.current="paused",h=setTimeout(y,jse))}else v==="paused"?(o.current="deleting",h=setTimeout(y,aM)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),h=setTimeout(y,aM)):(u.current+=1,o.current="waiting",h=setTimeout(y,Fse)):(o.current="typing",h=setTimeout(y,oM))};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 XB=["DEV Anywhere","/unlimited @anytime"];function $se({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(GB,{texts:XB,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 Hse=3e3,Use=1e4,Hm=12,Wse=4,lM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},qse={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function tw(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 du(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Fh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function cM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function ZB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Vse(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 Yse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Fh(e.rttMs):"等待检测"}function Kse(){const e=xi("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 uM(e){dr("local",cn.latencyMonitorPosition,JSON.stringify(e))}function Gse(){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 nw(e,t){const n=Gse(),r=Hm,i=Hm,s=Math.max(r,n.width-t.width-Hm),o=Math.max(i,n.height-t.height-Hm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Xse(){const e=Ne(T=>T.latencyMonitorEnabled),t=Ne(T=>T.connected),n=Ne(T=>T.proxyOnline),r=Ne(T=>T.selectedProxyId),[i,s]=b.useState(qse),[o,l]=b.useState(()=>Kse()),u=b.useRef(!1),d=b.useRef(null),h=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,$)=>cM($.state)-cM(T.state))[0]??{state:"idle"}).state,[i]),v=ZB(y);async function _(){if(u.current)return;const T=Nt;if(!T||!t){const U=du("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:du("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:du("未连接开发机")}));const[$,P,W]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:$.status==="fulfilled"?tw($.value):du($.reason instanceof Error?$.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?tw(P.value):du(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:W.status==="fulfilled"?tw(W.value):du(W.reason instanceof Error?W.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,$=null;const P=async()=>{await _(),!T&&($=setTimeout(P,document.hidden?Use:Hse))};return P(),()=>{T=!0,u.current=!1,$&&clearTimeout($)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const $=T.getBoundingClientRect(),P=nw(o,{width:$.width,height:$.height});P.x===o.x&&P.y===o.y||(l(P),uM(P))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,x=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function E(T){var P,W;if(T.button!==0)return;const $=T.currentTarget.getBoundingClientRect();h.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:$.left,originY:$.top,width:$.width,height:$.height,dragging:!1},(W=(P=T.currentTarget).setPointerCapture)==null||W.call(P,T.pointerId)}function k(T){const $=h.current;if(!$||$.pointerId!==T.pointerId)return;const P=T.clientX-$.startX,W=T.clientY-$.startY;if(!$.dragging&&Math.hypot(P,W)<Wse)return;$.dragging=!0,T.preventDefault();const U=nw({x:$.originX+P,y:$.originY+W},{width:$.width,height:$.height});l(U)}function R(T){var F,D;const $=h.current;if(!$||$.pointerId!==T.pointerId||(h.current=null,(D=(F=T.currentTarget).releasePointerCapture)==null||D.call(F,T.pointerId),!$.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=T.clientX-$.startX,W=T.clientY-$.startY,U=nw({x:$.originX+P,y:$.originY+W},{width:$.width,height:$.height});l(U),uM(U)}function A(T){var P,W;const $=h.current;!$||$.pointerId!==T.pointerId||(h.current=null,(W=(P=T.currentTarget).releasePointerCapture)==null||W.call(P,T.pointerId))}function I(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return g.jsxs(T1,{children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:qe("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",Vse(v)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Fh(i.webRelay.rttMs)},开发机 ${Fh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:I,children:[g.jsx(EP,{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 ",Fh(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Fh(w.rttMs)]}),g.jsx(pl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(A1,{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(bt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:g.jsx(Nx,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(lM).map(T=>g.jsx(Zse,{label:lM[T],measurement:i[T]},T))})]})]})}function Zse({label:e,measurement:t}){const n=ZB(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:qe("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:Yse(t)})]})]})}const QB="/__dev_anywhere_debug/browser-state-dumps",Qse=1500,Jse=10,rw=80,z1=500,eoe=["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"],toe=["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 dM(){if(typeof window>"u")return"off";const e=o3("debugDump");return e==="auto"?"auto":e!==null||uoe("debugInput")?"manual":"off"}function noe(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:ooe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:hM(document.activeElement),selection:aoe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>hM(i)).filter(i=>!!i),root:JB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:hu(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:hu(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:hu(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:hu(()=>fM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:hu(()=>fM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:hu(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function roe(e="manual"){const t=noe(e);return ioe(t)}async function ioe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await soe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:QB}}catch(r){const i=a3(r),s=loe(e.createdAt);return coe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function soe(e){const t=await fetch(QB,{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 JB(e,t,n){if(n.count>=Qse||t>Jse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=pM(e.textContent??"");return u?{kind:"text",text:Qv(u,z1)}:{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,rw))u.nodeType===Node.TEXT_NODE&&!pM(u.textContent??"")||r.push(JB(u,t+1,n));s.length>rw&&(i=s.length-rw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:s3(e),attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e)},l=i3(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function hM(e){if(!(e instanceof HTMLElement))return null;const t=i3(e);return{path:s3(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e),...t?{value:t}:{}}}function ooe(){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 e3(e){const t={};for(const n of eoe){const r=e.getAttribute(n);r!==null&&(t[n]=Qv(r,500))}return t}function t3(e){const t=e.getBoundingClientRect();return{x:Yi(t.x),y:Yi(t.y),width:Yi(t.width),height:Yi(t.height),top:Yi(t.top),right:Yi(t.right),bottom:Yi(t.bottom),left:Yi(t.left)}}function n3(e){return{top:Yi(e.scrollTop),left:Yi(e.scrollLeft),height:Yi(e.scrollHeight),width:Yi(e.scrollWidth),clientHeight:Yi(e.clientHeight),clientWidth:Yi(e.clientWidth)}}function r3(e){const t=window.getComputedStyle(e),n={};for(const r of toe)n[r]=t.getPropertyValue(r);return n}function i3(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Qv(e.value,z1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function aoe(){var e;try{return Qv(((e=window.getSelection())==null?void 0:e.toString())??"",z1)}catch{return null}}function s3(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 loe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function coe(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 uoe(e){return o3(e)!==null}function o3(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 fM(e){return e?Zg(e.slice(-200)):null}function hu(e){try{return Zg(e())}catch(t){return{error:a3(t)}}}function Zg(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(Zg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Zg(r);return t}return String(e)}function pM(e){return e.replace(/\s+/g," ").trim()}function Qv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Yi(e){return Math.round(e*100)/100}function a3(e){return e instanceof Error?e.message:String(e)}const doe=500,hoe=1e3,foe=60;function poe(){const[e,t]=b.useState(()=>dM()),[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(dM());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 roe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&moe(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>=foe||(_(),h.current=window.setTimeout(()=>{h.current=null;const I=Date.now(),T=hoe-(I-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}`)},doe))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=A=>w(A.type);return x.forEach(A=>window.addEventListener(A,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(R=window.visualViewport)==null||R.addEventListener("scroll",E),()=>{var A,I;_(),x.forEach(T=>window.removeEventListener(T,E,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",E),(I=window.visualViewport)==null||I.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=goe(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(bt,{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(Jl,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(y8,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function moe(e){if(e.status==="saved"){Je.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){Je.info(`诊断已下载: ${e.filename}`);return}Je.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function goe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function voe(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 B1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:voe(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 Va(e){return e.length===0?"":`${Tn(Math.min(...e))}..${Tn(Math.max(...e))}`}function Nu(e){return[...new Set(e.filter(t=>t!==void 0).map(Tn))]}function l3(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 yoe="dev_anywhere_pty_input_latency_trace",mM=80,boe=1e4,_oe=new TextDecoder;let woe=0;const Gu=new Map,Ec=B1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:yoe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Soe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=koe)}function xoe(e,t){if(!Ec.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++woe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Aoe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Gu.get(e)??[];return s.push(i),F1(s,r),Gu.set(e,s),Yf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function gM(e,t){if(!e||!Ec.isEnabled())return;const n=performance.now(),r=Toe(e.sessionId,e.inputId);r&&(r.sentAt=n),Yf({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 Eoe(e,t,n){if(!Ec.isEnabled())return;const r=performance.now(),i=j1(e,r),s=Ooe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Moe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Yf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:Doe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Coe(e,t,n=1){if(!Ec.isEnabled())return;const r=performance.now(),i=j1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Yf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Roe(e,s))}function koe(){const e=Ec.getAll(),t=e.slice(-200),n=[...Gu.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(`
|
|
510
|
+
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},QJ="DialogDescriptionWarning",JJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${MI(QJ).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},r1=vI,eee=bI,i1=wI,s1=SI,o1=xI,OI=CI,DI=TI,a1=AI;function tee(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 nee(e){const[t,n]=b.useState(void 0);return Ei(()=>{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 ree=["top","right","bottom","left"],al=Math.min,as=Math.max,Ug=Math.round,zm=Math.floor,So=e=>({x:e,y:e}),iee={left:"right",right:"left",bottom:"top",top:"bottom"};function T0(e,t,n){return as(e,al(t,n))}function ra(e,t){return typeof e=="function"?e(t):e}function ia(e){return e.split("-")[0]}function ad(e){return e.split("-")[1]}function l1(e){return e==="x"?"y":"x"}function c1(e){return e==="y"?"height":"width"}function _o(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function u1(e){return l1(_o(e))}function see(e,t,n){n===void 0&&(n=!1);const r=ad(e),i=u1(e),s=c1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Wg(o)),[o,Wg(o)]}function oee(e){const t=Wg(e);return[R0(e),t,R0(t)]}function R0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const wN=["left","right"],SN=["right","left"],aee=["top","bottom"],lee=["bottom","top"];function cee(e,t,n){switch(e){case"top":case"bottom":return n?t?SN:wN:t?wN:SN;case"left":case"right":return t?aee:lee;default:return[]}}function uee(e,t,n,r){const i=ad(e);let s=cee(ia(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(R0)))),s}function Wg(e){const t=ia(e);return iee[t]+e.slice(t.length)}function dee(e){return{top:0,right:0,bottom:0,left:0,...e}}function PI(e){return typeof e!="number"?dee(e):{top:e,right:e,bottom:e,left:e}}function qg(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 xN(e,t,n){let{reference:r,floating:i}=e;const s=_o(t),o=u1(t),l=c1(o),u=ia(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(ad(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 hee(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}=ra(t,e),_=PI(v),x=l[y?p==="floating"?"reference":"floating":p],E=qg(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.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},I=qg(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(E.top-I.top+_.top)/A.y,bottom:(I.bottom-E.bottom+_.bottom)/A.y,left:(E.left-I.left+_.left)/A.x,right:(I.right-E.right+_.right)/A.x}}const fee=50,pee=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:hee},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}=xN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:R,y:A,data:I,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,_[E]={..._[E],...I},T&&v<fee&&(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}=xN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:_}},mee=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}=ra(e,t)||{};if(d==null)return{};const p=PI(h),y={x:n,y:r},v=u1(i),_=c1(v),w=await o.getDimensions(d),x=v==="y",E=x?"top":"left",k=x?"bottom":"right",R=x?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[v]-y[v]-s.floating[_],I=y[v]-s.reference[v],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let $=T?T[R]:0;(!$||!await(o.isElement==null?void 0:o.isElement(T)))&&($=l.floating[R]||s.floating[_]);const P=A/2-I/2,W=$/2-w[_]/2-1,U=al(p[E],W),F=al(p[k],W),D=U,M=$-w[_]-F,B=$/2-w[_]/2+P,O=T0(D,B,M),N=!u.arrow&&ad(i)!=null&&B!==O&&s.reference[_]/2-(B<D?U:F)-w[_]/2<0,V=N?B<D?B-D:B-M:0;return{[v]:y[v]+V,data:{[v]:O,centerOffset:B-O-V,...N&&{alignmentOffset:V}},reset:N}}}),gee=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,...x}=ra(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=ia(i),k=_o(l),R=ia(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),I=y||(R||!w?[Wg(l)]:oee(l)),T=_!=="none";!y&&T&&I.push(...uee(l,w,_,A));const $=[l,...I],P=await u.detectOverflow(t,x),W=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&W.push(P[E]),p){const B=see(i,o,A);W.push(P[B[0]],P[B[1]])}if(U=[...U,{placement:i,overflows:W}],!W.every(B=>B<=0)){var F,D;const B=(((F=s.flip)==null?void 0:F.index)||0)+1,O=$[B];if(O&&(!(p==="alignment"?k!==_o(O):!1)||U.every(q=>_o(q.placement)===k?q.overflows[0]>0:!0)))return{data:{index:B,overflows:U},reset:{placement:O}};let N=(D=U.filter(V=>V.overflows[0]<=0).sort((V,q)=>V.overflows[1]-q.overflows[1])[0])==null?void 0:D.placement;if(!N)switch(v){case"bestFit":{var M;const V=(M=U.filter(q=>{if(T){const H=_o(q.placement);return H===k||H==="y"}return!0}).map(q=>[q.placement,q.overflows.filter(H=>H>0).reduce((H,L)=>H+L,0)]).sort((q,H)=>q[1]-H[1])[0])==null?void 0:M[0];V&&(N=V);break}case"initialPlacement":N=l;break}if(i!==N)return{reset:{placement:N}}}return{}}}};function EN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function CN(e){return ree.some(t=>e[t]>=0)}const vee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ra(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=EN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:CN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=EN(o,n.floating);return{data:{escapedOffsets:l,escaped:CN(l)}}}default:return{}}}}},LI=new Set(["left","top"]);async function yee(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=ia(n),l=ad(n),u=_o(n)==="y",d=LI.has(o)?-1:1,h=s&&u?-1:1,p=ra(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 yee(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}}}}},_ee=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:E=>{let{x:k,y:R}=E;return{x:k,y:R}}},...d}=ra(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=_o(ia(i)),v=l1(y);let _=h[v],w=h[y];if(o){const E=v==="y"?"top":"left",k=v==="y"?"bottom":"right",R=_+p[E],A=_-p[k];_=T0(R,_,A)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+p[E],A=w-p[k];w=T0(R,w,A)}const x=u.fn({...t,[v]:_,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[v]:o,[y]:l}}}}}},wee=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}=ra(e,t),h={x:n,y:r},p=_o(i),y=l1(p);let v=h[y],_=h[p];const w=ra(l,t),x=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]+x.mainAxis,I=s.reference[y]+s.reference[R]-x.mainAxis;v<A?v=A:v>I&&(v=I)}if(d){var E,k;const R=y==="y"?"width":"height",A=LI.has(ia(i)),I=s.reference[p]-s.floating[R]+(A&&((E=o.offset)==null?void 0:E[p])||0)+(A?0:x.crossAxis),T=s.reference[p]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?x.crossAxis:0);_<I?_=I:_>T&&(_=T)}return{[y]:v,[p]:_}}}},See=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}=ra(e,t),h=await o.detectOverflow(t,d),p=ia(i),y=ad(i),v=_o(i)==="y",{width:_,height:w}=s.floating;let x,E;p==="top"||p==="bottom"?(x=p,E=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(E=p,x=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,R=_-h.left-h.right,A=al(w-h[x],k),I=al(_-h[E],R),T=!t.middlewareData.shift;let $=A,P=I;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&($=k),T&&!y){const U=as(h.left,0),F=as(h.right,0),D=as(h.top,0),M=as(h.bottom,0);v?P=_-2*(U!==0||F!==0?U+F:as(h.left,h.right)):$=w-2*(D!==0||M!==0?D+M:as(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:$});const W=await o.getDimensions(l.floating);return _!==W.width||w!==W.height?{reset:{rects:!0}}:{}}}};function Ov(){return typeof window<"u"}function ld(e){return II(e)?(e.nodeName||"").toLowerCase():"#document"}function ls(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Ro(e){var t;return(t=(II(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function II(e){return Ov()?e instanceof Node||e instanceof ls(e).Node:!1}function Gs(e){return Ov()?e instanceof Element||e instanceof ls(e).Element:!1}function oa(e){return Ov()?e instanceof HTMLElement||e instanceof ls(e).HTMLElement:!1}function kN(e){return!Ov()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof ls(e).ShadowRoot}function zf(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 xee(e){return/^(table|td|th)$/.test(ld(e))}function Dv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Eee=/transform|translate|scale|rotate|perspective|filter/,Cee=/paint|layout|strict|content/,Hl=e=>!!e&&e!=="none";let q_;function d1(e){const t=Gs(e)?Xs(e):e;return Hl(t.transform)||Hl(t.translate)||Hl(t.scale)||Hl(t.rotate)||Hl(t.perspective)||!h1()&&(Hl(t.backdropFilter)||Hl(t.filter))||Eee.test(t.willChange||"")||Cee.test(t.contain||"")}function kee(e){let t=ll(e);for(;oa(t)&&!qu(t);){if(d1(t))return t;if(Dv(t))return null;t=ll(t)}return null}function h1(){return q_==null&&(q_=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),q_}function qu(e){return/^(html|body|#document)$/.test(ld(e))}function Xs(e){return ls(e).getComputedStyle(e)}function Pv(e){return Gs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ll(e){if(ld(e)==="html")return e;const t=e.assignedSlot||e.parentNode||kN(e)&&e.host||Ro(e);return kN(t)?t.host:t}function zI(e){const t=ll(e);return qu(t)?e.ownerDocument?e.ownerDocument.body:e.body:oa(t)&&zf(t)?t:zI(t)}function pf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=zI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=ls(i);if(s){const l=A0(o);return t.concat(o,o.visualViewport||[],zf(i)?i:[],l&&n?pf(l):[])}else return t.concat(i,pf(i,[],n))}function A0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function BI(e){const t=Xs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=oa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=Ug(n)!==s||Ug(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function f1(e){return Gs(e)?e:e.contextElement}function Bu(e){const t=f1(e);if(!oa(t))return So(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=BI(t);let o=(s?Ug(n.width):n.width)/r,l=(s?Ug(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Tee=So(0);function jI(e){const t=ls(e);return!h1()||!t.visualViewport?Tee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ree(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==ls(e)?!1:t}function ac(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=f1(e);let o=So(1);t&&(r?Gs(r)&&(o=Bu(r)):o=Bu(e));const l=Ree(s,n,r)?jI(s):So(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=ls(s),v=r&&Gs(r)?ls(r):r;let _=y,w=A0(_);for(;w&&r&&v!==_;){const x=Bu(w),E=w.getBoundingClientRect(),k=Xs(w),R=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,A=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=R,d+=A,_=ls(w),w=A0(_)}}return qg({width:h,height:p,x:u,y:d})}function Lv(e,t){const n=Pv(e).scrollLeft;return t?t.left+n:ac(Ro(e)).left+n}function FI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Lv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Aee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=Ro(r),l=t?Dv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=So(1);const h=So(0),p=oa(r);if((p||!p&&!s)&&((ld(r)!=="body"||zf(o))&&(u=Pv(r)),p)){const v=ac(r);d=Bu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?FI(o,u):So(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 Nee(e){return Array.from(e.getClientRects())}function Mee(e){const t=Ro(e),n=Pv(e),r=e.ownerDocument.body,i=as(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=as(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Lv(e);const l=-n.scrollTop;return Xs(r).direction==="rtl"&&(o+=as(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const TN=25;function Oee(e,t){const n=ls(e),r=Ro(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=h1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Lv(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);_<=TN&&(s-=_)}else d<=TN&&(s+=d);return{width:s,height:o,x:l,y:u}}function Dee(e,t){const n=ac(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=oa(e)?Bu(e):So(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 RN(e,t,n){let r;if(t==="viewport")r=Oee(e,n);else if(t==="document")r=Mee(Ro(e));else if(Gs(t))r=Dee(t,n);else{const i=jI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return qg(r)}function $I(e,t){const n=ll(e);return n===t||!Gs(n)||qu(n)?!1:Xs(n).position==="fixed"||$I(n,t)}function Pee(e,t){const n=t.get(e);if(n)return n;let r=pf(e,[],!1).filter(l=>Gs(l)&&ld(l)!=="body"),i=null;const s=Xs(e).position==="fixed";let o=s?ll(e):e;for(;Gs(o)&&!qu(o);){const l=Xs(o),u=d1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||zf(o)&&!u&&$I(e,o))?r=r.filter(h=>h!==o):i=l,o=ll(o)}return t.set(e,r),r}function Lee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Dv(t)?[]:Pee(t,this._c):[].concat(n),r],l=RN(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=RN(t,o[y],i);u=as(v.top,u),d=al(v.right,d),h=al(v.bottom,h),p=as(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function Iee(e){const{width:t,height:n}=BI(e);return{width:t,height:n}}function zee(e,t,n){const r=oa(t),i=Ro(t),s=n==="fixed",o=ac(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=So(0);function d(){u.x=Lv(i)}if(r||!r&&!s)if((ld(t)!=="body"||zf(i))&&(l=Pv(t)),r){const v=ac(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?FI(i,l):So(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 V_(e){return Xs(e).position==="static"}function AN(e,t){if(!oa(e)||Xs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Ro(e)===n&&(n=n.ownerDocument.body),n}function HI(e,t){const n=ls(e);if(Dv(e))return n;if(!oa(e)){let i=ll(e);for(;i&&!qu(i);){if(Gs(i)&&!V_(i))return i;i=ll(i)}return n}let r=AN(e,t);for(;r&&xee(r)&&V_(r);)r=AN(r,t);return r&&qu(r)&&V_(r)&&!d1(r)?n:r||kee(e)||n}const Bee=async function(e){const t=this.getOffsetParent||HI,n=this.getDimensions,r=await n(e.floating);return{reference:zee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function jee(e){return Xs(e).direction==="rtl"}const Fee={convertOffsetParentRelativeRectToViewportRelativeRect:Aee,getDocumentElement:Ro,getClippingRect:Lee,getOffsetParent:HI,getElementRects:Bee,getClientRects:Nee,getDimensions:Iee,getScale:Bu,isElement:Gs,isRTL:jee};function UI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $ee(e,t){let n=null,r;const i=Ro(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 _=zm(p),w=zm(i.clientWidth-(h+y)),x=zm(i.clientHeight-(p+v)),E=zm(h),R={rootMargin:-_+"px "+-w+"px "+-x+"px "+-E+"px",threshold:as(0,al(1,u))||1};let A=!0;function I(T){const $=T[0].intersectionRatio;if($!==u){if(!A)return o();$?o(!1,$):r=setTimeout(()=>{o(!1,1e-7)},1e3)}$===1&&!UI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(I,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(I,R)}n.observe(e)}return o(!0),s}function Hee(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=f1(e),h=i||s?[...d?pf(d):[],...t?pf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?$ee(d,n):null;let y=-1,v=null;o&&(v=new ResizeObserver(E=>{let[k]=E;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?ac(e):null;u&&x();function x(){const E=ac(e);w&&!UI(w,E)&&n(),w=E,_=requestAnimationFrame(x)}return n(),()=>{var E;h.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(E=v)==null||E.disconnect(),v=null,u&&cancelAnimationFrame(_)}}const Uee=bee,Wee=_ee,qee=gee,Vee=See,Yee=vee,NN=mee,Kee=wee,Gee=(e,t,n)=>{const r=new Map,i={platform:Fee,...n},s={...i.platform,_c:r};return pee(e,t,{...i,platform:s})};var Xee=typeof document<"u",Zee=function(){},yg=Xee?b.useLayoutEffect:Zee;function Vg(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(!Vg(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)&&!Vg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function WI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function MN(e,t){const n=WI(e);return Math.round(t*n)/n}function Y_(e){const t=b.useRef(e);return yg(()=>{t.current=e}),t}function Qee(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);Vg(y,r)||v(r);const[_,w]=b.useState(null),[x,E]=b.useState(null),k=b.useCallback(q=>{q!==T.current&&(T.current=q,w(q))},[]),R=b.useCallback(q=>{q!==$.current&&($.current=q,E(q))},[]),A=s||_,I=o||x,T=b.useRef(null),$=b.useRef(null),P=b.useRef(h),W=u!=null,U=Y_(u),F=Y_(i),D=Y_(d),M=b.useCallback(()=>{if(!T.current||!$.current)return;const q={placement:t,strategy:n,middleware:y};F.current&&(q.platform=F.current),Gee(T.current,$.current,q).then(H=>{const L={...H,isPositioned:D.current!==!1};B.current&&!Vg(P.current,L)&&(P.current=L,id.flushSync(()=>{p(L)}))})},[y,t,n,F,D]);yg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(q=>({...q,isPositioned:!1})))},[d]);const B=b.useRef(!1);yg(()=>(B.current=!0,()=>{B.current=!1}),[]),yg(()=>{if(A&&(T.current=A),I&&($.current=I),A&&I){if(U.current)return U.current(A,I,M);M()}},[A,I,M,U,W]);const O=b.useMemo(()=>({reference:T,floating:$,setReference:k,setFloating:R}),[k,R]),N=b.useMemo(()=>({reference:A,floating:I}),[A,I]),V=b.useMemo(()=>{const q={position:n,left:0,top:0};if(!N.floating)return q;const H=MN(N.floating,h.x),L=MN(N.floating,h.y);return l?{...q,transform:"translate("+H+"px, "+L+"px)",...WI(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:L}},[n,l,N.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:M,refs:O,elements:N,floatingStyles:V}),[h,M,O,N,V])}const Jee=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?NN({element:r.current,padding:i}).fn(n):{}:r?NN({element:r,padding:i}).fn(n):{}}}},ete=(e,t)=>{const n=Uee(e);return{name:n.name,fn:n.fn,options:[e,t]}},tte=(e,t)=>{const n=Wee(e);return{name:n.name,fn:n.fn,options:[e,t]}},nte=(e,t)=>({fn:Kee(e).fn,options:[e,t]}),rte=(e,t)=>{const n=qee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ite=(e,t)=>{const n=Vee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ste=(e,t)=>{const n=Yee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ote=(e,t)=>{const n=Jee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var ate="Arrow",qI=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Zt.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"})})});qI.displayName=ate;var lte=qI,p1="Popper",[VI,yl]=sa(p1),[cte,YI]=VI(p1),KI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return g.jsx(cte,{scope:t,anchor:r,onAnchorChange:i,children:n})};KI.displayName=p1;var GI="PopperAnchor",XI=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=YI(GI,n),o=b.useRef(null),l=zn(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(Zt.div,{...i,ref:l})});XI.displayName=GI;var m1="PopperContent",[ute,dte]=VI(m1),ZI=b.forwardRef((e,t)=>{var ee,me,_e,Ce,Oe,Me;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,x=YI(m1,n),[E,k]=b.useState(null),R=zn(t,Ge=>k(Ge)),[A,I]=b.useState(null),T=nee(A),$=(T==null?void 0:T.width)??0,P=(T==null?void 0:T.height)??0,W=r+(s!=="center"?"-"+s:""),U=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},F=Array.isArray(d)?d:[d],D=F.length>0,M={padding:U,boundary:F.filter(fte),altBoundary:D},{refs:B,floatingStyles:O,placement:N,isPositioned:V,middlewareData:q}=Qee({strategy:"fixed",placement:W,whileElementsMounted:(...Ge)=>Hee(...Ge,{animationFrame:v==="always"}),elements:{reference:x.anchor},middleware:[ete({mainAxis:i+P,alignmentAxis:o}),u&&tte({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?nte():void 0,...M}),u&&rte({...M}),ite({...M,apply:({elements:Ge,rects:ct,availableWidth:At,availableHeight:ve})=>{const{width:Ve,height:Rt}=ct.reference,ye=Ge.floating.style;ye.setProperty("--radix-popper-available-width",`${At}px`),ye.setProperty("--radix-popper-available-height",`${ve}px`),ye.setProperty("--radix-popper-anchor-width",`${Ve}px`),ye.setProperty("--radix-popper-anchor-height",`${Rt}px`)}}),A&&ote({element:A,padding:l}),pte({arrowWidth:$,arrowHeight:P}),y&&ste({strategy:"referenceHidden",...M})]}),[H,L]=ez(N),Y=Co(_);Ei(()=>{V&&(Y==null||Y())},[V,Y]);const K=(ee=q.arrow)==null?void 0:ee.x,z=(me=q.arrow)==null?void 0:me.y,Q=((_e=q.arrow)==null?void 0:_e.centerOffset)!==0,[J,ne]=b.useState();return Ei(()=>{E&&ne(window.getComputedStyle(E).zIndex)},[E]),g.jsx("div",{ref:B.setFloating,"data-radix-popper-content-wrapper":"",style:{...O,transform:V?O.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(Ce=q.transformOrigin)==null?void 0:Ce.x,(Oe=q.transformOrigin)==null?void 0:Oe.y].join(" "),...((Me=q.hide)==null?void 0:Me.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(ute,{scope:n,placedSide:H,onArrowChange:I,arrowX:K,arrowY:z,shouldHideArrow:Q,children:g.jsx(Zt.div,{"data-side":H,"data-align":L,...w,ref:R,style:{...w.style,animation:V?void 0:"none"}})})})});ZI.displayName=m1;var QI="PopperArrow",hte={top:"bottom",right:"left",bottom:"top",left:"right"},JI=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=dte(QI,r),o=hte[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(lte,{...i,ref:n,style:{...i.style,display:"block"}})})});JI.displayName=QI;function fte(e){return e!==null}var pte=e=>({name:"transformOrigin",options:e,fn(t){var x,E,k;const{placement:n,rects:r,middlewareData:i}=t,o=((x=i.arrow)==null?void 0:x.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,h]=ez(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.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 ez(e){const[t,n="center"]=e.split("-");return[t,n]}var Iv=KI,Bf=XI,zv=ZI,Bv=JI,K_="rovingFocusGroup.onEntryFocus",mte={bubbles:!1,cancelable:!0},jf="RovingFocusGroup",[N0,tz,gte]=Qx(jf),[vte,nz]=sa(jf,[gte]),[yte,bte]=vte(jf),rz=b.forwardRef((e,t)=>g.jsx(N0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(N0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(_te,{...e,ref:t})})}));rz.displayName=jf;var _te=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=zn(t,y),_=Jx(s),[w,x]=sc({prop:o,defaultProp:l??null,onChange:u,caller:jf}),[E,k]=b.useState(!1),R=Co(d),A=tz(n),I=b.useRef(!1),[T,$]=b.useState(0);return b.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(K_,R),()=>P.removeEventListener(K_,R)},[R]),g.jsx(yte,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(P=>x(P),[x]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>$(P=>P+1),[]),onFocusableItemRemove:b.useCallback(()=>$(P=>P-1),[]),children:g.jsx(Zt.div,{tabIndex:E||T===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:yt(e.onMouseDown,()=>{I.current=!0}),onFocus:yt(e.onFocus,P=>{const W=!I.current;if(P.target===P.currentTarget&&W&&!E){const U=new CustomEvent(K_,mte);if(P.currentTarget.dispatchEvent(U),!U.defaultPrevented){const F=A().filter(N=>N.focusable),D=F.find(N=>N.active),M=F.find(N=>N.id===w),O=[D,M,...F].filter(Boolean).map(N=>N.ref.current);oz(O,h)}}I.current=!1}),onBlur:yt(e.onBlur,()=>k(!1))})})}),iz="RovingFocusGroupItem",sz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=bte(iz,n),p=h.currentTabStopId===d,y=tz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=h;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),g.jsx(N0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Zt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:yt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:yt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:yt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=xte(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(E==="last")R.reverse();else if(E==="prev"||E==="next"){E==="prev"&&R.reverse();const A=R.indexOf(x.currentTarget);R=h.loop?Ete(R,A+1):R.slice(A+1)}setTimeout(()=>oz(R))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});sz.displayName=iz;var wte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ste(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function xte(e,t,n){const r=Ste(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return wte[r]}function oz(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ete(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Cte=rz,kte=sz,M0=["Enter"," "],Tte=["ArrowDown","PageUp","Home"],az=["ArrowUp","PageDown","End"],Rte=[...Tte,...az],Ate={ltr:[...M0,"ArrowRight"],rtl:[...M0,"ArrowLeft"]},Nte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ff="Menu",[mf,Mte,Ote]=Qx(Ff),[bc,lz]=sa(Ff,[Ote,yl,nz]),jv=yl(),cz=nz(),[Dte,_c]=bc(Ff),[Pte,$f]=bc(Ff),uz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=jv(t),[u,d]=b.useState(null),h=b.useRef(!1),p=Co(s),y=Jx(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(Iv,{...l,children:g.jsx(Dte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(Pte,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};uz.displayName=Ff;var Lte="MenuAnchor",g1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bf,{...i,...r,ref:t})});g1.displayName=Lte;var v1="MenuPortal",[Ite,dz]=bc(v1,{forceMount:void 0}),hz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=_c(v1,t);return g.jsx(Ite,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(od,{asChild:!0,container:i,children:r})})})};hz.displayName=v1;var As="MenuContent",[zte,y1]=bc(As),fz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_c(As,e.__scopeMenu),o=$f(As,e.__scopeMenu);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(Bte,{...i,ref:t}):g.jsx(jte,{...i,ref:t})})})})}),Bte=b.forwardRef((e,t)=>{const n=_c(As,e.__scopeMenu),r=b.useRef(null),i=zn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Nv(s)},[]),g.jsx(b1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),jte=b.forwardRef((e,t)=>{const n=_c(As,e.__scopeMenu);return g.jsx(b1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Fte=ol("MenuContent.ScrollLock"),b1=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,x=_c(As,n),E=$f(As,n),k=jv(n),R=cz(n),A=Mte(n),[I,T]=b.useState(null),$=b.useRef(null),P=zn(t,$,x.onContentChange),W=b.useRef(0),U=b.useRef(""),F=b.useRef(0),D=b.useRef(null),M=b.useRef("right"),B=b.useRef(0),O=_?If:b.Fragment,N=_?{as:Fte,allowPinchZoom:!0}:void 0,V=H=>{var ee,me;const L=U.current+H,Y=A().filter(_e=>!_e.disabled),K=document.activeElement,z=(ee=Y.find(_e=>_e.ref.current===K))==null?void 0:ee.textValue,Q=Y.map(_e=>_e.textValue),J=Qte(Q,L,z),ne=(me=Y.find(_e=>_e.textValue===J))==null?void 0:me.ref.current;(function _e(Ce){U.current=Ce,window.clearTimeout(W.current),Ce!==""&&(W.current=window.setTimeout(()=>_e(""),1e3))})(L),ne&&setTimeout(()=>ne.focus())};b.useEffect(()=>()=>window.clearTimeout(W.current),[]),Rv();const q=b.useCallback(H=>{var Y,K;return M.current===((Y=D.current)==null?void 0:Y.side)&&ene(H,(K=D.current)==null?void 0:K.area)},[]);return g.jsx(zte,{scope:n,searchRef:U,onItemEnter:b.useCallback(H=>{q(H)&&H.preventDefault()},[q]),onItemLeave:b.useCallback(H=>{var L;q(H)||((L=$.current)==null||L.focus(),T(null))},[q]),onTriggerLeave:b.useCallback(H=>{q(H)&&H.preventDefault()},[q]),pointerGraceTimerRef:F,onPointerGraceIntentChange:b.useCallback(H=>{D.current=H},[]),children:g.jsx(O,{...N,children:g.jsx(Lf,{asChild:!0,trapped:i,onMountAutoFocus:yt(s,H=>{var L;H.preventDefault(),(L=$.current)==null||L.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(sd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Cte,{asChild:!0,...R,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:T,onEntryFocus:yt(u,H=>{E.isUsingKeyboardRef.current||H.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(zv,{role:"menu","aria-orientation":"vertical","data-state":Az(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:yt(w.onKeyDown,H=>{const Y=H.target.closest("[data-radix-menu-content]")===H.currentTarget,K=H.ctrlKey||H.altKey||H.metaKey,z=H.key.length===1;Y&&(H.key==="Tab"&&H.preventDefault(),!K&&z&&V(H.key));const Q=$.current;if(H.target!==Q||!Rte.includes(H.key))return;H.preventDefault();const ne=A().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);az.includes(H.key)&&ne.reverse(),Xte(ne)}),onBlur:yt(e.onBlur,H=>{H.currentTarget.contains(H.target)||(window.clearTimeout(W.current),U.current="")}),onPointerMove:yt(e.onPointerMove,gf(H=>{const L=H.target,Y=B.current!==H.clientX;if(H.currentTarget.contains(L)&&Y){const K=H.clientX>B.current?"right":"left";M.current=K,B.current=H.clientX}}))})})})})})})});fz.displayName=As;var $te="MenuGroup",_1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Zt.div,{role:"group",...r,ref:t})});_1.displayName=$te;var Hte="MenuLabel",pz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Zt.div,{...r,ref:t})});pz.displayName=Hte;var Yg="MenuItem",ON="menu.itemSelect",Fv=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=$f(Yg,e.__scopeMenu),l=y1(Yg,e.__scopeMenu),u=zn(t,s),d=b.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(ON,{bubbles:!0,cancelable:!0});p.addEventListener(ON,v=>r==null?void 0:r(v),{once:!0}),tI(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(mz,{...i,ref:u,disabled:n,onClick:yt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:yt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:yt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||M0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Fv.displayName=Yg;var mz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=y1(Yg,n),l=cz(n),u=b.useRef(null),d=zn(t,u),[h,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),g.jsx(mf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(kte,{asChild:!0,...l,focusable:!r,children:g.jsx(Zt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:yt(e.onPointerMove,gf(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:yt(e.onPointerLeave,gf(_=>o.onItemLeave(_))),onFocus:yt(e.onFocus,()=>p(!0)),onBlur:yt(e.onBlur,()=>p(!1))})})})}),Ute="MenuCheckboxItem",gz=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(wz,{scope:e.__scopeMenu,checked:n,children:g.jsx(Fv,{role:"menuitemcheckbox","aria-checked":Kg(n)?"mixed":n,...i,ref:t,"data-state":S1(n),onSelect:yt(i.onSelect,()=>r==null?void 0:r(Kg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});gz.displayName=Ute;var vz="MenuRadioGroup",[Wte,qte]=bc(vz,{value:void 0,onValueChange:()=>{}}),yz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Co(r);return g.jsx(Wte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(_1,{...i,ref:t})})});yz.displayName=vz;var bz="MenuRadioItem",_z=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=qte(bz,e.__scopeMenu),s=n===i.value;return g.jsx(wz,{scope:e.__scopeMenu,checked:s,children:g.jsx(Fv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":S1(s),onSelect:yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});_z.displayName=bz;var w1="MenuItemIndicator",[wz,Vte]=bc(w1,{checked:!1}),Sz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=Vte(w1,n);return g.jsx(Ps,{present:r||Kg(s.checked)||s.checked===!0,children:g.jsx(Zt.span,{...i,ref:t,"data-state":S1(s.checked)})})});Sz.displayName=w1;var Yte="MenuSeparator",xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Zt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});xz.displayName=Yte;var Kte="MenuArrow",Ez=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bv,{...i,...r,ref:t})});Ez.displayName=Kte;var Gte="MenuSub",[nRe,Cz]=bc(Gte),Ih="MenuSubTrigger",kz=b.forwardRef((e,t)=>{const n=_c(Ih,e.__scopeMenu),r=$f(Ih,e.__scopeMenu),i=Cz(Ih,e.__scopeMenu),s=y1(Ih,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(g1,{asChild:!0,...d,children:g.jsx(mz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Az(n.open),...e,ref:na(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:yt(e.onPointerMove,gf(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:yt(e.onPointerLeave,gf(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,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],R=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,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:yt(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Ate[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});kz.displayName=Ih;var Tz="MenuSubContent",Rz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_c(As,e.__scopeMenu),o=$f(As,e.__scopeMenu),l=Cz(Tz,e.__scopeMenu),u=b.useRef(null),d=zn(t,u);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:g.jsx(b1,{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:yt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:yt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:yt(e.onKeyDown,h=>{var v;const p=h.currentTarget.contains(h.target),y=Nte[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),h.preventDefault())})})})})})});Rz.displayName=Tz;function Az(e){return e?"open":"closed"}function Kg(e){return e==="indeterminate"}function S1(e){return Kg(e)?"indeterminate":e?"checked":"unchecked"}function Xte(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Zte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Qte(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=Zte(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 Jte(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 ene(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Jte(n,t)}function gf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var tne=uz,nne=g1,rne=hz,ine=fz,sne=_1,one=pz,ane=Fv,lne=gz,cne=yz,une=_z,dne=Sz,hne=xz,fne=Ez,pne=kz,mne=Rz,$v="DropdownMenu",[gne]=sa($v,[lz]),Pi=lz(),[vne,Nz]=gne($v),Mz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Pi(t),d=b.useRef(null),[h,p]=sc({prop:i,defaultProp:s??!1,onChange:o,caller:$v});return g.jsx(vne,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(tne,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};Mz.displayName=$v;var Oz="DropdownMenuTrigger",Dz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Nz(Oz,n),o=Pi(n);return g.jsx(nne,{asChild:!0,...o,children:g.jsx(Zt.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:na(t,s.triggerRef),onPointerDown:yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Dz.displayName=Oz;var yne="DropdownMenuPortal",Pz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Pi(t);return g.jsx(rne,{...r,...n})};Pz.displayName=yne;var Lz="DropdownMenuContent",Iz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Nz(Lz,n),s=Pi(n),o=b.useRef(!1);return g.jsx(ine,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:yt(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)"}})});Iz.displayName=Lz;var bne="DropdownMenuGroup",_ne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(sne,{...i,...r,ref:t})});_ne.displayName=bne;var wne="DropdownMenuLabel",zz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(one,{...i,...r,ref:t})});zz.displayName=wne;var Sne="DropdownMenuItem",Bz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(ane,{...i,...r,ref:t})});Bz.displayName=Sne;var xne="DropdownMenuCheckboxItem",jz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(lne,{...i,...r,ref:t})});jz.displayName=xne;var Ene="DropdownMenuRadioGroup",Cne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(cne,{...i,...r,ref:t})});Cne.displayName=Ene;var kne="DropdownMenuRadioItem",Tne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(une,{...i,...r,ref:t})});Tne.displayName=kne;var Rne="DropdownMenuItemIndicator",Fz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(dne,{...i,...r,ref:t})});Fz.displayName=Rne;var Ane="DropdownMenuSeparator",$z=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(hne,{...i,...r,ref:t})});$z.displayName=Ane;var Nne="DropdownMenuArrow",Mne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(fne,{...i,...r,ref:t})});Mne.displayName=Nne;var One="DropdownMenuSubTrigger",Dne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(pne,{...i,...r,ref:t})});Dne.displayName=One;var Pne="DropdownMenuSubContent",Lne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(mne,{...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)"}})});Lne.displayName=Pne;var Ine=Mz,zne=Dz,Bne=Pz,jne=Iz,Fne=zz,$ne=Bz,Hne=jz,Une=Fz,Wne=$z;function DN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Hv="Popover",[Hz]=sa(Hv,[yl]),Hf=yl(),[qne,bl]=Hz(Hv),Uz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Hf(t),u=b.useRef(null),[d,h]=b.useState(!1),[p,y]=sc({prop:r,defaultProp:i??!1,onChange:s,caller:Hv});return g.jsx(Iv,{...l,children:g.jsx(qne,{scope:t,contentId:gi(),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})})};Uz.displayName=Hv;var Wz="PopoverAnchor",Vne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bl(Wz,n),s=Hf(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(Bf,{...s,...r,ref:t})});Vne.displayName=Wz;var qz="PopoverTrigger",Vz=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bl(qz,n),s=Hf(n),o=zn(t,i.triggerRef),l=g.jsx(Zt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Zz(i.open),...r,ref:o,onClick:yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(Bf,{asChild:!0,...s,children:l})});Vz.displayName=qz;var x1="PopoverPortal",[Yne,Kne]=Hz(x1,{forceMount:void 0}),Yz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=bl(x1,t);return g.jsx(Yne,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(od,{asChild:!0,container:i,children:r})})})};Yz.displayName=x1;var Vu="PopoverContent",Kz=b.forwardRef((e,t)=>{const n=Kne(Vu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=bl(Vu,e.__scopePopover);return g.jsx(Ps,{present:r||s.open,children:s.modal?g.jsx(Xne,{...i,ref:t}):g.jsx(Zne,{...i,ref:t})})});Kz.displayName=Vu;var Gne=ol("PopoverContent.RemoveScroll"),Xne=b.forwardRef((e,t)=>{const n=bl(Vu,e.__scopePopover),r=b.useRef(null),i=zn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Nv(o)},[]),g.jsx(If,{as:Gne,allowPinchZoom:!0,children:g.jsx(Gz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:yt(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:yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Zne=b.forwardRef((e,t)=>{const n=bl(Vu,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return g.jsx(Gz,{...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()}})}),Gz=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=bl(Vu,n),v=Hf(n);return Rv(),g.jsx(Lf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(sd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(zv,{"data-state":Zz(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)"}})})})}),Xz="PopoverClose",Qne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bl(Xz,n);return g.jsx(Zt.button,{type:"button",...r,ref:t,onClick:yt(e.onClick,()=>i.onOpenChange(!1))})});Qne.displayName=Xz;var Jne="PopoverArrow",ere=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Hf(n);return g.jsx(Bv,{...i,...r,ref:t})});ere.displayName=Jne;function Zz(e){return e?"open":"closed"}var tre=Uz,nre=Vz,rre=Yz,ire=Kz,sre=[" ","Enter","ArrowUp","ArrowDown"],ore=[" ","Enter"],lc="Select",[Uv,Wv,are]=Qx(lc),[cd]=sa(lc,[are,yl]),qv=yl(),[lre,_l]=cd(lc),[cre,ure]=cd(lc),Qz=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=qv(t),[x,E]=b.useState(null),[k,R]=b.useState(null),[A,I]=b.useState(!1),T=Jx(d),[$,P]=sc({prop:r,defaultProp:i??!1,onChange:s,caller:lc}),[W,U]=sc({prop:o,defaultProp:l,onChange:u,caller:lc}),F=b.useRef(null),D=x?_||!!x.closest("form"):!0,[M,B]=b.useState(new Set),O=Array.from(M).map(N=>N.props.value).join(";");return g.jsx(Iv,{...w,children:g.jsxs(lre,{required:v,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:I,contentId:gi(),value:W,onValueChange:U,open:$,onOpenChange:P,dir:T,triggerPointerDownPosRef:F,disabled:y,children:[g.jsx(Uv.Provider,{scope:t,children:g.jsx(cre,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(N=>{B(V=>new Set(V).add(N))},[]),onNativeOptionRemove:b.useCallback(N=>{B(V=>{const q=new Set(V);return q.delete(N),q})},[]),children:n})}),D?g.jsxs(_B,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:W,onChange:N=>U(N.target.value),disabled:y,form:_,children:[W===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},O):null]})})};Qz.displayName=lc;var Jz="SelectTrigger",eB=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=qv(n),o=_l(Jz,n),l=o.disabled||r,u=zn(t,o.onTriggerChange),d=Wv(n),h=b.useRef("touch"),[p,y,v]=SB(w=>{const x=d().filter(R=>!R.disabled),E=x.find(R=>R.value===o.value),k=xB(x,w,E);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(Bf,{asChild:!0,...s,children:g.jsx(Zt.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":wB(o.value)?"":void 0,...i,ref:u,onClick:yt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&_(w)}),onPointerDown:yt(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:yt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&sre.includes(w.key)&&(_(),w.preventDefault())})})})});eB.displayName=Jz;var tB="SelectValue",nB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=_l(tB,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=zn(t,u.onValueNodeChange);return Ei(()=>{d(h)},[d,h]),g.jsx(Zt.span,{...l,ref:p,style:{pointerEvents:"none"},children:wB(u.value)?g.jsx(g.Fragment,{children:o}):s})});nB.displayName=tB;var dre="SelectIcon",rB=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Zt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});rB.displayName=dre;var hre="SelectPortal",iB=e=>g.jsx(od,{asChild:!0,...e});iB.displayName=hre;var cc="SelectContent",sB=b.forwardRef((e,t)=>{const n=_l(cc,e.__scopeSelect),[r,i]=b.useState();if(Ei(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?id.createPortal(g.jsx(oB,{scope:e.__scopeSelect,children:g.jsx(Uv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(aB,{...e,ref:t})});sB.displayName=cc;var Us=10,[oB,wl]=cd(cc),fre="SelectContentImpl",pre=ol("SelectContent.RemoveScroll"),aB=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:x,...E}=e,k=_l(cc,n),[R,A]=b.useState(null),[I,T]=b.useState(null),$=zn(t,ee=>A(ee)),[P,W]=b.useState(null),[U,F]=b.useState(null),D=Wv(n),[M,B]=b.useState(!1),O=b.useRef(!1);b.useEffect(()=>{if(R)return Nv(R)},[R]),Rv();const N=b.useCallback(ee=>{const[me,..._e]=D().map(Me=>Me.ref.current),[Ce]=_e.slice(-1),Oe=document.activeElement;for(const Me of ee)if(Me===Oe||(Me==null||Me.scrollIntoView({block:"nearest"}),Me===me&&I&&(I.scrollTop=0),Me===Ce&&I&&(I.scrollTop=I.scrollHeight),Me==null||Me.focus(),document.activeElement!==Oe))return},[D,I]),V=b.useCallback(()=>N([P,R]),[N,P,R]);b.useEffect(()=>{M&&V()},[M,V]);const{onOpenChange:q,triggerPointerDownPosRef:H}=k;b.useEffect(()=>{if(R){let ee={x:0,y:0};const me=Ce=>{var Oe,Me;ee={x:Math.abs(Math.round(Ce.pageX)-(((Oe=H.current)==null?void 0:Oe.x)??0)),y:Math.abs(Math.round(Ce.pageY)-(((Me=H.current)==null?void 0:Me.y)??0))}},_e=Ce=>{ee.x<=10&&ee.y<=10?Ce.preventDefault():R.contains(Ce.target)||q(!1),document.removeEventListener("pointermove",me),H.current=null};return H.current!==null&&(document.addEventListener("pointermove",me),document.addEventListener("pointerup",_e,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",me),document.removeEventListener("pointerup",_e,{capture:!0})}}},[R,q,H]),b.useEffect(()=>{const ee=()=>q(!1);return window.addEventListener("blur",ee),window.addEventListener("resize",ee),()=>{window.removeEventListener("blur",ee),window.removeEventListener("resize",ee)}},[q]);const[L,Y]=SB(ee=>{const me=D().filter(Oe=>!Oe.disabled),_e=me.find(Oe=>Oe.ref.current===document.activeElement),Ce=xB(me,ee,_e);Ce&&setTimeout(()=>Ce.ref.current.focus())}),K=b.useCallback((ee,me,_e)=>{const Ce=!O.current&&!_e;(k.value!==void 0&&k.value===me||Ce)&&(W(ee),Ce&&(O.current=!0))},[k.value]),z=b.useCallback(()=>R==null?void 0:R.focus(),[R]),Q=b.useCallback((ee,me,_e)=>{const Ce=!O.current&&!_e;(k.value!==void 0&&k.value===me||Ce)&&F(ee)},[k.value]),J=r==="popper"?O0:lB,ne=J===O0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:x}:{};return g.jsx(oB,{scope:n,content:R,viewport:I,onViewportChange:T,itemRefCallback:K,selectedItem:P,onItemLeave:z,itemTextRefCallback:Q,focusSelectedItem:V,selectedItemText:U,position:r,isPositioned:M,searchRef:L,children:g.jsx(If,{as:pre,allowPinchZoom:!0,children:g.jsx(Lf,{asChild:!0,trapped:k.open,onMountAutoFocus:ee=>{ee.preventDefault()},onUnmountAutoFocus:yt(i,ee=>{var me;(me=k.trigger)==null||me.focus({preventScroll:!0}),ee.preventDefault()}),children:g.jsx(sd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:ee=>ee.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(J,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:ee=>ee.preventDefault(),...E,...ne,onPlaced:()=>B(!0),ref:$,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:yt(E.onKeyDown,ee=>{const me=ee.ctrlKey||ee.altKey||ee.metaKey;if(ee.key==="Tab"&&ee.preventDefault(),!me&&ee.key.length===1&&Y(ee.key),["ArrowUp","ArrowDown","Home","End"].includes(ee.key)){let Ce=D().filter(Oe=>!Oe.disabled).map(Oe=>Oe.ref.current);if(["ArrowUp","End"].includes(ee.key)&&(Ce=Ce.slice().reverse()),["ArrowUp","ArrowDown"].includes(ee.key)){const Oe=ee.target,Me=Ce.indexOf(Oe);Ce=Ce.slice(Me+1)}setTimeout(()=>N(Ce)),ee.preventDefault()}})})})})})})});aB.displayName=fre;var mre="SelectItemAlignedPosition",lB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=_l(cc,n),o=wl(cc,n),[l,u]=b.useState(null),[d,h]=b.useState(null),p=zn(t,$=>h($)),y=Wv(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const $=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),W=s.valueNode.getBoundingClientRect(),U=E.getBoundingClientRect();if(s.dir!=="rtl"){const Oe=U.left-P.left,Me=W.left-Oe,Ge=$.left-Me,ct=$.width+Ge,At=Math.max(ct,P.width),ve=window.innerWidth-Us,Ve=DN(Me,[Us,Math.max(Us,ve-At)]);l.style.minWidth=ct+"px",l.style.left=Ve+"px"}else{const Oe=P.right-U.right,Me=window.innerWidth-W.right-Oe,Ge=window.innerWidth-$.right-Me,ct=$.width+Ge,At=Math.max(ct,P.width),ve=window.innerWidth-Us,Ve=DN(Me,[Us,Math.max(Us,ve-At)]);l.style.minWidth=ct+"px",l.style.right=Ve+"px"}const F=y(),D=window.innerHeight-Us*2,M=w.scrollHeight,B=window.getComputedStyle(d),O=parseInt(B.borderTopWidth,10),N=parseInt(B.paddingTop,10),V=parseInt(B.borderBottomWidth,10),q=parseInt(B.paddingBottom,10),H=O+N+M+q+V,L=Math.min(x.offsetHeight*5,H),Y=window.getComputedStyle(w),K=parseInt(Y.paddingTop,10),z=parseInt(Y.paddingBottom,10),Q=$.top+$.height/2-Us,J=D-Q,ne=x.offsetHeight/2,ee=x.offsetTop+ne,me=O+N+ee,_e=H-me;if(me<=Q){const Oe=F.length>0&&x===F[F.length-1].ref.current;l.style.bottom="0px";const Me=d.clientHeight-w.offsetTop-w.offsetHeight,Ge=Math.max(J,ne+(Oe?z:0)+Me+V),ct=me+Ge;l.style.height=ct+"px"}else{const Oe=F.length>0&&x===F[0].ref.current;l.style.top="0px";const Ge=Math.max(Q,O+w.offsetTop+(Oe?K:0)+ne)+_e;l.style.height=Ge+"px",w.scrollTop=me-Q+w.offsetTop}l.style.margin=`${Us}px 0`,l.style.minHeight=L+"px",l.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ei(()=>R(),[R]);const[A,I]=b.useState();Ei(()=>{d&&I(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback($=>{$&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return g.jsx(vre,{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(Zt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});lB.displayName=mre;var gre="SelectPopperPosition",O0=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Us,...s}=e,o=qv(n);return g.jsx(zv,{...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)"}})});O0.displayName=gre;var[vre,E1]=cd(cc,{}),D0="SelectViewport",cB=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=wl(D0,n),o=E1(D0,n),l=zn(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(Uv.Slot,{scope:n,children:g.jsx(Zt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:yt(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-Us*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<_){const k=E+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})})})]})});cB.displayName=D0;var uB="SelectGroup",[yre,bre]=cd(uB),_re=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return g.jsx(yre,{scope:n,id:i,children:g.jsx(Zt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});_re.displayName=uB;var dB="SelectLabel",wre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bre(dB,n);return g.jsx(Zt.div,{id:i.id,...r,ref:t})});wre.displayName=dB;var Gg="SelectItem",[Sre,hB]=cd(Gg),fB=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=_l(Gg,n),u=wl(Gg,n),d=l.value===r,[h,p]=b.useState(s??""),[y,v]=b.useState(!1),_=zn(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=gi(),x=b.useRef("touch"),E=()=>{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(Sre,{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(Uv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Zt.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:yt(o.onFocus,()=>v(!0)),onBlur:yt(o.onBlur,()=>v(!1)),onClick:yt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:yt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:yt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:yt(o.onPointerMove,k=>{var R;x.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:yt(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:yt(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(ore.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});fB.displayName=Gg;var zh="SelectItemText",pB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=_l(zh,n),l=wl(zh,n),u=hB(zh,n),d=ure(zh,n),[h,p]=b.useState(null),y=zn(t,E=>p(E),u.onItemTextChange,E=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,E,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:x}=d;return Ei(()=>(w(_),()=>x(_)),[w,x,_]),g.jsxs(g.Fragment,{children:[g.jsx(Zt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?id.createPortal(s.children,o.valueNode):null]})});pB.displayName=zh;var mB="SelectItemIndicator",gB=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return hB(mB,n).isSelected?g.jsx(Zt.span,{"aria-hidden":!0,...r,ref:t}):null});gB.displayName=mB;var P0="SelectScrollUpButton",vB=b.forwardRef((e,t)=>{const n=wl(P0,e.__scopeSelect),r=E1(P0,e.__scopeSelect),[i,s]=b.useState(!1),o=zn(t,r.onScrollButtonChange);return Ei(()=>{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(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});vB.displayName=P0;var L0="SelectScrollDownButton",yB=b.forwardRef((e,t)=>{const n=wl(L0,e.__scopeSelect),r=E1(L0,e.__scopeSelect),[i,s]=b.useState(!1),o=zn(t,r.onScrollButtonChange);return Ei(()=>{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(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});yB.displayName=L0;var bB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=wl("SelectScrollButton",n),o=b.useRef(null),l=Wv(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ei(()=>{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(Zt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:yt(i.onPointerLeave,()=>{u()})})}),xre="SelectSeparator",Ere=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Zt.div,{"aria-hidden":!0,...r,ref:t})});Ere.displayName=xre;var I0="SelectArrow",Cre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qv(n),s=_l(I0,n),o=wl(I0,n);return s.open&&o.position==="popper"?g.jsx(Bv,{...i,...r,ref:t}):null});Cre.displayName=I0;var kre="SelectBubbleInput",_B=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=zn(r,i),o=tee(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(Zt.select,{...n,style:{...nI,...n.style},ref:s,defaultValue:t})});_B.displayName=kre;function wB(e){return e===""||e===void 0}function SB(e){const t=Co(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 xB(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=Tre(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 Tre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Rre=Qz,Are=eB,Nre=nB,Mre=rB,Ore=iB,Dre=sB,Pre=cB,Lre=fB,Ire=pB,zre=gB,Bre=vB,jre=yB,[Vv]=sa("Tooltip",[yl]),Yv=yl(),EB="TooltipProvider",Fre=700,z0="tooltip.open",[$re,C1]=Vv(EB),CB=e=>{const{__scopeTooltip:t,delayDuration:n=Fre,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($re,{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})};CB.displayName=EB;var vf="Tooltip",[Hre,Uf]=Vv(vf),kB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=C1(vf,e.__scopeTooltip),d=Yv(t),[h,p]=b.useState(null),y=gi(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,x=b.useRef(!1),[E,k]=sc({prop:r,defaultProp:i??!1,onChange:$=>{$?(u.onOpen(),document.dispatchEvent(new CustomEvent(z0))):u.onClose(),s==null||s($)},caller:vf}),R=b.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,k(!0)},[k]),I=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Iv,{...d,children:g.jsx(Hre,{scope:t,contentId:y,open:E,stateAttribute:R,trigger:h,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?I():(window.clearTimeout(v.current),v.current=0)},[I,_]),onOpen:A,onClose:I,disableHoverableContent:_,children:n})})};kB.displayName=vf;var B0="TooltipTrigger",TB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Uf(B0,n),s=C1(B0,n),o=Yv(n),l=b.useRef(null),u=zn(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(Bf,{asChild:!0,...o,children:g.jsx(Zt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:yt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:yt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:yt(e.onBlur,i.onClose),onClick:yt(e.onClick,i.onClose)})})});TB.displayName=B0;var k1="TooltipPortal",[Ure,Wre]=Vv(k1,{forceMount:void 0}),RB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Uf(k1,t);return g.jsx(Ure,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(od,{asChild:!0,container:i,children:r})})})};RB.displayName=k1;var Yu="TooltipContent",AB=b.forwardRef((e,t)=>{const n=Wre(Yu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Uf(Yu,e.__scopeTooltip);return g.jsx(Ps,{present:r||o.open,children:o.disableHoverableContent?g.jsx(NB,{side:i,...s,ref:t}):g.jsx(qre,{side:i,...s,ref:t})})}),qre=b.forwardRef((e,t)=>{const n=Uf(Yu,e.__scopeTooltip),r=C1(Yu,e.__scopeTooltip),i=b.useRef(null),s=zn(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 x=_.currentTarget,E={x:_.clientX,y:_.clientY},k=Gre(E,x.getBoundingClientRect()),R=Xre(E,k),A=Zre(w.getBoundingClientRect()),I=Jre([...R,...A]);l(I),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&h){const _=x=>v(x,h),w=x=>v(x,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 x=w.target,E={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),R=!Qre(E,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,h,o,d,y]),g.jsx(NB,{...e,ref:s})}),[Vre,Yre]=Vv(vf,{isInside:!1}),Kre=TQ("TooltipContent"),NB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Uf(Yu,n),d=Yv(n),{onClose:h}=u;return b.useEffect(()=>(document.addEventListener(z0,h),()=>document.removeEventListener(z0,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(sd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(zv,{"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(Kre,{children:r}),g.jsx(Vre,{scope:n,isInside:!0,children:g.jsx(iI,{id:u.contentId,role:"tooltip",children:i||r})})]})})});AB.displayName=Yu;var MB="TooltipArrow",OB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Yv(n);return Yre(MB,n).isInside?null:g.jsx(Bv,{...i,...r,ref:t})});OB.displayName=MB;function Gre(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 Xre(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 Zre(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 Qre(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,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 Jre(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),eie(t)}function eie(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 tie=CB,nie=kB,rie=TB,iie=RB,sie=AB,oie=OB;function T1({...e}){return g.jsx(tre,{"data-slot":"popover",...e})}function R1({...e}){return g.jsx(nre,{"data-slot":"popover-trigger",...e})}function A1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(rre,{children:g.jsx(ire,{"data-slot":"popover-content",align:t,sideOffset:n,className:qe("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 aie={"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 tc({variant:e,action:t}){const{heading:n,body:r}=aie[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 lie={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},cie={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function PN({status:e,className:t}){return g.jsx("span",{className:qe("inline-block w-2 h-2 rounded-full shrink-0",lie[e],t),role:"status","aria-label":cie[e]})}function DB({layout:e,variant:t="default"}){const n=Ne(_=>_.proxies),r=Ne(_=>_.proxyListLoaded),i=Ne(_=>_.relayClientAuthIssue),s=Ne(_=>_.selectedProxyId),o=Ne(_=>_.proxySwitchTarget),l=Di(),u=Qs(),[d,h]=b.useState(!1);async function p(_,w){if(o)return;const x=Nt;if(!x){Je.error("请先连接开发机");return}const E=w??_,k=s!==null&&s!==_;Ne.getState().setProxySwitchTarget({proxyId:_,name:E});try{const R=await x.selectProxy(_);if(!R.success){Je.error(`无法连接 ${E}:${R.error??"未知错误"}`);return}k&&(zt.getState().prepareForProxySwitch(E),ii.getState().prepareForProxySwitch()),dr("local",cn.proxyId,_),Ne.getState().setProxy(_,w??null),Ne.getState().setProxyOnline(!0),Ne.getState().transitionToPhase("session_browsing"),x.sendControl({type:"session_list"}),x.requestProxyInfo().then(A=>{if(Ne.getState().selectedProxyId!==_)return;const I=ii.getState();I.setHomePath(A.homePath),I.setAgentCli(A.agentCli)}).catch(A=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",A)}),x.requestAgentStatuses().then(A=>{if(Ne.getState().selectedProxyId!==_)return;const I=zt.getState();for(const T of A)I.setAgentStatus(T.sessionId,T.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),x.requestSessionHistory().then(A=>{Ne.getState().selectedProxyId===_&&zt.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:"未知错误";Je.error(`无法连接 ${E}:${A}`)}finally{Ne.getState().setProxySwitchTarget(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(tc,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(tc,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(tc,{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,x=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||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:qe("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",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx(PN,{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(Jl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===_.proxyId?g.jsx(ta,{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(Jl,{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(T1,{open:d,onOpenChange:h,children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:qe("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:qe("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:v}),g.jsx(pl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(A1,{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,x=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||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:qe("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",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线",children:[g.jsx(PN,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsx(Jl,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===_.proxyId?g.jsx(ta,{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 LN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,IN=BP,uie=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return IN(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=LN(h)||LN(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,x]=_;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return IN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},die=uie("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 bt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?CQ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:qe(die({variant:t,size:n,className:e})),...i})}function hie({delayDuration:e=0,...t}){return g.jsx(tie,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Wf({...e}){return g.jsx(nie,{"data-slot":"tooltip",...e})}function qf({...e}){return g.jsx(rie,{"data-slot":"tooltip-trigger",...e})}function Vf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(iie,{children:g.jsxs(sie,{"data-slot":"tooltip-content",sideOffset:t,className:qe("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(oie,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Kv({...e}){return g.jsx(r1,{"data-slot":"sheet",...e})}function fie({...e}){return g.jsx(eee,{"data-slot":"sheet-trigger",...e})}function pie({...e}){return g.jsx(i1,{"data-slot":"sheet-portal",...e})}function mie({className:e,...t}){return g.jsx(s1,{"data-slot":"sheet-overlay",className:qe("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 Gv({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(mie,{className:t}),g.jsxs(o1,{"data-slot":"sheet-content",className:qe("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(a1,{"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(ed,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function N1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:qe("flex flex-col gap-1.5 p-4",e),...t})}function Xv({className:e,...t}){return g.jsx(OI,{"data-slot":"sheet-title",className:qe("font-semibold text-foreground",e),...t})}function gie({className:e,...t}){return g.jsx(DI,{"data-slot":"sheet-description",className:qe("text-sm text-muted-foreground",e),...t})}function M1({...e}){return g.jsx(Ine,{"data-slot":"dropdown-menu",...e})}function O1({...e}){return g.jsx(zne,{"data-slot":"dropdown-menu-trigger",...e})}function D1({className:e,sideOffset:t=4,...n}){return g.jsx(Bne,{children:g.jsx(jne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:qe("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 yo({className:e,inset:t,variant:n="default",...r}){return g.jsx($ne,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:qe("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 G_({className:e,children:t,checked:n,...r}){return g.jsxs(Hne,{"data-slot":"dropdown-menu-checkbox-item",className:qe("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(Une,{children:g.jsx(ta,{className:"size-4"})})}),t]})}function Bm({className:e,inset:t,...n}){return g.jsx(Fne,{"data-slot":"dropdown-menu-label","data-inset":t,className:qe("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function X_({className:e,...t}){return g.jsx(Wne,{"data-slot":"dropdown-menu-separator",className:qe("-mx-1 my-1 h-px bg-border",e),...t})}const vie={claude:"Claude Code",codex:"Codex"},zN=["claude","codex"];function Zv(e){return vie[e]}function PB(e,t){return zN.indexOf(e)-zN.indexOf(t)}function j0(e){return e.provider??"claude"}const F0=60*1e3,$0=60*F0,yie=24*$0;function LB(e,t=Date.now()){const n=t-e;if(n<F0)return"刚刚";if(n<$0)return`${Math.floor(n/F0)} 分钟前`;if(n<yie)return`${Math.floor(n/$0)} 小时前`;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 BN={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 H0(e){return e.kind!=="terminal"?BN[e.state]:e.state==="terminated"?BN.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=H0(e);return g.jsx("span",{className:qe("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function _ie({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;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 wie({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=kv(e.name),d=Kx(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?LB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:qe("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(_ie,{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:Zv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:qe("shrink-0",H0(e).text),children:H0(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(M1,{children:[g.jsx(O1,{asChild:!0,children:g.jsx(bt,{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(f8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(yo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(yo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function wc({...e}){return g.jsx(r1,{"data-slot":"dialog",...e})}function Sie({...e}){return g.jsx(i1,{"data-slot":"dialog-portal",...e})}function xie({className:e,...t}){return g.jsx(s1,{"data-slot":"dialog-overlay",className:qe("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 Sc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs(Sie,{"data-slot":"dialog-portal",children:[g.jsx(xie,{}),g.jsxs(o1,{"data-slot":"dialog-content",className:qe("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(a1,{"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(ed,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function xc({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:qe("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Ku({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:qe("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(a1,{asChild:!0,children:g.jsx(bt,{variant:"outline",children:"Close"})})]})}function cl({className:e,...t}){return g.jsx(OI,{"data-slot":"dialog-title",className:qe("text-lg leading-none font-semibold",e),...t})}function uc({className:e,...t}){return g.jsx(DI,{"data-slot":"dialog-description",className:qe("text-sm text-muted-foreground",e),...t})}function ul(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 Eie({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(Cie,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:LB(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:qe("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(j9,{className:qe("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 Cie({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(kie,{mode:t})]})}function kie({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:qe("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 IB({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(m7,{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 Tie({now:e}){const t=zt(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),[x,E]=b.useState(new Set),k=Qs(),R=b.useMemo(()=>{const F=new Map;for(const D of t){const M=j0(D);let B=F.get(M);B||(B=new Map,F.set(M,B));const O=zB(D.projectDir),N=B.get(O);N?N.sessions.push(D):B.set(O,{dir:O,sessions:[D]})}return Array.from(F.entries()).sort(([D],[M])=>PB(D,M)).map(([D,M])=>({provider:D,sessions:Array.from(M.values()).flatMap(B=>B.sessions),projects:Array.from(M.values()).map(B=>({dir:B.dir,shortDir:kv(B.dir),sessions:B.sessions}))}))},[t]);function A(F){s(F),l(Rie(F)),d("default")}async function I(F,D,M){if(n)return;const B=Nt;if(!B){Je.error("请先连接开发机");return}r(F.id);const O=j0(F);try{const N=await B.createSession({cwd:F.projectDir,mode:D,provider:O,resumeSessionId:F.id,...M?{permissionMode:M}:{}});if(N.error||!N.sessionId){Je.error(`恢复失败:${N.error??"未知错误"}`);return}const V={sessionId:N.sessionId,state:"idle",mode:N.mode??D,provider:N.provider??"claude"};zt.getState().addSession(V),k(`/chat/${N.sessionId}?mode=${N.mode??D}`),s(null)}catch(N){Je.error(`恢复失败:${N instanceof Error?N.message:String(N)}`)}finally{r(null)}}function T(){const F=Nt;!F||h||(p(!0),F.requestSessionHistory().then(D=>zt.getState().setHistorySessions(D)).catch(D=>{Je.error(D instanceof Error?D.message:String(D))}).finally(()=>{p(!1)}))}function $(F,D){const M=jN(F,D);E(B=>{const O=new Set(B);return O.has(M)?O.delete(M):O.add(M),O})}function P(F){w(D=>{const M=new Set(D);return M.has(F)?M.delete(F):M.add(F),M})}const W=t.length>0,U=i?BB():[];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:()=>W&&v(F=>!F),disabled:!W,"aria-expanded":W?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:qe("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:["全部会话",W?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),W?g.jsx(Xh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(bt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:T,disabled:h,"data-slot":"history-refresh",children:g.jsx(Nx,{className:qe("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!W&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),W&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(F=>{const D=_.has(F.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>P(F.provider),"aria-expanded":!D,"data-slot":"history-provider-header","data-expanded":!D,className:qe("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:Zv(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(Xh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!D&&"rotate-90"),"aria-hidden":"true"})]}),!D&&g.jsx("ul",{role:"list",className:"flex flex-col",children:F.projects.map(M=>{const B=jN(F.provider,M.dir),O=x.has(B);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>$(F.provider,M.dir),"aria-expanded":O,"data-slot":"history-group-header","data-expanded":O,className:qe("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(Xh,{className:qe("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:M.sessions.map(N=>g.jsx(Eie,{session:N,now:e,disabled:n!==null,loading:n===N.id,onClick:()=>A(N),modeTag:N.preferredMode},N.id))})]},B)})})]},F.provider)})}),g.jsx(Aie,{session:i,open:i!==null,modes:U,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:F=>{F||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&I(i,o,u)}})]})}function jN(e,t){return`${e}:${zB(t)}`}function zB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function BB(){return["json","pty"]}function Rie(e){const t=BB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Aie({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=ul("(min-width: 768px)");b.useEffect(()=>{t||p(!1)},[t]);const _=h?g.jsx(IB,{providerLabel:e?Zv(j0(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(FN,{checked:r==="json",label:"聊天",icon:g.jsx(Ax,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(FN,{checked:r==="pty",label:"终端",icon:g.jsx(Mx,{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(Z_,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(Z_,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(Z_,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(bt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(bt,{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(wc,{open:t,onOpenChange:o,children:g.jsxs(Sc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(xc,{className:"min-w-0",children:[g.jsx(cl,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(uc,{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(Ku,{children:w})]})}):g.jsx(Kv,{open:t,onOpenChange:o,children:g.jsxs(Gv,{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(N1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Xv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(gie,{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 FN({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:qe("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(ta,{className:qe("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Z_({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:qe("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:qe("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:qe("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:qe("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(ta,{className:qe("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Nie({...e}){return g.jsx(Rre,{"data-slot":"select",...e})}function Mie({...e}){return g.jsx(Nre,{"data-slot":"select-value",...e})}function Oie({className:e,size:t="default",children:n,...r}){return g.jsxs(Are,{"data-slot":"select-trigger","data-size":t,className:qe("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(Mre,{asChild:!0,children:g.jsx(pl,{className:"size-4 opacity-50"})})]})}function Die({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(Ore,{children:g.jsxs(Dre,{"data-slot":"select-content",className:qe("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(Lie,{}),g.jsx(Pre,{className:qe("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(Iie,{})]})})}function Pie({className:e,children:t,...n}){return g.jsxs(Lre,{"data-slot":"select-item",className:qe("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(zre,{children:g.jsx(ta,{className:"size-4"})})}),g.jsx(Ire,{children:t})]})}function Lie({className:e,...t}){return g.jsx(Bre,{"data-slot":"select-scroll-up-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Rx,{className:"size-4"})})}function Iie({className:e,...t}){return g.jsx(jre,{"data-slot":"select-scroll-down-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(pl,{className:"size-4"})})}function P1(e){return!e||e.endsWith("/")?e:`${e}/`}function zie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function Bie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function jie(e,t,n){var o;if(t==="insert")return{currentPath:Bie(e)||"./",query:zie(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:P1(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 Fie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function $ie(e,t){return`${P1(e)}${t.name}${t.isDir?"/":""}`}function $N(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 jB=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ii(H=>H.tree),h=ii(H=>H.cwd),p=ii(H=>H.homePath),y=i==="insert"?h:p||h,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>jie(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,x=b.useMemo(()=>Fie(y,w),[y,w]),E=_.query,k=b.useRef(new Set),[R,A]=b.useState(!1),[I,T]=b.useState(""),[$,P]=b.useState(!1);b.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const H=Nt;if(!H)return;let L=!1;return k.current.add(x),H.requestDirectoryList(x).then(Y=>{L||ii.getState().setDirEntries(Y.path,Y.entries)}).catch(()=>{L||ii.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{L=!0}},[x,d]);const W=!d.has(x),U=b.useMemo(()=>{let H=d.get(x)??[];return o&&(H=H.filter(L=>L.isDir)),E&&(H=H.filter(L=>L.name.toLowerCase().includes(E))),H},[d,x,E,o]),[F,D]=b.useState(0);b.useEffect(()=>D(0),[w,E]),b.useEffect(()=>{A(!1),T("")},[x]),b.useEffect(()=>{F>=U.length&&U.length>0&&D(U.length-1)},[U.length,F]);const M=b.useRef(null),B=b.useRef(!1);b.useEffect(()=>{var L;if(!B.current)return;B.current=!1;const H=(L=M.current)==null?void 0:L.querySelector(`[data-entry-index="${F}"]`);H==null||H.scrollIntoView({block:"nearest"})},[F]);const O=b.useCallback(H=>{const L=$ie(w,H);return i==="insert"?L.replace(/^\.\//,""):L},[w,i]);async function N(){const H=$N(x,I);if(!(!H||!r)){P(!0);try{const L=await r(H);if(!L)return;T(""),A(!1),n(P1(L))}finally{P(!1)}}}b.useImperativeHandle(u,()=>({handleKey(H){return U.length===0?!1:H.key==="ArrowDown"?(B.current=!0,D(L=>Math.min(U.length-1,L+1)),!0):H.key==="ArrowUp"?(B.current=!0,D(L=>Math.max(0,L-1)),!0):H.key==="Enter"&&!H.nativeEvent.isComposing?(n(O(U[F])),!0):!1}}),[U,F,O,n]);const V=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",q=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:V,"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:!x||$,onClick:()=>A(H=>!H),children:"新建目录"}):null]}),R?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:I,onChange:H=>T(H.target.value),onKeyDown:H=>{H.key==="Enter"&&!H.nativeEvent.isComposing&&(H.preventDefault(),N()),H.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:!$N(x,I)||$,onClick:()=>void N(),children:$?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:q,children:U.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:W?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map((H,L)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(O(H)),onMouseEnter:()=>D(L),className:qe("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",L===F&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",H.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":H.isDir?"dir":"file","data-entry-index":L,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[H.name,H.isDir?"/":""]})})},H.name))})})]})}),HN="工作目录不存在或不可访问:",Hie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],FB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],ea={claude:"Claude Code",codex:"Codex"};function Uie(e,t){return t!==Zr.PATH_NOT_FOUND||!e.startsWith(HN)?null:e.slice(HN.length).trim()||null}function Xg(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 Wie(e,t){return t.title?t.disabled?`${ea[e]}:${t.title}`:`${ea[e]} 路径:${t.title}`:`${ea[e]}:${t.label}`}function qie(e,t){return e!=="codex"||FB.some(n=>n.value===t)?t:"default"}async function Vie({relay:e,agentCli:t,form:n,timeoutMs:r=Vx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Xg(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?`${ea[n.provider]} 不可用:${p}`:`${ea[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=Uie(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 Yie({relay:e,timeoutMs:t=Vx}){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 Kie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Xg("claude",e),y=Xg("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(UN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(UN,{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(Gie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(Xie,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function UN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Wf,{children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":ea[e],onClick:i,className:qe("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:ea[e]}),g.jsx("span",{className:qe("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(Vf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:Wie(e,n)})})]})}function Gie({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"?"/home/dev/.local/bin/claude":"/home/dev/.local/bin/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(bt,{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(bt,{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 Xie({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:qe("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(bt,{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(bt,{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(W8,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:qe("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 Bh({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),[x,E]=b.useState(null),[k,R]=b.useState(!1),[A,I]=b.useState(null),[T,$]=b.useState(""),[P,W]=b.useState(!1),U=b.useRef(null),F=b.useRef(e);F.current=e;const D=Qs(),M=ii(Ce=>Ce.homePath),B=ii(Ce=>Ce.agentCli),O=ul("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&B)return;const Ce=Nt==null?void 0:Nt.requestProxyInfo();Ce&&Ce.then(Oe=>{const Me=ii.getState();Me.setHomePath(Oe.homePath),Me.setAgentCli(Oe.agentCli)}).catch(Oe=>{console.error("[create-session-dialog] requestProxyInfo failed",Oe)})},[e,M,B]),b.useEffect(()=>{if(!k)return;function Ce(Oe){var Ge;const Me=Oe.target;Me instanceof Node&&((Ge=U.current)!=null&&Ge.contains(Me))||window.setTimeout(()=>R(!1),0)}return document.addEventListener("pointerdown",Ce,!0),()=>document.removeEventListener("pointerdown",Ce,!0)},[k]);function N(){r(""),s(""),R(!1),l("claude"),d("pty"),p("default"),v(!1),E(null),I(null),$(""),W(!1)}function V(){if(h==="bypassPermissions"){v(!0);return}z()}async function q(){await z(),F.current&&v(!1)}const H=o==="codex"?FB:Hie,L=Xg(o,B),Y=_||P||L.disabled;function K(Ce){const Oe=qie(Ce,h);Oe!==h&&p(Oe)}async function z(Ce){E(null),w(!0);try{const Oe=await Vie({relay:Nt,agentCli:B,form:{cwd:Ce??i,name:n,provider:o,permissionMode:h,mode:u}});if(Oe.type==="success"){if(zt.getState().addSession(Oe.session),!F.current)return;t(!1),N(),D(Oe.route);return}if(Oe.type==="missing_cwd"&&E(Oe.path),Je.error(Oe.message),Oe.type==="validation_error"||Oe.type==="relay_missing")return}finally{w(!1)}}async function Q(Ce){const Oe=Nt;if(!Oe)return Je.error("请先连接开发机"),null;try{const Me=await Oe.createDirectory(Ce);return Me.success?(s(Me.path),E(null),Je.success("目录已创建"),Me.path):(Je.error(`目录创建失败:${Me.error??"未知错误"}`),null)}catch(Me){return Je.error(Me instanceof Error?Me.message:String(Me)),null}}function J(Ce){var Me;const Oe=B==null?void 0:B[Ce];I(Ce),$((Oe==null?void 0:Oe.command)??((Me=Oe==null?void 0:Oe.suggestions)==null?void 0:Me[0])??"")}async function ne(){if(!A)return;const Ce=T.trim();if(!Ce){Je.error("请输入 Agent CLI 路径");return}const Oe=Nt;if(!Oe){Je.error("请先连接开发机");return}W(!0);try{const Me=await Oe.updateAgentCliPath(A,Ce);if(Me.error||!Me.agentCli){Je.error(`路径保存失败:${Me.error??"未知错误"}`);return}ii.getState().setAgentCli(Me.agentCli),Je.success(`${ea[A]} 路径已保存`),I(null),$("")}catch(Me){Je.error(Me instanceof Error?Me.message:String(Me))}finally{W(!1)}}function ee(Ce){d(Ce),K(o)}function me(Ce){var Me;const Oe=Ce.relatedTarget;Oe instanceof Node&&((Me=U.current)!=null&&Me.contains(Oe))||window.setTimeout(()=>R(!1),0)}const _e=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(IB,{providerLabel:ea[o]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),g.jsx(bt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void q(),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:Ce=>{Ce.preventDefault(),V()},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:Ce=>r(Ce.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:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:me,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:Ce=>{s(Ce.target.value),E(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(jB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:Q,onSelect:Ce=>{s(Ce),E(null),R(!0)}}):null]}),x?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:x})]}):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:()=>ee("pty"),className:qe("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:()=>ee("json"),className:qe("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(Kie,{agentCli:B,provider:o,isDesktop:O,editingCliProvider:A,cliPathInput:T,savingCliPath:P,onProviderChange:Ce=>{l(Ce),K(Ce)},onOpenCliPathEditor:J,onCliPathInputChange:$,onCancelCliPathEditor:()=>{I(null),$("")},onSaveCliPath:()=>void ne()}),g.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"权限模式"}),g.jsxs(Nie,{value:h,onValueChange:Ce=>p(Ce),children:[g.jsx(Oie,{className:"w-full",children:g.jsx(Mie,{})}),g.jsx(Die,{children:H.map(Ce=>g.jsx(Pie,{value:Ce.value,children:Ce.label},Ce.value))})]})]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),g.jsx(bt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return O?g.jsx(wc,{open:e,onOpenChange:t,children:g.jsxs(Sc,{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(xc,{children:g.jsx(cl,{children:y?"跳过全部审批?":"新建会话"})}),_e]})}):g.jsx(Kv,{open:e,onOpenChange:t,children:g.jsxs(Gv,{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(N1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:y?"跳过全部审批?":"新建会话"})}),_e]})})}function jh({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(wc,{open:e,onOpenChange:r,children:g.jsx(Sc,{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(xc,{children:[g.jsx(cl,{children:"重命名会话"}),g.jsx(uc,{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:qe("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(Ku,{children:[g.jsx(bt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(bt,{type:"submit",disabled:h,children:"保存"})]})]})})})}function Zie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function Qie(e){return(e==null?void 0:e.kind)==="terminal"}function Jie(e){return Zie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Qie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function jm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Jie(t);function s(){t&&(r(t),n(!1))}return g.jsx(wc,{open:e,onOpenChange:n,children:g.jsxs(Sc,{"data-slot":"session-termination-dialog",children:[g.jsxs(xc,{children:[g.jsx(cl,{children:i.title}),g.jsx(uc,{children:i.description})]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(bt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function $B(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 ese(e){if(e.session.state==="error")return"error";const t=$B(e);return t==="disconnected"?e.session.state:t}function HB({layout:e}){const t=zt(Q=>Q.sessions),n=zt(Q=>Q.sessionListLoaded),r=zt(Q=>Q.agentStatusBySessionId),i=zt(Q=>Q.ptyStateBySessionId),s=zt(Q=>Q.renameSession),o=Xt(Q=>Q.bySessionId),l=mU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Ne(Q=>!!Q.selectedProxyId),h=Ne(Q=>Q.proxyListLoaded),p=Ne(Q=>Q.proxySwitchTarget),y=zt(Q=>Q.loadingProxyName),v=p!==null||!h||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",x=Qs(),[E,k]=b.useState(!1),[R,A]=b.useState(!1),[I,T]=b.useState(null),[$,P]=b.useState(null),{creatingTerminal:W,createTerminal:U}=UB(),[F,D]=b.useState(new Set),[M,B]=b.useState(()=>Date.now());b.useEffect(()=>{const Q=setInterval(()=>B(Date.now()),6e4);return()=>clearInterval(Q)},[]);function O(Q,J){x(`/chat/${Q}?mode=${J??"json"}`,{replace:!1})}function N(Q){const J=Q.sessionId,ne=Nt;if(!ne){Je.error("请先连接开发机");return}ne.sendControl({type:"session_terminate",sessionId:J}),zt.getState().removeSession(J),Xt.getState().clearSession(J),J===u&&x("/sessions"),(Q==null?void 0:Q.mode)==="pty"&&Q.ptyOwner==="local-terminal"?Je.info("已断开页面连接,本地终端仍在运行"):Je.info("正在终止会话",{duration:1500})}async function V(Q,J){const ne=Nt;if(!ne)throw new Error("请先连接开发机");const ee=await ne.renameSession(Q,J);if(!ee.success)throw new Error(ee.error??"重命名失败");s(Q,ee.name??J),Je.success("已重命名会话")}function q(Q){D(J=>{const ne=new Set(J);return ne.has(Q)?ne.delete(Q):ne.add(Q),ne})}function H(Q){var ee;const J=Q.mode==="json"&&(((ee=o[Q.sessionId])==null?void 0:ee.pendingApprovals.some(me=>me.status==="pending"))??!1),ne=ese({session:Q,agentStatus:r[Q.sessionId],ptyState:i[Q.sessionId],hasPendingApproval:J});return ne===Q.state?Q:{...Q,state:ne}}const L=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(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]});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(Jl,{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(tc,{variant:"no-proxy"})}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]});const Y=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",L?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=L?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:tse(t).map(Q=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>q(Q.provider),"aria-expanded":!F.has(Q.provider),className:qe("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:nse(Q.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:Q.sessions.length}),g.jsx(Xh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(Q.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(Q.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:Q.sessions.map(J=>g.jsx(wie,{session:H(J),selected:J.sessionId===u,now:M,onClick:()=>O(J.sessionId,J.mode),onRename:()=>T(J),onTerminate:()=>P(J)},J.sessionId))})]},Q.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),z=g.jsx(Tie,{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,K,z]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(bt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[g.jsx(TP,{"aria-hidden":"true"}),"新建"]})}),g.jsx(ise,{open:R,creatingTerminal:W,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>void U(()=>A(!1))}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,z]}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:$!==null,session:$,onOpenChange:Q=>{Q||P(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:Q=>{Q||T(null)},onRename:V})]})}function tse(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])=>rse(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function nse(e){return e==="terminal"?"终端":Zv(e)}function rse(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:PB(e,t)}function UB(){const e=Qs(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await Yie({relay:Nt});if(s.type!=="success"){Je.error(s.message);return}zt.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function WN({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Ne(E=>!!E.selectedProxyId),l=Ne(E=>E.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:h}=UB();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 _(E){E.preventDefault(),p()}const w=g.jsxs(bt,{variant:"outline","data-slot":"create-session-trigger",className:qe(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(TP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),x=u?g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:w}),g.jsxs(D1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:E=>{s.current&&(s.current=!1,E.preventDefault())},children:[g.jsxs(yo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[g.jsx(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(yo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[g.jsx(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return g.jsxs(g.Fragment,{children:[u?x:g.jsxs(Wf,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[g.jsx(qf,{asChild:!0,children:x}),g.jsx(Vf,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),g.jsx(Bh,{open:t,onOpenChange:n})]})}function ise({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(Kv,{open:e,onOpenChange:n,children:g.jsxs(Gv,{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(N1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.jsxs(bt,{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(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(bt,{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(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const sse="0.5.22",ose={version:sse},ase={playback:"playback",capture:"play-and-record"};function lse(){return typeof navigator>"u"?null:navigator.audioSession??null}function cse(){return{setMode:()=>{},release:()=>{}}}class use{constructor(t=lse){vt(this,"leases",new Map);vt(this,"session",null);vt(this,"baselineType",null);vt(this,"nextLeaseId",1);vt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return cse();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(ase[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 L1=new use,U0=64,qN=-60,WB=32;function VN(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 YN(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 dse(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 hse(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 qB{constructor(t,n=24e3,r={}){vt(this,"nextStartTime",0);vt(this,"activityEndToken",0);vt(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=dse(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*WB/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=hse(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,x;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(x=(w=this.options).onPlaybackChunk)==null||x.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 Q_={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},KN="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",fse=800,GN=300,pse=1600;function W0(e,t){return e.filter(n=>!n.model||n.model===t)}function XN({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 Fm({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=!!VB(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(ZN,{label:h,muted:!d&&!t}),g.jsx(pl,{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(ta,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(ZN,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function ZN({label:e,muted:t=!1}){const n=VB(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 mse({scrollRef:e}={}){const[t,n]=b.useState(Q_),[r,i]=b.useState(String(Q_.turnIdleSeconds)),[s,o]=b.useState(()=>Tm()),[l,u]=b.useState(""),[d,h]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),x=b.useRef(null),E=b.useRef(null),k=b.useRef(null),R=b.useRef(null);b.useEffect(()=>{const ne=Nt;if(!ne){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ee=!1;return _({kind:"loading"}),ne.requestVoiceConfig().then(me=>{if(!ee){if(me.error||!me.config){_({kind:"error",message:me.error??"读取语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),h(!1),y(!0),_({kind:"idle"})}}).catch(me=>{ee||_({kind:"error",message:me instanceof Error?me.message:"读取语音设置失败"})}),()=>{ee=!0}},[]),b.useEffect(()=>{const ne=Nt;if(!ne||!p)return;let ee=!1;return ne.requestVoiceCapabilities({region:t.region}).then(me=>{if(!ee){if(me.error||!me.capabilities){o(Tm());return}o(me.capabilities)}}).catch(()=>{ee||o(Tm())}),()=>{ee=!0}},[t.region,p]),b.useEffect(()=>()=>{K(),z()},[]);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]),I=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",T=b.useMemo(()=>W0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=T.some(ne=>ne.value===t.ttsVoice)?t.ttsVoice:"",W=T.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",U=b.useMemo(()=>bse(r),[r]),F=U?null:"请输入正整数秒数",D=W??F,M=I||!!D,B=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),O=b.useMemo(()=>eM(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),N=b.useMemo(()=>_se(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),V=b.useMemo(()=>eM(T,P),[T,P]);function q(){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:U??Q_.turnIdleSeconds}}async function H(){if(I)return;if(D){_({kind:"error",message:D});return}const ne=Nt;if(!ne){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ee=q();z(),_({kind:"saving"});const me=performance.now();try{const _e=await ne.updateVoiceConfig(ee),Ce=performance.now()-me;if(Ce<GN&&await yse(GN-Ce),!_e.success||_e.error||!_e.config){_({kind:"error",message:_e.error??"保存语音设置失败"});return}n(_e.config),i(String(_e.config.turnIdleSeconds)),u(""),h(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(Oe=>Oe.kind==="saved"?{kind:"idle"}:Oe)},pse),ne.requestVoiceCapabilities({region:_e.config.region}).then(Oe=>{Oe.capabilities&&o(Oe.capabilities)}).catch(()=>{o(Tm())})}catch(_e){_({kind:"error",message:_e instanceof Error?_e.message:"保存语音设置失败"})}}async function L(){if(I)return;if(D){_({kind:"error",message:D});return}const ne=Nt;if(!ne){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ee;try{ee=Y()}catch(me){_({kind:"error",message:JN(me)});return}_({kind:"testing"});try{const[me]=await Promise.all([ne.testVoiceConfig(q()),ee.ready]);if(!me.success||me.error){K(),_({kind:"error",message:me.error??"语音配置测试失败"});return}const _e=await Q(me,ee.context);_({kind:"playingTest",transcript:me.transcript}),k.current=setTimeout(()=>{k.current=null,K(),_({kind:"testPassed",transcript:me.transcript})},_e)}catch(me){K(),_({kind:"error",message:JN(me)})}}function Y(){K();const ne=L1.acquire("playback");x.current=ne;try{const ee=vse();return w.current=ee,{context:ee,ready:QN(ee)}}catch(ee){throw ne.release(),x.current=null,ee}}function K(){var ne,ee,me;k.current&&(clearTimeout(k.current),k.current=null),(ne=E.current)==null||ne.stop(),E.current=null,(ee=w.current)==null||ee.close(),w.current=null,(me=x.current)==null||me.release(),x.current=null}function z(){R.current&&(clearTimeout(R.current),R.current=null)}async function Q(ne,ee){if(!ne.audioBase64)throw new Error("语音测试未返回可播放音频");if(ne.audioEncoding&&ne.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const me=ne.audioSampleRate??24e3,_e=gse(ne.audioBase64);if(_e.byteLength===0||_e.byteLength%2!==0)throw new Error("测试音频数据无效");await QN(ee);const Ce=new qB(ee,me);E.current=Ce,Ce.enqueue(_e);const Oe=Math.ceil(_e.byteLength/2/me*1e3);return Math.max(fse,Oe)}function J(ne){var ee;return((ee=W0(s.ttsVoices,ne)[0])==null?void 0:ee.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:ne=>{ne.preventDefault(),H()},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(XN,{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(NP,{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:ne=>{u(ne.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${KN} w-full pl-9`})]}),t.configured&&g.jsxs(bt,{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(f7,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(Fm,{label:"地域",value:t.region,options:B,onChange:ne=>n(ee=>({...ee,region:ne==="intl"?"intl":"cn"}))}),g.jsx(Fm,{label:"语音识别模型",value:t.asrModel,options:O,onChange:ne=>n(ee=>({...ee,asrModel:ne}))}),g.jsx(Fm,{label:"语音合成模型",value:t.ttsModel,options:N,onChange:ne=>n(ee=>({...ee,ttsModel:ne,ttsVoice:J(ne)}))}),g.jsx(Fm,{label:"语音音色",value:P,options:V,placeholder:T.length===0?"暂无可用音色":"请选择音色",onChange:ne=>n(ee=>({...ee,ttsVoice:ne})),help:W}),g.jsx(XN,{label:"结束停顿时间(秒)",help:F,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:ne=>i(ne.target.value),className:`${KN} 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(bt,{type:"button",variant:"outline",disabled:M,onClick:()=>void L(),children:[g.jsx(DP,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(bt,{type:"submit",disabled:M,children:[g.jsx(e7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function gse(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 vse(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function QN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function JN(e){return e instanceof Error?e.message:"语音配置测试失败"}function yse(e){return new Promise(t=>setTimeout(t,e))}function bse(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function eM(e,t){const n=e.map(r=>({value:r.value,label:YB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function _se(e,t,n){const r=e.map(i=>{const s=W0(t,i.value).length===0;return{value:i.value,label:`${YB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function VB(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 YB(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 wse=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Sse=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],I1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function KB(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 xse(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Ese(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Cse(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function q0({open:e,onOpenChange:t}){const n=Ne(W=>W.relayUrl),r=Ne(W=>W.latencyMonitorEnabled),i=Ne(W=>W.setLatencyMonitorEnabled),s=Ne(W=>W.sessionIdleNotificationsEnabled),o=Ne(W=>W.setSessionIdleNotificationsEnabled),l=Ne(W=>W.inputModePreference),u=Ne(W=>W.setInputModePreference),d=Ne(W=>W.themePreference),h=Ne(W=>W.setThemePreference),p=Ne(W=>W.ptyScrollTraceEnabled),y=Ne(W=>W.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,x]=b.useState({kind:"idle"}),E=b.useRef(null),k=b.useRef(null),R=bQ(),A=b.useMemo(()=>Cv().osName==="iPad",[]),I=b.useCallback(async W=>{if(!W){o(!1);return}const U=await KZ();if(U==="granted"){o(!0);return}if(U==="denied"){Je.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){Je.info("未授予通知权限,会话通知保持关闭");return}Je.error("当前浏览器不支持系统通知")},[o]),T=b.useCallback(async W=>{x({kind:"loading"});try{const U=await fetch(xse(n),{cache:"no-store",signal:W});if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=await U.json();if(F.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:F.version??"未知",uptime:F.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;x({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const W=new AbortController;return T(W.signal),()=>W.abort()},[T,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const W=window.requestAnimationFrame(()=>{var U;(U=E.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(W)},[e,v]);const $=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${KB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(wc,{open:e,onOpenChange:t,children:g.jsxs(Sc,{className:qe("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:E,showCloseButton:v==="menu",children:[g.jsx(xc,{className:qe(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(bt,{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(bv,{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(cl,{children:Ese(v)}),g.jsx(uc,{className:"max-w-[28rem] leading-5",children:Cse(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(cl,{children:"设置"}),g.jsx(uc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(kse,{relayVersion:$,relayDetail:P,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(Rse,{saved:R}):v==="clients"?g.jsx(Dse,{}):v==="voice"?g.jsx(mse,{scrollRef:k}):g.jsx(Tse,{relayTokenSaved:R,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:I,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function kse({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:I1,"data-slot":"settings-dialog-body",children:[g.jsx(nM,{icon:g.jsx(OP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:ose.version,detail:"当前浏览器加载的版本"}),g.jsx(nM,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Tse({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(uu,{title:"服务",children:[g.jsx($m,{icon:g.jsx(U9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx($m,{icon:g.jsx(NP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx($m,{icon:g.jsx(_7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),g.jsx(uu,{title:"外观",children:g.jsx(tM,{icon:g.jsx(u7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:wse,onValueChange:n})}),g.jsx(uu,{title:"通知",children:g.jsx(ew,{icon:g.jsx(q9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(uu,{title:"交互",children:g.jsx(tM,{icon:g.jsx(MP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Sse,onValueChange:i})}):null,g.jsxs(uu,{title:"高级诊断",children:[g.jsx(ew,{icon:g.jsx(lf,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(ew,{icon:g.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(uu,{title:"关于",children:g.jsx($m,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function uu({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 tM({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:qe("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 Rse({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{JL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}if(!ZL(h)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),Je.error(p);return}o(null),Je.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{QL(),l()};return g.jsxs("form",{className:I1,"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(bt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(bt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Ase(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Nse(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Ase(e)}function Mse(e){return CX(e)}function Ose(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return KB(t)}function J_({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 Dse(){const e=Ne(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=Nt;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=Nt;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:I1,"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(bt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Nx,{className:qe("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:Mse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(J_,{label:"已连接",value:Ose(y.connectedAt)}),y.proxyId?g.jsx(J_,{label:"连接到",value:Nse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(J_,{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(bt,{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(N8,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function ew({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:qe("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:qe("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:qe("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 $m({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(Xh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function nM({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:qe("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 Pse="xterm-helper-textarea";function Lse(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Pse)?!1:(e.blur(),!0)}function rM(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&&Ise(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Ise(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 zse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Lse()},[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,rM(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(rM(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Bse({className:e}){const t=Ne(o=>o.sidebarCollapsed),n=Ne(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=zse();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:qe("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(sM,{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(iM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(WN,{compact:!0})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:qe("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(JP,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(sM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx(DB,{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(HB,{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(WN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(iM,{onClick:()=>i(!0)})})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]})}function iM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:qe("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(LP,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(Vf,{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 sM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?F8:B8;return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:qe("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:qe("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(Vf,{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 jse=1500,Fse=300,oM=70,aM=35;function GB({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,oM)):(o.current="paused",h=setTimeout(y,jse))}else v==="paused"?(o.current="deleting",h=setTimeout(y,aM)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),h=setTimeout(y,aM)):(u.current+=1,o.current="waiting",h=setTimeout(y,Fse)):(o.current="typing",h=setTimeout(y,oM))};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 XB=["DEV Anywhere","/unlimited @anytime"];function $se({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(GB,{texts:XB,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 Hse=3e3,Use=1e4,Hm=12,Wse=4,lM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},qse={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function tw(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 du(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Fh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function cM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function ZB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Vse(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 Yse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Fh(e.rttMs):"等待检测"}function Kse(){const e=xi("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 uM(e){dr("local",cn.latencyMonitorPosition,JSON.stringify(e))}function Gse(){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 nw(e,t){const n=Gse(),r=Hm,i=Hm,s=Math.max(r,n.width-t.width-Hm),o=Math.max(i,n.height-t.height-Hm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Xse(){const e=Ne(T=>T.latencyMonitorEnabled),t=Ne(T=>T.connected),n=Ne(T=>T.proxyOnline),r=Ne(T=>T.selectedProxyId),[i,s]=b.useState(qse),[o,l]=b.useState(()=>Kse()),u=b.useRef(!1),d=b.useRef(null),h=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,$)=>cM($.state)-cM(T.state))[0]??{state:"idle"}).state,[i]),v=ZB(y);async function _(){if(u.current)return;const T=Nt;if(!T||!t){const U=du("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:du("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:du("未连接开发机")}));const[$,P,W]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:$.status==="fulfilled"?tw($.value):du($.reason instanceof Error?$.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?tw(P.value):du(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:W.status==="fulfilled"?tw(W.value):du(W.reason instanceof Error?W.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,$=null;const P=async()=>{await _(),!T&&($=setTimeout(P,document.hidden?Use:Hse))};return P(),()=>{T=!0,u.current=!1,$&&clearTimeout($)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const $=T.getBoundingClientRect(),P=nw(o,{width:$.width,height:$.height});P.x===o.x&&P.y===o.y||(l(P),uM(P))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,x=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function E(T){var P,W;if(T.button!==0)return;const $=T.currentTarget.getBoundingClientRect();h.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:$.left,originY:$.top,width:$.width,height:$.height,dragging:!1},(W=(P=T.currentTarget).setPointerCapture)==null||W.call(P,T.pointerId)}function k(T){const $=h.current;if(!$||$.pointerId!==T.pointerId)return;const P=T.clientX-$.startX,W=T.clientY-$.startY;if(!$.dragging&&Math.hypot(P,W)<Wse)return;$.dragging=!0,T.preventDefault();const U=nw({x:$.originX+P,y:$.originY+W},{width:$.width,height:$.height});l(U)}function R(T){var F,D;const $=h.current;if(!$||$.pointerId!==T.pointerId||(h.current=null,(D=(F=T.currentTarget).releasePointerCapture)==null||D.call(F,T.pointerId),!$.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=T.clientX-$.startX,W=T.clientY-$.startY,U=nw({x:$.originX+P,y:$.originY+W},{width:$.width,height:$.height});l(U),uM(U)}function A(T){var P,W;const $=h.current;!$||$.pointerId!==T.pointerId||(h.current=null,(W=(P=T.currentTarget).releasePointerCapture)==null||W.call(P,T.pointerId))}function I(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return g.jsxs(T1,{children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:qe("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",Vse(v)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Fh(i.webRelay.rttMs)},开发机 ${Fh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:I,children:[g.jsx(EP,{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 ",Fh(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Fh(w.rttMs)]}),g.jsx(pl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(A1,{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(bt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:g.jsx(Nx,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(lM).map(T=>g.jsx(Zse,{label:lM[T],measurement:i[T]},T))})]})]})}function Zse({label:e,measurement:t}){const n=ZB(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:qe("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:Yse(t)})]})]})}const QB="/__dev_anywhere_debug/browser-state-dumps",Qse=1500,Jse=10,rw=80,z1=500,eoe=["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"],toe=["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 dM(){if(typeof window>"u")return"off";const e=o3("debugDump");return e==="auto"?"auto":e!==null||uoe("debugInput")?"manual":"off"}function noe(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:ooe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:hM(document.activeElement),selection:aoe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>hM(i)).filter(i=>!!i),root:JB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:hu(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:hu(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:hu(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:hu(()=>fM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:hu(()=>fM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:hu(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function roe(e="manual"){const t=noe(e);return ioe(t)}async function ioe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await soe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:QB}}catch(r){const i=a3(r),s=loe(e.createdAt);return coe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function soe(e){const t=await fetch(QB,{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 JB(e,t,n){if(n.count>=Qse||t>Jse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=pM(e.textContent??"");return u?{kind:"text",text:Qv(u,z1)}:{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,rw))u.nodeType===Node.TEXT_NODE&&!pM(u.textContent??"")||r.push(JB(u,t+1,n));s.length>rw&&(i=s.length-rw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:s3(e),attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e)},l=i3(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function hM(e){if(!(e instanceof HTMLElement))return null;const t=i3(e);return{path:s3(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e),...t?{value:t}:{}}}function ooe(){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 e3(e){const t={};for(const n of eoe){const r=e.getAttribute(n);r!==null&&(t[n]=Qv(r,500))}return t}function t3(e){const t=e.getBoundingClientRect();return{x:Yi(t.x),y:Yi(t.y),width:Yi(t.width),height:Yi(t.height),top:Yi(t.top),right:Yi(t.right),bottom:Yi(t.bottom),left:Yi(t.left)}}function n3(e){return{top:Yi(e.scrollTop),left:Yi(e.scrollLeft),height:Yi(e.scrollHeight),width:Yi(e.scrollWidth),clientHeight:Yi(e.clientHeight),clientWidth:Yi(e.clientWidth)}}function r3(e){const t=window.getComputedStyle(e),n={};for(const r of toe)n[r]=t.getPropertyValue(r);return n}function i3(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Qv(e.value,z1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function aoe(){var e;try{return Qv(((e=window.getSelection())==null?void 0:e.toString())??"",z1)}catch{return null}}function s3(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 loe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function coe(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 uoe(e){return o3(e)!==null}function o3(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 fM(e){return e?Zg(e.slice(-200)):null}function hu(e){try{return Zg(e())}catch(t){return{error:a3(t)}}}function Zg(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(Zg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Zg(r);return t}return String(e)}function pM(e){return e.replace(/\s+/g," ").trim()}function Qv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Yi(e){return Math.round(e*100)/100}function a3(e){return e instanceof Error?e.message:String(e)}const doe=500,hoe=1e3,foe=60;function poe(){const[e,t]=b.useState(()=>dM()),[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(dM());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 roe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&moe(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>=foe||(_(),h.current=window.setTimeout(()=>{h.current=null;const I=Date.now(),T=hoe-(I-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}`)},doe))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=A=>w(A.type);return x.forEach(A=>window.addEventListener(A,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(R=window.visualViewport)==null||R.addEventListener("scroll",E),()=>{var A,I;_(),x.forEach(T=>window.removeEventListener(T,E,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",E),(I=window.visualViewport)==null||I.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=goe(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(bt,{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(Jl,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(y8,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function moe(e){if(e.status==="saved"){Je.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){Je.info(`诊断已下载: ${e.filename}`);return}Je.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function goe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function voe(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 B1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:voe(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 Va(e){return e.length===0?"":`${Tn(Math.min(...e))}..${Tn(Math.max(...e))}`}function Nu(e){return[...new Set(e.filter(t=>t!==void 0).map(Tn))]}function l3(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 yoe="dev_anywhere_pty_input_latency_trace",mM=80,boe=1e4,_oe=new TextDecoder;let woe=0;const Gu=new Map,Ec=B1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:yoe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Soe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=koe)}function xoe(e,t){if(!Ec.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++woe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Aoe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Gu.get(e)??[];return s.push(i),F1(s,r),Gu.set(e,s),Yf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function gM(e,t){if(!e||!Ec.isEnabled())return;const n=performance.now(),r=Toe(e.sessionId,e.inputId);r&&(r.sentAt=n),Yf({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 Eoe(e,t,n){if(!Ec.isEnabled())return;const r=performance.now(),i=j1(e,r),s=Ooe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Moe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Yf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:Doe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Coe(e,t,n=1){if(!Ec.isEnabled())return;const r=performance.now(),i=j1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Yf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Roe(e,s))}function koe(){const e=Ec.getAll(),t=e.slice(-200),n=[...Gu.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(`
|
|
511
511
|
`)}function Yf(e){Ec.append(e)}function j1(e,t){const n=Gu.get(e)??[];return F1(n,t),Gu.set(e,n),n}function F1(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>boe;(i||s)&&e.splice(n,1)}e.length>mM&&e.splice(0,e.length-mM)}function Toe(e,t){return(Gu.get(e)??[]).find(n=>n.inputId===t)??null}function Roe(e,t){if(!Ec.isEnabled())return;const n=performance.now(),r=j1(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)}Yf({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:$1(r,n),details:i>0?`paint=${i}`:""}),F1(r,n)}function $1(e,t){const n=e[0];return n?t-n.startedAt:null}function Aoe(e){return e==="\r"||e===`
|
|
512
512
|
`?"enter":e.startsWith("\x1B")?"escape":Noe(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function Noe(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 Moe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function Ooe(e){try{return _oe.decode(e)}catch{return""}}function Doe(e){return e.filter(Boolean).join(" ")}function Ys(e,t){if(!e||!t)return;const n=xoe(e,t),r=ec;if(!r){gM(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});gM(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const vM=-1;function Poe({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=vM,i(e,"\r");return}if(s.current===vM){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function Loe(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=Ix(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 Ioe({target:e,sendRawInput:t}){return Poe({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function zoe({sendRawInput:e=Ys}){const t=Ne(d=>d.connected),n=Ne(d=>d.proxyOnline),r=Ne(d=>d.selectedProxyId),i=zt(d=>d.sessions),s=zt(d=>d.ptyStateBySessionId),o=zt(d=>d.agentStatusBySessionId),l=zt(d=>d.ptyAutoYesBySessionKey),u=i.map(d=>Loe({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(Ioe,{target:d,sendRawInput:e},d.key))})}function Boe(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 Zl=function(e,t){return Number(e.toFixed(t))},joe=function(e,t){return t},Dn=function(e,t,n){n&&typeof n=="function"&&n(e,t)},Foe=function(e){return-Math.cos(e*Math.PI)/2+.5},$oe=function(e){return e},Hoe=function(e){return e*e},Uoe=function(e){return e*(2-e)},Woe=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},qoe=function(e){return e*e*e},Voe=function(e){return--e*e*e+1},Yoe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},Koe=function(e){return e*e*e*e},Goe=function(e){return 1- --e*e*e*e},Xoe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},Zoe=function(e){return e*e*e*e*e},Qoe=function(e){return 1+--e*e*e*e*e},Joe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},c3={easeOut:Foe,linear:$oe,easeInQuad:Hoe,easeOutQuad:Uoe,easeInOutQuad:Woe,easeInCubic:qoe,easeOutCubic:Voe,easeInOutCubic:Yoe,easeInQuart:Koe,easeOutQuart:Goe,easeInOutQuart:Xoe,easeInQuint:Zoe,easeOutQuint:Qoe,easeInOutQuint:Joe},u3=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Vs=function(e){e.mounted&&(u3(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function d3(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Vs(e),e.animation=function(){if(!e.mounted)return u3(e.animation);var o=new Date().getTime()-i,l=o/n,u=c3[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function eae(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function Sl(e,t,n,r){var i=eae(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):d3(e,r,n,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+h*v,w=u+p*v,x=d+y*v;s(_,w,x)})}}function tae(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 nae=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}},H1=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=tae(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,h=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,v=l.newDiffHeight,_=nae(u,h,y,d,p,v,!!s),w=u>=h&&d>=p;o&&w&&!s&&(_.minPositionX=0,_.maxPositionX=0,_.minPositionY=0,_.maxPositionY=0);var x=e.setup,E=x.minPositionX,k=x.maxPositionX,R=x.minPositionY,A=x.maxPositionY;return E!=null&&(_.minPositionX=u*(1-t)+E*t),k!=null&&(_.maxPositionX=k*t),R!=null&&(_.minPositionY=d*(1-t)+R*t),A!=null&&(_.maxPositionY=A*t),_},yf=function(e,t,n,r){return r?e<t?Zl(t,2):e>n?Zl(n,2):Zl(e,2):Zl(e,2)},Xu=function(e,t){var n=H1(e,t);return e.bounds=n,n};function Kf(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=yf(e,l-p,d+p,r),_=yf(t,u-y,h+y,r);return{x:v,y:_}}function Jv(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=Kf(p,y,i,s,0,0,null);return v}var yM=1e-7;function Gf(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,yM),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,yM)}var bM=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=Xf(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},_M=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},rae=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}},iae=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 sae(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,x=r>v||r<_,E=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>v?d.offsetHeight:e.setup.minPositionY||0,R=Jv(e,E,k,i,e.bounds,l||u),A=R.x,I=R.y;return{scale:i,positionX:w?A:n,positionY:x?I:r}}}function h3(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=Kf(t,n,l,s,r,i,o),v=y.x,_=y.y;e.setState(d,v,_)}}var oae=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}},dl=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},el;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(el||(el={}));var aae=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},lae=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 cae(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 wM(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:yf(e,s,o,i)}function uae(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var iw=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 dae(e,t,n){var r,i,s=aae(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 x=uae(d),E=(r={},r[el.TOUCH]=v,r[el.MOUSE]=_,r)[n],k=(i={},i[el.TOUCH]=y,i[el.MOUSE]=p,i)[n],R=t.x-o.x,A=t.y-o.y,I=iw(R/x,k,E),T=iw(A/x,k,E),$=w-l,P=R*R+A*A,W=iw(Math.sqrt(P)/$,k,E);e.velocity={velocityX:I,velocityY:T,total:W}}e.lastMousePosition=t,e.velocityTime=w}}function hae(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=lae(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,x=r.panning,E=x.lockAxisY,k=x.lockAxisX,R=w.animationType,A=_.sizeX,I=_.sizeY,T=_.velocityAlignmentTime,$=T,P=cae(e,u),W=Math.max(P,$),U=dl(e,A),F=dl(e,I),D=U*i.offsetWidth/100,M=F*i.offsetHeight/100,B=d+D,O=h-D,N=p+M,V=y-M,q=e.state,H=new Date().getTime();d3(e,R,W,function(L){var Y=e.state,K=Y.scale,z=Y.positionX,Q=Y.positionY,J=new Date().getTime()-H,ne=J/$,ee=c3[_.animationType],me=1-ee(Math.min(1,ne)),_e=1-L,Ce=z+o*_e,Oe=Q+l*_e,Me=wM(Ce,q.positionX,z,k,v,h,d,O,B,me),Ge=wM(Oe,q.positionY,Q,E,v,y,p,V,N,me);if(z!==Ce||Q!==Oe){e.setState(K,Me,Ge);var ct=e.props.onPanning;ct&&ct(Rn(e),{})}})}}function SM(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},Vs(e),Xu(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?iae(e,t):rae(e,t)}function f3(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=sae(e);y&&Sl(e,y,d,h)}}function xM(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=oae(e,t,n),h=d.x,p=d.y,y=dl(e,l),v=dl(e,u);dae(e,{x:h,y:p},r),h3(e,h,p,y,v)}}function fae(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,x=!e.setup.limitToBounds||y<_||v<w,E=!t&&n&&n.total>.1&&x;E?hae(e):f3(e)}}function U1(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Gf(Zl(t,2),s,o,0,!1),d=Xu(e,u),h=Jv(e,n,r,u,d,l),p=h.x,y=h.y;return{scale:u,positionX:p,positionY:y}}function W1(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)&&f3(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,x=n||i.offsetHeight/2,E=r<o?o:l,k=U1(e,E,w,x);k&&Sl(e,k,p,y)}}var Ts=function(){return Ts=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},Ts.apply(this,arguments)};function EM(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 sw={scale:1,positionX:0,positionY:0},Gl={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"}},V0={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},p3=function(e){var t,n,r,i,s,o,l,u,d,h=Math.max((t=e.minScale)!==null&&t!==void 0?t:Gl.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:Gl.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:sw.scale,v=Math.min(Math.max(y,h),p),_=yf((i=e.initialPositionX)!==null&&i!==void 0?i:sw.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=yf((l=e.initialPositionY)!==null&&l!==void 0?l:sw.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}},CM=function(e){var t=Ts({},Gl);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Gl[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Gl[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=Ts(Ts({},Gl[r]),e[r]):u?t[r]=EM(EM([],Gl[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},m3=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=Gf(Zl(p,3),l,o,h,!1);return y};function g3(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,x=(_/2-h)/d,E=(w/2-p)/d,k=m3(e,t,n),R=U1(e,k,x,E);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,I=A.onZoomStart,T=A.onZoom,$=A.onZoomStop,P=new MouseEvent("mousemove",{bubbles:!0}),W=Rn(e);Dn(W,P,I),Dn(W,P,T),Sl(e,R,v,i);var U=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;U&&U.setTimeout(function(){e.mounted&&Dn(Rn(e),P,$)},v)}function v3(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,h=o.centerOnInit,p=p3(e.props),y=e.state,v=y.scale,_=y.positionX,w=y.positionY;if(l){var x=p.positionX,E=p.positionY;if(h&&u){var k=q1(p.scale,l,u);x=k.positionX,E=k.positionY}var R=H1(e,p.scale),A=Kf(x,E,R,d,0,0,l),I={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,$=T.onZoomStart,P=T.onZoom,W=T.onZoomStop,U=new MouseEvent("mousemove",{bubbles:!0}),F=Rn(e);Dn(F,U,$),Dn(F,U,P),Sl(e,I,t,n);var D=(s=(i=l.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&s!==void 0?s:typeof window<"u"?window:null;D&&D.setTimeout(function(){e.mounted&&Dn(Rn(e),U,W)},t)}}}function pae(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 mae(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(),_=pae(t,s,o,l),w=_.x,x=_.y,E=v.width/l.scale,k=v.height/l.scale,R=s.offsetWidth/E,A=s.offsetHeight/k,I=Gf(n||Math.min(R,A),h,p,0,!1),T=(y.width-E*I)/2,$=(y.height-k*I)/2,P=(y.left-w)*I+T+r,W=(y.top-x)*I+$+i,U=H1(e,I),F=Kf(P,W,U,d,0,0,s),D=F.x,M=F.y;return{positionX:D,positionY:M,scale:I}}var gae=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),g3(e,1,t,n,r)}},vae=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),g3(e,-1,t,n,r)}},yae=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};Sl(e,v,i,s)}}},bae=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),v3(e,t,n)}},_ae=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=q1(t||i.scale,s,o);Sl(e,l,n,r)}}},wae=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=mae(e,u,n,s,o);Sl(e,d,r,i)}}},Y0=function(e){return{instance:e,state:e.state,zoomIn:gae(e),zoomOut:vae(e),setTransform:yae(e),resetTransform:bae(e),centerView:_ae(e),zoomToElement:wae(e)}},Sae=function(e){return{instance:e,state:e.state}},Rn=function(e){var t={};return Object.assign(t,Sae(e)),Object.assign(t,Y0(e)),t},ow=!1;function aw(){try{var e={get passive(){return ow=!0,!1}};return e}catch{return ow=!1,ow}}var Um=".".concat(V0.wrapperClass),Xf=function(e,t){return t.some(function(n){return e.matches("".concat(Um," ").concat(n,", ").concat(Um," .").concat(n,", ").concat(Um," ").concat(n," *, ").concat(Um," .").concat(n," *"))})},bf=function(e){e&&clearTimeout(e)},xae=function(e){return Number.parseFloat(e.toFixed(8))},y3=function(e,t,n){var r=xae(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},q1=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 Eae(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Cae(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var b3=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=Xf(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},kae=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=b3(e,t);if(l)return!1;var u=t.target,d=Xf(u,o);if(d)return!1;var h=e.isPressingKeys(s);return!!h},Tae=function(e){return e?e.deltaY<0?1:-1:0};function Rae(e,t){var n=Tae(e),r=joe(t,n);return r}function _3(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 Aae=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,x=Gf(_,d,u,y,w&&!p);return x},w3=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},Nae=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=Xf(o,i);return!u},Mae=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},Oae=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}},S3=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))},Dae=5,Pae=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/Dae),x=n+w,E=x===1/0?0:Zl(x,10);return Gf(E,o,s,h,!p&&!u)},x3=160,E3=100,Lae=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))},Iae=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,x=p.disabled,E=y.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var k=Rae(t,null),R=_?E*Math.abs(t.deltaY):E,A=Aae(e,k,R,!t.ctrlKey);if(u!==A){var I=Xu(e,A),T=_3(t,s,u),$=x||w===0||h||v,P=d&&$,W=Jv(e,T.x,T.y,A,I,P),U=W.x,F=W.y;e.previousWheelEvent=t,e.setState(A,U,F),Dn(Rn(e),t,r),Dn(Rn(e),t,i)}},zae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;bf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(W1(e,t.x,t.y),e.wheelAnimationTimer=null)},E3);var s=w3(e,t);s&&(bf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Dn(Rn(e),t,r),Dn(Rn(e),t,i))},x3))},Bae=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))},jae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;bf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(W1(e,t.x,t.y),e.wheelAnimationTimer=null)},E3);var s=w3(e,t);s&&(bf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Dn(Rn(e),t,r),Dn(Rn(e),t,i))},x3))},C3=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}},Fae=function(e,t){var n=S3(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=C3(t),Vs(e)},$ae=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,x=y.allowPanning;if(!(r===null||!n)){var E=Oae(t,o,n);if(!(!Number.isFinite(E.x)||!Number.isFinite(E.y))){var k=S3(t),R=Pae(e,k),A=C3(t),I=o/R,T=(A.x-((s==null?void 0:s.x)||0))*I,$=(A.y-((s==null?void 0:s.y)||0))*I;if(!(R===o&&T===0&&$===0)){e.pinchPreviousCenter=A;var P=Xu(e,R),W=_||w===0||d,U=u&&W,F=Jv(e,E.x,E.y,R,P,U),D=F.x,M=F.y;if(e.pinchMidpoint=E,e.lastDistance=k,v.disabled||!x)e.setState(R,D,M);else{var B=p.sizeX,O=p.sizeY,N=dl(e,B,R),V=dl(e,O,R),q=D+T,H=M+$,L=Kf(q,H,P,u,N,V,i),Y=L.x,K=L.y;e.setState(R,Y,K)}}}}},Hae=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,W1(e,t==null?void 0:t.x,t==null?void 0:t.y)},k3=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;bf(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,Dn(Rn(e),t,n)},r)},Uae=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),v3(e,o,l,function(){return Dn(Rn(e),t,i)}),k3(e,t)};function Wae(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function qae(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 Uae(e,t);if(!s)return console.error("No ContentComponent found");var x=Wae(y,e.state.scale),E=m3(e,x,v);if(o!==E){Dn(Rn(e),t,u);var k=_3(t,s,o),R=U1(e,E,k.x,k.y);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");Dn(Rn(e),t,d),Sl(e,R,_,w),k3(e,t)}}}var Vae=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=Xf(u,l);return!p},Yae=(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&&Xu(n,n.state.scale),n.setup=CM(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=aw(),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=aw(),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=aw();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=b3(n,r);s&&(Lae(n,r),Iae(n,r),zae(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=kae(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,x=n.setup.autoAlignment,E=x.sizeX,k=x.sizeY,R=dl(n,E),A=dl(n,k);_===h&&w===p||(Bae(n,r),h3(n,_,w,R,A),Dn(Rn(n),r,i),jae(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=bM(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),SM(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=_M(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),xM(n,r.clientX,r.clientY,el.MOUSE),Dn(Rn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(fae(n,i),Dn(Rn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=Nae(n,r);o&&(Fae(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=Mae(n);o&&(r.preventDefault(),r.stopPropagation(),$ae(n,r),Dn(Rn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(Hae(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=bM(n,r);if(p){if(!v)return;Vs(n),SM(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=_M(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];xM(n,l.clientX,l.clientY,el.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=Vae(n,r);s&&qae(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=q1(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):y3(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,Xu(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),Eae(n.props.ref,s)},this.props=t,this.setup=CM(this.props),this.state=p3(this.props)}return e})(),ey=Ze.createContext(null),Kae=function(e,t){return typeof e=="function"?e(t):e},Gae=Ze.forwardRef(function(e,t){var n=b.useRef(new Yae(e)).current,r=Kae(e.children,Y0(n));return b.useImperativeHandle(t,function(){return Y0(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),g.jsx(ey.Provider,Ts({value:n},{children:r}))});Ze.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(ey);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",Ts({},e,{ref:Cae([n,t])}))});function Xae(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 Zae=`.transform-component-module_wrapper__SPB86 {
|
|
513
513
|
position: relative;
|
|
@@ -644,7 +644,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
|
|
|
644
644
|
`))return null;const n=Sge(t);return!n||/\s/.test(n)||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||fE(n)||n.split("/").includes("...")?null:n}function Ege(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/")||e.includes("/"))return!1;const t=e.split(".");if(t.length<2)return!1;const n=t.at(-1)??"";return wge.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function Cge(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(A4,""),n=t.split("/").pop()??t;return/[A-Za-z_-]/.test(n)}function kge(e){const t=xge(e);return!t||Ege(t)||!Cge(t)?null:_ge.test(t)?{kind:"image-preview",path:t}:A4.test(t)?{kind:"file-download",path:t}:null}const Tge=16,Rge=24,xh=6,Age=425,Yh=-1;function Jm(e,t){return e.pointerId===t||t===Yh}function mu(e){return Math.hypot(e.lastX-e.startX,e.lastY-e.startY)}function Ti(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 Nge({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(mu(F)>xh){h(F),Ti("longpress:cancel-drift",{distance:mu(F),threshold:xh});return}if(s!=null&&s({clientX:F.startX,clientY:F.startY})){F.longPressArmed=!0,h(F),Ti("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 D={clientX:F.lastX,clientY:F.lastY};window.setTimeout(()=>u==null?void 0:u(D),0)},[u]),_=b.useCallback((F,D,M,B=!1)=>{const O={pointerId:F,startX:D,startY:M,lastX:D,lastY:M,moved:!1,longPressArmed:!1,longPressed:!1,longPressDelivered:!1,touchEventStream:B,longPressTimer:null};O.longPressTimer=window.setTimeout(()=>{d.current===O&&y(O)},Age),d.current=O,Ti("start",{pointerId:F,clientX:D,clientY:M,touchEventStream:B}),r==null||r({clientX:D,clientY:M})},[y,r]),w=b.useCallback((F,D,M)=>{const B=d.current;if(!B||!Jm(B,F))return!1;B.lastX=D,B.lastY=M;const O=mu(B);if(B.longPressArmed&&O>xh&&(B.longPressArmed=!1,Ti("longpress:cancel-armed-drift",{pointerId:F,clientX:D,clientY:M,distance:O,threshold:xh})),B.longPressed)return Ti("move",{pointerId:F,clientX:D,clientY:M,distance:O,moved:B.moved,longPressed:!0}),l==null||l({clientX:D,clientY:M}),!0;const N=D-B.startX,V=M-B.startY;return!B.moved&&O>=Tge&&(B.moved=!0,h(B)),Ti("move",{pointerId:F,clientX:D,clientY:M,dx:N,dy:V,distance:O,moved:B.moved,longPressed:!1}),B.moved},[h,l]),x=b.useCallback((F,D)=>{var N;const M=d.current;if(!M||!Jm(M,F))return null;D&&(M.lastX=D.clientX,M.lastY=D.clientY),d.current=null,h(M);const B=mu(M);let O;if(M.longPressArmed){if(B<=xh)return p(M),v(M),O="longpress",Ti("finish",{pointerId:F,result:O,point:D,moved:M.moved,distance:B,longPressed:!0,longPressArmed:!0}),O;M.longPressArmed=!1}return M.longPressed?(v(M),O="longpress",Ti("finish",{pointerId:F,result:O,point:D,moved:M.moved,longPressArmed:M.longPressArmed,distance:B,longPressed:!0}),O):M.moved?D&&mu(M)<=Rge&&(i!=null&&i(D))?(t(),O="link",Ti("finish",{pointerId:F,result:O,point:D,moved:!0,distance:B,longPressed:!1}),O):(t(),O="scroll",Ti("finish",{pointerId:F,result:O,point:D,moved:!0,distance:B,longPressed:!1}),O):D&&(i!=null&&i(D))?(t(),O="link",Ti("finish",{pointerId:F,result:O,point:D,moved:!1,distance:B,longPressed:!1}),O):(n?n():(N=e.current)==null||N.focus(),O="tap",Ti("finish",{pointerId:F,result:O,point:D,moved:!1,distance:B,longPressed:!1}),O)},[h,v,n,i,p,t,e]),E=b.useCallback(F=>{const D=d.current;return!D||!Jm(D,F)?null:(h(D),d.current=null,D.longPressed?(v(D),Ti("cancel",{pointerId:F,result:"longpress"}),"longpress"):(D.longPressArmed&&Ti("cancel",{pointerId:F,result:"armed"}),t(),Ti("cancel",{pointerId:F,result:"scroll",moved:D.moved,distance:mu(D)}),"scroll"))},[h,v,t]),k=b.useCallback(F=>{if(F.pointerType!=="touch")return;const D=F.target;!(D instanceof Element)||!D.closest(".xterm")||(_(F.pointerId,F.clientX,F.clientY),F.stopPropagation())},[_]),R=b.useCallback(F=>{if(F.pointerType!=="touch")return;const D=w(F.pointerId,F.clientX,F.clientY),M=d.current;M&&D&&(F.stopPropagation(),M.longPressed&&F.preventDefault())},[w]),A=b.useCallback(F=>{const D=x(F.pointerId,{clientX:F.clientX,clientY:F.clientY});D&&(F.stopPropagation(),D==="link"&&F.cancelable&&F.preventDefault())},[x]),I=b.useCallback(F=>{const D=d.current;if(F.pointerType==="touch"&&D&&Jm(D,F.pointerId)&&D.touchEventStream&&!D.longPressed){F.stopPropagation();return}E(F.pointerId)&&F.stopPropagation()},[E]),T=b.useCallback(F=>{const D=F.target;if(!(D instanceof Element)||!D.closest(".xterm"))return;if(d.current){d.current.touchEventStream=!0;return}const M=F.touches[0]??F.changedTouches[0];M&&_(Yh,M.clientX,M.clientY,!0)},[_]),$=b.useCallback(F=>{const D=F.touches[0]??F.changedTouches[0];if(!D)return;const M=w(Yh,D.clientX,D.clientY),B=d.current;B&&M&&B.longPressed&&(F.stopPropagation(),F.preventDefault())},[w]),P=b.useCallback(F=>{const D=F.changedTouches[0],M=d.current,B=D?{clientX:D.clientX,clientY:D.clientY}:M?{clientX:M.lastX,clientY:M.lastY}:void 0,O=x(Yh,B);(O==="longpress"||O==="link")&&(F.stopPropagation(),F.cancelable&&F.preventDefault())},[x]),W=b.useCallback(F=>{E(Yh)==="longpress"&&F.stopPropagation()},[E]),U=b.useCallback(F=>{const D=d.current;D&&(F.preventDefault(),F.stopPropagation(),y(D))},[y]);return{onPointerDownCapture:k,onPointerMoveCapture:R,onPointerUpCapture:A,onPointerCancelCapture:I,onTouchStartCapture:T,onTouchMoveCapture:$,onTouchEndCapture:P,onTouchCancelCapture:W,onContextMenuCapture:U}}function Mge({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:x}){const E=b.useRef(null),k=b.useRef(null),R=b.useRef(null),A=b.useRef(!1),I=b.useRef(null),T=b.useCallback(()=>{var O;(O=I.current)==null||O.call(I),I.current=null,k.current=null,R.current=null,A.current=!1,E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)},[]),$=b.useCallback(()=>{var H;E.current=null;const O=k.current;if(!O||!t||!i())return;const N=t.getBoundingClientRect(),{dx:V,dy:q}=l4({pointerX:O.clientX,pointerY:O.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});V!==0&&(p==null||p(`selectionGestureAutoscroll dx=${Math.round(V)}`),t.scrollLeft+=V),q!==0&&(t.scrollTop+=q),(V!==0||q!==0)&&(y==null||y({scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}),(H=R.current)==null||H.call(R,O)),E.current=requestAnimationFrame($)},[t,i,p,y]),P=b.useCallback((O,N)=>{k.current=O,R.current=N,E.current===null&&(E.current=requestAnimationFrame($))},[$]);b.useEffect(()=>T,[T]),b.useEffect(()=>{if(!t)return;const O=N=>{A.current&&N.preventDefault()};return t.addEventListener("touchmove",O,{capture:!0,passive:!1}),document.addEventListener("touchmove",O,{capture:!0,passive:!1}),()=>{t.removeEventListener("touchmove",O,{capture:!0}),document.removeEventListener("touchmove",O,{capture:!0})}},[t]);const W=b.useCallback(O=>{T(),A.current=!0,u(O)},[u,T]),U=b.useCallback(O=>{d(O),P(O,d)},[d,P]),F=b.useCallback(O=>{T(),h(O)},[h,T]),D=Nge({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:W,onLongPressMove:U,onLongPressEnd:F}),M=b.useCallback((O,N)=>{N.preventDefault(),N.stopPropagation(),T(),A.current=!0,v(O);let V=()=>{};const q=Y=>{Y.cancelable&&Y.preventDefault();const K={clientX:Y.clientX,clientY:Y.clientY};_(O,K),P(K,z=>_(O,z))},H=Y=>{const K={clientX:Y.clientX,clientY:Y.clientY};V(),I.current=null,T(),w(O,K)},L=()=>{V(),I.current=null,T(),x(O)};V=()=>{window.removeEventListener("pointermove",q),window.removeEventListener("pointerup",H),window.removeEventListener("pointercancel",L)},I.current=V,window.addEventListener("pointermove",q,{passive:!1}),window.addEventListener("pointerup",H,{once:!0}),window.addEventListener("pointercancel",L,{once:!0})},[x,w,_,v,T,P]),B=b.useCallback((O,N)=>{if(I.current||!(N.touches[0]??N.changedTouches[0]))return;N.preventDefault(),N.stopPropagation(),A.current=!0,v(O);let q=()=>{};const H=K=>{const z=K.touches[0]??K.changedTouches[0];if(!z)return;K.cancelable&&K.preventDefault();const Q={clientX:z.clientX,clientY:z.clientY};_(O,Q),P(Q,J=>_(O,J))},L=K=>{const z=K.changedTouches[0],Q=z?{clientX:z.clientX,clientY:z.clientY}:k.current;q(),I.current=null,T(),w(O,Q)},Y=()=>{q(),I.current=null,T(),x(O)};q=()=>{window.removeEventListener("touchmove",H),window.removeEventListener("touchend",L),window.removeEventListener("touchcancel",Y)},I.current=q,window.addEventListener("touchmove",H,{passive:!1}),window.addEventListener("touchend",L,{once:!0}),window.addEventListener("touchcancel",Y,{once:!0})},[x,w,_,v,T,P]);return{pointerHandlers:D,stopPtySelectionGesture:T,handlePtySelectionHandlePointerDown:M,handlePtySelectionHandleTouchStart:B}}const Oge=8;function Dge(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),x=b.useRef(null),E=b.useRef(null),k=b.useRef(null),R=b.useRef(!1),A=b.useRef(null),I=b.useRef(null),T=b.useRef(""),$=b.useRef(null),[P,W]=b.useState(null),[U,F]=b.useState(null),[D,M]=b.useState(null),B=b.useMemo(()=>vge(u),[u]),O=b.useCallback((ye,Fe)=>{const Ye=window.visualViewport;return R4({clientX:ye,clientY:Fe,viewportWidth:(Ye==null?void 0:Ye.width)??window.innerWidth,viewportHeight:(Ye==null?void 0:Ye.height)??window.innerHeight,viewportOffsetLeft:(Ye==null?void 0:Ye.offsetLeft)??0,viewportOffsetTop:(Ye==null?void 0:Ye.offsetTop)??0})},[]),N=b.useCallback((ye,Fe)=>{const Ye=n.current,be=r.current;return!Ye||!be?null:yge({terminal:Ye,host:be,anchor:ye,focus:Fe})},[n,r]),V=b.useCallback((ye,Fe)=>{const Ye=Fe??kge(ye);return I.current=Ye,M(Ye),Ye},[]),q=b.useCallback(ye=>{const Fe=window.visualViewport;return bge({handles:ye,viewportWidth:(Fe==null?void 0:Fe.width)??window.innerWidth,viewportHeight:(Fe==null?void 0:Fe.height)??window.innerHeight,viewportOffsetLeft:(Fe==null?void 0:Fe.offsetLeft)??0,viewportOffsetTop:(Fe==null?void 0:Fe.offsetTop)??0})},[]),H=b.useCallback(()=>{const ye=w.current,Fe=x.current;if(!ye||!Fe){F(null);return}const Ye=N(ye,Fe);if(F(Ye),!Ye){W(null);return}W(be=>be&&q(Ye))},[N,q]),L=b.useCallback(()=>{var ye,Fe;(ye=$.current)==null||ye.call($),E.current=null,k.current=null,w.current=null,x.current=null,R.current=!1,A.current=null,I.current=null,T.current="",(Fe=n.current)==null||Fe.clearSelection(),W(null),F(null),M(null)},[n]),Y=b.useCallback((ye="")=>{w.current=null,x.current=null,R.current=!1,I.current=null,T.current=ye,W(null),F(null),M(null)},[]),K=b.useCallback(({clientX:ye,clientY:Fe})=>{const Ye=n.current,be=r.current;d({blur:!1}),k.current={clientX:ye,clientY:Fe},E.current=Ye&&be?Vh({terminal:Ye,host:be,clientX:ye,clientY:Fe}):null},[d,n,r]),z=b.useCallback(({clientX:ye,clientY:Fe,draggedHandle:Ye="focus"})=>{const be=n.current,Qe=r.current,Ke=w.current,dt=x.current;if(!be||!Qe||!Ke)return null;const de=Vh({terminal:be,host:Qe,clientX:ye,clientY:Fe});if(!de)return null;const Ae=Ye==="anchor"?de:Ke,tt=Ye==="focus"?de:dt??Ke;w.current=Ae,x.current=tt,R.current=!0;const et=av({terminal:be,anchor:Ae,focus:tt});return T.current=(et==null?void 0:et.text)??"",V((et==null?void 0:et.text)??""),F(et?N(Ae,tt):null),et},[N,V,n,r]),Q=b.useCallback(({point:ye,clientX:Fe,clientY:Ye,showToolbar:be=!0})=>{const Qe=n.current,Ke=r.current;if(!Qe||!Ke)return!1;A.current=null;const dt=ye?X2({terminal:Qe,point:ye}):null,de=dt??(ye?YS({terminal:Qe,point:ye}):G2({terminal:Qe,host:Ke,clientX:Fe,clientY:Ye}));if(!(de!=null&&de.text))return!1;w.current=de.anchor,x.current=de.focus,T.current=de.text,V(de.text,dt==null?void 0:dt.pathAction);const Ae=N(de.anchor,de.focus);return F(Ae),be&&W(Ae?q(Ae):O(Fe,Ye)),!0},[N,O,q,V,n,r]),J=b.useCallback(()=>{const ye=w.current,Fe=x.current;if(!ye||!Fe){W(null);return}const Ye=N(ye,Fe);F(Ye),W(Ye?q(Ye):null)},[N,q]),ne=b.useCallback(ye=>{var be,Qe;const Fe=((Qe=(be=n.current)==null?void 0:be.getSelection)==null?void 0:Qe.call(be))??"",Ye=V(Fe);T.current=Fe,w.current=null,x.current=null,R.current=!1,F(null),W(Ye?O(ye.clientX,ye.clientY):null)},[O,V,n]);b.useEffect(()=>{const ye=r.current;if(!ye)return;let Fe=!1;const Ye=Ke=>{var de,Ae;if(Ke.pointerType!=="mouse"||Ke.button!==0)return;const dt=Ke.target;!(dt instanceof Element)||!dt.closest(".xterm")||(Fe=!0,Y(((Ae=(de=n.current)==null?void 0:de.getSelection)==null?void 0:Ae.call(de))??""))},be=Ke=>{if(Ke.pointerType!=="mouse"||!Fe)return;Fe=!1;const dt={clientX:Ke.clientX,clientY:Ke.clientY};window.setTimeout(()=>ne(dt),0)},Qe=()=>{Fe=!1};return ye.addEventListener("pointerdown",Ye,!0),window.addEventListener("pointerup",be,!0),window.addEventListener("pointercancel",Qe,!0),()=>{ye.removeEventListener("pointerdown",Ye,!0),window.removeEventListener("pointerup",be,!0),window.removeEventListener("pointercancel",Qe,!0)}},[Y,ne,n,r]),b.useLayoutEffect(()=>{if(!P&&!U)return;const ye=Fe=>{const Ye=Fe.target;Ye instanceof Element&&Ye.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]')||L()};return document.addEventListener("pointerdown",ye,!0),document.addEventListener("touchstart",ye,!0),()=>{document.removeEventListener("pointerdown",ye,!0),document.removeEventListener("touchstart",ye,!0)}},[L,U,P]),b.useEffect(()=>{if(!s||!P)return;const ye=()=>{const Fe=A.current;Fe&&s.scrollLeft===Fe.scrollLeft&&s.scrollTop===Fe.scrollTop||L()};return s.addEventListener("scroll",ye,{passive:!0}),()=>s.removeEventListener("scroll",ye)},[L,s,P]);const ee=U!==null;b.useLayoutEffect(()=>{var ye;ee&&((ye=i.current)==null||ye.relayout(),H())},[ee,l,H,i]),b.useEffect(()=>{ee&&H()},[ee,H,o.scrollLeft,o.scrollTop]),b.useEffect(()=>{if(!ee)return;const ye=window.visualViewport;let Fe=0,Ye=0;const be=()=>{cancelAnimationFrame(Fe),window.clearTimeout(Ye),Fe=requestAnimationFrame(()=>{H(),Ye=window.setTimeout(()=>{Fe=requestAnimationFrame(()=>H())},160)})};return be(),window.addEventListener("resize",be),ye==null||ye.addEventListener("resize",be),ye==null||ye.addEventListener("scroll",be),()=>{cancelAnimationFrame(Fe),window.clearTimeout(Ye),window.removeEventListener("resize",be),ye==null||ye.removeEventListener("resize",be),ye==null||ye.removeEventListener("scroll",be)}},[ee,H]);const me=b.useCallback(({clientX:ye,clientY:Fe})=>{const Ye=n.current,be=r.current;if(!Ye||!be)return;const Qe=Vh({terminal:Ye,host:be,clientX:ye,clientY:Fe})??E.current;if(Ye.clearSelection(),!Qe){w.current=null,x.current=null,I.current=null,T.current="",W(null),F(null),M(null);return}w.current=Qe,x.current=Qe,R.current=!1,I.current=null,T.current="",W(null),F(null),M(null),Q({point:Qe,clientX:ye,clientY:Fe,showToolbar:!1})},[Q,n,r]),_e=b.useCallback(({clientX:ye,clientY:Fe})=>{z({clientX:ye,clientY:Fe}),W(null)},[z]),Ce=b.useCallback(({clientX:ye,clientY:Fe})=>{const Ye=n.current,be=r.current;if(!Ye||!be)return;const Qe=w.current,Ke=Vh({terminal:Ye,host:be,clientX:ye,clientY:Fe}),dt=Ke??x.current,de=E.current,Ae=k.current,tt=Ae?Math.hypot(ye-Ae.clientX,Fe-Ae.clientY)>=Oge:!1,et=de??Ke;if(!R.current&&!tt&&T.current){J(),E.current=null,k.current=null;return}const ut=!R.current&&!tt&&et?X2({terminal:Ye,point:et}):null,Ot=tt?Ke??dt:dt,Bt=(R.current||tt)&&Qe&&Ot?av({terminal:Ye,anchor:Qe,focus:Ot}):ut??G2({terminal:Ye,host:be,clientX:ye,clientY:Fe})??(de?YS({terminal:Ye,point:de}):null);if(E.current=null,k.current=null,!(Bt!=null&&Bt.text)){L();return}w.current=Bt.anchor,x.current=Bt.focus,T.current=Bt.text,V(Bt.text,ut==null?void 0:ut.pathAction);const Jt=N(Bt.anchor,Bt.focus);F(Jt),W(Jt?q(Jt):O(ye,Fe))},[L,N,O,q,V,J,n,r]),Oe=b.useCallback(()=>{var Ye;const ye=n.current,Fe=((Ye=ye==null?void 0:ye.getSelection)==null?void 0:Ye.call(ye))||T.current;Fe&&k4(Fe,{allowLegacyFallback:!0}).then(be=>{L(),be==="failed"?Je.error("复制失败"):Je.success("已复制")})},[L,n]),Me=b.useCallback(()=>{const ye=I.current;ye&&(ye.kind==="image-preview"?_(ye.path):v(ye.path),L())},[L,v,_]),Ge=b.useCallback(()=>w.current!==null,[]),ct=b.useCallback(()=>{W(null)},[]),At=b.useCallback((ye,{clientX:Fe,clientY:Ye})=>{z({clientX:Fe,clientY:Ye,draggedHandle:ye}),W(null)},[z]),ve=b.useCallback((ye,Fe)=>{Fe&&z({...Fe,draggedHandle:ye}),T.current&&J()},[z,J]),Ve=b.useCallback(()=>{W(null)},[]);b.useEffect(()=>{},[L,N,q,t,V,n]);const Rt=Mge({terminalRef:n,containerEl:s,suppressPtyFocus:d,focusPtyInput:h,isSelectionActive:Ge,onTap:p,isTapCandidate:y,onLongPressCandidateStart:K,onLongPressStart:me,onLongPressMove:_e,onLongPressEnd:Ce,onHorizontalScrollIntent:ye=>{var Fe;return(Fe=i.current)==null?void 0:Fe.markHorizontalScrollIntent(ye)},onSelectionAutoscroll:ye=>{A.current=ye},onHandleDragStart:ct,onHandleDragMove:At,onHandleDragEnd:ve,onHandleDragCancel:Ve});return $.current=Rt.stopPtySelectionGesture,{pointerHandlers:Rt.pointerHandlers,ptySelectionToolbar:P,ptySelectionHandles:U,ptySelectionPathAction:D,ptySelectionHandleMetrics:B,copyPtySelection:Oe,openPtySelectionPathAction:Me,handlePtySelectionHandlePointerDown:Rt.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Rt.handlePtySelectionHandleTouchStart}}function Pge(){return Ne(e=>e.ptyScrollTraceEnabled)}const Lge=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function Q2(e){return Lge.has(e)}function yE(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!Q2(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>Q2(r.type))??null}function Ige(e){return`${e.startsWith("@")?e:`@${e}`} `}async function N4(e){const t=yE(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await E4(t),r=await e.relay.uploadClipboardImage(e.sessionId,n);if(!r.success||!r.path)throw new Error(r.error??"剪贴板图片上传失败");return{path:r.path,pathMention:Ige(r.path)}}function zge(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 Bge({sessionId:e,terminalRef:t,onAfterPaste:n}){return b.useCallback(async r=>{var u;const i=r.clipboardData,s=!!yE(i),o=s?null:zge(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Nt;if(!l){Je.error("请先连接开发机");return}if(s){const d=Je.loading("图片上传中...");try{const h=await N4({clipboardData:i,relay:l,sessionId:e});if(Je.dismiss(d),!h)return;Ys(e,h.pathMention)}catch(h){Je.error(h instanceof Error?h.message:String(h),{id:d});return}}else if(o){const d=await Cf({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 jge=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),J2={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:Hfe};function Fge({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function $ge({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function Hge({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function Uge({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:jge.has(n)}const eO=8,Wge=32;function qge({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+eO:t?Wge:eO}function Vge(e){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"?"\x1B[A":e.key==="ArrowDown"?"\x1B[B":e.key==="ArrowRight"?"\x1B[C":e.key==="ArrowLeft"?"\x1B[D":e.key==="Delete"?"\x1B[3~":e.key==="Home"?"\x1B[H":e.key==="End"?"\x1B[F":null}function Yge(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,mobileControlsHeight:o}=e,l=ege(),u=ige(),d=Pge(),{openImagePreview:h}=A3(),p=b.useRef(null),y=b.useRef(null),v=b.useRef([]),_=b.useRef(null),w=b.useRef(null),x=b.useRef(n),E=b.useRef(n),k=b.useRef(!1),R=b.useRef(!1),A=b.useRef(!1),I=b.useRef(null),T=b.useRef(null),$=b.useRef(null),P=b.useRef(null),W=b.useRef({keyboardOpen:!1,controlsVisible:!1}),U=b.useRef(!1),F=b.useRef(!1),D=b.useRef(!1),M=b.useRef(null),B=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[O,N]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[V,q]=b.useState(!1),[H,L]=b.useState(!1),[Y,K]=b.useState({resultIndex:-1,resultCount:0}),z=Ne(Z=>Z.connected),Q=Ne(Z=>Z.proxyOnline),J=Ne(Z=>Z.ptyFontSize),ne=Ne(Z=>Z.inputModePreference),ee=Ne(Z=>Z.adaptiveInputModality),me=Ne(Z=>Z.setAdaptiveInputModality),_e=ee==="hardware",Ce=ul("(pointer: coarse), (hover: none)"),{bottomOffset:Oe,layoutBottomInset:Me}=vE(),Ge=ne==="hardware",ct=Hge({touchEditingSurface:Ce,inputModePreference:ne,detectedPhysicalKeyboard:_e,softKeyboardDetected:Oe>0}),At=Ce&&!ct,ve=ct?0:Oe,Ve=ve>0,Rt=ct?0:Me;U.current=ct,b.useEffect(()=>{x.current=n},[n]),b.useEffect(()=>{k.current=l.ready},[l.ready]);const ye=b.useCallback(()=>x.current&&k.current,[]);b.useEffect(()=>{ve>0&&q(!0)},[ve]);const Fe=rge({containerEl:r,xtermHostRef:s,terminalRef:p}),{ptyInputFocused:Ye,suppressPtyFocus:be,focusPtyInput:Qe,handleFocusCapture:Ke,handleBlurCapture:dt}=Fe,de=Fge({softKeyboardEditingSurface:At,ptyInputFocused:Ye,keyboardOpen:Ve});B.current={keyboardOffset:ve,hasSeenSoftKeyboard:V,showMobilePtyControls:de,touchEditingSurface:Ce,ptyInputFocused:Ye,containerPaddingBottom:B.current.containerPaddingBottom,mobileControlsBottomInset:Rt};const Ae=u.clearNewFramesWhileAway;T.current||(T.current=U2(()=>{var Z;(Z=w.current)==null||Z.relayout()})),$.current||($.current=U2(()=>{var se,ce;const Z=P.current??{reason:"rawInput",force:!1};P.current=null,(se=w.current)==null||se.traceRawInputFollowFire(),(ce=w.current)==null||ce.scrollToBottom(Z.reason,Z.force?{force:!0}:void 0),Ae()}));const tt=b.useCallback(()=>{M.current!==null&&(cancelAnimationFrame(M.current),M.current=null)},[]),et=b.useCallback(()=>{D.current=!0,tt()},[tt]),ut=b.useCallback(()=>{var Z;!D.current||document.visibilityState==="hidden"||((Z=w.current)==null||Z.preparePageResumeRestore(),tt(),M.current=requestAnimationFrame(()=>{M.current=requestAnimationFrame(()=>{M.current=null;const se=w.current;se&&(se.restorePageResume(),Ae(),D.current=!1)})}))},[tt,Ae]);b.useEffect(()=>()=>{var Z,se;(Z=T.current)==null||Z.dispose(),(se=$.current)==null||se.dispose(),tt(),T.current=null,$.current=null},[tt]),b.useEffect(()=>{const Z=()=>{et()},se=()=>{if(document.visibilityState==="hidden"){Z();return}ut()};return document.addEventListener("visibilitychange",se),window.addEventListener("pagehide",Z),window.addEventListener("pageshow",ut),window.addEventListener("focus",ut),()=>{document.removeEventListener("visibilitychange",se),window.removeEventListener("pagehide",Z),window.removeEventListener("pageshow",ut),window.removeEventListener("focus",ut),tt()}},[tt,et,ut]),b.useEffect(()=>{const Z=E.current;if(E.current=n,Z!==n){if(!n){et();return}ut()}},[n,et,ut]);const Ot=b.useCallback((Z="rawInput",se)=>{var Re,He;const ce=P.current,fe=(ce==null?void 0:ce.force)===!0||(se==null?void 0:se.force)===!0;P.current={reason:(se==null?void 0:se.force)===!0||!ce?Z:ce.reason,force:fe},(Re=w.current)==null||Re.traceRawInputFollowScheduled(Z),(He=$.current)==null||He.schedule()},[]),Bt=b.useCallback((Z,se)=>{var ce;!Z.includes("\r")&&!Z.includes(`
|
|
645
645
|
`)||(ce=w.current)==null||ce.resetHorizontalScroll(se,{holdUntilCursorVisible:!0})},[]),Jt=b.useCallback(()=>U.current?"submit":"linefeed",[]),pn=b.useCallback(()=>U.current,[]);b.useEffect(()=>{if(!n||ne!=="auto"||!Ce)return;const Z=ce=>{const fe=s.current,Re=r;return ce instanceof Node?fe!=null&&fe.contains(ce)||ce===document.body||ce===document.documentElement?!0:Re!=null&&Re.contains(ce)?ce instanceof HTMLElement?ce.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:ce===window},se=ce=>{var He;if(!Uge({active:x.current,touchEditingSurface:Ce,key:ce.key,code:ce.code,altKey:ce.altKey,ctrlKey:ce.ctrlKey,metaKey:ce.metaKey,isComposing:ce.isComposing,targetAcceptsPtyInput:Z(ce.target)}))return;me("hardware"),U.current=!0,(He=p.current)==null||He.focus();const fe=s.current;if(ce.target instanceof Node&&(fe!=null&&fe.contains(ce.target)))return;const Re=Vge(ce);!Re||!ye()||(ce.preventDefault(),ce.stopPropagation(),Ys(t,Re),Ot("physicalKeyboard"),Bt(Re,"physicalKeyboardEnter"))};return window.addEventListener("keydown",se,!0),()=>window.removeEventListener("keydown",se,!0)},[n,ye,r,ne,Bt,Ot,t,me,Ce,s]);const sn=b.useCallback(Z=>{const se=Nt;if(!se){Je.error("请先连接开发机");return}const ce=Je.loading(`下载 ${Z} ...`);V1({relay:se,sessionId:t,path:Z}).then(fe=>{fe.ok?Je.success(`已开始下载 ${Z}`,{id:ce}):Je.error(fe.error,{id:ce})}).catch(fe=>{Je.error(fe instanceof Error?fe.message:String(fe),{id:ce})})},[t]),Vt=b.useCallback(Z=>{const se=p.current;return se?Dme(se,v.current,Z):!1},[]),Xn=b.useCallback(Z=>{const se=p.current;return se?Ome(se,v.current,Z):!1},[]),Ht=Dge({sessionId:t,terminalRef:p,xtermHostRef:s,scrollControllerRef:w,containerEl:r,scrollState:O,keyboardOffset:ve,ptyFontSize:J,suppressPtyFocus:be,focusPtyInput:Qe,onTap:Vt,isTapCandidate:Xn,onDownloadPath:sn,onPreviewPath:h});F.current=Ht.ptySelectionHandles!==null;const Zn=Bge({sessionId:t,terminalRef:p,onAfterPaste:()=>Ot("paste")}),je=b.useCallback(Z=>{if(!ye()){Z.preventDefault();return}Zn(Z)},[ye,Zn]),[Xe,mt]=b.useState(!1),jt=b.useCallback(Z=>{Z.dataTransfer.types.includes("Files")&&(Z.preventDefault(),mt(se=>se||!0))},[]),te=b.useCallback(Z=>{Z.currentTarget.contains(Z.relatedTarget)||mt(!1)},[]),we=b.useCallback(async Z=>{var Re;const se=(Re=Z.dataTransfer.files)==null?void 0:Re[0];if(!se||(Z.preventDefault(),mt(!1),!ye()))return;const ce=Nt;if(!ce){Je.error("请先连接开发机");return}const fe=await Cf({relay:ce,sessionId:t,file:se});fe&&(Ys(t,`@${fe} `),Ot("dropUpload"))},[ye,Ot,t]),Le=b.useCallback(Z=>{var ce;if(!ye()){Z.preventDefault();return}const se=Z.target;se instanceof Element&&se.closest(".xterm")||(Z.preventDefault(),(ce=p.current)==null||ce.focus())},[ye]);b.useEffect(()=>{if(!z||!Q)return;const Z=s.current,se=ec,ce=Nt,fe=r,Re=i.current;if(!Z||!se||!ce||!fe||!Re)return;let He=null,lt=null,gt=null,Et=null,qt=null,bn=null,Yt=null;const Ir=Ype({host:Z,sessionId:t,ws:se,relay:ce,scheduleAutoFocus:At?()=>{}:void 0,createTerminal:async En=>{const We=await i4(En,{fontSize:Ne.getState().ptyFontSize});return Yt=We.serializeAddon,We},attachRawInput:(En,We,pt)=>hpe(En,We,{...pt,getPlainEnterBehavior:Jt,isPhysicalKeyboardMode:pn,physicalKeyboardMode:Ge}),isInputEnabled:ye,canFocus:ye,onTerminalReady:En=>{const We=En;p.current=We;const pt=new vce({highlightLimit:1e3});We.loadAddon(pt),y.current=pt,bn=pt.onDidChangeResults(Kt=>{K(Kt)}),L(!0);const Ut=pme(We,h);He=Ut.dispose;const mn=Tme(We,sn);lt=mn.dispose,v.current=[Ut.provider,mn.provider],Kme(()=>p.current);const Pn=Xfe(Z,{serializeRangeAsHtml:(Kt,en)=>(Yt==null?void 0:Yt.serializeAsHTML({range:{startLine:Kt,endLine:Math.min(en,Math.max(0,We.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??""});Et=Pn.dispose;const Pt=D.current;Pt&&(A.current=!1);const Cn=Hpe({container:fe,spacer:Re,host:Z,term:We,hasNewFrame:()=>R.current,consumeNewFrame:()=>{R.current=!1},hasNewFramesWhileAway:()=>u.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:u.setHasNewFramesWhileAway,onAtBottomChange:u.handleAtBottomChange,onScrollStateChange:N,initialUserHasVerticalScrollIntent:Pt?!1:A.current,onUserVerticalScrollIntentChange:Kt=>{A.current=Kt},onTouchReviewStart:be,onTouchBoundaryPrevent:be,onReviewSnapshotCapture:Pn.captureRange,onReviewSnapshotSetVisible:Pn.setVisible,onReviewSnapshotClear:Pn.clear});w.current=Cn,gt=Cn.dispose,Pt&&(Cn.restorePageResume(),Ae(),D.current=!1),Xme(()=>{var Rc;const Kt=oi=>{if(!oi)return null;const ds=oi.getBoundingClientRect();return{top:ds.top,bottom:ds.bottom,height:ds.height,left:ds.left,right:ds.right,width:ds.width}},en=document.querySelector('[data-slot="pty-mobile-controls"]'),zi=document.querySelector("[data-keyboard-offset]"),zr=window.visualViewport,Is=Kt(en),ua=(zr==null?void 0:zr.height)??window.innerHeight;return{...Qme(Cn.getDebugProbe,{container:fe,spacer:Re,host:Z,term:We}),mobileLayout:{...B.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:zr?{height:zr.height,width:zr.width,offsetTop:zr.offsetTop,pageTop:zr.pageTop,scale:zr.scale}:null,chatRoot:{dataKeyboardOffset:(zi==null?void 0:zi.getAttribute("data-keyboard-offset"))??null,rect:Kt(zi)},ptyViewRect:Kt(fe.parentElement),containerRect:Kt(fe),controlsRect:Is,controlsOverflowBelowVisualViewport:Is===null?null:Is.bottom-ua,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(Rc=document.activeElement.closest("[data-slot]"))==null?void 0:Rc.getAttribute("data-slot")}:null},frame:{lastWriteAt:I.current,pendingNewFrame:R.current}}}),qt=Jfe({container:fe,host:Z,onHorizontalScrollIntent:Kt=>{var en;return(en=w.current)==null?void 0:en.markHorizontalScrollIntent(Kt)}}).dispose},onFramePending:()=>{R.current=!0,A.current&&!u.hasNewFramesWhileAwayRef.current&&u.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var En;I.current=performance.now(),(En=T.current)==null||En.schedule()},onRawInput:En=>{Ot("rawInput"),Bt(En,"rawInputEnter")},onError:En=>{const We=En instanceof Error?En.message:String(En);Je.error(`终端初始化失败:${We}`)},...l.transport});return _.current=Ir,()=>{qt==null||qt(),gt==null||gt(),Et==null||Et(),bn==null||bn.dispose(),Zme(),He==null||He(),lt==null||lt(),v.current=[],Gme(),y.current=null,L(!1),K({resultIndex:-1,resultCount:0}),Ir.dispose(),p.current=null,w.current=null,_.current=null}},[t,z,Q,r,i,s,l.transport,u.handleAtBottomChange,u.hasNewFramesWhileAwayRef,u.setHasNewFramesWhileAway,ye,Ge,Jt,pn,sn,h,be,Ot,Bt]),b.useEffect(()=>{const Z=p.current,se=w.current;!Z||!se||qfe(Z,J,se.relayout)},[J]),b.useEffect(()=>{if(!n||!l.ready||At)return;const Z=requestAnimationFrame(()=>{var se;return(se=p.current)==null?void 0:se.focus()});return()=>cancelAnimationFrame(Z)},[n,l.ready,At]);const ht=b.useCallback((Z="viewExternal",se)=>{var ce;(ce=w.current)==null||ce.scrollToBottom(Z,se)},[]),Lt=b.useCallback(()=>{var Z;(Z=w.current)==null||Z.refreshReviewSnapshot()},[]),ie=b.useCallback(Z=>{var se;(se=w.current)==null||se.scrollToRatio(Z)},[]),oe=b.useCallback(Z=>{var se;(se=w.current)==null||se.scrollToXRatio(Z)},[]),he=b.useCallback(Z=>{var lt;const se=p.current,ce=se==null?void 0:se.getSelectionPosition();if(!se||!ce)return;const fe=ce.start.y;if(fe>=Z&&fe<Z+se.rows)return;const Re=Math.max(0,se.buffer.active.length-se.rows);if(Re===0)return;const He=Math.max(0,Math.min(Re,fe-Math.floor(se.rows/2)));(lt=w.current)==null||lt.scrollToRatio(He/Re)},[]),pe=b.useCallback((Z,se=!1)=>{const ce=p.current,fe=y.current;if(!ce||!fe||!Z)return Z||(fe==null||fe.clearDecorations(),ce==null||ce.clearSelection(),K({resultIndex:-1,resultCount:0})),!1;const Re=ce.buffer.active.viewportY,He=fe.findNext(Z,{...J2,incremental:se});return He&&he(Re),He},[he]),X=b.useCallback(Z=>{const se=p.current,ce=y.current;if(!se||!ce||!Z)return!1;const fe=se.buffer.active.viewportY,Re=ce.findPrevious(Z,J2);return Re&&he(fe),Re},[he]),re=b.useCallback(()=>{var Z,se;(Z=y.current)==null||Z.clearDecorations(),(se=p.current)==null||se.clearSelection(),K({resultIndex:-1,resultCount:0})},[]),le=b.useCallback(Z=>{var se;ye()&&(Ys(t,Z),Ot("mobileControl",{force:!0}),Bt(Z,"mobileControlEnter"),(se=p.current)==null||se.focus())},[ye,Bt,Ot,t]),ke=b.useCallback(()=>{var se,ce,fe;if(!ye())return;const Z=(ce=(se=navigator.clipboard)==null?void 0:se.readText)==null?void 0:ce.bind(navigator.clipboard);if(!window.isSecureContext||!Z){Je.error("无法读取剪贴板"),(fe=p.current)==null||fe.focus();return}Z().then(Re=>{if(!Re)return;const He=p.current;if(He){He.paste(Re);return}Ys(t,Re),Ot("paste"),Bt(Re,"pasteEnter")}).catch(Re=>{const He=Re instanceof Error&&Re.message?Re.message:"无法读取剪贴板";Je.error(He)}).finally(()=>{var Re;return(Re=p.current)==null?void 0:Re.focus()})},[ye,Bt,Ot,t]),ze=qge({showMobilePtyControls:de,horizontalScrollable:O.horizontalScrollable,mobileControlsHeight:o});B.current.containerPaddingBottom=ze,b.useEffect(()=>{var ce,fe,Re;F.current?(ce=w.current)==null||ce.relayout():(fe=T.current)==null||fe.schedule();const Z=W.current,se=$ge({controlsVisible:de,keyboardOpen:Ve,previous:Z});W.current={keyboardOpen:Ve,controlsVisible:de},de&&(F.current?Ae():se?((Re=w.current)==null||Re.scrollToBottom("keyboardOffset",{force:!0}),Ae()):Ve||Ot("keyboardOffset"))},[ve,Ve,de,ze,Ae,Ot]);const it=b.useMemo(()=>({onFocusCapture:Ke,onBlurCapture:dt}),[Ke,dt]);return{scrollState:O,isAtBottom:u.isAtBottom,hasNewFramesWhileAway:u.hasNewFramesWhileAway,ptyInputFocused:Ye,showMobilePtyControls:de,touchEditingSurface:Ce,keyboardOffset:ve,physicalKeyboardMode:ct,softKeyboardEditingSurface:At,mobileControlsBottomInset:Rt,connectionReady:l.ready,connectionOverlay:l.overlay,containerPaddingBottom:ze,traceEnabled:d,findReady:H,findResultIndex:Y.resultIndex,findResultCount:Y.resultCount,findNext:pe,findPrevious:X,clearFind:re,refreshReviewSnapshot:Lt,scrollToBottom:ht,scrollToRatio:ie,scrollToXRatio:oe,clearNewFramesWhileAway:Ae,sendMobileInput:le,pasteMobileClipboard:ke,handleTerminalContainerMouseDown:Le,handlePasteCapture:je,pointerHandlers:Ht.pointerHandlers,focusHandlers:it,ptySelectionToolbar:Ht.ptySelectionToolbar,ptySelectionHandles:Ht.ptySelectionHandles,ptySelectionPathAction:Ht.ptySelectionPathAction,ptySelectionHandleMetrics:Ht.ptySelectionHandleMetrics,copyPtySelection:Ht.copyPtySelection,openPtySelectionPathAction:Ht.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:Ht.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Ht.handlePtySelectionHandleTouchStart,isPtyDragOver:Xe,handlePtyDragOver:jt,handlePtyDragLeave:te,handlePtyDrop:we}}function Kge({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=Yge({sessionId:e,active:r,containerEl:s,spacerRef:v,xtermHostRef:_,mobileControlsHeight:l}),x=w.ptySelectionHandleMetrics,{clearFind:E,findNext:k,findPrevious:R,findReady:A,findResultCount:I,findResultIndex:T}=w,$=b.useCallback(()=>{R(p)},[R,p]),P=b.useCallback(()=>{k(p)},[k,p]),W=b.useCallback(()=>h(!0),[]),U=b.useCallback(()=>{h(!1),E()},[E]),F=P3({enabled:r,open:d,openRequest:i,onOpen:W,onClose:U,onPrevious:$,onNext:P});return b.useEffect(()=>{!d||!A||(p?k(p,!0):E())},[E,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(K0,{query:p,resultIndex:T,resultCount:I,focusRequest:F.focusRequest,loading:!!p&&!A,onQueryChange:y,onPrevious:$,onNext:P,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:D=>{w.refreshReviewSnapshot(),w.pointerHandlers.onPointerDownCapture(D)},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(M3,{visible:!w.isAtBottom,hasNewMessages:w.hasNewFramesWhileAway,className:d?"top-14":"top-10",onClick:()=>{w.scrollToBottom("backToBottomBtn",{force:!0}),w.clearNewFramesWhileAway()}}),w.showMobilePtyControls?g.jsx(Ale,{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(tO,{kind:"anchor",position:w.ptySelectionHandles.anchor,metrics:x,"aria-label":"调整选区起点",onPointerDown:D=>w.handlePtySelectionHandlePointerDown("anchor",D),onTouchStart:D=>w.handlePtySelectionHandleTouchStart("anchor",D)}),g.jsx(tO,{kind:"focus",position:w.ptySelectionHandles.focus,metrics:x,"aria-label":"调整选区终点",onPointerDown:D=>w.handlePtySelectionHandlePointerDown("focus",D),onTouchStart:D=>w.handlePtySelectionHandleTouchStart("focus",D)})]}):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:D=>D.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:D=>D.preventDefault(),onClick:w.openPtySelectionPathAction,"aria-label":w.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:w.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,g.jsx(zle,{state:w.scrollState,onScrollRatio:w.scrollToRatio}),g.jsx(Ble,{state:w.scrollState,onScrollRatio:w.scrollToXRatio}),g.jsx(gle,{...w.connectionOverlay}),g.jsx(yle,{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(Gge,{}):null]})}function tO({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 Gge(){const[e,t]=b.useState(!1);async function n(){const r=ple();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 Xge=3,Zge=1024,Qge=720,eg=.5,M4=b.createContext(null);function Jge({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Ne(k=>k.selectedProxyId),u=zt(k=>k.sessions),d=zt(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(`
|
|
646
646
|
`),[u]),v=b.useCallback(k=>{p.current=k.sessionId,i(k),n(R=>Boe(R,k.sessionId,{capacity:Xge,now:Date.now(),activeSessionId:k.sessionId}).map(I=>I.sessionId===k.sessionId?{...I,sessionKind:k.sessionKind,provider:k.provider}:I))},[]),_=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&&nve(A,R)?A:R)},[]),x=b.useCallback((k,R)=>{R!==void 0&&n(A=>A.map(I=>I.sessionId===k?{...I,findRequest:R}:I))},[]);b.useEffect(()=>{if(!d)return;const k=new Set(y?y.split(`
|
|
647
|
-
`):[]);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 E=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:x,updateViewportRect:w}),[v,_,x,w]);return g.jsxs(M4.Provider,{value:E,children:[e,g.jsx(tve,{entries:t,activeView:r,viewportRect:s})]})}function eve({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(M4),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 tve({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)??Zge,height:(n==null?void 0:n.height)??Qge};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(N3,{sessionId:r.sessionId,children:g.jsx(Kge,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function nve(e,t){return Math.abs(e.top-t.top)<=eg&&Math.abs(e.left-t.left)<=eg&&Math.abs(e.width-t.width)<=eg&&Math.abs(e.height-t.height)<=eg}function bE({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 _E="dev-anywhere:last-chat-route",O4="dev-anywhere:route-restored",KS="dev-anywhere:restored-target";function rve(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function ive(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(_E))??null}catch{return null}}function sve(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(_E,e)}catch{}}function D4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(_E)}catch{}}function ove(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(O4))==="1"}catch{return!1}}function ave(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(O4,"1")}catch{}}function lve(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(KS,e)}catch{}}function cve(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(KS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(KS)),n}catch{return null}}function uve(e){const t=UL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Og(){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 dve(){return typeof navigator>"u"?{supported:!0}:uve({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Og()})}function hve(){Ume(),Wme();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(()=>Og()),u=Ne(P=>P.proxies.length),d=Ne(P=>P.proxyListLoaded),h=Ne(P=>P.relayClientAuthIssue),p=Ne(P=>!!P.selectedProxyId),y=Ne(P=>P.selectedProxyId),v=Ne(P=>P.selectedProxyName),_=zt(P=>P.sessions.length),w=Ne(P=>P.pendingToast),x=Ne(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=bE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:h}),R=v??y,I=e.pathname==="/sessions"&&d&&u>0?g.jsxs(bt,{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(OP,{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:Je.error,info:Je.info,success:Je.success})[w.kind](w.message),x(null)},[w,x]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Og());return}const P=window.matchMedia("(display-mode: standalone)"),W=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(Og());return U(),P.addEventListener("change",U),W.addEventListener("change",U),()=>{P.removeEventListener("change",U),W.removeEventListener("change",U)}},[]);const T=b.useRef(!1);b.useEffect(()=>{if(T.current)return;T.current=!0;const P=rve({pathname:e.pathname,alreadyRestored:ove(),lastRoute:ive()});ave(),P&&(lve(P),t(P,{replace:!0}))},[]);const $=b.useRef(!1);return b.useEffect(()=>{n?($.current=!0,sve(`${e.pathname}${e.search}`)):$.current&&($.current=!1,D4())},[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(bt,{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(LP,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx($se,{subtitle:k,action:I}),g.jsx(zoe,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(Bse,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(Jge,{children:g.jsx("div",{className:qe("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(HU,{})},r?"top-level":e.pathname)})})]}),g.jsx(q0,{open:i,onOpenChange:s}),g.jsx(poe,{}),g.jsx(Xse,{}),g.jsx(pZ,{})]})}function P4({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(GB,{texts:XB,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 fve(){const e=Ne(o=>o.proxies),t=Ne(o=>!!o.selectedProxyId),n=Ne(o=>o.relayClientAuthIssue),r=zt(o=>o.sessions.length),i=bE({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(DB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(tc,{variant:s}):g.jsx(P4,{subtitle:i})})]})}function pve(){const e=Ne(o=>o.proxies),t=Ne(o=>!!o.selectedProxyId),n=Ne(o=>o.relayClientAuthIssue),r=zt(o=>o.sessions.length),i=xi("local",cn.proxyId)!==null;if(!t&&!i)return g.jsx($U,{to:"/",replace:!0});const s=bE({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(HB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(P4,{subtitle:s})})]})}function L4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function mve(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function I4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return mve(e,typeof((t=L4())==null?void 0:t.request)=="function")}function gve(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function vve(){const e=L4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(gve(I4()));return e.request("screen")}function yve(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class bve{constructor(t={}){vt(this,"activeScopes",new Set);vt(this,"pendingScopes",new Set);vt(this,"listeners",new Map);vt(this,"sentinel",null);vt(this,"requestInFlight",null);vt(this,"requestWakeLock");vt(this,"documentRef");vt(this,"windowRef");vt(this,"unavailableReason");vt(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(()=>{})});vt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??vve,this.unavailableReason=typeof t.request=="function"?null:I4(),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 Ka=new bve;function z4(e){const[t,n]=b.useState(()=>Ka.getSnapshot(e));b.useEffect(()=>Ka.subscribe(e,n),[e]),b.useEffect(()=>()=>{Ka.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Ka.enable(e),[e]),i=b.useCallback(()=>Ka.disable(e),[e]),s=b.useCallback(()=>Ka.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function _ve(){return new AudioContext}class wve{constructor(t=_ve){vt(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 Dg=new wve,nO=400,Du=[];let B4=1;function Sve(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Kh(e){const t={sequence:B4++,timestamp:new Date().toISOString(),monotonicMs:Sve(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Du.push(t),Du.length>nO&&Du.splice(0,Du.length-nO)}function xve(){return Du.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Eve(){Du.length=0,B4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:xve,clear:Eve});function j4(e){return`voice-pilot:${e}`}function Cve(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 kve="modulepreload",Tve=function(e){return"/"+e},rO={},Rve=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=Tve(d),d in rO)return;rO[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":kve,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)})},Ave="/assets/fvad-DYxbW2my.wasm",Qu=16e3,Nve=20,Ga=Qu*Nve/1e3,Bw=Ga*Int16Array.BYTES_PER_ELEMENT;let iO=null;async function Mve(){return iO??(iO=Rve(async()=>{const{default:e}=await import("./fvad-QBrzThuq.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Ave:t}))),iO}class wE{constructor(t,n,r){vt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Mve(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(Bw);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Qu)!==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 wE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==Bw)throw new Error(`语音活动检测帧必须为 ${Bw} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Ga);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 Ove{constructor(t={}){vt(this,"startSpeechFrames");vt(this,"endSilenceFrames");vt(this,"active",!1);vt(this,"speechFrames",0);vt(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 Dve{constructor(){vt(this,"pending",new Float32Array(Ga));vt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Ga-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Ga&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Ga<=t.length;)n(t.slice(r,r+Ga)),r+=Ga;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const Pve="/__dev_anywhere_debug/voice-fixture",Lve=Qu*WB/1e3;function Ive(){return wE.create(3)}const zve={createVad:Ive,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Bve(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 jve(e){for(const t of e.getTracks())t.stop()}function F4(e){const t=e.createAudioContext({sampleRate:Qu});if(t.sampleRate!==Qu)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function Fve(e){const t=F4(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:Qu}})}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(),jve(n),t.state!=="closed"&&await t.close()}}}async function $ve(e,t){const n=F4(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 $4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Pve}:{kind:"microphone"}}async function Hve(e,t=zve){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await $ve(e.source.url,t):await Fve(t)}catch(h){throw n.destroy(),h}const i=new Ove,s=new Dve,o=r.context.createScriptProcessor(Lve,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Cve(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:Bve(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 H4(e=Cv().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function Uve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function Wve({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=Uve(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 qve(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 Vve(){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(qve(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const gu="min-h-9 gap-2.5",tg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function fo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:qe("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function Yve({label:e}){return g.jsxs(fo,{className:"relative",children:[g.jsx(MP,{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 Kve({sessionId:e,mode:t,onFind:n}){const r=H4(),i=Qs(),s=zt(ve=>ve.sessions.find(Ve=>Ve.sessionId===e)),o=zt(ve=>ve.ptyTitles[e]),l=Ne(ve=>ve.ptyFontSize),u=Ne(ve=>ve.chatContentFontSize),d=Ne(ve=>ve.selectedProxyId),h=Ne(ve=>ve.adjustPtyFontSize),p=Ne(ve=>ve.adjustChatContentFontSize),y=Ne(ve=>ve.setChatContentFontSize),v=Ne(ve=>ve.resetPtyFontSize),_=Ne(ve=>ve.resetChatContentFontSize),w=Ne(ve=>ve.inputModePreference==="hardware"),x=zt(ve=>ve.renameSession),E=Ix(d,e),k=zt(ve=>E?!!ve.ptyAutoYesBySessionKey[E]:!1),R=zt(ve=>ve.setPtyAutoYes),I=ul("(pointer: coarse), (hover: none)")&&!w,T=t==="pty"||(s==null?void 0:s.mode)==="pty",$=(s==null?void 0:s.kind)==="terminal",P=z4(e),W=ln(ve=>ve.bySessionId[e]??sy),U=ln(ve=>ve.enable),F=ln(ve=>ve.disable),D=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Kx(s),B=D&&(s==null?void 0:s.name)||M||T&&o||(s==null?void 0:s.name)||e.slice(0,8),O=!!(T&&!$&&o&&!D),N=T?l:Px(u,I),V=!T&&I?nL:eL,q=T?v:_,[H,L]=b.useState(!1),[Y,K]=b.useState(!1),z=W.enabled,Q=P.active||z,J=P.pending||!P.supported||z;function ne(ve){if(T){h(ve);return}if(I){y(N+ve);return}p(ve)}function ee(){P.toggle().catch(ve=>{Je.error(ve instanceof Error?ve.message:String(ve))})}async function me(ve){var Rt;if(T||$){Je.info("Voice Pilot 目前适用于聊天会话。");return}if(ve!==!0){F(e);return}const Ve=Nt;if(!Ve){Je.error("请先连接开发机");return}try{if(!((Rt=(await Ve.requestVoiceConfig()).config)!=null&&Rt.configured)){Je.info("请先在设置里配置 Voice Pilot。");return}L(!0)}catch(ye){Je.error(ye instanceof Error?ye.message:String(ye))}}async function _e(){var ye;K(!0);let ve=null,Ve=!1;const Rt=j4(e);try{Kh({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 Fe=Ka.enable(Rt).then(()=>{Kh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ke=>{throw Kh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ke instanceof Error?Ke.message:String(Ke)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ke})});ve=L1.acquire("capture");const Ye=Dg.prepare(),Qe=$4().kind==="microphone"?Vve():Promise.resolve();await Promise.all([Fe,Ye,Qe]),U(e),Ve=!0,L(!1)}catch(Fe){Kh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Fe instanceof Error?Fe.message:String(Fe)}}),Je.error(Fe instanceof Error?Fe.message:String(Fe))}finally{ve==null||ve.release(),Ve||await Ka.disable(Rt).catch(()=>{}),K(!1)}}const Ce=b.useRef(null),Oe=b.useRef(null),[Me,Ge]=b.useState(!1);async function ct(ve){var Fe;const Ve=(Fe=ve.target.files)==null?void 0:Fe[0];if(ve.target.value="",!Ve)return;const Rt=Nt;if(!Rt){Je.error("请先连接开发机");return}const ye=await Cf({relay:Rt,sessionId:e,file:Ve});ye&&Ys(e,`@${ye} `)}async function At(ve,Ve){const Rt=Nt;if(!Rt)throw new Error("请先连接开发机");const ye=await Rt.renameSession(ve,Ve);if(!ye.success)throw new Error(ye.error??"重命名失败");x(ve,ye.name??Ve),Je.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(bt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(bv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(Wve,{title:B,isPtyTitle:O})}),g.jsxs(M1,{modal:!1,children:[g.jsx(O1,{asChild:!0,children:g.jsx(bt,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(d8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(Bm,{className:tg,children:"会话"}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(fo,{children:g.jsx(Ig,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-rename",onSelect:()=>Ge(!0),children:[g.jsx(fo,{children:g.jsx(V8,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(G_,{checked:Q,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:ee,children:[g.jsx(fo,{children:g.jsx(T8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:P.supported?z?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":P.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),T&&!$&&g.jsxs(G_,{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:!E,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ve=>{E&&R(E,ve===!0)},children:[g.jsx(fo,{children:g.jsx(ta,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!T&&!$&&g.jsxs(G_,{checked:W.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:me,children:[g.jsx(fo,{children:g.jsx(D8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(X_,{}),T&&!$?g.jsxs(g.Fragment,{children:[g.jsx(Bm,{className:tg,children:"快捷键"}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ys(e,""),children:[g.jsx(Yve,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(X_,{}),g.jsx(Bm,{className:tg,children:"文件"}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ve;return(ve=Oe.current)==null?void 0:ve.click()},children:[g.jsx(fo,{children:g.jsx(Pf,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ve;return(ve=Ce.current)==null?void 0:ve.click()},children:[g.jsx(fo,{children:g.jsx(IP,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(X_,{})]}):null,g.jsx(Bm,{className:tg,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(fo,{children:g.jsx(v7,{"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(bt,{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<=V,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ve=>{ve.stopPropagation(),ne(-1)},children:g.jsx(L8,{"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(bt,{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>=tL,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ve=>{ve.stopPropagation(),ne(1)},children:g.jsx(G8,{"aria-hidden":"true"})})]})]})}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-font-reset",onClick:q,children:[g.jsx(fo,{children:g.jsx(Q8,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(jh,{open:Me,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Ge,onRename:At}),g.jsx(wc,{open:H&&!W.enabled,onOpenChange:ve=>{Y||L(ve)},children:g.jsxs(Sc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(xc,{children:[g.jsx(cl,{children:"开启 Voice Pilot?"}),g.jsx(uc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"outline",disabled:Y,onClick:()=>L(!1),children:"取消"}),g.jsx(bt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Y,onClick:()=>{_e()},children:Y?"正在开启...":"开启 Voice Pilot"})]})]})}),T?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Oe,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ve=>{ct(ve)}}),g.jsx("input",{ref:Ce,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ve=>{ct(ve)}})]}):null]})}function vu(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,x=w/16,E=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(_,5)} ms`,`
|
|
647
|
+
`):[]);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 E=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:x,updateViewportRect:w}),[v,_,x,w]);return g.jsxs(M4.Provider,{value:E,children:[e,g.jsx(tve,{entries:t,activeView:r,viewportRect:s})]})}function eve({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(M4),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 tve({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)??Zge,height:(n==null?void 0:n.height)??Qge};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(N3,{sessionId:r.sessionId,children:g.jsx(Kge,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function nve(e,t){return Math.abs(e.top-t.top)<=eg&&Math.abs(e.left-t.left)<=eg&&Math.abs(e.width-t.width)<=eg&&Math.abs(e.height-t.height)<=eg}function bE({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 _E="dev-anywhere:last-chat-route",O4="dev-anywhere:route-restored",KS="dev-anywhere:restored-target";function rve(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function ive(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(_E))??null}catch{return null}}function sve(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(_E,e)}catch{}}function D4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(_E)}catch{}}function ove(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(O4))==="1"}catch{return!1}}function ave(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(O4,"1")}catch{}}function lve(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(KS,e)}catch{}}function cve(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(KS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(KS)),n}catch{return null}}function uve(e){const t=UL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Og(){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 dve(){return typeof navigator>"u"?{supported:!0}:uve({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Og()})}function hve(){Ume(),Wme();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(()=>Og()),u=Ne(P=>P.proxies.length),d=Ne(P=>P.proxyListLoaded),h=Ne(P=>P.relayClientAuthIssue),p=Ne(P=>!!P.selectedProxyId),y=Ne(P=>P.selectedProxyId),v=Ne(P=>P.selectedProxyName),_=zt(P=>P.sessions.length),w=Ne(P=>P.pendingToast),x=Ne(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=bE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:h}),R=v??y,I=e.pathname==="/sessions"&&d&&u>0?g.jsxs(bt,{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(OP,{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:Je.error,info:Je.info,success:Je.success})[w.kind](w.message),x(null)},[w,x]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Og());return}const P=window.matchMedia("(display-mode: standalone)"),W=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(Og());return U(),P.addEventListener("change",U),W.addEventListener("change",U),()=>{P.removeEventListener("change",U),W.removeEventListener("change",U)}},[]);const T=b.useRef(!1);b.useEffect(()=>{if(T.current)return;T.current=!0;const P=rve({pathname:e.pathname,alreadyRestored:ove(),lastRoute:ive()});ave(),P&&(lve(P),t(P,{replace:!0}))},[]);const $=b.useRef(!1);return b.useEffect(()=>{n?($.current=!0,sve(`${e.pathname}${e.search}`)):$.current&&($.current=!1,D4())},[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(bt,{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(LP,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx($se,{subtitle:k,action:I}),g.jsx(zoe,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(Bse,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(Jge,{children:g.jsx("div",{className:qe("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(HU,{})},r?"top-level":e.pathname)})})]}),g.jsx(q0,{open:i,onOpenChange:s}),g.jsx(poe,{}),g.jsx(Xse,{}),g.jsx(pZ,{})]})}function P4({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(GB,{texts:XB,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 fve(){const e=Ne(o=>o.proxies),t=Ne(o=>!!o.selectedProxyId),n=Ne(o=>o.relayClientAuthIssue),r=zt(o=>o.sessions.length),i=bE({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(DB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(tc,{variant:s}):g.jsx(P4,{subtitle:i})})]})}function pve(){const e=Ne(o=>o.proxies),t=Ne(o=>!!o.selectedProxyId),n=Ne(o=>o.relayClientAuthIssue),r=zt(o=>o.sessions.length),i=xi("local",cn.proxyId)!==null;if(!t&&!i)return g.jsx($U,{to:"/",replace:!0});const s=bE({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(HB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(P4,{subtitle:s})})]})}function L4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function mve(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function I4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return mve(e,typeof((t=L4())==null?void 0:t.request)=="function")}function gve(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function vve(){const e=L4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(gve(I4()));return e.request("screen")}function yve(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class bve{constructor(t={}){vt(this,"activeScopes",new Set);vt(this,"pendingScopes",new Set);vt(this,"listeners",new Map);vt(this,"sentinel",null);vt(this,"requestInFlight",null);vt(this,"requestWakeLock");vt(this,"documentRef");vt(this,"windowRef");vt(this,"unavailableReason");vt(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(()=>{})});vt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??vve,this.unavailableReason=typeof t.request=="function"?null:I4(),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 Ka=new bve;function z4(e){const[t,n]=b.useState(()=>Ka.getSnapshot(e));b.useEffect(()=>Ka.subscribe(e,n),[e]),b.useEffect(()=>()=>{Ka.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Ka.enable(e),[e]),i=b.useCallback(()=>Ka.disable(e),[e]),s=b.useCallback(()=>Ka.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function _ve(){return new AudioContext}class wve{constructor(t=_ve){vt(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 Dg=new wve,nO=400,Du=[];let B4=1;function Sve(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Kh(e){const t={sequence:B4++,timestamp:new Date().toISOString(),monotonicMs:Sve(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Du.push(t),Du.length>nO&&Du.splice(0,Du.length-nO)}function xve(){return Du.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Eve(){Du.length=0,B4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:xve,clear:Eve});function j4(e){return`voice-pilot:${e}`}function Cve(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 kve="modulepreload",Tve=function(e){return"/"+e},rO={},Rve=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=Tve(d),d in rO)return;rO[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":kve,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)})},Ave="/assets/fvad-DYxbW2my.wasm",Qu=16e3,Nve=20,Ga=Qu*Nve/1e3,Bw=Ga*Int16Array.BYTES_PER_ELEMENT;let iO=null;async function Mve(){return iO??(iO=Rve(async()=>{const{default:e}=await import("./fvad-QW-WKQIv.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Ave:t}))),iO}class wE{constructor(t,n,r){vt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Mve(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(Bw);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Qu)!==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 wE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==Bw)throw new Error(`语音活动检测帧必须为 ${Bw} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Ga);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 Ove{constructor(t={}){vt(this,"startSpeechFrames");vt(this,"endSilenceFrames");vt(this,"active",!1);vt(this,"speechFrames",0);vt(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 Dve{constructor(){vt(this,"pending",new Float32Array(Ga));vt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Ga-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Ga&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Ga<=t.length;)n(t.slice(r,r+Ga)),r+=Ga;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const Pve="/__dev_anywhere_debug/voice-fixture",Lve=Qu*WB/1e3;function Ive(){return wE.create(3)}const zve={createVad:Ive,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Bve(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 jve(e){for(const t of e.getTracks())t.stop()}function F4(e){const t=e.createAudioContext({sampleRate:Qu});if(t.sampleRate!==Qu)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function Fve(e){const t=F4(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:Qu}})}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(),jve(n),t.state!=="closed"&&await t.close()}}}async function $ve(e,t){const n=F4(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 $4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Pve}:{kind:"microphone"}}async function Hve(e,t=zve){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await $ve(e.source.url,t):await Fve(t)}catch(h){throw n.destroy(),h}const i=new Ove,s=new Dve,o=r.context.createScriptProcessor(Lve,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Cve(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:Bve(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 H4(e=Cv().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function Uve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function Wve({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=Uve(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 qve(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 Vve(){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(qve(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const gu="min-h-9 gap-2.5",tg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function fo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:qe("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function Yve({label:e}){return g.jsxs(fo,{className:"relative",children:[g.jsx(MP,{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 Kve({sessionId:e,mode:t,onFind:n}){const r=H4(),i=Qs(),s=zt(ve=>ve.sessions.find(Ve=>Ve.sessionId===e)),o=zt(ve=>ve.ptyTitles[e]),l=Ne(ve=>ve.ptyFontSize),u=Ne(ve=>ve.chatContentFontSize),d=Ne(ve=>ve.selectedProxyId),h=Ne(ve=>ve.adjustPtyFontSize),p=Ne(ve=>ve.adjustChatContentFontSize),y=Ne(ve=>ve.setChatContentFontSize),v=Ne(ve=>ve.resetPtyFontSize),_=Ne(ve=>ve.resetChatContentFontSize),w=Ne(ve=>ve.inputModePreference==="hardware"),x=zt(ve=>ve.renameSession),E=Ix(d,e),k=zt(ve=>E?!!ve.ptyAutoYesBySessionKey[E]:!1),R=zt(ve=>ve.setPtyAutoYes),I=ul("(pointer: coarse), (hover: none)")&&!w,T=t==="pty"||(s==null?void 0:s.mode)==="pty",$=(s==null?void 0:s.kind)==="terminal",P=z4(e),W=ln(ve=>ve.bySessionId[e]??sy),U=ln(ve=>ve.enable),F=ln(ve=>ve.disable),D=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Kx(s),B=D&&(s==null?void 0:s.name)||M||T&&o||(s==null?void 0:s.name)||e.slice(0,8),O=!!(T&&!$&&o&&!D),N=T?l:Px(u,I),V=!T&&I?nL:eL,q=T?v:_,[H,L]=b.useState(!1),[Y,K]=b.useState(!1),z=W.enabled,Q=P.active||z,J=P.pending||!P.supported||z;function ne(ve){if(T){h(ve);return}if(I){y(N+ve);return}p(ve)}function ee(){P.toggle().catch(ve=>{Je.error(ve instanceof Error?ve.message:String(ve))})}async function me(ve){var Rt;if(T||$){Je.info("Voice Pilot 目前适用于聊天会话。");return}if(ve!==!0){F(e);return}const Ve=Nt;if(!Ve){Je.error("请先连接开发机");return}try{if(!((Rt=(await Ve.requestVoiceConfig()).config)!=null&&Rt.configured)){Je.info("请先在设置里配置 Voice Pilot。");return}L(!0)}catch(ye){Je.error(ye instanceof Error?ye.message:String(ye))}}async function _e(){var ye;K(!0);let ve=null,Ve=!1;const Rt=j4(e);try{Kh({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 Fe=Ka.enable(Rt).then(()=>{Kh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ke=>{throw Kh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ke instanceof Error?Ke.message:String(Ke)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ke})});ve=L1.acquire("capture");const Ye=Dg.prepare(),Qe=$4().kind==="microphone"?Vve():Promise.resolve();await Promise.all([Fe,Ye,Qe]),U(e),Ve=!0,L(!1)}catch(Fe){Kh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Fe instanceof Error?Fe.message:String(Fe)}}),Je.error(Fe instanceof Error?Fe.message:String(Fe))}finally{ve==null||ve.release(),Ve||await Ka.disable(Rt).catch(()=>{}),K(!1)}}const Ce=b.useRef(null),Oe=b.useRef(null),[Me,Ge]=b.useState(!1);async function ct(ve){var Fe;const Ve=(Fe=ve.target.files)==null?void 0:Fe[0];if(ve.target.value="",!Ve)return;const Rt=Nt;if(!Rt){Je.error("请先连接开发机");return}const ye=await Cf({relay:Rt,sessionId:e,file:Ve});ye&&Ys(e,`@${ye} `)}async function At(ve,Ve){const Rt=Nt;if(!Rt)throw new Error("请先连接开发机");const ye=await Rt.renameSession(ve,Ve);if(!ye.success)throw new Error(ye.error??"重命名失败");x(ve,ye.name??Ve),Je.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(bt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(bv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(Wve,{title:B,isPtyTitle:O})}),g.jsxs(M1,{modal:!1,children:[g.jsx(O1,{asChild:!0,children:g.jsx(bt,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(d8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(Bm,{className:tg,children:"会话"}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(fo,{children:g.jsx(Ig,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-rename",onSelect:()=>Ge(!0),children:[g.jsx(fo,{children:g.jsx(V8,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(G_,{checked:Q,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:ee,children:[g.jsx(fo,{children:g.jsx(T8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:P.supported?z?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":P.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),T&&!$&&g.jsxs(G_,{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:!E,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ve=>{E&&R(E,ve===!0)},children:[g.jsx(fo,{children:g.jsx(ta,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!T&&!$&&g.jsxs(G_,{checked:W.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:me,children:[g.jsx(fo,{children:g.jsx(D8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(X_,{}),T&&!$?g.jsxs(g.Fragment,{children:[g.jsx(Bm,{className:tg,children:"快捷键"}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ys(e,""),children:[g.jsx(Yve,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(X_,{}),g.jsx(Bm,{className:tg,children:"文件"}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ve;return(ve=Oe.current)==null?void 0:ve.click()},children:[g.jsx(fo,{children:g.jsx(Pf,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ve;return(ve=Ce.current)==null?void 0:ve.click()},children:[g.jsx(fo,{children:g.jsx(IP,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(X_,{})]}):null,g.jsx(Bm,{className:tg,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(fo,{children:g.jsx(v7,{"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(bt,{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<=V,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ve=>{ve.stopPropagation(),ne(-1)},children:g.jsx(L8,{"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(bt,{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>=tL,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ve=>{ve.stopPropagation(),ne(1)},children:g.jsx(G8,{"aria-hidden":"true"})})]})]})}),g.jsxs(yo,{className:gu,"data-slot":"chat-menu-font-reset",onClick:q,children:[g.jsx(fo,{children:g.jsx(Q8,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(jh,{open:Me,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Ge,onRename:At}),g.jsx(wc,{open:H&&!W.enabled,onOpenChange:ve=>{Y||L(ve)},children:g.jsxs(Sc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(xc,{children:[g.jsx(cl,{children:"开启 Voice Pilot?"}),g.jsx(uc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Ku,{children:[g.jsx(bt,{type:"button",variant:"outline",disabled:Y,onClick:()=>L(!1),children:"取消"}),g.jsx(bt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Y,onClick:()=>{_e()},children:Y?"正在开启...":"开启 Voice Pilot"})]})]})}),T?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Oe,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ve=>{ct(ve)}}),g.jsx("input",{ref:Ce,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ve=>{ct(ve)}})]}):null]})}function vu(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,x=w/16,E=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(_,5)} ms`,`
|
|
648
648
|
font-size: .6rem;
|
|
649
649
|
font-weight: bold;
|
|
650
650
|
color: hsl(${Math.max(0,Math.min(120-120*x,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 sO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Gve=(e,t)=>Math.abs(e-t)<1.01,Xve=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},oO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Zve=e=>e,Qve=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},Jve=(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(oO(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(oO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},aO={passive:!0},lO=typeof window>"u"?!0:"onscrollend"in window,eye=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&lO?()=>{}:Xve(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,aO);const d=e.options.useScrollendEvent&&lO;return d&&n.addEventListener("scrollend",u,aO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},tye=(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"]},nye=(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 rye{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:Zve,rangeExtractor:Qve,onChange:()=>{},measureElement:tye,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=vu(()=>(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=vu(()=>[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=vu(()=>[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 x,E;const k=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){x=w;const T=y[x],$=T!==void 0?p[T]:void 0;E=$?$.end+this.options.gap:r+i}else{const T=this.options.lanes===1?p[v-1]:this.getFurthestMeasurement(p,v);E=T?T.end+this.options.gap:r+i,x=T?T.lane:v%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(v,x)}const R=d.get(_),A=typeof R=="number"?R:this.options.estimateSize(v),I=E+A;p[v]={index:v,start:E,size:A,end:I,key:_,lane:x},y[x]=v}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=vu(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?iye({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=vu(()=>{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=vu(()=>[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 sO(r[U4(0,r.length-1,i=>sO(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&&Gve(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 U4=(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 iye({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=U4(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 cO=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sye({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?id.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new rye(r));return i.setOptions(r),cO(()=>i._didMount(),[]),cO(()=>i._willUpdate()),i}function oye(e){return sye({observeElementRect:Jve,observeElementOffset:eye,scrollToFn:nye,...e})}function aye(e){return e.kind==="diff"}const lye=12e4;function uO(e){return e?e.replace(/\r\n?/gu,`
|