@dev-anywhere/relay 0.5.17 → 0.5.18

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.
@@ -507,7 +507,7 @@ ${t}`:e:t}function z_(e,t,n){const r=$g(t),i=$g(n);return!r&&!i?null:{kind:"diff
507
507
 
508
508
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
509
509
 
510
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},QJ="DialogDescriptionWarning",JJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${MI(QJ).contentName}}.`;return b.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},r1=vI,eee=bI,i1=wI,s1=SI,o1=xI,OI=CI,DI=TI,a1=AI;function tee(e){const t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function nee(e){const[t,n]=b.useState(void 0);return Ei(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const u=s.borderBoxSize,d=Array.isArray(u)?u[0]:u;o=d.inlineSize,l=d.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const ree=["top","right","bottom","left"],ol=Math.min,ls=Math.max,Ug=Math.round,zm=Math.floor,_o=e=>({x:e,y:e}),iee={left:"right",right:"left",bottom:"top",top:"bottom"};function T0(e,t,n){return ls(e,ol(t,n))}function ra(e,t){return typeof e=="function"?e(t):e}function ia(e){return e.split("-")[0]}function od(e){return e.split("-")[1]}function l1(e){return e==="x"?"y":"x"}function c1(e){return e==="y"?"height":"width"}function yo(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function u1(e){return l1(yo(e))}function see(e,t,n){n===void 0&&(n=!1);const r=od(e),i=u1(e),s=c1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Wg(o)),[o,Wg(o)]}function oee(e){const t=Wg(e);return[R0(e),t,R0(t)]}function R0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const wN=["left","right"],SN=["right","left"],aee=["top","bottom"],lee=["bottom","top"];function cee(e,t,n){switch(e){case"top":case"bottom":return n?t?SN:wN:t?wN:SN;case"left":case"right":return t?aee:lee;default:return[]}}function uee(e,t,n,r){const i=od(e);let s=cee(ia(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(R0)))),s}function Wg(e){const t=ia(e);return iee[t]+e.slice(t.length)}function dee(e){return{top:0,right:0,bottom:0,left:0,...e}}function PI(e){return typeof e!="number"?dee(e):{top:e,right:e,bottom:e,left:e}}function qg(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function xN(e,t,n){let{reference:r,floating:i}=e;const s=yo(t),o=u1(t),l=c1(o),u=ia(t),d=s==="y",h=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let v;switch(u){case"top":v={x:h,y:r.y-i.height};break;case"bottom":v={x:h,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:p};break;case"left":v={x:r.x-i.width,y:p};break;default:v={x:r.x,y:r.y}}switch(od(t)){case"start":v[o]-=y*(n&&d?-1:1);break;case"end":v[o]+=y*(n&&d?-1:1);break}return v}async function hee(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:p="floating",altBoundary:y=!1,padding:v=0}=ra(t,e),_=PI(v),x=l[y?p==="floating"?"reference":"floating":p],E=qg(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),A=await(s.isElement==null?void 0:s.isElement(R))?await(s.getScale==null?void 0:s.getScale(R))||{x:1,y:1}:{x:1,y:1},I=qg(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(E.top-I.top+_.top)/A.y,bottom:(I.bottom-E.bottom+_.bottom)/A.y,left:(E.left-I.left+_.left)/A.x,right:(I.right-E.right+_.right)/A.x}}const fee=50,pee=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:hee},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=xN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:R,y:A,data:I,reset:T}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});h=R??h,p=A??p,_[E]={..._[E],...I},T&&v<fee&&(v++,typeof T=="object"&&(T.placement&&(y=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:p}=xN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:_}},mee=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=ra(e,t)||{};if(d==null)return{};const p=PI(h),y={x:n,y:r},v=u1(i),_=c1(v),w=await o.getDimensions(d),x=v==="y",E=x?"top":"left",k=x?"bottom":"right",R=x?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[v]-y[v]-s.floating[_],I=y[v]-s.reference[v],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let H=T?T[R]:0;(!H||!await(o.isElement==null?void 0:o.isElement(T)))&&(H=l.floating[R]||s.floating[_]);const D=A/2-I/2,W=H/2-w[_]/2-1,U=ol(p[E],W),F=ol(p[k],W),O=U,M=H-w[_]-F,z=H/2-w[_]/2+D,L=T0(O,z,M),N=!u.arrow&&od(i)!=null&&z!==L&&s.reference[_]/2-(z<O?U:F)-w[_]/2<0,q=N?z<O?z-O:z-M:0;return{[v]:y[v]+q,data:{[v]:L,centerOffset:z-L-q,...N&&{alignmentOffset:q}},reset:N}}}),gee=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...x}=ra(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=ia(i),k=yo(l),R=ia(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),I=y||(R||!w?[Wg(l)]:oee(l)),T=_!=="none";!y&&T&&I.push(...uee(l,w,_,A));const H=[l,...I],D=await u.detectOverflow(t,x),W=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&W.push(D[E]),p){const z=see(i,o,A);W.push(D[z[0]],D[z[1]])}if(U=[...U,{placement:i,overflows:W}],!W.every(z=>z<=0)){var F,O;const z=(((F=s.flip)==null?void 0:F.index)||0)+1,L=H[z];if(L&&(!(p==="alignment"?k!==yo(L):!1)||U.every(Y=>yo(Y.placement)===k?Y.overflows[0]>0:!0)))return{data:{index:z,overflows:U},reset:{placement:L}};let N=(O=U.filter(q=>q.overflows[0]<=0).sort((q,Y)=>q.overflows[1]-Y.overflows[1])[0])==null?void 0:O.placement;if(!N)switch(v){case"bestFit":{var M;const q=(M=U.filter(Y=>{if(T){const $=yo(Y.placement);return $===k||$==="y"}return!0}).map(Y=>[Y.placement,Y.overflows.filter($=>$>0).reduce(($,P)=>$+P,0)]).sort((Y,$)=>Y[1]-$[1])[0])==null?void 0:M[0];q&&(N=q);break}case"initialPlacement":N=l;break}if(i!==N)return{reset:{placement:N}}}return{}}}};function EN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function CN(e){return ree.some(t=>e[t]>=0)}const vee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ra(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=EN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:CN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=EN(o,n.floating);return{data:{escapedOffsets:l,escaped:CN(l)}}}default:return{}}}}},LI=new Set(["left","top"]);async function yee(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=ia(n),l=od(n),u=yo(n)==="y",d=LI.has(o)?-1:1,h=s&&u?-1:1,p=ra(t,e);let{mainAxis:y,crossAxis:v,alignmentAxis:_}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof _=="number"&&(v=l==="end"?_*-1:_),u?{x:v*h,y:y*d}:{x:y*d,y:v*h}}const bee=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:s,placement:o,middlewareData:l}=t,u=await yee(t,e);return o===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:s+u.y,data:{...u,placement:o}}}}},_ee=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:E=>{let{x:k,y:R}=E;return{x:k,y:R}}},...d}=ra(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=yo(ia(i)),v=l1(y);let _=h[v],w=h[y];if(o){const E=v==="y"?"top":"left",k=v==="y"?"bottom":"right",R=_+p[E],A=_-p[k];_=T0(R,_,A)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+p[E],A=w-p[k];w=T0(R,w,A)}const x=u.fn({...t,[v]:_,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[v]:o,[y]:l}}}}}},wee=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:u=!0,crossAxis:d=!0}=ra(e,t),h={x:n,y:r},p=yo(i),y=l1(p);let v=h[y],_=h[p];const w=ra(l,t),x=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const R=y==="y"?"height":"width",A=s.reference[y]-s.floating[R]+x.mainAxis,I=s.reference[y]+s.reference[R]-x.mainAxis;v<A?v=A:v>I&&(v=I)}if(d){var E,k;const R=y==="y"?"width":"height",A=LI.has(ia(i)),I=s.reference[p]-s.floating[R]+(A&&((E=o.offset)==null?void 0:E[p])||0)+(A?0:x.crossAxis),T=s.reference[p]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?x.crossAxis:0);_<I?_=I:_>T&&(_=T)}return{[y]:v,[p]:_}}}},See=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:u=()=>{},...d}=ra(e,t),h=await o.detectOverflow(t,d),p=ia(i),y=od(i),v=yo(i)==="y",{width:_,height:w}=s.floating;let x,E;p==="top"||p==="bottom"?(x=p,E=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(E=p,x=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,R=_-h.left-h.right,A=ol(w-h[x],k),I=ol(_-h[E],R),T=!t.middlewareData.shift;let H=A,D=I;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(D=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(H=k),T&&!y){const U=ls(h.left,0),F=ls(h.right,0),O=ls(h.top,0),M=ls(h.bottom,0);v?D=_-2*(U!==0||F!==0?U+F:ls(h.left,h.right)):H=w-2*(O!==0||M!==0?O+M:ls(h.top,h.bottom))}await u({...t,availableWidth:D,availableHeight:H});const W=await o.getDimensions(l.floating);return _!==W.width||w!==W.height?{reset:{rects:!0}}:{}}}};function Ov(){return typeof window<"u"}function ad(e){return II(e)?(e.nodeName||"").toLowerCase():"#document"}function cs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ko(e){var t;return(t=(II(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function II(e){return Ov()?e instanceof Node||e instanceof cs(e).Node:!1}function Ys(e){return Ov()?e instanceof Element||e instanceof cs(e).Element:!1}function oa(e){return Ov()?e instanceof HTMLElement||e instanceof cs(e).HTMLElement:!1}function kN(e){return!Ov()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof cs(e).ShadowRoot}function zf(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Ks(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function xee(e){return/^(table|td|th)$/.test(ad(e))}function Dv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Eee=/transform|translate|scale|rotate|perspective|filter/,Cee=/paint|layout|strict|content/,$l=e=>!!e&&e!=="none";let q_;function d1(e){const t=Ys(e)?Ks(e):e;return $l(t.transform)||$l(t.translate)||$l(t.scale)||$l(t.rotate)||$l(t.perspective)||!h1()&&($l(t.backdropFilter)||$l(t.filter))||Eee.test(t.willChange||"")||Cee.test(t.contain||"")}function kee(e){let t=al(e);for(;oa(t)&&!Wu(t);){if(d1(t))return t;if(Dv(t))return null;t=al(t)}return null}function h1(){return q_==null&&(q_=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),q_}function Wu(e){return/^(html|body|#document)$/.test(ad(e))}function Ks(e){return cs(e).getComputedStyle(e)}function Pv(e){return Ys(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function al(e){if(ad(e)==="html")return e;const t=e.assignedSlot||e.parentNode||kN(e)&&e.host||ko(e);return kN(t)?t.host:t}function zI(e){const t=al(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:oa(t)&&zf(t)?t:zI(t)}function pf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=zI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=cs(i);if(s){const l=A0(o);return t.concat(o,o.visualViewport||[],zf(i)?i:[],l&&n?pf(l):[])}else return t.concat(i,pf(i,[],n))}function A0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function BI(e){const t=Ks(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=oa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=Ug(n)!==s||Ug(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function f1(e){return Ys(e)?e:e.contextElement}function zu(e){const t=f1(e);if(!oa(t))return _o(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=BI(t);let o=(s?Ug(n.width):n.width)/r,l=(s?Ug(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Tee=_o(0);function jI(e){const t=cs(e);return!h1()||!t.visualViewport?Tee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ree(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==cs(e)?!1:t}function oc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=f1(e);let o=_o(1);t&&(r?Ys(r)&&(o=zu(r)):o=zu(e));const l=Ree(s,n,r)?jI(s):_o(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=cs(s),v=r&&Ys(r)?cs(r):r;let _=y,w=A0(_);for(;w&&r&&v!==_;){const x=zu(w),E=w.getBoundingClientRect(),k=Ks(w),R=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,A=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=R,d+=A,_=cs(w),w=A0(_)}}return qg({width:h,height:p,x:u,y:d})}function Lv(e,t){const n=Pv(e).scrollLeft;return t?t.left+n:oc(ko(e)).left+n}function FI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Lv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Aee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=ko(r),l=t?Dv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=_o(1);const h=_o(0),p=oa(r);if((p||!p&&!s)&&((ad(r)!=="body"||zf(o))&&(u=Pv(r)),p)){const v=oc(r);d=zu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?FI(o,u):_o(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function Nee(e){return Array.from(e.getClientRects())}function Mee(e){const t=ko(e),n=Pv(e),r=e.ownerDocument.body,i=ls(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=ls(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Lv(e);const l=-n.scrollTop;return Ks(r).direction==="rtl"&&(o+=ls(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const TN=25;function Oee(e,t){const n=cs(e),r=ko(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=h1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Lv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),v=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-v);_<=TN&&(s-=_)}else d<=TN&&(s+=d);return{width:s,height:o,x:l,y:u}}function Dee(e,t){const n=oc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=oa(e)?zu(e):_o(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function RN(e,t,n){let r;if(t==="viewport")r=Oee(e,n);else if(t==="document")r=Mee(ko(e));else if(Ys(t))r=Dee(t,n);else{const i=jI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return qg(r)}function $I(e,t){const n=al(e);return n===t||!Ys(n)||Wu(n)?!1:Ks(n).position==="fixed"||$I(n,t)}function Pee(e,t){const n=t.get(e);if(n)return n;let r=pf(e,[],!1).filter(l=>Ys(l)&&ad(l)!=="body"),i=null;const s=Ks(e).position==="fixed";let o=s?al(e):e;for(;Ys(o)&&!Wu(o);){const l=Ks(o),u=d1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||zf(o)&&!u&&$I(e,o))?r=r.filter(h=>h!==o):i=l,o=al(o)}return t.set(e,r),r}function Lee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Dv(t)?[]:Pee(t,this._c):[].concat(n),r],l=RN(t,o[0],i);let u=l.top,d=l.right,h=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const v=RN(t,o[y],i);u=ls(v.top,u),d=ol(v.right,d),h=ol(v.bottom,h),p=ls(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function Iee(e){const{width:t,height:n}=BI(e);return{width:t,height:n}}function zee(e,t,n){const r=oa(t),i=ko(t),s=n==="fixed",o=oc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=_o(0);function d(){u.x=Lv(i)}if(r||!r&&!s)if((ad(t)!=="body"||zf(i))&&(l=Pv(t)),r){const v=oc(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?FI(i,l):_o(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function V_(e){return Ks(e).position==="static"}function AN(e,t){if(!oa(e)||Ks(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ko(e)===n&&(n=n.ownerDocument.body),n}function HI(e,t){const n=cs(e);if(Dv(e))return n;if(!oa(e)){let i=al(e);for(;i&&!Wu(i);){if(Ys(i)&&!V_(i))return i;i=al(i)}return n}let r=AN(e,t);for(;r&&xee(r)&&V_(r);)r=AN(r,t);return r&&Wu(r)&&V_(r)&&!d1(r)?n:r||kee(e)||n}const Bee=async function(e){const t=this.getOffsetParent||HI,n=this.getDimensions,r=await n(e.floating);return{reference:zee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function jee(e){return Ks(e).direction==="rtl"}const Fee={convertOffsetParentRelativeRectToViewportRelativeRect:Aee,getDocumentElement:ko,getClippingRect:Lee,getOffsetParent:HI,getElementRects:Bee,getClientRects:Nee,getDimensions:Iee,getScale:zu,isElement:Ys,isRTL:jee};function UI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $ee(e,t){let n=null,r;const i=ko(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:h,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const _=zm(p),w=zm(i.clientWidth-(h+y)),x=zm(i.clientHeight-(p+v)),E=zm(h),R={rootMargin:-_+"px "+-w+"px "+-x+"px "+-E+"px",threshold:ls(0,ol(1,u))||1};let A=!0;function I(T){const H=T[0].intersectionRatio;if(H!==u){if(!A)return o();H?o(!1,H):r=setTimeout(()=>{o(!1,1e-7)},1e3)}H===1&&!UI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(I,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(I,R)}n.observe(e)}return o(!0),s}function Hee(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=f1(e),h=i||s?[...d?pf(d):[],...t?pf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?$ee(d,n):null;let y=-1,v=null;o&&(v=new ResizeObserver(E=>{let[k]=E;k&&k.target===d&&v&&t&&(v.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var R;(R=v)==null||R.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let _,w=u?oc(e):null;u&&x();function x(){const E=oc(e);w&&!UI(w,E)&&n(),w=E,_=requestAnimationFrame(x)}return n(),()=>{var E;h.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(E=v)==null||E.disconnect(),v=null,u&&cancelAnimationFrame(_)}}const Uee=bee,Wee=_ee,qee=gee,Vee=See,Yee=vee,NN=mee,Kee=wee,Gee=(e,t,n)=>{const r=new Map,i={platform:Fee,...n},s={...i.platform,_c:r};return pee(e,t,{...i,platform:s})};var Xee=typeof document<"u",Zee=function(){},yg=Xee?b.useLayoutEffect:Zee;function Vg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Vg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!Vg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function WI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function MN(e,t){const n=WI(e);return Math.round(t*n)/n}function Y_(e){const t=b.useRef(e);return yg(()=>{t.current=e}),t}function Qee(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=b.useState(r);Vg(y,r)||v(r);const[_,w]=b.useState(null),[x,E]=b.useState(null),k=b.useCallback(Y=>{Y!==T.current&&(T.current=Y,w(Y))},[]),R=b.useCallback(Y=>{Y!==H.current&&(H.current=Y,E(Y))},[]),A=s||_,I=o||x,T=b.useRef(null),H=b.useRef(null),D=b.useRef(h),W=u!=null,U=Y_(u),F=Y_(i),O=Y_(d),M=b.useCallback(()=>{if(!T.current||!H.current)return;const Y={placement:t,strategy:n,middleware:y};F.current&&(Y.platform=F.current),Gee(T.current,H.current,Y).then($=>{const P={...$,isPositioned:O.current!==!1};z.current&&!Vg(D.current,P)&&(D.current=P,rd.flushSync(()=>{p(P)}))})},[y,t,n,F,O]);yg(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,p(Y=>({...Y,isPositioned:!1})))},[d]);const z=b.useRef(!1);yg(()=>(z.current=!0,()=>{z.current=!1}),[]),yg(()=>{if(A&&(T.current=A),I&&(H.current=I),A&&I){if(U.current)return U.current(A,I,M);M()}},[A,I,M,U,W]);const L=b.useMemo(()=>({reference:T,floating:H,setReference:k,setFloating:R}),[k,R]),N=b.useMemo(()=>({reference:A,floating:I}),[A,I]),q=b.useMemo(()=>{const Y={position:n,left:0,top:0};if(!N.floating)return Y;const $=MN(N.floating,h.x),P=MN(N.floating,h.y);return l?{...Y,transform:"translate("+$+"px, "+P+"px)",...WI(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:P}},[n,l,N.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:M,refs:L,elements:N,floatingStyles:q}),[h,M,L,N,q])}const Jee=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?NN({element:r.current,padding:i}).fn(n):{}:r?NN({element:r,padding:i}).fn(n):{}}}},ete=(e,t)=>{const n=Uee(e);return{name:n.name,fn:n.fn,options:[e,t]}},tte=(e,t)=>{const n=Wee(e);return{name:n.name,fn:n.fn,options:[e,t]}},nte=(e,t)=>({fn:Kee(e).fn,options:[e,t]}),rte=(e,t)=>{const n=qee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ite=(e,t)=>{const n=Vee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ste=(e,t)=>{const n=Yee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ote=(e,t)=>{const n=Jee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var ate="Arrow",qI=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Kt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:g.jsx("polygon",{points:"0,0 30,0 15,10"})})});qI.displayName=ate;var lte=qI,p1="Popper",[VI,vl]=sa(p1),[cte,YI]=VI(p1),KI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return g.jsx(cte,{scope:t,anchor:r,onAnchorChange:i,children:n})};KI.displayName=p1;var GI="PopperAnchor",XI=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=YI(GI,n),o=b.useRef(null),l=Bn(t,o),u=b.useRef(null);return b.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:g.jsx(Kt.div,{...i,ref:l})});XI.displayName=GI;var m1="PopperContent",[ute,dte]=VI(m1),ZI=b.forwardRef((e,t)=>{var J,me,Se,Re,Ae,He;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:v="optimized",onPlaced:_,...w}=e,x=YI(m1,n),[E,k]=b.useState(null),R=Bn(t,qe=>k(qe)),[A,I]=b.useState(null),T=nee(A),H=(T==null?void 0:T.width)??0,D=(T==null?void 0:T.height)??0,W=r+(s!=="center"?"-"+s:""),U=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},F=Array.isArray(d)?d:[d],O=F.length>0,M={padding:U,boundary:F.filter(fte),altBoundary:O},{refs:z,floatingStyles:L,placement:N,isPositioned:q,middlewareData:Y}=Qee({strategy:"fixed",placement:W,whileElementsMounted:(...qe)=>Hee(...qe,{animationFrame:v==="always"}),elements:{reference:x.anchor},middleware:[ete({mainAxis:i+D,alignmentAxis:o}),u&&tte({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?nte():void 0,...M}),u&&rte({...M}),ite({...M,apply:({elements:qe,rects:pt,availableWidth:kt,availableHeight:ve})=>{const{width:Ke,height:Tt}=pt.reference,_e=qe.floating.style;_e.setProperty("--radix-popper-available-width",`${kt}px`),_e.setProperty("--radix-popper-available-height",`${ve}px`),_e.setProperty("--radix-popper-anchor-width",`${Ke}px`),_e.setProperty("--radix-popper-anchor-height",`${Tt}px`)}}),A&&ote({element:A,padding:l}),pte({arrowWidth:H,arrowHeight:D}),y&&ste({strategy:"referenceHidden",...M})]}),[$,P]=ez(N),V=xo(_);Ei(()=>{q&&(V==null||V())},[q,V]);const G=(J=Y.arrow)==null?void 0:J.x,B=(me=Y.arrow)==null?void 0:me.y,K=((Se=Y.arrow)==null?void 0:Se.centerOffset)!==0,[ee,te]=b.useState();return Ei(()=>{E&&te(window.getComputedStyle(E).zIndex)},[E]),g.jsx("div",{ref:z.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:q?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ee,"--radix-popper-transform-origin":[(Re=Y.transformOrigin)==null?void 0:Re.x,(Ae=Y.transformOrigin)==null?void 0:Ae.y].join(" "),...((He=Y.hide)==null?void 0:He.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(ute,{scope:n,placedSide:$,onArrowChange:I,arrowX:G,arrowY:B,shouldHideArrow:K,children:g.jsx(Kt.div,{"data-side":$,"data-align":P,...w,ref:R,style:{...w.style,animation:q?void 0:"none"}})})})});ZI.displayName=m1;var QI="PopperArrow",hte={top:"bottom",right:"left",bottom:"top",left:"right"},JI=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=dte(QI,r),o=hte[s.placedSide];return g.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:g.jsx(lte,{...i,ref:n,style:{...i.style,display:"block"}})})});JI.displayName=QI;function fte(e){return e!==null}var pte=e=>({name:"transformOrigin",options:e,fn(t){var x,E,k;const{placement:n,rects:r,middlewareData:i}=t,o=((x=i.arrow)==null?void 0:x.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,h]=ez(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.x)??0)+l/2,v=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?p:`${y}px`,w=`${-u}px`):d==="top"?(_=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?p:`${v}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?p:`${v}px`),{data:{x:_,y:w}}}});function ez(e){const[t,n="center"]=e.split("-");return[t,n]}var Iv=KI,Bf=XI,zv=ZI,Bv=JI,K_="rovingFocusGroup.onEntryFocus",mte={bubbles:!1,cancelable:!0},jf="RovingFocusGroup",[N0,tz,gte]=Qx(jf),[vte,nz]=sa(jf,[gte]),[yte,bte]=vte(jf),rz=b.forwardRef((e,t)=>g.jsx(N0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(N0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(_te,{...e,ref:t})})}));rz.displayName=jf;var _te=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...p}=e,y=b.useRef(null),v=Bn(t,y),_=Jx(s),[w,x]=ic({prop:o,defaultProp:l??null,onChange:u,caller:jf}),[E,k]=b.useState(!1),R=xo(d),A=tz(n),I=b.useRef(!1),[T,H]=b.useState(0);return b.useEffect(()=>{const D=y.current;if(D)return D.addEventListener(K_,R),()=>D.removeEventListener(K_,R)},[R]),g.jsx(yte,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(D=>x(D),[x]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>H(D=>D+1),[]),onFocusableItemRemove:b.useCallback(()=>H(D=>D-1),[]),children:g.jsx(Kt.div,{tabIndex:E||T===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:ft(e.onMouseDown,()=>{I.current=!0}),onFocus:ft(e.onFocus,D=>{const W=!I.current;if(D.target===D.currentTarget&&W&&!E){const U=new CustomEvent(K_,mte);if(D.currentTarget.dispatchEvent(U),!U.defaultPrevented){const F=A().filter(N=>N.focusable),O=F.find(N=>N.active),M=F.find(N=>N.id===w),L=[O,M,...F].filter(Boolean).map(N=>N.ref.current);oz(L,h)}}I.current=!1}),onBlur:ft(e.onBlur,()=>k(!1))})})}),iz="RovingFocusGroupItem",sz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=bte(iz,n),p=h.currentTabStopId===d,y=tz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=h;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),g.jsx(N0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Kt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:ft(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:ft(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:ft(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=xte(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(E==="last")R.reverse();else if(E==="prev"||E==="next"){E==="prev"&&R.reverse();const A=R.indexOf(x.currentTarget);R=h.loop?Ete(R,A+1):R.slice(A+1)}setTimeout(()=>oz(R))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});sz.displayName=iz;var wte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ste(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function xte(e,t,n){const r=Ste(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return wte[r]}function oz(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ete(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Cte=rz,kte=sz,M0=["Enter"," "],Tte=["ArrowDown","PageUp","Home"],az=["ArrowUp","PageDown","End"],Rte=[...Tte,...az],Ate={ltr:[...M0,"ArrowRight"],rtl:[...M0,"ArrowLeft"]},Nte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ff="Menu",[mf,Mte,Ote]=Qx(Ff),[yc,lz]=sa(Ff,[Ote,vl,nz]),jv=vl(),cz=nz(),[Dte,bc]=yc(Ff),[Pte,$f]=yc(Ff),uz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=jv(t),[u,d]=b.useState(null),h=b.useRef(!1),p=xo(s),y=Jx(i);return b.useEffect(()=>{const v=()=>{h.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>h.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),g.jsx(Iv,{...l,children:g.jsx(Dte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(Pte,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};uz.displayName=Ff;var Lte="MenuAnchor",g1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bf,{...i,...r,ref:t})});g1.displayName=Lte;var v1="MenuPortal",[Ite,dz]=yc(v1,{forceMount:void 0}),hz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=bc(v1,t);return g.jsx(Ite,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(sd,{asChild:!0,container:i,children:r})})})};hz.displayName=v1;var As="MenuContent",[zte,y1]=yc(As),fz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=bc(As,e.__scopeMenu),o=$f(As,e.__scopeMenu);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(Bte,{...i,ref:t}):g.jsx(jte,{...i,ref:t})})})})}),Bte=b.forwardRef((e,t)=>{const n=bc(As,e.__scopeMenu),r=b.useRef(null),i=Bn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Nv(s)},[]),g.jsx(b1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ft(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),jte=b.forwardRef((e,t)=>{const n=bc(As,e.__scopeMenu);return g.jsx(b1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Fte=sl("MenuContent.ScrollLock"),b1=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,disableOutsideScroll:_,...w}=e,x=bc(As,n),E=$f(As,n),k=jv(n),R=cz(n),A=Mte(n),[I,T]=b.useState(null),H=b.useRef(null),D=Bn(t,H,x.onContentChange),W=b.useRef(0),U=b.useRef(""),F=b.useRef(0),O=b.useRef(null),M=b.useRef("right"),z=b.useRef(0),L=_?If:b.Fragment,N=_?{as:Fte,allowPinchZoom:!0}:void 0,q=$=>{var J,me;const P=U.current+$,V=A().filter(Se=>!Se.disabled),G=document.activeElement,B=(J=V.find(Se=>Se.ref.current===G))==null?void 0:J.textValue,K=V.map(Se=>Se.textValue),ee=Qte(K,P,B),te=(me=V.find(Se=>Se.textValue===ee))==null?void 0:me.ref.current;(function Se(Re){U.current=Re,window.clearTimeout(W.current),Re!==""&&(W.current=window.setTimeout(()=>Se(""),1e3))})(P),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(W.current),[]),Rv();const Y=b.useCallback($=>{var V,G;return M.current===((V=O.current)==null?void 0:V.side)&&ene($,(G=O.current)==null?void 0:G.area)},[]);return g.jsx(zte,{scope:n,searchRef:U,onItemEnter:b.useCallback($=>{Y($)&&$.preventDefault()},[Y]),onItemLeave:b.useCallback($=>{var P;Y($)||((P=H.current)==null||P.focus(),T(null))},[Y]),onTriggerLeave:b.useCallback($=>{Y($)&&$.preventDefault()},[Y]),pointerGraceTimerRef:F,onPointerGraceIntentChange:b.useCallback($=>{O.current=$},[]),children:g.jsx(L,{...N,children:g.jsx(Lf,{asChild:!0,trapped:i,onMountAutoFocus:ft(s,$=>{var P;$.preventDefault(),(P=H.current)==null||P.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(id,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Cte,{asChild:!0,...R,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:T,onEntryFocus:ft(u,$=>{E.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(zv,{role:"menu","aria-orientation":"vertical","data-state":Az(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:ft(w.onKeyDown,$=>{const V=$.target.closest("[data-radix-menu-content]")===$.currentTarget,G=$.ctrlKey||$.altKey||$.metaKey,B=$.key.length===1;V&&($.key==="Tab"&&$.preventDefault(),!G&&B&&q($.key));const K=H.current;if($.target!==K||!Rte.includes($.key))return;$.preventDefault();const te=A().filter(J=>!J.disabled).map(J=>J.ref.current);az.includes($.key)&&te.reverse(),Xte(te)}),onBlur:ft(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(W.current),U.current="")}),onPointerMove:ft(e.onPointerMove,gf($=>{const P=$.target,V=z.current!==$.clientX;if($.currentTarget.contains(P)&&V){const G=$.clientX>z.current?"right":"left";M.current=G,z.current=$.clientX}}))})})})})})})});fz.displayName=As;var $te="MenuGroup",_1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Kt.div,{role:"group",...r,ref:t})});_1.displayName=$te;var Hte="MenuLabel",pz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Kt.div,{...r,ref:t})});pz.displayName=Hte;var Yg="MenuItem",ON="menu.itemSelect",Fv=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=$f(Yg,e.__scopeMenu),l=y1(Yg,e.__scopeMenu),u=Bn(t,s),d=b.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(ON,{bubbles:!0,cancelable:!0});p.addEventListener(ON,v=>r==null?void 0:r(v),{once:!0}),tI(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(mz,{...i,ref:u,disabled:n,onClick:ft(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:ft(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:ft(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||M0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Fv.displayName=Yg;var mz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=y1(Yg,n),l=cz(n),u=b.useRef(null),d=Bn(t,u),[h,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),g.jsx(mf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(kte,{asChild:!0,...l,focusable:!r,children:g.jsx(Kt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:ft(e.onPointerMove,gf(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ft(e.onPointerLeave,gf(_=>o.onItemLeave(_))),onFocus:ft(e.onFocus,()=>p(!0)),onBlur:ft(e.onBlur,()=>p(!1))})})})}),Ute="MenuCheckboxItem",gz=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(wz,{scope:e.__scopeMenu,checked:n,children:g.jsx(Fv,{role:"menuitemcheckbox","aria-checked":Kg(n)?"mixed":n,...i,ref:t,"data-state":S1(n),onSelect:ft(i.onSelect,()=>r==null?void 0:r(Kg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});gz.displayName=Ute;var vz="MenuRadioGroup",[Wte,qte]=yc(vz,{value:void 0,onValueChange:()=>{}}),yz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=xo(r);return g.jsx(Wte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(_1,{...i,ref:t})})});yz.displayName=vz;var bz="MenuRadioItem",_z=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=qte(bz,e.__scopeMenu),s=n===i.value;return g.jsx(wz,{scope:e.__scopeMenu,checked:s,children:g.jsx(Fv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":S1(s),onSelect:ft(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});_z.displayName=bz;var w1="MenuItemIndicator",[wz,Vte]=yc(w1,{checked:!1}),Sz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=Vte(w1,n);return g.jsx(Ps,{present:r||Kg(s.checked)||s.checked===!0,children:g.jsx(Kt.span,{...i,ref:t,"data-state":S1(s.checked)})})});Sz.displayName=w1;var Yte="MenuSeparator",xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Kt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});xz.displayName=Yte;var Kte="MenuArrow",Ez=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bv,{...i,...r,ref:t})});Ez.displayName=Kte;var Gte="MenuSub",[eRe,Cz]=yc(Gte),Ih="MenuSubTrigger",kz=b.forwardRef((e,t)=>{const n=bc(Ih,e.__scopeMenu),r=$f(Ih,e.__scopeMenu),i=Cz(Ih,e.__scopeMenu),s=y1(Ih,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>h,[h]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),g.jsx(g1,{asChild:!0,...d,children:g.jsx(mz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Az(n.open),...e,ref:na(t,i.onTriggerChange),onClick:p=>{var y;(y=e.onClick)==null||y.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ft(e.onPointerMove,gf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:ft(e.onPointerLeave,gf(p=>{var v,_;h();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],R=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,y:p.clientY},{x:k,y:y.top},{x:R,y:y.top},{x:R,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ft(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Ate[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});kz.displayName=Ih;var Tz="MenuSubContent",Rz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=bc(As,e.__scopeMenu),o=$f(As,e.__scopeMenu),l=Cz(Tz,e.__scopeMenu),u=b.useRef(null),d=Bn(t,u);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:g.jsx(b1,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:ft(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ft(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:ft(e.onKeyDown,h=>{var v;const p=h.currentTarget.contains(h.target),y=Nte[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),h.preventDefault())})})})})})});Rz.displayName=Tz;function Az(e){return e?"open":"closed"}function Kg(e){return e==="indeterminate"}function S1(e){return Kg(e)?"indeterminate":e?"checked":"unchecked"}function Xte(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Zte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Qte(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Zte(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function Jte(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function ene(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Jte(n,t)}function gf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var tne=uz,nne=g1,rne=hz,ine=fz,sne=_1,one=pz,ane=Fv,lne=gz,cne=yz,une=_z,dne=Sz,hne=xz,fne=Ez,pne=kz,mne=Rz,$v="DropdownMenu",[gne]=sa($v,[lz]),Pi=lz(),[vne,Nz]=gne($v),Mz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Pi(t),d=b.useRef(null),[h,p]=ic({prop:i,defaultProp:s??!1,onChange:o,caller:$v});return g.jsx(vne,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(tne,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};Mz.displayName=$v;var Oz="DropdownMenuTrigger",Dz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Nz(Oz,n),o=Pi(n);return g.jsx(nne,{asChild:!0,...o,children:g.jsx(Kt.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:na(t,s.triggerRef),onPointerDown:ft(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:ft(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Dz.displayName=Oz;var yne="DropdownMenuPortal",Pz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Pi(t);return g.jsx(rne,{...r,...n})};Pz.displayName=yne;var Lz="DropdownMenuContent",Iz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Nz(Lz,n),s=Pi(n),o=b.useRef(!1);return g.jsx(ine,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:ft(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:ft(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Iz.displayName=Lz;var bne="DropdownMenuGroup",_ne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(sne,{...i,...r,ref:t})});_ne.displayName=bne;var wne="DropdownMenuLabel",zz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(one,{...i,...r,ref:t})});zz.displayName=wne;var Sne="DropdownMenuItem",Bz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(ane,{...i,...r,ref:t})});Bz.displayName=Sne;var xne="DropdownMenuCheckboxItem",jz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(lne,{...i,...r,ref:t})});jz.displayName=xne;var Ene="DropdownMenuRadioGroup",Cne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(cne,{...i,...r,ref:t})});Cne.displayName=Ene;var kne="DropdownMenuRadioItem",Tne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(une,{...i,...r,ref:t})});Tne.displayName=kne;var Rne="DropdownMenuItemIndicator",Fz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(dne,{...i,...r,ref:t})});Fz.displayName=Rne;var Ane="DropdownMenuSeparator",$z=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(hne,{...i,...r,ref:t})});$z.displayName=Ane;var Nne="DropdownMenuArrow",Mne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(fne,{...i,...r,ref:t})});Mne.displayName=Nne;var One="DropdownMenuSubTrigger",Dne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(pne,{...i,...r,ref:t})});Dne.displayName=One;var Pne="DropdownMenuSubContent",Lne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(mne,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Lne.displayName=Pne;var Ine=Mz,zne=Dz,Bne=Pz,jne=Iz,Fne=zz,$ne=Bz,Hne=jz,Une=Fz,Wne=$z;function DN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Hv="Popover",[Hz]=sa(Hv,[vl]),Hf=vl(),[qne,yl]=Hz(Hv),Uz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Hf(t),u=b.useRef(null),[d,h]=b.useState(!1),[p,y]=ic({prop:r,defaultProp:i??!1,onChange:s,caller:Hv});return g.jsx(Iv,{...l,children:g.jsx(qne,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:o,children:n})})};Uz.displayName=Hv;var Wz="PopoverAnchor",Vne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=yl(Wz,n),s=Hf(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(Bf,{...s,...r,ref:t})});Vne.displayName=Wz;var qz="PopoverTrigger",Vz=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=yl(qz,n),s=Hf(n),o=Bn(t,i.triggerRef),l=g.jsx(Kt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Zz(i.open),...r,ref:o,onClick:ft(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(Bf,{asChild:!0,...s,children:l})});Vz.displayName=qz;var x1="PopoverPortal",[Yne,Kne]=Hz(x1,{forceMount:void 0}),Yz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=yl(x1,t);return g.jsx(Yne,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(sd,{asChild:!0,container:i,children:r})})})};Yz.displayName=x1;var qu="PopoverContent",Kz=b.forwardRef((e,t)=>{const n=Kne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=yl(qu,e.__scopePopover);return g.jsx(Ps,{present:r||s.open,children:s.modal?g.jsx(Xne,{...i,ref:t}):g.jsx(Zne,{...i,ref:t})})});Kz.displayName=qu;var Gne=sl("PopoverContent.RemoveScroll"),Xne=b.forwardRef((e,t)=>{const n=yl(qu,e.__scopePopover),r=b.useRef(null),i=Bn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Nv(o)},[]),g.jsx(If,{as:Gne,allowPinchZoom:!0,children:g.jsx(Gz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ft(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:ft(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:ft(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Zne=b.forwardRef((e,t)=>{const n=yl(qu,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return g.jsx(Gz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),Gz=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,...p}=e,y=yl(qu,n),v=Hf(n);return Rv(),g.jsx(Lf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(id,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(zv,{"data-state":Zz(y.open),role:"dialog",id:y.contentId,...v,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Xz="PopoverClose",Qne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=yl(Xz,n);return g.jsx(Kt.button,{type:"button",...r,ref:t,onClick:ft(e.onClick,()=>i.onOpenChange(!1))})});Qne.displayName=Xz;var Jne="PopoverArrow",ere=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Hf(n);return g.jsx(Bv,{...i,...r,ref:t})});ere.displayName=Jne;function Zz(e){return e?"open":"closed"}var tre=Uz,nre=Vz,rre=Yz,ire=Kz,sre=[" ","Enter","ArrowUp","ArrowDown"],ore=[" ","Enter"],ac="Select",[Uv,Wv,are]=Qx(ac),[ld]=sa(ac,[are,vl]),qv=vl(),[lre,bl]=ld(ac),[cre,ure]=ld(ac),Qz=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:h,autoComplete:p,disabled:y,required:v,form:_}=e,w=qv(t),[x,E]=b.useState(null),[k,R]=b.useState(null),[A,I]=b.useState(!1),T=Jx(d),[H,D]=ic({prop:r,defaultProp:i??!1,onChange:s,caller:ac}),[W,U]=ic({prop:o,defaultProp:l,onChange:u,caller:ac}),F=b.useRef(null),O=x?_||!!x.closest("form"):!0,[M,z]=b.useState(new Set),L=Array.from(M).map(N=>N.props.value).join(";");return g.jsx(Iv,{...w,children:g.jsxs(lre,{required:v,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:I,contentId:gi(),value:W,onValueChange:U,open:H,onOpenChange:D,dir:T,triggerPointerDownPosRef:F,disabled:y,children:[g.jsx(Uv.Provider,{scope:t,children:g.jsx(cre,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(N=>{z(q=>new Set(q).add(N))},[]),onNativeOptionRemove:b.useCallback(N=>{z(q=>{const Y=new Set(q);return Y.delete(N),Y})},[]),children:n})}),O?g.jsxs(_B,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:W,onChange:N=>U(N.target.value),disabled:y,form:_,children:[W===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};Qz.displayName=ac;var Jz="SelectTrigger",eB=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=qv(n),o=bl(Jz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Wv(n),h=b.useRef("touch"),[p,y,v]=SB(w=>{const x=d().filter(R=>!R.disabled),E=x.find(R=>R.value===o.value),k=xB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),_=w=>{l||(o.onOpenChange(!0),v()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return g.jsx(Bf,{asChild:!0,...s,children:g.jsx(Kt.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":wB(o.value)?"":void 0,...i,ref:u,onClick:ft(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&_(w)}),onPointerDown:ft(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:ft(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&sre.includes(w.key)&&(_(),w.preventDefault())})})})});eB.displayName=Jz;var tB="SelectValue",nB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=bl(tB,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ei(()=>{d(h)},[d,h]),g.jsx(Kt.span,{...l,ref:p,style:{pointerEvents:"none"},children:wB(u.value)?g.jsx(g.Fragment,{children:o}):s})});nB.displayName=tB;var dre="SelectIcon",rB=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Kt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});rB.displayName=dre;var hre="SelectPortal",iB=e=>g.jsx(sd,{asChild:!0,...e});iB.displayName=hre;var lc="SelectContent",sB=b.forwardRef((e,t)=>{const n=bl(lc,e.__scopeSelect),[r,i]=b.useState();if(Ei(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?rd.createPortal(g.jsx(oB,{scope:e.__scopeSelect,children:g.jsx(Uv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(aB,{...e,ref:t})});sB.displayName=lc;var $s=10,[oB,_l]=ld(lc),fre="SelectContentImpl",pre=sl("SelectContent.RemoveScroll"),aB=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=bl(lc,n),[R,A]=b.useState(null),[I,T]=b.useState(null),H=Bn(t,J=>A(J)),[D,W]=b.useState(null),[U,F]=b.useState(null),O=Wv(n),[M,z]=b.useState(!1),L=b.useRef(!1);b.useEffect(()=>{if(R)return Nv(R)},[R]),Rv();const N=b.useCallback(J=>{const[me,...Se]=O().map(He=>He.ref.current),[Re]=Se.slice(-1),Ae=document.activeElement;for(const He of J)if(He===Ae||(He==null||He.scrollIntoView({block:"nearest"}),He===me&&I&&(I.scrollTop=0),He===Re&&I&&(I.scrollTop=I.scrollHeight),He==null||He.focus(),document.activeElement!==Ae))return},[O,I]),q=b.useCallback(()=>N([D,R]),[N,D,R]);b.useEffect(()=>{M&&q()},[M,q]);const{onOpenChange:Y,triggerPointerDownPosRef:$}=k;b.useEffect(()=>{if(R){let J={x:0,y:0};const me=Re=>{var Ae,He;J={x:Math.abs(Math.round(Re.pageX)-(((Ae=$.current)==null?void 0:Ae.x)??0)),y:Math.abs(Math.round(Re.pageY)-(((He=$.current)==null?void 0:He.y)??0))}},Se=Re=>{J.x<=10&&J.y<=10?Re.preventDefault():R.contains(Re.target)||Y(!1),document.removeEventListener("pointermove",me),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",me),document.addEventListener("pointerup",Se,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",me),document.removeEventListener("pointerup",Se,{capture:!0})}}},[R,Y,$]),b.useEffect(()=>{const J=()=>Y(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[Y]);const[P,V]=SB(J=>{const me=O().filter(Ae=>!Ae.disabled),Se=me.find(Ae=>Ae.ref.current===document.activeElement),Re=xB(me,J,Se);Re&&setTimeout(()=>Re.ref.current.focus())}),G=b.useCallback((J,me,Se)=>{const Re=!L.current&&!Se;(k.value!==void 0&&k.value===me||Re)&&(W(J),Re&&(L.current=!0))},[k.value]),B=b.useCallback(()=>R==null?void 0:R.focus(),[R]),K=b.useCallback((J,me,Se)=>{const Re=!L.current&&!Se;(k.value!==void 0&&k.value===me||Re)&&F(J)},[k.value]),ee=r==="popper"?O0:lB,te=ee===O0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:x}:{};return g.jsx(oB,{scope:n,content:R,viewport:I,onViewportChange:T,itemRefCallback:G,selectedItem:D,onItemLeave:B,itemTextRefCallback:K,focusSelectedItem:q,selectedItemText:U,position:r,isPositioned:M,searchRef:P,children:g.jsx(If,{as:pre,allowPinchZoom:!0,children:g.jsx(Lf,{asChild:!0,trapped:k.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:ft(i,J=>{var me;(me=k.trigger)==null||me.focus({preventScroll:!0}),J.preventDefault()}),children:g.jsx(id,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(ee,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:J=>J.preventDefault(),...E,...te,onPlaced:()=>z(!0),ref:H,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:ft(E.onKeyDown,J=>{const me=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!me&&J.key.length===1&&V(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Re=O().filter(Ae=>!Ae.disabled).map(Ae=>Ae.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Re=Re.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const Ae=J.target,He=Re.indexOf(Ae);Re=Re.slice(He+1)}setTimeout(()=>N(Re)),J.preventDefault()}})})})})})})});aB.displayName=fre;var mre="SelectItemAlignedPosition",lB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=bl(lc,n),o=_l(lc,n),[l,u]=b.useState(null),[d,h]=b.useState(null),p=Bn(t,H=>h(H)),y=Wv(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const H=s.trigger.getBoundingClientRect(),D=d.getBoundingClientRect(),W=s.valueNode.getBoundingClientRect(),U=E.getBoundingClientRect();if(s.dir!=="rtl"){const Ae=U.left-D.left,He=W.left-Ae,qe=H.left-He,pt=H.width+qe,kt=Math.max(pt,D.width),ve=window.innerWidth-$s,Ke=DN(He,[$s,Math.max($s,ve-kt)]);l.style.minWidth=pt+"px",l.style.left=Ke+"px"}else{const Ae=D.right-U.right,He=window.innerWidth-W.right-Ae,qe=window.innerWidth-H.right-He,pt=H.width+qe,kt=Math.max(pt,D.width),ve=window.innerWidth-$s,Ke=DN(He,[$s,Math.max($s,ve-kt)]);l.style.minWidth=pt+"px",l.style.right=Ke+"px"}const F=y(),O=window.innerHeight-$s*2,M=w.scrollHeight,z=window.getComputedStyle(d),L=parseInt(z.borderTopWidth,10),N=parseInt(z.paddingTop,10),q=parseInt(z.borderBottomWidth,10),Y=parseInt(z.paddingBottom,10),$=L+N+M+Y+q,P=Math.min(x.offsetHeight*5,$),V=window.getComputedStyle(w),G=parseInt(V.paddingTop,10),B=parseInt(V.paddingBottom,10),K=H.top+H.height/2-$s,ee=O-K,te=x.offsetHeight/2,J=x.offsetTop+te,me=L+N+J,Se=$-me;if(me<=K){const Ae=F.length>0&&x===F[F.length-1].ref.current;l.style.bottom="0px";const He=d.clientHeight-w.offsetTop-w.offsetHeight,qe=Math.max(ee,te+(Ae?B:0)+He+q),pt=me+qe;l.style.height=pt+"px"}else{const Ae=F.length>0&&x===F[0].ref.current;l.style.top="0px";const qe=Math.max(K,L+w.offsetTop+(Ae?G:0)+te)+Se;l.style.height=qe+"px",w.scrollTop=me-K+w.offsetTop}l.style.margin=`${$s}px 0`,l.style.minHeight=P+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ei(()=>R(),[R]);const[A,I]=b.useState();Ei(()=>{d&&I(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(H=>{H&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return g.jsx(vre,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:T,children:g.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:g.jsx(Kt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});lB.displayName=mre;var gre="SelectPopperPosition",O0=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=$s,...s}=e,o=qv(n);return g.jsx(zv,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});O0.displayName=gre;var[vre,E1]=ld(lc,{}),D0="SelectViewport",cB=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=_l(D0,n),o=E1(D0,n),l=Bn(t,s.onViewportChange),u=b.useRef(0);return g.jsxs(g.Fragment,{children:[g.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),g.jsx(Uv.Slot,{scope:n,children:g.jsx(Kt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:ft(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const v=Math.abs(u.current-h.scrollTop);if(v>0){const _=window.innerHeight-$s*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<_){const k=E+v,R=Math.min(_,k),A=k-R;p.style.height=R+"px",p.style.bottom==="0px"&&(h.scrollTop=A>0?A:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});cB.displayName=D0;var uB="SelectGroup",[yre,bre]=ld(uB),_re=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return g.jsx(yre,{scope:n,id:i,children:g.jsx(Kt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});_re.displayName=uB;var dB="SelectLabel",wre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bre(dB,n);return g.jsx(Kt.div,{id:i.id,...r,ref:t})});wre.displayName=dB;var Gg="SelectItem",[Sre,hB]=ld(Gg),fB=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=bl(Gg,n),u=_l(Gg,n),d=l.value===r,[h,p]=b.useState(s??""),[y,v]=b.useState(!1),_=Bn(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=gi(),x=b.useRef("touch"),E=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return g.jsx(Sre,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{p(R=>R||((k==null?void 0:k.textContent)??"").trim())},[]),children:g.jsx(Uv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Kt.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:ft(o.onFocus,()=>v(!0)),onBlur:ft(o.onBlur,()=>v(!1)),onClick:ft(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:ft(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:ft(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:ft(o.onPointerMove,k=>{var R;x.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ft(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:ft(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(ore.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});fB.displayName=Gg;var zh="SelectItemText",pB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=bl(zh,n),l=_l(zh,n),u=hB(zh,n),d=ure(zh,n),[h,p]=b.useState(null),y=Bn(t,E=>p(E),u.onItemTextChange,E=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,E,u.value,u.disabled)}),v=h==null?void 0:h.textContent,_=b.useMemo(()=>g.jsx("option",{value:u.value,disabled:u.disabled,children:v},u.value),[u.disabled,u.value,v]),{onNativeOptionAdd:w,onNativeOptionRemove:x}=d;return Ei(()=>(w(_),()=>x(_)),[w,x,_]),g.jsxs(g.Fragment,{children:[g.jsx(Kt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?rd.createPortal(s.children,o.valueNode):null]})});pB.displayName=zh;var mB="SelectItemIndicator",gB=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return hB(mB,n).isSelected?g.jsx(Kt.span,{"aria-hidden":!0,...r,ref:t}):null});gB.displayName=mB;var P0="SelectScrollUpButton",vB=b.forwardRef((e,t)=>{const n=_l(P0,e.__scopeSelect),r=E1(P0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ei(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollTop>0;s(d)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?g.jsx(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});vB.displayName=P0;var L0="SelectScrollDownButton",yB=b.forwardRef((e,t)=>{const n=_l(L0,e.__scopeSelect),r=E1(L0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ei(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,h=Math.ceil(u.scrollTop)<d;s(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?g.jsx(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});yB.displayName=L0;var bB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=_l("SelectScrollButton",n),o=b.useRef(null),l=Wv(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ei(()=>{var h;const d=l().find(p=>p.ref.current===document.activeElement);(h=d==null?void 0:d.ref.current)==null||h.scrollIntoView({block:"nearest"})},[l]),g.jsx(Kt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:ft(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:ft(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:ft(i.onPointerLeave,()=>{u()})})}),xre="SelectSeparator",Ere=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Kt.div,{"aria-hidden":!0,...r,ref:t})});Ere.displayName=xre;var I0="SelectArrow",Cre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qv(n),s=bl(I0,n),o=_l(I0,n);return s.open&&o.position==="popper"?g.jsx(Bv,{...i,...r,ref:t}):null});Cre.displayName=I0;var kre="SelectBubbleInput",_B=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=Bn(r,i),o=tee(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&h){const p=new Event("change",{bubbles:!0});h.call(l,t),l.dispatchEvent(p)}},[o,t]),g.jsx(Kt.select,{...n,style:{...nI,...n.style},ref:s,defaultValue:t})});_B.displayName=kre;function wB(e){return e===""||e===void 0}function SB(e){const t=xo(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function xB(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Tre(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.textValue.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function Tre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Rre=Qz,Are=eB,Nre=nB,Mre=rB,Ore=iB,Dre=sB,Pre=cB,Lre=fB,Ire=pB,zre=gB,Bre=vB,jre=yB,[Vv]=sa("Tooltip",[vl]),Yv=vl(),EB="TooltipProvider",Fre=700,z0="tooltip.open",[$re,C1]=Vv(EB),CB=e=>{const{__scopeTooltip:t,delayDuration:n=Fre,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=b.useRef(!0),l=b.useRef(!1),u=b.useRef(0);return b.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),g.jsx($re,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:b.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};CB.displayName=EB;var vf="Tooltip",[Hre,Uf]=Vv(vf),kB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=C1(vf,e.__scopeTooltip),d=Yv(t),[h,p]=b.useState(null),y=gi(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,x=b.useRef(!1),[E,k]=ic({prop:r,defaultProp:i??!1,onChange:H=>{H?(u.onOpen(),document.dispatchEvent(new CustomEvent(z0))):u.onClose(),s==null||s(H)},caller:vf}),R=b.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,k(!0)},[k]),I=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Iv,{...d,children:g.jsx(Hre,{scope:t,contentId:y,open:E,stateAttribute:R,trigger:h,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?I():(window.clearTimeout(v.current),v.current=0)},[I,_]),onOpen:A,onClose:I,disableHoverableContent:_,children:n})})};kB.displayName=vf;var B0="TooltipTrigger",TB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Uf(B0,n),s=C1(B0,n),o=Yv(n),l=b.useRef(null),u=Bn(t,l,i.onTriggerChange),d=b.useRef(!1),h=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),g.jsx(Bf,{asChild:!0,...o,children:g.jsx(Kt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:ft(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:ft(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:ft(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:ft(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:ft(e.onBlur,i.onClose),onClick:ft(e.onClick,i.onClose)})})});TB.displayName=B0;var k1="TooltipPortal",[Ure,Wre]=Vv(k1,{forceMount:void 0}),RB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Uf(k1,t);return g.jsx(Ure,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(sd,{asChild:!0,container:i,children:r})})})};RB.displayName=k1;var Vu="TooltipContent",AB=b.forwardRef((e,t)=>{const n=Wre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Uf(Vu,e.__scopeTooltip);return g.jsx(Ps,{present:r||o.open,children:o.disableHoverableContent?g.jsx(NB,{side:i,...s,ref:t}):g.jsx(qre,{side:i,...s,ref:t})})}),qre=b.forwardRef((e,t)=>{const n=Uf(Vu,e.__scopeTooltip),r=C1(Vu,e.__scopeTooltip),i=b.useRef(null),s=Bn(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=b.useCallback(()=>{l(null),p(!1)},[p]),v=b.useCallback((_,w)=>{const x=_.currentTarget,E={x:_.clientX,y:_.clientY},k=Gre(E,x.getBoundingClientRect()),R=Xre(E,k),A=Zre(w.getBoundingClientRect()),I=Jre([...R,...A]);l(I),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&h){const _=x=>v(x,h),w=x=>v(x,u);return u.addEventListener("pointerleave",_),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),h.removeEventListener("pointerleave",w)}}},[u,h,v,y]),b.useEffect(()=>{if(o){const _=w=>{const x=w.target,E={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),R=!Qre(E,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,h,o,d,y]),g.jsx(NB,{...e,ref:s})}),[Vre,Yre]=Vv(vf,{isInside:!1}),Kre=TQ("TooltipContent"),NB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Uf(Vu,n),d=Yv(n),{onClose:h}=u;return b.useEffect(()=>(document.addEventListener(z0,h),()=>document.removeEventListener(z0,h)),[h]),b.useEffect(()=>{if(u.trigger){const p=y=>{const v=y.target;v!=null&&v.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),g.jsx(id,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(zv,{"data-state":u.stateAttribute,...d,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[g.jsx(Kre,{children:r}),g.jsx(Vre,{scope:n,isInside:!0,children:g.jsx(iI,{id:u.contentId,role:"tooltip",children:i||r})})]})})});AB.displayName=Vu;var MB="TooltipArrow",OB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Yv(n);return Yre(MB,n).isInside?null:g.jsx(Bv,{...i,...r,ref:t})});OB.displayName=MB;function Gre(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function Xre(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function Zre(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function Qre(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function Jre(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),eie(t)}function eie(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var tie=CB,nie=kB,rie=TB,iie=RB,sie=AB,oie=OB;function T1({...e}){return g.jsx(tre,{"data-slot":"popover",...e})}function R1({...e}){return g.jsx(nre,{"data-slot":"popover-trigger",...e})}function A1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(rre,{children:g.jsx(ire,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const aie={"no-proxy":{heading:"还没有连接开发机",body:"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。"},"client-token-missing":{heading:"需要 client token",body:"Relay 服务器已启用客户端访问控制。请在设置里填写。"},"client-token-invalid":{heading:"client token 无效",body:"当前浏览器保存的 client token 无效或已过期。请在设置里更新。"},"no-session":{heading:"没有选中的会话",body:""},"no-messages":{heading:"开始对话",body:""}};function ec({variant:e,action:t}){const{heading:n,body:r}=aie[e];return e==="no-messages"?g.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:g.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[g.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&g.jsx("div",{children:t})]})}const lie={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},cie={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function PN({status:e,className:t}){return g.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",lie[e],t),role:"status","aria-label":cie[e]})}function DB({layout:e,variant:t="default"}){const n=Oe(_=>_.proxies),r=Oe(_=>_.proxyListLoaded),i=Oe(_=>_.relayClientAuthIssue),s=Oe(_=>_.selectedProxyId),o=Oe(_=>_.proxySwitchTarget),l=Di(),u=Xs(),[d,h]=b.useState(!1);async function p(_,w){if(o)return;const x=Nt;if(!x){et.error("请先连接开发机");return}const E=w??_,k=s!==null&&s!==_;Oe.getState().setProxySwitchTarget({proxyId:_,name:E});try{const R=await x.selectProxy(_);if(!R.success){et.error(`无法连接 ${E}:${R.error??"未知错误"}`);return}k&&(It.getState().prepareForProxySwitch(E),ii.getState().prepareForProxySwitch()),fr("local",on.proxyId,_),Oe.getState().setProxy(_,w??null),Oe.getState().setProxyOnline(!0),Oe.getState().transitionToPhase("session_browsing"),x.sendControl({type:"session_list"}),x.requestProxyInfo().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const I=ii.getState();I.setHomePath(A.homePath),I.setAgentCli(A.agentCli)}).catch(A=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",A)}),x.requestAgentStatuses().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const I=It.getState();for(const T of A)I.setAgentStatus(T.sessionId,T.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),x.requestSessionHistory().then(A=>{Oe.getState().selectedProxyId===_&&It.getState().setHistorySessions(A)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),h(!1),(e==="page"||l.pathname.startsWith("/chat/"))&&u("/sessions")}catch(R){const A=R instanceof Error?R.message:"未知错误";et.error(`无法连接 ${E}:${A}`)}finally{Oe.getState().setProxySwitchTarget(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(ec,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(ec,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(ec,{variant:"no-proxy"}):g.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[g.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),g.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,x=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:Ye("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",w?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx(PN,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),g.jsx(Ql,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===_.proxyId?g.jsx(ta,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})]}):g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[g.jsx(Ql,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});const y=n.find(_=>_.proxyId===s),v=(y==null?void 0:y.name)??(y==null?void 0:y.proxyId)??"未选择开发机";return g.jsxs(T1,{open:d,onOpenChange:h,children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${v}`,children:[t==="default"&&g.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),g.jsx("span",{className:Ye("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:v}),g.jsx(fl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(A1,{align:"start",className:"w-[260px] p-1",children:n.length===0?g.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):g.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,x=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:Ye("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",w?"bg-accent text-accent-foreground":"hover:bg-accent",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线",children:[g.jsx(PN,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsx(Ql,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===_.proxyId?g.jsx(ta,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&s!==_.proxyId&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})})]})}const LN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,IN=BP,uie=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return IN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(d=>{const h=n==null?void 0:n[d],p=s==null?void 0:s[d];if(h===null)return null;const y=LN(h)||LN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,h)=>{let[p,y]=h;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,h)=>{let{class:p,className:y,...v}=h;return Object.entries(v).every(_=>{let[w,x]=_;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return IN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},die=uie("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-normal whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function mt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?CQ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(die({variant:t,size:n,className:e})),...i})}function hie({delayDuration:e=0,...t}){return g.jsx(tie,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Wf({...e}){return g.jsx(nie,{"data-slot":"tooltip",...e})}function qf({...e}){return g.jsx(rie,{"data-slot":"tooltip-trigger",...e})}function Vf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(iie,{children:g.jsxs(sie,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&g.jsx(oie,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Kv({...e}){return g.jsx(r1,{"data-slot":"sheet",...e})}function fie({...e}){return g.jsx(eee,{"data-slot":"sheet-trigger",...e})}function pie({...e}){return g.jsx(i1,{"data-slot":"sheet-portal",...e})}function mie({className:e,...t}){return g.jsx(s1,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Gv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return g.jsxs(pie,{children:[g.jsx(mie,{className:t}),g.jsxs(o1,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&g.jsxs(a1,{"data-slot":"sheet-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[g.jsx(Ju,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function N1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function Xv({className:e,...t}){return g.jsx(OI,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function gie({className:e,...t}){return g.jsx(DI,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}function M1({...e}){return g.jsx(Ine,{"data-slot":"dropdown-menu",...e})}function O1({...e}){return g.jsx(zne,{"data-slot":"dropdown-menu-trigger",...e})}function D1({className:e,sideOffset:t=4,...n}){return g.jsx(Bne,{children:g.jsx(jne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function go({className:e,inset:t,variant:n="default",...r}){return g.jsx($ne,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function G_({className:e,children:t,checked:n,...r}){return g.jsxs(Hne,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[g.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:g.jsx(Une,{children:g.jsx(ta,{className:"size-4"})})}),t]})}function Bm({className:e,inset:t,...n}){return g.jsx(Fne,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function X_({className:e,...t}){return g.jsx(Wne,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}const vie={claude:"Claude Code",codex:"Codex"},zN=["claude","codex"];function Zv(e){return vie[e]}function PB(e,t){return zN.indexOf(e)-zN.indexOf(t)}function j0(e){return e.provider??"claude"}const F0=60*1e3,$0=60*F0,yie=24*$0;function LB(e,t=Date.now()){const n=t-e;if(n<F0)return"刚刚";if(n<$0)return`${Math.floor(n/F0)} 分钟前`;if(n<yie)return`${Math.floor(n/$0)} 小时前`;const r=new Date(e),i=r.getMonth()+1,s=r.getDate(),o=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0");return`${i} 月 ${s} 日 ${o}:${l}`}const BN={idle:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"空闲"},working:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"工作中"},compacting:{dot:"bg-[var(--color-status-compacting)] animate-pulse",text:"text-[var(--color-status-compacting)]",label:"压缩中"},waiting_approval:{dot:"bg-[var(--color-status-warning)]",text:"text-[var(--color-status-warning)]",label:"等待审批"},error:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"出错"},terminated:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已终止"}};function H0(e){return e.kind!=="terminal"?BN[e.state]:e.state==="terminated"?BN.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function bie({session:e}){const t=H0(e);return g.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function _ie({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;return g.jsx("span",{className:"inline-flex h-5 w-4 shrink-0 items-center justify-center text-muted-foreground",role:"img","aria-label":t,title:t,"data-slot":"session-mode-icon","data-mode":e,children:g.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function wie({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=kv(e.name),d=Kx(e),h=e.nameLocked&&e.name?e.name:d||(u==="New Session"?e.sessionId.slice(0,8):u),p=!!e.mode||!!e.provider||o!==void 0,y=o!==void 0?LB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&g.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),g.jsxs("button",{type:"button",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[g.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[g.jsx(bie,{session:e}),g.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&g.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&g.jsx(_ie,{mode:e.mode}),e.mode&&g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Zv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:Ye("shrink-0",H0(e).text),children:H0(e).label}),y&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),g.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:g.jsx(mt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:g.jsx(f8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(go,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(go,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function _c({...e}){return g.jsx(r1,{"data-slot":"dialog",...e})}function Sie({...e}){return g.jsx(i1,{"data-slot":"dialog-portal",...e})}function xie({className:e,...t}){return g.jsx(s1,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function wc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs(Sie,{"data-slot":"dialog-portal",children:[g.jsx(xie,{}),g.jsxs(o1,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&g.jsxs(a1,{"data-slot":"dialog-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[g.jsx(Ju,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Sc({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&g.jsx(a1,{asChild:!0,children:g.jsx(mt,{variant:"outline",children:"Close"})})]})}function ll({className:e,...t}){return g.jsx(OI,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function cc({className:e,...t}){return g.jsx(DI,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function cl(e){const[t,n]=b.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return b.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function Eie({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(Cie,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:LB(e.updatedAt,t)}),u=g.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return g.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:g.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,g.jsx(j9,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Cie({title:e,modeTag:t}){return g.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&g.jsx(kie,{mode:t})]})}function kie({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:g.jsx(n,{className:"size-3","aria-hidden":"true"})})}function IB({providerLabel:e}){return g.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:g.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[g.jsx(m7,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),g.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Tie({now:e}){const t=It(F=>F.historySessions),[n,r]=b.useState(null),[i,s]=b.useState(null),[o,l]=b.useState("json"),[u,d]=b.useState("default"),[h,p]=b.useState(!1),[y,v]=b.useState(!1),[_,w]=b.useState(new Set),[x,E]=b.useState(new Set),k=Xs(),R=b.useMemo(()=>{const F=new Map;for(const O of t){const M=j0(O);let z=F.get(M);z||(z=new Map,F.set(M,z));const L=zB(O.projectDir),N=z.get(L);N?N.sessions.push(O):z.set(L,{dir:L,sessions:[O]})}return Array.from(F.entries()).sort(([O],[M])=>PB(O,M)).map(([O,M])=>({provider:O,sessions:Array.from(M.values()).flatMap(z=>z.sessions),projects:Array.from(M.values()).map(z=>({dir:z.dir,shortDir:kv(z.dir),sessions:z.sessions}))}))},[t]);function A(F){s(F),l(Rie(F)),d("default")}async function I(F,O,M){if(n)return;const z=Nt;if(!z){et.error("请先连接开发机");return}r(F.id);const L=j0(F);try{const N=await z.createSession({cwd:F.projectDir,mode:O,provider:L,resumeSessionId:F.id,...M?{permissionMode:M}:{}});if(N.error||!N.sessionId){et.error(`恢复失败:${N.error??"未知错误"}`);return}const q={sessionId:N.sessionId,state:"idle",mode:N.mode??O,provider:N.provider??"claude"};It.getState().addSession(q),k(`/chat/${N.sessionId}?mode=${N.mode??O}`),s(null)}catch(N){et.error(`恢复失败:${N instanceof Error?N.message:String(N)}`)}finally{r(null)}}function T(){const F=Nt;!F||h||(p(!0),F.requestSessionHistory().then(O=>It.getState().setHistorySessions(O)).catch(O=>{et.error(O instanceof Error?O.message:String(O))}).finally(()=>{p(!1)}))}function H(F,O){const M=jN(F,O);E(z=>{const L=new Set(z);return L.has(M)?L.delete(M):L.add(M),L})}function D(F){w(O=>{const M=new Set(O);return M.has(F)?M.delete(F):M.add(F),M})}const W=t.length>0,U=i?BB():[];return g.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[g.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[g.jsxs("button",{type:"button",onClick:()=>W&&v(F=>!F),disabled:!W,"aria-expanded":W?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[g.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",W?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),W?g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:T,disabled:h,"data-slot":"history-refresh",children:g.jsx(Nx,{className:Ye("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!W&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),W&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(F=>{const O=_.has(F.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>D(F.provider),"aria-expanded":!O,"data-slot":"history-provider-header","data-expanded":!O,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:Zv(F.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:F.sessions.length}),g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!O&&"rotate-90"),"aria-hidden":"true"})]}),!O&&g.jsx("ul",{role:"list",className:"flex flex-col",children:F.projects.map(M=>{const z=jN(F.provider,M.dir),L=x.has(z);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>H(F.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),g.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&g.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(N=>g.jsx(Eie,{session:N,now:e,disabled:n!==null,loading:n===N.id,onClick:()=>A(N),modeTag:N.preferredMode},N.id))})]},z)})})]},F.provider)})}),g.jsx(Aie,{session:i,open:i!==null,modes:U,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:F=>{F||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&I(i,o,u)}})]})}function jN(e,t){return`${e}:${zB(t)}`}function zB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function BB(){return["json","pty"]}function Rie(e){const t=BB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Aie({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=b.useState(!1),y=i==="bypassPermissions",v=cl("(min-width: 768px)");b.useEffect(()=>{t||p(!1)},[t]);const _=h?g.jsx(IB,{providerLabel:e?Zv(j0(e)):"Agent"}):g.jsxs("div",{className:"grid min-w-0 gap-4",children:[g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&g.jsx(FN,{checked:r==="json",label:"聊天",icon:g.jsx(Ax,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(FN,{checked:r==="pty",label:"终端",icon:g.jsx(Mx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[g.jsx(Z_,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(Z_,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(Z_,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(mt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(mt,{type:"button",variant:h?"destructive":"default",disabled:s,onClick:()=>{if(y&&!h){p(!0);return}d()},"data-slot":h?"bypass-permission-confirm":void 0,children:s?"恢复中...":h?"确认":"恢复"})]});return v?g.jsx(_c,{open:t,onOpenChange:o,children:g.jsxs(wc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(Sc,{className:"min-w-0",children:[g.jsx(ll,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(cc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),_,g.jsx(Yu,{children:w})]})}):g.jsx(Kv,{open:t,onOpenChange:o,children:g.jsxs(Gv,{side:"bottom",focusSurfaceOnOpen:!0,className:"inset-x-2 w-auto max-h-[calc(100dvh-0.75rem)] min-w-0 overflow-hidden rounded-t-xl border bg-background p-0","data-slot":"history-restore-dialog",children:[g.jsxs(N1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Xv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(gie,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),g.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:_}),g.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:g.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function FN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,g.jsx("span",{className:"min-w-0 text-center",children:t}),g.jsx(ta,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Z_({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[g.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&g.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),g.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&g.jsx(ta,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Nie({...e}){return g.jsx(Rre,{"data-slot":"select",...e})}function Mie({...e}){return g.jsx(Nre,{"data-slot":"select-value",...e})}function Oie({className:e,size:t="default",children:n,...r}){return g.jsxs(Are,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,g.jsx(Mre,{asChild:!0,children:g.jsx(fl,{className:"size-4 opacity-50"})})]})}function Die({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(Ore,{children:g.jsxs(Dre,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[g.jsx(Lie,{}),g.jsx(Pre,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),g.jsx(Iie,{})]})})}function Pie({className:e,children:t,...n}){return g.jsxs(Lre,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[g.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(zre,{children:g.jsx(ta,{className:"size-4"})})}),g.jsx(Ire,{children:t})]})}function Lie({className:e,...t}){return g.jsx(Bre,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Rx,{className:"size-4"})})}function Iie({className:e,...t}){return g.jsx(jre,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(fl,{className:"size-4"})})}function P1(e){return!e||e.endsWith("/")?e:`${e}/`}function zie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function Bie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function jie(e,t,n){var o;if(t==="insert")return{currentPath:Bie(e)||"./",query:zie(e)};if(!e)return{currentPath:"./",query:""};const r=e.replace(/\/+$/,"")||"/";if(e.endsWith("/")||r===(n==null?void 0:n.baseCwd)||((o=n==null?void 0:n.knownDirs)==null?void 0:o.has(r)))return{currentPath:P1(r),query:""};const s=e.lastIndexOf("/");return{currentPath:s>=0?e.slice(0,s+1):"./",query:s>=0?e.slice(s+1).toLowerCase():e.toLowerCase()}}function Fie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function $ie(e,t){return`${P1(e)}${t.name}${t.isDir?"/":""}`}function $N(e,t){const n=e.trim().replace(/\/+$/,"")||"/",r=t.trim().replace(/^\/+|\/+$/g,"");return!n.startsWith("/")||!r||t.trim().startsWith("/")||r.split("/").some(i=>i===""||i==="."||i==="..")?null:n==="/"?`/${r}`:`${n}/${r}`}const jB=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ii($=>$.tree),h=ii($=>$.cwd),p=ii($=>$.homePath),y=i==="insert"?h:p||h,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>jie(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,x=b.useMemo(()=>Fie(y,w),[y,w]),E=_.query,k=b.useRef(new Set),[R,A]=b.useState(!1),[I,T]=b.useState(""),[H,D]=b.useState(!1);b.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const $=Nt;if(!$)return;let P=!1;return k.current.add(x),$.requestDirectoryList(x).then(V=>{P||ii.getState().setDirEntries(V.path,V.entries)}).catch(()=>{P||ii.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{P=!0}},[x,d]);const W=!d.has(x),U=b.useMemo(()=>{let $=d.get(x)??[];return o&&($=$.filter(P=>P.isDir)),E&&($=$.filter(P=>P.name.toLowerCase().includes(E))),$},[d,x,E,o]),[F,O]=b.useState(0);b.useEffect(()=>O(0),[w,E]),b.useEffect(()=>{A(!1),T("")},[x]),b.useEffect(()=>{F>=U.length&&U.length>0&&O(U.length-1)},[U.length,F]);const M=b.useRef(null),z=b.useRef(!1);b.useEffect(()=>{var P;if(!z.current)return;z.current=!1;const $=(P=M.current)==null?void 0:P.querySelector(`[data-entry-index="${F}"]`);$==null||$.scrollIntoView({block:"nearest"})},[F]);const L=b.useCallback($=>{const P=$ie(w,$);return i==="insert"?P.replace(/^\.\//,""):P},[w,i]);async function N(){const $=$N(x,I);if(!(!$||!r)){D(!0);try{const P=await r($);if(!P)return;T(""),A(!1),n(P1(P))}finally{D(!1)}}}b.useImperativeHandle(u,()=>({handleKey($){return U.length===0?!1:$.key==="ArrowDown"?(z.current=!0,O(P=>Math.min(U.length-1,P+1)),!0):$.key==="ArrowUp"?(z.current=!0,O(P=>Math.max(0,P-1)),!0):$.key==="Enter"&&!$.nativeEvent.isComposing?(n(L(U[F])),!0):!1}}),[U,F,L,n]);const q=s==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":i==="insert"?"absolute bottom-full left-0 right-0 z-50 mb-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden":"absolute left-0 right-0 top-full z-50 mt-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden",Y=s==="inline"?"h-44 overflow-y-auto overscroll-contain":i==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return g.jsxs("div",{className:q,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?g.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?g.jsx("button",{type:"button",className:"rounded px-2 py-1 text-xs text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",disabled:!x||H,onClick:()=>A($=>!$),children:"新建目录"}):null]}),R?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:I,onChange:$=>T($.target.value),onKeyDown:$=>{$.key==="Enter"&&!$.nativeEvent.isComposing&&($.preventDefault(),N()),$.key==="Escape"&&(A(!1),T(""))},placeholder:"目录名称",className:"min-h-11 min-w-0 flex-1 rounded-md border border-border bg-input px-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-8 md:min-h-0 md:text-sm",autoComplete:"off",autoCorrect:"off",spellCheck:!1}),g.jsx("button",{type:"button",className:"min-h-11 rounded-md bg-primary px-3 text-sm text-primary-foreground disabled:cursor-not-allowed disabled:opacity-50 md:h-8 md:min-h-0",disabled:!$N(x,I)||H,onClick:()=>void N(),children:H?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:Y,children:U.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:W?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map(($,P)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(L($)),onMouseEnter:()=>O(P),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",P===F&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",$.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":$.isDir?"dir":"file","data-entry-index":P,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[$.name,$.isDir?"/":""]})})},$.name))})})]})}),HN="工作目录不存在或不可访问:",Hie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],FB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],ea={claude:"Claude Code",codex:"Codex"};function Uie(e,t){return t!==Zr.PATH_NOT_FOUND||!e.startsWith(HN)?null:e.slice(HN.length).trim()||null}function Xg(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function Wie(e,t){return t.title?t.disabled?`${ea[e]}:${t.title}`:`${ea[e]} 路径:${t.title}`:`${ea[e]}:${t.label}`}function qie(e,t){return e!=="codex"||FB.some(n=>n.value===t)?t:"default"}async function Vie({relay:e,agentCli:t,form:n,timeoutMs:r=Vx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Xg(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${ea[n.provider]} 不可用:${p}`:`${ea[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=Uie(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,v=((h=p.name)==null?void 0:h.trim())||void 0;return{type:"success",session:{sessionId:p.sessionId,...p.kind!==void 0?{kind:p.kind}:{},name:v,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",mode:y,provider:p.provider??l,...p.ptyOwner!==void 0?{ptyOwner:p.ptyOwner}:{}},route:`/chat/${p.sessionId}?mode=${y}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function Yie({relay:e,timeoutMs:t=Vx}){var n;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const r=await e.createSession({kind:"terminal",mode:"pty"},t);return r.error||!r.sessionId?{type:"create_error",message:`创建终端失败:${r.error??"未知错误"}`}:{type:"success",session:{sessionId:r.sessionId,kind:"terminal",name:((n=r.name)==null?void 0:n.trim())||void 0,...r.nameLocked!==void 0?{nameLocked:r.nameLocked}:{},state:"idle",mode:"pty",provider:r.provider??"claude",...r.ptyOwner!==void 0?{ptyOwner:r.ptyOwner}:{}},route:`/chat/${r.sessionId}?mode=pty`}}catch(r){return{type:"exception",message:r instanceof Error?r.message:String(r)}}}function Kie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Xg("claude",e),y=Xg("codex",e),v=e==null?void 0:e[t];return g.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[g.jsxs("div",{className:"flex items-center justify-between",children:[g.jsx("span",{className:"text-sm",children:"Agent CLI"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsx(UN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(UN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),g.jsx("div",{className:"relative min-w-0 rounded-md border border-border bg-muted/20 px-3 py-2.5 md:p-3","data-slot":"agent-cli-path-card",children:r===t?g.jsx(Gie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(Xie,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function UN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Wf,{children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":ea[e],onClick:i,className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:ea[e]}),g.jsx("span",{className:Ye("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(Vf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:Wie(e,n)})})]})}function Gie({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[g.jsxs("label",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:"sr-only",children:"CLI 路径"}),g.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),o()),l.key==="Escape"&&(l.preventDefault(),s())},placeholder:e==="claude"?"/home/dev/.local/bin/claude":"/home/dev/.local/bin/codex",className:"min-h-11 w-full rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-10 md:min-h-0 md:text-sm"}),g.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>g.jsx("option",{value:l},l))})]}),g.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[g.jsx(mt,{type:"button",variant:"ghost",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground md:h-8 md:min-h-0",onClick:s,disabled:r,children:"取消"}),g.jsx(mt,{type:"button",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium md:h-8 md:min-h-0",onClick:o,disabled:r||!n.trim(),children:r?"保存中...":"保存路径"})]})]})]})}function Xie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[g.jsx("p",{className:Ye("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),g.jsx(mt,{type:"button",variant:"outline",className:"h-8 min-h-0 shrink-0 self-end rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground sm:self-auto",onClick:()=>r(e),children:"指定路径"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 size-11 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/70 hover:text-foreground","aria-label":"指定路径",onClick:()=>r(e),children:g.jsx(W8,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:Ye("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function Bh({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[h,p]=b.useState("default"),[y,v]=b.useState(!1),[_,w]=b.useState(!1),[x,E]=b.useState(null),[k,R]=b.useState(!1),[A,I]=b.useState(null),[T,H]=b.useState(""),[D,W]=b.useState(!1),U=b.useRef(null),F=b.useRef(e);F.current=e;const O=Xs(),M=ii(Re=>Re.homePath),z=ii(Re=>Re.agentCli),L=cl("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&z)return;const Re=Nt==null?void 0:Nt.requestProxyInfo();Re&&Re.then(Ae=>{const He=ii.getState();He.setHomePath(Ae.homePath),He.setAgentCli(Ae.agentCli)}).catch(Ae=>{console.error("[create-session-dialog] requestProxyInfo failed",Ae)})},[e,M,z]),b.useEffect(()=>{if(!k)return;function Re(Ae){var qe;const He=Ae.target;He instanceof Node&&((qe=U.current)!=null&&qe.contains(He))||window.setTimeout(()=>R(!1),0)}return document.addEventListener("pointerdown",Re,!0),()=>document.removeEventListener("pointerdown",Re,!0)},[k]);function N(){r(""),s(""),R(!1),l("claude"),d("pty"),p("default"),v(!1),E(null),I(null),H(""),W(!1)}function q(){if(h==="bypassPermissions"){v(!0);return}B()}async function Y(){await B(),F.current&&v(!1)}const $=o==="codex"?FB:Hie,P=Xg(o,z),V=_||D||P.disabled;function G(Re){const Ae=qie(Re,h);Ae!==h&&p(Ae)}async function B(Re){E(null),w(!0);try{const Ae=await Vie({relay:Nt,agentCli:z,form:{cwd:Re??i,name:n,provider:o,permissionMode:h,mode:u}});if(Ae.type==="success"){if(It.getState().addSession(Ae.session),!F.current)return;t(!1),N(),O(Ae.route);return}if(Ae.type==="missing_cwd"&&E(Ae.path),et.error(Ae.message),Ae.type==="validation_error"||Ae.type==="relay_missing")return}finally{w(!1)}}async function K(Re){const Ae=Nt;if(!Ae)return et.error("请先连接开发机"),null;try{const He=await Ae.createDirectory(Re);return He.success?(s(He.path),E(null),et.success("目录已创建"),He.path):(et.error(`目录创建失败:${He.error??"未知错误"}`),null)}catch(He){return et.error(He instanceof Error?He.message:String(He)),null}}function ee(Re){var He;const Ae=z==null?void 0:z[Re];I(Re),H((Ae==null?void 0:Ae.command)??((He=Ae==null?void 0:Ae.suggestions)==null?void 0:He[0])??"")}async function te(){if(!A)return;const Re=T.trim();if(!Re){et.error("请输入 Agent CLI 路径");return}const Ae=Nt;if(!Ae){et.error("请先连接开发机");return}W(!0);try{const He=await Ae.updateAgentCliPath(A,Re);if(He.error||!He.agentCli){et.error(`路径保存失败:${He.error??"未知错误"}`);return}ii.getState().setAgentCli(He.agentCli),et.success(`${ea[A]} 路径已保存`),I(null),H("")}catch(He){et.error(He instanceof Error?He.message:String(He))}finally{W(!1)}}function J(Re){d(Re),G(o)}function me(Re){var He;const Ae=Re.relatedTarget;Ae instanceof Node&&((He=U.current)!=null&&He.contains(Ae))||window.setTimeout(()=>R(!1),0)}const Se=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(IB,{providerLabel:ea[o]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),g.jsx(mt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void Y(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):g.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Re=>{Re.preventDefault(),q()},children:[g.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[g.jsx("span",{className:"text-sm",children:"名称(可选)"}),g.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Re=>r(Re.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),g.jsxs("div",{ref:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:me,children:[g.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),g.jsx("input",{id:"create-session-cwd",type:"text","aria-labelledby":"create-session-cwd-label",name:"dev-anywhere-session-cwd",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:i,onFocus:()=>R(!0),onChange:Re=>{s(Re.target.value),E(null)},placeholder:"输入绝对路径",className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm"}),k?g.jsx(jB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:K,onSelect:Re=>{s(Re),E(null),R(!0)}}):null]}),x?g.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[g.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),g.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:x})]}):null,g.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"交互方式"}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>J("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),g.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>J("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),g.jsx(Kie,{agentCli:z,provider:o,isDesktop:L,editingCliProvider:A,cliPathInput:T,savingCliPath:D,onProviderChange:Re=>{l(Re),G(Re)},onOpenCliPathEditor:ee,onCliPathInputChange:H,onCancelCliPathEditor:()=>{I(null),H("")},onSaveCliPath:()=>void te()}),g.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"权限模式"}),g.jsxs(Nie,{value:h,onValueChange:Re=>p(Re),children:[g.jsx(Oie,{className:"w-full",children:g.jsx(Mie,{})}),g.jsx(Die,{children:$.map(Re=>g.jsx(Pie,{value:Re.value,children:Re.label},Re.value))})]})]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),g.jsx(mt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:V,children:_?"创建中...":"创建"})]})]});return L?g.jsx(_c,{open:e,onOpenChange:t,children:g.jsxs(wc,{className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[44rem]","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[g.jsx(Sc,{children:g.jsx(ll,{children:y?"跳过全部审批?":"新建会话"})}),Se]})}):g.jsx(Kv,{open:e,onOpenChange:t,children:g.jsxs(Gv,{side:"bottom",className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto overflow-x-hidden overflow-y-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[g.jsx(N1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:y?"跳过全部审批?":"新建会话"})}),Se]})})}function jh({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=b.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=b.useState(s),[u,d]=b.useState(null),[h,p]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(v){v.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return g.jsx(_c,{open:e,onOpenChange:r,children:g.jsx(wc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:g.jsxs("form",{className:"grid gap-4",onSubmit:v=>void y(v),children:[g.jsxs(Sc,{children:[g.jsx(ll,{children:"重命名会话"}),g.jsx(cc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),g.jsxs("div",{className:"grid gap-2",children:[g.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),g.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:v=>{l(v.target.value),u&&d(null)}}),u?g.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(mt,{type:"submit",disabled:h,children:"保存"})]})]})})})}function Zie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function Qie(e){return(e==null?void 0:e.kind)==="terminal"}function Jie(e){return Zie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Qie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function jm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Jie(t);function s(){t&&(r(t),n(!1))}return g.jsx(_c,{open:e,onOpenChange:n,children:g.jsxs(wc,{"data-slot":"session-termination-dialog",children:[g.jsxs(Sc,{children:[g.jsx(ll,{children:i.title}),g.jsx(cc,{children:i.description})]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(mt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function $B(e){var t,n,r,i,s,o,l,u,d,h,p,y;return e.connected===!1||e.proxyOnline===!1?"disconnected":e.routeSessionEnded||((t=e.session)==null?void 0:t.state)==="terminated"?"terminated":((n=e.session)==null?void 0:n.state)==="error"?"error":e.hasPendingApproval||((r=e.session)==null?void 0:r.state)==="waiting_approval"?"waiting_approval":((i=e.session)==null?void 0:i.state)==="compacting"?"compacting":((s=e.session)==null?void 0:s.state)==="working"?"working":((o=e.session)==null?void 0:o.state)==="idle"?"idle":((l=e.agentStatus)==null?void 0:l.phase)==="waiting_permission"||((u=e.ptyState)==null?void 0:u.state)==="approval_wait"?"waiting_approval":((d=e.agentStatus)==null?void 0:d.phase)==="thinking"||((h=e.agentStatus)==null?void 0:h.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function ese(e){if(e.session.state==="error")return"error";const t=$B(e);return t==="disconnected"?e.session.state:t}function HB({layout:e}){const t=It(K=>K.sessions),n=It(K=>K.sessionListLoaded),r=It(K=>K.agentStatusBySessionId),i=It(K=>K.ptyStateBySessionId),s=It(K=>K.renameSession),o=Vt(K=>K.bySessionId),l=mU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Oe(K=>!!K.selectedProxyId),h=Oe(K=>K.proxyListLoaded),p=Oe(K=>K.proxySwitchTarget),y=It(K=>K.loadingProxyName),v=p!==null||!h||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",x=Xs(),[E,k]=b.useState(!1),[R,A]=b.useState(!1),[I,T]=b.useState(null),[H,D]=b.useState(null),{creatingTerminal:W,createTerminal:U}=UB(),[F,O]=b.useState(new Set),[M,z]=b.useState(()=>Date.now());b.useEffect(()=>{const K=setInterval(()=>z(Date.now()),6e4);return()=>clearInterval(K)},[]);function L(K,ee){x(`/chat/${K}?mode=${ee??"json"}`,{replace:!1})}function N(K){const ee=K.sessionId,te=Nt;if(!te){et.error("请先连接开发机");return}te.sendControl({type:"session_terminate",sessionId:ee}),It.getState().removeSession(ee),Vt.getState().clearSession(ee),ee===u&&x("/sessions"),(K==null?void 0:K.mode)==="pty"&&K.ptyOwner==="local-terminal"?et.info("已断开页面连接,本地终端仍在运行"):et.info("正在终止会话",{duration:1500})}async function q(K,ee){const te=Nt;if(!te)throw new Error("请先连接开发机");const J=await te.renameSession(K,ee);if(!J.success)throw new Error(J.error??"重命名失败");s(K,J.name??ee),et.success("已重命名会话")}function Y(K){O(ee=>{const te=new Set(ee);return te.has(K)?te.delete(K):te.add(K),te})}function $(K){var J;const ee=K.mode==="json"&&(((J=o[K.sessionId])==null?void 0:J.pendingApprovals.some(me=>me.status==="pending"))??!1),te=ese({session:K,agentStatus:r[K.sessionId],ptyState:i[K.sessionId],hasPendingApproval:ee});return te===K.state?K:{...K,state:te}}const P=t.length>0;if(e==="sidebar"&&(v||!d))return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":v?"session-list-loading":void 0,role:v?"status":void 0,"aria-live":v?"polite":void 0,children:v?w:"请先连接开发机"}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]});if(e==="page"&&v)return g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[g.jsx(Ql,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsx("div",{className:"flex-1",children:g.jsx(ec,{variant:"no-proxy"})}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]});const V=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",P?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),G=P?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:tse(t).map(K=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>Y(K.provider),"aria-expanded":!F.has(K.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:nse(K.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:K.sessions.length}),g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(K.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(K.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:K.sessions.map(ee=>g.jsx(wie,{session:$(ee),selected:ee.sessionId===u,now:M,onClick:()=>L(ee.sessionId,ee.mode),onRename:()=>T(ee),onTerminate:()=>D(ee)},ee.sessionId))})]},K.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),B=g.jsx(Tie,{now:M});return e==="page"?g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[V,G,B]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(mt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[g.jsx(TP,{"aria-hidden":"true"}),"新建"]})}),g.jsx(ise,{open:R,creatingTerminal:W,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>void U(()=>A(!1))}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[V,G,B]}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]})}function tse(e){const t=new Map;for(const n of e){const r=n.kind==="terminal"?"terminal":n.provider,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t.entries()).sort(([n],[r])=>rse(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function nse(e){return e==="terminal"?"终端":Zv(e)}function rse(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:PB(e,t)}function UB(){const e=Xs(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await Yie({relay:Nt});if(s.type!=="success"){et.error(s.message);return}It.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function WN({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Oe(E=>!!E.selectedProxyId),l=Oe(E=>E.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:h}=UB();function p(){i(!0),window.setTimeout(()=>i(!1),2e3)}function y(){if(!u){p();return}s.current=!0,n(!0)}function v(){if(!u){p();return}s.current=!0,h()}function _(E){E.preventDefault(),p()}const w=g.jsxs(mt,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!u&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!u,onClick:u?void 0:_,children:[g.jsx(TP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),x=u?g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:w}),g.jsxs(D1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:E=>{s.current&&(s.current=!1,E.preventDefault())},children:[g.jsxs(go,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[g.jsx(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(go,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[g.jsx(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return g.jsxs(g.Fragment,{children:[u?x:g.jsxs(Wf,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[g.jsx(qf,{asChild:!0,children:x}),g.jsx(Vf,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),g.jsx(Bh,{open:t,onOpenChange:n})]})}function ise({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=b.useRef(!1);function o(l){s.current=!0,l()}return g.jsx(Kv,{open:e,onOpenChange:n,children:g.jsxs(Gv,{side:"bottom",overlayClassName:"bg-black/10 dark:bg-black/30",className:"inset-x-2 w-auto rounded-t-xl border border-border/80 bg-background px-3 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3 shadow-2xl","data-slot":"create-session-type-sheet",focusSurfaceOnOpen:!0,onCloseAutoFocus:l=>{s.current&&(s.current=!1,l.preventDefault())},children:[g.jsx(N1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.jsxs(mt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-agent-session-sheet-item",onClick:()=>o(r),children:[g.jsx(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(mt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-terminal-session-sheet-item",disabled:t,onClick:()=>o(i),children:[g.jsx(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const sse="0.5.17",ose={version:sse},ase={playback:"playback",capture:"play-and-record"};function lse(){return typeof navigator>"u"?null:navigator.audioSession??null}function cse(){return{setMode:()=>{},release:()=>{}}}class use{constructor(t=lse){ht(this,"leases",new Map);ht(this,"session",null);ht(this,"baselineType",null);ht(this,"nextLeaseId",1);ht(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return cse();this.leases.size===0&&(this.session=n,this.baselineType=n.type);const r=this.nextLeaseId++;this.leases.set(r,{mode:t,order:this.nextOrder++});try{this.applyActiveMode()}catch(s){throw this.leases.delete(r),this.leases.size===0?this.restoreWhenUnused():this.applyActiveModeBestEffort(),s}let i=!1;return{setMode:s=>{if(i)return;const o=this.leases.get(r);if(!o)return;const l={...o};o.mode=s,o.order=this.nextOrder++;try{this.applyActiveMode()}catch(u){throw this.leases.set(r,l),this.applyActiveModeBestEffort(),u}},release:()=>{if(!i){if(i=!0,this.leases.delete(r),this.leases.size===0){this.restoreWhenUnused();return}this.applyActiveModeBestEffort()}}}}applyActiveMode(){const t=[...this.leases.values()].reduce((n,r)=>!n||r.order>n.order?r:n,null);!t||!this.session||this.setNativeType(ase[t.mode])}applyActiveModeBestEffort(){try{this.applyActiveMode()}catch{}}restoreWhenUnused(){const t=this.session,n=this.baselineType;if(this.session=null,this.baselineType=null,!(!t||n===null))try{t.type=n}catch{}}setNativeType(t){if(!(!this.session||this.session.type===t)){try{this.session.type=t}catch{throw new Error("浏览器无法切换语音音频模式")}if(this.session.type!==t)throw new Error("浏览器无法切换语音音频模式")}}}const L1=new use,U0=64,qN=-60,WB=32;function VN(e){if(!Number.isFinite(e)||e===0)return 0;const t=Math.min(1,Math.abs(e)),n=20*Math.log10(t),r=Math.max(0,Math.min(1,(n-qN)/-qN));return e<0?-r:r}function YN(e,t=8){const n=Math.floor(e.byteLength/2);if(n===0||!Number.isFinite(t)||t<=0)return[];const r=Math.min(n,Math.max(1,Math.floor(t))),i=new DataView(e.buffer,e.byteOffset,e.byteLength),s=[];for(let o=0;o<r;o+=1){const l=Math.floor(o*n/r),u=Math.max(l+1,Math.floor((o+1)*n/r));let d=1,h=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),h=Math.max(h,y)}s.push({min:d,max:h})}return s}function dse(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=Math.floor(e.byteLength/2),r=new Float32Array(n);for(let i=0;i<n;i+=1)r[i]=t.getInt16(i*2,!0)/32768;return r}function hse(e){if(e.length===0)return 0;const t=Math.max(1,Math.floor(e.length/512));let n=0,r=0;for(let i=0;i<e.length;i+=t){const s=e[i]??0;n+=s*s,r+=1}return r===0?0:Math.min(1,Math.sqrt(n/r)*10)}class qB{constructor(t,n=24e3,r={}){ht(this,"nextStartTime",0);ht(this,"activityEndToken",0);ht(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=dse(t),r=this.context.createBuffer(1,n.length,this.sampleRate);r.getChannelData(0).set(n);const i=this.context.createBufferSource();i.buffer=r,i.connect(this.context.destination);const s=Math.max(this.context.currentTime,this.nextStartTime);i.start(s);const o=s+r.duration;this.nextStartTime=o,this.schedulePlaybackFrames(t,n,s,o);const l=Math.max(0,(o-this.context.currentTime)*1e3);return this.emitPlaybackEvent("pcm-scheduled",{bytes:t.byteLength,durationMs:r.duration*1e3}),typeof i.addEventListener=="function"&&i.addEventListener("ended",()=>{this.emitPlaybackEvent("source-ended",{bytes:t.byteLength,durationMs:r.duration*1e3})},{once:!0}),l}stop(){var t,n;this.nextStartTime=this.context.currentTime,this.activityEndToken+=1;for(const r of this.timelineTimers)clearTimeout(r);this.timelineTimers.clear(),(n=(t=this.options).onActivityLevel)==null||n.call(t,0),this.emitPlaybackEvent("stopped")}snapshot(){const t=this.context.currentTime;return{contextState:String(this.context.state??"unknown"),contextTime:t,nextStartTime:this.nextStartTime,queuedMs:Math.max(0,(this.nextStartTime-t)*1e3)}}schedulePlaybackFrames(t,n,r,i){if(!this.options.onActivityLevel&&!this.options.onPlaybackChunk)return;const s=Math.max(1,Math.round(this.sampleRate*WB/1e3)),o=this.activityEndToken+=1;for(let l=0;l<n.length;l+=s){const u=Math.min(n.length,l+s),d=r+l/this.sampleRate,h=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),y=hse(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,x;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(x=(w=this.options).onPlaybackChunk)==null||x.call(w,p)},h)}if(this.options.onActivityLevel){const l=Math.max(0,(i-this.context.currentTime)*1e3);this.scheduleTimer(()=>{var u,d;o===this.activityEndToken&&((d=(u=this.options).onActivityLevel)==null||d.call(u,0))},l)}}scheduleTimer(t,n){const r=setTimeout(()=>{this.timelineTimers.delete(r),t()},n);this.timelineTimers.add(r)}emitPlaybackEvent(t,n={}){var r,i;(i=(r=this.options).onPlaybackEvent)==null||i.call(r,{event:t,...this.snapshot(),...n})}}const Q_={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},KN="min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none transition-colors placeholder:text-muted-foreground/65 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",fse=800,GN=300,pse=1600;function W0(e,t){return e.filter(n=>!n.model||n.model===t)}function XN({label:e,children:t,help:n}){return g.jsxs("div",{className:"block min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 transition-colors focus-within:border-ring/55 focus-within:bg-card/75 sm:p-3",children:[g.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.jsx("div",{className:"mt-2 min-w-0",children:t}),n?g.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Fm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=b.useState(!1),u=b.useId(),d=n.find(v=>v.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!VB(h).detail;return g.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:v=>{v.currentTarget.contains(v.relatedTarget)||l(!1)},children:[g.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.jsxs("button",{type:"button","aria-labelledby":u,"aria-haspopup":"listbox","aria-expanded":o,disabled:p.length===0,className:`mt-2 flex w-full min-w-0 items-center justify-between gap-3 rounded-md border border-border bg-input px-3 text-left outline-none transition-colors hover:border-primary/40 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(v=>!v),"data-slot":"voice-settings-choice-trigger",children:[g.jsx(ZN,{label:h,muted:!d&&!t}),g.jsx(fl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?g.jsx("div",{role:"listbox","aria-labelledby":u,className:"mt-2 max-h-64 overflow-y-auto rounded-md border border-border/80 bg-popover p-1 shadow-sm",children:n.map(v=>{const _=v.value===t;return g.jsxs("button",{type:"button",role:"option","aria-label":v.label,"aria-selected":_,disabled:v.disabled,className:"flex w-full min-w-0 items-center gap-2 rounded-sm px-2.5 py-2.5 text-left text-sm outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-45",onClick:()=>{v.disabled||(r(v.value),l(!1))},children:[g.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?g.jsx(ta,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(ZN,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function ZN({label:e,muted:t=!1}){const n=VB(e);return g.jsxs("span",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?g.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function mse({scrollRef:e}={}){const[t,n]=b.useState(Q_),[r,i]=b.useState(String(Q_.turnIdleSeconds)),[s,o]=b.useState(()=>Tm()),[l,u]=b.useState(""),[d,h]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),x=b.useRef(null),E=b.useRef(null),k=b.useRef(null),R=b.useRef(null);b.useEffect(()=>{const te=Nt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let J=!1;return _({kind:"loading"}),te.requestVoiceConfig().then(me=>{if(!J){if(me.error||!me.config){_({kind:"error",message:me.error??"读取语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),h(!1),y(!0),_({kind:"idle"})}}).catch(me=>{J||_({kind:"error",message:me instanceof Error?me.message:"读取语音设置失败"})}),()=>{J=!0}},[]),b.useEffect(()=>{const te=Nt;if(!te||!p)return;let J=!1;return te.requestVoiceCapabilities({region:t.region}).then(me=>{if(!J){if(me.error||!me.capabilities){o(Tm());return}o(me.capabilities)}}).catch(()=>{J||o(Tm())}),()=>{J=!0}},[t.region,p]),b.useEffect(()=>()=>{G(),B()},[]);const A=b.useMemo(()=>v.kind==="loading"?"读取中...":v.kind==="saving"?"保存中...":v.kind==="testing"?"正在测试语音合成":v.kind==="playingTest"?"正在播放测试音频":v.kind==="testPassed"?"测试通过":v.kind==="saved"?"已保存":v.kind==="error"?v.message:null,[v]),I=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",T=b.useMemo(()=>W0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),D=T.some(te=>te.value===t.ttsVoice)?t.ttsVoice:"",W=T.length===0?"当前模型暂无可用音色":D?null:"请选择可用音色",U=b.useMemo(()=>bse(r),[r]),F=U?null:"请输入正整数秒数",O=W??F,M=I||!!O,z=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=b.useMemo(()=>eM(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),N=b.useMemo(()=>_se(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),q=b.useMemo(()=>eM(T,D),[T,D]);function Y(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:U??Q_.turnIdleSeconds}}async function $(){if(I)return;if(O){_({kind:"error",message:O});return}const te=Nt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}const J=Y();B(),_({kind:"saving"});const me=performance.now();try{const Se=await te.updateVoiceConfig(J),Re=performance.now()-me;if(Re<GN&&await yse(GN-Re),!Se.success||Se.error||!Se.config){_({kind:"error",message:Se.error??"保存语音设置失败"});return}n(Se.config),i(String(Se.config.turnIdleSeconds)),u(""),h(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(Ae=>Ae.kind==="saved"?{kind:"idle"}:Ae)},pse),te.requestVoiceCapabilities({region:Se.config.region}).then(Ae=>{Ae.capabilities&&o(Ae.capabilities)}).catch(()=>{o(Tm())})}catch(Se){_({kind:"error",message:Se instanceof Error?Se.message:"保存语音设置失败"})}}async function P(){if(I)return;if(O){_({kind:"error",message:O});return}const te=Nt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let J;try{J=V()}catch(me){_({kind:"error",message:JN(me)});return}_({kind:"testing"});try{const[me]=await Promise.all([te.testVoiceConfig(Y()),J.ready]);if(!me.success||me.error){G(),_({kind:"error",message:me.error??"语音配置测试失败"});return}const Se=await K(me,J.context);_({kind:"playingTest",transcript:me.transcript}),k.current=setTimeout(()=>{k.current=null,G(),_({kind:"testPassed",transcript:me.transcript})},Se)}catch(me){G(),_({kind:"error",message:JN(me)})}}function V(){G();const te=L1.acquire("playback");x.current=te;try{const J=vse();return w.current=J,{context:J,ready:QN(J)}}catch(J){throw te.release(),x.current=null,J}}function G(){var te,J,me;k.current&&(clearTimeout(k.current),k.current=null),(te=E.current)==null||te.stop(),E.current=null,(J=w.current)==null||J.close(),w.current=null,(me=x.current)==null||me.release(),x.current=null}function B(){R.current&&(clearTimeout(R.current),R.current=null)}async function K(te,J){if(!te.audioBase64)throw new Error("语音测试未返回可播放音频");if(te.audioEncoding&&te.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const me=te.audioSampleRate??24e3,Se=gse(te.audioBase64);if(Se.byteLength===0||Se.byteLength%2!==0)throw new Error("测试音频数据无效");await QN(J);const Re=new qB(J,me);E.current=Re,Re.enqueue(Se);const Ae=Math.ceil(Se.byteLength/2/me*1e3);return Math.max(fse,Ae)}function ee(te){var J;return((J=W0(s.ttsVoices,te)[0])==null?void 0:J.value)??""}return g.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:te=>{te.preventDefault(),$()},children:[g.jsx("div",{className:"flex min-h-0 flex-1 flex-col px-4 py-3 sm:px-5 sm:py-3.5","data-slot":"voice-settings-body-frame",children:g.jsx("div",{className:"dev-render-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"voice-settings-scroll",ref:e,children:g.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[g.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),g.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),g.jsx("span",{className:"shrink-0 rounded-full border border-primary/35 bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:"Bailian"})]})}),g.jsx(XN,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:g.jsxs("div",{className:"flex min-w-0 gap-2",children:[g.jsxs("div",{className:"relative min-w-0 flex-1",children:[g.jsx(NP,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),g.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:te=>{u(te.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${KN} w-full pl-9`})]}),t.configured&&g.jsxs(mt,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),h(!0)},children:[g.jsx(f7,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(Fm,{label:"地域",value:t.region,options:z,onChange:te=>n(J=>({...J,region:te==="intl"?"intl":"cn"}))}),g.jsx(Fm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:te=>n(J=>({...J,asrModel:te}))}),g.jsx(Fm,{label:"语音合成模型",value:t.ttsModel,options:N,onChange:te=>n(J=>({...J,ttsModel:te,ttsVoice:ee(te)}))}),g.jsx(Fm,{label:"语音音色",value:D,options:q,placeholder:T.length===0?"暂无可用音色":"请选择音色",onChange:te=>n(J=>({...J,ttsVoice:te})),help:W}),g.jsx(XN,{label:"结束停顿时间(秒)",help:F,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:te=>i(te.target.value),className:`${KN} w-full`})})]})})}),g.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[g.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),g.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[A?g.jsx("div",{role:v.kind==="error"?"alert":"status","aria-live":"polite",className:v.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:A}):null,g.jsxs(mt,{type:"button",variant:"outline",disabled:M,onClick:()=>void P(),children:[g.jsx(DP,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(mt,{type:"submit",disabled:M,children:[g.jsx(e7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function gse(e){const t=window.atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n}function vse(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function QN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function JN(e){return e instanceof Error?e.message:"语音配置测试失败"}function yse(e){return new Promise(t=>setTimeout(t,e))}function bse(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function eM(e,t){const n=e.map(r=>({value:r.value,label:YB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function _se(e,t,n){const r=e.map(i=>{const s=W0(t,i.value).length===0;return{value:i.value,label:`${YB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function VB(e){const t=e.split(" · ").map(n=>n.trim()).filter(Boolean);return t.length<=1?{title:e,detail:null}:{title:t[0],detail:t.slice(1).join(" · ")}}function YB(e){if(!e.age)return e.label;const t=`年龄 ${e.age}`;if(e.label.includes(t))return e.label;const n=` · ${e.age}`;return e.label.endsWith(n)?`${e.label.slice(0,-n.length)} · ${t}`:`${e.label} · ${t}`}const wse=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Sse=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],I1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function KB(e){if(!Number.isFinite(e)||e<0)return"未知";if(e<60)return`${Math.floor(e)} 秒`;const t=Math.floor(e/60);if(t<60)return`${t} 分钟`;const n=Math.floor(t/60),r=t%60;if(n<24)return r>0?`${n} 小时 ${r} 分钟`:`${n} 小时`;const i=Math.floor(n/24),s=n%24;return s>0?`${i} 天 ${s} 小时`:`${i} 天`}function xse(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Ese(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Cse(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function q0({open:e,onOpenChange:t}){const n=Oe(W=>W.relayUrl),r=Oe(W=>W.latencyMonitorEnabled),i=Oe(W=>W.setLatencyMonitorEnabled),s=Oe(W=>W.sessionIdleNotificationsEnabled),o=Oe(W=>W.setSessionIdleNotificationsEnabled),l=Oe(W=>W.inputModePreference),u=Oe(W=>W.setInputModePreference),d=Oe(W=>W.themePreference),h=Oe(W=>W.setThemePreference),p=Oe(W=>W.ptyScrollTraceEnabled),y=Oe(W=>W.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,x]=b.useState({kind:"idle"}),E=b.useRef(null),k=b.useRef(null),R=bQ(),A=b.useMemo(()=>Cv().osName==="iPad",[]),I=b.useCallback(async W=>{if(!W){o(!1);return}const U=await KZ();if(U==="granted"){o(!0);return}if(U==="denied"){et.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){et.info("未授予通知权限,会话通知保持关闭");return}et.error("当前浏览器不支持系统通知")},[o]),T=b.useCallback(async W=>{x({kind:"loading"});try{const U=await fetch(xse(n),{cache:"no-store",signal:W});if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=await U.json();if(F.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:F.version??"未知",uptime:F.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;x({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const W=new AbortController;return T(W.signal),()=>W.abort()},[T,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const W=window.requestAnimationFrame(()=>{var U;(U=E.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(W)},[e,v]);const H=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",D=w.kind==="ready"?`运行 ${KB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(_c,{open:e,onOpenChange:t,children:g.jsxs(wc,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",v==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",v==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":v,focusSurfaceOnOpen:!0,ref:E,showCloseButton:v==="menu",children:[g.jsx(Sc,{className:Ye(v==="menu"&&"pr-12 text-left",v!=="menu"&&"text-left",v==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:v!=="menu"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-start gap-2",children:[g.jsx(mt,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>_("menu"),children:g.jsx(bv,{className:"size-4","aria-hidden":"true"})}),g.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[g.jsx(ll,{children:Ese(v)}),g.jsx(cc,{className:"max-w-[28rem] leading-5",children:Cse(v)})]})]}),v==="voice"?g.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):g.jsxs(g.Fragment,{children:[g.jsx(ll,{children:"设置"}),g.jsx(cc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(kse,{relayVersion:H,relayDetail:D,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(Rse,{saved:R}):v==="clients"?g.jsx(Dse,{}):v==="voice"?g.jsx(mse,{scrollRef:k}):g.jsx(Tse,{relayTokenSaved:R,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:I,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function kse({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:I1,"data-slot":"settings-dialog-body",children:[g.jsx(nM,{icon:g.jsx(OP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:ose.version,detail:"当前浏览器加载的版本"}),g.jsx(nM,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Tse({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:h,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:v,onOpenClients:_,onOpenVersion:w}){return g.jsxs("div",{className:"dev-render-scroll min-h-0 space-y-4 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"settings-dialog-body",children:[g.jsxs(cu,{title:"服务",children:[g.jsx($m,{icon:g.jsx(U9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx($m,{icon:g.jsx(NP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx($m,{icon:g.jsx(_7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),g.jsx(cu,{title:"外观",children:g.jsx(tM,{icon:g.jsx(u7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:wse,onValueChange:n})}),g.jsx(cu,{title:"通知",children:g.jsx(ew,{icon:g.jsx(q9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(cu,{title:"交互",children:g.jsx(tM,{icon:g.jsx(MP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Sse,onValueChange:i})}):null,g.jsxs(cu,{title:"高级诊断",children:[g.jsx(ew,{icon:g.jsx(lf,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(ew,{icon:g.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(cu,{title:"关于",children:g.jsx($m,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({title:e,children:t}){return g.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[g.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),g.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function tM({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return g.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,g.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return g.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Rse({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{JL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}if(!ZL(h)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),et.error(p);return}o(null),et.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{QL(),l()};return g.jsxs("form",{className:I1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[g.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[g.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),g.jsx("input",{id:t,type:"password",value:r,onChange:h=>{i(h.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?g.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),g.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?g.jsx(mt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(mt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Ase(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Nse(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Ase(e)}function Mse(e){return CX(e)}function Ose(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return KB(t)}function J_({label:e,value:t,title:n}){return g.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[g.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),g.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function Dse(){const e=Oe(y=>y.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),h=b.useCallback(async()=>{const y=Nt;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(v){o(v instanceof Error?v.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{h()},[h]);const p=b.useCallback(async y=>{const v=Nt;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:I1,"data-slot":"settings-dialog-body",children:[g.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Nx,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?g.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?g.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const v=y.current===!0,_=l===y.clientId;return g.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children:g.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[g.jsxs("div",{className:"min-w-0 space-y-1.5",children:[g.jsx("div",{className:"min-w-0",children:g.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Mse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(J_,{label:"已连接",value:Ose(y.connectedAt)}),y.proxyId?g.jsx(J_,{label:"连接到",value:Nse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(J_,{label:"来源 IP",value:y.remoteAddress}):null]})]}),v?g.jsx("div",{className:"inline-flex h-9 w-full items-center justify-center rounded-md border border-primary/30 bg-primary/10 px-3 text-sm font-normal text-primary","aria-label":"当前设备","data-slot":"relay-client-current-indicator",children:"当前设备"}):g.jsxs(mt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[g.jsx(N8,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function ew({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return g.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[g.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),g.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),g.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:g.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function $m({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return g.jsxs("button",{type:"button",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:r,"aria-labelledby":i,"aria-describedby":n?s:void 0,"data-slot":"settings-menu-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground transition-colors group-hover:text-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),g.jsx(Xh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function nM({icon:e,label:t,value:n,detail:r,muted:i=!1}){return g.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[g.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[g.jsx("div",{className:"text-sm text-muted-foreground",children:t}),g.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const Pse="xterm-helper-textarea";function Lse(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Pse)?!1:(e.blur(),!0)}function rM(e,t,n){if(!e||Math.abs(n)<1)return!1;let r=e instanceof Element?e:null;for(;r&&t.contains(r);){if(r instanceof HTMLElement&&Ise(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Ise(e,t){if(e.scrollHeight<=e.clientHeight+1)return!1;const n=window.getComputedStyle(e).overflowY;return n!=="auto"&&n!=="scroll"&&n!=="overlay"?!1:t<0?e.scrollTop>0:e.scrollTop+e.clientHeight<e.scrollHeight-1}function zse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Lse()},[e]),i=b.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=b.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const h=(n.current??u.clientY)-u.clientY;n.current=u.clientY,rM(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(rM(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Bse({className:e}){const t=Oe(o=>o.sidebarCollapsed),n=Oe(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=zse();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[g.jsx(sM,{collapsed:!0,onClick:n}),g.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),g.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[g.jsx(iM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(WN,{compact:!0})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[g.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:g.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx(JP,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(sM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx(DB,{layout:"dropdown",variant:"sidebarChrome"})})]})}),g.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:g.jsx("div",{className:"flex-1 min-h-0",children:g.jsx(HB,{layout:"sidebar"})})}),g.jsxs("div",{className:"dev-sidebar-fade flex shrink-0 gap-2 px-2 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-2","data-slot":"sidebar-new-session",children:[g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(WN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(iM,{onClick:()=>i(!0)})})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]})}function iM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[g.jsx(LP,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(Vf,{side:t,sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:"设置"})]})}function sM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?F8:B8;return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:g.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(Vf,{side:e?"right":"top",sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:n})]})}const jse=1500,Fse=300,oM=70,aM=35;function GB({texts:e,className:t}){const[n,r]=b.useState(""),[i,s]=b.useState(!0),o=b.useRef("typing"),l=b.useRef(0),u=b.useRef(0);b.useEffect(()=>{const h=setInterval(()=>s(p=>!p),530);return()=>clearInterval(h)},[]),b.useEffect(()=>{let h;const p=()=>e[u.current%e.length],y=()=>{const v=o.current;if(v==="typing"){const _=p();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),h=setTimeout(y,oM)):(o.current="paused",h=setTimeout(y,jse))}else v==="paused"?(o.current="deleting",h=setTimeout(y,aM)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),h=setTimeout(y,aM)):(u.current+=1,o.current="waiting",h=setTimeout(y,Fse)):(o.current="typing",h=setTimeout(y,oM))};return h=setTimeout(y,500),()=>clearTimeout(h)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return g.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[g.jsx("span",{className:"text-green-500",children:"> "}),g.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),g.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),g.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const XB=["DEV Anywhere","/unlimited @anytime"];function $se({subtitle:e,action:t}){return g.jsx("section",{className:"dev-mobile-brand-hero border-b border-border/80 px-4 pb-5 pt-[calc(env(safe-area-inset-top)+1.25rem)] md:hidden","data-slot":"mobile-brand-hero","aria-label":"DEV Anywhere",children:g.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[g.jsx(GB,{texts:XB,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),g.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?g.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Hse=3e3,Use=1e4,Hm=12,Wse=4,lM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},qse={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function tw(e){if(!e.success||e.rttMs===void 0)return{state:"unavailable",error:e.error??"不可用",updatedAt:Date.now()};const t=e.rttMs;return{state:t<=120?"ok":t<=300?"warn":"bad",rttMs:t,updatedAt:Date.now()}}function uu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Fh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function cM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function ZB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Vse(e){switch(e){case"ok":return"border-emerald-500/35 bg-emerald-500/10 text-emerald-300";case"warn":return"border-amber-500/40 bg-amber-500/10 text-amber-300";case"bad":return"border-destructive/55 bg-destructive/10 text-destructive";default:return"border-border bg-card/90 text-muted-foreground"}}function Yse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Fh(e.rttMs):"等待检测"}function Kse(){const e=xi("local",on.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function uM(e){fr("local",on.latencyMonitorPosition,JSON.stringify(e))}function Gse(){var e,t;return{width:((e=window.visualViewport)==null?void 0:e.width)??window.innerWidth??document.documentElement.clientWidth??0,height:((t=window.visualViewport)==null?void 0:t.height)??window.innerHeight??document.documentElement.clientHeight??0}}function nw(e,t){const n=Gse(),r=Hm,i=Hm,s=Math.max(r,n.width-t.width-Hm),o=Math.max(i,n.height-t.height-Hm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Xse(){const e=Oe(T=>T.latencyMonitorEnabled),t=Oe(T=>T.connected),n=Oe(T=>T.proxyOnline),r=Oe(T=>T.selectedProxyId),[i,s]=b.useState(qse),[o,l]=b.useState(()=>Kse()),u=b.useRef(!1),d=b.useRef(null),h=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,H)=>cM(H.state)-cM(T.state))[0]??{state:"idle"}).state,[i]),v=ZB(y);async function _(){if(u.current)return;const T=Nt;if(!T||!t){const U=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,D,W]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:H.status==="fulfilled"?tw(H.value):uu(H.reason instanceof Error?H.reason.message:"测速失败"),relayProxy:D.status==="fulfilled"?tw(D.value):uu(D.reason instanceof Error?D.reason.message:"测速失败"),webProxy:W.status==="fulfilled"?tw(W.value):uu(W.reason instanceof Error?W.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,H=null;const D=async()=>{await _(),!T&&(H=setTimeout(D,document.hidden?Use:Hse))};return D(),()=>{T=!0,u.current=!1,H&&clearTimeout(H)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const H=T.getBoundingClientRect(),D=nw(o,{width:H.width,height:H.height});D.x===o.x&&D.y===o.y||(l(D),uM(D))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,x=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function E(T){var D,W;if(T.button!==0)return;const H=T.currentTarget.getBoundingClientRect();h.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:H.left,originY:H.top,width:H.width,height:H.height,dragging:!1},(W=(D=T.currentTarget).setPointerCapture)==null||W.call(D,T.pointerId)}function k(T){const H=h.current;if(!H||H.pointerId!==T.pointerId)return;const D=T.clientX-H.startX,W=T.clientY-H.startY;if(!H.dragging&&Math.hypot(D,W)<Wse)return;H.dragging=!0,T.preventDefault();const U=nw({x:H.originX+D,y:H.originY+W},{width:H.width,height:H.height});l(U)}function R(T){var F,O;const H=h.current;if(!H||H.pointerId!==T.pointerId||(h.current=null,(O=(F=T.currentTarget).releasePointerCapture)==null||O.call(F,T.pointerId),!H.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const D=T.clientX-H.startX,W=T.clientY-H.startY,U=nw({x:H.originX+D,y:H.originY+W},{width:H.width,height:H.height});l(U),uM(U)}function A(T){var D,W;const H=h.current;!H||H.pointerId!==T.pointerId||(h.current=null,(W=(D=T.currentTarget).releasePointerCapture)==null||W.call(D,T.pointerId))}function I(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return g.jsxs(T1,{children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Vse(v)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Fh(i.webRelay.rttMs)},开发机 ${Fh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:I,children:[g.jsx(EP,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),g.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",Fh(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Fh(w.rttMs)]}),g.jsx(fl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(A1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:g.jsx(Nx,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(lM).map(T=>g.jsx(Zse,{label:lM[T],measurement:i[T]},T))})]})]})}function Zse({label:e,measurement:t}){const n=ZB(t.state);return g.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[g.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),g.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Yse(t)})]})]})}const QB="/__dev_anywhere_debug/browser-state-dumps",Qse=1500,Jse=10,rw=80,z1=500,eoe=["id","class","data-slot","data-state","data-testid","role","aria-label","aria-hidden","name","type","autocomplete","autocorrect","autocapitalize","inputmode","enterkeyhint","virtualkeyboardpolicy","contenteditable","placeholder","href","src"],toe=["display","position","visibility","opacity","pointer-events","z-index","overflow","overflow-x","overflow-y","touch-action","transform","translate","color-scheme","background-color","color","font-size","line-height","padding-top","padding-right","padding-bottom","padding-left","margin-top","margin-right","margin-bottom","margin-left"];function dM(){if(typeof window>"u")return"off";const e=o3("debugDump");return e==="auto"?"auto":e!==null||uoe("debugInput")?"manual":"off"}function noe(e="manual"){const t={count:0,truncated:!1},n=window,r={schemaVersion:1,createdAt:new Date().toISOString(),trigger:e,url:{href:window.location.href,origin:window.location.origin,pathname:window.location.pathname,search:window.location.search,hash:window.location.hash},browser:{userAgent:navigator.userAgent,language:navigator.language,languages:Array.from(navigator.languages??[]),platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints??0,cookieEnabled:navigator.cookieEnabled,onLine:navigator.onLine},viewport:ooe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:hM(document.activeElement),selection:aoe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>hM(i)).filter(i=>!!i),root:JB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug: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(()=>fM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>fM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function roe(e="manual"){const t=noe(e);return ioe(t)}async function ioe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await soe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:QB}}catch(r){const i=a3(r),s=loe(e.createdAt);return coe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function soe(e){const t=await fetch(QB,{method:"POST",headers:{"content-type":"application/json"},body:e});if(!t.ok)throw new Error(`${t.status} ${await t.text()}`);const n=await t.json();if(!n.ok||!n.path||typeof n.bytes!="number")throw new Error("debug endpoint returned an invalid response");return{path:n.path,bytes:n.bytes}}function JB(e,t,n){if(n.count>=Qse||t>Jse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=pM(e.textContent??"");return u?{kind:"text",text:Qv(u,z1)}:{kind:"text",text:""}}if(!(e instanceof HTMLElement))return{kind:"truncated"};const r=[];let i=0;const s=Array.from(e.childNodes);for(const u of s.slice(0,rw))u.nodeType===Node.TEXT_NODE&&!pM(u.textContent??"")||r.push(JB(u,t+1,n));s.length>rw&&(i=s.length-rw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:s3(e),attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e)},l=i3(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function hM(e){if(!(e instanceof HTMLElement))return null;const t=i3(e);return{path:s3(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e),...t?{value:t}:{}}}function ooe(){var n;const e=window.visualViewport,t=((n=screen.orientation)==null?void 0:n.type)??null;return{window:{innerWidth:window.innerWidth,innerHeight:window.innerHeight,outerWidth:window.outerWidth,outerHeight:window.outerHeight,devicePixelRatio:window.devicePixelRatio,scrollX:window.scrollX,scrollY:window.scrollY},visualViewport:e?{width:e.width,height:e.height,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,pageLeft:e.pageLeft,pageTop:e.pageTop,scale:e.scale}:null,screen:{width:screen.width,height:screen.height,availWidth:screen.availWidth,availHeight:screen.availHeight,orientation:t}}}function e3(e){const t={};for(const n of eoe){const r=e.getAttribute(n);r!==null&&(t[n]=Qv(r,500))}return t}function t3(e){const t=e.getBoundingClientRect();return{x:Vi(t.x),y:Vi(t.y),width:Vi(t.width),height:Vi(t.height),top:Vi(t.top),right:Vi(t.right),bottom:Vi(t.bottom),left:Vi(t.left)}}function n3(e){return{top:Vi(e.scrollTop),left:Vi(e.scrollLeft),height:Vi(e.scrollHeight),width:Vi(e.scrollWidth),clientHeight:Vi(e.clientHeight),clientWidth:Vi(e.clientWidth)}}function r3(e){const t=window.getComputedStyle(e),n={};for(const r of toe)n[r]=t.getPropertyValue(r);return n}function i3(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Qv(e.value,z1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function aoe(){var e;try{return Qv(((e=window.getSelection())==null?void 0:e.toString())??"",z1)}catch{return null}}function s3(e){const t=[];let n=e;for(;n&&n!==document.documentElement;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}const i=n.getAttribute("data-slot");i?r+=`[data-slot="${i}"]`:n.classList.length>0&&(r+=`.${Array.from(n.classList).slice(0,3).join(".")}`);const s=n.parentElement;if(s){const o=n.tagName,l=Array.from(s.children).filter(u=>u instanceof HTMLElement&&u.tagName===o);l.length>1&&(r+=`:nth-of-type(${l.indexOf(n)+1})`)}t.unshift(r),n=s}return`html>${t.join(">")}`}function loe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function coe(e,t,n){if(typeof document>"u")return!1;const r=new Blob([t],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");return s.href=i,s.download=e,s.rel="noopener",document.body.append(s),s.click(),s.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3),!0}function uoe(e){return o3(e)!==null}function o3(e){const t=new URLSearchParams(window.location.search);if(t.has(e))return t.get(e)??"";const[,n=""]=window.location.hash.split("?"),r=new URLSearchParams(n);return r.has(e)?r.get(e)??"":null}function fM(e){return e?Zg(e.slice(-200)):null}function du(e){try{return Zg(e())}catch(t){return{error:a3(t)}}}function Zg(e){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(Array.isArray(e))return e.map(Zg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Zg(r);return t}return String(e)}function pM(e){return e.replace(/\s+/g," ").trim()}function Qv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Vi(e){return Math.round(e*100)/100}function a3(e){return e instanceof Error?e.message:String(e)}const doe=500,hoe=1e3,foe=60;function poe(){const[e,t]=b.useState(()=>dM()),[n,r]=b.useState(!1),[i,s]=b.useState(null),o=b.useRef(null),l=b.useRef(!1),u=b.useRef(0),d=b.useRef(0),h=b.useRef(null);b.useEffect(()=>{const _=()=>t(dM());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const p=b.useCallback(async(_="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await roe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&moe(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),b.useEffect(()=>{var k,R;if(e!=="auto")return;const _=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=A=>{d.current>=foe||(_(),h.current=window.setTimeout(()=>{h.current=null;const I=Date.now(),T=hoe-(I-u.current);if(T>0){h.current=window.setTimeout(()=>w(A),T);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${A}`)},doe))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=A=>w(A.type);return x.forEach(A=>window.addEventListener(A,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(R=window.visualViewport)==null||R.addEventListener("scroll",E),()=>{var A,I;_(),x.forEach(T=>window.removeEventListener(T,E,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",E),(I=window.visualViewport)==null||I.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=goe(i);return g.jsxs("div",{className:"fixed bottom-3 right-3 z-[90] flex max-w-[min(360px,calc(100vw-24px))] flex-col items-end gap-1",children:[v?g.jsx("div",{className:"max-w-full truncate rounded-md border border-border/70 bg-popover/95 px-2 py-1 text-[10px] text-muted-foreground shadow",children:v}):null,g.jsxs(mt,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void p("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?g.jsx(Ql,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(y8,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function moe(e){if(e.status==="saved"){et.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){et.info(`诊断已下载: ${e.filename}`);return}et.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function goe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function voe(e){if(typeof window>"u")return null;try{const t=window.localStorage;return!t||typeof t.getItem!="function"?null:t.getItem(e)}catch{return null}}function B1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:voe(n)==="1",l=()=>typeof window>"u"?[]:window[t]??[],u=d=>{typeof window>"u"||(window[t]=d)};return{isEnabled:o,append(d){if(typeof window>"u")return;const h=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&h.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const v=h.indexOf(y);v>=0&&v!==h.length-1&&(h.splice(v,1),h.push(y)),u(h);return}}}if(h.push(d),i&&s.set(d.event,d),h.length>r){const p=h.splice(0,h.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(h)},getAll:l}}function En(e){return Math.round(e*10)/10}function qa(e){return e.length===0?"":`${En(Math.min(...e))}..${En(Math.max(...e))}`}function Au(e){return[...new Set(e.filter(t=>t!==void 0).map(En))]}function l3(e){let t=0,n=0;for(let r=1;r<e.length;r+=1){const i=e[r]-e[r-1];if(Math.abs(i)<1)continue;const s=Math.sign(i);t!==0&&s!==t&&(n+=1),t=s}return n}const yoe="dev_anywhere_pty_input_latency_trace",mM=80,boe=1e4,_oe=new TextDecoder;let woe=0;const Ku=new Map,xc=B1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:yoe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Soe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=koe)}function xoe(e,t){if(!xc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++woe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Aoe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),F1(s,r),Ku.set(e,s),Yf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function gM(e,t){if(!e||!xc.isEnabled())return;const n=performance.now(),r=Toe(e.sessionId,e.inputId);r&&(r.sentAt=n),Yf({t:n,event:"input:ws-send",sessionId:e.sessionId,inputId:e.inputId,inputKind:r==null?void 0:r.kind,dataLength:r==null?void 0:r.dataLength,sent:t.sent,queueWhenDisconnected:t.queueWhenDisconnected,deltaFromInputMs:r?n-r.startedAt:null,details:t.details})}function Eoe(e,t,n){if(!xc.isEnabled())return;const r=performance.now(),i=j1(e,r),s=Ooe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Moe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Yf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:Doe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Coe(e,t,n=1){if(!xc.isEnabled())return;const r=performance.now(),i=j1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Yf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Roe(e,s))}function koe(){const e=xc.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?"":En(s.sentAt-s.startedAt),s.firstOutputAt===null?"":En(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":En(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":En(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":En(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[En(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?"":En(s.deltaFromInputMs),s.details??""].join(" "));return["DEV Anywhere PTY input latency trace",`events=${e.length}, included=${t.length}, pendingInputs=${n.length}`,"pending input summary:","inputId sessionId kind len wsSendMs firstOutputMs echoMatchMs xtermWriteMs paintMs",...r,"events:","t event sessionId inputId kind len sent queue outputSeq bytes chunks pending deltaMs details",...i].join(`
510
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},QJ="DialogDescriptionWarning",JJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${MI(QJ).contentName}}.`;return b.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},r1=vI,eee=bI,i1=wI,s1=SI,o1=xI,OI=CI,DI=TI,a1=AI;function tee(e){const t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function nee(e){const[t,n]=b.useState(void 0);return Ei(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const u=s.borderBoxSize,d=Array.isArray(u)?u[0]:u;o=d.inlineSize,l=d.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const ree=["top","right","bottom","left"],ol=Math.min,ls=Math.max,Ug=Math.round,zm=Math.floor,_o=e=>({x:e,y:e}),iee={left:"right",right:"left",bottom:"top",top:"bottom"};function T0(e,t,n){return ls(e,ol(t,n))}function ra(e,t){return typeof e=="function"?e(t):e}function ia(e){return e.split("-")[0]}function od(e){return e.split("-")[1]}function l1(e){return e==="x"?"y":"x"}function c1(e){return e==="y"?"height":"width"}function yo(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function u1(e){return l1(yo(e))}function see(e,t,n){n===void 0&&(n=!1);const r=od(e),i=u1(e),s=c1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Wg(o)),[o,Wg(o)]}function oee(e){const t=Wg(e);return[R0(e),t,R0(t)]}function R0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const wN=["left","right"],SN=["right","left"],aee=["top","bottom"],lee=["bottom","top"];function cee(e,t,n){switch(e){case"top":case"bottom":return n?t?SN:wN:t?wN:SN;case"left":case"right":return t?aee:lee;default:return[]}}function uee(e,t,n,r){const i=od(e);let s=cee(ia(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(R0)))),s}function Wg(e){const t=ia(e);return iee[t]+e.slice(t.length)}function dee(e){return{top:0,right:0,bottom:0,left:0,...e}}function PI(e){return typeof e!="number"?dee(e):{top:e,right:e,bottom:e,left:e}}function qg(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function xN(e,t,n){let{reference:r,floating:i}=e;const s=yo(t),o=u1(t),l=c1(o),u=ia(t),d=s==="y",h=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let v;switch(u){case"top":v={x:h,y:r.y-i.height};break;case"bottom":v={x:h,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:p};break;case"left":v={x:r.x-i.width,y:p};break;default:v={x:r.x,y:r.y}}switch(od(t)){case"start":v[o]-=y*(n&&d?-1:1);break;case"end":v[o]+=y*(n&&d?-1:1);break}return v}async function hee(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:p="floating",altBoundary:y=!1,padding:v=0}=ra(t,e),_=PI(v),x=l[y?p==="floating"?"reference":"floating":p],E=qg(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),A=await(s.isElement==null?void 0:s.isElement(R))?await(s.getScale==null?void 0:s.getScale(R))||{x:1,y:1}:{x:1,y:1},I=qg(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(E.top-I.top+_.top)/A.y,bottom:(I.bottom-E.bottom+_.bottom)/A.y,left:(E.left-I.left+_.left)/A.x,right:(I.right-E.right+_.right)/A.x}}const fee=50,pee=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:hee},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=xN(d,r,u),y=r,v=0;const _={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:R,y:A,data:I,reset:T}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});h=R??h,p=A??p,_[E]={..._[E],...I},T&&v<fee&&(v++,typeof T=="object"&&(T.placement&&(y=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:p}=xN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:_}},mee=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=ra(e,t)||{};if(d==null)return{};const p=PI(h),y={x:n,y:r},v=u1(i),_=c1(v),w=await o.getDimensions(d),x=v==="y",E=x?"top":"left",k=x?"bottom":"right",R=x?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[v]-y[v]-s.floating[_],I=y[v]-s.reference[v],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let H=T?T[R]:0;(!H||!await(o.isElement==null?void 0:o.isElement(T)))&&(H=l.floating[R]||s.floating[_]);const D=A/2-I/2,W=H/2-w[_]/2-1,U=ol(p[E],W),F=ol(p[k],W),O=U,M=H-w[_]-F,z=H/2-w[_]/2+D,L=T0(O,z,M),N=!u.arrow&&od(i)!=null&&z!==L&&s.reference[_]/2-(z<O?U:F)-w[_]/2<0,q=N?z<O?z-O:z-M:0;return{[v]:y[v]+q,data:{[v]:L,centerOffset:z-L-q,...N&&{alignmentOffset:q}},reset:N}}}),gee=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...x}=ra(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=ia(i),k=yo(l),R=ia(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),I=y||(R||!w?[Wg(l)]:oee(l)),T=_!=="none";!y&&T&&I.push(...uee(l,w,_,A));const H=[l,...I],D=await u.detectOverflow(t,x),W=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&W.push(D[E]),p){const z=see(i,o,A);W.push(D[z[0]],D[z[1]])}if(U=[...U,{placement:i,overflows:W}],!W.every(z=>z<=0)){var F,O;const z=(((F=s.flip)==null?void 0:F.index)||0)+1,L=H[z];if(L&&(!(p==="alignment"?k!==yo(L):!1)||U.every(Y=>yo(Y.placement)===k?Y.overflows[0]>0:!0)))return{data:{index:z,overflows:U},reset:{placement:L}};let N=(O=U.filter(q=>q.overflows[0]<=0).sort((q,Y)=>q.overflows[1]-Y.overflows[1])[0])==null?void 0:O.placement;if(!N)switch(v){case"bestFit":{var M;const q=(M=U.filter(Y=>{if(T){const $=yo(Y.placement);return $===k||$==="y"}return!0}).map(Y=>[Y.placement,Y.overflows.filter($=>$>0).reduce(($,P)=>$+P,0)]).sort((Y,$)=>Y[1]-$[1])[0])==null?void 0:M[0];q&&(N=q);break}case"initialPlacement":N=l;break}if(i!==N)return{reset:{placement:N}}}return{}}}};function EN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function CN(e){return ree.some(t=>e[t]>=0)}const vee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ra(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=EN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:CN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=EN(o,n.floating);return{data:{escapedOffsets:l,escaped:CN(l)}}}default:return{}}}}},LI=new Set(["left","top"]);async function yee(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=ia(n),l=od(n),u=yo(n)==="y",d=LI.has(o)?-1:1,h=s&&u?-1:1,p=ra(t,e);let{mainAxis:y,crossAxis:v,alignmentAxis:_}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof _=="number"&&(v=l==="end"?_*-1:_),u?{x:v*h,y:y*d}:{x:y*d,y:v*h}}const bee=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:s,placement:o,middlewareData:l}=t,u=await yee(t,e);return o===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:s+u.y,data:{...u,placement:o}}}}},_ee=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:E=>{let{x:k,y:R}=E;return{x:k,y:R}}},...d}=ra(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=yo(ia(i)),v=l1(y);let _=h[v],w=h[y];if(o){const E=v==="y"?"top":"left",k=v==="y"?"bottom":"right",R=_+p[E],A=_-p[k];_=T0(R,_,A)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+p[E],A=w-p[k];w=T0(R,w,A)}const x=u.fn({...t,[v]:_,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[v]:o,[y]:l}}}}}},wee=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:u=!0,crossAxis:d=!0}=ra(e,t),h={x:n,y:r},p=yo(i),y=l1(p);let v=h[y],_=h[p];const w=ra(l,t),x=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const R=y==="y"?"height":"width",A=s.reference[y]-s.floating[R]+x.mainAxis,I=s.reference[y]+s.reference[R]-x.mainAxis;v<A?v=A:v>I&&(v=I)}if(d){var E,k;const R=y==="y"?"width":"height",A=LI.has(ia(i)),I=s.reference[p]-s.floating[R]+(A&&((E=o.offset)==null?void 0:E[p])||0)+(A?0:x.crossAxis),T=s.reference[p]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[p])||0)-(A?x.crossAxis:0);_<I?_=I:_>T&&(_=T)}return{[y]:v,[p]:_}}}},See=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:u=()=>{},...d}=ra(e,t),h=await o.detectOverflow(t,d),p=ia(i),y=od(i),v=yo(i)==="y",{width:_,height:w}=s.floating;let x,E;p==="top"||p==="bottom"?(x=p,E=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(E=p,x=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,R=_-h.left-h.right,A=ol(w-h[x],k),I=ol(_-h[E],R),T=!t.middlewareData.shift;let H=A,D=I;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(D=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(H=k),T&&!y){const U=ls(h.left,0),F=ls(h.right,0),O=ls(h.top,0),M=ls(h.bottom,0);v?D=_-2*(U!==0||F!==0?U+F:ls(h.left,h.right)):H=w-2*(O!==0||M!==0?O+M:ls(h.top,h.bottom))}await u({...t,availableWidth:D,availableHeight:H});const W=await o.getDimensions(l.floating);return _!==W.width||w!==W.height?{reset:{rects:!0}}:{}}}};function Ov(){return typeof window<"u"}function ad(e){return II(e)?(e.nodeName||"").toLowerCase():"#document"}function cs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ko(e){var t;return(t=(II(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function II(e){return Ov()?e instanceof Node||e instanceof cs(e).Node:!1}function Ys(e){return Ov()?e instanceof Element||e instanceof cs(e).Element:!1}function oa(e){return Ov()?e instanceof HTMLElement||e instanceof cs(e).HTMLElement:!1}function kN(e){return!Ov()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof cs(e).ShadowRoot}function zf(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Ks(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function xee(e){return/^(table|td|th)$/.test(ad(e))}function Dv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Eee=/transform|translate|scale|rotate|perspective|filter/,Cee=/paint|layout|strict|content/,$l=e=>!!e&&e!=="none";let q_;function d1(e){const t=Ys(e)?Ks(e):e;return $l(t.transform)||$l(t.translate)||$l(t.scale)||$l(t.rotate)||$l(t.perspective)||!h1()&&($l(t.backdropFilter)||$l(t.filter))||Eee.test(t.willChange||"")||Cee.test(t.contain||"")}function kee(e){let t=al(e);for(;oa(t)&&!Wu(t);){if(d1(t))return t;if(Dv(t))return null;t=al(t)}return null}function h1(){return q_==null&&(q_=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),q_}function Wu(e){return/^(html|body|#document)$/.test(ad(e))}function Ks(e){return cs(e).getComputedStyle(e)}function Pv(e){return Ys(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function al(e){if(ad(e)==="html")return e;const t=e.assignedSlot||e.parentNode||kN(e)&&e.host||ko(e);return kN(t)?t.host:t}function zI(e){const t=al(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:oa(t)&&zf(t)?t:zI(t)}function pf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=zI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=cs(i);if(s){const l=A0(o);return t.concat(o,o.visualViewport||[],zf(i)?i:[],l&&n?pf(l):[])}else return t.concat(i,pf(i,[],n))}function A0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function BI(e){const t=Ks(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=oa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=Ug(n)!==s||Ug(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function f1(e){return Ys(e)?e:e.contextElement}function zu(e){const t=f1(e);if(!oa(t))return _o(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=BI(t);let o=(s?Ug(n.width):n.width)/r,l=(s?Ug(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Tee=_o(0);function jI(e){const t=cs(e);return!h1()||!t.visualViewport?Tee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ree(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==cs(e)?!1:t}function oc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=f1(e);let o=_o(1);t&&(r?Ys(r)&&(o=zu(r)):o=zu(e));const l=Ree(s,n,r)?jI(s):_o(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=cs(s),v=r&&Ys(r)?cs(r):r;let _=y,w=A0(_);for(;w&&r&&v!==_;){const x=zu(w),E=w.getBoundingClientRect(),k=Ks(w),R=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,A=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=R,d+=A,_=cs(w),w=A0(_)}}return qg({width:h,height:p,x:u,y:d})}function Lv(e,t){const n=Pv(e).scrollLeft;return t?t.left+n:oc(ko(e)).left+n}function FI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Lv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Aee(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=ko(r),l=t?Dv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=_o(1);const h=_o(0),p=oa(r);if((p||!p&&!s)&&((ad(r)!=="body"||zf(o))&&(u=Pv(r)),p)){const v=oc(r);d=zu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const y=o&&!p&&!s?FI(o,u):_o(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function Nee(e){return Array.from(e.getClientRects())}function Mee(e){const t=ko(e),n=Pv(e),r=e.ownerDocument.body,i=ls(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=ls(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Lv(e);const l=-n.scrollTop;return Ks(r).direction==="rtl"&&(o+=ls(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const TN=25;function Oee(e,t){const n=cs(e),r=ko(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=h1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Lv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),v=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-v);_<=TN&&(s-=_)}else d<=TN&&(s+=d);return{width:s,height:o,x:l,y:u}}function Dee(e,t){const n=oc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=oa(e)?zu(e):_o(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function RN(e,t,n){let r;if(t==="viewport")r=Oee(e,n);else if(t==="document")r=Mee(ko(e));else if(Ys(t))r=Dee(t,n);else{const i=jI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return qg(r)}function $I(e,t){const n=al(e);return n===t||!Ys(n)||Wu(n)?!1:Ks(n).position==="fixed"||$I(n,t)}function Pee(e,t){const n=t.get(e);if(n)return n;let r=pf(e,[],!1).filter(l=>Ys(l)&&ad(l)!=="body"),i=null;const s=Ks(e).position==="fixed";let o=s?al(e):e;for(;Ys(o)&&!Wu(o);){const l=Ks(o),u=d1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||zf(o)&&!u&&$I(e,o))?r=r.filter(h=>h!==o):i=l,o=al(o)}return t.set(e,r),r}function Lee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Dv(t)?[]:Pee(t,this._c):[].concat(n),r],l=RN(t,o[0],i);let u=l.top,d=l.right,h=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const v=RN(t,o[y],i);u=ls(v.top,u),d=ol(v.right,d),h=ol(v.bottom,h),p=ls(v.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function Iee(e){const{width:t,height:n}=BI(e);return{width:t,height:n}}function zee(e,t,n){const r=oa(t),i=ko(t),s=n==="fixed",o=oc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=_o(0);function d(){u.x=Lv(i)}if(r||!r&&!s)if((ad(t)!=="body"||zf(i))&&(l=Pv(t)),r){const v=oc(t,!0,s,t);u.x=v.x+t.clientLeft,u.y=v.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?FI(i,l):_o(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function V_(e){return Ks(e).position==="static"}function AN(e,t){if(!oa(e)||Ks(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ko(e)===n&&(n=n.ownerDocument.body),n}function HI(e,t){const n=cs(e);if(Dv(e))return n;if(!oa(e)){let i=al(e);for(;i&&!Wu(i);){if(Ys(i)&&!V_(i))return i;i=al(i)}return n}let r=AN(e,t);for(;r&&xee(r)&&V_(r);)r=AN(r,t);return r&&Wu(r)&&V_(r)&&!d1(r)?n:r||kee(e)||n}const Bee=async function(e){const t=this.getOffsetParent||HI,n=this.getDimensions,r=await n(e.floating);return{reference:zee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function jee(e){return Ks(e).direction==="rtl"}const Fee={convertOffsetParentRelativeRectToViewportRelativeRect:Aee,getDocumentElement:ko,getClippingRect:Lee,getOffsetParent:HI,getElementRects:Bee,getClientRects:Nee,getDimensions:Iee,getScale:zu,isElement:Ys,isRTL:jee};function UI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $ee(e,t){let n=null,r;const i=ko(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:h,top:p,width:y,height:v}=d;if(l||t(),!y||!v)return;const _=zm(p),w=zm(i.clientWidth-(h+y)),x=zm(i.clientHeight-(p+v)),E=zm(h),R={rootMargin:-_+"px "+-w+"px "+-x+"px "+-E+"px",threshold:ls(0,ol(1,u))||1};let A=!0;function I(T){const H=T[0].intersectionRatio;if(H!==u){if(!A)return o();H?o(!1,H):r=setTimeout(()=>{o(!1,1e-7)},1e3)}H===1&&!UI(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(I,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(I,R)}n.observe(e)}return o(!0),s}function Hee(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=f1(e),h=i||s?[...d?pf(d):[],...t?pf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?$ee(d,n):null;let y=-1,v=null;o&&(v=new ResizeObserver(E=>{let[k]=E;k&&k.target===d&&v&&t&&(v.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var R;(R=v)==null||R.observe(t)})),n()}),d&&!u&&v.observe(d),t&&v.observe(t));let _,w=u?oc(e):null;u&&x();function x(){const E=oc(e);w&&!UI(w,E)&&n(),w=E,_=requestAnimationFrame(x)}return n(),()=>{var E;h.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(E=v)==null||E.disconnect(),v=null,u&&cancelAnimationFrame(_)}}const Uee=bee,Wee=_ee,qee=gee,Vee=See,Yee=vee,NN=mee,Kee=wee,Gee=(e,t,n)=>{const r=new Map,i={platform:Fee,...n},s={...i.platform,_c:r};return pee(e,t,{...i,platform:s})};var Xee=typeof document<"u",Zee=function(){},yg=Xee?b.useLayoutEffect:Zee;function Vg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Vg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!Vg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function WI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function MN(e,t){const n=WI(e);return Math.round(t*n)/n}function Y_(e){const t=b.useRef(e);return yg(()=>{t.current=e}),t}function Qee(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,v]=b.useState(r);Vg(y,r)||v(r);const[_,w]=b.useState(null),[x,E]=b.useState(null),k=b.useCallback(Y=>{Y!==T.current&&(T.current=Y,w(Y))},[]),R=b.useCallback(Y=>{Y!==H.current&&(H.current=Y,E(Y))},[]),A=s||_,I=o||x,T=b.useRef(null),H=b.useRef(null),D=b.useRef(h),W=u!=null,U=Y_(u),F=Y_(i),O=Y_(d),M=b.useCallback(()=>{if(!T.current||!H.current)return;const Y={placement:t,strategy:n,middleware:y};F.current&&(Y.platform=F.current),Gee(T.current,H.current,Y).then($=>{const P={...$,isPositioned:O.current!==!1};z.current&&!Vg(D.current,P)&&(D.current=P,rd.flushSync(()=>{p(P)}))})},[y,t,n,F,O]);yg(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,p(Y=>({...Y,isPositioned:!1})))},[d]);const z=b.useRef(!1);yg(()=>(z.current=!0,()=>{z.current=!1}),[]),yg(()=>{if(A&&(T.current=A),I&&(H.current=I),A&&I){if(U.current)return U.current(A,I,M);M()}},[A,I,M,U,W]);const L=b.useMemo(()=>({reference:T,floating:H,setReference:k,setFloating:R}),[k,R]),N=b.useMemo(()=>({reference:A,floating:I}),[A,I]),q=b.useMemo(()=>{const Y={position:n,left:0,top:0};if(!N.floating)return Y;const $=MN(N.floating,h.x),P=MN(N.floating,h.y);return l?{...Y,transform:"translate("+$+"px, "+P+"px)",...WI(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:P}},[n,l,N.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:M,refs:L,elements:N,floatingStyles:q}),[h,M,L,N,q])}const Jee=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?NN({element:r.current,padding:i}).fn(n):{}:r?NN({element:r,padding:i}).fn(n):{}}}},ete=(e,t)=>{const n=Uee(e);return{name:n.name,fn:n.fn,options:[e,t]}},tte=(e,t)=>{const n=Wee(e);return{name:n.name,fn:n.fn,options:[e,t]}},nte=(e,t)=>({fn:Kee(e).fn,options:[e,t]}),rte=(e,t)=>{const n=qee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ite=(e,t)=>{const n=Vee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ste=(e,t)=>{const n=Yee(e);return{name:n.name,fn:n.fn,options:[e,t]}},ote=(e,t)=>{const n=Jee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var ate="Arrow",qI=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return g.jsx(Kt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:g.jsx("polygon",{points:"0,0 30,0 15,10"})})});qI.displayName=ate;var lte=qI,p1="Popper",[VI,vl]=sa(p1),[cte,YI]=VI(p1),KI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return g.jsx(cte,{scope:t,anchor:r,onAnchorChange:i,children:n})};KI.displayName=p1;var GI="PopperAnchor",XI=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=YI(GI,n),o=b.useRef(null),l=Bn(t,o),u=b.useRef(null);return b.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:g.jsx(Kt.div,{...i,ref:l})});XI.displayName=GI;var m1="PopperContent",[ute,dte]=VI(m1),ZI=b.forwardRef((e,t)=>{var J,me,Se,Re,Ae,He;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:v="optimized",onPlaced:_,...w}=e,x=YI(m1,n),[E,k]=b.useState(null),R=Bn(t,qe=>k(qe)),[A,I]=b.useState(null),T=nee(A),H=(T==null?void 0:T.width)??0,D=(T==null?void 0:T.height)??0,W=r+(s!=="center"?"-"+s:""),U=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},F=Array.isArray(d)?d:[d],O=F.length>0,M={padding:U,boundary:F.filter(fte),altBoundary:O},{refs:z,floatingStyles:L,placement:N,isPositioned:q,middlewareData:Y}=Qee({strategy:"fixed",placement:W,whileElementsMounted:(...qe)=>Hee(...qe,{animationFrame:v==="always"}),elements:{reference:x.anchor},middleware:[ete({mainAxis:i+D,alignmentAxis:o}),u&&tte({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?nte():void 0,...M}),u&&rte({...M}),ite({...M,apply:({elements:qe,rects:pt,availableWidth:kt,availableHeight:ve})=>{const{width:Ke,height:Tt}=pt.reference,_e=qe.floating.style;_e.setProperty("--radix-popper-available-width",`${kt}px`),_e.setProperty("--radix-popper-available-height",`${ve}px`),_e.setProperty("--radix-popper-anchor-width",`${Ke}px`),_e.setProperty("--radix-popper-anchor-height",`${Tt}px`)}}),A&&ote({element:A,padding:l}),pte({arrowWidth:H,arrowHeight:D}),y&&ste({strategy:"referenceHidden",...M})]}),[$,P]=ez(N),V=xo(_);Ei(()=>{q&&(V==null||V())},[q,V]);const G=(J=Y.arrow)==null?void 0:J.x,B=(me=Y.arrow)==null?void 0:me.y,K=((Se=Y.arrow)==null?void 0:Se.centerOffset)!==0,[ee,te]=b.useState();return Ei(()=>{E&&te(window.getComputedStyle(E).zIndex)},[E]),g.jsx("div",{ref:z.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:q?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ee,"--radix-popper-transform-origin":[(Re=Y.transformOrigin)==null?void 0:Re.x,(Ae=Y.transformOrigin)==null?void 0:Ae.y].join(" "),...((He=Y.hide)==null?void 0:He.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:g.jsx(ute,{scope:n,placedSide:$,onArrowChange:I,arrowX:G,arrowY:B,shouldHideArrow:K,children:g.jsx(Kt.div,{"data-side":$,"data-align":P,...w,ref:R,style:{...w.style,animation:q?void 0:"none"}})})})});ZI.displayName=m1;var QI="PopperArrow",hte={top:"bottom",right:"left",bottom:"top",left:"right"},JI=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=dte(QI,r),o=hte[s.placedSide];return g.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:g.jsx(lte,{...i,ref:n,style:{...i.style,display:"block"}})})});JI.displayName=QI;function fte(e){return e!==null}var pte=e=>({name:"transformOrigin",options:e,fn(t){var x,E,k;const{placement:n,rects:r,middlewareData:i}=t,o=((x=i.arrow)==null?void 0:x.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,h]=ez(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.x)??0)+l/2,v=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?p:`${y}px`,w=`${-u}px`):d==="top"?(_=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?p:`${v}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?p:`${v}px`),{data:{x:_,y:w}}}});function ez(e){const[t,n="center"]=e.split("-");return[t,n]}var Iv=KI,Bf=XI,zv=ZI,Bv=JI,K_="rovingFocusGroup.onEntryFocus",mte={bubbles:!1,cancelable:!0},jf="RovingFocusGroup",[N0,tz,gte]=Qx(jf),[vte,nz]=sa(jf,[gte]),[yte,bte]=vte(jf),rz=b.forwardRef((e,t)=>g.jsx(N0.Provider,{scope:e.__scopeRovingFocusGroup,children:g.jsx(N0.Slot,{scope:e.__scopeRovingFocusGroup,children:g.jsx(_te,{...e,ref:t})})}));rz.displayName=jf;var _te=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...p}=e,y=b.useRef(null),v=Bn(t,y),_=Jx(s),[w,x]=ic({prop:o,defaultProp:l??null,onChange:u,caller:jf}),[E,k]=b.useState(!1),R=xo(d),A=tz(n),I=b.useRef(!1),[T,H]=b.useState(0);return b.useEffect(()=>{const D=y.current;if(D)return D.addEventListener(K_,R),()=>D.removeEventListener(K_,R)},[R]),g.jsx(yte,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(D=>x(D),[x]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>H(D=>D+1),[]),onFocusableItemRemove:b.useCallback(()=>H(D=>D-1),[]),children:g.jsx(Kt.div,{tabIndex:E||T===0?-1:0,"data-orientation":r,...p,ref:v,style:{outline:"none",...e.style},onMouseDown:ft(e.onMouseDown,()=>{I.current=!0}),onFocus:ft(e.onFocus,D=>{const W=!I.current;if(D.target===D.currentTarget&&W&&!E){const U=new CustomEvent(K_,mte);if(D.currentTarget.dispatchEvent(U),!U.defaultPrevented){const F=A().filter(N=>N.focusable),O=F.find(N=>N.active),M=F.find(N=>N.id===w),L=[O,M,...F].filter(Boolean).map(N=>N.ref.current);oz(L,h)}}I.current=!1}),onBlur:ft(e.onBlur,()=>k(!1))})})}),iz="RovingFocusGroupItem",sz=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=bte(iz,n),p=h.currentTabStopId===d,y=tz(n),{onFocusableItemAdd:v,onFocusableItemRemove:_,currentTabStopId:w}=h;return b.useEffect(()=>{if(r)return v(),()=>_()},[r,v,_]),g.jsx(N0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:g.jsx(Kt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:ft(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:ft(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:ft(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=xte(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(E==="last")R.reverse();else if(E==="prev"||E==="next"){E==="prev"&&R.reverse();const A=R.indexOf(x.currentTarget);R=h.loop?Ete(R,A+1):R.slice(A+1)}setTimeout(()=>oz(R))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});sz.displayName=iz;var wte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ste(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function xte(e,t,n){const r=Ste(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return wte[r]}function oz(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ete(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Cte=rz,kte=sz,M0=["Enter"," "],Tte=["ArrowDown","PageUp","Home"],az=["ArrowUp","PageDown","End"],Rte=[...Tte,...az],Ate={ltr:[...M0,"ArrowRight"],rtl:[...M0,"ArrowLeft"]},Nte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ff="Menu",[mf,Mte,Ote]=Qx(Ff),[yc,lz]=sa(Ff,[Ote,vl,nz]),jv=vl(),cz=nz(),[Dte,bc]=yc(Ff),[Pte,$f]=yc(Ff),uz=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=jv(t),[u,d]=b.useState(null),h=b.useRef(!1),p=xo(s),y=Jx(i);return b.useEffect(()=>{const v=()=>{h.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>h.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),g.jsx(Iv,{...l,children:g.jsx(Dte,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:g.jsx(Pte,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};uz.displayName=Ff;var Lte="MenuAnchor",g1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bf,{...i,...r,ref:t})});g1.displayName=Lte;var v1="MenuPortal",[Ite,dz]=yc(v1,{forceMount:void 0}),hz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=bc(v1,t);return g.jsx(Ite,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(sd,{asChild:!0,container:i,children:r})})})};hz.displayName=v1;var As="MenuContent",[zte,y1]=yc(As),fz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=bc(As,e.__scopeMenu),o=$f(As,e.__scopeMenu);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:o.modal?g.jsx(Bte,{...i,ref:t}):g.jsx(jte,{...i,ref:t})})})})}),Bte=b.forwardRef((e,t)=>{const n=bc(As,e.__scopeMenu),r=b.useRef(null),i=Bn(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Nv(s)},[]),g.jsx(b1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ft(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),jte=b.forwardRef((e,t)=>{const n=bc(As,e.__scopeMenu);return g.jsx(b1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Fte=sl("MenuContent.ScrollLock"),b1=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,disableOutsideScroll:_,...w}=e,x=bc(As,n),E=$f(As,n),k=jv(n),R=cz(n),A=Mte(n),[I,T]=b.useState(null),H=b.useRef(null),D=Bn(t,H,x.onContentChange),W=b.useRef(0),U=b.useRef(""),F=b.useRef(0),O=b.useRef(null),M=b.useRef("right"),z=b.useRef(0),L=_?If:b.Fragment,N=_?{as:Fte,allowPinchZoom:!0}:void 0,q=$=>{var J,me;const P=U.current+$,V=A().filter(Se=>!Se.disabled),G=document.activeElement,B=(J=V.find(Se=>Se.ref.current===G))==null?void 0:J.textValue,K=V.map(Se=>Se.textValue),ee=Qte(K,P,B),te=(me=V.find(Se=>Se.textValue===ee))==null?void 0:me.ref.current;(function Se(Re){U.current=Re,window.clearTimeout(W.current),Re!==""&&(W.current=window.setTimeout(()=>Se(""),1e3))})(P),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(W.current),[]),Rv();const Y=b.useCallback($=>{var V,G;return M.current===((V=O.current)==null?void 0:V.side)&&ene($,(G=O.current)==null?void 0:G.area)},[]);return g.jsx(zte,{scope:n,searchRef:U,onItemEnter:b.useCallback($=>{Y($)&&$.preventDefault()},[Y]),onItemLeave:b.useCallback($=>{var P;Y($)||((P=H.current)==null||P.focus(),T(null))},[Y]),onTriggerLeave:b.useCallback($=>{Y($)&&$.preventDefault()},[Y]),pointerGraceTimerRef:F,onPointerGraceIntentChange:b.useCallback($=>{O.current=$},[]),children:g.jsx(L,{...N,children:g.jsx(Lf,{asChild:!0,trapped:i,onMountAutoFocus:ft(s,$=>{var P;$.preventDefault(),(P=H.current)==null||P.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(id,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:v,children:g.jsx(Cte,{asChild:!0,...R,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:T,onEntryFocus:ft(u,$=>{E.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(zv,{role:"menu","aria-orientation":"vertical","data-state":Az(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:D,style:{outline:"none",...w.style},onKeyDown:ft(w.onKeyDown,$=>{const V=$.target.closest("[data-radix-menu-content]")===$.currentTarget,G=$.ctrlKey||$.altKey||$.metaKey,B=$.key.length===1;V&&($.key==="Tab"&&$.preventDefault(),!G&&B&&q($.key));const K=H.current;if($.target!==K||!Rte.includes($.key))return;$.preventDefault();const te=A().filter(J=>!J.disabled).map(J=>J.ref.current);az.includes($.key)&&te.reverse(),Xte(te)}),onBlur:ft(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(W.current),U.current="")}),onPointerMove:ft(e.onPointerMove,gf($=>{const P=$.target,V=z.current!==$.clientX;if($.currentTarget.contains(P)&&V){const G=$.clientX>z.current?"right":"left";M.current=G,z.current=$.clientX}}))})})})})})})});fz.displayName=As;var $te="MenuGroup",_1=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Kt.div,{role:"group",...r,ref:t})});_1.displayName=$te;var Hte="MenuLabel",pz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Kt.div,{...r,ref:t})});pz.displayName=Hte;var Yg="MenuItem",ON="menu.itemSelect",Fv=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=$f(Yg,e.__scopeMenu),l=y1(Yg,e.__scopeMenu),u=Bn(t,s),d=b.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(ON,{bubbles:!0,cancelable:!0});p.addEventListener(ON,v=>r==null?void 0:r(v),{once:!0}),tI(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return g.jsx(mz,{...i,ref:u,disabled:n,onClick:ft(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:ft(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:ft(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||M0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Fv.displayName=Yg;var mz=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=y1(Yg,n),l=cz(n),u=b.useRef(null),d=Bn(t,u),[h,p]=b.useState(!1),[y,v]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&v((_.textContent??"").trim())},[s.children]),g.jsx(mf.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:g.jsx(kte,{asChild:!0,...l,focusable:!r,children:g.jsx(Kt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:ft(e.onPointerMove,gf(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ft(e.onPointerLeave,gf(_=>o.onItemLeave(_))),onFocus:ft(e.onFocus,()=>p(!0)),onBlur:ft(e.onBlur,()=>p(!1))})})})}),Ute="MenuCheckboxItem",gz=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return g.jsx(wz,{scope:e.__scopeMenu,checked:n,children:g.jsx(Fv,{role:"menuitemcheckbox","aria-checked":Kg(n)?"mixed":n,...i,ref:t,"data-state":S1(n),onSelect:ft(i.onSelect,()=>r==null?void 0:r(Kg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});gz.displayName=Ute;var vz="MenuRadioGroup",[Wte,qte]=yc(vz,{value:void 0,onValueChange:()=>{}}),yz=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=xo(r);return g.jsx(Wte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:g.jsx(_1,{...i,ref:t})})});yz.displayName=vz;var bz="MenuRadioItem",_z=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=qte(bz,e.__scopeMenu),s=n===i.value;return g.jsx(wz,{scope:e.__scopeMenu,checked:s,children:g.jsx(Fv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":S1(s),onSelect:ft(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});_z.displayName=bz;var w1="MenuItemIndicator",[wz,Vte]=yc(w1,{checked:!1}),Sz=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=Vte(w1,n);return g.jsx(Ps,{present:r||Kg(s.checked)||s.checked===!0,children:g.jsx(Kt.span,{...i,ref:t,"data-state":S1(s.checked)})})});Sz.displayName=w1;var Yte="MenuSeparator",xz=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return g.jsx(Kt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});xz.displayName=Yte;var Kte="MenuArrow",Ez=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jv(n);return g.jsx(Bv,{...i,...r,ref:t})});Ez.displayName=Kte;var Gte="MenuSub",[eRe,Cz]=yc(Gte),Ih="MenuSubTrigger",kz=b.forwardRef((e,t)=>{const n=bc(Ih,e.__scopeMenu),r=$f(Ih,e.__scopeMenu),i=Cz(Ih,e.__scopeMenu),s=y1(Ih,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>h,[h]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),g.jsx(g1,{asChild:!0,...d,children:g.jsx(mz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Az(n.open),...e,ref:na(t,i.onTriggerChange),onClick:p=>{var y;(y=e.onClick)==null||y.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ft(e.onPointerMove,gf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:ft(e.onPointerLeave,gf(p=>{var v,_;h();const y=(v=n.content)==null?void 0:v.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],R=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,y:p.clientY},{x:k,y:y.top},{x:R,y:y.top},{x:R,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ft(e.onKeyDown,p=>{var v;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Ate[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});kz.displayName=Ih;var Tz="MenuSubContent",Rz=b.forwardRef((e,t)=>{const n=dz(As,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=bc(As,e.__scopeMenu),o=$f(As,e.__scopeMenu),l=Cz(Tz,e.__scopeMenu),u=b.useRef(null),d=Bn(t,u);return g.jsx(mf.Provider,{scope:e.__scopeMenu,children:g.jsx(Ps,{present:r||s.open,children:g.jsx(mf.Slot,{scope:e.__scopeMenu,children:g.jsx(b1,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:ft(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ft(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:ft(e.onKeyDown,h=>{var v;const p=h.currentTarget.contains(h.target),y=Nte[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(v=l.trigger)==null||v.focus(),h.preventDefault())})})})})})});Rz.displayName=Tz;function Az(e){return e?"open":"closed"}function Kg(e){return e==="indeterminate"}function S1(e){return Kg(e)?"indeterminate":e?"checked":"unchecked"}function Xte(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Zte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Qte(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Zte(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function Jte(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function ene(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Jte(n,t)}function gf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var tne=uz,nne=g1,rne=hz,ine=fz,sne=_1,one=pz,ane=Fv,lne=gz,cne=yz,une=_z,dne=Sz,hne=xz,fne=Ez,pne=kz,mne=Rz,$v="DropdownMenu",[gne]=sa($v,[lz]),Pi=lz(),[vne,Nz]=gne($v),Mz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Pi(t),d=b.useRef(null),[h,p]=ic({prop:i,defaultProp:s??!1,onChange:o,caller:$v});return g.jsx(vne,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(y=>!y),[p]),modal:l,children:g.jsx(tne,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};Mz.displayName=$v;var Oz="DropdownMenuTrigger",Dz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Nz(Oz,n),o=Pi(n);return g.jsx(nne,{asChild:!0,...o,children:g.jsx(Kt.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:na(t,s.triggerRef),onPointerDown:ft(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:ft(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Dz.displayName=Oz;var yne="DropdownMenuPortal",Pz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Pi(t);return g.jsx(rne,{...r,...n})};Pz.displayName=yne;var Lz="DropdownMenuContent",Iz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Nz(Lz,n),s=Pi(n),o=b.useRef(!1);return g.jsx(ine,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:ft(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:ft(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Iz.displayName=Lz;var bne="DropdownMenuGroup",_ne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(sne,{...i,...r,ref:t})});_ne.displayName=bne;var wne="DropdownMenuLabel",zz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(one,{...i,...r,ref:t})});zz.displayName=wne;var Sne="DropdownMenuItem",Bz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(ane,{...i,...r,ref:t})});Bz.displayName=Sne;var xne="DropdownMenuCheckboxItem",jz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(lne,{...i,...r,ref:t})});jz.displayName=xne;var Ene="DropdownMenuRadioGroup",Cne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(cne,{...i,...r,ref:t})});Cne.displayName=Ene;var kne="DropdownMenuRadioItem",Tne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(une,{...i,...r,ref:t})});Tne.displayName=kne;var Rne="DropdownMenuItemIndicator",Fz=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(dne,{...i,...r,ref:t})});Fz.displayName=Rne;var Ane="DropdownMenuSeparator",$z=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(hne,{...i,...r,ref:t})});$z.displayName=Ane;var Nne="DropdownMenuArrow",Mne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(fne,{...i,...r,ref:t})});Mne.displayName=Nne;var One="DropdownMenuSubTrigger",Dne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(pne,{...i,...r,ref:t})});Dne.displayName=One;var Pne="DropdownMenuSubContent",Lne=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Pi(n);return g.jsx(mne,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Lne.displayName=Pne;var Ine=Mz,zne=Dz,Bne=Pz,jne=Iz,Fne=zz,$ne=Bz,Hne=jz,Une=Fz,Wne=$z;function DN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Hv="Popover",[Hz]=sa(Hv,[vl]),Hf=vl(),[qne,yl]=Hz(Hv),Uz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Hf(t),u=b.useRef(null),[d,h]=b.useState(!1),[p,y]=ic({prop:r,defaultProp:i??!1,onChange:s,caller:Hv});return g.jsx(Iv,{...l,children:g.jsx(qne,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(v=>!v),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:o,children:n})})};Uz.displayName=Hv;var Wz="PopoverAnchor",Vne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=yl(Wz,n),s=Hf(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),g.jsx(Bf,{...s,...r,ref:t})});Vne.displayName=Wz;var qz="PopoverTrigger",Vz=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=yl(qz,n),s=Hf(n),o=Bn(t,i.triggerRef),l=g.jsx(Kt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Zz(i.open),...r,ref:o,onClick:ft(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:g.jsx(Bf,{asChild:!0,...s,children:l})});Vz.displayName=qz;var x1="PopoverPortal",[Yne,Kne]=Hz(x1,{forceMount:void 0}),Yz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=yl(x1,t);return g.jsx(Yne,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(sd,{asChild:!0,container:i,children:r})})})};Yz.displayName=x1;var qu="PopoverContent",Kz=b.forwardRef((e,t)=>{const n=Kne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=yl(qu,e.__scopePopover);return g.jsx(Ps,{present:r||s.open,children:s.modal?g.jsx(Xne,{...i,ref:t}):g.jsx(Zne,{...i,ref:t})})});Kz.displayName=qu;var Gne=sl("PopoverContent.RemoveScroll"),Xne=b.forwardRef((e,t)=>{const n=yl(qu,e.__scopePopover),r=b.useRef(null),i=Bn(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Nv(o)},[]),g.jsx(If,{as:Gne,allowPinchZoom:!0,children:g.jsx(Gz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ft(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:ft(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:ft(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Zne=b.forwardRef((e,t)=>{const n=yl(qu,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return g.jsx(Gz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),Gz=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,...p}=e,y=yl(qu,n),v=Hf(n);return Rv(),g.jsx(Lf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:g.jsx(id,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:g.jsx(zv,{"data-state":Zz(y.open),role:"dialog",id:y.contentId,...v,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Xz="PopoverClose",Qne=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=yl(Xz,n);return g.jsx(Kt.button,{type:"button",...r,ref:t,onClick:ft(e.onClick,()=>i.onOpenChange(!1))})});Qne.displayName=Xz;var Jne="PopoverArrow",ere=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Hf(n);return g.jsx(Bv,{...i,...r,ref:t})});ere.displayName=Jne;function Zz(e){return e?"open":"closed"}var tre=Uz,nre=Vz,rre=Yz,ire=Kz,sre=[" ","Enter","ArrowUp","ArrowDown"],ore=[" ","Enter"],ac="Select",[Uv,Wv,are]=Qx(ac),[ld]=sa(ac,[are,vl]),qv=vl(),[lre,bl]=ld(ac),[cre,ure]=ld(ac),Qz=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:h,autoComplete:p,disabled:y,required:v,form:_}=e,w=qv(t),[x,E]=b.useState(null),[k,R]=b.useState(null),[A,I]=b.useState(!1),T=Jx(d),[H,D]=ic({prop:r,defaultProp:i??!1,onChange:s,caller:ac}),[W,U]=ic({prop:o,defaultProp:l,onChange:u,caller:ac}),F=b.useRef(null),O=x?_||!!x.closest("form"):!0,[M,z]=b.useState(new Set),L=Array.from(M).map(N=>N.props.value).join(";");return g.jsx(Iv,{...w,children:g.jsxs(lre,{required:v,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:I,contentId:gi(),value:W,onValueChange:U,open:H,onOpenChange:D,dir:T,triggerPointerDownPosRef:F,disabled:y,children:[g.jsx(Uv.Provider,{scope:t,children:g.jsx(cre,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(N=>{z(q=>new Set(q).add(N))},[]),onNativeOptionRemove:b.useCallback(N=>{z(q=>{const Y=new Set(q);return Y.delete(N),Y})},[]),children:n})}),O?g.jsxs(_B,{"aria-hidden":!0,required:v,tabIndex:-1,name:h,autoComplete:p,value:W,onChange:N=>U(N.target.value),disabled:y,form:_,children:[W===void 0?g.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};Qz.displayName=ac;var Jz="SelectTrigger",eB=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=qv(n),o=bl(Jz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Wv(n),h=b.useRef("touch"),[p,y,v]=SB(w=>{const x=d().filter(R=>!R.disabled),E=x.find(R=>R.value===o.value),k=xB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),_=w=>{l||(o.onOpenChange(!0),v()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return g.jsx(Bf,{asChild:!0,...s,children:g.jsx(Kt.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":wB(o.value)?"":void 0,...i,ref:u,onClick:ft(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&_(w)}),onPointerDown:ft(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:ft(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&sre.includes(w.key)&&(_(),w.preventDefault())})})})});eB.displayName=Jz;var tB="SelectValue",nB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=bl(tB,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ei(()=>{d(h)},[d,h]),g.jsx(Kt.span,{...l,ref:p,style:{pointerEvents:"none"},children:wB(u.value)?g.jsx(g.Fragment,{children:o}):s})});nB.displayName=tB;var dre="SelectIcon",rB=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return g.jsx(Kt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});rB.displayName=dre;var hre="SelectPortal",iB=e=>g.jsx(sd,{asChild:!0,...e});iB.displayName=hre;var lc="SelectContent",sB=b.forwardRef((e,t)=>{const n=bl(lc,e.__scopeSelect),[r,i]=b.useState();if(Ei(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?rd.createPortal(g.jsx(oB,{scope:e.__scopeSelect,children:g.jsx(Uv.Slot,{scope:e.__scopeSelect,children:g.jsx("div",{children:e.children})})}),s):null}return g.jsx(aB,{...e,ref:t})});sB.displayName=lc;var $s=10,[oB,_l]=ld(lc),fre="SelectContentImpl",pre=sl("SelectContent.RemoveScroll"),aB=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=bl(lc,n),[R,A]=b.useState(null),[I,T]=b.useState(null),H=Bn(t,J=>A(J)),[D,W]=b.useState(null),[U,F]=b.useState(null),O=Wv(n),[M,z]=b.useState(!1),L=b.useRef(!1);b.useEffect(()=>{if(R)return Nv(R)},[R]),Rv();const N=b.useCallback(J=>{const[me,...Se]=O().map(He=>He.ref.current),[Re]=Se.slice(-1),Ae=document.activeElement;for(const He of J)if(He===Ae||(He==null||He.scrollIntoView({block:"nearest"}),He===me&&I&&(I.scrollTop=0),He===Re&&I&&(I.scrollTop=I.scrollHeight),He==null||He.focus(),document.activeElement!==Ae))return},[O,I]),q=b.useCallback(()=>N([D,R]),[N,D,R]);b.useEffect(()=>{M&&q()},[M,q]);const{onOpenChange:Y,triggerPointerDownPosRef:$}=k;b.useEffect(()=>{if(R){let J={x:0,y:0};const me=Re=>{var Ae,He;J={x:Math.abs(Math.round(Re.pageX)-(((Ae=$.current)==null?void 0:Ae.x)??0)),y:Math.abs(Math.round(Re.pageY)-(((He=$.current)==null?void 0:He.y)??0))}},Se=Re=>{J.x<=10&&J.y<=10?Re.preventDefault():R.contains(Re.target)||Y(!1),document.removeEventListener("pointermove",me),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",me),document.addEventListener("pointerup",Se,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",me),document.removeEventListener("pointerup",Se,{capture:!0})}}},[R,Y,$]),b.useEffect(()=>{const J=()=>Y(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[Y]);const[P,V]=SB(J=>{const me=O().filter(Ae=>!Ae.disabled),Se=me.find(Ae=>Ae.ref.current===document.activeElement),Re=xB(me,J,Se);Re&&setTimeout(()=>Re.ref.current.focus())}),G=b.useCallback((J,me,Se)=>{const Re=!L.current&&!Se;(k.value!==void 0&&k.value===me||Re)&&(W(J),Re&&(L.current=!0))},[k.value]),B=b.useCallback(()=>R==null?void 0:R.focus(),[R]),K=b.useCallback((J,me,Se)=>{const Re=!L.current&&!Se;(k.value!==void 0&&k.value===me||Re)&&F(J)},[k.value]),ee=r==="popper"?O0:lB,te=ee===O0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:v,sticky:_,hideWhenDetached:w,avoidCollisions:x}:{};return g.jsx(oB,{scope:n,content:R,viewport:I,onViewportChange:T,itemRefCallback:G,selectedItem:D,onItemLeave:B,itemTextRefCallback:K,focusSelectedItem:q,selectedItemText:U,position:r,isPositioned:M,searchRef:P,children:g.jsx(If,{as:pre,allowPinchZoom:!0,children:g.jsx(Lf,{asChild:!0,trapped:k.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:ft(i,J=>{var me;(me=k.trigger)==null||me.focus({preventScroll:!0}),J.preventDefault()}),children:g.jsx(id,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:g.jsx(ee,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:J=>J.preventDefault(),...E,...te,onPlaced:()=>z(!0),ref:H,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:ft(E.onKeyDown,J=>{const me=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!me&&J.key.length===1&&V(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Re=O().filter(Ae=>!Ae.disabled).map(Ae=>Ae.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Re=Re.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const Ae=J.target,He=Re.indexOf(Ae);Re=Re.slice(He+1)}setTimeout(()=>N(Re)),J.preventDefault()}})})})})})})});aB.displayName=fre;var mre="SelectItemAlignedPosition",lB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=bl(lc,n),o=_l(lc,n),[l,u]=b.useState(null),[d,h]=b.useState(null),p=Bn(t,H=>h(H)),y=Wv(n),v=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const H=s.trigger.getBoundingClientRect(),D=d.getBoundingClientRect(),W=s.valueNode.getBoundingClientRect(),U=E.getBoundingClientRect();if(s.dir!=="rtl"){const Ae=U.left-D.left,He=W.left-Ae,qe=H.left-He,pt=H.width+qe,kt=Math.max(pt,D.width),ve=window.innerWidth-$s,Ke=DN(He,[$s,Math.max($s,ve-kt)]);l.style.minWidth=pt+"px",l.style.left=Ke+"px"}else{const Ae=D.right-U.right,He=window.innerWidth-W.right-Ae,qe=window.innerWidth-H.right-He,pt=H.width+qe,kt=Math.max(pt,D.width),ve=window.innerWidth-$s,Ke=DN(He,[$s,Math.max($s,ve-kt)]);l.style.minWidth=pt+"px",l.style.right=Ke+"px"}const F=y(),O=window.innerHeight-$s*2,M=w.scrollHeight,z=window.getComputedStyle(d),L=parseInt(z.borderTopWidth,10),N=parseInt(z.paddingTop,10),q=parseInt(z.borderBottomWidth,10),Y=parseInt(z.paddingBottom,10),$=L+N+M+Y+q,P=Math.min(x.offsetHeight*5,$),V=window.getComputedStyle(w),G=parseInt(V.paddingTop,10),B=parseInt(V.paddingBottom,10),K=H.top+H.height/2-$s,ee=O-K,te=x.offsetHeight/2,J=x.offsetTop+te,me=L+N+J,Se=$-me;if(me<=K){const Ae=F.length>0&&x===F[F.length-1].ref.current;l.style.bottom="0px";const He=d.clientHeight-w.offsetTop-w.offsetHeight,qe=Math.max(ee,te+(Ae?B:0)+He+q),pt=me+qe;l.style.height=pt+"px"}else{const Ae=F.length>0&&x===F[0].ref.current;l.style.top="0px";const qe=Math.max(K,L+w.offsetTop+(Ae?G:0)+te)+Se;l.style.height=qe+"px",w.scrollTop=me-K+w.offsetTop}l.style.margin=`${$s}px 0`,l.style.minHeight=P+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>v.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ei(()=>R(),[R]);const[A,I]=b.useState();Ei(()=>{d&&I(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(H=>{H&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return g.jsx(vre,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:v,onScrollButtonChange:T,children:g.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:g.jsx(Kt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});lB.displayName=mre;var gre="SelectPopperPosition",O0=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=$s,...s}=e,o=qv(n);return g.jsx(zv,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});O0.displayName=gre;var[vre,E1]=ld(lc,{}),D0="SelectViewport",cB=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=_l(D0,n),o=E1(D0,n),l=Bn(t,s.onViewportChange),u=b.useRef(0);return g.jsxs(g.Fragment,{children:[g.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),g.jsx(Uv.Slot,{scope:n,children:g.jsx(Kt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:ft(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const v=Math.abs(u.current-h.scrollTop);if(v>0){const _=window.innerHeight-$s*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<_){const k=E+v,R=Math.min(_,k),A=k-R;p.style.height=R+"px",p.style.bottom==="0px"&&(h.scrollTop=A>0?A:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});cB.displayName=D0;var uB="SelectGroup",[yre,bre]=ld(uB),_re=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return g.jsx(yre,{scope:n,id:i,children:g.jsx(Kt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});_re.displayName=uB;var dB="SelectLabel",wre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bre(dB,n);return g.jsx(Kt.div,{id:i.id,...r,ref:t})});wre.displayName=dB;var Gg="SelectItem",[Sre,hB]=ld(Gg),fB=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=bl(Gg,n),u=_l(Gg,n),d=l.value===r,[h,p]=b.useState(s??""),[y,v]=b.useState(!1),_=Bn(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=gi(),x=b.useRef("touch"),E=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return g.jsx(Sre,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{p(R=>R||((k==null?void 0:k.textContent)??"").trim())},[]),children:g.jsx(Uv.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:g.jsx(Kt.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:ft(o.onFocus,()=>v(!0)),onBlur:ft(o.onBlur,()=>v(!1)),onClick:ft(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:ft(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:ft(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:ft(o.onPointerMove,k=>{var R;x.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ft(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:ft(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(ore.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});fB.displayName=Gg;var zh="SelectItemText",pB=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=bl(zh,n),l=_l(zh,n),u=hB(zh,n),d=ure(zh,n),[h,p]=b.useState(null),y=Bn(t,E=>p(E),u.onItemTextChange,E=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,E,u.value,u.disabled)}),v=h==null?void 0:h.textContent,_=b.useMemo(()=>g.jsx("option",{value:u.value,disabled:u.disabled,children:v},u.value),[u.disabled,u.value,v]),{onNativeOptionAdd:w,onNativeOptionRemove:x}=d;return Ei(()=>(w(_),()=>x(_)),[w,x,_]),g.jsxs(g.Fragment,{children:[g.jsx(Kt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?rd.createPortal(s.children,o.valueNode):null]})});pB.displayName=zh;var mB="SelectItemIndicator",gB=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return hB(mB,n).isSelected?g.jsx(Kt.span,{"aria-hidden":!0,...r,ref:t}):null});gB.displayName=mB;var P0="SelectScrollUpButton",vB=b.forwardRef((e,t)=>{const n=_l(P0,e.__scopeSelect),r=E1(P0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ei(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollTop>0;s(d)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?g.jsx(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});vB.displayName=P0;var L0="SelectScrollDownButton",yB=b.forwardRef((e,t)=>{const n=_l(L0,e.__scopeSelect),r=E1(L0,e.__scopeSelect),[i,s]=b.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ei(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,h=Math.ceil(u.scrollTop)<d;s(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?g.jsx(bB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});yB.displayName=L0;var bB=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=_l("SelectScrollButton",n),o=b.useRef(null),l=Wv(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ei(()=>{var h;const d=l().find(p=>p.ref.current===document.activeElement);(h=d==null?void 0:d.ref.current)==null||h.scrollIntoView({block:"nearest"})},[l]),g.jsx(Kt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:ft(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:ft(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:ft(i.onPointerLeave,()=>{u()})})}),xre="SelectSeparator",Ere=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return g.jsx(Kt.div,{"aria-hidden":!0,...r,ref:t})});Ere.displayName=xre;var I0="SelectArrow",Cre=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qv(n),s=bl(I0,n),o=_l(I0,n);return s.open&&o.position==="popper"?g.jsx(Bv,{...i,...r,ref:t}):null});Cre.displayName=I0;var kre="SelectBubbleInput",_B=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=Bn(r,i),o=tee(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&h){const p=new Event("change",{bubbles:!0});h.call(l,t),l.dispatchEvent(p)}},[o,t]),g.jsx(Kt.select,{...n,style:{...nI,...n.style},ref:s,defaultValue:t})});_B.displayName=kre;function wB(e){return e===""||e===void 0}function SB(e){const t=xo(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function xB(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=Tre(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const u=o.find(d=>d.textValue.toLowerCase().startsWith(i.toLowerCase()));return u!==n?u:void 0}function Tre(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Rre=Qz,Are=eB,Nre=nB,Mre=rB,Ore=iB,Dre=sB,Pre=cB,Lre=fB,Ire=pB,zre=gB,Bre=vB,jre=yB,[Vv]=sa("Tooltip",[vl]),Yv=vl(),EB="TooltipProvider",Fre=700,z0="tooltip.open",[$re,C1]=Vv(EB),CB=e=>{const{__scopeTooltip:t,delayDuration:n=Fre,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=b.useRef(!0),l=b.useRef(!1),u=b.useRef(0);return b.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),g.jsx($re,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:b.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};CB.displayName=EB;var vf="Tooltip",[Hre,Uf]=Vv(vf),kB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=C1(vf,e.__scopeTooltip),d=Yv(t),[h,p]=b.useState(null),y=gi(),v=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,x=b.useRef(!1),[E,k]=ic({prop:r,defaultProp:i??!1,onChange:H=>{H?(u.onOpen(),document.dispatchEvent(new CustomEvent(z0))):u.onClose(),s==null||s(H)},caller:vf}),R=b.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),A=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,k(!0)},[k]),I=b.useCallback(()=>{window.clearTimeout(v.current),v.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,k(!0),v.current=0},w)},[w,k]);return b.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]),g.jsx(Iv,{...d,children:g.jsx(Hre,{scope:t,contentId:y,open:E,stateAttribute:R,trigger:h,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?I():(window.clearTimeout(v.current),v.current=0)},[I,_]),onOpen:A,onClose:I,disableHoverableContent:_,children:n})})};kB.displayName=vf;var B0="TooltipTrigger",TB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Uf(B0,n),s=C1(B0,n),o=Yv(n),l=b.useRef(null),u=Bn(t,l,i.onTriggerChange),d=b.useRef(!1),h=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),g.jsx(Bf,{asChild:!0,...o,children:g.jsx(Kt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:ft(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:ft(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:ft(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:ft(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:ft(e.onBlur,i.onClose),onClick:ft(e.onClick,i.onClose)})})});TB.displayName=B0;var k1="TooltipPortal",[Ure,Wre]=Vv(k1,{forceMount:void 0}),RB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Uf(k1,t);return g.jsx(Ure,{scope:t,forceMount:n,children:g.jsx(Ps,{present:n||s.open,children:g.jsx(sd,{asChild:!0,container:i,children:r})})})};RB.displayName=k1;var Vu="TooltipContent",AB=b.forwardRef((e,t)=>{const n=Wre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Uf(Vu,e.__scopeTooltip);return g.jsx(Ps,{present:r||o.open,children:o.disableHoverableContent?g.jsx(NB,{side:i,...s,ref:t}):g.jsx(qre,{side:i,...s,ref:t})})}),qre=b.forwardRef((e,t)=>{const n=Uf(Vu,e.__scopeTooltip),r=C1(Vu,e.__scopeTooltip),i=b.useRef(null),s=Bn(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=b.useCallback(()=>{l(null),p(!1)},[p]),v=b.useCallback((_,w)=>{const x=_.currentTarget,E={x:_.clientX,y:_.clientY},k=Gre(E,x.getBoundingClientRect()),R=Xre(E,k),A=Zre(w.getBoundingClientRect()),I=Jre([...R,...A]);l(I),p(!0)},[p]);return b.useEffect(()=>()=>y(),[y]),b.useEffect(()=>{if(u&&h){const _=x=>v(x,h),w=x=>v(x,u);return u.addEventListener("pointerleave",_),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),h.removeEventListener("pointerleave",w)}}},[u,h,v,y]),b.useEffect(()=>{if(o){const _=w=>{const x=w.target,E={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),R=!Qre(E,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,h,o,d,y]),g.jsx(NB,{...e,ref:s})}),[Vre,Yre]=Vv(vf,{isInside:!1}),Kre=TQ("TooltipContent"),NB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Uf(Vu,n),d=Yv(n),{onClose:h}=u;return b.useEffect(()=>(document.addEventListener(z0,h),()=>document.removeEventListener(z0,h)),[h]),b.useEffect(()=>{if(u.trigger){const p=y=>{const v=y.target;v!=null&&v.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),g.jsx(id,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:g.jsxs(zv,{"data-state":u.stateAttribute,...d,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[g.jsx(Kre,{children:r}),g.jsx(Vre,{scope:n,isInside:!0,children:g.jsx(iI,{id:u.contentId,role:"tooltip",children:i||r})})]})})});AB.displayName=Vu;var MB="TooltipArrow",OB=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Yv(n);return Yre(MB,n).isInside?null:g.jsx(Bv,{...i,...r,ref:t})});OB.displayName=MB;function Gre(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function Xre(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function Zre(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function Qre(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],u=t[o],d=l.x,h=l.y,p=u.x,y=u.y;h>r!=y>r&&n<(p-d)*(r-h)/(y-h)+d&&(i=!i)}return i}function Jre(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),eie(t)}function eie(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var tie=CB,nie=kB,rie=TB,iie=RB,sie=AB,oie=OB;function T1({...e}){return g.jsx(tre,{"data-slot":"popover",...e})}function R1({...e}){return g.jsx(nre,{"data-slot":"popover-trigger",...e})}function A1({className:e,align:t="center",sideOffset:n=4,...r}){return g.jsx(rre,{children:g.jsx(ire,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const aie={"no-proxy":{heading:"还没有连接开发机",body:"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。"},"client-token-missing":{heading:"需要 client token",body:"Relay 服务器已启用客户端访问控制。请在设置里填写。"},"client-token-invalid":{heading:"client token 无效",body:"当前浏览器保存的 client token 无效或已过期。请在设置里更新。"},"no-session":{heading:"没有选中的会话",body:""},"no-messages":{heading:"开始对话",body:""}};function ec({variant:e,action:t}){const{heading:n,body:r}=aie[e];return e==="no-messages"?g.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:g.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[g.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&g.jsx("div",{children:t})]})}const lie={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},cie={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function PN({status:e,className:t}){return g.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",lie[e],t),role:"status","aria-label":cie[e]})}function DB({layout:e,variant:t="default"}){const n=Oe(_=>_.proxies),r=Oe(_=>_.proxyListLoaded),i=Oe(_=>_.relayClientAuthIssue),s=Oe(_=>_.selectedProxyId),o=Oe(_=>_.proxySwitchTarget),l=Di(),u=Xs(),[d,h]=b.useState(!1);async function p(_,w){if(o)return;const x=Nt;if(!x){et.error("请先连接开发机");return}const E=w??_,k=s!==null&&s!==_;Oe.getState().setProxySwitchTarget({proxyId:_,name:E});try{const R=await x.selectProxy(_);if(!R.success){et.error(`无法连接 ${E}:${R.error??"未知错误"}`);return}k&&(It.getState().prepareForProxySwitch(E),ii.getState().prepareForProxySwitch()),fr("local",on.proxyId,_),Oe.getState().setProxy(_,w??null),Oe.getState().setProxyOnline(!0),Oe.getState().transitionToPhase("session_browsing"),x.sendControl({type:"session_list"}),x.requestProxyInfo().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const I=ii.getState();I.setHomePath(A.homePath),I.setAgentCli(A.agentCli)}).catch(A=>{console.error("[proxy-switcher] post-bind proxy info fetch failed",A)}),x.requestAgentStatuses().then(A=>{if(Oe.getState().selectedProxyId!==_)return;const I=It.getState();for(const T of A)I.setAgentStatus(T.sessionId,T.payload)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),x.requestSessionHistory().then(A=>{Oe.getState().selectedProxyId===_&&It.getState().setHistorySessions(A)}).catch(A=>{console.error("[proxy-switcher] post-bind data fetch failed",A)}),h(!1),(e==="page"||l.pathname.startsWith("/chat/"))&&u("/sessions")}catch(R){const A=R instanceof Error?R.message:"未知错误";et.error(`无法连接 ${E}:${A}`)}finally{Oe.getState().setProxySwitchTarget(null)}}if(e==="page")return i==="missing_client_token"?g.jsx(ec,{variant:"client-token-missing"}):i==="invalid_client_token"?g.jsx(ec,{variant:"client-token-invalid"}):r?n.length===0?g.jsx(ec,{variant:"no-proxy"}):g.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[g.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),g.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,x=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:Ye("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",w?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线,暂时无法连接",children:[g.jsx(PN,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),g.jsx(Ql,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===_.proxyId?g.jsx(ta,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})]}):g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[g.jsx(Ql,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"text-sm",children:"连接中..."})]});const y=n.find(_=>_.proxyId===s),v=(y==null?void 0:y.name)??(y==null?void 0:y.proxyId)??"未选择开发机";return g.jsxs(T1,{open:d,onOpenChange:h,children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${v}`,children:[t==="default"&&g.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),g.jsx("span",{className:Ye("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:v}),g.jsx(fl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),g.jsx(A1,{align:"start",className:"w-[260px] p-1",children:n.length===0?g.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):g.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(_=>{const w=(o==null?void 0:o.proxyId)===_.proxyId,x=o!==null;return g.jsx("li",{children:g.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":_.proxyId,"data-online":_.online,"data-selecting":w||void 0,disabled:!_.online||x,"aria-busy":w||void 0,onClick:()=>p(_.proxyId,_.name),className:Ye("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",w?"bg-accent text-accent-foreground":"hover:bg-accent",x&&!w?"opacity-50":"",_.online?"":"opacity-50"),"aria-pressed":s===_.proxyId,title:_.online?void 0:"这台开发机离线",children:[g.jsx(PN,{status:_.online?"online":"offline"}),g.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:_.name??_.proxyId}),w?g.jsx(Ql,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===_.proxyId?g.jsx(ta,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!_.online&&s!==_.proxyId&&!w&&g.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},_.proxyId)})})})]})}const LN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,IN=BP,uie=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return IN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(d=>{const h=n==null?void 0:n[d],p=s==null?void 0:s[d];if(h===null)return null;const y=LN(h)||LN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,h)=>{let[p,y]=h;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,h)=>{let{class:p,className:y,...v}=h;return Object.entries(v).every(_=>{let[w,x]=_;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return IN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},die=uie("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-normal whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function mt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?CQ:"button";return g.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(die({variant:t,size:n,className:e})),...i})}function hie({delayDuration:e=0,...t}){return g.jsx(tie,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Wf({...e}){return g.jsx(nie,{"data-slot":"tooltip",...e})}function qf({...e}){return g.jsx(rie,{"data-slot":"tooltip-trigger",...e})}function Vf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return g.jsx(iie,{children:g.jsxs(sie,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&g.jsx(oie,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Kv({...e}){return g.jsx(r1,{"data-slot":"sheet",...e})}function fie({...e}){return g.jsx(eee,{"data-slot":"sheet-trigger",...e})}function pie({...e}){return g.jsx(i1,{"data-slot":"sheet-portal",...e})}function mie({className:e,...t}){return g.jsx(s1,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Gv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return g.jsxs(pie,{children:[g.jsx(mie,{className:t}),g.jsxs(o1,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&g.jsxs(a1,{"data-slot":"sheet-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[g.jsx(Ju,{className:"size-4"}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function N1({className:e,...t}){return g.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function Xv({className:e,...t}){return g.jsx(OI,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function gie({className:e,...t}){return g.jsx(DI,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}function M1({...e}){return g.jsx(Ine,{"data-slot":"dropdown-menu",...e})}function O1({...e}){return g.jsx(zne,{"data-slot":"dropdown-menu-trigger",...e})}function D1({className:e,sideOffset:t=4,...n}){return g.jsx(Bne,{children:g.jsx(jne,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function go({className:e,inset:t,variant:n="default",...r}){return g.jsx($ne,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function G_({className:e,children:t,checked:n,...r}){return g.jsxs(Hne,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[g.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:g.jsx(Une,{children:g.jsx(ta,{className:"size-4"})})}),t]})}function Bm({className:e,inset:t,...n}){return g.jsx(Fne,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function X_({className:e,...t}){return g.jsx(Wne,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}const vie={claude:"Claude Code",codex:"Codex"},zN=["claude","codex"];function Zv(e){return vie[e]}function PB(e,t){return zN.indexOf(e)-zN.indexOf(t)}function j0(e){return e.provider??"claude"}const F0=60*1e3,$0=60*F0,yie=24*$0;function LB(e,t=Date.now()){const n=t-e;if(n<F0)return"刚刚";if(n<$0)return`${Math.floor(n/F0)} 分钟前`;if(n<yie)return`${Math.floor(n/$0)} 小时前`;const r=new Date(e),i=r.getMonth()+1,s=r.getDate(),o=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0");return`${i} 月 ${s} 日 ${o}:${l}`}const BN={idle:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"空闲"},working:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"工作中"},compacting:{dot:"bg-[var(--color-status-compacting)] animate-pulse",text:"text-[var(--color-status-compacting)]",label:"压缩中"},waiting_approval:{dot:"bg-[var(--color-status-warning)]",text:"text-[var(--color-status-warning)]",label:"等待审批"},error:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"出错"},terminated:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已终止"}};function H0(e){return e.kind!=="terminal"?BN[e.state]:e.state==="terminated"?BN.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function bie({session:e}){const t=H0(e);return g.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function _ie({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;return g.jsx("span",{className:"inline-flex h-5 w-4 shrink-0 items-center justify-center text-muted-foreground",role:"img","aria-label":t,title:t,"data-slot":"session-mode-icon","data-mode":e,children:g.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function wie({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=kv(e.name),d=Kx(e),h=e.nameLocked&&e.name?e.name:d||(u==="New Session"?e.sessionId.slice(0,8):u),p=!!e.mode||!!e.provider||o!==void 0,y=o!==void 0?LB(o,n):null,v=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":v?"断开远程连接":"终止会话";return g.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&g.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),g.jsxs("button",{type:"button",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[g.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[g.jsx(bie,{session:e}),g.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&g.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&g.jsx(_ie,{mode:e.mode}),e.mode&&g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Zv(e.provider)}),g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),g.jsx("span",{className:Ye("shrink-0",H0(e).text),children:H0(e).label}),y&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),g.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:g.jsx(mt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:g.jsx(f8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end","data-slot":"session-row-menu",children:[i&&g.jsx(go,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&g.jsx(go,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function _c({...e}){return g.jsx(r1,{"data-slot":"dialog",...e})}function Sie({...e}){return g.jsx(i1,{"data-slot":"dialog-portal",...e})}function xie({className:e,...t}){return g.jsx(s1,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function wc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return g.jsxs(Sie,{"data-slot":"dialog-portal",children:[g.jsx(xie,{}),g.jsxs(o1,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&g.jsxs(a1,{"data-slot":"dialog-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[g.jsx(Ju,{}),g.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Sc({className:e,...t}){return g.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return g.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&g.jsx(a1,{asChild:!0,children:g.jsx(mt,{variant:"outline",children:"Close"})})]})}function ll({className:e,...t}){return g.jsx(OI,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function cc({className:e,...t}){return g.jsx(DI,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function cl(e){const[t,n]=b.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return b.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function Eie({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=g.jsx(Cie,{title:e.title,modeTag:s}),l=g.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:LB(e.updatedAt,t)}),u=g.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return g.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:g.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,g.jsx(j9,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Cie({title:e,modeTag:t}){return g.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&g.jsx(kie,{mode:t})]})}function kie({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?Ax:Mx;return g.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:g.jsx(n,{className:"size-3","aria-hidden":"true"})})}function IB({providerLabel:e}){return g.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:g.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[g.jsx(m7,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),g.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Tie({now:e}){const t=It(F=>F.historySessions),[n,r]=b.useState(null),[i,s]=b.useState(null),[o,l]=b.useState("json"),[u,d]=b.useState("default"),[h,p]=b.useState(!1),[y,v]=b.useState(!1),[_,w]=b.useState(new Set),[x,E]=b.useState(new Set),k=Xs(),R=b.useMemo(()=>{const F=new Map;for(const O of t){const M=j0(O);let z=F.get(M);z||(z=new Map,F.set(M,z));const L=zB(O.projectDir),N=z.get(L);N?N.sessions.push(O):z.set(L,{dir:L,sessions:[O]})}return Array.from(F.entries()).sort(([O],[M])=>PB(O,M)).map(([O,M])=>({provider:O,sessions:Array.from(M.values()).flatMap(z=>z.sessions),projects:Array.from(M.values()).map(z=>({dir:z.dir,shortDir:kv(z.dir),sessions:z.sessions}))}))},[t]);function A(F){s(F),l(Rie(F)),d("default")}async function I(F,O,M){if(n)return;const z=Nt;if(!z){et.error("请先连接开发机");return}r(F.id);const L=j0(F);try{const N=await z.createSession({cwd:F.projectDir,mode:O,provider:L,resumeSessionId:F.id,...M?{permissionMode:M}:{}});if(N.error||!N.sessionId){et.error(`恢复失败:${N.error??"未知错误"}`);return}const q={sessionId:N.sessionId,state:"idle",mode:N.mode??O,provider:N.provider??"claude"};It.getState().addSession(q),k(`/chat/${N.sessionId}?mode=${N.mode??O}`),s(null)}catch(N){et.error(`恢复失败:${N instanceof Error?N.message:String(N)}`)}finally{r(null)}}function T(){const F=Nt;!F||h||(p(!0),F.requestSessionHistory().then(O=>It.getState().setHistorySessions(O)).catch(O=>{et.error(O instanceof Error?O.message:String(O))}).finally(()=>{p(!1)}))}function H(F,O){const M=jN(F,O);E(z=>{const L=new Set(z);return L.has(M)?L.delete(M):L.add(M),L})}function D(F){w(O=>{const M=new Set(O);return M.has(F)?M.delete(F):M.add(F),M})}const W=t.length>0,U=i?BB():[];return g.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[g.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[g.jsxs("button",{type:"button",onClick:()=>W&&v(F=>!F),disabled:!W,"aria-expanded":W?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[g.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",W?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),W?g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:T,disabled:h,"data-slot":"history-refresh",children:g.jsx(Nx,{className:Ye("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!W&&g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),W&&y&&g.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(F=>{const O=_.has(F.provider);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>D(F.provider),"aria-expanded":!O,"data-slot":"history-provider-header","data-expanded":!O,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:Zv(F.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:F.sessions.length}),g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!O&&"rotate-90"),"aria-hidden":"true"})]}),!O&&g.jsx("ul",{role:"list",className:"flex flex-col",children:F.projects.map(M=>{const z=jN(F.provider,M.dir),L=x.has(z);return g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>H(F.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),g.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&g.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(N=>g.jsx(Eie,{session:N,now:e,disabled:n!==null,loading:n===N.id,onClick:()=>A(N),modeTag:N.preferredMode},N.id))})]},z)})})]},F.provider)})}),g.jsx(Aie,{session:i,open:i!==null,modes:U,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:F=>{F||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&I(i,o,u)}})]})}function jN(e,t){return`${e}:${zB(t)}`}function zB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function BB(){return["json","pty"]}function Rie(e){const t=BB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Aie({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=b.useState(!1),y=i==="bypassPermissions",v=cl("(min-width: 768px)");b.useEffect(()=>{t||p(!1)},[t]);const _=h?g.jsx(IB,{providerLabel:e?Zv(j0(e)):"Agent"}):g.jsxs("div",{className:"grid min-w-0 gap-4",children:[g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&g.jsx(FN,{checked:r==="json",label:"聊天",icon:g.jsx(Ax,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&g.jsx(FN,{checked:r==="pty",label:"终端",icon:g.jsx(Mx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),g.jsxs("div",{className:"grid min-w-0 gap-2",children:[g.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),g.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[g.jsx(Z_,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),g.jsx(Z_,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),g.jsx(Z_,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=g.jsxs(g.Fragment,{children:[g.jsx(mt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),g.jsx(mt,{type:"button",variant:h?"destructive":"default",disabled:s,onClick:()=>{if(y&&!h){p(!0);return}d()},"data-slot":h?"bypass-permission-confirm":void 0,children:s?"恢复中...":h?"确认":"恢复"})]});return v?g.jsx(_c,{open:t,onOpenChange:o,children:g.jsxs(wc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[g.jsxs(Sc,{className:"min-w-0",children:[g.jsx(ll,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(cc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),_,g.jsx(Yu,{children:w})]})}):g.jsx(Kv,{open:t,onOpenChange:o,children:g.jsxs(Gv,{side:"bottom",focusSurfaceOnOpen:!0,className:"inset-x-2 w-auto max-h-[calc(100dvh-0.75rem)] min-w-0 overflow-hidden rounded-t-xl border bg-background p-0","data-slot":"history-restore-dialog",children:[g.jsxs(N1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[g.jsx(Xv,{children:h?"跳过全部审批?":"恢复会话"}),g.jsx(gie,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),g.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:_}),g.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:g.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function FN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,g.jsx("span",{className:"min-w-0 text-center",children:t}),g.jsx(ta,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Z_({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return g.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[g.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&g.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),g.jsxs("span",{className:"grid min-w-0 gap-1",children:[g.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),g.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&g.jsx(ta,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Nie({...e}){return g.jsx(Rre,{"data-slot":"select",...e})}function Mie({...e}){return g.jsx(Nre,{"data-slot":"select-value",...e})}function Oie({className:e,size:t="default",children:n,...r}){return g.jsxs(Are,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,g.jsx(Mre,{asChild:!0,children:g.jsx(fl,{className:"size-4 opacity-50"})})]})}function Die({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return g.jsx(Ore,{children:g.jsxs(Dre,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[g.jsx(Lie,{}),g.jsx(Pre,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),g.jsx(Iie,{})]})})}function Pie({className:e,children:t,...n}){return g.jsxs(Lre,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[g.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(zre,{children:g.jsx(ta,{className:"size-4"})})}),g.jsx(Ire,{children:t})]})}function Lie({className:e,...t}){return g.jsx(Bre,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(Rx,{className:"size-4"})})}function Iie({className:e,...t}){return g.jsx(jre,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:g.jsx(fl,{className:"size-4"})})}function P1(e){return!e||e.endsWith("/")?e:`${e}/`}function zie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function Bie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function jie(e,t,n){var o;if(t==="insert")return{currentPath:Bie(e)||"./",query:zie(e)};if(!e)return{currentPath:"./",query:""};const r=e.replace(/\/+$/,"")||"/";if(e.endsWith("/")||r===(n==null?void 0:n.baseCwd)||((o=n==null?void 0:n.knownDirs)==null?void 0:o.has(r)))return{currentPath:P1(r),query:""};const s=e.lastIndexOf("/");return{currentPath:s>=0?e.slice(0,s+1):"./",query:s>=0?e.slice(s+1).toLowerCase():e.toLowerCase()}}function Fie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function $ie(e,t){return`${P1(e)}${t.name}${t.isDir?"/":""}`}function $N(e,t){const n=e.trim().replace(/\/+$/,"")||"/",r=t.trim().replace(/^\/+|\/+$/g,"");return!n.startsWith("/")||!r||t.trim().startsWith("/")||r.split("/").some(i=>i===""||i==="."||i==="..")?null:n==="/"?`/${r}`:`${n}/${r}`}const jB=b.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=ii($=>$.tree),h=ii($=>$.cwd),p=ii($=>$.homePath),y=i==="insert"?h:p||h,v=b.useMemo(()=>new Set(d.keys()),[d]),_=b.useMemo(()=>jie(t,i,{baseCwd:y,knownDirs:v}),[t,i,y,v]),w=_.currentPath,x=b.useMemo(()=>Fie(y,w),[y,w]),E=_.query,k=b.useRef(new Set),[R,A]=b.useState(!1),[I,T]=b.useState(""),[H,D]=b.useState(!1);b.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const $=Nt;if(!$)return;let P=!1;return k.current.add(x),$.requestDirectoryList(x).then(V=>{P||ii.getState().setDirEntries(V.path,V.entries)}).catch(()=>{P||ii.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{P=!0}},[x,d]);const W=!d.has(x),U=b.useMemo(()=>{let $=d.get(x)??[];return o&&($=$.filter(P=>P.isDir)),E&&($=$.filter(P=>P.name.toLowerCase().includes(E))),$},[d,x,E,o]),[F,O]=b.useState(0);b.useEffect(()=>O(0),[w,E]),b.useEffect(()=>{A(!1),T("")},[x]),b.useEffect(()=>{F>=U.length&&U.length>0&&O(U.length-1)},[U.length,F]);const M=b.useRef(null),z=b.useRef(!1);b.useEffect(()=>{var P;if(!z.current)return;z.current=!1;const $=(P=M.current)==null?void 0:P.querySelector(`[data-entry-index="${F}"]`);$==null||$.scrollIntoView({block:"nearest"})},[F]);const L=b.useCallback($=>{const P=$ie(w,$);return i==="insert"?P.replace(/^\.\//,""):P},[w,i]);async function N(){const $=$N(x,I);if(!(!$||!r)){D(!0);try{const P=await r($);if(!P)return;T(""),A(!1),n(P1(P))}finally{D(!1)}}}b.useImperativeHandle(u,()=>({handleKey($){return U.length===0?!1:$.key==="ArrowDown"?(z.current=!0,O(P=>Math.min(U.length-1,P+1)),!0):$.key==="ArrowUp"?(z.current=!0,O(P=>Math.max(0,P-1)),!0):$.key==="Enter"&&!$.nativeEvent.isComposing?(n(L(U[F])),!0):!1}}),[U,F,L,n]);const q=s==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":i==="insert"?"absolute bottom-full left-0 right-0 z-50 mb-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden":"absolute left-0 right-0 top-full z-50 mt-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden",Y=s==="inline"?"h-44 overflow-y-auto overscroll-contain":i==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return g.jsxs("div",{className:q,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?g.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?g.jsx("button",{type:"button",className:"rounded px-2 py-1 text-xs text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",disabled:!x||H,onClick:()=>A($=>!$),children:"新建目录"}):null]}),R?g.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[g.jsx("input",{type:"text",value:I,onChange:$=>T($.target.value),onKeyDown:$=>{$.key==="Enter"&&!$.nativeEvent.isComposing&&($.preventDefault(),N()),$.key==="Escape"&&(A(!1),T(""))},placeholder:"目录名称",className:"min-h-11 min-w-0 flex-1 rounded-md border border-border bg-input px-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-8 md:min-h-0 md:text-sm",autoComplete:"off",autoCorrect:"off",spellCheck:!1}),g.jsx("button",{type:"button",className:"min-h-11 rounded-md bg-primary px-3 text-sm text-primary-foreground disabled:cursor-not-allowed disabled:opacity-50 md:h-8 md:min-h-0",disabled:!$N(x,I)||H,onClick:()=>void N(),children:H?"创建中...":"创建目录"})]}):null]}):null,g.jsx("div",{className:Y,children:U.length===0?g.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:W?"加载中...":"没有匹配的路径"}):g.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:U.map(($,P)=>g.jsx("li",{children:g.jsx("button",{type:"button",onClick:()=>n(L($)),onMouseEnter:()=>O(P),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",P===F&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",$.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":$.isDir?"dir":"file","data-entry-index":P,children:g.jsxs("span",{className:"font-mono text-[13px]",children:[$.name,$.isDir?"/":""]})})},$.name))})})]})}),HN="工作目录不存在或不可访问:",Hie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],FB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],ea={claude:"Claude Code",codex:"Codex"};function Uie(e,t){return t!==Zr.PATH_NOT_FOUND||!e.startsWith(HN)?null:e.slice(HN.length).trim()||null}function Xg(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function Wie(e,t){return t.title?t.disabled?`${ea[e]}:${t.title}`:`${ea[e]} 路径:${t.title}`:`${ea[e]}:${t.label}`}function qie(e,t){return e!=="codex"||FB.some(n=>n.value===t)?t:"default"}async function Vie({relay:e,agentCli:t,form:n,timeoutMs:r=Vx}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Xg(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${ea[n.provider]} 不可用:${p}`:`${ea[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=Uie(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,v=((h=p.name)==null?void 0:h.trim())||void 0;return{type:"success",session:{sessionId:p.sessionId,...p.kind!==void 0?{kind:p.kind}:{},name:v,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",mode:y,provider:p.provider??l,...p.ptyOwner!==void 0?{ptyOwner:p.ptyOwner}:{}},route:`/chat/${p.sessionId}?mode=${y}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function Yie({relay:e,timeoutMs:t=Vx}){var n;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const r=await e.createSession({kind:"terminal",mode:"pty"},t);return r.error||!r.sessionId?{type:"create_error",message:`创建终端失败:${r.error??"未知错误"}`}:{type:"success",session:{sessionId:r.sessionId,kind:"terminal",name:((n=r.name)==null?void 0:n.trim())||void 0,...r.nameLocked!==void 0?{nameLocked:r.nameLocked}:{},state:"idle",mode:"pty",provider:r.provider??"claude",...r.ptyOwner!==void 0?{ptyOwner:r.ptyOwner}:{}},route:`/chat/${r.sessionId}?mode=pty`}}catch(r){return{type:"exception",message:r instanceof Error?r.message:String(r)}}}function Kie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Xg("claude",e),y=Xg("codex",e),v=e==null?void 0:e[t];return g.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[g.jsxs("div",{className:"flex items-center justify-between",children:[g.jsx("span",{className:"text-sm",children:"Agent CLI"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsx(UN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),g.jsx(UN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),g.jsx("div",{className:"relative min-w-0 rounded-md border border-border bg-muted/20 px-3 py-2.5 md:p-3","data-slot":"agent-cli-path-card",children:r===t?g.jsx(Gie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):g.jsx(Xie,{provider:t,selectedCli:v,isDesktop:n,onOpenCliPathEditor:l})})]})}function UN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return g.jsxs(Wf,{children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-pressed":t,"aria-label":ea[e],onClick:i,className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:ea[e]}),g.jsx("span",{className:Ye("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),g.jsx(Vf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:g.jsx("span",{className:"break-all font-mono text-xs",children:Wie(e,n)})})]})}function Gie({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[g.jsxs("label",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:"sr-only",children:"CLI 路径"}),g.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),o()),l.key==="Escape"&&(l.preventDefault(),s())},placeholder:e==="claude"?"/home/dev/.local/bin/claude":"/home/dev/.local/bin/codex",className:"min-h-11 w-full rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-10 md:min-h-0 md:text-sm"}),g.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>g.jsx("option",{value:l},l))})]}),g.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[g.jsx(mt,{type:"button",variant:"ghost",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground md:h-8 md:min-h-0",onClick:s,disabled:r,children:"取消"}),g.jsx(mt,{type:"button",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium md:h-8 md:min-h-0",onClick:o,disabled:r||!n.trim(),children:r?"保存中...":"保存路径"})]})]})]})}function Xie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[g.jsx("p",{className:Ye("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),g.jsx(mt,{type:"button",variant:"outline",className:"h-8 min-h-0 shrink-0 self-end rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground sm:self-auto",onClick:()=>r(e),children:"指定路径"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 size-11 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/70 hover:text-foreground","aria-label":"指定路径",onClick:()=>r(e),children:g.jsx(W8,{className:"size-4","aria-hidden":"true"})}),g.jsx("p",{className:Ye("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function Bh({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[h,p]=b.useState("default"),[y,v]=b.useState(!1),[_,w]=b.useState(!1),[x,E]=b.useState(null),[k,R]=b.useState(!1),[A,I]=b.useState(null),[T,H]=b.useState(""),[D,W]=b.useState(!1),U=b.useRef(null),F=b.useRef(e);F.current=e;const O=Xs(),M=ii(Re=>Re.homePath),z=ii(Re=>Re.agentCli),L=cl("(min-width: 768px)");b.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),b.useEffect(()=>{if(!e||M&&z)return;const Re=Nt==null?void 0:Nt.requestProxyInfo();Re&&Re.then(Ae=>{const He=ii.getState();He.setHomePath(Ae.homePath),He.setAgentCli(Ae.agentCli)}).catch(Ae=>{console.error("[create-session-dialog] requestProxyInfo failed",Ae)})},[e,M,z]),b.useEffect(()=>{if(!k)return;function Re(Ae){var qe;const He=Ae.target;He instanceof Node&&((qe=U.current)!=null&&qe.contains(He))||window.setTimeout(()=>R(!1),0)}return document.addEventListener("pointerdown",Re,!0),()=>document.removeEventListener("pointerdown",Re,!0)},[k]);function N(){r(""),s(""),R(!1),l("claude"),d("pty"),p("default"),v(!1),E(null),I(null),H(""),W(!1)}function q(){if(h==="bypassPermissions"){v(!0);return}B()}async function Y(){await B(),F.current&&v(!1)}const $=o==="codex"?FB:Hie,P=Xg(o,z),V=_||D||P.disabled;function G(Re){const Ae=qie(Re,h);Ae!==h&&p(Ae)}async function B(Re){E(null),w(!0);try{const Ae=await Vie({relay:Nt,agentCli:z,form:{cwd:Re??i,name:n,provider:o,permissionMode:h,mode:u}});if(Ae.type==="success"){if(It.getState().addSession(Ae.session),!F.current)return;t(!1),N(),O(Ae.route);return}if(Ae.type==="missing_cwd"&&E(Ae.path),et.error(Ae.message),Ae.type==="validation_error"||Ae.type==="relay_missing")return}finally{w(!1)}}async function K(Re){const Ae=Nt;if(!Ae)return et.error("请先连接开发机"),null;try{const He=await Ae.createDirectory(Re);return He.success?(s(He.path),E(null),et.success("目录已创建"),He.path):(et.error(`目录创建失败:${He.error??"未知错误"}`),null)}catch(He){return et.error(He instanceof Error?He.message:String(He)),null}}function ee(Re){var He;const Ae=z==null?void 0:z[Re];I(Re),H((Ae==null?void 0:Ae.command)??((He=Ae==null?void 0:Ae.suggestions)==null?void 0:He[0])??"")}async function te(){if(!A)return;const Re=T.trim();if(!Re){et.error("请输入 Agent CLI 路径");return}const Ae=Nt;if(!Ae){et.error("请先连接开发机");return}W(!0);try{const He=await Ae.updateAgentCliPath(A,Re);if(He.error||!He.agentCli){et.error(`路径保存失败:${He.error??"未知错误"}`);return}ii.getState().setAgentCli(He.agentCli),et.success(`${ea[A]} 路径已保存`),I(null),H("")}catch(He){et.error(He instanceof Error?He.message:String(He))}finally{W(!1)}}function J(Re){d(Re),G(o)}function me(Re){var He;const Ae=Re.relatedTarget;Ae instanceof Node&&((He=U.current)!=null&&He.contains(Ae))||window.setTimeout(()=>R(!1),0)}const Se=y?g.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[g.jsx(IB,{providerLabel:ea[o]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>v(!1),disabled:_,children:"返回"}),g.jsx(mt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void Y(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):g.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Re=>{Re.preventDefault(),q()},children:[g.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[g.jsx("span",{className:"text-sm",children:"名称(可选)"}),g.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Re=>r(Re.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),g.jsxs("div",{ref:U,className:"relative flex min-w-0 flex-col gap-2",onBlur:me,children:[g.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),g.jsx("input",{id:"create-session-cwd",type:"text","aria-labelledby":"create-session-cwd-label",name:"dev-anywhere-session-cwd",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:i,onFocus:()=>R(!0),onChange:Re=>{s(Re.target.value),E(null)},placeholder:"输入绝对路径",className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm"}),k?g.jsx(jB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:K,onSelect:Re=>{s(Re),E(null),R(!0)}}):null]}),x?g.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[g.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),g.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:x})]}):null,g.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"交互方式"}),g.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[g.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>J("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),g.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>J("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[g.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),g.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),g.jsx(Kie,{agentCli:z,provider:o,isDesktop:L,editingCliProvider:A,cliPathInput:T,savingCliPath:D,onProviderChange:Re=>{l(Re),G(Re)},onOpenCliPathEditor:ee,onCliPathInputChange:H,onCancelCliPathEditor:()=>{I(null),H("")},onSaveCliPath:()=>void te()}),g.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[g.jsx("span",{className:"text-sm",children:"权限模式"}),g.jsxs(Nie,{value:h,onValueChange:Re=>p(Re),children:[g.jsx(Oie,{className:"w-full",children:g.jsx(Mie,{})}),g.jsx(Die,{children:$.map(Re=>g.jsx(Pie,{value:Re.value,children:Re.label},Re.value))})]})]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),g.jsx(mt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:V,children:_?"创建中...":"创建"})]})]});return L?g.jsx(_c,{open:e,onOpenChange:t,children:g.jsxs(wc,{className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[44rem]","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[g.jsx(Sc,{children:g.jsx(ll,{children:y?"跳过全部审批?":"新建会话"})}),Se]})}):g.jsx(Kv,{open:e,onOpenChange:t,children:g.jsxs(Gv,{side:"bottom",className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto overflow-x-hidden overflow-y-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[g.jsx(N1,{className:"px-0 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:y?"跳过全部审批?":"新建会话"})}),Se]})})}function jh({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=b.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=b.useState(s),[u,d]=b.useState(null),[h,p]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(v){v.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return g.jsx(_c,{open:e,onOpenChange:r,children:g.jsx(wc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:g.jsxs("form",{className:"grid gap-4",onSubmit:v=>void y(v),children:[g.jsxs(Sc,{children:[g.jsx(ll,{children:"重命名会话"}),g.jsx(cc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),g.jsxs("div",{className:"grid gap-2",children:[g.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),g.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:v=>{l(v.target.value),u&&d(null)}}),u?g.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),g.jsx(mt,{type:"submit",disabled:h,children:"保存"})]})]})})})}function Zie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function Qie(e){return(e==null?void 0:e.kind)==="terminal"}function Jie(e){return Zie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Qie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function jm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Jie(t);function s(){t&&(r(t),n(!1))}return g.jsx(_c,{open:e,onOpenChange:n,children:g.jsxs(wc,{"data-slot":"session-termination-dialog",children:[g.jsxs(Sc,{children:[g.jsx(ll,{children:i.title}),g.jsx(cc,{children:i.description})]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),g.jsx(mt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function $B(e){var t,n,r,i,s,o,l,u,d,h,p,y;return e.connected===!1||e.proxyOnline===!1?"disconnected":e.routeSessionEnded||((t=e.session)==null?void 0:t.state)==="terminated"?"terminated":((n=e.session)==null?void 0:n.state)==="error"?"error":e.hasPendingApproval||((r=e.session)==null?void 0:r.state)==="waiting_approval"?"waiting_approval":((i=e.session)==null?void 0:i.state)==="compacting"?"compacting":((s=e.session)==null?void 0:s.state)==="working"?"working":((o=e.session)==null?void 0:o.state)==="idle"?"idle":((l=e.agentStatus)==null?void 0:l.phase)==="waiting_permission"||((u=e.ptyState)==null?void 0:u.state)==="approval_wait"?"waiting_approval":((d=e.agentStatus)==null?void 0:d.phase)==="thinking"||((h=e.agentStatus)==null?void 0:h.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function ese(e){if(e.session.state==="error")return"error";const t=$B(e);return t==="disconnected"?e.session.state:t}function HB({layout:e}){const t=It(K=>K.sessions),n=It(K=>K.sessionListLoaded),r=It(K=>K.agentStatusBySessionId),i=It(K=>K.ptyStateBySessionId),s=It(K=>K.renameSession),o=Vt(K=>K.bySessionId),l=mU("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Oe(K=>!!K.selectedProxyId),h=Oe(K=>K.proxyListLoaded),p=Oe(K=>K.proxySwitchTarget),y=It(K=>K.loadingProxyName),v=p!==null||!h||d&&!n,_=(p==null?void 0:p.name)??y,w=_?`正在连接 ${_}...`:"连接中...",x=Xs(),[E,k]=b.useState(!1),[R,A]=b.useState(!1),[I,T]=b.useState(null),[H,D]=b.useState(null),{creatingTerminal:W,createTerminal:U}=UB(),[F,O]=b.useState(new Set),[M,z]=b.useState(()=>Date.now());b.useEffect(()=>{const K=setInterval(()=>z(Date.now()),6e4);return()=>clearInterval(K)},[]);function L(K,ee){x(`/chat/${K}?mode=${ee??"json"}`,{replace:!1})}function N(K){const ee=K.sessionId,te=Nt;if(!te){et.error("请先连接开发机");return}te.sendControl({type:"session_terminate",sessionId:ee}),It.getState().removeSession(ee),Vt.getState().clearSession(ee),ee===u&&x("/sessions"),(K==null?void 0:K.mode)==="pty"&&K.ptyOwner==="local-terminal"?et.info("已断开页面连接,本地终端仍在运行"):et.info("正在终止会话",{duration:1500})}async function q(K,ee){const te=Nt;if(!te)throw new Error("请先连接开发机");const J=await te.renameSession(K,ee);if(!J.success)throw new Error(J.error??"重命名失败");s(K,J.name??ee),et.success("已重命名会话")}function Y(K){O(ee=>{const te=new Set(ee);return te.has(K)?te.delete(K):te.add(K),te})}function $(K){var J;const ee=K.mode==="json"&&(((J=o[K.sessionId])==null?void 0:J.pendingApprovals.some(me=>me.status==="pending"))??!1),te=ese({session:K,agentStatus:r[K.sessionId],ptyState:i[K.sessionId],hasPendingApproval:ee});return te===K.state?K:{...K,state:te}}const P=t.length>0;if(e==="sidebar"&&(v||!d))return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":v?"session-list-loading":void 0,role:v?"status":void 0,"aria-live":v?"polite":void 0,children:v?w:"请先连接开发机"}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]});if(e==="page"&&v)return g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[g.jsx(Ql,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),g.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsx("div",{className:"flex-1",children:g.jsx(ec,{variant:"no-proxy"})}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]});const V=g.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",P?g.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),G=P?g.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:tse(t).map(K=>g.jsxs("li",{children:[g.jsxs("button",{type:"button",onClick:()=>Y(K.provider),"aria-expanded":!F.has(K.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[g.jsx("span",{className:"font-mono",children:nse(K.provider)}),g.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),g.jsx("span",{className:"tabular-nums",children:K.sessions.length}),g.jsx(Xh,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!F.has(K.provider)&&"rotate-90"),"aria-hidden":"true"})]}),F.has(K.provider)?null:g.jsx("ul",{role:"list",className:"flex flex-col",children:K.sessions.map(ee=>g.jsx(wie,{session:$(ee),selected:ee.sessionId===u,now:M,onClick:()=>L(ee.sessionId,ee.mode),onRename:()=>T(ee),onTerminate:()=>D(ee)},ee.sessionId))})]},K.provider))}):g.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),B=g.jsx(Tie,{now:M});return e==="page"?g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[V,G,B]}),g.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:g.jsxs(mt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[g.jsx(TP,{"aria-hidden":"true"}),"新建"]})}),g.jsx(ise,{open:R,creatingTerminal:W,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>void U(()=>A(!1))}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[V,G,B]}),g.jsx(Bh,{open:E,onOpenChange:k}),g.jsx(jm,{open:H!==null,session:H,onOpenChange:K=>{K||D(null)},onConfirm:N}),g.jsx(jh,{open:I!==null,sessionId:(I==null?void 0:I.sessionId)??null,initialName:I==null?void 0:I.name,onOpenChange:K=>{K||T(null)},onRename:q})]})}function tse(e){const t=new Map;for(const n of e){const r=n.kind==="terminal"?"terminal":n.provider,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t.entries()).sort(([n],[r])=>rse(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function nse(e){return e==="terminal"?"终端":Zv(e)}function rse(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:PB(e,t)}function UB(){const e=Xs(),[t,n]=b.useState(!1);async function r(i){if(!t){n(!0);try{const s=await Yie({relay:Nt});if(s.type!=="success"){et.error(s.message);return}It.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function WN({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),s=b.useRef(!1),o=Oe(E=>!!E.selectedProxyId),l=Oe(E=>E.proxySwitchTarget!==null),u=o&&!l,{creatingTerminal:d,createTerminal:h}=UB();function p(){i(!0),window.setTimeout(()=>i(!1),2e3)}function y(){if(!u){p();return}s.current=!0,n(!0)}function v(){if(!u){p();return}s.current=!0,h()}function _(E){E.preventDefault(),p()}const w=g.jsxs(mt,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!u&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!u,onClick:u?void 0:_,children:[g.jsx(TP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate",children:"新建"})]}),x=u?g.jsxs(M1,{children:[g.jsx(O1,{asChild:!0,children:w}),g.jsxs(D1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:E=>{s.current&&(s.current=!1,E.preventDefault())},children:[g.jsxs(go,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:y,children:[g.jsx(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(go,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:d,onSelect:v,children:[g.jsx(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"正在创建终端会话...":"终端会话"]})]})]}):w;return g.jsxs(g.Fragment,{children:[u?x:g.jsxs(Wf,{open:u?void 0:r,onOpenChange:u?void 0:i,children:[g.jsx(qf,{asChild:!0,children:x}),g.jsx(Vf,{side:"top",children:l?"正在切换开发机":"请先连接开发机"})]}),g.jsx(Bh,{open:t,onOpenChange:n})]})}function ise({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=b.useRef(!1);function o(l){s.current=!0,l()}return g.jsx(Kv,{open:e,onOpenChange:n,children:g.jsxs(Gv,{side:"bottom",overlayClassName:"bg-black/10 dark:bg-black/30",className:"inset-x-2 w-auto rounded-t-xl border border-border/80 bg-background px-3 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3 shadow-2xl","data-slot":"create-session-type-sheet",focusSurfaceOnOpen:!0,onCloseAutoFocus:l=>{s.current&&(s.current=!1,l.preventDefault())},children:[g.jsx(N1,{className:"px-1 pb-1 pt-0 text-left",children:g.jsx(Xv,{children:"新建"})}),g.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[g.jsxs(mt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-agent-session-sheet-item",onClick:()=>o(r),children:[g.jsx(kP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),g.jsxs(mt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-terminal-session-sheet-item",disabled:t,onClick:()=>o(i),children:[g.jsx(lf,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const sse="0.5.18",ose={version:sse},ase={playback:"playback",capture:"play-and-record"};function lse(){return typeof navigator>"u"?null:navigator.audioSession??null}function cse(){return{setMode:()=>{},release:()=>{}}}class use{constructor(t=lse){ht(this,"leases",new Map);ht(this,"session",null);ht(this,"baselineType",null);ht(this,"nextLeaseId",1);ht(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return cse();this.leases.size===0&&(this.session=n,this.baselineType=n.type);const r=this.nextLeaseId++;this.leases.set(r,{mode:t,order:this.nextOrder++});try{this.applyActiveMode()}catch(s){throw this.leases.delete(r),this.leases.size===0?this.restoreWhenUnused():this.applyActiveModeBestEffort(),s}let i=!1;return{setMode:s=>{if(i)return;const o=this.leases.get(r);if(!o)return;const l={...o};o.mode=s,o.order=this.nextOrder++;try{this.applyActiveMode()}catch(u){throw this.leases.set(r,l),this.applyActiveModeBestEffort(),u}},release:()=>{if(!i){if(i=!0,this.leases.delete(r),this.leases.size===0){this.restoreWhenUnused();return}this.applyActiveModeBestEffort()}}}}applyActiveMode(){const t=[...this.leases.values()].reduce((n,r)=>!n||r.order>n.order?r:n,null);!t||!this.session||this.setNativeType(ase[t.mode])}applyActiveModeBestEffort(){try{this.applyActiveMode()}catch{}}restoreWhenUnused(){const t=this.session,n=this.baselineType;if(this.session=null,this.baselineType=null,!(!t||n===null))try{t.type=n}catch{}}setNativeType(t){if(!(!this.session||this.session.type===t)){try{this.session.type=t}catch{throw new Error("浏览器无法切换语音音频模式")}if(this.session.type!==t)throw new Error("浏览器无法切换语音音频模式")}}}const L1=new use,U0=64,qN=-60,WB=32;function VN(e){if(!Number.isFinite(e)||e===0)return 0;const t=Math.min(1,Math.abs(e)),n=20*Math.log10(t),r=Math.max(0,Math.min(1,(n-qN)/-qN));return e<0?-r:r}function YN(e,t=8){const n=Math.floor(e.byteLength/2);if(n===0||!Number.isFinite(t)||t<=0)return[];const r=Math.min(n,Math.max(1,Math.floor(t))),i=new DataView(e.buffer,e.byteOffset,e.byteLength),s=[];for(let o=0;o<r;o+=1){const l=Math.floor(o*n/r),u=Math.max(l+1,Math.floor((o+1)*n/r));let d=1,h=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),h=Math.max(h,y)}s.push({min:d,max:h})}return s}function dse(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=Math.floor(e.byteLength/2),r=new Float32Array(n);for(let i=0;i<n;i+=1)r[i]=t.getInt16(i*2,!0)/32768;return r}function hse(e){if(e.length===0)return 0;const t=Math.max(1,Math.floor(e.length/512));let n=0,r=0;for(let i=0;i<e.length;i+=t){const s=e[i]??0;n+=s*s,r+=1}return r===0?0:Math.min(1,Math.sqrt(n/r)*10)}class qB{constructor(t,n=24e3,r={}){ht(this,"nextStartTime",0);ht(this,"activityEndToken",0);ht(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=dse(t),r=this.context.createBuffer(1,n.length,this.sampleRate);r.getChannelData(0).set(n);const i=this.context.createBufferSource();i.buffer=r,i.connect(this.context.destination);const s=Math.max(this.context.currentTime,this.nextStartTime);i.start(s);const o=s+r.duration;this.nextStartTime=o,this.schedulePlaybackFrames(t,n,s,o);const l=Math.max(0,(o-this.context.currentTime)*1e3);return this.emitPlaybackEvent("pcm-scheduled",{bytes:t.byteLength,durationMs:r.duration*1e3}),typeof i.addEventListener=="function"&&i.addEventListener("ended",()=>{this.emitPlaybackEvent("source-ended",{bytes:t.byteLength,durationMs:r.duration*1e3})},{once:!0}),l}stop(){var t,n;this.nextStartTime=this.context.currentTime,this.activityEndToken+=1;for(const r of this.timelineTimers)clearTimeout(r);this.timelineTimers.clear(),(n=(t=this.options).onActivityLevel)==null||n.call(t,0),this.emitPlaybackEvent("stopped")}snapshot(){const t=this.context.currentTime;return{contextState:String(this.context.state??"unknown"),contextTime:t,nextStartTime:this.nextStartTime,queuedMs:Math.max(0,(this.nextStartTime-t)*1e3)}}schedulePlaybackFrames(t,n,r,i){if(!this.options.onActivityLevel&&!this.options.onPlaybackChunk)return;const s=Math.max(1,Math.round(this.sampleRate*WB/1e3)),o=this.activityEndToken+=1;for(let l=0;l<n.length;l+=s){const u=Math.min(n.length,l+s),d=r+l/this.sampleRate,h=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),y=hse(n.subarray(l,u));this.scheduleTimer(()=>{var v,_,w,x;(_=(v=this.options).onActivityLevel)==null||_.call(v,y),(x=(w=this.options).onPlaybackChunk)==null||x.call(w,p)},h)}if(this.options.onActivityLevel){const l=Math.max(0,(i-this.context.currentTime)*1e3);this.scheduleTimer(()=>{var u,d;o===this.activityEndToken&&((d=(u=this.options).onActivityLevel)==null||d.call(u,0))},l)}}scheduleTimer(t,n){const r=setTimeout(()=>{this.timelineTimers.delete(r),t()},n);this.timelineTimers.add(r)}emitPlaybackEvent(t,n={}){var r,i;(i=(r=this.options).onPlaybackEvent)==null||i.call(r,{event:t,...this.snapshot(),...n})}}const Q_={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},KN="min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none transition-colors placeholder:text-muted-foreground/65 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",fse=800,GN=300,pse=1600;function W0(e,t){return e.filter(n=>!n.model||n.model===t)}function XN({label:e,children:t,help:n}){return g.jsxs("div",{className:"block min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 transition-colors focus-within:border-ring/55 focus-within:bg-card/75 sm:p-3",children:[g.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.jsx("div",{className:"mt-2 min-w-0",children:t}),n?g.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Fm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=b.useState(!1),u=b.useId(),d=n.find(v=>v.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(v=>!v.disabled),y=!!VB(h).detail;return g.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:v=>{v.currentTarget.contains(v.relatedTarget)||l(!1)},children:[g.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),g.jsxs("button",{type:"button","aria-labelledby":u,"aria-haspopup":"listbox","aria-expanded":o,disabled:p.length===0,className:`mt-2 flex w-full min-w-0 items-center justify-between gap-3 rounded-md border border-border bg-input px-3 text-left outline-none transition-colors hover:border-primary/40 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(v=>!v),"data-slot":"voice-settings-choice-trigger",children:[g.jsx(ZN,{label:h,muted:!d&&!t}),g.jsx(fl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?g.jsx("div",{role:"listbox","aria-labelledby":u,className:"mt-2 max-h-64 overflow-y-auto rounded-md border border-border/80 bg-popover p-1 shadow-sm",children:n.map(v=>{const _=v.value===t;return g.jsxs("button",{type:"button",role:"option","aria-label":v.label,"aria-selected":_,disabled:v.disabled,className:"flex w-full min-w-0 items-center gap-2 rounded-sm px-2.5 py-2.5 text-left text-sm outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-45",onClick:()=>{v.disabled||(r(v.value),l(!1))},children:[g.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?g.jsx(ta,{className:"size-4","aria-hidden":"true"}):null}),g.jsx(ZN,{label:v.label})]},v.value)})}):null,s?g.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function ZN({label:e,muted:t=!1}){const n=VB(e);return g.jsxs("span",{className:"min-w-0 flex-1",children:[g.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?g.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function mse({scrollRef:e}={}){const[t,n]=b.useState(Q_),[r,i]=b.useState(String(Q_.turnIdleSeconds)),[s,o]=b.useState(()=>Tm()),[l,u]=b.useState(""),[d,h]=b.useState(!1),[p,y]=b.useState(!1),[v,_]=b.useState({kind:"idle"}),w=b.useRef(null),x=b.useRef(null),E=b.useRef(null),k=b.useRef(null),R=b.useRef(null);b.useEffect(()=>{const te=Nt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let J=!1;return _({kind:"loading"}),te.requestVoiceConfig().then(me=>{if(!J){if(me.error||!me.config){_({kind:"error",message:me.error??"读取语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),h(!1),y(!0),_({kind:"idle"})}}).catch(me=>{J||_({kind:"error",message:me instanceof Error?me.message:"读取语音设置失败"})}),()=>{J=!0}},[]),b.useEffect(()=>{const te=Nt;if(!te||!p)return;let J=!1;return te.requestVoiceCapabilities({region:t.region}).then(me=>{if(!J){if(me.error||!me.capabilities){o(Tm());return}o(me.capabilities)}}).catch(()=>{J||o(Tm())}),()=>{J=!0}},[t.region,p]),b.useEffect(()=>()=>{G(),B()},[]);const A=b.useMemo(()=>v.kind==="loading"?"读取中...":v.kind==="saving"?"保存中...":v.kind==="testing"?"正在测试语音合成":v.kind==="playingTest"?"正在播放测试音频":v.kind==="testPassed"?"测试通过":v.kind==="saved"?"已保存":v.kind==="error"?v.message:null,[v]),I=v.kind==="saving"||v.kind==="loading"||v.kind==="testing"||v.kind==="playingTest",T=b.useMemo(()=>W0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),D=T.some(te=>te.value===t.ttsVoice)?t.ttsVoice:"",W=T.length===0?"当前模型暂无可用音色":D?null:"请选择可用音色",U=b.useMemo(()=>bse(r),[r]),F=U?null:"请输入正整数秒数",O=W??F,M=I||!!O,z=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=b.useMemo(()=>eM(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),N=b.useMemo(()=>_se(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),q=b.useMemo(()=>eM(T,D),[T,D]);function Y(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:U??Q_.turnIdleSeconds}}async function $(){if(I)return;if(O){_({kind:"error",message:O});return}const te=Nt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}const J=Y();B(),_({kind:"saving"});const me=performance.now();try{const Se=await te.updateVoiceConfig(J),Re=performance.now()-me;if(Re<GN&&await yse(GN-Re),!Se.success||Se.error||!Se.config){_({kind:"error",message:Se.error??"保存语音设置失败"});return}n(Se.config),i(String(Se.config.turnIdleSeconds)),u(""),h(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(Ae=>Ae.kind==="saved"?{kind:"idle"}:Ae)},pse),te.requestVoiceCapabilities({region:Se.config.region}).then(Ae=>{Ae.capabilities&&o(Ae.capabilities)}).catch(()=>{o(Tm())})}catch(Se){_({kind:"error",message:Se instanceof Error?Se.message:"保存语音设置失败"})}}async function P(){if(I)return;if(O){_({kind:"error",message:O});return}const te=Nt;if(!te){_({kind:"error",message:"请先连接 Relay 服务器"});return}let J;try{J=V()}catch(me){_({kind:"error",message:JN(me)});return}_({kind:"testing"});try{const[me]=await Promise.all([te.testVoiceConfig(Y()),J.ready]);if(!me.success||me.error){G(),_({kind:"error",message:me.error??"语音配置测试失败"});return}const Se=await K(me,J.context);_({kind:"playingTest",transcript:me.transcript}),k.current=setTimeout(()=>{k.current=null,G(),_({kind:"testPassed",transcript:me.transcript})},Se)}catch(me){G(),_({kind:"error",message:JN(me)})}}function V(){G();const te=L1.acquire("playback");x.current=te;try{const J=vse();return w.current=J,{context:J,ready:QN(J)}}catch(J){throw te.release(),x.current=null,J}}function G(){var te,J,me;k.current&&(clearTimeout(k.current),k.current=null),(te=E.current)==null||te.stop(),E.current=null,(J=w.current)==null||J.close(),w.current=null,(me=x.current)==null||me.release(),x.current=null}function B(){R.current&&(clearTimeout(R.current),R.current=null)}async function K(te,J){if(!te.audioBase64)throw new Error("语音测试未返回可播放音频");if(te.audioEncoding&&te.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const me=te.audioSampleRate??24e3,Se=gse(te.audioBase64);if(Se.byteLength===0||Se.byteLength%2!==0)throw new Error("测试音频数据无效");await QN(J);const Re=new qB(J,me);E.current=Re,Re.enqueue(Se);const Ae=Math.ceil(Se.byteLength/2/me*1e3);return Math.max(fse,Ae)}function ee(te){var J;return((J=W0(s.ttsVoices,te)[0])==null?void 0:J.value)??""}return g.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:te=>{te.preventDefault(),$()},children:[g.jsx("div",{className:"flex min-h-0 flex-1 flex-col px-4 py-3 sm:px-5 sm:py-3.5","data-slot":"voice-settings-body-frame",children:g.jsx("div",{className:"dev-render-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"voice-settings-scroll",ref:e,children:g.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[g.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),g.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),g.jsx("span",{className:"shrink-0 rounded-full border border-primary/35 bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:"Bailian"})]})}),g.jsx(XN,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:g.jsxs("div",{className:"flex min-w-0 gap-2",children:[g.jsxs("div",{className:"relative min-w-0 flex-1",children:[g.jsx(NP,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),g.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:te=>{u(te.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${KN} w-full pl-9`})]}),t.configured&&g.jsxs(mt,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),h(!0)},children:[g.jsx(f7,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),g.jsx(Fm,{label:"地域",value:t.region,options:z,onChange:te=>n(J=>({...J,region:te==="intl"?"intl":"cn"}))}),g.jsx(Fm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:te=>n(J=>({...J,asrModel:te}))}),g.jsx(Fm,{label:"语音合成模型",value:t.ttsModel,options:N,onChange:te=>n(J=>({...J,ttsModel:te,ttsVoice:ee(te)}))}),g.jsx(Fm,{label:"语音音色",value:D,options:q,placeholder:T.length===0?"暂无可用音色":"请选择音色",onChange:te=>n(J=>({...J,ttsVoice:te})),help:W}),g.jsx(XN,{label:"结束停顿时间(秒)",help:F,children:g.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:te=>i(te.target.value),className:`${KN} w-full`})})]})})}),g.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[g.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),g.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[A?g.jsx("div",{role:v.kind==="error"?"alert":"status","aria-live":"polite",className:v.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:A}):null,g.jsxs(mt,{type:"button",variant:"outline",disabled:M,onClick:()=>void P(),children:[g.jsx(DP,{className:"size-4","aria-hidden":"true"}),"测试"]}),g.jsxs(mt,{type:"submit",disabled:M,children:[g.jsx(e7,{className:"size-4","aria-hidden":"true"}),v.kind==="saving"?"保存中...":"保存"]})]})]})]})}function gse(e){const t=window.atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n}function vse(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function QN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function JN(e){return e instanceof Error?e.message:"语音配置测试失败"}function yse(e){return new Promise(t=>setTimeout(t,e))}function bse(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function eM(e,t){const n=e.map(r=>({value:r.value,label:YB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function _se(e,t,n){const r=e.map(i=>{const s=W0(t,i.value).length===0;return{value:i.value,label:`${YB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function VB(e){const t=e.split(" · ").map(n=>n.trim()).filter(Boolean);return t.length<=1?{title:e,detail:null}:{title:t[0],detail:t.slice(1).join(" · ")}}function YB(e){if(!e.age)return e.label;const t=`年龄 ${e.age}`;if(e.label.includes(t))return e.label;const n=` · ${e.age}`;return e.label.endsWith(n)?`${e.label.slice(0,-n.length)} · ${t}`:`${e.label} · ${t}`}const wse=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Sse=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],I1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function KB(e){if(!Number.isFinite(e)||e<0)return"未知";if(e<60)return`${Math.floor(e)} 秒`;const t=Math.floor(e/60);if(t<60)return`${t} 分钟`;const n=Math.floor(t/60),r=t%60;if(n<24)return r>0?`${n} 小时 ${r} 分钟`:`${n} 小时`;const i=Math.floor(n/24),s=n%24;return s>0?`${i} 天 ${s} 小时`:`${i} 天`}function xse(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Ese(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Cse(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function q0({open:e,onOpenChange:t}){const n=Oe(W=>W.relayUrl),r=Oe(W=>W.latencyMonitorEnabled),i=Oe(W=>W.setLatencyMonitorEnabled),s=Oe(W=>W.sessionIdleNotificationsEnabled),o=Oe(W=>W.setSessionIdleNotificationsEnabled),l=Oe(W=>W.inputModePreference),u=Oe(W=>W.setInputModePreference),d=Oe(W=>W.themePreference),h=Oe(W=>W.setThemePreference),p=Oe(W=>W.ptyScrollTraceEnabled),y=Oe(W=>W.setPtyScrollTraceEnabled),[v,_]=b.useState("menu"),[w,x]=b.useState({kind:"idle"}),E=b.useRef(null),k=b.useRef(null),R=bQ(),A=b.useMemo(()=>Cv().osName==="iPad",[]),I=b.useCallback(async W=>{if(!W){o(!1);return}const U=await KZ();if(U==="granted"){o(!0);return}if(U==="denied"){et.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(U==="default"){et.info("未授予通知权限,会话通知保持关闭");return}et.error("当前浏览器不支持系统通知")},[o]),T=b.useCallback(async W=>{x({kind:"loading"});try{const U=await fetch(xse(n),{cache:"no-store",signal:W});if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=await U.json();if(F.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:F.version??"未知",uptime:F.uptime??0})}catch(U){if(U instanceof DOMException&&U.name==="AbortError")return;x({kind:"error",message:U instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e){_("menu");return}},[e]),b.useEffect(()=>{if(!e||v!=="version")return;const W=new AbortController;return T(W.signal),()=>W.abort()},[T,e,v]),b.useEffect(()=>{if(!e||v!=="voice")return;const W=window.requestAnimationFrame(()=>{var U;(U=E.current)==null||U.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(W)},[e,v]);const H=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",D=w.kind==="ready"?`运行 ${KB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return g.jsx(_c,{open:e,onOpenChange:t,children:g.jsxs(wc,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",v==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",v==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":v,focusSurfaceOnOpen:!0,ref:E,showCloseButton:v==="menu",children:[g.jsx(Sc,{className:Ye(v==="menu"&&"pr-12 text-left",v!=="menu"&&"text-left",v==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:v!=="menu"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-start gap-2",children:[g.jsx(mt,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>_("menu"),children:g.jsx(bv,{className:"size-4","aria-hidden":"true"})}),g.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[g.jsx(ll,{children:Ese(v)}),g.jsx(cc,{className:"max-w-[28rem] leading-5",children:Cse(v)})]})]}),v==="voice"?g.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):g.jsxs(g.Fragment,{children:[g.jsx(ll,{children:"设置"}),g.jsx(cc,{children:"连接、外观、通知和高级诊断选项。"})]})}),v==="version"?g.jsx(kse,{relayVersion:H,relayDetail:D,relayMuted:w.kind==="error"}):v==="relay-token"?g.jsx(Rse,{saved:R}):v==="clients"?g.jsx(Dse,{}):v==="voice"?g.jsx(mse,{scrollRef:k}):g.jsx(Tse,{relayTokenSaved:R,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:A,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:I,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function kse({relayVersion:e,relayDetail:t,relayMuted:n}){return g.jsxs("div",{className:I1,"data-slot":"settings-dialog-body",children:[g.jsx(nM,{icon:g.jsx(OP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:ose.version,detail:"当前浏览器加载的版本"}),g.jsx(nM,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Tse({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:h,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:v,onOpenClients:_,onOpenVersion:w}){return g.jsxs("div",{className:"dev-render-scroll min-h-0 space-y-4 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"settings-dialog-body",children:[g.jsxs(cu,{title:"服务",children:[g.jsx($m,{icon:g.jsx(U9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),g.jsx($m,{icon:g.jsx(NP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:v}),g.jsx($m,{icon:g.jsx(_7,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),g.jsx(cu,{title:"外观",children:g.jsx(tM,{icon:g.jsx(u7,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:wse,onValueChange:n})}),g.jsx(cu,{title:"通知",children:g.jsx(ew,{icon:g.jsx(q9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?g.jsx(cu,{title:"交互",children:g.jsx(tM,{icon:g.jsx(MP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Sse,onValueChange:i})}):null,g.jsxs(cu,{title:"高级诊断",children:[g.jsx(ew,{icon:g.jsx(lf,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),g.jsx(ew,{icon:g.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),g.jsx(cu,{title:"关于",children:g.jsx($m,{icon:g.jsx(PP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({title:e,children:t}){return g.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[g.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),g.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function tM({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return g.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,g.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return g.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Rse({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{JL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}if(!ZL(h)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),et.error(p);return}o(null),et.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{QL(),l()};return g.jsxs("form",{className:I1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[g.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[g.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),g.jsx("input",{id:t,type:"password",value:r,onChange:h=>{i(h.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?g.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),g.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?g.jsx(mt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,g.jsx(mt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Ase(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Nse(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Ase(e)}function Mse(e){return CX(e)}function Ose(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return KB(t)}function J_({label:e,value:t,title:n}){return g.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[g.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),g.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function Dse(){const e=Oe(y=>y.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),h=b.useCallback(async()=>{const y=Nt;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(v){o(v instanceof Error?v.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{h()},[h]);const p=b.useCallback(async y=>{const v=Nt;if(!v){o("Relay 未连接。");return}u(y),o(null);try{const _=await v.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return g.jsxs("div",{className:I1,"data-slot":"settings-dialog-body",children:[g.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:g.jsx(Nx,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?g.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?g.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const v=y.current===!0,_=l===y.clientId;return g.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children:g.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[g.jsxs("div",{className:"min-w-0 space-y-1.5",children:[g.jsx("div",{className:"min-w-0",children:g.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Mse(y)})}),g.jsxs("div",{className:"space-y-1",children:[g.jsx(J_,{label:"已连接",value:Ose(y.connectedAt)}),y.proxyId?g.jsx(J_,{label:"连接到",value:Nse(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?g.jsx(J_,{label:"来源 IP",value:y.remoteAddress}):null]})]}),v?g.jsx("div",{className:"inline-flex h-9 w-full items-center justify-center rounded-md border border-primary/30 bg-primary/10 px-3 text-sm font-normal text-primary","aria-label":"当前设备","data-slot":"relay-client-current-indicator",children:"当前设备"}):g.jsxs(mt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[g.jsx(N8,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function ew({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return g.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[g.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),g.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),g.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:g.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function $m({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return g.jsxs("button",{type:"button",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:r,"aria-labelledby":i,"aria-describedby":n?s:void 0,"data-slot":"settings-menu-item",children:[g.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground transition-colors group-hover:text-foreground",children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?g.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),g.jsx(Xh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function nM({icon:e,label:t,value:n,detail:r,muted:i=!1}){return g.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[g.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[g.jsx("div",{className:"text-sm text-muted-foreground",children:t}),g.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const Pse="xterm-helper-textarea";function Lse(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Pse)?!1:(e.blur(),!0)}function rM(e,t,n){if(!e||Math.abs(n)<1)return!1;let r=e instanceof Element?e:null;for(;r&&t.contains(r);){if(r instanceof HTMLElement&&Ise(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Ise(e,t){if(e.scrollHeight<=e.clientHeight+1)return!1;const n=window.getComputedStyle(e).overflowY;return n!=="auto"&&n!=="scroll"&&n!=="overlay"?!1:t<0?e.scrollTop>0:e.scrollTop+e.clientHeight<e.scrollHeight-1}function zse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Lse()},[e]),i=b.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=b.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const h=(n.current??u.clientY)-u.clientY;n.current=u.clientY,rM(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(rM(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Bse({className:e}){const t=Oe(o=>o.sidebarCollapsed),n=Oe(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=zse();return t?g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[g.jsx(sM,{collapsed:!0,onClick:n}),g.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),g.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[g.jsx(iM,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),g.jsx(WN,{compact:!0})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]}):g.jsxs(g.Fragment,{children:[g.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[g.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:g.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[g.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g.jsx(JP,{className:"text-[13px]",slot:"sidebar-brand"}),g.jsx(sM,{collapsed:!1,onClick:n})]}),g.jsx("div",{className:"mt-2.5",children:g.jsx(DB,{layout:"dropdown",variant:"sidebarChrome"})})]})}),g.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:g.jsx("div",{className:"flex-1 min-h-0",children:g.jsx(HB,{layout:"sidebar"})})}),g.jsxs("div",{className:"dev-sidebar-fade flex shrink-0 gap-2 px-2 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-2","data-slot":"sidebar-new-session",children:[g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(WN,{})}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsx(iM,{onClick:()=>i(!0)})})]})]}),g.jsx(q0,{open:r,onOpenChange:i})]})}function iM({compact:e=!1,tooltipSide:t="top",onClick:n}){return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[g.jsx(LP,{className:"size-4","aria-hidden":"true"}),!e&&g.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),g.jsx(Vf,{side:t,sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:"设置"})]})}function sM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?F8:B8;return g.jsxs(Wf,{delayDuration:500,children:[g.jsx(qf,{asChild:!0,children:g.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:g.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),g.jsx(Vf,{side:e?"right":"top",sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:n})]})}const jse=1500,Fse=300,oM=70,aM=35;function GB({texts:e,className:t}){const[n,r]=b.useState(""),[i,s]=b.useState(!0),o=b.useRef("typing"),l=b.useRef(0),u=b.useRef(0);b.useEffect(()=>{const h=setInterval(()=>s(p=>!p),530);return()=>clearInterval(h)},[]),b.useEffect(()=>{let h;const p=()=>e[u.current%e.length],y=()=>{const v=o.current;if(v==="typing"){const _=p();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),h=setTimeout(y,oM)):(o.current="paused",h=setTimeout(y,jse))}else v==="paused"?(o.current="deleting",h=setTimeout(y,aM)):v==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),h=setTimeout(y,aM)):(u.current+=1,o.current="waiting",h=setTimeout(y,Fse)):(o.current="typing",h=setTimeout(y,oM))};return h=setTimeout(y,500),()=>clearTimeout(h)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return g.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[g.jsx("span",{className:"text-green-500",children:"> "}),g.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),g.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),g.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const XB=["DEV Anywhere","/unlimited @anytime"];function $se({subtitle:e,action:t}){return g.jsx("section",{className:"dev-mobile-brand-hero border-b border-border/80 px-4 pb-5 pt-[calc(env(safe-area-inset-top)+1.25rem)] md:hidden","data-slot":"mobile-brand-hero","aria-label":"DEV Anywhere",children:g.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[g.jsx(GB,{texts:XB,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),g.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?g.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Hse=3e3,Use=1e4,Hm=12,Wse=4,lM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},qse={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function tw(e){if(!e.success||e.rttMs===void 0)return{state:"unavailable",error:e.error??"不可用",updatedAt:Date.now()};const t=e.rttMs;return{state:t<=120?"ok":t<=300?"warn":"bad",rttMs:t,updatedAt:Date.now()}}function uu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Fh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function cM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function ZB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Vse(e){switch(e){case"ok":return"border-emerald-500/35 bg-emerald-500/10 text-emerald-300";case"warn":return"border-amber-500/40 bg-amber-500/10 text-amber-300";case"bad":return"border-destructive/55 bg-destructive/10 text-destructive";default:return"border-border bg-card/90 text-muted-foreground"}}function Yse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Fh(e.rttMs):"等待检测"}function Kse(){const e=xi("local",on.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function uM(e){fr("local",on.latencyMonitorPosition,JSON.stringify(e))}function Gse(){var e,t;return{width:((e=window.visualViewport)==null?void 0:e.width)??window.innerWidth??document.documentElement.clientWidth??0,height:((t=window.visualViewport)==null?void 0:t.height)??window.innerHeight??document.documentElement.clientHeight??0}}function nw(e,t){const n=Gse(),r=Hm,i=Hm,s=Math.max(r,n.width-t.width-Hm),o=Math.max(i,n.height-t.height-Hm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Xse(){const e=Oe(T=>T.latencyMonitorEnabled),t=Oe(T=>T.connected),n=Oe(T=>T.proxyOnline),r=Oe(T=>T.selectedProxyId),[i,s]=b.useState(qse),[o,l]=b.useState(()=>Kse()),u=b.useRef(!1),d=b.useRef(null),h=b.useRef(null),p=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,H)=>cM(H.state)-cM(T.state))[0]??{state:"idle"}).state,[i]),v=ZB(y);async function _(){if(u.current)return;const T=Nt;if(!T||!t){const U=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,D,W]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:H.status==="fulfilled"?tw(H.value):uu(H.reason instanceof Error?H.reason.message:"测速失败"),relayProxy:D.status==="fulfilled"?tw(D.value):uu(D.reason instanceof Error?D.reason.message:"测速失败"),webProxy:W.status==="fulfilled"?tw(W.value):uu(W.reason instanceof Error?W.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,H=null;const D=async()=>{await _(),!T&&(H=setTimeout(D,document.hidden?Use:Hse))};return D(),()=>{T=!0,u.current=!1,H&&clearTimeout(H)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const H=T.getBoundingClientRect(),D=nw(o,{width:H.width,height:H.height});D.x===o.x&&D.y===o.y||(l(D),uM(D))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,x=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function E(T){var D,W;if(T.button!==0)return;const H=T.currentTarget.getBoundingClientRect();h.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:H.left,originY:H.top,width:H.width,height:H.height,dragging:!1},(W=(D=T.currentTarget).setPointerCapture)==null||W.call(D,T.pointerId)}function k(T){const H=h.current;if(!H||H.pointerId!==T.pointerId)return;const D=T.clientX-H.startX,W=T.clientY-H.startY;if(!H.dragging&&Math.hypot(D,W)<Wse)return;H.dragging=!0,T.preventDefault();const U=nw({x:H.originX+D,y:H.originY+W},{width:H.width,height:H.height});l(U)}function R(T){var F,O;const H=h.current;if(!H||H.pointerId!==T.pointerId||(h.current=null,(O=(F=T.currentTarget).releasePointerCapture)==null||O.call(F,T.pointerId),!H.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const D=T.clientX-H.startX,W=T.clientY-H.startY,U=nw({x:H.originX+D,y:H.originY+W},{width:H.width,height:H.height});l(U),uM(U)}function A(T){var D,W;const H=h.current;!H||H.pointerId!==T.pointerId||(h.current=null,(W=(D=T.currentTarget).releasePointerCapture)==null||W.call(D,T.pointerId))}function I(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return g.jsxs(T1,{children:[g.jsx(R1,{asChild:!0,children:g.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Vse(v)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Fh(i.webRelay.rttMs)},开发机 ${Fh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:I,children:[g.jsx(EP,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),g.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",Fh(i.webRelay.rttMs)]}),g.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Fh(w.rttMs)]}),g.jsx(fl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),g.jsxs(A1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{children:[g.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),g.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),g.jsx(mt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:g.jsx(Nx,{className:"size-3","aria-hidden":"true"})})]}),g.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(lM).map(T=>g.jsx(Zse,{label:lM[T],measurement:i[T]},T))})]})]})}function Zse({label:e,measurement:t}){const n=ZB(t.state);return g.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[g.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),g.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Yse(t)})]})]})}const QB="/__dev_anywhere_debug/browser-state-dumps",Qse=1500,Jse=10,rw=80,z1=500,eoe=["id","class","data-slot","data-state","data-testid","role","aria-label","aria-hidden","name","type","autocomplete","autocorrect","autocapitalize","inputmode","enterkeyhint","virtualkeyboardpolicy","contenteditable","placeholder","href","src"],toe=["display","position","visibility","opacity","pointer-events","z-index","overflow","overflow-x","overflow-y","touch-action","transform","translate","color-scheme","background-color","color","font-size","line-height","padding-top","padding-right","padding-bottom","padding-left","margin-top","margin-right","margin-bottom","margin-left"];function dM(){if(typeof window>"u")return"off";const e=o3("debugDump");return e==="auto"?"auto":e!==null||uoe("debugInput")?"manual":"off"}function noe(e="manual"){const t={count:0,truncated:!1},n=window,r={schemaVersion:1,createdAt:new Date().toISOString(),trigger:e,url:{href:window.location.href,origin:window.location.origin,pathname:window.location.pathname,search:window.location.search,hash:window.location.hash},browser:{userAgent:navigator.userAgent,language:navigator.language,languages:Array.from(navigator.languages??[]),platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints??0,cookieEnabled:navigator.cookieEnabled,onLine:navigator.onLine},viewport:ooe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:hM(document.activeElement),selection:aoe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>hM(i)).filter(i=>!!i),root:JB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug: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(()=>fM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>fM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function roe(e="manual"){const t=noe(e);return ioe(t)}async function ioe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await soe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:QB}}catch(r){const i=a3(r),s=loe(e.createdAt);return coe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function soe(e){const t=await fetch(QB,{method:"POST",headers:{"content-type":"application/json"},body:e});if(!t.ok)throw new Error(`${t.status} ${await t.text()}`);const n=await t.json();if(!n.ok||!n.path||typeof n.bytes!="number")throw new Error("debug endpoint returned an invalid response");return{path:n.path,bytes:n.bytes}}function JB(e,t,n){if(n.count>=Qse||t>Jse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=pM(e.textContent??"");return u?{kind:"text",text:Qv(u,z1)}:{kind:"text",text:""}}if(!(e instanceof HTMLElement))return{kind:"truncated"};const r=[];let i=0;const s=Array.from(e.childNodes);for(const u of s.slice(0,rw))u.nodeType===Node.TEXT_NODE&&!pM(u.textContent??"")||r.push(JB(u,t+1,n));s.length>rw&&(i=s.length-rw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:s3(e),attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e)},l=i3(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function hM(e){if(!(e instanceof HTMLElement))return null;const t=i3(e);return{path:s3(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:e3(e),rect:t3(e),scroll:n3(e),style:r3(e),...t?{value:t}:{}}}function ooe(){var n;const e=window.visualViewport,t=((n=screen.orientation)==null?void 0:n.type)??null;return{window:{innerWidth:window.innerWidth,innerHeight:window.innerHeight,outerWidth:window.outerWidth,outerHeight:window.outerHeight,devicePixelRatio:window.devicePixelRatio,scrollX:window.scrollX,scrollY:window.scrollY},visualViewport:e?{width:e.width,height:e.height,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,pageLeft:e.pageLeft,pageTop:e.pageTop,scale:e.scale}:null,screen:{width:screen.width,height:screen.height,availWidth:screen.availWidth,availHeight:screen.availHeight,orientation:t}}}function e3(e){const t={};for(const n of eoe){const r=e.getAttribute(n);r!==null&&(t[n]=Qv(r,500))}return t}function t3(e){const t=e.getBoundingClientRect();return{x:Vi(t.x),y:Vi(t.y),width:Vi(t.width),height:Vi(t.height),top:Vi(t.top),right:Vi(t.right),bottom:Vi(t.bottom),left:Vi(t.left)}}function n3(e){return{top:Vi(e.scrollTop),left:Vi(e.scrollLeft),height:Vi(e.scrollHeight),width:Vi(e.scrollWidth),clientHeight:Vi(e.clientHeight),clientWidth:Vi(e.clientWidth)}}function r3(e){const t=window.getComputedStyle(e),n={};for(const r of toe)n[r]=t.getPropertyValue(r);return n}function i3(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Qv(e.value,z1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function aoe(){var e;try{return Qv(((e=window.getSelection())==null?void 0:e.toString())??"",z1)}catch{return null}}function s3(e){const t=[];let n=e;for(;n&&n!==document.documentElement;){let r=n.tagName.toLowerCase();if(n.id){r+=`#${n.id}`,t.unshift(r);break}const i=n.getAttribute("data-slot");i?r+=`[data-slot="${i}"]`:n.classList.length>0&&(r+=`.${Array.from(n.classList).slice(0,3).join(".")}`);const s=n.parentElement;if(s){const o=n.tagName,l=Array.from(s.children).filter(u=>u instanceof HTMLElement&&u.tagName===o);l.length>1&&(r+=`:nth-of-type(${l.indexOf(n)+1})`)}t.unshift(r),n=s}return`html>${t.join(">")}`}function loe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function coe(e,t,n){if(typeof document>"u")return!1;const r=new Blob([t],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");return s.href=i,s.download=e,s.rel="noopener",document.body.append(s),s.click(),s.remove(),window.setTimeout(()=>URL.revokeObjectURL(i),1e3),!0}function uoe(e){return o3(e)!==null}function o3(e){const t=new URLSearchParams(window.location.search);if(t.has(e))return t.get(e)??"";const[,n=""]=window.location.hash.split("?"),r=new URLSearchParams(n);return r.has(e)?r.get(e)??"":null}function fM(e){return e?Zg(e.slice(-200)):null}function du(e){try{return Zg(e())}catch(t){return{error:a3(t)}}}function Zg(e){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(Array.isArray(e))return e.map(Zg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Zg(r);return t}return String(e)}function pM(e){return e.replace(/\s+/g," ").trim()}function Qv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Vi(e){return Math.round(e*100)/100}function a3(e){return e instanceof Error?e.message:String(e)}const doe=500,hoe=1e3,foe=60;function poe(){const[e,t]=b.useState(()=>dM()),[n,r]=b.useState(!1),[i,s]=b.useState(null),o=b.useRef(null),l=b.useRef(!1),u=b.useRef(0),d=b.useRef(0),h=b.useRef(null);b.useEffect(()=>{const _=()=>t(dM());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const p=b.useCallback(async(_="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await roe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&moe(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),b.useEffect(()=>{var k,R;if(e!=="auto")return;const _=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=A=>{d.current>=foe||(_(),h.current=window.setTimeout(()=>{h.current=null;const I=Date.now(),T=hoe-(I-u.current);if(T>0){h.current=window.setTimeout(()=>w(A),T);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${A}`)},doe))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=A=>w(A.type);return x.forEach(A=>window.addEventListener(A,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(R=window.visualViewport)==null||R.addEventListener("scroll",E),()=>{var A,I;_(),x.forEach(T=>window.removeEventListener(T,E,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",E),(I=window.visualViewport)==null||I.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",v=goe(i);return g.jsxs("div",{className:"fixed bottom-3 right-3 z-[90] flex max-w-[min(360px,calc(100vw-24px))] flex-col items-end gap-1",children:[v?g.jsx("div",{className:"max-w-full truncate rounded-md border border-border/70 bg-popover/95 px-2 py-1 text-[10px] text-muted-foreground shadow",children:v}):null,g.jsxs(mt,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void p("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?g.jsx(Ql,{className:"size-3.5 animate-spin","aria-hidden":"true"}):g.jsx(y8,{className:"size-3.5","aria-hidden":"true"}),g.jsx("span",{children:y})]})]})}function moe(e){if(e.status==="saved"){et.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){et.info(`诊断已下载: ${e.filename}`);return}et.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function goe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function voe(e){if(typeof window>"u")return null;try{const t=window.localStorage;return!t||typeof t.getItem!="function"?null:t.getItem(e)}catch{return null}}function B1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:voe(n)==="1",l=()=>typeof window>"u"?[]:window[t]??[],u=d=>{typeof window>"u"||(window[t]=d)};return{isEnabled:o,append(d){if(typeof window>"u")return;const h=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&h.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const v=h.indexOf(y);v>=0&&v!==h.length-1&&(h.splice(v,1),h.push(y)),u(h);return}}}if(h.push(d),i&&s.set(d.event,d),h.length>r){const p=h.splice(0,h.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(h)},getAll:l}}function En(e){return Math.round(e*10)/10}function qa(e){return e.length===0?"":`${En(Math.min(...e))}..${En(Math.max(...e))}`}function Au(e){return[...new Set(e.filter(t=>t!==void 0).map(En))]}function l3(e){let t=0,n=0;for(let r=1;r<e.length;r+=1){const i=e[r]-e[r-1];if(Math.abs(i)<1)continue;const s=Math.sign(i);t!==0&&s!==t&&(n+=1),t=s}return n}const yoe="dev_anywhere_pty_input_latency_trace",mM=80,boe=1e4,_oe=new TextDecoder;let woe=0;const Ku=new Map,xc=B1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:yoe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Soe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=koe)}function xoe(e,t){if(!xc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++woe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Aoe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),F1(s,r),Ku.set(e,s),Yf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function gM(e,t){if(!e||!xc.isEnabled())return;const n=performance.now(),r=Toe(e.sessionId,e.inputId);r&&(r.sentAt=n),Yf({t:n,event:"input:ws-send",sessionId:e.sessionId,inputId:e.inputId,inputKind:r==null?void 0:r.kind,dataLength:r==null?void 0:r.dataLength,sent:t.sent,queueWhenDisconnected:t.queueWhenDisconnected,deltaFromInputMs:r?n-r.startedAt:null,details:t.details})}function Eoe(e,t,n){if(!xc.isEnabled())return;const r=performance.now(),i=j1(e,r),s=Ooe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Moe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Yf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:Doe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Coe(e,t,n=1){if(!xc.isEnabled())return;const r=performance.now(),i=j1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Yf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:$1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Roe(e,s))}function koe(){const e=xc.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?"":En(s.sentAt-s.startedAt),s.firstOutputAt===null?"":En(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":En(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":En(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":En(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[En(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?"":En(s.deltaFromInputMs),s.details??""].join(" "));return["DEV Anywhere PTY input latency trace",`events=${e.length}, included=${t.length}, pendingInputs=${n.length}`,"pending input summary:","inputId sessionId kind len wsSendMs firstOutputMs echoMatchMs xtermWriteMs paintMs",...r,"events:","t event sessionId inputId kind len sent queue outputSeq bytes chunks pending deltaMs details",...i].join(`
511
511
  `)}function Yf(e){xc.append(e)}function j1(e,t){const n=Ku.get(e)??[];return F1(n,t),Ku.set(e,n),n}function F1(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>boe;(i||s)&&e.splice(n,1)}e.length>mM&&e.splice(0,e.length-mM)}function Toe(e,t){return(Ku.get(e)??[]).find(n=>n.inputId===t)??null}function Roe(e,t){if(!xc.isEnabled())return;const n=performance.now(),r=j1(e,n);let i=0;for(const s of t){const o=r.find(l=>l.inputId===s);!o||o.paintAt!==null||(o.paintAt=n,i+=1)}Yf({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:$1(r,n),details:i>0?`paint=${i}`:""}),F1(r,n)}function $1(e,t){const n=e[0];return n?t-n.startedAt:null}function Aoe(e){return e==="\r"||e===`
512
512
  `?"enter":e.startsWith("\x1B")?"escape":Noe(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function Noe(e){for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(n>=0&&n<=8||n>=11&&n<=31||n===127)return!0}return!1}function Moe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function Ooe(e){try{return _oe.decode(e)}catch{return""}}function Doe(e){return e.filter(Boolean).join(" ")}function qs(e,t){if(!e||!t)return;const n=xoe(e,t),r=Jl;if(!r){gM(n,{sent:!1,queueWhenDisconnected:!1,details:"no-ws-manager"});return}const i={type:"remote_input_raw",sessionId:e,data:t};n&&(i.traceId=n.inputId);const s=r.send(JSON.stringify(i),{queueWhenDisconnected:!0});gM(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const vM=-1;function Poe({sessionId:e,enabled:t,waiting:n,approvalSeq:r,sendRawInput:i=qs}){const s=b.useRef(void 0),o=b.useRef(e);b.useEffect(()=>{if(o.current!==e&&(o.current=e,s.current=void 0),!n){s.current=void 0;return}if(r===void 0){if(s.current!==void 0)return;s.current=vM,i(e,"\r");return}if(s.current===vM){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function Loe(e){var r,i,s;if(!e.connected||!e.proxyOnline||e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.state==="idle"||e.session.state==="error"||e.session.state==="terminated")return null;const t=Ix(e.proxyId,e.session.sessionId);return!t||!e.autoYesBySessionKey[t]||!(e.session.state==="waiting_approval"||((r=e.agentStatus)==null?void 0:r.phase)==="waiting_permission"||((i=e.ptyState)==null?void 0:i.state)==="approval_wait")?null:{key:t,sessionId:e.session.sessionId,waiting:!0,approvalSeq:((s=e.ptyState)==null?void 0:s.state)==="approval_wait"?e.ptyState.seq:void 0}}function Ioe({target:e,sendRawInput:t}){return Poe({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function zoe({sendRawInput:e=qs}){const t=Oe(d=>d.connected),n=Oe(d=>d.proxyOnline),r=Oe(d=>d.selectedProxyId),i=It(d=>d.sessions),s=It(d=>d.ptyStateBySessionId),o=It(d=>d.agentStatusBySessionId),l=It(d=>d.ptyAutoYesBySessionKey),u=i.map(d=>Loe({proxyId:r,session:d,ptyState:s[d.sessionId],agentStatus:o[d.sessionId],autoYesBySessionKey:l,connected:t,proxyOnline:n})).filter(d=>d!==null);return g.jsx(g.Fragment,{children:u.map(d=>g.jsx(Ioe,{target:d,sendRawInput:e},d.key))})}function Boe(e,t,n){const r=e.some(s=>s.sessionId===t)?e.map(s=>s.sessionId===t?{...s,touchedAt:n.now}:s):[...e,{sessionId:t,touchedAt:n.now}];if(r.length<=n.capacity)return r;const i=r.filter(s=>s.sessionId!==n.activeSessionId).sort((s,o)=>s.touchedAt-o.touchedAt)[0];return i?r.filter(s=>s.sessionId!==i.sessionId):r.slice(-3)}var Xl=function(e,t){return Number(e.toFixed(t))},joe=function(e,t){return t},On=function(e,t,n){n&&typeof n=="function"&&n(e,t)},Foe=function(e){return-Math.cos(e*Math.PI)/2+.5},$oe=function(e){return e},Hoe=function(e){return e*e},Uoe=function(e){return e*(2-e)},Woe=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},qoe=function(e){return e*e*e},Voe=function(e){return--e*e*e+1},Yoe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},Koe=function(e){return e*e*e*e},Goe=function(e){return 1- --e*e*e*e},Xoe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},Zoe=function(e){return e*e*e*e*e},Qoe=function(e){return 1+--e*e*e*e*e},Joe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},c3={easeOut:Foe,linear:$oe,easeInQuad:Hoe,easeOutQuad:Uoe,easeInOutQuad:Woe,easeInCubic:qoe,easeOutCubic:Voe,easeInOutCubic:Yoe,easeInQuart:Koe,easeOutQuart:Goe,easeInOutQuart:Xoe,easeInQuint:Zoe,easeOutQuint:Qoe,easeInOutQuint:Joe},u3=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Ws=function(e){e.mounted&&(u3(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function d3(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Ws(e),e.animation=function(){if(!e.mounted)return u3(e.animation);var o=new Date().getTime()-i,l=o/n,u=c3[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function eae(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function wl(e,t,n,r){var i=eae(t);if(!(!e.mounted||!i)){var s=e.setState,o=e.state,l=o.scale,u=o.positionX,d=o.positionY,h=t.scale-l,p=t.positionX-u,y=t.positionY-d;n===0?s(t.scale,t.positionX,t.positionY):d3(e,r,n,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+h*v,w=u+p*v,x=d+y*v;s(_,w,x)})}}function tae(e,t,n){var r=e.offsetWidth,i=e.offsetHeight,s=t.offsetWidth,o=t.offsetHeight,l=s*n,u=o*n,d=r-l,h=i-u;return{wrapperWidth:r,wrapperHeight:i,newContentWidth:l,newDiffWidth:d,newContentHeight:u,newDiffHeight:h}}var nae=function(e,t,n,r,i,s,o){var l=e>t?n*(o?.5:1):0,u=r>i?s*(o?.5:1):0,d=e-t-l,h=l,p=r-i-u,y=u;return{minPositionX:d,maxPositionX:h,minPositionY:p,maxPositionY:y,scaleWidthFactor:l,scaleHeightFactor:u}},H1=function(e,t){var n=e.wrapperComponent,r=e.contentComponent,i=e.setup,s=i.centerZoomedOut,o=i.disablePadding;if(!n||!r)throw new Error("Components are not mounted");var l=tae(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,h=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,v=l.newDiffHeight,_=nae(u,h,y,d,p,v,!!s),w=u>=h&&d>=p;o&&w&&!s&&(_.minPositionX=0,_.maxPositionX=0,_.minPositionY=0,_.maxPositionY=0);var x=e.setup,E=x.minPositionX,k=x.maxPositionX,R=x.minPositionY,A=x.maxPositionY;return E!=null&&(_.minPositionX=u*(1-t)+E*t),k!=null&&(_.maxPositionX=k*t),R!=null&&(_.minPositionY=d*(1-t)+R*t),A!=null&&(_.maxPositionY=A*t),_},yf=function(e,t,n,r){return r?e<t?Xl(t,2):e>n?Xl(n,2):Xl(e,2):Xl(e,2)},Gu=function(e,t){var n=H1(e,t);return e.bounds=n,n};function Kf(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,h=n.maxPositionY,p=0,y=0;o&&(p=i,y=s);var v=yf(e,l-p,d+p,r),_=yf(t,u-y,h+y,r);return{x:v,y:_}}function Jv(e,t,n,r,i,s){var o=e.state,l=o.scale,u=o.positionX,d=o.positionY,h=r-l;if(typeof t!="number"||typeof n!="number")return console.error("Mouse X and Y position were not provided!"),{x:u,y:d};var p=u-t*h,y=d-n*h,v=Kf(p,y,i,s,0,0,null);return v}var yM=1e-7;function Gf(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,yM),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,yM)}var bM=function(e,t){var n=e.setup.panning.excluded,r=e.isInitialized,i=e.wrapperComponent,s=t.target,o="shadowRoot"in s&&"composedPath"in t,l=o?t.composedPath().some(function(h){return h instanceof Element?i==null?void 0:i.contains(h):!1}):i==null?void 0:i.contains(s),u=r&&s&&l;if(!u)return!1;var d=Xf(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},_M=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},rae=function(e,t){var n=e.state,r=n.positionX,i=n.positionY;e.isPanning=!0;var s=t.clientX,o=t.clientY;e.startCoords={x:s-r,y:o-i}},iae=function(e,t){var n=t.touches,r=e.state,i=r.positionX,s=r.positionY;e.isPanning=!0;var o=n.length===1;if(o){var l=n[0].clientX,u=n[0].clientY;e.startCoords={x:l-i,y:u-s}}};function sae(e){var t=e.state,n=t.positionX,r=t.positionY,i=t.scale,s=e.setup,o=s.disabled,l=s.limitToBounds,u=s.centerZoomedOut,d=e.wrapperComponent;if(!(o||!d||!e.bounds)){var h=e.bounds,p=h.maxPositionX,y=h.minPositionX,v=h.maxPositionY,_=h.minPositionY,w=n>p||n<y,x=r>v||r<_,E=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>v?d.offsetHeight:e.setup.minPositionY||0,R=Jv(e,E,k,i,e.bounds,l||u),A=R.x,I=R.y;return{scale:i,positionX:w?A:n,positionY:x?I:r}}}function h3(e,t,n,r,i){var s=e.setup.limitToBounds,o=e.wrapperComponent,l=e.bounds,u=e.state,d=u.scale,h=u.positionX,p=u.positionY;if(!(o===null||l===null||t===h&&n===p)){var y=Kf(t,n,l,s,r,i,o),v=y.x,_=y.y;e.setState(d,v,_)}}var oae=function(e,t,n){var r=e.startCoords,i=e.state,s=e.setup.panning,o=s.lockAxisX,l=s.lockAxisY,u=i.positionX,d=i.positionY;if(!r)return{x:u,y:d};var h=t-r.x,p=n-r.y,y=o?u:h,v=l?d:p;return{x:y,y:v}},ul=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},Ja;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(Ja||(Ja={}));var aae=function(e){var t=e.mounted,n=e.wrapperComponent,r=e.contentComponent,i=e.setup,s=i.disabled,o=i.velocityAnimation,l=i.limitToBounds,u=e.state.scale,d=o.disabled;if(d||s||!t||!n||!r)return!1;if(!l)return!0;var h=n.offsetWidth<r.offsetWidth*u||n.offsetHeight<r.offsetHeight*u;return h},lae=function(e){var t=e.mounted,n=e.velocity,r=e.bounds,i=e.setup,s=i.disabled,o=i.velocityAnimation,l=o.disabled,u=!l&&!s&&t;return!(!u||!n||!r)};function cae(e,t){var n=e.setup.velocityAnimation,r=n.animationTime,i=n.maxAnimationTime,s=n.inertia;return Math.min(r*Math.max(1,Math.abs(t/s)),i)}function wM(e,t,n,r,i,s,o,l,u,d){if(i){if(t>o&&n>o){var h=o+(e-o)*d;return h>u?u:h<o?o:h}if(t<s&&n<s){var h=s+(e-s)*d;return h<l?l:h>s?s:h}}return r?t:yf(e,s,o,i)}function uae(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var iw=function(e,t,n){var r=0,i=e*n;return Number.isNaN(i)?r:e<0?Math.max(i,-t):Math.min(i,t)};function dae(e,t,n){var r,i,s=aae(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,h=u.velocityAnimation,p=h.maxStrengthMouse,y=h.maxStrengthTouch,v=h.sensitivityTouch,_=h.sensitivityMouse,w=Date.now();if(o&&l&&d){var x=uae(d),E=(r={},r[Ja.TOUCH]=v,r[Ja.MOUSE]=_,r)[n],k=(i={},i[Ja.TOUCH]=y,i[Ja.MOUSE]=p,i)[n],R=t.x-o.x,A=t.y-o.y,I=iw(R/x,k,E),T=iw(A/x,k,E),H=w-l,D=R*R+A*A,W=iw(Math.sqrt(D)/H,k,E);e.velocity={velocityX:I,velocityY:T,total:W}}e.lastMousePosition=t,e.velocityTime=w}}function hae(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=lae(e);if(!(!s||!t||!n||!i)){var o=t.velocityX,l=t.velocityY,u=t.total,d=n.maxPositionX,h=n.minPositionX,p=n.maxPositionY,y=n.minPositionY,v=r.limitToBounds,_=r.autoAlignment,w=r.zoomAnimation,x=r.panning,E=x.lockAxisY,k=x.lockAxisX,R=w.animationType,A=_.sizeX,I=_.sizeY,T=_.velocityAlignmentTime,H=T,D=cae(e,u),W=Math.max(D,H),U=ul(e,A),F=ul(e,I),O=U*i.offsetWidth/100,M=F*i.offsetHeight/100,z=d+O,L=h-O,N=p+M,q=y-M,Y=e.state,$=new Date().getTime();d3(e,R,W,function(P){var V=e.state,G=V.scale,B=V.positionX,K=V.positionY,ee=new Date().getTime()-$,te=ee/H,J=c3[_.animationType],me=1-J(Math.min(1,te)),Se=1-P,Re=B+o*Se,Ae=K+l*Se,He=wM(Re,Y.positionX,B,k,v,h,d,L,z,me),qe=wM(Ae,Y.positionY,K,E,v,y,p,q,N,me);if(B!==Re||K!==Ae){e.setState(G,He,qe);var pt=e.props.onPanning;pt&&pt(Cn(e),{})}})}}function SM(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},Ws(e),Gu(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?iae(e,t):rae(e,t)}function f3(e,t){var n=e.state.scale,r=e.setup,i=r.minScale,s=r.autoAlignment,o=s.disabled,l=s.sizeX,u=s.sizeY,d=s.animationTime,h=s.animationType,p=o||n<i||!l&&!u;if(!p){var y=sae(e);y&&wl(e,y,d,h)}}function xM(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=oae(e,t,n),h=d.x,p=d.y,y=ul(e,l),v=ul(e,u);dae(e,{x:h,y:p},r),h3(e,h,p,y,v)}}function fae(e,t){if(e.isPanning){var n=e.velocity,r=e.wrapperComponent,i=e.contentComponent;e.isPanning=!1;var s=e.state,o=s.positionX,l=s.positionY,u=s.scale,d=e.panStartPosition;if(e.panStartPosition=null,d){var h=o-d.x,p=l-d.y;if(h*h+p*p<=25)return}e.isAnimating=!1,e.animation=null;var y=(r==null?void 0:r.offsetWidth)||0,v=(r==null?void 0:r.offsetHeight)||0,_=((i==null?void 0:i.offsetWidth)||0)*u,w=((i==null?void 0:i.offsetHeight)||0)*u,x=!e.setup.limitToBounds||y<_||v<w,E=!t&&n&&n.total>.1&&x;E?hae(e):f3(e)}}function U1(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Gf(Xl(t,2),s,o,0,!1),d=Gu(e,u),h=Jv(e,n,r,u,d,l),p=h.x,y=h.y;return{scale:u,positionX:p,positionY:y}}function W1(e,t,n){var r=e.state.scale,i=e.wrapperComponent,s=e.setup,o=s.minScale,l=s.maxScale,u=s.limitToBounds,d=s.zoomAnimation,h=d.disabled,p=d.animationTime,y=d.animationType,v=r>=o&&r<=l,_=h||v;if((r>=1||u)&&f3(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,x=n||i.offsetHeight/2,E=r<o?o:l,k=U1(e,E,w,x);k&&wl(e,k,p,y)}}var Ts=function(){return Ts=Object.assign||function(t){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Ts.apply(this,arguments)};function EM(e,t,n){for(var r=0,i=t.length,s;r<i;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}var sw={scale:1,positionX:0,positionY:0},Kl={disabled:!1,minPositionX:null,maxPositionX:null,minPositionY:null,maxPositionY:null,minScale:1,maxScale:8,limitToBounds:!0,centerZoomedOut:!1,centerOnInit:!1,disablePadding:!1,smooth:!0,detached:!1,wheel:{step:.015,disabled:!1,wheelDisabled:!1,touchPadDisabled:!1,activationKeys:[],excluded:[]},trackPadPanning:{disabled:!0,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,activationKeys:[],excluded:[]},panning:{disabled:!1,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,allowLeftClickPan:!0,allowMiddleClickPan:!0,allowRightClickPan:!0,activationKeys:[],excluded:[]},pinch:{step:5,disabled:!1,allowPanning:!0,excluded:[]},doubleClick:{disabled:!1,step:.7,mode:"zoomIn",animationType:"easeOut",animationTime:200,excluded:[]},zoomAnimation:{disabled:!1,size:.4,animationTime:200,animationType:"easeOut"},autoAlignment:{disabled:!1,sizeX:100,sizeY:100,animationTime:200,velocityAlignmentTime:400,animationType:"easeOut"},velocityAnimation:{disabled:!1,sensitivityMouse:1,sensitivityTouch:1.2,maxStrengthMouse:20,maxStrengthTouch:40,inertia:1,animationTime:300,maxAnimationTime:800,animationType:"easeOut"}},V0={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},p3=function(e){var t,n,r,i,s,o,l,u,d,h=Math.max((t=e.minScale)!==null&&t!==void 0?t:Kl.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:Kl.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:sw.scale,v=Math.min(Math.max(y,h),p),_=yf((i=e.initialPositionX)!==null&&i!==void 0?i:sw.positionX,(s=e.minPositionX)!==null&&s!==void 0?s:-1/0,(o=e.maxPositionX)!==null&&o!==void 0?o:1/0,e.minPositionX!=null||e.maxPositionX!=null),w=yf((l=e.initialPositionY)!==null&&l!==void 0?l:sw.positionY,(u=e.minPositionY)!==null&&u!==void 0?u:-1/0,(d=e.maxPositionY)!==null&&d!==void 0?d:1/0,e.minPositionY!=null||e.maxPositionY!=null);return{previousScale:v,scale:v,positionX:_,positionY:w}},CM=function(e){var t=Ts({},Kl);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Kl[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Kl[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=Ts(Ts({},Kl[r]),e[r]):u?t[r]=EM(EM([],Kl[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},m3=function(e,t,n){var r=e.state.scale,i=e.wrapperComponent,s=e.setup,o=s.maxScale,l=s.minScale,u=s.zoomAnimation,d=s.smooth,h=u.size;if(!i)throw new Error("Wrapper is not mounted");var p=d?r*Math.exp(t*n):r+t*n,y=Gf(Xl(p,3),l,o,h,!1);return y};function g3(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,h=u.positionX,p=u.positionY,y=e.setup.zoomAnimation;if(!l)return console.error("No WrapperComponent found");var v=y.disabled?0:r,_=l.offsetWidth,w=l.offsetHeight,x=(_/2-h)/d,E=(w/2-p)/d,k=m3(e,t,n),R=U1(e,k,x,E);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,I=A.onZoomStart,T=A.onZoom,H=A.onZoomStop,D=new MouseEvent("mousemove",{bubbles:!0}),W=Cn(e);On(W,D,I),On(W,D,T),wl(e,R,v,i);var U=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;U&&U.setTimeout(function(){e.mounted&&On(Cn(e),D,H)},v)}function v3(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,h=o.centerOnInit,p=p3(e.props),y=e.state,v=y.scale,_=y.positionX,w=y.positionY;if(l){var x=p.positionX,E=p.positionY;if(h&&u){var k=q1(p.scale,l,u);x=k.positionX,E=k.positionY}var R=H1(e,p.scale),A=Kf(x,E,R,d,0,0,l),I={scale:p.scale,positionX:A.x,positionY:A.y};if(!(v===p.scale&&_===p.positionX&&w===p.positionY)){r==null||r();var T=e.props,H=T.onZoomStart,D=T.onZoom,W=T.onZoomStop,U=new MouseEvent("mousemove",{bubbles:!0}),F=Cn(e);On(F,U,H),On(F,U,D),wl(e,I,t,n);var O=(s=(i=l.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&s!==void 0?s:typeof window<"u"?window:null;O&&O.setTimeout(function(){e.mounted&&On(Cn(e),U,W)},t)}}}function pae(e,t,n,r){var i=e.getBoundingClientRect(),s=t.getBoundingClientRect(),o=n.getBoundingClientRect(),l=s.x*r.scale,u=s.y*r.scale;return{x:(i.x-o.x+l)/r.scale,y:(i.y-o.y+u)/r.scale}}function mae(e,t,n,r,i){r===void 0&&(r=0),i===void 0&&(i=0);var s=e.wrapperComponent,o=e.contentComponent,l=e.state,u=e.setup,d=u.limitToBounds,h=u.minScale,p=u.maxScale;if(!s||!o)return l;var y=s.getBoundingClientRect(),v=t.getBoundingClientRect(),_=pae(t,s,o,l),w=_.x,x=_.y,E=v.width/l.scale,k=v.height/l.scale,R=s.offsetWidth/E,A=s.offsetHeight/k,I=Gf(n||Math.min(R,A),h,p,0,!1),T=(y.width-E*I)/2,H=(y.height-k*I)/2,D=(y.left-w)*I+T+r,W=(y.top-x)*I+H+i,U=H1(e,I),F=Kf(D,W,U,d,0,0,s),O=F.x,M=F.y;return{positionX:O,positionY:M,scale:I}}var gae=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),g3(e,1,t,n,r)}},vae=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),g3(e,-1,t,n,r)}},yae=function(e){return function(t,n,r,i,s){i===void 0&&(i=300),s===void 0&&(s="easeOut");var o=e.state,l=o.positionX,u=o.positionY,d=o.scale,h=e.wrapperComponent,p=e.contentComponent,y=e.setup.disabled;if(!(y||!h||!p)){var v={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};wl(e,v,i,s)}}},bae=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),v3(e,t,n)}},_ae=function(e){return function(t,n,r){n===void 0&&(n=200),r===void 0&&(r="easeOut");var i=e.state,s=e.wrapperComponent,o=e.contentComponent;if(s&&o){var l=q1(t||i.scale,s,o);wl(e,l,n,r)}}},wae=function(e){return function(t,n,r,i,s,o){r===void 0&&(r=600),i===void 0&&(i="easeOut"),s===void 0&&(s=0),o===void 0&&(o=0),Ws(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=mae(e,u,n,s,o);wl(e,d,r,i)}}},Y0=function(e){return{instance:e,state:e.state,zoomIn:gae(e),zoomOut:vae(e),setTransform:yae(e),resetTransform:bae(e),centerView:_ae(e),zoomToElement:wae(e)}},Sae=function(e){return{instance:e,state:e.state}},Cn=function(e){var t={};return Object.assign(t,Sae(e)),Object.assign(t,Y0(e)),t},ow=!1;function aw(){try{var e={get passive(){return ow=!0,!1}};return e}catch{return ow=!1,ow}}var Um=".".concat(V0.wrapperClass),Xf=function(e,t){return t.some(function(n){return e.matches("".concat(Um," ").concat(n,", ").concat(Um," .").concat(n,", ").concat(Um," ").concat(n," *, ").concat(Um," .").concat(n," *"))})},bf=function(e){e&&clearTimeout(e)},xae=function(e){return Number.parseFloat(e.toFixed(8))},y3=function(e,t,n){var r=xae(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},q1=function(e,t,n){var r=n.offsetWidth*e,i=n.offsetHeight*e,s=(t.offsetWidth-r)/2,o=(t.offsetHeight-i)/2;return{scale:e,positionX:s,positionY:o}};function Eae(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Cae(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var b3=function(e,t){var n=e.setup.wheel,r=n.disabled,i=n.wheelDisabled,s=n.touchPadDisabled,o=n.excluded,l=e.isInitialized,u=e.isPanning,d=t.target,h=l&&!u&&!r&&d;if(!h||i&&!t.ctrlKey||s&&t.ctrlKey)return!1;var p=Xf(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},kae=function(e,t){var n=e.setup,r=n.disabled,i=n.trackPadPanning,s=i.activationKeys,o=i.excluded;if(!e.wrapperComponent||!e.contentComponent||r||i.disabled||t.ctrlKey)return!1;var l=b3(e,t);if(l)return!1;var u=t.target,d=Xf(u,o);if(d)return!1;var h=e.isPressingKeys(s);return!!h},Tae=function(e){return e?e.deltaY<0?1:-1:0};function Rae(e,t){var n=Tae(e),r=joe(t,n);return r}function _3(e,t,n){var r=t.getBoundingClientRect(),i=0,s=0;if("clientX"in e)i=(e.clientX-r.left)/n,s=(e.clientY-r.top)/n;else{var o=e.touches[0];i=(o.clientX-r.left)/n,s=(o.clientY-r.top)/n}return(Number.isNaN(i)||Number.isNaN(s))&&console.error("No mouse or touch offset found"),{x:i,y:s}}var Aae=function(e,t,n,r,i){var s=e.state.scale,o=e.wrapperComponent,l=e.setup,u=l.maxScale,d=l.minScale,h=l.zoomAnimation,p=l.disablePadding,y=h.size,v=h.disabled;if(!o)throw new Error("Wrapper is not mounted");var _=s+t*n,w=r?!1:!v,x=Gf(_,d,u,y,w&&!p);return x},w3=function(e,t){var n=e.previousWheelEvent,r=e.state.scale,i=e.setup,s=i.maxScale,o=i.minScale;return n?r<s||r>o||Math.sign(n.deltaY)!==Math.sign(t.deltaY)||n.deltaY>0&&n.deltaY<t.deltaY||n.deltaY<0&&n.deltaY>t.deltaY||Math.sign(n.deltaY)!==Math.sign(t.deltaY):!1},Nae=function(e,t){var n=e.setup.pinch,r=n.disabled,i=n.excluded,s=e.isInitialized,o=t.target,l=s&&!r&&o;if(!l)return!1;var u=Xf(o,i);return!u},Mae=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},Oae=function(e,t,n){var r=n.getBoundingClientRect(),i=e.touches,s=i[0].clientX-r.left,o=i[0].clientY-r.top,l=i[1].clientX-r.left,u=i[1].clientY-r.top;return{x:(s+l)/2/t,y:(o+u)/2/t}},S3=function(e){return Math.sqrt(Math.pow(e.touches[0].pageX-e.touches[1].pageX,2)+Math.pow(e.touches[0].pageY-e.touches[1].pageY,2))},Dae=5,Pae=function(e,t){var n=e.pinchStartScale,r=e.pinchStartDistance,i=e.setup,s=i.maxScale,o=i.minScale,l=i.zoomAnimation,u=i.disablePadding,d=i.pinch,h=l.size,p=l.disabled,y=d.step;if(!n||r===null)throw new Error("Pinch touches distance was not provided");if(t<0)return e.state.scale;var v=t/r,_=v*n,w=(_-n)*(y/Dae),x=n+w,E=x===1/0?0:Xl(x,10);return Gf(E,o,s,h,!p&&!u)},x3=160,E3=100,Lae=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(Ws(e),On(Cn(e),t,r),On(Cn(e),t,i))},Iae=function(e,t){var n=e.props,r=n.onWheel,i=n.onZoom,s=e.contentComponent,o=e.setup,l=e.state,u=l.scale,d=o.limitToBounds,h=o.centerZoomedOut,p=o.zoomAnimation,y=o.wheel,v=o.disablePadding,_=o.smooth,w=p.size,x=p.disabled,E=y.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var k=Rae(t,null),R=_?E*Math.abs(t.deltaY):E,A=Aae(e,k,R,!t.ctrlKey);if(u!==A){var I=Gu(e,A),T=_3(t,s,u),H=x||w===0||h||v,D=d&&H,W=Jv(e,T.x,T.y,A,I,D),U=W.x,F=W.y;e.previousWheelEvent=t,e.setState(A,U,F),On(Cn(e),t,r),On(Cn(e),t,i)}},zae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;bf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(W1(e,t.x,t.y),e.wheelAnimationTimer=null)},E3);var s=w3(e,t);s&&(bf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,On(Cn(e),t,r),On(Cn(e),t,i))},x3))},Bae=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(Ws(e),On(Cn(e),t,r),On(Cn(e),t,i))},jae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;bf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(W1(e,t.x,t.y),e.wheelAnimationTimer=null)},E3);var s=w3(e,t);s&&(bf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,On(Cn(e),t,r),On(Cn(e),t,i))},x3))},C3=function(e){for(var t=0,n=0,r=0;r<2;r+=1)t+=e.touches[r].clientX,n+=e.touches[r].clientY;var i=t/2,s=n/2;return{x:i,y:s}},Fae=function(e,t){var n=S3(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=C3(t),Ws(e)},$ae=function(e,t){var n=e.contentComponent,r=e.pinchStartDistance,i=e.wrapperComponent,s=e.pinchPreviousCenter,o=e.state.scale,l=e.setup,u=l.limitToBounds,d=l.centerZoomedOut,h=l.zoomAnimation,p=l.autoAlignment,y=l.pinch,v=l.panning,_=h.disabled,w=h.size,x=y.allowPanning;if(!(r===null||!n)){var E=Oae(t,o,n);if(!(!Number.isFinite(E.x)||!Number.isFinite(E.y))){var k=S3(t),R=Pae(e,k),A=C3(t),I=o/R,T=(A.x-((s==null?void 0:s.x)||0))*I,H=(A.y-((s==null?void 0:s.y)||0))*I;if(!(R===o&&T===0&&H===0)){e.pinchPreviousCenter=A;var D=Gu(e,R),W=_||w===0||d,U=u&&W,F=Jv(e,E.x,E.y,R,D,U),O=F.x,M=F.y;if(e.pinchMidpoint=E,e.lastDistance=k,v.disabled||!x)e.setState(R,O,M);else{var z=p.sizeX,L=p.sizeY,N=ul(e,z,R),q=ul(e,L,R),Y=O+T,$=M+H,P=Kf(Y,$,D,u,N,q,i),V=P.x,G=P.y;e.setState(R,V,G)}}}}},Hae=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,W1(e,t==null?void 0:t.x,t==null?void 0:t.y)},k3=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;bf(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,On(Cn(e),t,n)},r)},Uae=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;On(Cn(e),t,r),v3(e,o,l,function(){return On(Cn(e),t,i)}),k3(e,t)};function Wae(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function qae(e,t){var n=e.setup,r=e.doubleClickStopEventTimer,i=e.state,s=e.contentComponent,o=i.scale,l=e.props,u=l.onZoomStart,d=l.onZoom,h=n.doubleClick,p=h.disabled,y=h.mode,v=h.step,_=h.animationTime,w=h.animationType;if(!p&&!r){if(y==="reset")return Uae(e,t);if(!s)return console.error("No ContentComponent found");var x=Wae(y,e.state.scale),E=m3(e,x,v);if(o!==E){On(Cn(e),t,u);var k=_3(t,s,o),R=U1(e,E,k.x,k.y);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");On(Cn(e),t,d),wl(e,R,_,w),k3(e,t)}}}var Vae=function(e,t){var n=e.isInitialized,r=e.setup,i=e.wrapperComponent,s=r.doubleClick,o=s.disabled,l=s.excluded,u=t.target,d=i==null?void 0:i.contains(u),h=n&&u&&d&&!o;if(!h)return!1;var p=Xf(u,l);return!p},Yae=(function(){function e(t){var n=this;this.mounted=!0,this.onChangeCallbacks=new Set,this.onInitCallbacks=new Set,this.onTransformCallbacks=new Set,this.wrapperComponent=null,this.contentComponent=null,this.isInitialized=!1,this.bounds=null,this.previousWheelEvent=null,this.wheelStopEventTimer=null,this.wheelAnimationTimer=null,this.isPanning=!1,this.isWheelPanning=!1,this.startCoords=null,this.panStartPosition=null,this.lastTouch=null,this.isPinching=!1,this.distance=null,this.lastDistance=null,this.pinchStartDistance=null,this.pinchStartScale=null,this.pinchMidpoint=null,this.pinchPreviousCenter=null,this.doubleClickStopEventTimer=null,this.velocity=null,this.velocityTime=null,this.lastMousePosition=null,this.isAnimating=!1,this.animation=null,this.pressedKeys={},this.mount=function(){n.initializeWindowEvents()},this.unmount=function(){n.cleanupWindowEvents()},this.update=function(r){n.props=r,n.wrapperComponent&&n.contentComponent&&Gu(n,n.state.scale),n.setup=CM(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=aw(),u=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,d=u==null?void 0:u.defaultView;(i=n.wrapperComponent)===null||i===void 0||i.addEventListener("wheel",n.onWheelPanning,l),(s=n.wrapperComponent)===null||s===void 0||s.addEventListener("keyup",n.setKeyUnPressed,l),(o=n.wrapperComponent)===null||o===void 0||o.addEventListener("keydown",n.setKeyPressed,l),d==null||d.addEventListener("mousedown",n.onPanningStart,l),d==null||d.addEventListener("mousemove",n.onPanning,l),d==null||d.addEventListener("mouseup",n.onPanningStop,l),u==null||u.addEventListener("mouseleave",n.clearPanning,l),d==null||d.addEventListener("keyup",n.setKeyUnPressed,l),d==null||d.addEventListener("keydown",n.setKeyPressed,l),d==null||d.addEventListener("blur",n.handleWindowBlur)},this.cleanupWindowEvents=function(){var r,i,s,o,l,u=aw(),d=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,h=d==null?void 0:d.defaultView;h==null||h.removeEventListener("mousedown",n.onPanningStart,u),h==null||h.removeEventListener("mousemove",n.onPanning,u),h==null||h.removeEventListener("mouseup",n.onPanningStop,u),d==null||d.removeEventListener("mouseleave",n.clearPanning,u),h==null||h.removeEventListener("keyup",n.setKeyUnPressed,u),h==null||h.removeEventListener("keydown",n.setKeyPressed,u),h==null||h.removeEventListener("blur",n.handleWindowBlur),document.removeEventListener("mouseleave",n.clearPanning,u),(i=n.wrapperComponent)===null||i===void 0||i.removeEventListener("wheel",n.onWheelPanning,u),(s=n.wrapperComponent)===null||s===void 0||s.removeEventListener("keyup",n.setKeyUnPressed,u),(o=n.wrapperComponent)===null||o===void 0||o.removeEventListener("keydown",n.setKeyPressed,u),Ws(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=aw();r.addEventListener("wheel",n.onWheelZoom,i),r.addEventListener("dblclick",n.onDoubleClick,i),r.addEventListener("touchstart",n.onTouchPanningStart,i),r.addEventListener("touchmove",n.onTouchPanning,i),r.addEventListener("touchend",n.onTouchPanningStop,i)},this.handleInitialize=function(r){var i=n.setup.centerOnInit;n.applyTransformation(),n.onInitCallbacks.forEach(function(s){return s(Cn(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(Cn(n))}),n.setCenter(),(s=n.observer)===null||s===void 0||s.disconnect())}),setTimeout(function(){var s;(s=n.observer)===null||s===void 0||s.disconnect()},5e3),n.observer.observe(r))},this.onWheelZoom=function(r){var i=n.setup.disabled;if(!i){n.syncModifierKeys(r);var s=b3(n,r);s&&(Lae(n,r),Iae(n,r),zae(n,r))}},this.onWheelPanning=function(r){var i=n.props.onPanning,s=n.setup.trackPadPanning,o=s.lockAxisX,l=s.lockAxisY;n.syncModifierKeys(r);var u=kae(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,h=d.positionX,p=d.positionY,y=h-r.deltaX,v=p-r.deltaY,_=o?h:y,w=l?p:v,x=n.setup.autoAlignment,E=x.sizeX,k=x.sizeY,R=ul(n,E),A=ul(n,k);_===h&&w===p||(Bae(n,r),h3(n,_,w,R,A),On(Cn(n),r,i),jae(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=bM(n,r);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.button===0&&!n.setup.panning.allowLeftClickPan||r.button===1&&!n.setup.panning.allowMiddleClickPan||r.button===2&&!n.setup.panning.allowRightClickPan||(r.preventDefault(),r.stopPropagation(),Ws(n),SM(n,r),On(Cn(n),r,s)))}}},this.onPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(!i){if(n.syncModifierKeys(r),n.isPanning&&r.buttons===0){n.clearPanning(r);return}var o=_M(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),xM(n,r.clientX,r.clientY,Ja.MOUSE),On(Cn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(fae(n,i),On(Cn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=Nae(n,r);o&&(Fae(n,r),Ws(n),On(Cn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=Mae(n);o&&(r.preventDefault(),r.stopPropagation(),$ae(n,r),On(Cn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(Hae(n),On(Cn(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,Ws(n);var h=r.touches,p=h.length===1,y=h.length===2,v=bM(n,r);if(p){if(!v)return;Ws(n),SM(n,r),On(Cn(n),r,l)}y&&n.onPinchStart(r)}}},this.onTouchPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(n.isPanning&&r.touches.length===1){if(i)return;var o=_M(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];xM(n,l.clientX,l.clientY,Ja.TOUCH),On(Cn(n),r,s)}else r.touches.length>1&&n.onPinch(r)},this.onTouchPanningStop=function(r){n.onPanningStop(r),n.onPinchStop(r)},this.onDoubleClick=function(r){var i=n.setup.disabled;if(!i){var s=Vae(n,r);s&&qae(n,r)}},this.clearPanning=function(r){n.isPanning&&n.onPanningStop(r)},this.handleWindowBlur=function(){n.pressedKeys={},n.isPanning&&(n.isPanning=!1,n.startCoords=null)},this.syncModifierKeys=function(r){var i=r.ctrlKey,s=r.metaKey,o=r.shiftKey,l=r.altKey;typeof i=="boolean"&&(n.pressedKeys.Control=i),typeof s=="boolean"&&(n.pressedKeys.Meta=s),typeof o=="boolean"&&(n.pressedKeys.Shift=o),typeof l=="boolean"&&(n.pressedKeys.Alt=l)},this.setKeyPressed=function(r){n.pressedKeys[r.key]=!0},this.setKeyUnPressed=function(r){n.pressedKeys[r.key]=!1},this.isPressingKeys=function(r){return typeof r=="function"?r(Object.entries(n.pressedKeys).filter(function(i){var s=i[1];return s}).map(function(i){var s=i[0];return s})):r.length?!!r.every(function(i){return n.pressedKeys[i]}):!0},this.setCenter=function(){if(n.wrapperComponent&&n.contentComponent){var r=q1(n.state.scale,n.wrapperComponent,n.contentComponent);n.setState(r.scale,r.positionX,r.positionY)}},this.handleTransformStyles=function(r,i,s){return n.props.customTransform?n.props.customTransform(r,i,s):y3(r,i,s)},this.getContext=function(){return Cn(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:Cn(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=Cn(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),On(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=Cn(n);On(s,void 0,n.props.onInit),Eae(n.props.ref,s)},this.props=t,this.setup=CM(this.props),this.state=p3(this.props)}return e})(),ey=Ze.createContext(null),Kae=function(e,t){return typeof e=="function"?e(t):e},Gae=Ze.forwardRef(function(e,t){var n=b.useRef(new Yae(e)).current,r=Kae(e.children,Y0(n));return b.useImperativeHandle(t,function(){return Y0(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),g.jsx(ey.Provider,Ts({value:n},{children:r}))});Ze.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(ey);return b.useEffect(function(){return r.onChange(function(i){if(n.current){var s=0,o=0;n.current.style.transform=r.handleTransformStyles(s,o,1/i.instance.state.scale)}})},[r]),g.jsx("div",Ts({},e,{ref:Cae([n,t])}))});function Xae(e,t){t===void 0&&(t={});var n=t.insertAt;if(!(typeof document>"u")){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",n==="top"&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var Zae=`.transform-component-module_wrapper__SPB86 {
513
513
  position: relative;
@@ -639,12 +639,12 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
639
639
  `+t.stack):t},0)}}addListener(t){return this.listeners.push(t),()=>{this._removeListener(t)}}emit(t){this.listeners.forEach(n=>{n(t)})}_removeListener(t){this.listeners.splice(this.listeners.indexOf(t),1)}setUnexpectedErrorHandler(t){this.unexpectedErrorHandler=t}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(t){this.unexpectedErrorHandler(t),this.emit(t)}onUnexpectedExternalError(t){this.unexpectedErrorHandler(t)}},Uhe=new Hhe;function Rw(e){Whe(e)||Uhe.onUnexpectedError(e)}var IS="Canceled";function Whe(e){return e instanceof qhe?!0:e instanceof Error&&e.name===IS&&e.message===IS}var qhe=class extends Error{constructor(){super(IS),this.name=this.message}},R2=class zS extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof zS)return t;let n=new zS;return n.message=t.message,n.stack=t.stack,n}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}};function Vhe(e,t){let n=this,r=!1,i;return function(){return r||(r=!0,t||(i=e.apply(n,arguments))),i}}var Yhe;(e=>{function t(s){return s<0}e.isLessThan=t;function n(s){return s<=0}e.isLessThanOrEqual=n;function r(s){return s>0}e.isGreaterThan=r;function i(s){return s===0}e.isNeitherLessOrGreaterThan=i,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(Yhe||(Yhe={}));var B5;(e=>{function t(A){return A&&typeof A=="object"&&typeof A[Symbol.iterator]=="function"}e.is=t;let n=Object.freeze([]);function r(){return n}e.empty=r;function*i(A){yield A}e.single=i;function s(A){return t(A)?A:i(A)}e.wrap=s;function o(A){return A||n}e.from=o;function*l(A){for(let I=A.length-1;I>=0;I--)yield A[I]}e.reverse=l;function u(A){return!A||A[Symbol.iterator]().next().done===!0}e.isEmpty=u;function d(A){return A[Symbol.iterator]().next().value}e.first=d;function h(A,I){let T=0;for(let H of A)if(I(H,T++))return!0;return!1}e.some=h;function p(A,I){for(let T of A)if(I(T))return T}e.find=p;function*y(A,I){for(let T of A)I(T)&&(yield T)}e.filter=y;function*v(A,I){let T=0;for(let H of A)yield I(H,T++)}e.map=v;function*_(A,I){let T=0;for(let H of A)yield*I(H,T++)}e.flatMap=_;function*w(...A){for(let I of A)yield*I}e.concat=w;function x(A,I,T){let H=T;for(let D of A)H=I(H,D);return H}e.reduce=x;function*E(A,I,T=A.length){for(I<0&&(I+=A.length),T<0?T+=A.length:T>A.length&&(T=A.length);I<T;I++)yield A[I]}e.slice=E;function k(A,I=Number.POSITIVE_INFINITY){let T=[];if(I===0)return[T,A];let H=A[Symbol.iterator]();for(let D=0;D<I;D++){let W=H.next();if(W.done)return[T,e.empty()];T.push(W.value)}return[T,{[Symbol.iterator](){return H}}]}e.consume=k;async function R(A){let I=[];for await(let T of A)I.push(T);return Promise.resolve(I)}e.asyncToArray=R})(B5||(B5={}));function j5(e){if(B5.is(e)){let t=[];for(let n of e)if(n)try{n.dispose()}catch(r){t.push(r)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"Encountered errors while disposing of store");return Array.isArray(e)?[]:e}else if(e)return e.dispose(),e}function Khe(...e){return F5(()=>j5(e))}function F5(e){return{dispose:Vhe(()=>{e()})}}var $5=class H5{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{j5(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?H5.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}delete(t){if(t){if(t===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(t),t.dispose()}}deleteAndLeak(t){t&&this._toDispose.has(t)&&(this._toDispose.delete(t),void 0)}};$5.DISABLE_DISPOSED_WARNING=!1;var oE=$5,sv=class{constructor(){this._store=new oE,this._store}dispose(){this._store.dispose()}_register(t){if(t===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(t)}};sv.None=Object.freeze({dispose(){}});var Ghe=globalThis.performance&&typeof globalThis.performance.now=="function",Xhe=class U5{static create(t){return new U5(t)}constructor(t){this._now=Ghe&&t===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},Zhe;(e=>{e.None=()=>sv.None;function t(O,M){return p(O,()=>{},0,void 0,!0,void 0,M)}e.defer=t;function n(O){return(M,z=null,L)=>{let N=!1,q;return q=O(Y=>{if(!N)return q?q.dispose():N=!0,M.call(z,Y)},null,L),N&&q.dispose(),q}}e.once=n;function r(O,M,z){return d((L,N=null,q)=>O(Y=>L.call(N,M(Y)),null,q),z)}e.map=r;function i(O,M,z){return d((L,N=null,q)=>O(Y=>{M(Y),L.call(N,Y)},null,q),z)}e.forEach=i;function s(O,M,z){return d((L,N=null,q)=>O(Y=>M(Y)&&L.call(N,Y),null,q),z)}e.filter=s;function o(O){return O}e.signal=o;function l(...O){return(M,z=null,L)=>{let N=Khe(...O.map(q=>q(Y=>M.call(z,Y))));return h(N,L)}}e.any=l;function u(O,M,z,L){let N=z;return r(O,q=>(N=M(N,q),N),L)}e.reduce=u;function d(O,M){let z,L={onWillAddFirstListener(){z=O(N.fire,N)},onDidRemoveLastListener(){z==null||z.dispose()}},N=new Ua(L);return M==null||M.add(N),N.event}function h(O,M){return M instanceof Array?M.push(O):M&&M.add(O),O}function p(O,M,z=100,L=!1,N=!1,q,Y){let $,P,V,G=0,B,K={leakWarningThreshold:q,onWillAddFirstListener(){$=O(te=>{G++,P=M(P,te),L&&!V&&(ee.fire(P),P=void 0),B=()=>{let J=P;P=void 0,V=void 0,(!L||G>1)&&ee.fire(J),G=0},typeof z=="number"?(clearTimeout(V),V=setTimeout(B,z)):V===void 0&&(V=0,queueMicrotask(B))})},onWillRemoveListener(){N&&G>0&&(B==null||B())},onDidRemoveLastListener(){B=void 0,$.dispose()}},ee=new Ua(K);return Y==null||Y.add(ee),ee.event}e.debounce=p;function y(O,M=0,z){return e.debounce(O,(L,N)=>L?(L.push(N),L):[N],M,void 0,!0,void 0,z)}e.accumulate=y;function v(O,M=(L,N)=>L===N,z){let L=!0,N;return s(O,q=>{let Y=L||!M(q,N);return L=!1,N=q,Y},z)}e.latch=v;function _(O,M,z){return[e.filter(O,M,z),e.filter(O,L=>!M(L),z)]}e.split=_;function w(O,M=!1,z=[],L){let N=z.slice(),q=O(P=>{N?N.push(P):$.fire(P)});L&&L.add(q);let Y=()=>{N==null||N.forEach(P=>$.fire(P)),N=null},$=new Ua({onWillAddFirstListener(){q||(q=O(P=>$.fire(P)),L&&L.add(q))},onDidAddFirstListener(){N&&(M?setTimeout(Y):Y())},onDidRemoveLastListener(){q&&q.dispose(),q=null}});return L&&L.add($),$.event}e.buffer=w;function x(O,M){return(z,L,N)=>{let q=M(new k);return O(function(Y){let $=q.evaluate(Y);$!==E&&z.call(L,$)},void 0,N)}}e.chain=x;let E=Symbol("HaltChainable");class k{constructor(){this.steps=[]}map(M){return this.steps.push(M),this}forEach(M){return this.steps.push(z=>(M(z),z)),this}filter(M){return this.steps.push(z=>M(z)?z:E),this}reduce(M,z){let L=z;return this.steps.push(N=>(L=M(L,N),L)),this}latch(M=(z,L)=>z===L){let z=!0,L;return this.steps.push(N=>{let q=z||!M(N,L);return z=!1,L=N,q?N:E}),this}evaluate(M){for(let z of this.steps)if(M=z(M),M===E)break;return M}}function R(O,M,z=L=>L){let L=(...$)=>Y.fire(z(...$)),N=()=>O.on(M,L),q=()=>O.removeListener(M,L),Y=new Ua({onWillAddFirstListener:N,onDidRemoveLastListener:q});return Y.event}e.fromNodeEventEmitter=R;function A(O,M,z=L=>L){let L=(...$)=>Y.fire(z(...$)),N=()=>O.addEventListener(M,L),q=()=>O.removeEventListener(M,L),Y=new Ua({onWillAddFirstListener:N,onDidRemoveLastListener:q});return Y.event}e.fromDOMEventEmitter=A;function I(O){return new Promise(M=>n(O)(M))}e.toPromise=I;function T(O){let M=new Ua;return O.then(z=>{M.fire(z)},()=>{M.fire(void 0)}).finally(()=>{M.dispose()}),M.event}e.fromPromise=T;function H(O,M){return O(z=>M.fire(z))}e.forward=H;function D(O,M,z){return M(z),O(L=>M(L))}e.runAndSubscribe=D;class W{constructor(M,z){this._observable=M,this._counter=0,this._hasChanged=!1;let L={onWillAddFirstListener:()=>{M.addObserver(this)},onDidRemoveLastListener:()=>{M.removeObserver(this)}};this.emitter=new Ua(L),z&&z.add(this.emitter)}beginUpdate(M){this._counter++}handlePossibleChange(M){}handleChange(M,z){this._hasChanged=!0}endUpdate(M){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function U(O,M){return new W(O,M).emitter.event}e.fromObservable=U;function F(O){return(M,z,L)=>{let N=0,q=!1,Y={beginUpdate(){N++},endUpdate(){N--,N===0&&(O.reportChanges(),q&&(q=!1,M.call(z)))},handlePossibleChange(){},handleChange(){q=!0}};O.addObserver(Y),O.reportChanges();let $={dispose(){O.removeObserver(Y)}};return L instanceof oE?L.add($):Array.isArray(L)&&L.push($),$}}e.fromObservableLight=F})(Zhe||(Zhe={}));var BS=class jS{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${jS._idPool++}`,jS.all.add(this)}start(t){this._stopWatch=new Xhe,this.listenerCount=t}stop(){if(this._stopWatch){let t=this._stopWatch.elapsed();this.durations.push(t),this.elapsedOverall+=t,this.invocationCount+=1,this._stopWatch=void 0}}};BS.all=new Set,BS._idPool=0;var Qhe=BS,Jhe=-1,W5=class q5{constructor(t,n,r=(q5._idPool++).toString(16).padStart(3,"0")){this._errorHandler=t,this.threshold=n,this.name=r,this._warnCountdown=0}dispose(){var t;(t=this._stacks)==null||t.clear()}check(t,n){let r=this.threshold;if(r<=0||n<r)return;this._stacks||(this._stacks=new Map);let i=this._stacks.get(t.value)||0;if(this._stacks.set(t.value,i+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=r*.5;let[s,o]=this.getMostFrequentStack(),l=`[${this.name}] potential listener LEAK detected, having ${n} listeners already. MOST frequent listener (${o}):`;console.warn(l),console.warn(s);let u=new nfe(l,s);this._errorHandler(u)}return()=>{let s=this._stacks.get(t.value)||0;this._stacks.set(t.value,s-1)}}getMostFrequentStack(){if(!this._stacks)return;let t,n=0;for(let[r,i]of this._stacks)(!t||n<i)&&(t=[r,i],n=i);return t}};W5._idPool=1;var efe=W5,tfe=class V5{constructor(t){this.value=t}static create(){let t=new Error;return new V5(t.stack??"")}print(){console.warn(this.value.split(`
640
640
  `).slice(2).join(`
641
641
  `))}},nfe=class extends Error{constructor(t,n){super(t),this.name="ListenerLeakError",this.stack=n}},rfe=class extends Error{constructor(t,n){super(t),this.name="ListenerRefusalError",this.stack=n}},ife=0,Aw=class{constructor(t){this.value=t,this.id=ife++}},sfe=2,ofe,Ua=class{constructor(e){var t,n,r,i;this._size=0,this._options=e,this._leakageMon=(t=this._options)!=null&&t.leakWarningThreshold?new efe((e==null?void 0:e.onListenerError)??Rw,((n=this._options)==null?void 0:n.leakWarningThreshold)??Jhe):void 0,this._perfMon=(r=this._options)!=null&&r._profName?new Qhe(this._options._profName):void 0,this._deliveryQueue=(i=this._options)==null?void 0:i.deliveryQueue}dispose(){var e,t,n,r;this._disposed||(this._disposed=!0,((e=this._deliveryQueue)==null?void 0:e.current)===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),(n=(t=this._options)==null?void 0:t.onDidRemoveLastListener)==null||n.call(t),(r=this._leakageMon)==null||r.dispose())}get event(){return this._event??(this._event=(e,t,n)=>{var o,l,u,d,h;if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let p=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(p);let y=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],v=new rfe(`${p}. HINT: Stack shows most frequent listener (${y[1]}-times)`,y[0]);return(((o=this._options)==null?void 0:o.onListenerError)||Rw)(v),sv.None}if(this._disposed)return sv.None;t&&(e=e.bind(t));let r=new Aw(e),i;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(r.stack=tfe.create(),i=this._leakageMon.check(r.stack,this._size+1)),this._listeners?this._listeners instanceof Aw?(this._deliveryQueue??(this._deliveryQueue=new afe),this._listeners=[this._listeners,r]):this._listeners.push(r):((u=(l=this._options)==null?void 0:l.onWillAddFirstListener)==null||u.call(l,this),this._listeners=r,(h=(d=this._options)==null?void 0:d.onDidAddFirstListener)==null||h.call(d,this)),this._size++;let s=F5(()=>{i==null||i(),this._removeListener(r)});return n instanceof oE?n.add(s):Array.isArray(n)&&n.push(s),s}),this._event}_removeListener(e){var i,s,o,l;if((s=(i=this._options)==null?void 0:i.onWillRemoveListener)==null||s.call(i,this),!this._listeners)return;if(this._size===1){this._listeners=void 0,(l=(o=this._options)==null?void 0:o.onDidRemoveLastListener)==null||l.call(o,this),this._size=0;return}let t=this._listeners,n=t.indexOf(e);if(n===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,t[n]=void 0;let r=this._deliveryQueue.current===this;if(this._size*sfe<=t.length){let u=0;for(let d=0;d<t.length;d++)t[d]?t[u++]=t[d]:r&&(this._deliveryQueue.end--,u<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=u}}_deliver(e,t){var r;if(!e)return;let n=((r=this._options)==null?void 0:r.onListenerError)||Rw;if(!n){e.value(t);return}try{e.value(t)}catch(i){n(i)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){var t,n,r,i;if((t=this._deliveryQueue)!=null&&t.current&&(this._deliverQueue(this._deliveryQueue),(n=this._perfMon)==null||n.stop()),(r=this._perfMon)==null||r.start(this._size),this._listeners)if(this._listeners instanceof Aw)this._deliver(this._listeners,e);else{let s=this._deliveryQueue;s.enqueue(this,e,this._listeners.length),this._deliverQueue(s)}(i=this._perfMon)==null||i.stop()}hasListeners(){return this._size>0}},afe=class{constructor(){this.i=-1,this.end=0}enqueue(t,n,r){this.i=0,this.end=r,this.current=t,this.value=n}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Bu=class Rg{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new Ua,this.onChange=this._onChange.event;let t=new $he;this.register(t),this._active=t.version,this._activeProvider=t}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,n,r=!1){return(t&16777215)<<3|(n&3)<<1|(r?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let n=0,r=0,i=t.length;for(let s=0;s<i;++s){let o=t.charCodeAt(s);if(55296<=o&&o<=56319){if(++s>=i)return n+this.wcwidth(o);let d=t.charCodeAt(s);56320<=d&&d<=57343?o=(o-55296)*1024+d-56320+65536:n+=this.wcwidth(d)}let l=this.charProperties(o,r),u=Rg.extractWidth(l);Rg.extractShouldJoin(l)&&(u-=Rg.extractWidth(r)),n+=u,r=l}return n}charProperties(t,n){return this._activeProvider.charProperties(t,n)}},aE=0,Y5=-3,Ef=class{constructor(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}},lfe=class{constructor(e,t){this.tag=0,this.bitcount=0,this.destLen=0,this.sourceIndex=0,this.source=e,this.dest=t,this.ltree=new Ef,this.dtree=new Ef}},K5=new Ef,G5=new Ef,lE=new Uint8Array(30),cE=new Uint16Array(30),X5=new Uint8Array(30),Z5=new Uint16Array(30),cfe=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),A2=new Ef,oo=new Uint8Array(320);function Q5(e,t,n,r){var i,s;for(i=0;i<n;++i)e[i]=0;for(i=0;i<30-n;++i)e[i+n]=i/n|0;for(s=r,i=0;i<30;++i)t[i]=s,s+=1<<e[i]}function ufe(e,t){var n;for(n=0;n<7;++n)e.table[n]=0;for(e.table[7]=24,e.table[8]=152,e.table[9]=112,n=0;n<24;++n)e.trans[n]=256+n;for(n=0;n<144;++n)e.trans[24+n]=n;for(n=0;n<8;++n)e.trans[168+n]=280+n;for(n=0;n<112;++n)e.trans[176+n]=144+n;for(n=0;n<5;++n)t.table[n]=0;for(t.table[5]=32,n=0;n<32;++n)t.trans[n]=n}var N2=new Uint16Array(16);function Nw(e,t,n,r){var i,s;for(i=0;i<16;++i)e.table[i]=0;for(i=0;i<r;++i)e.table[t[n+i]]++;for(e.table[0]=0,s=0,i=0;i<16;++i)N2[i]=s,s+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[N2[t[n+i]]++]=i)}function dfe(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function mo(e,t,n){if(!t)return n;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var r=e.tag&65535>>>16-t;return e.tag>>>=t,e.bitcount-=t,r+n}function FS(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var n=0,r=0,i=0,s=e.tag;do r=2*r+(s&1),s>>>=1,++i,n+=t.table[i],r-=t.table[i];while(r>=0);return e.tag=s,e.bitcount-=i,t.trans[n+r]}function hfe(e,t,n){var r,i,s,o,l,u;for(r=mo(e,5,257),i=mo(e,5,1),s=mo(e,4,4),o=0;o<19;++o)oo[o]=0;for(o=0;o<s;++o){var d=mo(e,3,0);oo[cfe[o]]=d}for(Nw(A2,oo,0,19),l=0;l<r+i;){var h=FS(e,A2);switch(h){case 16:var p=oo[l-1];for(u=mo(e,2,3);u;--u)oo[l++]=p;break;case 17:for(u=mo(e,3,3);u;--u)oo[l++]=0;break;case 18:for(u=mo(e,7,11);u;--u)oo[l++]=0;break;default:oo[l++]=h;break}}Nw(t,oo,0,r),Nw(n,oo,r,i)}function M2(e,t,n){for(;;){var r=FS(e,t);if(r===256)return aE;if(r<256)e.dest[e.destLen++]=r;else{var i,s,o,l;for(r-=257,i=mo(e,lE[r],cE[r]),s=FS(e,n),o=e.destLen-mo(e,X5[s],Z5[s]),l=o;l<o+i;++l)e.dest[e.destLen++]=e.dest[l]}}}function ffe(e){for(var t,n,r;e.bitcount>8;)e.sourceIndex--,e.bitcount-=8;if(t=e.source[e.sourceIndex+1],t=256*t+e.source[e.sourceIndex],n=e.source[e.sourceIndex+3],n=256*n+e.source[e.sourceIndex+2],t!==(~n&65535))return Y5;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,aE}function pfe(e,t){var n=new lfe(e,t),r,i,s;do{switch(r=dfe(n),i=mo(n,2,0),i){case 0:s=ffe(n);break;case 1:s=M2(n,K5,G5);break;case 2:hfe(n,n.ltree,n.dtree),s=M2(n,n.ltree,n.dtree);break;default:s=Y5}if(s!==aE)throw new Error("Data error")}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}ufe(K5,G5);Q5(lE,cE,4,3);Q5(X5,Z5,2,1);lE[28]=0;cE[28]=258;var O2=pfe,uE=11,rc=5,mfe=uE-rc,gfe=65536>>uE,vfe=1<<mfe,yfe=vfe-1,Ag=2,bfe=1<<rc,Mw=bfe-1,J5=65536>>rc,_fe=1024>>rc,wfe=J5+_fe,Sfe=wfe,xfe=32,Efe=Sfe+xfe,Cfe=1<<Ag,kfe=new Uint8Array(new Uint32Array([305419896]).buffer)[0]===18,Tfe=class{constructor(e){let t=new DataView(e.buffer);this.highStart=t.getUint32(0,!0),this.errorValue=t.getUint32(4,!0);let n=t.getUint32(8,!0);if(e=e.subarray(12),e=O2(e,new Uint8Array(n)),e=O2(e,new Uint8Array(n)),kfe){let r=e.length;for(let i=0;i<r;i+=4){let s=e[i];e[i]=e[i+3],e[i+3]=s;let o=e[i+1];e[i+1]=e[i+2],e[i+2]=o}}this.data=new Uint32Array(e.buffer)}get(e){let t;return e<0||e>1114111?this.errorValue:e<55296||e>56319&&e<=65535?(t=(this.data[e>>rc]<<Ag)+(e&Mw),this.data[t]):e<=65535?(t=(this.data[J5+(e-55296>>rc)]<<Ag)+(e&Mw),this.data[t]):e<this.highStart?(t=this.data[Efe-gfe+(e>>uE)],t=this.data[t+(e>>rc&yfe)],t=(t<<Ag)+(e&Mw),this.data[t]):this.data[this.data.length-Cfe]}},Rfe=Tfe,Afe="AAARAAAAAABwxwAAAb4LQfTtmw+sVmUdx58LL/ffe/kjzNBV80gW1F3yR+6CvbJiypoZa0paWmAWSluErSBbFtYkkuZykq6QamGJ4WRqo2kFGy6dYWtEq6G1MFAJbRbOVTQr+x7f5+x97q/n/3me87wXzm/3s+f/7/d7/p7znnvOlvGMbQM7wIPgEbAPHABPgcPgefAS+BfYwuv/F/Q2OulBxKcK6TMRPxu8FcwFbwcjYCFYDC4Cl4ArwNXgGvBJsA58UdBDwy+jbBO4La8DtoEd4H7wkNBuN+KPgn3gADgIngaHwFHwF/AyeAWMm4C+TGi3LdiJ/EnIex04A2RgFpgD5oKFYDG4CLwHXAo+IKSvAqt4/evA9bz9jWA6+Cq3dyvCP8HWNwX93wF38/ROcD94SCjP2+1B+BiPP4HwgOD/7xD/I08fRniMx48jPAFeBeuF+n29jE0G08FZvaPHYWZvh9mcEfAOjlhXx/qGfd2QvLO3zccmtMnzliC9lPt+GenD1nyMiK/LNf1cycs+gfAzPJ6vtxe4jhuQtx5sBLeA28G3eb3v8/Beif4HkPewxu5G6N/rMP4qfgEdvwZPgj+AZ8Cx3nYfxiE8Dk6AV0FfH/YEOB28AbwJDIPzQAtcAC4Gl/Z19F+J+NVCehWPr0b46b7RvixvdPg8yr7U10l/BfFN4La8DdgGdoAHwU/AI2AfOACeAofB8+AlcAKwfvyBKeCM/o7NrF9PXmdWv9/Ynot2I7ztIg8dF5I2a8i63CjZU+9Fm2Wcy4U4ZQVYyeOrwVoev57UuxHcJKRvFuJXgnU8/nUebtbYrKmpCUOx31P7UVNTU1NTU1NTU1OGLTz8Xr/77+W7+9vP0or0MxPMbXaizY8FW3sQ3wseB/t5/kGEh8DR/vbzwL8i/Af4Dy8fP8BYE0weaKenI/wV/DhrQG97JspngzlgLpgHzgPzwUhdVpfVZXVZXRa87HxwAVgQ4Pn5WEd85l5TUzOasvezFw/E3b/LoP9D4CpwrcTWWsGXNQOj748/G9k3G56d1KYxmbELwQbwKFiJvBM8nDWlHa5E+AOwCzwLzjkNeeB28NvTeB1OYyr0gQ1g99R23nGE50xj7MPgc+A+8K5Bxj4FHgB/G2z/T9XEzCZjd/S0WYX4Pc3/r/Nn5I0f6qQXIP5x8ENwBMyYyNhHJ3b0pOCuLrBvM941NTU1JyNHEp+BrC8dMyalt1/m3uWfhmeULzRGp9d3wf0WZSN8+prCr60Wz09tuNmx35sl9Y825HXvRN39KNveaL8flb9f913kbec67kHeTsR3gYcH2uV7ED4m2HhCYi/X9ZuBzvuXv0f8iKIfx5B/XCg7gTgbVPdvAsomCuWnD45eK28UyvL3Jt+s0fU2TVnOXJQvJHUWIb0ELAWXgCt4+UcMumSsEtpch/g6ouMGpG/ieZsc9N/q4YsLd3D9WyPbsWEbfNgO7hN82TWY/n8xKbmsC3xQsYKf+7sjrx2TH+u4H3vhx+OO6+X9hmtXN7C/4r15EPaeBs9J7L7YBeeED/k7wn8fbIf/Rji+yVizmd4vW6bB19cb/PU9w7MxMA60bzPHgM8+zG623+OnzOf55yNc3Gw/k303wveBy3nZcoTXgNVgLfiCRNcG5N3SbIebwZ08fhe4l8d/BH7K4yI/4+HPwS/BAfBks+PzIaHuc3x+ivSL4GUyZ68I6fwZYRNMG2qnz+Th2QjfMtTx/1zE5w61nyN+Q7C3aKgdin1dgrylYBn4INdhGn/Z2FfFiqH01/SUXMvnPD+jC+j85N/RqRhR/DYaS6T+P09K1mD+vzW+5zVqqeVUl0wTz2lK8odJHRGXfBufdGLSoSo3+ZFJ6sl0qvJVNmhI4z4i06mrZ6uT1le1z5h5HE3tMiHPtQ5javu+ItMXUr/MXpmwmyRL3D6U7UwIMyYfczGu0qdqb2pbhcw4xQkhWQBMerrZ/liXrGTbsQwTwrEu4zSczKLrd7fCSKiKn+zSo8BWXMe8myXWOivrUxWi60OPoQ7VIasbQ0S/Ukk3rZVullNhHEL1rYoxUF0PTfm6elWJzq54ZsU4z11ohOy0oxT2izFqCNj4TesXcWZo6+Jfqr1O+1O1beqDagypj2J9F1u2daucj3Eknmq/6PaHrK7Mb1o35DiW1a/a76LuhlDXZX25SOz11S33ErKxDb2/fc/bFKI6axskn+4/W90u9mOtbRf7smsoTdvOfwoRz0t6DaP9k81v6P7Re5aUQudTd303rX+bZzBl97/KR7E+Xbux9lLI+aNr1PfaYLpPDiW2/vrYTX1drMIeXbMye6HXlw8292Jl7ZXxLxRlxXbcaH9drjFlxfa3Qozx8NWRi834lPVZbD+SmN7EJPzc9TVCSVXXDps9L+513b2J7fMu176V2YOhx1A3JrJ8KrLxUumpcu5j/lYT+2tzLRVDZmhjO442a1Clu0ox9VPVXzE/lcS4V0k1D6LI1pJsz8fct9SGbO5l/rmKzTlvsxdj3IvRtC2uv0t1fotltvd2VaCy5Sp5m0EhnZG4CCNxXZrWp/VUIrOjapfnNw11ZNI0V/GWzKNuxtzGKKTEtJeR0NVmpojbtBuW5On0u0is9ZMxvU8ZM+8vEyadtu10oqtP9Q4rcJEm85+Two/QkpGwjI6YkgkhtUfzZOW6fFVexuRri+qj9TJJHZkdmW5abiu0rs6uj2TMfmx06bISUj9tZ9Lja8dVQtox6WpxTJKfW3M4MSTmvU4sWy1CU6BF4jIfdNeDjHWuO1lCWIm2Jr2ixNZvklD2fP0Q6+vsmO4hqN1hJvfDtV5G8mTlsvau4qPP1a64L1skT6QYEzEtq0PzGZOfCbSdSmcKTP7Qs86Ej/1hEpelaV6IMdT5ayu2+nT9tmnnO746XbLxE8t0qOrYtJWhmk9bvaLfsrotRVw1PnR+bcafSUKZ6Mps7smobybJLH2R6WqRkJa1DHV0UmbfUcksiSF0HExSpp+uY0zbTklMaCm7blzEtg8h1rNMXNaYi05ZXsbC75sQ/4+aUxFV2jL50Q3jE0rK2rVtN09By8OHoo1vH2LPSdE323mr2sdu0pUZiDkWLRKWnfeQY6taKzHF9n/GPv8jd/0/egiRvYMR24fU79iY3s9Qva9RlYR8n8HHtq9fMcT1HRWfdZXiHd9YInt/iI4PTaf+BimXKvdXYU+3hlRpHzs2dVK/cxhDn+xs0I2jzxjL5kpXz1VU72aLtkK/97sALKyQqu25SshvG6h08/cLrlKswRklKXvvXfa+pZt+y8nah5YUv2Oo/ap/X2URdRfico9K69hcp6r6XaCz5Wo/hs/iNTGF6N6tV92/9ZS0Wba9SlT3pKF/e6W674+x9ly+VRL73cPU8ygb31D3eSqfVd+iqET0y3YMYojoO11XqrTt2nPxmeq1HYeqxkmUMt8DiesjpoTSr+qDrD+qPZDiOZxMdH0pRPX8MFUfQtv0Xbs+a1a1NnRryNZ/2+tsaPG5ZoX0RXZei88yZGdo4UMPj/cwv/kMJboxLISuQbE+1VW12Mx7FWOrW3M9Hv7Y+uxyraPSo8B2TGPuLdOeZha+hBKf8Sjsm/oR+7pmsx/oeOraFWdXleeV6oyl41zm+mgSuq9C6ox1TsU8D+m4dwMmf8v2nz7Tm+fYfj7HV1K/x1HWjquvY+2dllxM64ue87Su772zzbXIVC+WxLZTRR9MdkMTypZNH1z6G0tUvoccwxA+hfLNdV+a7MaQqscztMi+7QnxDZXvd1dldWQOyMbApb1Jd2h91Ffx+y9Xfb7tClokboOvrRhrbVpFFO8z+65t2/u4su9MUx028znH01/TGVDmHAj13W1o+1USw+eUfYtpO+b82rRNsb6oPpV+1fdBqddB6n3WDXvdJDZrJ0QfQp6bsc/kqq4BIddHWXGdN1pmWveh58F1zYUW1zmOITHXWOg1XrZvZSWUf77tq1ofqear6muaT1lIQp3bofabSafJVlnfYo9B6LGr8uzz2Xchvzfw+T9PlgiV/A8=";function Nfe(e){if(typeof Buffer<"u")return Buffer.from(e,"base64");let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<n.length;++r)n[r]=t.charCodeAt(r);return n}var Mfe=new Rfe(Nfe(Afe)),$S=15,HS=0,Ofe=48,Dfe=4,Pfe=0,e4=1,t4=2,US=3,Lfe=4,Ow=5,Dw=6,Pw=7,D2=8,Lw=9,P2=10,Ife=11,zfe=32;function L2(e){return(e&Ofe)>>Dfe}function Bfe(e,t){let n=(e&$S)>>HS,r=(t&$S)>>HS;return jfe(n,r)?r===US?zfe:r+16:r-16}function jfe(e,t){return e>=Ow&&e<=Lw&&(e==Ow&&(t==Ow||t==Dw||t==D2||t==Lw)||(e==D2||e==Dw)&&(t==Dw||t==Pw)||(e==Lw||e==Pw)&&t==Pw)||t==t4||t==P2||e==e4||t==Lfe||e==P2&&t==Ife||t==US&&e==US}function I2(e){return Mfe.get(e)}var n4=class r4{constructor(t=!0){this.ambiguousCharsAreWide=!1,this.version=t?"15-graphemes":"15",this.handleGraphemes=t}charProperties(t,n){if(t>=32&&t<127&&n>>3===0)return r4._plainNarrowProperties;let r=I2(t),i=L2(r),s=!1;if(i>=2?i=i===3||this.ambiguousCharsAreWide||t===65039?2:1:i=1,n!==0){let o=Bu.extractWidth(n);this.handleGraphemes?r=Bfe(Bu.extractCharKind(n),r):r=i===0?1:0,s=r>0,s&&(o>i?i=o:r===32&&(i=2))}return Bu.createPropertyValue(r,i,s)}wcwidth(t){let n=I2(t),r=L2(n),i=(n&$S)>>HS;return i===t4||i===e4?0:r>=2&&(r===3||this.ambiguousCharsAreWide)?2:1}};n4._plainNarrowProperties=Bu.createPropertyValue(Pfe,1,!1);var z2=n4,Ffe=class{constructor(){this._oldVersion=""}activate(e){this._provider15||(this._provider15=new z2(!1)),this._provider15Graphemes||(this._provider15Graphemes=new z2(!0));let t=e.unicode;this._unicode=t,t.register(this._provider15),t.register(this._provider15Graphemes),this._oldVersion=t.activeVersion,t.activeVersion="15-graphemes"}dispose(){this._unicode&&(this._unicode.activeVersion=this._oldVersion)}};const $fe={background:"#1E1E1E",foreground:"#D4D4D4",cursor:"#D4D4D4",cursorAccent:"#1E1E1E",selectionBackground:"#264F78",selectionForeground:void 0,black:"#000000",red:"#CD3131",green:"#0DBC79",yellow:"#E5E510",blue:"#2472C8",magenta:"#BC3FBC",cyan:"#11A8CD",white:"#E5E5E5",brightBlack:"#666666",brightRed:"#F14C4C",brightGreen:"#23D18B",brightYellow:"#F5F543",brightBlue:"#3B8EEA",brightMagenta:"#D670D6",brightCyan:"#29B8DB",brightWhite:"#E5E5E5"},Hfe={matchBackground:"#264F78",matchBorder:"#3B8EEA",matchOverviewRuler:"#3B8EEA",activeMatchBackground:"#7A4E00",activeMatchBorder:"#F5F543",activeMatchColorOverviewRuler:"#F5F543"},Ufe="─│╭╮╰╯";function Wfe(e={}){return{scrollback:5e3,fontFamily:rL,fontSize:e.fontSize??Fu,cursorBlink:!0,cursorStyle:"block",cursorInactiveStyle:"none",disableStdin:!1,theme:$fe,allowProposedApi:!0}}async function i4(e,t={}){await document.fonts.ready;const n=t.fontSize??Fu;try{await document.fonts.load(`${n}px "Sarasa Fixed SC"`,Ufe)}catch{}const r=new khe(Wfe(t)),i=new Mhe,s=new Bhe,o=new Ffe;r.loadAddon(i),r.loadAddon(s),r.loadAddon(o),e.replaceChildren(),r.open(e);const l=()=>{r.refresh(0,r.rows-1)},u=()=>{document.visibilityState==="visible"&&r.refresh(0,r.rows-1)},d=()=>{r.refresh(0,r.rows-1)},h=()=>{r.refresh(0,r.rows-1)};return document.fonts.addEventListener("loadingdone",l),document.addEventListener("visibilitychange",u),window.addEventListener("pageshow",d),window.addEventListener("focus",h),{terminal:r,serializeAddon:i,dispose:()=>{document.fonts.removeEventListener("loadingdone",l),document.removeEventListener("visibilitychange",u),window.removeEventListener("pageshow",d),window.removeEventListener("focus",h),r.dispose()}}}function qfe(e,t,n){return e.options.fontSize===t?!1:(e.options.fontSize=t,requestAnimationFrame(()=>n==null?void 0:n()),!0)}const s4="pty-review-snapshot";function Vfe(e){return Array.from(e.children).find(t=>t instanceof HTMLElement&&t.classList.contains("xterm-rows")&&t.dataset.slot!==s4)??null}function Yfe(e){for(const t of e.querySelectorAll('[class*="xterm-cursor"]'))for(const n of Array.from(t.classList))n.startsWith("xterm-cursor")&&t.classList.remove(n);e.classList.remove("xterm-focus")}function Kfe(e){let t=null;const n=()=>{t==null||t.remove(),t=null};return{capture:()=>{const i=e.querySelector(".xterm-screen");if(!i)return!1;const s=Vfe(i);if(!s)return!1;const o=s.cloneNode(!0);Yfe(o);const l=document.createElement("div");l.dataset.slot=s4,l.setAttribute("aria-hidden","true"),Object.assign(l.style,{position:"absolute",inset:"0",overflow:"hidden",pointerEvents:"none",backgroundColor:getComputedStyle(i).backgroundColor}),l.append(o);const u=Array.from(i.children).find(d=>d instanceof HTMLElement&&d.classList.contains("xterm-selection"));return i.insertBefore(l,u??null),t==null||t.remove(),t=l,!0},clear:n,dispose:n}}const o4=28,a4=14;function Qm(e,t,n){const r=Math.min(1,Math.max(0,1-e/t));return Math.ceil(n*r)}function l4({pointerX:e,pointerY:t,rect:n,scrollLeft:r,scrollTop:i,scrollWidth:s,scrollHeight:o,clientWidth:l,clientHeight:u,edgePx:d=o4,maxSpeedPx:h=a4}){let p=0;const y=e-n.left,v=n.right-e;if(y<d&&r>0)p=-Qm(y,d,h);else if(v<d){const E=Math.max(0,s-l);r<E&&(p=Qm(v,d,h))}let _=0;const w=t-n.top,x=n.bottom-t;if(w<d&&i>0)_=-Qm(w,d,h);else if(x<d){const E=Math.max(0,o-u);i<E&&(_=Qm(x,d,h))}return{dx:p,dy:_}}const Gfe=o4,Xfe=a4;function Zfe(e){var T,H,D,W;const{container:t,host:n,edgePx:r=Gfe,maxSpeedPx:i=Xfe,onHorizontalScrollIntent:s,requestFrame:o=U=>requestAnimationFrame(U),cancelFrame:l=U=>cancelAnimationFrame(U)}=e;let u=!1,d=0,h=0,p=null,y=0,v="unknown",_=null,w=null,x=null;const E=()=>{if(x&&x.isConnected)return x;const U=n.querySelector(".xterm-screen");return x=U??n,v=U?"xterm-screen":"host",x},k=()=>{u=!1,p!==null&&(l(p),p=null)},R=()=>{if(p=null,!u)return;const U=t.getBoundingClientRect(),{dx:F,dy:O}=l4({pointerX:d,pointerY:h,rect:U,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:r,maxSpeedPx:i});F!==0&&(s==null||s(`dragSelectAutoscroll dx=${Math.round(F)}`),t.scrollLeft+=F),O!==0&&(t.scrollTop+=O),(F!==0||O!==0)&&(E().dispatchEvent(new MouseEvent("mousemove",{clientX:d,clientY:h,bubbles:!0,cancelable:!0})),y+=1,_={dx:F,dy:O},w=Date.now()),p=o(R)},A=U=>{U.pointerType==="mouse"&&U.button===0&&(u=!0,d=U.clientX,h=U.clientY,p===null&&(p=o(R)))},I=U=>{u&&(d=U.clientX,h=U.clientY)};return t.addEventListener("pointerdown",A),(T=globalThis.addEventListener)==null||T.call(globalThis,"pointermove",I),(H=globalThis.addEventListener)==null||H.call(globalThis,"pointerup",k),(D=globalThis.addEventListener)==null||D.call(globalThis,"pointercancel",k),(W=globalThis.addEventListener)==null||W.call(globalThis,"blur",k),{dispose(){var U,F,O,M;k(),t.removeEventListener("pointerdown",A),(U=globalThis.removeEventListener)==null||U.call(globalThis,"pointermove",I),(F=globalThis.removeEventListener)==null||F.call(globalThis,"pointerup",k),(O=globalThis.removeEventListener)==null||O.call(globalThis,"pointercancel",k),(M=globalThis.removeEventListener)==null||M.call(globalThis,"blur",k)},getDebugSnapshot(){return{dragging:u,pointerX:d,pointerY:h,dispatchCount:y,dispatchTargetTag:v,lastScrollDelta:_,lastDispatchedAt:w}}}}const Qfe=16,Jfe=16,epe=16;function c4(e){const t=Array.from(e);return t.length!==1?!1:/^[\p{P}\p{S}]$/u.test(t[0])}function tpe(e){if(e.length!==1)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function npe(e){for(const t of e){const n=t.codePointAt(0);if(n!==void 0&&n>127)return!0}return!1}function rpe(e,t){return t.physicalKeyboardMode!==!0||e.length===0?!1:e===" "||npe(e)?!0:Array.from(e).every(c4)}function ipe(e,t={}){return e.type!=="keydown"||e.ctrlKey||e.metaKey||e.altKey||e.isComposing||t.imeComposing?!1:c4(e.key)||t.physicalKeyboardMode===!0&&(e.key===" "||tpe(e.key))}function spe(e){return e.type!=="keydown"||!e.ctrlKey||e.metaKey||e.altKey||e.shiftKey?!1:e.key===" "||e.key==="Spacebar"||e.code==="Space"}function ope(e){return e.type!=="keydown"?!1:e.metaKey}function u4(e){return{inputMode:e.getAttribute("inputmode"),enterKeyHint:e.getAttribute("enterkeyhint"),autocapitalize:e.getAttribute("autocapitalize"),autocomplete:e.getAttribute("autocomplete"),autocorrect:e.getAttribute("autocorrect"),spellcheck:e.spellcheck,colorScheme:e.style.colorScheme}}function d4(e,t){t.inputMode===null?e.removeAttribute("inputmode"):e.setAttribute("inputmode",t.inputMode),t.enterKeyHint===null?e.removeAttribute("enterkeyhint"):e.setAttribute("enterkeyhint",t.enterKeyHint),t.autocapitalize===null?e.removeAttribute("autocapitalize"):e.setAttribute("autocapitalize",t.autocapitalize),t.autocomplete===null?e.removeAttribute("autocomplete"):e.setAttribute("autocomplete",t.autocomplete),t.autocorrect===null?e.removeAttribute("autocorrect"):e.setAttribute("autocorrect",t.autocorrect),e.spellcheck=t.spellcheck,e.style.colorScheme=t.colorScheme}function ape(){if(typeof window>"u"||typeof document>"u")return null;const e=window.getComputedStyle(document.documentElement).colorScheme;return e.includes("dark")?"dark":e.includes("light")?"light":null}function lpe(e){const t=u4(e),n=ape();return e.setAttribute("autocapitalize","off"),e.setAttribute("autocomplete","off"),e.setAttribute("autocorrect","off"),e.spellcheck=!1,n&&(e.style.colorScheme=n),()=>d4(e,t)}function cpe(e){const t=u4(e);return e.setAttribute("enterkeyhint","send"),()=>{d4(e,t)}}function upe(e,t,n={}){var L,N,q,Y;let r,i,s,o=!1,l;const u=()=>{var $;return(($=n.isPhysicalKeyboardMode)==null?void 0:$.call(n))??n.physicalKeyboardMode===!0},d=()=>{var $;return(($=n.getPlainEnterBehavior)==null?void 0:$.call(n))??n.plainEnterBehavior??"submit"},h=e.textarea?lpe(e.textarea):void 0,p=u()&&e.textarea?cpe(e.textarea):void 0,y=()=>{const $=e.textarea;!$||l||(l=setTimeout(()=>{l=void 0,o||($.value="")},0))},v=$=>{var P;if(n.isInputEnabled&&!n.isInputEnabled()){y();return}qs(t,$),(P=n.onRawInput)==null||P.call(n,$),y()},_=$=>{v($)},w=()=>{i&&(clearTimeout(i.timer),i=void 0)},x=()=>{s&&(clearTimeout(s.timer),s=void 0)},E=$=>{if(x(),!$)return;const P={data:$,timer:setTimeout(()=>{s===P&&(s=void 0)},epe)};s=P},k=$=>{E(`${(s==null?void 0:s.data)??""}${$}`)},R=$=>!s||!$||!s.data.startsWith($)?!1:(E(s.data.slice($.length)),!0),A=($,P)=>{w();const V={data:$,keydownText:P,timer:setTimeout(()=>{i===V&&(i=void 0)},Jfe)};i=V},I=($,P)=>{const V=$.startsWith(P.data)?P.data:$.startsWith(P.keydownText)?P.keydownText:"";return V?$.slice(V.length):$},T=($,P,V)=>I($,{data:V,keydownText:P.keydownText}),H=($,P)=>{let V=!1;for(const G of $.bufferedXtermData){let B=G;if(!V){const K=T(G,$,P);K!==G&&(B=K,V=!0)}B&&_(B)}},D=$=>{const P=r;P&&(r=void 0,clearTimeout(P.timer),v($),A($,P.keydownText),H(P,$))},W=$=>{r&&D(r.keydownText),w();const P={bufferedXtermData:[],keydownText:$,timer:setTimeout(()=>{r===P&&D($)},Qfe)};r=P},U=$=>rpe($,{physicalKeyboardMode:u()})?R($)?(y(),!0):(v($),A($,$),!0):!1,F=$=>{const P=$,V=P.data??"";if(!P.isComposing&&r&&V){D(V);return}P.isComposing||P.inputType!=="insertText"&&P.inputType!=="insertCompositionText"||U(V)},O=()=>{o=!0,l&&(clearTimeout(l),l=void 0);const $=e.textarea;$&&($.value="")},M=$=>{o=!1,r&&$.data&&D($.data)},z=e.onData($=>{if(r){r.bufferedXtermData.push($);return}if(i){const P=I($,i);w(),P&&_(P);return}_($),k($)});return(L=e.textarea)==null||L.addEventListener("input",F),(N=e.textarea)==null||N.addEventListener("compositionstart",O,!0),(q=e.textarea)==null||q.addEventListener("compositionend",M),(Y=e.attachCustomKeyEventHandler)==null||Y.call(e,$=>u()&&(spe($)||ope($))?!1:ipe($,{physicalKeyboardMode:u(),imeComposing:o})?(W($.key),!1):$.type!=="keydown"||$.key!=="Enter"?!0:d()==="linefeed"!==$.shiftKey?(v(`
642
- `),$.preventDefault(),!1):!0),{dispose:()=>{var $,P,V;z.dispose(),($=e.textarea)==null||$.removeEventListener("input",F),(P=e.textarea)==null||P.removeEventListener("compositionstart",O,!0),(V=e.textarea)==null||V.removeEventListener("compositionend",M),r&&(clearTimeout(r.timer),r=void 0),l&&(clearTimeout(l),l=void 0),p==null||p(),h==null||h(),w(),x()}}}function h4(e,t){if(e.cellH<=0||e.cellW<=0||e.rows<=0||e.cols<=0)return null;const n=e.rows*e.cellH,r=e.bufferLength<=e.rows,i=Math.max(0,e.visibleContentHeight??0),s=i>0?Math.min(n,i):n,o=t<0?1:Math.max(1,t+1),l=r?Math.max(0,s-o*e.cellH):0,u=Math.max(0,e.bufferLength-e.rows),d=u*e.cellH+i;if(i>0&&n>i&&e.cursorY!==void 0){const p=Math.max(0,Math.min(e.rows-1,e.cursorY)),y=u*e.cellH,v=y+n-i,_=y+p*e.cellH-(i-e.cellH)/2;return{spacerHeight:Math.max(y,Math.min(v,_))+i,spacerWidth:e.cols*e.cellW,hostWidth:e.cols*e.cellW,hostHeight:n,hostPaddingTop:l}}return{spacerHeight:Math.max(e.bufferLength*e.cellH,d),spacerWidth:e.cols*e.cellW,hostWidth:e.cols*e.cellW,hostHeight:n,hostPaddingTop:l}}function dE(e){const t=e.paddingTop+e.cursorBufferRow*e.cellH,n=e.containerScrollTop+e.paddingTop,r=e.containerScrollTop+e.containerClientHeight-e.paddingBottom,i=Math.max(1,e.atBottomThreshold),s=e.cellH>0&&t>=n-i&&t+e.cellH<=r+i,o=Math.max(0,e.containerScrollHeight-e.containerClientHeight),l=e.rows*e.cellH,u=e.cellH>0&&l>e.visibleContentHeight;let d,h;if(u){d=s;const p=t-e.paddingTop-(e.visibleContentHeight-e.cellH)/2,v=Math.max(0,e.bufferLength-e.rows)*e.cellH;h=Math.max(v,Math.min(o,p))}else d=e.containerScrollTop+e.containerClientHeight>=e.containerScrollHeight-e.atBottomThreshold,h=o;return{isAtBottom:d,bottomScrollTop:h,cursorInViewport:s}}function f4(e){if(e.cellH<=0)return 0;const t=e.rows*e.cellH,n=e.visibleContentHeight!==void 0&&t<e.visibleContentHeight?e.visibleContentHeight-t:0;return Math.max(0,e.ydisp*e.cellH+n)}function B2(e,t){if(t.cellH<=0)return{ydisp:t.viewportY};const n=Math.max(0,t.bufferLength-t.rows),r=n*t.cellH;if(e>=r)return{ydisp:n};const i=Math.max(0,Math.floor(e/t.cellH));return{ydisp:Math.min(i,n)}}function dpe(e,t){return t<=0?0:Math.max(0,e)*t}function hpe(){return{intent:!1,lastUserInputAt:null,unmarkedOriginLeft:null,lastSeenLeft:0,pendingFollowLeft:null}}function fpe(e,t){return{...e,intent:t,unmarkedOriginLeft:t?e.unmarkedOriginLeft:null}}function Ng(e,t){return{state:{...fpe(e,!1),lastUserInputAt:null,pendingFollowLeft:null,...t.scrollLeft!==void 0?{lastSeenLeft:t.scrollLeft}:{}},trace:e.intent?{kind:"clear",details:t.details}:null}}function ppe(e,t){return{state:{...e,intent:!0,lastUserInputAt:t.now,unmarkedOriginLeft:null},trace:e.intent?null:{kind:"set",details:t.details}}}function mpe(e,t){return{...e,pendingFollowLeft:t}}function gpe(e,t){if(!t.hasOverflow)return{...Ng(e,{details:`reason=not-scrollable scrollLeft=${t.scrollLeft}`,scrollLeft:0}),resetScrollLeft:t.scrollLeft!==0};if(t.scrollLeft===e.lastSeenLeft)return{state:e,trace:null,resetScrollLeft:!1};const n=t.pendingFollowTolerancePx??1,r=t.recentUserInputMs??500;if(e.pendingFollowLeft!==null&&Math.abs(t.scrollLeft-e.pendingFollowLeft)<=n)return{state:{...e,pendingFollowLeft:null,unmarkedOriginLeft:null,lastSeenLeft:t.scrollLeft},trace:null,resetScrollLeft:!1};if(e.lastUserInputAt!==null&&t.now-e.lastUserInputAt<=r){const u=`site=onContainerScroll prev=${e.lastSeenLeft} next=${t.scrollLeft}`;return{state:{...e,intent:!0,pendingFollowLeft:null,unmarkedOriginLeft:null,lastSeenLeft:t.scrollLeft},trace:e.intent?null:{kind:"set",details:u},resetScrollLeft:!1}}const o=e.unmarkedOriginLeft===null?e.lastSeenLeft:e.unmarkedOriginLeft,l=Math.abs(t.scrollLeft-o);if(l>=t.nativeIntentThresholdPx){const u=`site=onContainerScroll-native prev=${o} next=${t.scrollLeft} delta=${l}`;return{state:{...e,intent:!0,pendingFollowLeft:null,unmarkedOriginLeft:null,lastSeenLeft:t.scrollLeft},trace:e.intent?null:{kind:"set",details:u},resetScrollLeft:!1}}return{state:{...e,pendingFollowLeft:null,unmarkedOriginLeft:o,lastSeenLeft:t.scrollLeft},trace:{kind:"ignore",details:`site=onContainerScroll prev=${e.lastSeenLeft} next=${t.scrollLeft} nativeDelta=${l}`},resetScrollLeft:!1}}function vpe({syncingExternal:e,effectiveScrollTop:t,pendingFollowTop:n,pendingProgrammaticTop:r,atBottom:i,canPassiveFollow:s,tolerancePx:o=1}){if(e)return{action:"external-sync",nextPendingFollowTop:n,nextPendingProgrammaticTop:r};if(n!==null&&Math.abs(t-n)<=o)return{action:"programmatic-follow",nextPendingFollowTop:null,nextPendingProgrammaticTop:null};const u=r!==null&&Math.abs(t-r)<=o&&s;return!i&&u?{action:"programmatic-drift",nextPendingFollowTop:null,nextPendingProgrammaticTop:null}:{action:"continue",nextPendingFollowTop:null,nextPendingProgrammaticTop:null}}function ype(e){return!e.force&&e.reviewing?{action:"blocked-by-review"}:!e.reviewing&&e.viewportY===e.expectedYdisp&&(Math.abs(e.scrollTop-e.bottomScrollTop)<=1||!e.force&&e.atBottom)?{action:"noop"}:{action:"follow"}}function bpe(e){return!(e.bottomScrollTop<e.domMaxScrollTop-1)||e.rawScrollTop<=e.bottomScrollTop+1?{action:"keep",scrollTop:e.rawScrollTop}:{action:"clamp",scrollTop:e.bottomScrollTop}}function _pe({container:e,term:t,onWheel:n,onTouchStart:r,onTouchMove:i,onTouchEnd:s,onTouchCancel:o,onContainerScroll:l,onTermScroll:u,onRender:d,onRelayout:h,onWriteParsed:p}){var x;e.addEventListener("wheel",n,{passive:!1,capture:!0}),e.addEventListener("touchstart",r,{passive:!0}),e.addEventListener("touchmove",i,{passive:!0}),e.addEventListener("touchend",s,{passive:!0}),e.addEventListener("touchcancel",o,{passive:!0}),e.addEventListener("scroll",l,{passive:!0});const y=t.onScroll(u),v=t.onRender(d),_=p?(x=t.onWriteParsed)==null?void 0:x.call(t,p):void 0,w=new ResizeObserver(h);return w.observe(e),{dispose:()=>{e.removeEventListener("scroll",l),e.removeEventListener("wheel",n,{capture:!0}),e.removeEventListener("touchstart",r),e.removeEventListener("touchmove",i),e.removeEventListener("touchend",s),e.removeEventListener("touchcancel",o),y.dispose(),v.dispose(),_==null||_.dispose(),w.disconnect()}}}function wpe({container:e,host:t,term:n,atBottomThreshold:r,getDims:i,getVerticalInsets:s,getPrevCursorBufferRow:o,getPendingProgrammaticScrollTop:l,getPendingFollowCursorScrollTop:u,getPendingFollowCursorScrollLeft:d,getPendingContainerSyncRetry:h,getHorizontalIntent:p,getVerticalIntent:y,getUserHasVerticalScrollIntent:v}){var T,H;let _=null,w=null;const x=()=>{var z;const D=document.activeElement;if(!D)return null;const W=D.getAttribute("aria-label")??"",U=D.tagName,F=typeof D.closest=="function"?((z=D.closest("[data-slot]"))==null?void 0:z.getAttribute("data-slot"))??"":"",O=D.id?`#${D.id}`:"",M=typeof D.className=="string"&&D.className?"."+D.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";return W?`${W}|${U}${O}${M}{${F}}`:`${U}${O}${M}{${F}}`},E=(D,W={})=>{if(!cw())return;const U=e.getBoundingClientRect(),F=t.getBoundingClientRect(),O=window.visualViewport,{cellH:M,cellW:z}=i(),{paddingTop:L,paddingBottom:N}=s(),q=Math.max(0,e.clientHeight-L-N),Y=n.buffer.active,$=Y.baseY+Y.cursorY,P=dE({rows:n.rows,cellH:M,bufferLength:Y.length,cursorBufferRow:$,visibleContentHeight:q,paddingTop:L,paddingBottom:N,containerScrollTop:e.scrollTop,containerScrollHeight:e.scrollHeight,containerClientHeight:e.clientHeight,atBottomThreshold:r}),V=o(),G=V===null?null:$-V,B=W.cursorDeltaRows!==void 0?W.cursorDeltaRows:G,K=W.scrollDeltaToAnchor!==void 0?W.scrollDeltaToAnchor:e.scrollTop-P.bottomScrollTop,ee=Hs(t.style.top),te=M>0?f4({ydisp:Y.viewportY,rows:n.rows,cellH:M,visibleContentHeight:q}):0,J=Hs(t.style.height),me=e.scrollTop,Se=me+e.clientHeight,Re=ee+J,Ae=Math.max(0,Math.min(Se,Re)-Math.max(me,ee)),He=y();hle({t:performance.now(),event:D,scope:W.scope,action:W.action,reason:W.reason,scrollTop:e.scrollTop,scrollLeft:e.scrollLeft,scrollHeight:e.scrollHeight,scrollWidth:e.scrollWidth,clientHeight:e.clientHeight,clientWidth:e.clientWidth,innerHeight:window.innerHeight,visualViewportHeight:O==null?void 0:O.height,visualViewportOffsetTop:O==null?void 0:O.offsetTop,containerTop:U.top,containerBottom:U.bottom,hostRectTop:F.top,hostRectBottom:F.bottom,viewportY:Y.viewportY,bufferLength:Y.length,hostTop:t.style.top,cellH:M,cellW:z,cursorX:Y.cursorX,cursorY:Y.cursorY,cursorBufferRow:$,cursorDeltaRows:B,cursorInViewport:P.cursorInViewport,anchorBottomScrollTop:P.bottomScrollTop,scrollDeltaToAnchor:K,pendingProgrammaticScrollTop:l(),pendingFollowCursorScrollTop:u(),pendingFollowCursorScrollLeft:d(),pendingContainerSyncRetry:h(),horizontalIntent:p(),intentMode:He.mode,intentSource:He.source,intentTransition:He.lastTransitionId,prevCursorBufferRow:V,hostTopDrift:ee-te,viewportHostCoverage:e.clientHeight>0?Ae/e.clientHeight:0,focus:x(),atBottom:P.isAtBottom,touchActive:He.touchActive,userIntent:v(),...W})},k=D=>{if(!cw())return;const W=window.visualViewport;if(!W)return;const U=_===null?0:W.height-_,F=w===null?0:W.offsetTop-w;_=W.height,w=W.offsetTop,E(D,{vvHeightDelta:U,vvOffsetDelta:F})},R=()=>k("vv:resize"),A=()=>k("vv:scroll"),I=D=>{var z;if(!cw())return;const W=D.target,U=W===e||W instanceof Node&&e.contains(W),F=W&&typeof W.closest=="function"?((z=W.closest("[data-slot]"))==null?void 0:z.getAttribute("data-slot"))??"":"",O=(W==null?void 0:W.tagName)??"",M=W&&typeof W.className=="string"&&W.className?"."+W.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";E(`wheel:window deltaY=${Math.round(D.deltaY)} reachesContainer=${U?1:0} prevented=${D.defaultPrevented?1:0} target=${O}${M}{${F}}`)};return(T=window.visualViewport)==null||T.addEventListener("resize",R),(H=window.visualViewport)==null||H.addEventListener("scroll",A),window.addEventListener("wheel",I,{passive:!0,capture:!0}),{trace:E,dispose:()=>{var D,W;(D=window.visualViewport)==null||D.removeEventListener("resize",R),(W=window.visualViewport)==null||W.removeEventListener("scroll",A),window.removeEventListener("wheel",I,{capture:!0})}}}function p4(e){return{mode:e!=null&&e.initialIntent?"reviewing":"following",source:e!=null&&e.initialIntent?"initial":"none",touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1,lastScrollTop:(e==null?void 0:e.scrollTop)??0,lastTransitionId:e!=null&&e.initialIntent?"attach.reviewing":"attach.following"}}const Iw=e=>e.mode==="reviewing",wh=e=>e.mode==="following";function Spe(e,t){return e==="following"&&t==="reviewing"?"set":e==="reviewing"&&t==="following"?"clear":"keep"}function Gr(e,t,n,r=!1){const i=e.mode!==t.mode;return{state:t,changed:e!==t,outputPausedChanged:i,notifyTouchReviewStart:r,trace:{id:t.lastTransitionId,action:Spe(e.mode,t.mode),reason:n}}}function Sh(e,t,n,r){return{...e,mode:"reviewing",source:t,lastScrollTop:n,lastTransitionId:r}}function zw(e,t,n,r){return{...e,mode:"following",source:t,lastScrollTop:n,lastTransitionId:r}}function xpe(e){throw new Error(`Unhandled PTY vertical intent event: ${JSON.stringify(e)}`)}function Epe(e,t,n){const r=t.type==="touch-end"?"touch.end":"touch.cancel",i=e.touchStartScrollTop!==null&&t.scrollTop>e.touchStartScrollTop,s=e.touchStartScrollTop===null||t.scrollTop>=e.touchStartScrollTop-n,o={...e,touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1,lastScrollTop:t.scrollTop};return e.mode==="reviewing"&&t.atCursorAwareBottom&&(i||s||t.releaseOnSemanticBottom===!0)?Gr(e,{...o,mode:"following",source:"none",lastTransitionId:`${r}.bottom-down`},`scrollTop=${t.scrollTop} atBottom=true`):Gr(e,{...o,lastTransitionId:`${r}.not-bottom`},`scrollTop=${t.scrollTop} atBottom=${t.atCursorAwareBottom}`)}function Cpe(e,t,n={}){const r=n.atBottomThreshold??8;switch(t.type){case"attach":{const i=p4({initialIntent:t.initialIntent,scrollTop:t.scrollTop});return Gr(e,i,`initialIntent=${t.initialIntent}`)}case"scroll-to-bottom":return t.force?Gr(e,zw({...e,touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1},"programmatic-bottom",e.lastScrollTop,"bottom.force"),`reason=${t.reason} force=true`):Gr(e,{...e,lastTransitionId:`bottom.passive.${e.mode}`},`reason=${t.reason} force=false`);case"scroll-to-ratio":return Gr(e,Sh(e,"ratio-scroll",t.scrollTop,"ratio.reviewing"),`ratio=${t.ratio}`);case"wheel":return t.nextScrollTop===t.previousScrollTop?Gr(e,{...e,lastTransitionId:"wheel.clamped",lastScrollTop:t.nextScrollTop},`delta=${t.deltaY}`):t.deltaY<0?Gr(e,Sh(e,"wheel",t.nextScrollTop,"wheel.up"),`delta=${t.deltaY}`):t.deltaY>0&&t.reachedCursorAwareBottom?Gr(e,zw(e,"none",t.nextScrollTop,"wheel.down.bottom"),`delta=${t.deltaY}`):Gr(e,Sh(e,"wheel",t.nextScrollTop,"wheel.down.not-bottom"),`delta=${t.deltaY}`);case"container-scroll":return t.source!=="user"?Gr(e,{...e,lastScrollTop:t.scrollTop,lastTransitionId:`container.${t.source}`},`source=${t.source} scrollTop=${t.scrollTop}`):t.atCursorAwareBottom?t.verticalDelta>r&&e.mode==="reviewing"&&!e.touchActive?Gr(e,zw(e,"none",t.scrollTop,"container.user.bottom-down"),`delta=${t.verticalDelta} threshold=${r}`):Gr(e,{...e,lastScrollTop:t.scrollTop,lastTransitionId:"container.user.bottom-small-delta"},`delta=${t.verticalDelta} threshold=${r}`):Gr(e,Sh(e,"native-scroll",t.scrollTop,"container.user.away"),`scrollTop=${t.scrollTop} atBottom=false`);case"touch-start":return Gr(e,{...e,touchActive:!0,touchStartY:t.clientY,touchStartScrollTop:t.scrollTop,touchReviewNotified:!1,lastScrollTop:t.scrollTop,lastTransitionId:"touch.start"},`clientY=${t.clientY??"null"}`);case"touch-move":{const i=e.touchStartY===null||t.clientY===null?0:Math.abs(t.clientY-e.touchStartY);return i>=t.reviewThresholdPx&&!e.touchReviewNotified?Gr(e,{...Sh(e,"touch",e.lastScrollTop,"touch.move.review"),touchReviewNotified:!0},`movement=${i} threshold=${t.reviewThresholdPx}`,!0):i>=t.reviewThresholdPx?Gr(e,{...e,lastTransitionId:"touch.move.reviewing"},`movement=${i} threshold=${t.reviewThresholdPx}`):Gr(e,{...e,lastTransitionId:"touch.move.below-threshold"},`movement=${i} threshold=${t.reviewThresholdPx}`)}case"touch-end":case"touch-cancel":return Epe(e,t,r);default:return xpe(t)}}const hi={bottom:{defaultThresholdPx:8},horizontal:{nativeIntentThresholdPx:48},rawInput:{recentLayoutDriftMs:1e3},touch:{scrollJumpMinThresholdPx:512,hostTopJumpMinThresholdPx:64,gestureSlopPx:16,horizontalGestureSlopPx:6,horizontalLockRatio:1,verticalLockRatio:1.25,nativeScrollRecentMs:500}};function kpe({reviewing:e,cellH:t,rows:n,visibleContentHeight:r,cursorBufferRow:i,prevCursorBufferRow:s,cursorInViewport:o,targetScrollTop:l,currentScrollTop:u}){if(e)return{action:"skip",reason:"intent",nextPrevCursorBufferRow:null,cursorDeltaRows:null};if(t<=0)return{action:"skip",reason:"cellH=0",nextPrevCursorBufferRow:s,cursorDeltaRows:null};if(n*t<=r)return{action:"skip",reason:"shortHost",nextPrevCursorBufferRow:null,cursorDeltaRows:null};if(s===i&&o)return{action:"skip",reason:"same-row",nextPrevCursorBufferRow:s,cursorDeltaRows:0};const d=s===null?null:i-s;return o?{action:"skip",reason:"inViewport",nextPrevCursorBufferRow:i,cursorDeltaRows:d}:Math.abs(l-u)<=1?{action:"skip",reason:"aligned",nextPrevCursorBufferRow:i,cursorDeltaRows:d}:{action:"follow",reason:"cursor-outside",nextPrevCursorBufferRow:i,cursorDeltaRows:d,targetScrollTop:l}}function Tpe({startX:e,startY:t,currentX:n,currentY:r}){if(t===null||r===null)return null;const i=e!==null&&n!==null?n-e:0,s=r-t;return{dx:i,dy:s,absDx:Math.abs(i),absDy:Math.abs(s),distance:Math.hypot(i,s),startY:t}}function Rpe({touchActive:e,touchStartScrollTop:t,touchStartY:n,currentY:r,touchStartedAtCursorAwareBottom:i,bottomScrollTop:s,domMaxScrollTop:o}){if(!e||t===null||n===null||r===null)return!1;const l=Math.min(o,s),u=i?s:t,d=Math.max(0,Math.min(l,u+(n-r)));return{touchStartScrollTop:t,touchStartY:n,currentY:r,gestureBaseScrollTop:u,expectedScrollTop:d,cursorAwareMaxScrollTop:l,touchDeltaY:r-n}}function Ape({touchActive:e,touchStartClientX:t,touchStartScrollLeft:n,currentX:r,maxScrollLeft:i}){if(!e||t===null||n===null||r===null)return!1;const s=Math.max(0,Math.min(i,n+(t-r)));return{touchStartX:t,currentX:r,touchStartScrollLeft:n,expectedScrollLeft:s,maxScrollLeft:i,touchDeltaX:r-t}}function Npe({touchStartScrollTop:e,liveScrollTop:t,atBottomThreshold:n,touchStartedAtCursorAwareBottom:r,anchorIsAtBottom:i,reviewedDuringTouch:s}){const o=e===null||t>=e-n;return{atCursorAwareBottomForIntent:!s&&i||r&&!s&&o,releaseOnSemanticBottom:r&&i&&!s}}function Mpe(){const e=new WeakMap;return{set(t,n,r){let i=e.get(t);i||(i=new Map,e.set(t,i)),i.get(n)!==r&&(i.set(n,r),t.style[n]=r)}}}function Ope(){return{startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,lastGestureAt:null,lastHorizontalGestureAt:null,gestureMode:null}}function Dpe(e,t){return{...e,startedAtCursorAwareBottom:t.startedAtCursorAwareBottom,startClientX:t.startClientX,startScrollLeft:t.startScrollLeft,lastClientY:t.startClientY,lastGestureAt:t.now,gestureMode:t.startClientY===null?null:"pending"}}function Ppe(e,t){return{...e,lastGestureAt:t}}function j2(e,t){return{...e,lastHorizontalGestureAt:t}}function Lpe(e,t){return{...e,lastClientY:t.currentY,lastGestureAt:t.now}}function Ipe(e,t){return!t.touchActive||e.gestureMode!==null||t.currentY===null?e:{...e,gestureMode:"pending"}}function F2(e,t){return e.gestureMode===t?e:{...e,gestureMode:t}}function zpe(e){return{...e,startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,gestureMode:null}}function Bpe({container:e,atBottomThreshold:t,trace:n,getPageResumePending:r,getVerticalIntent:i,dispatchVerticalIntent:s,getCurrentAnchor:o,getLastSeenScrollTop:l,hasHorizontalOverflow:u,clearHorizontalIntentIfUnscrollable:d,markHorizontalUserInput:h,onTouchBoundaryPrevent:p,notifyAtBottom:y,flushPendingTouchScrollNotify:v}){let _=Ope();const w=D=>{const W=D??_.lastClientY,U=o(),F=Math.max(0,e.scrollHeight-e.clientHeight),O=i();return Rpe({touchActive:O.touchActive,touchStartScrollTop:O.touchStartScrollTop,touchStartY:O.touchStartY,currentY:W,touchStartedAtCursorAwareBottom:_.startedAtCursorAwareBottom,bottomScrollTop:U.bottomScrollTop,domMaxScrollTop:F})},x=(D,W)=>Tpe({startX:_.startClientX,startY:i().touchStartY,currentX:D,currentY:W}),E=D=>{const W=Math.max(0,e.scrollWidth-e.clientWidth);return Ape({touchActive:i().touchActive,touchStartClientX:_.startClientX,touchStartScrollLeft:_.startScrollLeft,currentX:D,maxScrollLeft:W})},k=(D,W,U,F,O)=>D?[`raw=${Math.round(W)}`,`effective=${Math.round(U)}`,`prev=${Math.round(F)}`,`delta=${Math.round(O)}`,`expected=${Math.round(D.expectedScrollTop)}`,`startScroll=${Math.round(D.touchStartScrollTop)}`,`base=${Math.round(D.gestureBaseScrollTop)}`,`startY=${Math.round(D.touchStartY)}`,`currentY=${Math.round(D.currentY)}`,`touchDeltaY=${Math.round(D.touchDeltaY)}`,`max=${Math.round(D.cursorAwareMaxScrollTop)}`].join(" "):null,R=D=>{var M;if(r()){n("touchstart:page-resume-pending");return}const W=((M=D.touches)==null?void 0:M[0])??null,U=(W==null?void 0:W.clientX)??null,F=(W==null?void 0:W.clientY)??null;d("touchstart");const O=o();_=Dpe(_,{startedAtCursorAwareBottom:O.isAtBottom,startClientX:U,startClientY:F,startScrollLeft:e.scrollLeft,now:performance.now()}),s({type:"touch-start",clientY:F,scrollTop:e.scrollTop}),n("touchstart",{details:[`startX=${U??"null"}`,`startY=${F??"null"}`,`startScroll=${Math.round(e.scrollTop)}`,`bottom=${Math.round(O.bottomScrollTop)}`,`atBottom=${O.isAtBottom?1:0}`].join(" ")})},A=D=>{var Y;if(r()){n("touchmove:page-resume-pending");return}const W=((Y=D.touches)==null?void 0:Y[0])??null,U=(W==null?void 0:W.clientX)??null,F=(W==null?void 0:W.clientY)??null,O=performance.now();_=Lpe(_,{currentY:F,now:O});const M=x(U,F);n("touchmove",{details:F===null?"currentY=null":k(w(F),e.scrollTop,e.scrollTop,l(),e.scrollTop-l())??[`mode=${_.gestureMode??"none"}`,`currentY=${Math.round(F)}`,M?`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`:null].filter(Boolean).join(" ")});const z=u();if(z||d("touchmove"),_=Ipe(_,{touchActive:i().touchActive,currentY:F}),_.gestureMode==="pending"&&M){const $=z&&M.absDx>=hi.touch.horizontalGestureSlopPx&&M.absDx>M.absDy*hi.touch.horizontalLockRatio,P=M.absDy>=hi.touch.gestureSlopPx&&(!z||M.absDy>M.absDx*hi.touch.verticalLockRatio);if($)_=F2(_,"horizontal"),_=j2(_,O),n("touchmove:horizontal-lock",{details:`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`});else if(P)_=F2(_,"vertical"),n("touchmove:vertical-lock",{details:`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)} threshold=${hi.touch.gestureSlopPx}`});else{n("touchmove:pending",{details:[`dx=${Math.round(M.dx)}`,`dy=${Math.round(M.dy)}`,`distance=${Math.round(M.distance)}`,`hThreshold=${hi.touch.horizontalGestureSlopPx}`,`vThreshold=${hi.touch.gestureSlopPx}`].join(" ")}),M.absDy<hi.touch.gestureSlopPx&&s({type:"touch-move",clientY:F,reviewThresholdPx:hi.touch.gestureSlopPx});return}}if(_.gestureMode==="horizontal"){const $=E(U);if(!z||!$){d("touchmove-horizontal"),n("touchmove:horizontal-native",{details:M?`blocked dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`:"blocked movement=null"});return}M&&(_=j2(_,O),h(`site=touchmove-horizontal dx=${Math.round(M.absDx)} dy=${Math.round(M.absDy)}`)),n("touchmove:horizontal-native",{details:[`scrollLeft=${Math.round(e.scrollLeft)}`,`expected=${Math.round($.expectedScrollLeft)}`,`startScrollLeft=${Math.round($.touchStartScrollLeft)}`,`startX=${Math.round($.touchStartX)}`,`currentX=${Math.round($.currentX)}`,`touchDeltaX=${Math.round($.touchDeltaX)}`,`max=${Math.round($.maxScrollLeft)}`].join(" ")});return}if(_.gestureMode!=="vertical")return;const L=w(F);if(L&&n("touchmove:vertical-native",{details:[`scrollTop=${Math.round(e.scrollTop)}`,`expected=${Math.round(L.expectedScrollTop)}`,`startScroll=${Math.round(L.touchStartScrollTop)}`,`base=${Math.round(L.gestureBaseScrollTop)}`,`startY=${Math.round(L.touchStartY)}`,`currentY=${Math.round(L.currentY)}`,`touchDeltaY=${Math.round(L.touchDeltaY)}`].join(" ")}),L&&_.startedAtCursorAwareBottom&&L.expectedScrollTop>=L.cursorAwareMaxScrollTop-t&&F!==null&&F<=L.touchStartY){n("touchmove:bottom-boundary-follow");return}s({type:"touch-move",clientY:F,reviewThresholdPx:hi.touch.gestureSlopPx}).notifyTouchReviewStart&&(p==null||p(),n("touchmove:review"))},I=D=>{const W=e.scrollTop,U=o(),F=Npe({touchStartScrollTop:i().touchStartScrollTop,liveScrollTop:W,atBottomThreshold:t,touchStartedAtCursorAwareBottom:_.startedAtCursorAwareBottom,anchorIsAtBottom:U.isAtBottom,reviewedDuringTouch:i().touchReviewNotified});_=zpe(_),s({type:D,scrollTop:W,atCursorAwareBottom:F.atCursorAwareBottomForIntent,releaseOnSemanticBottom:F.releaseOnSemanticBottom}),_=Ppe(_,performance.now()),v(),y()};return{onTouchStart:R,onTouchMove:A,onTouchEnd:()=>{if(r()){n("touchend:page-resume-pending");return}I("touch-end"),n("touchend")},onTouchCancel:()=>{if(r()){n("touchcancel:page-resume-pending");return}I("touch-cancel"),n("touchcancel")},isRecentNativeScroll:()=>i().touchActive||_.lastGestureAt!==null&&performance.now()-_.lastGestureAt<=hi.touch.nativeScrollRecentMs,isRecentHorizontalGesture:()=>_.lastHorizontalGestureAt!==null&&performance.now()-_.lastHorizontalGestureAt<=hi.touch.nativeScrollRecentMs,getScrollExpectation:w,describeScrollExpectation:k,getState:()=>_}}function hE(e,t){const n=e.querySelector(".xterm-screen");return!n||t.cols<=0||t.rows<=0?null:{cellW:n.clientWidth/t.cols,cellH:n.clientHeight/t.rows}}function jpe(e,t){for(let n=t-1;n>=0;n--){const r=e.viewportY+n;if(r<0||r>=e.length)continue;const i=e.getLine(r);if(i&&i.translateToString(!0).trimEnd().length>0)return n}return-1}function Fpe(e){const{container:t,spacer:n,host:r,term:i,hasNewFrame:s,consumeNewFrame:o,hasNewFramesWhileAway:l,setNewFramesWhileAway:u,onAtBottomChange:d,onScrollStateChange:h,initialUserHasVerticalScrollIntent:p=!1,onUserVerticalScrollIntentChange:y,onTouchReviewStart:v,onTouchBoundaryPrevent:_,onReviewSnapshotCapture:w,onReviewSnapshotClear:x,atBottomThreshold:E=hi.bottom.defaultThresholdPx}=e,k=()=>hE(r,i)??{cellH:0,cellW:0},R=()=>{const ne=getComputedStyle(t);return{paddingTop:Hs(ne.paddingTop),paddingBottom:Hs(ne.paddingBottom)}},A=Mpe(),I=(ne,ce,Ce)=>{A.set(ne,ce,Ce)},T={external:!1,internal:!1};let H=null,D="",W=p4({initialIntent:p,scrollTop:t.scrollTop}),U=null,F=null,O=!1,M=null,z=hpe(),L=0,N=!1,q=null,Y=null,$=null,P=null,V=p;const G=()=>Iw(W),B=wpe({container:t,host:r,term:i,atBottomThreshold:E,getDims:k,getVerticalInsets:R,getPrevCursorBufferRow:()=>q,getPendingProgrammaticScrollTop:()=>U,getPendingFollowCursorScrollTop:()=>M,getPendingFollowCursorScrollLeft:()=>z.pendingFollowLeft,getPendingContainerSyncRetry:()=>O,getHorizontalIntent:()=>z.intent,getVerticalIntent:()=>W,getUserHasVerticalScrollIntent:()=>G()}),K=B.trace,ee=ne=>{if(ne){if(ne.kind==="ignore"){K("horizontal-intent:ignore",{details:ne.details});return}K(`horizontal-intent:${ne.kind}`,{details:ne.details})}},te=()=>t.scrollWidth>t.clientWidth+E,J=ne=>{if(te())return!1;const ce=Ng(z,{details:`site=${ne} reason=not-scrollable scrollWidth=${t.scrollWidth} clientWidth=${t.clientWidth}`,scrollLeft:t.scrollLeft});return z=ce.state,ee(ce.trace),t.scrollLeft!==0&&(t.scrollLeft=0,z={...z,lastSeenLeft:0}),!0},me=ne=>{if(!te()){J("markHorizontalUserInput");return}const ce=ppe(z,{now:performance.now(),details:ne});z=ce.state,ee(ce.trace)},Se=()=>({scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,scrollHeight:t.scrollHeight,scrollWidth:t.scrollWidth,clientHeight:t.clientHeight,clientWidth:t.clientWidth,scrollable:t.scrollHeight>t.clientHeight+E,horizontalScrollable:te()}),Re=()=>{if(!h)return;const ne=Se(),ce=[ne.scrollTop,ne.scrollLeft,ne.scrollHeight,ne.scrollWidth,ne.clientHeight,ne.clientWidth,ne.scrollable,ne.horizontalScrollable].join(":");ce!==D&&(D=ce,h(ne))},Ae=()=>{const{cellH:ne}=k(),{paddingTop:ce,paddingBottom:Ce}=R(),re=i.buffer.active;return dE({rows:i.rows,cellH:ne,bufferLength:re.length,cursorBufferRow:re.baseY+re.cursorY,visibleContentHeight:Math.max(0,t.clientHeight-ce-Ce),paddingTop:ce,paddingBottom:Ce,containerScrollTop:t.scrollTop,containerScrollHeight:t.scrollHeight,containerClientHeight:t.clientHeight,atBottomThreshold:E})},He=()=>{const ne=Ae().isAtBottom;H!==ne&&(H=ne,d==null||d(ne))},qe=()=>{He(),Re()},pt=()=>W.touchActive,kt=()=>{$!==null&&(P==null||P($),$=null,P=null)},ve=()=>{if($!==null)return;const ne=()=>{$=null,P=null,qe()};if(typeof window.requestAnimationFrame=="function"){$=window.requestAnimationFrame(ne),P=typeof window.cancelAnimationFrame=="function"?ce=>window.cancelAnimationFrame(ce):null;return}$=window.setTimeout(ne,16),P=ce=>window.clearTimeout(ce)},Ke=()=>{$!==null&&(kt(),qe())},Tt=(ne="rawInput")=>{Y=performance.now(),K(`rawInputFollow:scheduled[${ne}]`)},_e=()=>{Y=performance.now(),K("rawInputFollow:fire")},Be=()=>{G()&&(V=(w==null?void 0:w())===!1)},Ve=ne=>{const ce=Iw(W),Ce=Cpe(W,ne,{atBottomThreshold:E});W=Ce.state,Ce.trace&&K(`intent:${Ce.trace.action}`,{details:`id=${Ce.trace.id} reason=${Ce.trace.reason}`});const re=Iw(W);return ce!==re&&(y==null||y(re),re?V=!0:(V=!1,x==null||x())),Ce.notifyTouchReviewStart&&(v==null||v()),Ce},be=(ne,ce,Ce)=>{if(ce<=0)return;const re=Ce??(()=>{const{paddingTop:ze,paddingBottom:Fe}=R();return Math.max(0,t.clientHeight-ze-Fe)})(),fe=f4({ydisp:ne,rows:i.rows,cellH:ce,visibleContentHeight:re}),ye=r.style.top,Te=`${fe}px`;I(r,"position","absolute"),I(r,"left","0px"),I(r,"top",Te),ye!==Te&&K("host-position",{ydisp:ne,details:`${ye||"0px"}->${Te}`})},Xe=(ne="internal",ce={})=>{const Ce=Math.max(0,i.buffer.active.length-i.rows),re=Ae(),fe=ype({force:ce.force??!1,reviewing:G(),viewportY:i.buffer.active.viewportY,expectedYdisp:Ce,scrollTop:t.scrollTop,bottomScrollTop:re.bottomScrollTop,atBottom:re.isAtBottom}).action;if(fe==="blocked-by-review")return;if(fe==="noop"){O=!1;return}K(`scroll-to-bottom:start[${ne}]`),Ve({type:"scroll-to-bottom",force:ce.force??!1,reason:ne});const ye=Math.max(0,i.buffer.active.length-i.rows);T.internal=!0;try{i.scrollToLine(ye)}finally{T.internal=!1}const{cellH:Te}=k();Te!==0&&be(ye,Te);const ze=Ae().bottomScrollTop;t.scrollTop=ze,U=ze,q=i.buffer.active.baseY+i.buffer.active.cursorY,qe(),O=!1,K("scroll-to-bottom:end",{ydisp:ye})},tt=()=>{N=!0,K("page-resume:prepare-follow"),G()&&Ve({type:"scroll-to-bottom",force:!0,reason:"pageResumePrepare"})},ut=()=>{tt(),Gt(),Xe("pageResume",{force:!0}),Je("pageResume"),N=!1},de=ne=>{K("scroll-to-ratio:start");const ce=Math.max(0,t.scrollHeight-t.clientHeight),Ce=Math.max(0,Math.min(1,ne)),re=ce*Ce;Ve({type:"scroll-to-ratio",ratio:Ce,scrollTop:re}),V=!0,t.scrollTop=re,Dn()},Me=ne=>{if(ne===0)return;K("wheel");const ce=Math.max(0,t.scrollHeight-t.clientHeight),Ce=Math.min(ce,Ae().bottomScrollTop);if(Ce<=0){K("wheel:max-zero");return}const re=t.scrollTop,fe=Math.max(0,Math.min(Ce,re+ne));if(fe===re){K("wheel:clamped"),qe();return}V=!0,t.scrollTop=fe,L=fe,Dn(),Ve({type:"wheel",deltaY:ne,previousScrollTop:re,nextScrollTop:fe,reachedCursorAwareBottom:fe>re&&fe>=Ce-E&&Ae().isAtBottom}),G()&&(V=!0)},nt=ne=>{if(!te()){J("scrollToXRatio"),qe();return}const ce=Math.max(0,t.scrollWidth-t.clientWidth),Ce=Math.max(0,Math.min(1,ne));t.scrollLeft=ce*Ce,me(`site=scrollToXRatio ratio=${Ce}`),z={...z,lastSeenLeft:t.scrollLeft},qe()},Je=(ne="external",ce={})=>{const Ce=t.scrollLeft,re=Ng(z,{details:`site=resetHorizontalScroll reason=${ne}`,scrollLeft:0});z=re.state,ee(re.trace),Ce!==0&&(t.scrollLeft=0),ce.holdUntilCursorVisible&&me(`site=resetHorizontalScroll-hold reason=${ne}`),K(`horizontal-scroll-reset[${ne}]`,{details:`scrollLeft=${Ce}->${t.scrollLeft}`}),qe()},lt=(ne="external")=>{me(`site=${ne}`)};let At=0,zt=null,Yt=-1;const hn=()=>{const ne=i.buffer.active,ce=`${At}:${ne.viewportY}:${ne.length}:${i.rows}`;return ce===zt||(Yt=jpe(ne,i.rows),zt=ce),Yt},Gt=()=>{const{cellH:ne,cellW:ce}=k();if(ne===0||ce===0)return;const{paddingTop:Ce,paddingBottom:re}=R(),fe=Math.max(0,t.clientHeight-Ce-re),ye=i.buffer.active,Te=hn(),ze=h4({bufferLength:ye.length,rows:i.rows,cols:i.cols,viewportY:ye.viewportY,cursorY:ye.cursorY,cellH:ne,cellW:ce,visibleContentHeight:fe},Te);ze&&(I(n,"overflow","hidden"),I(n,"height",`${ze.spacerHeight}px`),I(n,"width",`${ze.spacerWidth}px`),I(r,"width",`${ze.hostWidth}px`),I(r,"height",`${ze.hostHeight}px`),I(r,"paddingTop",`${ze.hostPaddingTop}px`),F=performance.now(),be(ye.viewportY,ne,fe))},qt=(ne,ce,Ce={})=>{if(ne===i.buffer.active.viewportY){Ce.deferHostUntilRender||be(ne,ce);return}T.internal=!0;try{if(Ce.deferHostUntilRender){i.scrollToLine(ne);return}be(ne,ce),i.scrollToLine(ne)}finally{T.internal=!1}},Xn=()=>s()?(o(),wh(W)?(Xe("pendingFrame"),"followed"):(l()||u(!0),"marked")):"none",Ut=(ne,ce)=>{const Ce=i.buffer.active;return B2(ne,{bufferLength:Ce.length,rows:i.rows,cols:i.cols,viewportY:Ce.viewportY,cellH:ce}).ydisp},Dn=(ne={})=>{kt(),K("container-sync:start");const{cellH:ce}=k();if(ce===0){O=!0;return}O=!1;const Ce=Ut(t.scrollTop,ce);qt(Ce,ce,{deferHostUntilRender:ne.deferHostUntilRender??pt()}),qe(),K("container-sync:end",{ydisp:Ce})},je=()=>W.touchActive||wt.isRecentNativeScroll(),Qe=ne=>{if(!je())return!1;const{cellH:ce}=k();if(ce===0)return!1;const Ce=Ut(ne,ce);return Ce!==i.buffer.active.viewportY?!1:(ve(),K("container-sync:skip[same-row-touch]",{ydisp:Ce,details:`scrollTop=${Math.round(ne)} viewportY=${i.buffer.active.viewportY}`}),!0)},St=ne=>{const ce=Math.max(0,t.scrollHeight-t.clientHeight),Ce=Ae(),re=bpe({rawScrollTop:ne,bottomScrollTop:Ce.bottomScrollTop,domMaxScrollTop:ce});return re.action==="keep"||(K("container-scroll:clamp-cursor-bottom",{details:`prev=${ne} next=${re.scrollTop} domMax=${ce}`}),t.scrollTop=re.scrollTop,U=null,M=null),re.scrollTop},wt=Bpe({container:t,atBottomThreshold:E,trace:K,getPageResumePending:()=>N,getVerticalIntent:()=>W,dispatchVerticalIntent:Ve,getCurrentAnchor:Ae,getLastSeenScrollTop:()=>L,hasHorizontalOverflow:te,clearHorizontalIntentIfUnscrollable:J,markHorizontalUserInput:me,onTouchBoundaryPrevent:_,notifyAtBottom:He,flushPendingTouchScrollNotify:Ke}),Q=()=>z.intent?wt.getState().gestureMode==="horizontal"||wt.isRecentHorizontalGesture():!1,we=ne=>{const ce=wt.getScrollExpectation();if(!ce)return!1;const{touchStartScrollTop:Ce,touchStartY:re,currentY:fe,gestureBaseScrollTop:ye,expectedScrollTop:Te}=ce,ze=Math.abs(fe-re)>.5,Fe=ne<=E&&ye>t.clientHeight,Rt=parseFloat(r.style.top||"0"),Ft=Ae(),Zt=wt.getState().startedAtCursorAwareBottom&&Number.isFinite(Rt)&&Math.abs(ne-Rt)<=E&&Math.abs(Ft.bottomScrollTop-Rt)<=t.clientHeight+E&&Math.abs(Te-ne)>hi.touch.hostTopJumpMinThresholdPx;if(!ze&&!Fe&&!Zt)return!1;const Tn=Math.max(hi.touch.scrollJumpMinThresholdPx,t.clientHeight*1.25);return!Zt&&Math.abs(ne-Te)<=Tn?!1:(K("container-scroll:restore-touch-impossible-jump",{details:[`scrollTop=${Math.round(ne)}`,`expected=${Math.round(Te)}`,`diff=${Math.round(ne-Te)}`,`threshold=${Math.round(Tn)}`,`touchStart=${Math.round(Ce)}`,Zt?"hostTop=1":null,`startY=${Math.round(re)}`,`currentY=${Math.round(fe)}`].filter(Boolean).join(" ")}),t.scrollTop=Te,L=Te,Dn({deferHostUntilRender:!0}),!0)},We=(ne,ce,Ce)=>{if(ce||W.touchActive||!wh(W)||!(Y!==null&&performance.now()-Y<=hi.rawInput.recentLayoutDriftMs))return!1;const fe=Ae();return K("container-scroll:restore-raw-input-layout-bottom",{details:`scrollTop=${ne} bottom=${fe.bottomScrollTop}`}),Ve({type:"container-scroll",source:"programmatic-bottom",scrollTop:ne,atCursorAwareBottom:ce,verticalDelta:Ce}),Xe("rawInputLayoutDrift"),!0},ct=()=>{K("container-scroll");const ne=gpe(z,{hasOverflow:te(),scrollLeft:t.scrollLeft,now:performance.now(),nativeIntentThresholdPx:hi.horizontal.nativeIntentThresholdPx});z=ne.state,ee(ne.trace),ne.resetScrollLeft&&(t.scrollLeft=0);const ce=t.scrollTop,Ce=L,re=ce-L,fe=St(ce);if(W.touchActive){const ze=wt.getScrollExpectation();K("container-scroll:touch-active",{details:wt.describeScrollExpectation(ze,ce,fe,Ce,re)??`raw=${Math.round(ce)} effective=${Math.round(fe)}`})}L=fe;const ye=vpe({syncingExternal:T.external,effectiveScrollTop:fe,pendingFollowTop:M,pendingProgrammaticTop:U,atBottom:Ae().isAtBottom,canPassiveFollow:wh(W)});if(M=ye.nextPendingFollowTop,U=ye.nextPendingProgrammaticTop,ye.action==="external-sync"){Ve({type:"container-scroll",source:"external-sync",scrollTop:fe,atCursorAwareBottom:Ae().isAtBottom,verticalDelta:re}),qe();return}if(ye.action==="programmatic-follow"){Ve({type:"container-scroll",source:"programmatic-follow",scrollTop:fe,atCursorAwareBottom:Ae().isAtBottom,verticalDelta:re}),qe();return}const Te=Ae().isAtBottom;if(ye.action==="programmatic-drift"){Ve({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Te,verticalDelta:re}),Xe("programmaticDrift");return}if(!we(fe)&&!We(fe,Te,re)){if(N){K("container-scroll:page-resume-pending",{details:`scrollTop=${fe} bottom=${Ae().bottomScrollTop}`}),Ve({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Te,verticalDelta:re}),Dn();return}Ve({type:"container-scroll",source:"user",scrollTop:fe,atCursorAwareBottom:Te,verticalDelta:re}),G()&&(V=!0),!Qe(fe)&&Dn()}},Pt=()=>{if(K("term-scroll"),!T.internal){T.external=!0;try{Gt();const ne=Xn();if(ne==="followed")return;if(ne==="none"&&wh(W)){Xe("termScroll");return}const{cellH:ce}=k();if(ce!==0){const Ce=i.buffer.active,{ydisp:re}=B2(t.scrollTop,{bufferLength:Ce.length,rows:i.rows,cols:i.cols,viewportY:Ce.viewportY,cellH:ce,cellW:1});qt(re,ce)}qe()}finally{T.external=!1}}},ie=()=>{Gt();const ne=Xn();if(ne==="followed")return;if(ne==="none"&&wh(W)){Xe("relayout");return}const{cellH:ce}=k();if(ce!==0)if(O)K("pending-sync-retry-fire"),Dn();else{const Ce=Ut(t.scrollTop,ce),re=dpe(i.buffer.active.viewportY,ce);Ce!==i.buffer.active.viewportY?t.scrollTop=re:Math.abs(t.scrollTop-re)>1&&K("relayout:preserve-host-offset",{details:`scrollTop=${Math.round(t.scrollTop)} viewportTop=${Math.round(re)} ydisp=${Ce}`}),be(i.buffer.active.viewportY,ce)}qe()},oe=()=>{const{cellH:ne}=k(),{paddingTop:ce,paddingBottom:Ce}=R(),re=Math.max(0,t.clientHeight-ce-Ce),fe=i.buffer.active,ye=fe.baseY+fe.cursorY,Te=q,ze=Ae(),Fe=kpe({reviewing:G(),cellH:ne,rows:i.rows,visibleContentHeight:re,cursorBufferRow:ye,prevCursorBufferRow:q,cursorInViewport:ze.cursorInViewport,targetScrollTop:ze.bottomScrollTop,currentScrollTop:t.scrollTop});if(Fe.reason==="intent"){q=Fe.nextPrevCursorBufferRow,K("followCursorY:skip",{details:Fe.reason});return}if(Fe.reason==="cellH=0"){K("followCursorY:skip",{details:Fe.reason});return}if(Fe.reason==="shortHost"){q=Fe.nextPrevCursorBufferRow,K("followCursorY:skip",{details:Fe.reason});return}if(Fe.reason==="same-row"){K("followCursorY:skip[same-row]",{cursorDeltaRows:Fe.cursorDeltaRows,details:`cursorRow=${ye} same-row`});return}if(q=Fe.nextPrevCursorBufferRow,Fe.reason==="inViewport"){K("followCursorY:skip",{cursorDeltaRows:Fe.cursorDeltaRows,details:`cursorRow=${Te??"null"}->${ye} inViewport`});return}if(Fe.reason==="aligned"){K("followCursorY:skip",{cursorDeltaRows:Fe.cursorDeltaRows,details:`cursorRow=${Te??"null"}->${ye} aligned`});return}if(Fe.action!=="follow")return;M=Fe.targetScrollTop;const Rt=t.scrollTop;t.scrollTop=Fe.targetScrollTop,K("followCursorY:hit",{cursorDeltaRows:Fe.cursorDeltaRows,scrollDeltaToAnchor:Rt-Fe.targetScrollTop,details:`cursorRow=${Te??"null"}->${ye} scrollTop=${Math.round(Rt)}->${Math.round(Fe.targetScrollTop)}`})},he=()=>{if(!te()){J("followCursorX");return}const{cellW:ne}=k();if(ne<=0)return;const ce=i.buffer.active.cursorX*ne,Ce=t.scrollLeft,re=Ce+t.clientWidth;if(ce>=Ce&&ce<=re){if(Q()){K("followCursorX:skip",{details:`horizontalTouchIntent cursorPx=${ce} viewport=${Ce}..${re}`});return}const Fe=Ng(z,{details:`site=followCursorX cursorPx=${ce} viewport=${Ce}..${re}`,scrollLeft:t.scrollLeft});z=Fe.state,ee(Fe.trace),K("followCursorX:skip",{details:"cursorInViewport"});return}if(z.intent){K("followCursorX:skip",{details:`horizontalIntent cursorPx=${ce} viewport=${Ce}..${re}`});return}const ye=Math.max(0,ce-t.clientWidth/2),Te=Math.max(0,t.scrollWidth-t.clientWidth),ze=Math.min(Te,ye);z=mpe(z,ze),t.scrollLeft=ze,K("followCursorX:hit",{details:`cursorPx=${ce} viewport=${Ce}..${re} target=${ze}`})},pe=()=>{K("render"),Gt(),O&&(K("pending-sync-retry-fire"),Dn()),Xn(),he(),oe(),V&&G()&&(V=(w==null?void 0:w())===!1),qe()};Gt(),G()?qe():Xe("init");const se=_pe({container:t,term:i,onWheel:ne=>{te()&&Math.abs(ne.deltaX)>0&&Math.abs(ne.deltaX)>=Math.abs(ne.deltaY)&&me(`site=wheel deltaX=${ne.deltaX}`),ne.deltaY!==0&&(K("wheel:enter"),ne.preventDefault(),ne.stopPropagation(),Me(ne.deltaY))},onTouchStart:wt.onTouchStart,onTouchMove:wt.onTouchMove,onTouchEnd:wt.onTouchEnd,onTouchCancel:wt.onTouchCancel,onContainerScroll:ct,onTermScroll:Pt,onRender:pe,onRelayout:ie,onWriteParsed:()=>{At+=1}});return{dispose:()=>{se.dispose(),B.dispose(),kt(),x==null||x()},relayout:ie,scrollToBottom:Xe,preparePageResumeRestore:tt,restorePageResume:ut,scrollToRatio:de,scrollToXRatio:nt,resetHorizontalScroll:Je,markHorizontalScrollIntent:lt,traceRawInputFollowScheduled:Tt,traceRawInputFollowFire:_e,refreshReviewSnapshot:Be,getDebugProbe:()=>{const{cellH:ne,cellW:ce}=k(),{paddingTop:Ce,paddingBottom:re}=R();return{cellH:ne,cellW:ce,paddingTop:Ce,paddingBottom:re,canvasLastY:ne>0&&ce>0?hn():-1,userHasVerticalScrollIntent:G(),verticalIntentMode:W.mode,verticalIntentSource:W.source,verticalIntentTransitionId:W.lastTransitionId,userHasHorizontalScrollIntent:z.intent,pendingProgrammaticScrollTop:U,pendingFollowCursorScrollTop:M,pendingFollowCursorScrollLeft:z.pendingFollowLeft,prevCursorBufferRow:q,lastSeenScrollTop:L,lastSeenScrollLeft:z.lastSeenLeft,touchScrollActive:W.touchActive,touchScrollGestureMode:wt.getState().gestureMode,syncingInternal:T.internal,syncingExternal:T.external,atBottomThreshold:E,lastSpacerUpdateAt:F,pendingContainerSyncRetry:O}}}}function $pe(e,t={}){const{onFramePending:n,onFrameWritten:r,schedule:i=v=>requestAnimationFrame(v),cancel:s=v=>cancelAnimationFrame(v)}=t;let o=null,l=!1,u=[],d=[];const h=()=>{u=[],d=[],o!==null&&(s(o),o=null)},p=()=>{if(o=null,l||u.length===0)return;const v=u,_=d;u=[],d=[];const w=v.reduce((k,R)=>k+R.byteLength,0),x=new Uint8Array(w);let E=0;for(const k of v)x.set(k,E),E+=k.byteLength;e.write(x,()=>{for(const k of _)k();r==null||r()})},y=()=>{l||o!==null||u.length===0||(o=i(p))};return{target:{reset:()=>{h(),e.reset()},resize:(v,_)=>e.resize(v,_),write:(v,_)=>{if(typeof v=="string"){e.write(v,_);return}const w=u.length===0;u.push(v),_&&d.push(_),w&&(n==null||n()),y()}},clear:h,dispose:()=>{l=!0,h()}}}const $2=5e3,Hpe=1e3;function Upe(e={}){let t=0;const n=e.requestIdFactory??(()=>`pty-snapshot-${++t}`);let r=null,i=!1,s=[];const o=new Map;let l=0,u=0;const d=h=>{let p=0,y=l+1;for(;o.has(y);){const v=o.get(y);o.delete(y),l=y,h.write(v),p+=1,y+=1}return p};return{startSnapshotRequest(){const h=n();return r=h,i=!1,s=[],o.clear(),u+=1,h},hasAppliedSnapshot(){return i},hasPendingGap(){return i&&o.size>0},handleBinaryFrame(h,p){if(!i)return s.push(h),s.length>$2&&s.splice(0,s.length-$2),{written:!1,hasGap:!1};if(h.outputSeq<=l)return{written:!1,hasGap:!1};if(o.set(h.outputSeq,h.data),o.size>Hpe){const v=o.keys().next().value;v!==void 0&&o.delete(v)}return{written:d(p)>0,hasGap:o.size>0}},applySnapshot(h,p){if(!r)return{applied:!1,reason:"no_active_request"};if(h.requestId!==r)return{applied:!1,reason:"stale_snapshot"};const y=s;s=[],o.clear(),r=null,i=!0,l=h.outputSeq,u+=1;const v=u,_=y.filter(w=>w.outputSeq>h.outputSeq).sort((w,x)=>w.outputSeq-x.outputSeq);return p.reset(),p.resize(h.cols,h.rows),p.write(h.data,()=>{if(v===u){for(const w of _)o.set(w.outputSeq,w.data);d(p)}}),{applied:!0,replayedFrames:_.length}}}}function Wpe(e){const{sessionId:t,ws:n,relay:r,target:i,retryDelayMs:s=3e4,slowNoticeDelayMs:o=1e4,gapRecoveryDelayMs:l=2e3,scheduleReady:u=$=>requestAnimationFrame($),scheduleFrameFlush:d,cancelFrameFlush:h,onFramePending:p,onFrameWritten:y,onReady:v,onSubscribeDelayed:_,onSubscribeStarted:w,onGapRecovery:x}=e,E=Upe(),R=$pe({reset:()=>i.reset(),resize:($,P)=>i.resize($,P),write:($,P)=>{i.write($,()=>{$ instanceof Uint8Array&&Coe(t,$.byteLength),P==null||P()})}},{onFramePending:p,onFrameWritten:y,schedule:d,cancel:h});let A=!1,I=null,T=null,H=null,D=!1;const W=()=>{I&&(clearTimeout(I),I=null)},U=()=>{T&&(clearTimeout(T),T=null)},F=()=>{H&&(clearTimeout(H),H=null)},O=()=>{H||(H=setTimeout(()=>{H=null,!(A||!E.hasPendingGap())&&(x==null||x(),N())},l))},M=()=>{const $=E.startSnapshotRequest();n.send(JSON.stringify({type:"session_subscribe",sessionId:t,requestId:$}))},z=()=>{I=setTimeout(()=>{I=null,!(A||E.hasAppliedSnapshot())&&(M(),z())},s)},L=()=>{T=setTimeout(()=>{T=null,!(A||E.hasAppliedSnapshot()||D)&&(D=!0,_==null||_())},o)},N=()=>{A||(W(),U(),F(),R.clear(),D=!1,w==null||w(),M(),z(),L())},q=n.subscribeBinary(t,($,P)=>{if(A)return;Eoe(t,$,P),E.handleBinaryFrame({data:$,outputSeq:P},R.target).hasGap?O():F()}),Y=r.onMessage($=>{if(A||$.sessionId!==t)return;if($.type==="terminal_resize"){R.target.resize($.cols,$.rows),N();return}$.type!=="session_snapshot"||!E.applySnapshot({requestId:$.requestId,cols:$.cols,rows:$.rows,data:$.data,outputSeq:$.outputSeq},R.target).applied||(W(),U(),u(()=>{A||v==null||v()}))});return N(),{dispose:()=>{A=!0,W(),U(),F(),R.dispose(),q(),Y()}}}function qpe(e){const{host:t,sessionId:n,ws:r,relay:i,createTerminal:s,attachRawInput:o,attachTransport:l=Wpe,scheduleAutoFocus:u=D=>requestAnimationFrame(D),onTerminalReady:d,onFramePending:h,onFrameWritten:p,onRawInput:y,isInputEnabled:v,canFocus:_=()=>!0,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E,onError:k}=e;let R=!1,A=null,I=null,T=null,H=null;return(async()=>{try{const D=await s(t);if(R){D.dispose();return}A=D.dispose,I=o(D.terminal,n,{onRawInput:y,...v?{isInputEnabled:v}:{}}).dispose;const W=()=>{_()&&D.terminal.focus()};t.addEventListener("pointerdown",W,{passive:!0}),H=()=>t.removeEventListener("pointerdown",W),d==null||d(D.terminal),u(()=>{R||W()}),T=l({sessionId:n,ws:r,relay:i,target:D.terminal,onFramePending:h,onFrameWritten:p,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E})}catch(D){console.error("[pty-terminal-controller] initialization failed",D),k==null||k(D)}})(),{dispose:()=>{R=!0,T==null||T.dispose(),H==null||H(),I==null||I(),A==null||A()}}}function fE(e){if(/^[a-z][a-z0-9+.-]*:\/\//i.test(e))return!1;const t=e.indexOf(":");if(t<=0)return!1;const n=e.slice(0,t),r=e.slice(t+1);return!r.includes("/")||!/^[A-Za-z0-9._~-]+(?:@[A-Za-z0-9.-]+)?$/.test(n)||!(n.includes("@")?n.slice(n.lastIndexOf("@")+1):n).includes(".")?!1:/^[A-Za-z0-9._~%+-]+(?:\/[A-Za-z0-9._~%+-]+)+$/.test(r)}const Vpe=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*?\\.(?:png|jpe?g|webp|gif)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","gi"),Ype=/\.(?:png|jpe?g|webp|gif)$/i;function m4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function Kpe(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(/\.(?:png|jpe?g|webp|gif)$/i,""),n=t.split("/").pop()??t;return n.length<2?!1:/[A-Za-z_-]/.test(n)}function pE(e){const t=m4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||fE(t)||!Ype.test(t)?!1:Kpe(t)}function Gpe(e){const t=new Set,n=[];for(const r of e.matchAll(Vpe)){const i=m4(r[0]??"");!pE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const ov=16,Xpe=8,Zpe=/(?:^|[\s([{@])@?(?:\/|\.\/|\.\.\/|~\/|\.dev-anywhere\/)[A-Za-z0-9_./~%+,:=#-]*$/,Qpe=/^[A-Za-z0-9_./~%+,:=#-]+$/;function g4(e,t,n){const r=[eme(e,t),...tme(e,t)].filter(s=>s!==null),i=new Set;return r.flatMap(s=>{const o=s.parts.map(l=>l.text).join("");return Jpe(o,n).map(l=>{const u=sme(s.parts,l.startIndex),d=ome(s.parts,l.endIndex);return!u||!d?null:{path:l.path,startLineNumber:u.lineNumber,startColumn:u.column,endLineNumber:d.lineNumber,endColumn:d.column,segments:ame(s.parts,l.startIndex,l.endIndex)}}).filter(l=>l!==null).filter(l=>t>=l.startLineNumber&&t<=l.endLineNumber).filter(l=>{const u=`${l.path}:${l.startLineNumber}:${l.startColumn}:${l.endLineNumber}:${l.endColumn}`;return i.has(u)?!1:(i.add(u),!0)})})}function v4(e){return e.segments.length>0?e.segments.map(t=>({start:{x:t.startColumn,y:t.lineNumber},end:{x:t.endColumn,y:t.lineNumber}})):[{start:{x:e.startColumn,y:e.startLineNumber},end:{x:e.endColumn,y:e.endLineNumber}}]}function Jpe(e,t){const n=t(e),r=[];let i=0;for(const s of n){const o=e.indexOf(s,i);if(o<0)continue;const l=o>0&&e[o-1]==="@"?o-1:o,u=o+s.length;r.push({path:s,startIndex:l,endIndex:u}),i=o+s.length}return r}function eme(e,t){const n=e.buffer.active;let r=t,i=t;for(let s=0;s<ov;s+=1){const o=n.getLine(r-1);if(!(o!=null&&o.isWrapped)||r<=1)break;r-=1}for(let s=0;s<ov;s+=1){const o=n.getLine(i);if(!(o!=null&&o.isWrapped))break;i+=1}return WS(e,r,i)}function WS(e,t,n){const r=e.buffer.active;let i=n??t;if(n===void 0)for(let o=0;o<ov;o+=1){const l=r.getLine(i);if(!(l!=null&&l.isWrapped))break;i+=1}const s=[];for(let o=t;o<=i;o+=1){const l=r.getLine(o-1);if(!l)return null;const u=l.translateToString(!0);s.push({lineNumber:o,sourceText:u,sourceStartIndex:0,text:u})}return{startLineNumber:t,endLineNumber:i,parts:s}}function tme(e,t){const n=e.buffer.active,r=[],i=Math.max(1,t-ov);for(let s=i;s<=t;s+=1){const o=n.getLine(s-1);if(!o||o.isWrapped)continue;const l=nme(e,s);l&&t>=l.startLineNumber&&t<=l.endLineNumber&&r.push(l)}return r}function nme(e,t){const n=WS(e,t);if(!n)return null;const r=n.parts.map(l=>l.text).join("");if(!Zpe.test(r))return null;const i=[...n.parts];let s=n.endLineNumber,o=!1;for(let l=0;l<Xpe;l+=1){const u=s+1,d=WS(e,u);if(!d)break;const h=d.parts[0];if(!h)break;const p=rme(h.sourceText),y=h.sourceText.slice(p);if(!ime(p,y))break;i.push({...h,sourceStartIndex:p,text:y}),i.push(...d.parts.slice(1)),o=!0,s=d.endLineNumber}return o?{startLineNumber:t,endLineNumber:s,parts:i}:null}function rme(e){var t;return((t=e.match(/^\s*/))==null?void 0:t[0].length)??0}function ime(e,t){return e<2||!t||t.startsWith("-")||t.startsWith("•")||t.startsWith("›")||t.includes("://")?!1:Qpe.test(t)}function sme(e,t){let n=t;for(let r=0;r<e.length;r+=1){const i=e[r];if(i){if(n<i.text.length)return{lineNumber:i.lineNumber,column:qS(i.sourceText,i.sourceStartIndex+n)};if(n===i.text.length&&r<e.length-1){const s=e[r+1];return s?{lineNumber:s.lineNumber,column:qS(s.sourceText,s.sourceStartIndex)}:null}n-=i.text.length}}return null}function ome(e,t){let n=t-1;for(const r of e){if(n<r.text.length)return{lineNumber:r.lineNumber,column:mE(r.sourceText.slice(0,r.sourceStartIndex+n+1))};n-=r.text.length}return null}function ame(e,t,n){const r=[];let i=0;for(const s of e){const o=i+s.text.length,l=Math.max(t,i),u=Math.min(n,o);if(l<u){const d=l-i,h=u-i;r.push({lineNumber:s.lineNumber,startColumn:qS(s.sourceText,s.sourceStartIndex+d),endColumn:mE(s.sourceText.slice(0,s.sourceStartIndex+h))})}i=o}return r}function qS(e,t){return mE(e.slice(0,t))+1}function mE(e){let t=0;for(const n of e)t+=lme(n.codePointAt(0)??0);return t}function lme(e){return e===0||e<32||e>=127&&e<160||cme(e)?0:ume(e)?2:1}function cme(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function ume(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}function y4(e,t){return g4(e,t,Gpe)}function dme(e){var n,r;if(e.metaKey||e.ctrlKey)return!0;const t="pointerType"in e?String(e.pointerType):"";return t==="touch"||t==="pen"?!0:((r=(n=window.matchMedia)==null?void 0:n.call(window,"(pointer: coarse), (hover: none)"))==null?void 0:r.matches)??!1}function hme(e,t){const n={provideLinks(i,s){const o=y4(e,i);if(o.length===0){s(void 0);return}const l=o.reduce((u,d)=>{for(const h of v4(d))h.start.y!==i||h.end.y!==i||u.push({text:d.path,range:h,decorations:{underline:!0,pointerCursor:!0},activate:p=>{dme(p)&&t(d.path)}});return u},[]);s(l.length>0?l:void 0)}},r=e.registerLinkProvider(n);return{dispose:()=>r.dispose(),provider:n}}const fme=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*\\.[A-Za-z0-9]{1,8}(?=[\\s`\"'<>),.;:!?,。;:!?、]|$)","gi"),pme=/\.(?:png|jpe?g|webp|gif)$/i,mme=/\.[A-Za-z0-9]{1,8}$/,gme=/^(?:com|net|org|io|dev|app|top|cn|ai|co|me|xyz|site|online|cloud|tools|tech|info|biz|us|uk|de|jp|fr|ru|nl|in)$/i,vme=new Set(["cargo.toml","composer.json","eslint.config.js","eslint.config.mjs","gemfile.lock","go.mod","go.sum","package-lock.json","package.json","pnpm-lock.yaml","prettier.config.js","pyproject.toml","readme.md","requirements.txt","tailwind.config.js","tailwind.config.ts","tsconfig.json","vite.config.ts","vitest.config.ts","yarn.lock"]);function b4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function yme(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(/\.[A-Za-z0-9]{1,8}$/,""),n=t.split("/").pop()??t;return n.length<2?!1:/[A-Za-z_-]/.test(n)}function bme(e){if(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 gme.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function _me(e){return e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/")||e.includes("/")}function wme(e){return _me(e)?!0:vme.has(e.toLowerCase())}function gE(e){const t=b4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||fE(t)||bme(t)||pme.test(t)||!mme.test(t)||!wme(t)||t.split("/").includes("...")?!1:yme(t)}function Sme(e){const t=new Set,n=[];for(const r of e.matchAll(fme)){const i=b4(r[0]??"");!gE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const xme=750;function _4(e,t){return g4(e,t,Sme)}function Eme(e){return e.metaKey||e.ctrlKey}function Cme(e,t){let n=null;const r=(o,l)=>{if(!Eme(l))return;const u=performance.now();(n==null?void 0:n.path)===o&&u-n.at<xme||(n={path:o,at:u},t(o))},i={provideLinks(o,l){const u=_4(e,o);if(u.length===0){l(void 0);return}const d=u.reduce((h,p)=>{for(const y of v4(p))y.start.y!==o||y.end.y!==o||h.push({text:p.path,range:y,decorations:{underline:!1,pointerCursor:!0},hover:()=>{kme(e,p)},leave:()=>{Mg(e)},dispose:()=>{Mg(e)},activate:v=>{r(p.path,v)}});return h},[]);l(d.length>0?d:void 0)}},s=e.registerLinkProvider(i);return{dispose:()=>{Mg(e),s.dispose()},provider:i}}function kme(e,t){const n=e.element;if(!n)return;const r=n.querySelector(".xterm-screen");if(!r||e.cols<=0||e.rows<=0)return;const i=n.getBoundingClientRect(),s=r.getBoundingClientRect(),o=(r.clientWidth||s.width)/e.cols,l=(r.clientHeight||s.height)/e.rows;if(!Number.isFinite(o)||!Number.isFinite(l)||o<=0||l<=0)return;Mg(e),Tme(n);const u=document.createElement("div");u.dataset.slot="pty-file-link-hover-overlay",u.style.position="absolute",u.style.inset="0",u.style.pointerEvents="none",u.style.zIndex="4",n.append(u);const d=s.left-i.left,h=s.top-i.top,p=e.buffer.active.viewportY;for(const y of t.segments){const v=y.lineNumber-p;if(v<1||v>e.rows)continue;const _=document.createElement("div");_.dataset.slot="pty-file-link-hover-segment",_.dataset.range=`${y.lineNumber}:${y.startColumn}-${y.endColumn}`,_.style.position="absolute",_.style.left=`${d+(y.startColumn-1)*o}px`,_.style.top=`${h+(v-1)*l+l-2}px`,_.style.width=`${Math.max(1,y.endColumn-y.startColumn+1)*o}px`,_.style.height="2px",_.style.background="currentColor",_.style.opacity="0.8",u.append(_)}}function Mg(e){var t;(t=e.element)==null||t.querySelectorAll('[data-slot="pty-file-link-hover-overlay"]').forEach(n=>n.remove())}function Tme(e){window.getComputedStyle(e).position==="static"&&(e.style.position="relative")}function Wa(e,t={}){const n=window.__ccTestPtyTouchLinkActivations;n&&(n.push({event:e,t:performance.now(),...t}),n.length>200&&n.splice(0,n.length-200))}function Rme(e,t,n){const r=e.range.start.y*n+e.range.start.x,i=e.range.end.y*n+e.range.end.x,s=t.y*n+t.x;return r<=s&&s<=i}function Ame(e){const t=new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,clientX:e.clientX,clientY:e.clientY});return Object.defineProperty(t,"pointerType",{configurable:!0,value:"touch"}),t}function w4(e,t,n){if(t.length===0)return Wa("skip",{reason:"no-providers",point:n}),null;const r=e.element,i=r==null?void 0:r.querySelector(".xterm-screen"),s=(r==null?void 0:r.parentElement)??r;if(!i||!s)return Wa("skip",{reason:"missing-elements",hasScreen:!!i,hasMetricHost:!!s,point:n}),null;const o=hE(s,e);if(!o||o.cellW<=0||o.cellH<=0)return Wa("skip",{reason:"missing-metrics",metrics:o,point:n}),null;const l=i.getBoundingClientRect(),u=Math.floor((n.clientX-l.left)/o.cellW)+1,d=Math.floor((n.clientY-l.top)/o.cellH)+1;if(u<1||u>e.cols||d<1||d>e.rows)return Wa("skip",{reason:"point-out-of-range",point:n,viewportX:u,viewportY:d,cols:e.cols,rows:e.rows,rect:{left:l.left,top:l.top,width:l.width,height:l.height},metrics:o}),null;const h=e.buffer.active.viewportY+d,p={x:u,y:h};Wa("probe",{point:n,viewportX:u,viewportY:d,bufferLineNumber:h,providers:t.length,metrics:o});for(const y of t){let v=null;if(y.provideLinks(h,_=>{Wa("links",{bufferLineNumber:h,position:p,count:(_==null?void 0:_.length)??0,links:_==null?void 0:_.map(x=>({text:x.text,range:x.range}))});const w=_==null?void 0:_.find(x=>Rme(x,p,e.cols));w&&(v=w)}),v)return v}return Wa("miss",{position:p,point:n,bufferLineNumber:h}),null}function Nme(e,t,n){return w4(e,t,n)!==null}function Mme(e,t,n){const r=w4(e,t,n);return r?(r.activate(Ame(n),r.text),Wa("activate",{text:r.text,range:r.range,point:n}),!0):!1}const Ome=2*1024*1024,Dme=2560,H2=.82,Pme=.9,Lme=new Set(["image/jpeg","image/png","image/webp"]),S4=new Map([["image/jpeg","jpg"],["image/png","png"],["image/webp","webp"]]);function x4(e){return e.size>Ome&&Lme.has(e.type)}function Ime(e,t,n=Dme){const r=Math.max(e,t);if(!Number.isFinite(r)||r<=0)throw new Error("图片尺寸无效");const i=Math.min(1,n/r);return{width:Math.max(1,Math.round(e*i)),height:Math.max(1,Math.round(t*i))}}function zme(e,t){const n=S4.get(t);return n?`${e.replace(/\.(?:jpe?g|png|webp)$/iu,"")||"image"}.${n}`:e}function Bme(){return typeof createImageBitmap!="function"||typeof document>"u"?null:{async decode(e){const t=await createImageBitmap(e,{imageOrientation:"from-image"});return{source:t,width:t.width,height:t.height,close:()=>t.close()}},async encode(e,t,n,r,i){const s=document.createElement("canvas");s.width=t,s.height=n;const o=s.getContext("2d");if(!o)throw new Error("浏览器无法创建图片压缩画布");return o.imageSmoothingEnabled=!0,o.imageSmoothingQuality="high",o.drawImage(e.source,0,0,t,n),new Promise(l=>s.toBlob(l,r,i))}}}async function E4(e,t=Bme()){var r;if(!x4(e)||!t)return e;let n=null;try{n=await t.decode(e);const i=Ime(n.width,n.height);let s=await t.encode(n,i.width,i.height,"image/webp",H2);return(s==null?void 0:s.type)!=="image/webp"&&e.type==="image/jpeg"&&(s=await t.encode(n,i.width,i.height,"image/jpeg",H2)),!s||!S4.has(s.type)||s.size>=e.size*Pme?e:new File([s],zme(e.name,s.type),{type:s.type,lastModified:e.lastModified})}catch{return e}finally{(r=n==null?void 0:n.close)==null||r.call(n)}}async function Cf(e){const t=x4(e.file),n=et.loading(t?`正在压缩并上传 ${e.file.name} ...`:`上传 ${e.file.name} ...`);try{const r=await E4(e.file),i=await e.relay.uploadFile(e.sessionId,r);return!i.success||!i.path?(et.error(i.error??"上传失败",{id:n}),null):(e.successLabel===null?et.dismiss(n):et.success(e.successLabel??`已上传 ${i.path}`,{id:n}),i.path)}catch(r){return et.error(r instanceof Error?r.message:String(r),{id:n}),null}}function U2(e){let t=null,n=!1;const r=()=>{t=null,n||e()};return{schedule:()=>{n||t!==null||(t=requestAnimationFrame(r))},dispose:()=>{n=!0,t!==null&&(cancelAnimationFrame(t),t=null)}}}const W2="--dev-visual-viewport-height",jme=.3;function C4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i=!0,subtractVisualViewportOffsetTop:s=!0}){const o=s?n:0,l=e-t-o,u=r-t-o,d=q2(l,e),h=i?q2(u,r):0;return Math.max(d,h)}function Fme({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r=e,allowBaselineFallback:i=!1,softKeyboardOpen:s=!1}){return s?Math.max(e-t-n,0):C4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i})}function q2(e,t){const n=Math.max(e,0);return n<=0?0:n/Math.max(t,1)>=jme?n:0}function $me(){b.useEffect(()=>{const e=window.visualViewport;let t=0;const n=()=>{cancelAnimationFrame(t),t=requestAnimationFrame(()=>{const r=(e==null?void 0:e.height)??window.innerHeight;document.documentElement.style.setProperty(W2,`${r}px`)})};return n(),window.addEventListener("resize",n),e==null||e.addEventListener("resize",n),e==null||e.addEventListener("scroll",n),()=>{cancelAnimationFrame(t),window.removeEventListener("resize",n),e==null||e.removeEventListener("resize",n),e==null||e.removeEventListener("scroll",n),document.documentElement.style.removeProperty(W2)}},[])}function V2(){const e=document.documentElement,t=document.body;return window.scrollX!==0||window.scrollY!==0||e.scrollLeft!==0||e.scrollTop!==0||t.scrollLeft!==0||t.scrollTop!==0?(window.scrollTo(0,0),e.scrollLeft=0,e.scrollTop=0,t.scrollLeft=0,t.scrollTop=0,!0):!1}function Hme(){b.useEffect(()=>{const e=window.visualViewport;let t=0;const n=()=>{V2(),cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,V2()})};return n(),window.addEventListener("scroll",n,{passive:!0}),window.addEventListener("resize",n),e==null||e.addEventListener("scroll",n,{passive:!0}),e==null||e.addEventListener("resize",n),()=>{cancelAnimationFrame(t),window.removeEventListener("scroll",n),window.removeEventListener("resize",n),e==null||e.removeEventListener("scroll",n),e==null||e.removeEventListener("resize",n)}},[])}function Ume(){return vE().bottomOffset}function vE(){const[e,t]=b.useState({bottomOffset:0,layoutBottomInset:0}),n=b.useRef(0),r=b.useRef(0);return b.useEffect(()=>{const i=window.visualViewport;if(!i)return;const s=Wme();let o=0;const l=()=>{const h=i.height,p=i.offsetTop,y=i.width,v=Math.max(window.innerHeight,h+p);!n.current||Math.abs(y-r.current)>1?(n.current=v,r.current=y):n.current=Math.max(n.current,v);const _=window.innerHeight,w=qme(),x=!s||w,E=s&&w,k=C4({layoutViewportHeight:_,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:x,subtractVisualViewportOffsetTop:s}),R={bottomOffset:k,layoutBottomInset:Fme({layoutViewportHeight:_,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:E,softKeyboardOpen:k>0})};t(A=>A.bottomOffset===R.bottomOffset&&A.layoutBottomInset===R.layoutBottomInset?A:R)},u=()=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=0,l()})};u(),window.addEventListener("resize",u),i.addEventListener("resize",u),i.addEventListener("scroll",u);const d=()=>{setTimeout(u,300)};return window.addEventListener("focusout",d),()=>{cancelAnimationFrame(o),window.removeEventListener("resize",u),i.removeEventListener("resize",u),i.removeEventListener("scroll",u),window.removeEventListener("focusout",d)}},[]),e}function Wme(){if(typeof navigator>"u")return!1;const e=navigator.userAgent??"",t=navigator.platform??"",n=navigator.maxTouchPoints??0;return/iPad|iPhone|iPod/.test(e)||t==="MacIntel"&&n>1&&(e.includes("Mac OS X")||e.includes("Macintosh"))}function qme(){const e=document.activeElement;return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Vme(e){window.__devAnywherePtyTerminal=e}function Yme(){window.__devAnywherePtyTerminal&&delete window.__devAnywherePtyTerminal}function Kme(e){window.__devAnywherePtyDebug=e}function Gme(){window.__devAnywherePtyDebug&&delete window.__devAnywherePtyDebug}function Xme(e,t){const n=e(),{container:r,spacer:i,host:s,term:o}=t,{cellH:l,cellW:u,paddingTop:d,paddingBottom:h,canvasLastY:p}=n,y=Math.max(0,r.clientHeight-d-h),v=o.buffer.active;let _=0;if(l>0&&u>0){const z=h4({bufferLength:v.length,rows:o.rows,cols:o.cols,viewportY:v.viewportY,cursorY:v.cursorY,cellH:l,cellW:u,visibleContentHeight:y},p);_=(z==null?void 0:z.spacerHeight)??0}const w=Hs(i.style.height),x=Hs(s.style.top),E=Hs(s.style.height),k=Hs(s.style.width),R=Hs(s.style.paddingTop),A=Hs(i.style.width);let I=0;if(l>0){const z=o.rows*l,L=z>0&&z<y?y-z:0;I=Math.max(0,v.viewportY*l+L)}const T=x-I,H=r.scrollTop,D=H+r.clientHeight,W=x+E,U=Math.max(0,Math.min(D,W)-Math.max(H,x)),F=r.clientHeight>0?U/r.clientHeight:0,O=v.baseY+v.cursorY,M=dE({rows:o.rows,cellH:l,bufferLength:v.length,cursorBufferRow:O,visibleContentHeight:y,paddingTop:d,paddingBottom:h,containerScrollTop:r.scrollTop,containerScrollHeight:r.scrollHeight,containerClientHeight:r.clientHeight,atBottomThreshold:n.atBottomThreshold});return{ts:performance.now(),container:{scrollTop:r.scrollTop,scrollLeft:r.scrollLeft,scrollHeight:r.scrollHeight,scrollWidth:r.scrollWidth,clientHeight:r.clientHeight,clientWidth:r.clientWidth,paddingTop:d,paddingBottom:h},spacer:{height:w,width:A},host:{top:x,height:E,width:k,paddingTop:R,expectedTop:I,topDrift:T},term:{rows:o.rows,cols:o.cols,bufferLength:v.length,viewportY:v.viewportY,baseY:v.baseY,cursorX:v.cursorX,cursorY:v.cursorY},cell:{h:l,w:u},visibleContentHeight:y,anchor:{atBottom:M.isAtBottom,cursorInViewport:M.cursorInViewport,cursorBufferRow:O,bottomScrollTop:M.bottomScrollTop,scrollTopDeltaToBottom:r.scrollTop-M.bottomScrollTop},intent:{vertical:n.userHasVerticalScrollIntent,horizontal:n.userHasHorizontalScrollIntent},verticalIntent:{mode:n.verticalIntentMode,source:n.verticalIntentSource,transitionId:n.verticalIntentTransitionId},pinned:!n.userHasVerticalScrollIntent,pendingProgrammaticScrollTop:n.pendingProgrammaticScrollTop,pendingFollowCursorScrollTop:n.pendingFollowCursorScrollTop,pendingFollowCursorScrollLeft:n.pendingFollowCursorScrollLeft,prevCursorBufferRow:n.prevCursorBufferRow,lastSeenScrollTop:n.lastSeenScrollTop,lastSeenScrollLeft:n.lastSeenScrollLeft,touchScrollActive:n.touchScrollActive,touchScrollGestureMode:n.touchScrollGestureMode,syncing:{internal:n.syncingInternal,external:n.syncingExternal},pending:{programmaticScrollTop:n.pendingProgrammaticScrollTop,followCursorScrollTop:n.pendingFollowCursorScrollTop,followCursorScrollLeft:n.pendingFollowCursorScrollLeft,containerSyncRetry:n.pendingContainerSyncRetry},expectedSpacerHeight:_,spacerDrift:w-_,lastSpacerUpdateAt:n.lastSpacerUpdateAt,viewportHostCoverage:F,pendingContainerSyncRetry:n.pendingContainerSyncRetry}}const sy={enabled:!1,phase:"idle",error:null,lastSpokenText:"",approvalRequestId:null,activityLevel:0,waveform:[],resumeRequestSeq:0};function Zme(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function Bs(e,t,n){const r=e.bySessionId[t]??sy;return{bySessionId:{...e.bySessionId,[t]:n(r)}}}const sn=ed()(td(e=>({bySessionId:{},enable:t=>e(n=>Bs(n,t,r=>({...r,enabled:!0,phase:"starting",error:null,waveform:[]}))),disable:t=>e(n=>Bs(n,t,r=>({...r,enabled:!1,phase:"idle",error:null,approvalRequestId:null,activityLevel:0,waveform:[]}))),requestResume:t=>e(n=>Bs(n,t,r=>({...r,resumeRequestSeq:r.resumeRequestSeq+1}))),setPhase:(t,n)=>e(r=>Bs(r,t,i=>({...i,phase:n,error:n==="error"?i.error:null}))),setError:(t,n)=>e(r=>Bs(r,t,i=>({...i,phase:"error",error:n,activityLevel:0,waveform:[]}))),clearError:t=>e(n=>Bs(n,t,r=>({...r,error:null,phase:r.enabled&&r.phase==="error"?"starting":r.phase}))),setLastSpokenText:(t,n)=>e(r=>Bs(r,t,i=>({...i,lastSpokenText:n}))),setApproval:(t,n)=>e(r=>Bs(r,t,i=>({...i,approvalRequestId:n}))),setActivityLevel:(t,n)=>e(r=>Bs(r,t,i=>({...i,activityLevel:Zme(n)}))),appendWaveform:(t,n)=>{n.length!==0&&e(r=>Bs(r,t,i=>({...i,waveform:[...i.waveform,...n].slice(-U0)})))},clearWaveform:t=>e(n=>Bs(n,t,r=>({...r,waveform:[]}))),resetAll:()=>e({bySessionId:{}})}),{name:"voice-pilot-store"}));function Qme(){const[e,t]=b.useState(!1),[n,r]=b.useState(!1),[i,s]=b.useState(!1);b.useEffect(()=>{if(e){r(!1);return}const p=setTimeout(()=>r(!0),300);return()=>clearTimeout(p)},[e]);const o=b.useCallback(()=>{t(!0),s(!1)},[]),l=b.useCallback(()=>{t(!1),s(!1)},[]),u=b.useCallback(()=>{s(!0)},[]),d=b.useMemo(()=>({connecting:n,subscribeDelayed:i}),[n,i]),h=b.useMemo(()=>({onReady:o,onSubscribeStarted:l,onSubscribeDelayed:u}),[o,u,l]);return{ready:e,overlay:d,transport:h}}const Jme=900;function ege(){var t;const e=navigator.virtualKeyboard;(t=e==null?void 0:e.show)==null||t.call(e)}function tge(e){const{containerEl:t,xtermHostRef:n,terminalRef:r}=e,[i,s]=b.useState(!1),o=b.useRef(0),l=b.useCallback(()=>{const v=document.activeElement;!t||!(v instanceof HTMLElement)||!t.contains(v)||v.blur()},[t]),u=b.useCallback(()=>{const v=n.current,_=document.activeElement,w=!!(v&&_ instanceof HTMLElement&&v.contains(_));s(w),w&&ege()},[n]),d=b.useCallback((v={})=>{o.current=performance.now()+Jme,(v.blur??!0)&&(l(),s(!1))},[l]),h=b.useCallback(v=>{if(performance.now()<=o.current){v.target instanceof HTMLElement&&v.target.blur(),window.setTimeout(u,0);return}u()},[u]),p=b.useCallback(()=>{window.setTimeout(u,0)},[u]),y=b.useCallback(()=>{var v;o.current=0,(v=r.current)==null||v.focus(),window.setTimeout(u,0)},[u,r]);return{ptyInputFocused:i,suppressPtyFocus:d,focusPtyInput:y,handleFocusCapture:h,handleBlurCapture:p}}function nge(){const[e,t]=b.useState(!0),[n,r]=b.useState(!1),i=b.useRef(n);b.useEffect(()=>{i.current=n},[n]);const s=b.useCallback(l=>{t(l),l&&r(!1)},[]),o=b.useCallback(()=>{r(!1)},[]);return{isAtBottom:e,hasNewFramesWhileAway:n,hasNewFramesWhileAwayRef:i,setHasNewFramesWhileAway:r,handleAtBottomChange:s,clearNewFramesWhileAway:o}}async function k4(e,{allowLegacyFallback:t=!1}={}){var r,i;const n=(i=(r=navigator.clipboard)==null?void 0:r.writeText)==null?void 0:i.bind(navigator.clipboard);if(n&&window.isSecureContext!==!1)try{return await n(e),"clipboard"}catch{}return t&&rge(e)?"legacy":"failed"}function rge(e){if(!document.body||typeof document.execCommand!="function")return!1;const t=document.createElement("textarea");t.value=e,t.readOnly=!0,t.setAttribute("aria-hidden","true"),t.style.position="fixed",t.style.left="-9999px",t.style.top="0",t.style.opacity="0",t.style.fontSize="16px",document.body.appendChild(t);try{return t.select(),t.setSelectionRange(0,e.length),document.execCommand("copy")}catch{return!1}finally{t.remove()}}const ige=new Intl.Segmenter("zh-CN",{granularity:"word"}),sge=/^[./:@_+~=-]+$/u,oge=/[a-z0-9]/iu;function T4({terminal:e,host:t,cellWidth:n,cellHeight:r}){return n&&r?{cellW:n,cellH:r}:hE(t,e)}function age(e,t){const n=Math.min(e.length,t),r=[];let i="";for(let s=0;s<n;s+=1){const o=e.getCell(s),l=(o==null?void 0:o.getWidth())??1;if(l===0)continue;const u=(o==null?void 0:o.getChars())||" ",d=i.length;i+=u,r.push({textStart:d,textEnd:i.length,cellStart:s,cellEnd:Math.min(n-1,s+Math.max(1,l)-1)})}return{text:i.trimEnd(),spans:r}}function Y2(e){return sge.test(e.segment)}function VS(e){return e.isWordLike===!0&&oge.test(e.segment)}function lge(e,t){let n=t,r=t;for(;n>0;){let o=n-1;for(;o>=0&&Y2(e[o]);)o-=1;if(o===n-1)break;if(o>=0&&VS(e[o])){n=o;continue}n=o+1;break}for(;r+1<e.length;){let o=r+1;for(;o<e.length&&Y2(e[o]);)o+=1;if(o===r+1||o>=e.length||!VS(e[o]))break;r=o}const i=e[n].index,s=e[r];return{start:i,end:s.index+s.segment.length}}function cge(e){const t=Array.from(ige.segment(e)),n=[],r=new Set,i=s=>{const o=`${s.start}:${s.end}`;r.has(o)||(r.add(o),n.push(s))};for(let s=0;s<t.length;s+=1){const o=t[s];o.isWordLike&&i(VS(o)?lge(t,s):{start:o.index,end:o.index+o.segment.length})}for(const s of t){if(s.isWordLike||!s.segment.trim())continue;const o={start:s.index,end:s.index+s.segment.length};n.some(l=>l.start<=o.start&&l.end>=o.end)||i(o)}return n.sort((s,o)=>s.start-o.start||s.end-o.end)}function uge(e,t){const{text:n,spans:r}=age(e,t);return cge(n).flatMap(i=>{const s=r.filter(u=>u.textStart<i.end&&u.textEnd>i.start),o=s[0],l=s.at(-1);return o&&l?[{start:o.cellStart,end:l.cellEnd}]:[]})}function dge(e,t){if(e.length===0)return null;let n=0,r=Number.POSITIVE_INFINITY;for(let i=0;i<e.length;i+=1){const s=e[i],o=t<s.start?s.start-t:t>s.end?t-s.end:0;o<r&&(r=o,n=i)}return n}function hge(e,t){return e.row<t.row||e.row===t.row&&e.column<=t.column?{start:e,end:t}:{start:t,end:e}}function fge(e,t,n){const r=[];for(let i=t.row;i<=n.row;i+=1){const s=e.buffer.active.getLine(i);if(!s){r.push("");continue}const o=i===t.row?t.column:0,l=i===n.row?n.column+1:e.cols;r.push(s.translateToString(!0,o,l))}return r.join(`
642
+ `),$.preventDefault(),!1):!0),{dispose:()=>{var $,P,V;z.dispose(),($=e.textarea)==null||$.removeEventListener("input",F),(P=e.textarea)==null||P.removeEventListener("compositionstart",O,!0),(V=e.textarea)==null||V.removeEventListener("compositionend",M),r&&(clearTimeout(r.timer),r=void 0),l&&(clearTimeout(l),l=void 0),p==null||p(),h==null||h(),w(),x()}}}function h4(e,t){if(e.cellH<=0||e.cellW<=0||e.rows<=0||e.cols<=0)return null;const n=e.rows*e.cellH,r=e.bufferLength<=e.rows,i=Math.max(0,e.visibleContentHeight??0),s=i>0?Math.min(n,i):n,o=t<0?1:Math.max(1,t+1),l=r?Math.max(0,s-o*e.cellH):0,u=Math.max(0,e.bufferLength-e.rows),d=u*e.cellH+i;if(i>0&&n>i&&e.cursorY!==void 0){const p=Math.max(0,Math.min(e.rows-1,e.cursorY)),y=u*e.cellH,v=y+n-i,_=y+p*e.cellH-(i-e.cellH)/2;return{spacerHeight:Math.max(y,Math.min(v,_))+i,spacerWidth:e.cols*e.cellW,hostWidth:e.cols*e.cellW,hostHeight:n,hostPaddingTop:l}}return{spacerHeight:Math.max(e.bufferLength*e.cellH,d),spacerWidth:e.cols*e.cellW,hostWidth:e.cols*e.cellW,hostHeight:n,hostPaddingTop:l}}function dE(e){const t=e.paddingTop+e.cursorBufferRow*e.cellH,n=e.containerScrollTop+e.paddingTop,r=e.containerScrollTop+e.containerClientHeight-e.paddingBottom,i=Math.max(1,e.atBottomThreshold),s=e.cellH>0&&t>=n-i&&t+e.cellH<=r+i,o=Math.max(0,e.containerScrollHeight-e.containerClientHeight),l=e.rows*e.cellH,u=e.cellH>0&&l>e.visibleContentHeight;let d,h;if(u){d=s;const p=t-e.paddingTop-(e.visibleContentHeight-e.cellH)/2,v=Math.max(0,e.bufferLength-e.rows)*e.cellH;h=Math.max(v,Math.min(o,p))}else d=e.containerScrollTop+e.containerClientHeight>=e.containerScrollHeight-e.atBottomThreshold,h=o;return{isAtBottom:d,bottomScrollTop:h,cursorInViewport:s}}function f4(e){if(e.cellH<=0)return 0;const t=e.rows*e.cellH,n=e.visibleContentHeight!==void 0&&t<e.visibleContentHeight?e.visibleContentHeight-t:0;return Math.max(0,e.ydisp*e.cellH+n)}function B2(e,t){if(t.cellH<=0)return{ydisp:t.viewportY};const n=Math.max(0,t.bufferLength-t.rows),r=n*t.cellH;if(e>=r)return{ydisp:n};const i=Math.max(0,Math.floor(e/t.cellH));return{ydisp:Math.min(i,n)}}function dpe(e,t){return t<=0?0:Math.max(0,e)*t}function hpe(){return{intent:!1,lastUserInputAt:null,unmarkedOriginLeft:null,lastSeenLeft:0,pendingFollowLeft:null}}function fpe(e,t){return{...e,intent:t,unmarkedOriginLeft:t?e.unmarkedOriginLeft:null}}function Ng(e,t){return{state:{...fpe(e,!1),lastUserInputAt:null,pendingFollowLeft:null,...t.scrollLeft!==void 0?{lastSeenLeft:t.scrollLeft}:{}},trace:e.intent?{kind:"clear",details:t.details}:null}}function ppe(e,t){return{state:{...e,intent:!0,lastUserInputAt:t.now,unmarkedOriginLeft:null},trace:e.intent?null:{kind:"set",details:t.details}}}function mpe(e,t){return{...e,pendingFollowLeft:t}}function gpe(e,t){if(!t.hasOverflow)return{...Ng(e,{details:`reason=not-scrollable scrollLeft=${t.scrollLeft}`,scrollLeft:0}),resetScrollLeft:t.scrollLeft!==0};if(t.scrollLeft===e.lastSeenLeft)return{state:e,trace:null,resetScrollLeft:!1};const n=t.pendingFollowTolerancePx??1,r=t.recentUserInputMs??500;if(e.pendingFollowLeft!==null&&Math.abs(t.scrollLeft-e.pendingFollowLeft)<=n)return{state:{...e,pendingFollowLeft:null,unmarkedOriginLeft:null,lastSeenLeft:t.scrollLeft},trace:null,resetScrollLeft:!1};if(e.lastUserInputAt!==null&&t.now-e.lastUserInputAt<=r){const u=`site=onContainerScroll prev=${e.lastSeenLeft} next=${t.scrollLeft}`;return{state:{...e,intent:!0,pendingFollowLeft:null,unmarkedOriginLeft:null,lastSeenLeft:t.scrollLeft},trace:e.intent?null:{kind:"set",details:u},resetScrollLeft:!1}}const o=e.unmarkedOriginLeft===null?e.lastSeenLeft:e.unmarkedOriginLeft,l=Math.abs(t.scrollLeft-o);if(l>=t.nativeIntentThresholdPx){const u=`site=onContainerScroll-native prev=${o} next=${t.scrollLeft} delta=${l}`;return{state:{...e,intent:!0,pendingFollowLeft:null,unmarkedOriginLeft:null,lastSeenLeft:t.scrollLeft},trace:e.intent?null:{kind:"set",details:u},resetScrollLeft:!1}}return{state:{...e,pendingFollowLeft:null,unmarkedOriginLeft:o,lastSeenLeft:t.scrollLeft},trace:{kind:"ignore",details:`site=onContainerScroll prev=${e.lastSeenLeft} next=${t.scrollLeft} nativeDelta=${l}`},resetScrollLeft:!1}}function vpe({syncingExternal:e,effectiveScrollTop:t,pendingFollowTop:n,pendingProgrammaticTop:r,atBottom:i,canPassiveFollow:s,tolerancePx:o=1}){if(e)return{action:"external-sync",nextPendingFollowTop:n,nextPendingProgrammaticTop:r};if(n!==null&&Math.abs(t-n)<=o)return{action:"programmatic-follow",nextPendingFollowTop:null,nextPendingProgrammaticTop:null};const u=r!==null&&Math.abs(t-r)<=o&&s;return!i&&u?{action:"programmatic-drift",nextPendingFollowTop:null,nextPendingProgrammaticTop:null}:{action:"continue",nextPendingFollowTop:null,nextPendingProgrammaticTop:null}}function ype(e){return!e.force&&e.reviewing?{action:"blocked-by-review"}:!e.reviewing&&e.viewportY===e.expectedYdisp&&(Math.abs(e.scrollTop-e.bottomScrollTop)<=1||!e.force&&e.atBottom)?{action:"noop"}:{action:"follow"}}function bpe(e){return!(e.bottomScrollTop<e.domMaxScrollTop-1)||e.rawScrollTop<=e.bottomScrollTop+1?{action:"keep",scrollTop:e.rawScrollTop}:{action:"clamp",scrollTop:e.bottomScrollTop}}function _pe({container:e,term:t,onWheel:n,onTouchStart:r,onTouchMove:i,onTouchEnd:s,onTouchCancel:o,onContainerScroll:l,onTermScroll:u,onRender:d,onRelayout:h,onWriteParsed:p}){var x;e.addEventListener("wheel",n,{passive:!1,capture:!0}),e.addEventListener("touchstart",r,{passive:!0}),e.addEventListener("touchmove",i,{passive:!0}),e.addEventListener("touchend",s,{passive:!0}),e.addEventListener("touchcancel",o,{passive:!0}),e.addEventListener("scroll",l,{passive:!0});const y=t.onScroll(u),v=t.onRender(d),_=p?(x=t.onWriteParsed)==null?void 0:x.call(t,p):void 0,w=new ResizeObserver(h);return w.observe(e),{dispose:()=>{e.removeEventListener("scroll",l),e.removeEventListener("wheel",n,{capture:!0}),e.removeEventListener("touchstart",r),e.removeEventListener("touchmove",i),e.removeEventListener("touchend",s),e.removeEventListener("touchcancel",o),y.dispose(),v.dispose(),_==null||_.dispose(),w.disconnect()}}}function wpe({container:e,host:t,term:n,atBottomThreshold:r,getDims:i,getVerticalInsets:s,getPrevCursorBufferRow:o,getPendingProgrammaticScrollTop:l,getPendingFollowCursorScrollTop:u,getPendingFollowCursorScrollLeft:d,getPendingContainerSyncRetry:h,getHorizontalIntent:p,getVerticalIntent:y,getUserHasVerticalScrollIntent:v}){var T,H;let _=null,w=null;const x=()=>{var z;const D=document.activeElement;if(!D)return null;const W=D.getAttribute("aria-label")??"",U=D.tagName,F=typeof D.closest=="function"?((z=D.closest("[data-slot]"))==null?void 0:z.getAttribute("data-slot"))??"":"",O=D.id?`#${D.id}`:"",M=typeof D.className=="string"&&D.className?"."+D.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";return W?`${W}|${U}${O}${M}{${F}}`:`${U}${O}${M}{${F}}`},E=(D,W={})=>{if(!cw())return;const U=e.getBoundingClientRect(),F=t.getBoundingClientRect(),O=window.visualViewport,{cellH:M,cellW:z}=i(),{paddingTop:L,paddingBottom:N}=s(),q=Math.max(0,e.clientHeight-L-N),Y=n.buffer.active,$=Y.baseY+Y.cursorY,P=dE({rows:n.rows,cellH:M,bufferLength:Y.length,cursorBufferRow:$,visibleContentHeight:q,paddingTop:L,paddingBottom:N,containerScrollTop:e.scrollTop,containerScrollHeight:e.scrollHeight,containerClientHeight:e.clientHeight,atBottomThreshold:r}),V=o(),G=V===null?null:$-V,B=W.cursorDeltaRows!==void 0?W.cursorDeltaRows:G,K=W.scrollDeltaToAnchor!==void 0?W.scrollDeltaToAnchor:e.scrollTop-P.bottomScrollTop,ee=Hs(t.style.top),te=M>0?f4({ydisp:Y.viewportY,rows:n.rows,cellH:M,visibleContentHeight:q}):0,J=Hs(t.style.height),me=e.scrollTop,Se=me+e.clientHeight,Re=ee+J,Ae=Math.max(0,Math.min(Se,Re)-Math.max(me,ee)),He=y();hle({t:performance.now(),event:D,scope:W.scope,action:W.action,reason:W.reason,scrollTop:e.scrollTop,scrollLeft:e.scrollLeft,scrollHeight:e.scrollHeight,scrollWidth:e.scrollWidth,clientHeight:e.clientHeight,clientWidth:e.clientWidth,innerHeight:window.innerHeight,visualViewportHeight:O==null?void 0:O.height,visualViewportOffsetTop:O==null?void 0:O.offsetTop,containerTop:U.top,containerBottom:U.bottom,hostRectTop:F.top,hostRectBottom:F.bottom,viewportY:Y.viewportY,bufferLength:Y.length,hostTop:t.style.top,cellH:M,cellW:z,cursorX:Y.cursorX,cursorY:Y.cursorY,cursorBufferRow:$,cursorDeltaRows:B,cursorInViewport:P.cursorInViewport,anchorBottomScrollTop:P.bottomScrollTop,scrollDeltaToAnchor:K,pendingProgrammaticScrollTop:l(),pendingFollowCursorScrollTop:u(),pendingFollowCursorScrollLeft:d(),pendingContainerSyncRetry:h(),horizontalIntent:p(),intentMode:He.mode,intentSource:He.source,intentTransition:He.lastTransitionId,prevCursorBufferRow:V,hostTopDrift:ee-te,viewportHostCoverage:e.clientHeight>0?Ae/e.clientHeight:0,focus:x(),atBottom:P.isAtBottom,touchActive:He.touchActive,userIntent:v(),...W})},k=D=>{if(!cw())return;const W=window.visualViewport;if(!W)return;const U=_===null?0:W.height-_,F=w===null?0:W.offsetTop-w;_=W.height,w=W.offsetTop,E(D,{vvHeightDelta:U,vvOffsetDelta:F})},R=()=>k("vv:resize"),A=()=>k("vv:scroll"),I=D=>{var z;if(!cw())return;const W=D.target,U=W===e||W instanceof Node&&e.contains(W),F=W&&typeof W.closest=="function"?((z=W.closest("[data-slot]"))==null?void 0:z.getAttribute("data-slot"))??"":"",O=(W==null?void 0:W.tagName)??"",M=W&&typeof W.className=="string"&&W.className?"."+W.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";E(`wheel:window deltaY=${Math.round(D.deltaY)} reachesContainer=${U?1:0} prevented=${D.defaultPrevented?1:0} target=${O}${M}{${F}}`)};return(T=window.visualViewport)==null||T.addEventListener("resize",R),(H=window.visualViewport)==null||H.addEventListener("scroll",A),window.addEventListener("wheel",I,{passive:!0,capture:!0}),{trace:E,dispose:()=>{var D,W;(D=window.visualViewport)==null||D.removeEventListener("resize",R),(W=window.visualViewport)==null||W.removeEventListener("scroll",A),window.removeEventListener("wheel",I,{capture:!0})}}}function p4(e){return{mode:e!=null&&e.initialIntent?"reviewing":"following",source:e!=null&&e.initialIntent?"initial":"none",touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1,lastScrollTop:(e==null?void 0:e.scrollTop)??0,lastTransitionId:e!=null&&e.initialIntent?"attach.reviewing":"attach.following"}}const Iw=e=>e.mode==="reviewing",wh=e=>e.mode==="following";function Spe(e,t){return e==="following"&&t==="reviewing"?"set":e==="reviewing"&&t==="following"?"clear":"keep"}function Gr(e,t,n,r=!1){const i=e.mode!==t.mode;return{state:t,changed:e!==t,outputPausedChanged:i,notifyTouchReviewStart:r,trace:{id:t.lastTransitionId,action:Spe(e.mode,t.mode),reason:n}}}function Sh(e,t,n,r){return{...e,mode:"reviewing",source:t,lastScrollTop:n,lastTransitionId:r}}function zw(e,t,n,r){return{...e,mode:"following",source:t,lastScrollTop:n,lastTransitionId:r}}function xpe(e){throw new Error(`Unhandled PTY vertical intent event: ${JSON.stringify(e)}`)}function Epe(e,t,n){const r=t.type==="touch-end"?"touch.end":"touch.cancel",i=e.touchStartScrollTop!==null&&t.scrollTop>e.touchStartScrollTop,s=e.touchStartScrollTop===null||t.scrollTop>=e.touchStartScrollTop-n,o={...e,touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1,lastScrollTop:t.scrollTop};return e.mode==="reviewing"&&t.atCursorAwareBottom&&(i||s||t.releaseOnSemanticBottom===!0)?Gr(e,{...o,mode:"following",source:"none",lastTransitionId:`${r}.bottom-down`},`scrollTop=${t.scrollTop} atBottom=true`):Gr(e,{...o,lastTransitionId:`${r}.not-bottom`},`scrollTop=${t.scrollTop} atBottom=${t.atCursorAwareBottom}`)}function Cpe(e,t,n={}){const r=n.atBottomThreshold??8;switch(t.type){case"attach":{const i=p4({initialIntent:t.initialIntent,scrollTop:t.scrollTop});return Gr(e,i,`initialIntent=${t.initialIntent}`)}case"scroll-to-bottom":return t.force?Gr(e,zw({...e,touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1},"programmatic-bottom",e.lastScrollTop,"bottom.force"),`reason=${t.reason} force=true`):Gr(e,{...e,lastTransitionId:`bottom.passive.${e.mode}`},`reason=${t.reason} force=false`);case"scroll-to-ratio":return Gr(e,Sh(e,"ratio-scroll",t.scrollTop,"ratio.reviewing"),`ratio=${t.ratio}`);case"wheel":return t.nextScrollTop===t.previousScrollTop?Gr(e,{...e,lastTransitionId:"wheel.clamped",lastScrollTop:t.nextScrollTop},`delta=${t.deltaY}`):t.deltaY<0?Gr(e,Sh(e,"wheel",t.nextScrollTop,"wheel.up"),`delta=${t.deltaY}`):t.deltaY>0&&t.reachedCursorAwareBottom?Gr(e,zw(e,"none",t.nextScrollTop,"wheel.down.bottom"),`delta=${t.deltaY}`):Gr(e,Sh(e,"wheel",t.nextScrollTop,"wheel.down.not-bottom"),`delta=${t.deltaY}`);case"container-scroll":return t.source!=="user"?Gr(e,{...e,lastScrollTop:t.scrollTop,lastTransitionId:`container.${t.source}`},`source=${t.source} scrollTop=${t.scrollTop}`):t.atCursorAwareBottom?t.verticalDelta>r&&e.mode==="reviewing"&&!e.touchActive?Gr(e,zw(e,"none",t.scrollTop,"container.user.bottom-down"),`delta=${t.verticalDelta} threshold=${r}`):Gr(e,{...e,lastScrollTop:t.scrollTop,lastTransitionId:"container.user.bottom-small-delta"},`delta=${t.verticalDelta} threshold=${r}`):Gr(e,Sh(e,"native-scroll",t.scrollTop,"container.user.away"),`scrollTop=${t.scrollTop} atBottom=false`);case"touch-start":return Gr(e,{...e,touchActive:!0,touchStartY:t.clientY,touchStartScrollTop:t.scrollTop,touchReviewNotified:!1,lastScrollTop:t.scrollTop,lastTransitionId:"touch.start"},`clientY=${t.clientY??"null"}`);case"touch-move":{const i=e.touchStartY===null||t.clientY===null?0:Math.abs(t.clientY-e.touchStartY);return i>=t.reviewThresholdPx&&!e.touchReviewNotified?Gr(e,{...Sh(e,"touch",e.lastScrollTop,"touch.move.review"),touchReviewNotified:!0},`movement=${i} threshold=${t.reviewThresholdPx}`,!0):i>=t.reviewThresholdPx?Gr(e,{...e,lastTransitionId:"touch.move.reviewing"},`movement=${i} threshold=${t.reviewThresholdPx}`):Gr(e,{...e,lastTransitionId:"touch.move.below-threshold"},`movement=${i} threshold=${t.reviewThresholdPx}`)}case"touch-end":case"touch-cancel":return Epe(e,t,r);default:return xpe(t)}}const hi={bottom:{defaultThresholdPx:8},horizontal:{nativeIntentThresholdPx:48},rawInput:{recentLayoutDriftMs:1e3},touch:{scrollJumpMinThresholdPx:512,hostTopJumpMinThresholdPx:64,gestureSlopPx:16,horizontalGestureSlopPx:6,horizontalLockRatio:1,verticalLockRatio:1.25,nativeScrollRecentMs:500}};function kpe({reviewing:e,cellH:t,rows:n,visibleContentHeight:r,cursorBufferRow:i,prevCursorBufferRow:s,cursorInViewport:o,targetScrollTop:l,currentScrollTop:u}){if(e)return{action:"skip",reason:"intent",nextPrevCursorBufferRow:null,cursorDeltaRows:null};if(t<=0)return{action:"skip",reason:"cellH=0",nextPrevCursorBufferRow:s,cursorDeltaRows:null};if(n*t<=r)return{action:"skip",reason:"shortHost",nextPrevCursorBufferRow:null,cursorDeltaRows:null};if(s===i&&o)return{action:"skip",reason:"same-row",nextPrevCursorBufferRow:s,cursorDeltaRows:0};const d=s===null?null:i-s;return o?{action:"skip",reason:"inViewport",nextPrevCursorBufferRow:i,cursorDeltaRows:d}:Math.abs(l-u)<=1?{action:"skip",reason:"aligned",nextPrevCursorBufferRow:i,cursorDeltaRows:d}:{action:"follow",reason:"cursor-outside",nextPrevCursorBufferRow:i,cursorDeltaRows:d,targetScrollTop:l}}function Tpe({startX:e,startY:t,currentX:n,currentY:r}){if(t===null||r===null)return null;const i=e!==null&&n!==null?n-e:0,s=r-t;return{dx:i,dy:s,absDx:Math.abs(i),absDy:Math.abs(s),distance:Math.hypot(i,s),startY:t}}function Rpe({touchActive:e,touchStartScrollTop:t,touchStartY:n,currentY:r,touchStartedAtCursorAwareBottom:i,bottomScrollTop:s,domMaxScrollTop:o}){if(!e||t===null||n===null||r===null)return!1;const l=Math.min(o,s),u=i?s:t,d=Math.max(0,Math.min(l,u+(n-r)));return{touchStartScrollTop:t,touchStartY:n,currentY:r,gestureBaseScrollTop:u,expectedScrollTop:d,cursorAwareMaxScrollTop:l,touchDeltaY:r-n}}function Ape({touchActive:e,touchStartClientX:t,touchStartScrollLeft:n,currentX:r,maxScrollLeft:i}){if(!e||t===null||n===null||r===null)return!1;const s=Math.max(0,Math.min(i,n+(t-r)));return{touchStartX:t,currentX:r,touchStartScrollLeft:n,expectedScrollLeft:s,maxScrollLeft:i,touchDeltaX:r-t}}function Npe({touchStartScrollTop:e,liveScrollTop:t,atBottomThreshold:n,touchStartedAtCursorAwareBottom:r,anchorIsAtBottom:i,reviewedDuringTouch:s}){const o=e===null||t>=e-n;return{atCursorAwareBottomForIntent:!s&&i||r&&!s&&o,releaseOnSemanticBottom:r&&i&&!s}}function Mpe(){const e=new WeakMap;return{set(t,n,r){let i=e.get(t);i||(i=new Map,e.set(t,i)),i.get(n)!==r&&(i.set(n,r),t.style[n]=r)}}}function Ope(){return{startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,lastGestureAt:null,lastHorizontalGestureAt:null,gestureMode:null}}function Dpe(e,t){return{...e,startedAtCursorAwareBottom:t.startedAtCursorAwareBottom,startClientX:t.startClientX,startScrollLeft:t.startScrollLeft,lastClientY:t.startClientY,lastGestureAt:t.now,gestureMode:t.startClientY===null?null:"pending"}}function Ppe(e,t){return{...e,lastGestureAt:t}}function j2(e,t){return{...e,lastHorizontalGestureAt:t}}function Lpe(e,t){return{...e,lastClientY:t.currentY,lastGestureAt:t.now}}function Ipe(e,t){return!t.touchActive||e.gestureMode!==null||t.currentY===null?e:{...e,gestureMode:"pending"}}function F2(e,t){return e.gestureMode===t?e:{...e,gestureMode:t}}function zpe(e){return{...e,startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,gestureMode:null}}function Bpe({container:e,atBottomThreshold:t,trace:n,getPageResumePending:r,getVerticalIntent:i,dispatchVerticalIntent:s,getCurrentAnchor:o,getLastSeenScrollTop:l,hasHorizontalOverflow:u,clearHorizontalIntentIfUnscrollable:d,markHorizontalUserInput:h,onTouchBoundaryPrevent:p,notifyAtBottom:y,flushPendingTouchScrollNotify:v}){let _=Ope();const w=D=>{const W=D??_.lastClientY,U=o(),F=Math.max(0,e.scrollHeight-e.clientHeight),O=i();return Rpe({touchActive:O.touchActive,touchStartScrollTop:O.touchStartScrollTop,touchStartY:O.touchStartY,currentY:W,touchStartedAtCursorAwareBottom:_.startedAtCursorAwareBottom,bottomScrollTop:U.bottomScrollTop,domMaxScrollTop:F})},x=(D,W)=>Tpe({startX:_.startClientX,startY:i().touchStartY,currentX:D,currentY:W}),E=D=>{const W=Math.max(0,e.scrollWidth-e.clientWidth);return Ape({touchActive:i().touchActive,touchStartClientX:_.startClientX,touchStartScrollLeft:_.startScrollLeft,currentX:D,maxScrollLeft:W})},k=(D,W,U,F,O)=>D?[`raw=${Math.round(W)}`,`effective=${Math.round(U)}`,`prev=${Math.round(F)}`,`delta=${Math.round(O)}`,`expected=${Math.round(D.expectedScrollTop)}`,`startScroll=${Math.round(D.touchStartScrollTop)}`,`base=${Math.round(D.gestureBaseScrollTop)}`,`startY=${Math.round(D.touchStartY)}`,`currentY=${Math.round(D.currentY)}`,`touchDeltaY=${Math.round(D.touchDeltaY)}`,`max=${Math.round(D.cursorAwareMaxScrollTop)}`].join(" "):null,R=D=>{var M;if(r()){n("touchstart:page-resume-pending");return}const W=((M=D.touches)==null?void 0:M[0])??null,U=(W==null?void 0:W.clientX)??null,F=(W==null?void 0:W.clientY)??null;d("touchstart");const O=o();_=Dpe(_,{startedAtCursorAwareBottom:O.isAtBottom,startClientX:U,startClientY:F,startScrollLeft:e.scrollLeft,now:performance.now()}),s({type:"touch-start",clientY:F,scrollTop:e.scrollTop}),n("touchstart",{details:[`startX=${U??"null"}`,`startY=${F??"null"}`,`startScroll=${Math.round(e.scrollTop)}`,`bottom=${Math.round(O.bottomScrollTop)}`,`atBottom=${O.isAtBottom?1:0}`].join(" ")})},A=D=>{var Y;if(r()){n("touchmove:page-resume-pending");return}const W=((Y=D.touches)==null?void 0:Y[0])??null,U=(W==null?void 0:W.clientX)??null,F=(W==null?void 0:W.clientY)??null,O=performance.now();_=Lpe(_,{currentY:F,now:O});const M=x(U,F);n("touchmove",{details:F===null?"currentY=null":k(w(F),e.scrollTop,e.scrollTop,l(),e.scrollTop-l())??[`mode=${_.gestureMode??"none"}`,`currentY=${Math.round(F)}`,M?`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`:null].filter(Boolean).join(" ")});const z=u();if(z||d("touchmove"),_=Ipe(_,{touchActive:i().touchActive,currentY:F}),_.gestureMode==="pending"&&M){const $=z&&M.absDx>=hi.touch.horizontalGestureSlopPx&&M.absDx>M.absDy*hi.touch.horizontalLockRatio,P=M.absDy>=hi.touch.gestureSlopPx&&(!z||M.absDy>M.absDx*hi.touch.verticalLockRatio);if($)_=F2(_,"horizontal"),_=j2(_,O),n("touchmove:horizontal-lock",{details:`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`});else if(P)_=F2(_,"vertical"),n("touchmove:vertical-lock",{details:`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)} threshold=${hi.touch.gestureSlopPx}`});else{n("touchmove:pending",{details:[`dx=${Math.round(M.dx)}`,`dy=${Math.round(M.dy)}`,`distance=${Math.round(M.distance)}`,`hThreshold=${hi.touch.horizontalGestureSlopPx}`,`vThreshold=${hi.touch.gestureSlopPx}`].join(" ")}),M.absDy<hi.touch.gestureSlopPx&&s({type:"touch-move",clientY:F,reviewThresholdPx:hi.touch.gestureSlopPx});return}}if(_.gestureMode==="horizontal"){const $=E(U);if(!z||!$){d("touchmove-horizontal"),n("touchmove:horizontal-native",{details:M?`blocked dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`:"blocked movement=null"});return}M&&(_=j2(_,O),h(`site=touchmove-horizontal dx=${Math.round(M.absDx)} dy=${Math.round(M.absDy)}`)),n("touchmove:horizontal-native",{details:[`scrollLeft=${Math.round(e.scrollLeft)}`,`expected=${Math.round($.expectedScrollLeft)}`,`startScrollLeft=${Math.round($.touchStartScrollLeft)}`,`startX=${Math.round($.touchStartX)}`,`currentX=${Math.round($.currentX)}`,`touchDeltaX=${Math.round($.touchDeltaX)}`,`max=${Math.round($.maxScrollLeft)}`].join(" ")});return}if(_.gestureMode!=="vertical")return;const L=w(F);if(L&&n("touchmove:vertical-native",{details:[`scrollTop=${Math.round(e.scrollTop)}`,`expected=${Math.round(L.expectedScrollTop)}`,`startScroll=${Math.round(L.touchStartScrollTop)}`,`base=${Math.round(L.gestureBaseScrollTop)}`,`startY=${Math.round(L.touchStartY)}`,`currentY=${Math.round(L.currentY)}`,`touchDeltaY=${Math.round(L.touchDeltaY)}`].join(" ")}),L&&_.startedAtCursorAwareBottom&&L.expectedScrollTop>=L.cursorAwareMaxScrollTop-t&&F!==null&&F<=L.touchStartY){n("touchmove:bottom-boundary-follow");return}s({type:"touch-move",clientY:F,reviewThresholdPx:hi.touch.gestureSlopPx}).notifyTouchReviewStart&&(p==null||p(),n("touchmove:review"))},I=D=>{const W=e.scrollTop,U=o(),F=Npe({touchStartScrollTop:i().touchStartScrollTop,liveScrollTop:W,atBottomThreshold:t,touchStartedAtCursorAwareBottom:_.startedAtCursorAwareBottom,anchorIsAtBottom:U.isAtBottom,reviewedDuringTouch:i().touchReviewNotified});_=zpe(_),s({type:D,scrollTop:W,atCursorAwareBottom:F.atCursorAwareBottomForIntent,releaseOnSemanticBottom:F.releaseOnSemanticBottom}),_=Ppe(_,performance.now()),v(),y()};return{onTouchStart:R,onTouchMove:A,onTouchEnd:()=>{if(r()){n("touchend:page-resume-pending");return}I("touch-end"),n("touchend")},onTouchCancel:()=>{if(r()){n("touchcancel:page-resume-pending");return}I("touch-cancel"),n("touchcancel")},isRecentNativeScroll:()=>i().touchActive||_.lastGestureAt!==null&&performance.now()-_.lastGestureAt<=hi.touch.nativeScrollRecentMs,isRecentHorizontalGesture:()=>_.lastHorizontalGestureAt!==null&&performance.now()-_.lastHorizontalGestureAt<=hi.touch.nativeScrollRecentMs,getScrollExpectation:w,describeScrollExpectation:k,getState:()=>_}}function hE(e,t){const n=e.querySelector(".xterm-screen");return!n||t.cols<=0||t.rows<=0?null:{cellW:n.clientWidth/t.cols,cellH:n.clientHeight/t.rows}}function jpe(e,t){for(let n=t-1;n>=0;n--){const r=e.viewportY+n;if(r<0||r>=e.length)continue;const i=e.getLine(r);if(i&&i.translateToString(!0).trimEnd().length>0)return n}return-1}function Fpe(e){const{container:t,spacer:n,host:r,term:i,hasNewFrame:s,consumeNewFrame:o,hasNewFramesWhileAway:l,setNewFramesWhileAway:u,onAtBottomChange:d,onScrollStateChange:h,initialUserHasVerticalScrollIntent:p=!1,onUserVerticalScrollIntentChange:y,onTouchReviewStart:v,onTouchBoundaryPrevent:_,onReviewSnapshotCapture:w,onReviewSnapshotClear:x,atBottomThreshold:E=hi.bottom.defaultThresholdPx}=e,k=()=>hE(r,i)??{cellH:0,cellW:0},R=()=>{const ne=getComputedStyle(t);return{paddingTop:Hs(ne.paddingTop),paddingBottom:Hs(ne.paddingBottom)}},A=Mpe(),I=(ne,ce,Ce)=>{A.set(ne,ce,Ce)},T={external:!1,internal:!1};let H=null,D="",W=p4({initialIntent:p,scrollTop:t.scrollTop}),U=null,F=null,O=!1,M=null,z=hpe(),L=0,N=!1,q=null,Y=null,$=null,P=null,V=p;const G=()=>Iw(W),B=wpe({container:t,host:r,term:i,atBottomThreshold:E,getDims:k,getVerticalInsets:R,getPrevCursorBufferRow:()=>q,getPendingProgrammaticScrollTop:()=>U,getPendingFollowCursorScrollTop:()=>M,getPendingFollowCursorScrollLeft:()=>z.pendingFollowLeft,getPendingContainerSyncRetry:()=>O,getHorizontalIntent:()=>z.intent,getVerticalIntent:()=>W,getUserHasVerticalScrollIntent:()=>G()}),K=B.trace,ee=ne=>{if(ne){if(ne.kind==="ignore"){K("horizontal-intent:ignore",{details:ne.details});return}K(`horizontal-intent:${ne.kind}`,{details:ne.details})}},te=()=>t.scrollWidth>t.clientWidth+E,J=ne=>{if(te())return!1;const ce=Ng(z,{details:`site=${ne} reason=not-scrollable scrollWidth=${t.scrollWidth} clientWidth=${t.clientWidth}`,scrollLeft:t.scrollLeft});return z=ce.state,ee(ce.trace),t.scrollLeft!==0&&(t.scrollLeft=0,z={...z,lastSeenLeft:0}),!0},me=ne=>{if(!te()){J("markHorizontalUserInput");return}const ce=ppe(z,{now:performance.now(),details:ne});z=ce.state,ee(ce.trace)},Se=()=>({scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,scrollHeight:t.scrollHeight,scrollWidth:t.scrollWidth,clientHeight:t.clientHeight,clientWidth:t.clientWidth,scrollable:t.scrollHeight>t.clientHeight+E,horizontalScrollable:te()}),Re=()=>{if(!h)return;const ne=Se(),ce=[ne.scrollTop,ne.scrollLeft,ne.scrollHeight,ne.scrollWidth,ne.clientHeight,ne.clientWidth,ne.scrollable,ne.horizontalScrollable].join(":");ce!==D&&(D=ce,h(ne))},Ae=()=>{const{cellH:ne}=k(),{paddingTop:ce,paddingBottom:Ce}=R(),re=i.buffer.active;return dE({rows:i.rows,cellH:ne,bufferLength:re.length,cursorBufferRow:re.baseY+re.cursorY,visibleContentHeight:Math.max(0,t.clientHeight-ce-Ce),paddingTop:ce,paddingBottom:Ce,containerScrollTop:t.scrollTop,containerScrollHeight:t.scrollHeight,containerClientHeight:t.clientHeight,atBottomThreshold:E})},He=()=>{const ne=Ae().isAtBottom;H!==ne&&(H=ne,d==null||d(ne))},qe=()=>{He(),Re()},pt=()=>W.touchActive,kt=()=>{$!==null&&(P==null||P($),$=null,P=null)},ve=()=>{if($!==null)return;const ne=()=>{$=null,P=null,qe()};if(typeof window.requestAnimationFrame=="function"){$=window.requestAnimationFrame(ne),P=typeof window.cancelAnimationFrame=="function"?ce=>window.cancelAnimationFrame(ce):null;return}$=window.setTimeout(ne,16),P=ce=>window.clearTimeout(ce)},Ke=()=>{$!==null&&(kt(),qe())},Tt=(ne="rawInput")=>{Y=performance.now(),K(`rawInputFollow:scheduled[${ne}]`)},_e=()=>{Y=performance.now(),K("rawInputFollow:fire")},Be=()=>{G()&&(V=(w==null?void 0:w())===!1)},Ve=ne=>{const ce=Iw(W),Ce=Cpe(W,ne,{atBottomThreshold:E});W=Ce.state,Ce.trace&&K(`intent:${Ce.trace.action}`,{details:`id=${Ce.trace.id} reason=${Ce.trace.reason}`});const re=Iw(W);return ce!==re&&(y==null||y(re),re?V=!0:(V=!1,x==null||x())),Ce.notifyTouchReviewStart&&(v==null||v()),Ce},be=(ne,ce,Ce)=>{if(ce<=0)return;const re=Ce??(()=>{const{paddingTop:ze,paddingBottom:Fe}=R();return Math.max(0,t.clientHeight-ze-Fe)})(),fe=f4({ydisp:ne,rows:i.rows,cellH:ce,visibleContentHeight:re}),ye=r.style.top,Te=`${fe}px`;I(r,"position","absolute"),I(r,"left","0px"),I(r,"top",Te),ye!==Te&&K("host-position",{ydisp:ne,details:`${ye||"0px"}->${Te}`})},Xe=(ne="internal",ce={})=>{const Ce=Math.max(0,i.buffer.active.length-i.rows),re=Ae(),fe=ype({force:ce.force??!1,reviewing:G(),viewportY:i.buffer.active.viewportY,expectedYdisp:Ce,scrollTop:t.scrollTop,bottomScrollTop:re.bottomScrollTop,atBottom:re.isAtBottom}).action;if(fe==="blocked-by-review")return;if(fe==="noop"){O=!1;return}K(`scroll-to-bottom:start[${ne}]`),Ve({type:"scroll-to-bottom",force:ce.force??!1,reason:ne});const ye=Math.max(0,i.buffer.active.length-i.rows);T.internal=!0;try{i.scrollToLine(ye)}finally{T.internal=!1}const{cellH:Te}=k();Te!==0&&be(ye,Te);const ze=Ae().bottomScrollTop;t.scrollTop=ze,U=ze,q=i.buffer.active.baseY+i.buffer.active.cursorY,qe(),O=!1,K("scroll-to-bottom:end",{ydisp:ye})},tt=()=>{N=!0,K("page-resume:prepare-follow"),G()&&Ve({type:"scroll-to-bottom",force:!0,reason:"pageResumePrepare"})},ut=()=>{tt(),Gt(),Xe("pageResume",{force:!0}),Je("pageResume"),N=!1},de=ne=>{K("scroll-to-ratio:start");const ce=Math.max(0,t.scrollHeight-t.clientHeight),Ce=Math.max(0,Math.min(1,ne)),re=ce*Ce;Ve({type:"scroll-to-ratio",ratio:Ce,scrollTop:re}),V=!0,t.scrollTop=re,Dn()},Me=ne=>{if(ne===0)return;K("wheel");const ce=Math.max(0,t.scrollHeight-t.clientHeight),Ce=Math.min(ce,Ae().bottomScrollTop);if(Ce<=0){K("wheel:max-zero");return}const re=t.scrollTop,fe=Math.max(0,Math.min(Ce,re+ne));if(fe===re){K("wheel:clamped"),qe();return}V=!0,t.scrollTop=fe,L=fe,Dn(),Ve({type:"wheel",deltaY:ne,previousScrollTop:re,nextScrollTop:fe,reachedCursorAwareBottom:fe>re&&fe>=Ce-E&&Ae().isAtBottom}),G()&&(V=!0)},nt=ne=>{if(!te()){J("scrollToXRatio"),qe();return}const ce=Math.max(0,t.scrollWidth-t.clientWidth),Ce=Math.max(0,Math.min(1,ne));t.scrollLeft=ce*Ce,me(`site=scrollToXRatio ratio=${Ce}`),z={...z,lastSeenLeft:t.scrollLeft},qe()},Je=(ne="external",ce={})=>{const Ce=t.scrollLeft,re=Ng(z,{details:`site=resetHorizontalScroll reason=${ne}`,scrollLeft:0});z=re.state,ee(re.trace),Ce!==0&&(t.scrollLeft=0),ce.holdUntilCursorVisible&&me(`site=resetHorizontalScroll-hold reason=${ne}`),K(`horizontal-scroll-reset[${ne}]`,{details:`scrollLeft=${Ce}->${t.scrollLeft}`}),qe()},lt=(ne="external")=>{me(`site=${ne}`)};let At=0,zt=null,Yt=-1;const hn=()=>{const ne=i.buffer.active,ce=`${At}:${ne.viewportY}:${ne.length}:${i.rows}`;return ce===zt||(Yt=jpe(ne,i.rows),zt=ce),Yt},Gt=()=>{const{cellH:ne,cellW:ce}=k();if(ne===0||ce===0)return;const{paddingTop:Ce,paddingBottom:re}=R(),fe=Math.max(0,t.clientHeight-Ce-re),ye=i.buffer.active,Te=hn(),ze=h4({bufferLength:ye.length,rows:i.rows,cols:i.cols,viewportY:ye.viewportY,cursorY:ye.cursorY,cellH:ne,cellW:ce,visibleContentHeight:fe},Te);ze&&(I(n,"overflow","hidden"),I(n,"height",`${ze.spacerHeight}px`),I(n,"width",`${ze.spacerWidth}px`),I(r,"width",`${ze.hostWidth}px`),I(r,"height",`${ze.hostHeight}px`),I(r,"paddingTop",`${ze.hostPaddingTop}px`),F=performance.now(),be(ye.viewportY,ne,fe))},qt=(ne,ce,Ce={})=>{if(ne===i.buffer.active.viewportY){Ce.deferHostUntilRender||be(ne,ce);return}T.internal=!0;try{if(Ce.deferHostUntilRender){i.scrollToLine(ne);return}be(ne,ce),i.scrollToLine(ne)}finally{T.internal=!1}},Xn=()=>s()?(o(),wh(W)?(Xe("pendingFrame"),"followed"):(l()||u(!0),"marked")):"none",Ut=(ne,ce)=>{const Ce=i.buffer.active;return B2(ne,{bufferLength:Ce.length,rows:i.rows,cols:i.cols,viewportY:Ce.viewportY,cellH:ce}).ydisp},Dn=(ne={})=>{kt(),K("container-sync:start");const{cellH:ce}=k();if(ce===0){O=!0;return}O=!1;const Ce=Ut(t.scrollTop,ce);qt(Ce,ce,{deferHostUntilRender:ne.deferHostUntilRender??pt()}),qe(),K("container-sync:end",{ydisp:Ce})},je=()=>W.touchActive||wt.isRecentNativeScroll(),Qe=ne=>{if(!je())return!1;const{cellH:ce}=k();if(ce===0)return!1;const Ce=Ut(ne,ce);return Ce!==i.buffer.active.viewportY?!1:(ve(),K("container-sync:skip[same-row-touch]",{ydisp:Ce,details:`scrollTop=${Math.round(ne)} viewportY=${i.buffer.active.viewportY}`}),!0)},St=ne=>{const ce=Math.max(0,t.scrollHeight-t.clientHeight),Ce=Ae(),re=bpe({rawScrollTop:ne,bottomScrollTop:Ce.bottomScrollTop,domMaxScrollTop:ce});return re.action==="keep"||(K("container-scroll:clamp-cursor-bottom",{details:`prev=${ne} next=${re.scrollTop} domMax=${ce}`}),t.scrollTop=re.scrollTop,U=null,M=null),re.scrollTop},wt=Bpe({container:t,atBottomThreshold:E,trace:K,getPageResumePending:()=>N,getVerticalIntent:()=>W,dispatchVerticalIntent:Ve,getCurrentAnchor:Ae,getLastSeenScrollTop:()=>L,hasHorizontalOverflow:te,clearHorizontalIntentIfUnscrollable:J,markHorizontalUserInput:me,onTouchBoundaryPrevent:_,notifyAtBottom:He,flushPendingTouchScrollNotify:Ke}),Q=()=>z.intent?wt.getState().gestureMode==="horizontal"||wt.isRecentHorizontalGesture():!1,we=ne=>{const ce=wt.getScrollExpectation();if(!ce)return!1;const{touchStartScrollTop:Ce,touchStartY:re,currentY:fe,gestureBaseScrollTop:ye,expectedScrollTop:Te}=ce,ze=Math.abs(fe-re)>.5,Fe=ne<=E&&ye>t.clientHeight,Rt=parseFloat(r.style.top||"0"),Ft=Ae(),Zt=wt.getState().startedAtCursorAwareBottom&&Number.isFinite(Rt)&&Math.abs(ne-Rt)<=E&&Math.abs(Ft.bottomScrollTop-Rt)<=t.clientHeight+E&&Math.abs(Te-ne)>hi.touch.hostTopJumpMinThresholdPx;if(!ze&&!Fe&&!Zt)return!1;const Tn=Math.max(hi.touch.scrollJumpMinThresholdPx,t.clientHeight*1.25);return!Zt&&Math.abs(ne-Te)<=Tn?!1:(K("container-scroll:restore-touch-impossible-jump",{details:[`scrollTop=${Math.round(ne)}`,`expected=${Math.round(Te)}`,`diff=${Math.round(ne-Te)}`,`threshold=${Math.round(Tn)}`,`touchStart=${Math.round(Ce)}`,Zt?"hostTop=1":null,`startY=${Math.round(re)}`,`currentY=${Math.round(fe)}`].filter(Boolean).join(" ")}),t.scrollTop=Te,L=Te,Dn({deferHostUntilRender:!0}),!0)},We=(ne,ce,Ce)=>{if(ce||W.touchActive||!wh(W)||!(Y!==null&&performance.now()-Y<=hi.rawInput.recentLayoutDriftMs))return!1;const fe=Ae();return K("container-scroll:restore-raw-input-layout-bottom",{details:`scrollTop=${ne} bottom=${fe.bottomScrollTop}`}),Ve({type:"container-scroll",source:"programmatic-bottom",scrollTop:ne,atCursorAwareBottom:ce,verticalDelta:Ce}),Xe("rawInputLayoutDrift"),!0},ct=()=>{K("container-scroll");const ne=gpe(z,{hasOverflow:te(),scrollLeft:t.scrollLeft,now:performance.now(),nativeIntentThresholdPx:hi.horizontal.nativeIntentThresholdPx});z=ne.state,ee(ne.trace),ne.resetScrollLeft&&(t.scrollLeft=0);const ce=t.scrollTop,Ce=L,re=ce-L,fe=St(ce);if(W.touchActive){const ze=wt.getScrollExpectation();K("container-scroll:touch-active",{details:wt.describeScrollExpectation(ze,ce,fe,Ce,re)??`raw=${Math.round(ce)} effective=${Math.round(fe)}`})}L=fe;const ye=vpe({syncingExternal:T.external,effectiveScrollTop:fe,pendingFollowTop:M,pendingProgrammaticTop:U,atBottom:Ae().isAtBottom,canPassiveFollow:wh(W)});if(M=ye.nextPendingFollowTop,U=ye.nextPendingProgrammaticTop,ye.action==="external-sync"){Ve({type:"container-scroll",source:"external-sync",scrollTop:fe,atCursorAwareBottom:Ae().isAtBottom,verticalDelta:re}),qe();return}if(ye.action==="programmatic-follow"){Ve({type:"container-scroll",source:"programmatic-follow",scrollTop:fe,atCursorAwareBottom:Ae().isAtBottom,verticalDelta:re}),qe();return}const Te=Ae().isAtBottom;if(ye.action==="programmatic-drift"){Ve({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Te,verticalDelta:re}),Xe("programmaticDrift");return}if(!we(fe)&&!We(fe,Te,re)){if(N){K("container-scroll:page-resume-pending",{details:`scrollTop=${fe} bottom=${Ae().bottomScrollTop}`}),Ve({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Te,verticalDelta:re}),Dn();return}Ve({type:"container-scroll",source:"user",scrollTop:fe,atCursorAwareBottom:Te,verticalDelta:re}),G()&&re!==0&&(V=!0),!Qe(fe)&&Dn()}},Pt=()=>{if(K("term-scroll"),!T.internal){T.external=!0;try{Gt();const ne=Xn();if(ne==="followed")return;if(ne==="none"&&wh(W)){Xe("termScroll");return}const{cellH:ce}=k();if(ce!==0){const Ce=i.buffer.active,{ydisp:re}=B2(t.scrollTop,{bufferLength:Ce.length,rows:i.rows,cols:i.cols,viewportY:Ce.viewportY,cellH:ce,cellW:1});qt(re,ce)}qe()}finally{T.external=!1}}},ie=()=>{Gt();const ne=Xn();if(ne==="followed")return;if(ne==="none"&&wh(W)){Xe("relayout");return}const{cellH:ce}=k();if(ce!==0)if(O)K("pending-sync-retry-fire"),Dn();else{const Ce=Ut(t.scrollTop,ce),re=dpe(i.buffer.active.viewportY,ce);Ce!==i.buffer.active.viewportY?t.scrollTop=re:Math.abs(t.scrollTop-re)>1&&K("relayout:preserve-host-offset",{details:`scrollTop=${Math.round(t.scrollTop)} viewportTop=${Math.round(re)} ydisp=${Ce}`}),be(i.buffer.active.viewportY,ce)}qe()},oe=()=>{const{cellH:ne}=k(),{paddingTop:ce,paddingBottom:Ce}=R(),re=Math.max(0,t.clientHeight-ce-Ce),fe=i.buffer.active,ye=fe.baseY+fe.cursorY,Te=q,ze=Ae(),Fe=kpe({reviewing:G(),cellH:ne,rows:i.rows,visibleContentHeight:re,cursorBufferRow:ye,prevCursorBufferRow:q,cursorInViewport:ze.cursorInViewport,targetScrollTop:ze.bottomScrollTop,currentScrollTop:t.scrollTop});if(Fe.reason==="intent"){q=Fe.nextPrevCursorBufferRow,K("followCursorY:skip",{details:Fe.reason});return}if(Fe.reason==="cellH=0"){K("followCursorY:skip",{details:Fe.reason});return}if(Fe.reason==="shortHost"){q=Fe.nextPrevCursorBufferRow,K("followCursorY:skip",{details:Fe.reason});return}if(Fe.reason==="same-row"){K("followCursorY:skip[same-row]",{cursorDeltaRows:Fe.cursorDeltaRows,details:`cursorRow=${ye} same-row`});return}if(q=Fe.nextPrevCursorBufferRow,Fe.reason==="inViewport"){K("followCursorY:skip",{cursorDeltaRows:Fe.cursorDeltaRows,details:`cursorRow=${Te??"null"}->${ye} inViewport`});return}if(Fe.reason==="aligned"){K("followCursorY:skip",{cursorDeltaRows:Fe.cursorDeltaRows,details:`cursorRow=${Te??"null"}->${ye} aligned`});return}if(Fe.action!=="follow")return;M=Fe.targetScrollTop;const Rt=t.scrollTop;t.scrollTop=Fe.targetScrollTop,K("followCursorY:hit",{cursorDeltaRows:Fe.cursorDeltaRows,scrollDeltaToAnchor:Rt-Fe.targetScrollTop,details:`cursorRow=${Te??"null"}->${ye} scrollTop=${Math.round(Rt)}->${Math.round(Fe.targetScrollTop)}`})},he=()=>{if(!te()){J("followCursorX");return}const{cellW:ne}=k();if(ne<=0)return;const ce=i.buffer.active.cursorX*ne,Ce=t.scrollLeft,re=Ce+t.clientWidth;if(ce>=Ce&&ce<=re){if(Q()){K("followCursorX:skip",{details:`horizontalTouchIntent cursorPx=${ce} viewport=${Ce}..${re}`});return}const Fe=Ng(z,{details:`site=followCursorX cursorPx=${ce} viewport=${Ce}..${re}`,scrollLeft:t.scrollLeft});z=Fe.state,ee(Fe.trace),K("followCursorX:skip",{details:"cursorInViewport"});return}if(z.intent){K("followCursorX:skip",{details:`horizontalIntent cursorPx=${ce} viewport=${Ce}..${re}`});return}const ye=Math.max(0,ce-t.clientWidth/2),Te=Math.max(0,t.scrollWidth-t.clientWidth),ze=Math.min(Te,ye);z=mpe(z,ze),t.scrollLeft=ze,K("followCursorX:hit",{details:`cursorPx=${ce} viewport=${Ce}..${re} target=${ze}`})},pe=()=>{K("render"),Gt(),O&&(K("pending-sync-retry-fire"),Dn()),Xn(),he(),oe(),V&&G()&&(V=(w==null?void 0:w())===!1),qe()};Gt(),G()?qe():Xe("init");const se=_pe({container:t,term:i,onWheel:ne=>{te()&&Math.abs(ne.deltaX)>0&&Math.abs(ne.deltaX)>=Math.abs(ne.deltaY)&&me(`site=wheel deltaX=${ne.deltaX}`),ne.deltaY!==0&&(K("wheel:enter"),ne.preventDefault(),ne.stopPropagation(),Me(ne.deltaY))},onTouchStart:wt.onTouchStart,onTouchMove:wt.onTouchMove,onTouchEnd:wt.onTouchEnd,onTouchCancel:wt.onTouchCancel,onContainerScroll:ct,onTermScroll:Pt,onRender:pe,onRelayout:ie,onWriteParsed:()=>{At+=1}});return{dispose:()=>{se.dispose(),B.dispose(),kt(),x==null||x()},relayout:ie,scrollToBottom:Xe,preparePageResumeRestore:tt,restorePageResume:ut,scrollToRatio:de,scrollToXRatio:nt,resetHorizontalScroll:Je,markHorizontalScrollIntent:lt,traceRawInputFollowScheduled:Tt,traceRawInputFollowFire:_e,refreshReviewSnapshot:Be,getDebugProbe:()=>{const{cellH:ne,cellW:ce}=k(),{paddingTop:Ce,paddingBottom:re}=R();return{cellH:ne,cellW:ce,paddingTop:Ce,paddingBottom:re,canvasLastY:ne>0&&ce>0?hn():-1,userHasVerticalScrollIntent:G(),verticalIntentMode:W.mode,verticalIntentSource:W.source,verticalIntentTransitionId:W.lastTransitionId,userHasHorizontalScrollIntent:z.intent,pendingProgrammaticScrollTop:U,pendingFollowCursorScrollTop:M,pendingFollowCursorScrollLeft:z.pendingFollowLeft,prevCursorBufferRow:q,lastSeenScrollTop:L,lastSeenScrollLeft:z.lastSeenLeft,touchScrollActive:W.touchActive,touchScrollGestureMode:wt.getState().gestureMode,syncingInternal:T.internal,syncingExternal:T.external,atBottomThreshold:E,lastSpacerUpdateAt:F,pendingContainerSyncRetry:O}}}}function $pe(e,t={}){const{onFramePending:n,onFrameWritten:r,schedule:i=v=>requestAnimationFrame(v),cancel:s=v=>cancelAnimationFrame(v)}=t;let o=null,l=!1,u=[],d=[];const h=()=>{u=[],d=[],o!==null&&(s(o),o=null)},p=()=>{if(o=null,l||u.length===0)return;const v=u,_=d;u=[],d=[];const w=v.reduce((k,R)=>k+R.byteLength,0),x=new Uint8Array(w);let E=0;for(const k of v)x.set(k,E),E+=k.byteLength;e.write(x,()=>{for(const k of _)k();r==null||r()})},y=()=>{l||o!==null||u.length===0||(o=i(p))};return{target:{reset:()=>{h(),e.reset()},resize:(v,_)=>e.resize(v,_),write:(v,_)=>{if(typeof v=="string"){e.write(v,_);return}const w=u.length===0;u.push(v),_&&d.push(_),w&&(n==null||n()),y()}},clear:h,dispose:()=>{l=!0,h()}}}const $2=5e3,Hpe=1e3;function Upe(e={}){let t=0;const n=e.requestIdFactory??(()=>`pty-snapshot-${++t}`);let r=null,i=!1,s=[];const o=new Map;let l=0,u=0;const d=h=>{let p=0,y=l+1;for(;o.has(y);){const v=o.get(y);o.delete(y),l=y,h.write(v),p+=1,y+=1}return p};return{startSnapshotRequest(){const h=n();return r=h,i=!1,s=[],o.clear(),u+=1,h},hasAppliedSnapshot(){return i},hasPendingGap(){return i&&o.size>0},handleBinaryFrame(h,p){if(!i)return s.push(h),s.length>$2&&s.splice(0,s.length-$2),{written:!1,hasGap:!1};if(h.outputSeq<=l)return{written:!1,hasGap:!1};if(o.set(h.outputSeq,h.data),o.size>Hpe){const v=o.keys().next().value;v!==void 0&&o.delete(v)}return{written:d(p)>0,hasGap:o.size>0}},applySnapshot(h,p){if(!r)return{applied:!1,reason:"no_active_request"};if(h.requestId!==r)return{applied:!1,reason:"stale_snapshot"};const y=s;s=[],o.clear(),r=null,i=!0,l=h.outputSeq,u+=1;const v=u,_=y.filter(w=>w.outputSeq>h.outputSeq).sort((w,x)=>w.outputSeq-x.outputSeq);return p.reset(),p.resize(h.cols,h.rows),p.write(h.data,()=>{if(v===u){for(const w of _)o.set(w.outputSeq,w.data);d(p)}}),{applied:!0,replayedFrames:_.length}}}}function Wpe(e){const{sessionId:t,ws:n,relay:r,target:i,retryDelayMs:s=3e4,slowNoticeDelayMs:o=1e4,gapRecoveryDelayMs:l=2e3,scheduleReady:u=$=>requestAnimationFrame($),scheduleFrameFlush:d,cancelFrameFlush:h,onFramePending:p,onFrameWritten:y,onReady:v,onSubscribeDelayed:_,onSubscribeStarted:w,onGapRecovery:x}=e,E=Upe(),R=$pe({reset:()=>i.reset(),resize:($,P)=>i.resize($,P),write:($,P)=>{i.write($,()=>{$ instanceof Uint8Array&&Coe(t,$.byteLength),P==null||P()})}},{onFramePending:p,onFrameWritten:y,schedule:d,cancel:h});let A=!1,I=null,T=null,H=null,D=!1;const W=()=>{I&&(clearTimeout(I),I=null)},U=()=>{T&&(clearTimeout(T),T=null)},F=()=>{H&&(clearTimeout(H),H=null)},O=()=>{H||(H=setTimeout(()=>{H=null,!(A||!E.hasPendingGap())&&(x==null||x(),N())},l))},M=()=>{const $=E.startSnapshotRequest();n.send(JSON.stringify({type:"session_subscribe",sessionId:t,requestId:$}))},z=()=>{I=setTimeout(()=>{I=null,!(A||E.hasAppliedSnapshot())&&(M(),z())},s)},L=()=>{T=setTimeout(()=>{T=null,!(A||E.hasAppliedSnapshot()||D)&&(D=!0,_==null||_())},o)},N=()=>{A||(W(),U(),F(),R.clear(),D=!1,w==null||w(),M(),z(),L())},q=n.subscribeBinary(t,($,P)=>{if(A)return;Eoe(t,$,P),E.handleBinaryFrame({data:$,outputSeq:P},R.target).hasGap?O():F()}),Y=r.onMessage($=>{if(A||$.sessionId!==t)return;if($.type==="terminal_resize"){R.target.resize($.cols,$.rows),N();return}$.type!=="session_snapshot"||!E.applySnapshot({requestId:$.requestId,cols:$.cols,rows:$.rows,data:$.data,outputSeq:$.outputSeq},R.target).applied||(W(),U(),u(()=>{A||v==null||v()}))});return N(),{dispose:()=>{A=!0,W(),U(),F(),R.dispose(),q(),Y()}}}function qpe(e){const{host:t,sessionId:n,ws:r,relay:i,createTerminal:s,attachRawInput:o,attachTransport:l=Wpe,scheduleAutoFocus:u=D=>requestAnimationFrame(D),onTerminalReady:d,onFramePending:h,onFrameWritten:p,onRawInput:y,isInputEnabled:v,canFocus:_=()=>!0,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E,onError:k}=e;let R=!1,A=null,I=null,T=null,H=null;return(async()=>{try{const D=await s(t);if(R){D.dispose();return}A=D.dispose,I=o(D.terminal,n,{onRawInput:y,...v?{isInputEnabled:v}:{}}).dispose;const W=()=>{_()&&D.terminal.focus()};t.addEventListener("pointerdown",W,{passive:!0}),H=()=>t.removeEventListener("pointerdown",W),d==null||d(D.terminal),u(()=>{R||W()}),T=l({sessionId:n,ws:r,relay:i,target:D.terminal,onFramePending:h,onFrameWritten:p,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E})}catch(D){console.error("[pty-terminal-controller] initialization failed",D),k==null||k(D)}})(),{dispose:()=>{R=!0,T==null||T.dispose(),H==null||H(),I==null||I(),A==null||A()}}}function fE(e){if(/^[a-z][a-z0-9+.-]*:\/\//i.test(e))return!1;const t=e.indexOf(":");if(t<=0)return!1;const n=e.slice(0,t),r=e.slice(t+1);return!r.includes("/")||!/^[A-Za-z0-9._~-]+(?:@[A-Za-z0-9.-]+)?$/.test(n)||!(n.includes("@")?n.slice(n.lastIndexOf("@")+1):n).includes(".")?!1:/^[A-Za-z0-9._~%+-]+(?:\/[A-Za-z0-9._~%+-]+)+$/.test(r)}const Vpe=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*?\\.(?:png|jpe?g|webp|gif)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","gi"),Ype=/\.(?:png|jpe?g|webp|gif)$/i;function m4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function Kpe(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(/\.(?:png|jpe?g|webp|gif)$/i,""),n=t.split("/").pop()??t;return n.length<2?!1:/[A-Za-z_-]/.test(n)}function pE(e){const t=m4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||fE(t)||!Ype.test(t)?!1:Kpe(t)}function Gpe(e){const t=new Set,n=[];for(const r of e.matchAll(Vpe)){const i=m4(r[0]??"");!pE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const ov=16,Xpe=8,Zpe=/(?:^|[\s([{@])@?(?:\/|\.\/|\.\.\/|~\/|\.dev-anywhere\/)[A-Za-z0-9_./~%+,:=#-]*$/,Qpe=/^[A-Za-z0-9_./~%+,:=#-]+$/;function g4(e,t,n){const r=[eme(e,t),...tme(e,t)].filter(s=>s!==null),i=new Set;return r.flatMap(s=>{const o=s.parts.map(l=>l.text).join("");return Jpe(o,n).map(l=>{const u=sme(s.parts,l.startIndex),d=ome(s.parts,l.endIndex);return!u||!d?null:{path:l.path,startLineNumber:u.lineNumber,startColumn:u.column,endLineNumber:d.lineNumber,endColumn:d.column,segments:ame(s.parts,l.startIndex,l.endIndex)}}).filter(l=>l!==null).filter(l=>t>=l.startLineNumber&&t<=l.endLineNumber).filter(l=>{const u=`${l.path}:${l.startLineNumber}:${l.startColumn}:${l.endLineNumber}:${l.endColumn}`;return i.has(u)?!1:(i.add(u),!0)})})}function v4(e){return e.segments.length>0?e.segments.map(t=>({start:{x:t.startColumn,y:t.lineNumber},end:{x:t.endColumn,y:t.lineNumber}})):[{start:{x:e.startColumn,y:e.startLineNumber},end:{x:e.endColumn,y:e.endLineNumber}}]}function Jpe(e,t){const n=t(e),r=[];let i=0;for(const s of n){const o=e.indexOf(s,i);if(o<0)continue;const l=o>0&&e[o-1]==="@"?o-1:o,u=o+s.length;r.push({path:s,startIndex:l,endIndex:u}),i=o+s.length}return r}function eme(e,t){const n=e.buffer.active;let r=t,i=t;for(let s=0;s<ov;s+=1){const o=n.getLine(r-1);if(!(o!=null&&o.isWrapped)||r<=1)break;r-=1}for(let s=0;s<ov;s+=1){const o=n.getLine(i);if(!(o!=null&&o.isWrapped))break;i+=1}return WS(e,r,i)}function WS(e,t,n){const r=e.buffer.active;let i=n??t;if(n===void 0)for(let o=0;o<ov;o+=1){const l=r.getLine(i);if(!(l!=null&&l.isWrapped))break;i+=1}const s=[];for(let o=t;o<=i;o+=1){const l=r.getLine(o-1);if(!l)return null;const u=l.translateToString(!0);s.push({lineNumber:o,sourceText:u,sourceStartIndex:0,text:u})}return{startLineNumber:t,endLineNumber:i,parts:s}}function tme(e,t){const n=e.buffer.active,r=[],i=Math.max(1,t-ov);for(let s=i;s<=t;s+=1){const o=n.getLine(s-1);if(!o||o.isWrapped)continue;const l=nme(e,s);l&&t>=l.startLineNumber&&t<=l.endLineNumber&&r.push(l)}return r}function nme(e,t){const n=WS(e,t);if(!n)return null;const r=n.parts.map(l=>l.text).join("");if(!Zpe.test(r))return null;const i=[...n.parts];let s=n.endLineNumber,o=!1;for(let l=0;l<Xpe;l+=1){const u=s+1,d=WS(e,u);if(!d)break;const h=d.parts[0];if(!h)break;const p=rme(h.sourceText),y=h.sourceText.slice(p);if(!ime(p,y))break;i.push({...h,sourceStartIndex:p,text:y}),i.push(...d.parts.slice(1)),o=!0,s=d.endLineNumber}return o?{startLineNumber:t,endLineNumber:s,parts:i}:null}function rme(e){var t;return((t=e.match(/^\s*/))==null?void 0:t[0].length)??0}function ime(e,t){return e<2||!t||t.startsWith("-")||t.startsWith("•")||t.startsWith("›")||t.includes("://")?!1:Qpe.test(t)}function sme(e,t){let n=t;for(let r=0;r<e.length;r+=1){const i=e[r];if(i){if(n<i.text.length)return{lineNumber:i.lineNumber,column:qS(i.sourceText,i.sourceStartIndex+n)};if(n===i.text.length&&r<e.length-1){const s=e[r+1];return s?{lineNumber:s.lineNumber,column:qS(s.sourceText,s.sourceStartIndex)}:null}n-=i.text.length}}return null}function ome(e,t){let n=t-1;for(const r of e){if(n<r.text.length)return{lineNumber:r.lineNumber,column:mE(r.sourceText.slice(0,r.sourceStartIndex+n+1))};n-=r.text.length}return null}function ame(e,t,n){const r=[];let i=0;for(const s of e){const o=i+s.text.length,l=Math.max(t,i),u=Math.min(n,o);if(l<u){const d=l-i,h=u-i;r.push({lineNumber:s.lineNumber,startColumn:qS(s.sourceText,s.sourceStartIndex+d),endColumn:mE(s.sourceText.slice(0,s.sourceStartIndex+h))})}i=o}return r}function qS(e,t){return mE(e.slice(0,t))+1}function mE(e){let t=0;for(const n of e)t+=lme(n.codePointAt(0)??0);return t}function lme(e){return e===0||e<32||e>=127&&e<160||cme(e)?0:ume(e)?2:1}function cme(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function ume(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}function y4(e,t){return g4(e,t,Gpe)}function dme(e){var n,r;if(e.metaKey||e.ctrlKey)return!0;const t="pointerType"in e?String(e.pointerType):"";return t==="touch"||t==="pen"?!0:((r=(n=window.matchMedia)==null?void 0:n.call(window,"(pointer: coarse), (hover: none)"))==null?void 0:r.matches)??!1}function hme(e,t){const n={provideLinks(i,s){const o=y4(e,i);if(o.length===0){s(void 0);return}const l=o.reduce((u,d)=>{for(const h of v4(d))h.start.y!==i||h.end.y!==i||u.push({text:d.path,range:h,decorations:{underline:!0,pointerCursor:!0},activate:p=>{dme(p)&&t(d.path)}});return u},[]);s(l.length>0?l:void 0)}},r=e.registerLinkProvider(n);return{dispose:()=>r.dispose(),provider:n}}const fme=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*\\.[A-Za-z0-9]{1,8}(?=[\\s`\"'<>),.;:!?,。;:!?、]|$)","gi"),pme=/\.(?:png|jpe?g|webp|gif)$/i,mme=/\.[A-Za-z0-9]{1,8}$/,gme=/^(?:com|net|org|io|dev|app|top|cn|ai|co|me|xyz|site|online|cloud|tools|tech|info|biz|us|uk|de|jp|fr|ru|nl|in)$/i,vme=new Set(["cargo.toml","composer.json","eslint.config.js","eslint.config.mjs","gemfile.lock","go.mod","go.sum","package-lock.json","package.json","pnpm-lock.yaml","prettier.config.js","pyproject.toml","readme.md","requirements.txt","tailwind.config.js","tailwind.config.ts","tsconfig.json","vite.config.ts","vitest.config.ts","yarn.lock"]);function b4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function yme(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(/\.[A-Za-z0-9]{1,8}$/,""),n=t.split("/").pop()??t;return n.length<2?!1:/[A-Za-z_-]/.test(n)}function bme(e){if(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 gme.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function _me(e){return e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/")||e.includes("/")}function wme(e){return _me(e)?!0:vme.has(e.toLowerCase())}function gE(e){const t=b4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||fE(t)||bme(t)||pme.test(t)||!mme.test(t)||!wme(t)||t.split("/").includes("...")?!1:yme(t)}function Sme(e){const t=new Set,n=[];for(const r of e.matchAll(fme)){const i=b4(r[0]??"");!gE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const xme=750;function _4(e,t){return g4(e,t,Sme)}function Eme(e){return e.metaKey||e.ctrlKey}function Cme(e,t){let n=null;const r=(o,l)=>{if(!Eme(l))return;const u=performance.now();(n==null?void 0:n.path)===o&&u-n.at<xme||(n={path:o,at:u},t(o))},i={provideLinks(o,l){const u=_4(e,o);if(u.length===0){l(void 0);return}const d=u.reduce((h,p)=>{for(const y of v4(p))y.start.y!==o||y.end.y!==o||h.push({text:p.path,range:y,decorations:{underline:!1,pointerCursor:!0},hover:()=>{kme(e,p)},leave:()=>{Mg(e)},dispose:()=>{Mg(e)},activate:v=>{r(p.path,v)}});return h},[]);l(d.length>0?d:void 0)}},s=e.registerLinkProvider(i);return{dispose:()=>{Mg(e),s.dispose()},provider:i}}function kme(e,t){const n=e.element;if(!n)return;const r=n.querySelector(".xterm-screen");if(!r||e.cols<=0||e.rows<=0)return;const i=n.getBoundingClientRect(),s=r.getBoundingClientRect(),o=(r.clientWidth||s.width)/e.cols,l=(r.clientHeight||s.height)/e.rows;if(!Number.isFinite(o)||!Number.isFinite(l)||o<=0||l<=0)return;Mg(e),Tme(n);const u=document.createElement("div");u.dataset.slot="pty-file-link-hover-overlay",u.style.position="absolute",u.style.inset="0",u.style.pointerEvents="none",u.style.zIndex="4",n.append(u);const d=s.left-i.left,h=s.top-i.top,p=e.buffer.active.viewportY;for(const y of t.segments){const v=y.lineNumber-p;if(v<1||v>e.rows)continue;const _=document.createElement("div");_.dataset.slot="pty-file-link-hover-segment",_.dataset.range=`${y.lineNumber}:${y.startColumn}-${y.endColumn}`,_.style.position="absolute",_.style.left=`${d+(y.startColumn-1)*o}px`,_.style.top=`${h+(v-1)*l+l-2}px`,_.style.width=`${Math.max(1,y.endColumn-y.startColumn+1)*o}px`,_.style.height="2px",_.style.background="currentColor",_.style.opacity="0.8",u.append(_)}}function Mg(e){var t;(t=e.element)==null||t.querySelectorAll('[data-slot="pty-file-link-hover-overlay"]').forEach(n=>n.remove())}function Tme(e){window.getComputedStyle(e).position==="static"&&(e.style.position="relative")}function Wa(e,t={}){const n=window.__ccTestPtyTouchLinkActivations;n&&(n.push({event:e,t:performance.now(),...t}),n.length>200&&n.splice(0,n.length-200))}function Rme(e,t,n){const r=e.range.start.y*n+e.range.start.x,i=e.range.end.y*n+e.range.end.x,s=t.y*n+t.x;return r<=s&&s<=i}function Ame(e){const t=new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,clientX:e.clientX,clientY:e.clientY});return Object.defineProperty(t,"pointerType",{configurable:!0,value:"touch"}),t}function w4(e,t,n){if(t.length===0)return Wa("skip",{reason:"no-providers",point:n}),null;const r=e.element,i=r==null?void 0:r.querySelector(".xterm-screen"),s=(r==null?void 0:r.parentElement)??r;if(!i||!s)return Wa("skip",{reason:"missing-elements",hasScreen:!!i,hasMetricHost:!!s,point:n}),null;const o=hE(s,e);if(!o||o.cellW<=0||o.cellH<=0)return Wa("skip",{reason:"missing-metrics",metrics:o,point:n}),null;const l=i.getBoundingClientRect(),u=Math.floor((n.clientX-l.left)/o.cellW)+1,d=Math.floor((n.clientY-l.top)/o.cellH)+1;if(u<1||u>e.cols||d<1||d>e.rows)return Wa("skip",{reason:"point-out-of-range",point:n,viewportX:u,viewportY:d,cols:e.cols,rows:e.rows,rect:{left:l.left,top:l.top,width:l.width,height:l.height},metrics:o}),null;const h=e.buffer.active.viewportY+d,p={x:u,y:h};Wa("probe",{point:n,viewportX:u,viewportY:d,bufferLineNumber:h,providers:t.length,metrics:o});for(const y of t){let v=null;if(y.provideLinks(h,_=>{Wa("links",{bufferLineNumber:h,position:p,count:(_==null?void 0:_.length)??0,links:_==null?void 0:_.map(x=>({text:x.text,range:x.range}))});const w=_==null?void 0:_.find(x=>Rme(x,p,e.cols));w&&(v=w)}),v)return v}return Wa("miss",{position:p,point:n,bufferLineNumber:h}),null}function Nme(e,t,n){return w4(e,t,n)!==null}function Mme(e,t,n){const r=w4(e,t,n);return r?(r.activate(Ame(n),r.text),Wa("activate",{text:r.text,range:r.range,point:n}),!0):!1}const Ome=2*1024*1024,Dme=2560,H2=.82,Pme=.9,Lme=new Set(["image/jpeg","image/png","image/webp"]),S4=new Map([["image/jpeg","jpg"],["image/png","png"],["image/webp","webp"]]);function x4(e){return e.size>Ome&&Lme.has(e.type)}function Ime(e,t,n=Dme){const r=Math.max(e,t);if(!Number.isFinite(r)||r<=0)throw new Error("图片尺寸无效");const i=Math.min(1,n/r);return{width:Math.max(1,Math.round(e*i)),height:Math.max(1,Math.round(t*i))}}function zme(e,t){const n=S4.get(t);return n?`${e.replace(/\.(?:jpe?g|png|webp)$/iu,"")||"image"}.${n}`:e}function Bme(){return typeof createImageBitmap!="function"||typeof document>"u"?null:{async decode(e){const t=await createImageBitmap(e,{imageOrientation:"from-image"});return{source:t,width:t.width,height:t.height,close:()=>t.close()}},async encode(e,t,n,r,i){const s=document.createElement("canvas");s.width=t,s.height=n;const o=s.getContext("2d");if(!o)throw new Error("浏览器无法创建图片压缩画布");return o.imageSmoothingEnabled=!0,o.imageSmoothingQuality="high",o.drawImage(e.source,0,0,t,n),new Promise(l=>s.toBlob(l,r,i))}}}async function E4(e,t=Bme()){var r;if(!x4(e)||!t)return e;let n=null;try{n=await t.decode(e);const i=Ime(n.width,n.height);let s=await t.encode(n,i.width,i.height,"image/webp",H2);return(s==null?void 0:s.type)!=="image/webp"&&e.type==="image/jpeg"&&(s=await t.encode(n,i.width,i.height,"image/jpeg",H2)),!s||!S4.has(s.type)||s.size>=e.size*Pme?e:new File([s],zme(e.name,s.type),{type:s.type,lastModified:e.lastModified})}catch{return e}finally{(r=n==null?void 0:n.close)==null||r.call(n)}}async function Cf(e){const t=x4(e.file),n=et.loading(t?`正在压缩并上传 ${e.file.name} ...`:`上传 ${e.file.name} ...`);try{const r=await E4(e.file),i=await e.relay.uploadFile(e.sessionId,r);return!i.success||!i.path?(et.error(i.error??"上传失败",{id:n}),null):(e.successLabel===null?et.dismiss(n):et.success(e.successLabel??`已上传 ${i.path}`,{id:n}),i.path)}catch(r){return et.error(r instanceof Error?r.message:String(r),{id:n}),null}}function U2(e){let t=null,n=!1;const r=()=>{t=null,n||e()};return{schedule:()=>{n||t!==null||(t=requestAnimationFrame(r))},dispose:()=>{n=!0,t!==null&&(cancelAnimationFrame(t),t=null)}}}const W2="--dev-visual-viewport-height",jme=.3;function C4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i=!0,subtractVisualViewportOffsetTop:s=!0}){const o=s?n:0,l=e-t-o,u=r-t-o,d=q2(l,e),h=i?q2(u,r):0;return Math.max(d,h)}function Fme({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r=e,allowBaselineFallback:i=!1,softKeyboardOpen:s=!1}){return s?Math.max(e-t-n,0):C4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i})}function q2(e,t){const n=Math.max(e,0);return n<=0?0:n/Math.max(t,1)>=jme?n:0}function $me(){b.useEffect(()=>{const e=window.visualViewport;let t=0;const n=()=>{cancelAnimationFrame(t),t=requestAnimationFrame(()=>{const r=(e==null?void 0:e.height)??window.innerHeight;document.documentElement.style.setProperty(W2,`${r}px`)})};return n(),window.addEventListener("resize",n),e==null||e.addEventListener("resize",n),e==null||e.addEventListener("scroll",n),()=>{cancelAnimationFrame(t),window.removeEventListener("resize",n),e==null||e.removeEventListener("resize",n),e==null||e.removeEventListener("scroll",n),document.documentElement.style.removeProperty(W2)}},[])}function V2(){const e=document.documentElement,t=document.body;return window.scrollX!==0||window.scrollY!==0||e.scrollLeft!==0||e.scrollTop!==0||t.scrollLeft!==0||t.scrollTop!==0?(window.scrollTo(0,0),e.scrollLeft=0,e.scrollTop=0,t.scrollLeft=0,t.scrollTop=0,!0):!1}function Hme(){b.useEffect(()=>{const e=window.visualViewport;let t=0;const n=()=>{V2(),cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,V2()})};return n(),window.addEventListener("scroll",n,{passive:!0}),window.addEventListener("resize",n),e==null||e.addEventListener("scroll",n,{passive:!0}),e==null||e.addEventListener("resize",n),()=>{cancelAnimationFrame(t),window.removeEventListener("scroll",n),window.removeEventListener("resize",n),e==null||e.removeEventListener("scroll",n),e==null||e.removeEventListener("resize",n)}},[])}function Ume(){return vE().bottomOffset}function vE(){const[e,t]=b.useState({bottomOffset:0,layoutBottomInset:0}),n=b.useRef(0),r=b.useRef(0);return b.useEffect(()=>{const i=window.visualViewport;if(!i)return;const s=Wme();let o=0;const l=()=>{const h=i.height,p=i.offsetTop,y=i.width,v=Math.max(window.innerHeight,h+p);!n.current||Math.abs(y-r.current)>1?(n.current=v,r.current=y):n.current=Math.max(n.current,v);const _=window.innerHeight,w=qme(),x=!s||w,E=s&&w,k=C4({layoutViewportHeight:_,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:x,subtractVisualViewportOffsetTop:s}),R={bottomOffset:k,layoutBottomInset:Fme({layoutViewportHeight:_,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:E,softKeyboardOpen:k>0})};t(A=>A.bottomOffset===R.bottomOffset&&A.layoutBottomInset===R.layoutBottomInset?A:R)},u=()=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=0,l()})};u(),window.addEventListener("resize",u),i.addEventListener("resize",u),i.addEventListener("scroll",u);const d=()=>{setTimeout(u,300)};return window.addEventListener("focusout",d),()=>{cancelAnimationFrame(o),window.removeEventListener("resize",u),i.removeEventListener("resize",u),i.removeEventListener("scroll",u),window.removeEventListener("focusout",d)}},[]),e}function Wme(){if(typeof navigator>"u")return!1;const e=navigator.userAgent??"",t=navigator.platform??"",n=navigator.maxTouchPoints??0;return/iPad|iPhone|iPod/.test(e)||t==="MacIntel"&&n>1&&(e.includes("Mac OS X")||e.includes("Macintosh"))}function qme(){const e=document.activeElement;return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Vme(e){window.__devAnywherePtyTerminal=e}function Yme(){window.__devAnywherePtyTerminal&&delete window.__devAnywherePtyTerminal}function Kme(e){window.__devAnywherePtyDebug=e}function Gme(){window.__devAnywherePtyDebug&&delete window.__devAnywherePtyDebug}function Xme(e,t){const n=e(),{container:r,spacer:i,host:s,term:o}=t,{cellH:l,cellW:u,paddingTop:d,paddingBottom:h,canvasLastY:p}=n,y=Math.max(0,r.clientHeight-d-h),v=o.buffer.active;let _=0;if(l>0&&u>0){const z=h4({bufferLength:v.length,rows:o.rows,cols:o.cols,viewportY:v.viewportY,cursorY:v.cursorY,cellH:l,cellW:u,visibleContentHeight:y},p);_=(z==null?void 0:z.spacerHeight)??0}const w=Hs(i.style.height),x=Hs(s.style.top),E=Hs(s.style.height),k=Hs(s.style.width),R=Hs(s.style.paddingTop),A=Hs(i.style.width);let I=0;if(l>0){const z=o.rows*l,L=z>0&&z<y?y-z:0;I=Math.max(0,v.viewportY*l+L)}const T=x-I,H=r.scrollTop,D=H+r.clientHeight,W=x+E,U=Math.max(0,Math.min(D,W)-Math.max(H,x)),F=r.clientHeight>0?U/r.clientHeight:0,O=v.baseY+v.cursorY,M=dE({rows:o.rows,cellH:l,bufferLength:v.length,cursorBufferRow:O,visibleContentHeight:y,paddingTop:d,paddingBottom:h,containerScrollTop:r.scrollTop,containerScrollHeight:r.scrollHeight,containerClientHeight:r.clientHeight,atBottomThreshold:n.atBottomThreshold});return{ts:performance.now(),container:{scrollTop:r.scrollTop,scrollLeft:r.scrollLeft,scrollHeight:r.scrollHeight,scrollWidth:r.scrollWidth,clientHeight:r.clientHeight,clientWidth:r.clientWidth,paddingTop:d,paddingBottom:h},spacer:{height:w,width:A},host:{top:x,height:E,width:k,paddingTop:R,expectedTop:I,topDrift:T},term:{rows:o.rows,cols:o.cols,bufferLength:v.length,viewportY:v.viewportY,baseY:v.baseY,cursorX:v.cursorX,cursorY:v.cursorY},cell:{h:l,w:u},visibleContentHeight:y,anchor:{atBottom:M.isAtBottom,cursorInViewport:M.cursorInViewport,cursorBufferRow:O,bottomScrollTop:M.bottomScrollTop,scrollTopDeltaToBottom:r.scrollTop-M.bottomScrollTop},intent:{vertical:n.userHasVerticalScrollIntent,horizontal:n.userHasHorizontalScrollIntent},verticalIntent:{mode:n.verticalIntentMode,source:n.verticalIntentSource,transitionId:n.verticalIntentTransitionId},pinned:!n.userHasVerticalScrollIntent,pendingProgrammaticScrollTop:n.pendingProgrammaticScrollTop,pendingFollowCursorScrollTop:n.pendingFollowCursorScrollTop,pendingFollowCursorScrollLeft:n.pendingFollowCursorScrollLeft,prevCursorBufferRow:n.prevCursorBufferRow,lastSeenScrollTop:n.lastSeenScrollTop,lastSeenScrollLeft:n.lastSeenScrollLeft,touchScrollActive:n.touchScrollActive,touchScrollGestureMode:n.touchScrollGestureMode,syncing:{internal:n.syncingInternal,external:n.syncingExternal},pending:{programmaticScrollTop:n.pendingProgrammaticScrollTop,followCursorScrollTop:n.pendingFollowCursorScrollTop,followCursorScrollLeft:n.pendingFollowCursorScrollLeft,containerSyncRetry:n.pendingContainerSyncRetry},expectedSpacerHeight:_,spacerDrift:w-_,lastSpacerUpdateAt:n.lastSpacerUpdateAt,viewportHostCoverage:F,pendingContainerSyncRetry:n.pendingContainerSyncRetry}}const sy={enabled:!1,phase:"idle",error:null,lastSpokenText:"",approvalRequestId:null,activityLevel:0,waveform:[],resumeRequestSeq:0};function Zme(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function Bs(e,t,n){const r=e.bySessionId[t]??sy;return{bySessionId:{...e.bySessionId,[t]:n(r)}}}const sn=ed()(td(e=>({bySessionId:{},enable:t=>e(n=>Bs(n,t,r=>({...r,enabled:!0,phase:"starting",error:null,waveform:[]}))),disable:t=>e(n=>Bs(n,t,r=>({...r,enabled:!1,phase:"idle",error:null,approvalRequestId:null,activityLevel:0,waveform:[]}))),requestResume:t=>e(n=>Bs(n,t,r=>({...r,resumeRequestSeq:r.resumeRequestSeq+1}))),setPhase:(t,n)=>e(r=>Bs(r,t,i=>({...i,phase:n,error:n==="error"?i.error:null}))),setError:(t,n)=>e(r=>Bs(r,t,i=>({...i,phase:"error",error:n,activityLevel:0,waveform:[]}))),clearError:t=>e(n=>Bs(n,t,r=>({...r,error:null,phase:r.enabled&&r.phase==="error"?"starting":r.phase}))),setLastSpokenText:(t,n)=>e(r=>Bs(r,t,i=>({...i,lastSpokenText:n}))),setApproval:(t,n)=>e(r=>Bs(r,t,i=>({...i,approvalRequestId:n}))),setActivityLevel:(t,n)=>e(r=>Bs(r,t,i=>({...i,activityLevel:Zme(n)}))),appendWaveform:(t,n)=>{n.length!==0&&e(r=>Bs(r,t,i=>({...i,waveform:[...i.waveform,...n].slice(-U0)})))},clearWaveform:t=>e(n=>Bs(n,t,r=>({...r,waveform:[]}))),resetAll:()=>e({bySessionId:{}})}),{name:"voice-pilot-store"}));function Qme(){const[e,t]=b.useState(!1),[n,r]=b.useState(!1),[i,s]=b.useState(!1);b.useEffect(()=>{if(e){r(!1);return}const p=setTimeout(()=>r(!0),300);return()=>clearTimeout(p)},[e]);const o=b.useCallback(()=>{t(!0),s(!1)},[]),l=b.useCallback(()=>{t(!1),s(!1)},[]),u=b.useCallback(()=>{s(!0)},[]),d=b.useMemo(()=>({connecting:n,subscribeDelayed:i}),[n,i]),h=b.useMemo(()=>({onReady:o,onSubscribeStarted:l,onSubscribeDelayed:u}),[o,u,l]);return{ready:e,overlay:d,transport:h}}const Jme=900;function ege(){var t;const e=navigator.virtualKeyboard;(t=e==null?void 0:e.show)==null||t.call(e)}function tge(e){const{containerEl:t,xtermHostRef:n,terminalRef:r}=e,[i,s]=b.useState(!1),o=b.useRef(0),l=b.useCallback(()=>{const v=document.activeElement;!t||!(v instanceof HTMLElement)||!t.contains(v)||v.blur()},[t]),u=b.useCallback(()=>{const v=n.current,_=document.activeElement,w=!!(v&&_ instanceof HTMLElement&&v.contains(_));s(w),w&&ege()},[n]),d=b.useCallback((v={})=>{o.current=performance.now()+Jme,(v.blur??!0)&&(l(),s(!1))},[l]),h=b.useCallback(v=>{if(performance.now()<=o.current){v.target instanceof HTMLElement&&v.target.blur(),window.setTimeout(u,0);return}u()},[u]),p=b.useCallback(()=>{window.setTimeout(u,0)},[u]),y=b.useCallback(()=>{var v;o.current=0,(v=r.current)==null||v.focus(),window.setTimeout(u,0)},[u,r]);return{ptyInputFocused:i,suppressPtyFocus:d,focusPtyInput:y,handleFocusCapture:h,handleBlurCapture:p}}function nge(){const[e,t]=b.useState(!0),[n,r]=b.useState(!1),i=b.useRef(n);b.useEffect(()=>{i.current=n},[n]);const s=b.useCallback(l=>{t(l),l&&r(!1)},[]),o=b.useCallback(()=>{r(!1)},[]);return{isAtBottom:e,hasNewFramesWhileAway:n,hasNewFramesWhileAwayRef:i,setHasNewFramesWhileAway:r,handleAtBottomChange:s,clearNewFramesWhileAway:o}}async function k4(e,{allowLegacyFallback:t=!1}={}){var r,i;const n=(i=(r=navigator.clipboard)==null?void 0:r.writeText)==null?void 0:i.bind(navigator.clipboard);if(n&&window.isSecureContext!==!1)try{return await n(e),"clipboard"}catch{}return t&&rge(e)?"legacy":"failed"}function rge(e){if(!document.body||typeof document.execCommand!="function")return!1;const t=document.createElement("textarea");t.value=e,t.readOnly=!0,t.setAttribute("aria-hidden","true"),t.style.position="fixed",t.style.left="-9999px",t.style.top="0",t.style.opacity="0",t.style.fontSize="16px",document.body.appendChild(t);try{return t.select(),t.setSelectionRange(0,e.length),document.execCommand("copy")}catch{return!1}finally{t.remove()}}const ige=new Intl.Segmenter("zh-CN",{granularity:"word"}),sge=/^[./:@_+~=-]+$/u,oge=/[a-z0-9]/iu;function T4({terminal:e,host:t,cellWidth:n,cellHeight:r}){return n&&r?{cellW:n,cellH:r}:hE(t,e)}function age(e,t){const n=Math.min(e.length,t),r=[];let i="";for(let s=0;s<n;s+=1){const o=e.getCell(s),l=(o==null?void 0:o.getWidth())??1;if(l===0)continue;const u=(o==null?void 0:o.getChars())||" ",d=i.length;i+=u,r.push({textStart:d,textEnd:i.length,cellStart:s,cellEnd:Math.min(n-1,s+Math.max(1,l)-1)})}return{text:i.trimEnd(),spans:r}}function Y2(e){return sge.test(e.segment)}function VS(e){return e.isWordLike===!0&&oge.test(e.segment)}function lge(e,t){let n=t,r=t;for(;n>0;){let o=n-1;for(;o>=0&&Y2(e[o]);)o-=1;if(o===n-1)break;if(o>=0&&VS(e[o])){n=o;continue}n=o+1;break}for(;r+1<e.length;){let o=r+1;for(;o<e.length&&Y2(e[o]);)o+=1;if(o===r+1||o>=e.length||!VS(e[o]))break;r=o}const i=e[n].index,s=e[r];return{start:i,end:s.index+s.segment.length}}function cge(e){const t=Array.from(ige.segment(e)),n=[],r=new Set,i=s=>{const o=`${s.start}:${s.end}`;r.has(o)||(r.add(o),n.push(s))};for(let s=0;s<t.length;s+=1){const o=t[s];o.isWordLike&&i(VS(o)?lge(t,s):{start:o.index,end:o.index+o.segment.length})}for(const s of t){if(s.isWordLike||!s.segment.trim())continue;const o={start:s.index,end:s.index+s.segment.length};n.some(l=>l.start<=o.start&&l.end>=o.end)||i(o)}return n.sort((s,o)=>s.start-o.start||s.end-o.end)}function uge(e,t){const{text:n,spans:r}=age(e,t);return cge(n).flatMap(i=>{const s=r.filter(u=>u.textStart<i.end&&u.textEnd>i.start),o=s[0],l=s.at(-1);return o&&l?[{start:o.cellStart,end:l.cellEnd}]:[]})}function dge(e,t){if(e.length===0)return null;let n=0,r=Number.POSITIVE_INFINITY;for(let i=0;i<e.length;i+=1){const s=e[i],o=t<s.start?s.start-t:t>s.end?t-s.end:0;o<r&&(r=o,n=i)}return n}function hge(e,t){return e.row<t.row||e.row===t.row&&e.column<=t.column?{start:e,end:t}:{start:t,end:e}}function fge(e,t,n){const r=[];for(let i=t.row;i<=n.row;i+=1){const s=e.buffer.active.getLine(i);if(!s){r.push("");continue}const o=i===t.row?t.column:0,l=i===n.row?n.column+1:e.cols;r.push(s.translateToString(!0,o,l))}return r.join(`
643
643
  `).replace(/\s+$/,"")}function Vh({terminal:e,host:t,clientX:n,clientY:r,cellWidth:i,cellHeight:s}){const o=t.querySelector(".xterm-screen");if(!o)return null;const l=T4({terminal:e,host:t,cellWidth:i,cellHeight:s});if(!(l!=null&&l.cellW)||!l.cellH)return null;const u=o.getBoundingClientRect(),d=Math.floor((r-u.top)/l.cellH),h=Math.floor((n-u.left)/l.cellW);return d<0||d>=e.rows||h<0||h>=e.cols?null:{row:e.buffer.active.viewportY+d,column:h}}function K2({terminal:e,host:t,point:n,affinity:r="before",cellWidth:i,cellHeight:s}){const o=t.querySelector(".xterm-screen");if(!o)return null;const l=T4({terminal:e,host:t,cellWidth:i,cellHeight:s});if(!(l!=null&&l.cellW)||!l.cellH)return null;const u=n.row-e.buffer.active.viewportY;if(u<0||u>=e.rows||n.column<0||n.column>=e.cols)return null;const d=o.getBoundingClientRect(),h=r==="after"?n.column+1:n.column;return{left:d.left+h*l.cellW,top:d.top+(u+1)*l.cellH}}function av({terminal:e,anchor:t,focus:n}){var u;const{start:r,end:i}=hge(t,n),o=Math.max(0,i.row-r.row)*e.cols+(i.column-r.column)+1;if(o<=0)return null;e.select(r.column,r.row,o);const l=((u=e.getSelection)==null?void 0:u.call(e))||fge(e,r,i);return l.trim()?{anchor:t,focus:n,text:l}:null}function G2({terminal:e,host:t,clientX:n,clientY:r,cellWidth:i,cellHeight:s}){const o=Vh({terminal:e,host:t,clientX:n,clientY:r,cellWidth:i,cellHeight:s});return o?YS({terminal:e,point:o}):null}function YS({terminal:e,point:t}){const n=e.buffer.active.getLine(t.row);if(!n)return null;const r=uge(n,e.cols),i=dge(r,t.column);if(i===null)return null;const s=r[i];return s?av({terminal:e,anchor:{row:t.row,column:s.start},focus:{row:t.row,column:s.end}}):null}function X2({terminal:e,point:t}){const n=t.row+1,r=t.column+1,i=[...y4(e,n).map(o=>({match:o,pathAction:{kind:"image-preview",path:o.path}})),..._4(e,n).map(o=>({match:o,pathAction:{kind:"file-download",path:o.path}}))].find(({match:o})=>!(n<o.startLineNumber||n>o.endLineNumber||n===o.startLineNumber&&r<o.startColumn||n===o.endLineNumber&&r>o.endColumn));if(!i)return null;const s=av({terminal:e,anchor:{row:i.match.startLineNumber-1,column:i.match.startColumn-1},focus:{row:i.match.endLineNumber-1,column:i.match.endColumn-1}});return s?{...s,pathAction:i.pathAction}:null}function Z2(e,t,n){return t>n?(t+n)/2:Math.min(Math.max(e,t),n)}const pge=64;function R4({clientX:e,clientY:t,viewportWidth:n,viewportHeight:r,viewportOffsetLeft:i=0,viewportOffsetTop:s=0}){const o=i+56,l=i+n-56,u=s+56,d=s+r-pge;return{left:Z2(e,o,l),top:Z2(t-48,u,d)}}function mge(e){return{visualSize:Math.round(Math.min(12,Math.max(8,e*.55))),stemSize:Math.round(Math.min(11,Math.max(7,e*.5))),touchSize:44}}function gge({terminal:e,host:t,anchor:n,focus:r}){const i=e.buffer.active.viewportY,s=i+e.rows-1,o=d=>({...d,row:Math.min(s,Math.max(i,d.row))}),l=K2({terminal:e,host:t,point:o(n),affinity:"before"}),u=K2({terminal:e,host:t,point:o(r),affinity:"after"});return!l||!u?null:{anchor:l,focus:u}}function vge({handles:e,viewportWidth:t,viewportHeight:n,viewportOffsetLeft:r=0,viewportOffsetTop:i=0}){return R4({clientX:(e.anchor.left+e.focus.left)/2,clientY:Math.min(e.anchor.top,e.focus.top),viewportWidth:t,viewportHeight:n,viewportOffsetLeft:r,viewportOffsetTop:i})}const yge=/\.(?:png|jpe?g|webp|gif)$/i,A4=/\.[A-Za-z0-9]{1,8}$/,bge=/^(?:com|net|org|io|dev|app|top|cn|ai|co|me|xyz|site|online|cloud|tools|tech|info|biz|us|uk|de|jp|fr|ru|nl|in)$/i;function _ge(e){return e.trim().replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function wge(e){const t=e.trim();if(!t||t.includes(`
644
644
  `))return null;const n=_ge(t);return!n||/\s/.test(n)||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||fE(n)||n.split("/").includes("...")?null:n}function Sge(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 bge.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function xge(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(A4,""),n=t.split("/").pop()??t;return/[A-Za-z_-]/.test(n)}function Ege(e){const t=wge(e);return!t||Sge(t)||!xge(t)?null:yge.test(t)?{kind:"image-preview",path:t}:A4.test(t)?{kind:"file-download",path:t}:null}const Cge=16,kge=24,xh=6,Tge=425,Yh=-1;function Jm(e,t){return e.pointerId===t||t===Yh}function pu(e){return Math.hypot(e.lastX-e.startX,e.lastY-e.startY)}function Ti(e,t={}){const n=window.__ccTestPtyTouchGestureEvents;n&&(n.push({event:e,t:performance.now(),...t}),n.length>200&&n.splice(0,n.length-200))}function Rge({terminalRef:e,suppressPtyFocus:t,focusTerminal:n,onLongPressCandidateStart:r,onTap:i,isTapCandidate:s,onLongPressStart:o,onLongPressMove:l,onLongPressEnd:u}){const d=b.useRef(null),h=b.useCallback(F=>{F.longPressTimer!==null&&(window.clearTimeout(F.longPressTimer),F.longPressTimer=null)},[]),p=b.useCallback(F=>{F.longPressed||F.moved||(F.longPressed=!0,F.longPressArmed=!1,h(F),t(),o==null||o({clientX:F.startX,clientY:F.startY}))},[h,o,t]),y=b.useCallback(F=>{if(!(F.longPressed||F.longPressArmed||F.moved)){if(pu(F)>xh){h(F),Ti("longpress:cancel-drift",{distance:pu(F),threshold:xh});return}if(s!=null&&s({clientX:F.startX,clientY:F.startY})){F.longPressArmed=!0,h(F),Ti("longpress:arm-link",{clientX:F.startX,clientY:F.startY});return}p(F)}},[h,s,p]),v=b.useCallback(F=>{if(F.longPressDelivered||!F.longPressed||F.moved)return;F.longPressDelivered=!0;const O={clientX:F.lastX,clientY:F.lastY};window.setTimeout(()=>u==null?void 0:u(O),0)},[u]),_=b.useCallback((F,O,M,z=!1)=>{const L={pointerId:F,startX:O,startY:M,lastX:O,lastY:M,moved:!1,longPressArmed:!1,longPressed:!1,longPressDelivered:!1,touchEventStream:z,longPressTimer:null};L.longPressTimer=window.setTimeout(()=>{d.current===L&&y(L)},Tge),d.current=L,Ti("start",{pointerId:F,clientX:O,clientY:M,touchEventStream:z}),r==null||r({clientX:O,clientY:M})},[y,r]),w=b.useCallback((F,O,M)=>{const z=d.current;if(!z||!Jm(z,F))return!1;z.lastX=O,z.lastY=M;const L=pu(z);if(z.longPressArmed&&L>xh&&(z.longPressArmed=!1,Ti("longpress:cancel-armed-drift",{pointerId:F,clientX:O,clientY:M,distance:L,threshold:xh})),z.longPressed)return Ti("move",{pointerId:F,clientX:O,clientY:M,distance:L,moved:z.moved,longPressed:!0}),l==null||l({clientX:O,clientY:M}),!0;const N=O-z.startX,q=M-z.startY;return!z.moved&&L>=Cge&&(z.moved=!0,h(z)),Ti("move",{pointerId:F,clientX:O,clientY:M,dx:N,dy:q,distance:L,moved:z.moved,longPressed:!1}),z.moved},[h,l]),x=b.useCallback((F,O)=>{var N;const M=d.current;if(!M||!Jm(M,F))return null;O&&(M.lastX=O.clientX,M.lastY=O.clientY),d.current=null,h(M);const z=pu(M);let L;if(M.longPressArmed){if(z<=xh)return p(M),v(M),L="longpress",Ti("finish",{pointerId:F,result:L,point:O,moved:M.moved,distance:z,longPressed:!0,longPressArmed:!0}),L;M.longPressArmed=!1}return M.longPressed?(v(M),L="longpress",Ti("finish",{pointerId:F,result:L,point:O,moved:M.moved,longPressArmed:M.longPressArmed,distance:z,longPressed:!0}),L):M.moved?O&&pu(M)<=kge&&(i!=null&&i(O))?(t(),L="link",Ti("finish",{pointerId:F,result:L,point:O,moved:!0,distance:z,longPressed:!1}),L):(t(),L="scroll",Ti("finish",{pointerId:F,result:L,point:O,moved:!0,distance:z,longPressed:!1}),L):O&&(i!=null&&i(O))?(t(),L="link",Ti("finish",{pointerId:F,result:L,point:O,moved:!1,distance:z,longPressed:!1}),L):(n?n():(N=e.current)==null||N.focus(),L="tap",Ti("finish",{pointerId:F,result:L,point:O,moved:!1,distance:z,longPressed:!1}),L)},[h,v,n,i,p,t,e]),E=b.useCallback(F=>{const O=d.current;return!O||!Jm(O,F)?null:(h(O),d.current=null,O.longPressed?(v(O),Ti("cancel",{pointerId:F,result:"longpress"}),"longpress"):(O.longPressArmed&&Ti("cancel",{pointerId:F,result:"armed"}),t(),Ti("cancel",{pointerId:F,result:"scroll",moved:O.moved,distance:pu(O)}),"scroll"))},[h,v,t]),k=b.useCallback(F=>{if(F.pointerType!=="touch")return;const O=F.target;!(O instanceof Element)||!O.closest(".xterm")||(_(F.pointerId,F.clientX,F.clientY),F.stopPropagation())},[_]),R=b.useCallback(F=>{if(F.pointerType!=="touch")return;const O=w(F.pointerId,F.clientX,F.clientY),M=d.current;M&&O&&(F.stopPropagation(),M.longPressed&&F.preventDefault())},[w]),A=b.useCallback(F=>{const O=x(F.pointerId,{clientX:F.clientX,clientY:F.clientY});O&&(F.stopPropagation(),O==="link"&&F.cancelable&&F.preventDefault())},[x]),I=b.useCallback(F=>{const O=d.current;if(F.pointerType==="touch"&&O&&Jm(O,F.pointerId)&&O.touchEventStream&&!O.longPressed){F.stopPropagation();return}E(F.pointerId)&&F.stopPropagation()},[E]),T=b.useCallback(F=>{const O=F.target;if(!(O instanceof Element)||!O.closest(".xterm"))return;if(d.current){d.current.touchEventStream=!0;return}const M=F.touches[0]??F.changedTouches[0];M&&_(Yh,M.clientX,M.clientY,!0)},[_]),H=b.useCallback(F=>{const O=F.touches[0]??F.changedTouches[0];if(!O)return;const M=w(Yh,O.clientX,O.clientY),z=d.current;z&&M&&z.longPressed&&(F.stopPropagation(),F.preventDefault())},[w]),D=b.useCallback(F=>{const O=F.changedTouches[0],M=d.current,z=O?{clientX:O.clientX,clientY:O.clientY}:M?{clientX:M.lastX,clientY:M.lastY}:void 0,L=x(Yh,z);(L==="longpress"||L==="link")&&(F.stopPropagation(),F.cancelable&&F.preventDefault())},[x]),W=b.useCallback(F=>{E(Yh)==="longpress"&&F.stopPropagation()},[E]),U=b.useCallback(F=>{const O=d.current;O&&(F.preventDefault(),F.stopPropagation(),y(O))},[y]);return{onPointerDownCapture:k,onPointerMoveCapture:R,onPointerUpCapture:A,onPointerCancelCapture:I,onTouchStartCapture:T,onTouchMoveCapture:H,onTouchEndCapture:D,onTouchCancelCapture:W,onContextMenuCapture:U}}function Age({terminalRef:e,containerEl:t,suppressPtyFocus:n,focusPtyInput:r,isSelectionActive:i,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:u,onLongPressMove:d,onLongPressEnd:h,onHorizontalScrollIntent:p,onSelectionAutoscroll:y,onHandleDragStart:v,onHandleDragMove:_,onHandleDragEnd:w,onHandleDragCancel:x}){const E=b.useRef(null),k=b.useRef(null),R=b.useRef(null),A=b.useRef(!1),I=b.useRef(null),T=b.useCallback(()=>{var L;(L=I.current)==null||L.call(I),I.current=null,k.current=null,R.current=null,A.current=!1,E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)},[]),H=b.useCallback(()=>{var $;E.current=null;const L=k.current;if(!L||!t||!i())return;const N=t.getBoundingClientRect(),{dx:q,dy:Y}=l4({pointerX:L.clientX,pointerY:L.clientY,rect:N,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:44,maxSpeedPx:18});q!==0&&(p==null||p(`selectionGestureAutoscroll dx=${Math.round(q)}`),t.scrollLeft+=q),Y!==0&&(t.scrollTop+=Y),(q!==0||Y!==0)&&(y==null||y({scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}),($=R.current)==null||$.call(R,L)),E.current=requestAnimationFrame(H)},[t,i,p,y]),D=b.useCallback((L,N)=>{k.current=L,R.current=N,E.current===null&&(E.current=requestAnimationFrame(H))},[H]);b.useEffect(()=>T,[T]),b.useEffect(()=>{if(!t)return;const L=N=>{A.current&&N.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 W=b.useCallback(L=>{T(),A.current=!0,u(L)},[u,T]),U=b.useCallback(L=>{d(L),D(L,d)},[d,D]),F=b.useCallback(L=>{T(),h(L)},[h,T]),O=Rge({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:W,onLongPressMove:U,onLongPressEnd:F}),M=b.useCallback((L,N)=>{N.preventDefault(),N.stopPropagation(),T(),A.current=!0,v(L);let q=()=>{};const Y=V=>{V.cancelable&&V.preventDefault();const G={clientX:V.clientX,clientY:V.clientY};_(L,G),D(G,B=>_(L,B))},$=V=>{const G={clientX:V.clientX,clientY:V.clientY};q(),I.current=null,T(),w(L,G)},P=()=>{q(),I.current=null,T(),x(L)};q=()=>{window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",$),window.removeEventListener("pointercancel",P)},I.current=q,window.addEventListener("pointermove",Y,{passive:!1}),window.addEventListener("pointerup",$,{once:!0}),window.addEventListener("pointercancel",P,{once:!0})},[x,w,_,v,T,D]),z=b.useCallback((L,N)=>{if(I.current||!(N.touches[0]??N.changedTouches[0]))return;N.preventDefault(),N.stopPropagation(),A.current=!0,v(L);let Y=()=>{};const $=G=>{const B=G.touches[0]??G.changedTouches[0];if(!B)return;G.cancelable&&G.preventDefault();const K={clientX:B.clientX,clientY:B.clientY};_(L,K),D(K,ee=>_(L,ee))},P=G=>{const B=G.changedTouches[0],K=B?{clientX:B.clientX,clientY:B.clientY}:k.current;Y(),I.current=null,T(),w(L,K)},V=()=>{Y(),I.current=null,T(),x(L)};Y=()=>{window.removeEventListener("touchmove",$),window.removeEventListener("touchend",P),window.removeEventListener("touchcancel",V)},I.current=Y,window.addEventListener("touchmove",$,{passive:!1}),window.addEventListener("touchend",P,{once:!0}),window.addEventListener("touchcancel",V,{once:!0})},[x,w,_,v,T,D]);return{pointerHandlers:O,stopPtySelectionGesture:T,handlePtySelectionHandlePointerDown:M,handlePtySelectionHandleTouchStart:z}}const Nge=8;function Mge(e){const{sessionId:t,terminalRef:n,xtermHostRef:r,scrollControllerRef:i,containerEl:s,scrollState:o,keyboardOffset:l,ptyFontSize:u,suppressPtyFocus:d,focusPtyInput:h,onTap:p,isTapCandidate:y,onDownloadPath:v,onPreviewPath:_}=e,w=b.useRef(null),x=b.useRef(null),E=b.useRef(null),k=b.useRef(null),R=b.useRef(!1),A=b.useRef(null),I=b.useRef(null),T=b.useRef(""),H=b.useRef(null),[D,W]=b.useState(null),[U,F]=b.useState(null),[O,M]=b.useState(null),z=b.useMemo(()=>mge(u),[u]),L=b.useCallback((_e,Be)=>{const Ve=window.visualViewport;return R4({clientX:_e,clientY:Be,viewportWidth:(Ve==null?void 0:Ve.width)??window.innerWidth,viewportHeight:(Ve==null?void 0:Ve.height)??window.innerHeight,viewportOffsetLeft:(Ve==null?void 0:Ve.offsetLeft)??0,viewportOffsetTop:(Ve==null?void 0:Ve.offsetTop)??0})},[]),N=b.useCallback((_e,Be)=>{const Ve=n.current,be=r.current;return!Ve||!be?null:gge({terminal:Ve,host:be,anchor:_e,focus:Be})},[n,r]),q=b.useCallback((_e,Be)=>{const Ve=Be??Ege(_e);return I.current=Ve,M(Ve),Ve},[]),Y=b.useCallback(_e=>{const Be=window.visualViewport;return vge({handles:_e,viewportWidth:(Be==null?void 0:Be.width)??window.innerWidth,viewportHeight:(Be==null?void 0:Be.height)??window.innerHeight,viewportOffsetLeft:(Be==null?void 0:Be.offsetLeft)??0,viewportOffsetTop:(Be==null?void 0:Be.offsetTop)??0})},[]),$=b.useCallback(()=>{const _e=w.current,Be=x.current;if(!_e||!Be){F(null);return}const Ve=N(_e,Be);if(F(Ve),!Ve){W(null);return}W(be=>be&&Y(Ve))},[N,Y]),P=b.useCallback(()=>{var _e,Be;(_e=H.current)==null||_e.call(H),E.current=null,k.current=null,w.current=null,x.current=null,R.current=!1,A.current=null,I.current=null,T.current="",(Be=n.current)==null||Be.clearSelection(),W(null),F(null),M(null)},[n]),V=b.useCallback((_e="")=>{w.current=null,x.current=null,R.current=!1,I.current=null,T.current=_e,W(null),F(null),M(null)},[]),G=b.useCallback(({clientX:_e,clientY:Be})=>{const Ve=n.current,be=r.current;d({blur:!1}),k.current={clientX:_e,clientY:Be},E.current=Ve&&be?Vh({terminal:Ve,host:be,clientX:_e,clientY:Be}):null},[d,n,r]),B=b.useCallback(({clientX:_e,clientY:Be,draggedHandle:Ve="focus"})=>{const be=n.current,Xe=r.current,tt=w.current,ut=x.current;if(!be||!Xe||!tt)return null;const de=Vh({terminal:be,host:Xe,clientX:_e,clientY:Be});if(!de)return null;const Me=Ve==="anchor"?de:tt,nt=Ve==="focus"?de:ut??tt;w.current=Me,x.current=nt,R.current=!0;const Je=av({terminal:be,anchor:Me,focus:nt});return T.current=(Je==null?void 0:Je.text)??"",q((Je==null?void 0:Je.text)??""),F(Je?N(Me,nt):null),Je},[N,q,n,r]),K=b.useCallback(({point:_e,clientX:Be,clientY:Ve,showToolbar:be=!0})=>{const Xe=n.current,tt=r.current;if(!Xe||!tt)return!1;A.current=null;const ut=_e?X2({terminal:Xe,point:_e}):null,de=ut??(_e?YS({terminal:Xe,point:_e}):G2({terminal:Xe,host:tt,clientX:Be,clientY:Ve}));if(!(de!=null&&de.text))return!1;w.current=de.anchor,x.current=de.focus,T.current=de.text,q(de.text,ut==null?void 0:ut.pathAction);const Me=N(de.anchor,de.focus);return F(Me),be&&W(Me?Y(Me):L(Be,Ve)),!0},[N,L,Y,q,n,r]),ee=b.useCallback(()=>{const _e=w.current,Be=x.current;if(!_e||!Be){W(null);return}const Ve=N(_e,Be);F(Ve),W(Ve?Y(Ve):null)},[N,Y]),te=b.useCallback(_e=>{var be,Xe;const Be=((Xe=(be=n.current)==null?void 0:be.getSelection)==null?void 0:Xe.call(be))??"",Ve=q(Be);T.current=Be,w.current=null,x.current=null,R.current=!1,F(null),W(Ve?L(_e.clientX,_e.clientY):null)},[L,q,n]);b.useEffect(()=>{const _e=r.current;if(!_e)return;let Be=!1;const Ve=tt=>{var de,Me;if(tt.pointerType!=="mouse"||tt.button!==0)return;const ut=tt.target;!(ut instanceof Element)||!ut.closest(".xterm")||(Be=!0,V(((Me=(de=n.current)==null?void 0:de.getSelection)==null?void 0:Me.call(de))??""))},be=tt=>{if(tt.pointerType!=="mouse"||!Be)return;Be=!1;const ut={clientX:tt.clientX,clientY:tt.clientY};window.setTimeout(()=>te(ut),0)},Xe=()=>{Be=!1};return _e.addEventListener("pointerdown",Ve,!0),window.addEventListener("pointerup",be,!0),window.addEventListener("pointercancel",Xe,!0),()=>{_e.removeEventListener("pointerdown",Ve,!0),window.removeEventListener("pointerup",be,!0),window.removeEventListener("pointercancel",Xe,!0)}},[V,te,n,r]),b.useLayoutEffect(()=>{if(!D&&!U)return;const _e=Be=>{const Ve=Be.target;Ve instanceof Element&&Ve.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]')||P()};return document.addEventListener("pointerdown",_e,!0),document.addEventListener("touchstart",_e,!0),()=>{document.removeEventListener("pointerdown",_e,!0),document.removeEventListener("touchstart",_e,!0)}},[P,U,D]),b.useEffect(()=>{if(!s||!D)return;const _e=()=>{const Be=A.current;Be&&s.scrollLeft===Be.scrollLeft&&s.scrollTop===Be.scrollTop||P()};return s.addEventListener("scroll",_e,{passive:!0}),()=>s.removeEventListener("scroll",_e)},[P,s,D]);const J=U!==null;b.useLayoutEffect(()=>{var _e;J&&((_e=i.current)==null||_e.relayout(),$())},[J,l,$,i]),b.useEffect(()=>{J&&$()},[J,$,o.scrollLeft,o.scrollTop]),b.useEffect(()=>{if(!J)return;const _e=window.visualViewport;let Be=0,Ve=0;const be=()=>{cancelAnimationFrame(Be),window.clearTimeout(Ve),Be=requestAnimationFrame(()=>{$(),Ve=window.setTimeout(()=>{Be=requestAnimationFrame(()=>$())},160)})};return be(),window.addEventListener("resize",be),_e==null||_e.addEventListener("resize",be),_e==null||_e.addEventListener("scroll",be),()=>{cancelAnimationFrame(Be),window.clearTimeout(Ve),window.removeEventListener("resize",be),_e==null||_e.removeEventListener("resize",be),_e==null||_e.removeEventListener("scroll",be)}},[J,$]);const me=b.useCallback(({clientX:_e,clientY:Be})=>{const Ve=n.current,be=r.current;if(!Ve||!be)return;const Xe=Vh({terminal:Ve,host:be,clientX:_e,clientY:Be})??E.current;if(Ve.clearSelection(),!Xe){w.current=null,x.current=null,I.current=null,T.current="",W(null),F(null),M(null);return}w.current=Xe,x.current=Xe,R.current=!1,I.current=null,T.current="",W(null),F(null),M(null),K({point:Xe,clientX:_e,clientY:Be,showToolbar:!1})},[K,n,r]),Se=b.useCallback(({clientX:_e,clientY:Be})=>{B({clientX:_e,clientY:Be}),W(null)},[B]),Re=b.useCallback(({clientX:_e,clientY:Be})=>{const Ve=n.current,be=r.current;if(!Ve||!be)return;const Xe=w.current,tt=Vh({terminal:Ve,host:be,clientX:_e,clientY:Be}),ut=tt??x.current,de=E.current,Me=k.current,nt=Me?Math.hypot(_e-Me.clientX,Be-Me.clientY)>=Nge:!1,Je=de??tt;if(!R.current&&!nt&&T.current){ee(),E.current=null,k.current=null;return}const lt=!R.current&&!nt&&Je?X2({terminal:Ve,point:Je}):null,At=nt?tt??ut:ut,zt=(R.current||nt)&&Xe&&At?av({terminal:Ve,anchor:Xe,focus:At}):lt??G2({terminal:Ve,host:be,clientX:_e,clientY:Be})??(de?YS({terminal:Ve,point:de}):null);if(E.current=null,k.current=null,!(zt!=null&&zt.text)){P();return}w.current=zt.anchor,x.current=zt.focus,T.current=zt.text,q(zt.text,lt==null?void 0:lt.pathAction);const Yt=N(zt.anchor,zt.focus);F(Yt),W(Yt?Y(Yt):L(_e,Be))},[P,N,L,Y,q,ee,n,r]),Ae=b.useCallback(()=>{var Ve;const _e=n.current,Be=((Ve=_e==null?void 0:_e.getSelection)==null?void 0:Ve.call(_e))||T.current;Be&&k4(Be,{allowLegacyFallback:!0}).then(be=>{P(),be==="failed"?et.error("复制失败"):et.success("已复制")})},[P,n]),He=b.useCallback(()=>{const _e=I.current;_e&&(_e.kind==="image-preview"?_(_e.path):v(_e.path),P())},[P,v,_]),qe=b.useCallback(()=>w.current!==null,[]),pt=b.useCallback(()=>{W(null)},[]),kt=b.useCallback((_e,{clientX:Be,clientY:Ve})=>{B({clientX:Be,clientY:Ve,draggedHandle:_e}),W(null)},[B]),ve=b.useCallback((_e,Be)=>{Be&&B({...Be,draggedHandle:_e}),T.current&&ee()},[B,ee]),Ke=b.useCallback(()=>{W(null)},[]);b.useEffect(()=>{},[P,N,Y,t,q,n]);const Tt=Age({terminalRef:n,containerEl:s,suppressPtyFocus:d,focusPtyInput:h,isSelectionActive:qe,onTap:p,isTapCandidate:y,onLongPressCandidateStart:G,onLongPressStart:me,onLongPressMove:Se,onLongPressEnd:Re,onHorizontalScrollIntent:_e=>{var Be;return(Be=i.current)==null?void 0:Be.markHorizontalScrollIntent(_e)},onSelectionAutoscroll:_e=>{A.current=_e},onHandleDragStart:pt,onHandleDragMove:kt,onHandleDragEnd:ve,onHandleDragCancel:Ke});return H.current=Tt.stopPtySelectionGesture,{pointerHandlers:Tt.pointerHandlers,ptySelectionToolbar:D,ptySelectionHandles:U,ptySelectionPathAction:O,ptySelectionHandleMetrics:z,copyPtySelection:Ae,openPtySelectionPathAction:He,handlePtySelectionHandlePointerDown:Tt.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Tt.handlePtySelectionHandleTouchStart}}function Oge(){return Oe(e=>e.ptyScrollTraceEnabled)}const Dge=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function Q2(e){return Dge.has(e)}function yE(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!Q2(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>Q2(r.type))??null}function Pge(e){return`${e.startsWith("@")?e:`@${e}`} `}async function N4(e){const t=yE(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await E4(t),r=await e.relay.uploadClipboardImage(e.sessionId,n);if(!r.success||!r.path)throw new Error(r.error??"剪贴板图片上传失败");return{path:r.path,pathMention:Pge(r.path)}}function Lge(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 Ige({sessionId:e,terminalRef:t,onAfterPaste:n}){return b.useCallback(async r=>{var u;const i=r.clipboardData,s=!!yE(i),o=s?null:Lge(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Nt;if(!l){et.error("请先连接开发机");return}if(s){const d=et.loading("图片上传中...");try{const h=await N4({clipboardData:i,relay:l,sessionId:e});if(et.dismiss(d),!h)return;qs(e,h.pathMention)}catch(h){et.error(h instanceof Error?h.message:String(h),{id:d});return}}else if(o){const d=await Cf({relay:l,sessionId:e,file:o});if(!d)return;qs(e,`@${d} `)}n==null||n(),(u=t.current)==null||u.focus()},[e,t,n])}const zge=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),J2={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:Hfe};function Bge({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function jge({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function Fge({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function $ge({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:zge.has(n)}const eO=8,Hge=32;function Uge({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+eO:t?Hge:eO}function Wge(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 qge(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,mobileControlsHeight:o}=e,l=Qme(),u=nge(),d=Oge(),{openImagePreview:h}=A3(),p=b.useRef(null),y=b.useRef(null),v=b.useRef([]),_=b.useRef(null),w=b.useRef(null),x=b.useRef(n),E=b.useRef(n),k=b.useRef(!1),R=b.useRef(!1),A=b.useRef(!1),I=b.useRef(null),T=b.useRef(null),H=b.useRef(null),D=b.useRef(null),W=b.useRef({keyboardOpen:!1,controlsVisible:!1}),U=b.useRef(!1),F=b.useRef(!1),O=b.useRef(!1),M=b.useRef(null),z=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[L,N]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[q,Y]=b.useState(!1),[$,P]=b.useState(!1),[V,G]=b.useState({resultIndex:-1,resultCount:0}),B=Oe(re=>re.connected),K=Oe(re=>re.proxyOnline),ee=Oe(re=>re.ptyFontSize),te=Oe(re=>re.inputModePreference),J=Oe(re=>re.adaptiveInputModality),me=Oe(re=>re.setAdaptiveInputModality),Se=J==="hardware",Re=cl("(pointer: coarse), (hover: none)"),{bottomOffset:Ae,layoutBottomInset:He}=vE(),qe=te==="hardware",pt=Fge({touchEditingSurface:Re,inputModePreference:te,detectedPhysicalKeyboard:Se,softKeyboardDetected:Ae>0}),kt=Re&&!pt,ve=pt?0:Ae,Ke=ve>0,Tt=pt?0:He;U.current=pt,b.useEffect(()=>{x.current=n},[n]),b.useEffect(()=>{k.current=l.ready},[l.ready]);const _e=b.useCallback(()=>x.current&&k.current,[]);b.useEffect(()=>{ve>0&&Y(!0)},[ve]);const Be=tge({containerEl:r,xtermHostRef:s,terminalRef:p}),{ptyInputFocused:Ve,suppressPtyFocus:be,focusPtyInput:Xe,handleFocusCapture:tt,handleBlurCapture:ut}=Be,de=Bge({softKeyboardEditingSurface:kt,ptyInputFocused:Ve,keyboardOpen:Ke});z.current={keyboardOffset:ve,hasSeenSoftKeyboard:q,showMobilePtyControls:de,touchEditingSurface:Re,ptyInputFocused:Ve,containerPaddingBottom:z.current.containerPaddingBottom,mobileControlsBottomInset:Tt};const Me=u.clearNewFramesWhileAway;T.current||(T.current=U2(()=>{var re;(re=w.current)==null||re.relayout()})),H.current||(H.current=U2(()=>{var fe,ye;const re=D.current??{reason:"rawInput",force:!1};D.current=null,(fe=w.current)==null||fe.traceRawInputFollowFire(),(ye=w.current)==null||ye.scrollToBottom(re.reason,re.force?{force:!0}:void 0),Me()}));const nt=b.useCallback(()=>{M.current!==null&&(cancelAnimationFrame(M.current),M.current=null)},[]),Je=b.useCallback(()=>{O.current=!0,nt()},[nt]),lt=b.useCallback(()=>{var re;!O.current||document.visibilityState==="hidden"||((re=w.current)==null||re.preparePageResumeRestore(),nt(),M.current=requestAnimationFrame(()=>{M.current=requestAnimationFrame(()=>{M.current=null;const fe=w.current;fe&&(fe.restorePageResume(),Me(),O.current=!1)})}))},[nt,Me]);b.useEffect(()=>()=>{var re,fe;(re=T.current)==null||re.dispose(),(fe=H.current)==null||fe.dispose(),nt(),T.current=null,H.current=null},[nt]),b.useEffect(()=>{const re=()=>{Je()},fe=()=>{if(document.visibilityState==="hidden"){re();return}lt()};return document.addEventListener("visibilitychange",fe),window.addEventListener("pagehide",re),window.addEventListener("pageshow",lt),window.addEventListener("focus",lt),()=>{document.removeEventListener("visibilitychange",fe),window.removeEventListener("pagehide",re),window.removeEventListener("pageshow",lt),window.removeEventListener("focus",lt),nt()}},[nt,Je,lt]),b.useEffect(()=>{const re=E.current;if(E.current=n,re!==n){if(!n){Je();return}lt()}},[n,Je,lt]);const At=b.useCallback((re="rawInput",fe)=>{var ze,Fe;const ye=D.current,Te=(ye==null?void 0:ye.force)===!0||(fe==null?void 0:fe.force)===!0;D.current={reason:(fe==null?void 0:fe.force)===!0||!ye?re:ye.reason,force:Te},(ze=w.current)==null||ze.traceRawInputFollowScheduled(re),(Fe=H.current)==null||Fe.schedule()},[]),zt=b.useCallback((re,fe)=>{var ye;!re.includes("\r")&&!re.includes(`
645
645
  `)||(ye=w.current)==null||ye.resetHorizontalScroll(fe,{holdUntilCursorVisible:!0})},[]),Yt=b.useCallback(()=>U.current?"submit":"linefeed",[]),hn=b.useCallback(()=>U.current,[]);b.useEffect(()=>{if(!n||te!=="auto"||!Re)return;const re=ye=>{const Te=s.current,ze=r;return ye instanceof Node?Te!=null&&Te.contains(ye)||ye===document.body||ye===document.documentElement?!0:ze!=null&&ze.contains(ye)?ye instanceof HTMLElement?ye.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:ye===window},fe=ye=>{var Fe;if(!$ge({active:x.current,touchEditingSurface:Re,key:ye.key,code:ye.code,altKey:ye.altKey,ctrlKey:ye.ctrlKey,metaKey:ye.metaKey,isComposing:ye.isComposing,targetAcceptsPtyInput:re(ye.target)}))return;me("hardware"),U.current=!0,(Fe=p.current)==null||Fe.focus();const Te=s.current;if(ye.target instanceof Node&&(Te!=null&&Te.contains(ye.target)))return;const ze=Wge(ye);!ze||!_e()||(ye.preventDefault(),ye.stopPropagation(),qs(t,ze),At("physicalKeyboard"),zt(ze,"physicalKeyboardEnter"))};return window.addEventListener("keydown",fe,!0),()=>window.removeEventListener("keydown",fe,!0)},[n,_e,r,te,zt,At,t,me,Re,s]);const Gt=b.useCallback(re=>{const fe=Nt;if(!fe){et.error("请先连接开发机");return}const ye=et.loading(`下载 ${re} ...`);V1({relay:fe,sessionId:t,path:re}).then(Te=>{Te.ok?et.success(`已开始下载 ${re}`,{id:ye}):et.error(Te.error,{id:ye})}).catch(Te=>{et.error(Te instanceof Error?Te.message:String(Te),{id:ye})})},[t]),qt=b.useCallback(re=>{const fe=p.current;return fe?Mme(fe,v.current,re):!1},[]),Xn=b.useCallback(re=>{const fe=p.current;return fe?Nme(fe,v.current,re):!1},[]),Ut=Mge({sessionId:t,terminalRef:p,xtermHostRef:s,scrollControllerRef:w,containerEl:r,scrollState:L,keyboardOffset:ve,ptyFontSize:ee,suppressPtyFocus:be,focusPtyInput:Xe,onTap:qt,isTapCandidate:Xn,onDownloadPath:Gt,onPreviewPath:h});F.current=Ut.ptySelectionHandles!==null;const Dn=Ige({sessionId:t,terminalRef:p,onAfterPaste:()=>At("paste")}),je=b.useCallback(re=>{if(!_e()){re.preventDefault();return}Dn(re)},[_e,Dn]),[Qe,St]=b.useState(!1),wt=b.useCallback(re=>{re.dataTransfer.types.includes("Files")&&(re.preventDefault(),St(fe=>fe||!0))},[]),Q=b.useCallback(re=>{re.currentTarget.contains(re.relatedTarget)||St(!1)},[]),we=b.useCallback(async re=>{var ze;const fe=(ze=re.dataTransfer.files)==null?void 0:ze[0];if(!fe||(re.preventDefault(),St(!1),!_e()))return;const ye=Nt;if(!ye){et.error("请先连接开发机");return}const Te=await Cf({relay:ye,sessionId:t,file:fe});Te&&(qs(t,`@${Te} `),At("dropUpload"))},[_e,At,t]),We=b.useCallback(re=>{var ye;if(!_e()){re.preventDefault();return}const fe=re.target;fe instanceof Element&&fe.closest(".xterm")||(re.preventDefault(),(ye=p.current)==null||ye.focus())},[_e]);b.useEffect(()=>{if(!B||!K)return;const re=s.current,fe=Jl,ye=Nt,Te=r,ze=i.current;if(!re||!fe||!ye||!Te||!ze)return;let Fe=null,Rt=null,Ft=null,Sn=null,Zt=null,Tn=null;const Gi=qpe({host:re,sessionId:t,ws:fe,relay:ye,scheduleAutoFocus:kt?()=>{}:void 0,createTerminal:async Pn=>await i4(Pn,{fontSize:Oe.getState().ptyFontSize}),attachRawInput:(Pn,Rn,Ge)=>upe(Pn,Rn,{...Ge,getPlainEnterBehavior:Yt,isPhysicalKeyboardMode:hn,physicalKeyboardMode:qe}),isInputEnabled:_e,canFocus:_e,onTerminalReady:Pn=>{const Rn=Pn;p.current=Rn;const Ge=new vce({highlightLimit:1e3});Rn.loadAddon(Ge),y.current=Ge,Tn=Ge.onDidChangeResults(An=>{G(An)}),P(!0);const gt=hme(Rn,h);Fe=gt.dispose;const $t=Cme(Rn,Gt);Rt=$t.dispose,v.current=[gt.provider,$t.provider],Vme(()=>p.current);const pn=Kfe(re);Sn=pn.dispose;const jn=O.current;jn&&(A.current=!1);const Ot=Fpe({container:Te,spacer:ze,host:re,term:Rn,hasNewFrame:()=>R.current,consumeNewFrame:()=>{R.current=!1},hasNewFramesWhileAway:()=>u.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:u.setHasNewFramesWhileAway,onAtBottomChange:u.handleAtBottomChange,onScrollStateChange:N,initialUserHasVerticalScrollIntent:jn?!1:A.current,onUserVerticalScrollIntentChange:An=>{A.current=An},onTouchReviewStart:be,onTouchBoundaryPrevent:be,onReviewSnapshotCapture:pn.capture,onReviewSnapshotClear:pn.clear});w.current=Ot,Ft=Ot.dispose,jn&&(Ot.restorePageResume(),Me(),O.current=!1),Kme(()=>{var Ao;const An=Tc=>{if(!Tc)return null;const xr=Tc.getBoundingClientRect();return{top:xr.top,bottom:xr.bottom,height:xr.height,left:xr.left,right:xr.right,width:xr.width}},ln=document.querySelector('[data-slot="pty-mobile-controls"]'),tn=document.querySelector("[data-keyboard-offset]"),Br=window.visualViewport,Xi=An(ln),Ro=(Br==null?void 0:Br.height)??window.innerHeight;return{...Xme(Ot.getDebugProbe,{container:Te,spacer:ze,host:re,term:Rn}),mobileLayout:{...z.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:Br?{height:Br.height,width:Br.width,offsetTop:Br.offsetTop,pageTop:Br.pageTop,scale:Br.scale}:null,chatRoot:{dataKeyboardOffset:(tn==null?void 0:tn.getAttribute("data-keyboard-offset"))??null,rect:An(tn)},ptyViewRect:An(Te.parentElement),containerRect:An(Te),controlsRect:Xi,controlsOverflowBelowVisualViewport:Xi===null?null:Xi.bottom-Ro,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(Ao=document.activeElement.closest("[data-slot]"))==null?void 0:Ao.getAttribute("data-slot")}:null},frame:{lastWriteAt:I.current,pendingNewFrame:R.current}}}),Zt=Zfe({container:Te,host:re,onHorizontalScrollIntent:An=>{var ln;return(ln=w.current)==null?void 0:ln.markHorizontalScrollIntent(An)}}).dispose},onFramePending:()=>{R.current=!0,A.current&&!u.hasNewFramesWhileAwayRef.current&&u.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Pn;I.current=performance.now(),(Pn=T.current)==null||Pn.schedule()},onRawInput:Pn=>{At("rawInput"),zt(Pn,"rawInputEnter")},onError:Pn=>{const Rn=Pn instanceof Error?Pn.message:String(Pn);et.error(`终端初始化失败:${Rn}`)},...l.transport});return _.current=Gi,()=>{Zt==null||Zt(),Ft==null||Ft(),Sn==null||Sn(),Tn==null||Tn.dispose(),Gme(),Fe==null||Fe(),Rt==null||Rt(),v.current=[],Yme(),y.current=null,P(!1),G({resultIndex:-1,resultCount:0}),Gi.dispose(),p.current=null,w.current=null,_.current=null}},[t,B,K,r,i,s,l.transport,u.handleAtBottomChange,u.hasNewFramesWhileAwayRef,u.setHasNewFramesWhileAway,_e,qe,Yt,hn,Gt,h,be,At,zt]),b.useEffect(()=>{const re=p.current,fe=w.current;!re||!fe||qfe(re,ee,fe.relayout)},[ee]),b.useEffect(()=>{if(!n||!l.ready||kt)return;const re=requestAnimationFrame(()=>{var fe;return(fe=p.current)==null?void 0:fe.focus()});return()=>cancelAnimationFrame(re)},[n,l.ready,kt]);const ct=b.useCallback((re="viewExternal",fe)=>{var ye;(ye=w.current)==null||ye.scrollToBottom(re,fe)},[]),Pt=b.useCallback(()=>{var re;(re=w.current)==null||re.refreshReviewSnapshot()},[]),ie=b.useCallback(re=>{var fe;(fe=w.current)==null||fe.scrollToRatio(re)},[]),oe=b.useCallback(re=>{var fe;(fe=w.current)==null||fe.scrollToXRatio(re)},[]),he=b.useCallback(re=>{var Rt;const fe=p.current,ye=fe==null?void 0:fe.getSelectionPosition();if(!fe||!ye)return;const Te=ye.start.y;if(Te>=re&&Te<re+fe.rows)return;const ze=Math.max(0,fe.buffer.active.length-fe.rows);if(ze===0)return;const Fe=Math.max(0,Math.min(ze,Te-Math.floor(fe.rows/2)));(Rt=w.current)==null||Rt.scrollToRatio(Fe/ze)},[]),pe=b.useCallback((re,fe=!1)=>{const ye=p.current,Te=y.current;if(!ye||!Te||!re)return re||(Te==null||Te.clearDecorations(),ye==null||ye.clearSelection(),G({resultIndex:-1,resultCount:0})),!1;const ze=ye.buffer.active.viewportY,Fe=Te.findNext(re,{...J2,incremental:fe});return Fe&&he(ze),Fe},[he]),Z=b.useCallback(re=>{const fe=p.current,ye=y.current;if(!fe||!ye||!re)return!1;const Te=fe.buffer.active.viewportY,ze=ye.findPrevious(re,J2);return ze&&he(Te),ze},[he]),se=b.useCallback(()=>{var re,fe;(re=y.current)==null||re.clearDecorations(),(fe=p.current)==null||fe.clearSelection(),G({resultIndex:-1,resultCount:0})},[]),le=b.useCallback(re=>{var fe;_e()&&(qs(t,re),At("mobileControl",{force:!0}),zt(re,"mobileControlEnter"),(fe=p.current)==null||fe.focus())},[_e,zt,At,t]),ne=b.useCallback(()=>{var fe,ye,Te;if(!_e())return;const re=(ye=(fe=navigator.clipboard)==null?void 0:fe.readText)==null?void 0:ye.bind(navigator.clipboard);if(!window.isSecureContext||!re){et.error("无法读取剪贴板"),(Te=p.current)==null||Te.focus();return}re().then(ze=>{if(!ze)return;const Fe=p.current;if(Fe){Fe.paste(ze);return}qs(t,ze),At("paste"),zt(ze,"pasteEnter")}).catch(ze=>{const Fe=ze instanceof Error&&ze.message?ze.message:"无法读取剪贴板";et.error(Fe)}).finally(()=>{var ze;return(ze=p.current)==null?void 0:ze.focus()})},[_e,zt,At,t]),ce=Uge({showMobilePtyControls:de,horizontalScrollable:L.horizontalScrollable,mobileControlsHeight:o});z.current.containerPaddingBottom=ce,b.useEffect(()=>{var ye,Te,ze;F.current?(ye=w.current)==null||ye.relayout():(Te=T.current)==null||Te.schedule();const re=W.current,fe=jge({controlsVisible:de,keyboardOpen:Ke,previous:re});W.current={keyboardOpen:Ke,controlsVisible:de},de&&(F.current?Me():fe?((ze=w.current)==null||ze.scrollToBottom("keyboardOffset",{force:!0}),Me()):Ke||At("keyboardOffset"))},[ve,Ke,de,ce,Me,At]);const Ce=b.useMemo(()=>({onFocusCapture:tt,onBlurCapture:ut}),[tt,ut]);return{scrollState:L,isAtBottom:u.isAtBottom,hasNewFramesWhileAway:u.hasNewFramesWhileAway,ptyInputFocused:Ve,showMobilePtyControls:de,touchEditingSurface:Re,keyboardOffset:ve,physicalKeyboardMode:pt,softKeyboardEditingSurface:kt,mobileControlsBottomInset:Tt,connectionReady:l.ready,connectionOverlay:l.overlay,containerPaddingBottom:ce,traceEnabled:d,findReady:$,findResultIndex:V.resultIndex,findResultCount:V.resultCount,findNext:pe,findPrevious:Z,clearFind:se,refreshReviewSnapshot:Pt,scrollToBottom:ct,scrollToRatio:ie,scrollToXRatio:oe,clearNewFramesWhileAway:Me,sendMobileInput:le,pasteMobileClipboard:ne,handleTerminalContainerMouseDown:We,handlePasteCapture:je,pointerHandlers:Ut.pointerHandlers,focusHandlers:Ce,ptySelectionToolbar:Ut.ptySelectionToolbar,ptySelectionHandles:Ut.ptySelectionHandles,ptySelectionPathAction:Ut.ptySelectionPathAction,ptySelectionHandleMetrics:Ut.ptySelectionHandleMetrics,copyPtySelection:Ut.copyPtySelection,openPtySelectionPathAction:Ut.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:Ut.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Ut.handlePtySelectionHandleTouchStart,isPtyDragOver:Qe,handlePtyDragOver:wt,handlePtyDragLeave:Q,handlePtyDrop:we}}function Vge({sessionId:e,sessionKind:t,provider:n,active:r=!0,findRequest:i}){const[s,o]=b.useState(null),[l,u]=b.useState(0),[d,h]=b.useState(!1),[p,y]=b.useState(""),v=b.useRef(null),_=b.useRef(null),w=qge({sessionId:e,active:r,containerEl:s,spacerRef:v,xtermHostRef:_,mobileControlsHeight:l}),x=w.ptySelectionHandleMetrics,{clearFind:E,findNext:k,findPrevious:R,findReady:A,findResultCount:I,findResultIndex:T}=w,H=b.useCallback(()=>{R(p)},[R,p]),D=b.useCallback(()=>{k(p)},[k,p]),W=b.useCallback(()=>h(!0),[]),U=b.useCallback(()=>{h(!1),E()},[E]),F=P3({enabled:r,open:d,openRequest:i,onOpen:W,onClose:U,onPrevious:H,onNext:D});return b.useEffect(()=>{!d||!A||(p?k(p,!0):E())},[E,k,d,p,A]),g.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":w.connectionReady?"true":"false","aria-busy":!w.connectionReady,children:[d?g.jsx(K0,{query:p,resultIndex:T,resultCount:I,focusRequest:F.focusRequest,loading:!!p&&!A,onQueryChange:y,onPrevious:H,onNext:D,onClose:F.closeFind}):null,g.jsx("div",{ref:o,className:"flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${w.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:w.handleTerminalContainerMouseDown,onPointerDownCapture:O=>{w.refreshReviewSnapshot(),w.pointerHandlers.onPointerDownCapture(O)},onPointerMoveCapture:w.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:w.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:w.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:w.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:w.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:w.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:w.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:w.pointerHandlers.onContextMenuCapture,onPasteCapture:w.handlePasteCapture,onDragOver:w.handlePtyDragOver,onDragLeave:w.handlePtyDragLeave,onDrop:w.handlePtyDrop,onFocusCapture:w.focusHandlers.onFocusCapture,onBlurCapture:w.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":w.isPtyDragOver?"true":void 0,children:g.jsx("div",{ref:v,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:g.jsx("div",{ref:_,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})})}),g.jsx(M3,{visible:!w.isAtBottom,hasNewMessages:w.hasNewFramesWhileAway,className:d?"top-14":"top-10",onClick:()=>{w.scrollToBottom("backToBottomBtn",{force:!0}),w.clearNewFramesWhileAway()}}),w.showMobilePtyControls?g.jsx(Ale,{sessionKind:t,provider:n,bottomInset:w.mobileControlsBottomInset,onInput:w.sendMobileInput,onPaste:w.pasteMobileClipboard,onHeightChange:u}):null,w.ptySelectionHandles?g.jsxs(g.Fragment,{children:[g.jsx(tO,{kind:"anchor",position:w.ptySelectionHandles.anchor,metrics:x,"aria-label":"调整选区起点",onPointerDown:O=>w.handlePtySelectionHandlePointerDown("anchor",O),onTouchStart:O=>w.handlePtySelectionHandleTouchStart("anchor",O)}),g.jsx(tO,{kind:"focus",position:w.ptySelectionHandles.focus,metrics:x,"aria-label":"调整选区终点",onPointerDown:O=>w.handlePtySelectionHandlePointerDown("focus",O),onTouchStart:O=>w.handlePtySelectionHandleTouchStart("focus",O)})]}):null,w.ptySelectionToolbar?g.jsxs("div",{className:"fixed z-50 flex -translate-x-1/2 gap-1 rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-lg",style:{left:w.ptySelectionToolbar.left,top:w.ptySelectionToolbar.top},"data-slot":"pty-selection-toolbar",children:[g.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:O=>O.preventDefault(),onClick:w.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),w.ptySelectionPathAction?g.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:O=>O.preventDefault(),onClick:w.openPtySelectionPathAction,"aria-label":w.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:w.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,g.jsx(zle,{state:w.scrollState,onScrollRatio:w.scrollToRatio}),g.jsx(Ble,{state:w.scrollState,onScrollRatio:w.scrollToXRatio}),g.jsx(gle,{...w.connectionOverlay}),g.jsx(yle,{ptyInputFocused:w.ptyInputFocused,touchEditingSurface:w.touchEditingSurface,softKeyboardEditingSurface:w.softKeyboardEditingSurface,physicalKeyboardMode:w.physicalKeyboardMode,keyboardOffset:w.keyboardOffset,showMobilePtyControls:w.showMobilePtyControls,mobileControlsBottomInset:w.mobileControlsBottomInset}),w.traceEnabled?g.jsx(Yge,{}):null]})}function tO({kind:e,position:t,metrics:n,"aria-label":r,onPointerDown:i,onTouchStart:s}){const o=n.touchSize/2,l=2,u=n.visualSize,d=Math.max(n.stemSize+2,u+1),h=o-l/2,p=o,y=e==="anchor"?h-u+l:h,v=p+d-u+l,_=e==="anchor"?{borderTopLeftRadius:u,borderBottomLeftRadius:u,borderTopRightRadius:2,borderBottomRightRadius:u}:{borderTopLeftRadius:2,borderBottomLeftRadius:u,borderTopRightRadius:u,borderBottomRightRadius:u};return g.jsxs("button",{type:"button",className:"fixed z-50 touch-none rounded-full bg-transparent p-0 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",style:{left:t.left,top:t.top,width:n.touchSize,height:n.touchSize,transform:"translate(-50%, -50%)"},"data-slot":"pty-selection-handle","data-kind":e,"aria-label":r,onPointerDown:i,onTouchStart:s,children:[g.jsx("span",{className:"pointer-events-none absolute rounded-full bg-primary",style:{left:h,top:p,width:l,height:d},"data-slot":"pty-selection-handle-stem"}),g.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:y,top:v,width:u,height:u,..._},"data-slot":"pty-selection-handle-dot"})]})}function Yge(){const[e,t]=b.useState(!1);async function n(){const r=ple();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return g.jsx("button",{type:"button",className:"absolute left-3 top-3 z-30 rounded border border-border bg-popover/90 px-2 py-1 text-[11px] text-muted-foreground",onPointerDown:r=>r.preventDefault(),onClick:n,"data-slot":"pty-scroll-trace-copy",children:e?"Copied":"Trace"})}const Kge=3,Gge=1024,Xge=720,eg=.5,M4=b.createContext(null);function Zge({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Oe(k=>k.selectedProxyId),u=It(k=>k.sessions),d=It(k=>k.sessionListLoaded),h=b.useRef(l),p=b.useRef(null),y=b.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
646
646
  `),[u]),v=b.useCallback(k=>{p.current=k.sessionId,i(k),n(R=>Boe(R,k.sessionId,{capacity:Kge,now:Date.now(),activeSessionId:k.sessionId}).map(I=>I.sessionId===k.sessionId?{...I,sessionKind:k.sessionKind,provider:k.provider}:I))},[]),_=b.useCallback(k=>{p.current===k&&(p.current=null),i(R=>(R==null?void 0:R.sessionId)===k?null:R),o(R=>p.current===null?null:R)},[]),w=b.useCallback((k,R)=>{p.current===k&&o(A=>!R||A&&eve(A,R)?A:R)},[]),x=b.useCallback((k,R)=>{R!==void 0&&n(A=>A.map(I=>I.sessionId===k?{...I,findRequest:R}:I))},[]);b.useEffect(()=>{if(!d)return;const k=new Set(y?y.split(`
647
- `):[]);n(R=>R.filter(A=>k.has(A.sessionId))),i(R=>R&&k.has(R.sessionId)?R:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),b.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const E=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:x,updateViewportRect:w}),[v,_,x,w]);return g.jsxs(M4.Provider,{value:E,children:[e,g.jsx(Jge,{entries:t,activeView:r,viewportRect:s})]})}function Qge({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(M4),s=b.useRef(null);if(!i)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:o,deactivate:l,updateFindRequest:u,updateViewportRect:d}=i;return b.useLayoutEffect(()=>(o({sessionId:e,sessionKind:t,provider:n}),()=>l(e)),[o,l,e,t,n]),b.useLayoutEffect(()=>{u(e,r)},[r,e,u]),b.useLayoutEffect(()=>{const h=s.current;if(!h)return;const p=()=>{const v=h.getBoundingClientRect();d(e,{top:v.top,left:v.left,width:v.width,height:v.height})};p();const y=new ResizeObserver(p);return y.observe(h),window.addEventListener("resize",p),()=>{y.disconnect(),window.removeEventListener("resize",p)}},[e,d]),g.jsx("div",{ref:s,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function Jge({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:g.jsx("div",{className:"fixed inset-0 z-10 pointer-events-none","data-slot":"pty-keepalive-layer",children:e.map(r=>{const i=(t==null?void 0:t.sessionId)===r.sessionId&&n!==null,s=i?n:{top:-1e5,left:0,width:(n==null?void 0:n.width)??Gge,height:(n==null?void 0:n.height)??Xge};return g.jsx("div",{className:"absolute overflow-hidden bg-background","data-slot":"pty-keepalive-entry","data-session-id":r.sessionId,"data-active":i?"true":"false","aria-hidden":!i,style:{top:s.top,left:s.left,width:s.width,height:s.height,pointerEvents:i?"auto":"none",visibility:i?"visible":"hidden"},children:g.jsx(N3,{sessionId:r.sessionId,children:g.jsx(Vge,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function eve(e,t){return Math.abs(e.top-t.top)<=eg&&Math.abs(e.left-t.left)<=eg&&Math.abs(e.width-t.width)<=eg&&Math.abs(e.height-t.height)<=eg}function bE({route:e,surface:t,proxiesLength:n,hasProxy:r,sessionCount:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 服务器需要 client token。请在设置里填写。":s==="invalid_client_token"?"当前浏览器保存的 client token 无效或已过期。请在设置里更新。":n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。":t==="mobile"&&e==="proxy-select"||!r?"选择要连接的开发机。":i===0?"还没有会话。可以从本地终端接入,也可以新建会话。":t==="desktop"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}const _E="dev-anywhere:last-chat-route",O4="dev-anywhere:route-restored",KS="dev-anywhere:restored-target";function tve(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function nve(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(_E))??null}catch{return null}}function rve(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(_E,e)}catch{}}function D4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(_E)}catch{}}function ive(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(O4))==="1"}catch{return!1}}function sve(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(O4,"1")}catch{}}function ove(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(KS,e)}catch{}}function ave(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(KS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(KS)),n}catch{return null}}function lve(e){const t=UL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Og(){if(typeof window>"u"||typeof navigator>"u")return!1;const e=typeof window.matchMedia=="function"&&(window.matchMedia("(display-mode: standalone)").matches||window.matchMedia("(display-mode: fullscreen)").matches),t=!!navigator.standalone;return e||t}function cve(){return typeof navigator>"u"?{supported:!0}:lve({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Og()})}function uve(){$me(),Hme();const e=Di(),t=Xs(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=b.useState(!1),[o,l]=b.useState(()=>Og()),u=Oe(D=>D.proxies.length),d=Oe(D=>D.proxyListLoaded),h=Oe(D=>D.relayClientAuthIssue),p=Oe(D=>!!D.selectedProxyId),y=Oe(D=>D.selectedProxyId),v=Oe(D=>D.selectedProxyName),_=It(D=>D.sessions.length),w=Oe(D=>D.pendingToast),x=Oe(D=>D.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=bE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:h}),R=v??y,I=e.pathname==="/sessions"&&d&&u>0?g.jsxs(mt,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":R?`切换开发机,当前 ${R}`:"切换开发机",onClick:()=>t("/"),children:[g.jsx(OP,{className:"size-4 text-primary","aria-hidden":"true"}),g.jsxs("span",{className:"min-w-0 truncate",children:[g.jsx("span",{className:"text-foreground",children:"切换开发机"}),R?g.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",R]}):null]})]}):null;b.useEffect(()=>{if(!w)return;({error:et.error,info:et.info,success:et.success})[w.kind](w.message),x(null)},[w,x]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Og());return}const D=window.matchMedia("(display-mode: standalone)"),W=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(Og());return U(),D.addEventListener("change",U),W.addEventListener("change",U),()=>{D.removeEventListener("change",U),W.removeEventListener("change",U)}},[]);const T=b.useRef(!1);b.useEffect(()=>{if(T.current)return;T.current=!0;const D=tve({pathname:e.pathname,alreadyRestored:ive(),lastRoute:nve()});sve(),D&&(ove(D),t(D,{replace:!0}))},[]);const H=b.useRef(!1);return b.useEffect(()=>{n?(H.current=!0,rve(`${e.pathname}${e.search}`)):H.current&&(H.current=!1,D4())},[n,e.pathname,e.search]),g.jsxs("div",{className:"flex flex-col bg-background text-foreground",style:{height:"var(--dev-app-shell-height, max(100dvh, var(--dev-visual-viewport-height, 100dvh)))"},"data-slot":"app-shell","data-standalone-display":o?"true":void 0,children:[!n&&g.jsx(mt,{variant:"ghost",size:"icon",className:"dev-mobile-settings-trigger group fixed right-4 z-30 size-11 rounded-full border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-transparent hover:text-foreground md:hidden","aria-label":"设置","data-slot":"mobile-settings-trigger",onClick:()=>s(!0),children:g.jsx("span",{"data-slot":"mobile-settings-trigger-visual",className:"flex size-7 items-center justify-center rounded-full border border-border/80 bg-card/90 shadow-lg backdrop-blur transition-colors group-hover:border-primary/45 group-hover:bg-accent",children:g.jsx(LP,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx($se,{subtitle:k,action:I}),g.jsx(zoe,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(Bse,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(Zge,{children:g.jsx("div",{className:Ye("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(HU,{})},r?"top-level":e.pathname)})})]}),g.jsx(q0,{open:i,onOpenChange:s}),g.jsx(poe,{}),g.jsx(Xse,{}),g.jsx(pZ,{})]})}function P4({subtitle:e,action:t}){return g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[g.jsx(GB,{texts:XB,className:"text-2xl md:text-3xl font-bold"}),g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&g.jsx("div",{children:t})]})}function dve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=It(o=>o.sessions.length),i=bE({route:"proxy-select",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n}),s=n==="missing_client_token"?"client-token-missing":n==="invalid_client_token"?"client-token-invalid":null;return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx(DB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(ec,{variant:s}):g.jsx(P4,{subtitle:i})})]})}function hve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=It(o=>o.sessions.length),i=xi("local",on.proxyId)!==null;if(!t&&!i)return g.jsx($U,{to:"/",replace:!0});const s=bE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx(HB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(P4,{subtitle:s})})]})}function L4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function fve(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function I4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return fve(e,typeof((t=L4())==null?void 0:t.request)=="function")}function pve(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function mve(){const e=L4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(pve(I4()));return e.request("screen")}function gve(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class vve{constructor(t={}){ht(this,"activeScopes",new Set);ht(this,"pendingScopes",new Set);ht(this,"listeners",new Map);ht(this,"sentinel",null);ht(this,"requestInFlight",null);ht(this,"requestWakeLock");ht(this,"documentRef");ht(this,"windowRef");ht(this,"unavailableReason");ht(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(()=>{})});ht(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??mve,this.unavailableReason=typeof t.request=="function"?null:I4(),this.documentRef=t.document??(typeof document>"u"?void 0:document),this.windowRef=t.window??(typeof window>"u"?void 0:window),(n=this.documentRef)==null||n.addEventListener("visibilitychange",this.handleVisibilityChange),(r=this.windowRef)==null||r.addEventListener("pagehide",this.handlePageHide)}isSupported(){return this.unavailableReason===null}getSnapshot(t){return{active:this.activeScopes.has(t),pending:this.pendingScopes.has(t),supported:this.isSupported(),unavailableReason:this.unavailableReason}}subscribe(t,n){const r=this.listeners.get(t)??new Set;return r.add(n),this.listeners.set(t,r),n(this.getSnapshot(t)),()=>{r.delete(n),r.size===0&&this.listeners.delete(t)}}async enable(t){this.activeScopes.add(t),this.pendingScopes.add(t),this.notify(t);try{await this.ensureWakeLock()}catch(n){throw this.activeScopes.delete(t),new Error(gve(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 Ya=new vve;function z4(e){const[t,n]=b.useState(()=>Ya.getSnapshot(e));b.useEffect(()=>Ya.subscribe(e,n),[e]),b.useEffect(()=>()=>{Ya.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Ya.enable(e),[e]),i=b.useCallback(()=>Ya.disable(e),[e]),s=b.useCallback(()=>Ya.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function yve(){return new AudioContext}class bve{constructor(t=yve){ht(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Dg=new bve,nO=400,Ou=[];let B4=1;function _ve(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Kh(e){const t={sequence:B4++,timestamp:new Date().toISOString(),monotonicMs:_ve(),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>nO&&Ou.splice(0,Ou.length-nO)}function wve(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Sve(){Ou.length=0,B4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:wve,clear:Sve});function j4(e){return`voice-pilot:${e}`}function xve(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 Eve="modulepreload",Cve=function(e){return"/"+e},rO={},kve=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=Cve(d),d in rO)return;rO[d]=!0;const h=d.endsWith(".css"),p=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const y=document.createElement("link");if(y.rel=h?"stylesheet":Eve,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((v,_)=>{y.addEventListener("load",v),y.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},Tve="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Rve=20,Ka=Zu*Rve/1e3,Bw=Ka*Int16Array.BYTES_PER_ELEMENT;let iO=null;async function Ave(){return iO??(iO=kve(async()=>{const{default:e}=await import("./fvad-hCXSsY4Z.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Tve:t}))),iO}class wE{constructor(t,n,r){ht(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Ave(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(Bw);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Zu)!==0)throw n._free(i),n._fvad_free(r),new Error("浏览器语音活动检测器不支持 16 kHz 音频");if(n._fvad_set_mode(r,t)!==0)throw n._free(i),n._fvad_free(r),new Error("无法配置浏览器语音活动检测器");return new wE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==Bw)throw new Error(`语音活动检测帧必须为 ${Bw} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Ka);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 Nve{constructor(t={}){ht(this,"startSpeechFrames");ht(this,"endSilenceFrames");ht(this,"active",!1);ht(this,"speechFrames",0);ht(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 Mve{constructor(){ht(this,"pending",new Float32Array(Ka));ht(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Ka-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Ka&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Ka<=t.length;)n(t.slice(r,r+Ka)),r+=Ka;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const Ove="/__dev_anywhere_debug/voice-fixture",Dve=Zu*WB/1e3;function Pve(){return wE.create(3)}const Lve={createVad:Pve,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Ive(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 zve(e){for(const t of e.getTracks())t.stop()}function F4(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 Bve(e){const t=F4(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(),zve(n),t.state!=="closed"&&await t.close()}}}async function jve(e,t){const n=F4(t);try{const r=await t.fetch(e);if(!r.ok)throw new Error(`测试录音读取失败 (${r.status})`);const i=await n.decodeAudioData(await r.arrayBuffer()),s=n.createBufferSource();s.buffer=i;let o=!1,l=!1;return{context:n,input:s,async start(){o||l||(o=!0,n.state==="suspended"&&await n.resume(),s.start())},async stop(){if(!l){if(l=!0,o)try{s.stop()}catch{}s.disconnect(),n.state!=="closed"&&await n.close()}}}}catch(r){throw await n.close().catch(()=>{}),r}}function $4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Ove}:{kind:"microphone"}}async function Fve(e,t=Lve){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await jve(e.source.url,t):await Bve(t)}catch(h){throw n.destroy(),h}const i=new Nve,s=new Mve,o=r.context.createScriptProcessor(Dve,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=xve(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:Ive(p)});const _=i.push(v);_==="speech-start"&&e.onSpeechStart(),_==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function H4(e=Cv().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function $ve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function Hve({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=$ve(e);return g.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&g.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),g.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function Uve(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 Wve(){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(Uve(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",tg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function uo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function qve({label:e}){return g.jsxs(uo,{className:"relative",children:[g.jsx(MP,{className:"size-4","aria-hidden":"true"}),g.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3 min-w-4 items-center justify-center rounded-[3px] border border-border bg-popover px-0.5 font-mono text-[7px] leading-none text-muted-foreground shadow-sm",children:e})]})}function Vve({sessionId:e,mode:t,onFind:n}){const r=H4(),i=Xs(),s=It(ve=>ve.sessions.find(Ke=>Ke.sessionId===e)),o=It(ve=>ve.ptyTitles[e]),l=Oe(ve=>ve.ptyFontSize),u=Oe(ve=>ve.chatContentFontSize),d=Oe(ve=>ve.selectedProxyId),h=Oe(ve=>ve.adjustPtyFontSize),p=Oe(ve=>ve.adjustChatContentFontSize),y=Oe(ve=>ve.setChatContentFontSize),v=Oe(ve=>ve.resetPtyFontSize),_=Oe(ve=>ve.resetChatContentFontSize),w=Oe(ve=>ve.inputModePreference==="hardware"),x=It(ve=>ve.renameSession),E=Ix(d,e),k=It(ve=>E?!!ve.ptyAutoYesBySessionKey[E]:!1),R=It(ve=>ve.setPtyAutoYes),I=cl("(pointer: coarse), (hover: none)")&&!w,T=t==="pty"||(s==null?void 0:s.mode)==="pty",H=(s==null?void 0:s.kind)==="terminal",D=z4(e),W=sn(ve=>ve.bySessionId[e]??sy),U=sn(ve=>ve.enable),F=sn(ve=>ve.disable),O=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Kx(s),z=O&&(s==null?void 0:s.name)||M||T&&o||(s==null?void 0:s.name)||e.slice(0,8),L=!!(T&&!H&&o&&!O),N=T?l:Px(u,I),q=!T&&I?nL:eL,Y=T?v:_,[$,P]=b.useState(!1),[V,G]=b.useState(!1),B=W.enabled,K=D.active||B,ee=D.pending||!D.supported||B;function te(ve){if(T){h(ve);return}if(I){y(N+ve);return}p(ve)}function J(){D.toggle().catch(ve=>{et.error(ve instanceof Error?ve.message:String(ve))})}async function me(ve){var Tt;if(T||H){et.info("Voice Pilot 目前适用于聊天会话。");return}if(ve!==!0){F(e);return}const Ke=Nt;if(!Ke){et.error("请先连接开发机");return}try{if(!((Tt=(await Ke.requestVoiceConfig()).config)!=null&&Tt.configured)){et.info("请先在设置里配置 Voice Pilot。");return}P(!0)}catch(_e){et.error(_e instanceof Error?_e.message:String(_e))}}async function Se(){var _e;G(!0);let ve=null,Ke=!1;const Tt=j4(e);try{Kh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((_e=navigator.userActivation)==null?void 0:_e.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Be=Ya.enable(Tt).then(()=>{Kh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},tt=>{throw Kh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:tt instanceof Error?tt.message:String(tt)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:tt})});ve=L1.acquire("capture");const Ve=Dg.prepare(),Xe=$4().kind==="microphone"?Wve():Promise.resolve();await Promise.all([Be,Ve,Xe]),U(e),Ke=!0,P(!1)}catch(Be){Kh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Be instanceof Error?Be.message:String(Be)}}),et.error(Be instanceof Error?Be.message:String(Be))}finally{ve==null||ve.release(),Ke||await Ya.disable(Tt).catch(()=>{}),G(!1)}}const Re=b.useRef(null),Ae=b.useRef(null),[He,qe]=b.useState(!1);async function pt(ve){var Be;const Ke=(Be=ve.target.files)==null?void 0:Be[0];if(ve.target.value="",!Ke)return;const Tt=Nt;if(!Tt){et.error("请先连接开发机");return}const _e=await Cf({relay:Tt,sessionId:e,file:Ke});_e&&qs(e,`@${_e} `)}async function kt(ve,Ke){const Tt=Nt;if(!Tt)throw new Error("请先连接开发机");const _e=await Tt.renameSession(ve,Ke);if(!_e.success)throw new Error(_e.error??"重命名失败");x(ve,_e.name??Ke),et.success("已重命名会话")}return g.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[g.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:g.jsxs("div",{className:"grid min-h-12 w-full grid-cols-[2.25rem_minmax(0,1fr)_2.25rem] items-center","data-slot":"chat-header-rail",children:[g.jsx("div",{className:"flex justify-start",children:g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(bv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(Hve,{title:z,isPtyTitle:L})}),g.jsxs(M1,{modal:!1,children:[g.jsx(O1,{asChild:!0,children:g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(d8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(Bm,{className:tg,children:"会话"}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(uo,{children:g.jsx(Ig,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>qe(!0),children:[g.jsx(uo,{children:g.jsx(V8,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(G_,{checked:K,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ee,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:J,children:[g.jsx(uo,{children:g.jsx(T8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:D.supported?B?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":D.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),T&&!H&&g.jsxs(G_,{checked:k,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!E,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ve=>{E&&R(E,ve===!0)},children:[g.jsx(uo,{children:g.jsx(ta,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!T&&!H&&g.jsxs(G_,{checked:W.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:me,children:[g.jsx(uo,{children:g.jsx(D8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(X_,{}),T&&!H?g.jsxs(g.Fragment,{children:[g.jsx(Bm,{className:tg,children:"快捷键"}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>qs(e,""),children:[g.jsx(qve,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(X_,{}),g.jsx(Bm,{className:tg,children:"文件"}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ve;return(ve=Ae.current)==null?void 0:ve.click()},children:[g.jsx(uo,{children:g.jsx(Pf,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ve;return(ve=Re.current)==null?void 0:ve.click()},children:[g.jsx(uo,{children:g.jsx(IP,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(X_,{})]}):null,g.jsx(Bm,{className:tg,children:"字号"}),g.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:g.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[g.jsx(uo,{children:g.jsx(v7,{"aria-hidden":"true"})}),g.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:N<=q,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ve=>{ve.stopPropagation(),te(-1)},children:g.jsx(L8,{"aria-hidden":"true"})}),g.jsxs("span",{className:"flex h-[22px] min-w-11 items-center justify-center px-1 text-sm font-medium leading-none tabular-nums text-foreground","data-slot":"chat-menu-font-size",children:[N,"px"]}),g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:N>=tL,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ve=>{ve.stopPropagation(),te(1)},children:g.jsx(G8,{"aria-hidden":"true"})})]})]})}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-font-reset",onClick:Y,children:[g.jsx(uo,{children:g.jsx(Q8,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(jh,{open:He,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:qe,onRename:kt}),g.jsx(_c,{open:$&&!W.enabled,onOpenChange:ve=>{V||P(ve)},children:g.jsxs(wc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(Sc,{children:[g.jsx(ll,{children:"开启 Voice Pilot?"}),g.jsx(cc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"outline",disabled:V,onClick:()=>P(!1),children:"取消"}),g.jsx(mt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:V,onClick:()=>{Se()},children:V?"正在开启...":"开启 Voice Pilot"})]})]})}),T?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Ae,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ve=>{pt(ve)}}),g.jsx("input",{ref:Re,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ve=>{pt(ve)}})]}):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((_,w)=>r[w]!==_)))return i;r=p;let v;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(v=Date.now()),i=t(...p),n.key&&((d=n.debug)!=null&&d.call(n))){const _=Math.round((Date.now()-h)*100)/100,w=Math.round((Date.now()-v)*100)/100,x=w/16,E=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(_,5)} ms`,`
647
+ `):[]);n(R=>R.filter(A=>k.has(A.sessionId))),i(R=>R&&k.has(R.sessionId)?R:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),b.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const E=b.useMemo(()=>({activate:v,deactivate:_,updateFindRequest:x,updateViewportRect:w}),[v,_,x,w]);return g.jsxs(M4.Provider,{value:E,children:[e,g.jsx(Jge,{entries:t,activeView:r,viewportRect:s})]})}function Qge({sessionId:e,sessionKind:t,provider:n,findRequest:r}){const i=b.useContext(M4),s=b.useRef(null);if(!i)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:o,deactivate:l,updateFindRequest:u,updateViewportRect:d}=i;return b.useLayoutEffect(()=>(o({sessionId:e,sessionKind:t,provider:n}),()=>l(e)),[o,l,e,t,n]),b.useLayoutEffect(()=>{u(e,r)},[r,e,u]),b.useLayoutEffect(()=>{const h=s.current;if(!h)return;const p=()=>{const v=h.getBoundingClientRect();d(e,{top:v.top,left:v.left,width:v.width,height:v.height})};p();const y=new ResizeObserver(p);return y.observe(h),window.addEventListener("resize",p),()=>{y.disconnect(),window.removeEventListener("resize",p)}},[e,d]),g.jsx("div",{ref:s,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function Jge({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:g.jsx("div",{className:"fixed inset-0 z-10 pointer-events-none","data-slot":"pty-keepalive-layer",children:e.map(r=>{const i=(t==null?void 0:t.sessionId)===r.sessionId&&n!==null,s=i?n:{top:-1e5,left:0,width:(n==null?void 0:n.width)??Gge,height:(n==null?void 0:n.height)??Xge};return g.jsx("div",{className:"absolute overflow-hidden bg-background","data-slot":"pty-keepalive-entry","data-session-id":r.sessionId,"data-active":i?"true":"false","aria-hidden":!i,style:{top:s.top,left:s.left,width:s.width,height:s.height,pointerEvents:i?"auto":"none",visibility:i?"visible":"hidden"},children:g.jsx(N3,{sessionId:r.sessionId,children:g.jsx(Vge,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function eve(e,t){return Math.abs(e.top-t.top)<=eg&&Math.abs(e.left-t.left)<=eg&&Math.abs(e.width-t.width)<=eg&&Math.abs(e.height-t.height)<=eg}function bE({route:e,surface:t,proxiesLength:n,hasProxy:r,sessionCount:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 服务器需要 client token。请在设置里填写。":s==="invalid_client_token"?"当前浏览器保存的 client token 无效或已过期。请在设置里更新。":n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。":t==="mobile"&&e==="proxy-select"||!r?"选择要连接的开发机。":i===0?"还没有会话。可以从本地终端接入,也可以新建会话。":t==="desktop"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}const _E="dev-anywhere:last-chat-route",O4="dev-anywhere:route-restored",KS="dev-anywhere:restored-target";function tve(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function nve(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(_E))??null}catch{return null}}function rve(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(_E,e)}catch{}}function D4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(_E)}catch{}}function ive(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(O4))==="1"}catch{return!1}}function sve(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(O4,"1")}catch{}}function ove(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(KS,e)}catch{}}function ave(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(KS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(KS)),n}catch{return null}}function lve(e){const t=UL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Og(){if(typeof window>"u"||typeof navigator>"u")return!1;const e=typeof window.matchMedia=="function"&&(window.matchMedia("(display-mode: standalone)").matches||window.matchMedia("(display-mode: fullscreen)").matches),t=!!navigator.standalone;return e||t}function cve(){return typeof navigator>"u"?{supported:!0}:lve({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Og()})}function uve(){$me(),Hme();const e=Di(),t=Xs(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=b.useState(!1),[o,l]=b.useState(()=>Og()),u=Oe(D=>D.proxies.length),d=Oe(D=>D.proxyListLoaded),h=Oe(D=>D.relayClientAuthIssue),p=Oe(D=>!!D.selectedProxyId),y=Oe(D=>D.selectedProxyId),v=Oe(D=>D.selectedProxyName),_=It(D=>D.sessions.length),w=Oe(D=>D.pendingToast),x=Oe(D=>D.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=bE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:_,relayClientAuthIssue:h}),R=v??y,I=e.pathname==="/sessions"&&d&&u>0?g.jsxs(mt,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":R?`切换开发机,当前 ${R}`:"切换开发机",onClick:()=>t("/"),children:[g.jsx(OP,{className:"size-4 text-primary","aria-hidden":"true"}),g.jsxs("span",{className:"min-w-0 truncate",children:[g.jsx("span",{className:"text-foreground",children:"切换开发机"}),R?g.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",R]}):null]})]}):null;b.useEffect(()=>{if(!w)return;({error:et.error,info:et.info,success:et.success})[w.kind](w.message),x(null)},[w,x]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Og());return}const D=window.matchMedia("(display-mode: standalone)"),W=window.matchMedia("(display-mode: fullscreen)"),U=()=>l(Og());return U(),D.addEventListener("change",U),W.addEventListener("change",U),()=>{D.removeEventListener("change",U),W.removeEventListener("change",U)}},[]);const T=b.useRef(!1);b.useEffect(()=>{if(T.current)return;T.current=!0;const D=tve({pathname:e.pathname,alreadyRestored:ive(),lastRoute:nve()});sve(),D&&(ove(D),t(D,{replace:!0}))},[]);const H=b.useRef(!1);return b.useEffect(()=>{n?(H.current=!0,rve(`${e.pathname}${e.search}`)):H.current&&(H.current=!1,D4())},[n,e.pathname,e.search]),g.jsxs("div",{className:"flex flex-col bg-background text-foreground",style:{height:"var(--dev-app-shell-height, max(100dvh, var(--dev-visual-viewport-height, 100dvh)))"},"data-slot":"app-shell","data-standalone-display":o?"true":void 0,children:[!n&&g.jsx(mt,{variant:"ghost",size:"icon",className:"dev-mobile-settings-trigger group fixed right-4 z-30 size-11 rounded-full border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-transparent hover:text-foreground md:hidden","aria-label":"设置","data-slot":"mobile-settings-trigger",onClick:()=>s(!0),children:g.jsx("span",{"data-slot":"mobile-settings-trigger-visual",className:"flex size-7 items-center justify-center rounded-full border border-border/80 bg-card/90 shadow-lg backdrop-blur transition-colors group-hover:border-primary/45 group-hover:bg-accent",children:g.jsx(LP,{className:"size-4","aria-hidden":"true"})})}),!n&&g.jsx($se,{subtitle:k,action:I}),g.jsx(zoe,{}),g.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[g.jsx(Bse,{className:"hidden md:flex"}),g.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:g.jsx(Zge,{children:g.jsx("div",{className:Ye("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:g.jsx(HU,{})},r?"top-level":e.pathname)})})]}),g.jsx(q0,{open:i,onOpenChange:s}),g.jsx(poe,{}),g.jsx(Xse,{}),g.jsx(pZ,{})]})}function P4({subtitle:e,action:t}){return g.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[g.jsx(GB,{texts:XB,className:"text-2xl md:text-3xl font-bold"}),g.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&g.jsx("div",{children:t})]})}function dve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=It(o=>o.sessions.length),i=bE({route:"proxy-select",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n}),s=n==="missing_client_token"?"client-token-missing":n==="invalid_client_token"?"client-token-invalid":null;return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx(DB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:s?g.jsx(ec,{variant:s}):g.jsx(P4,{subtitle:i})})]})}function hve(){const e=Oe(o=>o.proxies),t=Oe(o=>!!o.selectedProxyId),n=Oe(o=>o.relayClientAuthIssue),r=It(o=>o.sessions.length),i=xi("local",on.proxyId)!==null;if(!t&&!i)return g.jsx($U,{to:"/",replace:!0});const s=bE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-full md:hidden",children:g.jsx(HB,{layout:"page"})}),g.jsx("div",{className:"hidden md:block h-full",children:g.jsx(P4,{subtitle:s})})]})}function L4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function fve(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function I4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return fve(e,typeof((t=L4())==null?void 0:t.request)=="function")}function pve(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function mve(){const e=L4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(pve(I4()));return e.request("screen")}function gve(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class vve{constructor(t={}){ht(this,"activeScopes",new Set);ht(this,"pendingScopes",new Set);ht(this,"listeners",new Map);ht(this,"sentinel",null);ht(this,"requestInFlight",null);ht(this,"requestWakeLock");ht(this,"documentRef");ht(this,"windowRef");ht(this,"unavailableReason");ht(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(()=>{})});ht(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??mve,this.unavailableReason=typeof t.request=="function"?null:I4(),this.documentRef=t.document??(typeof document>"u"?void 0:document),this.windowRef=t.window??(typeof window>"u"?void 0:window),(n=this.documentRef)==null||n.addEventListener("visibilitychange",this.handleVisibilityChange),(r=this.windowRef)==null||r.addEventListener("pagehide",this.handlePageHide)}isSupported(){return this.unavailableReason===null}getSnapshot(t){return{active:this.activeScopes.has(t),pending:this.pendingScopes.has(t),supported:this.isSupported(),unavailableReason:this.unavailableReason}}subscribe(t,n){const r=this.listeners.get(t)??new Set;return r.add(n),this.listeners.set(t,r),n(this.getSnapshot(t)),()=>{r.delete(n),r.size===0&&this.listeners.delete(t)}}async enable(t){this.activeScopes.add(t),this.pendingScopes.add(t),this.notify(t);try{await this.ensureWakeLock()}catch(n){throw this.activeScopes.delete(t),new Error(gve(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 Ya=new vve;function z4(e){const[t,n]=b.useState(()=>Ya.getSnapshot(e));b.useEffect(()=>Ya.subscribe(e,n),[e]),b.useEffect(()=>()=>{Ya.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Ya.enable(e),[e]),i=b.useCallback(()=>Ya.disable(e),[e]),s=b.useCallback(()=>Ya.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function yve(){return new AudioContext}class bve{constructor(t=yve){ht(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Dg=new bve,nO=400,Ou=[];let B4=1;function _ve(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Kh(e){const t={sequence:B4++,timestamp:new Date().toISOString(),monotonicMs:_ve(),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>nO&&Ou.splice(0,Ou.length-nO)}function wve(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function Sve(){Ou.length=0,B4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:wve,clear:Sve});function j4(e){return`voice-pilot:${e}`}function xve(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 Eve="modulepreload",Cve=function(e){return"/"+e},rO={},kve=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=Cve(d),d in rO)return;rO[d]=!0;const h=d.endsWith(".css"),p=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const y=document.createElement("link");if(y.rel=h?"stylesheet":Eve,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((v,_)=>{y.addEventListener("load",v),y.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},Tve="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Rve=20,Ka=Zu*Rve/1e3,Bw=Ka*Int16Array.BYTES_PER_ELEMENT;let iO=null;async function Ave(){return iO??(iO=kve(async()=>{const{default:e}=await import("./fvad-DrtXpjHa.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Tve:t}))),iO}class wE{constructor(t,n,r){ht(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Ave(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(Bw);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Zu)!==0)throw n._free(i),n._fvad_free(r),new Error("浏览器语音活动检测器不支持 16 kHz 音频");if(n._fvad_set_mode(r,t)!==0)throw n._free(i),n._fvad_free(r),new Error("无法配置浏览器语音活动检测器");return new wE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==Bw)throw new Error(`语音活动检测帧必须为 ${Bw} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Ka);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 Nve{constructor(t={}){ht(this,"startSpeechFrames");ht(this,"endSilenceFrames");ht(this,"active",!1);ht(this,"speechFrames",0);ht(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 Mve{constructor(){ht(this,"pending",new Float32Array(Ka));ht(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Ka-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Ka&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Ka<=t.length;)n(t.slice(r,r+Ka)),r+=Ka;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const Ove="/__dev_anywhere_debug/voice-fixture",Dve=Zu*WB/1e3;function Pve(){return wE.create(3)}const Lve={createVad:Pve,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Ive(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 zve(e){for(const t of e.getTracks())t.stop()}function F4(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 Bve(e){const t=F4(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(),zve(n),t.state!=="closed"&&await t.close()}}}async function jve(e,t){const n=F4(t);try{const r=await t.fetch(e);if(!r.ok)throw new Error(`测试录音读取失败 (${r.status})`);const i=await n.decodeAudioData(await r.arrayBuffer()),s=n.createBufferSource();s.buffer=i;let o=!1,l=!1;return{context:n,input:s,async start(){o||l||(o=!0,n.state==="suspended"&&await n.resume(),s.start())},async stop(){if(!l){if(l=!0,o)try{s.stop()}catch{}s.disconnect(),n.state!=="closed"&&await n.close()}}}}catch(r){throw await n.close().catch(()=>{}),r}}function $4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Ove}:{kind:"microphone"}}async function Fve(e,t=Lve){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await jve(e.source.url,t):await Bve(t)}catch(h){throw n.destroy(),h}const i=new Nve,s=new Mve,o=r.context.createScriptProcessor(Dve,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=xve(p),v=n.process(y);e.onFrame({pcm:y,speechProbability:v?1:0,activityLevel:Ive(p)});const _=i.push(v);_==="speech-start"&&e.onSpeechStart(),_==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function H4(e=Cv().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function $ve(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function Hve({title:e,isPtyTitle:t}){if(!t)return g.jsx(g.Fragment,{children:e});const{indicator:n,label:r}=$ve(e);return g.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&g.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),g.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function Uve(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 Wve(){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(Uve(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",tg="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function uo({children:e,className:t}){return g.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function qve({label:e}){return g.jsxs(uo,{className:"relative",children:[g.jsx(MP,{className:"size-4","aria-hidden":"true"}),g.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3 min-w-4 items-center justify-center rounded-[3px] border border-border bg-popover px-0.5 font-mono text-[7px] leading-none text-muted-foreground shadow-sm",children:e})]})}function Vve({sessionId:e,mode:t,onFind:n}){const r=H4(),i=Xs(),s=It(ve=>ve.sessions.find(Ke=>Ke.sessionId===e)),o=It(ve=>ve.ptyTitles[e]),l=Oe(ve=>ve.ptyFontSize),u=Oe(ve=>ve.chatContentFontSize),d=Oe(ve=>ve.selectedProxyId),h=Oe(ve=>ve.adjustPtyFontSize),p=Oe(ve=>ve.adjustChatContentFontSize),y=Oe(ve=>ve.setChatContentFontSize),v=Oe(ve=>ve.resetPtyFontSize),_=Oe(ve=>ve.resetChatContentFontSize),w=Oe(ve=>ve.inputModePreference==="hardware"),x=It(ve=>ve.renameSession),E=Ix(d,e),k=It(ve=>E?!!ve.ptyAutoYesBySessionKey[E]:!1),R=It(ve=>ve.setPtyAutoYes),I=cl("(pointer: coarse), (hover: none)")&&!w,T=t==="pty"||(s==null?void 0:s.mode)==="pty",H=(s==null?void 0:s.kind)==="terminal",D=z4(e),W=sn(ve=>ve.bySessionId[e]??sy),U=sn(ve=>ve.enable),F=sn(ve=>ve.disable),O=!!(s!=null&&s.nameLocked&&(s!=null&&s.name)),M=Kx(s),z=O&&(s==null?void 0:s.name)||M||T&&o||(s==null?void 0:s.name)||e.slice(0,8),L=!!(T&&!H&&o&&!O),N=T?l:Px(u,I),q=!T&&I?nL:eL,Y=T?v:_,[$,P]=b.useState(!1),[V,G]=b.useState(!1),B=W.enabled,K=D.active||B,ee=D.pending||!D.supported||B;function te(ve){if(T){h(ve);return}if(I){y(N+ve);return}p(ve)}function J(){D.toggle().catch(ve=>{et.error(ve instanceof Error?ve.message:String(ve))})}async function me(ve){var Tt;if(T||H){et.info("Voice Pilot 目前适用于聊天会话。");return}if(ve!==!0){F(e);return}const Ke=Nt;if(!Ke){et.error("请先连接开发机");return}try{if(!((Tt=(await Ke.requestVoiceConfig()).config)!=null&&Tt.configured)){et.info("请先在设置里配置 Voice Pilot。");return}P(!0)}catch(_e){et.error(_e instanceof Error?_e.message:String(_e))}}async function Se(){var _e;G(!0);let ve=null,Ke=!1;const Tt=j4(e);try{Kh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((_e=navigator.userActivation)==null?void 0:_e.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Be=Ya.enable(Tt).then(()=>{Kh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},tt=>{throw Kh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:tt instanceof Error?tt.message:String(tt)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:tt})});ve=L1.acquire("capture");const Ve=Dg.prepare(),Xe=$4().kind==="microphone"?Wve():Promise.resolve();await Promise.all([Be,Ve,Xe]),U(e),Ke=!0,P(!1)}catch(Be){Kh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Be instanceof Error?Be.message:String(Be)}}),et.error(Be instanceof Error?Be.message:String(Be))}finally{ve==null||ve.release(),Ke||await Ya.disable(Tt).catch(()=>{}),G(!1)}}const Re=b.useRef(null),Ae=b.useRef(null),[He,qe]=b.useState(!1);async function pt(ve){var Be;const Ke=(Be=ve.target.files)==null?void 0:Be[0];if(ve.target.value="",!Ke)return;const Tt=Nt;if(!Tt){et.error("请先连接开发机");return}const _e=await Cf({relay:Tt,sessionId:e,file:Ke});_e&&qs(e,`@${_e} `)}async function kt(ve,Ke){const Tt=Nt;if(!Tt)throw new Error("请先连接开发机");const _e=await Tt.renameSession(ve,Ke);if(!_e.success)throw new Error(_e.error??"重命名失败");x(ve,_e.name??Ke),et.success("已重命名会话")}return g.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[g.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:g.jsxs("div",{className:"grid min-h-12 w-full grid-cols-[2.25rem_minmax(0,1fr)_2.25rem] items-center","data-slot":"chat-header-rail",children:[g.jsx("div",{className:"flex justify-start",children:g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>i("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:g.jsx(bv,{"aria-hidden":"true"})})}),g.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:g.jsx(Hve,{title:z,isPtyTitle:L})}),g.jsxs(M1,{modal:!1,children:[g.jsx(O1,{asChild:!0,children:g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:g.jsx(d8,{"aria-hidden":"true"})})}),g.jsxs(D1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[g.jsx(Bm,{className:tg,children:"会话"}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[g.jsx(uo,{children:g.jsx(Ig,{"aria-hidden":"true"})}),"在会话中查找"]}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>qe(!0),children:[g.jsx(uo,{children:g.jsx(V8,{"aria-hidden":"true"})}),"重命名"]}),g.jsxs(G_,{checked:K,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ee,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:J,children:[g.jsx(uo,{children:g.jsx(T8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:D.supported?B?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":D.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),T&&!H&&g.jsxs(G_,{checked:k,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!E,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ve=>{E&&R(E,ve===!0)},children:[g.jsx(uo,{children:g.jsx(ta,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!T&&!H&&g.jsxs(G_,{checked:W.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:me,children:[g.jsx(uo,{children:g.jsx(D8,{"aria-hidden":"true"})}),g.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),g.jsx(X_,{}),T&&!H?g.jsxs(g.Fragment,{children:[g.jsx(Bm,{className:tg,children:"快捷键"}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>qs(e,""),children:[g.jsx(qve,{label:"^O"}),"发送 Ctrl+O"]}),g.jsx(X_,{}),g.jsx(Bm,{className:tg,children:"文件"}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var ve;return(ve=Ae.current)==null?void 0:ve.click()},children:[g.jsx(uo,{children:g.jsx(Pf,{"aria-hidden":"true"})}),"上传照片或视频"]}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var ve;return(ve=Re.current)==null?void 0:ve.click()},children:[g.jsx(uo,{children:g.jsx(IP,{"aria-hidden":"true"})}),"上传文件"]}),g.jsx(X_,{})]}):null,g.jsx(Bm,{className:tg,children:"字号"}),g.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:g.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[g.jsx(uo,{children:g.jsx(v7,{"aria-hidden":"true"})}),g.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:N<=q,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ve=>{ve.stopPropagation(),te(-1)},children:g.jsx(L8,{"aria-hidden":"true"})}),g.jsxs("span",{className:"flex h-[22px] min-w-11 items-center justify-center px-1 text-sm font-medium leading-none tabular-nums text-foreground","data-slot":"chat-menu-font-size",children:[N,"px"]}),g.jsx(mt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:N>=tL,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ve=>{ve.stopPropagation(),te(1)},children:g.jsx(G8,{"aria-hidden":"true"})})]})]})}),g.jsxs(go,{className:mu,"data-slot":"chat-menu-font-reset",onClick:Y,children:[g.jsx(uo,{children:g.jsx(Q8,{"aria-hidden":"true"})}),g.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),g.jsx(jh,{open:He,sessionId:e,initialName:s==null?void 0:s.name,onOpenChange:qe,onRename:kt}),g.jsx(_c,{open:$&&!W.enabled,onOpenChange:ve=>{V||P(ve)},children:g.jsxs(wc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[g.jsxs(Sc,{children:[g.jsx(ll,{children:"开启 Voice Pilot?"}),g.jsx(cc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),g.jsxs(Yu,{children:[g.jsx(mt,{type:"button",variant:"outline",disabled:V,onClick:()=>P(!1),children:"取消"}),g.jsx(mt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:V,onClick:()=>{Se()},children:V?"正在开启...":"开启 Voice Pilot"})]})]})}),T?g.jsxs(g.Fragment,{children:[g.jsx("input",{ref:Ae,type:"file",accept:r.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ve=>{pt(ve)}}),g.jsx("input",{ref:Re,type:"file",accept:r.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ve=>{pt(ve)}})]}):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((_,w)=>r[w]!==_)))return i;r=p;let v;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(v=Date.now()),i=t(...p),n.key&&((d=n.debug)!=null&&d.call(n))){const _=Math.round((Date.now()-h)*100)/100,w=Math.round((Date.now()-v)*100)/100,x=w/16,E=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(_,5)} ms`,`
648
648
  font-size: .6rem;
649
649
  font-weight: bold;
650
650
  color: hsl(${Math.max(0,Math.min(120-120*x,120))}deg 100% 31%);`,n==null?void 0:n.key)}return n!=null&&n.onChange&&!(s&&n.skipInitialOnChange)&&n.onChange(i),s=!1,i}return o.updateDeps=l=>{r=l},o}function sO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Yve=(e,t)=>Math.abs(e-t)<1.01,Kve=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},oO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Gve=e=>e,Xve=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},Zve=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const i=o=>{const{width:l,height:u}=o;t({width:Math.round(l),height:Math.round(u)})};if(i(oO(n)),!r.ResizeObserver)return()=>{};const s=new r.ResizeObserver(o=>{const l=()=>{const u=o[0];if(u!=null&&u.borderBoxSize){const d=u.borderBoxSize[0];if(d){i({width:d.inlineSize,height:d.blockSize});return}}i(oO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},aO={passive:!0},lO=typeof window>"u"?!0:"onscrollend"in window,Qve=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&lO?()=>{}:Kve(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=h=>()=>{const{horizontal:p,isRtl:y}=e.options;i=p?n.scrollLeft*(y&&-1||1):n.scrollTop,s(),t(i,h)},l=o(!0),u=o(!1);n.addEventListener("scroll",l,aO);const d=e.options.useScrollendEvent&&lO;return d&&n.addEventListener("scrollend",u,aO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},Jve=(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"]},eye=(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 tye{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:Gve,rangeExtractor:Xve,onChange:()=>{},measureElement:Jve,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...n}},this.notify=n=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,n)},this.maybeNotify=gu(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,s)=>{this.scrollAdjustments=0,this.scrollDirection=s?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=s,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(n,r)=>{const i=new Map,s=new Map;for(let o=r-1;o>=0;o--){const l=n[o];if(i.has(l.lane))continue;const u=s.get(l.lane);if(u==null||l.end>u.end?s.set(l.lane,l):l.end<u.end&&i.set(l.lane,!0),i.size===this.options.lanes)break}return s.size===this.options.lanes?Array.from(s.values()).sort((o,l)=>o.end===l.end?o.index-l.index:o.end-l.end)[0]:void 0},this.getMeasurementOptions=gu(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(n,r,i,s,o,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:i,getItemKey:s,enabled:o,lanes:l,laneAssignmentMode:u}),{key:!1}),this.getMeasurements=gu(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:i,getItemKey:s,enabled:o,lanes:l,laneAssignmentMode:u},d)=>{if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const v of this.laneAssignments.keys())v>=n&&this.laneAssignments.delete(v);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(v=>{this.itemSizeCache.set(v.key,v.size)}));const h=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1);const p=this.measurementsCache.slice(0,h),y=new Array(l).fill(void 0);for(let v=0;v<h;v++){const _=p[v];_&&(y[_.lane]=v)}for(let v=h;v<n;v++){const _=s(v),w=this.laneAssignments.get(v);let x,E;const k=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){x=w;const T=y[x],H=T!==void 0?p[T]:void 0;E=H?H.end+this.options.gap:r+i}else{const T=this.options.lanes===1?p[v-1]:this.getFurthestMeasurement(p,v);E=T?T.end+this.options.gap:r+i,x=T?T.lane:v%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(v,x)}const R=d.get(_),A=typeof R=="number"?R:this.options.estimateSize(v),I=E+A;p[v]={index:v,start:E,size:A,end:I,key:_,lane:x},y[x]=v}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=gu(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?nye({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 sO(r[U4(0,r.length-1,i=>sO(r[i]).start,n)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(n,r,i=0)=>{if(!this.scrollElement)return 0;const s=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=n>=o+s?"end":"start"),r==="center"?n+=(i-s)/2:r==="end"&&(n-=s);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.getSize(),s=this.getScrollOffset(),o=this.measurementsCache[n];if(!o)return;if(r==="auto")if(o.end>=s+i-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,o.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:i="auto"}={})=>{const s=this.getOffsetForAlignment(n,r),o=this.now();this.scrollState={index:null,align:r,behavior:i,startedAt:o,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:i="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const s=this.getOffsetForIndex(n,r);if(!s)return;const[o,l]=s,u=this.now();this.scrollState={index:n,align:l,behavior:i,startedAt:u,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const i=this.getScrollOffset()+n,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((n=r[r.length-1])==null?void 0:n.end)??0;else{const s=Array(this.options.lanes).fill(null);let o=r.length-1;for(;o>=0&&s.some(l=>l===null);){const l=r[o];s[l.lane]===null&&(s[l.lane]=l.end),o--}i=Math.max(...s.filter(l=>l!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:r,behavior:i})=>{this.options.scrollToFn(n,{behavior:i,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(t)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=r?r[0]:this.scrollState.lastTargetOffset,s=1,o=i!==this.scrollState.lastTargetOffset;if(!o&&Yve(i,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.scrollState=null;return}}else this.scrollState.stableFrames=0,o&&(this.scrollState.lastTargetOffset=i,this.scrollState.behavior="auto",this._scrollToOffset(i,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const U4=(e,t,n,r)=>{for(;e<=t;){const i=(e+t)/2|0,s=n(i);if(s<r)e=i+1;else if(s>r)t=i-1;else return i}return e>0?e-1:0};function nye({measurements:e,outerSize:t,scrollOffset:n,lanes:r}){const i=e.length-1,s=u=>e[u].start;if(e.length<=r)return{startIndex:0,endIndex:i};let o=U4(0,i,s,n),l=o;if(r===1)for(;l<i&&e[l].end<n+t;)l++;else if(r>1){const u=Array(r).fill(0);for(;l<i&&u.some(h=>h<n+t);){const h=e[l];u[h.lane]=h.end,l++}const d=Array(r).fill(n+t);for(;o>=0&&d.some(h=>h>=n);){const h=e[o];d[h.lane]=h.start,o--}o=Math.max(0,o-o%r),l=Math.min(i,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}const cO=typeof document<"u"?b.useLayoutEffect:b.useEffect;function rye({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?rd.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new tye(r));return i.setOptions(r),cO(()=>i._didMount(),[]),cO(()=>i._willUpdate()),i}function iye(e){return rye({observeElementRect:Zve,observeElementOffset:Qve,scrollToFn:eye,...e})}function sye(e){return e.kind==="diff"}const oye=12e4;function uO(e){return e?e.replace(/\r\n?/gu,`