@dev-anywhere/relay 0.5.8 → 0.5.9
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.
|
@@ -497,7 +497,7 @@ ${t}`:e:t}function zb(e,t,n){const r=jg(t),i=jg(n);return!r&&!i?null:{kind:"diff
|
|
|
497
497
|
|
|
498
498
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
499
499
|
|
|
500
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},EJ="DialogDescriptionWarning",CJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${xI(EJ).contentName}}.`;return _.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},t1=cI,kJ=dI,n1=fI,r1=pI,i1=mI,EI=vI,CI=_I,s1=wI;function TJ(e){const t=_.useRef({value:e,previous:e});return _.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function RJ(e){const[t,n]=_.useState(void 0);return Ti(()=>{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 AJ=["top","right","bottom","left"],cl=Math.min,hs=Math.max,$g=Math.round,Im=Math.floor,Eo=e=>({x:e,y:e}),NJ={left:"right",right:"left",bottom:"top",top:"bottom"};function k0(e,t,n){return hs(e,cl(t,n))}function sa(e,t){return typeof e=="function"?e(t):e}function oa(e){return e.split("-")[0]}function sd(e){return e.split("-")[1]}function o1(e){return e==="x"?"y":"x"}function a1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function l1(e){return o1(So(e))}function MJ(e,t,n){n===void 0&&(n=!1);const r=sd(e),i=l1(e),s=a1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Hg(o)),[o,Hg(o)]}function OJ(e){const t=Hg(e);return[T0(e),t,T0(t)]}function T0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const vN=["left","right"],yN=["right","left"],DJ=["top","bottom"],PJ=["bottom","top"];function LJ(e,t,n){switch(e){case"top":case"bottom":return n?t?yN:vN:t?vN:yN;case"left":case"right":return t?DJ:PJ;default:return[]}}function IJ(e,t,n,r){const i=sd(e);let s=LJ(oa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(T0)))),s}function Hg(e){const t=oa(e);return NJ[t]+e.slice(t.length)}function zJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function kI(e){return typeof e!="number"?zJ(e):{top:e,right:e,bottom:e,left:e}}function Ug(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 _N(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=l1(t),l=a1(o),u=oa(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(sd(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 BJ(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}=sa(t,e),b=kI(v),x=l[y?p==="floating"?"reference":"floating":p],E=Ug(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,T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),N=await(s.isElement==null?void 0:s.isElement(T))?await(s.getScale==null?void 0:s.getScale(T))||{x:1,y:1}:{x:1,y:1},z=Ug(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:T,strategy:u}):k);return{top:(E.top-z.top+b.top)/N.y,bottom:(z.bottom-E.bottom+b.bottom)/N.y,left:(E.left-z.left+b.left)/N.x,right:(z.right-E.right+b.right)/N.x}}const jJ=50,FJ=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:BJ},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}=_N(d,r,u),y=r,v=0;const b={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:T,y:N,data:z,reset:R}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:b,rects:d,platform:l,elements:{reference:e,floating:t}});h=T??h,p=N??p,b[E]={...b[E],...z},R&&v<jJ&&(v++,typeof R=="object"&&(R.placement&&(y=R.placement),R.rects&&(d=R.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):R.rects),{x:h,y:p}=_N(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:b}},$J=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}=sa(e,t)||{};if(d==null)return{};const p=kI(h),y={x:n,y:r},v=l1(i),b=a1(v),w=await o.getDimensions(d),x=v==="y",E=x?"top":"left",k=x?"bottom":"right",T=x?"clientHeight":"clientWidth",N=s.reference[b]+s.reference[v]-y[v]-s.floating[b],z=y[v]-s.reference[v],R=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let F=R?R[T]:0;(!F||!await(o.isElement==null?void 0:o.isElement(R)))&&(F=l.floating[T]||s.floating[b]);const P=N/2-z/2,q=F/2-w[b]/2-1,H=cl(p[E],q),$=cl(p[k],q),D=H,M=F-w[b]-$,j=F/2-w[b]/2+P,L=k0(D,j,M),O=!u.arrow&&sd(i)!=null&&j!==L&&s.reference[b]/2-(j<D?H:$)-w[b]/2<0,Y=O?j<D?j-D:j-M:0;return{[v]:y[v]+Y,data:{[v]:L,centerOffset:j-L-Y,...O&&{alignmentOffset:Y}},reset:O}}}),HJ=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:b="none",flipAlignment:w=!0,...x}=sa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=oa(i),k=So(l),T=oa(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),z=y||(T||!w?[Hg(l)]:OJ(l)),R=b!=="none";!y&&R&&z.push(...IJ(l,w,b,N));const F=[l,...z],P=await u.detectOverflow(t,x),q=[];let H=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&q.push(P[E]),p){const j=MJ(i,o,N);q.push(P[j[0]],P[j[1]])}if(H=[...H,{placement:i,overflows:q}],!q.every(j=>j<=0)){var $,D;const j=((($=s.flip)==null?void 0:$.index)||0)+1,L=F[j];if(L&&(!(p==="alignment"?k!==So(L):!1)||H.every(K=>So(K.placement)===k?K.overflows[0]>0:!0)))return{data:{index:j,overflows:H},reset:{placement:L}};let O=(D=H.filter(Y=>Y.overflows[0]<=0).sort((Y,K)=>Y.overflows[1]-K.overflows[1])[0])==null?void 0:D.placement;if(!O)switch(v){case"bestFit":{var M;const Y=(M=H.filter(K=>{if(R){const U=So(K.placement);return U===k||U==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(U=>U>0).reduce((U,A)=>U+A,0)]).sort((K,U)=>K[1]-U[1])[0])==null?void 0:M[0];Y&&(O=Y);break}case"initialPlacement":O=l;break}if(i!==O)return{reset:{placement:O}}}return{}}}};function bN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function wN(e){return AJ.some(t=>e[t]>=0)}const UJ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=sa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=bN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:wN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=bN(o,n.floating);return{data:{escapedOffsets:l,escaped:wN(l)}}}default:return{}}}}},TI=new Set(["left","top"]);async function WJ(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=oa(n),l=sd(n),u=So(n)==="y",d=TI.has(o)?-1:1,h=s&&u?-1:1,p=sa(t,e);let{mainAxis:y,crossAxis:v,alignmentAxis:b}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof b=="number"&&(v=l==="end"?b*-1:b),u?{x:v*h,y:y*d}:{x:y*d,y:v*h}}const qJ=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 WJ(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}}}}},VJ=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:T}=E;return{x:k,y:T}}},...d}=sa(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=So(oa(i)),v=o1(y);let b=h[v],w=h[y];if(o){const E=v==="y"?"top":"left",k=v==="y"?"bottom":"right",T=b+p[E],N=b-p[k];b=k0(T,b,N)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[E],N=w-p[k];w=k0(T,w,N)}const x=u.fn({...t,[v]:b,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[v]:o,[y]:l}}}}}},YJ=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}=sa(e,t),h={x:n,y:r},p=So(i),y=o1(p);let v=h[y],b=h[p];const w=sa(l,t),x=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const T=y==="y"?"height":"width",N=s.reference[y]-s.floating[T]+x.mainAxis,z=s.reference[y]+s.reference[T]-x.mainAxis;v<N?v=N:v>z&&(v=z)}if(d){var E,k;const T=y==="y"?"width":"height",N=TI.has(oa(i)),z=s.reference[p]-s.floating[T]+(N&&((E=o.offset)==null?void 0:E[p])||0)+(N?0:x.crossAxis),R=s.reference[p]+s.reference[T]+(N?0:((k=o.offset)==null?void 0:k[p])||0)-(N?x.crossAxis:0);b<z?b=z:b>R&&(b=R)}return{[y]:v,[p]:b}}}},KJ=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}=sa(e,t),h=await o.detectOverflow(t,d),p=oa(i),y=sd(i),v=So(i)==="y",{width:b,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,T=b-h.left-h.right,N=cl(w-h[x],k),z=cl(b-h[E],T),R=!t.middlewareData.shift;let F=N,P=z;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(F=k),R&&!y){const H=hs(h.left,0),$=hs(h.right,0),D=hs(h.top,0),M=hs(h.bottom,0);v?P=b-2*(H!==0||$!==0?H+$:hs(h.left,h.right)):F=w-2*(D!==0||M!==0?D+M:hs(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:F});const q=await o.getDimensions(l.floating);return b!==q.width||w!==q.height?{reset:{rects:!0}}:{}}}};function Mv(){return typeof window<"u"}function od(e){return RI(e)?(e.nodeName||"").toLowerCase():"#document"}function fs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function No(e){var t;return(t=(RI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function RI(e){return Mv()?e instanceof Node||e instanceof fs(e).Node:!1}function Xs(e){return Mv()?e instanceof Element||e instanceof fs(e).Element:!1}function la(e){return Mv()?e instanceof HTMLElement||e instanceof fs(e).HTMLElement:!1}function SN(e){return!Mv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof fs(e).ShadowRoot}function If(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Zs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function GJ(e){return/^(table|td|th)$/.test(od(e))}function Ov(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const XJ=/transform|translate|scale|rotate|perspective|filter/,ZJ=/paint|layout|strict|content/,Wl=e=>!!e&&e!=="none";let qb;function c1(e){const t=Xs(e)?Zs(e):e;return Wl(t.transform)||Wl(t.translate)||Wl(t.scale)||Wl(t.rotate)||Wl(t.perspective)||!u1()&&(Wl(t.backdropFilter)||Wl(t.filter))||XJ.test(t.willChange||"")||ZJ.test(t.contain||"")}function QJ(e){let t=ul(e);for(;la(t)&&!Wu(t);){if(c1(t))return t;if(Ov(t))return null;t=ul(t)}return null}function u1(){return qb==null&&(qb=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),qb}function Wu(e){return/^(html|body|#document)$/.test(od(e))}function Zs(e){return fs(e).getComputedStyle(e)}function Dv(e){return Xs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ul(e){if(od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||SN(e)&&e.host||No(e);return SN(t)?t.host:t}function AI(e){const t=ul(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:la(t)&&If(t)?t:AI(t)}function ff(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=AI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=fs(i);if(s){const l=R0(o);return t.concat(o,o.visualViewport||[],If(i)?i:[],l&&n?ff(l):[])}else return t.concat(i,ff(i,[],n))}function R0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function NI(e){const t=Zs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=la(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=$g(n)!==s||$g(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function d1(e){return Xs(e)?e:e.contextElement}function Bu(e){const t=d1(e);if(!la(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=NI(t);let o=(s?$g(n.width):n.width)/r,l=(s?$g(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const JJ=Eo(0);function MI(e){const t=fs(e);return!u1()||!t.visualViewport?JJ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function eee(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==fs(e)?!1:t}function lc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=d1(e);let o=Eo(1);t&&(r?Xs(r)&&(o=Bu(r)):o=Bu(e));const l=eee(s,n,r)?MI(s):Eo(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,h=i.width/o.x,p=i.height/o.y;if(s){const y=fs(s),v=r&&Xs(r)?fs(r):r;let b=y,w=R0(b);for(;w&&r&&v!==b;){const x=Bu(w),E=w.getBoundingClientRect(),k=Zs(w),T=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,N=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=T,d+=N,b=fs(w),w=R0(b)}}return Ug({width:h,height:p,x:u,y:d})}function Pv(e,t){const n=Dv(e).scrollLeft;return t?t.left+n:lc(No(e)).left+n}function OI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Pv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function tee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Ov(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=Eo(1);const h=Eo(0),p=la(r);if((p||!p&&!s)&&((od(r)!=="body"||If(o))&&(u=Dv(r)),p)){const v=lc(r);d=Bu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?OI(o,u):Eo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function nee(e){return Array.from(e.getClientRects())}function ree(e){const t=No(e),n=Dv(e),r=e.ownerDocument.body,i=hs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=hs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Pv(e);const l=-n.scrollTop;return Zs(r).direction==="rtl"&&(o+=hs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const xN=25;function iee(e,t){const n=fs(e),r=No(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=u1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Pv(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,b=Math.abs(r.clientWidth-p.clientWidth-v);b<=xN&&(s-=b)}else d<=xN&&(s+=d);return{width:s,height:o,x:l,y:u}}function see(e,t){const n=lc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=la(e)?Bu(e):Eo(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function EN(e,t,n){let r;if(t==="viewport")r=iee(e,n);else if(t==="document")r=ree(No(e));else if(Xs(t))r=see(t,n);else{const i=MI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ug(r)}function DI(e,t){const n=ul(e);return n===t||!Xs(n)||Wu(n)?!1:Zs(n).position==="fixed"||DI(n,t)}function oee(e,t){const n=t.get(e);if(n)return n;let r=ff(e,[],!1).filter(l=>Xs(l)&&od(l)!=="body"),i=null;const s=Zs(e).position==="fixed";let o=s?ul(e):e;for(;Xs(o)&&!Wu(o);){const l=Zs(o),u=c1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||If(o)&&!u&&DI(e,o))?r=r.filter(h=>h!==o):i=l,o=ul(o)}return t.set(e,r),r}function aee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Ov(t)?[]:oee(t,this._c):[].concat(n),r],l=EN(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=EN(t,o[y],i);u=hs(v.top,u),d=cl(v.right,d),h=cl(v.bottom,h),p=hs(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function lee(e){const{width:t,height:n}=NI(e);return{width:t,height:n}}function cee(e,t,n){const r=la(t),i=No(t),s=n==="fixed",o=lc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=Eo(0);function d(){u.x=Pv(i)}if(r||!r&&!s)if((od(t)!=="body"||If(i))&&(l=Dv(t)),r){const v=lc(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?OI(i,l):Eo(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function Vb(e){return Zs(e).position==="static"}function CN(e,t){if(!la(e)||Zs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return No(e)===n&&(n=n.ownerDocument.body),n}function PI(e,t){const n=fs(e);if(Ov(e))return n;if(!la(e)){let i=ul(e);for(;i&&!Wu(i);){if(Xs(i)&&!Vb(i))return i;i=ul(i)}return n}let r=CN(e,t);for(;r&&GJ(r)&&Vb(r);)r=CN(r,t);return r&&Wu(r)&&Vb(r)&&!c1(r)?n:r||QJ(e)||n}const uee=async function(e){const t=this.getOffsetParent||PI,n=this.getDimensions,r=await n(e.floating);return{reference:cee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function dee(e){return Zs(e).direction==="rtl"}const hee={convertOffsetParentRelativeRectToViewportRelativeRect:tee,getDocumentElement:No,getClippingRect:aee,getOffsetParent:PI,getElementRects:uee,getClientRects:nee,getDimensions:lee,getScale:Bu,isElement:Xs,isRTL:dee};function LI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function fee(e,t){let n=null,r;const i=No(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:h,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const b=Im(p),w=Im(i.clientWidth-(h+y)),x=Im(i.clientHeight-(p+v)),E=Im(h),T={rootMargin:-b+"px "+-w+"px "+-x+"px "+-E+"px",threshold:hs(0,cl(1,u))||1};let N=!0;function z(R){const F=R[0].intersectionRatio;if(F!==u){if(!N)return o();F?o(!1,F):r=setTimeout(()=>{o(!1,1e-7)},1e3)}F===1&&!LI(d,e.getBoundingClientRect())&&o(),N=!1}try{n=new IntersectionObserver(z,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(z,T)}n.observe(e)}return o(!0),s}function pee(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=d1(e),h=i||s?[...d?ff(d):[],...t?ff(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?fee(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 T;(T=v)==null||T.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let b,w=u?lc(e):null;u&&x();function x(){const E=lc(e);w&&!LI(w,E)&&n(),w=E,b=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(b)}}const mee=qJ,gee=VJ,vee=HJ,yee=KJ,_ee=UJ,kN=$J,bee=YJ,wee=(e,t,n)=>{const r=new Map,i={platform:hee,...n},s={...i.platform,_c:r};return FJ(e,t,{...i,platform:s})};var See=typeof document<"u",xee=function(){},gg=See?_.useLayoutEffect:xee;function Wg(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(!Wg(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)&&!Wg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function II(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function TN(e,t){const n=II(e);return Math.round(t*n)/n}function Yb(e){const t=_.useRef(e);return gg(()=>{t.current=e}),t}function Eee(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]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=_.useState(r);Wg(y,r)||v(r);const[b,w]=_.useState(null),[x,E]=_.useState(null),k=_.useCallback(K=>{K!==R.current&&(R.current=K,w(K))},[]),T=_.useCallback(K=>{K!==F.current&&(F.current=K,E(K))},[]),N=s||b,z=o||x,R=_.useRef(null),F=_.useRef(null),P=_.useRef(h),q=u!=null,H=Yb(u),$=Yb(i),D=Yb(d),M=_.useCallback(()=>{if(!R.current||!F.current)return;const K={placement:t,strategy:n,middleware:y};$.current&&(K.platform=$.current),wee(R.current,F.current,K).then(U=>{const A={...U,isPositioned:D.current!==!1};j.current&&!Wg(P.current,A)&&(P.current=A,nd.flushSync(()=>{p(A)}))})},[y,t,n,$,D]);gg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[d]);const j=_.useRef(!1);gg(()=>(j.current=!0,()=>{j.current=!1}),[]),gg(()=>{if(N&&(R.current=N),z&&(F.current=z),N&&z){if(H.current)return H.current(N,z,M);M()}},[N,z,M,H,q]);const L=_.useMemo(()=>({reference:R,floating:F,setReference:k,setFloating:T}),[k,T]),O=_.useMemo(()=>({reference:N,floating:z}),[N,z]),Y=_.useMemo(()=>{const K={position:n,left:0,top:0};if(!O.floating)return K;const U=TN(O.floating,h.x),A=TN(O.floating,h.y);return l?{...K,transform:"translate("+U+"px, "+A+"px)",...II(O.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:A}},[n,l,O.floating,h.x,h.y]);return _.useMemo(()=>({...h,update:M,refs:L,elements:O,floatingStyles:Y}),[h,M,L,O,Y])}const Cee=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?kN({element:r.current,padding:i}).fn(n):{}:r?kN({element:r,padding:i}).fn(n):{}}}},kee=(e,t)=>{const n=mee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Tee=(e,t)=>{const n=gee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ree=(e,t)=>({fn:bee(e).fn,options:[e,t]}),Aee=(e,t)=>{const n=vee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Nee=(e,t)=>{const n=yee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Mee=(e,t)=>{const n=_ee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Oee=(e,t)=>{const n=Cee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Dee="Arrow",zI=_.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Qt.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"})})});zI.displayName=Dee;var Pee=zI,h1="Popper",[BI,bl]=aa(h1),[Lee,jI]=BI(h1),FI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return g.jsx(Lee,{scope:t,anchor:r,onAnchorChange:i,children:n})};FI.displayName=h1;var $I="PopperAnchor",HI=_.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=jI($I,n),o=_.useRef(null),l=Bn(t,o),u=_.useRef(null);return _.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(Qt.div,{...i,ref:l})});HI.displayName=$I;var f1="PopperContent",[Iee,zee]=BI(f1),UI=_.forwardRef((e,t)=>{var te,de,ve,xe,Re,ze;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:b,...w}=e,x=jI(f1,n),[E,k]=_.useState(null),T=Bn(t,Ye=>k(Ye)),[N,z]=_.useState(null),R=RJ(N),F=(R==null?void 0:R.width)??0,P=(R==null?void 0:R.height)??0,q=r+(s!=="center"?"-"+s:""),H=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},$=Array.isArray(d)?d:[d],D=$.length>0,M={padding:H,boundary:$.filter(jee),altBoundary:D},{refs:j,floatingStyles:L,placement:O,isPositioned:Y,middlewareData:K}=Eee({strategy:"fixed",placement:q,whileElementsMounted:(...Ye)=>pee(...Ye,{animationFrame:v==="always"}),elements:{reference:x.anchor},middleware:[kee({mainAxis:i+P,alignmentAxis:o}),u&&Tee({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Ree():void 0,...M}),u&&Aee({...M}),Nee({...M,apply:({elements:Ye,rects:mt,availableWidth:zt,availableHeight:ge})=>{const{width:he,height:Ve}=mt.reference,ce=Ye.floating.style;ce.setProperty("--radix-popper-available-width",`${zt}px`),ce.setProperty("--radix-popper-available-height",`${ge}px`),ce.setProperty("--radix-popper-anchor-width",`${he}px`),ce.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),N&&Oee({element:N,padding:l}),Fee({arrowWidth:F,arrowHeight:P}),y&&Mee({strategy:"referenceHidden",...M})]}),[U,A]=VI(O),W=To(b);Ti(()=>{Y&&(W==null||W())},[Y,W]);const G=(te=K.arrow)==null?void 0:te.x,I=(de=K.arrow)==null?void 0:de.y,ne=((ve=K.arrow)==null?void 0:ve.centerOffset)!==0,[ie,se]=_.useState();return Ti(()=>{E&&se(window.getComputedStyle(E).zIndex)},[E]),g.jsx("div",{ref:j.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:Y?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ie,"--radix-popper-transform-origin":[(xe=K.transformOrigin)==null?void 0:xe.x,(Re=K.transformOrigin)==null?void 0:Re.y].join(" "),...((ze=K.hide)==null?void 0:ze.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(Iee,{scope:n,placedSide:U,onArrowChange:z,arrowX:G,arrowY:I,shouldHideArrow:ne,children:g.jsx(Qt.div,{"data-side":U,"data-align":A,...w,ref:T,style:{...w.style,animation:Y?void 0:"none"}})})})});UI.displayName=f1;var WI="PopperArrow",Bee={top:"bottom",right:"left",bottom:"top",left:"right"},qI=_.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=zee(WI,r),o=Bee[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(Pee,{...i,ref:n,style:{...i.style,display:"block"}})})});qI.displayName=WI;function jee(e){return e!==null}var Fee=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]=VI(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 b="",w="";return d==="bottom"?(b=o?p:`${y}px`,w=`${-u}px`):d==="top"?(b=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(b=`${-u}px`,w=o?p:`${v}px`):d==="left"&&(b=`${r.floating.width+u}px`,w=o?p:`${v}px`),{data:{x:b,y:w}}}});function VI(e){const[t,n="center"]=e.split("-");return[t,n]}var Lv=FI,zf=HI,Iv=UI,zv=qI,Kb="rovingFocusGroup.onEntryFocus",$ee={bubbles:!1,cancelable:!0},Bf="RovingFocusGroup",[A0,YI,Hee]=Xx(Bf),[Uee,KI]=aa(Bf,[Hee]),[Wee,qee]=Uee(Bf),GI=_.forwardRef((e,t)=>g.jsx(A0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(A0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(Vee,{...e,ref:t})})}));GI.displayName=Bf;var Vee=_.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=_.useRef(null),v=Bn(t,y),b=Zx(s),[w,x]=oc({prop:o,defaultProp:l??null,onChange:u,caller:Bf}),[E,k]=_.useState(!1),T=To(d),N=YI(n),z=_.useRef(!1),[R,F]=_.useState(0);return _.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(Kb,T),()=>P.removeEventListener(Kb,T)},[T]),g.jsx(Wee,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:w,onItemFocus:_.useCallback(P=>x(P),[x]),onItemShiftTab:_.useCallback(()=>k(!0),[]),onFocusableItemAdd:_.useCallback(()=>F(P=>P+1),[]),onFocusableItemRemove:_.useCallback(()=>F(P=>P-1),[]),children:g.jsx(Qt.div,{tabIndex:E||R===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:vt(e.onMouseDown,()=>{z.current=!0}),onFocus:vt(e.onFocus,P=>{const q=!z.current;if(P.target===P.currentTarget&&q&&!E){const H=new CustomEvent(Kb,$ee);if(P.currentTarget.dispatchEvent(H),!H.defaultPrevented){const $=N().filter(O=>O.focusable),D=$.find(O=>O.active),M=$.find(O=>O.id===w),L=[D,M,...$].filter(Boolean).map(O=>O.ref.current);QI(L,h)}}z.current=!1}),onBlur:vt(e.onBlur,()=>k(!1))})})}),XI="RovingFocusGroupItem",ZI=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=qee(XI,n),p=h.currentTabStopId===d,y=YI(n),{onFocusableItemAdd:v,onFocusableItemRemove:b,currentTabStopId:w}=h;return _.useEffect(()=>{if(r)return v(),()=>b()},[r,v,b]),g.jsx(A0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Qt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:vt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:vt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:vt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=Gee(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let T=y().filter(N=>N.focusable).map(N=>N.ref.current);if(E==="last")T.reverse();else if(E==="prev"||E==="next"){E==="prev"&&T.reverse();const N=T.indexOf(x.currentTarget);T=h.loop?Xee(T,N+1):T.slice(N+1)}setTimeout(()=>QI(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});ZI.displayName=XI;var Yee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Kee(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Gee(e,t,n){const r=Kee(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Yee[r]}function QI(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Xee(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zee=GI,Qee=ZI,N0=["Enter"," "],Jee=["ArrowDown","PageUp","Home"],JI=["ArrowUp","PageDown","End"],ete=[...Jee,...JI],tte={ltr:[...N0,"ArrowRight"],rtl:[...N0,"ArrowLeft"]},nte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},jf="Menu",[pf,rte,ite]=Xx(jf),[bc,ez]=aa(jf,[ite,bl,KI]),Bv=bl(),tz=KI(),[ste,wc]=bc(jf),[ote,Ff]=bc(jf),nz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Bv(t),[u,d]=_.useState(null),h=_.useRef(!1),p=To(s),y=Zx(i);return _.useEffect(()=>{const v=()=>{h.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>h.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),g.jsx(Lv,{...l,children:g.jsx(ste,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(ote,{scope:t,onClose:_.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};nz.displayName=jf;var ate="MenuAnchor",p1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Bv(n);return g.jsx(zf,{...i,...r,ref:t})});p1.displayName=ate;var m1="MenuPortal",[lte,rz]=bc(m1,{forceMount:void 0}),iz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=wc(m1,t);return g.jsx(lte,{scope:t,forceMount:n,children:g.jsx(Bs,{present:n||s.open,children:g.jsx(id,{asChild:!0,container:i,children:r})})})};iz.displayName=m1;var Ds="MenuContent",[cte,g1]=bc(Ds),sz=_.forwardRef((e,t)=>{const n=rz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=Ff(Ds,e.__scopeMenu);return g.jsx(pf.Provider,{scope:e.__scopeMenu,children:g.jsx(Bs,{present:r||s.open,children:g.jsx(pf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(ute,{...i,ref:t}):g.jsx(dte,{...i,ref:t})})})})}),ute=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu),r=_.useRef(null),i=Bn(t,r);return _.useEffect(()=>{const s=r.current;if(s)return Av(s)},[]),g.jsx(v1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:vt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),dte=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu);return g.jsx(v1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),hte=ll("MenuContent.ScrollLock"),v1=_.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:b,...w}=e,x=wc(Ds,n),E=Ff(Ds,n),k=Bv(n),T=tz(n),N=rte(n),[z,R]=_.useState(null),F=_.useRef(null),P=Bn(t,F,x.onContentChange),q=_.useRef(0),H=_.useRef(""),$=_.useRef(0),D=_.useRef(null),M=_.useRef("right"),j=_.useRef(0),L=b?Lf:_.Fragment,O=b?{as:hte,allowPinchZoom:!0}:void 0,Y=U=>{var te,de;const A=H.current+U,W=N().filter(ve=>!ve.disabled),G=document.activeElement,I=(te=W.find(ve=>ve.ref.current===G))==null?void 0:te.textValue,ne=W.map(ve=>ve.textValue),ie=Ete(ne,A,I),se=(de=W.find(ve=>ve.textValue===ie))==null?void 0:de.ref.current;(function ve(xe){H.current=xe,window.clearTimeout(q.current),xe!==""&&(q.current=window.setTimeout(()=>ve(""),1e3))})(A),se&&setTimeout(()=>se.focus())};_.useEffect(()=>()=>window.clearTimeout(q.current),[]),Tv();const K=_.useCallback(U=>{var W,G;return M.current===((W=D.current)==null?void 0:W.side)&&kte(U,(G=D.current)==null?void 0:G.area)},[]);return g.jsx(cte,{scope:n,searchRef:H,onItemEnter:_.useCallback(U=>{K(U)&&U.preventDefault()},[K]),onItemLeave:_.useCallback(U=>{var A;K(U)||((A=F.current)==null||A.focus(),R(null))},[K]),onTriggerLeave:_.useCallback(U=>{K(U)&&U.preventDefault()},[K]),pointerGraceTimerRef:$,onPointerGraceIntentChange:_.useCallback(U=>{D.current=U},[]),children:g.jsx(L,{...O,children:g.jsx(Pf,{asChild:!0,trapped:i,onMountAutoFocus:vt(s,U=>{var A;U.preventDefault(),(A=F.current)==null||A.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(rd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Zee,{asChild:!0,...T,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:z,onCurrentTabStopIdChange:R,onEntryFocus:vt(u,U=>{E.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(Iv,{role:"menu","aria-orientation":"vertical","data-state":wz(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:vt(w.onKeyDown,U=>{const W=U.target.closest("[data-radix-menu-content]")===U.currentTarget,G=U.ctrlKey||U.altKey||U.metaKey,I=U.key.length===1;W&&(U.key==="Tab"&&U.preventDefault(),!G&&I&&Y(U.key));const ne=F.current;if(U.target!==ne||!ete.includes(U.key))return;U.preventDefault();const se=N().filter(te=>!te.disabled).map(te=>te.ref.current);JI.includes(U.key)&&se.reverse(),Ste(se)}),onBlur:vt(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(q.current),H.current="")}),onPointerMove:vt(e.onPointerMove,mf(U=>{const A=U.target,W=j.current!==U.clientX;if(U.currentTarget.contains(A)&&W){const G=U.clientX>j.current?"right":"left";M.current=G,j.current=U.clientX}}))})})})})})})});sz.displayName=Ds;var fte="MenuGroup",y1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Qt.div,{role:"group",...r,ref:t})});y1.displayName=fte;var pte="MenuLabel",oz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Qt.div,{...r,ref:t})});oz.displayName=pte;var qg="MenuItem",RN="menu.itemSelect",jv=_.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=_.useRef(null),o=Ff(qg,e.__scopeMenu),l=g1(qg,e.__scopeMenu),u=Bn(t,s),d=_.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(RN,{bubbles:!0,cancelable:!0});p.addEventListener(RN,v=>r==null?void 0:r(v),{once:!0}),YL(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(az,{...i,ref:u,disabled:n,onClick:vt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:vt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:vt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||N0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});jv.displayName=qg;var az=_.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=g1(qg,n),l=tz(n),u=_.useRef(null),d=Bn(t,u),[h,p]=_.useState(!1),[y,v]=_.useState("");return _.useEffect(()=>{const b=u.current;b&&v((b.textContent??"").trim())},[s.children]),g.jsx(pf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(Qee,{asChild:!0,...l,focusable:!r,children:g.jsx(Qt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:vt(e.onPointerMove,mf(b=>{r?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:vt(e.onPointerLeave,mf(b=>o.onItemLeave(b))),onFocus:vt(e.onFocus,()=>p(!0)),onBlur:vt(e.onBlur,()=>p(!1))})})})}),mte="MenuCheckboxItem",lz=_.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(fz,{scope:e.__scopeMenu,checked:n,children:g.jsx(jv,{role:"menuitemcheckbox","aria-checked":Vg(n)?"mixed":n,...i,ref:t,"data-state":b1(n),onSelect:vt(i.onSelect,()=>r==null?void 0:r(Vg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});lz.displayName=mte;var cz="MenuRadioGroup",[gte,vte]=bc(cz,{value:void 0,onValueChange:()=>{}}),uz=_.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return g.jsx(gte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(y1,{...i,ref:t})})});uz.displayName=cz;var dz="MenuRadioItem",hz=_.forwardRef((e,t)=>{const{value:n,...r}=e,i=vte(dz,e.__scopeMenu),s=n===i.value;return g.jsx(fz,{scope:e.__scopeMenu,checked:s,children:g.jsx(jv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":b1(s),onSelect:vt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});hz.displayName=dz;var _1="MenuItemIndicator",[fz,yte]=bc(_1,{checked:!1}),pz=_.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=yte(_1,n);return g.jsx(Bs,{present:r||Vg(s.checked)||s.checked===!0,children:g.jsx(Qt.span,{...i,ref:t,"data-state":b1(s.checked)})})});pz.displayName=_1;var _te="MenuSeparator",mz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Qt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});mz.displayName=_te;var bte="MenuArrow",gz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Bv(n);return g.jsx(zv,{...i,...r,ref:t})});gz.displayName=bte;var wte="MenuSub",[_Te,vz]=bc(wte),Ph="MenuSubTrigger",yz=_.forwardRef((e,t)=>{const n=wc(Ph,e.__scopeMenu),r=Ff(Ph,e.__scopeMenu),i=vz(Ph,e.__scopeMenu),s=g1(Ph,e.__scopeMenu),o=_.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=_.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return _.useEffect(()=>h,[h]),_.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),g.jsx(p1,{asChild:!0,...d,children:g.jsx(az,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":wz(n.open),...e,ref:ia(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:vt(e.onPointerMove,mf(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:vt(e.onPointerLeave,mf(p=>{var v,b;h();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(b=n.content)==null?void 0:b.dataset.side,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],T=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,y:p.clientY},{x:k,y:y.top},{x:T,y:y.top},{x:T,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:vt(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||tte[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});yz.displayName=Ph;var _z="MenuSubContent",bz=_.forwardRef((e,t)=>{const n=rz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=Ff(Ds,e.__scopeMenu),l=vz(_z,e.__scopeMenu),u=_.useRef(null),d=Bn(t,u);return g.jsx(pf.Provider,{scope:e.__scopeMenu,children:g.jsx(Bs,{present:r||s.open,children:g.jsx(pf.Slot,{scope:e.__scopeMenu,children:g.jsx(v1,{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:vt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:vt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:vt(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())})})})})})});bz.displayName=_z;function wz(e){return e?"open":"closed"}function Vg(e){return e==="indeterminate"}function b1(e){return Vg(e)?"indeterminate":e?"checked":"unchecked"}function Ste(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function xte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Ete(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=xte(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 Cte(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 kte(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Cte(n,t)}function mf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Tte=nz,Rte=p1,Ate=iz,Nte=sz,Mte=y1,Ote=oz,Dte=jv,Pte=lz,Lte=uz,Ite=hz,zte=pz,Bte=mz,jte=gz,Fte=yz,$te=bz,Fv="DropdownMenu",[Hte]=aa(Fv,[ez]),ji=ez(),[Ute,Sz]=Hte(Fv),xz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=ji(t),d=_.useRef(null),[h,p]=oc({prop:i,defaultProp:s??!1,onChange:o,caller:Fv});return g.jsx(Ute,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:_.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(Tte,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};xz.displayName=Fv;var Ez="DropdownMenuTrigger",Cz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Sz(Ez,n),o=ji(n);return g.jsx(Rte,{asChild:!0,...o,children:g.jsx(Qt.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:ia(t,s.triggerRef),onPointerDown:vt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:vt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Cz.displayName=Ez;var Wte="DropdownMenuPortal",kz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=ji(t);return g.jsx(Ate,{...r,...n})};kz.displayName=Wte;var Tz="DropdownMenuContent",Rz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Sz(Tz,n),s=ji(n),o=_.useRef(!1);return g.jsx(Nte,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:vt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:vt(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)"}})});Rz.displayName=Tz;var qte="DropdownMenuGroup",Vte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Mte,{...i,...r,ref:t})});Vte.displayName=qte;var Yte="DropdownMenuLabel",Az=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Ote,{...i,...r,ref:t})});Az.displayName=Yte;var Kte="DropdownMenuItem",Nz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Dte,{...i,...r,ref:t})});Nz.displayName=Kte;var Gte="DropdownMenuCheckboxItem",Mz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Pte,{...i,...r,ref:t})});Mz.displayName=Gte;var Xte="DropdownMenuRadioGroup",Zte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Lte,{...i,...r,ref:t})});Zte.displayName=Xte;var Qte="DropdownMenuRadioItem",Jte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Ite,{...i,...r,ref:t})});Jte.displayName=Qte;var ene="DropdownMenuItemIndicator",Oz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(zte,{...i,...r,ref:t})});Oz.displayName=ene;var tne="DropdownMenuSeparator",Dz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Bte,{...i,...r,ref:t})});Dz.displayName=tne;var nne="DropdownMenuArrow",rne=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(jte,{...i,...r,ref:t})});rne.displayName=nne;var ine="DropdownMenuSubTrigger",sne=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Fte,{...i,...r,ref:t})});sne.displayName=ine;var one="DropdownMenuSubContent",ane=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx($te,{...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)"}})});ane.displayName=one;var lne=xz,cne=Cz,une=kz,dne=Rz,hne=Az,fne=Nz,pne=Mz,mne=Oz,gne=Dz;function AN(e,[t,n]){return Math.min(n,Math.max(t,e))}var $v="Popover",[Pz]=aa($v,[bl]),$f=bl(),[vne,wl]=Pz($v),Lz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=$f(t),u=_.useRef(null),[d,h]=_.useState(!1),[p,y]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:$v});return g.jsx(Lv,{...l,children:g.jsx(vne,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:_.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:o,children:n})})};Lz.displayName=$v;var Iz="PopoverAnchor",yne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Iz,n),s=$f(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return _.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(zf,{...s,...r,ref:t})});yne.displayName=Iz;var zz="PopoverTrigger",Bz=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(zz,n),s=$f(n),o=Bn(t,i.triggerRef),l=g.jsx(Qt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Uz(i.open),...r,ref:o,onClick:vt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(zf,{asChild:!0,...s,children:l})});Bz.displayName=zz;var w1="PopoverPortal",[_ne,bne]=Pz(w1,{forceMount:void 0}),jz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=wl(w1,t);return g.jsx(_ne,{scope:t,forceMount:n,children:g.jsx(Bs,{present:n||s.open,children:g.jsx(id,{asChild:!0,container:i,children:r})})})};jz.displayName=w1;var qu="PopoverContent",Fz=_.forwardRef((e,t)=>{const n=bne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=wl(qu,e.__scopePopover);return g.jsx(Bs,{present:r||s.open,children:s.modal?g.jsx(Sne,{...i,ref:t}):g.jsx(xne,{...i,ref:t})})});Fz.displayName=qu;var wne=ll("PopoverContent.RemoveScroll"),Sne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(null),i=Bn(t,r),s=_.useRef(!1);return _.useEffect(()=>{const o=r.current;if(o)return Av(o)},[]),g.jsx(Lf,{as:wne,allowPinchZoom:!0,children:g.jsx($z,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:vt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:vt(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:vt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),xne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return g.jsx($z,{...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()}})}),$z=_.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=wl(qu,n),v=$f(n);return Tv(),g.jsx(Pf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(rd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(Iv,{"data-state":Uz(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)"}})})})}),Hz="PopoverClose",Ene=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Hz,n);return g.jsx(Qt.button,{type:"button",...r,ref:t,onClick:vt(e.onClick,()=>i.onOpenChange(!1))})});Ene.displayName=Hz;var Cne="PopoverArrow",kne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$f(n);return g.jsx(zv,{...i,...r,ref:t})});kne.displayName=Cne;function Uz(e){return e?"open":"closed"}var Tne=Lz,Rne=Bz,Ane=jz,Nne=Fz,Mne=[" ","Enter","ArrowUp","ArrowDown"],One=[" ","Enter"],cc="Select",[Hv,Uv,Dne]=Xx(cc),[ad]=aa(cc,[Dne,bl]),Wv=bl(),[Pne,Sl]=ad(cc),[Lne,Ine]=ad(cc),Wz=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:b}=e,w=Wv(t),[x,E]=_.useState(null),[k,T]=_.useState(null),[N,z]=_.useState(!1),R=Zx(d),[F,P]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:cc}),[q,H]=oc({prop:o,defaultProp:l,onChange:u,caller:cc}),$=_.useRef(null),D=x?b||!!x.closest("form"):!0,[M,j]=_.useState(new Set),L=Array.from(M).map(O=>O.props.value).join(";");return g.jsx(Lv,{...w,children:g.jsxs(Pne,{required:v,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:N,onValueNodeHasChildrenChange:z,contentId:gi(),value:q,onValueChange:H,open:F,onOpenChange:P,dir:R,triggerPointerDownPosRef:$,disabled:y,children:[g.jsx(Hv.Provider,{scope:t,children:g.jsx(Lne,{scope:e.__scopeSelect,onNativeOptionAdd:_.useCallback(O=>{j(Y=>new Set(Y).add(O))},[]),onNativeOptionRemove:_.useCallback(O=>{j(Y=>{const K=new Set(Y);return K.delete(O),K})},[]),children:n})}),D?g.jsxs(hB,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:q,onChange:O=>H(O.target.value),disabled:y,form:b,children:[q===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};Wz.displayName=cc;var qz="SelectTrigger",Vz=_.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Wv(n),o=Sl(qz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Uv(n),h=_.useRef("touch"),[p,y,v]=pB(w=>{const x=d().filter(T=>!T.disabled),E=x.find(T=>T.value===o.value),k=mB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),b=w=>{l||(o.onOpenChange(!0),v()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return g.jsx(zf,{asChild:!0,...s,children:g.jsx(Qt.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":fB(o.value)?"":void 0,...i,ref:u,onClick:vt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&b(w)}),onPointerDown:vt(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"&&(b(w),w.preventDefault())}),onKeyDown:vt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&Mne.includes(w.key)&&(b(),w.preventDefault())})})})});Vz.displayName=qz;var Yz="SelectValue",Kz=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=Sl(Yz,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ti(()=>{d(h)},[d,h]),g.jsx(Qt.span,{...l,ref:p,style:{pointerEvents:"none"},children:fB(u.value)?g.jsx(g.Fragment,{children:o}):s})});Kz.displayName=Yz;var zne="SelectIcon",Gz=_.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Qt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});Gz.displayName=zne;var Bne="SelectPortal",Xz=e=>g.jsx(id,{asChild:!0,...e});Xz.displayName=Bne;var uc="SelectContent",Zz=_.forwardRef((e,t)=>{const n=Sl(uc,e.__scopeSelect),[r,i]=_.useState();if(Ti(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?nd.createPortal(g.jsx(Qz,{scope:e.__scopeSelect,children:g.jsx(Hv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(Jz,{...e,ref:t})});Zz.displayName=uc;var qs=10,[Qz,xl]=ad(uc),jne="SelectContentImpl",Fne=ll("SelectContent.RemoveScroll"),Jz=_.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:b,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=Sl(uc,n),[T,N]=_.useState(null),[z,R]=_.useState(null),F=Bn(t,te=>N(te)),[P,q]=_.useState(null),[H,$]=_.useState(null),D=Uv(n),[M,j]=_.useState(!1),L=_.useRef(!1);_.useEffect(()=>{if(T)return Av(T)},[T]),Tv();const O=_.useCallback(te=>{const[de,...ve]=D().map(ze=>ze.ref.current),[xe]=ve.slice(-1),Re=document.activeElement;for(const ze of te)if(ze===Re||(ze==null||ze.scrollIntoView({block:"nearest"}),ze===de&&z&&(z.scrollTop=0),ze===xe&&z&&(z.scrollTop=z.scrollHeight),ze==null||ze.focus(),document.activeElement!==Re))return},[D,z]),Y=_.useCallback(()=>O([P,T]),[O,P,T]);_.useEffect(()=>{M&&Y()},[M,Y]);const{onOpenChange:K,triggerPointerDownPosRef:U}=k;_.useEffect(()=>{if(T){let te={x:0,y:0};const de=xe=>{var Re,ze;te={x:Math.abs(Math.round(xe.pageX)-(((Re=U.current)==null?void 0:Re.x)??0)),y:Math.abs(Math.round(xe.pageY)-(((ze=U.current)==null?void 0:ze.y)??0))}},ve=xe=>{te.x<=10&&te.y<=10?xe.preventDefault():T.contains(xe.target)||K(!1),document.removeEventListener("pointermove",de),U.current=null};return U.current!==null&&(document.addEventListener("pointermove",de),document.addEventListener("pointerup",ve,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",de),document.removeEventListener("pointerup",ve,{capture:!0})}}},[T,K,U]),_.useEffect(()=>{const te=()=>K(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[K]);const[A,W]=pB(te=>{const de=D().filter(Re=>!Re.disabled),ve=de.find(Re=>Re.ref.current===document.activeElement),xe=mB(de,te,ve);xe&&setTimeout(()=>xe.ref.current.focus())}),G=_.useCallback((te,de,ve)=>{const xe=!L.current&&!ve;(k.value!==void 0&&k.value===de||xe)&&(q(te),xe&&(L.current=!0))},[k.value]),I=_.useCallback(()=>T==null?void 0:T.focus(),[T]),ne=_.useCallback((te,de,ve)=>{const xe=!L.current&&!ve;(k.value!==void 0&&k.value===de||xe)&&$(te)},[k.value]),ie=r==="popper"?M0:eB,se=ie===M0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:b,hideWhenDetached:w,avoidCollisions:x}:{};return g.jsx(Qz,{scope:n,content:T,viewport:z,onViewportChange:R,itemRefCallback:G,selectedItem:P,onItemLeave:I,itemTextRefCallback:ne,focusSelectedItem:Y,selectedItemText:H,position:r,isPositioned:M,searchRef:A,children:g.jsx(Lf,{as:Fne,allowPinchZoom:!0,children:g.jsx(Pf,{asChild:!0,trapped:k.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:vt(i,te=>{var de;(de=k.trigger)==null||de.focus({preventScroll:!0}),te.preventDefault()}),children:g.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(ie,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:te=>te.preventDefault(),...E,...se,onPlaced:()=>j(!0),ref:F,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:vt(E.onKeyDown,te=>{const de=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!de&&te.key.length===1&&W(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let xe=D().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);if(["ArrowUp","End"].includes(te.key)&&(xe=xe.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const Re=te.target,ze=xe.indexOf(Re);xe=xe.slice(ze+1)}setTimeout(()=>O(xe)),te.preventDefault()}})})})})})})});Jz.displayName=jne;var $ne="SelectItemAlignedPosition",eB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=Sl(uc,n),o=xl(uc,n),[l,u]=_.useState(null),[d,h]=_.useState(null),p=Bn(t,F=>h(F)),y=Uv(n),v=_.useRef(!1),b=_.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,T=_.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const F=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),q=s.valueNode.getBoundingClientRect(),H=E.getBoundingClientRect();if(s.dir!=="rtl"){const Re=H.left-P.left,ze=q.left-Re,Ye=F.left-ze,mt=F.width+Ye,zt=Math.max(mt,P.width),ge=window.innerWidth-qs,he=AN(ze,[qs,Math.max(qs,ge-zt)]);l.style.minWidth=mt+"px",l.style.left=he+"px"}else{const Re=P.right-H.right,ze=window.innerWidth-q.right-Re,Ye=window.innerWidth-F.right-ze,mt=F.width+Ye,zt=Math.max(mt,P.width),ge=window.innerWidth-qs,he=AN(ze,[qs,Math.max(qs,ge-zt)]);l.style.minWidth=mt+"px",l.style.right=he+"px"}const $=y(),D=window.innerHeight-qs*2,M=w.scrollHeight,j=window.getComputedStyle(d),L=parseInt(j.borderTopWidth,10),O=parseInt(j.paddingTop,10),Y=parseInt(j.borderBottomWidth,10),K=parseInt(j.paddingBottom,10),U=L+O+M+K+Y,A=Math.min(x.offsetHeight*5,U),W=window.getComputedStyle(w),G=parseInt(W.paddingTop,10),I=parseInt(W.paddingBottom,10),ne=F.top+F.height/2-qs,ie=D-ne,se=x.offsetHeight/2,te=x.offsetTop+se,de=L+O+te,ve=U-de;if(de<=ne){const Re=$.length>0&&x===$[$.length-1].ref.current;l.style.bottom="0px";const ze=d.clientHeight-w.offsetTop-w.offsetHeight,Ye=Math.max(ie,se+(Re?I:0)+ze+Y),mt=de+Ye;l.style.height=mt+"px"}else{const Re=$.length>0&&x===$[0].ref.current;l.style.top="0px";const Ye=Math.max(ne,L+w.offsetTop+(Re?G:0)+se)+ve;l.style.height=Ye+"px",w.scrollTop=de-ne+w.offsetTop}l.style.margin=`${qs}px 0`,l.style.minHeight=A+"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]);Ti(()=>T(),[T]);const[N,z]=_.useState();Ti(()=>{d&&z(window.getComputedStyle(d).zIndex)},[d]);const R=_.useCallback(F=>{F&&b.current===!0&&(T(),k==null||k(),b.current=!1)},[T,k]);return g.jsx(Une,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:R,children:g.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:g.jsx(Qt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});eB.displayName=$ne;var Hne="SelectPopperPosition",M0=_.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=qs,...s}=e,o=Wv(n);return g.jsx(Iv,{...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)"}})});M0.displayName=Hne;var[Une,S1]=ad(uc,{}),O0="SelectViewport",tB=_.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=xl(O0,n),o=S1(O0,n),l=Bn(t,s.onViewportChange),u=_.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(Hv.Slot,{scope:n,children:g.jsx(Qt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:vt(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 b=window.innerHeight-qs*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<b){const k=E+v,T=Math.min(b,k),N=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(h.scrollTop=N>0?N:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});tB.displayName=O0;var nB="SelectGroup",[Wne,qne]=ad(nB),Vne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return g.jsx(Wne,{scope:n,id:i,children:g.jsx(Qt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});Vne.displayName=nB;var rB="SelectLabel",Yne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qne(rB,n);return g.jsx(Qt.div,{id:i.id,...r,ref:t})});Yne.displayName=rB;var Yg="SelectItem",[Kne,iB]=ad(Yg),sB=_.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=Sl(Yg,n),u=xl(Yg,n),d=l.value===r,[h,p]=_.useState(s??""),[y,v]=_.useState(!1),b=Bn(t,k=>{var T;return(T=u.itemRefCallback)==null?void 0:T.call(u,k,r,i)}),w=gi(),x=_.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(Kne,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:_.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:g.jsx(Hv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Qt.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:b,onFocus:vt(o.onFocus,()=>v(!0)),onBlur:vt(o.onBlur,()=>v(!1)),onClick:vt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:vt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:vt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:vt(o.onPointerMove,k=>{var T;x.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:vt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:vt(o.onKeyDown,k=>{var N;((N=u.searchRef)==null?void 0:N.current)!==""&&k.key===" "||(One.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});sB.displayName=Yg;var Lh="SelectItemText",oB=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Sl(Lh,n),l=xl(Lh,n),u=iB(Lh,n),d=Ine(Lh,n),[h,p]=_.useState(null),y=Bn(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 Ti(()=>(w(b),()=>x(b)),[w,x,b]),g.jsxs(g.Fragment,{children:[g.jsx(Qt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?nd.createPortal(s.children,o.valueNode):null]})});oB.displayName=Lh;var aB="SelectItemIndicator",lB=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return iB(aB,n).isSelected?g.jsx(Qt.span,{"aria-hidden":!0,...r,ref:t}):null});lB.displayName=aB;var D0="SelectScrollUpButton",cB=_.forwardRef((e,t)=>{const n=xl(D0,e.__scopeSelect),r=S1(D0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{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(dB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});cB.displayName=D0;var P0="SelectScrollDownButton",uB=_.forwardRef((e,t)=>{const n=xl(P0,e.__scopeSelect),r=S1(P0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{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(dB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});uB.displayName=P0;var dB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=xl("SelectScrollButton",n),o=_.useRef(null),l=Uv(n),u=_.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return _.useEffect(()=>()=>u(),[u]),Ti(()=>{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(Qt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:vt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:vt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:vt(i.onPointerLeave,()=>{u()})})}),Gne="SelectSeparator",Xne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Qt.div,{"aria-hidden":!0,...r,ref:t})});Xne.displayName=Gne;var L0="SelectArrow",Zne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Wv(n),s=Sl(L0,n),o=xl(L0,n);return s.open&&o.position==="popper"?g.jsx(zv,{...i,...r,ref:t}):null});Zne.displayName=L0;var Qne="SelectBubbleInput",hB=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=_.useRef(null),s=Bn(r,i),o=TJ(t);return _.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(Qt.select,{...n,style:{...KL,...n.style},ref:s,defaultValue:t})});hB.displayName=Qne;function fB(e){return e===""||e===void 0}function pB(e){const t=To(e),n=_.useRef(""),r=_.useRef(0),i=_.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=_.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return _.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function mB(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Jne(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 Jne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ere=Wz,tre=Vz,nre=Kz,rre=Gz,ire=Xz,sre=Zz,ore=tB,are=sB,lre=oB,cre=lB,ure=cB,dre=uB,[qv]=aa("Tooltip",[bl]),Vv=bl(),gB="TooltipProvider",hre=700,I0="tooltip.open",[fre,x1]=qv(gB),vB=e=>{const{__scopeTooltip:t,delayDuration:n=hre,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=_.useRef(!0),l=_.useRef(!1),u=_.useRef(0);return _.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),g.jsx(fre,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:_.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};vB.displayName=gB;var gf="Tooltip",[pre,Hf]=qv(gf),yB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=x1(gf,e.__scopeTooltip),d=Vv(t),[h,p]=_.useState(null),y=gi(),v=_.useRef(0),b=o??u.disableHoverableContent,w=l??u.delayDuration,x=_.useRef(!1),[E,k]=oc({prop:r,defaultProp:i??!1,onChange:F=>{F?(u.onOpen(),document.dispatchEvent(new CustomEvent(I0))):u.onClose(),s==null||s(F)},caller:gf}),T=_.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),N=_.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,k(!0)},[k]),z=_.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),R=_.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,k(!0),v.current=0},w)},[w,k]);return _.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Lv,{...d,children:g.jsx(pre,{scope:t,contentId:y,open:E,stateAttribute:T,trigger:h,onTriggerChange:p,onTriggerEnter:_.useCallback(()=>{u.isOpenDelayedRef.current?R():N()},[u.isOpenDelayedRef,R,N]),onTriggerLeave:_.useCallback(()=>{b?z():(window.clearTimeout(v.current),v.current=0)},[z,b]),onOpen:N,onClose:z,disableHoverableContent:b,children:n})})};yB.displayName=gf;var z0="TooltipTrigger",_B=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Hf(z0,n),s=x1(z0,n),o=Vv(n),l=_.useRef(null),u=Bn(t,l,i.onTriggerChange),d=_.useRef(!1),h=_.useRef(!1),p=_.useCallback(()=>d.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),g.jsx(zf,{asChild:!0,...o,children:g.jsx(Qt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:vt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:vt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:vt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:vt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:vt(e.onBlur,i.onClose),onClick:vt(e.onClick,i.onClose)})})});_B.displayName=z0;var E1="TooltipPortal",[mre,gre]=qv(E1,{forceMount:void 0}),bB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Hf(E1,t);return g.jsx(mre,{scope:t,forceMount:n,children:g.jsx(Bs,{present:n||s.open,children:g.jsx(id,{asChild:!0,container:i,children:r})})})};bB.displayName=E1;var Vu="TooltipContent",wB=_.forwardRef((e,t)=>{const n=gre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Hf(Vu,e.__scopeTooltip);return g.jsx(Bs,{present:r||o.open,children:o.disableHoverableContent?g.jsx(SB,{side:i,...s,ref:t}):g.jsx(vre,{side:i,...s,ref:t})})}),vre=_.forwardRef((e,t)=>{const n=Hf(Vu,e.__scopeTooltip),r=x1(Vu,e.__scopeTooltip),i=_.useRef(null),s=Bn(t,i),[o,l]=_.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=_.useCallback(()=>{l(null),p(!1)},[p]),v=_.useCallback((b,w)=>{const x=b.currentTarget,E={x:b.clientX,y:b.clientY},k=wre(E,x.getBoundingClientRect()),T=Sre(E,k),N=xre(w.getBoundingClientRect()),z=Cre([...T,...N]);l(z),p(!0)},[p]);return _.useEffect(()=>()=>y(),[y]),_.useEffect(()=>{if(u&&h){const b=x=>v(x,h),w=x=>v(x,u);return u.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[u,h,v,y]),_.useEffect(()=>{if(o){const b=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)),T=!Ere(E,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[u,h,o,d,y]),g.jsx(SB,{...e,ref:s})}),[yre,_re]=qv(gf,{isInside:!1}),bre=JZ("TooltipContent"),SB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Hf(Vu,n),d=Vv(n),{onClose:h}=u;return _.useEffect(()=>(document.addEventListener(I0,h),()=>document.removeEventListener(I0,h)),[h]),_.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(rd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(Iv,{"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(bre,{children:r}),g.jsx(yre,{scope:n,isInside:!0,children:g.jsx(XL,{id:u.contentId,role:"tooltip",children:i||r})})]})})});wB.displayName=Vu;var xB="TooltipArrow",EB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Vv(n);return _re(xB,n).isInside?null:g.jsx(zv,{...i,...r,ref:t})});EB.displayName=xB;function wre(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 Sre(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 xre(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 Ere(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 Cre(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),kre(t)}function kre(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 Tre=vB,Rre=yB,Are=_B,Nre=bB,Mre=wB,Ore=EB;function C1({...e}){return g.jsx(Tne,{"data-slot":"popover",...e})}function k1({...e}){return g.jsx(Rne,{"data-slot":"popover-trigger",...e})}function T1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(Ane,{children:g.jsx(Nne,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const Dre={"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 nc({variant:e,action:t}){const{heading:n,body:r}=Dre[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 Pre={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Lre={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function NN({status:e,className:t}){return g.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Pre[e],t),role:"status","aria-label":Lre[e]})}function CB({layout:e,variant:t="default"}){const n=Ie(w=>w.proxies),r=Ie(w=>w.proxyListLoaded),i=Ie(w=>w.relayClientAuthIssue),s=Ie(w=>w.selectedProxyId),o=Bi(),l=Js(),[u,d]=_.useState(!1),[h,p]=_.useState(null);async function y(w,x){if(h)return;const E=Ot;if(!E){rt.error("请先连接开发机");return}const k=x??w;p(w);try{const T=await E.selectProxy(w);if(!T.success){rt.error(`无法连接 ${k}:${T.error??"未知错误"}`);return}dr("local",ln.proxyId,w),Ie.getState().setProxy(w,x??null),Ie.getState().setProxyOnline(!0),Ie.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestAgentStatuses().then(N=>{const z=qt.getState();for(const R of N)z.setAgentStatus(R.sessionId,R.payload)}).catch(N=>{console.error("[proxy-switcher] post-bind data fetch failed",N)}),E.requestSessionHistory().then(N=>qt.getState().setHistorySessions(N)).catch(N=>{console.error("[proxy-switcher] post-bind data fetch failed",N)}),d(!1),(e==="page"||o.pathname.startsWith("/chat/"))&&l("/sessions")}catch(T){const N=T instanceof Error?T.message:"未知错误";rt.error(`无法连接 ${k}:${N}`)}finally{p(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(nc,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(nc,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(nc,{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(w=>{const x=h===w.proxyId,E=h!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",x?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx(NN,{status:w.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),g.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===w.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&!x&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.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(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});const v=n.find(w=>w.proxyId===s),b=(v==null?void 0:v.name)??(v==null?void 0:v.proxyId)??"未选择开发机";return g.jsxs(C1,{open:u,onOpenChange:d,children:[g.jsx(k1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${b}`,children:[t==="default"&&g.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),g.jsx("span",{className:We("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:b}),g.jsx(gl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(T1,{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(w=>{const x=h===w.proxyId,E=h!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",x?"bg-accent text-accent-foreground":"hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线",children:[g.jsx(NN,{status:w.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?g.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===w.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&s!==w.proxyId&&!x&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})})]})}const MN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,ON=OP,Ire=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return ON(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=MN(h)||MN(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(b=>{let[w,x]=b;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return ON(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},zre=Ire("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 St({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?ZZ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(zre({variant:t,size:n,className:e})),...i})}function Bre({delayDuration:e=0,...t}){return g.jsx(Tre,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Uf({...e}){return g.jsx(Rre,{"data-slot":"tooltip",...e})}function Wf({...e}){return g.jsx(Are,{"data-slot":"tooltip-trigger",...e})}function qf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(Nre,{children:g.jsxs(Mre,{"data-slot":"tooltip-content",sideOffset:t,className:We("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&g.jsx(Ore,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Yv({...e}){return g.jsx(t1,{"data-slot":"sheet",...e})}function jre({...e}){return g.jsx(kJ,{"data-slot":"sheet-trigger",...e})}function Fre({...e}){return g.jsx(n1,{"data-slot":"sheet-portal",...e})}function $re({className:e,...t}){return g.jsx(r1,{"data-slot":"sheet-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Kv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return g.jsxs(Fre,{children:[g.jsx($re,{className:t}),g.jsxs(i1,{"data-slot":"sheet-content",className:We("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&g.jsxs(s1,{"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(Df,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function R1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function Gv({className:e,...t}){return g.jsx(EI,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Hre({className:e,...t}){return g.jsx(CI,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}function A1({...e}){return g.jsx(lne,{"data-slot":"dropdown-menu",...e})}function N1({...e}){return g.jsx(cne,{"data-slot":"dropdown-menu-trigger",...e})}function M1({className:e,sideOffset:t=4,...n}){return g.jsx(une,{children:g.jsx(dne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function bo({className:e,inset:t,variant:n="default",...r}){return g.jsx(fne,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Gb({className:e,children:t,checked:n,...r}){return g.jsxs(pne,{"data-slot":"dropdown-menu-checkbox-item",className:We("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[g.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:g.jsx(mne,{children:g.jsx(ra,{className:"size-4"})})}),t]})}function zm({className:e,inset:t,...n}){return g.jsx(hne,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Xb({className:e,...t}){return g.jsx(gne,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}const Ure={claude:"Claude Code",codex:"Codex"},DN=["claude","codex"];function Xv(e){return Ure[e]}function kB(e,t){return DN.indexOf(e)-DN.indexOf(t)}function B0(e){return e.provider??"claude"}const j0=60*1e3,F0=60*j0,Wre=24*F0;function TB(e,t=Date.now()){const n=t-e;if(n<j0)return"刚刚";if(n<F0)return`${Math.floor(n/j0)} 分钟前`;if(n<Wre)return`${Math.floor(n/F0)} 小时前`;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 PN={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 $0(e){return e.kind!=="terminal"?PN[e.state]:e.state==="terminated"?PN.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 qre({session:e}){const t=$0(e);return g.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Vre({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Rx:Nx;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 Yre({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Cv(e.name),d=Yx(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?TB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",b=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:We("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&g.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),g.jsxs("button",{type:"button",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[g.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[g.jsx(qre,{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(Vre,{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:Xv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:We("shrink-0",$0(e).text),children:$0(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(A1,{children:[g.jsx(N1,{asChild:!0,children:g.jsx(St,{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(t8,{"aria-hidden":"true"})})}),g.jsxs(M1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(bo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(bo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:b})]})]})]})}function Sc({...e}){return g.jsx(t1,{"data-slot":"dialog",...e})}function Kre({...e}){return g.jsx(n1,{"data-slot":"dialog-portal",...e})}function Gre({className:e,...t}){return g.jsx(r1,{"data-slot":"dialog-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function xc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs(Kre,{"data-slot":"dialog-portal",children:[g.jsx(Gre,{}),g.jsxs(i1,{"data-slot":"dialog-content",className:We("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&g.jsxs(s1,{"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(Df,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ec({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&g.jsx(s1,{asChild:!0,children:g.jsx(St,{variant:"outline",children:"Close"})})]})}function dl({className:e,...t}){return g.jsx(EI,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function dc({className:e,...t}){return g.jsx(CI,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function hl(e){const[t,n]=_.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return _.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 Xre({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(Zre,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:TB(e.updatedAt,t)}),u=g.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return g.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:g.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:We("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,g.jsx(A9,{className:We("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Zre({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(Qre,{mode:t})]})}function Qre({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Rx:Nx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:g.jsx(n,{className:"size-3","aria-hidden":"true"})})}function RB({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(t7,{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 Jre({now:e}){const t=qt($=>$.historySessions),[n,r]=_.useState(null),[i,s]=_.useState(null),[o,l]=_.useState("json"),[u,d]=_.useState("default"),[h,p]=_.useState(!1),[y,v]=_.useState(!1),[b,w]=_.useState(new Set),[x,E]=_.useState(new Set),k=Js(),T=_.useMemo(()=>{const $=new Map;for(const D of t){const M=B0(D);let j=$.get(M);j||(j=new Map,$.set(M,j));const L=AB(D.projectDir),O=j.get(L);O?O.sessions.push(D):j.set(L,{dir:L,sessions:[D]})}return Array.from($.entries()).sort(([D],[M])=>kB(D,M)).map(([D,M])=>({provider:D,sessions:Array.from(M.values()).flatMap(j=>j.sessions),projects:Array.from(M.values()).map(j=>({dir:j.dir,shortDir:Cv(j.dir),sessions:j.sessions}))}))},[t]);function N($){s($),l(eie($)),d("default")}async function z($,D,M){if(n)return;const j=Ot;if(!j){rt.error("请先连接开发机");return}r($.id);const L=B0($);try{const O=await j.createSession({cwd:$.projectDir,mode:D,provider:L,resumeSessionId:$.id,...M?{permissionMode:M}:{}});if(O.error||!O.sessionId){rt.error(`恢复失败:${O.error??"未知错误"}`);return}const Y={sessionId:O.sessionId,state:"idle",mode:O.mode??D,provider:O.provider??"claude"};qt.getState().addSession(Y),k(`/chat/${O.sessionId}?mode=${O.mode??D}`),s(null)}catch(O){rt.error(`恢复失败:${O instanceof Error?O.message:String(O)}`)}finally{r(null)}}function R(){const $=Ot;!$||h||(p(!0),$.requestSessionHistory().then(D=>qt.getState().setHistorySessions(D)).catch(D=>{rt.error(D instanceof Error?D.message:String(D))}).finally(()=>{p(!1)}))}function F($,D){const M=LN($,D);E(j=>{const L=new Set(j);return L.has(M)?L.delete(M):L.add(M),L})}function P($){w(D=>{const M=new Set(D);return M.has($)?M.delete($):M.add($),M})}const q=t.length>0,H=i?NB():[];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:()=>q&&v($=>!$),disabled:!q,"aria-expanded":q?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:We("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[g.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",q?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),q?g.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:R,disabled:h,"data-slot":"history-refresh",children:g.jsx(Ax,{className:We("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!q&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),q&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:T.map($=>{const D=b.has($.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>P($.provider),"aria-expanded":!D,"data-slot":"history-provider-header","data-expanded":!D,className:We("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:Xv($.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:$.sessions.length}),g.jsx(Kh,{className:We("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:$.projects.map(M=>{const j=LN($.provider,M.dir),L=x.has(j);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>F($.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:We("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),g.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),g.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&g.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(O=>g.jsx(Xre,{session:O,now:e,disabled:n!==null,loading:n===O.id,onClick:()=>N(O),modeTag:O.preferredMode},O.id))})]},j)})})]},$.provider)})}),g.jsx(tie,{session:i,open:i!==null,modes:H,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:$=>{$||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&z(i,o,u)}})]})}function LN(e,t){return`${e}:${AB(t)}`}function AB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function NB(){return["json","pty"]}function eie(e){const t=NB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function tie({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=_.useState(!1),y=i==="bypassPermissions",v=hl("(min-width: 768px)");_.useEffect(()=>{t||p(!1)},[t]);const b=h?g.jsx(RB,{providerLabel:e?Xv(B0(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(IN,{checked:r==="json",label:"聊天",icon:g.jsx(Rx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(IN,{checked:r==="pty",label:"终端",icon:g.jsx(Nx,{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(Zb,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(Zb,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(Zb,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(St,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(St,{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(Sc,{open:t,onOpenChange:o,children:g.jsxs(xc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(Ec,{className:"min-w-0",children:[g.jsx(dl,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(dc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),b,g.jsx(Yu,{children:w})]})}):g.jsx(Yv,{open:t,onOpenChange:o,children:g.jsxs(Kv,{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(R1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Gv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(Hre,{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:b}),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 IN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:We("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,g.jsx("span",{className:"min-w-0 text-center",children:t}),g.jsx(ra,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Zb({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:We("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[g.jsx("span",{className:We("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&g.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:We("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),g.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&g.jsx(ra,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function nie({...e}){return g.jsx(ere,{"data-slot":"select",...e})}function rie({...e}){return g.jsx(nre,{"data-slot":"select-value",...e})}function iie({className:e,size:t="default",children:n,...r}){return g.jsxs(tre,{"data-slot":"select-trigger","data-size":t,className:We("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,g.jsx(rre,{asChild:!0,children:g.jsx(gl,{className:"size-4 opacity-50"})})]})}function sie({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(ire,{children:g.jsxs(sre,{"data-slot":"select-content",className:We("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[g.jsx(aie,{}),g.jsx(ore,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),g.jsx(lie,{})]})})}function oie({className:e,children:t,...n}){return g.jsxs(are,{"data-slot":"select-item",className:We("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[g.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(cre,{children:g.jsx(ra,{className:"size-4"})})}),g.jsx(lre,{children:t})]})}function aie({className:e,...t}){return g.jsx(ure,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Tx,{className:"size-4"})})}function lie({className:e,...t}){return g.jsx(dre,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(gl,{className:"size-4"})})}function O1(e){return!e||e.endsWith("/")?e:`${e}/`}function cie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function uie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function die(e,t,n){var o;if(t==="insert")return{currentPath:uie(e)||"./",query:cie(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:O1(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 hie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function fie(e,t){return`${O1(e)}${t.name}${t.isDir?"/":""}`}function zN(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 MB=_.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=Ei(U=>U.tree),h=Ei(U=>U.cwd),p=Ei(U=>U.homePath),y=i==="insert"?h:p||h,v=_.useMemo(()=>new Set(d.keys()),[d]),b=_.useMemo(()=>die(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=b.currentPath,x=_.useMemo(()=>hie(y,w),[y,w]),E=b.query,k=_.useRef(new Set),[T,N]=_.useState(!1),[z,R]=_.useState(""),[F,P]=_.useState(!1);_.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const U=Ot;if(!U)return;let A=!1;return k.current.add(x),U.requestDirectoryList(x).then(W=>{A||Ei.getState().setDirEntries(W.path,W.entries)}).catch(()=>{A||Ei.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{A=!0}},[x,d]);const q=!d.has(x),H=_.useMemo(()=>{let U=d.get(x)??[];return o&&(U=U.filter(A=>A.isDir)),E&&(U=U.filter(A=>A.name.toLowerCase().includes(E))),U},[d,x,E,o]),[$,D]=_.useState(0);_.useEffect(()=>D(0),[w,E]),_.useEffect(()=>{N(!1),R("")},[x]),_.useEffect(()=>{$>=H.length&&H.length>0&&D(H.length-1)},[H.length,$]);const M=_.useRef(null),j=_.useRef(!1);_.useEffect(()=>{var A;if(!j.current)return;j.current=!1;const U=(A=M.current)==null?void 0:A.querySelector(`[data-entry-index="${$}"]`);U==null||U.scrollIntoView({block:"nearest"})},[$]);const L=_.useCallback(U=>{const A=fie(w,U);return i==="insert"?A.replace(/^\.\//,""):A},[w,i]);async function O(){const U=zN(x,z);if(!(!U||!r)){P(!0);try{const A=await r(U);if(!A)return;R(""),N(!1),n(O1(A))}finally{P(!1)}}}_.useImperativeHandle(u,()=>({handleKey(U){return H.length===0?!1:U.key==="ArrowDown"?(j.current=!0,D(A=>Math.min(H.length-1,A+1)),!0):U.key==="ArrowUp"?(j.current=!0,D(A=>Math.max(0,A-1)),!0):U.key==="Enter"&&!U.nativeEvent.isComposing?(n(L(H[$])),!0):!1}}),[H,$,L,n]);const Y=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",K=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:Y,"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||F,onClick:()=>N(U=>!U),children:"新建目录"}):null]}),T?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:z,onChange:U=>R(U.target.value),onKeyDown:U=>{U.key==="Enter"&&!U.nativeEvent.isComposing&&(U.preventDefault(),O()),U.key==="Escape"&&(N(!1),R(""))},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:!zN(x,z)||F,onClick:()=>void O(),children:F?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:K,children:H.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:q?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:H.map((U,A)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(L(U)),onMouseEnter:()=>D(A),className:We("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",A===$&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",U.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":U.isDir?"dir":"file","data-entry-index":A,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[U.name,U.isDir?"/":""]})})},U.name))})})]})}),BN="工作目录不存在或不可访问:",pie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],OB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function mie(e,t){return t!==Xr.PATH_NOT_FOUND||!e.startsWith(BN)?null:e.slice(BN.length).trim()||null}function Kg(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 gie(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function vie(e,t){return e!=="codex"||OB.some(n=>n.value===t)?t:"default"}async function yie({relay:e,agentCli:t,form:n,timeoutMs:r=qx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Kg(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${na[n.provider]} 不可用:${p}`:`${na[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=mie(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 _ie({relay:e,timeoutMs:t=qx}){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 bie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Kg("claude",e),y=Kg("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(jN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(jN,{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(wie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(Sie,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function jN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Uf,{children:[g.jsx(Wf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:na[e]}),g.jsx("span",{className:We("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(qf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:gie(e,n)})})]})}function wie({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(St,{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(St,{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 Sie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[g.jsx("p",{className:We("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),g.jsx(St,{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(St,{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(N8,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:We("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function Ih({open:e,onOpenChange:t}){const[n,r]=_.useState(""),[i,s]=_.useState(""),[o,l]=_.useState("claude"),[u,d]=_.useState("pty"),[h,p]=_.useState("default"),[y,v]=_.useState(!1),[b,w]=_.useState(!1),[x,E]=_.useState(null),[k,T]=_.useState(!1),[N,z]=_.useState(null),[R,F]=_.useState(""),[P,q]=_.useState(!1),H=_.useRef(null),$=_.useRef(e);$.current=e;const D=Js(),M=Ei(xe=>xe.homePath),j=Ei(xe=>xe.agentCli),L=hl("(min-width: 768px)");_.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),_.useEffect(()=>{if(!e||M&&j)return;const xe=Ot==null?void 0:Ot.requestProxyInfo();xe&&xe.then(Re=>{const ze=Ei.getState();ze.setHomePath(Re.homePath),ze.setAgentCli(Re.agentCli)}).catch(Re=>{console.error("[create-session-dialog] requestProxyInfo failed",Re)})},[e,M,j]),_.useEffect(()=>{if(!k)return;function xe(Re){var Ye;const ze=Re.target;ze instanceof Node&&((Ye=H.current)!=null&&Ye.contains(ze))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",xe,!0),()=>document.removeEventListener("pointerdown",xe,!0)},[k]);function O(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),v(!1),E(null),z(null),F(""),q(!1)}function Y(){if(h==="bypassPermissions"){v(!0);return}I()}async function K(){await I(),$.current&&v(!1)}const U=o==="codex"?OB:pie,A=Kg(o,j),W=b||P||A.disabled;function G(xe){const Re=vie(xe,h);Re!==h&&p(Re)}async function I(xe){E(null),w(!0);try{const Re=await yie({relay:Ot,agentCli:j,form:{cwd:xe??i,name:n,provider:o,permissionMode:h,mode:u}});if(Re.type==="success"){if(qt.getState().addSession(Re.session),!$.current)return;t(!1),O(),D(Re.route);return}if(Re.type==="missing_cwd"&&E(Re.path),rt.error(Re.message),Re.type==="validation_error"||Re.type==="relay_missing")return}finally{w(!1)}}async function ne(xe){const Re=Ot;if(!Re)return rt.error("请先连接开发机"),null;try{const ze=await Re.createDirectory(xe);return ze.success?(s(ze.path),E(null),rt.success("目录已创建"),ze.path):(rt.error(`目录创建失败:${ze.error??"未知错误"}`),null)}catch(ze){return rt.error(ze instanceof Error?ze.message:String(ze)),null}}function ie(xe){var ze;const Re=j==null?void 0:j[xe];z(xe),F((Re==null?void 0:Re.command)??((ze=Re==null?void 0:Re.suggestions)==null?void 0:ze[0])??"")}async function se(){if(!N)return;const xe=R.trim();if(!xe){rt.error("请输入 Agent CLI 路径");return}const Re=Ot;if(!Re){rt.error("请先连接开发机");return}q(!0);try{const ze=await Re.updateAgentCliPath(N,xe);if(ze.error||!ze.agentCli){rt.error(`路径保存失败:${ze.error??"未知错误"}`);return}Ei.getState().setAgentCli(ze.agentCli),rt.success(`${na[N]} 路径已保存`),z(null),F("")}catch(ze){rt.error(ze instanceof Error?ze.message:String(ze))}finally{q(!1)}}function te(xe){d(xe),G(o)}function de(xe){var ze;const Re=xe.relatedTarget;Re instanceof Node&&((ze=H.current)!=null&&ze.contains(Re))||window.setTimeout(()=>T(!1),0)}const ve=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(RB,{providerLabel:na[o]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:b,children:"返回"}),g.jsx(St,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void K(),disabled:b,"data-slot":"bypass-permission-confirm",children:b?"创建中...":"确认"})]})]}):g.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:xe=>{xe.preventDefault(),Y()},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:xe=>r(xe.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:H,className:"relative flex min-w-0 flex-col gap-2",onBlur:de,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:()=>T(!0),onChange:xe=>{s(xe.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(MB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ne,onSelect:xe=>{s(xe),E(null),T(!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:()=>te("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),g.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>te("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),g.jsx(bie,{agentCli:j,provider:o,isDesktop:L,editingCliProvider:N,cliPathInput:R,savingCliPath:P,onProviderChange:xe=>{l(xe),G(xe)},onOpenCliPathEditor:ie,onCliPathInputChange:F,onCancelCliPathEditor:()=>{z(null),F("")},onSaveCliPath:()=>void se()}),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:xe=>p(xe),children:[g.jsx(iie,{className:"w-full",children:g.jsx(rie,{})}),g.jsx(sie,{children:U.map(xe=>g.jsx(oie,{value:xe.value,children:xe.label},xe.value))})]})]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:b,children:"取消"}),g.jsx(St,{type:"submit",className:"min-h-11 md:min-h-0",disabled:W,children:b?"创建中...":"创建"})]})]});return L?g.jsx(Sc,{open:e,onOpenChange:t,children:g.jsxs(xc,{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(Ec,{children:g.jsx(dl,{children:y?"跳过全部审批?":"新建会话"})}),ve]})}):g.jsx(Yv,{open:e,onOpenChange:t,children:g.jsxs(Kv,{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(R1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Gv,{children:y?"跳过全部审批?":"新建会话"})}),ve]})})}function zh({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=_.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=_.useState(s),[u,d]=_.useState(null),[h,p]=_.useState(!1);_.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(v){v.preventDefault();const b=o.trim();if(!b){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,b),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return g.jsx(Sc,{open:e,onOpenChange:r,children:g.jsx(xc,{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(Ec,{children:[g.jsx(dl,{children:"重命名会话"}),g.jsx(dc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),g.jsxs("div",{className:"grid gap-2",children:[g.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),g.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:v=>{l(v.target.value),u&&d(null)}}),u?g.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(St,{type:"submit",disabled:h,children:"保存"})]})]})})})}function xie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function Eie(e){return(e==null?void 0:e.kind)==="terminal"}function Cie(e){return xie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Eie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function Bm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Cie(t);function s(){t&&(r(t),n(!1))}return g.jsx(Sc,{open:e,onOpenChange:n,children:g.jsxs(xc,{"data-slot":"session-termination-dialog",children:[g.jsxs(Ec,{children:[g.jsx(dl,{children:i.title}),g.jsx(dc,{children:i.description})]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(St,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function DB(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 kie(e){if(e.session.state==="error")return"error";const t=DB(e);return t==="disconnected"?e.session.state:t}function PB({layout:e}){const t=qt(A=>A.sessions),n=qt(A=>A.sessionListLoaded),r=qt(A=>A.agentStatusBySessionId),i=qt(A=>A.ptyStateBySessionId),s=qt(A=>A.renameSession),o=Zt(A=>A.bySessionId),l=sU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Ie(A=>!!A.selectedProxyId),p=!Ie(A=>A.proxyListLoaded)||d&&!n,y=Js(),[v,b]=_.useState(!1),[w,x]=_.useState(!1),[E,k]=_.useState(null),[T,N]=_.useState(null),{creatingTerminal:z,createTerminal:R}=LB(),[F,P]=_.useState(new Set),[q,H]=_.useState(()=>Date.now());_.useEffect(()=>{const A=setInterval(()=>H(Date.now()),6e4);return()=>clearInterval(A)},[]);function $(A,W){y(`/chat/${A}?mode=${W??"json"}`,{replace:!1})}function D(A){const W=A.sessionId,G=Ot;if(!G){rt.error("请先连接开发机");return}G.sendControl({type:"session_terminate",sessionId:W}),qt.getState().removeSession(W),Zt.getState().clearSession(W),W===u&&y("/sessions"),(A==null?void 0:A.mode)==="pty"&&A.ptyOwner==="local-terminal"?rt.info("已断开页面连接,本地终端仍在运行"):rt.info("正在终止会话",{duration:1500})}async function M(A,W){const G=Ot;if(!G)throw new Error("请先连接开发机");const I=await G.renameSession(A,W);if(!I.success)throw new Error(I.error??"重命名失败");s(A,I.name??W),rt.success("已重命名会话")}function j(A){P(W=>{const G=new Set(W);return G.has(A)?G.delete(A):G.add(A),G})}function L(A){var I;const W=A.mode==="json"&&(((I=o[A.sessionId])==null?void 0:I.pendingApprovals.some(ne=>ne.status==="pending"))??!1),G=kie({session:A,agentStatus:r[A.sessionId],ptyState:i[A.sessionId],hasPendingApproval:W});return G===A.state?A:{...A,state:G}}const O=t.length>0;if(e==="sidebar"&&(p||!d))return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70",children:p?"连接中...":"请先连接开发机"}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});if(e==="page"&&p)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",children:[g.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});if(e==="page"&&!d)return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsx("div",{className:"flex-1",children:g.jsx(nc,{variant:"no-proxy"})}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});const Y=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",O?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=O?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:Tie(t).map(A=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>j(A.provider),"aria-expanded":!F.has(A.provider),className:We("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:Rie(A.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:A.sessions.length}),g.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(A.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(A.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:A.sessions.map(W=>g.jsx(Yre,{session:L(W),selected:W.sessionId===u,now:q,onClick:()=>$(W.sessionId,W.mode),onRename:()=>k(W),onTerminate:()=>N(W)},W.sessionId))})]},A.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),U=g.jsx(Jre,{now:q});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,U]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(St,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>x(!0),children:[g.jsx(wP,{"aria-hidden":"true"}),"新建"]})}),g.jsx(Nie,{open:w,creatingTerminal:z,onOpenChange:x,onCreateAgent:()=>{x(!1),b(!0)},onCreateTerminal:()=>void R(()=>x(!1))}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,U]}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]})}function Tie(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])=>Aie(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Rie(e){return e==="terminal"?"终端":Xv(e)}function Aie(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:kB(e,t)}function LB(){const e=Js(),[t,n]=_.useState(!1);async function r(i){if(!t){n(!0);try{const s=await _ie({relay:Ot});if(s.type!=="success"){rt.error(s.message);return}qt.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function FN({compact:e=!1}){const[t,n]=_.useState(!1),[r,i]=_.useState(!1),s=_.useRef(!1),o=Ie(w=>!!w.selectedProxyId),{creatingTerminal:l,createTerminal:u}=LB();function d(){i(!0),window.setTimeout(()=>i(!1),2e3)}function h(){if(!o){d();return}s.current=!0,n(!0)}function p(){if(!o){d();return}s.current=!0,u()}function y(w){w.preventDefault(),d()}const v=g.jsxs(St,{variant:"outline","data-slot":"create-session-trigger",className:We(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!o&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!o,onClick:o?void 0:y,children:[g.jsx(wP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),b=o?g.jsxs(A1,{children:[g.jsx(N1,{asChild:!0,children:v}),g.jsxs(M1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:w=>{s.current&&(s.current=!1,w.preventDefault())},children:[g.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:h,children:[g.jsx(bP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:l,onSelect:p,children:[g.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),l?"正在创建终端会话...":"终端会话"]})]})]}):v;return g.jsxs(g.Fragment,{children:[o?b:g.jsxs(Uf,{open:o?void 0:r,onOpenChange:o?void 0:i,children:[g.jsx(Wf,{asChild:!0,children:b}),g.jsx(qf,{side:"top",children:o?"新建会话":"请先连接开发机"})]}),g.jsx(Ih,{open:t,onOpenChange:n})]})}function Nie({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=_.useRef(!1);function o(l){s.current=!0,l()}return g.jsx(Yv,{open:e,onOpenChange:n,children:g.jsxs(Kv,{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(R1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Gv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.jsxs(St,{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(bP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(St,{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(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Mie="0.5.8",Oie={version:Mie},Die={playback:"playback",capture:"play-and-record"};function Pie(){return typeof navigator>"u"?null:navigator.audioSession??null}function Lie(){return{setMode:()=>{},release:()=>{}}}class Iie{constructor(t=Pie){gt(this,"leases",new Map);gt(this,"session",null);gt(this,"baselineType",null);gt(this,"nextLeaseId",1);gt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Lie();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(Die[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 D1=new Iie,H0=64,$N=-60,IB=32;function HN(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-$N)/-$N));return e<0?-r:r}function UN(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 zie(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 Bie(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 zB{constructor(t,n=24e3,r={}){gt(this,"nextStartTime",0);gt(this,"activityEndToken",0);gt(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=zie(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*IB/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=Bie(n.subarray(l,u));this.scheduleTimer(()=>{var v,b,w,x;(b=(v=this.options).onActivityLevel)==null||b.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 Qb={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},WN="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",jie=800,qN=300,Fie=1600;function U0(e,t){return e.filter(n=>!n.model||n.model===t)}function VN({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 jm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=_.useState(!1),u=_.useId(),d=n.find(v=>v.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!BB(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(YN,{label:h,muted:!d&&!t}),g.jsx(gl,{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 b=v.value===t;return g.jsxs("button",{type:"button",role:"option","aria-label":v.label,"aria-selected":b,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:b?g.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(YN,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function YN({label:e,muted:t=!1}){const n=BB(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 $ie({scrollRef:e}={}){const[t,n]=_.useState(Qb),[r,i]=_.useState(String(Qb.turnIdleSeconds)),[s,o]=_.useState(()=>km()),[l,u]=_.useState(""),[d,h]=_.useState(!1),[p,y]=_.useState(!1),[v,b]=_.useState({kind:"idle"}),w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(null);_.useEffect(()=>{const se=Ot;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te=!1;return b({kind:"loading"}),se.requestVoiceConfig().then(de=>{if(!te){if(de.error||!de.config){b({kind:"error",message:de.error??"读取语音设置失败"});return}n(de.config),i(String(de.config.turnIdleSeconds)),u(""),h(!1),y(!0),b({kind:"idle"})}}).catch(de=>{te||b({kind:"error",message:de instanceof Error?de.message:"读取语音设置失败"})}),()=>{te=!0}},[]),_.useEffect(()=>{const se=Ot;if(!se||!p)return;let te=!1;return se.requestVoiceCapabilities({region:t.region}).then(de=>{if(!te){if(de.error||!de.capabilities){o(km());return}o(de.capabilities)}}).catch(()=>{te||o(km())}),()=>{te=!0}},[t.region,p]),_.useEffect(()=>()=>{G(),I()},[]);const N=_.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]),z=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",R=_.useMemo(()=>U0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=R.some(se=>se.value===t.ttsVoice)?t.ttsVoice:"",q=R.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",H=_.useMemo(()=>qie(r),[r]),$=H?null:"请输入正整数秒数",D=q??$,M=z||!!D,j=_.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=_.useMemo(()=>XN(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),O=_.useMemo(()=>Vie(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),Y=_.useMemo(()=>XN(R,P),[R,P]);function K(){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:H??Qb.turnIdleSeconds}}async function U(){if(z)return;if(D){b({kind:"error",message:D});return}const se=Ot;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}const te=K();I(),b({kind:"saving"});const de=performance.now();try{const ve=await se.updateVoiceConfig(te),xe=performance.now()-de;if(xe<qN&&await Wie(qN-xe),!ve.success||ve.error||!ve.config){b({kind:"error",message:ve.error??"保存语音设置失败"});return}n(ve.config),i(String(ve.config.turnIdleSeconds)),u(""),h(!1),b({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,b(Re=>Re.kind==="saved"?{kind:"idle"}:Re)},Fie),se.requestVoiceCapabilities({region:ve.config.region}).then(Re=>{Re.capabilities&&o(Re.capabilities)}).catch(()=>{o(km())})}catch(ve){b({kind:"error",message:ve instanceof Error?ve.message:"保存语音设置失败"})}}async function A(){if(z)return;if(D){b({kind:"error",message:D});return}const se=Ot;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te;try{te=W()}catch(de){b({kind:"error",message:GN(de)});return}b({kind:"testing"});try{const[de]=await Promise.all([se.testVoiceConfig(K()),te.ready]);if(!de.success||de.error){G(),b({kind:"error",message:de.error??"语音配置测试失败"});return}const ve=await ne(de,te.context);b({kind:"playingTest",transcript:de.transcript}),k.current=setTimeout(()=>{k.current=null,G(),b({kind:"testPassed",transcript:de.transcript})},ve)}catch(de){G(),b({kind:"error",message:GN(de)})}}function W(){G();const se=D1.acquire("playback");x.current=se;try{const te=Uie();return w.current=te,{context:te,ready:KN(te)}}catch(te){throw se.release(),x.current=null,te}}function G(){var se,te,de;k.current&&(clearTimeout(k.current),k.current=null),(se=E.current)==null||se.stop(),E.current=null,(te=w.current)==null||te.close(),w.current=null,(de=x.current)==null||de.release(),x.current=null}function I(){T.current&&(clearTimeout(T.current),T.current=null)}async function ne(se,te){if(!se.audioBase64)throw new Error("语音测试未返回可播放音频");if(se.audioEncoding&&se.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const de=se.audioSampleRate??24e3,ve=Hie(se.audioBase64);if(ve.byteLength===0||ve.byteLength%2!==0)throw new Error("测试音频数据无效");await KN(te);const xe=new zB(te,de);E.current=xe,xe.enqueue(ve);const Re=Math.ceil(ve.byteLength/2/de*1e3);return Math.max(jie,Re)}function ie(se){var te;return((te=U0(s.ttsVoices,se)[0])==null?void 0:te.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:se=>{se.preventDefault(),U()},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(VN,{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(EP,{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:se=>{u(se.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${WN} w-full pl-9`})]}),t.configured&&g.jsxs(St,{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(J8,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(jm,{label:"地域",value:t.region,options:j,onChange:se=>n(te=>({...te,region:se==="intl"?"intl":"cn"}))}),g.jsx(jm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:se=>n(te=>({...te,asrModel:se}))}),g.jsx(jm,{label:"语音合成模型",value:t.ttsModel,options:O,onChange:se=>n(te=>({...te,ttsModel:se,ttsVoice:ie(se)}))}),g.jsx(jm,{label:"语音音色",value:P,options:Y,placeholder:R.length===0?"暂无可用音色":"请选择音色",onChange:se=>n(te=>({...te,ttsVoice:se})),help:q}),g.jsx(VN,{label:"结束停顿时间(秒)",help:$,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:se=>i(se.target.value),className:`${WN} 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:[N?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:N}):null,g.jsxs(St,{type:"button",variant:"outline",disabled:M,onClick:()=>void A(),children:[g.jsx(TP,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(St,{type:"submit",disabled:M,children:[g.jsx(F8,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Hie(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 Uie(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function KN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function GN(e){return e instanceof Error?e.message:"语音配置测试失败"}function Wie(e){return new Promise(t=>setTimeout(t,e))}function qie(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function XN(e,t){const n=e.map(r=>({value:r.value,label:jB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Vie(e,t,n){const r=e.map(i=>{const s=U0(t,i.value).length===0;return{value:i.value,label:`${jB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function BB(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 jB(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 Yie=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Kie=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],P1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function FB(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 Gie(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Xie(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Zie(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function W0({open:e,onOpenChange:t}){const n=Ie(q=>q.relayUrl),r=Ie(q=>q.latencyMonitorEnabled),i=Ie(q=>q.setLatencyMonitorEnabled),s=Ie(q=>q.sessionIdleNotificationsEnabled),o=Ie(q=>q.setSessionIdleNotificationsEnabled),l=Ie(q=>q.inputModePreference),u=Ie(q=>q.setInputModePreference),d=Ie(q=>q.themePreference),h=Ie(q=>q.setThemePreference),p=Ie(q=>q.ptyScrollTraceEnabled),y=Ie(q=>q.setPtyScrollTraceEnabled),[v,b]=_.useState("menu"),[w,x]=_.useState({kind:"idle"}),E=_.useRef(null),k=_.useRef(null),T=VZ(),N=_.useMemo(()=>Ev().osName==="iPad",[]),z=_.useCallback(async q=>{if(!q){o(!1);return}const H=await wZ();if(H==="granted"){o(!0);return}if(H==="denied"){rt.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(H==="default"){rt.info("未授予通知权限,会话通知保持关闭");return}rt.error("当前浏览器不支持系统通知")},[o]),R=_.useCallback(async q=>{x({kind:"loading"});try{const H=await fetch(Gie(n),{cache:"no-store",signal:q});if(!H.ok)throw new Error(`HTTP ${H.status}`);const $=await H.json();if($.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:$.version??"未知",uptime:$.uptime??0})}catch(H){if(H instanceof DOMException&&H.name==="AbortError")return;x({kind:"error",message:H instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);_.useEffect(()=>{if(!e){b("menu");return}},[e]),_.useEffect(()=>{if(!e||v!=="version")return;const q=new AbortController;return R(q.signal),()=>q.abort()},[R,e,v]),_.useEffect(()=>{if(!e||v!=="voice")return;const q=window.requestAnimationFrame(()=>{var H;(H=E.current)==null||H.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(q)},[e,v]);const F=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${FB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(Sc,{open:e,onOpenChange:t,children:g.jsxs(xc,{className:We("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",v==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",v==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":v,focusSurfaceOnOpen:!0,ref:E,showCloseButton:v==="menu",children:[g.jsx(Ec,{className:We(v==="menu"&&"pr-12 text-left",v!=="menu"&&"text-left",v==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:v!=="menu"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-start gap-2",children:[g.jsx(St,{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:()=>b("menu"),children:g.jsx(vv,{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(dl,{children:Xie(v)}),g.jsx(dc,{className:"max-w-[28rem] leading-5",children:Zie(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(dl,{children:"设置"}),g.jsx(dc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(Qie,{relayVersion:F,relayDetail:P,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(ese,{saved:T}):v==="clients"?g.jsx(sse,{}):v==="voice"?g.jsx($ie,{scrollRef:k}):g.jsx(Jie,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:N,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:z,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>b("voice"),onOpenRelayToken:()=>b("relay-token"),onOpenClients:()=>b("clients"),onOpenVersion:()=>b("version")})]})})}function Qie({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:P1,"data-slot":"settings-dialog-body",children:[g.jsx(QN,{icon:g.jsx(kP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Oie.version,detail:"当前浏览器加载的版本"}),g.jsx(QN,{icon:g.jsx(RP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Jie({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:b,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(cu,{title:"服务",children:[g.jsx(Fm,{icon:g.jsx(D9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx(Fm,{icon:g.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx(Fm,{icon:g.jsx(o7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:b})]}),g.jsx(cu,{title:"外观",children:g.jsx(ZN,{icon:g.jsx(X8,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Yie,onValueChange:n})}),g.jsx(cu,{title:"通知",children:g.jsx(ew,{icon:g.jsx(L9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(cu,{title:"交互",children:g.jsx(ZN,{icon:g.jsx(CP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Kie,onValueChange:i})}):null,g.jsxs(cu,{title:"高级诊断",children:[g.jsx(ew,{icon:g.jsx(of,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(ew,{icon:g.jsx(yP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(cu,{title:"关于",children:g.jsx(Fm,{icon:g.jsx(RP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({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 ZN({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=_.useId(),l=_.useId();return g.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,g.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return g.jsx("button",{type:"button",role:"radio","aria-checked":d,className:We("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function ese({saved:e}){const t=_.useId(),n=_.useId(),[r,i]=_.useState(""),[s,o]=_.useState(null),l=()=>{qL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}UL(h),l()},d=()=>{WL(),l()};return g.jsxs("form",{className:P1,"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(St,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(St,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function tse(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())||tse(e)}function rse(e){return dX(e)}function ise(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return FB(t)}function Jb({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 sse(){const e=Ie(y=>y.proxies),[t,n]=_.useState([]),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,u]=_.useState(null),d=_.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),h=_.useCallback(async()=>{const y=Ot;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)}},[]);_.useEffect(()=>{h()},[h]);const p=_.useCallback(async y=>{const v=Ot;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const b=await v.kickRelayClient(y);if(!b.success){o(b.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(b){o(b instanceof Error?b.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:P1,"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(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Ax,{className:We("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?g.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?g.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const v=y.current===!0,b=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:rse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(Jb,{label:"已连接",value:ise(y.connectedAt)}),y.proxyId?g.jsx(Jb,{label:"连接到",value:nse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(Jb,{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(St,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:b,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[g.jsx(g8,{className:"size-3.5","aria-hidden":"true"}),b?"断开中...":"断开"]})]})},y.clientId)})]})}function ew({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=_.useId(),o=_.useId();return g.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[g.jsx("div",{className:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),g.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),g.jsx("span",{className:We("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:g.jsx("span",{className:We("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function Fm({icon:e,label:t,detail:n,onClick:r}){const i=_.useId(),s=_.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(Kh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function QN({icon:e,label:t,value:n,detail:r,muted:i=!1}){return g.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[g.jsx("div",{className:We("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[g.jsx("div",{className:"text-sm text-muted-foreground",children:t}),g.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const ose="xterm-helper-textarea";function ase(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(ose)?!1:(e.blur(),!0)}function JN(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&&lse(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function lse(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 cse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=_.useRef(null),r=_.useCallback(()=>{e&&ase()},[e]),i=_.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=_.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,JN(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=_.useCallback(l=>{r(),t&&(JN(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function use({className:e}){const t=Ie(o=>o.sidebarCollapsed),n=Ie(o=>o.toggleSidebarCollapsed),[r,i]=_.useState(!1),s=cse();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[g.jsx(tM,{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(eM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(FN,{compact:!0})]})]}),g.jsx(W0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[g.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:g.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx(YP,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(tM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx(CB,{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(PB,{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(FN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(eM,{onClick:()=>i(!0)})})]})]}),g.jsx(W0,{open:r,onOpenChange:i})]})}function eM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Uf,{delayDuration:500,children:[g.jsx(Wf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[g.jsx(AP,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(qf,{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 tM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?k8:E8;return g.jsxs(Uf,{delayDuration:500,children:[g.jsx(Wf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:g.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(qf,{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 dse=1500,hse=300,nM=70,rM=35;function $B({texts:e,className:t}){const[n,r]=_.useState(""),[i,s]=_.useState(!0),o=_.useRef("typing"),l=_.useRef(0),u=_.useRef(0);return _.useEffect(()=>{const d=setInterval(()=>s(h=>!h),530);return()=>clearInterval(d)},[]),_.useEffect(()=>{let d;const h=()=>e[u.current%e.length],p=()=>{const y=o.current;if(y==="typing"){const v=h();l.current<v.length?(l.current+=1,r(v.slice(0,l.current)),d=setTimeout(p,nM)):(o.current="paused",d=setTimeout(p,dse))}else y==="paused"?(o.current="deleting",d=setTimeout(p,rM)):y==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),d=setTimeout(p,rM)):(u.current+=1,o.current="waiting",d=setTimeout(p,hse)):(o.current="typing",d=setTimeout(p,nM))};return d=setTimeout(p,500),()=>clearTimeout(d)},[e]),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-foreground/90",children:n}),g.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const HB=["DEV Anywhere","/unlimited @anytime"];function fse({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($B,{texts:HB,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 pse=3e3,mse=1e4,$m=12,gse=4,iM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},vse={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 uu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Bh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function sM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function UB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function yse(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 _se(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Bh(e.rttMs):"等待检测"}function bse(){const e=ki("local",ln.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 oM(e){dr("local",ln.latencyMonitorPosition,JSON.stringify(e))}function wse(){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=wse(),r=$m,i=$m,s=Math.max(r,n.width-t.width-$m),o=Math.max(i,n.height-t.height-$m);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Sse(){const e=Ie(R=>R.latencyMonitorEnabled),t=Ie(R=>R.connected),n=Ie(R=>R.proxyOnline),r=Ie(R=>R.selectedProxyId),[i,s]=_.useState(vse),[o,l]=_.useState(()=>bse()),u=_.useRef(!1),d=_.useRef(null),h=_.useRef(null),p=_.useRef(!1),y=_.useMemo(()=>(Object.values(i).sort((R,F)=>sM(F.state)-sM(R.state))[0]??{state:"idle"}).state,[i]),v=UB(y);async function b(){if(u.current)return;const R=Ot;if(!R||!t){const H=uu("Relay 服务器未连接");s({webRelay:H,relayProxy:H,webProxy:H});return}u.current=!0,s(H=>({webRelay:{...H.webRelay,state:"measuring"},relayProxy:n?{...H.relayProxy,state:"measuring"}:uu("未连接开发机"),webProxy:n?{...H.webProxy,state:"measuring"}:uu("未连接开发机")}));const[F,P,q]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:F.status==="fulfilled"?tw(F.value):uu(F.reason instanceof Error?F.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?tw(P.value):uu(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:q.status==="fulfilled"?tw(q.value):uu(q.reason instanceof Error?q.reason.message:"测速失败")}),u.current=!1}if(_.useEffect(()=>{if(!e)return;let R=!1,F=null;const P=async()=>{await b(),!R&&(F=setTimeout(P,document.hidden?mse:pse))};return P(),()=>{R=!0,u.current=!1,F&&clearTimeout(F)}},[e,t,n,r]),_.useEffect(()=>{if(!e||!o)return;const R=d.current;if(!R)return;const F=R.getBoundingClientRect(),P=nw(o,{width:F.width,height:F.height});P.x===o.x&&P.y===o.y||(l(P),oM(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(R){var P,q;if(R.button!==0)return;const F=R.currentTarget.getBoundingClientRect();h.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,originX:F.left,originY:F.top,width:F.width,height:F.height,dragging:!1},(q=(P=R.currentTarget).setPointerCapture)==null||q.call(P,R.pointerId)}function k(R){const F=h.current;if(!F||F.pointerId!==R.pointerId)return;const P=R.clientX-F.startX,q=R.clientY-F.startY;if(!F.dragging&&Math.hypot(P,q)<gse)return;F.dragging=!0,R.preventDefault();const H=nw({x:F.originX+P,y:F.originY+q},{width:F.width,height:F.height});l(H)}function T(R){var $,D;const F=h.current;if(!F||F.pointerId!==R.pointerId||(h.current=null,(D=($=R.currentTarget).releasePointerCapture)==null||D.call($,R.pointerId),!F.dragging))return;R.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=R.clientX-F.startX,q=R.clientY-F.startY,H=nw({x:F.originX+P,y:F.originY+q},{width:F.width,height:F.height});l(H),oM(H)}function N(R){var P,q;const F=h.current;!F||F.pointerId!==R.pointerId||(h.current=null,(q=(P=R.currentTarget).releasePointerCapture)==null||q.call(P,R.pointerId))}function z(R){p.current&&(p.current=!1,R.preventDefault(),R.stopPropagation())}return g.jsxs(C1,{children:[g.jsx(k1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:We("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",yse(v)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Bh(i.webRelay.rttMs)},开发机 ${Bh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:T,onPointerCancel:N,onClickCapture:z,children:[g.jsx(yP,{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 ",Bh(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Bh(w.rttMs)]}),g.jsx(gl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(T1,{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(St,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void b(),children:g.jsx(Ax,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(iM).map(R=>g.jsx(xse,{label:iM[R],measurement:i[R]},R))})]})]})}function xse({label:e,measurement:t}){const n=UB(t.state);return g.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[g.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:We("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),g.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:_se(t)})]})]})}const WB="/__dev_anywhere_debug/browser-state-dumps",Ese=1500,Cse=10,rw=80,L1=500,kse=["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"],Tse=["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 aM(){if(typeof window>"u")return"off";const e=QB("debugDump");return e==="auto"?"auto":e!==null||Ise("debugInput")?"manual":"off"}function Rse(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:Ose(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:lM(document.activeElement),selection:Dse(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>lM(i)).filter(i=>!!i),root:qB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:du(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:du(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:du(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:du(()=>cM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>cM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function Ase(e="manual"){const t=Rse(e);return Nse(t)}async function Nse(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Mse(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:WB}}catch(r){const i=JB(r),s=Pse(e.createdAt);return Lse(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Mse(e){const t=await fetch(WB,{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 qB(e,t,n){if(n.count>=Ese||t>Cse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=uM(e.textContent??"");return u?{kind:"text",text:Zv(u,L1)}:{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&&!uM(u.textContent??"")||r.push(qB(u,t+1,n));s.length>rw&&(i=s.length-rw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:ZB(e),attrs:VB(e),rect:YB(e),scroll:KB(e),style:GB(e)},l=XB(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function lM(e){if(!(e instanceof HTMLElement))return null;const t=XB(e);return{path:ZB(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:VB(e),rect:YB(e),scroll:KB(e),style:GB(e),...t?{value:t}:{}}}function Ose(){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 VB(e){const t={};for(const n of kse){const r=e.getAttribute(n);r!==null&&(t[n]=Zv(r,500))}return t}function YB(e){const t=e.getBoundingClientRect();return{x:Zi(t.x),y:Zi(t.y),width:Zi(t.width),height:Zi(t.height),top:Zi(t.top),right:Zi(t.right),bottom:Zi(t.bottom),left:Zi(t.left)}}function KB(e){return{top:Zi(e.scrollTop),left:Zi(e.scrollLeft),height:Zi(e.scrollHeight),width:Zi(e.scrollWidth),clientHeight:Zi(e.clientHeight),clientWidth:Zi(e.clientWidth)}}function GB(e){const t=window.getComputedStyle(e),n={};for(const r of Tse)n[r]=t.getPropertyValue(r);return n}function XB(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Zv(e.value,L1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Dse(){var e;try{return Zv(((e=window.getSelection())==null?void 0:e.toString())??"",L1)}catch{return null}}function ZB(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 Pse(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Lse(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 Ise(e){return QB(e)!==null}function QB(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 cM(e){return e?Gg(e.slice(-200)):null}function du(e){try{return Gg(e())}catch(t){return{error:JB(t)}}}function Gg(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(Gg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Gg(r);return t}return String(e)}function uM(e){return e.replace(/\s+/g," ").trim()}function Zv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Zi(e){return Math.round(e*100)/100}function JB(e){return e instanceof Error?e.message:String(e)}const zse=500,Bse=1e3,jse=60;function Fse(){const[e,t]=_.useState(()=>aM()),[n,r]=_.useState(!1),[i,s]=_.useState(null),o=_.useRef(null),l=_.useRef(!1),u=_.useRef(0),d=_.useRef(0),h=_.useRef(null);_.useEffect(()=>{const b=()=>t(aM());return window.addEventListener("hashchange",b),window.addEventListener("popstate",b),()=>{window.removeEventListener("hashchange",b),window.removeEventListener("popstate",b)}},[]);const p=_.useCallback(async(b="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await Ase(b);return o.current=w,s(w),(b==="manual"||w.status==="failed")&&$se(w),w}finally{l.current=!1,r(!1)}},[]);if(_.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),_.useEffect(()=>{var k,T;if(e!=="auto")return;const b=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=N=>{d.current>=jse||(b(),h.current=window.setTimeout(()=>{h.current=null;const z=Date.now(),R=Bse-(z-u.current);if(R>0){h.current=window.setTimeout(()=>w(N),R);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${N}`)},zse))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=N=>w(N.type);return x.forEach(N=>window.addEventListener(N,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(T=window.visualViewport)==null||T.addEventListener("scroll",E),()=>{var N,z;b(),x.forEach(R=>window.removeEventListener(R,E,!0)),(N=window.visualViewport)==null||N.removeEventListener("resize",E),(z=window.visualViewport)==null||z.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=Hse(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(St,{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(Lu,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(o8,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function $se(e){if(e.status==="saved"){rt.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){rt.info(`诊断已下载: ${e.filename}`);return}rt.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Hse(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Use(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 I1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:Use(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 Cn(e){return Math.round(e*10)/10}function Ka(e){return e.length===0?"":`${Cn(Math.min(...e))}..${Cn(Math.max(...e))}`}function Au(e){return[...new Set(e.filter(t=>t!==void 0).map(Cn))]}function e3(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 Wse="dev_anywhere_pty_input_latency_trace",dM=80,qse=1e4,Vse=new TextDecoder;let Yse=0;const Ku=new Map,Cc=I1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Wse,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Kse(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Qse)}function Gse(e,t){if(!Cc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Yse}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:toe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),B1(s,r),Ku.set(e,s),Vf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function hM(e,t){if(!e||!Cc.isEnabled())return;const n=performance.now(),r=Jse(e.sessionId,e.inputId);r&&(r.sentAt=n),Vf({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 Xse(e,t,n){if(!Cc.isEnabled())return;const r=performance.now(),i=z1(e,r),s=ioe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&roe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Vf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:j1(i,r),details:soe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Zse(e,t,n=1){if(!Cc.isEnabled())return;const r=performance.now(),i=z1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Vf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:j1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>eoe(e,s))}function Qse(){const e=Cc.getAll(),t=e.slice(-200),n=[...Ku.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Cn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Cn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Cn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Cn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Cn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Cn(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?"":Cn(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(`
|
|
500
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},EJ="DialogDescriptionWarning",CJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${xI(EJ).contentName}}.`;return _.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},t1=cI,kJ=dI,n1=fI,r1=pI,i1=mI,EI=vI,CI=_I,s1=wI;function TJ(e){const t=_.useRef({value:e,previous:e});return _.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function RJ(e){const[t,n]=_.useState(void 0);return Ti(()=>{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 AJ=["top","right","bottom","left"],cl=Math.min,hs=Math.max,$g=Math.round,Im=Math.floor,Eo=e=>({x:e,y:e}),NJ={left:"right",right:"left",bottom:"top",top:"bottom"};function k0(e,t,n){return hs(e,cl(t,n))}function sa(e,t){return typeof e=="function"?e(t):e}function oa(e){return e.split("-")[0]}function sd(e){return e.split("-")[1]}function o1(e){return e==="x"?"y":"x"}function a1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function l1(e){return o1(So(e))}function MJ(e,t,n){n===void 0&&(n=!1);const r=sd(e),i=l1(e),s=a1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Hg(o)),[o,Hg(o)]}function OJ(e){const t=Hg(e);return[T0(e),t,T0(t)]}function T0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const vN=["left","right"],yN=["right","left"],DJ=["top","bottom"],PJ=["bottom","top"];function LJ(e,t,n){switch(e){case"top":case"bottom":return n?t?yN:vN:t?vN:yN;case"left":case"right":return t?DJ:PJ;default:return[]}}function IJ(e,t,n,r){const i=sd(e);let s=LJ(oa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(T0)))),s}function Hg(e){const t=oa(e);return NJ[t]+e.slice(t.length)}function zJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function kI(e){return typeof e!="number"?zJ(e):{top:e,right:e,bottom:e,left:e}}function Ug(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 _N(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=l1(t),l=a1(o),u=oa(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(sd(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 BJ(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}=sa(t,e),b=kI(v),x=l[y?p==="floating"?"reference":"floating":p],E=Ug(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,T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),N=await(s.isElement==null?void 0:s.isElement(T))?await(s.getScale==null?void 0:s.getScale(T))||{x:1,y:1}:{x:1,y:1},z=Ug(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:T,strategy:u}):k);return{top:(E.top-z.top+b.top)/N.y,bottom:(z.bottom-E.bottom+b.bottom)/N.y,left:(E.left-z.left+b.left)/N.x,right:(z.right-E.right+b.right)/N.x}}const jJ=50,FJ=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:BJ},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}=_N(d,r,u),y=r,v=0;const b={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:T,y:N,data:z,reset:R}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:b,rects:d,platform:l,elements:{reference:e,floating:t}});h=T??h,p=N??p,b[E]={...b[E],...z},R&&v<jJ&&(v++,typeof R=="object"&&(R.placement&&(y=R.placement),R.rects&&(d=R.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):R.rects),{x:h,y:p}=_N(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:b}},$J=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}=sa(e,t)||{};if(d==null)return{};const p=kI(h),y={x:n,y:r},v=l1(i),b=a1(v),w=await o.getDimensions(d),x=v==="y",E=x?"top":"left",k=x?"bottom":"right",T=x?"clientHeight":"clientWidth",N=s.reference[b]+s.reference[v]-y[v]-s.floating[b],z=y[v]-s.reference[v],R=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let F=R?R[T]:0;(!F||!await(o.isElement==null?void 0:o.isElement(R)))&&(F=l.floating[T]||s.floating[b]);const P=N/2-z/2,q=F/2-w[b]/2-1,H=cl(p[E],q),$=cl(p[k],q),D=H,M=F-w[b]-$,j=F/2-w[b]/2+P,L=k0(D,j,M),O=!u.arrow&&sd(i)!=null&&j!==L&&s.reference[b]/2-(j<D?H:$)-w[b]/2<0,Y=O?j<D?j-D:j-M:0;return{[v]:y[v]+Y,data:{[v]:L,centerOffset:j-L-Y,...O&&{alignmentOffset:Y}},reset:O}}}),HJ=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:b="none",flipAlignment:w=!0,...x}=sa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=oa(i),k=So(l),T=oa(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),z=y||(T||!w?[Hg(l)]:OJ(l)),R=b!=="none";!y&&R&&z.push(...IJ(l,w,b,N));const F=[l,...z],P=await u.detectOverflow(t,x),q=[];let H=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&q.push(P[E]),p){const j=MJ(i,o,N);q.push(P[j[0]],P[j[1]])}if(H=[...H,{placement:i,overflows:q}],!q.every(j=>j<=0)){var $,D;const j=((($=s.flip)==null?void 0:$.index)||0)+1,L=F[j];if(L&&(!(p==="alignment"?k!==So(L):!1)||H.every(K=>So(K.placement)===k?K.overflows[0]>0:!0)))return{data:{index:j,overflows:H},reset:{placement:L}};let O=(D=H.filter(Y=>Y.overflows[0]<=0).sort((Y,K)=>Y.overflows[1]-K.overflows[1])[0])==null?void 0:D.placement;if(!O)switch(v){case"bestFit":{var M;const Y=(M=H.filter(K=>{if(R){const U=So(K.placement);return U===k||U==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(U=>U>0).reduce((U,A)=>U+A,0)]).sort((K,U)=>K[1]-U[1])[0])==null?void 0:M[0];Y&&(O=Y);break}case"initialPlacement":O=l;break}if(i!==O)return{reset:{placement:O}}}return{}}}};function bN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function wN(e){return AJ.some(t=>e[t]>=0)}const UJ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=sa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=bN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:wN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=bN(o,n.floating);return{data:{escapedOffsets:l,escaped:wN(l)}}}default:return{}}}}},TI=new Set(["left","top"]);async function WJ(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=oa(n),l=sd(n),u=So(n)==="y",d=TI.has(o)?-1:1,h=s&&u?-1:1,p=sa(t,e);let{mainAxis:y,crossAxis:v,alignmentAxis:b}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof b=="number"&&(v=l==="end"?b*-1:b),u?{x:v*h,y:y*d}:{x:y*d,y:v*h}}const qJ=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 WJ(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}}}}},VJ=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:T}=E;return{x:k,y:T}}},...d}=sa(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=So(oa(i)),v=o1(y);let b=h[v],w=h[y];if(o){const E=v==="y"?"top":"left",k=v==="y"?"bottom":"right",T=b+p[E],N=b-p[k];b=k0(T,b,N)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[E],N=w-p[k];w=k0(T,w,N)}const x=u.fn({...t,[v]:b,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[v]:o,[y]:l}}}}}},YJ=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}=sa(e,t),h={x:n,y:r},p=So(i),y=o1(p);let v=h[y],b=h[p];const w=sa(l,t),x=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const T=y==="y"?"height":"width",N=s.reference[y]-s.floating[T]+x.mainAxis,z=s.reference[y]+s.reference[T]-x.mainAxis;v<N?v=N:v>z&&(v=z)}if(d){var E,k;const T=y==="y"?"width":"height",N=TI.has(oa(i)),z=s.reference[p]-s.floating[T]+(N&&((E=o.offset)==null?void 0:E[p])||0)+(N?0:x.crossAxis),R=s.reference[p]+s.reference[T]+(N?0:((k=o.offset)==null?void 0:k[p])||0)-(N?x.crossAxis:0);b<z?b=z:b>R&&(b=R)}return{[y]:v,[p]:b}}}},KJ=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}=sa(e,t),h=await o.detectOverflow(t,d),p=oa(i),y=sd(i),v=So(i)==="y",{width:b,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,T=b-h.left-h.right,N=cl(w-h[x],k),z=cl(b-h[E],T),R=!t.middlewareData.shift;let F=N,P=z;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(F=k),R&&!y){const H=hs(h.left,0),$=hs(h.right,0),D=hs(h.top,0),M=hs(h.bottom,0);v?P=b-2*(H!==0||$!==0?H+$:hs(h.left,h.right)):F=w-2*(D!==0||M!==0?D+M:hs(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:F});const q=await o.getDimensions(l.floating);return b!==q.width||w!==q.height?{reset:{rects:!0}}:{}}}};function Mv(){return typeof window<"u"}function od(e){return RI(e)?(e.nodeName||"").toLowerCase():"#document"}function fs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function No(e){var t;return(t=(RI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function RI(e){return Mv()?e instanceof Node||e instanceof fs(e).Node:!1}function Xs(e){return Mv()?e instanceof Element||e instanceof fs(e).Element:!1}function la(e){return Mv()?e instanceof HTMLElement||e instanceof fs(e).HTMLElement:!1}function SN(e){return!Mv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof fs(e).ShadowRoot}function If(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Zs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function GJ(e){return/^(table|td|th)$/.test(od(e))}function Ov(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const XJ=/transform|translate|scale|rotate|perspective|filter/,ZJ=/paint|layout|strict|content/,Wl=e=>!!e&&e!=="none";let qb;function c1(e){const t=Xs(e)?Zs(e):e;return Wl(t.transform)||Wl(t.translate)||Wl(t.scale)||Wl(t.rotate)||Wl(t.perspective)||!u1()&&(Wl(t.backdropFilter)||Wl(t.filter))||XJ.test(t.willChange||"")||ZJ.test(t.contain||"")}function QJ(e){let t=ul(e);for(;la(t)&&!Wu(t);){if(c1(t))return t;if(Ov(t))return null;t=ul(t)}return null}function u1(){return qb==null&&(qb=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),qb}function Wu(e){return/^(html|body|#document)$/.test(od(e))}function Zs(e){return fs(e).getComputedStyle(e)}function Dv(e){return Xs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ul(e){if(od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||SN(e)&&e.host||No(e);return SN(t)?t.host:t}function AI(e){const t=ul(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:la(t)&&If(t)?t:AI(t)}function ff(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=AI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=fs(i);if(s){const l=R0(o);return t.concat(o,o.visualViewport||[],If(i)?i:[],l&&n?ff(l):[])}else return t.concat(i,ff(i,[],n))}function R0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function NI(e){const t=Zs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=la(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=$g(n)!==s||$g(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function d1(e){return Xs(e)?e:e.contextElement}function Bu(e){const t=d1(e);if(!la(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=NI(t);let o=(s?$g(n.width):n.width)/r,l=(s?$g(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const JJ=Eo(0);function MI(e){const t=fs(e);return!u1()||!t.visualViewport?JJ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function eee(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==fs(e)?!1:t}function lc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=d1(e);let o=Eo(1);t&&(r?Xs(r)&&(o=Bu(r)):o=Bu(e));const l=eee(s,n,r)?MI(s):Eo(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,h=i.width/o.x,p=i.height/o.y;if(s){const y=fs(s),v=r&&Xs(r)?fs(r):r;let b=y,w=R0(b);for(;w&&r&&v!==b;){const x=Bu(w),E=w.getBoundingClientRect(),k=Zs(w),T=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,N=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=T,d+=N,b=fs(w),w=R0(b)}}return Ug({width:h,height:p,x:u,y:d})}function Pv(e,t){const n=Dv(e).scrollLeft;return t?t.left+n:lc(No(e)).left+n}function OI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Pv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function tee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Ov(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=Eo(1);const h=Eo(0),p=la(r);if((p||!p&&!s)&&((od(r)!=="body"||If(o))&&(u=Dv(r)),p)){const v=lc(r);d=Bu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?OI(o,u):Eo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function nee(e){return Array.from(e.getClientRects())}function ree(e){const t=No(e),n=Dv(e),r=e.ownerDocument.body,i=hs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=hs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Pv(e);const l=-n.scrollTop;return Zs(r).direction==="rtl"&&(o+=hs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const xN=25;function iee(e,t){const n=fs(e),r=No(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=u1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Pv(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,b=Math.abs(r.clientWidth-p.clientWidth-v);b<=xN&&(s-=b)}else d<=xN&&(s+=d);return{width:s,height:o,x:l,y:u}}function see(e,t){const n=lc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=la(e)?Bu(e):Eo(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function EN(e,t,n){let r;if(t==="viewport")r=iee(e,n);else if(t==="document")r=ree(No(e));else if(Xs(t))r=see(t,n);else{const i=MI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ug(r)}function DI(e,t){const n=ul(e);return n===t||!Xs(n)||Wu(n)?!1:Zs(n).position==="fixed"||DI(n,t)}function oee(e,t){const n=t.get(e);if(n)return n;let r=ff(e,[],!1).filter(l=>Xs(l)&&od(l)!=="body"),i=null;const s=Zs(e).position==="fixed";let o=s?ul(e):e;for(;Xs(o)&&!Wu(o);){const l=Zs(o),u=c1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||If(o)&&!u&&DI(e,o))?r=r.filter(h=>h!==o):i=l,o=ul(o)}return t.set(e,r),r}function aee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Ov(t)?[]:oee(t,this._c):[].concat(n),r],l=EN(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=EN(t,o[y],i);u=hs(v.top,u),d=cl(v.right,d),h=cl(v.bottom,h),p=hs(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function lee(e){const{width:t,height:n}=NI(e);return{width:t,height:n}}function cee(e,t,n){const r=la(t),i=No(t),s=n==="fixed",o=lc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=Eo(0);function d(){u.x=Pv(i)}if(r||!r&&!s)if((od(t)!=="body"||If(i))&&(l=Dv(t)),r){const v=lc(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?OI(i,l):Eo(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function Vb(e){return Zs(e).position==="static"}function CN(e,t){if(!la(e)||Zs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return No(e)===n&&(n=n.ownerDocument.body),n}function PI(e,t){const n=fs(e);if(Ov(e))return n;if(!la(e)){let i=ul(e);for(;i&&!Wu(i);){if(Xs(i)&&!Vb(i))return i;i=ul(i)}return n}let r=CN(e,t);for(;r&&GJ(r)&&Vb(r);)r=CN(r,t);return r&&Wu(r)&&Vb(r)&&!c1(r)?n:r||QJ(e)||n}const uee=async function(e){const t=this.getOffsetParent||PI,n=this.getDimensions,r=await n(e.floating);return{reference:cee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function dee(e){return Zs(e).direction==="rtl"}const hee={convertOffsetParentRelativeRectToViewportRelativeRect:tee,getDocumentElement:No,getClippingRect:aee,getOffsetParent:PI,getElementRects:uee,getClientRects:nee,getDimensions:lee,getScale:Bu,isElement:Xs,isRTL:dee};function LI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function fee(e,t){let n=null,r;const i=No(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:h,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const b=Im(p),w=Im(i.clientWidth-(h+y)),x=Im(i.clientHeight-(p+v)),E=Im(h),T={rootMargin:-b+"px "+-w+"px "+-x+"px "+-E+"px",threshold:hs(0,cl(1,u))||1};let N=!0;function z(R){const F=R[0].intersectionRatio;if(F!==u){if(!N)return o();F?o(!1,F):r=setTimeout(()=>{o(!1,1e-7)},1e3)}F===1&&!LI(d,e.getBoundingClientRect())&&o(),N=!1}try{n=new IntersectionObserver(z,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(z,T)}n.observe(e)}return o(!0),s}function pee(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=d1(e),h=i||s?[...d?ff(d):[],...t?ff(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?fee(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 T;(T=v)==null||T.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let b,w=u?lc(e):null;u&&x();function x(){const E=lc(e);w&&!LI(w,E)&&n(),w=E,b=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(b)}}const mee=qJ,gee=VJ,vee=HJ,yee=KJ,_ee=UJ,kN=$J,bee=YJ,wee=(e,t,n)=>{const r=new Map,i={platform:hee,...n},s={...i.platform,_c:r};return FJ(e,t,{...i,platform:s})};var See=typeof document<"u",xee=function(){},gg=See?_.useLayoutEffect:xee;function Wg(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(!Wg(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)&&!Wg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function II(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function TN(e,t){const n=II(e);return Math.round(t*n)/n}function Yb(e){const t=_.useRef(e);return gg(()=>{t.current=e}),t}function Eee(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]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=_.useState(r);Wg(y,r)||v(r);const[b,w]=_.useState(null),[x,E]=_.useState(null),k=_.useCallback(K=>{K!==R.current&&(R.current=K,w(K))},[]),T=_.useCallback(K=>{K!==F.current&&(F.current=K,E(K))},[]),N=s||b,z=o||x,R=_.useRef(null),F=_.useRef(null),P=_.useRef(h),q=u!=null,H=Yb(u),$=Yb(i),D=Yb(d),M=_.useCallback(()=>{if(!R.current||!F.current)return;const K={placement:t,strategy:n,middleware:y};$.current&&(K.platform=$.current),wee(R.current,F.current,K).then(U=>{const A={...U,isPositioned:D.current!==!1};j.current&&!Wg(P.current,A)&&(P.current=A,nd.flushSync(()=>{p(A)}))})},[y,t,n,$,D]);gg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[d]);const j=_.useRef(!1);gg(()=>(j.current=!0,()=>{j.current=!1}),[]),gg(()=>{if(N&&(R.current=N),z&&(F.current=z),N&&z){if(H.current)return H.current(N,z,M);M()}},[N,z,M,H,q]);const L=_.useMemo(()=>({reference:R,floating:F,setReference:k,setFloating:T}),[k,T]),O=_.useMemo(()=>({reference:N,floating:z}),[N,z]),Y=_.useMemo(()=>{const K={position:n,left:0,top:0};if(!O.floating)return K;const U=TN(O.floating,h.x),A=TN(O.floating,h.y);return l?{...K,transform:"translate("+U+"px, "+A+"px)",...II(O.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:A}},[n,l,O.floating,h.x,h.y]);return _.useMemo(()=>({...h,update:M,refs:L,elements:O,floatingStyles:Y}),[h,M,L,O,Y])}const Cee=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?kN({element:r.current,padding:i}).fn(n):{}:r?kN({element:r,padding:i}).fn(n):{}}}},kee=(e,t)=>{const n=mee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Tee=(e,t)=>{const n=gee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ree=(e,t)=>({fn:bee(e).fn,options:[e,t]}),Aee=(e,t)=>{const n=vee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Nee=(e,t)=>{const n=yee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Mee=(e,t)=>{const n=_ee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Oee=(e,t)=>{const n=Cee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Dee="Arrow",zI=_.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Qt.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"})})});zI.displayName=Dee;var Pee=zI,h1="Popper",[BI,bl]=aa(h1),[Lee,jI]=BI(h1),FI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return g.jsx(Lee,{scope:t,anchor:r,onAnchorChange:i,children:n})};FI.displayName=h1;var $I="PopperAnchor",HI=_.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=jI($I,n),o=_.useRef(null),l=Bn(t,o),u=_.useRef(null);return _.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(Qt.div,{...i,ref:l})});HI.displayName=$I;var f1="PopperContent",[Iee,zee]=BI(f1),UI=_.forwardRef((e,t)=>{var te,de,ve,xe,Re,ze;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:b,...w}=e,x=jI(f1,n),[E,k]=_.useState(null),T=Bn(t,Ye=>k(Ye)),[N,z]=_.useState(null),R=RJ(N),F=(R==null?void 0:R.width)??0,P=(R==null?void 0:R.height)??0,q=r+(s!=="center"?"-"+s:""),H=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},$=Array.isArray(d)?d:[d],D=$.length>0,M={padding:H,boundary:$.filter(jee),altBoundary:D},{refs:j,floatingStyles:L,placement:O,isPositioned:Y,middlewareData:K}=Eee({strategy:"fixed",placement:q,whileElementsMounted:(...Ye)=>pee(...Ye,{animationFrame:v==="always"}),elements:{reference:x.anchor},middleware:[kee({mainAxis:i+P,alignmentAxis:o}),u&&Tee({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Ree():void 0,...M}),u&&Aee({...M}),Nee({...M,apply:({elements:Ye,rects:mt,availableWidth:zt,availableHeight:ge})=>{const{width:he,height:Ve}=mt.reference,ce=Ye.floating.style;ce.setProperty("--radix-popper-available-width",`${zt}px`),ce.setProperty("--radix-popper-available-height",`${ge}px`),ce.setProperty("--radix-popper-anchor-width",`${he}px`),ce.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),N&&Oee({element:N,padding:l}),Fee({arrowWidth:F,arrowHeight:P}),y&&Mee({strategy:"referenceHidden",...M})]}),[U,A]=VI(O),W=To(b);Ti(()=>{Y&&(W==null||W())},[Y,W]);const G=(te=K.arrow)==null?void 0:te.x,I=(de=K.arrow)==null?void 0:de.y,ne=((ve=K.arrow)==null?void 0:ve.centerOffset)!==0,[ie,se]=_.useState();return Ti(()=>{E&&se(window.getComputedStyle(E).zIndex)},[E]),g.jsx("div",{ref:j.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:Y?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ie,"--radix-popper-transform-origin":[(xe=K.transformOrigin)==null?void 0:xe.x,(Re=K.transformOrigin)==null?void 0:Re.y].join(" "),...((ze=K.hide)==null?void 0:ze.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(Iee,{scope:n,placedSide:U,onArrowChange:z,arrowX:G,arrowY:I,shouldHideArrow:ne,children:g.jsx(Qt.div,{"data-side":U,"data-align":A,...w,ref:T,style:{...w.style,animation:Y?void 0:"none"}})})})});UI.displayName=f1;var WI="PopperArrow",Bee={top:"bottom",right:"left",bottom:"top",left:"right"},qI=_.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=zee(WI,r),o=Bee[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(Pee,{...i,ref:n,style:{...i.style,display:"block"}})})});qI.displayName=WI;function jee(e){return e!==null}var Fee=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]=VI(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 b="",w="";return d==="bottom"?(b=o?p:`${y}px`,w=`${-u}px`):d==="top"?(b=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(b=`${-u}px`,w=o?p:`${v}px`):d==="left"&&(b=`${r.floating.width+u}px`,w=o?p:`${v}px`),{data:{x:b,y:w}}}});function VI(e){const[t,n="center"]=e.split("-");return[t,n]}var Lv=FI,zf=HI,Iv=UI,zv=qI,Kb="rovingFocusGroup.onEntryFocus",$ee={bubbles:!1,cancelable:!0},Bf="RovingFocusGroup",[A0,YI,Hee]=Xx(Bf),[Uee,KI]=aa(Bf,[Hee]),[Wee,qee]=Uee(Bf),GI=_.forwardRef((e,t)=>g.jsx(A0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(A0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(Vee,{...e,ref:t})})}));GI.displayName=Bf;var Vee=_.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=_.useRef(null),v=Bn(t,y),b=Zx(s),[w,x]=oc({prop:o,defaultProp:l??null,onChange:u,caller:Bf}),[E,k]=_.useState(!1),T=To(d),N=YI(n),z=_.useRef(!1),[R,F]=_.useState(0);return _.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(Kb,T),()=>P.removeEventListener(Kb,T)},[T]),g.jsx(Wee,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:w,onItemFocus:_.useCallback(P=>x(P),[x]),onItemShiftTab:_.useCallback(()=>k(!0),[]),onFocusableItemAdd:_.useCallback(()=>F(P=>P+1),[]),onFocusableItemRemove:_.useCallback(()=>F(P=>P-1),[]),children:g.jsx(Qt.div,{tabIndex:E||R===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:vt(e.onMouseDown,()=>{z.current=!0}),onFocus:vt(e.onFocus,P=>{const q=!z.current;if(P.target===P.currentTarget&&q&&!E){const H=new CustomEvent(Kb,$ee);if(P.currentTarget.dispatchEvent(H),!H.defaultPrevented){const $=N().filter(O=>O.focusable),D=$.find(O=>O.active),M=$.find(O=>O.id===w),L=[D,M,...$].filter(Boolean).map(O=>O.ref.current);QI(L,h)}}z.current=!1}),onBlur:vt(e.onBlur,()=>k(!1))})})}),XI="RovingFocusGroupItem",ZI=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=qee(XI,n),p=h.currentTabStopId===d,y=YI(n),{onFocusableItemAdd:v,onFocusableItemRemove:b,currentTabStopId:w}=h;return _.useEffect(()=>{if(r)return v(),()=>b()},[r,v,b]),g.jsx(A0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Qt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:vt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:vt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:vt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=Gee(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let T=y().filter(N=>N.focusable).map(N=>N.ref.current);if(E==="last")T.reverse();else if(E==="prev"||E==="next"){E==="prev"&&T.reverse();const N=T.indexOf(x.currentTarget);T=h.loop?Xee(T,N+1):T.slice(N+1)}setTimeout(()=>QI(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});ZI.displayName=XI;var Yee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Kee(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Gee(e,t,n){const r=Kee(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Yee[r]}function QI(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Xee(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zee=GI,Qee=ZI,N0=["Enter"," "],Jee=["ArrowDown","PageUp","Home"],JI=["ArrowUp","PageDown","End"],ete=[...Jee,...JI],tte={ltr:[...N0,"ArrowRight"],rtl:[...N0,"ArrowLeft"]},nte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},jf="Menu",[pf,rte,ite]=Xx(jf),[bc,ez]=aa(jf,[ite,bl,KI]),Bv=bl(),tz=KI(),[ste,wc]=bc(jf),[ote,Ff]=bc(jf),nz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Bv(t),[u,d]=_.useState(null),h=_.useRef(!1),p=To(s),y=Zx(i);return _.useEffect(()=>{const v=()=>{h.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>h.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),g.jsx(Lv,{...l,children:g.jsx(ste,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(ote,{scope:t,onClose:_.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};nz.displayName=jf;var ate="MenuAnchor",p1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Bv(n);return g.jsx(zf,{...i,...r,ref:t})});p1.displayName=ate;var m1="MenuPortal",[lte,rz]=bc(m1,{forceMount:void 0}),iz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=wc(m1,t);return g.jsx(lte,{scope:t,forceMount:n,children:g.jsx(Bs,{present:n||s.open,children:g.jsx(id,{asChild:!0,container:i,children:r})})})};iz.displayName=m1;var Ds="MenuContent",[cte,g1]=bc(Ds),sz=_.forwardRef((e,t)=>{const n=rz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=Ff(Ds,e.__scopeMenu);return g.jsx(pf.Provider,{scope:e.__scopeMenu,children:g.jsx(Bs,{present:r||s.open,children:g.jsx(pf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(ute,{...i,ref:t}):g.jsx(dte,{...i,ref:t})})})})}),ute=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu),r=_.useRef(null),i=Bn(t,r);return _.useEffect(()=>{const s=r.current;if(s)return Av(s)},[]),g.jsx(v1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:vt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),dte=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu);return g.jsx(v1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),hte=ll("MenuContent.ScrollLock"),v1=_.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:b,...w}=e,x=wc(Ds,n),E=Ff(Ds,n),k=Bv(n),T=tz(n),N=rte(n),[z,R]=_.useState(null),F=_.useRef(null),P=Bn(t,F,x.onContentChange),q=_.useRef(0),H=_.useRef(""),$=_.useRef(0),D=_.useRef(null),M=_.useRef("right"),j=_.useRef(0),L=b?Lf:_.Fragment,O=b?{as:hte,allowPinchZoom:!0}:void 0,Y=U=>{var te,de;const A=H.current+U,W=N().filter(ve=>!ve.disabled),G=document.activeElement,I=(te=W.find(ve=>ve.ref.current===G))==null?void 0:te.textValue,ne=W.map(ve=>ve.textValue),ie=Ete(ne,A,I),se=(de=W.find(ve=>ve.textValue===ie))==null?void 0:de.ref.current;(function ve(xe){H.current=xe,window.clearTimeout(q.current),xe!==""&&(q.current=window.setTimeout(()=>ve(""),1e3))})(A),se&&setTimeout(()=>se.focus())};_.useEffect(()=>()=>window.clearTimeout(q.current),[]),Tv();const K=_.useCallback(U=>{var W,G;return M.current===((W=D.current)==null?void 0:W.side)&&kte(U,(G=D.current)==null?void 0:G.area)},[]);return g.jsx(cte,{scope:n,searchRef:H,onItemEnter:_.useCallback(U=>{K(U)&&U.preventDefault()},[K]),onItemLeave:_.useCallback(U=>{var A;K(U)||((A=F.current)==null||A.focus(),R(null))},[K]),onTriggerLeave:_.useCallback(U=>{K(U)&&U.preventDefault()},[K]),pointerGraceTimerRef:$,onPointerGraceIntentChange:_.useCallback(U=>{D.current=U},[]),children:g.jsx(L,{...O,children:g.jsx(Pf,{asChild:!0,trapped:i,onMountAutoFocus:vt(s,U=>{var A;U.preventDefault(),(A=F.current)==null||A.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(rd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Zee,{asChild:!0,...T,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:z,onCurrentTabStopIdChange:R,onEntryFocus:vt(u,U=>{E.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(Iv,{role:"menu","aria-orientation":"vertical","data-state":wz(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:vt(w.onKeyDown,U=>{const W=U.target.closest("[data-radix-menu-content]")===U.currentTarget,G=U.ctrlKey||U.altKey||U.metaKey,I=U.key.length===1;W&&(U.key==="Tab"&&U.preventDefault(),!G&&I&&Y(U.key));const ne=F.current;if(U.target!==ne||!ete.includes(U.key))return;U.preventDefault();const se=N().filter(te=>!te.disabled).map(te=>te.ref.current);JI.includes(U.key)&&se.reverse(),Ste(se)}),onBlur:vt(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(q.current),H.current="")}),onPointerMove:vt(e.onPointerMove,mf(U=>{const A=U.target,W=j.current!==U.clientX;if(U.currentTarget.contains(A)&&W){const G=U.clientX>j.current?"right":"left";M.current=G,j.current=U.clientX}}))})})})})})})});sz.displayName=Ds;var fte="MenuGroup",y1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Qt.div,{role:"group",...r,ref:t})});y1.displayName=fte;var pte="MenuLabel",oz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Qt.div,{...r,ref:t})});oz.displayName=pte;var qg="MenuItem",RN="menu.itemSelect",jv=_.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=_.useRef(null),o=Ff(qg,e.__scopeMenu),l=g1(qg,e.__scopeMenu),u=Bn(t,s),d=_.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(RN,{bubbles:!0,cancelable:!0});p.addEventListener(RN,v=>r==null?void 0:r(v),{once:!0}),YL(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(az,{...i,ref:u,disabled:n,onClick:vt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:vt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:vt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||N0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});jv.displayName=qg;var az=_.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=g1(qg,n),l=tz(n),u=_.useRef(null),d=Bn(t,u),[h,p]=_.useState(!1),[y,v]=_.useState("");return _.useEffect(()=>{const b=u.current;b&&v((b.textContent??"").trim())},[s.children]),g.jsx(pf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(Qee,{asChild:!0,...l,focusable:!r,children:g.jsx(Qt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:vt(e.onPointerMove,mf(b=>{r?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:vt(e.onPointerLeave,mf(b=>o.onItemLeave(b))),onFocus:vt(e.onFocus,()=>p(!0)),onBlur:vt(e.onBlur,()=>p(!1))})})})}),mte="MenuCheckboxItem",lz=_.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(fz,{scope:e.__scopeMenu,checked:n,children:g.jsx(jv,{role:"menuitemcheckbox","aria-checked":Vg(n)?"mixed":n,...i,ref:t,"data-state":b1(n),onSelect:vt(i.onSelect,()=>r==null?void 0:r(Vg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});lz.displayName=mte;var cz="MenuRadioGroup",[gte,vte]=bc(cz,{value:void 0,onValueChange:()=>{}}),uz=_.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return g.jsx(gte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(y1,{...i,ref:t})})});uz.displayName=cz;var dz="MenuRadioItem",hz=_.forwardRef((e,t)=>{const{value:n,...r}=e,i=vte(dz,e.__scopeMenu),s=n===i.value;return g.jsx(fz,{scope:e.__scopeMenu,checked:s,children:g.jsx(jv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":b1(s),onSelect:vt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});hz.displayName=dz;var _1="MenuItemIndicator",[fz,yte]=bc(_1,{checked:!1}),pz=_.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=yte(_1,n);return g.jsx(Bs,{present:r||Vg(s.checked)||s.checked===!0,children:g.jsx(Qt.span,{...i,ref:t,"data-state":b1(s.checked)})})});pz.displayName=_1;var _te="MenuSeparator",mz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Qt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});mz.displayName=_te;var bte="MenuArrow",gz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Bv(n);return g.jsx(zv,{...i,...r,ref:t})});gz.displayName=bte;var wte="MenuSub",[_Te,vz]=bc(wte),Ph="MenuSubTrigger",yz=_.forwardRef((e,t)=>{const n=wc(Ph,e.__scopeMenu),r=Ff(Ph,e.__scopeMenu),i=vz(Ph,e.__scopeMenu),s=g1(Ph,e.__scopeMenu),o=_.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=_.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return _.useEffect(()=>h,[h]),_.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),g.jsx(p1,{asChild:!0,...d,children:g.jsx(az,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":wz(n.open),...e,ref:ia(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:vt(e.onPointerMove,mf(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:vt(e.onPointerLeave,mf(p=>{var v,b;h();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(b=n.content)==null?void 0:b.dataset.side,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],T=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,y:p.clientY},{x:k,y:y.top},{x:T,y:y.top},{x:T,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:vt(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||tte[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});yz.displayName=Ph;var _z="MenuSubContent",bz=_.forwardRef((e,t)=>{const n=rz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=Ff(Ds,e.__scopeMenu),l=vz(_z,e.__scopeMenu),u=_.useRef(null),d=Bn(t,u);return g.jsx(pf.Provider,{scope:e.__scopeMenu,children:g.jsx(Bs,{present:r||s.open,children:g.jsx(pf.Slot,{scope:e.__scopeMenu,children:g.jsx(v1,{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:vt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:vt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:vt(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())})})})})})});bz.displayName=_z;function wz(e){return e?"open":"closed"}function Vg(e){return e==="indeterminate"}function b1(e){return Vg(e)?"indeterminate":e?"checked":"unchecked"}function Ste(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function xte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Ete(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=xte(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 Cte(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 kte(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Cte(n,t)}function mf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Tte=nz,Rte=p1,Ate=iz,Nte=sz,Mte=y1,Ote=oz,Dte=jv,Pte=lz,Lte=uz,Ite=hz,zte=pz,Bte=mz,jte=gz,Fte=yz,$te=bz,Fv="DropdownMenu",[Hte]=aa(Fv,[ez]),ji=ez(),[Ute,Sz]=Hte(Fv),xz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=ji(t),d=_.useRef(null),[h,p]=oc({prop:i,defaultProp:s??!1,onChange:o,caller:Fv});return g.jsx(Ute,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:_.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(Tte,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};xz.displayName=Fv;var Ez="DropdownMenuTrigger",Cz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Sz(Ez,n),o=ji(n);return g.jsx(Rte,{asChild:!0,...o,children:g.jsx(Qt.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:ia(t,s.triggerRef),onPointerDown:vt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:vt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Cz.displayName=Ez;var Wte="DropdownMenuPortal",kz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=ji(t);return g.jsx(Ate,{...r,...n})};kz.displayName=Wte;var Tz="DropdownMenuContent",Rz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Sz(Tz,n),s=ji(n),o=_.useRef(!1);return g.jsx(Nte,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:vt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:vt(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)"}})});Rz.displayName=Tz;var qte="DropdownMenuGroup",Vte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Mte,{...i,...r,ref:t})});Vte.displayName=qte;var Yte="DropdownMenuLabel",Az=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Ote,{...i,...r,ref:t})});Az.displayName=Yte;var Kte="DropdownMenuItem",Nz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Dte,{...i,...r,ref:t})});Nz.displayName=Kte;var Gte="DropdownMenuCheckboxItem",Mz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Pte,{...i,...r,ref:t})});Mz.displayName=Gte;var Xte="DropdownMenuRadioGroup",Zte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Lte,{...i,...r,ref:t})});Zte.displayName=Xte;var Qte="DropdownMenuRadioItem",Jte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Ite,{...i,...r,ref:t})});Jte.displayName=Qte;var ene="DropdownMenuItemIndicator",Oz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(zte,{...i,...r,ref:t})});Oz.displayName=ene;var tne="DropdownMenuSeparator",Dz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Bte,{...i,...r,ref:t})});Dz.displayName=tne;var nne="DropdownMenuArrow",rne=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(jte,{...i,...r,ref:t})});rne.displayName=nne;var ine="DropdownMenuSubTrigger",sne=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx(Fte,{...i,...r,ref:t})});sne.displayName=ine;var one="DropdownMenuSubContent",ane=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return g.jsx($te,{...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)"}})});ane.displayName=one;var lne=xz,cne=Cz,une=kz,dne=Rz,hne=Az,fne=Nz,pne=Mz,mne=Oz,gne=Dz;function AN(e,[t,n]){return Math.min(n,Math.max(t,e))}var $v="Popover",[Pz]=aa($v,[bl]),$f=bl(),[vne,wl]=Pz($v),Lz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=$f(t),u=_.useRef(null),[d,h]=_.useState(!1),[p,y]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:$v});return g.jsx(Lv,{...l,children:g.jsx(vne,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:_.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:o,children:n})})};Lz.displayName=$v;var Iz="PopoverAnchor",yne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Iz,n),s=$f(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return _.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(zf,{...s,...r,ref:t})});yne.displayName=Iz;var zz="PopoverTrigger",Bz=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(zz,n),s=$f(n),o=Bn(t,i.triggerRef),l=g.jsx(Qt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Uz(i.open),...r,ref:o,onClick:vt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(zf,{asChild:!0,...s,children:l})});Bz.displayName=zz;var w1="PopoverPortal",[_ne,bne]=Pz(w1,{forceMount:void 0}),jz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=wl(w1,t);return g.jsx(_ne,{scope:t,forceMount:n,children:g.jsx(Bs,{present:n||s.open,children:g.jsx(id,{asChild:!0,container:i,children:r})})})};jz.displayName=w1;var qu="PopoverContent",Fz=_.forwardRef((e,t)=>{const n=bne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=wl(qu,e.__scopePopover);return g.jsx(Bs,{present:r||s.open,children:s.modal?g.jsx(Sne,{...i,ref:t}):g.jsx(xne,{...i,ref:t})})});Fz.displayName=qu;var wne=ll("PopoverContent.RemoveScroll"),Sne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(null),i=Bn(t,r),s=_.useRef(!1);return _.useEffect(()=>{const o=r.current;if(o)return Av(o)},[]),g.jsx(Lf,{as:wne,allowPinchZoom:!0,children:g.jsx($z,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:vt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:vt(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:vt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),xne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return g.jsx($z,{...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()}})}),$z=_.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=wl(qu,n),v=$f(n);return Tv(),g.jsx(Pf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(rd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(Iv,{"data-state":Uz(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)"}})})})}),Hz="PopoverClose",Ene=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Hz,n);return g.jsx(Qt.button,{type:"button",...r,ref:t,onClick:vt(e.onClick,()=>i.onOpenChange(!1))})});Ene.displayName=Hz;var Cne="PopoverArrow",kne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$f(n);return g.jsx(zv,{...i,...r,ref:t})});kne.displayName=Cne;function Uz(e){return e?"open":"closed"}var Tne=Lz,Rne=Bz,Ane=jz,Nne=Fz,Mne=[" ","Enter","ArrowUp","ArrowDown"],One=[" ","Enter"],cc="Select",[Hv,Uv,Dne]=Xx(cc),[ad]=aa(cc,[Dne,bl]),Wv=bl(),[Pne,Sl]=ad(cc),[Lne,Ine]=ad(cc),Wz=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:b}=e,w=Wv(t),[x,E]=_.useState(null),[k,T]=_.useState(null),[N,z]=_.useState(!1),R=Zx(d),[F,P]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:cc}),[q,H]=oc({prop:o,defaultProp:l,onChange:u,caller:cc}),$=_.useRef(null),D=x?b||!!x.closest("form"):!0,[M,j]=_.useState(new Set),L=Array.from(M).map(O=>O.props.value).join(";");return g.jsx(Lv,{...w,children:g.jsxs(Pne,{required:v,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:N,onValueNodeHasChildrenChange:z,contentId:gi(),value:q,onValueChange:H,open:F,onOpenChange:P,dir:R,triggerPointerDownPosRef:$,disabled:y,children:[g.jsx(Hv.Provider,{scope:t,children:g.jsx(Lne,{scope:e.__scopeSelect,onNativeOptionAdd:_.useCallback(O=>{j(Y=>new Set(Y).add(O))},[]),onNativeOptionRemove:_.useCallback(O=>{j(Y=>{const K=new Set(Y);return K.delete(O),K})},[]),children:n})}),D?g.jsxs(hB,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:q,onChange:O=>H(O.target.value),disabled:y,form:b,children:[q===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};Wz.displayName=cc;var qz="SelectTrigger",Vz=_.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Wv(n),o=Sl(qz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Uv(n),h=_.useRef("touch"),[p,y,v]=pB(w=>{const x=d().filter(T=>!T.disabled),E=x.find(T=>T.value===o.value),k=mB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),b=w=>{l||(o.onOpenChange(!0),v()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return g.jsx(zf,{asChild:!0,...s,children:g.jsx(Qt.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":fB(o.value)?"":void 0,...i,ref:u,onClick:vt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&b(w)}),onPointerDown:vt(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"&&(b(w),w.preventDefault())}),onKeyDown:vt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&Mne.includes(w.key)&&(b(),w.preventDefault())})})})});Vz.displayName=qz;var Yz="SelectValue",Kz=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=Sl(Yz,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ti(()=>{d(h)},[d,h]),g.jsx(Qt.span,{...l,ref:p,style:{pointerEvents:"none"},children:fB(u.value)?g.jsx(g.Fragment,{children:o}):s})});Kz.displayName=Yz;var zne="SelectIcon",Gz=_.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Qt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});Gz.displayName=zne;var Bne="SelectPortal",Xz=e=>g.jsx(id,{asChild:!0,...e});Xz.displayName=Bne;var uc="SelectContent",Zz=_.forwardRef((e,t)=>{const n=Sl(uc,e.__scopeSelect),[r,i]=_.useState();if(Ti(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?nd.createPortal(g.jsx(Qz,{scope:e.__scopeSelect,children:g.jsx(Hv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(Jz,{...e,ref:t})});Zz.displayName=uc;var qs=10,[Qz,xl]=ad(uc),jne="SelectContentImpl",Fne=ll("SelectContent.RemoveScroll"),Jz=_.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:b,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=Sl(uc,n),[T,N]=_.useState(null),[z,R]=_.useState(null),F=Bn(t,te=>N(te)),[P,q]=_.useState(null),[H,$]=_.useState(null),D=Uv(n),[M,j]=_.useState(!1),L=_.useRef(!1);_.useEffect(()=>{if(T)return Av(T)},[T]),Tv();const O=_.useCallback(te=>{const[de,...ve]=D().map(ze=>ze.ref.current),[xe]=ve.slice(-1),Re=document.activeElement;for(const ze of te)if(ze===Re||(ze==null||ze.scrollIntoView({block:"nearest"}),ze===de&&z&&(z.scrollTop=0),ze===xe&&z&&(z.scrollTop=z.scrollHeight),ze==null||ze.focus(),document.activeElement!==Re))return},[D,z]),Y=_.useCallback(()=>O([P,T]),[O,P,T]);_.useEffect(()=>{M&&Y()},[M,Y]);const{onOpenChange:K,triggerPointerDownPosRef:U}=k;_.useEffect(()=>{if(T){let te={x:0,y:0};const de=xe=>{var Re,ze;te={x:Math.abs(Math.round(xe.pageX)-(((Re=U.current)==null?void 0:Re.x)??0)),y:Math.abs(Math.round(xe.pageY)-(((ze=U.current)==null?void 0:ze.y)??0))}},ve=xe=>{te.x<=10&&te.y<=10?xe.preventDefault():T.contains(xe.target)||K(!1),document.removeEventListener("pointermove",de),U.current=null};return U.current!==null&&(document.addEventListener("pointermove",de),document.addEventListener("pointerup",ve,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",de),document.removeEventListener("pointerup",ve,{capture:!0})}}},[T,K,U]),_.useEffect(()=>{const te=()=>K(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[K]);const[A,W]=pB(te=>{const de=D().filter(Re=>!Re.disabled),ve=de.find(Re=>Re.ref.current===document.activeElement),xe=mB(de,te,ve);xe&&setTimeout(()=>xe.ref.current.focus())}),G=_.useCallback((te,de,ve)=>{const xe=!L.current&&!ve;(k.value!==void 0&&k.value===de||xe)&&(q(te),xe&&(L.current=!0))},[k.value]),I=_.useCallback(()=>T==null?void 0:T.focus(),[T]),ne=_.useCallback((te,de,ve)=>{const xe=!L.current&&!ve;(k.value!==void 0&&k.value===de||xe)&&$(te)},[k.value]),ie=r==="popper"?M0:eB,se=ie===M0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:b,hideWhenDetached:w,avoidCollisions:x}:{};return g.jsx(Qz,{scope:n,content:T,viewport:z,onViewportChange:R,itemRefCallback:G,selectedItem:P,onItemLeave:I,itemTextRefCallback:ne,focusSelectedItem:Y,selectedItemText:H,position:r,isPositioned:M,searchRef:A,children:g.jsx(Lf,{as:Fne,allowPinchZoom:!0,children:g.jsx(Pf,{asChild:!0,trapped:k.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:vt(i,te=>{var de;(de=k.trigger)==null||de.focus({preventScroll:!0}),te.preventDefault()}),children:g.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(ie,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:te=>te.preventDefault(),...E,...se,onPlaced:()=>j(!0),ref:F,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:vt(E.onKeyDown,te=>{const de=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!de&&te.key.length===1&&W(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let xe=D().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);if(["ArrowUp","End"].includes(te.key)&&(xe=xe.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const Re=te.target,ze=xe.indexOf(Re);xe=xe.slice(ze+1)}setTimeout(()=>O(xe)),te.preventDefault()}})})})})})})});Jz.displayName=jne;var $ne="SelectItemAlignedPosition",eB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=Sl(uc,n),o=xl(uc,n),[l,u]=_.useState(null),[d,h]=_.useState(null),p=Bn(t,F=>h(F)),y=Uv(n),v=_.useRef(!1),b=_.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,T=_.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const F=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),q=s.valueNode.getBoundingClientRect(),H=E.getBoundingClientRect();if(s.dir!=="rtl"){const Re=H.left-P.left,ze=q.left-Re,Ye=F.left-ze,mt=F.width+Ye,zt=Math.max(mt,P.width),ge=window.innerWidth-qs,he=AN(ze,[qs,Math.max(qs,ge-zt)]);l.style.minWidth=mt+"px",l.style.left=he+"px"}else{const Re=P.right-H.right,ze=window.innerWidth-q.right-Re,Ye=window.innerWidth-F.right-ze,mt=F.width+Ye,zt=Math.max(mt,P.width),ge=window.innerWidth-qs,he=AN(ze,[qs,Math.max(qs,ge-zt)]);l.style.minWidth=mt+"px",l.style.right=he+"px"}const $=y(),D=window.innerHeight-qs*2,M=w.scrollHeight,j=window.getComputedStyle(d),L=parseInt(j.borderTopWidth,10),O=parseInt(j.paddingTop,10),Y=parseInt(j.borderBottomWidth,10),K=parseInt(j.paddingBottom,10),U=L+O+M+K+Y,A=Math.min(x.offsetHeight*5,U),W=window.getComputedStyle(w),G=parseInt(W.paddingTop,10),I=parseInt(W.paddingBottom,10),ne=F.top+F.height/2-qs,ie=D-ne,se=x.offsetHeight/2,te=x.offsetTop+se,de=L+O+te,ve=U-de;if(de<=ne){const Re=$.length>0&&x===$[$.length-1].ref.current;l.style.bottom="0px";const ze=d.clientHeight-w.offsetTop-w.offsetHeight,Ye=Math.max(ie,se+(Re?I:0)+ze+Y),mt=de+Ye;l.style.height=mt+"px"}else{const Re=$.length>0&&x===$[0].ref.current;l.style.top="0px";const Ye=Math.max(ne,L+w.offsetTop+(Re?G:0)+se)+ve;l.style.height=Ye+"px",w.scrollTop=de-ne+w.offsetTop}l.style.margin=`${qs}px 0`,l.style.minHeight=A+"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]);Ti(()=>T(),[T]);const[N,z]=_.useState();Ti(()=>{d&&z(window.getComputedStyle(d).zIndex)},[d]);const R=_.useCallback(F=>{F&&b.current===!0&&(T(),k==null||k(),b.current=!1)},[T,k]);return g.jsx(Une,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:R,children:g.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:g.jsx(Qt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});eB.displayName=$ne;var Hne="SelectPopperPosition",M0=_.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=qs,...s}=e,o=Wv(n);return g.jsx(Iv,{...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)"}})});M0.displayName=Hne;var[Une,S1]=ad(uc,{}),O0="SelectViewport",tB=_.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=xl(O0,n),o=S1(O0,n),l=Bn(t,s.onViewportChange),u=_.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(Hv.Slot,{scope:n,children:g.jsx(Qt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:vt(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 b=window.innerHeight-qs*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<b){const k=E+v,T=Math.min(b,k),N=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(h.scrollTop=N>0?N:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});tB.displayName=O0;var nB="SelectGroup",[Wne,qne]=ad(nB),Vne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return g.jsx(Wne,{scope:n,id:i,children:g.jsx(Qt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});Vne.displayName=nB;var rB="SelectLabel",Yne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qne(rB,n);return g.jsx(Qt.div,{id:i.id,...r,ref:t})});Yne.displayName=rB;var Yg="SelectItem",[Kne,iB]=ad(Yg),sB=_.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=Sl(Yg,n),u=xl(Yg,n),d=l.value===r,[h,p]=_.useState(s??""),[y,v]=_.useState(!1),b=Bn(t,k=>{var T;return(T=u.itemRefCallback)==null?void 0:T.call(u,k,r,i)}),w=gi(),x=_.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(Kne,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:_.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:g.jsx(Hv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Qt.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:b,onFocus:vt(o.onFocus,()=>v(!0)),onBlur:vt(o.onBlur,()=>v(!1)),onClick:vt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:vt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:vt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:vt(o.onPointerMove,k=>{var T;x.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:vt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:vt(o.onKeyDown,k=>{var N;((N=u.searchRef)==null?void 0:N.current)!==""&&k.key===" "||(One.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});sB.displayName=Yg;var Lh="SelectItemText",oB=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Sl(Lh,n),l=xl(Lh,n),u=iB(Lh,n),d=Ine(Lh,n),[h,p]=_.useState(null),y=Bn(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 Ti(()=>(w(b),()=>x(b)),[w,x,b]),g.jsxs(g.Fragment,{children:[g.jsx(Qt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?nd.createPortal(s.children,o.valueNode):null]})});oB.displayName=Lh;var aB="SelectItemIndicator",lB=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return iB(aB,n).isSelected?g.jsx(Qt.span,{"aria-hidden":!0,...r,ref:t}):null});lB.displayName=aB;var D0="SelectScrollUpButton",cB=_.forwardRef((e,t)=>{const n=xl(D0,e.__scopeSelect),r=S1(D0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{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(dB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});cB.displayName=D0;var P0="SelectScrollDownButton",uB=_.forwardRef((e,t)=>{const n=xl(P0,e.__scopeSelect),r=S1(P0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{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(dB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});uB.displayName=P0;var dB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=xl("SelectScrollButton",n),o=_.useRef(null),l=Uv(n),u=_.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return _.useEffect(()=>()=>u(),[u]),Ti(()=>{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(Qt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:vt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:vt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:vt(i.onPointerLeave,()=>{u()})})}),Gne="SelectSeparator",Xne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Qt.div,{"aria-hidden":!0,...r,ref:t})});Xne.displayName=Gne;var L0="SelectArrow",Zne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Wv(n),s=Sl(L0,n),o=xl(L0,n);return s.open&&o.position==="popper"?g.jsx(zv,{...i,...r,ref:t}):null});Zne.displayName=L0;var Qne="SelectBubbleInput",hB=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=_.useRef(null),s=Bn(r,i),o=TJ(t);return _.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(Qt.select,{...n,style:{...KL,...n.style},ref:s,defaultValue:t})});hB.displayName=Qne;function fB(e){return e===""||e===void 0}function pB(e){const t=To(e),n=_.useRef(""),r=_.useRef(0),i=_.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=_.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return _.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function mB(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Jne(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 Jne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ere=Wz,tre=Vz,nre=Kz,rre=Gz,ire=Xz,sre=Zz,ore=tB,are=sB,lre=oB,cre=lB,ure=cB,dre=uB,[qv]=aa("Tooltip",[bl]),Vv=bl(),gB="TooltipProvider",hre=700,I0="tooltip.open",[fre,x1]=qv(gB),vB=e=>{const{__scopeTooltip:t,delayDuration:n=hre,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=_.useRef(!0),l=_.useRef(!1),u=_.useRef(0);return _.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),g.jsx(fre,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:_.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};vB.displayName=gB;var gf="Tooltip",[pre,Hf]=qv(gf),yB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=x1(gf,e.__scopeTooltip),d=Vv(t),[h,p]=_.useState(null),y=gi(),v=_.useRef(0),b=o??u.disableHoverableContent,w=l??u.delayDuration,x=_.useRef(!1),[E,k]=oc({prop:r,defaultProp:i??!1,onChange:F=>{F?(u.onOpen(),document.dispatchEvent(new CustomEvent(I0))):u.onClose(),s==null||s(F)},caller:gf}),T=_.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),N=_.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,k(!0)},[k]),z=_.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),R=_.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,k(!0),v.current=0},w)},[w,k]);return _.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Lv,{...d,children:g.jsx(pre,{scope:t,contentId:y,open:E,stateAttribute:T,trigger:h,onTriggerChange:p,onTriggerEnter:_.useCallback(()=>{u.isOpenDelayedRef.current?R():N()},[u.isOpenDelayedRef,R,N]),onTriggerLeave:_.useCallback(()=>{b?z():(window.clearTimeout(v.current),v.current=0)},[z,b]),onOpen:N,onClose:z,disableHoverableContent:b,children:n})})};yB.displayName=gf;var z0="TooltipTrigger",_B=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Hf(z0,n),s=x1(z0,n),o=Vv(n),l=_.useRef(null),u=Bn(t,l,i.onTriggerChange),d=_.useRef(!1),h=_.useRef(!1),p=_.useCallback(()=>d.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),g.jsx(zf,{asChild:!0,...o,children:g.jsx(Qt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:vt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:vt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:vt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:vt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:vt(e.onBlur,i.onClose),onClick:vt(e.onClick,i.onClose)})})});_B.displayName=z0;var E1="TooltipPortal",[mre,gre]=qv(E1,{forceMount:void 0}),bB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Hf(E1,t);return g.jsx(mre,{scope:t,forceMount:n,children:g.jsx(Bs,{present:n||s.open,children:g.jsx(id,{asChild:!0,container:i,children:r})})})};bB.displayName=E1;var Vu="TooltipContent",wB=_.forwardRef((e,t)=>{const n=gre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Hf(Vu,e.__scopeTooltip);return g.jsx(Bs,{present:r||o.open,children:o.disableHoverableContent?g.jsx(SB,{side:i,...s,ref:t}):g.jsx(vre,{side:i,...s,ref:t})})}),vre=_.forwardRef((e,t)=>{const n=Hf(Vu,e.__scopeTooltip),r=x1(Vu,e.__scopeTooltip),i=_.useRef(null),s=Bn(t,i),[o,l]=_.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=_.useCallback(()=>{l(null),p(!1)},[p]),v=_.useCallback((b,w)=>{const x=b.currentTarget,E={x:b.clientX,y:b.clientY},k=wre(E,x.getBoundingClientRect()),T=Sre(E,k),N=xre(w.getBoundingClientRect()),z=Cre([...T,...N]);l(z),p(!0)},[p]);return _.useEffect(()=>()=>y(),[y]),_.useEffect(()=>{if(u&&h){const b=x=>v(x,h),w=x=>v(x,u);return u.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[u,h,v,y]),_.useEffect(()=>{if(o){const b=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)),T=!Ere(E,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[u,h,o,d,y]),g.jsx(SB,{...e,ref:s})}),[yre,_re]=qv(gf,{isInside:!1}),bre=JZ("TooltipContent"),SB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Hf(Vu,n),d=Vv(n),{onClose:h}=u;return _.useEffect(()=>(document.addEventListener(I0,h),()=>document.removeEventListener(I0,h)),[h]),_.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(rd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(Iv,{"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(bre,{children:r}),g.jsx(yre,{scope:n,isInside:!0,children:g.jsx(XL,{id:u.contentId,role:"tooltip",children:i||r})})]})})});wB.displayName=Vu;var xB="TooltipArrow",EB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Vv(n);return _re(xB,n).isInside?null:g.jsx(zv,{...i,...r,ref:t})});EB.displayName=xB;function wre(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 Sre(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 xre(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 Ere(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 Cre(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),kre(t)}function kre(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 Tre=vB,Rre=yB,Are=_B,Nre=bB,Mre=wB,Ore=EB;function C1({...e}){return g.jsx(Tne,{"data-slot":"popover",...e})}function k1({...e}){return g.jsx(Rne,{"data-slot":"popover-trigger",...e})}function T1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(Ane,{children:g.jsx(Nne,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const Dre={"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 nc({variant:e,action:t}){const{heading:n,body:r}=Dre[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 Pre={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Lre={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function NN({status:e,className:t}){return g.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Pre[e],t),role:"status","aria-label":Lre[e]})}function CB({layout:e,variant:t="default"}){const n=Ie(w=>w.proxies),r=Ie(w=>w.proxyListLoaded),i=Ie(w=>w.relayClientAuthIssue),s=Ie(w=>w.selectedProxyId),o=Bi(),l=Js(),[u,d]=_.useState(!1),[h,p]=_.useState(null);async function y(w,x){if(h)return;const E=Ot;if(!E){rt.error("请先连接开发机");return}const k=x??w;p(w);try{const T=await E.selectProxy(w);if(!T.success){rt.error(`无法连接 ${k}:${T.error??"未知错误"}`);return}dr("local",ln.proxyId,w),Ie.getState().setProxy(w,x??null),Ie.getState().setProxyOnline(!0),Ie.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestAgentStatuses().then(N=>{const z=qt.getState();for(const R of N)z.setAgentStatus(R.sessionId,R.payload)}).catch(N=>{console.error("[proxy-switcher] post-bind data fetch failed",N)}),E.requestSessionHistory().then(N=>qt.getState().setHistorySessions(N)).catch(N=>{console.error("[proxy-switcher] post-bind data fetch failed",N)}),d(!1),(e==="page"||o.pathname.startsWith("/chat/"))&&l("/sessions")}catch(T){const N=T instanceof Error?T.message:"未知错误";rt.error(`无法连接 ${k}:${N}`)}finally{p(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(nc,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(nc,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(nc,{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(w=>{const x=h===w.proxyId,E=h!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",x?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx(NN,{status:w.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),g.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===w.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&!x&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.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(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});const v=n.find(w=>w.proxyId===s),b=(v==null?void 0:v.name)??(v==null?void 0:v.proxyId)??"未选择开发机";return g.jsxs(C1,{open:u,onOpenChange:d,children:[g.jsx(k1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${b}`,children:[t==="default"&&g.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),g.jsx("span",{className:We("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:b}),g.jsx(gl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(T1,{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(w=>{const x=h===w.proxyId,E=h!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",x?"bg-accent text-accent-foreground":"hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线",children:[g.jsx(NN,{status:w.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?g.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===w.proxyId?g.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&s!==w.proxyId&&!x&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})})]})}const MN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,ON=OP,Ire=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return ON(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=MN(h)||MN(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(b=>{let[w,x]=b;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return ON(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},zre=Ire("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 St({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?ZZ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(zre({variant:t,size:n,className:e})),...i})}function Bre({delayDuration:e=0,...t}){return g.jsx(Tre,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Uf({...e}){return g.jsx(Rre,{"data-slot":"tooltip",...e})}function Wf({...e}){return g.jsx(Are,{"data-slot":"tooltip-trigger",...e})}function qf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(Nre,{children:g.jsxs(Mre,{"data-slot":"tooltip-content",sideOffset:t,className:We("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&g.jsx(Ore,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Yv({...e}){return g.jsx(t1,{"data-slot":"sheet",...e})}function jre({...e}){return g.jsx(kJ,{"data-slot":"sheet-trigger",...e})}function Fre({...e}){return g.jsx(n1,{"data-slot":"sheet-portal",...e})}function $re({className:e,...t}){return g.jsx(r1,{"data-slot":"sheet-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Kv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return g.jsxs(Fre,{children:[g.jsx($re,{className:t}),g.jsxs(i1,{"data-slot":"sheet-content",className:We("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&g.jsxs(s1,{"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(Df,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function R1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function Gv({className:e,...t}){return g.jsx(EI,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Hre({className:e,...t}){return g.jsx(CI,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}function A1({...e}){return g.jsx(lne,{"data-slot":"dropdown-menu",...e})}function N1({...e}){return g.jsx(cne,{"data-slot":"dropdown-menu-trigger",...e})}function M1({className:e,sideOffset:t=4,...n}){return g.jsx(une,{children:g.jsx(dne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function bo({className:e,inset:t,variant:n="default",...r}){return g.jsx(fne,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Gb({className:e,children:t,checked:n,...r}){return g.jsxs(pne,{"data-slot":"dropdown-menu-checkbox-item",className:We("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[g.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:g.jsx(mne,{children:g.jsx(ra,{className:"size-4"})})}),t]})}function zm({className:e,inset:t,...n}){return g.jsx(hne,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Xb({className:e,...t}){return g.jsx(gne,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}const Ure={claude:"Claude Code",codex:"Codex"},DN=["claude","codex"];function Xv(e){return Ure[e]}function kB(e,t){return DN.indexOf(e)-DN.indexOf(t)}function B0(e){return e.provider??"claude"}const j0=60*1e3,F0=60*j0,Wre=24*F0;function TB(e,t=Date.now()){const n=t-e;if(n<j0)return"刚刚";if(n<F0)return`${Math.floor(n/j0)} 分钟前`;if(n<Wre)return`${Math.floor(n/F0)} 小时前`;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 PN={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 $0(e){return e.kind!=="terminal"?PN[e.state]:e.state==="terminated"?PN.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 qre({session:e}){const t=$0(e);return g.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Vre({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Rx:Nx;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 Yre({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Cv(e.name),d=Yx(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?TB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",b=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:We("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&g.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),g.jsxs("button",{type:"button",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[g.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[g.jsx(qre,{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(Vre,{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:Xv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:We("shrink-0",$0(e).text),children:$0(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(A1,{children:[g.jsx(N1,{asChild:!0,children:g.jsx(St,{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(t8,{"aria-hidden":"true"})})}),g.jsxs(M1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(bo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(bo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:b})]})]})]})}function Sc({...e}){return g.jsx(t1,{"data-slot":"dialog",...e})}function Kre({...e}){return g.jsx(n1,{"data-slot":"dialog-portal",...e})}function Gre({className:e,...t}){return g.jsx(r1,{"data-slot":"dialog-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function xc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs(Kre,{"data-slot":"dialog-portal",children:[g.jsx(Gre,{}),g.jsxs(i1,{"data-slot":"dialog-content",className:We("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&g.jsxs(s1,{"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(Df,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ec({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&g.jsx(s1,{asChild:!0,children:g.jsx(St,{variant:"outline",children:"Close"})})]})}function dl({className:e,...t}){return g.jsx(EI,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function dc({className:e,...t}){return g.jsx(CI,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function hl(e){const[t,n]=_.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return _.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 Xre({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(Zre,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:TB(e.updatedAt,t)}),u=g.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return g.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:g.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:We("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,g.jsx(A9,{className:We("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Zre({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(Qre,{mode:t})]})}function Qre({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Rx:Nx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:g.jsx(n,{className:"size-3","aria-hidden":"true"})})}function RB({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(t7,{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 Jre({now:e}){const t=qt($=>$.historySessions),[n,r]=_.useState(null),[i,s]=_.useState(null),[o,l]=_.useState("json"),[u,d]=_.useState("default"),[h,p]=_.useState(!1),[y,v]=_.useState(!1),[b,w]=_.useState(new Set),[x,E]=_.useState(new Set),k=Js(),T=_.useMemo(()=>{const $=new Map;for(const D of t){const M=B0(D);let j=$.get(M);j||(j=new Map,$.set(M,j));const L=AB(D.projectDir),O=j.get(L);O?O.sessions.push(D):j.set(L,{dir:L,sessions:[D]})}return Array.from($.entries()).sort(([D],[M])=>kB(D,M)).map(([D,M])=>({provider:D,sessions:Array.from(M.values()).flatMap(j=>j.sessions),projects:Array.from(M.values()).map(j=>({dir:j.dir,shortDir:Cv(j.dir),sessions:j.sessions}))}))},[t]);function N($){s($),l(eie($)),d("default")}async function z($,D,M){if(n)return;const j=Ot;if(!j){rt.error("请先连接开发机");return}r($.id);const L=B0($);try{const O=await j.createSession({cwd:$.projectDir,mode:D,provider:L,resumeSessionId:$.id,...M?{permissionMode:M}:{}});if(O.error||!O.sessionId){rt.error(`恢复失败:${O.error??"未知错误"}`);return}const Y={sessionId:O.sessionId,state:"idle",mode:O.mode??D,provider:O.provider??"claude"};qt.getState().addSession(Y),k(`/chat/${O.sessionId}?mode=${O.mode??D}`),s(null)}catch(O){rt.error(`恢复失败:${O instanceof Error?O.message:String(O)}`)}finally{r(null)}}function R(){const $=Ot;!$||h||(p(!0),$.requestSessionHistory().then(D=>qt.getState().setHistorySessions(D)).catch(D=>{rt.error(D instanceof Error?D.message:String(D))}).finally(()=>{p(!1)}))}function F($,D){const M=LN($,D);E(j=>{const L=new Set(j);return L.has(M)?L.delete(M):L.add(M),L})}function P($){w(D=>{const M=new Set(D);return M.has($)?M.delete($):M.add($),M})}const q=t.length>0,H=i?NB():[];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:()=>q&&v($=>!$),disabled:!q,"aria-expanded":q?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:We("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[g.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",q?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),q?g.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:R,disabled:h,"data-slot":"history-refresh",children:g.jsx(Ax,{className:We("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!q&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),q&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:T.map($=>{const D=b.has($.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>P($.provider),"aria-expanded":!D,"data-slot":"history-provider-header","data-expanded":!D,className:We("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:Xv($.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:$.sessions.length}),g.jsx(Kh,{className:We("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:$.projects.map(M=>{const j=LN($.provider,M.dir),L=x.has(j);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>F($.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:We("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),g.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),g.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&g.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(O=>g.jsx(Xre,{session:O,now:e,disabled:n!==null,loading:n===O.id,onClick:()=>N(O),modeTag:O.preferredMode},O.id))})]},j)})})]},$.provider)})}),g.jsx(tie,{session:i,open:i!==null,modes:H,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:$=>{$||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&z(i,o,u)}})]})}function LN(e,t){return`${e}:${AB(t)}`}function AB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function NB(){return["json","pty"]}function eie(e){const t=NB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function tie({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=_.useState(!1),y=i==="bypassPermissions",v=hl("(min-width: 768px)");_.useEffect(()=>{t||p(!1)},[t]);const b=h?g.jsx(RB,{providerLabel:e?Xv(B0(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(IN,{checked:r==="json",label:"聊天",icon:g.jsx(Rx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(IN,{checked:r==="pty",label:"终端",icon:g.jsx(Nx,{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(Zb,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(Zb,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(Zb,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(St,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(St,{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(Sc,{open:t,onOpenChange:o,children:g.jsxs(xc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(Ec,{className:"min-w-0",children:[g.jsx(dl,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(dc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),b,g.jsx(Yu,{children:w})]})}):g.jsx(Yv,{open:t,onOpenChange:o,children:g.jsxs(Kv,{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(R1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Gv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(Hre,{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:b}),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 IN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:We("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,g.jsx("span",{className:"min-w-0 text-center",children:t}),g.jsx(ra,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Zb({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:We("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[g.jsx("span",{className:We("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&g.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:We("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),g.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&g.jsx(ra,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function nie({...e}){return g.jsx(ere,{"data-slot":"select",...e})}function rie({...e}){return g.jsx(nre,{"data-slot":"select-value",...e})}function iie({className:e,size:t="default",children:n,...r}){return g.jsxs(tre,{"data-slot":"select-trigger","data-size":t,className:We("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,g.jsx(rre,{asChild:!0,children:g.jsx(gl,{className:"size-4 opacity-50"})})]})}function sie({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(ire,{children:g.jsxs(sre,{"data-slot":"select-content",className:We("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[g.jsx(aie,{}),g.jsx(ore,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),g.jsx(lie,{})]})})}function oie({className:e,children:t,...n}){return g.jsxs(are,{"data-slot":"select-item",className:We("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[g.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(cre,{children:g.jsx(ra,{className:"size-4"})})}),g.jsx(lre,{children:t})]})}function aie({className:e,...t}){return g.jsx(ure,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Tx,{className:"size-4"})})}function lie({className:e,...t}){return g.jsx(dre,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(gl,{className:"size-4"})})}function O1(e){return!e||e.endsWith("/")?e:`${e}/`}function cie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function uie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function die(e,t,n){var o;if(t==="insert")return{currentPath:uie(e)||"./",query:cie(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:O1(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 hie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function fie(e,t){return`${O1(e)}${t.name}${t.isDir?"/":""}`}function zN(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 MB=_.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=Ei(U=>U.tree),h=Ei(U=>U.cwd),p=Ei(U=>U.homePath),y=i==="insert"?h:p||h,v=_.useMemo(()=>new Set(d.keys()),[d]),b=_.useMemo(()=>die(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=b.currentPath,x=_.useMemo(()=>hie(y,w),[y,w]),E=b.query,k=_.useRef(new Set),[T,N]=_.useState(!1),[z,R]=_.useState(""),[F,P]=_.useState(!1);_.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const U=Ot;if(!U)return;let A=!1;return k.current.add(x),U.requestDirectoryList(x).then(W=>{A||Ei.getState().setDirEntries(W.path,W.entries)}).catch(()=>{A||Ei.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{A=!0}},[x,d]);const q=!d.has(x),H=_.useMemo(()=>{let U=d.get(x)??[];return o&&(U=U.filter(A=>A.isDir)),E&&(U=U.filter(A=>A.name.toLowerCase().includes(E))),U},[d,x,E,o]),[$,D]=_.useState(0);_.useEffect(()=>D(0),[w,E]),_.useEffect(()=>{N(!1),R("")},[x]),_.useEffect(()=>{$>=H.length&&H.length>0&&D(H.length-1)},[H.length,$]);const M=_.useRef(null),j=_.useRef(!1);_.useEffect(()=>{var A;if(!j.current)return;j.current=!1;const U=(A=M.current)==null?void 0:A.querySelector(`[data-entry-index="${$}"]`);U==null||U.scrollIntoView({block:"nearest"})},[$]);const L=_.useCallback(U=>{const A=fie(w,U);return i==="insert"?A.replace(/^\.\//,""):A},[w,i]);async function O(){const U=zN(x,z);if(!(!U||!r)){P(!0);try{const A=await r(U);if(!A)return;R(""),N(!1),n(O1(A))}finally{P(!1)}}}_.useImperativeHandle(u,()=>({handleKey(U){return H.length===0?!1:U.key==="ArrowDown"?(j.current=!0,D(A=>Math.min(H.length-1,A+1)),!0):U.key==="ArrowUp"?(j.current=!0,D(A=>Math.max(0,A-1)),!0):U.key==="Enter"&&!U.nativeEvent.isComposing?(n(L(H[$])),!0):!1}}),[H,$,L,n]);const Y=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",K=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:Y,"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||F,onClick:()=>N(U=>!U),children:"新建目录"}):null]}),T?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:z,onChange:U=>R(U.target.value),onKeyDown:U=>{U.key==="Enter"&&!U.nativeEvent.isComposing&&(U.preventDefault(),O()),U.key==="Escape"&&(N(!1),R(""))},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:!zN(x,z)||F,onClick:()=>void O(),children:F?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:K,children:H.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:q?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:H.map((U,A)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(L(U)),onMouseEnter:()=>D(A),className:We("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",A===$&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",U.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":U.isDir?"dir":"file","data-entry-index":A,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[U.name,U.isDir?"/":""]})})},U.name))})})]})}),BN="工作目录不存在或不可访问:",pie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],OB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function mie(e,t){return t!==Xr.PATH_NOT_FOUND||!e.startsWith(BN)?null:e.slice(BN.length).trim()||null}function Kg(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 gie(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function vie(e,t){return e!=="codex"||OB.some(n=>n.value===t)?t:"default"}async function yie({relay:e,agentCli:t,form:n,timeoutMs:r=qx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Kg(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${na[n.provider]} 不可用:${p}`:`${na[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=mie(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 _ie({relay:e,timeoutMs:t=qx}){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 bie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Kg("claude",e),y=Kg("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(jN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(jN,{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(wie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(Sie,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function jN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Uf,{children:[g.jsx(Wf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:na[e]}),g.jsx("span",{className:We("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(qf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:gie(e,n)})})]})}function wie({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(St,{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(St,{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 Sie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[g.jsx("p",{className:We("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),g.jsx(St,{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(St,{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(N8,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:We("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function Ih({open:e,onOpenChange:t}){const[n,r]=_.useState(""),[i,s]=_.useState(""),[o,l]=_.useState("claude"),[u,d]=_.useState("pty"),[h,p]=_.useState("default"),[y,v]=_.useState(!1),[b,w]=_.useState(!1),[x,E]=_.useState(null),[k,T]=_.useState(!1),[N,z]=_.useState(null),[R,F]=_.useState(""),[P,q]=_.useState(!1),H=_.useRef(null),$=_.useRef(e);$.current=e;const D=Js(),M=Ei(xe=>xe.homePath),j=Ei(xe=>xe.agentCli),L=hl("(min-width: 768px)");_.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),_.useEffect(()=>{if(!e||M&&j)return;const xe=Ot==null?void 0:Ot.requestProxyInfo();xe&&xe.then(Re=>{const ze=Ei.getState();ze.setHomePath(Re.homePath),ze.setAgentCli(Re.agentCli)}).catch(Re=>{console.error("[create-session-dialog] requestProxyInfo failed",Re)})},[e,M,j]),_.useEffect(()=>{if(!k)return;function xe(Re){var Ye;const ze=Re.target;ze instanceof Node&&((Ye=H.current)!=null&&Ye.contains(ze))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",xe,!0),()=>document.removeEventListener("pointerdown",xe,!0)},[k]);function O(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),v(!1),E(null),z(null),F(""),q(!1)}function Y(){if(h==="bypassPermissions"){v(!0);return}I()}async function K(){await I(),$.current&&v(!1)}const U=o==="codex"?OB:pie,A=Kg(o,j),W=b||P||A.disabled;function G(xe){const Re=vie(xe,h);Re!==h&&p(Re)}async function I(xe){E(null),w(!0);try{const Re=await yie({relay:Ot,agentCli:j,form:{cwd:xe??i,name:n,provider:o,permissionMode:h,mode:u}});if(Re.type==="success"){if(qt.getState().addSession(Re.session),!$.current)return;t(!1),O(),D(Re.route);return}if(Re.type==="missing_cwd"&&E(Re.path),rt.error(Re.message),Re.type==="validation_error"||Re.type==="relay_missing")return}finally{w(!1)}}async function ne(xe){const Re=Ot;if(!Re)return rt.error("请先连接开发机"),null;try{const ze=await Re.createDirectory(xe);return ze.success?(s(ze.path),E(null),rt.success("目录已创建"),ze.path):(rt.error(`目录创建失败:${ze.error??"未知错误"}`),null)}catch(ze){return rt.error(ze instanceof Error?ze.message:String(ze)),null}}function ie(xe){var ze;const Re=j==null?void 0:j[xe];z(xe),F((Re==null?void 0:Re.command)??((ze=Re==null?void 0:Re.suggestions)==null?void 0:ze[0])??"")}async function se(){if(!N)return;const xe=R.trim();if(!xe){rt.error("请输入 Agent CLI 路径");return}const Re=Ot;if(!Re){rt.error("请先连接开发机");return}q(!0);try{const ze=await Re.updateAgentCliPath(N,xe);if(ze.error||!ze.agentCli){rt.error(`路径保存失败:${ze.error??"未知错误"}`);return}Ei.getState().setAgentCli(ze.agentCli),rt.success(`${na[N]} 路径已保存`),z(null),F("")}catch(ze){rt.error(ze instanceof Error?ze.message:String(ze))}finally{q(!1)}}function te(xe){d(xe),G(o)}function de(xe){var ze;const Re=xe.relatedTarget;Re instanceof Node&&((ze=H.current)!=null&&ze.contains(Re))||window.setTimeout(()=>T(!1),0)}const ve=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(RB,{providerLabel:na[o]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:b,children:"返回"}),g.jsx(St,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void K(),disabled:b,"data-slot":"bypass-permission-confirm",children:b?"创建中...":"确认"})]})]}):g.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:xe=>{xe.preventDefault(),Y()},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:xe=>r(xe.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:H,className:"relative flex min-w-0 flex-col gap-2",onBlur:de,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:()=>T(!0),onChange:xe=>{s(xe.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(MB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ne,onSelect:xe=>{s(xe),E(null),T(!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:()=>te("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),g.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>te("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),g.jsx(bie,{agentCli:j,provider:o,isDesktop:L,editingCliProvider:N,cliPathInput:R,savingCliPath:P,onProviderChange:xe=>{l(xe),G(xe)},onOpenCliPathEditor:ie,onCliPathInputChange:F,onCancelCliPathEditor:()=>{z(null),F("")},onSaveCliPath:()=>void se()}),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:xe=>p(xe),children:[g.jsx(iie,{className:"w-full",children:g.jsx(rie,{})}),g.jsx(sie,{children:U.map(xe=>g.jsx(oie,{value:xe.value,children:xe.label},xe.value))})]})]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:b,children:"取消"}),g.jsx(St,{type:"submit",className:"min-h-11 md:min-h-0",disabled:W,children:b?"创建中...":"创建"})]})]});return L?g.jsx(Sc,{open:e,onOpenChange:t,children:g.jsxs(xc,{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(Ec,{children:g.jsx(dl,{children:y?"跳过全部审批?":"新建会话"})}),ve]})}):g.jsx(Yv,{open:e,onOpenChange:t,children:g.jsxs(Kv,{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(R1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Gv,{children:y?"跳过全部审批?":"新建会话"})}),ve]})})}function zh({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=_.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=_.useState(s),[u,d]=_.useState(null),[h,p]=_.useState(!1);_.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(v){v.preventDefault();const b=o.trim();if(!b){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,b),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return g.jsx(Sc,{open:e,onOpenChange:r,children:g.jsx(xc,{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(Ec,{children:[g.jsx(dl,{children:"重命名会话"}),g.jsx(dc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),g.jsxs("div",{className:"grid gap-2",children:[g.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),g.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:v=>{l(v.target.value),u&&d(null)}}),u?g.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(St,{type:"submit",disabled:h,children:"保存"})]})]})})})}function xie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function Eie(e){return(e==null?void 0:e.kind)==="terminal"}function Cie(e){return xie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Eie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function Bm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Cie(t);function s(){t&&(r(t),n(!1))}return g.jsx(Sc,{open:e,onOpenChange:n,children:g.jsxs(xc,{"data-slot":"session-termination-dialog",children:[g.jsxs(Ec,{children:[g.jsx(dl,{children:i.title}),g.jsx(dc,{children:i.description})]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(St,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function DB(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 kie(e){if(e.session.state==="error")return"error";const t=DB(e);return t==="disconnected"?e.session.state:t}function PB({layout:e}){const t=qt(A=>A.sessions),n=qt(A=>A.sessionListLoaded),r=qt(A=>A.agentStatusBySessionId),i=qt(A=>A.ptyStateBySessionId),s=qt(A=>A.renameSession),o=Zt(A=>A.bySessionId),l=sU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Ie(A=>!!A.selectedProxyId),p=!Ie(A=>A.proxyListLoaded)||d&&!n,y=Js(),[v,b]=_.useState(!1),[w,x]=_.useState(!1),[E,k]=_.useState(null),[T,N]=_.useState(null),{creatingTerminal:z,createTerminal:R}=LB(),[F,P]=_.useState(new Set),[q,H]=_.useState(()=>Date.now());_.useEffect(()=>{const A=setInterval(()=>H(Date.now()),6e4);return()=>clearInterval(A)},[]);function $(A,W){y(`/chat/${A}?mode=${W??"json"}`,{replace:!1})}function D(A){const W=A.sessionId,G=Ot;if(!G){rt.error("请先连接开发机");return}G.sendControl({type:"session_terminate",sessionId:W}),qt.getState().removeSession(W),Zt.getState().clearSession(W),W===u&&y("/sessions"),(A==null?void 0:A.mode)==="pty"&&A.ptyOwner==="local-terminal"?rt.info("已断开页面连接,本地终端仍在运行"):rt.info("正在终止会话",{duration:1500})}async function M(A,W){const G=Ot;if(!G)throw new Error("请先连接开发机");const I=await G.renameSession(A,W);if(!I.success)throw new Error(I.error??"重命名失败");s(A,I.name??W),rt.success("已重命名会话")}function j(A){P(W=>{const G=new Set(W);return G.has(A)?G.delete(A):G.add(A),G})}function L(A){var I;const W=A.mode==="json"&&(((I=o[A.sessionId])==null?void 0:I.pendingApprovals.some(ne=>ne.status==="pending"))??!1),G=kie({session:A,agentStatus:r[A.sessionId],ptyState:i[A.sessionId],hasPendingApproval:W});return G===A.state?A:{...A,state:G}}const O=t.length>0;if(e==="sidebar"&&(p||!d))return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70",children:p?"连接中...":"请先连接开发机"}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});if(e==="page"&&p)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",children:[g.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});if(e==="page"&&!d)return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsx("div",{className:"flex-1",children:g.jsx(nc,{variant:"no-proxy"})}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});const Y=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",O?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=O?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:Tie(t).map(A=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>j(A.provider),"aria-expanded":!F.has(A.provider),className:We("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:Rie(A.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:A.sessions.length}),g.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(A.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(A.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:A.sessions.map(W=>g.jsx(Yre,{session:L(W),selected:W.sessionId===u,now:q,onClick:()=>$(W.sessionId,W.mode),onRename:()=>k(W),onTerminate:()=>N(W)},W.sessionId))})]},A.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),U=g.jsx(Jre,{now:q});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,U]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(St,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>x(!0),children:[g.jsx(wP,{"aria-hidden":"true"}),"新建"]})}),g.jsx(Nie,{open:w,creatingTerminal:z,onOpenChange:x,onCreateAgent:()=>{x(!1),b(!0)},onCreateTerminal:()=>void R(()=>x(!1))}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,U]}),g.jsx(Ih,{open:v,onOpenChange:b}),g.jsx(Bm,{open:T!==null,session:T,onOpenChange:A=>{A||N(null)},onConfirm:D}),g.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]})}function Tie(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])=>Aie(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Rie(e){return e==="terminal"?"终端":Xv(e)}function Aie(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:kB(e,t)}function LB(){const e=Js(),[t,n]=_.useState(!1);async function r(i){if(!t){n(!0);try{const s=await _ie({relay:Ot});if(s.type!=="success"){rt.error(s.message);return}qt.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function FN({compact:e=!1}){const[t,n]=_.useState(!1),[r,i]=_.useState(!1),s=_.useRef(!1),o=Ie(w=>!!w.selectedProxyId),{creatingTerminal:l,createTerminal:u}=LB();function d(){i(!0),window.setTimeout(()=>i(!1),2e3)}function h(){if(!o){d();return}s.current=!0,n(!0)}function p(){if(!o){d();return}s.current=!0,u()}function y(w){w.preventDefault(),d()}const v=g.jsxs(St,{variant:"outline","data-slot":"create-session-trigger",className:We(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!o&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!o,onClick:o?void 0:y,children:[g.jsx(wP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),b=o?g.jsxs(A1,{children:[g.jsx(N1,{asChild:!0,children:v}),g.jsxs(M1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:w=>{s.current&&(s.current=!1,w.preventDefault())},children:[g.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:h,children:[g.jsx(bP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:l,onSelect:p,children:[g.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),l?"正在创建终端会话...":"终端会话"]})]})]}):v;return g.jsxs(g.Fragment,{children:[o?b:g.jsxs(Uf,{open:o?void 0:r,onOpenChange:o?void 0:i,children:[g.jsx(Wf,{asChild:!0,children:b}),g.jsx(qf,{side:"top",children:o?"新建会话":"请先连接开发机"})]}),g.jsx(Ih,{open:t,onOpenChange:n})]})}function Nie({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=_.useRef(!1);function o(l){s.current=!0,l()}return g.jsx(Yv,{open:e,onOpenChange:n,children:g.jsxs(Kv,{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(R1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Gv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.jsxs(St,{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(bP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(St,{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(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Mie="0.5.9",Oie={version:Mie},Die={playback:"playback",capture:"play-and-record"};function Pie(){return typeof navigator>"u"?null:navigator.audioSession??null}function Lie(){return{setMode:()=>{},release:()=>{}}}class Iie{constructor(t=Pie){gt(this,"leases",new Map);gt(this,"session",null);gt(this,"baselineType",null);gt(this,"nextLeaseId",1);gt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Lie();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(Die[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 D1=new Iie,H0=64,$N=-60,IB=32;function HN(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-$N)/-$N));return e<0?-r:r}function UN(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 zie(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 Bie(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 zB{constructor(t,n=24e3,r={}){gt(this,"nextStartTime",0);gt(this,"activityEndToken",0);gt(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=zie(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*IB/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=Bie(n.subarray(l,u));this.scheduleTimer(()=>{var v,b,w,x;(b=(v=this.options).onActivityLevel)==null||b.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 Qb={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},WN="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",jie=800,qN=300,Fie=1600;function U0(e,t){return e.filter(n=>!n.model||n.model===t)}function VN({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 jm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=_.useState(!1),u=_.useId(),d=n.find(v=>v.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!BB(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(YN,{label:h,muted:!d&&!t}),g.jsx(gl,{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 b=v.value===t;return g.jsxs("button",{type:"button",role:"option","aria-label":v.label,"aria-selected":b,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:b?g.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(YN,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function YN({label:e,muted:t=!1}){const n=BB(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 $ie({scrollRef:e}={}){const[t,n]=_.useState(Qb),[r,i]=_.useState(String(Qb.turnIdleSeconds)),[s,o]=_.useState(()=>km()),[l,u]=_.useState(""),[d,h]=_.useState(!1),[p,y]=_.useState(!1),[v,b]=_.useState({kind:"idle"}),w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(null);_.useEffect(()=>{const se=Ot;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te=!1;return b({kind:"loading"}),se.requestVoiceConfig().then(de=>{if(!te){if(de.error||!de.config){b({kind:"error",message:de.error??"读取语音设置失败"});return}n(de.config),i(String(de.config.turnIdleSeconds)),u(""),h(!1),y(!0),b({kind:"idle"})}}).catch(de=>{te||b({kind:"error",message:de instanceof Error?de.message:"读取语音设置失败"})}),()=>{te=!0}},[]),_.useEffect(()=>{const se=Ot;if(!se||!p)return;let te=!1;return se.requestVoiceCapabilities({region:t.region}).then(de=>{if(!te){if(de.error||!de.capabilities){o(km());return}o(de.capabilities)}}).catch(()=>{te||o(km())}),()=>{te=!0}},[t.region,p]),_.useEffect(()=>()=>{G(),I()},[]);const N=_.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]),z=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",R=_.useMemo(()=>U0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=R.some(se=>se.value===t.ttsVoice)?t.ttsVoice:"",q=R.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",H=_.useMemo(()=>qie(r),[r]),$=H?null:"请输入正整数秒数",D=q??$,M=z||!!D,j=_.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=_.useMemo(()=>XN(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),O=_.useMemo(()=>Vie(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),Y=_.useMemo(()=>XN(R,P),[R,P]);function K(){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:H??Qb.turnIdleSeconds}}async function U(){if(z)return;if(D){b({kind:"error",message:D});return}const se=Ot;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}const te=K();I(),b({kind:"saving"});const de=performance.now();try{const ve=await se.updateVoiceConfig(te),xe=performance.now()-de;if(xe<qN&&await Wie(qN-xe),!ve.success||ve.error||!ve.config){b({kind:"error",message:ve.error??"保存语音设置失败"});return}n(ve.config),i(String(ve.config.turnIdleSeconds)),u(""),h(!1),b({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,b(Re=>Re.kind==="saved"?{kind:"idle"}:Re)},Fie),se.requestVoiceCapabilities({region:ve.config.region}).then(Re=>{Re.capabilities&&o(Re.capabilities)}).catch(()=>{o(km())})}catch(ve){b({kind:"error",message:ve instanceof Error?ve.message:"保存语音设置失败"})}}async function A(){if(z)return;if(D){b({kind:"error",message:D});return}const se=Ot;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te;try{te=W()}catch(de){b({kind:"error",message:GN(de)});return}b({kind:"testing"});try{const[de]=await Promise.all([se.testVoiceConfig(K()),te.ready]);if(!de.success||de.error){G(),b({kind:"error",message:de.error??"语音配置测试失败"});return}const ve=await ne(de,te.context);b({kind:"playingTest",transcript:de.transcript}),k.current=setTimeout(()=>{k.current=null,G(),b({kind:"testPassed",transcript:de.transcript})},ve)}catch(de){G(),b({kind:"error",message:GN(de)})}}function W(){G();const se=D1.acquire("playback");x.current=se;try{const te=Uie();return w.current=te,{context:te,ready:KN(te)}}catch(te){throw se.release(),x.current=null,te}}function G(){var se,te,de;k.current&&(clearTimeout(k.current),k.current=null),(se=E.current)==null||se.stop(),E.current=null,(te=w.current)==null||te.close(),w.current=null,(de=x.current)==null||de.release(),x.current=null}function I(){T.current&&(clearTimeout(T.current),T.current=null)}async function ne(se,te){if(!se.audioBase64)throw new Error("语音测试未返回可播放音频");if(se.audioEncoding&&se.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const de=se.audioSampleRate??24e3,ve=Hie(se.audioBase64);if(ve.byteLength===0||ve.byteLength%2!==0)throw new Error("测试音频数据无效");await KN(te);const xe=new zB(te,de);E.current=xe,xe.enqueue(ve);const Re=Math.ceil(ve.byteLength/2/de*1e3);return Math.max(jie,Re)}function ie(se){var te;return((te=U0(s.ttsVoices,se)[0])==null?void 0:te.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:se=>{se.preventDefault(),U()},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(VN,{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(EP,{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:se=>{u(se.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${WN} w-full pl-9`})]}),t.configured&&g.jsxs(St,{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(J8,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(jm,{label:"地域",value:t.region,options:j,onChange:se=>n(te=>({...te,region:se==="intl"?"intl":"cn"}))}),g.jsx(jm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:se=>n(te=>({...te,asrModel:se}))}),g.jsx(jm,{label:"语音合成模型",value:t.ttsModel,options:O,onChange:se=>n(te=>({...te,ttsModel:se,ttsVoice:ie(se)}))}),g.jsx(jm,{label:"语音音色",value:P,options:Y,placeholder:R.length===0?"暂无可用音色":"请选择音色",onChange:se=>n(te=>({...te,ttsVoice:se})),help:q}),g.jsx(VN,{label:"结束停顿时间(秒)",help:$,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:se=>i(se.target.value),className:`${WN} 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:[N?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:N}):null,g.jsxs(St,{type:"button",variant:"outline",disabled:M,onClick:()=>void A(),children:[g.jsx(TP,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(St,{type:"submit",disabled:M,children:[g.jsx(F8,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Hie(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 Uie(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function KN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function GN(e){return e instanceof Error?e.message:"语音配置测试失败"}function Wie(e){return new Promise(t=>setTimeout(t,e))}function qie(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function XN(e,t){const n=e.map(r=>({value:r.value,label:jB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Vie(e,t,n){const r=e.map(i=>{const s=U0(t,i.value).length===0;return{value:i.value,label:`${jB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function BB(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 jB(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 Yie=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Kie=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],P1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function FB(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 Gie(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Xie(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Zie(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function W0({open:e,onOpenChange:t}){const n=Ie(q=>q.relayUrl),r=Ie(q=>q.latencyMonitorEnabled),i=Ie(q=>q.setLatencyMonitorEnabled),s=Ie(q=>q.sessionIdleNotificationsEnabled),o=Ie(q=>q.setSessionIdleNotificationsEnabled),l=Ie(q=>q.inputModePreference),u=Ie(q=>q.setInputModePreference),d=Ie(q=>q.themePreference),h=Ie(q=>q.setThemePreference),p=Ie(q=>q.ptyScrollTraceEnabled),y=Ie(q=>q.setPtyScrollTraceEnabled),[v,b]=_.useState("menu"),[w,x]=_.useState({kind:"idle"}),E=_.useRef(null),k=_.useRef(null),T=VZ(),N=_.useMemo(()=>Ev().osName==="iPad",[]),z=_.useCallback(async q=>{if(!q){o(!1);return}const H=await wZ();if(H==="granted"){o(!0);return}if(H==="denied"){rt.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(H==="default"){rt.info("未授予通知权限,会话通知保持关闭");return}rt.error("当前浏览器不支持系统通知")},[o]),R=_.useCallback(async q=>{x({kind:"loading"});try{const H=await fetch(Gie(n),{cache:"no-store",signal:q});if(!H.ok)throw new Error(`HTTP ${H.status}`);const $=await H.json();if($.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:$.version??"未知",uptime:$.uptime??0})}catch(H){if(H instanceof DOMException&&H.name==="AbortError")return;x({kind:"error",message:H instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);_.useEffect(()=>{if(!e){b("menu");return}},[e]),_.useEffect(()=>{if(!e||v!=="version")return;const q=new AbortController;return R(q.signal),()=>q.abort()},[R,e,v]),_.useEffect(()=>{if(!e||v!=="voice")return;const q=window.requestAnimationFrame(()=>{var H;(H=E.current)==null||H.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(q)},[e,v]);const F=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${FB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(Sc,{open:e,onOpenChange:t,children:g.jsxs(xc,{className:We("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",v==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",v==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":v,focusSurfaceOnOpen:!0,ref:E,showCloseButton:v==="menu",children:[g.jsx(Ec,{className:We(v==="menu"&&"pr-12 text-left",v!=="menu"&&"text-left",v==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:v!=="menu"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-start gap-2",children:[g.jsx(St,{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:()=>b("menu"),children:g.jsx(vv,{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(dl,{children:Xie(v)}),g.jsx(dc,{className:"max-w-[28rem] leading-5",children:Zie(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(dl,{children:"设置"}),g.jsx(dc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(Qie,{relayVersion:F,relayDetail:P,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(ese,{saved:T}):v==="clients"?g.jsx(sse,{}):v==="voice"?g.jsx($ie,{scrollRef:k}):g.jsx(Jie,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:N,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:z,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>b("voice"),onOpenRelayToken:()=>b("relay-token"),onOpenClients:()=>b("clients"),onOpenVersion:()=>b("version")})]})})}function Qie({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:P1,"data-slot":"settings-dialog-body",children:[g.jsx(QN,{icon:g.jsx(kP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Oie.version,detail:"当前浏览器加载的版本"}),g.jsx(QN,{icon:g.jsx(RP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Jie({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:b,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(cu,{title:"服务",children:[g.jsx(Fm,{icon:g.jsx(D9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx(Fm,{icon:g.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx(Fm,{icon:g.jsx(o7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:b})]}),g.jsx(cu,{title:"外观",children:g.jsx(ZN,{icon:g.jsx(X8,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Yie,onValueChange:n})}),g.jsx(cu,{title:"通知",children:g.jsx(ew,{icon:g.jsx(L9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(cu,{title:"交互",children:g.jsx(ZN,{icon:g.jsx(CP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Kie,onValueChange:i})}):null,g.jsxs(cu,{title:"高级诊断",children:[g.jsx(ew,{icon:g.jsx(of,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(ew,{icon:g.jsx(yP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(cu,{title:"关于",children:g.jsx(Fm,{icon:g.jsx(RP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({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 ZN({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=_.useId(),l=_.useId();return g.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,g.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return g.jsx("button",{type:"button",role:"radio","aria-checked":d,className:We("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function ese({saved:e}){const t=_.useId(),n=_.useId(),[r,i]=_.useState(""),[s,o]=_.useState(null),l=()=>{qL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}UL(h),l()},d=()=>{WL(),l()};return g.jsxs("form",{className:P1,"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(St,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(St,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function tse(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())||tse(e)}function rse(e){return dX(e)}function ise(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return FB(t)}function Jb({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 sse(){const e=Ie(y=>y.proxies),[t,n]=_.useState([]),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,u]=_.useState(null),d=_.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),h=_.useCallback(async()=>{const y=Ot;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)}},[]);_.useEffect(()=>{h()},[h]);const p=_.useCallback(async y=>{const v=Ot;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const b=await v.kickRelayClient(y);if(!b.success){o(b.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(b){o(b instanceof Error?b.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:P1,"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(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Ax,{className:We("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?g.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?g.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const v=y.current===!0,b=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:rse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(Jb,{label:"已连接",value:ise(y.connectedAt)}),y.proxyId?g.jsx(Jb,{label:"连接到",value:nse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(Jb,{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(St,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:b,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[g.jsx(g8,{className:"size-3.5","aria-hidden":"true"}),b?"断开中...":"断开"]})]})},y.clientId)})]})}function ew({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=_.useId(),o=_.useId();return g.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[g.jsx("div",{className:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),g.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),g.jsx("span",{className:We("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:g.jsx("span",{className:We("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function Fm({icon:e,label:t,detail:n,onClick:r}){const i=_.useId(),s=_.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(Kh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function QN({icon:e,label:t,value:n,detail:r,muted:i=!1}){return g.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[g.jsx("div",{className:We("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[g.jsx("div",{className:"text-sm text-muted-foreground",children:t}),g.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const ose="xterm-helper-textarea";function ase(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(ose)?!1:(e.blur(),!0)}function JN(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&&lse(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function lse(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 cse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=_.useRef(null),r=_.useCallback(()=>{e&&ase()},[e]),i=_.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=_.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,JN(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=_.useCallback(l=>{r(),t&&(JN(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function use({className:e}){const t=Ie(o=>o.sidebarCollapsed),n=Ie(o=>o.toggleSidebarCollapsed),[r,i]=_.useState(!1),s=cse();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[g.jsx(tM,{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(eM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(FN,{compact:!0})]})]}),g.jsx(W0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:We("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[g.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:g.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx(YP,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(tM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx(CB,{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(PB,{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(FN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(eM,{onClick:()=>i(!0)})})]})]}),g.jsx(W0,{open:r,onOpenChange:i})]})}function eM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Uf,{delayDuration:500,children:[g.jsx(Wf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[g.jsx(AP,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(qf,{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 tM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?k8:E8;return g.jsxs(Uf,{delayDuration:500,children:[g.jsx(Wf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:g.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(qf,{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 dse=1500,hse=300,nM=70,rM=35;function $B({texts:e,className:t}){const[n,r]=_.useState(""),[i,s]=_.useState(!0),o=_.useRef("typing"),l=_.useRef(0),u=_.useRef(0);return _.useEffect(()=>{const d=setInterval(()=>s(h=>!h),530);return()=>clearInterval(d)},[]),_.useEffect(()=>{let d;const h=()=>e[u.current%e.length],p=()=>{const y=o.current;if(y==="typing"){const v=h();l.current<v.length?(l.current+=1,r(v.slice(0,l.current)),d=setTimeout(p,nM)):(o.current="paused",d=setTimeout(p,dse))}else y==="paused"?(o.current="deleting",d=setTimeout(p,rM)):y==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),d=setTimeout(p,rM)):(u.current+=1,o.current="waiting",d=setTimeout(p,hse)):(o.current="typing",d=setTimeout(p,nM))};return d=setTimeout(p,500),()=>clearTimeout(d)},[e]),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-foreground/90",children:n}),g.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const HB=["DEV Anywhere","/unlimited @anytime"];function fse({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($B,{texts:HB,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 pse=3e3,mse=1e4,$m=12,gse=4,iM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},vse={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 uu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Bh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function sM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function UB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function yse(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 _se(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Bh(e.rttMs):"等待检测"}function bse(){const e=ki("local",ln.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 oM(e){dr("local",ln.latencyMonitorPosition,JSON.stringify(e))}function wse(){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=wse(),r=$m,i=$m,s=Math.max(r,n.width-t.width-$m),o=Math.max(i,n.height-t.height-$m);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Sse(){const e=Ie(R=>R.latencyMonitorEnabled),t=Ie(R=>R.connected),n=Ie(R=>R.proxyOnline),r=Ie(R=>R.selectedProxyId),[i,s]=_.useState(vse),[o,l]=_.useState(()=>bse()),u=_.useRef(!1),d=_.useRef(null),h=_.useRef(null),p=_.useRef(!1),y=_.useMemo(()=>(Object.values(i).sort((R,F)=>sM(F.state)-sM(R.state))[0]??{state:"idle"}).state,[i]),v=UB(y);async function b(){if(u.current)return;const R=Ot;if(!R||!t){const H=uu("Relay 服务器未连接");s({webRelay:H,relayProxy:H,webProxy:H});return}u.current=!0,s(H=>({webRelay:{...H.webRelay,state:"measuring"},relayProxy:n?{...H.relayProxy,state:"measuring"}:uu("未连接开发机"),webProxy:n?{...H.webProxy,state:"measuring"}:uu("未连接开发机")}));const[F,P,q]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:F.status==="fulfilled"?tw(F.value):uu(F.reason instanceof Error?F.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?tw(P.value):uu(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:q.status==="fulfilled"?tw(q.value):uu(q.reason instanceof Error?q.reason.message:"测速失败")}),u.current=!1}if(_.useEffect(()=>{if(!e)return;let R=!1,F=null;const P=async()=>{await b(),!R&&(F=setTimeout(P,document.hidden?mse:pse))};return P(),()=>{R=!0,u.current=!1,F&&clearTimeout(F)}},[e,t,n,r]),_.useEffect(()=>{if(!e||!o)return;const R=d.current;if(!R)return;const F=R.getBoundingClientRect(),P=nw(o,{width:F.width,height:F.height});P.x===o.x&&P.y===o.y||(l(P),oM(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(R){var P,q;if(R.button!==0)return;const F=R.currentTarget.getBoundingClientRect();h.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,originX:F.left,originY:F.top,width:F.width,height:F.height,dragging:!1},(q=(P=R.currentTarget).setPointerCapture)==null||q.call(P,R.pointerId)}function k(R){const F=h.current;if(!F||F.pointerId!==R.pointerId)return;const P=R.clientX-F.startX,q=R.clientY-F.startY;if(!F.dragging&&Math.hypot(P,q)<gse)return;F.dragging=!0,R.preventDefault();const H=nw({x:F.originX+P,y:F.originY+q},{width:F.width,height:F.height});l(H)}function T(R){var $,D;const F=h.current;if(!F||F.pointerId!==R.pointerId||(h.current=null,(D=($=R.currentTarget).releasePointerCapture)==null||D.call($,R.pointerId),!F.dragging))return;R.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=R.clientX-F.startX,q=R.clientY-F.startY,H=nw({x:F.originX+P,y:F.originY+q},{width:F.width,height:F.height});l(H),oM(H)}function N(R){var P,q;const F=h.current;!F||F.pointerId!==R.pointerId||(h.current=null,(q=(P=R.currentTarget).releasePointerCapture)==null||q.call(P,R.pointerId))}function z(R){p.current&&(p.current=!1,R.preventDefault(),R.stopPropagation())}return g.jsxs(C1,{children:[g.jsx(k1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:We("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",yse(v)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Bh(i.webRelay.rttMs)},开发机 ${Bh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:T,onPointerCancel:N,onClickCapture:z,children:[g.jsx(yP,{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 ",Bh(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Bh(w.rttMs)]}),g.jsx(gl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(T1,{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(St,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void b(),children:g.jsx(Ax,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(iM).map(R=>g.jsx(xse,{label:iM[R],measurement:i[R]},R))})]})]})}function xse({label:e,measurement:t}){const n=UB(t.state);return g.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[g.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:We("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),g.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:_se(t)})]})]})}const WB="/__dev_anywhere_debug/browser-state-dumps",Ese=1500,Cse=10,rw=80,L1=500,kse=["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"],Tse=["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 aM(){if(typeof window>"u")return"off";const e=QB("debugDump");return e==="auto"?"auto":e!==null||Ise("debugInput")?"manual":"off"}function Rse(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:Ose(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:lM(document.activeElement),selection:Dse(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>lM(i)).filter(i=>!!i),root:qB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:du(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:du(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:du(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:du(()=>cM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>cM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function Ase(e="manual"){const t=Rse(e);return Nse(t)}async function Nse(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Mse(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:WB}}catch(r){const i=JB(r),s=Pse(e.createdAt);return Lse(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Mse(e){const t=await fetch(WB,{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 qB(e,t,n){if(n.count>=Ese||t>Cse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=uM(e.textContent??"");return u?{kind:"text",text:Zv(u,L1)}:{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&&!uM(u.textContent??"")||r.push(qB(u,t+1,n));s.length>rw&&(i=s.length-rw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:ZB(e),attrs:VB(e),rect:YB(e),scroll:KB(e),style:GB(e)},l=XB(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function lM(e){if(!(e instanceof HTMLElement))return null;const t=XB(e);return{path:ZB(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:VB(e),rect:YB(e),scroll:KB(e),style:GB(e),...t?{value:t}:{}}}function Ose(){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 VB(e){const t={};for(const n of kse){const r=e.getAttribute(n);r!==null&&(t[n]=Zv(r,500))}return t}function YB(e){const t=e.getBoundingClientRect();return{x:Zi(t.x),y:Zi(t.y),width:Zi(t.width),height:Zi(t.height),top:Zi(t.top),right:Zi(t.right),bottom:Zi(t.bottom),left:Zi(t.left)}}function KB(e){return{top:Zi(e.scrollTop),left:Zi(e.scrollLeft),height:Zi(e.scrollHeight),width:Zi(e.scrollWidth),clientHeight:Zi(e.clientHeight),clientWidth:Zi(e.clientWidth)}}function GB(e){const t=window.getComputedStyle(e),n={};for(const r of Tse)n[r]=t.getPropertyValue(r);return n}function XB(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Zv(e.value,L1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Dse(){var e;try{return Zv(((e=window.getSelection())==null?void 0:e.toString())??"",L1)}catch{return null}}function ZB(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 Pse(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Lse(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 Ise(e){return QB(e)!==null}function QB(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 cM(e){return e?Gg(e.slice(-200)):null}function du(e){try{return Gg(e())}catch(t){return{error:JB(t)}}}function Gg(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(Gg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Gg(r);return t}return String(e)}function uM(e){return e.replace(/\s+/g," ").trim()}function Zv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Zi(e){return Math.round(e*100)/100}function JB(e){return e instanceof Error?e.message:String(e)}const zse=500,Bse=1e3,jse=60;function Fse(){const[e,t]=_.useState(()=>aM()),[n,r]=_.useState(!1),[i,s]=_.useState(null),o=_.useRef(null),l=_.useRef(!1),u=_.useRef(0),d=_.useRef(0),h=_.useRef(null);_.useEffect(()=>{const b=()=>t(aM());return window.addEventListener("hashchange",b),window.addEventListener("popstate",b),()=>{window.removeEventListener("hashchange",b),window.removeEventListener("popstate",b)}},[]);const p=_.useCallback(async(b="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await Ase(b);return o.current=w,s(w),(b==="manual"||w.status==="failed")&&$se(w),w}finally{l.current=!1,r(!1)}},[]);if(_.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),_.useEffect(()=>{var k,T;if(e!=="auto")return;const b=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=N=>{d.current>=jse||(b(),h.current=window.setTimeout(()=>{h.current=null;const z=Date.now(),R=Bse-(z-u.current);if(R>0){h.current=window.setTimeout(()=>w(N),R);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${N}`)},zse))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=N=>w(N.type);return x.forEach(N=>window.addEventListener(N,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(T=window.visualViewport)==null||T.addEventListener("scroll",E),()=>{var N,z;b(),x.forEach(R=>window.removeEventListener(R,E,!0)),(N=window.visualViewport)==null||N.removeEventListener("resize",E),(z=window.visualViewport)==null||z.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=Hse(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(St,{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(Lu,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(o8,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function $se(e){if(e.status==="saved"){rt.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){rt.info(`诊断已下载: ${e.filename}`);return}rt.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Hse(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Use(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 I1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:Use(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 Cn(e){return Math.round(e*10)/10}function Ka(e){return e.length===0?"":`${Cn(Math.min(...e))}..${Cn(Math.max(...e))}`}function Au(e){return[...new Set(e.filter(t=>t!==void 0).map(Cn))]}function e3(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 Wse="dev_anywhere_pty_input_latency_trace",dM=80,qse=1e4,Vse=new TextDecoder;let Yse=0;const Ku=new Map,Cc=I1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Wse,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Kse(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Qse)}function Gse(e,t){if(!Cc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Yse}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:toe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),B1(s,r),Ku.set(e,s),Vf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function hM(e,t){if(!e||!Cc.isEnabled())return;const n=performance.now(),r=Jse(e.sessionId,e.inputId);r&&(r.sentAt=n),Vf({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 Xse(e,t,n){if(!Cc.isEnabled())return;const r=performance.now(),i=z1(e,r),s=ioe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&roe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Vf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:j1(i,r),details:soe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Zse(e,t,n=1){if(!Cc.isEnabled())return;const r=performance.now(),i=z1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Vf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:j1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>eoe(e,s))}function Qse(){const e=Cc.getAll(),t=e.slice(-200),n=[...Ku.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Cn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Cn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Cn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Cn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Cn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Cn(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?"":Cn(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(`
|
|
501
501
|
`)}function Vf(e){Cc.append(e)}function z1(e,t){const n=Ku.get(e)??[];return B1(n,t),Ku.set(e,n),n}function B1(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>qse;(i||s)&&e.splice(n,1)}e.length>dM&&e.splice(0,e.length-dM)}function Jse(e,t){return(Ku.get(e)??[]).find(n=>n.inputId===t)??null}function eoe(e,t){if(!Cc.isEnabled())return;const n=performance.now(),r=z1(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)}Vf({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:j1(r,n),details:i>0?`paint=${i}`:""}),B1(r,n)}function j1(e,t){const n=e[0];return n?t-n.startedAt:null}function toe(e){return e==="\r"||e===`
|
|
502
502
|
`?"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 roe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function ioe(e){try{return Vse.decode(e)}catch{return""}}function soe(e){return e.filter(Boolean).join(" ")}function Ks(e,t){if(!e||!t)return;const n=Gse(e,t),r=tc;if(!r){hM(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});hM(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const fM=-1;function ooe({sessionId:e,enabled:t,waiting:n,approvalSeq:r,sendRawInput:i=Ks}){const s=_.useRef(void 0),o=_.useRef(e);_.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=fM,i(e,"\r");return}if(s.current===fM){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function aoe(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=Lx(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 loe({target:e,sendRawInput:t}){return ooe({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function coe({sendRawInput:e=Ks}){const t=Ie(d=>d.connected),n=Ie(d=>d.proxyOnline),r=Ie(d=>d.selectedProxyId),i=qt(d=>d.sessions),s=qt(d=>d.ptyStateBySessionId),o=qt(d=>d.agentStatusBySessionId),l=qt(d=>d.ptyAutoYesBySessionKey),u=i.map(d=>aoe({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(loe,{target:d,sendRawInput:e},d.key))})}function uoe(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 Jl=function(e,t){return Number(e.toFixed(t))},doe=function(e,t){return t},Ln=function(e,t,n){n&&typeof n=="function"&&n(e,t)},hoe=function(e){return-Math.cos(e*Math.PI)/2+.5},foe=function(e){return e},poe=function(e){return e*e},moe=function(e){return e*(2-e)},goe=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},voe=function(e){return e*e*e},yoe=function(e){return--e*e*e+1},_oe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},boe=function(e){return e*e*e*e},woe=function(e){return 1- --e*e*e*e},Soe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},xoe=function(e){return e*e*e*e*e},Eoe=function(e){return 1+--e*e*e*e*e},Coe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},t3={easeOut:hoe,linear:foe,easeInQuad:poe,easeOutQuad:moe,easeInOutQuad:goe,easeInCubic:voe,easeOutCubic:yoe,easeInOutCubic:_oe,easeInQuart:boe,easeOutQuart:woe,easeInOutQuart:Soe,easeInQuint:xoe,easeOutQuint:Eoe,easeInOutQuint:Coe},n3=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Ys=function(e){e.mounted&&(n3(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function r3(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Ys(e),e.animation=function(){if(!e.mounted)return n3(e.animation);var o=new Date().getTime()-i,l=o/n,u=t3[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function koe(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function El(e,t,n,r){var i=koe(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):r3(e,r,n,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var b=l+h*v,w=u+p*v,x=d+y*v;s(b,w,x)})}}function Toe(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 Roe=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}},F1=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=Toe(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,h=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,v=l.newDiffHeight,b=Roe(u,h,y,d,p,v,!!s),w=u>=h&&d>=p;o&&w&&!s&&(b.minPositionX=0,b.maxPositionX=0,b.minPositionY=0,b.maxPositionY=0);var x=e.setup,E=x.minPositionX,k=x.maxPositionX,T=x.minPositionY,N=x.maxPositionY;return E!=null&&(b.minPositionX=u*(1-t)+E*t),k!=null&&(b.maxPositionX=k*t),T!=null&&(b.minPositionY=d*(1-t)+T*t),N!=null&&(b.maxPositionY=N*t),b},vf=function(e,t,n,r){return r?e<t?Jl(t,2):e>n?Jl(n,2):Jl(e,2):Jl(e,2)},Gu=function(e,t){var n=F1(e,t);return e.bounds=n,n};function Yf(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=vf(e,l-p,d+p,r),b=vf(t,u-y,h+y,r);return{x:v,y:b}}function Qv(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=Yf(p,y,i,s,0,0,null);return v}var pM=1e-7;function Kf(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,pM),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,pM)}var mM=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=Gf(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},gM=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},Aoe=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}},Noe=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 Moe(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,b=h.minPositionY,w=n>p||n<y,x=r>v||r<b,E=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>v?d.offsetHeight:e.setup.minPositionY||0,T=Qv(e,E,k,i,e.bounds,l||u),N=T.x,z=T.y;return{scale:i,positionX:w?N:n,positionY:x?z:r}}}function i3(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=Yf(t,n,l,s,r,i,o),v=y.x,b=y.y;e.setState(d,v,b)}}var Ooe=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}},fl=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},nl;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(nl||(nl={}));var Doe=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},Poe=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 Loe(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 vM(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:vf(e,s,o,i)}function Ioe(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 zoe(e,t,n){var r,i,s=Doe(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,b=h.sensitivityMouse,w=Date.now();if(o&&l&&d){var x=Ioe(d),E=(r={},r[nl.TOUCH]=v,r[nl.MOUSE]=b,r)[n],k=(i={},i[nl.TOUCH]=y,i[nl.MOUSE]=p,i)[n],T=t.x-o.x,N=t.y-o.y,z=iw(T/x,k,E),R=iw(N/x,k,E),F=w-l,P=T*T+N*N,q=iw(Math.sqrt(P)/F,k,E);e.velocity={velocityX:z,velocityY:R,total:q}}e.lastMousePosition=t,e.velocityTime=w}}function Boe(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Poe(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,b=r.autoAlignment,w=r.zoomAnimation,x=r.panning,E=x.lockAxisY,k=x.lockAxisX,T=w.animationType,N=b.sizeX,z=b.sizeY,R=b.velocityAlignmentTime,F=R,P=Loe(e,u),q=Math.max(P,F),H=fl(e,N),$=fl(e,z),D=H*i.offsetWidth/100,M=$*i.offsetHeight/100,j=d+D,L=h-D,O=p+M,Y=y-M,K=e.state,U=new Date().getTime();r3(e,T,q,function(A){var W=e.state,G=W.scale,I=W.positionX,ne=W.positionY,ie=new Date().getTime()-U,se=ie/F,te=t3[b.animationType],de=1-te(Math.min(1,se)),ve=1-A,xe=I+o*ve,Re=ne+l*ve,ze=vM(xe,K.positionX,I,k,v,h,d,L,j,de),Ye=vM(Re,K.positionY,ne,E,v,y,p,Y,O,de);if(I!==xe||ne!==Re){e.setState(G,ze,Ye);var mt=e.props.onPanning;mt&&mt(kn(e),{})}})}}function yM(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},Ys(e),Gu(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?Noe(e,t):Aoe(e,t)}function s3(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=Moe(e);y&&El(e,y,d,h)}}function _M(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=Ooe(e,t,n),h=d.x,p=d.y,y=fl(e,l),v=fl(e,u);zoe(e,{x:h,y:p},r),i3(e,h,p,y,v)}}function joe(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,b=((i==null?void 0:i.offsetWidth)||0)*u,w=((i==null?void 0:i.offsetHeight)||0)*u,x=!e.setup.limitToBounds||y<b||v<w,E=!t&&n&&n.total>.1&&x;E?Boe(e):s3(e)}}function $1(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Kf(Jl(t,2),s,o,0,!1),d=Gu(e,u),h=Qv(e,n,r,u,d,l),p=h.x,y=h.y;return{scale:u,positionX:p,positionY:y}}function H1(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,b=h||v;if((r>=1||u)&&s3(e),!(b||!i||!e.mounted)){var w=t||i.offsetWidth/2,x=n||i.offsetHeight/2,E=r<o?o:l,k=$1(e,E,w,x);k&&El(e,k,p,y)}}var Ms=function(){return Ms=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},Ms.apply(this,arguments)};function bM(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},Zl={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"}},q0={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},o3=function(e){var t,n,r,i,s,o,l,u,d,h=Math.max((t=e.minScale)!==null&&t!==void 0?t:Zl.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:Zl.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:sw.scale,v=Math.min(Math.max(y,h),p),b=vf((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=vf((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:b,positionY:w}},wM=function(e){var t=Ms({},Zl);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Zl[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Zl[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=Ms(Ms({},Zl[r]),e[r]):u?t[r]=bM(bM([],Zl[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},a3=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=Kf(Jl(p,3),l,o,h,!1);return y};function l3(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,b=l.offsetWidth,w=l.offsetHeight,x=(b/2-h)/d,E=(w/2-p)/d,k=a3(e,t,n),T=$1(e,k,x,E);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");var N=e.props,z=N.onZoomStart,R=N.onZoom,F=N.onZoomStop,P=new MouseEvent("mousemove",{bubbles:!0}),q=kn(e);Ln(q,P,z),Ln(q,P,R),El(e,T,v,i);var H=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;H&&H.setTimeout(function(){e.mounted&&Ln(kn(e),P,F)},v)}function c3(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,h=o.centerOnInit,p=o3(e.props),y=e.state,v=y.scale,b=y.positionX,w=y.positionY;if(l){var x=p.positionX,E=p.positionY;if(h&&u){var k=U1(p.scale,l,u);x=k.positionX,E=k.positionY}var T=F1(e,p.scale),N=Yf(x,E,T,d,0,0,l),z={scale:p.scale,positionX:N.x,positionY:N.y};if(!(v===p.scale&&b===p.positionX&&w===p.positionY)){r==null||r();var R=e.props,F=R.onZoomStart,P=R.onZoom,q=R.onZoomStop,H=new MouseEvent("mousemove",{bubbles:!0}),$=kn(e);Ln($,H,F),Ln($,H,P),El(e,z,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&&Ln(kn(e),H,q)},t)}}}function Foe(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 $oe(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(),b=Foe(t,s,o,l),w=b.x,x=b.y,E=v.width/l.scale,k=v.height/l.scale,T=s.offsetWidth/E,N=s.offsetHeight/k,z=Kf(n||Math.min(T,N),h,p,0,!1),R=(y.width-E*z)/2,F=(y.height-k*z)/2,P=(y.left-w)*z+R+r,q=(y.top-x)*z+F+i,H=F1(e,z),$=Yf(P,q,H,d,0,0,s),D=$.x,M=$.y;return{positionX:D,positionY:M,scale:z}}var Hoe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),l3(e,1,t,n,r)}},Uoe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),l3(e,-1,t,n,r)}},Woe=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};El(e,v,i,s)}}},qoe=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),c3(e,t,n)}},Voe=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=U1(t||i.scale,s,o);El(e,l,n,r)}}},Yoe=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),Ys(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=$oe(e,u,n,s,o);El(e,d,r,i)}}},V0=function(e){return{instance:e,state:e.state,zoomIn:Hoe(e),zoomOut:Uoe(e),setTransform:Woe(e),resetTransform:qoe(e),centerView:Voe(e),zoomToElement:Yoe(e)}},Koe=function(e){return{instance:e,state:e.state}},kn=function(e){var t={};return Object.assign(t,Koe(e)),Object.assign(t,V0(e)),t},ow=!1;function aw(){try{var e={get passive(){return ow=!0,!1}};return e}catch{return ow=!1,ow}}var Hm=".".concat(q0.wrapperClass),Gf=function(e,t){return t.some(function(n){return e.matches("".concat(Hm," ").concat(n,", ").concat(Hm," .").concat(n,", ").concat(Hm," ").concat(n," *, ").concat(Hm," .").concat(n," *"))})},yf=function(e){e&&clearTimeout(e)},Goe=function(e){return Number.parseFloat(e.toFixed(8))},u3=function(e,t,n){var r=Goe(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},U1=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 Xoe(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Zoe(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var d3=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=Gf(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},Qoe=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=d3(e,t);if(l)return!1;var u=t.target,d=Gf(u,o);if(d)return!1;var h=e.isPressingKeys(s);return!!h},Joe=function(e){return e?e.deltaY<0?1:-1:0};function eae(e,t){var n=Joe(e),r=doe(t,n);return r}function h3(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 tae=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 b=s+t*n,w=r?!1:!v,x=Kf(b,d,u,y,w&&!p);return x},f3=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=Gf(o,i);return!u},rae=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},iae=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}},p3=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))},sae=5,oae=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,b=v*n,w=(b-n)*(y/sae),x=n+w,E=x===1/0?0:Jl(x,10);return Kf(E,o,s,h,!p&&!u)},m3=160,g3=100,aae=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(Ys(e),Ln(kn(e),t,r),Ln(kn(e),t,i))},lae=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,b=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=eae(t,null),T=b?E*Math.abs(t.deltaY):E,N=tae(e,k,T,!t.ctrlKey);if(u!==N){var z=Gu(e,N),R=h3(t,s,u),F=x||w===0||h||v,P=d&&F,q=Qv(e,R.x,R.y,N,z,P),H=q.x,$=q.y;e.previousWheelEvent=t,e.setState(N,H,$),Ln(kn(e),t,r),Ln(kn(e),t,i)}},cae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;yf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(H1(e,t.x,t.y),e.wheelAnimationTimer=null)},g3);var s=f3(e,t);s&&(yf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Ln(kn(e),t,r),Ln(kn(e),t,i))},m3))},uae=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(Ys(e),Ln(kn(e),t,r),Ln(kn(e),t,i))},dae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;yf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(H1(e,t.x,t.y),e.wheelAnimationTimer=null)},g3);var s=f3(e,t);s&&(yf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Ln(kn(e),t,r),Ln(kn(e),t,i))},m3))},v3=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}},hae=function(e,t){var n=p3(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=v3(t),Ys(e)},fae=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,b=h.disabled,w=h.size,x=y.allowPanning;if(!(r===null||!n)){var E=iae(t,o,n);if(!(!Number.isFinite(E.x)||!Number.isFinite(E.y))){var k=p3(t),T=oae(e,k),N=v3(t),z=o/T,R=(N.x-((s==null?void 0:s.x)||0))*z,F=(N.y-((s==null?void 0:s.y)||0))*z;if(!(T===o&&R===0&&F===0)){e.pinchPreviousCenter=N;var P=Gu(e,T),q=b||w===0||d,H=u&&q,$=Qv(e,E.x,E.y,T,P,H),D=$.x,M=$.y;if(e.pinchMidpoint=E,e.lastDistance=k,v.disabled||!x)e.setState(T,D,M);else{var j=p.sizeX,L=p.sizeY,O=fl(e,j,T),Y=fl(e,L,T),K=D+R,U=M+F,A=Yf(K,U,P,u,O,Y,i),W=A.x,G=A.y;e.setState(T,W,G)}}}}},pae=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,H1(e,t==null?void 0:t.x,t==null?void 0:t.y)},y3=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;yf(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,Ln(kn(e),t,n)},r)},mae=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;Ln(kn(e),t,r),c3(e,o,l,function(){return Ln(kn(e),t,i)}),y3(e,t)};function gae(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function vae(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,b=h.animationTime,w=h.animationType;if(!p&&!r){if(y==="reset")return mae(e,t);if(!s)return console.error("No ContentComponent found");var x=gae(y,e.state.scale),E=a3(e,x,v);if(o!==E){Ln(kn(e),t,u);var k=h3(t,s,o),T=$1(e,E,k.x,k.y);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");Ln(kn(e),t,d),El(e,T,b,w),y3(e,t)}}}var yae=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=Gf(u,l);return!p},_ae=(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&&Gu(n,n.state.scale),n.setup=wM(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),Ys(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(kn(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(kn(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=d3(n,r);s&&(aae(n,r),lae(n,r),cae(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=Qoe(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,b=o?h:y,w=l?p:v,x=n.setup.autoAlignment,E=x.sizeX,k=x.sizeY,T=fl(n,E),N=fl(n,k);b===h&&w===p||(uae(n,r),i3(n,b,w,T,N),Ln(kn(n),r,i),dae(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=mM(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(),Ys(n),yM(n,r),Ln(kn(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=gM(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),_M(n,r.clientX,r.clientY,nl.MOUSE),Ln(kn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(joe(n,i),Ln(kn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=nae(n,r);o&&(hae(n,r),Ys(n),Ln(kn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=rae(n);o&&(r.preventDefault(),r.stopPropagation(),fae(n,r),Ln(kn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(pae(n),Ln(kn(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,Ys(n);var h=r.touches,p=h.length===1,y=h.length===2,v=mM(n,r);if(p){if(!v)return;Ys(n),yM(n,r),Ln(kn(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=gM(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];_M(n,l.clientX,l.clientY,nl.TOUCH),Ln(kn(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=yae(n,r);s&&vae(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=U1(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):u3(r,i,s)},this.getContext=function(){return kn(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:kn(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=kn(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),Ln(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,Gu(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=kn(n);Ln(s,void 0,n.props.onInit),Xoe(n.props.ref,s)},this.props=t,this.setup=wM(this.props),this.state=o3(this.props)}return e})(),Jv=Ge.createContext(null),bae=function(e,t){return typeof e=="function"?e(t):e},wae=Ge.forwardRef(function(e,t){var n=_.useRef(new _ae(e)).current,r=bae(e.children,V0(n));return _.useImperativeHandle(t,function(){return V0(n)},[n]),_.useEffect(function(){n.update(e)},[n,e]),g.jsx(Jv.Provider,Ms({value:n},{children:r}))});Ge.forwardRef(function(e,t){var n=_.useRef(null),r=_.useContext(Jv);return _.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",Ms({},e,{ref:Zoe([n,t])}))});function Sae(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 xae=`.transform-component-module_wrapper__SPB86 {
|
|
503
503
|
position: relative;
|
|
@@ -634,7 +634,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
|
|
|
634
634
|
`))return null;const n=Wme(t);return!n||/\s/.test(n)||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||uE(n)||n.split("/").includes("...")?null:n}function Vme(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 Ume.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function Yme(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(b4,""),n=t.split("/").pop()??t;return/[A-Za-z_-]/.test(n)}function Kme(e){const t=qme(e);return!t||Vme(t)||!Yme(t)?null:Hme.test(t)?{kind:"image-preview",path:t}:b4.test(t)?{kind:"file-download",path:t}:null}const Gme=16,Xme=24,wh=6,Zme=425,qh=-1;function Qm(e,t){return e.pointerId===t||t===qh}function pu(e){return Math.hypot(e.lastX-e.startX,e.lastY-e.startY)}function Mi(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 Qme({terminalRef:e,suppressPtyFocus:t,focusTerminal:n,onLongPressCandidateStart:r,onTap:i,isTapCandidate:s,onLongPressStart:o,onLongPressMove:l,onLongPressEnd:u}){const d=_.useRef(null),h=_.useCallback($=>{$.longPressTimer!==null&&(window.clearTimeout($.longPressTimer),$.longPressTimer=null)},[]),p=_.useCallback($=>{$.longPressed||$.moved||($.longPressed=!0,$.longPressArmed=!1,h($),t(),o==null||o({clientX:$.startX,clientY:$.startY}))},[h,o,t]),y=_.useCallback($=>{if(!($.longPressed||$.longPressArmed||$.moved)){if(pu($)>wh){h($),Mi("longpress:cancel-drift",{distance:pu($),threshold:wh});return}if(s!=null&&s({clientX:$.startX,clientY:$.startY})){$.longPressArmed=!0,h($),Mi("longpress:arm-link",{clientX:$.startX,clientY:$.startY});return}p($)}},[h,s,p]),v=_.useCallback($=>{if($.longPressDelivered||!$.longPressed||$.moved)return;$.longPressDelivered=!0;const D={clientX:$.lastX,clientY:$.lastY};window.setTimeout(()=>u==null?void 0:u(D),0)},[u]),b=_.useCallback(($,D,M,j=!1)=>{const L={pointerId:$,startX:D,startY:M,lastX:D,lastY:M,moved:!1,longPressArmed:!1,longPressed:!1,longPressDelivered:!1,touchEventStream:j,longPressTimer:null};L.longPressTimer=window.setTimeout(()=>{d.current===L&&y(L)},Zme),d.current=L,Mi("start",{pointerId:$,clientX:D,clientY:M,touchEventStream:j}),r==null||r({clientX:D,clientY:M})},[y,r]),w=_.useCallback(($,D,M)=>{const j=d.current;if(!j||!Qm(j,$))return!1;j.lastX=D,j.lastY=M;const L=pu(j);if(j.longPressArmed&&L>wh&&(j.longPressArmed=!1,Mi("longpress:cancel-armed-drift",{pointerId:$,clientX:D,clientY:M,distance:L,threshold:wh})),j.longPressed)return Mi("move",{pointerId:$,clientX:D,clientY:M,distance:L,moved:j.moved,longPressed:!0}),l==null||l({clientX:D,clientY:M}),!0;const O=D-j.startX,Y=M-j.startY;return!j.moved&&L>=Gme&&(j.moved=!0,h(j)),Mi("move",{pointerId:$,clientX:D,clientY:M,dx:O,dy:Y,distance:L,moved:j.moved,longPressed:!1}),j.moved},[h,l]),x=_.useCallback(($,D)=>{var O;const M=d.current;if(!M||!Qm(M,$))return null;D&&(M.lastX=D.clientX,M.lastY=D.clientY),d.current=null,h(M);const j=pu(M);let L;if(M.longPressArmed){if(j<=wh)return p(M),v(M),L="longpress",Mi("finish",{pointerId:$,result:L,point:D,moved:M.moved,distance:j,longPressed:!0,longPressArmed:!0}),L;M.longPressArmed=!1}return M.longPressed?(v(M),L="longpress",Mi("finish",{pointerId:$,result:L,point:D,moved:M.moved,longPressArmed:M.longPressArmed,distance:j,longPressed:!0}),L):M.moved?D&&pu(M)<=Xme&&(i!=null&&i(D))?(t(),L="link",Mi("finish",{pointerId:$,result:L,point:D,moved:!0,distance:j,longPressed:!1}),L):(t(),L="scroll",Mi("finish",{pointerId:$,result:L,point:D,moved:!0,distance:j,longPressed:!1}),L):D&&(i!=null&&i(D))?(t(),L="link",Mi("finish",{pointerId:$,result:L,point:D,moved:!1,distance:j,longPressed:!1}),L):(n?n():(O=e.current)==null||O.focus(),L="tap",Mi("finish",{pointerId:$,result:L,point:D,moved:!1,distance:j,longPressed:!1}),L)},[h,v,n,i,p,t,e]),E=_.useCallback($=>{const D=d.current;return!D||!Qm(D,$)?null:(h(D),d.current=null,D.longPressed?(v(D),Mi("cancel",{pointerId:$,result:"longpress"}),"longpress"):(D.longPressArmed&&Mi("cancel",{pointerId:$,result:"armed"}),t(),Mi("cancel",{pointerId:$,result:"scroll",moved:D.moved,distance:pu(D)}),"scroll"))},[h,v,t]),k=_.useCallback($=>{if($.pointerType!=="touch")return;const D=$.target;!(D instanceof Element)||!D.closest(".xterm")||(b($.pointerId,$.clientX,$.clientY),$.stopPropagation())},[b]),T=_.useCallback($=>{if($.pointerType!=="touch")return;const D=w($.pointerId,$.clientX,$.clientY),M=d.current;M&&D&&($.stopPropagation(),M.longPressed&&$.preventDefault())},[w]),N=_.useCallback($=>{const D=x($.pointerId,{clientX:$.clientX,clientY:$.clientY});D&&($.stopPropagation(),D==="link"&&$.cancelable&&$.preventDefault())},[x]),z=_.useCallback($=>{const D=d.current;if($.pointerType==="touch"&&D&&Qm(D,$.pointerId)&&D.touchEventStream&&!D.longPressed){$.stopPropagation();return}E($.pointerId)&&$.stopPropagation()},[E]),R=_.useCallback($=>{const D=$.target;if(!(D instanceof Element)||!D.closest(".xterm"))return;if(d.current){d.current.touchEventStream=!0;return}const M=$.touches[0]??$.changedTouches[0];M&&b(qh,M.clientX,M.clientY,!0)},[b]),F=_.useCallback($=>{const D=$.touches[0]??$.changedTouches[0];if(!D)return;const M=w(qh,D.clientX,D.clientY),j=d.current;j&&M&&j.longPressed&&($.stopPropagation(),$.preventDefault())},[w]),P=_.useCallback($=>{const D=$.changedTouches[0],M=d.current,j=D?{clientX:D.clientX,clientY:D.clientY}:M?{clientX:M.lastX,clientY:M.lastY}:void 0,L=x(qh,j);(L==="longpress"||L==="link")&&($.stopPropagation(),$.cancelable&&$.preventDefault())},[x]),q=_.useCallback($=>{E(qh)==="longpress"&&$.stopPropagation()},[E]),H=_.useCallback($=>{const D=d.current;D&&($.preventDefault(),$.stopPropagation(),y(D))},[y]);return{onPointerDownCapture:k,onPointerMoveCapture:T,onPointerUpCapture:N,onPointerCancelCapture:z,onTouchStartCapture:R,onTouchMoveCapture:F,onTouchEndCapture:P,onTouchCancelCapture:q,onContextMenuCapture:H}}function Jme({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:b,onHandleDragEnd:w,onHandleDragCancel:x}){const E=_.useRef(null),k=_.useRef(null),T=_.useRef(null),N=_.useRef(!1),z=_.useRef(null),R=_.useCallback(()=>{var L;(L=z.current)==null||L.call(z),z.current=null,k.current=null,T.current=null,N.current=!1,E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)},[]),F=_.useCallback(()=>{var U;E.current=null;const L=k.current;if(!L||!t||!i())return;const O=t.getBoundingClientRect(),{dx:Y,dy:K}=J5({pointerX:L.clientX,pointerY:L.clientY,rect:O,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:44,maxSpeedPx:18});Y!==0&&(p==null||p(`selectionGestureAutoscroll dx=${Math.round(Y)}`),t.scrollLeft+=Y),K!==0&&(t.scrollTop+=K),(Y!==0||K!==0)&&(y==null||y({scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}),(U=T.current)==null||U.call(T,L)),E.current=requestAnimationFrame(F)},[t,i,p,y]),P=_.useCallback((L,O)=>{k.current=L,T.current=O,E.current===null&&(E.current=requestAnimationFrame(F))},[F]);_.useEffect(()=>R,[R]),_.useEffect(()=>{if(!t)return;const L=O=>{N.current&&O.preventDefault()};return t.addEventListener("touchmove",L,{capture:!0,passive:!1}),document.addEventListener("touchmove",L,{capture:!0,passive:!1}),()=>{t.removeEventListener("touchmove",L,{capture:!0}),document.removeEventListener("touchmove",L,{capture:!0})}},[t]);const q=_.useCallback(L=>{R(),N.current=!0,u(L)},[u,R]),H=_.useCallback(L=>{d(L),P(L,d)},[d,P]),$=_.useCallback(L=>{R(),h(L)},[h,R]),D=Qme({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:q,onLongPressMove:H,onLongPressEnd:$}),M=_.useCallback((L,O)=>{O.preventDefault(),O.stopPropagation(),R(),N.current=!0,v(L);let Y=()=>{};const K=W=>{W.cancelable&&W.preventDefault();const G={clientX:W.clientX,clientY:W.clientY};b(L,G),P(G,I=>b(L,I))},U=W=>{const G={clientX:W.clientX,clientY:W.clientY};Y(),z.current=null,R(),w(L,G)},A=()=>{Y(),z.current=null,R(),x(L)};Y=()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",U),window.removeEventListener("pointercancel",A)},z.current=Y,window.addEventListener("pointermove",K,{passive:!1}),window.addEventListener("pointerup",U,{once:!0}),window.addEventListener("pointercancel",A,{once:!0})},[x,w,b,v,R,P]),j=_.useCallback((L,O)=>{if(z.current||!(O.touches[0]??O.changedTouches[0]))return;O.preventDefault(),O.stopPropagation(),N.current=!0,v(L);let K=()=>{};const U=G=>{const I=G.touches[0]??G.changedTouches[0];if(!I)return;G.cancelable&&G.preventDefault();const ne={clientX:I.clientX,clientY:I.clientY};b(L,ne),P(ne,ie=>b(L,ie))},A=G=>{const I=G.changedTouches[0],ne=I?{clientX:I.clientX,clientY:I.clientY}:k.current;K(),z.current=null,R(),w(L,ne)},W=()=>{K(),z.current=null,R(),x(L)};K=()=>{window.removeEventListener("touchmove",U),window.removeEventListener("touchend",A),window.removeEventListener("touchcancel",W)},z.current=K,window.addEventListener("touchmove",U,{passive:!1}),window.addEventListener("touchend",A,{once:!0}),window.addEventListener("touchcancel",W,{once:!0})},[x,w,b,v,R,P]);return{pointerHandlers:D,stopPtySelectionGesture:R,handlePtySelectionHandlePointerDown:M,handlePtySelectionHandleTouchStart:j}}const ege=8;function tge(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:b}=e,w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(!1),N=_.useRef(null),z=_.useRef(null),R=_.useRef(""),F=_.useRef(null),[P,q]=_.useState(null),[H,$]=_.useState(null),[D,M]=_.useState(null),j=_.useMemo(()=>jme(u),[u]),L=_.useCallback((ce,Ce)=>{const He=window.visualViewport;return _4({clientX:ce,clientY:Ce,viewportWidth:(He==null?void 0:He.width)??window.innerWidth,viewportHeight:(He==null?void 0:He.height)??window.innerHeight,viewportOffsetLeft:(He==null?void 0:He.offsetLeft)??0,viewportOffsetTop:(He==null?void 0:He.offsetTop)??0})},[]),O=_.useCallback((ce,Ce)=>{const He=n.current,tt=r.current;return!He||!tt?null:Fme({terminal:He,host:tt,anchor:ce,focus:Ce})},[n,r]),Y=_.useCallback((ce,Ce)=>{const He=Ce??Kme(ce);return z.current=He,M(He),He},[]),K=_.useCallback(ce=>{const Ce=window.visualViewport;return $me({handles:ce,viewportWidth:(Ce==null?void 0:Ce.width)??window.innerWidth,viewportHeight:(Ce==null?void 0:Ce.height)??window.innerHeight,viewportOffsetLeft:(Ce==null?void 0:Ce.offsetLeft)??0,viewportOffsetTop:(Ce==null?void 0:Ce.offsetTop)??0})},[]),U=_.useCallback(()=>{const ce=w.current,Ce=x.current;if(!ce||!Ce){$(null);return}const He=O(ce,Ce);if($(He),!He){q(null);return}q(tt=>tt&&K(He))},[O,K]),A=_.useCallback(()=>{var ce,Ce;(ce=F.current)==null||ce.call(F),E.current=null,k.current=null,w.current=null,x.current=null,T.current=!1,N.current=null,z.current=null,R.current="",(Ce=n.current)==null||Ce.clearSelection(),q(null),$(null),M(null)},[n]),W=_.useCallback((ce="")=>{w.current=null,x.current=null,T.current=!1,z.current=null,R.current=ce,q(null),$(null),M(null)},[]),G=_.useCallback(({clientX:ce,clientY:Ce})=>{const He=n.current,tt=r.current;d({blur:!1}),k.current={clientX:ce,clientY:Ce},E.current=He&&tt?Wh({terminal:He,host:tt,clientX:ce,clientY:Ce}):null},[d,n,r]),I=_.useCallback(({clientX:ce,clientY:Ce,draggedHandle:He="focus"})=>{const tt=n.current,it=r.current,ht=w.current,yt=x.current;if(!tt||!it||!ht)return null;const fe=Wh({terminal:tt,host:it,clientX:ce,clientY:Ce});if(!fe)return null;const Ae=He==="anchor"?fe:ht,nt=He==="focus"?fe:yt??ht;w.current=Ae,x.current=nt,T.current=!0;const Ze=sv({terminal:tt,anchor:Ae,focus:nt});return R.current=(Ze==null?void 0:Ze.text)??"",Y((Ze==null?void 0:Ze.text)??""),$(Ze?O(Ae,nt):null),Ze},[O,Y,n,r]),ne=_.useCallback(({point:ce,clientX:Ce,clientY:He,showToolbar:tt=!0})=>{const it=n.current,ht=r.current;if(!it||!ht)return!1;N.current=null;const yt=ce?V2({terminal:it,point:ce}):null,fe=yt??(ce?VS({terminal:it,point:ce}):q2({terminal:it,host:ht,clientX:Ce,clientY:He}));if(!(fe!=null&&fe.text))return!1;w.current=fe.anchor,x.current=fe.focus,R.current=fe.text,Y(fe.text,yt==null?void 0:yt.pathAction);const Ae=O(fe.anchor,fe.focus);return $(Ae),tt&&q(Ae?K(Ae):L(Ce,He)),!0},[O,L,K,Y,n,r]),ie=_.useCallback(()=>{const ce=w.current,Ce=x.current;if(!ce||!Ce){q(null);return}const He=O(ce,Ce);$(He),q(He?K(He):null)},[O,K]),se=_.useCallback(ce=>{var tt,it;const Ce=((it=(tt=n.current)==null?void 0:tt.getSelection)==null?void 0:it.call(tt))??"",He=Y(Ce);R.current=Ce,w.current=null,x.current=null,T.current=!1,$(null),q(He?L(ce.clientX,ce.clientY):null)},[L,Y,n]);_.useEffect(()=>{const ce=r.current;if(!ce)return;let Ce=!1;const He=ht=>{var fe,Ae;if(ht.pointerType!=="mouse"||ht.button!==0)return;const yt=ht.target;!(yt instanceof Element)||!yt.closest(".xterm")||(Ce=!0,W(((Ae=(fe=n.current)==null?void 0:fe.getSelection)==null?void 0:Ae.call(fe))??""))},tt=ht=>{if(ht.pointerType!=="mouse"||!Ce)return;Ce=!1;const yt={clientX:ht.clientX,clientY:ht.clientY};window.setTimeout(()=>se(yt),0)},it=()=>{Ce=!1};return ce.addEventListener("pointerdown",He,!0),window.addEventListener("pointerup",tt,!0),window.addEventListener("pointercancel",it,!0),()=>{ce.removeEventListener("pointerdown",He,!0),window.removeEventListener("pointerup",tt,!0),window.removeEventListener("pointercancel",it,!0)}},[W,se,n,r]),_.useLayoutEffect(()=>{if(!P&&!H)return;const ce=Ce=>{const He=Ce.target;He instanceof Element&&He.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]')||A()};return document.addEventListener("pointerdown",ce,!0),document.addEventListener("touchstart",ce,!0),()=>{document.removeEventListener("pointerdown",ce,!0),document.removeEventListener("touchstart",ce,!0)}},[A,H,P]),_.useEffect(()=>{if(!s||!P)return;const ce=()=>{const Ce=N.current;Ce&&s.scrollLeft===Ce.scrollLeft&&s.scrollTop===Ce.scrollTop||A()};return s.addEventListener("scroll",ce,{passive:!0}),()=>s.removeEventListener("scroll",ce)},[A,s,P]);const te=H!==null;_.useLayoutEffect(()=>{var ce;te&&((ce=i.current)==null||ce.relayout(),U())},[te,l,U,i]),_.useEffect(()=>{te&&U()},[te,U,o.scrollLeft,o.scrollTop]),_.useEffect(()=>{if(!te)return;const ce=window.visualViewport;let Ce=0,He=0;const tt=()=>{cancelAnimationFrame(Ce),window.clearTimeout(He),Ce=requestAnimationFrame(()=>{U(),He=window.setTimeout(()=>{Ce=requestAnimationFrame(()=>U())},160)})};return tt(),window.addEventListener("resize",tt),ce==null||ce.addEventListener("resize",tt),ce==null||ce.addEventListener("scroll",tt),()=>{cancelAnimationFrame(Ce),window.clearTimeout(He),window.removeEventListener("resize",tt),ce==null||ce.removeEventListener("resize",tt),ce==null||ce.removeEventListener("scroll",tt)}},[te,U]);const de=_.useCallback(({clientX:ce,clientY:Ce})=>{const He=n.current,tt=r.current;if(!He||!tt)return;const it=Wh({terminal:He,host:tt,clientX:ce,clientY:Ce})??E.current;if(He.clearSelection(),!it){w.current=null,x.current=null,z.current=null,R.current="",q(null),$(null),M(null);return}w.current=it,x.current=it,T.current=!1,z.current=null,R.current="",q(null),$(null),M(null),ne({point:it,clientX:ce,clientY:Ce,showToolbar:!1})},[ne,n,r]),ve=_.useCallback(({clientX:ce,clientY:Ce})=>{I({clientX:ce,clientY:Ce}),q(null)},[I]),xe=_.useCallback(({clientX:ce,clientY:Ce})=>{const He=n.current,tt=r.current;if(!He||!tt)return;const it=w.current,ht=Wh({terminal:He,host:tt,clientX:ce,clientY:Ce}),yt=ht??x.current,fe=E.current,Ae=k.current,nt=Ae?Math.hypot(ce-Ae.clientX,Ce-Ae.clientY)>=ege:!1,Ze=fe??ht;if(!T.current&&!nt&&R.current){ie(),E.current=null,k.current=null;return}const st=!T.current&&!nt&&Ze?V2({terminal:He,point:Ze}):null,Mt=nt?ht??yt:yt,Ht=(T.current||nt)&&it&&Mt?sv({terminal:He,anchor:it,focus:Mt}):st??q2({terminal:He,host:tt,clientX:ce,clientY:Ce})??(fe?VS({terminal:He,point:fe}):null);if(E.current=null,k.current=null,!(Ht!=null&&Ht.text)){A();return}w.current=Ht.anchor,x.current=Ht.focus,R.current=Ht.text,Y(Ht.text,st==null?void 0:st.pathAction);const Yt=O(Ht.anchor,Ht.focus);$(Yt),q(Yt?K(Yt):L(ce,Ce))},[A,O,L,K,Y,ie,n,r]),Re=_.useCallback(()=>{var He;const ce=n.current,Ce=((He=ce==null?void 0:ce.getSelection)==null?void 0:He.call(ce))||R.current;Ce&&v4(Ce,{allowLegacyFallback:!0}).then(tt=>{A(),tt==="failed"?rt.error("复制失败"):rt.success("已复制")})},[A,n]),ze=_.useCallback(()=>{const ce=z.current;ce&&(ce.kind==="image-preview"?b(ce.path):v(ce.path),A())},[A,v,b]),Ye=_.useCallback(()=>w.current!==null,[]),mt=_.useCallback(()=>{q(null)},[]),zt=_.useCallback((ce,{clientX:Ce,clientY:He})=>{I({clientX:Ce,clientY:He,draggedHandle:ce}),q(null)},[I]),ge=_.useCallback((ce,Ce)=>{Ce&&I({...Ce,draggedHandle:ce}),R.current&&ie()},[I,ie]),he=_.useCallback(()=>{q(null)},[]);_.useEffect(()=>{},[A,O,K,t,Y,n]);const Ve=Jme({terminalRef:n,containerEl:s,suppressPtyFocus:d,focusPtyInput:h,isSelectionActive:Ye,onTap:p,isTapCandidate:y,onLongPressCandidateStart:G,onLongPressStart:de,onLongPressMove:ve,onLongPressEnd:xe,onHorizontalScrollIntent:ce=>{var Ce;return(Ce=i.current)==null?void 0:Ce.markHorizontalScrollIntent(ce)},onSelectionAutoscroll:ce=>{N.current=ce},onHandleDragStart:mt,onHandleDragMove:zt,onHandleDragEnd:ge,onHandleDragCancel:he});return F.current=Ve.stopPtySelectionGesture,{pointerHandlers:Ve.pointerHandlers,ptySelectionToolbar:P,ptySelectionHandles:H,ptySelectionPathAction:D,ptySelectionHandleMetrics:j,copyPtySelection:Re,openPtySelectionPathAction:ze,handlePtySelectionHandlePointerDown:Ve.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Ve.handlePtySelectionHandleTouchStart}}function nge(){return Ie(e=>e.ptyScrollTraceEnabled)}const rge=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function K2(e){return rge.has(e)}function mE(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!K2(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>K2(r.type))??null}function ige(e){return`${e.startsWith("@")?e:`@${e}`} `}function G2(e,t,n,r){const i=Math.max(0,Math.min(n,e.length)),s=Math.max(i,Math.min(r,e.length));return{value:`${e.slice(0,i)}${t}${e.slice(s)}`,cursor:i+t.length}}async function w4(e){const t=mE(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await m4(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 sge(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 oge({sessionId:e,terminalRef:t,onAfterPaste:n}){return _.useCallback(async r=>{var u;const i=r.clipboardData,s=!!mE(i),o=s?null:sge(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Ot;if(!l){rt.error("请先连接开发机");return}if(s){const d=rt.loading("图片上传中...");try{const h=await w4({clipboardData:i,relay:l,sessionId:e});if(rt.dismiss(d),!h)return;Ks(e,h.pathMention)}catch(h){rt.error(h instanceof Error?h.message:String(h),{id:d});return}}else if(o){const d=await Ef({relay:l,sessionId:e,file:o});if(!d)return;Ks(e,`@${d} `)}n==null||n(),(u=t.current)==null||u.focus()},[e,t,n])}const age=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),X2={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:hfe};function lge({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function cge({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function uge({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function dge({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:age.has(n)}const Z2=8,hge=32;function fge({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+Z2:t?hge:Z2}function pge(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 mge(e){const{sessionId:t,sessionKind:n,ptyOwner:r,active:i=!0,containerEl:s,spacerRef:o,xtermHostRef:l,mobileControlsHeight:u}=e,d=Sme(),h=kme(),p=nge(),{openImagePreview:y}=w3(),v=_.useRef(null),b=_.useRef(null),w=_.useRef([]),x=_.useRef(null),E=_.useRef(null),k=_.useRef(i),T=_.useRef(i),N=_.useRef(!1),z=_.useRef(!1),R=_.useRef(!1),F=_.useRef(null),P=_.useRef(null),q=_.useRef(null),H=_.useRef(null),$=_.useRef({keyboardOpen:!1,controlsVisible:!1}),D=_.useRef(!1),M=_.useRef(!1),j=_.useRef(!1),L=_.useRef(!1),O=_.useRef(null),Y=_.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[K,U]=_.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[A,W]=_.useState(!1),[G,I]=_.useState(!1),[ne,ie]=_.useState({resultIndex:-1,resultCount:0}),se=Ie(we=>we.connected),te=Ie(we=>we.proxyOnline),de=Ie(we=>we.ptyFontSize),ve=Ie(we=>we.inputModePreference),xe=Ie(we=>we.adaptiveInputModality),Re=Ie(we=>we.setAdaptiveInputModality),ze=xe==="hardware",Ye=r==="proxy-hosted"||n==="terminal",mt=hl("(pointer: coarse), (hover: none)"),{bottomOffset:zt,layoutBottomInset:ge}=pE(),he=ve==="hardware",Ve=uge({touchEditingSurface:mt,inputModePreference:ve,detectedPhysicalKeyboard:ze,softKeyboardDetected:zt>0}),ce=mt&&!Ve,Ce=Ve?0:zt,He=Ce>0,tt=Ve?0:ge;M.current=Ve,_.useEffect(()=>{k.current=i},[i]),_.useEffect(()=>{N.current=d.ready},[d.ready]);const it=_.useCallback(()=>k.current&&N.current,[]);_.useEffect(()=>{Ce>0&&W(!0)},[Ce]);const ht=Cme({containerEl:s,xtermHostRef:l,terminalRef:v}),{ptyInputFocused:yt,suppressPtyFocus:fe,focusPtyInput:Ae,handleFocusCapture:nt,handleBlurCapture:Ze}=ht,st=lge({softKeyboardEditingSurface:ce,ptyInputFocused:yt,keyboardOpen:He});D.current=ce&&(st||Ce>0),Y.current={keyboardOffset:Ce,hasSeenSoftKeyboard:A,showMobilePtyControls:st,touchEditingSurface:mt,ptyInputFocused:yt,containerPaddingBottom:Y.current.containerPaddingBottom,mobileControlsBottomInset:tt};const Mt=h.clearNewFramesWhileAway;P.current||(P.current=j2(()=>{var we;(we=E.current)==null||we.relayout()})),q.current||(q.current=j2(()=>{var Se,je;const we=H.current??{reason:"rawInput",force:!1};H.current=null,(Se=E.current)==null||Se.traceRawInputFollowFire(),(je=E.current)==null||je.scrollToBottom(we.reason,we.force?{force:!0}:void 0),Mt()}));const Ht=_.useCallback(()=>{O.current!==null&&(cancelAnimationFrame(O.current),O.current=null)},[]),Yt=_.useCallback(()=>{L.current=!0,Ht()},[Ht]),Xt=_.useCallback(()=>{var we;!L.current||document.visibilityState==="hidden"||((we=E.current)==null||we.preparePageResumeRestore(),Ht(),O.current=requestAnimationFrame(()=>{O.current=requestAnimationFrame(()=>{O.current=null;const Se=E.current;Se&&(Se.restorePageResume(),Mt(),L.current=!1)})}))},[Ht,Mt]);_.useEffect(()=>()=>{var we,Se;(we=P.current)==null||we.dispose(),(Se=q.current)==null||Se.dispose(),Ht(),P.current=null,q.current=null},[Ht]),_.useEffect(()=>{const we=()=>{Yt()},Se=()=>{if(document.visibilityState==="hidden"){we();return}Xt()};return document.addEventListener("visibilitychange",Se),window.addEventListener("pagehide",we),window.addEventListener("pageshow",Xt),window.addEventListener("focus",Xt),()=>{document.removeEventListener("visibilitychange",Se),window.removeEventListener("pagehide",we),window.removeEventListener("pageshow",Xt),window.removeEventListener("focus",Xt),Ht()}},[Ht,Yt,Xt]),_.useEffect(()=>{const we=T.current;if(T.current=i,we!==i){if(!i){Yt();return}Xt()}},[i,Yt,Xt]);const Pt=_.useCallback((we="rawInput",Se)=>{var ft,Lt;const je=H.current,et=(je==null?void 0:je.force)===!0||(Se==null?void 0:Se.force)===!0;H.current={reason:(Se==null?void 0:Se.force)===!0||!je?we:je.reason,force:et},(ft=E.current)==null||ft.traceRawInputFollowScheduled(we),(Lt=q.current)==null||Lt.schedule()},[]),Bt=_.useCallback(()=>{var we,Se;(we=x.current)==null||we.setOutputPaused(!1),(Se=x.current)==null||Se.flushOutput()},[]),Mn=_.useCallback((we,Se)=>{var je;!we.includes("\r")&&!we.includes(`
|
|
635
635
|
`)||(je=E.current)==null||je.resetHorizontalScroll(Se,{holdUntilCursorVisible:!0})},[]),pn=_.useCallback(()=>M.current?"submit":"linefeed",[]),_n=_.useCallback(()=>M.current,[]);_.useEffect(()=>{if(!i||ve!=="auto"||!mt)return;const we=je=>{const et=l.current,ft=s;return je instanceof Node?et!=null&&et.contains(je)||je===document.body||je===document.documentElement?!0:ft!=null&&ft.contains(je)?je instanceof HTMLElement?je.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:je===window},Se=je=>{var Lt;if(!dge({active:k.current,touchEditingSurface:mt,key:je.key,code:je.code,altKey:je.altKey,ctrlKey:je.ctrlKey,metaKey:je.metaKey,isComposing:je.isComposing,targetAcceptsPtyInput:we(je.target)}))return;Re("hardware"),M.current=!0,(Lt=v.current)==null||Lt.focus();const et=l.current;if(je.target instanceof Node&&(et!=null&&et.contains(je.target)))return;const ft=pge(je);!ft||!it()||(je.preventDefault(),je.stopPropagation(),Ks(t,ft),Bt(),Pt("physicalKeyboard"),Mn(ft,"physicalKeyboardEnter"))};return window.addEventListener("keydown",Se,!0),()=>window.removeEventListener("keydown",Se,!0)},[i,it,s,ve,Mn,Bt,Pt,t,Re,mt,l]);const Le=_.useCallback(we=>{const Se=Ot;if(!Se){rt.error("请先连接开发机");return}const je=rt.loading(`下载 ${we} ...`);W1({relay:Se,sessionId:t,path:we}).then(et=>{et.ok?rt.success(`已开始下载 ${we}`,{id:je}):rt.error(et.error,{id:je})}).catch(et=>{rt.error(et instanceof Error?et.message:String(et),{id:je})})},[t]),Xe=_.useCallback(we=>{const Se=v.current;return Se?tme(Se,w.current,we):!1},[]),Nt=_.useCallback(we=>{const Se=v.current;return Se?eme(Se,w.current,we):!1},[]),At=tge({sessionId:t,terminalRef:v,xtermHostRef:l,scrollControllerRef:E,containerEl:s,scrollState:K,keyboardOffset:Ce,ptyFontSize:de,suppressPtyFocus:fe,focusPtyInput:Ae,onTap:Xe,isTapCandidate:Nt,onDownloadPath:Le,onPreviewPath:y});j.current=At.ptySelectionHandles!==null;const J=oge({sessionId:t,terminalRef:v,onAfterPaste:()=>{Bt(),Pt("paste")}}),ye=_.useCallback(we=>{if(!it()){we.preventDefault();return}J(we)},[it,J]),[Ue,dt]=_.useState(!1),jt=_.useCallback(we=>{we.dataTransfer.types.includes("Files")&&(we.preventDefault(),dt(Se=>Se||!0))},[]),re=_.useCallback(we=>{we.currentTarget.contains(we.relatedTarget)||dt(!1)},[]),oe=_.useCallback(async we=>{var ft;const Se=(ft=we.dataTransfer.files)==null?void 0:ft[0];if(!Se||(we.preventDefault(),dt(!1),!it()))return;const je=Ot;if(!je){rt.error("请先连接开发机");return}const et=await Ef({relay:je,sessionId:t,file:Se});et&&(Ks(t,`@${et} `),Bt(),Pt("dropUpload"))},[it,Bt,Pt,t]),ue=_.useCallback(we=>{var je;if(!it()){we.preventDefault();return}const Se=we.target;Se instanceof Element&&Se.closest(".xterm")||(we.preventDefault(),(je=v.current)==null||je.focus())},[it]);_.useEffect(()=>{if(!se||!te)return;const we=l.current,Se=tc,je=Ot,et=s,ft=o.current;if(!we||!Se||!je||!et||!ft)return;let Lt=null,Rn=null,tn=null,Kn=null,An=null,Ai=null;const _t=mpe({host:we,sessionId:t,ws:Se,relay:je,scheduleAutoFocus:ce?()=>{}:void 0,createTerminal:async Ct=>await X5(Ct,{fontSize:Ie.getState().ptyFontSize}),attachRawInput:(Ct,Kt,On)=>Mfe(Ct,Kt,{...On,getPlainEnterBehavior:pn,isPhysicalKeyboardMode:_n,physicalKeyboardMode:he}),isInputEnabled:it,canFocus:it,onTerminalReady:Ct=>{const Kt=Ct;v.current=Kt;const On=new $le({highlightLimit:1e3});Kt.loadAddon(On),b.current=On,Ai=On.onDidChangeResults(ar=>{ie(ar)}),I(!0);const Ft=Ipe(Kt,y);Lt=Ft.dispose;const Nn=Gpe(Kt,Le);Rn=Nn.dispose,w.current=[Ft.provider,Nn.provider],gme(()=>v.current);const Qn=L.current;Qn&&(R.current=!1);const un=upe({container:et,spacer:ft,host:we,term:Kt,hasNewFrame:()=>z.current,consumeNewFrame:()=>{z.current=!1},hasNewFramesWhileAway:()=>h.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:h.setHasNewFramesWhileAway,onAtBottomChange:h.handleAtBottomChange,onScrollStateChange:U,initialUserHasVerticalScrollIntent:Qn?!1:R.current,onUserVerticalScrollIntentChange:ar=>{var gr,si;R.current=ar,(gr=x.current)==null||gr.setOutputPaused(ar),ar||(si=x.current)==null||si.flushOutput()},onTouchReviewStart:fe,onTouchBoundaryPrevent:fe});E.current=un,tn=un.dispose,Qn&&(un.restorePageResume(),Mt(),L.current=!1),yme(()=>{var ha;const ar=to=>{if(!to)return null;const es=to.getBoundingClientRect();return{top:es.top,bottom:es.bottom,height:es.height,left:es.left,right:es.right,width:es.width}},gr=document.querySelector('[data-slot="pty-mobile-controls"]'),si=document.querySelector("[data-keyboard-offset]"),vi=window.visualViewport,kl=ar(gr),yi=(vi==null?void 0:vi.height)??window.innerHeight;return{...bme(un.getDebugProbe,{container:et,spacer:ft,host:we,term:Kt}),mobileLayout:{...Y.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:vi?{height:vi.height,width:vi.width,offsetTop:vi.offsetTop,pageTop:vi.pageTop,scale:vi.scale}:null,chatRoot:{dataKeyboardOffset:(si==null?void 0:si.getAttribute("data-keyboard-offset"))??null,rect:ar(si)},ptyViewRect:ar(et.parentElement),containerRect:ar(et),controlsRect:kl,controlsOverflowBelowVisualViewport:kl===null?null:kl.bottom-yi,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(ha=document.activeElement.closest("[data-slot]"))==null?void 0:ha.getAttribute("data-slot")}:null},frame:{lastWriteAt:F.current,pendingNewFrame:z.current}}}),An=yfe({container:et,host:we,onHorizontalScrollIntent:ar=>{var gr;return(gr=E.current)==null?void 0:gr.markHorizontalScrollIntent(ar)}}).dispose,Ye&&(Kn=Lfe({container:et,term:Kt,onResize:(gr,si)=>{je.sendControl({type:"terminal_resize_request",sessionId:t,cols:gr,rows:si})},onRelayout:()=>{var gr;return(gr=E.current)==null?void 0:gr.relayout()},preserveRows:()=>D.current}).dispose)},onFramePending:()=>{z.current=!0,R.current&&!h.hasNewFramesWhileAwayRef.current&&h.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Ct;F.current=performance.now(),(Ct=P.current)==null||Ct.schedule()},onRawInput:Ct=>{Bt(),Pt("rawInput"),Mn(Ct,"rawInputEnter")},onError:Ct=>{const Kt=Ct instanceof Error?Ct.message:String(Ct);rt.error(`终端初始化失败:${Kt}`)},...d.transport});return x.current=_t,()=>{Kn==null||Kn(),An==null||An(),tn==null||tn(),Ai==null||Ai.dispose(),_me(),Lt==null||Lt(),Rn==null||Rn(),w.current=[],vme(),b.current=null,I(!1),ie({resultIndex:-1,resultCount:0}),_t.dispose(),v.current=null,E.current=null,x.current=null}},[t,se,te,s,o,l,d.transport,h.handleAtBottomChange,h.hasNewFramesWhileAwayRef,h.setHasNewFramesWhileAway,it,he,pn,_n,Le,y,fe,Pt,Mn,Bt,Ye]),_.useEffect(()=>{const we=v.current,Se=E.current;!we||!Se||mfe(we,de,Se.relayout)},[de]),_.useEffect(()=>{if(!i||!d.ready||ce)return;const we=requestAnimationFrame(()=>{var Se;return(Se=v.current)==null?void 0:Se.focus()});return()=>cancelAnimationFrame(we)},[i,d.ready,ce]);const Q=_.useCallback((we="viewExternal",Se)=>{var je;(je=E.current)==null||je.scrollToBottom(we,Se)},[]),V=_.useCallback(we=>{var Se;(Se=E.current)==null||Se.scrollToRatio(we)},[]),Z=_.useCallback(we=>{var Se;(Se=E.current)==null||Se.scrollToXRatio(we)},[]),ee=_.useCallback(we=>{var Rn;const Se=v.current,je=Se==null?void 0:Se.getSelectionPosition();if(!Se||!je)return;const et=je.start.y;if(et>=we&&et<we+Se.rows)return;const ft=Math.max(0,Se.buffer.active.length-Se.rows);if(ft===0)return;const Lt=Math.max(0,Math.min(ft,et-Math.floor(Se.rows/2)));(Rn=E.current)==null||Rn.scrollToRatio(Lt/ft)},[]),pe=_.useCallback((we,Se=!1)=>{const je=v.current,et=b.current;if(!je||!et||!we)return we||(et==null||et.clearDecorations(),je==null||je.clearSelection(),ie({resultIndex:-1,resultCount:0})),!1;const ft=je.buffer.active.viewportY,Lt=et.findNext(we,{...X2,incremental:Se});return Lt&&ee(ft),Lt},[ee]),ke=_.useCallback(we=>{const Se=v.current,je=b.current;if(!Se||!je||!we)return!1;const et=Se.buffer.active.viewportY,ft=je.findPrevious(we,X2);return ft&&ee(et),ft},[ee]),Be=_.useCallback(()=>{var we,Se;(we=b.current)==null||we.clearDecorations(),(Se=v.current)==null||Se.clearSelection(),ie({resultIndex:-1,resultCount:0})},[]),De=_.useCallback(we=>{var Se;it()&&(Ks(t,we),Pt("mobileControl",{force:!0}),Mn(we,"mobileControlEnter"),(Se=v.current)==null||Se.focus())},[it,Mn,Pt,t]),qe=_.useCallback(()=>{var Se,je,et;if(!it())return;const we=(je=(Se=navigator.clipboard)==null?void 0:Se.readText)==null?void 0:je.bind(navigator.clipboard);if(!window.isSecureContext||!we){rt.error("无法读取剪贴板"),(et=v.current)==null||et.focus();return}we().then(ft=>{if(!ft)return;const Lt=v.current;if(Lt){Lt.paste(ft);return}Ks(t,ft),Bt(),Pt("paste"),Mn(ft,"pasteEnter")}).catch(ft=>{const Lt=ft instanceof Error&&ft.message?ft.message:"无法读取剪贴板";rt.error(Lt)}).finally(()=>{var ft;return(ft=v.current)==null?void 0:ft.focus()})},[it,Mn,Bt,Pt,t]),at=fge({showMobilePtyControls:st,horizontalScrollable:K.horizontalScrollable,mobileControlsHeight:u});Y.current.containerPaddingBottom=at,_.useEffect(()=>{var je,et,ft;j.current?(je=E.current)==null||je.relayout():(et=P.current)==null||et.schedule();const we=$.current,Se=cge({controlsVisible:st,keyboardOpen:He,previous:we});$.current={keyboardOpen:He,controlsVisible:st},st&&(j.current?Mt():Se?((ft=E.current)==null||ft.scrollToBottom("keyboardOffset",{force:!0}),Mt()):He||Pt("keyboardOffset"))},[Ce,He,st,at,Mt,Pt]);const ut=_.useMemo(()=>({onFocusCapture:nt,onBlurCapture:Ze}),[nt,Ze]);return{scrollState:K,isAtBottom:h.isAtBottom,hasNewFramesWhileAway:h.hasNewFramesWhileAway,ptyInputFocused:yt,showMobilePtyControls:st,touchEditingSurface:mt,keyboardOffset:Ce,physicalKeyboardMode:Ve,softKeyboardEditingSurface:ce,mobileControlsBottomInset:tt,connectionReady:d.ready,connectionOverlay:d.overlay,containerPaddingBottom:at,traceEnabled:p,findReady:G,findResultIndex:ne.resultIndex,findResultCount:ne.resultCount,findNext:pe,findPrevious:ke,clearFind:Be,scrollToBottom:Q,scrollToRatio:V,scrollToXRatio:Z,clearNewFramesWhileAway:Mt,sendMobileInput:De,pasteMobileClipboard:qe,handleTerminalContainerMouseDown:ue,handlePasteCapture:ye,pointerHandlers:At.pointerHandlers,focusHandlers:ut,ptySelectionToolbar:At.ptySelectionToolbar,ptySelectionHandles:At.ptySelectionHandles,ptySelectionPathAction:At.ptySelectionPathAction,ptySelectionHandleMetrics:At.ptySelectionHandleMetrics,copyPtySelection:At.copyPtySelection,openPtySelectionPathAction:At.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:At.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:At.handlePtySelectionHandleTouchStart,isPtyDragOver:Ue,handlePtyDragOver:jt,handlePtyDragLeave:re,handlePtyDrop:oe}}function gge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,active:i=!0,findRequest:s}){const[o,l]=_.useState(null),[u,d]=_.useState(0),[h,p]=_.useState(!1),[y,v]=_.useState(""),b=_.useRef(null),w=_.useRef(null),x=mge({sessionId:e,sessionKind:t,ptyOwner:r,active:i,containerEl:o,spacerRef:b,xtermHostRef:w,mobileControlsHeight:u}),E=x.ptySelectionHandleMetrics,{clearFind:k,findNext:T,findPrevious:N,findReady:z,findResultCount:R,findResultIndex:F}=x,P=_.useCallback(()=>{N(y)},[N,y]),q=_.useCallback(()=>{T(y)},[T,y]),H=_.useCallback(()=>p(!0),[]),$=_.useCallback(()=>{p(!1),k()},[k]),D=k3({enabled:i,open:h,openRequest:s,onOpen:H,onClose:$,onPrevious:P,onNext:q});return _.useEffect(()=>{!h||!z||(y?T(y,!0):k())},[k,T,h,y,z]),g.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":x.connectionReady?"true":"false","aria-busy":!x.connectionReady,children:[h?g.jsx(Y0,{query:y,resultIndex:F,resultCount:R,focusRequest:D.focusRequest,loading:!!y&&!z,onQueryChange:v,onPrevious:P,onNext:q,onClose:D.closeFind}):null,g.jsx("div",{ref:l,className:"flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${x.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:x.handleTerminalContainerMouseDown,onPointerDownCapture:x.pointerHandlers.onPointerDownCapture,onPointerMoveCapture:x.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:x.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:x.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:x.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:x.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:x.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:x.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:x.pointerHandlers.onContextMenuCapture,onPasteCapture:x.handlePasteCapture,onDragOver:x.handlePtyDragOver,onDragLeave:x.handlePtyDragLeave,onDrop:x.handlePtyDrop,onFocusCapture:x.focusHandlers.onFocusCapture,onBlurCapture:x.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":x.isPtyDragOver?"true":void 0,children:g.jsx("div",{ref:b,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:g.jsx("div",{ref:w,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})})}),g.jsx(x3,{visible:!x.isAtBottom,hasNewMessages:x.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{x.scrollToBottom("backToBottomBtn",{force:!0}),x.clearNewFramesWhileAway()}}),x.showMobilePtyControls?g.jsx(Jae,{sessionKind:t,provider:n,bottomInset:x.mobileControlsBottomInset,onInput:x.sendMobileInput,onPaste:x.pasteMobileClipboard,onHeightChange:d}):null,x.ptySelectionHandles?g.jsxs(g.Fragment,{children:[g.jsx(Q2,{kind:"anchor",position:x.ptySelectionHandles.anchor,metrics:E,"aria-label":"调整选区起点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("anchor",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("anchor",M)}),g.jsx(Q2,{kind:"focus",position:x.ptySelectionHandles.focus,metrics:E,"aria-label":"调整选区终点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("focus",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("focus",M)})]}):null,x.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:x.ptySelectionToolbar.left,top:x.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:M=>M.preventDefault(),onClick:x.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),x.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:M=>M.preventDefault(),onClick:x.openPtySelectionPathAction,"aria-label":x.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:x.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,g.jsx(ale,{state:x.scrollState,onScrollRatio:x.scrollToRatio}),g.jsx(lle,{state:x.scrollState,onScrollRatio:x.scrollToXRatio}),g.jsx(Fae,{...x.connectionOverlay}),g.jsx(Hae,{ptyInputFocused:x.ptyInputFocused,touchEditingSurface:x.touchEditingSurface,softKeyboardEditingSurface:x.softKeyboardEditingSurface,physicalKeyboardMode:x.physicalKeyboardMode,keyboardOffset:x.keyboardOffset,showMobilePtyControls:x.showMobilePtyControls,mobileControlsBottomInset:x.mobileControlsBottomInset}),x.traceEnabled?g.jsx(vge,{}):null]})}function Q2({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,b=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,...b},"data-slot":"pty-selection-handle-dot"})]})}function vge(){const[e,t]=_.useState(!1);async function n(){const r=Bae();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 yge=3,_ge=1024,bge=720,Jm=.5,S4=_.createContext(null);function wge({children:e}){const[t,n]=_.useState([]),[r,i]=_.useState(null),[s,o]=_.useState(null),l=Ie(k=>k.selectedProxyId),u=qt(k=>k.sessions),d=qt(k=>k.sessionListLoaded),h=_.useRef(l),p=_.useRef(null),y=_.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
|
|
636
636
|
`),[u]),v=_.useCallback(k=>{p.current=k.sessionId,i(k),n(T=>uoe(T,k.sessionId,{capacity:yge,now:Date.now(),activeSessionId:k.sessionId}).map(z=>z.sessionId===k.sessionId?{...z,sessionKind:k.sessionKind,provider:k.provider,ptyOwner:k.ptyOwner}:z))},[]),b=_.useCallback(k=>{p.current===k&&(p.current=null),i(T=>(T==null?void 0:T.sessionId)===k?null:T),o(T=>p.current===null?null:T)},[]),w=_.useCallback((k,T)=>{p.current===k&&o(N=>!T||N&&Ege(N,T)?N:T)},[]),x=_.useCallback((k,T)=>{T!==void 0&&n(N=>N.map(z=>z.sessionId===k?{...z,findRequest:T}:z))},[]);_.useEffect(()=>{if(!d)return;const k=new Set(y?y.split(`
|
|
637
|
-
`):[]);n(T=>T.filter(N=>k.has(N.sessionId))),i(T=>T&&k.has(T.sessionId)?T:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),_.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const E=_.useMemo(()=>({activate:v,deactivate:b,updateFindRequest:x,updateViewportRect:w}),[v,b,x,w]);return g.jsxs(S4.Provider,{value:E,children:[e,g.jsx(xge,{entries:t,activeView:r,viewportRect:s})]})}function Sge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,findRequest:i}){const s=_.useContext(S4),o=_.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateViewportRect:h}=s;return _.useLayoutEffect(()=>(l({sessionId:e,sessionKind:t,provider:n,ptyOwner:r}),()=>u(e)),[l,u,e,t,n,r]),_.useLayoutEffect(()=>{d(e,i)},[i,e,d]),_.useLayoutEffect(()=>{const p=o.current;if(!p)return;const y=()=>{const b=p.getBoundingClientRect();h(e,{top:b.top,left:b.left,width:b.width,height:b.height})};y();const v=new ResizeObserver(y);return v.observe(p),window.addEventListener("resize",y),()=>{v.disconnect(),window.removeEventListener("resize",y)}},[e,h]),g.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function xge({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)??_ge,height:(n==null?void 0:n.height)??bge};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(S3,{sessionId:r.sessionId,children:g.jsx(gge,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,ptyOwner:r.ptyOwner,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function Ege(e,t){return Math.abs(e.top-t.top)<=Jm&&Math.abs(e.left-t.left)<=Jm&&Math.abs(e.width-t.width)<=Jm&&Math.abs(e.height-t.height)<=Jm}function gE({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 vE="dev-anywhere:last-chat-route",x4="dev-anywhere:route-restored",YS="dev-anywhere:restored-target";function Cge(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function kge(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(vE))??null}catch{return null}}function Tge(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(vE,e)}catch{}}function E4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(vE)}catch{}}function Rge(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(x4))==="1"}catch{return!1}}function Age(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(x4,"1")}catch{}}function Nge(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(YS,e)}catch{}}function Mge(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(YS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(YS)),n}catch{return null}}function Oge(e){const t=PL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Ng(){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 Dge(){return typeof navigator>"u"?{supported:!0}:Oge({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Ng()})}function Pge(){dme(),hme();const e=Bi(),t=Js(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=_.useState(!1),[o,l]=_.useState(()=>Ng()),u=Ie(P=>P.proxies.length),d=Ie(P=>P.proxyListLoaded),h=Ie(P=>P.relayClientAuthIssue),p=Ie(P=>!!P.selectedProxyId),y=Ie(P=>P.selectedProxyId),v=Ie(P=>P.selectedProxyName),b=qt(P=>P.sessions.length),w=Ie(P=>P.pendingToast),x=Ie(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=gE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:b,relayClientAuthIssue:h}),T=v??y,z=e.pathname==="/sessions"&&d&&u>0?g.jsxs(St,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":T?`切换开发机,当前 ${T}`:"切换开发机",onClick:()=>t("/"),children:[g.jsx(kP,{className:"size-4 text-primary","aria-hidden":"true"}),g.jsxs("span",{className:"min-w-0 truncate",children:[g.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?g.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;_.useEffect(()=>{if(!w)return;({error:rt.error,info:rt.info,success:rt.success})[w.kind](w.message),x(null)},[w,x]),_.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Ng());return}const P=window.matchMedia("(display-mode: standalone)"),q=window.matchMedia("(display-mode: fullscreen)"),H=()=>l(Ng());return H(),P.addEventListener("change",H),q.addEventListener("change",H),()=>{P.removeEventListener("change",H),q.removeEventListener("change",H)}},[]);const R=_.useRef(!1);_.useEffect(()=>{if(R.current)return;R.current=!0;const P=Cge({pathname:e.pathname,alreadyRestored:Rge(),lastRoute:kge()});Age(),P&&(Nge(P),t(P,{replace:!0}))},[]);const F=_.useRef(!1);return _.useEffect(()=>{n?(F.current=!0,Tge(`${e.pathname}${e.search}`)):F.current&&(F.current=!1,E4())},[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(St,{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(AP,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx(fse,{subtitle:k,action:z}),g.jsx(coe,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(use,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(wge,{children:g.jsx("div",{className:We("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(OU,{})},r?"top-level":e.pathname)})})]}),g.jsx(W0,{open:i,onOpenChange:s}),g.jsx(Fse,{}),g.jsx(Sse,{}),g.jsx($X,{})]})}function C4({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($B,{texts:HB,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 Lge(){const e=Ie(o=>o.proxies),t=Ie(o=>!!o.selectedProxyId),n=Ie(o=>o.relayClientAuthIssue),r=qt(o=>o.sessions.length),i=gE({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(CB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(nc,{variant:s}):g.jsx(C4,{subtitle:i})})]})}function Ige(){const e=Ie(o=>o.proxies),t=Ie(o=>!!o.selectedProxyId),n=Ie(o=>o.relayClientAuthIssue),r=qt(o=>o.sessions.length),i=ki("local",ln.proxyId)!==null;if(!t&&!i)return g.jsx(MU,{to:"/",replace:!0});const s=gE({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(PB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(C4,{subtitle:s})})]})}function k4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function zge(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function T4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return zge(e,typeof((t=k4())==null?void 0:t.request)=="function")}function Bge(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function jge(){const e=k4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(Bge(T4()));return e.request("screen")}function Fge(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class $ge{constructor(t={}){gt(this,"activeScopes",new Set);gt(this,"pendingScopes",new Set);gt(this,"listeners",new Map);gt(this,"sentinel",null);gt(this,"requestInFlight",null);gt(this,"requestWakeLock");gt(this,"documentRef");gt(this,"windowRef");gt(this,"unavailableReason");gt(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(()=>{})});gt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??jge,this.unavailableReason=typeof t.request=="function"?null:T4(),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(Fge(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const Xa=new $ge;function R4(e){const[t,n]=_.useState(()=>Xa.getSnapshot(e));_.useEffect(()=>Xa.subscribe(e,n),[e]),_.useEffect(()=>()=>{Xa.disable(e).catch(()=>{})},[e]);const r=_.useCallback(()=>Xa.enable(e),[e]),i=_.useCallback(()=>Xa.disable(e),[e]),s=_.useCallback(()=>Xa.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function Hge(){return new AudioContext}class Uge{constructor(t=Hge){gt(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 Mg=new Uge,J2=400,Ou=[];let A4=1;function Wge(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Vh(e){const t={sequence:A4++,timestamp:new Date().toISOString(),monotonicMs:Wge(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Ou.push(t),Ou.length>J2&&Ou.splice(0,Ou.length-J2)}function qge(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Vge(){Ou.length=0,A4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:qge,clear:Vge});function N4(e){return`voice-pilot:${e}`}function Yge(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 Kge="modulepreload",Gge=function(e){return"/"+e},eO={},Xge=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=Gge(d),d in eO)return;eO[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":Kge,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((v,b)=>{y.addEventListener("load",v),y.addEventListener("error",()=>b(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)})},Zge="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Qge=20,Za=Zu*Qge/1e3,Bw=Za*Int16Array.BYTES_PER_ELEMENT;let tO=null;async function Jge(){return tO??(tO=Xge(async()=>{const{default:e}=await import("./fvad-DLcnOq36.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Zge:t}))),tO}class yE{constructor(t,n,r){gt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Jge(),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,Zu)!==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 yE(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,Za);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class eve{constructor(t={}){gt(this,"startSpeechFrames");gt(this,"endSilenceFrames");gt(this,"active",!1);gt(this,"speechFrames",0);gt(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 tve{constructor(){gt(this,"pending",new Float32Array(Za));gt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Za-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Za&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Za<=t.length;)n(t.slice(r,r+Za)),r+=Za;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const nve="/__dev_anywhere_debug/voice-fixture",rve=Zu*IB/1e3;function ive(){return yE.create(3)}const sve={createVad:ive,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function ove(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 ave(e){for(const t of e.getTracks())t.stop()}function M4(e){const t=e.createAudioContext({sampleRate:Zu});if(t.sampleRate!==Zu)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function lve(e){const t=M4(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:Zu}})}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(),ave(n),t.state!=="closed"&&await t.close()}}}async function cve(e,t){const n=M4(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 O4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:nve}:{kind:"microphone"}}async function uve(e,t=sve){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await cve(e.source.url,t):await lve(t)}catch(h){throw n.destroy(),h}const i=new eve,s=new tve,o=r.context.createScriptProcessor(rve,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Yge(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:ove(p)});const b=i.push(v);b==="speech-start"&&e.onSpeechStart(),b==="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 D4(e=Ev().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function dve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function hve({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=dve(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 fve(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 pve(){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(fve(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",eg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function mve({label:e}){return g.jsxs(mo,{className:"relative",children:[g.jsx(CP,{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 gve({sessionId:e,mode:t,onFind:n}){const r=D4(),i=Js(),s=qt(ge=>ge.sessions.find(he=>he.sessionId===e)),o=qt(ge=>ge.ptyTitles[e]),l=Ie(ge=>ge.ptyFontSize),u=Ie(ge=>ge.chatContentFontSize),d=Ie(ge=>ge.selectedProxyId),h=Ie(ge=>ge.adjustPtyFontSize),p=Ie(ge=>ge.adjustChatContentFontSize),y=Ie(ge=>ge.setChatContentFontSize),v=Ie(ge=>ge.resetPtyFontSize),b=Ie(ge=>ge.resetChatContentFontSize),w=Ie(ge=>ge.inputModePreference==="hardware"),x=qt(ge=>ge.renameSession),E=Lx(d,e),k=qt(ge=>E?!!ge.ptyAutoYesBySessionKey[E]:!1),T=qt(ge=>ge.setPtyAutoYes),z=hl("(pointer: coarse), (hover: none)")&&!w,R=t==="pty"||(s==null?void 0:s.mode)==="pty",F=(s==null?void 0:s.kind)==="terminal",P=R4(e),q=on(ge=>ge.bySessionId[e]??sy),H=on(ge=>ge.enable),$=on(ge=>ge.disable),D=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Yx(s),j=D&&(s==null?void 0:s.name)||M||R&&o||(s==null?void 0:s.name)||e.slice(0,8),L=!!(R&&!F&&o&&!D),O=R?l:Dx(u,z),Y=!R&&z?XP:KP,K=R?v:b,[U,A]=_.useState(!1),[W,G]=_.useState(!1),I=q.enabled,ne=P.active||I,ie=P.pending||!P.supported||I;function se(ge){if(R){h(ge);return}if(z){y(O+ge);return}p(ge)}function te(){P.toggle().catch(ge=>{rt.error(ge instanceof Error?ge.message:String(ge))})}async function de(ge){var Ve;if(R||F){rt.info("Voice Pilot 目前适用于聊天会话。");return}if(ge!==!0){$(e);return}const he=Ot;if(!he){rt.error("请先连接开发机");return}try{if(!((Ve=(await he.requestVoiceConfig()).config)!=null&&Ve.configured)){rt.info("请先在设置里配置 Voice Pilot。");return}A(!0)}catch(ce){rt.error(ce instanceof Error?ce.message:String(ce))}}async function ve(){var ce;G(!0);let ge=null,he=!1;const Ve=N4(e);try{Vh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((ce=navigator.userActivation)==null?void 0:ce.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Ce=Xa.enable(Ve).then(()=>{Vh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},ht=>{throw Vh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:ht instanceof Error?ht.message:String(ht)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:ht})});ge=D1.acquire("capture");const He=Mg.prepare(),it=O4().kind==="microphone"?pve():Promise.resolve();await Promise.all([Ce,He,it]),H(e),he=!0,A(!1)}catch(Ce){Vh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Ce instanceof Error?Ce.message:String(Ce)}}),rt.error(Ce instanceof Error?Ce.message:String(Ce))}finally{ge==null||ge.release(),he||await Xa.disable(Ve).catch(()=>{}),G(!1)}}const xe=_.useRef(null),Re=_.useRef(null),[ze,Ye]=_.useState(!1);async function mt(ge){var Ce;const he=(Ce=ge.target.files)==null?void 0:Ce[0];if(ge.target.value="",!he)return;const Ve=Ot;if(!Ve){rt.error("请先连接开发机");return}const ce=await Ef({relay:Ve,sessionId:e,file:he});ce&&Ks(e,`@${ce} `)}async function zt(ge,he){const Ve=Ot;if(!Ve)throw new Error("请先连接开发机");const ce=await Ve.renameSession(ge,he);if(!ce.success)throw new Error(ce.error??"重命名失败");x(ge,ce.name??he),rt.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(St,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(vv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(hve,{title:j,isPtyTitle:L})}),g.jsxs(A1,{modal:!1,children:[g.jsx(N1,{asChild:!0,children:g.jsx(St,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(J9,{"aria-hidden":"true"})})}),g.jsxs(M1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(zm,{className:eg,children:"会话"}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(mo,{children:g.jsx(Pg,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>Ye(!0),children:[g.jsx(mo,{children:g.jsx(O8,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(Gb,{checked:ne,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ie,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:te,children:[g.jsx(mo,{children:g.jsx(f8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:P.supported?I?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":P.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),R&&!F&&g.jsxs(Gb,{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:ge=>{E&&T(E,ge===!0)},children:[g.jsx(mo,{children:g.jsx(ra,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!R&&!F&&g.jsxs(Gb,{checked:q.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:de,children:[g.jsx(mo,{children:g.jsx(_8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(Xb,{}),R&&!F?g.jsxs(g.Fragment,{children:[g.jsx(zm,{className:eg,children:"快捷键"}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ks(e,""),children:[g.jsx(mve,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(Xb,{}),g.jsx(zm,{className:eg,children:"文件"}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ge;return(ge=Re.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(yv,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ge;return(ge=xe.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(NP,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(Xb,{})]}):null,g.jsx(zm,{className:eg,children:"字号"}),g.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:g.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[g.jsx(mo,{children:g.jsx(r7,{"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(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:O<=Y,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ge=>{ge.stopPropagation(),se(-1)},children:g.jsx(w8,{"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:[O,"px"]}),g.jsx(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:O>=GP,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ge=>{ge.stopPropagation(),se(1)},children:g.jsx(L8,{"aria-hidden":"true"})})]})]})}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-font-reset",onClick:K,children:[g.jsx(mo,{children:g.jsx(B8,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(zh,{open:ze,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Ye,onRename:zt}),g.jsx(Sc,{open:U&&!q.enabled,onOpenChange:ge=>{W||A(ge)},children:g.jsxs(xc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(Ec,{children:[g.jsx(dl,{children:"开启 Voice Pilot?"}),g.jsx(dc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"outline",disabled:W,onClick:()=>A(!1),children:"取消"}),g.jsx(St,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:W,onClick:()=>{ve()},children:W?"正在开启...":"开启 Voice Pilot"})]})]})}),R?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Re,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ge=>{mt(ge)}}),g.jsx("input",{ref:xe,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ge=>{mt(ge)}})]}):null]})}function gu(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((b,w)=>r[w]!==b)))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 b=Math.round((Date.now()-h)*100)/100,w=Math.round((Date.now()-v)*100)/100,x=w/16,E=(k,T)=>{for(k=String(k);k.length<T;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(b,5)} ms`,`
|
|
637
|
+
`):[]);n(T=>T.filter(N=>k.has(N.sessionId))),i(T=>T&&k.has(T.sessionId)?T:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),_.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const E=_.useMemo(()=>({activate:v,deactivate:b,updateFindRequest:x,updateViewportRect:w}),[v,b,x,w]);return g.jsxs(S4.Provider,{value:E,children:[e,g.jsx(xge,{entries:t,activeView:r,viewportRect:s})]})}function Sge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,findRequest:i}){const s=_.useContext(S4),o=_.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateViewportRect:h}=s;return _.useLayoutEffect(()=>(l({sessionId:e,sessionKind:t,provider:n,ptyOwner:r}),()=>u(e)),[l,u,e,t,n,r]),_.useLayoutEffect(()=>{d(e,i)},[i,e,d]),_.useLayoutEffect(()=>{const p=o.current;if(!p)return;const y=()=>{const b=p.getBoundingClientRect();h(e,{top:b.top,left:b.left,width:b.width,height:b.height})};y();const v=new ResizeObserver(y);return v.observe(p),window.addEventListener("resize",y),()=>{v.disconnect(),window.removeEventListener("resize",y)}},[e,h]),g.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function xge({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)??_ge,height:(n==null?void 0:n.height)??bge};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(S3,{sessionId:r.sessionId,children:g.jsx(gge,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,ptyOwner:r.ptyOwner,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function Ege(e,t){return Math.abs(e.top-t.top)<=Jm&&Math.abs(e.left-t.left)<=Jm&&Math.abs(e.width-t.width)<=Jm&&Math.abs(e.height-t.height)<=Jm}function gE({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 vE="dev-anywhere:last-chat-route",x4="dev-anywhere:route-restored",YS="dev-anywhere:restored-target";function Cge(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function kge(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(vE))??null}catch{return null}}function Tge(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(vE,e)}catch{}}function E4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(vE)}catch{}}function Rge(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(x4))==="1"}catch{return!1}}function Age(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(x4,"1")}catch{}}function Nge(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(YS,e)}catch{}}function Mge(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(YS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(YS)),n}catch{return null}}function Oge(e){const t=PL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Ng(){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 Dge(){return typeof navigator>"u"?{supported:!0}:Oge({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Ng()})}function Pge(){dme(),hme();const e=Bi(),t=Js(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=_.useState(!1),[o,l]=_.useState(()=>Ng()),u=Ie(P=>P.proxies.length),d=Ie(P=>P.proxyListLoaded),h=Ie(P=>P.relayClientAuthIssue),p=Ie(P=>!!P.selectedProxyId),y=Ie(P=>P.selectedProxyId),v=Ie(P=>P.selectedProxyName),b=qt(P=>P.sessions.length),w=Ie(P=>P.pendingToast),x=Ie(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=gE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:b,relayClientAuthIssue:h}),T=v??y,z=e.pathname==="/sessions"&&d&&u>0?g.jsxs(St,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":T?`切换开发机,当前 ${T}`:"切换开发机",onClick:()=>t("/"),children:[g.jsx(kP,{className:"size-4 text-primary","aria-hidden":"true"}),g.jsxs("span",{className:"min-w-0 truncate",children:[g.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?g.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;_.useEffect(()=>{if(!w)return;({error:rt.error,info:rt.info,success:rt.success})[w.kind](w.message),x(null)},[w,x]),_.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Ng());return}const P=window.matchMedia("(display-mode: standalone)"),q=window.matchMedia("(display-mode: fullscreen)"),H=()=>l(Ng());return H(),P.addEventListener("change",H),q.addEventListener("change",H),()=>{P.removeEventListener("change",H),q.removeEventListener("change",H)}},[]);const R=_.useRef(!1);_.useEffect(()=>{if(R.current)return;R.current=!0;const P=Cge({pathname:e.pathname,alreadyRestored:Rge(),lastRoute:kge()});Age(),P&&(Nge(P),t(P,{replace:!0}))},[]);const F=_.useRef(!1);return _.useEffect(()=>{n?(F.current=!0,Tge(`${e.pathname}${e.search}`)):F.current&&(F.current=!1,E4())},[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(St,{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(AP,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx(fse,{subtitle:k,action:z}),g.jsx(coe,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(use,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(wge,{children:g.jsx("div",{className:We("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(OU,{})},r?"top-level":e.pathname)})})]}),g.jsx(W0,{open:i,onOpenChange:s}),g.jsx(Fse,{}),g.jsx(Sse,{}),g.jsx($X,{})]})}function C4({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($B,{texts:HB,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 Lge(){const e=Ie(o=>o.proxies),t=Ie(o=>!!o.selectedProxyId),n=Ie(o=>o.relayClientAuthIssue),r=qt(o=>o.sessions.length),i=gE({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(CB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(nc,{variant:s}):g.jsx(C4,{subtitle:i})})]})}function Ige(){const e=Ie(o=>o.proxies),t=Ie(o=>!!o.selectedProxyId),n=Ie(o=>o.relayClientAuthIssue),r=qt(o=>o.sessions.length),i=ki("local",ln.proxyId)!==null;if(!t&&!i)return g.jsx(MU,{to:"/",replace:!0});const s=gE({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(PB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(C4,{subtitle:s})})]})}function k4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function zge(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function T4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return zge(e,typeof((t=k4())==null?void 0:t.request)=="function")}function Bge(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function jge(){const e=k4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(Bge(T4()));return e.request("screen")}function Fge(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class $ge{constructor(t={}){gt(this,"activeScopes",new Set);gt(this,"pendingScopes",new Set);gt(this,"listeners",new Map);gt(this,"sentinel",null);gt(this,"requestInFlight",null);gt(this,"requestWakeLock");gt(this,"documentRef");gt(this,"windowRef");gt(this,"unavailableReason");gt(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(()=>{})});gt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??jge,this.unavailableReason=typeof t.request=="function"?null:T4(),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(Fge(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const Xa=new $ge;function R4(e){const[t,n]=_.useState(()=>Xa.getSnapshot(e));_.useEffect(()=>Xa.subscribe(e,n),[e]),_.useEffect(()=>()=>{Xa.disable(e).catch(()=>{})},[e]);const r=_.useCallback(()=>Xa.enable(e),[e]),i=_.useCallback(()=>Xa.disable(e),[e]),s=_.useCallback(()=>Xa.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function Hge(){return new AudioContext}class Uge{constructor(t=Hge){gt(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 Mg=new Uge,J2=400,Ou=[];let A4=1;function Wge(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Vh(e){const t={sequence:A4++,timestamp:new Date().toISOString(),monotonicMs:Wge(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Ou.push(t),Ou.length>J2&&Ou.splice(0,Ou.length-J2)}function qge(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Vge(){Ou.length=0,A4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:qge,clear:Vge});function N4(e){return`voice-pilot:${e}`}function Yge(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 Kge="modulepreload",Gge=function(e){return"/"+e},eO={},Xge=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=Gge(d),d in eO)return;eO[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":Kge,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((v,b)=>{y.addEventListener("load",v),y.addEventListener("error",()=>b(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)})},Zge="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Qge=20,Za=Zu*Qge/1e3,Bw=Za*Int16Array.BYTES_PER_ELEMENT;let tO=null;async function Jge(){return tO??(tO=Xge(async()=>{const{default:e}=await import("./fvad-CyIQRjst.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Zge:t}))),tO}class yE{constructor(t,n,r){gt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Jge(),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,Zu)!==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 yE(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,Za);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class eve{constructor(t={}){gt(this,"startSpeechFrames");gt(this,"endSilenceFrames");gt(this,"active",!1);gt(this,"speechFrames",0);gt(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 tve{constructor(){gt(this,"pending",new Float32Array(Za));gt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Za-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Za&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Za<=t.length;)n(t.slice(r,r+Za)),r+=Za;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const nve="/__dev_anywhere_debug/voice-fixture",rve=Zu*IB/1e3;function ive(){return yE.create(3)}const sve={createVad:ive,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function ove(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 ave(e){for(const t of e.getTracks())t.stop()}function M4(e){const t=e.createAudioContext({sampleRate:Zu});if(t.sampleRate!==Zu)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function lve(e){const t=M4(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:Zu}})}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(),ave(n),t.state!=="closed"&&await t.close()}}}async function cve(e,t){const n=M4(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 O4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:nve}:{kind:"microphone"}}async function uve(e,t=sve){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await cve(e.source.url,t):await lve(t)}catch(h){throw n.destroy(),h}const i=new eve,s=new tve,o=r.context.createScriptProcessor(rve,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Yge(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:ove(p)});const b=i.push(v);b==="speech-start"&&e.onSpeechStart(),b==="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 D4(e=Ev().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function dve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function hve({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=dve(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 fve(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 pve(){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(fve(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",eg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function mve({label:e}){return g.jsxs(mo,{className:"relative",children:[g.jsx(CP,{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 gve({sessionId:e,mode:t,onFind:n}){const r=D4(),i=Js(),s=qt(ge=>ge.sessions.find(he=>he.sessionId===e)),o=qt(ge=>ge.ptyTitles[e]),l=Ie(ge=>ge.ptyFontSize),u=Ie(ge=>ge.chatContentFontSize),d=Ie(ge=>ge.selectedProxyId),h=Ie(ge=>ge.adjustPtyFontSize),p=Ie(ge=>ge.adjustChatContentFontSize),y=Ie(ge=>ge.setChatContentFontSize),v=Ie(ge=>ge.resetPtyFontSize),b=Ie(ge=>ge.resetChatContentFontSize),w=Ie(ge=>ge.inputModePreference==="hardware"),x=qt(ge=>ge.renameSession),E=Lx(d,e),k=qt(ge=>E?!!ge.ptyAutoYesBySessionKey[E]:!1),T=qt(ge=>ge.setPtyAutoYes),z=hl("(pointer: coarse), (hover: none)")&&!w,R=t==="pty"||(s==null?void 0:s.mode)==="pty",F=(s==null?void 0:s.kind)==="terminal",P=R4(e),q=on(ge=>ge.bySessionId[e]??sy),H=on(ge=>ge.enable),$=on(ge=>ge.disable),D=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Yx(s),j=D&&(s==null?void 0:s.name)||M||R&&o||(s==null?void 0:s.name)||e.slice(0,8),L=!!(R&&!F&&o&&!D),O=R?l:Dx(u,z),Y=!R&&z?XP:KP,K=R?v:b,[U,A]=_.useState(!1),[W,G]=_.useState(!1),I=q.enabled,ne=P.active||I,ie=P.pending||!P.supported||I;function se(ge){if(R){h(ge);return}if(z){y(O+ge);return}p(ge)}function te(){P.toggle().catch(ge=>{rt.error(ge instanceof Error?ge.message:String(ge))})}async function de(ge){var Ve;if(R||F){rt.info("Voice Pilot 目前适用于聊天会话。");return}if(ge!==!0){$(e);return}const he=Ot;if(!he){rt.error("请先连接开发机");return}try{if(!((Ve=(await he.requestVoiceConfig()).config)!=null&&Ve.configured)){rt.info("请先在设置里配置 Voice Pilot。");return}A(!0)}catch(ce){rt.error(ce instanceof Error?ce.message:String(ce))}}async function ve(){var ce;G(!0);let ge=null,he=!1;const Ve=N4(e);try{Vh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((ce=navigator.userActivation)==null?void 0:ce.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Ce=Xa.enable(Ve).then(()=>{Vh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},ht=>{throw Vh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:ht instanceof Error?ht.message:String(ht)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:ht})});ge=D1.acquire("capture");const He=Mg.prepare(),it=O4().kind==="microphone"?pve():Promise.resolve();await Promise.all([Ce,He,it]),H(e),he=!0,A(!1)}catch(Ce){Vh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Ce instanceof Error?Ce.message:String(Ce)}}),rt.error(Ce instanceof Error?Ce.message:String(Ce))}finally{ge==null||ge.release(),he||await Xa.disable(Ve).catch(()=>{}),G(!1)}}const xe=_.useRef(null),Re=_.useRef(null),[ze,Ye]=_.useState(!1);async function mt(ge){var Ce;const he=(Ce=ge.target.files)==null?void 0:Ce[0];if(ge.target.value="",!he)return;const Ve=Ot;if(!Ve){rt.error("请先连接开发机");return}const ce=await Ef({relay:Ve,sessionId:e,file:he});ce&&Ks(e,`@${ce} `)}async function zt(ge,he){const Ve=Ot;if(!Ve)throw new Error("请先连接开发机");const ce=await Ve.renameSession(ge,he);if(!ce.success)throw new Error(ce.error??"重命名失败");x(ge,ce.name??he),rt.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(St,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(vv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(hve,{title:j,isPtyTitle:L})}),g.jsxs(A1,{modal:!1,children:[g.jsx(N1,{asChild:!0,children:g.jsx(St,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(J9,{"aria-hidden":"true"})})}),g.jsxs(M1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(zm,{className:eg,children:"会话"}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(mo,{children:g.jsx(Pg,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>Ye(!0),children:[g.jsx(mo,{children:g.jsx(O8,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(Gb,{checked:ne,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ie,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:te,children:[g.jsx(mo,{children:g.jsx(f8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:P.supported?I?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":P.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),R&&!F&&g.jsxs(Gb,{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:ge=>{E&&T(E,ge===!0)},children:[g.jsx(mo,{children:g.jsx(ra,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!R&&!F&&g.jsxs(Gb,{checked:q.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:de,children:[g.jsx(mo,{children:g.jsx(_8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(Xb,{}),R&&!F?g.jsxs(g.Fragment,{children:[g.jsx(zm,{className:eg,children:"快捷键"}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ks(e,""),children:[g.jsx(mve,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(Xb,{}),g.jsx(zm,{className:eg,children:"文件"}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ge;return(ge=Re.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(yv,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ge;return(ge=xe.current)==null?void 0:ge.click()},children:[g.jsx(mo,{children:g.jsx(NP,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(Xb,{})]}):null,g.jsx(zm,{className:eg,children:"字号"}),g.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:g.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[g.jsx(mo,{children:g.jsx(r7,{"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(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:O<=Y,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ge=>{ge.stopPropagation(),se(-1)},children:g.jsx(w8,{"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:[O,"px"]}),g.jsx(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:O>=GP,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ge=>{ge.stopPropagation(),se(1)},children:g.jsx(L8,{"aria-hidden":"true"})})]})]})}),g.jsxs(bo,{className:mu,"data-slot":"chat-menu-font-reset",onClick:K,children:[g.jsx(mo,{children:g.jsx(B8,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(zh,{open:ze,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:Ye,onRename:zt}),g.jsx(Sc,{open:U&&!q.enabled,onOpenChange:ge=>{W||A(ge)},children:g.jsxs(xc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(Ec,{children:[g.jsx(dl,{children:"开启 Voice Pilot?"}),g.jsx(dc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Yu,{children:[g.jsx(St,{type:"button",variant:"outline",disabled:W,onClick:()=>A(!1),children:"取消"}),g.jsx(St,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:W,onClick:()=>{ve()},children:W?"正在开启...":"开启 Voice Pilot"})]})]})}),R?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Re,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ge=>{mt(ge)}}),g.jsx("input",{ref:xe,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ge=>{mt(ge)}})]}):null]})}function gu(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((b,w)=>r[w]!==b)))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 b=Math.round((Date.now()-h)*100)/100,w=Math.round((Date.now()-v)*100)/100,x=w/16,E=(k,T)=>{for(k=String(k);k.length<T;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(b,5)} ms`,`
|
|
638
638
|
font-size: .6rem;
|
|
639
639
|
font-weight: bold;
|
|
640
640
|
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 nO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const vve=(e,t)=>Math.abs(e-t)<1.01,yve=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},rO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},_ve=e=>e,bve=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},wve=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const i=o=>{const{width:l,height:u}=o;t({width:Math.round(l),height:Math.round(u)})};if(i(rO(n)),!r.ResizeObserver)return()=>{};const s=new r.ResizeObserver(o=>{const l=()=>{const u=o[0];if(u!=null&&u.borderBoxSize){const d=u.borderBoxSize[0];if(d){i({width:d.inlineSize,height:d.blockSize});return}}i(rO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},iO={passive:!0},sO=typeof window>"u"?!0:"onscrollend"in window,Sve=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&sO?()=>{}:yve(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,iO);const d=e.options.useScrollendEvent&&sO;return d&&n.addEventListener("scrollend",u,iO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},xve=(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"]},Eve=(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 Cve{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:_ve,rangeExtractor:bve,onChange:()=>{},measureElement:xve,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=gu(()=>(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=gu(()=>[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=gu(()=>[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 b=p[v];b&&(y[b.lane]=v)}for(let v=h;v<n;v++){const b=s(v),w=this.laneAssignments.get(v);let x,E;const k=u==="estimate"||d.has(b);if(w!==void 0&&this.options.lanes>1){x=w;const R=y[x],F=R!==void 0?p[R]:void 0;E=F?F.end+this.options.gap:r+i}else{const R=this.options.lanes===1?p[v-1]:this.getFurthestMeasurement(p,v);E=R?R.end+this.options.gap:r+i,x=R?R.lane:v%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(v,x)}const T=d.get(b),N=typeof T=="number"?T:this.options.estimateSize(v),z=E+N;p[v]={index:v,start:E,size:N,end:z,key:b,lane:x},y[x]=v}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=gu(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?kve({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=gu(()=>{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=gu(()=>[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 nO(r[P4(0,r.length-1,i=>nO(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&&vve(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 P4=(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 kve({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=P4(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 oO=typeof document<"u"?_.useLayoutEffect:_.useEffect;function Tve({useFlushSync:e=!0,...t}){const n=_.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?nd.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=_.useState(()=>new Cve(r));return i.setOptions(r),oO(()=>i._didMount(),[]),oO(()=>i._willUpdate()),i}function Rve(e){return Tve({observeElementRect:wve,observeElementOffset:Sve,scrollToFn:Eve,...e})}function Ave(e){return e.kind==="diff"}const Nve=12e4;function aO(e){return e?e.replace(/\r\n?/gu,`
|