@dev-anywhere/relay 0.10.8 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jmuxer.min-f89rJUS-.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-BJfcp90E.js","assets/__vite-browser-external-D7Ct-6yo.js"])))=>i.map(i=>d[i]);
2
2
  var pq=Object.defineProperty;var mq=(e,t,n)=>t in e?pq(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Me=(e,t,n)=>mq(e,typeof t!="symbol"?t+"":t,n);function gq(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 fm(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function aBe(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 Tx={exports:{}},Eh={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -602,7 +602,7 @@ ${s}`,l=W5(`${_1(r.kind)}:${r.path}`,o,r.kind);n.push(l.kind==="diff"?{...l,co
602
602
 
603
603
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
604
604
 
605
- 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},ale="DialogDescriptionWarning",lle=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${M3(ale).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},Ck=v3,cle=b3,kk=w3,Tk=x3,Rk=S3,P3=C3,I3=T3,Db=A3;function ule(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 dle(e){const[t,n]=b.useState(void 0);return rs(()=>{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 fle=["top","right","bottom","left"],nc=Math.min,Ws=Math.max,$y=Math.round,kv=Math.floor,la=e=>({x:e,y:e}),hle={left:"right",right:"left",bottom:"top",top:"bottom"};function T1(e,t,n){return Ws(e,nc(t,n))}function Ya(e,t){return typeof e=="function"?e(t):e}function Va(e){return e.split("-")[0]}function xf(e){return e.split("-")[1]}function Ak(e){return e==="x"?"y":"x"}function Nk(e){return e==="y"?"height":"width"}function sa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function Mk(e){return Ak(sa(e))}function ple(e,t,n){n===void 0&&(n=!1);const r=xf(e),i=Mk(e),s=Nk(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Uy(o)),[o,Uy(o)]}function mle(e){const t=Uy(e);return[R1(e),t,R1(t)]}function R1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const uI=["left","right"],dI=["right","left"],gle=["top","bottom"],vle=["bottom","top"];function yle(e,t,n){switch(e){case"top":case"bottom":return n?t?dI:uI:t?uI:dI;case"left":case"right":return t?gle:vle;default:return[]}}function ble(e,t,n,r){const i=xf(e);let s=yle(Va(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(R1)))),s}function Uy(e){const t=Va(e);return hle[t]+e.slice(t.length)}function _le(e){return{top:0,right:0,bottom:0,left:0,...e}}function O3(e){return typeof e!="number"?_le(e):{top:e,right:e,bottom:e,left:e}}function Wy(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 fI(e,t,n){let{reference:r,floating:i}=e;const s=sa(t),o=Mk(t),l=Nk(o),u=Va(t),d=s==="y",f=r.x+r.width/2-i.width/2,h=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:h};break;case"left":g={x:r.x-i.width,y:h};break;default:g={x:r.x,y:r.y}}switch(xf(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 wle(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:h="floating",altBoundary:v=!1,padding:g=0}=Ya(t,e),_=O3(g),S=l[v?h==="floating"?"reference":"floating":h],x=Wy(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})),T=h==="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)),A=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},I=Wy(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:T,offsetParent:k,strategy:u}):T);return{top:(x.top-I.top+_.top)/A.y,bottom:(I.bottom-x.bottom+_.bottom)/A.y,left:(x.left-I.left+_.left)/A.x,right:(I.right-x.right+_.right)/A.x}}const xle=50,Sle=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:wle},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:f,y:h}=fI(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:T}=S,{x:k,y:A,data:I,reset:R}=await T({x:f,y:h,initialPlacement:r,placement:v,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=k??f,h=A??h,_[x]={..._[x],...I},R&&g<xle&&(g++,typeof R=="object"&&(R.placement&&(v=R.placement),R.rects&&(d=R.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):R.rects),{x:f,y:h}=fI(d,v,u)),w=-1)}return{x:f,y:h,placement:v,strategy:i,middlewareData:_}},Ele=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}=Ya(e,t)||{};if(d==null)return{};const h=O3(f),v={x:n,y:r},g=Mk(i),_=Nk(g),w=await o.getDimensions(d),S=g==="y",x=S?"top":"left",T=S?"bottom":"right",k=S?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[g]-v[g]-s.floating[_],I=v[g]-s.reference[g],R=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let M=R?R[k]:0;(!M||!await(o.isElement==null?void 0:o.isElement(R)))&&(M=l.floating[k]||s.floating[_]);const z=A/2-I/2,Y=M/2-w[_]/2-1,W=nc(h[x],Y),G=nc(h[T],Y),O=W,N=M-w[_]-G,L=M/2-w[_]/2+z,D=T1(O,L,N),P=!u.arrow&&xf(i)!=null&&L!==D&&s.reference[_]/2-(L<O?W:G)-w[_]/2<0,B=P?L<O?L-O:L-N:0;return{[g]:v[g]+B,data:{[g]:D,centerOffset:L-D-B,...P&&{alignmentOffset:B}},reset:P}}}),Cle=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:h=!0,fallbackPlacements:v,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=Ya(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Va(i),T=sa(l),k=Va(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),I=v||(k||!w?[Uy(l)]:mle(l)),R=_!=="none";!v&&R&&I.push(...ble(l,w,_,A));const M=[l,...I],z=await u.detectOverflow(t,S),Y=[];let W=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&Y.push(z[x]),h){const L=ple(i,o,A);Y.push(z[L[0]],z[L[1]])}if(W=[...W,{placement:i,overflows:Y}],!Y.every(L=>L<=0)){var G,O;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,D=M[L];if(D&&(!(h==="alignment"?T!==sa(D):!1)||W.every(F=>sa(F.placement)===T?F.overflows[0]>0:!0)))return{data:{index:L,overflows:W},reset:{placement:D}};let P=(O=W.filter(B=>B.overflows[0]<=0).sort((B,F)=>B.overflows[1]-F.overflows[1])[0])==null?void 0:O.placement;if(!P)switch(g){case"bestFit":{var N;const B=(N=W.filter(F=>{if(R){const U=sa(F.placement);return U===T||U==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(U=>U>0).reduce((U,j)=>U+j,0)]).sort((F,U)=>F[1]-U[1])[0])==null?void 0:N[0];B&&(P=B);break}case"initialPlacement":P=l;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function hI(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function pI(e){return fle.some(t=>e[t]>=0)}const kle=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=Ya(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=hI(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:pI(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=hI(o,n.floating);return{data:{escapedOffsets:l,escaped:pI(l)}}}default:return{}}}}},L3=new Set(["left","top"]);async function Tle(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Va(n),l=xf(n),u=sa(n)==="y",d=L3.has(o)?-1:1,f=s&&u?-1:1,h=Ya(t,e);let{mainAxis:v,crossAxis:g,alignmentAxis:_}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof _=="number"&&(g=l==="end"?_*-1:_),u?{x:g*f,y:v*d}:{x:v*d,y:g*f}}const Rle=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 Tle(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}}}}},Ale=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:T,y:k}=x;return{x:T,y:k}}},...d}=Ya(e,t),f={x:n,y:r},h=await s.detectOverflow(t,d),v=sa(Va(i)),g=Ak(v);let _=f[g],w=f[v];if(o){const x=g==="y"?"top":"left",T=g==="y"?"bottom":"right",k=_+h[x],A=_-h[T];_=T1(k,_,A)}if(l){const x=v==="y"?"top":"left",T=v==="y"?"bottom":"right",k=w+h[x],A=w-h[T];w=T1(k,w,A)}const S=u.fn({...t,[g]:_,[v]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[g]:o,[v]:l}}}}}},Nle=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}=Ya(e,t),f={x:n,y:r},h=sa(i),v=Ak(h);let g=f[v],_=f[h];const w=Ya(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const k=v==="y"?"height":"width",A=s.reference[v]-s.floating[k]+S.mainAxis,I=s.reference[v]+s.reference[k]-S.mainAxis;g<A?g=A:g>I&&(g=I)}if(d){var x,T;const k=v==="y"?"width":"height",A=L3.has(Va(i)),I=s.reference[h]-s.floating[k]+(A&&((x=o.offset)==null?void 0:x[h])||0)+(A?0:S.crossAxis),R=s.reference[h]+s.reference[k]+(A?0:((T=o.offset)==null?void 0:T[h])||0)-(A?S.crossAxis:0);_<I?_=I:_>R&&(_=R)}return{[v]:g,[h]:_}}}},Mle=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}=Ya(e,t),f=await o.detectOverflow(t,d),h=Va(i),v=xf(i),g=sa(i)==="y",{width:_,height:w}=s.floating;let S,x;h==="top"||h==="bottom"?(S=h,x=v===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=h,S=v==="end"?"top":"bottom");const T=w-f.top-f.bottom,k=_-f.left-f.right,A=nc(w-f[S],T),I=nc(_-f[x],k),R=!t.middlewareData.shift;let M=A,z=I;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(z=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(M=T),R&&!v){const W=Ws(f.left,0),G=Ws(f.right,0),O=Ws(f.top,0),N=Ws(f.bottom,0);g?z=_-2*(W!==0||G!==0?W+G:Ws(f.left,f.right)):M=w-2*(O!==0||N!==0?O+N:Ws(f.top,f.bottom))}await u({...t,availableWidth:z,availableHeight:M});const Y=await o.getDimensions(l.floating);return _!==Y.width||w!==Y.height?{reset:{rects:!0}}:{}}}};function Bb(){return typeof window<"u"}function Sf(e){return D3(e)?(e.nodeName||"").toLowerCase():"#document"}function Vs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ma(e){var t;return(t=(D3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function D3(e){return Bb()?e instanceof Node||e instanceof Vs(e).Node:!1}function Bo(e){return Bb()?e instanceof Element||e instanceof Vs(e).Element:!1}function Za(e){return Bb()?e instanceof HTMLElement||e instanceof Vs(e).HTMLElement:!1}function mI(e){return!Bb()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vs(e).ShadowRoot}function Em(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=zo(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Ple(e){return/^(table|td|th)$/.test(Sf(e))}function zb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Ile=/transform|translate|scale|rotate|perspective|filter/,Ole=/paint|layout|strict|content/,$c=e=>!!e&&e!=="none";let x0;function Pk(e){const t=Bo(e)?zo(e):e;return $c(t.transform)||$c(t.translate)||$c(t.scale)||$c(t.rotate)||$c(t.perspective)||!Ik()&&($c(t.backdropFilter)||$c(t.filter))||Ile.test(t.willChange||"")||Ole.test(t.contain||"")}function Lle(e){let t=rc(e);for(;Za(t)&&!lf(t);){if(Pk(t))return t;if(zb(t))return null;t=rc(t)}return null}function Ik(){return x0==null&&(x0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),x0}function lf(e){return/^(html|body|#document)$/.test(Sf(e))}function zo(e){return Vs(e).getComputedStyle(e)}function jb(e){return Bo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function rc(e){if(Sf(e)==="html")return e;const t=e.assignedSlot||e.parentNode||mI(e)&&e.host||ma(e);return mI(t)?t.host:t}function B3(e){const t=rc(e);return lf(t)?e.ownerDocument?e.ownerDocument.body:e.body:Za(t)&&Em(t)?t:B3(t)}function Zp(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=B3(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Vs(i);if(s){const l=A1(o);return t.concat(o,o.visualViewport||[],Em(i)?i:[],l&&n?Zp(l):[])}else return t.concat(i,Zp(i,[],n))}function A1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function z3(e){const t=zo(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Za(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=$y(n)!==s||$y(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function Ok(e){return Bo(e)?e:e.contextElement}function Gd(e){const t=Ok(e);if(!Za(t))return la(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=z3(t);let o=(s?$y(n.width):n.width)/r,l=(s?$y(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Dle=la(0);function j3(e){const t=Vs(e);return!Ik()||!t.visualViewport?Dle:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ble(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Vs(e)?!1:t}function fu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=Ok(e);let o=la(1);t&&(r?Bo(r)&&(o=Gd(r)):o=Gd(e));const l=Ble(s,n,r)?j3(s):la(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,f=i.width/o.x,h=i.height/o.y;if(s){const v=Vs(s),g=r&&Bo(r)?Vs(r):r;let _=v,w=A1(_);for(;w&&r&&g!==_;){const S=Gd(w),x=w.getBoundingClientRect(),T=zo(w),k=x.left+(w.clientLeft+parseFloat(T.paddingLeft))*S.x,A=x.top+(w.clientTop+parseFloat(T.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,h*=S.y,u+=k,d+=A,_=Vs(w),w=A1(_)}}return Wy({width:f,height:h,x:u,y:d})}function Fb(e,t){const n=jb(e).scrollLeft;return t?t.left+n:fu(ma(e)).left+n}function F3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Fb(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function zle(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=ma(r),l=t?zb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=la(1);const f=la(0),h=Za(r);if((h||!h&&!s)&&((Sf(r)!=="body"||Em(o))&&(u=jb(r)),h)){const g=fu(r);d=Gd(r),f.x=g.x+r.clientLeft,f.y=g.y+r.clientTop}const v=o&&!h&&!s?F3(o,u):la(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 jle(e){return Array.from(e.getClientRects())}function Fle(e){const t=ma(e),n=jb(e),r=e.ownerDocument.body,i=Ws(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ws(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Fb(e);const l=-n.scrollTop;return zo(r).direction==="rtl"&&(o+=Ws(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const gI=25;function Hle(e,t){const n=Vs(e),r=ma(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=Ik();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Fb(r);if(d<=0){const f=r.ownerDocument,h=f.body,v=getComputedStyle(h),g=f.compatMode==="CSS1Compat"&&parseFloat(v.marginLeft)+parseFloat(v.marginRight)||0,_=Math.abs(r.clientWidth-h.clientWidth-g);_<=gI&&(s-=_)}else d<=gI&&(s+=d);return{width:s,height:o,x:l,y:u}}function $le(e,t){const n=fu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Za(e)?Gd(e):la(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 vI(e,t,n){let r;if(t==="viewport")r=Hle(e,n);else if(t==="document")r=Fle(ma(e));else if(Bo(t))r=$le(t,n);else{const i=j3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Wy(r)}function H3(e,t){const n=rc(e);return n===t||!Bo(n)||lf(n)?!1:zo(n).position==="fixed"||H3(n,t)}function Ule(e,t){const n=t.get(e);if(n)return n;let r=Zp(e,[],!1).filter(l=>Bo(l)&&Sf(l)!=="body"),i=null;const s=zo(e).position==="fixed";let o=s?rc(e):e;for(;Bo(o)&&!lf(o);){const l=zo(o),u=Pk(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Em(o)&&!u&&H3(e,o))?r=r.filter(f=>f!==o):i=l,o=rc(o)}return t.set(e,r),r}function Wle(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?zb(t)?[]:Ule(t,this._c):[].concat(n),r],l=vI(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,h=l.left;for(let v=1;v<o.length;v++){const g=vI(t,o[v],i);u=Ws(g.top,u),d=nc(g.right,d),f=nc(g.bottom,f),h=Ws(g.left,h)}return{width:d-h,height:f-u,x:h,y:u}}function qle(e){const{width:t,height:n}=z3(e);return{width:t,height:n}}function Yle(e,t,n){const r=Za(t),i=ma(t),s=n==="fixed",o=fu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=la(0);function d(){u.x=Fb(i)}if(r||!r&&!s)if((Sf(t)!=="body"||Em(i))&&(l=jb(t)),r){const g=fu(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?F3(i,l):la(0),h=o.left+l.scrollLeft-u.x-f.x,v=o.top+l.scrollTop-u.y-f.y;return{x:h,y:v,width:o.width,height:o.height}}function S0(e){return zo(e).position==="static"}function yI(e,t){if(!Za(e)||zo(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ma(e)===n&&(n=n.ownerDocument.body),n}function $3(e,t){const n=Vs(e);if(zb(e))return n;if(!Za(e)){let i=rc(e);for(;i&&!lf(i);){if(Bo(i)&&!S0(i))return i;i=rc(i)}return n}let r=yI(e,t);for(;r&&Ple(r)&&S0(r);)r=yI(r,t);return r&&lf(r)&&S0(r)&&!Pk(r)?n:r||Lle(e)||n}const Vle=async function(e){const t=this.getOffsetParent||$3,n=this.getDimensions,r=await n(e.floating);return{reference:Yle(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Kle(e){return zo(e).direction==="rtl"}const Gle={convertOffsetParentRelativeRectToViewportRelativeRect:zle,getDocumentElement:ma,getClippingRect:Wle,getOffsetParent:$3,getElementRects:Vle,getClientRects:jle,getDimensions:qle,getScale:Gd,isElement:Bo,isRTL:Kle};function U3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Xle(e,t){let n=null,r;const i=ma(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:h,width:v,height:g}=d;if(l||t(),!v||!g)return;const _=kv(h),w=kv(i.clientWidth-(f+v)),S=kv(i.clientHeight-(h+g)),x=kv(f),k={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:Ws(0,nc(1,u))||1};let A=!0;function I(R){const M=R[0].intersectionRatio;if(M!==u){if(!A)return o();M?o(!1,M):r=setTimeout(()=>{o(!1,1e-7)},1e3)}M===1&&!U3(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(I,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(I,k)}n.observe(e)}return o(!0),s}function Zle(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=Ok(e),f=i||s?[...d?Zp(d):[],...t?Zp(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const h=d&&l?Xle(d,n):null;let v=-1,g=null;o&&(g=new ResizeObserver(x=>{let[T]=x;T&&T.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?fu(e):null;u&&S();function S(){const x=fu(e);w&&!U3(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(T=>{i&&T.removeEventListener("scroll",n),s&&T.removeEventListener("resize",n)}),h==null||h(),(x=g)==null||x.disconnect(),g=null,u&&cancelAnimationFrame(_)}}const Jle=Rle,Qle=Ale,ece=Cle,tce=Mle,nce=kle,bI=Ele,rce=Nle,ice=(e,t,n)=>{const r=new Map,i={platform:Gle,...n},s={...i.platform,_c:r};return Sle(e,t,{...i,platform:s})};var sce=typeof document<"u",oce=function(){},py=sce?b.useLayoutEffect:oce;function qy(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(!qy(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)&&!qy(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function W3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function _I(e,t){const n=W3(e);return Math.round(t*n)/n}function E0(e){const t=b.useRef(e);return py(()=>{t.current=e}),t}function ace(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,h]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[v,g]=b.useState(r);qy(v,r)||g(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),T=b.useCallback(F=>{F!==R.current&&(R.current=F,w(F))},[]),k=b.useCallback(F=>{F!==M.current&&(M.current=F,x(F))},[]),A=s||_,I=o||S,R=b.useRef(null),M=b.useRef(null),z=b.useRef(f),Y=u!=null,W=E0(u),G=E0(i),O=E0(d),N=b.useCallback(()=>{if(!R.current||!M.current)return;const F={placement:t,strategy:n,middleware:v};G.current&&(F.platform=G.current),ice(R.current,M.current,F).then(U=>{const j={...U,isPositioned:O.current!==!1};L.current&&!qy(z.current,j)&&(z.current=j,Eu.flushSync(()=>{h(j)}))})},[v,t,n,G,O]);py(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,h(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);py(()=>(L.current=!0,()=>{L.current=!1}),[]),py(()=>{if(A&&(R.current=A),I&&(M.current=I),A&&I){if(W.current)return W.current(A,I,N);N()}},[A,I,N,W,Y]);const D=b.useMemo(()=>({reference:R,floating:M,setReference:T,setFloating:k}),[T,k]),P=b.useMemo(()=>({reference:A,floating:I}),[A,I]),B=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!P.floating)return F;const U=_I(P.floating,f.x),j=_I(P.floating,f.y);return l?{...F,transform:"translate("+U+"px, "+j+"px)",...W3(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:j}},[n,l,P.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:N,refs:D,elements:P,floatingStyles:B}),[f,N,D,P,B])}const lce=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?bI({element:r.current,padding:i}).fn(n):{}:r?bI({element:r,padding:i}).fn(n):{}}}},cce=(e,t)=>{const n=Jle(e);return{name:n.name,fn:n.fn,options:[e,t]}},uce=(e,t)=>{const n=Qle(e);return{name:n.name,fn:n.fn,options:[e,t]}},dce=(e,t)=>({fn:rce(e).fn,options:[e,t]}),fce=(e,t)=>{const n=ece(e);return{name:n.name,fn:n.fn,options:[e,t]}},hce=(e,t)=>{const n=tce(e);return{name:n.name,fn:n.fn,options:[e,t]}},pce=(e,t)=>{const n=nce(e);return{name:n.name,fn:n.fn,options:[e,t]}},mce=(e,t)=>{const n=lce(e);return{name:n.name,fn:n.fn,options:[e,t]}};var gce="Arrow",q3=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(Sn.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"})})});q3.displayName=gce;var vce=q3,Lk="Popper",[Y3,fc]=Xa(Lk),[yce,V3]=Y3(Lk),K3=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(yce,{scope:t,anchor:r,onAnchorChange:i,children:n})};K3.displayName=Lk;var G3="PopperAnchor",X3=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=V3(G3,n),o=b.useRef(null),l=dr(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(Sn.div,{...i,ref:l})});X3.displayName=G3;var Dk="PopperContent",[bce,_ce]=Y3(Dk),Z3=b.forwardRef((e,t)=>{var Z,ce,ie,me,ge,ve;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:h="partial",hideWhenDetached:v=!1,updatePositionStrategy:g="optimized",onPlaced:_,...w}=e,S=V3(Dk,n),[x,T]=b.useState(null),k=dr(t,Te=>T(Te)),[A,I]=b.useState(null),R=dle(A),M=(R==null?void 0:R.width)??0,z=(R==null?void 0:R.height)??0,Y=r+(s!=="center"?"-"+s:""),W=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},G=Array.isArray(d)?d:[d],O=G.length>0,N={padding:W,boundary:G.filter(xce),altBoundary:O},{refs:L,floatingStyles:D,placement:P,isPositioned:B,middlewareData:F}=ace({strategy:"fixed",placement:Y,whileElementsMounted:(...Te)=>Zle(...Te,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[cce({mainAxis:i+z,alignmentAxis:o}),u&&uce({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?dce():void 0,...N}),u&&fce({...N}),hce({...N,apply:({elements:Te,rects:Xe,availableWidth:wt,availableHeight:et})=>{const{width:ft,height:Ne}=Xe.reference,Ue=Te.floating.style;Ue.setProperty("--radix-popper-available-width",`${wt}px`),Ue.setProperty("--radix-popper-available-height",`${et}px`),Ue.setProperty("--radix-popper-anchor-width",`${ft}px`),Ue.setProperty("--radix-popper-anchor-height",`${Ne}px`)}}),A&&mce({element:A,padding:l}),Sce({arrowWidth:M,arrowHeight:z}),v&&pce({strategy:"referenceHidden",...N})]}),[U,j]=e4(P),V=Do(_);rs(()=>{B&&(V==null||V())},[B,V]);const X=(Z=F.arrow)==null?void 0:Z.x,H=(ce=F.arrow)==null?void 0:ce.y,Q=((ie=F.arrow)==null?void 0:ie.centerOffset)!==0,[ne,te]=b.useState();return rs(()=>{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:ne,"--radix-popper-transform-origin":[(me=F.transformOrigin)==null?void 0:me.x,(ge=F.transformOrigin)==null?void 0:ge.y].join(" "),...((ve=F.hide)==null?void 0:ve.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(bce,{scope:n,placedSide:U,onArrowChange:I,arrowX:X,arrowY:H,shouldHideArrow:Q,children:m.jsx(Sn.div,{"data-side":U,"data-align":j,...w,ref:k,style:{...w.style,animation:B?void 0:"none"}})})})});Z3.displayName=Dk;var J3="PopperArrow",wce={top:"bottom",right:"left",bottom:"top",left:"right"},Q3=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=_ce(J3,r),o=wce[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(vce,{...i,ref:n,style:{...i.style,display:"block"}})})});Q3.displayName=J3;function xce(e){return e!==null}var Sce=e=>({name:"transformOrigin",options:e,fn(t){var S,x,T;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]=e4(n),h={start:"0%",center:"50%",end:"100%"}[f],v=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,g=(((T=i.arrow)==null?void 0:T.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?h:`${v}px`,w=`${-u}px`):d==="top"?(_=o?h:`${v}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?h:`${g}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?h:`${g}px`),{data:{x:_,y:w}}}});function e4(e){const[t,n="center"]=e.split("-");return[t,n]}var Cm=K3,km=X3,Hb=Z3,$b=Q3,C0="rovingFocusGroup.onEntryFocus",Ece={bubbles:!1,cancelable:!0},Tm="RovingFocusGroup",[N1,t4,Cce]=_k(Tm),[kce,n4]=Xa(Tm,[Cce]),[Tce,Rce]=kce(Tm),r4=b.forwardRef((e,t)=>m.jsx(N1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(N1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(Ace,{...e,ref:t})})}));r4.displayName=Tm;var Ace=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,...h}=e,v=b.useRef(null),g=dr(t,v),_=wk(s),[w,S]=tc({prop:o,defaultProp:l??null,onChange:u,caller:Tm}),[x,T]=b.useState(!1),k=Do(d),A=t4(n),I=b.useRef(!1),[R,M]=b.useState(0);return b.useEffect(()=>{const z=v.current;if(z)return z.addEventListener(C0,k),()=>z.removeEventListener(C0,k)},[k]),m.jsx(Tce,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(z=>S(z),[S]),onItemShiftTab:b.useCallback(()=>T(!0),[]),onFocusableItemAdd:b.useCallback(()=>M(z=>z+1),[]),onFocusableItemRemove:b.useCallback(()=>M(z=>z-1),[]),children:m.jsx(Sn.div,{tabIndex:x||R===0?-1:0,"data-orientation":r,...h,ref:g,style:{outline:"none",...e.style},onMouseDown:qt(e.onMouseDown,()=>{I.current=!0}),onFocus:qt(e.onFocus,z=>{const Y=!I.current;if(z.target===z.currentTarget&&Y&&!x){const W=new CustomEvent(C0,Ece);if(z.currentTarget.dispatchEvent(W),!W.defaultPrevented){const G=A().filter(P=>P.focusable),O=G.find(P=>P.active),N=G.find(P=>P.id===w),D=[O,N,...G].filter(Boolean).map(P=>P.ref.current);o4(D,f)}}I.current=!1}),onBlur:qt(e.onBlur,()=>T(!1))})})}),i4="RovingFocusGroupItem",s4=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=bi(),d=s||u,f=Rce(i4,n),h=f.currentTabStopId===d,v=t4(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(N1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(Sn.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:qt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:qt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:qt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=Pce(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(A=>A.focusable).map(A=>A.ref.current);if(x==="last")k.reverse();else if(x==="prev"||x==="next"){x==="prev"&&k.reverse();const A=k.indexOf(S.currentTarget);k=f.loop?Ice(k,A+1):k.slice(A+1)}setTimeout(()=>o4(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:w!=null}):o})})});s4.displayName=i4;var Nce={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Mce(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Pce(e,t,n){const r=Mce(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Nce[r]}function o4(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ice(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Oce=r4,Lce=s4,M1=["Enter"," "],Dce=["ArrowDown","PageUp","Home"],a4=["ArrowUp","PageDown","End"],Bce=[...Dce,...a4],zce={ltr:[...M1,"ArrowRight"],rtl:[...M1,"ArrowLeft"]},jce={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Rm="Menu",[Jp,Fce,Hce]=_k(Rm),[Cu,l4]=Xa(Rm,[Hce,fc,n4]),Am=fc(),c4=n4(),[u4,hc]=Cu(Rm),[$ce,Nm]=Cu(Rm),d4=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Am(t),[u,d]=b.useState(null),f=b.useRef(!1),h=Do(s),v=wk(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(Cm,{...l,children:m.jsx(u4,{scope:t,open:n,onOpenChange:h,content:u,onContentChange:d,children:m.jsx($ce,{scope:t,onClose:b.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:f,dir:v,modal:o,children:r})})})};d4.displayName=Rm;var Uce="MenuAnchor",Bk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Am(n);return m.jsx(km,{...i,...r,ref:t})});Bk.displayName=Uce;var zk="MenuPortal",[Wce,f4]=Cu(zk,{forceMount:void 0}),h4=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=hc(zk,t);return m.jsx(Wce,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};h4.displayName=zk;var go="MenuContent",[qce,jk]=Cu(go),p4=b.forwardRef((e,t)=>{const n=f4(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hc(go,e.__scopeMenu),o=Nm(go,e.__scopeMenu);return m.jsx(Jp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Jp.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Yce,{...i,ref:t}):m.jsx(Vce,{...i,ref:t})})})})}),Yce=b.forwardRef((e,t)=>{const n=hc(go,e.__scopeMenu),r=b.useRef(null),i=dr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Ob(s)},[]),m.jsx(Fk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:qt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Vce=b.forwardRef((e,t)=>{const n=hc(go,e.__scopeMenu);return m.jsx(Fk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Kce=ec("MenuContent.ScrollLock"),Fk=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:h,onInteractOutside:v,onDismiss:g,disableOutsideScroll:_,...w}=e,S=hc(go,n),x=Nm(go,n),T=Am(n),k=c4(n),A=Fce(n),[I,R]=b.useState(null),M=b.useRef(null),z=dr(t,M,S.onContentChange),Y=b.useRef(0),W=b.useRef(""),G=b.useRef(0),O=b.useRef(null),N=b.useRef("right"),L=b.useRef(0),D=_?Sm:b.Fragment,P=_?{as:Kce,allowPinchZoom:!0}:void 0,B=U=>{var Z,ce;const j=W.current+U,V=A().filter(ie=>!ie.disabled),X=document.activeElement,H=(Z=V.find(ie=>ie.ref.current===X))==null?void 0:Z.textValue,Q=V.map(ie=>ie.textValue),ne=oue(Q,j,H),te=(ce=V.find(ie=>ie.textValue===ne))==null?void 0:ce.ref.current;(function ie(me){W.current=me,window.clearTimeout(Y.current),me!==""&&(Y.current=window.setTimeout(()=>ie(""),1e3))})(j),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(Y.current),[]),Pb();const F=b.useCallback(U=>{var V,X;return N.current===((V=O.current)==null?void 0:V.side)&&lue(U,(X=O.current)==null?void 0:X.area)},[]);return m.jsx(qce,{scope:n,searchRef:W,onItemEnter:b.useCallback(U=>{F(U)&&U.preventDefault()},[F]),onItemLeave:b.useCallback(U=>{var j;F(U)||((j=M.current)==null||j.focus(),R(null))},[F]),onTriggerLeave:b.useCallback(U=>{F(U)&&U.preventDefault()},[F]),pointerGraceTimerRef:G,onPointerGraceIntentChange:b.useCallback(U=>{O.current=U},[]),children:m.jsx(D,{...P,children:m.jsx(xm,{asChild:!0,trapped:i,onMountAutoFocus:qt(s,U=>{var j;U.preventDefault(),(j=M.current)==null||j.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:h,onInteractOutside:v,onDismiss:g,children:m.jsx(Oce,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:R,onEntryFocus:qt(u,U=>{x.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(Hb,{role:"menu","aria-orientation":"vertical","data-state":M4(S.open),"data-radix-menu-content":"",dir:x.dir,...T,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:qt(w.onKeyDown,U=>{const V=U.target.closest("[data-radix-menu-content]")===U.currentTarget,X=U.ctrlKey||U.altKey||U.metaKey,H=U.key.length===1;V&&(U.key==="Tab"&&U.preventDefault(),!X&&H&&B(U.key));const Q=M.current;if(U.target!==Q||!Bce.includes(U.key))return;U.preventDefault();const te=A().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);a4.includes(U.key)&&te.reverse(),iue(te)}),onBlur:qt(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(Y.current),W.current="")}),onPointerMove:qt(e.onPointerMove,Qp(U=>{const j=U.target,V=L.current!==U.clientX;if(U.currentTarget.contains(j)&&V){const X=U.clientX>L.current?"right":"left";N.current=X,L.current=U.clientX}}))})})})})})})});p4.displayName=go;var Gce="MenuGroup",Hk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(Sn.div,{role:"group",...r,ref:t})});Hk.displayName=Gce;var Xce="MenuLabel",m4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(Sn.div,{...r,ref:t})});m4.displayName=Xce;var Yy="MenuItem",wI="menu.itemSelect",Ub=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Nm(Yy,e.__scopeMenu),l=jk(Yy,e.__scopeMenu),u=dr(t,s),d=b.useRef(!1),f=()=>{const h=s.current;if(!n&&h){const v=new CustomEvent(wI,{bubbles:!0,cancelable:!0});h.addEventListener(wI,g=>r==null?void 0:r(g),{once:!0}),t3(h,v),v.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(g4,{...i,ref:u,disabled:n,onClick:qt(e.onClick,f),onPointerDown:h=>{var v;(v=e.onPointerDown)==null||v.call(e,h),d.current=!0},onPointerUp:qt(e.onPointerUp,h=>{var v;d.current||(v=h.currentTarget)==null||v.click()}),onKeyDown:qt(e.onKeyDown,h=>{const v=l.searchRef.current!=="";n||v&&h.key===" "||M1.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Ub.displayName=Yy;var g4=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=jk(Yy,n),l=c4(n),u=b.useRef(null),d=dr(t,u),[f,h]=b.useState(!1),[v,g]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&g((_.textContent??"").trim())},[s.children]),m.jsx(Jp.ItemSlot,{scope:n,disabled:r,textValue:i??v,children:m.jsx(Lce,{asChild:!0,...l,focusable:!r,children:m.jsx(Sn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:qt(e.onPointerMove,Qp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:qt(e.onPointerLeave,Qp(_=>o.onItemLeave(_))),onFocus:qt(e.onFocus,()=>h(!0)),onBlur:qt(e.onBlur,()=>h(!1))})})})}),Zce="MenuCheckboxItem",v4=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(x4,{scope:e.__scopeMenu,checked:n,children:m.jsx(Ub,{role:"menuitemcheckbox","aria-checked":Vy(n)?"mixed":n,...i,ref:t,"data-state":Wk(n),onSelect:qt(i.onSelect,()=>r==null?void 0:r(Vy(n)?!0:!n),{checkForDefaultPrevented:!1})})})});v4.displayName=Zce;var y4="MenuRadioGroup",[Jce,Qce]=Cu(y4,{value:void 0,onValueChange:()=>{}}),b4=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Do(r);return m.jsx(Jce,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(Hk,{...i,ref:t})})});b4.displayName=y4;var _4="MenuRadioItem",w4=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=Qce(_4,e.__scopeMenu),s=n===i.value;return m.jsx(x4,{scope:e.__scopeMenu,checked:s,children:m.jsx(Ub,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Wk(s),onSelect:qt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});w4.displayName=_4;var $k="MenuItemIndicator",[x4,eue]=Cu($k,{checked:!1}),S4=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=eue($k,n);return m.jsx(xo,{present:r||Vy(s.checked)||s.checked===!0,children:m.jsx(Sn.span,{...i,ref:t,"data-state":Wk(s.checked)})})});S4.displayName=$k;var tue="MenuSeparator",E4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(Sn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});E4.displayName=tue;var nue="MenuArrow",C4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Am(n);return m.jsx($b,{...i,...r,ref:t})});C4.displayName=nue;var Uk="MenuSub",[rue,k4]=Cu(Uk),T4=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=hc(Uk,t),o=Am(t),[l,u]=b.useState(null),[d,f]=b.useState(null),h=Do(i);return b.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),m.jsx(Cm,{...o,children:m.jsx(u4,{scope:t,open:r,onOpenChange:h,content:d,onContentChange:f,children:m.jsx(rue,{scope:t,contentId:bi(),triggerId:bi(),trigger:l,onTriggerChange:u,children:n})})})};T4.displayName=Uk;var fp="MenuSubTrigger",R4=b.forwardRef((e,t)=>{const n=hc(fp,e.__scopeMenu),r=Nm(fp,e.__scopeMenu),i=k4(fp,e.__scopeMenu),s=jk(fp,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 h=l.current;return()=>{window.clearTimeout(h),u(null)}},[l,u]),m.jsx(Bk,{asChild:!0,...d,children:m.jsx(g4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":M4(n.open),...e,ref:qa(t,i.onTriggerChange),onClick:h=>{var v;(v=e.onClick)==null||v.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:qt(e.onPointerMove,Qp(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:qt(e.onPointerLeave,Qp(h=>{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,T=v[S?"left":"right"],k=v[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+x,y:h.clientY},{x:T,y:v.top},{x:k,y:v.top},{x:k,y:v.bottom},{x:T,y:v.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:qt(e.onKeyDown,h=>{var g;const v=s.searchRef.current!=="";e.disabled||v&&h.key===" "||zce[r.dir].includes(h.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),h.preventDefault())})})})});R4.displayName=fp;var A4="MenuSubContent",N4=b.forwardRef((e,t)=>{const n=f4(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hc(go,e.__scopeMenu),o=Nm(go,e.__scopeMenu),l=k4(A4,e.__scopeMenu),u=b.useRef(null),d=dr(t,u);return m.jsx(Jp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Jp.Slot,{scope:e.__scopeMenu,children:m.jsx(Fk,{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 h;o.isUsingKeyboardRef.current&&((h=u.current)==null||h.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:qt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:qt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:qt(e.onKeyDown,f=>{var g;const h=f.currentTarget.contains(f.target),v=jce[o.dir].includes(f.key);h&&v&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});N4.displayName=A4;function M4(e){return e?"open":"closed"}function Vy(e){return e==="indeterminate"}function Wk(e){return Vy(e)?"indeterminate":e?"checked":"unchecked"}function iue(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function sue(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function oue(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=sue(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 aue(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,h=u.x,v=u.y;f>r!=v>r&&n<(h-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function lue(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return aue(n,t)}function Qp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var cue=d4,uue=Bk,due=h4,fue=p4,hue=Hk,pue=m4,mue=Ub,gue=v4,vue=b4,yue=w4,bue=S4,_ue=E4,wue=C4,xue=T4,Sue=R4,Eue=N4,Wb="DropdownMenu",[Cue]=Xa(Wb,[l4]),is=l4(),[kue,P4]=Cue(Wb),I4=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=is(t),d=b.useRef(null),[f,h]=tc({prop:i,defaultProp:s??!1,onChange:o,caller:Wb});return m.jsx(kue,{scope:t,triggerId:bi(),triggerRef:d,contentId:bi(),open:f,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(v=>!v),[h]),modal:l,children:m.jsx(cue,{...u,open:f,onOpenChange:h,dir:r,modal:l,children:n})})};I4.displayName=Wb;var O4="DropdownMenuTrigger",L4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=P4(O4,n),o=is(n);return m.jsx(uue,{asChild:!0,...o,children:m.jsx(Sn.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:qa(t,s.triggerRef),onPointerDown:qt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:qt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});L4.displayName=O4;var Tue="DropdownMenuPortal",D4=e=>{const{__scopeDropdownMenu:t,...n}=e,r=is(t);return m.jsx(due,{...r,...n})};D4.displayName=Tue;var B4="DropdownMenuContent",z4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=P4(B4,n),s=is(n),o=b.useRef(!1);return m.jsx(fue,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:qt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:qt(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)"}})});z4.displayName=B4;var Rue="DropdownMenuGroup",Aue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(hue,{...i,...r,ref:t})});Aue.displayName=Rue;var Nue="DropdownMenuLabel",j4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(pue,{...i,...r,ref:t})});j4.displayName=Nue;var Mue="DropdownMenuItem",F4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(mue,{...i,...r,ref:t})});F4.displayName=Mue;var Pue="DropdownMenuCheckboxItem",H4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(gue,{...i,...r,ref:t})});H4.displayName=Pue;var Iue="DropdownMenuRadioGroup",Oue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(vue,{...i,...r,ref:t})});Oue.displayName=Iue;var Lue="DropdownMenuRadioItem",Due=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(yue,{...i,...r,ref:t})});Due.displayName=Lue;var Bue="DropdownMenuItemIndicator",$4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(bue,{...i,...r,ref:t})});$4.displayName=Bue;var zue="DropdownMenuSeparator",U4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(_ue,{...i,...r,ref:t})});U4.displayName=zue;var jue="DropdownMenuArrow",Fue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(wue,{...i,...r,ref:t})});Fue.displayName=jue;var Hue=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=is(t),[l,u]=tc({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return m.jsx(xue,{...o,open:l,onOpenChange:u,children:n})},$ue="DropdownMenuSubTrigger",W4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(Sue,{...i,...r,ref:t})});W4.displayName=$ue;var Uue="DropdownMenuSubContent",q4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(Eue,{...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)"}})});q4.displayName=Uue;var Wue=I4,que=L4,Y4=D4,Yue=z4,Vue=j4,Kue=F4,Gue=H4,Xue=$4,Zue=U4,Jue=Hue,Que=W4,ede=q4;function xI(e,[t,n]){return Math.min(n,Math.max(t,e))}var qb="Popover",[V4]=Xa(qb,[fc]),Mm=fc(),[tde,pc]=V4(qb),K4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Mm(t),u=b.useRef(null),[d,f]=b.useState(!1),[h,v]=tc({prop:r,defaultProp:i??!1,onChange:s,caller:qb});return m.jsx(Cm,{...l,children:m.jsx(tde,{scope:t,contentId:bi(),triggerRef:u,open:h,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})})};K4.displayName=qb;var G4="PopoverAnchor",nde=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pc(G4,n),s=Mm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(km,{...s,...r,ref:t})});nde.displayName=G4;var X4="PopoverTrigger",Z4=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pc(X4,n),s=Mm(n),o=dr(t,i.triggerRef),l=m.jsx(Sn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":nF(i.open),...r,ref:o,onClick:qt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(km,{asChild:!0,...s,children:l})});Z4.displayName=X4;var qk="PopoverPortal",[rde,ide]=V4(qk,{forceMount:void 0}),J4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=pc(qk,t);return m.jsx(rde,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};J4.displayName=qk;var cf="PopoverContent",Q4=b.forwardRef((e,t)=>{const n=ide(cf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=pc(cf,e.__scopePopover);return m.jsx(xo,{present:r||s.open,children:s.modal?m.jsx(ode,{...i,ref:t}):m.jsx(ade,{...i,ref:t})})});Q4.displayName=cf;var sde=ec("PopoverContent.RemoveScroll"),ode=b.forwardRef((e,t)=>{const n=pc(cf,e.__scopePopover),r=b.useRef(null),i=dr(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Ob(o)},[]),m.jsx(Sm,{as:sde,allowPinchZoom:!0,children:m.jsx(eF,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:qt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:qt(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:qt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),ade=b.forwardRef((e,t)=>{const n=pc(cf,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(eF,{...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&&d.contains(o)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),eF=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,...h}=e,v=pc(cf,n),g=Mm(n);return Pb(),m.jsx(xm,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>v.onOpenChange(!1),children:m.jsx(Hb,{"data-state":nF(v.open),role:"dialog",id:v.contentId,...g,...h,ref:t,style:{...h.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)"}})})})}),tF="PopoverClose",lde=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pc(tF,n);return m.jsx(Sn.button,{type:"button",...r,ref:t,onClick:qt(e.onClick,()=>i.onOpenChange(!1))})});lde.displayName=tF;var cde="PopoverArrow",ude=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Mm(n);return m.jsx($b,{...i,...r,ref:t})});ude.displayName=cde;function nF(e){return e?"open":"closed"}var dde=K4,fde=Z4,hde=J4,pde=Q4,mde=[" ","Enter","ArrowUp","ArrowDown"],gde=[" ","Enter"],hu="Select",[Yb,Vb,vde]=_k(hu),[Ef]=Xa(hu,[vde,fc]),Kb=fc(),[yde,mc]=Ef(hu),[bde,_de]=Ef(hu),rF=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:f,autoComplete:h,disabled:v,required:g,form:_}=e,w=Kb(t),[S,x]=b.useState(null),[T,k]=b.useState(null),[A,I]=b.useState(!1),R=wk(d),[M,z]=tc({prop:r,defaultProp:i??!1,onChange:s,caller:hu}),[Y,W]=tc({prop:o,defaultProp:l,onChange:u,caller:hu}),G=b.useRef(null),O=S?_||!!S.closest("form"):!0,[N,L]=b.useState(new Set),D=Array.from(N).map(P=>P.props.value).join(";");return m.jsx(Cm,{...w,children:m.jsxs(yde,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:T,onValueNodeChange:k,valueNodeHasChildren:A,onValueNodeHasChildrenChange:I,contentId:bi(),value:Y,onValueChange:W,open:M,onOpenChange:z,dir:R,triggerPointerDownPosRef:G,disabled:v,children:[m.jsx(Yb.Provider,{scope:t,children:m.jsx(bde,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{L(B=>new Set(B).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{L(B=>{const F=new Set(B);return F.delete(P),F})},[]),children:n})}),O?m.jsxs(CF,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:h,value:Y,onChange:P=>W(P.target.value),disabled:v,form:_,children:[Y===void 0?m.jsx("option",{value:""}):null,Array.from(N)]},D):null]})})};rF.displayName=hu;var iF="SelectTrigger",sF=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Kb(n),o=mc(iF,n),l=o.disabled||r,u=dr(t,o.onTriggerChange),d=Vb(n),f=b.useRef("touch"),[h,v,g]=TF(w=>{const S=d().filter(k=>!k.disabled),x=S.find(k=>k.value===o.value),T=RF(S,w,x);T!==void 0&&o.onValueChange(T.value)}),_=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(km,{asChild:!0,...s,children:m.jsx(Sn.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":kF(o.value)?"":void 0,...i,ref:u,onClick:qt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:qt(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:qt(i.onKeyDown,w=>{const S=h.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&v(w.key),!(S&&w.key===" ")&&mde.includes(w.key)&&(_(),w.preventDefault())})})})});sF.displayName=iF;var oF="SelectValue",aF=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=mc(oF,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,h=dr(t,u.onValueNodeChange);return rs(()=>{d(f)},[d,f]),m.jsx(Sn.span,{...l,ref:h,style:{pointerEvents:"none"},children:kF(u.value)?m.jsx(m.Fragment,{children:o}):s})});aF.displayName=oF;var wde="SelectIcon",lF=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(Sn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});lF.displayName=wde;var xde="SelectPortal",cF=e=>m.jsx(wf,{asChild:!0,...e});cF.displayName=xde;var pu="SelectContent",uF=b.forwardRef((e,t)=>{const n=mc(pu,e.__scopeSelect),[r,i]=b.useState();if(rs(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?Eu.createPortal(m.jsx(dF,{scope:e.__scopeSelect,children:m.jsx(Yb.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(fF,{...e,ref:t})});uF.displayName=pu;var No=10,[dF,gc]=Ef(pu),Sde="SelectContentImpl",Ede=ec("SelectContent.RemoveScroll"),fF=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:h,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,T=mc(pu,n),[k,A]=b.useState(null),[I,R]=b.useState(null),M=dr(t,Z=>A(Z)),[z,Y]=b.useState(null),[W,G]=b.useState(null),O=Vb(n),[N,L]=b.useState(!1),D=b.useRef(!1);b.useEffect(()=>{if(k)return Ob(k)},[k]),Pb();const P=b.useCallback(Z=>{const[ce,...ie]=O().map(ve=>ve.ref.current),[me]=ie.slice(-1),ge=document.activeElement;for(const ve of Z)if(ve===ge||(ve==null||ve.scrollIntoView({block:"nearest"}),ve===ce&&I&&(I.scrollTop=0),ve===me&&I&&(I.scrollTop=I.scrollHeight),ve==null||ve.focus(),document.activeElement!==ge))return},[O,I]),B=b.useCallback(()=>P([z,k]),[P,z,k]);b.useEffect(()=>{N&&B()},[N,B]);const{onOpenChange:F,triggerPointerDownPosRef:U}=T;b.useEffect(()=>{if(k){let Z={x:0,y:0};const ce=me=>{var ge,ve;Z={x:Math.abs(Math.round(me.pageX)-(((ge=U.current)==null?void 0:ge.x)??0)),y:Math.abs(Math.round(me.pageY)-(((ve=U.current)==null?void 0:ve.y)??0))}},ie=me=>{Z.x<=10&&Z.y<=10?me.preventDefault():k.contains(me.target)||F(!1),document.removeEventListener("pointermove",ce),U.current=null};return U.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,U]),b.useEffect(()=>{const Z=()=>F(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[F]);const[j,V]=TF(Z=>{const ce=O().filter(ge=>!ge.disabled),ie=ce.find(ge=>ge.ref.current===document.activeElement),me=RF(ce,Z,ie);me&&setTimeout(()=>me.ref.current.focus())}),X=b.useCallback((Z,ce,ie)=>{const me=!D.current&&!ie;(T.value!==void 0&&T.value===ce||me)&&(Y(Z),me&&(D.current=!0))},[T.value]),H=b.useCallback(()=>k==null?void 0:k.focus(),[k]),Q=b.useCallback((Z,ce,ie)=>{const me=!D.current&&!ie;(T.value!==void 0&&T.value===ce||me)&&G(Z)},[T.value]),ne=r==="popper"?P1:hF,te=ne===P1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:h,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(dF,{scope:n,content:k,viewport:I,onViewportChange:R,itemRefCallback:X,selectedItem:z,onItemLeave:H,itemTextRefCallback:Q,focusSelectedItem:B,selectedItemText:W,position:r,isPositioned:N,searchRef:j,children:m.jsx(Sm,{as:Ede,allowPinchZoom:!0,children:m.jsx(xm,{asChild:!0,trapped:T.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:qt(i,Z=>{var ce;(ce=T.trigger)==null||ce.focus({preventScroll:!0}),Z.preventDefault()}),children:m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:m.jsx(ne,{role:"listbox",id:T.contentId,"data-state":T.open?"open":"closed",dir:T.dir,onContextMenu:Z=>Z.preventDefault(),...x,...te,onPlaced:()=>L(!0),ref:M,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:qt(x.onKeyDown,Z=>{const ce=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!ce&&Z.key.length===1&&V(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let me=O().filter(ge=>!ge.disabled).map(ge=>ge.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(me=me.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ge=Z.target,ve=me.indexOf(ge);me=me.slice(ve+1)}setTimeout(()=>P(me)),Z.preventDefault()}})})})})})})});fF.displayName=Sde;var Cde="SelectItemAlignedPosition",hF=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=mc(pu,n),o=gc(pu,n),[l,u]=b.useState(null),[d,f]=b.useState(null),h=dr(t,M=>f(M)),v=Vb(n),g=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:T}=o,k=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const M=s.trigger.getBoundingClientRect(),z=d.getBoundingClientRect(),Y=s.valueNode.getBoundingClientRect(),W=x.getBoundingClientRect();if(s.dir!=="rtl"){const ge=W.left-z.left,ve=Y.left-ge,Te=M.left-ve,Xe=M.width+Te,wt=Math.max(Xe,z.width),et=window.innerWidth-No,ft=xI(ve,[No,Math.max(No,et-wt)]);l.style.minWidth=Xe+"px",l.style.left=ft+"px"}else{const ge=z.right-W.right,ve=window.innerWidth-Y.right-ge,Te=window.innerWidth-M.right-ve,Xe=M.width+Te,wt=Math.max(Xe,z.width),et=window.innerWidth-No,ft=xI(ve,[No,Math.max(No,et-wt)]);l.style.minWidth=Xe+"px",l.style.right=ft+"px"}const G=v(),O=window.innerHeight-No*2,N=w.scrollHeight,L=window.getComputedStyle(d),D=parseInt(L.borderTopWidth,10),P=parseInt(L.paddingTop,10),B=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),U=D+P+N+F+B,j=Math.min(S.offsetHeight*5,U),V=window.getComputedStyle(w),X=parseInt(V.paddingTop,10),H=parseInt(V.paddingBottom,10),Q=M.top+M.height/2-No,ne=O-Q,te=S.offsetHeight/2,Z=S.offsetTop+te,ce=D+P+Z,ie=U-ce;if(ce<=Q){const ge=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const ve=d.clientHeight-w.offsetTop-w.offsetHeight,Te=Math.max(ne,te+(ge?H:0)+ve+B),Xe=ce+Te;l.style.height=Xe+"px"}else{const ge=G.length>0&&S===G[0].ref.current;l.style.top="0px";const Te=Math.max(Q,D+w.offsetTop+(ge?X:0)+te)+ie;l.style.height=Te+"px",w.scrollTop=ce-Q+w.offsetTop}l.style.margin=`${No}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]);rs(()=>k(),[k]);const[A,I]=b.useState();rs(()=>{d&&I(window.getComputedStyle(d).zIndex)},[d]);const R=b.useCallback(M=>{M&&_.current===!0&&(k(),T==null||T(),_.current=!1)},[k,T]);return m.jsx(Tde,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:R,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:m.jsx(Sn.div,{...i,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});hF.displayName=Cde;var kde="SelectPopperPosition",P1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=No,...s}=e,o=Kb(n);return m.jsx(Hb,{...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)"}})});P1.displayName=kde;var[Tde,Yk]=Ef(pu,{}),I1="SelectViewport",pF=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=gc(I1,n),o=Yk(I1,n),l=dr(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(Yb.Slot,{scope:n,children:m.jsx(Sn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:qt(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:h,shouldExpandOnScrollRef:v}=o;if(v!=null&&v.current&&h){const g=Math.abs(u.current-f.scrollTop);if(g>0){const _=window.innerHeight-No*2,w=parseFloat(h.style.minHeight),S=parseFloat(h.style.height),x=Math.max(w,S);if(x<_){const T=x+g,k=Math.min(_,T),A=T-k;h.style.height=k+"px",h.style.bottom==="0px"&&(f.scrollTop=A>0?A:0,h.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});pF.displayName=I1;var mF="SelectGroup",[Rde,Ade]=Ef(mF),Nde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bi();return m.jsx(Rde,{scope:n,id:i,children:m.jsx(Sn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});Nde.displayName=mF;var gF="SelectLabel",Mde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Ade(gF,n);return m.jsx(Sn.div,{id:i.id,...r,ref:t})});Mde.displayName=gF;var Ky="SelectItem",[Pde,vF]=Ef(Ky),yF=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=mc(Ky,n),u=gc(Ky,n),d=l.value===r,[f,h]=b.useState(s??""),[v,g]=b.useState(!1),_=dr(t,T=>{var k;return(k=u.itemRefCallback)==null?void 0:k.call(u,T,r,i)}),w=bi(),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(Pde,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(T=>{h(k=>k||((T==null?void 0:T.textContent)??"").trim())},[]),children:m.jsx(Yb.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(Sn.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:qt(o.onFocus,()=>g(!0)),onBlur:qt(o.onBlur,()=>g(!1)),onClick:qt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:qt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:qt(o.onPointerDown,T=>{S.current=T.pointerType}),onPointerMove:qt(o.onPointerMove,T=>{var k;S.current=T.pointerType,i?(k=u.onItemLeave)==null||k.call(u):S.current==="mouse"&&T.currentTarget.focus({preventScroll:!0})}),onPointerLeave:qt(o.onPointerLeave,T=>{var k;T.currentTarget===document.activeElement&&((k=u.onItemLeave)==null||k.call(u))}),onKeyDown:qt(o.onKeyDown,T=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&T.key===" "||(gde.includes(T.key)&&x(),T.key===" "&&T.preventDefault())})})})})});yF.displayName=Ky;var hp="SelectItemText",bF=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=mc(hp,n),l=gc(hp,n),u=vF(hp,n),d=_de(hp,n),[f,h]=b.useState(null),v=dr(t,x=>h(x),u.onItemTextChange,x=>{var T;return(T=l.itemTextRefCallback)==null?void 0:T.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 rs(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(Sn.span,{id:u.textId,...s,ref:v}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Eu.createPortal(s.children,o.valueNode):null]})});bF.displayName=hp;var _F="SelectItemIndicator",wF=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return vF(_F,n).isSelected?m.jsx(Sn.span,{"aria-hidden":!0,...r,ref:t}):null});wF.displayName=_F;var O1="SelectScrollUpButton",xF=b.forwardRef((e,t)=>{const n=gc(O1,e.__scopeSelect),r=Yk(O1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return rs(()=>{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(EF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});xF.displayName=O1;var L1="SelectScrollDownButton",SF=b.forwardRef((e,t)=>{const n=gc(L1,e.__scopeSelect),r=Yk(L1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return rs(()=>{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(EF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});SF.displayName=L1;var EF=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=gc("SelectScrollButton",n),o=b.useRef(null),l=Vb(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),rs(()=>{var f;const d=l().find(h=>h.ref.current===document.activeElement);(f=d==null?void 0:d.ref.current)==null||f.scrollIntoView({block:"nearest"})},[l]),m.jsx(Sn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:qt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:qt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:qt(i.onPointerLeave,()=>{u()})})}),Ide="SelectSeparator",Ode=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(Sn.div,{"aria-hidden":!0,...r,ref:t})});Ode.displayName=Ide;var D1="SelectArrow",Lde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Kb(n),s=mc(D1,n),o=gc(D1,n);return s.open&&o.position==="popper"?m.jsx($b,{...i,...r,ref:t}):null});Lde.displayName=D1;var Dde="SelectBubbleInput",CF=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=dr(r,i),o=ule(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 h=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(h)}},[o,t]),m.jsx(Sn.select,{...n,style:{...n3,...n.style},ref:s,defaultValue:t})});CF.displayName=Dde;function kF(e){return e===""||e===void 0}function TF(e){const t=Do(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 RF(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=Bde(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 Bde(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var zde=rF,jde=sF,Fde=aF,Hde=lF,$de=cF,Ude=uF,Wde=pF,qde=yF,Yde=bF,Vde=wF,Kde=xF,Gde=SF,[Gb]=Xa("Tooltip",[fc]),Xb=fc(),AF="TooltipProvider",Xde=700,B1="tooltip.open",[Zde,Vk]=Gb(AF),NF=e=>{const{__scopeTooltip:t,delayDuration:n=Xde,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(Zde,{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})};NF.displayName=AF;var em="Tooltip",[Jde,Pm]=Gb(em),MF=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=Vk(em,e.__scopeTooltip),d=Xb(t),[f,h]=b.useState(null),v=bi(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,T]=tc({prop:r,defaultProp:i??!1,onChange:M=>{M?(u.onOpen(),document.dispatchEvent(new CustomEvent(B1))):u.onClose(),s==null||s(M)},caller:em}),k=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),A=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,S.current=!1,T(!0)},[T]),I=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,T(!1)},[T]),R=b.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{S.current=!0,T(!0),g.current=0},w)},[w,T]);return b.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),m.jsx(Cm,{...d,children:m.jsx(Jde,{scope:t,contentId:v,open:x,stateAttribute:k,trigger:f,onTriggerChange:h,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?R():A()},[u.isOpenDelayedRef,R,A]),onTriggerLeave:b.useCallback(()=>{_?I():(window.clearTimeout(g.current),g.current=0)},[I,_]),onOpen:A,onClose:I,disableHoverableContent:_,children:n})})};MF.displayName=em;var z1="TooltipTrigger",PF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Pm(z1,n),s=Vk(z1,n),o=Xb(n),l=b.useRef(null),u=dr(t,l,i.onTriggerChange),d=b.useRef(!1),f=b.useRef(!1),h=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),m.jsx(km,{asChild:!0,...o,children:m.jsx(Sn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:qt(e.onPointerMove,v=>{v.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:qt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:qt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:qt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:qt(e.onBlur,i.onClose),onClick:qt(e.onClick,i.onClose)})})});PF.displayName=z1;var Kk="TooltipPortal",[Qde,efe]=Gb(Kk,{forceMount:void 0}),IF=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Pm(Kk,t);return m.jsx(Qde,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};IF.displayName=Kk;var uf="TooltipContent",OF=b.forwardRef((e,t)=>{const n=efe(uf,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Pm(uf,e.__scopeTooltip);return m.jsx(xo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(LF,{side:i,...s,ref:t}):m.jsx(tfe,{side:i,...s,ref:t})})}),tfe=b.forwardRef((e,t)=>{const n=Pm(uf,e.__scopeTooltip),r=Vk(uf,e.__scopeTooltip),i=b.useRef(null),s=dr(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:h}=r,v=b.useCallback(()=>{l(null),h(!1)},[h]),g=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},T=sfe(x,S.getBoundingClientRect()),k=ofe(x,T),A=afe(w.getBoundingClientRect()),I=cfe([...k,...A]);l(I),h(!0)},[h]);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},T=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),k=!lfe(x,o);T?v():k&&(v(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,v]),m.jsx(LF,{...e,ref:s})}),[nfe,rfe]=Gb(em,{isInside:!1}),ife=Doe("TooltipContent"),LF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Pm(uf,n),d=Xb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(B1,f),()=>document.removeEventListener(B1,f)),[f]),b.useEffect(()=>{if(u.trigger){const h=v=>{const g=v.target;g!=null&&g.contains(u.trigger)&&f()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[u.trigger,f]),m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:h=>h.preventDefault(),onDismiss:f,children:m.jsxs(Hb,{"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(ife,{children:r}),m.jsx(nfe,{scope:n,isInside:!0,children:m.jsx(i3,{id:u.contentId,role:"tooltip",children:i||r})})]})})});OF.displayName=uf;var DF="TooltipArrow",BF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Xb(n);return rfe(DF,n).isInside?null:m.jsx($b,{...i,...r,ref:t})});BF.displayName=DF;function sfe(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 ofe(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 afe(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 lfe(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,h=u.x,v=u.y;f>r!=v>r&&n<(h-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function cfe(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),ufe(t)}function ufe(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 dfe=NF,ffe=MF,hfe=PF,pfe=IF,mfe=OF,gfe=BF;const zF=b.createContext(!1);function vfe({blocked:e,children:t}){return m.jsx(zF.Provider,{value:e,children:t})}function Im(){return b.useContext(zF)}function Zb({...e}){return m.jsx(dde,{"data-slot":"popover",...e})}function Jb({...e}){return m.jsx(fde,{"data-slot":"popover-trigger",...e})}function Qb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=Im();return m.jsx(hde,{children:m.jsx(pde,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:o||r?!0:void 0,"aria-disabled":o?!0:i,"data-relay-interaction-blocked":o?"true":void 0,...s})})}const SI=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,EI=dj,yfe=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return EI(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],h=s==null?void 0:s[d];if(f===null)return null;const v=SI(f)||SI(h);return i[d][v]}),l=n&&Object.entries(n).reduce((d,f)=>{let[h,v]=f;return v===void 0||(d[h]=v),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:h,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,h,v]:d},[]);return EI(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},bfe=yfe("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 ct({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?Ooe:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(bfe({variant:t,size:n,className:e})),...i})}function Cf({...e}){return m.jsx(Wue,{"data-slot":"dropdown-menu",...e})}function _fe({...e}){return m.jsx(Y4,{"data-slot":"dropdown-menu-portal",...e})}function kf({...e}){return m.jsx(que,{"data-slot":"dropdown-menu-trigger",...e})}function Tf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=Im();return m.jsx(Y4,{children:m.jsx(Yue,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:s||n?!0:void 0,"aria-disabled":s?!0:r,"data-relay-interaction-blocked":s?"true":void 0,...i})})}function ni({className:e,inset:t,variant:n="default",...r}){return m.jsx(Kue,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function k0({className:e,children:t,checked:n,...r}){return m.jsxs(Gue,{"data-slot":"dropdown-menu-checkbox-item",className:We("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(Xue,{children:m.jsx(da,{className:"size-4"})})}),t]})}function Dh({className:e,inset:t,...n}){return m.jsx(Vue,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Ul({className:e,...t}){return m.jsx(Zue,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}function wfe({...e}){return m.jsx(Jue,{"data-slot":"dropdown-menu-sub",...e})}function xfe({className:e,inset:t,children:n,...r}){return m.jsxs(Que,{"data-slot":"dropdown-menu-sub-trigger","data-inset":t,className:We("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-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_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(Yd,{className:"ml-auto size-4"})]})}function Sfe({className:e,...t}){return m.jsx(ede,{"data-slot":"dropdown-menu-sub-content",className:We("z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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),...t})}const Efe={"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 nu({variant:e,action:t}){const{heading:n,body:r}=Efe[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 Cfe={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},kfe={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function j1({status:e,className:t}){return m.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Cfe[e],t),role:"status","aria-label":kfe[e]})}function Mp({name:e,osName:t,className:n,nameClassName:r}){return m.jsxs("span",{className:We("min-w-0 flex-1",n),children:[m.jsx("span",{"data-slot":"proxy-name",className:We("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 Yi({...e}){return m.jsx(Ck,{"data-slot":"dialog",...e})}function Tfe({...e}){return m.jsx(kk,{"data-slot":"dialog-portal",...e})}function jF({...e}){return m.jsx(Db,{"data-slot":"dialog-close",...e})}function Rfe({className:e,...t}){return m.jsx(Tk,{"data-slot":"dialog-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Vi({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=Im();return m.jsxs(Tfe,{"data-slot":"dialog-portal",children:[m.jsx(Rfe,{}),m.jsxs(Rk,{"data-slot":"dialog-content",className:We("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus: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(Db,{"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(lc,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ki({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Gs({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(Db,{asChild:!0,children:m.jsx(ct,{variant:"outline",children:"Close"})})]})}function Oi({className:e,...t}){return m.jsx(P3,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function fs({className:e,...t}){return m.jsx(I3,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function Afe(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function Nfe({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(Yi,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Vi,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"移除离线开发机?"}),m.jsx(fs,{children:Afe(t)})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(ct,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(Gr,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const my=80,Mfe=8,Pfe=1.2;function CI(e){return Math.max(0,Math.min(my,e))}function Ife({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),[h,v]=b.useState(null),g=h??(i?my:0),_=h!==null;function w(k){var A,I;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?my:0,axis:"pending"};try{(I=(A=k.currentTarget).setPointerCapture)==null||I.call(A,k.pointerId)}catch{}}}function S(k){const A=d.current;if(!A||A.pointerId!==k.pointerId)return;const I=k.clientX-A.startX,R=k.clientY-A.startY;if(A.axis==="pending"){if(Math.hypot(I,R)<Mfe)return;A.axis=Math.abs(I)>Math.abs(R)*Pfe?"horizontal":"vertical"}A.axis!=="vertical"&&(k.preventDefault(),v(CI(A.startOffset-I)))}function x(k,A=!1){var M,z;const I=d.current;if(!I||I.pointerId!==k.pointerId)return;d.current=null;try{(z=(M=k.currentTarget).releasePointerCapture)==null||z.call(M,k.pointerId)}catch{}if(I.axis!=="horizontal"||A){v(null);return}k.preventDefault();const R=h??CI(I.startOffset-(k.clientX-I.startX));v(null),o(R>=my/2),f.current=!0,window.setTimeout(()=>{f.current=!1},0)}function T(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:T,children:[m.jsx(j1,{status:"offline"}),m.jsx(Mp,{name:u,osName:n}),r&&m.jsx(da,{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 FF({layout:e,variant:t="default"}){const n=Re(M=>M.proxies),r=Re(M=>M.proxyListLoaded),i=Re(M=>M.relayClientAuthIssue),s=Re(M=>M.selectedProxyId),o=Re(M=>M.proxySwitchTarget),l=hs(),u=ks(),[d,f]=b.useState(!1),[h,v]=b.useState(null),[g,_]=b.useState(null),[w,S]=b.useState(null);async function x(M,z){if(o)return;const Y=Bt;if(!Y){He.error("请先连接开发机");return}const W=z??M,G=s!==null&&s!==M;Re.getState().setProxySwitchTarget({proxyId:M,name:W});try{const O=await Y.selectProxy(M);if(!O.success){He.error(`无法连接 ${W}:${O.error??"未知错误"}`);return}const N=Y.getPreviewScope();if(!N||N.proxyId!==M||N.bindingId!==O.bindingId)throw Pt.dispose(),Y.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Pt.activate(Y,N),Pt.syncWebSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] web preview snapshot failed",L)}),Pt.syncDeviceSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] device preview snapshot failed",L)}),G&&(Ut.getState().prepareForProxySwitch(W),ii.getState().prepareForProxySwitch()),Ir("local",Tn.proxyId,M),Re.getState().setProxy(M,z??null),Re.getState().setProxyOnline(!0),Re.getState().transitionToPhase("session_browsing"),Y.sendControl({type:"session_list_request"}),Y.requestProxyInfo().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(Y,N))return;const D=ii.getState();D.setHomePath(L.homePath),D.setAgentCli(L.agentCli),Re.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Pt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),Y.requestAgentStatuses().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(Y,N))return;const D=Ut.getState();for(const P of L)D.setAgentStatus(P.sessionId,P.payload)}).catch(L=>{Pt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),fk(Y).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 N=O instanceof Error?O.message:"未知错误";He.error(`无法连接 ${W}:${N}`)}finally{Re.getState().setProxySwitchTarget(null)}}function T(M){M.online||w||(v(null),_({proxyId:M.proxyId,...M.name?{name:M.name}:{}}))}async function k(){const M=g;if(!M||w)return;const z=Bt;if(!z){He.error("Relay 连接不可用,请稍后重试");return}const Y=Re.getState().proxies.find(W=>W.proxyId===M.proxyId);if(!Y){if(!Re.getState().proxyListLoaded){He.info("正在重新连接 Relay,请稍后再试");return}Np(M.proxyId,z)&&u("/"),He.info("这台开发机已经不在列表中"),_(null);return}if(Y.online){He.warning("这台开发机已重新上线,未移除"),_(null);return}S(M.proxyId),Sse(M.proxyId);try{const W=await z.removeOfflineProxy(M.proxyId);if(W.success){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),He.success(`已移除 ${M.name??M.proxyId}`),_(null);return}if(W.errorCode===Or.PROXY_ONLINE){Dd(M.proxyId),He.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(W.errorCode===Or.PROXY_NOT_FOUND){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),He.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Dd(M.proxyId),He.error(W.error??"无法移除开发机,请重试")}catch(W){He.error(W instanceof Error?W.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const A=m.jsx(Nfe,{open:g!==null,target:g,removing:w!==null,onOpenChange:M=>{M||_(null)},onConfirm:()=>{k()}});if(e==="page")return i==="missing_client_token"?m.jsx(nu,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(nu,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(nu,{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(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=o!==null;return M.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":"true","data-selecting":z||void 0,disabled:Y||w!==null,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:We("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",M.osName?"h-14":"h-11",z?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",Y&&!z||w!==null?"opacity-50":""),"aria-pressed":s===M.proxyId,children:[m.jsx(j1,{status:"online"}),m.jsx(Mp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"正在连接"}),m.jsx(Gr,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===M.proxyId?m.jsx(da,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},M.proxyId):m.jsx(Ife,{proxyId:M.proxyId,name:M.name,osName:M.osName,selected:s===M.proxyId,revealed:h===M.proxyId,disabled:Y||w!==null,onRevealedChange:W=>v(W?M.proxyId:null),onRemove:()=>T(M)},M.proxyId)})})]}),A]}):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(Gr,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const I=n.find(M=>M.proxyId===s),R=(I==null?void 0:I.name)??(I==null?void 0:I.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Zb,{open:d,onOpenChange:f,children:[m.jsx(Jb,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex 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":`当前连接:${R}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx(Mp,{name:R,osName:I==null?void 0:I.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(ac,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(Qb,{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(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=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":M.proxyId,"data-online":M.online,"data-selecting":z||void 0,disabled:!M.online||Y,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:We("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",M.osName?"h-12":"h-9",z?"bg-accent text-accent-foreground":"hover:bg-accent",Y&&!z?"opacity-50":"",M.online?"":"opacity-50"),"aria-pressed":s===M.proxyId,title:M.online?void 0:"这台开发机离线",children:[m.jsx(j1,{status:M.online?"online":"offline"}),m.jsx(Mp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsx(Gr,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===M.proxyId?m.jsx(da,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!M.online&&!z&&m.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]}),!M.online&&m.jsxs(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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:Y||w!==null,"aria-label":`${M.name??M.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(wb,{"aria-hidden":"true"})})}),m.jsx(Tf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(ni,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:W=>{W.stopPropagation(),T(M)},children:[m.jsx(lj,{"aria-hidden":"true"}),"移除开发机"]})})]})]},M.proxyId)})})})]}),A]})}function Ofe({delayDuration:e=0,...t}){return m.jsx(dfe,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Rf({...e}){return m.jsx(ffe,{"data-slot":"tooltip",...e})}function Af({...e}){return m.jsx(hfe,{"data-slot":"tooltip-trigger",...e})}function Nf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(pfe,{children:m.jsxs(mfe,{"data-slot":"tooltip-content",sideOffset:t,className:We("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(gfe,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function vc({...e}){return m.jsx(Ck,{"data-slot":"sheet",...e})}function Lfe({...e}){return m.jsx(cle,{"data-slot":"sheet-trigger",...e})}function Dfe({...e}){return m.jsx(kk,{"data-slot":"sheet-portal",...e})}function Bfe({className:e,...t}){return m.jsx(Tk,{"data-slot":"sheet-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function yc({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=Im();return m.jsxs(Dfe,{children:[m.jsx(Bfe,{className:t}),m.jsxs(Rk,{"data-slot":"sheet-content",className:We("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:h=>{o==null||o(h),!(!s||h.defaultPrevented)&&(h.preventDefault(),h.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(Db,{"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(lc,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function ku({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function bc({className:e,...t}){return m.jsx(P3,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function e_({className:e,...t}){return m.jsx(I3,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}const zfe={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"},kI=["claude","codex","kimi","cursor"];function t_(e){return zfe[e]}function HF(e,t){return kI.indexOf(e)-kI.indexOf(t)}function Yl(e){return e.provider}const F1=60*1e3,H1=60*F1,jfe=24*H1;function $F(e,t=Date.now()){const n=t-e;if(n<F1)return"刚刚";if(n<H1)return`${Math.floor(n/F1)} 分钟前`;if(n<jfe)return`${Math.floor(n/H1)} 小时前`;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 $1={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 Ffe({session:e}){const t=$1[e.state];return m.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Hfe({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?$C:qC;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 $fe({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=ii(w=>w.homePath),l=e.lastActive,u=e.cwd,d=gk(e.name,o),f=vk(e,o),h=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),v=$F(l,n),g=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return m.jsxs("li",{className:We("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&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:[e.kind!=="terminal"&&m.jsx(Ffe,{session:e}),m.jsx("span",{className:"text-sm font-normal truncate flex-1",title:u,children:h})]}),m.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[m.jsx(Hfe,{mode:e.mode}),e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:t_(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:We("shrink-0",$1[e.state].text),children:$1[e.state].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(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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(wb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(ni,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(ni,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}const Ufe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAACIUlEQVRYw+2Wz2sTQRTHP7uzsUtAyB/RvyLiJadQYlE8CB6qePMP0IOUSKMFBS8einePgiB1KXvqbaGll/wB7b2NlDQ/3Nnt7sx4SLKQ2DS21s3BfGHYN294733nPd7bgQXmDOv9h4/rUSTf5BlU2KKx/urFJpA6Wp03Hj1eI45jwNxooE+fv/N87d5v329fv9SBLeDMcd1iHHZ/uJmVmUbDTJwZzHBjWxaWZYE10A2W4dnDu0T9Nk8f3CHsnvLkfpmwezpycBv46bhLLhuv6wOXxmCMQWt94VJKjcmj/aRea02SJMRxTBzHhGGIlDKjvvH2HYAAbPum035V2MbMmYA22ppUep7Hzs7OVKMgCG6OwKRie3ubWq3GysoKvu9n+t3d3X+TAaX10rTDarWayZVKZexsb28vk5VSSCmRUhJFEVJKer0eYRiSpila66kEnKuwTZKEfr/P8vIyh4eHHBwcUCgUSNP02hm4lIDv+5TLZU5OTjg6Ohr0+miEWhbGmL8KDuBMdsHq6iqe5wFQKpXodDpZwMswq5um2TtGjxseHx9TLBbHBsefOJ1FcGYJpJQ0m01arVauc8ABaLfb7O/vD39I+cKJooggCFBKzWcSnifJ3IJfOAkXBBYEFgRyH0TCFo36xuZLIYR7rRvYNkLYCCHQGrRKUUpd+tLsdjpbgAK0BdwCSsNnssjp4groAWfWsAwOUMixJBpIgJT/Hr8AJyImgbVGgskAAAAASUVORK5CYII=",Wfe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFFElEQVRYw+1Wa0xbZRh+SyPQwiE4nJCuuAFSSiezUrkVNcZdNF6SMcmmC/GHyzJ/GNmfTQmomIkil0SmgW3J5swcwwsyHMHoNrlE3cUREUbLraAUSsGxuBVaBpzv8zunPdcexg9/ypd8+S7n8jzv8z7few7Aavu/N5XS5iUXPkoGC7fGWNqV9pbrK9w7qFIAf3LKPXW4rPR90/z8vFoggdgnmBEjJIyIZueIGUUd0YGRXS8Ja5rMyXpDksnzdnXDYIiCAIbRkVGtFBwrg2OkDI7uBk7mZH1vzP0L5NUeJQKWAXs/xS1SEvXww6lyOFF1ECK1GhkJDhTxHSEkI4MkpFhCZIzfYPCSmLoUCTiGHZFc8p6ymkEXex9kPGyEkzXvAkVFi8BFaZB0kSo0NwrRMyRMZutsEAGSf9Z47km31i85hqvd/fx1Y0IcfF5TAlRUNA+MlpVelALZXlhYOJ1kTPeSVwZ5wNDT3UOx4ODP+dVuGxR/dExCorhwD7kawnvA7wOREnQwGc4DDKG4dYmM/JCXrpIqQDYtdpudYsERCpwVBE3fd0DRh3X8fdu3ZkBF6QE/ieWkF58EFljYSzZZWPmZdwURmHCOa5Rc39TaDm+Vfcrfm7ctE6oOFbGvEKJdWj4tnAdITzXnesiDUgK/jGMdwaRGHA4K5EctEFljy0U42XBORCILqj94R0qCFo4eS4gB5g3onzP5Z4qQhAATPTFf6LzPqxbnVnC5f36o+ig0njvPk9jxdDa8tHOXQh1YkngBBwpQnD7BGxm1hg5SgCFgu95LKVY5lgzN9/cq62DcNcWTqCjeCxH6zEDUggmRiAQKqKN7wOBjos/PUHnkHjAwBUhe5eSFxpicAK0NdaDXxfIP/mabgPA1SZJCg2nBF6wJAyfAuMnq4eTnCXT+hQkwGFzjTo0ysP9lb+zdDa1naiXgX7R2Q2FlC/huDEkKDRKVYMwrsARpGZt5A4oVsHg8HvWka0IrjpZ7kIrQQP3Rcti/r4AH9szdYYHLj18Al70D/nG0CUWHFpVdWuhhYRo6Tp+8wB1BngAT/ejwsJbLuZBvBFufyILO7z6DbMsmieT5B8/Ajx3X4GZ/K8y5eyUngJvznkB++ZNSLUz0nl3ZKpecgMXed52SS1+8fw8cqSqBKCqCB6/7+gq8WtoIjr7LMGM7CynrYyAnMx2sWRbIzX6U9EzIzcmEx6xZEK/XCceQdH3CRp9Yfr61j+Jr214pup1sfRE/mL0dP19QiG0DDixuE9O3cP6BerxxRyXWm5/FaxPMuLevH6/Uag5/gkPU92BQqfCb1S0DX17GL4uxQ9pGsIUpfJPjTi1nmNO1ZZBqSORvam63s5L3/PE73OxrgoXbLtaID5lSVvzlytmcB7FpL7Ayp+c+x6RgUEKAOX6OwQGtzzun5qTnJOeMVlJ7HtxDv8Kt0TagF31sXsfGxqC3z74igYE//4bw6HWgW29kvn5A8i9JgeonB65q+farnc3fnI7nFNhCjGfO2gLNncPgdI7BrPMSLM7NSEtqwOGxj+yG0Mi1dyUxM9QBxvjo6deKj58lBPZJCFwcxm1HPi5P67ryc4y/5vurF6jDQKUOh0UvAWaj5qpa4HyLSHCFBsn3EM0DvV56yvH4MwUVhMAxeQqomRvTocKn1H8S6DseWJx1B8BF33h5oRH9fC4HrtFSdJIpwyvPP6vAhSFcz9SB//h7HXSvQuuSy7/aVhvT/gWL3beQH5sGiAAAAABJRU5ErkJggg==",qfe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAEGUlEQVRYw+1XS2hcVRj+zus+5s5kJp2Oie8kBFqCSYYuBBEyYxooIhiL0oUKutKVjVMDughCceXCPjbShUUXLgStLakUXCROFIxSxbEJWPoIo26iY8m0TZqM6dzjYm7unXvPvZPp2hy43DPn/v/5v/P9j/MPsDP+74OELY688c2rwkx9rJmpwBcJ6SjJe7HSrEQkIAHKNTBuHORh8lxPHE89OOzpSxuQNqRte3P3qQO299v9ZvvlXBln3a5vggkzS0NOn9WtdEoxLm30ZODfVNqAlJBSAs6jAImYAxKE0GoYA1lhJresuwofvKyhN0Mwu0hx8sKdFgbaA8K4DhBSpCEAclyPN23SePdmGuEy+pjAxNOmSm07QJpcSLmO6bc7SwoAYXTkCWEKzed/3nRlRgc1TDxjbUuzH4jfTUyYRQDwARg5XEwxLdYTttHpmXXMLv7ryu4fNJDbU2/L38E5oRyEiTkFAAHJC6MjUvnEV6uYWdhw5SeffwBjQ+b2GRCgn2sxEJCSAgCEZpkWa3mKE+dvYebSuqtSGN+FsWHrnjKAaRZAqOoCyrUc46YbeFEnOj69goXfa67eked2Yyxr+XzcKhuYMMrnJmNVBQATZj6Y31GneO+zCpaWvZh462AXHknXHbAyEIRN/icUXI8X3UNvTZ4qzGcb6bddoWlsvrp+F9ebAADAvoej6oN0gTBhgBD6q1t1Pf+TPNestvzY1yVwZDyNvm7NVb+9VsP0d1chjYEW+hLc6ABAigoAQugw5bqqHCg0+4djeP1AJyzD897sxSUc/Wge1OoFk60zQBhJfFkQJQUAE2a+UX7DT27pQOHZ3Xhir+k79Yef/4iz399AIj3kAxvFAtetou/iA4DRyZ9STJg9/sDz5n1dHFOH0uhKeR67XK7g3VNF/F27H4l0f0j1CzMeB2XanAKAEJKnXAsEXoP+l0YSeDHX4Qu2Ty+UcPKL35C8bwDCoBFXtRN4W+sAuB4HgJICAIRmKdf9lGvA1KE0Bh/VfZS/eexrXF7W0dk9hL5uHU8OJBrGIN03pETpWhW/XF1x1px7pnHLqi6glOUIoT7Kxh+P+4zPXlzC0dM/gMX7YSUbRefU4f7IJuiVAw/hhakiKreajAmrfGaCVlUAXM8H/bW6UXeF3v/kW5ydX0Eys89XFVfX64ibLBLExloFQMYhmYMbiaLSfY29cylLmFAKzbn5m1i8Ukb5jz9x824nkpk9SmS/dmwBCfaP1yE6dEtI3F6r4cYdHZqOZv/PKQAIoXlKhVr9IHGlkgCMvTAi0uqvqo1l2REahIBnHACcBrcUBEBBSAoEoQUoWNPDmtJw4+rQrF3VMxO0FMZAyd6sgVDW3BcAlIGAARBuO95+n+/v9oWZBNcThZ1/QTsjbPwHmclZWfW3uBoAAAAASUVORK5CYII=";function Yfe({shell:e,label:t}){const n=e==="cmd"?Ufe:e==="powershell"?t==="Windows PowerShell"?qfe:Wfe:null;return n?m.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"size-5 shrink-0 object-contain",width:20,height:20,draggable:!1}):m.jsx(ou,{className:"size-5 text-muted-foreground","aria-hidden":"true"})}function bo(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 Vfe({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Kfe,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:$F(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:We("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(uV,{className:We("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Kfe({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(Gfe,{mode:t})]})}function Gfe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?$C:qC;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function UF({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(iG,{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 Xfe({now:e}){const t=ii(O=>O.homePath),n=Ut(O=>O.historySessions),r=Ut(O=>O.historyLoadStatus),[i,s]=b.useState(null),[o,l]=b.useState(null),[u,d]=b.useState("json"),[f,h]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(new Set),[S,x]=b.useState(new Set),T=ks(),k=b.useMemo(()=>{const O=new Map;for(const N of n){const L=Yl(N);let D=O.get(L);D||(D=new Map,O.set(L,D));const P=WF(N.projectDir),B=D.get(P);B?B.sessions.push(N):D.set(P,{dir:P,sessions:[N]})}return Array.from(O.entries()).sort(([N],[L])=>HF(N,L)).map(([N,L])=>({provider:N,sessions:Array.from(L.values()).flatMap(D=>D.sessions),projects:Array.from(L.values()).map(D=>({dir:D.dir,shortDir:Gp(D.dir,t,{compact:!0}),sessions:D.sessions}))}))},[n,t]);function A(O){l(O),d(Zfe(O)),h(Jfe(O))}async function I(O,N,L){if(i)return;const D=Bt;if(!D){He.error("请先连接开发机");return}s(O.id);const P=Yl(O);try{const B=await D.createSession({kind:"agent",cwd:O.projectDir,mode:N,provider:P,resumeSessionId:O.id,...L?{permissionMode:L}:{}});if(!B.success){if(B.errorCode===Or.SESSION_ALREADY_ACTIVE){Ut.getState().setCodexActiveWriterConflict({...B.activeWriterPid?{activeWriterPid:B.activeWriterPid}:{}}),l(null);return}He.error(`恢复失败:${B.error}`);return}if(B.kind!=="agent"){He.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},U=B.mode==="pty"?{...F,mode:"pty",ptyOwner:B.ptyOwner}:{...F,mode:"json"};Ut.getState().addSession(U),T(`/chat/${B.sessionId}?mode=${B.mode}`),l(null)}catch(B){He.error(`恢复失败:${B instanceof Error?B.message:String(B)}`)}finally{s(null)}}function R(){const O=Bt;!O||Ut.getState().historyLoadStatus==="loading"||fk(O).then(N=>{N.status==="failed"&&He.error(N.error instanceof Error?N.error.message:String(N.error))})}function M(O,N){const L=TI(O,N);x(D=>{const P=new Set(D);return P.has(L)?P.delete(L):P.add(L),P})}function z(O){w(N=>{const L=new Set(N);return L.has(O)?L.delete(O):L.add(O),L})}const Y=n.length>0,W=r==="loading",G=o?qF(Yl(o)):[];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:()=>Y&&g(O=>!O),disabled:!Y,"aria-expanded":Y?v:void 0,"data-slot":"history-section-header","data-expanded":v,className:We("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",Y?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),Y?m.jsx(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",v&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":W,title:W?"正在加载":"刷新",onClick:R,disabled:W,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(bm,{className:We("size-3.5",W&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!Y&&W&&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(Gr,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!Y&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!Y&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),Y&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!Y&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),Y&&v&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(O=>{const N=_.has(O.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>z(O.provider),"aria-expanded":!N,"data-slot":"history-provider-header","data-expanded":!N,className:We("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:t_(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(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!N&&"rotate-90"),"aria-hidden":"true"})]}),!N&&m.jsx("ul",{role:"list",className:"flex flex-col",children:O.projects.map(L=>{const D=TI(O.provider,L.dir),P=S.has(D);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>M(O.provider,L.dir),"aria-expanded":P,"data-slot":"history-group-header","data-expanded":P,className:We("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[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(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",P&&"rotate-90"),"aria-hidden":"true"})]}),P&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(B=>m.jsx(Vfe,{session:B,now:e,disabled:i!==null,loading:i===B.id,onClick:()=>A(B),modeTag:B.preferredMode},B.id))})]},D)})})]},O.provider)})}),m.jsx(Qfe,{session:o,open:o!==null,modes:G,mode:u,permissionMode:f,submitting:i!==null,onOpenChange:O=>{O||l(null)},onModeChange:O=>{d(O),O==="json"&&o&&Yl(o)==="cursor"&&f==="auto"&&h("default")},onPermissionModeChange:h,onConfirm:()=>{o&&I(o,u,f)}})]})}function TI(e,t){return`${e}:${WF(t)}`}function WF(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function qF(e){return["json","pty"]}function Zfe(e){const t=qF(Yl(e));return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"pty"}function Jfe(e){return Yl(e)==="codex"?"auto":"default"}function Qfe({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[f,h]=b.useState(!1),v=i==="bypassPermissions",g=bo("(min-width: 768px)"),_=e?Yl(e):null,w=_==="codex",S=_==="kimi",x=_==="cursor";b.useEffect(()=>{t||h(!1)},[t]);const T=f?m.jsx(UF,{providerLabel:e?t_(Yl(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(RI,{checked:r==="json",label:"聊天",icon:m.jsx($C,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(RI,{checked:r==="pty",label:"终端",icon:m.jsx(qC,{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(Tv,{checked:i==="default",label:S?"手工审批":x?"命令审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":x?"Cursor CLI 在执行命令前询问。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),!(x&&r==="json")&&m.jsx(Tv,{checked:i==="auto",label:w?"按需审批":S?"自动审批":x?"智能自动":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":x?"Cursor CLI 自动执行判定为安全的工具,其余仍会询问。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),(S||x)&&m.jsx(Tv,{checked:i==="plan",label:"只读规划",description:x?"Cursor CLI 使用只读规划模式。":"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(Tv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?h(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(ct,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(v&&!f){h(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return g?m.jsx(Yi,{open:t,onOpenChange:o,children:m.jsxs(Vi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Ki,{className:"min-w-0",children:[m.jsx(Oi,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(fs,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),T,m.jsx(Gs,{children:k})]})}):m.jsx(vc,{open:t,onOpenChange:o,children:m.jsxs(yc,{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(ku,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(bc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(e_,{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:T}),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:k})})]})})}function RI({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:We("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(da,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Tv({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:We("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:We("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:We("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(da,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function n_({...e}){return m.jsx(zde,{"data-slot":"select",...e})}function r_({...e}){return m.jsx(Fde,{"data-slot":"select-value",...e})}function i_({className:e,size:t="default",children:n,...r}){return m.jsxs(jde,{"data-slot":"select-trigger","data-size":t,className:We("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(Hde,{asChild:!0,children:m.jsx(ac,{className:"size-4 opacity-50"})})]})}function s_({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=Im();return m.jsx($de,{children:m.jsxs(Ude,{"data-slot":"select-content",className:We("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,inert:l||i?!0:void 0,"aria-disabled":l?!0:s,"data-relay-interaction-blocked":l?"true":void 0,...o,children:[m.jsx(ehe,{}),m.jsx(Wde,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(the,{})]})})}function o_({className:e,children:t,...n}){return m.jsxs(qde,{"data-slot":"select-item",className:We("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(Vde,{children:m.jsx(da,{className:"size-4"})})}),m.jsx(Yde,{children:t})]})}function ehe({className:e,...t}){return m.jsx(Kde,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(jC,{className:"size-4"})})}function the({className:e,...t}){return m.jsx(Gde,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(ac,{className:"size-4"})})}function nhe(e,t,n){var u;if(t==="insert"){const d=e.split("@").pop()??"",f=uu((n==null?void 0:n.baseCwd)??d)==="\\",h=Math.max(d.lastIndexOf("/"),f?d.lastIndexOf("\\"):-1);return{currentPath:h>=0?d.slice(0,h+1):f?".\\":"./",query:d.slice(h+1).toLowerCase()}}const r=aa((n==null?void 0:n.baseCwd)??"");if(!e)return{currentPath:Ys(r),query:""};const i=Tb(r,e);if(!i)return{currentPath:"",query:""};const s=uk(i),o=uu(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:Ys(i),query:""}:{currentPath:Ys(s),query:i.slice(i.lastIndexOf(o)+1).toLowerCase()}}function T0(e,t){return Tb(e,t)}const YF=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:h=!0,title:v},g){const _=ii(be=>f?be.treeWithHidden:be.tree),w=ii(be=>be.cwd),S=ii(be=>be.homePath),x=Re(be=>be.selectedProxyId),T=o==="insert"?w:S||w,k=b.useMemo(()=>new Set(_.keys()),[_]),A=b.useMemo(()=>nhe(t,o,{baseCwd:T,knownDirs:k}),[t,o,T,k]),I=A.currentPath,R=b.useMemo(()=>T0(T,I),[T,I]),M=A.query,z=b.useRef(new Map),[Y,W]=b.useState(!1),[G,O]=b.useState(""),[N,L]=b.useState(!1),[D,P]=b.useState(null),[B,F]=b.useState(0),[U,j]=b.useState(!1),[V,X]=b.useState(null),[H,Q]=b.useState(null);b.useEffect(()=>{if(!U)return;let be=!1;X(null),Q(null);const rt=Bt==null?void 0:Bt.requestFileSystemRoots();return rt||Q("尚未连接开发机"),rt==null||rt.then($e=>{be||($e.error!==void 0||$e.errorCode!==void 0?Q($e.error||"读取失败"):X($e.roots))},$e=>{be||Q($e instanceof Error?$e.message:"读取失败")}),()=>{be=!0}},[U,x,B]),b.useEffect(()=>{if(!R||U)return;const be=`${x}\0${f?"hidden":"default"}\0${R}`;if(_.has(R))return;const rt=Bt;if(!rt)return;let $e=!1;P(Ze=>(Ze==null?void 0:Ze.path)===R?null:Ze);let Ae=z.current.get(be);if(!Ae){Ae=rt.requestDirectoryList(R,{includeHidden:f}),z.current.set(be,Ae);const Ze=()=>{z.current.get(be)===Ae&&z.current.delete(be)};Ae.then(Ze,Ze)}return Ae.then(Ze=>{if(!$e){if(Ze.error!==void 0||Ze.errorCode!==void 0){P({path:R,message:Ze.error||"读取失败"});return}ii.getState().setDirEntries(Ze.path,Ze.entries,Ze.includeHidden)}},Ze=>{$e||P({path:R,message:Ze instanceof Error?Ze.message:"读取失败"})}),()=>{$e=!0}},[R,f,_,B,U,x]);const ne=U?H?{message:H}:null:(D==null?void 0:D.path)===R?D:null,te=U?V===null&&!H:!_.has(R)&&!ne,Z=b.useMemo(()=>d==null?void 0:d.map(be=>be.startsWith(".")?be.toLowerCase():`.${be.toLowerCase()}`),[d]),ce=b.useMemo(()=>{if(U){if(!V)return[];const rt=[...S?[{name:"主目录",path:S}]:[],...V];return[...new Map(rt.map($e=>[$e.path,$e])).values()].map($e=>({...$e,isDir:!0}))}let be=_.get(R)??[];return u?be=be.filter(rt=>rt.isDir):Z!=null&&Z.length&&(be=be.filter(rt=>rt.isDir||Z.some($e=>rt.name.toLowerCase().endsWith($e)))),M&&(be=be.filter(rt=>rt.name.toLowerCase().includes(M))),be},[_,R,M,u,Z,U,V,S]),[ie,me]=b.useState(h?0:-1);b.useEffect(()=>me(h?0:-1),[h,I,M,U]),b.useEffect(()=>{W(!1),O("")},[R]),b.useEffect(()=>{ie>=ce.length&&ce.length>0&&me(ce.length-1)},[ce.length,ie]);const ge=b.useRef(null),ve=b.useRef(!1);b.useEffect(()=>{var rt;if(!ve.current)return;ve.current=!1;const be=(rt=ge.current)==null?void 0:rt.querySelector(`[data-entry-index="${ie}"]`);be==null||be.scrollIntoView({block:"nearest"})},[ie]);const Te=b.useCallback(be=>{const rt=uu(T),$e=`${Ys(I,T)}${be.name}${be.isDir?rt:""}`;if(o==="insert")return $e.replace(rt==="\\"?/^\.[\\/]/:/^\.\//,"");const Ae=T0(T,$e);return be.isDir?Ys(Ae):Ae},[T,I,o]),Xe=b.useCallback(be=>{const rt=T0(T,be);if(!rt)return;j(!1);const $e=Ys(rt);if(o==="select"){r($e);return}n($e)},[T,o,r,n]),wt=b.useCallback(be=>{if(be.path){Xe(be.path);return}const rt=Te(be);if(be.isDir){Xe(rt);return}n(rt)},[Te,Xe,n]);async function et(){const be=C2(R,G);if(!(!be||!s)){L(!0);try{const rt=await s(be);if(!rt)return;if(O(""),W(!1),i){i(Ys(rt));return}Xe(rt)}finally{L(!1)}}}b.useImperativeHandle(g,()=>({handleKey(be){return ce.length===0?!1:be.key==="ArrowDown"?(ve.current=!0,me(rt=>Math.min(ce.length-1,rt+1)),!0):be.key==="ArrowUp"?(ve.current=!0,me(rt=>Math.max(0,rt-1)),!0):be.key==="Enter"&&ie>=0&&!be.nativeEvent.isComposing?(wt(ce[ie]),!0):!1}}),[ce,ie,wt]);const ft=b.useMemo(()=>uk(R),[R]),Ne=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",Ue=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:Ne,"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:U?void 0:R,children:U?"磁盘/挂载点":Gp(R,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.jsxs("span",{className:"flex items-center gap-4",children:[m.jsx("button",{type:"button","aria-pressed":U,className:"inline-flex min-h-11 min-w-11 items-center justify-start px-0 text-left text-xs font-medium text-primary hover:underline focus-visible:underline md:min-h-8 md:min-w-0",onClick:()=>{j(be=>!be),W(!1)},children:U?"返回目录":"磁盘/挂载点"}),U?null: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:!R,onClick:()=>{R===ft?j(!0):Xe(ft)},children:"上一级"})]}),!U&&(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-end px-0 text-right 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:!R||N,onClick:()=>W(be=>!be),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-end px-0 text-right 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:!R,onClick:()=>i(Ys(R)),children:"选定"}):null]}):null]}),Y&&!U?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:G,onChange:be=>O(be.target.value),onKeyDown:be=>{be.key==="Enter"&&!be.nativeEvent.isComposing&&(be.preventDefault(),et()),be.key==="Escape"&&(W(!1),O(""))},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:!C2(R,G)||N,onClick:()=>{et()},children:N?"创建中...":"创建目录"})]}):null]}):m.jsxs("div",{className:"flex items-center gap-3 border-b border-border/70 px-3",children:[m.jsx("button",{type:"button","aria-pressed":U,className:"inline-flex min-h-11 min-w-11 shrink-0 items-center justify-start px-0 text-left text-xs font-medium text-primary hover:underline md:min-h-8 md:min-w-0",onClick:()=>j(be=>!be),children:U?"返回目录":"磁盘/挂载点"}),m.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:U?"磁盘/挂载点":Gp(R,S)})]}),m.jsx("div",{className:Ue,"data-slot":"file-path-picker-entries",children:ne?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:ne.message,children:U?"无法读取磁盘位置":"无法读取这个文件夹"}),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:()=>F(be=>be+1),children:"重试"})]}):ce.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:te?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:ge,role:"list",className:"flex flex-col",children:ce.map((be,rt)=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>wt(be),onMouseEnter:()=>me(rt),className:We("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",rt===ie&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",be.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":be.isDir?"dir":"file","data-entry-name":be.name,"data-entry-index":rt,title:be.path,children:[m.jsxs("span",{className:"min-w-0 truncate font-mono text-[13px]",children:[be.name,be.isDir&&!be.path?"/":""]}),be.path&&be.path!==be.name?m.jsx("span",{className:"ml-auto min-w-0 truncate text-xs font-normal text-muted-foreground",children:be.path}):null]})},be.path??be.name))})})]})});function AI(e,t,n){const r=pp(e,t);return r?n==="file"?Ys(uk(r)):n==="directory"?Ys(r):r:t}function pp(e,t){const n=aa(e,t);return n?e.endsWith("/")||uu(n)==="\\"&&e.endsWith("\\")?Ys(n):n:""}function Gk({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:h,required:v,autoFocus:g,"aria-describedby":_,"aria-invalid":w,"data-slot":S,className:x,onKeyDown:T}){const k=b.useId(),A=f??`remote-path-${k}`,I=`${A}-label`,R=ii(te=>te.homePath),M=bo("(pointer: coarse), (hover: none)"),z=bf().deviceKind,Y=M||z==="phone"||z==="tablet",[W,G]=b.useState(!1),[O,N]=b.useState(()=>AI(e,R,n)),[L,D]=b.useState(e),P=b.useRef(null),B=b.useRef(null),F=b.useRef(null);b.useEffect(()=>{W||document.activeElement===B.current||L===e||D(e)},[L,W,e]),b.useEffect(()=>{if(!W)return;function te(Z){const ce=P.current,ie=Z.target;ce&&(Z.composedPath().includes(ce)||ie instanceof Node&&ce.contains(ie))||(G(!1),D(e))}return document.addEventListener("click",te),()=>document.removeEventListener("click",te)},[W,e]),b.useEffect(()=>{o&&(G(!1),D(e))},[o,e]);const U=n!=="file";function j(){if(o)return;const te=AI(e,R,n);N(te),D(e),G(!0)}function V(){G(!1),D(e)}function X(te){const Z=pp(te,R);Z&&(N(Z),D(Z),t(Z),G(!1))}function H(te){const Z=pp(te,R);Z&&N(Z)}function Q(te){var Z;if(W&&((Z=F.current)!=null&&Z.handleKey(te))){te.preventDefault();return}if(te.key==="Escape"&&W){te.preventDefault(),V();return}T==null||T(te)}const ne=W?m.jsx("div",{className:We(Y&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(YF,{ref:F,mode:"select",placement:Y?"inline":"floating",filter:O,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!Y,title:l,onNavigate:H,onSelect:X,onSelectCurrentDirectory:U?X:void 0,onCreateDirectory:s})}):null;return m.jsxs("div",{className:We("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:I,className:"min-w-0 text-sm",children:u}),d?m.jsx("div",{className:"flex shrink-0 items-center gap-4",children:d}):null]}),m.jsxs("div",{ref:P,className:"relative min-w-0",onBlur:te=>{if(!W||Y)return;const Z=te.relatedTarget;Z instanceof Node&&te.currentTarget.contains(Z)||window.setTimeout(()=>{var ce;(ce=P.current)!=null&&ce.contains(document.activeElement)||V()},0)},children:[m.jsxs("div",{className:"relative flex min-w-0 items-center",children:[m.jsx("input",{ref:B,id:A,type:"text","aria-labelledby":I,"aria-describedby":_,"aria-invalid":w,name:h,required:v,autoFocus:g&&!Y,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:()=>{Y?G(!1):j()},onBlur:()=>D(e),onKeyDown:Q,onChange:te=>{const Z=te.target.value,ce=pp(Z,R);D(Z),N(ce||R),t(ce||Z),G(!Y)},onPaste:te=>{const Z=te.clipboardData.getData("text").trim(),ce=Z.startsWith('"')&&Z.endsWith('"')?Z.slice(1,-1):Z,ie=pp(ce,R);ie&&(te.preventDefault(),D(ie),N(ie),t(ie),G(!Y))},placeholder:l,className:"min-h-11 min-w-0 w-full rounded-md border border-border bg-input pl-3 pr-12 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"}),m.jsx("button",{type:"button","aria-label":typeof u=="string"?`浏览${u}`:"浏览路径","aria-expanded":W,"aria-controls":`${A}-browser`,disabled:o,"data-slot":"remote-path-browse",onClick:()=>{var te;Y&&((te=B.current)==null||te.blur()),W?V():j()},className:"absolute inset-y-0 right-0 flex w-11 items-center justify-center rounded-r-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",children:m.jsx(sK,{className:"size-5","aria-hidden":"true"})})]}),m.jsx("div",{id:`${A}-browser`,children:ne})]})]})}const NI="工作目录不存在或不可访问:",rhe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],VF=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],KF=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],Xk=[{value:"default",label:"命令审批"},{value:"auto",label:"智能自动"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],GF=Xk.filter(e=>e.value!=="auto"),tm={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"};function ihe(e,t){return t!==Or.PATH_NOT_FOUND||!e.startsWith(NI)?null:e.slice(NI.length).trim()||null}function XF(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:n.notReported?{label:"未上报",disabled:!0,title:n.error}:{label:"未找到",disabled:!0,title:n.error}}function she(e,t,n="pty"){return e==="codex"?VF.some(r=>r.value===t)?t:"auto":e==="kimi"?KF.some(r=>r.value===t)?t:"default":e==="cursor"?(n==="json"?GF:Xk).some(i=>i.value===t)?t:"default":t}async function ohe({relay:e,agentCli:t,form:n,timeoutMs:r=lk}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(XF(n.provider,t).disabled){const h=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:h?`${tm[n.provider]} 不可用:${h}`:`${tm[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const h=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(!h.success){const w=ihe(h.error,h.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${h.error}`}}if(h.kind!=="agent")return{type:"create_error",message:"创建失败:开发机返回了错误的会话类型"};const v=((f=h.name)==null?void 0:f.trim())||void 0,g={sessionId:h.sessionId,kind:"agent",name:v,...h.nameLocked!==void 0?{nameLocked:h.nameLocked}:{},state:"idle",cwd:h.cwd,lastActive:h.lastActive,provider:h.provider};return{type:"success",session:h.mode==="pty"?{...g,mode:"pty",ptyOwner:h.ptyOwner}:{...g,mode:"json"},route:`/chat/${h.sessionId}?mode=${h.mode}`}}catch(h){return{type:"exception",message:h instanceof Error?h.message:String(h)}}}async function ahe({relay:e,shell:t,timeoutMs:n=lk}){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.shellFamily!==void 0?{shellFamily:i.shellFamily}:{},...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 lhe=["claude","codex","kimi","cursor"];function che({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)??"",h=n===t,v=h?r:f,g=h&&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(n_,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(i_,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(r_,{})}),m.jsx(s_,{"data-slot":"agent-cli-provider-options",children:lhe.map(_=>m.jsx(o_,{value:_,className:"min-h-11 md:min-h-0",children:tm[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(Gk,{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"&&h&&(_.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 mp(e){const t=Re(r=>r.selectedProxyId),n=Re(r=>r.relayUrl);return m.jsx(uhe,{...e,proxyId:t,relayUrl:n},JSON.stringify([n,t]))}function uhe({open:e,onOpenChange:t,proxyId:n,relayUrl:r}){var ge;const[i,s]=b.useState(""),[o,l]=b.useState(""),[u,d]=b.useState("claude"),[f,h]=b.useState("pty"),[v,g]=b.useState("default"),[_,w]=b.useState(!1),[S,x]=b.useState(!1),[T,k]=b.useState(null),[A,I]=b.useState(null),[R,M]=b.useState(""),[z,Y]=b.useState(!1),W=b.useRef(e);W.current=e;const G=ks(),O=ii(ve=>ve.homePath),N=ii(ve=>ve.agentCli),L=bo("(min-width: 768px)"),D=b.useRef(!0);b.useEffect(()=>(D.current=!0,()=>{D.current=!1}),[]);const P=b.useCallback(()=>{const ve=Re.getState();return D.current&&ve.selectedProxyId===n&&ve.relayUrl===r},[n,r]);b.useEffect(()=>{e&&!o&&O&&l(O)},[e,O,o]),b.useEffect(()=>{if(!e||O&&N)return;const ve=Bt==null?void 0:Bt.requestProxyInfo();if(!ve)return;let Te=!0;return ve.then(Xe=>{if(!Te||!P())return;const wt=ii.getState();wt.setHomePath(Xe.homePath),wt.setAgentCli(Xe.agentCli)}).catch(Xe=>{!Te||!P()||console.error("[create-session-dialog] requestProxyInfo failed",Xe)}),()=>{Te=!1}},[e,O,N,P]);function B(){s(""),l(""),d("claude"),h("pty"),g("default"),w(!1),k(null),I(null),M(""),Y(!1)}function F(){if(v==="bypassPermissions"){w(!0);return}ne()}async function U(){await ne(),P()&&W.current&&w(!1)}const j=u==="codex"?VF:u==="kimi"?KF:u==="cursor"?f==="json"?GF:Xk:rhe,V=XF(u,N),X=A===u&&R.trim()!==(((ge=N==null?void 0:N[u])==null?void 0:ge.command)??""),H=S||z||V.disabled||X;function Q(ve,Te=f){const Xe=she(ve,v,Te);Xe!==v&&g(Xe)}async function ne(ve){k(null),x(!0);try{const Te=await ohe({relay:Bt,agentCli:N,form:{cwd:ve??o,name:i,provider:u,permissionMode:v,mode:f}});if(!P())return;if(Te.type==="success"){if(Ut.getState().addSession(Te.session),!W.current)return;t(!1),B(),G(Te.route);return}if(Te.type==="missing_cwd"&&k(Te.path),He.error(Te.message),Te.type==="validation_error"||Te.type==="relay_missing")return}finally{P()&&x(!1)}}async function te(ve){const Te=Bt;if(!Te)return He.error("请先连接开发机"),null;try{const Xe=await Te.createDirectory(ve);return P()?Xe.success?(k(null),He.success("目录已创建"),Xe.path):(He.error(`目录创建失败:${Xe.error??"未知错误"}`),null):null}catch(Xe){return P()&&He.error(Xe instanceof Error?Xe.message:String(Xe)),null}}function Z(ve,Te){I(ve),M(Te)}async function ce(){if(!A)return;const ve=A,Te=R.trim();if(!Te){He.error("请选择 Agent CLI 可执行文件");return}const Xe=Bt;if(!Xe){He.error("请先连接开发机");return}Y(!0);try{const wt=await Xe.updateAgentCliPath(ve,Te);if(!P())return;if(wt.error||!wt.agentCli){He.error(`路径保存失败:${wt.error??"未知错误"}`);return}ii.getState().setAgentCli(wt.agentCli),He.success(`${tm[ve]} 路径已保存`),I(null),M("")}catch(wt){if(!P())return;He.error(wt instanceof Error?wt.message:String(wt))}finally{P()&&Y(!1)}}function ie(ve){h(ve),Q(u,ve)}const me=_?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(UF,{providerLabel:tm[u]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>w(!1),disabled:S,children:"返回"}),m.jsx(ct,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>{U()},disabled:S,"data-slot":"bypass-permission-confirm",children:S?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:ve=>{ve.preventDefault(),F()},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:i,onChange:ve=>s(ve.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(Gk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:o,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:te,onValueChange:ve=>{l(ve),k(null)}}),T?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:T})]}):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:We("grid min-w-0 gap-2","grid-cols-1 sm:grid-cols-2"),children:[m.jsxs("button",{type:"button","aria-pressed":f==="pty",onClick:()=>ie("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",f==="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":f==="json",onClick:()=>ie("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",f==="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(che,{agentCli:N,provider:u,cliPathDraftProvider:A,cliPathDraft:R,savingCliPath:z,onProviderChange:ve=>{d(ve),Q(ve),I(null),M("")},onCliPathDraftChange:Z,onDiscardCliPathDraft:()=>{I(null),M("")},onSaveCliPath:()=>{ce()}}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(n_,{value:v,onValueChange:ve=>g(ve),children:[m.jsx(i_,{className:"w-full",children:m.jsx(r_,{})}),m.jsx(s_,{children:j.map(ve=>m.jsx(o_,{value:ve.value,children:ve.label},ve.value))})]})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:S,children:"取消"}),m.jsx(ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:H,children:S?"创建中...":"创建"})]})]});return L?m.jsx(Yi,{open:e,onOpenChange:t,children:m.jsxs(Vi,{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(Ki,{children:m.jsx(Oi,{children:_?"跳过全部审批?":"新建会话"})}),me]})}):m.jsx(vc,{open:e,onOpenChange:t,children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(bc,{children:_?"跳过全部审批?":"新建会话"})}),me]})})}function gp({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,h]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),h(!1))},[s,e]);async function v(g){g.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){h(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{h(!1)}}}return m.jsx(Yi,{open:e,onOpenChange:r,children:m.jsx(Vi,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>{v(g)},children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"重命名会话"}),m.jsx(fs,{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:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled: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(Gs,{children:[m.jsx(ct,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(ct,{type:"submit",disabled:f,children:"保存"})]})]})})})}function dhe(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function fhe(e){return(e==null?void 0:e.kind)==="terminal"}function hhe(e){return dhe(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code/Cursor CLI 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:fhe(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function Rv({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=hhe(t);function s(){t&&(r(t),n(!1))}return m.jsx(Yi,{open:e,onOpenChange:n,children:m.jsxs(Vi,{"data-slot":"session-termination-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:i.title}),m.jsx(fs,{children:i.description})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(ct,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function ZF(e){var t,n,r,i,s,o,l,u,d,f,h,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"||((h=e.agentStatus)==null?void 0:h.phase)==="outputting"||((v=e.ptyState)==null?void 0:v.state)==="working"?"working":"idle"}function phe(e){if(e.session.state==="error")return"error";const t=ZF(e);return t==="disconnected"?e.session.state:t}const mhe=new Set(["localhost","127.0.0.1","[::1]"]),U1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function ghe(){return Ii("local",Tn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function JF(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function R0(e,t){var n;return((n=JF(e,t))==null?void 0:n.available)===!0}function vhe(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!mhe.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Bh(){return{status:"idle"}}function yhe({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(ghe),[o,l]=b.useState("local"),[u,d]=b.useState(""),[f,h]=b.useState(""),[v,g]=b.useState(""),[_,w]=b.useState(Bh),[S,x]=b.useState(!1),T=b.useRef(null),k=b.useRef(null),A=b.useRef(null),I=b.useRef(null),R=b.useRef(i);R.current=i;const M=b.useRef(e);M.current=e;const z=bo("(min-width: 768px)"),Y=Re(te=>te.selectedProxyId),W=Yr(te=>te.capability),G=Yr(te=>te.capabilityStatus),O=Yr(te=>te.capabilityError),N=Yr(te=>{var Z;return((Z=te.authoritative)==null?void 0:Z.scope)??null}),L=N?`${N.proxyId}\0${N.bindingId}`:null,D=b.useCallback(te=>{R.current=te,s(te),Ir("local",Tn.webPreviewTunnelProvider,te)},[]);function P(){var te,Z;r(""),l("local"),d(""),h(""),g(""),w(Bh()),x(!1),(te=T.current)==null||te.abort(),T.current=null,(Z=k.current)==null||Z.abort(),k.current=null,A.current=null,I.current=null}const B=b.useCallback(async te=>{var ie;(ie=T.current)==null||ie.abort();const Z=new AbortController;T.current=Z;const ce=Pt.getActiveScope();if(!(!ce||ce.proxyId!==Y))try{const me=await Pt.requestWebPreviewCapability(ce,te,{signal:Z.signal});if(!me||Z.signal.aborted||!M.current||!me.success)return;const ge=R.current,ve=ge==="cloudflare"?"cpolar":"cloudflare";!R0(me.capability,ge)&&R0(me.capability,ve)&&D(ve)}catch{}},[D,Y]);function F(te){!te&&S||t(te)}b.useEffect(()=>{if(!e){P();return}return B(!1),()=>{var te;(te=T.current)==null||te.abort(),T.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(Bh()),g("");return}const Z=new AbortController;k.current=Z,w({status:"loading"}),g("");const ce=window.setTimeout(()=>{const me=Bt,ge=Pt.getActiveScope();if(!me||!ge||ge.proxyId!==Y){w({status:"error",message:"请先连接开发机"});return}Pt.inspectStaticWebPreview(ge,te,{signal:Z.signal}).then(ve=>{if(!ve||Z.signal.aborted||!M.current||!Pt.isActive(me,ge))return;if(!ve.success){w({status:"error",message:ve.error});return}const Te=ve.htmlEntries;if(Te.length===0&&!ve.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const Xe={entryPath:ve.entryPath,htmlEntries:Te};w({status:"ready",path:te,result:Xe}),g(ve.entryPath??"")}).catch(ve=>{Z.signal.aborted||!M.current||ve instanceof Error&&ve.name==="AbortError"||!Pt.isActive(me,ge)||w({status:"error",message:ve instanceof Error?ve.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(ce),Z.abort(),k.current===Z&&(k.current=null)}},[e,L,Y,o,f]);const U=o==="local"?vhe(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||v),V=G==="loaded"&&R0(W,i),H=S||!V||!(o==="local"?U===null:j);async function Q(){var me,ge,ve;if(H)return;const te=Bt;if(!te){He.error("请先连接开发机");return}let Z;if(o==="local")Z={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const Te=_.result.entryPath??v;if(!Te)return;Z={kind:"static",path:_.path,entryPath:Te}}x(!0);const ce=Pt.getActiveScope();if(!ce){x(!1),He.error("请先连接开发机");return}let ie=null;try{const Te=n.trim(),Xe=JSON.stringify({proxyId:ce.proxyId,tunnelProvider:i,source:Z,name:Te||void 0});((me=A.current)==null?void 0:me.sourceKey)!==Xe&&(A.current={sourceKey:Xe,operationId:wm(`preview-operation-${i}`)}),ie=A.current.operationId,I.current=ie;const wt=await Pt.createWebPreview(ce,Z,{tunnelProvider:i,operationId:ie,...Te?{name:Te}:{}});if(I.current!==ie)return;if(!wt.accepted){((ge=A.current)==null?void 0:ge.operationId)===ie&&(A.current=null),He.error(wt.error);return}if(((ve=A.current)==null?void 0:ve.operationId)===ie&&(A.current=null),!M.current||!Pt.isActive(te,ce))return;t(!1)}catch(Te){if(!ie||I.current!==ie||!M.current||!Pt.isActive(te,ce))return;He.error(Te instanceof Error?Te.message:"无法创建网页预览")}finally{ie&&I.current===ie&&(I.current=null,M.current&&x(!1))}}const ne=m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-web-preview-form",autoComplete:"off",onSubmit:te=>{te.preventDefault(),Q()},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(n_,{value:i,disabled:S,onValueChange:te=>D(te),children:[m.jsx(i_,{"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(r_,{})}),m.jsx(s_,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(U1).map(te=>m.jsx(o_,{value:te,"data-slot":"web-preview-tunnel-provider-option","data-provider":te,children:U1[te].label},te))})]})]}),m.jsx(bhe,{status:G,capability:W,provider:i,error:O,disabled:S,onRetry:()=>{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(Bh()),g(""),l("local")},className:We("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(Bh()),g(""),l("static")},className:We("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&&U!==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&&U?m.jsx("span",{"data-slot":"web-preview-local-url-error",className:"text-xs text-destructive",role:"alert",children:U}):null]}):m.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx(Gk,{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:h}),m.jsx(_he,{inspection:_,selectedEntryPath:v,disabled:S,onEntryPathChange:te=>{g(te)}})]}),m.jsxs(Gs,{children:[m.jsx(ct,{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(ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:H,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(Yi,{open:e,onOpenChange:F,children:m.jsxs(Vi,{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(Ki,{children:[m.jsx(Oi,{children:"新建网页预览"}),m.jsx(fs,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),ne]})}):m.jsx(vc,{open:e,onOpenChange:F,children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(bc,{children:"新建网页预览"}),m.jsx(e_,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),ne]})})}function bhe({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=U1[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(Gr,{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(Zz,{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(MI,{onClick:s,disabled:i})]})});const l=JF(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(PV,{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(h=>m.jsx("li",{"data-slot":n==="cloudflare"?"web-preview-cloudflared-suggestion":"web-preview-cpolar-suggestion","data-provider":n,"data-path":h,children:m.jsx("code",{className:"break-all rounded bg-muted px-1 py-0.5",children:h})},h))})]}):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(MI,{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(EV,{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 MI({onClick:e,disabled:t}){return m.jsxs(ct,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(bm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function _he({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(Gr,{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(n_,{value:t,onValueChange:r,disabled:n,children:[m.jsx(i_,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(r_,{placeholder:"选择网页"})}),m.jsx(s_,{children:e.result.htmlEntries.map(o=>m.jsx(o_,{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 whe({open:e,platform:t,onOpenChange:n}){const r=ks(),i=bo("(min-width: 768px)"),s=Re(F=>F.selectedProxyId),o=mr(F=>F.capability),l=mr(F=>F.targets),u=mr(F=>F.targetsStatus),d=mr(F=>F.targetsError),f=mr($5),h=mr(F=>{var U;return((U=F.authoritative)==null?void 0:U.scope)??null}),v=h?`${h.proxyId}\0${h.bindingId}`:null,[g,_]=b.useState(""),[w,S]=b.useState(null),[x,T]=b.useState(!1),k=b.useRef(null),A=b.useRef(e);A.current=e;const I=b.useRef(null),R=b.useRef(null),M=b.useMemo(()=>l.filter(F=>F.platform===t),[t,l]),z=b.useMemo(()=>new Set(f.map(F=>F.targetId)),[f]),Y=b.useMemo(()=>M.filter(F=>!z.has(F.targetId)),[z,M]),W=Y.find(F=>F.targetId===w),G=o==null?void 0:o[t],O=b.useCallback(async F=>{var X;(X=k.current)==null||X.abort();const U=new AbortController;k.current=U;const j=Bt,V=Pt.getActiveScope();if(!(!j||!V||V.proxyId!==s))try{const H=await Pt.requestDevicePreviewCapability(V,F,{signal:U.signal});if(!H||U.signal.aborted||!A.current||!H.success)return;await Pt.requestDevicePreviewTargets(V,!0,{signal:U.signal})}catch{}},[s]);b.useEffect(()=>{var F;if(!e){(F=k.current)==null||F.abort(),k.current=null,_(""),S(null),T(!1),I.current=null,R.current=null;return}return O(!1),()=>{var U;(U=k.current)==null||U.abort(),k.current=null}},[O,e,t,v]),b.useEffect(()=>{if(e){if(w&&!W){S(null);return}!w&&Y.length===1&&S(Y[0].targetId)}},[e,Y,W,w]);async function N(){var X,H,Q;const F=W;if(!F||x||(G==null?void 0:G.available)!==!0)return;const U=Bt,j=Pt.getActiveScope();if(!U||!j||j.proxyId!==s){He.error("请先连接开发机");return}T(!0);let V=null;try{const ne=g.trim(),te=((X=I.current)==null?void 0:X.proxyId)===j.proxyId&&I.current.targetId===F.targetId&&I.current.name===ne?I.current:{proxyId:j.proxyId,targetId:F.targetId,name:ne,operationId:wm("device-preview-operation")};I.current=te,V=te.operationId,R.current=V;const Z=await Pt.createDevicePreview(j,F.targetId,{operationId:te.operationId,...ne?{name:ne}:{}});if(R.current!==te.operationId)return;if(!Z.accepted){if(((H=I.current)==null?void 0:H.operationId)===te.operationId&&(I.current=null),!A.current||!Pt.isActive(U,j))return;He.error(Z.error);return}if(((Q=I.current)==null?void 0:Q.operationId)===te.operationId&&(I.current=null),!A.current||!Pt.isActive(U,j))return;n(!1),r(`/preview/device/${Z.previewId}`)}catch(ne){if(!V||R.current!==V||!A.current||!Pt.isActive(U,j))return;He.error(ne instanceof Error?ne.message:"无法创建模拟器预览")}finally{V&&R.current===V&&(R.current=null,A.current&&T(!1))}}function L(F){var U;!F&&x||(F||((U=k.current)==null||U.abort(),k.current=null,I.current=null,R.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(xhe,{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(Gr,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(PI,{message:d??"无法读取模拟器列表"}):M.length===0?m.jsx(PI,{message:`没有已启动的 ${W1[t]}`}):M.map(F=>{const U=F.targetId===w,j=z.has(F.targetId);return m.jsx(She,{target:F,selected:U,disabled:j||x,alreadyOpen:j,onClick:()=>{S(F.targetId)}},F.targetId)})}),m.jsxs(Gs,{className:"gap-2 sm:gap-2",children:[m.jsxs(ct,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>{O(!0)},"data-slot":"device-preview-refresh",children:[m.jsx(bm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(ct,{type:"button",disabled:!W||x||(G==null?void 0:G.available)!==!0,onClick:()=>{N()},"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),P=`新建 ${W1[t]} 预览`,B="选择开发机上已经启动的模拟器。";return i?m.jsx(Yi,{open:e,onOpenChange:L,children:m.jsxs(Vi,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:P}),m.jsx(fs,{children:B})]}),D]})}):m.jsx(vc,{open:e,onOpenChange:L,children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(bc,{children:P}),m.jsx(e_,{children:B})]}),D]})})}function xhe({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(Zz,{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 PI({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 She({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:We("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(da,{className:"size-4 text-primary","aria-hidden":"true"}):null]})}function QF({open:e,onOpenChange:t}){const[n,r]=b.useState(()=>e?"chooser":"closed"),i=b.useRef(null),s=bo("(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(A0,{icon:m.jsx(Qz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(A0,{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(A0,{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(Yi,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(Vi,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"新建预览"}),m.jsx(fs,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(vc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(bc,{children:"新建预览"}),m.jsx(e_,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx(yhe,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(whe,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function A0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(ct,{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 Ehe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Yi,{open:e!==null,onOpenChange:n,children:m.jsxs(Vi,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"停止预览?"}),m.jsx(fs,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(ct,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"device-preview-close-confirm",children:t?"正在停止...":"停止预览"})]})]})})}const Che={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 khe({preview:e,selected:t,pendingOperation:n,onRename:r,onReconnect:i,onClose:s}){const o=Che[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",h=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[m.jsx("span",{className:We("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:We("shrink-0",l.text),children:l.label})]})]});return m.jsxs("li",{className:We("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(zC,{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:h}):m.jsx("div",{className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:h}),m.jsxs(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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(Gr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(wb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(ni,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(ni,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(Ul,{}),m.jsx(ni,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function The({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Yi,{open:e!==null,onOpenChange:n,children:m.jsxs(Vi,{"data-slot":"preview-close-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"关闭预览?"}),m.jsx(fs,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(ct,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function Rhe({target:e,onOpenChange:t,onRename:n}){return m.jsx(Ahe,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function Ahe({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 h(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(Yi,{open:e!==null,onOpenChange:f,children:m.jsx(Vi,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>{h(v)},children:[m.jsx(Ki,{children:m.jsx(Oi,{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:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",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(Gs,{children:[m.jsx(ct,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(ct,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const Nhe={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 Mhe(e){return e.source.kind==="local"?e.source.url:Tb(e.source.rootPath,e.source.entryPath)}async function Phe(e){if(await Xp(e,{allowUserGestureFallback:!0})==="failed"){He.error("复制失败,请稍后重试");return}He.success("链接已复制")}async function Ihe(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;He.error("无法打开系统分享面板")}}function Ohe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=ii(w=>w.homePath),o=Nhe[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",h=d&&typeof navigator<"u"&&typeof navigator.share=="function",v=Mhe(e),g=e.source.kind==="static"?Gp(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:We("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(Qz,{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:We("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(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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(Gr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(wb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(ni,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(ni,{"data-slot":"preview-row-copy-item",onSelect:()=>{Phe(u)},children:"复制链接"}):null,h?m.jsx(ni,{"data-slot":"preview-row-share-item",onSelect:()=>{Ihe(e.name,u)},children:"分享…"}):null,f?m.jsx(ni,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(Ul,{}),m.jsx(ni,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const Lhe=Object.freeze([]),Dhe=Object.freeze([]);function fd(e,t,n){return Object.freeze({kind:e,previewId:t,scope:Object.freeze({proxyId:n.proxyId,bindingId:n.bindingId})})}function Uc(e,t){return e!==null&&e.kind===t.kind&&e.previewId===t.previewId&&rn(e.scope,t.scope)}function vp(e,t,n){return t!==null&&n!==void 0&&rn(e.scope,t)&&rn(e.scope,n)}function zh(e){const t=Pt.getActiveScope(),n=e.kind==="web"?Yr.getState().authoritative:mr.getState().authoritative;return!n||!vp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function Yo(e){const t=Pt.getActiveScope();return t!==null&&rn(t,e)}function II(){const e=Yr(N=>N.authoritative),t=mr(N=>N.authoritative),n=Qo(N=>N.registry),r=Pt.getActiveScope(),i=r&&e&&rn(r,e.scope)?e.scope:null,s=r&&t&&rn(r,t.scope)?t.scope:null,o=i&&e?e.previews:Lhe,l=s&&t?t.previews:Dhe,u=zz("/preview/device/:id"),d=ks(),[f,h]=b.useState(null),[v,g]=b.useState(null),_=(v==null?void 0:v.kind)==="web"&&vp(v,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===v.previewId)??null:null,w=(v==null?void 0:v.kind)==="device"&&vp(v,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===v.previewId)??null:null,S=_??w,x=(f==null?void 0:f.kind)==="web"&&vp(f,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===f.previewId)??null:null,T=(f==null?void 0:f.kind)==="device"&&vp(f,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===f.previewId)??null:null;b.useEffect(()=>{v&&!S&&g(N=>Uc(N,v)?null:N),f&&!x&&!T&&h(N=>Uc(N,f)?null:N)},[f,T,v,S,x]);function k(N,L,D){var P;return(P=z5(n,N,L,D)[0])==null?void 0:P.kind}if(o.length===0&&l.length===0)return null;async function A(N){if(zh(N))try{const L=await Pt.reconnectWebPreview(N.scope,N.previewId);if(!Yo(N.scope))return;L.success||He.error(L.error)}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function I(N,L){if(!zh(N))return;let D;try{D=N.kind==="web"?await Pt.renameWebPreview(N.scope,N.previewId,L):await Pt.renameDevicePreview(N.scope,N.previewId,L)}catch(P){if(!Yo(N.scope))return;throw P}if(Yo(N.scope)&&!D.success)throw new Error(D.error)}async function R(N){if(zh(N))try{const L=await Pt.closeWebPreview(N.scope,N.previewId);if(!Yo(N.scope))return;if(!L.success){He.error(L.error);return}h(D=>Uc(D,N)?null:D)}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function M(N){if(zh(N))try{const L=await Pt.reconnectDevicePreview(N.scope,N.previewId);if(!Yo(N.scope))return;L.success||He.error(L.error)}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(N){if(zh(N))try{const L=await Pt.closeDevicePreview(N.scope,N.previewId);if(!Yo(N.scope))return;if(!L.success){He.error(L.error);return}h(D=>Uc(D,N)?null:D),(u==null?void 0:u.params.id)===N.previewId&&d("/sessions")}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const Y=(f==null?void 0:f.kind)==="web"&&k(f.scope,"web",f.previewId)==="close",W=(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(N=>m.jsx(Ohe,{preview:N,pendingOperation:i?k(i,"web",N.previewId):void 0,onRename:()=>i&&g(fd("web",N.previewId,i)),onReconnect:()=>i&&void A(fd("web",N.previewId,i)),onClose:()=>i&&h(fd("web",N.previewId,i))},N.previewId)),l.map(N=>m.jsx(khe,{preview:N,selected:(u==null?void 0:u.params.id)===N.previewId,pendingOperation:s?k(s,"device",N.previewId):void 0,onRename:()=>s&&g(fd("device",N.previewId,s)),onReconnect:()=>s&&void M(fd("device",N.previewId,s)),onClose:()=>s&&h(fd("device",N.previewId,s))},N.previewId))]}),m.jsx(Rhe,{target:G&&S?{targetKey:`${G.kind}\0${G.scope.proxyId}\0${G.scope.bindingId}\0${G.previewId}`,name:S.name}:null,onOpenChange:N=>{!N&&G&&g(L=>Uc(L,G)?null:L)},onRename:N=>G?I(G,N):Promise.resolve()}),m.jsx(The,{preview:x,closing:Y,onOpenChange:N=>{!N&&!Y&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void R(O)}),m.jsx(Ehe,{preview:T,closing:W,onOpenChange:N=>{!N&&!W&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void z(O)})]})}function e6({layout:e}){const t=Ut(ie=>ie.sessions),n=Ut(ie=>ie.sessionListLoaded),r=Ut(ie=>ie.agentStatusBySessionId),i=Ut(ie=>ie.ptyStateBySessionId),s=Ut(ie=>ie.renameSession),o=cn(ie=>ie.bySessionId),l=zz("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Re(ie=>!!ie.selectedProxyId),f=Re(ie=>ie.proxyListLoaded),h=Re(ie=>ie.proxySwitchTarget),v=Ut(ie=>ie.loadingProxyName),g=h!==null||!f||d&&!n,_=(h==null?void 0:h.name)??v,w=_?`正在连接 ${_}...`:"连接中...",S=ks(),[x,T]=b.useState(!1),[k,A]=b.useState(!1),[I,R]=b.useState(!1),[M,z]=b.useState(!1),[Y,W]=b.useState(null),[G,O]=b.useState(null),{creatingTerminal:N,creatingShell:L,createTerminal:D}=t6(),[P,B]=b.useState(new Set),[F,U]=b.useState(()=>Date.now());b.useEffect(()=>{const ie=setInterval(()=>U(Date.now()),6e4);return()=>clearInterval(ie)},[]);function j(ie,me){S(`/chat/${ie}?mode=${me}`,{replace:!1})}function V(ie){const me=ie.sessionId,ge=Bt;if(!ge){He.error("请先连接开发机");return}ge.sendControl({type:"session_terminate",sessionId:me}),Ut.getState().removeSession(me),cn.getState().clearSession(me),me===u&&S("/sessions"),(ie==null?void 0:ie.kind)==="agent"&&ie.mode==="pty"&&ie.ptyOwner==="local-terminal"?He.info("已断开页面连接,本地终端仍在运行"):He.info("正在终止会话",{duration:1500})}async function X(ie,me){const ge=Bt;if(!ge)throw new Error("请先连接开发机");const ve=await ge.renameSession(ie,me);if(!ve.success)throw new Error(ve.error??"重命名失败");s(ie,ve.name??me),He.success("已重命名会话")}function H(ie){B(me=>{const ge=new Set(me);return ge.has(ie)?ge.delete(ie):ge.add(ie),ge})}function Q(ie){var ve;const me=ie.mode==="json"&&(((ve=o[ie.sessionId])==null?void 0:ve.pendingApprovals.some(Te=>Te.status==="pending"))??!1),ge=phe({session:ie,agentStatus:r[ie.sessionId],ptyState:i[ie.sessionId],hasPendingApproval:me});return ge===ie.state?ie:{...ie,state:ge}}const ne=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(mp,{open:x,onOpenChange:T}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]});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(Gr,{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(nu,{variant:"no-proxy"})}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]});const te=m.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",ne?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),Z=ne?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:Bhe(t).map(ie=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>H(ie.provider),"aria-expanded":!P.has(ie.provider),className:We("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:zhe(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(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!P.has(ie.provider)&&"rotate-90"),"aria-hidden":"true"})]}),P.has(ie.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:ie.sessions.map(me=>m.jsx($fe,{session:Q(me),selected:me.sessionId===u,now:F,onClick:()=>j(me.sessionId,me.mode),onRename:()=>W(me),onTerminate:()=>O(me)},me.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(Xfe,{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,Z,m.jsx(II,{}),ce]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(ct,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[m.jsx(Jz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(Uhe,{open:k,creatingTerminal:N,onOpenChange:A,onCreateAgent:()=>{A(!1),T(!0)},onCreateTerminal:()=>{n6()?(A(!1),R(!0)):D(void 0,()=>A(!1))},onCreatePreview:()=>{A(!1),z(!0)}}),m.jsx(r6,{layout:"mobile",open:I,creatingTerminal:N,creatingShell:L,onOpenChange:R,onBack:()=>{R(!1),A(!0)},onCreate:ie=>{D(ie,()=>R(!1))}}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(QF,{open:M,onOpenChange:z}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[te,Z,m.jsx(II,{}),ce]}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]})}function Bhe(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])=>jhe(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function zhe(e){return e==="terminal"?"终端":t_(e)}function jhe(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:HF(e,t)}function t6(){const e=ks(),[t,n]=b.useState(null),r=t!==null;async function i(s,o){var u;const l=Re.getState();if(!(r||!l.connected||!l.proxyOnline||!l.selectedProxyId||l.proxySwitchTarget)&&!Zk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await ahe({relay:Bt,shell:s});if(d.type!=="success"){He.error(d.message);return}Ut.getState().addSession(d.session),o==null||o(),e(d.route)}finally{n(null)}}}return{creatingTerminal:r,creatingShell:t,createTerminal:i}}function Zk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function Fhe(e){const t=Re(u=>u.terminalShells),n=Re(Zk),r=Re(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=Bt,f=d==null?void 0:d.getPreviewScope();if(s(!1),!d||!f||f.proxyId!==r){s(!0);return}return d.requestProxyInfo().then(h=>{const v=Re.getState(),g=d.getPreviewScope();u||!v.connected||!v.proxyOnline||v.selectedProxyId!==r||!g||!rn(f,g)||v.setTerminalShells(h.terminalShells)},()=>{u||s(!0)}),()=>{u=!0}},[e,n,r,o]),{terminalShells:t,needsDetection:n,failed:i,retry:()=>l(u=>u+1)}}const Hhe=[{label:"启动 Shell"}];function $he(e){return e!=null&&e.length?e:Hhe}function n6(){var t;const e=Re.getState();return Zk(e)||!!((t=e.terminalShells)!=null&&t.length)}function OI({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),h=b.useRef(!1),v=Re(Y=>!!Y.selectedProxyId),g=Re(Y=>Y.proxySwitchTarget!==null),_=v&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=t6();function T(){f(!0),window.setTimeout(()=>f(!1),2e3)}function k(){if(!_){T();return}h.current=!0,o(!0)}function A(){if(!_){T();return}h.current=!0,n6()?i(!0):x()}function I(){if(!_){T();return}h.current=!0,u(!0)}function R(Y){Y.preventDefault(),T()}const M=m.jsxs(ct,{variant:"outline","data-slot":"create-session-trigger",className:We(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!_&&"opacity-50 hover:bg-background"),"aria-label":"新建","aria-disabled":!_,onClick:_?void 0:R,children:[m.jsx(Jz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),z=_?m.jsxs(Cf,{open:t,onOpenChange:n,children:[m.jsx(kf,{asChild:!0,children:M}),m.jsxs(Tf,{align:e?"end":"start",className:"w-80","data-slot":"create-session-type-menu",onCloseAutoFocus:Y=>{h.current&&(h.current=!1,Y.preventDefault())},children:[m.jsxs(ni,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:k,children:[m.jsx(Xz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ni,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:w,onSelect:A,children:[m.jsx(ou,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),w?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx(Ul,{}),m.jsxs(ni,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:I,children:[m.jsx(UC,{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:"在浏览器中预览网页或设备模拟器"})]})]})]})]}):M;return m.jsxs(m.Fragment,{children:[_?z:m.jsxs(Rf,{open:_?void 0:d,onOpenChange:_?void 0:f,children:[m.jsx(Af,{asChild:!0,children:z}),m.jsx(Nf,{side:"top",children:g?"正在切换开发机":"请先连接开发机"})]}),m.jsx(r6,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:Y=>{x(Y,()=>i(!1))}}),m.jsx(mp,{open:s,onOpenChange:o}),m.jsx(QF,{open:l,onOpenChange:u})]})}function Uhe({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(vc,{open:e,onOpenChange:n,children:m.jsxs(yc,{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(ku,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(bc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(ct,{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(Xz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ct,{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(ou,{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(ct,{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(UC,{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 r6({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=Fhe(t),h=b.useRef(!1),v=Re(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(ct,{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(ou,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"终端检测失败,点击重试":"正在检测终端..."]}):$he(l).map(w=>m.jsxs(ct,{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(Yfe,{shell:w.id,label:w.label}),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(ct,{type:"button",variant:"ghost",className:"min-h-11 justify-start gap-3 px-3 text-muted-foreground",disabled:n,onClick:()=>{h.current=!0,s()},children:[m.jsx(gf,{className:"size-4","aria-hidden":"true"}),"返回"]})]});function _(w){h.current&&(h.current=!1,w.preventDefault())}return e==="mobile"?m.jsx(vc,{open:t,onOpenChange:i,children:m.jsxs(yc,{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(ku,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(bc,{children:"Shell 会话"})}),g]})}):m.jsx(Yi,{open:t,onOpenChange:i,children:m.jsxs(Vi,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(Ki,{children:m.jsx(Oi,{children:"Shell 会话"})}),g]})})}const Whe="0.10.8",qhe={version:Whe},Yhe={playback:"playback",capture:"play-and-record"};function Vhe(){return typeof navigator>"u"?null:navigator.audioSession??null}function Khe(){return{setMode:()=>{},release:()=>{}}}class Ghe{constructor(t=Vhe){Me(this,"getAudioSession");Me(this,"leases",new Map);Me(this,"session",null);Me(this,"baselineType",null);Me(this,"nextLeaseId",1);Me(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Khe();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(Yhe[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 Jk=new Ghe,q1=64,LI=-60,i6=32;function DI(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-LI)/-LI));return e<0?-r:r}function BI(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 h=l;h<u;h+=1){const v=i.getInt16(h*2,!0)/32768;d=Math.min(d,v),f=Math.max(f,v)}s.push({min:d,max:f})}return s}function Xhe(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 Zhe(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 s6{constructor(t,n=24e3,r={}){Me(this,"context");Me(this,"sampleRate");Me(this,"options");Me(this,"nextStartTime",0);Me(this,"activityEndToken",0);Me(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=Xhe(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*i6/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),h=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),v=Zhe(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,h)},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 N0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},zI="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",Jhe=800,jI=300,Qhe=1600;function Y1(e,t){return e.filter(n=>!n.model||n.model===t)}function FI({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 Av({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),h=n.filter(g=>!g.disabled),v=!!o6(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:h.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(HI,{label:f,muted:!d&&!t}),m.jsx(ac,{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(da,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(HI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function HI({label:e,muted:t=!1}){const n=o6(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 epe({scrollRef:e}={}){const[t,n]=b.useState(N0),[r,i]=b.useState(String(N0.turnIdleSeconds)),[s,o]=b.useState(()=>hv()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[h,v]=b.useState(!1),[g,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),T=b.useRef(null),k=b.useRef(null),A=b.useRef(!1);b.useEffect(()=>{const Z=Bt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce=!1;return _({kind:"loading"}),Z.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 Z=Bt;if(!Z||!h)return;let ce=!1;return Z.requestVoiceCapabilities({region:t.region}).then(ie=>{if(!ce){if(ie.error||!ie.capabilities){o(hv());return}o(ie.capabilities)}}).catch(()=>{ce||o(hv())}),()=>{ce=!0}},[t.region,h]),b.useEffect(()=>(A.current=!0,()=>{A.current=!1,H(),Q()}),[]);const I=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]),R=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",M=b.useMemo(()=>Y1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),Y=M.some(Z=>Z.value===t.ttsVoice)?t.ttsVoice:"",W=M.length===0?"当前模型暂无可用音色":Y?null:"请选择可用音色",G=b.useMemo(()=>ipe(r),[r]),O=G?null:"请输入正整数秒数",N=W??O,L=R||!!N,D=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>WI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),B=b.useMemo(()=>spe(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>WI(M,Y),[M,Y]);function U(){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??N0.turnIdleSeconds}}async function j(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=Bt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ce=U();Q(),_({kind:"saving"});const ie=performance.now();try{const me=await Z.updateVoiceConfig(ce);if(!A.current)return;const ge=performance.now()-ie;if(ge<jI&&await rpe(jI-ge),!A.current)return;if(!me.success||me.error||!me.config){_({kind:"error",message:me.error??"保存语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),k.current=setTimeout(()=>{k.current=null,_(ve=>ve.kind==="saved"?{kind:"idle"}:ve)},Qhe),Z.requestVoiceCapabilities({region:me.config.region}).then(ve=>{A.current&&ve.capabilities&&o(ve.capabilities)}).catch(()=>{A.current&&o(hv())})}catch(me){if(!A.current)return;_({kind:"error",message:me instanceof Error?me.message:"保存语音设置失败"})}}async function V(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=Bt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce;try{ce=X()}catch(ie){_({kind:"error",message:UI(ie)});return}_({kind:"testing"});try{const[ie]=await Promise.all([Z.testVoiceConfig(U()),ce.ready]);if(!ie.success||ie.error){H(),_({kind:"error",message:ie.error??"语音配置测试失败"});return}const me=await ne(ie,ce.context);_({kind:"playingTest",transcript:ie.transcript}),T.current=setTimeout(()=>{T.current=null,H(),_({kind:"testPassed",transcript:ie.transcript})},me)}catch(ie){H(),_({kind:"error",message:UI(ie)})}}function X(){H();const Z=Jk.acquire("playback");S.current=Z;try{const ce=npe();return w.current=ce,{context:ce,ready:$I(ce)}}catch(ce){throw Z.release(),S.current=null,ce}}function H(){var Z,ce,ie;T.current&&(clearTimeout(T.current),T.current=null),(Z=x.current)==null||Z.stop(),x.current=null,(ce=w.current)==null||ce.close(),w.current=null,(ie=S.current)==null||ie.release(),S.current=null}function Q(){k.current&&(clearTimeout(k.current),k.current=null)}async function ne(Z,ce){if(!Z.audioBase64)throw new Error("语音测试未返回可播放音频");if(Z.audioEncoding&&Z.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ie=Z.audioSampleRate??24e3,me=tpe(Z.audioBase64);if(me.byteLength===0||me.byteLength%2!==0)throw new Error("测试音频数据无效");await $I(ce);const ge=new s6(ce,ie);x.current=ge,ge.enqueue(me);const ve=Math.ceil(me.byteLength/2/ie*1e3);return Math.max(Jhe,ve)}function te(Z){var ce;return((ce=Y1(s.ttsVoices,Z)[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:Z=>{Z.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(FI,{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(rj,{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:Z=>{u(Z.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${zI} w-full pl-9`})]}),t.configured&&m.jsxs(ct,{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(lj,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(Av,{label:"地域",value:t.region,options:D,onChange:Z=>n(ce=>({...ce,region:Z==="intl"?"intl":"cn"}))}),m.jsx(Av,{label:"语音识别模型",value:t.asrModel,options:P,onChange:Z=>n(ce=>({...ce,asrModel:Z}))}),m.jsx(Av,{label:"语音合成模型",value:t.ttsModel,options:B,onChange:Z=>n(ce=>({...ce,ttsModel:Z,ttsVoice:te(Z)}))}),m.jsx(Av,{label:"语音音色",value:Y,options:F,placeholder:M.length===0?"暂无可用音色":"请选择音色",onChange:Z=>n(ce=>({...ce,ttsVoice:Z})),help:W}),m.jsx(FI,{label:"结束停顿时间(秒)",help:O,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:Z=>i(Z.target.value),className:`${zI} 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:[I?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:I}):null,m.jsxs(ct,{type:"button",variant:"outline",disabled:L,onClick:()=>{V()},children:[m.jsx(WC,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(ct,{type:"submit",disabled:L,children:[m.jsx(UK,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function tpe(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 npe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function $I(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function UI(e){return e instanceof Error?e.message:"语音配置测试失败"}function rpe(e){return new Promise(t=>setTimeout(t,e))}function ipe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function WI(e,t){const n=e.map(r=>({value:r.value,label:a6(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function spe(e,t,n){const r=e.map(i=>{const s=Y1(t,i.value).length===0;return{value:i.value,label:`${a6(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function o6(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 a6(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 ope=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],ape=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],Qk="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function l6(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 lpe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function cpe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function upe(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function V1({open:e,onOpenChange:t}){const n=Re(G=>G.relayUrl),r=Re(G=>G.latencyMonitorEnabled),i=Re(G=>G.setLatencyMonitorEnabled),s=Re(G=>G.sessionIdleNotificationsEnabled),o=Re(G=>G.setSessionIdleNotificationsEnabled),l=Re(G=>G.inputModePreference),u=Re(G=>G.setInputModePreference),d=Re(G=>G.themePreference),f=Re(G=>G.setThemePreference),h=Re(G=>G.ptyScrollTraceEnabled),v=Re(G=>G.setPtyScrollTraceEnabled),[g,_]=b.useState("menu"),[w,S]=b.useState(e),[x,T]=b.useState({kind:"idle"}),k=b.useRef(null),A=b.useRef(null),I=Toe(),R=b.useMemo(()=>bf().osName==="iPad",[]);e!==w&&(S(e),e&&_("menu"));const M=b.useCallback(async G=>{if(!G){o(!1);return}const O=await Jse();if(O==="granted"){o(!0);return}if(O==="denied"){He.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(O==="default"){He.info("未授予通知权限,会话通知保持关闭");return}He.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{T({kind:"loading"});try{const O=await fetch(lpe(n),{cache:"no-store",signal:G});if(!O.ok)throw new Error(`HTTP ${O.status}`);const N=await O.json();if(N.status!=="ok")throw new Error("状态异常");T({kind:"ready",version:N.version??"未知",uptime:N.uptime??0})}catch(O){if(O instanceof DOMException&&O.name==="AbortError")return;T({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}),A.current&&(A.current.scrollTop=0)});return()=>window.cancelAnimationFrame(G)},[e,g]);const Y=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",W=x.kind==="ready"?`运行 ${l6(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(Yi,{open:e,onOpenChange:t,children:m.jsxs(Vi,{className:We("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":g,focusSurfaceOnOpen:!0,ref:k,showCloseButton:g==="menu",children:[m.jsx(Ki,{className:We(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(ct,{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(gf,{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(Oi,{children:cpe(g)}),m.jsx(fs,{className:"max-w-[28rem] leading-5",children:upe(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(Oi,{children:"设置"}),m.jsx(fs,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(dpe,{relayVersion:Y,relayDetail:W,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(hpe,{saved:I}):g==="clients"?m.jsx(ype,{}):g==="voice"?m.jsx(epe,{scrollRef:A}):m.jsx(fpe,{relayTokenSaved:I,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:R,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:M,ptyScrollTraceEnabled:h,onPtyScrollTraceEnabledChange:v,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function dpe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:Qk,"data-slot":"settings-dialog-body",children:[m.jsx(YI,{icon:m.jsx(ij,{className:"size-4","aria-hidden":"true"}),label:"Web",value:qhe.version,detail:"当前浏览器加载的版本"}),m.jsx(YI,{icon:m.jsx(oj,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function fpe({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:f,onLatencyMonitorEnabledChange:h,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(hd,{title:"服务",children:[m.jsx(Nv,{icon:m.jsx(pV,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:v}),m.jsx(Nv,{icon:m.jsx(rj,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(Nv,{icon:m.jsx(dG,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(hd,{title:"外观",children:m.jsx(qI,{icon:m.jsx(eG,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:ope,onValueChange:n})}),m.jsx(hd,{title:"通知",children:m.jsx(P0,{icon:m.jsx(gV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(hd,{title:"交互",children:m.jsx(qI,{icon:m.jsx(HC,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:ape,onValueChange:i})}):null,m.jsxs(hd,{title:"高级诊断",children:[m.jsx(P0,{icon:m.jsx(ou,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(P0,{icon:m.jsx(Kz,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:h})]}),m.jsx(hd,{title:"关于",children:m.jsx(Nv,{icon:m.jsx(oj,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function hd({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 qI({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:We("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function hpe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{Q5().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!Z5(f)){const h="Relay Token 保存失败,请检查浏览器存储权限。";o(h),He.error(h);return}o(null),He.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{J5(),l()};return m.jsxs("form",{className:Qk,"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(ct,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(ct,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function ppe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function mpe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||ppe(e)}function gpe(e){return Ure(e)}function vpe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return l6(t)}function M0({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 ype(){const e=Re(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=Bt;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 h=b.useCallback(async v=>{const g=Bt;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:Qk,"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(ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>{f()},disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(bm,{className:We("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:gpe(v)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(M0,{label:"已连接",value:vpe(v.connectedAt)}),v.proxyId?m.jsx(M0,{label:"连接到",value:mpe(v.proxyId,d),title:v.proxyId}):null,v.remoteAddress?m.jsx(M0,{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(ct,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>{h(v.clientId)},"data-slot":"relay-client-action",children:[m.jsx(vK,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},v.clientId)})]})}function P0({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:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),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:We("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:We("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function Nv({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(Yd,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function YI({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:We("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),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 bpe="xterm-helper-textarea";function _pe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(bpe)?!1:(e.blur(),!0)}function VI(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&&wpe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function wpe(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 xpe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&_pe()},[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,VI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(VI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Spe({className:e}){const t=Re(o=>o.sidebarCollapsed),n=Re(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=xpe();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:We("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(GI,{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(KI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(OI,{compact:!0})]})]}),m.jsx(V1,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:We("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[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(kj,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(GI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(FF,{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(e6,{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(OI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(KI,{onClick:()=>i(!0)})})]})]}),m.jsx(V1,{open:r,onOpenChange:i})]})}function KI({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(Rf,{delayDuration:500,children:[m.jsx(Af,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(aj,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(Nf,{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 GI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?AK:TK;return m.jsxs(Rf,{delayDuration:500,children:[m.jsx(Af,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(Nf,{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 Epe=1500,Cpe=300,XI=70,ZI=35;function c6({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(h=>!h),530);return()=>clearInterval(f)},[]),b.useEffect(()=>{let f;const h=()=>e[u.current%e.length],v=()=>{const g=o.current;if(g==="typing"){const _=h();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(v,XI)):(o.current="paused",f=setTimeout(v,Epe))}else g==="paused"?(o.current="deleting",f=setTimeout(v,ZI)):g==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),f=setTimeout(v,ZI)):(u.current+=1,o.current="waiting",f=setTimeout(v,Cpe)):(o.current="typing",f=setTimeout(v,XI))};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 u6=["DEV Anywhere","/unlimited @anytime"];function kpe({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(c6,{texts:u6,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 Tpe=3e3,Rpe=1e4,Mv=12,Ape=4,JI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Npe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function I0(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 pd(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function yp(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function QI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function d6(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Mpe(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 Ppe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?yp(e.rttMs):"等待检测"}function Ipe(){const e=Ii("local",Tn.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 eO(e){Ir("local",Tn.latencyMonitorPosition,JSON.stringify(e))}function Ope(){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 O0(e,t){const n=Ope(),r=Mv,i=Mv,s=Math.max(r,n.width-t.width-Mv),o=Math.max(i,n.height-t.height-Mv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Lpe(){const e=Re(R=>R.latencyMonitorEnabled),t=Re(R=>R.connected),n=Re(R=>R.proxyOnline),r=Re(R=>R.selectedProxyId),[i,s]=b.useState(Npe),[o,l]=b.useState(()=>Ipe()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),h=b.useRef(!1),v=b.useMemo(()=>(Object.values(i).sort((R,M)=>QI(M.state)-QI(R.state))[0]??{state:"idle"}).state,[i]),g=d6(v);async function _(){if(u.current)return;const R=Bt;if(!R||!t){const W=pd("Relay 服务器未连接");s({webRelay:W,relayProxy:W,webProxy:W});return}u.current=!0,s(W=>({webRelay:{...W.webRelay,state:"measuring"},relayProxy:n?{...W.relayProxy,state:"measuring"}:pd("未连接开发机"),webProxy:n?{...W.webProxy,state:"measuring"}:pd("未连接开发机")}));const[M,z,Y]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:M.status==="fulfilled"?I0(M.value):pd(M.reason instanceof Error?M.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?I0(z.value):pd(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:Y.status==="fulfilled"?I0(Y.value):pd(Y.reason instanceof Error?Y.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let R=!1,M=null;const z=async()=>{await _(),!R&&(M=setTimeout(z,document.hidden?Rpe:Tpe))};return z(),()=>{R=!0,u.current=!1,M&&clearTimeout(M)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const R=d.current;if(!R)return;const M=R.getBoundingClientRect(),z=O0(o,{width:M.width,height:M.height});z.x===o.x&&z.y===o.y||(l(z),eO(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(R){var z,Y;if(R.button!==0)return;const M=R.currentTarget.getBoundingClientRect();f.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,originX:M.left,originY:M.top,width:M.width,height:M.height,dragging:!1},(Y=(z=R.currentTarget).setPointerCapture)==null||Y.call(z,R.pointerId)}function T(R){const M=f.current;if(!M||M.pointerId!==R.pointerId)return;const z=R.clientX-M.startX,Y=R.clientY-M.startY;if(!M.dragging&&Math.hypot(z,Y)<Ape)return;M.dragging=!0,R.preventDefault();const W=O0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(W)}function k(R){var G,O;const M=f.current;if(!M||M.pointerId!==R.pointerId||(f.current=null,(O=(G=R.currentTarget).releasePointerCapture)==null||O.call(G,R.pointerId),!M.dragging))return;R.preventDefault(),h.current=!0,window.setTimeout(()=>{h.current=!1},200);const z=R.clientX-M.startX,Y=R.clientY-M.startY,W=O0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(W),eO(W)}function A(R){var z,Y;const M=f.current;!M||M.pointerId!==R.pointerId||(f.current=null,(Y=(z=R.currentTarget).releasePointerCapture)==null||Y.call(z,R.pointerId))}function I(R){h.current&&(h.current=!1,R.preventDefault(),R.stopPropagation())}return m.jsxs(Zb,{children:[m.jsx(Jb,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:We("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Mpe(g)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${yp(i.webRelay.rttMs)},开发机 ${yp(w.rttMs)}`,onPointerDown:x,onPointerMove:T,onPointerUp:k,onPointerCancel:A,onClickCapture:I,children:[m.jsx(Kz,{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 ",yp(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",yp(w.rttMs)]}),m.jsx(ac,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(Qb,{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(ct,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>{_()},children:m.jsx(bm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(JI).map(R=>m.jsx(Dpe,{label:JI[R],measurement:i[R]},R))})]})]})}function Dpe({label:e,measurement:t}){const n=d6(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:We("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Ppe(t)})]})]})}const f6="/__dev_anywhere_debug/browser-state-dumps",Bpe=1500,zpe=10,L0=80,eT=500,jpe=["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"],Fpe=["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 tO(){if(typeof window>"u")return"off";const e=_6("debugDump");return e==="auto"?"auto":e!==null||Gpe("debugInput")?"manual":"off"}function Hpe(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:qpe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:nO(document.activeElement),selection:Ype(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>nO(i)).filter(i=>!!i),root:h6(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:md(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:md(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:md(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:md(()=>rO(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:md(()=>rO(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:md(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function $pe(e="manual"){const t=Hpe(e);return Upe(t)}async function Upe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Wpe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:f6}}catch(r){const i=w6(r),s=Vpe(e.createdAt);return Kpe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Wpe(e){const t=await fetch(f6,{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 h6(e,t,n){if(n.count>=Bpe||t>zpe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=iO(e.textContent??"");return u?{kind:"text",text:a_(u,eT)}:{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,L0))u.nodeType===Node.TEXT_NODE&&!iO(u.textContent??"")||r.push(h6(u,t+1,n));s.length>L0&&(i=s.length-L0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:b6(e),attrs:p6(e),rect:m6(e),scroll:g6(e),style:v6(e)},l=y6(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function nO(e){if(!(e instanceof HTMLElement))return null;const t=y6(e);return{path:b6(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:p6(e),rect:m6(e),scroll:g6(e),style:v6(e),...t?{value:t}:{}}}function qpe(){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 p6(e){const t={};for(const n of jpe){const r=e.getAttribute(n);r!==null&&(t[n]=a_(r,500))}return t}function m6(e){const t=e.getBoundingClientRect();return{x:Cs(t.x),y:Cs(t.y),width:Cs(t.width),height:Cs(t.height),top:Cs(t.top),right:Cs(t.right),bottom:Cs(t.bottom),left:Cs(t.left)}}function g6(e){return{top:Cs(e.scrollTop),left:Cs(e.scrollLeft),height:Cs(e.scrollHeight),width:Cs(e.scrollWidth),clientHeight:Cs(e.clientHeight),clientWidth:Cs(e.clientWidth)}}function v6(e){const t=window.getComputedStyle(e),n={};for(const r of Fpe)n[r]=t.getPropertyValue(r);return n}function y6(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:a_(e.value,eT),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Ype(){var e;try{return a_(((e=window.getSelection())==null?void 0:e.toString())??"",eT)}catch{return null}}function b6(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 Vpe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Kpe(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 Gpe(e){return _6(e)!==null}function _6(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 rO(e){return e?Gy(e.slice(-200)):null}function md(e){try{return Gy(e())}catch(t){return{error:w6(t)}}}function Gy(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(Gy);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Gy(r);return t}return String(e)}function iO(e){return e.replace(/\s+/g," ").trim()}function a_(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Cs(e){return Math.round(e*100)/100}function w6(e){return e instanceof Error?e.message:String(e)}const Xpe=500,Zpe=1e3,Jpe=60;function Qpe(){const[e,t]=b.useState(()=>tO()),[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(tO());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const h=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 $pe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&eme(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=h,()=>{window.__devAnywhereDumpBrowserState===h&&delete window.__devAnywhereDumpBrowserState}),[h]),b.useEffect(()=>{var T,k;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=A=>{d.current>=Jpe||(_(),f.current=window.setTimeout(()=>{f.current=null;const I=Date.now(),R=Zpe-(I-u.current);if(R>0){f.current=window.setTimeout(()=>w(A),R);return}u.current=Date.now(),d.current+=1,h(`auto:${d.current}:${A}`)},Xpe))};w("initial");const S=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=A=>w(A.type);return S.forEach(A=>window.addEventListener(A,x,!0)),(T=window.visualViewport)==null||T.addEventListener("resize",x),(k=window.visualViewport)==null||k.addEventListener("scroll",x),()=>{var A,I;_(),S.forEach(R=>window.removeEventListener(R,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(I=window.visualViewport)==null||I.removeEventListener("scroll",x)}},[h,e]),e==="off")return null;const v=e==="auto"?"自动诊断中":"保存诊断",g=tme(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(ct,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>{h("manual")},disabled:n,"data-slot":"browser-state-dump",children:[n?m.jsx(Gr,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(QV,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:v})]})]})}function eme(e){if(e.status==="saved"){He.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){He.info(`诊断已下载: ${e.filename}`);return}He.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function tme(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function nme({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(Gr,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(ct,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function rme(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 tT(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:rme(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 h=i(d);if(h!==null){const v=s.get(d.event);if(v&&i(v)===h&&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 h=f.splice(0,f.length-r);if(i)for(const v of h)s.get(v.event)===v&&s.delete(v.event)}u(f)},getAll:l}}function tr(e){return Math.round(e*10)/10}function Bl(e){return e.length===0?"":`${tr(Math.min(...e))}..${tr(Math.max(...e))}`}function Bd(e){return[...new Set(e.filter(t=>t!==void 0).map(tr))]}function x6(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 ime="dev_anywhere_pty_input_latency_trace",sO=80,sme=1e4,ome=new TextDecoder;let ame=0;const df=new Map,Tu=tT({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:ime,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function lme(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=fme)}function cme(e,t){if(!Tu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++ame}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:mme(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=df.get(e)??[];return s.push(i),rT(s,r),df.set(e,s),Om({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function oO(e,t){if(!e||!Tu.isEnabled())return;const n=performance.now(),r=hme(e.sessionId,e.inputId);r&&(r.sentAt=n),Om({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 ume(e,t,n){if(!Tu.isEnabled())return;const r=performance.now(),i=nT(e,r),s=yme(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&vme(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Om({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:iT(i,r),details:bme([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function dme(e,t,n=1){if(!Tu.isEnabled())return;const r=performance.now(),i=nT(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Om({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:iT(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>pme(e,s))}function fme(){const e=Tu.getAll(),t=e.slice(-200),n=[...df.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":tr(s.sentAt-s.startedAt),s.firstOutputAt===null?"":tr(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":tr(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":tr(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":tr(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[tr(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?"":tr(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(`
605
+ 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},ale="DialogDescriptionWarning",lle=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${M3(ale).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},Ck=v3,cle=b3,kk=w3,Tk=x3,Rk=S3,P3=C3,I3=T3,Db=A3;function ule(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 dle(e){const[t,n]=b.useState(void 0);return rs(()=>{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 fle=["top","right","bottom","left"],nc=Math.min,Ws=Math.max,$y=Math.round,kv=Math.floor,la=e=>({x:e,y:e}),hle={left:"right",right:"left",bottom:"top",top:"bottom"};function T1(e,t,n){return Ws(e,nc(t,n))}function Ya(e,t){return typeof e=="function"?e(t):e}function Va(e){return e.split("-")[0]}function xf(e){return e.split("-")[1]}function Ak(e){return e==="x"?"y":"x"}function Nk(e){return e==="y"?"height":"width"}function sa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function Mk(e){return Ak(sa(e))}function ple(e,t,n){n===void 0&&(n=!1);const r=xf(e),i=Mk(e),s=Nk(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Uy(o)),[o,Uy(o)]}function mle(e){const t=Uy(e);return[R1(e),t,R1(t)]}function R1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const uI=["left","right"],dI=["right","left"],gle=["top","bottom"],vle=["bottom","top"];function yle(e,t,n){switch(e){case"top":case"bottom":return n?t?dI:uI:t?uI:dI;case"left":case"right":return t?gle:vle;default:return[]}}function ble(e,t,n,r){const i=xf(e);let s=yle(Va(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(R1)))),s}function Uy(e){const t=Va(e);return hle[t]+e.slice(t.length)}function _le(e){return{top:0,right:0,bottom:0,left:0,...e}}function O3(e){return typeof e!="number"?_le(e):{top:e,right:e,bottom:e,left:e}}function Wy(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 fI(e,t,n){let{reference:r,floating:i}=e;const s=sa(t),o=Mk(t),l=Nk(o),u=Va(t),d=s==="y",f=r.x+r.width/2-i.width/2,h=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:h};break;case"left":g={x:r.x-i.width,y:h};break;default:g={x:r.x,y:r.y}}switch(xf(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 wle(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:h="floating",altBoundary:v=!1,padding:g=0}=Ya(t,e),_=O3(g),S=l[v?h==="floating"?"reference":"floating":h],x=Wy(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})),T=h==="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)),A=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},I=Wy(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:T,offsetParent:k,strategy:u}):T);return{top:(x.top-I.top+_.top)/A.y,bottom:(I.bottom-x.bottom+_.bottom)/A.y,left:(x.left-I.left+_.left)/A.x,right:(I.right-x.right+_.right)/A.x}}const xle=50,Sle=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:wle},u=await(o.isRTL==null?void 0:o.isRTL(t));let d=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:f,y:h}=fI(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:T}=S,{x:k,y:A,data:I,reset:R}=await T({x:f,y:h,initialPlacement:r,placement:v,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=k??f,h=A??h,_[x]={..._[x],...I},R&&g<xle&&(g++,typeof R=="object"&&(R.placement&&(v=R.placement),R.rects&&(d=R.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):R.rects),{x:f,y:h}=fI(d,v,u)),w=-1)}return{x:f,y:h,placement:v,strategy:i,middlewareData:_}},Ele=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}=Ya(e,t)||{};if(d==null)return{};const h=O3(f),v={x:n,y:r},g=Mk(i),_=Nk(g),w=await o.getDimensions(d),S=g==="y",x=S?"top":"left",T=S?"bottom":"right",k=S?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[g]-v[g]-s.floating[_],I=v[g]-s.reference[g],R=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let M=R?R[k]:0;(!M||!await(o.isElement==null?void 0:o.isElement(R)))&&(M=l.floating[k]||s.floating[_]);const z=A/2-I/2,Y=M/2-w[_]/2-1,W=nc(h[x],Y),G=nc(h[T],Y),O=W,N=M-w[_]-G,L=M/2-w[_]/2+z,D=T1(O,L,N),P=!u.arrow&&xf(i)!=null&&L!==D&&s.reference[_]/2-(L<O?W:G)-w[_]/2<0,B=P?L<O?L-O:L-N:0;return{[g]:v[g]+B,data:{[g]:D,centerOffset:L-D-B,...P&&{alignmentOffset:B}},reset:P}}}),Cle=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:h=!0,fallbackPlacements:v,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=Ya(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Va(i),T=sa(l),k=Va(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),I=v||(k||!w?[Uy(l)]:mle(l)),R=_!=="none";!v&&R&&I.push(...ble(l,w,_,A));const M=[l,...I],z=await u.detectOverflow(t,S),Y=[];let W=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&Y.push(z[x]),h){const L=ple(i,o,A);Y.push(z[L[0]],z[L[1]])}if(W=[...W,{placement:i,overflows:Y}],!Y.every(L=>L<=0)){var G,O;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,D=M[L];if(D&&(!(h==="alignment"?T!==sa(D):!1)||W.every(F=>sa(F.placement)===T?F.overflows[0]>0:!0)))return{data:{index:L,overflows:W},reset:{placement:D}};let P=(O=W.filter(B=>B.overflows[0]<=0).sort((B,F)=>B.overflows[1]-F.overflows[1])[0])==null?void 0:O.placement;if(!P)switch(g){case"bestFit":{var N;const B=(N=W.filter(F=>{if(R){const U=sa(F.placement);return U===T||U==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(U=>U>0).reduce((U,j)=>U+j,0)]).sort((F,U)=>F[1]-U[1])[0])==null?void 0:N[0];B&&(P=B);break}case"initialPlacement":P=l;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function hI(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function pI(e){return fle.some(t=>e[t]>=0)}const kle=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=Ya(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=hI(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:pI(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=hI(o,n.floating);return{data:{escapedOffsets:l,escaped:pI(l)}}}default:return{}}}}},L3=new Set(["left","top"]);async function Tle(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Va(n),l=xf(n),u=sa(n)==="y",d=L3.has(o)?-1:1,f=s&&u?-1:1,h=Ya(t,e);let{mainAxis:v,crossAxis:g,alignmentAxis:_}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof _=="number"&&(g=l==="end"?_*-1:_),u?{x:g*f,y:v*d}:{x:v*d,y:g*f}}const Rle=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 Tle(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}}}}},Ale=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:T,y:k}=x;return{x:T,y:k}}},...d}=Ya(e,t),f={x:n,y:r},h=await s.detectOverflow(t,d),v=sa(Va(i)),g=Ak(v);let _=f[g],w=f[v];if(o){const x=g==="y"?"top":"left",T=g==="y"?"bottom":"right",k=_+h[x],A=_-h[T];_=T1(k,_,A)}if(l){const x=v==="y"?"top":"left",T=v==="y"?"bottom":"right",k=w+h[x],A=w-h[T];w=T1(k,w,A)}const S=u.fn({...t,[g]:_,[v]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[g]:o,[v]:l}}}}}},Nle=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}=Ya(e,t),f={x:n,y:r},h=sa(i),v=Ak(h);let g=f[v],_=f[h];const w=Ya(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const k=v==="y"?"height":"width",A=s.reference[v]-s.floating[k]+S.mainAxis,I=s.reference[v]+s.reference[k]-S.mainAxis;g<A?g=A:g>I&&(g=I)}if(d){var x,T;const k=v==="y"?"width":"height",A=L3.has(Va(i)),I=s.reference[h]-s.floating[k]+(A&&((x=o.offset)==null?void 0:x[h])||0)+(A?0:S.crossAxis),R=s.reference[h]+s.reference[k]+(A?0:((T=o.offset)==null?void 0:T[h])||0)-(A?S.crossAxis:0);_<I?_=I:_>R&&(_=R)}return{[v]:g,[h]:_}}}},Mle=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}=Ya(e,t),f=await o.detectOverflow(t,d),h=Va(i),v=xf(i),g=sa(i)==="y",{width:_,height:w}=s.floating;let S,x;h==="top"||h==="bottom"?(S=h,x=v===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=h,S=v==="end"?"top":"bottom");const T=w-f.top-f.bottom,k=_-f.left-f.right,A=nc(w-f[S],T),I=nc(_-f[x],k),R=!t.middlewareData.shift;let M=A,z=I;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(z=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(M=T),R&&!v){const W=Ws(f.left,0),G=Ws(f.right,0),O=Ws(f.top,0),N=Ws(f.bottom,0);g?z=_-2*(W!==0||G!==0?W+G:Ws(f.left,f.right)):M=w-2*(O!==0||N!==0?O+N:Ws(f.top,f.bottom))}await u({...t,availableWidth:z,availableHeight:M});const Y=await o.getDimensions(l.floating);return _!==Y.width||w!==Y.height?{reset:{rects:!0}}:{}}}};function Bb(){return typeof window<"u"}function Sf(e){return D3(e)?(e.nodeName||"").toLowerCase():"#document"}function Vs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ma(e){var t;return(t=(D3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function D3(e){return Bb()?e instanceof Node||e instanceof Vs(e).Node:!1}function Bo(e){return Bb()?e instanceof Element||e instanceof Vs(e).Element:!1}function Za(e){return Bb()?e instanceof HTMLElement||e instanceof Vs(e).HTMLElement:!1}function mI(e){return!Bb()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vs(e).ShadowRoot}function Em(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=zo(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Ple(e){return/^(table|td|th)$/.test(Sf(e))}function zb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Ile=/transform|translate|scale|rotate|perspective|filter/,Ole=/paint|layout|strict|content/,$c=e=>!!e&&e!=="none";let x0;function Pk(e){const t=Bo(e)?zo(e):e;return $c(t.transform)||$c(t.translate)||$c(t.scale)||$c(t.rotate)||$c(t.perspective)||!Ik()&&($c(t.backdropFilter)||$c(t.filter))||Ile.test(t.willChange||"")||Ole.test(t.contain||"")}function Lle(e){let t=rc(e);for(;Za(t)&&!lf(t);){if(Pk(t))return t;if(zb(t))return null;t=rc(t)}return null}function Ik(){return x0==null&&(x0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),x0}function lf(e){return/^(html|body|#document)$/.test(Sf(e))}function zo(e){return Vs(e).getComputedStyle(e)}function jb(e){return Bo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function rc(e){if(Sf(e)==="html")return e;const t=e.assignedSlot||e.parentNode||mI(e)&&e.host||ma(e);return mI(t)?t.host:t}function B3(e){const t=rc(e);return lf(t)?e.ownerDocument?e.ownerDocument.body:e.body:Za(t)&&Em(t)?t:B3(t)}function Zp(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=B3(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Vs(i);if(s){const l=A1(o);return t.concat(o,o.visualViewport||[],Em(i)?i:[],l&&n?Zp(l):[])}else return t.concat(i,Zp(i,[],n))}function A1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function z3(e){const t=zo(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Za(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=$y(n)!==s||$y(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function Ok(e){return Bo(e)?e:e.contextElement}function Gd(e){const t=Ok(e);if(!Za(t))return la(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=z3(t);let o=(s?$y(n.width):n.width)/r,l=(s?$y(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Dle=la(0);function j3(e){const t=Vs(e);return!Ik()||!t.visualViewport?Dle:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ble(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Vs(e)?!1:t}function fu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=Ok(e);let o=la(1);t&&(r?Bo(r)&&(o=Gd(r)):o=Gd(e));const l=Ble(s,n,r)?j3(s):la(0);let u=(i.left+l.x)/o.x,d=(i.top+l.y)/o.y,f=i.width/o.x,h=i.height/o.y;if(s){const v=Vs(s),g=r&&Bo(r)?Vs(r):r;let _=v,w=A1(_);for(;w&&r&&g!==_;){const S=Gd(w),x=w.getBoundingClientRect(),T=zo(w),k=x.left+(w.clientLeft+parseFloat(T.paddingLeft))*S.x,A=x.top+(w.clientTop+parseFloat(T.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,h*=S.y,u+=k,d+=A,_=Vs(w),w=A1(_)}}return Wy({width:f,height:h,x:u,y:d})}function Fb(e,t){const n=jb(e).scrollLeft;return t?t.left+n:fu(ma(e)).left+n}function F3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Fb(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function zle(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=ma(r),l=t?zb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=la(1);const f=la(0),h=Za(r);if((h||!h&&!s)&&((Sf(r)!=="body"||Em(o))&&(u=jb(r)),h)){const g=fu(r);d=Gd(r),f.x=g.x+r.clientLeft,f.y=g.y+r.clientTop}const v=o&&!h&&!s?F3(o,u):la(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 jle(e){return Array.from(e.getClientRects())}function Fle(e){const t=ma(e),n=jb(e),r=e.ownerDocument.body,i=Ws(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ws(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Fb(e);const l=-n.scrollTop;return zo(r).direction==="rtl"&&(o+=Ws(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const gI=25;function Hle(e,t){const n=Vs(e),r=ma(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=Ik();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Fb(r);if(d<=0){const f=r.ownerDocument,h=f.body,v=getComputedStyle(h),g=f.compatMode==="CSS1Compat"&&parseFloat(v.marginLeft)+parseFloat(v.marginRight)||0,_=Math.abs(r.clientWidth-h.clientWidth-g);_<=gI&&(s-=_)}else d<=gI&&(s+=d);return{width:s,height:o,x:l,y:u}}function $le(e,t){const n=fu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Za(e)?Gd(e):la(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 vI(e,t,n){let r;if(t==="viewport")r=Hle(e,n);else if(t==="document")r=Fle(ma(e));else if(Bo(t))r=$le(t,n);else{const i=j3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Wy(r)}function H3(e,t){const n=rc(e);return n===t||!Bo(n)||lf(n)?!1:zo(n).position==="fixed"||H3(n,t)}function Ule(e,t){const n=t.get(e);if(n)return n;let r=Zp(e,[],!1).filter(l=>Bo(l)&&Sf(l)!=="body"),i=null;const s=zo(e).position==="fixed";let o=s?rc(e):e;for(;Bo(o)&&!lf(o);){const l=zo(o),u=Pk(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Em(o)&&!u&&H3(e,o))?r=r.filter(f=>f!==o):i=l,o=rc(o)}return t.set(e,r),r}function Wle(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?zb(t)?[]:Ule(t,this._c):[].concat(n),r],l=vI(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,h=l.left;for(let v=1;v<o.length;v++){const g=vI(t,o[v],i);u=Ws(g.top,u),d=nc(g.right,d),f=nc(g.bottom,f),h=Ws(g.left,h)}return{width:d-h,height:f-u,x:h,y:u}}function qle(e){const{width:t,height:n}=z3(e);return{width:t,height:n}}function Yle(e,t,n){const r=Za(t),i=ma(t),s=n==="fixed",o=fu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=la(0);function d(){u.x=Fb(i)}if(r||!r&&!s)if((Sf(t)!=="body"||Em(i))&&(l=jb(t)),r){const g=fu(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?F3(i,l):la(0),h=o.left+l.scrollLeft-u.x-f.x,v=o.top+l.scrollTop-u.y-f.y;return{x:h,y:v,width:o.width,height:o.height}}function S0(e){return zo(e).position==="static"}function yI(e,t){if(!Za(e)||zo(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ma(e)===n&&(n=n.ownerDocument.body),n}function $3(e,t){const n=Vs(e);if(zb(e))return n;if(!Za(e)){let i=rc(e);for(;i&&!lf(i);){if(Bo(i)&&!S0(i))return i;i=rc(i)}return n}let r=yI(e,t);for(;r&&Ple(r)&&S0(r);)r=yI(r,t);return r&&lf(r)&&S0(r)&&!Pk(r)?n:r||Lle(e)||n}const Vle=async function(e){const t=this.getOffsetParent||$3,n=this.getDimensions,r=await n(e.floating);return{reference:Yle(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Kle(e){return zo(e).direction==="rtl"}const Gle={convertOffsetParentRelativeRectToViewportRelativeRect:zle,getDocumentElement:ma,getClippingRect:Wle,getOffsetParent:$3,getElementRects:Vle,getClientRects:jle,getDimensions:qle,getScale:Gd,isElement:Bo,isRTL:Kle};function U3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Xle(e,t){let n=null,r;const i=ma(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:h,width:v,height:g}=d;if(l||t(),!v||!g)return;const _=kv(h),w=kv(i.clientWidth-(f+v)),S=kv(i.clientHeight-(h+g)),x=kv(f),k={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:Ws(0,nc(1,u))||1};let A=!0;function I(R){const M=R[0].intersectionRatio;if(M!==u){if(!A)return o();M?o(!1,M):r=setTimeout(()=>{o(!1,1e-7)},1e3)}M===1&&!U3(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(I,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(I,k)}n.observe(e)}return o(!0),s}function Zle(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=Ok(e),f=i||s?[...d?Zp(d):[],...t?Zp(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const h=d&&l?Xle(d,n):null;let v=-1,g=null;o&&(g=new ResizeObserver(x=>{let[T]=x;T&&T.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?fu(e):null;u&&S();function S(){const x=fu(e);w&&!U3(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(T=>{i&&T.removeEventListener("scroll",n),s&&T.removeEventListener("resize",n)}),h==null||h(),(x=g)==null||x.disconnect(),g=null,u&&cancelAnimationFrame(_)}}const Jle=Rle,Qle=Ale,ece=Cle,tce=Mle,nce=kle,bI=Ele,rce=Nle,ice=(e,t,n)=>{const r=new Map,i={platform:Gle,...n},s={...i.platform,_c:r};return Sle(e,t,{...i,platform:s})};var sce=typeof document<"u",oce=function(){},py=sce?b.useLayoutEffect:oce;function qy(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(!qy(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)&&!qy(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function W3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function _I(e,t){const n=W3(e);return Math.round(t*n)/n}function E0(e){const t=b.useRef(e);return py(()=>{t.current=e}),t}function ace(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,h]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[v,g]=b.useState(r);qy(v,r)||g(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),T=b.useCallback(F=>{F!==R.current&&(R.current=F,w(F))},[]),k=b.useCallback(F=>{F!==M.current&&(M.current=F,x(F))},[]),A=s||_,I=o||S,R=b.useRef(null),M=b.useRef(null),z=b.useRef(f),Y=u!=null,W=E0(u),G=E0(i),O=E0(d),N=b.useCallback(()=>{if(!R.current||!M.current)return;const F={placement:t,strategy:n,middleware:v};G.current&&(F.platform=G.current),ice(R.current,M.current,F).then(U=>{const j={...U,isPositioned:O.current!==!1};L.current&&!qy(z.current,j)&&(z.current=j,Eu.flushSync(()=>{h(j)}))})},[v,t,n,G,O]);py(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,h(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);py(()=>(L.current=!0,()=>{L.current=!1}),[]),py(()=>{if(A&&(R.current=A),I&&(M.current=I),A&&I){if(W.current)return W.current(A,I,N);N()}},[A,I,N,W,Y]);const D=b.useMemo(()=>({reference:R,floating:M,setReference:T,setFloating:k}),[T,k]),P=b.useMemo(()=>({reference:A,floating:I}),[A,I]),B=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!P.floating)return F;const U=_I(P.floating,f.x),j=_I(P.floating,f.y);return l?{...F,transform:"translate("+U+"px, "+j+"px)",...W3(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:j}},[n,l,P.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:N,refs:D,elements:P,floatingStyles:B}),[f,N,D,P,B])}const lce=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?bI({element:r.current,padding:i}).fn(n):{}:r?bI({element:r,padding:i}).fn(n):{}}}},cce=(e,t)=>{const n=Jle(e);return{name:n.name,fn:n.fn,options:[e,t]}},uce=(e,t)=>{const n=Qle(e);return{name:n.name,fn:n.fn,options:[e,t]}},dce=(e,t)=>({fn:rce(e).fn,options:[e,t]}),fce=(e,t)=>{const n=ece(e);return{name:n.name,fn:n.fn,options:[e,t]}},hce=(e,t)=>{const n=tce(e);return{name:n.name,fn:n.fn,options:[e,t]}},pce=(e,t)=>{const n=nce(e);return{name:n.name,fn:n.fn,options:[e,t]}},mce=(e,t)=>{const n=lce(e);return{name:n.name,fn:n.fn,options:[e,t]}};var gce="Arrow",q3=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(Sn.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"})})});q3.displayName=gce;var vce=q3,Lk="Popper",[Y3,fc]=Xa(Lk),[yce,V3]=Y3(Lk),K3=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(yce,{scope:t,anchor:r,onAnchorChange:i,children:n})};K3.displayName=Lk;var G3="PopperAnchor",X3=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=V3(G3,n),o=b.useRef(null),l=dr(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(Sn.div,{...i,ref:l})});X3.displayName=G3;var Dk="PopperContent",[bce,_ce]=Y3(Dk),Z3=b.forwardRef((e,t)=>{var Z,ce,ie,me,ge,ve;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:h="partial",hideWhenDetached:v=!1,updatePositionStrategy:g="optimized",onPlaced:_,...w}=e,S=V3(Dk,n),[x,T]=b.useState(null),k=dr(t,Te=>T(Te)),[A,I]=b.useState(null),R=dle(A),M=(R==null?void 0:R.width)??0,z=(R==null?void 0:R.height)??0,Y=r+(s!=="center"?"-"+s:""),W=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},G=Array.isArray(d)?d:[d],O=G.length>0,N={padding:W,boundary:G.filter(xce),altBoundary:O},{refs:L,floatingStyles:D,placement:P,isPositioned:B,middlewareData:F}=ace({strategy:"fixed",placement:Y,whileElementsMounted:(...Te)=>Zle(...Te,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[cce({mainAxis:i+z,alignmentAxis:o}),u&&uce({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?dce():void 0,...N}),u&&fce({...N}),hce({...N,apply:({elements:Te,rects:Xe,availableWidth:wt,availableHeight:et})=>{const{width:ft,height:Ne}=Xe.reference,Ue=Te.floating.style;Ue.setProperty("--radix-popper-available-width",`${wt}px`),Ue.setProperty("--radix-popper-available-height",`${et}px`),Ue.setProperty("--radix-popper-anchor-width",`${ft}px`),Ue.setProperty("--radix-popper-anchor-height",`${Ne}px`)}}),A&&mce({element:A,padding:l}),Sce({arrowWidth:M,arrowHeight:z}),v&&pce({strategy:"referenceHidden",...N})]}),[U,j]=e4(P),V=Do(_);rs(()=>{B&&(V==null||V())},[B,V]);const X=(Z=F.arrow)==null?void 0:Z.x,H=(ce=F.arrow)==null?void 0:ce.y,Q=((ie=F.arrow)==null?void 0:ie.centerOffset)!==0,[ne,te]=b.useState();return rs(()=>{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:ne,"--radix-popper-transform-origin":[(me=F.transformOrigin)==null?void 0:me.x,(ge=F.transformOrigin)==null?void 0:ge.y].join(" "),...((ve=F.hide)==null?void 0:ve.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(bce,{scope:n,placedSide:U,onArrowChange:I,arrowX:X,arrowY:H,shouldHideArrow:Q,children:m.jsx(Sn.div,{"data-side":U,"data-align":j,...w,ref:k,style:{...w.style,animation:B?void 0:"none"}})})})});Z3.displayName=Dk;var J3="PopperArrow",wce={top:"bottom",right:"left",bottom:"top",left:"right"},Q3=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=_ce(J3,r),o=wce[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(vce,{...i,ref:n,style:{...i.style,display:"block"}})})});Q3.displayName=J3;function xce(e){return e!==null}var Sce=e=>({name:"transformOrigin",options:e,fn(t){var S,x,T;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]=e4(n),h={start:"0%",center:"50%",end:"100%"}[f],v=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,g=(((T=i.arrow)==null?void 0:T.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?h:`${v}px`,w=`${-u}px`):d==="top"?(_=o?h:`${v}px`,w=`${r.floating.height+u}px`):d==="right"?(_=`${-u}px`,w=o?h:`${g}px`):d==="left"&&(_=`${r.floating.width+u}px`,w=o?h:`${g}px`),{data:{x:_,y:w}}}});function e4(e){const[t,n="center"]=e.split("-");return[t,n]}var Cm=K3,km=X3,Hb=Z3,$b=Q3,C0="rovingFocusGroup.onEntryFocus",Ece={bubbles:!1,cancelable:!0},Tm="RovingFocusGroup",[N1,t4,Cce]=_k(Tm),[kce,n4]=Xa(Tm,[Cce]),[Tce,Rce]=kce(Tm),r4=b.forwardRef((e,t)=>m.jsx(N1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(N1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(Ace,{...e,ref:t})})}));r4.displayName=Tm;var Ace=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,...h}=e,v=b.useRef(null),g=dr(t,v),_=wk(s),[w,S]=tc({prop:o,defaultProp:l??null,onChange:u,caller:Tm}),[x,T]=b.useState(!1),k=Do(d),A=t4(n),I=b.useRef(!1),[R,M]=b.useState(0);return b.useEffect(()=>{const z=v.current;if(z)return z.addEventListener(C0,k),()=>z.removeEventListener(C0,k)},[k]),m.jsx(Tce,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(z=>S(z),[S]),onItemShiftTab:b.useCallback(()=>T(!0),[]),onFocusableItemAdd:b.useCallback(()=>M(z=>z+1),[]),onFocusableItemRemove:b.useCallback(()=>M(z=>z-1),[]),children:m.jsx(Sn.div,{tabIndex:x||R===0?-1:0,"data-orientation":r,...h,ref:g,style:{outline:"none",...e.style},onMouseDown:qt(e.onMouseDown,()=>{I.current=!0}),onFocus:qt(e.onFocus,z=>{const Y=!I.current;if(z.target===z.currentTarget&&Y&&!x){const W=new CustomEvent(C0,Ece);if(z.currentTarget.dispatchEvent(W),!W.defaultPrevented){const G=A().filter(P=>P.focusable),O=G.find(P=>P.active),N=G.find(P=>P.id===w),D=[O,N,...G].filter(Boolean).map(P=>P.ref.current);o4(D,f)}}I.current=!1}),onBlur:qt(e.onBlur,()=>T(!1))})})}),i4="RovingFocusGroupItem",s4=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=bi(),d=s||u,f=Rce(i4,n),h=f.currentTabStopId===d,v=t4(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(N1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(Sn.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:qt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:qt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:qt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=Pce(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(A=>A.focusable).map(A=>A.ref.current);if(x==="last")k.reverse();else if(x==="prev"||x==="next"){x==="prev"&&k.reverse();const A=k.indexOf(S.currentTarget);k=f.loop?Ice(k,A+1):k.slice(A+1)}setTimeout(()=>o4(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:w!=null}):o})})});s4.displayName=i4;var Nce={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Mce(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Pce(e,t,n){const r=Mce(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Nce[r]}function o4(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ice(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Oce=r4,Lce=s4,M1=["Enter"," "],Dce=["ArrowDown","PageUp","Home"],a4=["ArrowUp","PageDown","End"],Bce=[...Dce,...a4],zce={ltr:[...M1,"ArrowRight"],rtl:[...M1,"ArrowLeft"]},jce={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Rm="Menu",[Jp,Fce,Hce]=_k(Rm),[Cu,l4]=Xa(Rm,[Hce,fc,n4]),Am=fc(),c4=n4(),[u4,hc]=Cu(Rm),[$ce,Nm]=Cu(Rm),d4=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Am(t),[u,d]=b.useState(null),f=b.useRef(!1),h=Do(s),v=wk(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(Cm,{...l,children:m.jsx(u4,{scope:t,open:n,onOpenChange:h,content:u,onContentChange:d,children:m.jsx($ce,{scope:t,onClose:b.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:f,dir:v,modal:o,children:r})})})};d4.displayName=Rm;var Uce="MenuAnchor",Bk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Am(n);return m.jsx(km,{...i,...r,ref:t})});Bk.displayName=Uce;var zk="MenuPortal",[Wce,f4]=Cu(zk,{forceMount:void 0}),h4=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=hc(zk,t);return m.jsx(Wce,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};h4.displayName=zk;var go="MenuContent",[qce,jk]=Cu(go),p4=b.forwardRef((e,t)=>{const n=f4(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hc(go,e.__scopeMenu),o=Nm(go,e.__scopeMenu);return m.jsx(Jp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Jp.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Yce,{...i,ref:t}):m.jsx(Vce,{...i,ref:t})})})})}),Yce=b.forwardRef((e,t)=>{const n=hc(go,e.__scopeMenu),r=b.useRef(null),i=dr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Ob(s)},[]),m.jsx(Fk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:qt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Vce=b.forwardRef((e,t)=>{const n=hc(go,e.__scopeMenu);return m.jsx(Fk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Kce=ec("MenuContent.ScrollLock"),Fk=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:h,onInteractOutside:v,onDismiss:g,disableOutsideScroll:_,...w}=e,S=hc(go,n),x=Nm(go,n),T=Am(n),k=c4(n),A=Fce(n),[I,R]=b.useState(null),M=b.useRef(null),z=dr(t,M,S.onContentChange),Y=b.useRef(0),W=b.useRef(""),G=b.useRef(0),O=b.useRef(null),N=b.useRef("right"),L=b.useRef(0),D=_?Sm:b.Fragment,P=_?{as:Kce,allowPinchZoom:!0}:void 0,B=U=>{var Z,ce;const j=W.current+U,V=A().filter(ie=>!ie.disabled),X=document.activeElement,H=(Z=V.find(ie=>ie.ref.current===X))==null?void 0:Z.textValue,Q=V.map(ie=>ie.textValue),ne=oue(Q,j,H),te=(ce=V.find(ie=>ie.textValue===ne))==null?void 0:ce.ref.current;(function ie(me){W.current=me,window.clearTimeout(Y.current),me!==""&&(Y.current=window.setTimeout(()=>ie(""),1e3))})(j),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(Y.current),[]),Pb();const F=b.useCallback(U=>{var V,X;return N.current===((V=O.current)==null?void 0:V.side)&&lue(U,(X=O.current)==null?void 0:X.area)},[]);return m.jsx(qce,{scope:n,searchRef:W,onItemEnter:b.useCallback(U=>{F(U)&&U.preventDefault()},[F]),onItemLeave:b.useCallback(U=>{var j;F(U)||((j=M.current)==null||j.focus(),R(null))},[F]),onTriggerLeave:b.useCallback(U=>{F(U)&&U.preventDefault()},[F]),pointerGraceTimerRef:G,onPointerGraceIntentChange:b.useCallback(U=>{O.current=U},[]),children:m.jsx(D,{...P,children:m.jsx(xm,{asChild:!0,trapped:i,onMountAutoFocus:qt(s,U=>{var j;U.preventDefault(),(j=M.current)==null||j.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:h,onInteractOutside:v,onDismiss:g,children:m.jsx(Oce,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:R,onEntryFocus:qt(u,U=>{x.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(Hb,{role:"menu","aria-orientation":"vertical","data-state":M4(S.open),"data-radix-menu-content":"",dir:x.dir,...T,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:qt(w.onKeyDown,U=>{const V=U.target.closest("[data-radix-menu-content]")===U.currentTarget,X=U.ctrlKey||U.altKey||U.metaKey,H=U.key.length===1;V&&(U.key==="Tab"&&U.preventDefault(),!X&&H&&B(U.key));const Q=M.current;if(U.target!==Q||!Bce.includes(U.key))return;U.preventDefault();const te=A().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);a4.includes(U.key)&&te.reverse(),iue(te)}),onBlur:qt(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(Y.current),W.current="")}),onPointerMove:qt(e.onPointerMove,Qp(U=>{const j=U.target,V=L.current!==U.clientX;if(U.currentTarget.contains(j)&&V){const X=U.clientX>L.current?"right":"left";N.current=X,L.current=U.clientX}}))})})})})})})});p4.displayName=go;var Gce="MenuGroup",Hk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(Sn.div,{role:"group",...r,ref:t})});Hk.displayName=Gce;var Xce="MenuLabel",m4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(Sn.div,{...r,ref:t})});m4.displayName=Xce;var Yy="MenuItem",wI="menu.itemSelect",Ub=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Nm(Yy,e.__scopeMenu),l=jk(Yy,e.__scopeMenu),u=dr(t,s),d=b.useRef(!1),f=()=>{const h=s.current;if(!n&&h){const v=new CustomEvent(wI,{bubbles:!0,cancelable:!0});h.addEventListener(wI,g=>r==null?void 0:r(g),{once:!0}),t3(h,v),v.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(g4,{...i,ref:u,disabled:n,onClick:qt(e.onClick,f),onPointerDown:h=>{var v;(v=e.onPointerDown)==null||v.call(e,h),d.current=!0},onPointerUp:qt(e.onPointerUp,h=>{var v;d.current||(v=h.currentTarget)==null||v.click()}),onKeyDown:qt(e.onKeyDown,h=>{const v=l.searchRef.current!=="";n||v&&h.key===" "||M1.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Ub.displayName=Yy;var g4=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=jk(Yy,n),l=c4(n),u=b.useRef(null),d=dr(t,u),[f,h]=b.useState(!1),[v,g]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&g((_.textContent??"").trim())},[s.children]),m.jsx(Jp.ItemSlot,{scope:n,disabled:r,textValue:i??v,children:m.jsx(Lce,{asChild:!0,...l,focusable:!r,children:m.jsx(Sn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:qt(e.onPointerMove,Qp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:qt(e.onPointerLeave,Qp(_=>o.onItemLeave(_))),onFocus:qt(e.onFocus,()=>h(!0)),onBlur:qt(e.onBlur,()=>h(!1))})})})}),Zce="MenuCheckboxItem",v4=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(x4,{scope:e.__scopeMenu,checked:n,children:m.jsx(Ub,{role:"menuitemcheckbox","aria-checked":Vy(n)?"mixed":n,...i,ref:t,"data-state":Wk(n),onSelect:qt(i.onSelect,()=>r==null?void 0:r(Vy(n)?!0:!n),{checkForDefaultPrevented:!1})})})});v4.displayName=Zce;var y4="MenuRadioGroup",[Jce,Qce]=Cu(y4,{value:void 0,onValueChange:()=>{}}),b4=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Do(r);return m.jsx(Jce,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(Hk,{...i,ref:t})})});b4.displayName=y4;var _4="MenuRadioItem",w4=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=Qce(_4,e.__scopeMenu),s=n===i.value;return m.jsx(x4,{scope:e.__scopeMenu,checked:s,children:m.jsx(Ub,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Wk(s),onSelect:qt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});w4.displayName=_4;var $k="MenuItemIndicator",[x4,eue]=Cu($k,{checked:!1}),S4=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=eue($k,n);return m.jsx(xo,{present:r||Vy(s.checked)||s.checked===!0,children:m.jsx(Sn.span,{...i,ref:t,"data-state":Wk(s.checked)})})});S4.displayName=$k;var tue="MenuSeparator",E4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(Sn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});E4.displayName=tue;var nue="MenuArrow",C4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Am(n);return m.jsx($b,{...i,...r,ref:t})});C4.displayName=nue;var Uk="MenuSub",[rue,k4]=Cu(Uk),T4=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=hc(Uk,t),o=Am(t),[l,u]=b.useState(null),[d,f]=b.useState(null),h=Do(i);return b.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),m.jsx(Cm,{...o,children:m.jsx(u4,{scope:t,open:r,onOpenChange:h,content:d,onContentChange:f,children:m.jsx(rue,{scope:t,contentId:bi(),triggerId:bi(),trigger:l,onTriggerChange:u,children:n})})})};T4.displayName=Uk;var fp="MenuSubTrigger",R4=b.forwardRef((e,t)=>{const n=hc(fp,e.__scopeMenu),r=Nm(fp,e.__scopeMenu),i=k4(fp,e.__scopeMenu),s=jk(fp,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 h=l.current;return()=>{window.clearTimeout(h),u(null)}},[l,u]),m.jsx(Bk,{asChild:!0,...d,children:m.jsx(g4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":M4(n.open),...e,ref:qa(t,i.onTriggerChange),onClick:h=>{var v;(v=e.onClick)==null||v.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:qt(e.onPointerMove,Qp(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:qt(e.onPointerLeave,Qp(h=>{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,T=v[S?"left":"right"],k=v[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+x,y:h.clientY},{x:T,y:v.top},{x:k,y:v.top},{x:k,y:v.bottom},{x:T,y:v.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:qt(e.onKeyDown,h=>{var g;const v=s.searchRef.current!=="";e.disabled||v&&h.key===" "||zce[r.dir].includes(h.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),h.preventDefault())})})})});R4.displayName=fp;var A4="MenuSubContent",N4=b.forwardRef((e,t)=>{const n=f4(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hc(go,e.__scopeMenu),o=Nm(go,e.__scopeMenu),l=k4(A4,e.__scopeMenu),u=b.useRef(null),d=dr(t,u);return m.jsx(Jp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Jp.Slot,{scope:e.__scopeMenu,children:m.jsx(Fk,{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 h;o.isUsingKeyboardRef.current&&((h=u.current)==null||h.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:qt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:qt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:qt(e.onKeyDown,f=>{var g;const h=f.currentTarget.contains(f.target),v=jce[o.dir].includes(f.key);h&&v&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});N4.displayName=A4;function M4(e){return e?"open":"closed"}function Vy(e){return e==="indeterminate"}function Wk(e){return Vy(e)?"indeterminate":e?"checked":"unchecked"}function iue(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function sue(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function oue(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=sue(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 aue(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,h=u.x,v=u.y;f>r!=v>r&&n<(h-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function lue(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return aue(n,t)}function Qp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var cue=d4,uue=Bk,due=h4,fue=p4,hue=Hk,pue=m4,mue=Ub,gue=v4,vue=b4,yue=w4,bue=S4,_ue=E4,wue=C4,xue=T4,Sue=R4,Eue=N4,Wb="DropdownMenu",[Cue]=Xa(Wb,[l4]),is=l4(),[kue,P4]=Cue(Wb),I4=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=is(t),d=b.useRef(null),[f,h]=tc({prop:i,defaultProp:s??!1,onChange:o,caller:Wb});return m.jsx(kue,{scope:t,triggerId:bi(),triggerRef:d,contentId:bi(),open:f,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(v=>!v),[h]),modal:l,children:m.jsx(cue,{...u,open:f,onOpenChange:h,dir:r,modal:l,children:n})})};I4.displayName=Wb;var O4="DropdownMenuTrigger",L4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=P4(O4,n),o=is(n);return m.jsx(uue,{asChild:!0,...o,children:m.jsx(Sn.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:qa(t,s.triggerRef),onPointerDown:qt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:qt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});L4.displayName=O4;var Tue="DropdownMenuPortal",D4=e=>{const{__scopeDropdownMenu:t,...n}=e,r=is(t);return m.jsx(due,{...r,...n})};D4.displayName=Tue;var B4="DropdownMenuContent",z4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=P4(B4,n),s=is(n),o=b.useRef(!1);return m.jsx(fue,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:qt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:qt(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)"}})});z4.displayName=B4;var Rue="DropdownMenuGroup",Aue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(hue,{...i,...r,ref:t})});Aue.displayName=Rue;var Nue="DropdownMenuLabel",j4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(pue,{...i,...r,ref:t})});j4.displayName=Nue;var Mue="DropdownMenuItem",F4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(mue,{...i,...r,ref:t})});F4.displayName=Mue;var Pue="DropdownMenuCheckboxItem",H4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(gue,{...i,...r,ref:t})});H4.displayName=Pue;var Iue="DropdownMenuRadioGroup",Oue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(vue,{...i,...r,ref:t})});Oue.displayName=Iue;var Lue="DropdownMenuRadioItem",Due=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(yue,{...i,...r,ref:t})});Due.displayName=Lue;var Bue="DropdownMenuItemIndicator",$4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(bue,{...i,...r,ref:t})});$4.displayName=Bue;var zue="DropdownMenuSeparator",U4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(_ue,{...i,...r,ref:t})});U4.displayName=zue;var jue="DropdownMenuArrow",Fue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(wue,{...i,...r,ref:t})});Fue.displayName=jue;var Hue=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=is(t),[l,u]=tc({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return m.jsx(xue,{...o,open:l,onOpenChange:u,children:n})},$ue="DropdownMenuSubTrigger",W4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(Sue,{...i,...r,ref:t})});W4.displayName=$ue;var Uue="DropdownMenuSubContent",q4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=is(n);return m.jsx(Eue,{...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)"}})});q4.displayName=Uue;var Wue=I4,que=L4,Y4=D4,Yue=z4,Vue=j4,Kue=F4,Gue=H4,Xue=$4,Zue=U4,Jue=Hue,Que=W4,ede=q4;function xI(e,[t,n]){return Math.min(n,Math.max(t,e))}var qb="Popover",[V4]=Xa(qb,[fc]),Mm=fc(),[tde,pc]=V4(qb),K4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Mm(t),u=b.useRef(null),[d,f]=b.useState(!1),[h,v]=tc({prop:r,defaultProp:i??!1,onChange:s,caller:qb});return m.jsx(Cm,{...l,children:m.jsx(tde,{scope:t,contentId:bi(),triggerRef:u,open:h,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})})};K4.displayName=qb;var G4="PopoverAnchor",nde=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pc(G4,n),s=Mm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(km,{...s,...r,ref:t})});nde.displayName=G4;var X4="PopoverTrigger",Z4=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pc(X4,n),s=Mm(n),o=dr(t,i.triggerRef),l=m.jsx(Sn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":nF(i.open),...r,ref:o,onClick:qt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(km,{asChild:!0,...s,children:l})});Z4.displayName=X4;var qk="PopoverPortal",[rde,ide]=V4(qk,{forceMount:void 0}),J4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=pc(qk,t);return m.jsx(rde,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};J4.displayName=qk;var cf="PopoverContent",Q4=b.forwardRef((e,t)=>{const n=ide(cf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=pc(cf,e.__scopePopover);return m.jsx(xo,{present:r||s.open,children:s.modal?m.jsx(ode,{...i,ref:t}):m.jsx(ade,{...i,ref:t})})});Q4.displayName=cf;var sde=ec("PopoverContent.RemoveScroll"),ode=b.forwardRef((e,t)=>{const n=pc(cf,e.__scopePopover),r=b.useRef(null),i=dr(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return Ob(o)},[]),m.jsx(Sm,{as:sde,allowPinchZoom:!0,children:m.jsx(eF,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:qt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:qt(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:qt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),ade=b.forwardRef((e,t)=>{const n=pc(cf,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(eF,{...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&&d.contains(o)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),eF=b.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,...h}=e,v=pc(cf,n),g=Mm(n);return Pb(),m.jsx(xm,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>v.onOpenChange(!1),children:m.jsx(Hb,{"data-state":nF(v.open),role:"dialog",id:v.contentId,...g,...h,ref:t,style:{...h.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)"}})})})}),tF="PopoverClose",lde=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pc(tF,n);return m.jsx(Sn.button,{type:"button",...r,ref:t,onClick:qt(e.onClick,()=>i.onOpenChange(!1))})});lde.displayName=tF;var cde="PopoverArrow",ude=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Mm(n);return m.jsx($b,{...i,...r,ref:t})});ude.displayName=cde;function nF(e){return e?"open":"closed"}var dde=K4,fde=Z4,hde=J4,pde=Q4,mde=[" ","Enter","ArrowUp","ArrowDown"],gde=[" ","Enter"],hu="Select",[Yb,Vb,vde]=_k(hu),[Ef]=Xa(hu,[vde,fc]),Kb=fc(),[yde,mc]=Ef(hu),[bde,_de]=Ef(hu),rF=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:l,onValueChange:u,dir:d,name:f,autoComplete:h,disabled:v,required:g,form:_}=e,w=Kb(t),[S,x]=b.useState(null),[T,k]=b.useState(null),[A,I]=b.useState(!1),R=wk(d),[M,z]=tc({prop:r,defaultProp:i??!1,onChange:s,caller:hu}),[Y,W]=tc({prop:o,defaultProp:l,onChange:u,caller:hu}),G=b.useRef(null),O=S?_||!!S.closest("form"):!0,[N,L]=b.useState(new Set),D=Array.from(N).map(P=>P.props.value).join(";");return m.jsx(Cm,{...w,children:m.jsxs(yde,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:T,onValueNodeChange:k,valueNodeHasChildren:A,onValueNodeHasChildrenChange:I,contentId:bi(),value:Y,onValueChange:W,open:M,onOpenChange:z,dir:R,triggerPointerDownPosRef:G,disabled:v,children:[m.jsx(Yb.Provider,{scope:t,children:m.jsx(bde,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{L(B=>new Set(B).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{L(B=>{const F=new Set(B);return F.delete(P),F})},[]),children:n})}),O?m.jsxs(CF,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:h,value:Y,onChange:P=>W(P.target.value),disabled:v,form:_,children:[Y===void 0?m.jsx("option",{value:""}):null,Array.from(N)]},D):null]})})};rF.displayName=hu;var iF="SelectTrigger",sF=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Kb(n),o=mc(iF,n),l=o.disabled||r,u=dr(t,o.onTriggerChange),d=Vb(n),f=b.useRef("touch"),[h,v,g]=TF(w=>{const S=d().filter(k=>!k.disabled),x=S.find(k=>k.value===o.value),T=RF(S,w,x);T!==void 0&&o.onValueChange(T.value)}),_=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(km,{asChild:!0,...s,children:m.jsx(Sn.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":kF(o.value)?"":void 0,...i,ref:u,onClick:qt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:qt(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:qt(i.onKeyDown,w=>{const S=h.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&v(w.key),!(S&&w.key===" ")&&mde.includes(w.key)&&(_(),w.preventDefault())})})})});sF.displayName=iF;var oF="SelectValue",aF=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=mc(oF,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,h=dr(t,u.onValueNodeChange);return rs(()=>{d(f)},[d,f]),m.jsx(Sn.span,{...l,ref:h,style:{pointerEvents:"none"},children:kF(u.value)?m.jsx(m.Fragment,{children:o}):s})});aF.displayName=oF;var wde="SelectIcon",lF=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(Sn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});lF.displayName=wde;var xde="SelectPortal",cF=e=>m.jsx(wf,{asChild:!0,...e});cF.displayName=xde;var pu="SelectContent",uF=b.forwardRef((e,t)=>{const n=mc(pu,e.__scopeSelect),[r,i]=b.useState();if(rs(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?Eu.createPortal(m.jsx(dF,{scope:e.__scopeSelect,children:m.jsx(Yb.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(fF,{...e,ref:t})});uF.displayName=pu;var No=10,[dF,gc]=Ef(pu),Sde="SelectContentImpl",Ede=ec("SelectContent.RemoveScroll"),fF=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:h,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,T=mc(pu,n),[k,A]=b.useState(null),[I,R]=b.useState(null),M=dr(t,Z=>A(Z)),[z,Y]=b.useState(null),[W,G]=b.useState(null),O=Vb(n),[N,L]=b.useState(!1),D=b.useRef(!1);b.useEffect(()=>{if(k)return Ob(k)},[k]),Pb();const P=b.useCallback(Z=>{const[ce,...ie]=O().map(ve=>ve.ref.current),[me]=ie.slice(-1),ge=document.activeElement;for(const ve of Z)if(ve===ge||(ve==null||ve.scrollIntoView({block:"nearest"}),ve===ce&&I&&(I.scrollTop=0),ve===me&&I&&(I.scrollTop=I.scrollHeight),ve==null||ve.focus(),document.activeElement!==ge))return},[O,I]),B=b.useCallback(()=>P([z,k]),[P,z,k]);b.useEffect(()=>{N&&B()},[N,B]);const{onOpenChange:F,triggerPointerDownPosRef:U}=T;b.useEffect(()=>{if(k){let Z={x:0,y:0};const ce=me=>{var ge,ve;Z={x:Math.abs(Math.round(me.pageX)-(((ge=U.current)==null?void 0:ge.x)??0)),y:Math.abs(Math.round(me.pageY)-(((ve=U.current)==null?void 0:ve.y)??0))}},ie=me=>{Z.x<=10&&Z.y<=10?me.preventDefault():k.contains(me.target)||F(!1),document.removeEventListener("pointermove",ce),U.current=null};return U.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,U]),b.useEffect(()=>{const Z=()=>F(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[F]);const[j,V]=TF(Z=>{const ce=O().filter(ge=>!ge.disabled),ie=ce.find(ge=>ge.ref.current===document.activeElement),me=RF(ce,Z,ie);me&&setTimeout(()=>me.ref.current.focus())}),X=b.useCallback((Z,ce,ie)=>{const me=!D.current&&!ie;(T.value!==void 0&&T.value===ce||me)&&(Y(Z),me&&(D.current=!0))},[T.value]),H=b.useCallback(()=>k==null?void 0:k.focus(),[k]),Q=b.useCallback((Z,ce,ie)=>{const me=!D.current&&!ie;(T.value!==void 0&&T.value===ce||me)&&G(Z)},[T.value]),ne=r==="popper"?P1:hF,te=ne===P1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:h,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(dF,{scope:n,content:k,viewport:I,onViewportChange:R,itemRefCallback:X,selectedItem:z,onItemLeave:H,itemTextRefCallback:Q,focusSelectedItem:B,selectedItemText:W,position:r,isPositioned:N,searchRef:j,children:m.jsx(Sm,{as:Ede,allowPinchZoom:!0,children:m.jsx(xm,{asChild:!0,trapped:T.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:qt(i,Z=>{var ce;(ce=T.trigger)==null||ce.focus({preventScroll:!0}),Z.preventDefault()}),children:m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:m.jsx(ne,{role:"listbox",id:T.contentId,"data-state":T.open?"open":"closed",dir:T.dir,onContextMenu:Z=>Z.preventDefault(),...x,...te,onPlaced:()=>L(!0),ref:M,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:qt(x.onKeyDown,Z=>{const ce=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!ce&&Z.key.length===1&&V(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let me=O().filter(ge=>!ge.disabled).map(ge=>ge.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(me=me.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ge=Z.target,ve=me.indexOf(ge);me=me.slice(ve+1)}setTimeout(()=>P(me)),Z.preventDefault()}})})})})})})});fF.displayName=Sde;var Cde="SelectItemAlignedPosition",hF=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=mc(pu,n),o=gc(pu,n),[l,u]=b.useState(null),[d,f]=b.useState(null),h=dr(t,M=>f(M)),v=Vb(n),g=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:T}=o,k=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const M=s.trigger.getBoundingClientRect(),z=d.getBoundingClientRect(),Y=s.valueNode.getBoundingClientRect(),W=x.getBoundingClientRect();if(s.dir!=="rtl"){const ge=W.left-z.left,ve=Y.left-ge,Te=M.left-ve,Xe=M.width+Te,wt=Math.max(Xe,z.width),et=window.innerWidth-No,ft=xI(ve,[No,Math.max(No,et-wt)]);l.style.minWidth=Xe+"px",l.style.left=ft+"px"}else{const ge=z.right-W.right,ve=window.innerWidth-Y.right-ge,Te=window.innerWidth-M.right-ve,Xe=M.width+Te,wt=Math.max(Xe,z.width),et=window.innerWidth-No,ft=xI(ve,[No,Math.max(No,et-wt)]);l.style.minWidth=Xe+"px",l.style.right=ft+"px"}const G=v(),O=window.innerHeight-No*2,N=w.scrollHeight,L=window.getComputedStyle(d),D=parseInt(L.borderTopWidth,10),P=parseInt(L.paddingTop,10),B=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),U=D+P+N+F+B,j=Math.min(S.offsetHeight*5,U),V=window.getComputedStyle(w),X=parseInt(V.paddingTop,10),H=parseInt(V.paddingBottom,10),Q=M.top+M.height/2-No,ne=O-Q,te=S.offsetHeight/2,Z=S.offsetTop+te,ce=D+P+Z,ie=U-ce;if(ce<=Q){const ge=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const ve=d.clientHeight-w.offsetTop-w.offsetHeight,Te=Math.max(ne,te+(ge?H:0)+ve+B),Xe=ce+Te;l.style.height=Xe+"px"}else{const ge=G.length>0&&S===G[0].ref.current;l.style.top="0px";const Te=Math.max(Q,D+w.offsetTop+(ge?X:0)+te)+ie;l.style.height=Te+"px",w.scrollTop=ce-Q+w.offsetTop}l.style.margin=`${No}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]);rs(()=>k(),[k]);const[A,I]=b.useState();rs(()=>{d&&I(window.getComputedStyle(d).zIndex)},[d]);const R=b.useCallback(M=>{M&&_.current===!0&&(k(),T==null||T(),_.current=!1)},[k,T]);return m.jsx(Tde,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:R,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:m.jsx(Sn.div,{...i,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});hF.displayName=Cde;var kde="SelectPopperPosition",P1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=No,...s}=e,o=Kb(n);return m.jsx(Hb,{...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)"}})});P1.displayName=kde;var[Tde,Yk]=Ef(pu,{}),I1="SelectViewport",pF=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=gc(I1,n),o=Yk(I1,n),l=dr(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(Yb.Slot,{scope:n,children:m.jsx(Sn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:qt(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:h,shouldExpandOnScrollRef:v}=o;if(v!=null&&v.current&&h){const g=Math.abs(u.current-f.scrollTop);if(g>0){const _=window.innerHeight-No*2,w=parseFloat(h.style.minHeight),S=parseFloat(h.style.height),x=Math.max(w,S);if(x<_){const T=x+g,k=Math.min(_,T),A=T-k;h.style.height=k+"px",h.style.bottom==="0px"&&(f.scrollTop=A>0?A:0,h.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});pF.displayName=I1;var mF="SelectGroup",[Rde,Ade]=Ef(mF),Nde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bi();return m.jsx(Rde,{scope:n,id:i,children:m.jsx(Sn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});Nde.displayName=mF;var gF="SelectLabel",Mde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Ade(gF,n);return m.jsx(Sn.div,{id:i.id,...r,ref:t})});Mde.displayName=gF;var Ky="SelectItem",[Pde,vF]=Ef(Ky),yF=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=mc(Ky,n),u=gc(Ky,n),d=l.value===r,[f,h]=b.useState(s??""),[v,g]=b.useState(!1),_=dr(t,T=>{var k;return(k=u.itemRefCallback)==null?void 0:k.call(u,T,r,i)}),w=bi(),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(Pde,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(T=>{h(k=>k||((T==null?void 0:T.textContent)??"").trim())},[]),children:m.jsx(Yb.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(Sn.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:qt(o.onFocus,()=>g(!0)),onBlur:qt(o.onBlur,()=>g(!1)),onClick:qt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:qt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:qt(o.onPointerDown,T=>{S.current=T.pointerType}),onPointerMove:qt(o.onPointerMove,T=>{var k;S.current=T.pointerType,i?(k=u.onItemLeave)==null||k.call(u):S.current==="mouse"&&T.currentTarget.focus({preventScroll:!0})}),onPointerLeave:qt(o.onPointerLeave,T=>{var k;T.currentTarget===document.activeElement&&((k=u.onItemLeave)==null||k.call(u))}),onKeyDown:qt(o.onKeyDown,T=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&T.key===" "||(gde.includes(T.key)&&x(),T.key===" "&&T.preventDefault())})})})})});yF.displayName=Ky;var hp="SelectItemText",bF=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=mc(hp,n),l=gc(hp,n),u=vF(hp,n),d=_de(hp,n),[f,h]=b.useState(null),v=dr(t,x=>h(x),u.onItemTextChange,x=>{var T;return(T=l.itemTextRefCallback)==null?void 0:T.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 rs(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(Sn.span,{id:u.textId,...s,ref:v}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Eu.createPortal(s.children,o.valueNode):null]})});bF.displayName=hp;var _F="SelectItemIndicator",wF=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return vF(_F,n).isSelected?m.jsx(Sn.span,{"aria-hidden":!0,...r,ref:t}):null});wF.displayName=_F;var O1="SelectScrollUpButton",xF=b.forwardRef((e,t)=>{const n=gc(O1,e.__scopeSelect),r=Yk(O1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return rs(()=>{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(EF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});xF.displayName=O1;var L1="SelectScrollDownButton",SF=b.forwardRef((e,t)=>{const n=gc(L1,e.__scopeSelect),r=Yk(L1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return rs(()=>{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(EF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});SF.displayName=L1;var EF=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=gc("SelectScrollButton",n),o=b.useRef(null),l=Vb(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),rs(()=>{var f;const d=l().find(h=>h.ref.current===document.activeElement);(f=d==null?void 0:d.ref.current)==null||f.scrollIntoView({block:"nearest"})},[l]),m.jsx(Sn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:qt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:qt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:qt(i.onPointerLeave,()=>{u()})})}),Ide="SelectSeparator",Ode=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(Sn.div,{"aria-hidden":!0,...r,ref:t})});Ode.displayName=Ide;var D1="SelectArrow",Lde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Kb(n),s=mc(D1,n),o=gc(D1,n);return s.open&&o.position==="popper"?m.jsx($b,{...i,...r,ref:t}):null});Lde.displayName=D1;var Dde="SelectBubbleInput",CF=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=dr(r,i),o=ule(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 h=new Event("change",{bubbles:!0});f.call(l,t),l.dispatchEvent(h)}},[o,t]),m.jsx(Sn.select,{...n,style:{...n3,...n.style},ref:s,defaultValue:t})});CF.displayName=Dde;function kF(e){return e===""||e===void 0}function TF(e){const t=Do(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 RF(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=Bde(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 Bde(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var zde=rF,jde=sF,Fde=aF,Hde=lF,$de=cF,Ude=uF,Wde=pF,qde=yF,Yde=bF,Vde=wF,Kde=xF,Gde=SF,[Gb]=Xa("Tooltip",[fc]),Xb=fc(),AF="TooltipProvider",Xde=700,B1="tooltip.open",[Zde,Vk]=Gb(AF),NF=e=>{const{__scopeTooltip:t,delayDuration:n=Xde,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(Zde,{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})};NF.displayName=AF;var em="Tooltip",[Jde,Pm]=Gb(em),MF=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=Vk(em,e.__scopeTooltip),d=Xb(t),[f,h]=b.useState(null),v=bi(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,T]=tc({prop:r,defaultProp:i??!1,onChange:M=>{M?(u.onOpen(),document.dispatchEvent(new CustomEvent(B1))):u.onClose(),s==null||s(M)},caller:em}),k=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),A=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,S.current=!1,T(!0)},[T]),I=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,T(!1)},[T]),R=b.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{S.current=!0,T(!0),g.current=0},w)},[w,T]);return b.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),m.jsx(Cm,{...d,children:m.jsx(Jde,{scope:t,contentId:v,open:x,stateAttribute:k,trigger:f,onTriggerChange:h,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?R():A()},[u.isOpenDelayedRef,R,A]),onTriggerLeave:b.useCallback(()=>{_?I():(window.clearTimeout(g.current),g.current=0)},[I,_]),onOpen:A,onClose:I,disableHoverableContent:_,children:n})})};MF.displayName=em;var z1="TooltipTrigger",PF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Pm(z1,n),s=Vk(z1,n),o=Xb(n),l=b.useRef(null),u=dr(t,l,i.onTriggerChange),d=b.useRef(!1),f=b.useRef(!1),h=b.useCallback(()=>d.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),m.jsx(km,{asChild:!0,...o,children:m.jsx(Sn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:qt(e.onPointerMove,v=>{v.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:qt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:qt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:qt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:qt(e.onBlur,i.onClose),onClick:qt(e.onClick,i.onClose)})})});PF.displayName=z1;var Kk="TooltipPortal",[Qde,efe]=Gb(Kk,{forceMount:void 0}),IF=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Pm(Kk,t);return m.jsx(Qde,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};IF.displayName=Kk;var uf="TooltipContent",OF=b.forwardRef((e,t)=>{const n=efe(uf,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Pm(uf,e.__scopeTooltip);return m.jsx(xo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(LF,{side:i,...s,ref:t}):m.jsx(tfe,{side:i,...s,ref:t})})}),tfe=b.forwardRef((e,t)=>{const n=Pm(uf,e.__scopeTooltip),r=Vk(uf,e.__scopeTooltip),i=b.useRef(null),s=dr(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:h}=r,v=b.useCallback(()=>{l(null),h(!1)},[h]),g=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},T=sfe(x,S.getBoundingClientRect()),k=ofe(x,T),A=afe(w.getBoundingClientRect()),I=cfe([...k,...A]);l(I),h(!0)},[h]);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},T=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),k=!lfe(x,o);T?v():k&&(v(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,v]),m.jsx(LF,{...e,ref:s})}),[nfe,rfe]=Gb(em,{isInside:!1}),ife=Doe("TooltipContent"),LF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Pm(uf,n),d=Xb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(B1,f),()=>document.removeEventListener(B1,f)),[f]),b.useEffect(()=>{if(u.trigger){const h=v=>{const g=v.target;g!=null&&g.contains(u.trigger)&&f()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[u.trigger,f]),m.jsx(_f,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:h=>h.preventDefault(),onDismiss:f,children:m.jsxs(Hb,{"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(ife,{children:r}),m.jsx(nfe,{scope:n,isInside:!0,children:m.jsx(i3,{id:u.contentId,role:"tooltip",children:i||r})})]})})});OF.displayName=uf;var DF="TooltipArrow",BF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Xb(n);return rfe(DF,n).isInside?null:m.jsx($b,{...i,...r,ref:t})});BF.displayName=DF;function sfe(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 ofe(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 afe(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 lfe(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,h=u.x,v=u.y;f>r!=v>r&&n<(h-d)*(r-f)/(v-f)+d&&(i=!i)}return i}function cfe(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),ufe(t)}function ufe(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 dfe=NF,ffe=MF,hfe=PF,pfe=IF,mfe=OF,gfe=BF;const zF=b.createContext(!1);function vfe({blocked:e,children:t}){return m.jsx(zF.Provider,{value:e,children:t})}function Im(){return b.useContext(zF)}function Zb({...e}){return m.jsx(dde,{"data-slot":"popover",...e})}function Jb({...e}){return m.jsx(fde,{"data-slot":"popover-trigger",...e})}function Qb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=Im();return m.jsx(hde,{children:m.jsx(pde,{"data-slot":"popover-content",align:t,sideOffset:n,className:We("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:o||r?!0:void 0,"aria-disabled":o?!0:i,"data-relay-interaction-blocked":o?"true":void 0,...s})})}const SI=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,EI=dj,yfe=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return EI(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],h=s==null?void 0:s[d];if(f===null)return null;const v=SI(f)||SI(h);return i[d][v]}),l=n&&Object.entries(n).reduce((d,f)=>{let[h,v]=f;return v===void 0||(d[h]=v),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:h,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,h,v]:d},[]);return EI(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},bfe=yfe("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 ct({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?Ooe:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(bfe({variant:t,size:n,className:e})),...i})}function Cf({...e}){return m.jsx(Wue,{"data-slot":"dropdown-menu",...e})}function _fe({...e}){return m.jsx(Y4,{"data-slot":"dropdown-menu-portal",...e})}function kf({...e}){return m.jsx(que,{"data-slot":"dropdown-menu-trigger",...e})}function Tf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=Im();return m.jsx(Y4,{children:m.jsx(Yue,{"data-slot":"dropdown-menu-content",sideOffset:t,className:We("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:s||n?!0:void 0,"aria-disabled":s?!0:r,"data-relay-interaction-blocked":s?"true":void 0,...i})})}function ni({className:e,inset:t,variant:n="default",...r}){return m.jsx(Kue,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:We("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function k0({className:e,children:t,checked:n,...r}){return m.jsxs(Gue,{"data-slot":"dropdown-menu-checkbox-item",className:We("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(Xue,{children:m.jsx(da,{className:"size-4"})})}),t]})}function Dh({className:e,inset:t,...n}){return m.jsx(Vue,{"data-slot":"dropdown-menu-label","data-inset":t,className:We("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Ul({className:e,...t}){return m.jsx(Zue,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}function wfe({...e}){return m.jsx(Jue,{"data-slot":"dropdown-menu-sub",...e})}function xfe({className:e,inset:t,children:n,...r}){return m.jsxs(Que,{"data-slot":"dropdown-menu-sub-trigger","data-inset":t,className:We("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-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_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(Yd,{className:"ml-auto size-4"})]})}function Sfe({className:e,...t}){return m.jsx(ede,{"data-slot":"dropdown-menu-sub-content",className:We("z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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),...t})}const Efe={"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 nu({variant:e,action:t}){const{heading:n,body:r}=Efe[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 Cfe={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},kfe={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function j1({status:e,className:t}){return m.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",Cfe[e],t),role:"status","aria-label":kfe[e]})}function Mp({name:e,osName:t,className:n,nameClassName:r}){return m.jsxs("span",{className:We("min-w-0 flex-1",n),children:[m.jsx("span",{"data-slot":"proxy-name",className:We("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 Yi({...e}){return m.jsx(Ck,{"data-slot":"dialog",...e})}function Tfe({...e}){return m.jsx(kk,{"data-slot":"dialog-portal",...e})}function jF({...e}){return m.jsx(Db,{"data-slot":"dialog-close",...e})}function Rfe({className:e,...t}){return m.jsx(Tk,{"data-slot":"dialog-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Vi({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=Im();return m.jsxs(Tfe,{"data-slot":"dialog-portal",children:[m.jsx(Rfe,{}),m.jsxs(Rk,{"data-slot":"dialog-content",className:We("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus: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(Db,{"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(lc,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Ki({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:We("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Gs({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:We("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(Db,{asChild:!0,children:m.jsx(ct,{variant:"outline",children:"Close"})})]})}function Oi({className:e,...t}){return m.jsx(P3,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function fs({className:e,...t}){return m.jsx(I3,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function Afe(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function Nfe({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(Yi,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Vi,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"移除离线开发机?"}),m.jsx(fs,{children:Afe(t)})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(ct,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(Gr,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const my=80,Mfe=8,Pfe=1.2;function CI(e){return Math.max(0,Math.min(my,e))}function Ife({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),[h,v]=b.useState(null),g=h??(i?my:0),_=h!==null;function w(k){var A,I;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?my:0,axis:"pending"};try{(I=(A=k.currentTarget).setPointerCapture)==null||I.call(A,k.pointerId)}catch{}}}function S(k){const A=d.current;if(!A||A.pointerId!==k.pointerId)return;const I=k.clientX-A.startX,R=k.clientY-A.startY;if(A.axis==="pending"){if(Math.hypot(I,R)<Mfe)return;A.axis=Math.abs(I)>Math.abs(R)*Pfe?"horizontal":"vertical"}A.axis!=="vertical"&&(k.preventDefault(),v(CI(A.startOffset-I)))}function x(k,A=!1){var M,z;const I=d.current;if(!I||I.pointerId!==k.pointerId)return;d.current=null;try{(z=(M=k.currentTarget).releasePointerCapture)==null||z.call(M,k.pointerId)}catch{}if(I.axis!=="horizontal"||A){v(null);return}k.preventDefault();const R=h??CI(I.startOffset-(k.clientX-I.startX));v(null),o(R>=my/2),f.current=!0,window.setTimeout(()=>{f.current=!1},0)}function T(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:T,children:[m.jsx(j1,{status:"offline"}),m.jsx(Mp,{name:u,osName:n}),r&&m.jsx(da,{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 FF({layout:e,variant:t="default"}){const n=Re(M=>M.proxies),r=Re(M=>M.proxyListLoaded),i=Re(M=>M.relayClientAuthIssue),s=Re(M=>M.selectedProxyId),o=Re(M=>M.proxySwitchTarget),l=hs(),u=ks(),[d,f]=b.useState(!1),[h,v]=b.useState(null),[g,_]=b.useState(null),[w,S]=b.useState(null);async function x(M,z){if(o)return;const Y=Bt;if(!Y){He.error("请先连接开发机");return}const W=z??M,G=s!==null&&s!==M;Re.getState().setProxySwitchTarget({proxyId:M,name:W});try{const O=await Y.selectProxy(M);if(!O.success){He.error(`无法连接 ${W}:${O.error??"未知错误"}`);return}const N=Y.getPreviewScope();if(!N||N.proxyId!==M||N.bindingId!==O.bindingId)throw Pt.dispose(),Y.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Pt.activate(Y,N),Pt.syncWebSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] web preview snapshot failed",L)}),Pt.syncDeviceSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] device preview snapshot failed",L)}),G&&(Ut.getState().prepareForProxySwitch(W),ii.getState().prepareForProxySwitch()),Ir("local",Tn.proxyId,M),Re.getState().setProxy(M,z??null),Re.getState().setProxyOnline(!0),Re.getState().transitionToPhase("session_browsing"),Y.sendControl({type:"session_list_request"}),Y.requestProxyInfo().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(Y,N))return;const D=ii.getState();D.setHomePath(L.homePath),D.setAgentCli(L.agentCli),Re.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Pt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),Y.requestAgentStatuses().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(Y,N))return;const D=Ut.getState();for(const P of L)D.setAgentStatus(P.sessionId,P.payload)}).catch(L=>{Pt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),fk(Y).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 N=O instanceof Error?O.message:"未知错误";He.error(`无法连接 ${W}:${N}`)}finally{Re.getState().setProxySwitchTarget(null)}}function T(M){M.online||w||(v(null),_({proxyId:M.proxyId,...M.name?{name:M.name}:{}}))}async function k(){const M=g;if(!M||w)return;const z=Bt;if(!z){He.error("Relay 连接不可用,请稍后重试");return}const Y=Re.getState().proxies.find(W=>W.proxyId===M.proxyId);if(!Y){if(!Re.getState().proxyListLoaded){He.info("正在重新连接 Relay,请稍后再试");return}Np(M.proxyId,z)&&u("/"),He.info("这台开发机已经不在列表中"),_(null);return}if(Y.online){He.warning("这台开发机已重新上线,未移除"),_(null);return}S(M.proxyId),Sse(M.proxyId);try{const W=await z.removeOfflineProxy(M.proxyId);if(W.success){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),He.success(`已移除 ${M.name??M.proxyId}`),_(null);return}if(W.errorCode===Or.PROXY_ONLINE){Dd(M.proxyId),He.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(W.errorCode===Or.PROXY_NOT_FOUND){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),He.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Dd(M.proxyId),He.error(W.error??"无法移除开发机,请重试")}catch(W){He.error(W instanceof Error?W.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const A=m.jsx(Nfe,{open:g!==null,target:g,removing:w!==null,onOpenChange:M=>{M||_(null)},onConfirm:()=>{k()}});if(e==="page")return i==="missing_client_token"?m.jsx(nu,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(nu,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(nu,{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(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=o!==null;return M.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":"true","data-selecting":z||void 0,disabled:Y||w!==null,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:We("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",M.osName?"h-14":"h-11",z?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",Y&&!z||w!==null?"opacity-50":""),"aria-pressed":s===M.proxyId,children:[m.jsx(j1,{status:"online"}),m.jsx(Mp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"正在连接"}),m.jsx(Gr,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===M.proxyId?m.jsx(da,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},M.proxyId):m.jsx(Ife,{proxyId:M.proxyId,name:M.name,osName:M.osName,selected:s===M.proxyId,revealed:h===M.proxyId,disabled:Y||w!==null,onRevealedChange:W=>v(W?M.proxyId:null),onRemove:()=>T(M)},M.proxyId)})})]}),A]}):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(Gr,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const I=n.find(M=>M.proxyId===s),R=(I==null?void 0:I.name)??(I==null?void 0:I.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Zb,{open:d,onOpenChange:f,children:[m.jsx(Jb,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:We("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex 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":`当前连接:${R}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx(Mp,{name:R,osName:I==null?void 0:I.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(ac,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(Qb,{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(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=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":M.proxyId,"data-online":M.online,"data-selecting":z||void 0,disabled:!M.online||Y,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:We("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",M.osName?"h-12":"h-9",z?"bg-accent text-accent-foreground":"hover:bg-accent",Y&&!z?"opacity-50":"",M.online?"":"opacity-50"),"aria-pressed":s===M.proxyId,title:M.online?void 0:"这台开发机离线",children:[m.jsx(j1,{status:M.online?"online":"offline"}),m.jsx(Mp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsx(Gr,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===M.proxyId?m.jsx(da,{className:"h-4 w-4 text-primary shrink-0","aria-label":"已选"}):null,!M.online&&!z&&m.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"离线"})]}),!M.online&&m.jsxs(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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:Y||w!==null,"aria-label":`${M.name??M.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(wb,{"aria-hidden":"true"})})}),m.jsx(Tf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(ni,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:W=>{W.stopPropagation(),T(M)},children:[m.jsx(lj,{"aria-hidden":"true"}),"移除开发机"]})})]})]},M.proxyId)})})})]}),A]})}function Ofe({delayDuration:e=0,...t}){return m.jsx(dfe,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Rf({...e}){return m.jsx(ffe,{"data-slot":"tooltip",...e})}function Af({...e}){return m.jsx(hfe,{"data-slot":"tooltip-trigger",...e})}function Nf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(pfe,{children:m.jsxs(mfe,{"data-slot":"tooltip-content",sideOffset:t,className:We("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(gfe,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function vc({...e}){return m.jsx(Ck,{"data-slot":"sheet",...e})}function Lfe({...e}){return m.jsx(cle,{"data-slot":"sheet-trigger",...e})}function Dfe({...e}){return m.jsx(kk,{"data-slot":"sheet-portal",...e})}function Bfe({className:e,...t}){return m.jsx(Tk,{"data-slot":"sheet-overlay",className:We("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function yc({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=Im();return m.jsxs(Dfe,{children:[m.jsx(Bfe,{className:t}),m.jsxs(Rk,{"data-slot":"sheet-content",className:We("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus:h=>{o==null||o(h),!(!s||h.defaultPrevented)&&(h.preventDefault(),h.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(Db,{"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(lc,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function ku({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:We("flex flex-col gap-1.5 p-4",e),...t})}function bc({className:e,...t}){return m.jsx(P3,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function e_({className:e,...t}){return m.jsx(I3,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}const zfe={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"},kI=["claude","codex","kimi","cursor"];function t_(e){return zfe[e]}function HF(e,t){return kI.indexOf(e)-kI.indexOf(t)}function Yl(e){return e.provider}const F1=60*1e3,H1=60*F1,jfe=24*H1;function $F(e,t=Date.now()){const n=t-e;if(n<F1)return"刚刚";if(n<H1)return`${Math.floor(n/F1)} 分钟前`;if(n<jfe)return`${Math.floor(n/H1)} 小时前`;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 $1={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 Ffe({session:e}){const t=$1[e.state];return m.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Hfe({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?$C:qC;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 $fe({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=ii(w=>w.homePath),l=e.lastActive,u=e.cwd,d=gk(e.name,o),f=vk(e,o),h=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),v=$F(l,n),g=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return m.jsxs("li",{className:We("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&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:[e.kind!=="terminal"&&m.jsx(Ffe,{session:e}),m.jsx("span",{className:"text-sm font-normal truncate flex-1",title:u,children:h})]}),m.jsxs("span",{className:"flex items-center gap-1.5 text-xs leading-5 h-5",children:[m.jsx(Hfe,{mode:e.mode}),e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:t_(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:We("shrink-0",$1[e.state].text),children:$1[e.state].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(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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(wb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(ni,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(ni,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}const Ufe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAACIUlEQVRYw+2Wz2sTQRTHP7uzsUtAyB/RvyLiJadQYlE8CB6qePMP0IOUSKMFBS8einePgiB1KXvqbaGll/wB7b2NlDQ/3Nnt7sx4SLKQ2DS21s3BfGHYN294733nPd7bgQXmDOv9h4/rUSTf5BlU2KKx/urFJpA6Wp03Hj1eI45jwNxooE+fv/N87d5v329fv9SBLeDMcd1iHHZ/uJmVmUbDTJwZzHBjWxaWZYE10A2W4dnDu0T9Nk8f3CHsnvLkfpmwezpycBv46bhLLhuv6wOXxmCMQWt94VJKjcmj/aRea02SJMRxTBzHhGGIlDKjvvH2HYAAbPum035V2MbMmYA22ppUep7Hzs7OVKMgCG6OwKRie3ubWq3GysoKvu9n+t3d3X+TAaX10rTDarWayZVKZexsb28vk5VSSCmRUhJFEVJKer0eYRiSpila66kEnKuwTZKEfr/P8vIyh4eHHBwcUCgUSNP02hm4lIDv+5TLZU5OTjg6Ohr0+miEWhbGmL8KDuBMdsHq6iqe5wFQKpXodDpZwMswq5um2TtGjxseHx9TLBbHBsefOJ1FcGYJpJQ0m01arVauc8ABaLfb7O/vD39I+cKJooggCFBKzWcSnifJ3IJfOAkXBBYEFgRyH0TCFo36xuZLIYR7rRvYNkLYCCHQGrRKUUpd+tLsdjpbgAK0BdwCSsNnssjp4groAWfWsAwOUMixJBpIgJT/Hr8AJyImgbVGgskAAAAASUVORK5CYII=",Wfe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFFElEQVRYw+1Wa0xbZRh+SyPQwiE4nJCuuAFSSiezUrkVNcZdNF6SMcmmC/GHyzJ/GNmfTQmomIkil0SmgW3J5swcwwsyHMHoNrlE3cUREUbLraAUSsGxuBVaBpzv8zunPdcexg9/ypd8+S7n8jzv8z7few7Aavu/N5XS5iUXPkoGC7fGWNqV9pbrK9w7qFIAf3LKPXW4rPR90/z8vFoggdgnmBEjJIyIZueIGUUd0YGRXS8Ja5rMyXpDksnzdnXDYIiCAIbRkVGtFBwrg2OkDI7uBk7mZH1vzP0L5NUeJQKWAXs/xS1SEvXww6lyOFF1ECK1GhkJDhTxHSEkI4MkpFhCZIzfYPCSmLoUCTiGHZFc8p6ymkEXex9kPGyEkzXvAkVFi8BFaZB0kSo0NwrRMyRMZutsEAGSf9Z47km31i85hqvd/fx1Y0IcfF5TAlRUNA+MlpVelALZXlhYOJ1kTPeSVwZ5wNDT3UOx4ODP+dVuGxR/dExCorhwD7kawnvA7wOREnQwGc4DDKG4dYmM/JCXrpIqQDYtdpudYsERCpwVBE3fd0DRh3X8fdu3ZkBF6QE/ieWkF58EFljYSzZZWPmZdwURmHCOa5Rc39TaDm+Vfcrfm7ctE6oOFbGvEKJdWj4tnAdITzXnesiDUgK/jGMdwaRGHA4K5EctEFljy0U42XBORCILqj94R0qCFo4eS4gB5g3onzP5Z4qQhAATPTFf6LzPqxbnVnC5f36o+ig0njvPk9jxdDa8tHOXQh1YkngBBwpQnD7BGxm1hg5SgCFgu95LKVY5lgzN9/cq62DcNcWTqCjeCxH6zEDUggmRiAQKqKN7wOBjos/PUHnkHjAwBUhe5eSFxpicAK0NdaDXxfIP/mabgPA1SZJCg2nBF6wJAyfAuMnq4eTnCXT+hQkwGFzjTo0ysP9lb+zdDa1naiXgX7R2Q2FlC/huDEkKDRKVYMwrsARpGZt5A4oVsHg8HvWka0IrjpZ7kIrQQP3Rcti/r4AH9szdYYHLj18Al70D/nG0CUWHFpVdWuhhYRo6Tp+8wB1BngAT/ejwsJbLuZBvBFufyILO7z6DbMsmieT5B8/Ajx3X4GZ/K8y5eyUngJvznkB++ZNSLUz0nl3ZKpecgMXed52SS1+8fw8cqSqBKCqCB6/7+gq8WtoIjr7LMGM7CynrYyAnMx2sWRbIzX6U9EzIzcmEx6xZEK/XCceQdH3CRp9Yfr61j+Jr214pup1sfRE/mL0dP19QiG0DDixuE9O3cP6BerxxRyXWm5/FaxPMuLevH6/Uag5/gkPU92BQqfCb1S0DX17GL4uxQ9pGsIUpfJPjTi1nmNO1ZZBqSORvam63s5L3/PE73OxrgoXbLtaID5lSVvzlytmcB7FpL7Ayp+c+x6RgUEKAOX6OwQGtzzun5qTnJOeMVlJ7HtxDv8Kt0TagF31sXsfGxqC3z74igYE//4bw6HWgW29kvn5A8i9JgeonB65q+farnc3fnI7nFNhCjGfO2gLNncPgdI7BrPMSLM7NSEtqwOGxj+yG0Mi1dyUxM9QBxvjo6deKj58lBPZJCFwcxm1HPi5P67ryc4y/5vurF6jDQKUOh0UvAWaj5qpa4HyLSHCFBsn3EM0DvV56yvH4MwUVhMAxeQqomRvTocKn1H8S6DseWJx1B8BF33h5oRH9fC4HrtFSdJIpwyvPP6vAhSFcz9SB//h7HXSvQuuSy7/aVhvT/gWL3beQH5sGiAAAAABJRU5ErkJggg==",qfe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAEGUlEQVRYw+1XS2hcVRj+zus+5s5kJp2Oie8kBFqCSYYuBBEyYxooIhiL0oUKutKVjVMDughCceXCPjbShUUXLgStLakUXCROFIxSxbEJWPoIo26iY8m0TZqM6dzjYm7unXvPvZPp2hy43DPn/v/5v/P9j/MPsDP+74OELY688c2rwkx9rJmpwBcJ6SjJe7HSrEQkIAHKNTBuHORh8lxPHE89OOzpSxuQNqRte3P3qQO299v9ZvvlXBln3a5vggkzS0NOn9WtdEoxLm30ZODfVNqAlJBSAs6jAImYAxKE0GoYA1lhJresuwofvKyhN0Mwu0hx8sKdFgbaA8K4DhBSpCEAclyPN23SePdmGuEy+pjAxNOmSm07QJpcSLmO6bc7SwoAYXTkCWEKzed/3nRlRgc1TDxjbUuzH4jfTUyYRQDwARg5XEwxLdYTttHpmXXMLv7ryu4fNJDbU2/L38E5oRyEiTkFAAHJC6MjUvnEV6uYWdhw5SeffwBjQ+b2GRCgn2sxEJCSAgCEZpkWa3mKE+dvYebSuqtSGN+FsWHrnjKAaRZAqOoCyrUc46YbeFEnOj69goXfa67eked2Yyxr+XzcKhuYMMrnJmNVBQATZj6Y31GneO+zCpaWvZh462AXHknXHbAyEIRN/icUXI8X3UNvTZ4qzGcb6bddoWlsvrp+F9ebAADAvoej6oN0gTBhgBD6q1t1Pf+TPNestvzY1yVwZDyNvm7NVb+9VsP0d1chjYEW+hLc6ABAigoAQugw5bqqHCg0+4djeP1AJyzD897sxSUc/Wge1OoFk60zQBhJfFkQJQUAE2a+UX7DT27pQOHZ3Xhir+k79Yef/4iz399AIj3kAxvFAtetou/iA4DRyZ9STJg9/sDz5n1dHFOH0uhKeR67XK7g3VNF/F27H4l0f0j1CzMeB2XanAKAEJKnXAsEXoP+l0YSeDHX4Qu2Ty+UcPKL35C8bwDCoBFXtRN4W+sAuB4HgJICAIRmKdf9lGvA1KE0Bh/VfZS/eexrXF7W0dk9hL5uHU8OJBrGIN03pETpWhW/XF1x1px7pnHLqi6glOUIoT7Kxh+P+4zPXlzC0dM/gMX7YSUbRefU4f7IJuiVAw/hhakiKreajAmrfGaCVlUAXM8H/bW6UXeF3v/kW5ydX0Eys89XFVfX64ibLBLExloFQMYhmYMbiaLSfY29cylLmFAKzbn5m1i8Ukb5jz9x824nkpk9SmS/dmwBCfaP1yE6dEtI3F6r4cYdHZqOZv/PKQAIoXlKhVr9IHGlkgCMvTAi0uqvqo1l2REahIBnHACcBrcUBEBBSAoEoQUoWNPDmtJw4+rQrF3VMxO0FMZAyd6sgVDW3BcAlIGAARBuO95+n+/v9oWZBNcThZ1/QTsjbPwHmclZWfW3uBoAAAAASUVORK5CYII=";function Yfe({shell:e,label:t}){const n=e==="cmd"?Ufe:e==="powershell"?t==="Windows PowerShell"?qfe:Wfe:null;return n?m.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"size-5 shrink-0 object-contain",width:20,height:20,draggable:!1}):m.jsx(ou,{className:"size-5 text-muted-foreground","aria-hidden":"true"})}function bo(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 Vfe({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Kfe,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:$F(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:We("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(uV,{className:We("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Kfe({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(Gfe,{mode:t})]})}function Gfe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?$C:qC;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:We("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function UF({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(iG,{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 Xfe({now:e}){const t=ii(O=>O.homePath),n=Ut(O=>O.historySessions),r=Ut(O=>O.historyLoadStatus),[i,s]=b.useState(null),[o,l]=b.useState(null),[u,d]=b.useState("json"),[f,h]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(new Set),[S,x]=b.useState(new Set),T=ks(),k=b.useMemo(()=>{const O=new Map;for(const N of n){const L=Yl(N);let D=O.get(L);D||(D=new Map,O.set(L,D));const P=WF(N.projectDir),B=D.get(P);B?B.sessions.push(N):D.set(P,{dir:P,sessions:[N]})}return Array.from(O.entries()).sort(([N],[L])=>HF(N,L)).map(([N,L])=>({provider:N,sessions:Array.from(L.values()).flatMap(D=>D.sessions),projects:Array.from(L.values()).map(D=>({dir:D.dir,shortDir:Gp(D.dir,t,{compact:!0}),sessions:D.sessions}))}))},[n,t]);function A(O){l(O),d(Zfe(O)),h(Jfe(O))}async function I(O,N,L){if(i)return;const D=Bt;if(!D){He.error("请先连接开发机");return}s(O.id);const P=Yl(O);try{const B=await D.createSession({kind:"agent",cwd:O.projectDir,mode:N,provider:P,resumeSessionId:O.id,...L?{permissionMode:L}:{}});if(!B.success){if(B.errorCode===Or.SESSION_ALREADY_ACTIVE){Ut.getState().setCodexActiveWriterConflict({...B.activeWriterPid?{activeWriterPid:B.activeWriterPid}:{}}),l(null);return}He.error(`恢复失败:${B.error}`);return}if(B.kind!=="agent"){He.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},U=B.mode==="pty"?{...F,mode:"pty",ptyOwner:B.ptyOwner}:{...F,mode:"json"};Ut.getState().addSession(U),T(`/chat/${B.sessionId}?mode=${B.mode}`),l(null)}catch(B){He.error(`恢复失败:${B instanceof Error?B.message:String(B)}`)}finally{s(null)}}function R(){const O=Bt;!O||Ut.getState().historyLoadStatus==="loading"||fk(O).then(N=>{N.status==="failed"&&He.error(N.error instanceof Error?N.error.message:String(N.error))})}function M(O,N){const L=TI(O,N);x(D=>{const P=new Set(D);return P.has(L)?P.delete(L):P.add(L),P})}function z(O){w(N=>{const L=new Set(N);return L.has(O)?L.delete(O):L.add(O),L})}const Y=n.length>0,W=r==="loading",G=o?qF(Yl(o)):[];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:()=>Y&&g(O=>!O),disabled:!Y,"aria-expanded":Y?v:void 0,"data-slot":"history-section-header","data-expanded":v,className:We("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",Y?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),Y?m.jsx(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",v&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":W,title:W?"正在加载":"刷新",onClick:R,disabled:W,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(bm,{className:We("size-3.5",W&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!Y&&W&&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(Gr,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!Y&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!Y&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),Y&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!Y&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),Y&&v&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(O=>{const N=_.has(O.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>z(O.provider),"aria-expanded":!N,"data-slot":"history-provider-header","data-expanded":!N,className:We("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:t_(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(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!N&&"rotate-90"),"aria-hidden":"true"})]}),!N&&m.jsx("ul",{role:"list",className:"flex flex-col",children:O.projects.map(L=>{const D=TI(O.provider,L.dir),P=S.has(D);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>M(O.provider,L.dir),"aria-expanded":P,"data-slot":"history-group-header","data-expanded":P,className:We("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[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(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",P&&"rotate-90"),"aria-hidden":"true"})]}),P&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(B=>m.jsx(Vfe,{session:B,now:e,disabled:i!==null,loading:i===B.id,onClick:()=>A(B),modeTag:B.preferredMode},B.id))})]},D)})})]},O.provider)})}),m.jsx(Qfe,{session:o,open:o!==null,modes:G,mode:u,permissionMode:f,submitting:i!==null,onOpenChange:O=>{O||l(null)},onModeChange:O=>{d(O),O==="json"&&o&&Yl(o)==="cursor"&&f==="auto"&&h("default")},onPermissionModeChange:h,onConfirm:()=>{o&&I(o,u,f)}})]})}function TI(e,t){return`${e}:${WF(t)}`}function WF(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function qF(e){return["json","pty"]}function Zfe(e){const t=qF(Yl(e));return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"pty"}function Jfe(e){return Yl(e)==="codex"?"auto":"default"}function Qfe({session:e,open:t,modes:n,mode:r,permissionMode:i,submitting:s,onOpenChange:o,onModeChange:l,onPermissionModeChange:u,onConfirm:d}){const[f,h]=b.useState(!1),v=i==="bypassPermissions",g=bo("(min-width: 768px)"),_=e?Yl(e):null,w=_==="codex",S=_==="kimi",x=_==="cursor";b.useEffect(()=>{t||h(!1)},[t]);const T=f?m.jsx(UF,{providerLabel:e?t_(Yl(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(RI,{checked:r==="json",label:"聊天",icon:m.jsx($C,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(RI,{checked:r==="pty",label:"终端",icon:m.jsx(qC,{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(Tv,{checked:i==="default",label:S?"手工审批":x?"命令审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":x?"Cursor CLI 在执行命令前询问。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),!(x&&r==="json")&&m.jsx(Tv,{checked:i==="auto",label:w?"按需审批":S?"自动审批":x?"智能自动":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":x?"Cursor CLI 自动执行判定为安全的工具,其余仍会询问。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),(S||x)&&m.jsx(Tv,{checked:i==="plan",label:"只读规划",description:x?"Cursor CLI 使用只读规划模式。":"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(Tv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?h(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(ct,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(v&&!f){h(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return g?m.jsx(Yi,{open:t,onOpenChange:o,children:m.jsxs(Vi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Ki,{className:"min-w-0",children:[m.jsx(Oi,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(fs,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),T,m.jsx(Gs,{children:k})]})}):m.jsx(vc,{open:t,onOpenChange:o,children:m.jsxs(yc,{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(ku,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(bc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(e_,{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:T}),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:k})})]})})}function RI({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:We("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(da,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Tv({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:We("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:We("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:We("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:We("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(da,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function n_({...e}){return m.jsx(zde,{"data-slot":"select",...e})}function r_({...e}){return m.jsx(Fde,{"data-slot":"select-value",...e})}function i_({className:e,size:t="default",children:n,...r}){return m.jsxs(jde,{"data-slot":"select-trigger","data-size":t,className:We("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(Hde,{asChild:!0,children:m.jsx(ac,{className:"size-4 opacity-50"})})]})}function s_({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=Im();return m.jsx($de,{children:m.jsxs(Ude,{"data-slot":"select-content",className:We("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,inert:l||i?!0:void 0,"aria-disabled":l?!0:s,"data-relay-interaction-blocked":l?"true":void 0,...o,children:[m.jsx(ehe,{}),m.jsx(Wde,{className:We("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(the,{})]})})}function o_({className:e,children:t,...n}){return m.jsxs(qde,{"data-slot":"select-item",className:We("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(Vde,{children:m.jsx(da,{className:"size-4"})})}),m.jsx(Yde,{children:t})]})}function ehe({className:e,...t}){return m.jsx(Kde,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(jC,{className:"size-4"})})}function the({className:e,...t}){return m.jsx(Gde,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(ac,{className:"size-4"})})}function nhe(e,t,n){var u;if(t==="insert"){const d=e.split("@").pop()??"",f=uu((n==null?void 0:n.baseCwd)??d)==="\\",h=Math.max(d.lastIndexOf("/"),f?d.lastIndexOf("\\"):-1);return{currentPath:h>=0?d.slice(0,h+1):f?".\\":"./",query:d.slice(h+1).toLowerCase()}}const r=aa((n==null?void 0:n.baseCwd)??"");if(!e)return{currentPath:Ys(r),query:""};const i=Tb(r,e);if(!i)return{currentPath:"",query:""};const s=uk(i),o=uu(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:Ys(i),query:""}:{currentPath:Ys(s),query:i.slice(i.lastIndexOf(o)+1).toLowerCase()}}function T0(e,t){return Tb(e,t)}const YF=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:h=!0,title:v},g){const _=ii(be=>f?be.treeWithHidden:be.tree),w=ii(be=>be.cwd),S=ii(be=>be.homePath),x=Re(be=>be.selectedProxyId),T=o==="insert"?w:S||w,k=b.useMemo(()=>new Set(_.keys()),[_]),A=b.useMemo(()=>nhe(t,o,{baseCwd:T,knownDirs:k}),[t,o,T,k]),I=A.currentPath,R=b.useMemo(()=>T0(T,I),[T,I]),M=A.query,z=b.useRef(new Map),[Y,W]=b.useState(!1),[G,O]=b.useState(""),[N,L]=b.useState(!1),[D,P]=b.useState(null),[B,F]=b.useState(0),[U,j]=b.useState(!1),[V,X]=b.useState(null),[H,Q]=b.useState(null);b.useEffect(()=>{if(!U)return;let be=!1;X(null),Q(null);const rt=Bt==null?void 0:Bt.requestFileSystemRoots();return rt||Q("尚未连接开发机"),rt==null||rt.then($e=>{be||($e.error!==void 0||$e.errorCode!==void 0?Q($e.error||"读取失败"):X($e.roots))},$e=>{be||Q($e instanceof Error?$e.message:"读取失败")}),()=>{be=!0}},[U,x,B]),b.useEffect(()=>{if(!R||U)return;const be=`${x}\0${f?"hidden":"default"}\0${R}`;if(_.has(R))return;const rt=Bt;if(!rt)return;let $e=!1;P(Ze=>(Ze==null?void 0:Ze.path)===R?null:Ze);let Ae=z.current.get(be);if(!Ae){Ae=rt.requestDirectoryList(R,{includeHidden:f}),z.current.set(be,Ae);const Ze=()=>{z.current.get(be)===Ae&&z.current.delete(be)};Ae.then(Ze,Ze)}return Ae.then(Ze=>{if(!$e){if(Ze.error!==void 0||Ze.errorCode!==void 0){P({path:R,message:Ze.error||"读取失败"});return}ii.getState().setDirEntries(Ze.path,Ze.entries,Ze.includeHidden)}},Ze=>{$e||P({path:R,message:Ze instanceof Error?Ze.message:"读取失败"})}),()=>{$e=!0}},[R,f,_,B,U,x]);const ne=U?H?{message:H}:null:(D==null?void 0:D.path)===R?D:null,te=U?V===null&&!H:!_.has(R)&&!ne,Z=b.useMemo(()=>d==null?void 0:d.map(be=>be.startsWith(".")?be.toLowerCase():`.${be.toLowerCase()}`),[d]),ce=b.useMemo(()=>{if(U){if(!V)return[];const rt=[...S?[{name:"主目录",path:S}]:[],...V];return[...new Map(rt.map($e=>[$e.path,$e])).values()].map($e=>({...$e,isDir:!0}))}let be=_.get(R)??[];return u?be=be.filter(rt=>rt.isDir):Z!=null&&Z.length&&(be=be.filter(rt=>rt.isDir||Z.some($e=>rt.name.toLowerCase().endsWith($e)))),M&&(be=be.filter(rt=>rt.name.toLowerCase().includes(M))),be},[_,R,M,u,Z,U,V,S]),[ie,me]=b.useState(h?0:-1);b.useEffect(()=>me(h?0:-1),[h,I,M,U]),b.useEffect(()=>{W(!1),O("")},[R]),b.useEffect(()=>{ie>=ce.length&&ce.length>0&&me(ce.length-1)},[ce.length,ie]);const ge=b.useRef(null),ve=b.useRef(!1);b.useEffect(()=>{var rt;if(!ve.current)return;ve.current=!1;const be=(rt=ge.current)==null?void 0:rt.querySelector(`[data-entry-index="${ie}"]`);be==null||be.scrollIntoView({block:"nearest"})},[ie]);const Te=b.useCallback(be=>{const rt=uu(T),$e=`${Ys(I,T)}${be.name}${be.isDir?rt:""}`;if(o==="insert")return $e.replace(rt==="\\"?/^\.[\\/]/:/^\.\//,"");const Ae=T0(T,$e);return be.isDir?Ys(Ae):Ae},[T,I,o]),Xe=b.useCallback(be=>{const rt=T0(T,be);if(!rt)return;j(!1);const $e=Ys(rt);if(o==="select"){r($e);return}n($e)},[T,o,r,n]),wt=b.useCallback(be=>{if(be.path){Xe(be.path);return}const rt=Te(be);if(be.isDir){Xe(rt);return}n(rt)},[Te,Xe,n]);async function et(){const be=C2(R,G);if(!(!be||!s)){L(!0);try{const rt=await s(be);if(!rt)return;if(O(""),W(!1),i){i(Ys(rt));return}Xe(rt)}finally{L(!1)}}}b.useImperativeHandle(g,()=>({handleKey(be){return ce.length===0?!1:be.key==="ArrowDown"?(ve.current=!0,me(rt=>Math.min(ce.length-1,rt+1)),!0):be.key==="ArrowUp"?(ve.current=!0,me(rt=>Math.max(0,rt-1)),!0):be.key==="Enter"&&ie>=0&&!be.nativeEvent.isComposing?(wt(ce[ie]),!0):!1}}),[ce,ie,wt]);const ft=b.useMemo(()=>uk(R),[R]),Ne=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",Ue=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:Ne,"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:U?void 0:R,children:U?"磁盘/挂载点":Gp(R,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.jsxs("span",{className:"flex items-center gap-4",children:[m.jsx("button",{type:"button","aria-pressed":U,className:"inline-flex min-h-11 min-w-11 items-center justify-start px-0 text-left text-xs font-medium text-primary hover:underline focus-visible:underline md:min-h-8 md:min-w-0",onClick:()=>{j(be=>!be),W(!1)},children:U?"返回目录":"磁盘/挂载点"}),U?null: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:!R,onClick:()=>{R===ft?j(!0):Xe(ft)},children:"上一级"})]}),!U&&(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-end px-0 text-right 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:!R||N,onClick:()=>W(be=>!be),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-end px-0 text-right 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:!R,onClick:()=>i(Ys(R)),children:"选定"}):null]}):null]}),Y&&!U?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:G,onChange:be=>O(be.target.value),onKeyDown:be=>{be.key==="Enter"&&!be.nativeEvent.isComposing&&(be.preventDefault(),et()),be.key==="Escape"&&(W(!1),O(""))},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:!C2(R,G)||N,onClick:()=>{et()},children:N?"创建中...":"创建目录"})]}):null]}):m.jsxs("div",{className:"flex items-center gap-3 border-b border-border/70 px-3",children:[m.jsx("button",{type:"button","aria-pressed":U,className:"inline-flex min-h-11 min-w-11 shrink-0 items-center justify-start px-0 text-left text-xs font-medium text-primary hover:underline md:min-h-8 md:min-w-0",onClick:()=>j(be=>!be),children:U?"返回目录":"磁盘/挂载点"}),m.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:U?"磁盘/挂载点":Gp(R,S)})]}),m.jsx("div",{className:Ue,"data-slot":"file-path-picker-entries",children:ne?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:ne.message,children:U?"无法读取磁盘位置":"无法读取这个文件夹"}),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:()=>F(be=>be+1),children:"重试"})]}):ce.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:te?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:ge,role:"list",className:"flex flex-col",children:ce.map((be,rt)=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>wt(be),onMouseEnter:()=>me(rt),className:We("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",rt===ie&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",be.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":be.isDir?"dir":"file","data-entry-name":be.name,"data-entry-index":rt,title:be.path,children:[m.jsxs("span",{className:"min-w-0 truncate font-mono text-[13px]",children:[be.name,be.isDir&&!be.path?"/":""]}),be.path&&be.path!==be.name?m.jsx("span",{className:"ml-auto min-w-0 truncate text-xs font-normal text-muted-foreground",children:be.path}):null]})},be.path??be.name))})})]})});function AI(e,t,n){const r=pp(e,t);return r?n==="file"?Ys(uk(r)):n==="directory"?Ys(r):r:t}function pp(e,t){const n=aa(e,t);return n?e.endsWith("/")||uu(n)==="\\"&&e.endsWith("\\")?Ys(n):n:""}function Gk({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:h,required:v,autoFocus:g,"aria-describedby":_,"aria-invalid":w,"data-slot":S,className:x,onKeyDown:T}){const k=b.useId(),A=f??`remote-path-${k}`,I=`${A}-label`,R=ii(te=>te.homePath),M=bo("(pointer: coarse), (hover: none)"),z=bf().deviceKind,Y=M||z==="phone"||z==="tablet",[W,G]=b.useState(!1),[O,N]=b.useState(()=>AI(e,R,n)),[L,D]=b.useState(e),P=b.useRef(null),B=b.useRef(null),F=b.useRef(null);b.useEffect(()=>{W||document.activeElement===B.current||L===e||D(e)},[L,W,e]),b.useEffect(()=>{if(!W)return;function te(Z){const ce=P.current,ie=Z.target;ce&&(Z.composedPath().includes(ce)||ie instanceof Node&&ce.contains(ie))||(G(!1),D(e))}return document.addEventListener("click",te),()=>document.removeEventListener("click",te)},[W,e]),b.useEffect(()=>{o&&(G(!1),D(e))},[o,e]);const U=n!=="file";function j(){if(o)return;const te=AI(e,R,n);N(te),D(e),G(!0)}function V(){G(!1),D(e)}function X(te){const Z=pp(te,R);Z&&(N(Z),D(Z),t(Z),G(!1))}function H(te){const Z=pp(te,R);Z&&N(Z)}function Q(te){var Z;if(W&&((Z=F.current)!=null&&Z.handleKey(te))){te.preventDefault();return}if(te.key==="Escape"&&W){te.preventDefault(),V();return}T==null||T(te)}const ne=W?m.jsx("div",{className:We(Y&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(YF,{ref:F,mode:"select",placement:Y?"inline":"floating",filter:O,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!Y,title:l,onNavigate:H,onSelect:X,onSelectCurrentDirectory:U?X:void 0,onCreateDirectory:s})}):null;return m.jsxs("div",{className:We("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:I,className:"min-w-0 text-sm",children:u}),d?m.jsx("div",{className:"flex shrink-0 items-center gap-4",children:d}):null]}),m.jsxs("div",{ref:P,className:"relative min-w-0",onBlur:te=>{if(!W||Y)return;const Z=te.relatedTarget;Z instanceof Node&&te.currentTarget.contains(Z)||window.setTimeout(()=>{var ce;(ce=P.current)!=null&&ce.contains(document.activeElement)||V()},0)},children:[m.jsxs("div",{className:"relative flex min-w-0 items-center",children:[m.jsx("input",{ref:B,id:A,type:"text","aria-labelledby":I,"aria-describedby":_,"aria-invalid":w,name:h,required:v,autoFocus:g&&!Y,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:()=>{Y?G(!1):j()},onBlur:()=>D(e),onKeyDown:Q,onChange:te=>{const Z=te.target.value,ce=pp(Z,R);D(Z),N(ce||R),t(ce||Z),G(!Y)},onPaste:te=>{const Z=te.clipboardData.getData("text").trim(),ce=Z.startsWith('"')&&Z.endsWith('"')?Z.slice(1,-1):Z,ie=pp(ce,R);ie&&(te.preventDefault(),D(ie),N(ie),t(ie),G(!Y))},placeholder:l,className:"min-h-11 min-w-0 w-full rounded-md border border-border bg-input pl-3 pr-12 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"}),m.jsx("button",{type:"button","aria-label":typeof u=="string"?`浏览${u}`:"浏览路径","aria-expanded":W,"aria-controls":`${A}-browser`,disabled:o,"data-slot":"remote-path-browse",onClick:()=>{var te;Y&&((te=B.current)==null||te.blur()),W?V():j()},className:"absolute inset-y-0 right-0 flex w-11 items-center justify-center rounded-r-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",children:m.jsx(sK,{className:"size-5","aria-hidden":"true"})})]}),m.jsx("div",{id:`${A}-browser`,children:ne})]})]})}const NI="工作目录不存在或不可访问:",rhe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],VF=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],KF=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],Xk=[{value:"default",label:"命令审批"},{value:"auto",label:"智能自动"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],GF=Xk.filter(e=>e.value!=="auto"),tm={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"};function ihe(e,t){return t!==Or.PATH_NOT_FOUND||!e.startsWith(NI)?null:e.slice(NI.length).trim()||null}function XF(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:n.notReported?{label:"未上报",disabled:!0,title:n.error}:{label:"未找到",disabled:!0,title:n.error}}function she(e,t,n="pty"){return e==="codex"?VF.some(r=>r.value===t)?t:"auto":e==="kimi"?KF.some(r=>r.value===t)?t:"default":e==="cursor"?(n==="json"?GF:Xk).some(i=>i.value===t)?t:"default":t}async function ohe({relay:e,agentCli:t,form:n,timeoutMs:r=lk}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(XF(n.provider,t).disabled){const h=(d=t==null?void 0:t[n.provider])==null?void 0:d.error;return{type:"provider_unavailable",message:h?`${tm[n.provider]} 不可用:${h}`:`${tm[n.provider]} 暂不可用`}}const o=n.mode,l=n.provider,u=n.name.trim();try{const h=await e.createSession({kind:"agent",cwd:i,name:u||void 0,mode:o,provider:l,permissionMode:n.permissionMode},r);if(!h.success){const w=ihe(h.error,h.errorCode);return w?{type:"missing_cwd",path:w,message:"找不到这个工作目录"}:{type:"create_error",message:`创建失败:${h.error}`}}if(h.kind!=="agent")return{type:"create_error",message:"创建失败:开发机返回了错误的会话类型"};const v=((f=h.name)==null?void 0:f.trim())||void 0,g={sessionId:h.sessionId,kind:"agent",name:v,...h.nameLocked!==void 0?{nameLocked:h.nameLocked}:{},state:"idle",cwd:h.cwd,lastActive:h.lastActive,provider:h.provider};return{type:"success",session:h.mode==="pty"?{...g,mode:"pty",ptyOwner:h.ptyOwner}:{...g,mode:"json"},route:`/chat/${h.sessionId}?mode=${h.mode}`}}catch(h){return{type:"exception",message:h instanceof Error?h.message:String(h)}}}async function ahe({relay:e,shell:t,timeoutMs:n=lk}){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.shellFamily!==void 0?{shellFamily:i.shellFamily}:{},...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 lhe=["claude","codex","kimi","cursor"];function che({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)??"",h=n===t,v=h?r:f,g=h&&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(n_,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(i_,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(r_,{})}),m.jsx(s_,{"data-slot":"agent-cli-provider-options",children:lhe.map(_=>m.jsx(o_,{value:_,className:"min-h-11 md:min-h-0",children:tm[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(Gk,{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"&&h&&(_.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 mp(e){const t=Re(r=>r.selectedProxyId),n=Re(r=>r.relayUrl);return m.jsx(uhe,{...e,proxyId:t,relayUrl:n},JSON.stringify([n,t]))}function uhe({open:e,onOpenChange:t,proxyId:n,relayUrl:r}){var ge;const[i,s]=b.useState(""),[o,l]=b.useState(""),[u,d]=b.useState("claude"),[f,h]=b.useState("pty"),[v,g]=b.useState("default"),[_,w]=b.useState(!1),[S,x]=b.useState(!1),[T,k]=b.useState(null),[A,I]=b.useState(null),[R,M]=b.useState(""),[z,Y]=b.useState(!1),W=b.useRef(e);W.current=e;const G=ks(),O=ii(ve=>ve.homePath),N=ii(ve=>ve.agentCli),L=bo("(min-width: 768px)"),D=b.useRef(!0);b.useEffect(()=>(D.current=!0,()=>{D.current=!1}),[]);const P=b.useCallback(()=>{const ve=Re.getState();return D.current&&ve.selectedProxyId===n&&ve.relayUrl===r},[n,r]);b.useEffect(()=>{e&&!o&&O&&l(O)},[e,O,o]),b.useEffect(()=>{if(!e||O&&N)return;const ve=Bt==null?void 0:Bt.requestProxyInfo();if(!ve)return;let Te=!0;return ve.then(Xe=>{if(!Te||!P())return;const wt=ii.getState();wt.setHomePath(Xe.homePath),wt.setAgentCli(Xe.agentCli)}).catch(Xe=>{!Te||!P()||console.error("[create-session-dialog] requestProxyInfo failed",Xe)}),()=>{Te=!1}},[e,O,N,P]);function B(){s(""),l(""),d("claude"),h("pty"),g("default"),w(!1),k(null),I(null),M(""),Y(!1)}function F(){if(v==="bypassPermissions"){w(!0);return}ne()}async function U(){await ne(),P()&&W.current&&w(!1)}const j=u==="codex"?VF:u==="kimi"?KF:u==="cursor"?f==="json"?GF:Xk:rhe,V=XF(u,N),X=A===u&&R.trim()!==(((ge=N==null?void 0:N[u])==null?void 0:ge.command)??""),H=S||z||V.disabled||X;function Q(ve,Te=f){const Xe=she(ve,v,Te);Xe!==v&&g(Xe)}async function ne(ve){k(null),x(!0);try{const Te=await ohe({relay:Bt,agentCli:N,form:{cwd:ve??o,name:i,provider:u,permissionMode:v,mode:f}});if(!P())return;if(Te.type==="success"){if(Ut.getState().addSession(Te.session),!W.current)return;t(!1),B(),G(Te.route);return}if(Te.type==="missing_cwd"&&k(Te.path),He.error(Te.message),Te.type==="validation_error"||Te.type==="relay_missing")return}finally{P()&&x(!1)}}async function te(ve){const Te=Bt;if(!Te)return He.error("请先连接开发机"),null;try{const Xe=await Te.createDirectory(ve);return P()?Xe.success?(k(null),He.success("目录已创建"),Xe.path):(He.error(`目录创建失败:${Xe.error??"未知错误"}`),null):null}catch(Xe){return P()&&He.error(Xe instanceof Error?Xe.message:String(Xe)),null}}function Z(ve,Te){I(ve),M(Te)}async function ce(){if(!A)return;const ve=A,Te=R.trim();if(!Te){He.error("请选择 Agent CLI 可执行文件");return}const Xe=Bt;if(!Xe){He.error("请先连接开发机");return}Y(!0);try{const wt=await Xe.updateAgentCliPath(ve,Te);if(!P())return;if(wt.error||!wt.agentCli){He.error(`路径保存失败:${wt.error??"未知错误"}`);return}ii.getState().setAgentCli(wt.agentCli),He.success(`${tm[ve]} 路径已保存`),I(null),M("")}catch(wt){if(!P())return;He.error(wt instanceof Error?wt.message:String(wt))}finally{P()&&Y(!1)}}function ie(ve){h(ve),Q(u,ve)}const me=_?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(UF,{providerLabel:tm[u]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>w(!1),disabled:S,children:"返回"}),m.jsx(ct,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>{U()},disabled:S,"data-slot":"bypass-permission-confirm",children:S?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:ve=>{ve.preventDefault(),F()},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:i,onChange:ve=>s(ve.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(Gk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:o,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:te,onValueChange:ve=>{l(ve),k(null)}}),T?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:T})]}):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:We("grid min-w-0 gap-2","grid-cols-1 sm:grid-cols-2"),children:[m.jsxs("button",{type:"button","aria-pressed":f==="pty",onClick:()=>ie("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",f==="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":f==="json",onClick:()=>ie("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",f==="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(che,{agentCli:N,provider:u,cliPathDraftProvider:A,cliPathDraft:R,savingCliPath:z,onProviderChange:ve=>{d(ve),Q(ve),I(null),M("")},onCliPathDraftChange:Z,onDiscardCliPathDraft:()=>{I(null),M("")},onSaveCliPath:()=>{ce()}}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(n_,{value:v,onValueChange:ve=>g(ve),children:[m.jsx(i_,{className:"w-full",children:m.jsx(r_,{})}),m.jsx(s_,{children:j.map(ve=>m.jsx(o_,{value:ve.value,children:ve.label},ve.value))})]})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:S,children:"取消"}),m.jsx(ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:H,children:S?"创建中...":"创建"})]})]});return L?m.jsx(Yi,{open:e,onOpenChange:t,children:m.jsxs(Vi,{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(Ki,{children:m.jsx(Oi,{children:_?"跳过全部审批?":"新建会话"})}),me]})}):m.jsx(vc,{open:e,onOpenChange:t,children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(bc,{children:_?"跳过全部审批?":"新建会话"})}),me]})})}function gp({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,h]=b.useState(!1);b.useEffect(()=>{e&&(l(s),d(null),h(!1))},[s,e]);async function v(g){g.preventDefault();const _=o.trim();if(!_){d("会话标题不能为空");return}if(t){h(!0);try{await i(t,_),r(!1)}catch(w){d(w instanceof Error?w.message:String(w))}finally{h(!1)}}}return m.jsx(Yi,{open:e,onOpenChange:r,children:m.jsx(Vi,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>{v(g)},children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"重命名会话"}),m.jsx(fs,{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:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled: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(Gs,{children:[m.jsx(ct,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(ct,{type:"submit",disabled:f,children:"保存"})]})]})})})}function dhe(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function fhe(e){return(e==null?void 0:e.kind)==="terminal"}function hhe(e){return dhe(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code/Cursor CLI 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:fhe(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function Rv({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=hhe(t);function s(){t&&(r(t),n(!1))}return m.jsx(Yi,{open:e,onOpenChange:n,children:m.jsxs(Vi,{"data-slot":"session-termination-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:i.title}),m.jsx(fs,{children:i.description})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(ct,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function ZF(e){var t,n,r,i,s,o,l,u,d,f,h,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"||((h=e.agentStatus)==null?void 0:h.phase)==="outputting"||((v=e.ptyState)==null?void 0:v.state)==="working"?"working":"idle"}function phe(e){if(e.session.state==="error")return"error";const t=ZF(e);return t==="disconnected"?e.session.state:t}const mhe=new Set(["localhost","127.0.0.1","[::1]"]),U1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function ghe(){return Ii("local",Tn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function JF(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function R0(e,t){var n;return((n=JF(e,t))==null?void 0:n.available)===!0}function vhe(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!mhe.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Bh(){return{status:"idle"}}function yhe({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(ghe),[o,l]=b.useState("local"),[u,d]=b.useState(""),[f,h]=b.useState(""),[v,g]=b.useState(""),[_,w]=b.useState(Bh),[S,x]=b.useState(!1),T=b.useRef(null),k=b.useRef(null),A=b.useRef(null),I=b.useRef(null),R=b.useRef(i);R.current=i;const M=b.useRef(e);M.current=e;const z=bo("(min-width: 768px)"),Y=Re(te=>te.selectedProxyId),W=Yr(te=>te.capability),G=Yr(te=>te.capabilityStatus),O=Yr(te=>te.capabilityError),N=Yr(te=>{var Z;return((Z=te.authoritative)==null?void 0:Z.scope)??null}),L=N?`${N.proxyId}\0${N.bindingId}`:null,D=b.useCallback(te=>{R.current=te,s(te),Ir("local",Tn.webPreviewTunnelProvider,te)},[]);function P(){var te,Z;r(""),l("local"),d(""),h(""),g(""),w(Bh()),x(!1),(te=T.current)==null||te.abort(),T.current=null,(Z=k.current)==null||Z.abort(),k.current=null,A.current=null,I.current=null}const B=b.useCallback(async te=>{var ie;(ie=T.current)==null||ie.abort();const Z=new AbortController;T.current=Z;const ce=Pt.getActiveScope();if(!(!ce||ce.proxyId!==Y))try{const me=await Pt.requestWebPreviewCapability(ce,te,{signal:Z.signal});if(!me||Z.signal.aborted||!M.current||!me.success)return;const ge=R.current,ve=ge==="cloudflare"?"cpolar":"cloudflare";!R0(me.capability,ge)&&R0(me.capability,ve)&&D(ve)}catch{}},[D,Y]);function F(te){!te&&S||t(te)}b.useEffect(()=>{if(!e){P();return}return B(!1),()=>{var te;(te=T.current)==null||te.abort(),T.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(Bh()),g("");return}const Z=new AbortController;k.current=Z,w({status:"loading"}),g("");const ce=window.setTimeout(()=>{const me=Bt,ge=Pt.getActiveScope();if(!me||!ge||ge.proxyId!==Y){w({status:"error",message:"请先连接开发机"});return}Pt.inspectStaticWebPreview(ge,te,{signal:Z.signal}).then(ve=>{if(!ve||Z.signal.aborted||!M.current||!Pt.isActive(me,ge))return;if(!ve.success){w({status:"error",message:ve.error});return}const Te=ve.htmlEntries;if(Te.length===0&&!ve.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const Xe={entryPath:ve.entryPath,htmlEntries:Te};w({status:"ready",path:te,result:Xe}),g(ve.entryPath??"")}).catch(ve=>{Z.signal.aborted||!M.current||ve instanceof Error&&ve.name==="AbortError"||!Pt.isActive(me,ge)||w({status:"error",message:ve instanceof Error?ve.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(ce),Z.abort(),k.current===Z&&(k.current=null)}},[e,L,Y,o,f]);const U=o==="local"?vhe(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||v),V=G==="loaded"&&R0(W,i),H=S||!V||!(o==="local"?U===null:j);async function Q(){var me,ge,ve;if(H)return;const te=Bt;if(!te){He.error("请先连接开发机");return}let Z;if(o==="local")Z={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const Te=_.result.entryPath??v;if(!Te)return;Z={kind:"static",path:_.path,entryPath:Te}}x(!0);const ce=Pt.getActiveScope();if(!ce){x(!1),He.error("请先连接开发机");return}let ie=null;try{const Te=n.trim(),Xe=JSON.stringify({proxyId:ce.proxyId,tunnelProvider:i,source:Z,name:Te||void 0});((me=A.current)==null?void 0:me.sourceKey)!==Xe&&(A.current={sourceKey:Xe,operationId:wm(`preview-operation-${i}`)}),ie=A.current.operationId,I.current=ie;const wt=await Pt.createWebPreview(ce,Z,{tunnelProvider:i,operationId:ie,...Te?{name:Te}:{}});if(I.current!==ie)return;if(!wt.accepted){((ge=A.current)==null?void 0:ge.operationId)===ie&&(A.current=null),He.error(wt.error);return}if(((ve=A.current)==null?void 0:ve.operationId)===ie&&(A.current=null),!M.current||!Pt.isActive(te,ce))return;t(!1)}catch(Te){if(!ie||I.current!==ie||!M.current||!Pt.isActive(te,ce))return;He.error(Te instanceof Error?Te.message:"无法创建网页预览")}finally{ie&&I.current===ie&&(I.current=null,M.current&&x(!1))}}const ne=m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-web-preview-form",autoComplete:"off",onSubmit:te=>{te.preventDefault(),Q()},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(n_,{value:i,disabled:S,onValueChange:te=>D(te),children:[m.jsx(i_,{"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(r_,{})}),m.jsx(s_,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(U1).map(te=>m.jsx(o_,{value:te,"data-slot":"web-preview-tunnel-provider-option","data-provider":te,children:U1[te].label},te))})]})]}),m.jsx(bhe,{status:G,capability:W,provider:i,error:O,disabled:S,onRetry:()=>{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(Bh()),g(""),l("local")},className:We("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(Bh()),g(""),l("static")},className:We("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&&U!==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&&U?m.jsx("span",{"data-slot":"web-preview-local-url-error",className:"text-xs text-destructive",role:"alert",children:U}):null]}):m.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx(Gk,{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:h}),m.jsx(_he,{inspection:_,selectedEntryPath:v,disabled:S,onEntryPathChange:te=>{g(te)}})]}),m.jsxs(Gs,{children:[m.jsx(ct,{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(ct,{type:"submit",className:"min-h-11 md:min-h-0",disabled:H,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(Yi,{open:e,onOpenChange:F,children:m.jsxs(Vi,{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(Ki,{children:[m.jsx(Oi,{children:"新建网页预览"}),m.jsx(fs,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),ne]})}):m.jsx(vc,{open:e,onOpenChange:F,children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(bc,{children:"新建网页预览"}),m.jsx(e_,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),ne]})})}function bhe({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=U1[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(Gr,{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(Zz,{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(MI,{onClick:s,disabled:i})]})});const l=JF(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(PV,{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(h=>m.jsx("li",{"data-slot":n==="cloudflare"?"web-preview-cloudflared-suggestion":"web-preview-cpolar-suggestion","data-provider":n,"data-path":h,children:m.jsx("code",{className:"break-all rounded bg-muted px-1 py-0.5",children:h})},h))})]}):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(MI,{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(EV,{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 MI({onClick:e,disabled:t}){return m.jsxs(ct,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(bm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function _he({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(Gr,{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(n_,{value:t,onValueChange:r,disabled:n,children:[m.jsx(i_,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(r_,{placeholder:"选择网页"})}),m.jsx(s_,{children:e.result.htmlEntries.map(o=>m.jsx(o_,{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 whe({open:e,platform:t,onOpenChange:n}){const r=ks(),i=bo("(min-width: 768px)"),s=Re(F=>F.selectedProxyId),o=mr(F=>F.capability),l=mr(F=>F.targets),u=mr(F=>F.targetsStatus),d=mr(F=>F.targetsError),f=mr($5),h=mr(F=>{var U;return((U=F.authoritative)==null?void 0:U.scope)??null}),v=h?`${h.proxyId}\0${h.bindingId}`:null,[g,_]=b.useState(""),[w,S]=b.useState(null),[x,T]=b.useState(!1),k=b.useRef(null),A=b.useRef(e);A.current=e;const I=b.useRef(null),R=b.useRef(null),M=b.useMemo(()=>l.filter(F=>F.platform===t),[t,l]),z=b.useMemo(()=>new Set(f.map(F=>F.targetId)),[f]),Y=b.useMemo(()=>M.filter(F=>!z.has(F.targetId)),[z,M]),W=Y.find(F=>F.targetId===w),G=o==null?void 0:o[t],O=b.useCallback(async F=>{var X;(X=k.current)==null||X.abort();const U=new AbortController;k.current=U;const j=Bt,V=Pt.getActiveScope();if(!(!j||!V||V.proxyId!==s))try{const H=await Pt.requestDevicePreviewCapability(V,F,{signal:U.signal});if(!H||U.signal.aborted||!A.current||!H.success)return;await Pt.requestDevicePreviewTargets(V,!0,{signal:U.signal})}catch{}},[s]);b.useEffect(()=>{var F;if(!e){(F=k.current)==null||F.abort(),k.current=null,_(""),S(null),T(!1),I.current=null,R.current=null;return}return O(!1),()=>{var U;(U=k.current)==null||U.abort(),k.current=null}},[O,e,t,v]),b.useEffect(()=>{if(e){if(w&&!W){S(null);return}!w&&Y.length===1&&S(Y[0].targetId)}},[e,Y,W,w]);async function N(){var X,H,Q;const F=W;if(!F||x||(G==null?void 0:G.available)!==!0)return;const U=Bt,j=Pt.getActiveScope();if(!U||!j||j.proxyId!==s){He.error("请先连接开发机");return}T(!0);let V=null;try{const ne=g.trim(),te=((X=I.current)==null?void 0:X.proxyId)===j.proxyId&&I.current.targetId===F.targetId&&I.current.name===ne?I.current:{proxyId:j.proxyId,targetId:F.targetId,name:ne,operationId:wm("device-preview-operation")};I.current=te,V=te.operationId,R.current=V;const Z=await Pt.createDevicePreview(j,F.targetId,{operationId:te.operationId,...ne?{name:ne}:{}});if(R.current!==te.operationId)return;if(!Z.accepted){if(((H=I.current)==null?void 0:H.operationId)===te.operationId&&(I.current=null),!A.current||!Pt.isActive(U,j))return;He.error(Z.error);return}if(((Q=I.current)==null?void 0:Q.operationId)===te.operationId&&(I.current=null),!A.current||!Pt.isActive(U,j))return;n(!1),r(`/preview/device/${Z.previewId}`)}catch(ne){if(!V||R.current!==V||!A.current||!Pt.isActive(U,j))return;He.error(ne instanceof Error?ne.message:"无法创建模拟器预览")}finally{V&&R.current===V&&(R.current=null,A.current&&T(!1))}}function L(F){var U;!F&&x||(F||((U=k.current)==null||U.abort(),k.current=null,I.current=null,R.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(xhe,{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(Gr,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(PI,{message:d??"无法读取模拟器列表"}):M.length===0?m.jsx(PI,{message:`没有已启动的 ${W1[t]}`}):M.map(F=>{const U=F.targetId===w,j=z.has(F.targetId);return m.jsx(She,{target:F,selected:U,disabled:j||x,alreadyOpen:j,onClick:()=>{S(F.targetId)}},F.targetId)})}),m.jsxs(Gs,{className:"gap-2 sm:gap-2",children:[m.jsxs(ct,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>{O(!0)},"data-slot":"device-preview-refresh",children:[m.jsx(bm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(ct,{type:"button",disabled:!W||x||(G==null?void 0:G.available)!==!0,onClick:()=>{N()},"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),P=`新建 ${W1[t]} 预览`,B="选择开发机上已经启动的模拟器。";return i?m.jsx(Yi,{open:e,onOpenChange:L,children:m.jsxs(Vi,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:P}),m.jsx(fs,{children:B})]}),D]})}):m.jsx(vc,{open:e,onOpenChange:L,children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(bc,{children:P}),m.jsx(e_,{children:B})]}),D]})})}function xhe({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(Zz,{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 PI({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 She({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:We("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(da,{className:"size-4 text-primary","aria-hidden":"true"}):null]})}function QF({open:e,onOpenChange:t}){const[n,r]=b.useState(()=>e?"chooser":"closed"),i=b.useRef(null),s=bo("(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(A0,{icon:m.jsx(Qz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(A0,{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(A0,{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(Yi,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(Vi,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"新建预览"}),m.jsx(fs,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(vc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(yc,{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(ku,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(bc,{children:"新建预览"}),m.jsx(e_,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx(yhe,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(whe,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function A0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(ct,{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 Ehe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Yi,{open:e!==null,onOpenChange:n,children:m.jsxs(Vi,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"停止预览?"}),m.jsx(fs,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(ct,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"device-preview-close-confirm",children:t?"正在停止...":"停止预览"})]})]})})}const Che={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 khe({preview:e,selected:t,pendingOperation:n,onRename:r,onReconnect:i,onClose:s}){const o=Che[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",h=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[m.jsx("span",{className:We("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:We("shrink-0",l.text),children:l.label})]})]});return m.jsxs("li",{className:We("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(zC,{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:h}):m.jsx("div",{className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:h}),m.jsxs(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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(Gr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(wb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(ni,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(ni,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(Ul,{}),m.jsx(ni,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function The({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(Yi,{open:e!==null,onOpenChange:n,children:m.jsxs(Vi,{"data-slot":"preview-close-dialog",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"关闭预览?"}),m.jsx(fs,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(ct,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function Rhe({target:e,onOpenChange:t,onRename:n}){return m.jsx(Ahe,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function Ahe({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 h(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(Yi,{open:e!==null,onOpenChange:f,children:m.jsx(Vi,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>{h(v)},children:[m.jsx(Ki,{children:m.jsx(Oi,{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:We("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",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(Gs,{children:[m.jsx(ct,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(ct,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const Nhe={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 Mhe(e){return e.source.kind==="local"?e.source.url:Tb(e.source.rootPath,e.source.entryPath)}async function Phe(e){if(await Xp(e,{allowUserGestureFallback:!0})==="failed"){He.error("复制失败,请稍后重试");return}He.success("链接已复制")}async function Ihe(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;He.error("无法打开系统分享面板")}}function Ohe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=ii(w=>w.homePath),o=Nhe[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",h=d&&typeof navigator<"u"&&typeof navigator.share=="function",v=Mhe(e),g=e.source.kind==="static"?Gp(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:We("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(Qz,{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:We("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(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{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(Gr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(wb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(ni,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(ni,{"data-slot":"preview-row-copy-item",onSelect:()=>{Phe(u)},children:"复制链接"}):null,h?m.jsx(ni,{"data-slot":"preview-row-share-item",onSelect:()=>{Ihe(e.name,u)},children:"分享…"}):null,f?m.jsx(ni,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(Ul,{}),m.jsx(ni,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const Lhe=Object.freeze([]),Dhe=Object.freeze([]);function fd(e,t,n){return Object.freeze({kind:e,previewId:t,scope:Object.freeze({proxyId:n.proxyId,bindingId:n.bindingId})})}function Uc(e,t){return e!==null&&e.kind===t.kind&&e.previewId===t.previewId&&rn(e.scope,t.scope)}function vp(e,t,n){return t!==null&&n!==void 0&&rn(e.scope,t)&&rn(e.scope,n)}function zh(e){const t=Pt.getActiveScope(),n=e.kind==="web"?Yr.getState().authoritative:mr.getState().authoritative;return!n||!vp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function Yo(e){const t=Pt.getActiveScope();return t!==null&&rn(t,e)}function II(){const e=Yr(N=>N.authoritative),t=mr(N=>N.authoritative),n=Qo(N=>N.registry),r=Pt.getActiveScope(),i=r&&e&&rn(r,e.scope)?e.scope:null,s=r&&t&&rn(r,t.scope)?t.scope:null,o=i&&e?e.previews:Lhe,l=s&&t?t.previews:Dhe,u=zz("/preview/device/:id"),d=ks(),[f,h]=b.useState(null),[v,g]=b.useState(null),_=(v==null?void 0:v.kind)==="web"&&vp(v,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===v.previewId)??null:null,w=(v==null?void 0:v.kind)==="device"&&vp(v,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===v.previewId)??null:null,S=_??w,x=(f==null?void 0:f.kind)==="web"&&vp(f,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===f.previewId)??null:null,T=(f==null?void 0:f.kind)==="device"&&vp(f,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===f.previewId)??null:null;b.useEffect(()=>{v&&!S&&g(N=>Uc(N,v)?null:N),f&&!x&&!T&&h(N=>Uc(N,f)?null:N)},[f,T,v,S,x]);function k(N,L,D){var P;return(P=z5(n,N,L,D)[0])==null?void 0:P.kind}if(o.length===0&&l.length===0)return null;async function A(N){if(zh(N))try{const L=await Pt.reconnectWebPreview(N.scope,N.previewId);if(!Yo(N.scope))return;L.success||He.error(L.error)}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function I(N,L){if(!zh(N))return;let D;try{D=N.kind==="web"?await Pt.renameWebPreview(N.scope,N.previewId,L):await Pt.renameDevicePreview(N.scope,N.previewId,L)}catch(P){if(!Yo(N.scope))return;throw P}if(Yo(N.scope)&&!D.success)throw new Error(D.error)}async function R(N){if(zh(N))try{const L=await Pt.closeWebPreview(N.scope,N.previewId);if(!Yo(N.scope))return;if(!L.success){He.error(L.error);return}h(D=>Uc(D,N)?null:D)}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function M(N){if(zh(N))try{const L=await Pt.reconnectDevicePreview(N.scope,N.previewId);if(!Yo(N.scope))return;L.success||He.error(L.error)}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(N){if(zh(N))try{const L=await Pt.closeDevicePreview(N.scope,N.previewId);if(!Yo(N.scope))return;if(!L.success){He.error(L.error);return}h(D=>Uc(D,N)?null:D),(u==null?void 0:u.params.id)===N.previewId&&d("/sessions")}catch(L){if(!Yo(N.scope))return;He.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const Y=(f==null?void 0:f.kind)==="web"&&k(f.scope,"web",f.previewId)==="close",W=(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(N=>m.jsx(Ohe,{preview:N,pendingOperation:i?k(i,"web",N.previewId):void 0,onRename:()=>i&&g(fd("web",N.previewId,i)),onReconnect:()=>i&&void A(fd("web",N.previewId,i)),onClose:()=>i&&h(fd("web",N.previewId,i))},N.previewId)),l.map(N=>m.jsx(khe,{preview:N,selected:(u==null?void 0:u.params.id)===N.previewId,pendingOperation:s?k(s,"device",N.previewId):void 0,onRename:()=>s&&g(fd("device",N.previewId,s)),onReconnect:()=>s&&void M(fd("device",N.previewId,s)),onClose:()=>s&&h(fd("device",N.previewId,s))},N.previewId))]}),m.jsx(Rhe,{target:G&&S?{targetKey:`${G.kind}\0${G.scope.proxyId}\0${G.scope.bindingId}\0${G.previewId}`,name:S.name}:null,onOpenChange:N=>{!N&&G&&g(L=>Uc(L,G)?null:L)},onRename:N=>G?I(G,N):Promise.resolve()}),m.jsx(The,{preview:x,closing:Y,onOpenChange:N=>{!N&&!Y&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void R(O)}),m.jsx(Ehe,{preview:T,closing:W,onOpenChange:N=>{!N&&!W&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void z(O)})]})}function e6({layout:e}){const t=Ut(ie=>ie.sessions),n=Ut(ie=>ie.sessionListLoaded),r=Ut(ie=>ie.agentStatusBySessionId),i=Ut(ie=>ie.ptyStateBySessionId),s=Ut(ie=>ie.renameSession),o=cn(ie=>ie.bySessionId),l=zz("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Re(ie=>!!ie.selectedProxyId),f=Re(ie=>ie.proxyListLoaded),h=Re(ie=>ie.proxySwitchTarget),v=Ut(ie=>ie.loadingProxyName),g=h!==null||!f||d&&!n,_=(h==null?void 0:h.name)??v,w=_?`正在连接 ${_}...`:"连接中...",S=ks(),[x,T]=b.useState(!1),[k,A]=b.useState(!1),[I,R]=b.useState(!1),[M,z]=b.useState(!1),[Y,W]=b.useState(null),[G,O]=b.useState(null),{creatingTerminal:N,creatingShell:L,createTerminal:D}=t6(),[P,B]=b.useState(new Set),[F,U]=b.useState(()=>Date.now());b.useEffect(()=>{const ie=setInterval(()=>U(Date.now()),6e4);return()=>clearInterval(ie)},[]);function j(ie,me){S(`/chat/${ie}?mode=${me}`,{replace:!1})}function V(ie){const me=ie.sessionId,ge=Bt;if(!ge){He.error("请先连接开发机");return}ge.sendControl({type:"session_terminate",sessionId:me}),Ut.getState().removeSession(me),cn.getState().clearSession(me),me===u&&S("/sessions"),(ie==null?void 0:ie.kind)==="agent"&&ie.mode==="pty"&&ie.ptyOwner==="local-terminal"?He.info("已断开页面连接,本地终端仍在运行"):He.info("正在终止会话",{duration:1500})}async function X(ie,me){const ge=Bt;if(!ge)throw new Error("请先连接开发机");const ve=await ge.renameSession(ie,me);if(!ve.success)throw new Error(ve.error??"重命名失败");s(ie,ve.name??me),He.success("已重命名会话")}function H(ie){B(me=>{const ge=new Set(me);return ge.has(ie)?ge.delete(ie):ge.add(ie),ge})}function Q(ie){var ve;const me=ie.mode==="json"&&(((ve=o[ie.sessionId])==null?void 0:ve.pendingApprovals.some(Te=>Te.status==="pending"))??!1),ge=phe({session:ie,agentStatus:r[ie.sessionId],ptyState:i[ie.sessionId],hasPendingApproval:me});return ge===ie.state?ie:{...ie,state:ge}}const ne=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(mp,{open:x,onOpenChange:T}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]});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(Gr,{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(nu,{variant:"no-proxy"})}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]});const te=m.jsxs("h3",{className:"px-4 pt-3 pb-2 text-sm font-semibold text-foreground","data-slot":"active-section-header",children:["活跃会话",ne?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),Z=ne?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:Bhe(t).map(ie=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>H(ie.provider),"aria-expanded":!P.has(ie.provider),className:We("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:zhe(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(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!P.has(ie.provider)&&"rotate-90"),"aria-hidden":"true"})]}),P.has(ie.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:ie.sessions.map(me=>m.jsx($fe,{session:Q(me),selected:me.sessionId===u,now:F,onClick:()=>j(me.sessionId,me.mode),onRename:()=>W(me),onTerminate:()=>O(me)},me.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(Xfe,{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,Z,m.jsx(II,{}),ce]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(ct,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[m.jsx(Jz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(Uhe,{open:k,creatingTerminal:N,onOpenChange:A,onCreateAgent:()=>{A(!1),T(!0)},onCreateTerminal:()=>{n6()?(A(!1),R(!0)):D(void 0,()=>A(!1))},onCreatePreview:()=>{A(!1),z(!0)}}),m.jsx(r6,{layout:"mobile",open:I,creatingTerminal:N,creatingShell:L,onOpenChange:R,onBack:()=>{R(!1),A(!0)},onCreate:ie=>{D(ie,()=>R(!1))}}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(QF,{open:M,onOpenChange:z}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[te,Z,m.jsx(II,{}),ce]}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(Rv,{open:G!==null,session:G,onOpenChange:ie=>{ie||O(null)},onConfirm:V}),m.jsx(gp,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ie=>{ie||W(null)},onRename:X})]})}function Bhe(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])=>jhe(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function zhe(e){return e==="terminal"?"终端":t_(e)}function jhe(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:HF(e,t)}function t6(){const e=ks(),[t,n]=b.useState(null),r=t!==null;async function i(s,o){var u;const l=Re.getState();if(!(r||!l.connected||!l.proxyOnline||!l.selectedProxyId||l.proxySwitchTarget)&&!Zk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await ahe({relay:Bt,shell:s});if(d.type!=="success"){He.error(d.message);return}Ut.getState().addSession(d.session),o==null||o(),e(d.route)}finally{n(null)}}}return{creatingTerminal:r,creatingShell:t,createTerminal:i}}function Zk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function Fhe(e){const t=Re(u=>u.terminalShells),n=Re(Zk),r=Re(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=Bt,f=d==null?void 0:d.getPreviewScope();if(s(!1),!d||!f||f.proxyId!==r){s(!0);return}return d.requestProxyInfo().then(h=>{const v=Re.getState(),g=d.getPreviewScope();u||!v.connected||!v.proxyOnline||v.selectedProxyId!==r||!g||!rn(f,g)||v.setTerminalShells(h.terminalShells)},()=>{u||s(!0)}),()=>{u=!0}},[e,n,r,o]),{terminalShells:t,needsDetection:n,failed:i,retry:()=>l(u=>u+1)}}const Hhe=[{label:"启动 Shell"}];function $he(e){return e!=null&&e.length?e:Hhe}function n6(){var t;const e=Re.getState();return Zk(e)||!!((t=e.terminalShells)!=null&&t.length)}function OI({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),h=b.useRef(!1),v=Re(Y=>!!Y.selectedProxyId),g=Re(Y=>Y.proxySwitchTarget!==null),_=v&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=t6();function T(){f(!0),window.setTimeout(()=>f(!1),2e3)}function k(){if(!_){T();return}h.current=!0,o(!0)}function A(){if(!_){T();return}h.current=!0,n6()?i(!0):x()}function I(){if(!_){T();return}h.current=!0,u(!0)}function R(Y){Y.preventDefault(),T()}const M=m.jsxs(ct,{variant:"outline","data-slot":"create-session-trigger",className:We(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!_&&"opacity-50 hover:bg-background"),"aria-label":"新建","aria-disabled":!_,onClick:_?void 0:R,children:[m.jsx(Jz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),z=_?m.jsxs(Cf,{open:t,onOpenChange:n,children:[m.jsx(kf,{asChild:!0,children:M}),m.jsxs(Tf,{align:e?"end":"start",className:"w-80","data-slot":"create-session-type-menu",onCloseAutoFocus:Y=>{h.current&&(h.current=!1,Y.preventDefault())},children:[m.jsxs(ni,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:k,children:[m.jsx(Xz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ni,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:w,onSelect:A,children:[m.jsx(ou,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),w?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx(Ul,{}),m.jsxs(ni,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:I,children:[m.jsx(UC,{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:"在浏览器中预览网页或设备模拟器"})]})]})]})]}):M;return m.jsxs(m.Fragment,{children:[_?z:m.jsxs(Rf,{open:_?void 0:d,onOpenChange:_?void 0:f,children:[m.jsx(Af,{asChild:!0,children:z}),m.jsx(Nf,{side:"top",children:g?"正在切换开发机":"请先连接开发机"})]}),m.jsx(r6,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:Y=>{x(Y,()=>i(!1))}}),m.jsx(mp,{open:s,onOpenChange:o}),m.jsx(QF,{open:l,onOpenChange:u})]})}function Uhe({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(vc,{open:e,onOpenChange:n,children:m.jsxs(yc,{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(ku,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(bc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(ct,{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(Xz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ct,{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(ou,{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(ct,{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(UC,{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 r6({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=Fhe(t),h=b.useRef(!1),v=Re(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(ct,{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(ou,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"终端检测失败,点击重试":"正在检测终端..."]}):$he(l).map(w=>m.jsxs(ct,{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(Yfe,{shell:w.id,label:w.label}),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(ct,{type:"button",variant:"ghost",className:"min-h-11 justify-start gap-3 px-3 text-muted-foreground",disabled:n,onClick:()=>{h.current=!0,s()},children:[m.jsx(gf,{className:"size-4","aria-hidden":"true"}),"返回"]})]});function _(w){h.current&&(h.current=!1,w.preventDefault())}return e==="mobile"?m.jsx(vc,{open:t,onOpenChange:i,children:m.jsxs(yc,{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(ku,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(bc,{children:"Shell 会话"})}),g]})}):m.jsx(Yi,{open:t,onOpenChange:i,children:m.jsxs(Vi,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(Ki,{children:m.jsx(Oi,{children:"Shell 会话"})}),g]})})}const Whe="0.10.9",qhe={version:Whe},Yhe={playback:"playback",capture:"play-and-record"};function Vhe(){return typeof navigator>"u"?null:navigator.audioSession??null}function Khe(){return{setMode:()=>{},release:()=>{}}}class Ghe{constructor(t=Vhe){Me(this,"getAudioSession");Me(this,"leases",new Map);Me(this,"session",null);Me(this,"baselineType",null);Me(this,"nextLeaseId",1);Me(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Khe();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(Yhe[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 Jk=new Ghe,q1=64,LI=-60,i6=32;function DI(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-LI)/-LI));return e<0?-r:r}function BI(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 h=l;h<u;h+=1){const v=i.getInt16(h*2,!0)/32768;d=Math.min(d,v),f=Math.max(f,v)}s.push({min:d,max:f})}return s}function Xhe(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 Zhe(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 s6{constructor(t,n=24e3,r={}){Me(this,"context");Me(this,"sampleRate");Me(this,"options");Me(this,"nextStartTime",0);Me(this,"activityEndToken",0);Me(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=Xhe(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*i6/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),h=t.slice(l*Int16Array.BYTES_PER_ELEMENT,u*Int16Array.BYTES_PER_ELEMENT),v=Zhe(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,h)},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 N0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},zI="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",Jhe=800,jI=300,Qhe=1600;function Y1(e,t){return e.filter(n=>!n.model||n.model===t)}function FI({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 Av({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),h=n.filter(g=>!g.disabled),v=!!o6(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:h.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(HI,{label:f,muted:!d&&!t}),m.jsx(ac,{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(da,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(HI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function HI({label:e,muted:t=!1}){const n=o6(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 epe({scrollRef:e}={}){const[t,n]=b.useState(N0),[r,i]=b.useState(String(N0.turnIdleSeconds)),[s,o]=b.useState(()=>hv()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[h,v]=b.useState(!1),[g,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),T=b.useRef(null),k=b.useRef(null),A=b.useRef(!1);b.useEffect(()=>{const Z=Bt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce=!1;return _({kind:"loading"}),Z.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 Z=Bt;if(!Z||!h)return;let ce=!1;return Z.requestVoiceCapabilities({region:t.region}).then(ie=>{if(!ce){if(ie.error||!ie.capabilities){o(hv());return}o(ie.capabilities)}}).catch(()=>{ce||o(hv())}),()=>{ce=!0}},[t.region,h]),b.useEffect(()=>(A.current=!0,()=>{A.current=!1,H(),Q()}),[]);const I=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]),R=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",M=b.useMemo(()=>Y1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),Y=M.some(Z=>Z.value===t.ttsVoice)?t.ttsVoice:"",W=M.length===0?"当前模型暂无可用音色":Y?null:"请选择可用音色",G=b.useMemo(()=>ipe(r),[r]),O=G?null:"请输入正整数秒数",N=W??O,L=R||!!N,D=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>WI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),B=b.useMemo(()=>spe(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>WI(M,Y),[M,Y]);function U(){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??N0.turnIdleSeconds}}async function j(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=Bt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ce=U();Q(),_({kind:"saving"});const ie=performance.now();try{const me=await Z.updateVoiceConfig(ce);if(!A.current)return;const ge=performance.now()-ie;if(ge<jI&&await rpe(jI-ge),!A.current)return;if(!me.success||me.error||!me.config){_({kind:"error",message:me.error??"保存语音设置失败"});return}n(me.config),i(String(me.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),k.current=setTimeout(()=>{k.current=null,_(ve=>ve.kind==="saved"?{kind:"idle"}:ve)},Qhe),Z.requestVoiceCapabilities({region:me.config.region}).then(ve=>{A.current&&ve.capabilities&&o(ve.capabilities)}).catch(()=>{A.current&&o(hv())})}catch(me){if(!A.current)return;_({kind:"error",message:me instanceof Error?me.message:"保存语音设置失败"})}}async function V(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=Bt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ce;try{ce=X()}catch(ie){_({kind:"error",message:UI(ie)});return}_({kind:"testing"});try{const[ie]=await Promise.all([Z.testVoiceConfig(U()),ce.ready]);if(!ie.success||ie.error){H(),_({kind:"error",message:ie.error??"语音配置测试失败"});return}const me=await ne(ie,ce.context);_({kind:"playingTest",transcript:ie.transcript}),T.current=setTimeout(()=>{T.current=null,H(),_({kind:"testPassed",transcript:ie.transcript})},me)}catch(ie){H(),_({kind:"error",message:UI(ie)})}}function X(){H();const Z=Jk.acquire("playback");S.current=Z;try{const ce=npe();return w.current=ce,{context:ce,ready:$I(ce)}}catch(ce){throw Z.release(),S.current=null,ce}}function H(){var Z,ce,ie;T.current&&(clearTimeout(T.current),T.current=null),(Z=x.current)==null||Z.stop(),x.current=null,(ce=w.current)==null||ce.close(),w.current=null,(ie=S.current)==null||ie.release(),S.current=null}function Q(){k.current&&(clearTimeout(k.current),k.current=null)}async function ne(Z,ce){if(!Z.audioBase64)throw new Error("语音测试未返回可播放音频");if(Z.audioEncoding&&Z.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ie=Z.audioSampleRate??24e3,me=tpe(Z.audioBase64);if(me.byteLength===0||me.byteLength%2!==0)throw new Error("测试音频数据无效");await $I(ce);const ge=new s6(ce,ie);x.current=ge,ge.enqueue(me);const ve=Math.ceil(me.byteLength/2/ie*1e3);return Math.max(Jhe,ve)}function te(Z){var ce;return((ce=Y1(s.ttsVoices,Z)[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:Z=>{Z.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(FI,{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(rj,{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:Z=>{u(Z.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${zI} w-full pl-9`})]}),t.configured&&m.jsxs(ct,{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(lj,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(Av,{label:"地域",value:t.region,options:D,onChange:Z=>n(ce=>({...ce,region:Z==="intl"?"intl":"cn"}))}),m.jsx(Av,{label:"语音识别模型",value:t.asrModel,options:P,onChange:Z=>n(ce=>({...ce,asrModel:Z}))}),m.jsx(Av,{label:"语音合成模型",value:t.ttsModel,options:B,onChange:Z=>n(ce=>({...ce,ttsModel:Z,ttsVoice:te(Z)}))}),m.jsx(Av,{label:"语音音色",value:Y,options:F,placeholder:M.length===0?"暂无可用音色":"请选择音色",onChange:Z=>n(ce=>({...ce,ttsVoice:Z})),help:W}),m.jsx(FI,{label:"结束停顿时间(秒)",help:O,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:Z=>i(Z.target.value),className:`${zI} 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:[I?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:I}):null,m.jsxs(ct,{type:"button",variant:"outline",disabled:L,onClick:()=>{V()},children:[m.jsx(WC,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(ct,{type:"submit",disabled:L,children:[m.jsx(UK,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function tpe(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 npe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function $I(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function UI(e){return e instanceof Error?e.message:"语音配置测试失败"}function rpe(e){return new Promise(t=>setTimeout(t,e))}function ipe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function WI(e,t){const n=e.map(r=>({value:r.value,label:a6(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function spe(e,t,n){const r=e.map(i=>{const s=Y1(t,i.value).length===0;return{value:i.value,label:`${a6(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function o6(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 a6(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 ope=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],ape=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],Qk="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function l6(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 lpe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function cpe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function upe(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function V1({open:e,onOpenChange:t}){const n=Re(G=>G.relayUrl),r=Re(G=>G.latencyMonitorEnabled),i=Re(G=>G.setLatencyMonitorEnabled),s=Re(G=>G.sessionIdleNotificationsEnabled),o=Re(G=>G.setSessionIdleNotificationsEnabled),l=Re(G=>G.inputModePreference),u=Re(G=>G.setInputModePreference),d=Re(G=>G.themePreference),f=Re(G=>G.setThemePreference),h=Re(G=>G.ptyScrollTraceEnabled),v=Re(G=>G.setPtyScrollTraceEnabled),[g,_]=b.useState("menu"),[w,S]=b.useState(e),[x,T]=b.useState({kind:"idle"}),k=b.useRef(null),A=b.useRef(null),I=Toe(),R=b.useMemo(()=>bf().osName==="iPad",[]);e!==w&&(S(e),e&&_("menu"));const M=b.useCallback(async G=>{if(!G){o(!1);return}const O=await Jse();if(O==="granted"){o(!0);return}if(O==="denied"){He.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(O==="default"){He.info("未授予通知权限,会话通知保持关闭");return}He.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{T({kind:"loading"});try{const O=await fetch(lpe(n),{cache:"no-store",signal:G});if(!O.ok)throw new Error(`HTTP ${O.status}`);const N=await O.json();if(N.status!=="ok")throw new Error("状态异常");T({kind:"ready",version:N.version??"未知",uptime:N.uptime??0})}catch(O){if(O instanceof DOMException&&O.name==="AbortError")return;T({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}),A.current&&(A.current.scrollTop=0)});return()=>window.cancelAnimationFrame(G)},[e,g]);const Y=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",W=x.kind==="ready"?`运行 ${l6(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(Yi,{open:e,onOpenChange:t,children:m.jsxs(Vi,{className:We("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":g,focusSurfaceOnOpen:!0,ref:k,showCloseButton:g==="menu",children:[m.jsx(Ki,{className:We(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(ct,{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(gf,{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(Oi,{children:cpe(g)}),m.jsx(fs,{className:"max-w-[28rem] leading-5",children:upe(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(Oi,{children:"设置"}),m.jsx(fs,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(dpe,{relayVersion:Y,relayDetail:W,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(hpe,{saved:I}):g==="clients"?m.jsx(ype,{}):g==="voice"?m.jsx(epe,{scrollRef:A}):m.jsx(fpe,{relayTokenSaved:I,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:R,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:M,ptyScrollTraceEnabled:h,onPtyScrollTraceEnabledChange:v,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function dpe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:Qk,"data-slot":"settings-dialog-body",children:[m.jsx(YI,{icon:m.jsx(ij,{className:"size-4","aria-hidden":"true"}),label:"Web",value:qhe.version,detail:"当前浏览器加载的版本"}),m.jsx(YI,{icon:m.jsx(oj,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function fpe({relayTokenSaved:e,themePreference:t,onThemePreferenceChange:n,inputModePreference:r,onInputModePreferenceChange:i,showInputModeSetting:s,sessionIdleNotificationsEnabled:o,onSessionIdleNotificationsEnabledChange:l,ptyScrollTraceEnabled:u,onPtyScrollTraceEnabledChange:d,latencyMonitorEnabled:f,onLatencyMonitorEnabledChange:h,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(hd,{title:"服务",children:[m.jsx(Nv,{icon:m.jsx(pV,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:v}),m.jsx(Nv,{icon:m.jsx(rj,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(Nv,{icon:m.jsx(dG,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(hd,{title:"外观",children:m.jsx(qI,{icon:m.jsx(eG,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:ope,onValueChange:n})}),m.jsx(hd,{title:"通知",children:m.jsx(P0,{icon:m.jsx(gV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(hd,{title:"交互",children:m.jsx(qI,{icon:m.jsx(HC,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:ape,onValueChange:i})}):null,m.jsxs(hd,{title:"高级诊断",children:[m.jsx(P0,{icon:m.jsx(ou,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(P0,{icon:m.jsx(Kz,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:h})]}),m.jsx(hd,{title:"关于",children:m.jsx(Nv,{icon:m.jsx(oj,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function hd({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 qI({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:We("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function hpe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{Q5().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!Z5(f)){const h="Relay Token 保存失败,请检查浏览器存储权限。";o(h),He.error(h);return}o(null),He.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{J5(),l()};return m.jsxs("form",{className:Qk,"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(ct,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(ct,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function ppe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function mpe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||ppe(e)}function gpe(e){return Ure(e)}function vpe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return l6(t)}function M0({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 ype(){const e=Re(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=Bt;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 h=b.useCallback(async v=>{const g=Bt;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:Qk,"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(ct,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>{f()},disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(bm,{className:We("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:gpe(v)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(M0,{label:"已连接",value:vpe(v.connectedAt)}),v.proxyId?m.jsx(M0,{label:"连接到",value:mpe(v.proxyId,d),title:v.proxyId}):null,v.remoteAddress?m.jsx(M0,{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(ct,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>{h(v.clientId)},"data-slot":"relay-client-action",children:[m.jsx(vK,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},v.clientId)})]})}function P0({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:We("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),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:We("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:We("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function Nv({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(Yd,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function YI({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:We("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),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 bpe="xterm-helper-textarea";function _pe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(bpe)?!1:(e.blur(),!0)}function VI(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&&wpe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function wpe(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 xpe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&_pe()},[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,VI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(VI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function Spe({className:e}){const t=Re(o=>o.sidebarCollapsed),n=Re(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=xpe();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:We("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(GI,{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(KI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(OI,{compact:!0})]})]}),m.jsx(V1,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:We("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[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(kj,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(GI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(FF,{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(e6,{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(OI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(KI,{onClick:()=>i(!0)})})]})]}),m.jsx(V1,{open:r,onOpenChange:i})]})}function KI({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(Rf,{delayDuration:500,children:[m.jsx(Af,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:We("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(aj,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(Nf,{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 GI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?AK:TK;return m.jsxs(Rf,{delayDuration:500,children:[m.jsx(Af,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:We("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:We("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(Nf,{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 Epe=1500,Cpe=300,XI=70,ZI=35;function c6({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(h=>!h),530);return()=>clearInterval(f)},[]),b.useEffect(()=>{let f;const h=()=>e[u.current%e.length],v=()=>{const g=o.current;if(g==="typing"){const _=h();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(v,XI)):(o.current="paused",f=setTimeout(v,Epe))}else g==="paused"?(o.current="deleting",f=setTimeout(v,ZI)):g==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),f=setTimeout(v,ZI)):(u.current+=1,o.current="waiting",f=setTimeout(v,Cpe)):(o.current="typing",f=setTimeout(v,XI))};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 u6=["DEV Anywhere","/unlimited @anytime"];function kpe({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(c6,{texts:u6,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 Tpe=3e3,Rpe=1e4,Mv=12,Ape=4,JI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Npe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function I0(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 pd(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function yp(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function QI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function d6(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Mpe(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 Ppe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?yp(e.rttMs):"等待检测"}function Ipe(){const e=Ii("local",Tn.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 eO(e){Ir("local",Tn.latencyMonitorPosition,JSON.stringify(e))}function Ope(){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 O0(e,t){const n=Ope(),r=Mv,i=Mv,s=Math.max(r,n.width-t.width-Mv),o=Math.max(i,n.height-t.height-Mv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function Lpe(){const e=Re(R=>R.latencyMonitorEnabled),t=Re(R=>R.connected),n=Re(R=>R.proxyOnline),r=Re(R=>R.selectedProxyId),[i,s]=b.useState(Npe),[o,l]=b.useState(()=>Ipe()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),h=b.useRef(!1),v=b.useMemo(()=>(Object.values(i).sort((R,M)=>QI(M.state)-QI(R.state))[0]??{state:"idle"}).state,[i]),g=d6(v);async function _(){if(u.current)return;const R=Bt;if(!R||!t){const W=pd("Relay 服务器未连接");s({webRelay:W,relayProxy:W,webProxy:W});return}u.current=!0,s(W=>({webRelay:{...W.webRelay,state:"measuring"},relayProxy:n?{...W.relayProxy,state:"measuring"}:pd("未连接开发机"),webProxy:n?{...W.webProxy,state:"measuring"}:pd("未连接开发机")}));const[M,z,Y]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:M.status==="fulfilled"?I0(M.value):pd(M.reason instanceof Error?M.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?I0(z.value):pd(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:Y.status==="fulfilled"?I0(Y.value):pd(Y.reason instanceof Error?Y.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let R=!1,M=null;const z=async()=>{await _(),!R&&(M=setTimeout(z,document.hidden?Rpe:Tpe))};return z(),()=>{R=!0,u.current=!1,M&&clearTimeout(M)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const R=d.current;if(!R)return;const M=R.getBoundingClientRect(),z=O0(o,{width:M.width,height:M.height});z.x===o.x&&z.y===o.y||(l(z),eO(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(R){var z,Y;if(R.button!==0)return;const M=R.currentTarget.getBoundingClientRect();f.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,originX:M.left,originY:M.top,width:M.width,height:M.height,dragging:!1},(Y=(z=R.currentTarget).setPointerCapture)==null||Y.call(z,R.pointerId)}function T(R){const M=f.current;if(!M||M.pointerId!==R.pointerId)return;const z=R.clientX-M.startX,Y=R.clientY-M.startY;if(!M.dragging&&Math.hypot(z,Y)<Ape)return;M.dragging=!0,R.preventDefault();const W=O0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(W)}function k(R){var G,O;const M=f.current;if(!M||M.pointerId!==R.pointerId||(f.current=null,(O=(G=R.currentTarget).releasePointerCapture)==null||O.call(G,R.pointerId),!M.dragging))return;R.preventDefault(),h.current=!0,window.setTimeout(()=>{h.current=!1},200);const z=R.clientX-M.startX,Y=R.clientY-M.startY,W=O0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(W),eO(W)}function A(R){var z,Y;const M=f.current;!M||M.pointerId!==R.pointerId||(f.current=null,(Y=(z=R.currentTarget).releasePointerCapture)==null||Y.call(z,R.pointerId))}function I(R){h.current&&(h.current=!1,R.preventDefault(),R.stopPropagation())}return m.jsxs(Zb,{children:[m.jsx(Jb,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:We("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Mpe(g)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${yp(i.webRelay.rttMs)},开发机 ${yp(w.rttMs)}`,onPointerDown:x,onPointerMove:T,onPointerUp:k,onPointerCancel:A,onClickCapture:I,children:[m.jsx(Kz,{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 ",yp(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",yp(w.rttMs)]}),m.jsx(ac,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(Qb,{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(ct,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>{_()},children:m.jsx(bm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(JI).map(R=>m.jsx(Dpe,{label:JI[R],measurement:i[R]},R))})]})]})}function Dpe({label:e,measurement:t}){const n=d6(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:We("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Ppe(t)})]})]})}const f6="/__dev_anywhere_debug/browser-state-dumps",Bpe=1500,zpe=10,L0=80,eT=500,jpe=["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"],Fpe=["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 tO(){if(typeof window>"u")return"off";const e=_6("debugDump");return e==="auto"?"auto":e!==null||Gpe("debugInput")?"manual":"off"}function Hpe(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:qpe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:nO(document.activeElement),selection:Ype(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>nO(i)).filter(i=>!!i),root:h6(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:md(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:md(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:md(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:md(()=>rO(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:md(()=>rO(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:md(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function $pe(e="manual"){const t=Hpe(e);return Upe(t)}async function Upe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Wpe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:f6}}catch(r){const i=w6(r),s=Vpe(e.createdAt);return Kpe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Wpe(e){const t=await fetch(f6,{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 h6(e,t,n){if(n.count>=Bpe||t>zpe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=iO(e.textContent??"");return u?{kind:"text",text:a_(u,eT)}:{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,L0))u.nodeType===Node.TEXT_NODE&&!iO(u.textContent??"")||r.push(h6(u,t+1,n));s.length>L0&&(i=s.length-L0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:b6(e),attrs:p6(e),rect:m6(e),scroll:g6(e),style:v6(e)},l=y6(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function nO(e){if(!(e instanceof HTMLElement))return null;const t=y6(e);return{path:b6(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:p6(e),rect:m6(e),scroll:g6(e),style:v6(e),...t?{value:t}:{}}}function qpe(){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 p6(e){const t={};for(const n of jpe){const r=e.getAttribute(n);r!==null&&(t[n]=a_(r,500))}return t}function m6(e){const t=e.getBoundingClientRect();return{x:Cs(t.x),y:Cs(t.y),width:Cs(t.width),height:Cs(t.height),top:Cs(t.top),right:Cs(t.right),bottom:Cs(t.bottom),left:Cs(t.left)}}function g6(e){return{top:Cs(e.scrollTop),left:Cs(e.scrollLeft),height:Cs(e.scrollHeight),width:Cs(e.scrollWidth),clientHeight:Cs(e.clientHeight),clientWidth:Cs(e.clientWidth)}}function v6(e){const t=window.getComputedStyle(e),n={};for(const r of Fpe)n[r]=t.getPropertyValue(r);return n}function y6(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:a_(e.value,eT),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Ype(){var e;try{return a_(((e=window.getSelection())==null?void 0:e.toString())??"",eT)}catch{return null}}function b6(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 Vpe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Kpe(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 Gpe(e){return _6(e)!==null}function _6(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 rO(e){return e?Gy(e.slice(-200)):null}function md(e){try{return Gy(e())}catch(t){return{error:w6(t)}}}function Gy(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(Gy);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Gy(r);return t}return String(e)}function iO(e){return e.replace(/\s+/g," ").trim()}function a_(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Cs(e){return Math.round(e*100)/100}function w6(e){return e instanceof Error?e.message:String(e)}const Xpe=500,Zpe=1e3,Jpe=60;function Qpe(){const[e,t]=b.useState(()=>tO()),[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(tO());return window.addEventListener("hashchange",_),window.addEventListener("popstate",_),()=>{window.removeEventListener("hashchange",_),window.removeEventListener("popstate",_)}},[]);const h=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 $pe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&eme(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=h,()=>{window.__devAnywhereDumpBrowserState===h&&delete window.__devAnywhereDumpBrowserState}),[h]),b.useEffect(()=>{var T,k;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=A=>{d.current>=Jpe||(_(),f.current=window.setTimeout(()=>{f.current=null;const I=Date.now(),R=Zpe-(I-u.current);if(R>0){f.current=window.setTimeout(()=>w(A),R);return}u.current=Date.now(),d.current+=1,h(`auto:${d.current}:${A}`)},Xpe))};w("initial");const S=["focusin","focusout","beforeinput","input","compositionstart","compositionupdate","compositionend","keydown","keyup","pointerdown","pointerup","resize","visibilitychange"],x=A=>w(A.type);return S.forEach(A=>window.addEventListener(A,x,!0)),(T=window.visualViewport)==null||T.addEventListener("resize",x),(k=window.visualViewport)==null||k.addEventListener("scroll",x),()=>{var A,I;_(),S.forEach(R=>window.removeEventListener(R,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(I=window.visualViewport)==null||I.removeEventListener("scroll",x)}},[h,e]),e==="off")return null;const v=e==="auto"?"自动诊断中":"保存诊断",g=tme(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(ct,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>{h("manual")},disabled:n,"data-slot":"browser-state-dump",children:[n?m.jsx(Gr,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(QV,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:v})]})]})}function eme(e){if(e.status==="saved"){He.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){He.info(`诊断已下载: ${e.filename}`);return}He.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function tme(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function nme({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(Gr,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(ct,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function rme(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 tT(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:rme(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 h=i(d);if(h!==null){const v=s.get(d.event);if(v&&i(v)===h&&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 h=f.splice(0,f.length-r);if(i)for(const v of h)s.get(v.event)===v&&s.delete(v.event)}u(f)},getAll:l}}function tr(e){return Math.round(e*10)/10}function Bl(e){return e.length===0?"":`${tr(Math.min(...e))}..${tr(Math.max(...e))}`}function Bd(e){return[...new Set(e.filter(t=>t!==void 0).map(tr))]}function x6(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 ime="dev_anywhere_pty_input_latency_trace",sO=80,sme=1e4,ome=new TextDecoder;let ame=0;const df=new Map,Tu=tT({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:ime,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function lme(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=fme)}function cme(e,t){if(!Tu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++ame}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:mme(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=df.get(e)??[];return s.push(i),rT(s,r),df.set(e,s),Om({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function oO(e,t){if(!e||!Tu.isEnabled())return;const n=performance.now(),r=hme(e.sessionId,e.inputId);r&&(r.sentAt=n),Om({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 ume(e,t,n){if(!Tu.isEnabled())return;const r=performance.now(),i=nT(e,r),s=yme(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&vme(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Om({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:iT(i,r),details:bme([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function dme(e,t,n=1){if(!Tu.isEnabled())return;const r=performance.now(),i=nT(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Om({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:iT(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>pme(e,s))}function fme(){const e=Tu.getAll(),t=e.slice(-200),n=[...df.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":tr(s.sentAt-s.startedAt),s.firstOutputAt===null?"":tr(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":tr(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":tr(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":tr(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[tr(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?"":tr(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(`
606
606
  `)}function Om(e){Tu.append(e)}function nT(e,t){const n=df.get(e)??[];return rT(n,t),df.set(e,n),n}function rT(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>sme;(i||s)&&e.splice(n,1)}e.length>sO&&e.splice(0,e.length-sO)}function hme(e,t){return(df.get(e)??[]).find(n=>n.inputId===t)??null}function pme(e,t){if(!Tu.isEnabled())return;const n=performance.now(),r=nT(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)}Om({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:iT(r,n),details:i>0?`paint=${i}`:""}),rT(r,n)}function iT(e,t){const n=e[0];return n?t-n.startedAt:null}function mme(e){return e==="\r"||e===`
607
607
  `?"enter":e.startsWith("\x1B")?"escape":gme(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function gme(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 vme(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function yme(e){try{return ome.decode(e)}catch{return""}}function bme(e){return e.filter(Boolean).join(" ")}function Io(e,t){if(!e||!t)return;const n=cme(e,t),r=Wa;if(!r){oO(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});oO(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}function _me({sessionId:e,enabled:t,waiting:n,approvalRequestId:r,approvalScopeKey:i=e,history:s,sendRawInput:o=Io}){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 wme(e){var i,s;if(e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.provider==="codex")return null;const t=ck(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 xme({target:e,sendRawInput:t,history:n}){return _me({sessionId:e.sessionId,enabled:e.enabled,waiting:e.waiting,approvalRequestId:e.approvalRequestId,approvalScopeKey:e.key,history:n,sendRawInput:t}),null}function Sme({sendRawInput:e=Io}){const t=Re(d=>d.connected),n=Re(d=>d.proxyOnline),r=Re(d=>d.selectedProxyId),i=Ut(d=>d.sessions),s=Ut(d=>d.agentStatusBySessionId),o=Ut(d=>d.ptyAutoYesBySessionKey),l=b.useRef(new Map),u=i.map(d=>wme({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(xme,{target:d,sendRawInput:e,history:l.current},d.key))})}function Eme(e,t){return e.some(n=>n.sessionId===t)?e:[...e,{sessionId:t}]}const Cme={[Or.PATH_NOT_FOUND]:"文件不存在",[Or.PATH_NOT_DIRECTORY]:"路径不是目录",[Or.PATH_ACCESS_DENIED]:"无权访问该路径",[Or.INVALID_PATH]:"路径无效",[Or.SESSION_NOT_FOUND]:"会话已结束",[Or.SESSION_ALREADY_ACTIVE]:"Codex 会话仍在运行",[Or.PROXY_OFFLINE]:"开发机已离线",[Or.PROVIDER_UNSUPPORTED]:"不支持的 Provider",[Or.APPROVAL_POLICY_UNSUPPORTED]:"不支持的审批策略",[Or.WORKER_START_FAILED]:"Worker 启动失败",[Or.PROCESS_START_FAILED]:"进程启动失败"};function S6(e){const t=e.errorCode?Cme[e.errorCode]:void 0;return t||(e.rawError&&e.rawError.trim().length>0?e.rawError:e.fallback)}function sT(e){if(/^[a-z][a-z0-9+.-]*:\/\//i.test(e))return!1;const t=e.indexOf(":");if(t<=0)return!1;const n=e.slice(0,t),r=e.slice(t+1);return!r.includes("/")||!/^[A-Za-z0-9._~-]+(?:@[A-Za-z0-9.-]+)?$/.test(n)||!(n.includes("@")?n.slice(n.lastIndexOf("@")+1):n).includes(".")?!1:/^[A-Za-z0-9._~%+-]+(?:\/[A-Za-z0-9._~%+-]+)+$/.test(r)}const kme=new RegExp("(?<![\\p{L}\\p{N}@:/.-])(?:~\\/|[^\\s`\"'<>,。;:!?、@])[^\\s`\"'<>,。;:!?、@]*?\\.(?:png|jpe?g|webp|gif|bmp|heic|heif|mp4|webm|mov|m4v|ogv)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","giu"),Tme=new RegExp("(?<![A-Za-z0-9._+-])@(?:~\\/|[^\\s`\"'<>,。;:!?、@])[^\\s`\"'<>,。;:!?、@]*?\\.(?:png|jpe?g|webp|gif|bmp|heic|heif|mp4|webm|mov|m4v|ogv)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","giu"),E6=/\.(?:png|jpe?g|webp|gif|bmp|heic|heif|mp4|webm|mov|m4v|ogv)$/i;function oT(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function C6(e){if(/[\\/]/.test(e))return!0;const t=e.replace(E6,""),n=t.split(/[\\/]/).pop()??t;return n.length<2?!1:/[\p{L}_-]/u.test(n)}function _c(e){const t=oT(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||sT(t)||!E6.test(t)?null:/\.(?:mp4|webm|mov|m4v|ogv)$/i.test(t)?"video":"image"}function Rme(e){const t=oT(e);return _c(t)?C6(t):!1}function k6(e){const t=[];for(const n of[Tme,kme])for(const r of e.matchAll(n)){const i=r[0]??"",s=r.index??-1;if(s<0)continue;const o=s+i.length;if(t.some(d=>s<d.end&&o>d.start))continue;const l=oT(i),u=_c(l);!u||!C6(l)||t.push({kind:u,path:l,start:s,end:o})}return t.sort((n,r)=>n.start-r.start)}function Ame(e){const t=new Set,n=[];for(const{path:r}of k6(e))t.has(r)||(t.add(r),n.push(r));return n}var Qc=function(e,t){return Number(e.toFixed(t))},Nme=function(e,t){return t},cr=function(e,t,n){n&&typeof n=="function"&&n(e,t)},Mme=function(e){return-Math.cos(e*Math.PI)/2+.5},Pme=function(e){return e},Ime=function(e){return e*e},Ome=function(e){return e*(2-e)},Lme=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},Dme=function(e){return e*e*e},Bme=function(e){return--e*e*e+1},zme=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},jme=function(e){return e*e*e*e},Fme=function(e){return 1- --e*e*e*e},Hme=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},$me=function(e){return e*e*e*e*e},Ume=function(e){return 1+--e*e*e*e*e},Wme=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},T6={easeOut:Mme,linear:Pme,easeInQuad:Ime,easeOutQuad:Ome,easeInOutQuad:Lme,easeInCubic:Dme,easeOutCubic:Bme,easeInOutCubic:zme,easeInQuart:jme,easeOutQuart:Fme,easeInOutQuart:Hme,easeInQuint:$me,easeOutQuint:Ume,easeInOutQuint:Wme},R6=function(e){typeof e=="number"&&cancelAnimationFrame(e)},Po=function(e){e.mounted&&(R6(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function A6(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;Po(e),e.animation=function(){if(!e.mounted)return R6(e.animation);var o=new Date().getTime()-i,l=o/n,u=T6[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function qme(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function wc(e,t,n,r){var i=qme(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,h=t.positionX-u,v=t.positionY-d;n===0?s(t.scale,t.positionX,t.positionY):A6(e,r,n,function(g){g!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+f*g,w=u+h*g,S=d+v*g;s(_,w,S)})}}function Yme(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 Vme=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,h=r-i-u,v=u;return{minPositionX:d,maxPositionX:f,minPositionY:h,maxPositionY:v,scaleWidthFactor:l,scaleHeightFactor:u}},aT=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=Yme(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,f=l.newContentWidth,h=l.newContentHeight,v=l.newDiffWidth,g=l.newDiffHeight,_=Vme(u,f,v,d,h,g,!!s),w=u>=f&&d>=h;o&&w&&!s&&(_.minPositionX=0,_.maxPositionX=0,_.minPositionY=0,_.maxPositionY=0);var S=e.setup,x=S.minPositionX,T=S.maxPositionX,k=S.minPositionY,A=S.maxPositionY;return x!=null&&(_.minPositionX=u*(1-t)+x*t),T!=null&&(_.maxPositionX=T*t),k!=null&&(_.minPositionY=d*(1-t)+k*t),A!=null&&(_.maxPositionY=A*t),_},nm=function(e,t,n,r){return r?e<t?Qc(t,2):e>n?Qc(n,2):Qc(e,2):Qc(e,2)},ff=function(e,t){var n=aT(e,t);return e.bounds=n,n};function Lm(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,f=n.maxPositionY,h=0,v=0;o&&(h=i,v=s);var g=nm(e,l-h,d+h,r),_=nm(t,u-v,f+v,r);return{x:g,y:_}}function l_(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 h=u-t*f,v=d-n*f,g=Lm(h,v,i,s,0,0,null);return g}var aO=1e-7;function Dm(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,aO),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,aO)}var lO=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=Bm(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},cO=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},Kme=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}},Gme=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 Xme(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,h=f.maxPositionX,v=f.minPositionX,g=f.maxPositionY,_=f.minPositionY,w=n>h||n<v,S=r>g||r<_,x=n>h?d.offsetWidth:e.setup.minPositionX||0,T=r>g?d.offsetHeight:e.setup.minPositionY||0,k=l_(e,x,T,i,e.bounds,l||u),A=k.x,I=k.y;return{scale:i,positionX:w?A:n,positionY:S?I:r}}}function N6(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,h=u.positionY;if(!(o===null||l===null||t===f&&n===h)){var v=Lm(t,n,l,s,r,i,o),g=v.x,_=v.y;e.setState(d,g,_)}}var Zme=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,h=n-r.y,v=o?u:f,g=l?d:h;return{x:v,y:g}},ic=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},Vl;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(Vl||(Vl={}));var Jme=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},Qme=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 ege(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 uO(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:nm(e,s,o,i)}function tge(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var D0=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 nge(e,t,n){var r,i,s=Jme(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,f=u.velocityAnimation,h=f.maxStrengthMouse,v=f.maxStrengthTouch,g=f.sensitivityTouch,_=f.sensitivityMouse,w=Date.now();if(o&&l&&d){var S=tge(d),x=(r={},r[Vl.TOUCH]=g,r[Vl.MOUSE]=_,r)[n],T=(i={},i[Vl.TOUCH]=v,i[Vl.MOUSE]=h,i)[n],k=t.x-o.x,A=t.y-o.y,I=D0(k/S,T,x),R=D0(A/S,T,x),M=w-l,z=k*k+A*A,Y=D0(Math.sqrt(z)/M,T,x);e.velocity={velocityX:I,velocityY:R,total:Y}}e.lastMousePosition=t,e.velocityTime=w}}function rge(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Qme(e);if(!(!s||!t||!n||!i)){var o=t.velocityX,l=t.velocityY,u=t.total,d=n.maxPositionX,f=n.minPositionX,h=n.maxPositionY,v=n.minPositionY,g=r.limitToBounds,_=r.autoAlignment,w=r.zoomAnimation,S=r.panning,x=S.lockAxisY,T=S.lockAxisX,k=w.animationType,A=_.sizeX,I=_.sizeY,R=_.velocityAlignmentTime,M=R,z=ege(e,u),Y=Math.max(z,M),W=ic(e,A),G=ic(e,I),O=W*i.offsetWidth/100,N=G*i.offsetHeight/100,L=d+O,D=f-O,P=h+N,B=v-N,F=e.state,U=new Date().getTime();A6(e,k,Y,function(j){var V=e.state,X=V.scale,H=V.positionX,Q=V.positionY,ne=new Date().getTime()-U,te=ne/M,Z=T6[_.animationType],ce=1-Z(Math.min(1,te)),ie=1-j,me=H+o*ie,ge=Q+l*ie,ve=uO(me,F.positionX,H,T,g,f,d,D,L,ce),Te=uO(ge,F.positionY,Q,x,g,v,h,B,P,ce);if(H!==me||Q!==ge){e.setState(X,ve,Te);var Xe=e.props.onPanning;Xe&&Xe(nr(e),{})}})}}function dO(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},Po(e),ff(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?Gme(e,t):Kme(e,t)}function M6(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,h=o||n<i||!l&&!u;if(!h){var v=Xme(e);v&&wc(e,v,d,f)}}function fO(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=Zme(e,t,n),f=d.x,h=d.y,v=ic(e,l),g=ic(e,u);nge(e,{x:f,y:h},r),N6(e,f,h,v,g)}}function ige(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,h=l-d.y;if(f*f+h*h<=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?rge(e):M6(e)}}function lT(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Dm(Qc(t,2),s,o,0,!1),d=ff(e,u),f=l_(e,n,r,u,d,l),h=f.x,v=f.y;return{scale:u,positionX:h,positionY:v}}function cT(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,h=d.animationTime,v=d.animationType,g=r>=o&&r<=l,_=f||g;if((r>=1||u)&&M6(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,S=n||i.offsetHeight/2,x=r<o?o:l,T=lT(e,x,w,S);T&&wc(e,T,h,v)}}var po=function(){return po=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},po.apply(this,arguments)};function hO(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 B0={scale:1,positionX:0,positionY:0},Zc={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"}},K1={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},P6=function(e){var t,n,r,i,s,o,l,u,d,f=Math.max((t=e.minScale)!==null&&t!==void 0?t:Zc.minScale,1e-7),h=(n=e.maxScale)!==null&&n!==void 0?n:Zc.maxScale,v=(r=e.initialScale)!==null&&r!==void 0?r:B0.scale,g=Math.min(Math.max(v,f),h),_=nm((i=e.initialPositionX)!==null&&i!==void 0?i:B0.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=nm((l=e.initialPositionY)!==null&&l!==void 0?l:B0.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}},pO=function(e){var t=po({},Zc);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Zc[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Zc[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=po(po({},Zc[r]),e[r]):u?t[r]=hO(hO([],Zc[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},I6=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 h=d?r*Math.exp(t*n):r+t*n,v=Dm(Qc(h,3),l,o,f,!1);return v};function O6(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,f=u.positionX,h=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-h)/d,T=I6(e,t,n),k=lT(e,T,S,x);if(!k)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,I=A.onZoomStart,R=A.onZoom,M=A.onZoomStop,z=new MouseEvent("mousemove",{bubbles:!0}),Y=nr(e);cr(Y,z,I),cr(Y,z,R),wc(e,k,g,i);var W=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;W&&W.setTimeout(function(){e.mounted&&cr(nr(e),z,M)},g)}function L6(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,f=o.centerOnInit,h=P6(e.props),v=e.state,g=v.scale,_=v.positionX,w=v.positionY;if(l){var S=h.positionX,x=h.positionY;if(f&&u){var T=uT(h.scale,l,u);S=T.positionX,x=T.positionY}var k=aT(e,h.scale),A=Lm(S,x,k,d,0,0,l),I={scale:h.scale,positionX:A.x,positionY:A.y};if(!(g===h.scale&&_===h.positionX&&w===h.positionY)){r==null||r();var R=e.props,M=R.onZoomStart,z=R.onZoom,Y=R.onZoomStop,W=new MouseEvent("mousemove",{bubbles:!0}),G=nr(e);cr(G,W,M),cr(G,W,z),wc(e,I,t,n);var O=(s=(i=l.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&s!==void 0?s:typeof window<"u"?window:null;O&&O.setTimeout(function(){e.mounted&&cr(nr(e),W,Y)},t)}}}function sge(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 oge(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,h=u.maxScale;if(!s||!o)return l;var v=s.getBoundingClientRect(),g=t.getBoundingClientRect(),_=sge(t,s,o,l),w=_.x,S=_.y,x=g.width/l.scale,T=g.height/l.scale,k=s.offsetWidth/x,A=s.offsetHeight/T,I=Dm(n||Math.min(k,A),f,h,0,!1),R=(v.width-x*I)/2,M=(v.height-T*I)/2,z=(v.left-w)*I+R+r,Y=(v.top-S)*I+M+i,W=aT(e,I),G=Lm(z,Y,W,d,0,0,s),O=G.x,N=G.y;return{positionX:O,positionY:N,scale:I}}var age=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),O6(e,1,t,n,r)}},lge=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),O6(e,-1,t,n,r)}},cge=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,h=e.contentComponent,v=e.setup.disabled;if(!(v||!f||!h)){var g={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};wc(e,g,i,s)}}},uge=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),L6(e,t,n)}},dge=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=uT(t||i.scale,s,o);wc(e,l,n,r)}}},fge=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),Po(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=oge(e,u,n,s,o);wc(e,d,r,i)}}},Xy=function(e){return{instance:e,state:e.state,zoomIn:age(e),zoomOut:lge(e),setTransform:cge(e),resetTransform:uge(e),centerView:dge(e),zoomToElement:fge(e)}},G1=function(e){return{instance:e,state:e.state}},nr=function(e){var t={};return Object.assign(t,G1(e)),Object.assign(t,Xy(e)),t},z0=!1;function j0(){try{var e={get passive(){return z0=!0,!1}};return e}catch{return z0=!1,z0}}var Pv=".".concat(K1.wrapperClass),Bm=function(e,t){return t.some(function(n){return e.matches("".concat(Pv," ").concat(n,", ").concat(Pv," .").concat(n,", ").concat(Pv," ").concat(n," *, ").concat(Pv," .").concat(n," *"))})},rm=function(e){e&&clearTimeout(e)},hge=function(e){return Number.parseFloat(e.toFixed(8))},D6=function(e,t,n){var r=hge(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},uT=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 pge(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function mge(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var B6=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 h=Bm(d,o);if(h)return!1;var v=e.isPressingKeys(e.setup.wheel.activationKeys);return!!v},gge=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=B6(e,t);if(l)return!1;var u=t.target,d=Bm(u,o);if(d)return!1;var f=e.isPressingKeys(s);return!!f},vge=function(e){return e?e.deltaY<0?1:-1:0};function yge(e,t){var n=vge(e),r=Nme(t,n);return r}function z6(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 bge=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,h=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=Dm(_,d,u,v,w&&!h);return S},j6=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},_ge=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=Bm(o,i);return!u},wge=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},xge=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}},F6=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))},Sge=5,Ege=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,h=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/Sge),S=n+w,x=S===1/0?0:Qc(S,10);return Dm(x,o,s,f,!h&&!u)},H6=160,$6=100,Cge=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(Po(e),cr(nr(e),t,r),cr(nr(e),t,i))},kge=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,h=o.zoomAnimation,v=o.wheel,g=o.disablePadding,_=o.smooth,w=h.size,S=h.disabled,x=v.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var T=yge(t,null),k=_?x*Math.abs(t.deltaY):x,A=bge(e,T,k,!t.ctrlKey);if(u!==A){var I=ff(e,A),R=z6(t,s,u),M=S||w===0||f||g,z=d&&M,Y=l_(e,R.x,R.y,A,I,z),W=Y.x,G=Y.y;e.previousWheelEvent=t,e.setState(A,W,G),cr(nr(e),t,r),cr(nr(e),t,i)}},Tge=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;rm(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(cT(e,t.x,t.y),e.wheelAnimationTimer=null)},$6);var s=j6(e,t);s&&(rm(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,cr(nr(e),t,r),cr(nr(e),t,i))},H6))},Rge=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(Po(e),cr(nr(e),t,r),cr(nr(e),t,i))},Age=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;rm(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(cT(e,t.x,t.y),e.wheelAnimationTimer=null)},$6);var s=j6(e,t);s&&(rm(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,cr(nr(e),t,r),cr(nr(e),t,i))},H6))},U6=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}},Nge=function(e,t){var n=F6(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=U6(t),Po(e)},Mge=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,h=l.autoAlignment,v=l.pinch,g=l.panning,_=f.disabled,w=f.size,S=v.allowPanning;if(!(r===null||!n)){var x=xge(t,o,n);if(!(!Number.isFinite(x.x)||!Number.isFinite(x.y))){var T=F6(t),k=Ege(e,T),A=U6(t),I=o/k,R=(A.x-((s==null?void 0:s.x)||0))*I,M=(A.y-((s==null?void 0:s.y)||0))*I;if(!(k===o&&R===0&&M===0)){e.pinchPreviousCenter=A;var z=ff(e,k),Y=_||w===0||d,W=u&&Y,G=l_(e,x.x,x.y,k,z,W),O=G.x,N=G.y;if(e.pinchMidpoint=x,e.lastDistance=T,g.disabled||!S)e.setState(k,O,N);else{var L=h.sizeX,D=h.sizeY,P=ic(e,L,k),B=ic(e,D,k),F=O+R,U=N+M,j=Lm(F,U,z,u,P,B,i),V=j.x,X=j.y;e.setState(k,V,X)}}}}},Pge=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,cT(e,t==null?void 0:t.x,t==null?void 0:t.y)},W6=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;rm(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,cr(nr(e),t,n)},r)},Ige=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;cr(nr(e),t,r),L6(e,o,l,function(){return cr(nr(e),t,i)}),W6(e,t)};function Oge(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function Lge(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,h=f.disabled,v=f.mode,g=f.step,_=f.animationTime,w=f.animationType;if(!h&&!r){if(v==="reset")return Ige(e,t);if(!s)return console.error("No ContentComponent found");var S=Oge(v,e.state.scale),x=I6(e,S,g);if(o!==x){cr(nr(e),t,u);var T=z6(t,s,o),k=lT(e,x,T.x,T.y);if(!k)return console.error("Error during zoom event. New transformation state was not calculated.");cr(nr(e),t,d),wc(e,k,_,w),W6(e,t)}}}var Dge=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 h=Bm(u,l);return!h},Bge=(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&&ff(n,n.state.scale),n.setup=pO(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=j0(),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=j0(),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),Po(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=j0();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(nr(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(nr(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=B6(n,r);s&&(Cge(n,r),kge(n,r),Tge(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=gge(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,f=d.positionX,h=d.positionY,v=f-r.deltaX,g=h-r.deltaY,_=o?f:v,w=l?h:g,S=n.setup.autoAlignment,x=S.sizeX,T=S.sizeY,k=ic(n,x),A=ic(n,T);_===f&&w===h||(Rge(n,r),N6(n,_,w,k,A),cr(nr(n),r,i),Age(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=lO(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(),Po(n),dO(n,r),cr(nr(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=cO(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),fO(n,r.clientX,r.clientY,Vl.MOUSE),cr(nr(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(ige(n,i),cr(nr(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=_ge(n,r);o&&(Nge(n,r),Po(n),cr(nr(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=wge(n);o&&(r.preventDefault(),r.stopPropagation(),Mge(n,r),cr(nr(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(Pge(n),cr(nr(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,Po(n);var f=r.touches,h=f.length===1,v=f.length===2,g=lO(n,r);if(h){if(!g)return;Po(n),dO(n,r),cr(nr(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=cO(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];fO(n,l.clientX,l.clientY,Vl.TOUCH),cr(nr(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=Dge(n,r);s&&Lge(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=uT(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):D6(r,i,s)},this.getContext=function(){return nr(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:nr(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=nr(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),cr(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,ff(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=nr(n);cr(s,void 0,n.props.onInit),pge(n.props.ref,s)},this.props=t,this.setup=pO(this.props),this.state=P6(this.props)}return e})(),zm=gt.createContext(null),zge=function(e,t){return typeof e=="function"?e(t):e},jge=gt.forwardRef(function(e,t){var n=b.useRef(new Bge(e)).current,r=zge(e.children,Xy(n));return b.useImperativeHandle(t,function(){return Xy(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),m.jsx(zm.Provider,po({value:n},{children:r}))});gt.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(zm);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",po({},e,{ref:mge([n,t])}))});function Fge(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 Hge=`.transform-component-module_wrapper__SPB86 {
608
608
  position: relative;
@@ -741,7 +741,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
741
741
  `:"\r":e.key==="Backspace"?"":e.key==="Tab"?e.shiftKey?"\x1B[Z":" ":e.key==="Escape"?"\x1B":e.key==="ArrowUp"?kp("\x1B[A",t):e.key==="ArrowDown"?kp("\x1B[B",t):e.key==="ArrowRight"?kp("\x1B[C",t):e.key==="ArrowLeft"?kp("\x1B[D",t):e.key==="Delete"?"\x1B[3~":e.key==="Home"?"\x1B[H":e.key==="End"?"\x1B[F":null}function wEe(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,selectionHandleLayerRef:o,mobileControlsHeight:l}=e,u=h1e(),d=u.markDisconnected,f=v1e(),h=lEe(),{openMediaPreview:v}=u_(),g=b.useRef(null),_=b.useRef([]),w=b.useRef(null),S=b.useRef(null),x=b.useRef(!1),T=b.useRef([]),k=b.useRef(null),A=b.useRef(null),I=b.useRef(n),R=b.useRef(n),M=b.useRef(!1),z=b.useRef(!1),Y=b.useRef(!1),W=b.useRef(!1),G=b.useRef(null),O=b.useRef(null),N=b.useRef(null),L=b.useRef(null),D=b.useRef({keyboardOpen:!1,controlsVisible:!1}),P=b.useRef(!1),B=b.useRef(!1),F=b.useRef(!1),U=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[j,V]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[X,H]=b.useState(!1),[Q,ne]=b.useState(!1),[te,Z]=b.useState({resultIndex:-1,resultCount:0}),ce=Re(De=>De.connected),ie=Re(De=>De.proxyOnline),me=Re(De=>De.ptyFontSize),ge=Re(De=>De.inputModePreference),ve=Re(De=>De.adaptiveInputModality),Te=Re(De=>De.setAdaptiveInputModality),Xe=ve==="hardware",wt=bo("(pointer: coarse), (hover: none)"),{bottomOffset:et,layoutBottomInset:ft}=LT(),Ne=ge==="hardware",Ue=gEe({touchEditingSurface:wt,inputModePreference:ge,detectedPhysicalKeyboard:Xe,softKeyboardDetected:et>0}),be=wt&&!Ue,rt=Ue?0:et,$e=rt>0,Ae=Ue?0:ft,[Ze,Tt]=b.useState(()=>ce&&ie);P.current=Ue,I.current=n,M.current=u.ready,z.current=ce&&ie;const ye=b.useCallback(()=>I.current&&M.current&&z.current,[]),Ke=b.useCallback(De=>{const qe=Ut.getState().sessions.find(Be=>Be.sessionId===t);if((qe==null?void 0:qe.mode)!=="pty"||qe.ptyOwner!=="proxy-hosted")return;const dt=g.current,bt=s.current,Kt=Bt;if(!ye()||!dt||!bt||!r||!Kt){He.error("终端尚未就绪");return}const fn=_.current.at(-1)??dt,Pe=De==="fit"?jxe(r,bt,dt):zxe(fn,De);if(!Pe){He.error("无法获取终端显示区域的尺寸");return}Pe.cols===fn.cols&&Pe.rows===fn.rows||(Kt.sendControl({type:"terminal_resize_request",sessionId:t,...Pe})?(_.current.push(Pe),Ut.getState().setPtyGeometry(t,Pe)):He.error("终端尺寸调整失败,请检查连接"))},[ye,r,t,s]);b.useEffect(()=>{(!n||!u.ready||!ce||!ie)&&(_.current=[]);const De=_.current.at(-1)??g.current;Ut.getState().setPtyGeometry(t,u.ready&&ce&&ie&&De?{cols:De.cols,rows:De.rows}:null)},[n,u.ready,ce,ie,t]),b.useEffect(()=>{ce&&ie&&Tt(!0)},[ce,ie]),b.useEffect(()=>{rt>0&&H(!0)},[rt]);const _e=g1e({containerEl:r,xtermHostRef:s,terminalRef:g}),{ptyInputFocused:Je,suppressPtyFocus:pt,focusPtyInput:St,handleFocusCapture:Dt,handleBlurCapture:yn}=_e,on=pEe({softKeyboardEditingSurface:be,ptyInputFocused:Je,keyboardOpen:$e});U.current={keyboardOffset:rt,hasSeenSoftKeyboard:X,showMobilePtyControls:on,touchEditingSurface:wt,ptyInputFocused:Je,containerPaddingBottom:U.current.containerPaddingBottom,mobileControlsBottomInset:Ae};const tn=f.clearNewFramesWhileAway;O.current||(O.current=oD(()=>{var De;(De=A.current)==null||De.relayout()}));const Ct=b.useCallback(()=>{F.current=!1},[]);N.current||(N.current=oD(()=>{var qe,dt;const De=L.current??{reason:"rawInput",force:!1};L.current=null,De.force&&Ct(),(qe=A.current)==null||qe.traceRawInputFollowFire(),(dt=A.current)==null||dt.scrollToBottom(De.reason,De.force?{force:!0}:void 0),tn()}));const gn=b.useCallback(()=>{if(F.current)return;const De=A.current;De&&De.preparePageResumeRestore(),F.current=!0},[]),Wt=b.useCallback(()=>{if(!F.current||document.visibilityState==="hidden"||!I.current||!M.current)return;const De=A.current;De&&(De.restorePageResume(),tn(),F.current=!1)},[tn]);b.useEffect(()=>()=>{var De,qe;(De=O.current)==null||De.dispose(),(qe=N.current)==null||qe.dispose(),O.current=null,N.current=null},[]),b.useEffect(()=>{const De=()=>{gn()},qe=()=>{if(document.visibilityState==="hidden"){De();return}Wt()};return document.addEventListener("visibilitychange",qe),window.addEventListener("pagehide",De),window.addEventListener("pageshow",Wt),window.addEventListener("focus",Wt),()=>{document.removeEventListener("visibilitychange",qe),window.removeEventListener("pagehide",De),window.removeEventListener("pageshow",Wt),window.removeEventListener("focus",Wt)}},[gn,Wt]),b.useLayoutEffect(()=>{const De=R.current;if(R.current=n,!n){De&&gn();return}(!De||F.current)&&u.ready&&Wt()},[n,u.ready,gn,Wt]);const en=b.useCallback((De="rawInput",qe)=>{var Kt,fn;const dt=L.current,bt=(dt==null?void 0:dt.force)===!0||(qe==null?void 0:qe.force)===!0;L.current={reason:(qe==null?void 0:qe.force)===!0||!dt?De:dt.reason,force:bt},(Kt=A.current)==null||Kt.traceRawInputFollowScheduled(De),(fn=N.current)==null||fn.schedule()},[]),wn=b.useCallback((De,qe)=>{var dt,bt;!De||QL(De)||((dt=A.current)==null||dt.resumeHorizontalCursorFollow(qe),!(!De.includes("\r")&&!De.includes(`
742
742
  `))&&((bt=A.current)==null||bt.resetHorizontalScroll(qe,{holdUntilCursorVisible:!0})))},[]),rr=b.useCallback(()=>P.current?"submit":"linefeed",[]),or=b.useCallback(()=>P.current,[]);b.useEffect(()=>{if(!n||ge!=="auto"||!wt)return;const De=dt=>{const bt=s.current,Kt=r;return dt instanceof Node?bt!=null&&bt.contains(dt)||dt===document.body||dt===document.documentElement?!0:Kt!=null&&Kt.contains(dt)?dt instanceof HTMLElement?dt.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:dt===window},qe=dt=>{var fn,Pe;if(!vEe({active:I.current,touchEditingSurface:wt,key:dt.key,code:dt.code,altKey:dt.altKey,ctrlKey:dt.ctrlKey,metaKey:dt.metaKey,isComposing:dt.isComposing,targetAcceptsPtyInput:De(dt.target)}))return;Te("hardware"),P.current=!0,(fn=g.current)==null||fn.focus();const bt=s.current;if(dt.target instanceof Node&&(bt!=null&&bt.contains(dt.target)))return;const Kt=_Ee(dt,(Pe=g.current)==null?void 0:Pe.modes);!Kt||!ye()||(dt.preventDefault(),dt.stopPropagation(),Io(t,Kt),en("physicalKeyboard"),wn(Kt,"physicalKeyboardEnter"))};return window.addEventListener("keydown",qe,!0),()=>window.removeEventListener("keydown",qe,!0)},[n,ye,r,ge,wn,en,t,Te,wt,s]);const En=b.useCallback(De=>{const qe=Bt;if(!qe){He.error("请先连接开发机");return}const dt=He.loading(`下载 ${De} ...`);c_({relay:qe,sessionId:t,path:De}).then(bt=>{bt.ok?He.success(`已开始下载 ${De}`,{id:dt}):He.error(bt.error,{id:dt})}).catch(bt=>{He.error(bt instanceof Error?bt.message:String(bt),{id:dt})})},[t]),q=b.useCallback(De=>{const qe=g.current;return qe?WSe(qe,T.current,De):!1},[]),se=b.useCallback(De=>{const qe=g.current;return qe?USe(qe,T.current,De):!1},[]),oe=aEe({terminalRef:g,xtermHostRef:s,selectionHandleLayerRef:o,scrollControllerRef:A,containerEl:r,keyboardOffset:rt,ptyFontSize:me,suppressPtyFocus:pt,focusPtyInput:St,onTap:q,isTapCandidate:se,onDownloadPath:En,onPreviewPath:v}),ke=oe.clearManagedPtySelection,fe=oe.clearPtySelection;B.current=oe.hasPtySelection();const K=b.useCallback(()=>{const De=g.current,qe=S.current,dt=x.current&&De?XL(De.getSelectionPosition(),De.cols):null;qe==null||qe.render(dt)},[]),re=fEe({sessionId:t,terminalRef:g,onAfterPaste:()=>en("paste")}),le=b.useCallback(De=>{if(!ye()){De.preventDefault();return}fe(),re(De)},[ye,fe,re]),[he,J]=b.useState(!1),ae=b.useCallback(De=>{De.dataTransfer.types.includes("Files")&&(De.preventDefault(),J(qe=>qe||!0))},[]),ue=b.useCallback(De=>{De.currentTarget.contains(De.relatedTarget)||J(!1)},[]),Ie=b.useCallback(async De=>{var Kt,fn;const qe=(Kt=De.dataTransfer.files)==null?void 0:Kt[0];if(!qe||(De.preventDefault(),J(!1),!ye()))return;const dt=Bt;if(!dt){He.error("请先连接开发机");return}const bt=await cm({relay:dt,sessionId:t,file:qe});bt&&(Io(t,`@${bt} `),(fn=A.current)==null||fn.resumeHorizontalCursorFollow("dropUpload"),en("dropUpload"))},[ye,en,t]),Ge=b.useCallback(De=>{var dt;if(!ye()){De.preventDefault();return}const qe=De.target;qe instanceof Element&&qe.closest(".xterm")||(De.preventDefault(),(dt=g.current)==null||dt.focus())},[ye]);b.useEffect(()=>{if(!Ze)return;const De=s.current,qe=Wa,dt=Bt,bt=r,Kt=i.current;if(!De||!qe||!dt||!bt||!Kt)return;let fn=null,Pe=null,Be=null,tt=null,at=null,Ht=null,an=null,zt=null,nn=null;const Zr=uSe({host:De,sessionId:t,ws:qe,relay:dt,scheduleAutoFocus:be?()=>{}:Hn=>{requestAnimationFrame(()=>{dD(s.current)&&Hn()})},createTerminal:async Hn=>{const Xn=await b$(Hn,{fontSize:Re.getState().ptyFontSize});return nn=Xn.serializeAddon,Xn},attachRawInput:(Hn,Xn,wi)=>v0e(Hn,Xn,{...wi,getPlainEnterBehavior:rr,isPhysicalKeyboardMode:or,physicalKeyboardMode:Ne}),isInputEnabled:ye,canFocus:ye,onTerminalReady:Hn=>{fe();const Xn=Hn;g.current=Xn,_.current=[],an=Xn.onResize(({cols:Mt,rows:Lt})=>{const vt=_.current,Pn=vt.findIndex($n=>$n.cols===Mt&&$n.rows===Lt);_.current=Pn>=0?vt.slice(Pn+1):[],M.current&&z.current&&Ut.getState().setPtyGeometry(t,_.current.at(-1)??{cols:Mt,rows:Lt})});const wi=new mye({highlightLimit:1e3});Xn.loadAddon(wi),w.current=wi,at=wi.onDidChangeResults(Mt=>{Z(Mt),K()}),ne(!0);const So=SSe(Xn,v);fn=So.dispose;const de=DSe(Xn,En);Pe=de.dispose,T.current=[So.provider,de.provider],a1e(()=>g.current);const je=Fxe(Xn),Ye=Kxe(De,{serializeRangeAsHtml:(Mt,Lt)=>(nn==null?void 0:nn.serializeAsHTML({range:{startLine:Mt,endLine:Math.min(Lt,Math.max(0,Xn.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??"",getSerializedCell:(Mt,Lt)=>{var Pn;const vt=(Pn=Xn.buffer.active.getLine(Mt))==null?void 0:Pn.getCell(Lt);return vt?{text:vt.getWidth()===0?"":vt.getChars()||" ",isDim:!!vt.isDim(),isRenderedFgRGB:vt.isInverse()?vt.isBgRGB():vt.isFgRGB()}:null},getSelectionLine:Mt=>Xn.buffer.active.getLine(Mt)??null,getBufferRowIdentityOffset:je.getOffset});tt=()=>{Ye.dispose(),je.dispose()};const lt=F.current;lt&&(W.current=!1);const yt=tSe({container:bt,spacer:Kt,host:De,term:Xn,hasNewFrame:()=>Y.current,consumeNewFrame:()=>{Y.current=!1},hasNewFramesWhileAway:()=>f.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:f.setHasNewFramesWhileAway,onAtBottomChange:f.handleAtBottomChange,onScrollStateChange:V,initialUserHasVerticalScrollIntent:lt?!1:W.current,onUserVerticalScrollIntentChange:Mt=>{W.current=Mt},onTouchReviewStart:pt,onHistoryProjectionChange:Mt=>{const Lt=Ye.render(Mt);return Lt&&K(),Lt},getBufferRowIdentityOffset:je.getOffset});A.current=yt,Be=yt.dispose,zt=C$({terminal:Xn,container:bt,getLine:Mt=>lb(De,Mt)??Xn.buffer.active.getLine(Mt)??null,resolveRange:()=>x.current?XL(Xn.getSelectionPosition(),Xn.cols):null,projectionOnly:!0,overlaySlot:"pty-search-selection-overlay",segmentSlot:"pty-search-selection-segment",selectionBackground:eC.activeMatchBackground,borderColor:eC.activeMatchBorder,opacity:"0.62"}),S.current=zt,Ht=Xn.onSelectionChange(K),K(),lt&&(yt.restorePageResume(),tn(),F.current=!1),c1e(()=>{var Bi;const Mt=Sr=>{if(!Sr)return null;const fi=Sr.getBoundingClientRect();return{top:fi.top,bottom:fi.bottom,height:fi.height,left:fi.left,right:fi.right,width:fi.width}},Lt=document.querySelector('[data-slot="pty-mobile-controls"]'),vt=document.querySelector("[data-keyboard-offset]"),Pn=window.visualViewport,$n=Mt(Lt),zn=(Pn==null?void 0:Pn.height)??window.innerHeight;return{...d1e(yt.getDebugProbe,{container:bt,spacer:Kt,host:De,term:Xn}),mobileLayout:{...U.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:Pn?{height:Pn.height,width:Pn.width,offsetTop:Pn.offsetTop,pageTop:Pn.pageTop,scale:Pn.scale}:null,chatRoot:{dataKeyboardOffset:(vt==null?void 0:vt.getAttribute("data-keyboard-offset"))??null,rect:Mt(vt)},ptyViewRect:Mt(bt.parentElement),containerRect:Mt(bt),controlsRect:$n,controlsOverflowBelowVisualViewport:$n===null?null:$n.bottom-zn,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(Bi=document.activeElement.closest("[data-slot]"))==null?void 0:Bi.getAttribute("data-slot")}:null},frame:{lastWriteAt:G.current,pendingNewFrame:Y.current}}})},onFramePending:()=>{var Hn;Y.current=!0,(Hn=A.current)==null||Hn.markHorizontalLiveFramePending(),W.current&&!f.hasNewFramesWhileAwayRef.current&&f.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Hn;G.current=performance.now(),(Hn=O.current)==null||Hn.schedule()},onRawInput:Hn=>{QL(Hn)||(en("rawInput",{force:!0}),wn(Hn,"rawInputEnter"))},onError:Hn=>{const Xn=Hn instanceof Error?Hn.message:String(Hn);He.error(`终端初始化失败:${Xn}`)},connectTransportInitially:ce&&ie,...u.transport,onReady:()=>{_.current=[];const Hn=g.current;Hn&&Ut.getState().setPtyGeometry(t,{cols:Hn.cols,rows:Hn.rows}),u.transport.onReady()}});return k.current=Zr,()=>{x.current=!1,Ht==null||Ht.dispose(),an==null||an.dispose(),_.current=[],Ut.getState().setPtyGeometry(t,null),zt==null||zt.dispose(),S.current===zt&&(S.current=null),fe(),Be==null||Be(),tt==null||tt(),at==null||at.dispose(),u1e(),fn==null||fn(),Pe==null||Pe(),T.current=[],l1e(),w.current=null,ne(!1),Z({resultIndex:-1,resultCount:0}),Zr.dispose(),g.current=null,A.current=null,k.current=null}},[t,Ze,r,i,s,u.transport,f.handleAtBottomChange,f.hasNewFramesWhileAwayRef,f.setHasNewFramesWhileAway,ye,Ne,rr,or,En,v,pt,en,wn,fe,K]),b.useEffect(()=>{if(!Ze)return;const De=k.current;if(De){if(!ce||!ie){d(),De.setTransportActive(!1);return}return fSe(t,n?"active":"background",()=>{var qe;(qe=k.current)==null||qe.setTransportActive(!0)})}},[n,ce,d,ie,t,Ze]),b.useEffect(()=>{const De=g.current,qe=A.current;!De||!qe||Dxe(De,me,qe.relayout)},[me]),b.useEffect(()=>{if(!n||!u.ready||be)return;const De=requestAnimationFrame(()=>{var qe;dD(s.current)&&((qe=g.current)==null||qe.focus())});return()=>cancelAnimationFrame(De)},[n,u.ready,be,s]);const mt=b.useCallback((De="viewExternal",qe)=>{var dt;qe!=null&&qe.force&&Ct(),(dt=A.current)==null||dt.scrollToBottom(De,qe)},[Ct]),ut=b.useCallback(De=>{var qe;(qe=A.current)==null||qe.scrollToRatio(De)},[]),It=b.useCallback(De=>{var qe;(qe=A.current)==null||qe.scrollToXRatio(De)},[]),Rt=b.useCallback(De=>{var Pe;const qe=g.current,dt=qe==null?void 0:qe.getSelectionPosition();if(!qe||!dt)return;const bt=dt.start.y;if(bt>=De&&bt<De+qe.rows)return;const Kt=Math.max(0,qe.buffer.active.length-qe.rows);if(Kt===0)return;const fn=Math.max(0,Math.min(Kt,bt-Math.floor(qe.rows/2)));(Pe=A.current)==null||Pe.scrollToRatio(fn/Kt)},[]),xt=b.useCallback((De,qe=!1)=>{const dt=g.current,bt=w.current;if(!dt||!bt||!De)return De||(x.current=!1,bt==null||bt.clearDecorations(),dt==null||dt.clearSelection(),ke(),K(),Z({resultIndex:-1,resultCount:0})),!1;ke(),x.current=!0;const Kt=dt.buffer.active.viewportY,fn=bt.findNext(De,{..._D,incremental:qe});return fn&&Rt(Kt),K(),fn},[ke,K,Rt]),Qt=b.useCallback(De=>{const qe=g.current,dt=w.current;if(!qe||!dt||!De)return!1;ke(),x.current=!0;const bt=qe.buffer.active.viewportY,Kt=dt.findPrevious(De,_D);return Kt&&Rt(bt),K(),Kt},[ke,K,Rt]),Nt=b.useCallback(()=>{var De,qe;x.current=!1,(De=w.current)==null||De.clearDecorations(),(qe=g.current)==null||qe.clearSelection(),ke(),K(),Z({resultIndex:-1,resultCount:0})},[ke,K]),pn=b.useCallback(De=>{var dt,bt;if(!ye())return;const qe=kp(De,(dt=g.current)==null?void 0:dt.modes);Io(t,qe),en("mobileControl",{force:!0}),wn(De,"mobileControlEnter"),(bt=g.current)==null||bt.focus()},[ye,wn,en,t]),$t=b.useCallback(()=>{var qe,dt,bt;if(!ye())return;const De=(dt=(qe=navigator.clipboard)==null?void 0:qe.readText)==null?void 0:dt.bind(navigator.clipboard);if(!window.isSecureContext||!De){He.error("无法读取剪贴板"),(bt=g.current)==null||bt.focus();return}De().then(Kt=>{if(!Kt)return;const fn=g.current;if(fn){fn.paste(Kt);return}Io(t,Kt),en("paste"),wn(Kt,"pasteEnter")}).catch(Kt=>{const fn=Kt instanceof Error&&Kt.message?Kt.message:"无法读取剪贴板";He.error(fn)}).finally(()=>{var Kt;return(Kt=g.current)==null?void 0:Kt.focus()})},[ye,wn,en,t]),Mn=bEe({showMobilePtyControls:on,horizontalScrollable:j.horizontalScrollable,mobileControlsHeight:l});U.current.containerPaddingBottom=Mn,b.useEffect(()=>{var dt,bt;B.current?(dt=A.current)==null||dt.relayout():(bt=O.current)==null||bt.schedule();const De=D.current,qe=mEe({controlsVisible:on,keyboardOpen:$e,previous:De});D.current={keyboardOpen:$e,controlsVisible:on},on&&(B.current?tn():qe&&en("keyboardOffset",{force:!0}))},[rt,$e,on,Mn,tn,en]);const bn=b.useMemo(()=>({onFocusCapture:Dt,onBlurCapture:yn}),[Dt,yn]);return{scrollState:j,isAtBottom:f.isAtBottom,hasNewFramesWhileAway:f.hasNewFramesWhileAway,ptyInputFocused:Je,showMobilePtyControls:on,touchEditingSurface:wt,keyboardOffset:rt,physicalKeyboardMode:Ue,softKeyboardEditingSurface:be,mobileControlsBottomInset:Ae,connectionReady:u.ready,connectionOverlay:u.overlay,containerPaddingBottom:Mn,traceEnabled:h,findReady:Q,findResultIndex:te.resultIndex,findResultCount:te.resultCount,findNext:xt,findPrevious:Qt,clearFind:Nt,resizeTerminal:Ke,scrollToBottom:mt,scrollToRatio:ut,scrollToXRatio:It,clearNewFramesWhileAway:tn,sendMobileInput:pn,pasteMobileClipboard:$t,handleTerminalContainerMouseDown:Ge,handlePasteCapture:le,pointerHandlers:oe.pointerHandlers,focusHandlers:bn,ptySelectionToolbar:oe.ptySelectionToolbar,ptySelectionHandles:oe.ptySelectionHandles,ptySelectionPathAction:oe.ptySelectionPathAction,ptySelectionHandleMetrics:oe.ptySelectionHandleMetrics,copyPtySelection:oe.copyPtySelection,openPtySelectionPathAction:oe.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:oe.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:oe.handlePtySelectionHandleTouchStart,isPtyDragOver:he,handlePtyDragOver:ae,handlePtyDragLeave:ue,handlePtyDrop:Ie}}function xEe({sessionId:e,sessionKind:t,provider:n,active:r=!0,findRequest:i,resizeRequest:s}){const o=Ut(B=>{const F=B.sessions.find(U=>U.sessionId===e);return(F==null?void 0:F.kind)==="terminal"?F.shellFamily:void 0}),[l,u]=b.useState(null),[d,f]=b.useState(0),[h,v]=b.useState(!1),[g,_]=b.useState(""),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),T=wEe({sessionId:e,active:r,containerEl:l,spacerRef:w,xtermHostRef:S,selectionHandleLayerRef:x,mobileControlsHeight:d}),k=T.ptySelectionHandleMetrics,{clearFind:A,findNext:I,findPrevious:R,findReady:M,findResultCount:z,findResultIndex:Y}=T,W=b.useRef(s==null?void 0:s.requestId),{resizeTerminal:G}=T;b.useEffect(()=>{s===void 0||s.requestId===W.current||(W.current=s.requestId,r&&G(s.action))},[r,s,G]);const O=b.useCallback(()=>{R(g)},[R,g]),N=b.useCallback(()=>{I(g)},[I,g]),L=b.useCallback(()=>v(!0),[]),D=b.useCallback(()=>{v(!1),A()},[A]),P=eH({enabled:r,open:h,openRequest:i,onOpen:L,onClose:D,onPrevious:O,onNext:N});return b.useEffect(()=>{!h||!M||(g?I(g,!0):A())},[A,I,h,g,M]),m.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":T.connectionReady?"true":"false","aria-busy":!T.connectionReady,children:[h?m.jsx(Z1,{query:g,resultIndex:Y,resultCount:z,focusRequest:P.focusRequest,loading:!!g&&!M,onQueryChange:_,onPrevious:O,onNext:N,onClose:P.closeFind}):null,m.jsxs("div",{ref:u,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) + ${T.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:T.handleTerminalContainerMouseDown,onPointerDownCapture:B=>{T.pointerHandlers.onPointerDownCapture(B)},onPointerMoveCapture:T.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:T.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:T.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:T.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:T.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:T.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:T.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:T.pointerHandlers.onContextMenuCapture,onPasteCapture:T.handlePasteCapture,onDragOver:T.handlePtyDragOver,onDragLeave:T.handlePtyDragLeave,onDrop:T.handlePtyDrop,onFocusCapture:T.focusHandlers.onFocusCapture,onBlurCapture:T.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":T.isPtyDragOver?"true":void 0,children:[m.jsx("div",{ref:w,style:{position:"relative",overflowAnchor:"none"},"data-slot":"pty-spacer",children:m.jsx("div",{ref:S,style:{position:"absolute",left:0,top:0,overflow:"hidden",overflowAnchor:"none",boxSizing:"border-box"},"data-slot":"pty-host"})}),m.jsx("div",{ref:x,"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(X6,{visible:!T.isAtBottom,hasNewMessages:T.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{T.scrollToBottom("backToBottomBtn",{force:!0}),T.clearNewFramesWhileAway()}}),T.showMobilePtyControls?m.jsx(Mve,{sessionKind:t,provider:n,shellFamily:o,bottomInset:T.mobileControlsBottomInset,onInput:T.sendMobileInput,onPaste:T.pasteMobileClipboard,onHeightChange:f}):null,T.ptySelectionHandles&&x.current?Eu.createPortal(m.jsxs(m.Fragment,{children:[m.jsx(xD,{kind:"anchor",metrics:k,"aria-label":"调整选区起点",onPointerDown:B=>T.handlePtySelectionHandlePointerDown("anchor",B),onTouchStart:B=>T.handlePtySelectionHandleTouchStart("anchor",B)}),m.jsx(xD,{kind:"focus",metrics:k,"aria-label":"调整选区终点",onPointerDown:B=>T.handlePtySelectionHandlePointerDown("focus",B),onTouchStart:B=>T.handlePtySelectionHandleTouchStart("focus",B)})]}),x.current):null,T.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:T.ptySelectionToolbar.left,top:T.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:B=>B.preventDefault(),onClick:T.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),T.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:B=>B.preventDefault(),onClick:T.openPtySelectionPathAction,"aria-label":T.ptySelectionPathAction.kind==="media-preview"?_c(T.ptySelectionPathAction.path)==="video"?"预览终端选区视频":"预览终端选区图片":"下载终端选区文件",children:T.ptySelectionPathAction.kind==="media-preview"?"预览":"下载"}):null]}):null,m.jsx(jve,{state:T.scrollState,scrollContainer:l,onScrollRatio:T.scrollToRatio}),m.jsx(Fve,{state:T.scrollState,onScrollRatio:T.scrollToXRatio}),m.jsx(mve,{...T.connectionOverlay}),m.jsx(vve,{ptyInputFocused:T.ptyInputFocused,touchEditingSurface:T.touchEditingSurface,softKeyboardEditingSurface:T.softKeyboardEditingSurface,physicalKeyboardMode:T.physicalKeyboardMode,keyboardOffset:T.keyboardOffset,showMobilePtyControls:T.showMobilePtyControls,mobileControlsBottomInset:T.mobileControlsBottomInset}),T.traceEnabled?m.jsx(SEe,{}):null]})}function xD({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,h=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:h,top:v,width:l,height:l,...g},"data-slot":"pty-selection-handle-dot"})]})}function SEe(){const[e,t]=b.useState(!1);async function n(){const r=hve();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 EEe=1024,CEe=720,Kv=.5,J$=b.createContext(null);function kEe({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Re(k=>k.selectedProxyId),u=Ut(k=>k.sessions),d=Ut(k=>k.sessionListLoaded),f=b.useRef(l),h=b.useRef(null),v=b.useMemo(()=>u.filter(k=>k.mode==="pty").map(k=>k.sessionId).sort().join(`
743
743
  `),[u]),g=b.useCallback(k=>{h.current=k.sessionId,i(k),n(A=>Eme(A,k.sessionId).map(R=>R.sessionId===k.sessionId?{...R,sessionKind:k.sessionKind,provider:k.provider}:R))},[]),_=b.useCallback(k=>{h.current===k&&(h.current=null),i(A=>(A==null?void 0:A.sessionId)===k?null:A),o(A=>h.current===null?null:A)},[]),w=b.useCallback((k,A)=>{h.current===k&&o(I=>!A||I&&AEe(I,A)?I:A)},[]),S=b.useCallback((k,A)=>{A!==void 0&&n(I=>I.map(R=>R.sessionId===k?{...R,findRequest:A}:R))},[]),x=b.useCallback((k,A)=>{A===void 0||h.current!==k||n(I=>I.map(R=>R.sessionId===k?{...R,resizeRequest:A}:R))},[]);b.useEffect(()=>{if(!d)return;const k=new Set(v?v.split(`
744
- `):[]);n(A=>A.filter(I=>k.has(I.sessionId))),i(A=>A&&k.has(A.sessionId)?A:null),h.current&&!k.has(h.current)&&(h.current=null,o(null))},[v,d]),b.useEffect(()=>{const k=f.current;f.current=l,!(!k||k===l)&&(h.current=null,n([]),i(null),o(null))},[l]);const T=b.useMemo(()=>({activate:g,deactivate:_,updateFindRequest:S,updateResizeRequest:x,updateViewportRect:w}),[g,_,S,x,w]);return m.jsxs(J$.Provider,{value:T,children:[e,m.jsx(REe,{entries:t,activeView:r,viewportRect:s})]})}function TEe({sessionId:e,sessionKind:t,provider:n,findRequest:r,resizeRequest:i}){const s=b.useContext(J$),o=b.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateResizeRequest:f,updateViewportRect:h}=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();h(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,h]),m.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function REe({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)??EEe,height:(n==null?void 0:n.height)??CEe};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(G6,{sessionId:r.sessionId,active:i,children:m.jsx(xEe,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,resizeRequest:r.resizeRequest})})},r.sessionId)})})}function AEe(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 NEe(){const e=Ut(r=>r.codexActiveWriterConflict),t=Ut(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(Yi,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Vi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"该 Codex 会话仍在运行"}),m.jsxs(fs,{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(Gs,{children:m.jsx(ct,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function zT({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 MEe(e){const t=O5(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function ky(){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 PEe(){return typeof navigator>"u"?{supported:!0}:MEe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:ky()})}function IEe(){t1e(),n1e();const e=hs(),t=ks(),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(()=>ky()),f=Re(O=>O.proxies.length),h=Re(O=>O.proxyListLoaded),v=Re(O=>O.relayClientAuthIssue),g=Re(O=>O.relayConnectionIssue),_=Re(O=>!!O.selectedProxyId),w=Re(O=>O.selectedProxyId),S=Re(O=>O.selectedProxyName),x=Re(O=>{var N;return(N=O.proxies.find(L=>L.proxyId===O.selectedProxyId))==null?void 0:N.osName});Ut(O=>O.sessions.length);const T=Re(O=>O.pendingToast),k=Re(O=>O.setPendingToast),A=e.pathname==="/"?"proxy-select":"sessions",I=g!==null&&v===null,R=zT({route:A,surface:"mobile",proxiesLength:f,proxyListLoaded:h,hasProxy:_,relayClientAuthIssue:v}),M=S??w,Y=e.pathname==="/sessions"&&h&&f>0?m.jsxs(ct,{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":M?`切换开发机,当前 ${M}`:"切换开发机",onClick:()=>t("/"),children:[m.jsx(ij,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx(Mp,{name:M??"切换开发机",osName:x,nameClassName:"text-foreground"})]}):null;b.useEffect(()=>{if(!T)return;({error:He.error,info:He.info,success:He.success})[T.kind](T.message),k(null)},[T,k]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(ky());return}const O=window.matchMedia("(display-mode: standalone)"),N=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(ky());return L(),O.addEventListener("change",L),N.addEventListener("change",L),()=>{O.removeEventListener("change",L),N.removeEventListener("change",L)}},[]);const W=b.useRef(!1);b.useEffect(()=>{if(W.current)return;W.current=!0;const O=gse({pathname:e.pathname,alreadyRestored:bse(),lastRoute:vse()});_se(),O&&(wse(O),t(O,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,yse(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,Fy())},[n,e.pathname,e.search]),m.jsxs(vfe,{blocked:I,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:I?!0:void 0,"aria-hidden":I?!0:void 0,children:[!i&&m.jsx(ct,{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(aj,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(kpe,{subtitle:R,action:Y}),m.jsx(Sme,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(Spe,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(kEe,{children:m.jsx("div",{className:We("h-full",!s&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),"data-slot":"route-content",children:m.jsx(hY,{})},s?"top-level":e.pathname)})})]}),m.jsx(V1,{open:o,onOpenChange:l}),m.jsx(NEe,{}),m.jsx(Qpe,{}),m.jsx(Lpe,{}),m.jsx($ie,{})]}),I&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(nme,{issue:g})}):null]})}function Q$({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(c6,{texts:u6,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 OEe(){const e=Re(o=>o.proxies),t=Re(o=>o.proxyListLoaded),n=Re(o=>!!o.selectedProxyId),r=Re(o=>o.relayClientAuthIssue);Ut(o=>o.sessions.length);const i=zT({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(FF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(nu,{variant:s}):m.jsx(Q$,{subtitle:i})})]})}function LEe(){const e=Re(o=>o.proxies),t=Re(o=>o.proxyListLoaded),n=Re(o=>!!o.selectedProxyId),r=Re(o=>o.relayClientAuthIssue);Ut(o=>o.sessions.length);const i=Ii("local",Tn.proxyId)!==null;if(!n&&!i)return m.jsx(fY,{to:"/",replace:!0});const s=zT({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(e6,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(Q$,{subtitle:s})})]})}function eU(){if(!(typeof navigator>"u"))return navigator.wakeLock}function DEe(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function tU(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return DEe(e,typeof((t=eU())==null?void 0:t.request)=="function")}function BEe(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function zEe(){const e=eU();if(typeof(e==null?void 0:e.request)!="function")throw new Error(BEe(tU()));return e.request("screen")}function jEe(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class FEe{constructor(t={}){Me(this,"activeScopes",new Set);Me(this,"pendingScopes",new Set);Me(this,"listeners",new Map);Me(this,"sentinel",null);Me(this,"requestInFlight",null);Me(this,"requestWakeLock");Me(this,"documentRef");Me(this,"windowRef");Me(this,"unavailableReason");Me(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(()=>{})});Me(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??zEe,this.unavailableReason=typeof t.request=="function"?null:tU(),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(jEe(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 jl=new FEe;function nU(e){const[t,n]=b.useState(()=>jl.getSnapshot(e));b.useEffect(()=>jl.subscribe(e,n),[e]),b.useEffect(()=>()=>{jl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>jl.enable(e),[e]),i=b.useCallback(()=>jl.disable(e),[e]),s=b.useCallback(()=>jl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function HEe({axis:e,label:t,value:n,min:r,max:i,disabled:s,onCommit:o}){const[l,u]=b.useState(null),[d,f]=b.useState(!1),[h,v]=b.useState(!1);function g(){u(null),f(!1),v(!1)}function _(w){if(s||!d||l===null){g();return}const S=l.trim(),x=Number(S);if(!/^\d+$/.test(S)||!Number.isSafeInteger(x)||x<r||x>i){He.error(`请输入 ${r}–${i} 之间的整数`),w?v(!0):g();return}g(),x!==n&&o(x)}return m.jsx("input",{type:"text",inputMode:"numeric",enterKeyHint:"done",pattern:"[0-9]*","aria-label":`设置${t}`,"aria-invalid":h,"data-slot":`chat-menu-${e}-value`,"data-terminal-dimension-input":"","data-editing":l!==null?"true":"false",className:We("h-[22px] w-9 rounded-[5px] border border-transparent bg-transparent px-0.5 text-center text-sm font-medium leading-none tabular-nums text-foreground outline-none hover:bg-muted/45 focus:border-ring focus:bg-background disabled:cursor-not-allowed disabled:opacity-50 [@media(pointer:coarse)]:focus:text-base",h&&"border-destructive focus:border-destructive"),disabled:s,value:l??(n==null?void 0:n.toString())??"",placeholder:"—",autoComplete:"off",spellCheck:!1,onFocus:w=>{u(w.currentTarget.value),f(!1),w.currentTarget.select()},onChange:w=>{u(w.currentTarget.value),f(!0),v(!1)},onBlur:()=>_(!1),onKeyDown:w=>{w.stopPropagation(),!w.nativeEvent.isComposing&&(w.key==="Enter"?(w.preventDefault(),_(!0)):w.key==="Escape"&&(w.preventDefault(),g()))}})}function $Ee(){return new AudioContext}class UEe{constructor(t=$Ee){Me(this,"createContext");Me(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 Ty=new UEe,SD=400,Ud=[];let rU=1;function WEe(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Rp(e){const t={sequence:rU++,timestamp:new Date().toISOString(),monotonicMs:WEe(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Ud.push(t),Ud.length>SD&&Ud.splice(0,Ud.length-SD)}function qEe(){return Ud.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function YEe(){Ud.length=0,rU=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:qEe,clear:YEe});function iU(e){return`voice-pilot:${e}`}function VEe(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 KEe="modulepreload",GEe=function(e){return"/"+e},ED={},sU=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(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};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=GEe(d),d in ED)return;ED[d]=!0;const f=d.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${h}`))return;const v=document.createElement("link");if(v.rel=f?"stylesheet":KEe,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)})},XEe="/assets/fvad-DYxbW2my.wasm",pf=16e3,ZEe=20,Fl=pf*ZEe/1e3,wS=Fl*Int16Array.BYTES_PER_ELEMENT;let xS=null;async function JEe(){return xS??(xS=sU(async()=>{const{default:e}=await import("./fvad-Dd_Y4mnL.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?XEe:t}))),xS}class jT{constructor(t,n,r){Me(this,"module");Me(this,"handle");Me(this,"framePointer");Me(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await JEe(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(wS);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,pf)!==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 jT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==wS)throw new Error(`语音活动检测帧必须为 ${wS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Fl);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 QEe{constructor(t={}){Me(this,"startSpeechFrames");Me(this,"endSilenceFrames");Me(this,"active",!1);Me(this,"speechFrames",0);Me(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 eCe{constructor(){Me(this,"pending",new Float32Array(Fl));Me(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Fl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Fl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Fl<=t.length;)n(t.slice(r,r+Fl)),r+=Fl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const tCe="/__dev_anywhere_debug/voice-fixture",nCe=pf*i6/1e3;function rCe(){return jT.create(3)}const iCe={createVad:rCe,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function sCe(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 oCe(e){for(const t of e.getTracks())t.stop()}function oU(e){const t=e.createAudioContext({sampleRate:pf});if(t.sampleRate!==pf)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function aCe(e){const t=oU(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:pf}})}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(),oCe(n),t.state!=="closed"&&await t.close()}}}async function lCe(e,t){const n=oU(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 aU(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:tCe}:{kind:"microphone"}}async function cCe(e,t=iCe){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await lCe(e.source.url,t):await aCe(t)}catch(f){throw n.destroy(),f}const i=new QEe,s=new eCe,o=r.context.createScriptProcessor(nCe,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),h=>{const v=VEe(h),g=n.process(v);e.onFrame({pcm:v,speechProbability:g?1:0,activityLevel:sCe(h)});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 lU(e=bf().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function uCe(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function dCe({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=uCe(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 fCe(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 hCe(){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(fCe(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Ml="min-h-9 gap-2.5",Xh="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",pCe=[{axis:"cols",label:"列数",unit:"列",Icon:OV,min:ob,max:au},{axis:"rows",label:"行数",unit:"行",Icon:HK,min:ab,max:lu}];function zs({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function mCe({label:e}){return m.jsxs(zs,{className:"relative",children:[m.jsx(HC,{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 gCe({sessionId:e,mode:t,onFind:n,onResizeTerminal:r}){const i=ii(_e=>_e.homePath),s=lU(),o=ks(),l=Ut(_e=>_e.sessions.find(Je=>Je.sessionId===e)),u=Ut(_e=>_e.ptyTitles[e]),d=Ut(_e=>_e.ptyGeometryBySessionId[e]),f=Re(_e=>_e.ptyFontSize),h=Re(_e=>_e.chatContentFontSize),v=Re(_e=>_e.selectedProxyId),g=Re(_e=>_e.connected),_=Re(_e=>_e.proxyOnline),w=Re(_e=>_e.adjustPtyFontSize),S=Re(_e=>_e.adjustChatContentFontSize),x=Re(_e=>_e.setChatContentFontSize),T=Re(_e=>_e.resetPtyFontSize),k=Re(_e=>_e.resetChatContentFontSize),A=Re(_e=>_e.inputModePreference==="hardware"),I=Ut(_e=>_e.renameSession),R=ck(v,e),M=(l==null?void 0:l.provider)!=="codex",z=Ut(_e=>M&&R?!!_e.ptyAutoYesBySessionKey[R]:!1),Y=Ut(_e=>_e.setPtyAutoYes),G=bo("(pointer: coarse), (hover: none)")&&!A,O=t==="pty"||(l==null?void 0:l.mode)==="pty",N=J6(l??{}).menu,L=b.useRef(null),D=b.useRef(null),P=b.useRef(!1),[B,F]=b.useState(!1),U=(l==null?void 0:l.kind)==="terminal",j=nU(e),V=Ln(_e=>_e.bySessionId[e]??v_),X=Ln(_e=>_e.enable),H=Ln(_e=>_e.disable),Q=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),ne=vk(l,i),te=Q&&(l==null?void 0:l.name)||ne||O&&u||(l==null?void 0:l.name)||e.slice(0,8),Z=!!(O&&!U&&u&&!Q),ce=O?f:KC(h,G),ie=!O&&G?Aj:Tj,me=O?T:k,[ge,ve]=b.useState(!1),[Te,Xe]=b.useState(!1),wt=V.enabled,et=j.active||wt,ft=j.pending||!j.supported||wt;function Ne(_e){if(O){w(_e);return}if(G){x(ce+_e);return}S(_e)}function Ue(){j.toggle().catch(_e=>{He.error(_e instanceof Error?_e.message:String(_e))})}async function be(_e){var pt;if(O||U){He.info("Voice Pilot 目前适用于聊天会话。");return}if(_e!==!0){H(e);return}const Je=Bt;if(!Je){He.error("请先连接开发机");return}try{if(!((pt=(await Je.requestVoiceConfig()).config)!=null&&pt.configured)){He.info("请先在设置里配置 Voice Pilot。");return}ve(!0)}catch(St){He.error(St instanceof Error?St.message:String(St))}}async function rt(){var St;Xe(!0);let _e=null,Je=!1;const pt=iU(e);try{Rp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((St=navigator.userActivation)==null?void 0:St.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Dt=jl.enable(pt).then(()=>{Rp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ct=>{throw Rp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ct instanceof Error?Ct.message:String(Ct)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ct})});_e=Jk.acquire("capture");const yn=Ty.prepare(),tn=aU().kind==="microphone"?hCe():Promise.resolve();await Promise.all([Dt,yn,tn]),X(e),Je=!0,ve(!1)}catch(Dt){Rp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Dt instanceof Error?Dt.message:String(Dt)}}),He.error(Dt instanceof Error?Dt.message:String(Dt))}finally{_e==null||_e.release(),Je||await jl.disable(pt).catch(()=>{}),Xe(!1)}}const $e=b.useRef(null),Ae=b.useRef(null),[Ze,Tt]=b.useState(!1);async function ye(_e){var Dt;const Je=(Dt=_e.target.files)==null?void 0:Dt[0];if(_e.target.value="",!Je)return;const pt=Bt;if(!pt){He.error("请先连接开发机");return}const St=await cm({relay:pt,sessionId:e,file:Je});St&&Io(e,`@${St} `)}async function Ke(_e,Je){const pt=Bt;if(!pt)throw new Error("请先连接开发机");const St=await pt.renameSession(_e,Je);if(!St.success)throw new Error(St.error??"重命名失败");I(_e,St.name??Je),He.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(ct,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>o("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(gf,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(dCe,{title:te,isPtyTitle:Z})}),m.jsxs(Cf,{modal:!1,onOpenChange:_e=>{_e?P.current=!1:F(!1)},children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{ref:L,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 Je=document.activeElement,pt=Je==null?void 0:Je.closest('[data-slot="pty-keepalive-entry"]');D.current=O&&Je instanceof HTMLTextAreaElement&&Je.matches('[data-slot="pty-host"] .xterm-helper-textarea')&&(pt==null?void 0:pt.getAttribute("data-session-id"))===e&&pt.getAttribute("data-active")==="true"?Je:null},onKeyDownCapture:_e=>{["Enter"," ","ArrowDown"].includes(_e.key)&&(D.current=null)},children:m.jsx(UV,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)] data-[state=open]:animate-none","data-slot":"chat-overflow-menu",onEscapeKeyDown:_e=>{if(_e.target instanceof HTMLElement&&_e.target.matches('[data-terminal-dimension-input][data-editing="true"]')){_e.preventDefault();return}P.current=!0},onInteractOutside:()=>{const _e=document.activeElement;_e instanceof HTMLInputElement&&_e.hasAttribute("data-terminal-dimension-input")&&_e.blur()},onCloseAutoFocus:_e=>{const Je=D.current,pt=P.current;D.current=null,P.current=!1;const St=Je==null?void 0:Je.closest('[data-slot="pty-keepalive-entry"]'),Dt=document.activeElement;_e.defaultPrevented||!pt||!O||!(Je!=null&&Je.isConnected)||(St==null?void 0:St.getAttribute("data-session-id"))!==e||St.getAttribute("data-active")!=="true"||Dt!==document.body&&Dt!==document.documentElement&&Dt!==L.current&&Dt!==Je&&!(Dt!=null&&Dt.closest('[data-slot="chat-overflow-menu"]'))||(_e.preventDefault(),Je.focus({preventScroll:!0}))},children:[m.jsx(Dh,{className:Xh,children:"会话"}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(zs,{children:m.jsx(Ny,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-rename",onSelect:()=>Tt(!0),children:[m.jsx(zs,{children:m.jsx(IK,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(k0,{checked:et,className:We("min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",!j.supported&&!et&&"pr-2"),disabled:ft,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Ue,children:[m.jsx(zs,{children:m.jsx(pK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:j.supported?wt?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":j.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),O&&!U&&M&&m.jsxs(k0,{checked:z,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!R,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:_e=>{R&&Y(R,_e===!0)},children:[m.jsx(zs,{children:m.jsx(gG,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!O&&!U&&m.jsxs(k0,{checked:V.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:be,children:[m.jsx(zs,{children:m.jsx(xK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Ul,{}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="local-terminal"&&m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"终端尺寸"}),m.jsx("div",{role:"note","data-slot":"chat-menu-local-terminal-size-hint",className:"max-w-52 whitespace-normal px-2 pb-2 text-xs leading-relaxed text-muted-foreground",children:"本会话为本地终端会话,请在开发机上调整窗口大小。"}),m.jsx(Ul,{})]}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="proxy-hosted"&&r&&m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"终端尺寸"}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-fit-terminal",disabled:!g||!_||l.state==="error",onSelect:()=>r("fit"),children:[m.jsx(zs,{children:m.jsx(bK,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),pCe.map(({axis:_e,label:Je,unit:pt,Icon:St,min:Dt,max:yn})=>{const on=d==null?void 0:d[_e],tn=!g||!_||l.state==="error"||on===void 0;return m.jsxs("div",{role:"group","aria-label":Je,className:"flex min-h-9 items-center gap-2.5 px-2 text-sm","data-slot":`chat-menu-${_e}-control`,children:[m.jsx(zs,{children:m.jsx(St,{"aria-hidden":"true"})}),m.jsx("span",{children:Je}),m.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[m.jsx(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:tn||on!==void 0&&on<=Dt,"aria-label":`减少${pt}`,"data-slot":`chat-menu-decrease-${_e}`,onClick:Ct=>{Ct.stopPropagation(),r(`decrease-${_e}`)},children:m.jsx(t1,{"aria-hidden":"true"})}),m.jsx(HEe,{axis:_e,label:Je,value:on,min:Dt,max:yn,disabled:tn,onCommit:Ct=>r({axis:_e,value:Ct})},`${e}-${_e}`),m.jsx(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:tn||on!==void 0&&on>=yn,"aria-label":`增加${pt}`,"data-slot":`chat-menu-increase-${_e}`,onClick:Ct=>{Ct.stopPropagation(),r(`increase-${_e}`)},children:m.jsx(n1,{"aria-hidden":"true"})})]})]},_e)}),m.jsx(Ul,{})]}),O&&m.jsxs(m.Fragment,{children:[m.jsxs(wfe,{open:B,onOpenChange:F,children:[m.jsxs(xfe,{className:We(Ml,"[&>svg:last-child]:ml-0"),"data-slot":"chat-menu-shortcuts-trigger",onClick:_e=>{B&&(_e.preventDefault(),F(!1))},children:[m.jsx(zs,{children:m.jsx(HC,{"aria-hidden":"true"})}),"发送快捷键"]}),m.jsx(_fe,{children:m.jsx(Sfe,{className:We("min-w-44 max-w-[calc(100vw-1rem)] max-h-(--radix-dropdown-menu-content-available-height) overflow-y-auto","data-[side=left]:translate-x-[max(0px,calc(100%-var(--radix-dropdown-menu-content-available-width)))]","data-[side=right]:-translate-x-[max(0px,calc(100%-var(--radix-dropdown-menu-content-available-width)))]"),sideOffset:4,collisionPadding:8,sticky:"always","data-slot":"chat-menu-shortcuts",children:N.map(_e=>m.jsxs(ni,{className:Ml,"data-slot":`chat-menu-send-${_e.id}`,disabled:!g||!_||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>Io(e,_e.data),children:[m.jsx(mCe,{label:_e.display}),"发送 ",_e.key]},_e.id))})})]}),m.jsx(Ul,{})]}),O&&!U?m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"文件"}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-upload-image",onClick:()=>{var _e;return(_e=Ae.current)==null?void 0:_e.click()},children:[m.jsx(zs,{children:m.jsx(ym,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-upload-file",onClick:()=>{var _e;return(_e=$e.current)==null?void 0:_e.click()},children:[m.jsx(zs,{children:m.jsx(cj,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Ul,{})]}):null,m.jsx(Dh,{className:Xh,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(zs,{children:m.jsx(oG,{"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(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ce<=ie,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:_e=>{_e.stopPropagation(),Ne(-1)},children:m.jsx(t1,{"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:[ce,"px"]}),m.jsx(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ce>=Rj,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:_e=>{_e.stopPropagation(),Ne(1)},children:m.jsx(n1,{"aria-hidden":"true"})})]})]})}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-font-reset",onClick:me,children:[m.jsx(zs,{children:m.jsx(sj,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(gp,{open:Ze,sessionId:e,initialName:l==null?void 0:l.name,onOpenChange:Tt,onRename:Ke}),m.jsx(Yi,{open:ge&&!V.enabled,onOpenChange:_e=>{Te||ve(_e)},children:m.jsxs(Vi,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"开启 Voice Pilot?"}),m.jsx(fs,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"outline",disabled:Te,onClick:()=>ve(!1),children:"取消"}),m.jsx(ct,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Te,onClick:()=>{rt()},children:Te?"正在开启...":"开启 Voice Pilot"})]})]})}),O?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:Ae,type:"file",accept:s.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:_e=>{ye(_e)}}),m.jsx("input",{ref:$e,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:_e=>{ye(_e)}})]}):null]})}function Sd(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 h=e();if(!(h.length!==r.length||h.some((_,w)=>r[w]!==_)))return i;r=h;let g;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(g=Date.now()),i=t(...h),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=(T,k)=>{for(T=String(T);T.length<k;)T=" "+T;return T};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
744
+ `):[]);n(A=>A.filter(I=>k.has(I.sessionId))),i(A=>A&&k.has(A.sessionId)?A:null),h.current&&!k.has(h.current)&&(h.current=null,o(null))},[v,d]),b.useEffect(()=>{const k=f.current;f.current=l,!(!k||k===l)&&(h.current=null,n([]),i(null),o(null))},[l]);const T=b.useMemo(()=>({activate:g,deactivate:_,updateFindRequest:S,updateResizeRequest:x,updateViewportRect:w}),[g,_,S,x,w]);return m.jsxs(J$.Provider,{value:T,children:[e,m.jsx(REe,{entries:t,activeView:r,viewportRect:s})]})}function TEe({sessionId:e,sessionKind:t,provider:n,findRequest:r,resizeRequest:i}){const s=b.useContext(J$),o=b.useRef(null);if(!s)throw new Error("PtyKeepAliveViewport must be used within PtyKeepAliveProvider");const{activate:l,deactivate:u,updateFindRequest:d,updateResizeRequest:f,updateViewportRect:h}=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();h(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,h]),m.jsx("div",{ref:o,className:"h-full w-full bg-background","data-slot":"pty-keepalive-viewport","data-session-id":e})}function REe({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)??EEe,height:(n==null?void 0:n.height)??CEe};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(G6,{sessionId:r.sessionId,active:i,children:m.jsx(xEe,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,resizeRequest:r.resizeRequest})})},r.sessionId)})})}function AEe(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 NEe(){const e=Ut(r=>r.codexActiveWriterConflict),t=Ut(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(Yi,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Vi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"该 Codex 会话仍在运行"}),m.jsxs(fs,{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(Gs,{children:m.jsx(ct,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function zT({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 MEe(e){const t=O5(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function ky(){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 PEe(){return typeof navigator>"u"?{supported:!0}:MEe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:ky()})}function IEe(){t1e(),n1e();const e=hs(),t=ks(),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(()=>ky()),f=Re(O=>O.proxies.length),h=Re(O=>O.proxyListLoaded),v=Re(O=>O.relayClientAuthIssue),g=Re(O=>O.relayConnectionIssue),_=Re(O=>!!O.selectedProxyId),w=Re(O=>O.selectedProxyId),S=Re(O=>O.selectedProxyName),x=Re(O=>{var N;return(N=O.proxies.find(L=>L.proxyId===O.selectedProxyId))==null?void 0:N.osName});Ut(O=>O.sessions.length);const T=Re(O=>O.pendingToast),k=Re(O=>O.setPendingToast),A=e.pathname==="/"?"proxy-select":"sessions",I=g!==null&&v===null,R=zT({route:A,surface:"mobile",proxiesLength:f,proxyListLoaded:h,hasProxy:_,relayClientAuthIssue:v}),M=S??w,Y=e.pathname==="/sessions"&&h&&f>0?m.jsxs(ct,{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":M?`切换开发机,当前 ${M}`:"切换开发机",onClick:()=>t("/"),children:[m.jsx(ij,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx(Mp,{name:M??"切换开发机",osName:x,nameClassName:"text-foreground"})]}):null;b.useEffect(()=>{if(!T)return;({error:He.error,info:He.info,success:He.success})[T.kind](T.message),k(null)},[T,k]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(ky());return}const O=window.matchMedia("(display-mode: standalone)"),N=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(ky());return L(),O.addEventListener("change",L),N.addEventListener("change",L),()=>{O.removeEventListener("change",L),N.removeEventListener("change",L)}},[]);const W=b.useRef(!1);b.useEffect(()=>{if(W.current)return;W.current=!0;const O=gse({pathname:e.pathname,alreadyRestored:bse(),lastRoute:vse()});_se(),O&&(wse(O),t(O,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,yse(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,Fy())},[n,e.pathname,e.search]),m.jsxs(vfe,{blocked:I,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:I?!0:void 0,"aria-hidden":I?!0:void 0,children:[!i&&m.jsx(ct,{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(aj,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(kpe,{subtitle:R,action:Y}),m.jsx(Sme,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(Spe,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(kEe,{children:m.jsx("div",{className:We("h-full",!s&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),"data-slot":"route-content",children:m.jsx(hY,{})},s?"top-level":e.pathname)})})]}),m.jsx(V1,{open:o,onOpenChange:l}),m.jsx(NEe,{}),m.jsx(Qpe,{}),m.jsx(Lpe,{}),m.jsx($ie,{})]}),I&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(nme,{issue:g})}):null]})}function Q$({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(c6,{texts:u6,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 OEe(){const e=Re(o=>o.proxies),t=Re(o=>o.proxyListLoaded),n=Re(o=>!!o.selectedProxyId),r=Re(o=>o.relayClientAuthIssue);Ut(o=>o.sessions.length);const i=zT({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(FF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(nu,{variant:s}):m.jsx(Q$,{subtitle:i})})]})}function LEe(){const e=Re(o=>o.proxies),t=Re(o=>o.proxyListLoaded),n=Re(o=>!!o.selectedProxyId),r=Re(o=>o.relayClientAuthIssue);Ut(o=>o.sessions.length);const i=Ii("local",Tn.proxyId)!==null;if(!n&&!i)return m.jsx(fY,{to:"/",replace:!0});const s=zT({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(e6,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(Q$,{subtitle:s})})]})}function eU(){if(!(typeof navigator>"u"))return navigator.wakeLock}function DEe(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function tU(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return DEe(e,typeof((t=eU())==null?void 0:t.request)=="function")}function BEe(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function zEe(){const e=eU();if(typeof(e==null?void 0:e.request)!="function")throw new Error(BEe(tU()));return e.request("screen")}function jEe(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class FEe{constructor(t={}){Me(this,"activeScopes",new Set);Me(this,"pendingScopes",new Set);Me(this,"listeners",new Map);Me(this,"sentinel",null);Me(this,"requestInFlight",null);Me(this,"requestWakeLock");Me(this,"documentRef");Me(this,"windowRef");Me(this,"unavailableReason");Me(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(()=>{})});Me(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??zEe,this.unavailableReason=typeof t.request=="function"?null:tU(),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(jEe(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 jl=new FEe;function nU(e){const[t,n]=b.useState(()=>jl.getSnapshot(e));b.useEffect(()=>jl.subscribe(e,n),[e]),b.useEffect(()=>()=>{jl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>jl.enable(e),[e]),i=b.useCallback(()=>jl.disable(e),[e]),s=b.useCallback(()=>jl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function HEe({axis:e,label:t,value:n,min:r,max:i,disabled:s,onCommit:o}){const[l,u]=b.useState(null),[d,f]=b.useState(!1),[h,v]=b.useState(!1);function g(){u(null),f(!1),v(!1)}function _(w){if(s||!d||l===null){g();return}const S=l.trim(),x=Number(S);if(!/^\d+$/.test(S)||!Number.isSafeInteger(x)||x<r||x>i){He.error(`请输入 ${r}–${i} 之间的整数`),w?v(!0):g();return}g(),x!==n&&o(x)}return m.jsx("input",{type:"text",inputMode:"numeric",enterKeyHint:"done",pattern:"[0-9]*","aria-label":`设置${t}`,"aria-invalid":h,"data-slot":`chat-menu-${e}-value`,"data-terminal-dimension-input":"","data-editing":l!==null?"true":"false",className:We("h-[22px] w-9 rounded-[5px] border border-transparent bg-transparent px-0.5 text-center text-sm font-medium leading-none tabular-nums text-foreground outline-none hover:bg-muted/45 focus:border-ring focus:bg-background disabled:cursor-not-allowed disabled:opacity-50 [@media(pointer:coarse)]:focus:text-base",h&&"border-destructive focus:border-destructive"),disabled:s,value:l??(n==null?void 0:n.toString())??"",placeholder:"—",autoComplete:"off",spellCheck:!1,onFocus:w=>{u(w.currentTarget.value),f(!1),w.currentTarget.select()},onChange:w=>{u(w.currentTarget.value),f(!0),v(!1)},onBlur:()=>_(!1),onKeyDown:w=>{w.stopPropagation(),!w.nativeEvent.isComposing&&(w.key==="Enter"?(w.preventDefault(),_(!0)):w.key==="Escape"&&(w.preventDefault(),g()))}})}function $Ee(){return new AudioContext}class UEe{constructor(t=$Ee){Me(this,"createContext");Me(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 Ty=new UEe,SD=400,Ud=[];let rU=1;function WEe(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Rp(e){const t={sequence:rU++,timestamp:new Date().toISOString(),monotonicMs:WEe(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};Ud.push(t),Ud.length>SD&&Ud.splice(0,Ud.length-SD)}function qEe(){return Ud.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function YEe(){Ud.length=0,rU=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:qEe,clear:YEe});function iU(e){return`voice-pilot:${e}`}function VEe(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 KEe="modulepreload",GEe=function(e){return"/"+e},ED={},sU=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(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};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=GEe(d),d in ED)return;ED[d]=!0;const f=d.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${h}`))return;const v=document.createElement("link");if(v.rel=f?"stylesheet":KEe,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)})},XEe="/assets/fvad-DYxbW2my.wasm",pf=16e3,ZEe=20,Fl=pf*ZEe/1e3,wS=Fl*Int16Array.BYTES_PER_ELEMENT;let xS=null;async function JEe(){return xS??(xS=sU(async()=>{const{default:e}=await import("./fvad-BXU6FrVg.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?XEe:t}))),xS}class jT{constructor(t,n,r){Me(this,"module");Me(this,"handle");Me(this,"framePointer");Me(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await JEe(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(wS);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,pf)!==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 jT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==wS)throw new Error(`语音活动检测帧必须为 ${wS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Fl);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 QEe{constructor(t={}){Me(this,"startSpeechFrames");Me(this,"endSilenceFrames");Me(this,"active",!1);Me(this,"speechFrames",0);Me(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 eCe{constructor(){Me(this,"pending",new Float32Array(Fl));Me(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Fl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Fl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Fl<=t.length;)n(t.slice(r,r+Fl)),r+=Fl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const tCe="/__dev_anywhere_debug/voice-fixture",nCe=pf*i6/1e3;function rCe(){return jT.create(3)}const iCe={createVad:rCe,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function sCe(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 oCe(e){for(const t of e.getTracks())t.stop()}function oU(e){const t=e.createAudioContext({sampleRate:pf});if(t.sampleRate!==pf)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function aCe(e){const t=oU(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:pf}})}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(),oCe(n),t.state!=="closed"&&await t.close()}}}async function lCe(e,t){const n=oU(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 aU(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:tCe}:{kind:"microphone"}}async function cCe(e,t=iCe){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await lCe(e.source.url,t):await aCe(t)}catch(f){throw n.destroy(),f}const i=new QEe,s=new eCe,o=r.context.createScriptProcessor(nCe,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),h=>{const v=VEe(h),g=n.process(v);e.onFrame({pcm:v,speechProbability:g?1:0,activityLevel:sCe(h)});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 lU(e=bf().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function uCe(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function dCe({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=uCe(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 fCe(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 hCe(){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(fCe(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Ml="min-h-9 gap-2.5",Xh="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",pCe=[{axis:"cols",label:"列数",unit:"列",Icon:OV,min:ob,max:au},{axis:"rows",label:"行数",unit:"行",Icon:HK,min:ab,max:lu}];function zs({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:We("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function mCe({label:e}){return m.jsxs(zs,{className:"relative",children:[m.jsx(HC,{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 gCe({sessionId:e,mode:t,onFind:n,onResizeTerminal:r}){const i=ii(_e=>_e.homePath),s=lU(),o=ks(),l=Ut(_e=>_e.sessions.find(Je=>Je.sessionId===e)),u=Ut(_e=>_e.ptyTitles[e]),d=Ut(_e=>_e.ptyGeometryBySessionId[e]),f=Re(_e=>_e.ptyFontSize),h=Re(_e=>_e.chatContentFontSize),v=Re(_e=>_e.selectedProxyId),g=Re(_e=>_e.connected),_=Re(_e=>_e.proxyOnline),w=Re(_e=>_e.adjustPtyFontSize),S=Re(_e=>_e.adjustChatContentFontSize),x=Re(_e=>_e.setChatContentFontSize),T=Re(_e=>_e.resetPtyFontSize),k=Re(_e=>_e.resetChatContentFontSize),A=Re(_e=>_e.inputModePreference==="hardware"),I=Ut(_e=>_e.renameSession),R=ck(v,e),M=(l==null?void 0:l.provider)!=="codex",z=Ut(_e=>M&&R?!!_e.ptyAutoYesBySessionKey[R]:!1),Y=Ut(_e=>_e.setPtyAutoYes),G=bo("(pointer: coarse), (hover: none)")&&!A,O=t==="pty"||(l==null?void 0:l.mode)==="pty",N=J6(l??{}).menu,L=b.useRef(null),D=b.useRef(null),P=b.useRef(!1),[B,F]=b.useState(!1),U=(l==null?void 0:l.kind)==="terminal",j=nU(e),V=Ln(_e=>_e.bySessionId[e]??v_),X=Ln(_e=>_e.enable),H=Ln(_e=>_e.disable),Q=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),ne=vk(l,i),te=Q&&(l==null?void 0:l.name)||ne||O&&u||(l==null?void 0:l.name)||e.slice(0,8),Z=!!(O&&!U&&u&&!Q),ce=O?f:KC(h,G),ie=!O&&G?Aj:Tj,me=O?T:k,[ge,ve]=b.useState(!1),[Te,Xe]=b.useState(!1),wt=V.enabled,et=j.active||wt,ft=j.pending||!j.supported||wt;function Ne(_e){if(O){w(_e);return}if(G){x(ce+_e);return}S(_e)}function Ue(){j.toggle().catch(_e=>{He.error(_e instanceof Error?_e.message:String(_e))})}async function be(_e){var pt;if(O||U){He.info("Voice Pilot 目前适用于聊天会话。");return}if(_e!==!0){H(e);return}const Je=Bt;if(!Je){He.error("请先连接开发机");return}try{if(!((pt=(await Je.requestVoiceConfig()).config)!=null&&pt.configured)){He.info("请先在设置里配置 Voice Pilot。");return}ve(!0)}catch(St){He.error(St instanceof Error?St.message:String(St))}}async function rt(){var St;Xe(!0);let _e=null,Je=!1;const pt=iU(e);try{Rp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((St=navigator.userActivation)==null?void 0:St.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Dt=jl.enable(pt).then(()=>{Rp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Ct=>{throw Rp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Ct instanceof Error?Ct.message:String(Ct)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Ct})});_e=Jk.acquire("capture");const yn=Ty.prepare(),tn=aU().kind==="microphone"?hCe():Promise.resolve();await Promise.all([Dt,yn,tn]),X(e),Je=!0,ve(!1)}catch(Dt){Rp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Dt instanceof Error?Dt.message:String(Dt)}}),He.error(Dt instanceof Error?Dt.message:String(Dt))}finally{_e==null||_e.release(),Je||await jl.disable(pt).catch(()=>{}),Xe(!1)}}const $e=b.useRef(null),Ae=b.useRef(null),[Ze,Tt]=b.useState(!1);async function ye(_e){var Dt;const Je=(Dt=_e.target.files)==null?void 0:Dt[0];if(_e.target.value="",!Je)return;const pt=Bt;if(!pt){He.error("请先连接开发机");return}const St=await cm({relay:pt,sessionId:e,file:Je});St&&Io(e,`@${St} `)}async function Ke(_e,Je){const pt=Bt;if(!pt)throw new Error("请先连接开发机");const St=await pt.renameSession(_e,Je);if(!St.success)throw new Error(St.error??"重命名失败");I(_e,St.name??Je),He.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(ct,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>o("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(gf,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(dCe,{title:te,isPtyTitle:Z})}),m.jsxs(Cf,{modal:!1,onOpenChange:_e=>{_e?P.current=!1:F(!1)},children:[m.jsx(kf,{asChild:!0,children:m.jsx(ct,{ref:L,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 Je=document.activeElement,pt=Je==null?void 0:Je.closest('[data-slot="pty-keepalive-entry"]');D.current=O&&Je instanceof HTMLTextAreaElement&&Je.matches('[data-slot="pty-host"] .xterm-helper-textarea')&&(pt==null?void 0:pt.getAttribute("data-session-id"))===e&&pt.getAttribute("data-active")==="true"?Je:null},onKeyDownCapture:_e=>{["Enter"," ","ArrowDown"].includes(_e.key)&&(D.current=null)},children:m.jsx(UV,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)] data-[state=open]:animate-none","data-slot":"chat-overflow-menu",onEscapeKeyDown:_e=>{if(_e.target instanceof HTMLElement&&_e.target.matches('[data-terminal-dimension-input][data-editing="true"]')){_e.preventDefault();return}P.current=!0},onInteractOutside:()=>{const _e=document.activeElement;_e instanceof HTMLInputElement&&_e.hasAttribute("data-terminal-dimension-input")&&_e.blur()},onCloseAutoFocus:_e=>{const Je=D.current,pt=P.current;D.current=null,P.current=!1;const St=Je==null?void 0:Je.closest('[data-slot="pty-keepalive-entry"]'),Dt=document.activeElement;_e.defaultPrevented||!pt||!O||!(Je!=null&&Je.isConnected)||(St==null?void 0:St.getAttribute("data-session-id"))!==e||St.getAttribute("data-active")!=="true"||Dt!==document.body&&Dt!==document.documentElement&&Dt!==L.current&&Dt!==Je&&!(Dt!=null&&Dt.closest('[data-slot="chat-overflow-menu"]'))||(_e.preventDefault(),Je.focus({preventScroll:!0}))},children:[m.jsx(Dh,{className:Xh,children:"会话"}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(zs,{children:m.jsx(Ny,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-rename",onSelect:()=>Tt(!0),children:[m.jsx(zs,{children:m.jsx(IK,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(k0,{checked:et,className:We("min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",!j.supported&&!et&&"pr-2"),disabled:ft,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Ue,children:[m.jsx(zs,{children:m.jsx(pK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:j.supported?wt?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":j.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),O&&!U&&M&&m.jsxs(k0,{checked:z,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",disabled:!R,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:_e=>{R&&Y(R,_e===!0)},children:[m.jsx(zs,{children:m.jsx(gG,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!O&&!U&&m.jsxs(k0,{checked:V.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:be,children:[m.jsx(zs,{children:m.jsx(xK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Ul,{}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="local-terminal"&&m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"终端尺寸"}),m.jsx("div",{role:"note","data-slot":"chat-menu-local-terminal-size-hint",className:"max-w-52 whitespace-normal px-2 pb-2 text-xs leading-relaxed text-muted-foreground",children:"本会话为本地终端会话,请在开发机上调整窗口大小。"}),m.jsx(Ul,{})]}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="proxy-hosted"&&r&&m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"终端尺寸"}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-fit-terminal",disabled:!g||!_||l.state==="error",onSelect:()=>r("fit"),children:[m.jsx(zs,{children:m.jsx(bK,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),pCe.map(({axis:_e,label:Je,unit:pt,Icon:St,min:Dt,max:yn})=>{const on=d==null?void 0:d[_e],tn=!g||!_||l.state==="error"||on===void 0;return m.jsxs("div",{role:"group","aria-label":Je,className:"flex min-h-9 items-center gap-2.5 px-2 text-sm","data-slot":`chat-menu-${_e}-control`,children:[m.jsx(zs,{children:m.jsx(St,{"aria-hidden":"true"})}),m.jsx("span",{children:Je}),m.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[m.jsx(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:tn||on!==void 0&&on<=Dt,"aria-label":`减少${pt}`,"data-slot":`chat-menu-decrease-${_e}`,onClick:Ct=>{Ct.stopPropagation(),r(`decrease-${_e}`)},children:m.jsx(t1,{"aria-hidden":"true"})}),m.jsx(HEe,{axis:_e,label:Je,value:on,min:Dt,max:yn,disabled:tn,onCommit:Ct=>r({axis:_e,value:Ct})},`${e}-${_e}`),m.jsx(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:tn||on!==void 0&&on>=yn,"aria-label":`增加${pt}`,"data-slot":`chat-menu-increase-${_e}`,onClick:Ct=>{Ct.stopPropagation(),r(`increase-${_e}`)},children:m.jsx(n1,{"aria-hidden":"true"})})]})]},_e)}),m.jsx(Ul,{})]}),O&&m.jsxs(m.Fragment,{children:[m.jsxs(wfe,{open:B,onOpenChange:F,children:[m.jsxs(xfe,{className:We(Ml,"[&>svg:last-child]:ml-0"),"data-slot":"chat-menu-shortcuts-trigger",onClick:_e=>{B&&(_e.preventDefault(),F(!1))},children:[m.jsx(zs,{children:m.jsx(HC,{"aria-hidden":"true"})}),"发送快捷键"]}),m.jsx(_fe,{children:m.jsx(Sfe,{className:We("min-w-44 max-w-[calc(100vw-1rem)] max-h-(--radix-dropdown-menu-content-available-height) overflow-y-auto","data-[side=left]:translate-x-[max(0px,calc(100%-var(--radix-dropdown-menu-content-available-width)))]","data-[side=right]:-translate-x-[max(0px,calc(100%-var(--radix-dropdown-menu-content-available-width)))]"),sideOffset:4,collisionPadding:8,sticky:"always","data-slot":"chat-menu-shortcuts",children:N.map(_e=>m.jsxs(ni,{className:Ml,"data-slot":`chat-menu-send-${_e.id}`,disabled:!g||!_||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>Io(e,_e.data),children:[m.jsx(mCe,{label:_e.display}),"发送 ",_e.key]},_e.id))})})]}),m.jsx(Ul,{})]}),O&&!U?m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"文件"}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-upload-image",onClick:()=>{var _e;return(_e=Ae.current)==null?void 0:_e.click()},children:[m.jsx(zs,{children:m.jsx(ym,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-upload-file",onClick:()=>{var _e;return(_e=$e.current)==null?void 0:_e.click()},children:[m.jsx(zs,{children:m.jsx(cj,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Ul,{})]}):null,m.jsx(Dh,{className:Xh,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(zs,{children:m.jsx(oG,{"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(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ce<=ie,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:_e=>{_e.stopPropagation(),Ne(-1)},children:m.jsx(t1,{"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:[ce,"px"]}),m.jsx(ct,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ce>=Rj,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:_e=>{_e.stopPropagation(),Ne(1)},children:m.jsx(n1,{"aria-hidden":"true"})})]})]})}),m.jsxs(ni,{className:Ml,"data-slot":"chat-menu-font-reset",onClick:me,children:[m.jsx(zs,{children:m.jsx(sj,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(gp,{open:Ze,sessionId:e,initialName:l==null?void 0:l.name,onOpenChange:Tt,onRename:Ke}),m.jsx(Yi,{open:ge&&!V.enabled,onOpenChange:_e=>{Te||ve(_e)},children:m.jsxs(Vi,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Ki,{children:[m.jsx(Oi,{children:"开启 Voice Pilot?"}),m.jsx(fs,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Gs,{children:[m.jsx(ct,{type:"button",variant:"outline",disabled:Te,onClick:()=>ve(!1),children:"取消"}),m.jsx(ct,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:Te,onClick:()=>{rt()},children:Te?"正在开启...":"开启 Voice Pilot"})]})]})}),O?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:Ae,type:"file",accept:s.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:_e=>{ye(_e)}}),m.jsx("input",{ref:$e,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:_e=>{ye(_e)}})]}):null]})}function Sd(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 h=e();if(!(h.length!==r.length||h.some((_,w)=>r[w]!==_)))return i;r=h;let g;if(n.key&&((u=n.debug)!=null&&u.call(n))&&(g=Date.now()),i=t(...h),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=(T,k)=>{for(T=String(T);T.length<k;)T=" "+T;return T};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
745
745
  font-size: .6rem;
746
746
  font-weight: bold;
747
747
  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 CD(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const vCe=(e,t)=>Math.abs(e-t)<1.01,yCe=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},kD=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},bCe=e=>e,_Ce=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},wCe=(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(kD(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(kD(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},TD={passive:!0},RD=typeof window>"u"?!0:"onscrollend"in window,xCe=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&RD?()=>{}:yCe(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=f=>()=>{const{horizontal:h,isRtl:v}=e.options;i=h?n.scrollLeft*(v&&-1||1):n.scrollTop,s(),t(i,f)},l=o(!0),u=o(!1);n.addEventListener("scroll",l,TD);const d=e.options.useScrollendEvent&&RD;return d&&n.addEventListener("scrollend",u,TD),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},SCe=(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"]},ECe=(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 CCe{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:bCe,rangeExtractor:_Ce,onChange:()=>{},measureElement:SCe,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=Sd(()=>(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=Sd(()=>[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=Sd(()=>[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 h=this.measurementsCache.slice(0,f),v=new Array(l).fill(void 0);for(let g=0;g<f;g++){const _=h[g];_&&(v[_.lane]=g)}for(let g=f;g<n;g++){const _=s(g),w=this.laneAssignments.get(g);let S,x;const T=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){S=w;const R=v[S],M=R!==void 0?h[R]:void 0;x=M?M.end+this.options.gap:r+i}else{const R=this.options.lanes===1?h[g-1]:this.getFurthestMeasurement(h,g);x=R?R.end+this.options.gap:r+i,S=R?R.lane:g%this.options.lanes,this.options.lanes>1&&T&&this.laneAssignments.set(g,S)}const k=d.get(_),A=typeof k=="number"?k:this.options.estimateSize(g),I=x+A;h[g]={index:g,start:x,size:A,end:I,key:_,lane:S},v[S]=g}return this.measurementsCache=h,h},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Sd(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?kCe({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Sd(()=>{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=Sd(()=>[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 CD(r[cU(0,r.length-1,i=>CD(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&&vCe(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 cU=(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 kCe({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=cU(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 AD=typeof document<"u"?b.useLayoutEffect:b.useEffect;function TCe({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?Eu.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new CCe(r));return i.setOptions(r),AD(()=>i._didMount(),[]),AD(()=>i._willUpdate()),i}function RCe(e){return TCe({observeElementRect:wCe,observeElementOffset:xCe,scrollToFn:ECe,...e})}function ACe(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=_c(i)??(OT(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 NCe(e){const t=ACe(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 MCe(e){return e.kind==="diff"}const PCe=12e4;function ND(e){return e?e.replace(/\r\n?/gu,`
@@ -866,4 +866,4 @@ fn main() {
866
866
  ---
867
867
 
868
868
  _End of sample._
869
- `;function kDe(){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(gb,{text:CDe})})})]})})}function c9(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 u9(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 TDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=c9(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:u9(e,t,r)}function RDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=c9(n);return r?u9(e,t,r):null}async function ADe(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class NDe{constructor(t,n,r=ADe){Me(this,"canvas");Me(this,"onSize");Me(this,"decoder");Me(this,"latest",null);Me(this,"painting",!1);Me(this,"disposed",!1);Me(this,"generation",0);Me(this,"lastSequence",-1);Me(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 MDe=120,PDe=8*1024*1024,IDe=1e3/30,ODe=.15,LDe=100,DDe=.001;function BDe(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 Kc(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 zDe(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 jDe{constructor(t,n={}){Me(this,"video");Me(this,"options");Me(this,"muxer",null);Me(this,"initialSources");Me(this,"initialVideoState");Me(this,"configuration",null);Me(this,"configurationApplied",!1);Me(this,"muxerReady",!1);Me(this,"awaitingKeyframe",!0);Me(this,"pendingFrames",[]);Me(this,"fedFramesAwaitingPlayback",[]);Me(this,"bufferedPacketCount",0);Me(this,"bufferedBytes",0);Me(this,"maxBufferedPackets");Me(this,"maxBufferedBytes");Me(this,"lastObservedMediaTime",null);Me(this,"resyncRequired",!1);Me(this,"playPending",!1);Me(this,"playRequested",!1);Me(this,"started",!1);Me(this,"destroyed",!1);Me(this,"generation",0);Me(this,"playbackDelayTimer",null);Me(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});Me(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});Me(this,"handleVideoError",()=>{this.destroyed||this.reportError(zDe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=iz(n.maxBufferedPackets,MDe),this.maxBufferedBytes=iz(n.maxBufferedBytes,PDe),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 sU(async()=>{const{default:r}=await import("./jmuxer.min-f89rJUS-.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(Kc(n,"Failed to initialize H.264 video playback")),this.destroy()}}feedConfiguration(t){if(this.configuration&&BDe(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:IDe,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(Kc(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()},LDe))}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<=ODe)return;this.video.currentTime=Math.max(0,n-DDe),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(Kc(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(Kc(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(Kc(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(Kc(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(Kc(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 iz(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class FDe{constructor(){Me(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>=Oh;){const s=new DataView(this.buffer.buffer,this.buffer.byteOffset+i,Oh),o=s.getUint32(0,!0),l=s.getUint32(4,!0);if(o===0||o>zy)throw this.buffer=new Uint8Array(0),new RangeError(`Invalid device preview frame length: ${o}`);const u=Oh+o;if(this.buffer.byteLength-i<u)break;r.push({sequence:l,jpeg:this.buffer.slice(i+Oh,i+u)}),i+=u}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Oh+zy)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 HDe{constructor(){Me(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>=cp;){const s=this.buffer.subarray(i),o=Nre(s);if(!o)throw this.buffer=new Uint8Array(0),new RangeError("Invalid H.264 device preview packet header");const l=cp+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+cp,i+l)}),i+=l}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>cp+zy)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 $De(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 UDe(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 d9(e,t,n){$De(e);const r=Mb(),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 WDe(e,t){const n=t.fetch??globalThis.fetch,r=await d9(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new FDe,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 qDe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await d9(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=UDe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new HDe,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 YDe=16,VDe=16;class KDe{constructor(t){Me(this,"send");Me(this,"onFailure");Me(this,"now");Me(this,"moveFlushMs");Me(this,"maxInFlightMoves");Me(this,"active",null);Me(this,"inFlightMoves",0);Me(this,"disposed",!1);Me(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??YDe,this.maxInFlightMoves=t.maxInFlightMoves??VDe}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 GDe=15e3,XDe=1e4,ZDe={ios:40,android:28},JDe={ios:{width:390,height:844},android:{width:412,height:915}};function QDe(){const{id:e=""}=Hz(),t=ks(),n=mr(Ne=>$5(Ne).find(Ue=>Ue.previewId===e)),r=mr(Ne=>Ne.listLoaded),i=mr(Ne=>{var Ue;return((Ue=Ne.authoritative)==null?void 0:Ue.scope)??null}),s=Qo(Ne=>nse(Ne,i,"device",e,"reconnect")),o=b.useRef(null),l=b.useRef(null),u=b.useRef(null),d=b.useRef(null),f=b.useRef(null),h=b.useRef(()=>{}),v=b.useRef(null),g=b.useRef(null),[_,w]=b.useState(0),[S,x]=b.useState("waiting"),[T,k]=b.useState(null),[A,I]=b.useState(null),[R,M]=b.useState(null),[z,Y]=b.useState(""),[W,G]=b.useState(!1),[O,N]=b.useState(!1),[L,D]=b.useState(!1),P=n==null?void 0:n.previewId,B=n==null?void 0:n.state,F=n==null?void 0:n.platform,U=b.useCallback(()=>{const Ne=f.current;f.current=null,Ne==null||Ne.dispose()},[]);b.useEffect(()=>{if(F!=="ios"){d.current=null,M(null);return}const Ne=o.current;if(!Ne)return;const Ue=new NDe(Ne,M);return Ue.reset(!0),M(null),d.current=Ue,()=>{Ue.dispose(),d.current=null}},[P,F]),b.useEffect(()=>{if(U(),h.current=()=>{},v.current=null,g.current=null,I(null),N(!1),D(!1),!P||B!=="ready"){B==="disconnected"?(x("error"),k("模拟器已断开")):(x("waiting"),k(null));return}const Ne=Bt,Ue=i;if(!Ne||!Ue||!Pt.isActive(Ne,Ue)){x("error"),k("开发机连接已断开");return}let be=!1,rt=null,$e=null,Ae=null,Ze=null,Tt=null,ye=0,Ke=!1;const _e=()=>{Tt=null,Ae==null||Ae.abort(),Ae=null,Ze==null||Ze.destroy(),Ze=null,rt&&clearTimeout(rt),rt=null,$e&&clearTimeout($e),$e=null},Je=Ct=>{x("streaming"),$e&&clearTimeout($e),$e=setTimeout(()=>{$e=null,!(be||Ct.signal.aborted||Tt!==Ct.leaseId||!Pt.isActive(Ne,Ue))&&(ye=0)},XDe)},pt=()=>{if(be||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;const Ct=Math.min(5e3,500*2**ye);ye+=1,rt=setTimeout(()=>{St()},Ct)},St=async()=>{var gn;if(U(),_e(),be||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;Ke=!1,(gn=d.current)==null||gn.reset(),M(null),x("connecting"),k(null),I(null);const Ct=new AbortController;Ae=Ct;try{const Wt=await Pt.requestDevicePreviewStream(Ue,P,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:Ct.signal});if(be||Ct.signal.aborted||!Pt.isActive(Ne,Ue)||!Wt)return;if(!Wt.success)throw new Error(Wt.error);const en=Wt;if(Tt=en.leaseId,I(en),F==="android"){const rr=l.current;if(!rr)throw new Error("无法初始化 Android 模拟器播放器");let or;const En=new Promise((ke,fe)=>{or=fe}),q=setTimeout(()=>{or(new Error("Android 模拟器画面启动超时"))},GDe),se=ke=>{or(ke instanceof Error?ke:new Error(String(ke)))},oe=new jDe(rr,{onStart:()=>{clearTimeout(q),!(be||en.signal.aborted||!Pt.isActive(Ne,Ue))&&Je(en)},onError:se,onResyncRequired:se});Ze=oe;try{await Promise.race([qDe(en.url,{signal:en.signal,onSize:ke=>{!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue)&&M(ke)},onPacket:ke=>{!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue)&&oe.feed(ke)}}),En])}finally{clearTimeout(q)}if(!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开");return}let wn=!1;if(await WDe(en.url,{signal:en.signal,onFrame:rr=>{if(be||en.signal.aborted||!Pt.isActive(Ne,Ue))return;const or=d.current;or&&(or.enqueue(rr.sequence,rr.jpeg),wn||(wn=!0,Je(en)))}}),!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开")}catch(Wt){if(be||Ct.signal.aborted||!Pt.isActive(Ne,Ue))return;Dt(Wt,!1)}},Dt=(Ct,gn)=>{if(be||Ke||!Pt.isActive(Ne,Ue))return;Ke=!0;const Wt=Ct instanceof Error?Ct.message:"模拟器画面已断开";U(),_e(),v.current=null,g.current=null,I(null),N(!1),D(!1),x("error"),k(Wt),gn&&He.error(Wt),pt()},yn=(Ct,gn,Wt=!0)=>{Ct===Tt&&Dt(gn,Wt)};h.current=yn;const on=Ne.onMessage(Ct=>{if(Ct.type!=="device_preview_control_revoked_push"||!rn(Ct.scope,Ue)||Ct.leaseId!==Tt||!Pt.isActive(Ne,Ue))return;if(g.current=null,D(!1),Ct.reason==="taken_over"){v.current=null,N(!1),U(),I(Wt=>(Wt==null?void 0:Wt.leaseId)===Ct.leaseId?{...Wt,controlMode:"view_only"}:Wt),He.info("控制权已由其他页面接管");return}const gn=new Error(Ct.reason==="proxy_offline"?"开发机连接已断开":Ct.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");yn(Ct.leaseId,gn,!1)}),tn=()=>{if(document.visibilityState==="hidden"){U(),_e(),v.current=null,g.current=null,I(null),N(!1),D(!1),x("waiting");return}ye=0,St()};return document.addEventListener("visibilitychange",tn),St(),()=>{be=!0,h.current===yn&&(h.current=()=>{}),on(),document.removeEventListener("visibilitychange",tn),U(),_e()}},[U,P,F,i,B,_]),b.useEffect(()=>{var Ne;(Ne=f.current)==null||Ne.cancel()},[R==null?void 0:R.height,R==null?void 0:R.width]);const j=(n==null?void 0:n.state)==="ready"&&(A==null?void 0:A.previewId)===n.previewId&&i&&rn(A.scope,i)?A:null,V=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{U();const Ne=Bt,Ue=j;if(!Ne||!Ue||!V)return;const be=new KDe({send:async rt=>{const $e=await Pt.sendDevicePreviewInput(Ue,rt);if(!$e)throw new Error("模拟器控制连接已失效");if(!$e.success)throw new Error($e.error)},onFailure:rt=>{f.current===be&&h.current(Ue.leaseId,rt)}});return f.current=be,()=>{f.current===be&&(f.current=null),be.dispose()}},[V,j,U]);const X=R??JDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],H=ZDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],Q=X.width/X.height,ne=X.width>X.height?"landscape":"portrait",te=ne==="landscape"?`, ${X.width}px`:"",Z={aspectRatio:`${X.width} / ${X.height}`,width:`max(1px, min(calc(100cqw - ${H}px), calc(${(Q*100).toFixed(6)}cqh - ${(Q*H).toFixed(6)}px)${te}))`};b.useEffect(()=>{V||G(!1)},[V]);const ce=b.useCallback(async(Ne,Ue=!0)=>{const be=Bt,rt=j;if(!be||!rt||!V)return!1;try{const $e=await Pt.sendDevicePreviewInput(rt,Ne);return!$e||!Pt.isActive(be,rt.scope)?!1:$e.success?!0:(Ue&&He.error($e.error),!1)}catch($e){return rt.signal.aborted||!Pt.isActive(be,rt.scope)||Ue&&He.error($e instanceof Error?$e.message:"模拟器操作失败"),!1}},[V,j]);function ie(Ne,Ue){const be=u.current;if(!be||!R)return null;const rt=be.getBoundingClientRect(),$e={left:rt.left,top:rt.top,width:rt.width,height:rt.height,frameWidth:R.width,frameHeight:R.height};return Ue==="start"?TDe(Ne.clientX,Ne.clientY,$e):RDe(Ne.clientX,Ne.clientY,$e)}function me(Ne){var rt,$e;if(!V||Ne.button!==0)return;const Ue=ie(Ne,"start");if(!Ue)return;const be=f.current;be!=null&&be.begin(Ne.pointerId,Ue)&&(Ne.preventDefault(),($e=(rt=Ne.currentTarget).setPointerCapture)==null||$e.call(rt,Ne.pointerId))}function ge(Ne){var be;const Ue=ie(Ne,"captured");Ue&&(be=f.current)!=null&&be.move(Ne.pointerId,Ue)&&Ne.preventDefault()}function ve(Ne){var be;const Ue=ie(Ne,"captured");Ue&&((be=f.current)!=null&&be.end(Ne.pointerId,Ue))&&Ne.preventDefault()}function Te(Ne){var Ue;(Ue=f.current)==null||Ue.cancel(Ne.pointerId)}async function Xe(){const Ne=Bt,Ue=j;if(!Ne||!Ue||L||S!=="streaming")return;const be=Symbol("device-preview-control-claim");g.current=be,D(!0);try{const rt=await Pt.claimDevicePreviewControl(Ue);if(g.current!==be||!rt||!Pt.isActive(Ne,Ue.scope))return;if(!rt.success){He.error(rt.error);return}I($e=>($e==null?void 0:$e.leaseId)===Ue.leaseId?{...$e,controlMode:"controller"}:$e)}catch(rt){if(g.current!==be||Ue.signal.aborted||!Pt.isActive(Ne,Ue.scope))return;He.error(rt instanceof Error?rt.message:"暂时无法取得控制权")}finally{g.current===be&&(g.current=null,D(!1))}}async function wt(Ne){Ne.preventDefault();const Ue=z;if(!Ue||O)return;const be=Symbol("device-preview-text-input");v.current=be,N(!0);const rt=await ce({kind:"text",text:Ue});v.current===be&&(rt&&(Y(""),G(!1)),v.current=null,N(!1))}function et(){var Ne;(Ne=f.current)==null||Ne.cancel(),ce({kind:"orientation",orientation:R&&R.width>R.height?"portrait":"landscape_right"})}async function ft(){if((n==null?void 0:n.state)!=="disconnected"){w(be=>be+1);return}const Ne=Bt,Ue=Pt.getActiveScope();if(!Ne||!Ue){He.error("请先连接开发机");return}try{const be=await Pt.reconnectDevicePreview(Ue,n.previewId);be.success||He.error(be.error)}catch(be){if(!Pt.isActive(Ne,Ue))return;He.error(be instanceof Error?be.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(ct,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(gf,{"aria-hidden":"true"})}),m.jsx(UC,{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(ct,{size:"sm",variant:"outline",disabled:L,onClick:()=>{Xe()},"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:V?"可操控":S==="streaming"?"仅查看":"连接中"})]}),m.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-muted/30",children:m.jsxs("div",{className:We("grid h-full min-h-0 min-w-0 gap-3 p-3 md:gap-4 md:p-6",ne==="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":ne,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:We("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:Z,"data-slot":"device-preview-device-shell","data-platform":n.platform,"data-orientation":ne,children:[m.jsx(eBe,{platform:n.platform,orientation:ne}),m.jsx("div",{ref:u,className:We("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",V&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":V?"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:Ne=>{const Ue=Ne.currentTarget;Ue.videoWidth>0&&Ue.videoHeight>0&&M({width:Ue.videoWidth,height:Ue.videoHeight})},onResize:Ne=>{const Ue=Ne.currentTarget;Ue.videoWidth>0&&Ue.videoHeight>0&&M({width:Ue.videoWidth,height:Ue.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:We("absolute inset-0 z-20 select-none rounded-[var(--device-screen-radius)]",V?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:me,onPointerMove:ge,onPointerUp:ve,onPointerCancel:Te,onLostPointerCapture:Te,onContextMenu:Ne=>{V&&Ne.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":V?"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:T}),m.jsxs(ct,{variant:"outline",size:"sm",disabled:s,onClick:()=>{ft()},"data-slot":"device-preview-retry",children:[s?m.jsx(Gr,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(Gr,{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":ne,role:"group","aria-label":"模拟器控制",children:m.jsxs("div",{className:We("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",ne==="portrait"&&"md:flex-col"),children:[m.jsx(GS,{control:"home",label:"主屏幕",disabled:!V,icon:m.jsx(lK,{"aria-hidden":"true"}),tooltipSide:ne==="portrait"?"left":"top",onClick:()=>{ce({kind:"button",button:"home"})}}),n.platform==="android"?m.jsx(GS,{control:"back",label:"返回",disabled:!V,icon:m.jsx(lG,{"aria-hidden":"true"}),tooltipSide:ne==="portrait"?"left":"top",onClick:()=>{ce({kind:"button",button:"back"})}}):null,m.jsx(GS,{control:"orientation",label:"旋转",disabled:!V||!R,icon:m.jsx(jK,{"aria-hidden":"true"}),tooltipSide:ne==="portrait"?"left":"top",onClick:et}),m.jsx("span",{className:We("mx-0.5 h-6 w-px shrink-0 bg-border/80",ne==="portrait"&&"md:mx-0 md:h-px md:w-6"),"aria-hidden":"true"}),m.jsxs(Zb,{open:W,onOpenChange:Ne=>{(!Ne||V)&&G(Ne)},children:[m.jsxs(Rf,{children:[m.jsx(Af,{asChild:!0,children:m.jsx(Jb,{asChild:!0,children:m.jsx(ct,{type:"button",variant:"ghost",size:"icon",className:We("size-11 rounded-full text-muted-foreground hover:text-foreground",W&&"bg-accent text-foreground"),disabled:!V,"aria-label":"粘贴文字","aria-expanded":W,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(e1,{"aria-hidden":"true"})})})}),m.jsx(Nf,{side:ne==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(Qb,{side:ne==="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:Ne=>{wt(Ne)},children:[m.jsx("textarea",{value:z,onChange:Ne=>Y(Ne.target.value),disabled:!V||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(ct,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!V||!z||O,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:O?m.jsx(Gr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(e1,{"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(ct,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(Gr,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function GS({control:e,label:t,icon:n,disabled:r,tooltipSide:i,onClick:s}){return m.jsxs(Rf,{children:[m.jsx(Af,{asChild:!0,children:m.jsx(ct,{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(Nf,{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 eBe({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:We("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:We("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:We("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 Jd=jY([{path:"/",element:m.jsx(IEe,{}),children:[{index:!0,element:m.jsx(OEe,{})},{path:"sessions",element:m.jsx(LEe,{})},{path:"chat/:id",element:m.jsx(mDe,{})},{path:"preview/device/:id",element:m.jsx(QDe,{})}]},{path:"/pty-test",element:m.jsx(yDe,{})},{path:"/tokens",element:m.jsx(EDe,{})},{path:"/markdown-test",element:m.jsx(kDe,{})}]);function tBe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Xp(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(kj,{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(DV,{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(ct,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(da,{className:"size-4","aria-hidden":"true"}):m.jsx(FC,{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 nBe({children:e}){const t=PEe();return t.supported?e:m.jsx(tBe,{browserName:t.browserName})}function rBe(){return m.jsx(nBe,{children:m.jsx(iBe,{})})}function iBe(){return Ioe(),m.jsx(Ofe,{delayDuration:200,children:m.jsx(cY,{router:Jd})})}function sBe(e=window.history){e.scrollRestoration="manual"}sBe();SX();lme();Cq.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(rBe,{})}));export{sU as _,fm as a,aBe as g};
869
+ `;function kDe(){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(gb,{text:CDe})})})]})})}function c9(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 u9(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 TDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=c9(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:u9(e,t,r)}function RDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=c9(n);return r?u9(e,t,r):null}async function ADe(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class NDe{constructor(t,n,r=ADe){Me(this,"canvas");Me(this,"onSize");Me(this,"decoder");Me(this,"latest",null);Me(this,"painting",!1);Me(this,"disposed",!1);Me(this,"generation",0);Me(this,"lastSequence",-1);Me(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 MDe=120,PDe=8*1024*1024,IDe=1e3/30,ODe=.15,LDe=100,DDe=.001;function BDe(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 Kc(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 zDe(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 jDe{constructor(t,n={}){Me(this,"video");Me(this,"options");Me(this,"muxer",null);Me(this,"initialSources");Me(this,"initialVideoState");Me(this,"configuration",null);Me(this,"configurationApplied",!1);Me(this,"muxerReady",!1);Me(this,"awaitingKeyframe",!0);Me(this,"pendingFrames",[]);Me(this,"fedFramesAwaitingPlayback",[]);Me(this,"bufferedPacketCount",0);Me(this,"bufferedBytes",0);Me(this,"maxBufferedPackets");Me(this,"maxBufferedBytes");Me(this,"lastObservedMediaTime",null);Me(this,"resyncRequired",!1);Me(this,"playPending",!1);Me(this,"playRequested",!1);Me(this,"started",!1);Me(this,"destroyed",!1);Me(this,"generation",0);Me(this,"playbackDelayTimer",null);Me(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});Me(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});Me(this,"handleVideoError",()=>{this.destroyed||this.reportError(zDe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=iz(n.maxBufferedPackets,MDe),this.maxBufferedBytes=iz(n.maxBufferedBytes,PDe),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 sU(async()=>{const{default:r}=await import("./jmuxer.min-BJfcp90E.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(Kc(n,"Failed to initialize H.264 video playback")),this.destroy()}}feedConfiguration(t){if(this.configuration&&BDe(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:IDe,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(Kc(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()},LDe))}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<=ODe)return;this.video.currentTime=Math.max(0,n-DDe),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(Kc(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(Kc(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(Kc(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(Kc(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(Kc(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 iz(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class FDe{constructor(){Me(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>=Oh;){const s=new DataView(this.buffer.buffer,this.buffer.byteOffset+i,Oh),o=s.getUint32(0,!0),l=s.getUint32(4,!0);if(o===0||o>zy)throw this.buffer=new Uint8Array(0),new RangeError(`Invalid device preview frame length: ${o}`);const u=Oh+o;if(this.buffer.byteLength-i<u)break;r.push({sequence:l,jpeg:this.buffer.slice(i+Oh,i+u)}),i+=u}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Oh+zy)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 HDe{constructor(){Me(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>=cp;){const s=this.buffer.subarray(i),o=Nre(s);if(!o)throw this.buffer=new Uint8Array(0),new RangeError("Invalid H.264 device preview packet header");const l=cp+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+cp,i+l)}),i+=l}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>cp+zy)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 $De(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 UDe(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 d9(e,t,n){$De(e);const r=Mb(),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 WDe(e,t){const n=t.fetch??globalThis.fetch,r=await d9(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new FDe,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 qDe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await d9(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=UDe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new HDe,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 YDe=16,VDe=16;class KDe{constructor(t){Me(this,"send");Me(this,"onFailure");Me(this,"now");Me(this,"moveFlushMs");Me(this,"maxInFlightMoves");Me(this,"active",null);Me(this,"inFlightMoves",0);Me(this,"disposed",!1);Me(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??YDe,this.maxInFlightMoves=t.maxInFlightMoves??VDe}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 GDe=15e3,XDe=1e4,ZDe={ios:40,android:28},JDe={ios:{width:390,height:844},android:{width:412,height:915}};function QDe(){const{id:e=""}=Hz(),t=ks(),n=mr(Ne=>$5(Ne).find(Ue=>Ue.previewId===e)),r=mr(Ne=>Ne.listLoaded),i=mr(Ne=>{var Ue;return((Ue=Ne.authoritative)==null?void 0:Ue.scope)??null}),s=Qo(Ne=>nse(Ne,i,"device",e,"reconnect")),o=b.useRef(null),l=b.useRef(null),u=b.useRef(null),d=b.useRef(null),f=b.useRef(null),h=b.useRef(()=>{}),v=b.useRef(null),g=b.useRef(null),[_,w]=b.useState(0),[S,x]=b.useState("waiting"),[T,k]=b.useState(null),[A,I]=b.useState(null),[R,M]=b.useState(null),[z,Y]=b.useState(""),[W,G]=b.useState(!1),[O,N]=b.useState(!1),[L,D]=b.useState(!1),P=n==null?void 0:n.previewId,B=n==null?void 0:n.state,F=n==null?void 0:n.platform,U=b.useCallback(()=>{const Ne=f.current;f.current=null,Ne==null||Ne.dispose()},[]);b.useEffect(()=>{if(F!=="ios"){d.current=null,M(null);return}const Ne=o.current;if(!Ne)return;const Ue=new NDe(Ne,M);return Ue.reset(!0),M(null),d.current=Ue,()=>{Ue.dispose(),d.current=null}},[P,F]),b.useEffect(()=>{if(U(),h.current=()=>{},v.current=null,g.current=null,I(null),N(!1),D(!1),!P||B!=="ready"){B==="disconnected"?(x("error"),k("模拟器已断开")):(x("waiting"),k(null));return}const Ne=Bt,Ue=i;if(!Ne||!Ue||!Pt.isActive(Ne,Ue)){x("error"),k("开发机连接已断开");return}let be=!1,rt=null,$e=null,Ae=null,Ze=null,Tt=null,ye=0,Ke=!1;const _e=()=>{Tt=null,Ae==null||Ae.abort(),Ae=null,Ze==null||Ze.destroy(),Ze=null,rt&&clearTimeout(rt),rt=null,$e&&clearTimeout($e),$e=null},Je=Ct=>{x("streaming"),$e&&clearTimeout($e),$e=setTimeout(()=>{$e=null,!(be||Ct.signal.aborted||Tt!==Ct.leaseId||!Pt.isActive(Ne,Ue))&&(ye=0)},XDe)},pt=()=>{if(be||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;const Ct=Math.min(5e3,500*2**ye);ye+=1,rt=setTimeout(()=>{St()},Ct)},St=async()=>{var gn;if(U(),_e(),be||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;Ke=!1,(gn=d.current)==null||gn.reset(),M(null),x("connecting"),k(null),I(null);const Ct=new AbortController;Ae=Ct;try{const Wt=await Pt.requestDevicePreviewStream(Ue,P,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:Ct.signal});if(be||Ct.signal.aborted||!Pt.isActive(Ne,Ue)||!Wt)return;if(!Wt.success)throw new Error(Wt.error);const en=Wt;if(Tt=en.leaseId,I(en),F==="android"){const rr=l.current;if(!rr)throw new Error("无法初始化 Android 模拟器播放器");let or;const En=new Promise((ke,fe)=>{or=fe}),q=setTimeout(()=>{or(new Error("Android 模拟器画面启动超时"))},GDe),se=ke=>{or(ke instanceof Error?ke:new Error(String(ke)))},oe=new jDe(rr,{onStart:()=>{clearTimeout(q),!(be||en.signal.aborted||!Pt.isActive(Ne,Ue))&&Je(en)},onError:se,onResyncRequired:se});Ze=oe;try{await Promise.race([qDe(en.url,{signal:en.signal,onSize:ke=>{!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue)&&M(ke)},onPacket:ke=>{!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue)&&oe.feed(ke)}}),En])}finally{clearTimeout(q)}if(!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开");return}let wn=!1;if(await WDe(en.url,{signal:en.signal,onFrame:rr=>{if(be||en.signal.aborted||!Pt.isActive(Ne,Ue))return;const or=d.current;or&&(or.enqueue(rr.sequence,rr.jpeg),wn||(wn=!0,Je(en)))}}),!be&&!en.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开")}catch(Wt){if(be||Ct.signal.aborted||!Pt.isActive(Ne,Ue))return;Dt(Wt,!1)}},Dt=(Ct,gn)=>{if(be||Ke||!Pt.isActive(Ne,Ue))return;Ke=!0;const Wt=Ct instanceof Error?Ct.message:"模拟器画面已断开";U(),_e(),v.current=null,g.current=null,I(null),N(!1),D(!1),x("error"),k(Wt),gn&&He.error(Wt),pt()},yn=(Ct,gn,Wt=!0)=>{Ct===Tt&&Dt(gn,Wt)};h.current=yn;const on=Ne.onMessage(Ct=>{if(Ct.type!=="device_preview_control_revoked_push"||!rn(Ct.scope,Ue)||Ct.leaseId!==Tt||!Pt.isActive(Ne,Ue))return;if(g.current=null,D(!1),Ct.reason==="taken_over"){v.current=null,N(!1),U(),I(Wt=>(Wt==null?void 0:Wt.leaseId)===Ct.leaseId?{...Wt,controlMode:"view_only"}:Wt),He.info("控制权已由其他页面接管");return}const gn=new Error(Ct.reason==="proxy_offline"?"开发机连接已断开":Ct.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");yn(Ct.leaseId,gn,!1)}),tn=()=>{if(document.visibilityState==="hidden"){U(),_e(),v.current=null,g.current=null,I(null),N(!1),D(!1),x("waiting");return}ye=0,St()};return document.addEventListener("visibilitychange",tn),St(),()=>{be=!0,h.current===yn&&(h.current=()=>{}),on(),document.removeEventListener("visibilitychange",tn),U(),_e()}},[U,P,F,i,B,_]),b.useEffect(()=>{var Ne;(Ne=f.current)==null||Ne.cancel()},[R==null?void 0:R.height,R==null?void 0:R.width]);const j=(n==null?void 0:n.state)==="ready"&&(A==null?void 0:A.previewId)===n.previewId&&i&&rn(A.scope,i)?A:null,V=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{U();const Ne=Bt,Ue=j;if(!Ne||!Ue||!V)return;const be=new KDe({send:async rt=>{const $e=await Pt.sendDevicePreviewInput(Ue,rt);if(!$e)throw new Error("模拟器控制连接已失效");if(!$e.success)throw new Error($e.error)},onFailure:rt=>{f.current===be&&h.current(Ue.leaseId,rt)}});return f.current=be,()=>{f.current===be&&(f.current=null),be.dispose()}},[V,j,U]);const X=R??JDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],H=ZDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],Q=X.width/X.height,ne=X.width>X.height?"landscape":"portrait",te=ne==="landscape"?`, ${X.width}px`:"",Z={aspectRatio:`${X.width} / ${X.height}`,width:`max(1px, min(calc(100cqw - ${H}px), calc(${(Q*100).toFixed(6)}cqh - ${(Q*H).toFixed(6)}px)${te}))`};b.useEffect(()=>{V||G(!1)},[V]);const ce=b.useCallback(async(Ne,Ue=!0)=>{const be=Bt,rt=j;if(!be||!rt||!V)return!1;try{const $e=await Pt.sendDevicePreviewInput(rt,Ne);return!$e||!Pt.isActive(be,rt.scope)?!1:$e.success?!0:(Ue&&He.error($e.error),!1)}catch($e){return rt.signal.aborted||!Pt.isActive(be,rt.scope)||Ue&&He.error($e instanceof Error?$e.message:"模拟器操作失败"),!1}},[V,j]);function ie(Ne,Ue){const be=u.current;if(!be||!R)return null;const rt=be.getBoundingClientRect(),$e={left:rt.left,top:rt.top,width:rt.width,height:rt.height,frameWidth:R.width,frameHeight:R.height};return Ue==="start"?TDe(Ne.clientX,Ne.clientY,$e):RDe(Ne.clientX,Ne.clientY,$e)}function me(Ne){var rt,$e;if(!V||Ne.button!==0)return;const Ue=ie(Ne,"start");if(!Ue)return;const be=f.current;be!=null&&be.begin(Ne.pointerId,Ue)&&(Ne.preventDefault(),($e=(rt=Ne.currentTarget).setPointerCapture)==null||$e.call(rt,Ne.pointerId))}function ge(Ne){var be;const Ue=ie(Ne,"captured");Ue&&(be=f.current)!=null&&be.move(Ne.pointerId,Ue)&&Ne.preventDefault()}function ve(Ne){var be;const Ue=ie(Ne,"captured");Ue&&((be=f.current)!=null&&be.end(Ne.pointerId,Ue))&&Ne.preventDefault()}function Te(Ne){var Ue;(Ue=f.current)==null||Ue.cancel(Ne.pointerId)}async function Xe(){const Ne=Bt,Ue=j;if(!Ne||!Ue||L||S!=="streaming")return;const be=Symbol("device-preview-control-claim");g.current=be,D(!0);try{const rt=await Pt.claimDevicePreviewControl(Ue);if(g.current!==be||!rt||!Pt.isActive(Ne,Ue.scope))return;if(!rt.success){He.error(rt.error);return}I($e=>($e==null?void 0:$e.leaseId)===Ue.leaseId?{...$e,controlMode:"controller"}:$e)}catch(rt){if(g.current!==be||Ue.signal.aborted||!Pt.isActive(Ne,Ue.scope))return;He.error(rt instanceof Error?rt.message:"暂时无法取得控制权")}finally{g.current===be&&(g.current=null,D(!1))}}async function wt(Ne){Ne.preventDefault();const Ue=z;if(!Ue||O)return;const be=Symbol("device-preview-text-input");v.current=be,N(!0);const rt=await ce({kind:"text",text:Ue});v.current===be&&(rt&&(Y(""),G(!1)),v.current=null,N(!1))}function et(){var Ne;(Ne=f.current)==null||Ne.cancel(),ce({kind:"orientation",orientation:R&&R.width>R.height?"portrait":"landscape_right"})}async function ft(){if((n==null?void 0:n.state)!=="disconnected"){w(be=>be+1);return}const Ne=Bt,Ue=Pt.getActiveScope();if(!Ne||!Ue){He.error("请先连接开发机");return}try{const be=await Pt.reconnectDevicePreview(Ue,n.previewId);be.success||He.error(be.error)}catch(be){if(!Pt.isActive(Ne,Ue))return;He.error(be instanceof Error?be.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(ct,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(gf,{"aria-hidden":"true"})}),m.jsx(UC,{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(ct,{size:"sm",variant:"outline",disabled:L,onClick:()=>{Xe()},"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:V?"可操控":S==="streaming"?"仅查看":"连接中"})]}),m.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-muted/30",children:m.jsxs("div",{className:We("grid h-full min-h-0 min-w-0 gap-3 p-3 md:gap-4 md:p-6",ne==="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":ne,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:We("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:Z,"data-slot":"device-preview-device-shell","data-platform":n.platform,"data-orientation":ne,children:[m.jsx(eBe,{platform:n.platform,orientation:ne}),m.jsx("div",{ref:u,className:We("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",V&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":V?"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:Ne=>{const Ue=Ne.currentTarget;Ue.videoWidth>0&&Ue.videoHeight>0&&M({width:Ue.videoWidth,height:Ue.videoHeight})},onResize:Ne=>{const Ue=Ne.currentTarget;Ue.videoWidth>0&&Ue.videoHeight>0&&M({width:Ue.videoWidth,height:Ue.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:We("absolute inset-0 z-20 select-none rounded-[var(--device-screen-radius)]",V?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:me,onPointerMove:ge,onPointerUp:ve,onPointerCancel:Te,onLostPointerCapture:Te,onContextMenu:Ne=>{V&&Ne.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":V?"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:T}),m.jsxs(ct,{variant:"outline",size:"sm",disabled:s,onClick:()=>{ft()},"data-slot":"device-preview-retry",children:[s?m.jsx(Gr,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(Gr,{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":ne,role:"group","aria-label":"模拟器控制",children:m.jsxs("div",{className:We("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",ne==="portrait"&&"md:flex-col"),children:[m.jsx(GS,{control:"home",label:"主屏幕",disabled:!V,icon:m.jsx(lK,{"aria-hidden":"true"}),tooltipSide:ne==="portrait"?"left":"top",onClick:()=>{ce({kind:"button",button:"home"})}}),n.platform==="android"?m.jsx(GS,{control:"back",label:"返回",disabled:!V,icon:m.jsx(lG,{"aria-hidden":"true"}),tooltipSide:ne==="portrait"?"left":"top",onClick:()=>{ce({kind:"button",button:"back"})}}):null,m.jsx(GS,{control:"orientation",label:"旋转",disabled:!V||!R,icon:m.jsx(jK,{"aria-hidden":"true"}),tooltipSide:ne==="portrait"?"left":"top",onClick:et}),m.jsx("span",{className:We("mx-0.5 h-6 w-px shrink-0 bg-border/80",ne==="portrait"&&"md:mx-0 md:h-px md:w-6"),"aria-hidden":"true"}),m.jsxs(Zb,{open:W,onOpenChange:Ne=>{(!Ne||V)&&G(Ne)},children:[m.jsxs(Rf,{children:[m.jsx(Af,{asChild:!0,children:m.jsx(Jb,{asChild:!0,children:m.jsx(ct,{type:"button",variant:"ghost",size:"icon",className:We("size-11 rounded-full text-muted-foreground hover:text-foreground",W&&"bg-accent text-foreground"),disabled:!V,"aria-label":"粘贴文字","aria-expanded":W,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(e1,{"aria-hidden":"true"})})})}),m.jsx(Nf,{side:ne==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(Qb,{side:ne==="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:Ne=>{wt(Ne)},children:[m.jsx("textarea",{value:z,onChange:Ne=>Y(Ne.target.value),disabled:!V||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(ct,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!V||!z||O,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:O?m.jsx(Gr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(e1,{"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(ct,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(Gr,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function GS({control:e,label:t,icon:n,disabled:r,tooltipSide:i,onClick:s}){return m.jsxs(Rf,{children:[m.jsx(Af,{asChild:!0,children:m.jsx(ct,{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(Nf,{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 eBe({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:We("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:We("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:We("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 Jd=jY([{path:"/",element:m.jsx(IEe,{}),children:[{index:!0,element:m.jsx(OEe,{})},{path:"sessions",element:m.jsx(LEe,{})},{path:"chat/:id",element:m.jsx(mDe,{})},{path:"preview/device/:id",element:m.jsx(QDe,{})}]},{path:"/pty-test",element:m.jsx(yDe,{})},{path:"/tokens",element:m.jsx(EDe,{})},{path:"/markdown-test",element:m.jsx(kDe,{})}]);function tBe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Xp(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(kj,{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(DV,{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(ct,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(da,{className:"size-4","aria-hidden":"true"}):m.jsx(FC,{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 nBe({children:e}){const t=PEe();return t.supported?e:m.jsx(tBe,{browserName:t.browserName})}function rBe(){return m.jsx(nBe,{children:m.jsx(iBe,{})})}function iBe(){return Ioe(),m.jsx(Ofe,{delayDuration:200,children:m.jsx(cY,{router:Jd})})}function sBe(e=window.history){e.scrollRestoration="manual"}sBe();SX();lme();Cq.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(rBe,{})}));export{sU as _,fm as a,aBe as g};