@dev-anywhere/relay 0.9.8 → 0.9.10

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jmuxer.min-DIchSTQ7.js","assets/__vite-browser-external-D7Ct-6yo.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jmuxer.min-DhPlAXXG.js","assets/__vite-browser-external-D7Ct-6yo.js"])))=>i.map(i=>d[i]);
2
2
  var nW=Object.defineProperty;var rW=(e,t,n)=>t in e?nW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var je=(e,t,n)=>rW(e,typeof t!="symbol"?t+"":t,n);function iW(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();function Gp(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function yLe(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}),n}var ax={exports:{}},hh={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -587,7 +587,7 @@ ${s}`,l=Wj(`${ZS(r.kind)}:${r.path}`,o,r.kind);n.push(l.kind==="diff"?{...l,co
587
587
 
588
588
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
589
589
 
590
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},joe="DialogDescriptionWarning",Foe=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${M5(joe).contentName}}.`;return b.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},KC=v5,$oe=b5,GC=w5,XC=x5,ZC=S5,P5=C5,I5=T5,gb=A5;function Hoe(e){const t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function Uoe(e){const[t,n]=b.useState(void 0);return Xi(()=>{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 Woe=["top","right","bottom","left"],Gl=Math.min,js=Math.max,ky=Math.round,ov=Math.floor,ta=e=>({x:e,y:e}),qoe={left:"right",right:"left",bottom:"top",top:"bottom"};function i1(e,t,n){return js(e,Gl(t,n))}function Ua(e,t){return typeof e=="function"?e(t):e}function Wa(e){return e.split("-")[0]}function uf(e){return e.split("-")[1]}function QC(e){return e==="x"?"y":"x"}function JC(e){return e==="y"?"height":"width"}function Qo(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function ek(e){return QC(Qo(e))}function Voe(e,t,n){n===void 0&&(n=!1);const r=uf(e),i=ek(e),s=JC(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Ty(o)),[o,Ty(o)]}function Yoe(e){const t=Ty(e);return[s1(e),t,s1(t)]}function s1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const P2=["left","right"],I2=["right","left"],Koe=["top","bottom"],Goe=["bottom","top"];function Xoe(e,t,n){switch(e){case"top":case"bottom":return n?t?I2:P2:t?P2:I2;case"left":case"right":return t?Koe:Goe;default:return[]}}function Zoe(e,t,n,r){const i=uf(e);let s=Xoe(Wa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(s1)))),s}function Ty(e){const t=Wa(e);return qoe[t]+e.slice(t.length)}function Qoe(e){return{top:0,right:0,bottom:0,left:0,...e}}function O5(e){return typeof e!="number"?Qoe(e):{top:e,right:e,bottom:e,left:e}}function Ry(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 O2(e,t,n){let{reference:r,floating:i}=e;const s=Qo(t),o=ek(t),l=JC(o),u=Wa(t),d=s==="y",f=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,v=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:f,y:r.y-i.height};break;case"bottom":g={x:f,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(uf(t)){case"start":g[o]-=v*(n&&d?-1:1);break;case"end":g[o]+=v*(n&&d?-1:1);break}return g}async function Joe(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:f="viewport",elementContext:p="floating",altBoundary:v=!1,padding:g=0}=Ua(t,e),_=O5(g),S=l[v?p==="floating"?"reference":"floating":p],x=Ry(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(S)))==null||n?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:f,strategy:u})),R=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),N=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},M=Ry(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:R,offsetParent:k,strategy:u}):R);return{top:(x.top-M.top+_.top)/N.y,bottom:(M.bottom-x.bottom+_.bottom)/N.y,left:(x.left-M.left+_.left)/N.x,right:(M.right-x.right+_.right)/N.x}}const eae=50,tae=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:Joe},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:f,y:p}=O2(d,r,u),v=r,g=0;const _={};for(let w=0;w<s.length;w++){const S=s[w];if(!S)continue;const{name:x,fn:R}=S,{x:k,y:N,data:M,reset:T}=await R({x:f,y:p,initialPlacement:r,placement:v,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=k??f,p=N??p,_[x]={..._[x],...M},T&&g<eae&&(g++,typeof T=="object"&&(T.placement&&(v=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:f,y:p}=O2(d,v,u)),w=-1)}return{x:f,y:p,placement:v,strategy:i,middlewareData:_}},nae=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:f=0}=Ua(e,t)||{};if(d==null)return{};const p=O5(f),v={x:n,y:r},g=ek(i),_=JC(g),w=await o.getDimensions(d),S=g==="y",x=S?"top":"left",R=S?"bottom":"right",k=S?"clientHeight":"clientWidth",N=s.reference[_]+s.reference[g]-v[g]-s.floating[_],M=v[g]-s.reference[g],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let P=T?T[k]:0;(!P||!await(o.isElement==null?void 0:o.isElement(T)))&&(P=l.floating[k]||s.floating[_]);const z=N/2-M/2,V=P/2-w[_]/2-1,U=Gl(p[x],V),G=Gl(p[R],V),O=U,A=P-w[_]-G,L=P/2-w[_]/2+z,D=i1(O,L,A),I=!u.arrow&&uf(i)!=null&&L!==D&&s.reference[_]/2-(L<O?U:G)-w[_]/2<0,B=I?L<O?L-O:L-A:0;return{[g]:v[g]+B,data:{[g]:D,centerOffset:L-D-B,...I&&{alignmentOffset:B}},reset:I}}}),rae=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:f=!0,crossAxis:p=!0,fallbackPlacements:v,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=Ua(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Wa(i),R=Qo(l),k=Wa(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),M=v||(k||!w?[Ty(l)]:Yoe(l)),T=_!=="none";!v&&T&&M.push(...Zoe(l,w,_,N));const P=[l,...M],z=await u.detectOverflow(t,S),V=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&V.push(z[x]),p){const L=Voe(i,o,N);V.push(z[L[0]],z[L[1]])}if(U=[...U,{placement:i,overflows:V}],!V.every(L=>L<=0)){var G,O;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,D=P[L];if(D&&(!(p==="alignment"?R!==Qo(D):!1)||U.every(F=>Qo(F.placement)===R?F.overflows[0]>0:!0)))return{data:{index:L,overflows:U},reset:{placement:D}};let I=(O=U.filter(B=>B.overflows[0]<=0).sort((B,F)=>B.overflows[1]-F.overflows[1])[0])==null?void 0:O.placement;if(!I)switch(g){case"bestFit":{var A;const B=(A=U.filter(F=>{if(T){const Y=Qo(F.placement);return Y===R||Y==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(Y=>Y>0).reduce((Y,j)=>Y+j,0)]).sort((F,Y)=>F[1]-Y[1])[0])==null?void 0:A[0];B&&(I=B);break}case"initialPlacement":I=l;break}if(i!==I)return{reset:{placement:I}}}return{}}}};function L2(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function D2(e){return Woe.some(t=>e[t]>=0)}const iae=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=Ua(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=L2(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:D2(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=L2(o,n.floating);return{data:{escapedOffsets:l,escaped:D2(l)}}}default:return{}}}}},L5=new Set(["left","top"]);async function sae(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Wa(n),l=uf(n),u=Qo(n)==="y",d=L5.has(o)?-1:1,f=s&&u?-1:1,p=Ua(t,e);let{mainAxis:v,crossAxis:g,alignmentAxis:_}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof _=="number"&&(g=l==="end"?_*-1:_),u?{x:g*f,y:v*d}:{x:v*d,y:g*f}}const oae=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 sae(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}}}}},aae=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:x=>{let{x:R,y:k}=x;return{x:R,y:k}}},...d}=Ua(e,t),f={x:n,y:r},p=await s.detectOverflow(t,d),v=Qo(Wa(i)),g=QC(v);let _=f[g],w=f[v];if(o){const x=g==="y"?"top":"left",R=g==="y"?"bottom":"right",k=_+p[x],N=_-p[R];_=i1(k,_,N)}if(l){const x=v==="y"?"top":"left",R=v==="y"?"bottom":"right",k=w+p[x],N=w-p[R];w=i1(k,w,N)}const S=u.fn({...t,[g]:_,[v]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[g]:o,[v]:l}}}}}},lae=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}=Ua(e,t),f={x:n,y:r},p=Qo(i),v=QC(p);let g=f[v],_=f[p];const w=Ua(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const k=v==="y"?"height":"width",N=s.reference[v]-s.floating[k]+S.mainAxis,M=s.reference[v]+s.reference[k]-S.mainAxis;g<N?g=N:g>M&&(g=M)}if(d){var x,R;const k=v==="y"?"width":"height",N=L5.has(Wa(i)),M=s.reference[p]-s.floating[k]+(N&&((x=o.offset)==null?void 0:x[p])||0)+(N?0:S.crossAxis),T=s.reference[p]+s.reference[k]+(N?0:((R=o.offset)==null?void 0:R[p])||0)-(N?S.crossAxis:0);_<M?_=M:_>T&&(_=T)}return{[v]:g,[p]:_}}}},cae=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}=Ua(e,t),f=await o.detectOverflow(t,d),p=Wa(i),v=uf(i),g=Qo(i)==="y",{width:_,height:w}=s.floating;let S,x;p==="top"||p==="bottom"?(S=p,x=v===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=p,S=v==="end"?"top":"bottom");const R=w-f.top-f.bottom,k=_-f.left-f.right,N=Gl(w-f[S],R),M=Gl(_-f[x],k),T=!t.middlewareData.shift;let P=N,z=M;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(z=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(P=R),T&&!v){const U=js(f.left,0),G=js(f.right,0),O=js(f.top,0),A=js(f.bottom,0);g?z=_-2*(U!==0||G!==0?U+G:js(f.left,f.right)):P=w-2*(O!==0||A!==0?O+A:js(f.top,f.bottom))}await u({...t,availableWidth:z,availableHeight:P});const V=await o.getDimensions(l.floating);return _!==V.width||w!==V.height?{reset:{rects:!0}}:{}}}};function vb(){return typeof window<"u"}function df(e){return D5(e)?(e.nodeName||"").toLowerCase():"#document"}function Hs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ca(e){var t;return(t=(D5(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function D5(e){return vb()?e instanceof Node||e instanceof Hs(e).Node:!1}function Ao(e){return vb()?e instanceof Element||e instanceof Hs(e).Element:!1}function Ka(e){return vb()?e instanceof HTMLElement||e instanceof Hs(e).HTMLElement:!1}function B2(e){return!vb()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Hs(e).ShadowRoot}function cm(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=No(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function uae(e){return/^(table|td|th)$/.test(df(e))}function yb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const dae=/transform|translate|scale|rotate|perspective|filter/,fae=/paint|layout|strict|content/,Pc=e=>!!e&&e!=="none";let r0;function tk(e){const t=Ao(e)?No(e):e;return Pc(t.transform)||Pc(t.translate)||Pc(t.scale)||Pc(t.rotate)||Pc(t.perspective)||!nk()&&(Pc(t.backdropFilter)||Pc(t.filter))||dae.test(t.willChange||"")||fae.test(t.contain||"")}function hae(e){let t=Xl(e);for(;Ka(t)&&!Xd(t);){if(tk(t))return t;if(yb(t))return null;t=Xl(t)}return null}function nk(){return r0==null&&(r0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),r0}function Xd(e){return/^(html|body|#document)$/.test(df(e))}function No(e){return Hs(e).getComputedStyle(e)}function bb(e){return Ao(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Xl(e){if(df(e)==="html")return e;const t=e.assignedSlot||e.parentNode||B2(e)&&e.host||ca(e);return B2(t)?t.host:t}function B5(e){const t=Xl(e);return Xd(t)?e.ownerDocument?e.ownerDocument.body:e.body:Ka(t)&&cm(t)?t:B5(t)}function Ip(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=B5(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Hs(i);if(s){const l=o1(o);return t.concat(o,o.visualViewport||[],cm(i)?i:[],l&&n?Ip(l):[])}else return t.concat(i,Ip(i,[],n))}function o1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function z5(e){const t=No(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ka(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=ky(n)!==s||ky(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function rk(e){return Ao(e)?e:e.contextElement}function Bd(e){const t=rk(e);if(!Ka(t))return ta(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=z5(t);let o=(s?ky(n.width):n.width)/r,l=(s?ky(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const pae=ta(0);function j5(e){const t=Hs(e);return!nk()||!t.visualViewport?pae:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function mae(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Hs(e)?!1:t}function nu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=rk(e);let o=ta(1);t&&(r?Ao(r)&&(o=Bd(r)):o=Bd(e));const l=mae(s,n,r)?j5(s):ta(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,f=i.width/o.x,p=i.height/o.y;if(s){const v=Hs(s),g=r&&Ao(r)?Hs(r):r;let _=v,w=o1(_);for(;w&&r&&g!==_;){const S=Bd(w),x=w.getBoundingClientRect(),R=No(w),k=x.left+(w.clientLeft+parseFloat(R.paddingLeft))*S.x,N=x.top+(w.clientTop+parseFloat(R.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,p*=S.y,u+=k,d+=N,_=Hs(w),w=o1(_)}}return Ry({width:f,height:p,x:u,y:d})}function _b(e,t){const n=bb(e).scrollLeft;return t?t.left+n:nu(ca(e)).left+n}function F5(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-_b(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function gae(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=ca(r),l=t?yb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=ta(1);const f=ta(0),p=Ka(r);if((p||!p&&!s)&&((df(r)!=="body"||cm(o))&&(u=bb(r)),p)){const g=nu(r);d=Bd(r),f.x=g.x+r.clientLeft,f.y=g.y+r.clientTop}const v=o&&!p&&!s?F5(o,u):ta(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+f.x+v.x,y:n.y*d.y-u.scrollTop*d.y+f.y+v.y}}function vae(e){return Array.from(e.getClientRects())}function yae(e){const t=ca(e),n=bb(e),r=e.ownerDocument.body,i=js(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=js(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+_b(e);const l=-n.scrollTop;return No(r).direction==="rtl"&&(o+=js(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const z2=25;function bae(e,t){const n=Hs(e),r=ca(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const f=nk();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=_b(r);if(d<=0){const f=r.ownerDocument,p=f.body,v=getComputedStyle(p),g=f.compatMode==="CSS1Compat"&&parseFloat(v.marginLeft)+parseFloat(v.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-g);_<=z2&&(s-=_)}else d<=z2&&(s+=d);return{width:s,height:o,x:l,y:u}}function _ae(e,t){const n=nu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Ka(e)?Bd(e):ta(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 j2(e,t,n){let r;if(t==="viewport")r=bae(e,n);else if(t==="document")r=yae(ca(e));else if(Ao(t))r=_ae(t,n);else{const i=j5(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ry(r)}function $5(e,t){const n=Xl(e);return n===t||!Ao(n)||Xd(n)?!1:No(n).position==="fixed"||$5(n,t)}function wae(e,t){const n=t.get(e);if(n)return n;let r=Ip(e,[],!1).filter(l=>Ao(l)&&df(l)!=="body"),i=null;const s=No(e).position==="fixed";let o=s?Xl(e):e;for(;Ao(o)&&!Xd(o);){const l=No(o),u=tk(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||cm(o)&&!u&&$5(e,o))?r=r.filter(f=>f!==o):i=l,o=Xl(o)}return t.set(e,r),r}function xae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?yb(t)?[]:wae(t,this._c):[].concat(n),r],l=j2(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,p=l.left;for(let v=1;v<o.length;v++){const g=j2(t,o[v],i);u=js(g.top,u),d=Gl(g.right,d),f=Gl(g.bottom,f),p=js(g.left,p)}return{width:d-p,height:f-u,x:p,y:u}}function Sae(e){const{width:t,height:n}=z5(e);return{width:t,height:n}}function Eae(e,t,n){const r=Ka(t),i=ca(t),s=n==="fixed",o=nu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=ta(0);function d(){u.x=_b(i)}if(r||!r&&!s)if((df(t)!=="body"||cm(i))&&(l=bb(t)),r){const g=nu(t,!0,s,t);u.x=g.x+t.clientLeft,u.y=g.y+t.clientTop}else i&&d();s&&!r&&i&&d();const f=i&&!r&&!s?F5(i,l):ta(0),p=o.left+l.scrollLeft-u.x-f.x,v=o.top+l.scrollTop-u.y-f.y;return{x:p,y:v,width:o.width,height:o.height}}function i0(e){return No(e).position==="static"}function F2(e,t){if(!Ka(e)||No(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ca(e)===n&&(n=n.ownerDocument.body),n}function H5(e,t){const n=Hs(e);if(yb(e))return n;if(!Ka(e)){let i=Xl(e);for(;i&&!Xd(i);){if(Ao(i)&&!i0(i))return i;i=Xl(i)}return n}let r=F2(e,t);for(;r&&uae(r)&&i0(r);)r=F2(r,t);return r&&Xd(r)&&i0(r)&&!tk(r)?n:r||hae(e)||n}const Cae=async function(e){const t=this.getOffsetParent||H5,n=this.getDimensions,r=await n(e.floating);return{reference:Eae(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function kae(e){return No(e).direction==="rtl"}const Tae={convertOffsetParentRelativeRectToViewportRelativeRect:gae,getDocumentElement:ca,getClippingRect:xae,getOffsetParent:H5,getElementRects:Cae,getClientRects:vae,getDimensions:Sae,getScale:Bd,isElement:Ao,isRTL:kae};function U5(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Rae(e,t){let n=null,r;const i=ca(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:f,top:p,width:v,height:g}=d;if(l||t(),!v||!g)return;const _=ov(p),w=ov(i.clientWidth-(f+v)),S=ov(i.clientHeight-(p+g)),x=ov(f),k={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:js(0,Gl(1,u))||1};let N=!0;function M(T){const P=T[0].intersectionRatio;if(P!==u){if(!N)return o();P?o(!1,P):r=setTimeout(()=>{o(!1,1e-7)},1e3)}P===1&&!U5(d,e.getBoundingClientRect())&&o(),N=!1}try{n=new IntersectionObserver(M,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(M,k)}n.observe(e)}return o(!0),s}function Aae(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=rk(e),f=i||s?[...d?Ip(d):[],...t?Ip(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const p=d&&l?Rae(d,n):null;let v=-1,g=null;o&&(g=new ResizeObserver(x=>{let[R]=x;R&&R.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(v),v=requestAnimationFrame(()=>{var k;(k=g)==null||k.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let _,w=u?nu(e):null;u&&S();function S(){const x=nu(e);w&&!U5(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(R=>{i&&R.removeEventListener("scroll",n),s&&R.removeEventListener("resize",n)}),p==null||p(),(x=g)==null||x.disconnect(),g=null,u&&cancelAnimationFrame(_)}}const Nae=oae,Mae=aae,Pae=rae,Iae=cae,Oae=iae,$2=nae,Lae=lae,Dae=(e,t,n)=>{const r=new Map,i={platform:Tae,...n},s={...i.platform,_c:r};return tae(e,t,{...i,platform:s})};var Bae=typeof document<"u",zae=function(){},Yv=Bae?b.useLayoutEffect:zae;function Ay(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(!Ay(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)&&!Ay(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function W5(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function H2(e,t){const n=W5(e);return Math.round(t*n)/n}function s0(e){const t=b.useRef(e);return Yv(()=>{t.current=e}),t}function jae(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,[f,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[v,g]=b.useState(r);Ay(v,r)||g(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),R=b.useCallback(F=>{F!==T.current&&(T.current=F,w(F))},[]),k=b.useCallback(F=>{F!==P.current&&(P.current=F,x(F))},[]),N=s||_,M=o||S,T=b.useRef(null),P=b.useRef(null),z=b.useRef(f),V=u!=null,U=s0(u),G=s0(i),O=s0(d),A=b.useCallback(()=>{if(!T.current||!P.current)return;const F={placement:t,strategy:n,middleware:v};G.current&&(F.platform=G.current),Dae(T.current,P.current,F).then(Y=>{const j={...Y,isPositioned:O.current!==!1};L.current&&!Ay(z.current,j)&&(z.current=j,mu.flushSync(()=>{p(j)}))})},[v,t,n,G,O]);Yv(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,p(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);Yv(()=>(L.current=!0,()=>{L.current=!1}),[]),Yv(()=>{if(N&&(T.current=N),M&&(P.current=M),N&&M){if(U.current)return U.current(N,M,A);A()}},[N,M,A,U,V]);const D=b.useMemo(()=>({reference:T,floating:P,setReference:R,setFloating:k}),[R,k]),I=b.useMemo(()=>({reference:N,floating:M}),[N,M]),B=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!I.floating)return F;const Y=H2(I.floating,f.x),j=H2(I.floating,f.y);return l?{...F,transform:"translate("+Y+"px, "+j+"px)",...W5(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Y,top:j}},[n,l,I.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:A,refs:D,elements:I,floatingStyles:B}),[f,A,D,I,B])}const Fae=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?$2({element:r.current,padding:i}).fn(n):{}:r?$2({element:r,padding:i}).fn(n):{}}}},$ae=(e,t)=>{const n=Nae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Hae=(e,t)=>{const n=Mae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uae=(e,t)=>({fn:Lae(e).fn,options:[e,t]}),Wae=(e,t)=>{const n=Pae(e);return{name:n.name,fn:n.fn,options:[e,t]}},qae=(e,t)=>{const n=Iae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Vae=(e,t)=>{const n=Oae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Yae=(e,t)=>{const n=Fae(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Kae="Arrow",q5=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(wn.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:m.jsx("polygon",{points:"0,0 30,0 15,10"})})});q5.displayName=Kae;var Gae=q5,ik="Popper",[V5,ic]=Ya(ik),[Xae,Y5]=V5(ik),K5=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(Xae,{scope:t,anchor:r,onAnchorChange:i,children:n})};K5.displayName=ik;var G5="PopperAnchor",X5=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=Y5(G5,n),o=b.useRef(null),l=sr(t,o),u=b.useRef(null);return b.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:m.jsx(wn.div,{...i,ref:l})});X5.displayName=G5;var sk="PopperContent",[Zae,Qae]=V5(sk),Z5=b.forwardRef((e,t)=>{var Q,ce,ie,le,be,Le;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:f=0,sticky:p="partial",hideWhenDetached:v=!1,updatePositionStrategy:g="optimized",onPlaced:_,...w}=e,S=Y5(sk,n),[x,R]=b.useState(null),k=sr(t,he=>R(he)),[N,M]=b.useState(null),T=Uoe(N),P=(T==null?void 0:T.width)??0,z=(T==null?void 0:T.height)??0,V=r+(s!=="center"?"-"+s:""),U=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},G=Array.isArray(d)?d:[d],O=G.length>0,A={padding:U,boundary:G.filter(ele),altBoundary:O},{refs:L,floatingStyles:D,placement:I,isPositioned:B,middlewareData:F}=jae({strategy:"fixed",placement:V,whileElementsMounted:(...he)=>Aae(...he,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[$ae({mainAxis:i+z,alignmentAxis:o}),u&&Hae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Uae():void 0,...A}),u&&Wae({...A}),qae({...A,apply:({elements:he,rects:He,availableWidth:Pt,availableHeight:Ge})=>{const{width:it,height:$e}=He.reference,We=he.floating.style;We.setProperty("--radix-popper-available-width",`${Pt}px`),We.setProperty("--radix-popper-available-height",`${Ge}px`),We.setProperty("--radix-popper-anchor-width",`${it}px`),We.setProperty("--radix-popper-anchor-height",`${$e}px`)}}),N&&Yae({element:N,padding:l}),tle({arrowWidth:P,arrowHeight:z}),v&&Vae({strategy:"referenceHidden",...A})]}),[Y,j]=e3(I),q=oa(_);Xi(()=>{B&&(q==null||q())},[B,q]);const K=(Q=F.arrow)==null?void 0:Q.x,$=(ce=F.arrow)==null?void 0:ce.y,ne=((ie=F.arrow)==null?void 0:ie.centerOffset)!==0,[J,te]=b.useState();return Xi(()=>{x&&te(window.getComputedStyle(x).zIndex)},[x]),m.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:B?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(le=F.transformOrigin)==null?void 0:le.x,(be=F.transformOrigin)==null?void 0:be.y].join(" "),...((Le=F.hide)==null?void 0:Le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(Zae,{scope:n,placedSide:Y,onArrowChange:M,arrowX:K,arrowY:$,shouldHideArrow:ne,children:m.jsx(wn.div,{"data-side":Y,"data-align":j,...w,ref:k,style:{...w.style,animation:B?void 0:"none"}})})})});Z5.displayName=sk;var Q5="PopperArrow",Jae={top:"bottom",right:"left",bottom:"top",left:"right"},J5=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Qae(Q5,r),o=Jae[s.placedSide];return m.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:m.jsx(Gae,{...i,ref:n,style:{...i.style,display:"block"}})})});J5.displayName=Q5;function ele(e){return e!==null}var tle=e=>({name:"transformOrigin",options:e,fn(t){var S,x,R;const{placement:n,rects:r,middlewareData:i}=t,o=((S=i.arrow)==null?void 0:S.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,f]=e3(n),p={start:"0%",center:"50%",end:"100%"}[f],v=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,g=(((R=i.arrow)==null?void 0:R.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?p:`${v}px`,w=`${-u}px`):d==="top"?(_=o?p:`${v}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?p:`${g}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?p:`${g}px`),{data:{x:_,y:w}}}});function e3(e){const[t,n="center"]=e.split("-");return[t,n]}var wb=K5,um=X5,xb=Z5,Sb=J5,o0="rovingFocusGroup.onEntryFocus",nle={bubbles:!1,cancelable:!0},dm="RovingFocusGroup",[a1,t3,rle]=UC(dm),[ile,n3]=Ya(dm,[rle]),[sle,ole]=ile(dm),r3=b.forwardRef((e,t)=>m.jsx(a1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(a1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(ale,{...e,ref:t})})}));r3.displayName=dm;var ale=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...p}=e,v=b.useRef(null),g=sr(t,v),_=WC(s),[w,S]=eu({prop:o,defaultProp:l??null,onChange:u,caller:dm}),[x,R]=b.useState(!1),k=oa(d),N=t3(n),M=b.useRef(!1),[T,P]=b.useState(0);return b.useEffect(()=>{const z=v.current;if(z)return z.addEventListener(o0,k),()=>z.removeEventListener(o0,k)},[k]),m.jsx(sle,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(z=>S(z),[S]),onItemShiftTab:b.useCallback(()=>R(!0),[]),onFocusableItemAdd:b.useCallback(()=>P(z=>z+1),[]),onFocusableItemRemove:b.useCallback(()=>P(z=>z-1),[]),children:m.jsx(wn.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:$t(e.onMouseDown,()=>{M.current=!0}),onFocus:$t(e.onFocus,z=>{const V=!M.current;if(z.target===z.currentTarget&&V&&!x){const U=new CustomEvent(o0,nle);if(z.currentTarget.dispatchEvent(U),!U.defaultPrevented){const G=N().filter(I=>I.focusable),O=G.find(I=>I.active),A=G.find(I=>I.id===w),D=[O,A,...G].filter(Boolean).map(I=>I.ref.current);o3(D,f)}}M.current=!1}),onBlur:$t(e.onBlur,()=>R(!1))})})}),i3="RovingFocusGroupItem",s3=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=ji(),d=s||u,f=ole(i3,n),p=f.currentTabStopId===d,v=t3(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(a1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(wn.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:$t(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:$t(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:$t(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=ule(S,f.orientation,f.dir);if(x!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let k=v().filter(N=>N.focusable).map(N=>N.ref.current);if(x==="last")k.reverse();else if(x==="prev"||x==="next"){x==="prev"&&k.reverse();const N=k.indexOf(S.currentTarget);k=f.loop?dle(k,N+1):k.slice(N+1)}setTimeout(()=>o3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});s3.displayName=i3;var lle={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function cle(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ule(e,t,n){const r=cle(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return lle[r]}function o3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function dle(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var fle=r3,hle=s3,l1=["Enter"," "],ple=["ArrowDown","PageUp","Home"],a3=["ArrowUp","PageDown","End"],mle=[...ple,...a3],gle={ltr:[...l1,"ArrowRight"],rtl:[...l1,"ArrowLeft"]},vle={ltr:["ArrowLeft"],rtl:["ArrowRight"]},fm="Menu",[Op,yle,ble]=UC(fm),[gu,l3]=Ya(fm,[ble,ic,n3]),Eb=ic(),c3=n3(),[_le,vu]=gu(fm),[wle,hm]=gu(fm),u3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Eb(t),[u,d]=b.useState(null),f=b.useRef(!1),p=oa(s),v=WC(i);return b.useEffect(()=>{const g=()=>{f.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>f.current=!1;return document.addEventListener("keydown",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),m.jsx(wb,{...l,children:m.jsx(_le,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:m.jsx(wle,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:f,dir:v,modal:o,children:r})})})};u3.displayName=fm;var xle="MenuAnchor",ok=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Eb(n);return m.jsx(um,{...i,...r,ref:t})});ok.displayName=xle;var ak="MenuPortal",[Sle,d3]=gu(ak,{forceMount:void 0}),f3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=vu(ak,t);return m.jsx(Sle,{scope:t,forceMount:n,children:m.jsx(yo,{present:n||s.open,children:m.jsx(cf,{asChild:!0,container:i,children:r})})})};f3.displayName=ak;var fo="MenuContent",[Ele,lk]=gu(fo),h3=b.forwardRef((e,t)=>{const n=d3(fo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=vu(fo,e.__scopeMenu),o=hm(fo,e.__scopeMenu);return m.jsx(Op.Provider,{scope:e.__scopeMenu,children:m.jsx(yo,{present:r||s.open,children:m.jsx(Op.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Cle,{...i,ref:t}):m.jsx(kle,{...i,ref:t})})})})}),Cle=b.forwardRef((e,t)=>{const n=vu(fo,e.__scopeMenu),r=b.useRef(null),i=sr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return pb(s)},[]),m.jsx(ck,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:$t(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),kle=b.forwardRef((e,t)=>{const n=vu(fo,e.__scopeMenu);return m.jsx(ck,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Tle=Kl("MenuContent.ScrollLock"),ck=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:v,onDismiss:g,disableOutsideScroll:_,...w}=e,S=vu(fo,n),x=hm(fo,n),R=Eb(n),k=c3(n),N=yle(n),[M,T]=b.useState(null),P=b.useRef(null),z=sr(t,P,S.onContentChange),V=b.useRef(0),U=b.useRef(""),G=b.useRef(0),O=b.useRef(null),A=b.useRef("right"),L=b.useRef(0),D=_?lm:b.Fragment,I=_?{as:Tle,allowPinchZoom:!0}:void 0,B=Y=>{var Q,ce;const j=U.current+Y,q=N().filter(ie=>!ie.disabled),K=document.activeElement,$=(Q=q.find(ie=>ie.ref.current===K))==null?void 0:Q.textValue,ne=q.map(ie=>ie.textValue),J=jle(ne,j,$),te=(ce=q.find(ie=>ie.textValue===J))==null?void 0:ce.ref.current;(function ie(le){U.current=le,window.clearTimeout(V.current),le!==""&&(V.current=window.setTimeout(()=>ie(""),1e3))})(j),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(V.current),[]),fb();const F=b.useCallback(Y=>{var q,K;return A.current===((q=O.current)==null?void 0:q.side)&&$le(Y,(K=O.current)==null?void 0:K.area)},[]);return m.jsx(Ele,{scope:n,searchRef:U,onItemEnter:b.useCallback(Y=>{F(Y)&&Y.preventDefault()},[F]),onItemLeave:b.useCallback(Y=>{var j;F(Y)||((j=P.current)==null||j.focus(),T(null))},[F]),onTriggerLeave:b.useCallback(Y=>{F(Y)&&Y.preventDefault()},[F]),pointerGraceTimerRef:G,onPointerGraceIntentChange:b.useCallback(Y=>{O.current=Y},[]),children:m.jsx(D,{...I,children:m.jsx(am,{asChild:!0,trapped:i,onMountAutoFocus:$t(s,Y=>{var j;Y.preventDefault(),(j=P.current)==null||j.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:v,onDismiss:g,children:m.jsx(fle,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:M,onCurrentTabStopIdChange:T,onEntryFocus:$t(u,Y=>{x.isUsingKeyboardRef.current||Y.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(xb,{role:"menu","aria-orientation":"vertical","data-state":A3(S.open),"data-radix-menu-content":"",dir:x.dir,...R,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:$t(w.onKeyDown,Y=>{const q=Y.target.closest("[data-radix-menu-content]")===Y.currentTarget,K=Y.ctrlKey||Y.altKey||Y.metaKey,$=Y.key.length===1;q&&(Y.key==="Tab"&&Y.preventDefault(),!K&&$&&B(Y.key));const ne=P.current;if(Y.target!==ne||!mle.includes(Y.key))return;Y.preventDefault();const te=N().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);a3.includes(Y.key)&&te.reverse(),Ble(te)}),onBlur:$t(e.onBlur,Y=>{Y.currentTarget.contains(Y.target)||(window.clearTimeout(V.current),U.current="")}),onPointerMove:$t(e.onPointerMove,Lp(Y=>{const j=Y.target,q=L.current!==Y.clientX;if(Y.currentTarget.contains(j)&&q){const K=Y.clientX>L.current?"right":"left";A.current=K,L.current=Y.clientX}}))})})})})})})});h3.displayName=fo;var Rle="MenuGroup",uk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(wn.div,{role:"group",...r,ref:t})});uk.displayName=Rle;var Ale="MenuLabel",p3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(wn.div,{...r,ref:t})});p3.displayName=Ale;var Ny="MenuItem",U2="menu.itemSelect",Cb=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=hm(Ny,e.__scopeMenu),l=lk(Ny,e.__scopeMenu),u=sr(t,s),d=b.useRef(!1),f=()=>{const p=s.current;if(!n&&p){const v=new CustomEvent(U2,{bubbles:!0,cancelable:!0});p.addEventListener(U2,g=>r==null?void 0:r(g),{once:!0}),t5(p,v),v.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(m3,{...i,ref:u,disabled:n,onClick:$t(e.onClick,f),onPointerDown:p=>{var v;(v=e.onPointerDown)==null||v.call(e,p),d.current=!0},onPointerUp:$t(e.onPointerUp,p=>{var v;d.current||(v=p.currentTarget)==null||v.click()}),onKeyDown:$t(e.onKeyDown,p=>{const v=l.searchRef.current!=="";n||v&&p.key===" "||l1.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Cb.displayName=Ny;var m3=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=lk(Ny,n),l=c3(n),u=b.useRef(null),d=sr(t,u),[f,p]=b.useState(!1),[v,g]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&g((_.textContent??"").trim())},[s.children]),m.jsx(Op.ItemSlot,{scope:n,disabled:r,textValue:i??v,children:m.jsx(hle,{asChild:!0,...l,focusable:!r,children:m.jsx(wn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:$t(e.onPointerMove,Lp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:$t(e.onPointerLeave,Lp(_=>o.onItemLeave(_))),onFocus:$t(e.onFocus,()=>p(!0)),onBlur:$t(e.onBlur,()=>p(!1))})})})}),Nle="MenuCheckboxItem",g3=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(w3,{scope:e.__scopeMenu,checked:n,children:m.jsx(Cb,{role:"menuitemcheckbox","aria-checked":My(n)?"mixed":n,...i,ref:t,"data-state":fk(n),onSelect:$t(i.onSelect,()=>r==null?void 0:r(My(n)?!0:!n),{checkForDefaultPrevented:!1})})})});g3.displayName=Nle;var v3="MenuRadioGroup",[Mle,Ple]=gu(v3,{value:void 0,onValueChange:()=>{}}),y3=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=oa(r);return m.jsx(Mle,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(uk,{...i,ref:t})})});y3.displayName=v3;var b3="MenuRadioItem",_3=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=Ple(b3,e.__scopeMenu),s=n===i.value;return m.jsx(w3,{scope:e.__scopeMenu,checked:s,children:m.jsx(Cb,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":fk(s),onSelect:$t(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});_3.displayName=b3;var dk="MenuItemIndicator",[w3,Ile]=gu(dk,{checked:!1}),x3=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=Ile(dk,n);return m.jsx(yo,{present:r||My(s.checked)||s.checked===!0,children:m.jsx(wn.span,{...i,ref:t,"data-state":fk(s.checked)})})});x3.displayName=dk;var Ole="MenuSeparator",S3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(wn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});S3.displayName=Ole;var Lle="MenuArrow",E3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Eb(n);return m.jsx(Sb,{...i,...r,ref:t})});E3.displayName=Lle;var Dle="MenuSub",[_Le,C3]=gu(Dle),Jh="MenuSubTrigger",k3=b.forwardRef((e,t)=>{const n=vu(Jh,e.__scopeMenu),r=hm(Jh,e.__scopeMenu),i=C3(Jh,e.__scopeMenu),s=lk(Jh,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},f=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>f,[f]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),m.jsx(ok,{asChild:!0,...d,children:m.jsx(m3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":A3(n.open),...e,ref:Ha(t,i.onTriggerChange),onClick:p=>{var v;(v=e.onClick)==null||v.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:$t(e.onPointerMove,Lp(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:$t(e.onPointerLeave,Lp(p=>{var g,_;f();const v=(g=n.content)==null?void 0:g.getBoundingClientRect();if(v){const w=(_=n.content)==null?void 0:_.dataset.side,S=w==="right",x=S?-5:5,R=v[S?"left":"right"],k=v[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+x,y:p.clientY},{x:R,y:v.top},{x:k,y:v.top},{x:k,y:v.bottom},{x:R,y:v.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:$t(e.onKeyDown,p=>{var g;const v=s.searchRef.current!=="";e.disabled||v&&p.key===" "||gle[r.dir].includes(p.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),p.preventDefault())})})})});k3.displayName=Jh;var T3="MenuSubContent",R3=b.forwardRef((e,t)=>{const n=d3(fo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=vu(fo,e.__scopeMenu),o=hm(fo,e.__scopeMenu),l=C3(T3,e.__scopeMenu),u=b.useRef(null),d=sr(t,u);return m.jsx(Op.Provider,{scope:e.__scopeMenu,children:m.jsx(yo,{present:r||s.open,children:m.jsx(Op.Slot,{scope:e.__scopeMenu,children:m.jsx(ck,{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:f=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:$t(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:$t(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:$t(e.onKeyDown,f=>{var g;const p=f.currentTarget.contains(f.target),v=vle[o.dir].includes(f.key);p&&v&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});R3.displayName=T3;function A3(e){return e?"open":"closed"}function My(e){return e==="indeterminate"}function fk(e){return My(e)?"indeterminate":e?"checked":"unchecked"}function Ble(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function zle(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function jle(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=zle(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 Fle(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,f=l.y,p=u.x,v=u.y;f>r!=v>r&&n<(p-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function $le(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Fle(n,t)}function Lp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Hle=u3,Ule=ok,Wle=f3,qle=h3,Vle=uk,Yle=p3,Kle=Cb,Gle=g3,Xle=y3,Zle=_3,Qle=x3,Jle=S3,ece=E3,tce=k3,nce=R3,kb="DropdownMenu",[rce]=Ya(kb,[l3]),us=l3(),[ice,N3]=rce(kb),M3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=us(t),d=b.useRef(null),[f,p]=eu({prop:i,defaultProp:s??!1,onChange:o,caller:kb});return m.jsx(ice,{scope:t,triggerId:ji(),triggerRef:d,contentId:ji(),open:f,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(v=>!v),[p]),modal:l,children:m.jsx(Hle,{...u,open:f,onOpenChange:p,dir:r,modal:l,children:n})})};M3.displayName=kb;var P3="DropdownMenuTrigger",I3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=N3(P3,n),o=us(n);return m.jsx(Ule,{asChild:!0,...o,children:m.jsx(wn.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:Ha(t,s.triggerRef),onPointerDown:$t(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:$t(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});I3.displayName=P3;var sce="DropdownMenuPortal",O3=e=>{const{__scopeDropdownMenu:t,...n}=e,r=us(t);return m.jsx(Wle,{...r,...n})};O3.displayName=sce;var L3="DropdownMenuContent",D3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=N3(L3,n),s=us(n),o=b.useRef(!1);return m.jsx(qle,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:$t(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:$t(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,f=u.button===2||d;(!i.modal||f)&&(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)"}})});D3.displayName=L3;var oce="DropdownMenuGroup",ace=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Vle,{...i,...r,ref:t})});ace.displayName=oce;var lce="DropdownMenuLabel",B3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Yle,{...i,...r,ref:t})});B3.displayName=lce;var cce="DropdownMenuItem",z3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Kle,{...i,...r,ref:t})});z3.displayName=cce;var uce="DropdownMenuCheckboxItem",j3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Gle,{...i,...r,ref:t})});j3.displayName=uce;var dce="DropdownMenuRadioGroup",fce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Xle,{...i,...r,ref:t})});fce.displayName=dce;var hce="DropdownMenuRadioItem",pce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Zle,{...i,...r,ref:t})});pce.displayName=hce;var mce="DropdownMenuItemIndicator",F3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Qle,{...i,...r,ref:t})});F3.displayName=mce;var gce="DropdownMenuSeparator",$3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Jle,{...i,...r,ref:t})});$3.displayName=gce;var vce="DropdownMenuArrow",yce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(ece,{...i,...r,ref:t})});yce.displayName=vce;var bce="DropdownMenuSubTrigger",_ce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(tce,{...i,...r,ref:t})});_ce.displayName=bce;var wce="DropdownMenuSubContent",xce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(nce,{...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)"}})});xce.displayName=wce;var Sce=M3,Ece=I3,Cce=O3,kce=D3,Tce=B3,Rce=z3,Ace=j3,Nce=F3,Mce=$3;function W2(e,[t,n]){return Math.min(n,Math.max(t,e))}var Tb="Popover",[H3]=Ya(Tb,[ic]),pm=ic(),[Pce,sc]=H3(Tb),U3=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=pm(t),u=b.useRef(null),[d,f]=b.useState(!1),[p,v]=eu({prop:r,defaultProp:i??!1,onChange:s,caller:Tb});return m.jsx(wb,{...l,children:m.jsx(Pce,{scope:t,contentId:ji(),triggerRef:u,open:p,onOpenChange:v,onOpenToggle:b.useCallback(()=>v(g=>!g),[v]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>f(!0),[]),onCustomAnchorRemove:b.useCallback(()=>f(!1),[]),modal:o,children:n})})};U3.displayName=Tb;var W3="PopoverAnchor",Ice=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=sc(W3,n),s=pm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(um,{...s,...r,ref:t})});Ice.displayName=W3;var q3="PopoverTrigger",V3=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=sc(q3,n),s=pm(n),o=sr(t,i.triggerRef),l=m.jsx(wn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Z3(i.open),...r,ref:o,onClick:$t(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(um,{asChild:!0,...s,children:l})});V3.displayName=q3;var hk="PopoverPortal",[Oce,Lce]=H3(hk,{forceMount:void 0}),Y3=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=sc(hk,t);return m.jsx(Oce,{scope:t,forceMount:n,children:m.jsx(yo,{present:n||s.open,children:m.jsx(cf,{asChild:!0,container:i,children:r})})})};Y3.displayName=hk;var Zd="PopoverContent",K3=b.forwardRef((e,t)=>{const n=Lce(Zd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=sc(Zd,e.__scopePopover);return m.jsx(yo,{present:r||s.open,children:s.modal?m.jsx(Bce,{...i,ref:t}):m.jsx(zce,{...i,ref:t})})});K3.displayName=Zd;var Dce=Kl("PopoverContent.RemoveScroll"),Bce=b.forwardRef((e,t)=>{const n=sc(Zd,e.__scopePopover),r=b.useRef(null),i=sr(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return pb(o)},[]),m.jsx(lm,{as:Dce,allowPinchZoom:!0,children:m.jsx(G3,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:$t(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:$t(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:$t(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),zce=b.forwardRef((e,t)=>{const n=sc(Zd,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(G3,{...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()}})}),G3=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,...p}=e,v=sc(Zd,n),g=pm(n);return fb(),m.jsx(am,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>v.onOpenChange(!1),children:m.jsx(xb,{"data-state":Z3(v.open),role:"dialog",id:v.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)"}})})})}),X3="PopoverClose",jce=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=sc(X3,n);return m.jsx(wn.button,{type:"button",...r,ref:t,onClick:$t(e.onClick,()=>i.onOpenChange(!1))})});jce.displayName=X3;var Fce="PopoverArrow",$ce=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pm(n);return m.jsx(Sb,{...i,...r,ref:t})});$ce.displayName=Fce;function Z3(e){return e?"open":"closed"}var Hce=U3,Uce=V3,Wce=Y3,qce=K3,Vce=[" ","Enter","ArrowUp","ArrowDown"],Yce=[" ","Enter"],ru="Select",[Rb,Ab,Kce]=UC(ru),[ff]=Ya(ru,[Kce,ic]),Nb=ic(),[Gce,oc]=ff(ru),[Xce,Zce]=ff(ru),Q3=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:f,autoComplete:p,disabled:v,required:g,form:_}=e,w=Nb(t),[S,x]=b.useState(null),[R,k]=b.useState(null),[N,M]=b.useState(!1),T=WC(d),[P,z]=eu({prop:r,defaultProp:i??!1,onChange:s,caller:ru}),[V,U]=eu({prop:o,defaultProp:l,onChange:u,caller:ru}),G=b.useRef(null),O=S?_||!!S.closest("form"):!0,[A,L]=b.useState(new Set),D=Array.from(A).map(I=>I.props.value).join(";");return m.jsx(wb,{...w,children:m.jsxs(Gce,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:R,onValueNodeChange:k,valueNodeHasChildren:N,onValueNodeHasChildrenChange:M,contentId:ji(),value:V,onValueChange:U,open:P,onOpenChange:z,dir:T,triggerPointerDownPosRef:G,disabled:v,children:[m.jsx(Rb.Provider,{scope:t,children:m.jsx(Xce,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(I=>{L(B=>new Set(B).add(I))},[]),onNativeOptionRemove:b.useCallback(I=>{L(B=>{const F=new Set(B);return F.delete(I),F})},[]),children:n})}),O?m.jsxs(_4,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:p,value:V,onChange:I=>U(I.target.value),disabled:v,form:_,children:[V===void 0?m.jsx("option",{value:""}):null,Array.from(A)]},D):null]})})};Q3.displayName=ru;var J3="SelectTrigger",e4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Nb(n),o=oc(J3,n),l=o.disabled||r,u=sr(t,o.onTriggerChange),d=Ab(n),f=b.useRef("touch"),[p,v,g]=x4(w=>{const S=d().filter(k=>!k.disabled),x=S.find(k=>k.value===o.value),R=S4(S,w,x);R!==void 0&&o.onValueChange(R.value)}),_=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(um,{asChild:!0,...s,children:m.jsx(wn.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":w4(o.value)?"":void 0,...i,ref:u,onClick:$t(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:$t(i.onPointerDown,w=>{f.current=w.pointerType;const S=w.target;S.hasPointerCapture(w.pointerId)&&S.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:$t(i.onKeyDown,w=>{const S=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&v(w.key),!(S&&w.key===" ")&&Vce.includes(w.key)&&(_(),w.preventDefault())})})})});e4.displayName=J3;var t4="SelectValue",n4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=oc(t4,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,p=sr(t,u.onValueNodeChange);return Xi(()=>{d(f)},[d,f]),m.jsx(wn.span,{...l,ref:p,style:{pointerEvents:"none"},children:w4(u.value)?m.jsx(m.Fragment,{children:o}):s})});n4.displayName=t4;var Qce="SelectIcon",r4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(wn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});r4.displayName=Qce;var Jce="SelectPortal",i4=e=>m.jsx(cf,{asChild:!0,...e});i4.displayName=Jce;var iu="SelectContent",s4=b.forwardRef((e,t)=>{const n=oc(iu,e.__scopeSelect),[r,i]=b.useState();if(Xi(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?mu.createPortal(m.jsx(o4,{scope:e.__scopeSelect,children:m.jsx(Rb.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(a4,{...e,ref:t})});s4.displayName=iu;var ko=10,[o4,ac]=ff(iu),eue="SelectContentImpl",tue=Kl("SelectContent.RemoveScroll"),a4=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,R=oc(iu,n),[k,N]=b.useState(null),[M,T]=b.useState(null),P=sr(t,Q=>N(Q)),[z,V]=b.useState(null),[U,G]=b.useState(null),O=Ab(n),[A,L]=b.useState(!1),D=b.useRef(!1);b.useEffect(()=>{if(k)return pb(k)},[k]),fb();const I=b.useCallback(Q=>{const[ce,...ie]=O().map(Le=>Le.ref.current),[le]=ie.slice(-1),be=document.activeElement;for(const Le of Q)if(Le===be||(Le==null||Le.scrollIntoView({block:"nearest"}),Le===ce&&M&&(M.scrollTop=0),Le===le&&M&&(M.scrollTop=M.scrollHeight),Le==null||Le.focus(),document.activeElement!==be))return},[O,M]),B=b.useCallback(()=>I([z,k]),[I,z,k]);b.useEffect(()=>{A&&B()},[A,B]);const{onOpenChange:F,triggerPointerDownPosRef:Y}=R;b.useEffect(()=>{if(k){let Q={x:0,y:0};const ce=le=>{var be,Le;Q={x:Math.abs(Math.round(le.pageX)-(((be=Y.current)==null?void 0:be.x)??0)),y:Math.abs(Math.round(le.pageY)-(((Le=Y.current)==null?void 0:Le.y)??0))}},ie=le=>{Q.x<=10&&Q.y<=10?le.preventDefault():k.contains(le.target)||F(!1),document.removeEventListener("pointermove",ce),Y.current=null};return Y.current!==null&&(document.addEventListener("pointermove",ce),document.addEventListener("pointerup",ie,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ce),document.removeEventListener("pointerup",ie,{capture:!0})}}},[k,F,Y]),b.useEffect(()=>{const Q=()=>F(!1);return window.addEventListener("blur",Q),window.addEventListener("resize",Q),()=>{window.removeEventListener("blur",Q),window.removeEventListener("resize",Q)}},[F]);const[j,q]=x4(Q=>{const ce=O().filter(be=>!be.disabled),ie=ce.find(be=>be.ref.current===document.activeElement),le=S4(ce,Q,ie);le&&setTimeout(()=>le.ref.current.focus())}),K=b.useCallback((Q,ce,ie)=>{const le=!D.current&&!ie;(R.value!==void 0&&R.value===ce||le)&&(V(Q),le&&(D.current=!0))},[R.value]),$=b.useCallback(()=>k==null?void 0:k.focus(),[k]),ne=b.useCallback((Q,ce,ie)=>{const le=!D.current&&!ie;(R.value!==void 0&&R.value===ce||le)&&G(Q)},[R.value]),J=r==="popper"?c1:l4,te=J===c1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(o4,{scope:n,content:k,viewport:M,onViewportChange:T,itemRefCallback:K,selectedItem:z,onItemLeave:$,itemTextRefCallback:ne,focusSelectedItem:B,selectedItemText:U,position:r,isPositioned:A,searchRef:j,children:m.jsx(lm,{as:tue,allowPinchZoom:!0,children:m.jsx(am,{asChild:!0,trapped:R.open,onMountAutoFocus:Q=>{Q.preventDefault()},onUnmountAutoFocus:$t(i,Q=>{var ce;(ce=R.trigger)==null||ce.focus({preventScroll:!0}),Q.preventDefault()}),children:m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:Q=>Q.preventDefault(),onDismiss:()=>R.onOpenChange(!1),children:m.jsx(J,{role:"listbox",id:R.contentId,"data-state":R.open?"open":"closed",dir:R.dir,onContextMenu:Q=>Q.preventDefault(),...x,...te,onPlaced:()=>L(!0),ref:P,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:$t(x.onKeyDown,Q=>{const ce=Q.ctrlKey||Q.altKey||Q.metaKey;if(Q.key==="Tab"&&Q.preventDefault(),!ce&&Q.key.length===1&&q(Q.key),["ArrowUp","ArrowDown","Home","End"].includes(Q.key)){let le=O().filter(be=>!be.disabled).map(be=>be.ref.current);if(["ArrowUp","End"].includes(Q.key)&&(le=le.slice().reverse()),["ArrowUp","ArrowDown"].includes(Q.key)){const be=Q.target,Le=le.indexOf(be);le=le.slice(Le+1)}setTimeout(()=>I(le)),Q.preventDefault()}})})})})})})});a4.displayName=eue;var nue="SelectItemAlignedPosition",l4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=oc(iu,n),o=ac(iu,n),[l,u]=b.useState(null),[d,f]=b.useState(null),p=sr(t,P=>f(P)),v=Ab(n),g=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:R}=o,k=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const P=s.trigger.getBoundingClientRect(),z=d.getBoundingClientRect(),V=s.valueNode.getBoundingClientRect(),U=x.getBoundingClientRect();if(s.dir!=="rtl"){const be=U.left-z.left,Le=V.left-be,he=P.left-Le,He=P.width+he,Pt=Math.max(He,z.width),Ge=window.innerWidth-ko,it=W2(Le,[ko,Math.max(ko,Ge-Pt)]);l.style.minWidth=He+"px",l.style.left=it+"px"}else{const be=z.right-U.right,Le=window.innerWidth-V.right-be,he=window.innerWidth-P.right-Le,He=P.width+he,Pt=Math.max(He,z.width),Ge=window.innerWidth-ko,it=W2(Le,[ko,Math.max(ko,Ge-Pt)]);l.style.minWidth=He+"px",l.style.right=it+"px"}const G=v(),O=window.innerHeight-ko*2,A=w.scrollHeight,L=window.getComputedStyle(d),D=parseInt(L.borderTopWidth,10),I=parseInt(L.paddingTop,10),B=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),Y=D+I+A+F+B,j=Math.min(S.offsetHeight*5,Y),q=window.getComputedStyle(w),K=parseInt(q.paddingTop,10),$=parseInt(q.paddingBottom,10),ne=P.top+P.height/2-ko,J=O-ne,te=S.offsetHeight/2,Q=S.offsetTop+te,ce=D+I+Q,ie=Y-ce;if(ce<=ne){const be=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const Le=d.clientHeight-w.offsetTop-w.offsetHeight,he=Math.max(J,te+(be?$:0)+Le+B),He=ce+he;l.style.height=He+"px"}else{const be=G.length>0&&S===G[0].ref.current;l.style.top="0px";const he=Math.max(ne,D+w.offsetTop+(be?K:0)+te)+ie;l.style.height=he+"px",w.scrollTop=ce-ne+w.offsetTop}l.style.margin=`${ko}px 0`,l.style.minHeight=j+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[v,s.trigger,s.valueNode,l,d,w,S,x,s.dir,r]);Xi(()=>k(),[k]);const[N,M]=b.useState();Xi(()=>{d&&M(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(P=>{P&&_.current===!0&&(k(),R==null||R(),_.current=!1)},[k,R]);return m.jsx(iue,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:m.jsx(wn.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});l4.displayName=nue;var rue="SelectPopperPosition",c1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=ko,...s}=e,o=Nb(n);return m.jsx(xb,{...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)"}})});c1.displayName=rue;var[iue,pk]=ff(iu,{}),u1="SelectViewport",c4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=ac(u1,n),o=pk(u1,n),l=sr(t,s.onViewportChange),u=b.useRef(0);return m.jsxs(m.Fragment,{children:[m.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}),m.jsx(Rb.Slot,{scope:n,children:m.jsx(wn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:$t(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:v}=o;if(v!=null&&v.current&&p){const g=Math.abs(u.current-f.scrollTop);if(g>0){const _=window.innerHeight-ko*2,w=parseFloat(p.style.minHeight),S=parseFloat(p.style.height),x=Math.max(w,S);if(x<_){const R=x+g,k=Math.min(_,R),N=R-k;p.style.height=k+"px",p.style.bottom==="0px"&&(f.scrollTop=N>0?N:0,p.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});c4.displayName=u1;var u4="SelectGroup",[sue,oue]=ff(u4),aue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=ji();return m.jsx(sue,{scope:n,id:i,children:m.jsx(wn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});aue.displayName=u4;var d4="SelectLabel",lue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=oue(d4,n);return m.jsx(wn.div,{id:i.id,...r,ref:t})});lue.displayName=d4;var Py="SelectItem",[cue,f4]=ff(Py),h4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=oc(Py,n),u=ac(Py,n),d=l.value===r,[f,p]=b.useState(s??""),[v,g]=b.useState(!1),_=sr(t,R=>{var k;return(k=u.itemRefCallback)==null?void 0:k.call(u,R,r,i)}),w=ji(),S=b.useRef("touch"),x=()=>{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 m.jsx(cue,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(R=>{p(k=>k||((R==null?void 0:R.textContent)??"").trim())},[]),children:m.jsx(Rb.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(wn.div,{role:"option","aria-labelledby":w,"data-highlighted":v?"":void 0,"aria-selected":d&&v,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:$t(o.onFocus,()=>g(!0)),onBlur:$t(o.onBlur,()=>g(!1)),onClick:$t(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:$t(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:$t(o.onPointerDown,R=>{S.current=R.pointerType}),onPointerMove:$t(o.onPointerMove,R=>{var k;S.current=R.pointerType,i?(k=u.onItemLeave)==null||k.call(u):S.current==="mouse"&&R.currentTarget.focus({preventScroll:!0})}),onPointerLeave:$t(o.onPointerLeave,R=>{var k;R.currentTarget===document.activeElement&&((k=u.onItemLeave)==null||k.call(u))}),onKeyDown:$t(o.onKeyDown,R=>{var N;((N=u.searchRef)==null?void 0:N.current)!==""&&R.key===" "||(Yce.includes(R.key)&&x(),R.key===" "&&R.preventDefault())})})})})});h4.displayName=Py;var ep="SelectItemText",p4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=oc(ep,n),l=ac(ep,n),u=f4(ep,n),d=Zce(ep,n),[f,p]=b.useState(null),v=sr(t,x=>p(x),u.onItemTextChange,x=>{var R;return(R=l.itemTextRefCallback)==null?void 0:R.call(l,x,u.value,u.disabled)}),g=f==null?void 0:f.textContent,_=b.useMemo(()=>m.jsx("option",{value:u.value,disabled:u.disabled,children:g},u.value),[u.disabled,u.value,g]),{onNativeOptionAdd:w,onNativeOptionRemove:S}=d;return Xi(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(wn.span,{id:u.textId,...s,ref:v}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?mu.createPortal(s.children,o.valueNode):null]})});p4.displayName=ep;var m4="SelectItemIndicator",g4=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return f4(m4,n).isSelected?m.jsx(wn.span,{"aria-hidden":!0,...r,ref:t}):null});g4.displayName=m4;var d1="SelectScrollUpButton",v4=b.forwardRef((e,t)=>{const n=ac(d1,e.__scopeSelect),r=pk(d1,e.__scopeSelect),[i,s]=b.useState(!1),o=sr(t,r.onScrollButtonChange);return Xi(()=>{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?m.jsx(b4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});v4.displayName=d1;var f1="SelectScrollDownButton",y4=b.forwardRef((e,t)=>{const n=ac(f1,e.__scopeSelect),r=pk(f1,e.__scopeSelect),[i,s]=b.useState(!1),o=sr(t,r.onScrollButtonChange);return Xi(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,f=Math.ceil(u.scrollTop)<d;s(f)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?m.jsx(b4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});y4.displayName=f1;var b4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=ac("SelectScrollButton",n),o=b.useRef(null),l=Ab(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Xi(()=>{var f;const d=l().find(p=>p.ref.current===document.activeElement);(f=d==null?void 0:d.ref.current)==null||f.scrollIntoView({block:"nearest"})},[l]),m.jsx(wn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:$t(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:$t(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:$t(i.onPointerLeave,()=>{u()})})}),uue="SelectSeparator",due=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(wn.div,{"aria-hidden":!0,...r,ref:t})});due.displayName=uue;var h1="SelectArrow",fue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Nb(n),s=oc(h1,n),o=ac(h1,n);return s.open&&o.position==="popper"?m.jsx(Sb,{...i,...r,ref:t}):null});fue.displayName=h1;var hue="SelectBubbleInput",_4=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=sr(r,i),o=Hoe(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&f){const p=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(p)}},[o,t]),m.jsx(wn.select,{...n,style:{...n5,...n.style},ref:s,defaultValue:t})});_4.displayName=hue;function w4(e){return e===""||e===void 0}function x4(e){const t=oa(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function S4(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=pue(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 pue(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var mue=Q3,gue=e4,vue=n4,yue=r4,bue=i4,_ue=s4,wue=c4,xue=h4,Sue=p4,Eue=g4,Cue=v4,kue=y4,[Mb]=Ya("Tooltip",[ic]),Pb=ic(),E4="TooltipProvider",Tue=700,p1="tooltip.open",[Rue,mk]=Mb(E4),C4=e=>{const{__scopeTooltip:t,delayDuration:n=Tue,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=b.useRef(!0),l=b.useRef(!1),u=b.useRef(0);return b.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),m.jsx(Rue,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:b.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};C4.displayName=E4;var Dp="Tooltip",[Aue,mm]=Mb(Dp),k4=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=mk(Dp,e.__scopeTooltip),d=Pb(t),[f,p]=b.useState(null),v=ji(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,R]=eu({prop:r,defaultProp:i??!1,onChange:P=>{P?(u.onOpen(),document.dispatchEvent(new CustomEvent(p1))):u.onClose(),s==null||s(P)},caller:Dp}),k=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),N=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,S.current=!1,R(!0)},[R]),M=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,R(!1)},[R]),T=b.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{S.current=!0,R(!0),g.current=0},w)},[w,R]);return b.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),m.jsx(wb,{...d,children:m.jsx(Aue,{scope:t,contentId:v,open:x,stateAttribute:k,trigger:f,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():N()},[u.isOpenDelayedRef,T,N]),onTriggerLeave:b.useCallback(()=>{_?M():(window.clearTimeout(g.current),g.current=0)},[M,_]),onOpen:N,onClose:M,disableHoverableContent:_,children:n})})};k4.displayName=Dp;var m1="TooltipTrigger",T4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=mm(m1,n),s=mk(m1,n),o=Pb(n),l=b.useRef(null),u=sr(t,l,i.onTriggerChange),d=b.useRef(!1),f=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),m.jsx(um,{asChild:!0,...o,children:m.jsx(wn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:$t(e.onPointerMove,v=>{v.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:$t(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:$t(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:$t(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:$t(e.onBlur,i.onClose),onClick:$t(e.onClick,i.onClose)})})});T4.displayName=m1;var gk="TooltipPortal",[Nue,Mue]=Mb(gk,{forceMount:void 0}),R4=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=mm(gk,t);return m.jsx(Nue,{scope:t,forceMount:n,children:m.jsx(yo,{present:n||s.open,children:m.jsx(cf,{asChild:!0,container:i,children:r})})})};R4.displayName=gk;var Qd="TooltipContent",A4=b.forwardRef((e,t)=>{const n=Mue(Qd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=mm(Qd,e.__scopeTooltip);return m.jsx(yo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(N4,{side:i,...s,ref:t}):m.jsx(Pue,{side:i,...s,ref:t})})}),Pue=b.forwardRef((e,t)=>{const n=mm(Qd,e.__scopeTooltip),r=mk(Qd,e.__scopeTooltip),i=b.useRef(null),s=sr(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:p}=r,v=b.useCallback(()=>{l(null),p(!1)},[p]),g=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},R=Due(x,S.getBoundingClientRect()),k=Bue(x,R),N=zue(w.getBoundingClientRect()),M=Fue([...k,...N]);l(M),p(!0)},[p]);return b.useEffect(()=>()=>v(),[v]),b.useEffect(()=>{if(u&&f){const _=S=>g(S,f),w=S=>g(S,u);return u.addEventListener("pointerleave",_),f.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),f.removeEventListener("pointerleave",w)}}},[u,f,g,v]),b.useEffect(()=>{if(o){const _=w=>{const S=w.target,x={x:w.clientX,y:w.clientY},R=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),k=!jue(x,o);R?v():k&&(v(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,v]),m.jsx(N4,{...e,ref:s})}),[Iue,Oue]=Mb(Dp,{isInside:!1}),Lue=pse("TooltipContent"),N4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=mm(Qd,n),d=Pb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(p1,f),()=>document.removeEventListener(p1,f)),[f]),b.useEffect(()=>{if(u.trigger){const p=v=>{const g=v.target;g!=null&&g.contains(u.trigger)&&f()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,f]),m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:f,children:m.jsxs(xb,{"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:[m.jsx(Lue,{children:r}),m.jsx(Iue,{scope:n,isInside:!0,children:m.jsx(i5,{id:u.contentId,role:"tooltip",children:i||r})})]})})});A4.displayName=Qd;var M4="TooltipArrow",P4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Pb(n);return Oue(M4,n).isInside?null:m.jsx(Sb,{...i,...r,ref:t})});P4.displayName=M4;function Due(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 Bue(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 zue(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 jue(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,f=l.y,p=u.x,v=u.y;f>r!=v>r&&n<(p-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function Fue(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),$ue(t)}function $ue(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 Hue=C4,Uue=k4,Wue=T4,que=R4,Vue=A4,Yue=P4;const I4=b.createContext(!1);function Kue({blocked:e,children:t}){return m.jsx(I4.Provider,{value:e,children:t})}function gm(){return b.useContext(I4)}function Ib({...e}){return m.jsx(Hce,{"data-slot":"popover",...e})}function Ob({...e}){return m.jsx(Uce,{"data-slot":"popover-trigger",...e})}function Lb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=gm();return m.jsx(Wce,{children:m.jsx(qce,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:o||r?!0:void 0,"aria-disabled":o?!0:i,"data-relay-interaction-blocked":o?"true":void 0,...s})})}const q2=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,V2=pz,Gue=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return V2(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 f=n==null?void 0:n[d],p=s==null?void 0:s[d];if(f===null)return null;const v=q2(f)||q2(p);return i[d][v]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,v]=f;return v===void 0||(d[p]=v),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:p,className:v,...g}=f;return Object.entries(g).every(_=>{let[w,S]=_;return Array.isArray(S)?S.includes({...s,...l}[w]):{...s,...l}[w]===S})?[...d,p,v]:d},[]);return V2(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Xue=Gue("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 pt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?fse:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(Xue({variant:t,size:n,className:e})),...i})}function hf({...e}){return m.jsx(Sce,{"data-slot":"dropdown-menu",...e})}function pf({...e}){return m.jsx(Ece,{"data-slot":"dropdown-menu-trigger",...e})}function mf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=gm();return m.jsx(Cce,{children:m.jsx(kce,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:s||n?!0:void 0,"aria-disabled":s?!0:r,"data-relay-interaction-blocked":s?"true":void 0,...i})})}function Lr({className:e,inset:t,variant:n="default",...r}){return m.jsx(Rce,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function a0({className:e,children:t,checked:n,...r}){return m.jsxs(Ace,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(Nce,{children:m.jsx(ia,{className:"size-4"})})}),t]})}function av({className:e,inset:t,...n}){return m.jsx(Tce,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function zd({className:e,...t}){return m.jsx(Mce,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}const Zue={"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 Yc({variant:e,action:t}){const{heading:n,body:r}=Zue[e];return e==="no-messages"?m.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:m.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):m.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:[m.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&m.jsx("div",{children:t})]})}const Que={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Jue={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function g1({status:e,className:t}){return m.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",Que[e],t),role:"status","aria-label":Jue[e]})}function gp({name:e,osName:t,className:n,nameClassName:r}){return m.jsxs("span",{className:Ye("min-w-0 flex-1",n),children:[m.jsx("span",{"data-slot":"proxy-name",className:Ye("block truncate text-sm font-normal leading-5",r),children:e}),t&&m.jsx("span",{"data-slot":"proxy-os",className:"block truncate text-xs font-normal leading-4 text-muted-foreground",children:t})]})}function Zi({...e}){return m.jsx(KC,{"data-slot":"dialog",...e})}function ede({...e}){return m.jsx(GC,{"data-slot":"dialog-portal",...e})}function tde({...e}){return m.jsx(gb,{"data-slot":"dialog-close",...e})}function nde({className:e,...t}){return m.jsx(XC,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Qi({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=gm();return m.jsxs(ede,{"data-slot":"dialog-portal",children:[m.jsx(nde,{}),m.jsxs(ZC,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:d=>{i==null||i(d),!(!r||d.defaultPrevented)&&(d.preventDefault(),d.currentTarget.focus({preventScroll:!0}))},inert:u||s?!0:void 0,"aria-disabled":u?!0:o,"data-relay-interaction-blocked":u?"true":void 0,...l,children:[t,n&&m.jsxs(gb,{"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:[m.jsx(fu,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ji({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Ws({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(gb,{asChild:!0,children:m.jsx(pt,{variant:"outline",children:"Close"})})]})}function Fi({className:e,...t}){return m.jsx(P5,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function Ss({className:e,...t}){return m.jsx(I5,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function rde(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function ide({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(Zi,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Qi,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"移除离线开发机?"}),m.jsx(Ss,{children:rde(t)})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(pt,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const Kv=80,sde=8,ode=1.2;function Y2(e){return Math.max(0,Math.min(Kv,e))}function ade({proxyId:e,name:t,osName:n,selected:r,revealed:i,disabled:s=!1,onRevealedChange:o,onRemove:l}){const u=t??e,d=b.useRef(null),f=b.useRef(!1),[p,v]=b.useState(null),g=p??(i?Kv:0),_=p!==null;function w(k){var N,M;if(!(s||k.pointerType!=="touch"&&k.pointerType!=="pen")&&!k.target.closest("button")){d.current={pointerId:k.pointerId,startX:k.clientX,startY:k.clientY,startOffset:i?Kv:0,axis:"pending"};try{(M=(N=k.currentTarget).setPointerCapture)==null||M.call(N,k.pointerId)}catch{}}}function S(k){const N=d.current;if(!N||N.pointerId!==k.pointerId)return;const M=k.clientX-N.startX,T=k.clientY-N.startY;if(N.axis==="pending"){if(Math.hypot(M,T)<sde)return;N.axis=Math.abs(M)>Math.abs(T)*ode?"horizontal":"vertical"}N.axis!=="vertical"&&(k.preventDefault(),v(Y2(N.startOffset-M)))}function x(k,N=!1){var P,z;const M=d.current;if(!M||M.pointerId!==k.pointerId)return;d.current=null;try{(z=(P=k.currentTarget).releasePointerCapture)==null||z.call(P,k.pointerId)}catch{}if(M.axis!=="horizontal"||N){v(null);return}k.preventDefault();const T=p??Y2(M.startOffset-(k.clientX-M.startX));v(null),o(T>=Kv/2),f.current=!0,window.setTimeout(()=>{f.current=!1},0)}function R(k){if(f.current){f.current=!1,k.preventDefault();return}i&&o(!1)}return m.jsxs("li",{className:`relative ${n?"h-14":"h-11"} overflow-hidden rounded-md border border-border bg-card`,"data-slot":"proxy-item","data-swipeable":"true","data-proxy-id":e,"data-online":"false","data-revealed":i||void 0,children:[m.jsxs("div",{className:"relative z-10 flex h-full w-full touch-pan-y select-none items-center gap-3 bg-card px-3 text-left text-muted-foreground transition-transform duration-200 ease-out motion-reduce:transition-none",style:{transform:`translateX(-${g}px)`,transitionDuration:_?"0ms":void 0},title:"这台开发机离线。向左滑动可移除。","data-slot":"proxy-swipe-foreground","data-offset":g,onPointerDown:w,onPointerMove:S,onPointerUp:k=>x(k),onPointerCancel:k=>x(k,!0),onClick:R,children:[m.jsx(g1,{status:"offline"}),m.jsx(gp,{name:u,osName:n}),r&&m.jsx(ia,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}),m.jsx("span",{className:"shrink-0 text-xs",children:"离线"})]}),m.jsx("button",{type:"button",className:`absolute inset-y-0 right-0 z-0 flex w-20 items-center justify-center bg-destructive text-sm font-medium text-white outline-none transition-colors hover:bg-destructive/90 focus-visible:z-20 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50 ${i?"":"pointer-events-none"}`,tabIndex:i?0:-1,disabled:s,"aria-label":`移除 ${u}`,"aria-hidden":i?void 0:!0,"data-slot":"proxy-mobile-remove",onClick:l,children:"移除"})]})}function O4({layout:e,variant:t="default"}){const n=Te(P=>P.proxies),r=Te(P=>P.proxyListLoaded),i=Te(P=>P.relayClientAuthIssue),s=Te(P=>P.selectedProxyId),o=Te(P=>P.proxySwitchTarget),l=cs(),u=Es(),[d,f]=b.useState(!1),[p,v]=b.useState(null),[g,_]=b.useState(null),[w,S]=b.useState(null);async function x(P,z){if(o)return;const V=Ft;if(!V){qe.error("请先连接开发机");return}const U=z??P,G=s!==null&&s!==P;Te.getState().setProxySwitchTarget({proxyId:P,name:U});try{const O=await V.selectProxy(P);if(!O.success){qe.error(`无法连接 ${U}:${O.error??"未知错误"}`);return}const A=V.getPreviewScope();if(!A||A.proxyId!==P||A.bindingId!==O.bindingId)throw Rt.dispose(),V.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Rt.activate(V,A),Rt.syncWebSnapshot(A).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] web preview snapshot failed",L)}),Rt.syncDeviceSnapshot(A).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] device preview snapshot failed",L)}),G&&(Gt.getState().prepareForProxySwitch(U),Vr.getState().prepareForProxySwitch()),Tr("local",Sn.proxyId,P),Te.getState().setProxy(P,z??null),Te.getState().setProxyOnline(!0),Te.getState().transitionToPhase("session_browsing"),V.sendControl({type:"session_list_request"}),V.requestProxyInfo().then(L=>{if(Te.getState().selectedProxyId!==P||!Rt.isActive(V,A))return;const D=Vr.getState();D.setHomePath(L.homePath),D.setAgentCli(L.agentCli),Te.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Rt.isActive(V,A)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),V.requestAgentStatuses().then(L=>{if(Te.getState().selectedProxyId!==P||!Rt.isActive(V,A))return;const D=Gt.getState();for(const I of L)D.setAgentStatus(I.sessionId,I.payload)}).catch(L=>{Rt.isActive(V,A)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),LC(V).then(L=>{L.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",L.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/")||l.pathname.startsWith("/preview/device/"))&&u("/sessions")}catch(O){const A=O instanceof Error?O.message:"未知错误";qe.error(`无法连接 ${U}:${A}`)}finally{Te.getState().setProxySwitchTarget(null)}}function R(P){P.online||w||(v(null),_({proxyId:P.proxyId,...P.name?{name:P.name}:{}}))}async function k(){const P=g;if(!P||w)return;const z=Ft;if(!z){qe.error("Relay 连接不可用,请稍后重试");return}const V=Te.getState().proxies.find(U=>U.proxyId===P.proxyId);if(!V){if(!Te.getState().proxyListLoaded){qe.info("正在重新连接 Relay,请稍后再试");return}mp(P.proxyId,z)&&u("/"),qe.info("这台开发机已经不在列表中"),_(null);return}if(V.online){qe.warning("这台开发机已重新上线,未移除"),_(null);return}S(P.proxyId),tie(P.proxyId);try{const U=await z.removeOfflineProxy(P.proxyId);if(U.success){Rd(P.proxyId),mp(P.proxyId,z)&&u("/"),qe.success(`已移除 ${P.name??P.proxyId}`),_(null);return}if(U.errorCode===Rr.PROXY_ONLINE){Rd(P.proxyId),qe.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(U.errorCode===Rr.PROXY_NOT_FOUND){Rd(P.proxyId),mp(P.proxyId,z)&&u("/"),qe.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Rd(P.proxyId),qe.error(U.error??"无法移除开发机,请重试")}catch(U){qe.error(U instanceof Error?U.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const N=m.jsx(ide,{open:g!==null,target:g,removing:w!==null,onOpenChange:P=>{P||_(null)},onConfirm:()=>void k()});if(e==="page")return i==="missing_client_token"?m.jsx(Yc,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(Yc,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(Yc,{variant:"no-proxy"}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex h-full flex-col gap-3 overflow-auto p-4",children:[m.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"开发机"}),m.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(P=>{const z=(o==null?void 0:o.proxyId)===P.proxyId,V=o!==null;return P.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":P.proxyId,"data-online":"true","data-selecting":z||void 0,disabled:V||w!==null,"aria-busy":z||void 0,onClick:()=>x(P.proxyId,P.name),className:Ye("flex min-h-[44px] w-full items-center gap-3 rounded-md border bg-card px-3 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-card",P.osName?"h-14":"h-11",z?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",V&&!z||w!==null?"opacity-50":""),"aria-pressed":s===P.proxyId,children:[m.jsx(g1,{status:"online"}),m.jsx(gp,{name:P.name??P.proxyId,osName:P.osName}),z?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"正在连接"}),m.jsx(oi,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===P.proxyId?m.jsx(ia,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},P.proxyId):m.jsx(ade,{proxyId:P.proxyId,name:P.name,osName:P.osName,selected:s===P.proxyId,revealed:p===P.proxyId,disabled:V||w!==null,onRevealedChange:U=>v(U?P.proxyId:null),onRemove:()=>R(P)},P.proxyId)})})]}),N]}):m.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:[m.jsx(oi,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const M=n.find(P=>P.proxyId===s),T=(M==null?void 0:M.name)??(M==null?void 0:M.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Ib,{open:d,onOpenChange:f,children:[m.jsx(Ob,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex min-h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 py-1.5 hover:bg-accent"),"aria-label":`当前连接:${T}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx(gp,{name:T,osName:M==null?void 0:M.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(ec,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(Lb,{align:"start",className:"w-[260px] p-1",children:n.length===0?m.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):m.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(P=>{const z=(o==null?void 0:o.proxyId)===P.proxyId,V=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":P.proxyId,"data-online":P.online,"data-selecting":z||void 0,disabled:!P.online||V,"aria-busy":z||void 0,onClick:()=>x(P.proxyId,P.name),className:Ye("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",P.osName?"h-12":"h-9",z?"bg-accent text-accent-foreground":"hover:bg-accent",V&&!z?"opacity-50":"",P.online?"":"opacity-50"),"aria-pressed":s===P.proxyId,title:P.online?void 0:"这台开发机离线",children:[m.jsx(g1,{status:P.online?"online":"offline"}),m.jsx(gp,{name:P.name??P.proxyId,osName:P.osName}),z?m.jsx(oi,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===P.proxyId?m.jsx(ia,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!P.online&&!z&&m.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]}),!P.online&&m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:V||w!==null,"aria-label":`${P.name??P.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsx(mf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(Lr,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:U=>{U.stopPropagation(),R(P)},children:[m.jsx(dz,{"aria-hidden":"true"}),"移除开发机"]})})]})]},P.proxyId)})})})]}),N]})}function lde({delayDuration:e=0,...t}){return m.jsx(Hue,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function gf({...e}){return m.jsx(Uue,{"data-slot":"tooltip",...e})}function vf({...e}){return m.jsx(Wue,{"data-slot":"tooltip-trigger",...e})}function yf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(que,{children:m.jsxs(Vue,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(Yue,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function lc({...e}){return m.jsx(KC,{"data-slot":"sheet",...e})}function cde({...e}){return m.jsx($oe,{"data-slot":"sheet-trigger",...e})}function ude({...e}){return m.jsx(GC,{"data-slot":"sheet-portal",...e})}function dde({className:e,...t}){return m.jsx(XC,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function cc({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,inert:l,"aria-disabled":u,...d}){const f=gm();return m.jsxs(ude,{children:[m.jsx(dde,{className:t}),m.jsxs(ZC,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:p=>{o==null||o(p),!(!s||p.defaultPrevented)&&(p.preventDefault(),p.currentTarget.focus({preventScroll:!0}))},inert:f||l?!0:void 0,"aria-disabled":f?!0:u,"data-relay-interaction-blocked":f?"true":void 0,...d,children:[n,i&&m.jsxs(gb,{"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:[m.jsx(fu,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function yu({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function uc({className:e,...t}){return m.jsx(P5,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function Db({className:e,...t}){return m.jsx(I5,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}const fde={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"},K2=["claude","codex","kimi"];function Bb(e){return fde[e]}function L4(e,t){return K2.indexOf(e)-K2.indexOf(t)}function Bp(e){return e.provider}const v1=60*1e3,y1=60*v1,hde=24*y1;function D4(e,t=Date.now()){const n=t-e;if(n<v1)return"刚刚";if(n<y1)return`${Math.floor(n/v1)} 分钟前`;if(n<hde)return`${Math.floor(n/y1)} 小时前`;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 G2={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 b1(e){return e.kind!=="terminal"?G2[e.state]:e.state==="terminated"?G2.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 pde({session:e}){const t=b1(e);return m.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function mde({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?fC:pC;return m.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:m.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function gde({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=Vr(w=>w.homePath),l=e.lastActive,u=e.cwd,d=jC(e.name,o),f=FC(e,o),p=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),v=D4(l,n),g=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return m.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&m.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),m.jsxs("button",{type:"button","data-slot":"session-row-select",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:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx(pde,{session:e}),m.jsx("span",{className:"text-sm font-normal truncate flex-1",title:u,children:p})]}),m.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[m.jsx(mde,{mode:e.mode}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Bb(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:Ye("shrink-0",b1(e).text),children:b1(e).label}),v&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:v})]})]})]}),(i||s)&&m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(Lr,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(Lr,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function mo(e){const[t,n]=b.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return b.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function vde({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(yde,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:D4(e.updatedAt,t)}),u=m.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return m.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:m.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(Q7,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function yde({title:e,modeTag:t}){return m.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[m.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&m.jsx(bde,{mode:t})]})}function bde({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?fC:pC;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function B4({providerLabel:e}){return m.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:m.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[m.jsx(qY,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),m.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function _de({now:e}){const t=Vr(O=>O.homePath),n=Gt(O=>O.historySessions),r=Gt(O=>O.historyLoadStatus),[i,s]=b.useState(null),[o,l]=b.useState(null),[u,d]=b.useState("json"),[f,p]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(new Set),[S,x]=b.useState(new Set),R=Es(),k=b.useMemo(()=>{const O=new Map;for(const A of n){const L=Bp(A);let D=O.get(L);D||(D=new Map,O.set(L,D));const I=z4(A.projectDir),B=D.get(I);B?B.sessions.push(A):D.set(I,{dir:I,sessions:[A]})}return Array.from(O.entries()).sort(([A],[L])=>L4(A,L)).map(([A,L])=>({provider:A,sessions:Array.from(L.values()).flatMap(D=>D.sessions),projects:Array.from(L.values()).map(D=>({dir:D.dir,shortDir:om(D.dir,t,{compact:!0}),sessions:D.sessions}))}))},[n,t]);function N(O){l(O),d(wde(O)),p(xde(O))}async function M(O,A,L){if(i)return;const D=Ft;if(!D){qe.error("请先连接开发机");return}s(O.id);const I=Bp(O);try{const B=await D.createSession({kind:"agent",cwd:O.projectDir,mode:A,provider:I,resumeSessionId:O.id,...L?{permissionMode:L}:{}});if(!B.success){if(B.errorCode===Rr.SESSION_ALREADY_ACTIVE){Gt.getState().setCodexActiveWriterConflict({...B.activeWriterPid?{activeWriterPid:B.activeWriterPid}:{}}),l(null);return}qe.error(`恢复失败:${B.error}`);return}if(B.kind!=="agent"){qe.error("恢复失败:开发机返回了错误的会话类型");return}const F={sessionId:B.sessionId,kind:"agent",...B.name!==void 0?{name:B.name}:{},...B.nameLocked!==void 0?{nameLocked:B.nameLocked}:{},state:"idle",cwd:B.cwd,lastActive:B.lastActive,provider:B.provider},Y=B.mode==="pty"?{...F,mode:"pty",ptyOwner:B.ptyOwner}:{...F,mode:"json"};Gt.getState().addSession(Y),R(`/chat/${B.sessionId}?mode=${B.mode}`),l(null)}catch(B){qe.error(`恢复失败:${B instanceof Error?B.message:String(B)}`)}finally{s(null)}}function T(){const O=Ft;!O||Gt.getState().historyLoadStatus==="loading"||LC(O).then(A=>{A.status==="failed"&&qe.error(A.error instanceof Error?A.error.message:String(A.error))})}function P(O,A){const L=X2(O,A);x(D=>{const I=new Set(D);return I.has(L)?I.delete(L):I.add(L),I})}function z(O){w(A=>{const L=new Set(A);return L.has(O)?L.delete(O):L.add(O),L})}const V=n.length>0,U=r==="loading",G=o?j4():[];return m.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[m.jsxs("div",{className:"flex min-h-11 w-full items-center gap-1.5 px-4 py-1.5 md:min-h-[36px]",children:[m.jsxs("button",{type:"button",onClick:()=>V&&g(O=>!O),disabled:!V,"aria-expanded":V?v:void 0,"data-slot":"history-section-header","data-expanded":v,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",V?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),V?m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",v&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(pt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":U,title:U?"正在加载":"刷新",onClick:T,disabled:U,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(nm,{className:Ye("size-3.5",U&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!V&&U&&m.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-loading",role:"status","aria-live":"polite",children:[m.jsx(oi,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!V&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!V&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),V&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!V&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),V&&v&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(O=>{const A=_.has(O.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>z(O.provider),"aria-expanded":!A,"data-slot":"history-provider-header","data-expanded":!A,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:Bb(O.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:O.sessions.length}),m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!A&&"rotate-90"),"aria-hidden":"true"})]}),!A&&m.jsx("ul",{role:"list",className:"flex flex-col",children:O.projects.map(L=>{const D=X2(O.provider,L.dir),I=S.has(D);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>P(O.provider,L.dir),"aria-expanded":I,"data-slot":"history-group-header","data-expanded":I,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:L.dir,children:L.shortDir}),m.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:L.sessions.length}),m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",I&&"rotate-90"),"aria-hidden":"true"})]}),I&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(B=>m.jsx(vde,{session:B,now:e,disabled:i!==null,loading:i===B.id,onClick:()=>N(B),modeTag:B.preferredMode},B.id))})]},D)})})]},O.provider)})}),m.jsx(Sde,{session:o,open:o!==null,modes:G,mode:u,permissionMode:f,submitting:i!==null,onOpenChange:O=>{O||l(null)},onModeChange:d,onPermissionModeChange:p,onConfirm:()=>{o&&M(o,u,f)}})]})}function X2(e,t){return`${e}:${z4(t)}`}function z4(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function j4(){return["json","pty"]}function wde(e){const t=j4();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function xde(e){return Bp(e)==="codex"?"auto":"default"}function Sde({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[f,p]=b.useState(!1),v=i==="bypassPermissions",g=mo("(min-width: 768px)"),_=e?Bp(e):null,w=_==="codex",S=_==="kimi";b.useEffect(()=>{t||p(!1)},[t]);const x=f?m.jsx(B4,{providerLabel:e?Bb(Bp(e)):"Agent"}):m.jsxs("div",{className:"grid min-w-0 gap-4",children:[m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&m.jsx(Z2,{checked:r==="json",label:"聊天",icon:m.jsx(fC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(Z2,{checked:r==="pty",label:"终端",icon:m.jsx(pC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[!w&&m.jsx(lv,{checked:i==="default",label:S?"手工审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),m.jsx(lv,{checked:i==="auto",label:w?"按需审批":S?"自动审批":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),S&&m.jsx(lv,{checked:i==="plan",label:"只读规划",description:"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(lv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),R=m.jsxs(m.Fragment,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?p(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(pt,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(v&&!f){p(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return g?m.jsx(Zi,{open:t,onOpenChange:o,children:m.jsxs(Qi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Ji,{className:"min-w-0",children:[m.jsx(Fi,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Ss,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),x,m.jsx(Ws,{children:R})]})}):m.jsx(lc,{open:t,onOpenChange:o,children:m.jsxs(cc,{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:[m.jsxs(yu,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(uc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Db,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),m.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:x}),m.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:m.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:R})})]})})}function Z2({checked:e,label:t,icon:n,disabled:r,onClick:i}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(ia,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function lv({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),m.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&m.jsx(ia,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function zb({...e}){return m.jsx(mue,{"data-slot":"select",...e})}function jb({...e}){return m.jsx(vue,{"data-slot":"select-value",...e})}function Fb({className:e,size:t="default",children:n,...r}){return m.jsxs(gue,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(yue,{asChild:!0,children:m.jsx(ec,{className:"size-4 opacity-50"})})]})}function $b({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=gm();return m.jsx(bue,{children:m.jsxs(_ue,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,inert:l||i?!0:void 0,"aria-disabled":l?!0:s,"data-relay-interaction-blocked":l?"true":void 0,...o,children:[m.jsx(Ede,{}),m.jsx(wue,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(Cde,{})]})})}function Hb({className:e,children:t,...n}){return m.jsxs(xue,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(Eue,{children:m.jsx(ia,{className:"size-4"})})}),m.jsx(Sue,{children:t})]})}function Ede({className:e,...t}){return m.jsx(Cue,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(uC,{className:"size-4"})})}function Cde({className:e,...t}){return m.jsx(kue,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(ec,{className:"size-4"})})}function kde(e,t,n){var u;if(t==="insert"){const d=e.split("@").pop()??"",f=Jc((n==null?void 0:n.baseCwd)??d)==="\\",p=Math.max(d.lastIndexOf("/"),f?d.lastIndexOf("\\"):-1);return{currentPath:p>=0?d.slice(0,p+1):f?".\\":"./",query:d.slice(p+1).toLowerCase()}}const r=ea((n==null?void 0:n.baseCwd)??"");if(!e)return{currentPath:lo(r),query:""};const i=ab(r,e);if(!i)return{currentPath:"",query:""};const s=IC(i),o=Jc(i);return e.endsWith("/")||o==="\\"&&e.endsWith("\\")||i===s||i===r||((u=n==null?void 0:n.knownDirs)==null?void 0:u.has(i))?{currentPath:lo(i),query:""}:{currentPath:lo(s),query:i.slice(i.lastIndexOf(o)+1).toLowerCase()}}function l0(e,t){return ab(e,t)}const F4=b.forwardRef(function({filter:t,onSelect:n,onNavigate:r,onSelectCurrentDirectory:i,onCreateDirectory:s,mode:o="insert",placement:l="floating",dirsOnly:u=!1,fileExtensions:d,includeHidden:f=!1,autoHighlightFirst:p=!0,title:v},g){const _=Vr(he=>f?he.treeWithHidden:he.tree),w=Vr(he=>he.cwd),S=Vr(he=>he.homePath),x=o==="insert"?w:S||w,R=b.useMemo(()=>new Set(_.keys()),[_]),k=b.useMemo(()=>kde(t,o,{baseCwd:x,knownDirs:R}),[t,o,x,R]),N=k.currentPath,M=b.useMemo(()=>l0(x,N),[x,N]),T=k.query,P=b.useRef(new Map),[z,V]=b.useState(!1),[U,G]=b.useState(""),[O,A]=b.useState(!1),[L,D]=b.useState(null),[I,B]=b.useState(0);b.useEffect(()=>{if(!M)return;const he=`${f?"hidden":"default"}\0${M}`;if(_.has(M))return;const He=Ft;if(!He)return;let Pt=!1;D(it=>(it==null?void 0:it.path)===M?null:it);let Ge=P.current.get(he);if(!Ge){Ge=He.requestDirectoryList(M,{includeHidden:f}),P.current.set(he,Ge);const it=()=>{P.current.get(he)===Ge&&P.current.delete(he)};Ge.then(it,it)}return Ge.then(it=>{if(!Pt){if(it.error!==void 0||it.errorCode!==void 0){D({path:M,message:it.error||"读取失败"});return}Vr.getState().setDirEntries(it.path,it.entries,it.includeHidden)}},it=>{Pt||D({path:M,message:it instanceof Error?it.message:"读取失败"})}),()=>{Pt=!0}},[M,f,_,I]);const F=(L==null?void 0:L.path)===M?L:null,Y=!_.has(M)&&!F,j=b.useMemo(()=>d==null?void 0:d.map(he=>he.startsWith(".")?he.toLowerCase():`.${he.toLowerCase()}`),[d]),q=b.useMemo(()=>{let he=_.get(M)??[];return u?he=he.filter(He=>He.isDir):j!=null&&j.length&&(he=he.filter(He=>He.isDir||j.some(Pt=>He.name.toLowerCase().endsWith(Pt)))),T&&(he=he.filter(He=>He.name.toLowerCase().includes(T))),he},[_,M,T,u,j]),[K,$]=b.useState(p?0:-1);b.useEffect(()=>$(p?0:-1),[p,N,T]),b.useEffect(()=>{V(!1),G("")},[M]),b.useEffect(()=>{K>=q.length&&q.length>0&&$(q.length-1)},[q.length,K]);const ne=b.useRef(null),J=b.useRef(!1);b.useEffect(()=>{var He;if(!J.current)return;J.current=!1;const he=(He=ne.current)==null?void 0:He.querySelector(`[data-entry-index="${K}"]`);he==null||he.scrollIntoView({block:"nearest"})},[K]);const te=b.useCallback(he=>{const He=Jc(x),Pt=`${lo(N,x)}${he.name}${he.isDir?He:""}`;if(o==="insert")return Pt.replace(He==="\\"?/^\.[\\/]/:/^\.\//,"");const Ge=l0(x,Pt);return he.isDir?lo(Ge):Ge},[x,N,o]),Q=b.useCallback(he=>{const He=l0(x,he);if(!He)return;const Pt=lo(He);if(o==="select"){r(Pt);return}n(Pt)},[x,o,r,n]),ce=b.useCallback(he=>{const He=te(he);if(he.isDir){Q(He);return}n(He)},[te,Q,n]);async function ie(){const he=YP(M,U);if(!(!he||!s)){A(!0);try{const He=await s(he);if(!He)return;if(G(""),V(!1),i){i(lo(He));return}Q(He)}finally{A(!1)}}}b.useImperativeHandle(g,()=>({handleKey(he){return q.length===0?!1:he.key==="ArrowDown"?(J.current=!0,$(He=>Math.min(q.length-1,He+1)),!0):he.key==="ArrowUp"?(J.current=!0,$(He=>Math.max(0,He-1)),!0):he.key==="Enter"&&K>=0&&!he.nativeEvent.isComposing?(ce(q[K]),!0):!1}}),[q,K,ce]);const le=b.useMemo(()=>IC(M),[M]),be=l==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":o==="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",Le=l==="inline"?"max-h-[min(11rem,30dvh)] overflow-y-auto overscroll-contain":o==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return m.jsxs("div",{className:be,"data-slot":"file-path-picker","data-mode":o,"data-placement":l,children:[o==="select"?m.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[m.jsxs("div",{className:"min-w-0",children:[v?m.jsx("p",{className:"mb-2 truncate text-xs text-muted-foreground","data-slot":"file-path-picker-title",children:v}):null,m.jsx("p",{className:"truncate font-mono text-xs text-foreground","data-slot":"file-path-picker-current-directory",title:M,children:om(M,S)||"正在读取路径"})]}),m.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",role:"toolbar","aria-label":"路径操作","data-slot":"file-path-picker-actions",children:[m.jsx("button",{type:"button","data-slot":"file-path-picker-parent",className:"inline-flex min-h-11 min-w-11 items-center justify-start px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",disabled:!M||M===le,onClick:()=>Q(le),children:"上一级"}),i||s?m.jsxs("span",{className:"flex shrink-0 items-center gap-4",children:[s?m.jsx("button",{type:"button","data-slot":"file-path-picker-create-directory-toggle",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",disabled:!M||O,onClick:()=>V(he=>!he),children:"新建目录"}):null,i?m.jsx("button",{type:"button","data-slot":"select-current-directory",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",disabled:!M,onClick:()=>i(lo(M)),children:"选定"}):null]}):null]}),z?m.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[m.jsx("input",{type:"text","data-slot":"file-path-picker-create-directory-name",value:U,onChange:he=>G(he.target.value),onKeyDown:he=>{he.key==="Enter"&&!he.nativeEvent.isComposing&&(he.preventDefault(),ie()),he.key==="Escape"&&(V(!1),G(""))},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}),m.jsx("button",{type:"button","data-slot":"file-path-picker-create-directory-submit",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:!YP(M,U)||O,onClick:()=>void ie(),children:O?"创建中...":"创建目录"})]}):null]}):null,m.jsx("div",{className:Le,"data-slot":"file-path-picker-entries",children:F?m.jsxs("div",{"data-slot":"file-path-picker-error",className:"flex items-center justify-between gap-3 px-3 py-2",role:"alert",children:[m.jsx("span",{className:"min-w-0 text-xs text-destructive",title:F.message,children:"无法读取这个文件夹"}),m.jsx("button",{type:"button","data-slot":"file-path-picker-retry",className:"shrink-0 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",onClick:()=>B(he=>he+1),children:"重试"})]}):q.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:Y?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:ne,role:"list",className:"flex flex-col",children:q.map((he,He)=>m.jsx("li",{children:m.jsx("button",{type:"button",onClick:()=>ce(he),onMouseEnter:()=>$(He),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",He===K&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",he.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":he.isDir?"dir":"file","data-entry-name":he.name,"data-entry-index":He,children:m.jsxs("span",{className:"font-mono text-[13px]",children:[he.name,he.isDir?"/":""]})})},he.name))})})]})});function Q2(e,t,n){const r=Gv(e,t);return r?n==="file"?lo(IC(r)):r:t}function Gv(e,t){const n=ea(e,t);return n?e.endsWith("/")||Jc(n)==="\\"&&e.endsWith("\\")?lo(n):n:""}function vk({value:e,onValueChange:t,selectionKind:n,fileExtensions:r,includeHidden:i=!1,onCreateDirectory:s,disabled:o=!1,placeholder:l="选择路径",label:u,labelActions:d,id:f,name:p,required:v,autoFocus:g,"aria-describedby":_,"aria-invalid":w,"data-slot":S,className:x,onKeyDown:R}){const k=b.useId(),N=f??`remote-path-${k}`,M=`${N}-label`,T=Vr(J=>J.homePath),P=mo("(pointer: coarse), (hover: none)"),z=af().deviceKind,V=P||z==="phone"||z==="tablet",[U,G]=b.useState(!1),[O,A]=b.useState(()=>Q2(e,T,n)),[L,D]=b.useState(e),I=b.useRef(null),B=b.useRef(null);b.useEffect(()=>{U||L===e||D(e)},[L,U,e]),b.useEffect(()=>{if(!U)return;function J(te){const Q=I.current,ce=te.target;Q&&(te.composedPath().includes(Q)||ce instanceof Node&&Q.contains(ce))||(G(!1),D(e))}return document.addEventListener("click",J),()=>document.removeEventListener("click",J)},[U,e]),b.useEffect(()=>{o&&(G(!1),D(e))},[o,e]);const F=n!=="file";function Y(){if(o)return;const J=Q2(e,T,n);A(J),D(e),G(!0)}function j(){G(!1),D(e)}function q(J){const te=Gv(J,T);te&&(A(te),D(te),t(te),G(!1))}function K(J){const te=Gv(J,T);te&&A(te)}function $(J){var te;if(U&&((te=B.current)!=null&&te.handleKey(J))){J.preventDefault();return}if(J.key==="Escape"&&U){J.preventDefault(),j();return}R==null||R(J)}const ne=U?m.jsx("div",{className:Ye(V&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(F4,{ref:B,mode:"select",placement:V?"inline":"floating",filter:O,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!V,title:l,onNavigate:K,onSelect:q,onSelectCurrentDirectory:F?q:void 0,onCreateDirectory:s})}):null;return m.jsxs("div",{className:Ye("flex min-w-0 flex-col gap-1",x),children:[m.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[m.jsx("span",{id:M,className:"min-w-0 text-sm",children:u}),d?m.jsx("div",{className:"flex shrink-0 items-center gap-4",children:d}):null]}),m.jsx("div",{ref:I,className:"relative min-w-0",onBlur:J=>{if(!U||V)return;const te=J.relatedTarget;te instanceof Node&&J.currentTarget.contains(te)||window.setTimeout(()=>{var Q;(Q=I.current)!=null&&Q.contains(document.activeElement)||j()},0)},children:V?m.jsxs(m.Fragment,{children:[m.jsxs("button",{id:N,type:"button","aria-labelledby":M,"aria-describedby":_,"aria-invalid":w,"aria-expanded":U,"aria-controls":`${N}-browser`,disabled:o,"data-slot":S,"data-path-control":"button",onClick:()=>{U?j():Y()},className:"flex min-h-11 w-full min-w-0 items-center gap-2 rounded-md border border-border bg-input px-3 text-left text-base outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",children:[m.jsx(WV,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsx("span",{className:Ye("min-w-0 flex-1 truncate font-mono",e?"text-foreground":"text-muted-foreground"),title:e||void 0,children:om(e,T)||l})]}),p?m.jsx("input",{type:"hidden",name:p,value:e,required:v}):null,m.jsx("div",{id:`${N}-browser`,children:ne})]}):m.jsxs(m.Fragment,{children:[m.jsx("input",{id:N,type:"text","aria-labelledby":M,"aria-describedby":_,"aria-invalid":w,name:p,required:v,autoFocus:g,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:Y,onChange:J=>{const te=J.target.value,Q=Gv(te,T);D(te),A(Q||T),t(Q||te),G(!0)},onKeyDown:$,placeholder:l,className:"min-h-11 min-w-0 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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"}),ne]})})]})}const J2="工作目录不存在或不可访问:",Tde=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],$4=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],H4=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],zp={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"};function Rde(e,t){return t!==Rr.PATH_NOT_FOUND||!e.startsWith(J2)?null:e.slice(J2.length).trim()||null}function U4(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 Ade(e,t){return e==="codex"?$4.some(n=>n.value===t)?t:"auto":e==="kimi"?H4.some(n=>n.value===t)?t:"default":t}async function Nde({relay:e,agentCli:t,form:n,timeoutMs:r=MC}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(U4(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?`${zp[n.provider]} 不可用:${p}`:`${zp[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.success){const w=Rde(p.error,p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error}`}}if(p.kind!=="agent")return{type:"create_error",message:"创建失败:开发机返回了错误的会话类型"};const v=((f=p.name)==null?void 0:f.trim())||void 0,g={sessionId:p.sessionId,kind:"agent",name:v,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",cwd:p.cwd,lastActive:p.lastActive,provider:p.provider};return{type:"success",session:p.mode==="pty"?{...g,mode:"pty",ptyOwner:p.ptyOwner}:{...g,mode:"json"},route:`/chat/${p.sessionId}?mode=${p.mode}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function Mde({relay:e,shell:t,timeoutMs:n=MC}){var r;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const i=await e.createSession({kind:"terminal",mode:"pty",...t?{shell:t}:{}},n);return i.success?i.kind!=="terminal"?{type:"create_error",message:"创建终端失败:开发机返回了错误的会话类型"}:{type:"success",session:{sessionId:i.sessionId,kind:"terminal",name:((r=i.name)==null?void 0:r.trim())||void 0,...i.nameLocked!==void 0?{nameLocked:i.nameLocked}:{},state:"idle",cwd:i.cwd,lastActive:i.lastActive,mode:"pty",provider:i.provider,ptyOwner:i.ptyOwner},route:`/chat/${i.sessionId}?mode=pty`}:{type:"create_error",message:`创建终端失败:${i.error}`}}catch(i){return{type:"exception",message:i instanceof Error?i.message:String(i)}}}const Pde=["claude","codex","kimi"];function Ide({agentCli:e,provider:t,cliPathDraftProvider:n,cliPathDraft:r,savingCliPath:i,onProviderChange:s,onCliPathDraftChange:o,onDiscardCliPathDraft:l,onSaveCliPath:u}){const d=e==null?void 0:e[t],f=(d==null?void 0:d.command)??"",p=n===t,v=p?r:f,g=p&&r.trim()!==f;return m.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"Agent CLI"}),m.jsxs(zb,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(Fb,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(jb,{})}),m.jsx($b,{"data-slot":"agent-cli-provider-options",children:Pde.map(_=>m.jsx(Hb,{value:_,className:"min-h-11 md:min-h-0",children:zp[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(vk,{id:`agent-cli-path-${t}`,"data-slot":"agent-cli-path",label:"CLI 路径",value:v,onValueChange:_=>o(t,_),selectionKind:"file",includeHidden:!0,disabled:i,placeholder:"选择 CLI 可执行文件",labelActions:g?m.jsxs("div",{className:"flex items-center gap-4","data-slot":"agent-cli-path-actions",children:[m.jsx("button",{type:"button",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-muted-foreground hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:no-underline md:min-h-8 md:min-w-0",onClick:l,disabled:i,children:"取消"}),m.jsx("button",{type:"button",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",onClick:u,disabled:i||!r.trim(),children:i?"保存中...":"保存"})]}):void 0,onKeyDown:_=>{_.key==="Enter"&&g&&(_.preventDefault(),_.stopPropagation(),u()),_.key==="Escape"&&p&&(_.preventDefault(),_.stopPropagation(),l())}},t),d!=null&&d.error&&!g?m.jsx("p",{className:"mt-1 break-all text-xs text-destructive",children:d.error}):null]})]})}function tp({open:e,onOpenChange:t}){var Q;const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,p]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[R,k]=b.useState(null),[N,M]=b.useState(""),[T,P]=b.useState(!1),z=b.useRef(e);z.current=e;const V=Es(),U=Vr(ce=>ce.homePath),G=Vr(ce=>ce.agentCli),O=mo("(min-width: 768px)");b.useEffect(()=>{e&&!i&&U&&s(U)},[e,U,i]),b.useEffect(()=>{if(!e||U&&G)return;const ce=Ft==null?void 0:Ft.requestProxyInfo();ce&&ce.then(ie=>{const le=Vr.getState();le.setHomePath(ie.homePath),le.setAgentCli(ie.agentCli)}).catch(ie=>{console.error("[create-session-dialog] requestProxyInfo failed",ie)})},[e,U,G]);function A(){r(""),s(""),l("claude"),d("pty"),p("default"),g(!1),x(null),k(null),M(""),P(!1)}function L(){if(f==="bypassPermissions"){g(!0);return}q()}async function D(){await q(),z.current&&g(!1)}const I=o==="codex"?$4:o==="kimi"?H4:Tde,B=U4(o,G),F=R===o&&N.trim()!==(((Q=G==null?void 0:G[o])==null?void 0:Q.command)??""),Y=_||T||B.disabled||F;function j(ce){const ie=Ade(ce,f);ie!==f&&p(ie)}async function q(ce){x(null),w(!0);try{const ie=await Nde({relay:Ft,agentCli:G,form:{cwd:ce??i,name:n,provider:o,permissionMode:f,mode:u}});if(ie.type==="success"){if(Gt.getState().addSession(ie.session),!z.current)return;t(!1),A(),V(ie.route);return}if(ie.type==="missing_cwd"&&x(ie.path),qe.error(ie.message),ie.type==="validation_error"||ie.type==="relay_missing")return}finally{w(!1)}}async function K(ce){const ie=Ft;if(!ie)return qe.error("请先连接开发机"),null;try{const le=await ie.createDirectory(ce);return le.success?(x(null),qe.success("目录已创建"),le.path):(qe.error(`目录创建失败:${le.error??"未知错误"}`),null)}catch(le){return qe.error(le instanceof Error?le.message:String(le)),null}}function $(ce,ie){k(ce),M(ie)}async function ne(){if(!R)return;const ce=R,ie=N.trim();if(!ie){qe.error("请选择 Agent CLI 可执行文件");return}const le=Ft;if(!le){qe.error("请先连接开发机");return}P(!0);try{const be=await le.updateAgentCliPath(ce,ie);if(be.error||!be.agentCli){qe.error(`路径保存失败:${be.error??"未知错误"}`);return}Vr.getState().setAgentCli(be.agentCli),qe.success(`${zp[ce]} 路径已保存`),k(null),M("")}catch(be){qe.error(be instanceof Error?be.message:String(be))}finally{P(!1)}}function J(ce){d(ce),j(o)}const te=v?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(B4,{providerLabel:zp[o]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:_,children:"返回"}),m.jsx(pt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void D(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:ce=>{ce.preventDefault(),L()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:ce=>r(ce.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),m.jsx(vk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:i,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:K,onValueChange:ce=>{s(ce),x(null)}}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>J("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>J("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(Ide,{agentCli:G,provider:o,cliPathDraftProvider:R,cliPathDraft:N,savingCliPath:T,onProviderChange:ce=>{l(ce),j(ce),k(null),M("")},onCliPathDraftChange:$,onDiscardCliPathDraft:()=>{k(null),M("")},onSaveCliPath:()=>void ne()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(zb,{value:f,onValueChange:ce=>p(ce),children:[m.jsx(Fb,{className:"w-full",children:m.jsx(jb,{})}),m.jsx($b,{children:I.map(ce=>m.jsx(Hb,{value:ce.value,children:ce.label},ce.value))})]})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(pt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return O?m.jsx(Zi,{open:e,onOpenChange:t,children:m.jsxs(Qi,{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:[m.jsx(Ji,{children:m.jsx(Fi,{children:v?"跳过全部审批?":"新建会话"})}),te]})}):m.jsx(lc,{open:e,onOpenChange:t,children:m.jsxs(cc,{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:[m.jsx(yu,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(uc,{children:v?"跳过全部审批?":"新建会话"})}),te]})})}function np({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=b.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=b.useState(s),[u,d]=b.useState(null),[f,p]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function v(g){g.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return m.jsx(Zi,{open:e,onOpenChange:r,children:m.jsx(Qi,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>void v(g),children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"重命名会话"}),m.jsx(Ss,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),m.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:f,onChange:g=>{l(g.target.value),u&&d(null)}}),u?m.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(pt,{type:"submit",disabled:f,children:"保存"})]})]})})})}function Ode(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function Lde(e){return(e==null?void 0:e.kind)==="terminal"}function Dde(e){return Ode(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Lde(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function cv({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Dde(t);function s(){t&&(r(t),n(!1))}return m.jsx(Zi,{open:e,onOpenChange:n,children:m.jsxs(Qi,{"data-slot":"session-termination-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:i.title}),m.jsx(Ss,{children:i.description})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(pt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function W4(e){var t,n,r,i,s,o,l,u,d,f,p,v;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"||((f=e.agentStatus)==null?void 0:f.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((v=e.ptyState)==null?void 0:v.state)==="working"?"working":"idle"}function Bde(e){if(e.session.state==="error")return"error";const t=W4(e);return t==="disconnected"?e.session.state:t}const zde=new Set(["localhost","127.0.0.1","[::1]"]),_1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function jde(){return Ci("local",Sn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function q4(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function c0(e,t){var n;return((n=q4(e,t))==null?void 0:n.available)===!0}function Fde(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!zde.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Ch(){return{status:"idle"}}function $de({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(jde),[o,l]=b.useState("local"),[u,d]=b.useState(""),[f,p]=b.useState(""),[v,g]=b.useState(""),[_,w]=b.useState(Ch),[S,x]=b.useState(!1),R=b.useRef(null),k=b.useRef(null),N=b.useRef(null),M=b.useRef(null),T=b.useRef(i);T.current=i;const P=b.useRef(e);P.current=e;const z=mo("(min-width: 768px)"),V=Te(te=>te.selectedProxyId),U=Ur(te=>te.capability),G=Ur(te=>te.capabilityStatus),O=Ur(te=>te.capabilityError),A=Ur(te=>{var Q;return((Q=te.authoritative)==null?void 0:Q.scope)??null}),L=A?`${A.proxyId}\0${A.bindingId}`:null,D=b.useCallback(te=>{T.current=te,s(te),Tr("local",Sn.webPreviewTunnelProvider,te)},[]);function I(){var te,Q;r(""),l("local"),d(""),p(""),g(""),w(Ch()),x(!1),(te=R.current)==null||te.abort(),R.current=null,(Q=k.current)==null||Q.abort(),k.current=null,N.current=null,M.current=null}const B=b.useCallback(async te=>{var ie;(ie=R.current)==null||ie.abort();const Q=new AbortController;R.current=Q;const ce=Rt.getActiveScope();if(!(!ce||ce.proxyId!==V))try{const le=await Rt.requestWebPreviewCapability(ce,te,{signal:Q.signal});if(!le||Q.signal.aborted||!P.current||!le.success)return;const be=T.current,Le=be==="cloudflare"?"cpolar":"cloudflare";!c0(le.capability,be)&&c0(le.capability,Le)&&D(Le)}catch{}},[D,V]);function F(te){!te&&S||t(te)}b.useEffect(()=>{if(!e){I();return}return B(!1),()=>{var te;(te=R.current)==null||te.abort(),R.current=null}},[B,e,L]),b.useEffect(()=>{var ie;if(!e||o!=="static")return;(ie=k.current)==null||ie.abort(),k.current=null;const te=f.trim();if(!te){w(Ch()),g("");return}const Q=new AbortController;k.current=Q,w({status:"loading"}),g("");const ce=window.setTimeout(()=>{const le=Ft,be=Rt.getActiveScope();if(!le||!be||be.proxyId!==V){w({status:"error",message:"请先连接开发机"});return}Rt.inspectStaticWebPreview(be,te,{signal:Q.signal}).then(Le=>{if(!Le||Q.signal.aborted||!P.current||!Rt.isActive(le,be))return;if(!Le.success){w({status:"error",message:Le.error});return}const he=Le.htmlEntries;if(he.length===0&&!Le.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const He={entryPath:Le.entryPath,htmlEntries:he};w({status:"ready",path:te,result:He}),g(Le.entryPath??"")}).catch(Le=>{Q.signal.aborted||!P.current||Le instanceof Error&&Le.name==="AbortError"||!Rt.isActive(le,be)||w({status:"error",message:Le instanceof Error?Le.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(ce),Q.abort(),k.current===Q&&(k.current=null)}},[e,L,V,o,f]);const Y=o==="local"?Fde(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||v),q=G==="loaded"&&c0(U,i),$=S||!q||!(o==="local"?Y===null:j);async function ne(){var le,be,Le;if($)return;const te=Ft;if(!te){qe.error("请先连接开发机");return}let Q;if(o==="local")Q={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const he=_.result.entryPath??v;if(!he)return;Q={kind:"static",path:_.path,entryPath:he}}x(!0);const ce=Rt.getActiveScope();if(!ce){x(!1),qe.error("请先连接开发机");return}let ie=null;try{const he=n.trim(),He=JSON.stringify({proxyId:ce.proxyId,tunnelProvider:i,source:Q,name:he||void 0});((le=N.current)==null?void 0:le.sourceKey)!==He&&(N.current={sourceKey:He,operationId:sm(`preview-operation-${i}`)}),ie=N.current.operationId,M.current=ie;const Pt=await Rt.createWebPreview(ce,Q,{tunnelProvider:i,operationId:ie,...he?{name:he}:{}});if(M.current!==ie)return;if(!Pt.accepted){((be=N.current)==null?void 0:be.operationId)===ie&&(N.current=null),qe.error(Pt.error);return}if(((Le=N.current)==null?void 0:Le.operationId)===ie&&(N.current=null),!P.current||!Rt.isActive(te,ce))return;t(!1)}catch(he){if(!ie||M.current!==ie||!P.current||!Rt.isActive(te,ce))return;qe.error(he instanceof Error?he.message:"无法创建网页预览")}finally{ie&&M.current===ie&&(M.current=null,P.current&&x(!1))}}const J=m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-web-preview-form",autoComplete:"off",onSubmit:te=>{te.preventDefault(),ne()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-web-preview-name",value:n,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S,placeholder:"自动生成","data-slot":"web-preview-name",onChange:te=>{r(te.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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"})]}),m.jsxs("section",{className:"flex min-w-0 flex-col gap-1","data-slot":"web-preview-tunnel-provider-field","data-provider":i,children:[m.jsx("span",{className:"text-sm",children:"内网穿透服务"}),m.jsxs(zb,{value:i,disabled:S,onValueChange:te=>D(te),children:[m.jsx(Fb,{"aria-label":"内网穿透服务","data-slot":"web-preview-tunnel-provider-select","data-provider":i,className:"min-h-11 w-full md:min-h-0",children:m.jsx(jb,{})}),m.jsx($b,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(_1).map(te=>m.jsx(Hb,{value:te,"data-slot":"web-preview-tunnel-provider-option","data-provider":te,children:_1[te].label},te))})]})]}),m.jsx(Hde,{status:G,capability:U,provider:i,error:O,disabled:S,onRetry:()=>void B(!0)}),m.jsxs("section",{"aria-label":"网页来源",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"网页来源"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","data-slot":"web-preview-source-local",disabled:S,"aria-pressed":o==="local",onClick:()=>{var te;(te=k.current)==null||te.abort(),k.current=null,w(Ch()),g(""),l("local")},className:Ye("flex min-h-16 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 disabled:cursor-not-allowed disabled:opacity-60",o==="local"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"本机网站"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"输入 localhost 地址"})]}),m.jsxs("button",{type:"button","data-slot":"web-preview-source-static",disabled:S,"aria-pressed":o==="static",onClick:()=>{var te;(te=k.current)==null||te.abort(),k.current=null,w(Ch()),g(""),l("static")},className:Ye("flex min-h-16 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 disabled:cursor-not-allowed disabled:opacity-60",o==="static"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"网页文件"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"选择 HTML 网页文件或目录"})]})]})]}),o==="local"?m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"本机网站地址"}),m.jsx("input",{type:"url","data-slot":"web-preview-local-url","aria-label":"本机网站地址",inputMode:"url",name:"dev-anywhere-preview-local-url",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S,value:u,onChange:te=>{d(te.target.value)},placeholder:"http://localhost:5173","aria-invalid":u.length>0&&Y!==null,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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"}),u.length>0&&Y?m.jsx("span",{"data-slot":"web-preview-local-url-error",className:"text-xs text-destructive",role:"alert",children:Y}):null]}):m.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx(vk,{id:"create-web-preview-path",name:"dev-anywhere-preview-static-path","data-slot":"web-preview-static-path",label:"网页位置",value:f,selectionKind:"file-or-directory",fileExtensions:[".html",".htm"],disabled:S,placeholder:"选择 HTML 网页文件或目录",onValueChange:p}),m.jsx(Ude,{inspection:_,selectedEntryPath:v,disabled:S,onEntryPathChange:te=>{g(te)}})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost","data-slot":"create-web-preview-cancel",className:"min-h-11 md:min-h-0",onClick:()=>F(!1),disabled:S,children:"取消"}),m.jsx(pt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:$,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(Zi,{open:e,onOpenChange:F,children:m.jsxs(Qi,{showCloseButton:!S,onEscapeKeyDown:te=>{S&&te.preventDefault()},onPointerDownOutside:te=>{S&&te.preventDefault()},className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[40rem]","data-slot":"create-web-preview-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"新建网页预览"}),m.jsx(Ss,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),J]})}):m.jsx(lc,{open:e,onOpenChange:F,children:m.jsxs(cc,{side:"bottom",showCloseButton:!S,onEscapeKeyDown:te=>{S&&te.preventDefault()},onPointerDownOutside:te=>{S&&te.preventDefault()},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-web-preview-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(yu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(uc,{children:"新建网页预览"}),m.jsx(Db,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),J]})})}function Hde({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=_1[n];if(e==="loading"||e==="idle")return m.jsxs("div",{"data-slot":"web-preview-capability-status","data-status":"loading","data-provider":n,className:"flex items-center gap-2 rounded-md border border-border/70 bg-muted/20 px-3 py-2 text-sm text-muted-foreground",role:"status",children:[m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在检测 ",o.label,"..."]});if(e==="error")return m.jsx("div",{"data-slot":"web-preview-capability-status","data-status":"error","data-provider":n,className:"rounded-md border border-destructive/45 bg-destructive/5 p-3",role:"alert",children:m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(ez,{className:"mt-0.5 size-4 shrink-0 text-destructive","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("p",{className:"text-sm font-medium",children:["无法检测 ",o.label]}),r?m.jsx("p",{className:"mt-1 break-words text-xs text-muted-foreground",children:r}):null]}),m.jsx(eI,{onClick:s,disabled:i})]})});const l=q4(t,n);if(!(l!=null&&l.available)){const u=(l==null?void 0:l.suggestions)??[],d=`未找到 ${o.label}`,f=(l==null?void 0:l.error)&&l.error!==d;return m.jsx("div",{"data-slot":"web-preview-capability-status","data-status":"missing","data-provider":n,className:"rounded-md border border-[var(--color-status-warning)]/45 bg-[var(--color-status-warning)]/5 p-3",role:"alert",children:m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(_V,{className:"mt-0.5 size-4 shrink-0 text-[var(--color-status-warning)]","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("p",{className:"text-sm font-medium",children:d}),m.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["请先安装 ",o.executable,",并确保它在用户 Shell 的 PATH 中,然后重新检测。"]}),u.length>0?m.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[m.jsx("span",{children:"检测到的位置:"}),m.jsx("ul",{className:"mt-1 space-y-1",children:u.map(p=>m.jsx("li",{"data-slot":n==="cloudflare"?"web-preview-cloudflared-suggestion":"web-preview-cpolar-suggestion","data-provider":n,"data-path":p,children:m.jsx("code",{className:"break-all rounded bg-muted px-1 py-0.5",children:p})},p))})]}):null,o.installUrl?m.jsx("a",{"data-slot":"web-preview-cloudflared-install-link","data-provider":n,href:o.installUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-block text-xs text-primary underline-offset-4 hover:underline",children:"查看官方安装说明"}):null,f?m.jsx("p",{className:"mt-1 break-words text-xs text-muted-foreground/80",children:l.error}):null]}),m.jsx(eI,{onClick:s,disabled:i})]})})}return m.jsxs("div",{"data-slot":"web-preview-capability-status","data-status":"ready","data-provider":n,className:"flex items-center gap-2 rounded-md border border-[var(--color-status-success)]/35 bg-[var(--color-status-success)]/5 px-3 py-2 text-sm",role:"status",children:[m.jsx(fV,{className:"size-4 text-[var(--color-status-success)]","aria-hidden":"true"}),m.jsxs("span",{children:[o.label," 已安装"]}),l.version?m.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["· ",l.version]}):null]})}function eI({onClick:e,disabled:t}){return m.jsxs(pt,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(nm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function Ude({inspection:e,selectedEntryPath:t,disabled:n,onEntryPathChange:r}){if(e.status==="idle")return null;if(e.status==="loading")return m.jsxs("span",{"data-slot":"web-preview-static-inspection","data-status":"loading",className:"flex items-center gap-2 text-xs text-muted-foreground",role:"status",children:[m.jsx(oi,{className:"size-3.5 animate-spin","aria-hidden":"true"}),"正在检查网页..."]});if(e.status==="error")return m.jsx("span",{"data-slot":"web-preview-static-inspection","data-status":"error",className:"text-xs text-destructive",role:"alert",children:e.message});if(!e.result.entryPath&&e.result.htmlEntries.length>1)return m.jsxs("label",{"data-slot":"web-preview-static-inspection","data-status":"choose-entry",className:"mt-1 flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"这个文件夹里有多个网页,打开预览时先显示哪个?"}),m.jsxs(zb,{value:t,onValueChange:r,disabled:n,children:[m.jsx(Fb,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(jb,{placeholder:"选择网页"})}),m.jsx($b,{children:e.result.htmlEntries.map(o=>m.jsx(Hb,{value:o,"data-entry-path":o,children:o},o))})]})]});const s=e.result.entryPath;return s?m.jsxs("span",{"data-slot":"web-preview-static-inspection","data-status":"ready","data-entry-path":s,className:"truncate text-xs text-muted-foreground",title:s,children:["打开时显示:",m.jsx("span",{className:"font-mono",children:s})]}):null}const w1={ios:"iOS Simulator",android:"Android Emulator"};function Wde({open:e,platform:t,onOpenChange:n}){const r=Es(),i=mo("(min-width: 768px)"),s=Te(F=>F.selectedProxyId),o=dr(F=>F.capability),l=dr(F=>F.targets),u=dr(F=>F.targetsStatus),d=dr(F=>F.targetsError),f=dr(Hj),p=dr(F=>{var Y;return((Y=F.authoritative)==null?void 0:Y.scope)??null}),v=p?`${p.proxyId}\0${p.bindingId}`:null,[g,_]=b.useState(""),[w,S]=b.useState(null),[x,R]=b.useState(!1),k=b.useRef(null),N=b.useRef(e);N.current=e;const M=b.useRef(null),T=b.useRef(null),P=b.useMemo(()=>l.filter(F=>F.platform===t),[t,l]),z=b.useMemo(()=>new Set(f.map(F=>F.targetId)),[f]),V=b.useMemo(()=>P.filter(F=>!z.has(F.targetId)),[z,P]),U=V.find(F=>F.targetId===w),G=o==null?void 0:o[t],O=b.useCallback(async F=>{var K;(K=k.current)==null||K.abort();const Y=new AbortController;k.current=Y;const j=Ft,q=Rt.getActiveScope();if(!(!j||!q||q.proxyId!==s))try{const $=await Rt.requestDevicePreviewCapability(q,F,{signal:Y.signal});if(!$||Y.signal.aborted||!N.current||!$.success)return;await Rt.requestDevicePreviewTargets(q,!0,{signal:Y.signal})}catch{}},[s]);b.useEffect(()=>{var F;if(!e){(F=k.current)==null||F.abort(),k.current=null,_(""),S(null),R(!1),M.current=null,T.current=null;return}return O(!1),()=>{var Y;(Y=k.current)==null||Y.abort(),k.current=null}},[O,e,t,v]),b.useEffect(()=>{if(e){if(w&&!U){S(null);return}!w&&V.length===1&&S(V[0].targetId)}},[e,V,U,w]);async function A(){var K,$,ne;const F=U;if(!F||x||(G==null?void 0:G.available)!==!0)return;const Y=Ft,j=Rt.getActiveScope();if(!Y||!j||j.proxyId!==s){qe.error("请先连接开发机");return}R(!0);let q=null;try{const J=g.trim(),te=((K=M.current)==null?void 0:K.proxyId)===j.proxyId&&M.current.targetId===F.targetId&&M.current.name===J?M.current:{proxyId:j.proxyId,targetId:F.targetId,name:J,operationId:sm("device-preview-operation")};M.current=te,q=te.operationId,T.current=q;const Q=await Rt.createDevicePreview(j,F.targetId,{operationId:te.operationId,...J?{name:J}:{}});if(T.current!==te.operationId)return;if(!Q.accepted){if((($=M.current)==null?void 0:$.operationId)===te.operationId&&(M.current=null),!N.current||!Rt.isActive(Y,j))return;qe.error(Q.error);return}if(((ne=M.current)==null?void 0:ne.operationId)===te.operationId&&(M.current=null),!N.current||!Rt.isActive(Y,j))return;n(!1),r(`/preview/device/${Q.previewId}`)}catch(J){if(!q||T.current!==q||!N.current||!Rt.isActive(Y,j))return;qe.error(J instanceof Error?J.message:"无法创建模拟器预览")}finally{q&&T.current===q&&(T.current=null,N.current&&R(!1))}}function L(F){var Y;!F&&x||(F||((Y=k.current)==null||Y.abort(),k.current=null,M.current=null,T.current=null,_(""),S(null)),n(F))}const D=m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4",children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-device-preview-name",value:g,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:x,placeholder:"自动生成","data-slot":"device-preview-name",onChange:F=>{_(F.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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"})]}),m.jsx(qde,{platform:t,tool:G}),m.jsx("div",{className:"grid min-w-0 grid-cols-1 gap-2","data-slot":"device-preview-targets",children:u==="loading"?m.jsxs("div",{className:"flex min-h-28 items-center justify-center gap-2 text-sm text-muted-foreground",children:[m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(tI,{message:d??"无法读取模拟器列表"}):P.length===0?m.jsx(tI,{message:`没有已启动的 ${w1[t]}`}):P.map(F=>{const Y=F.targetId===w,j=z.has(F.targetId);return m.jsx(Vde,{target:F,selected:Y,disabled:j||x,alreadyOpen:j,onClick:()=>{S(F.targetId)}},F.targetId)})}),m.jsxs(Ws,{className:"gap-2 sm:gap-2",children:[m.jsxs(pt,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>void O(!0),"data-slot":"device-preview-refresh",children:[m.jsx(nm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(pt,{type:"button",disabled:!U||x||(G==null?void 0:G.available)!==!0,onClick:()=>void A(),"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),I=`新建 ${w1[t]} 预览`,B="选择开发机上已经启动的模拟器。";return i?m.jsx(Zi,{open:e,onOpenChange:L,children:m.jsxs(Qi,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:I}),m.jsx(Ss,{children:B})]}),D]})}):m.jsx(lc,{open:e,onOpenChange:L,children:m.jsxs(cc,{side:"bottom",showCloseButton:!x,className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto min-w-0 max-w-[calc(100%-1rem)] 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-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(yu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(uc,{children:I}),m.jsx(Db,{children:B})]}),D]})})}function qde({platform:e,tool:t}){if(!t||t.available)return null;const n=e==="android"&&!!t.command,r=e==="ios"?"Baguette":"adb",i=t.supported?e==="ios"&&t.version?"outdated":t.command?"unavailable":"missing":"unsupported",s=n?"Android 模拟器预览不可用":i==="unsupported"?`${w1[e]} 不可用`:i==="outdated"?`需要更新 ${r}`:i==="unavailable"?`${r} 暂时不可用`:`未找到 ${r}`,o=t.error??(e==="ios"?"需要先在开发机上安装 Baguette 0.1.96 或更高版本。":"需要先在开发机上安装 adb。"),l=o.trim()!==s.trim();return m.jsx("div",{className:"rounded-lg border border-amber-500/45 bg-amber-500/5 p-3 text-sm","data-slot":"device-preview-tool-status","data-status":i,children:m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ez,{className:"mt-0.5 size-4 shrink-0 text-amber-600","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0",children:[m.jsx("p",{className:"font-medium",children:s}),l?m.jsx("p",{className:"mt-1 text-muted-foreground","data-slot":"device-preview-tool-description",children:o}):null,i!=="unsupported"&&!n?m.jsx("a",{href:e==="ios"?"https://github.com/tddworks/baguette#install":"https://developer.android.com/tools/releases/platform-tools",target:"_blank",rel:"noreferrer",className:"mt-1 inline-block text-primary underline underline-offset-4",children:"查看安装方法"}):null]})]})})}function tI({message:e}){return m.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-dashed px-4 text-center text-sm text-muted-foreground",children:e})}function Vde({target:e,selected:t,disabled:n,alreadyOpen:r,onClick:i}){const s=e.platform==="ios"?"iOS":"Android",o=`${e.model} · ${s} ${e.osVersion}`;return m.jsxs("button",{type:"button",className:Ye("flex min-h-16 w-full min-w-0 max-w-full items-center gap-3 overflow-hidden rounded-lg border px-3 py-2 text-left outline-none transition-colors",t?"border-primary bg-primary/5":"border-border hover:bg-accent",n&&"cursor-not-allowed opacity-55"),disabled:n,"aria-pressed":t,onClick:i,"data-slot":"device-preview-target","data-target-id":e.targetId,"data-already-open":r?"true":"false","data-interactive":e.interactive?"true":"false",children:[m.jsx(my,{className:"size-5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"block truncate text-sm font-medium",children:e.name}),m.jsx("span",{className:"mt-0.5 block truncate text-xs text-muted-foreground","data-slot":"device-preview-target-device","data-device-model":e.model,"data-os-version":e.osVersion,children:o})]}),r?m.jsx("span",{className:"text-xs text-muted-foreground",children:"已在预览"}):t?m.jsx(ia,{className:"size-4 text-primary","aria-hidden":"true"}):null]})}function V4({open:e,onOpenChange:t}){const[n,r]=b.useState(()=>e?"chooser":"closed"),i=b.useRef(null),s=mo("(min-width: 768px)");b.useLayoutEffect(()=>{if(e){n==="closed"&&r("chooser");return}n!=="closed"&&(i.current=n,r("closed"))},[e,n]);function o(){t(!1)}const l=m.jsxs("div",{className:"grid gap-2 pt-2","data-slot":"frontend-preview-options",children:[m.jsx(u0,{icon:m.jsx(rz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(u0,{icon:m.jsx(my,{className:"size-5","aria-hidden":"true"}),title:"iOS Simulator",description:"查看和操控开发机上已启动的 iPhone 或 iPad 模拟器",slot:"frontend-preview-ios",onClick:()=>r("ios")}),m.jsx(u0,{icon:m.jsx(my,{className:"size-5","aria-hidden":"true"}),title:"Android Emulator",description:"查看和操控开发机上已启动的 Android 模拟器",slot:"frontend-preview-android",onClick:()=>r("android")})]}),u=n==="closed"?i.current:n,d=e&&n!=="closed";switch(u){case"chooser":return s?m.jsx(Zi,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(Qi,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"新建预览"}),m.jsx(Ss,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(lc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(cc,{side:"bottom",className:"inset-x-2 w-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-frontend-preview-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(yu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(uc,{children:"新建预览"}),m.jsx(Db,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx($de,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(Wde,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function u0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(pt,{type:"button",variant:"outline",className:"h-auto min-h-[4.5rem] justify-start gap-3 px-4 py-3 text-left","data-slot":r,onClick:i,children:[m.jsx("span",{className:"text-muted-foreground",children:e}),m.jsxs("span",{className:"min-w-0",children:[m.jsx("span",{className:"block font-medium text-foreground",children:t}),m.jsx("span",{className:"mt-0.5 block whitespace-normal text-xs leading-5 text-muted-foreground",children:n})]})]})}function Yde({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Zi,{open:e!==null,onOpenChange:n,children:m.jsxs(Qi,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"停止预览?"}),m.jsx(Ss,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(pt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"device-preview-close-confirm",children:t?"正在停止...":"停止预览"})]})]})})}const Kde={ready:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"已连接"},disconnected:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已断开"}};function Gde({preview:e,selected:t,pendingOperation:n,onRename:r,onReconnect:i,onClose:s}){const o=Kde[e.state],l=n==="reconnect"?{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"正在重新连接",busy:!0}:n==="close"?{dot:"bg-muted-foreground animate-pulse",text:"text-muted-foreground",label:"正在停止",busy:!0}:o,u=e.state==="ready",d=e.state==="disconnected",f=e.platform==="ios"?"iOS":"Android",p=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[m.jsx("span",{className:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(my,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1 truncate text-muted-foreground","data-slot":"device-preview-row-device","data-device-model":e.model,"data-os-version":e.osVersion,children:[e.model," · ",f," ",e.osVersion]}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]})]});return m.jsxs("li",{className:Ye("relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent",t&&"bg-accent"),"data-slot":"device-preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":n,children:[u?m.jsx(cC,{to:`/preview/device/${e.previewId}`,className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring md:min-h-0","data-slot":"device-preview-row-open",children:p}):m.jsx("div",{className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:p}),m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"模拟器预览操作",disabled:n!==void 0,"data-slot":"device-preview-row-menu-trigger",children:l.busy||n==="rename"?m.jsx(oi,{className:"animate-spin","aria-hidden":"true"}):m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(Lr,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(Lr,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(zd,{}),m.jsx(Lr,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function Xde({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Zi,{open:e!==null,onOpenChange:n,children:m.jsxs(Qi,{"data-slot":"preview-close-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"关闭预览?"}),m.jsx(Ss,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(pt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function Zde({target:e,onOpenChange:t,onRename:n}){return m.jsx(Qde,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function Qde({target:e,onOpenChange:t,onRename:n}){const[r,i]=b.useState(()=>(e==null?void 0:e.name.trim())??""),[s,o]=b.useState(null),[l,u]=b.useState(!1),d=b.useRef((e==null?void 0:e.targetKey)??null);b.useLayoutEffect(()=>()=>{d.current=null},[]);function f(v){!v&&l||t(v)}async function p(v){v.preventDefault();const g=r.trim();if(!g){o("名称不能为空");return}if(!e||l)return;const _=e.targetKey;u(!0);try{if(await n(g),d.current!==_)return;t(!1)}catch(w){if(d.current!==_)return;o(w instanceof Error?w.message:String(w))}finally{d.current===_&&u(!1)}}return m.jsx(Zi,{open:e!==null,onOpenChange:f,children:m.jsx(Qi,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>void p(v),children:[m.jsx(Ji,{children:m.jsx(Fi,{children:"重命名预览"})}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"preview-rename-name",className:"text-sm font-medium",children:"预览名称"}),m.jsx("input",{id:"preview-rename-name",value:r,autoFocus:!0,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-invalid":!!s,"aria-describedby":s?"preview-rename-error":void 0,"data-slot":"preview-rename-input",className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",s&&"border-destructive focus-visible:ring-destructive/20"),disabled:l,onChange:v=>{i(v.target.value),s&&o(null)}}),s?m.jsx("p",{id:"preview-rename-error",className:"text-sm text-destructive",role:"alert",children:s}):null]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(pt,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const Jde={starting:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"正在创建",busy:!0},ready:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"可访问"},failed:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"连接失败"},disconnected:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已断开"},stopping:{dot:"bg-muted-foreground animate-pulse",text:"text-muted-foreground",label:"正在关闭",busy:!0}};function efe(e){return e.source.kind==="local"?e.source.url:ab(e.source.rootPath,e.source.entryPath)}async function tfe(e){if(await Pp(e,{allowUserGestureFallback:!0})==="failed"){qe.error("复制失败,请稍后重试");return}qe.success("链接已复制")}async function nfe(e,t){if(typeof navigator.share=="function")try{await navigator.share({title:e,url:t})}catch(n){if(n instanceof DOMException&&n.name==="AbortError")return;qe.error("无法打开系统分享面板")}}function rfe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=Vr(w=>w.homePath),o=Jde[e.state],l=t==="reconnect"?{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"正在重新连接",busy:!0}:t==="close"?{dot:"bg-muted-foreground animate-pulse",text:"text-muted-foreground",label:"正在关闭",busy:!0}:o,u=e.state==="ready"?e.publicUrl:null,d=u!==null,f=e.state==="failed"||e.state==="disconnected",p=d&&typeof navigator<"u"&&typeof navigator.share=="function",v=efe(e),g=e.source.kind==="static"?om(v,s):v,_=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx("span",{className:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(rz,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground",title:v,children:g}),m.jsx("span",{className:"shrink-0 text-muted-foreground/60","aria-hidden":"true",children:"·"}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]}),e.state==="failed"?m.jsx("span",{"data-slot":"preview-row-error",className:"truncate text-xs text-destructive/90",title:e.error,children:e.error}):null]});return m.jsxs("li",{className:"relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent","data-slot":"preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":t,children:[d?m.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer","data-slot":"preview-row-open",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring md:min-h-0",children:_}):m.jsx("div",{"data-slot":"preview-row-inactive","aria-disabled":"true",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:_}),m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"预览操作","data-slot":"preview-row-menu-trigger",disabled:e.state==="stopping"||t!==void 0,children:l.busy||t==="rename"?m.jsx(oi,{className:"animate-spin","aria-hidden":"true"}):m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(Lr,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(Lr,{"data-slot":"preview-row-copy-item",onSelect:()=>void tfe(u),children:"复制链接"}):null,p?m.jsx(Lr,{"data-slot":"preview-row-share-item",onSelect:()=>void nfe(e.name,u),children:"分享…"}):null,f?m.jsx(Lr,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(zd,{}),m.jsx(Lr,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const ife=Object.freeze([]),sfe=Object.freeze([]);function sd(e,t,n){return Object.freeze({kind:e,previewId:t,scope:Object.freeze({proxyId:n.proxyId,bindingId:n.bindingId})})}function Ic(e,t){return e!==null&&e.kind===t.kind&&e.previewId===t.previewId&&Qt(e.scope,t.scope)}function rp(e,t,n){return t!==null&&n!==void 0&&Qt(e.scope,t)&&Qt(e.scope,n)}function kh(e){const t=Rt.getActiveScope(),n=e.kind==="web"?Ur.getState().authoritative:dr.getState().authoritative;return!n||!rp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function zo(e){const t=Rt.getActiveScope();return t!==null&&Qt(t,e)}function nI(){const e=Ur(A=>A.authoritative),t=dr(A=>A.authoritative),n=Vo(A=>A.registry),r=Rt.getActiveScope(),i=r&&e&&Qt(r,e.scope)?e.scope:null,s=r&&t&&Qt(r,t.scope)?t.scope:null,o=i&&e?e.previews:ife,l=s&&t?t.previews:sfe,u=$B("/preview/device/:id"),d=Es(),[f,p]=b.useState(null),[v,g]=b.useState(null),_=(v==null?void 0:v.kind)==="web"&&rp(v,r,e==null?void 0:e.scope)?o.find(A=>A.previewId===v.previewId)??null:null,w=(v==null?void 0:v.kind)==="device"&&rp(v,r,t==null?void 0:t.scope)?l.find(A=>A.previewId===v.previewId)??null:null,S=_??w,x=(f==null?void 0:f.kind)==="web"&&rp(f,r,e==null?void 0:e.scope)?o.find(A=>A.previewId===f.previewId)??null:null,R=(f==null?void 0:f.kind)==="device"&&rp(f,r,t==null?void 0:t.scope)?l.find(A=>A.previewId===f.previewId)??null:null;b.useEffect(()=>{v&&!S&&g(A=>Ic(A,v)?null:A),f&&!x&&!R&&p(A=>Ic(A,f)?null:A)},[f,R,v,S,x]);function k(A,L,D){var I;return(I=zj(n,A,L,D)[0])==null?void 0:I.kind}if(o.length===0&&l.length===0)return null;async function N(A){if(kh(A))try{const L=await Rt.reconnectWebPreview(A.scope,A.previewId);if(!zo(A.scope))return;L.success||qe.error(L.error)}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function M(A,L){if(!kh(A))return;let D;try{D=A.kind==="web"?await Rt.renameWebPreview(A.scope,A.previewId,L):await Rt.renameDevicePreview(A.scope,A.previewId,L)}catch(I){if(!zo(A.scope))return;throw I}if(zo(A.scope)&&!D.success)throw new Error(D.error)}async function T(A){if(kh(A))try{const L=await Rt.closeWebPreview(A.scope,A.previewId);if(!zo(A.scope))return;if(!L.success){qe.error(L.error);return}p(D=>Ic(D,A)?null:D)}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function P(A){if(kh(A))try{const L=await Rt.reconnectDevicePreview(A.scope,A.previewId);if(!zo(A.scope))return;L.success||qe.error(L.error)}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(A){if(kh(A))try{const L=await Rt.closeDevicePreview(A.scope,A.previewId);if(!zo(A.scope))return;if(!L.success){qe.error(L.error);return}p(D=>Ic(D,A)?null:D),(u==null?void 0:u.params.id)===A.previewId&&d("/sessions")}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const V=(f==null?void 0:f.kind)==="web"&&k(f.scope,"web",f.previewId)==="close",U=(f==null?void 0:f.kind)==="device"&&k(f.scope,"device",f.previewId)==="close",G=v,O=f;return m.jsxs("section",{"data-slot":"preview-section","aria-labelledby":"preview-section-title",children:[m.jsxs("h3",{id:"preview-section-title",className:"px-4 pb-2 pt-3 text-sm font-semibold text-foreground",children:["预览",m.jsxs("span",{className:"ml-1 font-normal text-muted-foreground/70",children:["· ",o.length+l.length]})]}),m.jsxs("ul",{role:"list",className:"flex w-full min-w-0 flex-col",children:[o.map(A=>m.jsx(rfe,{preview:A,pendingOperation:i?k(i,"web",A.previewId):void 0,onRename:()=>i&&g(sd("web",A.previewId,i)),onReconnect:()=>i&&void N(sd("web",A.previewId,i)),onClose:()=>i&&p(sd("web",A.previewId,i))},A.previewId)),l.map(A=>m.jsx(Gde,{preview:A,selected:(u==null?void 0:u.params.id)===A.previewId,pendingOperation:s?k(s,"device",A.previewId):void 0,onRename:()=>s&&g(sd("device",A.previewId,s)),onReconnect:()=>s&&void P(sd("device",A.previewId,s)),onClose:()=>s&&p(sd("device",A.previewId,s))},A.previewId))]}),m.jsx(Zde,{target:G&&S?{targetKey:`${G.kind}\0${G.scope.proxyId}\0${G.scope.bindingId}\0${G.previewId}`,name:S.name}:null,onOpenChange:A=>{!A&&G&&g(L=>Ic(L,G)?null:L)},onRename:A=>G?M(G,A):Promise.resolve()}),m.jsx(Xde,{preview:x,closing:V,onOpenChange:A=>{!A&&!V&&O&&p(L=>Ic(L,O)?null:L)},onConfirm:()=>O&&void T(O)}),m.jsx(Yde,{preview:R,closing:U,onOpenChange:A=>{!A&&!U&&O&&p(L=>Ic(L,O)?null:L)},onConfirm:()=>O&&void z(O)})]})}function Y4({layout:e}){const t=Gt(ie=>ie.sessions),n=Gt(ie=>ie.sessionListLoaded),r=Gt(ie=>ie.agentStatusBySessionId),i=Gt(ie=>ie.ptyStateBySessionId),s=Gt(ie=>ie.renameSession),o=dn(ie=>ie.bySessionId),l=$B("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Te(ie=>!!ie.selectedProxyId),f=Te(ie=>ie.proxyListLoaded),p=Te(ie=>ie.proxySwitchTarget),v=Gt(ie=>ie.loadingProxyName),g=p!==null||!f||d&&!n,_=(p==null?void 0:p.name)??v,w=_?`正在连接 ${_}...`:"连接中...",S=Es(),[x,R]=b.useState(!1),[k,N]=b.useState(!1),[M,T]=b.useState(!1),[P,z]=b.useState(!1),[V,U]=b.useState(null),[G,O]=b.useState(null),{creatingTerminal:A,creatingShell:L,createTerminal:D}=K4(),[I,B]=b.useState(new Set),[F,Y]=b.useState(()=>Date.now());b.useEffect(()=>{const ie=setInterval(()=>Y(Date.now()),6e4);return()=>clearInterval(ie)},[]);function j(ie,le){S(`/chat/${ie}?mode=${le}`,{replace:!1})}function q(ie){const le=ie.sessionId,be=Ft;if(!be){qe.error("请先连接开发机");return}be.sendControl({type:"session_terminate",sessionId:le}),Gt.getState().removeSession(le),dn.getState().clearSession(le),le===u&&S("/sessions"),(ie==null?void 0:ie.kind)==="agent"&&ie.mode==="pty"&&ie.ptyOwner==="local-terminal"?qe.info("已断开页面连接,本地终端仍在运行"):qe.info("正在终止会话",{duration:1500})}async function K(ie,le){const be=Ft;if(!be)throw new Error("请先连接开发机");const Le=await be.renameSession(ie,le);if(!Le.success)throw new Error(Le.error??"重命名失败");s(ie,Le.name??le),qe.success("已重命名会话")}function $(ie){B(le=>{const be=new Set(le);return be.has(ie)?be.delete(ie):be.add(ie),be})}function ne(ie){var Le;const le=ie.mode==="json"&&(((Le=o[ie.sessionId])==null?void 0:Le.pendingApprovals.some(he=>he.status==="pending"))??!1),be=Bde({session:ie,agentStatus:r[ie.sessionId],ptyState:i[ie.sessionId],hasPendingApproval:le});return be===ie.state?ie:{...ie,state:be}}const J=t.length>0;if(e==="sidebar"&&(g||!d))return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":g?"session-list-loading":void 0,role:g?"status":void 0,"aria-live":g?"polite":void 0,children:g?w:"请先连接开发机"}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]});if(e==="page"&&g)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[m.jsx(oi,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsx("div",{className:"flex-1",children:m.jsx(Yc,{variant:"no-proxy"})}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]});const te=m.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",J?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),Q=J?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:ofe(t).map(ie=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>$(ie.provider),"aria-expanded":!I.has(ie.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:afe(ie.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:ie.sessions.length}),m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!I.has(ie.provider)&&"rotate-90"),"aria-hidden":"true"})]}),I.has(ie.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:ie.sessions.map(le=>m.jsx(gde,{session:ne(le),selected:le.sessionId===u,now:F,onClick:()=>j(le.sessionId,le.mode),onRename:()=>U(le),onTerminate:()=>O(le)},le.sessionId))})]},ie.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),ce=m.jsx(_de,{now:F});return e==="page"?m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[te,Q,m.jsx(nI,{}),ce]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(pt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>N(!0),children:[m.jsx(tz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(ffe,{open:k,creatingTerminal:A,onOpenChange:N,onCreateAgent:()=>{N(!1),R(!0)},onCreateTerminal:()=>{G4()?(N(!1),T(!0)):D(void 0,()=>N(!1))},onCreatePreview:()=>{N(!1),z(!0)}}),m.jsx(X4,{layout:"mobile",open:M,creatingTerminal:A,creatingShell:L,onOpenChange:T,onBack:()=>{T(!1),N(!0)},onCreate:ie=>void D(ie,()=>T(!1))}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(V4,{open:P,onOpenChange:z}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[te,Q,m.jsx(nI,{}),ce]}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]})}function ofe(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])=>lfe(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function afe(e){return e==="terminal"?"终端":Bb(e)}function lfe(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:L4(e,t)}function K4(){const e=Es(),[t,n]=b.useState(null),r=t!==null;async function i(s,o){var u;const l=Te.getState();if(!(r||!l.connected||!l.proxyOnline||!l.selectedProxyId||l.proxySwitchTarget)&&!yk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await Mde({relay:Ft,shell:s});if(d.type!=="success"){qe.error(d.message);return}Gt.getState().addSession(d.session),o==null||o(),e(d.route)}finally{n(null)}}}return{creatingTerminal:r,creatingShell:t,createTerminal:i}}function yk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function cfe(e){const t=Te(u=>u.terminalShells),n=Te(yk),r=Te(u=>u.selectedProxyId),[i,s]=b.useState(!1),[o,l]=b.useState(0);return b.useEffect(()=>{if(!e||!n)return;let u=!1;const d=Ft,f=d==null?void 0:d.getPreviewScope();if(s(!1),!d||!f||f.proxyId!==r){s(!0);return}return d.requestProxyInfo().then(p=>{const v=Te.getState(),g=d.getPreviewScope();u||!v.connected||!v.proxyOnline||v.selectedProxyId!==r||!g||!Qt(f,g)||v.setTerminalShells(p.terminalShells)},()=>{u||s(!0)}),()=>{u=!0}},[e,n,r,o]),{terminalShells:t,needsDetection:n,failed:i,retry:()=>l(u=>u+1)}}const ufe=[{label:"启动 Shell"}];function dfe(e){return e!=null&&e.length?e:ufe}function G4(){var t;const e=Te.getState();return yk(e)||!!((t=e.terminalShells)!=null&&t.length)}function rI({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),[s,o]=b.useState(!1),[l,u]=b.useState(!1),[d,f]=b.useState(!1),p=b.useRef(!1),v=Te(V=>!!V.selectedProxyId),g=Te(V=>V.proxySwitchTarget!==null),_=v&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=K4();function R(){f(!0),window.setTimeout(()=>f(!1),2e3)}function k(){if(!_){R();return}p.current=!0,o(!0)}function N(){if(!_){R();return}p.current=!0,G4()?i(!0):x()}function M(){if(!_){R();return}p.current=!0,u(!0)}function T(V){V.preventDefault(),R()}const P=m.jsxs(pt,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!_&&"opacity-50 hover:bg-background"),"aria-label":"新建","aria-disabled":!_,onClick:_?void 0:T,children:[m.jsx(tz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),z=_?m.jsxs(hf,{open:t,onOpenChange:n,children:[m.jsx(pf,{asChild:!0,children:P}),m.jsxs(mf,{align:e?"end":"start",className:"w-80","data-slot":"create-session-type-menu",onCloseAutoFocus:V=>{p.current&&(p.current=!1,V.preventDefault())},children:[m.jsxs(Lr,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:k,children:[m.jsx(JB,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(Lr,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:w,onSelect:N,children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),w?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx(zd,{}),m.jsxs(Lr,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:M,children:[m.jsx(hC,{className:"mt-0.5 size-4 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"flex items-center gap-1.5 font-medium",children:"预览"}),m.jsx("span",{className:"mt-0.5 block text-xs leading-4 text-muted-foreground",children:"在浏览器中预览网页或设备模拟器"})]})]})]})]}):P;return m.jsxs(m.Fragment,{children:[_?z:m.jsxs(gf,{open:_?void 0:d,onOpenChange:_?void 0:f,children:[m.jsx(vf,{asChild:!0,children:z}),m.jsx(yf,{side:"top",children:g?"正在切换开发机":"请先连接开发机"})]}),m.jsx(X4,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:V=>void x(V,()=>i(!1))}),m.jsx(tp,{open:s,onOpenChange:o}),m.jsx(V4,{open:l,onOpenChange:u})]})}function ffe({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i,onCreatePreview:s}){const o=b.useRef(!1);function l(u){o.current=!0,u()}return m.jsx(lc,{open:e,onOpenChange:n,children:m.jsxs(cc,{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:u=>{o.current&&(o.current=!1,u.preventDefault())},children:[m.jsx(yu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(uc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(pt,{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:()=>l(r),children:[m.jsx(JB,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(pt,{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:()=>l(i),children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx("div",{className:"mx-1 h-px bg-border","aria-hidden":"true"}),m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-16 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-frontend-preview-sheet-item",onClick:()=>l(s),children:[m.jsx(hC,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0",children:[m.jsx("span",{className:"flex items-center gap-1.5 font-medium",children:"预览"}),m.jsx("span",{className:"mt-0.5 block text-xs leading-4 text-muted-foreground",children:"在浏览器中预览网页或设备模拟器"})]})]})]})]})})}function X4({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=cfe(t),p=b.useRef(!1),v=Te(w=>w.connected&&w.proxyOnline&&!!w.selectedProxyId&&!w.proxySwitchTarget),g=m.jsxs("div",{className:"grid gap-2","data-slot":"terminal-shell-options",children:[u?m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"terminal-shell-detection",disabled:!d,onClick:f,children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"终端检测失败,点击重试":"正在检测终端..."]}):dfe(l).map(w=>m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"terminal-shell-option","data-shell":w.id,disabled:n||!v,onClick:()=>o(w.id),children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),r===(w.id??"default")?"正在创建 Shell 会话...":w.label]},w.id??"default")),m.jsx("div",{className:"mx-1 h-px bg-border","aria-hidden":"true"}),m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-11 justify-start gap-3 px-3 text-muted-foreground",disabled:n,onClick:()=>{p.current=!0,s()},children:[m.jsx(sf,{className:"size-4","aria-hidden":"true"}),"返回"]})]});function _(w){p.current&&(p.current=!1,w.preventDefault())}return e==="mobile"?m.jsx(lc,{open:t,onOpenChange:i,children:m.jsxs(cc,{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-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(yu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(uc,{children:"Shell 会话"})}),g]})}):m.jsx(Zi,{open:t,onOpenChange:i,children:m.jsxs(Qi,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(Ji,{children:m.jsx(Fi,{children:"Shell 会话"})}),g]})})}const hfe="0.9.8",pfe={version:hfe},mfe={playback:"playback",capture:"play-and-record"};function gfe(){return typeof navigator>"u"?null:navigator.audioSession??null}function vfe(){return{setMode:()=>{},release:()=>{}}}class yfe{constructor(t=gfe){je(this,"leases",new Map);je(this,"session",null);je(this,"baselineType",null);je(this,"nextLeaseId",1);je(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return vfe();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(mfe[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 bk=new yfe,x1=64,iI=-60,Z4=32;function sI(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-iI)/-iI));return e<0?-r:r}function oI(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,f=-1;for(let p=l;p<u;p+=1){const v=i.getInt16(p*2,!0)/32768;d=Math.min(d,v),f=Math.max(f,v)}s.push({min:d,max:f})}return s}function bfe(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 _fe(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 Q4{constructor(t,n=24e3,r={}){je(this,"nextStartTime",0);je(this,"activityEndToken",0);je(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=bfe(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*Z4/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,f=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),v=_fe(n.subarray(l,u));this.scheduleTimer(()=>{var g,_,w,S;(_=(g=this.options).onActivityLevel)==null||_.call(g,v),(S=(w=this.options).onPlaybackChunk)==null||S.call(w,p)},f)}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 d0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},aI="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",wfe=800,lI=300,xfe=1600;function S1(e,t){return e.filter(n=>!n.model||n.model===t)}function cI({label:e,children:t,help:n}){return m.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:[m.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.jsx("div",{className:"mt-2 min-w-0",children:t}),n?m.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function uv({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=b.useState(!1),u=b.useId(),d=n.find(g=>g.value===t),f=(d==null?void 0:d.label)??(t||i),p=n.filter(g=>!g.disabled),v=!!J4(f).detail;return m.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:[m.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.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 ${v?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[m.jsx(uI,{label:f,muted:!d&&!t}),m.jsx(ec,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?m.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 _=g.value===t;return m.jsxs("button",{type:"button",role:"option","aria-label":g.label,"aria-selected":_,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:[m.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?m.jsx(ia,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(uI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function uI({label:e,muted:t=!1}){const n=J4(e);return m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?m.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Sfe({scrollRef:e}={}){const[t,n]=b.useState(d0),[r,i]=b.useState(String(d0.turnIdleSeconds)),[s,o]=b.useState(()=>Gg()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[p,v]=b.useState(!1),[g,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),R=b.useRef(null),k=b.useRef(null),N=b.useRef(!1);b.useEffect(()=>{const Q=Ft;if(!Q){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce=!1;return _({kind:"loading"}),Q.requestVoiceConfig().then(ie=>{if(!ce){if(ie.error||!ie.config){_({kind:"error",message:ie.error??"读取语音设置失败"});return}n(ie.config),i(String(ie.config.turnIdleSeconds)),u(""),f(!1),v(!0),_({kind:"idle"})}}).catch(ie=>{ce||_({kind:"error",message:ie instanceof Error?ie.message:"读取语音设置失败"})}),()=>{ce=!0}},[]),b.useEffect(()=>{const Q=Ft;if(!Q||!p)return;let ce=!1;return Q.requestVoiceCapabilities({region:t.region}).then(ie=>{if(!ce){if(ie.error||!ie.capabilities){o(Gg());return}o(ie.capabilities)}}).catch(()=>{ce||o(Gg())}),()=>{ce=!0}},[t.region,p]),b.useEffect(()=>(N.current=!0,()=>{N.current=!1,$(),ne()}),[]);const M=b.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]),T=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",P=b.useMemo(()=>S1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),V=P.some(Q=>Q.value===t.ttsVoice)?t.ttsVoice:"",U=P.length===0?"当前模型暂无可用音色":V?null:"请选择可用音色",G=b.useMemo(()=>Tfe(r),[r]),O=G?null:"请输入正整数秒数",A=U??O,L=T||!!A,D=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),I=b.useMemo(()=>hI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),B=b.useMemo(()=>Rfe(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>hI(P,V),[P,V]);function Y(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:G??d0.turnIdleSeconds}}async function j(){if(T)return;if(A){_({kind:"error",message:A});return}const Q=Ft;if(!Q){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ce=Y();ne(),_({kind:"saving"});const ie=performance.now();try{const le=await Q.updateVoiceConfig(ce);if(!N.current)return;const be=performance.now()-ie;if(be<lI&&await kfe(lI-be),!N.current)return;if(!le.success||le.error||!le.config){_({kind:"error",message:le.error??"保存语音设置失败"});return}n(le.config),i(String(le.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),k.current=setTimeout(()=>{k.current=null,_(Le=>Le.kind==="saved"?{kind:"idle"}:Le)},xfe),Q.requestVoiceCapabilities({region:le.config.region}).then(Le=>{N.current&&Le.capabilities&&o(Le.capabilities)}).catch(()=>{N.current&&o(Gg())})}catch(le){if(!N.current)return;_({kind:"error",message:le instanceof Error?le.message:"保存语音设置失败"})}}async function q(){if(T)return;if(A){_({kind:"error",message:A});return}const Q=Ft;if(!Q){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce;try{ce=K()}catch(ie){_({kind:"error",message:fI(ie)});return}_({kind:"testing"});try{const[ie]=await Promise.all([Q.testVoiceConfig(Y()),ce.ready]);if(!ie.success||ie.error){$(),_({kind:"error",message:ie.error??"语音配置测试失败"});return}const le=await J(ie,ce.context);_({kind:"playingTest",transcript:ie.transcript}),R.current=setTimeout(()=>{R.current=null,$(),_({kind:"testPassed",transcript:ie.transcript})},le)}catch(ie){$(),_({kind:"error",message:fI(ie)})}}function K(){$();const Q=bk.acquire("playback");S.current=Q;try{const ce=Cfe();return w.current=ce,{context:ce,ready:dI(ce)}}catch(ce){throw Q.release(),S.current=null,ce}}function $(){var Q,ce,ie;R.current&&(clearTimeout(R.current),R.current=null),(Q=x.current)==null||Q.stop(),x.current=null,(ce=w.current)==null||ce.close(),w.current=null,(ie=S.current)==null||ie.release(),S.current=null}function ne(){k.current&&(clearTimeout(k.current),k.current=null)}async function J(Q,ce){if(!Q.audioBase64)throw new Error("语音测试未返回可播放音频");if(Q.audioEncoding&&Q.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ie=Q.audioSampleRate??24e3,le=Efe(Q.audioBase64);if(le.byteLength===0||le.byteLength%2!==0)throw new Error("测试音频数据无效");await dI(ce);const be=new Q4(ce,ie);x.current=be,be.enqueue(le);const Le=Math.ceil(le.byteLength/2/ie*1e3);return Math.max(wfe,Le)}function te(Q){var ce;return((ce=S1(s.ttsVoices,Q)[0])==null?void 0:ce.value)??""}return m.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:Q=>{Q.preventDefault(),j()},children:[m.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:m.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:m.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[m.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsxs("div",{className:"min-w-0",children:[m.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),m.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),m.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"})]})}),m.jsx(cI,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:m.jsxs("div",{className:"flex min-w-0 gap-2",children:[m.jsxs("div",{className:"relative min-w-0 flex-1",children:[m.jsx(sz,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),m.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:Q=>{u(Q.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${aI} w-full pl-9`})]}),t.configured&&m.jsxs(pt,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),f(!0)},children:[m.jsx(dz,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(uv,{label:"地域",value:t.region,options:D,onChange:Q=>n(ce=>({...ce,region:Q==="intl"?"intl":"cn"}))}),m.jsx(uv,{label:"语音识别模型",value:t.asrModel,options:I,onChange:Q=>n(ce=>({...ce,asrModel:Q}))}),m.jsx(uv,{label:"语音合成模型",value:t.ttsModel,options:B,onChange:Q=>n(ce=>({...ce,ttsModel:Q,ttsVoice:te(Q)}))}),m.jsx(uv,{label:"语音音色",value:V,options:F,placeholder:P.length===0?"暂无可用音色":"请选择音色",onChange:Q=>n(ce=>({...ce,ttsVoice:Q})),help:U}),m.jsx(cI,{label:"结束停顿时间(秒)",help:O,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:Q=>i(Q.target.value),className:`${aI} w-full`})})]})})}),m.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[m.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),m.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[M?m.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:M}):null,m.jsxs(pt,{type:"button",variant:"outline",disabled:L,onClick:()=>void q(),children:[m.jsx(lz,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(pt,{type:"submit",disabled:L,children:[m.jsx(NY,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Efe(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 Cfe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function dI(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function fI(e){return e instanceof Error?e.message:"语音配置测试失败"}function kfe(e){return new Promise(t=>setTimeout(t,e))}function Tfe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function hI(e,t){const n=e.map(r=>({value:r.value,label:eF(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Rfe(e,t,n){const r=e.map(i=>{const s=S1(t,i.value).length===0;return{value:i.value,label:`${eF(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function J4(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 eF(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 Afe=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Nfe=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],_k="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function tF(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 Mfe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Pfe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Ife(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function E1({open:e,onOpenChange:t}){const n=Te(G=>G.relayUrl),r=Te(G=>G.latencyMonitorEnabled),i=Te(G=>G.setLatencyMonitorEnabled),s=Te(G=>G.sessionIdleNotificationsEnabled),o=Te(G=>G.setSessionIdleNotificationsEnabled),l=Te(G=>G.inputModePreference),u=Te(G=>G.setInputModePreference),d=Te(G=>G.themePreference),f=Te(G=>G.setThemePreference),p=Te(G=>G.ptyScrollTraceEnabled),v=Te(G=>G.setPtyScrollTraceEnabled),[g,_]=b.useState("menu"),[w,S]=b.useState(e),[x,R]=b.useState({kind:"idle"}),k=b.useRef(null),N=b.useRef(null),M=sse(),T=b.useMemo(()=>af().osName==="iPad",[]);e!==w&&(S(e),e&&_("menu"));const P=b.useCallback(async G=>{if(!G){o(!1);return}const O=await Nie();if(O==="granted"){o(!0);return}if(O==="denied"){qe.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(O==="default"){qe.info("未授予通知权限,会话通知保持关闭");return}qe.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{R({kind:"loading"});try{const O=await fetch(Mfe(n),{cache:"no-store",signal:G});if(!O.ok)throw new Error(`HTTP ${O.status}`);const A=await O.json();if(A.status!=="ok")throw new Error("状态异常");R({kind:"ready",version:A.version??"未知",uptime:A.uptime??0})}catch(O){if(O instanceof DOMException&&O.name==="AbortError")return;R({kind:"error",message:O instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e||g!=="version")return;const G=new AbortController;return z(G.signal),()=>G.abort()},[z,e,g]),b.useEffect(()=>{if(!e||g!=="voice")return;const G=window.requestAnimationFrame(()=>{var O;(O=k.current)==null||O.focus({preventScroll:!0}),N.current&&(N.current.scrollTop=0)});return()=>window.cancelAnimationFrame(G)},[e,g]);const V=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",U=x.kind==="ready"?`运行 ${tF(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(Zi,{open:e,onOpenChange:t,children:m.jsxs(Qi,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",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:k,showCloseButton:g==="menu",children:[m.jsx(Ji,{className:Ye(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"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(pt,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>_("menu"),children:m.jsx(sf,{className:"size-4","aria-hidden":"true"})}),m.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[m.jsx(Fi,{children:Pfe(g)}),m.jsx(Ss,{className:"max-w-[28rem] leading-5",children:Ife(g)})]})]}),g==="voice"?m.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):m.jsxs(m.Fragment,{children:[m.jsx(Fi,{children:"设置"}),m.jsx(Ss,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(Ofe,{relayVersion:V,relayDetail:U,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(Dfe,{saved:M}):g==="clients"?m.jsx($fe,{}):g==="voice"?m.jsx(Sfe,{scrollRef:N}):m.jsx(Lfe,{relayTokenSaved:M,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:T,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:P,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:v,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function Ofe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:_k,"data-slot":"settings-dialog-body",children:[m.jsx(mI,{icon:m.jsx(az,{className:"size-4","aria-hidden":"true"}),label:"Web",value:pfe.version,detail:"当前浏览器加载的版本"}),m.jsx(mI,{icon:m.jsx(cz,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Lfe({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:f,onLatencyMonitorEnabledChange:p,onOpenVoice:v,onOpenRelayToken:g,onOpenClients:_,onOpenVersion:w}){return m.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:[m.jsxs(od,{title:"服务",children:[m.jsx(dv,{icon:m.jsx(nV,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:v}),m.jsx(dv,{icon:m.jsx(sz,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(dv,{icon:m.jsx(QY,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(od,{title:"外观",children:m.jsx(pI,{icon:m.jsx($Y,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Afe,onValueChange:n})}),m.jsx(od,{title:"通知",children:m.jsx(h0,{icon:m.jsx(iV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(od,{title:"交互",children:m.jsx(pI,{icon:m.jsx(oz,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Nfe,onValueChange:i})}):null,m.jsxs(od,{title:"高级诊断",children:[m.jsx(h0,{icon:m.jsx(Zc,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(h0,{icon:m.jsx(ZB,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:p})]}),m.jsx(od,{title:"关于",children:m.jsx(dv,{icon:m.jsx(cz,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function od({title:e,children:t}){return m.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[m.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),m.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function pI({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return m.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,m.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 m.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Dfe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{Jj().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!Zj(f)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),qe.error(p);return}o(null),qe.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{Qj(),l()};return m.jsxs("form",{className:_k,"data-slot":"settings-dialog-body",onSubmit:f=>{f.preventDefault(),u()},children:[m.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[m.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),m.jsx("input",{id:t,type:"password",value:r,onChange:f=>{i(f.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?m.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),m.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?m.jsx(pt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(pt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Bfe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function zfe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Bfe(e)}function jfe(e){return wne(e)}function Ffe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return tF(t)}function f0({label:e,value:t,title:n}){return m.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[m.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),m.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function $fe(){const e=Te(v=>v.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(v=>[v.proxyId,v.name]).filter(v=>typeof v[1]=="string")),[e]),f=b.useCallback(async()=>{const v=Ft;if(!v){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await v.requestRelayClients())}catch(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{f()},[f]);const p=b.useCallback(async v=>{const g=Ft;if(!g){o("Relay 未连接。");return}u(v),o(null);try{const _=await g.kickRelayClient(v);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==v))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:_k,"data-slot":"settings-dialog-body",children:[m.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),m.jsx(pt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(nm,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?m.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?m.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(v=>{const g=v.current===!0,_=l===v.clientId;return m.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":v.clientId,title:`客户端 ${v.clientId}`,children:m.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[m.jsxs("div",{className:"min-w-0 space-y-1.5",children:[m.jsx("div",{className:"min-w-0",children:m.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:jfe(v)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(f0,{label:"已连接",value:Ffe(v.connectedAt)}),v.proxyId?m.jsx(f0,{label:"连接到",value:zfe(v.proxyId,d),title:v.proxyId}):null,v.remoteAddress?m.jsx(f0,{label:"来源 IP",value:v.remoteAddress}):null]})]}),g?m.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:"当前设备"}):m.jsxs(pt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void p(v.clientId),"data-slot":"relay-client-action",children:[m.jsx(rY,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},v.clientId)})]})}function h0({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return m.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:[m.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),m.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),m.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function dv({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return m.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:[m.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}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),m.jsx(pp,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function mI({icon:e,label:t,value:n,detail:r,muted:i=!1}){return m.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[m.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[m.jsx("div",{className:"text-sm text-muted-foreground",children:t}),m.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const Hfe="xterm-helper-textarea";function Ufe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Hfe)?!1:(e.blur(),!0)}function gI(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&&Wfe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Wfe(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 qfe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Ufe()},[e]),i=b.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=b.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const f=(n.current??u.clientY)-u.clientY;n.current=u.clientY,gI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(gI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Vfe({className:e}){const t=Te(o=>o.sidebarCollapsed),n=Te(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=qfe();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(yI,{collapsed:!0,onClick:n}),m.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),m.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[m.jsx(vI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(rI,{compact:!0})]})]}),m.jsx(E1,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[m.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:m.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx(Az,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(yI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(O4,{layout:"dropdown",variant:"sidebarChrome"})})]})}),m.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:m.jsx("div",{className:"flex-1 min-h-0",children:m.jsx(Y4,{layout:"sidebar"})})}),m.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:[m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(rI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(vI,{onClick:()=>i(!0)})})]})]}),m.jsx(E1,{open:r,onOpenChange:i})]})}function vI({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(gf,{delayDuration:500,children:[m.jsx(vf,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(uz,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(yf,{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 yI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?gY:pY;return m.jsxs(gf,{delayDuration:500,children:[m.jsx(vf,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(yf,{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 Yfe=1500,Kfe=300,bI=70,_I=35;function nF({texts:e,className:t}){const[n,r]=b.useState(""),[i,s]=b.useState(!0),o=b.useRef("typing"),l=b.useRef(0),u=b.useRef(0);b.useEffect(()=>{const f=setInterval(()=>s(p=>!p),530);return()=>clearInterval(f)},[]),b.useEffect(()=>{let f;const p=()=>e[u.current%e.length],v=()=>{const g=o.current;if(g==="typing"){const _=p();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(v,bI)):(o.current="paused",f=setTimeout(v,Yfe))}else g==="paused"?(o.current="deleting",f=setTimeout(v,_I)):g==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),f=setTimeout(v,_I)):(u.current+=1,o.current="waiting",f=setTimeout(v,Kfe)):(o.current="typing",f=setTimeout(v,bI))};return f=setTimeout(v,500),()=>clearTimeout(f)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return m.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[m.jsx("span",{className:"text-green-500",children:"> "}),m.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),m.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),m.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const rF=["DEV Anywhere","/unlimited @anytime"];function Gfe({subtitle:e,action:t}){return m.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:m.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[m.jsx(nF,{texts:rF,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),e?m.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}):null,t?m.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Xfe=3e3,Zfe=1e4,fv=12,Qfe=4,wI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Jfe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function p0(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 ad(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function ip(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function xI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function iF(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function ehe(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 the(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?ip(e.rttMs):"等待检测"}function nhe(){const e=Ci("local",Sn.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 SI(e){Tr("local",Sn.latencyMonitorPosition,JSON.stringify(e))}function rhe(){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 m0(e,t){const n=rhe(),r=fv,i=fv,s=Math.max(r,n.width-t.width-fv),o=Math.max(i,n.height-t.height-fv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function ihe(){const e=Te(T=>T.latencyMonitorEnabled),t=Te(T=>T.connected),n=Te(T=>T.proxyOnline),r=Te(T=>T.selectedProxyId),[i,s]=b.useState(Jfe),[o,l]=b.useState(()=>nhe()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),p=b.useRef(!1),v=b.useMemo(()=>(Object.values(i).sort((T,P)=>xI(P.state)-xI(T.state))[0]??{state:"idle"}).state,[i]),g=iF(v);async function _(){if(u.current)return;const T=Ft;if(!T||!t){const U=ad("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:ad("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:ad("未连接开发机")}));const[P,z,V]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:P.status==="fulfilled"?p0(P.value):ad(P.reason instanceof Error?P.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?p0(z.value):ad(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:V.status==="fulfilled"?p0(V.value):ad(V.reason instanceof Error?V.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,P=null;const z=async()=>{await _(),!T&&(P=setTimeout(z,document.hidden?Zfe:Xfe))};return z(),()=>{T=!0,u.current=!1,P&&clearTimeout(P)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const P=T.getBoundingClientRect(),z=m0(o,{width:P.width,height:P.height});z.x===o.x&&z.y===o.y||(l(z),SI(z))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,S=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(T){var z,V;if(T.button!==0)return;const P=T.currentTarget.getBoundingClientRect();f.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:P.left,originY:P.top,width:P.width,height:P.height,dragging:!1},(V=(z=T.currentTarget).setPointerCapture)==null||V.call(z,T.pointerId)}function R(T){const P=f.current;if(!P||P.pointerId!==T.pointerId)return;const z=T.clientX-P.startX,V=T.clientY-P.startY;if(!P.dragging&&Math.hypot(z,V)<Qfe)return;P.dragging=!0,T.preventDefault();const U=m0({x:P.originX+z,y:P.originY+V},{width:P.width,height:P.height});l(U)}function k(T){var G,O;const P=f.current;if(!P||P.pointerId!==T.pointerId||(f.current=null,(O=(G=T.currentTarget).releasePointerCapture)==null||O.call(G,T.pointerId),!P.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const z=T.clientX-P.startX,V=T.clientY-P.startY,U=m0({x:P.originX+z,y:P.originY+V},{width:P.width,height:P.height});l(U),SI(U)}function N(T){var z,V;const P=f.current;!P||P.pointerId!==T.pointerId||(f.current=null,(V=(z=T.currentTarget).releasePointerCapture)==null||V.call(z,T.pointerId))}function M(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return m.jsxs(Ib,{children:[m.jsx(Ob,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",ehe(g)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${ip(i.webRelay.rttMs)},开发机 ${ip(w.rttMs)}`,onPointerDown:x,onPointerMove:R,onPointerUp:k,onPointerCancel:N,onClickCapture:M,children:[m.jsx(ZB,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),m.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",ip(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",ip(w.rttMs)]}),m.jsx(ec,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(Lb,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[m.jsxs("div",{className:"flex items-start justify-between gap-3",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),m.jsx(pt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(nm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(wI).map(T=>m.jsx(she,{label:wI[T],measurement:i[T]},T))})]})]})}function she({label:e,measurement:t}){const n=iF(t.state);return m.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:[m.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:the(t)})]})]})}const sF="/__dev_anywhere_debug/browser-state-dumps",ohe=1500,ahe=10,g0=80,wk=500,lhe=["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"],che=["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 EI(){if(typeof window>"u")return"off";const e=hF("debugDump");return e==="auto"?"auto":e!==null||yhe("debugInput")?"manual":"off"}function uhe(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:phe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:CI(document.activeElement),selection:mhe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>CI(i)).filter(i=>!!i),root:oF(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:ld(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:ld(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:ld(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:ld(()=>kI(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:ld(()=>kI(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:ld(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function dhe(e="manual"){const t=uhe(e);return fhe(t)}async function fhe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await hhe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:sF}}catch(r){const i=pF(r),s=ghe(e.createdAt);return vhe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function hhe(e){const t=await fetch(sF,{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 oF(e,t,n){if(n.count>=ohe||t>ahe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=TI(e.textContent??"");return u?{kind:"text",text:Ub(u,wk)}:{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,g0))u.nodeType===Node.TEXT_NODE&&!TI(u.textContent??"")||r.push(oF(u,t+1,n));s.length>g0&&(i=s.length-g0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:fF(e),attrs:aF(e),rect:lF(e),scroll:cF(e),style:uF(e)},l=dF(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function CI(e){if(!(e instanceof HTMLElement))return null;const t=dF(e);return{path:fF(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:aF(e),rect:lF(e),scroll:cF(e),style:uF(e),...t?{value:t}:{}}}function phe(){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 aF(e){const t={};for(const n of lhe){const r=e.getAttribute(n);r!==null&&(t[n]=Ub(r,500))}return t}function lF(e){const t=e.getBoundingClientRect();return{x:xs(t.x),y:xs(t.y),width:xs(t.width),height:xs(t.height),top:xs(t.top),right:xs(t.right),bottom:xs(t.bottom),left:xs(t.left)}}function cF(e){return{top:xs(e.scrollTop),left:xs(e.scrollLeft),height:xs(e.scrollHeight),width:xs(e.scrollWidth),clientHeight:xs(e.clientHeight),clientWidth:xs(e.clientWidth)}}function uF(e){const t=window.getComputedStyle(e),n={};for(const r of che)n[r]=t.getPropertyValue(r);return n}function dF(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Ub(e.value,wk),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function mhe(){var e;try{return Ub(((e=window.getSelection())==null?void 0:e.toString())??"",wk)}catch{return null}}function fF(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 ghe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function vhe(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 yhe(e){return hF(e)!==null}function hF(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 kI(e){return e?Iy(e.slice(-200)):null}function ld(e){try{return Iy(e())}catch(t){return{error:pF(t)}}}function Iy(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(Iy);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Iy(r);return t}return String(e)}function TI(e){return e.replace(/\s+/g," ").trim()}function Ub(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function xs(e){return Math.round(e*100)/100}function pF(e){return e instanceof Error?e.message:String(e)}const bhe=500,_he=1e3,whe=60;function xhe(){const[e,t]=b.useState(()=>EI()),[n,r]=b.useState(!1),[i,s]=b.useState(null),o=b.useRef(null),l=b.useRef(!1),u=b.useRef(0),d=b.useRef(0),f=b.useRef(null);b.useEffect(()=>{const _=()=>t(EI());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const p=b.useCallback(async(_="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await dhe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&She(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),b.useEffect(()=>{var R,k;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=N=>{d.current>=whe||(_(),f.current=window.setTimeout(()=>{f.current=null;const M=Date.now(),T=_he-(M-u.current);if(T>0){f.current=window.setTimeout(()=>w(N),T);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${N}`)},bhe))};w("initial");const S=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=N=>w(N.type);return S.forEach(N=>window.addEventListener(N,x,!0)),(R=window.visualViewport)==null||R.addEventListener("resize",x),(k=window.visualViewport)==null||k.addEventListener("scroll",x),()=>{var N,M;_(),S.forEach(T=>window.removeEventListener(T,x,!0)),(N=window.visualViewport)==null||N.removeEventListener("resize",x),(M=window.visualViewport)==null||M.removeEventListener("scroll",x)}},[p,e]),e==="off")return null;const v=e==="auto"?"自动诊断中":"保存诊断",g=Ehe(i);return m.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?m.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,m.jsxs(pt,{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?m.jsx(oi,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(jV,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:v})]})]})}function She(e){if(e.status==="saved"){qe.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){qe.info(`诊断已下载: ${e.filename}`);return}qe.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Ehe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Che({issue:e}){const t=e==="unreachable"?"暂时无法连接":e==="page_outdated"?"当前页面版本较旧,请刷新后重试":e==="service_outdated"?"服务端版本较旧,请更新服务后重试":e==="protocol_mismatch"?"页面与服务端版本不一致,请刷新后重试":"连接已断开",n=e==="page_outdated"||e==="protocol_mismatch"?"刷新页面":e==="service_outdated"?"重新检测":null;return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 px-6 text-center text-muted-foreground","data-slot":"relay-connection-state","data-state":"unavailable","data-issue":e,role:"status","aria-live":"polite",children:[e==="unreachable"?m.jsx(oi,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(pt,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function khe(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 xk(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:khe(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 f=l();if(i){const p=i(d);if(p!==null){const v=s.get(d.event);if(v&&i(v)===p&&f.includes(v)){v.t=d.t,v.repeat=(v.repeat??0)+1;const g=f.indexOf(v);g>=0&&g!==f.length-1&&(f.splice(g,1),f.push(v)),u(f);return}}}if(f.push(d),i&&s.set(d.event,d),f.length>r){const p=f.splice(0,f.length-r);if(i)for(const v of p)s.get(v.event)===v&&s.delete(v.event)}u(f)},getAll:l}}function Yn(e){return Math.round(e*10)/10}function Il(e){return e.length===0?"":`${Yn(Math.min(...e))}..${Yn(Math.max(...e))}`}function Ad(e){return[...new Set(e.filter(t=>t!==void 0).map(Yn))]}function mF(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 The="dev_anywhere_pty_input_latency_trace",RI=80,Rhe=1e4,Ahe=new TextDecoder;let Nhe=0;const Jd=new Map,bu=xk({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:The,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Mhe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Lhe)}function Phe(e,t){if(!bu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Nhe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:zhe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Jd.get(e)??[];return s.push(i),Ek(s,r),Jd.set(e,s),vm({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function AI(e,t){if(!e||!bu.isEnabled())return;const n=performance.now(),r=Dhe(e.sessionId,e.inputId);r&&(r.sentAt=n),vm({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 Ihe(e,t,n){if(!bu.isEnabled())return;const r=performance.now(),i=Sk(e,r),s=$he(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Fhe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));vm({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:Ck(i,r),details:Hhe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Ohe(e,t,n=1){if(!bu.isEnabled())return;const r=performance.now(),i=Sk(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));vm({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:Ck(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Bhe(e,s))}function Lhe(){const e=bu.getAll(),t=e.slice(-200),n=[...Jd.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Yn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Yn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Yn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Yn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Yn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Yn(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?"":Yn(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(`
590
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},joe="DialogDescriptionWarning",Foe=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${M5(joe).contentName}}.`;return b.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},KC=v5,$oe=b5,GC=w5,XC=x5,ZC=S5,P5=C5,I5=T5,gb=A5;function Hoe(e){const t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function Uoe(e){const[t,n]=b.useState(void 0);return Xi(()=>{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 Woe=["top","right","bottom","left"],Gl=Math.min,js=Math.max,ky=Math.round,ov=Math.floor,ta=e=>({x:e,y:e}),qoe={left:"right",right:"left",bottom:"top",top:"bottom"};function i1(e,t,n){return js(e,Gl(t,n))}function Ua(e,t){return typeof e=="function"?e(t):e}function Wa(e){return e.split("-")[0]}function uf(e){return e.split("-")[1]}function QC(e){return e==="x"?"y":"x"}function JC(e){return e==="y"?"height":"width"}function Qo(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function ek(e){return QC(Qo(e))}function Voe(e,t,n){n===void 0&&(n=!1);const r=uf(e),i=ek(e),s=JC(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Ty(o)),[o,Ty(o)]}function Yoe(e){const t=Ty(e);return[s1(e),t,s1(t)]}function s1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const P2=["left","right"],I2=["right","left"],Koe=["top","bottom"],Goe=["bottom","top"];function Xoe(e,t,n){switch(e){case"top":case"bottom":return n?t?I2:P2:t?P2:I2;case"left":case"right":return t?Koe:Goe;default:return[]}}function Zoe(e,t,n,r){const i=uf(e);let s=Xoe(Wa(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(s1)))),s}function Ty(e){const t=Wa(e);return qoe[t]+e.slice(t.length)}function Qoe(e){return{top:0,right:0,bottom:0,left:0,...e}}function O5(e){return typeof e!="number"?Qoe(e):{top:e,right:e,bottom:e,left:e}}function Ry(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 O2(e,t,n){let{reference:r,floating:i}=e;const s=Qo(t),o=ek(t),l=JC(o),u=Wa(t),d=s==="y",f=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,v=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:f,y:r.y-i.height};break;case"bottom":g={x:f,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(uf(t)){case"start":g[o]-=v*(n&&d?-1:1);break;case"end":g[o]+=v*(n&&d?-1:1);break}return g}async function Joe(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:f="viewport",elementContext:p="floating",altBoundary:v=!1,padding:g=0}=Ua(t,e),_=O5(g),S=l[v?p==="floating"?"reference":"floating":p],x=Ry(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(S)))==null||n?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:f,strategy:u})),R=p==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),N=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},M=Ry(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:R,offsetParent:k,strategy:u}):R);return{top:(x.top-M.top+_.top)/N.y,bottom:(M.bottom-x.bottom+_.bottom)/N.y,left:(x.left-M.left+_.left)/N.x,right:(M.right-x.right+_.right)/N.x}}const eae=50,tae=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:Joe},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:f,y:p}=O2(d,r,u),v=r,g=0;const _={};for(let w=0;w<s.length;w++){const S=s[w];if(!S)continue;const{name:x,fn:R}=S,{x:k,y:N,data:M,reset:T}=await R({x:f,y:p,initialPlacement:r,placement:v,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=k??f,p=N??p,_[x]={..._[x],...M},T&&g<eae&&(g++,typeof T=="object"&&(T.placement&&(v=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:f,y:p}=O2(d,v,u)),w=-1)}return{x:f,y:p,placement:v,strategy:i,middlewareData:_}},nae=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:f=0}=Ua(e,t)||{};if(d==null)return{};const p=O5(f),v={x:n,y:r},g=ek(i),_=JC(g),w=await o.getDimensions(d),S=g==="y",x=S?"top":"left",R=S?"bottom":"right",k=S?"clientHeight":"clientWidth",N=s.reference[_]+s.reference[g]-v[g]-s.floating[_],M=v[g]-s.reference[g],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let P=T?T[k]:0;(!P||!await(o.isElement==null?void 0:o.isElement(T)))&&(P=l.floating[k]||s.floating[_]);const z=N/2-M/2,V=P/2-w[_]/2-1,U=Gl(p[x],V),G=Gl(p[R],V),O=U,A=P-w[_]-G,L=P/2-w[_]/2+z,D=i1(O,L,A),I=!u.arrow&&uf(i)!=null&&L!==D&&s.reference[_]/2-(L<O?U:G)-w[_]/2<0,B=I?L<O?L-O:L-A:0;return{[g]:v[g]+B,data:{[g]:D,centerOffset:L-D-B,...I&&{alignmentOffset:B}},reset:I}}}),rae=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:f=!0,crossAxis:p=!0,fallbackPlacements:v,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=Ua(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Wa(i),R=Qo(l),k=Wa(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),M=v||(k||!w?[Ty(l)]:Yoe(l)),T=_!=="none";!v&&T&&M.push(...Zoe(l,w,_,N));const P=[l,...M],z=await u.detectOverflow(t,S),V=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&V.push(z[x]),p){const L=Voe(i,o,N);V.push(z[L[0]],z[L[1]])}if(U=[...U,{placement:i,overflows:V}],!V.every(L=>L<=0)){var G,O;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,D=P[L];if(D&&(!(p==="alignment"?R!==Qo(D):!1)||U.every(F=>Qo(F.placement)===R?F.overflows[0]>0:!0)))return{data:{index:L,overflows:U},reset:{placement:D}};let I=(O=U.filter(B=>B.overflows[0]<=0).sort((B,F)=>B.overflows[1]-F.overflows[1])[0])==null?void 0:O.placement;if(!I)switch(g){case"bestFit":{var A;const B=(A=U.filter(F=>{if(T){const Y=Qo(F.placement);return Y===R||Y==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(Y=>Y>0).reduce((Y,j)=>Y+j,0)]).sort((F,Y)=>F[1]-Y[1])[0])==null?void 0:A[0];B&&(I=B);break}case"initialPlacement":I=l;break}if(i!==I)return{reset:{placement:I}}}return{}}}};function L2(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function D2(e){return Woe.some(t=>e[t]>=0)}const iae=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=Ua(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=L2(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:D2(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=L2(o,n.floating);return{data:{escapedOffsets:l,escaped:D2(l)}}}default:return{}}}}},L5=new Set(["left","top"]);async function sae(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Wa(n),l=uf(n),u=Qo(n)==="y",d=L5.has(o)?-1:1,f=s&&u?-1:1,p=Ua(t,e);let{mainAxis:v,crossAxis:g,alignmentAxis:_}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&typeof _=="number"&&(g=l==="end"?_*-1:_),u?{x:g*f,y:v*d}:{x:v*d,y:g*f}}const oae=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 sae(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}}}}},aae=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:x=>{let{x:R,y:k}=x;return{x:R,y:k}}},...d}=Ua(e,t),f={x:n,y:r},p=await s.detectOverflow(t,d),v=Qo(Wa(i)),g=QC(v);let _=f[g],w=f[v];if(o){const x=g==="y"?"top":"left",R=g==="y"?"bottom":"right",k=_+p[x],N=_-p[R];_=i1(k,_,N)}if(l){const x=v==="y"?"top":"left",R=v==="y"?"bottom":"right",k=w+p[x],N=w-p[R];w=i1(k,w,N)}const S=u.fn({...t,[g]:_,[v]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[g]:o,[v]:l}}}}}},lae=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}=Ua(e,t),f={x:n,y:r},p=Qo(i),v=QC(p);let g=f[v],_=f[p];const w=Ua(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const k=v==="y"?"height":"width",N=s.reference[v]-s.floating[k]+S.mainAxis,M=s.reference[v]+s.reference[k]-S.mainAxis;g<N?g=N:g>M&&(g=M)}if(d){var x,R;const k=v==="y"?"width":"height",N=L5.has(Wa(i)),M=s.reference[p]-s.floating[k]+(N&&((x=o.offset)==null?void 0:x[p])||0)+(N?0:S.crossAxis),T=s.reference[p]+s.reference[k]+(N?0:((R=o.offset)==null?void 0:R[p])||0)-(N?S.crossAxis:0);_<M?_=M:_>T&&(_=T)}return{[v]:g,[p]:_}}}},cae=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}=Ua(e,t),f=await o.detectOverflow(t,d),p=Wa(i),v=uf(i),g=Qo(i)==="y",{width:_,height:w}=s.floating;let S,x;p==="top"||p==="bottom"?(S=p,x=v===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=p,S=v==="end"?"top":"bottom");const R=w-f.top-f.bottom,k=_-f.left-f.right,N=Gl(w-f[S],R),M=Gl(_-f[x],k),T=!t.middlewareData.shift;let P=N,z=M;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(z=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(P=R),T&&!v){const U=js(f.left,0),G=js(f.right,0),O=js(f.top,0),A=js(f.bottom,0);g?z=_-2*(U!==0||G!==0?U+G:js(f.left,f.right)):P=w-2*(O!==0||A!==0?O+A:js(f.top,f.bottom))}await u({...t,availableWidth:z,availableHeight:P});const V=await o.getDimensions(l.floating);return _!==V.width||w!==V.height?{reset:{rects:!0}}:{}}}};function vb(){return typeof window<"u"}function df(e){return D5(e)?(e.nodeName||"").toLowerCase():"#document"}function Hs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ca(e){var t;return(t=(D5(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function D5(e){return vb()?e instanceof Node||e instanceof Hs(e).Node:!1}function Ao(e){return vb()?e instanceof Element||e instanceof Hs(e).Element:!1}function Ka(e){return vb()?e instanceof HTMLElement||e instanceof Hs(e).HTMLElement:!1}function B2(e){return!vb()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Hs(e).ShadowRoot}function cm(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=No(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function uae(e){return/^(table|td|th)$/.test(df(e))}function yb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const dae=/transform|translate|scale|rotate|perspective|filter/,fae=/paint|layout|strict|content/,Pc=e=>!!e&&e!=="none";let r0;function tk(e){const t=Ao(e)?No(e):e;return Pc(t.transform)||Pc(t.translate)||Pc(t.scale)||Pc(t.rotate)||Pc(t.perspective)||!nk()&&(Pc(t.backdropFilter)||Pc(t.filter))||dae.test(t.willChange||"")||fae.test(t.contain||"")}function hae(e){let t=Xl(e);for(;Ka(t)&&!Xd(t);){if(tk(t))return t;if(yb(t))return null;t=Xl(t)}return null}function nk(){return r0==null&&(r0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),r0}function Xd(e){return/^(html|body|#document)$/.test(df(e))}function No(e){return Hs(e).getComputedStyle(e)}function bb(e){return Ao(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Xl(e){if(df(e)==="html")return e;const t=e.assignedSlot||e.parentNode||B2(e)&&e.host||ca(e);return B2(t)?t.host:t}function B5(e){const t=Xl(e);return Xd(t)?e.ownerDocument?e.ownerDocument.body:e.body:Ka(t)&&cm(t)?t:B5(t)}function Ip(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=B5(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Hs(i);if(s){const l=o1(o);return t.concat(o,o.visualViewport||[],cm(i)?i:[],l&&n?Ip(l):[])}else return t.concat(i,Ip(i,[],n))}function o1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function z5(e){const t=No(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ka(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=ky(n)!==s||ky(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function rk(e){return Ao(e)?e:e.contextElement}function Bd(e){const t=rk(e);if(!Ka(t))return ta(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=z5(t);let o=(s?ky(n.width):n.width)/r,l=(s?ky(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const pae=ta(0);function j5(e){const t=Hs(e);return!nk()||!t.visualViewport?pae:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function mae(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Hs(e)?!1:t}function nu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=rk(e);let o=ta(1);t&&(r?Ao(r)&&(o=Bd(r)):o=Bd(e));const l=mae(s,n,r)?j5(s):ta(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,f=i.width/o.x,p=i.height/o.y;if(s){const v=Hs(s),g=r&&Ao(r)?Hs(r):r;let _=v,w=o1(_);for(;w&&r&&g!==_;){const S=Bd(w),x=w.getBoundingClientRect(),R=No(w),k=x.left+(w.clientLeft+parseFloat(R.paddingLeft))*S.x,N=x.top+(w.clientTop+parseFloat(R.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,p*=S.y,u+=k,d+=N,_=Hs(w),w=o1(_)}}return Ry({width:f,height:p,x:u,y:d})}function _b(e,t){const n=bb(e).scrollLeft;return t?t.left+n:nu(ca(e)).left+n}function F5(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-_b(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function gae(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=ca(r),l=t?yb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=ta(1);const f=ta(0),p=Ka(r);if((p||!p&&!s)&&((df(r)!=="body"||cm(o))&&(u=bb(r)),p)){const g=nu(r);d=Bd(r),f.x=g.x+r.clientLeft,f.y=g.y+r.clientTop}const v=o&&!p&&!s?F5(o,u):ta(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+f.x+v.x,y:n.y*d.y-u.scrollTop*d.y+f.y+v.y}}function vae(e){return Array.from(e.getClientRects())}function yae(e){const t=ca(e),n=bb(e),r=e.ownerDocument.body,i=js(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=js(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+_b(e);const l=-n.scrollTop;return No(r).direction==="rtl"&&(o+=js(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const z2=25;function bae(e,t){const n=Hs(e),r=ca(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,u=0;if(i){s=i.width,o=i.height;const f=nk();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=_b(r);if(d<=0){const f=r.ownerDocument,p=f.body,v=getComputedStyle(p),g=f.compatMode==="CSS1Compat"&&parseFloat(v.marginLeft)+parseFloat(v.marginRight)||0,_=Math.abs(r.clientWidth-p.clientWidth-g);_<=z2&&(s-=_)}else d<=z2&&(s+=d);return{width:s,height:o,x:l,y:u}}function _ae(e,t){const n=nu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Ka(e)?Bd(e):ta(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 j2(e,t,n){let r;if(t==="viewport")r=bae(e,n);else if(t==="document")r=yae(ca(e));else if(Ao(t))r=_ae(t,n);else{const i=j5(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ry(r)}function $5(e,t){const n=Xl(e);return n===t||!Ao(n)||Xd(n)?!1:No(n).position==="fixed"||$5(n,t)}function wae(e,t){const n=t.get(e);if(n)return n;let r=Ip(e,[],!1).filter(l=>Ao(l)&&df(l)!=="body"),i=null;const s=No(e).position==="fixed";let o=s?Xl(e):e;for(;Ao(o)&&!Xd(o);){const l=No(o),u=tk(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||cm(o)&&!u&&$5(e,o))?r=r.filter(f=>f!==o):i=l,o=Xl(o)}return t.set(e,r),r}function xae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?yb(t)?[]:wae(t,this._c):[].concat(n),r],l=j2(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,p=l.left;for(let v=1;v<o.length;v++){const g=j2(t,o[v],i);u=js(g.top,u),d=Gl(g.right,d),f=Gl(g.bottom,f),p=js(g.left,p)}return{width:d-p,height:f-u,x:p,y:u}}function Sae(e){const{width:t,height:n}=z5(e);return{width:t,height:n}}function Eae(e,t,n){const r=Ka(t),i=ca(t),s=n==="fixed",o=nu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=ta(0);function d(){u.x=_b(i)}if(r||!r&&!s)if((df(t)!=="body"||cm(i))&&(l=bb(t)),r){const g=nu(t,!0,s,t);u.x=g.x+t.clientLeft,u.y=g.y+t.clientTop}else i&&d();s&&!r&&i&&d();const f=i&&!r&&!s?F5(i,l):ta(0),p=o.left+l.scrollLeft-u.x-f.x,v=o.top+l.scrollTop-u.y-f.y;return{x:p,y:v,width:o.width,height:o.height}}function i0(e){return No(e).position==="static"}function F2(e,t){if(!Ka(e)||No(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ca(e)===n&&(n=n.ownerDocument.body),n}function H5(e,t){const n=Hs(e);if(yb(e))return n;if(!Ka(e)){let i=Xl(e);for(;i&&!Xd(i);){if(Ao(i)&&!i0(i))return i;i=Xl(i)}return n}let r=F2(e,t);for(;r&&uae(r)&&i0(r);)r=F2(r,t);return r&&Xd(r)&&i0(r)&&!tk(r)?n:r||hae(e)||n}const Cae=async function(e){const t=this.getOffsetParent||H5,n=this.getDimensions,r=await n(e.floating);return{reference:Eae(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function kae(e){return No(e).direction==="rtl"}const Tae={convertOffsetParentRelativeRectToViewportRelativeRect:gae,getDocumentElement:ca,getClippingRect:xae,getOffsetParent:H5,getElementRects:Cae,getClientRects:vae,getDimensions:Sae,getScale:Bd,isElement:Ao,isRTL:kae};function U5(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Rae(e,t){let n=null,r;const i=ca(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:f,top:p,width:v,height:g}=d;if(l||t(),!v||!g)return;const _=ov(p),w=ov(i.clientWidth-(f+v)),S=ov(i.clientHeight-(p+g)),x=ov(f),k={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:js(0,Gl(1,u))||1};let N=!0;function M(T){const P=T[0].intersectionRatio;if(P!==u){if(!N)return o();P?o(!1,P):r=setTimeout(()=>{o(!1,1e-7)},1e3)}P===1&&!U5(d,e.getBoundingClientRect())&&o(),N=!1}try{n=new IntersectionObserver(M,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(M,k)}n.observe(e)}return o(!0),s}function Aae(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=rk(e),f=i||s?[...d?Ip(d):[],...t?Ip(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const p=d&&l?Rae(d,n):null;let v=-1,g=null;o&&(g=new ResizeObserver(x=>{let[R]=x;R&&R.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(v),v=requestAnimationFrame(()=>{var k;(k=g)==null||k.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let _,w=u?nu(e):null;u&&S();function S(){const x=nu(e);w&&!U5(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(R=>{i&&R.removeEventListener("scroll",n),s&&R.removeEventListener("resize",n)}),p==null||p(),(x=g)==null||x.disconnect(),g=null,u&&cancelAnimationFrame(_)}}const Nae=oae,Mae=aae,Pae=rae,Iae=cae,Oae=iae,$2=nae,Lae=lae,Dae=(e,t,n)=>{const r=new Map,i={platform:Tae,...n},s={...i.platform,_c:r};return tae(e,t,{...i,platform:s})};var Bae=typeof document<"u",zae=function(){},Yv=Bae?b.useLayoutEffect:zae;function Ay(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(!Ay(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)&&!Ay(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function W5(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function H2(e,t){const n=W5(e);return Math.round(t*n)/n}function s0(e){const t=b.useRef(e);return Yv(()=>{t.current=e}),t}function jae(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,[f,p]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[v,g]=b.useState(r);Ay(v,r)||g(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),R=b.useCallback(F=>{F!==T.current&&(T.current=F,w(F))},[]),k=b.useCallback(F=>{F!==P.current&&(P.current=F,x(F))},[]),N=s||_,M=o||S,T=b.useRef(null),P=b.useRef(null),z=b.useRef(f),V=u!=null,U=s0(u),G=s0(i),O=s0(d),A=b.useCallback(()=>{if(!T.current||!P.current)return;const F={placement:t,strategy:n,middleware:v};G.current&&(F.platform=G.current),Dae(T.current,P.current,F).then(Y=>{const j={...Y,isPositioned:O.current!==!1};L.current&&!Ay(z.current,j)&&(z.current=j,mu.flushSync(()=>{p(j)}))})},[v,t,n,G,O]);Yv(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,p(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);Yv(()=>(L.current=!0,()=>{L.current=!1}),[]),Yv(()=>{if(N&&(T.current=N),M&&(P.current=M),N&&M){if(U.current)return U.current(N,M,A);A()}},[N,M,A,U,V]);const D=b.useMemo(()=>({reference:T,floating:P,setReference:R,setFloating:k}),[R,k]),I=b.useMemo(()=>({reference:N,floating:M}),[N,M]),B=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!I.floating)return F;const Y=H2(I.floating,f.x),j=H2(I.floating,f.y);return l?{...F,transform:"translate("+Y+"px, "+j+"px)",...W5(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Y,top:j}},[n,l,I.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:A,refs:D,elements:I,floatingStyles:B}),[f,A,D,I,B])}const Fae=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?$2({element:r.current,padding:i}).fn(n):{}:r?$2({element:r,padding:i}).fn(n):{}}}},$ae=(e,t)=>{const n=Nae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Hae=(e,t)=>{const n=Mae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uae=(e,t)=>({fn:Lae(e).fn,options:[e,t]}),Wae=(e,t)=>{const n=Pae(e);return{name:n.name,fn:n.fn,options:[e,t]}},qae=(e,t)=>{const n=Iae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Vae=(e,t)=>{const n=Oae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Yae=(e,t)=>{const n=Fae(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Kae="Arrow",q5=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(wn.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:m.jsx("polygon",{points:"0,0 30,0 15,10"})})});q5.displayName=Kae;var Gae=q5,ik="Popper",[V5,ic]=Ya(ik),[Xae,Y5]=V5(ik),K5=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(Xae,{scope:t,anchor:r,onAnchorChange:i,children:n})};K5.displayName=ik;var G5="PopperAnchor",X5=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=Y5(G5,n),o=b.useRef(null),l=sr(t,o),u=b.useRef(null);return b.useEffect(()=>{const d=u.current;u.current=(r==null?void 0:r.current)||o.current,d!==u.current&&s.onAnchorChange(u.current)}),r?null:m.jsx(wn.div,{...i,ref:l})});X5.displayName=G5;var sk="PopperContent",[Zae,Qae]=V5(sk),Z5=b.forwardRef((e,t)=>{var Q,ce,ie,le,be,Le;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:f=0,sticky:p="partial",hideWhenDetached:v=!1,updatePositionStrategy:g="optimized",onPlaced:_,...w}=e,S=Y5(sk,n),[x,R]=b.useState(null),k=sr(t,he=>R(he)),[N,M]=b.useState(null),T=Uoe(N),P=(T==null?void 0:T.width)??0,z=(T==null?void 0:T.height)??0,V=r+(s!=="center"?"-"+s:""),U=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},G=Array.isArray(d)?d:[d],O=G.length>0,A={padding:U,boundary:G.filter(ele),altBoundary:O},{refs:L,floatingStyles:D,placement:I,isPositioned:B,middlewareData:F}=jae({strategy:"fixed",placement:V,whileElementsMounted:(...he)=>Aae(...he,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[$ae({mainAxis:i+z,alignmentAxis:o}),u&&Hae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Uae():void 0,...A}),u&&Wae({...A}),qae({...A,apply:({elements:he,rects:He,availableWidth:Pt,availableHeight:Ge})=>{const{width:it,height:$e}=He.reference,We=he.floating.style;We.setProperty("--radix-popper-available-width",`${Pt}px`),We.setProperty("--radix-popper-available-height",`${Ge}px`),We.setProperty("--radix-popper-anchor-width",`${it}px`),We.setProperty("--radix-popper-anchor-height",`${$e}px`)}}),N&&Yae({element:N,padding:l}),tle({arrowWidth:P,arrowHeight:z}),v&&Vae({strategy:"referenceHidden",...A})]}),[Y,j]=e3(I),q=oa(_);Xi(()=>{B&&(q==null||q())},[B,q]);const K=(Q=F.arrow)==null?void 0:Q.x,$=(ce=F.arrow)==null?void 0:ce.y,ne=((ie=F.arrow)==null?void 0:ie.centerOffset)!==0,[J,te]=b.useState();return Xi(()=>{x&&te(window.getComputedStyle(x).zIndex)},[x]),m.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:B?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(le=F.transformOrigin)==null?void 0:le.x,(be=F.transformOrigin)==null?void 0:be.y].join(" "),...((Le=F.hide)==null?void 0:Le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(Zae,{scope:n,placedSide:Y,onArrowChange:M,arrowX:K,arrowY:$,shouldHideArrow:ne,children:m.jsx(wn.div,{"data-side":Y,"data-align":j,...w,ref:k,style:{...w.style,animation:B?void 0:"none"}})})})});Z5.displayName=sk;var Q5="PopperArrow",Jae={top:"bottom",right:"left",bottom:"top",left:"right"},J5=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Qae(Q5,r),o=Jae[s.placedSide];return m.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:m.jsx(Gae,{...i,ref:n,style:{...i.style,display:"block"}})})});J5.displayName=Q5;function ele(e){return e!==null}var tle=e=>({name:"transformOrigin",options:e,fn(t){var S,x,R;const{placement:n,rects:r,middlewareData:i}=t,o=((S=i.arrow)==null?void 0:S.centerOffset)!==0,l=o?0:e.arrowWidth,u=o?0:e.arrowHeight,[d,f]=e3(n),p={start:"0%",center:"50%",end:"100%"}[f],v=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,g=(((R=i.arrow)==null?void 0:R.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?p:`${v}px`,w=`${-u}px`):d==="top"?(_=o?p:`${v}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?p:`${g}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?p:`${g}px`),{data:{x:_,y:w}}}});function e3(e){const[t,n="center"]=e.split("-");return[t,n]}var wb=K5,um=X5,xb=Z5,Sb=J5,o0="rovingFocusGroup.onEntryFocus",nle={bubbles:!1,cancelable:!0},dm="RovingFocusGroup",[a1,t3,rle]=UC(dm),[ile,n3]=Ya(dm,[rle]),[sle,ole]=ile(dm),r3=b.forwardRef((e,t)=>m.jsx(a1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(a1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(ale,{...e,ref:t})})}));r3.displayName=dm;var ale=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...p}=e,v=b.useRef(null),g=sr(t,v),_=WC(s),[w,S]=eu({prop:o,defaultProp:l??null,onChange:u,caller:dm}),[x,R]=b.useState(!1),k=oa(d),N=t3(n),M=b.useRef(!1),[T,P]=b.useState(0);return b.useEffect(()=>{const z=v.current;if(z)return z.addEventListener(o0,k),()=>z.removeEventListener(o0,k)},[k]),m.jsx(sle,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(z=>S(z),[S]),onItemShiftTab:b.useCallback(()=>R(!0),[]),onFocusableItemAdd:b.useCallback(()=>P(z=>z+1),[]),onFocusableItemRemove:b.useCallback(()=>P(z=>z-1),[]),children:m.jsx(wn.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:$t(e.onMouseDown,()=>{M.current=!0}),onFocus:$t(e.onFocus,z=>{const V=!M.current;if(z.target===z.currentTarget&&V&&!x){const U=new CustomEvent(o0,nle);if(z.currentTarget.dispatchEvent(U),!U.defaultPrevented){const G=N().filter(I=>I.focusable),O=G.find(I=>I.active),A=G.find(I=>I.id===w),D=[O,A,...G].filter(Boolean).map(I=>I.ref.current);o3(D,f)}}M.current=!1}),onBlur:$t(e.onBlur,()=>R(!1))})})}),i3="RovingFocusGroupItem",s3=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=ji(),d=s||u,f=ole(i3,n),p=f.currentTabStopId===d,v=t3(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(a1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(wn.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:$t(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:$t(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:$t(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=ule(S,f.orientation,f.dir);if(x!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let k=v().filter(N=>N.focusable).map(N=>N.ref.current);if(x==="last")k.reverse();else if(x==="prev"||x==="next"){x==="prev"&&k.reverse();const N=k.indexOf(S.currentTarget);k=f.loop?dle(k,N+1):k.slice(N+1)}setTimeout(()=>o3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:w!=null}):o})})});s3.displayName=i3;var lle={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function cle(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ule(e,t,n){const r=cle(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return lle[r]}function o3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function dle(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var fle=r3,hle=s3,l1=["Enter"," "],ple=["ArrowDown","PageUp","Home"],a3=["ArrowUp","PageDown","End"],mle=[...ple,...a3],gle={ltr:[...l1,"ArrowRight"],rtl:[...l1,"ArrowLeft"]},vle={ltr:["ArrowLeft"],rtl:["ArrowRight"]},fm="Menu",[Op,yle,ble]=UC(fm),[gu,l3]=Ya(fm,[ble,ic,n3]),Eb=ic(),c3=n3(),[_le,vu]=gu(fm),[wle,hm]=gu(fm),u3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Eb(t),[u,d]=b.useState(null),f=b.useRef(!1),p=oa(s),v=WC(i);return b.useEffect(()=>{const g=()=>{f.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>f.current=!1;return document.addEventListener("keydown",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),m.jsx(wb,{...l,children:m.jsx(_le,{scope:t,open:n,onOpenChange:p,content:u,onContentChange:d,children:m.jsx(wle,{scope:t,onClose:b.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:f,dir:v,modal:o,children:r})})})};u3.displayName=fm;var xle="MenuAnchor",ok=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Eb(n);return m.jsx(um,{...i,...r,ref:t})});ok.displayName=xle;var ak="MenuPortal",[Sle,d3]=gu(ak,{forceMount:void 0}),f3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=vu(ak,t);return m.jsx(Sle,{scope:t,forceMount:n,children:m.jsx(yo,{present:n||s.open,children:m.jsx(cf,{asChild:!0,container:i,children:r})})})};f3.displayName=ak;var fo="MenuContent",[Ele,lk]=gu(fo),h3=b.forwardRef((e,t)=>{const n=d3(fo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=vu(fo,e.__scopeMenu),o=hm(fo,e.__scopeMenu);return m.jsx(Op.Provider,{scope:e.__scopeMenu,children:m.jsx(yo,{present:r||s.open,children:m.jsx(Op.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Cle,{...i,ref:t}):m.jsx(kle,{...i,ref:t})})})})}),Cle=b.forwardRef((e,t)=>{const n=vu(fo,e.__scopeMenu),r=b.useRef(null),i=sr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return pb(s)},[]),m.jsx(ck,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:$t(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),kle=b.forwardRef((e,t)=>{const n=vu(fo,e.__scopeMenu);return m.jsx(ck,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Tle=Kl("MenuContent.ScrollLock"),ck=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:v,onDismiss:g,disableOutsideScroll:_,...w}=e,S=vu(fo,n),x=hm(fo,n),R=Eb(n),k=c3(n),N=yle(n),[M,T]=b.useState(null),P=b.useRef(null),z=sr(t,P,S.onContentChange),V=b.useRef(0),U=b.useRef(""),G=b.useRef(0),O=b.useRef(null),A=b.useRef("right"),L=b.useRef(0),D=_?lm:b.Fragment,I=_?{as:Tle,allowPinchZoom:!0}:void 0,B=Y=>{var Q,ce;const j=U.current+Y,q=N().filter(ie=>!ie.disabled),K=document.activeElement,$=(Q=q.find(ie=>ie.ref.current===K))==null?void 0:Q.textValue,ne=q.map(ie=>ie.textValue),J=jle(ne,j,$),te=(ce=q.find(ie=>ie.textValue===J))==null?void 0:ce.ref.current;(function ie(le){U.current=le,window.clearTimeout(V.current),le!==""&&(V.current=window.setTimeout(()=>ie(""),1e3))})(j),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(V.current),[]),fb();const F=b.useCallback(Y=>{var q,K;return A.current===((q=O.current)==null?void 0:q.side)&&$le(Y,(K=O.current)==null?void 0:K.area)},[]);return m.jsx(Ele,{scope:n,searchRef:U,onItemEnter:b.useCallback(Y=>{F(Y)&&Y.preventDefault()},[F]),onItemLeave:b.useCallback(Y=>{var j;F(Y)||((j=P.current)==null||j.focus(),T(null))},[F]),onTriggerLeave:b.useCallback(Y=>{F(Y)&&Y.preventDefault()},[F]),pointerGraceTimerRef:G,onPointerGraceIntentChange:b.useCallback(Y=>{O.current=Y},[]),children:m.jsx(D,{...I,children:m.jsx(am,{asChild:!0,trapped:i,onMountAutoFocus:$t(s,Y=>{var j;Y.preventDefault(),(j=P.current)==null||j.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:v,onDismiss:g,children:m.jsx(fle,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:M,onCurrentTabStopIdChange:T,onEntryFocus:$t(u,Y=>{x.isUsingKeyboardRef.current||Y.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(xb,{role:"menu","aria-orientation":"vertical","data-state":A3(S.open),"data-radix-menu-content":"",dir:x.dir,...R,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:$t(w.onKeyDown,Y=>{const q=Y.target.closest("[data-radix-menu-content]")===Y.currentTarget,K=Y.ctrlKey||Y.altKey||Y.metaKey,$=Y.key.length===1;q&&(Y.key==="Tab"&&Y.preventDefault(),!K&&$&&B(Y.key));const ne=P.current;if(Y.target!==ne||!mle.includes(Y.key))return;Y.preventDefault();const te=N().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);a3.includes(Y.key)&&te.reverse(),Ble(te)}),onBlur:$t(e.onBlur,Y=>{Y.currentTarget.contains(Y.target)||(window.clearTimeout(V.current),U.current="")}),onPointerMove:$t(e.onPointerMove,Lp(Y=>{const j=Y.target,q=L.current!==Y.clientX;if(Y.currentTarget.contains(j)&&q){const K=Y.clientX>L.current?"right":"left";A.current=K,L.current=Y.clientX}}))})})})})})})});h3.displayName=fo;var Rle="MenuGroup",uk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(wn.div,{role:"group",...r,ref:t})});uk.displayName=Rle;var Ale="MenuLabel",p3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(wn.div,{...r,ref:t})});p3.displayName=Ale;var Ny="MenuItem",U2="menu.itemSelect",Cb=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=hm(Ny,e.__scopeMenu),l=lk(Ny,e.__scopeMenu),u=sr(t,s),d=b.useRef(!1),f=()=>{const p=s.current;if(!n&&p){const v=new CustomEvent(U2,{bubbles:!0,cancelable:!0});p.addEventListener(U2,g=>r==null?void 0:r(g),{once:!0}),t5(p,v),v.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(m3,{...i,ref:u,disabled:n,onClick:$t(e.onClick,f),onPointerDown:p=>{var v;(v=e.onPointerDown)==null||v.call(e,p),d.current=!0},onPointerUp:$t(e.onPointerUp,p=>{var v;d.current||(v=p.currentTarget)==null||v.click()}),onKeyDown:$t(e.onKeyDown,p=>{const v=l.searchRef.current!=="";n||v&&p.key===" "||l1.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Cb.displayName=Ny;var m3=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=lk(Ny,n),l=c3(n),u=b.useRef(null),d=sr(t,u),[f,p]=b.useState(!1),[v,g]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&g((_.textContent??"").trim())},[s.children]),m.jsx(Op.ItemSlot,{scope:n,disabled:r,textValue:i??v,children:m.jsx(hle,{asChild:!0,...l,focusable:!r,children:m.jsx(wn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:$t(e.onPointerMove,Lp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:$t(e.onPointerLeave,Lp(_=>o.onItemLeave(_))),onFocus:$t(e.onFocus,()=>p(!0)),onBlur:$t(e.onBlur,()=>p(!1))})})})}),Nle="MenuCheckboxItem",g3=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(w3,{scope:e.__scopeMenu,checked:n,children:m.jsx(Cb,{role:"menuitemcheckbox","aria-checked":My(n)?"mixed":n,...i,ref:t,"data-state":fk(n),onSelect:$t(i.onSelect,()=>r==null?void 0:r(My(n)?!0:!n),{checkForDefaultPrevented:!1})})})});g3.displayName=Nle;var v3="MenuRadioGroup",[Mle,Ple]=gu(v3,{value:void 0,onValueChange:()=>{}}),y3=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=oa(r);return m.jsx(Mle,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(uk,{...i,ref:t})})});y3.displayName=v3;var b3="MenuRadioItem",_3=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=Ple(b3,e.__scopeMenu),s=n===i.value;return m.jsx(w3,{scope:e.__scopeMenu,checked:s,children:m.jsx(Cb,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":fk(s),onSelect:$t(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});_3.displayName=b3;var dk="MenuItemIndicator",[w3,Ile]=gu(dk,{checked:!1}),x3=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=Ile(dk,n);return m.jsx(yo,{present:r||My(s.checked)||s.checked===!0,children:m.jsx(wn.span,{...i,ref:t,"data-state":fk(s.checked)})})});x3.displayName=dk;var Ole="MenuSeparator",S3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(wn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});S3.displayName=Ole;var Lle="MenuArrow",E3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Eb(n);return m.jsx(Sb,{...i,...r,ref:t})});E3.displayName=Lle;var Dle="MenuSub",[_Le,C3]=gu(Dle),Jh="MenuSubTrigger",k3=b.forwardRef((e,t)=>{const n=vu(Jh,e.__scopeMenu),r=hm(Jh,e.__scopeMenu),i=C3(Jh,e.__scopeMenu),s=lk(Jh,e.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:u}=s,d={__scopeMenu:e.__scopeMenu},f=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>f,[f]),b.useEffect(()=>{const p=l.current;return()=>{window.clearTimeout(p),u(null)}},[l,u]),m.jsx(ok,{asChild:!0,...d,children:m.jsx(m3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":A3(n.open),...e,ref:Ha(t,i.onTriggerChange),onClick:p=>{var v;(v=e.onClick)==null||v.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:$t(e.onPointerMove,Lp(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:$t(e.onPointerLeave,Lp(p=>{var g,_;f();const v=(g=n.content)==null?void 0:g.getBoundingClientRect();if(v){const w=(_=n.content)==null?void 0:_.dataset.side,S=w==="right",x=S?-5:5,R=v[S?"left":"right"],k=v[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+x,y:p.clientY},{x:R,y:v.top},{x:k,y:v.top},{x:k,y:v.bottom},{x:R,y:v.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:$t(e.onKeyDown,p=>{var g;const v=s.searchRef.current!=="";e.disabled||v&&p.key===" "||gle[r.dir].includes(p.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),p.preventDefault())})})})});k3.displayName=Jh;var T3="MenuSubContent",R3=b.forwardRef((e,t)=>{const n=d3(fo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=vu(fo,e.__scopeMenu),o=hm(fo,e.__scopeMenu),l=C3(T3,e.__scopeMenu),u=b.useRef(null),d=sr(t,u);return m.jsx(Op.Provider,{scope:e.__scopeMenu,children:m.jsx(yo,{present:r||s.open,children:m.jsx(Op.Slot,{scope:e.__scopeMenu,children:m.jsx(ck,{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:f=>{var p;o.isUsingKeyboardRef.current&&((p=u.current)==null||p.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:$t(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:$t(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:$t(e.onKeyDown,f=>{var g;const p=f.currentTarget.contains(f.target),v=vle[o.dir].includes(f.key);p&&v&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});R3.displayName=T3;function A3(e){return e?"open":"closed"}function My(e){return e==="indeterminate"}function fk(e){return My(e)?"indeterminate":e?"checked":"unchecked"}function Ble(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function zle(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function jle(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=zle(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 Fle(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,f=l.y,p=u.x,v=u.y;f>r!=v>r&&n<(p-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function $le(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Fle(n,t)}function Lp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Hle=u3,Ule=ok,Wle=f3,qle=h3,Vle=uk,Yle=p3,Kle=Cb,Gle=g3,Xle=y3,Zle=_3,Qle=x3,Jle=S3,ece=E3,tce=k3,nce=R3,kb="DropdownMenu",[rce]=Ya(kb,[l3]),us=l3(),[ice,N3]=rce(kb),M3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=us(t),d=b.useRef(null),[f,p]=eu({prop:i,defaultProp:s??!1,onChange:o,caller:kb});return m.jsx(ice,{scope:t,triggerId:ji(),triggerRef:d,contentId:ji(),open:f,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(v=>!v),[p]),modal:l,children:m.jsx(Hle,{...u,open:f,onOpenChange:p,dir:r,modal:l,children:n})})};M3.displayName=kb;var P3="DropdownMenuTrigger",I3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=N3(P3,n),o=us(n);return m.jsx(Ule,{asChild:!0,...o,children:m.jsx(wn.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:Ha(t,s.triggerRef),onPointerDown:$t(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:$t(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});I3.displayName=P3;var sce="DropdownMenuPortal",O3=e=>{const{__scopeDropdownMenu:t,...n}=e,r=us(t);return m.jsx(Wle,{...r,...n})};O3.displayName=sce;var L3="DropdownMenuContent",D3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=N3(L3,n),s=us(n),o=b.useRef(!1);return m.jsx(qle,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:$t(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:$t(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,f=u.button===2||d;(!i.modal||f)&&(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)"}})});D3.displayName=L3;var oce="DropdownMenuGroup",ace=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Vle,{...i,...r,ref:t})});ace.displayName=oce;var lce="DropdownMenuLabel",B3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Yle,{...i,...r,ref:t})});B3.displayName=lce;var cce="DropdownMenuItem",z3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Kle,{...i,...r,ref:t})});z3.displayName=cce;var uce="DropdownMenuCheckboxItem",j3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Gle,{...i,...r,ref:t})});j3.displayName=uce;var dce="DropdownMenuRadioGroup",fce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Xle,{...i,...r,ref:t})});fce.displayName=dce;var hce="DropdownMenuRadioItem",pce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Zle,{...i,...r,ref:t})});pce.displayName=hce;var mce="DropdownMenuItemIndicator",F3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Qle,{...i,...r,ref:t})});F3.displayName=mce;var gce="DropdownMenuSeparator",$3=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(Jle,{...i,...r,ref:t})});$3.displayName=gce;var vce="DropdownMenuArrow",yce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(ece,{...i,...r,ref:t})});yce.displayName=vce;var bce="DropdownMenuSubTrigger",_ce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(tce,{...i,...r,ref:t})});_ce.displayName=bce;var wce="DropdownMenuSubContent",xce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=us(n);return m.jsx(nce,{...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)"}})});xce.displayName=wce;var Sce=M3,Ece=I3,Cce=O3,kce=D3,Tce=B3,Rce=z3,Ace=j3,Nce=F3,Mce=$3;function W2(e,[t,n]){return Math.min(n,Math.max(t,e))}var Tb="Popover",[H3]=Ya(Tb,[ic]),pm=ic(),[Pce,sc]=H3(Tb),U3=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=pm(t),u=b.useRef(null),[d,f]=b.useState(!1),[p,v]=eu({prop:r,defaultProp:i??!1,onChange:s,caller:Tb});return m.jsx(wb,{...l,children:m.jsx(Pce,{scope:t,contentId:ji(),triggerRef:u,open:p,onOpenChange:v,onOpenToggle:b.useCallback(()=>v(g=>!g),[v]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>f(!0),[]),onCustomAnchorRemove:b.useCallback(()=>f(!1),[]),modal:o,children:n})})};U3.displayName=Tb;var W3="PopoverAnchor",Ice=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=sc(W3,n),s=pm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(um,{...s,...r,ref:t})});Ice.displayName=W3;var q3="PopoverTrigger",V3=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=sc(q3,n),s=pm(n),o=sr(t,i.triggerRef),l=m.jsx(wn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Z3(i.open),...r,ref:o,onClick:$t(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(um,{asChild:!0,...s,children:l})});V3.displayName=q3;var hk="PopoverPortal",[Oce,Lce]=H3(hk,{forceMount:void 0}),Y3=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=sc(hk,t);return m.jsx(Oce,{scope:t,forceMount:n,children:m.jsx(yo,{present:n||s.open,children:m.jsx(cf,{asChild:!0,container:i,children:r})})})};Y3.displayName=hk;var Zd="PopoverContent",K3=b.forwardRef((e,t)=>{const n=Lce(Zd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=sc(Zd,e.__scopePopover);return m.jsx(yo,{present:r||s.open,children:s.modal?m.jsx(Bce,{...i,ref:t}):m.jsx(zce,{...i,ref:t})})});K3.displayName=Zd;var Dce=Kl("PopoverContent.RemoveScroll"),Bce=b.forwardRef((e,t)=>{const n=sc(Zd,e.__scopePopover),r=b.useRef(null),i=sr(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return pb(o)},[]),m.jsx(lm,{as:Dce,allowPinchZoom:!0,children:m.jsx(G3,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:$t(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:$t(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:$t(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),zce=b.forwardRef((e,t)=>{const n=sc(Zd,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(G3,{...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()}})}),G3=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,...p}=e,v=sc(Zd,n),g=pm(n);return fb(),m.jsx(am,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>v.onOpenChange(!1),children:m.jsx(xb,{"data-state":Z3(v.open),role:"dialog",id:v.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)"}})})})}),X3="PopoverClose",jce=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=sc(X3,n);return m.jsx(wn.button,{type:"button",...r,ref:t,onClick:$t(e.onClick,()=>i.onOpenChange(!1))})});jce.displayName=X3;var Fce="PopoverArrow",$ce=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pm(n);return m.jsx(Sb,{...i,...r,ref:t})});$ce.displayName=Fce;function Z3(e){return e?"open":"closed"}var Hce=U3,Uce=V3,Wce=Y3,qce=K3,Vce=[" ","Enter","ArrowUp","ArrowDown"],Yce=[" ","Enter"],ru="Select",[Rb,Ab,Kce]=UC(ru),[ff]=Ya(ru,[Kce,ic]),Nb=ic(),[Gce,oc]=ff(ru),[Xce,Zce]=ff(ru),Q3=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:f,autoComplete:p,disabled:v,required:g,form:_}=e,w=Nb(t),[S,x]=b.useState(null),[R,k]=b.useState(null),[N,M]=b.useState(!1),T=WC(d),[P,z]=eu({prop:r,defaultProp:i??!1,onChange:s,caller:ru}),[V,U]=eu({prop:o,defaultProp:l,onChange:u,caller:ru}),G=b.useRef(null),O=S?_||!!S.closest("form"):!0,[A,L]=b.useState(new Set),D=Array.from(A).map(I=>I.props.value).join(";");return m.jsx(wb,{...w,children:m.jsxs(Gce,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:R,onValueNodeChange:k,valueNodeHasChildren:N,onValueNodeHasChildrenChange:M,contentId:ji(),value:V,onValueChange:U,open:P,onOpenChange:z,dir:T,triggerPointerDownPosRef:G,disabled:v,children:[m.jsx(Rb.Provider,{scope:t,children:m.jsx(Xce,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(I=>{L(B=>new Set(B).add(I))},[]),onNativeOptionRemove:b.useCallback(I=>{L(B=>{const F=new Set(B);return F.delete(I),F})},[]),children:n})}),O?m.jsxs(_4,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:p,value:V,onChange:I=>U(I.target.value),disabled:v,form:_,children:[V===void 0?m.jsx("option",{value:""}):null,Array.from(A)]},D):null]})})};Q3.displayName=ru;var J3="SelectTrigger",e4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Nb(n),o=oc(J3,n),l=o.disabled||r,u=sr(t,o.onTriggerChange),d=Ab(n),f=b.useRef("touch"),[p,v,g]=x4(w=>{const S=d().filter(k=>!k.disabled),x=S.find(k=>k.value===o.value),R=S4(S,w,x);R!==void 0&&o.onValueChange(R.value)}),_=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(um,{asChild:!0,...s,children:m.jsx(wn.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":w4(o.value)?"":void 0,...i,ref:u,onClick:$t(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:$t(i.onPointerDown,w=>{f.current=w.pointerType;const S=w.target;S.hasPointerCapture(w.pointerId)&&S.releasePointerCapture(w.pointerId),w.button===0&&w.ctrlKey===!1&&w.pointerType==="mouse"&&(_(w),w.preventDefault())}),onKeyDown:$t(i.onKeyDown,w=>{const S=p.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&v(w.key),!(S&&w.key===" ")&&Vce.includes(w.key)&&(_(),w.preventDefault())})})})});e4.displayName=J3;var t4="SelectValue",n4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=oc(t4,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,p=sr(t,u.onValueNodeChange);return Xi(()=>{d(f)},[d,f]),m.jsx(wn.span,{...l,ref:p,style:{pointerEvents:"none"},children:w4(u.value)?m.jsx(m.Fragment,{children:o}):s})});n4.displayName=t4;var Qce="SelectIcon",r4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(wn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});r4.displayName=Qce;var Jce="SelectPortal",i4=e=>m.jsx(cf,{asChild:!0,...e});i4.displayName=Jce;var iu="SelectContent",s4=b.forwardRef((e,t)=>{const n=oc(iu,e.__scopeSelect),[r,i]=b.useState();if(Xi(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?mu.createPortal(m.jsx(o4,{scope:e.__scopeSelect,children:m.jsx(Rb.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(a4,{...e,ref:t})});s4.displayName=iu;var ko=10,[o4,ac]=ff(iu),eue="SelectContentImpl",tue=Kl("SelectContent.RemoveScroll"),a4=b.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,R=oc(iu,n),[k,N]=b.useState(null),[M,T]=b.useState(null),P=sr(t,Q=>N(Q)),[z,V]=b.useState(null),[U,G]=b.useState(null),O=Ab(n),[A,L]=b.useState(!1),D=b.useRef(!1);b.useEffect(()=>{if(k)return pb(k)},[k]),fb();const I=b.useCallback(Q=>{const[ce,...ie]=O().map(Le=>Le.ref.current),[le]=ie.slice(-1),be=document.activeElement;for(const Le of Q)if(Le===be||(Le==null||Le.scrollIntoView({block:"nearest"}),Le===ce&&M&&(M.scrollTop=0),Le===le&&M&&(M.scrollTop=M.scrollHeight),Le==null||Le.focus(),document.activeElement!==be))return},[O,M]),B=b.useCallback(()=>I([z,k]),[I,z,k]);b.useEffect(()=>{A&&B()},[A,B]);const{onOpenChange:F,triggerPointerDownPosRef:Y}=R;b.useEffect(()=>{if(k){let Q={x:0,y:0};const ce=le=>{var be,Le;Q={x:Math.abs(Math.round(le.pageX)-(((be=Y.current)==null?void 0:be.x)??0)),y:Math.abs(Math.round(le.pageY)-(((Le=Y.current)==null?void 0:Le.y)??0))}},ie=le=>{Q.x<=10&&Q.y<=10?le.preventDefault():k.contains(le.target)||F(!1),document.removeEventListener("pointermove",ce),Y.current=null};return Y.current!==null&&(document.addEventListener("pointermove",ce),document.addEventListener("pointerup",ie,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ce),document.removeEventListener("pointerup",ie,{capture:!0})}}},[k,F,Y]),b.useEffect(()=>{const Q=()=>F(!1);return window.addEventListener("blur",Q),window.addEventListener("resize",Q),()=>{window.removeEventListener("blur",Q),window.removeEventListener("resize",Q)}},[F]);const[j,q]=x4(Q=>{const ce=O().filter(be=>!be.disabled),ie=ce.find(be=>be.ref.current===document.activeElement),le=S4(ce,Q,ie);le&&setTimeout(()=>le.ref.current.focus())}),K=b.useCallback((Q,ce,ie)=>{const le=!D.current&&!ie;(R.value!==void 0&&R.value===ce||le)&&(V(Q),le&&(D.current=!0))},[R.value]),$=b.useCallback(()=>k==null?void 0:k.focus(),[k]),ne=b.useCallback((Q,ce,ie)=>{const le=!D.current&&!ie;(R.value!==void 0&&R.value===ce||le)&&G(Q)},[R.value]),J=r==="popper"?c1:l4,te=J===c1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(o4,{scope:n,content:k,viewport:M,onViewportChange:T,itemRefCallback:K,selectedItem:z,onItemLeave:$,itemTextRefCallback:ne,focusSelectedItem:B,selectedItemText:U,position:r,isPositioned:A,searchRef:j,children:m.jsx(lm,{as:tue,allowPinchZoom:!0,children:m.jsx(am,{asChild:!0,trapped:R.open,onMountAutoFocus:Q=>{Q.preventDefault()},onUnmountAutoFocus:$t(i,Q=>{var ce;(ce=R.trigger)==null||ce.focus({preventScroll:!0}),Q.preventDefault()}),children:m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:Q=>Q.preventDefault(),onDismiss:()=>R.onOpenChange(!1),children:m.jsx(J,{role:"listbox",id:R.contentId,"data-state":R.open?"open":"closed",dir:R.dir,onContextMenu:Q=>Q.preventDefault(),...x,...te,onPlaced:()=>L(!0),ref:P,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:$t(x.onKeyDown,Q=>{const ce=Q.ctrlKey||Q.altKey||Q.metaKey;if(Q.key==="Tab"&&Q.preventDefault(),!ce&&Q.key.length===1&&q(Q.key),["ArrowUp","ArrowDown","Home","End"].includes(Q.key)){let le=O().filter(be=>!be.disabled).map(be=>be.ref.current);if(["ArrowUp","End"].includes(Q.key)&&(le=le.slice().reverse()),["ArrowUp","ArrowDown"].includes(Q.key)){const be=Q.target,Le=le.indexOf(be);le=le.slice(Le+1)}setTimeout(()=>I(le)),Q.preventDefault()}})})})})})})});a4.displayName=eue;var nue="SelectItemAlignedPosition",l4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=oc(iu,n),o=ac(iu,n),[l,u]=b.useState(null),[d,f]=b.useState(null),p=sr(t,P=>f(P)),v=Ab(n),g=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:R}=o,k=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const P=s.trigger.getBoundingClientRect(),z=d.getBoundingClientRect(),V=s.valueNode.getBoundingClientRect(),U=x.getBoundingClientRect();if(s.dir!=="rtl"){const be=U.left-z.left,Le=V.left-be,he=P.left-Le,He=P.width+he,Pt=Math.max(He,z.width),Ge=window.innerWidth-ko,it=W2(Le,[ko,Math.max(ko,Ge-Pt)]);l.style.minWidth=He+"px",l.style.left=it+"px"}else{const be=z.right-U.right,Le=window.innerWidth-V.right-be,he=window.innerWidth-P.right-Le,He=P.width+he,Pt=Math.max(He,z.width),Ge=window.innerWidth-ko,it=W2(Le,[ko,Math.max(ko,Ge-Pt)]);l.style.minWidth=He+"px",l.style.right=it+"px"}const G=v(),O=window.innerHeight-ko*2,A=w.scrollHeight,L=window.getComputedStyle(d),D=parseInt(L.borderTopWidth,10),I=parseInt(L.paddingTop,10),B=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),Y=D+I+A+F+B,j=Math.min(S.offsetHeight*5,Y),q=window.getComputedStyle(w),K=parseInt(q.paddingTop,10),$=parseInt(q.paddingBottom,10),ne=P.top+P.height/2-ko,J=O-ne,te=S.offsetHeight/2,Q=S.offsetTop+te,ce=D+I+Q,ie=Y-ce;if(ce<=ne){const be=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const Le=d.clientHeight-w.offsetTop-w.offsetHeight,he=Math.max(J,te+(be?$:0)+Le+B),He=ce+he;l.style.height=He+"px"}else{const be=G.length>0&&S===G[0].ref.current;l.style.top="0px";const he=Math.max(ne,D+w.offsetTop+(be?K:0)+te)+ie;l.style.height=he+"px",w.scrollTop=ce-ne+w.offsetTop}l.style.margin=`${ko}px 0`,l.style.minHeight=j+"px",l.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[v,s.trigger,s.valueNode,l,d,w,S,x,s.dir,r]);Xi(()=>k(),[k]);const[N,M]=b.useState();Xi(()=>{d&&M(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(P=>{P&&_.current===!0&&(k(),R==null||R(),_.current=!1)},[k,R]);return m.jsx(iue,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:N},children:m.jsx(wn.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});l4.displayName=nue;var rue="SelectPopperPosition",c1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=ko,...s}=e,o=Nb(n);return m.jsx(xb,{...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)"}})});c1.displayName=rue;var[iue,pk]=ff(iu,{}),u1="SelectViewport",c4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=ac(u1,n),o=pk(u1,n),l=sr(t,s.onViewportChange),u=b.useRef(0);return m.jsxs(m.Fragment,{children:[m.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}),m.jsx(Rb.Slot,{scope:n,children:m.jsx(wn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:$t(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:v}=o;if(v!=null&&v.current&&p){const g=Math.abs(u.current-f.scrollTop);if(g>0){const _=window.innerHeight-ko*2,w=parseFloat(p.style.minHeight),S=parseFloat(p.style.height),x=Math.max(w,S);if(x<_){const R=x+g,k=Math.min(_,R),N=R-k;p.style.height=k+"px",p.style.bottom==="0px"&&(f.scrollTop=N>0?N:0,p.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});c4.displayName=u1;var u4="SelectGroup",[sue,oue]=ff(u4),aue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=ji();return m.jsx(sue,{scope:n,id:i,children:m.jsx(wn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});aue.displayName=u4;var d4="SelectLabel",lue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=oue(d4,n);return m.jsx(wn.div,{id:i.id,...r,ref:t})});lue.displayName=d4;var Py="SelectItem",[cue,f4]=ff(Py),h4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=oc(Py,n),u=ac(Py,n),d=l.value===r,[f,p]=b.useState(s??""),[v,g]=b.useState(!1),_=sr(t,R=>{var k;return(k=u.itemRefCallback)==null?void 0:k.call(u,R,r,i)}),w=ji(),S=b.useRef("touch"),x=()=>{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 m.jsx(cue,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(R=>{p(k=>k||((R==null?void 0:R.textContent)??"").trim())},[]),children:m.jsx(Rb.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(wn.div,{role:"option","aria-labelledby":w,"data-highlighted":v?"":void 0,"aria-selected":d&&v,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:$t(o.onFocus,()=>g(!0)),onBlur:$t(o.onBlur,()=>g(!1)),onClick:$t(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:$t(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:$t(o.onPointerDown,R=>{S.current=R.pointerType}),onPointerMove:$t(o.onPointerMove,R=>{var k;S.current=R.pointerType,i?(k=u.onItemLeave)==null||k.call(u):S.current==="mouse"&&R.currentTarget.focus({preventScroll:!0})}),onPointerLeave:$t(o.onPointerLeave,R=>{var k;R.currentTarget===document.activeElement&&((k=u.onItemLeave)==null||k.call(u))}),onKeyDown:$t(o.onKeyDown,R=>{var N;((N=u.searchRef)==null?void 0:N.current)!==""&&R.key===" "||(Yce.includes(R.key)&&x(),R.key===" "&&R.preventDefault())})})})})});h4.displayName=Py;var ep="SelectItemText",p4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=oc(ep,n),l=ac(ep,n),u=f4(ep,n),d=Zce(ep,n),[f,p]=b.useState(null),v=sr(t,x=>p(x),u.onItemTextChange,x=>{var R;return(R=l.itemTextRefCallback)==null?void 0:R.call(l,x,u.value,u.disabled)}),g=f==null?void 0:f.textContent,_=b.useMemo(()=>m.jsx("option",{value:u.value,disabled:u.disabled,children:g},u.value),[u.disabled,u.value,g]),{onNativeOptionAdd:w,onNativeOptionRemove:S}=d;return Xi(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(wn.span,{id:u.textId,...s,ref:v}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?mu.createPortal(s.children,o.valueNode):null]})});p4.displayName=ep;var m4="SelectItemIndicator",g4=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return f4(m4,n).isSelected?m.jsx(wn.span,{"aria-hidden":!0,...r,ref:t}):null});g4.displayName=m4;var d1="SelectScrollUpButton",v4=b.forwardRef((e,t)=>{const n=ac(d1,e.__scopeSelect),r=pk(d1,e.__scopeSelect),[i,s]=b.useState(!1),o=sr(t,r.onScrollButtonChange);return Xi(()=>{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?m.jsx(b4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});v4.displayName=d1;var f1="SelectScrollDownButton",y4=b.forwardRef((e,t)=>{const n=ac(f1,e.__scopeSelect),r=pk(f1,e.__scopeSelect),[i,s]=b.useState(!1),o=sr(t,r.onScrollButtonChange);return Xi(()=>{if(n.viewport&&n.isPositioned){let l=function(){const d=u.scrollHeight-u.clientHeight,f=Math.ceil(u.scrollTop)<d;s(f)};const u=n.viewport;return l(),u.addEventListener("scroll",l),()=>u.removeEventListener("scroll",l)}},[n.viewport,n.isPositioned]),i?m.jsx(b4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});y4.displayName=f1;var b4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=ac("SelectScrollButton",n),o=b.useRef(null),l=Ab(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Xi(()=>{var f;const d=l().find(p=>p.ref.current===document.activeElement);(f=d==null?void 0:d.ref.current)==null||f.scrollIntoView({block:"nearest"})},[l]),m.jsx(wn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:$t(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:$t(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:$t(i.onPointerLeave,()=>{u()})})}),uue="SelectSeparator",due=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(wn.div,{"aria-hidden":!0,...r,ref:t})});due.displayName=uue;var h1="SelectArrow",fue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Nb(n),s=oc(h1,n),o=ac(h1,n);return s.open&&o.position==="popper"?m.jsx(Sb,{...i,...r,ref:t}):null});fue.displayName=h1;var hue="SelectBubbleInput",_4=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=sr(r,i),o=Hoe(t);return b.useEffect(()=>{const l=i.current;if(!l)return;const u=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&f){const p=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(p)}},[o,t]),m.jsx(wn.select,{...n,style:{...n5,...n.style},ref:s,defaultValue:t})});_4.displayName=hue;function w4(e){return e===""||e===void 0}function x4(e){const t=oa(e),n=b.useRef(""),r=b.useRef(0),i=b.useCallback(o=>{const l=n.current+o;t(l),(function u(d){n.current=d,window.clearTimeout(r.current),d!==""&&(r.current=window.setTimeout(()=>u(""),1e3))})(l)},[t]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function S4(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=pue(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 pue(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var mue=Q3,gue=e4,vue=n4,yue=r4,bue=i4,_ue=s4,wue=c4,xue=h4,Sue=p4,Eue=g4,Cue=v4,kue=y4,[Mb]=Ya("Tooltip",[ic]),Pb=ic(),E4="TooltipProvider",Tue=700,p1="tooltip.open",[Rue,mk]=Mb(E4),C4=e=>{const{__scopeTooltip:t,delayDuration:n=Tue,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=b.useRef(!0),l=b.useRef(!1),u=b.useRef(0);return b.useEffect(()=>{const d=u.current;return()=>window.clearTimeout(d)},[]),m.jsx(Rue,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(u.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(u.current),u.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:b.useCallback(d=>{l.current=d},[]),disableHoverableContent:i,children:s})};C4.displayName=E4;var Dp="Tooltip",[Aue,mm]=Mb(Dp),k4=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=mk(Dp,e.__scopeTooltip),d=Pb(t),[f,p]=b.useState(null),v=ji(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,R]=eu({prop:r,defaultProp:i??!1,onChange:P=>{P?(u.onOpen(),document.dispatchEvent(new CustomEvent(p1))):u.onClose(),s==null||s(P)},caller:Dp}),k=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),N=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,S.current=!1,R(!0)},[R]),M=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,R(!1)},[R]),T=b.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{S.current=!0,R(!0),g.current=0},w)},[w,R]);return b.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),m.jsx(wb,{...d,children:m.jsx(Aue,{scope:t,contentId:v,open:x,stateAttribute:k,trigger:f,onTriggerChange:p,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():N()},[u.isOpenDelayedRef,T,N]),onTriggerLeave:b.useCallback(()=>{_?M():(window.clearTimeout(g.current),g.current=0)},[M,_]),onOpen:N,onClose:M,disableHoverableContent:_,children:n})})};k4.displayName=Dp;var m1="TooltipTrigger",T4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=mm(m1,n),s=mk(m1,n),o=Pb(n),l=b.useRef(null),u=sr(t,l,i.onTriggerChange),d=b.useRef(!1),f=b.useRef(!1),p=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),m.jsx(um,{asChild:!0,...o,children:m.jsx(wn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:$t(e.onPointerMove,v=>{v.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:$t(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:$t(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:$t(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:$t(e.onBlur,i.onClose),onClick:$t(e.onClick,i.onClose)})})});T4.displayName=m1;var gk="TooltipPortal",[Nue,Mue]=Mb(gk,{forceMount:void 0}),R4=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=mm(gk,t);return m.jsx(Nue,{scope:t,forceMount:n,children:m.jsx(yo,{present:n||s.open,children:m.jsx(cf,{asChild:!0,container:i,children:r})})})};R4.displayName=gk;var Qd="TooltipContent",A4=b.forwardRef((e,t)=>{const n=Mue(Qd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=mm(Qd,e.__scopeTooltip);return m.jsx(yo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(N4,{side:i,...s,ref:t}):m.jsx(Pue,{side:i,...s,ref:t})})}),Pue=b.forwardRef((e,t)=>{const n=mm(Qd,e.__scopeTooltip),r=mk(Qd,e.__scopeTooltip),i=b.useRef(null),s=sr(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:p}=r,v=b.useCallback(()=>{l(null),p(!1)},[p]),g=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},R=Due(x,S.getBoundingClientRect()),k=Bue(x,R),N=zue(w.getBoundingClientRect()),M=Fue([...k,...N]);l(M),p(!0)},[p]);return b.useEffect(()=>()=>v(),[v]),b.useEffect(()=>{if(u&&f){const _=S=>g(S,f),w=S=>g(S,u);return u.addEventListener("pointerleave",_),f.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",_),f.removeEventListener("pointerleave",w)}}},[u,f,g,v]),b.useEffect(()=>{if(o){const _=w=>{const S=w.target,x={x:w.clientX,y:w.clientY},R=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),k=!jue(x,o);R?v():k&&(v(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,v]),m.jsx(N4,{...e,ref:s})}),[Iue,Oue]=Mb(Dp,{isInside:!1}),Lue=pse("TooltipContent"),N4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=mm(Qd,n),d=Pb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(p1,f),()=>document.removeEventListener(p1,f)),[f]),b.useEffect(()=>{if(u.trigger){const p=v=>{const g=v.target;g!=null&&g.contains(u.trigger)&&f()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[u.trigger,f]),m.jsx(lf,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:p=>p.preventDefault(),onDismiss:f,children:m.jsxs(xb,{"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:[m.jsx(Lue,{children:r}),m.jsx(Iue,{scope:n,isInside:!0,children:m.jsx(i5,{id:u.contentId,role:"tooltip",children:i||r})})]})})});A4.displayName=Qd;var M4="TooltipArrow",P4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Pb(n);return Oue(M4,n).isInside?null:m.jsx(Sb,{...i,...r,ref:t})});P4.displayName=M4;function Due(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 Bue(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 zue(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 jue(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,f=l.y,p=u.x,v=u.y;f>r!=v>r&&n<(p-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function Fue(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),$ue(t)}function $ue(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 Hue=C4,Uue=k4,Wue=T4,que=R4,Vue=A4,Yue=P4;const I4=b.createContext(!1);function Kue({blocked:e,children:t}){return m.jsx(I4.Provider,{value:e,children:t})}function gm(){return b.useContext(I4)}function Ib({...e}){return m.jsx(Hce,{"data-slot":"popover",...e})}function Ob({...e}){return m.jsx(Uce,{"data-slot":"popover-trigger",...e})}function Lb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=gm();return m.jsx(Wce,{children:m.jsx(qce,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:o||r?!0:void 0,"aria-disabled":o?!0:i,"data-relay-interaction-blocked":o?"true":void 0,...s})})}const q2=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,V2=pz,Gue=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return V2(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 f=n==null?void 0:n[d],p=s==null?void 0:s[d];if(f===null)return null;const v=q2(f)||q2(p);return i[d][v]}),l=n&&Object.entries(n).reduce((d,f)=>{let[p,v]=f;return v===void 0||(d[p]=v),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:p,className:v,...g}=f;return Object.entries(g).every(_=>{let[w,S]=_;return Array.isArray(S)?S.includes({...s,...l}[w]):{...s,...l}[w]===S})?[...d,p,v]:d},[]);return V2(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Xue=Gue("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 pt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?fse:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(Xue({variant:t,size:n,className:e})),...i})}function hf({...e}){return m.jsx(Sce,{"data-slot":"dropdown-menu",...e})}function pf({...e}){return m.jsx(Ece,{"data-slot":"dropdown-menu-trigger",...e})}function mf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=gm();return m.jsx(Cce,{children:m.jsx(kce,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:s||n?!0:void 0,"aria-disabled":s?!0:r,"data-relay-interaction-blocked":s?"true":void 0,...i})})}function Lr({className:e,inset:t,variant:n="default",...r}){return m.jsx(Rce,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function a0({className:e,children:t,checked:n,...r}){return m.jsxs(Ace,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(Nce,{children:m.jsx(ia,{className:"size-4"})})}),t]})}function av({className:e,inset:t,...n}){return m.jsx(Tce,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function zd({className:e,...t}){return m.jsx(Mce,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}const Zue={"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 Yc({variant:e,action:t}){const{heading:n,body:r}=Zue[e];return e==="no-messages"?m.jsx("div",{className:"flex h-full w-full items-center justify-center animate-in fade-in-0 duration-200 motion-reduce:animate-none",children:m.jsx("p",{className:"text-sm text-muted-foreground",children:n})}):m.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:[m.jsx("h2",{className:"text-2xl font-semibold",children:n}),r&&m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}),t&&m.jsx("div",{children:t})]})}const Que={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Jue={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function g1({status:e,className:t}){return m.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",Que[e],t),role:"status","aria-label":Jue[e]})}function gp({name:e,osName:t,className:n,nameClassName:r}){return m.jsxs("span",{className:Ye("min-w-0 flex-1",n),children:[m.jsx("span",{"data-slot":"proxy-name",className:Ye("block truncate text-sm font-normal leading-5",r),children:e}),t&&m.jsx("span",{"data-slot":"proxy-os",className:"block truncate text-xs font-normal leading-4 text-muted-foreground",children:t})]})}function Zi({...e}){return m.jsx(KC,{"data-slot":"dialog",...e})}function ede({...e}){return m.jsx(GC,{"data-slot":"dialog-portal",...e})}function tde({...e}){return m.jsx(gb,{"data-slot":"dialog-close",...e})}function nde({className:e,...t}){return m.jsx(XC,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Qi({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=gm();return m.jsxs(ede,{"data-slot":"dialog-portal",children:[m.jsx(nde,{}),m.jsxs(ZC,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:d=>{i==null||i(d),!(!r||d.defaultPrevented)&&(d.preventDefault(),d.currentTarget.focus({preventScroll:!0}))},inert:u||s?!0:void 0,"aria-disabled":u?!0:o,"data-relay-interaction-blocked":u?"true":void 0,...l,children:[t,n&&m.jsxs(gb,{"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:[m.jsx(fu,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ji({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Ws({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(gb,{asChild:!0,children:m.jsx(pt,{variant:"outline",children:"Close"})})]})}function Fi({className:e,...t}){return m.jsx(P5,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function Ss({className:e,...t}){return m.jsx(I5,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function rde(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function ide({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(Zi,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Qi,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"移除离线开发机?"}),m.jsx(Ss,{children:rde(t)})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(pt,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const Kv=80,sde=8,ode=1.2;function Y2(e){return Math.max(0,Math.min(Kv,e))}function ade({proxyId:e,name:t,osName:n,selected:r,revealed:i,disabled:s=!1,onRevealedChange:o,onRemove:l}){const u=t??e,d=b.useRef(null),f=b.useRef(!1),[p,v]=b.useState(null),g=p??(i?Kv:0),_=p!==null;function w(k){var N,M;if(!(s||k.pointerType!=="touch"&&k.pointerType!=="pen")&&!k.target.closest("button")){d.current={pointerId:k.pointerId,startX:k.clientX,startY:k.clientY,startOffset:i?Kv:0,axis:"pending"};try{(M=(N=k.currentTarget).setPointerCapture)==null||M.call(N,k.pointerId)}catch{}}}function S(k){const N=d.current;if(!N||N.pointerId!==k.pointerId)return;const M=k.clientX-N.startX,T=k.clientY-N.startY;if(N.axis==="pending"){if(Math.hypot(M,T)<sde)return;N.axis=Math.abs(M)>Math.abs(T)*ode?"horizontal":"vertical"}N.axis!=="vertical"&&(k.preventDefault(),v(Y2(N.startOffset-M)))}function x(k,N=!1){var P,z;const M=d.current;if(!M||M.pointerId!==k.pointerId)return;d.current=null;try{(z=(P=k.currentTarget).releasePointerCapture)==null||z.call(P,k.pointerId)}catch{}if(M.axis!=="horizontal"||N){v(null);return}k.preventDefault();const T=p??Y2(M.startOffset-(k.clientX-M.startX));v(null),o(T>=Kv/2),f.current=!0,window.setTimeout(()=>{f.current=!1},0)}function R(k){if(f.current){f.current=!1,k.preventDefault();return}i&&o(!1)}return m.jsxs("li",{className:`relative ${n?"h-14":"h-11"} overflow-hidden rounded-md border border-border bg-card`,"data-slot":"proxy-item","data-swipeable":"true","data-proxy-id":e,"data-online":"false","data-revealed":i||void 0,children:[m.jsxs("div",{className:"relative z-10 flex h-full w-full touch-pan-y select-none items-center gap-3 bg-card px-3 text-left text-muted-foreground transition-transform duration-200 ease-out motion-reduce:transition-none",style:{transform:`translateX(-${g}px)`,transitionDuration:_?"0ms":void 0},title:"这台开发机离线。向左滑动可移除。","data-slot":"proxy-swipe-foreground","data-offset":g,onPointerDown:w,onPointerMove:S,onPointerUp:k=>x(k),onPointerCancel:k=>x(k,!0),onClick:R,children:[m.jsx(g1,{status:"offline"}),m.jsx(gp,{name:u,osName:n}),r&&m.jsx(ia,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}),m.jsx("span",{className:"shrink-0 text-xs",children:"离线"})]}),m.jsx("button",{type:"button",className:`absolute inset-y-0 right-0 z-0 flex w-20 items-center justify-center bg-destructive text-sm font-medium text-white outline-none transition-colors hover:bg-destructive/90 focus-visible:z-20 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50 ${i?"":"pointer-events-none"}`,tabIndex:i?0:-1,disabled:s,"aria-label":`移除 ${u}`,"aria-hidden":i?void 0:!0,"data-slot":"proxy-mobile-remove",onClick:l,children:"移除"})]})}function O4({layout:e,variant:t="default"}){const n=Te(P=>P.proxies),r=Te(P=>P.proxyListLoaded),i=Te(P=>P.relayClientAuthIssue),s=Te(P=>P.selectedProxyId),o=Te(P=>P.proxySwitchTarget),l=cs(),u=Es(),[d,f]=b.useState(!1),[p,v]=b.useState(null),[g,_]=b.useState(null),[w,S]=b.useState(null);async function x(P,z){if(o)return;const V=Ft;if(!V){qe.error("请先连接开发机");return}const U=z??P,G=s!==null&&s!==P;Te.getState().setProxySwitchTarget({proxyId:P,name:U});try{const O=await V.selectProxy(P);if(!O.success){qe.error(`无法连接 ${U}:${O.error??"未知错误"}`);return}const A=V.getPreviewScope();if(!A||A.proxyId!==P||A.bindingId!==O.bindingId)throw Rt.dispose(),V.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Rt.activate(V,A),Rt.syncWebSnapshot(A).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] web preview snapshot failed",L)}),Rt.syncDeviceSnapshot(A).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] device preview snapshot failed",L)}),G&&(Gt.getState().prepareForProxySwitch(U),Vr.getState().prepareForProxySwitch()),Tr("local",Sn.proxyId,P),Te.getState().setProxy(P,z??null),Te.getState().setProxyOnline(!0),Te.getState().transitionToPhase("session_browsing"),V.sendControl({type:"session_list_request"}),V.requestProxyInfo().then(L=>{if(Te.getState().selectedProxyId!==P||!Rt.isActive(V,A))return;const D=Vr.getState();D.setHomePath(L.homePath),D.setAgentCli(L.agentCli),Te.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Rt.isActive(V,A)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),V.requestAgentStatuses().then(L=>{if(Te.getState().selectedProxyId!==P||!Rt.isActive(V,A))return;const D=Gt.getState();for(const I of L)D.setAgentStatus(I.sessionId,I.payload)}).catch(L=>{Rt.isActive(V,A)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),LC(V).then(L=>{L.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",L.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/")||l.pathname.startsWith("/preview/device/"))&&u("/sessions")}catch(O){const A=O instanceof Error?O.message:"未知错误";qe.error(`无法连接 ${U}:${A}`)}finally{Te.getState().setProxySwitchTarget(null)}}function R(P){P.online||w||(v(null),_({proxyId:P.proxyId,...P.name?{name:P.name}:{}}))}async function k(){const P=g;if(!P||w)return;const z=Ft;if(!z){qe.error("Relay 连接不可用,请稍后重试");return}const V=Te.getState().proxies.find(U=>U.proxyId===P.proxyId);if(!V){if(!Te.getState().proxyListLoaded){qe.info("正在重新连接 Relay,请稍后再试");return}mp(P.proxyId,z)&&u("/"),qe.info("这台开发机已经不在列表中"),_(null);return}if(V.online){qe.warning("这台开发机已重新上线,未移除"),_(null);return}S(P.proxyId),tie(P.proxyId);try{const U=await z.removeOfflineProxy(P.proxyId);if(U.success){Rd(P.proxyId),mp(P.proxyId,z)&&u("/"),qe.success(`已移除 ${P.name??P.proxyId}`),_(null);return}if(U.errorCode===Rr.PROXY_ONLINE){Rd(P.proxyId),qe.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(U.errorCode===Rr.PROXY_NOT_FOUND){Rd(P.proxyId),mp(P.proxyId,z)&&u("/"),qe.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Rd(P.proxyId),qe.error(U.error??"无法移除开发机,请重试")}catch(U){qe.error(U instanceof Error?U.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const N=m.jsx(ide,{open:g!==null,target:g,removing:w!==null,onOpenChange:P=>{P||_(null)},onConfirm:()=>void k()});if(e==="page")return i==="missing_client_token"?m.jsx(Yc,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(Yc,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(Yc,{variant:"no-proxy"}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex h-full flex-col gap-3 overflow-auto p-4",children:[m.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"开发机"}),m.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(P=>{const z=(o==null?void 0:o.proxyId)===P.proxyId,V=o!==null;return P.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":P.proxyId,"data-online":"true","data-selecting":z||void 0,disabled:V||w!==null,"aria-busy":z||void 0,onClick:()=>x(P.proxyId,P.name),className:Ye("flex min-h-[44px] w-full items-center gap-3 rounded-md border bg-card px-3 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-card",P.osName?"h-14":"h-11",z?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",V&&!z||w!==null?"opacity-50":""),"aria-pressed":s===P.proxyId,children:[m.jsx(g1,{status:"online"}),m.jsx(gp,{name:P.name??P.proxyId,osName:P.osName}),z?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"正在连接"}),m.jsx(oi,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===P.proxyId?m.jsx(ia,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},P.proxyId):m.jsx(ade,{proxyId:P.proxyId,name:P.name,osName:P.osName,selected:s===P.proxyId,revealed:p===P.proxyId,disabled:V||w!==null,onRevealedChange:U=>v(U?P.proxyId:null),onRemove:()=>R(P)},P.proxyId)})})]}),N]}):m.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:[m.jsx(oi,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const M=n.find(P=>P.proxyId===s),T=(M==null?void 0:M.name)??(M==null?void 0:M.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Ib,{open:d,onOpenChange:f,children:[m.jsx(Ob,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex min-h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 py-1.5 hover:bg-accent"),"aria-label":`当前连接:${T}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx(gp,{name:T,osName:M==null?void 0:M.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(ec,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(Lb,{align:"start",className:"w-[260px] p-1",children:n.length===0?m.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):m.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(P=>{const z=(o==null?void 0:o.proxyId)===P.proxyId,V=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":P.proxyId,"data-online":P.online,"data-selecting":z||void 0,disabled:!P.online||V,"aria-busy":z||void 0,onClick:()=>x(P.proxyId,P.name),className:Ye("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",P.osName?"h-12":"h-9",z?"bg-accent text-accent-foreground":"hover:bg-accent",V&&!z?"opacity-50":"",P.online?"":"opacity-50"),"aria-pressed":s===P.proxyId,title:P.online?void 0:"这台开发机离线",children:[m.jsx(g1,{status:P.online?"online":"offline"}),m.jsx(gp,{name:P.name??P.proxyId,osName:P.osName}),z?m.jsx(oi,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===P.proxyId?m.jsx(ia,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!P.online&&!z&&m.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]}),!P.online&&m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:V||w!==null,"aria-label":`${P.name??P.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsx(mf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(Lr,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:U=>{U.stopPropagation(),R(P)},children:[m.jsx(dz,{"aria-hidden":"true"}),"移除开发机"]})})]})]},P.proxyId)})})})]}),N]})}function lde({delayDuration:e=0,...t}){return m.jsx(Hue,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function gf({...e}){return m.jsx(Uue,{"data-slot":"tooltip",...e})}function vf({...e}){return m.jsx(Wue,{"data-slot":"tooltip-trigger",...e})}function yf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(que,{children:m.jsxs(Vue,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(Yue,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function lc({...e}){return m.jsx(KC,{"data-slot":"sheet",...e})}function cde({...e}){return m.jsx($oe,{"data-slot":"sheet-trigger",...e})}function ude({...e}){return m.jsx(GC,{"data-slot":"sheet-portal",...e})}function dde({className:e,...t}){return m.jsx(XC,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function cc({className:e,overlayClassName:t,children:n,side:r="right",showCloseButton:i=!0,focusSurfaceOnOpen:s=!1,onOpenAutoFocus:o,inert:l,"aria-disabled":u,...d}){const f=gm();return m.jsxs(ude,{children:[m.jsx(dde,{className:t}),m.jsxs(ZC,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:p=>{o==null||o(p),!(!s||p.defaultPrevented)&&(p.preventDefault(),p.currentTarget.focus({preventScroll:!0}))},inert:f||l?!0:void 0,"aria-disabled":f?!0:u,"data-relay-interaction-blocked":f?"true":void 0,...d,children:[n,i&&m.jsxs(gb,{"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:[m.jsx(fu,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function yu({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function uc({className:e,...t}){return m.jsx(P5,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function Db({className:e,...t}){return m.jsx(I5,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}const fde={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"},K2=["claude","codex","kimi"];function Bb(e){return fde[e]}function L4(e,t){return K2.indexOf(e)-K2.indexOf(t)}function Bp(e){return e.provider}const v1=60*1e3,y1=60*v1,hde=24*y1;function D4(e,t=Date.now()){const n=t-e;if(n<v1)return"刚刚";if(n<y1)return`${Math.floor(n/v1)} 分钟前`;if(n<hde)return`${Math.floor(n/y1)} 小时前`;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 G2={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 b1(e){return e.kind!=="terminal"?G2[e.state]:e.state==="terminated"?G2.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 pde({session:e}){const t=b1(e);return m.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function mde({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?fC:pC;return m.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:m.jsx(n,{className:"size-3.5","aria-hidden":"true"})})}function gde({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=Vr(w=>w.homePath),l=e.lastActive,u=e.cwd,d=jC(e.name,o),f=FC(e,o),p=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),v=D4(l,n),g=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return m.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&m.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),m.jsxs("button",{type:"button","data-slot":"session-row-select",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:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx(pde,{session:e}),m.jsx("span",{className:"text-sm font-normal truncate flex-1",title:u,children:p})]}),m.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[m.jsx(mde,{mode:e.mode}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Bb(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:Ye("shrink-0",b1(e).text),children:b1(e).label}),v&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:v})]})]})]}),(i||s)&&m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"会话操作","data-slot":"session-row-menu-trigger",onClick:w=>w.stopPropagation(),children:m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(Lr,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(Lr,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function mo(e){const[t,n]=b.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(e).matches);return b.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const r=window.matchMedia(e),i=s=>n(s.matches);return n(r.matches),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),t}function vde({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(yde,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:D4(e.updatedAt,t)}),u=m.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return m.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:m.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(Q7,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function yde({title:e,modeTag:t}){return m.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[m.jsx("span",{className:"text-sm font-normal truncate min-w-0",title:e,children:e}),t&&m.jsx(bde,{mode:t})]})}function bde({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?fC:pC;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function B4({providerLabel:e}){return m.jsx("div",{className:"grid min-w-0 gap-4","data-slot":"bypass-permission-warning",role:"alert",children:m.jsxs("div",{className:"flex min-w-0 items-start gap-3 text-sm",children:[m.jsx(qY,{className:"mt-0.5 size-5 shrink-0 text-destructive","aria-hidden":"true"}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsxs("p",{className:"font-medium text-foreground",children:[e," 将不再请求工具审批。"]}),m.jsx("p",{className:"text-muted-foreground",children:"Agent 可以直接执行命令、修改或删除文件,并可能绕过部分沙箱保护。"})]})]})})}function _de({now:e}){const t=Vr(O=>O.homePath),n=Gt(O=>O.historySessions),r=Gt(O=>O.historyLoadStatus),[i,s]=b.useState(null),[o,l]=b.useState(null),[u,d]=b.useState("json"),[f,p]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(new Set),[S,x]=b.useState(new Set),R=Es(),k=b.useMemo(()=>{const O=new Map;for(const A of n){const L=Bp(A);let D=O.get(L);D||(D=new Map,O.set(L,D));const I=z4(A.projectDir),B=D.get(I);B?B.sessions.push(A):D.set(I,{dir:I,sessions:[A]})}return Array.from(O.entries()).sort(([A],[L])=>L4(A,L)).map(([A,L])=>({provider:A,sessions:Array.from(L.values()).flatMap(D=>D.sessions),projects:Array.from(L.values()).map(D=>({dir:D.dir,shortDir:om(D.dir,t,{compact:!0}),sessions:D.sessions}))}))},[n,t]);function N(O){l(O),d(wde(O)),p(xde(O))}async function M(O,A,L){if(i)return;const D=Ft;if(!D){qe.error("请先连接开发机");return}s(O.id);const I=Bp(O);try{const B=await D.createSession({kind:"agent",cwd:O.projectDir,mode:A,provider:I,resumeSessionId:O.id,...L?{permissionMode:L}:{}});if(!B.success){if(B.errorCode===Rr.SESSION_ALREADY_ACTIVE){Gt.getState().setCodexActiveWriterConflict({...B.activeWriterPid?{activeWriterPid:B.activeWriterPid}:{}}),l(null);return}qe.error(`恢复失败:${B.error}`);return}if(B.kind!=="agent"){qe.error("恢复失败:开发机返回了错误的会话类型");return}const F={sessionId:B.sessionId,kind:"agent",...B.name!==void 0?{name:B.name}:{},...B.nameLocked!==void 0?{nameLocked:B.nameLocked}:{},state:"idle",cwd:B.cwd,lastActive:B.lastActive,provider:B.provider},Y=B.mode==="pty"?{...F,mode:"pty",ptyOwner:B.ptyOwner}:{...F,mode:"json"};Gt.getState().addSession(Y),R(`/chat/${B.sessionId}?mode=${B.mode}`),l(null)}catch(B){qe.error(`恢复失败:${B instanceof Error?B.message:String(B)}`)}finally{s(null)}}function T(){const O=Ft;!O||Gt.getState().historyLoadStatus==="loading"||LC(O).then(A=>{A.status==="failed"&&qe.error(A.error instanceof Error?A.error.message:String(A.error))})}function P(O,A){const L=X2(O,A);x(D=>{const I=new Set(D);return I.has(L)?I.delete(L):I.add(L),I})}function z(O){w(A=>{const L=new Set(A);return L.has(O)?L.delete(O):L.add(O),L})}const V=n.length>0,U=r==="loading",G=o?j4():[];return m.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[m.jsxs("div",{className:"flex min-h-11 w-full items-center gap-1.5 px-4 py-1.5 md:min-h-[36px]",children:[m.jsxs("button",{type:"button",onClick:()=>V&&g(O=>!O),disabled:!V,"aria-expanded":V?v:void 0,"data-slot":"history-section-header","data-expanded":v,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",V?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),V?m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",v&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(pt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":U,title:U?"正在加载":"刷新",onClick:T,disabled:U,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(nm,{className:Ye("size-3.5",U&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!V&&U&&m.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-loading",role:"status","aria-live":"polite",children:[m.jsx(oi,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!V&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!V&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),V&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!V&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),V&&v&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(O=>{const A=_.has(O.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>z(O.provider),"aria-expanded":!A,"data-slot":"history-provider-header","data-expanded":!A,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:Bb(O.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:O.sessions.length}),m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!A&&"rotate-90"),"aria-hidden":"true"})]}),!A&&m.jsx("ul",{role:"list",className:"flex flex-col",children:O.projects.map(L=>{const D=X2(O.provider,L.dir),I=S.has(D);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>P(O.provider,L.dir),"aria-expanded":I,"data-slot":"history-group-header","data-expanded":I,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:L.dir,children:L.shortDir}),m.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:L.sessions.length}),m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",I&&"rotate-90"),"aria-hidden":"true"})]}),I&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(B=>m.jsx(vde,{session:B,now:e,disabled:i!==null,loading:i===B.id,onClick:()=>N(B),modeTag:B.preferredMode},B.id))})]},D)})})]},O.provider)})}),m.jsx(Sde,{session:o,open:o!==null,modes:G,mode:u,permissionMode:f,submitting:i!==null,onOpenChange:O=>{O||l(null)},onModeChange:d,onPermissionModeChange:p,onConfirm:()=>{o&&M(o,u,f)}})]})}function X2(e,t){return`${e}:${z4(t)}`}function z4(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function j4(){return["json","pty"]}function wde(e){const t=j4();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function xde(e){return Bp(e)==="codex"?"auto":"default"}function Sde({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[f,p]=b.useState(!1),v=i==="bypassPermissions",g=mo("(min-width: 768px)"),_=e?Bp(e):null,w=_==="codex",S=_==="kimi";b.useEffect(()=>{t||p(!1)},[t]);const x=f?m.jsx(B4,{providerLabel:e?Bb(Bp(e)):"Agent"}):m.jsxs("div",{className:"grid min-w-0 gap-4",children:[m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"恢复模式",className:"grid min-w-0 grid-cols-2 gap-2",children:[n.includes("json")&&m.jsx(Z2,{checked:r==="json",label:"聊天",icon:m.jsx(fC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(Z2,{checked:r==="pty",label:"终端",icon:m.jsx(pC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("pty")})]})]}),m.jsxs("div",{className:"grid min-w-0 gap-2",children:[m.jsx("span",{className:"text-sm font-medium",children:"权限模式"}),m.jsxs("div",{role:"radiogroup","aria-label":"权限模式",className:"grid min-w-0 gap-2",children:[!w&&m.jsx(lv,{checked:i==="default",label:S?"手工审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),m.jsx(lv,{checked:i==="auto",label:w?"按需审批":S?"自动审批":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),S&&m.jsx(lv,{checked:i==="plan",label:"只读规划",description:"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(lv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),R=m.jsxs(m.Fragment,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?p(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(pt,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(v&&!f){p(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return g?m.jsx(Zi,{open:t,onOpenChange:o,children:m.jsxs(Qi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Ji,{className:"min-w-0",children:[m.jsx(Fi,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Ss,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),x,m.jsx(Ws,{children:R})]})}):m.jsx(lc,{open:t,onOpenChange:o,children:m.jsxs(cc,{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:[m.jsxs(yu,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(uc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Db,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),m.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:x}),m.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:m.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:R})})]})})}function Z2({checked:e,label:t,icon:n,disabled:r,onClick:i}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(ia,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function lv({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),m.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&m.jsx(ia,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function zb({...e}){return m.jsx(mue,{"data-slot":"select",...e})}function jb({...e}){return m.jsx(vue,{"data-slot":"select-value",...e})}function Fb({className:e,size:t="default",children:n,...r}){return m.jsxs(gue,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(yue,{asChild:!0,children:m.jsx(ec,{className:"size-4 opacity-50"})})]})}function $b({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=gm();return m.jsx(bue,{children:m.jsxs(_ue,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,inert:l||i?!0:void 0,"aria-disabled":l?!0:s,"data-relay-interaction-blocked":l?"true":void 0,...o,children:[m.jsx(Ede,{}),m.jsx(wue,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(Cde,{})]})})}function Hb({className:e,children:t,...n}){return m.jsxs(xue,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(Eue,{children:m.jsx(ia,{className:"size-4"})})}),m.jsx(Sue,{children:t})]})}function Ede({className:e,...t}){return m.jsx(Cue,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(uC,{className:"size-4"})})}function Cde({className:e,...t}){return m.jsx(kue,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(ec,{className:"size-4"})})}function kde(e,t,n){var u;if(t==="insert"){const d=e.split("@").pop()??"",f=Jc((n==null?void 0:n.baseCwd)??d)==="\\",p=Math.max(d.lastIndexOf("/"),f?d.lastIndexOf("\\"):-1);return{currentPath:p>=0?d.slice(0,p+1):f?".\\":"./",query:d.slice(p+1).toLowerCase()}}const r=ea((n==null?void 0:n.baseCwd)??"");if(!e)return{currentPath:lo(r),query:""};const i=ab(r,e);if(!i)return{currentPath:"",query:""};const s=IC(i),o=Jc(i);return e.endsWith("/")||o==="\\"&&e.endsWith("\\")||i===s||i===r||((u=n==null?void 0:n.knownDirs)==null?void 0:u.has(i))?{currentPath:lo(i),query:""}:{currentPath:lo(s),query:i.slice(i.lastIndexOf(o)+1).toLowerCase()}}function l0(e,t){return ab(e,t)}const F4=b.forwardRef(function({filter:t,onSelect:n,onNavigate:r,onSelectCurrentDirectory:i,onCreateDirectory:s,mode:o="insert",placement:l="floating",dirsOnly:u=!1,fileExtensions:d,includeHidden:f=!1,autoHighlightFirst:p=!0,title:v},g){const _=Vr(he=>f?he.treeWithHidden:he.tree),w=Vr(he=>he.cwd),S=Vr(he=>he.homePath),x=o==="insert"?w:S||w,R=b.useMemo(()=>new Set(_.keys()),[_]),k=b.useMemo(()=>kde(t,o,{baseCwd:x,knownDirs:R}),[t,o,x,R]),N=k.currentPath,M=b.useMemo(()=>l0(x,N),[x,N]),T=k.query,P=b.useRef(new Map),[z,V]=b.useState(!1),[U,G]=b.useState(""),[O,A]=b.useState(!1),[L,D]=b.useState(null),[I,B]=b.useState(0);b.useEffect(()=>{if(!M)return;const he=`${f?"hidden":"default"}\0${M}`;if(_.has(M))return;const He=Ft;if(!He)return;let Pt=!1;D(it=>(it==null?void 0:it.path)===M?null:it);let Ge=P.current.get(he);if(!Ge){Ge=He.requestDirectoryList(M,{includeHidden:f}),P.current.set(he,Ge);const it=()=>{P.current.get(he)===Ge&&P.current.delete(he)};Ge.then(it,it)}return Ge.then(it=>{if(!Pt){if(it.error!==void 0||it.errorCode!==void 0){D({path:M,message:it.error||"读取失败"});return}Vr.getState().setDirEntries(it.path,it.entries,it.includeHidden)}},it=>{Pt||D({path:M,message:it instanceof Error?it.message:"读取失败"})}),()=>{Pt=!0}},[M,f,_,I]);const F=(L==null?void 0:L.path)===M?L:null,Y=!_.has(M)&&!F,j=b.useMemo(()=>d==null?void 0:d.map(he=>he.startsWith(".")?he.toLowerCase():`.${he.toLowerCase()}`),[d]),q=b.useMemo(()=>{let he=_.get(M)??[];return u?he=he.filter(He=>He.isDir):j!=null&&j.length&&(he=he.filter(He=>He.isDir||j.some(Pt=>He.name.toLowerCase().endsWith(Pt)))),T&&(he=he.filter(He=>He.name.toLowerCase().includes(T))),he},[_,M,T,u,j]),[K,$]=b.useState(p?0:-1);b.useEffect(()=>$(p?0:-1),[p,N,T]),b.useEffect(()=>{V(!1),G("")},[M]),b.useEffect(()=>{K>=q.length&&q.length>0&&$(q.length-1)},[q.length,K]);const ne=b.useRef(null),J=b.useRef(!1);b.useEffect(()=>{var He;if(!J.current)return;J.current=!1;const he=(He=ne.current)==null?void 0:He.querySelector(`[data-entry-index="${K}"]`);he==null||he.scrollIntoView({block:"nearest"})},[K]);const te=b.useCallback(he=>{const He=Jc(x),Pt=`${lo(N,x)}${he.name}${he.isDir?He:""}`;if(o==="insert")return Pt.replace(He==="\\"?/^\.[\\/]/:/^\.\//,"");const Ge=l0(x,Pt);return he.isDir?lo(Ge):Ge},[x,N,o]),Q=b.useCallback(he=>{const He=l0(x,he);if(!He)return;const Pt=lo(He);if(o==="select"){r(Pt);return}n(Pt)},[x,o,r,n]),ce=b.useCallback(he=>{const He=te(he);if(he.isDir){Q(He);return}n(He)},[te,Q,n]);async function ie(){const he=YP(M,U);if(!(!he||!s)){A(!0);try{const He=await s(he);if(!He)return;if(G(""),V(!1),i){i(lo(He));return}Q(He)}finally{A(!1)}}}b.useImperativeHandle(g,()=>({handleKey(he){return q.length===0?!1:he.key==="ArrowDown"?(J.current=!0,$(He=>Math.min(q.length-1,He+1)),!0):he.key==="ArrowUp"?(J.current=!0,$(He=>Math.max(0,He-1)),!0):he.key==="Enter"&&K>=0&&!he.nativeEvent.isComposing?(ce(q[K]),!0):!1}}),[q,K,ce]);const le=b.useMemo(()=>IC(M),[M]),be=l==="inline"?"relative w-full bg-popover border border-border rounded-md overflow-hidden":o==="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",Le=l==="inline"?"max-h-[min(11rem,30dvh)] overflow-y-auto overscroll-contain":o==="select"?"max-h-44 overflow-y-auto overscroll-contain":"max-h-60 overflow-y-auto overscroll-contain";return m.jsxs("div",{className:be,"data-slot":"file-path-picker","data-mode":o,"data-placement":l,children:[o==="select"?m.jsxs("div",{className:"border-b border-border/70 px-3 py-2",children:[m.jsxs("div",{className:"min-w-0",children:[v?m.jsx("p",{className:"mb-2 truncate text-xs text-muted-foreground","data-slot":"file-path-picker-title",children:v}):null,m.jsx("p",{className:"truncate font-mono text-xs text-foreground","data-slot":"file-path-picker-current-directory",title:M,children:om(M,S)||"正在读取路径"})]}),m.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",role:"toolbar","aria-label":"路径操作","data-slot":"file-path-picker-actions",children:[m.jsx("button",{type:"button","data-slot":"file-path-picker-parent",className:"inline-flex min-h-11 min-w-11 items-center justify-start px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",disabled:!M||M===le,onClick:()=>Q(le),children:"上一级"}),i||s?m.jsxs("span",{className:"flex shrink-0 items-center gap-4",children:[s?m.jsx("button",{type:"button","data-slot":"file-path-picker-create-directory-toggle",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",disabled:!M||O,onClick:()=>V(he=>!he),children:"新建目录"}):null,i?m.jsx("button",{type:"button","data-slot":"select-current-directory",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",disabled:!M,onClick:()=>i(lo(M)),children:"选定"}):null]}):null]}),z?m.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[m.jsx("input",{type:"text","data-slot":"file-path-picker-create-directory-name",value:U,onChange:he=>G(he.target.value),onKeyDown:he=>{he.key==="Enter"&&!he.nativeEvent.isComposing&&(he.preventDefault(),ie()),he.key==="Escape"&&(V(!1),G(""))},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}),m.jsx("button",{type:"button","data-slot":"file-path-picker-create-directory-submit",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:!YP(M,U)||O,onClick:()=>void ie(),children:O?"创建中...":"创建目录"})]}):null]}):null,m.jsx("div",{className:Le,"data-slot":"file-path-picker-entries",children:F?m.jsxs("div",{"data-slot":"file-path-picker-error",className:"flex items-center justify-between gap-3 px-3 py-2",role:"alert",children:[m.jsx("span",{className:"min-w-0 text-xs text-destructive",title:F.message,children:"无法读取这个文件夹"}),m.jsx("button",{type:"button","data-slot":"file-path-picker-retry",className:"shrink-0 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",onClick:()=>B(he=>he+1),children:"重试"})]}):q.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:Y?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:ne,role:"list",className:"flex flex-col",children:q.map((he,He)=>m.jsx("li",{children:m.jsx("button",{type:"button",onClick:()=>ce(he),onMouseEnter:()=>$(He),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",He===K&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",he.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":he.isDir?"dir":"file","data-entry-name":he.name,"data-entry-index":He,children:m.jsxs("span",{className:"font-mono text-[13px]",children:[he.name,he.isDir?"/":""]})})},he.name))})})]})});function Q2(e,t,n){const r=Gv(e,t);return r?n==="file"?lo(IC(r)):r:t}function Gv(e,t){const n=ea(e,t);return n?e.endsWith("/")||Jc(n)==="\\"&&e.endsWith("\\")?lo(n):n:""}function vk({value:e,onValueChange:t,selectionKind:n,fileExtensions:r,includeHidden:i=!1,onCreateDirectory:s,disabled:o=!1,placeholder:l="选择路径",label:u,labelActions:d,id:f,name:p,required:v,autoFocus:g,"aria-describedby":_,"aria-invalid":w,"data-slot":S,className:x,onKeyDown:R}){const k=b.useId(),N=f??`remote-path-${k}`,M=`${N}-label`,T=Vr(J=>J.homePath),P=mo("(pointer: coarse), (hover: none)"),z=af().deviceKind,V=P||z==="phone"||z==="tablet",[U,G]=b.useState(!1),[O,A]=b.useState(()=>Q2(e,T,n)),[L,D]=b.useState(e),I=b.useRef(null),B=b.useRef(null);b.useEffect(()=>{U||L===e||D(e)},[L,U,e]),b.useEffect(()=>{if(!U)return;function J(te){const Q=I.current,ce=te.target;Q&&(te.composedPath().includes(Q)||ce instanceof Node&&Q.contains(ce))||(G(!1),D(e))}return document.addEventListener("click",J),()=>document.removeEventListener("click",J)},[U,e]),b.useEffect(()=>{o&&(G(!1),D(e))},[o,e]);const F=n!=="file";function Y(){if(o)return;const J=Q2(e,T,n);A(J),D(e),G(!0)}function j(){G(!1),D(e)}function q(J){const te=Gv(J,T);te&&(A(te),D(te),t(te),G(!1))}function K(J){const te=Gv(J,T);te&&A(te)}function $(J){var te;if(U&&((te=B.current)!=null&&te.handleKey(J))){J.preventDefault();return}if(J.key==="Escape"&&U){J.preventDefault(),j();return}R==null||R(J)}const ne=U?m.jsx("div",{className:Ye(V&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(F4,{ref:B,mode:"select",placement:V?"inline":"floating",filter:O,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!V,title:l,onNavigate:K,onSelect:q,onSelectCurrentDirectory:F?q:void 0,onCreateDirectory:s})}):null;return m.jsxs("div",{className:Ye("flex min-w-0 flex-col gap-1",x),children:[m.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[m.jsx("span",{id:M,className:"min-w-0 text-sm",children:u}),d?m.jsx("div",{className:"flex shrink-0 items-center gap-4",children:d}):null]}),m.jsx("div",{ref:I,className:"relative min-w-0",onBlur:J=>{if(!U||V)return;const te=J.relatedTarget;te instanceof Node&&J.currentTarget.contains(te)||window.setTimeout(()=>{var Q;(Q=I.current)!=null&&Q.contains(document.activeElement)||j()},0)},children:V?m.jsxs(m.Fragment,{children:[m.jsxs("button",{id:N,type:"button","aria-labelledby":M,"aria-describedby":_,"aria-invalid":w,"aria-expanded":U,"aria-controls":`${N}-browser`,disabled:o,"data-slot":S,"data-path-control":"button",onClick:()=>{U?j():Y()},className:"flex min-h-11 w-full min-w-0 items-center gap-2 rounded-md border border-border bg-input px-3 text-left text-base outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",children:[m.jsx(WV,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsx("span",{className:Ye("min-w-0 flex-1 truncate font-mono",e?"text-foreground":"text-muted-foreground"),title:e||void 0,children:om(e,T)||l})]}),p?m.jsx("input",{type:"hidden",name:p,value:e,required:v}):null,m.jsx("div",{id:`${N}-browser`,children:ne})]}):m.jsxs(m.Fragment,{children:[m.jsx("input",{id:N,type:"text","aria-labelledby":M,"aria-describedby":_,"aria-invalid":w,name:p,required:v,autoFocus:g,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:Y,onChange:J=>{const te=J.target.value,Q=Gv(te,T);D(te),A(Q||T),t(Q||te),G(!0)},onKeyDown:$,placeholder:l,className:"min-h-11 min-w-0 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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"}),ne]})})]})}const J2="工作目录不存在或不可访问:",Tde=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],$4=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],H4=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],zp={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"};function Rde(e,t){return t!==Rr.PATH_NOT_FOUND||!e.startsWith(J2)?null:e.slice(J2.length).trim()||null}function U4(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 Ade(e,t){return e==="codex"?$4.some(n=>n.value===t)?t:"auto":e==="kimi"?H4.some(n=>n.value===t)?t:"default":t}async function Nde({relay:e,agentCli:t,form:n,timeoutMs:r=MC}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(U4(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?`${zp[n.provider]} 不可用:${p}`:`${zp[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.success){const w=Rde(p.error,p.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${p.error}`}}if(p.kind!=="agent")return{type:"create_error",message:"创建失败:开发机返回了错误的会话类型"};const v=((f=p.name)==null?void 0:f.trim())||void 0,g={sessionId:p.sessionId,kind:"agent",name:v,...p.nameLocked!==void 0?{nameLocked:p.nameLocked}:{},state:"idle",cwd:p.cwd,lastActive:p.lastActive,provider:p.provider};return{type:"success",session:p.mode==="pty"?{...g,mode:"pty",ptyOwner:p.ptyOwner}:{...g,mode:"json"},route:`/chat/${p.sessionId}?mode=${p.mode}`}}catch(p){return{type:"exception",message:p instanceof Error?p.message:String(p)}}}async function Mde({relay:e,shell:t,timeoutMs:n=MC}){var r;if(!e)return{type:"relay_missing",message:"请先连接开发机"};try{const i=await e.createSession({kind:"terminal",mode:"pty",...t?{shell:t}:{}},n);return i.success?i.kind!=="terminal"?{type:"create_error",message:"创建终端失败:开发机返回了错误的会话类型"}:{type:"success",session:{sessionId:i.sessionId,kind:"terminal",name:((r=i.name)==null?void 0:r.trim())||void 0,...i.nameLocked!==void 0?{nameLocked:i.nameLocked}:{},state:"idle",cwd:i.cwd,lastActive:i.lastActive,mode:"pty",provider:i.provider,ptyOwner:i.ptyOwner},route:`/chat/${i.sessionId}?mode=pty`}:{type:"create_error",message:`创建终端失败:${i.error}`}}catch(i){return{type:"exception",message:i instanceof Error?i.message:String(i)}}}const Pde=["claude","codex","kimi"];function Ide({agentCli:e,provider:t,cliPathDraftProvider:n,cliPathDraft:r,savingCliPath:i,onProviderChange:s,onCliPathDraftChange:o,onDiscardCliPathDraft:l,onSaveCliPath:u}){const d=e==null?void 0:e[t],f=(d==null?void 0:d.command)??"",p=n===t,v=p?r:f,g=p&&r.trim()!==f;return m.jsxs("section",{"aria-label":"Agent CLI",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"Agent CLI"}),m.jsxs(zb,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(Fb,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(jb,{})}),m.jsx($b,{"data-slot":"agent-cli-provider-options",children:Pde.map(_=>m.jsx(Hb,{value:_,className:"min-h-11 md:min-h-0",children:zp[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(vk,{id:`agent-cli-path-${t}`,"data-slot":"agent-cli-path",label:"CLI 路径",value:v,onValueChange:_=>o(t,_),selectionKind:"file",includeHidden:!0,disabled:i,placeholder:"选择 CLI 可执行文件",labelActions:g?m.jsxs("div",{className:"flex items-center gap-4","data-slot":"agent-cli-path-actions",children:[m.jsx("button",{type:"button",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-muted-foreground hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:no-underline md:min-h-8 md:min-w-0",onClick:l,disabled:i,children:"取消"}),m.jsx("button",{type:"button",className:"inline-flex min-h-11 min-w-11 items-center justify-center px-0 text-xs font-medium text-primary hover:underline focus-visible:underline focus-visible:outline-none disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline md:min-h-8 md:min-w-0",onClick:u,disabled:i||!r.trim(),children:i?"保存中...":"保存"})]}):void 0,onKeyDown:_=>{_.key==="Enter"&&g&&(_.preventDefault(),_.stopPropagation(),u()),_.key==="Escape"&&p&&(_.preventDefault(),_.stopPropagation(),l())}},t),d!=null&&d.error&&!g?m.jsx("p",{className:"mt-1 break-all text-xs text-destructive",children:d.error}):null]})]})}function tp({open:e,onOpenChange:t}){var Q;const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,p]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[R,k]=b.useState(null),[N,M]=b.useState(""),[T,P]=b.useState(!1),z=b.useRef(e);z.current=e;const V=Es(),U=Vr(ce=>ce.homePath),G=Vr(ce=>ce.agentCli),O=mo("(min-width: 768px)");b.useEffect(()=>{e&&!i&&U&&s(U)},[e,U,i]),b.useEffect(()=>{if(!e||U&&G)return;const ce=Ft==null?void 0:Ft.requestProxyInfo();ce&&ce.then(ie=>{const le=Vr.getState();le.setHomePath(ie.homePath),le.setAgentCli(ie.agentCli)}).catch(ie=>{console.error("[create-session-dialog] requestProxyInfo failed",ie)})},[e,U,G]);function A(){r(""),s(""),l("claude"),d("pty"),p("default"),g(!1),x(null),k(null),M(""),P(!1)}function L(){if(f==="bypassPermissions"){g(!0);return}q()}async function D(){await q(),z.current&&g(!1)}const I=o==="codex"?$4:o==="kimi"?H4:Tde,B=U4(o,G),F=R===o&&N.trim()!==(((Q=G==null?void 0:G[o])==null?void 0:Q.command)??""),Y=_||T||B.disabled||F;function j(ce){const ie=Ade(ce,f);ie!==f&&p(ie)}async function q(ce){x(null),w(!0);try{const ie=await Nde({relay:Ft,agentCli:G,form:{cwd:ce??i,name:n,provider:o,permissionMode:f,mode:u}});if(ie.type==="success"){if(Gt.getState().addSession(ie.session),!z.current)return;t(!1),A(),V(ie.route);return}if(ie.type==="missing_cwd"&&x(ie.path),qe.error(ie.message),ie.type==="validation_error"||ie.type==="relay_missing")return}finally{w(!1)}}async function K(ce){const ie=Ft;if(!ie)return qe.error("请先连接开发机"),null;try{const le=await ie.createDirectory(ce);return le.success?(x(null),qe.success("目录已创建"),le.path):(qe.error(`目录创建失败:${le.error??"未知错误"}`),null)}catch(le){return qe.error(le instanceof Error?le.message:String(le)),null}}function $(ce,ie){k(ce),M(ie)}async function ne(){if(!R)return;const ce=R,ie=N.trim();if(!ie){qe.error("请选择 Agent CLI 可执行文件");return}const le=Ft;if(!le){qe.error("请先连接开发机");return}P(!0);try{const be=await le.updateAgentCliPath(ce,ie);if(be.error||!be.agentCli){qe.error(`路径保存失败:${be.error??"未知错误"}`);return}Vr.getState().setAgentCli(be.agentCli),qe.success(`${zp[ce]} 路径已保存`),k(null),M("")}catch(be){qe.error(be instanceof Error?be.message:String(be))}finally{P(!1)}}function J(ce){d(ce),j(o)}const te=v?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(B4,{providerLabel:zp[o]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:_,children:"返回"}),m.jsx(pt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void D(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:ce=>{ce.preventDefault(),L()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:ce=>r(ce.target.value),className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring md:h-9 md:min-h-0 md:text-sm",placeholder:"自动生成"})]}),m.jsx(vk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:i,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:K,onValueChange:ce=>{s(ce),x(null)}}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>J("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>J("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(Ide,{agentCli:G,provider:o,cliPathDraftProvider:R,cliPathDraft:N,savingCliPath:T,onProviderChange:ce=>{l(ce),j(ce),k(null),M("")},onCliPathDraftChange:$,onDiscardCliPathDraft:()=>{k(null),M("")},onSaveCliPath:()=>void ne()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(zb,{value:f,onValueChange:ce=>p(ce),children:[m.jsx(Fb,{className:"w-full",children:m.jsx(jb,{})}),m.jsx($b,{children:I.map(ce=>m.jsx(Hb,{value:ce.value,children:ce.label},ce.value))})]})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(pt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:Y,children:_?"创建中...":"创建"})]})]});return O?m.jsx(Zi,{open:e,onOpenChange:t,children:m.jsxs(Qi,{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:[m.jsx(Ji,{children:m.jsx(Fi,{children:v?"跳过全部审批?":"新建会话"})}),te]})}):m.jsx(lc,{open:e,onOpenChange:t,children:m.jsxs(cc,{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:[m.jsx(yu,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(uc,{children:v?"跳过全部审批?":"新建会话"})}),te]})})}function np({open:e,sessionId:t,initialName:n,onOpenChange:r,onRename:i}){const s=b.useMemo(()=>(n==null?void 0:n.trim())??"",[n]),[o,l]=b.useState(s),[u,d]=b.useState(null),[f,p]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),p(!1))},[s,e]);async function v(g){g.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){p(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{p(!1)}}}return m.jsx(Zi,{open:e,onOpenChange:r,children:m.jsx(Qi,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>void v(g),children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"重命名会话"}),m.jsx(Ss,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),m.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:f,onChange:g=>{l(g.target.value),u&&d(null)}}),u?m.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(pt,{type:"submit",disabled:f,children:"保存"})]})]})})})}function Ode(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function Lde(e){return(e==null?void 0:e.kind)==="terminal"}function Dde(e){return Ode(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Lde(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function cv({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Dde(t);function s(){t&&(r(t),n(!1))}return m.jsx(Zi,{open:e,onOpenChange:n,children:m.jsxs(Qi,{"data-slot":"session-termination-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:i.title}),m.jsx(Ss,{children:i.description})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(pt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function W4(e){var t,n,r,i,s,o,l,u,d,f,p,v;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"||((f=e.agentStatus)==null?void 0:f.phase)==="tool_use"||((p=e.agentStatus)==null?void 0:p.phase)==="outputting"||((v=e.ptyState)==null?void 0:v.state)==="working"?"working":"idle"}function Bde(e){if(e.session.state==="error")return"error";const t=W4(e);return t==="disconnected"?e.session.state:t}const zde=new Set(["localhost","127.0.0.1","[::1]"]),_1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function jde(){return Ci("local",Sn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function q4(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function c0(e,t){var n;return((n=q4(e,t))==null?void 0:n.available)===!0}function Fde(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!zde.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Ch(){return{status:"idle"}}function $de({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(jde),[o,l]=b.useState("local"),[u,d]=b.useState(""),[f,p]=b.useState(""),[v,g]=b.useState(""),[_,w]=b.useState(Ch),[S,x]=b.useState(!1),R=b.useRef(null),k=b.useRef(null),N=b.useRef(null),M=b.useRef(null),T=b.useRef(i);T.current=i;const P=b.useRef(e);P.current=e;const z=mo("(min-width: 768px)"),V=Te(te=>te.selectedProxyId),U=Ur(te=>te.capability),G=Ur(te=>te.capabilityStatus),O=Ur(te=>te.capabilityError),A=Ur(te=>{var Q;return((Q=te.authoritative)==null?void 0:Q.scope)??null}),L=A?`${A.proxyId}\0${A.bindingId}`:null,D=b.useCallback(te=>{T.current=te,s(te),Tr("local",Sn.webPreviewTunnelProvider,te)},[]);function I(){var te,Q;r(""),l("local"),d(""),p(""),g(""),w(Ch()),x(!1),(te=R.current)==null||te.abort(),R.current=null,(Q=k.current)==null||Q.abort(),k.current=null,N.current=null,M.current=null}const B=b.useCallback(async te=>{var ie;(ie=R.current)==null||ie.abort();const Q=new AbortController;R.current=Q;const ce=Rt.getActiveScope();if(!(!ce||ce.proxyId!==V))try{const le=await Rt.requestWebPreviewCapability(ce,te,{signal:Q.signal});if(!le||Q.signal.aborted||!P.current||!le.success)return;const be=T.current,Le=be==="cloudflare"?"cpolar":"cloudflare";!c0(le.capability,be)&&c0(le.capability,Le)&&D(Le)}catch{}},[D,V]);function F(te){!te&&S||t(te)}b.useEffect(()=>{if(!e){I();return}return B(!1),()=>{var te;(te=R.current)==null||te.abort(),R.current=null}},[B,e,L]),b.useEffect(()=>{var ie;if(!e||o!=="static")return;(ie=k.current)==null||ie.abort(),k.current=null;const te=f.trim();if(!te){w(Ch()),g("");return}const Q=new AbortController;k.current=Q,w({status:"loading"}),g("");const ce=window.setTimeout(()=>{const le=Ft,be=Rt.getActiveScope();if(!le||!be||be.proxyId!==V){w({status:"error",message:"请先连接开发机"});return}Rt.inspectStaticWebPreview(be,te,{signal:Q.signal}).then(Le=>{if(!Le||Q.signal.aborted||!P.current||!Rt.isActive(le,be))return;if(!Le.success){w({status:"error",message:Le.error});return}const he=Le.htmlEntries;if(he.length===0&&!Le.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const He={entryPath:Le.entryPath,htmlEntries:he};w({status:"ready",path:te,result:He}),g(Le.entryPath??"")}).catch(Le=>{Q.signal.aborted||!P.current||Le instanceof Error&&Le.name==="AbortError"||!Rt.isActive(le,be)||w({status:"error",message:Le instanceof Error?Le.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(ce),Q.abort(),k.current===Q&&(k.current=null)}},[e,L,V,o,f]);const Y=o==="local"?Fde(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||v),q=G==="loaded"&&c0(U,i),$=S||!q||!(o==="local"?Y===null:j);async function ne(){var le,be,Le;if($)return;const te=Ft;if(!te){qe.error("请先连接开发机");return}let Q;if(o==="local")Q={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const he=_.result.entryPath??v;if(!he)return;Q={kind:"static",path:_.path,entryPath:he}}x(!0);const ce=Rt.getActiveScope();if(!ce){x(!1),qe.error("请先连接开发机");return}let ie=null;try{const he=n.trim(),He=JSON.stringify({proxyId:ce.proxyId,tunnelProvider:i,source:Q,name:he||void 0});((le=N.current)==null?void 0:le.sourceKey)!==He&&(N.current={sourceKey:He,operationId:sm(`preview-operation-${i}`)}),ie=N.current.operationId,M.current=ie;const Pt=await Rt.createWebPreview(ce,Q,{tunnelProvider:i,operationId:ie,...he?{name:he}:{}});if(M.current!==ie)return;if(!Pt.accepted){((be=N.current)==null?void 0:be.operationId)===ie&&(N.current=null),qe.error(Pt.error);return}if(((Le=N.current)==null?void 0:Le.operationId)===ie&&(N.current=null),!P.current||!Rt.isActive(te,ce))return;t(!1)}catch(he){if(!ie||M.current!==ie||!P.current||!Rt.isActive(te,ce))return;qe.error(he instanceof Error?he.message:"无法创建网页预览")}finally{ie&&M.current===ie&&(M.current=null,P.current&&x(!1))}}const J=m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-web-preview-form",autoComplete:"off",onSubmit:te=>{te.preventDefault(),ne()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-web-preview-name",value:n,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S,placeholder:"自动生成","data-slot":"web-preview-name",onChange:te=>{r(te.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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"})]}),m.jsxs("section",{className:"flex min-w-0 flex-col gap-1","data-slot":"web-preview-tunnel-provider-field","data-provider":i,children:[m.jsx("span",{className:"text-sm",children:"内网穿透服务"}),m.jsxs(zb,{value:i,disabled:S,onValueChange:te=>D(te),children:[m.jsx(Fb,{"aria-label":"内网穿透服务","data-slot":"web-preview-tunnel-provider-select","data-provider":i,className:"min-h-11 w-full md:min-h-0",children:m.jsx(jb,{})}),m.jsx($b,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(_1).map(te=>m.jsx(Hb,{value:te,"data-slot":"web-preview-tunnel-provider-option","data-provider":te,children:_1[te].label},te))})]})]}),m.jsx(Hde,{status:G,capability:U,provider:i,error:O,disabled:S,onRetry:()=>void B(!0)}),m.jsxs("section",{"aria-label":"网页来源",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"网页来源"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","data-slot":"web-preview-source-local",disabled:S,"aria-pressed":o==="local",onClick:()=>{var te;(te=k.current)==null||te.abort(),k.current=null,w(Ch()),g(""),l("local")},className:Ye("flex min-h-16 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 disabled:cursor-not-allowed disabled:opacity-60",o==="local"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"本机网站"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"输入 localhost 地址"})]}),m.jsxs("button",{type:"button","data-slot":"web-preview-source-static",disabled:S,"aria-pressed":o==="static",onClick:()=>{var te;(te=k.current)==null||te.abort(),k.current=null,w(Ch()),g(""),l("static")},className:Ye("flex min-h-16 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 disabled:cursor-not-allowed disabled:opacity-60",o==="static"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"网页文件"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"选择 HTML 网页文件或目录"})]})]})]}),o==="local"?m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"本机网站地址"}),m.jsx("input",{type:"url","data-slot":"web-preview-local-url","aria-label":"本机网站地址",inputMode:"url",name:"dev-anywhere-preview-local-url",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S,value:u,onChange:te=>{d(te.target.value)},placeholder:"http://localhost:5173","aria-invalid":u.length>0&&Y!==null,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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"}),u.length>0&&Y?m.jsx("span",{"data-slot":"web-preview-local-url-error",className:"text-xs text-destructive",role:"alert",children:Y}):null]}):m.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx(vk,{id:"create-web-preview-path",name:"dev-anywhere-preview-static-path","data-slot":"web-preview-static-path",label:"网页位置",value:f,selectionKind:"file-or-directory",fileExtensions:[".html",".htm"],disabled:S,placeholder:"选择 HTML 网页文件或目录",onValueChange:p}),m.jsx(Ude,{inspection:_,selectedEntryPath:v,disabled:S,onEntryPathChange:te=>{g(te)}})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost","data-slot":"create-web-preview-cancel",className:"min-h-11 md:min-h-0",onClick:()=>F(!1),disabled:S,children:"取消"}),m.jsx(pt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:$,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(Zi,{open:e,onOpenChange:F,children:m.jsxs(Qi,{showCloseButton:!S,onEscapeKeyDown:te=>{S&&te.preventDefault()},onPointerDownOutside:te=>{S&&te.preventDefault()},className:"!w-[calc(100vw-2rem)] !max-w-none max-h-[calc(100dvh-2rem)] overflow-y-auto sm:!w-[40rem]","data-slot":"create-web-preview-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"新建网页预览"}),m.jsx(Ss,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),J]})}):m.jsx(lc,{open:e,onOpenChange:F,children:m.jsxs(cc,{side:"bottom",showCloseButton:!S,onEscapeKeyDown:te=>{S&&te.preventDefault()},onPointerDownOutside:te=>{S&&te.preventDefault()},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-web-preview-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(yu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(uc,{children:"新建网页预览"}),m.jsx(Db,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),J]})})}function Hde({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=_1[n];if(e==="loading"||e==="idle")return m.jsxs("div",{"data-slot":"web-preview-capability-status","data-status":"loading","data-provider":n,className:"flex items-center gap-2 rounded-md border border-border/70 bg-muted/20 px-3 py-2 text-sm text-muted-foreground",role:"status",children:[m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在检测 ",o.label,"..."]});if(e==="error")return m.jsx("div",{"data-slot":"web-preview-capability-status","data-status":"error","data-provider":n,className:"rounded-md border border-destructive/45 bg-destructive/5 p-3",role:"alert",children:m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(ez,{className:"mt-0.5 size-4 shrink-0 text-destructive","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("p",{className:"text-sm font-medium",children:["无法检测 ",o.label]}),r?m.jsx("p",{className:"mt-1 break-words text-xs text-muted-foreground",children:r}):null]}),m.jsx(eI,{onClick:s,disabled:i})]})});const l=q4(t,n);if(!(l!=null&&l.available)){const u=(l==null?void 0:l.suggestions)??[],d=`未找到 ${o.label}`,f=(l==null?void 0:l.error)&&l.error!==d;return m.jsx("div",{"data-slot":"web-preview-capability-status","data-status":"missing","data-provider":n,className:"rounded-md border border-[var(--color-status-warning)]/45 bg-[var(--color-status-warning)]/5 p-3",role:"alert",children:m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(_V,{className:"mt-0.5 size-4 shrink-0 text-[var(--color-status-warning)]","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("p",{className:"text-sm font-medium",children:d}),m.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["请先安装 ",o.executable,",并确保它在用户 Shell 的 PATH 中,然后重新检测。"]}),u.length>0?m.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[m.jsx("span",{children:"检测到的位置:"}),m.jsx("ul",{className:"mt-1 space-y-1",children:u.map(p=>m.jsx("li",{"data-slot":n==="cloudflare"?"web-preview-cloudflared-suggestion":"web-preview-cpolar-suggestion","data-provider":n,"data-path":p,children:m.jsx("code",{className:"break-all rounded bg-muted px-1 py-0.5",children:p})},p))})]}):null,o.installUrl?m.jsx("a",{"data-slot":"web-preview-cloudflared-install-link","data-provider":n,href:o.installUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-block text-xs text-primary underline-offset-4 hover:underline",children:"查看官方安装说明"}):null,f?m.jsx("p",{className:"mt-1 break-words text-xs text-muted-foreground/80",children:l.error}):null]}),m.jsx(eI,{onClick:s,disabled:i})]})})}return m.jsxs("div",{"data-slot":"web-preview-capability-status","data-status":"ready","data-provider":n,className:"flex items-center gap-2 rounded-md border border-[var(--color-status-success)]/35 bg-[var(--color-status-success)]/5 px-3 py-2 text-sm",role:"status",children:[m.jsx(fV,{className:"size-4 text-[var(--color-status-success)]","aria-hidden":"true"}),m.jsxs("span",{children:[o.label," 已安装"]}),l.version?m.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["· ",l.version]}):null]})}function eI({onClick:e,disabled:t}){return m.jsxs(pt,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(nm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function Ude({inspection:e,selectedEntryPath:t,disabled:n,onEntryPathChange:r}){if(e.status==="idle")return null;if(e.status==="loading")return m.jsxs("span",{"data-slot":"web-preview-static-inspection","data-status":"loading",className:"flex items-center gap-2 text-xs text-muted-foreground",role:"status",children:[m.jsx(oi,{className:"size-3.5 animate-spin","aria-hidden":"true"}),"正在检查网页..."]});if(e.status==="error")return m.jsx("span",{"data-slot":"web-preview-static-inspection","data-status":"error",className:"text-xs text-destructive",role:"alert",children:e.message});if(!e.result.entryPath&&e.result.htmlEntries.length>1)return m.jsxs("label",{"data-slot":"web-preview-static-inspection","data-status":"choose-entry",className:"mt-1 flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"这个文件夹里有多个网页,打开预览时先显示哪个?"}),m.jsxs(zb,{value:t,onValueChange:r,disabled:n,children:[m.jsx(Fb,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(jb,{placeholder:"选择网页"})}),m.jsx($b,{children:e.result.htmlEntries.map(o=>m.jsx(Hb,{value:o,"data-entry-path":o,children:o},o))})]})]});const s=e.result.entryPath;return s?m.jsxs("span",{"data-slot":"web-preview-static-inspection","data-status":"ready","data-entry-path":s,className:"truncate text-xs text-muted-foreground",title:s,children:["打开时显示:",m.jsx("span",{className:"font-mono",children:s})]}):null}const w1={ios:"iOS Simulator",android:"Android Emulator"};function Wde({open:e,platform:t,onOpenChange:n}){const r=Es(),i=mo("(min-width: 768px)"),s=Te(F=>F.selectedProxyId),o=dr(F=>F.capability),l=dr(F=>F.targets),u=dr(F=>F.targetsStatus),d=dr(F=>F.targetsError),f=dr(Hj),p=dr(F=>{var Y;return((Y=F.authoritative)==null?void 0:Y.scope)??null}),v=p?`${p.proxyId}\0${p.bindingId}`:null,[g,_]=b.useState(""),[w,S]=b.useState(null),[x,R]=b.useState(!1),k=b.useRef(null),N=b.useRef(e);N.current=e;const M=b.useRef(null),T=b.useRef(null),P=b.useMemo(()=>l.filter(F=>F.platform===t),[t,l]),z=b.useMemo(()=>new Set(f.map(F=>F.targetId)),[f]),V=b.useMemo(()=>P.filter(F=>!z.has(F.targetId)),[z,P]),U=V.find(F=>F.targetId===w),G=o==null?void 0:o[t],O=b.useCallback(async F=>{var K;(K=k.current)==null||K.abort();const Y=new AbortController;k.current=Y;const j=Ft,q=Rt.getActiveScope();if(!(!j||!q||q.proxyId!==s))try{const $=await Rt.requestDevicePreviewCapability(q,F,{signal:Y.signal});if(!$||Y.signal.aborted||!N.current||!$.success)return;await Rt.requestDevicePreviewTargets(q,!0,{signal:Y.signal})}catch{}},[s]);b.useEffect(()=>{var F;if(!e){(F=k.current)==null||F.abort(),k.current=null,_(""),S(null),R(!1),M.current=null,T.current=null;return}return O(!1),()=>{var Y;(Y=k.current)==null||Y.abort(),k.current=null}},[O,e,t,v]),b.useEffect(()=>{if(e){if(w&&!U){S(null);return}!w&&V.length===1&&S(V[0].targetId)}},[e,V,U,w]);async function A(){var K,$,ne;const F=U;if(!F||x||(G==null?void 0:G.available)!==!0)return;const Y=Ft,j=Rt.getActiveScope();if(!Y||!j||j.proxyId!==s){qe.error("请先连接开发机");return}R(!0);let q=null;try{const J=g.trim(),te=((K=M.current)==null?void 0:K.proxyId)===j.proxyId&&M.current.targetId===F.targetId&&M.current.name===J?M.current:{proxyId:j.proxyId,targetId:F.targetId,name:J,operationId:sm("device-preview-operation")};M.current=te,q=te.operationId,T.current=q;const Q=await Rt.createDevicePreview(j,F.targetId,{operationId:te.operationId,...J?{name:J}:{}});if(T.current!==te.operationId)return;if(!Q.accepted){if((($=M.current)==null?void 0:$.operationId)===te.operationId&&(M.current=null),!N.current||!Rt.isActive(Y,j))return;qe.error(Q.error);return}if(((ne=M.current)==null?void 0:ne.operationId)===te.operationId&&(M.current=null),!N.current||!Rt.isActive(Y,j))return;n(!1),r(`/preview/device/${Q.previewId}`)}catch(J){if(!q||T.current!==q||!N.current||!Rt.isActive(Y,j))return;qe.error(J instanceof Error?J.message:"无法创建模拟器预览")}finally{q&&T.current===q&&(T.current=null,N.current&&R(!1))}}function L(F){var Y;!F&&x||(F||((Y=k.current)==null||Y.abort(),k.current=null,M.current=null,T.current=null,_(""),S(null)),n(F))}const D=m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4",children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-device-preview-name",value:g,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:x,placeholder:"自动生成","data-slot":"device-preview-name",onChange:F=>{_(F.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 disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"})]}),m.jsx(qde,{platform:t,tool:G}),m.jsx("div",{className:"grid min-w-0 grid-cols-1 gap-2","data-slot":"device-preview-targets",children:u==="loading"?m.jsxs("div",{className:"flex min-h-28 items-center justify-center gap-2 text-sm text-muted-foreground",children:[m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(tI,{message:d??"无法读取模拟器列表"}):P.length===0?m.jsx(tI,{message:`没有已启动的 ${w1[t]}`}):P.map(F=>{const Y=F.targetId===w,j=z.has(F.targetId);return m.jsx(Vde,{target:F,selected:Y,disabled:j||x,alreadyOpen:j,onClick:()=>{S(F.targetId)}},F.targetId)})}),m.jsxs(Ws,{className:"gap-2 sm:gap-2",children:[m.jsxs(pt,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>void O(!0),"data-slot":"device-preview-refresh",children:[m.jsx(nm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(pt,{type:"button",disabled:!U||x||(G==null?void 0:G.available)!==!0,onClick:()=>void A(),"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),I=`新建 ${w1[t]} 预览`,B="选择开发机上已经启动的模拟器。";return i?m.jsx(Zi,{open:e,onOpenChange:L,children:m.jsxs(Qi,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:I}),m.jsx(Ss,{children:B})]}),D]})}):m.jsx(lc,{open:e,onOpenChange:L,children:m.jsxs(cc,{side:"bottom",showCloseButton:!x,className:"inset-x-2 max-h-[calc(100dvh-0.75rem)] w-auto min-w-0 max-w-[calc(100%-1rem)] 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-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(yu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(uc,{children:I}),m.jsx(Db,{children:B})]}),D]})})}function qde({platform:e,tool:t}){if(!t||t.available)return null;const n=e==="android"&&!!t.command,r=e==="ios"?"Baguette":"adb",i=t.supported?e==="ios"&&t.version?"outdated":t.command?"unavailable":"missing":"unsupported",s=n?"Android 模拟器预览不可用":i==="unsupported"?`${w1[e]} 不可用`:i==="outdated"?`需要更新 ${r}`:i==="unavailable"?`${r} 暂时不可用`:`未找到 ${r}`,o=t.error??(e==="ios"?"需要先在开发机上安装 Baguette 0.1.96 或更高版本。":"需要先在开发机上安装 adb。"),l=o.trim()!==s.trim();return m.jsx("div",{className:"rounded-lg border border-amber-500/45 bg-amber-500/5 p-3 text-sm","data-slot":"device-preview-tool-status","data-status":i,children:m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ez,{className:"mt-0.5 size-4 shrink-0 text-amber-600","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0",children:[m.jsx("p",{className:"font-medium",children:s}),l?m.jsx("p",{className:"mt-1 text-muted-foreground","data-slot":"device-preview-tool-description",children:o}):null,i!=="unsupported"&&!n?m.jsx("a",{href:e==="ios"?"https://github.com/tddworks/baguette#install":"https://developer.android.com/tools/releases/platform-tools",target:"_blank",rel:"noreferrer",className:"mt-1 inline-block text-primary underline underline-offset-4",children:"查看安装方法"}):null]})]})})}function tI({message:e}){return m.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-dashed px-4 text-center text-sm text-muted-foreground",children:e})}function Vde({target:e,selected:t,disabled:n,alreadyOpen:r,onClick:i}){const s=e.platform==="ios"?"iOS":"Android",o=`${e.model} · ${s} ${e.osVersion}`;return m.jsxs("button",{type:"button",className:Ye("flex min-h-16 w-full min-w-0 max-w-full items-center gap-3 overflow-hidden rounded-lg border px-3 py-2 text-left outline-none transition-colors",t?"border-primary bg-primary/5":"border-border hover:bg-accent",n&&"cursor-not-allowed opacity-55"),disabled:n,"aria-pressed":t,onClick:i,"data-slot":"device-preview-target","data-target-id":e.targetId,"data-already-open":r?"true":"false","data-interactive":e.interactive?"true":"false",children:[m.jsx(my,{className:"size-5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"block truncate text-sm font-medium",children:e.name}),m.jsx("span",{className:"mt-0.5 block truncate text-xs text-muted-foreground","data-slot":"device-preview-target-device","data-device-model":e.model,"data-os-version":e.osVersion,children:o})]}),r?m.jsx("span",{className:"text-xs text-muted-foreground",children:"已在预览"}):t?m.jsx(ia,{className:"size-4 text-primary","aria-hidden":"true"}):null]})}function V4({open:e,onOpenChange:t}){const[n,r]=b.useState(()=>e?"chooser":"closed"),i=b.useRef(null),s=mo("(min-width: 768px)");b.useLayoutEffect(()=>{if(e){n==="closed"&&r("chooser");return}n!=="closed"&&(i.current=n,r("closed"))},[e,n]);function o(){t(!1)}const l=m.jsxs("div",{className:"grid gap-2 pt-2","data-slot":"frontend-preview-options",children:[m.jsx(u0,{icon:m.jsx(rz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(u0,{icon:m.jsx(my,{className:"size-5","aria-hidden":"true"}),title:"iOS Simulator",description:"查看和操控开发机上已启动的 iPhone 或 iPad 模拟器",slot:"frontend-preview-ios",onClick:()=>r("ios")}),m.jsx(u0,{icon:m.jsx(my,{className:"size-5","aria-hidden":"true"}),title:"Android Emulator",description:"查看和操控开发机上已启动的 Android 模拟器",slot:"frontend-preview-android",onClick:()=>r("android")})]}),u=n==="closed"?i.current:n,d=e&&n!=="closed";switch(u){case"chooser":return s?m.jsx(Zi,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(Qi,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"新建预览"}),m.jsx(Ss,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(lc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(cc,{side:"bottom",className:"inset-x-2 w-auto rounded-t-xl border bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"create-frontend-preview-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(yu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(uc,{children:"新建预览"}),m.jsx(Db,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx($de,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(Wde,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function u0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(pt,{type:"button",variant:"outline",className:"h-auto min-h-[4.5rem] justify-start gap-3 px-4 py-3 text-left","data-slot":r,onClick:i,children:[m.jsx("span",{className:"text-muted-foreground",children:e}),m.jsxs("span",{className:"min-w-0",children:[m.jsx("span",{className:"block font-medium text-foreground",children:t}),m.jsx("span",{className:"mt-0.5 block whitespace-normal text-xs leading-5 text-muted-foreground",children:n})]})]})}function Yde({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Zi,{open:e!==null,onOpenChange:n,children:m.jsxs(Qi,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"停止预览?"}),m.jsx(Ss,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(pt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"device-preview-close-confirm",children:t?"正在停止...":"停止预览"})]})]})})}const Kde={ready:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"已连接"},disconnected:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已断开"}};function Gde({preview:e,selected:t,pendingOperation:n,onRename:r,onReconnect:i,onClose:s}){const o=Kde[e.state],l=n==="reconnect"?{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"正在重新连接",busy:!0}:n==="close"?{dot:"bg-muted-foreground animate-pulse",text:"text-muted-foreground",label:"正在停止",busy:!0}:o,u=e.state==="ready",d=e.state==="disconnected",f=e.platform==="ios"?"iOS":"Android",p=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[m.jsx("span",{className:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(my,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1 truncate text-muted-foreground","data-slot":"device-preview-row-device","data-device-model":e.model,"data-os-version":e.osVersion,children:[e.model," · ",f," ",e.osVersion]}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]})]});return m.jsxs("li",{className:Ye("relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent",t&&"bg-accent"),"data-slot":"device-preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":n,children:[u?m.jsx(cC,{to:`/preview/device/${e.previewId}`,className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring md:min-h-0","data-slot":"device-preview-row-open",children:p}):m.jsx("div",{className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:p}),m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"模拟器预览操作",disabled:n!==void 0,"data-slot":"device-preview-row-menu-trigger",children:l.busy||n==="rename"?m.jsx(oi,{className:"animate-spin","aria-hidden":"true"}):m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(Lr,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(Lr,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(zd,{}),m.jsx(Lr,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function Xde({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Zi,{open:e!==null,onOpenChange:n,children:m.jsxs(Qi,{"data-slot":"preview-close-dialog",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"关闭预览?"}),m.jsx(Ss,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(pt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function Zde({target:e,onOpenChange:t,onRename:n}){return m.jsx(Qde,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function Qde({target:e,onOpenChange:t,onRename:n}){const[r,i]=b.useState(()=>(e==null?void 0:e.name.trim())??""),[s,o]=b.useState(null),[l,u]=b.useState(!1),d=b.useRef((e==null?void 0:e.targetKey)??null);b.useLayoutEffect(()=>()=>{d.current=null},[]);function f(v){!v&&l||t(v)}async function p(v){v.preventDefault();const g=r.trim();if(!g){o("名称不能为空");return}if(!e||l)return;const _=e.targetKey;u(!0);try{if(await n(g),d.current!==_)return;t(!1)}catch(w){if(d.current!==_)return;o(w instanceof Error?w.message:String(w))}finally{d.current===_&&u(!1)}}return m.jsx(Zi,{open:e!==null,onOpenChange:f,children:m.jsx(Qi,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>void p(v),children:[m.jsx(Ji,{children:m.jsx(Fi,{children:"重命名预览"})}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"preview-rename-name",className:"text-sm font-medium",children:"预览名称"}),m.jsx("input",{id:"preview-rename-name",value:r,autoFocus:!0,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-invalid":!!s,"aria-describedby":s?"preview-rename-error":void 0,"data-slot":"preview-rename-input",className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",s&&"border-destructive focus-visible:ring-destructive/20"),disabled:l,onChange:v=>{i(v.target.value),s&&o(null)}}),s?m.jsx("p",{id:"preview-rename-error",className:"text-sm text-destructive",role:"alert",children:s}):null]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(pt,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const Jde={starting:{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"正在创建",busy:!0},ready:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"可访问"},failed:{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"连接失败"},disconnected:{dot:"bg-muted-foreground",text:"text-muted-foreground",label:"已断开"},stopping:{dot:"bg-muted-foreground animate-pulse",text:"text-muted-foreground",label:"正在关闭",busy:!0}};function efe(e){return e.source.kind==="local"?e.source.url:ab(e.source.rootPath,e.source.entryPath)}async function tfe(e){if(await Pp(e,{allowUserGestureFallback:!0})==="failed"){qe.error("复制失败,请稍后重试");return}qe.success("链接已复制")}async function nfe(e,t){if(typeof navigator.share=="function")try{await navigator.share({title:e,url:t})}catch(n){if(n instanceof DOMException&&n.name==="AbortError")return;qe.error("无法打开系统分享面板")}}function rfe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=Vr(w=>w.homePath),o=Jde[e.state],l=t==="reconnect"?{dot:"bg-[var(--color-status-working)] animate-pulse",text:"text-[var(--color-status-working)]",label:"正在重新连接",busy:!0}:t==="close"?{dot:"bg-muted-foreground animate-pulse",text:"text-muted-foreground",label:"正在关闭",busy:!0}:o,u=e.state==="ready"?e.publicUrl:null,d=u!==null,f=e.state==="failed"||e.state==="disconnected",p=d&&typeof navigator<"u"&&typeof navigator.share=="function",v=efe(e),g=e.source.kind==="static"?om(v,s):v,_=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx("span",{className:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(rz,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground",title:v,children:g}),m.jsx("span",{className:"shrink-0 text-muted-foreground/60","aria-hidden":"true",children:"·"}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]}),e.state==="failed"?m.jsx("span",{"data-slot":"preview-row-error",className:"truncate text-xs text-destructive/90",title:e.error,children:e.error}):null]});return m.jsxs("li",{className:"relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent","data-slot":"preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":t,children:[d?m.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer","data-slot":"preview-row-open",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring md:min-h-0",children:_}):m.jsx("div",{"data-slot":"preview-row-inactive","aria-disabled":"true",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:_}),m.jsxs(hf,{children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{variant:"ghost",size:"icon-xs",className:"size-11 md:size-6","aria-label":"预览操作","data-slot":"preview-row-menu-trigger",disabled:e.state==="stopping"||t!==void 0,children:l.busy||t==="rename"?m.jsx(oi,{className:"animate-spin","aria-hidden":"true"}):m.jsx(Jy,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(Lr,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(Lr,{"data-slot":"preview-row-copy-item",onSelect:()=>void tfe(u),children:"复制链接"}):null,p?m.jsx(Lr,{"data-slot":"preview-row-share-item",onSelect:()=>void nfe(e.name,u),children:"分享…"}):null,f?m.jsx(Lr,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(zd,{}),m.jsx(Lr,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const ife=Object.freeze([]),sfe=Object.freeze([]);function sd(e,t,n){return Object.freeze({kind:e,previewId:t,scope:Object.freeze({proxyId:n.proxyId,bindingId:n.bindingId})})}function Ic(e,t){return e!==null&&e.kind===t.kind&&e.previewId===t.previewId&&Qt(e.scope,t.scope)}function rp(e,t,n){return t!==null&&n!==void 0&&Qt(e.scope,t)&&Qt(e.scope,n)}function kh(e){const t=Rt.getActiveScope(),n=e.kind==="web"?Ur.getState().authoritative:dr.getState().authoritative;return!n||!rp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function zo(e){const t=Rt.getActiveScope();return t!==null&&Qt(t,e)}function nI(){const e=Ur(A=>A.authoritative),t=dr(A=>A.authoritative),n=Vo(A=>A.registry),r=Rt.getActiveScope(),i=r&&e&&Qt(r,e.scope)?e.scope:null,s=r&&t&&Qt(r,t.scope)?t.scope:null,o=i&&e?e.previews:ife,l=s&&t?t.previews:sfe,u=$B("/preview/device/:id"),d=Es(),[f,p]=b.useState(null),[v,g]=b.useState(null),_=(v==null?void 0:v.kind)==="web"&&rp(v,r,e==null?void 0:e.scope)?o.find(A=>A.previewId===v.previewId)??null:null,w=(v==null?void 0:v.kind)==="device"&&rp(v,r,t==null?void 0:t.scope)?l.find(A=>A.previewId===v.previewId)??null:null,S=_??w,x=(f==null?void 0:f.kind)==="web"&&rp(f,r,e==null?void 0:e.scope)?o.find(A=>A.previewId===f.previewId)??null:null,R=(f==null?void 0:f.kind)==="device"&&rp(f,r,t==null?void 0:t.scope)?l.find(A=>A.previewId===f.previewId)??null:null;b.useEffect(()=>{v&&!S&&g(A=>Ic(A,v)?null:A),f&&!x&&!R&&p(A=>Ic(A,f)?null:A)},[f,R,v,S,x]);function k(A,L,D){var I;return(I=zj(n,A,L,D)[0])==null?void 0:I.kind}if(o.length===0&&l.length===0)return null;async function N(A){if(kh(A))try{const L=await Rt.reconnectWebPreview(A.scope,A.previewId);if(!zo(A.scope))return;L.success||qe.error(L.error)}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function M(A,L){if(!kh(A))return;let D;try{D=A.kind==="web"?await Rt.renameWebPreview(A.scope,A.previewId,L):await Rt.renameDevicePreview(A.scope,A.previewId,L)}catch(I){if(!zo(A.scope))return;throw I}if(zo(A.scope)&&!D.success)throw new Error(D.error)}async function T(A){if(kh(A))try{const L=await Rt.closeWebPreview(A.scope,A.previewId);if(!zo(A.scope))return;if(!L.success){qe.error(L.error);return}p(D=>Ic(D,A)?null:D)}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function P(A){if(kh(A))try{const L=await Rt.reconnectDevicePreview(A.scope,A.previewId);if(!zo(A.scope))return;L.success||qe.error(L.error)}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(A){if(kh(A))try{const L=await Rt.closeDevicePreview(A.scope,A.previewId);if(!zo(A.scope))return;if(!L.success){qe.error(L.error);return}p(D=>Ic(D,A)?null:D),(u==null?void 0:u.params.id)===A.previewId&&d("/sessions")}catch(L){if(!zo(A.scope))return;qe.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const V=(f==null?void 0:f.kind)==="web"&&k(f.scope,"web",f.previewId)==="close",U=(f==null?void 0:f.kind)==="device"&&k(f.scope,"device",f.previewId)==="close",G=v,O=f;return m.jsxs("section",{"data-slot":"preview-section","aria-labelledby":"preview-section-title",children:[m.jsxs("h3",{id:"preview-section-title",className:"px-4 pb-2 pt-3 text-sm font-semibold text-foreground",children:["预览",m.jsxs("span",{className:"ml-1 font-normal text-muted-foreground/70",children:["· ",o.length+l.length]})]}),m.jsxs("ul",{role:"list",className:"flex w-full min-w-0 flex-col",children:[o.map(A=>m.jsx(rfe,{preview:A,pendingOperation:i?k(i,"web",A.previewId):void 0,onRename:()=>i&&g(sd("web",A.previewId,i)),onReconnect:()=>i&&void N(sd("web",A.previewId,i)),onClose:()=>i&&p(sd("web",A.previewId,i))},A.previewId)),l.map(A=>m.jsx(Gde,{preview:A,selected:(u==null?void 0:u.params.id)===A.previewId,pendingOperation:s?k(s,"device",A.previewId):void 0,onRename:()=>s&&g(sd("device",A.previewId,s)),onReconnect:()=>s&&void P(sd("device",A.previewId,s)),onClose:()=>s&&p(sd("device",A.previewId,s))},A.previewId))]}),m.jsx(Zde,{target:G&&S?{targetKey:`${G.kind}\0${G.scope.proxyId}\0${G.scope.bindingId}\0${G.previewId}`,name:S.name}:null,onOpenChange:A=>{!A&&G&&g(L=>Ic(L,G)?null:L)},onRename:A=>G?M(G,A):Promise.resolve()}),m.jsx(Xde,{preview:x,closing:V,onOpenChange:A=>{!A&&!V&&O&&p(L=>Ic(L,O)?null:L)},onConfirm:()=>O&&void T(O)}),m.jsx(Yde,{preview:R,closing:U,onOpenChange:A=>{!A&&!U&&O&&p(L=>Ic(L,O)?null:L)},onConfirm:()=>O&&void z(O)})]})}function Y4({layout:e}){const t=Gt(ie=>ie.sessions),n=Gt(ie=>ie.sessionListLoaded),r=Gt(ie=>ie.agentStatusBySessionId),i=Gt(ie=>ie.ptyStateBySessionId),s=Gt(ie=>ie.renameSession),o=dn(ie=>ie.bySessionId),l=$B("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Te(ie=>!!ie.selectedProxyId),f=Te(ie=>ie.proxyListLoaded),p=Te(ie=>ie.proxySwitchTarget),v=Gt(ie=>ie.loadingProxyName),g=p!==null||!f||d&&!n,_=(p==null?void 0:p.name)??v,w=_?`正在连接 ${_}...`:"连接中...",S=Es(),[x,R]=b.useState(!1),[k,N]=b.useState(!1),[M,T]=b.useState(!1),[P,z]=b.useState(!1),[V,U]=b.useState(null),[G,O]=b.useState(null),{creatingTerminal:A,creatingShell:L,createTerminal:D}=K4(),[I,B]=b.useState(new Set),[F,Y]=b.useState(()=>Date.now());b.useEffect(()=>{const ie=setInterval(()=>Y(Date.now()),6e4);return()=>clearInterval(ie)},[]);function j(ie,le){S(`/chat/${ie}?mode=${le}`,{replace:!1})}function q(ie){const le=ie.sessionId,be=Ft;if(!be){qe.error("请先连接开发机");return}be.sendControl({type:"session_terminate",sessionId:le}),Gt.getState().removeSession(le),dn.getState().clearSession(le),le===u&&S("/sessions"),(ie==null?void 0:ie.kind)==="agent"&&ie.mode==="pty"&&ie.ptyOwner==="local-terminal"?qe.info("已断开页面连接,本地终端仍在运行"):qe.info("正在终止会话",{duration:1500})}async function K(ie,le){const be=Ft;if(!be)throw new Error("请先连接开发机");const Le=await be.renameSession(ie,le);if(!Le.success)throw new Error(Le.error??"重命名失败");s(ie,Le.name??le),qe.success("已重命名会话")}function $(ie){B(le=>{const be=new Set(le);return be.has(ie)?be.delete(ie):be.add(ie),be})}function ne(ie){var Le;const le=ie.mode==="json"&&(((Le=o[ie.sessionId])==null?void 0:Le.pendingApprovals.some(he=>he.status==="pending"))??!1),be=Bde({session:ie,agentStatus:r[ie.sessionId],ptyState:i[ie.sessionId],hasPendingApproval:le});return be===ie.state?ie:{...ie,state:be}}const J=t.length>0;if(e==="sidebar"&&(g||!d))return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":g?"session-list-loading":void 0,role:g?"status":void 0,"aria-live":g?"polite":void 0,children:g?w:"请先连接开发机"}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]});if(e==="page"&&g)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[m.jsx(oi,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"max-w-[min(24rem,calc(100%-2rem))] truncate text-sm",children:w})]});if(e==="page"&&!d)return m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsx("div",{className:"flex-1",children:m.jsx(Yc,{variant:"no-proxy"})}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]});const te=m.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",J?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),Q=J?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:ofe(t).map(ie=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>$(ie.provider),"aria-expanded":!I.has(ie.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:afe(ie.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:ie.sessions.length}),m.jsx(pp,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!I.has(ie.provider)&&"rotate-90"),"aria-hidden":"true"})]}),I.has(ie.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:ie.sessions.map(le=>m.jsx(gde,{session:ne(le),selected:le.sessionId===u,now:F,onClick:()=>j(le.sessionId,le.mode),onRename:()=>U(le),onTerminate:()=>O(le)},le.sessionId))})]},ie.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),ce=m.jsx(_de,{now:F});return e==="page"?m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain",children:[te,Q,m.jsx(nI,{}),ce]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(pt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>N(!0),children:[m.jsx(tz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(ffe,{open:k,creatingTerminal:A,onOpenChange:N,onCreateAgent:()=>{N(!1),R(!0)},onCreateTerminal:()=>{G4()?(N(!1),T(!0)):D(void 0,()=>N(!1))},onCreatePreview:()=>{N(!1),z(!0)}}),m.jsx(X4,{layout:"mobile",open:M,creatingTerminal:A,creatingShell:L,onOpenChange:T,onBack:()=>{T(!1),N(!0)},onCreate:ie=>void D(ie,()=>T(!1))}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(V4,{open:P,onOpenChange:z}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[te,Q,m.jsx(nI,{}),ce]}),m.jsx(tp,{open:x,onOpenChange:R}),m.jsx(cv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:q}),m.jsx(np,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:ie=>{ie||U(null)},onRename:K})]})}function ofe(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])=>lfe(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function afe(e){return e==="terminal"?"终端":Bb(e)}function lfe(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:L4(e,t)}function K4(){const e=Es(),[t,n]=b.useState(null),r=t!==null;async function i(s,o){var u;const l=Te.getState();if(!(r||!l.connected||!l.proxyOnline||!l.selectedProxyId||l.proxySwitchTarget)&&!yk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await Mde({relay:Ft,shell:s});if(d.type!=="success"){qe.error(d.message);return}Gt.getState().addSession(d.session),o==null||o(),e(d.route)}finally{n(null)}}}return{creatingTerminal:r,creatingShell:t,createTerminal:i}}function yk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function cfe(e){const t=Te(u=>u.terminalShells),n=Te(yk),r=Te(u=>u.selectedProxyId),[i,s]=b.useState(!1),[o,l]=b.useState(0);return b.useEffect(()=>{if(!e||!n)return;let u=!1;const d=Ft,f=d==null?void 0:d.getPreviewScope();if(s(!1),!d||!f||f.proxyId!==r){s(!0);return}return d.requestProxyInfo().then(p=>{const v=Te.getState(),g=d.getPreviewScope();u||!v.connected||!v.proxyOnline||v.selectedProxyId!==r||!g||!Qt(f,g)||v.setTerminalShells(p.terminalShells)},()=>{u||s(!0)}),()=>{u=!0}},[e,n,r,o]),{terminalShells:t,needsDetection:n,failed:i,retry:()=>l(u=>u+1)}}const ufe=[{label:"启动 Shell"}];function dfe(e){return e!=null&&e.length?e:ufe}function G4(){var t;const e=Te.getState();return yk(e)||!!((t=e.terminalShells)!=null&&t.length)}function rI({compact:e=!1}){const[t,n]=b.useState(!1),[r,i]=b.useState(!1),[s,o]=b.useState(!1),[l,u]=b.useState(!1),[d,f]=b.useState(!1),p=b.useRef(!1),v=Te(V=>!!V.selectedProxyId),g=Te(V=>V.proxySwitchTarget!==null),_=v&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=K4();function R(){f(!0),window.setTimeout(()=>f(!1),2e3)}function k(){if(!_){R();return}p.current=!0,o(!0)}function N(){if(!_){R();return}p.current=!0,G4()?i(!0):x()}function M(){if(!_){R();return}p.current=!0,u(!0)}function T(V){V.preventDefault(),R()}const P=m.jsxs(pt,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!_&&"opacity-50 hover:bg-background"),"aria-label":"新建","aria-disabled":!_,onClick:_?void 0:T,children:[m.jsx(tz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),z=_?m.jsxs(hf,{open:t,onOpenChange:n,children:[m.jsx(pf,{asChild:!0,children:P}),m.jsxs(mf,{align:e?"end":"start",className:"w-80","data-slot":"create-session-type-menu",onCloseAutoFocus:V=>{p.current&&(p.current=!1,V.preventDefault())},children:[m.jsxs(Lr,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:k,children:[m.jsx(JB,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(Lr,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:w,onSelect:N,children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),w?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx(zd,{}),m.jsxs(Lr,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:M,children:[m.jsx(hC,{className:"mt-0.5 size-4 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"flex items-center gap-1.5 font-medium",children:"预览"}),m.jsx("span",{className:"mt-0.5 block text-xs leading-4 text-muted-foreground",children:"在浏览器中预览网页或设备模拟器"})]})]})]})]}):P;return m.jsxs(m.Fragment,{children:[_?z:m.jsxs(gf,{open:_?void 0:d,onOpenChange:_?void 0:f,children:[m.jsx(vf,{asChild:!0,children:z}),m.jsx(yf,{side:"top",children:g?"正在切换开发机":"请先连接开发机"})]}),m.jsx(X4,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:V=>void x(V,()=>i(!1))}),m.jsx(tp,{open:s,onOpenChange:o}),m.jsx(V4,{open:l,onOpenChange:u})]})}function ffe({open:e,creatingTerminal:t,onOpenChange:n,onCreateAgent:r,onCreateTerminal:i,onCreatePreview:s}){const o=b.useRef(!1);function l(u){o.current=!0,u()}return m.jsx(lc,{open:e,onOpenChange:n,children:m.jsxs(cc,{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:u=>{o.current&&(o.current=!1,u.preventDefault())},children:[m.jsx(yu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(uc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(pt,{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:()=>l(r),children:[m.jsx(JB,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(pt,{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:()=>l(i),children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx("div",{className:"mx-1 h-px bg-border","aria-hidden":"true"}),m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-16 justify-start gap-3 rounded-md px-3 text-left","data-slot":"create-frontend-preview-sheet-item",onClick:()=>l(s),children:[m.jsx(hC,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0",children:[m.jsx("span",{className:"flex items-center gap-1.5 font-medium",children:"预览"}),m.jsx("span",{className:"mt-0.5 block text-xs leading-4 text-muted-foreground",children:"在浏览器中预览网页或设备模拟器"})]})]})]})]})})}function X4({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=cfe(t),p=b.useRef(!1),v=Te(w=>w.connected&&w.proxyOnline&&!!w.selectedProxyId&&!w.proxySwitchTarget),g=m.jsxs("div",{className:"grid gap-2","data-slot":"terminal-shell-options",children:[u?m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"terminal-shell-detection",disabled:!d,onClick:f,children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"终端检测失败,点击重试":"正在检测终端..."]}):dfe(l).map(w=>m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-12 justify-start gap-3 rounded-md px-3 text-left","data-slot":"terminal-shell-option","data-shell":w.id,disabled:n||!v,onClick:()=>o(w.id),children:[m.jsx(Zc,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),r===(w.id??"default")?"正在创建 Shell 会话...":w.label]},w.id??"default")),m.jsx("div",{className:"mx-1 h-px bg-border","aria-hidden":"true"}),m.jsxs(pt,{type:"button",variant:"ghost",className:"min-h-11 justify-start gap-3 px-3 text-muted-foreground",disabled:n,onClick:()=>{p.current=!0,s()},children:[m.jsx(sf,{className:"size-4","aria-hidden":"true"}),"返回"]})]});function _(w){p.current&&(p.current=!1,w.preventDefault())}return e==="mobile"?m.jsx(lc,{open:t,onOpenChange:i,children:m.jsxs(cc,{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-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(yu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(uc,{children:"Shell 会话"})}),g]})}):m.jsx(Zi,{open:t,onOpenChange:i,children:m.jsxs(Qi,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(Ji,{children:m.jsx(Fi,{children:"Shell 会话"})}),g]})})}const hfe="0.9.10",pfe={version:hfe},mfe={playback:"playback",capture:"play-and-record"};function gfe(){return typeof navigator>"u"?null:navigator.audioSession??null}function vfe(){return{setMode:()=>{},release:()=>{}}}class yfe{constructor(t=gfe){je(this,"leases",new Map);je(this,"session",null);je(this,"baselineType",null);je(this,"nextLeaseId",1);je(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return vfe();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(mfe[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 bk=new yfe,x1=64,iI=-60,Z4=32;function sI(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-iI)/-iI));return e<0?-r:r}function oI(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,f=-1;for(let p=l;p<u;p+=1){const v=i.getInt16(p*2,!0)/32768;d=Math.min(d,v),f=Math.max(f,v)}s.push({min:d,max:f})}return s}function bfe(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 _fe(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 Q4{constructor(t,n=24e3,r={}){je(this,"nextStartTime",0);je(this,"activityEndToken",0);je(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=bfe(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*Z4/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,f=Math.max(0,(d-this.context.currentTime)*1e3),p=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),v=_fe(n.subarray(l,u));this.scheduleTimer(()=>{var g,_,w,S;(_=(g=this.options).onActivityLevel)==null||_.call(g,v),(S=(w=this.options).onPlaybackChunk)==null||S.call(w,p)},f)}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 d0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},aI="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",wfe=800,lI=300,xfe=1600;function S1(e,t){return e.filter(n=>!n.model||n.model===t)}function cI({label:e,children:t,help:n}){return m.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:[m.jsx("span",{className:"block text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.jsx("div",{className:"mt-2 min-w-0",children:t}),n?m.jsx("span",{className:"mt-2 block text-xs leading-relaxed text-muted-foreground",children:n}):null]})}function uv({label:e,value:t,options:n,onChange:r,placeholder:i="请选择",help:s}){const[o,l]=b.useState(!1),u=b.useId(),d=n.find(g=>g.value===t),f=(d==null?void 0:d.label)??(t||i),p=n.filter(g=>!g.disabled),v=!!J4(f).detail;return m.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:[m.jsx("div",{id:u,className:"text-[13px] font-medium leading-none text-muted-foreground",children:e}),m.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 ${v?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[m.jsx(uI,{label:f,muted:!d&&!t}),m.jsx(ec,{className:`size-4 shrink-0 text-muted-foreground transition-transform ${o?"rotate-180":""}`,"aria-hidden":"true"})]}),o?m.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 _=g.value===t;return m.jsxs("button",{type:"button",role:"option","aria-label":g.label,"aria-selected":_,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:[m.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-primary",children:_?m.jsx(ia,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(uI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function uI({label:e,muted:t=!1}){const n=J4(e);return m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:`block truncate text-base leading-6 md:text-sm ${t?"text-muted-foreground":"text-foreground"}`,children:n.title}),n.detail?m.jsx("span",{className:"mt-0.5 block truncate text-xs leading-4 text-muted-foreground",children:n.detail}):null]})}function Sfe({scrollRef:e}={}){const[t,n]=b.useState(d0),[r,i]=b.useState(String(d0.turnIdleSeconds)),[s,o]=b.useState(()=>Gg()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[p,v]=b.useState(!1),[g,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),R=b.useRef(null),k=b.useRef(null),N=b.useRef(!1);b.useEffect(()=>{const Q=Ft;if(!Q){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce=!1;return _({kind:"loading"}),Q.requestVoiceConfig().then(ie=>{if(!ce){if(ie.error||!ie.config){_({kind:"error",message:ie.error??"读取语音设置失败"});return}n(ie.config),i(String(ie.config.turnIdleSeconds)),u(""),f(!1),v(!0),_({kind:"idle"})}}).catch(ie=>{ce||_({kind:"error",message:ie instanceof Error?ie.message:"读取语音设置失败"})}),()=>{ce=!0}},[]),b.useEffect(()=>{const Q=Ft;if(!Q||!p)return;let ce=!1;return Q.requestVoiceCapabilities({region:t.region}).then(ie=>{if(!ce){if(ie.error||!ie.capabilities){o(Gg());return}o(ie.capabilities)}}).catch(()=>{ce||o(Gg())}),()=>{ce=!0}},[t.region,p]),b.useEffect(()=>(N.current=!0,()=>{N.current=!1,$(),ne()}),[]);const M=b.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]),T=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",P=b.useMemo(()=>S1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),V=P.some(Q=>Q.value===t.ttsVoice)?t.ttsVoice:"",U=P.length===0?"当前模型暂无可用音色":V?null:"请选择可用音色",G=b.useMemo(()=>Tfe(r),[r]),O=G?null:"请输入正整数秒数",A=U??O,L=T||!!A,D=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),I=b.useMemo(()=>hI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),B=b.useMemo(()=>Rfe(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>hI(P,V),[P,V]);function Y(){return{...d?{clearApiKey:!0}:{},...!d&&l.trim()?{apiKey:l.trim()}:{},region:t.region,asrModel:t.asrModel.trim(),ttsModel:t.ttsModel.trim(),ttsVoice:t.ttsVoice.trim(),turnIdleSeconds:G??d0.turnIdleSeconds}}async function j(){if(T)return;if(A){_({kind:"error",message:A});return}const Q=Ft;if(!Q){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ce=Y();ne(),_({kind:"saving"});const ie=performance.now();try{const le=await Q.updateVoiceConfig(ce);if(!N.current)return;const be=performance.now()-ie;if(be<lI&&await kfe(lI-be),!N.current)return;if(!le.success||le.error||!le.config){_({kind:"error",message:le.error??"保存语音设置失败"});return}n(le.config),i(String(le.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),k.current=setTimeout(()=>{k.current=null,_(Le=>Le.kind==="saved"?{kind:"idle"}:Le)},xfe),Q.requestVoiceCapabilities({region:le.config.region}).then(Le=>{N.current&&Le.capabilities&&o(Le.capabilities)}).catch(()=>{N.current&&o(Gg())})}catch(le){if(!N.current)return;_({kind:"error",message:le instanceof Error?le.message:"保存语音设置失败"})}}async function q(){if(T)return;if(A){_({kind:"error",message:A});return}const Q=Ft;if(!Q){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce;try{ce=K()}catch(ie){_({kind:"error",message:fI(ie)});return}_({kind:"testing"});try{const[ie]=await Promise.all([Q.testVoiceConfig(Y()),ce.ready]);if(!ie.success||ie.error){$(),_({kind:"error",message:ie.error??"语音配置测试失败"});return}const le=await J(ie,ce.context);_({kind:"playingTest",transcript:ie.transcript}),R.current=setTimeout(()=>{R.current=null,$(),_({kind:"testPassed",transcript:ie.transcript})},le)}catch(ie){$(),_({kind:"error",message:fI(ie)})}}function K(){$();const Q=bk.acquire("playback");S.current=Q;try{const ce=Cfe();return w.current=ce,{context:ce,ready:dI(ce)}}catch(ce){throw Q.release(),S.current=null,ce}}function $(){var Q,ce,ie;R.current&&(clearTimeout(R.current),R.current=null),(Q=x.current)==null||Q.stop(),x.current=null,(ce=w.current)==null||ce.close(),w.current=null,(ie=S.current)==null||ie.release(),S.current=null}function ne(){k.current&&(clearTimeout(k.current),k.current=null)}async function J(Q,ce){if(!Q.audioBase64)throw new Error("语音测试未返回可播放音频");if(Q.audioEncoding&&Q.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ie=Q.audioSampleRate??24e3,le=Efe(Q.audioBase64);if(le.byteLength===0||le.byteLength%2!==0)throw new Error("测试音频数据无效");await dI(ce);const be=new Q4(ce,ie);x.current=be,be.enqueue(le);const Le=Math.ceil(le.byteLength/2/ie*1e3);return Math.max(wfe,Le)}function te(Q){var ce;return((ce=S1(s.ttsVoices,Q)[0])==null?void 0:ce.value)??""}return m.jsxs("form",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-slot":"voice-settings-panel",autoComplete:"off",onSubmit:Q=>{Q.preventDefault(),j()},children:[m.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:m.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:m.jsxs("div",{className:"space-y-3","data-slot":"voice-settings-fields",children:[m.jsx("div",{className:"grid gap-2 rounded-lg border border-border/75 bg-card/55 p-3.5 sm:p-3",children:m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsxs("div",{className:"min-w-0",children:[m.jsx("div",{className:"text-[13px] font-medium leading-none text-muted-foreground",children:"服务商"}),m.jsx("div",{className:"mt-2 truncate text-base font-medium text-foreground md:text-sm",children:"阿里云百炼"})]}),m.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"})]})}),m.jsx(cI,{label:"阿里云百炼 API Key",help:d?"保存后会清空已保存的 key":null,children:m.jsxs("div",{className:"flex min-w-0 gap-2",children:[m.jsxs("div",{className:"relative min-w-0 flex-1",children:[m.jsx(sz,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),m.jsx("input",{"aria-label":"阿里云百炼 API Key",type:"password",name:"dev-anywhere-bailian-api-key",autoComplete:"off",value:l,onChange:Q=>{u(Q.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${aI} w-full pl-9`})]}),t.configured&&m.jsxs(pt,{type:"button",variant:"outline",className:"min-h-11 shrink-0 px-3 md:h-9 md:min-h-0",onClick:()=>{u(""),f(!0)},children:[m.jsx(dz,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(uv,{label:"地域",value:t.region,options:D,onChange:Q=>n(ce=>({...ce,region:Q==="intl"?"intl":"cn"}))}),m.jsx(uv,{label:"语音识别模型",value:t.asrModel,options:I,onChange:Q=>n(ce=>({...ce,asrModel:Q}))}),m.jsx(uv,{label:"语音合成模型",value:t.ttsModel,options:B,onChange:Q=>n(ce=>({...ce,ttsModel:Q,ttsVoice:te(Q)}))}),m.jsx(uv,{label:"语音音色",value:V,options:F,placeholder:P.length===0?"暂无可用音色":"请选择音色",onChange:Q=>n(ce=>({...ce,ttsVoice:Q})),help:U}),m.jsx(cI,{label:"结束停顿时间(秒)",help:O,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:Q=>i(Q.target.value),className:`${aI} w-full`})})]})})}),m.jsxs("div",{className:"bg-background/95 px-4 pb-3.5 pt-0 backdrop-blur sm:px-5","data-slot":"voice-settings-footer",children:[m.jsx("div",{className:"mr-4 border-t border-border/70","data-slot":"voice-settings-footer-divider"}),m.jsxs("div",{className:"mt-3.5 flex items-center justify-end gap-2",children:[M?m.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:M}):null,m.jsxs(pt,{type:"button",variant:"outline",disabled:L,onClick:()=>void q(),children:[m.jsx(lz,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(pt,{type:"submit",disabled:L,children:[m.jsx(NY,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function Efe(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 Cfe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function dI(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function fI(e){return e instanceof Error?e.message:"语音配置测试失败"}function kfe(e){return new Promise(t=>setTimeout(t,e))}function Tfe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function hI(e,t){const n=e.map(r=>({value:r.value,label:eF(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Rfe(e,t,n){const r=e.map(i=>{const s=S1(t,i.value).length===0;return{value:i.value,label:`${eF(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function J4(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 eF(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 Afe=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],Nfe=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],_k="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function tF(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 Mfe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Pfe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Ife(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function E1({open:e,onOpenChange:t}){const n=Te(G=>G.relayUrl),r=Te(G=>G.latencyMonitorEnabled),i=Te(G=>G.setLatencyMonitorEnabled),s=Te(G=>G.sessionIdleNotificationsEnabled),o=Te(G=>G.setSessionIdleNotificationsEnabled),l=Te(G=>G.inputModePreference),u=Te(G=>G.setInputModePreference),d=Te(G=>G.themePreference),f=Te(G=>G.setThemePreference),p=Te(G=>G.ptyScrollTraceEnabled),v=Te(G=>G.setPtyScrollTraceEnabled),[g,_]=b.useState("menu"),[w,S]=b.useState(e),[x,R]=b.useState({kind:"idle"}),k=b.useRef(null),N=b.useRef(null),M=sse(),T=b.useMemo(()=>af().osName==="iPad",[]);e!==w&&(S(e),e&&_("menu"));const P=b.useCallback(async G=>{if(!G){o(!1);return}const O=await Nie();if(O==="granted"){o(!0);return}if(O==="denied"){qe.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(O==="default"){qe.info("未授予通知权限,会话通知保持关闭");return}qe.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{R({kind:"loading"});try{const O=await fetch(Mfe(n),{cache:"no-store",signal:G});if(!O.ok)throw new Error(`HTTP ${O.status}`);const A=await O.json();if(A.status!=="ok")throw new Error("状态异常");R({kind:"ready",version:A.version??"未知",uptime:A.uptime??0})}catch(O){if(O instanceof DOMException&&O.name==="AbortError")return;R({kind:"error",message:O instanceof Error?"当前 Relay 服务器无法读取版本":"读取失败"})}},[n]);b.useEffect(()=>{if(!e||g!=="version")return;const G=new AbortController;return z(G.signal),()=>G.abort()},[z,e,g]),b.useEffect(()=>{if(!e||g!=="voice")return;const G=window.requestAnimationFrame(()=>{var O;(O=k.current)==null||O.focus({preventScroll:!0}),N.current&&(N.current.scrollTop=0)});return()=>window.cancelAnimationFrame(G)},[e,g]);const V=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",U=x.kind==="ready"?`运行 ${tF(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(Zi,{open:e,onOpenChange:t,children:m.jsxs(Qi,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",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:k,showCloseButton:g==="menu",children:[m.jsx(Ji,{className:Ye(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"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(pt,{type:"button",variant:"ghost",size:"icon",className:"-ml-2 mt-0.5 size-11 sm:size-9","aria-label":"返回设置","data-slot":"voice-settings-back",onClick:()=>_("menu"),children:m.jsx(sf,{className:"size-4","aria-hidden":"true"})}),m.jsxs("div",{className:"min-w-0 space-y-1.5 pt-0.5 text-left",children:[m.jsx(Fi,{children:Pfe(g)}),m.jsx(Ss,{className:"max-w-[28rem] leading-5",children:Ife(g)})]})]}),g==="voice"?m.jsx("div",{className:"mr-4 mt-3.5 border-t border-border/70","data-slot":"voice-settings-header-divider"}):null]}):m.jsxs(m.Fragment,{children:[m.jsx(Fi,{children:"设置"}),m.jsx(Ss,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(Ofe,{relayVersion:V,relayDetail:U,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(Dfe,{saved:M}):g==="clients"?m.jsx($fe,{}):g==="voice"?m.jsx(Sfe,{scrollRef:N}):m.jsx(Lfe,{relayTokenSaved:M,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:T,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:P,ptyScrollTraceEnabled:p,onPtyScrollTraceEnabledChange:v,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function Ofe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:_k,"data-slot":"settings-dialog-body",children:[m.jsx(mI,{icon:m.jsx(az,{className:"size-4","aria-hidden":"true"}),label:"Web",value:pfe.version,detail:"当前浏览器加载的版本"}),m.jsx(mI,{icon:m.jsx(cz,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Lfe({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:f,onLatencyMonitorEnabledChange:p,onOpenVoice:v,onOpenRelayToken:g,onOpenClients:_,onOpenVersion:w}){return m.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:[m.jsxs(od,{title:"服务",children:[m.jsx(dv,{icon:m.jsx(nV,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:v}),m.jsx(dv,{icon:m.jsx(sz,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(dv,{icon:m.jsx(QY,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(od,{title:"外观",children:m.jsx(pI,{icon:m.jsx($Y,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Afe,onValueChange:n})}),m.jsx(od,{title:"通知",children:m.jsx(h0,{icon:m.jsx(iV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(od,{title:"交互",children:m.jsx(pI,{icon:m.jsx(oz,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:Nfe,onValueChange:i})}):null,m.jsxs(od,{title:"高级诊断",children:[m.jsx(h0,{icon:m.jsx(Zc,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(h0,{icon:m.jsx(ZB,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:p})]}),m.jsx(od,{title:"关于",children:m.jsx(dv,{icon:m.jsx(cz,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function od({title:e,children:t}){return m.jsxs("section",{className:"space-y-2","data-slot":"settings-section",children:[m.jsx("h3",{className:"px-1 text-xs font-medium text-muted-foreground",children:e}),m.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card/55 divide-y divide-border/70",children:t})]})}function pI({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return m.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,m.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 m.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function Dfe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{Jj().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!Zj(f)){const p="Relay Token 保存失败,请检查浏览器存储权限。";o(p),qe.error(p);return}o(null),qe.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{Qj(),l()};return m.jsxs("form",{className:_k,"data-slot":"settings-dialog-body",onSubmit:f=>{f.preventDefault(),u()},children:[m.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[m.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),m.jsx("input",{id:t,type:"password",value:r,onChange:f=>{i(f.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?m.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),m.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?m.jsx(pt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(pt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Bfe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function zfe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Bfe(e)}function jfe(e){return wne(e)}function Ffe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return tF(t)}function f0({label:e,value:t,title:n}){return m.jsxs("div",{className:"grid grid-cols-[3.75rem_minmax(0,1fr)] items-baseline gap-2 text-xs leading-5",children:[m.jsx("span",{className:"shrink-0 text-muted-foreground/80",children:e}),m.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:n??t,children:t})]})}function $fe(){const e=Te(v=>v.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(v=>[v.proxyId,v.name]).filter(v=>typeof v[1]=="string")),[e]),f=b.useCallback(async()=>{const v=Ft;if(!v){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await v.requestRelayClients())}catch(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{f()},[f]);const p=b.useCallback(async v=>{const g=Ft;if(!g){o("Relay 未连接。");return}u(v),o(null);try{const _=await g.kickRelayClient(v);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==v))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:_k,"data-slot":"settings-dialog-body",children:[m.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),m.jsx(pt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(nm,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?m.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?m.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(v=>{const g=v.current===!0,_=l===v.clientId;return m.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":v.clientId,title:`客户端 ${v.clientId}`,children:m.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_7.5rem] sm:items-start",children:[m.jsxs("div",{className:"min-w-0 space-y-1.5",children:[m.jsx("div",{className:"min-w-0",children:m.jsx("div",{className:"truncate text-sm font-medium leading-5 text-foreground",children:jfe(v)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(f0,{label:"已连接",value:Ffe(v.connectedAt)}),v.proxyId?m.jsx(f0,{label:"连接到",value:zfe(v.proxyId,d),title:v.proxyId}):null,v.remoteAddress?m.jsx(f0,{label:"来源 IP",value:v.remoteAddress}):null]})]}),g?m.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:"当前设备"}):m.jsxs(pt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void p(v.clientId),"data-slot":"relay-client-action",children:[m.jsx(rY,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},v.clientId)})]})}function h0({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return m.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:[m.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),m.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),m.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function dv({icon:e,label:t,detail:n,onClick:r}){const i=b.useId(),s=b.useId();return m.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:[m.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}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:i,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:s,className:"mt-1 text-xs text-muted-foreground",children:n}):null]}),m.jsx(pp,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function mI({icon:e,label:t,value:n,detail:r,muted:i=!1}){return m.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[m.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[m.jsx("div",{className:"text-sm text-muted-foreground",children:t}),m.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const Hfe="xterm-helper-textarea";function Ufe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(Hfe)?!1:(e.blur(),!0)}function gI(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&&Wfe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Wfe(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 qfe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Ufe()},[e]),i=b.useCallback(l=>{var u;n.current=((u=l.touches[0])==null?void 0:u.clientY)??null,r()},[r]),s=b.useCallback(l=>{if(!t)return;const u=l.touches[0];if(!u)return;const f=(n.current??u.clientY)-u.clientY;n.current=u.clientY,gI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(gI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Vfe({className:e}){const t=Te(o=>o.sidebarCollapsed),n=Te(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=qfe();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(yI,{collapsed:!0,onClick:n}),m.jsx("div",{className:"mt-3 h-px w-5 bg-border/70","aria-hidden":"true"}),m.jsxs("div",{className:"mt-auto flex flex-col gap-2",children:[m.jsx(vI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(rI,{compact:!0})]})]}),m.jsx(E1,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[m.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:m.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx(Az,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(yI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(O4,{layout:"dropdown",variant:"sidebarChrome"})})]})}),m.jsx("div",{className:"dev-sidebar-fade flex min-h-0 flex-1 flex-col overflow-hidden","data-slot":"sidebar-session-list",children:m.jsx("div",{className:"flex-1 min-h-0",children:m.jsx(Y4,{layout:"sidebar"})})}),m.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:[m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(rI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(vI,{onClick:()=>i(!0)})})]})]}),m.jsx(E1,{open:r,onOpenChange:i})]})}function vI({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(gf,{delayDuration:500,children:[m.jsx(vf,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(uz,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(yf,{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 yI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?gY:pY;return m.jsxs(gf,{delayDuration:500,children:[m.jsx(vf,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(yf,{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 Yfe=1500,Kfe=300,bI=70,_I=35;function nF({texts:e,className:t}){const[n,r]=b.useState(""),[i,s]=b.useState(!0),o=b.useRef("typing"),l=b.useRef(0),u=b.useRef(0);b.useEffect(()=>{const f=setInterval(()=>s(p=>!p),530);return()=>clearInterval(f)},[]),b.useEffect(()=>{let f;const p=()=>e[u.current%e.length],v=()=>{const g=o.current;if(g==="typing"){const _=p();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(v,bI)):(o.current="paused",f=setTimeout(v,Yfe))}else g==="paused"?(o.current="deleting",f=setTimeout(v,_I)):g==="deleting"?l.current>0?(l.current-=1,r(p().slice(0,l.current)),f=setTimeout(v,_I)):(u.current+=1,o.current="waiting",f=setTimeout(v,Kfe)):(o.current="typing",f=setTimeout(v,bI))};return f=setTimeout(v,500),()=>clearTimeout(f)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return m.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[m.jsx("span",{className:"text-green-500",children:"> "}),m.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),m.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),m.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const rF=["DEV Anywhere","/unlimited @anytime"];function Gfe({subtitle:e,action:t}){return m.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:m.jsxs("div",{className:"dev-mobile-brand-content min-w-0 space-y-3 pr-12",children:[m.jsx(nF,{texts:rF,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),e?m.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}):null,t?m.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Xfe=3e3,Zfe=1e4,fv=12,Qfe=4,wI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Jfe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function p0(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 ad(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function ip(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function xI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function iF(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function ehe(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 the(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?ip(e.rttMs):"等待检测"}function nhe(){const e=Ci("local",Sn.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 SI(e){Tr("local",Sn.latencyMonitorPosition,JSON.stringify(e))}function rhe(){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 m0(e,t){const n=rhe(),r=fv,i=fv,s=Math.max(r,n.width-t.width-fv),o=Math.max(i,n.height-t.height-fv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function ihe(){const e=Te(T=>T.latencyMonitorEnabled),t=Te(T=>T.connected),n=Te(T=>T.proxyOnline),r=Te(T=>T.selectedProxyId),[i,s]=b.useState(Jfe),[o,l]=b.useState(()=>nhe()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),p=b.useRef(!1),v=b.useMemo(()=>(Object.values(i).sort((T,P)=>xI(P.state)-xI(T.state))[0]??{state:"idle"}).state,[i]),g=iF(v);async function _(){if(u.current)return;const T=Ft;if(!T||!t){const U=ad("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:ad("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:ad("未连接开发机")}));const[P,z,V]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:P.status==="fulfilled"?p0(P.value):ad(P.reason instanceof Error?P.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?p0(z.value):ad(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:V.status==="fulfilled"?p0(V.value):ad(V.reason instanceof Error?V.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,P=null;const z=async()=>{await _(),!T&&(P=setTimeout(z,document.hidden?Zfe:Xfe))};return z(),()=>{T=!0,u.current=!1,P&&clearTimeout(P)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const P=T.getBoundingClientRect(),z=m0(o,{width:P.width,height:P.height});z.x===o.x&&z.y===o.y||(l(z),SI(z))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,S=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(T){var z,V;if(T.button!==0)return;const P=T.currentTarget.getBoundingClientRect();f.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:P.left,originY:P.top,width:P.width,height:P.height,dragging:!1},(V=(z=T.currentTarget).setPointerCapture)==null||V.call(z,T.pointerId)}function R(T){const P=f.current;if(!P||P.pointerId!==T.pointerId)return;const z=T.clientX-P.startX,V=T.clientY-P.startY;if(!P.dragging&&Math.hypot(z,V)<Qfe)return;P.dragging=!0,T.preventDefault();const U=m0({x:P.originX+z,y:P.originY+V},{width:P.width,height:P.height});l(U)}function k(T){var G,O;const P=f.current;if(!P||P.pointerId!==T.pointerId||(f.current=null,(O=(G=T.currentTarget).releasePointerCapture)==null||O.call(G,T.pointerId),!P.dragging))return;T.preventDefault(),p.current=!0,window.setTimeout(()=>{p.current=!1},200);const z=T.clientX-P.startX,V=T.clientY-P.startY,U=m0({x:P.originX+z,y:P.originY+V},{width:P.width,height:P.height});l(U),SI(U)}function N(T){var z,V;const P=f.current;!P||P.pointerId!==T.pointerId||(f.current=null,(V=(z=T.currentTarget).releasePointerCapture)==null||V.call(z,T.pointerId))}function M(T){p.current&&(p.current=!1,T.preventDefault(),T.stopPropagation())}return m.jsxs(Ib,{children:[m.jsx(Ob,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",ehe(g)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${ip(i.webRelay.rttMs)},开发机 ${ip(w.rttMs)}`,onPointerDown:x,onPointerMove:R,onPointerUp:k,onPointerCancel:N,onClickCapture:M,children:[m.jsx(ZB,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{className:"font-medium text-foreground",children:"延迟"}),m.jsxs("span",{className:"hidden text-muted-foreground sm:inline",children:["Relay ",ip(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",ip(w.rttMs)]}),m.jsx(ec,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(Lb,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[m.jsxs("div",{className:"flex items-start justify-between gap-3",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),m.jsx(pt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(nm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(wI).map(T=>m.jsx(she,{label:wI[T],measurement:i[T]},T))})]})]})}function she({label:e,measurement:t}){const n=iF(t.state);return m.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:[m.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:the(t)})]})]})}const sF="/__dev_anywhere_debug/browser-state-dumps",ohe=1500,ahe=10,g0=80,wk=500,lhe=["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"],che=["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 EI(){if(typeof window>"u")return"off";const e=hF("debugDump");return e==="auto"?"auto":e!==null||yhe("debugInput")?"manual":"off"}function uhe(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:phe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:CI(document.activeElement),selection:mhe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>CI(i)).filter(i=>!!i),root:oF(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:ld(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:ld(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:ld(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:ld(()=>kI(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:ld(()=>kI(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:ld(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function dhe(e="manual"){const t=uhe(e);return fhe(t)}async function fhe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await hhe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:sF}}catch(r){const i=pF(r),s=ghe(e.createdAt);return vhe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function hhe(e){const t=await fetch(sF,{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 oF(e,t,n){if(n.count>=ohe||t>ahe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=TI(e.textContent??"");return u?{kind:"text",text:Ub(u,wk)}:{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,g0))u.nodeType===Node.TEXT_NODE&&!TI(u.textContent??"")||r.push(oF(u,t+1,n));s.length>g0&&(i=s.length-g0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:fF(e),attrs:aF(e),rect:lF(e),scroll:cF(e),style:uF(e)},l=dF(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function CI(e){if(!(e instanceof HTMLElement))return null;const t=dF(e);return{path:fF(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:aF(e),rect:lF(e),scroll:cF(e),style:uF(e),...t?{value:t}:{}}}function phe(){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 aF(e){const t={};for(const n of lhe){const r=e.getAttribute(n);r!==null&&(t[n]=Ub(r,500))}return t}function lF(e){const t=e.getBoundingClientRect();return{x:xs(t.x),y:xs(t.y),width:xs(t.width),height:xs(t.height),top:xs(t.top),right:xs(t.right),bottom:xs(t.bottom),left:xs(t.left)}}function cF(e){return{top:xs(e.scrollTop),left:xs(e.scrollLeft),height:xs(e.scrollHeight),width:xs(e.scrollWidth),clientHeight:xs(e.clientHeight),clientWidth:xs(e.clientWidth)}}function uF(e){const t=window.getComputedStyle(e),n={};for(const r of che)n[r]=t.getPropertyValue(r);return n}function dF(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Ub(e.value,wk),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function mhe(){var e;try{return Ub(((e=window.getSelection())==null?void 0:e.toString())??"",wk)}catch{return null}}function fF(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 ghe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function vhe(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 yhe(e){return hF(e)!==null}function hF(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 kI(e){return e?Iy(e.slice(-200)):null}function ld(e){try{return Iy(e())}catch(t){return{error:pF(t)}}}function Iy(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(Iy);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Iy(r);return t}return String(e)}function TI(e){return e.replace(/\s+/g," ").trim()}function Ub(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function xs(e){return Math.round(e*100)/100}function pF(e){return e instanceof Error?e.message:String(e)}const bhe=500,_he=1e3,whe=60;function xhe(){const[e,t]=b.useState(()=>EI()),[n,r]=b.useState(!1),[i,s]=b.useState(null),o=b.useRef(null),l=b.useRef(!1),u=b.useRef(0),d=b.useRef(0),f=b.useRef(null);b.useEffect(()=>{const _=()=>t(EI());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const p=b.useCallback(async(_="manual")=>{if(l.current)return o.current??{status:"failed",error:"dump already running"};l.current=!0,r(!0);try{const w=await dhe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&She(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=p,()=>{window.__devAnywhereDumpBrowserState===p&&delete window.__devAnywhereDumpBrowserState}),[p]),b.useEffect(()=>{var R,k;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=N=>{d.current>=whe||(_(),f.current=window.setTimeout(()=>{f.current=null;const M=Date.now(),T=_he-(M-u.current);if(T>0){f.current=window.setTimeout(()=>w(N),T);return}u.current=Date.now(),d.current+=1,p(`auto:${d.current}:${N}`)},bhe))};w("initial");const S=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=N=>w(N.type);return S.forEach(N=>window.addEventListener(N,x,!0)),(R=window.visualViewport)==null||R.addEventListener("resize",x),(k=window.visualViewport)==null||k.addEventListener("scroll",x),()=>{var N,M;_(),S.forEach(T=>window.removeEventListener(T,x,!0)),(N=window.visualViewport)==null||N.removeEventListener("resize",x),(M=window.visualViewport)==null||M.removeEventListener("scroll",x)}},[p,e]),e==="off")return null;const v=e==="auto"?"自动诊断中":"保存诊断",g=Ehe(i);return m.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?m.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,m.jsxs(pt,{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?m.jsx(oi,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(jV,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:v})]})]})}function She(e){if(e.status==="saved"){qe.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){qe.info(`诊断已下载: ${e.filename}`);return}qe.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function Ehe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Che({issue:e}){const t=e==="unreachable"?"暂时无法连接":e==="page_outdated"?"当前页面版本较旧,请刷新后重试":e==="service_outdated"?"服务端版本较旧,请更新服务后重试":e==="protocol_mismatch"?"页面与服务端版本不一致,请刷新后重试":"连接已断开",n=e==="page_outdated"||e==="protocol_mismatch"?"刷新页面":e==="service_outdated"?"重新检测":null;return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 px-6 text-center text-muted-foreground","data-slot":"relay-connection-state","data-state":"unavailable","data-issue":e,role:"status","aria-live":"polite",children:[e==="unreachable"?m.jsx(oi,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(pt,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function khe(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 xk(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:khe(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 f=l();if(i){const p=i(d);if(p!==null){const v=s.get(d.event);if(v&&i(v)===p&&f.includes(v)){v.t=d.t,v.repeat=(v.repeat??0)+1;const g=f.indexOf(v);g>=0&&g!==f.length-1&&(f.splice(g,1),f.push(v)),u(f);return}}}if(f.push(d),i&&s.set(d.event,d),f.length>r){const p=f.splice(0,f.length-r);if(i)for(const v of p)s.get(v.event)===v&&s.delete(v.event)}u(f)},getAll:l}}function Yn(e){return Math.round(e*10)/10}function Il(e){return e.length===0?"":`${Yn(Math.min(...e))}..${Yn(Math.max(...e))}`}function Ad(e){return[...new Set(e.filter(t=>t!==void 0).map(Yn))]}function mF(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 The="dev_anywhere_pty_input_latency_trace",RI=80,Rhe=1e4,Ahe=new TextDecoder;let Nhe=0;const Jd=new Map,bu=xk({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:The,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Mhe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Lhe)}function Phe(e,t){if(!bu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++Nhe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:zhe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=Jd.get(e)??[];return s.push(i),Ek(s,r),Jd.set(e,s),vm({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function AI(e,t){if(!e||!bu.isEnabled())return;const n=performance.now(),r=Dhe(e.sessionId,e.inputId);r&&(r.sentAt=n),vm({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 Ihe(e,t,n){if(!bu.isEnabled())return;const r=performance.now(),i=Sk(e,r),s=$he(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&Fhe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));vm({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:Ck(i,r),details:Hhe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Ohe(e,t,n=1){if(!bu.isEnabled())return;const r=performance.now(),i=Sk(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));vm({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:Ck(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Bhe(e,s))}function Lhe(){const e=bu.getAll(),t=e.slice(-200),n=[...Jd.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Yn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Yn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Yn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Yn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Yn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Yn(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?"":Yn(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(`
591
591
  `)}function vm(e){bu.append(e)}function Sk(e,t){const n=Jd.get(e)??[];return Ek(n,t),Jd.set(e,n),n}function Ek(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>Rhe;(i||s)&&e.splice(n,1)}e.length>RI&&e.splice(0,e.length-RI)}function Dhe(e,t){return(Jd.get(e)??[]).find(n=>n.inputId===t)??null}function Bhe(e,t){if(!bu.isEnabled())return;const n=performance.now(),r=Sk(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)}vm({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:Ck(r,n),details:i>0?`paint=${i}`:""}),Ek(r,n)}function Ck(e,t){const n=e[0];return n?t-n.startedAt:null}function zhe(e){return e==="\r"||e===`
592
592
  `?"enter":e.startsWith("\x1B")?"escape":jhe(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function jhe(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 Fhe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function $he(e){try{return Ahe.decode(e)}catch{return""}}function Hhe(e){return e.filter(Boolean).join(" ")}function $s(e,t){if(!e||!t)return;const n=Phe(e,t),r=Fa;if(!r){AI(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});AI(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}function Uhe({sessionId:e,enabled:t,waiting:n,approvalRequestId:r,approvalScopeKey:i=e,history:s,sendRawInput:o=$s}){const l=b.useRef(new Map),u=s??l.current;b.useEffect(()=>{let d=u.get(i);if(d||(d={sent:!1,confirmedRequestIds:new Set},u.set(i,d)),!n){d.sent=!1,d.confirmedRequestId=void 0;return}if(r&&d.confirmedRequestIds.has(r)){d.sent=!0,d.confirmedRequestId=r;return}if(d.sent&&r&&d.confirmedRequestId===void 0){d.confirmedRequestId=r,d.confirmedRequestIds.add(r);return}d.sent&&(!r||d.confirmedRequestId===r)||t&&(d.sent=!0,d.confirmedRequestId=r,r&&d.confirmedRequestIds.add(r),o(e,"\r"))},[u,r,i,t,o,e,n])}function Whe(e){var i,s;if(e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.provider==="codex")return null;const t=PC(e.proxyId,e.session.sessionId);if(!t)return null;const n=!["idle","error","terminated"].includes(e.session.state),r=((i=e.agentStatus)==null?void 0:i.provider)===e.session.provider&&e.agentStatus.phase==="waiting_permission"?(s=e.agentStatus.permissionRequest)==null?void 0:s.requestId:void 0;return{key:t,sessionId:e.session.sessionId,enabled:e.connected&&e.proxyOnline&&!!e.autoYesBySessionKey[t],waiting:n&&(e.session.state==="waiting_approval"||!!r),approvalRequestId:r}}function qhe({target:e,sendRawInput:t,history:n}){return Uhe({sessionId:e.sessionId,enabled:e.enabled,waiting:e.waiting,approvalRequestId:e.approvalRequestId,approvalScopeKey:e.key,history:n,sendRawInput:t}),null}function Vhe({sendRawInput:e=$s}){const t=Te(d=>d.connected),n=Te(d=>d.proxyOnline),r=Te(d=>d.selectedProxyId),i=Gt(d=>d.sessions),s=Gt(d=>d.agentStatusBySessionId),o=Gt(d=>d.ptyAutoYesBySessionKey),l=b.useRef(new Map),u=i.map(d=>Whe({proxyId:r,session:d,agentStatus:s[d.sessionId],autoYesBySessionKey:o,connected:t,proxyOnline:n})).filter(d=>d!==null);return m.jsx(m.Fragment,{children:u.map(d=>m.jsx(qhe,{target:d,sendRawInput:e,history:l.current},d.key))})}function Yhe(e,t){return e.some(n=>n.sessionId===t)?e:[...e,{sessionId:t}]}var Wc=function(e,t){return Number(e.toFixed(t))},Khe=function(e,t){return t},nr=function(e,t,n){n&&typeof n=="function"&&n(e,t)},Ghe=function(e){return-Math.cos(e*Math.PI)/2+.5},Xhe=function(e){return e},Zhe=function(e){return e*e},Qhe=function(e){return e*(2-e)},Jhe=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},epe=function(e){return e*e*e},tpe=function(e){return--e*e*e+1},npe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},rpe=function(e){return e*e*e*e},ipe=function(e){return 1- --e*e*e*e},spe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},ope=function(e){return e*e*e*e*e},ape=function(e){return 1+--e*e*e*e*e},lpe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},gF={easeOut:Ghe,linear:Xhe,easeInQuad:Zhe,easeOutQuad:Qhe,easeInOutQuad:Jhe,easeInCubic:epe,easeOutCubic:tpe,easeInOutCubic:npe,easeInQuart:rpe,easeOutQuart:ipe,easeInOutQuart:spe,easeInQuint:ope,easeOutQuint:ape,easeInOutQuint:lpe},vF=function(e){typeof e=="number"&&cancelAnimationFrame(e)},To=function(e){e.mounted&&(vF(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function yF(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;To(e),e.animation=function(){if(!e.mounted)return vF(e.animation);var o=new Date().getTime()-i,l=o/n,u=gF[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function cpe(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function dc(e,t,n,r){var i=cpe(t);if(!(!e.mounted||!i)){var s=e.setState,o=e.state,l=o.scale,u=o.positionX,d=o.positionY,f=t.scale-l,p=t.positionX-u,v=t.positionY-d;n===0?s(t.scale,t.positionX,t.positionY):yF(e,r,n,function(g){g!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+f*g,w=u+p*g,S=d+v*g;s(_,w,S)})}}function upe(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,f=i-u;return{wrapperWidth:r,wrapperHeight:i,newContentWidth:l,newDiffWidth:d,newContentHeight:u,newDiffHeight:f}}var dpe=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,f=l,p=r-i-u,v=u;return{minPositionX:d,maxPositionX:f,minPositionY:p,maxPositionY:v,scaleWidthFactor:l,scaleHeightFactor:u}},kk=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=upe(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,f=l.newContentWidth,p=l.newContentHeight,v=l.newDiffWidth,g=l.newDiffHeight,_=dpe(u,f,v,d,p,g,!!s),w=u>=f&&d>=p;o&&w&&!s&&(_.minPositionX=0,_.maxPositionX=0,_.minPositionY=0,_.maxPositionY=0);var S=e.setup,x=S.minPositionX,R=S.maxPositionX,k=S.minPositionY,N=S.maxPositionY;return x!=null&&(_.minPositionX=u*(1-t)+x*t),R!=null&&(_.maxPositionX=R*t),k!=null&&(_.minPositionY=d*(1-t)+k*t),N!=null&&(_.maxPositionY=N*t),_},jp=function(e,t,n,r){return r?e<t?Wc(t,2):e>n?Wc(n,2):Wc(e,2):Wc(e,2)},ef=function(e,t){var n=kk(e,t);return e.bounds=n,n};function ym(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,f=n.maxPositionY,p=0,v=0;o&&(p=i,v=s);var g=jp(e,l-p,d+p,r),_=jp(t,u-v,f+v,r);return{x:g,y:_}}function Wb(e,t,n,r,i,s){var o=e.state,l=o.scale,u=o.positionX,d=o.positionY,f=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*f,v=d-n*f,g=ym(p,v,i,s,0,0,null);return g}var NI=1e-7;function bm(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,NI),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,NI)}var MI=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(f){return f instanceof Element?i==null?void 0:i.contains(f):!1}):i==null?void 0:i.contains(s),u=r&&s&&l;if(!u)return!1;var d=_m(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},PI=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},fpe=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}},hpe=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 ppe(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 f=e.bounds,p=f.maxPositionX,v=f.minPositionX,g=f.maxPositionY,_=f.minPositionY,w=n>p||n<v,S=r>g||r<_,x=n>p?d.offsetWidth:e.setup.minPositionX||0,R=r>g?d.offsetHeight:e.setup.minPositionY||0,k=Wb(e,x,R,i,e.bounds,l||u),N=k.x,M=k.y;return{scale:i,positionX:w?N:n,positionY:S?M:r}}}function bF(e,t,n,r,i){var s=e.setup.limitToBounds,o=e.wrapperComponent,l=e.bounds,u=e.state,d=u.scale,f=u.positionX,p=u.positionY;if(!(o===null||l===null||t===f&&n===p)){var v=ym(t,n,l,s,r,i,o),g=v.x,_=v.y;e.setState(d,g,_)}}var mpe=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 f=t-r.x,p=n-r.y,v=o?u:f,g=l?d:p;return{x:v,y:g}},Zl=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},$l;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})($l||($l={}));var gpe=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 f=n.offsetWidth<r.offsetWidth*u||n.offsetHeight<r.offsetHeight*u;return f},vpe=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 ype(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 II(e,t,n,r,i,s,o,l,u,d){if(i){if(t>o&&n>o){var f=o+(e-o)*d;return f>u?u:f<o?o:f}if(t<s&&n<s){var f=s+(e-s)*d;return f<l?l:f>s?s:f}}return r?t:jp(e,s,o,i)}function bpe(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var v0=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 _pe(e,t,n){var r,i,s=gpe(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,f=u.velocityAnimation,p=f.maxStrengthMouse,v=f.maxStrengthTouch,g=f.sensitivityTouch,_=f.sensitivityMouse,w=Date.now();if(o&&l&&d){var S=bpe(d),x=(r={},r[$l.TOUCH]=g,r[$l.MOUSE]=_,r)[n],R=(i={},i[$l.TOUCH]=v,i[$l.MOUSE]=p,i)[n],k=t.x-o.x,N=t.y-o.y,M=v0(k/S,R,x),T=v0(N/S,R,x),P=w-l,z=k*k+N*N,V=v0(Math.sqrt(z)/P,R,x);e.velocity={velocityX:M,velocityY:T,total:V}}e.lastMousePosition=t,e.velocityTime=w}}function wpe(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=vpe(e);if(!(!s||!t||!n||!i)){var o=t.velocityX,l=t.velocityY,u=t.total,d=n.maxPositionX,f=n.minPositionX,p=n.maxPositionY,v=n.minPositionY,g=r.limitToBounds,_=r.autoAlignment,w=r.zoomAnimation,S=r.panning,x=S.lockAxisY,R=S.lockAxisX,k=w.animationType,N=_.sizeX,M=_.sizeY,T=_.velocityAlignmentTime,P=T,z=ype(e,u),V=Math.max(z,P),U=Zl(e,N),G=Zl(e,M),O=U*i.offsetWidth/100,A=G*i.offsetHeight/100,L=d+O,D=f-O,I=p+A,B=v-A,F=e.state,Y=new Date().getTime();yF(e,k,V,function(j){var q=e.state,K=q.scale,$=q.positionX,ne=q.positionY,J=new Date().getTime()-Y,te=J/P,Q=gF[_.animationType],ce=1-Q(Math.min(1,te)),ie=1-j,le=$+o*ie,be=ne+l*ie,Le=II(le,F.positionX,$,R,g,f,d,D,L,ce),he=II(be,F.positionY,ne,x,g,v,p,B,I,ce);if($!==le||ne!==be){e.setState(K,Le,he);var He=e.props.onPanning;He&&He(Kn(e),{})}})}}function OI(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},To(e),ef(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?hpe(e,t):fpe(e,t)}function _F(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,f=s.animationType,p=o||n<i||!l&&!u;if(!p){var v=ppe(e);v&&dc(e,v,d,f)}}function LI(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=mpe(e,t,n),f=d.x,p=d.y,v=Zl(e,l),g=Zl(e,u);_pe(e,{x:f,y:p},r),bF(e,f,p,v,g)}}function xpe(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 f=o-d.x,p=l-d.y;if(f*f+p*p<=25)return}e.isAnimating=!1,e.animation=null;var v=(r==null?void 0:r.offsetWidth)||0,g=(r==null?void 0:r.offsetHeight)||0,_=((i==null?void 0:i.offsetWidth)||0)*u,w=((i==null?void 0:i.offsetHeight)||0)*u,S=!e.setup.limitToBounds||v<_||g<w,x=!t&&n&&n.total>.1&&S;x?wpe(e):_F(e)}}function Tk(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=bm(Wc(t,2),s,o,0,!1),d=ef(e,u),f=Wb(e,n,r,u,d,l),p=f.x,v=f.y;return{scale:u,positionX:p,positionY:v}}function Rk(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,f=d.disabled,p=d.animationTime,v=d.animationType,g=r>=o&&r<=l,_=f||g;if((r>=1||u)&&_F(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,S=n||i.offsetHeight/2,x=r<o?o:l,R=Tk(e,x,w,S);R&&dc(e,R,p,v)}}var co=function(){return co=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},co.apply(this,arguments)};function DI(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 y0={scale:1,positionX:0,positionY:0},Hc={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"}},C1={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},wF=function(e){var t,n,r,i,s,o,l,u,d,f=Math.max((t=e.minScale)!==null&&t!==void 0?t:Hc.minScale,1e-7),p=(n=e.maxScale)!==null&&n!==void 0?n:Hc.maxScale,v=(r=e.initialScale)!==null&&r!==void 0?r:y0.scale,g=Math.min(Math.max(v,f),p),_=jp((i=e.initialPositionX)!==null&&i!==void 0?i:y0.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=jp((l=e.initialPositionY)!==null&&l!==void 0?l:y0.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:_,positionY:w}},BI=function(e){var t=co({},Hc);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Hc[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Hc[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=co(co({},Hc[r]),e[r]):u?t[r]=DI(DI([],Hc[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},xF=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,f=u.size;if(!i)throw new Error("Wrapper is not mounted");var p=d?r*Math.exp(t*n):r+t*n,v=bm(Wc(p,3),l,o,f,!1);return v};function SF(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,f=u.positionX,p=u.positionY,v=e.setup.zoomAnimation;if(!l)return console.error("No WrapperComponent found");var g=v.disabled?0:r,_=l.offsetWidth,w=l.offsetHeight,S=(_/2-f)/d,x=(w/2-p)/d,R=xF(e,t,n),k=Tk(e,R,S,x);if(!k)return console.error("Error during zoom event. New transformation state was not calculated.");var N=e.props,M=N.onZoomStart,T=N.onZoom,P=N.onZoomStop,z=new MouseEvent("mousemove",{bubbles:!0}),V=Kn(e);nr(V,z,M),nr(V,z,T),dc(e,k,g,i);var U=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;U&&U.setTimeout(function(){e.mounted&&nr(Kn(e),z,P)},g)}function EF(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,f=o.centerOnInit,p=wF(e.props),v=e.state,g=v.scale,_=v.positionX,w=v.positionY;if(l){var S=p.positionX,x=p.positionY;if(f&&u){var R=Ak(p.scale,l,u);S=R.positionX,x=R.positionY}var k=kk(e,p.scale),N=ym(S,x,k,d,0,0,l),M={scale:p.scale,positionX:N.x,positionY:N.y};if(!(g===p.scale&&_===p.positionX&&w===p.positionY)){r==null||r();var T=e.props,P=T.onZoomStart,z=T.onZoom,V=T.onZoomStop,U=new MouseEvent("mousemove",{bubbles:!0}),G=Kn(e);nr(G,U,P),nr(G,U,z),dc(e,M,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&&nr(Kn(e),U,V)},t)}}}function Spe(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 Epe(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,f=u.minScale,p=u.maxScale;if(!s||!o)return l;var v=s.getBoundingClientRect(),g=t.getBoundingClientRect(),_=Spe(t,s,o,l),w=_.x,S=_.y,x=g.width/l.scale,R=g.height/l.scale,k=s.offsetWidth/x,N=s.offsetHeight/R,M=bm(n||Math.min(k,N),f,p,0,!1),T=(v.width-x*M)/2,P=(v.height-R*M)/2,z=(v.left-w)*M+T+r,V=(v.top-S)*M+P+i,U=kk(e,M),G=ym(z,V,U,d,0,0,s),O=G.x,A=G.y;return{positionX:O,positionY:A,scale:M}}var Cpe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),SF(e,1,t,n,r)}},kpe=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),SF(e,-1,t,n,r)}},Tpe=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,f=e.wrapperComponent,p=e.contentComponent,v=e.setup.disabled;if(!(v||!f||!p)){var g={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};dc(e,g,i,s)}}},Rpe=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),EF(e,t,n)}},Ape=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=Ak(t||i.scale,s,o);dc(e,l,n,r)}}},Npe=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),To(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=Epe(e,u,n,s,o);dc(e,d,r,i)}}},k1=function(e){return{instance:e,state:e.state,zoomIn:Cpe(e),zoomOut:kpe(e),setTransform:Tpe(e),resetTransform:Rpe(e),centerView:Ape(e),zoomToElement:Npe(e)}},Mpe=function(e){return{instance:e,state:e.state}},Kn=function(e){var t={};return Object.assign(t,Mpe(e)),Object.assign(t,k1(e)),t},b0=!1;function _0(){try{var e={get passive(){return b0=!0,!1}};return e}catch{return b0=!1,b0}}var hv=".".concat(C1.wrapperClass),_m=function(e,t){return t.some(function(n){return e.matches("".concat(hv," ").concat(n,", ").concat(hv," .").concat(n,", ").concat(hv," ").concat(n," *, ").concat(hv," .").concat(n," *"))})},Fp=function(e){e&&clearTimeout(e)},Ppe=function(e){return Number.parseFloat(e.toFixed(8))},CF=function(e,t,n){var r=Ppe(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},Ak=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 Ipe(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function Ope(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var kF=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,f=l&&!u&&!r&&d;if(!f||i&&!t.ctrlKey||s&&t.ctrlKey)return!1;var p=_m(d,o);if(p)return!1;var v=e.isPressingKeys(e.setup.wheel.activationKeys);return!!v},Lpe=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=kF(e,t);if(l)return!1;var u=t.target,d=_m(u,o);if(d)return!1;var f=e.isPressingKeys(s);return!!f},Dpe=function(e){return e?e.deltaY<0?1:-1:0};function Bpe(e,t){var n=Dpe(e),r=Khe(t,n);return r}function TF(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 zpe=function(e,t,n,r,i){var s=e.state.scale,o=e.wrapperComponent,l=e.setup,u=l.maxScale,d=l.minScale,f=l.zoomAnimation,p=l.disablePadding,v=f.size,g=f.disabled;if(!o)throw new Error("Wrapper is not mounted");var _=s+t*n,w=r?!1:!g,S=bm(_,d,u,v,w&&!p);return S},RF=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},jpe=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=_m(o,i);return!u},Fpe=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},$pe=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}},AF=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))},Hpe=5,Upe=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,f=l.size,p=l.disabled,v=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,_=g*n,w=(_-n)*(v/Hpe),S=n+w,x=S===1/0?0:Wc(S,10);return bm(x,o,s,f,!p&&!u)},NF=160,MF=100,Wpe=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(To(e),nr(Kn(e),t,r),nr(Kn(e),t,i))},qpe=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,f=o.centerZoomedOut,p=o.zoomAnimation,v=o.wheel,g=o.disablePadding,_=o.smooth,w=p.size,S=p.disabled,x=v.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var R=Bpe(t,null),k=_?x*Math.abs(t.deltaY):x,N=zpe(e,R,k,!t.ctrlKey);if(u!==N){var M=ef(e,N),T=TF(t,s,u),P=S||w===0||f||g,z=d&&P,V=Wb(e,T.x,T.y,N,M,z),U=V.x,G=V.y;e.previousWheelEvent=t,e.setState(N,U,G),nr(Kn(e),t,r),nr(Kn(e),t,i)}},Vpe=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;Fp(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(Rk(e,t.x,t.y),e.wheelAnimationTimer=null)},MF);var s=RF(e,t);s&&(Fp(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,nr(Kn(e),t,r),nr(Kn(e),t,i))},NF))},Ype=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(To(e),nr(Kn(e),t,r),nr(Kn(e),t,i))},Kpe=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;Fp(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(Rk(e,t.x,t.y),e.wheelAnimationTimer=null)},MF);var s=RF(e,t);s&&(Fp(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,nr(Kn(e),t,r),nr(Kn(e),t,i))},NF))},PF=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}},Gpe=function(e,t){var n=AF(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=PF(t),To(e)},Xpe=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,f=l.zoomAnimation,p=l.autoAlignment,v=l.pinch,g=l.panning,_=f.disabled,w=f.size,S=v.allowPanning;if(!(r===null||!n)){var x=$pe(t,o,n);if(!(!Number.isFinite(x.x)||!Number.isFinite(x.y))){var R=AF(t),k=Upe(e,R),N=PF(t),M=o/k,T=(N.x-((s==null?void 0:s.x)||0))*M,P=(N.y-((s==null?void 0:s.y)||0))*M;if(!(k===o&&T===0&&P===0)){e.pinchPreviousCenter=N;var z=ef(e,k),V=_||w===0||d,U=u&&V,G=Wb(e,x.x,x.y,k,z,U),O=G.x,A=G.y;if(e.pinchMidpoint=x,e.lastDistance=R,g.disabled||!S)e.setState(k,O,A);else{var L=p.sizeX,D=p.sizeY,I=Zl(e,L,k),B=Zl(e,D,k),F=O+T,Y=A+P,j=ym(F,Y,z,u,I,B,i),q=j.x,K=j.y;e.setState(k,q,K)}}}}},Zpe=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,Rk(e,t==null?void 0:t.x,t==null?void 0:t.y)},IF=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;Fp(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,nr(Kn(e),t,n)},r)},Qpe=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;nr(Kn(e),t,r),EF(e,o,l,function(){return nr(Kn(e),t,i)}),IF(e,t)};function Jpe(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function eme(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,f=n.doubleClick,p=f.disabled,v=f.mode,g=f.step,_=f.animationTime,w=f.animationType;if(!p&&!r){if(v==="reset")return Qpe(e,t);if(!s)return console.error("No ContentComponent found");var S=Jpe(v,e.state.scale),x=xF(e,S,g);if(o!==x){nr(Kn(e),t,u);var R=TF(t,s,o),k=Tk(e,x,R.x,R.y);if(!k)return console.error("Error during zoom event. New transformation state was not calculated.");nr(Kn(e),t,d),dc(e,k,_,w),IF(e,t)}}}var tme=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),f=n&&u&&d&&!o;if(!f)return!1;var p=_m(u,l);return!p},nme=(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&&ef(n,n.state.scale),n.setup=BI(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=_0(),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=_0(),d=(r=n.wrapperComponent)===null||r===void 0?void 0:r.ownerDocument,f=d==null?void 0:d.defaultView;f==null||f.removeEventListener("mousedown",n.onPanningStart,u),f==null||f.removeEventListener("mousemove",n.onPanning,u),f==null||f.removeEventListener("mouseup",n.onPanningStop,u),d==null||d.removeEventListener("mouseleave",n.clearPanning,u),f==null||f.removeEventListener("keyup",n.setKeyUnPressed,u),f==null||f.removeEventListener("keydown",n.setKeyPressed,u),f==null||f.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),To(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=_0();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=kF(n,r);s&&(Wpe(n,r),qpe(n,r),Vpe(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=Lpe(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,f=d.positionX,p=d.positionY,v=f-r.deltaX,g=p-r.deltaY,_=o?f:v,w=l?p:g,S=n.setup.autoAlignment,x=S.sizeX,R=S.sizeY,k=Zl(n,x),N=Zl(n,R);_===f&&w===p||(Ype(n,r),bF(n,_,w,k,N),nr(Kn(n),r,i),Kpe(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=MI(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(),To(n),OI(n,r),nr(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=PI(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),LI(n,r.clientX,r.clientY,$l.MOUSE),nr(Kn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(xpe(n,i),nr(Kn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=jpe(n,r);o&&(Gpe(n,r),To(n),nr(Kn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=Fpe(n);o&&(r.preventDefault(),r.stopPropagation(),Xpe(n,r),nr(Kn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(Zpe(n),nr(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,To(n);var f=r.touches,p=f.length===1,v=f.length===2,g=MI(n,r);if(p){if(!g)return;To(n),OI(n,r),nr(Kn(n),r,l)}v&&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=PI(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];LI(n,l.clientX,l.clientY,$l.TOUCH),nr(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=tme(n,r);s&&eme(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=Ak(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):CF(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)}),nr(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,ef(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=Kn(n);nr(s,void 0,n.props.onInit),Ipe(n.props.ref,s)},this.props=t,this.setup=BI(this.props),this.state=wF(this.props)}return e})(),qb=dt.createContext(null),rme=function(e,t){return typeof e=="function"?e(t):e},ime=dt.forwardRef(function(e,t){var n=b.useRef(new nme(e)).current,r=rme(e.children,k1(n));return b.useImperativeHandle(t,function(){return k1(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),m.jsx(qb.Provider,co({value:n},{children:r}))});dt.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(qb);return b.useEffect(function(){return r.onChange(function(i){if(n.current){var s=0,o=0;n.current.style.transform=r.handleTransformStyles(s,o,1/i.instance.state.scale)}})},[r]),m.jsx("div",co({},e,{ref:Ope([n,t])}))});function sme(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 ome=`.transform-component-module_wrapper__SPB86 {
593
593
  position: relative;
@@ -726,7 +726,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
726
726
  `:"\r":e.key==="Backspace"?"":e.key==="Tab"?e.shiftKey?"\x1B[Z":" ":e.key==="Escape"?"\x1B":e.key==="ArrowUp"?up("\x1B[A",t):e.key==="ArrowDown"?up("\x1B[B",t):e.key==="ArrowRight"?up("\x1B[C",t):e.key==="ArrowLeft"?up("\x1B[D",t):e.key==="Delete"?"\x1B[3~":e.key==="Home"?"\x1B[H":e.key==="End"?"\x1B[F":null}function FSe(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,selectionHandleLayerRef:o,mobileControlsHeight:l}=e,u=D0e(),d=u.markDisconnected,f=F0e(),p=TSe(),{openImagePreview:v}=Mk(),g=b.useRef(null),_=b.useRef(null),w=b.useRef(null),S=b.useRef(!1),x=b.useRef([]),R=b.useRef(null),k=b.useRef(null),N=b.useRef(n),M=b.useRef(n),T=b.useRef(!1),P=b.useRef(!1),z=b.useRef(!1),V=b.useRef(!1),U=b.useRef(null),G=b.useRef(null),O=b.useRef(null),A=b.useRef(null),L=b.useRef({keyboardOpen:!1,controlsVisible:!1}),D=b.useRef(!1),I=b.useRef(!1),B=b.useRef(!1),F=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[Y,j]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[q,K]=b.useState(!1),[$,ne]=b.useState(!1),[J,te]=b.useState({resultIndex:-1,resultCount:0}),Q=Te(Oe=>Oe.connected),ce=Te(Oe=>Oe.proxyOnline),ie=Te(Oe=>Oe.ptyFontSize),le=Te(Oe=>Oe.inputModePreference),be=Te(Oe=>Oe.adaptiveInputModality),Le=Te(Oe=>Oe.setAdaptiveInputModality),he=be==="hardware",He=mo("(pointer: coarse), (hover: none)"),{bottomOffset:Pt,layoutBottomInset:Ge}=sT(),it=le==="hardware",$e=LSe({touchEditingSurface:He,inputModePreference:le,detectedPhysicalKeyboard:he,softKeyboardDetected:Pt>0}),We=He&&!$e,vt=$e?0:Pt,mt=vt>0,st=$e?0:Ge,[Ae,_e]=b.useState(()=>Q&&ce);D.current=$e,N.current=n,T.current=u.ready,P.current=Q&&ce;const Qe=b.useCallback(()=>N.current&&T.current&&P.current,[]),ve=b.useCallback(()=>{const Oe=Gt.getState().sessions.find(Ne=>Ne.sessionId===t);if((Oe==null?void 0:Oe.mode)!=="pty"||Oe.ptyOwner!=="proxy-hosted")return;const Ze=g.current,tt=s.current,Tt=Ft;if(!Qe()||!Ze||!tt||!r||!Tt){qe.error("终端尚未就绪");return}const Nt=nwe(r,tt,Ze);if(!Nt){qe.error("无法获取终端显示区域的尺寸");return}Nt.cols===Ze.cols&&Nt.rows===Ze.rows||Tt.sendControl({type:"terminal_resize_request",sessionId:t,...Nt})||qe.error("终端尺寸调整失败,请检查连接")},[Qe,r,t,s]);b.useEffect(()=>{Q&&ce&&_e(!0)},[Q,ce]),b.useEffect(()=>{vt>0&&K(!0)},[vt]);const Fe=j0e({containerEl:r,xtermHostRef:s,terminalRef:g}),{ptyInputFocused:ot,suppressPtyFocus:yt,focusPtyInput:Et,handleFocusCapture:sn,handleBlurCapture:Xt}=Fe,on=ISe({softKeyboardEditingSurface:We,ptyInputFocused:ot,keyboardOpen:mt});F.current={keyboardOffset:vt,hasSeenSoftKeyboard:q,showMobilePtyControls:on,touchEditingSurface:He,ptyInputFocused:ot,containerPaddingBottom:F.current.containerPaddingBottom,mobileControlsBottomInset:st};const gn=f.clearNewFramesWhileAway;G.current||(G.current=cL(()=>{var Oe;(Oe=k.current)==null||Oe.relayout()}));const _n=b.useCallback(()=>{B.current=!1},[]);O.current||(O.current=cL(()=>{var Ze,tt;const Oe=A.current??{reason:"rawInput",force:!1};A.current=null,Oe.force&&_n(),(Ze=k.current)==null||Ze.traceRawInputFollowFire(),(tt=k.current)==null||tt.scrollToBottom(Oe.reason,Oe.force?{force:!0}:void 0),gn()}));const Ct=b.useCallback(()=>{if(B.current)return;const Oe=k.current;Oe&&Oe.preparePageResumeRestore(),B.current=!0},[]),tn=b.useCallback(()=>{if(!B.current||document.visibilityState==="hidden"||!N.current||!T.current)return;const Oe=k.current;Oe&&(Oe.restorePageResume(),gn(),B.current=!1)},[gn]);b.useEffect(()=>()=>{var Oe,Ze;(Oe=G.current)==null||Oe.dispose(),(Ze=O.current)==null||Ze.dispose(),G.current=null,O.current=null},[]),b.useEffect(()=>{const Oe=()=>{Ct()},Ze=()=>{if(document.visibilityState==="hidden"){Oe();return}tn()};return document.addEventListener("visibilitychange",Ze),window.addEventListener("pagehide",Oe),window.addEventListener("pageshow",tn),window.addEventListener("focus",tn),()=>{document.removeEventListener("visibilitychange",Ze),window.removeEventListener("pagehide",Oe),window.removeEventListener("pageshow",tn),window.removeEventListener("focus",tn)}},[Ct,tn]),b.useLayoutEffect(()=>{const Oe=M.current;if(M.current=n,!n){Oe&&Ct();return}(!Oe||B.current)&&u.ready&&tn()},[n,u.ready,Ct,tn]);const jt=b.useCallback((Oe="rawInput",Ze)=>{var Nt,Ne;const tt=A.current,Tt=(tt==null?void 0:tt.force)===!0||(Ze==null?void 0:Ze.force)===!0;A.current={reason:(Ze==null?void 0:Ze.force)===!0||!tt?Oe:tt.reason,force:Tt},(Nt=k.current)==null||Nt.traceRawInputFollowScheduled(Oe),(Ne=O.current)==null||Ne.schedule()},[]),cn=b.useCallback((Oe,Ze)=>{var tt;!Oe.includes("\r")&&!Oe.includes(`
727
727
  `)||(tt=k.current)==null||tt.resetHorizontalScroll(Ze,{holdUntilCursorVisible:!0})},[]),Mn=b.useCallback(()=>D.current?"submit":"linefeed",[]),Qn=b.useCallback(()=>D.current,[]);b.useEffect(()=>{if(!n||le!=="auto"||!He)return;const Oe=tt=>{const Tt=s.current,Nt=r;return tt instanceof Node?Tt!=null&&Tt.contains(tt)||tt===document.body||tt===document.documentElement?!0:Nt!=null&&Nt.contains(tt)?tt instanceof HTMLElement?tt.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:tt===window},Ze=tt=>{var Ne,_t;if(!DSe({active:N.current,touchEditingSurface:He,key:tt.key,code:tt.code,altKey:tt.altKey,ctrlKey:tt.ctrlKey,metaKey:tt.metaKey,isComposing:tt.isComposing,targetAcceptsPtyInput:Oe(tt.target)}))return;Le("hardware"),D.current=!0,(Ne=g.current)==null||Ne.focus();const Tt=s.current;if(tt.target instanceof Node&&(Tt!=null&&Tt.contains(tt.target)))return;const Nt=jSe(tt,(_t=g.current)==null?void 0:_t.modes);!Nt||!Qe()||(tt.preventDefault(),tt.stopPropagation(),$s(t,Nt),jt("physicalKeyboard"),cn(Nt,"physicalKeyboardEnter"))};return window.addEventListener("keydown",Ze,!0),()=>window.removeEventListener("keydown",Ze,!0)},[n,Qe,r,le,cn,jt,t,Le,He,s]);const qn=b.useCallback(Oe=>{const Ze=Ft;if(!Ze){qe.error("请先连接开发机");return}const tt=qe.loading(`下载 ${Oe} ...`);Nk({relay:Ze,sessionId:t,path:Oe}).then(Tt=>{Tt.ok?qe.success(`已开始下载 ${Oe}`,{id:tt}):qe.error(Tt.error,{id:tt})}).catch(Tt=>{qe.error(Tt instanceof Error?Tt.message:String(Tt),{id:tt})})},[t]),vn=b.useCallback(Oe=>{const Ze=g.current;return Ze?h0e(Ze,x.current,Oe):!1},[]),W=b.useCallback(Oe=>{const Ze=g.current;return Ze?f0e(Ze,x.current,Oe):!1},[]),re=kSe({terminalRef:g,xtermHostRef:s,selectionHandleLayerRef:o,scrollControllerRef:k,containerEl:r,keyboardOffset:vt,ptyFontSize:ie,suppressPtyFocus:yt,focusPtyInput:Et,onTap:vn,isTapCandidate:W,onDownloadPath:qn,onPreviewPath:v}),oe=re.clearManagedPtySelection,ue=re.clearPtySelection;I.current=re.hasPtySelection();const ye=b.useCallback(()=>{const Oe=g.current,Ze=w.current,tt=S.current&&Oe?ZO(Oe.getSelectionPosition(),Oe.cols):null;Ze==null||Ze.render(tt)},[]),Z=MSe({sessionId:t,terminalRef:g,onAfterPaste:()=>jt("paste")}),se=b.useCallback(Oe=>{if(!Qe()){Oe.preventDefault();return}Z(Oe)},[Qe,Z]),[fe,me]=b.useState(!1),X=b.useCallback(Oe=>{Oe.dataTransfer.types.includes("Files")&&(Oe.preventDefault(),me(Ze=>Ze||!0))},[]),ae=b.useCallback(Oe=>{Oe.currentTarget.contains(Oe.relatedTarget)||me(!1)},[]),de=b.useCallback(async Oe=>{var Nt;const Ze=(Nt=Oe.dataTransfer.files)==null?void 0:Nt[0];if(!Ze||(Oe.preventDefault(),me(!1),!Qe()))return;const tt=Ft;if(!tt){qe.error("请先连接开发机");return}const Tt=await Vp({relay:tt,sessionId:t,file:Ze});Tt&&($s(t,`@${Tt} `),jt("dropUpload"))},[Qe,jt,t]),De=b.useCallback(Oe=>{var tt;if(!Qe()){Oe.preventDefault();return}const Ze=Oe.target;Ze instanceof Element&&Ze.closest(".xterm")||(Oe.preventDefault(),(tt=g.current)==null||tt.focus())},[Qe]);b.useEffect(()=>{if(!Ae)return;const Oe=s.current,Ze=Fa,tt=Ft,Tt=r,Nt=i.current;if(!Oe||!Ze||!tt||!Tt||!Nt)return;let Ne=null,_t=null,Ot=null,Pe=null,ft=null,Dt=null,Zt=null,un=null;const ke=Txe({host:Oe,sessionId:t,ws:Ze,relay:tt,scheduleAutoFocus:We?()=>{}:Be=>{requestAnimationFrame(()=>{pL(s.current)&&Be()})},createTerminal:async Be=>{const at=await u6(Be,{fontSize:Te.getState().ptyFontSize});return un=at.serializeAddon,at},attachRawInput:(Be,at,Mt)=>Owe(Be,at,{...Mt,getPlainEnterBehavior:Mn,isPhysicalKeyboardMode:Qn,physicalKeyboardMode:it}),isInputEnabled:Qe,canFocus:Qe,onTerminalReady:Be=>{ue();const at=Be;g.current=at;const Mt=new kge({highlightLimit:1e3});at.loadAddon(Mt),_.current=Mt,ft=Mt.onDidChangeResults(Gn=>{te(Gn),ye()}),ne(!0);const wt=qxe(at,v);Ne=wt.dispose;const Pn=s0e(at,qn);_t=Pn.dispose,x.current=[wt.provider,Pn.provider],N0e(()=>g.current);const fr=rwe(at),lr=dwe(Oe,{serializeRangeAsHtml:(Gn,Zn)=>(un==null?void 0:un.serializeAsHTML({range:{startLine:Gn,endLine:Math.min(Zn,Math.max(0,at.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??"",getSerializedCell:(Gn,Zn)=>{var li;const Ai=(li=at.buffer.active.getLine(Gn))==null?void 0:li.getCell(Zn);return Ai?{text:Ai.getWidth()===0?"":Ai.getChars()||" ",isDim:!!Ai.isDim(),isRenderedFgRGB:Ai.isInverse()?Ai.isBgRGB():Ai.isFgRGB()}:null},getSelectionLine:Gn=>at.buffer.active.getLine(Gn)??null,getBufferRowIdentityOffset:fr.getOffset});Pe=()=>{lr.dispose(),fr.dispose()};const Ri=B.current;Ri&&(V.current=!1);const Kr=yxe({container:Tt,spacer:Nt,host:Oe,term:at,hasNewFrame:()=>z.current,consumeNewFrame:()=>{z.current=!1},hasNewFramesWhileAway:()=>f.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:f.setHasNewFramesWhileAway,onAtBottomChange:f.handleAtBottomChange,onScrollStateChange:j,initialUserHasVerticalScrollIntent:Ri?!1:V.current,onUserVerticalScrollIntentChange:Gn=>{V.current=Gn},onTouchReviewStart:yt,onHistoryProjectionChange:Gn=>{const Zn=lr.render(Gn);return Zn&&ye(),Zn},getBufferRowIdentityOffset:fr.getOffset});k.current=Kr,Ot=Kr.dispose,Zt=g6({terminal:at,container:Tt,getLine:Gn=>Hy(Oe,Gn)??at.buffer.active.getLine(Gn)??null,resolveRange:()=>S.current?ZO(at.getSelectionPosition(),at.cols):null,projectionOnly:!0,overlaySlot:"pty-search-selection-overlay",segmentSlot:"pty-search-selection-segment",selectionBackground:EE.activeMatchBackground,borderColor:EE.activeMatchBorder,opacity:"0.62"}),w.current=Zt,Dt=at.onSelectionChange(ye),ye(),Ri&&(Kr.restorePageResume(),gn(),B.current=!1),P0e(()=>{var Mr;const Gn=Jn=>{if(!Jn)return null;const ts=Jn.getBoundingClientRect();return{top:ts.top,bottom:ts.bottom,height:ts.height,left:ts.left,right:ts.right,width:ts.width}},Zn=document.querySelector('[data-slot="pty-mobile-controls"]'),Ai=document.querySelector("[data-keyboard-offset]"),li=window.visualViewport,an=Gn(Zn),Su=(li==null?void 0:li.height)??window.innerHeight;return{...O0e(Kr.getDebugProbe,{container:Tt,spacer:Nt,host:Oe,term:at}),mobileLayout:{...F.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:li?{height:li.height,width:li.width,offsetTop:li.offsetTop,pageTop:li.pageTop,scale:li.scale}:null,chatRoot:{dataKeyboardOffset:(Ai==null?void 0:Ai.getAttribute("data-keyboard-offset"))??null,rect:Gn(Ai)},ptyViewRect:Gn(Tt.parentElement),containerRect:Gn(Tt),controlsRect:an,controlsOverflowBelowVisualViewport:an===null?null:an.bottom-Su,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(Mr=document.activeElement.closest("[data-slot]"))==null?void 0:Mr.getAttribute("data-slot")}:null},frame:{lastWriteAt:U.current,pendingNewFrame:z.current}}})},onFramePending:()=>{var Be;z.current=!0,(Be=k.current)==null||Be.markHorizontalLiveFramePending(),V.current&&!f.hasNewFramesWhileAwayRef.current&&f.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Be;U.current=performance.now(),(Be=G.current)==null||Be.schedule()},onRawInput:Be=>{Lwe(Be)||(jt("rawInput",{force:!0}),cn(Be,"rawInputEnter"))},onError:Be=>{const at=Be instanceof Error?Be.message:String(Be);qe.error(`终端初始化失败:${at}`)},connectTransportInitially:Q&&ce,...u.transport});return R.current=ke,()=>{S.current=!1,Dt==null||Dt.dispose(),Zt==null||Zt.dispose(),w.current===Zt&&(w.current=null),ue(),Ot==null||Ot(),Pe==null||Pe(),ft==null||ft.dispose(),I0e(),Ne==null||Ne(),_t==null||_t(),x.current=[],M0e(),_.current=null,ne(!1),te({resultIndex:-1,resultCount:0}),ke.dispose(),g.current=null,k.current=null,R.current=null}},[t,Ae,r,i,s,u.transport,f.handleAtBottomChange,f.hasNewFramesWhileAwayRef,f.setHasNewFramesWhileAway,Qe,it,Mn,Qn,qn,v,yt,jt,cn,ue,ye]),b.useEffect(()=>{if(!Ae)return;const Oe=R.current;if(Oe){if(!Q||!ce){d(),Oe.setTransportActive(!1);return}return Axe(t,n?"active":"background",()=>{var Ze;(Ze=R.current)==null||Ze.setTransportActive(!0)})}},[n,Q,d,ce,t,Ae]),b.useEffect(()=>{const Oe=g.current,Ze=k.current;!Oe||!Ze||ewe(Oe,ie,Ze.relayout)},[ie]),b.useEffect(()=>{if(!n||!u.ready||We)return;const Oe=requestAnimationFrame(()=>{var Ze;pL(s.current)&&((Ze=g.current)==null||Ze.focus())});return()=>cancelAnimationFrame(Oe)},[n,u.ready,We,s]);const Ke=b.useCallback((Oe="viewExternal",Ze)=>{var tt;Ze!=null&&Ze.force&&_n(),(tt=k.current)==null||tt.scrollToBottom(Oe,Ze)},[_n]),lt=b.useCallback(Oe=>{var Ze;(Ze=k.current)==null||Ze.scrollToRatio(Oe)},[]),ct=b.useCallback(Oe=>{var Ze;(Ze=k.current)==null||Ze.scrollToXRatio(Oe)},[]),xt=b.useCallback(Oe=>{var _t;const Ze=g.current,tt=Ze==null?void 0:Ze.getSelectionPosition();if(!Ze||!tt)return;const Tt=tt.start.y;if(Tt>=Oe&&Tt<Oe+Ze.rows)return;const Nt=Math.max(0,Ze.buffer.active.length-Ze.rows);if(Nt===0)return;const Ne=Math.max(0,Math.min(Nt,Tt-Math.floor(Ze.rows/2)));(_t=k.current)==null||_t.scrollToRatio(Ne/Nt)},[]),kt=b.useCallback((Oe,Ze=!1)=>{const tt=g.current,Tt=_.current;if(!tt||!Tt||!Oe)return Oe||(S.current=!1,Tt==null||Tt.clearDecorations(),tt==null||tt.clearSelection(),oe(),ye(),te({resultIndex:-1,resultCount:0})),!1;oe(),S.current=!0;const Nt=tt.buffer.active.viewportY,Ne=Tt.findNext(Oe,{...SL,incremental:Ze});return Ne&&xt(Nt),ye(),Ne},[oe,ye,xt]),ut=b.useCallback(Oe=>{const Ze=g.current,tt=_.current;if(!Ze||!tt||!Oe)return!1;oe(),S.current=!0;const Tt=Ze.buffer.active.viewportY,Nt=tt.findPrevious(Oe,SL);return Nt&&xt(Tt),ye(),Nt},[oe,ye,xt]),Ht=b.useCallback(()=>{var Oe,Ze;S.current=!1,(Oe=_.current)==null||Oe.clearDecorations(),(Ze=g.current)==null||Ze.clearSelection(),oe(),ye(),te({resultIndex:-1,resultCount:0})},[oe,ye]),It=b.useCallback(Oe=>{var tt,Tt;if(!Qe())return;const Ze=up(Oe,(tt=g.current)==null?void 0:tt.modes);$s(t,Ze),jt("mobileControl",{force:!0}),cn(Oe,"mobileControlEnter"),(Tt=g.current)==null||Tt.focus()},[Qe,cn,jt,t]),mn=b.useCallback(()=>{var Ze,tt,Tt;if(!Qe())return;const Oe=(tt=(Ze=navigator.clipboard)==null?void 0:Ze.readText)==null?void 0:tt.bind(navigator.clipboard);if(!window.isSecureContext||!Oe){qe.error("无法读取剪贴板"),(Tt=g.current)==null||Tt.focus();return}Oe().then(Nt=>{if(!Nt)return;const Ne=g.current;if(Ne){Ne.paste(Nt);return}$s(t,Nt),jt("paste"),cn(Nt,"pasteEnter")}).catch(Nt=>{const Ne=Nt instanceof Error&&Nt.message?Nt.message:"无法读取剪贴板";qe.error(Ne)}).finally(()=>{var Nt;return(Nt=g.current)==null?void 0:Nt.focus()})},[Qe,cn,jt,t]),hn=zSe({showMobilePtyControls:on,horizontalScrollable:Y.horizontalScrollable,mobileControlsHeight:l});F.current.containerPaddingBottom=hn,b.useEffect(()=>{var tt,Tt;I.current?(tt=k.current)==null||tt.relayout():(Tt=G.current)==null||Tt.schedule();const Oe=L.current,Ze=OSe({controlsVisible:on,keyboardOpen:mt,previous:Oe});L.current={keyboardOpen:mt,controlsVisible:on},on&&(I.current?gn():Ze&&jt("keyboardOffset",{force:!0}))},[vt,mt,on,hn,gn,jt]);const yn=b.useMemo(()=>({onFocusCapture:sn,onBlurCapture:Xt}),[sn,Xt]);return{scrollState:Y,isAtBottom:f.isAtBottom,hasNewFramesWhileAway:f.hasNewFramesWhileAway,ptyInputFocused:ot,showMobilePtyControls:on,touchEditingSurface:He,keyboardOffset:vt,physicalKeyboardMode:$e,softKeyboardEditingSurface:We,mobileControlsBottomInset:st,connectionReady:u.ready,connectionOverlay:u.overlay,containerPaddingBottom:hn,traceEnabled:p,findReady:$,findResultIndex:J.resultIndex,findResultCount:J.resultCount,findNext:kt,findPrevious:ut,clearFind:Ht,fitToWindow:ve,scrollToBottom:Ke,scrollToRatio:lt,scrollToXRatio:ct,clearNewFramesWhileAway:gn,sendMobileInput:It,pasteMobileClipboard:mn,handleTerminalContainerMouseDown:De,handlePasteCapture:se,pointerHandlers:re.pointerHandlers,focusHandlers:yn,ptySelectionToolbar:re.ptySelectionToolbar,ptySelectionHandles:re.ptySelectionHandles,ptySelectionPathAction:re.ptySelectionPathAction,ptySelectionHandleMetrics:re.ptySelectionHandleMetrics,copyPtySelection:re.copyPtySelection,openPtySelectionPathAction:re.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:re.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:re.handlePtySelectionHandleTouchStart,isPtyDragOver:fe,handlePtyDragOver:X,handlePtyDragLeave:ae,handlePtyDrop:de}}function $Se({sessionId:e,sessionKind:t,provider:n,active:r=!0,findRequest:i,fitRequest:s}){const[o,l]=b.useState(null),[u,d]=b.useState(0),[f,p]=b.useState(!1),[v,g]=b.useState(""),_=b.useRef(null),w=b.useRef(null),S=b.useRef(null),x=FSe({sessionId:e,active:r,containerEl:o,spacerRef:_,xtermHostRef:w,selectionHandleLayerRef:S,mobileControlsHeight:u}),R=x.ptySelectionHandleMetrics,{clearFind:k,findNext:N,findPrevious:M,findReady:T,findResultCount:P,findResultIndex:z}=x,V=b.useRef(s),{fitToWindow:U}=x;b.useEffect(()=>{s===void 0||s===V.current||(V.current=s,r&&U())},[r,s,U]);const G=b.useCallback(()=>{M(v)},[M,v]),O=b.useCallback(()=>{N(v)},[N,v]),A=b.useCallback(()=>p(!0),[]),L=b.useCallback(()=>{p(!1),k()},[k]),D=FF({enabled:r,open:f,openRequest:i,onOpen:A,onClose:L,onPrevious:G,onNext:O});return b.useEffect(()=>{!f||!T||(v?N(v,!0):k())},[k,N,f,v,T]),m.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:[f?m.jsx(T1,{query:v,resultIndex:z,resultCount:P,focusRequest:D.focusRequest,loading:!!v&&!T,onQueryChange:g,onPrevious:G,onNext:O,onClose:D.closeFind}):null,m.jsxs("div",{ref:l,className:"relative 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:I=>{x.pointerHandlers.onPointerDownCapture(I)},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:[m.jsx("div",{ref:_,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:m.jsx("div",{ref:w,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})}),m.jsx("div",{ref:S,"data-slot":"pty-selection-handle-layer",style:{position:"absolute",left:0,top:0,width:0,height:0,contain:"layout size",overflow:"visible",pointerEvents:"none",zIndex:11}})]}),m.jsx(BF,{visible:!x.isAtBottom,hasNewMessages:x.hasNewFramesWhileAway,className:f?"top-14":"top-10",onClick:()=>{x.scrollToBottom("backToBottomBtn",{force:!0}),x.clearNewFramesWhileAway()}}),x.showMobilePtyControls?m.jsx(zme,{sessionKind:t,provider:n,bottomInset:x.mobileControlsBottomInset,onInput:x.sendMobileInput,onPaste:x.pasteMobileClipboard,onHeightChange:d}):null,x.ptySelectionHandles&&S.current?mu.createPortal(m.jsxs(m.Fragment,{children:[m.jsx(CL,{kind:"anchor",metrics:R,"aria-label":"调整选区起点",onPointerDown:I=>x.handlePtySelectionHandlePointerDown("anchor",I),onTouchStart:I=>x.handlePtySelectionHandleTouchStart("anchor",I)}),m.jsx(CL,{kind:"focus",metrics:R,"aria-label":"调整选区终点",onPointerDown:I=>x.handlePtySelectionHandlePointerDown("focus",I),onTouchStart:I=>x.handlePtySelectionHandleTouchStart("focus",I)})]}),S.current):null,x.ptySelectionToolbar?m.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:[m.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:I=>I.preventDefault(),onClick:x.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),x.ptySelectionPathAction?m.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:I=>I.preventDefault(),onClick:x.openPtySelectionPathAction,"aria-label":x.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:x.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,m.jsx(Vme,{state:x.scrollState,onScrollRatio:x.scrollToRatio}),m.jsx(Yme,{state:x.scrollState,onScrollRatio:x.scrollToXRatio}),m.jsx(Cme,{...x.connectionOverlay}),m.jsx(Tme,{ptyInputFocused:x.ptyInputFocused,touchEditingSurface:x.touchEditingSurface,softKeyboardEditingSurface:x.softKeyboardEditingSurface,physicalKeyboardMode:x.physicalKeyboardMode,keyboardOffset:x.keyboardOffset,showMobilePtyControls:x.showMobilePtyControls,mobileControlsBottomInset:x.mobileControlsBottomInset}),x.traceEnabled?m.jsx(HSe,{}):null]})}function CL({kind:e,metrics:t,"aria-label":n,onPointerDown:r,onTouchStart:i}){const s=t.touchSize/2,o=2,l=t.visualSize,u=Math.max(t.stemSize+2,l+1),d=s-o/2,f=s,p=e==="anchor"?d-l+o:d,v=f+u-l+o,g=e==="anchor"?{borderTopLeftRadius:l,borderBottomLeftRadius:l,borderTopRightRadius:2,borderBottomRightRadius:l}:{borderTopLeftRadius:2,borderBottomLeftRadius:l,borderTopRightRadius:l,borderBottomRightRadius:l};return m.jsxs("button",{type:"button",className:"absolute z-50 touch-none rounded-full bg-transparent p-0 pointer-events-auto focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",style:{left:0,top:0,width:t.touchSize,height:t.touchSize,transform:"translate3d(0, 0, 0) translate(-50%, -50%)",visibility:"hidden",willChange:"transform"},"data-slot":"pty-selection-handle","data-kind":e,"aria-label":n,onPointerDown:r,onTouchStart:i,children:[m.jsx("span",{className:"pointer-events-none absolute rounded-full bg-primary",style:{left:d,top:f,width:o,height:u},"data-slot":"pty-selection-handle-stem"}),m.jsx("span",{className:"pointer-events-none absolute border-2 border-primary bg-background shadow-sm shadow-black/30",style:{left:p,top:v,width:l,height:l,...g},"data-slot":"pty-selection-handle-dot"})]})}function HSe(){const[e,t]=b.useState(!1);async function n(){const r=Sme();try{await navigator.clipboard.writeText(r),t(!0),window.setTimeout(()=>t(!1),1200)}catch{window.prompt("Copy PTY scroll trace",r)}}return m.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 USe=1024,WSe=720,kv=.5,U6=b.createContext(null);function qSe({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Te(k=>k.selectedProxyId),u=Gt(k=>k.sessions),d=Gt(k=>k.sessionListLoaded),f=b.useRef(l),p=b.useRef(null),v=b.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
728
728
  `),[u]),g=b.useCallback(k=>{p.current=k.sessionId,i(k),n(N=>Yhe(N,k.sessionId).map(T=>T.sessionId===k.sessionId?{...T,sessionKind:k.sessionKind,provider:k.provider}:T))},[]),_=b.useCallback(k=>{p.current===k&&(p.current=null),i(N=>(N==null?void 0:N.sessionId)===k?null:N),o(N=>p.current===null?null:N)},[]),w=b.useCallback((k,N)=>{p.current===k&&o(M=>!N||M&&KSe(M,N)?M:N)},[]),S=b.useCallback((k,N)=>{N!==void 0&&n(M=>M.map(T=>T.sessionId===k?{...T,findRequest:N}:T))},[]),x=b.useCallback((k,N)=>{N===void 0||p.current!==k||n(M=>M.map(T=>T.sessionId===k?{...T,fitRequest:N}:T))},[]);b.useEffect(()=>{if(!d)return;const k=new Set(v?v.split(`
729
- `):[]);n(N=>N.filter(M=>k.has(M.sessionId))),i(N=>N&&k.has(N.sessionId)?N:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[v,d]),b.useEffect(()=>{const k=f.current;f.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const R=b.useMemo(()=>({activate:g,deactivate:_,updateFindRequest:S,updateFitRequest:x,updateViewportRect:w}),[g,_,S,x,w]);return m.jsxs(U6.Provider,{value:R,children:[e,m.jsx(YSe,{entries:t,activeView:r,viewportRect:s})]})}function VSe({sessionId:e,sessionKind:t,provider:n,findRequest:r,fitRequest:i}){const s=b.useContext(U6),o=b.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateFitRequest:f,updateViewportRect:p}=s;return b.useLayoutEffect(()=>(l({sessionId:e,sessionKind:t,provider:n}),()=>u(e)),[l,u,e,t,n]),b.useLayoutEffect(()=>{d(e,r)},[r,e,d]),b.useLayoutEffect(()=>{f(e,i)},[i,e,f]),b.useLayoutEffect(()=>{const v=o.current;if(!v)return;const g=()=>{const w=v.getBoundingClientRect();p(e,{top:w.top,left:w.left,width:w.width,height:w.height})};g();const _=new ResizeObserver(g);return _.observe(v),window.addEventListener("resize",g),()=>{_.disconnect(),window.removeEventListener("resize",g)}},[e,p]),m.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function YSe({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:m.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)??USe,height:(n==null?void 0:n.height)??WSe};return m.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:m.jsx(DF,{sessionId:r.sessionId,children:m.jsx($Se,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,fitRequest:r.fitRequest})})},r.sessionId)})})}function KSe(e,t){return Math.abs(e.top-t.top)<=kv&&Math.abs(e.left-t.left)<=kv&&Math.abs(e.width-t.width)<=kv&&Math.abs(e.height-t.height)<=kv}function GSe(){const e=Gt(r=>r.codexActiveWriterConflict),t=Gt(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(Zi,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Qi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"该 Codex 会话仍在运行"}),m.jsxs(Ss,{className:"space-y-2 text-left leading-6",children:[m.jsxs("span",{className:"block",children:["另一个 Codex 进程正在使用此会话",e!=null&&e.activeWriterPid?m.jsxs(m.Fragment,{children:["(PID"," ",m.jsx("span",{className:"font-mono text-foreground",children:e.activeWriterPid}),")"]}):null,"。"]}),m.jsx("span",{className:"block",children:"它可能来自本机终端、Codex App 或另一条 DEV Anywhere 会话。请先回到或结束原会话后再重试。"}),m.jsx("span",{className:"block text-muted-foreground/80",children:"DEV Anywhere 不会自动终止该进程。"})]})]}),m.jsx(Ws,{children:m.jsx(pt,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function lT({route:e,surface:t,proxiesLength:n,proxyListLoaded:r,hasProxy:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 需要 client token,请在设置中填写":s==="invalid_client_token"?"client token 无效或已过期,请在设置中更新":r?n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机":t==="mobile"&&e==="proxy-select"||!i?"选择要连接的开发机":null:null}function XSe(e){const t=Oj(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function uy(){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 ZSe(){return typeof navigator>"u"?{supported:!0}:XSe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:uy()})}function QSe(){E0e(),C0e();const e=cs(),t=Es(),n=e.pathname.startsWith("/chat/"),r=e.pathname.startsWith("/preview/device/"),i=n||r,s=e.pathname==="/"||e.pathname==="/sessions",[o,l]=b.useState(!1),[u,d]=b.useState(()=>uy()),f=Te(O=>O.proxies.length),p=Te(O=>O.proxyListLoaded),v=Te(O=>O.relayClientAuthIssue),g=Te(O=>O.relayConnectionIssue),_=Te(O=>!!O.selectedProxyId),w=Te(O=>O.selectedProxyId),S=Te(O=>O.selectedProxyName),x=Te(O=>{var A;return(A=O.proxies.find(L=>L.proxyId===O.selectedProxyId))==null?void 0:A.osName});Gt(O=>O.sessions.length);const R=Te(O=>O.pendingToast),k=Te(O=>O.setPendingToast),N=e.pathname==="/"?"proxy-select":"sessions",M=g!==null&&v===null,T=lT({route:N,surface:"mobile",proxiesLength:f,proxyListLoaded:p,hasProxy:_,relayClientAuthIssue:v}),P=S??w,V=e.pathname==="/sessions"&&p&&f>0?m.jsxs(pt,{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":P?`切换开发机,当前 ${P}`:"切换开发机",onClick:()=>t("/"),children:[m.jsx(az,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx(gp,{name:P??"切换开发机",osName:x,nameClassName:"text-foreground"})]}):null;b.useEffect(()=>{if(!R)return;({error:qe.error,info:qe.info,success:qe.success})[R.kind](R.message),k(null)},[R,k]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(uy());return}const O=window.matchMedia("(display-mode: standalone)"),A=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(uy());return L(),O.addEventListener("change",L),A.addEventListener("change",L),()=>{O.removeEventListener("change",L),A.removeEventListener("change",L)}},[]);const U=b.useRef(!1);b.useEffect(()=>{if(U.current)return;U.current=!0;const O=Kre({pathname:e.pathname,alreadyRestored:Zre(),lastRoute:Gre()});Qre(),O&&(Jre(O),t(O,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,Xre(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,Ey())},[n,e.pathname,e.search]),m.jsxs(Kue,{blocked:M,children:[m.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":u?"true":void 0,inert:M?!0:void 0,"aria-hidden":M?!0:void 0,children:[!i&&m.jsx(pt,{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:()=>l(!0),children:m.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:m.jsx(uz,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(Gfe,{subtitle:T,action:V}),m.jsx(Vhe,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(Vfe,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(qSe,{children:m.jsx("div",{className:Ye("h-full",!s&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),"data-slot":"route-content",children:m.jsx(t7,{})},s?"top-level":e.pathname)})})]}),m.jsx(E1,{open:o,onOpenChange:l}),m.jsx(GSe,{}),m.jsx(xhe,{}),m.jsx(ihe,{}),m.jsx(_re,{})]}),M&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(Che,{issue:g})}):null]})}function W6({subtitle:e,action:t}){return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[m.jsx(nF,{texts:rF,className:"text-2xl md:text-3xl font-bold"}),e?m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}):null,t&&m.jsx("div",{children:t})]})}function JSe(){const e=Te(o=>o.proxies),t=Te(o=>o.proxyListLoaded),n=Te(o=>!!o.selectedProxyId),r=Te(o=>o.relayClientAuthIssue);Gt(o=>o.sessions.length);const i=lT({route:"proxy-select",surface:"desktop",proxiesLength:e.length,proxyListLoaded:t,hasProxy:n,relayClientAuthIssue:r}),s=r==="missing_client_token"?"client-token-missing":r==="invalid_client_token"?"client-token-invalid":null;return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(O4,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(Yc,{variant:s}):m.jsx(W6,{subtitle:i})})]})}function e1e(){const e=Te(o=>o.proxies),t=Te(o=>o.proxyListLoaded),n=Te(o=>!!o.selectedProxyId),r=Te(o=>o.relayClientAuthIssue);Gt(o=>o.sessions.length);const i=Ci("local",Sn.proxyId)!==null;if(!n&&!i)return m.jsx(e7,{to:"/",replace:!0});const s=lT({route:"sessions",surface:"desktop",proxiesLength:e.length,proxyListLoaded:t,hasProxy:n,relayClientAuthIssue:r});return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(Y4,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(W6,{subtitle:s})})]})}function q6(){if(!(typeof navigator>"u"))return navigator.wakeLock}function t1e(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function V6(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return t1e(e,typeof((t=q6())==null?void 0:t.request)=="function")}function n1e(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function r1e(){const e=q6();if(typeof(e==null?void 0:e.request)!="function")throw new Error(n1e(V6()));return e.request("screen")}function i1e(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class s1e{constructor(t={}){je(this,"activeScopes",new Set);je(this,"pendingScopes",new Set);je(this,"listeners",new Map);je(this,"sentinel",null);je(this,"requestInFlight",null);je(this,"requestWakeLock");je(this,"documentRef");je(this,"windowRef");je(this,"unavailableReason");je(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(()=>{})});je(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??r1e,this.unavailableReason=typeof t.request=="function"?null:V6(),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(i1e(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 Ll=new s1e;function Y6(e){const[t,n]=b.useState(()=>Ll.getSnapshot(e));b.useEffect(()=>Ll.subscribe(e,n),[e]),b.useEffect(()=>()=>{Ll.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Ll.enable(e),[e]),i=b.useCallback(()=>Ll.disable(e),[e]),s=b.useCallback(()=>Ll.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function o1e(){return new AudioContext}class a1e{constructor(t=o1e){je(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 dy=new a1e,kL=400,Pd=[];let K6=1;function l1e(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function fp(e){const t={sequence:K6++,timestamp:new Date().toISOString(),monotonicMs:l1e(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Pd.push(t),Pd.length>kL&&Pd.splice(0,Pd.length-kL)}function c1e(){return Pd.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function u1e(){Pd.length=0,K6=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:c1e,clear:u1e});function G6(e){return`voice-pilot:${e}`}function d1e(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 f1e="modulepreload",h1e=function(e){return"/"+e},TL={},X6=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(f=>Promise.resolve(f).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=h1e(d),d in TL)return;TL[d]=!0;const f=d.endsWith(".css"),p=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const v=document.createElement("link");if(v.rel=f?"stylesheet":f1e,f||(v.as="script"),v.crossOrigin="",v.href=d,u&&v.setAttribute("nonce",u),document.head.appendChild(v),f)return new Promise((g,_)=>{v.addEventListener("load",g),v.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},p1e="/assets/fvad-DYxbW2my.wasm",nf=16e3,m1e=20,Dl=nf*m1e/1e3,tS=Dl*Int16Array.BYTES_PER_ELEMENT;let RL=null;async function g1e(){return RL??(RL=X6(async()=>{const{default:e}=await import("./fvad-Bjz5ovPS.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?p1e:t}))),RL}class cT{constructor(t,n,r){je(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await g1e(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(tS);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,nf)!==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 cT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==tS)throw new Error(`语音活动检测帧必须为 ${tS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Dl);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 v1e{constructor(t={}){je(this,"startSpeechFrames");je(this,"endSilenceFrames");je(this,"active",!1);je(this,"speechFrames",0);je(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 y1e{constructor(){je(this,"pending",new Float32Array(Dl));je(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Dl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Dl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Dl<=t.length;)n(t.slice(r,r+Dl)),r+=Dl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const b1e="/__dev_anywhere_debug/voice-fixture",_1e=nf*Z4/1e3;function w1e(){return cT.create(3)}const x1e={createVad:w1e,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function S1e(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 E1e(e){for(const t of e.getTracks())t.stop()}function Z6(e){const t=e.createAudioContext({sampleRate:nf});if(t.sampleRate!==nf)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function C1e(e){const t=Z6(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:nf}})}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(),E1e(n),t.state!=="closed"&&await t.close()}}}async function k1e(e,t){const n=Z6(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 Q6(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:b1e}:{kind:"microphone"}}async function T1e(e,t=x1e){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await k1e(e.source.url,t):await C1e(t)}catch(f){throw n.destroy(),f}const i=new v1e,s=new y1e,o=r.context.createScriptProcessor(_1e,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),p=>{const v=d1e(p),g=n.process(v);e.onFrame({pcm:v,speechProbability:g?1:0,activityLevel:S1e(p)});const _=i.push(g);_==="speech-start"&&e.onSpeechStart(),_==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function J6(e=af().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function R1e(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function A1e({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=R1e(e);return m.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&m.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),m.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function N1e(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 M1e(){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(N1e(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Pa="min-h-9 gap-2.5",Tv="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",P1e=[{slot:"answer-next",icon:"⌥↑",label:"发送 Alt+↑",data:"\x1B[1;3A"},{slot:"main-prompt",icon:"⌥↓",label:"发送 Alt+↓",data:"\x1B[1;3B"},{slot:"skip",icon:"^]",label:"发送 Ctrl+]",data:""}];function Co({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function nS({label:e}){return m.jsxs(Co,{className:"relative",children:[m.jsx(oz,{className:"size-4","aria-hidden":"true"}),m.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 I1e({sessionId:e,mode:t,onFind:n,onFitTerminal:r}){const i=Vr(_e=>_e.homePath),s=J6(),o=Es(),l=Gt(_e=>_e.sessions.find(Qe=>Qe.sessionId===e)),u=Gt(_e=>_e.ptyTitles[e]),d=Te(_e=>_e.ptyFontSize),f=Te(_e=>_e.chatContentFontSize),p=Te(_e=>_e.selectedProxyId),v=Te(_e=>_e.connected),g=Te(_e=>_e.proxyOnline),_=Te(_e=>_e.adjustPtyFontSize),w=Te(_e=>_e.adjustChatContentFontSize),S=Te(_e=>_e.setChatContentFontSize),x=Te(_e=>_e.resetPtyFontSize),R=Te(_e=>_e.resetChatContentFontSize),k=Te(_e=>_e.inputModePreference==="hardware"),N=Gt(_e=>_e.renameSession),M=PC(p,e),T=(l==null?void 0:l.provider)!=="codex",P=Gt(_e=>T&&M?!!_e.ptyAutoYesBySessionKey[M]:!1),z=Gt(_e=>_e.setPtyAutoYes),U=mo("(pointer: coarse), (hover: none)")&&!k,G=t==="pty"||(l==null?void 0:l.mode)==="pty",O=b.useRef(null),A=b.useRef(null),L=b.useRef(!1),D=(l==null?void 0:l.kind)==="terminal",I=Y6(e),B=An(_e=>_e.bySessionId[e]??Zb),F=An(_e=>_e.enable),Y=An(_e=>_e.disable),j=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),q=FC(l,i),K=j&&(l==null?void 0:l.name)||q||G&&u||(l==null?void 0:l.name)||e.slice(0,8),$=!!(G&&!D&&u&&!j),ne=G?d:vC(f,U),J=!G&&U?Pz:Nz,te=G?x:R,[Q,ce]=b.useState(!1),[ie,le]=b.useState(!1),be=B.enabled,Le=I.active||be,he=I.pending||!I.supported||be;function He(_e){if(G){_(_e);return}if(U){S(ne+_e);return}w(_e)}function Pt(){I.toggle().catch(_e=>{qe.error(_e instanceof Error?_e.message:String(_e))})}async function Ge(_e){var ve;if(G||D){qe.info("Voice Pilot 目前适用于聊天会话。");return}if(_e!==!0){Y(e);return}const Qe=Ft;if(!Qe){qe.error("请先连接开发机");return}try{if(!((ve=(await Qe.requestVoiceConfig()).config)!=null&&ve.configured)){qe.info("请先在设置里配置 Voice Pilot。");return}ce(!0)}catch(Fe){qe.error(Fe instanceof Error?Fe.message:String(Fe))}}async function it(){var Fe;le(!0);let _e=null,Qe=!1;const ve=G6(e);try{fp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((Fe=navigator.userActivation)==null?void 0:Fe.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const ot=Ll.enable(ve).then(()=>{fp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Xt=>{throw fp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Xt instanceof Error?Xt.message:String(Xt)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Xt})});_e=bk.acquire("capture");const yt=dy.prepare(),sn=Q6().kind==="microphone"?M1e():Promise.resolve();await Promise.all([ot,yt,sn]),F(e),Qe=!0,ce(!1)}catch(ot){fp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:ot instanceof Error?ot.message:String(ot)}}),qe.error(ot instanceof Error?ot.message:String(ot))}finally{_e==null||_e.release(),Qe||await Ll.disable(ve).catch(()=>{}),le(!1)}}const $e=b.useRef(null),We=b.useRef(null),[vt,mt]=b.useState(!1);async function st(_e){var ot;const Qe=(ot=_e.target.files)==null?void 0:ot[0];if(_e.target.value="",!Qe)return;const ve=Ft;if(!ve){qe.error("请先连接开发机");return}const Fe=await Vp({relay:ve,sessionId:e,file:Qe});Fe&&$s(e,`@${Fe} `)}async function Ae(_e,Qe){const ve=Ft;if(!ve)throw new Error("请先连接开发机");const Fe=await ve.renameSession(_e,Qe);if(!Fe.success)throw new Error(Fe.error??"重命名失败");N(_e,Fe.name??Qe),qe.success("已重命名会话")}return m.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[m.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:m.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:[m.jsx("div",{className:"flex justify-start",children:m.jsx(pt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>o("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(sf,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(A1e,{title:K,isPtyTitle:$})}),m.jsxs(hf,{modal:!1,onOpenChange:_e=>{_e&&(L.current=!1)},children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{ref:O,variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",onPointerDownCapture:_e=>{if(_e.currentTarget.getAttribute("data-state")==="open")return;const Qe=document.activeElement,ve=Qe==null?void 0:Qe.closest('[data-slot="pty-keepalive-entry"]');A.current=G&&Qe instanceof HTMLTextAreaElement&&Qe.matches('[data-slot="pty-host"] .xterm-helper-textarea')&&(ve==null?void 0:ve.getAttribute("data-session-id"))===e&&ve.getAttribute("data-active")==="true"?Qe:null},onKeyDownCapture:_e=>{["Enter"," ","ArrowDown"].includes(_e.key)&&(A.current=null)},children:m.jsx(AV,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",onEscapeKeyDown:()=>{L.current=!0},onCloseAutoFocus:_e=>{const Qe=A.current,ve=L.current;A.current=null,L.current=!1;const Fe=Qe==null?void 0:Qe.closest('[data-slot="pty-keepalive-entry"]'),ot=document.activeElement;_e.defaultPrevented||!ve||!G||!(Qe!=null&&Qe.isConnected)||(Fe==null?void 0:Fe.getAttribute("data-session-id"))!==e||Fe.getAttribute("data-active")!=="true"||ot!==document.body&&ot!==document.documentElement&&ot!==O.current&&ot!==Qe&&!(ot!=null&&ot.closest('[data-slot="chat-overflow-menu"]'))||(_e.preventDefault(),Qe.focus({preventScroll:!0}))},children:[m.jsx(av,{className:Tv,children:"会话"}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(Co,{children:m.jsx(py,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-rename",onSelect:()=>mt(!0),children:[m.jsx(Co,{children:m.jsx(_Y,{"aria-hidden":"true"})}),"重命名"]}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="proxy-hosted"&&r&&m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-fit-terminal",disabled:!v||!g||l.state==="error",onSelect:r,children:[m.jsx(Co,{children:m.jsx(sY,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),m.jsxs(a0,{checked:Le,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:he,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Pt,children:[m.jsx(Co,{children:m.jsx(eY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:I.supported?be?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":I.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),G&&!D&&m.jsxs(a0,{checked:P,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!M||!T,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:_e=>{M&&T&&z(M,_e===!0)},children:[m.jsx(Co,{children:m.jsx(rK,{"aria-hidden":"true"})}),m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"block",children:"Always yes"}),!T&&m.jsx("span",{className:"block text-xs",children:"Codex 终端请手动确认审批"})]})]}),!G&&!D&&m.jsxs(a0,{checked:B.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:Ge,children:[m.jsx(Co,{children:m.jsx(lY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(zd,{}),G&&m.jsxs(m.Fragment,{children:[m.jsx(av,{className:Tv,children:"快捷键"}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>$s(e,""),children:[m.jsx(nS,{label:"^O"}),"发送 Ctrl+O"]}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-send-ctrl-r",disabled:!v||!g||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>$s(e,""),children:[m.jsx(nS,{label:"^R"}),"发送 Ctrl+R"]}),(l==null?void 0:l.kind)==="agent"&&l.mode==="pty"&&l.provider==="codex"&&P1e.map(_e=>m.jsxs(Lr,{className:Pa,"data-slot":`chat-menu-codex-question-${_e.slot}`,disabled:!v||!g||l.state==="error",onSelect:()=>$s(e,_e.data),children:[m.jsx(nS,{label:_e.icon}),_e.label]},_e.slot)),m.jsx(zd,{})]}),G&&!D?m.jsxs(m.Fragment,{children:[m.jsx(av,{className:Tv,children:"文件"}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-upload-image",onClick:()=>{var _e;return(_e=We.current)==null?void 0:_e.click()},children:[m.jsx(Co,{children:m.jsx(tm,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-upload-file",onClick:()=>{var _e;return(_e=$e.current)==null?void 0:_e.click()},children:[m.jsx(Co,{children:m.jsx(fz,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(zd,{})]}):null,m.jsx(av,{className:Tv,children:"字号"}),m.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:m.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:[m.jsx(Co,{children:m.jsx(YY,{"aria-hidden":"true"})}),m.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[m.jsx(pt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ne<=J,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:_e=>{_e.stopPropagation(),He(-1)},children:m.jsx(uY,{"aria-hidden":"true"})}),m.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:[ne,"px"]}),m.jsx(pt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ne>=Mz,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:_e=>{_e.stopPropagation(),He(1)},children:m.jsx(SY,{"aria-hidden":"true"})})]})]})}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-font-reset",onClick:te,children:[m.jsx(Co,{children:m.jsx(kY,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(np,{open:vt,sessionId:e,initialName:l==null?void 0:l.name,onOpenChange:mt,onRename:Ae}),m.jsx(Zi,{open:Q&&!B.enabled,onOpenChange:_e=>{ie||ce(_e)},children:m.jsxs(Qi,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"开启 Voice Pilot?"}),m.jsx(Ss,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"outline",disabled:ie,onClick:()=>ce(!1),children:"取消"}),m.jsx(pt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:ie,onClick:()=>{it()},children:ie?"正在开启...":"开启 Voice Pilot"})]})]})}),G?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:We,type:"file",accept:s.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:_e=>{st(_e)}}),m.jsx("input",{ref:$e,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:_e=>{st(_e)}})]}):null]})}function md(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let f;n.key&&((l=n.debug)!=null&&l.call(n))&&(f=Date.now());const p=e();if(!(p.length!==r.length||p.some((_,w)=>r[w]!==_)))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 _=Math.round((Date.now()-f)*100)/100,w=Math.round((Date.now()-g)*100)/100,S=w/16,x=(R,k)=>{for(R=String(R);R.length<k;)R=" "+R;return R};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
729
+ `):[]);n(N=>N.filter(M=>k.has(M.sessionId))),i(N=>N&&k.has(N.sessionId)?N:null),p.current&&!k.has(p.current)&&(p.current=null,o(null))},[v,d]),b.useEffect(()=>{const k=f.current;f.current=l,!(!k||k===l)&&(p.current=null,n([]),i(null),o(null))},[l]);const R=b.useMemo(()=>({activate:g,deactivate:_,updateFindRequest:S,updateFitRequest:x,updateViewportRect:w}),[g,_,S,x,w]);return m.jsxs(U6.Provider,{value:R,children:[e,m.jsx(YSe,{entries:t,activeView:r,viewportRect:s})]})}function VSe({sessionId:e,sessionKind:t,provider:n,findRequest:r,fitRequest:i}){const s=b.useContext(U6),o=b.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateFitRequest:f,updateViewportRect:p}=s;return b.useLayoutEffect(()=>(l({sessionId:e,sessionKind:t,provider:n}),()=>u(e)),[l,u,e,t,n]),b.useLayoutEffect(()=>{d(e,r)},[r,e,d]),b.useLayoutEffect(()=>{f(e,i)},[i,e,f]),b.useLayoutEffect(()=>{const v=o.current;if(!v)return;const g=()=>{const w=v.getBoundingClientRect();p(e,{top:w.top,left:w.left,width:w.width,height:w.height})};g();const _=new ResizeObserver(g);return _.observe(v),window.addEventListener("resize",g),()=>{_.disconnect(),window.removeEventListener("resize",g)}},[e,p]),m.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function YSe({entries:e,activeView:t,viewportRect:n}){return e.length===0?null:m.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)??USe,height:(n==null?void 0:n.height)??WSe};return m.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:m.jsx(DF,{sessionId:r.sessionId,children:m.jsx($Se,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,fitRequest:r.fitRequest})})},r.sessionId)})})}function KSe(e,t){return Math.abs(e.top-t.top)<=kv&&Math.abs(e.left-t.left)<=kv&&Math.abs(e.width-t.width)<=kv&&Math.abs(e.height-t.height)<=kv}function GSe(){const e=Gt(r=>r.codexActiveWriterConflict),t=Gt(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(Zi,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Qi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"该 Codex 会话仍在运行"}),m.jsxs(Ss,{className:"space-y-2 text-left leading-6",children:[m.jsxs("span",{className:"block",children:["另一个 Codex 进程正在使用此会话",e!=null&&e.activeWriterPid?m.jsxs(m.Fragment,{children:["(PID"," ",m.jsx("span",{className:"font-mono text-foreground",children:e.activeWriterPid}),")"]}):null,"。"]}),m.jsx("span",{className:"block",children:"它可能来自本机终端、Codex App 或另一条 DEV Anywhere 会话。请先回到或结束原会话后再重试。"}),m.jsx("span",{className:"block text-muted-foreground/80",children:"DEV Anywhere 不会自动终止该进程。"})]})]}),m.jsx(Ws,{children:m.jsx(pt,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function lT({route:e,surface:t,proxiesLength:n,proxyListLoaded:r,hasProxy:i,relayClientAuthIssue:s=null}){return s==="missing_client_token"?"Relay 需要 client token,请在设置中填写":s==="invalid_client_token"?"client token 无效或已过期,请在设置中更新":r?n===0?"在开发机上启动 DEV Anywhere,本页会显示可连接的开发机":t==="mobile"&&e==="proxy-select"||!i?"选择要连接的开发机":null:null}function XSe(e){const t=Oj(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function uy(){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 ZSe(){return typeof navigator>"u"?{supported:!0}:XSe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:uy()})}function QSe(){E0e(),C0e();const e=cs(),t=Es(),n=e.pathname.startsWith("/chat/"),r=e.pathname.startsWith("/preview/device/"),i=n||r,s=e.pathname==="/"||e.pathname==="/sessions",[o,l]=b.useState(!1),[u,d]=b.useState(()=>uy()),f=Te(O=>O.proxies.length),p=Te(O=>O.proxyListLoaded),v=Te(O=>O.relayClientAuthIssue),g=Te(O=>O.relayConnectionIssue),_=Te(O=>!!O.selectedProxyId),w=Te(O=>O.selectedProxyId),S=Te(O=>O.selectedProxyName),x=Te(O=>{var A;return(A=O.proxies.find(L=>L.proxyId===O.selectedProxyId))==null?void 0:A.osName});Gt(O=>O.sessions.length);const R=Te(O=>O.pendingToast),k=Te(O=>O.setPendingToast),N=e.pathname==="/"?"proxy-select":"sessions",M=g!==null&&v===null,T=lT({route:N,surface:"mobile",proxiesLength:f,proxyListLoaded:p,hasProxy:_,relayClientAuthIssue:v}),P=S??w,V=e.pathname==="/sessions"&&p&&f>0?m.jsxs(pt,{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":P?`切换开发机,当前 ${P}`:"切换开发机",onClick:()=>t("/"),children:[m.jsx(az,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx(gp,{name:P??"切换开发机",osName:x,nameClassName:"text-foreground"})]}):null;b.useEffect(()=>{if(!R)return;({error:qe.error,info:qe.info,success:qe.success})[R.kind](R.message),k(null)},[R,k]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(uy());return}const O=window.matchMedia("(display-mode: standalone)"),A=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(uy());return L(),O.addEventListener("change",L),A.addEventListener("change",L),()=>{O.removeEventListener("change",L),A.removeEventListener("change",L)}},[]);const U=b.useRef(!1);b.useEffect(()=>{if(U.current)return;U.current=!0;const O=Kre({pathname:e.pathname,alreadyRestored:Zre(),lastRoute:Gre()});Qre(),O&&(Jre(O),t(O,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,Xre(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,Ey())},[n,e.pathname,e.search]),m.jsxs(Kue,{blocked:M,children:[m.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":u?"true":void 0,inert:M?!0:void 0,"aria-hidden":M?!0:void 0,children:[!i&&m.jsx(pt,{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:()=>l(!0),children:m.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:m.jsx(uz,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(Gfe,{subtitle:T,action:V}),m.jsx(Vhe,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(Vfe,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(qSe,{children:m.jsx("div",{className:Ye("h-full",!s&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),"data-slot":"route-content",children:m.jsx(t7,{})},s?"top-level":e.pathname)})})]}),m.jsx(E1,{open:o,onOpenChange:l}),m.jsx(GSe,{}),m.jsx(xhe,{}),m.jsx(ihe,{}),m.jsx(_re,{})]}),M&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(Che,{issue:g})}):null]})}function W6({subtitle:e,action:t}){return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-6 px-6 text-center",children:[m.jsx(nF,{texts:rF,className:"text-2xl md:text-3xl font-bold"}),e?m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}):null,t&&m.jsx("div",{children:t})]})}function JSe(){const e=Te(o=>o.proxies),t=Te(o=>o.proxyListLoaded),n=Te(o=>!!o.selectedProxyId),r=Te(o=>o.relayClientAuthIssue);Gt(o=>o.sessions.length);const i=lT({route:"proxy-select",surface:"desktop",proxiesLength:e.length,proxyListLoaded:t,hasProxy:n,relayClientAuthIssue:r}),s=r==="missing_client_token"?"client-token-missing":r==="invalid_client_token"?"client-token-invalid":null;return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(O4,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(Yc,{variant:s}):m.jsx(W6,{subtitle:i})})]})}function e1e(){const e=Te(o=>o.proxies),t=Te(o=>o.proxyListLoaded),n=Te(o=>!!o.selectedProxyId),r=Te(o=>o.relayClientAuthIssue);Gt(o=>o.sessions.length);const i=Ci("local",Sn.proxyId)!==null;if(!n&&!i)return m.jsx(e7,{to:"/",replace:!0});const s=lT({route:"sessions",surface:"desktop",proxiesLength:e.length,proxyListLoaded:t,hasProxy:n,relayClientAuthIssue:r});return m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"h-full md:hidden",children:m.jsx(Y4,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(W6,{subtitle:s})})]})}function q6(){if(!(typeof navigator>"u"))return navigator.wakeLock}function t1e(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function V6(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return t1e(e,typeof((t=q6())==null?void 0:t.request)=="function")}function n1e(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function r1e(){const e=q6();if(typeof(e==null?void 0:e.request)!="function")throw new Error(n1e(V6()));return e.request("screen")}function i1e(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class s1e{constructor(t={}){je(this,"activeScopes",new Set);je(this,"pendingScopes",new Set);je(this,"listeners",new Map);je(this,"sentinel",null);je(this,"requestInFlight",null);je(this,"requestWakeLock");je(this,"documentRef");je(this,"windowRef");je(this,"unavailableReason");je(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(()=>{})});je(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??r1e,this.unavailableReason=typeof t.request=="function"?null:V6(),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(i1e(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 Ll=new s1e;function Y6(e){const[t,n]=b.useState(()=>Ll.getSnapshot(e));b.useEffect(()=>Ll.subscribe(e,n),[e]),b.useEffect(()=>()=>{Ll.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>Ll.enable(e),[e]),i=b.useCallback(()=>Ll.disable(e),[e]),s=b.useCallback(()=>Ll.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function o1e(){return new AudioContext}class a1e{constructor(t=o1e){je(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 dy=new a1e,kL=400,Pd=[];let K6=1;function l1e(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function fp(e){const t={sequence:K6++,timestamp:new Date().toISOString(),monotonicMs:l1e(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Pd.push(t),Pd.length>kL&&Pd.splice(0,Pd.length-kL)}function c1e(){return Pd.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function u1e(){Pd.length=0,K6=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:c1e,clear:u1e});function G6(e){return`voice-pilot:${e}`}function d1e(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 f1e="modulepreload",h1e=function(e){return"/"+e},TL={},X6=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(f=>Promise.resolve(f).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=h1e(d),d in TL)return;TL[d]=!0;const f=d.endsWith(".css"),p=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const v=document.createElement("link");if(v.rel=f?"stylesheet":f1e,f||(v.as="script"),v.crossOrigin="",v.href=d,u&&v.setAttribute("nonce",u),document.head.appendChild(v),f)return new Promise((g,_)=>{v.addEventListener("load",g),v.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},p1e="/assets/fvad-DYxbW2my.wasm",nf=16e3,m1e=20,Dl=nf*m1e/1e3,tS=Dl*Int16Array.BYTES_PER_ELEMENT;let RL=null;async function g1e(){return RL??(RL=X6(async()=>{const{default:e}=await import("./fvad-BeAS4xDh.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?p1e:t}))),RL}class cT{constructor(t,n,r){je(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await g1e(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(tS);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,nf)!==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 cT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==tS)throw new Error(`语音活动检测帧必须为 ${tS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Dl);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 v1e{constructor(t={}){je(this,"startSpeechFrames");je(this,"endSilenceFrames");je(this,"active",!1);je(this,"speechFrames",0);je(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 y1e{constructor(){je(this,"pending",new Float32Array(Dl));je(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Dl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Dl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Dl<=t.length;)n(t.slice(r,r+Dl)),r+=Dl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const b1e="/__dev_anywhere_debug/voice-fixture",_1e=nf*Z4/1e3;function w1e(){return cT.create(3)}const x1e={createVad:w1e,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function S1e(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 E1e(e){for(const t of e.getTracks())t.stop()}function Z6(e){const t=e.createAudioContext({sampleRate:nf});if(t.sampleRate!==nf)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function C1e(e){const t=Z6(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:nf}})}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(),E1e(n),t.state!=="closed"&&await t.close()}}}async function k1e(e,t){const n=Z6(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 Q6(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:b1e}:{kind:"microphone"}}async function T1e(e,t=x1e){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await k1e(e.source.url,t):await C1e(t)}catch(f){throw n.destroy(),f}const i=new v1e,s=new y1e,o=r.context.createScriptProcessor(_1e,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),p=>{const v=d1e(p),g=n.process(v);e.onFrame({pcm:v,speechProbability:g?1:0,activityLevel:S1e(p)});const _=i.push(g);_==="speech-start"&&e.onSpeechStart(),_==="speech-end"&&e.onSpeechEnd()})},r.input.connect(o),o.connect(r.context.destination),{source:e.source.kind,start(){return d?Promise.reject(new Error("语音采集已停止")):(u??(u=(async()=>{l=!0,await r.start()})()),u)},stop(){return d??(d=(async()=>{l=!1,o.onaudioprocess=null,o.disconnect(),i.reset(),s.reset(),n.reset(),n.destroy(),await r.stop()})()),d}}}function J6(e=af().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function R1e(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function A1e({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=R1e(e);return m.jsxs("span",{className:"inline-flex items-center justify-center max-w-full min-w-0 font-mono font-normal",children:[n&&m.jsx("span",{className:"inline-block w-[1.25ch] shrink-0 text-center","aria-hidden":"true",children:n}),m.jsx("span",{className:"truncate",children:n?` ${r}`:r})]})}function N1e(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 M1e(){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(N1e(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Pa="min-h-9 gap-2.5",Tv="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",P1e=[{slot:"answer-next",icon:"⌥↑",label:"发送 Alt+↑",data:"\x1B[1;3A"},{slot:"main-prompt",icon:"⌥↓",label:"发送 Alt+↓",data:"\x1B[1;3B"},{slot:"skip",icon:"^]",label:"发送 Ctrl+]",data:""}];function Co({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function nS({label:e}){return m.jsxs(Co,{className:"relative",children:[m.jsx(oz,{className:"size-4","aria-hidden":"true"}),m.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 I1e({sessionId:e,mode:t,onFind:n,onFitTerminal:r}){const i=Vr(_e=>_e.homePath),s=J6(),o=Es(),l=Gt(_e=>_e.sessions.find(Qe=>Qe.sessionId===e)),u=Gt(_e=>_e.ptyTitles[e]),d=Te(_e=>_e.ptyFontSize),f=Te(_e=>_e.chatContentFontSize),p=Te(_e=>_e.selectedProxyId),v=Te(_e=>_e.connected),g=Te(_e=>_e.proxyOnline),_=Te(_e=>_e.adjustPtyFontSize),w=Te(_e=>_e.adjustChatContentFontSize),S=Te(_e=>_e.setChatContentFontSize),x=Te(_e=>_e.resetPtyFontSize),R=Te(_e=>_e.resetChatContentFontSize),k=Te(_e=>_e.inputModePreference==="hardware"),N=Gt(_e=>_e.renameSession),M=PC(p,e),T=(l==null?void 0:l.provider)!=="codex",P=Gt(_e=>T&&M?!!_e.ptyAutoYesBySessionKey[M]:!1),z=Gt(_e=>_e.setPtyAutoYes),U=mo("(pointer: coarse), (hover: none)")&&!k,G=t==="pty"||(l==null?void 0:l.mode)==="pty",O=b.useRef(null),A=b.useRef(null),L=b.useRef(!1),D=(l==null?void 0:l.kind)==="terminal",I=Y6(e),B=An(_e=>_e.bySessionId[e]??Zb),F=An(_e=>_e.enable),Y=An(_e=>_e.disable),j=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),q=FC(l,i),K=j&&(l==null?void 0:l.name)||q||G&&u||(l==null?void 0:l.name)||e.slice(0,8),$=!!(G&&!D&&u&&!j),ne=G?d:vC(f,U),J=!G&&U?Pz:Nz,te=G?x:R,[Q,ce]=b.useState(!1),[ie,le]=b.useState(!1),be=B.enabled,Le=I.active||be,he=I.pending||!I.supported||be;function He(_e){if(G){_(_e);return}if(U){S(ne+_e);return}w(_e)}function Pt(){I.toggle().catch(_e=>{qe.error(_e instanceof Error?_e.message:String(_e))})}async function Ge(_e){var ve;if(G||D){qe.info("Voice Pilot 目前适用于聊天会话。");return}if(_e!==!0){Y(e);return}const Qe=Ft;if(!Qe){qe.error("请先连接开发机");return}try{if(!((ve=(await Qe.requestVoiceConfig()).config)!=null&&ve.configured)){qe.info("请先在设置里配置 Voice Pilot。");return}ce(!0)}catch(Fe){qe.error(Fe instanceof Error?Fe.message:String(Fe))}}async function it(){var Fe;le(!0);let _e=null,Qe=!1;const ve=G6(e);try{fp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((Fe=navigator.userActivation)==null?void 0:Fe.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const ot=Ll.enable(ve).then(()=>{fp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Xt=>{throw fp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Xt instanceof Error?Xt.message:String(Xt)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Xt})});_e=bk.acquire("capture");const yt=dy.prepare(),sn=Q6().kind==="microphone"?M1e():Promise.resolve();await Promise.all([ot,yt,sn]),F(e),Qe=!0,ce(!1)}catch(ot){fp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:ot instanceof Error?ot.message:String(ot)}}),qe.error(ot instanceof Error?ot.message:String(ot))}finally{_e==null||_e.release(),Qe||await Ll.disable(ve).catch(()=>{}),le(!1)}}const $e=b.useRef(null),We=b.useRef(null),[vt,mt]=b.useState(!1);async function st(_e){var ot;const Qe=(ot=_e.target.files)==null?void 0:ot[0];if(_e.target.value="",!Qe)return;const ve=Ft;if(!ve){qe.error("请先连接开发机");return}const Fe=await Vp({relay:ve,sessionId:e,file:Qe});Fe&&$s(e,`@${Fe} `)}async function Ae(_e,Qe){const ve=Ft;if(!ve)throw new Error("请先连接开发机");const Fe=await ve.renameSession(_e,Qe);if(!Fe.success)throw new Error(Fe.error??"重命名失败");N(_e,Fe.name??Qe),qe.success("已重命名会话")}return m.jsxs("div",{className:"border-b border-border bg-card pt-[env(safe-area-inset-top)] shrink-0","data-slot":"chat-header",children:[m.jsx("div",{className:"dev-chat-shell-rail-inset","data-slot":"chat-header-rail-inset",children:m.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:[m.jsx("div",{className:"flex justify-start",children:m.jsx(pt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>o("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(sf,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(A1e,{title:K,isPtyTitle:$})}),m.jsxs(hf,{modal:!1,onOpenChange:_e=>{_e&&(L.current=!1)},children:[m.jsx(pf,{asChild:!0,children:m.jsx(pt,{ref:O,variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",onPointerDownCapture:_e=>{if(_e.currentTarget.getAttribute("data-state")==="open")return;const Qe=document.activeElement,ve=Qe==null?void 0:Qe.closest('[data-slot="pty-keepalive-entry"]');A.current=G&&Qe instanceof HTMLTextAreaElement&&Qe.matches('[data-slot="pty-host"] .xterm-helper-textarea')&&(ve==null?void 0:ve.getAttribute("data-session-id"))===e&&ve.getAttribute("data-active")==="true"?Qe:null},onKeyDownCapture:_e=>{["Enter"," ","ArrowDown"].includes(_e.key)&&(A.current=null)},children:m.jsx(AV,{"aria-hidden":"true"})})}),m.jsxs(mf,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)]","data-slot":"chat-overflow-menu",onEscapeKeyDown:()=>{L.current=!0},onCloseAutoFocus:_e=>{const Qe=A.current,ve=L.current;A.current=null,L.current=!1;const Fe=Qe==null?void 0:Qe.closest('[data-slot="pty-keepalive-entry"]'),ot=document.activeElement;_e.defaultPrevented||!ve||!G||!(Qe!=null&&Qe.isConnected)||(Fe==null?void 0:Fe.getAttribute("data-session-id"))!==e||Fe.getAttribute("data-active")!=="true"||ot!==document.body&&ot!==document.documentElement&&ot!==O.current&&ot!==Qe&&!(ot!=null&&ot.closest('[data-slot="chat-overflow-menu"]'))||(_e.preventDefault(),Qe.focus({preventScroll:!0}))},children:[m.jsx(av,{className:Tv,children:"会话"}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(Co,{children:m.jsx(py,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-rename",onSelect:()=>mt(!0),children:[m.jsx(Co,{children:m.jsx(_Y,{"aria-hidden":"true"})}),"重命名"]}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="proxy-hosted"&&r&&m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-fit-terminal",disabled:!v||!g||l.state==="error",onSelect:r,children:[m.jsx(Co,{children:m.jsx(sY,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),m.jsxs(a0,{checked:Le,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:he,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Pt,children:[m.jsx(Co,{children:m.jsx(eY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:I.supported?be?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":I.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),G&&!D&&m.jsxs(a0,{checked:P,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!M||!T,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:_e=>{M&&T&&z(M,_e===!0)},children:[m.jsx(Co,{children:m.jsx(rK,{"aria-hidden":"true"})}),m.jsxs("span",{className:"min-w-0 flex-1",children:[m.jsx("span",{className:"block",children:"Always yes"}),!T&&m.jsx("span",{className:"block text-xs",children:"Codex 终端请手动确认审批"})]})]}),!G&&!D&&m.jsxs(a0,{checked:B.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:Ge,children:[m.jsx(Co,{children:m.jsx(lY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(zd,{}),G&&m.jsxs(m.Fragment,{children:[m.jsx(av,{className:Tv,children:"快捷键"}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-send-ctrl-o",onClick:()=>$s(e,""),children:[m.jsx(nS,{label:"^O"}),"发送 Ctrl+O"]}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-send-ctrl-r",disabled:!v||!g||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>$s(e,""),children:[m.jsx(nS,{label:"^R"}),"发送 Ctrl+R"]}),(l==null?void 0:l.kind)==="agent"&&l.mode==="pty"&&l.provider==="codex"&&P1e.map(_e=>m.jsxs(Lr,{className:Pa,"data-slot":`chat-menu-codex-question-${_e.slot}`,disabled:!v||!g||l.state==="error",onSelect:()=>$s(e,_e.data),children:[m.jsx(nS,{label:_e.icon}),_e.label]},_e.slot)),m.jsx(zd,{})]}),G&&!D?m.jsxs(m.Fragment,{children:[m.jsx(av,{className:Tv,children:"文件"}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-upload-image",onClick:()=>{var _e;return(_e=We.current)==null?void 0:_e.click()},children:[m.jsx(Co,{children:m.jsx(tm,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-upload-file",onClick:()=>{var _e;return(_e=$e.current)==null?void 0:_e.click()},children:[m.jsx(Co,{children:m.jsx(fz,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(zd,{})]}):null,m.jsx(av,{className:Tv,children:"字号"}),m.jsx("div",{className:"px-2 pb-1","data-slot":"chat-menu-font-control",children:m.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:[m.jsx(Co,{children:m.jsx(YY,{"aria-hidden":"true"})}),m.jsxs("div",{className:"col-start-2 inline-flex w-fit shrink-0 items-center gap-2","data-slot":"chat-menu-font-stepper",children:[m.jsx(pt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ne<=J,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:_e=>{_e.stopPropagation(),He(-1)},children:m.jsx(uY,{"aria-hidden":"true"})}),m.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:[ne,"px"]}),m.jsx(pt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ne>=Mz,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:_e=>{_e.stopPropagation(),He(1)},children:m.jsx(SY,{"aria-hidden":"true"})})]})]})}),m.jsxs(Lr,{className:Pa,"data-slot":"chat-menu-font-reset",onClick:te,children:[m.jsx(Co,{children:m.jsx(kY,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(np,{open:vt,sessionId:e,initialName:l==null?void 0:l.name,onOpenChange:mt,onRename:Ae}),m.jsx(Zi,{open:Q&&!B.enabled,onOpenChange:_e=>{ie||ce(_e)},children:m.jsxs(Qi,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ji,{children:[m.jsx(Fi,{children:"开启 Voice Pilot?"}),m.jsx(Ss,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Ws,{children:[m.jsx(pt,{type:"button",variant:"outline",disabled:ie,onClick:()=>ce(!1),children:"取消"}),m.jsx(pt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:ie,onClick:()=>{it()},children:ie?"正在开启...":"开启 Voice Pilot"})]})]})}),G?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:We,type:"file",accept:s.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:_e=>{st(_e)}}),m.jsx("input",{ref:$e,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:_e=>{st(_e)}})]}):null]})}function md(e,t,n){let r=n.initialDeps??[],i,s=!0;function o(){var l,u,d;let f;n.key&&((l=n.debug)!=null&&l.call(n))&&(f=Date.now());const p=e();if(!(p.length!==r.length||p.some((_,w)=>r[w]!==_)))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 _=Math.round((Date.now()-f)*100)/100,w=Math.round((Date.now()-g)*100)/100,S=w/16,x=(R,k)=>{for(R=String(R);R.length<k;)R=" "+R;return R};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
730
730
  font-size: .6rem;
731
731
  font-weight: bold;
732
732
  color: hsl(${Math.max(0,Math.min(120-120*S,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 AL(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const O1e=(e,t)=>Math.abs(e-t)<1.01,L1e=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},NL=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},D1e=e=>e,B1e=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},z1e=(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(NL(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(NL(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},ML={passive:!0},PL=typeof window>"u"?!0:"onscrollend"in window,j1e=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&PL?()=>{}:L1e(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=f=>()=>{const{horizontal:p,isRtl:v}=e.options;i=p?n.scrollLeft*(v&&-1||1):n.scrollTop,s(),t(i,f)},l=o(!0),u=o(!1);n.addEventListener("scroll",l,ML);const d=e.options.useScrollendEvent&&PL;return d&&n.addEventListener("scrollend",u,ML),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},F1e=(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"]},$1e=(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 H1e{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:D1e,rangeExtractor:B1e,onChange:()=>{},measureElement:F1e,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=md(()=>(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=md(()=>[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=md(()=>[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 f=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,f),v=new Array(l).fill(void 0);for(let g=0;g<f;g++){const _=p[g];_&&(v[_.lane]=g)}for(let g=f;g<n;g++){const _=s(g),w=this.laneAssignments.get(g);let S,x;const R=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){S=w;const T=v[S],P=T!==void 0?p[T]:void 0;x=P?P.end+this.options.gap:r+i}else{const T=this.options.lanes===1?p[g-1]:this.getFurthestMeasurement(p,g);x=T?T.end+this.options.gap:r+i,S=T?T.lane:g%this.options.lanes,this.options.lanes>1&&R&&this.laneAssignments.set(g,S)}const k=d.get(_),N=typeof k=="number"?k:this.options.estimateSize(g),M=x+N;p[g]={index:g,start:x,size:N,end:M,key:_,lane:S},v[S]=g}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=md(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?U1e({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=md(()=>{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=md(()=>[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 AL(r[eH(0,r.length-1,i=>AL(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&&O1e(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 eH=(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 U1e({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=eH(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(f=>f<n+t);){const f=e[l];u[f.lane]=f.end,l++}const d=Array(r).fill(n+t);for(;o>=0&&d.some(f=>f>=n);){const f=e[o];d[f.lane]=f.start,o--}o=Math.max(0,o-o%r),l=Math.min(i,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}const IL=typeof document<"u"?b.useLayoutEffect:b.useEffect;function W1e({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?mu.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new H1e(r));return i.setOptions(r),IL(()=>i._didMount(),[]),IL(()=>i._willUpdate()),i}function q1e(e){return W1e({observeElementRect:z1e,observeElementOffset:j1e,scrollToFn:$1e,...e})}function V1e(e){var n;const t=[];for(const r of e.matchAll(new RegExp("(?<!\\S)@(.+?)(?=\\s+@|\\s*$)","gu"))){const i=r[1]??"",s=r.index??-1;if(s<0||!i)continue;const o=tT(i)?"image":iT(i,{allowBare:!0})?"file":null;o&&t.push({kind:o,path:i,start:s,end:s+(((n=r[0])==null?void 0:n.length)??0)})}return t}function Y1e(e){const t=V1e(e),n=[];let r=e.trimEnd().length;for(let i=t.length-1;i>=0;i-=1){const s=t[i];if(s){if(!/^\s*$/u.test(e.slice(s.end,r))||e[s.start]!=="@")break;n.unshift({kind:s.kind,path:s.path}),r=s.start}}return n.length===0?{bodyText:e,attachments:[]}:{bodyText:e.slice(0,r).trimEnd(),attachments:n}}function K1e(e){return e.kind==="diff"}const G1e=12e4;function OL(e){return e?e.replace(/\r\n?/gu,`
@@ -851,4 +851,4 @@ fn main() {
851
851
  ---
852
852
 
853
853
  _End of sample._
854
- `;function BOe(){return m.jsx("div",{className:"min-h-dvh bg-background text-foreground p-6",children:m.jsxs("div",{className:"mx-auto max-w-[720px] space-y-6",children:[m.jsxs("header",{children:[m.jsx("h1",{className:"text-lg font-semibold",children:"Markdown 渲染走查"}),m.jsx("p",{className:"text-sm text-muted-foreground",children:"下方模拟 assistant 气泡容器 (max-w 约束), 验证所有 markdown 元素在气泡内的实际渲染。"})]}),m.jsx("article",{className:"flex justify-start",children:m.jsx("div",{className:"max-w-[80%] rounded-md bg-card text-foreground px-4 py-2 text-sm",children:m.jsx(WE,{text:DOe})})})]})})}function ZU(e){if([e.left,e.top,e.width,e.height,e.frameWidth,e.frameHeight].some(l=>!Number.isFinite(l))||e.width<=0||e.height<=0||e.frameWidth<=0||e.frameHeight<=0)return null;const n=Math.min(e.width/e.frameWidth,e.height/e.frameHeight),r=e.frameWidth*n,i=e.frameHeight*n,s=e.left+(e.width-r)/2,o=e.top+(e.height-i)/2;return{left:s,top:o,right:s+r,bottom:o+i,width:r,height:i}}function QU(e,t,n){return{x:Math.min(1,Math.max(0,(e-n.left)/n.width)),y:Math.min(1,Math.max(0,(t-n.top)/n.height))}}function zOe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=ZU(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:QU(e,t,r)}function jOe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=ZU(n);return r?QU(e,t,r):null}async function FOe(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class $Oe{constructor(t,n,r=FOe){je(this,"latest",null);je(this,"painting",!1);je(this,"disposed",!1);je(this,"generation",0);je(this,"lastSequence",-1);je(this,"sizeReportedGeneration",-1);this.canvas=t,this.onSize=n,this.decoder=r}enqueue(t,n){var r;this.disposed||t<=this.lastSequence||((r=this.latest)==null?void 0:r.generation)===this.generation&&t<=this.latest.sequence||(this.latest={generation:this.generation,sequence:t,jpeg:n.slice()},this.painting||this.paintLoop())}reset(t=!1){var n;this.disposed||(this.generation+=1,this.latest=null,this.lastSequence=-1,t&&((n=this.canvas.getContext("2d",{alpha:!1}))==null||n.clearRect(0,0,this.canvas.width,this.canvas.height)))}dispose(){this.disposed=!0,this.generation+=1,this.latest=null}async paintLoop(){var t;this.painting=!0;try{for(;!this.disposed&&this.latest;){const n=this.latest;this.latest=null;let r;try{r=await this.decoder(n.jpeg)}catch(i){!this.disposed&&n.generation===this.generation&&console.warn("Failed to decode device preview frame",i);continue}try{if(this.disposed||n.generation!==this.generation||n.sequence<=this.lastSequence)continue;const i=this.canvas.width!==r.width||this.canvas.height!==r.height;i&&(this.canvas.width=r.width,this.canvas.height=r.height),(i||this.sizeReportedGeneration!==n.generation)&&(this.sizeReportedGeneration=n.generation,this.onSize({width:r.width,height:r.height})),(t=this.canvas.getContext("2d",{alpha:!1}))==null||t.drawImage(r,0,0),this.lastSequence=n.sequence}finally{r.close()}}}finally{this.painting=!1,!this.disposed&&this.latest&&this.paintLoop()}}}const HOe=120,UOe=8*1024*1024,WOe=1e3/30,qOe=.15,VOe=100,YOe=.001;function KOe(e,t){if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n+=1)if(e[n]!==t[n])return!1;return!0}function jc(e,t){if(e instanceof Error)return e;if(typeof e=="string"&&e.length>0)return new Error(e);if(e&&typeof e=="object"){const n=e,r=[n.name,n.message,n.error].filter(i=>typeof i=="string"&&i.length>0).join(": ");if(r.length>0)return new Error(r)}return new Error(t)}function GOe(e){const t=e.error;if(!t)return new Error("H.264 video playback failed");const n=t.message||`media error ${t.code}`;return new Error(`H.264 video playback failed: ${n}`)}class XOe{constructor(t,n={}){je(this,"muxer",null);je(this,"initialSources");je(this,"initialVideoState");je(this,"configuration",null);je(this,"configurationApplied",!1);je(this,"muxerReady",!1);je(this,"awaitingKeyframe",!0);je(this,"pendingFrames",[]);je(this,"fedFramesAwaitingPlayback",[]);je(this,"bufferedPacketCount",0);je(this,"bufferedBytes",0);je(this,"maxBufferedPackets");je(this,"maxBufferedBytes");je(this,"lastObservedMediaTime",null);je(this,"resyncRequired",!1);je(this,"playPending",!1);je(this,"playRequested",!1);je(this,"started",!1);je(this,"destroyed",!1);je(this,"generation",0);je(this,"playbackDelayTimer",null);je(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});je(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});je(this,"handleVideoError",()=>{this.destroyed||this.reportError(GOe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=aB(n.maxBufferedPackets,HOe),this.maxBufferedBytes=aB(n.maxBufferedBytes,UOe),this.initialSources=new Set(t.querySelectorAll("source")),this.initialVideoState={autoplay:t.autoplay,disableRemotePlayback:t.disableRemotePlayback,muted:t.muted,playsInline:t.playsInline,src:t.getAttribute("src"),srcObject:t.srcObject},t.srcObject=null,t.muted=!0,t.autoplay=!0,t.playsInline=!0,t.disableRemotePlayback=!0,t.addEventListener("playing",this.handlePlaying),t.addEventListener("error",this.handleVideoError),t.addEventListener("timeupdate",this.handleTimeUpdate);const r={node:t,mode:"video",flushingTime:0,maxDelay:150,clearBuffer:!0,onReady:()=>this.handleMuxerReady(),onError:i=>this.handleMuxerError(i),onUnsupportedCodec:i=>{this.reportError(new Error(`Browser does not support the H.264 codec ${i}`))}};this.initializeMuxer(r)}feed(t){if(!(this.destroyed||t.data.byteLength===0)){if(this.observePlaybackProgress(),t.kind==="configuration"){this.feedConfiguration(t.data);return}this.feedFrame(t)}}destroy(){var n;if(this.destroyed)return;this.destroyed=!0,this.generation+=1,this.clearBufferedGeneration(),this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("error",this.handleVideoError),this.video.removeEventListener("timeupdate",this.handleTimeUpdate),this.stopPlaybackDelayChecks();const t=this.generatedObjectUrls();try{(n=this.muxer)==null||n.destroy()}catch{}this.muxer=null;try{this.video.pause()}catch{}this.removeGeneratedSources(),this.video.removeAttribute("src"),this.initialVideoState.src!==null&&this.video.setAttribute("src",this.initialVideoState.src),this.video.srcObject=this.initialVideoState.srcObject,this.video.autoplay=this.initialVideoState.autoplay,this.video.disableRemotePlayback=this.initialVideoState.disableRemotePlayback,this.video.muted=this.initialVideoState.muted,this.video.playsInline=this.initialVideoState.playsInline;for(const r of t)this.revokeObjectUrl(r);try{this.video.load()}catch{}}async initializeMuxer(t){try{const{default:n}=await X6(async()=>{const{default:r}=await import("./jmuxer.min-DIchSTQ7.js").then(i=>i.j);return{default:r}},__vite__mapDeps([0,1]));if(this.destroyed)return;this.muxer=new n(t)}catch(n){if(this.destroyed)return;this.reportError(jc(n,"Failed to initialize H.264 video playback")),this.destroy()}}feedConfiguration(t){if(this.configuration&&KOe(this.configuration,t))return;const n=this.configuration!==null&&this.configurationApplied;if(this.clearBufferedGeneration(),this.wouldOverflow(t.byteLength)){this.requireResync();return}if(this.configuration=t.slice(),this.addBufferedPacket(t.byteLength),this.awaitingKeyframe=!0,n){this.resetMuxer();return}this.applyConfigurationIfReady()}feedFrame(t){if(!this.configuration)return;if(this.awaitingKeyframe){if(!t.keyframe)return;this.awaitingKeyframe=!1,this.resyncRequired=!1}const n={data:t.data.slice(),durationMs:Number.isFinite(t.durationMs)&&t.durationMs>0?t.durationMs:WOe,keyframe:t.keyframe};if(n.keyframe&&this.clearPendingFrames(),this.wouldOverflow(n.data.byteLength)){this.requireResync();return}if(this.addBufferedPacket(n.data.byteLength),!this.muxerReady||!this.configurationApplied){this.pendingFrames.push(n);return}this.applyFrame(n)||this.removeBufferedPacket(n.data.byteLength)}resetMuxer(){var r;const t=this.generatedSources(),n=this.generatedObjectUrls();this.generation+=1,this.muxerReady=!1,this.configurationApplied=!1,this.awaitingKeyframe=!0,this.playPending=!1,this.playRequested=!1,this.stopPlaybackDelayChecks();try{(r=this.muxer)==null||r.reset()}catch(i){this.reportError(jc(i,"Failed to reset H.264 video playback"))}for(const i of t)i.remove();for(const i of n)this.revokeObjectUrl(i)}handleMuxerReady(){this.destroyed||(this.muxerReady=!0,this.startPlaybackDelayChecks(),this.applyConfigurationIfReady(),this.flushPendingFrames())}startPlaybackDelayChecks(){this.playbackDelayTimer===null&&(this.playbackDelayTimer=setInterval(()=>{this.catchUpToLiveEdge()},VOe))}stopPlaybackDelayChecks(){this.playbackDelayTimer!==null&&(clearInterval(this.playbackDelayTimer),this.playbackDelayTimer=null)}catchUpToLiveEdge(){if(this.destroyed||this.video.seeking)return;const t=this.video.buffered;if(t.length!==0)try{const n=t.end(t.length-1),r=this.video.currentTime;if(!Number.isFinite(n)||!Number.isFinite(r)||n-r<=qOe)return;this.video.currentTime=Math.max(0,n-YOe),this.observePlaybackProgress()}catch{}}applyConfigurationIfReady(){if(!(this.destroyed||!this.muxerReady||this.configurationApplied||!this.configuration||!this.muxer))try{this.muxer.feed({video:this.configuration,duration:0,isLastVideoFrameComplete:!0}),this.configurationApplied=!0,this.flushPendingFrames()}catch(t){this.reportError(jc(t,"Failed to apply H.264 decoder configuration"))}}applyFrame(t){if(this.destroyed||!this.muxer)return!1;try{return this.muxer.feed({video:t.data,duration:t.durationMs,isLastVideoFrameComplete:!0}),this.fedFramesAwaitingPlayback.push({byteLength:t.data.byteLength,remainingDurationMs:t.durationMs}),this.attemptPlayback(),!0}catch(n){return this.reportError(jc(n,"Failed to feed an H.264 video frame")),!1}}flushPendingFrames(){if(this.destroyed||!this.muxerReady||!this.configurationApplied||!this.muxer)return;this.observePlaybackProgress();const t=this.pendingFrames;this.pendingFrames=[];for(const n of t){if(this.destroyed)return;this.applyFrame(n)||this.removeBufferedPacket(n.data.byteLength)}}attemptPlayback(){if(this.destroyed||this.playPending||this.playRequested)return;this.playPending=!0,this.playRequested=!0;const t=this.generation;let n;try{n=this.video.play()}catch(r){this.playPending=!1,this.playRequested=!1,this.reportError(jc(r,"Browser blocked H.264 video playback"));return}n.then(()=>{this.destroyed||t!==this.generation||(this.playPending=!1,this.markStarted())},r=>{this.destroyed||t!==this.generation||(this.playPending=!1,this.playRequested=!1,this.reportError(jc(r,"Browser blocked H.264 video playback")))})}handleMuxerError(t){this.destroyed||(t.name==="InvalidStateError"&&(this.generation+=1,this.muxerReady=!1,this.configurationApplied=!1,this.awaitingKeyframe=!0,this.clearBufferedGeneration(),this.playPending=!1,this.playRequested=!1,this.stopPlaybackDelayChecks()),this.reportError(jc(t,"H.264 video buffer failed")))}markStarted(){var t,n;this.started||(this.started=!0,(n=(t=this.options).onStart)==null||n.call(t))}reportError(t){var n,r;this.destroyed||(r=(n=this.options).onError)==null||r.call(n,t)}observePlaybackProgress(){const t=this.video.currentTime;if(!Number.isFinite(t)||t<0)return;if(this.lastObservedMediaTime===null||t<this.lastObservedMediaTime){this.lastObservedMediaTime=t;return}let n=(t-this.lastObservedMediaTime)*1e3;if(this.lastObservedMediaTime=t,!(n<=0))for(;n>0;){const r=this.fedFramesAwaitingPlayback[0];if(!r)return;if(n+Number.EPSILON<r.remainingDurationMs){r.remainingDurationMs-=n;return}n-=r.remainingDurationMs,this.fedFramesAwaitingPlayback.shift(),this.removeBufferedPacket(r.byteLength)}}wouldOverflow(t){return this.bufferedPacketCount+1>this.maxBufferedPackets||this.bufferedBytes+t>this.maxBufferedBytes}addBufferedPacket(t){this.bufferedPacketCount+=1,this.bufferedBytes+=t}removeBufferedPacket(t){this.bufferedPacketCount=Math.max(0,this.bufferedPacketCount-1),this.bufferedBytes=Math.max(0,this.bufferedBytes-t)}clearPendingFrames(){for(const t of this.pendingFrames)this.removeBufferedPacket(t.data.byteLength);this.pendingFrames=[]}clearBufferedGeneration(){this.pendingFrames=[],this.fedFramesAwaitingPlayback=[],this.configuration=null,this.configurationApplied=!1,this.bufferedPacketCount=0,this.bufferedBytes=0,this.lastObservedMediaTime=null}requireResync(){var n,r;const t=!this.resyncRequired;this.resyncRequired=!0,this.clearBufferedGeneration(),this.awaitingKeyframe=!0,this.resetMuxer(),t&&!this.destroyed&&((r=(n=this.options).onResyncRequired)==null||r.call(n,new Error("H.264 playback buffer overflowed; reconnecting for a fresh keyframe")))}generatedSources(){return Array.from(this.video.querySelectorAll("source")).filter(t=>!this.initialSources.has(t))}removeGeneratedSources(){for(const t of this.generatedSources())t.remove()}generatedObjectUrls(){const t=new Set,n=this.video.getAttribute("src");n!==this.initialVideoState.src&&(n!=null&&n.startsWith("blob:"))&&t.add(n);for(const r of this.generatedSources()){const i=r.getAttribute("src");i!=null&&i.startsWith("blob:")&&t.add(i)}return[...t]}revokeObjectUrl(t){if(typeof URL.revokeObjectURL=="function")try{URL.revokeObjectURL(t)}catch{}}}function aB(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class ZOe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=Sh;){const s=new DataView(this.buffer.buffer,this.buffer.byteOffset+i,Sh),o=s.getUint32(0,!0),l=s.getUint32(4,!0);if(o===0||o>xy)throw this.buffer=new Uint8Array(0),new RangeError(`Invalid device preview frame length: ${o}`);const u=Sh+o;if(this.buffer.byteLength-i<u)break;r.push({sequence:l,jpeg:this.buffer.slice(i+Sh,i+u)}),i+=u}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Sh+xy)throw this.buffer=new Uint8Array(0),new RangeError("Device preview stream buffer exceeded its limit");return r}finish(){if(this.buffer.byteLength!==0)throw this.buffer=new Uint8Array(0),new Error("Device preview stream ended with a truncated frame")}}class QOe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=Xh;){const s=this.buffer.subarray(i),o=lne(s);if(!o)throw this.buffer=new Uint8Array(0),new RangeError("Invalid H.264 device preview packet header");const l=Xh+o.annexBLength;if(this.buffer.byteLength-i<l)break;r.push({sequence:o.packetSequence,kind:o.configuration?"configuration":"frame",keyframe:o.keyframe,durationMs:o.durationMs,data:this.buffer.slice(i+Xh,i+l)}),i+=l}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Xh+xy)throw this.buffer=new Uint8Array(0),new RangeError("H.264 device preview stream buffer exceeded its limit");return r}finish(){if(this.buffer.byteLength!==0)throw this.buffer=new Uint8Array(0),new Error("H.264 device preview stream ended with a truncated packet")}}function JOe(e){let t;try{t=new URL(e,globalThis.location.href)}catch{throw new Error("无效的模拟器画面地址")}if(t.origin!==globalThis.location.origin||t.username!==""||t.password!==""||!/^\/api\/device-preview-streams\/[A-Za-z0-9_-]{1,256}$/u.test(t.pathname)||t.search!==""||t.hash!=="")throw new Error("拒绝连接不受信任的模拟器画面地址")}function eLe(e){const t=Number(e.headers.get("X-Device-Width")),n=Number(e.headers.get("X-Device-Height"));return!Number.isSafeInteger(t)||t<=0||!Number.isSafeInteger(n)||n<=0?null:{width:t,height:n}}async function JU(e,t,n){JOe(e);const r=db(),i=await n(e,{method:"GET",cache:"no-store",credentials:"same-origin",...r?{headers:{Authorization:`Bearer ${r}`}}:{},signal:t});if(!i.ok||!i.body)throw new Error(`无法打开模拟器画面(${i.status})`);return i}async function tLe(e,t){const n=t.fetch??globalThis.fetch,r=await JU(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new ZOe,s=r.body.getReader();try{for(;;){const{done:o,value:l}=await s.read();if(o)break;const d=i.push(l).at(-1);d&&await t.onFrame(d)}i.finish()}finally{s.releaseLock()}}async function nLe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await JU(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=eLe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new QOe,o=r.body.getReader();try{for(;;){const{done:u,value:d}=await o.read();if(u)break;for(const f of s.push(d))await t.onPacket(f)}s.finish()}finally{o.releaseLock()}}const rLe=16,iLe=16;class sLe{constructor(t){je(this,"send");je(this,"onFailure");je(this,"now");je(this,"moveFlushMs");je(this,"maxInFlightMoves");je(this,"active",null);je(this,"inFlightMoves",0);je(this,"disposed",!1);je(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??rLe,this.maxInFlightMoves=t.maxInFlightMoves??iLe}begin(t,n){if(this.disposed||this.failed||this.active)return!1;const r={pointerId:t,lastPoint:n,lastMoveAt:Number.NEGATIVE_INFINITY,pendingMove:null,moveFlushTimer:null};return this.active=r,this.dispatch(this.input("down",n)),!0}move(t,n){const r=this.matchingActive(t);if(!r)return!1;r.lastPoint=n,r.pendingMove=n;const i=this.now(),s=this.moveFlushMs-(i-r.lastMoveAt);return s>0?(r.moveFlushTimer===null&&(r.moveFlushTimer=setTimeout(()=>{r.moveFlushTimer=null,!(this.active!==r||this.disposed||this.failed)&&(r.lastMoveAt=this.now(),this.flushLatestMove())},s)),!0):(this.clearMoveTimer(r),r.lastMoveAt=i,this.flushLatestMove(),!0)}end(t,n){const r=this.matchingActive(t);return r?(r.lastPoint=n,this.finish(r),this.dispatch(this.input("up",n)),!0):!1}cancel(t){const n=this.active;if(!n||t!==void 0&&n.pointerId!==t)return!1;const r=n.lastPoint;return this.finish(n),this.dispatch(this.input("up",r)),!0}dispose(){if(this.disposed)return;const t=this.active;if(t&&this.finish(t),this.disposed=!0,!(!t||this.failed))try{Promise.resolve(this.send(this.input("up",t.lastPoint))).catch(()=>{})}catch{}}matchingActive(t){var n;return this.disposed||this.failed||((n=this.active)==null?void 0:n.pointerId)!==t?null:this.active}finish(t){this.active===t&&(this.active=null),this.clearMoveTimer(t),t.pendingMove=null}clearMoveTimer(t){t.moveFlushTimer!==null&&clearTimeout(t.moveFlushTimer),t.moveFlushTimer=null}flushLatestMove(){const t=this.active;if(!t||this.disposed||this.failed||!t.pendingMove||t.moveFlushTimer!==null||this.inFlightMoves>=this.maxInFlightMoves)return;const n=t.pendingMove;t.pendingMove=null,this.inFlightMoves+=1,this.dispatch(this.input("move",n),()=>{this.inFlightMoves=Math.max(0,this.inFlightMoves-1),this.flushLatestMove()})}dispatch(t,n){let r;try{r=Promise.resolve(this.send(t))}catch(i){this.fail(i),n==null||n();return}r.then(()=>n==null?void 0:n(),i=>{this.fail(i),n==null||n()})}fail(t){if(this.disposed||this.failed)return;this.failed=!0;const n=this.active;n&&this.finish(n),this.onFailure(t)}input(t,n){return{kind:"touch",phase:t,x:n.x,y:n.y}}}const oLe=15e3,aLe=1e4,lLe={ios:40,android:28},cLe={ios:{width:390,height:844},android:{width:412,height:915}};function uLe(){const{id:e=""}=WB(),t=Es(),n=dr($e=>Hj($e).find(We=>We.previewId===e)),r=dr($e=>$e.listLoaded),i=dr($e=>{var We;return((We=$e.authoritative)==null?void 0:We.scope)??null}),s=Vo($e=>Ore($e,i,"device",e,"reconnect")),o=b.useRef(null),l=b.useRef(null),u=b.useRef(null),d=b.useRef(null),f=b.useRef(null),p=b.useRef(()=>{}),v=b.useRef(null),g=b.useRef(null),[_,w]=b.useState(0),[S,x]=b.useState("waiting"),[R,k]=b.useState(null),[N,M]=b.useState(null),[T,P]=b.useState(null),[z,V]=b.useState(""),[U,G]=b.useState(!1),[O,A]=b.useState(!1),[L,D]=b.useState(!1),I=n==null?void 0:n.previewId,B=n==null?void 0:n.state,F=n==null?void 0:n.platform,Y=b.useCallback(()=>{const $e=f.current;f.current=null,$e==null||$e.dispose()},[]);b.useEffect(()=>{if(F!=="ios"){d.current=null,P(null);return}const $e=o.current;if(!$e)return;const We=new $Oe($e,P);return We.reset(!0),P(null),d.current=We,()=>{We.dispose(),d.current=null}},[I,F]),b.useEffect(()=>{if(Y(),p.current=()=>{},v.current=null,g.current=null,M(null),A(!1),D(!1),!I||B!=="ready"){B==="disconnected"?(x("error"),k("模拟器已断开")):(x("waiting"),k(null));return}const $e=Ft,We=i;if(!$e||!We||!Rt.isActive($e,We)){x("error"),k("开发机连接已断开");return}let vt=!1,mt=null,st=null,Ae=null,_e=null,Qe=null,ve=0,Fe=!1;const ot=()=>{Qe=null,Ae==null||Ae.abort(),Ae=null,_e==null||_e.destroy(),_e=null,mt&&clearTimeout(mt),mt=null,st&&clearTimeout(st),st=null},yt=Ct=>{x("streaming"),st&&clearTimeout(st),st=setTimeout(()=>{st=null,!(vt||Ct.signal.aborted||Qe!==Ct.leaseId||!Rt.isActive($e,We))&&(ve=0)},aLe)},Et=()=>{if(vt||document.visibilityState==="hidden"||!Rt.isActive($e,We))return;const Ct=Math.min(5e3,500*2**ve);ve+=1,mt=setTimeout(()=>void sn(),Ct)},sn=async()=>{var tn;if(Y(),ot(),vt||document.visibilityState==="hidden"||!Rt.isActive($e,We))return;Fe=!1,(tn=d.current)==null||tn.reset(),P(null),x("connecting"),k(null),M(null);const Ct=new AbortController;Ae=Ct;try{const jt=await Rt.requestDevicePreviewStream(We,I,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:Ct.signal});if(vt||Ct.signal.aborted||!Rt.isActive($e,We)||!jt)return;if(!jt.success)throw new Error(jt.error);const cn=jt;if(Qe=cn.leaseId,M(cn),F==="android"){const Qn=l.current;if(!Qn)throw new Error("无法初始化 Android 模拟器播放器");let qn;const vn=new Promise((ue,ye)=>{qn=ye}),W=setTimeout(()=>{qn(new Error("Android 模拟器画面启动超时"))},oLe),re=ue=>{qn(ue instanceof Error?ue:new Error(String(ue)))},oe=new XOe(Qn,{onStart:()=>{clearTimeout(W),!(vt||cn.signal.aborted||!Rt.isActive($e,We))&&yt(cn)},onError:re,onResyncRequired:re});_e=oe;try{await Promise.race([nLe(cn.url,{signal:cn.signal,onSize:ue=>{!vt&&!cn.signal.aborted&&Rt.isActive($e,We)&&P(ue)},onPacket:ue=>{!vt&&!cn.signal.aborted&&Rt.isActive($e,We)&&oe.feed(ue)}}),vn])}finally{clearTimeout(W)}if(!vt&&!cn.signal.aborted&&Rt.isActive($e,We))throw new Error("模拟器画面已断开");return}let Mn=!1;if(await tLe(cn.url,{signal:cn.signal,onFrame:Qn=>{if(vt||cn.signal.aborted||!Rt.isActive($e,We))return;const qn=d.current;qn&&(qn.enqueue(Qn.sequence,Qn.jpeg),Mn||(Mn=!0,yt(cn)))}}),!vt&&!cn.signal.aborted&&Rt.isActive($e,We))throw new Error("模拟器画面已断开")}catch(jt){if(vt||Ct.signal.aborted||!Rt.isActive($e,We))return;Xt(jt,!1)}},Xt=(Ct,tn)=>{if(vt||Fe||!Rt.isActive($e,We))return;Fe=!0;const jt=Ct instanceof Error?Ct.message:"模拟器画面已断开";Y(),ot(),v.current=null,g.current=null,M(null),A(!1),D(!1),x("error"),k(jt),tn&&qe.error(jt),Et()},on=(Ct,tn,jt=!0)=>{Ct===Qe&&Xt(tn,jt)};p.current=on;const gn=$e.onMessage(Ct=>{if(Ct.type!=="device_preview_control_revoked_push"||!Qt(Ct.scope,We)||Ct.leaseId!==Qe||!Rt.isActive($e,We))return;if(g.current=null,D(!1),Ct.reason==="taken_over"){v.current=null,A(!1),Y(),M(jt=>(jt==null?void 0:jt.leaseId)===Ct.leaseId?{...jt,controlMode:"view_only"}:jt),qe.info("控制权已由其他页面接管");return}const tn=new Error(Ct.reason==="proxy_offline"?"开发机连接已断开":Ct.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");on(Ct.leaseId,tn,!1)}),_n=()=>{if(document.visibilityState==="hidden"){Y(),ot(),v.current=null,g.current=null,M(null),A(!1),D(!1),x("waiting");return}ve=0,sn()};return document.addEventListener("visibilitychange",_n),sn(),()=>{vt=!0,p.current===on&&(p.current=()=>{}),gn(),document.removeEventListener("visibilitychange",_n),Y(),ot()}},[Y,I,F,i,B,_]),b.useEffect(()=>{var $e;($e=f.current)==null||$e.cancel()},[T==null?void 0:T.height,T==null?void 0:T.width]);const j=(n==null?void 0:n.state)==="ready"&&(N==null?void 0:N.previewId)===n.previewId&&i&&Qt(N.scope,i)?N:null,q=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{Y();const $e=Ft,We=j;if(!$e||!We||!q)return;const vt=new sLe({send:async mt=>{const st=await Rt.sendDevicePreviewInput(We,mt);if(!st)throw new Error("模拟器控制连接已失效");if(!st.success)throw new Error(st.error)},onFailure:mt=>{f.current===vt&&p.current(We.leaseId,mt)}});return f.current=vt,()=>{f.current===vt&&(f.current=null),vt.dispose()}},[q,j,Y]);const K=T??cLe[(n==null?void 0:n.platform)==="android"?"android":"ios"],$=lLe[(n==null?void 0:n.platform)==="android"?"android":"ios"],ne=K.width/K.height,J=K.width>K.height?"landscape":"portrait",te=J==="landscape"?`, ${K.width}px`:"",Q={aspectRatio:`${K.width} / ${K.height}`,width:`max(1px, min(calc(100cqw - ${$}px), calc(${(ne*100).toFixed(6)}cqh - ${(ne*$).toFixed(6)}px)${te}))`};b.useEffect(()=>{q||G(!1)},[q]);const ce=b.useCallback(async($e,We=!0)=>{const vt=Ft,mt=j;if(!vt||!mt||!q)return!1;try{const st=await Rt.sendDevicePreviewInput(mt,$e);return!st||!Rt.isActive(vt,mt.scope)?!1:st.success?!0:(We&&qe.error(st.error),!1)}catch(st){return mt.signal.aborted||!Rt.isActive(vt,mt.scope)||We&&qe.error(st instanceof Error?st.message:"模拟器操作失败"),!1}},[q,j]);function ie($e,We){const vt=u.current;if(!vt||!T)return null;const mt=vt.getBoundingClientRect(),st={left:mt.left,top:mt.top,width:mt.width,height:mt.height,frameWidth:T.width,frameHeight:T.height};return We==="start"?zOe($e.clientX,$e.clientY,st):jOe($e.clientX,$e.clientY,st)}function le($e){var mt,st;if(!q||$e.button!==0)return;const We=ie($e,"start");if(!We)return;const vt=f.current;vt!=null&&vt.begin($e.pointerId,We)&&($e.preventDefault(),(st=(mt=$e.currentTarget).setPointerCapture)==null||st.call(mt,$e.pointerId))}function be($e){var vt;const We=ie($e,"captured");We&&(vt=f.current)!=null&&vt.move($e.pointerId,We)&&$e.preventDefault()}function Le($e){var vt;const We=ie($e,"captured");We&&((vt=f.current)!=null&&vt.end($e.pointerId,We))&&$e.preventDefault()}function he($e){var We;(We=f.current)==null||We.cancel($e.pointerId)}async function He(){const $e=Ft,We=j;if(!$e||!We||L||S!=="streaming")return;const vt=Symbol("device-preview-control-claim");g.current=vt,D(!0);try{const mt=await Rt.claimDevicePreviewControl(We);if(g.current!==vt||!mt||!Rt.isActive($e,We.scope))return;if(!mt.success){qe.error(mt.error);return}M(st=>(st==null?void 0:st.leaseId)===We.leaseId?{...st,controlMode:"controller"}:st)}catch(mt){if(g.current!==vt||We.signal.aborted||!Rt.isActive($e,We.scope))return;qe.error(mt instanceof Error?mt.message:"暂时无法取得控制权")}finally{g.current===vt&&(g.current=null,D(!1))}}async function Pt($e){$e.preventDefault();const We=z;if(!We||O)return;const vt=Symbol("device-preview-text-input");v.current=vt,A(!0);const mt=await ce({kind:"text",text:We});v.current===vt&&(mt&&(V(""),G(!1)),v.current=null,A(!1))}function Ge(){var $e;($e=f.current)==null||$e.cancel(),ce({kind:"orientation",orientation:T&&T.width>T.height?"portrait":"landscape_right"})}async function it(){if((n==null?void 0:n.state)!=="disconnected"){w(vt=>vt+1);return}const $e=Ft,We=Rt.getActiveScope();if(!$e||!We){qe.error("请先连接开发机");return}try{const vt=await Rt.reconnectDevicePreview(We,n.previewId);vt.success||qe.error(vt.error)}catch(vt){if(!Rt.isActive($e,We))return;qe.error(vt instanceof Error?vt.message:"无法重新连接模拟器预览")}}return n?m.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-slot":"device-preview-page","data-preview-id":n.previewId,"data-stream-status":S,"data-control-mode":n.interactive?(j==null?void 0:j.controlMode)??"none":"unavailable",children:[m.jsxs("header",{className:"flex min-h-14 shrink-0 items-center gap-2 border-b px-3 md:px-4",children:[m.jsx(pt,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(sf,{"aria-hidden":"true"})}),m.jsx(hC,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("p",{className:"truncate text-sm font-medium",children:n.name}),m.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[n.model," · ",n.platform==="ios"?"iOS":"Android"," ",n.osVersion]})]}),n.interactive&&S==="streaming"&&(j==null?void 0:j.controlMode)==="view_only"?m.jsx(pt,{size:"sm",variant:"outline",disabled:L,onClick:()=>void He(),"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:q?"可操控":S==="streaming"?"仅查看":"连接中"})]}),m.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-muted/30",children:m.jsxs("div",{className:Ye("grid h-full min-h-0 min-w-0 gap-3 p-3 md:gap-4 md:p-6",J==="portrait"?"grid-rows-[minmax(0,1fr)_auto] md:grid-cols-[minmax(0,1fr)_auto] md:grid-rows-1":"grid-rows-[minmax(0,1fr)_auto]"),"data-slot":"device-preview-stage","data-orientation":J,children:[m.jsxs("div",{className:"relative flex min-h-0 min-w-0 items-center justify-center overflow-hidden [container-type:size]","data-slot":"device-preview-viewport",children:[m.jsxs("div",{className:Ye("relative isolate shrink-0 transition-[width,aspect-ratio] duration-300 ease-out motion-reduce:transition-none [container-type:size]",n.platform==="ios"?"[--device-screen-radius:clamp(22px,14cqmin,56px)] [--ios-rail:clamp(10px,4cqmin,16px)]":"[--device-screen-radius:clamp(14px,6.5cqw,38px)]"),style:Q,"data-slot":"device-preview-device-shell","data-platform":n.platform,"data-orientation":J,children:[m.jsx(dLe,{platform:n.platform,orientation:J}),m.jsx("div",{ref:u,className:Ye("relative z-10 flex h-full w-full min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-[var(--device-screen-radius)] bg-black ring-1 ring-black",q&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":q?"true":"false",children:n.platform==="android"?m.jsx("video",{ref:l,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-video",muted:!0,autoPlay:!0,playsInline:!0,disableRemotePlayback:!0,onLoadedMetadata:$e=>{const We=$e.currentTarget;We.videoWidth>0&&We.videoHeight>0&&P({width:We.videoWidth,height:We.videoHeight})},onResize:$e=>{const We=$e.currentTarget;We.videoWidth>0&&We.videoHeight>0&&P({width:We.videoWidth,height:We.videoHeight})}}):m.jsx("canvas",{ref:o,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-canvas"})}),m.jsx("div",{className:Ye("absolute inset-0 z-20 select-none rounded-[var(--device-screen-radius)]",q?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:le,onPointerMove:be,onPointerUp:Le,onPointerCancel:he,onLostPointerCapture:he,onContextMenu:$e=>{q&&$e.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":q?"true":"false","aria-hidden":"true"})]}),S!=="streaming"?m.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background/55 p-6 backdrop-blur-[1px]","data-slot":"device-preview-stream-overlay","data-stream-status":S,children:m.jsx("div",{className:"grid max-w-sm justify-items-center gap-3 text-center",children:S==="error"?m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:R}),m.jsxs(pt,{variant:"outline",size:"sm",disabled:s,onClick:()=>void it(),"data-slot":"device-preview-retry",children:[s?m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(oi,{className:"size-5 animate-spin text-muted-foreground","aria-hidden":!0}),m.jsx("p",{className:"text-sm text-muted-foreground",children:"正在连接画面..."})]})})}):null]}),m.jsx("div",{className:"relative z-20 flex min-w-0 items-center justify-center pb-[max(0px,env(safe-area-inset-bottom))] md:pb-0","data-slot":"device-preview-control-dock","data-orientation":J,role:"group","aria-label":"模拟器控制",children:m.jsxs("div",{className:Ye("flex max-w-full items-center gap-1 rounded-full border border-border/70 bg-card/85 p-1.5 shadow-xl ring-1 ring-black/5 backdrop-blur-xl",J==="portrait"&&"md:flex-col"),children:[m.jsx(AS,{control:"home",label:"主屏幕",disabled:!q,icon:m.jsx(YV,{"aria-hidden":"true"}),tooltipSide:J==="portrait"?"left":"top",onClick:()=>void ce({kind:"button",button:"home"})}),n.platform==="android"?m.jsx(AS,{control:"back",label:"返回",disabled:!q,icon:m.jsx(GY,{"aria-hidden":"true"}),tooltipSide:J==="portrait"?"left":"top",onClick:()=>void ce({kind:"button",button:"back"})}):null,m.jsx(AS,{control:"orientation",label:"旋转",disabled:!q||!T,icon:m.jsx(RY,{"aria-hidden":"true"}),tooltipSide:J==="portrait"?"left":"top",onClick:Ge}),m.jsx("span",{className:Ye("mx-0.5 h-6 w-px shrink-0 bg-border/80",J==="portrait"&&"md:mx-0 md:h-px md:w-6"),"aria-hidden":"true"}),m.jsxs(Ib,{open:U,onOpenChange:$e=>{(!$e||q)&&G($e)},children:[m.jsxs(gf,{children:[m.jsx(vf,{asChild:!0,children:m.jsx(Ob,{asChild:!0,children:m.jsx(pt,{type:"button",variant:"ghost",size:"icon",className:Ye("size-11 rounded-full text-muted-foreground hover:text-foreground",U&&"bg-accent text-foreground"),disabled:!q,"aria-label":"粘贴文字","aria-expanded":U,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(OS,{"aria-hidden":"true"})})})}),m.jsx(yf,{side:J==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(Lb,{side:J==="portrait"?"left":"top",align:"center",sideOffset:12,className:"w-[min(20rem,calc(100vw-1.5rem))] rounded-2xl bg-card/95 p-2 shadow-2xl backdrop-blur-xl",children:m.jsxs("form",{id:"device-preview-text-form",className:"flex items-end gap-2","data-slot":"device-preview-text-form",onSubmit:$e=>void Pt($e),children:[m.jsx("textarea",{value:z,onChange:$e=>V($e.target.value),disabled:!q||O,maxLength:4096,rows:3,placeholder:"粘贴文字","aria-label":"粘贴文字","data-slot":"device-preview-text-input",className:"min-h-20 min-w-0 flex-1 resize-none rounded-xl border bg-background px-3 py-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 md:text-sm"}),m.jsx(pt,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!q||!z||O,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:O?m.jsx(oi,{className:"animate-spin","aria-hidden":"true"}):m.jsx(OS,{"aria-hidden":"true"})})]})})]})]})})]})})]}):m.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center",children:r?m.jsxs("div",{className:"grid gap-3",children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:"无法找到该预览"}),m.jsx(pt,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(oi,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function AS({control:e,label:t,icon:n,disabled:r,tooltipSide:i,onClick:s}){return m.jsxs(gf,{children:[m.jsx(vf,{asChild:!0,children:m.jsx(pt,{type:"button",variant:"ghost",size:"icon",className:"size-11 rounded-full text-muted-foreground hover:text-foreground","aria-label":t,disabled:r,onClick:s,"data-slot":"device-preview-control","data-control":e,children:n})}),m.jsx(yf,{side:i,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:t})]})}function dLe({platform:e,orientation:t}){const n=t==="portrait";return e==="ios"?m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"ios","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[var(--ios-rail)] z-0 select-none rounded-[calc(var(--device-screen-radius)+var(--ios-rail))] border border-black/85 bg-[#202024] ring-1 ring-black/30","shadow-[inset_1px_1px_0_rgba(255,255,255,0.16),inset_-1px_-1px_0_rgba(0,0,0,0.72)]"),children:[m.jsx("span",{className:"absolute inset-[2px] rounded-[calc(var(--device-screen-radius)+var(--ios-rail)-2px)] ring-1 ring-inset ring-white/[0.05]"}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -left-[4px] top-[16%] h-[clamp(12px,4%,22px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[23%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[32%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -right-[4px] top-[28%] h-[clamp(36px,12%,64px)] w-[4px] rounded-r-[3px] border border-l-0 border-black/70 bg-[#343439] shadow-[inset_-1px_0_0_rgba(255,255,255,0.14)]"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[16%] h-[4px] w-[clamp(12px,4%,22px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[23%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[32%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -bottom-[4px] left-[28%] h-[4px] w-[clamp(36px,12%,64px)] rounded-b-[3px] border border-t-0 border-black/70 bg-[#343439] shadow-[inset_0_-1px_0_rgba(255,255,255,0.14)]"})]})]}):m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"android","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[9px] z-0 select-none rounded-[calc(var(--device-screen-radius)+9px)] border border-black/70 bg-[linear-gradient(145deg,#68717a_0%,#22272d_22%,#08090b_58%,#454c55_100%)] ring-1 ring-white/15"),children:[m.jsx("span",{className:Ye("absolute rounded-full bg-white/25 shadow-sm",n?"left-1/2 top-[3px] h-px w-[14%] -translate-x-1/2":"left-[3px] top-1/2 h-[14%] w-px -translate-y-1/2")}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -right-[4px] top-[20%] h-[14%] min-h-7 w-[3px] rounded-r-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -right-[4px] top-[38%] h-[9%] min-h-4 w-[3px] rounded-r-sm bg-slate-400 shadow-sm"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[20%] h-[3px] w-[14%] min-w-7 rounded-t-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -top-[4px] left-[38%] h-[3px] w-[9%] min-w-4 rounded-t-sm bg-slate-400 shadow-sm"})]})]})}const $d=T7([{path:"/",element:m.jsx(QSe,{}),children:[{index:!0,element:m.jsx(JSe,{})},{path:"sessions",element:m.jsx(e1e,{})},{path:"chat/:id",element:m.jsx(EOe,{})},{path:"preview/device/:id",element:m.jsx(uLe,{})}]},{path:"/pty-test",element:m.jsx(AOe,{})},{path:"/tokens",element:m.jsx(LOe,{})},{path:"/markdown-test",element:m.jsx(BOe,{})}]);function fLe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Pp(window.location.href,{allowUserGestureFallback:!0});n(i==="failed"?"failed":"copied")};return m.jsxs("div",{className:"flex min-h-[100dvh] flex-col overflow-hidden bg-background text-foreground","data-slot":"unsupported-ipad-browser",children:[m.jsx("header",{className:"mx-auto flex w-full max-w-5xl items-center px-6 py-5 sm:px-10",children:m.jsx(Az,{className:"text-sm",slot:"unsupported-browser-brand"})}),m.jsx("main",{className:"mx-auto flex w-full max-w-5xl flex-1 items-center px-6 pb-20 sm:px-10 sm:pb-24",children:m.jsxs("section",{className:"max-w-xl","aria-labelledby":"unsupported-browser-title",children:[m.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[m.jsx(xV,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx("span",{children:"iPad 浏览器支持"})]}),m.jsx("h1",{id:"unsupported-browser-title",className:"mt-4 text-3xl font-semibold tracking-normal sm:text-4xl",children:"请使用 Safari 打开"}),m.jsxs("p",{className:"mt-4 max-w-lg text-base leading-7 text-muted-foreground",children:["DEV Anywhere 暂不支持 iPad 上的 ",e,"。当前版本仅支持 Safari,以保证终端输入和实体键盘行为稳定。"]}),m.jsxs("div",{className:"mt-7 flex flex-wrap items-center gap-3",children:[m.jsxs(pt,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(ia,{className:"size-4","aria-hidden":"true"}):m.jsx(nz,{className:"size-4","aria-hidden":"true"}),t==="copied"?"链接已复制":"复制当前链接"]}),m.jsx("span",{className:"text-sm text-muted-foreground","aria-live":"polite",children:t==="copied"?"请切换到 Safari 后粘贴打开":t==="failed"?"复制失败,请从地址栏复制":"复制后在 Safari 中打开"})]})]})})]})}function hLe({children:e}){const t=ZSe();return t.supported?e:m.jsx(fLe,{browserName:t.browserName})}function pLe(){return m.jsx(hLe,{children:m.jsx(mLe,{})})}function mLe(){return dse(),m.jsx(lde,{delayDuration:200,children:m.jsx(Zq,{router:$d})})}function gLe(e=window.history){e.scrollRestoration="manual"}gLe();uG();Mhe();hW.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(pLe,{})}));export{X6 as _,Gp as a,yLe as g};
854
+ `;function BOe(){return m.jsx("div",{className:"min-h-dvh bg-background text-foreground p-6",children:m.jsxs("div",{className:"mx-auto max-w-[720px] space-y-6",children:[m.jsxs("header",{children:[m.jsx("h1",{className:"text-lg font-semibold",children:"Markdown 渲染走查"}),m.jsx("p",{className:"text-sm text-muted-foreground",children:"下方模拟 assistant 气泡容器 (max-w 约束), 验证所有 markdown 元素在气泡内的实际渲染。"})]}),m.jsx("article",{className:"flex justify-start",children:m.jsx("div",{className:"max-w-[80%] rounded-md bg-card text-foreground px-4 py-2 text-sm",children:m.jsx(WE,{text:DOe})})})]})})}function ZU(e){if([e.left,e.top,e.width,e.height,e.frameWidth,e.frameHeight].some(l=>!Number.isFinite(l))||e.width<=0||e.height<=0||e.frameWidth<=0||e.frameHeight<=0)return null;const n=Math.min(e.width/e.frameWidth,e.height/e.frameHeight),r=e.frameWidth*n,i=e.frameHeight*n,s=e.left+(e.width-r)/2,o=e.top+(e.height-i)/2;return{left:s,top:o,right:s+r,bottom:o+i,width:r,height:i}}function QU(e,t,n){return{x:Math.min(1,Math.max(0,(e-n.left)/n.width)),y:Math.min(1,Math.max(0,(t-n.top)/n.height))}}function zOe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=ZU(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:QU(e,t,r)}function jOe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=ZU(n);return r?QU(e,t,r):null}async function FOe(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class $Oe{constructor(t,n,r=FOe){je(this,"latest",null);je(this,"painting",!1);je(this,"disposed",!1);je(this,"generation",0);je(this,"lastSequence",-1);je(this,"sizeReportedGeneration",-1);this.canvas=t,this.onSize=n,this.decoder=r}enqueue(t,n){var r;this.disposed||t<=this.lastSequence||((r=this.latest)==null?void 0:r.generation)===this.generation&&t<=this.latest.sequence||(this.latest={generation:this.generation,sequence:t,jpeg:n.slice()},this.painting||this.paintLoop())}reset(t=!1){var n;this.disposed||(this.generation+=1,this.latest=null,this.lastSequence=-1,t&&((n=this.canvas.getContext("2d",{alpha:!1}))==null||n.clearRect(0,0,this.canvas.width,this.canvas.height)))}dispose(){this.disposed=!0,this.generation+=1,this.latest=null}async paintLoop(){var t;this.painting=!0;try{for(;!this.disposed&&this.latest;){const n=this.latest;this.latest=null;let r;try{r=await this.decoder(n.jpeg)}catch(i){!this.disposed&&n.generation===this.generation&&console.warn("Failed to decode device preview frame",i);continue}try{if(this.disposed||n.generation!==this.generation||n.sequence<=this.lastSequence)continue;const i=this.canvas.width!==r.width||this.canvas.height!==r.height;i&&(this.canvas.width=r.width,this.canvas.height=r.height),(i||this.sizeReportedGeneration!==n.generation)&&(this.sizeReportedGeneration=n.generation,this.onSize({width:r.width,height:r.height})),(t=this.canvas.getContext("2d",{alpha:!1}))==null||t.drawImage(r,0,0),this.lastSequence=n.sequence}finally{r.close()}}}finally{this.painting=!1,!this.disposed&&this.latest&&this.paintLoop()}}}const HOe=120,UOe=8*1024*1024,WOe=1e3/30,qOe=.15,VOe=100,YOe=.001;function KOe(e,t){if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n+=1)if(e[n]!==t[n])return!1;return!0}function jc(e,t){if(e instanceof Error)return e;if(typeof e=="string"&&e.length>0)return new Error(e);if(e&&typeof e=="object"){const n=e,r=[n.name,n.message,n.error].filter(i=>typeof i=="string"&&i.length>0).join(": ");if(r.length>0)return new Error(r)}return new Error(t)}function GOe(e){const t=e.error;if(!t)return new Error("H.264 video playback failed");const n=t.message||`media error ${t.code}`;return new Error(`H.264 video playback failed: ${n}`)}class XOe{constructor(t,n={}){je(this,"muxer",null);je(this,"initialSources");je(this,"initialVideoState");je(this,"configuration",null);je(this,"configurationApplied",!1);je(this,"muxerReady",!1);je(this,"awaitingKeyframe",!0);je(this,"pendingFrames",[]);je(this,"fedFramesAwaitingPlayback",[]);je(this,"bufferedPacketCount",0);je(this,"bufferedBytes",0);je(this,"maxBufferedPackets");je(this,"maxBufferedBytes");je(this,"lastObservedMediaTime",null);je(this,"resyncRequired",!1);je(this,"playPending",!1);je(this,"playRequested",!1);je(this,"started",!1);je(this,"destroyed",!1);je(this,"generation",0);je(this,"playbackDelayTimer",null);je(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});je(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});je(this,"handleVideoError",()=>{this.destroyed||this.reportError(GOe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=aB(n.maxBufferedPackets,HOe),this.maxBufferedBytes=aB(n.maxBufferedBytes,UOe),this.initialSources=new Set(t.querySelectorAll("source")),this.initialVideoState={autoplay:t.autoplay,disableRemotePlayback:t.disableRemotePlayback,muted:t.muted,playsInline:t.playsInline,src:t.getAttribute("src"),srcObject:t.srcObject},t.srcObject=null,t.muted=!0,t.autoplay=!0,t.playsInline=!0,t.disableRemotePlayback=!0,t.addEventListener("playing",this.handlePlaying),t.addEventListener("error",this.handleVideoError),t.addEventListener("timeupdate",this.handleTimeUpdate);const r={node:t,mode:"video",flushingTime:0,maxDelay:150,clearBuffer:!0,onReady:()=>this.handleMuxerReady(),onError:i=>this.handleMuxerError(i),onUnsupportedCodec:i=>{this.reportError(new Error(`Browser does not support the H.264 codec ${i}`))}};this.initializeMuxer(r)}feed(t){if(!(this.destroyed||t.data.byteLength===0)){if(this.observePlaybackProgress(),t.kind==="configuration"){this.feedConfiguration(t.data);return}this.feedFrame(t)}}destroy(){var n;if(this.destroyed)return;this.destroyed=!0,this.generation+=1,this.clearBufferedGeneration(),this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("error",this.handleVideoError),this.video.removeEventListener("timeupdate",this.handleTimeUpdate),this.stopPlaybackDelayChecks();const t=this.generatedObjectUrls();try{(n=this.muxer)==null||n.destroy()}catch{}this.muxer=null;try{this.video.pause()}catch{}this.removeGeneratedSources(),this.video.removeAttribute("src"),this.initialVideoState.src!==null&&this.video.setAttribute("src",this.initialVideoState.src),this.video.srcObject=this.initialVideoState.srcObject,this.video.autoplay=this.initialVideoState.autoplay,this.video.disableRemotePlayback=this.initialVideoState.disableRemotePlayback,this.video.muted=this.initialVideoState.muted,this.video.playsInline=this.initialVideoState.playsInline;for(const r of t)this.revokeObjectUrl(r);try{this.video.load()}catch{}}async initializeMuxer(t){try{const{default:n}=await X6(async()=>{const{default:r}=await import("./jmuxer.min-DhPlAXXG.js").then(i=>i.j);return{default:r}},__vite__mapDeps([0,1]));if(this.destroyed)return;this.muxer=new n(t)}catch(n){if(this.destroyed)return;this.reportError(jc(n,"Failed to initialize H.264 video playback")),this.destroy()}}feedConfiguration(t){if(this.configuration&&KOe(this.configuration,t))return;const n=this.configuration!==null&&this.configurationApplied;if(this.clearBufferedGeneration(),this.wouldOverflow(t.byteLength)){this.requireResync();return}if(this.configuration=t.slice(),this.addBufferedPacket(t.byteLength),this.awaitingKeyframe=!0,n){this.resetMuxer();return}this.applyConfigurationIfReady()}feedFrame(t){if(!this.configuration)return;if(this.awaitingKeyframe){if(!t.keyframe)return;this.awaitingKeyframe=!1,this.resyncRequired=!1}const n={data:t.data.slice(),durationMs:Number.isFinite(t.durationMs)&&t.durationMs>0?t.durationMs:WOe,keyframe:t.keyframe};if(n.keyframe&&this.clearPendingFrames(),this.wouldOverflow(n.data.byteLength)){this.requireResync();return}if(this.addBufferedPacket(n.data.byteLength),!this.muxerReady||!this.configurationApplied){this.pendingFrames.push(n);return}this.applyFrame(n)||this.removeBufferedPacket(n.data.byteLength)}resetMuxer(){var r;const t=this.generatedSources(),n=this.generatedObjectUrls();this.generation+=1,this.muxerReady=!1,this.configurationApplied=!1,this.awaitingKeyframe=!0,this.playPending=!1,this.playRequested=!1,this.stopPlaybackDelayChecks();try{(r=this.muxer)==null||r.reset()}catch(i){this.reportError(jc(i,"Failed to reset H.264 video playback"))}for(const i of t)i.remove();for(const i of n)this.revokeObjectUrl(i)}handleMuxerReady(){this.destroyed||(this.muxerReady=!0,this.startPlaybackDelayChecks(),this.applyConfigurationIfReady(),this.flushPendingFrames())}startPlaybackDelayChecks(){this.playbackDelayTimer===null&&(this.playbackDelayTimer=setInterval(()=>{this.catchUpToLiveEdge()},VOe))}stopPlaybackDelayChecks(){this.playbackDelayTimer!==null&&(clearInterval(this.playbackDelayTimer),this.playbackDelayTimer=null)}catchUpToLiveEdge(){if(this.destroyed||this.video.seeking)return;const t=this.video.buffered;if(t.length!==0)try{const n=t.end(t.length-1),r=this.video.currentTime;if(!Number.isFinite(n)||!Number.isFinite(r)||n-r<=qOe)return;this.video.currentTime=Math.max(0,n-YOe),this.observePlaybackProgress()}catch{}}applyConfigurationIfReady(){if(!(this.destroyed||!this.muxerReady||this.configurationApplied||!this.configuration||!this.muxer))try{this.muxer.feed({video:this.configuration,duration:0,isLastVideoFrameComplete:!0}),this.configurationApplied=!0,this.flushPendingFrames()}catch(t){this.reportError(jc(t,"Failed to apply H.264 decoder configuration"))}}applyFrame(t){if(this.destroyed||!this.muxer)return!1;try{return this.muxer.feed({video:t.data,duration:t.durationMs,isLastVideoFrameComplete:!0}),this.fedFramesAwaitingPlayback.push({byteLength:t.data.byteLength,remainingDurationMs:t.durationMs}),this.attemptPlayback(),!0}catch(n){return this.reportError(jc(n,"Failed to feed an H.264 video frame")),!1}}flushPendingFrames(){if(this.destroyed||!this.muxerReady||!this.configurationApplied||!this.muxer)return;this.observePlaybackProgress();const t=this.pendingFrames;this.pendingFrames=[];for(const n of t){if(this.destroyed)return;this.applyFrame(n)||this.removeBufferedPacket(n.data.byteLength)}}attemptPlayback(){if(this.destroyed||this.playPending||this.playRequested)return;this.playPending=!0,this.playRequested=!0;const t=this.generation;let n;try{n=this.video.play()}catch(r){this.playPending=!1,this.playRequested=!1,this.reportError(jc(r,"Browser blocked H.264 video playback"));return}n.then(()=>{this.destroyed||t!==this.generation||(this.playPending=!1,this.markStarted())},r=>{this.destroyed||t!==this.generation||(this.playPending=!1,this.playRequested=!1,this.reportError(jc(r,"Browser blocked H.264 video playback")))})}handleMuxerError(t){this.destroyed||(t.name==="InvalidStateError"&&(this.generation+=1,this.muxerReady=!1,this.configurationApplied=!1,this.awaitingKeyframe=!0,this.clearBufferedGeneration(),this.playPending=!1,this.playRequested=!1,this.stopPlaybackDelayChecks()),this.reportError(jc(t,"H.264 video buffer failed")))}markStarted(){var t,n;this.started||(this.started=!0,(n=(t=this.options).onStart)==null||n.call(t))}reportError(t){var n,r;this.destroyed||(r=(n=this.options).onError)==null||r.call(n,t)}observePlaybackProgress(){const t=this.video.currentTime;if(!Number.isFinite(t)||t<0)return;if(this.lastObservedMediaTime===null||t<this.lastObservedMediaTime){this.lastObservedMediaTime=t;return}let n=(t-this.lastObservedMediaTime)*1e3;if(this.lastObservedMediaTime=t,!(n<=0))for(;n>0;){const r=this.fedFramesAwaitingPlayback[0];if(!r)return;if(n+Number.EPSILON<r.remainingDurationMs){r.remainingDurationMs-=n;return}n-=r.remainingDurationMs,this.fedFramesAwaitingPlayback.shift(),this.removeBufferedPacket(r.byteLength)}}wouldOverflow(t){return this.bufferedPacketCount+1>this.maxBufferedPackets||this.bufferedBytes+t>this.maxBufferedBytes}addBufferedPacket(t){this.bufferedPacketCount+=1,this.bufferedBytes+=t}removeBufferedPacket(t){this.bufferedPacketCount=Math.max(0,this.bufferedPacketCount-1),this.bufferedBytes=Math.max(0,this.bufferedBytes-t)}clearPendingFrames(){for(const t of this.pendingFrames)this.removeBufferedPacket(t.data.byteLength);this.pendingFrames=[]}clearBufferedGeneration(){this.pendingFrames=[],this.fedFramesAwaitingPlayback=[],this.configuration=null,this.configurationApplied=!1,this.bufferedPacketCount=0,this.bufferedBytes=0,this.lastObservedMediaTime=null}requireResync(){var n,r;const t=!this.resyncRequired;this.resyncRequired=!0,this.clearBufferedGeneration(),this.awaitingKeyframe=!0,this.resetMuxer(),t&&!this.destroyed&&((r=(n=this.options).onResyncRequired)==null||r.call(n,new Error("H.264 playback buffer overflowed; reconnecting for a fresh keyframe")))}generatedSources(){return Array.from(this.video.querySelectorAll("source")).filter(t=>!this.initialSources.has(t))}removeGeneratedSources(){for(const t of this.generatedSources())t.remove()}generatedObjectUrls(){const t=new Set,n=this.video.getAttribute("src");n!==this.initialVideoState.src&&(n!=null&&n.startsWith("blob:"))&&t.add(n);for(const r of this.generatedSources()){const i=r.getAttribute("src");i!=null&&i.startsWith("blob:")&&t.add(i)}return[...t]}revokeObjectUrl(t){if(typeof URL.revokeObjectURL=="function")try{URL.revokeObjectURL(t)}catch{}}}function aB(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class ZOe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=Sh;){const s=new DataView(this.buffer.buffer,this.buffer.byteOffset+i,Sh),o=s.getUint32(0,!0),l=s.getUint32(4,!0);if(o===0||o>xy)throw this.buffer=new Uint8Array(0),new RangeError(`Invalid device preview frame length: ${o}`);const u=Sh+o;if(this.buffer.byteLength-i<u)break;r.push({sequence:l,jpeg:this.buffer.slice(i+Sh,i+u)}),i+=u}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Sh+xy)throw this.buffer=new Uint8Array(0),new RangeError("Device preview stream buffer exceeded its limit");return r}finish(){if(this.buffer.byteLength!==0)throw this.buffer=new Uint8Array(0),new Error("Device preview stream ended with a truncated frame")}}class QOe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=Xh;){const s=this.buffer.subarray(i),o=lne(s);if(!o)throw this.buffer=new Uint8Array(0),new RangeError("Invalid H.264 device preview packet header");const l=Xh+o.annexBLength;if(this.buffer.byteLength-i<l)break;r.push({sequence:o.packetSequence,kind:o.configuration?"configuration":"frame",keyframe:o.keyframe,durationMs:o.durationMs,data:this.buffer.slice(i+Xh,i+l)}),i+=l}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Xh+xy)throw this.buffer=new Uint8Array(0),new RangeError("H.264 device preview stream buffer exceeded its limit");return r}finish(){if(this.buffer.byteLength!==0)throw this.buffer=new Uint8Array(0),new Error("H.264 device preview stream ended with a truncated packet")}}function JOe(e){let t;try{t=new URL(e,globalThis.location.href)}catch{throw new Error("无效的模拟器画面地址")}if(t.origin!==globalThis.location.origin||t.username!==""||t.password!==""||!/^\/api\/device-preview-streams\/[A-Za-z0-9_-]{1,256}$/u.test(t.pathname)||t.search!==""||t.hash!=="")throw new Error("拒绝连接不受信任的模拟器画面地址")}function eLe(e){const t=Number(e.headers.get("X-Device-Width")),n=Number(e.headers.get("X-Device-Height"));return!Number.isSafeInteger(t)||t<=0||!Number.isSafeInteger(n)||n<=0?null:{width:t,height:n}}async function JU(e,t,n){JOe(e);const r=db(),i=await n(e,{method:"GET",cache:"no-store",credentials:"same-origin",...r?{headers:{Authorization:`Bearer ${r}`}}:{},signal:t});if(!i.ok||!i.body)throw new Error(`无法打开模拟器画面(${i.status})`);return i}async function tLe(e,t){const n=t.fetch??globalThis.fetch,r=await JU(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new ZOe,s=r.body.getReader();try{for(;;){const{done:o,value:l}=await s.read();if(o)break;const d=i.push(l).at(-1);d&&await t.onFrame(d)}i.finish()}finally{s.releaseLock()}}async function nLe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await JU(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=eLe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new QOe,o=r.body.getReader();try{for(;;){const{done:u,value:d}=await o.read();if(u)break;for(const f of s.push(d))await t.onPacket(f)}s.finish()}finally{o.releaseLock()}}const rLe=16,iLe=16;class sLe{constructor(t){je(this,"send");je(this,"onFailure");je(this,"now");je(this,"moveFlushMs");je(this,"maxInFlightMoves");je(this,"active",null);je(this,"inFlightMoves",0);je(this,"disposed",!1);je(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??rLe,this.maxInFlightMoves=t.maxInFlightMoves??iLe}begin(t,n){if(this.disposed||this.failed||this.active)return!1;const r={pointerId:t,lastPoint:n,lastMoveAt:Number.NEGATIVE_INFINITY,pendingMove:null,moveFlushTimer:null};return this.active=r,this.dispatch(this.input("down",n)),!0}move(t,n){const r=this.matchingActive(t);if(!r)return!1;r.lastPoint=n,r.pendingMove=n;const i=this.now(),s=this.moveFlushMs-(i-r.lastMoveAt);return s>0?(r.moveFlushTimer===null&&(r.moveFlushTimer=setTimeout(()=>{r.moveFlushTimer=null,!(this.active!==r||this.disposed||this.failed)&&(r.lastMoveAt=this.now(),this.flushLatestMove())},s)),!0):(this.clearMoveTimer(r),r.lastMoveAt=i,this.flushLatestMove(),!0)}end(t,n){const r=this.matchingActive(t);return r?(r.lastPoint=n,this.finish(r),this.dispatch(this.input("up",n)),!0):!1}cancel(t){const n=this.active;if(!n||t!==void 0&&n.pointerId!==t)return!1;const r=n.lastPoint;return this.finish(n),this.dispatch(this.input("up",r)),!0}dispose(){if(this.disposed)return;const t=this.active;if(t&&this.finish(t),this.disposed=!0,!(!t||this.failed))try{Promise.resolve(this.send(this.input("up",t.lastPoint))).catch(()=>{})}catch{}}matchingActive(t){var n;return this.disposed||this.failed||((n=this.active)==null?void 0:n.pointerId)!==t?null:this.active}finish(t){this.active===t&&(this.active=null),this.clearMoveTimer(t),t.pendingMove=null}clearMoveTimer(t){t.moveFlushTimer!==null&&clearTimeout(t.moveFlushTimer),t.moveFlushTimer=null}flushLatestMove(){const t=this.active;if(!t||this.disposed||this.failed||!t.pendingMove||t.moveFlushTimer!==null||this.inFlightMoves>=this.maxInFlightMoves)return;const n=t.pendingMove;t.pendingMove=null,this.inFlightMoves+=1,this.dispatch(this.input("move",n),()=>{this.inFlightMoves=Math.max(0,this.inFlightMoves-1),this.flushLatestMove()})}dispatch(t,n){let r;try{r=Promise.resolve(this.send(t))}catch(i){this.fail(i),n==null||n();return}r.then(()=>n==null?void 0:n(),i=>{this.fail(i),n==null||n()})}fail(t){if(this.disposed||this.failed)return;this.failed=!0;const n=this.active;n&&this.finish(n),this.onFailure(t)}input(t,n){return{kind:"touch",phase:t,x:n.x,y:n.y}}}const oLe=15e3,aLe=1e4,lLe={ios:40,android:28},cLe={ios:{width:390,height:844},android:{width:412,height:915}};function uLe(){const{id:e=""}=WB(),t=Es(),n=dr($e=>Hj($e).find(We=>We.previewId===e)),r=dr($e=>$e.listLoaded),i=dr($e=>{var We;return((We=$e.authoritative)==null?void 0:We.scope)??null}),s=Vo($e=>Ore($e,i,"device",e,"reconnect")),o=b.useRef(null),l=b.useRef(null),u=b.useRef(null),d=b.useRef(null),f=b.useRef(null),p=b.useRef(()=>{}),v=b.useRef(null),g=b.useRef(null),[_,w]=b.useState(0),[S,x]=b.useState("waiting"),[R,k]=b.useState(null),[N,M]=b.useState(null),[T,P]=b.useState(null),[z,V]=b.useState(""),[U,G]=b.useState(!1),[O,A]=b.useState(!1),[L,D]=b.useState(!1),I=n==null?void 0:n.previewId,B=n==null?void 0:n.state,F=n==null?void 0:n.platform,Y=b.useCallback(()=>{const $e=f.current;f.current=null,$e==null||$e.dispose()},[]);b.useEffect(()=>{if(F!=="ios"){d.current=null,P(null);return}const $e=o.current;if(!$e)return;const We=new $Oe($e,P);return We.reset(!0),P(null),d.current=We,()=>{We.dispose(),d.current=null}},[I,F]),b.useEffect(()=>{if(Y(),p.current=()=>{},v.current=null,g.current=null,M(null),A(!1),D(!1),!I||B!=="ready"){B==="disconnected"?(x("error"),k("模拟器已断开")):(x("waiting"),k(null));return}const $e=Ft,We=i;if(!$e||!We||!Rt.isActive($e,We)){x("error"),k("开发机连接已断开");return}let vt=!1,mt=null,st=null,Ae=null,_e=null,Qe=null,ve=0,Fe=!1;const ot=()=>{Qe=null,Ae==null||Ae.abort(),Ae=null,_e==null||_e.destroy(),_e=null,mt&&clearTimeout(mt),mt=null,st&&clearTimeout(st),st=null},yt=Ct=>{x("streaming"),st&&clearTimeout(st),st=setTimeout(()=>{st=null,!(vt||Ct.signal.aborted||Qe!==Ct.leaseId||!Rt.isActive($e,We))&&(ve=0)},aLe)},Et=()=>{if(vt||document.visibilityState==="hidden"||!Rt.isActive($e,We))return;const Ct=Math.min(5e3,500*2**ve);ve+=1,mt=setTimeout(()=>void sn(),Ct)},sn=async()=>{var tn;if(Y(),ot(),vt||document.visibilityState==="hidden"||!Rt.isActive($e,We))return;Fe=!1,(tn=d.current)==null||tn.reset(),P(null),x("connecting"),k(null),M(null);const Ct=new AbortController;Ae=Ct;try{const jt=await Rt.requestDevicePreviewStream(We,I,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:Ct.signal});if(vt||Ct.signal.aborted||!Rt.isActive($e,We)||!jt)return;if(!jt.success)throw new Error(jt.error);const cn=jt;if(Qe=cn.leaseId,M(cn),F==="android"){const Qn=l.current;if(!Qn)throw new Error("无法初始化 Android 模拟器播放器");let qn;const vn=new Promise((ue,ye)=>{qn=ye}),W=setTimeout(()=>{qn(new Error("Android 模拟器画面启动超时"))},oLe),re=ue=>{qn(ue instanceof Error?ue:new Error(String(ue)))},oe=new XOe(Qn,{onStart:()=>{clearTimeout(W),!(vt||cn.signal.aborted||!Rt.isActive($e,We))&&yt(cn)},onError:re,onResyncRequired:re});_e=oe;try{await Promise.race([nLe(cn.url,{signal:cn.signal,onSize:ue=>{!vt&&!cn.signal.aborted&&Rt.isActive($e,We)&&P(ue)},onPacket:ue=>{!vt&&!cn.signal.aborted&&Rt.isActive($e,We)&&oe.feed(ue)}}),vn])}finally{clearTimeout(W)}if(!vt&&!cn.signal.aborted&&Rt.isActive($e,We))throw new Error("模拟器画面已断开");return}let Mn=!1;if(await tLe(cn.url,{signal:cn.signal,onFrame:Qn=>{if(vt||cn.signal.aborted||!Rt.isActive($e,We))return;const qn=d.current;qn&&(qn.enqueue(Qn.sequence,Qn.jpeg),Mn||(Mn=!0,yt(cn)))}}),!vt&&!cn.signal.aborted&&Rt.isActive($e,We))throw new Error("模拟器画面已断开")}catch(jt){if(vt||Ct.signal.aborted||!Rt.isActive($e,We))return;Xt(jt,!1)}},Xt=(Ct,tn)=>{if(vt||Fe||!Rt.isActive($e,We))return;Fe=!0;const jt=Ct instanceof Error?Ct.message:"模拟器画面已断开";Y(),ot(),v.current=null,g.current=null,M(null),A(!1),D(!1),x("error"),k(jt),tn&&qe.error(jt),Et()},on=(Ct,tn,jt=!0)=>{Ct===Qe&&Xt(tn,jt)};p.current=on;const gn=$e.onMessage(Ct=>{if(Ct.type!=="device_preview_control_revoked_push"||!Qt(Ct.scope,We)||Ct.leaseId!==Qe||!Rt.isActive($e,We))return;if(g.current=null,D(!1),Ct.reason==="taken_over"){v.current=null,A(!1),Y(),M(jt=>(jt==null?void 0:jt.leaseId)===Ct.leaseId?{...jt,controlMode:"view_only"}:jt),qe.info("控制权已由其他页面接管");return}const tn=new Error(Ct.reason==="proxy_offline"?"开发机连接已断开":Ct.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");on(Ct.leaseId,tn,!1)}),_n=()=>{if(document.visibilityState==="hidden"){Y(),ot(),v.current=null,g.current=null,M(null),A(!1),D(!1),x("waiting");return}ve=0,sn()};return document.addEventListener("visibilitychange",_n),sn(),()=>{vt=!0,p.current===on&&(p.current=()=>{}),gn(),document.removeEventListener("visibilitychange",_n),Y(),ot()}},[Y,I,F,i,B,_]),b.useEffect(()=>{var $e;($e=f.current)==null||$e.cancel()},[T==null?void 0:T.height,T==null?void 0:T.width]);const j=(n==null?void 0:n.state)==="ready"&&(N==null?void 0:N.previewId)===n.previewId&&i&&Qt(N.scope,i)?N:null,q=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{Y();const $e=Ft,We=j;if(!$e||!We||!q)return;const vt=new sLe({send:async mt=>{const st=await Rt.sendDevicePreviewInput(We,mt);if(!st)throw new Error("模拟器控制连接已失效");if(!st.success)throw new Error(st.error)},onFailure:mt=>{f.current===vt&&p.current(We.leaseId,mt)}});return f.current=vt,()=>{f.current===vt&&(f.current=null),vt.dispose()}},[q,j,Y]);const K=T??cLe[(n==null?void 0:n.platform)==="android"?"android":"ios"],$=lLe[(n==null?void 0:n.platform)==="android"?"android":"ios"],ne=K.width/K.height,J=K.width>K.height?"landscape":"portrait",te=J==="landscape"?`, ${K.width}px`:"",Q={aspectRatio:`${K.width} / ${K.height}`,width:`max(1px, min(calc(100cqw - ${$}px), calc(${(ne*100).toFixed(6)}cqh - ${(ne*$).toFixed(6)}px)${te}))`};b.useEffect(()=>{q||G(!1)},[q]);const ce=b.useCallback(async($e,We=!0)=>{const vt=Ft,mt=j;if(!vt||!mt||!q)return!1;try{const st=await Rt.sendDevicePreviewInput(mt,$e);return!st||!Rt.isActive(vt,mt.scope)?!1:st.success?!0:(We&&qe.error(st.error),!1)}catch(st){return mt.signal.aborted||!Rt.isActive(vt,mt.scope)||We&&qe.error(st instanceof Error?st.message:"模拟器操作失败"),!1}},[q,j]);function ie($e,We){const vt=u.current;if(!vt||!T)return null;const mt=vt.getBoundingClientRect(),st={left:mt.left,top:mt.top,width:mt.width,height:mt.height,frameWidth:T.width,frameHeight:T.height};return We==="start"?zOe($e.clientX,$e.clientY,st):jOe($e.clientX,$e.clientY,st)}function le($e){var mt,st;if(!q||$e.button!==0)return;const We=ie($e,"start");if(!We)return;const vt=f.current;vt!=null&&vt.begin($e.pointerId,We)&&($e.preventDefault(),(st=(mt=$e.currentTarget).setPointerCapture)==null||st.call(mt,$e.pointerId))}function be($e){var vt;const We=ie($e,"captured");We&&(vt=f.current)!=null&&vt.move($e.pointerId,We)&&$e.preventDefault()}function Le($e){var vt;const We=ie($e,"captured");We&&((vt=f.current)!=null&&vt.end($e.pointerId,We))&&$e.preventDefault()}function he($e){var We;(We=f.current)==null||We.cancel($e.pointerId)}async function He(){const $e=Ft,We=j;if(!$e||!We||L||S!=="streaming")return;const vt=Symbol("device-preview-control-claim");g.current=vt,D(!0);try{const mt=await Rt.claimDevicePreviewControl(We);if(g.current!==vt||!mt||!Rt.isActive($e,We.scope))return;if(!mt.success){qe.error(mt.error);return}M(st=>(st==null?void 0:st.leaseId)===We.leaseId?{...st,controlMode:"controller"}:st)}catch(mt){if(g.current!==vt||We.signal.aborted||!Rt.isActive($e,We.scope))return;qe.error(mt instanceof Error?mt.message:"暂时无法取得控制权")}finally{g.current===vt&&(g.current=null,D(!1))}}async function Pt($e){$e.preventDefault();const We=z;if(!We||O)return;const vt=Symbol("device-preview-text-input");v.current=vt,A(!0);const mt=await ce({kind:"text",text:We});v.current===vt&&(mt&&(V(""),G(!1)),v.current=null,A(!1))}function Ge(){var $e;($e=f.current)==null||$e.cancel(),ce({kind:"orientation",orientation:T&&T.width>T.height?"portrait":"landscape_right"})}async function it(){if((n==null?void 0:n.state)!=="disconnected"){w(vt=>vt+1);return}const $e=Ft,We=Rt.getActiveScope();if(!$e||!We){qe.error("请先连接开发机");return}try{const vt=await Rt.reconnectDevicePreview(We,n.previewId);vt.success||qe.error(vt.error)}catch(vt){if(!Rt.isActive($e,We))return;qe.error(vt instanceof Error?vt.message:"无法重新连接模拟器预览")}}return n?m.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-slot":"device-preview-page","data-preview-id":n.previewId,"data-stream-status":S,"data-control-mode":n.interactive?(j==null?void 0:j.controlMode)??"none":"unavailable",children:[m.jsxs("header",{className:"flex min-h-14 shrink-0 items-center gap-2 border-b px-3 md:px-4",children:[m.jsx(pt,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(sf,{"aria-hidden":"true"})}),m.jsx(hC,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("p",{className:"truncate text-sm font-medium",children:n.name}),m.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[n.model," · ",n.platform==="ios"?"iOS":"Android"," ",n.osVersion]})]}),n.interactive&&S==="streaming"&&(j==null?void 0:j.controlMode)==="view_only"?m.jsx(pt,{size:"sm",variant:"outline",disabled:L,onClick:()=>void He(),"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:q?"可操控":S==="streaming"?"仅查看":"连接中"})]}),m.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-muted/30",children:m.jsxs("div",{className:Ye("grid h-full min-h-0 min-w-0 gap-3 p-3 md:gap-4 md:p-6",J==="portrait"?"grid-rows-[minmax(0,1fr)_auto] md:grid-cols-[minmax(0,1fr)_auto] md:grid-rows-1":"grid-rows-[minmax(0,1fr)_auto]"),"data-slot":"device-preview-stage","data-orientation":J,children:[m.jsxs("div",{className:"relative flex min-h-0 min-w-0 items-center justify-center overflow-hidden [container-type:size]","data-slot":"device-preview-viewport",children:[m.jsxs("div",{className:Ye("relative isolate shrink-0 transition-[width,aspect-ratio] duration-300 ease-out motion-reduce:transition-none [container-type:size]",n.platform==="ios"?"[--device-screen-radius:clamp(22px,14cqmin,56px)] [--ios-rail:clamp(10px,4cqmin,16px)]":"[--device-screen-radius:clamp(14px,6.5cqw,38px)]"),style:Q,"data-slot":"device-preview-device-shell","data-platform":n.platform,"data-orientation":J,children:[m.jsx(dLe,{platform:n.platform,orientation:J}),m.jsx("div",{ref:u,className:Ye("relative z-10 flex h-full w-full min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-[var(--device-screen-radius)] bg-black ring-1 ring-black",q&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":q?"true":"false",children:n.platform==="android"?m.jsx("video",{ref:l,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-video",muted:!0,autoPlay:!0,playsInline:!0,disableRemotePlayback:!0,onLoadedMetadata:$e=>{const We=$e.currentTarget;We.videoWidth>0&&We.videoHeight>0&&P({width:We.videoWidth,height:We.videoHeight})},onResize:$e=>{const We=$e.currentTarget;We.videoWidth>0&&We.videoHeight>0&&P({width:We.videoWidth,height:We.videoHeight})}}):m.jsx("canvas",{ref:o,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-canvas"})}),m.jsx("div",{className:Ye("absolute inset-0 z-20 select-none rounded-[var(--device-screen-radius)]",q?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:le,onPointerMove:be,onPointerUp:Le,onPointerCancel:he,onLostPointerCapture:he,onContextMenu:$e=>{q&&$e.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":q?"true":"false","aria-hidden":"true"})]}),S!=="streaming"?m.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background/55 p-6 backdrop-blur-[1px]","data-slot":"device-preview-stream-overlay","data-stream-status":S,children:m.jsx("div",{className:"grid max-w-sm justify-items-center gap-3 text-center",children:S==="error"?m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:R}),m.jsxs(pt,{variant:"outline",size:"sm",disabled:s,onClick:()=>void it(),"data-slot":"device-preview-retry",children:[s?m.jsx(oi,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(oi,{className:"size-5 animate-spin text-muted-foreground","aria-hidden":!0}),m.jsx("p",{className:"text-sm text-muted-foreground",children:"正在连接画面..."})]})})}):null]}),m.jsx("div",{className:"relative z-20 flex min-w-0 items-center justify-center pb-[max(0px,env(safe-area-inset-bottom))] md:pb-0","data-slot":"device-preview-control-dock","data-orientation":J,role:"group","aria-label":"模拟器控制",children:m.jsxs("div",{className:Ye("flex max-w-full items-center gap-1 rounded-full border border-border/70 bg-card/85 p-1.5 shadow-xl ring-1 ring-black/5 backdrop-blur-xl",J==="portrait"&&"md:flex-col"),children:[m.jsx(AS,{control:"home",label:"主屏幕",disabled:!q,icon:m.jsx(YV,{"aria-hidden":"true"}),tooltipSide:J==="portrait"?"left":"top",onClick:()=>void ce({kind:"button",button:"home"})}),n.platform==="android"?m.jsx(AS,{control:"back",label:"返回",disabled:!q,icon:m.jsx(GY,{"aria-hidden":"true"}),tooltipSide:J==="portrait"?"left":"top",onClick:()=>void ce({kind:"button",button:"back"})}):null,m.jsx(AS,{control:"orientation",label:"旋转",disabled:!q||!T,icon:m.jsx(RY,{"aria-hidden":"true"}),tooltipSide:J==="portrait"?"left":"top",onClick:Ge}),m.jsx("span",{className:Ye("mx-0.5 h-6 w-px shrink-0 bg-border/80",J==="portrait"&&"md:mx-0 md:h-px md:w-6"),"aria-hidden":"true"}),m.jsxs(Ib,{open:U,onOpenChange:$e=>{(!$e||q)&&G($e)},children:[m.jsxs(gf,{children:[m.jsx(vf,{asChild:!0,children:m.jsx(Ob,{asChild:!0,children:m.jsx(pt,{type:"button",variant:"ghost",size:"icon",className:Ye("size-11 rounded-full text-muted-foreground hover:text-foreground",U&&"bg-accent text-foreground"),disabled:!q,"aria-label":"粘贴文字","aria-expanded":U,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(OS,{"aria-hidden":"true"})})})}),m.jsx(yf,{side:J==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(Lb,{side:J==="portrait"?"left":"top",align:"center",sideOffset:12,className:"w-[min(20rem,calc(100vw-1.5rem))] rounded-2xl bg-card/95 p-2 shadow-2xl backdrop-blur-xl",children:m.jsxs("form",{id:"device-preview-text-form",className:"flex items-end gap-2","data-slot":"device-preview-text-form",onSubmit:$e=>void Pt($e),children:[m.jsx("textarea",{value:z,onChange:$e=>V($e.target.value),disabled:!q||O,maxLength:4096,rows:3,placeholder:"粘贴文字","aria-label":"粘贴文字","data-slot":"device-preview-text-input",className:"min-h-20 min-w-0 flex-1 resize-none rounded-xl border bg-background px-3 py-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 md:text-sm"}),m.jsx(pt,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!q||!z||O,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:O?m.jsx(oi,{className:"animate-spin","aria-hidden":"true"}):m.jsx(OS,{"aria-hidden":"true"})})]})})]})]})})]})})]}):m.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center",children:r?m.jsxs("div",{className:"grid gap-3",children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:"无法找到该预览"}),m.jsx(pt,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(oi,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function AS({control:e,label:t,icon:n,disabled:r,tooltipSide:i,onClick:s}){return m.jsxs(gf,{children:[m.jsx(vf,{asChild:!0,children:m.jsx(pt,{type:"button",variant:"ghost",size:"icon",className:"size-11 rounded-full text-muted-foreground hover:text-foreground","aria-label":t,disabled:r,onClick:s,"data-slot":"device-preview-control","data-control":e,children:n})}),m.jsx(yf,{side:i,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:t})]})}function dLe({platform:e,orientation:t}){const n=t==="portrait";return e==="ios"?m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"ios","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[var(--ios-rail)] z-0 select-none rounded-[calc(var(--device-screen-radius)+var(--ios-rail))] border border-black/85 bg-[#202024] ring-1 ring-black/30","shadow-[inset_1px_1px_0_rgba(255,255,255,0.16),inset_-1px_-1px_0_rgba(0,0,0,0.72)]"),children:[m.jsx("span",{className:"absolute inset-[2px] rounded-[calc(var(--device-screen-radius)+var(--ios-rail)-2px)] ring-1 ring-inset ring-white/[0.05]"}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -left-[4px] top-[16%] h-[clamp(12px,4%,22px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[23%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[32%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -right-[4px] top-[28%] h-[clamp(36px,12%,64px)] w-[4px] rounded-r-[3px] border border-l-0 border-black/70 bg-[#343439] shadow-[inset_-1px_0_0_rgba(255,255,255,0.14)]"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[16%] h-[4px] w-[clamp(12px,4%,22px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[23%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[32%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -bottom-[4px] left-[28%] h-[4px] w-[clamp(36px,12%,64px)] rounded-b-[3px] border border-t-0 border-black/70 bg-[#343439] shadow-[inset_0_-1px_0_rgba(255,255,255,0.14)]"})]})]}):m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"android","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[9px] z-0 select-none rounded-[calc(var(--device-screen-radius)+9px)] border border-black/70 bg-[linear-gradient(145deg,#68717a_0%,#22272d_22%,#08090b_58%,#454c55_100%)] ring-1 ring-white/15"),children:[m.jsx("span",{className:Ye("absolute rounded-full bg-white/25 shadow-sm",n?"left-1/2 top-[3px] h-px w-[14%] -translate-x-1/2":"left-[3px] top-1/2 h-[14%] w-px -translate-y-1/2")}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -right-[4px] top-[20%] h-[14%] min-h-7 w-[3px] rounded-r-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -right-[4px] top-[38%] h-[9%] min-h-4 w-[3px] rounded-r-sm bg-slate-400 shadow-sm"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[20%] h-[3px] w-[14%] min-w-7 rounded-t-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -top-[4px] left-[38%] h-[3px] w-[9%] min-w-4 rounded-t-sm bg-slate-400 shadow-sm"})]})]})}const $d=T7([{path:"/",element:m.jsx(QSe,{}),children:[{index:!0,element:m.jsx(JSe,{})},{path:"sessions",element:m.jsx(e1e,{})},{path:"chat/:id",element:m.jsx(EOe,{})},{path:"preview/device/:id",element:m.jsx(uLe,{})}]},{path:"/pty-test",element:m.jsx(AOe,{})},{path:"/tokens",element:m.jsx(LOe,{})},{path:"/markdown-test",element:m.jsx(BOe,{})}]);function fLe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Pp(window.location.href,{allowUserGestureFallback:!0});n(i==="failed"?"failed":"copied")};return m.jsxs("div",{className:"flex min-h-[100dvh] flex-col overflow-hidden bg-background text-foreground","data-slot":"unsupported-ipad-browser",children:[m.jsx("header",{className:"mx-auto flex w-full max-w-5xl items-center px-6 py-5 sm:px-10",children:m.jsx(Az,{className:"text-sm",slot:"unsupported-browser-brand"})}),m.jsx("main",{className:"mx-auto flex w-full max-w-5xl flex-1 items-center px-6 pb-20 sm:px-10 sm:pb-24",children:m.jsxs("section",{className:"max-w-xl","aria-labelledby":"unsupported-browser-title",children:[m.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[m.jsx(xV,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx("span",{children:"iPad 浏览器支持"})]}),m.jsx("h1",{id:"unsupported-browser-title",className:"mt-4 text-3xl font-semibold tracking-normal sm:text-4xl",children:"请使用 Safari 打开"}),m.jsxs("p",{className:"mt-4 max-w-lg text-base leading-7 text-muted-foreground",children:["DEV Anywhere 暂不支持 iPad 上的 ",e,"。当前版本仅支持 Safari,以保证终端输入和实体键盘行为稳定。"]}),m.jsxs("div",{className:"mt-7 flex flex-wrap items-center gap-3",children:[m.jsxs(pt,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(ia,{className:"size-4","aria-hidden":"true"}):m.jsx(nz,{className:"size-4","aria-hidden":"true"}),t==="copied"?"链接已复制":"复制当前链接"]}),m.jsx("span",{className:"text-sm text-muted-foreground","aria-live":"polite",children:t==="copied"?"请切换到 Safari 后粘贴打开":t==="failed"?"复制失败,请从地址栏复制":"复制后在 Safari 中打开"})]})]})})]})}function hLe({children:e}){const t=ZSe();return t.supported?e:m.jsx(fLe,{browserName:t.browserName})}function pLe(){return m.jsx(hLe,{children:m.jsx(mLe,{})})}function mLe(){return dse(),m.jsx(lde,{delayDuration:200,children:m.jsx(Zq,{router:$d})})}function gLe(e=window.history){e.scrollRestoration="manual"}gLe();uG();Mhe();hW.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(pLe,{})}));export{X6 as _,Gp as a,yLe as g};