@dev-anywhere/relay 0.5.3 → 0.5.4
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 Ib(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},wJ="DialogDescriptionWarning",SJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${wI(wJ).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},e1=aI,xJ=cI,t1=dI,n1=hI,r1=fI,SI=mI,xI=vI,i1=_I;function EJ(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 CJ(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 kJ=["top","right","bottom","left"],cl=Math.min,hs=Math.max,$g=Math.round,Lm=Math.floor,Eo=e=>({x:e,y:e}),TJ={left:"right",right:"left",bottom:"top",top:"bottom"};function C0(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 s1(e){return e==="x"?"y":"x"}function o1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function a1(e){return s1(So(e))}function RJ(e,t,n){n===void 0&&(n=!1);const r=sd(e),i=a1(e),s=o1(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 AJ(e){const t=Hg(e);return[k0(e),t,k0(t)]}function k0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gN=["left","right"],vN=["right","left"],NJ=["top","bottom"],MJ=["bottom","top"];function OJ(e,t,n){switch(e){case"top":case"bottom":return n?t?vN:gN:t?gN:vN;case"left":case"right":return t?NJ:MJ;default:return[]}}function DJ(e,t,n,r){const i=sd(e);let s=OJ(oa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(k0)))),s}function Hg(e){const t=oa(e);return TJ[t]+e.slice(t.length)}function PJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function EI(e){return typeof e!="number"?PJ(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 yN(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=a1(t),l=o1(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 g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:p};break;case"left":g={x:r.x-i.width,y:p};break;default:g={x:r.x,y:r.y}}switch(sd(t)){case"start":g[o]-=y*(n&&d?-1:1);break;case"end":g[o]+=y*(n&&d?-1:1);break}return g}async function LJ(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:g=0}=sa(t,e),b=EI(g),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)),A=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)/A.y,bottom:(z.bottom-E.bottom+b.bottom)/A.y,left:(E.left-z.left+b.left)/A.x,right:(z.right-E.right+b.right)/A.x}}const IJ=50,zJ=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:LJ},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}=yN(d,r,u),y=r,g=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:A,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=A??p,b[E]={...b[E],...z},R&&g<IJ&&(g++,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}=yN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:b}},BJ=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=EI(h),y={x:n,y:r},g=a1(i),b=o1(g),w=await o.getDimensions(d),x=g==="y",E=x?"top":"left",k=x?"bottom":"right",T=x?"clientHeight":"clientWidth",A=s.reference[b]+s.reference[g]-y[g]-s.floating[b],z=y[g]-s.reference[g],R=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let H=R?R[T]:0;(!H||!await(o.isElement==null?void 0:o.isElement(R)))&&(H=l.floating[T]||s.floating[b]);const P=A/2-z/2,q=H/2-w[b]/2-1,U=cl(p[E],q),$=cl(p[k],q),D=U,M=H-w[b]-$,j=H/2-w[b]/2+P,L=C0(D,j,M),O=!u.arrow&&sd(i)!=null&&j!==L&&s.reference[b]/2-(j<D?U:$)-w[b]/2<0,Y=O?j<D?j-D:j-M:0;return{[g]:y[g]+Y,data:{[g]:L,centerOffset:j-L-Y,...O&&{alignmentOffset:Y}},reset:O}}}),jJ=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:g="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,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),z=y||(T||!w?[Hg(l)]:AJ(l)),R=b!=="none";!y&&R&&z.push(...DJ(l,w,b,A));const H=[l,...z],P=await u.detectOverflow(t,x),q=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&q.push(P[E]),p){const j=RJ(i,o,A);q.push(P[j[0]],P[j[1]])}if(U=[...U,{placement:i,overflows:q}],!q.every(j=>j<=0)){var $,D;const j=((($=s.flip)==null?void 0:$.index)||0)+1,L=H[j];if(L&&(!(p==="alignment"?k!==So(L):!1)||U.every(K=>So(K.placement)===k?K.overflows[0]>0:!0)))return{data:{index:j,overflows:U},reset:{placement:L}};let O=(D=U.filter(Y=>Y.overflows[0]<=0).sort((Y,K)=>Y.overflows[1]-K.overflows[1])[0])==null?void 0:D.placement;if(!O)switch(g){case"bestFit":{var M;const Y=(M=U.filter(K=>{if(R){const F=So(K.placement);return F===k||F==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(F=>F>0).reduce((F,N)=>F+N,0)]).sort((K,F)=>K[1]-F[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 _N(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function bN(e){return kJ.some(t=>e[t]>=0)}const FJ=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=_N(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:bN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=_N(o,n.floating);return{data:{escapedOffsets:l,escaped:bN(l)}}}default:return{}}}}},CI=new Set(["left","top"]);async function $J(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=CI.has(o)?-1:1,h=s&&u?-1:1,p=sa(t,e);let{mainAxis:y,crossAxis:g,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"&&(g=l==="end"?b*-1:b),u?{x:g*h,y:y*d}:{x:y*d,y:g*h}}const HJ=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 $J(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}}}}},UJ=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)),g=s1(y);let b=h[g],w=h[y];if(o){const E=g==="y"?"top":"left",k=g==="y"?"bottom":"right",T=b+p[E],A=b-p[k];b=C0(T,b,A)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[E],A=w-p[k];w=C0(T,w,A)}const x=u.fn({...t,[g]:b,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[g]:o,[y]:l}}}}}},WJ=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=s1(p);let g=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",A=s.reference[y]-s.floating[T]+x.mainAxis,z=s.reference[y]+s.reference[T]-x.mainAxis;g<A?g=A:g>z&&(g=z)}if(d){var E,k;const T=y==="y"?"width":"height",A=CI.has(oa(i)),z=s.reference[p]-s.floating[T]+(A&&((E=o.offset)==null?void 0:E[p])||0)+(A?0:x.crossAxis),R=s.reference[p]+s.reference[T]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?x.crossAxis:0);b<z?b=z:b>R&&(b=R)}return{[y]:g,[p]:b}}}},qJ=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),g=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,A=cl(w-h[x],k),z=cl(b-h[E],T),R=!t.middlewareData.shift;let H=A,P=z;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(H=k),R&&!y){const U=hs(h.left,0),$=hs(h.right,0),D=hs(h.top,0),M=hs(h.bottom,0);g?P=b-2*(U!==0||$!==0?U+$:hs(h.left,h.right)):H=w-2*(D!==0||M!==0?D+M:hs(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:H});const q=await o.getDimensions(l.floating);return b!==q.width||w!==q.height?{reset:{rects:!0}}:{}}}};function Nv(){return typeof window<"u"}function od(e){return kI(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=(kI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function kI(e){return Nv()?e instanceof Node||e instanceof fs(e).Node:!1}function Xs(e){return Nv()?e instanceof Element||e instanceof fs(e).Element:!1}function la(e){return Nv()?e instanceof HTMLElement||e instanceof fs(e).HTMLElement:!1}function wN(e){return!Nv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof fs(e).ShadowRoot}function Lf(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 VJ(e){return/^(table|td|th)$/.test(od(e))}function Mv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const YJ=/transform|translate|scale|rotate|perspective|filter/,KJ=/paint|layout|strict|content/,Wl=e=>!!e&&e!=="none";let Wb;function l1(e){const t=Xs(e)?Zs(e):e;return Wl(t.transform)||Wl(t.translate)||Wl(t.scale)||Wl(t.rotate)||Wl(t.perspective)||!c1()&&(Wl(t.backdropFilter)||Wl(t.filter))||YJ.test(t.willChange||"")||KJ.test(t.contain||"")}function GJ(e){let t=ul(e);for(;la(t)&&!Wu(t);){if(l1(t))return t;if(Mv(t))return null;t=ul(t)}return null}function c1(){return Wb==null&&(Wb=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Wb}function Wu(e){return/^(html|body|#document)$/.test(od(e))}function Zs(e){return fs(e).getComputedStyle(e)}function Ov(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||wN(e)&&e.host||No(e);return wN(t)?t.host:t}function TI(e){const t=ul(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:la(t)&&Lf(t)?t:TI(t)}function hf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=TI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=fs(i);if(s){const l=T0(o);return t.concat(o,o.visualViewport||[],Lf(i)?i:[],l&&n?hf(l):[])}else return t.concat(i,hf(i,[],n))}function T0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function RI(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 u1(e){return Xs(e)?e:e.contextElement}function Bu(e){const t=u1(e);if(!la(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=RI(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 XJ=Eo(0);function AI(e){const t=fs(e);return!c1()||!t.visualViewport?XJ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ZJ(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=u1(e);let o=Eo(1);t&&(r?Xs(r)&&(o=Bu(r)):o=Bu(e));const l=ZJ(s,n,r)?AI(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),g=r&&Xs(r)?fs(r):r;let b=y,w=T0(b);for(;w&&r&&g!==b;){const x=Bu(w),E=w.getBoundingClientRect(),k=Zs(w),T=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,A=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=T,d+=A,b=fs(w),w=T0(b)}}return Ug({width:h,height:p,x:u,y:d})}function Dv(e,t){const n=Ov(e).scrollLeft;return t?t.left+n:lc(No(e)).left+n}function NI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Dv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function QJ(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Mv(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"||Lf(o))&&(u=Ov(r)),p)){const g=lc(r);d=Bu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const y=o&&!p&&!s?NI(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 JJ(e){return Array.from(e.getClientRects())}function eee(e){const t=No(e),n=Ov(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+Dv(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 SN=25;function tee(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=c1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Dv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),g=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,b=Math.abs(r.clientWidth-p.clientWidth-g);b<=SN&&(s-=b)}else d<=SN&&(s+=d);return{width:s,height:o,x:l,y:u}}function nee(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 xN(e,t,n){let r;if(t==="viewport")r=tee(e,n);else if(t==="document")r=eee(No(e));else if(Xs(t))r=nee(t,n);else{const i=AI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ug(r)}function MI(e,t){const n=ul(e);return n===t||!Xs(n)||Wu(n)?!1:Zs(n).position==="fixed"||MI(n,t)}function ree(e,t){const n=t.get(e);if(n)return n;let r=hf(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=l1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Lf(o)&&!u&&MI(e,o))?r=r.filter(h=>h!==o):i=l,o=ul(o)}return t.set(e,r),r}function iee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Mv(t)?[]:ree(t,this._c):[].concat(n),r],l=xN(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 g=xN(t,o[y],i);u=hs(g.top,u),d=cl(g.right,d),h=cl(g.bottom,h),p=hs(g.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function see(e){const{width:t,height:n}=RI(e);return{width:t,height:n}}function oee(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=Dv(i)}if(r||!r&&!s)if((od(t)!=="body"||Lf(i))&&(l=Ov(t)),r){const g=lc(t,!0,s,t);u.x=g.x+t.clientLeft,u.y=g.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?NI(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 qb(e){return Zs(e).position==="static"}function EN(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 OI(e,t){const n=fs(e);if(Mv(e))return n;if(!la(e)){let i=ul(e);for(;i&&!Wu(i);){if(Xs(i)&&!qb(i))return i;i=ul(i)}return n}let r=EN(e,t);for(;r&&VJ(r)&&qb(r);)r=EN(r,t);return r&&Wu(r)&&qb(r)&&!l1(r)?n:r||GJ(e)||n}const aee=async function(e){const t=this.getOffsetParent||OI,n=this.getDimensions,r=await n(e.floating);return{reference:oee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function lee(e){return Zs(e).direction==="rtl"}const cee={convertOffsetParentRelativeRectToViewportRelativeRect:QJ,getDocumentElement:No,getClippingRect:iee,getOffsetParent:OI,getElementRects:aee,getClientRects:JJ,getDimensions:see,getScale:Bu,isElement:Xs,isRTL:lee};function DI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function uee(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:g}=d;if(l||t(),!y||!g)return;const b=Lm(p),w=Lm(i.clientWidth-(h+y)),x=Lm(i.clientHeight-(p+g)),E=Lm(h),T={rootMargin:-b+"px "+-w+"px "+-x+"px "+-E+"px",threshold:hs(0,cl(1,u))||1};let A=!0;function z(R){const H=R[0].intersectionRatio;if(H!==u){if(!A)return o();H?o(!1,H):r=setTimeout(()=>{o(!1,1e-7)},1e3)}H===1&&!DI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(z,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(z,T)}n.observe(e)}return o(!0),s}function dee(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=u1(e),h=i||s?[...d?hf(d):[],...t?hf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?uee(d,n):null;let y=-1,g=null;o&&(g=new ResizeObserver(E=>{let[k]=E;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var T;(T=g)==null||T.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let b,w=u?lc(e):null;u&&x();function x(){const E=lc(e);w&&!DI(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=g)==null||E.disconnect(),g=null,u&&cancelAnimationFrame(b)}}const hee=HJ,fee=UJ,pee=jJ,mee=qJ,gee=FJ,CN=BJ,vee=WJ,yee=(e,t,n)=>{const r=new Map,i={platform:cee,...n},s={...i.platform,_c:r};return zJ(e,t,{...i,platform:s})};var _ee=typeof document<"u",bee=function(){},mg=_ee?_.useLayoutEffect:bee;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 PI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kN(e,t){const n=PI(e);return Math.round(t*n)/n}function Vb(e){const t=_.useRef(e);return mg(()=>{t.current=e}),t}function wee(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,g]=_.useState(r);Wg(y,r)||g(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!==H.current&&(H.current=K,E(K))},[]),A=s||b,z=o||x,R=_.useRef(null),H=_.useRef(null),P=_.useRef(h),q=u!=null,U=Vb(u),$=Vb(i),D=Vb(d),M=_.useCallback(()=>{if(!R.current||!H.current)return;const K={placement:t,strategy:n,middleware:y};$.current&&(K.platform=$.current),yee(R.current,H.current,K).then(F=>{const N={...F,isPositioned:D.current!==!1};j.current&&!Wg(P.current,N)&&(P.current=N,nd.flushSync(()=>{p(N)}))})},[y,t,n,$,D]);mg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[d]);const j=_.useRef(!1);mg(()=>(j.current=!0,()=>{j.current=!1}),[]),mg(()=>{if(A&&(R.current=A),z&&(H.current=z),A&&z){if(U.current)return U.current(A,z,M);M()}},[A,z,M,U,q]);const L=_.useMemo(()=>({reference:R,floating:H,setReference:k,setFloating:T}),[k,T]),O=_.useMemo(()=>({reference:A,floating:z}),[A,z]),Y=_.useMemo(()=>{const K={position:n,left:0,top:0};if(!O.floating)return K;const F=kN(O.floating,h.x),N=kN(O.floating,h.y);return l?{...K,transform:"translate("+F+"px, "+N+"px)",...PI(O.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:N}},[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 See=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?CN({element:r.current,padding:i}).fn(n):{}:r?CN({element:r,padding:i}).fn(n):{}}}},xee=(e,t)=>{const n=hee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eee=(e,t)=>{const n=fee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cee=(e,t)=>({fn:vee(e).fn,options:[e,t]}),kee=(e,t)=>{const n=pee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Tee=(e,t)=>{const n=mee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ree=(e,t)=>{const n=gee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aee=(e,t)=>{const n=See(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Nee="Arrow",LI=_.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return v.jsx(Qt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:v.jsx("polygon",{points:"0,0 30,0 15,10"})})});LI.displayName=Nee;var Mee=LI,d1="Popper",[II,bl]=aa(d1),[Oee,zI]=II(d1),BI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return v.jsx(Oee,{scope:t,anchor:r,onAnchorChange:i,children:n})};BI.displayName=d1;var jI="PopperAnchor",FI=_.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=zI(jI,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:v.jsx(Qt.div,{...i,ref:l})});FI.displayName=jI;var h1="PopperContent",[Dee,Pee]=II(h1),$I=_.forwardRef((e,t)=>{var te,ue,ge,Se,Te,Ie;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:g="optimized",onPlaced:b,...w}=e,x=zI(h1,n),[E,k]=_.useState(null),T=Bn(t,Ke=>k(Ke)),[A,z]=_.useState(null),R=CJ(A),H=(R==null?void 0:R.width)??0,P=(R==null?void 0:R.height)??0,q=r+(s!=="center"?"-"+s:""),U=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},$=Array.isArray(d)?d:[d],D=$.length>0,M={padding:U,boundary:$.filter(Iee),altBoundary:D},{refs:j,floatingStyles:L,placement:O,isPositioned:Y,middlewareData:K}=wee({strategy:"fixed",placement:q,whileElementsMounted:(...Ke)=>dee(...Ke,{animationFrame:g==="always"}),elements:{reference:x.anchor},middleware:[xee({mainAxis:i+P,alignmentAxis:o}),u&&Eee({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Cee():void 0,...M}),u&&kee({...M}),Tee({...M,apply:({elements:Ke,rects:gt,availableWidth:Oe,availableHeight:de})=>{const{width:Ee,height:Qe}=gt.reference,fe=Ke.floating.style;fe.setProperty("--radix-popper-available-width",`${Oe}px`),fe.setProperty("--radix-popper-available-height",`${de}px`),fe.setProperty("--radix-popper-anchor-width",`${Ee}px`),fe.setProperty("--radix-popper-anchor-height",`${Qe}px`)}}),A&&Aee({element:A,padding:l}),zee({arrowWidth:H,arrowHeight:P}),y&&Ree({strategy:"referenceHidden",...M})]}),[F,N]=WI(O),W=To(b);Ti(()=>{Y&&(W==null||W())},[Y,W]);const G=(te=K.arrow)==null?void 0:te.x,I=(ue=K.arrow)==null?void 0:ue.y,ne=((ge=K.arrow)==null?void 0:ge.centerOffset)!==0,[ie,se]=_.useState();return Ti(()=>{E&&se(window.getComputedStyle(E).zIndex)},[E]),v.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":[(Se=K.transformOrigin)==null?void 0:Se.x,(Te=K.transformOrigin)==null?void 0:Te.y].join(" "),...((Ie=K.hide)==null?void 0:Ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:v.jsx(Dee,{scope:n,placedSide:F,onArrowChange:z,arrowX:G,arrowY:I,shouldHideArrow:ne,children:v.jsx(Qt.div,{"data-side":F,"data-align":N,...w,ref:T,style:{...w.style,animation:Y?void 0:"none"}})})})});$I.displayName=h1;var HI="PopperArrow",Lee={top:"bottom",right:"left",bottom:"top",left:"right"},UI=_.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Pee(HI,r),o=Lee[s.placedSide];return v.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:v.jsx(Mee,{...i,ref:n,style:{...i.style,display:"block"}})})});UI.displayName=HI;function Iee(e){return e!==null}var zee=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]=WI(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.x)??0)+l/2,g=(((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:`${g}px`):d==="left"&&(b=`${r.floating.width+u}px`,w=o?p:`${g}px`),{data:{x:b,y:w}}}});function WI(e){const[t,n="center"]=e.split("-");return[t,n]}var Pv=BI,If=FI,Lv=$I,Iv=UI,Yb="rovingFocusGroup.onEntryFocus",Bee={bubbles:!1,cancelable:!0},zf="RovingFocusGroup",[R0,qI,jee]=Gx(zf),[Fee,VI]=aa(zf,[jee]),[$ee,Hee]=Fee(zf),YI=_.forwardRef((e,t)=>v.jsx(R0.Provider,{scope:e.__scopeRovingFocusGroup,children:v.jsx(R0.Slot,{scope:e.__scopeRovingFocusGroup,children:v.jsx(Uee,{...e,ref:t})})}));YI.displayName=zf;var Uee=_.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),g=Bn(t,y),b=Xx(s),[w,x]=oc({prop:o,defaultProp:l??null,onChange:u,caller:zf}),[E,k]=_.useState(!1),T=To(d),A=qI(n),z=_.useRef(!1),[R,H]=_.useState(0);return _.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(Yb,T),()=>P.removeEventListener(Yb,T)},[T]),v.jsx($ee,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:w,onItemFocus:_.useCallback(P=>x(P),[x]),onItemShiftTab:_.useCallback(()=>k(!0),[]),onFocusableItemAdd:_.useCallback(()=>H(P=>P+1),[]),onFocusableItemRemove:_.useCallback(()=>H(P=>P-1),[]),children:v.jsx(Qt.div,{tabIndex:E||R===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:yt(e.onMouseDown,()=>{z.current=!0}),onFocus:yt(e.onFocus,P=>{const q=!z.current;if(P.target===P.currentTarget&&q&&!E){const U=new CustomEvent(Yb,Bee);if(P.currentTarget.dispatchEvent(U),!U.defaultPrevented){const $=A().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);XI(L,h)}}z.current=!1}),onBlur:yt(e.onBlur,()=>k(!1))})})}),KI="RovingFocusGroupItem",GI=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=Hee(KI,n),p=h.currentTabStopId===d,y=qI(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:w}=h;return _.useEffect(()=>{if(r)return g(),()=>b()},[r,g,b]),v.jsx(R0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:v.jsx(Qt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:yt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:yt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:yt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=Vee(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(A=>A.focusable).map(A=>A.ref.current);if(E==="last")T.reverse();else if(E==="prev"||E==="next"){E==="prev"&&T.reverse();const A=T.indexOf(x.currentTarget);T=h.loop?Yee(T,A+1):T.slice(A+1)}setTimeout(()=>XI(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});GI.displayName=KI;var Wee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function qee(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Vee(e,t,n){const r=qee(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Wee[r]}function XI(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Yee(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Kee=YI,Gee=GI,A0=["Enter"," "],Xee=["ArrowDown","PageUp","Home"],ZI=["ArrowUp","PageDown","End"],Zee=[...Xee,...ZI],Qee={ltr:[...A0,"ArrowRight"],rtl:[...A0,"ArrowLeft"]},Jee={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Bf="Menu",[ff,ete,tte]=Gx(Bf),[bc,QI]=aa(Bf,[tte,bl,VI]),zv=bl(),JI=VI(),[nte,wc]=bc(Bf),[rte,jf]=bc(Bf),ez=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=zv(t),[u,d]=_.useState(null),h=_.useRef(!1),p=To(s),y=Xx(i);return _.useEffect(()=>{const g=()=>{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",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),v.jsx(Pv,{...l,children:v.jsx(nte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:v.jsx(rte,{scope:t,onClose:_.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};ez.displayName=Bf;var ite="MenuAnchor",f1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(If,{...i,...r,ref:t})});f1.displayName=ite;var p1="MenuPortal",[ste,tz]=bc(p1,{forceMount:void 0}),nz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=wc(p1,t);return v.jsx(ste,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};nz.displayName=p1;var Ds="MenuContent",[ote,m1]=bc(Ds),rz=_.forwardRef((e,t)=>{const n=tz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:o.modal?v.jsx(ate,{...i,ref:t}):v.jsx(lte,{...i,ref:t})})})})}),ate=_.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 Rv(s)},[]),v.jsx(g1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),lte=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu);return v.jsx(g1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),cte=ll("MenuContent.ScrollLock"),g1=_.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:g,disableOutsideScroll:b,...w}=e,x=wc(Ds,n),E=jf(Ds,n),k=zv(n),T=JI(n),A=ete(n),[z,R]=_.useState(null),H=_.useRef(null),P=Bn(t,H,x.onContentChange),q=_.useRef(0),U=_.useRef(""),$=_.useRef(0),D=_.useRef(null),M=_.useRef("right"),j=_.useRef(0),L=b?Pf:_.Fragment,O=b?{as:cte,allowPinchZoom:!0}:void 0,Y=F=>{var te,ue;const N=U.current+F,W=A().filter(ge=>!ge.disabled),G=document.activeElement,I=(te=W.find(ge=>ge.ref.current===G))==null?void 0:te.textValue,ne=W.map(ge=>ge.textValue),ie=wte(ne,N,I),se=(ue=W.find(ge=>ge.textValue===ie))==null?void 0:ue.ref.current;(function ge(Se){U.current=Se,window.clearTimeout(q.current),Se!==""&&(q.current=window.setTimeout(()=>ge(""),1e3))})(N),se&&setTimeout(()=>se.focus())};_.useEffect(()=>()=>window.clearTimeout(q.current),[]),kv();const K=_.useCallback(F=>{var W,G;return M.current===((W=D.current)==null?void 0:W.side)&&xte(F,(G=D.current)==null?void 0:G.area)},[]);return v.jsx(ote,{scope:n,searchRef:U,onItemEnter:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),onItemLeave:_.useCallback(F=>{var N;K(F)||((N=H.current)==null||N.focus(),R(null))},[K]),onTriggerLeave:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),pointerGraceTimerRef:$,onPointerGraceIntentChange:_.useCallback(F=>{D.current=F},[]),children:v.jsx(L,{...O,children:v.jsx(Df,{asChild:!0,trapped:i,onMountAutoFocus:yt(s,F=>{var N;F.preventDefault(),(N=H.current)==null||N.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:g,children:v.jsx(Kee,{asChild:!0,...T,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:z,onCurrentTabStopIdChange:R,onEntryFocus:yt(u,F=>{E.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:v.jsx(Lv,{role:"menu","aria-orientation":"vertical","data-state":_z(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:yt(w.onKeyDown,F=>{const W=F.target.closest("[data-radix-menu-content]")===F.currentTarget,G=F.ctrlKey||F.altKey||F.metaKey,I=F.key.length===1;W&&(F.key==="Tab"&&F.preventDefault(),!G&&I&&Y(F.key));const ne=H.current;if(F.target!==ne||!Zee.includes(F.key))return;F.preventDefault();const se=A().filter(te=>!te.disabled).map(te=>te.ref.current);ZI.includes(F.key)&&se.reverse(),_te(se)}),onBlur:yt(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(q.current),U.current="")}),onPointerMove:yt(e.onPointerMove,pf(F=>{const N=F.target,W=j.current!==F.clientX;if(F.currentTarget.contains(N)&&W){const G=F.clientX>j.current?"right":"left";M.current=G,j.current=F.clientX}}))})})})})})})});rz.displayName=Ds;var ute="MenuGroup",v1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Qt.div,{role:"group",...r,ref:t})});v1.displayName=ute;var dte="MenuLabel",iz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Qt.div,{...r,ref:t})});iz.displayName=dte;var qg="MenuItem",TN="menu.itemSelect",Bv=_.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=_.useRef(null),o=jf(qg,e.__scopeMenu),l=m1(qg,e.__scopeMenu),u=Bn(t,s),d=_.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(TN,{bubbles:!0,cancelable:!0});p.addEventListener(TN,g=>r==null?void 0:r(g),{once:!0}),qL(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return v.jsx(sz,{...i,ref:u,disabled:n,onClick:yt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:yt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:yt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||A0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Bv.displayName=qg;var sz=_.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=m1(qg,n),l=JI(n),u=_.useRef(null),d=Bn(t,u),[h,p]=_.useState(!1),[y,g]=_.useState("");return _.useEffect(()=>{const b=u.current;b&&g((b.textContent??"").trim())},[s.children]),v.jsx(ff.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:v.jsx(Gee,{asChild:!0,...l,focusable:!r,children:v.jsx(Qt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:yt(e.onPointerMove,pf(b=>{r?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:yt(e.onPointerLeave,pf(b=>o.onItemLeave(b))),onFocus:yt(e.onFocus,()=>p(!0)),onBlur:yt(e.onBlur,()=>p(!1))})})})}),hte="MenuCheckboxItem",oz=_.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return v.jsx(dz,{scope:e.__scopeMenu,checked:n,children:v.jsx(Bv,{role:"menuitemcheckbox","aria-checked":Vg(n)?"mixed":n,...i,ref:t,"data-state":_1(n),onSelect:yt(i.onSelect,()=>r==null?void 0:r(Vg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});oz.displayName=hte;var az="MenuRadioGroup",[fte,pte]=bc(az,{value:void 0,onValueChange:()=>{}}),lz=_.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return v.jsx(fte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:v.jsx(v1,{...i,ref:t})})});lz.displayName=az;var cz="MenuRadioItem",uz=_.forwardRef((e,t)=>{const{value:n,...r}=e,i=pte(cz,e.__scopeMenu),s=n===i.value;return v.jsx(dz,{scope:e.__scopeMenu,checked:s,children:v.jsx(Bv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_1(s),onSelect:yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});uz.displayName=cz;var y1="MenuItemIndicator",[dz,mte]=bc(y1,{checked:!1}),hz=_.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=mte(y1,n);return v.jsx(Bs,{present:r||Vg(s.checked)||s.checked===!0,children:v.jsx(Qt.span,{...i,ref:t,"data-state":_1(s.checked)})})});hz.displayName=y1;var gte="MenuSeparator",fz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Qt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});fz.displayName=gte;var vte="MenuArrow",pz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(Iv,{...i,...r,ref:t})});pz.displayName=vte;var yte="MenuSub",[uTe,mz]=bc(yte),Ph="MenuSubTrigger",gz=_.forwardRef((e,t)=>{const n=wc(Ph,e.__scopeMenu),r=jf(Ph,e.__scopeMenu),i=mz(Ph,e.__scopeMenu),s=m1(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]),v.jsx(f1,{asChild:!0,...d,children:v.jsx(sz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":_z(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:yt(e.onPointerMove,pf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:yt(e.onPointerLeave,pf(p=>{var g,b;h();const y=(g=n.content)==null?void 0:g.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:yt(e.onKeyDown,p=>{var g;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Qee[r.dir].includes(p.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),p.preventDefault())})})})});gz.displayName=Ph;var vz="MenuSubContent",yz=_.forwardRef((e,t)=>{const n=tz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu),l=mz(vz,e.__scopeMenu),u=_.useRef(null),d=Bn(t,u);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:v.jsx(g1,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:yt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:yt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:yt(e.onKeyDown,h=>{var g;const p=h.currentTarget.contains(h.target),y=Jee[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),h.preventDefault())})})})})})});yz.displayName=vz;function _z(e){return e?"open":"closed"}function Vg(e){return e==="indeterminate"}function _1(e){return Vg(e)?"indeterminate":e?"checked":"unchecked"}function _te(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function bte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function wte(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=bte(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 Ste(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 xte(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Ste(n,t)}function pf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Ete=ez,Cte=f1,kte=nz,Tte=rz,Rte=v1,Ate=iz,Nte=Bv,Mte=oz,Ote=lz,Dte=uz,Pte=hz,Lte=fz,Ite=pz,zte=gz,Bte=yz,jv="DropdownMenu",[jte]=aa(jv,[QI]),ji=QI(),[Fte,bz]=jte(jv),wz=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:jv});return v.jsx(Fte,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:_.useCallback(()=>p(y=>!y),[p]),modal:l,children:v.jsx(Ete,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};wz.displayName=jv;var Sz="DropdownMenuTrigger",xz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=bz(Sz,n),o=ji(n);return v.jsx(Cte,{asChild:!0,...o,children:v.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:yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});xz.displayName=Sz;var $te="DropdownMenuPortal",Ez=e=>{const{__scopeDropdownMenu:t,...n}=e,r=ji(t);return v.jsx(kte,{...r,...n})};Ez.displayName=$te;var Cz="DropdownMenuContent",kz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=bz(Cz,n),s=ji(n),o=_.useRef(!1);return v.jsx(Tte,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:yt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});kz.displayName=Cz;var Hte="DropdownMenuGroup",Ute=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Rte,{...i,...r,ref:t})});Ute.displayName=Hte;var Wte="DropdownMenuLabel",Tz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ate,{...i,...r,ref:t})});Tz.displayName=Wte;var qte="DropdownMenuItem",Rz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Nte,{...i,...r,ref:t})});Rz.displayName=qte;var Vte="DropdownMenuCheckboxItem",Az=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Mte,{...i,...r,ref:t})});Az.displayName=Vte;var Yte="DropdownMenuRadioGroup",Kte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ote,{...i,...r,ref:t})});Kte.displayName=Yte;var Gte="DropdownMenuRadioItem",Xte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Dte,{...i,...r,ref:t})});Xte.displayName=Gte;var Zte="DropdownMenuItemIndicator",Nz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Pte,{...i,...r,ref:t})});Nz.displayName=Zte;var Qte="DropdownMenuSeparator",Mz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Lte,{...i,...r,ref:t})});Mz.displayName=Qte;var Jte="DropdownMenuArrow",ene=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ite,{...i,...r,ref:t})});ene.displayName=Jte;var tne="DropdownMenuSubTrigger",nne=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(zte,{...i,...r,ref:t})});nne.displayName=tne;var rne="DropdownMenuSubContent",ine=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Bte,{...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)"}})});ine.displayName=rne;var sne=wz,one=xz,ane=Ez,lne=kz,cne=Tz,une=Rz,dne=Az,hne=Nz,fne=Mz;function RN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Fv="Popover",[Oz]=aa(Fv,[bl]),Ff=bl(),[pne,wl]=Oz(Fv),Dz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Ff(t),u=_.useRef(null),[d,h]=_.useState(!1),[p,y]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:Fv});return v.jsx(Pv,{...l,children:v.jsx(pne,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:_.useCallback(()=>y(g=>!g),[y]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:o,children:n})})};Dz.displayName=Fv;var Pz="PopoverAnchor",mne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Pz,n),s=Ff(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return _.useEffect(()=>(o(),()=>l()),[o,l]),v.jsx(If,{...s,...r,ref:t})});mne.displayName=Pz;var Lz="PopoverTrigger",Iz=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Lz,n),s=Ff(n),o=Bn(t,i.triggerRef),l=v.jsx(Qt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":$z(i.open),...r,ref:o,onClick:yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:v.jsx(If,{asChild:!0,...s,children:l})});Iz.displayName=Lz;var b1="PopoverPortal",[gne,vne]=Oz(b1,{forceMount:void 0}),zz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=wl(b1,t);return v.jsx(gne,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};zz.displayName=b1;var qu="PopoverContent",Bz=_.forwardRef((e,t)=>{const n=vne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=wl(qu,e.__scopePopover);return v.jsx(Bs,{present:r||s.open,children:s.modal?v.jsx(_ne,{...i,ref:t}):v.jsx(bne,{...i,ref:t})})});Bz.displayName=qu;var yne=ll("PopoverContent.RemoveScroll"),_ne=_.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 Rv(o)},[]),v.jsx(Pf,{as:yne,allowPinchZoom:!0,children:v.jsx(jz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:yt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),bne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return v.jsx(jz,{...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()}})}),jz=_.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),g=Ff(n);return kv(),v.jsx(Df,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:v.jsx(Lv,{"data-state":$z(y.open),role:"dialog",id:y.contentId,...g,...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)"}})})})}),Fz="PopoverClose",wne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Fz,n);return v.jsx(Qt.button,{type:"button",...r,ref:t,onClick:yt(e.onClick,()=>i.onOpenChange(!1))})});wne.displayName=Fz;var Sne="PopoverArrow",xne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Ff(n);return v.jsx(Iv,{...i,...r,ref:t})});xne.displayName=Sne;function $z(e){return e?"open":"closed"}var Ene=Dz,Cne=Iz,kne=zz,Tne=Bz,Rne=[" ","Enter","ArrowUp","ArrowDown"],Ane=[" ","Enter"],cc="Select",[$v,Hv,Nne]=Gx(cc),[ad]=aa(cc,[Nne,bl]),Uv=bl(),[Mne,Sl]=ad(cc),[One,Dne]=ad(cc),Hz=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:g,form:b}=e,w=Uv(t),[x,E]=_.useState(null),[k,T]=_.useState(null),[A,z]=_.useState(!1),R=Xx(d),[H,P]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:cc}),[q,U]=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 v.jsx(Pv,{...w,children:v.jsxs(Mne,{required:g,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:A,onValueNodeHasChildrenChange:z,contentId:gi(),value:q,onValueChange:U,open:H,onOpenChange:P,dir:R,triggerPointerDownPosRef:$,disabled:y,children:[v.jsx($v.Provider,{scope:t,children:v.jsx(One,{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?v.jsxs(uB,{"aria-hidden":!0,required:g,tabIndex:-1,name:h,autoComplete:p,value:q,onChange:O=>U(O.target.value),disabled:y,form:b,children:[q===void 0?v.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};Hz.displayName=cc;var Uz="SelectTrigger",Wz=_.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Uv(n),o=Sl(Uz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Hv(n),h=_.useRef("touch"),[p,y,g]=hB(w=>{const x=d().filter(T=>!T.disabled),E=x.find(T=>T.value===o.value),k=fB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),b=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return v.jsx(If,{asChild:!0,...s,children:v.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":dB(o.value)?"":void 0,...i,ref:u,onClick:yt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&b(w)}),onPointerDown:yt(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(b(w),w.preventDefault())}),onKeyDown:yt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&Rne.includes(w.key)&&(b(),w.preventDefault())})})})});Wz.displayName=Uz;var qz="SelectValue",Vz=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=Sl(qz,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ti(()=>{d(h)},[d,h]),v.jsx(Qt.span,{...l,ref:p,style:{pointerEvents:"none"},children:dB(u.value)?v.jsx(v.Fragment,{children:o}):s})});Vz.displayName=qz;var Pne="SelectIcon",Yz=_.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return v.jsx(Qt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});Yz.displayName=Pne;var Lne="SelectPortal",Kz=e=>v.jsx(id,{asChild:!0,...e});Kz.displayName=Lne;var uc="SelectContent",Gz=_.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(v.jsx(Xz,{scope:e.__scopeSelect,children:v.jsx($v.Slot,{scope:e.__scopeSelect,children:v.jsx("div",{children:e.children})})}),s):null}return v.jsx(Zz,{...e,ref:t})});Gz.displayName=uc;var qs=10,[Xz,xl]=ad(uc),Ine="SelectContentImpl",zne=ll("SelectContent.RemoveScroll"),Zz=_.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:g,sticky:b,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=Sl(uc,n),[T,A]=_.useState(null),[z,R]=_.useState(null),H=Bn(t,te=>A(te)),[P,q]=_.useState(null),[U,$]=_.useState(null),D=Hv(n),[M,j]=_.useState(!1),L=_.useRef(!1);_.useEffect(()=>{if(T)return Rv(T)},[T]),kv();const O=_.useCallback(te=>{const[ue,...ge]=D().map(Ie=>Ie.ref.current),[Se]=ge.slice(-1),Te=document.activeElement;for(const Ie of te)if(Ie===Te||(Ie==null||Ie.scrollIntoView({block:"nearest"}),Ie===ue&&z&&(z.scrollTop=0),Ie===Se&&z&&(z.scrollTop=z.scrollHeight),Ie==null||Ie.focus(),document.activeElement!==Te))return},[D,z]),Y=_.useCallback(()=>O([P,T]),[O,P,T]);_.useEffect(()=>{M&&Y()},[M,Y]);const{onOpenChange:K,triggerPointerDownPosRef:F}=k;_.useEffect(()=>{if(T){let te={x:0,y:0};const ue=Se=>{var Te,Ie;te={x:Math.abs(Math.round(Se.pageX)-(((Te=F.current)==null?void 0:Te.x)??0)),y:Math.abs(Math.round(Se.pageY)-(((Ie=F.current)==null?void 0:Ie.y)??0))}},ge=Se=>{te.x<=10&&te.y<=10?Se.preventDefault():T.contains(Se.target)||K(!1),document.removeEventListener("pointermove",ue),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",ue),document.addEventListener("pointerup",ge,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ue),document.removeEventListener("pointerup",ge,{capture:!0})}}},[T,K,F]),_.useEffect(()=>{const te=()=>K(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[K]);const[N,W]=hB(te=>{const ue=D().filter(Te=>!Te.disabled),ge=ue.find(Te=>Te.ref.current===document.activeElement),Se=fB(ue,te,ge);Se&&setTimeout(()=>Se.ref.current.focus())}),G=_.useCallback((te,ue,ge)=>{const Se=!L.current&&!ge;(k.value!==void 0&&k.value===ue||Se)&&(q(te),Se&&(L.current=!0))},[k.value]),I=_.useCallback(()=>T==null?void 0:T.focus(),[T]),ne=_.useCallback((te,ue,ge)=>{const Se=!L.current&&!ge;(k.value!==void 0&&k.value===ue||Se)&&$(te)},[k.value]),ie=r==="popper"?N0:Qz,se=ie===N0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:g,sticky:b,hideWhenDetached:w,avoidCollisions:x}:{};return v.jsx(Xz,{scope:n,content:T,viewport:z,onViewportChange:R,itemRefCallback:G,selectedItem:P,onItemLeave:I,itemTextRefCallback:ne,focusSelectedItem:Y,selectedItemText:U,position:r,isPositioned:M,searchRef:N,children:v.jsx(Pf,{as:zne,allowPinchZoom:!0,children:v.jsx(Df,{asChild:!0,trapped:k.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:yt(i,te=>{var ue;(ue=k.trigger)==null||ue.focus({preventScroll:!0}),te.preventDefault()}),children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:v.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:H,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:yt(E.onKeyDown,te=>{const ue=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!ue&&te.key.length===1&&W(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let Se=D().filter(Te=>!Te.disabled).map(Te=>Te.ref.current);if(["ArrowUp","End"].includes(te.key)&&(Se=Se.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const Te=te.target,Ie=Se.indexOf(Te);Se=Se.slice(Ie+1)}setTimeout(()=>O(Se)),te.preventDefault()}})})})})})})});Zz.displayName=Ine;var Bne="SelectItemAlignedPosition",Qz=_.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,H=>h(H)),y=Hv(n),g=_.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 H=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),q=s.valueNode.getBoundingClientRect(),U=E.getBoundingClientRect();if(s.dir!=="rtl"){const Te=U.left-P.left,Ie=q.left-Te,Ke=H.left-Ie,gt=H.width+Ke,Oe=Math.max(gt,P.width),de=window.innerWidth-qs,Ee=RN(Ie,[qs,Math.max(qs,de-Oe)]);l.style.minWidth=gt+"px",l.style.left=Ee+"px"}else{const Te=P.right-U.right,Ie=window.innerWidth-q.right-Te,Ke=window.innerWidth-H.right-Ie,gt=H.width+Ke,Oe=Math.max(gt,P.width),de=window.innerWidth-qs,Ee=RN(Ie,[qs,Math.max(qs,de-Oe)]);l.style.minWidth=gt+"px",l.style.right=Ee+"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),F=L+O+M+K+Y,N=Math.min(x.offsetHeight*5,F),W=window.getComputedStyle(w),G=parseInt(W.paddingTop,10),I=parseInt(W.paddingBottom,10),ne=H.top+H.height/2-qs,ie=D-ne,se=x.offsetHeight/2,te=x.offsetTop+se,ue=L+O+te,ge=F-ue;if(ue<=ne){const Te=$.length>0&&x===$[$.length-1].ref.current;l.style.bottom="0px";const Ie=d.clientHeight-w.offsetTop-w.offsetHeight,Ke=Math.max(ie,se+(Te?I:0)+Ie+Y),gt=ue+Ke;l.style.height=gt+"px"}else{const Te=$.length>0&&x===$[0].ref.current;l.style.top="0px";const Ke=Math.max(ne,L+w.offsetTop+(Te?G:0)+se)+ge;l.style.height=Ke+"px",w.scrollTop=ue-ne+w.offsetTop}l.style.margin=`${qs}px 0`,l.style.minHeight=N+"px",l.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ti(()=>T(),[T]);const[A,z]=_.useState();Ti(()=>{d&&z(window.getComputedStyle(d).zIndex)},[d]);const R=_.useCallback(H=>{H&&b.current===!0&&(T(),k==null||k(),b.current=!1)},[T,k]);return v.jsx(Fne,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:R,children:v.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:v.jsx(Qt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});Qz.displayName=Bne;var jne="SelectPopperPosition",N0=_.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=qs,...s}=e,o=Uv(n);return v.jsx(Lv,{...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)"}})});N0.displayName=jne;var[Fne,w1]=ad(uc,{}),M0="SelectViewport",Jz=_.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=xl(M0,n),o=w1(M0,n),l=Bn(t,s.onViewportChange),u=_.useRef(0);return v.jsxs(v.Fragment,{children:[v.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}),v.jsx($v.Slot,{scope:n,children:v.jsx(Qt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:yt(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const g=Math.abs(u.current-h.scrollTop);if(g>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+g,T=Math.min(b,k),A=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(h.scrollTop=A>0?A:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});Jz.displayName=M0;var eB="SelectGroup",[$ne,Hne]=ad(eB),Une=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return v.jsx($ne,{scope:n,id:i,children:v.jsx(Qt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});Une.displayName=eB;var tB="SelectLabel",Wne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Hne(tB,n);return v.jsx(Qt.div,{id:i.id,...r,ref:t})});Wne.displayName=tB;var Yg="SelectItem",[qne,nB]=ad(Yg),rB=_.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,g]=_.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 v.jsx(qne,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:_.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:v.jsx($v.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:v.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:yt(o.onFocus,()=>g(!0)),onBlur:yt(o.onBlur,()=>g(!1)),onClick:yt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:yt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:yt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:yt(o.onPointerMove,k=>{var T;x.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:yt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:yt(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(Ane.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});rB.displayName=Yg;var Lh="SelectItemText",iB=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Sl(Lh,n),l=xl(Lh,n),u=nB(Lh,n),d=Dne(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)}),g=h==null?void 0:h.textContent,b=_.useMemo(()=>v.jsx("option",{value:u.value,disabled:u.disabled,children:g},u.value),[u.disabled,u.value,g]),{onNativeOptionAdd:w,onNativeOptionRemove:x}=d;return Ti(()=>(w(b),()=>x(b)),[w,x,b]),v.jsxs(v.Fragment,{children:[v.jsx(Qt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?nd.createPortal(s.children,o.valueNode):null]})});iB.displayName=Lh;var sB="SelectItemIndicator",oB=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return nB(sB,n).isSelected?v.jsx(Qt.span,{"aria-hidden":!0,...r,ref:t}):null});oB.displayName=sB;var O0="SelectScrollUpButton",aB=_.forwardRef((e,t)=>{const n=xl(O0,e.__scopeSelect),r=w1(O0,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?v.jsx(cB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});aB.displayName=O0;var D0="SelectScrollDownButton",lB=_.forwardRef((e,t)=>{const n=xl(D0,e.__scopeSelect),r=w1(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.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?v.jsx(cB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});lB.displayName=D0;var cB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=xl("SelectScrollButton",n),o=_.useRef(null),l=Hv(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]),v.jsx(Qt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:yt(i.onPointerLeave,()=>{u()})})}),Vne="SelectSeparator",Yne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return v.jsx(Qt.div,{"aria-hidden":!0,...r,ref:t})});Yne.displayName=Vne;var P0="SelectArrow",Kne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Uv(n),s=Sl(P0,n),o=xl(P0,n);return s.open&&o.position==="popper"?v.jsx(Iv,{...i,...r,ref:t}):null});Kne.displayName=P0;var Gne="SelectBubbleInput",uB=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=_.useRef(null),s=Bn(r,i),o=EJ(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]),v.jsx(Qt.select,{...n,style:{...VL,...n.style},ref:s,defaultValue:t})});uB.displayName=Gne;function dB(e){return e===""||e===void 0}function hB(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 fB(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=Xne(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 Xne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zne=Hz,Qne=Wz,Jne=Vz,ere=Yz,tre=Kz,nre=Gz,rre=Jz,ire=rB,sre=iB,ore=oB,are=aB,lre=lB,[Wv]=aa("Tooltip",[bl]),qv=bl(),pB="TooltipProvider",cre=700,L0="tooltip.open",[ure,S1]=Wv(pB),mB=e=>{const{__scopeTooltip:t,delayDuration:n=cre,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)},[]),v.jsx(ure,{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})};mB.displayName=pB;var mf="Tooltip",[dre,$f]=Wv(mf),gB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=S1(mf,e.__scopeTooltip),d=qv(t),[h,p]=_.useState(null),y=gi(),g=_.useRef(0),b=o??u.disableHoverableContent,w=l??u.delayDuration,x=_.useRef(!1),[E,k]=oc({prop:r,defaultProp:i??!1,onChange:H=>{H?(u.onOpen(),document.dispatchEvent(new CustomEvent(L0))):u.onClose(),s==null||s(H)},caller:mf}),T=_.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),A=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,x.current=!1,k(!0)},[k]),z=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),R=_.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{x.current=!0,k(!0),g.current=0},w)},[w,k]);return _.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),v.jsx(Pv,{...d,children:v.jsx(dre,{scope:t,contentId:y,open:E,stateAttribute:T,trigger:h,onTriggerChange:p,onTriggerEnter:_.useCallback(()=>{u.isOpenDelayedRef.current?R():A()},[u.isOpenDelayedRef,R,A]),onTriggerLeave:_.useCallback(()=>{b?z():(window.clearTimeout(g.current),g.current=0)},[z,b]),onOpen:A,onClose:z,disableHoverableContent:b,children:n})})};gB.displayName=mf;var I0="TooltipTrigger",vB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=$f(I0,n),s=S1(I0,n),o=qv(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]),v.jsx(If,{asChild:!0,...o,children:v.jsx(Qt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:yt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:yt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:yt(e.onBlur,i.onClose),onClick:yt(e.onClick,i.onClose)})})});vB.displayName=I0;var x1="TooltipPortal",[hre,fre]=Wv(x1,{forceMount:void 0}),yB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=$f(x1,t);return v.jsx(hre,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};yB.displayName=x1;var Vu="TooltipContent",_B=_.forwardRef((e,t)=>{const n=fre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=$f(Vu,e.__scopeTooltip);return v.jsx(Bs,{present:r||o.open,children:o.disableHoverableContent?v.jsx(bB,{side:i,...s,ref:t}):v.jsx(pre,{side:i,...s,ref:t})})}),pre=_.forwardRef((e,t)=>{const n=$f(Vu,e.__scopeTooltip),r=S1(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]),g=_.useCallback((b,w)=>{const x=b.currentTarget,E={x:b.clientX,y:b.clientY},k=yre(E,x.getBoundingClientRect()),T=_re(E,k),A=bre(w.getBoundingClientRect()),z=Sre([...T,...A]);l(z),p(!0)},[p]);return _.useEffect(()=>()=>y(),[y]),_.useEffect(()=>{if(u&&h){const b=x=>g(x,h),w=x=>g(x,u);return u.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[u,h,g,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=!wre(E,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[u,h,o,d,y]),v.jsx(bB,{...e,ref:s})}),[mre,gre]=Wv(mf,{isInside:!1}),vre=XZ("TooltipContent"),bB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=$f(Vu,n),d=qv(n),{onClose:h}=u;return _.useEffect(()=>(document.addEventListener(L0,h),()=>document.removeEventListener(L0,h)),[h]),_.useEffect(()=>{if(u.trigger){const p=y=>{const g=y.target;g!=null&&g.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:v.jsxs(Lv,{"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:[v.jsx(vre,{children:r}),v.jsx(mre,{scope:n,isInside:!0,children:v.jsx(KL,{id:u.contentId,role:"tooltip",children:i||r})})]})})});_B.displayName=Vu;var wB="TooltipArrow",SB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=qv(n);return gre(wB,n).isInside?null:v.jsx(Iv,{...i,...r,ref:t})});SB.displayName=wB;function yre(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 _re(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 bre(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 wre(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 Sre(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),xre(t)}function xre(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 Ere=mB,Cre=gB,kre=vB,Tre=yB,Rre=_B,Are=SB;function E1({...e}){return v.jsx(Ene,{"data-slot":"popover",...e})}function C1({...e}){return v.jsx(Cne,{"data-slot":"popover-trigger",...e})}function k1({className:e,align:t="center",sideOffset:n=4,...r}){return v.jsx(kne,{children:v.jsx(Tne,{"data-slot":"popover-content",align:t,sideOffset:n,className:qe("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const Nre={"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}=Nre[e];return e==="no-messages"?v.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:v.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):v.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:[v.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&v.jsx("div",{children:t})]})}const Mre={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Ore={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function AN({status:e,className:t}){return v.jsx("span",{className:qe("inline-block w-2 h-2 rounded-full shrink-0",Mre[e],t),role:"status","aria-label":Ore[e]})}function xB({layout:e,variant:t="default"}){const n=Be(w=>w.proxies),r=Be(w=>w.proxyListLoaded),i=Be(w=>w.relayClientAuthIssue),s=Be(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){st.error("请先连接开发机");return}const k=x??w;p(w);try{const T=await E.selectProxy(w);if(!T.success){st.error(`无法连接 ${k}:${T.error??"未知错误"}`);return}dr("local",ln.proxyId,w),Be.getState().setProxy(w,x??null),Be.getState().setProxyOnline(!0),Be.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestAgentStatuses().then(A=>{const z=Wt.getState();for(const R of A)z.setAgentStatus(R.sessionId,R.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),E.requestSessionHistory().then(A=>Wt.getState().setHistorySessions(A)).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),d(!1),(e==="page"||o.pathname.startsWith("/chat/"))&&l("/sessions")}catch(T){const A=T instanceof Error?T.message:"未知错误";st.error(`无法连接 ${k}:${A}`)}finally{p(null)}}if(e==="page")return i==="missing_client_token"?v.jsx(nc,{variant:"client-token-missing"}):i==="invalid_client_token"?v.jsx(nc,{variant:"client-token-invalid"}):r?n.length===0?v.jsx(nc,{variant:"no-proxy"}):v.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[v.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),v.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.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:qe("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",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:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})]}):v.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:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});const g=n.find(w=>w.proxyId===s),b=(g==null?void 0:g.name)??(g==null?void 0:g.proxyId)??"未选择开发机";return v.jsxs(E1,{open:u,onOpenChange:d,children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:qe("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${b}`,children:[t==="default"&&v.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),v.jsx("span",{className:qe("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:b}),v.jsx(gl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),v.jsx(k1,{align:"start",className:"w-[260px] p-1",children:n.length===0?v.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):v.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.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:qe("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",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:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&s!==w.proxyId&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})})]})}const NN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,MN=MP,Dre=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return MN(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=NN(h)||NN(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,...g}=h;return Object.entries(g).every(b=>{let[w,x]=b;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return MN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Pre=Dre("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?KZ:"button";return v.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:qe(Pre({variant:t,size:n,className:e})),...i})}function Lre({delayDuration:e=0,...t}){return v.jsx(Ere,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Hf({...e}){return v.jsx(Cre,{"data-slot":"tooltip",...e})}function Uf({...e}){return v.jsx(kre,{"data-slot":"tooltip-trigger",...e})}function Wf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return v.jsx(Tre,{children:v.jsxs(Rre,{"data-slot":"tooltip-content",sideOffset:t,className:qe("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&v.jsx(Are,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Vv({...e}){return v.jsx(e1,{"data-slot":"sheet",...e})}function Ire({...e}){return v.jsx(xJ,{"data-slot":"sheet-trigger",...e})}function zre({...e}){return v.jsx(t1,{"data-slot":"sheet-portal",...e})}function Bre({className:e,...t}){return v.jsx(n1,{"data-slot":"sheet-overlay",className:qe("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Yv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return v.jsxs(zre,{children:[v.jsx(Bre,{className:t}),v.jsxs(r1,{"data-slot":"sheet-content",className:qe("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&v.jsxs(i1,{"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:[v.jsx(Of,{className:"size-4"}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function T1({className:e,...t}){return v.jsx("div",{"data-slot":"sheet-header",className:qe("flex flex-col gap-1.5 p-4",e),...t})}function Kv({className:e,...t}){return v.jsx(SI,{"data-slot":"sheet-title",className:qe("font-semibold text-foreground",e),...t})}function jre({className:e,...t}){return v.jsx(xI,{"data-slot":"sheet-description",className:qe("text-sm text-muted-foreground",e),...t})}function R1({...e}){return v.jsx(sne,{"data-slot":"dropdown-menu",...e})}function A1({...e}){return v.jsx(one,{"data-slot":"dropdown-menu-trigger",...e})}function N1({className:e,sideOffset:t=4,...n}){return v.jsx(ane,{children:v.jsx(lne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:qe("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function bo({className:e,inset:t,variant:n="default",...r}){return v.jsx(une,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:qe("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Kb({className:e,children:t,checked:n,...r}){return v.jsxs(dne,{"data-slot":"dropdown-menu-checkbox-item",className:qe("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[v.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:v.jsx(hne,{children:v.jsx(ra,{className:"size-4"})})}),t]})}function Im({className:e,inset:t,...n}){return v.jsx(cne,{"data-slot":"dropdown-menu-label","data-inset":t,className:qe("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Gb({className:e,...t}){return v.jsx(fne,{"data-slot":"dropdown-menu-separator",className:qe("-mx-1 my-1 h-px bg-border",e),...t})}const Fre={claude:"Claude Code",codex:"Codex"},ON=["claude","codex"];function Gv(e){return Fre[e]}function EB(e,t){return ON.indexOf(e)-ON.indexOf(t)}function z0(e){return e.provider??"claude"}const B0=60*1e3,j0=60*B0,$re=24*j0;function CB(e,t=Date.now()){const n=t-e;if(n<B0)return"刚刚";if(n<j0)return`${Math.floor(n/B0)} 分钟前`;if(n<$re)return`${Math.floor(n/j0)} 小时前`;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 DN={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 F0(e){return e.kind!=="terminal"?DN[e.state]:e.state==="terminated"?DN.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 Hre({session:e}){const t=F0(e);return v.jsx("span",{className:qe("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Ure({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.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:v.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Wre({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Ev(e.name),d=Vx(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?CB(o,n):null,g=e.mode==="pty"&&e.ptyOwner==="local-terminal",b=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return v.jsxs("li",{className:qe("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&v.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),v.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:[v.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[v.jsx(Hre,{session:e}),v.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&v.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&v.jsx(Ure,{mode:e.mode}),e.mode&&v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Gv(e.provider)}),v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),v.jsx("span",{className:qe("shrink-0",F0(e).text),children:F0(e).label}),y&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),v.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:v.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:v.jsx(Q9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end","data-slot":"session-row-menu",children:[i&&v.jsx(bo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&v.jsx(bo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:b})]})]})]})}function Sc({...e}){return v.jsx(e1,{"data-slot":"dialog",...e})}function qre({...e}){return v.jsx(t1,{"data-slot":"dialog-portal",...e})}function Vre({className:e,...t}){return v.jsx(n1,{"data-slot":"dialog-overlay",className:qe("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function xc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return v.jsxs(qre,{"data-slot":"dialog-portal",children:[v.jsx(Vre,{}),v.jsxs(r1,{"data-slot":"dialog-content",className:qe("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&v.jsxs(i1,{"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:[v.jsx(Of,{}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ec({className:e,...t}){return v.jsx("div",{"data-slot":"dialog-header",className:qe("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return v.jsxs("div",{"data-slot":"dialog-footer",className:qe("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&v.jsx(i1,{asChild:!0,children:v.jsx(St,{variant:"outline",children:"Close"})})]})}function dl({className:e,...t}){return v.jsx(SI,{"data-slot":"dialog-title",className:qe("text-lg leading-none font-semibold",e),...t})}function dc({className:e,...t}){return v.jsx(xI,{"data-slot":"dialog-description",className:qe("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 Yre({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=v.jsx(Kre,{title:e.title,modeTag:s}),l=v.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:CB(e.updatedAt,t)}),u=v.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return v.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:v.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:qe("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,v.jsx(k9,{className:qe("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Kre({title:e,modeTag:t}){return v.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[v.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&v.jsx(Gre,{mode:t})]})}function Gre({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:qe("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:v.jsx(n,{className:"size-3","aria-hidden":"true"})})}function kB({providerLabel:e}){return v.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:v.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[v.jsx(Q8,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),v.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Xre({now:e}){const t=Wt($=>$.historySessions),[n,r]=_.useState(null),[i,s]=_.useState(null),[o,l]=_.useState("json"),[u,d]=_.useState("default"),[h,p]=_.useState(!1),[y,g]=_.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=z0(D);let j=$.get(M);j||(j=new Map,$.set(M,j));const L=TB(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])=>EB(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:Ev(j.dir),sessions:j.sessions}))}))},[t]);function A($){s($),l(Zre($)),d("default")}async function z($,D,M){if(n)return;const j=Ot;if(!j){st.error("请先连接开发机");return}r($.id);const L=z0($);try{const O=await j.createSession({cwd:$.projectDir,mode:D,provider:L,resumeSessionId:$.id,...M?{permissionMode:M}:{}});if(O.error||!O.sessionId){st.error(`恢复失败:${O.error??"未知错误"}`);return}const Y={sessionId:O.sessionId,state:"idle",mode:O.mode??D,provider:O.provider??"claude"};Wt.getState().addSession(Y),k(`/chat/${O.sessionId}?mode=${O.mode??D}`),s(null)}catch(O){st.error(`恢复失败:${O instanceof Error?O.message:String(O)}`)}finally{r(null)}}function R(){const $=Ot;!$||h||(p(!0),$.requestSessionHistory().then(D=>Wt.getState().setHistorySessions(D)).catch(D=>{st.error(D instanceof Error?D.message:String(D))}).finally(()=>{p(!1)}))}function H($,D){const M=PN($,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,U=i?RB():[];return v.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[v.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[v.jsxs("button",{type:"button",onClick:()=>q&&g($=>!$),disabled:!q,"aria-expanded":q?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:qe("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[v.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",q?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),q?v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:R,disabled:h,"data-slot":"history-refresh",children:v.jsx(Tx,{className:qe("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!q&&v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),q&&y&&v.jsx("ul",{role:"list",className:"flex flex-col",children:T.map($=>{const D=b.has($.provider);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>P($.provider),"aria-expanded":!D,"data-slot":"history-provider-header","data-expanded":!D,className:qe("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:Gv($.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:$.sessions.length}),v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!D&&"rotate-90"),"aria-hidden":"true"})]}),!D&&v.jsx("ul",{role:"list",className:"flex flex-col",children:$.projects.map(M=>{const j=PN($.provider,M.dir),L=x.has(j);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>H($.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:qe("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),v.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&v.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(O=>v.jsx(Yre,{session:O,now:e,disabled:n!==null,loading:n===O.id,onClick:()=>A(O),modeTag:O.preferredMode},O.id))})]},j)})})]},$.provider)})}),v.jsx(Qre,{session:i,open:i!==null,modes:U,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:$=>{$||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&z(i,o,u)}})]})}function PN(e,t){return`${e}:${TB(t)}`}function TB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function RB(){return["json","pty"]}function Zre(e){const t=RB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Qre({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",g=hl("(min-width: 768px)");_.useEffect(()=>{t||p(!1)},[t]);const b=h?v.jsx(kB,{providerLabel:e?Gv(z0(e)):"Agent"}):v.jsxs("div",{className:"grid min-w-0 gap-4",children:[v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&v.jsx(LN,{checked:r==="json",label:"聊天",icon:v.jsx(kx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&v.jsx(LN,{checked:r==="pty",label:"终端",icon:v.jsx(Rx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[v.jsx(Xb,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),v.jsx(Xb,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),v.jsx(Xb,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=v.jsxs(v.Fragment,{children:[v.jsx(St,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),v.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 g?v.jsx(Sc,{open:t,onOpenChange:o,children:v.jsxs(xc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[v.jsxs(Ec,{className:"min-w-0",children:[v.jsx(dl,{children:h?"跳过全部审批?":"恢复会话"}),v.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,v.jsx(Yu,{children:w})]})}):v.jsx(Vv,{open:t,onOpenChange:o,children:v.jsxs(Yv,{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:[v.jsxs(T1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[v.jsx(Kv,{children:h?"跳过全部审批?":"恢复会话"}),v.jsx(jre,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),v.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:b}),v.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:v.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function LN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:qe("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,v.jsx("span",{className:"min-w-0 text-center",children:t}),v.jsx(ra,{className:qe("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Xb({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:qe("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[v.jsx("span",{className:qe("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&v.jsx("span",{className:qe("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),v.jsxs("span",{className:"grid min-w-0 gap-1",children:[v.jsx("span",{className:qe("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),v.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&v.jsx(ra,{className:qe("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Jre({...e}){return v.jsx(Zne,{"data-slot":"select",...e})}function eie({...e}){return v.jsx(Jne,{"data-slot":"select-value",...e})}function tie({className:e,size:t="default",children:n,...r}){return v.jsxs(Qne,{"data-slot":"select-trigger","data-size":t,className:qe("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,v.jsx(ere,{asChild:!0,children:v.jsx(gl,{className:"size-4 opacity-50"})})]})}function nie({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return v.jsx(tre,{children:v.jsxs(nre,{"data-slot":"select-content",className:qe("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[v.jsx(iie,{}),v.jsx(rre,{className:qe("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),v.jsx(sie,{})]})})}function rie({className:e,children:t,...n}){return v.jsxs(ire,{"data-slot":"select-item",className:qe("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[v.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:v.jsx(ore,{children:v.jsx(ra,{className:"size-4"})})}),v.jsx(sre,{children:t})]})}function iie({className:e,...t}){return v.jsx(are,{"data-slot":"select-scroll-up-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(Cx,{className:"size-4"})})}function sie({className:e,...t}){return v.jsx(lre,{"data-slot":"select-scroll-down-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(gl,{className:"size-4"})})}function M1(e){return!e||e.endsWith("/")?e:`${e}/`}function oie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function aie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function lie(e,t,n){var o;if(t==="insert")return{currentPath:aie(e)||"./",query:oie(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:M1(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 cie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function uie(e,t){return`${M1(e)}${t.name}${t.isDir?"/":""}`}function IN(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 AB=_.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=Ei(F=>F.tree),h=Ei(F=>F.cwd),p=Ei(F=>F.homePath),y=i==="insert"?h:p||h,g=_.useMemo(()=>new Set(d.keys()),[d]),b=_.useMemo(()=>lie(t,i,{baseCwd:y,knownDirs:g}),[t,i,y,g]),w=b.currentPath,x=_.useMemo(()=>cie(y,w),[y,w]),E=b.query,k=_.useRef(new Set),[T,A]=_.useState(!1),[z,R]=_.useState(""),[H,P]=_.useState(!1);_.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const F=Ot;if(!F)return;let N=!1;return k.current.add(x),F.requestDirectoryList(x).then(W=>{N||Ei.getState().setDirEntries(W.path,W.entries)}).catch(()=>{N||Ei.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{N=!0}},[x,d]);const q=!d.has(x),U=_.useMemo(()=>{let F=d.get(x)??[];return o&&(F=F.filter(N=>N.isDir)),E&&(F=F.filter(N=>N.name.toLowerCase().includes(E))),F},[d,x,E,o]),[$,D]=_.useState(0);_.useEffect(()=>D(0),[w,E]),_.useEffect(()=>{A(!1),R("")},[x]),_.useEffect(()=>{$>=U.length&&U.length>0&&D(U.length-1)},[U.length,$]);const M=_.useRef(null),j=_.useRef(!1);_.useEffect(()=>{var N;if(!j.current)return;j.current=!1;const F=(N=M.current)==null?void 0:N.querySelector(`[data-entry-index="${$}"]`);F==null||F.scrollIntoView({block:"nearest"})},[$]);const L=_.useCallback(F=>{const N=uie(w,F);return i==="insert"?N.replace(/^\.\//,""):N},[w,i]);async function O(){const F=IN(x,z);if(!(!F||!r)){P(!0);try{const N=await r(F);if(!N)return;R(""),A(!1),n(M1(N))}finally{P(!1)}}}_.useImperativeHandle(u,()=>({handleKey(F){return U.length===0?!1:F.key==="ArrowDown"?(j.current=!0,D(N=>Math.min(U.length-1,N+1)),!0):F.key==="ArrowUp"?(j.current=!0,D(N=>Math.max(0,N-1)),!0):F.key==="Enter"&&!F.nativeEvent.isComposing?(n(L(U[$])),!0):!1}}),[U,$,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 v.jsxs("div",{className:Y,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?v.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?v.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||H,onClick:()=>A(F=>!F),children:"新建目录"}):null]}),T?v.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[v.jsx("input",{type:"text",value:z,onChange:F=>R(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!F.nativeEvent.isComposing&&(F.preventDefault(),O()),F.key==="Escape"&&(A(!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}),v.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:!IN(x,z)||H,onClick:()=>void O(),children:H?"创建中...":"创建目录"})]}):null]}):null,v.jsx("div",{className:K,children:U.length===0?v.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:q?"加载中...":"没有匹配的路径"}):v.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map((F,N)=>v.jsx("li",{children:v.jsx("button",{type:"button",onClick:()=>n(L(F)),onMouseEnter:()=>D(N),className:qe("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",N===$&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",F.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":F.isDir?"dir":"file","data-entry-index":N,children:v.jsxs("span",{className:"font-mono text-[13px]",children:[F.name,F.isDir?"/":""]})})},F.name))})})]})}),zN="工作目录不存在或不可访问:",die=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],NB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function hie(e,t){return t!==Xr.PATH_NOT_FOUND||!e.startsWith(zN)?null:e.slice(zN.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 fie(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function pie(e,t){return e!=="codex"||NB.some(n=>n.value===t)?t:"default"}async function mie({relay:e,agentCli:t,form:n,timeoutMs:r=Ux}){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=hie(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,g=((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:g,...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 gie({relay:e,timeoutMs:t=Ux}){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 vie({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),g=e==null?void 0:e[t];return v.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[v.jsxs("div",{className:"flex items-center justify-between",children:[v.jsx("span",{className:"text-sm",children:"Agent CLI"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsx(BN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),v.jsx(BN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),v.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?v.jsx(yie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):v.jsx(_ie,{provider:t,selectedCli:g,isDesktop:n,onOpenCliPathEditor:l})})]})}function BN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return v.jsxs(Hf,{children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:qe("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:na[e]}),v.jsx("span",{className:qe("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),v.jsx(Wf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:v.jsx("span",{className:"break-all font-mono text-xs",children:fie(e,n)})})]})}function yie({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[v.jsxs("label",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:"sr-only",children:"CLI 路径"}),v.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"}),v.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>v.jsx("option",{value:l},l))})]}),v.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[v.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:"取消"}),v.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 _ie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[v.jsx("p",{className:qe("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),v.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:"指定路径"})]})]}):v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),v.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:v.jsx(T8,{className:"size-4","aria-hidden":"true"})}),v.jsx("p",{className:qe("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function 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,g]=_.useState(!1),[b,w]=_.useState(!1),[x,E]=_.useState(null),[k,T]=_.useState(!1),[A,z]=_.useState(null),[R,H]=_.useState(""),[P,q]=_.useState(!1),U=_.useRef(null),$=_.useRef(e);$.current=e;const D=Js(),M=Ei(Se=>Se.homePath),j=Ei(Se=>Se.agentCli),L=hl("(min-width: 768px)");_.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),_.useEffect(()=>{if(!e||M&&j)return;const Se=Ot==null?void 0:Ot.requestProxyInfo();Se&&Se.then(Te=>{const Ie=Ei.getState();Ie.setHomePath(Te.homePath),Ie.setAgentCli(Te.agentCli)}).catch(Te=>{console.error("[create-session-dialog] requestProxyInfo failed",Te)})},[e,M,j]),_.useEffect(()=>{if(!k)return;function Se(Te){var Ke;const Ie=Te.target;Ie instanceof Node&&((Ke=U.current)!=null&&Ke.contains(Ie))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",Se,!0),()=>document.removeEventListener("pointerdown",Se,!0)},[k]);function O(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),g(!1),E(null),z(null),H(""),q(!1)}function Y(){if(h==="bypassPermissions"){g(!0);return}I()}async function K(){await I(),$.current&&g(!1)}const F=o==="codex"?NB:die,N=Kg(o,j),W=b||P||N.disabled;function G(Se){const Te=pie(Se,h);Te!==h&&p(Te)}async function I(Se){E(null),w(!0);try{const Te=await mie({relay:Ot,agentCli:j,form:{cwd:Se??i,name:n,provider:o,permissionMode:h,mode:u}});if(Te.type==="success"){if(Wt.getState().addSession(Te.session),!$.current)return;t(!1),O(),D(Te.route);return}if(Te.type==="missing_cwd"&&E(Te.path),st.error(Te.message),Te.type==="validation_error"||Te.type==="relay_missing")return}finally{w(!1)}}async function ne(Se){const Te=Ot;if(!Te)return st.error("请先连接开发机"),null;try{const Ie=await Te.createDirectory(Se);return Ie.success?(s(Ie.path),E(null),st.success("目录已创建"),Ie.path):(st.error(`目录创建失败:${Ie.error??"未知错误"}`),null)}catch(Ie){return st.error(Ie instanceof Error?Ie.message:String(Ie)),null}}function ie(Se){var Ie;const Te=j==null?void 0:j[Se];z(Se),H((Te==null?void 0:Te.command)??((Ie=Te==null?void 0:Te.suggestions)==null?void 0:Ie[0])??"")}async function se(){if(!A)return;const Se=R.trim();if(!Se){st.error("请输入 Agent CLI 路径");return}const Te=Ot;if(!Te){st.error("请先连接开发机");return}q(!0);try{const Ie=await Te.updateAgentCliPath(A,Se);if(Ie.error||!Ie.agentCli){st.error(`路径保存失败:${Ie.error??"未知错误"}`);return}Ei.getState().setAgentCli(Ie.agentCli),st.success(`${na[A]} 路径已保存`),z(null),H("")}catch(Ie){st.error(Ie instanceof Error?Ie.message:String(Ie))}finally{q(!1)}}function te(Se){d(Se),G(o)}function ue(Se){var Ie;const Te=Se.relatedTarget;Te instanceof Node&&((Ie=U.current)!=null&&Ie.contains(Te))||window.setTimeout(()=>T(!1),0)}const ge=y?v.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[v.jsx(kB,{providerLabel:na[o]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:b,children:"返回"}),v.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?"创建中...":"确认"})]})]}):v.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Se=>{Se.preventDefault(),Y()},children:[v.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[v.jsx("span",{className:"text-sm",children:"名称(可选)"}),v.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Se=>r(Se.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:"自动生成"})]}),v.jsxs("div",{ref:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:ue,children:[v.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),v.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:Se=>{s(Se.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?v.jsx(AB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ne,onSelect:Se=>{s(Se),E(null),T(!0)}}):null]}),x?v.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[v.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),v.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:x})]}):null,v.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"交互方式"}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>te("pty"),className:qe("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),v.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>te("json"),className:qe("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),v.jsx(vie,{agentCli:j,provider:o,isDesktop:L,editingCliProvider:A,cliPathInput:R,savingCliPath:P,onProviderChange:Se=>{l(Se),G(Se)},onOpenCliPathEditor:ie,onCliPathInputChange:H,onCancelCliPathEditor:()=>{z(null),H("")},onSaveCliPath:()=>void se()}),v.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"权限模式"}),v.jsxs(Jre,{value:h,onValueChange:Se=>p(Se),children:[v.jsx(tie,{className:"w-full",children:v.jsx(eie,{})}),v.jsx(nie,{children:F.map(Se=>v.jsx(rie,{value:Se.value,children:Se.label},Se.value))})]})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:b,children:"取消"}),v.jsx(St,{type:"submit",className:"min-h-11 md:min-h-0",disabled:W,children:b?"创建中...":"创建"})]})]});return L?v.jsx(Sc,{open:e,onOpenChange:t,children:v.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:[v.jsx(Ec,{children:v.jsx(dl,{children:y?"跳过全部审批?":"新建会话"})}),ge]})}):v.jsx(Vv,{open:e,onOpenChange:t,children:v.jsxs(Yv,{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:[v.jsx(T1,{className:"px-0 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:y?"跳过全部审批?":"新建会话"})}),ge]})})}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(g){g.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 v.jsx(Sc,{open:e,onOpenChange:r,children:v.jsx(xc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:v.jsxs("form",{className:"grid gap-4",onSubmit:g=>void y(g),children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"重命名会话"}),v.jsx(dc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),v.jsxs("div",{className:"grid gap-2",children:[v.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),v.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:qe("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:g=>{l(g.target.value),u&&d(null)}}),u?v.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),v.jsx(St,{type:"submit",disabled:h,children:"保存"})]})]})})})}function bie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function wie(e){return(e==null?void 0:e.kind)==="terminal"}function Sie(e){return bie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:wie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function zm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Sie(t);function s(){t&&(r(t),n(!1))}return v.jsx(Sc,{open:e,onOpenChange:n,children:v.jsxs(xc,{"data-slot":"session-termination-dialog",children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:i.title}),v.jsx(dc,{children:i.description})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),v.jsx(St,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function MB(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 xie(e){if(e.session.state==="error")return"error";const t=MB(e);return t==="disconnected"?e.session.state:t}function OB({layout:e}){const t=Wt(N=>N.sessions),n=Wt(N=>N.sessionListLoaded),r=Wt(N=>N.agentStatusBySessionId),i=Wt(N=>N.ptyStateBySessionId),s=Wt(N=>N.renameSession),o=Zt(N=>N.bySessionId),l=nU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Be(N=>!!N.selectedProxyId),p=!Be(N=>N.proxyListLoaded)||d&&!n,y=Js(),[g,b]=_.useState(!1),[w,x]=_.useState(!1),[E,k]=_.useState(null),[T,A]=_.useState(null),{creatingTerminal:z,createTerminal:R}=DB(),[H,P]=_.useState(new Set),[q,U]=_.useState(()=>Date.now());_.useEffect(()=>{const N=setInterval(()=>U(Date.now()),6e4);return()=>clearInterval(N)},[]);function $(N,W){y(`/chat/${N}?mode=${W??"json"}`,{replace:!1})}function D(N){const W=N.sessionId,G=Ot;if(!G){st.error("请先连接开发机");return}G.sendControl({type:"session_terminate",sessionId:W}),Wt.getState().removeSession(W),Zt.getState().clearSession(W),W===u&&y("/sessions"),(N==null?void 0:N.mode)==="pty"&&N.ptyOwner==="local-terminal"?st.info("已断开页面连接,本地终端仍在运行"):st.info("正在终止会话",{duration:1500})}async function M(N,W){const G=Ot;if(!G)throw new Error("请先连接开发机");const I=await G.renameSession(N,W);if(!I.success)throw new Error(I.error??"重命名失败");s(N,I.name??W),st.success("已重命名会话")}function j(N){P(W=>{const G=new Set(W);return G.has(N)?G.delete(N):G.add(N),G})}function L(N){var I;const W=N.mode==="json"&&(((I=o[N.sessionId])==null?void 0:I.pendingApprovals.some(ne=>ne.status==="pending"))??!1),G=xie({session:N,agentStatus:r[N.sessionId],ptyState:i[N.sessionId],hasPendingApproval:W});return G===N.state?N:{...N,state:G}}const O=t.length>0;if(e==="sidebar"&&(p||!d))return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70",children:p?"连接中...":"请先连接开发机"}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]});if(e==="page"&&p)return v.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:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});if(e==="page"&&!d)return v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsx("div",{className:"flex-1",children:v.jsx(nc,{variant:"no-proxy"})}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]});const Y=v.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",O?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=O?v.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:Eie(t).map(N=>v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>j(N.provider),"aria-expanded":!H.has(N.provider),className:qe("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:Cie(N.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:N.sessions.length}),v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!H.has(N.provider)&&"rotate-90"),"aria-hidden":"true"})]}),H.has(N.provider)?null:v.jsx("ul",{role:"list",className:"flex flex-col",children:N.sessions.map(W=>v.jsx(Wre,{session:L(W),selected:W.sessionId===u,now:q,onClick:()=>$(W.sessionId,W.mode),onRename:()=>k(W),onTerminate:()=>A(W)},W.sessionId))})]},N.provider))}):v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),F=v.jsx(Xre,{now:q});return e==="page"?v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:v.jsxs(St,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>x(!0),children:[v.jsx(bP,{"aria-hidden":"true"}),"新建"]})}),v.jsx(Tie,{open:w,creatingTerminal:z,onOpenChange:x,onCreateAgent:()=>{x(!1),b(!0)},onCreateTerminal:()=>void R(()=>x(!1))}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]}):v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]})}function Eie(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])=>kie(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Cie(e){return e==="terminal"?"终端":Gv(e)}function kie(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:EB(e,t)}function DB(){const e=Js(),[t,n]=_.useState(!1);async function r(i){if(!t){n(!0);try{const s=await gie({relay:Ot});if(s.type!=="success"){st.error(s.message);return}Wt.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function jN({compact:e=!1}){const[t,n]=_.useState(!1),[r,i]=_.useState(!1),s=_.useRef(!1),o=Be(w=>!!w.selectedProxyId),{creatingTerminal:l,createTerminal:u}=DB();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 g=v.jsxs(St,{variant:"outline","data-slot":"create-session-trigger",className:qe(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!o&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!o,onClick:o?void 0:y,children:[v.jsx(bP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate",children:"新建"})]}),b=o?v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:g}),v.jsxs(N1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:w=>{s.current&&(s.current=!1,w.preventDefault())},children:[v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:h,children:[v.jsx(_P,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:l,onSelect:p,children:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),l?"正在创建终端会话...":"终端会话"]})]})]}):g;return v.jsxs(v.Fragment,{children:[o?b:v.jsxs(Hf,{open:o?void 0:r,onOpenChange:o?void 0:i,children:[v.jsx(Uf,{asChild:!0,children:b}),v.jsx(Wf,{side:"top",children:o?"新建会话":"请先连接开发机"})]}),v.jsx(Ih,{open:t,onOpenChange:n})]})}function Tie({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=_.useRef(!1);function o(l){s.current=!0,l()}return v.jsx(Vv,{open:e,onOpenChange:n,children:v.jsxs(Yv,{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:[v.jsx(T1,{className:"px-1 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:"新建"})}),v.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[v.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:[v.jsx(_P,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.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:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Rie="0.5.3",Aie={version:Rie},Nie={playback:"playback",capture:"play-and-record"};function Mie(){return typeof navigator>"u"?null:navigator.audioSession??null}function Oie(){return{setMode:()=>{},release:()=>{}}}class Die{constructor(t=Mie){vt(this,"leases",new Map);vt(this,"session",null);vt(this,"baselineType",null);vt(this,"nextLeaseId",1);vt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Oie();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(Nie[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 O1=new Die,$0=64,FN=-60,PB=32;function $N(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-FN)/-FN));return e<0?-r:r}function HN(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 Pie(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 Lie(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 LB{constructor(t,n=24e3,r={}){vt(this,"nextStartTime",0);vt(this,"activityEndToken",0);vt(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=Pie(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*PB/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=Lie(n.subarray(l,u));this.scheduleTimer(()=>{var g,b,w,x;(b=(g=this.options).onActivityLevel)==null||b.call(g,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 Zb={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},UN="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",Iie=800,WN=300,zie=1600;function H0(e,t){return e.filter(n=>!n.model||n.model===t)}function qN({label:e,children:t,help:n}){return v.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:[v.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.jsx("div",{className:"mt-2 min-w-0",children:t}),n?v.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Bm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=_.useState(!1),u=_.useId(),d=n.find(g=>g.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(g=>!g.disabled),y=!!IB(h).detail;return v.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:g=>{g.currentTarget.contains(g.relatedTarget)||l(!1)},children:[v.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.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(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[v.jsx(VN,{label:h,muted:!d&&!t}),v.jsx(gl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?v.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(g=>{const b=g.value===t;return v.jsxs("button",{type:"button",role:"option","aria-label":g.label,"aria-selected":b,disabled:g.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:()=>{g.disabled||(r(g.value),l(!1))},children:[v.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:b?v.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),v.jsx(VN,{label:g.label})]},g.value)})}):null,s?v.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function VN({label:e,muted:t=!1}){const n=IB(e);return v.jsxs("span",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?v.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Bie({scrollRef:e}={}){const[t,n]=_.useState(Zb),[r,i]=_.useState(String(Zb.turnIdleSeconds)),[s,o]=_.useState(()=>Cm()),[l,u]=_.useState(""),[d,h]=_.useState(!1),[p,y]=_.useState(!1),[g,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(ue=>{if(!te){if(ue.error||!ue.config){b({kind:"error",message:ue.error??"读取语音设置失败"});return}n(ue.config),i(String(ue.config.turnIdleSeconds)),u(""),h(!1),y(!0),b({kind:"idle"})}}).catch(ue=>{te||b({kind:"error",message:ue instanceof Error?ue.message:"读取语音设置失败"})}),()=>{te=!0}},[]),_.useEffect(()=>{const se=Ot;if(!se||!p)return;let te=!1;return se.requestVoiceCapabilities({region:t.region}).then(ue=>{if(!te){if(ue.error||!ue.capabilities){o(Cm());return}o(ue.capabilities)}}).catch(()=>{te||o(Cm())}),()=>{te=!0}},[t.region,p]),_.useEffect(()=>()=>{G(),I()},[]);const A=_.useMemo(()=>g.kind==="loading"?"读取中...":g.kind==="saving"?"保存中...":g.kind==="testing"?"正在测试语音合成":g.kind==="playingTest"?"正在播放测试音频":g.kind==="testPassed"?"测试通过":g.kind==="saved"?"已保存":g.kind==="error"?g.message:null,[g]),z=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",R=_.useMemo(()=>H0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=R.some(se=>se.value===t.ttsVoice)?t.ttsVoice:"",q=R.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",U=_.useMemo(()=>Hie(r),[r]),$=U?null:"请输入正整数秒数",D=q??$,M=z||!!D,j=_.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=_.useMemo(()=>GN(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),O=_.useMemo(()=>Uie(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),Y=_.useMemo(()=>GN(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:U??Zb.turnIdleSeconds}}async function F(){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 ue=performance.now();try{const ge=await se.updateVoiceConfig(te),Se=performance.now()-ue;if(Se<WN&&await $ie(WN-Se),!ge.success||ge.error||!ge.config){b({kind:"error",message:ge.error??"保存语音设置失败"});return}n(ge.config),i(String(ge.config.turnIdleSeconds)),u(""),h(!1),b({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,b(Te=>Te.kind==="saved"?{kind:"idle"}:Te)},zie),se.requestVoiceCapabilities({region:ge.config.region}).then(Te=>{Te.capabilities&&o(Te.capabilities)}).catch(()=>{o(Cm())})}catch(ge){b({kind:"error",message:ge instanceof Error?ge.message:"保存语音设置失败"})}}async function N(){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(ue){b({kind:"error",message:KN(ue)});return}b({kind:"testing"});try{const[ue]=await Promise.all([se.testVoiceConfig(K()),te.ready]);if(!ue.success||ue.error){G(),b({kind:"error",message:ue.error??"语音配置测试失败"});return}const ge=await ne(ue,te.context);b({kind:"playingTest",transcript:ue.transcript}),k.current=setTimeout(()=>{k.current=null,G(),b({kind:"testPassed",transcript:ue.transcript})},ge)}catch(ue){G(),b({kind:"error",message:KN(ue)})}}function W(){G();const se=O1.acquire("playback");x.current=se;try{const te=Fie();return w.current=te,{context:te,ready:YN(te)}}catch(te){throw se.release(),x.current=null,te}}function G(){var se,te,ue;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,(ue=x.current)==null||ue.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 ue=se.audioSampleRate??24e3,ge=jie(se.audioBase64);if(ge.byteLength===0||ge.byteLength%2!==0)throw new Error("测试音频数据无效");await YN(te);const Se=new LB(te,ue);E.current=Se,Se.enqueue(ge);const Te=Math.ceil(ge.byteLength/2/ue*1e3);return Math.max(Iie,Te)}function ie(se){var te;return((te=H0(s.ttsVoices,se)[0])==null?void 0:te.value)??""}return v.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(),F()},children:[v.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:v.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:v.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[v.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsxs("div",{className:"min-w-0",children:[v.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),v.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),v.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"})]})}),v.jsx(qN,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:v.jsxs("div",{className:"flex min-w-0 gap-2",children:[v.jsxs("div",{className:"relative min-w-0 flex-1",children:[v.jsx(xP,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),v.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:`${UN} w-full pl-9`})]}),t.configured&&v.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:[v.jsx(X8,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),v.jsx(Bm,{label:"地域",value:t.region,options:j,onChange:se=>n(te=>({...te,region:se==="intl"?"intl":"cn"}))}),v.jsx(Bm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:se=>n(te=>({...te,asrModel:se}))}),v.jsx(Bm,{label:"语音合成模型",value:t.ttsModel,options:O,onChange:se=>n(te=>({...te,ttsModel:se,ttsVoice:ie(se)}))}),v.jsx(Bm,{label:"语音音色",value:P,options:Y,placeholder:R.length===0?"暂无可用音色":"请选择音色",onChange:se=>n(te=>({...te,ttsVoice:se})),help:q}),v.jsx(qN,{label:"结束停顿时间(秒)",help:$,children:v.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:se=>i(se.target.value),className:`${UN} w-full`})})]})})}),v.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[v.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),v.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[A?v.jsx("div",{role:g.kind==="error"?"alert":"status","aria-live":"polite",className:g.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:A}):null,v.jsxs(St,{type:"button",variant:"outline",disabled:M,onClick:()=>void N(),children:[v.jsx(kP,{className:"size-4","aria-hidden":"true"}),"测试"]}),v.jsxs(St,{type:"submit",disabled:M,children:[v.jsx(z8,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function jie(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 Fie(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function YN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function KN(e){return e instanceof Error?e.message:"语音配置测试失败"}function $ie(e){return new Promise(t=>setTimeout(t,e))}function Hie(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function GN(e,t){const n=e.map(r=>({value:r.value,label:zB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Uie(e,t,n){const r=e.map(i=>{const s=H0(t,i.value).length===0;return{value:i.value,label:`${zB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function IB(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 zB(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 Wie=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],qie=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],D1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function BB(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 Vie(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Yie(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Kie(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function U0({open:e,onOpenChange:t}){const n=Be(q=>q.relayUrl),r=Be(q=>q.latencyMonitorEnabled),i=Be(q=>q.setLatencyMonitorEnabled),s=Be(q=>q.sessionIdleNotificationsEnabled),o=Be(q=>q.setSessionIdleNotificationsEnabled),l=Be(q=>q.inputModePreference),u=Be(q=>q.setInputModePreference),d=Be(q=>q.themePreference),h=Be(q=>q.setThemePreference),p=Be(q=>q.ptyScrollTraceEnabled),y=Be(q=>q.setPtyScrollTraceEnabled),[g,b]=_.useState("menu"),[w,x]=_.useState({kind:"idle"}),E=_.useRef(null),k=_.useRef(null),T=UZ(),A=_.useMemo(()=>Wx().osName==="iPad",[]),z=_.useCallback(async q=>{if(!q){o(!1);return}const U=await yZ();if(U==="granted"){o(!0);return}if(U==="denied"){st.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){st.info("未授予通知权限,会话通知保持关闭");return}st.error("当前浏览器不支持系统通知")},[o]),R=_.useCallback(async q=>{x({kind:"loading"});try{const U=await fetch(Vie(n),{cache:"no-store",signal:q});if(!U.ok)throw new Error(`HTTP ${U.status}`);const $=await U.json();if($.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:$.version??"未知",uptime:$.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;x({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);_.useEffect(()=>{if(!e){b("menu");return}},[e]),_.useEffect(()=>{if(!e||g!=="version")return;const q=new AbortController;return R(q.signal),()=>q.abort()},[R,e,g]),_.useEffect(()=>{if(!e||g!=="voice")return;const q=window.requestAnimationFrame(()=>{var U;(U=E.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(q)},[e,g]);const H=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${BB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return v.jsx(Sc,{open:e,onOpenChange:t,children:v.jsxs(xc,{className:qe("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="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":g,focusSurfaceOnOpen:!0,ref:E,showCloseButton:g==="menu",children:[v.jsx(Ec,{className:qe(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"flex items-start gap-2",children:[v.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:v.jsx(vv,{className:"size-4","aria-hidden":"true"})}),v.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[v.jsx(dl,{children:Yie(g)}),v.jsx(dc,{className:"max-w-[28rem] leading-5",children:Kie(g)})]})]}),g==="voice"?v.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):v.jsxs(v.Fragment,{children:[v.jsx(dl,{children:"设置"}),v.jsx(dc,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?v.jsx(Gie,{relayVersion:H,relayDetail:P,relayMuted:w.kind==="error"}):g==="relay-token"?v.jsx(Zie,{saved:T}):g==="clients"?v.jsx(nse,{}):g==="voice"?v.jsx(Bie,{scrollRef:k}):v.jsx(Xie,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,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 Gie({relayVersion:e,relayDetail:t,relayMuted:n}){return v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsx(ZN,{icon:v.jsx(CP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Aie.version,detail:"当前浏览器加载的版本"}),v.jsx(ZN,{icon:v.jsx(TP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Xie({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:g,onOpenClients:b,onOpenVersion:w}){return v.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:[v.jsxs(cu,{title:"服务",children:[v.jsx(jm,{icon:v.jsx(N9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),v.jsx(jm,{icon:v.jsx(xP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),v.jsx(jm,{icon:v.jsx(r7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:b})]}),v.jsx(cu,{title:"外观",children:v.jsx(XN,{icon:v.jsx(Y8,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Wie,onValueChange:n})}),v.jsx(cu,{title:"通知",children:v.jsx(Jb,{icon:v.jsx(O9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?v.jsx(cu,{title:"交互",children:v.jsx(XN,{icon:v.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:qie,onValueChange:i})}):null,v.jsxs(cu,{title:"高级诊断",children:[v.jsx(Jb,{icon:v.jsx(of,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),v.jsx(Jb,{icon:v.jsx(vP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),v.jsx(cu,{title:"关于",children:v.jsx(jm,{icon:v.jsx(TP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({title:e,children:t}){return v.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[v.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),v.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function XN({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=_.useId(),l=_.useId();return v.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[v.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,v.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 v.jsx("button",{type:"button",role:"radio","aria-checked":d,className:qe("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Zie({saved:e}){const t=_.useId(),n=_.useId(),[r,i]=_.useState(""),[s,o]=_.useState(null),l=()=>{UL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}$L(h),l()},d=()=>{HL(),l()};return v.jsxs("form",{className:D1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[v.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[v.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),v.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?v.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),v.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?v.jsx(St,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,v.jsx(St,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Qie(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Jie(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Qie(e)}function ese(e){return lX(e)}function tse(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return BB(t)}function Qb({label:e,value:t,title:n}){return v.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[v.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),v.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function nse(){const e=Be(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(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);_.useEffect(()=>{h()},[h]);const p=_.useCallback(async y=>{const g=Ot;if(!g){o("Relay 未连接。");return}u(y),o(null);try{const b=await g.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 v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:v.jsx(Tx,{className:qe("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?v.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?v.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 g=y.current===!0,b=l===y.clientId;return v.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:v.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[v.jsxs("div",{className:"min-w-0 space-y-1.5",children:[v.jsx("div",{className:"min-w-0",children:v.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:ese(y)})}),v.jsxs("div",{className:"space-y-1",children:[v.jsx(Qb,{label:"已连接",value:tse(y.connectedAt)}),y.proxyId?v.jsx(Qb,{label:"连接到",value:Jie(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?v.jsx(Qb,{label:"来源 IP",value:y.remoteAddress}):null]})]}),g?v.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:"当前设备"}):v.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:[v.jsx(f8,{className:"size-3.5","aria-hidden":"true"}),b?"断开中...":"断开"]})]})},y.clientId)})]})}function Jb({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=_.useId(),o=_.useId();return v.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:[v.jsx("div",{className:qe("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),v.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),v.jsx("span",{className:qe("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:v.jsx("span",{className:qe("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function jm({icon:e,label:t,detail:n,onClick:r}){const i=_.useId(),s=_.useId();return v.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:[v.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}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),v.jsx(Kh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function ZN({icon:e,label:t,value:n,detail:r,muted:i=!1}){return v.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[v.jsx("div",{className:qe("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[v.jsx("div",{className:"text-sm text-muted-foreground",children:t}),v.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const rse="xterm-helper-textarea";function ise(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(rse)?!1:(e.blur(),!0)}function QN(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&&sse(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function sse(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 ose({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=_.useRef(null),r=_.useCallback(()=>{e&&ise()},[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,QN(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=_.useCallback(l=>{r(),t&&(QN(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function ase({className:e}){const t=Be(o=>o.sidebarCollapsed),n=Be(o=>o.toggleSidebarCollapsed),[r,i]=_.useState(!1),s=ose();return t?v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:qe("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[v.jsx(eM,{collapsed:!0,onClick:n}),v.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),v.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[v.jsx(JN,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),v.jsx(jN,{compact:!0})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]}):v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:qe("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[v.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:v.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx(VP,{className:"text-[13px]",slot:"sidebar-brand"}),v.jsx(eM,{collapsed:!1,onClick:n})]}),v.jsx("div",{className:"mt-2.5",children:v.jsx(xB,{layout:"dropdown",variant:"sidebarChrome"})})]})}),v.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:v.jsx("div",{className:"flex-1 min-h-0",children:v.jsx(OB,{layout:"sidebar"})})}),v.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:[v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(jN,{})}),v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(JN,{onClick:()=>i(!0)})})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]})}function JN({compact:e=!1,tooltipSide:t="top",onClick:n}){return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:qe("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[v.jsx(RP,{className:"size-4","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),v.jsx(Wf,{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 eM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?x8:w8;return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:qe("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:v.jsx(r,{className:qe("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),v.jsx(Wf,{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 lse=1500,cse=300,tM=70,nM=35;function jB({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 g=h();l.current<g.length?(l.current+=1,r(g.slice(0,l.current)),d=setTimeout(p,tM)):(o.current="paused",d=setTimeout(p,lse))}else y==="paused"?(o.current="deleting",d=setTimeout(p,nM)):y==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),d=setTimeout(p,nM)):(u.current+=1,o.current="waiting",d=setTimeout(p,cse)):(o.current="typing",d=setTimeout(p,tM))};return d=setTimeout(p,500),()=>clearTimeout(d)},[e]),v.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[v.jsx("span",{className:"text-green-500",children:"> "}),v.jsx("span",{className:"text-foreground/90",children:n}),v.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const FB=["DEV Anywhere","/unlimited @anytime"];function use({subtitle:e,action:t}){return v.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:v.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[v.jsx(jB,{texts:FB,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),v.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?v.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const dse=3e3,hse=1e4,Fm=12,fse=4,rM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},pse={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function ew(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 iM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function $B(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function mse(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 gse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Bh(e.rttMs):"等待检测"}function vse(){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 sM(e){dr("local",ln.latencyMonitorPosition,JSON.stringify(e))}function yse(){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 tw(e,t){const n=yse(),r=Fm,i=Fm,s=Math.max(r,n.width-t.width-Fm),o=Math.max(i,n.height-t.height-Fm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function _se(){const e=Be(R=>R.latencyMonitorEnabled),t=Be(R=>R.connected),n=Be(R=>R.proxyOnline),r=Be(R=>R.selectedProxyId),[i,s]=_.useState(pse),[o,l]=_.useState(()=>vse()),u=_.useRef(!1),d=_.useRef(null),h=_.useRef(null),p=_.useRef(!1),y=_.useMemo(()=>(Object.values(i).sort((R,H)=>iM(H.state)-iM(R.state))[0]??{state:"idle"}).state,[i]),g=$B(y);async function b(){if(u.current)return;const R=Ot;if(!R||!t){const U=uu("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:uu("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:uu("未连接开发机")}));const[H,P,q]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:H.status==="fulfilled"?ew(H.value):uu(H.reason instanceof Error?H.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?ew(P.value):uu(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:q.status==="fulfilled"?ew(q.value):uu(q.reason instanceof Error?q.reason.message:"测速失败")}),u.current=!1}if(_.useEffect(()=>{if(!e)return;let R=!1,H=null;const P=async()=>{await b(),!R&&(H=setTimeout(P,document.hidden?hse:dse))};return P(),()=>{R=!0,u.current=!1,H&&clearTimeout(H)}},[e,t,n,r]),_.useEffect(()=>{if(!e||!o)return;const R=d.current;if(!R)return;const H=R.getBoundingClientRect(),P=tw(o,{width:H.width,height:H.height});P.x===o.x&&P.y===o.y||(l(P),sM(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 H=R.currentTarget.getBoundingClientRect();h.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,originX:H.left,originY:H.top,width:H.width,height:H.height,dragging:!1},(q=(P=R.currentTarget).setPointerCapture)==null||q.call(P,R.pointerId)}function k(R){const H=h.current;if(!H||H.pointerId!==R.pointerId)return;const P=R.clientX-H.startX,q=R.clientY-H.startY;if(!H.dragging&&Math.hypot(P,q)<fse)return;H.dragging=!0,R.preventDefault();const U=tw({x:H.originX+P,y:H.originY+q},{width:H.width,height:H.height});l(U)}function T(R){var $,D;const H=h.current;if(!H||H.pointerId!==R.pointerId||(h.current=null,(D=($=R.currentTarget).releasePointerCapture)==null||D.call($,R.pointerId),!H.dragging))return;R.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=R.clientX-H.startX,q=R.clientY-H.startY,U=tw({x:H.originX+P,y:H.originY+q},{width:H.width,height:H.height});l(U),sM(U)}function A(R){var P,q;const H=h.current;!H||H.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 v.jsxs(E1,{children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{ref:d,type:"button",className:qe("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",mse(g)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Bh(i.webRelay.rttMs)},开发机 ${Bh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:T,onPointerCancel:A,onClickCapture:z,children:[v.jsx(vP,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),v.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",Bh(i.webRelay.rttMs)]}),v.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Bh(w.rttMs)]}),v.jsx(gl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),v.jsxs(k1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[v.jsxs("div",{className:"flex items-start justify-between gap-3",children:[v.jsxs("div",{children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void b(),children:v.jsx(Tx,{className:"size-3","aria-hidden":"true"})})]}),v.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(rM).map(R=>v.jsx(bse,{label:rM[R],measurement:i[R]},R))})]})]})}function bse({label:e,measurement:t}){const n=$B(t.state);return v.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:[v.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx("span",{className:qe("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),v.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:gse(t)})]})]})}const HB="/__dev_anywhere_debug/browser-state-dumps",wse=1500,Sse=10,nw=80,P1=500,xse=["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"],Ese=["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 oM(){if(typeof window>"u")return"off";const e=XB("debugDump");return e==="auto"?"auto":e!==null||Dse("debugInput")?"manual":"off"}function Cse(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:Ase(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:aM(document.activeElement),selection:Nse(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>aM(i)).filter(i=>!!i),root:UB(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(()=>lM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>lM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function kse(e="manual"){const t=Cse(e);return Tse(t)}async function Tse(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Rse(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:HB}}catch(r){const i=ZB(r),s=Mse(e.createdAt);return Ose(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Rse(e){const t=await fetch(HB,{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 UB(e,t,n){if(n.count>=wse||t>Sse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=cM(e.textContent??"");return u?{kind:"text",text:Xv(u,P1)}:{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,nw))u.nodeType===Node.TEXT_NODE&&!cM(u.textContent??"")||r.push(UB(u,t+1,n));s.length>nw&&(i=s.length-nw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:GB(e),attrs:WB(e),rect:qB(e),scroll:VB(e),style:YB(e)},l=KB(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function aM(e){if(!(e instanceof HTMLElement))return null;const t=KB(e);return{path:GB(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:WB(e),rect:qB(e),scroll:VB(e),style:YB(e),...t?{value:t}:{}}}function Ase(){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 WB(e){const t={};for(const n of xse){const r=e.getAttribute(n);r!==null&&(t[n]=Xv(r,500))}return t}function qB(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 VB(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 YB(e){const t=window.getComputedStyle(e),n={};for(const r of Ese)n[r]=t.getPropertyValue(r);return n}function KB(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Xv(e.value,P1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Nse(){var e;try{return Xv(((e=window.getSelection())==null?void 0:e.toString())??"",P1)}catch{return null}}function GB(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 Mse(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Ose(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 Dse(e){return XB(e)!==null}function XB(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 lM(e){return e?Gg(e.slice(-200)):null}function du(e){try{return Gg(e())}catch(t){return{error:ZB(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 cM(e){return e.replace(/\s+/g," ").trim()}function Xv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Zi(e){return Math.round(e*100)/100}function ZB(e){return e instanceof Error?e.message:String(e)}const Pse=500,Lse=1e3,Ise=60;function zse(){const[e,t]=_.useState(()=>oM()),[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(oM());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 kse(b);return o.current=w,s(w),(b==="manual"||w.status==="failed")&&Bse(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=A=>{d.current>=Ise||(b(),h.current=window.setTimeout(()=>{h.current=null;const z=Date.now(),R=Lse-(z-u.current);if(R>0){h.current=window.setTimeout(()=>w(A),R);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${A}`)},Pse))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=A=>w(A.type);return x.forEach(A=>window.addEventListener(A,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(T=window.visualViewport)==null||T.addEventListener("scroll",E),()=>{var A,z;b(),x.forEach(R=>window.removeEventListener(R,E,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",E),(z=window.visualViewport)==null||z.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",g=jse(i);return v.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:[g?v.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:g}):null,v.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?v.jsx(Lu,{className:"size-3.5 animate-spin","aria-hidden":"true"}):v.jsx(r8,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{children:y})]})]})}function Bse(e){if(e.status==="saved"){st.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){st.info(`诊断已下载: ${e.filename}`);return}st.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function jse(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Fse(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 L1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:Fse(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 g=h.indexOf(y);g>=0&&g!==h.length-1&&(h.splice(g,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 QB(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 $se="dev_anywhere_pty_input_latency_trace",uM=80,Hse=1e4,Use=new TextDecoder;let Wse=0;const Ku=new Map,Cc=L1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:$se,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function qse(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Gse)}function Vse(e,t){if(!Cc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Wse}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Qse(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),z1(s,r),Ku.set(e,s),qf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function dM(e,t){if(!e||!Cc.isEnabled())return;const n=performance.now(),r=Xse(e.sessionId,e.inputId);r&&(r.sentAt=n),qf({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 Yse(e,t,n){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=toe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&eoe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));qf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:noe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Kse(e,t,n=1){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));qf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Zse(e,s))}function Gse(){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},wJ="DialogDescriptionWarning",SJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${wI(wJ).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},e1=aI,xJ=cI,t1=dI,n1=hI,r1=fI,SI=mI,xI=vI,i1=_I;function EJ(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 CJ(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 kJ=["top","right","bottom","left"],cl=Math.min,hs=Math.max,$g=Math.round,Lm=Math.floor,Eo=e=>({x:e,y:e}),TJ={left:"right",right:"left",bottom:"top",top:"bottom"};function C0(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 s1(e){return e==="x"?"y":"x"}function o1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function a1(e){return s1(So(e))}function RJ(e,t,n){n===void 0&&(n=!1);const r=sd(e),i=a1(e),s=o1(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 AJ(e){const t=Hg(e);return[k0(e),t,k0(t)]}function k0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gN=["left","right"],vN=["right","left"],NJ=["top","bottom"],MJ=["bottom","top"];function OJ(e,t,n){switch(e){case"top":case"bottom":return n?t?vN:gN:t?gN:vN;case"left":case"right":return t?NJ:MJ;default:return[]}}function DJ(e,t,n,r){const i=sd(e);let s=OJ(oa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(k0)))),s}function Hg(e){const t=oa(e);return TJ[t]+e.slice(t.length)}function PJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function EI(e){return typeof e!="number"?PJ(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 yN(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=a1(t),l=o1(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 g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:p};break;case"left":g={x:r.x-i.width,y:p};break;default:g={x:r.x,y:r.y}}switch(sd(t)){case"start":g[o]-=y*(n&&d?-1:1);break;case"end":g[o]+=y*(n&&d?-1:1);break}return g}async function LJ(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:g=0}=sa(t,e),b=EI(g),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)),A=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)/A.y,bottom:(z.bottom-E.bottom+b.bottom)/A.y,left:(E.left-z.left+b.left)/A.x,right:(z.right-E.right+b.right)/A.x}}const IJ=50,zJ=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:LJ},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}=yN(d,r,u),y=r,g=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:A,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=A??p,b[E]={...b[E],...z},R&&g<IJ&&(g++,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}=yN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:b}},BJ=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=EI(h),y={x:n,y:r},g=a1(i),b=o1(g),w=await o.getDimensions(d),x=g==="y",E=x?"top":"left",k=x?"bottom":"right",T=x?"clientHeight":"clientWidth",A=s.reference[b]+s.reference[g]-y[g]-s.floating[b],z=y[g]-s.reference[g],R=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let H=R?R[T]:0;(!H||!await(o.isElement==null?void 0:o.isElement(R)))&&(H=l.floating[T]||s.floating[b]);const P=A/2-z/2,q=H/2-w[b]/2-1,U=cl(p[E],q),$=cl(p[k],q),D=U,M=H-w[b]-$,j=H/2-w[b]/2+P,L=C0(D,j,M),O=!u.arrow&&sd(i)!=null&&j!==L&&s.reference[b]/2-(j<D?U:$)-w[b]/2<0,Y=O?j<D?j-D:j-M:0;return{[g]:y[g]+Y,data:{[g]:L,centerOffset:j-L-Y,...O&&{alignmentOffset:Y}},reset:O}}}),jJ=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:g="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,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),z=y||(T||!w?[Hg(l)]:AJ(l)),R=b!=="none";!y&&R&&z.push(...DJ(l,w,b,A));const H=[l,...z],P=await u.detectOverflow(t,x),q=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&q.push(P[E]),p){const j=RJ(i,o,A);q.push(P[j[0]],P[j[1]])}if(U=[...U,{placement:i,overflows:q}],!q.every(j=>j<=0)){var $,D;const j=((($=s.flip)==null?void 0:$.index)||0)+1,L=H[j];if(L&&(!(p==="alignment"?k!==So(L):!1)||U.every(K=>So(K.placement)===k?K.overflows[0]>0:!0)))return{data:{index:j,overflows:U},reset:{placement:L}};let O=(D=U.filter(Y=>Y.overflows[0]<=0).sort((Y,K)=>Y.overflows[1]-K.overflows[1])[0])==null?void 0:D.placement;if(!O)switch(g){case"bestFit":{var M;const Y=(M=U.filter(K=>{if(R){const F=So(K.placement);return F===k||F==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(F=>F>0).reduce((F,N)=>F+N,0)]).sort((K,F)=>K[1]-F[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 _N(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function bN(e){return kJ.some(t=>e[t]>=0)}const FJ=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=_N(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:bN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=_N(o,n.floating);return{data:{escapedOffsets:l,escaped:bN(l)}}}default:return{}}}}},CI=new Set(["left","top"]);async function $J(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=CI.has(o)?-1:1,h=s&&u?-1:1,p=sa(t,e);let{mainAxis:y,crossAxis:g,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"&&(g=l==="end"?b*-1:b),u?{x:g*h,y:y*d}:{x:y*d,y:g*h}}const HJ=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 $J(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}}}}},UJ=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)),g=s1(y);let b=h[g],w=h[y];if(o){const E=g==="y"?"top":"left",k=g==="y"?"bottom":"right",T=b+p[E],A=b-p[k];b=C0(T,b,A)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[E],A=w-p[k];w=C0(T,w,A)}const x=u.fn({...t,[g]:b,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[g]:o,[y]:l}}}}}},WJ=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=s1(p);let g=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",A=s.reference[y]-s.floating[T]+x.mainAxis,z=s.reference[y]+s.reference[T]-x.mainAxis;g<A?g=A:g>z&&(g=z)}if(d){var E,k;const T=y==="y"?"width":"height",A=CI.has(oa(i)),z=s.reference[p]-s.floating[T]+(A&&((E=o.offset)==null?void 0:E[p])||0)+(A?0:x.crossAxis),R=s.reference[p]+s.reference[T]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?x.crossAxis:0);b<z?b=z:b>R&&(b=R)}return{[y]:g,[p]:b}}}},qJ=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),g=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,A=cl(w-h[x],k),z=cl(b-h[E],T),R=!t.middlewareData.shift;let H=A,P=z;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(H=k),R&&!y){const U=hs(h.left,0),$=hs(h.right,0),D=hs(h.top,0),M=hs(h.bottom,0);g?P=b-2*(U!==0||$!==0?U+$:hs(h.left,h.right)):H=w-2*(D!==0||M!==0?D+M:hs(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:H});const q=await o.getDimensions(l.floating);return b!==q.width||w!==q.height?{reset:{rects:!0}}:{}}}};function Nv(){return typeof window<"u"}function od(e){return kI(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=(kI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function kI(e){return Nv()?e instanceof Node||e instanceof fs(e).Node:!1}function Xs(e){return Nv()?e instanceof Element||e instanceof fs(e).Element:!1}function la(e){return Nv()?e instanceof HTMLElement||e instanceof fs(e).HTMLElement:!1}function wN(e){return!Nv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof fs(e).ShadowRoot}function Lf(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 VJ(e){return/^(table|td|th)$/.test(od(e))}function Mv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const YJ=/transform|translate|scale|rotate|perspective|filter/,KJ=/paint|layout|strict|content/,Wl=e=>!!e&&e!=="none";let Wb;function l1(e){const t=Xs(e)?Zs(e):e;return Wl(t.transform)||Wl(t.translate)||Wl(t.scale)||Wl(t.rotate)||Wl(t.perspective)||!c1()&&(Wl(t.backdropFilter)||Wl(t.filter))||YJ.test(t.willChange||"")||KJ.test(t.contain||"")}function GJ(e){let t=ul(e);for(;la(t)&&!Wu(t);){if(l1(t))return t;if(Mv(t))return null;t=ul(t)}return null}function c1(){return Wb==null&&(Wb=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Wb}function Wu(e){return/^(html|body|#document)$/.test(od(e))}function Zs(e){return fs(e).getComputedStyle(e)}function Ov(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||wN(e)&&e.host||No(e);return wN(t)?t.host:t}function TI(e){const t=ul(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:la(t)&&Lf(t)?t:TI(t)}function hf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=TI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=fs(i);if(s){const l=T0(o);return t.concat(o,o.visualViewport||[],Lf(i)?i:[],l&&n?hf(l):[])}else return t.concat(i,hf(i,[],n))}function T0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function RI(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 u1(e){return Xs(e)?e:e.contextElement}function Bu(e){const t=u1(e);if(!la(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=RI(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 XJ=Eo(0);function AI(e){const t=fs(e);return!c1()||!t.visualViewport?XJ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ZJ(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=u1(e);let o=Eo(1);t&&(r?Xs(r)&&(o=Bu(r)):o=Bu(e));const l=ZJ(s,n,r)?AI(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),g=r&&Xs(r)?fs(r):r;let b=y,w=T0(b);for(;w&&r&&g!==b;){const x=Bu(w),E=w.getBoundingClientRect(),k=Zs(w),T=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,A=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=T,d+=A,b=fs(w),w=T0(b)}}return Ug({width:h,height:p,x:u,y:d})}function Dv(e,t){const n=Ov(e).scrollLeft;return t?t.left+n:lc(No(e)).left+n}function NI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Dv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function QJ(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Mv(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"||Lf(o))&&(u=Ov(r)),p)){const g=lc(r);d=Bu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const y=o&&!p&&!s?NI(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 JJ(e){return Array.from(e.getClientRects())}function eee(e){const t=No(e),n=Ov(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+Dv(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 SN=25;function tee(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=c1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Dv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),g=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,b=Math.abs(r.clientWidth-p.clientWidth-g);b<=SN&&(s-=b)}else d<=SN&&(s+=d);return{width:s,height:o,x:l,y:u}}function nee(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 xN(e,t,n){let r;if(t==="viewport")r=tee(e,n);else if(t==="document")r=eee(No(e));else if(Xs(t))r=nee(t,n);else{const i=AI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ug(r)}function MI(e,t){const n=ul(e);return n===t||!Xs(n)||Wu(n)?!1:Zs(n).position==="fixed"||MI(n,t)}function ree(e,t){const n=t.get(e);if(n)return n;let r=hf(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=l1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Lf(o)&&!u&&MI(e,o))?r=r.filter(h=>h!==o):i=l,o=ul(o)}return t.set(e,r),r}function iee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Mv(t)?[]:ree(t,this._c):[].concat(n),r],l=xN(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 g=xN(t,o[y],i);u=hs(g.top,u),d=cl(g.right,d),h=cl(g.bottom,h),p=hs(g.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function see(e){const{width:t,height:n}=RI(e);return{width:t,height:n}}function oee(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=Dv(i)}if(r||!r&&!s)if((od(t)!=="body"||Lf(i))&&(l=Ov(t)),r){const g=lc(t,!0,s,t);u.x=g.x+t.clientLeft,u.y=g.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?NI(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 qb(e){return Zs(e).position==="static"}function EN(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 OI(e,t){const n=fs(e);if(Mv(e))return n;if(!la(e)){let i=ul(e);for(;i&&!Wu(i);){if(Xs(i)&&!qb(i))return i;i=ul(i)}return n}let r=EN(e,t);for(;r&&VJ(r)&&qb(r);)r=EN(r,t);return r&&Wu(r)&&qb(r)&&!l1(r)?n:r||GJ(e)||n}const aee=async function(e){const t=this.getOffsetParent||OI,n=this.getDimensions,r=await n(e.floating);return{reference:oee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function lee(e){return Zs(e).direction==="rtl"}const cee={convertOffsetParentRelativeRectToViewportRelativeRect:QJ,getDocumentElement:No,getClippingRect:iee,getOffsetParent:OI,getElementRects:aee,getClientRects:JJ,getDimensions:see,getScale:Bu,isElement:Xs,isRTL:lee};function DI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function uee(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:g}=d;if(l||t(),!y||!g)return;const b=Lm(p),w=Lm(i.clientWidth-(h+y)),x=Lm(i.clientHeight-(p+g)),E=Lm(h),T={rootMargin:-b+"px "+-w+"px "+-x+"px "+-E+"px",threshold:hs(0,cl(1,u))||1};let A=!0;function z(R){const H=R[0].intersectionRatio;if(H!==u){if(!A)return o();H?o(!1,H):r=setTimeout(()=>{o(!1,1e-7)},1e3)}H===1&&!DI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(z,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(z,T)}n.observe(e)}return o(!0),s}function dee(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=u1(e),h=i||s?[...d?hf(d):[],...t?hf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?uee(d,n):null;let y=-1,g=null;o&&(g=new ResizeObserver(E=>{let[k]=E;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var T;(T=g)==null||T.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let b,w=u?lc(e):null;u&&x();function x(){const E=lc(e);w&&!DI(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=g)==null||E.disconnect(),g=null,u&&cancelAnimationFrame(b)}}const hee=HJ,fee=UJ,pee=jJ,mee=qJ,gee=FJ,CN=BJ,vee=WJ,yee=(e,t,n)=>{const r=new Map,i={platform:cee,...n},s={...i.platform,_c:r};return zJ(e,t,{...i,platform:s})};var _ee=typeof document<"u",bee=function(){},mg=_ee?_.useLayoutEffect:bee;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 PI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kN(e,t){const n=PI(e);return Math.round(t*n)/n}function Vb(e){const t=_.useRef(e);return mg(()=>{t.current=e}),t}function wee(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,g]=_.useState(r);Wg(y,r)||g(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!==H.current&&(H.current=K,E(K))},[]),A=s||b,z=o||x,R=_.useRef(null),H=_.useRef(null),P=_.useRef(h),q=u!=null,U=Vb(u),$=Vb(i),D=Vb(d),M=_.useCallback(()=>{if(!R.current||!H.current)return;const K={placement:t,strategy:n,middleware:y};$.current&&(K.platform=$.current),yee(R.current,H.current,K).then(F=>{const N={...F,isPositioned:D.current!==!1};j.current&&!Wg(P.current,N)&&(P.current=N,nd.flushSync(()=>{p(N)}))})},[y,t,n,$,D]);mg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[d]);const j=_.useRef(!1);mg(()=>(j.current=!0,()=>{j.current=!1}),[]),mg(()=>{if(A&&(R.current=A),z&&(H.current=z),A&&z){if(U.current)return U.current(A,z,M);M()}},[A,z,M,U,q]);const L=_.useMemo(()=>({reference:R,floating:H,setReference:k,setFloating:T}),[k,T]),O=_.useMemo(()=>({reference:A,floating:z}),[A,z]),Y=_.useMemo(()=>{const K={position:n,left:0,top:0};if(!O.floating)return K;const F=kN(O.floating,h.x),N=kN(O.floating,h.y);return l?{...K,transform:"translate("+F+"px, "+N+"px)",...PI(O.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:N}},[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 See=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?CN({element:r.current,padding:i}).fn(n):{}:r?CN({element:r,padding:i}).fn(n):{}}}},xee=(e,t)=>{const n=hee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eee=(e,t)=>{const n=fee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cee=(e,t)=>({fn:vee(e).fn,options:[e,t]}),kee=(e,t)=>{const n=pee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Tee=(e,t)=>{const n=mee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ree=(e,t)=>{const n=gee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aee=(e,t)=>{const n=See(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Nee="Arrow",LI=_.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return v.jsx(Qt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:v.jsx("polygon",{points:"0,0 30,0 15,10"})})});LI.displayName=Nee;var Mee=LI,d1="Popper",[II,bl]=aa(d1),[Oee,zI]=II(d1),BI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return v.jsx(Oee,{scope:t,anchor:r,onAnchorChange:i,children:n})};BI.displayName=d1;var jI="PopperAnchor",FI=_.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=zI(jI,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:v.jsx(Qt.div,{...i,ref:l})});FI.displayName=jI;var h1="PopperContent",[Dee,Pee]=II(h1),$I=_.forwardRef((e,t)=>{var te,ue,ge,Se,Te,Ie;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:g="optimized",onPlaced:b,...w}=e,x=zI(h1,n),[E,k]=_.useState(null),T=Bn(t,Ke=>k(Ke)),[A,z]=_.useState(null),R=CJ(A),H=(R==null?void 0:R.width)??0,P=(R==null?void 0:R.height)??0,q=r+(s!=="center"?"-"+s:""),U=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},$=Array.isArray(d)?d:[d],D=$.length>0,M={padding:U,boundary:$.filter(Iee),altBoundary:D},{refs:j,floatingStyles:L,placement:O,isPositioned:Y,middlewareData:K}=wee({strategy:"fixed",placement:q,whileElementsMounted:(...Ke)=>dee(...Ke,{animationFrame:g==="always"}),elements:{reference:x.anchor},middleware:[xee({mainAxis:i+P,alignmentAxis:o}),u&&Eee({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Cee():void 0,...M}),u&&kee({...M}),Tee({...M,apply:({elements:Ke,rects:gt,availableWidth:Oe,availableHeight:de})=>{const{width:Ee,height:Qe}=gt.reference,fe=Ke.floating.style;fe.setProperty("--radix-popper-available-width",`${Oe}px`),fe.setProperty("--radix-popper-available-height",`${de}px`),fe.setProperty("--radix-popper-anchor-width",`${Ee}px`),fe.setProperty("--radix-popper-anchor-height",`${Qe}px`)}}),A&&Aee({element:A,padding:l}),zee({arrowWidth:H,arrowHeight:P}),y&&Ree({strategy:"referenceHidden",...M})]}),[F,N]=WI(O),W=To(b);Ti(()=>{Y&&(W==null||W())},[Y,W]);const G=(te=K.arrow)==null?void 0:te.x,I=(ue=K.arrow)==null?void 0:ue.y,ne=((ge=K.arrow)==null?void 0:ge.centerOffset)!==0,[ie,se]=_.useState();return Ti(()=>{E&&se(window.getComputedStyle(E).zIndex)},[E]),v.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":[(Se=K.transformOrigin)==null?void 0:Se.x,(Te=K.transformOrigin)==null?void 0:Te.y].join(" "),...((Ie=K.hide)==null?void 0:Ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:v.jsx(Dee,{scope:n,placedSide:F,onArrowChange:z,arrowX:G,arrowY:I,shouldHideArrow:ne,children:v.jsx(Qt.div,{"data-side":F,"data-align":N,...w,ref:T,style:{...w.style,animation:Y?void 0:"none"}})})})});$I.displayName=h1;var HI="PopperArrow",Lee={top:"bottom",right:"left",bottom:"top",left:"right"},UI=_.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Pee(HI,r),o=Lee[s.placedSide];return v.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:v.jsx(Mee,{...i,ref:n,style:{...i.style,display:"block"}})})});UI.displayName=HI;function Iee(e){return e!==null}var zee=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]=WI(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.x)??0)+l/2,g=(((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:`${g}px`):d==="left"&&(b=`${r.floating.width+u}px`,w=o?p:`${g}px`),{data:{x:b,y:w}}}});function WI(e){const[t,n="center"]=e.split("-");return[t,n]}var Pv=BI,If=FI,Lv=$I,Iv=UI,Yb="rovingFocusGroup.onEntryFocus",Bee={bubbles:!1,cancelable:!0},zf="RovingFocusGroup",[R0,qI,jee]=Gx(zf),[Fee,VI]=aa(zf,[jee]),[$ee,Hee]=Fee(zf),YI=_.forwardRef((e,t)=>v.jsx(R0.Provider,{scope:e.__scopeRovingFocusGroup,children:v.jsx(R0.Slot,{scope:e.__scopeRovingFocusGroup,children:v.jsx(Uee,{...e,ref:t})})}));YI.displayName=zf;var Uee=_.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),g=Bn(t,y),b=Xx(s),[w,x]=oc({prop:o,defaultProp:l??null,onChange:u,caller:zf}),[E,k]=_.useState(!1),T=To(d),A=qI(n),z=_.useRef(!1),[R,H]=_.useState(0);return _.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(Yb,T),()=>P.removeEventListener(Yb,T)},[T]),v.jsx($ee,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:w,onItemFocus:_.useCallback(P=>x(P),[x]),onItemShiftTab:_.useCallback(()=>k(!0),[]),onFocusableItemAdd:_.useCallback(()=>H(P=>P+1),[]),onFocusableItemRemove:_.useCallback(()=>H(P=>P-1),[]),children:v.jsx(Qt.div,{tabIndex:E||R===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:yt(e.onMouseDown,()=>{z.current=!0}),onFocus:yt(e.onFocus,P=>{const q=!z.current;if(P.target===P.currentTarget&&q&&!E){const U=new CustomEvent(Yb,Bee);if(P.currentTarget.dispatchEvent(U),!U.defaultPrevented){const $=A().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);XI(L,h)}}z.current=!1}),onBlur:yt(e.onBlur,()=>k(!1))})})}),KI="RovingFocusGroupItem",GI=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=Hee(KI,n),p=h.currentTabStopId===d,y=qI(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:w}=h;return _.useEffect(()=>{if(r)return g(),()=>b()},[r,g,b]),v.jsx(R0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:v.jsx(Qt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:yt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:yt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:yt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=Vee(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(A=>A.focusable).map(A=>A.ref.current);if(E==="last")T.reverse();else if(E==="prev"||E==="next"){E==="prev"&&T.reverse();const A=T.indexOf(x.currentTarget);T=h.loop?Yee(T,A+1):T.slice(A+1)}setTimeout(()=>XI(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});GI.displayName=KI;var Wee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function qee(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Vee(e,t,n){const r=qee(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Wee[r]}function XI(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Yee(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Kee=YI,Gee=GI,A0=["Enter"," "],Xee=["ArrowDown","PageUp","Home"],ZI=["ArrowUp","PageDown","End"],Zee=[...Xee,...ZI],Qee={ltr:[...A0,"ArrowRight"],rtl:[...A0,"ArrowLeft"]},Jee={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Bf="Menu",[ff,ete,tte]=Gx(Bf),[bc,QI]=aa(Bf,[tte,bl,VI]),zv=bl(),JI=VI(),[nte,wc]=bc(Bf),[rte,jf]=bc(Bf),ez=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=zv(t),[u,d]=_.useState(null),h=_.useRef(!1),p=To(s),y=Xx(i);return _.useEffect(()=>{const g=()=>{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",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),v.jsx(Pv,{...l,children:v.jsx(nte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:v.jsx(rte,{scope:t,onClose:_.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};ez.displayName=Bf;var ite="MenuAnchor",f1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(If,{...i,...r,ref:t})});f1.displayName=ite;var p1="MenuPortal",[ste,tz]=bc(p1,{forceMount:void 0}),nz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=wc(p1,t);return v.jsx(ste,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};nz.displayName=p1;var Ds="MenuContent",[ote,m1]=bc(Ds),rz=_.forwardRef((e,t)=>{const n=tz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:o.modal?v.jsx(ate,{...i,ref:t}):v.jsx(lte,{...i,ref:t})})})})}),ate=_.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 Rv(s)},[]),v.jsx(g1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),lte=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu);return v.jsx(g1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),cte=ll("MenuContent.ScrollLock"),g1=_.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:g,disableOutsideScroll:b,...w}=e,x=wc(Ds,n),E=jf(Ds,n),k=zv(n),T=JI(n),A=ete(n),[z,R]=_.useState(null),H=_.useRef(null),P=Bn(t,H,x.onContentChange),q=_.useRef(0),U=_.useRef(""),$=_.useRef(0),D=_.useRef(null),M=_.useRef("right"),j=_.useRef(0),L=b?Pf:_.Fragment,O=b?{as:cte,allowPinchZoom:!0}:void 0,Y=F=>{var te,ue;const N=U.current+F,W=A().filter(ge=>!ge.disabled),G=document.activeElement,I=(te=W.find(ge=>ge.ref.current===G))==null?void 0:te.textValue,ne=W.map(ge=>ge.textValue),ie=wte(ne,N,I),se=(ue=W.find(ge=>ge.textValue===ie))==null?void 0:ue.ref.current;(function ge(Se){U.current=Se,window.clearTimeout(q.current),Se!==""&&(q.current=window.setTimeout(()=>ge(""),1e3))})(N),se&&setTimeout(()=>se.focus())};_.useEffect(()=>()=>window.clearTimeout(q.current),[]),kv();const K=_.useCallback(F=>{var W,G;return M.current===((W=D.current)==null?void 0:W.side)&&xte(F,(G=D.current)==null?void 0:G.area)},[]);return v.jsx(ote,{scope:n,searchRef:U,onItemEnter:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),onItemLeave:_.useCallback(F=>{var N;K(F)||((N=H.current)==null||N.focus(),R(null))},[K]),onTriggerLeave:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),pointerGraceTimerRef:$,onPointerGraceIntentChange:_.useCallback(F=>{D.current=F},[]),children:v.jsx(L,{...O,children:v.jsx(Df,{asChild:!0,trapped:i,onMountAutoFocus:yt(s,F=>{var N;F.preventDefault(),(N=H.current)==null||N.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:g,children:v.jsx(Kee,{asChild:!0,...T,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:z,onCurrentTabStopIdChange:R,onEntryFocus:yt(u,F=>{E.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:v.jsx(Lv,{role:"menu","aria-orientation":"vertical","data-state":_z(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:yt(w.onKeyDown,F=>{const W=F.target.closest("[data-radix-menu-content]")===F.currentTarget,G=F.ctrlKey||F.altKey||F.metaKey,I=F.key.length===1;W&&(F.key==="Tab"&&F.preventDefault(),!G&&I&&Y(F.key));const ne=H.current;if(F.target!==ne||!Zee.includes(F.key))return;F.preventDefault();const se=A().filter(te=>!te.disabled).map(te=>te.ref.current);ZI.includes(F.key)&&se.reverse(),_te(se)}),onBlur:yt(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(q.current),U.current="")}),onPointerMove:yt(e.onPointerMove,pf(F=>{const N=F.target,W=j.current!==F.clientX;if(F.currentTarget.contains(N)&&W){const G=F.clientX>j.current?"right":"left";M.current=G,j.current=F.clientX}}))})})})})})})});rz.displayName=Ds;var ute="MenuGroup",v1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Qt.div,{role:"group",...r,ref:t})});v1.displayName=ute;var dte="MenuLabel",iz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Qt.div,{...r,ref:t})});iz.displayName=dte;var qg="MenuItem",TN="menu.itemSelect",Bv=_.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=_.useRef(null),o=jf(qg,e.__scopeMenu),l=m1(qg,e.__scopeMenu),u=Bn(t,s),d=_.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(TN,{bubbles:!0,cancelable:!0});p.addEventListener(TN,g=>r==null?void 0:r(g),{once:!0}),qL(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return v.jsx(sz,{...i,ref:u,disabled:n,onClick:yt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:yt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:yt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||A0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Bv.displayName=qg;var sz=_.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=m1(qg,n),l=JI(n),u=_.useRef(null),d=Bn(t,u),[h,p]=_.useState(!1),[y,g]=_.useState("");return _.useEffect(()=>{const b=u.current;b&&g((b.textContent??"").trim())},[s.children]),v.jsx(ff.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:v.jsx(Gee,{asChild:!0,...l,focusable:!r,children:v.jsx(Qt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:yt(e.onPointerMove,pf(b=>{r?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:yt(e.onPointerLeave,pf(b=>o.onItemLeave(b))),onFocus:yt(e.onFocus,()=>p(!0)),onBlur:yt(e.onBlur,()=>p(!1))})})})}),hte="MenuCheckboxItem",oz=_.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return v.jsx(dz,{scope:e.__scopeMenu,checked:n,children:v.jsx(Bv,{role:"menuitemcheckbox","aria-checked":Vg(n)?"mixed":n,...i,ref:t,"data-state":_1(n),onSelect:yt(i.onSelect,()=>r==null?void 0:r(Vg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});oz.displayName=hte;var az="MenuRadioGroup",[fte,pte]=bc(az,{value:void 0,onValueChange:()=>{}}),lz=_.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return v.jsx(fte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:v.jsx(v1,{...i,ref:t})})});lz.displayName=az;var cz="MenuRadioItem",uz=_.forwardRef((e,t)=>{const{value:n,...r}=e,i=pte(cz,e.__scopeMenu),s=n===i.value;return v.jsx(dz,{scope:e.__scopeMenu,checked:s,children:v.jsx(Bv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_1(s),onSelect:yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});uz.displayName=cz;var y1="MenuItemIndicator",[dz,mte]=bc(y1,{checked:!1}),hz=_.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=mte(y1,n);return v.jsx(Bs,{present:r||Vg(s.checked)||s.checked===!0,children:v.jsx(Qt.span,{...i,ref:t,"data-state":_1(s.checked)})})});hz.displayName=y1;var gte="MenuSeparator",fz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Qt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});fz.displayName=gte;var vte="MenuArrow",pz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(Iv,{...i,...r,ref:t})});pz.displayName=vte;var yte="MenuSub",[uTe,mz]=bc(yte),Ph="MenuSubTrigger",gz=_.forwardRef((e,t)=>{const n=wc(Ph,e.__scopeMenu),r=jf(Ph,e.__scopeMenu),i=mz(Ph,e.__scopeMenu),s=m1(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]),v.jsx(f1,{asChild:!0,...d,children:v.jsx(sz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":_z(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:yt(e.onPointerMove,pf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:yt(e.onPointerLeave,pf(p=>{var g,b;h();const y=(g=n.content)==null?void 0:g.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:yt(e.onKeyDown,p=>{var g;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Qee[r.dir].includes(p.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),p.preventDefault())})})})});gz.displayName=Ph;var vz="MenuSubContent",yz=_.forwardRef((e,t)=>{const n=tz(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu),l=mz(vz,e.__scopeMenu),u=_.useRef(null),d=Bn(t,u);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:v.jsx(g1,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:yt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:yt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:yt(e.onKeyDown,h=>{var g;const p=h.currentTarget.contains(h.target),y=Jee[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),h.preventDefault())})})})})})});yz.displayName=vz;function _z(e){return e?"open":"closed"}function Vg(e){return e==="indeterminate"}function _1(e){return Vg(e)?"indeterminate":e?"checked":"unchecked"}function _te(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function bte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function wte(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=bte(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 Ste(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 xte(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Ste(n,t)}function pf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Ete=ez,Cte=f1,kte=nz,Tte=rz,Rte=v1,Ate=iz,Nte=Bv,Mte=oz,Ote=lz,Dte=uz,Pte=hz,Lte=fz,Ite=pz,zte=gz,Bte=yz,jv="DropdownMenu",[jte]=aa(jv,[QI]),ji=QI(),[Fte,bz]=jte(jv),wz=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:jv});return v.jsx(Fte,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:_.useCallback(()=>p(y=>!y),[p]),modal:l,children:v.jsx(Ete,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};wz.displayName=jv;var Sz="DropdownMenuTrigger",xz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=bz(Sz,n),o=ji(n);return v.jsx(Cte,{asChild:!0,...o,children:v.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:yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});xz.displayName=Sz;var $te="DropdownMenuPortal",Ez=e=>{const{__scopeDropdownMenu:t,...n}=e,r=ji(t);return v.jsx(kte,{...r,...n})};Ez.displayName=$te;var Cz="DropdownMenuContent",kz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=bz(Cz,n),s=ji(n),o=_.useRef(!1);return v.jsx(Tte,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:yt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});kz.displayName=Cz;var Hte="DropdownMenuGroup",Ute=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Rte,{...i,...r,ref:t})});Ute.displayName=Hte;var Wte="DropdownMenuLabel",Tz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ate,{...i,...r,ref:t})});Tz.displayName=Wte;var qte="DropdownMenuItem",Rz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Nte,{...i,...r,ref:t})});Rz.displayName=qte;var Vte="DropdownMenuCheckboxItem",Az=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Mte,{...i,...r,ref:t})});Az.displayName=Vte;var Yte="DropdownMenuRadioGroup",Kte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ote,{...i,...r,ref:t})});Kte.displayName=Yte;var Gte="DropdownMenuRadioItem",Xte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Dte,{...i,...r,ref:t})});Xte.displayName=Gte;var Zte="DropdownMenuItemIndicator",Nz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Pte,{...i,...r,ref:t})});Nz.displayName=Zte;var Qte="DropdownMenuSeparator",Mz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Lte,{...i,...r,ref:t})});Mz.displayName=Qte;var Jte="DropdownMenuArrow",ene=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ite,{...i,...r,ref:t})});ene.displayName=Jte;var tne="DropdownMenuSubTrigger",nne=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(zte,{...i,...r,ref:t})});nne.displayName=tne;var rne="DropdownMenuSubContent",ine=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Bte,{...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)"}})});ine.displayName=rne;var sne=wz,one=xz,ane=Ez,lne=kz,cne=Tz,une=Rz,dne=Az,hne=Nz,fne=Mz;function RN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Fv="Popover",[Oz]=aa(Fv,[bl]),Ff=bl(),[pne,wl]=Oz(Fv),Dz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Ff(t),u=_.useRef(null),[d,h]=_.useState(!1),[p,y]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:Fv});return v.jsx(Pv,{...l,children:v.jsx(pne,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:_.useCallback(()=>y(g=>!g),[y]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:o,children:n})})};Dz.displayName=Fv;var Pz="PopoverAnchor",mne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Pz,n),s=Ff(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return _.useEffect(()=>(o(),()=>l()),[o,l]),v.jsx(If,{...s,...r,ref:t})});mne.displayName=Pz;var Lz="PopoverTrigger",Iz=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Lz,n),s=Ff(n),o=Bn(t,i.triggerRef),l=v.jsx(Qt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":$z(i.open),...r,ref:o,onClick:yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:v.jsx(If,{asChild:!0,...s,children:l})});Iz.displayName=Lz;var b1="PopoverPortal",[gne,vne]=Oz(b1,{forceMount:void 0}),zz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=wl(b1,t);return v.jsx(gne,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};zz.displayName=b1;var qu="PopoverContent",Bz=_.forwardRef((e,t)=>{const n=vne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=wl(qu,e.__scopePopover);return v.jsx(Bs,{present:r||s.open,children:s.modal?v.jsx(_ne,{...i,ref:t}):v.jsx(bne,{...i,ref:t})})});Bz.displayName=qu;var yne=ll("PopoverContent.RemoveScroll"),_ne=_.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 Rv(o)},[]),v.jsx(Pf,{as:yne,allowPinchZoom:!0,children:v.jsx(jz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:yt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),bne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return v.jsx(jz,{...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()}})}),jz=_.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),g=Ff(n);return kv(),v.jsx(Df,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:v.jsx(Lv,{"data-state":$z(y.open),role:"dialog",id:y.contentId,...g,...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)"}})})})}),Fz="PopoverClose",wne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Fz,n);return v.jsx(Qt.button,{type:"button",...r,ref:t,onClick:yt(e.onClick,()=>i.onOpenChange(!1))})});wne.displayName=Fz;var Sne="PopoverArrow",xne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Ff(n);return v.jsx(Iv,{...i,...r,ref:t})});xne.displayName=Sne;function $z(e){return e?"open":"closed"}var Ene=Dz,Cne=Iz,kne=zz,Tne=Bz,Rne=[" ","Enter","ArrowUp","ArrowDown"],Ane=[" ","Enter"],cc="Select",[$v,Hv,Nne]=Gx(cc),[ad]=aa(cc,[Nne,bl]),Uv=bl(),[Mne,Sl]=ad(cc),[One,Dne]=ad(cc),Hz=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:g,form:b}=e,w=Uv(t),[x,E]=_.useState(null),[k,T]=_.useState(null),[A,z]=_.useState(!1),R=Xx(d),[H,P]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:cc}),[q,U]=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 v.jsx(Pv,{...w,children:v.jsxs(Mne,{required:g,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:A,onValueNodeHasChildrenChange:z,contentId:gi(),value:q,onValueChange:U,open:H,onOpenChange:P,dir:R,triggerPointerDownPosRef:$,disabled:y,children:[v.jsx($v.Provider,{scope:t,children:v.jsx(One,{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?v.jsxs(uB,{"aria-hidden":!0,required:g,tabIndex:-1,name:h,autoComplete:p,value:q,onChange:O=>U(O.target.value),disabled:y,form:b,children:[q===void 0?v.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};Hz.displayName=cc;var Uz="SelectTrigger",Wz=_.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Uv(n),o=Sl(Uz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Hv(n),h=_.useRef("touch"),[p,y,g]=hB(w=>{const x=d().filter(T=>!T.disabled),E=x.find(T=>T.value===o.value),k=fB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),b=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return v.jsx(If,{asChild:!0,...s,children:v.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":dB(o.value)?"":void 0,...i,ref:u,onClick:yt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&b(w)}),onPointerDown:yt(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(b(w),w.preventDefault())}),onKeyDown:yt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&Rne.includes(w.key)&&(b(),w.preventDefault())})})})});Wz.displayName=Uz;var qz="SelectValue",Vz=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=Sl(qz,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ti(()=>{d(h)},[d,h]),v.jsx(Qt.span,{...l,ref:p,style:{pointerEvents:"none"},children:dB(u.value)?v.jsx(v.Fragment,{children:o}):s})});Vz.displayName=qz;var Pne="SelectIcon",Yz=_.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return v.jsx(Qt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});Yz.displayName=Pne;var Lne="SelectPortal",Kz=e=>v.jsx(id,{asChild:!0,...e});Kz.displayName=Lne;var uc="SelectContent",Gz=_.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(v.jsx(Xz,{scope:e.__scopeSelect,children:v.jsx($v.Slot,{scope:e.__scopeSelect,children:v.jsx("div",{children:e.children})})}),s):null}return v.jsx(Zz,{...e,ref:t})});Gz.displayName=uc;var qs=10,[Xz,xl]=ad(uc),Ine="SelectContentImpl",zne=ll("SelectContent.RemoveScroll"),Zz=_.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:g,sticky:b,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=Sl(uc,n),[T,A]=_.useState(null),[z,R]=_.useState(null),H=Bn(t,te=>A(te)),[P,q]=_.useState(null),[U,$]=_.useState(null),D=Hv(n),[M,j]=_.useState(!1),L=_.useRef(!1);_.useEffect(()=>{if(T)return Rv(T)},[T]),kv();const O=_.useCallback(te=>{const[ue,...ge]=D().map(Ie=>Ie.ref.current),[Se]=ge.slice(-1),Te=document.activeElement;for(const Ie of te)if(Ie===Te||(Ie==null||Ie.scrollIntoView({block:"nearest"}),Ie===ue&&z&&(z.scrollTop=0),Ie===Se&&z&&(z.scrollTop=z.scrollHeight),Ie==null||Ie.focus(),document.activeElement!==Te))return},[D,z]),Y=_.useCallback(()=>O([P,T]),[O,P,T]);_.useEffect(()=>{M&&Y()},[M,Y]);const{onOpenChange:K,triggerPointerDownPosRef:F}=k;_.useEffect(()=>{if(T){let te={x:0,y:0};const ue=Se=>{var Te,Ie;te={x:Math.abs(Math.round(Se.pageX)-(((Te=F.current)==null?void 0:Te.x)??0)),y:Math.abs(Math.round(Se.pageY)-(((Ie=F.current)==null?void 0:Ie.y)??0))}},ge=Se=>{te.x<=10&&te.y<=10?Se.preventDefault():T.contains(Se.target)||K(!1),document.removeEventListener("pointermove",ue),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",ue),document.addEventListener("pointerup",ge,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ue),document.removeEventListener("pointerup",ge,{capture:!0})}}},[T,K,F]),_.useEffect(()=>{const te=()=>K(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[K]);const[N,W]=hB(te=>{const ue=D().filter(Te=>!Te.disabled),ge=ue.find(Te=>Te.ref.current===document.activeElement),Se=fB(ue,te,ge);Se&&setTimeout(()=>Se.ref.current.focus())}),G=_.useCallback((te,ue,ge)=>{const Se=!L.current&&!ge;(k.value!==void 0&&k.value===ue||Se)&&(q(te),Se&&(L.current=!0))},[k.value]),I=_.useCallback(()=>T==null?void 0:T.focus(),[T]),ne=_.useCallback((te,ue,ge)=>{const Se=!L.current&&!ge;(k.value!==void 0&&k.value===ue||Se)&&$(te)},[k.value]),ie=r==="popper"?N0:Qz,se=ie===N0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:g,sticky:b,hideWhenDetached:w,avoidCollisions:x}:{};return v.jsx(Xz,{scope:n,content:T,viewport:z,onViewportChange:R,itemRefCallback:G,selectedItem:P,onItemLeave:I,itemTextRefCallback:ne,focusSelectedItem:Y,selectedItemText:U,position:r,isPositioned:M,searchRef:N,children:v.jsx(Pf,{as:zne,allowPinchZoom:!0,children:v.jsx(Df,{asChild:!0,trapped:k.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:yt(i,te=>{var ue;(ue=k.trigger)==null||ue.focus({preventScroll:!0}),te.preventDefault()}),children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:v.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:H,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:yt(E.onKeyDown,te=>{const ue=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!ue&&te.key.length===1&&W(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let Se=D().filter(Te=>!Te.disabled).map(Te=>Te.ref.current);if(["ArrowUp","End"].includes(te.key)&&(Se=Se.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const Te=te.target,Ie=Se.indexOf(Te);Se=Se.slice(Ie+1)}setTimeout(()=>O(Se)),te.preventDefault()}})})})})})})});Zz.displayName=Ine;var Bne="SelectItemAlignedPosition",Qz=_.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,H=>h(H)),y=Hv(n),g=_.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 H=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),q=s.valueNode.getBoundingClientRect(),U=E.getBoundingClientRect();if(s.dir!=="rtl"){const Te=U.left-P.left,Ie=q.left-Te,Ke=H.left-Ie,gt=H.width+Ke,Oe=Math.max(gt,P.width),de=window.innerWidth-qs,Ee=RN(Ie,[qs,Math.max(qs,de-Oe)]);l.style.minWidth=gt+"px",l.style.left=Ee+"px"}else{const Te=P.right-U.right,Ie=window.innerWidth-q.right-Te,Ke=window.innerWidth-H.right-Ie,gt=H.width+Ke,Oe=Math.max(gt,P.width),de=window.innerWidth-qs,Ee=RN(Ie,[qs,Math.max(qs,de-Oe)]);l.style.minWidth=gt+"px",l.style.right=Ee+"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),F=L+O+M+K+Y,N=Math.min(x.offsetHeight*5,F),W=window.getComputedStyle(w),G=parseInt(W.paddingTop,10),I=parseInt(W.paddingBottom,10),ne=H.top+H.height/2-qs,ie=D-ne,se=x.offsetHeight/2,te=x.offsetTop+se,ue=L+O+te,ge=F-ue;if(ue<=ne){const Te=$.length>0&&x===$[$.length-1].ref.current;l.style.bottom="0px";const Ie=d.clientHeight-w.offsetTop-w.offsetHeight,Ke=Math.max(ie,se+(Te?I:0)+Ie+Y),gt=ue+Ke;l.style.height=gt+"px"}else{const Te=$.length>0&&x===$[0].ref.current;l.style.top="0px";const Ke=Math.max(ne,L+w.offsetTop+(Te?G:0)+se)+ge;l.style.height=Ke+"px",w.scrollTop=ue-ne+w.offsetTop}l.style.margin=`${qs}px 0`,l.style.minHeight=N+"px",l.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ti(()=>T(),[T]);const[A,z]=_.useState();Ti(()=>{d&&z(window.getComputedStyle(d).zIndex)},[d]);const R=_.useCallback(H=>{H&&b.current===!0&&(T(),k==null||k(),b.current=!1)},[T,k]);return v.jsx(Fne,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:R,children:v.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:v.jsx(Qt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});Qz.displayName=Bne;var jne="SelectPopperPosition",N0=_.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=qs,...s}=e,o=Uv(n);return v.jsx(Lv,{...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)"}})});N0.displayName=jne;var[Fne,w1]=ad(uc,{}),M0="SelectViewport",Jz=_.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=xl(M0,n),o=w1(M0,n),l=Bn(t,s.onViewportChange),u=_.useRef(0);return v.jsxs(v.Fragment,{children:[v.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}),v.jsx($v.Slot,{scope:n,children:v.jsx(Qt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:yt(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const g=Math.abs(u.current-h.scrollTop);if(g>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+g,T=Math.min(b,k),A=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(h.scrollTop=A>0?A:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});Jz.displayName=M0;var eB="SelectGroup",[$ne,Hne]=ad(eB),Une=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return v.jsx($ne,{scope:n,id:i,children:v.jsx(Qt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});Une.displayName=eB;var tB="SelectLabel",Wne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Hne(tB,n);return v.jsx(Qt.div,{id:i.id,...r,ref:t})});Wne.displayName=tB;var Yg="SelectItem",[qne,nB]=ad(Yg),rB=_.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,g]=_.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 v.jsx(qne,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:_.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:v.jsx($v.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:v.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:yt(o.onFocus,()=>g(!0)),onBlur:yt(o.onBlur,()=>g(!1)),onClick:yt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:yt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:yt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:yt(o.onPointerMove,k=>{var T;x.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:yt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:yt(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(Ane.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});rB.displayName=Yg;var Lh="SelectItemText",iB=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Sl(Lh,n),l=xl(Lh,n),u=nB(Lh,n),d=Dne(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)}),g=h==null?void 0:h.textContent,b=_.useMemo(()=>v.jsx("option",{value:u.value,disabled:u.disabled,children:g},u.value),[u.disabled,u.value,g]),{onNativeOptionAdd:w,onNativeOptionRemove:x}=d;return Ti(()=>(w(b),()=>x(b)),[w,x,b]),v.jsxs(v.Fragment,{children:[v.jsx(Qt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?nd.createPortal(s.children,o.valueNode):null]})});iB.displayName=Lh;var sB="SelectItemIndicator",oB=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return nB(sB,n).isSelected?v.jsx(Qt.span,{"aria-hidden":!0,...r,ref:t}):null});oB.displayName=sB;var O0="SelectScrollUpButton",aB=_.forwardRef((e,t)=>{const n=xl(O0,e.__scopeSelect),r=w1(O0,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?v.jsx(cB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});aB.displayName=O0;var D0="SelectScrollDownButton",lB=_.forwardRef((e,t)=>{const n=xl(D0,e.__scopeSelect),r=w1(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.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?v.jsx(cB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});lB.displayName=D0;var cB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=xl("SelectScrollButton",n),o=_.useRef(null),l=Hv(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]),v.jsx(Qt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:yt(i.onPointerLeave,()=>{u()})})}),Vne="SelectSeparator",Yne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return v.jsx(Qt.div,{"aria-hidden":!0,...r,ref:t})});Yne.displayName=Vne;var P0="SelectArrow",Kne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Uv(n),s=Sl(P0,n),o=xl(P0,n);return s.open&&o.position==="popper"?v.jsx(Iv,{...i,...r,ref:t}):null});Kne.displayName=P0;var Gne="SelectBubbleInput",uB=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=_.useRef(null),s=Bn(r,i),o=EJ(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]),v.jsx(Qt.select,{...n,style:{...VL,...n.style},ref:s,defaultValue:t})});uB.displayName=Gne;function dB(e){return e===""||e===void 0}function hB(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 fB(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=Xne(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 Xne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zne=Hz,Qne=Wz,Jne=Vz,ere=Yz,tre=Kz,nre=Gz,rre=Jz,ire=rB,sre=iB,ore=oB,are=aB,lre=lB,[Wv]=aa("Tooltip",[bl]),qv=bl(),pB="TooltipProvider",cre=700,L0="tooltip.open",[ure,S1]=Wv(pB),mB=e=>{const{__scopeTooltip:t,delayDuration:n=cre,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)},[]),v.jsx(ure,{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})};mB.displayName=pB;var mf="Tooltip",[dre,$f]=Wv(mf),gB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=S1(mf,e.__scopeTooltip),d=qv(t),[h,p]=_.useState(null),y=gi(),g=_.useRef(0),b=o??u.disableHoverableContent,w=l??u.delayDuration,x=_.useRef(!1),[E,k]=oc({prop:r,defaultProp:i??!1,onChange:H=>{H?(u.onOpen(),document.dispatchEvent(new CustomEvent(L0))):u.onClose(),s==null||s(H)},caller:mf}),T=_.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),A=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,x.current=!1,k(!0)},[k]),z=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),R=_.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{x.current=!0,k(!0),g.current=0},w)},[w,k]);return _.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),v.jsx(Pv,{...d,children:v.jsx(dre,{scope:t,contentId:y,open:E,stateAttribute:T,trigger:h,onTriggerChange:p,onTriggerEnter:_.useCallback(()=>{u.isOpenDelayedRef.current?R():A()},[u.isOpenDelayedRef,R,A]),onTriggerLeave:_.useCallback(()=>{b?z():(window.clearTimeout(g.current),g.current=0)},[z,b]),onOpen:A,onClose:z,disableHoverableContent:b,children:n})})};gB.displayName=mf;var I0="TooltipTrigger",vB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=$f(I0,n),s=S1(I0,n),o=qv(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]),v.jsx(If,{asChild:!0,...o,children:v.jsx(Qt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:yt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:yt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:yt(e.onBlur,i.onClose),onClick:yt(e.onClick,i.onClose)})})});vB.displayName=I0;var x1="TooltipPortal",[hre,fre]=Wv(x1,{forceMount:void 0}),yB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=$f(x1,t);return v.jsx(hre,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};yB.displayName=x1;var Vu="TooltipContent",_B=_.forwardRef((e,t)=>{const n=fre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=$f(Vu,e.__scopeTooltip);return v.jsx(Bs,{present:r||o.open,children:o.disableHoverableContent?v.jsx(bB,{side:i,...s,ref:t}):v.jsx(pre,{side:i,...s,ref:t})})}),pre=_.forwardRef((e,t)=>{const n=$f(Vu,e.__scopeTooltip),r=S1(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]),g=_.useCallback((b,w)=>{const x=b.currentTarget,E={x:b.clientX,y:b.clientY},k=yre(E,x.getBoundingClientRect()),T=_re(E,k),A=bre(w.getBoundingClientRect()),z=Sre([...T,...A]);l(z),p(!0)},[p]);return _.useEffect(()=>()=>y(),[y]),_.useEffect(()=>{if(u&&h){const b=x=>g(x,h),w=x=>g(x,u);return u.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[u,h,g,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=!wre(E,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[u,h,o,d,y]),v.jsx(bB,{...e,ref:s})}),[mre,gre]=Wv(mf,{isInside:!1}),vre=XZ("TooltipContent"),bB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=$f(Vu,n),d=qv(n),{onClose:h}=u;return _.useEffect(()=>(document.addEventListener(L0,h),()=>document.removeEventListener(L0,h)),[h]),_.useEffect(()=>{if(u.trigger){const p=y=>{const g=y.target;g!=null&&g.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:v.jsxs(Lv,{"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:[v.jsx(vre,{children:r}),v.jsx(mre,{scope:n,isInside:!0,children:v.jsx(KL,{id:u.contentId,role:"tooltip",children:i||r})})]})})});_B.displayName=Vu;var wB="TooltipArrow",SB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=qv(n);return gre(wB,n).isInside?null:v.jsx(Iv,{...i,...r,ref:t})});SB.displayName=wB;function yre(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 _re(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 bre(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 wre(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 Sre(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),xre(t)}function xre(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 Ere=mB,Cre=gB,kre=vB,Tre=yB,Rre=_B,Are=SB;function E1({...e}){return v.jsx(Ene,{"data-slot":"popover",...e})}function C1({...e}){return v.jsx(Cne,{"data-slot":"popover-trigger",...e})}function k1({className:e,align:t="center",sideOffset:n=4,...r}){return v.jsx(kne,{children:v.jsx(Tne,{"data-slot":"popover-content",align:t,sideOffset:n,className:qe("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const Nre={"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}=Nre[e];return e==="no-messages"?v.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:v.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):v.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:[v.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&v.jsx("div",{children:t})]})}const Mre={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Ore={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function AN({status:e,className:t}){return v.jsx("span",{className:qe("inline-block w-2 h-2 rounded-full shrink-0",Mre[e],t),role:"status","aria-label":Ore[e]})}function xB({layout:e,variant:t="default"}){const n=Be(w=>w.proxies),r=Be(w=>w.proxyListLoaded),i=Be(w=>w.relayClientAuthIssue),s=Be(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){st.error("请先连接开发机");return}const k=x??w;p(w);try{const T=await E.selectProxy(w);if(!T.success){st.error(`无法连接 ${k}:${T.error??"未知错误"}`);return}dr("local",ln.proxyId,w),Be.getState().setProxy(w,x??null),Be.getState().setProxyOnline(!0),Be.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestAgentStatuses().then(A=>{const z=Wt.getState();for(const R of A)z.setAgentStatus(R.sessionId,R.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),E.requestSessionHistory().then(A=>Wt.getState().setHistorySessions(A)).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),d(!1),(e==="page"||o.pathname.startsWith("/chat/"))&&l("/sessions")}catch(T){const A=T instanceof Error?T.message:"未知错误";st.error(`无法连接 ${k}:${A}`)}finally{p(null)}}if(e==="page")return i==="missing_client_token"?v.jsx(nc,{variant:"client-token-missing"}):i==="invalid_client_token"?v.jsx(nc,{variant:"client-token-invalid"}):r?n.length===0?v.jsx(nc,{variant:"no-proxy"}):v.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[v.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),v.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.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:qe("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",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:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})]}):v.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:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});const g=n.find(w=>w.proxyId===s),b=(g==null?void 0:g.name)??(g==null?void 0:g.proxyId)??"未选择开发机";return v.jsxs(E1,{open:u,onOpenChange:d,children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:qe("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${b}`,children:[t==="default"&&v.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),v.jsx("span",{className:qe("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:b}),v.jsx(gl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),v.jsx(k1,{align:"start",className:"w-[260px] p-1",children:n.length===0?v.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):v.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.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:qe("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",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:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&s!==w.proxyId&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})})]})}const NN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,MN=MP,Dre=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return MN(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=NN(h)||NN(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,...g}=h;return Object.entries(g).every(b=>{let[w,x]=b;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return MN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Pre=Dre("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?KZ:"button";return v.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:qe(Pre({variant:t,size:n,className:e})),...i})}function Lre({delayDuration:e=0,...t}){return v.jsx(Ere,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Hf({...e}){return v.jsx(Cre,{"data-slot":"tooltip",...e})}function Uf({...e}){return v.jsx(kre,{"data-slot":"tooltip-trigger",...e})}function Wf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return v.jsx(Tre,{children:v.jsxs(Rre,{"data-slot":"tooltip-content",sideOffset:t,className:qe("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&v.jsx(Are,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Vv({...e}){return v.jsx(e1,{"data-slot":"sheet",...e})}function Ire({...e}){return v.jsx(xJ,{"data-slot":"sheet-trigger",...e})}function zre({...e}){return v.jsx(t1,{"data-slot":"sheet-portal",...e})}function Bre({className:e,...t}){return v.jsx(n1,{"data-slot":"sheet-overlay",className:qe("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Yv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return v.jsxs(zre,{children:[v.jsx(Bre,{className:t}),v.jsxs(r1,{"data-slot":"sheet-content",className:qe("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&v.jsxs(i1,{"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:[v.jsx(Of,{className:"size-4"}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function T1({className:e,...t}){return v.jsx("div",{"data-slot":"sheet-header",className:qe("flex flex-col gap-1.5 p-4",e),...t})}function Kv({className:e,...t}){return v.jsx(SI,{"data-slot":"sheet-title",className:qe("font-semibold text-foreground",e),...t})}function jre({className:e,...t}){return v.jsx(xI,{"data-slot":"sheet-description",className:qe("text-sm text-muted-foreground",e),...t})}function R1({...e}){return v.jsx(sne,{"data-slot":"dropdown-menu",...e})}function A1({...e}){return v.jsx(one,{"data-slot":"dropdown-menu-trigger",...e})}function N1({className:e,sideOffset:t=4,...n}){return v.jsx(ane,{children:v.jsx(lne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:qe("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function bo({className:e,inset:t,variant:n="default",...r}){return v.jsx(une,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:qe("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Kb({className:e,children:t,checked:n,...r}){return v.jsxs(dne,{"data-slot":"dropdown-menu-checkbox-item",className:qe("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[v.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:v.jsx(hne,{children:v.jsx(ra,{className:"size-4"})})}),t]})}function Im({className:e,inset:t,...n}){return v.jsx(cne,{"data-slot":"dropdown-menu-label","data-inset":t,className:qe("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Gb({className:e,...t}){return v.jsx(fne,{"data-slot":"dropdown-menu-separator",className:qe("-mx-1 my-1 h-px bg-border",e),...t})}const Fre={claude:"Claude Code",codex:"Codex"},ON=["claude","codex"];function Gv(e){return Fre[e]}function EB(e,t){return ON.indexOf(e)-ON.indexOf(t)}function z0(e){return e.provider??"claude"}const B0=60*1e3,j0=60*B0,$re=24*j0;function CB(e,t=Date.now()){const n=t-e;if(n<B0)return"刚刚";if(n<j0)return`${Math.floor(n/B0)} 分钟前`;if(n<$re)return`${Math.floor(n/j0)} 小时前`;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 DN={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 F0(e){return e.kind!=="terminal"?DN[e.state]:e.state==="terminated"?DN.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 Hre({session:e}){const t=F0(e);return v.jsx("span",{className:qe("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Ure({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.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:v.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Wre({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Ev(e.name),d=Vx(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?CB(o,n):null,g=e.mode==="pty"&&e.ptyOwner==="local-terminal",b=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return v.jsxs("li",{className:qe("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&v.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),v.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:[v.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[v.jsx(Hre,{session:e}),v.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&v.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&v.jsx(Ure,{mode:e.mode}),e.mode&&v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Gv(e.provider)}),v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),v.jsx("span",{className:qe("shrink-0",F0(e).text),children:F0(e).label}),y&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),v.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:v.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:v.jsx(Q9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end","data-slot":"session-row-menu",children:[i&&v.jsx(bo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&v.jsx(bo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:b})]})]})]})}function Sc({...e}){return v.jsx(e1,{"data-slot":"dialog",...e})}function qre({...e}){return v.jsx(t1,{"data-slot":"dialog-portal",...e})}function Vre({className:e,...t}){return v.jsx(n1,{"data-slot":"dialog-overlay",className:qe("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function xc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return v.jsxs(qre,{"data-slot":"dialog-portal",children:[v.jsx(Vre,{}),v.jsxs(r1,{"data-slot":"dialog-content",className:qe("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&v.jsxs(i1,{"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:[v.jsx(Of,{}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ec({className:e,...t}){return v.jsx("div",{"data-slot":"dialog-header",className:qe("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return v.jsxs("div",{"data-slot":"dialog-footer",className:qe("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&v.jsx(i1,{asChild:!0,children:v.jsx(St,{variant:"outline",children:"Close"})})]})}function dl({className:e,...t}){return v.jsx(SI,{"data-slot":"dialog-title",className:qe("text-lg leading-none font-semibold",e),...t})}function dc({className:e,...t}){return v.jsx(xI,{"data-slot":"dialog-description",className:qe("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 Yre({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=v.jsx(Kre,{title:e.title,modeTag:s}),l=v.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:CB(e.updatedAt,t)}),u=v.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return v.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:v.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:qe("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,v.jsx(k9,{className:qe("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Kre({title:e,modeTag:t}){return v.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[v.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&v.jsx(Gre,{mode:t})]})}function Gre({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:qe("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:v.jsx(n,{className:"size-3","aria-hidden":"true"})})}function kB({providerLabel:e}){return v.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:v.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[v.jsx(Q8,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),v.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Xre({now:e}){const t=Wt($=>$.historySessions),[n,r]=_.useState(null),[i,s]=_.useState(null),[o,l]=_.useState("json"),[u,d]=_.useState("default"),[h,p]=_.useState(!1),[y,g]=_.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=z0(D);let j=$.get(M);j||(j=new Map,$.set(M,j));const L=TB(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])=>EB(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:Ev(j.dir),sessions:j.sessions}))}))},[t]);function A($){s($),l(Zre($)),d("default")}async function z($,D,M){if(n)return;const j=Ot;if(!j){st.error("请先连接开发机");return}r($.id);const L=z0($);try{const O=await j.createSession({cwd:$.projectDir,mode:D,provider:L,resumeSessionId:$.id,...M?{permissionMode:M}:{}});if(O.error||!O.sessionId){st.error(`恢复失败:${O.error??"未知错误"}`);return}const Y={sessionId:O.sessionId,state:"idle",mode:O.mode??D,provider:O.provider??"claude"};Wt.getState().addSession(Y),k(`/chat/${O.sessionId}?mode=${O.mode??D}`),s(null)}catch(O){st.error(`恢复失败:${O instanceof Error?O.message:String(O)}`)}finally{r(null)}}function R(){const $=Ot;!$||h||(p(!0),$.requestSessionHistory().then(D=>Wt.getState().setHistorySessions(D)).catch(D=>{st.error(D instanceof Error?D.message:String(D))}).finally(()=>{p(!1)}))}function H($,D){const M=PN($,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,U=i?RB():[];return v.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[v.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[v.jsxs("button",{type:"button",onClick:()=>q&&g($=>!$),disabled:!q,"aria-expanded":q?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:qe("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[v.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",q?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),q?v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:R,disabled:h,"data-slot":"history-refresh",children:v.jsx(Tx,{className:qe("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!q&&v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),q&&y&&v.jsx("ul",{role:"list",className:"flex flex-col",children:T.map($=>{const D=b.has($.provider);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>P($.provider),"aria-expanded":!D,"data-slot":"history-provider-header","data-expanded":!D,className:qe("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:Gv($.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:$.sessions.length}),v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!D&&"rotate-90"),"aria-hidden":"true"})]}),!D&&v.jsx("ul",{role:"list",className:"flex flex-col",children:$.projects.map(M=>{const j=PN($.provider,M.dir),L=x.has(j);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>H($.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:qe("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),v.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&v.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(O=>v.jsx(Yre,{session:O,now:e,disabled:n!==null,loading:n===O.id,onClick:()=>A(O),modeTag:O.preferredMode},O.id))})]},j)})})]},$.provider)})}),v.jsx(Qre,{session:i,open:i!==null,modes:U,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:$=>{$||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&z(i,o,u)}})]})}function PN(e,t){return`${e}:${TB(t)}`}function TB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function RB(){return["json","pty"]}function Zre(e){const t=RB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Qre({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",g=hl("(min-width: 768px)");_.useEffect(()=>{t||p(!1)},[t]);const b=h?v.jsx(kB,{providerLabel:e?Gv(z0(e)):"Agent"}):v.jsxs("div",{className:"grid min-w-0 gap-4",children:[v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&v.jsx(LN,{checked:r==="json",label:"聊天",icon:v.jsx(kx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&v.jsx(LN,{checked:r==="pty",label:"终端",icon:v.jsx(Rx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[v.jsx(Xb,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),v.jsx(Xb,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),v.jsx(Xb,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=v.jsxs(v.Fragment,{children:[v.jsx(St,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),v.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 g?v.jsx(Sc,{open:t,onOpenChange:o,children:v.jsxs(xc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[v.jsxs(Ec,{className:"min-w-0",children:[v.jsx(dl,{children:h?"跳过全部审批?":"恢复会话"}),v.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,v.jsx(Yu,{children:w})]})}):v.jsx(Vv,{open:t,onOpenChange:o,children:v.jsxs(Yv,{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:[v.jsxs(T1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[v.jsx(Kv,{children:h?"跳过全部审批?":"恢复会话"}),v.jsx(jre,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),v.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:b}),v.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:v.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function LN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:qe("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,v.jsx("span",{className:"min-w-0 text-center",children:t}),v.jsx(ra,{className:qe("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Xb({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:qe("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[v.jsx("span",{className:qe("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&v.jsx("span",{className:qe("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),v.jsxs("span",{className:"grid min-w-0 gap-1",children:[v.jsx("span",{className:qe("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),v.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&v.jsx(ra,{className:qe("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Jre({...e}){return v.jsx(Zne,{"data-slot":"select",...e})}function eie({...e}){return v.jsx(Jne,{"data-slot":"select-value",...e})}function tie({className:e,size:t="default",children:n,...r}){return v.jsxs(Qne,{"data-slot":"select-trigger","data-size":t,className:qe("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,v.jsx(ere,{asChild:!0,children:v.jsx(gl,{className:"size-4 opacity-50"})})]})}function nie({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return v.jsx(tre,{children:v.jsxs(nre,{"data-slot":"select-content",className:qe("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[v.jsx(iie,{}),v.jsx(rre,{className:qe("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),v.jsx(sie,{})]})})}function rie({className:e,children:t,...n}){return v.jsxs(ire,{"data-slot":"select-item",className:qe("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[v.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:v.jsx(ore,{children:v.jsx(ra,{className:"size-4"})})}),v.jsx(sre,{children:t})]})}function iie({className:e,...t}){return v.jsx(are,{"data-slot":"select-scroll-up-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(Cx,{className:"size-4"})})}function sie({className:e,...t}){return v.jsx(lre,{"data-slot":"select-scroll-down-button",className:qe("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(gl,{className:"size-4"})})}function M1(e){return!e||e.endsWith("/")?e:`${e}/`}function oie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function aie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function lie(e,t,n){var o;if(t==="insert")return{currentPath:aie(e)||"./",query:oie(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:M1(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 cie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function uie(e,t){return`${M1(e)}${t.name}${t.isDir?"/":""}`}function IN(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 AB=_.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=Ei(F=>F.tree),h=Ei(F=>F.cwd),p=Ei(F=>F.homePath),y=i==="insert"?h:p||h,g=_.useMemo(()=>new Set(d.keys()),[d]),b=_.useMemo(()=>lie(t,i,{baseCwd:y,knownDirs:g}),[t,i,y,g]),w=b.currentPath,x=_.useMemo(()=>cie(y,w),[y,w]),E=b.query,k=_.useRef(new Set),[T,A]=_.useState(!1),[z,R]=_.useState(""),[H,P]=_.useState(!1);_.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const F=Ot;if(!F)return;let N=!1;return k.current.add(x),F.requestDirectoryList(x).then(W=>{N||Ei.getState().setDirEntries(W.path,W.entries)}).catch(()=>{N||Ei.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{N=!0}},[x,d]);const q=!d.has(x),U=_.useMemo(()=>{let F=d.get(x)??[];return o&&(F=F.filter(N=>N.isDir)),E&&(F=F.filter(N=>N.name.toLowerCase().includes(E))),F},[d,x,E,o]),[$,D]=_.useState(0);_.useEffect(()=>D(0),[w,E]),_.useEffect(()=>{A(!1),R("")},[x]),_.useEffect(()=>{$>=U.length&&U.length>0&&D(U.length-1)},[U.length,$]);const M=_.useRef(null),j=_.useRef(!1);_.useEffect(()=>{var N;if(!j.current)return;j.current=!1;const F=(N=M.current)==null?void 0:N.querySelector(`[data-entry-index="${$}"]`);F==null||F.scrollIntoView({block:"nearest"})},[$]);const L=_.useCallback(F=>{const N=uie(w,F);return i==="insert"?N.replace(/^\.\//,""):N},[w,i]);async function O(){const F=IN(x,z);if(!(!F||!r)){P(!0);try{const N=await r(F);if(!N)return;R(""),A(!1),n(M1(N))}finally{P(!1)}}}_.useImperativeHandle(u,()=>({handleKey(F){return U.length===0?!1:F.key==="ArrowDown"?(j.current=!0,D(N=>Math.min(U.length-1,N+1)),!0):F.key==="ArrowUp"?(j.current=!0,D(N=>Math.max(0,N-1)),!0):F.key==="Enter"&&!F.nativeEvent.isComposing?(n(L(U[$])),!0):!1}}),[U,$,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 v.jsxs("div",{className:Y,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?v.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?v.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||H,onClick:()=>A(F=>!F),children:"新建目录"}):null]}),T?v.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[v.jsx("input",{type:"text",value:z,onChange:F=>R(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!F.nativeEvent.isComposing&&(F.preventDefault(),O()),F.key==="Escape"&&(A(!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}),v.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:!IN(x,z)||H,onClick:()=>void O(),children:H?"创建中...":"创建目录"})]}):null]}):null,v.jsx("div",{className:K,children:U.length===0?v.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:q?"加载中...":"没有匹配的路径"}):v.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map((F,N)=>v.jsx("li",{children:v.jsx("button",{type:"button",onClick:()=>n(L(F)),onMouseEnter:()=>D(N),className:qe("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",N===$&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",F.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":F.isDir?"dir":"file","data-entry-index":N,children:v.jsxs("span",{className:"font-mono text-[13px]",children:[F.name,F.isDir?"/":""]})})},F.name))})})]})}),zN="工作目录不存在或不可访问:",die=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],NB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function hie(e,t){return t!==Xr.PATH_NOT_FOUND||!e.startsWith(zN)?null:e.slice(zN.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 fie(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function pie(e,t){return e!=="codex"||NB.some(n=>n.value===t)?t:"default"}async function mie({relay:e,agentCli:t,form:n,timeoutMs:r=Ux}){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=hie(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,g=((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:g,...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 gie({relay:e,timeoutMs:t=Ux}){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 vie({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),g=e==null?void 0:e[t];return v.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[v.jsxs("div",{className:"flex items-center justify-between",children:[v.jsx("span",{className:"text-sm",children:"Agent CLI"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsx(BN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),v.jsx(BN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),v.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?v.jsx(yie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):v.jsx(_ie,{provider:t,selectedCli:g,isDesktop:n,onOpenCliPathEditor:l})})]})}function BN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return v.jsxs(Hf,{children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:qe("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:na[e]}),v.jsx("span",{className:qe("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),v.jsx(Wf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:v.jsx("span",{className:"break-all font-mono text-xs",children:fie(e,n)})})]})}function yie({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[v.jsxs("label",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:"sr-only",children:"CLI 路径"}),v.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"}),v.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>v.jsx("option",{value:l},l))})]}),v.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[v.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:"取消"}),v.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 _ie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[v.jsx("p",{className:qe("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),v.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:"指定路径"})]})]}):v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),v.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:v.jsx(T8,{className:"size-4","aria-hidden":"true"})}),v.jsx("p",{className:qe("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function 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,g]=_.useState(!1),[b,w]=_.useState(!1),[x,E]=_.useState(null),[k,T]=_.useState(!1),[A,z]=_.useState(null),[R,H]=_.useState(""),[P,q]=_.useState(!1),U=_.useRef(null),$=_.useRef(e);$.current=e;const D=Js(),M=Ei(Se=>Se.homePath),j=Ei(Se=>Se.agentCli),L=hl("(min-width: 768px)");_.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),_.useEffect(()=>{if(!e||M&&j)return;const Se=Ot==null?void 0:Ot.requestProxyInfo();Se&&Se.then(Te=>{const Ie=Ei.getState();Ie.setHomePath(Te.homePath),Ie.setAgentCli(Te.agentCli)}).catch(Te=>{console.error("[create-session-dialog] requestProxyInfo failed",Te)})},[e,M,j]),_.useEffect(()=>{if(!k)return;function Se(Te){var Ke;const Ie=Te.target;Ie instanceof Node&&((Ke=U.current)!=null&&Ke.contains(Ie))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",Se,!0),()=>document.removeEventListener("pointerdown",Se,!0)},[k]);function O(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),g(!1),E(null),z(null),H(""),q(!1)}function Y(){if(h==="bypassPermissions"){g(!0);return}I()}async function K(){await I(),$.current&&g(!1)}const F=o==="codex"?NB:die,N=Kg(o,j),W=b||P||N.disabled;function G(Se){const Te=pie(Se,h);Te!==h&&p(Te)}async function I(Se){E(null),w(!0);try{const Te=await mie({relay:Ot,agentCli:j,form:{cwd:Se??i,name:n,provider:o,permissionMode:h,mode:u}});if(Te.type==="success"){if(Wt.getState().addSession(Te.session),!$.current)return;t(!1),O(),D(Te.route);return}if(Te.type==="missing_cwd"&&E(Te.path),st.error(Te.message),Te.type==="validation_error"||Te.type==="relay_missing")return}finally{w(!1)}}async function ne(Se){const Te=Ot;if(!Te)return st.error("请先连接开发机"),null;try{const Ie=await Te.createDirectory(Se);return Ie.success?(s(Ie.path),E(null),st.success("目录已创建"),Ie.path):(st.error(`目录创建失败:${Ie.error??"未知错误"}`),null)}catch(Ie){return st.error(Ie instanceof Error?Ie.message:String(Ie)),null}}function ie(Se){var Ie;const Te=j==null?void 0:j[Se];z(Se),H((Te==null?void 0:Te.command)??((Ie=Te==null?void 0:Te.suggestions)==null?void 0:Ie[0])??"")}async function se(){if(!A)return;const Se=R.trim();if(!Se){st.error("请输入 Agent CLI 路径");return}const Te=Ot;if(!Te){st.error("请先连接开发机");return}q(!0);try{const Ie=await Te.updateAgentCliPath(A,Se);if(Ie.error||!Ie.agentCli){st.error(`路径保存失败:${Ie.error??"未知错误"}`);return}Ei.getState().setAgentCli(Ie.agentCli),st.success(`${na[A]} 路径已保存`),z(null),H("")}catch(Ie){st.error(Ie instanceof Error?Ie.message:String(Ie))}finally{q(!1)}}function te(Se){d(Se),G(o)}function ue(Se){var Ie;const Te=Se.relatedTarget;Te instanceof Node&&((Ie=U.current)!=null&&Ie.contains(Te))||window.setTimeout(()=>T(!1),0)}const ge=y?v.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[v.jsx(kB,{providerLabel:na[o]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:b,children:"返回"}),v.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?"创建中...":"确认"})]})]}):v.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Se=>{Se.preventDefault(),Y()},children:[v.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[v.jsx("span",{className:"text-sm",children:"名称(可选)"}),v.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Se=>r(Se.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:"自动生成"})]}),v.jsxs("div",{ref:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:ue,children:[v.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),v.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:Se=>{s(Se.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?v.jsx(AB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ne,onSelect:Se=>{s(Se),E(null),T(!0)}}):null]}),x?v.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[v.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),v.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:x})]}):null,v.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"交互方式"}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>te("pty"),className:qe("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),v.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>te("json"),className:qe("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),v.jsx(vie,{agentCli:j,provider:o,isDesktop:L,editingCliProvider:A,cliPathInput:R,savingCliPath:P,onProviderChange:Se=>{l(Se),G(Se)},onOpenCliPathEditor:ie,onCliPathInputChange:H,onCancelCliPathEditor:()=>{z(null),H("")},onSaveCliPath:()=>void se()}),v.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"权限模式"}),v.jsxs(Jre,{value:h,onValueChange:Se=>p(Se),children:[v.jsx(tie,{className:"w-full",children:v.jsx(eie,{})}),v.jsx(nie,{children:F.map(Se=>v.jsx(rie,{value:Se.value,children:Se.label},Se.value))})]})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:b,children:"取消"}),v.jsx(St,{type:"submit",className:"min-h-11 md:min-h-0",disabled:W,children:b?"创建中...":"创建"})]})]});return L?v.jsx(Sc,{open:e,onOpenChange:t,children:v.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:[v.jsx(Ec,{children:v.jsx(dl,{children:y?"跳过全部审批?":"新建会话"})}),ge]})}):v.jsx(Vv,{open:e,onOpenChange:t,children:v.jsxs(Yv,{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:[v.jsx(T1,{className:"px-0 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:y?"跳过全部审批?":"新建会话"})}),ge]})})}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(g){g.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 v.jsx(Sc,{open:e,onOpenChange:r,children:v.jsx(xc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:v.jsxs("form",{className:"grid gap-4",onSubmit:g=>void y(g),children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"重命名会话"}),v.jsx(dc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),v.jsxs("div",{className:"grid gap-2",children:[v.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),v.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:qe("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:g=>{l(g.target.value),u&&d(null)}}),u?v.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),v.jsx(St,{type:"submit",disabled:h,children:"保存"})]})]})})})}function bie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function wie(e){return(e==null?void 0:e.kind)==="terminal"}function Sie(e){return bie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:wie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function zm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Sie(t);function s(){t&&(r(t),n(!1))}return v.jsx(Sc,{open:e,onOpenChange:n,children:v.jsxs(xc,{"data-slot":"session-termination-dialog",children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:i.title}),v.jsx(dc,{children:i.description})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),v.jsx(St,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function MB(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 xie(e){if(e.session.state==="error")return"error";const t=MB(e);return t==="disconnected"?e.session.state:t}function OB({layout:e}){const t=Wt(N=>N.sessions),n=Wt(N=>N.sessionListLoaded),r=Wt(N=>N.agentStatusBySessionId),i=Wt(N=>N.ptyStateBySessionId),s=Wt(N=>N.renameSession),o=Zt(N=>N.bySessionId),l=nU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Be(N=>!!N.selectedProxyId),p=!Be(N=>N.proxyListLoaded)||d&&!n,y=Js(),[g,b]=_.useState(!1),[w,x]=_.useState(!1),[E,k]=_.useState(null),[T,A]=_.useState(null),{creatingTerminal:z,createTerminal:R}=DB(),[H,P]=_.useState(new Set),[q,U]=_.useState(()=>Date.now());_.useEffect(()=>{const N=setInterval(()=>U(Date.now()),6e4);return()=>clearInterval(N)},[]);function $(N,W){y(`/chat/${N}?mode=${W??"json"}`,{replace:!1})}function D(N){const W=N.sessionId,G=Ot;if(!G){st.error("请先连接开发机");return}G.sendControl({type:"session_terminate",sessionId:W}),Wt.getState().removeSession(W),Zt.getState().clearSession(W),W===u&&y("/sessions"),(N==null?void 0:N.mode)==="pty"&&N.ptyOwner==="local-terminal"?st.info("已断开页面连接,本地终端仍在运行"):st.info("正在终止会话",{duration:1500})}async function M(N,W){const G=Ot;if(!G)throw new Error("请先连接开发机");const I=await G.renameSession(N,W);if(!I.success)throw new Error(I.error??"重命名失败");s(N,I.name??W),st.success("已重命名会话")}function j(N){P(W=>{const G=new Set(W);return G.has(N)?G.delete(N):G.add(N),G})}function L(N){var I;const W=N.mode==="json"&&(((I=o[N.sessionId])==null?void 0:I.pendingApprovals.some(ne=>ne.status==="pending"))??!1),G=xie({session:N,agentStatus:r[N.sessionId],ptyState:i[N.sessionId],hasPendingApproval:W});return G===N.state?N:{...N,state:G}}const O=t.length>0;if(e==="sidebar"&&(p||!d))return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70",children:p?"连接中...":"请先连接开发机"}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]});if(e==="page"&&p)return v.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:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});if(e==="page"&&!d)return v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsx("div",{className:"flex-1",children:v.jsx(nc,{variant:"no-proxy"})}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]});const Y=v.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",O?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=O?v.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:Eie(t).map(N=>v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>j(N.provider),"aria-expanded":!H.has(N.provider),className:qe("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:Cie(N.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:N.sessions.length}),v.jsx(Kh,{className:qe("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!H.has(N.provider)&&"rotate-90"),"aria-hidden":"true"})]}),H.has(N.provider)?null:v.jsx("ul",{role:"list",className:"flex flex-col",children:N.sessions.map(W=>v.jsx(Wre,{session:L(W),selected:W.sessionId===u,now:q,onClick:()=>$(W.sessionId,W.mode),onRename:()=>k(W),onTerminate:()=>A(W)},W.sessionId))})]},N.provider))}):v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),F=v.jsx(Xre,{now:q});return e==="page"?v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:v.jsxs(St,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>x(!0),children:[v.jsx(bP,{"aria-hidden":"true"}),"新建"]})}),v.jsx(Tie,{open:w,creatingTerminal:z,onOpenChange:x,onCreateAgent:()=>{x(!1),b(!0)},onCreateTerminal:()=>void R(()=>x(!1))}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]}):v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:N=>{N||A(null)},onConfirm:D}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:N=>{N||k(null)},onRename:M})]})}function Eie(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])=>kie(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Cie(e){return e==="terminal"?"终端":Gv(e)}function kie(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:EB(e,t)}function DB(){const e=Js(),[t,n]=_.useState(!1);async function r(i){if(!t){n(!0);try{const s=await gie({relay:Ot});if(s.type!=="success"){st.error(s.message);return}Wt.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function jN({compact:e=!1}){const[t,n]=_.useState(!1),[r,i]=_.useState(!1),s=_.useRef(!1),o=Be(w=>!!w.selectedProxyId),{creatingTerminal:l,createTerminal:u}=DB();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 g=v.jsxs(St,{variant:"outline","data-slot":"create-session-trigger",className:qe(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!o&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!o,onClick:o?void 0:y,children:[v.jsx(bP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate",children:"新建"})]}),b=o?v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:g}),v.jsxs(N1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:w=>{s.current&&(s.current=!1,w.preventDefault())},children:[v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:h,children:[v.jsx(_P,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:l,onSelect:p,children:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),l?"正在创建终端会话...":"终端会话"]})]})]}):g;return v.jsxs(v.Fragment,{children:[o?b:v.jsxs(Hf,{open:o?void 0:r,onOpenChange:o?void 0:i,children:[v.jsx(Uf,{asChild:!0,children:b}),v.jsx(Wf,{side:"top",children:o?"新建会话":"请先连接开发机"})]}),v.jsx(Ih,{open:t,onOpenChange:n})]})}function Tie({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=_.useRef(!1);function o(l){s.current=!0,l()}return v.jsx(Vv,{open:e,onOpenChange:n,children:v.jsxs(Yv,{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:[v.jsx(T1,{className:"px-1 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:"新建"})}),v.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[v.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:[v.jsx(_P,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.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:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Rie="0.5.4",Aie={version:Rie},Nie={playback:"playback",capture:"play-and-record"};function Mie(){return typeof navigator>"u"?null:navigator.audioSession??null}function Oie(){return{setMode:()=>{},release:()=>{}}}class Die{constructor(t=Mie){vt(this,"leases",new Map);vt(this,"session",null);vt(this,"baselineType",null);vt(this,"nextLeaseId",1);vt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Oie();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(Nie[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 O1=new Die,$0=64,FN=-60,PB=32;function $N(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-FN)/-FN));return e<0?-r:r}function HN(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 Pie(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 Lie(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 LB{constructor(t,n=24e3,r={}){vt(this,"nextStartTime",0);vt(this,"activityEndToken",0);vt(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=Pie(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*PB/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=Lie(n.subarray(l,u));this.scheduleTimer(()=>{var g,b,w,x;(b=(g=this.options).onActivityLevel)==null||b.call(g,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 Zb={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},UN="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",Iie=800,WN=300,zie=1600;function H0(e,t){return e.filter(n=>!n.model||n.model===t)}function qN({label:e,children:t,help:n}){return v.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:[v.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.jsx("div",{className:"mt-2 min-w-0",children:t}),n?v.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Bm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=_.useState(!1),u=_.useId(),d=n.find(g=>g.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(g=>!g.disabled),y=!!IB(h).detail;return v.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:g=>{g.currentTarget.contains(g.relatedTarget)||l(!1)},children:[v.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.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(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[v.jsx(VN,{label:h,muted:!d&&!t}),v.jsx(gl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?v.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(g=>{const b=g.value===t;return v.jsxs("button",{type:"button",role:"option","aria-label":g.label,"aria-selected":b,disabled:g.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:()=>{g.disabled||(r(g.value),l(!1))},children:[v.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:b?v.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),v.jsx(VN,{label:g.label})]},g.value)})}):null,s?v.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function VN({label:e,muted:t=!1}){const n=IB(e);return v.jsxs("span",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?v.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Bie({scrollRef:e}={}){const[t,n]=_.useState(Zb),[r,i]=_.useState(String(Zb.turnIdleSeconds)),[s,o]=_.useState(()=>Cm()),[l,u]=_.useState(""),[d,h]=_.useState(!1),[p,y]=_.useState(!1),[g,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(ue=>{if(!te){if(ue.error||!ue.config){b({kind:"error",message:ue.error??"读取语音设置失败"});return}n(ue.config),i(String(ue.config.turnIdleSeconds)),u(""),h(!1),y(!0),b({kind:"idle"})}}).catch(ue=>{te||b({kind:"error",message:ue instanceof Error?ue.message:"读取语音设置失败"})}),()=>{te=!0}},[]),_.useEffect(()=>{const se=Ot;if(!se||!p)return;let te=!1;return se.requestVoiceCapabilities({region:t.region}).then(ue=>{if(!te){if(ue.error||!ue.capabilities){o(Cm());return}o(ue.capabilities)}}).catch(()=>{te||o(Cm())}),()=>{te=!0}},[t.region,p]),_.useEffect(()=>()=>{G(),I()},[]);const A=_.useMemo(()=>g.kind==="loading"?"读取中...":g.kind==="saving"?"保存中...":g.kind==="testing"?"正在测试语音合成":g.kind==="playingTest"?"正在播放测试音频":g.kind==="testPassed"?"测试通过":g.kind==="saved"?"已保存":g.kind==="error"?g.message:null,[g]),z=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",R=_.useMemo(()=>H0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=R.some(se=>se.value===t.ttsVoice)?t.ttsVoice:"",q=R.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",U=_.useMemo(()=>Hie(r),[r]),$=U?null:"请输入正整数秒数",D=q??$,M=z||!!D,j=_.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=_.useMemo(()=>GN(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),O=_.useMemo(()=>Uie(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),Y=_.useMemo(()=>GN(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:U??Zb.turnIdleSeconds}}async function F(){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 ue=performance.now();try{const ge=await se.updateVoiceConfig(te),Se=performance.now()-ue;if(Se<WN&&await $ie(WN-Se),!ge.success||ge.error||!ge.config){b({kind:"error",message:ge.error??"保存语音设置失败"});return}n(ge.config),i(String(ge.config.turnIdleSeconds)),u(""),h(!1),b({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,b(Te=>Te.kind==="saved"?{kind:"idle"}:Te)},zie),se.requestVoiceCapabilities({region:ge.config.region}).then(Te=>{Te.capabilities&&o(Te.capabilities)}).catch(()=>{o(Cm())})}catch(ge){b({kind:"error",message:ge instanceof Error?ge.message:"保存语音设置失败"})}}async function N(){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(ue){b({kind:"error",message:KN(ue)});return}b({kind:"testing"});try{const[ue]=await Promise.all([se.testVoiceConfig(K()),te.ready]);if(!ue.success||ue.error){G(),b({kind:"error",message:ue.error??"语音配置测试失败"});return}const ge=await ne(ue,te.context);b({kind:"playingTest",transcript:ue.transcript}),k.current=setTimeout(()=>{k.current=null,G(),b({kind:"testPassed",transcript:ue.transcript})},ge)}catch(ue){G(),b({kind:"error",message:KN(ue)})}}function W(){G();const se=O1.acquire("playback");x.current=se;try{const te=Fie();return w.current=te,{context:te,ready:YN(te)}}catch(te){throw se.release(),x.current=null,te}}function G(){var se,te,ue;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,(ue=x.current)==null||ue.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 ue=se.audioSampleRate??24e3,ge=jie(se.audioBase64);if(ge.byteLength===0||ge.byteLength%2!==0)throw new Error("测试音频数据无效");await YN(te);const Se=new LB(te,ue);E.current=Se,Se.enqueue(ge);const Te=Math.ceil(ge.byteLength/2/ue*1e3);return Math.max(Iie,Te)}function ie(se){var te;return((te=H0(s.ttsVoices,se)[0])==null?void 0:te.value)??""}return v.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(),F()},children:[v.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:v.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:v.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[v.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsxs("div",{className:"min-w-0",children:[v.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),v.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),v.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"})]})}),v.jsx(qN,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:v.jsxs("div",{className:"flex min-w-0 gap-2",children:[v.jsxs("div",{className:"relative min-w-0 flex-1",children:[v.jsx(xP,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),v.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:`${UN} w-full pl-9`})]}),t.configured&&v.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:[v.jsx(X8,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),v.jsx(Bm,{label:"地域",value:t.region,options:j,onChange:se=>n(te=>({...te,region:se==="intl"?"intl":"cn"}))}),v.jsx(Bm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:se=>n(te=>({...te,asrModel:se}))}),v.jsx(Bm,{label:"语音合成模型",value:t.ttsModel,options:O,onChange:se=>n(te=>({...te,ttsModel:se,ttsVoice:ie(se)}))}),v.jsx(Bm,{label:"语音音色",value:P,options:Y,placeholder:R.length===0?"暂无可用音色":"请选择音色",onChange:se=>n(te=>({...te,ttsVoice:se})),help:q}),v.jsx(qN,{label:"结束停顿时间(秒)",help:$,children:v.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:se=>i(se.target.value),className:`${UN} w-full`})})]})})}),v.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[v.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),v.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[A?v.jsx("div",{role:g.kind==="error"?"alert":"status","aria-live":"polite",className:g.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:A}):null,v.jsxs(St,{type:"button",variant:"outline",disabled:M,onClick:()=>void N(),children:[v.jsx(kP,{className:"size-4","aria-hidden":"true"}),"测试"]}),v.jsxs(St,{type:"submit",disabled:M,children:[v.jsx(z8,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function jie(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 Fie(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function YN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function KN(e){return e instanceof Error?e.message:"语音配置测试失败"}function $ie(e){return new Promise(t=>setTimeout(t,e))}function Hie(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function GN(e,t){const n=e.map(r=>({value:r.value,label:zB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Uie(e,t,n){const r=e.map(i=>{const s=H0(t,i.value).length===0;return{value:i.value,label:`${zB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function IB(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 zB(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 Wie=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],qie=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],D1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function BB(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 Vie(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Yie(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Kie(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function U0({open:e,onOpenChange:t}){const n=Be(q=>q.relayUrl),r=Be(q=>q.latencyMonitorEnabled),i=Be(q=>q.setLatencyMonitorEnabled),s=Be(q=>q.sessionIdleNotificationsEnabled),o=Be(q=>q.setSessionIdleNotificationsEnabled),l=Be(q=>q.inputModePreference),u=Be(q=>q.setInputModePreference),d=Be(q=>q.themePreference),h=Be(q=>q.setThemePreference),p=Be(q=>q.ptyScrollTraceEnabled),y=Be(q=>q.setPtyScrollTraceEnabled),[g,b]=_.useState("menu"),[w,x]=_.useState({kind:"idle"}),E=_.useRef(null),k=_.useRef(null),T=UZ(),A=_.useMemo(()=>Wx().osName==="iPad",[]),z=_.useCallback(async q=>{if(!q){o(!1);return}const U=await yZ();if(U==="granted"){o(!0);return}if(U==="denied"){st.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){st.info("未授予通知权限,会话通知保持关闭");return}st.error("当前浏览器不支持系统通知")},[o]),R=_.useCallback(async q=>{x({kind:"loading"});try{const U=await fetch(Vie(n),{cache:"no-store",signal:q});if(!U.ok)throw new Error(`HTTP ${U.status}`);const $=await U.json();if($.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:$.version??"未知",uptime:$.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;x({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);_.useEffect(()=>{if(!e){b("menu");return}},[e]),_.useEffect(()=>{if(!e||g!=="version")return;const q=new AbortController;return R(q.signal),()=>q.abort()},[R,e,g]),_.useEffect(()=>{if(!e||g!=="voice")return;const q=window.requestAnimationFrame(()=>{var U;(U=E.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(q)},[e,g]);const H=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${BB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return v.jsx(Sc,{open:e,onOpenChange:t,children:v.jsxs(xc,{className:qe("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="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":g,focusSurfaceOnOpen:!0,ref:E,showCloseButton:g==="menu",children:[v.jsx(Ec,{className:qe(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"flex items-start gap-2",children:[v.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:v.jsx(vv,{className:"size-4","aria-hidden":"true"})}),v.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[v.jsx(dl,{children:Yie(g)}),v.jsx(dc,{className:"max-w-[28rem] leading-5",children:Kie(g)})]})]}),g==="voice"?v.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):v.jsxs(v.Fragment,{children:[v.jsx(dl,{children:"设置"}),v.jsx(dc,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?v.jsx(Gie,{relayVersion:H,relayDetail:P,relayMuted:w.kind==="error"}):g==="relay-token"?v.jsx(Zie,{saved:T}):g==="clients"?v.jsx(nse,{}):g==="voice"?v.jsx(Bie,{scrollRef:k}):v.jsx(Xie,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,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 Gie({relayVersion:e,relayDetail:t,relayMuted:n}){return v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsx(ZN,{icon:v.jsx(CP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Aie.version,detail:"当前浏览器加载的版本"}),v.jsx(ZN,{icon:v.jsx(TP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Xie({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:g,onOpenClients:b,onOpenVersion:w}){return v.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:[v.jsxs(cu,{title:"服务",children:[v.jsx(jm,{icon:v.jsx(N9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),v.jsx(jm,{icon:v.jsx(xP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),v.jsx(jm,{icon:v.jsx(r7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:b})]}),v.jsx(cu,{title:"外观",children:v.jsx(XN,{icon:v.jsx(Y8,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Wie,onValueChange:n})}),v.jsx(cu,{title:"通知",children:v.jsx(Jb,{icon:v.jsx(O9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?v.jsx(cu,{title:"交互",children:v.jsx(XN,{icon:v.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:qie,onValueChange:i})}):null,v.jsxs(cu,{title:"高级诊断",children:[v.jsx(Jb,{icon:v.jsx(of,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),v.jsx(Jb,{icon:v.jsx(vP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),v.jsx(cu,{title:"关于",children:v.jsx(jm,{icon:v.jsx(TP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({title:e,children:t}){return v.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[v.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),v.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function XN({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=_.useId(),l=_.useId();return v.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[v.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,v.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 v.jsx("button",{type:"button",role:"radio","aria-checked":d,className:qe("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Zie({saved:e}){const t=_.useId(),n=_.useId(),[r,i]=_.useState(""),[s,o]=_.useState(null),l=()=>{UL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}$L(h),l()},d=()=>{HL(),l()};return v.jsxs("form",{className:D1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[v.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[v.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),v.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?v.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),v.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?v.jsx(St,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,v.jsx(St,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Qie(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Jie(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Qie(e)}function ese(e){return lX(e)}function tse(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return BB(t)}function Qb({label:e,value:t,title:n}){return v.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[v.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),v.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function nse(){const e=Be(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(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);_.useEffect(()=>{h()},[h]);const p=_.useCallback(async y=>{const g=Ot;if(!g){o("Relay 未连接。");return}u(y),o(null);try{const b=await g.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 v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:v.jsx(Tx,{className:qe("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?v.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?v.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 g=y.current===!0,b=l===y.clientId;return v.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:v.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[v.jsxs("div",{className:"min-w-0 space-y-1.5",children:[v.jsx("div",{className:"min-w-0",children:v.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:ese(y)})}),v.jsxs("div",{className:"space-y-1",children:[v.jsx(Qb,{label:"已连接",value:tse(y.connectedAt)}),y.proxyId?v.jsx(Qb,{label:"连接到",value:Jie(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?v.jsx(Qb,{label:"来源 IP",value:y.remoteAddress}):null]})]}),g?v.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:"当前设备"}):v.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:[v.jsx(f8,{className:"size-3.5","aria-hidden":"true"}),b?"断开中...":"断开"]})]})},y.clientId)})]})}function Jb({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=_.useId(),o=_.useId();return v.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:[v.jsx("div",{className:qe("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),v.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),v.jsx("span",{className:qe("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:v.jsx("span",{className:qe("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function jm({icon:e,label:t,detail:n,onClick:r}){const i=_.useId(),s=_.useId();return v.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:[v.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}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),v.jsx(Kh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function ZN({icon:e,label:t,value:n,detail:r,muted:i=!1}){return v.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[v.jsx("div",{className:qe("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[v.jsx("div",{className:"text-sm text-muted-foreground",children:t}),v.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const rse="xterm-helper-textarea";function ise(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(rse)?!1:(e.blur(),!0)}function QN(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&&sse(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function sse(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 ose({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=_.useRef(null),r=_.useCallback(()=>{e&&ise()},[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,QN(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=_.useCallback(l=>{r(),t&&(QN(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function ase({className:e}){const t=Be(o=>o.sidebarCollapsed),n=Be(o=>o.toggleSidebarCollapsed),[r,i]=_.useState(!1),s=ose();return t?v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:qe("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[v.jsx(eM,{collapsed:!0,onClick:n}),v.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),v.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[v.jsx(JN,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),v.jsx(jN,{compact:!0})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]}):v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:qe("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[v.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:v.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx(VP,{className:"text-[13px]",slot:"sidebar-brand"}),v.jsx(eM,{collapsed:!1,onClick:n})]}),v.jsx("div",{className:"mt-2.5",children:v.jsx(xB,{layout:"dropdown",variant:"sidebarChrome"})})]})}),v.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:v.jsx("div",{className:"flex-1 min-h-0",children:v.jsx(OB,{layout:"sidebar"})})}),v.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:[v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(jN,{})}),v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(JN,{onClick:()=>i(!0)})})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]})}function JN({compact:e=!1,tooltipSide:t="top",onClick:n}){return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:qe("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[v.jsx(RP,{className:"size-4","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),v.jsx(Wf,{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 eM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?x8:w8;return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:qe("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:v.jsx(r,{className:qe("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),v.jsx(Wf,{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 lse=1500,cse=300,tM=70,nM=35;function jB({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 g=h();l.current<g.length?(l.current+=1,r(g.slice(0,l.current)),d=setTimeout(p,tM)):(o.current="paused",d=setTimeout(p,lse))}else y==="paused"?(o.current="deleting",d=setTimeout(p,nM)):y==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),d=setTimeout(p,nM)):(u.current+=1,o.current="waiting",d=setTimeout(p,cse)):(o.current="typing",d=setTimeout(p,tM))};return d=setTimeout(p,500),()=>clearTimeout(d)},[e]),v.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[v.jsx("span",{className:"text-green-500",children:"> "}),v.jsx("span",{className:"text-foreground/90",children:n}),v.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const FB=["DEV Anywhere","/unlimited @anytime"];function use({subtitle:e,action:t}){return v.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:v.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[v.jsx(jB,{texts:FB,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),v.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?v.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const dse=3e3,hse=1e4,Fm=12,fse=4,rM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},pse={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function ew(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 iM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function $B(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function mse(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 gse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Bh(e.rttMs):"等待检测"}function vse(){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 sM(e){dr("local",ln.latencyMonitorPosition,JSON.stringify(e))}function yse(){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 tw(e,t){const n=yse(),r=Fm,i=Fm,s=Math.max(r,n.width-t.width-Fm),o=Math.max(i,n.height-t.height-Fm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function _se(){const e=Be(R=>R.latencyMonitorEnabled),t=Be(R=>R.connected),n=Be(R=>R.proxyOnline),r=Be(R=>R.selectedProxyId),[i,s]=_.useState(pse),[o,l]=_.useState(()=>vse()),u=_.useRef(!1),d=_.useRef(null),h=_.useRef(null),p=_.useRef(!1),y=_.useMemo(()=>(Object.values(i).sort((R,H)=>iM(H.state)-iM(R.state))[0]??{state:"idle"}).state,[i]),g=$B(y);async function b(){if(u.current)return;const R=Ot;if(!R||!t){const U=uu("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:uu("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:uu("未连接开发机")}));const[H,P,q]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:H.status==="fulfilled"?ew(H.value):uu(H.reason instanceof Error?H.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?ew(P.value):uu(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:q.status==="fulfilled"?ew(q.value):uu(q.reason instanceof Error?q.reason.message:"测速失败")}),u.current=!1}if(_.useEffect(()=>{if(!e)return;let R=!1,H=null;const P=async()=>{await b(),!R&&(H=setTimeout(P,document.hidden?hse:dse))};return P(),()=>{R=!0,u.current=!1,H&&clearTimeout(H)}},[e,t,n,r]),_.useEffect(()=>{if(!e||!o)return;const R=d.current;if(!R)return;const H=R.getBoundingClientRect(),P=tw(o,{width:H.width,height:H.height});P.x===o.x&&P.y===o.y||(l(P),sM(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 H=R.currentTarget.getBoundingClientRect();h.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,originX:H.left,originY:H.top,width:H.width,height:H.height,dragging:!1},(q=(P=R.currentTarget).setPointerCapture)==null||q.call(P,R.pointerId)}function k(R){const H=h.current;if(!H||H.pointerId!==R.pointerId)return;const P=R.clientX-H.startX,q=R.clientY-H.startY;if(!H.dragging&&Math.hypot(P,q)<fse)return;H.dragging=!0,R.preventDefault();const U=tw({x:H.originX+P,y:H.originY+q},{width:H.width,height:H.height});l(U)}function T(R){var $,D;const H=h.current;if(!H||H.pointerId!==R.pointerId||(h.current=null,(D=($=R.currentTarget).releasePointerCapture)==null||D.call($,R.pointerId),!H.dragging))return;R.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=R.clientX-H.startX,q=R.clientY-H.startY,U=tw({x:H.originX+P,y:H.originY+q},{width:H.width,height:H.height});l(U),sM(U)}function A(R){var P,q;const H=h.current;!H||H.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 v.jsxs(E1,{children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{ref:d,type:"button",className:qe("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",mse(g)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Bh(i.webRelay.rttMs)},开发机 ${Bh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:T,onPointerCancel:A,onClickCapture:z,children:[v.jsx(vP,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),v.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",Bh(i.webRelay.rttMs)]}),v.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Bh(w.rttMs)]}),v.jsx(gl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),v.jsxs(k1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[v.jsxs("div",{className:"flex items-start justify-between gap-3",children:[v.jsxs("div",{children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void b(),children:v.jsx(Tx,{className:"size-3","aria-hidden":"true"})})]}),v.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(rM).map(R=>v.jsx(bse,{label:rM[R],measurement:i[R]},R))})]})]})}function bse({label:e,measurement:t}){const n=$B(t.state);return v.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:[v.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx("span",{className:qe("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),v.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:gse(t)})]})]})}const HB="/__dev_anywhere_debug/browser-state-dumps",wse=1500,Sse=10,nw=80,P1=500,xse=["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"],Ese=["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 oM(){if(typeof window>"u")return"off";const e=XB("debugDump");return e==="auto"?"auto":e!==null||Dse("debugInput")?"manual":"off"}function Cse(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:Ase(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:aM(document.activeElement),selection:Nse(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>aM(i)).filter(i=>!!i),root:UB(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(()=>lM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>lM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function kse(e="manual"){const t=Cse(e);return Tse(t)}async function Tse(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Rse(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:HB}}catch(r){const i=ZB(r),s=Mse(e.createdAt);return Ose(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Rse(e){const t=await fetch(HB,{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 UB(e,t,n){if(n.count>=wse||t>Sse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=cM(e.textContent??"");return u?{kind:"text",text:Xv(u,P1)}:{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,nw))u.nodeType===Node.TEXT_NODE&&!cM(u.textContent??"")||r.push(UB(u,t+1,n));s.length>nw&&(i=s.length-nw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:GB(e),attrs:WB(e),rect:qB(e),scroll:VB(e),style:YB(e)},l=KB(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function aM(e){if(!(e instanceof HTMLElement))return null;const t=KB(e);return{path:GB(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:WB(e),rect:qB(e),scroll:VB(e),style:YB(e),...t?{value:t}:{}}}function Ase(){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 WB(e){const t={};for(const n of xse){const r=e.getAttribute(n);r!==null&&(t[n]=Xv(r,500))}return t}function qB(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 VB(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 YB(e){const t=window.getComputedStyle(e),n={};for(const r of Ese)n[r]=t.getPropertyValue(r);return n}function KB(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Xv(e.value,P1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Nse(){var e;try{return Xv(((e=window.getSelection())==null?void 0:e.toString())??"",P1)}catch{return null}}function GB(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 Mse(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Ose(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 Dse(e){return XB(e)!==null}function XB(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 lM(e){return e?Gg(e.slice(-200)):null}function du(e){try{return Gg(e())}catch(t){return{error:ZB(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 cM(e){return e.replace(/\s+/g," ").trim()}function Xv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Zi(e){return Math.round(e*100)/100}function ZB(e){return e instanceof Error?e.message:String(e)}const Pse=500,Lse=1e3,Ise=60;function zse(){const[e,t]=_.useState(()=>oM()),[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(oM());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 kse(b);return o.current=w,s(w),(b==="manual"||w.status==="failed")&&Bse(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=A=>{d.current>=Ise||(b(),h.current=window.setTimeout(()=>{h.current=null;const z=Date.now(),R=Lse-(z-u.current);if(R>0){h.current=window.setTimeout(()=>w(A),R);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${A}`)},Pse))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=A=>w(A.type);return x.forEach(A=>window.addEventListener(A,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(T=window.visualViewport)==null||T.addEventListener("scroll",E),()=>{var A,z;b(),x.forEach(R=>window.removeEventListener(R,E,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",E),(z=window.visualViewport)==null||z.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",g=jse(i);return v.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:[g?v.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:g}):null,v.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?v.jsx(Lu,{className:"size-3.5 animate-spin","aria-hidden":"true"}):v.jsx(r8,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{children:y})]})]})}function Bse(e){if(e.status==="saved"){st.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){st.info(`诊断已下载: ${e.filename}`);return}st.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function jse(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Fse(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 L1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:Fse(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 g=h.indexOf(y);g>=0&&g!==h.length-1&&(h.splice(g,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 QB(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 $se="dev_anywhere_pty_input_latency_trace",uM=80,Hse=1e4,Use=new TextDecoder;let Wse=0;const Ku=new Map,Cc=L1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:$se,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function qse(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Gse)}function Vse(e,t){if(!Cc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Wse}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Qse(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),z1(s,r),Ku.set(e,s),qf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function dM(e,t){if(!e||!Cc.isEnabled())return;const n=performance.now(),r=Xse(e.sessionId,e.inputId);r&&(r.sentAt=n),qf({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 Yse(e,t,n){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=toe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&eoe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));qf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:noe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Kse(e,t,n=1){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));qf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Zse(e,s))}function Gse(){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 qf(e){Cc.append(e)}function I1(e,t){const n=Ku.get(e)??[];return z1(n,t),Ku.set(e,n),n}function z1(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>Hse;(i||s)&&e.splice(n,1)}e.length>uM&&e.splice(0,e.length-uM)}function Xse(e,t){return(Ku.get(e)??[]).find(n=>n.inputId===t)??null}function Zse(e,t){if(!Cc.isEnabled())return;const n=performance.now(),r=I1(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)}qf({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:B1(r,n),details:i>0?`paint=${i}`:""}),z1(r,n)}function B1(e,t){const n=e[0];return n?t-n.startedAt:null}function Qse(e){return e==="\r"||e===`
|
|
502
502
|
`?"enter":e.startsWith("\x1B")?"escape":Jse(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function Jse(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 eoe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function toe(e){try{return Use.decode(e)}catch{return""}}function noe(e){return e.filter(Boolean).join(" ")}function Ks(e,t){if(!e||!t)return;const n=Vse(e,t),r=tc;if(!r){dM(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});dM(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const hM=-1;function roe({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=hM,i(e,"\r");return}if(s.current===hM){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function ioe(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=Dx(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 soe({target:e,sendRawInput:t}){return roe({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function ooe({sendRawInput:e=Ks}){const t=Be(d=>d.connected),n=Be(d=>d.proxyOnline),r=Be(d=>d.selectedProxyId),i=Wt(d=>d.sessions),s=Wt(d=>d.ptyStateBySessionId),o=Wt(d=>d.agentStatusBySessionId),l=Wt(d=>d.ptyAutoYesBySessionKey),u=i.map(d=>ioe({proxyId:r,session:d,ptyState:s[d.sessionId],agentStatus:o[d.sessionId],autoYesBySessionKey:l,connected:t,proxyOnline:n})).filter(d=>d!==null);return v.jsx(v.Fragment,{children:u.map(d=>v.jsx(soe,{target:d,sendRawInput:e},d.key))})}function aoe(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))},loe=function(e,t){return t},Ln=function(e,t,n){n&&typeof n=="function"&&n(e,t)},coe=function(e){return-Math.cos(e*Math.PI)/2+.5},uoe=function(e){return e},doe=function(e){return e*e},hoe=function(e){return e*(2-e)},foe=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},poe=function(e){return e*e*e},moe=function(e){return--e*e*e+1},goe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},voe=function(e){return e*e*e*e},yoe=function(e){return 1- --e*e*e*e},_oe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},boe=function(e){return e*e*e*e*e},woe=function(e){return 1+--e*e*e*e*e},Soe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},JB={easeOut:coe,linear:uoe,easeInQuad:doe,easeOutQuad:hoe,easeInOutQuad:foe,easeInCubic:poe,easeOutCubic:moe,easeInOutCubic:goe,easeInQuart:voe,easeOutQuart:yoe,easeInOutQuart:_oe,easeInQuint:boe,easeOutQuint:woe,easeInOutQuint:Soe},e3=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Ys=function(e){e.mounted&&(e3(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function t3(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Ys(e),e.animation=function(){if(!e.mounted)return e3(e.animation);var o=new Date().getTime()-i,l=o/n,u=JB[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function xoe(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=xoe(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):t3(e,r,n,function(g){g!==1?e.isAnimating=!0:e.isAnimating=!1;var b=l+h*g,w=u+p*g,x=d+y*g;s(b,w,x)})}}function Eoe(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 Coe=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}},j1=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=Eoe(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,h=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,g=l.newDiffHeight,b=Coe(u,h,y,d,p,g,!!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,A=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),A!=null&&(b.maxPositionY=A*t),b},gf=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=j1(e,t);return e.bounds=n,n};function Vf(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 g=gf(e,l-p,d+p,r),b=gf(t,u-y,h+y,r);return{x:g,y:b}}function Zv(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,g=Vf(p,y,i,s,0,0,null);return g}var fM=1e-7;function Yf(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,fM),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,fM)}var pM=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=Kf(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},mM=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},koe=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}},Toe=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 Roe(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,g=h.maxPositionY,b=h.minPositionY,w=n>p||n<y,x=r>g||r<b,E=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>g?d.offsetHeight:e.setup.minPositionY||0,T=Zv(e,E,k,i,e.bounds,l||u),A=T.x,z=T.y;return{scale:i,positionX:w?A:n,positionY:x?z:r}}}function n3(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=Vf(t,n,l,s,r,i,o),g=y.x,b=y.y;e.setState(d,g,b)}}var Aoe=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,g=l?d:p;return{x:y,y:g}},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 Noe=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},Moe=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 Ooe(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 gM(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:gf(e,s,o,i)}function Doe(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var rw=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 Poe(e,t,n){var r,i,s=Noe(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,g=h.sensitivityTouch,b=h.sensitivityMouse,w=Date.now();if(o&&l&&d){var x=Doe(d),E=(r={},r[nl.TOUCH]=g,r[nl.MOUSE]=b,r)[n],k=(i={},i[nl.TOUCH]=y,i[nl.MOUSE]=p,i)[n],T=t.x-o.x,A=t.y-o.y,z=rw(T/x,k,E),R=rw(A/x,k,E),H=w-l,P=T*T+A*A,q=rw(Math.sqrt(P)/H,k,E);e.velocity={velocityX:z,velocityY:R,total:q}}e.lastMousePosition=t,e.velocityTime=w}}function Loe(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Moe(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,g=r.limitToBounds,b=r.autoAlignment,w=r.zoomAnimation,x=r.panning,E=x.lockAxisY,k=x.lockAxisX,T=w.animationType,A=b.sizeX,z=b.sizeY,R=b.velocityAlignmentTime,H=R,P=Ooe(e,u),q=Math.max(P,H),U=fl(e,A),$=fl(e,z),D=U*i.offsetWidth/100,M=$*i.offsetHeight/100,j=d+D,L=h-D,O=p+M,Y=y-M,K=e.state,F=new Date().getTime();t3(e,T,q,function(N){var W=e.state,G=W.scale,I=W.positionX,ne=W.positionY,ie=new Date().getTime()-F,se=ie/H,te=JB[b.animationType],ue=1-te(Math.min(1,se)),ge=1-N,Se=I+o*ge,Te=ne+l*ge,Ie=gM(Se,K.positionX,I,k,g,h,d,L,j,ue),Ke=gM(Te,K.positionY,ne,E,g,y,p,Y,O,ue);if(I!==Se||ne!==Te){e.setState(G,Ie,Ke);var gt=e.props.onPanning;gt&>(kn(e),{})}})}}function vM(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?Toe(e,t):koe(e,t)}function r3(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=Roe(e);y&&El(e,y,d,h)}}function yM(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=Aoe(e,t,n),h=d.x,p=d.y,y=fl(e,l),g=fl(e,u);Poe(e,{x:h,y:p},r),n3(e,h,p,y,g)}}function Ioe(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,g=(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||g<w,E=!t&&n&&n.total>.1&&x;E?Loe(e):r3(e)}}function F1(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Yf(Jl(t,2),s,o,0,!1),d=Gu(e,u),h=Zv(e,n,r,u,d,l),p=h.x,y=h.y;return{scale:u,positionX:p,positionY:y}}function $1(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,g=r>=o&&r<=l,b=h||g;if((r>=1||u)&&r3(e),!(b||!i||!e.mounted)){var w=t||i.offsetWidth/2,x=n||i.offsetHeight/2,E=r<o?o:l,k=F1(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 _M(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 iw={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"}},W0={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},i3=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:iw.scale,g=Math.min(Math.max(y,h),p),b=gf((i=e.initialPositionX)!==null&&i!==void 0?i:iw.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=gf((l=e.initialPositionY)!==null&&l!==void 0?l:iw.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:g,scale:g,positionX:b,positionY:w}},bM=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]=_M(_M([],Zl[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},s3=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=Yf(Jl(p,3),l,o,h,!1);return y};function o3(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 g=y.disabled?0:r,b=l.offsetWidth,w=l.offsetHeight,x=(b/2-h)/d,E=(w/2-p)/d,k=s3(e,t,n),T=F1(e,k,x,E);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,z=A.onZoomStart,R=A.onZoom,H=A.onZoomStop,P=new MouseEvent("mousemove",{bubbles:!0}),q=kn(e);Ln(q,P,z),Ln(q,P,R),El(e,T,g,i);var U=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;U&&U.setTimeout(function(){e.mounted&&Ln(kn(e),P,H)},g)}function a3(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,h=o.centerOnInit,p=i3(e.props),y=e.state,g=y.scale,b=y.positionX,w=y.positionY;if(l){var x=p.positionX,E=p.positionY;if(h&&u){var k=H1(p.scale,l,u);x=k.positionX,E=k.positionY}var T=j1(e,p.scale),A=Vf(x,E,T,d,0,0,l),z={scale:p.scale,positionX:A.x,positionY:A.y};if(!(g===p.scale&&b===p.positionX&&w===p.positionY)){r==null||r();var R=e.props,H=R.onZoomStart,P=R.onZoom,q=R.onZoomStop,U=new MouseEvent("mousemove",{bubbles:!0}),$=kn(e);Ln($,U,H),Ln($,U,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),U,q)},t)}}}function zoe(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 Boe(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(),g=t.getBoundingClientRect(),b=zoe(t,s,o,l),w=b.x,x=b.y,E=g.width/l.scale,k=g.height/l.scale,T=s.offsetWidth/E,A=s.offsetHeight/k,z=Yf(n||Math.min(T,A),h,p,0,!1),R=(y.width-E*z)/2,H=(y.height-k*z)/2,P=(y.left-w)*z+R+r,q=(y.top-x)*z+H+i,U=j1(e,z),$=Vf(P,q,U,d,0,0,s),D=$.x,M=$.y;return{positionX:D,positionY:M,scale:z}}var joe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),o3(e,1,t,n,r)}},Foe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),o3(e,-1,t,n,r)}},$oe=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 g={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};El(e,g,i,s)}}},Hoe=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),a3(e,t,n)}},Uoe=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=H1(t||i.scale,s,o);El(e,l,n,r)}}},Woe=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=Boe(e,u,n,s,o);El(e,d,r,i)}}},q0=function(e){return{instance:e,state:e.state,zoomIn:joe(e),zoomOut:Foe(e),setTransform:$oe(e),resetTransform:Hoe(e),centerView:Uoe(e),zoomToElement:Woe(e)}},qoe=function(e){return{instance:e,state:e.state}},kn=function(e){var t={};return Object.assign(t,qoe(e)),Object.assign(t,q0(e)),t},sw=!1;function ow(){try{var e={get passive(){return sw=!0,!1}};return e}catch{return sw=!1,sw}}var $m=".".concat(W0.wrapperClass),Kf=function(e,t){return t.some(function(n){return e.matches("".concat($m," ").concat(n,", ").concat($m," .").concat(n,", ").concat($m," ").concat(n," *, ").concat($m," .").concat(n," *"))})},vf=function(e){e&&clearTimeout(e)},Voe=function(e){return Number.parseFloat(e.toFixed(8))},l3=function(e,t,n){var r=Voe(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},H1=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 Yoe(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Koe(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var c3=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=Kf(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},Goe=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=c3(e,t);if(l)return!1;var u=t.target,d=Kf(u,o);if(d)return!1;var h=e.isPressingKeys(s);return!!h},Xoe=function(e){return e?e.deltaY<0?1:-1:0};function Zoe(e,t){var n=Xoe(e),r=loe(t,n);return r}function u3(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 Qoe=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,g=h.disabled;if(!o)throw new Error("Wrapper is not mounted");var b=s+t*n,w=r?!1:!g,x=Yf(b,d,u,y,w&&!p);return x},d3=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},Joe=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=Kf(o,i);return!u},eae=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},tae=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}},h3=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))},nae=5,rae=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 g=t/r,b=g*n,w=(b-n)*(y/nae),x=n+w,E=x===1/0?0:Jl(x,10);return Yf(E,o,s,h,!p&&!u)},f3=160,p3=100,iae=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))},sae=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,g=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=Zoe(t,null),T=b?E*Math.abs(t.deltaY):E,A=Qoe(e,k,T,!t.ctrlKey);if(u!==A){var z=Gu(e,A),R=u3(t,s,u),H=x||w===0||h||g,P=d&&H,q=Zv(e,R.x,R.y,A,z,P),U=q.x,$=q.y;e.previousWheelEvent=t,e.setState(A,U,$),Ln(kn(e),t,r),Ln(kn(e),t,i)}},oae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;vf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&($1(e,t.x,t.y),e.wheelAnimationTimer=null)},p3);var s=d3(e,t);s&&(vf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Ln(kn(e),t,r),Ln(kn(e),t,i))},f3))},aae=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))},lae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;vf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&($1(e,t.x,t.y),e.wheelAnimationTimer=null)},p3);var s=d3(e,t);s&&(vf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Ln(kn(e),t,r),Ln(kn(e),t,i))},f3))},m3=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}},cae=function(e,t){var n=h3(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=m3(t),Ys(e)},uae=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,g=l.panning,b=h.disabled,w=h.size,x=y.allowPanning;if(!(r===null||!n)){var E=tae(t,o,n);if(!(!Number.isFinite(E.x)||!Number.isFinite(E.y))){var k=h3(t),T=rae(e,k),A=m3(t),z=o/T,R=(A.x-((s==null?void 0:s.x)||0))*z,H=(A.y-((s==null?void 0:s.y)||0))*z;if(!(T===o&&R===0&&H===0)){e.pinchPreviousCenter=A;var P=Gu(e,T),q=b||w===0||d,U=u&&q,$=Zv(e,E.x,E.y,T,P,U),D=$.x,M=$.y;if(e.pinchMidpoint=E,e.lastDistance=k,g.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,F=M+H,N=Vf(K,F,P,u,O,Y,i),W=N.x,G=N.y;e.setState(T,W,G)}}}}},dae=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,$1(e,t==null?void 0:t.x,t==null?void 0:t.y)},g3=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;vf(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,Ln(kn(e),t,n)},r)},hae=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),a3(e,o,l,function(){return Ln(kn(e),t,i)}),g3(e,t)};function fae(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function pae(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,g=h.step,b=h.animationTime,w=h.animationType;if(!p&&!r){if(y==="reset")return hae(e,t);if(!s)return console.error("No ContentComponent found");var x=fae(y,e.state.scale),E=s3(e,x,g);if(o!==E){Ln(kn(e),t,u);var k=u3(t,s,o),T=F1(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),g3(e,t)}}}var mae=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=Kf(u,l);return!p},gae=(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=bM(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=ow(),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=ow(),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=ow();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=c3(n,r);s&&(iae(n,r),sae(n,r),oae(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=Goe(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,h=d.positionX,p=d.positionY,y=h-r.deltaX,g=p-r.deltaY,b=o?h:y,w=l?p:g,x=n.setup.autoAlignment,E=x.sizeX,k=x.sizeY,T=fl(n,E),A=fl(n,k);b===h&&w===p||(aae(n,r),n3(n,b,w,T,A),Ln(kn(n),r,i),lae(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=pM(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),vM(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=mM(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),yM(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&&(Ioe(n,i),Ln(kn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=Joe(n,r);o&&(cae(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=eae(n);o&&(r.preventDefault(),r.stopPropagation(),uae(n,r),Ln(kn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(dae(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,g=pM(n,r);if(p){if(!g)return;Ys(n),vM(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=mM(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];yM(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=mae(n,r);s&&pae(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=H1(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):l3(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),Yoe(n.props.ref,s)},this.props=t,this.setup=bM(this.props),this.state=i3(this.props)}return e})(),Qv=Ge.createContext(null),vae=function(e,t){return typeof e=="function"?e(t):e},yae=Ge.forwardRef(function(e,t){var n=_.useRef(new gae(e)).current,r=vae(e.children,q0(n));return _.useImperativeHandle(t,function(){return q0(n)},[n]),_.useEffect(function(){n.update(e)},[n,e]),v.jsx(Qv.Provider,Ms({value:n},{children:r}))});Ge.forwardRef(function(e,t){var n=_.useRef(null),r=_.useContext(Qv);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]),v.jsx("div",Ms({},e,{ref:Koe([n,t])}))});function _ae(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 bae=`.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=Lme(t);return!n||/\s/.test(n)||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||cE(n)||n.split("/").includes("...")?null:n}function zme(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 Pme.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function Bme(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(y4,""),n=t.split("/").pop()??t;return/[A-Za-z_-]/.test(n)}function jme(e){const t=Ime(e);return!t||zme(t)||!Bme(t)?null:Dme.test(t)?{kind:"image-preview",path:t}:y4.test(t)?{kind:"file-download",path:t}:null}const Fme=16,$me=24,wh=6,Hme=425,qh=-1;function Zm(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 Ume({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]),g=_.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)},Hme),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||!Zm(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>=Fme&&(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||!Zm(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),g(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?(g(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)<=$me&&(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,g,n,i,p,t,e]),E=_.useCallback($=>{const D=d.current;return!D||!Zm(D,$)?null:(h(D),d.current=null,D.longPressed?(g(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,g,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]),A=_.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&&Zm(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]),H=_.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]),U=_.useCallback($=>{const D=d.current;D&&($.preventDefault(),$.stopPropagation(),y(D))},[y]);return{onPointerDownCapture:k,onPointerMoveCapture:T,onPointerUpCapture:A,onPointerCancelCapture:z,onTouchStartCapture:R,onTouchMoveCapture:H,onTouchEndCapture:P,onTouchCancelCapture:q,onContextMenuCapture:U}}function Wme({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:g,onHandleDragMove:b,onHandleDragEnd:w,onHandleDragCancel:x}){const E=_.useRef(null),k=_.useRef(null),T=_.useRef(null),A=_.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,A.current=!1,E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)},[]),H=_.useCallback(()=>{var F;E.current=null;const L=k.current;if(!L||!t||!i())return;const O=t.getBoundingClientRect(),{dx:Y,dy:K}=Z5({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}),(F=T.current)==null||F.call(T,L)),E.current=requestAnimationFrame(H)},[t,i,p,y]),P=_.useCallback((L,O)=>{k.current=L,T.current=O,E.current===null&&(E.current=requestAnimationFrame(H))},[H]);_.useEffect(()=>R,[R]),_.useEffect(()=>{if(!t)return;const L=O=>{A.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(),A.current=!0,u(L)},[u,R]),U=_.useCallback(L=>{d(L),P(L,d)},[d,P]),$=_.useCallback(L=>{R(),h(L)},[h,R]),D=Ume({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:q,onLongPressMove:U,onLongPressEnd:$}),M=_.useCallback((L,O)=>{O.preventDefault(),O.stopPropagation(),R(),A.current=!0,g(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))},F=W=>{const G={clientX:W.clientX,clientY:W.clientY};Y(),z.current=null,R(),w(L,G)},N=()=>{Y(),z.current=null,R(),x(L)};Y=()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",F),window.removeEventListener("pointercancel",N)},z.current=Y,window.addEventListener("pointermove",K,{passive:!1}),window.addEventListener("pointerup",F,{once:!0}),window.addEventListener("pointercancel",N,{once:!0})},[x,w,b,g,R,P]),j=_.useCallback((L,O)=>{if(z.current||!(O.touches[0]??O.changedTouches[0]))return;O.preventDefault(),O.stopPropagation(),A.current=!0,g(L);let K=()=>{};const F=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))},N=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",F),window.removeEventListener("touchend",N),window.removeEventListener("touchcancel",W)},z.current=K,window.addEventListener("touchmove",F,{passive:!1}),window.addEventListener("touchend",N,{once:!0}),window.addEventListener("touchcancel",W,{once:!0})},[x,w,b,g,R,P]);return{pointerHandlers:D,stopPtySelectionGesture:R,handlePtySelectionHandlePointerDown:M,handlePtySelectionHandleTouchStart:j}}const qme=8;function Vme(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:g,onPreviewPath:b}=e,w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(!1),A=_.useRef(null),z=_.useRef(null),R=_.useRef(""),H=_.useRef(null),[P,q]=_.useState(null),[U,$]=_.useState(null),[D,M]=_.useState(null),j=_.useMemo(()=>Nme(u),[u]),L=_.useCallback((fe,Ne)=>{const We=window.visualViewport;return v4({clientX:fe,clientY:Ne,viewportWidth:(We==null?void 0:We.width)??window.innerWidth,viewportHeight:(We==null?void 0:We.height)??window.innerHeight,viewportOffsetLeft:(We==null?void 0:We.offsetLeft)??0,viewportOffsetTop:(We==null?void 0:We.offsetTop)??0})},[]),O=_.useCallback((fe,Ne)=>{const We=n.current,tt=r.current;return!We||!tt?null:Mme({terminal:We,host:tt,anchor:fe,focus:Ne})},[n,r]),Y=_.useCallback((fe,Ne)=>{const We=Ne??jme(fe);return z.current=We,M(We),We},[]),K=_.useCallback(fe=>{const Ne=window.visualViewport;return Ome({handles:fe,viewportWidth:(Ne==null?void 0:Ne.width)??window.innerWidth,viewportHeight:(Ne==null?void 0:Ne.height)??window.innerHeight,viewportOffsetLeft:(Ne==null?void 0:Ne.offsetLeft)??0,viewportOffsetTop:(Ne==null?void 0:Ne.offsetTop)??0})},[]),F=_.useCallback(()=>{const fe=w.current,Ne=x.current;if(!fe||!Ne){$(null);return}const We=O(fe,Ne);if($(We),!We){q(null);return}q(tt=>tt&&K(We))},[O,K]),N=_.useCallback(()=>{var fe,Ne;(fe=H.current)==null||fe.call(H),E.current=null,k.current=null,w.current=null,x.current=null,T.current=!1,A.current=null,z.current=null,R.current="",(Ne=n.current)==null||Ne.clearSelection(),q(null),$(null),M(null)},[n]),W=_.useCallback((fe="")=>{w.current=null,x.current=null,T.current=!1,z.current=null,R.current=fe,q(null),$(null),M(null)},[]),G=_.useCallback(({clientX:fe,clientY:Ne})=>{const We=n.current,tt=r.current;d({blur:!1}),k.current={clientX:fe,clientY:Ne},E.current=We&&tt?Wh({terminal:We,host:tt,clientX:fe,clientY:Ne}):null},[d,n,r]),I=_.useCallback(({clientX:fe,clientY:Ne,draggedHandle:We="focus"})=>{const tt=n.current,it=r.current,mt=w.current,Nt=x.current;if(!tt||!it||!mt)return null;const he=Wh({terminal:tt,host:it,clientX:fe,clientY:Ne});if(!he)return null;const Re=We==="anchor"?he:mt,nt=We==="focus"?he:Nt??mt;w.current=Re,x.current=nt,T.current=!0;const Xe=sv({terminal:tt,anchor:Re,focus:nt});return R.current=(Xe==null?void 0:Xe.text)??"",Y((Xe==null?void 0:Xe.text)??""),$(Xe?O(Re,nt):null),Xe},[O,Y,n,r]),ne=_.useCallback(({point:fe,clientX:Ne,clientY:We,showToolbar:tt=!0})=>{const it=n.current,mt=r.current;if(!it||!mt)return!1;A.current=null;const Nt=fe?q2({terminal:it,point:fe}):null,he=Nt??(fe?WS({terminal:it,point:fe}):W2({terminal:it,host:mt,clientX:Ne,clientY:We}));if(!(he!=null&&he.text))return!1;w.current=he.anchor,x.current=he.focus,R.current=he.text,Y(he.text,Nt==null?void 0:Nt.pathAction);const Re=O(he.anchor,he.focus);return $(Re),tt&&q(Re?K(Re):L(Ne,We)),!0},[O,L,K,Y,n,r]),ie=_.useCallback(()=>{const fe=w.current,Ne=x.current;if(!fe||!Ne){q(null);return}const We=O(fe,Ne);$(We),q(We?K(We):null)},[O,K]),se=_.useCallback(fe=>{var tt,it;const Ne=((it=(tt=n.current)==null?void 0:tt.getSelection)==null?void 0:it.call(tt))??"",We=Y(Ne);R.current=Ne,w.current=null,x.current=null,T.current=!1,$(null),q(We?L(fe.clientX,fe.clientY):null)},[L,Y,n]);_.useEffect(()=>{const fe=r.current;if(!fe)return;let Ne=!1;const We=mt=>{var he,Re;if(mt.pointerType!=="mouse"||mt.button!==0)return;const Nt=mt.target;!(Nt instanceof Element)||!Nt.closest(".xterm")||(Ne=!0,W(((Re=(he=n.current)==null?void 0:he.getSelection)==null?void 0:Re.call(he))??""))},tt=mt=>{if(mt.pointerType!=="mouse"||!Ne)return;Ne=!1;const Nt={clientX:mt.clientX,clientY:mt.clientY};window.setTimeout(()=>se(Nt),0)},it=()=>{Ne=!1};return fe.addEventListener("pointerdown",We,!0),window.addEventListener("pointerup",tt,!0),window.addEventListener("pointercancel",it,!0),()=>{fe.removeEventListener("pointerdown",We,!0),window.removeEventListener("pointerup",tt,!0),window.removeEventListener("pointercancel",it,!0)}},[W,se,n,r]),_.useLayoutEffect(()=>{if(!P&&!U)return;const fe=Ne=>{const We=Ne.target;We instanceof Element&&We.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]')||N()};return document.addEventListener("pointerdown",fe,!0),document.addEventListener("touchstart",fe,!0),()=>{document.removeEventListener("pointerdown",fe,!0),document.removeEventListener("touchstart",fe,!0)}},[N,U,P]),_.useEffect(()=>{if(!s||!P)return;const fe=()=>{const Ne=A.current;Ne&&s.scrollLeft===Ne.scrollLeft&&s.scrollTop===Ne.scrollTop||N()};return s.addEventListener("scroll",fe,{passive:!0}),()=>s.removeEventListener("scroll",fe)},[N,s,P]);const te=U!==null;_.useLayoutEffect(()=>{var fe;te&&((fe=i.current)==null||fe.relayout(),F())},[te,l,F,i]),_.useEffect(()=>{te&&F()},[te,F,o.scrollLeft,o.scrollTop]),_.useEffect(()=>{if(!te)return;const fe=window.visualViewport;let Ne=0,We=0;const tt=()=>{cancelAnimationFrame(Ne),window.clearTimeout(We),Ne=requestAnimationFrame(()=>{F(),We=window.setTimeout(()=>{Ne=requestAnimationFrame(()=>F())},160)})};return tt(),window.addEventListener("resize",tt),fe==null||fe.addEventListener("resize",tt),fe==null||fe.addEventListener("scroll",tt),()=>{cancelAnimationFrame(Ne),window.clearTimeout(We),window.removeEventListener("resize",tt),fe==null||fe.removeEventListener("resize",tt),fe==null||fe.removeEventListener("scroll",tt)}},[te,F]);const ue=_.useCallback(({clientX:fe,clientY:Ne})=>{const We=n.current,tt=r.current;if(!We||!tt)return;const it=Wh({terminal:We,host:tt,clientX:fe,clientY:Ne})??E.current;if(We.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:fe,clientY:Ne,showToolbar:!1})},[ne,n,r]),ge=_.useCallback(({clientX:fe,clientY:Ne})=>{I({clientX:fe,clientY:Ne}),q(null)},[I]),Se=_.useCallback(({clientX:fe,clientY:Ne})=>{const We=n.current,tt=r.current;if(!We||!tt)return;const it=w.current,mt=Wh({terminal:We,host:tt,clientX:fe,clientY:Ne}),Nt=mt??x.current,he=E.current,Re=k.current,nt=Re?Math.hypot(fe-Re.clientX,Ne-Re.clientY)>=qme:!1,Xe=he??mt;if(!T.current&&!nt&&R.current){ie(),E.current=null,k.current=null;return}const at=!T.current&&!nt&&Xe?q2({terminal:We,point:Xe}):null,Vt=nt?mt??Nt:Nt,$t=(T.current||nt)&&it&&Vt?sv({terminal:We,anchor:it,focus:Vt}):at??W2({terminal:We,host:tt,clientX:fe,clientY:Ne})??(he?WS({terminal:We,point:he}):null);if(E.current=null,k.current=null,!($t!=null&&$t.text)){N();return}w.current=$t.anchor,x.current=$t.focus,R.current=$t.text,Y($t.text,at==null?void 0:at.pathAction);const Yt=O($t.anchor,$t.focus);$(Yt),q(Yt?K(Yt):L(fe,Ne))},[N,O,L,K,Y,ie,n,r]),Te=_.useCallback(()=>{var We;const fe=n.current,Ne=((We=fe==null?void 0:fe.getSelection)==null?void 0:We.call(fe))||R.current;Ne&&m4(Ne,{allowLegacyFallback:!0}).then(tt=>{N(),tt==="failed"?st.error("复制失败"):st.success("已复制")})},[N,n]),Ie=_.useCallback(()=>{const fe=z.current;fe&&(fe.kind==="image-preview"?b(fe.path):g(fe.path),N())},[N,g,b]),Ke=_.useCallback(()=>w.current!==null,[]),gt=_.useCallback(()=>{q(null)},[]),Oe=_.useCallback((fe,{clientX:Ne,clientY:We})=>{I({clientX:Ne,clientY:We,draggedHandle:fe}),q(null)},[I]),de=_.useCallback((fe,Ne)=>{Ne&&I({...Ne,draggedHandle:fe}),R.current&&ie()},[I,ie]),Ee=_.useCallback(()=>{q(null)},[]);_.useEffect(()=>{},[N,O,K,t,Y,n]);const Qe=Wme({terminalRef:n,containerEl:s,suppressPtyFocus:d,focusPtyInput:h,isSelectionActive:Ke,onTap:p,isTapCandidate:y,onLongPressCandidateStart:G,onLongPressStart:ue,onLongPressMove:ge,onLongPressEnd:Se,onHorizontalScrollIntent:fe=>{var Ne;return(Ne=i.current)==null?void 0:Ne.markHorizontalScrollIntent(fe)},onSelectionAutoscroll:fe=>{A.current=fe},onHandleDragStart:gt,onHandleDragMove:Oe,onHandleDragEnd:de,onHandleDragCancel:Ee});return H.current=Qe.stopPtySelectionGesture,{pointerHandlers:Qe.pointerHandlers,ptySelectionToolbar:P,ptySelectionHandles:U,ptySelectionPathAction:D,ptySelectionHandleMetrics:j,copyPtySelection:Te,openPtySelectionPathAction:Ie,handlePtySelectionHandlePointerDown:Qe.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Qe.handlePtySelectionHandleTouchStart}}function Yme(){return Be(e=>e.ptyScrollTraceEnabled)}const Kme=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function Y2(e){return Kme.has(e)}function pE(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!Y2(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>Y2(r.type))??null}function Gme(e){return`${e.startsWith("@")?e:`@${e}`} `}function K2(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 _4(e){const t=pE(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await f4(t),r=await e.relay.uploadClipboardImage(e.sessionId,n);if(!r.success||!r.path)throw new Error(r.error??"剪贴板图片上传失败");return{path:r.path,pathMention:Gme(r.path)}}function Xme(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 Zme({sessionId:e,terminalRef:t,onAfterPaste:n}){return _.useCallback(async r=>{var u;const i=r.clipboardData,s=!!pE(i),o=s?null:Xme(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Ot;if(!l){st.error("请先连接开发机");return}if(s){const d=st.loading("图片上传中...");try{const h=await _4({clipboardData:i,relay:l,sessionId:e});if(st.dismiss(d),!h)return;Ks(e,h.pathMention)}catch(h){st.error(h instanceof Error?h.message:String(h),{id:d});return}}else if(o){const d=await xf({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 Qme=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),G2={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:cfe};function Jme({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function ege({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function tge({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function nge({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:Qme.has(n)}const X2=8,rge=32;function ige({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+X2:t?rge:X2}function sge(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 oge(e){const{sessionId:t,sessionKind:n,ptyOwner:r,active:i=!0,containerEl:s,spacerRef:o,xtermHostRef:l,mobileControlsHeight:u}=e,d=yme(),h=Sme(),p=Yme(),{openImagePreview:y}=_3(),g=_.useRef(null),b=_.useRef(null),w=_.useRef([]),x=_.useRef(null),E=_.useRef(null),k=_.useRef(i),T=_.useRef(i),A=_.useRef(!1),z=_.useRef(!1),R=_.useRef(!1),H=_.useRef(null),P=_.useRef(null),q=_.useRef(null),U=_.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,F]=_.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[N,W]=_.useState(!1),[G,I]=_.useState(!1),[ne,ie]=_.useState({resultIndex:-1,resultCount:0}),se=Be(be=>be.connected),te=Be(be=>be.proxyOnline),ue=Be(be=>be.ptyFontSize),ge=Be(be=>be.inputModePreference),Se=Be(be=>be.adaptiveInputModality),Te=Be(be=>be.setAdaptiveInputModality),Ie=Se==="hardware",Ke=r==="proxy-hosted"||n==="terminal",gt=hl("(pointer: coarse), (hover: none)"),{bottomOffset:Oe,layoutBottomInset:de}=fE(),Ee=ge==="hardware",Qe=tge({touchEditingSurface:gt,inputModePreference:ge,detectedPhysicalKeyboard:Ie,softKeyboardDetected:Oe>0}),fe=gt&&!Qe,Ne=Qe?0:Oe,We=Ne>0,tt=Qe?0:de;M.current=Qe,_.useEffect(()=>{k.current=i},[i]),_.useEffect(()=>{A.current=d.ready},[d.ready]);const it=_.useCallback(()=>k.current&&A.current,[]);_.useEffect(()=>{Ne>0&&W(!0)},[Ne]);const mt=wme({containerEl:s,xtermHostRef:l,terminalRef:g}),{ptyInputFocused:Nt,suppressPtyFocus:he,focusPtyInput:Re,handleFocusCapture:nt,handleBlurCapture:Xe}=mt,at=Jme({softKeyboardEditingSurface:fe,ptyInputFocused:Nt,keyboardOpen:We});D.current=fe&&(at||Ne>0),Y.current={keyboardOffset:Ne,hasSeenSoftKeyboard:N,showMobilePtyControls:at,touchEditingSurface:gt,ptyInputFocused:Nt,containerPaddingBottom:Y.current.containerPaddingBottom,mobileControlsBottomInset:tt};const Vt=h.clearNewFramesWhileAway;P.current||(P.current=B2(()=>{var be;(be=E.current)==null||be.relayout()})),q.current||(q.current=B2(()=>{var we,Fe;const be=U.current??{reason:"rawInput",force:!1};U.current=null,(we=E.current)==null||we.traceRawInputFollowFire(),(Fe=E.current)==null||Fe.scrollToBottom(be.reason,be.force?{force:!0}:void 0),Vt()}));const $t=_.useCallback(()=>{O.current!==null&&(cancelAnimationFrame(O.current),O.current=null)},[]),Yt=_.useCallback(()=>{L.current=!0,$t()},[$t]),Xt=_.useCallback(()=>{var be;!L.current||document.visibilityState==="hidden"||((be=E.current)==null||be.preparePageResumeRestore(),$t(),O.current=requestAnimationFrame(()=>{O.current=requestAnimationFrame(()=>{O.current=null;const we=E.current;we&&(we.restorePageResume(),Vt(),L.current=!1)})}))},[$t,Vt]);_.useEffect(()=>()=>{var be,we;(be=P.current)==null||be.dispose(),(we=q.current)==null||we.dispose(),$t(),P.current=null,q.current=null},[$t]),_.useEffect(()=>{const be=()=>{Yt()},we=()=>{if(document.visibilityState==="hidden"){be();return}Xt()};return document.addEventListener("visibilitychange",we),window.addEventListener("pagehide",be),window.addEventListener("pageshow",Xt),window.addEventListener("focus",Xt),()=>{document.removeEventListener("visibilitychange",we),window.removeEventListener("pagehide",be),window.removeEventListener("pageshow",Xt),window.removeEventListener("focus",Xt),$t()}},[$t,Yt,Xt]),_.useEffect(()=>{const be=T.current;if(T.current=i,be!==i){if(!i){Yt();return}Xt()}},[i,Yt,Xt]);const Pt=_.useCallback((be="rawInput",we)=>{var ft,Lt;const Fe=U.current,rt=(Fe==null?void 0:Fe.force)===!0||(we==null?void 0:we.force)===!0;U.current={reason:(we==null?void 0:we.force)===!0||!Fe?be:Fe.reason,force:rt},(ft=E.current)==null||ft.traceRawInputFollowScheduled(be),(Lt=q.current)==null||Lt.schedule()},[]),zt=_.useCallback(()=>{var be,we;(be=x.current)==null||be.setOutputPaused(!1),(we=x.current)==null||we.flushOutput()},[]),Mn=_.useCallback((be,we)=>{var Fe;!be.includes("\r")&&!be.includes(`
|
|
635
635
|
`)||(Fe=E.current)==null||Fe.resetHorizontalScroll(we,{holdUntilCursorVisible:!0})},[]),pn=_.useCallback(()=>M.current?"submit":"linefeed",[]),_n=_.useCallback(()=>M.current,[]);_.useEffect(()=>{if(!i||ge!=="auto"||!gt)return;const be=Fe=>{const rt=l.current,ft=s;return Fe instanceof Node?rt!=null&&rt.contains(Fe)||Fe===document.body||Fe===document.documentElement?!0:ft!=null&&ft.contains(Fe)?Fe instanceof HTMLElement?Fe.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:Fe===window},we=Fe=>{var Lt;if(!nge({active:k.current,touchEditingSurface:gt,key:Fe.key,code:Fe.code,altKey:Fe.altKey,ctrlKey:Fe.ctrlKey,metaKey:Fe.metaKey,isComposing:Fe.isComposing,targetAcceptsPtyInput:be(Fe.target)}))return;Te("hardware"),M.current=!0,(Lt=g.current)==null||Lt.focus();const rt=l.current;if(Fe.target instanceof Node&&(rt!=null&&rt.contains(Fe.target)))return;const ft=sge(Fe);!ft||!it()||(Fe.preventDefault(),Fe.stopPropagation(),Ks(t,ft),zt(),Pt("physicalKeyboard"),Mn(ft,"physicalKeyboardEnter"))};return window.addEventListener("keydown",we,!0),()=>window.removeEventListener("keydown",we,!0)},[i,it,s,ge,Mn,zt,Pt,t,Te,gt,l]);const ze=_.useCallback(be=>{const we=Ot;if(!we){st.error("请先连接开发机");return}const Fe=st.loading(`下载 ${be} ...`);U1({relay:we,sessionId:t,path:be}).then(rt=>{rt.ok?st.success(`已开始下载 ${be}`,{id:Fe}):st.error(rt.error,{id:Fe})}).catch(rt=>{st.error(rt instanceof Error?rt.message:String(rt),{id:Fe})})},[t]),Ze=_.useCallback(be=>{const we=g.current;return we?Zpe(we,w.current,be):!1},[]),Mt=_.useCallback(be=>{const we=g.current;return we?Xpe(we,w.current,be):!1},[]),At=Vme({sessionId:t,terminalRef:g,xtermHostRef:l,scrollControllerRef:E,containerEl:s,scrollState:K,keyboardOffset:Ne,ptyFontSize:ue,suppressPtyFocus:he,focusPtyInput:Re,onTap:Ze,isTapCandidate:Mt,onDownloadPath:ze,onPreviewPath:y});j.current=At.ptySelectionHandles!==null;const J=Zme({sessionId:t,terminalRef:g,onAfterPaste:()=>{zt(),Pt("paste")}}),ve=_.useCallback(be=>{if(!it()){be.preventDefault();return}J(be)},[it,J]),[Ue,ht]=_.useState(!1),Bt=_.useCallback(be=>{be.dataTransfer.types.includes("Files")&&(be.preventDefault(),ht(we=>we||!0))},[]),re=_.useCallback(be=>{be.currentTarget.contains(be.relatedTarget)||ht(!1)},[]),oe=_.useCallback(async be=>{var ft;const we=(ft=be.dataTransfer.files)==null?void 0:ft[0];if(!we||(be.preventDefault(),ht(!1),!it()))return;const Fe=Ot;if(!Fe){st.error("请先连接开发机");return}const rt=await xf({relay:Fe,sessionId:t,file:we});rt&&(Ks(t,`@${rt} `),zt(),Pt("dropUpload"))},[it,zt,Pt,t]),ce=_.useCallback(be=>{var Fe;if(!it()){be.preventDefault();return}const we=be.target;we instanceof Element&&we.closest(".xterm")||(be.preventDefault(),(Fe=g.current)==null||Fe.focus())},[it]);_.useEffect(()=>{if(!se||!te)return;const be=l.current,we=tc,Fe=Ot,rt=s,ft=o.current;if(!be||!we||!Fe||!rt||!ft)return;let Lt=null,Rn=null,tn=null,Kn=null,An=null,Ai=null;const _t=dpe({host:be,sessionId:t,ws:we,relay:Fe,scheduleAutoFocus:fe?()=>{}:void 0,createTerminal:async Ct=>await K5(Ct,{fontSize:Be.getState().ptyFontSize}),attachRawInput:(Ct,Kt,On)=>Tfe(Ct,Kt,{...On,getPlainEnterBehavior:pn,isPhysicalKeyboardMode:_n,physicalKeyboardMode:Ee}),isInputEnabled:it,canFocus:it,onTerminalReady:Ct=>{const Kt=Ct;g.current=Kt;const On=new Ble({highlightLimit:1e3});Kt.loadAddon(On),b.current=On,Ai=On.onDidChangeResults(ar=>{ie(ar)}),I(!0);const jt=Ope(Kt,y);Lt=jt.dispose;const Nn=qpe(Kt,ze);Rn=Nn.dispose,w.current=[jt.provider,Nn.provider],hme(()=>g.current);const Qn=L.current;Qn&&(R.current=!1);const un=ope({container:rt,spacer:ft,host:be,term:Kt,hasNewFrame:()=>z.current,consumeNewFrame:()=>{z.current=!1},hasNewFramesWhileAway:()=>h.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:h.setHasNewFramesWhileAway,onAtBottomChange:h.handleAtBottomChange,onScrollStateChange:F,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:he,onTouchBoundaryPrevent:he});E.current=un,tn=un.dispose,Qn&&(un.restorePageResume(),Vt(),L.current=!1),pme(()=>{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{...gme(un.getDebugProbe,{container:rt,spacer:ft,host:be,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(rt.parentElement),containerRect:ar(rt),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:H.current,pendingNewFrame:z.current}}}),An=pfe({container:rt,host:be,onHorizontalScrollIntent:ar=>{var gr;return(gr=E.current)==null?void 0:gr.markHorizontalScrollIntent(ar)}}).dispose,Ke&&(Kn=Mfe({container:rt,term:Kt,onResize:(gr,si)=>{Fe.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;H.current=performance.now(),(Ct=P.current)==null||Ct.schedule()},onRawInput:Ct=>{zt(),Pt("rawInput"),Mn(Ct,"rawInputEnter")},onError:Ct=>{const Kt=Ct instanceof Error?Ct.message:String(Ct);st.error(`终端初始化失败:${Kt}`)},...d.transport});return x.current=_t,()=>{Kn==null||Kn(),An==null||An(),tn==null||tn(),Ai==null||Ai.dispose(),mme(),Lt==null||Lt(),Rn==null||Rn(),w.current=[],fme(),b.current=null,I(!1),ie({resultIndex:-1,resultCount:0}),_t.dispose(),g.current=null,E.current=null,x.current=null}},[t,se,te,s,o,l,d.transport,h.handleAtBottomChange,h.hasNewFramesWhileAwayRef,h.setHasNewFramesWhileAway,it,Ee,pn,_n,ze,y,he,Pt,Mn,zt,Ke]),_.useEffect(()=>{const be=g.current,we=E.current;!be||!we||dfe(be,ue,we.relayout)},[ue]),_.useEffect(()=>{if(!i||!d.ready||fe)return;const be=requestAnimationFrame(()=>{var we;return(we=g.current)==null?void 0:we.focus()});return()=>cancelAnimationFrame(be)},[i,d.ready,fe]);const Q=_.useCallback((be="viewExternal",we)=>{var Fe;(Fe=E.current)==null||Fe.scrollToBottom(be,we)},[]),V=_.useCallback(be=>{var we;(we=E.current)==null||we.scrollToRatio(be)},[]),Z=_.useCallback(be=>{var we;(we=E.current)==null||we.scrollToXRatio(be)},[]),ee=_.useCallback(be=>{var Rn;const we=g.current,Fe=we==null?void 0:we.getSelectionPosition();if(!we||!Fe)return;const rt=Fe.start.y;if(rt>=be&&rt<be+we.rows)return;const ft=Math.max(0,we.buffer.active.length-we.rows);if(ft===0)return;const Lt=Math.max(0,Math.min(ft,rt-Math.floor(we.rows/2)));(Rn=E.current)==null||Rn.scrollToRatio(Lt/ft)},[]),pe=_.useCallback((be,we=!1)=>{const Fe=g.current,rt=b.current;if(!Fe||!rt||!be)return be||(rt==null||rt.clearDecorations(),Fe==null||Fe.clearSelection(),ie({resultIndex:-1,resultCount:0})),!1;const ft=Fe.buffer.active.viewportY,Lt=rt.findNext(be,{...G2,incremental:we});return Lt&&ee(ft),Lt},[ee]),Ce=_.useCallback(be=>{const we=g.current,Fe=b.current;if(!we||!Fe||!be)return!1;const rt=we.buffer.active.viewportY,ft=Fe.findPrevious(be,G2);return ft&&ee(rt),ft},[ee]),je=_.useCallback(()=>{var be,we;(be=b.current)==null||be.clearDecorations(),(we=g.current)==null||we.clearSelection(),ie({resultIndex:-1,resultCount:0})},[]),Pe=_.useCallback(be=>{var we;it()&&(Ks(t,be),Pt("mobileControl",{force:!0}),Mn(be,"mobileControlEnter"),(we=g.current)==null||we.focus())},[it,Mn,Pt,t]),Ve=_.useCallback(()=>{var we,Fe,rt;if(!it())return;const be=(Fe=(we=navigator.clipboard)==null?void 0:we.readText)==null?void 0:Fe.bind(navigator.clipboard);if(!window.isSecureContext||!be){st.error("无法读取剪贴板"),(rt=g.current)==null||rt.focus();return}be().then(ft=>{if(!ft)return;const Lt=g.current;if(Lt){Lt.paste(ft);return}Ks(t,ft),zt(),Pt("paste"),Mn(ft,"pasteEnter")}).catch(ft=>{const Lt=ft instanceof Error&&ft.message?ft.message:"无法读取剪贴板";st.error(Lt)}).finally(()=>{var ft;return(ft=g.current)==null?void 0:ft.focus()})},[it,Mn,zt,Pt,t]),lt=ige({showMobilePtyControls:at,horizontalScrollable:K.horizontalScrollable,mobileControlsHeight:u});Y.current.containerPaddingBottom=lt,_.useEffect(()=>{var Fe,rt,ft;j.current?(Fe=E.current)==null||Fe.relayout():(rt=P.current)==null||rt.schedule();const be=$.current,we=ege({controlsVisible:at,keyboardOpen:We,previous:be});$.current={keyboardOpen:We,controlsVisible:at},at&&(j.current?Vt():we?((ft=E.current)==null||ft.scrollToBottom("keyboardOffset",{force:!0}),Vt()):We||Pt("keyboardOffset"))},[Ne,We,at,lt,Vt,Pt]);const dt=_.useMemo(()=>({onFocusCapture:nt,onBlurCapture:Xe}),[nt,Xe]);return{scrollState:K,isAtBottom:h.isAtBottom,hasNewFramesWhileAway:h.hasNewFramesWhileAway,ptyInputFocused:Nt,showMobilePtyControls:at,touchEditingSurface:gt,keyboardOffset:Ne,physicalKeyboardMode:Qe,softKeyboardEditingSurface:fe,mobileControlsBottomInset:tt,connectionReady:d.ready,connectionOverlay:d.overlay,containerPaddingBottom:lt,traceEnabled:p,findReady:G,findResultIndex:ne.resultIndex,findResultCount:ne.resultCount,findNext:pe,findPrevious:Ce,clearFind:je,scrollToBottom:Q,scrollToRatio:V,scrollToXRatio:Z,clearNewFramesWhileAway:Vt,sendMobileInput:Pe,pasteMobileClipboard:Ve,handleTerminalContainerMouseDown:ce,handlePasteCapture:ve,pointerHandlers:At.pointerHandlers,focusHandlers:dt,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:Bt,handlePtyDragLeave:re,handlePtyDrop:oe}}function age({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,g]=_.useState(""),b=_.useRef(null),w=_.useRef(null),x=oge({sessionId:e,sessionKind:t,ptyOwner:r,active:i,containerEl:o,spacerRef:b,xtermHostRef:w,mobileControlsHeight:u}),E=x.ptySelectionHandleMetrics,{clearFind:k,findNext:T,findPrevious:A,findReady:z,findResultCount:R,findResultIndex:H}=x,P=_.useCallback(()=>{A(y)},[A,y]),q=_.useCallback(()=>{T(y)},[T,y]),U=_.useCallback(()=>p(!0),[]),$=_.useCallback(()=>{p(!1),k()},[k]),D=E3({enabled:i,open:h,openRequest:s,onOpen:U,onClose:$,onPrevious:P,onNext:q});return _.useEffect(()=>{!h||!z||(y?T(y,!0):k())},[k,T,h,y,z]),v.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?v.jsx(V0,{query:y,resultIndex:H,resultCount:R,focusRequest:D.focusRequest,loading:!!y&&!z,onQueryChange:g,onPrevious:P,onNext:q,onClose:D.closeFind}):null,v.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:v.jsx("div",{ref:b,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:v.jsx("div",{ref:w,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})})}),v.jsx(w3,{visible:!x.isAtBottom,hasNewMessages:x.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{x.scrollToBottom("backToBottomBtn",{force:!0}),x.clearNewFramesWhileAway()}}),x.showMobilePtyControls?v.jsx(Xae,{sessionKind:t,provider:n,bottomInset:x.mobileControlsBottomInset,onInput:x.sendMobileInput,onPaste:x.pasteMobileClipboard,onHeightChange:d}):null,x.ptySelectionHandles?v.jsxs(v.Fragment,{children:[v.jsx(Z2,{kind:"anchor",position:x.ptySelectionHandles.anchor,metrics:E,"aria-label":"调整选区起点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("anchor",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("anchor",M)}),v.jsx(Z2,{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?v.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:[v.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?v.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,v.jsx(ile,{state:x.scrollState,onScrollRatio:x.scrollToRatio}),v.jsx(sle,{state:x.scrollState,onScrollRatio:x.scrollToXRatio}),v.jsx(zae,{...x.connectionOverlay}),v.jsx(jae,{ptyInputFocused:x.ptyInputFocused,touchEditingSurface:x.touchEditingSurface,softKeyboardEditingSurface:x.softKeyboardEditingSurface,physicalKeyboardMode:x.physicalKeyboardMode,keyboardOffset:x.keyboardOffset,showMobilePtyControls:x.showMobilePtyControls,mobileControlsBottomInset:x.mobileControlsBottomInset}),x.traceEnabled?v.jsx(lge,{}):null]})}function Z2({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,g=p+d-u+l,b=e==="anchor"?{borderTopLeftRadius:u,borderBottomLeftRadius:u,borderTopRightRadius:2,borderBottomRightRadius:u}:{borderTopLeftRadius:2,borderBottomLeftRadius:u,borderTopRightRadius:u,borderBottomRightRadius:u};return v.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:[v.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"}),v.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:y,top:g,width:u,height:u,...b},"data-slot":"pty-selection-handle-dot"})]})}function lge(){const[e,t]=_.useState(!1);async function n(){const r=Lae();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return v.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 cge=3,uge=1024,dge=720,Qm=.5,b4=_.createContext(null);function hge({children:e}){const[t,n]=_.useState([]),[r,i]=_.useState(null),[s,o]=_.useState(null),l=Be(k=>k.selectedProxyId),u=Wt(k=>k.sessions),d=Wt(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]),g=_.useCallback(k=>{p.current=k.sessionId,i(k),n(T=>aoe(T,k.sessionId,{capacity:cge,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(A=>!T||A&&mge(A,T)?A:T)},[]),x=_.useCallback((k,T)=>{T!==void 0&&n(A=>A.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(A=>k.has(A.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:g,deactivate:b,updateFindRequest:x,updateViewportRect:w}),[g,b,x,w]);return v.jsxs(b4.Provider,{value:E,children:[e,v.jsx(pge,{entries:t,activeView:r,viewportRect:s})]})}function fge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,findRequest:i}){const s=_.useContext(b4),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 g=new ResizeObserver(y);return g.observe(p),window.addEventListener("resize",y),()=>{g.disconnect(),window.removeEventListener("resize",y)}},[e,h]),v.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function pge({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:v.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)??uge,height:(n==null?void 0:n.height)??dge};return v.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:v.jsx(b3,{sessionId:r.sessionId,children:v.jsx(age,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,ptyOwner:r.ptyOwner,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function mge(e,t){return Math.abs(e.top-t.top)<=Qm&&Math.abs(e.left-t.left)<=Qm&&Math.abs(e.width-t.width)<=Qm&&Math.abs(e.height-t.height)<=Qm}function mE({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 gE="dev-anywhere:last-chat-route",w4="dev-anywhere:route-restored",qS="dev-anywhere:restored-target";function gge(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function vge(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(gE))??null}catch{return null}}function yge(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(gE,e)}catch{}}function S4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(gE)}catch{}}function _ge(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(w4))==="1"}catch{return!1}}function bge(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(w4,"1")}catch{}}function wge(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(qS,e)}catch{}}function Sge(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(qS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(qS)),n}catch{return null}}function xge(e){const t=DL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Ag(){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 Ege(){return typeof navigator>"u"?{supported:!0}:xge({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Ag()})}function Cge(){ame(),lme();const e=Bi(),t=Js(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=_.useState(!1),[o,l]=_.useState(()=>Ag()),u=Be(P=>P.proxies.length),d=Be(P=>P.proxyListLoaded),h=Be(P=>P.relayClientAuthIssue),p=Be(P=>!!P.selectedProxyId),y=Be(P=>P.selectedProxyId),g=Be(P=>P.selectedProxyName),b=Wt(P=>P.sessions.length),w=Be(P=>P.pendingToast),x=Be(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=mE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:b,relayClientAuthIssue:h}),T=g??y,z=e.pathname==="/sessions"&&d&&u>0?v.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:[v.jsx(CP,{className:"size-4 text-primary","aria-hidden":"true"}),v.jsxs("span",{className:"min-w-0 truncate",children:[v.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?v.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;_.useEffect(()=>{if(!w)return;({error:st.error,info:st.info,success:st.success})[w.kind](w.message),x(null)},[w,x]),_.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Ag());return}const P=window.matchMedia("(display-mode: standalone)"),q=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(Ag());return U(),P.addEventListener("change",U),q.addEventListener("change",U),()=>{P.removeEventListener("change",U),q.removeEventListener("change",U)}},[]);const R=_.useRef(!1);_.useEffect(()=>{if(R.current)return;R.current=!0;const P=gge({pathname:e.pathname,alreadyRestored:_ge(),lastRoute:vge()});bge(),P&&(wge(P),t(P,{replace:!0}))},[]);const H=_.useRef(!1);return _.useEffect(()=>{n?(H.current=!0,yge(`${e.pathname}${e.search}`)):H.current&&(H.current=!1,S4())},[n,e.pathname,e.search]),v.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&&v.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:v.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:v.jsx(RP,{className:"size-4","aria-hidden":"true"})})}),!n&&v.jsx(use,{subtitle:k,action:z}),v.jsx(ooe,{}),v.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[v.jsx(ase,{className:"hidden md:flex"}),v.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:v.jsx(hge,{children:v.jsx("div",{className:qe("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:v.jsx(AU,{})},r?"top-level":e.pathname)})})]}),v.jsx(U0,{open:i,onOpenChange:s}),v.jsx(zse,{}),v.jsx(_se,{}),v.jsx(BX,{})]})}function x4({subtitle:e,action:t}){return v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[v.jsx(jB,{texts:FB,className:"text-2xl md:text-3xl font-bold"}),v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&v.jsx("div",{children:t})]})}function kge(){const e=Be(o=>o.proxies),t=Be(o=>!!o.selectedProxyId),n=Be(o=>o.relayClientAuthIssue),r=Wt(o=>o.sessions.length),i=mE({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 v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(xB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:s?v.jsx(nc,{variant:s}):v.jsx(x4,{subtitle:i})})]})}function Tge(){const e=Be(o=>o.proxies),t=Be(o=>!!o.selectedProxyId),n=Be(o=>o.relayClientAuthIssue),r=Wt(o=>o.sessions.length),i=ki("local",ln.proxyId)!==null;if(!t&&!i)return v.jsx(RU,{to:"/",replace:!0});const s=mE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(OB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:v.jsx(x4,{subtitle:s})})]})}function E4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function Rge(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function C4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return Rge(e,typeof((t=E4())==null?void 0:t.request)=="function")}function Age(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function Nge(){const e=E4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(Age(C4()));return e.request("screen")}function Mge(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class Oge{constructor(t={}){vt(this,"activeScopes",new Set);vt(this,"pendingScopes",new Set);vt(this,"listeners",new Map);vt(this,"sentinel",null);vt(this,"requestInFlight",null);vt(this,"requestWakeLock");vt(this,"documentRef");vt(this,"windowRef");vt(this,"unavailableReason");vt(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});vt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??Nge,this.unavailableReason=typeof t.request=="function"?null:C4(),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(Mge(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 Oge;function k4(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 Dge(){return new AudioContext}class Pge{constructor(t=Dge){vt(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Ng=new Pge,Q2=400,Ou=[];let T4=1;function Lge(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Vh(e){const t={sequence:T4++,timestamp:new Date().toISOString(),monotonicMs:Lge(),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>Q2&&Ou.splice(0,Ou.length-Q2)}function Ige(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function zge(){Ou.length=0,T4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Ige,clear:zge});function R4(e){return`voice-pilot:${e}`}function Bge(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 jge="modulepreload",Fge=function(e){return"/"+e},J2={},$ge=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=Fge(d),d in J2)return;J2[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":jge,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((g,b)=>{y.addEventListener("load",g),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)})},Hge="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Uge=20,Za=Zu*Uge/1e3,zw=Za*Int16Array.BYTES_PER_ELEMENT;let eO=null;async function Wge(){return eO??(eO=$ge(async()=>{const{default:e}=await import("./fvad-DQEN24BT.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Hge:t}))),eO}class vE{constructor(t,n,r){vt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Wge(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(zw);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 vE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==zw)throw new Error(`语音活动检测帧必须为 ${zw} 字节`);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 qge{constructor(t={}){vt(this,"startSpeechFrames");vt(this,"endSilenceFrames");vt(this,"active",!1);vt(this,"speechFrames",0);vt(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class Vge{constructor(){vt(this,"pending",new Float32Array(Za));vt(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 Yge="/__dev_anywhere_debug/voice-fixture",Kge=Zu*PB/1e3;function Gge(){return vE.create(3)}const Xge={createVad:Gge,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Zge(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 Qge(e){for(const t of e.getTracks())t.stop()}function A4(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 Jge(e){const t=A4(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(),Qge(n),t.state!=="closed"&&await t.close()}}}async function eve(e,t){const n=A4(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 N4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Yge}:{kind:"microphone"}}async function tve(e,t=Xge){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await eve(e.source.url,t):await Jge(t)}catch(h){throw n.destroy(),h}const i=new qge,s=new Vge,o=r.context.createScriptProcessor(Kge,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Bge(p),g=n.process(y);e.onFrame({pcm:y,speechProbability:g?1:0,activityLevel:Zge(p)});const b=i.push(g);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 nve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function rve({title:e,isPtyTitle:t}){if(!t)return v.jsx(v.Fragment,{children:e});const{indicator:n,label:r}=nve(e);return v.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&v.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),v.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function ive(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 sve(){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(ive(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",Jm="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return v.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:qe("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function ove({label:e}){return v.jsxs(mo,{className:"relative",children:[v.jsx(EP,{className:"size-4","aria-hidden":"true"}),v.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 ave({sessionId:e,mode:t,onFind:n}){const r=Js(),i=Wt(Oe=>Oe.sessions.find(de=>de.sessionId===e)),s=Wt(Oe=>Oe.ptyTitles[e]),o=Be(Oe=>Oe.ptyFontSize),l=Be(Oe=>Oe.chatContentFontSize),u=Be(Oe=>Oe.selectedProxyId),d=Be(Oe=>Oe.adjustPtyFontSize),h=Be(Oe=>Oe.adjustChatContentFontSize),p=Be(Oe=>Oe.setChatContentFontSize),y=Be(Oe=>Oe.resetPtyFontSize),g=Be(Oe=>Oe.resetChatContentFontSize),b=Be(Oe=>Oe.inputModePreference==="hardware"),w=Wt(Oe=>Oe.renameSession),x=Dx(u,e),E=Wt(Oe=>x?!!Oe.ptyAutoYesBySessionKey[x]:!1),k=Wt(Oe=>Oe.setPtyAutoYes),A=hl("(pointer: coarse), (hover: none)")&&!b,z=t==="pty"||(i==null?void 0:i.mode)==="pty",R=(i==null?void 0:i.kind)==="terminal",H=k4(e),P=on(Oe=>Oe.bySessionId[e]??iy),q=on(Oe=>Oe.enable),U=on(Oe=>Oe.disable),$=!!(i!=null&&i.nameLocked&&(i!=null&&i.name)),D=Vx(i),M=$&&(i==null?void 0:i.name)||D||z&&s||(i==null?void 0:i.name)||e.slice(0,8),j=!!(z&&!R&&s&&!$),L=z?o:Mx(l,A),O=!z&&A?GP:YP,Y=z?y:g,[K,F]=_.useState(!1),[N,W]=_.useState(!1),G=P.enabled,I=H.active||G,ne=H.pending||!H.supported||G;function ie(Oe){if(z){d(Oe);return}if(A){p(L+Oe);return}h(Oe)}function se(){H.toggle().catch(Oe=>{st.error(Oe instanceof Error?Oe.message:String(Oe))})}async function te(Oe){var Ee;if(z||R){st.info("Voice Pilot 目前适用于聊天会话。");return}if(Oe!==!0){U(e);return}const de=Ot;if(!de){st.error("请先连接开发机");return}try{if(!((Ee=(await de.requestVoiceConfig()).config)!=null&&Ee.configured)){st.info("请先在设置里配置 Voice Pilot。");return}F(!0)}catch(Qe){st.error(Qe instanceof Error?Qe.message:String(Qe))}}async function ue(){var Qe;W(!0);let Oe=null,de=!1;const Ee=R4(e);try{Vh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((Qe=navigator.userActivation)==null?void 0:Qe.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const fe=Xa.enable(Ee).then(()=>{Vh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},it=>{throw Vh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:it instanceof Error?it.message:String(it)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:it})});Oe=O1.acquire("capture");const Ne=Ng.prepare(),tt=N4().kind==="microphone"?sve():Promise.resolve();await Promise.all([fe,Ne,tt]),q(e),de=!0,F(!1)}catch(fe){Vh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:fe instanceof Error?fe.message:String(fe)}}),st.error(fe instanceof Error?fe.message:String(fe))}finally{Oe==null||Oe.release(),de||await Xa.disable(Ee).catch(()=>{}),W(!1)}}const ge=_.useRef(null),Se=_.useRef(null),[Te,Ie]=_.useState(!1);async function Ke(Oe){var fe;const de=(fe=Oe.target.files)==null?void 0:fe[0];if(Oe.target.value="",!de)return;const Ee=Ot;if(!Ee){st.error("请先连接开发机");return}const Qe=await xf({relay:Ee,sessionId:e,file:de});Qe&&Ks(e,`@${Qe} `)}async function gt(Oe,de){const Ee=Ot;if(!Ee)throw new Error("请先连接开发机");const Qe=await Ee.renameSession(Oe,de);if(!Qe.success)throw new Error(Qe.error??"重命名失败");w(Oe,Qe.name??de),st.success("已重命名会话")}return v.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[v.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:v.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:[v.jsx("div",{className:"flex justify-start",children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>r("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:v.jsx(vv,{"aria-hidden":"true"})})}),v.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:v.jsx(rve,{title:M,isPtyTitle:j})}),v.jsxs(R1,{modal:!1,children:[v.jsx(A1,{asChild:!0,children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:v.jsx(X9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[v.jsx(Im,{className:Jm,children:"会话"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[v.jsx(mo,{children:v.jsx(Dg,{"aria-hidden":"true"})}),"在会话中查找"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>Ie(!0),children:[v.jsx(mo,{children:v.jsx(A8,{"aria-hidden":"true"})}),"重命名"]}),v.jsxs(Kb,{checked:I,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ne,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:se,children:[v.jsx(mo,{children:v.jsx(u8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:H.supported?G?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":H.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),z&&!R&&v.jsxs(Kb,{checked:E,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!x,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:Oe=>{x&&k(x,Oe===!0)},children:[v.jsx(mo,{children:v.jsx(ra,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!z&&!R&&v.jsxs(Kb,{checked:P.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:te,children:[v.jsx(mo,{children:v.jsx(g8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),v.jsx(Gb,{}),z&&!R?v.jsxs(v.Fragment,{children:[v.jsx(Im,{className:Jm,children:"快捷键"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ks(e,""),children:[v.jsx(ove,{label:"^O"}),"发送 Ctrl+O"]}),v.jsx(Gb,{}),v.jsx(Im,{className:Jm,children:"文件"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var Oe;return(Oe=Se.current)==null?void 0:Oe.click()},children:[v.jsx(mo,{children:v.jsx(yv,{"aria-hidden":"true"})}),"上传图片"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var Oe;return(Oe=ge.current)==null?void 0:Oe.click()},children:[v.jsx(mo,{children:v.jsx(AP,{"aria-hidden":"true"})}),"上传文件"]}),v.jsx(Gb,{})]}):null,v.jsx(Im,{className:Jm,children:"字号"}),v.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:v.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:[v.jsx(mo,{children:v.jsx(e7,{"aria-hidden":"true"})}),v.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[v.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:L<=O,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:Oe=>{Oe.stopPropagation(),ie(-1)},children:v.jsx(y8,{"aria-hidden":"true"})}),v.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:[L,"px"]}),v.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:L>=KP,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:Oe=>{Oe.stopPropagation(),ie(1)},children:v.jsx(O8,{"aria-hidden":"true"})})]})]})}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-font-reset",onClick:Y,children:[v.jsx(mo,{children:v.jsx(L8,{"aria-hidden":"true"})}),v.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),v.jsx(zh,{open:Te,sessionId:e,initialName:i==null?void 0:i.name,onOpenChange:Ie,onRename:gt}),v.jsx(Sc,{open:K&&!P.enabled,onOpenChange:Oe=>{N||F(Oe)},children:v.jsxs(xc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"开启 Voice Pilot?"}),v.jsx(dc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",disabled:N,onClick:()=>F(!1),children:"取消"}),v.jsx(St,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:N,onClick:()=>{ue()},children:N?"正在开启...":"开启 Voice Pilot"})]})]})}),z?v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:Se,type:"file",accept:"image/*",className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:Oe=>{Ke(Oe)}}),v.jsx("input",{ref:ge,type:"file",accept:"application/*,text/*",className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:Oe=>{Ke(Oe)}})]}):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 g;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(g=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()-g)*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(A=>k.has(A.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:g,deactivate:b,updateFindRequest:x,updateViewportRect:w}),[g,b,x,w]);return v.jsxs(b4.Provider,{value:E,children:[e,v.jsx(pge,{entries:t,activeView:r,viewportRect:s})]})}function fge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,findRequest:i}){const s=_.useContext(b4),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 g=new ResizeObserver(y);return g.observe(p),window.addEventListener("resize",y),()=>{g.disconnect(),window.removeEventListener("resize",y)}},[e,h]),v.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function pge({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:v.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)??uge,height:(n==null?void 0:n.height)??dge};return v.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:v.jsx(b3,{sessionId:r.sessionId,children:v.jsx(age,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,ptyOwner:r.ptyOwner,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function mge(e,t){return Math.abs(e.top-t.top)<=Qm&&Math.abs(e.left-t.left)<=Qm&&Math.abs(e.width-t.width)<=Qm&&Math.abs(e.height-t.height)<=Qm}function mE({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 gE="dev-anywhere:last-chat-route",w4="dev-anywhere:route-restored",qS="dev-anywhere:restored-target";function gge(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function vge(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(gE))??null}catch{return null}}function yge(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(gE,e)}catch{}}function S4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(gE)}catch{}}function _ge(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(w4))==="1"}catch{return!1}}function bge(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(w4,"1")}catch{}}function wge(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(qS,e)}catch{}}function Sge(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(qS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(qS)),n}catch{return null}}function xge(e){const t=DL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Ag(){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 Ege(){return typeof navigator>"u"?{supported:!0}:xge({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Ag()})}function Cge(){ame(),lme();const e=Bi(),t=Js(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=_.useState(!1),[o,l]=_.useState(()=>Ag()),u=Be(P=>P.proxies.length),d=Be(P=>P.proxyListLoaded),h=Be(P=>P.relayClientAuthIssue),p=Be(P=>!!P.selectedProxyId),y=Be(P=>P.selectedProxyId),g=Be(P=>P.selectedProxyName),b=Wt(P=>P.sessions.length),w=Be(P=>P.pendingToast),x=Be(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=mE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:b,relayClientAuthIssue:h}),T=g??y,z=e.pathname==="/sessions"&&d&&u>0?v.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:[v.jsx(CP,{className:"size-4 text-primary","aria-hidden":"true"}),v.jsxs("span",{className:"min-w-0 truncate",children:[v.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?v.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;_.useEffect(()=>{if(!w)return;({error:st.error,info:st.info,success:st.success})[w.kind](w.message),x(null)},[w,x]),_.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Ag());return}const P=window.matchMedia("(display-mode: standalone)"),q=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(Ag());return U(),P.addEventListener("change",U),q.addEventListener("change",U),()=>{P.removeEventListener("change",U),q.removeEventListener("change",U)}},[]);const R=_.useRef(!1);_.useEffect(()=>{if(R.current)return;R.current=!0;const P=gge({pathname:e.pathname,alreadyRestored:_ge(),lastRoute:vge()});bge(),P&&(wge(P),t(P,{replace:!0}))},[]);const H=_.useRef(!1);return _.useEffect(()=>{n?(H.current=!0,yge(`${e.pathname}${e.search}`)):H.current&&(H.current=!1,S4())},[n,e.pathname,e.search]),v.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&&v.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:v.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:v.jsx(RP,{className:"size-4","aria-hidden":"true"})})}),!n&&v.jsx(use,{subtitle:k,action:z}),v.jsx(ooe,{}),v.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[v.jsx(ase,{className:"hidden md:flex"}),v.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:v.jsx(hge,{children:v.jsx("div",{className:qe("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:v.jsx(AU,{})},r?"top-level":e.pathname)})})]}),v.jsx(U0,{open:i,onOpenChange:s}),v.jsx(zse,{}),v.jsx(_se,{}),v.jsx(BX,{})]})}function x4({subtitle:e,action:t}){return v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[v.jsx(jB,{texts:FB,className:"text-2xl md:text-3xl font-bold"}),v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&v.jsx("div",{children:t})]})}function kge(){const e=Be(o=>o.proxies),t=Be(o=>!!o.selectedProxyId),n=Be(o=>o.relayClientAuthIssue),r=Wt(o=>o.sessions.length),i=mE({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 v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(xB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:s?v.jsx(nc,{variant:s}):v.jsx(x4,{subtitle:i})})]})}function Tge(){const e=Be(o=>o.proxies),t=Be(o=>!!o.selectedProxyId),n=Be(o=>o.relayClientAuthIssue),r=Wt(o=>o.sessions.length),i=ki("local",ln.proxyId)!==null;if(!t&&!i)return v.jsx(RU,{to:"/",replace:!0});const s=mE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(OB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:v.jsx(x4,{subtitle:s})})]})}function E4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function Rge(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function C4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return Rge(e,typeof((t=E4())==null?void 0:t.request)=="function")}function Age(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function Nge(){const e=E4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(Age(C4()));return e.request("screen")}function Mge(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class Oge{constructor(t={}){vt(this,"activeScopes",new Set);vt(this,"pendingScopes",new Set);vt(this,"listeners",new Map);vt(this,"sentinel",null);vt(this,"requestInFlight",null);vt(this,"requestWakeLock");vt(this,"documentRef");vt(this,"windowRef");vt(this,"unavailableReason");vt(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});vt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??Nge,this.unavailableReason=typeof t.request=="function"?null:C4(),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(Mge(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 Oge;function k4(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 Dge(){return new AudioContext}class Pge{constructor(t=Dge){vt(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Ng=new Pge,Q2=400,Ou=[];let T4=1;function Lge(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Vh(e){const t={sequence:T4++,timestamp:new Date().toISOString(),monotonicMs:Lge(),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>Q2&&Ou.splice(0,Ou.length-Q2)}function Ige(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function zge(){Ou.length=0,T4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Ige,clear:zge});function R4(e){return`voice-pilot:${e}`}function Bge(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 jge="modulepreload",Fge=function(e){return"/"+e},J2={},$ge=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=Fge(d),d in J2)return;J2[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":jge,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((g,b)=>{y.addEventListener("load",g),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)})},Hge="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Uge=20,Za=Zu*Uge/1e3,zw=Za*Int16Array.BYTES_PER_ELEMENT;let eO=null;async function Wge(){return eO??(eO=$ge(async()=>{const{default:e}=await import("./fvad-eTzXvEav.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Hge:t}))),eO}class vE{constructor(t,n,r){vt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Wge(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(zw);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 vE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==zw)throw new Error(`语音活动检测帧必须为 ${zw} 字节`);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 qge{constructor(t={}){vt(this,"startSpeechFrames");vt(this,"endSilenceFrames");vt(this,"active",!1);vt(this,"speechFrames",0);vt(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class Vge{constructor(){vt(this,"pending",new Float32Array(Za));vt(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 Yge="/__dev_anywhere_debug/voice-fixture",Kge=Zu*PB/1e3;function Gge(){return vE.create(3)}const Xge={createVad:Gge,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Zge(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 Qge(e){for(const t of e.getTracks())t.stop()}function A4(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 Jge(e){const t=A4(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(),Qge(n),t.state!=="closed"&&await t.close()}}}async function eve(e,t){const n=A4(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 N4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Yge}:{kind:"microphone"}}async function tve(e,t=Xge){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await eve(e.source.url,t):await Jge(t)}catch(h){throw n.destroy(),h}const i=new qge,s=new Vge,o=r.context.createScriptProcessor(Kge,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Bge(p),g=n.process(y);e.onFrame({pcm:y,speechProbability:g?1:0,activityLevel:Zge(p)});const b=i.push(g);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 nve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function rve({title:e,isPtyTitle:t}){if(!t)return v.jsx(v.Fragment,{children:e});const{indicator:n,label:r}=nve(e);return v.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&v.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),v.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function ive(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 sve(){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(ive(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",Jm="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return v.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:qe("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function ove({label:e}){return v.jsxs(mo,{className:"relative",children:[v.jsx(EP,{className:"size-4","aria-hidden":"true"}),v.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 ave({sessionId:e,mode:t,onFind:n}){const r=Js(),i=Wt(Oe=>Oe.sessions.find(de=>de.sessionId===e)),s=Wt(Oe=>Oe.ptyTitles[e]),o=Be(Oe=>Oe.ptyFontSize),l=Be(Oe=>Oe.chatContentFontSize),u=Be(Oe=>Oe.selectedProxyId),d=Be(Oe=>Oe.adjustPtyFontSize),h=Be(Oe=>Oe.adjustChatContentFontSize),p=Be(Oe=>Oe.setChatContentFontSize),y=Be(Oe=>Oe.resetPtyFontSize),g=Be(Oe=>Oe.resetChatContentFontSize),b=Be(Oe=>Oe.inputModePreference==="hardware"),w=Wt(Oe=>Oe.renameSession),x=Dx(u,e),E=Wt(Oe=>x?!!Oe.ptyAutoYesBySessionKey[x]:!1),k=Wt(Oe=>Oe.setPtyAutoYes),A=hl("(pointer: coarse), (hover: none)")&&!b,z=t==="pty"||(i==null?void 0:i.mode)==="pty",R=(i==null?void 0:i.kind)==="terminal",H=k4(e),P=on(Oe=>Oe.bySessionId[e]??iy),q=on(Oe=>Oe.enable),U=on(Oe=>Oe.disable),$=!!(i!=null&&i.nameLocked&&(i!=null&&i.name)),D=Vx(i),M=$&&(i==null?void 0:i.name)||D||z&&s||(i==null?void 0:i.name)||e.slice(0,8),j=!!(z&&!R&&s&&!$),L=z?o:Mx(l,A),O=!z&&A?GP:YP,Y=z?y:g,[K,F]=_.useState(!1),[N,W]=_.useState(!1),G=P.enabled,I=H.active||G,ne=H.pending||!H.supported||G;function ie(Oe){if(z){d(Oe);return}if(A){p(L+Oe);return}h(Oe)}function se(){H.toggle().catch(Oe=>{st.error(Oe instanceof Error?Oe.message:String(Oe))})}async function te(Oe){var Ee;if(z||R){st.info("Voice Pilot 目前适用于聊天会话。");return}if(Oe!==!0){U(e);return}const de=Ot;if(!de){st.error("请先连接开发机");return}try{if(!((Ee=(await de.requestVoiceConfig()).config)!=null&&Ee.configured)){st.info("请先在设置里配置 Voice Pilot。");return}F(!0)}catch(Qe){st.error(Qe instanceof Error?Qe.message:String(Qe))}}async function ue(){var Qe;W(!0);let Oe=null,de=!1;const Ee=R4(e);try{Vh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((Qe=navigator.userActivation)==null?void 0:Qe.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const fe=Xa.enable(Ee).then(()=>{Vh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},it=>{throw Vh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:it instanceof Error?it.message:String(it)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:it})});Oe=O1.acquire("capture");const Ne=Ng.prepare(),tt=N4().kind==="microphone"?sve():Promise.resolve();await Promise.all([fe,Ne,tt]),q(e),de=!0,F(!1)}catch(fe){Vh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:fe instanceof Error?fe.message:String(fe)}}),st.error(fe instanceof Error?fe.message:String(fe))}finally{Oe==null||Oe.release(),de||await Xa.disable(Ee).catch(()=>{}),W(!1)}}const ge=_.useRef(null),Se=_.useRef(null),[Te,Ie]=_.useState(!1);async function Ke(Oe){var fe;const de=(fe=Oe.target.files)==null?void 0:fe[0];if(Oe.target.value="",!de)return;const Ee=Ot;if(!Ee){st.error("请先连接开发机");return}const Qe=await xf({relay:Ee,sessionId:e,file:de});Qe&&Ks(e,`@${Qe} `)}async function gt(Oe,de){const Ee=Ot;if(!Ee)throw new Error("请先连接开发机");const Qe=await Ee.renameSession(Oe,de);if(!Qe.success)throw new Error(Qe.error??"重命名失败");w(Oe,Qe.name??de),st.success("已重命名会话")}return v.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[v.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:v.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:[v.jsx("div",{className:"flex justify-start",children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>r("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:v.jsx(vv,{"aria-hidden":"true"})})}),v.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:v.jsx(rve,{title:M,isPtyTitle:j})}),v.jsxs(R1,{modal:!1,children:[v.jsx(A1,{asChild:!0,children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:v.jsx(X9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[v.jsx(Im,{className:Jm,children:"会话"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[v.jsx(mo,{children:v.jsx(Dg,{"aria-hidden":"true"})}),"在会话中查找"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>Ie(!0),children:[v.jsx(mo,{children:v.jsx(A8,{"aria-hidden":"true"})}),"重命名"]}),v.jsxs(Kb,{checked:I,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ne,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:se,children:[v.jsx(mo,{children:v.jsx(u8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:H.supported?G?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":H.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),z&&!R&&v.jsxs(Kb,{checked:E,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!x,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:Oe=>{x&&k(x,Oe===!0)},children:[v.jsx(mo,{children:v.jsx(ra,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!z&&!R&&v.jsxs(Kb,{checked:P.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:te,children:[v.jsx(mo,{children:v.jsx(g8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),v.jsx(Gb,{}),z&&!R?v.jsxs(v.Fragment,{children:[v.jsx(Im,{className:Jm,children:"快捷键"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ks(e,""),children:[v.jsx(ove,{label:"^O"}),"发送 Ctrl+O"]}),v.jsx(Gb,{}),v.jsx(Im,{className:Jm,children:"文件"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var Oe;return(Oe=Se.current)==null?void 0:Oe.click()},children:[v.jsx(mo,{children:v.jsx(yv,{"aria-hidden":"true"})}),"上传图片"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var Oe;return(Oe=ge.current)==null?void 0:Oe.click()},children:[v.jsx(mo,{children:v.jsx(AP,{"aria-hidden":"true"})}),"上传文件"]}),v.jsx(Gb,{})]}):null,v.jsx(Im,{className:Jm,children:"字号"}),v.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:v.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:[v.jsx(mo,{children:v.jsx(e7,{"aria-hidden":"true"})}),v.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[v.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:L<=O,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:Oe=>{Oe.stopPropagation(),ie(-1)},children:v.jsx(y8,{"aria-hidden":"true"})}),v.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:[L,"px"]}),v.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:L>=KP,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:Oe=>{Oe.stopPropagation(),ie(1)},children:v.jsx(O8,{"aria-hidden":"true"})})]})]})}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-font-reset",onClick:Y,children:[v.jsx(mo,{children:v.jsx(L8,{"aria-hidden":"true"})}),v.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),v.jsx(zh,{open:Te,sessionId:e,initialName:i==null?void 0:i.name,onOpenChange:Ie,onRename:gt}),v.jsx(Sc,{open:K&&!P.enabled,onOpenChange:Oe=>{N||F(Oe)},children:v.jsxs(xc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"开启 Voice Pilot?"}),v.jsx(dc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",disabled:N,onClick:()=>F(!1),children:"取消"}),v.jsx(St,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:N,onClick:()=>{ue()},children:N?"正在开启...":"开启 Voice Pilot"})]})]})}),z?v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:Se,type:"file",accept:"image/*",className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:Oe=>{Ke(Oe)}}),v.jsx("input",{ref:ge,type:"file",accept:"application/*,text/*",className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:Oe=>{Ke(Oe)}})]}):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 g;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(g=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()-g)*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 tO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const lve=(e,t)=>Math.abs(e-t)<1.01,cve=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},nO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},uve=e=>e,dve=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},hve=(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(nO(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(nO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},rO={passive:!0},iO=typeof window>"u"?!0:"onscrollend"in window,fve=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&iO?()=>{}:cve(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,rO);const d=e.options.useScrollendEvent&&iO;return d&&n.addEventListener("scrollend",u,rO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},pve=(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"]},mve=(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 gve{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:uve,rangeExtractor:dve,onChange:()=>{},measureElement:pve,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 g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);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(g=>{this.itemSizeCache.set(g.key,g.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 g=0;g<h;g++){const b=p[g];b&&(y[b.lane]=g)}for(let g=h;g<n;g++){const b=s(g),w=this.laneAssignments.get(g);let x,E;const k=u==="estimate"||d.has(b);if(w!==void 0&&this.options.lanes>1){x=w;const R=y[x],H=R!==void 0?p[R]:void 0;E=H?H.end+this.options.gap:r+i}else{const R=this.options.lanes===1?p[g-1]:this.getFurthestMeasurement(p,g);E=R?R.end+this.options.gap:r+i,x=R?R.lane:g%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(g,x)}const T=d.get(b),A=typeof T=="number"?T:this.options.estimateSize(g),z=E+A;p[g]={index:g,start:E,size:A,end:z,key:b,lane:x},y[x]=g}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?vve({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 tO(r[M4(0,r.length-1,i=>tO(r[i]).start,n)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(n,r,i=0)=>{if(!this.scrollElement)return 0;const s=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=n>=o+s?"end":"start"),r==="center"?n+=(i-s)/2:r==="end"&&(n-=s);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.getSize(),s=this.getScrollOffset(),o=this.measurementsCache[n];if(!o)return;if(r==="auto")if(o.end>=s+i-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,o.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:i="auto"}={})=>{const s=this.getOffsetForAlignment(n,r),o=this.now();this.scrollState={index:null,align:r,behavior:i,startedAt:o,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:i="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const s=this.getOffsetForIndex(n,r);if(!s)return;const[o,l]=s,u=this.now();this.scrollState={index:n,align:l,behavior:i,startedAt:u,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const i=this.getScrollOffset()+n,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((n=r[r.length-1])==null?void 0:n.end)??0;else{const s=Array(this.options.lanes).fill(null);let o=r.length-1;for(;o>=0&&s.some(l=>l===null);){const l=r[o];s[l.lane]===null&&(s[l.lane]=l.end),o--}i=Math.max(...s.filter(l=>l!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:i})=>{this.options.scrollToFn(n,{behavior:i,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(t)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=r?r[0]:this.scrollState.lastTargetOffset,s=1,o=i!==this.scrollState.lastTargetOffset;if(!o&&lve(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 M4=(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 vve({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=M4(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 sO=typeof document<"u"?_.useLayoutEffect:_.useEffect;function yve({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 gve(r));return i.setOptions(r),sO(()=>i._didMount(),[]),sO(()=>i._willUpdate()),i}function _ve(e){return yve({observeElementRect:hve,observeElementOffset:fve,scrollToFn:mve,...e})}function bve(e){return e.kind==="diff"}const wve=12e4;function oO(e){return e?e.replace(/\r\n?/gu,`
|