@dev-anywhere/relay 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -497,7 +497,7 @@ ${t}`:e:t}function Ib(e,t,n){const r=jg(t),i=jg(n);return!r&&!i?null:{kind:"diff
497
497
 
498
498
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
499
499
 
500
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},vJ="DialogDescriptionWarning",yJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${bI(vJ).contentName}}.`;return _.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},e1=oI,_J=lI,t1=uI,n1=dI,r1=hI,wI=pI,SI=gI,i1=yI;function bJ(e){const t=_.useRef({value:e,previous:e});return _.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function wJ(e){const[t,n]=_.useState(void 0);return Ti(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const u=s.borderBoxSize,d=Array.isArray(u)?u[0]:u;o=d.inlineSize,l=d.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const SJ=["top","right","bottom","left"],cl=Math.min,hs=Math.max,$g=Math.round,Lm=Math.floor,Eo=e=>({x:e,y:e}),xJ={left:"right",right:"left",bottom:"top",top:"bottom"};function C0(e,t,n){return hs(e,cl(t,n))}function sa(e,t){return typeof e=="function"?e(t):e}function oa(e){return e.split("-")[0]}function sd(e){return e.split("-")[1]}function s1(e){return e==="x"?"y":"x"}function o1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function a1(e){return s1(So(e))}function EJ(e,t,n){n===void 0&&(n=!1);const r=sd(e),i=a1(e),s=o1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Hg(o)),[o,Hg(o)]}function CJ(e){const t=Hg(e);return[k0(e),t,k0(t)]}function k0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gN=["left","right"],vN=["right","left"],kJ=["top","bottom"],TJ=["bottom","top"];function RJ(e,t,n){switch(e){case"top":case"bottom":return n?t?vN:gN:t?gN:vN;case"left":case"right":return t?kJ:TJ;default:return[]}}function AJ(e,t,n,r){const i=sd(e);let s=RJ(oa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(k0)))),s}function Hg(e){const t=oa(e);return xJ[t]+e.slice(t.length)}function NJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function xI(e){return typeof e!="number"?NJ(e):{top:e,right:e,bottom:e,left:e}}function Ug(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function yN(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=a1(t),l=o1(o),u=oa(t),d=s==="y",h=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:p};break;case"left":g={x:r.x-i.width,y:p};break;default:g={x:r.x,y:r.y}}switch(sd(t)){case"start":g[o]-=y*(n&&d?-1:1);break;case"end":g[o]+=y*(n&&d?-1:1);break}return g}async function MJ(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:p="floating",altBoundary:y=!1,padding:g=0}=sa(t,e),b=xI(g),x=l[y?p==="floating"?"reference":"floating":p],E=Ug(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),R=await(s.isElement==null?void 0:s.isElement(T))?await(s.getScale==null?void 0:s.getScale(T))||{x:1,y:1}:{x:1,y:1},z=Ug(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:T,strategy:u}):k);return{top:(E.top-z.top+b.top)/R.y,bottom:(z.bottom-E.bottom+b.bottom)/R.y,left:(E.left-z.left+b.left)/R.x,right:(z.right-E.right+b.right)/R.x}}const OJ=50,DJ=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:MJ},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=yN(d,r,u),y=r,g=0;const b={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:T,y:R,data:z,reset:N}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:b,rects:d,platform:l,elements:{reference:e,floating:t}});h=T??h,p=R??p,b[E]={...b[E],...z},N&&g<OJ&&(g++,typeof N=="object"&&(N.placement&&(y=N.placement),N.rects&&(d=N.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:h,y:p}=yN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:b}},PJ=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=sa(e,t)||{};if(d==null)return{};const p=xI(h),y={x:n,y:r},g=a1(i),b=o1(g),w=await o.getDimensions(d),x=g==="y",E=x?"top":"left",k=x?"bottom":"right",T=x?"clientHeight":"clientWidth",R=s.reference[b]+s.reference[g]-y[g]-s.floating[b],z=y[g]-s.reference[g],N=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let $=N?N[T]:0;(!$||!await(o.isElement==null?void 0:o.isElement(N)))&&($=l.floating[T]||s.floating[b]);const P=R/2-z/2,q=$/2-w[b]/2-1,H=cl(p[E],q),U=cl(p[k],q),O=H,M=$-w[b]-U,I=$/2-w[b]/2+P,L=C0(O,I,M),D=!u.arrow&&sd(i)!=null&&I!==L&&s.reference[b]/2-(I<O?H:U)-w[b]/2<0,Y=D?I<O?I-O:I-M:0;return{[g]:y[g]+Y,data:{[g]:L,centerOffset:I-L-Y,...D&&{alignmentOffset:Y}},reset:D}}}),LJ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:w=!0,...x}=sa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=oa(i),k=So(l),T=oa(l)===l,R=await(u.isRTL==null?void 0:u.isRTL(d.floating)),z=y||(T||!w?[Hg(l)]:CJ(l)),N=b!=="none";!y&&N&&z.push(...AJ(l,w,b,R));const $=[l,...z],P=await u.detectOverflow(t,x),q=[];let H=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&q.push(P[E]),p){const I=EJ(i,o,R);q.push(P[I[0]],P[I[1]])}if(H=[...H,{placement:i,overflows:q}],!q.every(I=>I<=0)){var U,O;const I=(((U=s.flip)==null?void 0:U.index)||0)+1,L=$[I];if(L&&(!(p==="alignment"?k!==So(L):!1)||H.every(K=>So(K.placement)===k?K.overflows[0]>0:!0)))return{data:{index:I,overflows:H},reset:{placement:L}};let D=(O=H.filter(Y=>Y.overflows[0]<=0).sort((Y,K)=>Y.overflows[1]-K.overflows[1])[0])==null?void 0:O.placement;if(!D)switch(g){case"bestFit":{var M;const Y=(M=H.filter(K=>{if(N){const F=So(K.placement);return F===k||F==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(F=>F>0).reduce((F,A)=>F+A,0)]).sort((K,F)=>K[1]-F[1])[0])==null?void 0:M[0];Y&&(D=Y);break}case"initialPlacement":D=l;break}if(i!==D)return{reset:{placement:D}}}return{}}}};function _N(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function bN(e){return SJ.some(t=>e[t]>=0)}const IJ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=sa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=_N(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:bN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=_N(o,n.floating);return{data:{escapedOffsets:l,escaped:bN(l)}}}default:return{}}}}},EI=new Set(["left","top"]);async function zJ(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=oa(n),l=sd(n),u=So(n)==="y",d=EI.has(o)?-1:1,h=s&&u?-1:1,p=sa(t,e);let{mainAxis:y,crossAxis:g,alignmentAxis:b}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof b=="number"&&(g=l==="end"?b*-1:b),u?{x:g*h,y:y*d}:{x:y*d,y:g*h}}const BJ=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 zJ(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}}}}},jJ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:E=>{let{x:k,y:T}=E;return{x:k,y:T}}},...d}=sa(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=So(oa(i)),g=s1(y);let b=h[g],w=h[y];if(o){const E=g==="y"?"top":"left",k=g==="y"?"bottom":"right",T=b+p[E],R=b-p[k];b=C0(T,b,R)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[E],R=w-p[k];w=C0(T,w,R)}const x=u.fn({...t,[g]:b,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[g]:o,[y]:l}}}}}},FJ=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:u=!0,crossAxis:d=!0}=sa(e,t),h={x:n,y:r},p=So(i),y=s1(p);let g=h[y],b=h[p];const w=sa(l,t),x=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const T=y==="y"?"height":"width",R=s.reference[y]-s.floating[T]+x.mainAxis,z=s.reference[y]+s.reference[T]-x.mainAxis;g<R?g=R:g>z&&(g=z)}if(d){var E,k;const T=y==="y"?"width":"height",R=EI.has(oa(i)),z=s.reference[p]-s.floating[T]+(R&&((E=o.offset)==null?void 0:E[p])||0)+(R?0:x.crossAxis),N=s.reference[p]+s.reference[T]+(R?0:((k=o.offset)==null?void 0:k[p])||0)-(R?x.crossAxis:0);b<z?b=z:b>N&&(b=N)}return{[y]:g,[p]:b}}}},$J=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:u=()=>{},...d}=sa(e,t),h=await o.detectOverflow(t,d),p=oa(i),y=sd(i),g=So(i)==="y",{width:b,height:w}=s.floating;let x,E;p==="top"||p==="bottom"?(x=p,E=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(E=p,x=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,T=b-h.left-h.right,R=cl(w-h[x],k),z=cl(b-h[E],T),N=!t.middlewareData.shift;let $=R,P=z;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&($=k),N&&!y){const H=hs(h.left,0),U=hs(h.right,0),O=hs(h.top,0),M=hs(h.bottom,0);g?P=b-2*(H!==0||U!==0?H+U:hs(h.left,h.right)):$=w-2*(O!==0||M!==0?O+M:hs(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:$});const q=await o.getDimensions(l.floating);return b!==q.width||w!==q.height?{reset:{rects:!0}}:{}}}};function Nv(){return typeof window<"u"}function od(e){return CI(e)?(e.nodeName||"").toLowerCase():"#document"}function fs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function No(e){var t;return(t=(CI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function CI(e){return Nv()?e instanceof Node||e instanceof fs(e).Node:!1}function Xs(e){return Nv()?e instanceof Element||e instanceof fs(e).Element:!1}function la(e){return Nv()?e instanceof HTMLElement||e instanceof fs(e).HTMLElement:!1}function wN(e){return!Nv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof fs(e).ShadowRoot}function Lf(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Zs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function HJ(e){return/^(table|td|th)$/.test(od(e))}function Mv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const UJ=/transform|translate|scale|rotate|perspective|filter/,WJ=/paint|layout|strict|content/,Wl=e=>!!e&&e!=="none";let Wb;function l1(e){const t=Xs(e)?Zs(e):e;return Wl(t.transform)||Wl(t.translate)||Wl(t.scale)||Wl(t.rotate)||Wl(t.perspective)||!c1()&&(Wl(t.backdropFilter)||Wl(t.filter))||UJ.test(t.willChange||"")||WJ.test(t.contain||"")}function qJ(e){let t=ul(e);for(;la(t)&&!Wu(t);){if(l1(t))return t;if(Mv(t))return null;t=ul(t)}return null}function c1(){return Wb==null&&(Wb=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Wb}function Wu(e){return/^(html|body|#document)$/.test(od(e))}function Zs(e){return fs(e).getComputedStyle(e)}function Ov(e){return Xs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ul(e){if(od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||wN(e)&&e.host||No(e);return wN(t)?t.host:t}function kI(e){const t=ul(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:la(t)&&Lf(t)?t:kI(t)}function hf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=kI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=fs(i);if(s){const l=T0(o);return t.concat(o,o.visualViewport||[],Lf(i)?i:[],l&&n?hf(l):[])}else return t.concat(i,hf(i,[],n))}function T0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function TI(e){const t=Zs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=la(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=$g(n)!==s||$g(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function u1(e){return Xs(e)?e:e.contextElement}function Bu(e){const t=u1(e);if(!la(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=TI(t);let o=(s?$g(n.width):n.width)/r,l=(s?$g(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const VJ=Eo(0);function RI(e){const t=fs(e);return!c1()||!t.visualViewport?VJ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function YJ(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==fs(e)?!1:t}function lc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=u1(e);let o=Eo(1);t&&(r?Xs(r)&&(o=Bu(r)):o=Bu(e));const l=YJ(s,n,r)?RI(s):Eo(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,h=i.width/o.x,p=i.height/o.y;if(s){const y=fs(s),g=r&&Xs(r)?fs(r):r;let b=y,w=T0(b);for(;w&&r&&g!==b;){const x=Bu(w),E=w.getBoundingClientRect(),k=Zs(w),T=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,R=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=T,d+=R,b=fs(w),w=T0(b)}}return Ug({width:h,height:p,x:u,y:d})}function Dv(e,t){const n=Ov(e).scrollLeft;return t?t.left+n:lc(No(e)).left+n}function AI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Dv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function KJ(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Mv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=Eo(1);const h=Eo(0),p=la(r);if((p||!p&&!s)&&((od(r)!=="body"||Lf(o))&&(u=Ov(r)),p)){const g=lc(r);d=Bu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const y=o&&!p&&!s?AI(o,u):Eo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function GJ(e){return Array.from(e.getClientRects())}function XJ(e){const t=No(e),n=Ov(e),r=e.ownerDocument.body,i=hs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=hs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Dv(e);const l=-n.scrollTop;return Zs(r).direction==="rtl"&&(o+=hs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const SN=25;function ZJ(e,t){const n=fs(e),r=No(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=c1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Dv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),g=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,b=Math.abs(r.clientWidth-p.clientWidth-g);b<=SN&&(s-=b)}else d<=SN&&(s+=d);return{width:s,height:o,x:l,y:u}}function QJ(e,t){const n=lc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=la(e)?Bu(e):Eo(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function xN(e,t,n){let r;if(t==="viewport")r=ZJ(e,n);else if(t==="document")r=XJ(No(e));else if(Xs(t))r=QJ(t,n);else{const i=RI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ug(r)}function NI(e,t){const n=ul(e);return n===t||!Xs(n)||Wu(n)?!1:Zs(n).position==="fixed"||NI(n,t)}function JJ(e,t){const n=t.get(e);if(n)return n;let r=hf(e,[],!1).filter(l=>Xs(l)&&od(l)!=="body"),i=null;const s=Zs(e).position==="fixed";let o=s?ul(e):e;for(;Xs(o)&&!Wu(o);){const l=Zs(o),u=l1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Lf(o)&&!u&&NI(e,o))?r=r.filter(h=>h!==o):i=l,o=ul(o)}return t.set(e,r),r}function eee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Mv(t)?[]:JJ(t,this._c):[].concat(n),r],l=xN(t,o[0],i);let u=l.top,d=l.right,h=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const g=xN(t,o[y],i);u=hs(g.top,u),d=cl(g.right,d),h=cl(g.bottom,h),p=hs(g.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function tee(e){const{width:t,height:n}=TI(e);return{width:t,height:n}}function nee(e,t,n){const r=la(t),i=No(t),s=n==="fixed",o=lc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=Eo(0);function d(){u.x=Dv(i)}if(r||!r&&!s)if((od(t)!=="body"||Lf(i))&&(l=Ov(t)),r){const g=lc(t,!0,s,t);u.x=g.x+t.clientLeft,u.y=g.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?AI(i,l):Eo(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function qb(e){return Zs(e).position==="static"}function EN(e,t){if(!la(e)||Zs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return No(e)===n&&(n=n.ownerDocument.body),n}function MI(e,t){const n=fs(e);if(Mv(e))return n;if(!la(e)){let i=ul(e);for(;i&&!Wu(i);){if(Xs(i)&&!qb(i))return i;i=ul(i)}return n}let r=EN(e,t);for(;r&&HJ(r)&&qb(r);)r=EN(r,t);return r&&Wu(r)&&qb(r)&&!l1(r)?n:r||qJ(e)||n}const ree=async function(e){const t=this.getOffsetParent||MI,n=this.getDimensions,r=await n(e.floating);return{reference:nee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function iee(e){return Zs(e).direction==="rtl"}const see={convertOffsetParentRelativeRectToViewportRelativeRect:KJ,getDocumentElement:No,getClippingRect:eee,getOffsetParent:MI,getElementRects:ree,getClientRects:GJ,getDimensions:tee,getScale:Bu,isElement:Xs,isRTL:iee};function OI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function oee(e,t){let n=null,r;const i=No(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:h,top:p,width:y,height:g}=d;if(l||t(),!y||!g)return;const b=Lm(p),w=Lm(i.clientWidth-(h+y)),x=Lm(i.clientHeight-(p+g)),E=Lm(h),T={rootMargin:-b+"px "+-w+"px "+-x+"px "+-E+"px",threshold:hs(0,cl(1,u))||1};let R=!0;function z(N){const $=N[0].intersectionRatio;if($!==u){if(!R)return o();$?o(!1,$):r=setTimeout(()=>{o(!1,1e-7)},1e3)}$===1&&!OI(d,e.getBoundingClientRect())&&o(),R=!1}try{n=new IntersectionObserver(z,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(z,T)}n.observe(e)}return o(!0),s}function aee(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=u1(e),h=i||s?[...d?hf(d):[],...t?hf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?oee(d,n):null;let y=-1,g=null;o&&(g=new ResizeObserver(E=>{let[k]=E;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var T;(T=g)==null||T.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let b,w=u?lc(e):null;u&&x();function x(){const E=lc(e);w&&!OI(w,E)&&n(),w=E,b=requestAnimationFrame(x)}return n(),()=>{var E;h.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(E=g)==null||E.disconnect(),g=null,u&&cancelAnimationFrame(b)}}const lee=BJ,cee=jJ,uee=LJ,dee=$J,hee=IJ,CN=PJ,fee=FJ,pee=(e,t,n)=>{const r=new Map,i={platform:see,...n},s={...i.platform,_c:r};return DJ(e,t,{...i,platform:s})};var mee=typeof document<"u",gee=function(){},mg=mee?_.useLayoutEffect:gee;function Wg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Wg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!Wg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function DI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kN(e,t){const n=DI(e);return Math.round(t*n)/n}function Vb(e){const t=_.useRef(e);return mg(()=>{t.current=e}),t}function vee(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,p]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,g]=_.useState(r);Wg(y,r)||g(r);const[b,w]=_.useState(null),[x,E]=_.useState(null),k=_.useCallback(K=>{K!==N.current&&(N.current=K,w(K))},[]),T=_.useCallback(K=>{K!==$.current&&($.current=K,E(K))},[]),R=s||b,z=o||x,N=_.useRef(null),$=_.useRef(null),P=_.useRef(h),q=u!=null,H=Vb(u),U=Vb(i),O=Vb(d),M=_.useCallback(()=>{if(!N.current||!$.current)return;const K={placement:t,strategy:n,middleware:y};U.current&&(K.platform=U.current),pee(N.current,$.current,K).then(F=>{const A={...F,isPositioned:O.current!==!1};I.current&&!Wg(P.current,A)&&(P.current=A,nd.flushSync(()=>{p(A)}))})},[y,t,n,U,O]);mg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[d]);const I=_.useRef(!1);mg(()=>(I.current=!0,()=>{I.current=!1}),[]),mg(()=>{if(R&&(N.current=R),z&&($.current=z),R&&z){if(H.current)return H.current(R,z,M);M()}},[R,z,M,H,q]);const L=_.useMemo(()=>({reference:N,floating:$,setReference:k,setFloating:T}),[k,T]),D=_.useMemo(()=>({reference:R,floating:z}),[R,z]),Y=_.useMemo(()=>{const K={position:n,left:0,top:0};if(!D.floating)return K;const F=kN(D.floating,h.x),A=kN(D.floating,h.y);return l?{...K,transform:"translate("+F+"px, "+A+"px)",...DI(D.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:A}},[n,l,D.floating,h.x,h.y]);return _.useMemo(()=>({...h,update:M,refs:L,elements:D,floatingStyles:Y}),[h,M,L,D,Y])}const yee=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?CN({element:r.current,padding:i}).fn(n):{}:r?CN({element:r,padding:i}).fn(n):{}}}},_ee=(e,t)=>{const n=lee(e);return{name:n.name,fn:n.fn,options:[e,t]}},bee=(e,t)=>{const n=cee(e);return{name:n.name,fn:n.fn,options:[e,t]}},wee=(e,t)=>({fn:fee(e).fn,options:[e,t]}),See=(e,t)=>{const n=uee(e);return{name:n.name,fn:n.fn,options:[e,t]}},xee=(e,t)=>{const n=dee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eee=(e,t)=>{const n=hee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cee=(e,t)=>{const n=yee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var kee="Arrow",PI=_.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return v.jsx(Xt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:v.jsx("polygon",{points:"0,0 30,0 15,10"})})});PI.displayName=kee;var Tee=PI,d1="Popper",[LI,bl]=aa(d1),[Ree,II]=LI(d1),zI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return v.jsx(Ree,{scope:t,anchor:r,onAnchorChange:i,children:n})};zI.displayName=d1;var BI="PopperAnchor",jI=_.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=II(BI,n),o=_.useRef(null),l=Bn(t,o),u=_.useRef(null);return _.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:v.jsx(Xt.div,{...i,ref:l})});jI.displayName=BI;var h1="PopperContent",[Aee,Nee]=LI(h1),FI=_.forwardRef((e,t)=>{var te,he,ge,Ee,Re,Ie;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:g="optimized",onPlaced:b,...w}=e,x=II(h1,n),[E,k]=_.useState(null),T=Bn(t,Ye=>k(Ye)),[R,z]=_.useState(null),N=wJ(R),$=(N==null?void 0:N.width)??0,P=(N==null?void 0:N.height)??0,q=r+(s!=="center"?"-"+s:""),H=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},U=Array.isArray(d)?d:[d],O=U.length>0,M={padding:H,boundary:U.filter(Oee),altBoundary:O},{refs:I,floatingStyles:L,placement:D,isPositioned:Y,middlewareData:K}=vee({strategy:"fixed",placement:q,whileElementsMounted:(...Ye)=>aee(...Ye,{animationFrame:g==="always"}),elements:{reference:x.anchor},middleware:[_ee({mainAxis:i+P,alignmentAxis:o}),u&&bee({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?wee():void 0,...M}),u&&See({...M}),xee({...M,apply:({elements:Ye,rects:gt,availableWidth:Me,availableHeight:de})=>{const{width:oe,height:ye}=gt.reference,we=Ye.floating.style;we.setProperty("--radix-popper-available-width",`${Me}px`),we.setProperty("--radix-popper-available-height",`${de}px`),we.setProperty("--radix-popper-anchor-width",`${oe}px`),we.setProperty("--radix-popper-anchor-height",`${ye}px`)}}),R&&Cee({element:R,padding:l}),Dee({arrowWidth:$,arrowHeight:P}),y&&Eee({strategy:"referenceHidden",...M})]}),[F,A]=UI(D),W=To(b);Ti(()=>{Y&&(W==null||W())},[Y,W]);const G=(te=K.arrow)==null?void 0:te.x,B=(he=K.arrow)==null?void 0:he.y,ne=((ge=K.arrow)==null?void 0:ge.centerOffset)!==0,[ie,se]=_.useState();return Ti(()=>{E&&se(window.getComputedStyle(E).zIndex)},[E]),v.jsx("div",{ref:I.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:Y?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ie,"--radix-popper-transform-origin":[(Ee=K.transformOrigin)==null?void 0:Ee.x,(Re=K.transformOrigin)==null?void 0:Re.y].join(" "),...((Ie=K.hide)==null?void 0:Ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:v.jsx(Aee,{scope:n,placedSide:F,onArrowChange:z,arrowX:G,arrowY:B,shouldHideArrow:ne,children:v.jsx(Xt.div,{"data-side":F,"data-align":A,...w,ref:T,style:{...w.style,animation:Y?void 0:"none"}})})})});FI.displayName=h1;var $I="PopperArrow",Mee={top:"bottom",right:"left",bottom:"top",left:"right"},HI=_.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Nee($I,r),o=Mee[s.placedSide];return v.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:v.jsx(Tee,{...i,ref:n,style:{...i.style,display:"block"}})})});HI.displayName=$I;function Oee(e){return e!==null}var Dee=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]=UI(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let b="",w="";return d==="bottom"?(b=o?p:`${y}px`,w=`${-u}px`):d==="top"?(b=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(b=`${-u}px`,w=o?p:`${g}px`):d==="left"&&(b=`${r.floating.width+u}px`,w=o?p:`${g}px`),{data:{x:b,y:w}}}});function UI(e){const[t,n="center"]=e.split("-");return[t,n]}var Pv=zI,If=jI,Lv=FI,Iv=HI,Yb="rovingFocusGroup.onEntryFocus",Pee={bubbles:!1,cancelable:!0},zf="RovingFocusGroup",[R0,WI,Lee]=Gx(zf),[Iee,qI]=aa(zf,[Lee]),[zee,Bee]=Iee(zf),VI=_.forwardRef((e,t)=>v.jsx(R0.Provider,{scope:e.__scopeRovingFocusGroup,children:v.jsx(R0.Slot,{scope:e.__scopeRovingFocusGroup,children:v.jsx(jee,{...e,ref:t})})}));VI.displayName=zf;var jee=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...p}=e,y=_.useRef(null),g=Bn(t,y),b=Xx(s),[w,x]=oc({prop:o,defaultProp:l??null,onChange:u,caller:zf}),[E,k]=_.useState(!1),T=To(d),R=WI(n),z=_.useRef(!1),[N,$]=_.useState(0);return _.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(Yb,T),()=>P.removeEventListener(Yb,T)},[T]),v.jsx(zee,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:w,onItemFocus:_.useCallback(P=>x(P),[x]),onItemShiftTab:_.useCallback(()=>k(!0),[]),onFocusableItemAdd:_.useCallback(()=>$(P=>P+1),[]),onFocusableItemRemove:_.useCallback(()=>$(P=>P-1),[]),children:v.jsx(Xt.div,{tabIndex:E||N===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:yt(e.onMouseDown,()=>{z.current=!0}),onFocus:yt(e.onFocus,P=>{const q=!z.current;if(P.target===P.currentTarget&&q&&!E){const H=new CustomEvent(Yb,Pee);if(P.currentTarget.dispatchEvent(H),!H.defaultPrevented){const U=R().filter(D=>D.focusable),O=U.find(D=>D.active),M=U.find(D=>D.id===w),L=[O,M,...U].filter(Boolean).map(D=>D.ref.current);GI(L,h)}}z.current=!1}),onBlur:yt(e.onBlur,()=>k(!1))})})}),YI="RovingFocusGroupItem",KI=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=Bee(YI,n),p=h.currentTabStopId===d,y=WI(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:w}=h;return _.useEffect(()=>{if(r)return g(),()=>b()},[r,g,b]),v.jsx(R0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:v.jsx(Xt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:yt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:yt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:yt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=Hee(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let T=y().filter(R=>R.focusable).map(R=>R.ref.current);if(E==="last")T.reverse();else if(E==="prev"||E==="next"){E==="prev"&&T.reverse();const R=T.indexOf(x.currentTarget);T=h.loop?Uee(T,R+1):T.slice(R+1)}setTimeout(()=>GI(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});KI.displayName=YI;var Fee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function $ee(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Hee(e,t,n){const r=$ee(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Fee[r]}function GI(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Uee(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Wee=VI,qee=KI,A0=["Enter"," "],Vee=["ArrowDown","PageUp","Home"],XI=["ArrowUp","PageDown","End"],Yee=[...Vee,...XI],Kee={ltr:[...A0,"ArrowRight"],rtl:[...A0,"ArrowLeft"]},Gee={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Bf="Menu",[ff,Xee,Zee]=Gx(Bf),[bc,ZI]=aa(Bf,[Zee,bl,qI]),zv=bl(),QI=qI(),[Qee,wc]=bc(Bf),[Jee,jf]=bc(Bf),JI=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=zv(t),[u,d]=_.useState(null),h=_.useRef(!1),p=To(s),y=Xx(i);return _.useEffect(()=>{const g=()=>{h.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>h.current=!1;return document.addEventListener("keydown",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),v.jsx(Pv,{...l,children:v.jsx(Qee,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:v.jsx(Jee,{scope:t,onClose:_.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};JI.displayName=Bf;var ete="MenuAnchor",f1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(If,{...i,...r,ref:t})});f1.displayName=ete;var p1="MenuPortal",[tte,ez]=bc(p1,{forceMount:void 0}),tz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=wc(p1,t);return v.jsx(tte,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};tz.displayName=p1;var Ds="MenuContent",[nte,m1]=bc(Ds),nz=_.forwardRef((e,t)=>{const n=ez(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:o.modal?v.jsx(rte,{...i,ref:t}):v.jsx(ite,{...i,ref:t})})})})}),rte=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu),r=_.useRef(null),i=Bn(t,r);return _.useEffect(()=>{const s=r.current;if(s)return Rv(s)},[]),v.jsx(g1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ite=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu);return v.jsx(g1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ste=ll("MenuContent.ScrollLock"),g1=_.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:g,disableOutsideScroll:b,...w}=e,x=wc(Ds,n),E=jf(Ds,n),k=zv(n),T=QI(n),R=Xee(n),[z,N]=_.useState(null),$=_.useRef(null),P=Bn(t,$,x.onContentChange),q=_.useRef(0),H=_.useRef(""),U=_.useRef(0),O=_.useRef(null),M=_.useRef("right"),I=_.useRef(0),L=b?Pf:_.Fragment,D=b?{as:ste,allowPinchZoom:!0}:void 0,Y=F=>{var te,he;const A=H.current+F,W=R().filter(ge=>!ge.disabled),G=document.activeElement,B=(te=W.find(ge=>ge.ref.current===G))==null?void 0:te.textValue,ne=W.map(ge=>ge.textValue),ie=vte(ne,A,B),se=(he=W.find(ge=>ge.textValue===ie))==null?void 0:he.ref.current;(function ge(Ee){H.current=Ee,window.clearTimeout(q.current),Ee!==""&&(q.current=window.setTimeout(()=>ge(""),1e3))})(A),se&&setTimeout(()=>se.focus())};_.useEffect(()=>()=>window.clearTimeout(q.current),[]),kv();const K=_.useCallback(F=>{var W,G;return M.current===((W=O.current)==null?void 0:W.side)&&_te(F,(G=O.current)==null?void 0:G.area)},[]);return v.jsx(nte,{scope:n,searchRef:H,onItemEnter:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),onItemLeave:_.useCallback(F=>{var A;K(F)||((A=$.current)==null||A.focus(),N(null))},[K]),onTriggerLeave:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),pointerGraceTimerRef:U,onPointerGraceIntentChange:_.useCallback(F=>{O.current=F},[]),children:v.jsx(L,{...D,children:v.jsx(Df,{asChild:!0,trapped:i,onMountAutoFocus:yt(s,F=>{var A;F.preventDefault(),(A=$.current)==null||A.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:g,children:v.jsx(Wee,{asChild:!0,...T,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:z,onCurrentTabStopIdChange:N,onEntryFocus:yt(u,F=>{E.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:v.jsx(Lv,{role:"menu","aria-orientation":"vertical","data-state":yz(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:yt(w.onKeyDown,F=>{const W=F.target.closest("[data-radix-menu-content]")===F.currentTarget,G=F.ctrlKey||F.altKey||F.metaKey,B=F.key.length===1;W&&(F.key==="Tab"&&F.preventDefault(),!G&&B&&Y(F.key));const ne=$.current;if(F.target!==ne||!Yee.includes(F.key))return;F.preventDefault();const se=R().filter(te=>!te.disabled).map(te=>te.ref.current);XI.includes(F.key)&&se.reverse(),mte(se)}),onBlur:yt(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(q.current),H.current="")}),onPointerMove:yt(e.onPointerMove,pf(F=>{const A=F.target,W=I.current!==F.clientX;if(F.currentTarget.contains(A)&&W){const G=F.clientX>I.current?"right":"left";M.current=G,I.current=F.clientX}}))})})})})})})});nz.displayName=Ds;var ote="MenuGroup",v1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Xt.div,{role:"group",...r,ref:t})});v1.displayName=ote;var ate="MenuLabel",rz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Xt.div,{...r,ref:t})});rz.displayName=ate;var qg="MenuItem",TN="menu.itemSelect",Bv=_.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=_.useRef(null),o=jf(qg,e.__scopeMenu),l=m1(qg,e.__scopeMenu),u=Bn(t,s),d=_.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(TN,{bubbles:!0,cancelable:!0});p.addEventListener(TN,g=>r==null?void 0:r(g),{once:!0}),WL(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return v.jsx(iz,{...i,ref:u,disabled:n,onClick:yt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:yt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:yt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||A0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Bv.displayName=qg;var iz=_.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=m1(qg,n),l=QI(n),u=_.useRef(null),d=Bn(t,u),[h,p]=_.useState(!1),[y,g]=_.useState("");return _.useEffect(()=>{const b=u.current;b&&g((b.textContent??"").trim())},[s.children]),v.jsx(ff.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:v.jsx(qee,{asChild:!0,...l,focusable:!r,children:v.jsx(Xt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:yt(e.onPointerMove,pf(b=>{r?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:yt(e.onPointerLeave,pf(b=>o.onItemLeave(b))),onFocus:yt(e.onFocus,()=>p(!0)),onBlur:yt(e.onBlur,()=>p(!1))})})})}),lte="MenuCheckboxItem",sz=_.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return v.jsx(uz,{scope:e.__scopeMenu,checked:n,children:v.jsx(Bv,{role:"menuitemcheckbox","aria-checked":Vg(n)?"mixed":n,...i,ref:t,"data-state":_1(n),onSelect:yt(i.onSelect,()=>r==null?void 0:r(Vg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});sz.displayName=lte;var oz="MenuRadioGroup",[cte,ute]=bc(oz,{value:void 0,onValueChange:()=>{}}),az=_.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return v.jsx(cte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:v.jsx(v1,{...i,ref:t})})});az.displayName=oz;var lz="MenuRadioItem",cz=_.forwardRef((e,t)=>{const{value:n,...r}=e,i=ute(lz,e.__scopeMenu),s=n===i.value;return v.jsx(uz,{scope:e.__scopeMenu,checked:s,children:v.jsx(Bv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_1(s),onSelect:yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});cz.displayName=lz;var y1="MenuItemIndicator",[uz,dte]=bc(y1,{checked:!1}),dz=_.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=dte(y1,n);return v.jsx(Bs,{present:r||Vg(s.checked)||s.checked===!0,children:v.jsx(Xt.span,{...i,ref:t,"data-state":_1(s.checked)})})});dz.displayName=y1;var hte="MenuSeparator",hz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Xt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});hz.displayName=hte;var fte="MenuArrow",fz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(Iv,{...i,...r,ref:t})});fz.displayName=fte;var pte="MenuSub",[Qke,pz]=bc(pte),Ph="MenuSubTrigger",mz=_.forwardRef((e,t)=>{const n=wc(Ph,e.__scopeMenu),r=jf(Ph,e.__scopeMenu),i=pz(Ph,e.__scopeMenu),s=m1(Ph,e.__scopeMenu),o=_.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=_.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return _.useEffect(()=>h,[h]),_.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),v.jsx(f1,{asChild:!0,...d,children:v.jsx(iz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":yz(n.open),...e,ref:ia(t,i.onTriggerChange),onClick:p=>{var y;(y=e.onClick)==null||y.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:yt(e.onPointerMove,pf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:yt(e.onPointerLeave,pf(p=>{var g,b;h();const y=(g=n.content)==null?void 0:g.getBoundingClientRect();if(y){const w=(b=n.content)==null?void 0:b.dataset.side,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],T=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,y:p.clientY},{x:k,y:y.top},{x:T,y:y.top},{x:T,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:yt(e.onKeyDown,p=>{var g;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Kee[r.dir].includes(p.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),p.preventDefault())})})})});mz.displayName=Ph;var gz="MenuSubContent",vz=_.forwardRef((e,t)=>{const n=ez(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu),l=pz(gz,e.__scopeMenu),u=_.useRef(null),d=Bn(t,u);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:v.jsx(g1,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:yt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:yt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:yt(e.onKeyDown,h=>{var g;const p=h.currentTarget.contains(h.target),y=Gee[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),h.preventDefault())})})})})})});vz.displayName=gz;function yz(e){return e?"open":"closed"}function Vg(e){return e==="indeterminate"}function _1(e){return Vg(e)?"indeterminate":e?"checked":"unchecked"}function mte(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function gte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function vte(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=gte(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 yte(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 _te(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return yte(n,t)}function pf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var bte=JI,wte=f1,Ste=tz,xte=nz,Ete=v1,Cte=rz,kte=Bv,Tte=sz,Rte=az,Ate=cz,Nte=dz,Mte=hz,Ote=fz,Dte=mz,Pte=vz,jv="DropdownMenu",[Lte]=aa(jv,[ZI]),ji=ZI(),[Ite,_z]=Lte(jv),bz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=ji(t),d=_.useRef(null),[h,p]=oc({prop:i,defaultProp:s??!1,onChange:o,caller:jv});return v.jsx(Ite,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:_.useCallback(()=>p(y=>!y),[p]),modal:l,children:v.jsx(bte,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};bz.displayName=jv;var wz="DropdownMenuTrigger",Sz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=_z(wz,n),o=ji(n);return v.jsx(wte,{asChild:!0,...o,children:v.jsx(Xt.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:ia(t,s.triggerRef),onPointerDown:yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Sz.displayName=wz;var zte="DropdownMenuPortal",xz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=ji(t);return v.jsx(Ste,{...r,...n})};xz.displayName=zte;var Ez="DropdownMenuContent",Cz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=_z(Ez,n),s=ji(n),o=_.useRef(!1);return v.jsx(xte,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:yt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Cz.displayName=Ez;var Bte="DropdownMenuGroup",jte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ete,{...i,...r,ref:t})});jte.displayName=Bte;var Fte="DropdownMenuLabel",kz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Cte,{...i,...r,ref:t})});kz.displayName=Fte;var $te="DropdownMenuItem",Tz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(kte,{...i,...r,ref:t})});Tz.displayName=$te;var Hte="DropdownMenuCheckboxItem",Rz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Tte,{...i,...r,ref:t})});Rz.displayName=Hte;var Ute="DropdownMenuRadioGroup",Wte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Rte,{...i,...r,ref:t})});Wte.displayName=Ute;var qte="DropdownMenuRadioItem",Vte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ate,{...i,...r,ref:t})});Vte.displayName=qte;var Yte="DropdownMenuItemIndicator",Az=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Nte,{...i,...r,ref:t})});Az.displayName=Yte;var Kte="DropdownMenuSeparator",Nz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Mte,{...i,...r,ref:t})});Nz.displayName=Kte;var Gte="DropdownMenuArrow",Xte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ote,{...i,...r,ref:t})});Xte.displayName=Gte;var Zte="DropdownMenuSubTrigger",Qte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Dte,{...i,...r,ref:t})});Qte.displayName=Zte;var Jte="DropdownMenuSubContent",ene=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Pte,{...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)"}})});ene.displayName=Jte;var tne=bz,nne=Sz,rne=xz,ine=Cz,sne=kz,one=Tz,ane=Rz,lne=Az,cne=Nz;function RN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Fv="Popover",[Mz]=aa(Fv,[bl]),Ff=bl(),[une,wl]=Mz(Fv),Oz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Ff(t),u=_.useRef(null),[d,h]=_.useState(!1),[p,y]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:Fv});return v.jsx(Pv,{...l,children:v.jsx(une,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:_.useCallback(()=>y(g=>!g),[y]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:o,children:n})})};Oz.displayName=Fv;var Dz="PopoverAnchor",dne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Dz,n),s=Ff(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return _.useEffect(()=>(o(),()=>l()),[o,l]),v.jsx(If,{...s,...r,ref:t})});dne.displayName=Dz;var Pz="PopoverTrigger",Lz=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Pz,n),s=Ff(n),o=Bn(t,i.triggerRef),l=v.jsx(Xt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Fz(i.open),...r,ref:o,onClick:yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:v.jsx(If,{asChild:!0,...s,children:l})});Lz.displayName=Pz;var b1="PopoverPortal",[hne,fne]=Mz(b1,{forceMount:void 0}),Iz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=wl(b1,t);return v.jsx(hne,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};Iz.displayName=b1;var qu="PopoverContent",zz=_.forwardRef((e,t)=>{const n=fne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=wl(qu,e.__scopePopover);return v.jsx(Bs,{present:r||s.open,children:s.modal?v.jsx(mne,{...i,ref:t}):v.jsx(gne,{...i,ref:t})})});zz.displayName=qu;var pne=ll("PopoverContent.RemoveScroll"),mne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(null),i=Bn(t,r),s=_.useRef(!1);return _.useEffect(()=>{const o=r.current;if(o)return Rv(o)},[]),v.jsx(Pf,{as:pne,allowPinchZoom:!0,children:v.jsx(Bz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:yt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),gne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return v.jsx(Bz,{...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()}})}),Bz=_.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,...p}=e,y=wl(qu,n),g=Ff(n);return kv(),v.jsx(Df,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:v.jsx(Lv,{"data-state":Fz(y.open),role:"dialog",id:y.contentId,...g,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),jz="PopoverClose",vne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(jz,n);return v.jsx(Xt.button,{type:"button",...r,ref:t,onClick:yt(e.onClick,()=>i.onOpenChange(!1))})});vne.displayName=jz;var yne="PopoverArrow",_ne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Ff(n);return v.jsx(Iv,{...i,...r,ref:t})});_ne.displayName=yne;function Fz(e){return e?"open":"closed"}var bne=Oz,wne=Lz,Sne=Iz,xne=zz,Ene=[" ","Enter","ArrowUp","ArrowDown"],Cne=[" ","Enter"],cc="Select",[$v,Hv,kne]=Gx(cc),[ad]=aa(cc,[kne,bl]),Uv=bl(),[Tne,Sl]=ad(cc),[Rne,Ane]=ad(cc),$z=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:h,autoComplete:p,disabled:y,required:g,form:b}=e,w=Uv(t),[x,E]=_.useState(null),[k,T]=_.useState(null),[R,z]=_.useState(!1),N=Xx(d),[$,P]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:cc}),[q,H]=oc({prop:o,defaultProp:l,onChange:u,caller:cc}),U=_.useRef(null),O=x?b||!!x.closest("form"):!0,[M,I]=_.useState(new Set),L=Array.from(M).map(D=>D.props.value).join(";");return v.jsx(Pv,{...w,children:v.jsxs(Tne,{required:g,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:R,onValueNodeHasChildrenChange:z,contentId:gi(),value:q,onValueChange:H,open:$,onOpenChange:P,dir:N,triggerPointerDownPosRef:U,disabled:y,children:[v.jsx($v.Provider,{scope:t,children:v.jsx(Rne,{scope:e.__scopeSelect,onNativeOptionAdd:_.useCallback(D=>{I(Y=>new Set(Y).add(D))},[]),onNativeOptionRemove:_.useCallback(D=>{I(Y=>{const K=new Set(Y);return K.delete(D),K})},[]),children:n})}),O?v.jsxs(cB,{"aria-hidden":!0,required:g,tabIndex:-1,name:h,autoComplete:p,value:q,onChange:D=>H(D.target.value),disabled:y,form:b,children:[q===void 0?v.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};$z.displayName=cc;var Hz="SelectTrigger",Uz=_.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Uv(n),o=Sl(Hz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Hv(n),h=_.useRef("touch"),[p,y,g]=dB(w=>{const x=d().filter(T=>!T.disabled),E=x.find(T=>T.value===o.value),k=hB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),b=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return v.jsx(If,{asChild:!0,...s,children:v.jsx(Xt.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":uB(o.value)?"":void 0,...i,ref:u,onClick:yt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&b(w)}),onPointerDown:yt(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(b(w),w.preventDefault())}),onKeyDown:yt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&Ene.includes(w.key)&&(b(),w.preventDefault())})})})});Uz.displayName=Hz;var Wz="SelectValue",qz=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=Sl(Wz,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ti(()=>{d(h)},[d,h]),v.jsx(Xt.span,{...l,ref:p,style:{pointerEvents:"none"},children:uB(u.value)?v.jsx(v.Fragment,{children:o}):s})});qz.displayName=Wz;var Nne="SelectIcon",Vz=_.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return v.jsx(Xt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});Vz.displayName=Nne;var Mne="SelectPortal",Yz=e=>v.jsx(id,{asChild:!0,...e});Yz.displayName=Mne;var uc="SelectContent",Kz=_.forwardRef((e,t)=>{const n=Sl(uc,e.__scopeSelect),[r,i]=_.useState();if(Ti(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?nd.createPortal(v.jsx(Gz,{scope:e.__scopeSelect,children:v.jsx($v.Slot,{scope:e.__scopeSelect,children:v.jsx("div",{children:e.children})})}),s):null}return v.jsx(Xz,{...e,ref:t})});Kz.displayName=uc;var qs=10,[Gz,xl]=ad(uc),One="SelectContentImpl",Dne=ll("SelectContent.RemoveScroll"),Xz=_.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:g,sticky:b,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=Sl(uc,n),[T,R]=_.useState(null),[z,N]=_.useState(null),$=Bn(t,te=>R(te)),[P,q]=_.useState(null),[H,U]=_.useState(null),O=Hv(n),[M,I]=_.useState(!1),L=_.useRef(!1);_.useEffect(()=>{if(T)return Rv(T)},[T]),kv();const D=_.useCallback(te=>{const[he,...ge]=O().map(Ie=>Ie.ref.current),[Ee]=ge.slice(-1),Re=document.activeElement;for(const Ie of te)if(Ie===Re||(Ie==null||Ie.scrollIntoView({block:"nearest"}),Ie===he&&z&&(z.scrollTop=0),Ie===Ee&&z&&(z.scrollTop=z.scrollHeight),Ie==null||Ie.focus(),document.activeElement!==Re))return},[O,z]),Y=_.useCallback(()=>D([P,T]),[D,P,T]);_.useEffect(()=>{M&&Y()},[M,Y]);const{onOpenChange:K,triggerPointerDownPosRef:F}=k;_.useEffect(()=>{if(T){let te={x:0,y:0};const he=Ee=>{var Re,Ie;te={x:Math.abs(Math.round(Ee.pageX)-(((Re=F.current)==null?void 0:Re.x)??0)),y:Math.abs(Math.round(Ee.pageY)-(((Ie=F.current)==null?void 0:Ie.y)??0))}},ge=Ee=>{te.x<=10&&te.y<=10?Ee.preventDefault():T.contains(Ee.target)||K(!1),document.removeEventListener("pointermove",he),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",he),document.addEventListener("pointerup",ge,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",he),document.removeEventListener("pointerup",ge,{capture:!0})}}},[T,K,F]),_.useEffect(()=>{const te=()=>K(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[K]);const[A,W]=dB(te=>{const he=O().filter(Re=>!Re.disabled),ge=he.find(Re=>Re.ref.current===document.activeElement),Ee=hB(he,te,ge);Ee&&setTimeout(()=>Ee.ref.current.focus())}),G=_.useCallback((te,he,ge)=>{const Ee=!L.current&&!ge;(k.value!==void 0&&k.value===he||Ee)&&(q(te),Ee&&(L.current=!0))},[k.value]),B=_.useCallback(()=>T==null?void 0:T.focus(),[T]),ne=_.useCallback((te,he,ge)=>{const Ee=!L.current&&!ge;(k.value!==void 0&&k.value===he||Ee)&&U(te)},[k.value]),ie=r==="popper"?N0:Zz,se=ie===N0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:g,sticky:b,hideWhenDetached:w,avoidCollisions:x}:{};return v.jsx(Gz,{scope:n,content:T,viewport:z,onViewportChange:N,itemRefCallback:G,selectedItem:P,onItemLeave:B,itemTextRefCallback:ne,focusSelectedItem:Y,selectedItemText:H,position:r,isPositioned:M,searchRef:A,children:v.jsx(Pf,{as:Dne,allowPinchZoom:!0,children:v.jsx(Df,{asChild:!0,trapped:k.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:yt(i,te=>{var he;(he=k.trigger)==null||he.focus({preventScroll:!0}),te.preventDefault()}),children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:v.jsx(ie,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:te=>te.preventDefault(),...E,...se,onPlaced:()=>I(!0),ref:$,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:yt(E.onKeyDown,te=>{const he=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!he&&te.key.length===1&&W(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let Ee=O().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);if(["ArrowUp","End"].includes(te.key)&&(Ee=Ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const Re=te.target,Ie=Ee.indexOf(Re);Ee=Ee.slice(Ie+1)}setTimeout(()=>D(Ee)),te.preventDefault()}})})})})})})});Xz.displayName=One;var Pne="SelectItemAlignedPosition",Zz=_.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=Sl(uc,n),o=xl(uc,n),[l,u]=_.useState(null),[d,h]=_.useState(null),p=Bn(t,$=>h($)),y=Hv(n),g=_.useRef(!1),b=_.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,T=_.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const $=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),q=s.valueNode.getBoundingClientRect(),H=E.getBoundingClientRect();if(s.dir!=="rtl"){const Re=H.left-P.left,Ie=q.left-Re,Ye=$.left-Ie,gt=$.width+Ye,Me=Math.max(gt,P.width),de=window.innerWidth-qs,oe=RN(Ie,[qs,Math.max(qs,de-Me)]);l.style.minWidth=gt+"px",l.style.left=oe+"px"}else{const Re=P.right-H.right,Ie=window.innerWidth-q.right-Re,Ye=window.innerWidth-$.right-Ie,gt=$.width+Ye,Me=Math.max(gt,P.width),de=window.innerWidth-qs,oe=RN(Ie,[qs,Math.max(qs,de-Me)]);l.style.minWidth=gt+"px",l.style.right=oe+"px"}const U=y(),O=window.innerHeight-qs*2,M=w.scrollHeight,I=window.getComputedStyle(d),L=parseInt(I.borderTopWidth,10),D=parseInt(I.paddingTop,10),Y=parseInt(I.borderBottomWidth,10),K=parseInt(I.paddingBottom,10),F=L+D+M+K+Y,A=Math.min(x.offsetHeight*5,F),W=window.getComputedStyle(w),G=parseInt(W.paddingTop,10),B=parseInt(W.paddingBottom,10),ne=$.top+$.height/2-qs,ie=O-ne,se=x.offsetHeight/2,te=x.offsetTop+se,he=L+D+te,ge=F-he;if(he<=ne){const Re=U.length>0&&x===U[U.length-1].ref.current;l.style.bottom="0px";const Ie=d.clientHeight-w.offsetTop-w.offsetHeight,Ye=Math.max(ie,se+(Re?B:0)+Ie+Y),gt=he+Ye;l.style.height=gt+"px"}else{const Re=U.length>0&&x===U[0].ref.current;l.style.top="0px";const Ye=Math.max(ne,L+w.offsetTop+(Re?G:0)+se)+ge;l.style.height=Ye+"px",w.scrollTop=he-ne+w.offsetTop}l.style.margin=`${qs}px 0`,l.style.minHeight=A+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ti(()=>T(),[T]);const[R,z]=_.useState();Ti(()=>{d&&z(window.getComputedStyle(d).zIndex)},[d]);const N=_.useCallback($=>{$&&b.current===!0&&(T(),k==null||k(),b.current=!1)},[T,k]);return v.jsx(Ine,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:N,children:v.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:R},children:v.jsx(Xt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});Zz.displayName=Pne;var Lne="SelectPopperPosition",N0=_.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=qs,...s}=e,o=Uv(n);return v.jsx(Lv,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});N0.displayName=Lne;var[Ine,w1]=ad(uc,{}),M0="SelectViewport",Qz=_.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=xl(M0,n),o=w1(M0,n),l=Bn(t,s.onViewportChange),u=_.useRef(0);return v.jsxs(v.Fragment,{children:[v.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),v.jsx($v.Slot,{scope:n,children:v.jsx(Xt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:yt(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const g=Math.abs(u.current-h.scrollTop);if(g>0){const b=window.innerHeight-qs*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<b){const k=E+g,T=Math.min(b,k),R=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(h.scrollTop=R>0?R:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});Qz.displayName=M0;var Jz="SelectGroup",[zne,Bne]=ad(Jz),jne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return v.jsx(zne,{scope:n,id:i,children:v.jsx(Xt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});jne.displayName=Jz;var eB="SelectLabel",Fne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bne(eB,n);return v.jsx(Xt.div,{id:i.id,...r,ref:t})});Fne.displayName=eB;var Yg="SelectItem",[$ne,tB]=ad(Yg),nB=_.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=Sl(Yg,n),u=xl(Yg,n),d=l.value===r,[h,p]=_.useState(s??""),[y,g]=_.useState(!1),b=Bn(t,k=>{var T;return(T=u.itemRefCallback)==null?void 0:T.call(u,k,r,i)}),w=gi(),x=_.useRef("touch"),E=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return v.jsx($ne,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:_.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:v.jsx($v.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:v.jsx(Xt.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:b,onFocus:yt(o.onFocus,()=>g(!0)),onBlur:yt(o.onBlur,()=>g(!1)),onClick:yt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:yt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:yt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:yt(o.onPointerMove,k=>{var T;x.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:yt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:yt(o.onKeyDown,k=>{var R;((R=u.searchRef)==null?void 0:R.current)!==""&&k.key===" "||(Cne.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});nB.displayName=Yg;var Lh="SelectItemText",rB=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Sl(Lh,n),l=xl(Lh,n),u=tB(Lh,n),d=Ane(Lh,n),[h,p]=_.useState(null),y=Bn(t,E=>p(E),u.onItemTextChange,E=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,E,u.value,u.disabled)}),g=h==null?void 0:h.textContent,b=_.useMemo(()=>v.jsx("option",{value:u.value,disabled:u.disabled,children:g},u.value),[u.disabled,u.value,g]),{onNativeOptionAdd:w,onNativeOptionRemove:x}=d;return Ti(()=>(w(b),()=>x(b)),[w,x,b]),v.jsxs(v.Fragment,{children:[v.jsx(Xt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?nd.createPortal(s.children,o.valueNode):null]})});rB.displayName=Lh;var iB="SelectItemIndicator",sB=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return tB(iB,n).isSelected?v.jsx(Xt.span,{"aria-hidden":!0,...r,ref:t}):null});sB.displayName=iB;var O0="SelectScrollUpButton",oB=_.forwardRef((e,t)=>{const n=xl(O0,e.__scopeSelect),r=w1(O0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollTop>0;s(d)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?v.jsx(lB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});oB.displayName=O0;var D0="SelectScrollDownButton",aB=_.forwardRef((e,t)=>{const n=xl(D0,e.__scopeSelect),r=w1(D0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,h=Math.ceil(u.scrollTop)<d;s(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?v.jsx(lB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});aB.displayName=D0;var lB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=xl("SelectScrollButton",n),o=_.useRef(null),l=Hv(n),u=_.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return _.useEffect(()=>()=>u(),[u]),Ti(()=>{var h;const d=l().find(p=>p.ref.current===document.activeElement);(h=d==null?void 0:d.ref.current)==null||h.scrollIntoView({block:"nearest"})},[l]),v.jsx(Xt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:yt(i.onPointerLeave,()=>{u()})})}),Hne="SelectSeparator",Une=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return v.jsx(Xt.div,{"aria-hidden":!0,...r,ref:t})});Une.displayName=Hne;var P0="SelectArrow",Wne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Uv(n),s=Sl(P0,n),o=xl(P0,n);return s.open&&o.position==="popper"?v.jsx(Iv,{...i,...r,ref:t}):null});Wne.displayName=P0;var qne="SelectBubbleInput",cB=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=_.useRef(null),s=Bn(r,i),o=bJ(t);return _.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&h){const p=new Event("change",{bubbles:!0});h.call(l,t),l.dispatchEvent(p)}},[o,t]),v.jsx(Xt.select,{...n,style:{...qL,...n.style},ref:s,defaultValue:t})});cB.displayName=qne;function uB(e){return e===""||e===void 0}function dB(e){const t=To(e),n=_.useRef(""),r=_.useRef(0),i=_.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=_.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return _.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function hB(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=Vne(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 Vne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Yne=$z,Kne=Uz,Gne=qz,Xne=Vz,Zne=Yz,Qne=Kz,Jne=Qz,ere=nB,tre=rB,nre=sB,rre=oB,ire=aB,[Wv]=aa("Tooltip",[bl]),qv=bl(),fB="TooltipProvider",sre=700,L0="tooltip.open",[ore,S1]=Wv(fB),pB=e=>{const{__scopeTooltip:t,delayDuration:n=sre,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=_.useRef(!0),l=_.useRef(!1),u=_.useRef(0);return _.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),v.jsx(ore,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:_.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};pB.displayName=fB;var mf="Tooltip",[are,$f]=Wv(mf),mB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=S1(mf,e.__scopeTooltip),d=qv(t),[h,p]=_.useState(null),y=gi(),g=_.useRef(0),b=o??u.disableHoverableContent,w=l??u.delayDuration,x=_.useRef(!1),[E,k]=oc({prop:r,defaultProp:i??!1,onChange:$=>{$?(u.onOpen(),document.dispatchEvent(new CustomEvent(L0))):u.onClose(),s==null||s($)},caller:mf}),T=_.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),R=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,x.current=!1,k(!0)},[k]),z=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),N=_.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{x.current=!0,k(!0),g.current=0},w)},[w,k]);return _.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),v.jsx(Pv,{...d,children:v.jsx(are,{scope:t,contentId:y,open:E,stateAttribute:T,trigger:h,onTriggerChange:p,onTriggerEnter:_.useCallback(()=>{u.isOpenDelayedRef.current?N():R()},[u.isOpenDelayedRef,N,R]),onTriggerLeave:_.useCallback(()=>{b?z():(window.clearTimeout(g.current),g.current=0)},[z,b]),onOpen:R,onClose:z,disableHoverableContent:b,children:n})})};mB.displayName=mf;var I0="TooltipTrigger",gB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=$f(I0,n),s=S1(I0,n),o=qv(n),l=_.useRef(null),u=Bn(t,l,i.onTriggerChange),d=_.useRef(!1),h=_.useRef(!1),p=_.useCallback(()=>d.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),v.jsx(If,{asChild:!0,...o,children:v.jsx(Xt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:yt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:yt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:yt(e.onBlur,i.onClose),onClick:yt(e.onClick,i.onClose)})})});gB.displayName=I0;var x1="TooltipPortal",[lre,cre]=Wv(x1,{forceMount:void 0}),vB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=$f(x1,t);return v.jsx(lre,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};vB.displayName=x1;var Vu="TooltipContent",yB=_.forwardRef((e,t)=>{const n=cre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=$f(Vu,e.__scopeTooltip);return v.jsx(Bs,{present:r||o.open,children:o.disableHoverableContent?v.jsx(_B,{side:i,...s,ref:t}):v.jsx(ure,{side:i,...s,ref:t})})}),ure=_.forwardRef((e,t)=>{const n=$f(Vu,e.__scopeTooltip),r=S1(Vu,e.__scopeTooltip),i=_.useRef(null),s=Bn(t,i),[o,l]=_.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=_.useCallback(()=>{l(null),p(!1)},[p]),g=_.useCallback((b,w)=>{const x=b.currentTarget,E={x:b.clientX,y:b.clientY},k=pre(E,x.getBoundingClientRect()),T=mre(E,k),R=gre(w.getBoundingClientRect()),z=yre([...T,...R]);l(z),p(!0)},[p]);return _.useEffect(()=>()=>y(),[y]),_.useEffect(()=>{if(u&&h){const b=x=>g(x,h),w=x=>g(x,u);return u.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[u,h,g,y]),_.useEffect(()=>{if(o){const b=w=>{const x=w.target,E={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),T=!vre(E,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[u,h,o,d,y]),v.jsx(_B,{...e,ref:s})}),[dre,hre]=Wv(mf,{isInside:!1}),fre=VZ("TooltipContent"),_B=_.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=$f(Vu,n),d=qv(n),{onClose:h}=u;return _.useEffect(()=>(document.addEventListener(L0,h),()=>document.removeEventListener(L0,h)),[h]),_.useEffect(()=>{if(u.trigger){const p=y=>{const g=y.target;g!=null&&g.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:v.jsxs(Lv,{"data-state":u.stateAttribute,...d,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[v.jsx(fre,{children:r}),v.jsx(dre,{scope:n,isInside:!0,children:v.jsx(YL,{id:u.contentId,role:"tooltip",children:i||r})})]})})});yB.displayName=Vu;var bB="TooltipArrow",wB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=qv(n);return hre(bB,n).isInside?null:v.jsx(Iv,{...i,...r,ref:t})});wB.displayName=bB;function pre(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 mre(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 gre(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 vre(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 yre(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),_re(t)}function _re(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 bre=pB,wre=mB,Sre=gB,xre=vB,Ere=yB,Cre=wB;function E1({...e}){return v.jsx(bne,{"data-slot":"popover",...e})}function C1({...e}){return v.jsx(wne,{"data-slot":"popover-trigger",...e})}function k1({className:e,align:t="center",sideOffset:n=4,...r}){return v.jsx(Sne,{children:v.jsx(xne,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const kre={"no-proxy":{heading:"还没有连接开发机",body:"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。"},"client-token-missing":{heading:"需要 client token",body:"Relay 服务器已启用客户端访问控制。请在设置里填写。"},"client-token-invalid":{heading:"client token 无效",body:"当前浏览器保存的 client token 无效或已过期。请在设置里更新。"},"no-session":{heading:"没有选中的会话",body:""},"no-messages":{heading:"开始对话",body:""}};function nc({variant:e,action:t}){const{heading:n,body:r}=kre[e];return e==="no-messages"?v.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:v.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[v.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&v.jsx("div",{children:t})]})}const Tre={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Rre={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function AN({status:e,className:t}){return v.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Tre[e],t),role:"status","aria-label":Rre[e]})}function SB({layout:e,variant:t="default"}){const n=ze(w=>w.proxies),r=ze(w=>w.proxyListLoaded),i=ze(w=>w.relayClientAuthIssue),s=ze(w=>w.selectedProxyId),o=Bi(),l=Js(),[u,d]=_.useState(!1),[h,p]=_.useState(null);async function y(w,x){if(h)return;const E=Mt;if(!E){nt.error("请先连接开发机");return}const k=x??w;p(w);try{const T=await E.selectProxy(w);if(!T.success){nt.error(`无法连接 ${k}:${T.error??"未知错误"}`);return}dr("local",ln.proxyId,w),ze.getState().setProxy(w,x??null),ze.getState().setProxyOnline(!0),ze.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestAgentStatuses().then(R=>{const z=Ut.getState();for(const N of R)z.setAgentStatus(N.sessionId,N.payload)}).catch(R=>{console.error("[proxy-switcher] post-bind data fetch failed",R)}),E.requestSessionHistory().then(R=>Ut.getState().setHistorySessions(R)).catch(R=>{console.error("[proxy-switcher] post-bind data fetch failed",R)}),d(!1),(e==="page"||o.pathname.startsWith("/chat/"))&&l("/sessions")}catch(T){const R=T instanceof Error?T.message:"未知错误";nt.error(`无法连接 ${k}:${R}`)}finally{p(null)}}if(e==="page")return i==="missing_client_token"?v.jsx(nc,{variant:"client-token-missing"}):i==="invalid_client_token"?v.jsx(nc,{variant:"client-token-invalid"}):r?n.length===0?v.jsx(nc,{variant:"no-proxy"}):v.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[v.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),v.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",x?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线,暂时无法连接",children:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})]}):v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});const g=n.find(w=>w.proxyId===s),b=(g==null?void 0:g.name)??(g==null?void 0:g.proxyId)??"未选择开发机";return v.jsxs(E1,{open:u,onOpenChange:d,children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${b}`,children:[t==="default"&&v.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),v.jsx("span",{className:We("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:b}),v.jsx(gl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),v.jsx(k1,{align:"start",className:"w-[260px] p-1",children:n.length===0?v.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):v.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",x?"bg-accent text-accent-foreground":"hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线",children:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&s!==w.proxyId&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})})]})}const NN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,MN=NP,Are=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return MN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(d=>{const h=n==null?void 0:n[d],p=s==null?void 0:s[d];if(h===null)return null;const y=NN(h)||NN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,h)=>{let[p,y]=h;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,h)=>{let{class:p,className:y,...g}=h;return Object.entries(g).every(b=>{let[w,x]=b;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return MN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Nre=Are("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-normal whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function St({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?WZ:"button";return v.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(Nre({variant:t,size:n,className:e})),...i})}function Mre({delayDuration:e=0,...t}){return v.jsx(bre,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Hf({...e}){return v.jsx(wre,{"data-slot":"tooltip",...e})}function Uf({...e}){return v.jsx(Sre,{"data-slot":"tooltip-trigger",...e})}function Wf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return v.jsx(xre,{children:v.jsxs(Ere,{"data-slot":"tooltip-content",sideOffset:t,className:We("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&v.jsx(Cre,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Vv({...e}){return v.jsx(e1,{"data-slot":"sheet",...e})}function Ore({...e}){return v.jsx(_J,{"data-slot":"sheet-trigger",...e})}function Dre({...e}){return v.jsx(t1,{"data-slot":"sheet-portal",...e})}function Pre({className:e,...t}){return v.jsx(n1,{"data-slot":"sheet-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Yv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return v.jsxs(Dre,{children:[v.jsx(Pre,{className:t}),v.jsxs(r1,{"data-slot":"sheet-content",className:We("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&v.jsxs(i1,{"data-slot":"sheet-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[v.jsx(Of,{className:"size-4"}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function T1({className:e,...t}){return v.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function Kv({className:e,...t}){return v.jsx(wI,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Lre({className:e,...t}){return v.jsx(SI,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}function R1({...e}){return v.jsx(tne,{"data-slot":"dropdown-menu",...e})}function A1({...e}){return v.jsx(nne,{"data-slot":"dropdown-menu-trigger",...e})}function N1({className:e,sideOffset:t=4,...n}){return v.jsx(rne,{children:v.jsx(ine,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function bo({className:e,inset:t,variant:n="default",...r}){return v.jsx(one,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Kb({className:e,children:t,checked:n,...r}){return v.jsxs(ane,{"data-slot":"dropdown-menu-checkbox-item",className:We("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[v.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:v.jsx(lne,{children:v.jsx(ra,{className:"size-4"})})}),t]})}function Im({className:e,inset:t,...n}){return v.jsx(sne,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Gb({className:e,...t}){return v.jsx(cne,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}const Ire={claude:"Claude Code",codex:"Codex"},ON=["claude","codex"];function Gv(e){return Ire[e]}function xB(e,t){return ON.indexOf(e)-ON.indexOf(t)}function z0(e){return e.provider??"claude"}const B0=60*1e3,j0=60*B0,zre=24*j0;function EB(e,t=Date.now()){const n=t-e;if(n<B0)return"刚刚";if(n<j0)return`${Math.floor(n/B0)} 分钟前`;if(n<zre)return`${Math.floor(n/j0)} 小时前`;const r=new Date(e),i=r.getMonth()+1,s=r.getDate(),o=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0");return`${i} 月 ${s} 日 ${o}:${l}`}const DN={idle:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"空闲"},working:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"工作中"},compacting:{dot:"bg-[var(--color-status-compacting)] animate-pulse",text:"text-[var(--color-status-compacting)]",label:"压缩中"},waiting_approval:{dot:"bg-[var(--color-status-warning)]",text:"text-[var(--color-status-warning)]",label:"等待审批"},error:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"出错"},terminated:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已终止"}};function F0(e){return e.kind!=="terminal"?DN[e.state]:e.state==="terminated"?DN.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function Bre({session:e}){const t=F0(e);return v.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function jre({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.jsx("span",{className:"inline-flex h-5 w-4 shrink-0 items-center justify-center text-muted-foreground",role:"img","aria-label":t,title:t,"data-slot":"session-mode-icon","data-mode":e,children:v.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Fre({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Ev(e.name),d=Vx(e),h=e.nameLocked&&e.name?e.name:d||(u==="New Session"?e.sessionId.slice(0,8):u),p=!!e.mode||!!e.provider||o!==void 0,y=o!==void 0?EB(o,n):null,g=e.mode==="pty"&&e.ptyOwner==="local-terminal",b=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return v.jsxs("li",{className:We("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&v.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),v.jsxs("button",{type:"button",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[v.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[v.jsx(Bre,{session:e}),v.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&v.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&v.jsx(jre,{mode:e.mode}),e.mode&&v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Gv(e.provider)}),v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),v.jsx("span",{className:We("shrink-0",F0(e).text),children:F0(e).label}),y&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),v.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:v.jsx(St,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:v.jsx(K9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end","data-slot":"session-row-menu",children:[i&&v.jsx(bo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&v.jsx(bo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:b})]})]})]})}function Sc({...e}){return v.jsx(e1,{"data-slot":"dialog",...e})}function $re({...e}){return v.jsx(t1,{"data-slot":"dialog-portal",...e})}function Hre({className:e,...t}){return v.jsx(n1,{"data-slot":"dialog-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function xc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return v.jsxs($re,{"data-slot":"dialog-portal",children:[v.jsx(Hre,{}),v.jsxs(r1,{"data-slot":"dialog-content",className:We("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&v.jsxs(i1,{"data-slot":"dialog-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[v.jsx(Of,{}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ec({className:e,...t}){return v.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return v.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&v.jsx(i1,{asChild:!0,children:v.jsx(St,{variant:"outline",children:"Close"})})]})}function dl({className:e,...t}){return v.jsx(wI,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function dc({className:e,...t}){return v.jsx(SI,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function hl(e){const[t,n]=_.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return _.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function Ure({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=v.jsx(Wre,{title:e.title,modeTag:s}),l=v.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:EB(e.updatedAt,t)}),u=v.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return v.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:v.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:We("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,v.jsx(S9,{className:We("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Wre({title:e,modeTag:t}){return v.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[v.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&v.jsx(qre,{mode:t})]})}function qre({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:v.jsx(n,{className:"size-3","aria-hidden":"true"})})}function CB({providerLabel:e}){return v.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:v.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[v.jsx(K8,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),v.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Vre({now:e}){const t=Ut(U=>U.historySessions),[n,r]=_.useState(null),[i,s]=_.useState(null),[o,l]=_.useState("json"),[u,d]=_.useState("default"),[h,p]=_.useState(!1),[y,g]=_.useState(!1),[b,w]=_.useState(new Set),[x,E]=_.useState(new Set),k=Js(),T=_.useMemo(()=>{const U=new Map;for(const O of t){const M=z0(O);let I=U.get(M);I||(I=new Map,U.set(M,I));const L=kB(O.projectDir),D=I.get(L);D?D.sessions.push(O):I.set(L,{dir:L,sessions:[O]})}return Array.from(U.entries()).sort(([O],[M])=>xB(O,M)).map(([O,M])=>({provider:O,sessions:Array.from(M.values()).flatMap(I=>I.sessions),projects:Array.from(M.values()).map(I=>({dir:I.dir,shortDir:Ev(I.dir),sessions:I.sessions}))}))},[t]);function R(U){s(U),l(Yre(U)),d("default")}async function z(U,O,M){if(n)return;const I=Mt;if(!I){nt.error("请先连接开发机");return}r(U.id);const L=z0(U);try{const D=await I.createSession({cwd:U.projectDir,mode:O,provider:L,resumeSessionId:U.id,...M?{permissionMode:M}:{}});if(D.error||!D.sessionId){nt.error(`恢复失败:${D.error??"未知错误"}`);return}const Y={sessionId:D.sessionId,state:"idle",mode:D.mode??O,provider:D.provider??"claude"};Ut.getState().addSession(Y),k(`/chat/${D.sessionId}?mode=${D.mode??O}`),s(null)}catch(D){nt.error(`恢复失败:${D instanceof Error?D.message:String(D)}`)}finally{r(null)}}function N(){const U=Mt;!U||h||(p(!0),U.requestSessionHistory().then(O=>Ut.getState().setHistorySessions(O)).catch(O=>{nt.error(O instanceof Error?O.message:String(O))}).finally(()=>{p(!1)}))}function $(U,O){const M=PN(U,O);E(I=>{const L=new Set(I);return L.has(M)?L.delete(M):L.add(M),L})}function P(U){w(O=>{const M=new Set(O);return M.has(U)?M.delete(U):M.add(U),M})}const q=t.length>0,H=i?TB():[];return v.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[v.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[v.jsxs("button",{type:"button",onClick:()=>q&&g(U=>!U),disabled:!q,"aria-expanded":q?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:We("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[v.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",q?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),q?v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:N,disabled:h,"data-slot":"history-refresh",children:v.jsx(Tx,{className:We("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!q&&v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),q&&y&&v.jsx("ul",{role:"list",className:"flex flex-col",children:T.map(U=>{const O=b.has(U.provider);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>P(U.provider),"aria-expanded":!O,"data-slot":"history-provider-header","data-expanded":!O,className:We("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:Gv(U.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:U.sessions.length}),v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!O&&"rotate-90"),"aria-hidden":"true"})]}),!O&&v.jsx("ul",{role:"list",className:"flex flex-col",children:U.projects.map(M=>{const I=PN(U.provider,M.dir),L=x.has(I);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>$(U.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:We("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),v.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&v.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(D=>v.jsx(Ure,{session:D,now:e,disabled:n!==null,loading:n===D.id,onClick:()=>R(D),modeTag:D.preferredMode},D.id))})]},I)})})]},U.provider)})}),v.jsx(Kre,{session:i,open:i!==null,modes:H,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:U=>{U||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&z(i,o,u)}})]})}function PN(e,t){return`${e}:${kB(t)}`}function kB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function TB(){return["json","pty"]}function Yre(e){const t=TB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Kre({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=_.useState(!1),y=i==="bypassPermissions",g=hl("(min-width: 768px)");_.useEffect(()=>{t||p(!1)},[t]);const b=h?v.jsx(CB,{providerLabel:e?Gv(z0(e)):"Agent"}):v.jsxs("div",{className:"grid min-w-0 gap-4",children:[v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&v.jsx(LN,{checked:r==="json",label:"聊天",icon:v.jsx(kx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&v.jsx(LN,{checked:r==="pty",label:"终端",icon:v.jsx(Rx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[v.jsx(Xb,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),v.jsx(Xb,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),v.jsx(Xb,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=v.jsxs(v.Fragment,{children:[v.jsx(St,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),v.jsx(St,{type:"button",variant:h?"destructive":"default",disabled:s,onClick:()=>{if(y&&!h){p(!0);return}d()},"data-slot":h?"bypass-permission-confirm":void 0,children:s?"恢复中...":h?"确认":"恢复"})]});return g?v.jsx(Sc,{open:t,onOpenChange:o,children:v.jsxs(xc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[v.jsxs(Ec,{className:"min-w-0",children:[v.jsx(dl,{children:h?"跳过全部审批?":"恢复会话"}),v.jsx(dc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),b,v.jsx(Yu,{children:w})]})}):v.jsx(Vv,{open:t,onOpenChange:o,children:v.jsxs(Yv,{side:"bottom",focusSurfaceOnOpen:!0,className:"inset-x-2 w-auto max-h-[calc(100dvh-0.75rem)] min-w-0 overflow-hidden rounded-t-xl border bg-background p-0","data-slot":"history-restore-dialog",children:[v.jsxs(T1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[v.jsx(Kv,{children:h?"跳过全部审批?":"恢复会话"}),v.jsx(Lre,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),v.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:b}),v.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:v.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function LN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:We("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,v.jsx("span",{className:"min-w-0 text-center",children:t}),v.jsx(ra,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Xb({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:We("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[v.jsx("span",{className:We("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&v.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),v.jsxs("span",{className:"grid min-w-0 gap-1",children:[v.jsx("span",{className:We("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),v.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&v.jsx(ra,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Gre({...e}){return v.jsx(Yne,{"data-slot":"select",...e})}function Xre({...e}){return v.jsx(Gne,{"data-slot":"select-value",...e})}function Zre({className:e,size:t="default",children:n,...r}){return v.jsxs(Kne,{"data-slot":"select-trigger","data-size":t,className:We("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,v.jsx(Xne,{asChild:!0,children:v.jsx(gl,{className:"size-4 opacity-50"})})]})}function Qre({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return v.jsx(Zne,{children:v.jsxs(Qne,{"data-slot":"select-content",className:We("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[v.jsx(eie,{}),v.jsx(Jne,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),v.jsx(tie,{})]})})}function Jre({className:e,children:t,...n}){return v.jsxs(ere,{"data-slot":"select-item",className:We("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[v.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:v.jsx(nre,{children:v.jsx(ra,{className:"size-4"})})}),v.jsx(tre,{children:t})]})}function eie({className:e,...t}){return v.jsx(rre,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(Cx,{className:"size-4"})})}function tie({className:e,...t}){return v.jsx(ire,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(gl,{className:"size-4"})})}function M1(e){return!e||e.endsWith("/")?e:`${e}/`}function nie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function rie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function iie(e,t,n){var o;if(t==="insert")return{currentPath:rie(e)||"./",query:nie(e)};if(!e)return{currentPath:"./",query:""};const r=e.replace(/\/+$/,"")||"/";if(e.endsWith("/")||r===(n==null?void 0:n.baseCwd)||((o=n==null?void 0:n.knownDirs)==null?void 0:o.has(r)))return{currentPath:M1(r),query:""};const s=e.lastIndexOf("/");return{currentPath:s>=0?e.slice(0,s+1):"./",query:s>=0?e.slice(s+1).toLowerCase():e.toLowerCase()}}function sie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function oie(e,t){return`${M1(e)}${t.name}${t.isDir?"/":""}`}function IN(e,t){const n=e.trim().replace(/\/+$/,"")||"/",r=t.trim().replace(/^\/+|\/+$/g,"");return!n.startsWith("/")||!r||t.trim().startsWith("/")||r.split("/").some(i=>i===""||i==="."||i==="..")?null:n==="/"?`/${r}`:`${n}/${r}`}const RB=_.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=Ei(F=>F.tree),h=Ei(F=>F.cwd),p=Ei(F=>F.homePath),y=i==="insert"?h:p||h,g=_.useMemo(()=>new Set(d.keys()),[d]),b=_.useMemo(()=>iie(t,i,{baseCwd:y,knownDirs:g}),[t,i,y,g]),w=b.currentPath,x=_.useMemo(()=>sie(y,w),[y,w]),E=b.query,k=_.useRef(new Set),[T,R]=_.useState(!1),[z,N]=_.useState(""),[$,P]=_.useState(!1);_.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const F=Mt;if(!F)return;let A=!1;return k.current.add(x),F.requestDirectoryList(x).then(W=>{A||Ei.getState().setDirEntries(W.path,W.entries)}).catch(()=>{A||Ei.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{A=!0}},[x,d]);const q=!d.has(x),H=_.useMemo(()=>{let F=d.get(x)??[];return o&&(F=F.filter(A=>A.isDir)),E&&(F=F.filter(A=>A.name.toLowerCase().includes(E))),F},[d,x,E,o]),[U,O]=_.useState(0);_.useEffect(()=>O(0),[w,E]),_.useEffect(()=>{R(!1),N("")},[x]),_.useEffect(()=>{U>=H.length&&H.length>0&&O(H.length-1)},[H.length,U]);const M=_.useRef(null),I=_.useRef(!1);_.useEffect(()=>{var A;if(!I.current)return;I.current=!1;const F=(A=M.current)==null?void 0:A.querySelector(`[data-entry-index="${U}"]`);F==null||F.scrollIntoView({block:"nearest"})},[U]);const L=_.useCallback(F=>{const A=oie(w,F);return i==="insert"?A.replace(/^\.\//,""):A},[w,i]);async function D(){const F=IN(x,z);if(!(!F||!r)){P(!0);try{const A=await r(F);if(!A)return;N(""),R(!1),n(M1(A))}finally{P(!1)}}}_.useImperativeHandle(u,()=>({handleKey(F){return H.length===0?!1:F.key==="ArrowDown"?(I.current=!0,O(A=>Math.min(H.length-1,A+1)),!0):F.key==="ArrowUp"?(I.current=!0,O(A=>Math.max(0,A-1)),!0):F.key==="Enter"&&!F.nativeEvent.isComposing?(n(L(H[U])),!0):!1}}),[H,U,L,n]);const Y=s==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":i==="insert"?"absolute bottom-full left-0 right-0 z-50 mb-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden":"absolute left-0 right-0 top-full z-50 mt-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden",K=s==="inline"?"h-44 overflow-y-auto overscroll-contain":i==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return v.jsxs("div",{className:Y,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?v.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?v.jsx("button",{type:"button",className:"rounded px-2 py-1 text-xs text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",disabled:!x||$,onClick:()=>R(F=>!F),children:"新建目录"}):null]}),T?v.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[v.jsx("input",{type:"text",value:z,onChange:F=>N(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!F.nativeEvent.isComposing&&(F.preventDefault(),D()),F.key==="Escape"&&(R(!1),N(""))},placeholder:"目录名称",className:"min-h-11 min-w-0 flex-1 rounded-md border border-border bg-input px-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-8 md:min-h-0 md:text-sm",autoComplete:"off",autoCorrect:"off",spellCheck:!1}),v.jsx("button",{type:"button",className:"min-h-11 rounded-md bg-primary px-3 text-sm text-primary-foreground disabled:cursor-not-allowed disabled:opacity-50 md:h-8 md:min-h-0",disabled:!IN(x,z)||$,onClick:()=>void D(),children:$?"创建中...":"创建目录"})]}):null]}):null,v.jsx("div",{className:K,children:H.length===0?v.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:q?"加载中...":"没有匹配的路径"}):v.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:H.map((F,A)=>v.jsx("li",{children:v.jsx("button",{type:"button",onClick:()=>n(L(F)),onMouseEnter:()=>O(A),className:We("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",A===U&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",F.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":F.isDir?"dir":"file","data-entry-index":A,children:v.jsxs("span",{className:"font-mono text-[13px]",children:[F.name,F.isDir?"/":""]})})},F.name))})})]})}),zN="工作目录不存在或不可访问:",aie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],AB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function lie(e,t){return t!==Xr.PATH_NOT_FOUND||!e.startsWith(zN)?null:e.slice(zN.length).trim()||null}function Kg(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function cie(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function uie(e,t){return e!=="codex"||AB.some(n=>n.value===t)?t:"default"}async function die({relay:e,agentCli:t,form:n,timeoutMs:r=Ux}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Kg(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${na[n.provider]} 不可用:${p}`:`${na[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=lie(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,g=((h=p.name)==null?void 0:h.trim())||void 0;return{type:"success",session:{sessionId:p.sessionId,...p.kind!==void 0?{kind:p.kind}:{},name:g,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",mode:y,provider:p.provider??l,...p.ptyOwner!==void 0?{ptyOwner:p.ptyOwner}:{}},route:`/chat/${p.sessionId}?mode=${y}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function hie({relay:e,timeoutMs:t=Ux}){var n;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const r=await e.createSession({kind:"terminal",mode:"pty"},t);return r.error||!r.sessionId?{type:"create_error",message:`创建终端失败:${r.error??"未知错误"}`}:{type:"success",session:{sessionId:r.sessionId,kind:"terminal",name:((n=r.name)==null?void 0:n.trim())||void 0,...r.nameLocked!==void 0?{nameLocked:r.nameLocked}:{},state:"idle",mode:"pty",provider:r.provider??"claude",...r.ptyOwner!==void 0?{ptyOwner:r.ptyOwner}:{}},route:`/chat/${r.sessionId}?mode=pty`}}catch(r){return{type:"exception",message:r instanceof Error?r.message:String(r)}}}function fie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Kg("claude",e),y=Kg("codex",e),g=e==null?void 0:e[t];return v.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[v.jsxs("div",{className:"flex items-center justify-between",children:[v.jsx("span",{className:"text-sm",children:"Agent CLI"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsx(BN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),v.jsx(BN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),v.jsx("div",{className:"relative min-w-0 rounded-md border border-border bg-muted/20 px-3 py-2.5 md:p-3","data-slot":"agent-cli-path-card",children:r===t?v.jsx(pie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):v.jsx(mie,{provider:t,selectedCli:g,isDesktop:n,onOpenCliPathEditor:l})})]})}function BN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return v.jsxs(Hf,{children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:na[e]}),v.jsx("span",{className:We("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),v.jsx(Wf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:v.jsx("span",{className:"break-all font-mono text-xs",children:cie(e,n)})})]})}function pie({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[v.jsxs("label",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:"sr-only",children:"CLI 路径"}),v.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),o()),l.key==="Escape"&&(l.preventDefault(),s())},placeholder:e==="claude"?"/home/dev/.local/bin/claude":"/home/dev/.local/bin/codex",className:"min-h-11 w-full rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-10 md:min-h-0 md:text-sm"}),v.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>v.jsx("option",{value:l},l))})]}),v.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground md:h-8 md:min-h-0",onClick:s,disabled:r,children:"取消"}),v.jsx(St,{type:"button",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium md:h-8 md:min-h-0",onClick:o,disabled:r||!n.trim(),children:r?"保存中...":"保存路径"})]})]})]})}function mie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[v.jsx("p",{className:We("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),v.jsx(St,{type:"button",variant:"outline",className:"h-8 min-h-0 shrink-0 self-end rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground sm:self-auto",onClick:()=>r(e),children:"指定路径"})]})]}):v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsx(St,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 size-11 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/70 hover:text-foreground","aria-label":"指定路径",onClick:()=>r(e),children:v.jsx(x8,{className:"size-4","aria-hidden":"true"})}),v.jsx("p",{className:We("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function Ih({open:e,onOpenChange:t}){const[n,r]=_.useState(""),[i,s]=_.useState(""),[o,l]=_.useState("claude"),[u,d]=_.useState("pty"),[h,p]=_.useState("default"),[y,g]=_.useState(!1),[b,w]=_.useState(!1),[x,E]=_.useState(null),[k,T]=_.useState(!1),[R,z]=_.useState(null),[N,$]=_.useState(""),[P,q]=_.useState(!1),H=_.useRef(null),U=_.useRef(e);U.current=e;const O=Js(),M=Ei(Ee=>Ee.homePath),I=Ei(Ee=>Ee.agentCli),L=hl("(min-width: 768px)");_.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),_.useEffect(()=>{if(!e||M&&I)return;const Ee=Mt==null?void 0:Mt.requestProxyInfo();Ee&&Ee.then(Re=>{const Ie=Ei.getState();Ie.setHomePath(Re.homePath),Ie.setAgentCli(Re.agentCli)}).catch(Re=>{console.error("[create-session-dialog] requestProxyInfo failed",Re)})},[e,M,I]),_.useEffect(()=>{if(!k)return;function Ee(Re){var Ye;const Ie=Re.target;Ie instanceof Node&&((Ye=H.current)!=null&&Ye.contains(Ie))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",Ee,!0),()=>document.removeEventListener("pointerdown",Ee,!0)},[k]);function D(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),g(!1),E(null),z(null),$(""),q(!1)}function Y(){if(h==="bypassPermissions"){g(!0);return}B()}async function K(){await B(),U.current&&g(!1)}const F=o==="codex"?AB:aie,A=Kg(o,I),W=b||P||A.disabled;function G(Ee){const Re=uie(Ee,h);Re!==h&&p(Re)}async function B(Ee){E(null),w(!0);try{const Re=await die({relay:Mt,agentCli:I,form:{cwd:Ee??i,name:n,provider:o,permissionMode:h,mode:u}});if(Re.type==="success"){if(Ut.getState().addSession(Re.session),!U.current)return;t(!1),D(),O(Re.route);return}if(Re.type==="missing_cwd"&&E(Re.path),nt.error(Re.message),Re.type==="validation_error"||Re.type==="relay_missing")return}finally{w(!1)}}async function ne(Ee){const Re=Mt;if(!Re)return nt.error("请先连接开发机"),null;try{const Ie=await Re.createDirectory(Ee);return Ie.success?(s(Ie.path),E(null),nt.success("目录已创建"),Ie.path):(nt.error(`目录创建失败:${Ie.error??"未知错误"}`),null)}catch(Ie){return nt.error(Ie instanceof Error?Ie.message:String(Ie)),null}}function ie(Ee){var Ie;const Re=I==null?void 0:I[Ee];z(Ee),$((Re==null?void 0:Re.command)??((Ie=Re==null?void 0:Re.suggestions)==null?void 0:Ie[0])??"")}async function se(){if(!R)return;const Ee=N.trim();if(!Ee){nt.error("请输入 Agent CLI 路径");return}const Re=Mt;if(!Re){nt.error("请先连接开发机");return}q(!0);try{const Ie=await Re.updateAgentCliPath(R,Ee);if(Ie.error||!Ie.agentCli){nt.error(`路径保存失败:${Ie.error??"未知错误"}`);return}Ei.getState().setAgentCli(Ie.agentCli),nt.success(`${na[R]} 路径已保存`),z(null),$("")}catch(Ie){nt.error(Ie instanceof Error?Ie.message:String(Ie))}finally{q(!1)}}function te(Ee){d(Ee),G(o)}function he(Ee){var Ie;const Re=Ee.relatedTarget;Re instanceof Node&&((Ie=H.current)!=null&&Ie.contains(Re))||window.setTimeout(()=>T(!1),0)}const ge=y?v.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[v.jsx(CB,{providerLabel:na[o]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:b,children:"返回"}),v.jsx(St,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void K(),disabled:b,"data-slot":"bypass-permission-confirm",children:b?"创建中...":"确认"})]})]}):v.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Ee=>{Ee.preventDefault(),Y()},children:[v.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[v.jsx("span",{className:"text-sm",children:"名称(可选)"}),v.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Ee=>r(Ee.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),v.jsxs("div",{ref:H,className:"relative flex min-w-0 flex-col gap-2",onBlur:he,children:[v.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),v.jsx("input",{id:"create-session-cwd",type:"text","aria-labelledby":"create-session-cwd-label",name:"dev-anywhere-session-cwd",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:i,onFocus:()=>T(!0),onChange:Ee=>{s(Ee.target.value),E(null)},placeholder:"输入绝对路径",className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm"}),k?v.jsx(RB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ne,onSelect:Ee=>{s(Ee),E(null),T(!0)}}):null]}),x?v.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[v.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),v.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:x})]}):null,v.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"交互方式"}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>te("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),v.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>te("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),v.jsx(fie,{agentCli:I,provider:o,isDesktop:L,editingCliProvider:R,cliPathInput:N,savingCliPath:P,onProviderChange:Ee=>{l(Ee),G(Ee)},onOpenCliPathEditor:ie,onCliPathInputChange:$,onCancelCliPathEditor:()=>{z(null),$("")},onSaveCliPath:()=>void se()}),v.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"权限模式"}),v.jsxs(Gre,{value:h,onValueChange:Ee=>p(Ee),children:[v.jsx(Zre,{className:"w-full",children:v.jsx(Xre,{})}),v.jsx(Qre,{children:F.map(Ee=>v.jsx(Jre,{value:Ee.value,children:Ee.label},Ee.value))})]})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:b,children:"取消"}),v.jsx(St,{type:"submit",className:"min-h-11 md:min-h-0",disabled:W,children:b?"创建中...":"创建"})]})]});return L?v.jsx(Sc,{open:e,onOpenChange:t,children:v.jsxs(xc,{className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[44rem]","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[v.jsx(Ec,{children:v.jsx(dl,{children:y?"跳过全部审批?":"新建会话"})}),ge]})}):v.jsx(Vv,{open:e,onOpenChange:t,children:v.jsxs(Yv,{side:"bottom",className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto overflow-x-hidden overflow-y-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[v.jsx(T1,{className:"px-0 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:y?"跳过全部审批?":"新建会话"})}),ge]})})}function zh({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=_.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=_.useState(s),[u,d]=_.useState(null),[h,p]=_.useState(!1);_.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(g){g.preventDefault();const b=o.trim();if(!b){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,b),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return v.jsx(Sc,{open:e,onOpenChange:r,children:v.jsx(xc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:v.jsxs("form",{className:"grid gap-4",onSubmit:g=>void y(g),children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"重命名会话"}),v.jsx(dc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),v.jsxs("div",{className:"grid gap-2",children:[v.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),v.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:g=>{l(g.target.value),u&&d(null)}}),u?v.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),v.jsx(St,{type:"submit",disabled:h,children:"保存"})]})]})})})}function gie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function vie(e){return(e==null?void 0:e.kind)==="terminal"}function yie(e){return gie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:vie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function zm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=yie(t);function s(){t&&(r(t),n(!1))}return v.jsx(Sc,{open:e,onOpenChange:n,children:v.jsxs(xc,{"data-slot":"session-termination-dialog",children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:i.title}),v.jsx(dc,{children:i.description})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),v.jsx(St,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function NB(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 _ie(e){if(e.session.state==="error")return"error";const t=NB(e);return t==="disconnected"?e.session.state:t}function MB({layout:e}){const t=Ut(A=>A.sessions),n=Ut(A=>A.sessionListLoaded),r=Ut(A=>A.agentStatusBySessionId),i=Ut(A=>A.ptyStateBySessionId),s=Ut(A=>A.renameSession),o=Gt(A=>A.bySessionId),l=QH("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=ze(A=>!!A.selectedProxyId),p=!ze(A=>A.proxyListLoaded)||d&&!n,y=Js(),[g,b]=_.useState(!1),[w,x]=_.useState(!1),[E,k]=_.useState(null),[T,R]=_.useState(null),{creatingTerminal:z,createTerminal:N}=OB(),[$,P]=_.useState(new Set),[q,H]=_.useState(()=>Date.now());_.useEffect(()=>{const A=setInterval(()=>H(Date.now()),6e4);return()=>clearInterval(A)},[]);function U(A,W){y(`/chat/${A}?mode=${W??"json"}`,{replace:!1})}function O(A){const W=A.sessionId,G=Mt;if(!G){nt.error("请先连接开发机");return}G.sendControl({type:"session_terminate",sessionId:W}),Ut.getState().removeSession(W),Gt.getState().clearSession(W),W===u&&y("/sessions"),(A==null?void 0:A.mode)==="pty"&&A.ptyOwner==="local-terminal"?nt.info("已断开页面连接,本地终端仍在运行"):nt.info("正在终止会话",{duration:1500})}async function M(A,W){const G=Mt;if(!G)throw new Error("请先连接开发机");const B=await G.renameSession(A,W);if(!B.success)throw new Error(B.error??"重命名失败");s(A,B.name??W),nt.success("已重命名会话")}function I(A){P(W=>{const G=new Set(W);return G.has(A)?G.delete(A):G.add(A),G})}function L(A){var B;const W=A.mode==="json"&&(((B=o[A.sessionId])==null?void 0:B.pendingApprovals.some(ne=>ne.status==="pending"))??!1),G=_ie({session:A,agentStatus:r[A.sessionId],ptyState:i[A.sessionId],hasPendingApproval:W});return G===A.state?A:{...A,state:G}}const D=t.length>0;if(e==="sidebar"&&(p||!d))return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70",children:p?"连接中...":"请先连接开发机"}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});if(e==="page"&&p)return v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});if(e==="page"&&!d)return v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsx("div",{className:"flex-1",children:v.jsx(nc,{variant:"no-proxy"})}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});const Y=v.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",D?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=D?v.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:bie(t).map(A=>v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>I(A.provider),"aria-expanded":!$.has(A.provider),className:We("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:wie(A.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:A.sessions.length}),v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!$.has(A.provider)&&"rotate-90"),"aria-hidden":"true"})]}),$.has(A.provider)?null:v.jsx("ul",{role:"list",className:"flex flex-col",children:A.sessions.map(W=>v.jsx(Fre,{session:L(W),selected:W.sessionId===u,now:q,onClick:()=>U(W.sessionId,W.mode),onRename:()=>k(W),onTerminate:()=>R(W)},W.sessionId))})]},A.provider))}):v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),F=v.jsx(Vre,{now:q});return e==="page"?v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:v.jsxs(St,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>x(!0),children:[v.jsx(_P,{"aria-hidden":"true"}),"新建"]})}),v.jsx(xie,{open:w,creatingTerminal:z,onOpenChange:x,onCreateAgent:()=>{x(!1),b(!0)},onCreateTerminal:()=>void N(()=>x(!1))}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]}):v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]})}function bie(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])=>Sie(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function wie(e){return e==="terminal"?"终端":Gv(e)}function Sie(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:xB(e,t)}function OB(){const e=Js(),[t,n]=_.useState(!1);async function r(i){if(!t){n(!0);try{const s=await hie({relay:Mt});if(s.type!=="success"){nt.error(s.message);return}Ut.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function jN({compact:e=!1}){const[t,n]=_.useState(!1),[r,i]=_.useState(!1),s=_.useRef(!1),o=ze(w=>!!w.selectedProxyId),{creatingTerminal:l,createTerminal:u}=OB();function d(){i(!0),window.setTimeout(()=>i(!1),2e3)}function h(){if(!o){d();return}s.current=!0,n(!0)}function p(){if(!o){d();return}s.current=!0,u()}function y(w){w.preventDefault(),d()}const g=v.jsxs(St,{variant:"outline","data-slot":"create-session-trigger",className:We(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!o&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!o,onClick:o?void 0:y,children:[v.jsx(_P,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate",children:"新建"})]}),b=o?v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:g}),v.jsxs(N1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:w=>{s.current&&(s.current=!1,w.preventDefault())},children:[v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:h,children:[v.jsx(yP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:l,onSelect:p,children:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),l?"正在创建终端会话...":"终端会话"]})]})]}):g;return v.jsxs(v.Fragment,{children:[o?b:v.jsxs(Hf,{open:o?void 0:r,onOpenChange:o?void 0:i,children:[v.jsx(Uf,{asChild:!0,children:b}),v.jsx(Wf,{side:"top",children:o?"新建会话":"请先连接开发机"})]}),v.jsx(Ih,{open:t,onOpenChange:n})]})}function xie({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=_.useRef(!1);function o(l){s.current=!0,l()}return v.jsx(Vv,{open:e,onOpenChange:n,children:v.jsxs(Yv,{side:"bottom",overlayClassName:"bg-black/10 dark:bg-black/30",className:"inset-x-2 w-auto rounded-t-xl border border-border/80 bg-background px-3 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3 shadow-2xl","data-slot":"create-session-type-sheet",focusSurfaceOnOpen:!0,onCloseAutoFocus:l=>{s.current&&(s.current=!1,l.preventDefault())},children:[v.jsx(T1,{className:"px-1 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:"新建"})}),v.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[v.jsxs(St,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-agent-session-sheet-item",onClick:()=>o(r),children:[v.jsx(yP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.jsxs(St,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-terminal-session-sheet-item",disabled:t,onClick:()=>o(i),children:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Eie="0.5.0",Cie={version:Eie},kie={playback:"playback",capture:"play-and-record"};function Tie(){return typeof navigator>"u"?null:navigator.audioSession??null}function Rie(){return{setMode:()=>{},release:()=>{}}}class Aie{constructor(t=Tie){vt(this,"leases",new Map);vt(this,"session",null);vt(this,"baselineType",null);vt(this,"nextLeaseId",1);vt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Rie();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(kie[t.mode])}applyActiveModeBestEffort(){try{this.applyActiveMode()}catch{}}restoreWhenUnused(){const t=this.session,n=this.baselineType;if(this.session=null,this.baselineType=null,!(!t||n===null))try{t.type=n}catch{}}setNativeType(t){if(!(!this.session||this.session.type===t)){try{this.session.type=t}catch{throw new Error("浏览器无法切换语音音频模式")}if(this.session.type!==t)throw new Error("浏览器无法切换语音音频模式")}}}const O1=new Aie,$0=64,FN=-60,DB=32;function $N(e){if(!Number.isFinite(e)||e===0)return 0;const t=Math.min(1,Math.abs(e)),n=20*Math.log10(t),r=Math.max(0,Math.min(1,(n-FN)/-FN));return e<0?-r:r}function HN(e,t=8){const n=Math.floor(e.byteLength/2);if(n===0||!Number.isFinite(t)||t<=0)return[];const r=Math.min(n,Math.max(1,Math.floor(t))),i=new DataView(e.buffer,e.byteOffset,e.byteLength),s=[];for(let o=0;o<r;o+=1){const l=Math.floor(o*n/r),u=Math.max(l+1,Math.floor((o+1)*n/r));let d=1,h=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),h=Math.max(h,y)}s.push({min:d,max:h})}return s}function Nie(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 Mie(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 PB{constructor(t,n=24e3,r={}){vt(this,"nextStartTime",0);vt(this,"activityEndToken",0);vt(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=Nie(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*DB/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=Mie(n.subarray(l,u));this.scheduleTimer(()=>{var g,b,w,x;(b=(g=this.options).onActivityLevel)==null||b.call(g,y),(x=(w=this.options).onPlaybackChunk)==null||x.call(w,p)},h)}if(this.options.onActivityLevel){const l=Math.max(0,(i-this.context.currentTime)*1e3);this.scheduleTimer(()=>{var u,d;o===this.activityEndToken&&((d=(u=this.options).onActivityLevel)==null||d.call(u,0))},l)}}scheduleTimer(t,n){const r=setTimeout(()=>{this.timelineTimers.delete(r),t()},n);this.timelineTimers.add(r)}emitPlaybackEvent(t,n={}){var r,i;(i=(r=this.options).onPlaybackEvent)==null||i.call(r,{event:t,...this.snapshot(),...n})}}const Zb={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},UN="min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none transition-colors placeholder:text-muted-foreground/65 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",Oie=800,WN=300,Die=1600;function H0(e,t){return e.filter(n=>!n.model||n.model===t)}function qN({label:e,children:t,help:n}){return v.jsxs("div",{className:"block min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 transition-colors focus-within:border-ring/55 focus-within:bg-card/75 sm:p-3",children:[v.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.jsx("div",{className:"mt-2 min-w-0",children:t}),n?v.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Bm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=_.useState(!1),u=_.useId(),d=n.find(g=>g.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(g=>!g.disabled),y=!!LB(h).detail;return v.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:g=>{g.currentTarget.contains(g.relatedTarget)||l(!1)},children:[v.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.jsxs("button",{type:"button","aria-labelledby":u,"aria-haspopup":"listbox","aria-expanded":o,disabled:p.length===0,className:`mt-2 flex w-full min-w-0 items-center justify-between gap-3 rounded-md border border-border bg-input px-3 text-left outline-none transition-colors hover:border-primary/40 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[v.jsx(VN,{label:h,muted:!d&&!t}),v.jsx(gl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?v.jsx("div",{role:"listbox","aria-labelledby":u,className:"mt-2 max-h-64 overflow-y-auto rounded-md border border-border/80 bg-popover p-1 shadow-sm",children:n.map(g=>{const b=g.value===t;return v.jsxs("button",{type:"button",role:"option","aria-label":g.label,"aria-selected":b,disabled:g.disabled,className:"flex w-full min-w-0 items-center gap-2 rounded-sm px-2.5 py-2.5 text-left text-sm outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-45",onClick:()=>{g.disabled||(r(g.value),l(!1))},children:[v.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:b?v.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),v.jsx(VN,{label:g.label})]},g.value)})}):null,s?v.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function VN({label:e,muted:t=!1}){const n=LB(e);return v.jsxs("span",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?v.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Pie({scrollRef:e}={}){const[t,n]=_.useState(Zb),[r,i]=_.useState(String(Zb.turnIdleSeconds)),[s,o]=_.useState(()=>Cm()),[l,u]=_.useState(""),[d,h]=_.useState(!1),[p,y]=_.useState(!1),[g,b]=_.useState({kind:"idle"}),w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(null);_.useEffect(()=>{const se=Mt;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te=!1;return b({kind:"loading"}),se.requestVoiceConfig().then(he=>{if(!te){if(he.error||!he.config){b({kind:"error",message:he.error??"读取语音设置失败"});return}n(he.config),i(String(he.config.turnIdleSeconds)),u(""),h(!1),y(!0),b({kind:"idle"})}}).catch(he=>{te||b({kind:"error",message:he instanceof Error?he.message:"读取语音设置失败"})}),()=>{te=!0}},[]),_.useEffect(()=>{const se=Mt;if(!se||!p)return;let te=!1;return se.requestVoiceCapabilities({region:t.region}).then(he=>{if(!te){if(he.error||!he.capabilities){o(Cm());return}o(he.capabilities)}}).catch(()=>{te||o(Cm())}),()=>{te=!0}},[t.region,p]),_.useEffect(()=>()=>{G(),B()},[]);const R=_.useMemo(()=>g.kind==="loading"?"读取中...":g.kind==="saving"?"保存中...":g.kind==="testing"?"正在测试语音合成":g.kind==="playingTest"?"正在播放测试音频":g.kind==="testPassed"?"测试通过":g.kind==="saved"?"已保存":g.kind==="error"?g.message:null,[g]),z=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",N=_.useMemo(()=>H0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=N.some(se=>se.value===t.ttsVoice)?t.ttsVoice:"",q=N.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",H=_.useMemo(()=>Bie(r),[r]),U=H?null:"请输入正整数秒数",O=q??U,M=z||!!O,I=_.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=_.useMemo(()=>GN(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),D=_.useMemo(()=>jie(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),Y=_.useMemo(()=>GN(N,P),[N,P]);function K(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:H??Zb.turnIdleSeconds}}async function F(){if(z)return;if(O){b({kind:"error",message:O});return}const se=Mt;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}const te=K();B(),b({kind:"saving"});const he=performance.now();try{const ge=await se.updateVoiceConfig(te),Ee=performance.now()-he;if(Ee<WN&&await zie(WN-Ee),!ge.success||ge.error||!ge.config){b({kind:"error",message:ge.error??"保存语音设置失败"});return}n(ge.config),i(String(ge.config.turnIdleSeconds)),u(""),h(!1),b({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,b(Re=>Re.kind==="saved"?{kind:"idle"}:Re)},Die),se.requestVoiceCapabilities({region:ge.config.region}).then(Re=>{Re.capabilities&&o(Re.capabilities)}).catch(()=>{o(Cm())})}catch(ge){b({kind:"error",message:ge instanceof Error?ge.message:"保存语音设置失败"})}}async function A(){if(z)return;if(O){b({kind:"error",message:O});return}const se=Mt;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te;try{te=W()}catch(he){b({kind:"error",message:KN(he)});return}b({kind:"testing"});try{const[he]=await Promise.all([se.testVoiceConfig(K()),te.ready]);if(!he.success||he.error){G(),b({kind:"error",message:he.error??"语音配置测试失败"});return}const ge=await ne(he,te.context);b({kind:"playingTest",transcript:he.transcript}),k.current=setTimeout(()=>{k.current=null,G(),b({kind:"testPassed",transcript:he.transcript})},ge)}catch(he){G(),b({kind:"error",message:KN(he)})}}function W(){G();const se=O1.acquire("playback");x.current=se;try{const te=Iie();return w.current=te,{context:te,ready:YN(te)}}catch(te){throw se.release(),x.current=null,te}}function G(){var se,te,he;k.current&&(clearTimeout(k.current),k.current=null),(se=E.current)==null||se.stop(),E.current=null,(te=w.current)==null||te.close(),w.current=null,(he=x.current)==null||he.release(),x.current=null}function B(){T.current&&(clearTimeout(T.current),T.current=null)}async function ne(se,te){if(!se.audioBase64)throw new Error("语音测试未返回可播放音频");if(se.audioEncoding&&se.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const he=se.audioSampleRate??24e3,ge=Lie(se.audioBase64);if(ge.byteLength===0||ge.byteLength%2!==0)throw new Error("测试音频数据无效");await YN(te);const Ee=new PB(te,he);E.current=Ee,Ee.enqueue(ge);const Re=Math.ceil(ge.byteLength/2/he*1e3);return Math.max(Oie,Re)}function ie(se){var te;return((te=H0(s.ttsVoices,se)[0])==null?void 0:te.value)??""}return v.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:se=>{se.preventDefault(),F()},children:[v.jsx("div",{className:"flex min-h-0 flex-1 flex-col px-4 py-3 sm:px-5 sm:py-3.5","data-slot":"voice-settings-body-frame",children:v.jsx("div",{className:"dev-render-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"voice-settings-scroll",ref:e,children:v.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[v.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsxs("div",{className:"min-w-0",children:[v.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),v.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),v.jsx("span",{className:"shrink-0 rounded-full border border-primary/35 bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:"Bailian"})]})}),v.jsx(qN,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:v.jsxs("div",{className:"flex min-w-0 gap-2",children:[v.jsxs("div",{className:"relative min-w-0 flex-1",children:[v.jsx(SP,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),v.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:se=>{u(se.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${UN} w-full pl-9`})]}),t.configured&&v.jsxs(St,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),h(!0)},children:[v.jsx(V8,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),v.jsx(Bm,{label:"地域",value:t.region,options:I,onChange:se=>n(te=>({...te,region:se==="intl"?"intl":"cn"}))}),v.jsx(Bm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:se=>n(te=>({...te,asrModel:se}))}),v.jsx(Bm,{label:"语音合成模型",value:t.ttsModel,options:D,onChange:se=>n(te=>({...te,ttsModel:se,ttsVoice:ie(se)}))}),v.jsx(Bm,{label:"语音音色",value:P,options:Y,placeholder:N.length===0?"暂无可用音色":"请选择音色",onChange:se=>n(te=>({...te,ttsVoice:se})),help:q}),v.jsx(qN,{label:"结束停顿时间(秒)",help:U,children:v.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:se=>i(se.target.value),className:`${UN} w-full`})})]})})}),v.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[v.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),v.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[R?v.jsx("div",{role:g.kind==="error"?"alert":"status","aria-live":"polite",className:g.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:R}):null,v.jsxs(St,{type:"button",variant:"outline",disabled:M,onClick:()=>void A(),children:[v.jsx(CP,{className:"size-4","aria-hidden":"true"}),"测试"]}),v.jsxs(St,{type:"submit",disabled:M,children:[v.jsx(D8,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Lie(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 Iie(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function YN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function KN(e){return e instanceof Error?e.message:"语音配置测试失败"}function zie(e){return new Promise(t=>setTimeout(t,e))}function Bie(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function GN(e,t){const n=e.map(r=>({value:r.value,label:IB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function jie(e,t,n){const r=e.map(i=>{const s=H0(t,i.value).length===0;return{value:i.value,label:`${IB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function LB(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 IB(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 Fie=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],$ie=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],D1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function zB(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 Hie(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Uie(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Wie(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function U0({open:e,onOpenChange:t}){const n=ze(q=>q.relayUrl),r=ze(q=>q.latencyMonitorEnabled),i=ze(q=>q.setLatencyMonitorEnabled),s=ze(q=>q.sessionIdleNotificationsEnabled),o=ze(q=>q.setSessionIdleNotificationsEnabled),l=ze(q=>q.inputModePreference),u=ze(q=>q.setInputModePreference),d=ze(q=>q.themePreference),h=ze(q=>q.setThemePreference),p=ze(q=>q.ptyScrollTraceEnabled),y=ze(q=>q.setPtyScrollTraceEnabled),[g,b]=_.useState("menu"),[w,x]=_.useState({kind:"idle"}),E=_.useRef(null),k=_.useRef(null),T=jZ(),R=_.useMemo(()=>Wx().osName==="iPad",[]),z=_.useCallback(async q=>{if(!q){o(!1);return}const H=await pZ();if(H==="granted"){o(!0);return}if(H==="denied"){nt.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(H==="default"){nt.info("未授予通知权限,会话通知保持关闭");return}nt.error("当前浏览器不支持系统通知")},[o]),N=_.useCallback(async q=>{x({kind:"loading"});try{const H=await fetch(Hie(n),{cache:"no-store",signal:q});if(!H.ok)throw new Error(`HTTP ${H.status}`);const U=await H.json();if(U.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:U.version??"未知",uptime:U.uptime??0})}catch(H){if(H instanceof DOMException&&H.name==="AbortError")return;x({kind:"error",message:H instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);_.useEffect(()=>{if(!e){b("menu");return}},[e]),_.useEffect(()=>{if(!e||g!=="version")return;const q=new AbortController;return N(q.signal),()=>q.abort()},[N,e,g]),_.useEffect(()=>{if(!e||g!=="voice")return;const q=window.requestAnimationFrame(()=>{var H;(H=E.current)==null||H.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(q)},[e,g]);const $=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${zB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return v.jsx(Sc,{open:e,onOpenChange:t,children:v.jsxs(xc,{className:We("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":g,focusSurfaceOnOpen:!0,ref:E,showCloseButton:g==="menu",children:[v.jsx(Ec,{className:We(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"flex items-start gap-2",children:[v.jsx(St,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>b("menu"),children:v.jsx(vv,{className:"size-4","aria-hidden":"true"})}),v.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[v.jsx(dl,{children:Uie(g)}),v.jsx(dc,{className:"max-w-[28rem] leading-5",children:Wie(g)})]})]}),g==="voice"?v.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):v.jsxs(v.Fragment,{children:[v.jsx(dl,{children:"设置"}),v.jsx(dc,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?v.jsx(qie,{relayVersion:$,relayDetail:P,relayMuted:w.kind==="error"}):g==="relay-token"?v.jsx(Yie,{saved:T}):g==="clients"?v.jsx(Qie,{}):g==="voice"?v.jsx(Pie,{scrollRef:k}):v.jsx(Vie,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:R,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:z,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>b("voice"),onOpenRelayToken:()=>b("relay-token"),onOpenClients:()=>b("clients"),onOpenVersion:()=>b("version")})]})})}function qie({relayVersion:e,relayDetail:t,relayMuted:n}){return v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsx(ZN,{icon:v.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Cie.version,detail:"当前浏览器加载的版本"}),v.jsx(ZN,{icon:v.jsx(kP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Vie({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:h,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:g,onOpenClients:b,onOpenVersion:w}){return v.jsxs("div",{className:"dev-render-scroll min-h-0 space-y-4 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"settings-dialog-body",children:[v.jsxs(cu,{title:"服务",children:[v.jsx(jm,{icon:v.jsx(k9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),v.jsx(jm,{icon:v.jsx(SP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),v.jsx(jm,{icon:v.jsx(J8,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:b})]}),v.jsx(cu,{title:"外观",children:v.jsx(XN,{icon:v.jsx(U8,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Fie,onValueChange:n})}),v.jsx(cu,{title:"通知",children:v.jsx(Jb,{icon:v.jsx(R9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?v.jsx(cu,{title:"交互",children:v.jsx(XN,{icon:v.jsx(xP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:$ie,onValueChange:i})}):null,v.jsxs(cu,{title:"高级诊断",children:[v.jsx(Jb,{icon:v.jsx(of,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),v.jsx(Jb,{icon:v.jsx(gP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),v.jsx(cu,{title:"关于",children:v.jsx(jm,{icon:v.jsx(kP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({title:e,children:t}){return v.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[v.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),v.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function XN({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=_.useId(),l=_.useId();return v.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[v.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,v.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return v.jsx("button",{type:"button",role:"radio","aria-checked":d,className:We("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Yie({saved:e}){const t=_.useId(),n=_.useId(),[r,i]=_.useState(""),[s,o]=_.useState(null),l=()=>{HL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}FL(h),l()},d=()=>{$L(),l()};return v.jsxs("form",{className:D1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[v.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[v.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),v.jsx("input",{id:t,type:"password",value:r,onChange:h=>{i(h.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?v.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),v.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?v.jsx(St,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,v.jsx(St,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Kie(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Gie(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Kie(e)}function Xie(e){return iX(e)}function Zie(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return zB(t)}function Qb({label:e,value:t,title:n}){return v.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[v.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),v.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function Qie(){const e=ze(y=>y.proxies),[t,n]=_.useState([]),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,u]=_.useState(null),d=_.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),h=_.useCallback(async()=>{const y=Mt;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);_.useEffect(()=>{h()},[h]);const p=_.useCallback(async y=>{const g=Mt;if(!g){o("Relay 未连接。");return}u(y),o(null);try{const b=await g.kickRelayClient(y);if(!b.success){o(b.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(b){o(b instanceof Error?b.message:"断开客户端失败。")}finally{u(null)}},[]);return v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:v.jsx(Tx,{className:We("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?v.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?v.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const g=y.current===!0,b=l===y.clientId;return v.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children:v.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[v.jsxs("div",{className:"min-w-0 space-y-1.5",children:[v.jsx("div",{className:"min-w-0",children:v.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Xie(y)})}),v.jsxs("div",{className:"space-y-1",children:[v.jsx(Qb,{label:"已连接",value:Zie(y.connectedAt)}),y.proxyId?v.jsx(Qb,{label:"连接到",value:Gie(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?v.jsx(Qb,{label:"来源 IP",value:y.remoteAddress}):null]})]}),g?v.jsx("div",{className:"inline-flex h-9 w-full items-center justify-center rounded-md border border-primary/30 bg-primary/10 px-3 text-sm font-normal text-primary","aria-label":"当前设备","data-slot":"relay-client-current-indicator",children:"当前设备"}):v.jsxs(St,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:b,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[v.jsx(c8,{className:"size-3.5","aria-hidden":"true"}),b?"断开中...":"断开"]})]})},y.clientId)})]})}function Jb({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=_.useId(),o=_.useId();return v.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[v.jsx("div",{className:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),v.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),v.jsx("span",{className:We("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:v.jsx("span",{className:We("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function jm({icon:e,label:t,detail:n,onClick:r}){const i=_.useId(),s=_.useId();return v.jsxs("button",{type:"button",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:r,"aria-labelledby":i,"aria-describedby":n?s:void 0,"data-slot":"settings-menu-item",children:[v.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground transition-colors group-hover:text-foreground",children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),v.jsx(Kh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function ZN({icon:e,label:t,value:n,detail:r,muted:i=!1}){return v.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[v.jsx("div",{className:We("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[v.jsx("div",{className:"text-sm text-muted-foreground",children:t}),v.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const Jie="xterm-helper-textarea";function ese(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Jie)?!1:(e.blur(),!0)}function QN(e,t,n){if(!e||Math.abs(n)<1)return!1;let r=e instanceof Element?e:null;for(;r&&t.contains(r);){if(r instanceof HTMLElement&&tse(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function tse(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 nse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=_.useRef(null),r=_.useCallback(()=>{e&&ese()},[e]),i=_.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=_.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const h=(n.current??u.clientY)-u.clientY;n.current=u.clientY,QN(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=_.useCallback(l=>{r(),t&&(QN(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function rse({className:e}){const t=ze(o=>o.sidebarCollapsed),n=ze(o=>o.toggleSidebarCollapsed),[r,i]=_.useState(!1),s=nse();return t?v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:We("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[v.jsx(eM,{collapsed:!0,onClick:n}),v.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),v.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[v.jsx(JN,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),v.jsx(jN,{compact:!0})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]}):v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:We("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[v.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:v.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx(qP,{className:"text-[13px]",slot:"sidebar-brand"}),v.jsx(eM,{collapsed:!1,onClick:n})]}),v.jsx("div",{className:"mt-2.5",children:v.jsx(SB,{layout:"dropdown",variant:"sidebarChrome"})})]})}),v.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:v.jsx("div",{className:"flex-1 min-h-0",children:v.jsx(MB,{layout:"sidebar"})})}),v.jsxs("div",{className:"dev-sidebar-fade flex shrink-0 gap-2 px-2 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-2","data-slot":"sidebar-new-session",children:[v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(jN,{})}),v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(JN,{onClick:()=>i(!0)})})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]})}function JN({compact:e=!1,tooltipSide:t="top",onClick:n}){return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[v.jsx(TP,{className:"size-4","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),v.jsx(Wf,{side:t,sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:"设置"})]})}function eM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?_8:v8;return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:v.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),v.jsx(Wf,{side:e?"right":"top",sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:n})]})}const ise=1500,sse=300,tM=70,nM=35;function BB({texts:e,className:t}){const[n,r]=_.useState(""),[i,s]=_.useState(!0),o=_.useRef("typing"),l=_.useRef(0),u=_.useRef(0);return _.useEffect(()=>{const d=setInterval(()=>s(h=>!h),530);return()=>clearInterval(d)},[]),_.useEffect(()=>{let d;const h=()=>e[u.current%e.length],p=()=>{const y=o.current;if(y==="typing"){const g=h();l.current<g.length?(l.current+=1,r(g.slice(0,l.current)),d=setTimeout(p,tM)):(o.current="paused",d=setTimeout(p,ise))}else y==="paused"?(o.current="deleting",d=setTimeout(p,nM)):y==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),d=setTimeout(p,nM)):(u.current+=1,o.current="waiting",d=setTimeout(p,sse)):(o.current="typing",d=setTimeout(p,tM))};return d=setTimeout(p,500),()=>clearTimeout(d)},[e]),v.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[v.jsx("span",{className:"text-green-500",children:"> "}),v.jsx("span",{className:"text-foreground/90",children:n}),v.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const jB=["DEV Anywhere","/unlimited @anytime"];function ose({subtitle:e,action:t}){return v.jsx("section",{className:"dev-mobile-brand-hero border-b border-border/80 px-4 pb-5 pt-[calc(env(safe-area-inset-top)+1.25rem)] md:hidden","data-slot":"mobile-brand-hero","aria-label":"DEV Anywhere",children:v.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[v.jsx(BB,{texts:jB,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),v.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?v.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const ase=3e3,lse=1e4,Fm=12,cse=4,rM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},use={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function ew(e){if(!e.success||e.rttMs===void 0)return{state:"unavailable",error:e.error??"不可用",updatedAt:Date.now()};const t=e.rttMs;return{state:t<=120?"ok":t<=300?"warn":"bad",rttMs:t,updatedAt:Date.now()}}function uu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Bh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function iM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function FB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function dse(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 hse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Bh(e.rttMs):"等待检测"}function fse(){const e=ki("local",ln.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function sM(e){dr("local",ln.latencyMonitorPosition,JSON.stringify(e))}function pse(){var e,t;return{width:((e=window.visualViewport)==null?void 0:e.width)??window.innerWidth??document.documentElement.clientWidth??0,height:((t=window.visualViewport)==null?void 0:t.height)??window.innerHeight??document.documentElement.clientHeight??0}}function tw(e,t){const n=pse(),r=Fm,i=Fm,s=Math.max(r,n.width-t.width-Fm),o=Math.max(i,n.height-t.height-Fm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function mse(){const e=ze(N=>N.latencyMonitorEnabled),t=ze(N=>N.connected),n=ze(N=>N.proxyOnline),r=ze(N=>N.selectedProxyId),[i,s]=_.useState(use),[o,l]=_.useState(()=>fse()),u=_.useRef(!1),d=_.useRef(null),h=_.useRef(null),p=_.useRef(!1),y=_.useMemo(()=>(Object.values(i).sort((N,$)=>iM($.state)-iM(N.state))[0]??{state:"idle"}).state,[i]),g=FB(y);async function b(){if(u.current)return;const N=Mt;if(!N||!t){const H=uu("Relay 服务器未连接");s({webRelay:H,relayProxy:H,webProxy:H});return}u.current=!0,s(H=>({webRelay:{...H.webRelay,state:"measuring"},relayProxy:n?{...H.relayProxy,state:"measuring"}:uu("未连接开发机"),webProxy:n?{...H.webProxy,state:"measuring"}:uu("未连接开发机")}));const[$,P,q]=await Promise.allSettled([N.measureWebRelayLatency(),n?N.measureRelayProxyLatency():Promise.resolve({success:!1}),n?N.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:$.status==="fulfilled"?ew($.value):uu($.reason instanceof Error?$.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?ew(P.value):uu(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:q.status==="fulfilled"?ew(q.value):uu(q.reason instanceof Error?q.reason.message:"测速失败")}),u.current=!1}if(_.useEffect(()=>{if(!e)return;let N=!1,$=null;const P=async()=>{await b(),!N&&($=setTimeout(P,document.hidden?lse:ase))};return P(),()=>{N=!0,u.current=!1,$&&clearTimeout($)}},[e,t,n,r]),_.useEffect(()=>{if(!e||!o)return;const N=d.current;if(!N)return;const $=N.getBoundingClientRect(),P=tw(o,{width:$.width,height:$.height});P.x===o.x&&P.y===o.y||(l(P),sM(P))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,x=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function E(N){var P,q;if(N.button!==0)return;const $=N.currentTarget.getBoundingClientRect();h.current={pointerId:N.pointerId,startX:N.clientX,startY:N.clientY,originX:$.left,originY:$.top,width:$.width,height:$.height,dragging:!1},(q=(P=N.currentTarget).setPointerCapture)==null||q.call(P,N.pointerId)}function k(N){const $=h.current;if(!$||$.pointerId!==N.pointerId)return;const P=N.clientX-$.startX,q=N.clientY-$.startY;if(!$.dragging&&Math.hypot(P,q)<cse)return;$.dragging=!0,N.preventDefault();const H=tw({x:$.originX+P,y:$.originY+q},{width:$.width,height:$.height});l(H)}function T(N){var U,O;const $=h.current;if(!$||$.pointerId!==N.pointerId||(h.current=null,(O=(U=N.currentTarget).releasePointerCapture)==null||O.call(U,N.pointerId),!$.dragging))return;N.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=N.clientX-$.startX,q=N.clientY-$.startY,H=tw({x:$.originX+P,y:$.originY+q},{width:$.width,height:$.height});l(H),sM(H)}function R(N){var P,q;const $=h.current;!$||$.pointerId!==N.pointerId||(h.current=null,(q=(P=N.currentTarget).releasePointerCapture)==null||q.call(P,N.pointerId))}function z(N){p.current&&(p.current=!1,N.preventDefault(),N.stopPropagation())}return v.jsxs(E1,{children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{ref:d,type:"button",className:We("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",dse(g)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Bh(i.webRelay.rttMs)},开发机 ${Bh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:T,onPointerCancel:R,onClickCapture:z,children:[v.jsx(gP,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),v.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",Bh(i.webRelay.rttMs)]}),v.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Bh(w.rttMs)]}),v.jsx(gl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),v.jsxs(k1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[v.jsxs("div",{className:"flex items-start justify-between gap-3",children:[v.jsxs("div",{children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void b(),children:v.jsx(Tx,{className:"size-3","aria-hidden":"true"})})]}),v.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(rM).map(N=>v.jsx(gse,{label:rM[N],measurement:i[N]},N))})]})]})}function gse({label:e,measurement:t}){const n=FB(t.state);return v.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[v.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx("span",{className:We("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),v.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:hse(t)})]})]})}const $B="/__dev_anywhere_debug/browser-state-dumps",vse=1500,yse=10,nw=80,P1=500,_se=["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"],bse=["display","position","visibility","opacity","pointer-events","z-index","overflow","overflow-x","overflow-y","touch-action","transform","translate","color-scheme","background-color","color","font-size","line-height","padding-top","padding-right","padding-bottom","padding-left","margin-top","margin-right","margin-bottom","margin-left"];function oM(){if(typeof window>"u")return"off";const e=GB("debugDump");return e==="auto"?"auto":e!==null||Ase("debugInput")?"manual":"off"}function wse(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:Cse(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:aM(document.activeElement),selection:kse(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>aM(i)).filter(i=>!!i),root:HB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:du(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:du(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:du(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:du(()=>lM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>lM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function Sse(e="manual"){const t=wse(e);return xse(t)}async function xse(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Ese(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:$B}}catch(r){const i=XB(r),s=Tse(e.createdAt);return Rse(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Ese(e){const t=await fetch($B,{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 HB(e,t,n){if(n.count>=vse||t>yse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=cM(e.textContent??"");return u?{kind:"text",text:Xv(u,P1)}:{kind:"text",text:""}}if(!(e instanceof HTMLElement))return{kind:"truncated"};const r=[];let i=0;const s=Array.from(e.childNodes);for(const u of s.slice(0,nw))u.nodeType===Node.TEXT_NODE&&!cM(u.textContent??"")||r.push(HB(u,t+1,n));s.length>nw&&(i=s.length-nw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:KB(e),attrs:UB(e),rect:WB(e),scroll:qB(e),style:VB(e)},l=YB(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function aM(e){if(!(e instanceof HTMLElement))return null;const t=YB(e);return{path:KB(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:UB(e),rect:WB(e),scroll:qB(e),style:VB(e),...t?{value:t}:{}}}function Cse(){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 UB(e){const t={};for(const n of _se){const r=e.getAttribute(n);r!==null&&(t[n]=Xv(r,500))}return t}function WB(e){const t=e.getBoundingClientRect();return{x:Zi(t.x),y:Zi(t.y),width:Zi(t.width),height:Zi(t.height),top:Zi(t.top),right:Zi(t.right),bottom:Zi(t.bottom),left:Zi(t.left)}}function qB(e){return{top:Zi(e.scrollTop),left:Zi(e.scrollLeft),height:Zi(e.scrollHeight),width:Zi(e.scrollWidth),clientHeight:Zi(e.clientHeight),clientWidth:Zi(e.clientWidth)}}function VB(e){const t=window.getComputedStyle(e),n={};for(const r of bse)n[r]=t.getPropertyValue(r);return n}function YB(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Xv(e.value,P1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function kse(){var e;try{return Xv(((e=window.getSelection())==null?void 0:e.toString())??"",P1)}catch{return null}}function KB(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 Tse(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Rse(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 Ase(e){return GB(e)!==null}function GB(e){const t=new URLSearchParams(window.location.search);if(t.has(e))return t.get(e)??"";const[,n=""]=window.location.hash.split("?"),r=new URLSearchParams(n);return r.has(e)?r.get(e)??"":null}function lM(e){return e?Gg(e.slice(-200)):null}function du(e){try{return Gg(e())}catch(t){return{error:XB(t)}}}function Gg(e){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(Array.isArray(e))return e.map(Gg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Gg(r);return t}return String(e)}function cM(e){return e.replace(/\s+/g," ").trim()}function Xv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Zi(e){return Math.round(e*100)/100}function XB(e){return e instanceof Error?e.message:String(e)}const Nse=500,Mse=1e3,Ose=60;function Dse(){const[e,t]=_.useState(()=>oM()),[n,r]=_.useState(!1),[i,s]=_.useState(null),o=_.useRef(null),l=_.useRef(!1),u=_.useRef(0),d=_.useRef(0),h=_.useRef(null);_.useEffect(()=>{const b=()=>t(oM());return window.addEventListener("hashchange",b),window.addEventListener("popstate",b),()=>{window.removeEventListener("hashchange",b),window.removeEventListener("popstate",b)}},[]);const p=_.useCallback(async(b="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await Sse(b);return o.current=w,s(w),(b==="manual"||w.status==="failed")&&Pse(w),w}finally{l.current=!1,r(!1)}},[]);if(_.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),_.useEffect(()=>{var k,T;if(e!=="auto")return;const b=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=R=>{d.current>=Ose||(b(),h.current=window.setTimeout(()=>{h.current=null;const z=Date.now(),N=Mse-(z-u.current);if(N>0){h.current=window.setTimeout(()=>w(R),N);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${R}`)},Nse))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=R=>w(R.type);return x.forEach(R=>window.addEventListener(R,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(T=window.visualViewport)==null||T.addEventListener("scroll",E),()=>{var R,z;b(),x.forEach(N=>window.removeEventListener(N,E,!0)),(R=window.visualViewport)==null||R.removeEventListener("resize",E),(z=window.visualViewport)==null||z.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",g=Lse(i);return v.jsxs("div",{className:"fixed bottom-3 right-3 z-[90] flex max-w-[min(360px,calc(100vw-24px))] flex-col items-end gap-1",children:[g?v.jsx("div",{className:"max-w-full truncate rounded-md border border-border/70 bg-popover/95 px-2 py-1 text-[10px] text-muted-foreground shadow",children:g}):null,v.jsxs(St,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void p("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?v.jsx(Lu,{className:"size-3.5 animate-spin","aria-hidden":"true"}):v.jsx(J9,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{children:y})]})]})}function Pse(e){if(e.status==="saved"){nt.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){nt.info(`诊断已下载: ${e.filename}`);return}nt.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Lse(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Ise(e){if(typeof window>"u")return null;try{const t=window.localStorage;return!t||typeof t.getItem!="function"?null:t.getItem(e)}catch{return null}}function L1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:Ise(n)==="1",l=()=>typeof window>"u"?[]:window[t]??[],u=d=>{typeof window>"u"||(window[t]=d)};return{isEnabled:o,append(d){if(typeof window>"u")return;const h=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&h.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const g=h.indexOf(y);g>=0&&g!==h.length-1&&(h.splice(g,1),h.push(y)),u(h);return}}}if(h.push(d),i&&s.set(d.event,d),h.length>r){const p=h.splice(0,h.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(h)},getAll:l}}function Cn(e){return Math.round(e*10)/10}function Ka(e){return e.length===0?"":`${Cn(Math.min(...e))}..${Cn(Math.max(...e))}`}function Au(e){return[...new Set(e.filter(t=>t!==void 0).map(Cn))]}function ZB(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 zse="dev_anywhere_pty_input_latency_trace",uM=80,Bse=1e4,jse=new TextDecoder;let Fse=0;const Ku=new Map,Cc=L1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:zse,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function $se(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=qse)}function Hse(e,t){if(!Cc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Fse}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Kse(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),z1(s,r),Ku.set(e,s),qf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function dM(e,t){if(!e||!Cc.isEnabled())return;const n=performance.now(),r=Vse(e.sessionId,e.inputId);r&&(r.sentAt=n),qf({t:n,event:"input:ws-send",sessionId:e.sessionId,inputId:e.inputId,inputKind:r==null?void 0:r.kind,dataLength:r==null?void 0:r.dataLength,sent:t.sent,queueWhenDisconnected:t.queueWhenDisconnected,deltaFromInputMs:r?n-r.startedAt:null,details:t.details})}function Use(e,t,n){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=Zse(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Xse(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));qf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:Qse([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Wse(e,t,n=1){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));qf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Yse(e,s))}function qse(){const e=Cc.getAll(),t=e.slice(-200),n=[...Ku.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Cn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Cn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Cn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Cn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Cn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Cn(s.t),s.repeat&&s.repeat>0?`${s.event} +${s.repeat}`:s.event,s.sessionId,s.inputId??"",s.inputKind??"",s.dataLength??"",s.sent===void 0?"":s.sent?"sent":"not-sent",s.queueWhenDisconnected?"queue-ok":"",s.outputSeq??"",s.bytes??"",s.chunkCount??"",s.pendingInputs??"",s.deltaFromInputMs===void 0||s.deltaFromInputMs===null?"":Cn(s.deltaFromInputMs),s.details??""].join(" "));return["DEV Anywhere PTY input latency trace",`events=${e.length}, included=${t.length}, pendingInputs=${n.length}`,"pending input summary:","inputId sessionId kind len wsSendMs firstOutputMs echoMatchMs xtermWriteMs paintMs",...r,"events:","t event sessionId inputId kind len sent queue outputSeq bytes chunks pending deltaMs details",...i].join(`
500
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},vJ="DialogDescriptionWarning",yJ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${bI(vJ).contentName}}.`;return _.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},e1=oI,_J=lI,t1=uI,n1=dI,r1=hI,wI=pI,SI=gI,i1=yI;function bJ(e){const t=_.useRef({value:e,previous:e});return _.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function wJ(e){const[t,n]=_.useState(void 0);return Ti(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const u=s.borderBoxSize,d=Array.isArray(u)?u[0]:u;o=d.inlineSize,l=d.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const SJ=["top","right","bottom","left"],cl=Math.min,hs=Math.max,$g=Math.round,Lm=Math.floor,Eo=e=>({x:e,y:e}),xJ={left:"right",right:"left",bottom:"top",top:"bottom"};function C0(e,t,n){return hs(e,cl(t,n))}function sa(e,t){return typeof e=="function"?e(t):e}function oa(e){return e.split("-")[0]}function sd(e){return e.split("-")[1]}function s1(e){return e==="x"?"y":"x"}function o1(e){return e==="y"?"height":"width"}function So(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function a1(e){return s1(So(e))}function EJ(e,t,n){n===void 0&&(n=!1);const r=sd(e),i=a1(e),s=o1(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Hg(o)),[o,Hg(o)]}function CJ(e){const t=Hg(e);return[k0(e),t,k0(t)]}function k0(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gN=["left","right"],vN=["right","left"],kJ=["top","bottom"],TJ=["bottom","top"];function RJ(e,t,n){switch(e){case"top":case"bottom":return n?t?vN:gN:t?gN:vN;case"left":case"right":return t?kJ:TJ;default:return[]}}function AJ(e,t,n,r){const i=sd(e);let s=RJ(oa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(k0)))),s}function Hg(e){const t=oa(e);return xJ[t]+e.slice(t.length)}function NJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function xI(e){return typeof e!="number"?NJ(e):{top:e,right:e,bottom:e,left:e}}function Ug(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function yN(e,t,n){let{reference:r,floating:i}=e;const s=So(t),o=a1(t),l=o1(o),u=oa(t),d=s==="y",h=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:p};break;case"left":g={x:r.x-i.width,y:p};break;default:g={x:r.x,y:r.y}}switch(sd(t)){case"start":g[o]-=y*(n&&d?-1:1);break;case"end":g[o]+=y*(n&&d?-1:1);break}return g}async function MJ(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:p="floating",altBoundary:y=!1,padding:g=0}=sa(t,e),b=xI(g),x=l[y?p==="floating"?"reference":"floating":p],E=Ug(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),R=await(s.isElement==null?void 0:s.isElement(T))?await(s.getScale==null?void 0:s.getScale(T))||{x:1,y:1}:{x:1,y:1},z=Ug(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:T,strategy:u}):k);return{top:(E.top-z.top+b.top)/R.y,bottom:(z.bottom-E.bottom+b.bottom)/R.y,left:(E.left-z.left+b.left)/R.x,right:(z.right-E.right+b.right)/R.x}}const OJ=50,DJ=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:MJ},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=yN(d,r,u),y=r,g=0;const b={};for(let w=0;w<s.length;w++){const x=s[w];if(!x)continue;const{name:E,fn:k}=x,{x:T,y:R,data:z,reset:N}=await k({x:h,y:p,initialPlacement:r,placement:y,strategy:i,middlewareData:b,rects:d,platform:l,elements:{reference:e,floating:t}});h=T??h,p=R??p,b[E]={...b[E],...z},N&&g<OJ&&(g++,typeof N=="object"&&(N.placement&&(y=N.placement),N.rects&&(d=N.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:h,y:p}=yN(d,y,u)),w=-1)}return{x:h,y:p,placement:y,strategy:i,middlewareData:b}},PJ=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=sa(e,t)||{};if(d==null)return{};const p=xI(h),y={x:n,y:r},g=a1(i),b=o1(g),w=await o.getDimensions(d),x=g==="y",E=x?"top":"left",k=x?"bottom":"right",T=x?"clientHeight":"clientWidth",R=s.reference[b]+s.reference[g]-y[g]-s.floating[b],z=y[g]-s.reference[g],N=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let $=N?N[T]:0;(!$||!await(o.isElement==null?void 0:o.isElement(N)))&&($=l.floating[T]||s.floating[b]);const P=R/2-z/2,q=$/2-w[b]/2-1,H=cl(p[E],q),U=cl(p[k],q),O=H,M=$-w[b]-U,I=$/2-w[b]/2+P,L=C0(O,I,M),D=!u.arrow&&sd(i)!=null&&I!==L&&s.reference[b]/2-(I<O?H:U)-w[b]/2<0,Y=D?I<O?I-O:I-M:0;return{[g]:y[g]+Y,data:{[g]:L,centerOffset:I-L-Y,...D&&{alignmentOffset:Y}},reset:D}}}),LJ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:w=!0,...x}=sa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const E=oa(i),k=So(l),T=oa(l)===l,R=await(u.isRTL==null?void 0:u.isRTL(d.floating)),z=y||(T||!w?[Hg(l)]:CJ(l)),N=b!=="none";!y&&N&&z.push(...AJ(l,w,b,R));const $=[l,...z],P=await u.detectOverflow(t,x),q=[];let H=((r=s.flip)==null?void 0:r.overflows)||[];if(h&&q.push(P[E]),p){const I=EJ(i,o,R);q.push(P[I[0]],P[I[1]])}if(H=[...H,{placement:i,overflows:q}],!q.every(I=>I<=0)){var U,O;const I=(((U=s.flip)==null?void 0:U.index)||0)+1,L=$[I];if(L&&(!(p==="alignment"?k!==So(L):!1)||H.every(K=>So(K.placement)===k?K.overflows[0]>0:!0)))return{data:{index:I,overflows:H},reset:{placement:L}};let D=(O=H.filter(Y=>Y.overflows[0]<=0).sort((Y,K)=>Y.overflows[1]-K.overflows[1])[0])==null?void 0:O.placement;if(!D)switch(g){case"bestFit":{var M;const Y=(M=H.filter(K=>{if(N){const F=So(K.placement);return F===k||F==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(F=>F>0).reduce((F,A)=>F+A,0)]).sort((K,F)=>K[1]-F[1])[0])==null?void 0:M[0];Y&&(D=Y);break}case"initialPlacement":D=l;break}if(i!==D)return{reset:{placement:D}}}return{}}}};function _N(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function bN(e){return SJ.some(t=>e[t]>=0)}const IJ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=sa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=_N(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:bN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=_N(o,n.floating);return{data:{escapedOffsets:l,escaped:bN(l)}}}default:return{}}}}},EI=new Set(["left","top"]);async function zJ(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=oa(n),l=sd(n),u=So(n)==="y",d=EI.has(o)?-1:1,h=s&&u?-1:1,p=sa(t,e);let{mainAxis:y,crossAxis:g,alignmentAxis:b}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof b=="number"&&(g=l==="end"?b*-1:b),u?{x:g*h,y:y*d}:{x:y*d,y:g*h}}const BJ=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 zJ(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}}}}},jJ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:u={fn:E=>{let{x:k,y:T}=E;return{x:k,y:T}}},...d}=sa(e,t),h={x:n,y:r},p=await s.detectOverflow(t,d),y=So(oa(i)),g=s1(y);let b=h[g],w=h[y];if(o){const E=g==="y"?"top":"left",k=g==="y"?"bottom":"right",T=b+p[E],R=b-p[k];b=C0(T,b,R)}if(l){const E=y==="y"?"top":"left",k=y==="y"?"bottom":"right",T=w+p[E],R=w-p[k];w=C0(T,w,R)}const x=u.fn({...t,[g]:b,[y]:w});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[g]:o,[y]:l}}}}}},FJ=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:u=!0,crossAxis:d=!0}=sa(e,t),h={x:n,y:r},p=So(i),y=s1(p);let g=h[y],b=h[p];const w=sa(l,t),x=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const T=y==="y"?"height":"width",R=s.reference[y]-s.floating[T]+x.mainAxis,z=s.reference[y]+s.reference[T]-x.mainAxis;g<R?g=R:g>z&&(g=z)}if(d){var E,k;const T=y==="y"?"width":"height",R=EI.has(oa(i)),z=s.reference[p]-s.floating[T]+(R&&((E=o.offset)==null?void 0:E[p])||0)+(R?0:x.crossAxis),N=s.reference[p]+s.reference[T]+(R?0:((k=o.offset)==null?void 0:k[p])||0)-(R?x.crossAxis:0);b<z?b=z:b>N&&(b=N)}return{[y]:g,[p]:b}}}},$J=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:u=()=>{},...d}=sa(e,t),h=await o.detectOverflow(t,d),p=oa(i),y=sd(i),g=So(i)==="y",{width:b,height:w}=s.floating;let x,E;p==="top"||p==="bottom"?(x=p,E=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(E=p,x=y==="end"?"top":"bottom");const k=w-h.top-h.bottom,T=b-h.left-h.right,R=cl(w-h[x],k),z=cl(b-h[E],T),N=!t.middlewareData.shift;let $=R,P=z;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=T),(r=t.middlewareData.shift)!=null&&r.enabled.y&&($=k),N&&!y){const H=hs(h.left,0),U=hs(h.right,0),O=hs(h.top,0),M=hs(h.bottom,0);g?P=b-2*(H!==0||U!==0?H+U:hs(h.left,h.right)):$=w-2*(O!==0||M!==0?O+M:hs(h.top,h.bottom))}await u({...t,availableWidth:P,availableHeight:$});const q=await o.getDimensions(l.floating);return b!==q.width||w!==q.height?{reset:{rects:!0}}:{}}}};function Nv(){return typeof window<"u"}function od(e){return CI(e)?(e.nodeName||"").toLowerCase():"#document"}function fs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function No(e){var t;return(t=(CI(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function CI(e){return Nv()?e instanceof Node||e instanceof fs(e).Node:!1}function Xs(e){return Nv()?e instanceof Element||e instanceof fs(e).Element:!1}function la(e){return Nv()?e instanceof HTMLElement||e instanceof fs(e).HTMLElement:!1}function wN(e){return!Nv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof fs(e).ShadowRoot}function Lf(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Zs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function HJ(e){return/^(table|td|th)$/.test(od(e))}function Mv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const UJ=/transform|translate|scale|rotate|perspective|filter/,WJ=/paint|layout|strict|content/,Wl=e=>!!e&&e!=="none";let Wb;function l1(e){const t=Xs(e)?Zs(e):e;return Wl(t.transform)||Wl(t.translate)||Wl(t.scale)||Wl(t.rotate)||Wl(t.perspective)||!c1()&&(Wl(t.backdropFilter)||Wl(t.filter))||UJ.test(t.willChange||"")||WJ.test(t.contain||"")}function qJ(e){let t=ul(e);for(;la(t)&&!Wu(t);){if(l1(t))return t;if(Mv(t))return null;t=ul(t)}return null}function c1(){return Wb==null&&(Wb=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Wb}function Wu(e){return/^(html|body|#document)$/.test(od(e))}function Zs(e){return fs(e).getComputedStyle(e)}function Ov(e){return Xs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ul(e){if(od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||wN(e)&&e.host||No(e);return wN(t)?t.host:t}function kI(e){const t=ul(e);return Wu(t)?e.ownerDocument?e.ownerDocument.body:e.body:la(t)&&Lf(t)?t:kI(t)}function hf(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=kI(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=fs(i);if(s){const l=T0(o);return t.concat(o,o.visualViewport||[],Lf(i)?i:[],l&&n?hf(l):[])}else return t.concat(i,hf(i,[],n))}function T0(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function TI(e){const t=Zs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=la(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=$g(n)!==s||$g(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function u1(e){return Xs(e)?e:e.contextElement}function Bu(e){const t=u1(e);if(!la(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=TI(t);let o=(s?$g(n.width):n.width)/r,l=(s?$g(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const VJ=Eo(0);function RI(e){const t=fs(e);return!c1()||!t.visualViewport?VJ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function YJ(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==fs(e)?!1:t}function lc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=u1(e);let o=Eo(1);t&&(r?Xs(r)&&(o=Bu(r)):o=Bu(e));const l=YJ(s,n,r)?RI(s):Eo(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,h=i.width/o.x,p=i.height/o.y;if(s){const y=fs(s),g=r&&Xs(r)?fs(r):r;let b=y,w=T0(b);for(;w&&r&&g!==b;){const x=Bu(w),E=w.getBoundingClientRect(),k=Zs(w),T=E.left+(w.clientLeft+parseFloat(k.paddingLeft))*x.x,R=E.top+(w.clientTop+parseFloat(k.paddingTop))*x.y;u*=x.x,d*=x.y,h*=x.x,p*=x.y,u+=T,d+=R,b=fs(w),w=T0(b)}}return Ug({width:h,height:p,x:u,y:d})}function Dv(e,t){const n=Ov(e).scrollLeft;return t?t.left+n:lc(No(e)).left+n}function AI(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Dv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function KJ(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=No(r),l=t?Mv(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=Eo(1);const h=Eo(0),p=la(r);if((p||!p&&!s)&&((od(r)!=="body"||Lf(o))&&(u=Ov(r)),p)){const g=lc(r);d=Bu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const y=o&&!p&&!s?AI(o,u):Eo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+y.x,y:n.y*d.y-u.scrollTop*d.y+h.y+y.y}}function GJ(e){return Array.from(e.getClientRects())}function XJ(e){const t=No(e),n=Ov(e),r=e.ownerDocument.body,i=hs(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=hs(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Dv(e);const l=-n.scrollTop;return Zs(r).direction==="rtl"&&(o+=hs(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const SN=25;function ZJ(e,t){const n=fs(e),r=No(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const h=c1();(!h||h&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Dv(r);if(d<=0){const h=r.ownerDocument,p=h.body,y=getComputedStyle(p),g=h.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,b=Math.abs(r.clientWidth-p.clientWidth-g);b<=SN&&(s-=b)}else d<=SN&&(s+=d);return{width:s,height:o,x:l,y:u}}function QJ(e,t){const n=lc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=la(e)?Bu(e):Eo(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,u=i*s.x,d=r*s.y;return{width:o,height:l,x:u,y:d}}function xN(e,t,n){let r;if(t==="viewport")r=ZJ(e,n);else if(t==="document")r=XJ(No(e));else if(Xs(t))r=QJ(t,n);else{const i=RI(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ug(r)}function NI(e,t){const n=ul(e);return n===t||!Xs(n)||Wu(n)?!1:Zs(n).position==="fixed"||NI(n,t)}function JJ(e,t){const n=t.get(e);if(n)return n;let r=hf(e,[],!1).filter(l=>Xs(l)&&od(l)!=="body"),i=null;const s=Zs(e).position==="fixed";let o=s?ul(e):e;for(;Xs(o)&&!Wu(o);){const l=Zs(o),u=l1(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Lf(o)&&!u&&NI(e,o))?r=r.filter(h=>h!==o):i=l,o=ul(o)}return t.set(e,r),r}function eee(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Mv(t)?[]:JJ(t,this._c):[].concat(n),r],l=xN(t,o[0],i);let u=l.top,d=l.right,h=l.bottom,p=l.left;for(let y=1;y<o.length;y++){const g=xN(t,o[y],i);u=hs(g.top,u),d=cl(g.right,d),h=cl(g.bottom,h),p=hs(g.left,p)}return{width:d-p,height:h-u,x:p,y:u}}function tee(e){const{width:t,height:n}=TI(e);return{width:t,height:n}}function nee(e,t,n){const r=la(t),i=No(t),s=n==="fixed",o=lc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=Eo(0);function d(){u.x=Dv(i)}if(r||!r&&!s)if((od(t)!=="body"||Lf(i))&&(l=Ov(t)),r){const g=lc(t,!0,s,t);u.x=g.x+t.clientLeft,u.y=g.y+t.clientTop}else i&&d();s&&!r&&i&&d();const h=i&&!r&&!s?AI(i,l):Eo(0),p=o.left+l.scrollLeft-u.x-h.x,y=o.top+l.scrollTop-u.y-h.y;return{x:p,y,width:o.width,height:o.height}}function qb(e){return Zs(e).position==="static"}function EN(e,t){if(!la(e)||Zs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return No(e)===n&&(n=n.ownerDocument.body),n}function MI(e,t){const n=fs(e);if(Mv(e))return n;if(!la(e)){let i=ul(e);for(;i&&!Wu(i);){if(Xs(i)&&!qb(i))return i;i=ul(i)}return n}let r=EN(e,t);for(;r&&HJ(r)&&qb(r);)r=EN(r,t);return r&&Wu(r)&&qb(r)&&!l1(r)?n:r||qJ(e)||n}const ree=async function(e){const t=this.getOffsetParent||MI,n=this.getDimensions,r=await n(e.floating);return{reference:nee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function iee(e){return Zs(e).direction==="rtl"}const see={convertOffsetParentRelativeRectToViewportRelativeRect:KJ,getDocumentElement:No,getClippingRect:eee,getOffsetParent:MI,getElementRects:ree,getClientRects:GJ,getDimensions:tee,getScale:Bu,isElement:Xs,isRTL:iee};function OI(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function oee(e,t){let n=null,r;const i=No(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,u){l===void 0&&(l=!1),u===void 0&&(u=1),s();const d=e.getBoundingClientRect(),{left:h,top:p,width:y,height:g}=d;if(l||t(),!y||!g)return;const b=Lm(p),w=Lm(i.clientWidth-(h+y)),x=Lm(i.clientHeight-(p+g)),E=Lm(h),T={rootMargin:-b+"px "+-w+"px "+-x+"px "+-E+"px",threshold:hs(0,cl(1,u))||1};let R=!0;function z(N){const $=N[0].intersectionRatio;if($!==u){if(!R)return o();$?o(!1,$):r=setTimeout(()=>{o(!1,1e-7)},1e3)}$===1&&!OI(d,e.getBoundingClientRect())&&o(),R=!1}try{n=new IntersectionObserver(z,{...T,root:i.ownerDocument})}catch{n=new IntersectionObserver(z,T)}n.observe(e)}return o(!0),s}function aee(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=u1(e),h=i||s?[...d?hf(d):[],...t?hf(t):[]]:[];h.forEach(E=>{i&&E.addEventListener("scroll",n,{passive:!0}),s&&E.addEventListener("resize",n)});const p=d&&l?oee(d,n):null;let y=-1,g=null;o&&(g=new ResizeObserver(E=>{let[k]=E;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var T;(T=g)==null||T.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let b,w=u?lc(e):null;u&&x();function x(){const E=lc(e);w&&!OI(w,E)&&n(),w=E,b=requestAnimationFrame(x)}return n(),()=>{var E;h.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),p==null||p(),(E=g)==null||E.disconnect(),g=null,u&&cancelAnimationFrame(b)}}const lee=BJ,cee=jJ,uee=LJ,dee=$J,hee=IJ,CN=PJ,fee=FJ,pee=(e,t,n)=>{const r=new Map,i={platform:see,...n},s={...i.platform,_c:r};return DJ(e,t,{...i,platform:s})};var mee=typeof document<"u",gee=function(){},mg=mee?_.useLayoutEffect:gee;function Wg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Wg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!Wg(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function DI(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kN(e,t){const n=DI(e);return Math.round(t*n)/n}function Vb(e){const t=_.useRef(e);return mg(()=>{t.current=e}),t}function vee(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,p]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[y,g]=_.useState(r);Wg(y,r)||g(r);const[b,w]=_.useState(null),[x,E]=_.useState(null),k=_.useCallback(K=>{K!==N.current&&(N.current=K,w(K))},[]),T=_.useCallback(K=>{K!==$.current&&($.current=K,E(K))},[]),R=s||b,z=o||x,N=_.useRef(null),$=_.useRef(null),P=_.useRef(h),q=u!=null,H=Vb(u),U=Vb(i),O=Vb(d),M=_.useCallback(()=>{if(!N.current||!$.current)return;const K={placement:t,strategy:n,middleware:y};U.current&&(K.platform=U.current),pee(N.current,$.current,K).then(F=>{const A={...F,isPositioned:O.current!==!1};I.current&&!Wg(P.current,A)&&(P.current=A,nd.flushSync(()=>{p(A)}))})},[y,t,n,U,O]);mg(()=>{d===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[d]);const I=_.useRef(!1);mg(()=>(I.current=!0,()=>{I.current=!1}),[]),mg(()=>{if(R&&(N.current=R),z&&($.current=z),R&&z){if(H.current)return H.current(R,z,M);M()}},[R,z,M,H,q]);const L=_.useMemo(()=>({reference:N,floating:$,setReference:k,setFloating:T}),[k,T]),D=_.useMemo(()=>({reference:R,floating:z}),[R,z]),Y=_.useMemo(()=>{const K={position:n,left:0,top:0};if(!D.floating)return K;const F=kN(D.floating,h.x),A=kN(D.floating,h.y);return l?{...K,transform:"translate("+F+"px, "+A+"px)",...DI(D.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:A}},[n,l,D.floating,h.x,h.y]);return _.useMemo(()=>({...h,update:M,refs:L,elements:D,floatingStyles:Y}),[h,M,L,D,Y])}const yee=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?CN({element:r.current,padding:i}).fn(n):{}:r?CN({element:r,padding:i}).fn(n):{}}}},_ee=(e,t)=>{const n=lee(e);return{name:n.name,fn:n.fn,options:[e,t]}},bee=(e,t)=>{const n=cee(e);return{name:n.name,fn:n.fn,options:[e,t]}},wee=(e,t)=>({fn:fee(e).fn,options:[e,t]}),See=(e,t)=>{const n=uee(e);return{name:n.name,fn:n.fn,options:[e,t]}},xee=(e,t)=>{const n=dee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eee=(e,t)=>{const n=hee(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cee=(e,t)=>{const n=yee(e);return{name:n.name,fn:n.fn,options:[e,t]}};var kee="Arrow",PI=_.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return v.jsx(Xt.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:v.jsx("polygon",{points:"0,0 30,0 15,10"})})});PI.displayName=kee;var Tee=PI,d1="Popper",[LI,bl]=aa(d1),[Ree,II]=LI(d1),zI=e=>{const{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return v.jsx(Ree,{scope:t,anchor:r,onAnchorChange:i,children:n})};zI.displayName=d1;var BI="PopperAnchor",jI=_.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=II(BI,n),o=_.useRef(null),l=Bn(t,o),u=_.useRef(null);return _.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:v.jsx(Xt.div,{...i,ref:l})});jI.displayName=BI;var h1="PopperContent",[Aee,Nee]=LI(h1),FI=_.forwardRef((e,t)=>{var te,he,ge,Ee,Re,Ie;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:p="partial",hideWhenDetached:y=!1,updatePositionStrategy:g="optimized",onPlaced:b,...w}=e,x=II(h1,n),[E,k]=_.useState(null),T=Bn(t,Ye=>k(Ye)),[R,z]=_.useState(null),N=wJ(R),$=(N==null?void 0:N.width)??0,P=(N==null?void 0:N.height)??0,q=r+(s!=="center"?"-"+s:""),H=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},U=Array.isArray(d)?d:[d],O=U.length>0,M={padding:H,boundary:U.filter(Oee),altBoundary:O},{refs:I,floatingStyles:L,placement:D,isPositioned:Y,middlewareData:K}=vee({strategy:"fixed",placement:q,whileElementsMounted:(...Ye)=>aee(...Ye,{animationFrame:g==="always"}),elements:{reference:x.anchor},middleware:[_ee({mainAxis:i+P,alignmentAxis:o}),u&&bee({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?wee():void 0,...M}),u&&See({...M}),xee({...M,apply:({elements:Ye,rects:gt,availableWidth:Me,availableHeight:de})=>{const{width:oe,height:ye}=gt.reference,we=Ye.floating.style;we.setProperty("--radix-popper-available-width",`${Me}px`),we.setProperty("--radix-popper-available-height",`${de}px`),we.setProperty("--radix-popper-anchor-width",`${oe}px`),we.setProperty("--radix-popper-anchor-height",`${ye}px`)}}),R&&Cee({element:R,padding:l}),Dee({arrowWidth:$,arrowHeight:P}),y&&Eee({strategy:"referenceHidden",...M})]}),[F,A]=UI(D),W=To(b);Ti(()=>{Y&&(W==null||W())},[Y,W]);const G=(te=K.arrow)==null?void 0:te.x,B=(he=K.arrow)==null?void 0:he.y,ne=((ge=K.arrow)==null?void 0:ge.centerOffset)!==0,[ie,se]=_.useState();return Ti(()=>{E&&se(window.getComputedStyle(E).zIndex)},[E]),v.jsx("div",{ref:I.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:Y?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ie,"--radix-popper-transform-origin":[(Ee=K.transformOrigin)==null?void 0:Ee.x,(Re=K.transformOrigin)==null?void 0:Re.y].join(" "),...((Ie=K.hide)==null?void 0:Ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:v.jsx(Aee,{scope:n,placedSide:F,onArrowChange:z,arrowX:G,arrowY:B,shouldHideArrow:ne,children:v.jsx(Xt.div,{"data-side":F,"data-align":A,...w,ref:T,style:{...w.style,animation:Y?void 0:"none"}})})})});FI.displayName=h1;var $I="PopperArrow",Mee={top:"bottom",right:"left",bottom:"top",left:"right"},HI=_.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Nee($I,r),o=Mee[s.placedSide];return v.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:v.jsx(Tee,{...i,ref:n,style:{...i.style,display:"block"}})})});HI.displayName=$I;function Oee(e){return e!==null}var Dee=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]=UI(n),p={start:"0%",center:"50%",end:"100%"}[h],y=(((E=i.arrow)==null?void 0:E.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let b="",w="";return d==="bottom"?(b=o?p:`${y}px`,w=`${-u}px`):d==="top"?(b=o?p:`${y}px`,w=`${r.floating.height+u}px`):d==="right"?(b=`${-u}px`,w=o?p:`${g}px`):d==="left"&&(b=`${r.floating.width+u}px`,w=o?p:`${g}px`),{data:{x:b,y:w}}}});function UI(e){const[t,n="center"]=e.split("-");return[t,n]}var Pv=zI,If=jI,Lv=FI,Iv=HI,Yb="rovingFocusGroup.onEntryFocus",Pee={bubbles:!1,cancelable:!0},zf="RovingFocusGroup",[R0,WI,Lee]=Gx(zf),[Iee,qI]=aa(zf,[Lee]),[zee,Bee]=Iee(zf),VI=_.forwardRef((e,t)=>v.jsx(R0.Provider,{scope:e.__scopeRovingFocusGroup,children:v.jsx(R0.Slot,{scope:e.__scopeRovingFocusGroup,children:v.jsx(jee,{...e,ref:t})})}));VI.displayName=zf;var jee=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...p}=e,y=_.useRef(null),g=Bn(t,y),b=Xx(s),[w,x]=oc({prop:o,defaultProp:l??null,onChange:u,caller:zf}),[E,k]=_.useState(!1),T=To(d),R=WI(n),z=_.useRef(!1),[N,$]=_.useState(0);return _.useEffect(()=>{const P=y.current;if(P)return P.addEventListener(Yb,T),()=>P.removeEventListener(Yb,T)},[T]),v.jsx(zee,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:w,onItemFocus:_.useCallback(P=>x(P),[x]),onItemShiftTab:_.useCallback(()=>k(!0),[]),onFocusableItemAdd:_.useCallback(()=>$(P=>P+1),[]),onFocusableItemRemove:_.useCallback(()=>$(P=>P-1),[]),children:v.jsx(Xt.div,{tabIndex:E||N===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:yt(e.onMouseDown,()=>{z.current=!0}),onFocus:yt(e.onFocus,P=>{const q=!z.current;if(P.target===P.currentTarget&&q&&!E){const H=new CustomEvent(Yb,Pee);if(P.currentTarget.dispatchEvent(H),!H.defaultPrevented){const U=R().filter(D=>D.focusable),O=U.find(D=>D.active),M=U.find(D=>D.id===w),L=[O,M,...U].filter(Boolean).map(D=>D.ref.current);GI(L,h)}}z.current=!1}),onBlur:yt(e.onBlur,()=>k(!1))})})}),YI="RovingFocusGroupItem",KI=_.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=gi(),d=s||u,h=Bee(YI,n),p=h.currentTabStopId===d,y=WI(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:w}=h;return _.useEffect(()=>{if(r)return g(),()=>b()},[r,g,b]),v.jsx(R0.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:v.jsx(Xt.span,{tabIndex:p?0:-1,"data-orientation":h.orientation,...l,ref:t,onMouseDown:yt(e.onMouseDown,x=>{r?h.onItemFocus(d):x.preventDefault()}),onFocus:yt(e.onFocus,()=>h.onItemFocus(d)),onKeyDown:yt(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){h.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const E=Hee(x,h.orientation,h.dir);if(E!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let T=y().filter(R=>R.focusable).map(R=>R.ref.current);if(E==="last")T.reverse();else if(E==="prev"||E==="next"){E==="prev"&&T.reverse();const R=T.indexOf(x.currentTarget);T=h.loop?Uee(T,R+1):T.slice(R+1)}setTimeout(()=>GI(T))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});KI.displayName=YI;var Fee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function $ee(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Hee(e,t,n){const r=$ee(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Fee[r]}function GI(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Uee(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Wee=VI,qee=KI,A0=["Enter"," "],Vee=["ArrowDown","PageUp","Home"],XI=["ArrowUp","PageDown","End"],Yee=[...Vee,...XI],Kee={ltr:[...A0,"ArrowRight"],rtl:[...A0,"ArrowLeft"]},Gee={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Bf="Menu",[ff,Xee,Zee]=Gx(Bf),[bc,ZI]=aa(Bf,[Zee,bl,qI]),zv=bl(),QI=qI(),[Qee,wc]=bc(Bf),[Jee,jf]=bc(Bf),JI=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=zv(t),[u,d]=_.useState(null),h=_.useRef(!1),p=To(s),y=Xx(i);return _.useEffect(()=>{const g=()=>{h.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>h.current=!1;return document.addEventListener("keydown",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),v.jsx(Pv,{...l,children:v.jsx(Qee,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:v.jsx(Jee,{scope:t,onClose:_.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:h,dir:y,modal:o,children:r})})})};JI.displayName=Bf;var ete="MenuAnchor",f1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(If,{...i,...r,ref:t})});f1.displayName=ete;var p1="MenuPortal",[tte,ez]=bc(p1,{forceMount:void 0}),tz=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=wc(p1,t);return v.jsx(tte,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};tz.displayName=p1;var Ds="MenuContent",[nte,m1]=bc(Ds),nz=_.forwardRef((e,t)=>{const n=ez(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:o.modal?v.jsx(rte,{...i,ref:t}):v.jsx(ite,{...i,ref:t})})})})}),rte=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu),r=_.useRef(null),i=Bn(t,r);return _.useEffect(()=>{const s=r.current;if(s)return Rv(s)},[]),v.jsx(g1,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ite=_.forwardRef((e,t)=>{const n=wc(Ds,e.__scopeMenu);return v.jsx(g1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ste=ll("MenuContent.ScrollLock"),g1=_.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:g,disableOutsideScroll:b,...w}=e,x=wc(Ds,n),E=jf(Ds,n),k=zv(n),T=QI(n),R=Xee(n),[z,N]=_.useState(null),$=_.useRef(null),P=Bn(t,$,x.onContentChange),q=_.useRef(0),H=_.useRef(""),U=_.useRef(0),O=_.useRef(null),M=_.useRef("right"),I=_.useRef(0),L=b?Pf:_.Fragment,D=b?{as:ste,allowPinchZoom:!0}:void 0,Y=F=>{var te,he;const A=H.current+F,W=R().filter(ge=>!ge.disabled),G=document.activeElement,B=(te=W.find(ge=>ge.ref.current===G))==null?void 0:te.textValue,ne=W.map(ge=>ge.textValue),ie=vte(ne,A,B),se=(he=W.find(ge=>ge.textValue===ie))==null?void 0:he.ref.current;(function ge(Ee){H.current=Ee,window.clearTimeout(q.current),Ee!==""&&(q.current=window.setTimeout(()=>ge(""),1e3))})(A),se&&setTimeout(()=>se.focus())};_.useEffect(()=>()=>window.clearTimeout(q.current),[]),kv();const K=_.useCallback(F=>{var W,G;return M.current===((W=O.current)==null?void 0:W.side)&&_te(F,(G=O.current)==null?void 0:G.area)},[]);return v.jsx(nte,{scope:n,searchRef:H,onItemEnter:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),onItemLeave:_.useCallback(F=>{var A;K(F)||((A=$.current)==null||A.focus(),N(null))},[K]),onTriggerLeave:_.useCallback(F=>{K(F)&&F.preventDefault()},[K]),pointerGraceTimerRef:U,onPointerGraceIntentChange:_.useCallback(F=>{O.current=F},[]),children:v.jsx(L,{...D,children:v.jsx(Df,{asChild:!0,trapped:i,onMountAutoFocus:yt(s,F=>{var A;F.preventDefault(),(A=$.current)==null||A.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:p,onInteractOutside:y,onDismiss:g,children:v.jsx(Wee,{asChild:!0,...T,dir:E.dir,orientation:"vertical",loop:r,currentTabStopId:z,onCurrentTabStopIdChange:N,onEntryFocus:yt(u,F=>{E.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:v.jsx(Lv,{role:"menu","aria-orientation":"vertical","data-state":yz(x.open),"data-radix-menu-content":"",dir:E.dir,...k,...w,ref:P,style:{outline:"none",...w.style},onKeyDown:yt(w.onKeyDown,F=>{const W=F.target.closest("[data-radix-menu-content]")===F.currentTarget,G=F.ctrlKey||F.altKey||F.metaKey,B=F.key.length===1;W&&(F.key==="Tab"&&F.preventDefault(),!G&&B&&Y(F.key));const ne=$.current;if(F.target!==ne||!Yee.includes(F.key))return;F.preventDefault();const se=R().filter(te=>!te.disabled).map(te=>te.ref.current);XI.includes(F.key)&&se.reverse(),mte(se)}),onBlur:yt(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(q.current),H.current="")}),onPointerMove:yt(e.onPointerMove,pf(F=>{const A=F.target,W=I.current!==F.clientX;if(F.currentTarget.contains(A)&&W){const G=F.clientX>I.current?"right":"left";M.current=G,I.current=F.clientX}}))})})})})})})});nz.displayName=Ds;var ote="MenuGroup",v1=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Xt.div,{role:"group",...r,ref:t})});v1.displayName=ote;var ate="MenuLabel",rz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Xt.div,{...r,ref:t})});rz.displayName=ate;var qg="MenuItem",TN="menu.itemSelect",Bv=_.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=_.useRef(null),o=jf(qg,e.__scopeMenu),l=m1(qg,e.__scopeMenu),u=Bn(t,s),d=_.useRef(!1),h=()=>{const p=s.current;if(!n&&p){const y=new CustomEvent(TN,{bubbles:!0,cancelable:!0});p.addEventListener(TN,g=>r==null?void 0:r(g),{once:!0}),WL(p,y),y.defaultPrevented?d.current=!1:o.onClose()}};return v.jsx(iz,{...i,ref:u,disabled:n,onClick:yt(e.onClick,h),onPointerDown:p=>{var y;(y=e.onPointerDown)==null||y.call(e,p),d.current=!0},onPointerUp:yt(e.onPointerUp,p=>{var y;d.current||(y=p.currentTarget)==null||y.click()}),onKeyDown:yt(e.onKeyDown,p=>{const y=l.searchRef.current!=="";n||y&&p.key===" "||A0.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Bv.displayName=qg;var iz=_.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=m1(qg,n),l=QI(n),u=_.useRef(null),d=Bn(t,u),[h,p]=_.useState(!1),[y,g]=_.useState("");return _.useEffect(()=>{const b=u.current;b&&g((b.textContent??"").trim())},[s.children]),v.jsx(ff.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:v.jsx(qee,{asChild:!0,...l,focusable:!r,children:v.jsx(Xt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:yt(e.onPointerMove,pf(b=>{r?o.onItemLeave(b):(o.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:yt(e.onPointerLeave,pf(b=>o.onItemLeave(b))),onFocus:yt(e.onFocus,()=>p(!0)),onBlur:yt(e.onBlur,()=>p(!1))})})})}),lte="MenuCheckboxItem",sz=_.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return v.jsx(uz,{scope:e.__scopeMenu,checked:n,children:v.jsx(Bv,{role:"menuitemcheckbox","aria-checked":Vg(n)?"mixed":n,...i,ref:t,"data-state":_1(n),onSelect:yt(i.onSelect,()=>r==null?void 0:r(Vg(n)?!0:!n),{checkForDefaultPrevented:!1})})})});sz.displayName=lte;var oz="MenuRadioGroup",[cte,ute]=bc(oz,{value:void 0,onValueChange:()=>{}}),az=_.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=To(r);return v.jsx(cte,{scope:e.__scopeMenu,value:n,onValueChange:s,children:v.jsx(v1,{...i,ref:t})})});az.displayName=oz;var lz="MenuRadioItem",cz=_.forwardRef((e,t)=>{const{value:n,...r}=e,i=ute(lz,e.__scopeMenu),s=n===i.value;return v.jsx(uz,{scope:e.__scopeMenu,checked:s,children:v.jsx(Bv,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_1(s),onSelect:yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});cz.displayName=lz;var y1="MenuItemIndicator",[uz,dte]=bc(y1,{checked:!1}),dz=_.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=dte(y1,n);return v.jsx(Bs,{present:r||Vg(s.checked)||s.checked===!0,children:v.jsx(Xt.span,{...i,ref:t,"data-state":_1(s.checked)})})});dz.displayName=y1;var hte="MenuSeparator",hz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return v.jsx(Xt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});hz.displayName=hte;var fte="MenuArrow",fz=_.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=zv(n);return v.jsx(Iv,{...i,...r,ref:t})});fz.displayName=fte;var pte="MenuSub",[Qke,pz]=bc(pte),Ph="MenuSubTrigger",mz=_.forwardRef((e,t)=>{const n=wc(Ph,e.__scopeMenu),r=jf(Ph,e.__scopeMenu),i=pz(Ph,e.__scopeMenu),s=m1(Ph,e.__scopeMenu),o=_.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},h=_.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return _.useEffect(()=>h,[h]),_.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),v.jsx(f1,{asChild:!0,...d,children:v.jsx(iz,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":yz(n.open),...e,ref:ia(t,i.onTriggerChange),onClick:p=>{var y;(y=e.onClick)==null||y.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:yt(e.onPointerMove,pf(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),h()},100))})),onPointerLeave:yt(e.onPointerLeave,pf(p=>{var g,b;h();const y=(g=n.content)==null?void 0:g.getBoundingClientRect();if(y){const w=(b=n.content)==null?void 0:b.dataset.side,x=w==="right",E=x?-5:5,k=y[x?"left":"right"],T=y[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+E,y:p.clientY},{x:k,y:y.top},{x:T,y:y.top},{x:T,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:yt(e.onKeyDown,p=>{var g;const y=s.searchRef.current!=="";e.disabled||y&&p.key===" "||Kee[r.dir].includes(p.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),p.preventDefault())})})})});mz.displayName=Ph;var gz="MenuSubContent",vz=_.forwardRef((e,t)=>{const n=ez(Ds,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=wc(Ds,e.__scopeMenu),o=jf(Ds,e.__scopeMenu),l=pz(gz,e.__scopeMenu),u=_.useRef(null),d=Bn(t,u);return v.jsx(ff.Provider,{scope:e.__scopeMenu,children:v.jsx(Bs,{present:r||s.open,children:v.jsx(ff.Slot,{scope:e.__scopeMenu,children:v.jsx(g1,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:yt(e.onFocusOutside,h=>{h.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:yt(e.onEscapeKeyDown,h=>{o.onClose(),h.preventDefault()}),onKeyDown:yt(e.onKeyDown,h=>{var g;const p=h.currentTarget.contains(h.target),y=Gee[o.dir].includes(h.key);p&&y&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),h.preventDefault())})})})})})});vz.displayName=gz;function yz(e){return e?"open":"closed"}function Vg(e){return e==="indeterminate"}function _1(e){return Vg(e)?"indeterminate":e?"checked":"unchecked"}function mte(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function gte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function vte(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=gte(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 yte(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 _te(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return yte(n,t)}function pf(e){return t=>t.pointerType==="mouse"?e(t):void 0}var bte=JI,wte=f1,Ste=tz,xte=nz,Ete=v1,Cte=rz,kte=Bv,Tte=sz,Rte=az,Ate=cz,Nte=dz,Mte=hz,Ote=fz,Dte=mz,Pte=vz,jv="DropdownMenu",[Lte]=aa(jv,[ZI]),ji=ZI(),[Ite,_z]=Lte(jv),bz=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=ji(t),d=_.useRef(null),[h,p]=oc({prop:i,defaultProp:s??!1,onChange:o,caller:jv});return v.jsx(Ite,{scope:t,triggerId:gi(),triggerRef:d,contentId:gi(),open:h,onOpenChange:p,onOpenToggle:_.useCallback(()=>p(y=>!y),[p]),modal:l,children:v.jsx(bte,{...u,open:h,onOpenChange:p,dir:r,modal:l,children:n})})};bz.displayName=jv;var wz="DropdownMenuTrigger",Sz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=_z(wz,n),o=ji(n);return v.jsx(wte,{asChild:!0,...o,children:v.jsx(Xt.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:ia(t,s.triggerRef),onPointerDown:yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});Sz.displayName=wz;var zte="DropdownMenuPortal",xz=e=>{const{__scopeDropdownMenu:t,...n}=e,r=ji(t);return v.jsx(Ste,{...r,...n})};xz.displayName=zte;var Ez="DropdownMenuContent",Cz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=_z(Ez,n),s=ji(n),o=_.useRef(!1);return v.jsx(xte,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:yt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!i.modal||h)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Cz.displayName=Ez;var Bte="DropdownMenuGroup",jte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ete,{...i,...r,ref:t})});jte.displayName=Bte;var Fte="DropdownMenuLabel",kz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Cte,{...i,...r,ref:t})});kz.displayName=Fte;var $te="DropdownMenuItem",Tz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(kte,{...i,...r,ref:t})});Tz.displayName=$te;var Hte="DropdownMenuCheckboxItem",Rz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Tte,{...i,...r,ref:t})});Rz.displayName=Hte;var Ute="DropdownMenuRadioGroup",Wte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Rte,{...i,...r,ref:t})});Wte.displayName=Ute;var qte="DropdownMenuRadioItem",Vte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ate,{...i,...r,ref:t})});Vte.displayName=qte;var Yte="DropdownMenuItemIndicator",Az=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Nte,{...i,...r,ref:t})});Az.displayName=Yte;var Kte="DropdownMenuSeparator",Nz=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Mte,{...i,...r,ref:t})});Nz.displayName=Kte;var Gte="DropdownMenuArrow",Xte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Ote,{...i,...r,ref:t})});Xte.displayName=Gte;var Zte="DropdownMenuSubTrigger",Qte=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Dte,{...i,...r,ref:t})});Qte.displayName=Zte;var Jte="DropdownMenuSubContent",ene=_.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=ji(n);return v.jsx(Pte,{...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)"}})});ene.displayName=Jte;var tne=bz,nne=Sz,rne=xz,ine=Cz,sne=kz,one=Tz,ane=Rz,lne=Az,cne=Nz;function RN(e,[t,n]){return Math.min(n,Math.max(t,e))}var Fv="Popover",[Mz]=aa(Fv,[bl]),Ff=bl(),[une,wl]=Mz(Fv),Oz=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Ff(t),u=_.useRef(null),[d,h]=_.useState(!1),[p,y]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:Fv});return v.jsx(Pv,{...l,children:v.jsx(une,{scope:t,contentId:gi(),triggerRef:u,open:p,onOpenChange:y,onOpenToggle:_.useCallback(()=>y(g=>!g),[y]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:o,children:n})})};Oz.displayName=Fv;var Dz="PopoverAnchor",dne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Dz,n),s=Ff(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return _.useEffect(()=>(o(),()=>l()),[o,l]),v.jsx(If,{...s,...r,ref:t})});dne.displayName=Dz;var Pz="PopoverTrigger",Lz=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(Pz,n),s=Ff(n),o=Bn(t,i.triggerRef),l=v.jsx(Xt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Fz(i.open),...r,ref:o,onClick:yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:v.jsx(If,{asChild:!0,...s,children:l})});Lz.displayName=Pz;var b1="PopoverPortal",[hne,fne]=Mz(b1,{forceMount:void 0}),Iz=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=wl(b1,t);return v.jsx(hne,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};Iz.displayName=b1;var qu="PopoverContent",zz=_.forwardRef((e,t)=>{const n=fne(qu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=wl(qu,e.__scopePopover);return v.jsx(Bs,{present:r||s.open,children:s.modal?v.jsx(mne,{...i,ref:t}):v.jsx(gne,{...i,ref:t})})});zz.displayName=qu;var pne=ll("PopoverContent.RemoveScroll"),mne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(null),i=Bn(t,r),s=_.useRef(!1);return _.useEffect(()=>{const o=r.current;if(o)return Rv(o)},[]),v.jsx(Pf,{as:pne,allowPinchZoom:!0,children:v.jsx(Bz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:yt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),gne=_.forwardRef((e,t)=>{const n=wl(qu,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return v.jsx(Bz,{...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()}})}),Bz=_.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,...p}=e,y=wl(qu,n),g=Ff(n);return kv(),v.jsx(Df,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:h,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:v.jsx(Lv,{"data-state":Fz(y.open),role:"dialog",id:y.contentId,...g,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),jz="PopoverClose",vne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=wl(jz,n);return v.jsx(Xt.button,{type:"button",...r,ref:t,onClick:yt(e.onClick,()=>i.onOpenChange(!1))})});vne.displayName=jz;var yne="PopoverArrow",_ne=_.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Ff(n);return v.jsx(Iv,{...i,...r,ref:t})});_ne.displayName=yne;function Fz(e){return e?"open":"closed"}var bne=Oz,wne=Lz,Sne=Iz,xne=zz,Ene=[" ","Enter","ArrowUp","ArrowDown"],Cne=[" ","Enter"],cc="Select",[$v,Hv,kne]=Gx(cc),[ad]=aa(cc,[kne,bl]),Uv=bl(),[Tne,Sl]=ad(cc),[Rne,Ane]=ad(cc),$z=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:h,autoComplete:p,disabled:y,required:g,form:b}=e,w=Uv(t),[x,E]=_.useState(null),[k,T]=_.useState(null),[R,z]=_.useState(!1),N=Xx(d),[$,P]=oc({prop:r,defaultProp:i??!1,onChange:s,caller:cc}),[q,H]=oc({prop:o,defaultProp:l,onChange:u,caller:cc}),U=_.useRef(null),O=x?b||!!x.closest("form"):!0,[M,I]=_.useState(new Set),L=Array.from(M).map(D=>D.props.value).join(";");return v.jsx(Pv,{...w,children:v.jsxs(Tne,{required:g,scope:t,trigger:x,onTriggerChange:E,valueNode:k,onValueNodeChange:T,valueNodeHasChildren:R,onValueNodeHasChildrenChange:z,contentId:gi(),value:q,onValueChange:H,open:$,onOpenChange:P,dir:N,triggerPointerDownPosRef:U,disabled:y,children:[v.jsx($v.Provider,{scope:t,children:v.jsx(Rne,{scope:e.__scopeSelect,onNativeOptionAdd:_.useCallback(D=>{I(Y=>new Set(Y).add(D))},[]),onNativeOptionRemove:_.useCallback(D=>{I(Y=>{const K=new Set(Y);return K.delete(D),K})},[]),children:n})}),O?v.jsxs(cB,{"aria-hidden":!0,required:g,tabIndex:-1,name:h,autoComplete:p,value:q,onChange:D=>H(D.target.value),disabled:y,form:b,children:[q===void 0?v.jsx("option",{value:""}):null,Array.from(M)]},L):null]})})};$z.displayName=cc;var Hz="SelectTrigger",Uz=_.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Uv(n),o=Sl(Hz,n),l=o.disabled||r,u=Bn(t,o.onTriggerChange),d=Hv(n),h=_.useRef("touch"),[p,y,g]=dB(w=>{const x=d().filter(T=>!T.disabled),E=x.find(T=>T.value===o.value),k=hB(x,w,E);k!==void 0&&o.onValueChange(k.value)}),b=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return v.jsx(If,{asChild:!0,...s,children:v.jsx(Xt.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":uB(o.value)?"":void 0,...i,ref:u,onClick:yt(i.onClick,w=>{w.currentTarget.focus(),h.current!=="mouse"&&b(w)}),onPointerDown:yt(i.onPointerDown,w=>{h.current=w.pointerType;const x=w.target;x.hasPointerCapture(w.pointerId)&&x.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(b(w),w.preventDefault())}),onKeyDown:yt(i.onKeyDown,w=>{const x=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(x&&w.key===" ")&&Ene.includes(w.key)&&(b(),w.preventDefault())})})})});Uz.displayName=Hz;var Wz="SelectValue",qz=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=Sl(Wz,n),{onValueNodeHasChildrenChange:d}=u,h=s!==void 0,p=Bn(t,u.onValueNodeChange);return Ti(()=>{d(h)},[d,h]),v.jsx(Xt.span,{...l,ref:p,style:{pointerEvents:"none"},children:uB(u.value)?v.jsx(v.Fragment,{children:o}):s})});qz.displayName=Wz;var Nne="SelectIcon",Vz=_.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return v.jsx(Xt.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});Vz.displayName=Nne;var Mne="SelectPortal",Yz=e=>v.jsx(id,{asChild:!0,...e});Yz.displayName=Mne;var uc="SelectContent",Kz=_.forwardRef((e,t)=>{const n=Sl(uc,e.__scopeSelect),[r,i]=_.useState();if(Ti(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?nd.createPortal(v.jsx(Gz,{scope:e.__scopeSelect,children:v.jsx($v.Slot,{scope:e.__scopeSelect,children:v.jsx("div",{children:e.children})})}),s):null}return v.jsx(Xz,{...e,ref:t})});Kz.displayName=uc;var qs=10,[Gz,xl]=ad(uc),One="SelectContentImpl",Dne=ll("SelectContent.RemoveScroll"),Xz=_.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:g,sticky:b,hideWhenDetached:w,avoidCollisions:x,...E}=e,k=Sl(uc,n),[T,R]=_.useState(null),[z,N]=_.useState(null),$=Bn(t,te=>R(te)),[P,q]=_.useState(null),[H,U]=_.useState(null),O=Hv(n),[M,I]=_.useState(!1),L=_.useRef(!1);_.useEffect(()=>{if(T)return Rv(T)},[T]),kv();const D=_.useCallback(te=>{const[he,...ge]=O().map(Ie=>Ie.ref.current),[Ee]=ge.slice(-1),Re=document.activeElement;for(const Ie of te)if(Ie===Re||(Ie==null||Ie.scrollIntoView({block:"nearest"}),Ie===he&&z&&(z.scrollTop=0),Ie===Ee&&z&&(z.scrollTop=z.scrollHeight),Ie==null||Ie.focus(),document.activeElement!==Re))return},[O,z]),Y=_.useCallback(()=>D([P,T]),[D,P,T]);_.useEffect(()=>{M&&Y()},[M,Y]);const{onOpenChange:K,triggerPointerDownPosRef:F}=k;_.useEffect(()=>{if(T){let te={x:0,y:0};const he=Ee=>{var Re,Ie;te={x:Math.abs(Math.round(Ee.pageX)-(((Re=F.current)==null?void 0:Re.x)??0)),y:Math.abs(Math.round(Ee.pageY)-(((Ie=F.current)==null?void 0:Ie.y)??0))}},ge=Ee=>{te.x<=10&&te.y<=10?Ee.preventDefault():T.contains(Ee.target)||K(!1),document.removeEventListener("pointermove",he),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",he),document.addEventListener("pointerup",ge,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",he),document.removeEventListener("pointerup",ge,{capture:!0})}}},[T,K,F]),_.useEffect(()=>{const te=()=>K(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[K]);const[A,W]=dB(te=>{const he=O().filter(Re=>!Re.disabled),ge=he.find(Re=>Re.ref.current===document.activeElement),Ee=hB(he,te,ge);Ee&&setTimeout(()=>Ee.ref.current.focus())}),G=_.useCallback((te,he,ge)=>{const Ee=!L.current&&!ge;(k.value!==void 0&&k.value===he||Ee)&&(q(te),Ee&&(L.current=!0))},[k.value]),B=_.useCallback(()=>T==null?void 0:T.focus(),[T]),ne=_.useCallback((te,he,ge)=>{const Ee=!L.current&&!ge;(k.value!==void 0&&k.value===he||Ee)&&U(te)},[k.value]),ie=r==="popper"?N0:Zz,se=ie===N0?{side:l,sideOffset:u,align:d,alignOffset:h,arrowPadding:p,collisionBoundary:y,collisionPadding:g,sticky:b,hideWhenDetached:w,avoidCollisions:x}:{};return v.jsx(Gz,{scope:n,content:T,viewport:z,onViewportChange:N,itemRefCallback:G,selectedItem:P,onItemLeave:B,itemTextRefCallback:ne,focusSelectedItem:Y,selectedItemText:H,position:r,isPositioned:M,searchRef:A,children:v.jsx(Pf,{as:Dne,allowPinchZoom:!0,children:v.jsx(Df,{asChild:!0,trapped:k.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:yt(i,te=>{var he;(he=k.trigger)==null||he.focus({preventScroll:!0}),te.preventDefault()}),children:v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:v.jsx(ie,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:te=>te.preventDefault(),...E,...se,onPlaced:()=>I(!0),ref:$,style:{display:"flex",flexDirection:"column",outline:"none",...E.style},onKeyDown:yt(E.onKeyDown,te=>{const he=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!he&&te.key.length===1&&W(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let Ee=O().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);if(["ArrowUp","End"].includes(te.key)&&(Ee=Ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const Re=te.target,Ie=Ee.indexOf(Re);Ee=Ee.slice(Ie+1)}setTimeout(()=>D(Ee)),te.preventDefault()}})})})})})})});Xz.displayName=One;var Pne="SelectItemAlignedPosition",Zz=_.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=Sl(uc,n),o=xl(uc,n),[l,u]=_.useState(null),[d,h]=_.useState(null),p=Bn(t,$=>h($)),y=Hv(n),g=_.useRef(!1),b=_.useRef(!0),{viewport:w,selectedItem:x,selectedItemText:E,focusSelectedItem:k}=o,T=_.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&x&&E){const $=s.trigger.getBoundingClientRect(),P=d.getBoundingClientRect(),q=s.valueNode.getBoundingClientRect(),H=E.getBoundingClientRect();if(s.dir!=="rtl"){const Re=H.left-P.left,Ie=q.left-Re,Ye=$.left-Ie,gt=$.width+Ye,Me=Math.max(gt,P.width),de=window.innerWidth-qs,oe=RN(Ie,[qs,Math.max(qs,de-Me)]);l.style.minWidth=gt+"px",l.style.left=oe+"px"}else{const Re=P.right-H.right,Ie=window.innerWidth-q.right-Re,Ye=window.innerWidth-$.right-Ie,gt=$.width+Ye,Me=Math.max(gt,P.width),de=window.innerWidth-qs,oe=RN(Ie,[qs,Math.max(qs,de-Me)]);l.style.minWidth=gt+"px",l.style.right=oe+"px"}const U=y(),O=window.innerHeight-qs*2,M=w.scrollHeight,I=window.getComputedStyle(d),L=parseInt(I.borderTopWidth,10),D=parseInt(I.paddingTop,10),Y=parseInt(I.borderBottomWidth,10),K=parseInt(I.paddingBottom,10),F=L+D+M+K+Y,A=Math.min(x.offsetHeight*5,F),W=window.getComputedStyle(w),G=parseInt(W.paddingTop,10),B=parseInt(W.paddingBottom,10),ne=$.top+$.height/2-qs,ie=O-ne,se=x.offsetHeight/2,te=x.offsetTop+se,he=L+D+te,ge=F-he;if(he<=ne){const Re=U.length>0&&x===U[U.length-1].ref.current;l.style.bottom="0px";const Ie=d.clientHeight-w.offsetTop-w.offsetHeight,Ye=Math.max(ie,se+(Re?B:0)+Ie+Y),gt=he+Ye;l.style.height=gt+"px"}else{const Re=U.length>0&&x===U[0].ref.current;l.style.top="0px";const Ye=Math.max(ne,L+w.offsetTop+(Re?G:0)+se)+ge;l.style.height=Ye+"px",w.scrollTop=he-ne+w.offsetTop}l.style.margin=`${qs}px 0`,l.style.minHeight=A+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,x,E,s.dir,r]);Ti(()=>T(),[T]);const[R,z]=_.useState();Ti(()=>{d&&z(window.getComputedStyle(d).zIndex)},[d]);const N=_.useCallback($=>{$&&b.current===!0&&(T(),k==null||k(),b.current=!1)},[T,k]);return v.jsx(Ine,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:N,children:v.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:R},children:v.jsx(Xt.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});Zz.displayName=Pne;var Lne="SelectPopperPosition",N0=_.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=qs,...s}=e,o=Uv(n);return v.jsx(Lv,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});N0.displayName=Lne;var[Ine,w1]=ad(uc,{}),M0="SelectViewport",Qz=_.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=xl(M0,n),o=w1(M0,n),l=Bn(t,s.onViewportChange),u=_.useRef(0);return v.jsxs(v.Fragment,{children:[v.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),v.jsx($v.Slot,{scope:n,children:v.jsx(Xt.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:yt(i.onScroll,d=>{const h=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.current&&p){const g=Math.abs(u.current-h.scrollTop);if(g>0){const b=window.innerHeight-qs*2,w=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),E=Math.max(w,x);if(E<b){const k=E+g,T=Math.min(b,k),R=k-T;p.style.height=T+"px",p.style.bottom==="0px"&&(h.scrollTop=R>0?R:0,p.style.justifyContent="flex-end")}}}u.current=h.scrollTop})})})]})});Qz.displayName=M0;var Jz="SelectGroup",[zne,Bne]=ad(Jz),jne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=gi();return v.jsx(zne,{scope:n,id:i,children:v.jsx(Xt.div,{role:"group","aria-labelledby":i,...r,ref:t})})});jne.displayName=Jz;var eB="SelectLabel",Fne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bne(eB,n);return v.jsx(Xt.div,{id:i.id,...r,ref:t})});Fne.displayName=eB;var Yg="SelectItem",[$ne,tB]=ad(Yg),nB=_.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=Sl(Yg,n),u=xl(Yg,n),d=l.value===r,[h,p]=_.useState(s??""),[y,g]=_.useState(!1),b=Bn(t,k=>{var T;return(T=u.itemRefCallback)==null?void 0:T.call(u,k,r,i)}),w=gi(),x=_.useRef("touch"),E=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return v.jsx($ne,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:_.useCallback(k=>{p(T=>T||((k==null?void 0:k.textContent)??"").trim())},[]),children:v.jsx($v.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:v.jsx(Xt.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:b,onFocus:yt(o.onFocus,()=>g(!0)),onBlur:yt(o.onBlur,()=>g(!1)),onClick:yt(o.onClick,()=>{x.current!=="mouse"&&E()}),onPointerUp:yt(o.onPointerUp,()=>{x.current==="mouse"&&E()}),onPointerDown:yt(o.onPointerDown,k=>{x.current=k.pointerType}),onPointerMove:yt(o.onPointerMove,k=>{var T;x.current=k.pointerType,i?(T=u.onItemLeave)==null||T.call(u):x.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:yt(o.onPointerLeave,k=>{var T;k.currentTarget===document.activeElement&&((T=u.onItemLeave)==null||T.call(u))}),onKeyDown:yt(o.onKeyDown,k=>{var R;((R=u.searchRef)==null?void 0:R.current)!==""&&k.key===" "||(Cne.includes(k.key)&&E(),k.key===" "&&k.preventDefault())})})})})});nB.displayName=Yg;var Lh="SelectItemText",rB=_.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=Sl(Lh,n),l=xl(Lh,n),u=tB(Lh,n),d=Ane(Lh,n),[h,p]=_.useState(null),y=Bn(t,E=>p(E),u.onItemTextChange,E=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.call(l,E,u.value,u.disabled)}),g=h==null?void 0:h.textContent,b=_.useMemo(()=>v.jsx("option",{value:u.value,disabled:u.disabled,children:g},u.value),[u.disabled,u.value,g]),{onNativeOptionAdd:w,onNativeOptionRemove:x}=d;return Ti(()=>(w(b),()=>x(b)),[w,x,b]),v.jsxs(v.Fragment,{children:[v.jsx(Xt.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?nd.createPortal(s.children,o.valueNode):null]})});rB.displayName=Lh;var iB="SelectItemIndicator",sB=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return tB(iB,n).isSelected?v.jsx(Xt.span,{"aria-hidden":!0,...r,ref:t}):null});sB.displayName=iB;var O0="SelectScrollUpButton",oB=_.forwardRef((e,t)=>{const n=xl(O0,e.__scopeSelect),r=w1(O0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollTop>0;s(d)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?v.jsx(lB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});oB.displayName=O0;var D0="SelectScrollDownButton",aB=_.forwardRef((e,t)=>{const n=xl(D0,e.__scopeSelect),r=w1(D0,e.__scopeSelect),[i,s]=_.useState(!1),o=Bn(t,r.onScrollButtonChange);return Ti(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,h=Math.ceil(u.scrollTop)<d;s(h)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?v.jsx(lB,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});aB.displayName=D0;var lB=_.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=xl("SelectScrollButton",n),o=_.useRef(null),l=Hv(n),u=_.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return _.useEffect(()=>()=>u(),[u]),Ti(()=>{var h;const d=l().find(p=>p.ref.current===document.activeElement);(h=d==null?void 0:d.ref.current)==null||h.scrollIntoView({block:"nearest"})},[l]),v.jsx(Xt.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:yt(i.onPointerLeave,()=>{u()})})}),Hne="SelectSeparator",Une=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return v.jsx(Xt.div,{"aria-hidden":!0,...r,ref:t})});Une.displayName=Hne;var P0="SelectArrow",Wne=_.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Uv(n),s=Sl(P0,n),o=xl(P0,n);return s.open&&o.position==="popper"?v.jsx(Iv,{...i,...r,ref:t}):null});Wne.displayName=P0;var qne="SelectBubbleInput",cB=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=_.useRef(null),s=Bn(r,i),o=bJ(t);return _.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,h=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&h){const p=new Event("change",{bubbles:!0});h.call(l,t),l.dispatchEvent(p)}},[o,t]),v.jsx(Xt.select,{...n,style:{...qL,...n.style},ref:s,defaultValue:t})});cB.displayName=qne;function uB(e){return e===""||e===void 0}function dB(e){const t=To(e),n=_.useRef(""),r=_.useRef(0),i=_.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=_.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return _.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function hB(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=Vne(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 Vne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Yne=$z,Kne=Uz,Gne=qz,Xne=Vz,Zne=Yz,Qne=Kz,Jne=Qz,ere=nB,tre=rB,nre=sB,rre=oB,ire=aB,[Wv]=aa("Tooltip",[bl]),qv=bl(),fB="TooltipProvider",sre=700,L0="tooltip.open",[ore,S1]=Wv(fB),pB=e=>{const{__scopeTooltip:t,delayDuration:n=sre,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=_.useRef(!0),l=_.useRef(!1),u=_.useRef(0);return _.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),v.jsx(ore,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:_.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};pB.displayName=fB;var mf="Tooltip",[are,$f]=Wv(mf),mB=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=S1(mf,e.__scopeTooltip),d=qv(t),[h,p]=_.useState(null),y=gi(),g=_.useRef(0),b=o??u.disableHoverableContent,w=l??u.delayDuration,x=_.useRef(!1),[E,k]=oc({prop:r,defaultProp:i??!1,onChange:$=>{$?(u.onOpen(),document.dispatchEvent(new CustomEvent(L0))):u.onClose(),s==null||s($)},caller:mf}),T=_.useMemo(()=>E?x.current?"delayed-open":"instant-open":"closed",[E]),R=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,x.current=!1,k(!0)},[k]),z=_.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),N=_.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{x.current=!0,k(!0),g.current=0},w)},[w,k]);return _.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),v.jsx(Pv,{...d,children:v.jsx(are,{scope:t,contentId:y,open:E,stateAttribute:T,trigger:h,onTriggerChange:p,onTriggerEnter:_.useCallback(()=>{u.isOpenDelayedRef.current?N():R()},[u.isOpenDelayedRef,N,R]),onTriggerLeave:_.useCallback(()=>{b?z():(window.clearTimeout(g.current),g.current=0)},[z,b]),onOpen:R,onClose:z,disableHoverableContent:b,children:n})})};mB.displayName=mf;var I0="TooltipTrigger",gB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=$f(I0,n),s=S1(I0,n),o=qv(n),l=_.useRef(null),u=Bn(t,l,i.onTriggerChange),d=_.useRef(!1),h=_.useRef(!1),p=_.useCallback(()=>d.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),v.jsx(If,{asChild:!0,...o,children:v.jsx(Xt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:yt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!h.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),h.current=!0)}),onPointerLeave:yt(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:yt(e.onBlur,i.onClose),onClick:yt(e.onClick,i.onClose)})})});gB.displayName=I0;var x1="TooltipPortal",[lre,cre]=Wv(x1,{forceMount:void 0}),vB=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=$f(x1,t);return v.jsx(lre,{scope:t,forceMount:n,children:v.jsx(Bs,{present:n||s.open,children:v.jsx(id,{asChild:!0,container:i,children:r})})})};vB.displayName=x1;var Vu="TooltipContent",yB=_.forwardRef((e,t)=>{const n=cre(Vu,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=$f(Vu,e.__scopeTooltip);return v.jsx(Bs,{present:r||o.open,children:o.disableHoverableContent?v.jsx(_B,{side:i,...s,ref:t}):v.jsx(ure,{side:i,...s,ref:t})})}),ure=_.forwardRef((e,t)=>{const n=$f(Vu,e.__scopeTooltip),r=S1(Vu,e.__scopeTooltip),i=_.useRef(null),s=Bn(t,i),[o,l]=_.useState(null),{trigger:u,onClose:d}=n,h=i.current,{onPointerInTransitChange:p}=r,y=_.useCallback(()=>{l(null),p(!1)},[p]),g=_.useCallback((b,w)=>{const x=b.currentTarget,E={x:b.clientX,y:b.clientY},k=pre(E,x.getBoundingClientRect()),T=mre(E,k),R=gre(w.getBoundingClientRect()),z=yre([...T,...R]);l(z),p(!0)},[p]);return _.useEffect(()=>()=>y(),[y]),_.useEffect(()=>{if(u&&h){const b=x=>g(x,h),w=x=>g(x,u);return u.addEventListener("pointerleave",b),h.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",b),h.removeEventListener("pointerleave",w)}}},[u,h,g,y]),_.useEffect(()=>{if(o){const b=w=>{const x=w.target,E={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),T=!vre(E,o);k?y():T&&(y(),d())};return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[u,h,o,d,y]),v.jsx(_B,{...e,ref:s})}),[dre,hre]=Wv(mf,{isInside:!1}),fre=VZ("TooltipContent"),_B=_.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=$f(Vu,n),d=qv(n),{onClose:h}=u;return _.useEffect(()=>(document.addEventListener(L0,h),()=>document.removeEventListener(L0,h)),[h]),_.useEffect(()=>{if(u.trigger){const p=y=>{const g=y.target;g!=null&&g.contains(u.trigger)&&h()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,h]),v.jsx(rd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:h,children:v.jsxs(Lv,{"data-state":u.stateAttribute,...d,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[v.jsx(fre,{children:r}),v.jsx(dre,{scope:n,isInside:!0,children:v.jsx(YL,{id:u.contentId,role:"tooltip",children:i||r})})]})})});yB.displayName=Vu;var bB="TooltipArrow",wB=_.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=qv(n);return hre(bB,n).isInside?null:v.jsx(Iv,{...i,...r,ref:t})});wB.displayName=bB;function pre(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 mre(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 gre(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 vre(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 yre(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),_re(t)}function _re(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 bre=pB,wre=mB,Sre=gB,xre=vB,Ere=yB,Cre=wB;function E1({...e}){return v.jsx(bne,{"data-slot":"popover",...e})}function C1({...e}){return v.jsx(wne,{"data-slot":"popover-trigger",...e})}function k1({className:e,align:t="center",sideOffset:n=4,...r}){return v.jsx(Sne,{children:v.jsx(xne,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}const kre={"no-proxy":{heading:"还没有连接开发机",body:"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。"},"client-token-missing":{heading:"需要 client token",body:"Relay 服务器已启用客户端访问控制。请在设置里填写。"},"client-token-invalid":{heading:"client token 无效",body:"当前浏览器保存的 client token 无效或已过期。请在设置里更新。"},"no-session":{heading:"没有选中的会话",body:""},"no-messages":{heading:"开始对话",body:""}};function nc({variant:e,action:t}){const{heading:n,body:r}=kre[e];return e==="no-messages"?v.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:v.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[v.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&v.jsx("div",{children:t})]})}const Tre={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Rre={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function AN({status:e,className:t}){return v.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Tre[e],t),role:"status","aria-label":Rre[e]})}function SB({layout:e,variant:t="default"}){const n=ze(w=>w.proxies),r=ze(w=>w.proxyListLoaded),i=ze(w=>w.relayClientAuthIssue),s=ze(w=>w.selectedProxyId),o=Bi(),l=Js(),[u,d]=_.useState(!1),[h,p]=_.useState(null);async function y(w,x){if(h)return;const E=Mt;if(!E){nt.error("请先连接开发机");return}const k=x??w;p(w);try{const T=await E.selectProxy(w);if(!T.success){nt.error(`无法连接 ${k}:${T.error??"未知错误"}`);return}dr("local",ln.proxyId,w),ze.getState().setProxy(w,x??null),ze.getState().setProxyOnline(!0),ze.getState().transitionToPhase("session_browsing"),E.sendControl({type:"session_list"}),E.requestAgentStatuses().then(R=>{const z=Ut.getState();for(const N of R)z.setAgentStatus(N.sessionId,N.payload)}).catch(R=>{console.error("[proxy-switcher] post-bind data fetch failed",R)}),E.requestSessionHistory().then(R=>Ut.getState().setHistorySessions(R)).catch(R=>{console.error("[proxy-switcher] post-bind data fetch failed",R)}),d(!1),(e==="page"||o.pathname.startsWith("/chat/"))&&l("/sessions")}catch(T){const R=T instanceof Error?T.message:"未知错误";nt.error(`无法连接 ${k}:${R}`)}finally{p(null)}}if(e==="page")return i==="missing_client_token"?v.jsx(nc,{variant:"client-token-missing"}):i==="invalid_client_token"?v.jsx(nc,{variant:"client-token-invalid"}):r?n.length===0?v.jsx(nc,{variant:"no-proxy"}):v.jsxs("div",{className:"flex flex-col gap-3 p-4 h-full overflow-auto",children:[v.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"可连接开发机"}),v.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-3 px-3 h-11 min-h-[44px] rounded-md border bg-card transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-card",x?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线,暂时无法连接",children:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"正在连接"}),v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-hidden":!0})]}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})]}):v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});const g=n.find(w=>w.proxyId===s),b=(g==null?void 0:g.name)??(g==null?void 0:g.proxyId)??"未选择开发机";return v.jsxs(E1,{open:u,onOpenChange:d,children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 hover:bg-accent"),"aria-label":`当前连接:${b}`,children:[t==="default"&&v.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),v.jsx("span",{className:We("truncate",t==="sidebarChrome"?"min-w-0 text-base font-semibold leading-none":"flex-1 text-center text-sm font-normal"),children:b}),v.jsx(gl,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),v.jsx(k1,{align:"start",className:"w-[260px] p-1",children:n.length===0?v.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):v.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(w=>{const x=h===w.proxyId,E=h!==null;return v.jsx("li",{children:v.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":w.proxyId,"data-online":w.online,"data-selecting":x||void 0,disabled:!w.online||E,"aria-busy":x||void 0,onClick:()=>y(w.proxyId,w.name),className:We("w-full flex items-center gap-2 px-2 h-9 rounded-md transition-colors text-left disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",x?"bg-accent text-accent-foreground":"hover:bg-accent",E&&!x?"opacity-50":"",w.online?"":"opacity-50"),"aria-pressed":s===w.proxyId,title:w.online?void 0:"这台开发机离线",children:[v.jsx(AN,{status:w.online?"online":"offline"}),v.jsx("span",{className:"text-sm font-normal flex-1 truncate min-w-0",children:w.name??w.proxyId}),x?v.jsx(Lu,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===w.proxyId?v.jsx(ra,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!w.online&&s!==w.proxyId&&!x&&v.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]})},w.proxyId)})})})]})}const NN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,MN=NP,Are=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return MN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(d=>{const h=n==null?void 0:n[d],p=s==null?void 0:s[d];if(h===null)return null;const y=NN(h)||NN(p);return i[d][y]}),l=n&&Object.entries(n).reduce((d,h)=>{let[p,y]=h;return y===void 0||(d[p]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,h)=>{let{class:p,className:y,...g}=h;return Object.entries(g).every(b=>{let[w,x]=b;return Array.isArray(x)?x.includes({...s,...l}[w]):{...s,...l}[w]===x})?[...d,p,y]:d},[]);return MN(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Nre=Are("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-normal whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function St({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?WZ:"button";return v.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(Nre({variant:t,size:n,className:e})),...i})}function Mre({delayDuration:e=0,...t}){return v.jsx(bre,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Hf({...e}){return v.jsx(wre,{"data-slot":"tooltip",...e})}function Uf({...e}){return v.jsx(Sre,{"data-slot":"tooltip-trigger",...e})}function Wf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return v.jsx(xre,{children:v.jsxs(Ere,{"data-slot":"tooltip-content",sideOffset:t,className:We("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&v.jsx(Cre,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function Vv({...e}){return v.jsx(e1,{"data-slot":"sheet",...e})}function Ore({...e}){return v.jsx(_J,{"data-slot":"sheet-trigger",...e})}function Dre({...e}){return v.jsx(t1,{"data-slot":"sheet-portal",...e})}function Pre({className:e,...t}){return v.jsx(n1,{"data-slot":"sheet-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Yv({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,...l}){return v.jsxs(Dre,{children:[v.jsx(Pre,{className:t}),v.jsxs(r1,{"data-slot":"sheet-content",className:We("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:u=>{o==null||o(u),!(!s||u.defaultPrevented)&&(u.preventDefault(),u.currentTarget.focus({preventScroll:!0}))},...l,children:[n,i&&v.jsxs(i1,{"data-slot":"sheet-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[v.jsx(Of,{className:"size-4"}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function T1({className:e,...t}){return v.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function Kv({className:e,...t}){return v.jsx(wI,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Lre({className:e,...t}){return v.jsx(SI,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}function R1({...e}){return v.jsx(tne,{"data-slot":"dropdown-menu",...e})}function A1({...e}){return v.jsx(nne,{"data-slot":"dropdown-menu-trigger",...e})}function N1({className:e,sideOffset:t=4,...n}){return v.jsx(rne,{children:v.jsx(ine,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})})}function bo({className:e,inset:t,variant:n="default",...r}){return v.jsx(one,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function Kb({className:e,children:t,checked:n,...r}){return v.jsxs(ane,{"data-slot":"dropdown-menu-checkbox-item",className:We("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[v.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:v.jsx(lne,{children:v.jsx(ra,{className:"size-4"})})}),t]})}function Im({className:e,inset:t,...n}){return v.jsx(sne,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Gb({className:e,...t}){return v.jsx(cne,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}const Ire={claude:"Claude Code",codex:"Codex"},ON=["claude","codex"];function Gv(e){return Ire[e]}function xB(e,t){return ON.indexOf(e)-ON.indexOf(t)}function z0(e){return e.provider??"claude"}const B0=60*1e3,j0=60*B0,zre=24*j0;function EB(e,t=Date.now()){const n=t-e;if(n<B0)return"刚刚";if(n<j0)return`${Math.floor(n/B0)} 分钟前`;if(n<zre)return`${Math.floor(n/j0)} 小时前`;const r=new Date(e),i=r.getMonth()+1,s=r.getDate(),o=String(r.getHours()).padStart(2,"0"),l=String(r.getMinutes()).padStart(2,"0");return`${i} 月 ${s} 日 ${o}:${l}`}const DN={idle:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"空闲"},working:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"工作中"},compacting:{dot:"bg-[var(--color-status-compacting)] animate-pulse",text:"text-[var(--color-status-compacting)]",label:"压缩中"},waiting_approval:{dot:"bg-[var(--color-status-warning)]",text:"text-[var(--color-status-warning)]",label:"等待审批"},error:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"出错"},terminated:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已终止"}};function F0(e){return e.kind!=="terminal"?DN[e.state]:e.state==="terminated"?DN.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function Bre({session:e}){const t=F0(e);return v.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function jre({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.jsx("span",{className:"inline-flex h-5 w-4 shrink-0 items-center justify-center text-muted-foreground",role:"img","aria-label":t,title:t,"data-slot":"session-mode-icon","data-mode":e,children:v.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function Fre({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=e.lastActive,l=e.cwd??e.name??e.sessionId,u=Ev(e.name),d=Vx(e),h=e.nameLocked&&e.name?e.name:d||(u==="New Session"?e.sessionId.slice(0,8):u),p=!!e.mode||!!e.provider||o!==void 0,y=o!==void 0?EB(o,n):null,g=e.mode==="pty"&&e.ptyOwner==="local-terminal",b=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return v.jsxs("li",{className:We("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&v.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),v.jsxs("button",{type:"button",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[v.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[v.jsx(Bre,{session:e}),v.jsx("span",{className:"text-sm font-normal truncate flex-1",title:l,children:h})]}),p&&v.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[e.mode&&v.jsx(jre,{mode:e.mode}),e.mode&&v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.provider&&e.kind!=="terminal"&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Gv(e.provider)}),v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),v.jsx("span",{className:We("shrink-0",F0(e).text),children:F0(e).label}),y&&v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),v.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:y})]})]})]}),(i||s)&&v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:v.jsx(St,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:v.jsx(K9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end","data-slot":"session-row-menu",children:[i&&v.jsx(bo,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&v.jsx(bo,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:b})]})]})]})}function Sc({...e}){return v.jsx(e1,{"data-slot":"dialog",...e})}function $re({...e}){return v.jsx(t1,{"data-slot":"dialog-portal",...e})}function Hre({className:e,...t}){return v.jsx(n1,{"data-slot":"dialog-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function xc({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,...s}){return v.jsxs($re,{"data-slot":"dialog-portal",children:[v.jsx(Hre,{}),v.jsxs(r1,{"data-slot":"dialog-content",className:We("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:o=>{i==null||i(o),!(!r||o.defaultPrevented)&&(o.preventDefault(),o.currentTarget.focus({preventScroll:!0}))},...s,children:[t,n&&v.jsxs(i1,{"data-slot":"dialog-close",className:"absolute top-2 right-2 flex size-11 items-center justify-center rounded-md opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[v.jsx(Of,{}),v.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ec({className:e,...t}){return v.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Yu({className:e,showCloseButton:t=!1,children:n,...r}){return v.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&v.jsx(i1,{asChild:!0,children:v.jsx(St,{variant:"outline",children:"Close"})})]})}function dl({className:e,...t}){return v.jsx(wI,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function dc({className:e,...t}){return v.jsx(SI,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function hl(e){const[t,n]=_.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return _.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function Ure({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=v.jsx(Wre,{title:e.title,modeTag:s}),l=v.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:EB(e.updatedAt,t)}),u=v.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return v.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:v.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:We("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,v.jsx(S9,{className:We("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Wre({title:e,modeTag:t}){return v.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[v.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&v.jsx(qre,{mode:t})]})}function qre({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?kx:Rx;return v.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:v.jsx(n,{className:"size-3","aria-hidden":"true"})})}function CB({providerLabel:e}){return v.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:v.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[v.jsx(K8,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),v.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function Vre({now:e}){const t=Ut(U=>U.historySessions),[n,r]=_.useState(null),[i,s]=_.useState(null),[o,l]=_.useState("json"),[u,d]=_.useState("default"),[h,p]=_.useState(!1),[y,g]=_.useState(!1),[b,w]=_.useState(new Set),[x,E]=_.useState(new Set),k=Js(),T=_.useMemo(()=>{const U=new Map;for(const O of t){const M=z0(O);let I=U.get(M);I||(I=new Map,U.set(M,I));const L=kB(O.projectDir),D=I.get(L);D?D.sessions.push(O):I.set(L,{dir:L,sessions:[O]})}return Array.from(U.entries()).sort(([O],[M])=>xB(O,M)).map(([O,M])=>({provider:O,sessions:Array.from(M.values()).flatMap(I=>I.sessions),projects:Array.from(M.values()).map(I=>({dir:I.dir,shortDir:Ev(I.dir),sessions:I.sessions}))}))},[t]);function R(U){s(U),l(Yre(U)),d("default")}async function z(U,O,M){if(n)return;const I=Mt;if(!I){nt.error("请先连接开发机");return}r(U.id);const L=z0(U);try{const D=await I.createSession({cwd:U.projectDir,mode:O,provider:L,resumeSessionId:U.id,...M?{permissionMode:M}:{}});if(D.error||!D.sessionId){nt.error(`恢复失败:${D.error??"未知错误"}`);return}const Y={sessionId:D.sessionId,state:"idle",mode:D.mode??O,provider:D.provider??"claude"};Ut.getState().addSession(Y),k(`/chat/${D.sessionId}?mode=${D.mode??O}`),s(null)}catch(D){nt.error(`恢复失败:${D instanceof Error?D.message:String(D)}`)}finally{r(null)}}function N(){const U=Mt;!U||h||(p(!0),U.requestSessionHistory().then(O=>Ut.getState().setHistorySessions(O)).catch(O=>{nt.error(O instanceof Error?O.message:String(O))}).finally(()=>{p(!1)}))}function $(U,O){const M=PN(U,O);E(I=>{const L=new Set(I);return L.has(M)?L.delete(M):L.add(M),L})}function P(U){w(O=>{const M=new Set(O);return M.has(U)?M.delete(U):M.add(U),M})}const q=t.length>0,H=i?TB():[];return v.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[v.jsxs("div",{className:"flex min-h-[36px] w-full items-center gap-1.5 px-4 py-1.5",children:[v.jsxs("button",{type:"button",onClick:()=>q&&g(U=>!U),disabled:!q,"aria-expanded":q?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:We("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[v.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",q?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),q?v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":h,title:"刷新",onClick:N,disabled:h,"data-slot":"history-refresh",children:v.jsx(Tx,{className:We("size-3.5",h&&"animate-spin"),"aria-hidden":"true"})})]}),!q&&v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),q&&y&&v.jsx("ul",{role:"list",className:"flex flex-col",children:T.map(U=>{const O=b.has(U.provider);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>P(U.provider),"aria-expanded":!O,"data-slot":"history-provider-header","data-expanded":!O,className:We("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:Gv(U.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:U.sessions.length}),v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!O&&"rotate-90"),"aria-hidden":"true"})]}),!O&&v.jsx("ul",{role:"list",className:"flex flex-col",children:U.projects.map(M=>{const I=PN(U.provider,M.dir),L=x.has(I);return v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>$(U.provider,M.dir),"aria-expanded":L,"data-slot":"history-group-header","data-expanded":L,className:We("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:M.dir,children:M.shortDir}),v.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:M.sessions.length}),v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",L&&"rotate-90"),"aria-hidden":"true"})]}),L&&v.jsx("ul",{role:"list",className:"flex flex-col",children:M.sessions.map(D=>v.jsx(Ure,{session:D,now:e,disabled:n!==null,loading:n===D.id,onClick:()=>R(D),modeTag:D.preferredMode},D.id))})]},I)})})]},U.provider)})}),v.jsx(Kre,{session:i,open:i!==null,modes:H,mode:o,permissionMode:u,submitting:n!==null,onOpenChange:U=>{U||s(null)},onModeChange:l,onPermissionModeChange:d,onConfirm:()=>{i&&z(i,o,u)}})]})}function PN(e,t){return`${e}:${kB(t)}`}function kB(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function TB(){return["json","pty"]}function Yre(e){const t=TB();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function Kre({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[h,p]=_.useState(!1),y=i==="bypassPermissions",g=hl("(min-width: 768px)");_.useEffect(()=>{t||p(!1)},[t]);const b=h?v.jsx(CB,{providerLabel:e?Gv(z0(e)):"Agent"}):v.jsxs("div",{className:"grid min-w-0 gap-4",children:[v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&v.jsx(LN,{checked:r==="json",label:"聊天",icon:v.jsx(kx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&v.jsx(LN,{checked:r==="pty",label:"终端",icon:v.jsx(Rx,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),v.jsxs("div",{className:"grid min-w-0 gap-2",children:[v.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),v.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[v.jsx(Xb,{checked:i==="default",label:"严格审批",description:"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),v.jsx(Xb,{checked:i==="auto",label:"自动判定",description:"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),v.jsx(Xb,{checked:i==="bypassPermissions",label:"跳过全部审批",description:"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),w=v.jsxs(v.Fragment,{children:[v.jsx(St,{type:"button",variant:"ghost",disabled:s,onClick:()=>{h?p(!1):o(!1)},children:h?"返回":"取消"}),v.jsx(St,{type:"button",variant:h?"destructive":"default",disabled:s,onClick:()=>{if(y&&!h){p(!0);return}d()},"data-slot":h?"bypass-permission-confirm":void 0,children:s?"恢复中...":h?"确认":"恢复"})]});return g?v.jsx(Sc,{open:t,onOpenChange:o,children:v.jsxs(xc,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[v.jsxs(Ec,{className:"min-w-0",children:[v.jsx(dl,{children:h?"跳过全部审批?":"恢复会话"}),v.jsx(dc,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),b,v.jsx(Yu,{children:w})]})}):v.jsx(Vv,{open:t,onOpenChange:o,children:v.jsxs(Yv,{side:"bottom",focusSurfaceOnOpen:!0,className:"inset-x-2 w-auto max-h-[calc(100dvh-0.75rem)] min-w-0 overflow-hidden rounded-t-xl border bg-background p-0","data-slot":"history-restore-dialog",children:[v.jsxs(T1,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[v.jsx(Kv,{children:h?"跳过全部审批?":"恢复会话"}),v.jsx(Lre,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),v.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:b}),v.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:v.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:w})})]})})}function LN({checked:e,label:t,icon:n,disabled:r,onClick:i}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:We("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,v.jsx("span",{className:"min-w-0 text-center",children:t}),v.jsx(ra,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Xb({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return v.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:We("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[v.jsx("span",{className:We("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&v.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),v.jsxs("span",{className:"grid min-w-0 gap-1",children:[v.jsx("span",{className:We("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),v.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&v.jsx(ra,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Gre({...e}){return v.jsx(Yne,{"data-slot":"select",...e})}function Xre({...e}){return v.jsx(Gne,{"data-slot":"select-value",...e})}function Zre({className:e,size:t="default",children:n,...r}){return v.jsxs(Kne,{"data-slot":"select-trigger","data-size":t,className:We("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,v.jsx(Xne,{asChild:!0,children:v.jsx(gl,{className:"size-4 opacity-50"})})]})}function Qre({className:e,children:t,position:n="item-aligned",align:r="center",...i}){return v.jsx(Zne,{children:v.jsxs(Qne,{"data-slot":"select-content",className:We("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,...i,children:[v.jsx(eie,{}),v.jsx(Jne,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),v.jsx(tie,{})]})})}function Jre({className:e,children:t,...n}){return v.jsxs(ere,{"data-slot":"select-item",className:We("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[v.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:v.jsx(nre,{children:v.jsx(ra,{className:"size-4"})})}),v.jsx(tre,{children:t})]})}function eie({className:e,...t}){return v.jsx(rre,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(Cx,{className:"size-4"})})}function tie({className:e,...t}){return v.jsx(ire,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:v.jsx(gl,{className:"size-4"})})}function M1(e){return!e||e.endsWith("/")?e:`${e}/`}function nie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(n+1).toLowerCase():t.toLowerCase()}function rie(e){const t=e.split("@").pop()??"",n=t.lastIndexOf("/");return n>=0?t.slice(0,n+1):""}function iie(e,t,n){var o;if(t==="insert")return{currentPath:rie(e)||"./",query:nie(e)};if(!e)return{currentPath:"./",query:""};const r=e.replace(/\/+$/,"")||"/";if(e.endsWith("/")||r===(n==null?void 0:n.baseCwd)||((o=n==null?void 0:n.knownDirs)==null?void 0:o.has(r)))return{currentPath:M1(r),query:""};const s=e.lastIndexOf("/");return{currentPath:s>=0?e.slice(0,s+1):"./",query:s>=0?e.slice(s+1).toLowerCase():e.toLowerCase()}}function sie(e,t){if(t.startsWith("/"))return t.replace(/\/+$/,"")||"/";if(!e)return"";const n=t.replace(/^\.\//,"").replace(/\/+$/,"");return n?`${e}/${n}`:e}function oie(e,t){return`${M1(e)}${t.name}${t.isDir?"/":""}`}function IN(e,t){const n=e.trim().replace(/\/+$/,"")||"/",r=t.trim().replace(/^\/+|\/+$/g,"");return!n.startsWith("/")||!r||t.trim().startsWith("/")||r.split("/").some(i=>i===""||i==="."||i==="..")?null:n==="/"?`/${r}`:`${n}/${r}`}const RB=_.forwardRef(function({filter:t,onSelect:n,onCreateDirectory:r,mode:i="insert",placement:s="floating",dirsOnly:o=!1,title:l},u){const d=Ei(F=>F.tree),h=Ei(F=>F.cwd),p=Ei(F=>F.homePath),y=i==="insert"?h:p||h,g=_.useMemo(()=>new Set(d.keys()),[d]),b=_.useMemo(()=>iie(t,i,{baseCwd:y,knownDirs:g}),[t,i,y,g]),w=b.currentPath,x=_.useMemo(()=>sie(y,w),[y,w]),E=b.query,k=_.useRef(new Set),[T,R]=_.useState(!1),[z,N]=_.useState(""),[$,P]=_.useState(!1);_.useEffect(()=>{if(!x||d.has(x)||k.current.has(x))return;const F=Mt;if(!F)return;let A=!1;return k.current.add(x),F.requestDirectoryList(x).then(W=>{A||Ei.getState().setDirEntries(W.path,W.entries)}).catch(()=>{A||Ei.getState().setDirEntries(x,[])}).finally(()=>{k.current.delete(x)}),()=>{A=!0}},[x,d]);const q=!d.has(x),H=_.useMemo(()=>{let F=d.get(x)??[];return o&&(F=F.filter(A=>A.isDir)),E&&(F=F.filter(A=>A.name.toLowerCase().includes(E))),F},[d,x,E,o]),[U,O]=_.useState(0);_.useEffect(()=>O(0),[w,E]),_.useEffect(()=>{R(!1),N("")},[x]),_.useEffect(()=>{U>=H.length&&H.length>0&&O(H.length-1)},[H.length,U]);const M=_.useRef(null),I=_.useRef(!1);_.useEffect(()=>{var A;if(!I.current)return;I.current=!1;const F=(A=M.current)==null?void 0:A.querySelector(`[data-entry-index="${U}"]`);F==null||F.scrollIntoView({block:"nearest"})},[U]);const L=_.useCallback(F=>{const A=oie(w,F);return i==="insert"?A.replace(/^\.\//,""):A},[w,i]);async function D(){const F=IN(x,z);if(!(!F||!r)){P(!0);try{const A=await r(F);if(!A)return;N(""),R(!1),n(M1(A))}finally{P(!1)}}}_.useImperativeHandle(u,()=>({handleKey(F){return H.length===0?!1:F.key==="ArrowDown"?(I.current=!0,O(A=>Math.min(H.length-1,A+1)),!0):F.key==="ArrowUp"?(I.current=!0,O(A=>Math.max(0,A-1)),!0):F.key==="Enter"&&!F.nativeEvent.isComposing?(n(L(H[U])),!0):!1}}),[H,U,L,n]);const Y=s==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":i==="insert"?"absolute bottom-full left-0 right-0 z-50 mb-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden":"absolute left-0 right-0 top-full z-50 mt-2 bg-popover border border-border rounded-md shadow-lg overflow-hidden",K=s==="inline"?"h-44 overflow-y-auto overscroll-contain":i==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return v.jsxs("div",{className:Y,"data-slot":"file-path-picker","data-mode":i,"data-placement":s,children:[i==="select"&&l?v.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx("span",{className:"text-xs text-muted-foreground",children:l}),r?v.jsx("button",{type:"button",className:"rounded px-2 py-1 text-xs text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",disabled:!x||$,onClick:()=>R(F=>!F),children:"新建目录"}):null]}),T?v.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[v.jsx("input",{type:"text",value:z,onChange:F=>N(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!F.nativeEvent.isComposing&&(F.preventDefault(),D()),F.key==="Escape"&&(R(!1),N(""))},placeholder:"目录名称",className:"min-h-11 min-w-0 flex-1 rounded-md border border-border bg-input px-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-8 md:min-h-0 md:text-sm",autoComplete:"off",autoCorrect:"off",spellCheck:!1}),v.jsx("button",{type:"button",className:"min-h-11 rounded-md bg-primary px-3 text-sm text-primary-foreground disabled:cursor-not-allowed disabled:opacity-50 md:h-8 md:min-h-0",disabled:!IN(x,z)||$,onClick:()=>void D(),children:$?"创建中...":"创建目录"})]}):null]}):null,v.jsx("div",{className:K,children:H.length===0?v.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:q?"加载中...":"没有匹配的路径"}):v.jsx("ul",{ref:M,role:"list",className:"flex flex-col",children:H.map((F,A)=>v.jsx("li",{children:v.jsx("button",{type:"button",onClick:()=>n(L(F)),onMouseEnter:()=>O(A),className:We("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",A===U&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",F.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":F.isDir?"dir":"file","data-entry-index":A,children:v.jsxs("span",{className:"font-mono text-[13px]",children:[F.name,F.isDir?"/":""]})})},F.name))})})]})}),zN="工作目录不存在或不可访问:",aie=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],AB=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"bypassPermissions",label:"跳过全部审批"}],na={claude:"Claude Code",codex:"Codex"};function lie(e,t){return t!==Xr.PATH_NOT_FOUND||!e.startsWith(zN)?null:e.slice(zN.length).trim()||null}function Kg(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function cie(e,t){return t.title?t.disabled?`${na[e]}:${t.title}`:`${na[e]} 路径:${t.title}`:`${na[e]}:${t.label}`}function uie(e,t){return e!=="codex"||AB.some(n=>n.value===t)?t:"default"}async function die({relay:e,agentCli:t,form:n,timeoutMs:r=Ux}){var d,h;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(Kg(n.provider,t).disabled){const p=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:p?`${na[n.provider]} 不可用:${p}`:`${na[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const p=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(p.error||!p.sessionId){const w=lie(p.error??"",p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error??"未知错误"}`}}const y=p.mode??o,g=((h=p.name)==null?void 0:h.trim())||void 0;return{type:"success",session:{sessionId:p.sessionId,...p.kind!==void 0?{kind:p.kind}:{},name:g,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",mode:y,provider:p.provider??l,...p.ptyOwner!==void 0?{ptyOwner:p.ptyOwner}:{}},route:`/chat/${p.sessionId}?mode=${y}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function hie({relay:e,timeoutMs:t=Ux}){var n;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const r=await e.createSession({kind:"terminal",mode:"pty"},t);return r.error||!r.sessionId?{type:"create_error",message:`创建终端失败:${r.error??"未知错误"}`}:{type:"success",session:{sessionId:r.sessionId,kind:"terminal",name:((n=r.name)==null?void 0:n.trim())||void 0,...r.nameLocked!==void 0?{nameLocked:r.nameLocked}:{},state:"idle",mode:"pty",provider:r.provider??"claude",...r.ptyOwner!==void 0?{ptyOwner:r.ptyOwner}:{}},route:`/chat/${r.sessionId}?mode=pty`}}catch(r){return{type:"exception",message:r instanceof Error?r.message:String(r)}}}function fie({agentCli:e,provider:t,isDesktop:n,editingCliProvider:r,cliPathInput:i,savingCliPath:s,onProviderChange:o,onOpenCliPathEditor:l,onCliPathInputChange:u,onCancelCliPathEditor:d,onSaveCliPath:h}){const p=Kg("claude",e),y=Kg("codex",e),g=e==null?void 0:e[t];return v.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[v.jsxs("div",{className:"flex items-center justify-between",children:[v.jsx("span",{className:"text-sm",children:"Agent CLI"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"选择要启动的 CLI"})]}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsx(BN,{provider:"claude",selected:t==="claude",status:p,agentCliLoaded:!!e,onClick:()=>o("claude")}),v.jsx(BN,{provider:"codex",selected:t==="codex",status:y,agentCliLoaded:!!e,onClick:()=>o("codex")})]}),v.jsx("div",{className:"relative min-w-0 rounded-md border border-border bg-muted/20 px-3 py-2.5 md:p-3","data-slot":"agent-cli-path-card",children:r===t?v.jsx(pie,{provider:r,agentCli:e,cliPathInput:i,savingCliPath:s,onCliPathInputChange:u,onCancel:d,onSave:h}):v.jsx(mie,{provider:t,selectedCli:g,isDesktop:n,onOpenCliPathEditor:l})})]})}function BN({provider:e,selected:t,status:n,agentCliLoaded:r,onClick:i}){return v.jsxs(Hf,{children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-pressed":t,"aria-label":na[e],onClick:i,className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",t?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:na[e]}),v.jsx("span",{className:We("text-xs text-muted-foreground",n.disabled&&r&&"text-destructive"),children:n.label})]})}),v.jsx(Wf,{side:"top",className:"max-w-[min(520px,calc(100vw-2rem))]",children:v.jsx("span",{className:"break-all font-mono text-xs",children:cie(e,n)})})]})}function pie({provider:e,agentCli:t,cliPathInput:n,savingCliPath:r,onCliPathInputChange:i,onCancel:s,onSave:o}){return v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center",children:[v.jsxs("label",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:"sr-only",children:"CLI 路径"}),v.jsx("input",{type:"text",list:`agent-cli-path-${e}`,value:n,onChange:l=>i(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),o()),l.key==="Escape"&&(l.preventDefault(),s())},placeholder:e==="claude"?"/home/dev/.local/bin/claude":"/home/dev/.local/bin/codex",className:"min-h-11 w-full rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-10 md:min-h-0 md:text-sm"}),v.jsx("datalist",{id:`agent-cli-path-${e}`,children:((t==null?void 0:t[e].suggestions)??[]).map(l=>v.jsx("option",{value:l},l))})]}),v.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground md:h-8 md:min-h-0",onClick:s,disabled:r,children:"取消"}),v.jsx(St,{type:"button",className:"min-h-11 shrink-0 rounded px-2.5 text-xs font-medium md:h-8 md:min-h-0",onClick:o,disabled:r||!n.trim(),children:r?"保存中...":"保存路径"})]})]})]})}function mie({provider:e,selectedCli:t,isDesktop:n,onOpenCliPathEditor:r}){return n?v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsxs("div",{className:"flex min-w-0 flex-col gap-2 md:flex-row md:items-center",children:[v.jsx("p",{className:We("flex h-10 min-w-0 flex-1 items-center truncate font-mono text-sm",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"}),v.jsx(St,{type:"button",variant:"outline",className:"h-8 min-h-0 shrink-0 self-end rounded px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground sm:self-auto",onClick:()=>r(e),children:"指定路径"})]})]}):v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"pr-11 text-xs text-muted-foreground",children:"CLI 路径"}),v.jsx(St,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 size-11 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/70 hover:text-foreground","aria-label":"指定路径",onClick:()=>r(e),children:v.jsx(x8,{className:"size-4","aria-hidden":"true"})}),v.jsx("p",{className:We("mt-1 min-w-0 break-all pr-11 font-mono text-sm leading-5",t!=null&&t.available?"text-foreground":"text-destructive"),title:(t==null?void 0:t.command)??(t==null?void 0:t.error),children:(t==null?void 0:t.command)??(t==null?void 0:t.error)??"等待检测结果"})]})}function Ih({open:e,onOpenChange:t}){const[n,r]=_.useState(""),[i,s]=_.useState(""),[o,l]=_.useState("claude"),[u,d]=_.useState("pty"),[h,p]=_.useState("default"),[y,g]=_.useState(!1),[b,w]=_.useState(!1),[x,E]=_.useState(null),[k,T]=_.useState(!1),[R,z]=_.useState(null),[N,$]=_.useState(""),[P,q]=_.useState(!1),H=_.useRef(null),U=_.useRef(e);U.current=e;const O=Js(),M=Ei(Ee=>Ee.homePath),I=Ei(Ee=>Ee.agentCli),L=hl("(min-width: 768px)");_.useEffect(()=>{e&&!i&&M&&s(M)},[e,M,i]),_.useEffect(()=>{if(!e||M&&I)return;const Ee=Mt==null?void 0:Mt.requestProxyInfo();Ee&&Ee.then(Re=>{const Ie=Ei.getState();Ie.setHomePath(Re.homePath),Ie.setAgentCli(Re.agentCli)}).catch(Re=>{console.error("[create-session-dialog] requestProxyInfo failed",Re)})},[e,M,I]),_.useEffect(()=>{if(!k)return;function Ee(Re){var Ye;const Ie=Re.target;Ie instanceof Node&&((Ye=H.current)!=null&&Ye.contains(Ie))||window.setTimeout(()=>T(!1),0)}return document.addEventListener("pointerdown",Ee,!0),()=>document.removeEventListener("pointerdown",Ee,!0)},[k]);function D(){r(""),s(""),T(!1),l("claude"),d("pty"),p("default"),g(!1),E(null),z(null),$(""),q(!1)}function Y(){if(h==="bypassPermissions"){g(!0);return}B()}async function K(){await B(),U.current&&g(!1)}const F=o==="codex"?AB:aie,A=Kg(o,I),W=b||P||A.disabled;function G(Ee){const Re=uie(Ee,h);Re!==h&&p(Re)}async function B(Ee){E(null),w(!0);try{const Re=await die({relay:Mt,agentCli:I,form:{cwd:Ee??i,name:n,provider:o,permissionMode:h,mode:u}});if(Re.type==="success"){if(Ut.getState().addSession(Re.session),!U.current)return;t(!1),D(),O(Re.route);return}if(Re.type==="missing_cwd"&&E(Re.path),nt.error(Re.message),Re.type==="validation_error"||Re.type==="relay_missing")return}finally{w(!1)}}async function ne(Ee){const Re=Mt;if(!Re)return nt.error("请先连接开发机"),null;try{const Ie=await Re.createDirectory(Ee);return Ie.success?(s(Ie.path),E(null),nt.success("目录已创建"),Ie.path):(nt.error(`目录创建失败:${Ie.error??"未知错误"}`),null)}catch(Ie){return nt.error(Ie instanceof Error?Ie.message:String(Ie)),null}}function ie(Ee){var Ie;const Re=I==null?void 0:I[Ee];z(Ee),$((Re==null?void 0:Re.command)??((Ie=Re==null?void 0:Re.suggestions)==null?void 0:Ie[0])??"")}async function se(){if(!R)return;const Ee=N.trim();if(!Ee){nt.error("请输入 Agent CLI 路径");return}const Re=Mt;if(!Re){nt.error("请先连接开发机");return}q(!0);try{const Ie=await Re.updateAgentCliPath(R,Ee);if(Ie.error||!Ie.agentCli){nt.error(`路径保存失败:${Ie.error??"未知错误"}`);return}Ei.getState().setAgentCli(Ie.agentCli),nt.success(`${na[R]} 路径已保存`),z(null),$("")}catch(Ie){nt.error(Ie instanceof Error?Ie.message:String(Ie))}finally{q(!1)}}function te(Ee){d(Ee),G(o)}function he(Ee){var Ie;const Re=Ee.relatedTarget;Re instanceof Node&&((Ie=H.current)!=null&&Ie.contains(Re))||window.setTimeout(()=>T(!1),0)}const ge=y?v.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[v.jsx(CB,{providerLabel:na[o]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:b,children:"返回"}),v.jsx(St,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void K(),disabled:b,"data-slot":"bypass-permission-confirm",children:b?"创建中...":"确认"})]})]}):v.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:Ee=>{Ee.preventDefault(),Y()},children:[v.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[v.jsx("span",{className:"text-sm",children:"名称(可选)"}),v.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:Ee=>r(Ee.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),v.jsxs("div",{ref:H,className:"relative flex min-w-0 flex-col gap-2",onBlur:he,children:[v.jsx("span",{id:"create-session-cwd-label",className:"text-sm",children:"工作目录"}),v.jsx("input",{id:"create-session-cwd",type:"text","aria-labelledby":"create-session-cwd-label",name:"dev-anywhere-session-cwd",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:i,onFocus:()=>T(!0),onChange:Ee=>{s(Ee.target.value),E(null)},placeholder:"输入绝对路径",className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm"}),k?v.jsx(RB,{mode:"select",dirsOnly:!0,filter:i,title:"选择下一级目录",onCreateDirectory:ne,onSelect:Ee=>{s(Ee),E(null),T(!0)}}):null]}),x?v.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[v.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),v.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:x})]}):null,v.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"交互方式"}),v.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[v.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>te("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),v.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>te("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[v.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),v.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),v.jsx(fie,{agentCli:I,provider:o,isDesktop:L,editingCliProvider:R,cliPathInput:N,savingCliPath:P,onProviderChange:Ee=>{l(Ee),G(Ee)},onOpenCliPathEditor:ie,onCliPathInputChange:$,onCancelCliPathEditor:()=>{z(null),$("")},onSaveCliPath:()=>void se()}),v.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[v.jsx("span",{className:"text-sm",children:"权限模式"}),v.jsxs(Gre,{value:h,onValueChange:Ee=>p(Ee),children:[v.jsx(Zre,{className:"w-full",children:v.jsx(Xre,{})}),v.jsx(Qre,{children:F.map(Ee=>v.jsx(Jre,{value:Ee.value,children:Ee.label},Ee.value))})]})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:b,children:"取消"}),v.jsx(St,{type:"submit",className:"min-h-11 md:min-h-0",disabled:W,children:b?"创建中...":"创建"})]})]});return L?v.jsx(Sc,{open:e,onOpenChange:t,children:v.jsxs(xc,{className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[44rem]","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[v.jsx(Ec,{children:v.jsx(dl,{children:y?"跳过全部审批?":"新建会话"})}),ge]})}):v.jsx(Vv,{open:e,onOpenChange:t,children:v.jsxs(Yv,{side:"bottom",className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto overflow-x-hidden overflow-y-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-session-dialog",focusSurfaceOnOpen:!0,children:[v.jsx(T1,{className:"px-0 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:y?"跳过全部审批?":"新建会话"})}),ge]})})}function zh({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=_.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=_.useState(s),[u,d]=_.useState(null),[h,p]=_.useState(!1);_.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function y(g){g.preventDefault();const b=o.trim();if(!b){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,b),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return v.jsx(Sc,{open:e,onOpenChange:r,children:v.jsx(xc,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:v.jsxs("form",{className:"grid gap-4",onSubmit:g=>void y(g),children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"重命名会话"}),v.jsx(dc,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),v.jsxs("div",{className:"grid gap-2",children:[v.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),v.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:h,onChange:g=>{l(g.target.value),u&&d(null)}}),u?v.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),v.jsx(St,{type:"submit",disabled:h,children:"保存"})]})]})})})}function gie(e){return(e==null?void 0:e.mode)==="pty"&&e.ptyOwner==="local-terminal"}function vie(e){return(e==null?void 0:e.kind)==="terminal"}function yie(e){return gie(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:vie(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function zm({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=yie(t);function s(){t&&(r(t),n(!1))}return v.jsx(Sc,{open:e,onOpenChange:n,children:v.jsxs(xc,{"data-slot":"session-termination-dialog",children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:i.title}),v.jsx(dc,{children:i.description})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),v.jsx(St,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function NB(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 _ie(e){if(e.session.state==="error")return"error";const t=NB(e);return t==="disconnected"?e.session.state:t}function MB({layout:e}){const t=Ut(A=>A.sessions),n=Ut(A=>A.sessionListLoaded),r=Ut(A=>A.agentStatusBySessionId),i=Ut(A=>A.ptyStateBySessionId),s=Ut(A=>A.renameSession),o=Gt(A=>A.bySessionId),l=QH("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=ze(A=>!!A.selectedProxyId),p=!ze(A=>A.proxyListLoaded)||d&&!n,y=Js(),[g,b]=_.useState(!1),[w,x]=_.useState(!1),[E,k]=_.useState(null),[T,R]=_.useState(null),{creatingTerminal:z,createTerminal:N}=OB(),[$,P]=_.useState(new Set),[q,H]=_.useState(()=>Date.now());_.useEffect(()=>{const A=setInterval(()=>H(Date.now()),6e4);return()=>clearInterval(A)},[]);function U(A,W){y(`/chat/${A}?mode=${W??"json"}`,{replace:!1})}function O(A){const W=A.sessionId,G=Mt;if(!G){nt.error("请先连接开发机");return}G.sendControl({type:"session_terminate",sessionId:W}),Ut.getState().removeSession(W),Gt.getState().clearSession(W),W===u&&y("/sessions"),(A==null?void 0:A.mode)==="pty"&&A.ptyOwner==="local-terminal"?nt.info("已断开页面连接,本地终端仍在运行"):nt.info("正在终止会话",{duration:1500})}async function M(A,W){const G=Mt;if(!G)throw new Error("请先连接开发机");const B=await G.renameSession(A,W);if(!B.success)throw new Error(B.error??"重命名失败");s(A,B.name??W),nt.success("已重命名会话")}function I(A){P(W=>{const G=new Set(W);return G.has(A)?G.delete(A):G.add(A),G})}function L(A){var B;const W=A.mode==="json"&&(((B=o[A.sessionId])==null?void 0:B.pendingApprovals.some(ne=>ne.status==="pending"))??!1),G=_ie({session:A,agentStatus:r[A.sessionId],ptyState:i[A.sessionId],hasPendingApproval:W});return G===A.state?A:{...A,state:G}}const D=t.length>0;if(e==="sidebar"&&(p||!d))return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70",children:p?"连接中...":"请先连接开发机"}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});if(e==="page"&&p)return v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:[v.jsx(Lu,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),v.jsx("p",{className:"text-sm",children:"连接中..."})]});if(e==="page"&&!d)return v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsx("div",{className:"flex-1",children:v.jsx(nc,{variant:"no-proxy"})}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]});const Y=v.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",D?v.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),K=D?v.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:bie(t).map(A=>v.jsxs("li",{children:[v.jsxs("button",{type:"button",onClick:()=>I(A.provider),"aria-expanded":!$.has(A.provider),className:We("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[v.jsx("span",{className:"font-mono",children:wie(A.provider)}),v.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),v.jsx("span",{className:"tabular-nums",children:A.sessions.length}),v.jsx(Kh,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!$.has(A.provider)&&"rotate-90"),"aria-hidden":"true"})]}),$.has(A.provider)?null:v.jsx("ul",{role:"list",className:"flex flex-col",children:A.sessions.map(W=>v.jsx(Fre,{session:L(W),selected:W.sessionId===u,now:q,onClick:()=>U(W.sessionId,W.mode),onRename:()=>k(W),onTerminate:()=>R(W)},W.sessionId))})]},A.provider))}):v.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),F=v.jsx(Vre,{now:q});return e==="page"?v.jsxs("div",{className:"flex flex-col h-full",children:[v.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:v.jsxs(St,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>x(!0),children:[v.jsx(_P,{"aria-hidden":"true"}),"新建"]})}),v.jsx(xie,{open:w,creatingTerminal:z,onOpenChange:x,onCreateAgent:()=>{x(!1),b(!0)},onCreateTerminal:()=>void N(()=>x(!1))}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]}):v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[Y,K,F]}),v.jsx(Ih,{open:g,onOpenChange:b}),v.jsx(zm,{open:T!==null,session:T,onOpenChange:A=>{A||R(null)},onConfirm:O}),v.jsx(zh,{open:E!==null,sessionId:(E==null?void 0:E.sessionId)??null,initialName:E==null?void 0:E.name,onOpenChange:A=>{A||k(null)},onRename:M})]})}function bie(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])=>Sie(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function wie(e){return e==="terminal"?"终端":Gv(e)}function Sie(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:xB(e,t)}function OB(){const e=Js(),[t,n]=_.useState(!1);async function r(i){if(!t){n(!0);try{const s=await hie({relay:Mt});if(s.type!=="success"){nt.error(s.message);return}Ut.getState().addSession(s.session),i==null||i(),e(s.route)}finally{n(!1)}}}return{creatingTerminal:t,createTerminal:r}}function jN({compact:e=!1}){const[t,n]=_.useState(!1),[r,i]=_.useState(!1),s=_.useRef(!1),o=ze(w=>!!w.selectedProxyId),{creatingTerminal:l,createTerminal:u}=OB();function d(){i(!0),window.setTimeout(()=>i(!1),2e3)}function h(){if(!o){d();return}s.current=!0,n(!0)}function p(){if(!o){d();return}s.current=!0,u()}function y(w){w.preventDefault(),d()}const g=v.jsxs(St,{variant:"outline","data-slot":"create-session-trigger",className:We(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!o&&"opacity-50 hover:bg-background"),"aria-label":"新建会话","aria-disabled":!o,onClick:o?void 0:y,children:[v.jsx(_P,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate",children:"新建"})]}),b=o?v.jsxs(R1,{children:[v.jsx(A1,{asChild:!0,children:g}),v.jsxs(N1,{align:e?"end":"start",className:"w-52","data-slot":"create-session-type-menu",onCloseAutoFocus:w=>{s.current&&(s.current=!1,w.preventDefault())},children:[v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:h,children:[v.jsx(yP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.jsxs(bo,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:l,onSelect:p,children:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),l?"正在创建终端会话...":"终端会话"]})]})]}):g;return v.jsxs(v.Fragment,{children:[o?b:v.jsxs(Hf,{open:o?void 0:r,onOpenChange:o?void 0:i,children:[v.jsx(Uf,{asChild:!0,children:b}),v.jsx(Wf,{side:"top",children:o?"新建会话":"请先连接开发机"})]}),v.jsx(Ih,{open:t,onOpenChange:n})]})}function xie({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i}){const s=_.useRef(!1);function o(l){s.current=!0,l()}return v.jsx(Vv,{open:e,onOpenChange:n,children:v.jsxs(Yv,{side:"bottom",overlayClassName:"bg-black/10 dark:bg-black/30",className:"inset-x-2 w-auto rounded-t-xl border border-border/80 bg-background px-3 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3 shadow-2xl","data-slot":"create-session-type-sheet",focusSurfaceOnOpen:!0,onCloseAutoFocus:l=>{s.current&&(s.current=!1,l.preventDefault())},children:[v.jsx(T1,{className:"px-1 pb-1 pt-0 text-left",children:v.jsx(Kv,{children:"新建"})}),v.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[v.jsxs(St,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-agent-session-sheet-item",onClick:()=>o(r),children:[v.jsx(yP,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),v.jsxs(St,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-terminal-session-sheet-item",disabled:t,onClick:()=>o(i),children:[v.jsx(of,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建终端会话...":"终端会话"]})]})]})})}const Eie="0.5.1",Cie={version:Eie},kie={playback:"playback",capture:"play-and-record"};function Tie(){return typeof navigator>"u"?null:navigator.audioSession??null}function Rie(){return{setMode:()=>{},release:()=>{}}}class Aie{constructor(t=Tie){vt(this,"leases",new Map);vt(this,"session",null);vt(this,"baselineType",null);vt(this,"nextLeaseId",1);vt(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Rie();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(kie[t.mode])}applyActiveModeBestEffort(){try{this.applyActiveMode()}catch{}}restoreWhenUnused(){const t=this.session,n=this.baselineType;if(this.session=null,this.baselineType=null,!(!t||n===null))try{t.type=n}catch{}}setNativeType(t){if(!(!this.session||this.session.type===t)){try{this.session.type=t}catch{throw new Error("浏览器无法切换语音音频模式")}if(this.session.type!==t)throw new Error("浏览器无法切换语音音频模式")}}}const O1=new Aie,$0=64,FN=-60,DB=32;function $N(e){if(!Number.isFinite(e)||e===0)return 0;const t=Math.min(1,Math.abs(e)),n=20*Math.log10(t),r=Math.max(0,Math.min(1,(n-FN)/-FN));return e<0?-r:r}function HN(e,t=8){const n=Math.floor(e.byteLength/2);if(n===0||!Number.isFinite(t)||t<=0)return[];const r=Math.min(n,Math.max(1,Math.floor(t))),i=new DataView(e.buffer,e.byteOffset,e.byteLength),s=[];for(let o=0;o<r;o+=1){const l=Math.floor(o*n/r),u=Math.max(l+1,Math.floor((o+1)*n/r));let d=1,h=-1;for(let p=l;p<u;p+=1){const y=i.getInt16(p*2,!0)/32768;d=Math.min(d,y),h=Math.max(h,y)}s.push({min:d,max:h})}return s}function Nie(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 Mie(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 PB{constructor(t,n=24e3,r={}){vt(this,"nextStartTime",0);vt(this,"activityEndToken",0);vt(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=Nie(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*DB/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=Mie(n.subarray(l,u));this.scheduleTimer(()=>{var g,b,w,x;(b=(g=this.options).onActivityLevel)==null||b.call(g,y),(x=(w=this.options).onPlaybackChunk)==null||x.call(w,p)},h)}if(this.options.onActivityLevel){const l=Math.max(0,(i-this.context.currentTime)*1e3);this.scheduleTimer(()=>{var u,d;o===this.activityEndToken&&((d=(u=this.options).onActivityLevel)==null||d.call(u,0))},l)}}scheduleTimer(t,n){const r=setTimeout(()=>{this.timelineTimers.delete(r),t()},n);this.timelineTimers.add(r)}emitPlaybackEvent(t,n={}){var r,i;(i=(r=this.options).onPlaybackEvent)==null||i.call(r,{event:t,...this.snapshot(),...n})}}const Zb={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},UN="min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none transition-colors placeholder:text-muted-foreground/65 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",Oie=800,WN=300,Die=1600;function H0(e,t){return e.filter(n=>!n.model||n.model===t)}function qN({label:e,children:t,help:n}){return v.jsxs("div",{className:"block min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 transition-colors focus-within:border-ring/55 focus-within:bg-card/75 sm:p-3",children:[v.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.jsx("div",{className:"mt-2 min-w-0",children:t}),n?v.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function Bm({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=_.useState(!1),u=_.useId(),d=n.find(g=>g.value===t),h=(d==null?void 0:d.label)??(t||i),p=n.filter(g=>!g.disabled),y=!!LB(h).detail;return v.jsxs("div",{className:"min-w-0 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",onBlur:g=>{g.currentTarget.contains(g.relatedTarget)||l(!1)},children:[v.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),v.jsxs("button",{type:"button","aria-labelledby":u,"aria-haspopup":"listbox","aria-expanded":o,disabled:p.length===0,className:`mt-2 flex w-full min-w-0 items-center justify-between gap-3 rounded-md border border-border bg-input px-3 text-left outline-none transition-colors hover:border-primary/40 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[v.jsx(VN,{label:h,muted:!d&&!t}),v.jsx(gl,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?v.jsx("div",{role:"listbox","aria-labelledby":u,className:"mt-2 max-h-64 overflow-y-auto rounded-md border border-border/80 bg-popover p-1 shadow-sm",children:n.map(g=>{const b=g.value===t;return v.jsxs("button",{type:"button",role:"option","aria-label":g.label,"aria-selected":b,disabled:g.disabled,className:"flex w-full min-w-0 items-center gap-2 rounded-sm px-2.5 py-2.5 text-left text-sm outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-45",onClick:()=>{g.disabled||(r(g.value),l(!1))},children:[v.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:b?v.jsx(ra,{className:"size-4","aria-hidden":"true"}):null}),v.jsx(VN,{label:g.label})]},g.value)})}):null,s?v.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function VN({label:e,muted:t=!1}){const n=LB(e);return v.jsxs("span",{className:"min-w-0 flex-1",children:[v.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?v.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Pie({scrollRef:e}={}){const[t,n]=_.useState(Zb),[r,i]=_.useState(String(Zb.turnIdleSeconds)),[s,o]=_.useState(()=>Cm()),[l,u]=_.useState(""),[d,h]=_.useState(!1),[p,y]=_.useState(!1),[g,b]=_.useState({kind:"idle"}),w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(null);_.useEffect(()=>{const se=Mt;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te=!1;return b({kind:"loading"}),se.requestVoiceConfig().then(he=>{if(!te){if(he.error||!he.config){b({kind:"error",message:he.error??"读取语音设置失败"});return}n(he.config),i(String(he.config.turnIdleSeconds)),u(""),h(!1),y(!0),b({kind:"idle"})}}).catch(he=>{te||b({kind:"error",message:he instanceof Error?he.message:"读取语音设置失败"})}),()=>{te=!0}},[]),_.useEffect(()=>{const se=Mt;if(!se||!p)return;let te=!1;return se.requestVoiceCapabilities({region:t.region}).then(he=>{if(!te){if(he.error||!he.capabilities){o(Cm());return}o(he.capabilities)}}).catch(()=>{te||o(Cm())}),()=>{te=!0}},[t.region,p]),_.useEffect(()=>()=>{G(),B()},[]);const R=_.useMemo(()=>g.kind==="loading"?"读取中...":g.kind==="saving"?"保存中...":g.kind==="testing"?"正在测试语音合成":g.kind==="playingTest"?"正在播放测试音频":g.kind==="testPassed"?"测试通过":g.kind==="saved"?"已保存":g.kind==="error"?g.message:null,[g]),z=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",N=_.useMemo(()=>H0(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),P=N.some(se=>se.value===t.ttsVoice)?t.ttsVoice:"",q=N.length===0?"当前模型暂无可用音色":P?null:"请选择可用音色",H=_.useMemo(()=>Bie(r),[r]),U=H?null:"请输入正整数秒数",O=q??U,M=z||!!O,I=_.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),L=_.useMemo(()=>GN(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),D=_.useMemo(()=>jie(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),Y=_.useMemo(()=>GN(N,P),[N,P]);function K(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:H??Zb.turnIdleSeconds}}async function F(){if(z)return;if(O){b({kind:"error",message:O});return}const se=Mt;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}const te=K();B(),b({kind:"saving"});const he=performance.now();try{const ge=await se.updateVoiceConfig(te),Ee=performance.now()-he;if(Ee<WN&&await zie(WN-Ee),!ge.success||ge.error||!ge.config){b({kind:"error",message:ge.error??"保存语音设置失败"});return}n(ge.config),i(String(ge.config.turnIdleSeconds)),u(""),h(!1),b({kind:"saved"}),T.current=setTimeout(()=>{T.current=null,b(Re=>Re.kind==="saved"?{kind:"idle"}:Re)},Die),se.requestVoiceCapabilities({region:ge.config.region}).then(Re=>{Re.capabilities&&o(Re.capabilities)}).catch(()=>{o(Cm())})}catch(ge){b({kind:"error",message:ge instanceof Error?ge.message:"保存语音设置失败"})}}async function A(){if(z)return;if(O){b({kind:"error",message:O});return}const se=Mt;if(!se){b({kind:"error",message:"请先连接 Relay 服务器"});return}let te;try{te=W()}catch(he){b({kind:"error",message:KN(he)});return}b({kind:"testing"});try{const[he]=await Promise.all([se.testVoiceConfig(K()),te.ready]);if(!he.success||he.error){G(),b({kind:"error",message:he.error??"语音配置测试失败"});return}const ge=await ne(he,te.context);b({kind:"playingTest",transcript:he.transcript}),k.current=setTimeout(()=>{k.current=null,G(),b({kind:"testPassed",transcript:he.transcript})},ge)}catch(he){G(),b({kind:"error",message:KN(he)})}}function W(){G();const se=O1.acquire("playback");x.current=se;try{const te=Iie();return w.current=te,{context:te,ready:YN(te)}}catch(te){throw se.release(),x.current=null,te}}function G(){var se,te,he;k.current&&(clearTimeout(k.current),k.current=null),(se=E.current)==null||se.stop(),E.current=null,(te=w.current)==null||te.close(),w.current=null,(he=x.current)==null||he.release(),x.current=null}function B(){T.current&&(clearTimeout(T.current),T.current=null)}async function ne(se,te){if(!se.audioBase64)throw new Error("语音测试未返回可播放音频");if(se.audioEncoding&&se.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const he=se.audioSampleRate??24e3,ge=Lie(se.audioBase64);if(ge.byteLength===0||ge.byteLength%2!==0)throw new Error("测试音频数据无效");await YN(te);const Ee=new PB(te,he);E.current=Ee,Ee.enqueue(ge);const Re=Math.ceil(ge.byteLength/2/he*1e3);return Math.max(Oie,Re)}function ie(se){var te;return((te=H0(s.ttsVoices,se)[0])==null?void 0:te.value)??""}return v.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:se=>{se.preventDefault(),F()},children:[v.jsx("div",{className:"flex min-h-0 flex-1 flex-col px-4 py-3 sm:px-5 sm:py-3.5","data-slot":"voice-settings-body-frame",children:v.jsx("div",{className:"dev-render-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"voice-settings-scroll",ref:e,children:v.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[v.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsxs("div",{className:"min-w-0",children:[v.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),v.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),v.jsx("span",{className:"shrink-0 rounded-full border border-primary/35 bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:"Bailian"})]})}),v.jsx(qN,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:v.jsxs("div",{className:"flex min-w-0 gap-2",children:[v.jsxs("div",{className:"relative min-w-0 flex-1",children:[v.jsx(SP,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),v.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:se=>{u(se.target.value),h(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${UN} w-full pl-9`})]}),t.configured&&v.jsxs(St,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),h(!0)},children:[v.jsx(V8,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),v.jsx(Bm,{label:"地域",value:t.region,options:I,onChange:se=>n(te=>({...te,region:se==="intl"?"intl":"cn"}))}),v.jsx(Bm,{label:"语音识别模型",value:t.asrModel,options:L,onChange:se=>n(te=>({...te,asrModel:se}))}),v.jsx(Bm,{label:"语音合成模型",value:t.ttsModel,options:D,onChange:se=>n(te=>({...te,ttsModel:se,ttsVoice:ie(se)}))}),v.jsx(Bm,{label:"语音音色",value:P,options:Y,placeholder:N.length===0?"暂无可用音色":"请选择音色",onChange:se=>n(te=>({...te,ttsVoice:se})),help:q}),v.jsx(qN,{label:"结束停顿时间(秒)",help:U,children:v.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:se=>i(se.target.value),className:`${UN} w-full`})})]})})}),v.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[v.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),v.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[R?v.jsx("div",{role:g.kind==="error"?"alert":"status","aria-live":"polite",className:g.kind==="error"?"min-w-0 flex-1 text-sm text-destructive":"min-w-0 flex-1 text-sm text-muted-foreground",children:R}):null,v.jsxs(St,{type:"button",variant:"outline",disabled:M,onClick:()=>void A(),children:[v.jsx(CP,{className:"size-4","aria-hidden":"true"}),"测试"]}),v.jsxs(St,{type:"submit",disabled:M,children:[v.jsx(D8,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Lie(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 Iie(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function YN(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function KN(e){return e instanceof Error?e.message:"语音配置测试失败"}function zie(e){return new Promise(t=>setTimeout(t,e))}function Bie(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function GN(e,t){const n=e.map(r=>({value:r.value,label:IB(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function jie(e,t,n){const r=e.map(i=>{const s=H0(t,i.value).length===0;return{value:i.value,label:`${IB(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function LB(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 IB(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 Fie=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],$ie=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],D1="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function zB(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 Hie(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Uie(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Wie(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function U0({open:e,onOpenChange:t}){const n=ze(q=>q.relayUrl),r=ze(q=>q.latencyMonitorEnabled),i=ze(q=>q.setLatencyMonitorEnabled),s=ze(q=>q.sessionIdleNotificationsEnabled),o=ze(q=>q.setSessionIdleNotificationsEnabled),l=ze(q=>q.inputModePreference),u=ze(q=>q.setInputModePreference),d=ze(q=>q.themePreference),h=ze(q=>q.setThemePreference),p=ze(q=>q.ptyScrollTraceEnabled),y=ze(q=>q.setPtyScrollTraceEnabled),[g,b]=_.useState("menu"),[w,x]=_.useState({kind:"idle"}),E=_.useRef(null),k=_.useRef(null),T=jZ(),R=_.useMemo(()=>Wx().osName==="iPad",[]),z=_.useCallback(async q=>{if(!q){o(!1);return}const H=await pZ();if(H==="granted"){o(!0);return}if(H==="denied"){nt.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(H==="default"){nt.info("未授予通知权限,会话通知保持关闭");return}nt.error("当前浏览器不支持系统通知")},[o]),N=_.useCallback(async q=>{x({kind:"loading"});try{const H=await fetch(Hie(n),{cache:"no-store",signal:q});if(!H.ok)throw new Error(`HTTP ${H.status}`);const U=await H.json();if(U.status!=="ok")throw new Error("状态异常");x({kind:"ready",version:U.version??"未知",uptime:U.uptime??0})}catch(H){if(H instanceof DOMException&&H.name==="AbortError")return;x({kind:"error",message:H instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);_.useEffect(()=>{if(!e){b("menu");return}},[e]),_.useEffect(()=>{if(!e||g!=="version")return;const q=new AbortController;return N(q.signal),()=>q.abort()},[N,e,g]),_.useEffect(()=>{if(!e||g!=="voice")return;const q=window.requestAnimationFrame(()=>{var H;(H=E.current)==null||H.focus({preventScroll:!0}),k.current&&(k.current.scrollTop=0)});return()=>window.cancelAnimationFrame(q)},[e,g]);const $=w.kind==="ready"?w.version:w.kind==="loading"?"读取中...":w.kind==="error"?"读取失败":"未读取",P=w.kind==="ready"?`运行 ${zB(w.uptime)}`:w.kind==="error"?w.message:"从当前 Relay 服务器 /health 读取";return v.jsx(Sc,{open:e,onOpenChange:t,children:v.jsxs(xc,{className:We("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":g,focusSurfaceOnOpen:!0,ref:E,showCloseButton:g==="menu",children:[v.jsx(Ec,{className:We(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"flex items-start gap-2",children:[v.jsx(St,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>b("menu"),children:v.jsx(vv,{className:"size-4","aria-hidden":"true"})}),v.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[v.jsx(dl,{children:Uie(g)}),v.jsx(dc,{className:"max-w-[28rem] leading-5",children:Wie(g)})]})]}),g==="voice"?v.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):v.jsxs(v.Fragment,{children:[v.jsx(dl,{children:"设置"}),v.jsx(dc,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?v.jsx(qie,{relayVersion:$,relayDetail:P,relayMuted:w.kind==="error"}):g==="relay-token"?v.jsx(Yie,{saved:T}):g==="clients"?v.jsx(Qie,{}):g==="voice"?v.jsx(Pie,{scrollRef:k}):v.jsx(Vie,{relayTokenSaved:T,themePreference:d,onThemePreferenceChange:h,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:R,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:z,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>b("voice"),onOpenRelayToken:()=>b("relay-token"),onOpenClients:()=>b("clients"),onOpenVersion:()=>b("version")})]})})}function qie({relayVersion:e,relayDetail:t,relayMuted:n}){return v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsx(ZN,{icon:v.jsx(EP,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Cie.version,detail:"当前浏览器加载的版本"}),v.jsx(ZN,{icon:v.jsx(kP,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Vie({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:h,onLatencyMonitorEnabledChange:p,onOpenVoice:y,onOpenRelayToken:g,onOpenClients:b,onOpenVersion:w}){return v.jsxs("div",{className:"dev-render-scroll min-h-0 space-y-4 overflow-y-auto overscroll-contain pr-4 sm:pr-1","data-slot":"settings-dialog-body",children:[v.jsxs(cu,{title:"服务",children:[v.jsx(jm,{icon:v.jsx(k9,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),v.jsx(jm,{icon:v.jsx(SP,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),v.jsx(jm,{icon:v.jsx(J8,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:b})]}),v.jsx(cu,{title:"外观",children:v.jsx(XN,{icon:v.jsx(U8,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Fie,onValueChange:n})}),v.jsx(cu,{title:"通知",children:v.jsx(Jb,{icon:v.jsx(R9,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?v.jsx(cu,{title:"交互",children:v.jsx(XN,{icon:v.jsx(xP,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:$ie,onValueChange:i})}):null,v.jsxs(cu,{title:"高级诊断",children:[v.jsx(Jb,{icon:v.jsx(of,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),v.jsx(Jb,{icon:v.jsx(gP,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:h,onCheckedChange:p})]}),v.jsx(cu,{title:"关于",children:v.jsx(jm,{icon:v.jsx(kP,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function cu({title:e,children:t}){return v.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[v.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),v.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function XN({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=_.useId(),l=_.useId();return v.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[v.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,v.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return v.jsx("button",{type:"button",role:"radio","aria-checked":d,className:We("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Yie({saved:e}){const t=_.useId(),n=_.useId(),[r,i]=_.useState(""),[s,o]=_.useState(null),l=()=>{HL().catch(h=>{o(h instanceof Error?h.message:"Relay 重连失败。")})},u=()=>{const h=r.trim();if(!h){o("请输入 token。");return}FL(h),l()},d=()=>{$L(),l()};return v.jsxs("form",{className:D1,"data-slot":"settings-dialog-body",onSubmit:h=>{h.preventDefault(),u()},children:[v.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[v.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),v.jsx("input",{id:t,type:"password",value:r,onChange:h=>{i(h.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?v.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),v.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?v.jsx(St,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,v.jsx(St,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Kie(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Gie(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Kie(e)}function Xie(e){return iX(e)}function Zie(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return zB(t)}function Qb({label:e,value:t,title:n}){return v.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[v.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),v.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function Qie(){const e=ze(y=>y.proxies),[t,n]=_.useState([]),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,u]=_.useState(null),d=_.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),h=_.useCallback(async()=>{const y=Mt;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);_.useEffect(()=>{h()},[h]);const p=_.useCallback(async y=>{const g=Mt;if(!g){o("Relay 未连接。");return}u(y),o(null);try{const b=await g.kickRelayClient(y);if(!b.success){o(b.error??"断开客户端失败。");return}n(w=>w.filter(x=>x.clientId!==y))}catch(b){o(b instanceof Error?b.message:"断开客户端失败。")}finally{u(null)}},[]);return v.jsxs("div",{className:D1,"data-slot":"settings-dialog-body",children:[v.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void h(),disabled:r,"data-slot":"relay-clients-refresh",children:v.jsx(Tx,{className:We("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?v.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?v.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const g=y.current===!0,b=l===y.clientId;return v.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children:v.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[v.jsxs("div",{className:"min-w-0 space-y-1.5",children:[v.jsx("div",{className:"min-w-0",children:v.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:Xie(y)})}),v.jsxs("div",{className:"space-y-1",children:[v.jsx(Qb,{label:"已连接",value:Zie(y.connectedAt)}),y.proxyId?v.jsx(Qb,{label:"连接到",value:Gie(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?v.jsx(Qb,{label:"来源 IP",value:y.remoteAddress}):null]})]}),g?v.jsx("div",{className:"inline-flex h-9 w-full items-center justify-center rounded-md border border-primary/30 bg-primary/10 px-3 text-sm font-normal text-primary","aria-label":"当前设备","data-slot":"relay-client-current-indicator",children:"当前设备"}):v.jsxs(St,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:b,onClick:()=>void p(y.clientId),"data-slot":"relay-client-action",children:[v.jsx(c8,{className:"size-3.5","aria-hidden":"true"}),b?"断开中...":"断开"]})]})},y.clientId)})]})}function Jb({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=_.useId(),o=_.useId();return v.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[v.jsx("div",{className:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),v.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),v.jsx("span",{className:We("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:v.jsx("span",{className:We("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function jm({icon:e,label:t,detail:n,onClick:r}){const i=_.useId(),s=_.useId();return v.jsxs("button",{type:"button",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:r,"aria-labelledby":i,"aria-describedby":n?s:void 0,"data-slot":"settings-menu-item",children:[v.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground transition-colors group-hover:text-foreground",children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?v.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),v.jsx(Kh,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function ZN({icon:e,label:t,value:n,detail:r,muted:i=!1}){return v.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[v.jsx("div",{className:We("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),v.jsxs("div",{className:"min-w-0 flex-1",children:[v.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[v.jsx("div",{className:"text-sm text-muted-foreground",children:t}),v.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const Jie="xterm-helper-textarea";function ese(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Jie)?!1:(e.blur(),!0)}function QN(e,t,n){if(!e||Math.abs(n)<1)return!1;let r=e instanceof Element?e:null;for(;r&&t.contains(r);){if(r instanceof HTMLElement&&tse(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function tse(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 nse({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=_.useRef(null),r=_.useCallback(()=>{e&&ese()},[e]),i=_.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=_.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const h=(n.current??u.clientY)-u.clientY;n.current=u.clientY,QN(l.target,l.currentTarget,h)||l.preventDefault()},[t]),o=_.useCallback(l=>{r(),t&&(QN(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function rse({className:e}){const t=ze(o=>o.sidebarCollapsed),n=ze(o=>o.toggleSidebarCollapsed),[r,i]=_.useState(!1),s=nse();return t?v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:We("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[v.jsx(eM,{collapsed:!0,onClick:n}),v.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),v.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[v.jsx(JN,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),v.jsx(jN,{compact:!0})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]}):v.jsxs(v.Fragment,{children:[v.jsxs("nav",{className:We("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[v.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:v.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx(qP,{className:"text-[13px]",slot:"sidebar-brand"}),v.jsx(eM,{collapsed:!1,onClick:n})]}),v.jsx("div",{className:"mt-2.5",children:v.jsx(SB,{layout:"dropdown",variant:"sidebarChrome"})})]})}),v.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:v.jsx("div",{className:"flex-1 min-h-0",children:v.jsx(MB,{layout:"sidebar"})})}),v.jsxs("div",{className:"dev-sidebar-fade flex shrink-0 gap-2 px-2 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-2","data-slot":"sidebar-new-session",children:[v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(jN,{})}),v.jsx("div",{className:"min-w-0 flex-1",children:v.jsx(JN,{onClick:()=>i(!0)})})]})]}),v.jsx(U0,{open:r,onOpenChange:i})]})}function JN({compact:e=!1,tooltipSide:t="top",onClick:n}){return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[v.jsx(TP,{className:"size-4","aria-hidden":"true"}),!e&&v.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),v.jsx(Wf,{side:t,sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:"设置"})]})}function eM({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?_8:v8;return v.jsxs(Hf,{delayDuration:500,children:[v.jsx(Uf,{asChild:!0,children:v.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:v.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),v.jsx(Wf,{side:e?"right":"top",sideOffset:10,hideArrow:!0,className:"border border-border/80 bg-card/95 px-2.5 py-1 text-muted-foreground shadow-sm backdrop-blur",children:n})]})}const ise=1500,sse=300,tM=70,nM=35;function BB({texts:e,className:t}){const[n,r]=_.useState(""),[i,s]=_.useState(!0),o=_.useRef("typing"),l=_.useRef(0),u=_.useRef(0);return _.useEffect(()=>{const d=setInterval(()=>s(h=>!h),530);return()=>clearInterval(d)},[]),_.useEffect(()=>{let d;const h=()=>e[u.current%e.length],p=()=>{const y=o.current;if(y==="typing"){const g=h();l.current<g.length?(l.current+=1,r(g.slice(0,l.current)),d=setTimeout(p,tM)):(o.current="paused",d=setTimeout(p,ise))}else y==="paused"?(o.current="deleting",d=setTimeout(p,nM)):y==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),d=setTimeout(p,nM)):(u.current+=1,o.current="waiting",d=setTimeout(p,sse)):(o.current="typing",d=setTimeout(p,tM))};return d=setTimeout(p,500),()=>clearTimeout(d)},[e]),v.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[v.jsx("span",{className:"text-green-500",children:"> "}),v.jsx("span",{className:"text-foreground/90",children:n}),v.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const jB=["DEV Anywhere","/unlimited @anytime"];function ose({subtitle:e,action:t}){return v.jsx("section",{className:"dev-mobile-brand-hero border-b border-border/80 px-4 pb-5 pt-[calc(env(safe-area-inset-top)+1.25rem)] md:hidden","data-slot":"mobile-brand-hero","aria-label":"DEV Anywhere",children:v.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[v.jsx(BB,{texts:jB,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),v.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}),t?v.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const ase=3e3,lse=1e4,Fm=12,cse=4,rM={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},use={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function ew(e){if(!e.success||e.rttMs===void 0)return{state:"unavailable",error:e.error??"不可用",updatedAt:Date.now()};const t=e.rttMs;return{state:t<=120?"ok":t<=300?"warn":"bad",rttMs:t,updatedAt:Date.now()}}function uu(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function Bh(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function iM(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function FB(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function dse(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 hse(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?Bh(e.rttMs):"等待检测"}function fse(){const e=ki("local",ln.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function sM(e){dr("local",ln.latencyMonitorPosition,JSON.stringify(e))}function pse(){var e,t;return{width:((e=window.visualViewport)==null?void 0:e.width)??window.innerWidth??document.documentElement.clientWidth??0,height:((t=window.visualViewport)==null?void 0:t.height)??window.innerHeight??document.documentElement.clientHeight??0}}function tw(e,t){const n=pse(),r=Fm,i=Fm,s=Math.max(r,n.width-t.width-Fm),o=Math.max(i,n.height-t.height-Fm);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function mse(){const e=ze(N=>N.latencyMonitorEnabled),t=ze(N=>N.connected),n=ze(N=>N.proxyOnline),r=ze(N=>N.selectedProxyId),[i,s]=_.useState(use),[o,l]=_.useState(()=>fse()),u=_.useRef(!1),d=_.useRef(null),h=_.useRef(null),p=_.useRef(!1),y=_.useMemo(()=>(Object.values(i).sort((N,$)=>iM($.state)-iM(N.state))[0]??{state:"idle"}).state,[i]),g=FB(y);async function b(){if(u.current)return;const N=Mt;if(!N||!t){const H=uu("Relay 服务器未连接");s({webRelay:H,relayProxy:H,webProxy:H});return}u.current=!0,s(H=>({webRelay:{...H.webRelay,state:"measuring"},relayProxy:n?{...H.relayProxy,state:"measuring"}:uu("未连接开发机"),webProxy:n?{...H.webProxy,state:"measuring"}:uu("未连接开发机")}));const[$,P,q]=await Promise.allSettled([N.measureWebRelayLatency(),n?N.measureRelayProxyLatency():Promise.resolve({success:!1}),n?N.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:$.status==="fulfilled"?ew($.value):uu($.reason instanceof Error?$.reason.message:"测速失败"),relayProxy:P.status==="fulfilled"?ew(P.value):uu(P.reason instanceof Error?P.reason.message:"测速失败"),webProxy:q.status==="fulfilled"?ew(q.value):uu(q.reason instanceof Error?q.reason.message:"测速失败")}),u.current=!1}if(_.useEffect(()=>{if(!e)return;let N=!1,$=null;const P=async()=>{await b(),!N&&($=setTimeout(P,document.hidden?lse:ase))};return P(),()=>{N=!0,u.current=!1,$&&clearTimeout($)}},[e,t,n,r]),_.useEffect(()=>{if(!e||!o)return;const N=d.current;if(!N)return;const $=N.getBoundingClientRect(),P=tw(o,{width:$.width,height:$.height});P.x===o.x&&P.y===o.y||(l(P),sM(P))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,x=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function E(N){var P,q;if(N.button!==0)return;const $=N.currentTarget.getBoundingClientRect();h.current={pointerId:N.pointerId,startX:N.clientX,startY:N.clientY,originX:$.left,originY:$.top,width:$.width,height:$.height,dragging:!1},(q=(P=N.currentTarget).setPointerCapture)==null||q.call(P,N.pointerId)}function k(N){const $=h.current;if(!$||$.pointerId!==N.pointerId)return;const P=N.clientX-$.startX,q=N.clientY-$.startY;if(!$.dragging&&Math.hypot(P,q)<cse)return;$.dragging=!0,N.preventDefault();const H=tw({x:$.originX+P,y:$.originY+q},{width:$.width,height:$.height});l(H)}function T(N){var U,O;const $=h.current;if(!$||$.pointerId!==N.pointerId||(h.current=null,(O=(U=N.currentTarget).releasePointerCapture)==null||O.call(U,N.pointerId),!$.dragging))return;N.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const P=N.clientX-$.startX,q=N.clientY-$.startY,H=tw({x:$.originX+P,y:$.originY+q},{width:$.width,height:$.height});l(H),sM(H)}function R(N){var P,q;const $=h.current;!$||$.pointerId!==N.pointerId||(h.current=null,(q=(P=N.currentTarget).releasePointerCapture)==null||q.call(P,N.pointerId))}function z(N){p.current&&(p.current=!1,N.preventDefault(),N.stopPropagation())}return v.jsxs(E1,{children:[v.jsx(C1,{asChild:!0,children:v.jsxs("button",{ref:d,type:"button",className:We("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",dse(g)),style:x,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${Bh(i.webRelay.rttMs)},开发机 ${Bh(w.rttMs)}`,onPointerDown:E,onPointerMove:k,onPointerUp:T,onPointerCancel:R,onClickCapture:z,children:[v.jsx(gP,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),v.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",Bh(i.webRelay.rttMs)]}),v.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",Bh(w.rttMs)]}),v.jsx(gl,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),v.jsxs(k1,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[v.jsxs("div",{className:"flex items-start justify-between gap-3",children:[v.jsxs("div",{children:[v.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),v.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),v.jsx(St,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void b(),children:v.jsx(Tx,{className:"size-3","aria-hidden":"true"})})]}),v.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(rM).map(N=>v.jsx(gse,{label:rM[N],measurement:i[N]},N))})]})]})}function gse({label:e,measurement:t}){const n=FB(t.state);return v.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[v.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsx("span",{className:We("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),v.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:hse(t)})]})]})}const $B="/__dev_anywhere_debug/browser-state-dumps",vse=1500,yse=10,nw=80,P1=500,_se=["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"],bse=["display","position","visibility","opacity","pointer-events","z-index","overflow","overflow-x","overflow-y","touch-action","transform","translate","color-scheme","background-color","color","font-size","line-height","padding-top","padding-right","padding-bottom","padding-left","margin-top","margin-right","margin-bottom","margin-left"];function oM(){if(typeof window>"u")return"off";const e=GB("debugDump");return e==="auto"?"auto":e!==null||Ase("debugInput")?"manual":"off"}function wse(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:Cse(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:aM(document.activeElement),selection:kse(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>aM(i)).filter(i=>!!i),root:HB(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:du(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:du(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:du(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:du(()=>lM(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:du(()=>lM(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:du(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function Sse(e="manual"){const t=wse(e);return xse(t)}async function xse(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Ese(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:$B}}catch(r){const i=XB(r),s=Tse(e.createdAt);return Rse(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Ese(e){const t=await fetch($B,{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 HB(e,t,n){if(n.count>=vse||t>yse)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=cM(e.textContent??"");return u?{kind:"text",text:Xv(u,P1)}:{kind:"text",text:""}}if(!(e instanceof HTMLElement))return{kind:"truncated"};const r=[];let i=0;const s=Array.from(e.childNodes);for(const u of s.slice(0,nw))u.nodeType===Node.TEXT_NODE&&!cM(u.textContent??"")||r.push(HB(u,t+1,n));s.length>nw&&(i=s.length-nw,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:KB(e),attrs:UB(e),rect:WB(e),scroll:qB(e),style:VB(e)},l=YB(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function aM(e){if(!(e instanceof HTMLElement))return null;const t=YB(e);return{path:KB(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:UB(e),rect:WB(e),scroll:qB(e),style:VB(e),...t?{value:t}:{}}}function Cse(){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 UB(e){const t={};for(const n of _se){const r=e.getAttribute(n);r!==null&&(t[n]=Xv(r,500))}return t}function WB(e){const t=e.getBoundingClientRect();return{x:Zi(t.x),y:Zi(t.y),width:Zi(t.width),height:Zi(t.height),top:Zi(t.top),right:Zi(t.right),bottom:Zi(t.bottom),left:Zi(t.left)}}function qB(e){return{top:Zi(e.scrollTop),left:Zi(e.scrollLeft),height:Zi(e.scrollHeight),width:Zi(e.scrollWidth),clientHeight:Zi(e.clientHeight),clientWidth:Zi(e.clientWidth)}}function VB(e){const t=window.getComputedStyle(e),n={};for(const r of bse)n[r]=t.getPropertyValue(r);return n}function YB(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Xv(e.value,P1),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function kse(){var e;try{return Xv(((e=window.getSelection())==null?void 0:e.toString())??"",P1)}catch{return null}}function KB(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 Tse(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Rse(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 Ase(e){return GB(e)!==null}function GB(e){const t=new URLSearchParams(window.location.search);if(t.has(e))return t.get(e)??"";const[,n=""]=window.location.hash.split("?"),r=new URLSearchParams(n);return r.has(e)?r.get(e)??"":null}function lM(e){return e?Gg(e.slice(-200)):null}function du(e){try{return Gg(e())}catch(t){return{error:XB(t)}}}function Gg(e){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(Array.isArray(e))return e.map(Gg);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Gg(r);return t}return String(e)}function cM(e){return e.replace(/\s+/g," ").trim()}function Xv(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Zi(e){return Math.round(e*100)/100}function XB(e){return e instanceof Error?e.message:String(e)}const Nse=500,Mse=1e3,Ose=60;function Dse(){const[e,t]=_.useState(()=>oM()),[n,r]=_.useState(!1),[i,s]=_.useState(null),o=_.useRef(null),l=_.useRef(!1),u=_.useRef(0),d=_.useRef(0),h=_.useRef(null);_.useEffect(()=>{const b=()=>t(oM());return window.addEventListener("hashchange",b),window.addEventListener("popstate",b),()=>{window.removeEventListener("hashchange",b),window.removeEventListener("popstate",b)}},[]);const p=_.useCallback(async(b="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await Sse(b);return o.current=w,s(w),(b==="manual"||w.status==="failed")&&Pse(w),w}finally{l.current=!1,r(!1)}},[]);if(_.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),_.useEffect(()=>{var k,T;if(e!=="auto")return;const b=()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},w=R=>{d.current>=Ose||(b(),h.current=window.setTimeout(()=>{h.current=null;const z=Date.now(),N=Mse-(z-u.current);if(N>0){h.current=window.setTimeout(()=>w(R),N);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${R}`)},Nse))};w("initial");const x=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],E=R=>w(R.type);return x.forEach(R=>window.addEventListener(R,E,!0)),(k=window.visualViewport)==null||k.addEventListener("resize",E),(T=window.visualViewport)==null||T.addEventListener("scroll",E),()=>{var R,z;b(),x.forEach(N=>window.removeEventListener(N,E,!0)),(R=window.visualViewport)==null||R.removeEventListener("resize",E),(z=window.visualViewport)==null||z.removeEventListener("scroll",E)}},[p,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",g=Lse(i);return v.jsxs("div",{className:"fixed bottom-3 right-3 z-[90] flex max-w-[min(360px,calc(100vw-24px))] flex-col items-end gap-1",children:[g?v.jsx("div",{className:"max-w-full truncate rounded-md border border-border/70 bg-popover/95 px-2 py-1 text-[10px] text-muted-foreground shadow",children:g}):null,v.jsxs(St,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void p("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?v.jsx(Lu,{className:"size-3.5 animate-spin","aria-hidden":"true"}):v.jsx(J9,{className:"size-3.5","aria-hidden":"true"}),v.jsx("span",{children:y})]})]})}function Pse(e){if(e.status==="saved"){nt.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){nt.info(`诊断已下载: ${e.filename}`);return}nt.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Lse(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Ise(e){if(typeof window>"u")return null;try{const t=window.localStorage;return!t||typeof t.getItem!="function"?null:t.getItem(e)}catch{return null}}function L1(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:Ise(n)==="1",l=()=>typeof window>"u"?[]:window[t]??[],u=d=>{typeof window>"u"||(window[t]=d)};return{isEnabled:o,append(d){if(typeof window>"u")return;const h=l();if(i){const p=i(d);if(p!==null){const y=s.get(d.event);if(y&&i(y)===p&&h.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const g=h.indexOf(y);g>=0&&g!==h.length-1&&(h.splice(g,1),h.push(y)),u(h);return}}}if(h.push(d),i&&s.set(d.event,d),h.length>r){const p=h.splice(0,h.length-r);if(i)for(const y of p)s.get(y.event)===y&&s.delete(y.event)}u(h)},getAll:l}}function Cn(e){return Math.round(e*10)/10}function Ka(e){return e.length===0?"":`${Cn(Math.min(...e))}..${Cn(Math.max(...e))}`}function Au(e){return[...new Set(e.filter(t=>t!==void 0).map(Cn))]}function ZB(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 zse="dev_anywhere_pty_input_latency_trace",uM=80,Bse=1e4,jse=new TextDecoder;let Fse=0;const Ku=new Map,Cc=L1({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:zse,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function $se(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=qse)}function Hse(e,t){if(!Cc.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Fse}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Kse(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Ku.get(e)??[];return s.push(i),z1(s,r),Ku.set(e,s),qf({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function dM(e,t){if(!e||!Cc.isEnabled())return;const n=performance.now(),r=Vse(e.sessionId,e.inputId);r&&(r.sentAt=n),qf({t:n,event:"input:ws-send",sessionId:e.sessionId,inputId:e.inputId,inputKind:r==null?void 0:r.kind,dataLength:r==null?void 0:r.dataLength,sent:t.sent,queueWhenDisconnected:t.queueWhenDisconnected,deltaFromInputMs:r?n-r.startedAt:null,details:t.details})}function Use(e,t,n){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=Zse(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Xse(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));qf({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:Qse([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Wse(e,t,n=1){if(!Cc.isEnabled())return;const r=performance.now(),i=I1(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));qf({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:B1(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Yse(e,s))}function qse(){const e=Cc.getAll(),t=e.slice(-200),n=[...Ku.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Cn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Cn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Cn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Cn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Cn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Cn(s.t),s.repeat&&s.repeat>0?`${s.event} +${s.repeat}`:s.event,s.sessionId,s.inputId??"",s.inputKind??"",s.dataLength??"",s.sent===void 0?"":s.sent?"sent":"not-sent",s.queueWhenDisconnected?"queue-ok":"",s.outputSeq??"",s.bytes??"",s.chunkCount??"",s.pendingInputs??"",s.deltaFromInputMs===void 0||s.deltaFromInputMs===null?"":Cn(s.deltaFromInputMs),s.details??""].join(" "));return["DEV Anywhere PTY input latency trace",`events=${e.length}, included=${t.length}, pendingInputs=${n.length}`,"pending input summary:","inputId sessionId kind len wsSendMs firstOutputMs echoMatchMs xtermWriteMs paintMs",...r,"events:","t event sessionId inputId kind len sent queue outputSeq bytes chunks pending deltaMs details",...i].join(`
501
501
  `)}function qf(e){Cc.append(e)}function I1(e,t){const n=Ku.get(e)??[];return z1(n,t),Ku.set(e,n),n}function z1(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>Bse;(i||s)&&e.splice(n,1)}e.length>uM&&e.splice(0,e.length-uM)}function Vse(e,t){return(Ku.get(e)??[]).find(n=>n.inputId===t)??null}function Yse(e,t){if(!Cc.isEnabled())return;const n=performance.now(),r=I1(e,n);let i=0;for(const s of t){const o=r.find(l=>l.inputId===s);!o||o.paintAt!==null||(o.paintAt=n,i+=1)}qf({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:B1(r,n),details:i>0?`paint=${i}`:""}),z1(r,n)}function B1(e,t){const n=e[0];return n?t-n.startedAt:null}function Kse(e){return e==="\r"||e===`
502
502
  `?"enter":e.startsWith("\x1B")?"escape":Gse(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function Gse(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 Xse(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function Zse(e){try{return jse.decode(e)}catch{return""}}function Qse(e){return e.filter(Boolean).join(" ")}function Ks(e,t){if(!e||!t)return;const n=Hse(e,t),r=tc;if(!r){dM(n,{sent:!1,queueWhenDisconnected:!1,details:"no-ws-manager"});return}const i={type:"remote_input_raw",sessionId:e,data:t};n&&(i.traceId=n.inputId);const s=r.send(JSON.stringify(i),{queueWhenDisconnected:!0});dM(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}const hM=-1;function Jse({sessionId:e,enabled:t,waiting:n,approvalSeq:r,sendRawInput:i=Ks}){const s=_.useRef(void 0),o=_.useRef(e);_.useEffect(()=>{if(o.current!==e&&(o.current=e,s.current=void 0),!n){s.current=void 0;return}if(r===void 0){if(s.current!==void 0)return;s.current=hM,i(e,"\r");return}if(s.current===hM){s.current=r;return}s.current!==r&&(s.current=r,i(e,"\r"))},[r,t,i,e,n])}function eoe(e){var r,i,s;if(!e.connected||!e.proxyOnline||e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.state==="idle"||e.session.state==="error"||e.session.state==="terminated")return null;const t=Dx(e.proxyId,e.session.sessionId);return!t||!e.autoYesBySessionKey[t]||!(e.session.state==="waiting_approval"||((r=e.agentStatus)==null?void 0:r.phase)==="waiting_permission"||((i=e.ptyState)==null?void 0:i.state)==="approval_wait")?null:{key:t,sessionId:e.session.sessionId,waiting:!0,approvalSeq:((s=e.ptyState)==null?void 0:s.state)==="approval_wait"?e.ptyState.seq:void 0}}function toe({target:e,sendRawInput:t}){return Jse({sessionId:e.sessionId,enabled:!0,waiting:e.waiting,approvalSeq:e.approvalSeq,sendRawInput:t}),null}function noe({sendRawInput:e=Ks}){const t=ze(d=>d.connected),n=ze(d=>d.proxyOnline),r=ze(d=>d.selectedProxyId),i=Ut(d=>d.sessions),s=Ut(d=>d.ptyStateBySessionId),o=Ut(d=>d.agentStatusBySessionId),l=Ut(d=>d.ptyAutoYesBySessionKey),u=i.map(d=>eoe({proxyId:r,session:d,ptyState:s[d.sessionId],agentStatus:o[d.sessionId],autoYesBySessionKey:l,connected:t,proxyOnline:n})).filter(d=>d!==null);return v.jsx(v.Fragment,{children:u.map(d=>v.jsx(toe,{target:d,sendRawInput:e},d.key))})}function roe(e,t,n){const r=e.some(s=>s.sessionId===t)?e.map(s=>s.sessionId===t?{...s,touchedAt:n.now}:s):[...e,{sessionId:t,touchedAt:n.now}];if(r.length<=n.capacity)return r;const i=r.filter(s=>s.sessionId!==n.activeSessionId).sort((s,o)=>s.touchedAt-o.touchedAt)[0];return i?r.filter(s=>s.sessionId!==i.sessionId):r.slice(-3)}var Jl=function(e,t){return Number(e.toFixed(t))},ioe=function(e,t){return t},Ln=function(e,t,n){n&&typeof n=="function"&&n(e,t)},soe=function(e){return-Math.cos(e*Math.PI)/2+.5},ooe=function(e){return e},aoe=function(e){return e*e},loe=function(e){return e*(2-e)},coe=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},uoe=function(e){return e*e*e},doe=function(e){return--e*e*e+1},hoe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},foe=function(e){return e*e*e*e},poe=function(e){return 1- --e*e*e*e},moe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},goe=function(e){return e*e*e*e*e},voe=function(e){return 1+--e*e*e*e*e},yoe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},QB={easeOut:soe,linear:ooe,easeInQuad:aoe,easeOutQuad:loe,easeInOutQuad:coe,easeInCubic:uoe,easeOutCubic:doe,easeInOutCubic:hoe,easeInQuart:foe,easeOutQuart:poe,easeInOutQuart:moe,easeInQuint:goe,easeOutQuint:voe,easeInOutQuint:yoe},JB=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Ys=function(e){e.mounted&&(JB(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function e3(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Ys(e),e.animation=function(){if(!e.mounted)return JB(e.animation);var o=new Date().getTime()-i,l=o/n,u=QB[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function _oe(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function El(e,t,n,r){var i=_oe(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):e3(e,r,n,function(g){g!==1?e.isAnimating=!0:e.isAnimating=!1;var b=l+h*g,w=u+p*g,x=d+y*g;s(b,w,x)})}}function boe(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 woe=function(e,t,n,r,i,s,o){var l=e>t?n*(o?.5:1):0,u=r>i?s*(o?.5:1):0,d=e-t-l,h=l,p=r-i-u,y=u;return{minPositionX:d,maxPositionX:h,minPositionY:p,maxPositionY:y,scaleWidthFactor:l,scaleHeightFactor:u}},j1=function(e,t){var n=e.wrapperComponent,r=e.contentComponent,i=e.setup,s=i.centerZoomedOut,o=i.disablePadding;if(!n||!r)throw new Error("Components are not mounted");var l=boe(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,h=l.newContentWidth,p=l.newContentHeight,y=l.newDiffWidth,g=l.newDiffHeight,b=woe(u,h,y,d,p,g,!!s),w=u>=h&&d>=p;o&&w&&!s&&(b.minPositionX=0,b.maxPositionX=0,b.minPositionY=0,b.maxPositionY=0);var x=e.setup,E=x.minPositionX,k=x.maxPositionX,T=x.minPositionY,R=x.maxPositionY;return E!=null&&(b.minPositionX=u*(1-t)+E*t),k!=null&&(b.maxPositionX=k*t),T!=null&&(b.minPositionY=d*(1-t)+T*t),R!=null&&(b.maxPositionY=R*t),b},gf=function(e,t,n,r){return r?e<t?Jl(t,2):e>n?Jl(n,2):Jl(e,2):Jl(e,2)},Gu=function(e,t){var n=j1(e,t);return e.bounds=n,n};function Vf(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,h=n.maxPositionY,p=0,y=0;o&&(p=i,y=s);var g=gf(e,l-p,d+p,r),b=gf(t,u-y,h+y,r);return{x:g,y:b}}function Zv(e,t,n,r,i,s){var o=e.state,l=o.scale,u=o.positionX,d=o.positionY,h=r-l;if(typeof t!="number"||typeof n!="number")return console.error("Mouse X and Y position were not provided!"),{x:u,y:d};var p=u-t*h,y=d-n*h,g=Vf(p,y,i,s,0,0,null);return g}var fM=1e-7;function Yf(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,fM),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,fM)}var pM=function(e,t){var n=e.setup.panning.excluded,r=e.isInitialized,i=e.wrapperComponent,s=t.target,o="shadowRoot"in s&&"composedPath"in t,l=o?t.composedPath().some(function(h){return h instanceof Element?i==null?void 0:i.contains(h):!1}):i==null?void 0:i.contains(s),u=r&&s&&l;if(!u)return!1;var d=Kf(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},mM=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},Soe=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}},xoe=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 Eoe(e){var t=e.state,n=t.positionX,r=t.positionY,i=t.scale,s=e.setup,o=s.disabled,l=s.limitToBounds,u=s.centerZoomedOut,d=e.wrapperComponent;if(!(o||!d||!e.bounds)){var h=e.bounds,p=h.maxPositionX,y=h.minPositionX,g=h.maxPositionY,b=h.minPositionY,w=n>p||n<y,x=r>g||r<b,E=n>p?d.offsetWidth:e.setup.minPositionX||0,k=r>g?d.offsetHeight:e.setup.minPositionY||0,T=Zv(e,E,k,i,e.bounds,l||u),R=T.x,z=T.y;return{scale:i,positionX:w?R:n,positionY:x?z:r}}}function t3(e,t,n,r,i){var s=e.setup.limitToBounds,o=e.wrapperComponent,l=e.bounds,u=e.state,d=u.scale,h=u.positionX,p=u.positionY;if(!(o===null||l===null||t===h&&n===p)){var y=Vf(t,n,l,s,r,i,o),g=y.x,b=y.y;e.setState(d,g,b)}}var Coe=function(e,t,n){var r=e.startCoords,i=e.state,s=e.setup.panning,o=s.lockAxisX,l=s.lockAxisY,u=i.positionX,d=i.positionY;if(!r)return{x:u,y:d};var h=t-r.x,p=n-r.y,y=o?u:h,g=l?d:p;return{x:y,y:g}},fl=function(e,t,n){var r=e.setup,i=e.state,s=r.minScale,o=r.disablePadding,l=r.centerZoomedOut,u=n??i.scale;return t>0&&u>=s&&!o&&!l?t:0},nl;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(nl||(nl={}));var koe=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},Toe=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 Roe(e,t){var n=e.setup.velocityAnimation,r=n.animationTime,i=n.maxAnimationTime,s=n.inertia;return Math.min(r*Math.max(1,Math.abs(t/s)),i)}function gM(e,t,n,r,i,s,o,l,u,d){if(i){if(t>o&&n>o){var h=o+(e-o)*d;return h>u?u:h<o?o:h}if(t<s&&n<s){var h=s+(e-s)*d;return h<l?l:h>s?s:h}}return r?t:gf(e,s,o,i)}function Aoe(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var rw=function(e,t,n){var r=0,i=e*n;return Number.isNaN(i)?r:e<0?Math.max(i,-t):Math.min(i,t)};function Noe(e,t,n){var r,i,s=koe(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,h=u.velocityAnimation,p=h.maxStrengthMouse,y=h.maxStrengthTouch,g=h.sensitivityTouch,b=h.sensitivityMouse,w=Date.now();if(o&&l&&d){var x=Aoe(d),E=(r={},r[nl.TOUCH]=g,r[nl.MOUSE]=b,r)[n],k=(i={},i[nl.TOUCH]=y,i[nl.MOUSE]=p,i)[n],T=t.x-o.x,R=t.y-o.y,z=rw(T/x,k,E),N=rw(R/x,k,E),$=w-l,P=T*T+R*R,q=rw(Math.sqrt(P)/$,k,E);e.velocity={velocityX:z,velocityY:N,total:q}}e.lastMousePosition=t,e.velocityTime=w}}function Moe(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Toe(e);if(!(!s||!t||!n||!i)){var o=t.velocityX,l=t.velocityY,u=t.total,d=n.maxPositionX,h=n.minPositionX,p=n.maxPositionY,y=n.minPositionY,g=r.limitToBounds,b=r.autoAlignment,w=r.zoomAnimation,x=r.panning,E=x.lockAxisY,k=x.lockAxisX,T=w.animationType,R=b.sizeX,z=b.sizeY,N=b.velocityAlignmentTime,$=N,P=Roe(e,u),q=Math.max(P,$),H=fl(e,R),U=fl(e,z),O=H*i.offsetWidth/100,M=U*i.offsetHeight/100,I=d+O,L=h-O,D=p+M,Y=y-M,K=e.state,F=new Date().getTime();e3(e,T,q,function(A){var W=e.state,G=W.scale,B=W.positionX,ne=W.positionY,ie=new Date().getTime()-F,se=ie/$,te=QB[b.animationType],he=1-te(Math.min(1,se)),ge=1-A,Ee=B+o*ge,Re=ne+l*ge,Ie=gM(Ee,K.positionX,B,k,g,h,d,L,I,he),Ye=gM(Re,K.positionY,ne,E,g,y,p,Y,D,he);if(B!==Ee||ne!==Re){e.setState(G,Ie,Ye);var gt=e.props.onPanning;gt&&gt(kn(e),{})}})}}function vM(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},Ys(e),Gu(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?xoe(e,t):Soe(e,t)}function n3(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=Eoe(e);y&&El(e,y,d,h)}}function yM(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=Coe(e,t,n),h=d.x,p=d.y,y=fl(e,l),g=fl(e,u);Noe(e,{x:h,y:p},r),t3(e,h,p,y,g)}}function Ooe(e,t){if(e.isPanning){var n=e.velocity,r=e.wrapperComponent,i=e.contentComponent;e.isPanning=!1;var s=e.state,o=s.positionX,l=s.positionY,u=s.scale,d=e.panStartPosition;if(e.panStartPosition=null,d){var h=o-d.x,p=l-d.y;if(h*h+p*p<=25)return}e.isAnimating=!1,e.animation=null;var y=(r==null?void 0:r.offsetWidth)||0,g=(r==null?void 0:r.offsetHeight)||0,b=((i==null?void 0:i.offsetWidth)||0)*u,w=((i==null?void 0:i.offsetHeight)||0)*u,x=!e.setup.limitToBounds||y<b||g<w,E=!t&&n&&n.total>.1&&x;E?Moe(e):n3(e)}}function F1(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Yf(Jl(t,2),s,o,0,!1),d=Gu(e,u),h=Zv(e,n,r,u,d,l),p=h.x,y=h.y;return{scale:u,positionX:p,positionY:y}}function $1(e,t,n){var r=e.state.scale,i=e.wrapperComponent,s=e.setup,o=s.minScale,l=s.maxScale,u=s.limitToBounds,d=s.zoomAnimation,h=d.disabled,p=d.animationTime,y=d.animationType,g=r>=o&&r<=l,b=h||g;if((r>=1||u)&&n3(e),!(b||!i||!e.mounted)){var w=t||i.offsetWidth/2,x=n||i.offsetHeight/2,E=r<o?o:l,k=F1(e,E,w,x);k&&El(e,k,p,y)}}var Ms=function(){return Ms=Object.assign||function(t){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Ms.apply(this,arguments)};function _M(e,t,n){for(var r=0,i=t.length,s;r<i;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}var iw={scale:1,positionX:0,positionY:0},Zl={disabled:!1,minPositionX:null,maxPositionX:null,minPositionY:null,maxPositionY:null,minScale:1,maxScale:8,limitToBounds:!0,centerZoomedOut:!1,centerOnInit:!1,disablePadding:!1,smooth:!0,detached:!1,wheel:{step:.015,disabled:!1,wheelDisabled:!1,touchPadDisabled:!1,activationKeys:[],excluded:[]},trackPadPanning:{disabled:!0,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,activationKeys:[],excluded:[]},panning:{disabled:!1,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,allowLeftClickPan:!0,allowMiddleClickPan:!0,allowRightClickPan:!0,activationKeys:[],excluded:[]},pinch:{step:5,disabled:!1,allowPanning:!0,excluded:[]},doubleClick:{disabled:!1,step:.7,mode:"zoomIn",animationType:"easeOut",animationTime:200,excluded:[]},zoomAnimation:{disabled:!1,size:.4,animationTime:200,animationType:"easeOut"},autoAlignment:{disabled:!1,sizeX:100,sizeY:100,animationTime:200,velocityAlignmentTime:400,animationType:"easeOut"},velocityAnimation:{disabled:!1,sensitivityMouse:1,sensitivityTouch:1.2,maxStrengthMouse:20,maxStrengthTouch:40,inertia:1,animationTime:300,maxAnimationTime:800,animationType:"easeOut"}},W0={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},r3=function(e){var t,n,r,i,s,o,l,u,d,h=Math.max((t=e.minScale)!==null&&t!==void 0?t:Zl.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:Zl.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:iw.scale,g=Math.min(Math.max(y,h),p),b=gf((i=e.initialPositionX)!==null&&i!==void 0?i:iw.positionX,(s=e.minPositionX)!==null&&s!==void 0?s:-1/0,(o=e.maxPositionX)!==null&&o!==void 0?o:1/0,e.minPositionX!=null||e.maxPositionX!=null),w=gf((l=e.initialPositionY)!==null&&l!==void 0?l:iw.positionY,(u=e.minPositionY)!==null&&u!==void 0?u:-1/0,(d=e.maxPositionY)!==null&&d!==void 0?d:1/0,e.minPositionY!=null||e.maxPositionY!=null);return{previousScale:g,scale:g,positionX:b,positionY:w}},bM=function(e){var t=Ms({},Zl);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Zl[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Zl[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=Ms(Ms({},Zl[r]),e[r]):u?t[r]=_M(_M([],Zl[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},i3=function(e,t,n){var r=e.state.scale,i=e.wrapperComponent,s=e.setup,o=s.maxScale,l=s.minScale,u=s.zoomAnimation,d=s.smooth,h=u.size;if(!i)throw new Error("Wrapper is not mounted");var p=d?r*Math.exp(t*n):r+t*n,y=Yf(Jl(p,3),l,o,h,!1);return y};function s3(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,h=u.positionX,p=u.positionY,y=e.setup.zoomAnimation;if(!l)return console.error("No WrapperComponent found");var g=y.disabled?0:r,b=l.offsetWidth,w=l.offsetHeight,x=(b/2-h)/d,E=(w/2-p)/d,k=i3(e,t,n),T=F1(e,k,x,E);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");var R=e.props,z=R.onZoomStart,N=R.onZoom,$=R.onZoomStop,P=new MouseEvent("mousemove",{bubbles:!0}),q=kn(e);Ln(q,P,z),Ln(q,P,N),El(e,T,g,i);var H=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;H&&H.setTimeout(function(){e.mounted&&Ln(kn(e),P,$)},g)}function o3(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,h=o.centerOnInit,p=r3(e.props),y=e.state,g=y.scale,b=y.positionX,w=y.positionY;if(l){var x=p.positionX,E=p.positionY;if(h&&u){var k=H1(p.scale,l,u);x=k.positionX,E=k.positionY}var T=j1(e,p.scale),R=Vf(x,E,T,d,0,0,l),z={scale:p.scale,positionX:R.x,positionY:R.y};if(!(g===p.scale&&b===p.positionX&&w===p.positionY)){r==null||r();var N=e.props,$=N.onZoomStart,P=N.onZoom,q=N.onZoomStop,H=new MouseEvent("mousemove",{bubbles:!0}),U=kn(e);Ln(U,H,$),Ln(U,H,P),El(e,z,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&&Ln(kn(e),H,q)},t)}}}function Doe(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 Poe(e,t,n,r,i){r===void 0&&(r=0),i===void 0&&(i=0);var s=e.wrapperComponent,o=e.contentComponent,l=e.state,u=e.setup,d=u.limitToBounds,h=u.minScale,p=u.maxScale;if(!s||!o)return l;var y=s.getBoundingClientRect(),g=t.getBoundingClientRect(),b=Doe(t,s,o,l),w=b.x,x=b.y,E=g.width/l.scale,k=g.height/l.scale,T=s.offsetWidth/E,R=s.offsetHeight/k,z=Yf(n||Math.min(T,R),h,p,0,!1),N=(y.width-E*z)/2,$=(y.height-k*z)/2,P=(y.left-w)*z+N+r,q=(y.top-x)*z+$+i,H=j1(e,z),U=Vf(P,q,H,d,0,0,s),O=U.x,M=U.y;return{positionX:O,positionY:M,scale:z}}var Loe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),s3(e,1,t,n,r)}},Ioe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),s3(e,-1,t,n,r)}},zoe=function(e){return function(t,n,r,i,s){i===void 0&&(i=300),s===void 0&&(s="easeOut");var o=e.state,l=o.positionX,u=o.positionY,d=o.scale,h=e.wrapperComponent,p=e.contentComponent,y=e.setup.disabled;if(!(y||!h||!p)){var g={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};El(e,g,i,s)}}},Boe=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),o3(e,t,n)}},joe=function(e){return function(t,n,r){n===void 0&&(n=200),r===void 0&&(r="easeOut");var i=e.state,s=e.wrapperComponent,o=e.contentComponent;if(s&&o){var l=H1(t||i.scale,s,o);El(e,l,n,r)}}},Foe=function(e){return function(t,n,r,i,s,o){r===void 0&&(r=600),i===void 0&&(i="easeOut"),s===void 0&&(s=0),o===void 0&&(o=0),Ys(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=Poe(e,u,n,s,o);El(e,d,r,i)}}},q0=function(e){return{instance:e,state:e.state,zoomIn:Loe(e),zoomOut:Ioe(e),setTransform:zoe(e),resetTransform:Boe(e),centerView:joe(e),zoomToElement:Foe(e)}},$oe=function(e){return{instance:e,state:e.state}},kn=function(e){var t={};return Object.assign(t,$oe(e)),Object.assign(t,q0(e)),t},sw=!1;function ow(){try{var e={get passive(){return sw=!0,!1}};return e}catch{return sw=!1,sw}}var $m=".".concat(W0.wrapperClass),Kf=function(e,t){return t.some(function(n){return e.matches("".concat($m," ").concat(n,", ").concat($m," .").concat(n,", ").concat($m," ").concat(n," *, ").concat($m," .").concat(n," *"))})},vf=function(e){e&&clearTimeout(e)},Hoe=function(e){return Number.parseFloat(e.toFixed(8))},a3=function(e,t,n){var r=Hoe(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},H1=function(e,t,n){var r=n.offsetWidth*e,i=n.offsetHeight*e,s=(t.offsetWidth-r)/2,o=(t.offsetHeight-i)/2;return{scale:e,positionX:s,positionY:o}};function Uoe(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Woe(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var l3=function(e,t){var n=e.setup.wheel,r=n.disabled,i=n.wheelDisabled,s=n.touchPadDisabled,o=n.excluded,l=e.isInitialized,u=e.isPanning,d=t.target,h=l&&!u&&!r&&d;if(!h||i&&!t.ctrlKey||s&&t.ctrlKey)return!1;var p=Kf(d,o);if(p)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},qoe=function(e,t){var n=e.setup,r=n.disabled,i=n.trackPadPanning,s=i.activationKeys,o=i.excluded;if(!e.wrapperComponent||!e.contentComponent||r||i.disabled||t.ctrlKey)return!1;var l=l3(e,t);if(l)return!1;var u=t.target,d=Kf(u,o);if(d)return!1;var h=e.isPressingKeys(s);return!!h},Voe=function(e){return e?e.deltaY<0?1:-1:0};function Yoe(e,t){var n=Voe(e),r=ioe(t,n);return r}function c3(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 Koe=function(e,t,n,r,i){var s=e.state.scale,o=e.wrapperComponent,l=e.setup,u=l.maxScale,d=l.minScale,h=l.zoomAnimation,p=l.disablePadding,y=h.size,g=h.disabled;if(!o)throw new Error("Wrapper is not mounted");var b=s+t*n,w=r?!1:!g,x=Yf(b,d,u,y,w&&!p);return x},u3=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},Goe=function(e,t){var n=e.setup.pinch,r=n.disabled,i=n.excluded,s=e.isInitialized,o=t.target,l=s&&!r&&o;if(!l)return!1;var u=Kf(o,i);return!u},Xoe=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},Zoe=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}},d3=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))},Qoe=5,Joe=function(e,t){var n=e.pinchStartScale,r=e.pinchStartDistance,i=e.setup,s=i.maxScale,o=i.minScale,l=i.zoomAnimation,u=i.disablePadding,d=i.pinch,h=l.size,p=l.disabled,y=d.step;if(!n||r===null)throw new Error("Pinch touches distance was not provided");if(t<0)return e.state.scale;var g=t/r,b=g*n,w=(b-n)*(y/Qoe),x=n+w,E=x===1/0?0:Jl(x,10);return Yf(E,o,s,h,!p&&!u)},h3=160,f3=100,eae=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(Ys(e),Ln(kn(e),t,r),Ln(kn(e),t,i))},tae=function(e,t){var n=e.props,r=n.onWheel,i=n.onZoom,s=e.contentComponent,o=e.setup,l=e.state,u=l.scale,d=o.limitToBounds,h=o.centerZoomedOut,p=o.zoomAnimation,y=o.wheel,g=o.disablePadding,b=o.smooth,w=p.size,x=p.disabled,E=y.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var k=Yoe(t,null),T=b?E*Math.abs(t.deltaY):E,R=Koe(e,k,T,!t.ctrlKey);if(u!==R){var z=Gu(e,R),N=c3(t,s,u),$=x||w===0||h||g,P=d&&$,q=Zv(e,N.x,N.y,R,z,P),H=q.x,U=q.y;e.previousWheelEvent=t,e.setState(R,H,U),Ln(kn(e),t,r),Ln(kn(e),t,i)}},nae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;vf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&($1(e,t.x,t.y),e.wheelAnimationTimer=null)},f3);var s=u3(e,t);s&&(vf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Ln(kn(e),t,r),Ln(kn(e),t,i))},h3))},rae=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(Ys(e),Ln(kn(e),t,r),Ln(kn(e),t,i))},iae=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;vf(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&($1(e,t.x,t.y),e.wheelAnimationTimer=null)},f3);var s=u3(e,t);s&&(vf(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,Ln(kn(e),t,r),Ln(kn(e),t,i))},h3))},p3=function(e){for(var t=0,n=0,r=0;r<2;r+=1)t+=e.touches[r].clientX,n+=e.touches[r].clientY;var i=t/2,s=n/2;return{x:i,y:s}},sae=function(e,t){var n=d3(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=p3(t),Ys(e)},oae=function(e,t){var n=e.contentComponent,r=e.pinchStartDistance,i=e.wrapperComponent,s=e.pinchPreviousCenter,o=e.state.scale,l=e.setup,u=l.limitToBounds,d=l.centerZoomedOut,h=l.zoomAnimation,p=l.autoAlignment,y=l.pinch,g=l.panning,b=h.disabled,w=h.size,x=y.allowPanning;if(!(r===null||!n)){var E=Zoe(t,o,n);if(!(!Number.isFinite(E.x)||!Number.isFinite(E.y))){var k=d3(t),T=Joe(e,k),R=p3(t),z=o/T,N=(R.x-((s==null?void 0:s.x)||0))*z,$=(R.y-((s==null?void 0:s.y)||0))*z;if(!(T===o&&N===0&&$===0)){e.pinchPreviousCenter=R;var P=Gu(e,T),q=b||w===0||d,H=u&&q,U=Zv(e,E.x,E.y,T,P,H),O=U.x,M=U.y;if(e.pinchMidpoint=E,e.lastDistance=k,g.disabled||!x)e.setState(T,O,M);else{var I=p.sizeX,L=p.sizeY,D=fl(e,I,T),Y=fl(e,L,T),K=O+N,F=M+$,A=Vf(K,F,P,u,D,Y,i),W=A.x,G=A.y;e.setState(T,W,G)}}}}},aae=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,$1(e,t==null?void 0:t.x,t==null?void 0:t.y)},m3=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;vf(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,Ln(kn(e),t,n)},r)},lae=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;Ln(kn(e),t,r),o3(e,o,l,function(){return Ln(kn(e),t,i)}),m3(e,t)};function cae(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function uae(e,t){var n=e.setup,r=e.doubleClickStopEventTimer,i=e.state,s=e.contentComponent,o=i.scale,l=e.props,u=l.onZoomStart,d=l.onZoom,h=n.doubleClick,p=h.disabled,y=h.mode,g=h.step,b=h.animationTime,w=h.animationType;if(!p&&!r){if(y==="reset")return lae(e,t);if(!s)return console.error("No ContentComponent found");var x=cae(y,e.state.scale),E=i3(e,x,g);if(o!==E){Ln(kn(e),t,u);var k=c3(t,s,o),T=F1(e,E,k.x,k.y);if(!T)return console.error("Error during zoom event. New transformation state was not calculated.");Ln(kn(e),t,d),El(e,T,b,w),m3(e,t)}}}var dae=function(e,t){var n=e.isInitialized,r=e.setup,i=e.wrapperComponent,s=r.doubleClick,o=s.disabled,l=s.excluded,u=t.target,d=i==null?void 0:i.contains(u),h=n&&u&&d&&!o;if(!h)return!1;var p=Kf(u,l);return!p},hae=(function(){function e(t){var n=this;this.mounted=!0,this.onChangeCallbacks=new Set,this.onInitCallbacks=new Set,this.onTransformCallbacks=new Set,this.wrapperComponent=null,this.contentComponent=null,this.isInitialized=!1,this.bounds=null,this.previousWheelEvent=null,this.wheelStopEventTimer=null,this.wheelAnimationTimer=null,this.isPanning=!1,this.isWheelPanning=!1,this.startCoords=null,this.panStartPosition=null,this.lastTouch=null,this.isPinching=!1,this.distance=null,this.lastDistance=null,this.pinchStartDistance=null,this.pinchStartScale=null,this.pinchMidpoint=null,this.pinchPreviousCenter=null,this.doubleClickStopEventTimer=null,this.velocity=null,this.velocityTime=null,this.lastMousePosition=null,this.isAnimating=!1,this.animation=null,this.pressedKeys={},this.mount=function(){n.initializeWindowEvents()},this.unmount=function(){n.cleanupWindowEvents()},this.update=function(r){n.props=r,n.wrapperComponent&&n.contentComponent&&Gu(n,n.state.scale),n.setup=bM(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=ow(),u=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,d=u==null?void 0:u.defaultView;(i=n.wrapperComponent)===null||i===void 0||i.addEventListener("wheel",n.onWheelPanning,l),(s=n.wrapperComponent)===null||s===void 0||s.addEventListener("keyup",n.setKeyUnPressed,l),(o=n.wrapperComponent)===null||o===void 0||o.addEventListener("keydown",n.setKeyPressed,l),d==null||d.addEventListener("mousedown",n.onPanningStart,l),d==null||d.addEventListener("mousemove",n.onPanning,l),d==null||d.addEventListener("mouseup",n.onPanningStop,l),u==null||u.addEventListener("mouseleave",n.clearPanning,l),d==null||d.addEventListener("keyup",n.setKeyUnPressed,l),d==null||d.addEventListener("keydown",n.setKeyPressed,l),d==null||d.addEventListener("blur",n.handleWindowBlur)},this.cleanupWindowEvents=function(){var r,i,s,o,l,u=ow(),d=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,h=d==null?void 0:d.defaultView;h==null||h.removeEventListener("mousedown",n.onPanningStart,u),h==null||h.removeEventListener("mousemove",n.onPanning,u),h==null||h.removeEventListener("mouseup",n.onPanningStop,u),d==null||d.removeEventListener("mouseleave",n.clearPanning,u),h==null||h.removeEventListener("keyup",n.setKeyUnPressed,u),h==null||h.removeEventListener("keydown",n.setKeyPressed,u),h==null||h.removeEventListener("blur",n.handleWindowBlur),document.removeEventListener("mouseleave",n.clearPanning,u),(i=n.wrapperComponent)===null||i===void 0||i.removeEventListener("wheel",n.onWheelPanning,u),(s=n.wrapperComponent)===null||s===void 0||s.removeEventListener("keyup",n.setKeyUnPressed,u),(o=n.wrapperComponent)===null||o===void 0||o.removeEventListener("keydown",n.setKeyPressed,u),Ys(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=ow();r.addEventListener("wheel",n.onWheelZoom,i),r.addEventListener("dblclick",n.onDoubleClick,i),r.addEventListener("touchstart",n.onTouchPanningStart,i),r.addEventListener("touchmove",n.onTouchPanning,i),r.addEventListener("touchend",n.onTouchPanningStop,i)},this.handleInitialize=function(r){var i=n.setup.centerOnInit;n.applyTransformation(),n.onInitCallbacks.forEach(function(s){return s(kn(n))}),i&&(n.setCenter(),n.observer=new ResizeObserver(function(){var s,o=r.offsetWidth,l=r.offsetHeight;(o>0||l>0)&&(n.onInitCallbacks.forEach(function(u){return u(kn(n))}),n.setCenter(),(s=n.observer)===null||s===void 0||s.disconnect())}),setTimeout(function(){var s;(s=n.observer)===null||s===void 0||s.disconnect()},5e3),n.observer.observe(r))},this.onWheelZoom=function(r){var i=n.setup.disabled;if(!i){n.syncModifierKeys(r);var s=l3(n,r);s&&(eae(n,r),tae(n,r),nae(n,r))}},this.onWheelPanning=function(r){var i=n.props.onPanning,s=n.setup.trackPadPanning,o=s.lockAxisX,l=s.lockAxisY;n.syncModifierKeys(r);var u=qoe(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,h=d.positionX,p=d.positionY,y=h-r.deltaX,g=p-r.deltaY,b=o?h:y,w=l?p:g,x=n.setup.autoAlignment,E=x.sizeX,k=x.sizeY,T=fl(n,E),R=fl(n,k);b===h&&w===p||(rae(n,r),t3(n,b,w,T,R),Ln(kn(n),r,i),iae(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=pM(n,r);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.button===0&&!n.setup.panning.allowLeftClickPan||r.button===1&&!n.setup.panning.allowMiddleClickPan||r.button===2&&!n.setup.panning.allowRightClickPan||(r.preventDefault(),r.stopPropagation(),Ys(n),vM(n,r),Ln(kn(n),r,s)))}}},this.onPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(!i){if(n.syncModifierKeys(r),n.isPanning&&r.buttons===0){n.clearPanning(r);return}var o=mM(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),yM(n,r.clientX,r.clientY,nl.MOUSE),Ln(kn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(Ooe(n,i),Ln(kn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=Goe(n,r);o&&(sae(n,r),Ys(n),Ln(kn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=Xoe(n);o&&(r.preventDefault(),r.stopPropagation(),oae(n,r),Ln(kn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(aae(n),Ln(kn(n),r,i))},this.onTouchPanningStart=function(r){var i=n.setup,s=i.disabled,o=i.doubleClick,l=n.props.onPanningStart;if(!s){var u=!(o!=null&&o.disabled),d=n.lastTouch&&+new Date-n.lastTouch<200;if(u&&d&&r.touches.length===1)n.onDoubleClick(r);else{n.lastTouch=+new Date,Ys(n);var h=r.touches,p=h.length===1,y=h.length===2,g=pM(n,r);if(p){if(!g)return;Ys(n),vM(n,r),Ln(kn(n),r,l)}y&&n.onPinchStart(r)}}},this.onTouchPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(n.isPanning&&r.touches.length===1){if(i)return;var o=mM(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];yM(n,l.clientX,l.clientY,nl.TOUCH),Ln(kn(n),r,s)}else r.touches.length>1&&n.onPinch(r)},this.onTouchPanningStop=function(r){n.onPanningStop(r),n.onPinchStop(r)},this.onDoubleClick=function(r){var i=n.setup.disabled;if(!i){var s=dae(n,r);s&&uae(n,r)}},this.clearPanning=function(r){n.isPanning&&n.onPanningStop(r)},this.handleWindowBlur=function(){n.pressedKeys={},n.isPanning&&(n.isPanning=!1,n.startCoords=null)},this.syncModifierKeys=function(r){var i=r.ctrlKey,s=r.metaKey,o=r.shiftKey,l=r.altKey;typeof i=="boolean"&&(n.pressedKeys.Control=i),typeof s=="boolean"&&(n.pressedKeys.Meta=s),typeof o=="boolean"&&(n.pressedKeys.Shift=o),typeof l=="boolean"&&(n.pressedKeys.Alt=l)},this.setKeyPressed=function(r){n.pressedKeys[r.key]=!0},this.setKeyUnPressed=function(r){n.pressedKeys[r.key]=!1},this.isPressingKeys=function(r){return typeof r=="function"?r(Object.entries(n.pressedKeys).filter(function(i){var s=i[1];return s}).map(function(i){var s=i[0];return s})):r.length?!!r.every(function(i){return n.pressedKeys[i]}):!0},this.setCenter=function(){if(n.wrapperComponent&&n.contentComponent){var r=H1(n.state.scale,n.wrapperComponent,n.contentComponent);n.setState(r.scale,r.positionX,r.positionY)}},this.handleTransformStyles=function(r,i,s){return n.props.customTransform?n.props.customTransform(r,i,s):a3(r,i,s)},this.getContext=function(){return kn(n)},this.applyTransformation=function(){if(!(!n.mounted||!n.contentComponent)){var r=n.state,i=r.scale,s=r.positionX,o=r.positionY,l=n.handleTransformStyles(s,o,i);n.props.detached||(n.contentComponent.style.transform=l),n.onTransformCallbacks.forEach(function(u){return u({scale:i,positionX:s,positionY:o,previousScale:n.state.previousScale,ref:kn(n)})})}},this.setState=function(r,i,s){var o=n.props.onTransform;if(!Number.isNaN(r)&&!Number.isNaN(i)&&!Number.isNaN(s)){var l=Math.max(r,1e-7);l!==n.state.scale&&(n.state.previousScale=n.state.scale,n.state.scale=l),n.state.positionX=i,n.state.positionY=s,n.applyTransformation();var u=kn(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),Ln(u,{scale:n.state.scale,positionX:i,positionY:s},o)}else console.error("Detected NaN set state values")},this.onTransform=function(r){return n.onTransformCallbacks.has(r)||n.onTransformCallbacks.add(r),function(){n.onTransformCallbacks.delete(r)}},this.onChange=function(r){return n.onChangeCallbacks.has(r)||n.onChangeCallbacks.add(r),function(){n.onChangeCallbacks.delete(r)}},this.onInit=function(r){return n.onInitCallbacks.has(r)||n.onInitCallbacks.add(r),function(){n.onInitCallbacks.delete(r)}},this.init=function(r,i){n.cleanupWindowEvents(),n.wrapperComponent=r,n.contentComponent=i,Gu(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=kn(n);Ln(s,void 0,n.props.onInit),Uoe(n.props.ref,s)},this.props=t,this.setup=bM(this.props),this.state=r3(this.props)}return e})(),Qv=Ke.createContext(null),fae=function(e,t){return typeof e=="function"?e(t):e},pae=Ke.forwardRef(function(e,t){var n=_.useRef(new hae(e)).current,r=fae(e.children,q0(n));return _.useImperativeHandle(t,function(){return q0(n)},[n]),_.useEffect(function(){n.update(e)},[n,e]),v.jsx(Qv.Provider,Ms({value:n},{children:r}))});Ke.forwardRef(function(e,t){var n=_.useRef(null),r=_.useContext(Qv);return _.useEffect(function(){return r.onChange(function(i){if(n.current){var s=0,o=0;n.current.style.transform=r.handleTransformStyles(s,o,1/i.instance.state.scale)}})},[r]),v.jsx("div",Ms({},e,{ref:Woe([n,t])}))});function mae(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 gae=`.transform-component-module_wrapper__SPB86 {
503
503
  position: relative;
@@ -629,12 +629,12 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
629
629
  `+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)}},ohe=new she;function Tw(e){ahe(e)||ohe.onUnexpectedError(e)}var PS="Canceled";function ahe(e){return e instanceof lhe?!0:e instanceof Error&&e.name===PS&&e.message===PS}var lhe=class extends Error{constructor(){super(PS),this.name=this.message}},x2=class LS extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof LS)return t;let n=new LS;return n.message=t.message,n.stack=t.stack,n}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}};function che(e,t){let n=this,r=!1,i;return function(){return r||(r=!0,t||(i=e.apply(n,arguments))),i}}var uhe;(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})(uhe||(uhe={}));var T5;(e=>{function t(R){return R&&typeof R=="object"&&typeof R[Symbol.iterator]=="function"}e.is=t;let n=Object.freeze([]);function r(){return n}e.empty=r;function*i(R){yield R}e.single=i;function s(R){return t(R)?R:i(R)}e.wrap=s;function o(R){return R||n}e.from=o;function*l(R){for(let z=R.length-1;z>=0;z--)yield R[z]}e.reverse=l;function u(R){return!R||R[Symbol.iterator]().next().done===!0}e.isEmpty=u;function d(R){return R[Symbol.iterator]().next().value}e.first=d;function h(R,z){let N=0;for(let $ of R)if(z($,N++))return!0;return!1}e.some=h;function p(R,z){for(let N of R)if(z(N))return N}e.find=p;function*y(R,z){for(let N of R)z(N)&&(yield N)}e.filter=y;function*g(R,z){let N=0;for(let $ of R)yield z($,N++)}e.map=g;function*b(R,z){let N=0;for(let $ of R)yield*z($,N++)}e.flatMap=b;function*w(...R){for(let z of R)yield*z}e.concat=w;function x(R,z,N){let $=N;for(let P of R)$=z($,P);return $}e.reduce=x;function*E(R,z,N=R.length){for(z<0&&(z+=R.length),N<0?N+=R.length:N>R.length&&(N=R.length);z<N;z++)yield R[z]}e.slice=E;function k(R,z=Number.POSITIVE_INFINITY){let N=[];if(z===0)return[N,R];let $=R[Symbol.iterator]();for(let P=0;P<z;P++){let q=$.next();if(q.done)return[N,e.empty()];N.push(q.value)}return[N,{[Symbol.iterator](){return $}}]}e.consume=k;async function T(R){let z=[];for await(let N of R)z.push(N);return Promise.resolve(z)}e.asyncToArray=T})(T5||(T5={}));function R5(e){if(T5.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 dhe(...e){return A5(()=>R5(e))}function A5(e){return{dispose:che(()=>{e()})}}var N5=class M5{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{R5(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?M5.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)}};N5.DISABLE_DISPOSED_WARNING=!1;var rE=N5,rv=class{constructor(){this._store=new rE,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)}};rv.None=Object.freeze({dispose(){}});var hhe=globalThis.performance&&typeof globalThis.performance.now=="function",fhe=class O5{static create(t){return new O5(t)}constructor(t){this._now=hhe&&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}},phe;(e=>{e.None=()=>rv.None;function t(O,M){return p(O,()=>{},0,void 0,!0,void 0,M)}e.defer=t;function n(O){return(M,I=null,L)=>{let D=!1,Y;return Y=O(K=>{if(!D)return Y?Y.dispose():D=!0,M.call(I,K)},null,L),D&&Y.dispose(),Y}}e.once=n;function r(O,M,I){return d((L,D=null,Y)=>O(K=>L.call(D,M(K)),null,Y),I)}e.map=r;function i(O,M,I){return d((L,D=null,Y)=>O(K=>{M(K),L.call(D,K)},null,Y),I)}e.forEach=i;function s(O,M,I){return d((L,D=null,Y)=>O(K=>M(K)&&L.call(D,K),null,Y),I)}e.filter=s;function o(O){return O}e.signal=o;function l(...O){return(M,I=null,L)=>{let D=dhe(...O.map(Y=>Y(K=>M.call(I,K))));return h(D,L)}}e.any=l;function u(O,M,I,L){let D=I;return r(O,Y=>(D=M(D,Y),D),L)}e.reduce=u;function d(O,M){let I,L={onWillAddFirstListener(){I=O(D.fire,D)},onDidRemoveLastListener(){I==null||I.dispose()}},D=new Va(L);return M==null||M.add(D),D.event}function h(O,M){return M instanceof Array?M.push(O):M&&M.add(O),O}function p(O,M,I=100,L=!1,D=!1,Y,K){let F,A,W,G=0,B,ne={leakWarningThreshold:Y,onWillAddFirstListener(){F=O(se=>{G++,A=M(A,se),L&&!W&&(ie.fire(A),A=void 0),B=()=>{let te=A;A=void 0,W=void 0,(!L||G>1)&&ie.fire(te),G=0},typeof I=="number"?(clearTimeout(W),W=setTimeout(B,I)):W===void 0&&(W=0,queueMicrotask(B))})},onWillRemoveListener(){D&&G>0&&(B==null||B())},onDidRemoveLastListener(){B=void 0,F.dispose()}},ie=new Va(ne);return K==null||K.add(ie),ie.event}e.debounce=p;function y(O,M=0,I){return e.debounce(O,(L,D)=>L?(L.push(D),L):[D],M,void 0,!0,void 0,I)}e.accumulate=y;function g(O,M=(L,D)=>L===D,I){let L=!0,D;return s(O,Y=>{let K=L||!M(Y,D);return L=!1,D=Y,K},I)}e.latch=g;function b(O,M,I){return[e.filter(O,M,I),e.filter(O,L=>!M(L),I)]}e.split=b;function w(O,M=!1,I=[],L){let D=I.slice(),Y=O(A=>{D?D.push(A):F.fire(A)});L&&L.add(Y);let K=()=>{D==null||D.forEach(A=>F.fire(A)),D=null},F=new Va({onWillAddFirstListener(){Y||(Y=O(A=>F.fire(A)),L&&L.add(Y))},onDidAddFirstListener(){D&&(M?setTimeout(K):K())},onDidRemoveLastListener(){Y&&Y.dispose(),Y=null}});return L&&L.add(F),F.event}e.buffer=w;function x(O,M){return(I,L,D)=>{let Y=M(new k);return O(function(K){let F=Y.evaluate(K);F!==E&&I.call(L,F)},void 0,D)}}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(I=>(M(I),I)),this}filter(M){return this.steps.push(I=>M(I)?I:E),this}reduce(M,I){let L=I;return this.steps.push(D=>(L=M(L,D),L)),this}latch(M=(I,L)=>I===L){let I=!0,L;return this.steps.push(D=>{let Y=I||!M(D,L);return I=!1,L=D,Y?D:E}),this}evaluate(M){for(let I of this.steps)if(M=I(M),M===E)break;return M}}function T(O,M,I=L=>L){let L=(...F)=>K.fire(I(...F)),D=()=>O.on(M,L),Y=()=>O.removeListener(M,L),K=new Va({onWillAddFirstListener:D,onDidRemoveLastListener:Y});return K.event}e.fromNodeEventEmitter=T;function R(O,M,I=L=>L){let L=(...F)=>K.fire(I(...F)),D=()=>O.addEventListener(M,L),Y=()=>O.removeEventListener(M,L),K=new Va({onWillAddFirstListener:D,onDidRemoveLastListener:Y});return K.event}e.fromDOMEventEmitter=R;function z(O){return new Promise(M=>n(O)(M))}e.toPromise=z;function N(O){let M=new Va;return O.then(I=>{M.fire(I)},()=>{M.fire(void 0)}).finally(()=>{M.dispose()}),M.event}e.fromPromise=N;function $(O,M){return O(I=>M.fire(I))}e.forward=$;function P(O,M,I){return M(I),O(L=>M(L))}e.runAndSubscribe=P;class q{constructor(M,I){this._observable=M,this._counter=0,this._hasChanged=!1;let L={onWillAddFirstListener:()=>{M.addObserver(this)},onDidRemoveLastListener:()=>{M.removeObserver(this)}};this.emitter=new Va(L),I&&I.add(this.emitter)}beginUpdate(M){this._counter++}handlePossibleChange(M){}handleChange(M,I){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 H(O,M){return new q(O,M).emitter.event}e.fromObservable=H;function U(O){return(M,I,L)=>{let D=0,Y=!1,K={beginUpdate(){D++},endUpdate(){D--,D===0&&(O.reportChanges(),Y&&(Y=!1,M.call(I)))},handlePossibleChange(){},handleChange(){Y=!0}};O.addObserver(K),O.reportChanges();let F={dispose(){O.removeObserver(K)}};return L instanceof rE?L.add(F):Array.isArray(L)&&L.push(F),F}}e.fromObservableLight=U})(phe||(phe={}));var IS=class zS{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${zS._idPool++}`,zS.all.add(this)}start(t){this._stopWatch=new fhe,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}}};IS.all=new Set,IS._idPool=0;var mhe=IS,ghe=-1,D5=class P5{constructor(t,n,r=(P5._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 _he(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}};D5._idPool=1;var vhe=D5,yhe=class L5{constructor(t){this.value=t}static create(){let t=new Error;return new L5(t.stack??"")}print(){console.warn(this.value.split(`
630
630
  `).slice(2).join(`
631
631
  `))}},_he=class extends Error{constructor(t,n){super(t),this.name="ListenerLeakError",this.stack=n}},bhe=class extends Error{constructor(t,n){super(t),this.name="ListenerRefusalError",this.stack=n}},whe=0,Rw=class{constructor(t){this.value=t,this.id=whe++}},She=2,xhe,Va=class{constructor(e){var t,n,r,i;this._size=0,this._options=e,this._leakageMon=(t=this._options)!=null&&t.leakWarningThreshold?new vhe((e==null?void 0:e.onListenerError)??Tw,((n=this._options)==null?void 0:n.leakWarningThreshold)??ghe):void 0,this._perfMon=(r=this._options)!=null&&r._profName?new mhe(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],g=new bhe(`${p}. HINT: Stack shows most frequent listener (${y[1]}-times)`,y[0]);return(((o=this._options)==null?void 0:o.onListenerError)||Tw)(g),rv.None}if(this._disposed)return rv.None;t&&(e=e.bind(t));let r=new Rw(e),i;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(r.stack=yhe.create(),i=this._leakageMon.check(r.stack,this._size+1)),this._listeners?this._listeners instanceof Rw?(this._deliveryQueue??(this._deliveryQueue=new Ehe),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=A5(()=>{i==null||i(),this._removeListener(r)});return n instanceof rE?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*She<=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)||Tw;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 Rw)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}},Ehe=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}},ju=class Cg{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new Va,this.onChange=this._onChange.event;let t=new ihe;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=Cg.extractWidth(l);Cg.extractShouldJoin(l)&&(u-=Cg.extractWidth(r)),n+=u,r=l}return n}charProperties(t,n){return this._activeProvider.charProperties(t,n)}},iE=0,I5=-3,Sf=class{constructor(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}},Che=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 Sf,this.dtree=new Sf}},z5=new Sf,B5=new Sf,sE=new Uint8Array(30),oE=new Uint16Array(30),j5=new Uint8Array(30),F5=new Uint16Array(30),khe=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),E2=new Sf,uo=new Uint8Array(320);function $5(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 The(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 C2=new Uint16Array(16);function Aw(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)C2[i]=s,s+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[C2[t[n+i]]++]=i)}function Rhe(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function _o(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 BS(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 Ahe(e,t,n){var r,i,s,o,l,u;for(r=_o(e,5,257),i=_o(e,5,1),s=_o(e,4,4),o=0;o<19;++o)uo[o]=0;for(o=0;o<s;++o){var d=_o(e,3,0);uo[khe[o]]=d}for(Aw(E2,uo,0,19),l=0;l<r+i;){var h=BS(e,E2);switch(h){case 16:var p=uo[l-1];for(u=_o(e,2,3);u;--u)uo[l++]=p;break;case 17:for(u=_o(e,3,3);u;--u)uo[l++]=0;break;case 18:for(u=_o(e,7,11);u;--u)uo[l++]=0;break;default:uo[l++]=h;break}}Aw(t,uo,0,r),Aw(n,uo,r,i)}function k2(e,t,n){for(;;){var r=BS(e,t);if(r===256)return iE;if(r<256)e.dest[e.destLen++]=r;else{var i,s,o,l;for(r-=257,i=_o(e,sE[r],oE[r]),s=BS(e,n),o=e.destLen-_o(e,j5[s],F5[s]),l=o;l<o+i;++l)e.dest[e.destLen++]=e.dest[l]}}}function Nhe(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 I5;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,iE}function Mhe(e,t){var n=new Che(e,t),r,i,s;do{switch(r=Rhe(n),i=_o(n,2,0),i){case 0:s=Nhe(n);break;case 1:s=k2(n,z5,B5);break;case 2:Ahe(n,n.ltree,n.dtree),s=k2(n,n.ltree,n.dtree);break;default:s=I5}if(s!==iE)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}The(z5,B5);$5(sE,oE,4,3);$5(j5,F5,2,1);sE[28]=0;oE[28]=258;var T2=Mhe,aE=11,sc=5,Ohe=aE-sc,Dhe=65536>>aE,Phe=1<<Ohe,Lhe=Phe-1,kg=2,Ihe=1<<sc,Nw=Ihe-1,H5=65536>>sc,zhe=1024>>sc,Bhe=H5+zhe,jhe=Bhe,Fhe=32,$he=jhe+Fhe,Hhe=1<<kg,Uhe=new Uint8Array(new Uint32Array([305419896]).buffer)[0]===18,Whe=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=T2(e,new Uint8Array(n)),e=T2(e,new Uint8Array(n)),Uhe){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>>sc]<<kg)+(e&Nw),this.data[t]):e<=65535?(t=(this.data[H5+(e-55296>>sc)]<<kg)+(e&Nw),this.data[t]):e<this.highStart?(t=this.data[$he-Dhe+(e>>aE)],t=this.data[t+(e>>sc&Lhe)],t=(t<<kg)+(e&Nw),this.data[t]):this.data[this.data.length-Hhe]}},qhe=Whe,Vhe="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 Yhe(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 Khe=new qhe(Yhe(Vhe)),jS=15,FS=0,Ghe=48,Xhe=4,Zhe=0,U5=1,W5=2,$S=3,Qhe=4,Mw=5,Ow=6,Dw=7,R2=8,Pw=9,A2=10,Jhe=11,efe=32;function N2(e){return(e&Ghe)>>Xhe}function tfe(e,t){let n=(e&jS)>>FS,r=(t&jS)>>FS;return nfe(n,r)?r===$S?efe:r+16:r-16}function nfe(e,t){return e>=Mw&&e<=Pw&&(e==Mw&&(t==Mw||t==Ow||t==R2||t==Pw)||(e==R2||e==Ow)&&(t==Ow||t==Dw)||(e==Pw||e==Dw)&&t==Dw)||t==W5||t==A2||e==U5||t==Qhe||e==A2&&t==Jhe||t==$S&&e==$S}function M2(e){return Khe.get(e)}var q5=class V5{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 V5._plainNarrowProperties;let r=M2(t),i=N2(r),s=!1;if(i>=2?i=i===3||this.ambiguousCharsAreWide||t===65039?2:1:i=1,n!==0){let o=ju.extractWidth(n);this.handleGraphemes?r=tfe(ju.extractCharKind(n),r):r=i===0?1:0,s=r>0,s&&(o>i?i=o:r===32&&(i=2))}return ju.createPropertyValue(r,i,s)}wcwidth(t){let n=M2(t),r=N2(n),i=(n&jS)>>FS;return i===W5||i===U5?0:r>=2&&(r===3||this.ambiguousCharsAreWide)?2:1}};q5._plainNarrowProperties=ju.createPropertyValue(Zhe,1,!1);var O2=q5,rfe=class{constructor(){this._oldVersion=""}activate(e){this._provider15||(this._provider15=new O2(!1)),this._provider15Graphemes||(this._provider15Graphemes=new O2(!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 ife={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"},sfe={matchBackground:"#264F78",matchBorder:"#3B8EEA",matchOverviewRuler:"#3B8EEA",activeMatchBackground:"#7A4E00",activeMatchBorder:"#F5F543",activeMatchColorOverviewRuler:"#F5F543"};function ofe(e={}){return{scrollback:5e3,fontFamily:'"Sarasa Fixed SC", "Noto Sans Mono CJK SC", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace',fontSize:e.fontSize??Lg,cursorBlink:!0,cursorStyle:"block",cursorInactiveStyle:"none",disableStdin:!1,theme:ife,allowProposedApi:!0}}async function Y5(e,t={}){await document.fonts.ready;const n=new Ude(ofe(t)),r=new Kde,i=new the,s=new rfe;n.loadAddon(r),n.loadAddon(i),n.loadAddon(s),e.replaceChildren(),n.open(e);const o=()=>{n.refresh(0,n.rows-1)},l=()=>{document.visibilityState==="visible"&&n.refresh(0,n.rows-1)},u=()=>{n.refresh(0,n.rows-1)},d=()=>{n.refresh(0,n.rows-1)};return document.fonts.addEventListener("loadingdone",o),document.addEventListener("visibilitychange",l),window.addEventListener("pageshow",u),window.addEventListener("focus",d),{terminal:n,serializeAddon:r,dispose:()=>{document.fonts.removeEventListener("loadingdone",o),document.removeEventListener("visibilitychange",l),window.removeEventListener("pageshow",u),window.removeEventListener("focus",d),n.dispose()}}}function afe(e,t,n){return e.options.fontSize===t?!1:(e.options.fontSize=t,requestAnimationFrame(()=>n==null?void 0:n()),!0)}const K5=28,G5=14;function Xm(e,t,n){const r=Math.min(1,Math.max(0,1-e/t));return Math.ceil(n*r)}function X5({pointerX:e,pointerY:t,rect:n,scrollLeft:r,scrollTop:i,scrollWidth:s,scrollHeight:o,clientWidth:l,clientHeight:u,edgePx:d=K5,maxSpeedPx:h=G5}){let p=0;const y=e-n.left,g=n.right-e;if(y<d&&r>0)p=-Xm(y,d,h);else if(g<d){const E=Math.max(0,s-l);r<E&&(p=Xm(g,d,h))}let b=0;const w=t-n.top,x=n.bottom-t;if(w<d&&i>0)b=-Xm(w,d,h);else if(x<d){const E=Math.max(0,o-u);i<E&&(b=Xm(x,d,h))}return{dx:p,dy:b}}const lfe=K5,cfe=G5;function ufe(e){var N,$,P,q;const{container:t,host:n,edgePx:r=lfe,maxSpeedPx:i=cfe,onHorizontalScrollIntent:s,requestFrame:o=H=>requestAnimationFrame(H),cancelFrame:l=H=>cancelAnimationFrame(H)}=e;let u=!1,d=0,h=0,p=null,y=0,g="unknown",b=null,w=null,x=null;const E=()=>{if(x&&x.isConnected)return x;const H=n.querySelector(".xterm-screen");return x=H??n,g=H?"xterm-screen":"host",x},k=()=>{u=!1,p!==null&&(l(p),p=null)},T=()=>{if(p=null,!u)return;const H=t.getBoundingClientRect(),{dx:U,dy:O}=X5({pointerX:d,pointerY:h,rect:H,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:r,maxSpeedPx:i});U!==0&&(s==null||s(`dragSelectAutoscroll dx=${Math.round(U)}`),t.scrollLeft+=U),O!==0&&(t.scrollTop+=O),(U!==0||O!==0)&&(E().dispatchEvent(new MouseEvent("mousemove",{clientX:d,clientY:h,bubbles:!0,cancelable:!0})),y+=1,b={dx:U,dy:O},w=Date.now()),p=o(T)},R=H=>{H.pointerType==="mouse"&&H.button===0&&(u=!0,d=H.clientX,h=H.clientY,p===null&&(p=o(T)))},z=H=>{u&&(d=H.clientX,h=H.clientY)};return t.addEventListener("pointerdown",R),(N=globalThis.addEventListener)==null||N.call(globalThis,"pointermove",z),($=globalThis.addEventListener)==null||$.call(globalThis,"pointerup",k),(P=globalThis.addEventListener)==null||P.call(globalThis,"pointercancel",k),(q=globalThis.addEventListener)==null||q.call(globalThis,"blur",k),{dispose(){var H,U,O,M;k(),t.removeEventListener("pointerdown",R),(H=globalThis.removeEventListener)==null||H.call(globalThis,"pointermove",z),(U=globalThis.removeEventListener)==null||U.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:g,lastScrollDelta:b,lastDispatchedAt:w}}}}const dfe=16,hfe=16,ffe=16;function Z5(e){const t=Array.from(e);return t.length!==1?!1:/^[\p{P}\p{S}]$/u.test(t[0])}function pfe(e){if(e.length!==1)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function mfe(e){for(const t of e){const n=t.codePointAt(0);if(n!==void 0&&n>127)return!0}return!1}function gfe(e,t){return t.physicalKeyboardMode!==!0||e.length===0?!1:e===" "||mfe(e)?!0:Array.from(e).every(Z5)}function vfe(e,t={}){return e.type!=="keydown"||e.ctrlKey||e.metaKey||e.altKey||e.isComposing||t.imeComposing?!1:Z5(e.key)||t.physicalKeyboardMode===!0&&(e.key===" "||pfe(e.key))}function yfe(e){return e.type!=="keydown"||!e.ctrlKey||e.metaKey||e.altKey||e.shiftKey?!1:e.key===" "||e.key==="Spacebar"||e.code==="Space"}function _fe(e){return e.type!=="keydown"?!1:e.metaKey}function Q5(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 J5(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 bfe(){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 wfe(e){const t=Q5(e),n=bfe();return e.setAttribute("autocapitalize","off"),e.setAttribute("autocomplete","off"),e.setAttribute("autocorrect","off"),e.spellcheck=!1,n&&(e.style.colorScheme=n),()=>J5(e,t)}function Sfe(e){const t=Q5(e);return e.setAttribute("enterkeyhint","send"),()=>{J5(e,t)}}function xfe(e,t,n={}){var L,D,Y,K;let r,i,s,o=!1,l;const u=()=>{var F;return((F=n.isPhysicalKeyboardMode)==null?void 0:F.call(n))??n.physicalKeyboardMode===!0},d=()=>{var F;return((F=n.getPlainEnterBehavior)==null?void 0:F.call(n))??n.plainEnterBehavior??"submit"},h=e.textarea?wfe(e.textarea):void 0,p=u()&&e.textarea?Sfe(e.textarea):void 0,y=()=>{const F=e.textarea;!F||l||(l=setTimeout(()=>{l=void 0,o||(F.value="")},0))},g=F=>{var A;if(n.isInputEnabled&&!n.isInputEnabled()){y();return}Ks(t,F),(A=n.onRawInput)==null||A.call(n,F),y()},b=F=>{g(F)},w=()=>{i&&(clearTimeout(i.timer),i=void 0)},x=()=>{s&&(clearTimeout(s.timer),s=void 0)},E=F=>{if(x(),!F)return;const A={data:F,timer:setTimeout(()=>{s===A&&(s=void 0)},ffe)};s=A},k=F=>{E(`${(s==null?void 0:s.data)??""}${F}`)},T=F=>!s||!F||!s.data.startsWith(F)?!1:(E(s.data.slice(F.length)),!0),R=(F,A)=>{w();const W={data:F,keydownText:A,timer:setTimeout(()=>{i===W&&(i=void 0)},hfe)};i=W},z=(F,A)=>{const W=F.startsWith(A.data)?A.data:F.startsWith(A.keydownText)?A.keydownText:"";return W?F.slice(W.length):F},N=(F,A,W)=>z(F,{data:W,keydownText:A.keydownText}),$=(F,A)=>{let W=!1;for(const G of F.bufferedXtermData){let B=G;if(!W){const ne=N(G,F,A);ne!==G&&(B=ne,W=!0)}B&&b(B)}},P=F=>{const A=r;A&&(r=void 0,clearTimeout(A.timer),g(F),R(F,A.keydownText),$(A,F))},q=F=>{r&&P(r.keydownText),w();const A={bufferedXtermData:[],keydownText:F,timer:setTimeout(()=>{r===A&&P(F)},dfe)};r=A},H=F=>gfe(F,{physicalKeyboardMode:u()})?T(F)?(y(),!0):(g(F),R(F,F),!0):!1,U=F=>{const A=F,W=A.data??"";if(!A.isComposing&&r&&W){P(W);return}A.isComposing||A.inputType!=="insertText"&&A.inputType!=="insertCompositionText"||H(W)},O=()=>{o=!0,l&&(clearTimeout(l),l=void 0);const F=e.textarea;F&&(F.value="")},M=F=>{o=!1,r&&F.data&&P(F.data)},I=e.onData(F=>{if(r){r.bufferedXtermData.push(F);return}if(i){const A=z(F,i);w(),A&&b(A);return}b(F),k(F)});return(L=e.textarea)==null||L.addEventListener("input",U),(D=e.textarea)==null||D.addEventListener("compositionstart",O,!0),(Y=e.textarea)==null||Y.addEventListener("compositionend",M),(K=e.attachCustomKeyEventHandler)==null||K.call(e,F=>u()&&(yfe(F)||_fe(F))?!1:vfe(F,{physicalKeyboardMode:u(),imeComposing:o})?(q(F.key),!1):F.type!=="keydown"||F.key!=="Enter"?!0:d()==="linefeed"!==F.shiftKey?(g(`
632
- `),F.preventDefault(),!1):!0),{dispose:()=>{var F,A,W;I.dispose(),(F=e.textarea)==null||F.removeEventListener("input",U),(A=e.textarea)==null||A.removeEventListener("compositionstart",O,!0),(W=e.textarea)==null||W.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 ry(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 Efe(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 Cfe(e,t,n,r,i={}){if(e<=0||t<=0||n<=0||r<=0)return null;const s=Math.floor(t/r),o=t-s*r,l=s+(o>=r*.75?1:0);return{cols:Math.max(i.minCols??20,Math.floor(e/n)),rows:Math.max(i.minRows??8,l)}}function kfe(e){const t=getComputedStyle(e);return{width:Math.max(0,e.clientWidth-Ii(t.paddingLeft)-Ii(t.paddingRight)),height:Math.max(0,e.clientHeight-Ii(t.paddingTop)-Ii(t.paddingBottom))}}function Tfe(e){const{container:t,term:n,onResize:r,onRelayout:i,preserveRows:s,minCols:o,minRows:l}=e;let u=!1,d=null;const h=()=>{if(d=null,u)return;const w=kfe(t),x=n.element;if(!x)return;const E=ry(x,n);if(!E)return;const k=Cfe(w.width,w.height,E.cellW,E.cellH,{minCols:o,minRows:l});if(!k)return;const T=s!=null&&s()?n.rows:k.rows;k.cols===n.cols&&T===n.rows||(n.resize(k.cols,T),r(k.cols,T),requestAnimationFrame(()=>{u||i==null||i()}))},p=()=>{d===null&&(d=requestAnimationFrame(h))};p();const y=new ResizeObserver(p);y.observe(t);const g=p;window.addEventListener("resize",g);const b=window.visualViewport;return b==null||b.addEventListener("resize",g),{dispose:()=>{u=!0,d!==null&&cancelAnimationFrame(d),y.disconnect(),window.removeEventListener("resize",g),b==null||b.removeEventListener("resize",g)}}}function e4(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,g=y+n-i,b=y+p*e.cellH-(i-e.cellH)/2;return{spacerHeight:Math.max(y,Math.min(g,b))+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 lE(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,g=Math.max(0,e.bufferLength-e.rows)*e.cellH;h=Math.max(g,Math.min(o,p))}else d=e.containerScrollTop+e.containerClientHeight>=e.containerScrollHeight-e.atBottomThreshold,h=o;return{isAtBottom:d,bottomScrollTop:h,cursorInViewport:s}}function t4(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 D2(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 Rfe(e,t){return t<=0?0:Math.max(0,e)*t}function Afe(){return{intent:!1,lastUserInputAt:null,unmarkedOriginLeft:null,lastSeenLeft:0,pendingFollowLeft:null}}function Nfe(e,t){return{...e,intent:t,unmarkedOriginLeft:t?e.unmarkedOriginLeft:null}}function Tg(e,t){return{state:{...Nfe(e,!1),lastUserInputAt:null,pendingFollowLeft:null,...t.scrollLeft!==void 0?{lastSeenLeft:t.scrollLeft}:{}},trace:e.intent?{kind:"clear",details:t.details}:null}}function Mfe(e,t){return{state:{...e,intent:!0,lastUserInputAt:t.now,unmarkedOriginLeft:null},trace:e.intent?null:{kind:"set",details:t.details}}}function Ofe(e,t){return{...e,pendingFollowLeft:t}}function Dfe(e,t){if(!t.hasOverflow)return{...Tg(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 Pfe({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 Lfe(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 Ife(e){return!(e.bottomScrollTop<e.domMaxScrollTop-1)||e.rawScrollTop<=e.bottomScrollTop+1?{action:"keep",scrollTop:e.rawScrollTop}:{action:"clamp",scrollTop:e.bottomScrollTop}}function zfe({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),g=t.onRender(d),b=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(),g.dispose(),b==null||b.dispose(),w.disconnect()}}}function Bfe({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:g}){var N,$;let b=null,w=null;const x=()=>{var I;const P=document.activeElement;if(!P)return null;const q=P.getAttribute("aria-label")??"",H=P.tagName,U=typeof P.closest=="function"?((I=P.closest("[data-slot]"))==null?void 0:I.getAttribute("data-slot"))??"":"",O=P.id?`#${P.id}`:"",M=typeof P.className=="string"&&P.className?"."+P.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";return q?`${q}|${H}${O}${M}{${U}}`:`${H}${O}${M}{${U}}`},E=(P,q={})=>{if(!lw())return;const H=e.getBoundingClientRect(),U=t.getBoundingClientRect(),O=window.visualViewport,{cellH:M,cellW:I}=i(),{paddingTop:L,paddingBottom:D}=s(),Y=Math.max(0,e.clientHeight-L-D),K=n.buffer.active,F=K.baseY+K.cursorY,A=lE({rows:n.rows,cellH:M,bufferLength:K.length,cursorBufferRow:F,visibleContentHeight:Y,paddingTop:L,paddingBottom:D,containerScrollTop:e.scrollTop,containerScrollHeight:e.scrollHeight,containerClientHeight:e.clientHeight,atBottomThreshold:r}),W=o(),G=W===null?null:F-W,B=q.cursorDeltaRows!==void 0?q.cursorDeltaRows:G,ne=q.scrollDeltaToAnchor!==void 0?q.scrollDeltaToAnchor:e.scrollTop-A.bottomScrollTop,ie=Ii(t.style.top),se=M>0?t4({ydisp:K.viewportY,rows:n.rows,cellH:M,visibleContentHeight:Y}):0,te=Ii(t.style.height),he=e.scrollTop,ge=he+e.clientHeight,Ee=ie+te,Re=Math.max(0,Math.min(ge,Ee)-Math.max(he,ie)),Ie=y();Aae({t:performance.now(),event:P,scope:q.scope,action:q.action,reason:q.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:H.top,containerBottom:H.bottom,hostRectTop:U.top,hostRectBottom:U.bottom,viewportY:K.viewportY,bufferLength:K.length,hostTop:t.style.top,cellH:M,cellW:I,cursorX:K.cursorX,cursorY:K.cursorY,cursorBufferRow:F,cursorDeltaRows:B,cursorInViewport:A.cursorInViewport,anchorBottomScrollTop:A.bottomScrollTop,scrollDeltaToAnchor:ne,pendingProgrammaticScrollTop:l(),pendingFollowCursorScrollTop:u(),pendingFollowCursorScrollLeft:d(),pendingContainerSyncRetry:h(),horizontalIntent:p(),intentMode:Ie.mode,intentSource:Ie.source,intentTransition:Ie.lastTransitionId,prevCursorBufferRow:W,hostTopDrift:ie-se,viewportHostCoverage:e.clientHeight>0?Re/e.clientHeight:0,focus:x(),atBottom:A.isAtBottom,touchActive:Ie.touchActive,userIntent:g(),...q})},k=P=>{if(!lw())return;const q=window.visualViewport;if(!q)return;const H=b===null?0:q.height-b,U=w===null?0:q.offsetTop-w;b=q.height,w=q.offsetTop,E(P,{vvHeightDelta:H,vvOffsetDelta:U})},T=()=>k("vv:resize"),R=()=>k("vv:scroll"),z=P=>{var I;if(!lw())return;const q=P.target,H=q===e||q instanceof Node&&e.contains(q),U=q&&typeof q.closest=="function"?((I=q.closest("[data-slot]"))==null?void 0:I.getAttribute("data-slot"))??"":"",O=(q==null?void 0:q.tagName)??"",M=q&&typeof q.className=="string"&&q.className?"."+q.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";E(`wheel:window deltaY=${Math.round(P.deltaY)} reachesContainer=${H?1:0} prevented=${P.defaultPrevented?1:0} target=${O}${M}{${U}}`)};return(N=window.visualViewport)==null||N.addEventListener("resize",T),($=window.visualViewport)==null||$.addEventListener("scroll",R),window.addEventListener("wheel",z,{passive:!0,capture:!0}),{trace:E,dispose:()=>{var P,q;(P=window.visualViewport)==null||P.removeEventListener("resize",T),(q=window.visualViewport)==null||q.removeEventListener("scroll",R),window.removeEventListener("wheel",z,{capture:!0})}}}function n4(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 Lw=e=>e.mode==="reviewing",_h=e=>e.mode==="following";function jfe(e,t){return e==="following"&&t==="reviewing"?"set":e==="reviewing"&&t==="following"?"clear":"keep"}function Kr(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:jfe(e.mode,t.mode),reason:n}}}function bh(e,t,n,r){return{...e,mode:"reviewing",source:t,lastScrollTop:n,lastTransitionId:r}}function Iw(e,t,n,r){return{...e,mode:"following",source:t,lastScrollTop:n,lastTransitionId:r}}function Ffe(e){throw new Error(`Unhandled PTY vertical intent event: ${JSON.stringify(e)}`)}function $fe(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)?Kr(e,{...o,mode:"following",source:"none",lastTransitionId:`${r}.bottom-down`},`scrollTop=${t.scrollTop} atBottom=true`):Kr(e,{...o,lastTransitionId:`${r}.not-bottom`},`scrollTop=${t.scrollTop} atBottom=${t.atCursorAwareBottom}`)}function Hfe(e,t,n={}){const r=n.atBottomThreshold??8;switch(t.type){case"attach":{const i=n4({initialIntent:t.initialIntent,scrollTop:t.scrollTop});return Kr(e,i,`initialIntent=${t.initialIntent}`)}case"scroll-to-bottom":return t.force?Kr(e,Iw({...e,touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1},"programmatic-bottom",e.lastScrollTop,"bottom.force"),`reason=${t.reason} force=true`):Kr(e,{...e,lastTransitionId:`bottom.passive.${e.mode}`},`reason=${t.reason} force=false`);case"scroll-to-ratio":return Kr(e,bh(e,"ratio-scroll",t.scrollTop,"ratio.reviewing"),`ratio=${t.ratio}`);case"wheel":return t.nextScrollTop===t.previousScrollTop?Kr(e,{...e,lastTransitionId:"wheel.clamped",lastScrollTop:t.nextScrollTop},`delta=${t.deltaY}`):t.deltaY<0?Kr(e,bh(e,"wheel",t.nextScrollTop,"wheel.up"),`delta=${t.deltaY}`):t.deltaY>0&&t.reachedCursorAwareBottom?Kr(e,Iw(e,"none",t.nextScrollTop,"wheel.down.bottom"),`delta=${t.deltaY}`):Kr(e,bh(e,"wheel",t.nextScrollTop,"wheel.down.not-bottom"),`delta=${t.deltaY}`);case"container-scroll":return t.source!=="user"?Kr(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?Kr(e,Iw(e,"none",t.scrollTop,"container.user.bottom-down"),`delta=${t.verticalDelta} threshold=${r}`):Kr(e,{...e,lastScrollTop:t.scrollTop,lastTransitionId:"container.user.bottom-small-delta"},`delta=${t.verticalDelta} threshold=${r}`):Kr(e,bh(e,"native-scroll",t.scrollTop,"container.user.away"),`scrollTop=${t.scrollTop} atBottom=false`);case"touch-start":return Kr(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?Kr(e,{...bh(e,"touch",e.lastScrollTop,"touch.move.review"),touchReviewNotified:!0},`movement=${i} threshold=${t.reviewThresholdPx}`,!0):i>=t.reviewThresholdPx?Kr(e,{...e,lastTransitionId:"touch.move.reviewing"},`movement=${i} threshold=${t.reviewThresholdPx}`):Kr(e,{...e,lastTransitionId:"touch.move.below-threshold"},`movement=${i} threshold=${t.reviewThresholdPx}`)}case"touch-end":case"touch-cancel":return $fe(e,t,r);default:return Ffe(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 Ufe({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 Wfe({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 qfe({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 Vfe({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 Yfe({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 Kfe(){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 Gfe(){return{startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,lastGestureAt:null,lastHorizontalGestureAt:null,gestureMode:null}}function Xfe(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 Zfe(e,t){return{...e,lastGestureAt:t}}function P2(e,t){return{...e,lastHorizontalGestureAt:t}}function Qfe(e,t){return{...e,lastClientY:t.currentY,lastGestureAt:t.now}}function Jfe(e,t){return!t.touchActive||e.gestureMode!==null||t.currentY===null?e:{...e,gestureMode:"pending"}}function L2(e,t){return e.gestureMode===t?e:{...e,gestureMode:t}}function epe(e){return{...e,startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,gestureMode:null}}function tpe({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:g}){let b=Gfe();const w=P=>{const q=P??b.lastClientY,H=o(),U=Math.max(0,e.scrollHeight-e.clientHeight),O=i();return qfe({touchActive:O.touchActive,touchStartScrollTop:O.touchStartScrollTop,touchStartY:O.touchStartY,currentY:q,touchStartedAtCursorAwareBottom:b.startedAtCursorAwareBottom,bottomScrollTop:H.bottomScrollTop,domMaxScrollTop:U})},x=(P,q)=>Wfe({startX:b.startClientX,startY:i().touchStartY,currentX:P,currentY:q}),E=P=>{const q=Math.max(0,e.scrollWidth-e.clientWidth);return Vfe({touchActive:i().touchActive,touchStartClientX:b.startClientX,touchStartScrollLeft:b.startScrollLeft,currentX:P,maxScrollLeft:q})},k=(P,q,H,U,O)=>P?[`raw=${Math.round(q)}`,`effective=${Math.round(H)}`,`prev=${Math.round(U)}`,`delta=${Math.round(O)}`,`expected=${Math.round(P.expectedScrollTop)}`,`startScroll=${Math.round(P.touchStartScrollTop)}`,`base=${Math.round(P.gestureBaseScrollTop)}`,`startY=${Math.round(P.touchStartY)}`,`currentY=${Math.round(P.currentY)}`,`touchDeltaY=${Math.round(P.touchDeltaY)}`,`max=${Math.round(P.cursorAwareMaxScrollTop)}`].join(" "):null,T=P=>{var M;if(r()){n("touchstart:page-resume-pending");return}const q=((M=P.touches)==null?void 0:M[0])??null,H=(q==null?void 0:q.clientX)??null,U=(q==null?void 0:q.clientY)??null;d("touchstart");const O=o();b=Xfe(b,{startedAtCursorAwareBottom:O.isAtBottom,startClientX:H,startClientY:U,startScrollLeft:e.scrollLeft,now:performance.now()}),s({type:"touch-start",clientY:U,scrollTop:e.scrollTop}),n("touchstart",{details:[`startX=${H??"null"}`,`startY=${U??"null"}`,`startScroll=${Math.round(e.scrollTop)}`,`bottom=${Math.round(O.bottomScrollTop)}`,`atBottom=${O.isAtBottom?1:0}`].join(" ")})},R=P=>{var K;if(r()){n("touchmove:page-resume-pending");return}const q=((K=P.touches)==null?void 0:K[0])??null,H=(q==null?void 0:q.clientX)??null,U=(q==null?void 0:q.clientY)??null,O=performance.now();b=Qfe(b,{currentY:U,now:O});const M=x(H,U);n("touchmove",{details:U===null?"currentY=null":k(w(U),e.scrollTop,e.scrollTop,l(),e.scrollTop-l())??[`mode=${b.gestureMode??"none"}`,`currentY=${Math.round(U)}`,M?`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`:null].filter(Boolean).join(" ")});const I=u();if(I||d("touchmove"),b=Jfe(b,{touchActive:i().touchActive,currentY:U}),b.gestureMode==="pending"&&M){const F=I&&M.absDx>=hi.touch.horizontalGestureSlopPx&&M.absDx>M.absDy*hi.touch.horizontalLockRatio,A=M.absDy>=hi.touch.gestureSlopPx&&(!I||M.absDy>M.absDx*hi.touch.verticalLockRatio);if(F)b=L2(b,"horizontal"),b=P2(b,O),n("touchmove:horizontal-lock",{details:`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`});else if(A)b=L2(b,"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:U,reviewThresholdPx:hi.touch.gestureSlopPx});return}}if(b.gestureMode==="horizontal"){const F=E(H);if(!I||!F){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&&(b=P2(b,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(F.expectedScrollLeft)}`,`startScrollLeft=${Math.round(F.touchStartScrollLeft)}`,`startX=${Math.round(F.touchStartX)}`,`currentX=${Math.round(F.currentX)}`,`touchDeltaX=${Math.round(F.touchDeltaX)}`,`max=${Math.round(F.maxScrollLeft)}`].join(" ")});return}if(b.gestureMode!=="vertical")return;const L=w(U);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&&b.startedAtCursorAwareBottom&&L.expectedScrollTop>=L.cursorAwareMaxScrollTop-t&&U!==null&&U<=L.touchStartY){n("touchmove:bottom-boundary-follow");return}s({type:"touch-move",clientY:U,reviewThresholdPx:hi.touch.gestureSlopPx}).notifyTouchReviewStart&&(p==null||p(),n("touchmove:review"))},z=P=>{const q=e.scrollTop,H=o(),U=Yfe({touchStartScrollTop:i().touchStartScrollTop,liveScrollTop:q,atBottomThreshold:t,touchStartedAtCursorAwareBottom:b.startedAtCursorAwareBottom,anchorIsAtBottom:H.isAtBottom,reviewedDuringTouch:i().touchReviewNotified});b=epe(b),s({type:P,scrollTop:q,atCursorAwareBottom:U.atCursorAwareBottomForIntent,releaseOnSemanticBottom:U.releaseOnSemanticBottom}),b=Zfe(b,performance.now()),g(),y()};return{onTouchStart:T,onTouchMove:R,onTouchEnd:()=>{if(r()){n("touchend:page-resume-pending");return}z("touch-end"),n("touchend")},onTouchCancel:()=>{if(r()){n("touchcancel:page-resume-pending");return}z("touch-cancel"),n("touchcancel")},isRecentNativeScroll:()=>i().touchActive||b.lastGestureAt!==null&&performance.now()-b.lastGestureAt<=hi.touch.nativeScrollRecentMs,isRecentHorizontalGesture:()=>b.lastHorizontalGestureAt!==null&&performance.now()-b.lastHorizontalGestureAt<=hi.touch.nativeScrollRecentMs,getScrollExpectation:w,describeScrollExpectation:k,getState:()=>b}}function npe(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:g,onTouchBoundaryPrevent:b,atBottomThreshold:w=hi.bottom.defaultThresholdPx}=e,x=()=>ry(r,i)??{cellH:0,cellW:0},E=()=>{const Q=getComputedStyle(t);return{paddingTop:Ii(Q.paddingTop),paddingBottom:Ii(Q.paddingBottom)}},k=Kfe(),T=(Q,V,Z)=>{k.set(Q,V,Z)},R={external:!1,internal:!1};let z=null,N="",$=n4({initialIntent:p,scrollTop:t.scrollTop}),P=null,q=null,H=!1,U=null,O=Afe(),M=0,I=!1,L=null,D=null,Y=null,K=null;const F=()=>Lw($),A=Bfe({container:t,host:r,term:i,atBottomThreshold:w,getDims:x,getVerticalInsets:E,getPrevCursorBufferRow:()=>L,getPendingProgrammaticScrollTop:()=>P,getPendingFollowCursorScrollTop:()=>U,getPendingFollowCursorScrollLeft:()=>O.pendingFollowLeft,getPendingContainerSyncRetry:()=>H,getHorizontalIntent:()=>O.intent,getVerticalIntent:()=>$,getUserHasVerticalScrollIntent:()=>F()}),W=A.trace,G=Q=>{if(Q){if(Q.kind==="ignore"){W("horizontal-intent:ignore",{details:Q.details});return}W(`horizontal-intent:${Q.kind}`,{details:Q.details})}},B=()=>t.scrollWidth>t.clientWidth+w,ne=Q=>{if(B())return!1;const V=Tg(O,{details:`site=${Q} reason=not-scrollable scrollWidth=${t.scrollWidth} clientWidth=${t.clientWidth}`,scrollLeft:t.scrollLeft});return O=V.state,G(V.trace),t.scrollLeft!==0&&(t.scrollLeft=0,O={...O,lastSeenLeft:0}),!0},ie=Q=>{if(!B()){ne("markHorizontalUserInput");return}const V=Mfe(O,{now:performance.now(),details:Q});O=V.state,G(V.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+w,horizontalScrollable:B()}),te=()=>{if(!h)return;const Q=se(),V=[Q.scrollTop,Q.scrollLeft,Q.scrollHeight,Q.scrollWidth,Q.clientHeight,Q.clientWidth,Q.scrollable,Q.horizontalScrollable].join(":");V!==N&&(N=V,h(Q))},he=()=>{const{cellH:Q}=x(),{paddingTop:V,paddingBottom:Z}=E(),ee=i.buffer.active;return lE({rows:i.rows,cellH:Q,bufferLength:ee.length,cursorBufferRow:ee.baseY+ee.cursorY,visibleContentHeight:Math.max(0,t.clientHeight-V-Z),paddingTop:V,paddingBottom:Z,containerScrollTop:t.scrollTop,containerScrollHeight:t.scrollHeight,containerClientHeight:t.clientHeight,atBottomThreshold:w})},ge=()=>{const Q=he().isAtBottom;z!==Q&&(z=Q,d==null||d(Q))},Ee=()=>{ge(),te()},Re=()=>$.touchActive,Ie=()=>{Y!==null&&(K==null||K(Y),Y=null,K=null)},Ye=()=>{if(Y!==null)return;const Q=()=>{Y=null,K=null,Ee()};if(typeof window.requestAnimationFrame=="function"){Y=window.requestAnimationFrame(Q),K=typeof window.cancelAnimationFrame=="function"?V=>window.cancelAnimationFrame(V):null;return}Y=window.setTimeout(Q,16),K=V=>window.clearTimeout(V)},gt=()=>{Y!==null&&(Ie(),Ee())},Me=(Q="rawInput")=>{D=performance.now(),W(`rawInputFollow:scheduled[${Q}]`)},de=()=>{D=performance.now(),W("rawInputFollow:fire")},oe=Q=>{const V=Lw($),Z=Hfe($,Q,{atBottomThreshold:w});$=Z.state,Z.trace&&W(`intent:${Z.trace.action}`,{details:`id=${Z.trace.id} reason=${Z.trace.reason}`});const ee=Lw($);return V!==ee&&(y==null||y(ee)),Z.notifyTouchReviewStart&&(g==null||g()),Z},ye=(Q,V,Z)=>{if(V<=0)return;const ee=Z??(()=>{const{paddingTop:Pe,paddingBottom:qe}=E();return Math.max(0,t.clientHeight-Pe-qe)})(),fe=t4({ydisp:Q,rows:i.rows,cellH:V,visibleContentHeight:ee}),ke=r.style.top,Be=`${fe}px`;T(r,"position","absolute"),T(r,"left","0px"),T(r,"top",Be),ke!==Be&&W("host-position",{ydisp:Q,details:`${ke||"0px"}->${Be}`})},we=(Q="internal",V={})=>{const Z=Math.max(0,i.buffer.active.length-i.rows),ee=he(),fe=Lfe({force:V.force??!1,reviewing:F(),viewportY:i.buffer.active.viewportY,expectedYdisp:Z,scrollTop:t.scrollTop,bottomScrollTop:ee.bottomScrollTop,atBottom:ee.isAtBottom}).action;if(fe==="blocked-by-review")return;if(fe==="noop"){H=!1;return}W(`scroll-to-bottom:start[${Q}]`),oe({type:"scroll-to-bottom",force:V.force??!1,reason:Q});const ke=Math.max(0,i.buffer.active.length-i.rows);R.internal=!0;try{i.scrollToLine(ke)}finally{R.internal=!1}const{cellH:Be}=x();Be!==0&&ye(ke,Be);const Pe=he().bottomScrollTop;t.scrollTop=Pe,P=Pe,L=i.buffer.active.baseY+i.buffer.active.cursorY,Ee(),H=!1,W("scroll-to-bottom:end",{ydisp:ke})},Qe=()=>{I=!0,W("page-resume:prepare-follow"),F()&&oe({type:"scroll-to-bottom",force:!0,reason:"pageResumePrepare"})},pt=()=>{Qe(),Wt(),we("pageResume",{force:!0}),I=!1},mt=Q=>{W("scroll-to-ratio:start");const V=Math.max(0,t.scrollHeight-t.clientHeight),Z=Math.max(0,Math.min(1,Q)),ee=V*Z;oe({type:"scroll-to-ratio",ratio:Z,scrollTop:ee}),t.scrollTop=ee,Dt()},ct=Q=>{if(Q===0)return;W("wheel");const V=Math.max(0,t.scrollHeight-t.clientHeight),Z=Math.min(V,he().bottomScrollTop);if(Z<=0){W("wheel:max-zero");return}const ee=t.scrollTop,fe=Math.max(0,Math.min(Z,ee+Q));if(fe===ee){W("wheel:clamped"),Ee();return}t.scrollTop=fe,M=fe,Dt(),oe({type:"wheel",deltaY:Q,previousScrollTop:ee,nextScrollTop:fe,reachedCursorAwareBottom:fe>ee&&fe>=Z-w&&he().isAtBottom})},dt=Q=>{if(!B()){ne("scrollToXRatio"),Ee();return}const V=Math.max(0,t.scrollWidth-t.clientWidth),Z=Math.max(0,Math.min(1,Q));t.scrollLeft=V*Z,ie(`site=scrollToXRatio ratio=${Z}`),O={...O,lastSeenLeft:t.scrollLeft},Ee()},At=(Q="external")=>{const V=t.scrollLeft,Z=Tg(O,{details:`site=resetHorizontalScroll reason=${Q}`,scrollLeft:0});O=Z.state,G(Z.trace),V!==0&&(t.scrollLeft=0),W(`horizontal-scroll-reset[${Q}]`,{details:`scrollLeft=${V}->${t.scrollLeft}`}),Ee()},me=(Q="external")=>{ie(`site=${Q}`)};let Oe=0,it=null,tt=-1;const Je=()=>{const Q=i.buffer.active,V=`${Oe}:${Q.viewportY}:${Q.length}:${i.rows}`;return V===it||(tt=Efe(Q,i.rows),it=V),tt},Wt=()=>{const{cellH:Q,cellW:V}=x();if(Q===0||V===0)return;const{paddingTop:Z,paddingBottom:ee}=E(),fe=Math.max(0,t.clientHeight-Z-ee),ke=i.buffer.active,Be=Je(),Pe=e4({bufferLength:ke.length,rows:i.rows,cols:i.cols,viewportY:ke.viewportY,cursorY:ke.cursorY,cellH:Q,cellW:V,visibleContentHeight:fe},Be);Pe&&(T(n,"overflow","hidden"),T(n,"height",`${Pe.spacerHeight}px`),T(n,"width",`${Pe.spacerWidth}px`),T(r,"width",`${Pe.hostWidth}px`),T(r,"height",`${Pe.hostHeight}px`),T(r,"paddingTop",`${Pe.hostPaddingTop}px`),q=performance.now(),ye(ke.viewportY,Q,fe))},nn=(Q,V,Z={})=>{if(Q===i.buffer.active.viewportY){Z.deferHostUntilRender||ye(Q,V);return}R.internal=!0;try{if(Z.deferHostUntilRender){i.scrollToLine(Q);return}ye(Q,V),i.scrollToLine(Q)}finally{R.internal=!1}},Qt=()=>s()?(o(),_h($)?(we("pendingFrame"),"followed"):(l()||u(!0),"marked")):"none",Kt=(Q,V)=>{const Z=i.buffer.active;return D2(Q,{bufferLength:Z.length,rows:i.rows,cols:i.cols,viewportY:Z.viewportY,cellH:V}).ydisp},Dt=(Q={})=>{Ie(),W("container-sync:start");const{cellH:V}=x();if(V===0){H=!0;return}H=!1;const Z=Kt(t.scrollTop,V);nn(Z,V,{deferHostUntilRender:Q.deferHostUntilRender??Re()}),Ee(),W("container-sync:end",{ydisp:Z})},zt=()=>$.touchActive||_n.isRecentNativeScroll(),Mn=Q=>{if(!zt())return!1;const{cellH:V}=x();if(V===0)return!1;const Z=Kt(Q,V);return Z!==i.buffer.active.viewportY?!1:(Ye(),W("container-sync:skip[same-row-touch]",{ydisp:Z,details:`scrollTop=${Math.round(Q)} viewportY=${i.buffer.active.viewportY}`}),!0)},pn=Q=>{const V=Math.max(0,t.scrollHeight-t.clientHeight),Z=he(),ee=Ife({rawScrollTop:Q,bottomScrollTop:Z.bottomScrollTop,domMaxScrollTop:V});return ee.action==="keep"||(W("container-scroll:clamp-cursor-bottom",{details:`prev=${Q} next=${ee.scrollTop} domMax=${V}`}),t.scrollTop=ee.scrollTop,P=null,U=null),ee.scrollTop},_n=tpe({container:t,atBottomThreshold:w,trace:W,getPageResumePending:()=>I,getVerticalIntent:()=>$,dispatchVerticalIntent:oe,getCurrentAnchor:he,getLastSeenScrollTop:()=>M,hasHorizontalOverflow:B,clearHorizontalIntentIfUnscrollable:ne,markHorizontalUserInput:ie,onTouchBoundaryPrevent:b,notifyAtBottom:ge,flushPendingTouchScrollNotify:gt}),Ue=()=>O.intent?_n.getState().gestureMode==="horizontal"||_n.isRecentHorizontalGesture():!1,Ge=Q=>{const V=_n.getScrollExpectation();if(!V)return!1;const{touchStartScrollTop:Z,touchStartY:ee,currentY:fe,gestureBaseScrollTop:ke,expectedScrollTop:Be}=V,Pe=Math.abs(fe-ee)>.5,qe=Q<=w&&ke>t.clientHeight,st=parseFloat(r.style.top||"0"),lt=he(),xe=_n.getState().startedAtCursorAwareBottom&&Number.isFinite(st)&&Math.abs(Q-st)<=w&&Math.abs(lt.bottomScrollTop-st)<=t.clientHeight+w&&Math.abs(Be-Q)>hi.touch.hostTopJumpMinThresholdPx;if(!Pe&&!qe&&!xe)return!1;const je=Math.max(hi.touch.scrollJumpMinThresholdPx,t.clientHeight*1.25);return!xe&&Math.abs(Q-Be)<=je?!1:(W("container-scroll:restore-touch-impossible-jump",{details:[`scrollTop=${Math.round(Q)}`,`expected=${Math.round(Be)}`,`diff=${Math.round(Q-Be)}`,`threshold=${Math.round(je)}`,`touchStart=${Math.round(Z)}`,xe?"hostTop=1":null,`startY=${Math.round(ee)}`,`currentY=${Math.round(fe)}`].filter(Boolean).join(" ")}),t.scrollTop=Be,M=Be,Dt({deferHostUntilRender:!0}),!0)},Pt=(Q,V,Z)=>{if(V||$.touchActive||!_h($)||!(D!==null&&performance.now()-D<=hi.rawInput.recentLayoutDriftMs))return!1;const fe=he();return W("container-scroll:restore-raw-input-layout-bottom",{details:`scrollTop=${Q} bottom=${fe.bottomScrollTop}`}),oe({type:"container-scroll",source:"programmatic-bottom",scrollTop:Q,atCursorAwareBottom:V,verticalDelta:Z}),we("rawInputLayoutDrift"),!0},Nt=()=>{W("container-scroll");const Q=Dfe(O,{hasOverflow:B(),scrollLeft:t.scrollLeft,now:performance.now(),nativeIntentThresholdPx:hi.horizontal.nativeIntentThresholdPx});O=Q.state,G(Q.trace),Q.resetScrollLeft&&(t.scrollLeft=0);const V=t.scrollTop,Z=M,ee=V-M,fe=pn(V);if($.touchActive){const Pe=_n.getScrollExpectation();W("container-scroll:touch-active",{details:_n.describeScrollExpectation(Pe,V,fe,Z,ee)??`raw=${Math.round(V)} effective=${Math.round(fe)}`})}M=fe;const ke=Pfe({syncingExternal:R.external,effectiveScrollTop:fe,pendingFollowTop:U,pendingProgrammaticTop:P,atBottom:he().isAtBottom,canPassiveFollow:_h($)});if(U=ke.nextPendingFollowTop,P=ke.nextPendingProgrammaticTop,ke.action==="external-sync"){oe({type:"container-scroll",source:"external-sync",scrollTop:fe,atCursorAwareBottom:he().isAtBottom,verticalDelta:ee}),Ee();return}if(ke.action==="programmatic-follow"){oe({type:"container-scroll",source:"programmatic-follow",scrollTop:fe,atCursorAwareBottom:he().isAtBottom,verticalDelta:ee}),Ee();return}const Be=he().isAtBottom;if(ke.action==="programmatic-drift"){oe({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Be,verticalDelta:ee}),we("programmaticDrift");return}if(!Ge(fe)&&!Pt(fe,Be,ee)){if(I){W("container-scroll:page-resume-pending",{details:`scrollTop=${fe} bottom=${he().bottomScrollTop}`}),oe({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Be,verticalDelta:ee}),Dt();return}oe({type:"container-scroll",source:"user",scrollTop:fe,atCursorAwareBottom:Be,verticalDelta:ee}),!Mn(fe)&&Dt()}},J=()=>{if(W("term-scroll"),!R.internal){R.external=!0;try{Wt();const Q=Qt();if(Q==="followed")return;if(Q==="none"&&_h($)){we("termScroll");return}const{cellH:V}=x();if(V!==0){const Z=i.buffer.active,{ydisp:ee}=D2(t.scrollTop,{bufferLength:Z.length,rows:i.rows,cols:i.cols,viewportY:Z.viewportY,cellH:V,cellW:1});nn(ee,V)}Ee()}finally{R.external=!1}}},ve=()=>{Wt();const Q=Qt();if(Q==="followed")return;if(Q==="none"&&_h($)){we("relayout");return}const{cellH:V}=x();if(V!==0)if(H)W("pending-sync-retry-fire"),Dt();else{const Z=Kt(t.scrollTop,V),ee=Rfe(i.buffer.active.viewportY,V);Z!==i.buffer.active.viewportY?t.scrollTop=ee:Math.abs(t.scrollTop-ee)>1&&W("relayout:preserve-host-offset",{details:`scrollTop=${Math.round(t.scrollTop)} viewportTop=${Math.round(ee)} ydisp=${Z}`}),ye(i.buffer.active.viewportY,V)}Ee()},He=()=>{const{cellH:Q}=x(),{paddingTop:V,paddingBottom:Z}=E(),ee=Math.max(0,t.clientHeight-V-Z),fe=i.buffer.active,ke=fe.baseY+fe.cursorY,Be=L,Pe=he(),qe=Ufe({reviewing:F(),cellH:Q,rows:i.rows,visibleContentHeight:ee,cursorBufferRow:ke,prevCursorBufferRow:L,cursorInViewport:Pe.cursorInViewport,targetScrollTop:Pe.bottomScrollTop,currentScrollTop:t.scrollTop});if(qe.reason==="intent"){L=qe.nextPrevCursorBufferRow,W("followCursorY:skip",{details:qe.reason});return}if(qe.reason==="cellH=0"){W("followCursorY:skip",{details:qe.reason});return}if(qe.reason==="shortHost"){L=qe.nextPrevCursorBufferRow,W("followCursorY:skip",{details:qe.reason});return}if(qe.reason==="same-row"){W("followCursorY:skip[same-row]",{cursorDeltaRows:qe.cursorDeltaRows,details:`cursorRow=${ke} same-row`});return}if(L=qe.nextPrevCursorBufferRow,qe.reason==="inViewport"){W("followCursorY:skip",{cursorDeltaRows:qe.cursorDeltaRows,details:`cursorRow=${Be??"null"}->${ke} inViewport`});return}if(qe.reason==="aligned"){W("followCursorY:skip",{cursorDeltaRows:qe.cursorDeltaRows,details:`cursorRow=${Be??"null"}->${ke} aligned`});return}if(qe.action!=="follow")return;U=qe.targetScrollTop;const st=t.scrollTop;t.scrollTop=qe.targetScrollTop,W("followCursorY:hit",{cursorDeltaRows:qe.cursorDeltaRows,scrollDeltaToAnchor:st-qe.targetScrollTop,details:`cursorRow=${Be??"null"}->${ke} scrollTop=${Math.round(st)}->${Math.round(qe.targetScrollTop)}`})},ut=()=>{if(!B()){ne("followCursorX");return}const{cellW:Q}=x();if(Q<=0)return;const V=i.buffer.active.cursorX*Q,Z=t.scrollLeft,ee=Z+t.clientWidth;if(V>=Z&&V<=ee){if(Ue()){W("followCursorX:skip",{details:`horizontalTouchIntent cursorPx=${V} viewport=${Z}..${ee}`});return}const qe=Tg(O,{details:`site=followCursorX cursorPx=${V} viewport=${Z}..${ee}`,scrollLeft:t.scrollLeft});O=qe.state,G(qe.trace),W("followCursorX:skip",{details:"cursorInViewport"});return}if(O.intent){W("followCursorX:skip",{details:`horizontalIntent cursorPx=${V} viewport=${Z}..${ee}`});return}const ke=Math.max(0,V-t.clientWidth/2),Be=Math.max(0,t.scrollWidth-t.clientWidth),Pe=Math.min(Be,ke);O=Ofe(O,Pe),t.scrollLeft=Pe,W("followCursorX:hit",{details:`cursorPx=${V} viewport=${Z}..${ee} target=${Pe}`})},Bt=()=>{W("render"),Wt(),H&&(W("pending-sync-retry-fire"),Dt()),Qt(),ut(),He(),Ee()};Wt(),F()?Ee():we("init");const ae=zfe({container:t,term:i,onWheel:Q=>{B()&&Math.abs(Q.deltaX)>0&&Math.abs(Q.deltaX)>=Math.abs(Q.deltaY)&&ie(`site=wheel deltaX=${Q.deltaX}`),Q.deltaY!==0&&(W("wheel:enter"),Q.preventDefault(),Q.stopPropagation(),ct(Q.deltaY))},onTouchStart:_n.onTouchStart,onTouchMove:_n.onTouchMove,onTouchEnd:_n.onTouchEnd,onTouchCancel:_n.onTouchCancel,onContainerScroll:Nt,onTermScroll:J,onRender:Bt,onRelayout:ve,onWriteParsed:()=>{Oe+=1}});return{dispose:()=>{ae.dispose(),A.dispose(),Ie()},relayout:ve,scrollToBottom:we,preparePageResumeRestore:Qe,restorePageResume:pt,scrollToRatio:mt,scrollToXRatio:dt,resetHorizontalScroll:At,markHorizontalScrollIntent:me,traceRawInputFollowScheduled:Me,traceRawInputFollowFire:de,getDebugProbe:()=>{const{cellH:Q,cellW:V}=x(),{paddingTop:Z,paddingBottom:ee}=E();return{cellH:Q,cellW:V,paddingTop:Z,paddingBottom:ee,canvasLastY:Q>0&&V>0?Je():-1,userHasVerticalScrollIntent:F(),verticalIntentMode:$.mode,verticalIntentSource:$.source,verticalIntentTransitionId:$.lastTransitionId,userHasHorizontalScrollIntent:O.intent,pendingProgrammaticScrollTop:P,pendingFollowCursorScrollTop:U,pendingFollowCursorScrollLeft:O.pendingFollowLeft,prevCursorBufferRow:L,lastSeenScrollTop:M,lastSeenScrollLeft:O.lastSeenLeft,touchScrollActive:$.touchActive,touchScrollGestureMode:_n.getState().gestureMode,syncingInternal:R.internal,syncingExternal:R.external,atBottomThreshold:w,lastSpacerUpdateAt:q,pendingContainerSyncRetry:H}}}}function rpe(e,t={}){const{onFramePending:n,onFrameWritten:r,paused:i=!1,schedule:s=w=>requestAnimationFrame(w),cancel:o=w=>cancelAnimationFrame(w)}=t;let l=null,u=!1,d=i,h=[],p=[];const y=()=>{h=[],p=[],l!==null&&(o(l),l=null)},g=()=>{if(l=null,u||h.length===0)return;const w=h,x=p;h=[],p=[];const E=w.reduce((R,z)=>R+z.byteLength,0),k=new Uint8Array(E);let T=0;for(const R of w)k.set(R,T),T+=R.byteLength;e.write(k,()=>{for(const R of x)R();r==null||r()})},b=()=>{u||d||l!==null||h.length===0||(l=s(g))};return{target:{reset:()=>{y(),e.reset()},resize:(w,x)=>e.resize(w,x),write:(w,x)=>{if(typeof w=="string"){e.write(w,x);return}const E=h.length===0;h.push(w),x&&p.push(x),E&&(n==null||n()),b()}},clear:y,flush:()=>{l!==null&&(o(l),l=null),g()},setPaused:w=>{d!==w&&(d=w,d||b())},dispose:()=>{u=!0,y()}}}const I2=5e3,ipe=1e3;function spe(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 g=o.get(y);o.delete(y),l=y,h.write(g),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>I2&&s.splice(0,s.length-I2),{written:!1,hasGap:!1};if(h.outputSeq<=l)return{written:!1,hasGap:!1};if(o.set(h.outputSeq,h.data),o.size>ipe){const g=o.keys().next().value;g!==void 0&&o.delete(g)}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 g=u,b=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(g===u){for(const w of b)o.set(w.outputSeq,w.data);d(p)}}),{applied:!0,replayedFrames:b.length}}}}function ope(e){const{sessionId:t,ws:n,relay:r,target:i,retryDelayMs:s=3e4,slowNoticeDelayMs:o=1e4,gapRecoveryDelayMs:l=2e3,scheduleReady:u=F=>requestAnimationFrame(F),scheduleFrameFlush:d,cancelFrameFlush:h,onFramePending:p,onFrameWritten:y,onReady:g,onSubscribeDelayed:b,onSubscribeStarted:w,onGapRecovery:x}=e,E=spe(),T=rpe({reset:()=>i.reset(),resize:(F,A)=>i.resize(F,A),write:(F,A)=>{i.write(F,()=>{F instanceof Uint8Array&&Wse(t,F.byteLength),A==null||A()})}},{onFramePending:p,onFrameWritten:y,schedule:d,cancel:h});let R=!1,z=null,N=null,$=null,P=!1;const q=()=>{z&&(clearTimeout(z),z=null)},H=()=>{N&&(clearTimeout(N),N=null)},U=()=>{$&&(clearTimeout($),$=null)},O=()=>{$||($=setTimeout(()=>{$=null,!(R||!E.hasPendingGap())&&(x==null||x(),D())},l))},M=()=>{const F=E.startSnapshotRequest();n.send(JSON.stringify({type:"session_subscribe",sessionId:t,requestId:F}))},I=()=>{z=setTimeout(()=>{z=null,!(R||E.hasAppliedSnapshot())&&(M(),I())},s)},L=()=>{N=setTimeout(()=>{N=null,!(R||E.hasAppliedSnapshot()||P)&&(P=!0,b==null||b())},o)},D=()=>{R||(q(),H(),U(),T.clear(),P=!1,w==null||w(),M(),I(),L())},Y=n.subscribeBinary(t,(F,A)=>{if(R)return;Use(t,F,A),E.handleBinaryFrame({data:F,outputSeq:A},T.target).hasGap?O():U()}),K=r.onMessage(F=>{if(R||F.sessionId!==t)return;if(F.type==="terminal_resize"){T.target.resize(F.cols,F.rows),D();return}F.type!=="session_snapshot"||!E.applySnapshot({requestId:F.requestId,cols:F.cols,rows:F.rows,data:F.data,outputSeq:F.outputSeq},T.target).applied||(q(),H(),u(()=>{R||g==null||g()}))});return D(),{flushOutput:()=>T.flush(),setOutputPaused:F=>T.setPaused(F),dispose:()=>{R=!0,q(),H(),U(),T.dispose(),Y(),K()}}}function ape(e){const{host:t,sessionId:n,ws:r,relay:i,createTerminal:s,attachRawInput:o,attachTransport:l=ope,scheduleAutoFocus:u=q=>requestAnimationFrame(q),onTerminalReady:d,onFramePending:h,onFrameWritten:p,onRawInput:y,isInputEnabled:g,canFocus:b=()=>!0,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E,onError:k}=e;let T=!1,R=null,z=null,N=null,$=null,P=!1;return(async()=>{try{const q=await s(t);if(T){q.dispose();return}R=q.dispose,z=o(q.terminal,n,{onRawInput:y,...g?{isInputEnabled:g}:{}}).dispose;const H=()=>{b()&&q.terminal.focus()};t.addEventListener("pointerdown",H,{passive:!0}),$=()=>t.removeEventListener("pointerdown",H),d==null||d(q.terminal),u(()=>{T||H()}),N=l({sessionId:n,ws:r,relay:i,target:q.terminal,onFramePending:h,onFrameWritten:p,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E}),N.setOutputPaused(P)}catch(q){console.error("[pty-terminal-controller] initialization failed",q),k==null||k(q)}})(),{flushOutput:()=>N==null?void 0:N.flushOutput(),setOutputPaused:q=>{P=q,N==null||N.setOutputPaused(q)},dispose:()=>{T=!0,N==null||N.dispose(),$==null||$(),z==null||z(),R==null||R()}}}function cE(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 lpe=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*?\\.(?:png|jpe?g|webp|gif)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","gi"),cpe=/\.(?:png|jpe?g|webp|gif)$/i;function r4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function upe(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 uE(e){const t=r4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||cE(t)||!cpe.test(t)?!1:upe(t)}function dpe(e){const t=new Set,n=[];for(const r of e.matchAll(lpe)){const i=r4(r[0]??"");!uE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const iv=16,hpe=8,fpe=/(?:^|[\s([{@])@?(?:\/|\.\/|\.\.\/|~\/|\.dev-anywhere\/)[A-Za-z0-9_./~%+,:=#-]*$/,ppe=/^[A-Za-z0-9_./~%+,:=#-]+$/;function i4(e,t,n){const r=[gpe(e,t),...vpe(e,t)].filter(s=>s!==null),i=new Set;return r.flatMap(s=>{const o=s.parts.map(l=>l.text).join("");return mpe(o,n).map(l=>{const u=wpe(s.parts,l.startIndex),d=Spe(s.parts,l.endIndex);return!u||!d?null:{path:l.path,startLineNumber:u.lineNumber,startColumn:u.column,endLineNumber:d.lineNumber,endColumn:d.column,segments:xpe(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 s4(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 mpe(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 gpe(e,t){const n=e.buffer.active;let r=t,i=t;for(let s=0;s<iv;s+=1){const o=n.getLine(r-1);if(!(o!=null&&o.isWrapped)||r<=1)break;r-=1}for(let s=0;s<iv;s+=1){const o=n.getLine(i);if(!(o!=null&&o.isWrapped))break;i+=1}return HS(e,r,i)}function HS(e,t,n){const r=e.buffer.active;let i=n??t;if(n===void 0)for(let o=0;o<iv;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 vpe(e,t){const n=e.buffer.active,r=[],i=Math.max(1,t-iv);for(let s=i;s<=t;s+=1){const o=n.getLine(s-1);if(!o||o.isWrapped)continue;const l=ype(e,s);l&&t>=l.startLineNumber&&t<=l.endLineNumber&&r.push(l)}return r}function ype(e,t){const n=HS(e,t);if(!n)return null;const r=n.parts.map(l=>l.text).join("");if(!fpe.test(r))return null;const i=[...n.parts];let s=n.endLineNumber,o=!1;for(let l=0;l<hpe;l+=1){const u=s+1,d=HS(e,u);if(!d)break;const h=d.parts[0];if(!h)break;const p=_pe(h.sourceText),y=h.sourceText.slice(p);if(!bpe(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 _pe(e){var t;return((t=e.match(/^\s*/))==null?void 0:t[0].length)??0}function bpe(e,t){return e<2||!t||t.startsWith("-")||t.startsWith("•")||t.startsWith("›")||t.includes("://")?!1:ppe.test(t)}function wpe(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:US(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:US(s.sourceText,s.sourceStartIndex)}:null}n-=i.text.length}}return null}function Spe(e,t){let n=t-1;for(const r of e){if(n<r.text.length)return{lineNumber:r.lineNumber,column:dE(r.sourceText.slice(0,r.sourceStartIndex+n+1))};n-=r.text.length}return null}function xpe(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:US(s.sourceText,s.sourceStartIndex+d),endColumn:dE(s.sourceText.slice(0,s.sourceStartIndex+h))})}i=o}return r}function US(e,t){return dE(e.slice(0,t))+1}function dE(e){let t=0;for(const n of e)t+=Epe(n.codePointAt(0)??0);return t}function Epe(e){return e===0||e<32||e>=127&&e<160||Cpe(e)?0:kpe(e)?2:1}function Cpe(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function kpe(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 o4(e,t){return i4(e,t,dpe)}function Tpe(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 Rpe(e,t){const n={provideLinks(i,s){const o=o4(e,i);if(o.length===0){s(void 0);return}const l=o.reduce((u,d)=>{for(const h of s4(d))h.start.y!==i||h.end.y!==i||u.push({text:d.path,range:h,decorations:{underline:!0,pointerCursor:!0},activate:p=>{Tpe(p)&&t(d.path)}});return u},[]);s(l.length>0?l:void 0)}},r=e.registerLinkProvider(n);return{dispose:()=>r.dispose(),provider:n}}const Ape=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*\\.[A-Za-z0-9]{1,8}(?=[\\s`\"'<>),.;:!?,。;:!?、]|$)","gi"),Npe=/\.(?:png|jpe?g|webp|gif)$/i,Mpe=/\.[A-Za-z0-9]{1,8}$/,Ope=/^(?: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,Dpe=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 a4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function Ppe(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 Lpe(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 Ope.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function Ipe(e){return e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/")||e.includes("/")}function zpe(e){return Ipe(e)?!0:Dpe.has(e.toLowerCase())}function hE(e){const t=a4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||cE(t)||Lpe(t)||Npe.test(t)||!Mpe.test(t)||!zpe(t)||t.split("/").includes("...")?!1:Ppe(t)}function Bpe(e){const t=new Set,n=[];for(const r of e.matchAll(Ape)){const i=a4(r[0]??"");!hE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const jpe=750;function l4(e,t){return i4(e,t,Bpe)}function Fpe(e){return e.metaKey||e.ctrlKey}function $pe(e,t){let n=null;const r=(o,l)=>{if(!Fpe(l))return;const u=performance.now();(n==null?void 0:n.path)===o&&u-n.at<jpe||(n={path:o,at:u},t(o))},i={provideLinks(o,l){const u=l4(e,o);if(u.length===0){l(void 0);return}const d=u.reduce((h,p)=>{for(const y of s4(p))y.start.y!==o||y.end.y!==o||h.push({text:p.path,range:y,decorations:{underline:!1,pointerCursor:!0},hover:()=>{Hpe(e,p)},leave:()=>{Rg(e)},dispose:()=>{Rg(e)},activate:g=>{r(p.path,g)}});return h},[]);l(d.length>0?d:void 0)}},s=e.registerLinkProvider(i);return{dispose:()=>{Rg(e),s.dispose()},provider:i}}function Hpe(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;Rg(e),Upe(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 g=y.lineNumber-p;if(g<1||g>e.rows)continue;const b=document.createElement("div");b.dataset.slot="pty-file-link-hover-segment",b.dataset.range=`${y.lineNumber}:${y.startColumn}-${y.endColumn}`,b.style.position="absolute",b.style.left=`${d+(y.startColumn-1)*o}px`,b.style.top=`${h+(g-1)*l+l-2}px`,b.style.width=`${Math.max(1,y.endColumn-y.startColumn+1)*o}px`,b.style.height="2px",b.style.background="currentColor",b.style.opacity="0.8",u.append(b)}}function Rg(e){var t;(t=e.element)==null||t.querySelectorAll('[data-slot="pty-file-link-hover-overlay"]').forEach(n=>n.remove())}function Upe(e){window.getComputedStyle(e).position==="static"&&(e.style.position="relative")}function Ya(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 Wpe(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 qpe(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 c4(e,t,n){if(t.length===0)return Ya("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 Ya("skip",{reason:"missing-elements",hasScreen:!!i,hasMetricHost:!!s,point:n}),null;const o=ry(s,e);if(!o||o.cellW<=0||o.cellH<=0)return Ya("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 Ya("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};Ya("probe",{point:n,viewportX:u,viewportY:d,bufferLineNumber:h,providers:t.length,metrics:o});for(const y of t){let g=null;if(y.provideLinks(h,b=>{Ya("links",{bufferLineNumber:h,position:p,count:(b==null?void 0:b.length)??0,links:b==null?void 0:b.map(x=>({text:x.text,range:x.range}))});const w=b==null?void 0:b.find(x=>Wpe(x,p,e.cols));w&&(g=w)}),g)return g}return Ya("miss",{position:p,point:n,bufferLineNumber:h}),null}function Vpe(e,t,n){return c4(e,t,n)!==null}function Ype(e,t,n){const r=c4(e,t,n);return r?(r.activate(qpe(n),r.text),Ya("activate",{text:r.text,range:r.range,point:n}),!0):!1}async function xf(e){const t=nt.loading(`上传 ${e.file.name} ...`);try{const n=await e.relay.uploadFile(e.sessionId,e.file);return!n.success||!n.path?(nt.error(n.error??"上传失败",{id:t}),null):(e.successLabel===null?nt.dismiss(t):nt.success(e.successLabel??`已上传 ${n.path}`,{id:t}),n.path)}catch(n){return nt.error(n instanceof Error?n.message:String(n),{id:t}),null}}function z2(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 B2="--dev-visual-viewport-height",Kpe=.3;function u4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i=!0}){const s=e-t-n,o=r-t-n,l=j2(s,e),u=i?j2(o,r):0;return Math.max(l,u)}function Gpe({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r=e,allowBaselineFallback:i=!1}){return u4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i})}function j2(e,t){const n=Math.max(e,0);return n<=0?0:n/Math.max(t,1)>=Kpe?n:0}function Xpe(){_.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(B2,`${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(B2)}},[])}function F2(){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 Zpe(){_.useEffect(()=>{const e=window.visualViewport;let t=0;const n=()=>{F2(),cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,F2()})};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 Qpe(){return fE().bottomOffset}function fE(){const[e,t]=_.useState({bottomOffset:0,layoutBottomInset:0}),n=_.useRef(0),r=_.useRef(0);return _.useEffect(()=>{const i=window.visualViewport;if(!i)return;const s=Jpe();let o=0;const l=()=>{const h=i.height,p=i.offsetTop,y=i.width,g=Math.max(window.innerHeight,h+p);!n.current||Math.abs(y-r.current)>1?(n.current=g,r.current=y):n.current=Math.max(n.current,g);const b=window.innerHeight,w=eme(),x=!s||w,E=s&&w,k={bottomOffset:u4({layoutViewportHeight:b,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:x}),layoutBottomInset:Gpe({layoutViewportHeight:b,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:E})};t(T=>T.bottomOffset===k.bottomOffset&&T.layoutBottomInset===k.layoutBottomInset?T:k)},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 Jpe(){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 eme(){const e=document.activeElement;return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function tme(e){window.__devAnywherePtyTerminal=e}function nme(){window.__devAnywherePtyTerminal&&delete window.__devAnywherePtyTerminal}function rme(e){window.__devAnywherePtyDebug=e}function ime(){window.__devAnywherePtyDebug&&delete window.__devAnywherePtyDebug}function sme(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),g=o.buffer.active;let b=0;if(l>0&&u>0){const I=e4({bufferLength:g.length,rows:o.rows,cols:o.cols,viewportY:g.viewportY,cursorY:g.cursorY,cellH:l,cellW:u,visibleContentHeight:y},p);b=(I==null?void 0:I.spacerHeight)??0}const w=Ii(i.style.height),x=Ii(s.style.top),E=Ii(s.style.height),k=Ii(s.style.width),T=Ii(s.style.paddingTop),R=Ii(i.style.width);let z=0;if(l>0){const I=o.rows*l,L=I>0&&I<y?y-I:0;z=Math.max(0,g.viewportY*l+L)}const N=x-z,$=r.scrollTop,P=$+r.clientHeight,q=x+E,H=Math.max(0,Math.min(P,q)-Math.max($,x)),U=r.clientHeight>0?H/r.clientHeight:0,O=g.baseY+g.cursorY,M=lE({rows:o.rows,cellH:l,bufferLength:g.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:R},host:{top:x,height:E,width:k,paddingTop:T,expectedTop:z,topDrift:N},term:{rows:o.rows,cols:o.cols,bufferLength:g.length,viewportY:g.viewportY,baseY:g.baseY,cursorX:g.cursorX,cursorY:g.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:b,spacerDrift:w-b,lastSpacerUpdateAt:n.lastSpacerUpdateAt,viewportHostCoverage:U,pendingContainerSyncRetry:n.pendingContainerSyncRetry}}const iy={enabled:!1,phase:"idle",error:null,lastSpokenText:"",approvalRequestId:null,activityLevel:0,waveform:[],resumeRequestSeq:0};function ome(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function Hs(e,t,n){const r=e.bySessionId[t]??iy;return{bySessionId:{...e.bySessionId,[t]:n(r)}}}const on=Ju()(ed(e=>({bySessionId:{},enable:t=>e(n=>Hs(n,t,r=>({...r,enabled:!0,phase:"starting",error:null,waveform:[]}))),disable:t=>e(n=>Hs(n,t,r=>({...r,enabled:!1,phase:"idle",error:null,approvalRequestId:null,activityLevel:0,waveform:[]}))),requestResume:t=>e(n=>Hs(n,t,r=>({...r,resumeRequestSeq:r.resumeRequestSeq+1}))),setPhase:(t,n)=>e(r=>Hs(r,t,i=>({...i,phase:n,error:n==="error"?i.error:null}))),setError:(t,n)=>e(r=>Hs(r,t,i=>({...i,phase:"error",error:n,activityLevel:0,waveform:[]}))),clearError:t=>e(n=>Hs(n,t,r=>({...r,error:null,phase:r.enabled&&r.phase==="error"?"starting":r.phase}))),setLastSpokenText:(t,n)=>e(r=>Hs(r,t,i=>({...i,lastSpokenText:n}))),setApproval:(t,n)=>e(r=>Hs(r,t,i=>({...i,approvalRequestId:n}))),setActivityLevel:(t,n)=>e(r=>Hs(r,t,i=>({...i,activityLevel:ome(n)}))),appendWaveform:(t,n)=>{n.length!==0&&e(r=>Hs(r,t,i=>({...i,waveform:[...i.waveform,...n].slice(-$0)})))},clearWaveform:t=>e(n=>Hs(n,t,r=>({...r,waveform:[]}))),resetAll:()=>e({bySessionId:{}})}),{name:"voice-pilot-store"}));function ame(){const[e,t]=_.useState(!1),[n,r]=_.useState(!1),[i,s]=_.useState(!1);_.useEffect(()=>{if(e){r(!1);return}const p=setTimeout(()=>r(!0),300);return()=>clearTimeout(p)},[e]);const o=_.useCallback(()=>{t(!0),s(!1)},[]),l=_.useCallback(()=>{t(!1),s(!1)},[]),u=_.useCallback(()=>{s(!0)},[]),d=_.useMemo(()=>({connecting:n,subscribeDelayed:i}),[n,i]),h=_.useMemo(()=>({onReady:o,onSubscribeStarted:l,onSubscribeDelayed:u}),[o,u,l]);return{ready:e,overlay:d,transport:h}}const lme=900;function cme(){var t;const e=navigator.virtualKeyboard;(t=e==null?void 0:e.show)==null||t.call(e)}function ume(e){const{containerEl:t,xtermHostRef:n,terminalRef:r}=e,[i,s]=_.useState(!1),o=_.useRef(0),l=_.useCallback(()=>{const g=document.activeElement;!t||!(g instanceof HTMLElement)||!t.contains(g)||g.blur()},[t]),u=_.useCallback(()=>{const g=n.current,b=document.activeElement,w=!!(g&&b instanceof HTMLElement&&g.contains(b));s(w),w&&cme()},[n]),d=_.useCallback((g={})=>{o.current=performance.now()+lme,(g.blur??!0)&&(l(),s(!1))},[l]),h=_.useCallback(g=>{if(performance.now()<=o.current){g.target instanceof HTMLElement&&g.target.blur(),window.setTimeout(u,0);return}u()},[u]),p=_.useCallback(()=>{window.setTimeout(u,0)},[u]),y=_.useCallback(()=>{var g;o.current=0,(g=r.current)==null||g.focus(),window.setTimeout(u,0)},[u,r]);return{ptyInputFocused:i,suppressPtyFocus:d,focusPtyInput:y,handleFocusCapture:h,handleBlurCapture:p}}function dme(){const[e,t]=_.useState(!0),[n,r]=_.useState(!1),i=_.useRef(n);_.useEffect(()=>{i.current=n},[n]);const s=_.useCallback(l=>{t(l),l&&r(!1)},[]),o=_.useCallback(()=>{r(!1)},[]);return{isAtBottom:e,hasNewFramesWhileAway:n,hasNewFramesWhileAwayRef:i,setHasNewFramesWhileAway:r,handleAtBottomChange:s,clearNewFramesWhileAway:o}}async function d4(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&&hme(e)?"legacy":"failed"}function hme(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()}}function h4({terminal:e,host:t,cellWidth:n,cellHeight:r}){return n&&r?{cellW:n,cellH:r}:ry(t,e)}function $2(e,t){var n;return(((n=e.getCell(t))==null?void 0:n.getChars())??"").trim().length>0}function fme(e,t){const n=Math.min(e.length,t),r=[];let i=0;for(;i<n;){for(;i<n&&!$2(e,i);)i+=1;if(i>=n)break;const s=i;for(;i+1<n&&$2(e,i+1);)i+=1;r.push({start:s,end:i}),i+=1}return r}function pme(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 mme(e,t,n){const s=e[t];if(!s)return{start:0,end:0};if(s.end-s.start+1>=18)return s;let o=t,l=t;const u=()=>e[l].end-e[o].start+1,d=()=>l-o+1;for(;u()<18&&d()<3;){const h=o>0?e[o-1]:null,p=l+1<e.length?e[l+1]:null;if(!h&&!p)break;if(h&&p){const y=Math.max(0,n-h.end),g=Math.max(0,p.start-n);y<=g?o-=1:l+=1}else h?o-=1:l+=1}return{start:e[o].start,end:e[l].end}}function gme(e,t){return e.row<t.row||e.row===t.row&&e.column<=t.column?{start:e,end:t}:{start:t,end:e}}function vme(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(`
632
+ `),F.preventDefault(),!1):!0),{dispose:()=>{var F,A,W;I.dispose(),(F=e.textarea)==null||F.removeEventListener("input",U),(A=e.textarea)==null||A.removeEventListener("compositionstart",O,!0),(W=e.textarea)==null||W.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 ry(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 Efe(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 Cfe(e,t,n,r,i={}){if(e<=0||t<=0||n<=0||r<=0)return null;const s=Math.floor(t/r),o=t-s*r,l=s+(o>=r*.75?1:0);return{cols:Math.max(i.minCols??20,Math.floor(e/n)),rows:Math.max(i.minRows??8,l)}}function kfe(e){const t=getComputedStyle(e);return{width:Math.max(0,e.clientWidth-Ii(t.paddingLeft)-Ii(t.paddingRight)),height:Math.max(0,e.clientHeight-Ii(t.paddingTop)-Ii(t.paddingBottom))}}function Tfe(e){const{container:t,term:n,onResize:r,onRelayout:i,preserveRows:s,minCols:o,minRows:l}=e;let u=!1,d=null;const h=()=>{if(d=null,u)return;const w=kfe(t),x=n.element;if(!x)return;const E=ry(x,n);if(!E)return;const k=Cfe(w.width,w.height,E.cellW,E.cellH,{minCols:o,minRows:l});if(!k)return;const T=s!=null&&s()?n.rows:k.rows;k.cols===n.cols&&T===n.rows||(n.resize(k.cols,T),r(k.cols,T),requestAnimationFrame(()=>{u||i==null||i()}))},p=()=>{d===null&&(d=requestAnimationFrame(h))};p();const y=new ResizeObserver(p);y.observe(t);const g=p;window.addEventListener("resize",g);const b=window.visualViewport;return b==null||b.addEventListener("resize",g),{dispose:()=>{u=!0,d!==null&&cancelAnimationFrame(d),y.disconnect(),window.removeEventListener("resize",g),b==null||b.removeEventListener("resize",g)}}}function e4(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,g=y+n-i,b=y+p*e.cellH-(i-e.cellH)/2;return{spacerHeight:Math.max(y,Math.min(g,b))+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 lE(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,g=Math.max(0,e.bufferLength-e.rows)*e.cellH;h=Math.max(g,Math.min(o,p))}else d=e.containerScrollTop+e.containerClientHeight>=e.containerScrollHeight-e.atBottomThreshold,h=o;return{isAtBottom:d,bottomScrollTop:h,cursorInViewport:s}}function t4(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 D2(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 Rfe(e,t){return t<=0?0:Math.max(0,e)*t}function Afe(){return{intent:!1,lastUserInputAt:null,unmarkedOriginLeft:null,lastSeenLeft:0,pendingFollowLeft:null}}function Nfe(e,t){return{...e,intent:t,unmarkedOriginLeft:t?e.unmarkedOriginLeft:null}}function Tg(e,t){return{state:{...Nfe(e,!1),lastUserInputAt:null,pendingFollowLeft:null,...t.scrollLeft!==void 0?{lastSeenLeft:t.scrollLeft}:{}},trace:e.intent?{kind:"clear",details:t.details}:null}}function Mfe(e,t){return{state:{...e,intent:!0,lastUserInputAt:t.now,unmarkedOriginLeft:null},trace:e.intent?null:{kind:"set",details:t.details}}}function Ofe(e,t){return{...e,pendingFollowLeft:t}}function Dfe(e,t){if(!t.hasOverflow)return{...Tg(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 Pfe({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 Lfe(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 Ife(e){return!(e.bottomScrollTop<e.domMaxScrollTop-1)||e.rawScrollTop<=e.bottomScrollTop+1?{action:"keep",scrollTop:e.rawScrollTop}:{action:"clamp",scrollTop:e.bottomScrollTop}}function zfe({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),g=t.onRender(d),b=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(),g.dispose(),b==null||b.dispose(),w.disconnect()}}}function Bfe({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:g}){var N,$;let b=null,w=null;const x=()=>{var I;const P=document.activeElement;if(!P)return null;const q=P.getAttribute("aria-label")??"",H=P.tagName,U=typeof P.closest=="function"?((I=P.closest("[data-slot]"))==null?void 0:I.getAttribute("data-slot"))??"":"",O=P.id?`#${P.id}`:"",M=typeof P.className=="string"&&P.className?"."+P.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";return q?`${q}|${H}${O}${M}{${U}}`:`${H}${O}${M}{${U}}`},E=(P,q={})=>{if(!lw())return;const H=e.getBoundingClientRect(),U=t.getBoundingClientRect(),O=window.visualViewport,{cellH:M,cellW:I}=i(),{paddingTop:L,paddingBottom:D}=s(),Y=Math.max(0,e.clientHeight-L-D),K=n.buffer.active,F=K.baseY+K.cursorY,A=lE({rows:n.rows,cellH:M,bufferLength:K.length,cursorBufferRow:F,visibleContentHeight:Y,paddingTop:L,paddingBottom:D,containerScrollTop:e.scrollTop,containerScrollHeight:e.scrollHeight,containerClientHeight:e.clientHeight,atBottomThreshold:r}),W=o(),G=W===null?null:F-W,B=q.cursorDeltaRows!==void 0?q.cursorDeltaRows:G,ne=q.scrollDeltaToAnchor!==void 0?q.scrollDeltaToAnchor:e.scrollTop-A.bottomScrollTop,ie=Ii(t.style.top),se=M>0?t4({ydisp:K.viewportY,rows:n.rows,cellH:M,visibleContentHeight:Y}):0,te=Ii(t.style.height),he=e.scrollTop,ge=he+e.clientHeight,Ee=ie+te,Re=Math.max(0,Math.min(ge,Ee)-Math.max(he,ie)),Ie=y();Aae({t:performance.now(),event:P,scope:q.scope,action:q.action,reason:q.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:H.top,containerBottom:H.bottom,hostRectTop:U.top,hostRectBottom:U.bottom,viewportY:K.viewportY,bufferLength:K.length,hostTop:t.style.top,cellH:M,cellW:I,cursorX:K.cursorX,cursorY:K.cursorY,cursorBufferRow:F,cursorDeltaRows:B,cursorInViewport:A.cursorInViewport,anchorBottomScrollTop:A.bottomScrollTop,scrollDeltaToAnchor:ne,pendingProgrammaticScrollTop:l(),pendingFollowCursorScrollTop:u(),pendingFollowCursorScrollLeft:d(),pendingContainerSyncRetry:h(),horizontalIntent:p(),intentMode:Ie.mode,intentSource:Ie.source,intentTransition:Ie.lastTransitionId,prevCursorBufferRow:W,hostTopDrift:ie-se,viewportHostCoverage:e.clientHeight>0?Re/e.clientHeight:0,focus:x(),atBottom:A.isAtBottom,touchActive:Ie.touchActive,userIntent:g(),...q})},k=P=>{if(!lw())return;const q=window.visualViewport;if(!q)return;const H=b===null?0:q.height-b,U=w===null?0:q.offsetTop-w;b=q.height,w=q.offsetTop,E(P,{vvHeightDelta:H,vvOffsetDelta:U})},T=()=>k("vv:resize"),R=()=>k("vv:scroll"),z=P=>{var I;if(!lw())return;const q=P.target,H=q===e||q instanceof Node&&e.contains(q),U=q&&typeof q.closest=="function"?((I=q.closest("[data-slot]"))==null?void 0:I.getAttribute("data-slot"))??"":"",O=(q==null?void 0:q.tagName)??"",M=q&&typeof q.className=="string"&&q.className?"."+q.className.split(/\s+/).filter(Boolean).slice(0,2).join("."):"";E(`wheel:window deltaY=${Math.round(P.deltaY)} reachesContainer=${H?1:0} prevented=${P.defaultPrevented?1:0} target=${O}${M}{${U}}`)};return(N=window.visualViewport)==null||N.addEventListener("resize",T),($=window.visualViewport)==null||$.addEventListener("scroll",R),window.addEventListener("wheel",z,{passive:!0,capture:!0}),{trace:E,dispose:()=>{var P,q;(P=window.visualViewport)==null||P.removeEventListener("resize",T),(q=window.visualViewport)==null||q.removeEventListener("scroll",R),window.removeEventListener("wheel",z,{capture:!0})}}}function n4(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 Lw=e=>e.mode==="reviewing",_h=e=>e.mode==="following";function jfe(e,t){return e==="following"&&t==="reviewing"?"set":e==="reviewing"&&t==="following"?"clear":"keep"}function Kr(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:jfe(e.mode,t.mode),reason:n}}}function bh(e,t,n,r){return{...e,mode:"reviewing",source:t,lastScrollTop:n,lastTransitionId:r}}function Iw(e,t,n,r){return{...e,mode:"following",source:t,lastScrollTop:n,lastTransitionId:r}}function Ffe(e){throw new Error(`Unhandled PTY vertical intent event: ${JSON.stringify(e)}`)}function $fe(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)?Kr(e,{...o,mode:"following",source:"none",lastTransitionId:`${r}.bottom-down`},`scrollTop=${t.scrollTop} atBottom=true`):Kr(e,{...o,lastTransitionId:`${r}.not-bottom`},`scrollTop=${t.scrollTop} atBottom=${t.atCursorAwareBottom}`)}function Hfe(e,t,n={}){const r=n.atBottomThreshold??8;switch(t.type){case"attach":{const i=n4({initialIntent:t.initialIntent,scrollTop:t.scrollTop});return Kr(e,i,`initialIntent=${t.initialIntent}`)}case"scroll-to-bottom":return t.force?Kr(e,Iw({...e,touchActive:!1,touchStartY:null,touchStartScrollTop:null,touchReviewNotified:!1},"programmatic-bottom",e.lastScrollTop,"bottom.force"),`reason=${t.reason} force=true`):Kr(e,{...e,lastTransitionId:`bottom.passive.${e.mode}`},`reason=${t.reason} force=false`);case"scroll-to-ratio":return Kr(e,bh(e,"ratio-scroll",t.scrollTop,"ratio.reviewing"),`ratio=${t.ratio}`);case"wheel":return t.nextScrollTop===t.previousScrollTop?Kr(e,{...e,lastTransitionId:"wheel.clamped",lastScrollTop:t.nextScrollTop},`delta=${t.deltaY}`):t.deltaY<0?Kr(e,bh(e,"wheel",t.nextScrollTop,"wheel.up"),`delta=${t.deltaY}`):t.deltaY>0&&t.reachedCursorAwareBottom?Kr(e,Iw(e,"none",t.nextScrollTop,"wheel.down.bottom"),`delta=${t.deltaY}`):Kr(e,bh(e,"wheel",t.nextScrollTop,"wheel.down.not-bottom"),`delta=${t.deltaY}`);case"container-scroll":return t.source!=="user"?Kr(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?Kr(e,Iw(e,"none",t.scrollTop,"container.user.bottom-down"),`delta=${t.verticalDelta} threshold=${r}`):Kr(e,{...e,lastScrollTop:t.scrollTop,lastTransitionId:"container.user.bottom-small-delta"},`delta=${t.verticalDelta} threshold=${r}`):Kr(e,bh(e,"native-scroll",t.scrollTop,"container.user.away"),`scrollTop=${t.scrollTop} atBottom=false`);case"touch-start":return Kr(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?Kr(e,{...bh(e,"touch",e.lastScrollTop,"touch.move.review"),touchReviewNotified:!0},`movement=${i} threshold=${t.reviewThresholdPx}`,!0):i>=t.reviewThresholdPx?Kr(e,{...e,lastTransitionId:"touch.move.reviewing"},`movement=${i} threshold=${t.reviewThresholdPx}`):Kr(e,{...e,lastTransitionId:"touch.move.below-threshold"},`movement=${i} threshold=${t.reviewThresholdPx}`)}case"touch-end":case"touch-cancel":return $fe(e,t,r);default:return Ffe(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 Ufe({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 Wfe({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 qfe({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 Vfe({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 Yfe({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 Kfe(){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 Gfe(){return{startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,lastGestureAt:null,lastHorizontalGestureAt:null,gestureMode:null}}function Xfe(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 Zfe(e,t){return{...e,lastGestureAt:t}}function P2(e,t){return{...e,lastHorizontalGestureAt:t}}function Qfe(e,t){return{...e,lastClientY:t.currentY,lastGestureAt:t.now}}function Jfe(e,t){return!t.touchActive||e.gestureMode!==null||t.currentY===null?e:{...e,gestureMode:"pending"}}function L2(e,t){return e.gestureMode===t?e:{...e,gestureMode:t}}function epe(e){return{...e,startedAtCursorAwareBottom:!1,startClientX:null,startScrollLeft:null,lastClientY:null,gestureMode:null}}function tpe({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:g}){let b=Gfe();const w=P=>{const q=P??b.lastClientY,H=o(),U=Math.max(0,e.scrollHeight-e.clientHeight),O=i();return qfe({touchActive:O.touchActive,touchStartScrollTop:O.touchStartScrollTop,touchStartY:O.touchStartY,currentY:q,touchStartedAtCursorAwareBottom:b.startedAtCursorAwareBottom,bottomScrollTop:H.bottomScrollTop,domMaxScrollTop:U})},x=(P,q)=>Wfe({startX:b.startClientX,startY:i().touchStartY,currentX:P,currentY:q}),E=P=>{const q=Math.max(0,e.scrollWidth-e.clientWidth);return Vfe({touchActive:i().touchActive,touchStartClientX:b.startClientX,touchStartScrollLeft:b.startScrollLeft,currentX:P,maxScrollLeft:q})},k=(P,q,H,U,O)=>P?[`raw=${Math.round(q)}`,`effective=${Math.round(H)}`,`prev=${Math.round(U)}`,`delta=${Math.round(O)}`,`expected=${Math.round(P.expectedScrollTop)}`,`startScroll=${Math.round(P.touchStartScrollTop)}`,`base=${Math.round(P.gestureBaseScrollTop)}`,`startY=${Math.round(P.touchStartY)}`,`currentY=${Math.round(P.currentY)}`,`touchDeltaY=${Math.round(P.touchDeltaY)}`,`max=${Math.round(P.cursorAwareMaxScrollTop)}`].join(" "):null,T=P=>{var M;if(r()){n("touchstart:page-resume-pending");return}const q=((M=P.touches)==null?void 0:M[0])??null,H=(q==null?void 0:q.clientX)??null,U=(q==null?void 0:q.clientY)??null;d("touchstart");const O=o();b=Xfe(b,{startedAtCursorAwareBottom:O.isAtBottom,startClientX:H,startClientY:U,startScrollLeft:e.scrollLeft,now:performance.now()}),s({type:"touch-start",clientY:U,scrollTop:e.scrollTop}),n("touchstart",{details:[`startX=${H??"null"}`,`startY=${U??"null"}`,`startScroll=${Math.round(e.scrollTop)}`,`bottom=${Math.round(O.bottomScrollTop)}`,`atBottom=${O.isAtBottom?1:0}`].join(" ")})},R=P=>{var K;if(r()){n("touchmove:page-resume-pending");return}const q=((K=P.touches)==null?void 0:K[0])??null,H=(q==null?void 0:q.clientX)??null,U=(q==null?void 0:q.clientY)??null,O=performance.now();b=Qfe(b,{currentY:U,now:O});const M=x(H,U);n("touchmove",{details:U===null?"currentY=null":k(w(U),e.scrollTop,e.scrollTop,l(),e.scrollTop-l())??[`mode=${b.gestureMode??"none"}`,`currentY=${Math.round(U)}`,M?`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`:null].filter(Boolean).join(" ")});const I=u();if(I||d("touchmove"),b=Jfe(b,{touchActive:i().touchActive,currentY:U}),b.gestureMode==="pending"&&M){const F=I&&M.absDx>=hi.touch.horizontalGestureSlopPx&&M.absDx>M.absDy*hi.touch.horizontalLockRatio,A=M.absDy>=hi.touch.gestureSlopPx&&(!I||M.absDy>M.absDx*hi.touch.verticalLockRatio);if(F)b=L2(b,"horizontal"),b=P2(b,O),n("touchmove:horizontal-lock",{details:`dx=${Math.round(M.dx)} dy=${Math.round(M.dy)} distance=${Math.round(M.distance)}`});else if(A)b=L2(b,"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:U,reviewThresholdPx:hi.touch.gestureSlopPx});return}}if(b.gestureMode==="horizontal"){const F=E(H);if(!I||!F){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&&(b=P2(b,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(F.expectedScrollLeft)}`,`startScrollLeft=${Math.round(F.touchStartScrollLeft)}`,`startX=${Math.round(F.touchStartX)}`,`currentX=${Math.round(F.currentX)}`,`touchDeltaX=${Math.round(F.touchDeltaX)}`,`max=${Math.round(F.maxScrollLeft)}`].join(" ")});return}if(b.gestureMode!=="vertical")return;const L=w(U);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&&b.startedAtCursorAwareBottom&&L.expectedScrollTop>=L.cursorAwareMaxScrollTop-t&&U!==null&&U<=L.touchStartY){n("touchmove:bottom-boundary-follow");return}s({type:"touch-move",clientY:U,reviewThresholdPx:hi.touch.gestureSlopPx}).notifyTouchReviewStart&&(p==null||p(),n("touchmove:review"))},z=P=>{const q=e.scrollTop,H=o(),U=Yfe({touchStartScrollTop:i().touchStartScrollTop,liveScrollTop:q,atBottomThreshold:t,touchStartedAtCursorAwareBottom:b.startedAtCursorAwareBottom,anchorIsAtBottom:H.isAtBottom,reviewedDuringTouch:i().touchReviewNotified});b=epe(b),s({type:P,scrollTop:q,atCursorAwareBottom:U.atCursorAwareBottomForIntent,releaseOnSemanticBottom:U.releaseOnSemanticBottom}),b=Zfe(b,performance.now()),g(),y()};return{onTouchStart:T,onTouchMove:R,onTouchEnd:()=>{if(r()){n("touchend:page-resume-pending");return}z("touch-end"),n("touchend")},onTouchCancel:()=>{if(r()){n("touchcancel:page-resume-pending");return}z("touch-cancel"),n("touchcancel")},isRecentNativeScroll:()=>i().touchActive||b.lastGestureAt!==null&&performance.now()-b.lastGestureAt<=hi.touch.nativeScrollRecentMs,isRecentHorizontalGesture:()=>b.lastHorizontalGestureAt!==null&&performance.now()-b.lastHorizontalGestureAt<=hi.touch.nativeScrollRecentMs,getScrollExpectation:w,describeScrollExpectation:k,getState:()=>b}}function npe(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:g,onTouchBoundaryPrevent:b,atBottomThreshold:w=hi.bottom.defaultThresholdPx}=e,x=()=>ry(r,i)??{cellH:0,cellW:0},E=()=>{const Q=getComputedStyle(t);return{paddingTop:Ii(Q.paddingTop),paddingBottom:Ii(Q.paddingBottom)}},k=Kfe(),T=(Q,V,Z)=>{k.set(Q,V,Z)},R={external:!1,internal:!1};let z=null,N="",$=n4({initialIntent:p,scrollTop:t.scrollTop}),P=null,q=null,H=!1,U=null,O=Afe(),M=0,I=!1,L=null,D=null,Y=null,K=null;const F=()=>Lw($),A=Bfe({container:t,host:r,term:i,atBottomThreshold:w,getDims:x,getVerticalInsets:E,getPrevCursorBufferRow:()=>L,getPendingProgrammaticScrollTop:()=>P,getPendingFollowCursorScrollTop:()=>U,getPendingFollowCursorScrollLeft:()=>O.pendingFollowLeft,getPendingContainerSyncRetry:()=>H,getHorizontalIntent:()=>O.intent,getVerticalIntent:()=>$,getUserHasVerticalScrollIntent:()=>F()}),W=A.trace,G=Q=>{if(Q){if(Q.kind==="ignore"){W("horizontal-intent:ignore",{details:Q.details});return}W(`horizontal-intent:${Q.kind}`,{details:Q.details})}},B=()=>t.scrollWidth>t.clientWidth+w,ne=Q=>{if(B())return!1;const V=Tg(O,{details:`site=${Q} reason=not-scrollable scrollWidth=${t.scrollWidth} clientWidth=${t.clientWidth}`,scrollLeft:t.scrollLeft});return O=V.state,G(V.trace),t.scrollLeft!==0&&(t.scrollLeft=0,O={...O,lastSeenLeft:0}),!0},ie=Q=>{if(!B()){ne("markHorizontalUserInput");return}const V=Mfe(O,{now:performance.now(),details:Q});O=V.state,G(V.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+w,horizontalScrollable:B()}),te=()=>{if(!h)return;const Q=se(),V=[Q.scrollTop,Q.scrollLeft,Q.scrollHeight,Q.scrollWidth,Q.clientHeight,Q.clientWidth,Q.scrollable,Q.horizontalScrollable].join(":");V!==N&&(N=V,h(Q))},he=()=>{const{cellH:Q}=x(),{paddingTop:V,paddingBottom:Z}=E(),ee=i.buffer.active;return lE({rows:i.rows,cellH:Q,bufferLength:ee.length,cursorBufferRow:ee.baseY+ee.cursorY,visibleContentHeight:Math.max(0,t.clientHeight-V-Z),paddingTop:V,paddingBottom:Z,containerScrollTop:t.scrollTop,containerScrollHeight:t.scrollHeight,containerClientHeight:t.clientHeight,atBottomThreshold:w})},ge=()=>{const Q=he().isAtBottom;z!==Q&&(z=Q,d==null||d(Q))},Ee=()=>{ge(),te()},Re=()=>$.touchActive,Ie=()=>{Y!==null&&(K==null||K(Y),Y=null,K=null)},Ye=()=>{if(Y!==null)return;const Q=()=>{Y=null,K=null,Ee()};if(typeof window.requestAnimationFrame=="function"){Y=window.requestAnimationFrame(Q),K=typeof window.cancelAnimationFrame=="function"?V=>window.cancelAnimationFrame(V):null;return}Y=window.setTimeout(Q,16),K=V=>window.clearTimeout(V)},gt=()=>{Y!==null&&(Ie(),Ee())},Me=(Q="rawInput")=>{D=performance.now(),W(`rawInputFollow:scheduled[${Q}]`)},de=()=>{D=performance.now(),W("rawInputFollow:fire")},oe=Q=>{const V=Lw($),Z=Hfe($,Q,{atBottomThreshold:w});$=Z.state,Z.trace&&W(`intent:${Z.trace.action}`,{details:`id=${Z.trace.id} reason=${Z.trace.reason}`});const ee=Lw($);return V!==ee&&(y==null||y(ee)),Z.notifyTouchReviewStart&&(g==null||g()),Z},ye=(Q,V,Z)=>{if(V<=0)return;const ee=Z??(()=>{const{paddingTop:Pe,paddingBottom:qe}=E();return Math.max(0,t.clientHeight-Pe-qe)})(),fe=t4({ydisp:Q,rows:i.rows,cellH:V,visibleContentHeight:ee}),ke=r.style.top,Be=`${fe}px`;T(r,"position","absolute"),T(r,"left","0px"),T(r,"top",Be),ke!==Be&&W("host-position",{ydisp:Q,details:`${ke||"0px"}->${Be}`})},we=(Q="internal",V={})=>{const Z=Math.max(0,i.buffer.active.length-i.rows),ee=he(),fe=Lfe({force:V.force??!1,reviewing:F(),viewportY:i.buffer.active.viewportY,expectedYdisp:Z,scrollTop:t.scrollTop,bottomScrollTop:ee.bottomScrollTop,atBottom:ee.isAtBottom}).action;if(fe==="blocked-by-review")return;if(fe==="noop"){H=!1;return}W(`scroll-to-bottom:start[${Q}]`),oe({type:"scroll-to-bottom",force:V.force??!1,reason:Q});const ke=Math.max(0,i.buffer.active.length-i.rows);R.internal=!0;try{i.scrollToLine(ke)}finally{R.internal=!1}const{cellH:Be}=x();Be!==0&&ye(ke,Be);const Pe=he().bottomScrollTop;t.scrollTop=Pe,P=Pe,L=i.buffer.active.baseY+i.buffer.active.cursorY,Ee(),H=!1,W("scroll-to-bottom:end",{ydisp:ke})},Qe=()=>{I=!0,W("page-resume:prepare-follow"),F()&&oe({type:"scroll-to-bottom",force:!0,reason:"pageResumePrepare"})},pt=()=>{Qe(),Wt(),we("pageResume",{force:!0}),I=!1},mt=Q=>{W("scroll-to-ratio:start");const V=Math.max(0,t.scrollHeight-t.clientHeight),Z=Math.max(0,Math.min(1,Q)),ee=V*Z;oe({type:"scroll-to-ratio",ratio:Z,scrollTop:ee}),t.scrollTop=ee,Dt()},ct=Q=>{if(Q===0)return;W("wheel");const V=Math.max(0,t.scrollHeight-t.clientHeight),Z=Math.min(V,he().bottomScrollTop);if(Z<=0){W("wheel:max-zero");return}const ee=t.scrollTop,fe=Math.max(0,Math.min(Z,ee+Q));if(fe===ee){W("wheel:clamped"),Ee();return}t.scrollTop=fe,M=fe,Dt(),oe({type:"wheel",deltaY:Q,previousScrollTop:ee,nextScrollTop:fe,reachedCursorAwareBottom:fe>ee&&fe>=Z-w&&he().isAtBottom})},dt=Q=>{if(!B()){ne("scrollToXRatio"),Ee();return}const V=Math.max(0,t.scrollWidth-t.clientWidth),Z=Math.max(0,Math.min(1,Q));t.scrollLeft=V*Z,ie(`site=scrollToXRatio ratio=${Z}`),O={...O,lastSeenLeft:t.scrollLeft},Ee()},At=(Q="external",V={})=>{const Z=t.scrollLeft,ee=Tg(O,{details:`site=resetHorizontalScroll reason=${Q}`,scrollLeft:0});O=ee.state,G(ee.trace),Z!==0&&(t.scrollLeft=0),V.holdUntilCursorVisible&&ie(`site=resetHorizontalScroll-hold reason=${Q}`),W(`horizontal-scroll-reset[${Q}]`,{details:`scrollLeft=${Z}->${t.scrollLeft}`}),Ee()},me=(Q="external")=>{ie(`site=${Q}`)};let Oe=0,it=null,tt=-1;const Je=()=>{const Q=i.buffer.active,V=`${Oe}:${Q.viewportY}:${Q.length}:${i.rows}`;return V===it||(tt=Efe(Q,i.rows),it=V),tt},Wt=()=>{const{cellH:Q,cellW:V}=x();if(Q===0||V===0)return;const{paddingTop:Z,paddingBottom:ee}=E(),fe=Math.max(0,t.clientHeight-Z-ee),ke=i.buffer.active,Be=Je(),Pe=e4({bufferLength:ke.length,rows:i.rows,cols:i.cols,viewportY:ke.viewportY,cursorY:ke.cursorY,cellH:Q,cellW:V,visibleContentHeight:fe},Be);Pe&&(T(n,"overflow","hidden"),T(n,"height",`${Pe.spacerHeight}px`),T(n,"width",`${Pe.spacerWidth}px`),T(r,"width",`${Pe.hostWidth}px`),T(r,"height",`${Pe.hostHeight}px`),T(r,"paddingTop",`${Pe.hostPaddingTop}px`),q=performance.now(),ye(ke.viewportY,Q,fe))},nn=(Q,V,Z={})=>{if(Q===i.buffer.active.viewportY){Z.deferHostUntilRender||ye(Q,V);return}R.internal=!0;try{if(Z.deferHostUntilRender){i.scrollToLine(Q);return}ye(Q,V),i.scrollToLine(Q)}finally{R.internal=!1}},Qt=()=>s()?(o(),_h($)?(we("pendingFrame"),"followed"):(l()||u(!0),"marked")):"none",Kt=(Q,V)=>{const Z=i.buffer.active;return D2(Q,{bufferLength:Z.length,rows:i.rows,cols:i.cols,viewportY:Z.viewportY,cellH:V}).ydisp},Dt=(Q={})=>{Ie(),W("container-sync:start");const{cellH:V}=x();if(V===0){H=!0;return}H=!1;const Z=Kt(t.scrollTop,V);nn(Z,V,{deferHostUntilRender:Q.deferHostUntilRender??Re()}),Ee(),W("container-sync:end",{ydisp:Z})},zt=()=>$.touchActive||_n.isRecentNativeScroll(),Mn=Q=>{if(!zt())return!1;const{cellH:V}=x();if(V===0)return!1;const Z=Kt(Q,V);return Z!==i.buffer.active.viewportY?!1:(Ye(),W("container-sync:skip[same-row-touch]",{ydisp:Z,details:`scrollTop=${Math.round(Q)} viewportY=${i.buffer.active.viewportY}`}),!0)},pn=Q=>{const V=Math.max(0,t.scrollHeight-t.clientHeight),Z=he(),ee=Ife({rawScrollTop:Q,bottomScrollTop:Z.bottomScrollTop,domMaxScrollTop:V});return ee.action==="keep"||(W("container-scroll:clamp-cursor-bottom",{details:`prev=${Q} next=${ee.scrollTop} domMax=${V}`}),t.scrollTop=ee.scrollTop,P=null,U=null),ee.scrollTop},_n=tpe({container:t,atBottomThreshold:w,trace:W,getPageResumePending:()=>I,getVerticalIntent:()=>$,dispatchVerticalIntent:oe,getCurrentAnchor:he,getLastSeenScrollTop:()=>M,hasHorizontalOverflow:B,clearHorizontalIntentIfUnscrollable:ne,markHorizontalUserInput:ie,onTouchBoundaryPrevent:b,notifyAtBottom:ge,flushPendingTouchScrollNotify:gt}),Ue=()=>O.intent?_n.getState().gestureMode==="horizontal"||_n.isRecentHorizontalGesture():!1,Ge=Q=>{const V=_n.getScrollExpectation();if(!V)return!1;const{touchStartScrollTop:Z,touchStartY:ee,currentY:fe,gestureBaseScrollTop:ke,expectedScrollTop:Be}=V,Pe=Math.abs(fe-ee)>.5,qe=Q<=w&&ke>t.clientHeight,st=parseFloat(r.style.top||"0"),lt=he(),xe=_n.getState().startedAtCursorAwareBottom&&Number.isFinite(st)&&Math.abs(Q-st)<=w&&Math.abs(lt.bottomScrollTop-st)<=t.clientHeight+w&&Math.abs(Be-Q)>hi.touch.hostTopJumpMinThresholdPx;if(!Pe&&!qe&&!xe)return!1;const je=Math.max(hi.touch.scrollJumpMinThresholdPx,t.clientHeight*1.25);return!xe&&Math.abs(Q-Be)<=je?!1:(W("container-scroll:restore-touch-impossible-jump",{details:[`scrollTop=${Math.round(Q)}`,`expected=${Math.round(Be)}`,`diff=${Math.round(Q-Be)}`,`threshold=${Math.round(je)}`,`touchStart=${Math.round(Z)}`,xe?"hostTop=1":null,`startY=${Math.round(ee)}`,`currentY=${Math.round(fe)}`].filter(Boolean).join(" ")}),t.scrollTop=Be,M=Be,Dt({deferHostUntilRender:!0}),!0)},Pt=(Q,V,Z)=>{if(V||$.touchActive||!_h($)||!(D!==null&&performance.now()-D<=hi.rawInput.recentLayoutDriftMs))return!1;const fe=he();return W("container-scroll:restore-raw-input-layout-bottom",{details:`scrollTop=${Q} bottom=${fe.bottomScrollTop}`}),oe({type:"container-scroll",source:"programmatic-bottom",scrollTop:Q,atCursorAwareBottom:V,verticalDelta:Z}),we("rawInputLayoutDrift"),!0},Nt=()=>{W("container-scroll");const Q=Dfe(O,{hasOverflow:B(),scrollLeft:t.scrollLeft,now:performance.now(),nativeIntentThresholdPx:hi.horizontal.nativeIntentThresholdPx});O=Q.state,G(Q.trace),Q.resetScrollLeft&&(t.scrollLeft=0);const V=t.scrollTop,Z=M,ee=V-M,fe=pn(V);if($.touchActive){const Pe=_n.getScrollExpectation();W("container-scroll:touch-active",{details:_n.describeScrollExpectation(Pe,V,fe,Z,ee)??`raw=${Math.round(V)} effective=${Math.round(fe)}`})}M=fe;const ke=Pfe({syncingExternal:R.external,effectiveScrollTop:fe,pendingFollowTop:U,pendingProgrammaticTop:P,atBottom:he().isAtBottom,canPassiveFollow:_h($)});if(U=ke.nextPendingFollowTop,P=ke.nextPendingProgrammaticTop,ke.action==="external-sync"){oe({type:"container-scroll",source:"external-sync",scrollTop:fe,atCursorAwareBottom:he().isAtBottom,verticalDelta:ee}),Ee();return}if(ke.action==="programmatic-follow"){oe({type:"container-scroll",source:"programmatic-follow",scrollTop:fe,atCursorAwareBottom:he().isAtBottom,verticalDelta:ee}),Ee();return}const Be=he().isAtBottom;if(ke.action==="programmatic-drift"){oe({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Be,verticalDelta:ee}),we("programmaticDrift");return}if(!Ge(fe)&&!Pt(fe,Be,ee)){if(I){W("container-scroll:page-resume-pending",{details:`scrollTop=${fe} bottom=${he().bottomScrollTop}`}),oe({type:"container-scroll",source:"programmatic-bottom",scrollTop:fe,atCursorAwareBottom:Be,verticalDelta:ee}),Dt();return}oe({type:"container-scroll",source:"user",scrollTop:fe,atCursorAwareBottom:Be,verticalDelta:ee}),!Mn(fe)&&Dt()}},J=()=>{if(W("term-scroll"),!R.internal){R.external=!0;try{Wt();const Q=Qt();if(Q==="followed")return;if(Q==="none"&&_h($)){we("termScroll");return}const{cellH:V}=x();if(V!==0){const Z=i.buffer.active,{ydisp:ee}=D2(t.scrollTop,{bufferLength:Z.length,rows:i.rows,cols:i.cols,viewportY:Z.viewportY,cellH:V,cellW:1});nn(ee,V)}Ee()}finally{R.external=!1}}},ve=()=>{Wt();const Q=Qt();if(Q==="followed")return;if(Q==="none"&&_h($)){we("relayout");return}const{cellH:V}=x();if(V!==0)if(H)W("pending-sync-retry-fire"),Dt();else{const Z=Kt(t.scrollTop,V),ee=Rfe(i.buffer.active.viewportY,V);Z!==i.buffer.active.viewportY?t.scrollTop=ee:Math.abs(t.scrollTop-ee)>1&&W("relayout:preserve-host-offset",{details:`scrollTop=${Math.round(t.scrollTop)} viewportTop=${Math.round(ee)} ydisp=${Z}`}),ye(i.buffer.active.viewportY,V)}Ee()},He=()=>{const{cellH:Q}=x(),{paddingTop:V,paddingBottom:Z}=E(),ee=Math.max(0,t.clientHeight-V-Z),fe=i.buffer.active,ke=fe.baseY+fe.cursorY,Be=L,Pe=he(),qe=Ufe({reviewing:F(),cellH:Q,rows:i.rows,visibleContentHeight:ee,cursorBufferRow:ke,prevCursorBufferRow:L,cursorInViewport:Pe.cursorInViewport,targetScrollTop:Pe.bottomScrollTop,currentScrollTop:t.scrollTop});if(qe.reason==="intent"){L=qe.nextPrevCursorBufferRow,W("followCursorY:skip",{details:qe.reason});return}if(qe.reason==="cellH=0"){W("followCursorY:skip",{details:qe.reason});return}if(qe.reason==="shortHost"){L=qe.nextPrevCursorBufferRow,W("followCursorY:skip",{details:qe.reason});return}if(qe.reason==="same-row"){W("followCursorY:skip[same-row]",{cursorDeltaRows:qe.cursorDeltaRows,details:`cursorRow=${ke} same-row`});return}if(L=qe.nextPrevCursorBufferRow,qe.reason==="inViewport"){W("followCursorY:skip",{cursorDeltaRows:qe.cursorDeltaRows,details:`cursorRow=${Be??"null"}->${ke} inViewport`});return}if(qe.reason==="aligned"){W("followCursorY:skip",{cursorDeltaRows:qe.cursorDeltaRows,details:`cursorRow=${Be??"null"}->${ke} aligned`});return}if(qe.action!=="follow")return;U=qe.targetScrollTop;const st=t.scrollTop;t.scrollTop=qe.targetScrollTop,W("followCursorY:hit",{cursorDeltaRows:qe.cursorDeltaRows,scrollDeltaToAnchor:st-qe.targetScrollTop,details:`cursorRow=${Be??"null"}->${ke} scrollTop=${Math.round(st)}->${Math.round(qe.targetScrollTop)}`})},ut=()=>{if(!B()){ne("followCursorX");return}const{cellW:Q}=x();if(Q<=0)return;const V=i.buffer.active.cursorX*Q,Z=t.scrollLeft,ee=Z+t.clientWidth;if(V>=Z&&V<=ee){if(Ue()){W("followCursorX:skip",{details:`horizontalTouchIntent cursorPx=${V} viewport=${Z}..${ee}`});return}const qe=Tg(O,{details:`site=followCursorX cursorPx=${V} viewport=${Z}..${ee}`,scrollLeft:t.scrollLeft});O=qe.state,G(qe.trace),W("followCursorX:skip",{details:"cursorInViewport"});return}if(O.intent){W("followCursorX:skip",{details:`horizontalIntent cursorPx=${V} viewport=${Z}..${ee}`});return}const ke=Math.max(0,V-t.clientWidth/2),Be=Math.max(0,t.scrollWidth-t.clientWidth),Pe=Math.min(Be,ke);O=Ofe(O,Pe),t.scrollLeft=Pe,W("followCursorX:hit",{details:`cursorPx=${V} viewport=${Z}..${ee} target=${Pe}`})},Bt=()=>{W("render"),Wt(),H&&(W("pending-sync-retry-fire"),Dt()),Qt(),ut(),He(),Ee()};Wt(),F()?Ee():we("init");const ae=zfe({container:t,term:i,onWheel:Q=>{B()&&Math.abs(Q.deltaX)>0&&Math.abs(Q.deltaX)>=Math.abs(Q.deltaY)&&ie(`site=wheel deltaX=${Q.deltaX}`),Q.deltaY!==0&&(W("wheel:enter"),Q.preventDefault(),Q.stopPropagation(),ct(Q.deltaY))},onTouchStart:_n.onTouchStart,onTouchMove:_n.onTouchMove,onTouchEnd:_n.onTouchEnd,onTouchCancel:_n.onTouchCancel,onContainerScroll:Nt,onTermScroll:J,onRender:Bt,onRelayout:ve,onWriteParsed:()=>{Oe+=1}});return{dispose:()=>{ae.dispose(),A.dispose(),Ie()},relayout:ve,scrollToBottom:we,preparePageResumeRestore:Qe,restorePageResume:pt,scrollToRatio:mt,scrollToXRatio:dt,resetHorizontalScroll:At,markHorizontalScrollIntent:me,traceRawInputFollowScheduled:Me,traceRawInputFollowFire:de,getDebugProbe:()=>{const{cellH:Q,cellW:V}=x(),{paddingTop:Z,paddingBottom:ee}=E();return{cellH:Q,cellW:V,paddingTop:Z,paddingBottom:ee,canvasLastY:Q>0&&V>0?Je():-1,userHasVerticalScrollIntent:F(),verticalIntentMode:$.mode,verticalIntentSource:$.source,verticalIntentTransitionId:$.lastTransitionId,userHasHorizontalScrollIntent:O.intent,pendingProgrammaticScrollTop:P,pendingFollowCursorScrollTop:U,pendingFollowCursorScrollLeft:O.pendingFollowLeft,prevCursorBufferRow:L,lastSeenScrollTop:M,lastSeenScrollLeft:O.lastSeenLeft,touchScrollActive:$.touchActive,touchScrollGestureMode:_n.getState().gestureMode,syncingInternal:R.internal,syncingExternal:R.external,atBottomThreshold:w,lastSpacerUpdateAt:q,pendingContainerSyncRetry:H}}}}function rpe(e,t={}){const{onFramePending:n,onFrameWritten:r,paused:i=!1,schedule:s=w=>requestAnimationFrame(w),cancel:o=w=>cancelAnimationFrame(w)}=t;let l=null,u=!1,d=i,h=[],p=[];const y=()=>{h=[],p=[],l!==null&&(o(l),l=null)},g=()=>{if(l=null,u||h.length===0)return;const w=h,x=p;h=[],p=[];const E=w.reduce((R,z)=>R+z.byteLength,0),k=new Uint8Array(E);let T=0;for(const R of w)k.set(R,T),T+=R.byteLength;e.write(k,()=>{for(const R of x)R();r==null||r()})},b=()=>{u||d||l!==null||h.length===0||(l=s(g))};return{target:{reset:()=>{y(),e.reset()},resize:(w,x)=>e.resize(w,x),write:(w,x)=>{if(typeof w=="string"){e.write(w,x);return}const E=h.length===0;h.push(w),x&&p.push(x),E&&(n==null||n()),b()}},clear:y,flush:()=>{l!==null&&(o(l),l=null),g()},setPaused:w=>{d!==w&&(d=w,d||b())},dispose:()=>{u=!0,y()}}}const I2=5e3,ipe=1e3;function spe(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 g=o.get(y);o.delete(y),l=y,h.write(g),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>I2&&s.splice(0,s.length-I2),{written:!1,hasGap:!1};if(h.outputSeq<=l)return{written:!1,hasGap:!1};if(o.set(h.outputSeq,h.data),o.size>ipe){const g=o.keys().next().value;g!==void 0&&o.delete(g)}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 g=u,b=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(g===u){for(const w of b)o.set(w.outputSeq,w.data);d(p)}}),{applied:!0,replayedFrames:b.length}}}}function ope(e){const{sessionId:t,ws:n,relay:r,target:i,retryDelayMs:s=3e4,slowNoticeDelayMs:o=1e4,gapRecoveryDelayMs:l=2e3,scheduleReady:u=F=>requestAnimationFrame(F),scheduleFrameFlush:d,cancelFrameFlush:h,onFramePending:p,onFrameWritten:y,onReady:g,onSubscribeDelayed:b,onSubscribeStarted:w,onGapRecovery:x}=e,E=spe(),T=rpe({reset:()=>i.reset(),resize:(F,A)=>i.resize(F,A),write:(F,A)=>{i.write(F,()=>{F instanceof Uint8Array&&Wse(t,F.byteLength),A==null||A()})}},{onFramePending:p,onFrameWritten:y,schedule:d,cancel:h});let R=!1,z=null,N=null,$=null,P=!1;const q=()=>{z&&(clearTimeout(z),z=null)},H=()=>{N&&(clearTimeout(N),N=null)},U=()=>{$&&(clearTimeout($),$=null)},O=()=>{$||($=setTimeout(()=>{$=null,!(R||!E.hasPendingGap())&&(x==null||x(),D())},l))},M=()=>{const F=E.startSnapshotRequest();n.send(JSON.stringify({type:"session_subscribe",sessionId:t,requestId:F}))},I=()=>{z=setTimeout(()=>{z=null,!(R||E.hasAppliedSnapshot())&&(M(),I())},s)},L=()=>{N=setTimeout(()=>{N=null,!(R||E.hasAppliedSnapshot()||P)&&(P=!0,b==null||b())},o)},D=()=>{R||(q(),H(),U(),T.clear(),P=!1,w==null||w(),M(),I(),L())},Y=n.subscribeBinary(t,(F,A)=>{if(R)return;Use(t,F,A),E.handleBinaryFrame({data:F,outputSeq:A},T.target).hasGap?O():U()}),K=r.onMessage(F=>{if(R||F.sessionId!==t)return;if(F.type==="terminal_resize"){T.target.resize(F.cols,F.rows),D();return}F.type!=="session_snapshot"||!E.applySnapshot({requestId:F.requestId,cols:F.cols,rows:F.rows,data:F.data,outputSeq:F.outputSeq},T.target).applied||(q(),H(),u(()=>{R||g==null||g()}))});return D(),{flushOutput:()=>T.flush(),setOutputPaused:F=>T.setPaused(F),dispose:()=>{R=!0,q(),H(),U(),T.dispose(),Y(),K()}}}function ape(e){const{host:t,sessionId:n,ws:r,relay:i,createTerminal:s,attachRawInput:o,attachTransport:l=ope,scheduleAutoFocus:u=q=>requestAnimationFrame(q),onTerminalReady:d,onFramePending:h,onFrameWritten:p,onRawInput:y,isInputEnabled:g,canFocus:b=()=>!0,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E,onError:k}=e;let T=!1,R=null,z=null,N=null,$=null,P=!1;return(async()=>{try{const q=await s(t);if(T){q.dispose();return}R=q.dispose,z=o(q.terminal,n,{onRawInput:y,...g?{isInputEnabled:g}:{}}).dispose;const H=()=>{b()&&q.terminal.focus()};t.addEventListener("pointerdown",H,{passive:!0}),$=()=>t.removeEventListener("pointerdown",H),d==null||d(q.terminal),u(()=>{T||H()}),N=l({sessionId:n,ws:r,relay:i,target:q.terminal,onFramePending:h,onFrameWritten:p,onReady:w,onSubscribeStarted:x,onSubscribeDelayed:E}),N.setOutputPaused(P)}catch(q){console.error("[pty-terminal-controller] initialization failed",q),k==null||k(q)}})(),{flushOutput:()=>N==null?void 0:N.flushOutput(),setOutputPaused:q=>{P=q,N==null||N.setOutputPaused(q)},dispose:()=>{T=!0,N==null||N.dispose(),$==null||$(),z==null||z(),R==null||R()}}}function cE(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 lpe=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*?\\.(?:png|jpe?g|webp|gif)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","gi"),cpe=/\.(?:png|jpe?g|webp|gif)$/i;function r4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function upe(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 uE(e){const t=r4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||cE(t)||!cpe.test(t)?!1:upe(t)}function dpe(e){const t=new Set,n=[];for(const r of e.matchAll(lpe)){const i=r4(r[0]??"");!uE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const iv=16,hpe=8,fpe=/(?:^|[\s([{@])@?(?:\/|\.\/|\.\.\/|~\/|\.dev-anywhere\/)[A-Za-z0-9_./~%+,:=#-]*$/,ppe=/^[A-Za-z0-9_./~%+,:=#-]+$/;function i4(e,t,n){const r=[gpe(e,t),...vpe(e,t)].filter(s=>s!==null),i=new Set;return r.flatMap(s=>{const o=s.parts.map(l=>l.text).join("");return mpe(o,n).map(l=>{const u=wpe(s.parts,l.startIndex),d=Spe(s.parts,l.endIndex);return!u||!d?null:{path:l.path,startLineNumber:u.lineNumber,startColumn:u.column,endLineNumber:d.lineNumber,endColumn:d.column,segments:xpe(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 s4(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 mpe(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 gpe(e,t){const n=e.buffer.active;let r=t,i=t;for(let s=0;s<iv;s+=1){const o=n.getLine(r-1);if(!(o!=null&&o.isWrapped)||r<=1)break;r-=1}for(let s=0;s<iv;s+=1){const o=n.getLine(i);if(!(o!=null&&o.isWrapped))break;i+=1}return HS(e,r,i)}function HS(e,t,n){const r=e.buffer.active;let i=n??t;if(n===void 0)for(let o=0;o<iv;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 vpe(e,t){const n=e.buffer.active,r=[],i=Math.max(1,t-iv);for(let s=i;s<=t;s+=1){const o=n.getLine(s-1);if(!o||o.isWrapped)continue;const l=ype(e,s);l&&t>=l.startLineNumber&&t<=l.endLineNumber&&r.push(l)}return r}function ype(e,t){const n=HS(e,t);if(!n)return null;const r=n.parts.map(l=>l.text).join("");if(!fpe.test(r))return null;const i=[...n.parts];let s=n.endLineNumber,o=!1;for(let l=0;l<hpe;l+=1){const u=s+1,d=HS(e,u);if(!d)break;const h=d.parts[0];if(!h)break;const p=_pe(h.sourceText),y=h.sourceText.slice(p);if(!bpe(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 _pe(e){var t;return((t=e.match(/^\s*/))==null?void 0:t[0].length)??0}function bpe(e,t){return e<2||!t||t.startsWith("-")||t.startsWith("•")||t.startsWith("›")||t.includes("://")?!1:ppe.test(t)}function wpe(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:US(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:US(s.sourceText,s.sourceStartIndex)}:null}n-=i.text.length}}return null}function Spe(e,t){let n=t-1;for(const r of e){if(n<r.text.length)return{lineNumber:r.lineNumber,column:dE(r.sourceText.slice(0,r.sourceStartIndex+n+1))};n-=r.text.length}return null}function xpe(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:US(s.sourceText,s.sourceStartIndex+d),endColumn:dE(s.sourceText.slice(0,s.sourceStartIndex+h))})}i=o}return r}function US(e,t){return dE(e.slice(0,t))+1}function dE(e){let t=0;for(const n of e)t+=Epe(n.codePointAt(0)??0);return t}function Epe(e){return e===0||e<32||e>=127&&e<160||Cpe(e)?0:kpe(e)?2:1}function Cpe(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function kpe(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 o4(e,t){return i4(e,t,dpe)}function Tpe(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 Rpe(e,t){const n={provideLinks(i,s){const o=o4(e,i);if(o.length===0){s(void 0);return}const l=o.reduce((u,d)=>{for(const h of s4(d))h.start.y!==i||h.end.y!==i||u.push({text:d.path,range:h,decorations:{underline:!0,pointerCursor:!0},activate:p=>{Tpe(p)&&t(d.path)}});return u},[]);s(l.length>0?l:void 0)}},r=e.registerLinkProvider(n);return{dispose:()=>r.dispose(),provider:n}}const Ape=new RegExp("(?<![A-Za-z0-9@:/.-])@?(?:~\\/|[A-Za-z0-9_./])[A-Za-z0-9_./~%+,:=#-]*\\.[A-Za-z0-9]{1,8}(?=[\\s`\"'<>),.;:!?,。;:!?、]|$)","gi"),Npe=/\.(?:png|jpe?g|webp|gif)$/i,Mpe=/\.[A-Za-z0-9]{1,8}$/,Ope=/^(?: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,Dpe=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 a4(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function Ppe(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 Lpe(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 Ope.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function Ipe(e){return e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/")||e.includes("/")}function zpe(e){return Ipe(e)?!0:Dpe.has(e.toLowerCase())}function hE(e){const t=a4(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||cE(t)||Lpe(t)||Npe.test(t)||!Mpe.test(t)||!zpe(t)||t.split("/").includes("...")?!1:Ppe(t)}function Bpe(e){const t=new Set,n=[];for(const r of e.matchAll(Ape)){const i=a4(r[0]??"");!hE(i)||t.has(i)||(t.add(i),n.push(i))}return n}const jpe=750;function l4(e,t){return i4(e,t,Bpe)}function Fpe(e){return e.metaKey||e.ctrlKey}function $pe(e,t){let n=null;const r=(o,l)=>{if(!Fpe(l))return;const u=performance.now();(n==null?void 0:n.path)===o&&u-n.at<jpe||(n={path:o,at:u},t(o))},i={provideLinks(o,l){const u=l4(e,o);if(u.length===0){l(void 0);return}const d=u.reduce((h,p)=>{for(const y of s4(p))y.start.y!==o||y.end.y!==o||h.push({text:p.path,range:y,decorations:{underline:!1,pointerCursor:!0},hover:()=>{Hpe(e,p)},leave:()=>{Rg(e)},dispose:()=>{Rg(e)},activate:g=>{r(p.path,g)}});return h},[]);l(d.length>0?d:void 0)}},s=e.registerLinkProvider(i);return{dispose:()=>{Rg(e),s.dispose()},provider:i}}function Hpe(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;Rg(e),Upe(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 g=y.lineNumber-p;if(g<1||g>e.rows)continue;const b=document.createElement("div");b.dataset.slot="pty-file-link-hover-segment",b.dataset.range=`${y.lineNumber}:${y.startColumn}-${y.endColumn}`,b.style.position="absolute",b.style.left=`${d+(y.startColumn-1)*o}px`,b.style.top=`${h+(g-1)*l+l-2}px`,b.style.width=`${Math.max(1,y.endColumn-y.startColumn+1)*o}px`,b.style.height="2px",b.style.background="currentColor",b.style.opacity="0.8",u.append(b)}}function Rg(e){var t;(t=e.element)==null||t.querySelectorAll('[data-slot="pty-file-link-hover-overlay"]').forEach(n=>n.remove())}function Upe(e){window.getComputedStyle(e).position==="static"&&(e.style.position="relative")}function Ya(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 Wpe(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 qpe(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 c4(e,t,n){if(t.length===0)return Ya("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 Ya("skip",{reason:"missing-elements",hasScreen:!!i,hasMetricHost:!!s,point:n}),null;const o=ry(s,e);if(!o||o.cellW<=0||o.cellH<=0)return Ya("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 Ya("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};Ya("probe",{point:n,viewportX:u,viewportY:d,bufferLineNumber:h,providers:t.length,metrics:o});for(const y of t){let g=null;if(y.provideLinks(h,b=>{Ya("links",{bufferLineNumber:h,position:p,count:(b==null?void 0:b.length)??0,links:b==null?void 0:b.map(x=>({text:x.text,range:x.range}))});const w=b==null?void 0:b.find(x=>Wpe(x,p,e.cols));w&&(g=w)}),g)return g}return Ya("miss",{position:p,point:n,bufferLineNumber:h}),null}function Vpe(e,t,n){return c4(e,t,n)!==null}function Ype(e,t,n){const r=c4(e,t,n);return r?(r.activate(qpe(n),r.text),Ya("activate",{text:r.text,range:r.range,point:n}),!0):!1}async function xf(e){const t=nt.loading(`上传 ${e.file.name} ...`);try{const n=await e.relay.uploadFile(e.sessionId,e.file);return!n.success||!n.path?(nt.error(n.error??"上传失败",{id:t}),null):(e.successLabel===null?nt.dismiss(t):nt.success(e.successLabel??`已上传 ${n.path}`,{id:t}),n.path)}catch(n){return nt.error(n instanceof Error?n.message:String(n),{id:t}),null}}function z2(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 B2="--dev-visual-viewport-height",Kpe=.3;function u4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i=!0}){const s=e-t-n,o=r-t-n,l=j2(s,e),u=i?j2(o,r):0;return Math.max(l,u)}function Gpe({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r=e,allowBaselineFallback:i=!1}){return u4({layoutViewportHeight:e,visualViewportHeight:t,visualViewportOffsetTop:n,baselineViewportHeight:r,allowBaselineFallback:i})}function j2(e,t){const n=Math.max(e,0);return n<=0?0:n/Math.max(t,1)>=Kpe?n:0}function Xpe(){_.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(B2,`${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(B2)}},[])}function F2(){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 Zpe(){_.useEffect(()=>{const e=window.visualViewport;let t=0;const n=()=>{F2(),cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,F2()})};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 Qpe(){return fE().bottomOffset}function fE(){const[e,t]=_.useState({bottomOffset:0,layoutBottomInset:0}),n=_.useRef(0),r=_.useRef(0);return _.useEffect(()=>{const i=window.visualViewport;if(!i)return;const s=Jpe();let o=0;const l=()=>{const h=i.height,p=i.offsetTop,y=i.width,g=Math.max(window.innerHeight,h+p);!n.current||Math.abs(y-r.current)>1?(n.current=g,r.current=y):n.current=Math.max(n.current,g);const b=window.innerHeight,w=eme(),x=!s||w,E=s&&w,k={bottomOffset:u4({layoutViewportHeight:b,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:x}),layoutBottomInset:Gpe({layoutViewportHeight:b,visualViewportHeight:h,visualViewportOffsetTop:p,baselineViewportHeight:n.current,allowBaselineFallback:E})};t(T=>T.bottomOffset===k.bottomOffset&&T.layoutBottomInset===k.layoutBottomInset?T:k)},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 Jpe(){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 eme(){const e=document.activeElement;return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function tme(e){window.__devAnywherePtyTerminal=e}function nme(){window.__devAnywherePtyTerminal&&delete window.__devAnywherePtyTerminal}function rme(e){window.__devAnywherePtyDebug=e}function ime(){window.__devAnywherePtyDebug&&delete window.__devAnywherePtyDebug}function sme(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),g=o.buffer.active;let b=0;if(l>0&&u>0){const I=e4({bufferLength:g.length,rows:o.rows,cols:o.cols,viewportY:g.viewportY,cursorY:g.cursorY,cellH:l,cellW:u,visibleContentHeight:y},p);b=(I==null?void 0:I.spacerHeight)??0}const w=Ii(i.style.height),x=Ii(s.style.top),E=Ii(s.style.height),k=Ii(s.style.width),T=Ii(s.style.paddingTop),R=Ii(i.style.width);let z=0;if(l>0){const I=o.rows*l,L=I>0&&I<y?y-I:0;z=Math.max(0,g.viewportY*l+L)}const N=x-z,$=r.scrollTop,P=$+r.clientHeight,q=x+E,H=Math.max(0,Math.min(P,q)-Math.max($,x)),U=r.clientHeight>0?H/r.clientHeight:0,O=g.baseY+g.cursorY,M=lE({rows:o.rows,cellH:l,bufferLength:g.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:R},host:{top:x,height:E,width:k,paddingTop:T,expectedTop:z,topDrift:N},term:{rows:o.rows,cols:o.cols,bufferLength:g.length,viewportY:g.viewportY,baseY:g.baseY,cursorX:g.cursorX,cursorY:g.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:b,spacerDrift:w-b,lastSpacerUpdateAt:n.lastSpacerUpdateAt,viewportHostCoverage:U,pendingContainerSyncRetry:n.pendingContainerSyncRetry}}const iy={enabled:!1,phase:"idle",error:null,lastSpokenText:"",approvalRequestId:null,activityLevel:0,waveform:[],resumeRequestSeq:0};function ome(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function Hs(e,t,n){const r=e.bySessionId[t]??iy;return{bySessionId:{...e.bySessionId,[t]:n(r)}}}const on=Ju()(ed(e=>({bySessionId:{},enable:t=>e(n=>Hs(n,t,r=>({...r,enabled:!0,phase:"starting",error:null,waveform:[]}))),disable:t=>e(n=>Hs(n,t,r=>({...r,enabled:!1,phase:"idle",error:null,approvalRequestId:null,activityLevel:0,waveform:[]}))),requestResume:t=>e(n=>Hs(n,t,r=>({...r,resumeRequestSeq:r.resumeRequestSeq+1}))),setPhase:(t,n)=>e(r=>Hs(r,t,i=>({...i,phase:n,error:n==="error"?i.error:null}))),setError:(t,n)=>e(r=>Hs(r,t,i=>({...i,phase:"error",error:n,activityLevel:0,waveform:[]}))),clearError:t=>e(n=>Hs(n,t,r=>({...r,error:null,phase:r.enabled&&r.phase==="error"?"starting":r.phase}))),setLastSpokenText:(t,n)=>e(r=>Hs(r,t,i=>({...i,lastSpokenText:n}))),setApproval:(t,n)=>e(r=>Hs(r,t,i=>({...i,approvalRequestId:n}))),setActivityLevel:(t,n)=>e(r=>Hs(r,t,i=>({...i,activityLevel:ome(n)}))),appendWaveform:(t,n)=>{n.length!==0&&e(r=>Hs(r,t,i=>({...i,waveform:[...i.waveform,...n].slice(-$0)})))},clearWaveform:t=>e(n=>Hs(n,t,r=>({...r,waveform:[]}))),resetAll:()=>e({bySessionId:{}})}),{name:"voice-pilot-store"}));function ame(){const[e,t]=_.useState(!1),[n,r]=_.useState(!1),[i,s]=_.useState(!1);_.useEffect(()=>{if(e){r(!1);return}const p=setTimeout(()=>r(!0),300);return()=>clearTimeout(p)},[e]);const o=_.useCallback(()=>{t(!0),s(!1)},[]),l=_.useCallback(()=>{t(!1),s(!1)},[]),u=_.useCallback(()=>{s(!0)},[]),d=_.useMemo(()=>({connecting:n,subscribeDelayed:i}),[n,i]),h=_.useMemo(()=>({onReady:o,onSubscribeStarted:l,onSubscribeDelayed:u}),[o,u,l]);return{ready:e,overlay:d,transport:h}}const lme=900;function cme(){var t;const e=navigator.virtualKeyboard;(t=e==null?void 0:e.show)==null||t.call(e)}function ume(e){const{containerEl:t,xtermHostRef:n,terminalRef:r}=e,[i,s]=_.useState(!1),o=_.useRef(0),l=_.useCallback(()=>{const g=document.activeElement;!t||!(g instanceof HTMLElement)||!t.contains(g)||g.blur()},[t]),u=_.useCallback(()=>{const g=n.current,b=document.activeElement,w=!!(g&&b instanceof HTMLElement&&g.contains(b));s(w),w&&cme()},[n]),d=_.useCallback((g={})=>{o.current=performance.now()+lme,(g.blur??!0)&&(l(),s(!1))},[l]),h=_.useCallback(g=>{if(performance.now()<=o.current){g.target instanceof HTMLElement&&g.target.blur(),window.setTimeout(u,0);return}u()},[u]),p=_.useCallback(()=>{window.setTimeout(u,0)},[u]),y=_.useCallback(()=>{var g;o.current=0,(g=r.current)==null||g.focus(),window.setTimeout(u,0)},[u,r]);return{ptyInputFocused:i,suppressPtyFocus:d,focusPtyInput:y,handleFocusCapture:h,handleBlurCapture:p}}function dme(){const[e,t]=_.useState(!0),[n,r]=_.useState(!1),i=_.useRef(n);_.useEffect(()=>{i.current=n},[n]);const s=_.useCallback(l=>{t(l),l&&r(!1)},[]),o=_.useCallback(()=>{r(!1)},[]);return{isAtBottom:e,hasNewFramesWhileAway:n,hasNewFramesWhileAwayRef:i,setHasNewFramesWhileAway:r,handleAtBottomChange:s,clearNewFramesWhileAway:o}}async function d4(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&&hme(e)?"legacy":"failed"}function hme(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()}}function h4({terminal:e,host:t,cellWidth:n,cellHeight:r}){return n&&r?{cellW:n,cellH:r}:ry(t,e)}function $2(e,t){var n;return(((n=e.getCell(t))==null?void 0:n.getChars())??"").trim().length>0}function fme(e,t){const n=Math.min(e.length,t),r=[];let i=0;for(;i<n;){for(;i<n&&!$2(e,i);)i+=1;if(i>=n)break;const s=i;for(;i+1<n&&$2(e,i+1);)i+=1;r.push({start:s,end:i}),i+=1}return r}function pme(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 mme(e,t,n){const s=e[t];if(!s)return{start:0,end:0};if(s.end-s.start+1>=18)return s;let o=t,l=t;const u=()=>e[l].end-e[o].start+1,d=()=>l-o+1;for(;u()<18&&d()<3;){const h=o>0?e[o-1]:null,p=l+1<e.length?e[l+1]:null;if(!h&&!p)break;if(h&&p){const y=Math.max(0,n-h.end),g=Math.max(0,p.start-n);y<=g?o-=1:l+=1}else h?o-=1:l+=1}return{start:e[o].start,end:e[l].end}}function gme(e,t){return e.row<t.row||e.row===t.row&&e.column<=t.column?{start:e,end:t}:{start:t,end:e}}function vme(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(`
633
633
  `).replace(/\s+$/,"")}function Wh({terminal:e,host:t,clientX:n,clientY:r,cellWidth:i,cellHeight:s}){const o=t.querySelector(".xterm-screen");if(!o)return null;const l=h4({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 H2({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=h4({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 sv({terminal:e,anchor:t,focus:n}){var u;const{start:r,end:i}=gme(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))||vme(e,r,i);return l.trim()?{anchor:t,focus:n,text:l}:null}function U2({terminal:e,host:t,clientX:n,clientY:r,cellWidth:i,cellHeight:s}){const o=Wh({terminal:e,host:t,clientX:n,clientY:r,cellWidth:i,cellHeight:s});return o?WS({terminal:e,point:o}):null}function WS({terminal:e,point:t}){const n=e.buffer.active.getLine(t.row);if(!n)return null;const r=fme(n,e.cols),i=pme(r,t.column);if(i===null)return null;const s=mme(r,i,t.column);return sv({terminal:e,anchor:{row:t.row,column:s.start},focus:{row:t.row,column:s.end}})}function W2({terminal:e,point:t}){const n=t.row+1,r=t.column+1,i=[...o4(e,n).map(o=>({match:o,pathAction:{kind:"image-preview",path:o.path}})),...l4(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=sv({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 q2(e,t,n){return t>n?(t+n)/2:Math.min(Math.max(e,t),n)}const yme=64;function f4({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-yme;return{left:q2(e,o,l),top:q2(t-48,u,d)}}function _me(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 bme({terminal:e,host:t,anchor:n,focus:r}){const i=H2({terminal:e,host:t,point:n,affinity:"before"}),s=H2({terminal:e,host:t,point:r,affinity:"after"});return!i||!s?null:{anchor:i,focus:s}}function wme({handles:e,viewportWidth:t,viewportHeight:n,viewportOffsetLeft:r=0,viewportOffsetTop:i=0}){return f4({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 Sme=/\.(?:png|jpe?g|webp|gif)$/i,p4=/\.[A-Za-z0-9]{1,8}$/,xme=/^(?: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 Eme(e){return e.trim().replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function Cme(e){const t=e.trim();if(!t||t.includes(`
634
634
  `))return null;const n=Eme(t);return!n||/\s/.test(n)||/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||cE(n)||n.split("/").includes("...")?null:n}function kme(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 xme.test(n)?t.every(r=>/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(r)):!1}function Tme(e){if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../")||e.startsWith("~/")||e.startsWith(".dev-anywhere/"))return!0;const t=e.replace(p4,""),n=t.split("/").pop()??t;return/[A-Za-z_-]/.test(n)}function Rme(e){const t=Cme(e);return!t||kme(t)||!Tme(t)?null:Sme.test(t)?{kind:"image-preview",path:t}:p4.test(t)?{kind:"file-download",path:t}:null}const Ame=16,Nme=24,wh=6,Mme=425,qh=-1;function Zm(e,t){return e.pointerId===t||t===qh}function pu(e){return Math.hypot(e.lastX-e.startX,e.lastY-e.startY)}function Mi(e,t={}){const n=window.__ccTestPtyTouchGestureEvents;n&&(n.push({event:e,t:performance.now(),...t}),n.length>200&&n.splice(0,n.length-200))}function Ome({terminalRef:e,suppressPtyFocus:t,focusTerminal:n,onLongPressCandidateStart:r,onTap:i,isTapCandidate:s,onLongPressStart:o,onLongPressMove:l,onLongPressEnd:u}){const d=_.useRef(null),h=_.useCallback(U=>{U.longPressTimer!==null&&(window.clearTimeout(U.longPressTimer),U.longPressTimer=null)},[]),p=_.useCallback(U=>{U.longPressed||U.moved||(U.longPressed=!0,U.longPressArmed=!1,h(U),t(),o==null||o({clientX:U.startX,clientY:U.startY}))},[h,o,t]),y=_.useCallback(U=>{if(!(U.longPressed||U.longPressArmed||U.moved)){if(pu(U)>wh){h(U),Mi("longpress:cancel-drift",{distance:pu(U),threshold:wh});return}if(s!=null&&s({clientX:U.startX,clientY:U.startY})){U.longPressArmed=!0,h(U),Mi("longpress:arm-link",{clientX:U.startX,clientY:U.startY});return}p(U)}},[h,s,p]),g=_.useCallback(U=>{if(U.longPressDelivered||!U.longPressed||U.moved)return;U.longPressDelivered=!0;const O={clientX:U.lastX,clientY:U.lastY};window.setTimeout(()=>u==null?void 0:u(O),0)},[u]),b=_.useCallback((U,O,M,I=!1)=>{const L={pointerId:U,startX:O,startY:M,lastX:O,lastY:M,moved:!1,longPressArmed:!1,longPressed:!1,longPressDelivered:!1,touchEventStream:I,longPressTimer:null};L.longPressTimer=window.setTimeout(()=>{d.current===L&&y(L)},Mme),d.current=L,Mi("start",{pointerId:U,clientX:O,clientY:M,touchEventStream:I}),r==null||r({clientX:O,clientY:M})},[y,r]),w=_.useCallback((U,O,M)=>{const I=d.current;if(!I||!Zm(I,U))return!1;I.lastX=O,I.lastY=M;const L=pu(I);if(I.longPressArmed&&L>wh&&(I.longPressArmed=!1,Mi("longpress:cancel-armed-drift",{pointerId:U,clientX:O,clientY:M,distance:L,threshold:wh})),I.longPressed)return Mi("move",{pointerId:U,clientX:O,clientY:M,distance:L,moved:I.moved,longPressed:!0}),l==null||l({clientX:O,clientY:M}),!0;const D=O-I.startX,Y=M-I.startY;return!I.moved&&L>=Ame&&(I.moved=!0,h(I)),Mi("move",{pointerId:U,clientX:O,clientY:M,dx:D,dy:Y,distance:L,moved:I.moved,longPressed:!1}),I.moved},[h,l]),x=_.useCallback((U,O)=>{var D;const M=d.current;if(!M||!Zm(M,U))return null;O&&(M.lastX=O.clientX,M.lastY=O.clientY),d.current=null,h(M);const I=pu(M);let L;if(M.longPressArmed){if(I<=wh)return p(M),g(M),L="longpress",Mi("finish",{pointerId:U,result:L,point:O,moved:M.moved,distance:I,longPressed:!0,longPressArmed:!0}),L;M.longPressArmed=!1}return M.longPressed?(g(M),L="longpress",Mi("finish",{pointerId:U,result:L,point:O,moved:M.moved,longPressArmed:M.longPressArmed,distance:I,longPressed:!0}),L):M.moved?O&&pu(M)<=Nme&&(i!=null&&i(O))?(t(),L="link",Mi("finish",{pointerId:U,result:L,point:O,moved:!0,distance:I,longPressed:!1}),L):(t(),L="scroll",Mi("finish",{pointerId:U,result:L,point:O,moved:!0,distance:I,longPressed:!1}),L):O&&(i!=null&&i(O))?(t(),L="link",Mi("finish",{pointerId:U,result:L,point:O,moved:!1,distance:I,longPressed:!1}),L):(n?n():(D=e.current)==null||D.focus(),L="tap",Mi("finish",{pointerId:U,result:L,point:O,moved:!1,distance:I,longPressed:!1}),L)},[h,g,n,i,p,t,e]),E=_.useCallback(U=>{const O=d.current;return!O||!Zm(O,U)?null:(h(O),d.current=null,O.longPressed?(g(O),Mi("cancel",{pointerId:U,result:"longpress"}),"longpress"):(O.longPressArmed&&Mi("cancel",{pointerId:U,result:"armed"}),t(),Mi("cancel",{pointerId:U,result:"scroll",moved:O.moved,distance:pu(O)}),"scroll"))},[h,g,t]),k=_.useCallback(U=>{if(U.pointerType!=="touch")return;const O=U.target;!(O instanceof Element)||!O.closest(".xterm")||(b(U.pointerId,U.clientX,U.clientY),U.stopPropagation())},[b]),T=_.useCallback(U=>{if(U.pointerType!=="touch")return;const O=w(U.pointerId,U.clientX,U.clientY),M=d.current;M&&O&&(U.stopPropagation(),M.longPressed&&U.preventDefault())},[w]),R=_.useCallback(U=>{const O=x(U.pointerId,{clientX:U.clientX,clientY:U.clientY});O&&(U.stopPropagation(),O==="link"&&U.cancelable&&U.preventDefault())},[x]),z=_.useCallback(U=>{const O=d.current;if(U.pointerType==="touch"&&O&&Zm(O,U.pointerId)&&O.touchEventStream&&!O.longPressed){U.stopPropagation();return}E(U.pointerId)&&U.stopPropagation()},[E]),N=_.useCallback(U=>{const O=U.target;if(!(O instanceof Element)||!O.closest(".xterm"))return;if(d.current){d.current.touchEventStream=!0;return}const M=U.touches[0]??U.changedTouches[0];M&&b(qh,M.clientX,M.clientY,!0)},[b]),$=_.useCallback(U=>{const O=U.touches[0]??U.changedTouches[0];if(!O)return;const M=w(qh,O.clientX,O.clientY),I=d.current;I&&M&&I.longPressed&&(U.stopPropagation(),U.preventDefault())},[w]),P=_.useCallback(U=>{const O=U.changedTouches[0],M=d.current,I=O?{clientX:O.clientX,clientY:O.clientY}:M?{clientX:M.lastX,clientY:M.lastY}:void 0,L=x(qh,I);(L==="longpress"||L==="link")&&(U.stopPropagation(),U.cancelable&&U.preventDefault())},[x]),q=_.useCallback(U=>{E(qh)==="longpress"&&U.stopPropagation()},[E]),H=_.useCallback(U=>{const O=d.current;O&&(U.preventDefault(),U.stopPropagation(),y(O))},[y]);return{onPointerDownCapture:k,onPointerMoveCapture:T,onPointerUpCapture:R,onPointerCancelCapture:z,onTouchStartCapture:N,onTouchMoveCapture:$,onTouchEndCapture:P,onTouchCancelCapture:q,onContextMenuCapture:H}}function Dme({terminalRef:e,containerEl:t,suppressPtyFocus:n,focusPtyInput:r,isSelectionActive:i,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:u,onLongPressMove:d,onLongPressEnd:h,onHorizontalScrollIntent:p,onHandleDragStart:y,onHandleDragMove:g,onHandleDragEnd:b,onHandleDragCancel:w}){const x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(!1),R=_.useRef(null),z=_.useCallback(()=>{var I;(I=R.current)==null||I.call(R),R.current=null,E.current=null,k.current=null,T.current=!1,x.current!==null&&(cancelAnimationFrame(x.current),x.current=null)},[]),N=_.useCallback(()=>{var K;x.current=null;const I=E.current;if(!I||!t||!i())return;const L=t.getBoundingClientRect(),{dx:D,dy:Y}=X5({pointerX:I.clientX,pointerY:I.clientY,rect:L,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,edgePx:44,maxSpeedPx:18});D!==0&&(p==null||p(`selectionGestureAutoscroll dx=${Math.round(D)}`),t.scrollLeft+=D),Y!==0&&(t.scrollTop+=Y),(D!==0||Y!==0)&&((K=k.current)==null||K.call(k,I)),x.current=requestAnimationFrame(N)},[t,i,p]),$=_.useCallback((I,L)=>{E.current=I,k.current=L,x.current===null&&(x.current=requestAnimationFrame(N))},[N]);_.useEffect(()=>z,[z]),_.useEffect(()=>{if(!t)return;const I=L=>{T.current&&L.preventDefault()};return t.addEventListener("touchmove",I,{capture:!0,passive:!1}),document.addEventListener("touchmove",I,{capture:!0,passive:!1}),()=>{t.removeEventListener("touchmove",I,{capture:!0}),document.removeEventListener("touchmove",I,{capture:!0})}},[t]);const P=_.useCallback(I=>{z(),T.current=!0,u(I)},[u,z]),q=_.useCallback(I=>{d(I),$(I,d)},[d,$]),H=_.useCallback(I=>{z(),h(I)},[h,z]),U=Ome({terminalRef:e,suppressPtyFocus:n,focusTerminal:r,onTap:s,isTapCandidate:o,onLongPressCandidateStart:l,onLongPressStart:P,onLongPressMove:q,onLongPressEnd:H}),O=_.useCallback((I,L)=>{L.preventDefault(),L.stopPropagation(),z(),T.current=!0,y(I);let D=()=>{};const Y=A=>{A.cancelable&&A.preventDefault();const W={clientX:A.clientX,clientY:A.clientY};g(I,W),$(W,G=>g(I,G))},K=A=>{const W={clientX:A.clientX,clientY:A.clientY};D(),R.current=null,z(),b(I,W)},F=()=>{D(),R.current=null,z(),w(I)};D=()=>{window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",K),window.removeEventListener("pointercancel",F)},R.current=D,window.addEventListener("pointermove",Y,{passive:!1}),window.addEventListener("pointerup",K,{once:!0}),window.addEventListener("pointercancel",F,{once:!0})},[w,b,g,y,z,$]),M=_.useCallback((I,L)=>{if(R.current||!(L.touches[0]??L.changedTouches[0]))return;L.preventDefault(),L.stopPropagation(),T.current=!0,y(I);let Y=()=>{};const K=W=>{const G=W.touches[0]??W.changedTouches[0];if(!G)return;W.cancelable&&W.preventDefault();const B={clientX:G.clientX,clientY:G.clientY};g(I,B),$(B,ne=>g(I,ne))},F=W=>{const G=W.changedTouches[0],B=G?{clientX:G.clientX,clientY:G.clientY}:E.current;Y(),R.current=null,z(),b(I,B)},A=()=>{Y(),R.current=null,z(),w(I)};Y=()=>{window.removeEventListener("touchmove",K),window.removeEventListener("touchend",F),window.removeEventListener("touchcancel",A)},R.current=Y,window.addEventListener("touchmove",K,{passive:!1}),window.addEventListener("touchend",F,{once:!0}),window.addEventListener("touchcancel",A,{once:!0})},[w,b,g,y,z,$]);return{pointerHandlers:U,stopPtySelectionGesture:z,handlePtySelectionHandlePointerDown:O,handlePtySelectionHandleTouchStart:M}}const Pme=8;function Lme(e){const{sessionId:t,terminalRef:n,xtermHostRef:r,scrollControllerRef:i,containerEl:s,scrollState:o,keyboardOffset:l,ptyFontSize:u,suppressPtyFocus:d,focusPtyInput:h,onTap:p,isTapCandidate:y,onDownloadPath:g,onPreviewPath:b}=e,w=_.useRef(null),x=_.useRef(null),E=_.useRef(null),k=_.useRef(null),T=_.useRef(!1),R=_.useRef(null),z=_.useRef(""),N=_.useRef(null),[$,P]=_.useState(null),[q,H]=_.useState(null),[U,O]=_.useState(null),M=_.useMemo(()=>_me(u),[u]),I=_.useCallback((oe,ye)=>{const we=window.visualViewport;return f4({clientX:oe,clientY:ye,viewportWidth:(we==null?void 0:we.width)??window.innerWidth,viewportHeight:(we==null?void 0:we.height)??window.innerHeight,viewportOffsetLeft:(we==null?void 0:we.offsetLeft)??0,viewportOffsetTop:(we==null?void 0:we.offsetTop)??0})},[]),L=_.useCallback((oe,ye)=>{const we=n.current,Qe=r.current;return!we||!Qe?null:bme({terminal:we,host:Qe,anchor:oe,focus:ye})},[n,r]),D=_.useCallback((oe,ye)=>{const we=ye??Rme(oe);return R.current=we,O(we),we},[]),Y=_.useCallback(oe=>{const ye=window.visualViewport;return wme({handles:oe,viewportWidth:(ye==null?void 0:ye.width)??window.innerWidth,viewportHeight:(ye==null?void 0:ye.height)??window.innerHeight,viewportOffsetLeft:(ye==null?void 0:ye.offsetLeft)??0,viewportOffsetTop:(ye==null?void 0:ye.offsetTop)??0})},[]),K=_.useCallback(()=>{const oe=w.current,ye=x.current;if(!oe||!ye){H(null);return}const we=L(oe,ye);if(H(we),!we){P(null);return}P(Qe=>Qe&&Y(we))},[L,Y]),F=_.useCallback(()=>{var oe,ye;(oe=N.current)==null||oe.call(N),E.current=null,k.current=null,w.current=null,x.current=null,T.current=!1,R.current=null,z.current="",(ye=n.current)==null||ye.clearSelection(),P(null),H(null),O(null)},[n]),A=_.useCallback((oe="")=>{w.current=null,x.current=null,T.current=!1,R.current=null,z.current=oe,P(null),H(null),O(null)},[]),W=_.useCallback(({clientX:oe,clientY:ye})=>{const we=n.current,Qe=r.current;d({blur:!1}),k.current={clientX:oe,clientY:ye},E.current=we&&Qe?Wh({terminal:we,host:Qe,clientX:oe,clientY:ye}):null},[d,n,r]),G=_.useCallback(({clientX:oe,clientY:ye,draggedHandle:we="focus"})=>{const Qe=n.current,pt=r.current,mt=w.current,ct=x.current;if(!Qe||!pt||!mt)return null;const dt=Wh({terminal:Qe,host:pt,clientX:oe,clientY:ye});if(!dt)return null;const At=we==="anchor"?dt:mt,me=we==="focus"?dt:ct??mt;w.current=At,x.current=me,T.current=!0;const Oe=sv({terminal:Qe,anchor:At,focus:me});return z.current=(Oe==null?void 0:Oe.text)??"",D((Oe==null?void 0:Oe.text)??""),H(Oe?L(At,me):null),Oe},[L,D,n,r]),B=_.useCallback(({point:oe,clientX:ye,clientY:we,showToolbar:Qe=!0})=>{const pt=n.current,mt=r.current;if(!pt||!mt)return!1;const ct=oe?W2({terminal:pt,point:oe}):null,dt=ct??(oe?WS({terminal:pt,point:oe}):U2({terminal:pt,host:mt,clientX:ye,clientY:we}));if(!(dt!=null&&dt.text))return!1;w.current=dt.anchor,x.current=dt.focus,z.current=dt.text,D(dt.text,ct==null?void 0:ct.pathAction);const At=L(dt.anchor,dt.focus);return H(At),Qe&&P(At?Y(At):I(ye,we)),!0},[L,I,Y,D,n,r]),ne=_.useCallback(()=>{const oe=w.current,ye=x.current;if(!oe||!ye){P(null);return}const we=L(oe,ye);H(we),P(we?Y(we):null)},[L,Y]),ie=_.useCallback(oe=>{var Qe,pt;const ye=((pt=(Qe=n.current)==null?void 0:Qe.getSelection)==null?void 0:pt.call(Qe))??"",we=D(ye);z.current=ye,w.current=null,x.current=null,T.current=!1,H(null),P(we?I(oe.clientX,oe.clientY):null)},[I,D,n]);_.useEffect(()=>{const oe=r.current;if(!oe)return;let ye=!1;const we=mt=>{var dt,At;if(mt.pointerType!=="mouse"||mt.button!==0)return;const ct=mt.target;!(ct instanceof Element)||!ct.closest(".xterm")||(ye=!0,A(((At=(dt=n.current)==null?void 0:dt.getSelection)==null?void 0:At.call(dt))??""))},Qe=mt=>{if(mt.pointerType!=="mouse"||!ye)return;ye=!1;const ct={clientX:mt.clientX,clientY:mt.clientY};window.setTimeout(()=>ie(ct),0)},pt=()=>{ye=!1};return oe.addEventListener("pointerdown",we,!0),window.addEventListener("pointerup",Qe,!0),window.addEventListener("pointercancel",pt,!0),()=>{oe.removeEventListener("pointerdown",we,!0),window.removeEventListener("pointerup",Qe,!0),window.removeEventListener("pointercancel",pt,!0)}},[A,ie,n,r]),_.useLayoutEffect(()=>{if(!$&&!q)return;const oe=ye=>{const we=ye.target;we instanceof Element&&we.closest('[data-slot="pty-selection-toolbar"], [data-slot="pty-selection-handle"]')||F()};return document.addEventListener("pointerdown",oe,!0),document.addEventListener("touchstart",oe,!0),()=>{document.removeEventListener("pointerdown",oe,!0),document.removeEventListener("touchstart",oe,!0)}},[F,q,$]),_.useEffect(()=>{if(!s||!$)return;const oe=()=>F();return s.addEventListener("scroll",oe,{passive:!0}),()=>s.removeEventListener("scroll",oe)},[F,s,$]);const se=q!==null;_.useLayoutEffect(()=>{var oe;se&&((oe=i.current)==null||oe.relayout(),K())},[se,l,K,i]),_.useEffect(()=>{se&&K()},[se,K,o.scrollLeft,o.scrollTop]),_.useEffect(()=>{if(!se)return;const oe=window.visualViewport;let ye=0,we=0;const Qe=()=>{cancelAnimationFrame(ye),window.clearTimeout(we),ye=requestAnimationFrame(()=>{K(),we=window.setTimeout(()=>{ye=requestAnimationFrame(()=>K())},160)})};return Qe(),window.addEventListener("resize",Qe),oe==null||oe.addEventListener("resize",Qe),oe==null||oe.addEventListener("scroll",Qe),()=>{cancelAnimationFrame(ye),window.clearTimeout(we),window.removeEventListener("resize",Qe),oe==null||oe.removeEventListener("resize",Qe),oe==null||oe.removeEventListener("scroll",Qe)}},[se,K]);const te=_.useCallback(({clientX:oe,clientY:ye})=>{const we=n.current,Qe=r.current;if(!we||!Qe)return;const pt=Wh({terminal:we,host:Qe,clientX:oe,clientY:ye})??E.current;if(we.clearSelection(),!pt){w.current=null,x.current=null,R.current=null,z.current="",P(null),H(null),O(null);return}w.current=pt,x.current=pt,T.current=!1,R.current=null,z.current="",P(null),H(null),O(null),B({point:pt,clientX:oe,clientY:ye,showToolbar:!1})},[B,n,r]),he=_.useCallback(({clientX:oe,clientY:ye})=>{G({clientX:oe,clientY:ye}),P(null)},[G]),ge=_.useCallback(({clientX:oe,clientY:ye})=>{const we=n.current,Qe=r.current;if(!we||!Qe)return;const pt=w.current,mt=Wh({terminal:we,host:Qe,clientX:oe,clientY:ye}),ct=mt??x.current,dt=E.current,At=k.current,me=At?Math.hypot(oe-At.clientX,ye-At.clientY)>=Pme:!1,Oe=dt??mt;if(!T.current&&!me&&z.current){ne(),E.current=null,k.current=null;return}const it=!T.current&&!me&&Oe?W2({terminal:we,point:Oe}):null,tt=me?mt??ct:ct,Je=(T.current||me)&&pt&&tt?sv({terminal:we,anchor:pt,focus:tt}):it??U2({terminal:we,host:Qe,clientX:oe,clientY:ye})??(dt?WS({terminal:we,point:dt}):null);if(E.current=null,k.current=null,!(Je!=null&&Je.text)){F();return}w.current=Je.anchor,x.current=Je.focus,z.current=Je.text,D(Je.text,it==null?void 0:it.pathAction);const Wt=L(Je.anchor,Je.focus);H(Wt),P(Wt?Y(Wt):I(oe,ye))},[F,L,I,Y,D,ne,n,r]),Ee=_.useCallback(()=>{var we;const oe=n.current,ye=((we=oe==null?void 0:oe.getSelection)==null?void 0:we.call(oe))||z.current;ye&&d4(ye,{allowLegacyFallback:!0}).then(Qe=>{F(),Qe==="failed"?nt.error("复制失败"):nt.success("已复制")})},[F,n]),Re=_.useCallback(()=>{const oe=R.current;oe&&(oe.kind==="image-preview"?b(oe.path):g(oe.path),F())},[F,g,b]),Ie=_.useCallback(()=>w.current!==null,[]),Ye=_.useCallback(()=>{P(null)},[]),gt=_.useCallback((oe,{clientX:ye,clientY:we})=>{G({clientX:ye,clientY:we,draggedHandle:oe}),P(null)},[G]),Me=_.useCallback((oe,ye)=>{ye&&G({...ye,draggedHandle:oe}),z.current&&ne()},[G,ne]);_.useEffect(()=>{},[F,L,Y,t,D,n]);const de=Dme({terminalRef:n,containerEl:s,suppressPtyFocus:d,focusPtyInput:h,isSelectionActive:Ie,onTap:p,isTapCandidate:y,onLongPressCandidateStart:W,onLongPressStart:te,onLongPressMove:he,onLongPressEnd:ge,onHorizontalScrollIntent:oe=>{var ye;return(ye=i.current)==null?void 0:ye.markHorizontalScrollIntent(oe)},onHandleDragStart:Ye,onHandleDragMove:gt,onHandleDragEnd:Me,onHandleDragCancel:Ye});return N.current=de.stopPtySelectionGesture,{pointerHandlers:de.pointerHandlers,ptySelectionToolbar:$,ptySelectionHandles:q,ptySelectionPathAction:U,ptySelectionHandleMetrics:M,copyPtySelection:Ee,openPtySelectionPathAction:Re,handlePtySelectionHandlePointerDown:de.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:de.handlePtySelectionHandleTouchStart}}function Ime(){return ze(e=>e.ptyScrollTraceEnabled)}const zme=new Set(["image/png","image/jpeg","image/webp","image/gif"]);function V2(e){return zme.has(e)}function pE(e){if(!e)return null;const t=Array.from(e.items??[]);for(const r of t){if(r.kind!=="file"||!V2(r.type))continue;const i=r.getAsFile();if(i)return i}return Array.from(e.files??[]).find(r=>V2(r.type))??null}function Bme(e){return`${e.startsWith("@")?e:`@${e}`} `}function Y2(e,t,n,r){const i=Math.max(0,Math.min(n,e.length)),s=Math.max(i,Math.min(r,e.length));return{value:`${e.slice(0,i)}${t}${e.slice(s)}`,cursor:i+t.length}}async function m4(e){const t=pE(e.clipboardData);if(!t)return null;if(!e.relay)throw new Error("请先连接开发机");const n=await e.relay.uploadClipboardImage(e.sessionId,t);if(!n.success||!n.path)throw new Error(n.error??"剪贴板图片上传失败");return{path:n.path,pathMention:Bme(n.path)}}function jme(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 Fme({sessionId:e,terminalRef:t,onAfterPaste:n}){return _.useCallback(async r=>{var u;const i=r.clipboardData,s=!!pE(i),o=s?null:jme(i);if(!s&&!o)return;r.preventDefault(),r.stopPropagation();const l=Mt;if(!l){nt.error("请先连接开发机");return}if(s){const d=nt.loading("图片上传中...");try{const h=await m4({clipboardData:i,relay:l,sessionId:e});if(nt.dismiss(d),!h)return;Ks(e,h.pathMention)}catch(h){nt.error(h instanceof Error?h.message:String(h),{id:d});return}}else if(o){const d=await xf({relay:l,sessionId:e,file:o});if(!d)return;Ks(e,`@${d} `)}n==null||n(),(u=t.current)==null||u.focus()},[e,t,n])}const $me=new Set(["Enter","Backspace","Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Delete","Home","End"]),K2={caseSensitive:!1,regex:!1,wholeWord:!1,decorations:sfe};function Hme({softKeyboardEditingSurface:e,ptyInputFocused:t,keyboardOpen:n}){return e&&t&&n}function Ume({controlsVisible:e,keyboardOpen:t,previous:n}){return e?!n.controlsVisible||t&&!n.keyboardOpen:!1}function Wme({touchEditingSurface:e,inputModePreference:t,detectedPhysicalKeyboard:n,softKeyboardDetected:r}){return!e||t==="hardware"?!0:t==="touch"?!1:n&&!r}function qme({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:$me.has(n)}const G2=8,Vme=32;function Yme({showMobilePtyControls:e,horizontalScrollable:t,mobileControlsHeight:n}){return e?Math.ceil(Math.max(0,n))+G2:t?Vme:G2}function Kme(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 Gme(e){const{sessionId:t,sessionKind:n,ptyOwner:r,active:i=!0,containerEl:s,spacerRef:o,xtermHostRef:l,mobileControlsHeight:u}=e,d=ame(),h=dme(),p=Ime(),{openImagePreview:y}=y3(),g=_.useRef(null),b=_.useRef(null),w=_.useRef([]),x=_.useRef(null),E=_.useRef(null),k=_.useRef(i),T=_.useRef(i),R=_.useRef(!1),z=_.useRef(!1),N=_.useRef(!1),$=_.useRef(null),P=_.useRef(null),q=_.useRef(null),H=_.useRef(null),U=_.useRef({keyboardOpen:!1,controlsVisible:!1}),O=_.useRef(!1),M=_.useRef(!1),I=_.useRef(!1),L=_.useRef(!1),D=_.useRef(null),Y=_.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[K,F]=_.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[A,W]=_.useState(!1),[G,B]=_.useState(!1),[ne,ie]=_.useState({resultIndex:-1,resultCount:0}),se=ze(Se=>Se.connected),te=ze(Se=>Se.proxyOnline),he=ze(Se=>Se.ptyFontSize),ge=ze(Se=>Se.inputModePreference),Ee=ze(Se=>Se.adaptiveInputModality),Re=ze(Se=>Se.setAdaptiveInputModality),Ie=Ee==="hardware",Ye=r==="proxy-hosted"||n==="terminal",gt=hl("(pointer: coarse), (hover: none)"),{bottomOffset:Me,layoutBottomInset:de}=fE(),oe=ge==="hardware",ye=Wme({touchEditingSurface:gt,inputModePreference:ge,detectedPhysicalKeyboard:Ie,softKeyboardDetected:Me>0}),we=gt&&!ye,Qe=ye?0:Me,pt=Qe>0,mt=ye?0:de;M.current=ye,_.useEffect(()=>{k.current=i},[i]),_.useEffect(()=>{R.current=d.ready},[d.ready]);const ct=_.useCallback(()=>k.current&&R.current,[]);_.useEffect(()=>{Qe>0&&W(!0)},[Qe]);const dt=ume({containerEl:s,xtermHostRef:l,terminalRef:g}),{ptyInputFocused:At,suppressPtyFocus:me,focusPtyInput:Oe,handleFocusCapture:it,handleBlurCapture:tt}=dt,Je=Hme({softKeyboardEditingSurface:we,ptyInputFocused:At,keyboardOpen:pt});O.current=we&&(Je||Qe>0),Y.current={keyboardOffset:Qe,hasSeenSoftKeyboard:A,showMobilePtyControls:Je,touchEditingSurface:gt,ptyInputFocused:At,containerPaddingBottom:Y.current.containerPaddingBottom,mobileControlsBottomInset:mt};const Wt=h.clearNewFramesWhileAway;P.current||(P.current=z2(()=>{var Se;(Se=E.current)==null||Se.relayout()})),q.current||(q.current=z2(()=>{var xe,je;const Se=H.current??{reason:"rawInput",force:!1};H.current=null,(xe=E.current)==null||xe.traceRawInputFollowFire(),(je=E.current)==null||je.scrollToBottom(Se.reason,Se.force?{force:!0}:void 0),Wt()}));const nn=_.useCallback(()=>{D.current!==null&&(cancelAnimationFrame(D.current),D.current=null)},[]),Qt=_.useCallback(()=>{L.current=!0,nn()},[nn]),Kt=_.useCallback(()=>{var Se;!L.current||document.visibilityState==="hidden"||((Se=E.current)==null||Se.preparePageResumeRestore(),nn(),D.current=requestAnimationFrame(()=>{D.current=requestAnimationFrame(()=>{D.current=null;const xe=E.current;xe&&(xe.restorePageResume(),Wt(),L.current=!1)})}))},[nn,Wt]);_.useEffect(()=>()=>{var Se,xe;(Se=P.current)==null||Se.dispose(),(xe=q.current)==null||xe.dispose(),nn(),P.current=null,q.current=null},[nn]),_.useEffect(()=>{const Se=()=>{Qt()},xe=()=>{if(document.visibilityState==="hidden"){Se();return}Kt()};return document.addEventListener("visibilitychange",xe),window.addEventListener("pagehide",Se),window.addEventListener("pageshow",Kt),window.addEventListener("focus",Kt),()=>{document.removeEventListener("visibilitychange",xe),window.removeEventListener("pagehide",Se),window.removeEventListener("pageshow",Kt),window.removeEventListener("focus",Kt),nn()}},[nn,Qt,Kt]),_.useEffect(()=>{const Se=T.current;if(T.current=i,Se!==i){if(!i){Qt();return}Kt()}},[i,Qt,Kt]);const Dt=_.useCallback((Se="rawInput",xe)=>{var ht,Lt;const je=H.current,et=(je==null?void 0:je.force)===!0||(xe==null?void 0:xe.force)===!0;H.current={reason:(xe==null?void 0:xe.force)===!0||!je?Se:je.reason,force:et},(ht=E.current)==null||ht.traceRawInputFollowScheduled(Se),(Lt=q.current)==null||Lt.schedule()},[]),zt=_.useCallback(()=>{var Se,xe;(Se=x.current)==null||Se.setOutputPaused(!1),(xe=x.current)==null||xe.flushOutput()},[]),Mn=_.useCallback((Se,xe)=>{var je;!Se.includes("\r")&&!Se.includes(`
635
- `)||(je=E.current)==null||je.resetHorizontalScroll(xe)},[]),pn=_.useCallback(()=>M.current?"submit":"linefeed",[]),_n=_.useCallback(()=>M.current,[]);_.useEffect(()=>{if(!i||ge!=="auto"||!gt)return;const Se=je=>{const et=l.current,ht=s;return je instanceof Node?et!=null&&et.contains(je)||je===document.body||je===document.documentElement?!0:ht!=null&&ht.contains(je)?je instanceof HTMLElement?je.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:je===window},xe=je=>{var Lt;if(!qme({active:k.current,touchEditingSurface:gt,key:je.key,code:je.code,altKey:je.altKey,ctrlKey:je.ctrlKey,metaKey:je.metaKey,isComposing:je.isComposing,targetAcceptsPtyInput:Se(je.target)}))return;Re("hardware"),M.current=!0,(Lt=g.current)==null||Lt.focus();const et=l.current;if(je.target instanceof Node&&(et!=null&&et.contains(je.target)))return;const ht=Kme(je);!ht||!ct()||(je.preventDefault(),je.stopPropagation(),Ks(t,ht),zt(),Dt("physicalKeyboard"),Mn(ht,"physicalKeyboardEnter"))};return window.addEventListener("keydown",xe,!0),()=>window.removeEventListener("keydown",xe,!0)},[i,ct,s,ge,Mn,zt,Dt,t,Re,gt,l]);const Ue=_.useCallback(Se=>{const xe=Mt;if(!xe){nt.error("请先连接开发机");return}const je=nt.loading(`下载 ${Se} ...`);U1({relay:xe,sessionId:t,path:Se}).then(et=>{et.ok?nt.success(`已开始下载 ${Se}`,{id:je}):nt.error(et.error,{id:je})}).catch(et=>{nt.error(et instanceof Error?et.message:String(et),{id:je})})},[t]),Ge=_.useCallback(Se=>{const xe=g.current;return xe?Ype(xe,w.current,Se):!1},[]),Pt=_.useCallback(Se=>{const xe=g.current;return xe?Vpe(xe,w.current,Se):!1},[]),Nt=Lme({sessionId:t,terminalRef:g,xtermHostRef:l,scrollControllerRef:E,containerEl:s,scrollState:K,keyboardOffset:Qe,ptyFontSize:he,suppressPtyFocus:me,focusPtyInput:Oe,onTap:Ge,isTapCandidate:Pt,onDownloadPath:Ue,onPreviewPath:y});I.current=Nt.ptySelectionHandles!==null;const J=Fme({sessionId:t,terminalRef:g,onAfterPaste:()=>{zt(),Dt("paste")}}),ve=_.useCallback(Se=>{if(!ct()){Se.preventDefault();return}J(Se)},[ct,J]),[He,ut]=_.useState(!1),Bt=_.useCallback(Se=>{Se.dataTransfer.types.includes("Files")&&(Se.preventDefault(),ut(xe=>xe||!0))},[]),re=_.useCallback(Se=>{Se.currentTarget.contains(Se.relatedTarget)||ut(!1)},[]),ae=_.useCallback(async Se=>{var ht;const xe=(ht=Se.dataTransfer.files)==null?void 0:ht[0];if(!xe||(Se.preventDefault(),ut(!1),!ct()))return;const je=Mt;if(!je){nt.error("请先连接开发机");return}const et=await xf({relay:je,sessionId:t,file:xe});et&&(Ks(t,`@${et} `),zt(),Dt("dropUpload"))},[ct,zt,Dt,t]),ue=_.useCallback(Se=>{var je;if(!ct()){Se.preventDefault();return}const xe=Se.target;xe instanceof Element&&xe.closest(".xterm")||(Se.preventDefault(),(je=g.current)==null||je.focus())},[ct]);_.useEffect(()=>{if(!se||!te)return;const Se=l.current,xe=tc,je=Mt,et=s,ht=o.current;if(!Se||!xe||!je||!et||!ht)return;let Lt=null,Rn=null,en=null,Kn=null,An=null,Ai=null;const _t=ape({host:Se,sessionId:t,ws:xe,relay:je,scheduleAutoFocus:we?()=>{}:void 0,createTerminal:async Ct=>await Y5(Ct,{fontSize:ze.getState().ptyFontSize}),attachRawInput:(Ct,Vt,On)=>xfe(Ct,Vt,{...On,getPlainEnterBehavior:pn,isPhysicalKeyboardMode:_n,physicalKeyboardMode:oe}),isInputEnabled:ct,canFocus:ct,onTerminalReady:Ct=>{const Vt=Ct;g.current=Vt;const On=new Ple({highlightLimit:1e3});Vt.loadAddon(On),b.current=On,Ai=On.onDidChangeResults(ar=>{ie(ar)}),B(!0);const jt=Rpe(Vt,y);Lt=jt.dispose;const Nn=$pe(Vt,Ue);Rn=Nn.dispose,w.current=[jt.provider,Nn.provider],tme(()=>g.current);const Qn=L.current;Qn&&(N.current=!1);const un=npe({container:et,spacer:ht,host:Se,term:Vt,hasNewFrame:()=>z.current,consumeNewFrame:()=>{z.current=!1},hasNewFramesWhileAway:()=>h.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:h.setHasNewFramesWhileAway,onAtBottomChange:h.handleAtBottomChange,onScrollStateChange:F,initialUserHasVerticalScrollIntent:Qn?!1:N.current,onUserVerticalScrollIntentChange:ar=>{var gr,si;N.current=ar,(gr=x.current)==null||gr.setOutputPaused(ar),ar||(si=x.current)==null||si.flushOutput()},onTouchReviewStart:me,onTouchBoundaryPrevent:me});E.current=un,en=un.dispose,Qn&&(un.restorePageResume(),Wt(),L.current=!1),rme(()=>{var ha;const ar=to=>{if(!to)return null;const es=to.getBoundingClientRect();return{top:es.top,bottom:es.bottom,height:es.height,left:es.left,right:es.right,width:es.width}},gr=document.querySelector('[data-slot="pty-mobile-controls"]'),si=document.querySelector("[data-keyboard-offset]"),vi=window.visualViewport,kl=ar(gr),yi=(vi==null?void 0:vi.height)??window.innerHeight;return{...sme(un.getDebugProbe,{container:et,spacer:ht,host:Se,term:Vt}),mobileLayout:{...Y.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:vi?{height:vi.height,width:vi.width,offsetTop:vi.offsetTop,pageTop:vi.pageTop,scale:vi.scale}:null,chatRoot:{dataKeyboardOffset:(si==null?void 0:si.getAttribute("data-keyboard-offset"))??null,rect:ar(si)},ptyViewRect:ar(et.parentElement),containerRect:ar(et),controlsRect:kl,controlsOverflowBelowVisualViewport:kl===null?null:kl.bottom-yi,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(ha=document.activeElement.closest("[data-slot]"))==null?void 0:ha.getAttribute("data-slot")}:null},frame:{lastWriteAt:$.current,pendingNewFrame:z.current}}}),An=ufe({container:et,host:Se,onHorizontalScrollIntent:ar=>{var gr;return(gr=E.current)==null?void 0:gr.markHorizontalScrollIntent(ar)}}).dispose,Ye&&(Kn=Tfe({container:et,term:Vt,onResize:(gr,si)=>{je.sendControl({type:"terminal_resize_request",sessionId:t,cols:gr,rows:si})},onRelayout:()=>{var gr;return(gr=E.current)==null?void 0:gr.relayout()},preserveRows:()=>O.current}).dispose)},onFramePending:()=>{z.current=!0,N.current&&!h.hasNewFramesWhileAwayRef.current&&h.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Ct;$.current=performance.now(),(Ct=P.current)==null||Ct.schedule()},onRawInput:Ct=>{zt(),Dt("rawInput"),Mn(Ct,"rawInputEnter")},onError:Ct=>{const Vt=Ct instanceof Error?Ct.message:String(Ct);nt.error(`终端初始化失败:${Vt}`)},...d.transport});return x.current=_t,()=>{Kn==null||Kn(),An==null||An(),en==null||en(),Ai==null||Ai.dispose(),ime(),Lt==null||Lt(),Rn==null||Rn(),w.current=[],nme(),b.current=null,B(!1),ie({resultIndex:-1,resultCount:0}),_t.dispose(),g.current=null,E.current=null,x.current=null}},[t,se,te,s,o,l,d.transport,h.handleAtBottomChange,h.hasNewFramesWhileAwayRef,h.setHasNewFramesWhileAway,ct,oe,pn,_n,Ue,y,me,Dt,Mn,zt,Ye]),_.useEffect(()=>{const Se=g.current,xe=E.current;!Se||!xe||afe(Se,he,xe.relayout)},[he]),_.useEffect(()=>{if(!i||!d.ready||we)return;const Se=requestAnimationFrame(()=>{var xe;return(xe=g.current)==null?void 0:xe.focus()});return()=>cancelAnimationFrame(Se)},[i,d.ready,we]);const Q=_.useCallback((Se="viewExternal",xe)=>{var je;(je=E.current)==null||je.scrollToBottom(Se,xe)},[]),V=_.useCallback(Se=>{var xe;(xe=E.current)==null||xe.scrollToRatio(Se)},[]),Z=_.useCallback(Se=>{var xe;(xe=E.current)==null||xe.scrollToXRatio(Se)},[]),ee=_.useCallback(Se=>{var Rn;const xe=g.current,je=xe==null?void 0:xe.getSelectionPosition();if(!xe||!je)return;const et=je.start.y;if(et>=Se&&et<Se+xe.rows)return;const ht=Math.max(0,xe.buffer.active.length-xe.rows);if(ht===0)return;const Lt=Math.max(0,Math.min(ht,et-Math.floor(xe.rows/2)));(Rn=E.current)==null||Rn.scrollToRatio(Lt/ht)},[]),fe=_.useCallback((Se,xe=!1)=>{const je=g.current,et=b.current;if(!je||!et||!Se)return Se||(et==null||et.clearDecorations(),je==null||je.clearSelection(),ie({resultIndex:-1,resultCount:0})),!1;const ht=je.buffer.active.viewportY,Lt=et.findNext(Se,{...K2,incremental:xe});return Lt&&ee(ht),Lt},[ee]),ke=_.useCallback(Se=>{const xe=g.current,je=b.current;if(!xe||!je||!Se)return!1;const et=xe.buffer.active.viewportY,ht=je.findPrevious(Se,K2);return ht&&ee(et),ht},[ee]),Be=_.useCallback(()=>{var Se,xe;(Se=b.current)==null||Se.clearDecorations(),(xe=g.current)==null||xe.clearSelection(),ie({resultIndex:-1,resultCount:0})},[]),Pe=_.useCallback(Se=>{var xe;ct()&&(Ks(t,Se),Dt("mobileControl",{force:!0}),Mn(Se,"mobileControlEnter"),(xe=g.current)==null||xe.focus())},[ct,Mn,Dt,t]),qe=_.useCallback(()=>{var xe,je,et;if(!ct())return;const Se=(je=(xe=navigator.clipboard)==null?void 0:xe.readText)==null?void 0:je.bind(navigator.clipboard);if(!window.isSecureContext||!Se){nt.error("无法读取剪贴板"),(et=g.current)==null||et.focus();return}Se().then(ht=>{if(!ht)return;const Lt=g.current;if(Lt){Lt.paste(ht);return}Ks(t,ht),zt(),Dt("paste"),Mn(ht,"pasteEnter")}).catch(ht=>{const Lt=ht instanceof Error&&ht.message?ht.message:"无法读取剪贴板";nt.error(Lt)}).finally(()=>{var ht;return(ht=g.current)==null?void 0:ht.focus()})},[ct,Mn,zt,Dt,t]),st=Yme({showMobilePtyControls:Je,horizontalScrollable:K.horizontalScrollable,mobileControlsHeight:u});Y.current.containerPaddingBottom=st,_.useEffect(()=>{var je,et,ht;I.current?(je=E.current)==null||je.relayout():(et=P.current)==null||et.schedule();const Se=U.current,xe=Ume({controlsVisible:Je,keyboardOpen:pt,previous:Se});U.current={keyboardOpen:pt,controlsVisible:Je},Je&&(I.current?Wt():xe?((ht=E.current)==null||ht.scrollToBottom("keyboardOffset",{force:!0}),Wt()):pt||Dt("keyboardOffset"))},[Qe,pt,Je,st,Wt,Dt]);const lt=_.useMemo(()=>({onFocusCapture:it,onBlurCapture:tt}),[it,tt]);return{scrollState:K,isAtBottom:h.isAtBottom,hasNewFramesWhileAway:h.hasNewFramesWhileAway,ptyInputFocused:At,showMobilePtyControls:Je,touchEditingSurface:gt,keyboardOffset:Qe,physicalKeyboardMode:ye,softKeyboardEditingSurface:we,mobileControlsBottomInset:mt,connectionReady:d.ready,connectionOverlay:d.overlay,containerPaddingBottom:st,traceEnabled:p,findReady:G,findResultIndex:ne.resultIndex,findResultCount:ne.resultCount,findNext:fe,findPrevious:ke,clearFind:Be,scrollToBottom:Q,scrollToRatio:V,scrollToXRatio:Z,clearNewFramesWhileAway:Wt,sendMobileInput:Pe,pasteMobileClipboard:qe,handleTerminalContainerMouseDown:ue,handlePasteCapture:ve,pointerHandlers:Nt.pointerHandlers,focusHandlers:lt,ptySelectionToolbar:Nt.ptySelectionToolbar,ptySelectionHandles:Nt.ptySelectionHandles,ptySelectionPathAction:Nt.ptySelectionPathAction,ptySelectionHandleMetrics:Nt.ptySelectionHandleMetrics,copyPtySelection:Nt.copyPtySelection,openPtySelectionPathAction:Nt.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:Nt.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Nt.handlePtySelectionHandleTouchStart,isPtyDragOver:He,handlePtyDragOver:Bt,handlePtyDragLeave:re,handlePtyDrop:ae}}function Xme({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,active:i=!0,findRequest:s}){const[o,l]=_.useState(null),[u,d]=_.useState(0),[h,p]=_.useState(!1),[y,g]=_.useState(""),b=_.useRef(null),w=_.useRef(null),x=Gme({sessionId:e,sessionKind:t,ptyOwner:r,active:i,containerEl:o,spacerRef:b,xtermHostRef:w,mobileControlsHeight:u}),E=x.ptySelectionHandleMetrics,{clearFind:k,findNext:T,findPrevious:R,findReady:z,findResultCount:N,findResultIndex:$}=x,P=_.useCallback(()=>{R(y)},[R,y]),q=_.useCallback(()=>{T(y)},[T,y]),H=_.useCallback(()=>p(!0),[]),U=_.useCallback(()=>{p(!1),k()},[k]),O=x3({enabled:i,open:h,openRequest:s,onOpen:H,onClose:U,onPrevious:P,onNext:q});return _.useEffect(()=>{!h||!z||(y?T(y,!0):k())},[k,T,h,y,z]),v.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":x.connectionReady?"true":"false","aria-busy":!x.connectionReady,children:[h?v.jsx(V0,{query:y,resultIndex:$,resultCount:N,focusRequest:O.focusRequest,loading:!!y&&!z,onQueryChange:g,onPrevious:P,onNext:q,onClose:O.closeFind}):null,v.jsx("div",{ref:l,className:"flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${x.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:x.handleTerminalContainerMouseDown,onPointerDownCapture:x.pointerHandlers.onPointerDownCapture,onPointerMoveCapture:x.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:x.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:x.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:x.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:x.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:x.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:x.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:x.pointerHandlers.onContextMenuCapture,onPasteCapture:x.handlePasteCapture,onDragOver:x.handlePtyDragOver,onDragLeave:x.handlePtyDragLeave,onDrop:x.handlePtyDrop,onFocusCapture:x.focusHandlers.onFocusCapture,onBlurCapture:x.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":x.isPtyDragOver?"true":void 0,children:v.jsx("div",{ref:b,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:v.jsx("div",{ref:w,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})})}),v.jsx(b3,{visible:!x.isAtBottom,hasNewMessages:x.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{x.scrollToBottom("backToBottomBtn",{force:!0}),x.clearNewFramesWhileAway()}}),x.showMobilePtyControls?v.jsx(Vae,{sessionKind:t,provider:n,bottomInset:x.mobileControlsBottomInset,onInput:x.sendMobileInput,onPaste:x.pasteMobileClipboard,onHeightChange:d}):null,x.ptySelectionHandles?v.jsxs(v.Fragment,{children:[v.jsx(X2,{kind:"anchor",position:x.ptySelectionHandles.anchor,metrics:E,"aria-label":"调整选区起点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("anchor",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("anchor",M)}),v.jsx(X2,{kind:"focus",position:x.ptySelectionHandles.focus,metrics:E,"aria-label":"调整选区终点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("focus",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("focus",M)})]}):null,x.ptySelectionToolbar?v.jsxs("div",{className:"fixed z-50 flex -translate-x-1/2 gap-1 rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-lg",style:{left:x.ptySelectionToolbar.left,top:x.ptySelectionToolbar.top},"data-slot":"pty-selection-toolbar",children:[v.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:M=>M.preventDefault(),onClick:x.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),x.ptySelectionPathAction?v.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:M=>M.preventDefault(),onClick:x.openPtySelectionPathAction,"aria-label":x.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:x.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,v.jsx(ele,{state:x.scrollState,onScrollRatio:x.scrollToRatio}),v.jsx(tle,{state:x.scrollState,onScrollRatio:x.scrollToXRatio}),v.jsx(Dae,{...x.connectionOverlay}),v.jsx(Lae,{ptyInputFocused:x.ptyInputFocused,touchEditingSurface:x.touchEditingSurface,softKeyboardEditingSurface:x.softKeyboardEditingSurface,physicalKeyboardMode:x.physicalKeyboardMode,keyboardOffset:x.keyboardOffset,showMobilePtyControls:x.showMobilePtyControls,mobileControlsBottomInset:x.mobileControlsBottomInset}),x.traceEnabled?v.jsx(Zme,{}):null]})}function X2({kind:e,position:t,metrics:n,"aria-label":r,onPointerDown:i,onTouchStart:s}){const o=n.touchSize/2,l=2,u=n.visualSize,d=Math.max(n.stemSize+2,u+1),h=o-l/2,p=o,y=e==="anchor"?h-u+l:h,g=p+d-u+l,b=e==="anchor"?{borderTopLeftRadius:u,borderBottomLeftRadius:u,borderTopRightRadius:2,borderBottomRightRadius:u}:{borderTopLeftRadius:2,borderBottomLeftRadius:u,borderTopRightRadius:u,borderBottomRightRadius:u};return v.jsxs("button",{type:"button",className:"fixed z-50 touch-none rounded-full bg-transparent p-0 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",style:{left:t.left,top:t.top,width:n.touchSize,height:n.touchSize,transform:"translate(-50%, -50%)"},"data-slot":"pty-selection-handle","data-kind":e,"aria-label":r,onPointerDown:i,onTouchStart:s,children:[v.jsx("span",{className:"pointer-events-none absolute rounded-full bg-primary",style:{left:h,top:p,width:l,height:d},"data-slot":"pty-selection-handle-stem"}),v.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:y,top:g,width:u,height:u,...b},"data-slot":"pty-selection-handle-dot"})]})}function Zme(){const[e,t]=_.useState(!1);async function n(){const r=Mae();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return v.jsx("button",{type:"button",className:"absolute left-3 top-3 z-30 rounded border border-border bg-popover/90 px-2 py-1 text-[11px] text-muted-foreground",onPointerDown:r=>r.preventDefault(),onClick:n,"data-slot":"pty-scroll-trace-copy",children:e?"Copied":"Trace"})}const Qme=3,Jme=1024,ege=720,Qm=.5,g4=_.createContext(null);function tge({children:e}){const[t,n]=_.useState([]),[r,i]=_.useState(null),[s,o]=_.useState(null),l=ze(k=>k.selectedProxyId),u=Ut(k=>k.sessions),d=Ut(k=>k.sessionListLoaded),h=_.useRef(l),p=_.useRef(null),y=_.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
635
+ `)||(je=E.current)==null||je.resetHorizontalScroll(xe,{holdUntilCursorVisible:!0})},[]),pn=_.useCallback(()=>M.current?"submit":"linefeed",[]),_n=_.useCallback(()=>M.current,[]);_.useEffect(()=>{if(!i||ge!=="auto"||!gt)return;const Se=je=>{const et=l.current,ht=s;return je instanceof Node?et!=null&&et.contains(je)||je===document.body||je===document.documentElement?!0:ht!=null&&ht.contains(je)?je instanceof HTMLElement?je.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:je===window},xe=je=>{var Lt;if(!qme({active:k.current,touchEditingSurface:gt,key:je.key,code:je.code,altKey:je.altKey,ctrlKey:je.ctrlKey,metaKey:je.metaKey,isComposing:je.isComposing,targetAcceptsPtyInput:Se(je.target)}))return;Re("hardware"),M.current=!0,(Lt=g.current)==null||Lt.focus();const et=l.current;if(je.target instanceof Node&&(et!=null&&et.contains(je.target)))return;const ht=Kme(je);!ht||!ct()||(je.preventDefault(),je.stopPropagation(),Ks(t,ht),zt(),Dt("physicalKeyboard"),Mn(ht,"physicalKeyboardEnter"))};return window.addEventListener("keydown",xe,!0),()=>window.removeEventListener("keydown",xe,!0)},[i,ct,s,ge,Mn,zt,Dt,t,Re,gt,l]);const Ue=_.useCallback(Se=>{const xe=Mt;if(!xe){nt.error("请先连接开发机");return}const je=nt.loading(`下载 ${Se} ...`);U1({relay:xe,sessionId:t,path:Se}).then(et=>{et.ok?nt.success(`已开始下载 ${Se}`,{id:je}):nt.error(et.error,{id:je})}).catch(et=>{nt.error(et instanceof Error?et.message:String(et),{id:je})})},[t]),Ge=_.useCallback(Se=>{const xe=g.current;return xe?Ype(xe,w.current,Se):!1},[]),Pt=_.useCallback(Se=>{const xe=g.current;return xe?Vpe(xe,w.current,Se):!1},[]),Nt=Lme({sessionId:t,terminalRef:g,xtermHostRef:l,scrollControllerRef:E,containerEl:s,scrollState:K,keyboardOffset:Qe,ptyFontSize:he,suppressPtyFocus:me,focusPtyInput:Oe,onTap:Ge,isTapCandidate:Pt,onDownloadPath:Ue,onPreviewPath:y});I.current=Nt.ptySelectionHandles!==null;const J=Fme({sessionId:t,terminalRef:g,onAfterPaste:()=>{zt(),Dt("paste")}}),ve=_.useCallback(Se=>{if(!ct()){Se.preventDefault();return}J(Se)},[ct,J]),[He,ut]=_.useState(!1),Bt=_.useCallback(Se=>{Se.dataTransfer.types.includes("Files")&&(Se.preventDefault(),ut(xe=>xe||!0))},[]),re=_.useCallback(Se=>{Se.currentTarget.contains(Se.relatedTarget)||ut(!1)},[]),ae=_.useCallback(async Se=>{var ht;const xe=(ht=Se.dataTransfer.files)==null?void 0:ht[0];if(!xe||(Se.preventDefault(),ut(!1),!ct()))return;const je=Mt;if(!je){nt.error("请先连接开发机");return}const et=await xf({relay:je,sessionId:t,file:xe});et&&(Ks(t,`@${et} `),zt(),Dt("dropUpload"))},[ct,zt,Dt,t]),ue=_.useCallback(Se=>{var je;if(!ct()){Se.preventDefault();return}const xe=Se.target;xe instanceof Element&&xe.closest(".xterm")||(Se.preventDefault(),(je=g.current)==null||je.focus())},[ct]);_.useEffect(()=>{if(!se||!te)return;const Se=l.current,xe=tc,je=Mt,et=s,ht=o.current;if(!Se||!xe||!je||!et||!ht)return;let Lt=null,Rn=null,en=null,Kn=null,An=null,Ai=null;const _t=ape({host:Se,sessionId:t,ws:xe,relay:je,scheduleAutoFocus:we?()=>{}:void 0,createTerminal:async Ct=>await Y5(Ct,{fontSize:ze.getState().ptyFontSize}),attachRawInput:(Ct,Vt,On)=>xfe(Ct,Vt,{...On,getPlainEnterBehavior:pn,isPhysicalKeyboardMode:_n,physicalKeyboardMode:oe}),isInputEnabled:ct,canFocus:ct,onTerminalReady:Ct=>{const Vt=Ct;g.current=Vt;const On=new Ple({highlightLimit:1e3});Vt.loadAddon(On),b.current=On,Ai=On.onDidChangeResults(ar=>{ie(ar)}),B(!0);const jt=Rpe(Vt,y);Lt=jt.dispose;const Nn=$pe(Vt,Ue);Rn=Nn.dispose,w.current=[jt.provider,Nn.provider],tme(()=>g.current);const Qn=L.current;Qn&&(N.current=!1);const un=npe({container:et,spacer:ht,host:Se,term:Vt,hasNewFrame:()=>z.current,consumeNewFrame:()=>{z.current=!1},hasNewFramesWhileAway:()=>h.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:h.setHasNewFramesWhileAway,onAtBottomChange:h.handleAtBottomChange,onScrollStateChange:F,initialUserHasVerticalScrollIntent:Qn?!1:N.current,onUserVerticalScrollIntentChange:ar=>{var gr,si;N.current=ar,(gr=x.current)==null||gr.setOutputPaused(ar),ar||(si=x.current)==null||si.flushOutput()},onTouchReviewStart:me,onTouchBoundaryPrevent:me});E.current=un,en=un.dispose,Qn&&(un.restorePageResume(),Wt(),L.current=!1),rme(()=>{var ha;const ar=to=>{if(!to)return null;const es=to.getBoundingClientRect();return{top:es.top,bottom:es.bottom,height:es.height,left:es.left,right:es.right,width:es.width}},gr=document.querySelector('[data-slot="pty-mobile-controls"]'),si=document.querySelector("[data-keyboard-offset]"),vi=window.visualViewport,kl=ar(gr),yi=(vi==null?void 0:vi.height)??window.innerHeight;return{...sme(un.getDebugProbe,{container:et,spacer:ht,host:Se,term:Vt}),mobileLayout:{...Y.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:vi?{height:vi.height,width:vi.width,offsetTop:vi.offsetTop,pageTop:vi.pageTop,scale:vi.scale}:null,chatRoot:{dataKeyboardOffset:(si==null?void 0:si.getAttribute("data-keyboard-offset"))??null,rect:ar(si)},ptyViewRect:ar(et.parentElement),containerRect:ar(et),controlsRect:kl,controlsOverflowBelowVisualViewport:kl===null?null:kl.bottom-yi,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(ha=document.activeElement.closest("[data-slot]"))==null?void 0:ha.getAttribute("data-slot")}:null},frame:{lastWriteAt:$.current,pendingNewFrame:z.current}}}),An=ufe({container:et,host:Se,onHorizontalScrollIntent:ar=>{var gr;return(gr=E.current)==null?void 0:gr.markHorizontalScrollIntent(ar)}}).dispose,Ye&&(Kn=Tfe({container:et,term:Vt,onResize:(gr,si)=>{je.sendControl({type:"terminal_resize_request",sessionId:t,cols:gr,rows:si})},onRelayout:()=>{var gr;return(gr=E.current)==null?void 0:gr.relayout()},preserveRows:()=>O.current}).dispose)},onFramePending:()=>{z.current=!0,N.current&&!h.hasNewFramesWhileAwayRef.current&&h.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Ct;$.current=performance.now(),(Ct=P.current)==null||Ct.schedule()},onRawInput:Ct=>{zt(),Dt("rawInput"),Mn(Ct,"rawInputEnter")},onError:Ct=>{const Vt=Ct instanceof Error?Ct.message:String(Ct);nt.error(`终端初始化失败:${Vt}`)},...d.transport});return x.current=_t,()=>{Kn==null||Kn(),An==null||An(),en==null||en(),Ai==null||Ai.dispose(),ime(),Lt==null||Lt(),Rn==null||Rn(),w.current=[],nme(),b.current=null,B(!1),ie({resultIndex:-1,resultCount:0}),_t.dispose(),g.current=null,E.current=null,x.current=null}},[t,se,te,s,o,l,d.transport,h.handleAtBottomChange,h.hasNewFramesWhileAwayRef,h.setHasNewFramesWhileAway,ct,oe,pn,_n,Ue,y,me,Dt,Mn,zt,Ye]),_.useEffect(()=>{const Se=g.current,xe=E.current;!Se||!xe||afe(Se,he,xe.relayout)},[he]),_.useEffect(()=>{if(!i||!d.ready||we)return;const Se=requestAnimationFrame(()=>{var xe;return(xe=g.current)==null?void 0:xe.focus()});return()=>cancelAnimationFrame(Se)},[i,d.ready,we]);const Q=_.useCallback((Se="viewExternal",xe)=>{var je;(je=E.current)==null||je.scrollToBottom(Se,xe)},[]),V=_.useCallback(Se=>{var xe;(xe=E.current)==null||xe.scrollToRatio(Se)},[]),Z=_.useCallback(Se=>{var xe;(xe=E.current)==null||xe.scrollToXRatio(Se)},[]),ee=_.useCallback(Se=>{var Rn;const xe=g.current,je=xe==null?void 0:xe.getSelectionPosition();if(!xe||!je)return;const et=je.start.y;if(et>=Se&&et<Se+xe.rows)return;const ht=Math.max(0,xe.buffer.active.length-xe.rows);if(ht===0)return;const Lt=Math.max(0,Math.min(ht,et-Math.floor(xe.rows/2)));(Rn=E.current)==null||Rn.scrollToRatio(Lt/ht)},[]),fe=_.useCallback((Se,xe=!1)=>{const je=g.current,et=b.current;if(!je||!et||!Se)return Se||(et==null||et.clearDecorations(),je==null||je.clearSelection(),ie({resultIndex:-1,resultCount:0})),!1;const ht=je.buffer.active.viewportY,Lt=et.findNext(Se,{...K2,incremental:xe});return Lt&&ee(ht),Lt},[ee]),ke=_.useCallback(Se=>{const xe=g.current,je=b.current;if(!xe||!je||!Se)return!1;const et=xe.buffer.active.viewportY,ht=je.findPrevious(Se,K2);return ht&&ee(et),ht},[ee]),Be=_.useCallback(()=>{var Se,xe;(Se=b.current)==null||Se.clearDecorations(),(xe=g.current)==null||xe.clearSelection(),ie({resultIndex:-1,resultCount:0})},[]),Pe=_.useCallback(Se=>{var xe;ct()&&(Ks(t,Se),Dt("mobileControl",{force:!0}),Mn(Se,"mobileControlEnter"),(xe=g.current)==null||xe.focus())},[ct,Mn,Dt,t]),qe=_.useCallback(()=>{var xe,je,et;if(!ct())return;const Se=(je=(xe=navigator.clipboard)==null?void 0:xe.readText)==null?void 0:je.bind(navigator.clipboard);if(!window.isSecureContext||!Se){nt.error("无法读取剪贴板"),(et=g.current)==null||et.focus();return}Se().then(ht=>{if(!ht)return;const Lt=g.current;if(Lt){Lt.paste(ht);return}Ks(t,ht),zt(),Dt("paste"),Mn(ht,"pasteEnter")}).catch(ht=>{const Lt=ht instanceof Error&&ht.message?ht.message:"无法读取剪贴板";nt.error(Lt)}).finally(()=>{var ht;return(ht=g.current)==null?void 0:ht.focus()})},[ct,Mn,zt,Dt,t]),st=Yme({showMobilePtyControls:Je,horizontalScrollable:K.horizontalScrollable,mobileControlsHeight:u});Y.current.containerPaddingBottom=st,_.useEffect(()=>{var je,et,ht;I.current?(je=E.current)==null||je.relayout():(et=P.current)==null||et.schedule();const Se=U.current,xe=Ume({controlsVisible:Je,keyboardOpen:pt,previous:Se});U.current={keyboardOpen:pt,controlsVisible:Je},Je&&(I.current?Wt():xe?((ht=E.current)==null||ht.scrollToBottom("keyboardOffset",{force:!0}),Wt()):pt||Dt("keyboardOffset"))},[Qe,pt,Je,st,Wt,Dt]);const lt=_.useMemo(()=>({onFocusCapture:it,onBlurCapture:tt}),[it,tt]);return{scrollState:K,isAtBottom:h.isAtBottom,hasNewFramesWhileAway:h.hasNewFramesWhileAway,ptyInputFocused:At,showMobilePtyControls:Je,touchEditingSurface:gt,keyboardOffset:Qe,physicalKeyboardMode:ye,softKeyboardEditingSurface:we,mobileControlsBottomInset:mt,connectionReady:d.ready,connectionOverlay:d.overlay,containerPaddingBottom:st,traceEnabled:p,findReady:G,findResultIndex:ne.resultIndex,findResultCount:ne.resultCount,findNext:fe,findPrevious:ke,clearFind:Be,scrollToBottom:Q,scrollToRatio:V,scrollToXRatio:Z,clearNewFramesWhileAway:Wt,sendMobileInput:Pe,pasteMobileClipboard:qe,handleTerminalContainerMouseDown:ue,handlePasteCapture:ve,pointerHandlers:Nt.pointerHandlers,focusHandlers:lt,ptySelectionToolbar:Nt.ptySelectionToolbar,ptySelectionHandles:Nt.ptySelectionHandles,ptySelectionPathAction:Nt.ptySelectionPathAction,ptySelectionHandleMetrics:Nt.ptySelectionHandleMetrics,copyPtySelection:Nt.copyPtySelection,openPtySelectionPathAction:Nt.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:Nt.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:Nt.handlePtySelectionHandleTouchStart,isPtyDragOver:He,handlePtyDragOver:Bt,handlePtyDragLeave:re,handlePtyDrop:ae}}function Xme({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,active:i=!0,findRequest:s}){const[o,l]=_.useState(null),[u,d]=_.useState(0),[h,p]=_.useState(!1),[y,g]=_.useState(""),b=_.useRef(null),w=_.useRef(null),x=Gme({sessionId:e,sessionKind:t,ptyOwner:r,active:i,containerEl:o,spacerRef:b,xtermHostRef:w,mobileControlsHeight:u}),E=x.ptySelectionHandleMetrics,{clearFind:k,findNext:T,findPrevious:R,findReady:z,findResultCount:N,findResultIndex:$}=x,P=_.useCallback(()=>{R(y)},[R,y]),q=_.useCallback(()=>{T(y)},[T,y]),H=_.useCallback(()=>p(!0),[]),U=_.useCallback(()=>{p(!1),k()},[k]),O=x3({enabled:i,open:h,openRequest:s,onOpen:H,onClose:U,onPrevious:P,onNext:q});return _.useEffect(()=>{!h||!z||(y?T(y,!0):k())},[k,T,h,y,z]),v.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":x.connectionReady?"true":"false","aria-busy":!x.connectionReady,children:[h?v.jsx(V0,{query:y,resultIndex:$,resultCount:N,focusRequest:O.focusRequest,loading:!!y&&!z,onQueryChange:g,onPrevious:P,onNext:q,onClose:O.closeFind}):null,v.jsx("div",{ref:l,className:"flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${x.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:x.handleTerminalContainerMouseDown,onPointerDownCapture:x.pointerHandlers.onPointerDownCapture,onPointerMoveCapture:x.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:x.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:x.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:x.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:x.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:x.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:x.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:x.pointerHandlers.onContextMenuCapture,onPasteCapture:x.handlePasteCapture,onDragOver:x.handlePtyDragOver,onDragLeave:x.handlePtyDragLeave,onDrop:x.handlePtyDrop,onFocusCapture:x.focusHandlers.onFocusCapture,onBlurCapture:x.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":x.isPtyDragOver?"true":void 0,children:v.jsx("div",{ref:b,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:v.jsx("div",{ref:w,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})})}),v.jsx(b3,{visible:!x.isAtBottom,hasNewMessages:x.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{x.scrollToBottom("backToBottomBtn",{force:!0}),x.clearNewFramesWhileAway()}}),x.showMobilePtyControls?v.jsx(Vae,{sessionKind:t,provider:n,bottomInset:x.mobileControlsBottomInset,onInput:x.sendMobileInput,onPaste:x.pasteMobileClipboard,onHeightChange:d}):null,x.ptySelectionHandles?v.jsxs(v.Fragment,{children:[v.jsx(X2,{kind:"anchor",position:x.ptySelectionHandles.anchor,metrics:E,"aria-label":"调整选区起点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("anchor",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("anchor",M)}),v.jsx(X2,{kind:"focus",position:x.ptySelectionHandles.focus,metrics:E,"aria-label":"调整选区终点",onPointerDown:M=>x.handlePtySelectionHandlePointerDown("focus",M),onTouchStart:M=>x.handlePtySelectionHandleTouchStart("focus",M)})]}):null,x.ptySelectionToolbar?v.jsxs("div",{className:"fixed z-50 flex -translate-x-1/2 gap-1 rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-lg",style:{left:x.ptySelectionToolbar.left,top:x.ptySelectionToolbar.top},"data-slot":"pty-selection-toolbar",children:[v.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:M=>M.preventDefault(),onClick:x.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),x.ptySelectionPathAction?v.jsx("button",{type:"button",className:"min-w-14 whitespace-nowrap rounded px-3 py-1.5 text-center text-sm font-medium leading-none hover:bg-accent active:bg-accent/80",onPointerDown:M=>M.preventDefault(),onClick:x.openPtySelectionPathAction,"aria-label":x.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:x.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,v.jsx(ele,{state:x.scrollState,onScrollRatio:x.scrollToRatio}),v.jsx(tle,{state:x.scrollState,onScrollRatio:x.scrollToXRatio}),v.jsx(Dae,{...x.connectionOverlay}),v.jsx(Lae,{ptyInputFocused:x.ptyInputFocused,touchEditingSurface:x.touchEditingSurface,softKeyboardEditingSurface:x.softKeyboardEditingSurface,physicalKeyboardMode:x.physicalKeyboardMode,keyboardOffset:x.keyboardOffset,showMobilePtyControls:x.showMobilePtyControls,mobileControlsBottomInset:x.mobileControlsBottomInset}),x.traceEnabled?v.jsx(Zme,{}):null]})}function X2({kind:e,position:t,metrics:n,"aria-label":r,onPointerDown:i,onTouchStart:s}){const o=n.touchSize/2,l=2,u=n.visualSize,d=Math.max(n.stemSize+2,u+1),h=o-l/2,p=o,y=e==="anchor"?h-u+l:h,g=p+d-u+l,b=e==="anchor"?{borderTopLeftRadius:u,borderBottomLeftRadius:u,borderTopRightRadius:2,borderBottomRightRadius:u}:{borderTopLeftRadius:2,borderBottomLeftRadius:u,borderTopRightRadius:u,borderBottomRightRadius:u};return v.jsxs("button",{type:"button",className:"fixed z-50 touch-none rounded-full bg-transparent p-0 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",style:{left:t.left,top:t.top,width:n.touchSize,height:n.touchSize,transform:"translate(-50%, -50%)"},"data-slot":"pty-selection-handle","data-kind":e,"aria-label":r,onPointerDown:i,onTouchStart:s,children:[v.jsx("span",{className:"pointer-events-none absolute rounded-full bg-primary",style:{left:h,top:p,width:l,height:d},"data-slot":"pty-selection-handle-stem"}),v.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:y,top:g,width:u,height:u,...b},"data-slot":"pty-selection-handle-dot"})]})}function Zme(){const[e,t]=_.useState(!1);async function n(){const r=Mae();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return v.jsx("button",{type:"button",className:"absolute left-3 top-3 z-30 rounded border border-border bg-popover/90 px-2 py-1 text-[11px] text-muted-foreground",onPointerDown:r=>r.preventDefault(),onClick:n,"data-slot":"pty-scroll-trace-copy",children:e?"Copied":"Trace"})}const Qme=3,Jme=1024,ege=720,Qm=.5,g4=_.createContext(null);function tge({children:e}){const[t,n]=_.useState([]),[r,i]=_.useState(null),[s,o]=_.useState(null),l=ze(k=>k.selectedProxyId),u=Ut(k=>k.sessions),d=Ut(k=>k.sessionListLoaded),h=_.useRef(l),p=_.useRef(null),y=_.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
636
636
  `),[u]),g=_.useCallback(k=>{p.current=k.sessionId,i(k),n(T=>roe(T,k.sessionId,{capacity:Qme,now:Date.now(),activeSessionId:k.sessionId}).map(z=>z.sessionId===k.sessionId?{...z,sessionKind:k.sessionKind,provider:k.provider,ptyOwner:k.ptyOwner}:z))},[]),b=_.useCallback(k=>{p.current===k&&(p.current=null),i(T=>(T==null?void 0:T.sessionId)===k?null:T),o(T=>p.current===null?null:T)},[]),w=_.useCallback((k,T)=>{p.current===k&&o(R=>!T||R&&ige(R,T)?R:T)},[]),x=_.useCallback((k,T)=>{T!==void 0&&n(R=>R.map(z=>z.sessionId===k?{...z,findRequest:T}:z))},[]);_.useEffect(()=>{if(!d)return;const k=new Set(y?y.split(`
637
- `):[]);n(T=>T.filter(R=>k.has(R.sessionId))),i(T=>T&&k.has(T.sessionId)?T:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),_.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const E=_.useMemo(()=>({activate:g,deactivate:b,updateFindRequest:x,updateViewportRect:w}),[g,b,x,w]);return v.jsxs(g4.Provider,{value:E,children:[e,v.jsx(rge,{entries:t,activeView:r,viewportRect:s})]})}function nge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,findRequest:i}){const s=_.useContext(g4),o=_.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateViewportRect:h}=s;return _.useLayoutEffect(()=>(l({sessionId:e,sessionKind:t,provider:n,ptyOwner:r}),()=>u(e)),[l,u,e,t,n,r]),_.useLayoutEffect(()=>{d(e,i)},[i,e,d]),_.useLayoutEffect(()=>{const p=o.current;if(!p)return;const y=()=>{const b=p.getBoundingClientRect();h(e,{top:b.top,left:b.left,width:b.width,height:b.height})};y();const g=new ResizeObserver(y);return g.observe(p),window.addEventListener("resize",y),()=>{g.disconnect(),window.removeEventListener("resize",y)}},[e,h]),v.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function rge({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:v.jsx("div",{className:"fixed inset-0 z-10 pointer-events-none","data-slot":"pty-keepalive-layer",children:e.map(r=>{const i=(t==null?void 0:t.sessionId)===r.sessionId&&n!==null,s=i?n:{top:-1e5,left:0,width:(n==null?void 0:n.width)??Jme,height:(n==null?void 0:n.height)??ege};return v.jsx("div",{className:"absolute overflow-hidden bg-background","data-slot":"pty-keepalive-entry","data-session-id":r.sessionId,"data-active":i?"true":"false","aria-hidden":!i,style:{top:s.top,left:s.left,width:s.width,height:s.height,pointerEvents:i?"auto":"none",visibility:i?"visible":"hidden"},children:v.jsx(_3,{sessionId:r.sessionId,children:v.jsx(Xme,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,ptyOwner:r.ptyOwner,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function ige(e,t){return Math.abs(e.top-t.top)<=Qm&&Math.abs(e.left-t.left)<=Qm&&Math.abs(e.width-t.width)<=Qm&&Math.abs(e.height-t.height)<=Qm}function mE({route:e,surface:t,proxiesLength:n,hasProxy:r,sessionCount:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 服务器需要 client token。请在设置里填写。":s==="invalid_client_token"?"当前浏览器保存的 client token 无效或已过期。请在设置里更新。":n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。":t==="mobile"&&e==="proxy-select"||!r?"选择要连接的开发机。":i===0?"还没有会话。可以从本地终端接入,也可以新建会话。":t==="desktop"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}const gE="dev-anywhere:last-chat-route",v4="dev-anywhere:route-restored",qS="dev-anywhere:restored-target";function sge(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function oge(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(gE))??null}catch{return null}}function age(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(gE,e)}catch{}}function y4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(gE)}catch{}}function lge(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(v4))==="1"}catch{return!1}}function cge(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(v4,"1")}catch{}}function uge(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(qS,e)}catch{}}function dge(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(qS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(qS)),n}catch{return null}}function hge(e){const t=OL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Ag(){if(typeof window>"u"||typeof navigator>"u")return!1;const e=typeof window.matchMedia=="function"&&(window.matchMedia("(display-mode: standalone)").matches||window.matchMedia("(display-mode: fullscreen)").matches),t=!!navigator.standalone;return e||t}function fge(){return typeof navigator>"u"?{supported:!0}:hge({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Ag()})}function pge(){Xpe(),Zpe();const e=Bi(),t=Js(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=_.useState(!1),[o,l]=_.useState(()=>Ag()),u=ze(P=>P.proxies.length),d=ze(P=>P.proxyListLoaded),h=ze(P=>P.relayClientAuthIssue),p=ze(P=>!!P.selectedProxyId),y=ze(P=>P.selectedProxyId),g=ze(P=>P.selectedProxyName),b=Ut(P=>P.sessions.length),w=ze(P=>P.pendingToast),x=ze(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=mE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:b,relayClientAuthIssue:h}),T=g??y,z=e.pathname==="/sessions"&&d&&u>0?v.jsxs(St,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":T?`切换开发机,当前 ${T}`:"切换开发机",onClick:()=>t("/"),children:[v.jsx(EP,{className:"size-4 text-primary","aria-hidden":"true"}),v.jsxs("span",{className:"min-w-0 truncate",children:[v.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?v.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;_.useEffect(()=>{if(!w)return;({error:nt.error,info:nt.info,success:nt.success})[w.kind](w.message),x(null)},[w,x]),_.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Ag());return}const P=window.matchMedia("(display-mode: standalone)"),q=window.matchMedia("(display-mode: fullscreen)"),H=()=>l(Ag());return H(),P.addEventListener("change",H),q.addEventListener("change",H),()=>{P.removeEventListener("change",H),q.removeEventListener("change",H)}},[]);const N=_.useRef(!1);_.useEffect(()=>{if(N.current)return;N.current=!0;const P=sge({pathname:e.pathname,alreadyRestored:lge(),lastRoute:oge()});cge(),P&&(uge(P),t(P,{replace:!0}))},[]);const $=_.useRef(!1);return _.useEffect(()=>{n?($.current=!0,age(`${e.pathname}${e.search}`)):$.current&&($.current=!1,y4())},[n,e.pathname,e.search]),v.jsxs("div",{className:"flex flex-col bg-background text-foreground",style:{height:"var(--dev-app-shell-height, max(100dvh, var(--dev-visual-viewport-height, 100dvh)))"},"data-slot":"app-shell","data-standalone-display":o?"true":void 0,children:[!n&&v.jsx(St,{variant:"ghost",size:"icon",className:"dev-mobile-settings-trigger group fixed right-4 z-30 size-11 rounded-full border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-transparent hover:text-foreground md:hidden","aria-label":"设置","data-slot":"mobile-settings-trigger",onClick:()=>s(!0),children:v.jsx("span",{"data-slot":"mobile-settings-trigger-visual",className:"flex size-7 items-center justify-center rounded-full border border-border/80 bg-card/90 shadow-lg backdrop-blur transition-colors group-hover:border-primary/45 group-hover:bg-accent",children:v.jsx(TP,{className:"size-4","aria-hidden":"true"})})}),!n&&v.jsx(ose,{subtitle:k,action:z}),v.jsx(noe,{}),v.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[v.jsx(rse,{className:"hidden md:flex"}),v.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:v.jsx(tge,{children:v.jsx("div",{className:We("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:v.jsx(CU,{})},r?"top-level":e.pathname)})})]}),v.jsx(U0,{open:i,onOpenChange:s}),v.jsx(Dse,{}),v.jsx(mse,{}),v.jsx(PX,{})]})}function _4({subtitle:e,action:t}){return v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[v.jsx(BB,{texts:jB,className:"text-2xl md:text-3xl font-bold"}),v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&v.jsx("div",{children:t})]})}function mge(){const e=ze(o=>o.proxies),t=ze(o=>!!o.selectedProxyId),n=ze(o=>o.relayClientAuthIssue),r=Ut(o=>o.sessions.length),i=mE({route:"proxy-select",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n}),s=n==="missing_client_token"?"client-token-missing":n==="invalid_client_token"?"client-token-invalid":null;return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(SB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:s?v.jsx(nc,{variant:s}):v.jsx(_4,{subtitle:i})})]})}function gge(){const e=ze(o=>o.proxies),t=ze(o=>!!o.selectedProxyId),n=ze(o=>o.relayClientAuthIssue),r=Ut(o=>o.sessions.length),i=ki("local",ln.proxyId)!==null;if(!t&&!i)return v.jsx(EU,{to:"/",replace:!0});const s=mE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(MB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:v.jsx(_4,{subtitle:s})})]})}function b4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function vge(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function w4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return vge(e,typeof((t=b4())==null?void 0:t.request)=="function")}function yge(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function _ge(){const e=b4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(yge(w4()));return e.request("screen")}function bge(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class wge{constructor(t={}){vt(this,"activeScopes",new Set);vt(this,"pendingScopes",new Set);vt(this,"listeners",new Map);vt(this,"sentinel",null);vt(this,"requestInFlight",null);vt(this,"requestWakeLock");vt(this,"documentRef");vt(this,"windowRef");vt(this,"unavailableReason");vt(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});vt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??_ge,this.unavailableReason=typeof t.request=="function"?null:w4(),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(bge(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const Xa=new wge;function S4(e){const[t,n]=_.useState(()=>Xa.getSnapshot(e));_.useEffect(()=>Xa.subscribe(e,n),[e]),_.useEffect(()=>()=>{Xa.disable(e).catch(()=>{})},[e]);const r=_.useCallback(()=>Xa.enable(e),[e]),i=_.useCallback(()=>Xa.disable(e),[e]),s=_.useCallback(()=>Xa.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function Sge(){return new AudioContext}class xge{constructor(t=Sge){vt(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Ng=new xge,Z2=400,Ou=[];let x4=1;function Ege(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Vh(e){const t={sequence:x4++,timestamp:new Date().toISOString(),monotonicMs:Ege(),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>Z2&&Ou.splice(0,Ou.length-Z2)}function Cge(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function kge(){Ou.length=0,x4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Cge,clear:kge});function E4(e){return`voice-pilot:${e}`}function Tge(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 Rge="modulepreload",Age=function(e){return"/"+e},Q2={},Nge=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=Age(d),d in Q2)return;Q2[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":Rge,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((g,b)=>{y.addEventListener("load",g),y.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},Mge="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Oge=20,Za=Zu*Oge/1e3,zw=Za*Int16Array.BYTES_PER_ELEMENT;let J2=null;async function Dge(){return J2??(J2=Nge(async()=>{const{default:e}=await import("./fvad-C44UvSw_.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Mge:t}))),J2}class vE{constructor(t,n,r){vt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Dge(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(zw);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Zu)!==0)throw n._free(i),n._fvad_free(r),new Error("浏览器语音活动检测器不支持 16 kHz 音频");if(n._fvad_set_mode(r,t)!==0)throw n._free(i),n._fvad_free(r),new Error("无法配置浏览器语音活动检测器");return new vE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==zw)throw new Error(`语音活动检测帧必须为 ${zw} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Za);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class Pge{constructor(t={}){vt(this,"startSpeechFrames");vt(this,"endSilenceFrames");vt(this,"active",!1);vt(this,"speechFrames",0);vt(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class Lge{constructor(){vt(this,"pending",new Float32Array(Za));vt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Za-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Za&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Za<=t.length;)n(t.slice(r,r+Za)),r+=Za;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const Ige="/__dev_anywhere_debug/voice-fixture",zge=Zu*DB/1e3;function Bge(){return vE.create(3)}const jge={createVad:Bge,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Fge(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 $ge(e){for(const t of e.getTracks())t.stop()}function C4(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 Hge(e){const t=C4(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(),$ge(n),t.state!=="closed"&&await t.close()}}}async function Uge(e,t){const n=C4(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 k4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Ige}:{kind:"microphone"}}async function Wge(e,t=jge){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await Uge(e.source.url,t):await Hge(t)}catch(h){throw n.destroy(),h}const i=new Pge,s=new Lge,o=r.context.createScriptProcessor(zge,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Tge(p),g=n.process(y);e.onFrame({pcm:y,speechProbability:g?1:0,activityLevel:Fge(p)});const b=i.push(g);b==="speech-start"&&e.onSpeechStart(),b==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function qge(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function Vge({title:e,isPtyTitle:t}){if(!t)return v.jsx(v.Fragment,{children:e});const{indicator:n,label:r}=qge(e);return v.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&v.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),v.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function Yge(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 Kge(){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(Yge(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",Jm="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return v.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function Gge({label:e}){return v.jsxs(mo,{className:"relative",children:[v.jsx(xP,{className:"size-4","aria-hidden":"true"}),v.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3 min-w-4 items-center justify-center rounded-[3px] border border-border bg-popover px-0.5 font-mono text-[7px] leading-none text-muted-foreground shadow-sm",children:e})]})}function Xge({sessionId:e,mode:t,onFind:n}){const r=Js(),i=Ut(Me=>Me.sessions.find(de=>de.sessionId===e)),s=Ut(Me=>Me.ptyTitles[e]),o=ze(Me=>Me.ptyFontSize),l=ze(Me=>Me.chatContentFontSize),u=ze(Me=>Me.selectedProxyId),d=ze(Me=>Me.adjustPtyFontSize),h=ze(Me=>Me.adjustChatContentFontSize),p=ze(Me=>Me.setChatContentFontSize),y=ze(Me=>Me.resetPtyFontSize),g=ze(Me=>Me.resetChatContentFontSize),b=ze(Me=>Me.inputModePreference==="hardware"),w=Ut(Me=>Me.renameSession),x=Dx(u,e),E=Ut(Me=>x?!!Me.ptyAutoYesBySessionKey[x]:!1),k=Ut(Me=>Me.setPtyAutoYes),R=hl("(pointer: coarse), (hover: none)")&&!b,z=t==="pty"||(i==null?void 0:i.mode)==="pty",N=(i==null?void 0:i.kind)==="terminal",$=S4(e),P=on(Me=>Me.bySessionId[e]??iy),q=on(Me=>Me.enable),H=on(Me=>Me.disable),U=!!(i!=null&&i.nameLocked&&(i!=null&&i.name)),O=Vx(i),M=U&&(i==null?void 0:i.name)||O||z&&s||(i==null?void 0:i.name)||e.slice(0,8),I=!!(z&&!N&&s&&!U),L=z?o:Mx(l,R),D=!z&&R?KP:VP,Y=z?y:g,[K,F]=_.useState(!1),[A,W]=_.useState(!1),G=P.enabled,B=$.active||G,ne=$.pending||!$.supported||G;function ie(Me){if(z){d(Me);return}if(R){p(L+Me);return}h(Me)}function se(){$.toggle().catch(Me=>{nt.error(Me instanceof Error?Me.message:String(Me))})}async function te(Me){var oe;if(z||N){nt.info("Voice Pilot 目前适用于聊天会话。");return}if(Me!==!0){H(e);return}const de=Mt;if(!de){nt.error("请先连接开发机");return}try{if(!((oe=(await de.requestVoiceConfig()).config)!=null&&oe.configured)){nt.info("请先在设置里配置 Voice Pilot。");return}F(!0)}catch(ye){nt.error(ye instanceof Error?ye.message:String(ye))}}async function he(){var ye;W(!0);let Me=null,de=!1;const oe=E4(e);try{Vh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((ye=navigator.userActivation)==null?void 0:ye.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const we=Xa.enable(oe).then(()=>{Vh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},ct=>{throw Vh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:ct instanceof Error?ct.message:String(ct)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:ct})});Me=O1.acquire("capture");const Qe=Ng.prepare(),mt=k4().kind==="microphone"?Kge():Promise.resolve();await Promise.all([we,Qe,mt]),q(e),de=!0,F(!1)}catch(we){Vh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:we instanceof Error?we.message:String(we)}}),nt.error(we instanceof Error?we.message:String(we))}finally{Me==null||Me.release(),de||await Xa.disable(oe).catch(()=>{}),W(!1)}}const ge=_.useRef(null),Ee=_.useRef(null),[Re,Ie]=_.useState(!1);async function Ye(Me){var we;const de=(we=Me.target.files)==null?void 0:we[0];if(Me.target.value="",!de)return;const oe=Mt;if(!oe){nt.error("请先连接开发机");return}const ye=await xf({relay:oe,sessionId:e,file:de});ye&&Ks(e,`@${ye} `)}async function gt(Me,de){const oe=Mt;if(!oe)throw new Error("请先连接开发机");const ye=await oe.renameSession(Me,de);if(!ye.success)throw new Error(ye.error??"重命名失败");w(Me,ye.name??de),nt.success("已重命名会话")}return v.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[v.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:v.jsxs("div",{className:"grid min-h-12 w-full grid-cols-[2.25rem_minmax(0,1fr)_2.25rem] items-center","data-slot":"chat-header-rail",children:[v.jsx("div",{className:"flex justify-start",children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>r("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:v.jsx(vv,{"aria-hidden":"true"})})}),v.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:v.jsx(Vge,{title:M,isPtyTitle:I})}),v.jsxs(R1,{modal:!1,children:[v.jsx(A1,{asChild:!0,children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:v.jsx(V9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[v.jsx(Im,{className:Jm,children:"会话"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[v.jsx(mo,{children:v.jsx(Dg,{"aria-hidden":"true"})}),"在会话中查找"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>Ie(!0),children:[v.jsx(mo,{children:v.jsx(C8,{"aria-hidden":"true"})}),"重命名"]}),v.jsxs(Kb,{checked:B,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ne,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:se,children:[v.jsx(mo,{children:v.jsx(o8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:$.supported?G?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":$.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),z&&!N&&v.jsxs(Kb,{checked:E,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!x,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:Me=>{x&&k(x,Me===!0)},children:[v.jsx(mo,{children:v.jsx(ra,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!z&&!N&&v.jsxs(Kb,{checked:P.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:te,children:[v.jsx(mo,{children:v.jsx(h8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),v.jsx(Gb,{}),z&&!N?v.jsxs(v.Fragment,{children:[v.jsx(Im,{className:Jm,children:"快捷键"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ks(e,""),children:[v.jsx(Gge,{label:"^O"}),"发送 Ctrl+O"]}),v.jsx(Gb,{}),v.jsx(Im,{className:Jm,children:"文件"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var Me;return(Me=Ee.current)==null?void 0:Me.click()},children:[v.jsx(mo,{children:v.jsx(yv,{"aria-hidden":"true"})}),"上传图片"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var Me;return(Me=ge.current)==null?void 0:Me.click()},children:[v.jsx(mo,{children:v.jsx(RP,{"aria-hidden":"true"})}),"上传文件"]}),v.jsx(Gb,{})]}):null,v.jsx(Im,{className:Jm,children:"字号"}),v.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:v.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[v.jsx(mo,{children:v.jsx(X8,{"aria-hidden":"true"})}),v.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[v.jsx(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:L<=D,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:Me=>{Me.stopPropagation(),ie(-1)},children:v.jsx(p8,{"aria-hidden":"true"})}),v.jsxs("span",{className:"flex h-[22px] min-w-11 items-center justify-center px-1 text-sm font-medium leading-none tabular-nums text-foreground","data-slot":"chat-menu-font-size",children:[L,"px"]}),v.jsx(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:L>=YP,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:Me=>{Me.stopPropagation(),ie(1)},children:v.jsx(R8,{"aria-hidden":"true"})})]})]})}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-font-reset",onClick:Y,children:[v.jsx(mo,{children:v.jsx(M8,{"aria-hidden":"true"})}),v.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),v.jsx(zh,{open:Re,sessionId:e,initialName:i==null?void 0:i.name,onOpenChange:Ie,onRename:gt}),v.jsx(Sc,{open:K&&!P.enabled,onOpenChange:Me=>{A||F(Me)},children:v.jsxs(xc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"开启 Voice Pilot?"}),v.jsx(dc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",disabled:A,onClick:()=>F(!1),children:"取消"}),v.jsx(St,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:A,onClick:()=>{he()},children:A?"正在开启...":"开启 Voice Pilot"})]})]})}),z?v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:Ee,type:"file",accept:"image/*",className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:Me=>{Ye(Me)}}),v.jsx("input",{ref:ge,type:"file",accept:"application/*,text/*",className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:Me=>{Ye(Me)}})]}):null]})}function gu(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let h;n.key&&((l=n.debug)!=null&&l.call(n))&&(h=Date.now());const p=e();if(!(p.length!==r.length||p.some((b,w)=>r[w]!==b)))return i;r=p;let g;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(g=Date.now()),i=t(...p),n.key&&((d=n.debug)!=null&&d.call(n))){const b=Math.round((Date.now()-h)*100)/100,w=Math.round((Date.now()-g)*100)/100,x=w/16,E=(k,T)=>{for(k=String(k);k.length<T;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(b,5)} ms`,`
637
+ `):[]);n(T=>T.filter(R=>k.has(R.sessionId))),i(T=>T&&k.has(T.sessionId)?T:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[y,d]),_.useEffect(()=>{const k=h.current;h.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const E=_.useMemo(()=>({activate:g,deactivate:b,updateFindRequest:x,updateViewportRect:w}),[g,b,x,w]);return v.jsxs(g4.Provider,{value:E,children:[e,v.jsx(rge,{entries:t,activeView:r,viewportRect:s})]})}function nge({sessionId:e,sessionKind:t,provider:n,ptyOwner:r,findRequest:i}){const s=_.useContext(g4),o=_.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateViewportRect:h}=s;return _.useLayoutEffect(()=>(l({sessionId:e,sessionKind:t,provider:n,ptyOwner:r}),()=>u(e)),[l,u,e,t,n,r]),_.useLayoutEffect(()=>{d(e,i)},[i,e,d]),_.useLayoutEffect(()=>{const p=o.current;if(!p)return;const y=()=>{const b=p.getBoundingClientRect();h(e,{top:b.top,left:b.left,width:b.width,height:b.height})};y();const g=new ResizeObserver(y);return g.observe(p),window.addEventListener("resize",y),()=>{g.disconnect(),window.removeEventListener("resize",y)}},[e,h]),v.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function rge({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:v.jsx("div",{className:"fixed inset-0 z-10 pointer-events-none","data-slot":"pty-keepalive-layer",children:e.map(r=>{const i=(t==null?void 0:t.sessionId)===r.sessionId&&n!==null,s=i?n:{top:-1e5,left:0,width:(n==null?void 0:n.width)??Jme,height:(n==null?void 0:n.height)??ege};return v.jsx("div",{className:"absolute overflow-hidden bg-background","data-slot":"pty-keepalive-entry","data-session-id":r.sessionId,"data-active":i?"true":"false","aria-hidden":!i,style:{top:s.top,left:s.left,width:s.width,height:s.height,pointerEvents:i?"auto":"none",visibility:i?"visible":"hidden"},children:v.jsx(_3,{sessionId:r.sessionId,children:v.jsx(Xme,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,ptyOwner:r.ptyOwner,active:i,findRequest:r.findRequest})})},r.sessionId)})})}function ige(e,t){return Math.abs(e.top-t.top)<=Qm&&Math.abs(e.left-t.left)<=Qm&&Math.abs(e.width-t.width)<=Qm&&Math.abs(e.height-t.height)<=Qm}function mE({route:e,surface:t,proxiesLength:n,hasProxy:r,sessionCount:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 服务器需要 client token。请在设置里填写。":s==="invalid_client_token"?"当前浏览器保存的 client token 无效或已过期。请在设置里更新。":n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机。":t==="mobile"&&e==="proxy-select"||!r?"选择要连接的开发机。":i===0?"还没有会话。可以从本地终端接入,也可以新建会话。":t==="desktop"?"从左侧打开会话,或新建会话开始新的任务。":"打开会话,或新建会话开始新的任务。"}const gE="dev-anywhere:last-chat-route",v4="dev-anywhere:route-restored",qS="dev-anywhere:restored-target";function sge(e){return e.alreadyRestored||e.pathname!=="/"||!e.lastRoute||!e.lastRoute.startsWith("/chat/")?null:e.lastRoute}function oge(){var e;try{return((e=globalThis.localStorage)==null?void 0:e.getItem(gE))??null}catch{return null}}function age(e){var t;try{(t=globalThis.localStorage)==null||t.setItem(gE,e)}catch{}}function y4(){var e;try{(e=globalThis.localStorage)==null||e.removeItem(gE)}catch{}}function lge(){var e;try{return((e=globalThis.sessionStorage)==null?void 0:e.getItem(v4))==="1"}catch{return!1}}function cge(){var e;try{(e=globalThis.sessionStorage)==null||e.setItem(v4,"1")}catch{}}function uge(e){var t;try{(t=globalThis.sessionStorage)==null||t.setItem(qS,e)}catch{}}function dge(){var e,t;try{const n=((e=globalThis.sessionStorage)==null?void 0:e.getItem(qS))??null;return n!==null&&((t=globalThis.sessionStorage)==null||t.removeItem(qS)),n}catch{return null}}function hge(e){const t=OL(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Ag(){if(typeof window>"u"||typeof navigator>"u")return!1;const e=typeof window.matchMedia=="function"&&(window.matchMedia("(display-mode: standalone)").matches||window.matchMedia("(display-mode: fullscreen)").matches),t=!!navigator.standalone;return e||t}function fge(){return typeof navigator>"u"?{supported:!0}:hge({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Ag()})}function pge(){Xpe(),Zpe();const e=Bi(),t=Js(),n=e.pathname.startsWith("/chat/"),r=e.pathname==="/"||e.pathname==="/sessions",[i,s]=_.useState(!1),[o,l]=_.useState(()=>Ag()),u=ze(P=>P.proxies.length),d=ze(P=>P.proxyListLoaded),h=ze(P=>P.relayClientAuthIssue),p=ze(P=>!!P.selectedProxyId),y=ze(P=>P.selectedProxyId),g=ze(P=>P.selectedProxyName),b=Ut(P=>P.sessions.length),w=ze(P=>P.pendingToast),x=ze(P=>P.setPendingToast),E=e.pathname==="/"?"proxy-select":"sessions",k=mE({route:E,surface:"mobile",proxiesLength:u,hasProxy:p,sessionCount:b,relayClientAuthIssue:h}),T=g??y,z=e.pathname==="/sessions"&&d&&u>0?v.jsxs(St,{variant:"ghost",size:"sm",className:"h-auto min-h-11 max-w-full justify-start rounded-md border border-border/70 bg-background/35 px-3 py-2 text-left text-muted-foreground hover:border-primary/45 hover:bg-accent/70 hover:text-foreground","data-slot":"mobile-switch-proxy","aria-label":T?`切换开发机,当前 ${T}`:"切换开发机",onClick:()=>t("/"),children:[v.jsx(EP,{className:"size-4 text-primary","aria-hidden":"true"}),v.jsxs("span",{className:"min-w-0 truncate",children:[v.jsx("span",{className:"text-foreground",children:"切换开发机"}),T?v.jsxs("span",{className:"ml-1 text-muted-foreground/75",children:["· ",T]}):null]})]}):null;_.useEffect(()=>{if(!w)return;({error:nt.error,info:nt.info,success:nt.success})[w.kind](w.message),x(null)},[w,x]),_.useEffect(()=>{if(typeof window.matchMedia!="function"){l(Ag());return}const P=window.matchMedia("(display-mode: standalone)"),q=window.matchMedia("(display-mode: fullscreen)"),H=()=>l(Ag());return H(),P.addEventListener("change",H),q.addEventListener("change",H),()=>{P.removeEventListener("change",H),q.removeEventListener("change",H)}},[]);const N=_.useRef(!1);_.useEffect(()=>{if(N.current)return;N.current=!0;const P=sge({pathname:e.pathname,alreadyRestored:lge(),lastRoute:oge()});cge(),P&&(uge(P),t(P,{replace:!0}))},[]);const $=_.useRef(!1);return _.useEffect(()=>{n?($.current=!0,age(`${e.pathname}${e.search}`)):$.current&&($.current=!1,y4())},[n,e.pathname,e.search]),v.jsxs("div",{className:"flex flex-col bg-background text-foreground",style:{height:"var(--dev-app-shell-height, max(100dvh, var(--dev-visual-viewport-height, 100dvh)))"},"data-slot":"app-shell","data-standalone-display":o?"true":void 0,children:[!n&&v.jsx(St,{variant:"ghost",size:"icon",className:"dev-mobile-settings-trigger group fixed right-4 z-30 size-11 rounded-full border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-transparent hover:text-foreground md:hidden","aria-label":"设置","data-slot":"mobile-settings-trigger",onClick:()=>s(!0),children:v.jsx("span",{"data-slot":"mobile-settings-trigger-visual",className:"flex size-7 items-center justify-center rounded-full border border-border/80 bg-card/90 shadow-lg backdrop-blur transition-colors group-hover:border-primary/45 group-hover:bg-accent",children:v.jsx(TP,{className:"size-4","aria-hidden":"true"})})}),!n&&v.jsx(ose,{subtitle:k,action:z}),v.jsx(noe,{}),v.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[v.jsx(rse,{className:"hidden md:flex"}),v.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:v.jsx(tge,{children:v.jsx("div",{className:We("h-full",!r&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),children:v.jsx(CU,{})},r?"top-level":e.pathname)})})]}),v.jsx(U0,{open:i,onOpenChange:s}),v.jsx(Dse,{}),v.jsx(mse,{}),v.jsx(PX,{})]})}function _4({subtitle:e,action:t}){return v.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[v.jsx(BB,{texts:jB,className:"text-2xl md:text-3xl font-bold"}),v.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}),t&&v.jsx("div",{children:t})]})}function mge(){const e=ze(o=>o.proxies),t=ze(o=>!!o.selectedProxyId),n=ze(o=>o.relayClientAuthIssue),r=Ut(o=>o.sessions.length),i=mE({route:"proxy-select",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n}),s=n==="missing_client_token"?"client-token-missing":n==="invalid_client_token"?"client-token-invalid":null;return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(SB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:s?v.jsx(nc,{variant:s}):v.jsx(_4,{subtitle:i})})]})}function gge(){const e=ze(o=>o.proxies),t=ze(o=>!!o.selectedProxyId),n=ze(o=>o.relayClientAuthIssue),r=Ut(o=>o.sessions.length),i=ki("local",ln.proxyId)!==null;if(!t&&!i)return v.jsx(EU,{to:"/",replace:!0});const s=mE({route:"sessions",surface:"desktop",proxiesLength:e.length,hasProxy:t,sessionCount:r,relayClientAuthIssue:n});return v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"h-full md:hidden",children:v.jsx(MB,{layout:"page"})}),v.jsx("div",{className:"hidden md:block h-full",children:v.jsx(_4,{subtitle:s})})]})}function b4(){if(!(typeof navigator>"u"))return navigator.wakeLock}function vge(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function w4(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return vge(e,typeof((t=b4())==null?void 0:t.request)=="function")}function yge(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function _ge(){const e=b4();if(typeof(e==null?void 0:e.request)!="function")throw new Error(yge(w4()));return e.request("screen")}function bge(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class wge{constructor(t={}){vt(this,"activeScopes",new Set);vt(this,"pendingScopes",new Set);vt(this,"listeners",new Map);vt(this,"sentinel",null);vt(this,"requestInFlight",null);vt(this,"requestWakeLock");vt(this,"documentRef");vt(this,"windowRef");vt(this,"unavailableReason");vt(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});vt(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??_ge,this.unavailableReason=typeof t.request=="function"?null:w4(),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(bge(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const Xa=new wge;function S4(e){const[t,n]=_.useState(()=>Xa.getSnapshot(e));_.useEffect(()=>Xa.subscribe(e,n),[e]),_.useEffect(()=>()=>{Xa.disable(e).catch(()=>{})},[e]);const r=_.useCallback(()=>Xa.enable(e),[e]),i=_.useCallback(()=>Xa.disable(e),[e]),s=_.useCallback(()=>Xa.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function Sge(){return new AudioContext}class xge{constructor(t=Sge){vt(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Ng=new xge,Z2=400,Ou=[];let x4=1;function Ege(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Vh(e){const t={sequence:x4++,timestamp:new Date().toISOString(),monotonicMs:Ege(),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>Z2&&Ou.splice(0,Ou.length-Z2)}function Cge(){return Ou.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function kge(){Ou.length=0,x4=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Cge,clear:kge});function E4(e){return`voice-pilot:${e}`}function Tge(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 Rge="modulepreload",Age=function(e){return"/"+e},Q2={},Nge=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=Age(d),d in Q2)return;Q2[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":Rge,h||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),h)return new Promise((g,b)=>{y.addEventListener("load",g),y.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},Mge="/assets/fvad-DYxbW2my.wasm",Zu=16e3,Oge=20,Za=Zu*Oge/1e3,zw=Za*Int16Array.BYTES_PER_ELEMENT;let J2=null;async function Dge(){return J2??(J2=Nge(async()=>{const{default:e}=await import("./fvad-kjPtSeoA.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?Mge:t}))),J2}class vE{constructor(t,n,r){vt(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await Dge(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(zw);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,Zu)!==0)throw n._free(i),n._fvad_free(r),new Error("浏览器语音活动检测器不支持 16 kHz 音频");if(n._fvad_set_mode(r,t)!==0)throw n._free(i),n._fvad_free(r),new Error("无法配置浏览器语音活动检测器");return new vE(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==zw)throw new Error(`语音活动检测帧必须为 ${zw} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Za);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class Pge{constructor(t={}){vt(this,"startSpeechFrames");vt(this,"endSilenceFrames");vt(this,"active",!1);vt(this,"speechFrames",0);vt(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class Lge{constructor(){vt(this,"pending",new Float32Array(Za));vt(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Za-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Za&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Za<=t.length;)n(t.slice(r,r+Za)),r+=Za;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const Ige="/__dev_anywhere_debug/voice-fixture",zge=Zu*DB/1e3;function Bge(){return vE.create(3)}const jge={createVad:Bge,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function Fge(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 $ge(e){for(const t of e.getTracks())t.stop()}function C4(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 Hge(e){const t=C4(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(),$ge(n),t.state!=="closed"&&await t.close()}}}async function Uge(e,t){const n=C4(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 k4(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:Ige}:{kind:"microphone"}}async function Wge(e,t=jge){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await Uge(e.source.url,t):await Hge(t)}catch(h){throw n.destroy(),h}const i=new Pge,s=new Lge,o=r.context.createScriptProcessor(zge,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=h=>{l&&s.push(h.inputBuffer.getChannelData(0),p=>{const y=Tge(p),g=n.process(y);e.onFrame({pcm:y,speechProbability:g?1:0,activityLevel:Fge(p)});const b=i.push(g);b==="speech-start"&&e.onSpeechStart(),b==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function qge(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function Vge({title:e,isPtyTitle:t}){if(!t)return v.jsx(v.Fragment,{children:e});const{indicator:n,label:r}=qge(e);return v.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&v.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),v.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function Yge(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 Kge(){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(Yge(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const mu="min-h-9 gap-2.5",Jm="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground";function mo({children:e,className:t}){return v.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function Gge({label:e}){return v.jsxs(mo,{className:"relative",children:[v.jsx(xP,{className:"size-4","aria-hidden":"true"}),v.jsx("span",{className:"absolute -right-1.5 -top-1 flex h-3 min-w-4 items-center justify-center rounded-[3px] border border-border bg-popover px-0.5 font-mono text-[7px] leading-none text-muted-foreground shadow-sm",children:e})]})}function Xge({sessionId:e,mode:t,onFind:n}){const r=Js(),i=Ut(Me=>Me.sessions.find(de=>de.sessionId===e)),s=Ut(Me=>Me.ptyTitles[e]),o=ze(Me=>Me.ptyFontSize),l=ze(Me=>Me.chatContentFontSize),u=ze(Me=>Me.selectedProxyId),d=ze(Me=>Me.adjustPtyFontSize),h=ze(Me=>Me.adjustChatContentFontSize),p=ze(Me=>Me.setChatContentFontSize),y=ze(Me=>Me.resetPtyFontSize),g=ze(Me=>Me.resetChatContentFontSize),b=ze(Me=>Me.inputModePreference==="hardware"),w=Ut(Me=>Me.renameSession),x=Dx(u,e),E=Ut(Me=>x?!!Me.ptyAutoYesBySessionKey[x]:!1),k=Ut(Me=>Me.setPtyAutoYes),R=hl("(pointer: coarse), (hover: none)")&&!b,z=t==="pty"||(i==null?void 0:i.mode)==="pty",N=(i==null?void 0:i.kind)==="terminal",$=S4(e),P=on(Me=>Me.bySessionId[e]??iy),q=on(Me=>Me.enable),H=on(Me=>Me.disable),U=!!(i!=null&&i.nameLocked&&(i!=null&&i.name)),O=Vx(i),M=U&&(i==null?void 0:i.name)||O||z&&s||(i==null?void 0:i.name)||e.slice(0,8),I=!!(z&&!N&&s&&!U),L=z?o:Mx(l,R),D=!z&&R?KP:VP,Y=z?y:g,[K,F]=_.useState(!1),[A,W]=_.useState(!1),G=P.enabled,B=$.active||G,ne=$.pending||!$.supported||G;function ie(Me){if(z){d(Me);return}if(R){p(L+Me);return}h(Me)}function se(){$.toggle().catch(Me=>{nt.error(Me instanceof Error?Me.message:String(Me))})}async function te(Me){var oe;if(z||N){nt.info("Voice Pilot 目前适用于聊天会话。");return}if(Me!==!0){H(e);return}const de=Mt;if(!de){nt.error("请先连接开发机");return}try{if(!((oe=(await de.requestVoiceConfig()).config)!=null&&oe.configured)){nt.info("请先在设置里配置 Voice Pilot。");return}F(!0)}catch(ye){nt.error(ye instanceof Error?ye.message:String(ye))}}async function he(){var ye;W(!0);let Me=null,de=!1;const oe=E4(e);try{Vh({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((ye=navigator.userActivation)==null?void 0:ye.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const we=Xa.enable(oe).then(()=>{Vh({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},ct=>{throw Vh({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:ct instanceof Error?ct.message:String(ct)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:ct})});Me=O1.acquire("capture");const Qe=Ng.prepare(),mt=k4().kind==="microphone"?Kge():Promise.resolve();await Promise.all([we,Qe,mt]),q(e),de=!0,F(!1)}catch(we){Vh({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:we instanceof Error?we.message:String(we)}}),nt.error(we instanceof Error?we.message:String(we))}finally{Me==null||Me.release(),de||await Xa.disable(oe).catch(()=>{}),W(!1)}}const ge=_.useRef(null),Ee=_.useRef(null),[Re,Ie]=_.useState(!1);async function Ye(Me){var we;const de=(we=Me.target.files)==null?void 0:we[0];if(Me.target.value="",!de)return;const oe=Mt;if(!oe){nt.error("请先连接开发机");return}const ye=await xf({relay:oe,sessionId:e,file:de});ye&&Ks(e,`@${ye} `)}async function gt(Me,de){const oe=Mt;if(!oe)throw new Error("请先连接开发机");const ye=await oe.renameSession(Me,de);if(!ye.success)throw new Error(ye.error??"重命名失败");w(Me,ye.name??de),nt.success("已重命名会话")}return v.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[v.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:v.jsxs("div",{className:"grid min-h-12 w-full grid-cols-[2.25rem_minmax(0,1fr)_2.25rem] items-center","data-slot":"chat-header-rail",children:[v.jsx("div",{className:"flex justify-start",children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>r("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:v.jsx(vv,{"aria-hidden":"true"})})}),v.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:v.jsx(Vge,{title:M,isPtyTitle:I})}),v.jsxs(R1,{modal:!1,children:[v.jsx(A1,{asChild:!0,children:v.jsx(St,{variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",children:v.jsx(V9,{"aria-hidden":"true"})})}),v.jsxs(N1,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",children:[v.jsx(Im,{className:Jm,children:"会话"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-find",onSelect:n,children:[v.jsx(mo,{children:v.jsx(Dg,{"aria-hidden":"true"})}),"在会话中查找"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-rename",onSelect:()=>Ie(!0),children:[v.jsx(mo,{children:v.jsx(C8,{"aria-hidden":"true"})}),"重命名"]}),v.jsxs(Kb,{checked:B,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:ne,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:se,children:[v.jsx(mo,{children:v.jsx(o8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:$.supported?G?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":$.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),z&&!N&&v.jsxs(Kb,{checked:E,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!x,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:Me=>{x&&k(x,Me===!0)},children:[v.jsx(mo,{children:v.jsx(ra,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!z&&!N&&v.jsxs(Kb,{checked:P.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:te,children:[v.jsx(mo,{children:v.jsx(h8,{"aria-hidden":"true"})}),v.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),v.jsx(Gb,{}),z&&!N?v.jsxs(v.Fragment,{children:[v.jsx(Im,{className:Jm,children:"快捷键"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>Ks(e,""),children:[v.jsx(Gge,{label:"^O"}),"发送 Ctrl+O"]}),v.jsx(Gb,{}),v.jsx(Im,{className:Jm,children:"文件"}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-image",onClick:()=>{var Me;return(Me=Ee.current)==null?void 0:Me.click()},children:[v.jsx(mo,{children:v.jsx(yv,{"aria-hidden":"true"})}),"上传图片"]}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-upload-file",onClick:()=>{var Me;return(Me=ge.current)==null?void 0:Me.click()},children:[v.jsx(mo,{children:v.jsx(RP,{"aria-hidden":"true"})}),"上传文件"]}),v.jsx(Gb,{})]}):null,v.jsx(Im,{className:Jm,children:"字号"}),v.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:v.jsxs("div",{className:"inline-grid min-h-9 grid-cols-[1.25rem_auto] items-center gap-x-2.5 py-1","data-slot":"chat-menu-font-row",children:[v.jsx(mo,{children:v.jsx(X8,{"aria-hidden":"true"})}),v.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[v.jsx(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:L<=D,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:Me=>{Me.stopPropagation(),ie(-1)},children:v.jsx(p8,{"aria-hidden":"true"})}),v.jsxs("span",{className:"flex h-[22px] min-w-11 items-center justify-center px-1 text-sm font-medium leading-none tabular-nums text-foreground","data-slot":"chat-menu-font-size",children:[L,"px"]}),v.jsx(St,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:L>=YP,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:Me=>{Me.stopPropagation(),ie(1)},children:v.jsx(R8,{"aria-hidden":"true"})})]})]})}),v.jsxs(bo,{className:mu,"data-slot":"chat-menu-font-reset",onClick:Y,children:[v.jsx(mo,{children:v.jsx(M8,{"aria-hidden":"true"})}),v.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),v.jsx(zh,{open:Re,sessionId:e,initialName:i==null?void 0:i.name,onOpenChange:Ie,onRename:gt}),v.jsx(Sc,{open:K&&!P.enabled,onOpenChange:Me=>{A||F(Me)},children:v.jsxs(xc,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[v.jsxs(Ec,{children:[v.jsx(dl,{children:"开启 Voice Pilot?"}),v.jsx(dc,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),v.jsxs(Yu,{children:[v.jsx(St,{type:"button",variant:"outline",disabled:A,onClick:()=>F(!1),children:"取消"}),v.jsx(St,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:A,onClick:()=>{he()},children:A?"正在开启...":"开启 Voice Pilot"})]})]})}),z?v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:Ee,type:"file",accept:"image/*",className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:Me=>{Ye(Me)}}),v.jsx("input",{ref:ge,type:"file",accept:"application/*,text/*",className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:Me=>{Ye(Me)}})]}):null]})}function gu(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let h;n.key&&((l=n.debug)!=null&&l.call(n))&&(h=Date.now());const p=e();if(!(p.length!==r.length||p.some((b,w)=>r[w]!==b)))return i;r=p;let g;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(g=Date.now()),i=t(...p),n.key&&((d=n.debug)!=null&&d.call(n))){const b=Math.round((Date.now()-h)*100)/100,w=Math.round((Date.now()-g)*100)/100,x=w/16,E=(k,T)=>{for(k=String(k);k.length<T;)k=" "+k;return k};console.info(`%c⏱ ${E(w,5)} /${E(b,5)} ms`,`
638
638
  font-size: .6rem;
639
639
  font-weight: bold;
640
640
  color: hsl(${Math.max(0,Math.min(120-120*x,120))}deg 100% 31%);`,n==null?void 0:n.key)}return n!=null&&n.onChange&&!(s&&n.skipInitialOnChange)&&n.onChange(i),s=!1,i}return o.updateDeps=l=>{r=l},o}function eO(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Zge=(e,t)=>Math.abs(e-t)<1.01,Qge=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},tO=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Jge=e=>e,eve=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},tve=(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(tO(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(tO(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},nO={passive:!0},rO=typeof window>"u"?!0:"onscrollend"in window,nve=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&rO?()=>{}:Qge(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,nO);const d=e.options.useScrollendEvent&&rO;return d&&n.addEventListener("scrollend",u,nO),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},rve=(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"]},ive=(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 sve{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:Jge,rangeExtractor:eve,onChange:()=>{},measureElement:rve,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...n}},this.notify=n=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,n)},this.maybeNotify=gu(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,s)=>{this.scrollAdjustments=0,this.scrollDirection=s?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=s,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(n,r)=>{const i=new Map,s=new Map;for(let o=r-1;o>=0;o--){const l=n[o];if(i.has(l.lane))continue;const u=s.get(l.lane);if(u==null||l.end>u.end?s.set(l.lane,l):l.end<u.end&&i.set(l.lane,!0),i.size===this.options.lanes)break}return s.size===this.options.lanes?Array.from(s.values()).sort((o,l)=>o.end===l.end?o.index-l.index:o.end-l.end)[0]:void 0},this.getMeasurementOptions=gu(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(n,r,i,s,o,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:r,scrollMargin:i,getItemKey:s,enabled:o,lanes:l,laneAssignmentMode:u}),{key:!1}),this.getMeasurements=gu(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:r,scrollMargin:i,getItemKey:s,enabled:o,lanes:l,laneAssignmentMode:u},d)=>{if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const h=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1);const p=this.measurementsCache.slice(0,h),y=new Array(l).fill(void 0);for(let g=0;g<h;g++){const b=p[g];b&&(y[b.lane]=g)}for(let g=h;g<n;g++){const b=s(g),w=this.laneAssignments.get(g);let x,E;const k=u==="estimate"||d.has(b);if(w!==void 0&&this.options.lanes>1){x=w;const N=y[x],$=N!==void 0?p[N]:void 0;E=$?$.end+this.options.gap:r+i}else{const N=this.options.lanes===1?p[g-1]:this.getFurthestMeasurement(p,g);E=N?N.end+this.options.gap:r+i,x=N?N.lane:g%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(g,x)}const T=d.get(b),R=typeof T=="number"?T:this.options.estimateSize(g),z=E+R;p[g]={index:g,start:E,size:R,end:z,key:b,lane:x},y[x]=g}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=gu(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?ove({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 eO(r[T4(0,r.length-1,i=>eO(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&&Zge(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 T4=(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 ove({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=T4(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 iO=typeof document<"u"?_.useLayoutEffect:_.useEffect;function ave({useFlushSync:e=!0,...t}){const n=_.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?nd.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=_.useState(()=>new sve(r));return i.setOptions(r),iO(()=>i._didMount(),[]),iO(()=>i._willUpdate()),i}function lve(e){return ave({observeElementRect:tve,observeElementOffset:nve,scrollToFn:ive,...e})}function cve(e){return e.kind==="diff"}const uve=12e4;function sO(e){return e?e.replace(/\r\n?/gu,`